Files
ai-agent/docs/transcript-format.md
gabrielvidalandClaude Opus 5.5 c3945fe965 refactor: retire core runner/ — pi's runner lives in the harness-pi plugin
runner/ (cli.mjs, extensions/folder-permissions.ts, test, README) was a
byte-for-byte duplicate of the harness-pi plugin's runner/, kept only as the
driver's fallback through the sidecar's config.RUNNER_BIN.

- delete runner/ and sidecar config.RUNNER_BIN
- scripts/test.py: drop the `runner` suite (it runs in ai-agent-plugins now)
- scripts/ab: the pi mirror replay uses a tree's runner/ when it has one
  (refs before this), else the plugin's (AB_PI_RUNNER)
- CLAUDE.md / docs / comments point at harness-pi's runner
- sidecar/local-model.md stays (harness-opencode's LOCAL_MODEL_GUIDE)

Merge only after harness-pi 1.1.0 is installed on the lab: harness-pi 1.0.x
reads config.RUNNER_BIN and would fail every pi run on this core.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 11:44:54 +01:00

17 KiB

Transcript format v1 — the contract for converter authors

The hub parses every conversation as a stream of events. A reader turns a harness's native records into these events and the parser (backend/conversations/parse/state.py, ParserState.apply) folds them into the summary and the thread the API returns. This page is the contract a converter writes to; backend/conversations/parse/events.py is its code (FIELDS, validate), and backend/test_parse_fixtures.py fails when the two disagree.

native source ──► reader ──► events ──► fold (ParserState) ──► summary / thread
Reader Reads Where
claude Claude Code's own JSONL, in place parse/readers/claude.py (+ claudetext.py)
legacy the pi / opencode / agy transcripts written in Claude Code's format before v1 — the lab's are rewritten to v1 (scripts/transcripts-v1.py); the workers' copies, and what a worker not updated yet writes, stay in it parse/readers/legacy.py
v1 files whose lines already are v1 events — what the converters write since step 1c parse/readers/v1.py
hub envelopes inbox, relay, cancel, restart note, author tags (any harness) parse/readers/hubtext.py

A file is v1 when its first line is a session event with "v": 1 (readers.reader_for); anything else is read as Claude Code's format — up to a line that is a v1 header, after which every line is v1: a converter that appends to a transcript it finds in the old format (a conversation from before v1, resumed) writes one ahead of its first event.

The writers — converters — are harness-pi's runner/cli.mjs (pi, in JavaScript), sidecar/opencode_mirror.py and sidecar/agy_mirror.py, the last two on sidecar/transcript_v1.py (Out: the header, the facts that moved, the dedup keys, the old-format continuation). Its copies of the hub's tables (tool names, API-error kinds, the text conventions below) are kept equal by backend/test_converter_tables.py.

The file

  • One JSON object per line, UTF-8, \n-terminated. Append only: the hub tails the file from a byte offset and never re-reads what it has folded. A line is read only once its newline is written.
  • Every event has t (its type). at (an ISO-8601 timestamp, UTC Z) may ride on any event and should be on every event that happened at a known time: the conversation's start and end, call latencies and tool durations are computed from it.
  • Ids (id, call, toolCall, …) are opaque strings, unique in the session.
  • Unknown types and unknown keys are ignored, so a newer converter does not break an older hub. A line that fails validation (below) is dropped. A converter keeps its own bookkeeping that way: the opencode and agy mirrors put the key of what they mirrored (ocKey, ocKeys / agyKey) on the first event of its events, and rebuild what a file holds from the file.
  • Fields not listed as required may be absent or null.

The events

Bold fields are required.

Type Fields Meaning
session v, id, harness, harnessVersion, account, machine, cwd, branch, sidechain, agent, parent Header: the first line (v = 1 there; its at the first moment written), then again with the facts that changed (cwd moved, branch switched). The first value of each fact wins. parent ({session, agent, toolCall}) or sidechain: true marks a subagent's transcript; agent is its agent id.
prompt text, id, origin, author, images, files Something a person (or the hub on their behalf) sent, already unwrapped: no hub envelope left in text. origin: user · queued (absorbed by a busy run mid-turn) · inbox · relay · scheduled · hook. author: {id, name, role} in a shared conversation.
inject kind, name, args, text, ref, baseDir, invoked, notes, taskIds Content put into the context that the user did not type — see the kinds below.
call id, request, model, effort, turnEffort, tier, virtual, failed, elapsedMs, empty A model API call (a step) starts; its blocks and usage follow. tier: fast, standard… virtual: not a real API call (a Code Mode script's). failed: the call failed (its blocks are an error). elapsedMs: how long it took (default: since the previous event's at, a session event aside). empty: the step has no blocks.
text text, call, id, paused A text block of the open call. paused: the harness's canned no-op reply (shown as a "paused" tag, not a bubble).
thinking text, call A thinking block.
tool_call tool, id, call, native, input, caller A tool call. tool is the neutral name (see "Tool names" below: shell, read, edit, agent… or <harness>:<name>); native the harness's own. input keeps Claude Code's argument shapes (command, file_path, old_string…) — a converter translates the arguments as the legacy ones do. caller: the id of the Code Mode script that made it.
tool_result toolCall, ok, text, plainText, data, images, async A tool's result (ok defaults to true). text: the result flattened to text; plainText: its text parts only, when it also had images or references. data: structured extras (evalId, bashDiff).
tool_settled toolCall, text, ms, late An asynchronous call's outcome after its tool_result (a Code Mode script that settled): what it returned, how long it ran; late: settled after its result was already delivered.
usage call, input, output, cacheRead, cacheWrite5m, cacheWrite1h, cacheWrite, reasoning, elapsedMs, cost What a call used, in tokens, whenever the harness knows it (before or after the call's blocks). cacheWrite is an unsplit cache write (priced at the 5-minute rate), ignored when a TTL split is given. cost: {usd, source} — only what the provider billed.
error kind, call, id, text, resetsAt An API or provider failure, classified by the reader that knows the wording. Inside a failed call it is also the call's message. kind: auth · rate_limit · overloaded · api_key · context · network · cli_outdated · unknown · other. resetsAt: epoch seconds a rate limit reopens.
turn_end reason, durationMs, heldS done / error: the harness went idle. held: a stop guard kept the turn open. interrupted: the user interrupted (shown as a tag; the turn is not closed by it).
queue op, text A follow-up waiting behind a running turn: enqueue · dequeue (read as its own turn) · remove (absorbed mid-turn).
compact trigger, preTokens, postTokens, durationMs Context compaction boundary (trigger: manual · auto).
agent id, toolCall, state, session A subagent's lifecycle (started · done), linked to its own session. Accepted, not folded yet.
meta kind, data, toolCall, text Session facts that are not turns: title (data: the title) · mode (data: true when Code Mode is on) · cost_state (data: model → cumulative token counts, the names of usage) · pr (data: {number, repo}) · hook_output (the hub's Bash diff hook's stdout for toolCall, in text).
tick busy, request The harness was alive at at and nothing else happened; busy: it is (again) at work, which reopens a finished turn; request: a model step was sent at at (Claude Code's api-request record) and is streaming until its blocks come in. Readers emit it for native records that carry nothing else.

inject kinds: skill (a skill's prompt: name, ref = the Skill tool call it belongs to, text = the prompt, absent for a repeat call's note, baseDir; invoked: {args, at} when the user typed /name — the hub draws the Skill card itself) · command (a typed slash command: name, args, text) · task_done (notes: background tasks that reported — {taskIds, toolUseId, status, summary, event, exitCode}) · compact_summary (text: what the agent remembers after a compaction) · held (text: the stop guard's label) · cancel (text: the queued message the user cancelled) · tasks_noted (taskIds: the background tasks the sidecar's restart note reported — their ends had been queued and never handed over before the run was stopped; sidecar/undelivered.py) · reminder · note.

Tool names

A tool_call's tool is one of the neutral names when the tool means the same thing on every harness, <harness>:<name> (the harness's own name) when only one harness has it — claude:CronCreate, claude:EnterPlanMode, opencode:execute, agy:manage_task — and mcp__<server>__<tool> for an MCP tool (agy's own mcp_<server>_<tool> spelling is kept too). native always carries the harness's original name. The fold, the cost buckets, the tool cards and the resource / lifecycle / deploy / worktree detection key on tool only. The table is parse/readers/toolnames.py; the buckets parse/tools.py TOOL_BUCKETS.

Neutral tool Claude Code opencode pi agy Cost bucket
shell Bash shell, bash bash run_command shell
shell_output BashOutput, TaskOutput — — — shell
shell_kill KillShell, TaskStop — — — shell
read Read, NotebookRead read read read_file, view_file, view_file_outline, view_code_item read
write Write write; patch (added file) write write_file, write_to_file edit
edit Edit, MultiEdit, NotebookEdit edit, multiedit; patch (per updated file) edit edit_file, replace_file_content, multi_edit_file, multi_replace_file_content edit
apply_patch — patch (not split per file) — — edit
delete_file — patch (deleted file) — — edit
grep Grep grep grep grep_search, code_search, grep search
glob Glob glob find find_by_name, find_files, glob search
list_dir LS list ls list_dir, list_directory search
web_fetch WebFetch webfetch — read_url_content, read_url web
web_search WebSearch websearch — search_web web
agent Agent, Task subagent, task — invoke_subagent agent
skill Skill skill — — skill
todo TodoWrite, TaskCreate, TaskUpdate, TaskGet, TaskList todowrite — — todo
ask_user AskUserQuestion question — ask_question tool

Everything else costs to the catch-all tool bucket. A text-only turn is msg, the first call's injected context context.

Where one neutral name covers several of a harness's tools, the input tells them apart (the fold and the cards do the same): edit with edits is a multi-edit, with notebook_path a notebook cell; shell_output / shell_kill with task_id name a background task, else a shell; todo with todos re-sends the whole list, with taskId updates one task (or reads it: taskId alone), with subject creates one, with none of these lists them (parse/tools.py todo_op).

A converter writes tool (the neutral name) and native (the harness's own: pi's bash, opencode's patch, agy's run_command), and keeps Claude Code's argument shapes in input (its tool mappers: mapToolCall in harness-pi's runner/cli.mjs, sidecar/opencode_tools.py, sidecar/agy_tools.py).

Legacy files (pi / opencode / agy transcripts the converters wrote in Claude Code's format, legacy.py): their tools were renamed to Claude Code's on the way in, so they map through the Claude Code column, and native is that Claude Code name — the harness's own is not in the file (nor in the v1 file the rewrite makes of it). A tool the converter kept under its own name is namespaced under the record's entrypoint (opencode, agy); pi's runner stamps none, so a lowercase name in an unstamped file is pi's (Claude Code's tools are PascalCase). The opencode mirror's Execute is opencode:execute.

Before v45 (PARSER_VERSION 44 and older) the API used Claude Code's names for every harness and the buckets bash and task. A worker's CLI can be older or newer than the hub, so the CLI prints either as the neutral name.

Ordering rules

  • session (with v) first.
  • A step is a call followed by its blocks (text, thinking, tool_call, error); blocks name it in call (or follow it directly). The hub folds a step once it is complete: its usage arrived, or any other event did.
  • Write a step whole, as soon as the model has finished it: its call, its blocks, then its usage, in one append. The hub holds a step until its usage (or the next event) — written together, the hold costs nothing, and a tool card shows while its tool runs. pi's runner writes a step at pi's message_end, the agy mirror a PLANNER_RESPONSE as it lands — both before the tools run. opencode writes a step's tokens only when the step ends, after its tools ran: its mirror writes the step then, results right after. A step whose turn ends (interrupted, failed, the next turn) before the step does goes out as it stands, without usage.
  • A usage may still come later, after the tools ran (a step written before it ended): a step with that usage alone prices it, and the content keeps its place — but that pair folds differently from the whole step (see the oddities below), which is why converters write steps whole.
  • A call id seen again is the same API call: its usage is counted once.
  • tool_result after its tool_call; a result with no known call is shown as an orphan row.
  • turn_end after the step it ends. A converter that has no time of its own for a turn's end (agy's run log says when a turn ended, not at what time) stamps it with the latest time the source recorded in that turn — never its own clock, so a mirror that catches up late or restarts writes the same file.

What a reader (or a converter) must never do

  • Compute a cost. usage.cost is only ever what the provider billed; pricing is the hub's (pricing.usage_cost, the EVOX2's local time price).
  • Emit an event for a partial line, or re-emit one for a line it already read: the hub's live state is (byte offset, reader state, fold state).
  • Leave a hub envelope (inbox prefix, author tag, relay markers) in a prompt's text, or a harness's text convention (an interrupt marker, a skill-prompt header) in a block: say what it is with the event. (The converters' prompt_events / promptEvents do it with the hub's own rules: the interrupt marker → turn_end: interrupted, a typed <command-name> → inject: command, other <…> context → inject reminder / note.)
  • Invent a model id: a call that never reached a model has no model. (Ids in angle brackets, like Claude Code's <synthetic>, are placeholders the fold never counts as a model.)

Known oddities

The event layer reproduces the old parser exactly (step 1b-i); these are kept, and the events make each easy to fix later:

  • A step whose usage comes after its tools ran (content, then a usage for the same call) folds differently from the step written whole: the item loses its out, and the turn's cost lands on its first tool card rather than its first card or bubble. The converters write whole steps (step 1c); the opencode transcripts from before v1 had such steps — the rewrite joins each usage to its step, the workers' copies keep them.
  • A failed call is a failed call on the <synthetic> placeholder with a zero usage: it counts as an assistant turn, as Claude Code's own API-error turns do (the converters write it that way for every harness).

The rewrite of the past transcripts (step 1c)

scripts/transcripts-v1.py rewrites the lab's pi / opencode / agy transcripts and the hub's archive copies of them to v1, in place (--verify · --dry-run · --apply · --restore · --prune; the originals are kept 30 days in ~/.cache/ai-agent/transcript-backups/). The translation is conversations/parse/rewrite_v1.py: each record through LegacyReader, its events written out — with no fix, the v1 file parses exactly like the old one. What --apply fixes on the way (rewrite_v1.FIXES): an opencode step's late usage joins its step (whole_steps); agy's turn closes take the source's last time instead of the mirror's clock (source_times); the header names pi (harness; the old pi files read as harness: null); an opencode step that failed or was aborted with no content no longer reads as one of pi's empty error turns from before 2026-11-06, a made-up API-error card (no_pi_fallback).

The workers' synced copies (data/workers/transcripts) are not rewritten: the hub's FeedMirror syncs them by size, without looking at the head, so a rewrite on the hub would be undone or corrupted by the next sync. They stay in the old format, which the hub reads — and when an updated worker resumes one, its converter continues the file in v1 behind a header.