Documentation
¶
Overview ¶
Package transcript reads the conversation files coding agents write — a JSONL format per harness — as entries (Entry, tool outputs and images included) and shapes them to wire.Message for the chat view. Files are only ever read: backwards from the end for paging, forwards from a remembered offset for tailing, never whole unless a cache entry is new or a relay reads the conversation (ReadEntries).
Index ¶
- Constants
- func AntigravityCwd(path string) string
- func CodexThread(parent, id string) string
- func CodexTurnState(path string) (string, int64)
- func EndOffset(path string) (int64, error)
- func OpenCodeProcPath(path string) string
- func ReadFrom(path, harness string, offset int64) ([]wire.Message, int64, error)
- func Summarize(input json.RawMessage) string
- func SyncOpenCode(path string, export []byte) error
- type Detail
- type Entry
- type Image
- type Index
- type Page
- type Roots
- type SubagentConversation
- type SubagentEvent
- type SubagentUpdate
- type Subagents
- func (s *Subagents) Conversation(callID, id string, before int64) (SubagentConversation, bool)
- func (s *Subagents) Conversations(callID string) []SubagentConversation
- func (s *Subagents) ReadFrom(offset int64) ([]wire.Message, int64, error)
- func (s *Subagents) ReadPage(before int64, limit int) (Page, error)
- func (s *Subagents) Refresh()
- func (s *Subagents) Updates() []SubagentUpdate
Constants ¶
const ( RoleUser = "user" RoleAssistant = "assistant" RoleTool = "tool" RoleSystem = "system" )
Roles of wire.Message.
const (
// DefaultLimit is the page size when the caller gives none.
DefaultLimit = 50
)
const RoleSubagent = "subagent"
RoleSubagent: an Entry reporting what became of a subagent (Sub; never a wire.Message). CallID is the tool call that started it, when the record names it.
const RoleToolOutput = "tool_output"
RoleToolOutput: an Entry holding one tool call's output (never a wire.Message).
Variables ¶
This section is empty.
Functions ¶
func AntigravityCwd ¶ added in v0.23.0
AntigravityCwd is the working directory of the Antigravity CLI conversation whose transcript is path, "" while history.jsonl does not tell it.
func CodexThread ¶ added in v0.31.0
CodexThread is the rollout of Codex thread id (a subagent's), whose parent's rollout is parent: <codex home>/sessions/YYYY/MM/DD/rollout-<ts>-<thread id>.jsonl, under the day the thread started — the parent's or a later one. "" when there is none (yet).
func CodexTurnState ¶ added in v0.31.0
CodexTurnState is what the last turn event of the Codex rollout at path tells, and when: task_started running, task_complete completed, turn_aborted failed — a subagent whose parent's turn ended before it reports nothing to the parent, so only its own rollout tells that it ended. "" when none is found.
func OpenCodeProcPath ¶ added in v0.22.0
OpenCodeProcPath is the process sidecar of the session recorded at path: {"pid", "started" (unix ms)}, the OpenCode process (its terminal UI) that last reported the session.
func ReadFrom ¶
ReadFrom parses the complete records from offset on and returns their messages with the offset to continue from. A trailing partial record is left for the next call. If the file shrank (rewritten), reading restarts at its current end without replaying it.
func Summarize ¶
func Summarize(input json.RawMessage) string
Summarize renders tool arguments (a JSON object, or a JSON string holding one) as a single short line: the command, file path, pattern, … whichever comes first in summaryKeys.
func SyncOpenCode ¶ added in v0.22.0
SyncOpenCode brings stagent's record of an OpenCode session at path (<root>/<session id>.jsonl) up to export, the output of `opencode session export <id>` ({info, messages}): it appends the session record when the title or directory changed and the messages the file lacks, in the export's order up to the first reply still being written (an assistant message without its completion time), which a later export brings complete. What the file holds is never rewritten. The file is replaced whole (a reader sees it before or after, never a part); two syncs at once write what one of them read, which the next sync completes.
Types ¶
type Detail ¶ added in v0.30.0
type Detail struct {
Found bool
// Input is the call's whole input as recorded (JSON text, or a
// free-form patch/code).
Input string
// Output is the call's output: its text, an image as imageRow; the
// answer row of a question. "" when none is recorded (yet).
Output string
// Patch is the files a file-changing call changes as a unified diff
// (fileChanges).
Patch string
// Truncated: Input, Output or Patch was cut to its limit
// (maxDetailInput, maxDetailOutput, maxDetailPatch).
Truncated bool
}
Detail is one tool call as `stagent follow`'s detail op answers it.
func ReadDetail ¶ added in v0.30.0
ReadDetail finds the tool call callID and its output in harness's transcript at path, reading backwards from the end, and returns them (Found false when the transcript holds no such call). Records larger than maxLine are skipped, as pages skip them.
type Entry ¶ added in v0.26.0
type Entry struct {
Role string // RoleUser | RoleAssistant | RoleTool (a tool call) | RoleSystem | RoleToolOutput
// Text is whole, never clipped: user/assistant/system text; a tool
// output's text; a tool call's one-line summary (what the chat row
// shows).
Text string
ToolName string // tool call; tool output when known
CallID string // tool call id (call and output share it) when the harness records one
// Input is a tool call's whole input as recorded (JSON text, or a
// free-form patch/code).
Input string
Images []Image // images carried by a user/assistant/tool-output entry
// Touched: the paths a file-changing tool call names, as written in
// its input.
Touched []string
Time int64 // unix ms
Ask *wire.Ask
Sub *SubagentEvent // RoleSubagent
}
Entry is one entry of a conversation as the harness recorded it, before it is shaped for the chat view (wire.Message) or the relay document. Each harness's parser reads its records as entries; messages shapes them for the chat view in one place.
func ReadEntries ¶ added in v0.26.0
ReadEntries reads harness's transcript at path from its start up to end (bytes; end <= 0 or past the file: the whole file) as entries, complete records only as ReadFrom reads them: thinking/reasoning, sub-agents' (sidechain) records and reports (RoleSubagent) and harness noise are left out — the same rows transcript.get leaves out — and tool outputs are in.
type Image ¶ added in v0.26.0
type Image struct {
MediaType string // image/png, image/jpeg, image/gif, image/webp ("" unknown)
Data []byte
Path string
}
Image is one image of an entry: Data (decoded) when the transcript holds it, else Path when the transcript only names a file.
type Index ¶
type Index struct {
// contains filtered or unexported fields
}
Index lists conversations of every harness, caching per-file metadata in a JSON file keyed by (path, mtime, size) so only changed files are read. Deleting the file only costs a rescan.
func (*Index) Conversation ¶
func (x *Index) Conversation(harness, path string) (c wire.Conversation, ok bool)
Conversation returns the metadata of one transcript file, re-reading it only when it changed since the last call. ok is false when the file is unreadable or is one List would skip (automation or sub-agent run, no id yet).
type Page ¶
type Page struct {
Messages []wire.Message // oldest first
// Cursor is the byte offset to pass as before for older messages;
// 0 means the beginning was reached.
Cursor int64
// End is the offset just after the newest complete record: tail from
// here to receive only what comes after this page.
End int64
}
Page is one page of a transcript.
func ReadPage ¶
ReadPage returns up to limit messages that end before byte offset before (0 = end of file), reading the file backwards so large transcripts cost only what the page needs. A record's messages are never split across pages, so a page may exceed limit by the few messages of its first record.
type Roots ¶
Roots are the directories each harness keeps its conversations in, by harness id (harness.Harness.TranscriptRoot).
func DefaultRoots ¶
DefaultRoots resolves the roots for a home directory as the harnesses do (CLAUDE_CONFIG_DIR, CODEX_HOME). getenv is the environment the harness runs with (os.Getenv for stagent's own).
type SubagentConversation ¶ added in v0.31.0
SubagentConversation is a subagent and a page of its conversation, whose rows carry neither call ids nor questions: they cannot be opened.
type SubagentEvent ¶ added in v0.31.0
type SubagentEvent struct {
// ID is the harness's id of the subagent (Claude Code's agentId,
// Codex's thread id, omp's task id); "" when the record names only the
// call, whose subagents Status is then about.
ID string
Name string
// Status is wire.SubagentRunning, SubagentCompleted or SubagentFailed;
// "" when the record only links the subagent to its call.
Status string
}
SubagentEvent is what one record tells of a subagent (an Entry of RoleSubagent): its id, tied to the tool call that started it when the entry's CallID is set, and what became of it.
type SubagentUpdate ¶ added in v0.31.0
SubagentUpdate is the subagents of a spawn row handed out before, as they are now.
type Subagents ¶ added in v0.31.0
type Subagents struct {
// contains filtered or unexported fields
}
Subagents follows the subagents the tool calls of one transcript start: it reads the transcript's pages and appended records as ReadPage and ReadFrom do, links each subagent-starting tool call (spawnTools) to the subagents it started, and sets them on the call's row. What a subagent does is read from its own conversation file. Not safe for concurrent use.
func NewSubagents ¶ added in v0.31.0
NewSubagents follows the subagents of harness's transcript at path, written by the agent's process that started at since (unix ms; 0 unknown).
func (*Subagents) Conversation ¶ added in v0.31.0
func (s *Subagents) Conversation(callID, id string, before int64) (SubagentConversation, bool)
Conversation is the subagent id of the call callID with the page of its messages before byte offset before (0: the newest); false when the call started no such subagent.
func (*Subagents) Conversations ¶ added in v0.31.0
func (s *Subagents) Conversations(callID string) []SubagentConversation
Conversations are the subagents of the call callID, each with the page of its newest messages; none when the call starts no subagents or none is known (yet).
func (*Subagents) ReadFrom ¶ added in v0.31.0
ReadFrom is transcript.ReadFrom, the subagent-starting rows carrying their subagents.
func (*Subagents) ReadPage ¶ added in v0.31.0
ReadPage is transcript.ReadPage, the subagent-starting rows carrying their subagents.
func (*Subagents) Refresh ¶ added in v0.31.0
func (s *Subagents) Refresh()
Refresh reads again what the subagents of the rows handed out do: it looks for the conversations not found yet and reads those that grew while their subagent runs (once more after it ended). Updates reports what changed.
func (*Subagents) Updates ¶ added in v0.31.0
func (s *Subagents) Updates() []SubagentUpdate
Updates are the spawn rows handed out (ReadPage, ReadFrom) whose subagents changed since, in call id order.