/** * OpenCode session importer. * * OpenCode stores sessions as a small object graph under * `~/.local/share/opencode/storage`, rather than one append-only file per * session the way Claude Code does: * * session//.json metadata, incl. a diff summary * message//.json one file per message * part//.json text, reasoning, tool calls, patches * project/.json worktree path and vcs * * Three things make this source materially better than the Claude Code one, * and the importer is written to exploit all three: * * 1. Assistant messages carry a `cost` the agent computed itself. Where that * is non-zero we report it as fact and mark the usage non-estimated, rather * than modelling dollars from a price table that can go stale. * * 2. The session record carries `summary.{files,additions,deletions}` — a * repository-level diff independent of the tool stream. That is the closest * thing in either source to ground truth about what actually changed. * * 3. Tool calls carry an explicit `state.status`, so denial and error are * distinguishable without string-matching output. * * Ordering is by id, not by directory order: OpenCode's ids are monotonic * within a session, which is what keeps parts attached to the right message * when timestamps collide. */ import { type Run } from "../model.js"; import type { DiscoveredFile, Source } from "./types.js"; type Json = Record; export declare function storageDir(): string; /** A message and the parts belonging to it, already ordered and parsed. */ export interface MessageWithParts { msg: Json; parts: Json[]; } export declare class OpenCodeSource implements Source { readonly name = "opencode"; /** Cached read-only handle, keyed on the resolved path. */ private conn; private readonly notices; /** * Open — or reuse — the database handle. * * Keyed on the resolved path because the registry hands out singletons while * `flightrec demo` and several tests move `OPENCODE_STORAGE_DIR` mid-process. * Without the key a source would happily serve the previous root's data. */ private db; private legacySessionFiles; /** * Is there OpenCode data here — not merely an OpenCode-shaped directory? * * This used to be one `statSync` on `storage/session`. OpenCode migrated to * SQLite in February 2026 and left that directory behind, so the check kept * answering yes against six months of frozen files. Presence of a container * is not presence of data. */ available(): boolean; /** * One "file" per session, from whichever backends have data. * * The database wins where both have a session, which on any migrated install * is everything: it is a strict superset, holding the legacy sessions plus * everything written since. Legacy-only sessions are still returned, because * an older OpenCode install has no database at all and a partially-migrated * one is not ours to assume away. * * Two backends rather than two registered sources on purpose: `makeRunId` * keys on the source *name*, so a second source called `opencode` would mint * identical run ids and the two would fight over one row. */ discover(): DiscoveredFile[]; /** Anything this scan noticed that a user should know. Drained by `ingest`. */ notes(): string[]; close(): void; load(path: string): Run[]; /** Dispatch on the path shape: synthetic paths carry a database and a session id. */ private read; private readFromDb; private readFromFiles; /** * Same rule as the Claude Code importer: wall-clock silence ends a run. * * Splits on `message.time.created`, which is the one timestamp the SQLite * migration left intact — see the hazard note in `opencodeDb.ts`. */ private segment; private buildRun; /** * The session record carries a repo-level diff summary. It covers the whole * session rather than one segment, so it is only trusted for a single-segment * session — and only to *fill in* a diff the tool stream failed to capture, * never to overwrite one it did. */ private applySessionSummary; private handlePart; private handleTool; private recordEdit; private recordCommand; private accumulateTokens; } export {};