Expand description
Hand-rolled JSON-lines logger. ~150 lines reusing the serde_json
serializer — deliberately not tracing (its implicit async span context
is moot for a processes-plus-threads design, and the process tree gives
us correlation for free). RFC 0010 §default-logging.
One NDJSON event per line to stderr (stdout is reserved for the
agent’s result). The canonical line schema (RFC 0010 §line-schema) is:
ts level event run_id agent_id agent_path comp pid [span_id parent_span_id trace_id] [dur_ms] [err] <event-specific>.
Structs§
- Event
Window - A snapshot of the ring window an
agentd://events?after=<seq>read returns: the entries withseq > after(after optional level/event-prefix filtering), plus the ring’s current window bounds and cumulativedropped. RFC 0016 §7.2. - LogCtx
- The correlation context stamped on every line. Children inherit
run_idandtrace_idand extendagent_path(the cheap subtree-query superpower: anagent_pathprefix selects a subtree with no backend join). RFC 0010 §tree-correlation. - Logger
- A logger bound to one
LogCtx. Cheap to clone (clones the ctx); writes serialize behind a process-global stderr mutex so lines never interleave.
Enums§
Constants§
- EVENTS_
RING_ DEFAULT - Default ring capacity (
AGENTD_EVENTS_RING, RFC 0016 §7.2/§11): the last N emitted lines held in memory. Bounds memory on a slow subscriber. - EVENTS_
SCHEMA - Envelope version for the
agentd://eventsread body (RFC 0016 §7.2/§8.1). Bumped only on a breaking change to the{oldest_seq,newest_seq,dropped, events}envelope — NOT the line schema (RFC 0010 owns + versions that).
Functions§
- install_
event_ ring - Install the bounded event ring with capacity
cap(RFC 0016 §7.2). Called once by the supervisor when the servedagentd://eventsresource is wanted (gated by--serve-mcp+ theeventsfeature at the call site). Idempotent — a second call resizes/clears. Never fatal (telemetry never crashes the run, §8.4). - read_
event_ window - Drain the ring into an
EventWindowfor a cursor read. Returns the entries withseq > after, capped atlimit(oldest-first), each with itsseqfolded into the RFC 0010 §3.2 line object.level/event_prefixesare the optional §7.3 server-side filters (a cheap prefix match over the held lines — no query engine).Nonewhen no ring is installed (the resource 404s at the server). RFC 0016 §7.2/§7.3. - rfc3339_
millis - Format a
SystemTimeas RFC 3339 UTC with millisecond precision, with no date-library dependency. Uses Howard Hinnant’scivil_from_daysalgorithm. Pre-epoch times clamp to the epoch (we never log them). - take_
events_ dirty - Take-and-clear the “new events since last check” flag — the served
agentd://eventsresource calls this on its coalescing tick to decide whether to fire anotifications/resources/updated. Returnstrueif any line was captured since the last call. RFC 0016 §7.2.