Repository navigation
fix(opencode): migrate Firstmate plugins to the V2 API so they load on OpenCode 2.x - #5108
BajajGirik wants to merge 14 commits into
Conversation
… lifecycle events
OpenCode 2.x renamed the transcript tables. The live end-to-end test still read `session`, `message`, and `part`, which are now frozen V1 leftovers that a 2.x run never writes, so the test could not reach the migrated plugins. Read `session_v2` and `session_message` instead. The V2 message row carries its role in a `type` column and holds assistant text in a `content` JSON array, so the assistant queries expand that array rather than joining `part`.
…y so turn-end SIGTERM cannot block watcher arming
… projection claim
|
Speaking as Kun's firstmate: whole thread read (first stamp; no prior comments/reviews; no linked closing issues; tip vs main HEAD: Contract-class:
VISION (per-rule, tip vs main inspected):
Security skim: no Closes: none linked. Outcome: Workflow approvals: CI |
|
Closing this PR in favor of a replacement that preserves the validated implementation and exact-head evidence. |
What broke
OpenCode 2.x refuses every Firstmate plugin:
All five plugins were written against the V1 API, which exported a named factory
that received
{ client, directory, worktree }and returned a hooks object. V2expects a default export with an
idand aneffectfunction that receives acontext object. No plugin loaded, so supervision, the turn-end guard, the
directory-change check, the pretool check, and the session-start nudge were all
silently inactive on OpenCode 2.x.
What this changes
Each plugin now exports a V2 default definition. A shared helper in
.opencode/plugins/lib/fm-v2-plugin.jsholds the parts every plugin repeats,so the five plugins keep one shape.
The event names moved too. V1
session.idleandsession.statusdo not existin V2. Supervision now keys on
session.execution.succeeded,session.execution.failed, andsession.execution.interrupted. Those three fireonce per turn, not once per step, which is what watcher arming needs.
bin/fm-spawn.shno longer passes--modelto OpenCode. V2 reads the model fromits per-launch configuration, so
opencode_config_content()writes it thereinstead. The other twelve harnesses keep the
--modelflag path unchanged.tests/fm-opencode-primary-live-e2e.test.shread the V1 sqlite tables, which V2froze in place. Its six queries now read
session_v2andsession_message. Theold tables still exist and still answer, so the test passed while never reaching
a migrated plugin.
A real bug found on the way
fm-primary-watch-arm.jsread the git root identity with an async child processinside the turn-end path. A SIGTERM arriving during that read left the promise
unsettled and the watcher never armed.
revParse()now usesspawnSync, so theread completes before a signal can interrupt it.
runProcess()also reportscode: 128on a signal kill instead of thenullthat Node passes through.Verification
All five affected suites pass, 239 assertions total:
fm-pi-watch-extensionfm-turnend-guardfm-busy-adapter-wiringfm-sessionstart-nudgefm-spawn-dispatch-profileopencode plugin listloads all 8 plugins on 2.0.11.The
session_v2migration was confirmed against the real database by comparingmax(time_created)between the legacy and V2 tables. The legacy tables stoppedreceiving rows 28 days ago.
Every change is scoped to OpenCode. The only non-OpenCode file touched is
bin/fm-spawn.sh, where the change is behind[ "$HARNESS" = opencode ].Ran through the no-mistakes pipeline: intent, rebase, review, test, document, and
lint all passed.
🤖 Generated with Claude Code