Files
devvm/internal/structure
w3cjandClaude Opus 5.5 6391a8ba48 fix(agents): opencode 2's history exports leave its credentials out
opencode 2 keeps its sessions and its logins in one SQLite database,
~/.local/share/opencode/opencode.db (opencode-<channel>.db for other
channels), in WAL mode, so the history export, which tarred
~/.local/share/opencode, carried its credential table (logins, API keys,
MCP OAuth tokens), account and control_account (its console's access
and refresh tokens) and session_share's secrets to this machine, and an
import gave them to another VM. The -wal file carries them too: it holds
full page images of what opencode wrote last, a just-saved credential
row among them, until a checkpoint, and opencode makes it at once.

The export now copies each database in the VM with sqlite3 (base
installs it: sqlite3 on Debian and Ubuntu, sqlite on Alpine), keeping
the sessions: VACUUM INTO (one snapshot, the WAL's rows included); every
trigger dropped; the login tables emptied (credential, account,
control_account, account_state, session_share, and any table whose name
or a column's says it holds a secret, for tables a later opencode adds);
the record of opencode's auth.json import migration taken out, so the
next VM's opencode imports the logins devvm's setup wrote there; WAL off
and secure_delete with VACUUM, so no free page keeps a deleted row; then
the rows counted, and the database left out on any failure or without
sqlite3. tar leaves the database and its -wal, -shm and -journal files
out and adds the copy at its path (--transform, links' targets kept).
The import does the same in the VM to an export it unpacks (one devvm
didn't write may hold the logins): it deletes the -wal, -shm and
-journal files and any database that isn't a regular file, and puts in
the copy, or nothing. Every sqlite3 runs with trusted_schema off.
opencode 1's mcp-auth.json joins the logins left out.

Rejected: excluding the database (loses opencode's sessions);
opencode session export (runs opencode and its server per session, and
per project, which rm's export can't count on).

Security review (security-audit skill, guidance mode, data isolation
and lifecycle): export scope, the WAL, import of an export holding the
logins, a trigger restoring rows and a hostile schema each have a holder
and a test (design.md's threat check). Not covered, documented: a secret
pasted into a session stays in it; a VM without sqlite3 exports no
opencode database; a remake's home copy keeps the database's logins, as
it's the same VM's data going to the same folder's VM.

Tests: TestOpencodeClean (a running opencode's database, its credential
only in the WAL of an open connection, an account's tokens, a share's
secret, a later table's key and a trigger: none in any byte of the copy,
the session kept; a file that isn't a database gives none),
TestHistoryExportRuns and TestHistoryImportCleansOpencode (GNU tar, with
and without sqlite3); the CLI tests' export calls; e2e's network section
plants a key with the VM's sqlite3 and finds neither it nor the login's
placeholders in devvm history export's file.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-06 00:36:16 -07:00
..