/** * Export a clean, readable transcript, dispatched between two kinds of * source: * * native — the adapter's OWN persistence, re-read after the fact: * claude-code — ~/.claude/projects//.jsonl * hermes — ~/.hermes/state.db via node:sqlite (read-only) * codex — $CODEX_HOME/sessions/YYYY/MM/DD/rollout--.jsonl * opencode — ~/.local/share/opencode/opencode.db via node:sqlite * mastracode-inprocess — ~/.agentproto/mastracode-inprocess/storage.db (Mastra libsql) * pi — ~/.pi/agent/sessions//_.jsonl * daemon — agentproto's own capture, `~/.agentproto/sessions//events.jsonl` * (written by transcript-writer.ts at the same point `projectEvent` * flattens events into the ANSI ring buffer, ahead of that flattening). * Available for ANY agent-cli session (acp or print protocol), not just * the two adapters with a native store. * * `source: "auto"` (the default) tries native first and falls back to * daemon events when there's no native strategy or its store can't be * read; `"native"` / `"daemon"` force one and surface its own error. * * Output: Markdown (default) or JSON, built from a shared ExportedSession * model so every source produces identical rendering logic. */ interface ExportedMessage { role: "user" | "assistant" | "tool" | "system"; text?: string; /** Set on a `user`-role message that is a typed inter-session message * (a `session-message` record) rather than the human: the daemon-attested * sender. Absent for a human prompt. Only the session id, label, relation, * kind and message id travel — `role`, `adapter` and `from.agentSlug` stay * on the live/stored envelope and are intentionally not exported. */ from?: { sessionId?: string; label?: string; relation: "child" | "parent" | "sibling" | "granted" | "human" | "system" /** @deprecated legacy value written before `granted` replaced it */ | "peer"; kind: string; messageId: string; }; reasoning?: string; toolName?: string; toolCalls?: { name: string; args: string; }[]; ts?: number; /** Daemon plumbing rather than the work itself: `handoff` marks the handoff * question and the source session's reply to it; `preamble` marks the * daemon-composed system slice (role, AGENTS.md contract, lineage) of a * spawned session's initial prompt. Checkpoints leave these out. */ internal?: "handoff" | "preamble"; /** `seq` of the events.jsonl record this message was built from — set by * the daemon-events exporter only (native stores have no event seq). A * batched assistant turn carries the seq of the record that STARTED the * batch (its first text/thought/tool-call record), so a transcript can be * cut at a message boundary by seq: everything `<= X` is the head, the * rest is the verbatim tail. A record with no seq (a command session's * kind-less CommandLogEntry line) yields a message with no seq. */ seq?: number; } interface ExportedSessionMeta { title?: string; model?: string; startedAt?: string; endedAt?: string; messageCount?: number; toolCallCount?: number; tokens?: { input?: number; output?: number; cacheRead?: number; cacheWrite?: number; reasoning?: number; contextSize?: number; contextUsed?: number; }; costUsd?: number; source?: string; /** Provenance carried over from the session descriptor's own * `origin`/`callerSessionId` (see sessions.ts) — distinct from `source`, * which names the EXPORTER that produced this payload (e.g. * "daemon-events", "codex"), not who invoked the underlying session. */ origin?: string; callerSessionId?: string; } interface ExportedSession { meta: ExportedSessionMeta; messages: ExportedMessage[]; } /** * Pure heuristic module that folds an exported session's messages into a * "story": chapters (inferred sub-tasks) + steps (one per fixed-height feed * row). Backs the `agentproto_session_story` MCP app panel. * * v1 = pure heuristics, NO LLM. Everything here is deterministic and * unit-testable so a future LLM-backed chaptering/summarizing pass can * replace the internals behind the same `buildStory(messages) => Story` * interface (mirrors the summarize_session heuristic → LLM swap path * described in summarize-session-tool.ts). * * Folding rule (mirrors transcript-export.ts's own batching): an assistant * message plus every immediately-following `role: "tool"` message collapse * into ONE step. A user message is always its own step, and is also a * candidate chapter boundary. */ type StoryStepKind = "text" | "edit" | "bash" | "read" | "user"; type ChapterStatus = "done" | "cur"; type RouteVerdict = "cont" | "newt"; interface StoryChapter { id: string; title: string; status: ChapterStatus; } type StoryItem = { text: string; } | { h: string; r: string; }; interface StoryStep { chap: string; kind: StoryStepKind; /** HH:MM:SS (UTC) when the source message carried a `ts`, else "". */ ts: string; sum: string; raw1: string; count: number; facts: string[]; items: StoryItem[]; route?: RouteVerdict; } interface Story { chapters: StoryChapter[]; steps: StoryStep[]; } /** Dominant kind for a group of tool calls: edit/write → edit, bash/terminal/ * command → bash, read/grep/glob → read, else text (pure assistant text). */ declare function classifyKind(toolCalls?: readonly { name: string; }[]): StoryStepKind; declare function classifyRoute(text: string): { route: RouteVerdict; title?: string; }; declare function buildStory(messages: readonly ExportedMessage[]): Story; export { type ChapterStatus, type ExportedMessage, type ExportedSession, type ExportedSessionMeta, type RouteVerdict, type Story, type StoryChapter, type StoryItem, type StoryStep, type StoryStepKind, buildStory, classifyKind, classifyRoute };