transcript

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 8 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 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

View Source
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.

View Source
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.

View Source
const MinSecretLen = 8

MinSecretLen is the shortest value Redact scrubs. A shorter one would redact half of any text by accident.

View Source
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.

View Source
const Redacted = "«redacted»"

Redacted replaces any credential value found in captured text.

View Source
const Version = 1

Version is the current turn schema version.

Variables

View Source
var StoreDefaults = Limits{
	MaxTurnBytes:  DefaultStoreMaxTurnBytes,
	MaxTurns:      DefaultStoreMaxTurns,
	MaxTotalBytes: DefaultStoreMaxTotalBytes,
}

StoreDefaults are Compact's bounds when a field is left zero.

View Source
var StreamDefaults = Limits{
	MaxTurnBytes:  DefaultStreamMaxTurnBytes,
	MaxTurns:      DefaultStreamMaxTurns,
	MaxTotalBytes: DefaultStreamMaxTotalBytes,
}

StreamDefaults are the recorder's bounds when a field is left zero.

Functions

func Encode

func Encode(t Turn) (string, error)

Encode renders a turn as its stdout line, without the trailing newline.

func HasPrefix

func HasPrefix(line []byte) bool

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

func Redact(text string, secrets []string) string

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

func Scrubbable(secrets []string) []string

Scrubbable keeps the values long enough to scrub, in order.

func Truncate

func Truncate(s string, limit int) (string, bool)

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.

func Truncated

func Truncated(turns []Turn) bool

Truncated reports whether any turn in a recorded transcript was cut, so a reader can be told the record is partial. It is derived from the turns themselves rather than reported alongside them, because only what survived into storage reliably shows what was kept.

Types

type Kind

type Kind string

Kind discriminates what a turn carries.

const (
	KindText       Kind = "text"
	KindThinking   Kind = "thinking"
	KindToolUse    Kind = "tool_use"
	KindToolResult Kind = "tool_result"
	KindNotice     Kind = "notice"
)

The turn kinds. Notice is the recorder's own voice (session banners, truncation, and budget aborts), never the agent's.

type Limits

type Limits struct {
	MaxTurnBytes  int
	MaxTurns      int
	MaxTotalBytes int
}

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

func NewRecorder(limits Limits, secrets []string, emit func(Turn)) *Recorder

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

func (r *Recorder) Notice(format string, args ...any)

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

func (r *Recorder) Record(t Turn)

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.

func (*Recorder) RecordAll

func (r *Recorder) RecordAll(turns []Turn)

RecordAll admits a batch, preserving order.

func (*Recorder) Stats

func (r *Recorder) Stats() (turns int, truncated bool)

Stats reports what the recorder admitted, for the stage result.

type Role

type Role string

Role is who produced a turn.

const (
	RoleAssistant Role = "assistant"
	RoleUser      Role = "user"
	RoleSystem    Role = "system"
)

The roles. Tool results are reported by the harness as user-role turns, matching how the model sees them.

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".

const (
	SyntaxDiff  Syntax = "diff"
	SyntaxShell Syntax = "shell"
)

The syntax hints.

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

func Compact(turns []Turn, l Limits) []Turn

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.

func Decode

func Decode(line []byte) (Turn, bool)

Decode recovers a turn from one log line; ok is false for any line that is not a turn line.

Jump to

Keyboard shortcuts

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