Skip to content

feat(onboarding): import local OpenCode 2 conversations - #35

Open
Rooster-Cogburn77 wants to merge 1 commit into
MiaAI-Lab:mainfrom
Rooster-Cogburn77:feat/opencode-session-import
Open

Rooster-Cogburn77 wants to merge 1 commit into
MiaAI-Lab:mainfrom
Rooster-Cogburn77:feat/opencode-session-import

Conversation

@Rooster-Cogburn77

Copy link
Copy Markdown

Problem

An existing OpenCode 2 session can be resumed by OpenCode, but M3's Welcome page cannot discover it. With the local OpenCode provider enabled, a repository used only in OpenCode is missing from the import list.

Change

Welcome now offers local OpenCode 2 conversations alongside Claude Code, Codex and Pi. An imported thread keeps its native session ID so the next turn resumes the original conversation. In an earlier Windows trial, 43 conversations imported and one continued for four M3 turns on the same OpenCode session.

For each enabled local provider, the scanner runs its configured executable with debug paths db and its provider environment. It opens the reported database read-only. The OpenCode command itself can create its log and repos directories and write opencode.log. An external server, failed lookup or in-memory database contributes no local history. Discovery lists top-level, unarchived sessions without reading message bodies. Import rechecks eligibility and streams messages from one SQLite snapshot. The raw read budget charges stored bytes, while the retained-history limit accounts for in-memory text separately.

Scope

This adds a source to the shared Welcome import flow. M3 keeps up to 200 visible messages per imported thread. Later turns written in another client do not live-sync into that view. A message edited in place without advancing the session timestamp or the last message sequence will not trigger rediscovery. The upstream discussion of this design is in T3 #2754 and #207.

Verification

  • All 13 OpenCode tests passed (12 scanner, one importer). The branch tests cover database selection, archiving between listing and import, continuation by native ID, and exact versus one-byte-short budgets for ASCII, CJK, and emoji. Run the following from apps/server.

    vp test run src/project/AgentSessionScanner.test.ts src/project/AgentSessionImporter.test.ts -t "OpenCode|OPENCODE_DB"
  • On Windows, 151 server tests passed, six failed at symlink creation under this account, and seven were skipped across the scanner, importer and WebSocket suites. The six failures also occur on the base revision. All 19 Welcome-page browser tests passed in Chrome. The repository pre-commit hook passed formatting, lint and knip on the six staged files. The server typecheck still reports the four known base diagnostics. The full pre-push check also encountered the six Windows symlink failures, and its default Playwright Chromium executable was missing. The 19 browser tests above used installed Chrome.

  • The two screenshots were captured from the base and feature branch against the same synthetic histories. Both show the same agent order and the same OpenCode model-list warning. On the base, acme/widgets shows six conversations and docs shows four. On the branch, widgets gains three OpenCode conversations and the OpenCode-only project acme/api appears with four. The docs count stays at four. The branch used the installed OpenCode CLI to resolve a named database.

  • Verification was on Windows. Peak process memory and macOS/Linux behavior were not measured.

Before (base 6a8f1b0)

Before: Welcome lists docs and acme/widgets, two projects.

After (feature branch)

After: Welcome includes acme/api and counts OpenCode conversations, three projects.

Implementation and review used GLM-5.4 through OpenCode and GPT-6 through Codex.

The Welcome page imported existing conversations from Claude Code,
Codex and Pi only, so a conversation started in the OpenCode app never
reached M3 Code. OpenCode keeps every session in one SQLite database
instead of one file per session, so the scanner had no source for it.

Add OpenCode as a fourth import source. The scanner asks each enabled
provider's configured OpenCode executable for its database with
`debug paths db`, in that provider's environment, and opens only the
file it names. It lists the top-level, unarchived sessions in
session_v2 without reading a message, taking each session's last
message sequence from OpenCode's index, and reads a session's visible
user and assistant text from session_message the way the Pi branch
reads plain message records.

An OpenCode session stands in for a transcript file: its row names its
folder, and its last sequence number and its own time take the place of
the file's size and time, so an unchanged session is recognised as
already imported. The session's row and its messages are read in one
transaction, which leaves out a session archived after it was listed. A
provider set to use an external server is not searched, since it could
not continue a local conversation. Rows are read one at a time under the
transcript reader's limits. The byte budget is charged as rows are read,
in the bytes SQLite stores, and a cut-off list is reported as such.

An imported thread is bound to its OpenCode session ID, so continuing
it continues that session rather than a copy.

Only OpenCode 2's session tables are read. Tests stand in for the
OpenCode executable, so they never consult a developer's real history.
@github-actions github-actions Bot added vouch:unvouched Author is not yet trusted in the VOUCHED list. size:XL labels Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XL vouch:unvouched Author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant