transcript

package
v0.66.16 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package transcript reads an AI coding agent's on-disk conversation transcript and renders it to a neutral, agent-agnostic Markdown document.

It supports Claude Code and Codex as source agents. The rendered output is handed to a different agent during an in-place migration (see docs/design/2026-06-24-cross-agent-conversation-migration-design.md) so the new agent can continue the work with the full readable history.

Reading is deliberately defensive: undocumented, drifting formats and partially-written (live) files are tolerated by skipping unparseable lines and counting them, rather than failing.

Index

Constants

View Source
const (
	AgentClaude = "claude"
	AgentCodex  = "codex"
)

Agent identifiers for supported source transcripts.

Variables

View Source
var ErrNoTurns = errors.New("transcript contains no usable turns")

ErrNoTurns is returned by Read when a transcript parsed successfully but contained no usable conversation turns. Callers use this to fail fast before disrupting a running session.

View Source
var ErrUnsupportedAgent = errors.New("unsupported source agent for migration")

ErrUnsupportedAgent is returned for source agents without a reader.

Functions

func BuildSeedPrompt

func BuildSeedPrompt(srcAgent, contextPath string) string

BuildSeedPrompt is the short instruction passed to the target agent as its opening prompt, pointing it at the rendered context file.

func CodexRolloutID

func CodexRolloutID(path string) (string, bool)

CodexRolloutID reads a rollout's session_meta id. Exported for the daemon's post-start id capture.

func CodexSessionIDSince added in v0.59.0

func CodexSessionIDSince(root, worktreePath string, since time.Time) (string, bool)

CodexSessionIDSince returns the native session id of the Codex rollout for a cwd created at/after `since`. Unlike LocateCodexSinceIn (newest-by-mtime), it refuses to guess when the (since, cwd) window contains rollouts with two or more DIFFERENT session ids — the concurrent shared-worktree / in-place case — returning ("", false) so the caller falls back to a non-pinned resume rather than cross-assigning another session's conversation. Pass root "" for the daemon default.

func LocateCodexSince

func LocateCodexSince(worktreePath string, since time.Time) (string, bool)

LocateCodexSince returns the newest Codex rollout for a cwd whose mtime is at or after `since`. Used for post-start session-id capture: filtering by start time avoids picking a stale rollout from a prior session in the same cwd (a real hazard for in-place sessions and codex→codex migrations).

func LocateCodexSinceIn added in v0.59.0

func LocateCodexSinceIn(root, worktreePath string, since time.Time) (string, bool)

LocateCodexSinceIn is LocateCodexSince scoped to an explicit Codex state root (CODEX_HOME). Pass "" to use the daemon's default root. This matters because the daemon-side scrape runs in the daemon process, but CODEX_HOME can be set per-session via the agent's launch env — reading the daemon's os.Getenv would scan the wrong directory and silently miss the rollout.

func Supported

func Supported(agent string) bool

Supported reports whether an agent can be used as a migration source.

Types

type Conversation

type Conversation struct {
	SrcAgent     string
	Turns        []Turn
	DroppedLines int // unparseable/skipped lines (format drift, partial tail)
}

Conversation is the parsed, normalized transcript.

func Read

func Read(agent, agentSessionID, worktreePath string) (*Conversation, error)

Read locates and parses the transcript for a session. agentSessionID is the id graith tracks for the source agent (used to locate Claude transcripts); worktreePath is the session's working directory (used to locate Codex transcripts and as a fallback). Returns ErrNoTurns if the transcript parsed but yielded nothing usable.

func (*Conversation) Render

func (c *Conversation) Render(opts RenderOptions) string

Render produces the neutral Markdown context document handed to the target agent. Turns are selected newest-first within the size budget but rendered chronologically so the document reads as a narrative.

type RenderOptions

type RenderOptions struct {
	// MaxBytes is the approximate size budget for the rendered body. When the
	// transcript exceeds it, the oldest turns are elided (newest kept). 0 uses
	// a default.
	MaxBytes int
	// MaxToolOutput caps each tool output block. 0 uses a default.
	MaxToolOutput int
}

RenderOptions tunes the Markdown output.

type Role

type Role string

Role classifies a turn in the neutral model.

const (
	RoleUser      Role = "user"
	RoleAssistant Role = "assistant"
	RoleTool      Role = "tool"
	// RoleContext is historical developer/system context (e.g. Codex
	// `developer` messages). It is rendered as background, never promoted to
	// live instructions.
	RoleContext Role = "context"
)

type ToolCall

type ToolCall struct {
	Name   string
	Args   string
	Output string
	Failed bool
}

ToolCall is a single tool invocation and its result, flattened from whatever nested or call-id-linked representation the source agent used.

type Turn

type Turn struct {
	Role     Role
	Text     string
	Tool     *ToolCall // non-nil when Role == RoleTool
	SrcAgent string    // source agent that produced the turn
}

Turn is one neutral conversation turn.

Jump to

Keyboard shortcuts

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