journal

package
v0.16.521 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2026 License: AGPL-3.0 Imports: 23 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package journal is the machine's journal of what happened along the whole way of a request: the page (navigation, key clicks, its requests to the runtime, console errors, uncaught exceptions, files that did not load), the runtime (requests that failed or changed something, MCP tool calls, app lifecycle, agent launches), the apps' views and Sinopia (what their SDK and bridge saw). One trace id goes from the page through the runtime into a view and its tool calls, so one error reads with its whole chain: `harnessly logs` and the MCP tool harnessly_logs.

It is a hint for the agent and the person, bounded in cost: lines are queued without waiting and written by one goroutine in batches, a full queue drops lines (counted), every hour has its own file with a size cap, and files older than the retention go. A line carries no body, no secret, no token, no text the person typed: only what happened, where, how long it took and how it ended.

Index

Constants

View Source
const (
	TraceHeader = "X-Hl-Trace"
	ChatHeader  = "X-Hl-Chat"
)

The headers the page sends with its requests: the trace of the action they belong to and the chat it is in.

View Source
const (
	Error = "error"
	Warn  = "warn"
	Info  = "info"
)

Levels, most severe first.

View Source
const (
	SourceWeb     = "web"
	SourceRuntime = "runtime"
	SourceApp     = "app"
	SourceSinopia = "sinopia"
	SourceAgent   = "agent"
	// SourcePreview is a page in a preview slot that is not harnessly's own: a dev server, a site.
	SourcePreview = "preview"
)

Sources: where a line was seen.

View Source
const ToolName = "harnessly_logs"

ToolName is the agents' MCP tool that reads the journal.

Variables

This section is empty.

Functions

func Add

func Add(e Entry)

Add queues a line in the default journal; with none it does nothing.

func Benign

func Benign(e Entry) bool

Benign is a line that is not a failure though the browser reports it as one: «ResizeObserver loop …» says a resize was put off to the next frame. The page, its views and Sinopia send it as an exception; it is not kept.

func CleanURL

func CleanURL(raw string) string

CleanURL is an address as the journal keeps it: no query, no fragment, no user info, a token in the path hidden.

func Describe

func Describe(e Entry) string

Describe is a line in a few words: "скрипт __hl/bridge-shim.js: 401", "tools.call x — timeout".

func FormatChains

func FormatChains(chains []Chain) string

FormatChains is the chains as text: each error, then the lines that led to it, then the conclusions.

func FormatLine

func FormatLine(e Entry) string

FormatLine is one line in a few words: time, source, event, what and how it ended.

func FormatLines

func FormatLines(lines []Entry) string

FormatLines is lines as text, one a line.

func HTTP

func HTTP(next http.Handler, opts HTTPOptions) http.Handler

HTTP writes down the runtime's requests: a failure (4xx a warning, 5xx an error), a request that changes something (not GET, HEAD or OPTIONS) and a slow GET as info. A socket (a hijacked connection) and a stream are not written. The request's context carries a scope with the page's trace and chat.

func NewTrace

func NewTrace(prefix string) string

NewTrace is a fresh trace id.

func ParseSince

func ParseSince(s string, now time.Time, def time.Duration) (time.Time, bool)

ParseSince reads "10m", "2h", "1d", a time "15:04" today, or an RFC 3339 time; "" is the default given.

func Redact

func Redact(s string) string

Redact hides what looks like a secret in a text: key=value pairs of secret names, bearer tokens, known key prefixes and long token-like runs.

func SetApp

func SetApp(ctx context.Context, app string)

SetApp tells the scope of ctx the app.

func SetCall

func SetCall(ctx context.Context, view, tool, note string)

SetCall tells the scope of ctx what the request is about: the app's view, the tool or method it calls and, for a failure, a few words of why (never a value or a body).

func SetChat

func SetChat(ctx context.Context, chat string)

SetChat tells the scope of ctx the chat (no scope: nothing).

func SetDefault

func SetDefault(j *Journal)

SetDefault makes j the journal Add writes to (nil: none).

func SetLevel

func SetLevel(ctx context.Context, level string)

SetLevel raises the level of the request's line: a refusal answered with 200 (a v2 command's) is a warning still.

func TelemetryEvent

func TelemetryEvent(e Entry) telemetry.Event

TelemetryEvent is a warning or an error as an optional export sends it (RUNTIME_JOURNAL_EXPORT=telemetry): technical properties only, as telemetry carries them — no text, no address, no chat.

Types

type Chain

type Chain struct {
	Errors []Entry `json:"errors"`
	Lines  []Entry `json:"lines"`
	// Hints are conclusions drawn from the lines (a file the page could not load that never reached the machine).
	Hints []string `json:"hints,omitempty"`
}

Chain is an error with the lines around it that tell how it came about: the same trace, else the same chat and app a little before it.

type Entry

