Make the OpenCode 2 lane deliver its tools, sidebar, commands and compaction-off parity

Draft
BL
2mo ago
+1798-232

Approved issue: #<needs one — no current open issue covers this lane work; see "No matching issue" below>
Closes #488

Harness coverage (required)

  • OpenCode 1: covered — the v1 lane's paths are untouched by these commits; the one shared helper they touch (the model-recovery probe in read-session-db.ts) detects 1.18 stores and keeps the existing v1 path, pinned by store-reader tests.
  • OpenCode 2: covered — this branch's subject. Full suite green and verified live on a real OpenCode 2 install (tools, sidebar numbers matching the host counter, /ctx-* commands, /ctx-dream, compaction-off mode).
  • Pi: covered for the two shared modules this branch changes — dreamer/task-scheduler.ts (canonical-prune fix; imported by pi-plugin/src/dreamer/index.ts) and recomp-orchestrator.ts (additive executor seam; imported by pi-plugin/src/commands/ctx-session-upgrade.ts). Both are behavior-preserving/beneficial on Pi and pinned by the shared suite. Not applicable for the OpenCode-only surfaces (the v2 plugin lane, the OpenCode store probe, the OpenCode TUI).
  • OMP: covered the same way as Pi via the shared Pi/oh-my-pi core for those two modules; not applicable for the OpenCode-only surfaces (there is no OMP-side v2 lane).
  • Rust module: not applicable — surface does not exist there (the v2 lane never enables the Rust transform mode — no transformMode wiring — and crates/ is untouched).

Base: v0.42.6 (698f572) · 13 commits · 27 files, +1,798/−232

Why

Magic Context ships an OpenCode 2 (v2) plugin lane, but on a real v2 install large parts of the product never engage: the ctx_* agent tools are never registered, the sidebar/status have no data source, /ctx-* commands don't exist, /ctx-dream can't run, context percentages read 0.0%, and projects with MC compaction disabled get nothing at all while the host compacts natively. These commits fix the v2 lane, verified live against OpenCode 2.

What this changes

1. Register the ctx_* tools on the v2 lane (8b4e91a) — the lane never registered the agent tool set. It now registers the same set as v1 through the codemode bridge, self-gating compaction-off.

2. Start the RPC server the TUI reads (753e7d8) — the v2 TUI is a pure RPC client, so without the plugin's server the sidebar/status render zeros. The lane now starts the same surface as v1, handed its draft-authoritative live maps, deferred one task so the server's filesystem writes stay outside the host's plugin-construction deadline.

3. Register /ctx-* from the app slot (d552baa) — the host's keymap provider isn't mounted during plugin setup; the lane now claims the always-mounted app slot and registers the command layer from its first render (the host's own bundled btw plugin uses the same pattern), with a warn-once fallback.

4. Compaction-off parity (94d70a3) — the lane early-returned when MC compaction is disabled, giving such projects no tools, no RPC, no memory/docs injection. It now skips only the compaction machinery and keeps the tool registry, RPC surface and the shared transform. TUI mirrors v1's compaction-off rows.

5. Repair the sidebar/status numbers (7e2c045, d198f78) — usage was never persisted on v2 (0.0% forever); the harness-keyed model-limit cache was never warmed (everything fell back to 200k, disagreeing with the transform's math); model recovery read only the frozen v1 tables. Now persists the lane's own measurement (pre- and post-transform), warms from context.model.list(), prefers session_message with a v1 fallback. Numbers match the host's own counter.

6. Wire /ctx-dream (0060ce7) — manual dream runs, capability-filtered (requiresTools tasks reported as unsupported rather than failed), executor seam threaded.

7. Review-round hardening (2c5c944, 58fbe49, d4c903d, 6fdab93, 88fb463, d4d0e92) — five adversarial review rounds: fail-closed guards, a switch-turn admission fix, per-session usage isolation, numeric guards; the scheduled dream capability filter and a canonical-prune data-loss fix; session.deleted teardown with raced-pass tombstones; partial-token guards; re-anchored e2e static guards; a comment documenting the fold materializer's deliberate cacheExpired: false.

Relationship to #477

Deliberately excluded — #477 is its own open PR. Note: on a store migrated from 1.18 the lane needs that guard to engage at all, so this branch alone no-ops there; native v2 stores work standalone. Happy to fold it in or reorder if preferred — and it rebases cleanly if #477 lands first.

Testing

  • Full plugin suite 4963/0 on this branch; typecheck clean.
  • Touched e2e contract files adapters-s2-contracts 10/10, store-reader 5/5; the rest of that suite fails environmentally on this macOS box (base reproduces it).
  • Live-verified on a real OpenCode 2 install: tools callable, sidebar matching the host counter, /ctx-status//ctx-recomp present, /ctx-dream running supported tasks, compaction-off behaving like v1.

Known gaps (unchanged from base)

/ctx-recomp//ctx-session-upgrade notify path inert without a v2 client seam (the runner itself now gets the executor) · v2 tool context has no directory (project identity falls back to the launch dir) · orphan session_meta rows on session deletion.

Notes for reviewers

Commits are self-contained — cherry-pick freely. Happy to split if preferred.

Process note (CONTRIBUTING.md) — drop before submitting

CONTRIBUTING.md (on master) requires an approved issue before a PR can leave draft: open a bug/design issue, wait for a maintainer to apply design-approved, and keep this PR in draft until then — the gate auto-converts unapproved ready-for-review PRs to draft and comments. Closes #<issue> goes in the body above once the issue exists. There is no docs/test bypass (only a maintainer trivial label).

I scanned all 19 open issues: none is an approved issue for this work. Nearest, for cross-linking rather than closing:

  • #475 — Migration 85 relabels a real OpenCode 2 host's rows to opencode — adjacent (same "v2 hosts don't behave" family) but a migration-labeling defect this branch does not touch.
  • #483 — OpenCode 2: historian always fails on OpenAI ChatGPT-subscription login (max_output_tokens) — a distinct provider-parameter defect; the lane fixes here do not change it.
  • #481 (closed) — every failed historian run leaves a hidden session behind — already closed.

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Summary by cubic

Previously, the OpenCode 2 plugin lane was mostly inert on a real OpenCode 2 install. This branch brings it to parity with the v1 lane.

What changed

  • Registers the ctx_* tool set and starts the RPC server the v2 TUI reads; compaction-off projects keep tools, RPC, transform, and sidebar rows.
  • Registers /ctx-status, /ctx-recomp, and /ctx-dream from the always-mounted app slot and reports dream results as an RPC dialog.
  • Persists the lane's own usage measurements, warms model limits from the host catalog, and reads model recovery from session_message.
  • Applies the same capability filter to scheduled and manual dream runs and prunes schedule rows against the canonical task set.

Side effects

  • OpenCode 1.18 stores keep resolving through the existing v1 read path.
  • Hidden-completion runs tolerate missing or non-numeric token fields instead of aborting the whole run.
  • Native v2 stores work standalone; v2 stores migrated from 1.18 still need the separate migrated-store guard before the lane engages.