toolpath-opencode
Derive Toolpath provenance documents from opencode session databases.
opencode stores every conversation — sessions, messages, typed
parts, tool calls, filesystem snapshots — in a single SQLite
database at ~/.local/share/opencode/opencode.db. This crate reads
that database directly (read-only) and maps it to Toolpath
documents, so every opencode-assisted change has a traceable origin
with real unified diffs reconstructed from the sibling snapshot
git repositories.
Overview
- Reading: open
opencode.dbwithrusqlite, enumerate projects and sessions, materialize typedMessage/Partrows from the JSON-in-TEXTdatacolumns. - Provider: implements
toolpath_convo::ConversationProvider, pairingtoolparts bycallID, foldingreasoningparts ontoTurn.thinking, and capturingstep-start/step-finishsnapshot SHAs onTurn.extra["opencode"]for file-artifact reconstruction. - Derivation: produces
toolpath::v1::Pathdocuments. When the matching snapshot git repo is still on disk, file changes per turn surface as sibling artifacts with a realgit diffas therawperspective — no diff reconstruction from tool output required.
Mapping
| opencode source | Toolpath destination |
|---|---|
session.id |
path.id = path-opencode-<first-8> |
session.directory + project.worktree |
path.base = { file://<worktree>, ref: <project-id> } |
User message |
Step with actor: "human:user" |
Assistant message |
Step with actor: "agent:<modelID>" |
reasoning part |
Turn.thinking (plaintext — safe to render) |
text part |
appended to Turn.text |
tool part (state: completed) |
Turn.tool_uses[] with input + result |
tool part (state: error) |
same, result.is_error = true |
step-start / step-finish snapshot SHA |
sibling file artifacts on the turn — unified diff as raw |
compaction / retry / patch / unknown parts |
ConversationEvent |
Usage
use ;
let manager = new;
let session_id = "ses_24ee4deb6ffeWw7ZKWNVoOAgjD";
let convo = manager.read_session?;
let path = derive_path;
# Ok::
CLI
What's not read
auth.json— live OAuth / API-key credentials. Deliberately never read to avoid leaking secrets into derived documents.log/*.log— process logs (same content already lands in the DB).bin/,cache/,node_modules/— transient caches.event,event_sequencetables — reserved for the sync service; observed empty in practice.
See
docs/agents/formats/opencode.md
in the workspace for the full on-disk format reference.
Part of Toolpath
This crate is part of the Toolpath workspace. See also:
toolpath— core provenance typestoolpath-convo— provider-agnostic conversation abstractiontoolpath-claude— Claude Code providertoolpath-gemini— Gemini CLI providertoolpath-pi— Pi (pi.dev) providerpath-cli— unified CLI (cargo install path-cli)