type Entry struct {
	// At is when it happened, in milliseconds.
	At     int64  `json:"at"`
	Level  string `json:"level"`
	Source string `json:"src"`
	// Event is what kind of thing happened: http, fetch, resource, exception, console, csp, nav, click, mcp.call,
	// app.session, app.enable, ui.initialize, view.file, storage, agent.launch, …
	Event  string `json:"ev"`
	Text   string `json:"text,omitempty"`
	Trace  string `json:"trace,omitempty"`
	Chat   string `json:"chat,omitempty"`
	App    string `json:"app,omitempty"`
	View   string `json:"view,omitempty"`
	Tool   string `json:"tool,omitempty"`
	Method string `json:"method,omitempty"`
	// URL is a path (or an origin and a path), never a query: a query is where tokens travel.
	URL    string `json:"url,omitempty"`
	Status int    `json:"status,omitempty"`
	Dur    int64  `json:"dur,omitempty"`
}

Entry is one line of the journal.

func Fill

func Fill(ctx context.Context, e Entry) Entry

Fill puts the scope of ctx into a line's empty trace, chat and app.

type Filter

type Filter struct {
	Since, Until time.Time
	Chat, Trace  string
	App          string
	// Source is one source or several separated by commas.
	Source string
	// Level is the least severe level taken: error takes errors, warn warnings and errors, info (or "") all.
	Level string
	// Text is a substring of the line's event, text, address or tool.
	Text  string
	Limit int
}

Filter picks lines.

type HTTPOptions

type HTTPOptions struct {
	// Quiet is a request whose success is not written (polls, streams, the journal's own routes); its failure is.
	Quiet func(r *http.Request) bool
	// Slow is how long a GET takes to be written as info (default 3 s).
	Slow time.Duration
}

HTTPOptions say which requests the middleware writes down.

type Journal

type Journal struct {

	// OnEntry, when set, is told every warning and error after it is written (an optional export): from the writer's
	// goroutine, so it must not block. Set it before lines come; AddSink is the way to add one later.
	OnEntry func(Entry)
	// contains filtered or unexported fields
}

Journal is a machine's journal in a directory of hourly files.

func Default

func Default() *Journal

Default is the journal Add writes to, nil when there is none.

func Open

func Open(dir string, opts Options) *Journal

Open starts a journal writing under dir.

func (*Journal) Add

func (j *Journal) Add(e Entry)

Add queues a line; it never waits. A line with no time takes now, with no level info.

func (*Journal) AddSink

func (j *Journal) AddSink(s Sink)

AddSink adds a receiver of the lines written from now on; safe while the journal writes.

func (*Journal) Chains

func (j *Journal) Chains(f Filter) []Chain

Chains are the errors the filter takes (whatever its level says, errors only), each with its chain; errors of one trace make one chain. Newest last; at most Limit chains (0: 20).

func (*Journal) Close

func (j *Journal) Close()

Close writes what waits and stops the writer.

func (*Journal) Dir

func (j *Journal) Dir() string

Dir is where the files are.

func (*Journal) Dropped

func (j *Journal) Dropped() int64

Dropped is how many lines a full queue or a full hour lost.

func (*Journal) Flush

func (j *Journal) Flush()

Flush waits until the lines queued before it are written.

func (*Journal) Query

func (j *Journal) Query(f Filter) []Entry

Query is the lines the filter takes, oldest first, the last Limit of them (0: 500).

func (*Journal) Reason

func (j *Journal) Reason(app, chat, trace string, since time.Time) string

Reason is the most telling known cause of a view's failure: the last error line of the app (and chat, when one is named) since the moment given, as one short phrase, "" when none is known. A visible error carries it.

type Options

type Options struct {
	// Keep is how long files are kept (default three days).
	Keep time.Duration
	// HourBytes is the most an hour's file takes of info lines; warnings and errors may take twice as much.
	HourBytes int64
	// Queue is how many lines may wait for the writer.
	Queue int
	// Now is the clock (tests).
	Now func() time.Time
}

Options bound a journal; zero values take the defaults.

type Scope

type Scope struct {
	// contains filtered or unexported fields
}

Scope is what a request knows of where it belongs; a handler deeper in may learn the chat (an agent's MCP call is told by its connection).

func ScopeOf

func ScopeOf(ctx context.Context) *Scope

ScopeOf is the scope of a request's context, nil when there is none.

func WithScope

func WithScope(ctx context.Context, trace, chat string) (context.Context, *Scope)

WithScope is ctx with a scope of the trace and chat given (either may be "").

func (*Scope) Of

func (s *Scope) Of() (trace, chat, app string)

Of is the trace, chat and app of a scope.

type Sink

type Sink struct {
	// All takes info lines too; otherwise only warnings and errors.
	All   bool
	Entry func(Entry)
}

Sink is told the lines the journal wrote, from the writer's goroutine: it must not block (queue and return).

type Tools

type Tools struct {
	J *Journal
	// Chat is the calling agent's chat, "" when it is not known.
	Chat string
	// Own keeps the caller to its own chat's lines (an agent inside the wall): the chat named, every line of another
	// chat or of none left out, and no answer when the chat is not known.
	Own bool
}

Tools is the journal's tool of the agents' MCP server.

func (Tools) Call

func (t Tools) Call(_ context.Context, _ string, args *jsvalue.Object) *jsvalue.Object

func (Tools) Has

func (Tools) Has(name string) bool

func (Tools) Instructions

func (Tools) Instructions() string

func (Tools) Tools

func (Tools) Tools() []any

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL