Skip to content

feat(opencode): add OpenCode 2 support with version-gated launch and plugins - #6525

Closed
nchandar wants to merge 2 commits into
kunchenguid:mainfrom
nchandar:fm/opencode2-pr-v1
Closed

nchandar wants to merge 2 commits into
kunchenguid:mainfrom
nchandar:fm/opencode2-pr-v1

Conversation

@nchandar

@nchandar nchandar commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Intent

The OpenCode 2 primary-plugin port is implemented and committed on branch fm/opencode2-verify-v1, verified to load clean on OpenCode 2.0.21 - all five fm.primary.* plugins now export a default definition with an id and a setup function, plus a new shared lib/fm-opencode2.js helper, because OpenCode 2 dropped the v1 server-plugin hook API.
Upstream firstmate at kunchenguid/firstmate has no OpenCode 2 support yet, so this work should be contributed back as a pull request.
Open that pull request.

What Changed

  • Detect the installed OpenCode major once at spawn (resolving the concrete opencode executable and probing --version, falling back to 1.x when undetectable) and key the launch shape, plugin shape, and recorded exit mechanics off that single resolved version: 2.x drops the top-level --model flag and rides the model/effort through OPENCODE_CONFIG_CONTENT (model pinned globally and on the build agent), while 1.x keeps --model and the agent.build.variant-only config (bin/fm-spawn.sh).
  • Add a shared .opencode/plugins/lib/fm-opencode2.js adapter and port all five fm.primary.* plugins to export a default definition with an id and setup(ctx), subscribing to session.execution.* events and hooking tool.execute.before through the OpenCode 2 server-plugin API that replaced the dropped v1 hooks; the turn-end guard fires only on root-session turn ends and is gated on notifyTurnEnd.
  • Record the detected OpenCode major in task meta so fm-control exits a 2.x composer with a raw Ctrl-C and a 1.x/undetected composer with /exit, and arm the busy-state contract on every detected major so OpenCode 1 keeps its existing wiring; update supervision/backend docs, add the port-scope doc, and extend the spawn-dispatch, busy-adapter, and control test suites.

Risk Assessment

⚠️ Medium: The change is well-structured, mirrors the retained OC1 patterns, and is covered by behavioral tests with only trivial findings, but it is broad and its correctness on OC2 rests on API-shape assumptions (promptSession delivery shapes, tool-hook throw-to-block) that CI cannot exercise without a live OpenCode 2, so it is safe to merge with those as monitored follow-ups.

Testing

Drove the OpenCode 2 port against the real product on this host (OpenCode v2.0.26, node v26). opencode plugin list loads all five committed fm.primary.* plugins cleanly with their declared default-export ids; an isolated adversarial control confirms OpenCode 2 surfaces the default export's id (valid plugin → its id, legacy v1 shape → -), so the positive result is meaningful. A node contract check confirms all five plugins, plus the real fm-spawn-generated v2 busy-state plugin, export {id, setup} and run setup() without throwing. The author's focused suites pass: fm-spawn-dispatch-profile (version-gated model/effort config shape, --model only on 1.x, unknown version→1.x, shared probe/launch executable, busy-plugin per major) and fm-control (exit key /exit on 1.x vs raw Ctrl-C on 2.x). The three OpenCode busy-adapter cases — skipped by an early abort in that file — were driven directly and pass, including the secondmate turn-end gating fix from 7b1b942. Visual evidence is N/A: this change is a CLI/plugin-runtime port with no rendered UI surface. One failure (a Claude secondmate Stop-guard case in fm-busy-adapter-wiring.test.sh) is environmental — the guard exits 0 because FM_HOME defaults to the host's real ~/github/firstmate and the temp sm-home isn't a recognized git scope — and lives in code byte-identical to base, so it is pre-existing and unrelated to the OpenCode 2 change. The upstream-PR half of the intent is owned by the PR phase, not this test phase.

  • Live validation: ✅ go - 7 of 8 scenarios driven live against the product
