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
- func Add(e Entry)
- func Benign(e Entry) bool
- func CleanURL(raw string) string
- func Describe(e Entry) string
- func FormatChains(chains []Chain) string
- func FormatLine(e Entry) string
- func FormatLines(lines []Entry) string
- func HTTP(next http.Handler, opts HTTPOptions) http.Handler
- func NewTrace(prefix string) string
- func ParseSince(s string, now time.Time, def time.Duration) (time.Time, bool)
- func Redact(s string) string
- func SetApp(ctx context.Context, app string)
- func SetCall(ctx context.Context, view, tool, note string)
- func SetChat(ctx context.Context, chat string)
- func SetDefault(j *Journal)
- func SetLevel(ctx context.Context, level string)
- func TelemetryEvent(e Entry) telemetry.Event
- type Chain
- type Entry
- type Filter
- type HTTPOptions
- type Journal
- func (j *Journal) Add(e Entry)
- func (j *Journal) AddSink(s Sink)
- func (j *Journal) Chains(f Filter) []Chain
- func (j *Journal) Close()
- func (j *Journal) Dir() string
- func (j *Journal) Dropped() int64
- func (j *Journal) Flush()
- func (j *Journal) Query(f Filter) []Entry
- func (j *Journal) Reason(app, chat, trace string, since time.Time) string
- type Options
- type Scope
- type Sink
- type Tools
Constants ¶
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.
const ( Error = "error" Warn = "warn" Info = "info" )
Levels, most severe first.
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.
const ToolName = "harnessly_logs"
ToolName is the agents' MCP tool that reads the journal.
Variables ¶
This section is empty.
Functions ¶
func Benign ¶
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 ¶
CleanURL is an address as the journal keeps it: no query, no fragment, no user info, a token in the path hidden.
func Describe ¶
Describe is a line in a few words: "скрипт __hl/bridge-shim.js: 401", "tools.call x — timeout".
func FormatChains ¶
FormatChains is the chains as text: each error, then the lines that led to it, then the conclusions.
func FormatLine ¶
FormatLine is one line in a few words: time, source, event, what and how it ended.
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 ParseSince ¶
ParseSince reads "10m", "2h", "1d", a time "15:04" today, or an RFC 3339 time; "" is the default given.
func Redact ¶
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 SetCall ¶
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 SetDefault ¶
func SetDefault(j *Journal)
SetDefault makes j the journal Add writes to (nil: none).
func SetLevel ¶
SetLevel raises the level of the request's line: a refusal answered with 200 (a v2 command's) is a warning still.
func TelemetryEvent ¶
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.
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 (*Journal) Add ¶
Add queues a line; it never waits. A line with no time takes now, with no level info.
func (*Journal) AddSink ¶
AddSink adds a receiver of the lines written from now on; safe while the journal writes.
func (*Journal) Chains ¶
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) Flush ¶
func (j *Journal) Flush()
Flush waits until the lines queued before it are written.
func (*Journal) Query ¶
Query is the lines the filter takes, oldest first, the last Limit of them (0: 500).
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).
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.