transcript

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: AGPL-3.0, Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package transcript persists a conversation to an append-only JSONL log on disk and reconstructs it for resume. The main session is written to <dir>/<sessionID>.jsonl; each subagent is written to its own sidechain file under <dir>/<sessionID>/subagents/agent-<agentID>.jsonl, so subagent tokens are counted and stored separately (aggregate them offline if needed).

The log is the full-fidelity history: every user/assistant/tool message is recorded as it is born. When compaction inserts a boundary, the post-boundary working set — the boundary marker, the summary, and the kept recent tail — is ALSO persisted as messages, so a cold-start resume restores the COMPACTED view (via llm.MessagesForAPI, which slices from the last boundary) instead of replaying raw history and re-summarizing. The kept tail is re-recorded after the boundary (it also exists earlier as births); only the post-boundary copy reaches the model. Lightweight working-set edits that do not add a boundary (MicroCompact tool-result clearing) stay ephemeral and are not persisted. A separate Type=="boundary" record is written for observability and is skipped during reconstruction.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LastUUID

func LastUUID(recs []Record) string

LastUUID returns the UUID of the last record, for continuing the parent chain.

func Messages

func Messages(recs []Record) ([]llm.Message, llm.Usage)

Messages reconstructs the raw conversation and cumulative usage from records. Boundary records are skipped — the working set is rebuilt by compaction on the next turn, not replayed from disk.

func NewAgentID

func NewAgentID() string

NewAgentID returns a fresh subagent identifier.

func NewSessionID

func NewSessionID() string

NewSessionID returns a fresh session identifier.

func SessionIDFrom

func SessionIDFrom(ctx context.Context) string

SessionIDFrom returns the session id carried on ctx, or "" if none.

func WithSessionID

func WithSessionID(ctx context.Context, sessionID string) context.Context

WithSessionID carries the active session id on the context so subagents can write their sidechain under the parent session's directory.

Types

type Record

type Record struct {
	UUID        string            `json:"uuid"`
	ParentUUID  string            `json:"parent_uuid,omitempty"`
	SessionID   string            `json:"session_id"`
	AgentID     string            `json:"agent_id,omitempty"`
	IsSidechain bool              `json:"is_sidechain,omitempty"`
	Timestamp   string            `json:"timestamp"`
	Type        string            `json:"type"` // "message" | "boundary"
	Message     *llm.Message      `json:"message,omitempty"`
	Usage       *llm.Usage        `json:"usage,omitempty"`    // assistant turns only
	Boundary    *llm.BoundaryMeta `json:"boundary,omitempty"` // Type=="boundary"
}

Record is one line of a JSONL transcript.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store is a directory of session transcripts.

func NewStore

func NewStore(dir string) *Store

NewStore returns a Store rooted at dir (created lazily on first write).

func (*Store) AgentPath

func (s *Store) AgentPath(sessionID, agentID string) string

AgentPath is the sidechain JSONL file for a subagent of a session.

func (*Store) Append

func (s *Store) Append(path string, recs ...Record) error

Append writes records to path as JSONL, creating parent directories. It is safe for concurrent use within the process.

func (*Store) Load

func (s *Store) Load(path string) ([]Record, error)

Load reads all records from a transcript file. A missing file yields no records and no error (a fresh session).

func (*Store) MainPath

func (s *Store) MainPath(sessionID string) string

MainPath is the JSONL file for a top-level session.

func (*Store) NewWriter

func (s *Store) NewWriter(sessionID, agentID string) *Writer

NewWriter returns a Writer for a fresh transcript file. agentID == "" writes the main session file; a non-empty agentID writes a subagent sidechain.

func (*Store) ResumeWriter

func (s *Store) ResumeWriter(sessionID, lastUUID string) *Writer

ResumeWriter returns a Writer that continues an existing main-session file, chaining new records after lastUUID.

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

Writer binds a Store, a file path, and a session/agent identity, assigning a UUID and parent link to each record. It satisfies harness.Recorder. Append errors are retained (see Err) rather than panicking, so a failing disk degrades to in-memory operation instead of crashing the agent loop.

func (*Writer) Err

func (w *Writer) Err() error

Err returns the first append error encountered, if any.

func (*Writer) RecordBoundary

func (w *Writer) RecordBoundary(meta llm.BoundaryMeta)

RecordBoundary persists a compaction boundary for observability.

func (*Writer) RecordMessage

func (w *Writer) RecordMessage(m llm.Message, usage llm.Usage)

RecordMessage persists a conversation message. usage is attributed to this turn (zero for non-assistant messages).

Jump to

Keyboard shortcuts

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