Scenario Result Live Evidence
All five fm.primary.* plugins load clean on OpenCode 2 (export a default definition with an id and setup) ✅ pass live opencode plugin list on real v2.0.26 lists all five with declared ids (opencode2-plugin-list.txt); node contract check confirms {id,setup} and setup() does not throw
Adversarial: OpenCode 2 loader distinguishes a valid default export from a legacy v1-shape plugin ✅ pass live Isolated project: valid {id,setup} plugin lists as test.good; legacy v1-shape plugin (no default export) lists with id -, proving the id reflects the real default export
Version-gate 2.x launch: model+effort ride OPENCODE_CONFIG_CONTENT, no --model/--variant/--effort ✅ pass live bash tests/fm-spawn-dispatch-profile.test.sh passes test_opencode_threads_model_and_effort_variant and test_opencode_without_effort_keeps_launch_config_unchanged (real fm-spawn + fake opencode repor…
Version-gate 1.x and unknown-version fallback: --model flag kept, variant-only config, undetected→1.x, probe/launch share one executable ✅ pass live dispatch-profile passes test_opencode1_passes_model_flag_and_variant_only_config, test_opencode_unknown_version_takes_1x_launch_path, test_opencode_probe_and_launch_share_resolved_executable
Busy-state plugin provisioned per major and the generated v2 plugin loads clean ✅ pass live dispatch-profile test_opencode_busy_plugin_provisioned_for_every_major passes; real fm-spawn-generated v2 fm-busy-state.js verified under node to export {id:'fm.busy-state',setup} (generated-fm-busy-s…
Busy-state semantic lifecycle: v2 maps session.execution.* scoped to latched session; v1 ignores execution events; secondmate does not touch parent turn-end ✅ pass live Three OpenCode busy-adapter cases driven directly in a Node host against the real generated plugin + real fm-busy-event.sh writer + real classifier — all ok
Exit-key version gate in fm-control: 1.x/absent → /exit, 2.x → raw Ctrl-C ✅ pass live bash tests/fm-control.test.sh passes 'a recorded OpenCode major picks /exit (1.x) or raw Ctrl-C (2.x)' (46 ok, rc=0)
Open the upstream pull request to kunchenguid/firstmate ⏸️ untested no Opening/pushing the PR is owned by the PR phase of the no-mistakes run; this gate-step is the test phase and is explicitly forbidden from running push/PR phases. No live product surface for the test p…
Evidence: opencode v2.0.26 plugin list — all five fm.primary.* load clean

Source: opencode v2.0.26 plugin list — all five fm.primary.* load clean

\### OpenCode version on this host
opencode v2.0.26

\### opencode plugin list (run from the worktree) - all five fm.primary.* load clean with declared ids
ID                                       VERSION  SOURCE
fm.primary.cd-check                      local    ~/.no-mistakes/worktrees/202df2ceeeaf/01M4P5B8D7VE3W9QRY6NQB2H2T/.opencode/plugins/fm-primary-cd-check.js
fm.primary.pretool-check                 local    ~/.no-mistakes/worktrees/202df2ceeeaf/01M4P5B8D7VE3W9QRY6NQB2H2T/.opencode/plugins/fm-primary-pretool-check.js
fm.primary.sessionstart-nudge            local    ~/.no-mistakes/worktrees/202df2ceeeaf/01M4P5B8D7VE3W9QRY6NQB2H2T/.opencode/plugins/fm-primary-sessionstart-nudge.js
fm.primary.turnend-guard                 local    ~/.no-mistakes/worktrees/202df2ceeeaf/01M4P5B8D7VE3W9QRY6NQB2H2T/.opencode/plugins/fm-primary-turnend-guard.js
fm.primary.watch-arm                     local    ~/.no-mistakes/worktrees/202df2ceeeaf/01M4P5B8D7VE3W9QRY6NQB2H2T/.opencode/plugins/fm-primary-watch-arm.js
Evidence: Real fm-spawn-generated OpenCode 2 busy-state plugin (export default {id,setup,server})

Source: Real fm-spawn-generated OpenCode 2 busy-state plugin (export default {id,setup,server})

// Firstmate semantic busy-state events + turn-end notification; written by
// fm-spawn under the contract owned by bin/fm-busy-lib.sh.
// Semantic state comes from OpenCode 2's session.execution.started and terminal
// session.execution.* events, with the OpenCode 1 session.status/session.idle
// names retained as legacy inputs. Scoping latches the first session that
// reports activity and ignores other sessions until the latched session settles,
// so a child's terminal event can never clear the worker's busy state. The
// turn-ended touch stays the watcher's wake NOTIFICATION, never current-state
// truth.
import { execFile } from "node:child_process";
const notifyTurnEnd = true;
const busyEvent = (state, event) =>
  new Promise((resolve) => {
    execFile("~/.no-mistakes/worktrees/202df2ceeeaf/01M4P5B8D7VE3W9QRY6NQB2H2T/bin/fm-busy-event.sh", [
      "apply", "/private/var/folders/nq/kgpf74px1rn116q_x77l6g8m0000gn/T/fm-busy-adapter-wiring.oopr3P/oc-gen-evid/home/state", "busy-oc-gen", state,
      "--gen", "g1791746893.17722.19632", "--source", "opencode-plugin", "--event", event,
    ], () => resolve());
  });
const touchTurnEnded = () =>
  new Promise((resolve) => {
    execFile("touch", ["/private/var/folders/nq/kgpf74px1rn116q_x77l6g8m0000gn/T/fm-busy-adapter-wiring.oopr3P/oc-gen-evid/home/state/busy-oc-gen.turn-ended"], () => resolve());
  });
const eventType = (event) => event && (event.type || event.name) || "";
const eventProperties = (event) => event && (event.properties || event.data) || {};
const sessionID = (event) => {
  const properties = eventProperties(event);
  return properties.sessionID || properties.sessionId || (properties.session && (properties.session.id || properties.session.parentID || properties.session.parentId)) || properties.id || "";
};
const setupEventSubscription = (ctx, handler) => {
  if (!ctx || !ctx.event || !ctx.event.subscribe) return false;
  const controller = new AbortController();
  void (async () => {
    try {
      const stream = await ctx.event.subscribe({ signal: controller.signal, onActivity() {} });
      for await (const event of stream) await handler(event);
    } catch {
    }
  })();
  return true;
};
const makeHandler = () => {
  let activeSession = null;
  return async (event) => {
    const type = eventType(event);
    const id = sessionID(event);
    if (type === "session.execution.started") {
      if (activeSession === null) activeSession = id;
      if (id === activeSession) await busyEvent("busy", "session-execution-started");
      return;
    }
    if (type === "session.execution.succeeded" || type === "session.execution.interrupted" || type === "session.execution.failed") {
      if (id === activeSession) {
        activeSession = null;
        await busyEvent("idle", type.replace(/\./g, "-"));
      }
      if (notifyTurnEnd) await touchTurnEnded();
      return;
    }
    if (type === "session.status") {
      const properties = eventProperties(event);
      const statusType = properties.status && properties.status.type;
      if (statusType === "busy" || statusType === "retry") {
        if (activeSession === null) activeSession = id;
        if (id === activeSession) await busyEvent("busy", "session-" + statusType);
        return;
      }
      if (statusType === "idle" && id === activeSession) {
        activeSession = null;
        await busyEvent("idle", "session-status-idle");
      }
      return;
    }
    if (type === "session.idle") {
      if (id === activeSession) {
        activeSession = null;
        await busyEvent("idle", "session-idle");
      }
      if (notifyTurnEnd) await touchTurnEnded();
    }
  };
};
export const FmBusyState = async () => {
  const handleEvent = makeHandler();
  return {
    event: async ({ event }) => handleEvent(event),
  };
};

export default {
  id: "fm.busy-state",
  server: FmBusyState,
  setup(ctx) {
    setupEventSubscription(ctx, makeHandler());
  },
};
Evidence: node default-export contract check across all five primary plugins
fm-primary-cd-check.js id="fm.primary.cd-check" setup=function setup({})=true OK=true
fm-primary-pretool-check.js id="fm.primary.pretool-check" setup=function setup({})=true OK=true
fm-primary-sessionstart-nudge.js id="fm.primary.sessionstart-nudge" setup=function setup({})=true OK=true
fm-primary-turnend-guard.js id="fm.primary.turnend-guard" setup=function setup({})=true OK=true
fm-primary-watch-arm.js id="fm.primary.watch-arm" setup=function setup({})=true OK=true
Evidence: OpenCode busy-adapter cases driven directly (skipped by suite's early abort)
ok - an opencode secondmate plugin closes the parent busy record without a parent turn-end
ok - opencode 1.x plugin classifies from session.status and ignores OpenCode 2 session.execution.* events
ok - opencode plugin classifies from session.execution.* (OpenCode 2), scoped to the latched worker session
- Outcome: ⚠️ 1 info across 1 run (16m12s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

⏭️ **Rebase** - skipped
  • ⚠️ bin/fm-spawn.sh - merge conflict rebasing onto refs/remotes/no-mistakes-push/fm/opencode2-pr-v1
⚠️ **Review** - 2 infos
  • ⚠️ bin/fm-spawn.sh:4946 - The OpenCode 2 busy-state plugin generated in fm-spawn.sh (the major>=2 heredoc, lines ~4909/4946/4968) calls touchTurnEnded() unconditionally on every session.execution.* terminal event and on session.idle. Unlike the retained OpenCode 1 plugin below it (line 4999: const notifyTurnEnd = $busy_notify_turnend;, gated touch at 5030) and the Claude Stop wiring (line 4822), it never interpolates or honors busy_notify_turnend. For an OpenCode 2 --secondmate launch busy_notify_turnend is set false (line 4721) yet WIRING_HARNESS stays opencode, so this 2.x branch runs and emits turn-ended touches the 1.x plugin suppresses — spurious watcher wake notifications that break the stated secondmate contract ('a secondmate's hooks ... do not touch the parent's turn-ended marker', line ~4712). Remedy restores parity with the 1.x plugin, not new scope: interpolate const notifyTurnEnd = $busy_notify_turnend; into the 2.x heredoc and wrap both await touchTurnEnded(); calls in if (notifyTurnEnd).

🔧 Fix applied.
2 infos still open:

  • ℹ️ .opencode/plugins/fm-primary-cd-check.js:78 - The OC2 setup-path handlers installCdCheck (fm-primary-cd-check.js:75) and installPretoolCheck (fm-primary-pretool-check.js:75) drop the OC1 server-path gate input?.tool !== "bash" (cd-check:62, pretool-check:62). They now run the cd/arm seatbelt against any tool whose input/output yields a command-like field via toolCommand(), not just bash. Concrete harm is low (only tools exposing command/cmd/script reach fm-cd-pretool-check.sh / fm-arm-pretool-check.sh, and the script must return code 2 to deny), but it is a real behavioral widening vs OC1 parity. The lib already exports toolName(), so restoring if (toolName(input) !== "bash") return; would re-establish parity; however this may be a deliberate choice if OC2 tool naming is unreliable (gating could fail-open), so the tradeoff is flagged rather than prescribed.
  • ℹ️ .opencode/plugins/fm-primary-cd-check.js:31 - This change adds a resolvePath() helper to fm-primary-cd-check.js:31 and fm-primary-pretool-check.js:31 that is never called: resolveRoot() in both files (lines 44-48) inlines its own realpathSync/resolve fallback, and the FmPrimaryCdCheck/FmPrimaryPretoolCheck factories inline the worktree resolution too. The helper is dead code introduced by the diff; remove it from both files. (The sibling plugins turnend-guard/watch-arm/sessionstart-nudge do reference their resolvePath, so only these two are dead.)
⚠️ **Test** - 1 info
  • ℹ️ tests/fm-busy-adapter-wiring.test.sh:703 - tests/fm-busy-adapter-wiring.test.sh aborts at the Claude secondmate Stop-guard case (test_secondmate_claude_stop_guard_owns_the_stop_verdict, line 703: expected exit 2, got 0). Root cause is environmental: bin/fm-turnend-guard.sh exits 0 because fm_primary_scope_matches fails when FM_HOME defaults to the real ~/github/firstmate and the temp sm-home is not a recognized primary git scope in this gate sandbox. The guard, bin/fm-busy-lib.sh, the test function, and its helpers are all byte-identical between base (e0d95ac) and target (7b1b942), so this reproduces on base and is NOT caused by the OpenCode 2 change. Because the failing fail exits the file, it masked the OpenCode cases later in the file; I drove those three OpenCode cases directly and they pass.
  • Live validation: ✅ go - 7 of 8 scenarios driven live against the product
Scenario Result Live Evidence
All five fm.primary.* plugins load clean on OpenCode 2 (export a default definition with an id and setup) ✅ pass live opencode plugin list on real v2.0.26 lists all five with declared ids (opencode2-plugin-list.txt); node contract check confirms {id,setup} and setup() does not throw
Adversarial: OpenCode 2 loader distinguishes a valid default export from a legacy v1-shape plugin ✅ pass live Isolated project: valid {id,setup} plugin lists as test.good; legacy v1-shape plugin (no default export) lists with id -, proving the id reflects the real default export
Version-gate 2.x launch: model+effort ride OPENCODE_CONFIG_CONTENT, no --model/--variant/--effort ✅ pass live bash tests/fm-spawn-dispatch-profile.test.sh passes test_opencode_threads_model_and_effort_variant and test_opencode_without_effort_keeps_launch_config_unchanged (real fm-spawn + fake opencode repor…
Version-gate 1.x and unknown-version fallback: --model flag kept, variant-only config, undetected→1.x, probe/launch share one executable ✅ pass live dispatch-profile passes test_opencode1_passes_model_flag_and_variant_only_config, test_opencode_unknown_version_takes_1x_launch_path, test_opencode_probe_and_launch_share_resolved_executable
Busy-state plugin provisioned per major and the generated v2 plugin loads clean ✅ pass live dispatch-profile test_opencode_busy_plugin_provisioned_for_every_major passes; real fm-spawn-generated v2 fm-busy-state.js verified under node to export {id:'fm.busy-state',setup} (generated-fm-busy-s…
Busy-state semantic lifecycle: v2 maps session.execution.* scoped to latched session; v1 ignores execution events; secondmate does not touch parent turn-end ✅ pass live Three OpenCode busy-adapter cases driven directly in a Node host against the real generated plugin + real fm-busy-event.sh writer + real classifier — all ok
Exit-key version gate in fm-control: 1.x/absent → /exit, 2.x → raw Ctrl-C ✅ pass live bash tests/fm-control.test.sh passes 'a recorded OpenCode major picks /exit (1.x) or raw Ctrl-C (2.x)' (46 ok, rc=0)
Open the upstream pull request to kunchenguid/firstmate ⏸️ untested no Opening/pushing the PR is owned by the PR phase of the no-mistakes run; this gate-step is the test phase and is explicitly forbidden from running push/PR phases. No live product surface for the test p…
  • opencode plugin list from the worktree on real OpenCode v2.0.26 — all five fm.primary.* plugins load with declared ids
  • opencode plugin list isolated adversarial control — valid {id,setup} plugin shows its id, legacy v1-shape (no default export) shows -
  • node --input-type=module default-export contract check on all five .opencode/plugins/fm-primary-*.js (id string + setup function + setup({}) does not throw)
  • bash tests/fm-spawn-dispatch-profile.test.sh — full pass incl. test_opencode_threads_model_and_effort_variant, test_opencode1_passes_model_flag_and_variant_only_config, test_opencode_probe_and_launch_share_resolved_executable, test_opencode_unknown_version_takes_1x_launch_path, test_opencode_busy_plugin_provisioned_for_every_major
  • bash tests/fm-control.test.sh — full pass incl. 'a recorded OpenCode major picks /exit (1.x) or raw Ctrl-C (2.x)'
  • Drove the three OpenCode busy-adapter cases directly (test_secondmate_opencode_plugin_closes_without_a_parent_turnend, test_opencode_plugin_semantic_lifecycle, test_opencode_plugin_v2_execution_lifecycle) — all pass
  • Generated the real v2 fm-busy-state.js via fm-spawn (probing opencode 2.0.21) and confirmed its {id:'fm.busy-state', setup} default-export contract loads under node
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@greptile-apps

greptile-apps Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[High risk] Ports primary plugins and spawn control to OpenCode 2.

The PR appears safe to merge based on this review; no new actionable finding or outstanding previous finding remains.

Reviews (6) · Last reviewed commit: "no-mistakes(document): de-version stale ..."

Comment thread .opencode/plugins/lib/fm-opencode2.js Resolved
Comment thread .opencode/plugins/lib/fm-opencode2.js Resolved
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun Chen's firstmate (public): first stamp vs main 42dd906d02f672652606057a193a6386b956c3f3. Diff reviewed (five .opencode/plugins/fm-primary-* plus the generated fm-busy-state.js gain an OpenCode 2 export default { id, setup }; new .opencode/plugins/lib/fm-opencode2.js; bin/fm-spawn.sh drops --model for every opencode launch and pins the model in OPENCODE_CONFIG_CONTENT; bin/fm-control-lib.sh exits every OpenCode composer with C-c).

Contract-class: new-default — main's specified OpenCode path is 1.15.7–1.18.x (/exit, --model, session.idle / session.status in the harness reference and supervision protocol). Tip rewrites that unconfigured harness=opencode spawn/control path to OpenCode 2 semantics with no version gate and no opt-in, and auto-loads supervision (watch-arm, turn-end guard, cd/pretool seatbelts, sessionstart nudge, busy-state) through setup() on a binary the prior contract did not run. Not restore: OpenCode 2 was not a specified broken default, and a vendor-port / bugfix motive does not make this new default a restore.

VISION (per rule):

  • One captain, one interface — aligns: same supervision outcomes; no new captain-facing surface.
  • Authority is explicit and never inferred — aligns: no new autonomy or merge grant; seatbelts still throw to refuse. The OC2 binding is not an opt-in, which is the contract-class finding, not a new consent grant.
  • Scripts own the mechanics, agents own the judgment — aligns: latch, busy map, and exit key are plugin/script mechanics.
  • A restart is a non-event — aligns: does not move durable obligations into chat memory.
  • Delegation with a spine — aligns: existing watch-arm / turn-end contracts, now on session.execution.*; not a new task shape.
  • The fleet outlives any vendor — does not align: the unconfigured OpenCode path is now bound to 2.0.21 semantics (C-c, config-content model, session.execution.*) and the documented 1.x contract is rewritten instead of a version-pinned dual path. OC1 server exports remain, but spawn and control are not gated.
  • Scope — aligns: harness adapter and plugins, not the workshop. No .github/workflows edit. docs/opencode-2-plugin-port-scope.md is maintainer-verification. Always-loaded contract is untouched aside from one afk skill sentence that drops the 1.18.4 version pin.

Gates: attestation MATCH (05f9a2aa902d039ca9a4bee365d14b01cf1fa99c). Greptile Review SUCCESS on that SHA; prior P1 threads are resolved (concurrent-session latch outdated; cross-session skipNextIdle resolved — tip uses per-session latch.exempt / latch.consume). CI run 37175205945 and Require no-mistakes runs 37175205960, 37176640685, 37176721602 are action_required on this head (fork), not green. MERGEABLE / UNSTABLE. No Fixes/Closes. In-body pipeline still says lint warning and ci pending. Not otherwise-ready, so this is not a captain close-vs-leave.

Waiting on fork workflow approval, not on the author.

Comment thread bin/fm-spawn.sh Resolved
@kunchenguid

kunchenguid commented Oct 4, 2026 •

Copy link
Copy Markdown
Owner

Speaking as Kun Chen's firstmate (public): re-stamp of bd44dd4f2e2131e4a36e1886eaad196b6150a517 vs main 9ea0c41a480cf965b80bba60a80701639f70f723. Prior stamp was on stale 05f9a2aa.

Contract-class: new-default. There is a real version gate, not only a docs claim. model_flag_for_harness and effort_flag_for_harness keep OpenCode 1 --model and the variant-only config only when the detected major is exactly 1. fm_control_exit_command sends /exit when the recorded major is empty or 1, and raw C-c otherwise. A detected 2.x install takes the OpenCode 2 launch (no --model; model pinned in OPENCODE_CONFIG_CONTENT) and C-c. An empty probe (unresolvable binary or a --version line with no x.y.z) records no opencode_version: the launch falls through to that 2.x shape while exit falls back to /exit. Failure-to-detect taking the new launch path is why this is not restore and not opt-in. The five fm-primary-* setup() exports and the generated fm-busy-state.js still ship for every opencode launch, with no version check.

VISION: The fleet outlives any vendor — does not align. A detected 1.x install stays on /exit and --model, but an undetectable probe hardens the OpenCode 2 launch contract into the fallback, and the OpenCode 2 setup() / session.execution.* surface stays on the shared plugin path rather than a quarantined, version-pinned adapter. No other VISION rule flipped vs the prior stamp.

Gates: attestation MATCH (bd44dd4f2e2131e4a36e1886eaad196b6150a517). Greptile Review SUCCESS on this SHA; no open P1 (earlier P1s, including the version-probe executable finding, are on older commits; the review of this head reports none outstanding). CI 37236949603 approved, in progress. Require no-mistakes 37236949571 approved, success. MERGEABLE / UNSTABLE. Not otherwise-ready. No captain card. Not merging.

Waiting on CI, not on the author.

@kunchenguid

Copy link
Copy Markdown
Owner

Thanks for adding the version gate. Two changes would make this mergeable:

  1. An unknown version means 1.x. If opencode can't be resolved, or --version has no x.y.z, launch should keep --model and the 1.x config, matching the /exit fallback you already have. Only a detected major of 2 or above should take the 2.x launch.
  2. Load the plugins only on a detected 2.x. The five fm-primary-* plugins and the generated fm-busy-state.js should load only when the probe reports major 2 or above, not on every OpenCode spawn.

The rest can stay as it is: the C-c exit, OPENCODE_CONFIG_CONTENT, and the plugin port itself. With those two changes, OpenCode 1 setups behave exactly as they do today, and only a confirmed OpenCode 2 gets the new path.

@nchandar
nchandar force-pushed the fm/opencode2-pr-v1 branch from bd44dd4 to fec3902 Compare October 6, 2026 07:22
@nchandar nchandar changed the title feat(opencode): port primary plugins and spawn/control to OpenCode 2 feat(opencode): add OpenCode 2 support with version-gated launch and plugins Oct 6, 2026
@nchandar

nchandar commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for adding the version gate. Two changes would make this mergeable:

  1. An unknown version means 1.x. If opencode can't be resolved, or --version has no x.y.z, launch should keep --model and the 1.x config, matching the /exit fallback you already have. Only a detected major of 2 or above should take the 2.x launch.
  2. Load the plugins only on a detected 2.x. The five fm-primary-* plugins and the generated fm-busy-state.js should load only when the probe reports major 2 or above, not on every OpenCode spawn.

The rest can stay as it is: the C-c exit, OPENCODE_CONFIG_CONTENT, and the plugin port itself. With those two changes, OpenCode 1 setups behave exactly as they do today, and only a confirmed OpenCode 2 gets the new path.

@kunchenguid Both changes are in:

  1. Unknown version → 1.x. If opencode can't be resolved or --version lacks x.y.z, launch keeps --model, the 1.x config, and /exit. Only major ≥ 2 takes the 2.x path.

  2. OC2 path gated to major ≥ 2. fm-busy-state.js is generated in its OC2 shape only on major ≥ 2 (OC1 keeps the session.status shape). The five fm-primary-* plugins carry both exports — OpenCode 2 uses the new setup, OpenCode 1 the unchanged v1 path.

OpenCode 1 behaves exactly as today; only OpenCode 2 gets the new path. C-c exit, OPENCODE_CONFIG_CONTENT, and the port are unchanged.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @nchandar. I re-read head fec3902a against main 0ec1c5a4 to check the two changes Kun asked for on 2026-10-05.

  1. Unknown version means 1.x: done. fm-spawn.sh resolves one opencode executable, probes that same binary, and sets OPENCODE_MAJOR=1 when the probe is empty or unparseable. Only a parsed major of 2 or above drops --model and pins the model in OPENCODE_CONFIG_CONTENT. fm_control_exit_command keeps /exit for an empty or 1 major.
  2. OpenCode 2 surface only on a detected 2.x: done for the generated plugin. fm-busy-state.js is generated in its session.execution.* shape only when the major is 2 or above, and 1.x gets the pre-port shape. The five fm-primary-* plugins ship both exports, and 1.x still loads its unchanged v1 export. That is a dual export rather than a load-time gate, which I'm noting for Kun.

Contract-class: new-default. A detected OpenCode 2 gets a launch, exit key and plugin surface that main never specified. One small change also reaches 1.x: the launch now runs the resolved absolute opencode path instead of a bare opencode. Kun decides; this won't auto-merge.

VISION: The fleet outlives any vendor moves to mostly aligns now that 1.x and undetected installs keep the specified path and the OpenCode 2 shape is version-gated. My earlier per-rule read stands otherwise.

Gates: the attestation matches fec3902a, Require no-mistakes passes, and Greptile's last review is clean. Security review: no network calls, secrets or workflow edits, and the plugins call only firstmate's own scripts. I approved the pending fork runs on this head (CI 37429284634, no-mistakes 37429284742, 37429379143, 37734517322, 37734735291). This is waiting on CI, not on you. Once it's green, it goes to Kun as a merge-or-leave decision.

…plugins

OpenCode 2 dropped the v1 server-plugin hook API, so the five fm.primary.*
plugins now export a default definition with an id and a setup function
alongside their legacy OpenCode 1 server export, backed by a new shared
lib/fm-opencode2.js helper; the turn-end guard, watch-arm, cd-check,
pretool-check, and sessionstart-nudge install their behavior from setup(ctx)
on OpenCode 2 and keep the server entrypoint for OpenCode 1.

fm-spawn probes the resolved opencode executable's --version once and branches
the launch, model flag, reasoning config, exit key, and busy-state plugin off
the detected major. A parsed major >= 2 takes the OpenCode 2 shape (no --model,
the model pinned through OPENCODE_CONFIG_CONTENT, a raw Ctrl-C exit, the
session.execution.* busy plugin); OpenCode 1.x and any undetected or
unparseable version fall back to the 1.x shape (--model, 1.x config, /exit)
everywhere. The worker busy-state plugin is always provisioned, but OpenCode 1
keeps the pre-port session.status/session.idle plugin so its busy-state wiring
is unchanged, and only a major >= 2 gets the session.execution plugin. Adapter
and supervision docs, OpenCode 2 live fixtures, and regression tests for the
unknown->1.x launch path and the version-gated busy-plugin shape are included.
@nchandar

nchandar commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor Author

@kunchenguid Rebased onto the latest main and re-pushed to clear a merge conflict. This update:

  • Rebased fm/opencode2-pr-v1 onto current main (single commit).
  • Gated the OpenCode 2 busy-state plugin's turn-end touch on busy_notify_turnend, mirroring the OpenCode 1 plugin — integrates main's new secondmate turn-end contract, so an OC2 --secondmate launch no longer touches the parent's turn-end marker.

No other behavior changes; the version gate and plugin port are unchanged.

@nchandar

Copy link
Copy Markdown
Contributor Author

Superseded by #7336, which landed OpenCode 2 support. Closing.

@nchandar nchandar closed this Oct 24, 2026
@nchandar
nchandar deleted the fm/opencode2-pr-v1 branch October 24, 2026 05:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants