Repository navigation
Conversation
OpenCode 2 replaced the V1 plugin API, so every plugin that returns a hooks
object from a named export fails to load with "Plugin must export a default
definition with an id and an effect or setup function". That left the OpenCode
primary with no watcher continuity, no turn-end guard, and neither pre-tool
seatbelt.
Port the five tracked primary plugins and the fm-spawn-generated busy-state
plugin to the V2 shape: a default export carrying an id and setup(ctx), events
through ctx.event.subscribe(), prompts through ctx.session.prompt, and tool
interception through ctx.tool.hook("execute.before", ...). V2 carries each
event's fields under data, so a session id is event.data.sessionID.
Drive the ported plugins from a shared Node host in the tests, and update the
behavior docs that named the V1 hooks. Also replace one fixed wall-clock wait
in the Pi watch suite with an iteration-counted poll loop, because it failed
under load on a clean checkout of the same revision.
Verified on OpenCode 2.0.28: all five primary plugins report active, where the
same query against a V1-shaped checkout reports five load failures.
|
Speaking as Kun's firstmate: first look at #7228 — thank you @gmach. What I inspected: full diff (21 files). Ports the five tracked OpenCode primary plugins plus the Contract-class: restore. OpenCode primary already had watcher continuity, turn-end guard, and pre-tool checks under the V1 plugin shape; OpenCode 2 refuses that shape, so the specified primary path was broken. This restores that path on the V2 API rather than adding a new unconfigured surface. VISION.md per-rule: One captain, one interface — aligns (supervision stays below deck). Authority explicit — aligns (no new consent surface). Scripts/agents split — aligns (hooks call existing scripts). Restart is a non-event — aligns (watcher/turn-end continuity restored). Delegation with a spine — aligns. Outlives any vendor — aligns (contracts bind to OpenCode 2 semantics; version-noted). Scope — aligns (command-layer supervision, not workshop). Security: no tip. Approved first-time fork CI runs Next: waiting on those approved runs. If green, this is auto-merge-eligible (restore) once main is green too. Nothing needed from you unless CI surfaces a real failure on this change. |
…aused by this PR, and it is now fixed. Invariant: every test script must parse under stock /bin/bash 3.2. Bash 3.2 tracks single quotes inside a quoted heredoc that sits inside `$( ... )`. The PR added two lines with apostrophes inside these node heredocs in tests/fm-pi-watch-extension.test.sh: the comment "the successor's own startup", which is unbalanced, and the message "another location's ... location's watcher". The first one made 3.2 fail with "unexpected EOF while looking for matching `)'" at line 461. I reworded both lines so they have no apostrophes. The meaning of the comment and the error message is unchanged. I swept every sibling site by running `/bin/bash -n` on all tests/*.sh and bin/*.sh: all of them parse now. Before the fix, the HEAD version reproduces the exact CI error under the local stock bash 3.2.57. After the fix, it parses cleanly. I did not run the full Pi suite again, because the edit only touches a comment and an error-message string. ci-1 (Behavior portable parallel 1) was not caused by this PR, so I made no change for it. The only failing script is tests/fm-pi-primary-types.test.sh, which reports TS2339 "Property 'prompt' does not exist on type 'BeforeAgentStartEvent'" in fm-branch-supervision.ts and fm-primary-pi-watch.ts. This PR does not touch either file. CI runs an unpinned `npm install -g @earendil-works/pi-coding-agent`, so the Pi package's API changed upstream. The latest CI run on main (7df545b) fails with the identical TS2339 errors in the same test. Fixing that drift needs its own change: either pin the Pi package version or update the Pi extensions to the new API
|
Speaking as Kun's firstmate: thanks @gmach. Since my 18:38Z stamp, no-mistakes added The Behavior portable parallel 1 failure ( Contract-class: restore (unchanged). VISION verdict unchanged: all rules align. Where it stands: waiting on CI and on main going green, not on you. Once both are green, this is on track to merge without anything more from you. Heads-up: #7231 edits the adjacent lines of |
What Changed
fm-primary-cd-check,fm-primary-pretool-check,fm-primary-sessionstart-nudge,fm-primary-turnend-guard,fm-primary-watch-arm) and the busy-state plugin thatbin/fm-spawn.shgenerates into the OpenCode 2 shape. Each one is now a default export with anidandsetup(ctx). Events arrive throughctx.event.subscribe()with their fields underevent.data, prompts go throughctx.session.prompt, and tool interception usesctx.tool.hook("execute.before", ...). OpenCode 2 refuses to load plugins in the old V1 named-export shape, so the OpenCode primary had no watcher continuity, turn-end guard, or pre-tool checks.tests/opencode-plugin-host.mjs) that the OpenCode plugin tests now use. The behavior docs, the harness reference and the supervision verification notes now name the V2 hooks and describe what was verified live: plugin load on OpenCode 2.0.28. In the Pi watch test suite, a fixed wall-clock wait is now a poll loop that counts iterations, because the wait failed under load.🤖 Generated with Claude Code
Risk Assessment
✅ Low: The fix round adds location filtering, a root-keyed coordinator and per-event/resubscribe guards in exactly the shape the user prescribed; tracing foreign-location, missing-location (session.get fallback) and same-location events through every plugin produced correct outcomes, and the new host cases would fail without the filter.
Testing
I started a private OpenCode 2.0.28 background service with its own home and port, separate from the operator's service, and asked it which plugins load. In this worktree all five primary plugins and the rendered fm-spawn busy-state plugin come back
active. A checkout holding the base revision's V1 plugins returns fivefailedentries with the V2 loader error. The busy-adapter, watch-arm, turnend-guard and sessionstart-nudge suites pass in the Node host, including the cross-location assertions. Live event delivery was not driven: real busy/idle needs a model turn, and creating a session in the worktree would run the primary nudge against the default FM_HOME. Those scenarios are therefore untested live. With the widened iteration budgets left uncommitted in the worktree, the Pi suite passed fully (60 ok) on one serial run. It failed one timing-sensitive case on the parallel run and a different case on the other serial run. On the base revision it failed all three runs, at varying cases. The isolated service was stopped and its temp home deleted. The only worktree change is the widened Pi test.opencode service(port 49911, throwaway HOME)Evidence: Live plugin load status, ported plugins (HEAD)
Source: Live plugin load status, ported plugins (HEAD)
fm-primary-cd-check active fm-primary-pretool-check active fm-primary-sessionstart-nudge active fm-primary-turnend-guard active fm-primary-watch-arm activeEvidence: Live plugin load status, base V1 plugins (control)
Source: Live plugin load status, base V1 plugins (control)
Evidence: Live plugin load status, generated fm-busy-state.js
Source: Live plugin load status, generated fm-busy-state.js
Evidence: Raw /api/plugin response (HEAD)
Source: Raw /api/plugin response (HEAD)
Evidence: busy-adapter wiring suite log
Source: busy-adapter wiring suite log
Evidence: watch-arm suite log
Source: watch-arm suite log
Evidence: turnend-guard suite log
Source: turnend-guard suite log
Evidence: sessionstart-nudge suite log
Source: sessionstart-nudge suite log
Evidence: Pi suite intermittent failure at HEAD (serial run 1)
Source: Pi suite intermittent failure at HEAD (serial run 1)
Evidence: Pi suite failure at HEAD under parallel load
Source: Pi suite failure at HEAD under parallel load
Evidence: Pi suite failures on base revision 6407052 (runs 1-3)
Source: Pi suite failures on base revision 6407052 (runs 1-3)
Pipeline
Updates from git push no-mistakes
⏭️ **intent** - skipped
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 3 issues found → auto-fixed ✅
.opencode/plugins/fm-primary-turnend-guard.js:75- The ported plugins act on every session.idle / session.created / session.status event from the whole OpenCode 2 server, not only their own location. In OpenCode 2.0.28 every TUI connects to one shared background service by default (opencode --help:--standalone Run with a private server instead of the background service). fm-spawn starts crewmates with plainopencode --prompt(bin/fm-spawn.sh:2179), so the primary and every OpenCode crewmate share that server. The plugin context'sevent.subscribefilters only by event kind (binary:event:{subscribe:()=>D.subscribe().pipe($o((H)=>bX(H)||J8(H)))}). OpenCode's own code checks location itself: the built-in browser plugin rejects with "Session belongs to another location" whensession.location.directory !== ctx.location.directory, and the TUI drops events wheree.location.directory !== o.location.directory. V1 plugins ran in each TUI's own process and only saw that instance's events, so this is a regression.Concrete failure: a crewmate's OpenCode session goes idle while the primary's watcher is unhealthy. The primary's turn-end guard gets that crewmate sessionID,
fm-turnend-guard.shreturns 2 for the primary home, andctx.session.promptinjects "TURN WOULD END BLIND" plus primary recovery instructions into the crewmate's session. Same root cause at the sibling sites:globalThis.__firstmateOpenCodeWatchArmnow lives in one shared server process. A firstmate scout or crewmate worktree that loads the same tracked plugin overwrites the primary's coordinator, and the primary guard then consults the wrong root.Fix at the shared boundary: drop events whose location does not match
ctx.location.directory(the event envelope'slocation, orctx.session.get+location.directoryas OpenCode's own plugin does) before any handler runs, and key the coordinator by resolved root. tests/opencode-plugin-host.mjs never emits foreign-location events, so the suites cannot catch this. Add a host case that emits an event from another location and asserts nothing happens..opencode/plugins/fm-primary-watch-arm.js:576- Each plugin's whole event handling now runs in one fire-and-forgetvoid (async () => { for await (...) })()loop with no catch and no resubscribe. V1 dispatched each event separately, so one failure only affected that event. Now any rejection permanently and silently stops watcher continuity, the turn-end guard, the nudge, or busy-state for the rest of the server's life, and it surfaces as an unhandled rejection in the shared server. Rejections include a stream failure or disconnect (OpenCode documents its event stream as volatile: "a slow consumer overflows and fails the stream, and events during disconnection are missed") and a throw from awaited handler code. The loops also run handlers serially and stop pulling events while they wait, which makes a slow consumer more likely. The turn-end guard awaitsensureArmed->waitForArmReady(up to the readiness timeout) plus the guard script and the prompt. busy-state awaits an execFile for every event. Same pattern at: .opencode/plugins/fm-primary-turnend-guard.js:74, .opencode/plugins/fm-primary-sessionstart-nudge.js:52, bin/fm-spawn.sh:4861 (generated busy-state). Minimal fix: catch per-event handler errors inside the loop, and log or restart the subscription when the iterator rejects, unless the controller was aborted.docs/verification/supervision.md:277- The live evidence only shows that the five plugins load asactive. Event delivery, theevent.data.sessionIDshape,ctx.location.directory, andctx.session.prompt({sessionID, text})were exercised only against the hand-written host in tests/opencode-plugin-host.mjs, and the doc says the live TUI e2e is broken. The plugin header comments (e.g. fm-primary-turnend-guard.js:13-15, fm-primary-watch-arm.js:563-565) still say these runtime behaviors were "verified ... against OpenCode 2.0.28". The binary schema does matchsession.idle/session.createddata carryingsessionID, but the claim is broader than the evidence, which is how the cross-location issue above went unnoticed.🔧 Fix applied.
✅ Re-checked - no issues remain.
git -C ~/.no-mistakes/worktrees/d7a6e2db43ff/01M4TQVDAH624TRNEWAS7Y53CA statusandgit -C ~/.no-mistakes/worktrees/d7a6e2db43ff/01M4TQVDAH624TRNEWAS7Y53CA diff). Respond with fix to validate it, or abort.🔧 No changes applied.
1 warning still open:
tests/fm-pi-watch-extension.test.sh- tests/fm-pi-watch-extension.test.sh fails intermittently, at a different timing-sensitive case each run (e.g. 'actionable close must start one successor', 'dispatcher must hand an accepted wake to the branch', 'redundant tool call', 'external healthy watcher'). The base revision 6407052 failed all three of its three runs. HEAD, with the uncommitted iteration-budget widening, passed fully on one of two serial runs, so the flakiness predates this change. As the operator asked, it is reported here and was not investigated further.opencode service(port 49911, throwaway HOME)opencode service set port 49911 && opencode service startwith HOME/XDG_* pointed at a throwaway /tmp/oc-lab.* (separate from the operator's background service on 49374), thenopencode api get '/api/plugin?location[directory]=<worktree>'Same plugin query against a throwaway checkout holding the base-revision (6407052) .opencode/plugins (V1 control)Rendered the fm-spawn.sh opencode fm-busy-state.js heredoc into a throwaway crew worktree and queried its plugin load statusbash tests/fm-busy-adapter-wiring.test.shbash tests/fm-watch-arm.test.shbash tests/fm-turnend-guard.test.shbash tests/fm-sessionstart-nudge.test.shbash tests/fm-pi-watch-extension.test.sh(1x in parallel with the other suites, 2x serially at HEAD with the worktree's widened iteration budgets)bash tests/fm-pi-watch-extension.test.sh3x in agit archive 6407052extraction of the base revision✅ **Document** - passed
✅ No issues found.
🔧 **Lint** - 1 issue found → no changes applied ✅
🔧 No changes applied.
✅ Re-checked - no issues remain.
✅ **Push** - passed
✅ No issues found.