transcript

package
v0.7.84 Latest Latest
Warning

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

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

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

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

func Open(dir string) (*Log, error)

Open returns the transcript stored in dir, loading any events already there. An empty dir keeps the transcript in memory only.

func (*Log) Add

func (l *Log) Add(events ...Event)

Add records events, stamping any without a time.

func (*Log) Events

func (l *Log) Events(limit int) []Event

Events returns the last limit events, or all of them when limit is zero or less.

func (*Log) Raw

func (l *Log) Raw(limit int) string

Raw returns the captured raw output, newest last, limited to limit bytes when limit is positive.

func (*Log) Recorder

func (l *Log) Recorder(mapper Mapper) *Recorder

Recorder returns a writer that captures a run's raw output into the log and maps each complete line through mapper, which may be nil.

func (*Log) System

func (l *Log) System(text string)

System records one of Code Loop's own events, such as a claim or a restart.

type Mapper

type Mapper interface {
	Map(line []byte) []Event
}

Mapper turns one line of a CLI's machine-readable output into transcript events. A line it does not recognize maps to nothing.

func NewMapper

func NewMapper(format string) Mapper

NewMapper returns the mapper for an agent definition's output format, or for the transcript format a generic JSONL definition names, or nil when the format has no structured mapping yet. Such a run still records its raw output and Code Loop's own system events.

type PlanItem

type PlanItem struct {
	Text   string `json:"text"`
	Status string `json:"status,omitempty"`
}

PlanItem is one step of an agent's plan.

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

func (r *Recorder) Exited(failed bool, reason string)

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.

func (*Recorder) Usage

func (r *Recorder) Usage() (Usage, int)

Usage returns the token use and cost the run's stream has reported so far, summed across its turns, and how many tool calls it made.

func (*Recorder) Write

func (r *Recorder) Write(p []byte) (int, error)

Write records p as raw output and maps every line it completes.

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.

Jump to

Keyboard shortcuts

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