Documentation
¶
Overview ¶
Package transcript is the agent conversation contract: the harness-neutral turn vocabulary every agent CLI's stream is projected onto, the prefixed JSONL line format that carries turns out of the agent pod on stdout, and the gzipped ConfigMap the owning controller persists them into.
Turns share stdout with the envelope's stage results but use their own prefix, so the two streams stay separate: a run emits hundreds of turns and one result, and the controller's result path should not have to walk the turns to find the result.
The in-pod recorder and the status server both round-trip through this package, so the capture and playback shapes cannot drift.
Index ¶
- Constants
- Variables
- func Encode(t Turn) (string, error)
- func HasPrefix(line []byte) bool
- func Redact(text string, secrets []string) string
- func Scrubbable(secrets []string) []string
- func Truncate(s string, limit int) (string, bool)
- func Truncated(turns []Turn) bool
- type Kind
- type Limits
- type Recorder
- type Role
- type Syntax
- type Turn
Constants ¶
const ( DefaultStreamMaxTurnBytes = 64 << 10 DefaultStreamMaxTurns = 0 DefaultStreamMaxTotalBytes = 8 << 20 )
Stream bounds: what the in-pod recorder admits onto stdout, and so what a live viewer sees. They are generous because the live stream is the whole conversation; only the total stays bounded, because the kubelet rotates a container log at 10 MiB by default and a non-follow read of the stage result sees only the current file, so an unbounded conversation could rotate the result events out of reach. MaxTurns of zero is unbounded.
const ( DefaultStoreMaxTurnBytes = 2048 DefaultStoreMaxTurns = 500 DefaultStoreMaxTotalBytes = 512 << 10 )
Store bounds: what Compact keeps for the persisted record. A transcript is stored in a ConfigMap, so the total is sized to leave headroom under the 1 MiB object cap even before gzip; the per-turn cap keeps one runaway tool result from consuming the whole budget.
const MinSecretLen = 8
MinSecretLen is the shortest value Redact scrubs. A shorter one would redact half of any text by accident.
const Prefix = "PATCHY-TURN: "
Prefix marks a turn line on the agent-runner's stdout. It differs from envelope.Prefix so the controller's result path, which scans for stage results, never has to decode a run's few hundred turns.
const Redacted = "«redacted»"
Redacted replaces any credential value found in captured text.
const Version = 1
Version is the current turn schema version.
Variables ¶
var StoreDefaults = Limits{ MaxTurnBytes: DefaultStoreMaxTurnBytes, MaxTurns: DefaultStoreMaxTurns, MaxTotalBytes: DefaultStoreMaxTotalBytes, }
StoreDefaults are Compact's bounds when a field is left zero.
var StreamDefaults = Limits{ MaxTurnBytes: DefaultStreamMaxTurnBytes, MaxTurns: DefaultStreamMaxTurns, MaxTotalBytes: DefaultStreamMaxTotalBytes, }
StreamDefaults are the recorder's bounds when a field is left zero.
Functions ¶
func HasPrefix ¶
HasPrefix reports whether a log line is a turn line. Callers scanning for some other prefix use it to skip turns cheaply, without a full decode.
func Redact ¶ added in v0.15.0
Redact replaces every occurrence of each secret in text with Redacted, in order, so a longer value listed before its own prefix is scrubbed whole. Values shorter than MinSecretLen are left alone.
func Scrubbable ¶ added in v0.15.0
Scrubbable keeps the values long enough to scrub, in order.
func Truncate ¶
Truncate caps s at limit bytes on a rune boundary (the API server rejects invalid UTF-8, and a turn is stored in a ConfigMap). It reports whether it cut anything.
Types ¶
type Limits ¶
Limits bounds one recording. A zero field takes the default for where the limits apply (stream or store); a negative field disables that bound.
type Recorder ¶
type Recorder struct {
// contains filtered or unexported fields
}
Recorder normalises, bounds, redacts, and sequences the turns of one run. It is the single gate every captured turn passes through on its way to stdout, so it enforces the stream bounds; the persisted record is a Compact of what it emitted, never a second capture that could disagree with it.
Recorder is safe for concurrent use, though the runner's line observer calls it from one goroutine.
func NewRecorder ¶
NewRecorder returns a recorder that hands each admitted turn to emit. secrets are literal credential values scrubbed from every captured field: the pod can hold secrets (the broker caller token, any credential-named environment variable) and a tool result can echo them.
func (*Recorder) Notice ¶
Notice emits a recorder-voiced turn, such as a budget abort or a stage banner. It is bounded like any other turn but never itself causes truncation.
func (*Recorder) Record ¶
Record admits one turn: it stamps the sequence and time, redacts, caps the text, and emits. Turns arriving after a bound is hit are dropped, and the first drop emits a closing notice so the reader knows the record is partial.
type Syntax ¶ added in v0.14.0
type Syntax string
Syntax is a harness-neutral rendering hint for a tool turn's Text. Empty means "infer from Path, or show plain".
type Turn ¶
type Turn struct {
V int `json:"v"`
Seq int `json:"seq"`
At string `json:"at,omitempty"`
Role Role `json:"role"`
Kind Kind `json:"kind"`
Tool string `json:"tool,omitempty"`
ID string `json:"id,omitempty"`
Path string `json:"path,omitempty"`
Syntax Syntax `json:"syntax,omitempty"`
Text string `json:"text,omitempty"`
Truncated bool `json:"truncated,omitempty"`
}
Turn is one entry in an agent's conversation, normalised across harnesses. Text carries the message body, the tool invocation's rendered input, or the tool result's excerpt depending on Kind; Truncated reports that the recorder capped it.
ID, Path and Syntax are optional and were added within Version 1: ID pairs a tool_use turn with its tool_result, Path names the file a tool call targets, and Syntax hints how to render Text. Records written before them decode with the fields empty.
func Compact ¶ added in v0.14.0
Compact bounds a recorded conversation for storage. Each turn is capped at MaxTurnBytes; when the turns exceed MaxTurns or their text exceeds MaxTotalBytes, the head and the tail are kept (how the run started and how it ended) and one notice in between says how many turns were elided. Zero fields take StoreDefaults; negative fields disable that bound. Turns keep their original Seq, so a stored record and the live stream agree on numbering; the notice reuses the Seq of the first turn it replaces.
The input is not modified.