Repository navigation
Conversation
2.x writes new sessions to `session_v2`/`session_message`, renamed `opencode import` to `opencode session import`, and takes a different import document. Detect the live schema and discover, load, fingerprint and archive 2.x sessions through the new tables; saving flattens the export into the 2.x document when the database speaks it. The import path handles what 2.x actually does: the project id is read from the `project` table (matching worktree ancestors, so repo subdirectories work) and falls back to OpenCode's own `global` sentinel, since the server derives the project from --directory; a duplicate id is reported as an error because the CLI exits 0 after a 409; inline `[Image N]` markers are reused instead of duplicated; mention offsets use UTF-16 code units like the composer; and attachment payloads are normalized to canonical base64 the way OpenCode's own 1.x migration does.
Absorbs what upstream skillsynchq#97 found against the 2.x source: - 2.x renamed the built-in tools and input keys (`bash` is `shell` with `timeout`/`background`, `filePath` is `path`, `task` is `subagent`, `Skill` is `skill` with `id`, `WebSearch` is `websearch`, `grep` takes `include`/`limit` and the inverse `caseSensitive`). Map them both ways: a 2.x session reads as the tools txcript knows and writes back with the names OpenCode's UI renders. - Force tool input to an object; 2.x validates a record, and a freeform Codex code-mode call would otherwise reject the whole import. - Carry the tool call's timing onto the part and write the full token object the schema validates, instead of zeroed timestamps and a partial 1.x object. - Choose the import document and command from `opencode --version`, not the database: an upgraded CLI migrates an old database on its next start, so the import can legitimately run first. This replaces the `opencode session list` bootstrap. - The text form is the 2.x `session export` document and `from_text` reads both layouts, so the WASM converters round-trip with the current CLI. - Records with no 1.x shape (`compaction`, `idle`, `shell`, `system`) ride through a load and an export unchanged, and synthetic user text becomes its own `synthetic` record. Verified against sst/opencode (`packages/core/src/tool/plugin/*.ts`, `packages/schema/src/session-message.ts`).
Author
|
Follow-up pushed (
Credit to @acaprino — the tool-rename table and the CLI-generation signal came out of #97. Both are verified here against Verification: 20 opencode library tests (was 14), 495 workspace tests, |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue: #96
What changed and why?
OpenCode 2.x moved new sessions to
session_v2/session_message(each message is one flat record), renamedopencode importtoopencode session import, and flattened the import document. txcript'sopencodeharness only knew the 1.x tables and command, so discovery found nothing andcontinue --with opencodefailed against a 2.x database.This PR detects which generation the live database speaks and supports both:
{info, parts}record the 1.x path already understands, so both generations converge on one code path.{type: "user", text, files}/{type: "assistant", content}) and handed toopencode session import --directory …; 1.x databases keep the legacyopencode importpath.Writing also mirrors what 2.x actually does:
info.projectIDandinfo.locationare schema-required but ignored by the server (it resolves the project from--directoryand rewrites the stored row). txcript emits the real project row id when the read-onlyprojecttable matches — including from a repository subdirectory, since OpenCode stores the canonical git/hg root — and falls back to OpenCode's ownglobalsentinel otherwise.[Image N]markers already present in the text are reused instead of duplicated, and mention offsets are written as UTF-16 code units, matching how the composer places extmarks.Before:
txcript list --from opencode→no local opencode sessions found;continue --with opencode→`opencode import` failed.After:
txcript list --from opencodelists the 2.x sessions andcontinue --with opencodeimports them throughopencode session import.This is an independent implementation of issue #96 and overlaps in scope with #97; it additionally covers the project-id fallback, duplicate-id detection, payload normalization and marker/offset edge cases listed above.
Verification
cargo test -p txcript --lib --features opencode opencode: 14 passed.cargo test --workspace --all-features: 489 passed, 0 failed.cargo clippy --workspace --all-featuresandcargo fmt --checkclean.