Documentation
¶
Overview ¶
Package transcript defines the normalized per-job event schema Code Loop records for every CLI run, and the mappers that turn each CLI's machine-readable event stream into it.
Index ¶
Constants ¶
const ( FormatClaudeStreamJSON = "stream-json" FormatCodexJSON = "codex-json" FormatOpencodeJSON = "opencode-json" FormatClineJSON = "cline-json" FormatMuseJSON = "muse-json" FormatGeminiJSON = "gemini-json" )
Format names that select a Mapper. They match the agent definitions' output formats.
const InterruptedStatus = "interrupted"
InterruptedStatus is the Status of a command the agent's process exited in the middle of.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Event ¶
type Event struct {
Kind Kind `json:"kind"`
Time time.Time `json:"time"`
// Text is a message, reasoning text, a relayed comment, or a system
// event's description.
Text string `json:"text,omitempty"`
// Name and Input describe a tool call; CallID ties a tool call to its
// result.
Name string `json:"name,omitempty"`
Input map[string]any `json:"input,omitempty"`
CallID string `json:"call_id,omitempty"`
// Output and IsError describe a tool result or a command's output.
Output string `json:"output,omitempty"`
IsError bool `json:"is_error,omitempty"`
Images []string `json:"images,omitempty"`
// Command, ExitCode and Status describe a shell command; Status is
// "running" or "done".
Command string `json:"command,omitempty"`
ExitCode *int `json:"exit_code,omitempty"`
Status string `json:"status,omitempty"`
// Path and Diff describe a file change.
Path string `json:"path,omitempty"`
Diff string `json:"diff,omitempty"`
// Items is a plan's checklist.
Items []PlanItem `json:"items,omitempty"`
// Usage is a turn's token use and cost.
Usage *Usage `json:"usage,omitempty"`
// Author and URL identify a relayed comment. Source is set instead of a
// GitHub comment when a scheduled task's or workflow's output was relayed:
// it labels the run that sent it, and URL links to that run.
Author string `json:"author,omitempty"`
URL string `json:"url,omitempty"`
Source string `json:"source,omitempty"`
}
Event is one entry in a job transcript. Only the fields its Kind uses are set.
type Flusher ¶
type Flusher interface {
Flush() []Event
}
Flusher is a Mapper that holds events back until a later line completes them, such as a message streamed as deltas. Flush returns what it still holds when the stream ends.
type Kind ¶
type Kind string
Kind names one event type in a job transcript.
const ( KindMessage Kind = "message" KindReasoning Kind = "reasoning" KindToolCall Kind = "tool_call" KindToolResult Kind = "tool_result" KindCommand Kind = "command" KindFileChange Kind = "file_change" KindPlan Kind = "plan" KindUsage Kind = "usage" KindCommentRelay Kind = "comment_relay" KindSystem Kind = "system" )
The event kinds of a job transcript. The first eight come from the CLI's own stream; comment_relay and system are recorded by Code Loop itself.
type Log ¶
type Log struct {
// contains filtered or unexported fields
}
Log is one job's transcript: its events and its raw output. It is safe for concurrent use. When it has a directory, every event and every raw byte is also appended to files there, so a transcript outlives a restart.
func Open ¶
Open returns the transcript stored in dir, loading any events already there. An empty dir keeps the transcript in memory only.
func (*Log) Events ¶
Events returns the last limit events, or all of them when limit is zero or less.
func (*Log) Raw ¶
Raw returns the captured raw output, newest last, limited to limit bytes when limit is positive.
type Mapper ¶
Mapper turns one line of a CLI's machine-readable output into transcript events. A line it does not recognize maps to nothing.
type Recorder ¶
type Recorder struct {
// contains filtered or unexported fields
}
Recorder is an io.Writer over a run's raw output stream.
func (*Recorder) Exited ¶ added in v0.7.76
Exited records that the agent's process is gone. Every tool call and command still open is closed as interrupted rather than left running forever, and when any was open or the process failed, a system event says the process exited, with reason when it is not empty (issue #1426).
func (*Recorder) Flush ¶
func (r *Recorder) Flush()
Flush maps a final line that ended without a newline, then records what the mapper still held back.
type TurnOutcome ¶ added in v0.7.25
type TurnOutcome int
TurnOutcome is what a stream's final result event says about the turn.
const ( // TurnUnfinished means the line is not a final result event. TurnUnfinished TurnOutcome = iota // TurnSucceeded is a final result event for a turn that completed. TurnSucceeded // TurnFailed is a final result event for a turn that ended in an error. TurnFailed )
func TurnResult ¶ added in v0.7.25
func TurnResult(format string, line []byte) TurnOutcome
TurnResult reads line as the final result event a CLI writes in format once its turn is over: Claude's and Gemini's "result" and Codex's "turn.completed" or "turn.failed". A run whose stream reached a successful one finished its work, even when the process it ran in did not exit cleanly afterwards (#1122). Formats without such an event report TurnUnfinished for every line.
type Usage ¶
type Usage struct {
InputTokens int `json:"input_tokens,omitempty"`
OutputTokens int `json:"output_tokens,omitempty"`
CacheReadTokens int `json:"cache_read_tokens,omitempty"`
CacheWriteTokens int `json:"cache_write_tokens,omitempty"`
CostUSD float64 `json:"cost_usd,omitempty"`
}
Usage is the token use and cost an agent reported.