Galaxy Shell / docs
Docs / Decisões e planos

Migration to OpenCode 2

openspec/changes/archive/2026-10-26-opencode-v2-migration/design.md · Editar no GitHub ↗

Esta página ainda não tem tradução em português. O conteúdo abaixo está em inglês.

Este documento registra decisões, planejamento ou evidências de uma etapa do projeto. Não implica que todos os itens estejam implementados ou validados na versão atual.

Nesta página

Migration to OpenCode 2

Doc status: history. Migration done on 2026-10-26 (OpenCode 2.1.4, still pinned); kept as the record of that migration. Checked 2026-11-10.

Implemented on 2026-10-26, with OpenCode 2.1.4, @opencode/client 2.1.4 and @opencode/plugin 2.1.4. The installer includes V2 without requiring a global OpenCode. The separate manifest runtime/opencode-package/package.json and its lock pin @opencode/cli and the native packages with npm integrities. scripts/bundle-opencode.sh installs into a temporary private staging directory, copies only the executable, removes the build packages and writes runtime/opencode.json with version, origin and SHA-256. AGENT_NATIVE_OPENCODE_BIN accepts an explicit executable of the same version. It does not change the global OpenCode.

Data and continuity

The core creates opencode-v2.db in the shell data directory with VACUUM INTO from a read-only connection to the original OpenCode database. The copy includes transactions committed in the WAL. OpenCode converts the schema and the messages in this copy. The original database stays available for a return to V1. New profiles without a previous database start empty. The existing copy is never overwritten at the next startup.

The session IDs, state.json, inline components and visual revisions remain. V2 moves the sessions that belong to the profile to the stable directory opencode-project, without recreating the conversation. The paginated V2 history is translated to the shell contract, including the outputs of inline publishing. This does not assume equivalence of every internal execution detail of V1.

The plugin opencode-codex-memory 0.9.12 uses its V2 adapter. The memory folder and its databases, notes and summaries keep the same destination. Session discovery is filtered by profile IDs and by auxiliary memory directories, including pages without matches. OpenCode itself manages credentials. The renderer receives only connection state. The catalog allows only free models with known prices or ChatGPT plan routes confirmed by OAuth. Empty prices are accepted only for this OAuth route, as V2 represents it. There is no paid fallback.

Return and verification

Before switching the shared runtime, obtain coordination.lock, confirm that no response is in progress, and create a private backup of the full profile and a consistent SQLite copy of the original database. Do not put backups in Git. To return to the V1 host, stop only the V2 host/core, preserve its new data and select the previous release with the same profile and Wayland socket. V1 uses its original database, not opencode-v2.db. New V2 turns are not automatically exported to the V1 database.

Implementation evidence: 58 Node tests, formatting and syntax analysis. A real V1 fixture converted by V2 preserved ID and content without a model call. The browser showed a synthetic history and the V2 catalog. The memory turn with a free model hit the provider quota, with no fallback. Activation on TTY4 used the release release-V0lLd7SN in ~/.local, the transient user unit agent-native-tty4-shell-v2-bundled.service, the same river-shell profile and the socket wayland-1. It did not update /usr/local or the boot configuration. The compositor stayed on PID 314875, started at 15:24:25 -03:00. The terminal created in the test stayed on PID 332778 after the host replacement. The host unit uses KillMode=process so it does not end detached applications together with the service.

Before the migration, there were 3 conversations and 34 messages. The exact comparison of the state of the three conversations and of the interface bundle passed before and after the tests. The three IDs exist in the V2 database and the SDK checked the user messages. The schema and the rows of the product's own sessions in the original database stay identical to the private backup. A synthetic QA conversation was added and preserved for inspection.

Memory: the folder did not exist in the previous TTY4 profile. The test created a synthetic note through the tool memory_add_note. Five text files kept the same hashes after restarting host/core. memory_search recovered the saved identifier after the restart. OpenCode confirmed OAuth, and the turns used the already selected model openai/gpt-6-luna, with reported cost of zero.

Browser connected to the TTY4 core: history, model selection, sending, end of the response and recovery of the note verified. The agent called desktop_state and open_application. The WM confirmed an agent-native-terminal window on the right. publish_surface produced an isolated HTML counter rendered inline. A first publication with meta was correctly rejected, and the agent fixed the document. The automation found the button but returned a target/focus error in the isolated frames. The counter update by click was not proven.

Electron host and real system: the process uses the release above and runtime/opencode 2.1.4. The Electron window is registered in River, the renderer is separate, and the compositor and terminal were preserved. No capture of the native composition on the monitor was obtained, and audio was not tested in this migration. The browser captures are evidence of the shared core, not visual proof of the Electron composition.

Packaging: a full installation without AGENT_NATIVE_OPENCODE_BIN and without OpenCode on the PATH passed. The self-contained binary ran with an empty environment and a PATH without commands. The SHA-256 matches the runtime in use on TTY4. The npm staging was removed. Manifests, executables and data have distinct responsibilities:

Location Responsibility
web-shell/core SDK adapter, policy and lifecycle
runtime/opencode-package Build manifests and integrities of the version
release/runtime/opencode Distributed self-contained executable
profile/opencode-v2.db and memory/ Conversations and memory outside the release

The four related chats completed the handoff, recorded the state in coordination.log and were archived. Earlier worktrees and commits were preserved.

Sources: https://opencode.ai/v2/docs/migrate-v1/ and https://opencode.ai/v2/docs/api .

The minimum Node version of the core becomes 22.13, when node:sqlite stops requiring a flag, for the initial consistent database copy. The validated release uses Node 24.19.0. Reference: https://nodejs.org/download/release/v22.13.0/docs/api/cli.html .

After the final restart, the WM rediscovered the two windows and kept their processes. The layout went back to the registration order: terminal on the left and conversation on the right. The current arrange_windows tool only offers tile, with no explicit reordering. The agent correctly reported this limitation in the test. This migration did not add persistence of the layout order.