Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
feat: give OpenCode an attachable Stage 3 pr-reviewer recipe so its agent card exposes a Shell session (#6238)
[._.]/ Adam Eivy19833098aa62
diff --git a/server/lib/providerVendors.js b/server/lib/providerVendors.jsindex ce93d1a46d..5ae932540b 100644--- a/server/lib/providerVendors.js+++ b/server/lib/providerVendors.js@@ -392,6 +392,57 @@ function opencodePublicReviewSpawnArgs(provider, { effectiveModel } = {}) {};}+const opencodeHeadlessSpawnArgs = defaultSpawnArgs(opencodeCliArgs, 'opencode');++/**+ * The tool-enabled agent an attachable Stage 3 session runs as. Named on the+ * argv rather than left to OpenCode's default so the session cannot inherit a+ * `plan` (read-only, hand-back-to-a-human) default from a user's own config.+ */+const OPENCODE_PUBLIC_REVIEW_ACTIONS_AGENT = 'build';++/**+ * The `sandboxed-actions` recipe. OpenCode ships no OS sandbox of its own, so+ * this adds NO enforcement over the open-to-every-binary tier (the disposable+ * worktree, the stripped child env, and the deterministic coordinator are the+ * isolation — see `supportsPublicReviewPosture`). The row exists for the+ * ATTACHABLE case (#6238): a headless run is still today's `opencode run …`,+ * argv-for-argv, but that one-shot print-mode invocation cannot become an+ * interactive session by dropping flags the way Claude's recipe does — in a+ * PTY it neither accepts a pasted prompt nor renders anything. OpenCode's real+ * interactive entry point is the BARE binary (`opencode [project]`, its default+ * subcommand), which takes the same `--agent`/`-m` flags and reads the prompt+ * the spawner already pastes into every other TUI (`agentTuiSpawning.js`).+ * Verified under node-pty against a local Ollama backend: the pasted prompt+ * renders, Enter submits it, and the build agent answers through its tools.+ *+ * `-m` is namespaced by `prefixOpencodeModel` exactly as the headless argv is,+ * so the two shapes cannot drift on the model. Provider args are not forwarded+ * on the attachable path (same rule as `buildTuiSpawnConfig`): a saved+ * `--agent plan` would swap the tool-enabled agent for one that hands back to a+ * human nobody has to be, and `--auto` is redundant with the config's blanket+ * allow. The permission surface is the same on both paths: the config+ * `buildOpencodeEnvVars` composes allows every tool and denies the three+ * interactive gates (`question` / `plan_enter` / `plan_exit`), so an unattended+ * session never parks on a selector — while an operator who attaches sees the+ * same run the headless child would have executed.+ */+function opencodePublicReviewActionsSpawnArgs(provider, { effectiveModel, effort, tui = false } = {}) {+ if (!tui) return opencodeHeadlessSpawnArgs(provider, { effectiveModel, effort });+ const args = ['--agent', OPENCODE_PUBLIC_REVIEW_ACTIONS_AGENT];+ const resolvedModel = prefixOpencodeModel(provider, effectiveModel);+ if (resolvedModel) args.push('-m', resolvedModel);+ return { command: provider?.command || 'opencode', args, stdinMode: 'prompt' };+}++/**+ * Any spawnable OpenCode binary, whatever it fronts. Unlike the no-tool+ * matcher there is no model-capability probe involved, so an MTPLX / llama.cpp+ * / vLLM / gateway backend is as eligible as Ollama — the actions stage is open+ * to every binary provider anyway; this row only decides attachability.+ */+const matchOpencodeBinary = (provider) => isDirectBinaryProvider(provider) && isOpencodeCommand(provider?.command);+const OPENCODE = {id: 'opencode',idFragment: 'opencode',@@ -401,15 +452,23 @@ const OPENCODE = {// (buildVendorCliArgs/buildVendorSpawnConfig fall back to matchCommand when// matchCliProvider is absent).cliArgs: opencodeCliArgs,- spawnArgs: defaultSpawnArgs(opencodeCliArgs, 'opencode'),+ spawnArgs: opencodeHeadlessSpawnArgs,publicReview: {[PUBLIC_REVIEW_NO_TOOL_POSTURE]: {spawnArgs: opencodePublicReviewSpawnArgs,matchProvider: isLocalOpencodeProvider,},- // No `sandboxed-actions` recipe: OpenCode ships no OS sandbox of its own,- // so it stays in the open-to-every-binary tier where the disposable- // worktree is the isolation — see `supportsPublicReviewPosture`.+ [PUBLIC_REVIEW_ACTIONS_POSTURE]: {+ spawnArgs: opencodePublicReviewActionsSpawnArgs,+ matchProvider: matchOpencodeBinary,+ // Not an enforcement: the stage stays worktree-only in the schedule UI.+ enforces: false,+ // Attachable: the bare-binary shape above is what the PTY runs. There is+ // no argv-level permission boundary to preserve here — the headless run+ // already executes with the same full tool access — so attaching widens+ // nothing; the recipe only supplies the invocation a PTY can drive.+ tui: true,+ },},};@@ -676,7 +735,8 @@ const CLAUDE = {[PUBLIC_REVIEW_ACTIONS_POSTURE]: {spawnArgs: claudePublicReviewSpawnArgsFor(CLAUDE_PUBLIC_REVIEW_ACTIONS_ARGS),matchProvider: matchClaudeBinary,- // The only posture/vendor pairing that may run as an ATTACHABLE session.+ // One of two posture/vendor pairings that may run as an ATTACHABLE session+ // (OpenCode is the other — see its row).// `claudePublicReviewArgs` drops only the flags that REQUIRE `--print`// (the headless output set plus CLAUDE_PRINT_ONLY_ARGS) for// `tui: true`; every enforcement flag above (`--permission-mode@@ -849,9 +909,15 @@ export function enforcedPublicReviewPosturesForProvider(provider) {return PUBLIC_REVIEW_POSTURES.filter((posture) => enforcesPublicReviewPosture(provider, posture));}-const enforcesPublicReviewPosture = (provider, posture) => (- isDirectBinaryProvider(provider) && Boolean(publicReviewRecipe(provider, posture))-);+// A recipe may declare `enforces: false` when it exists only to name an+// attachable invocation and adds no sandbox of its own (OpenCode's actions+// row): it is still the argv the stage runs, but the schedule UI must keep+// reporting that choice as worktree-only rather than OS-sandboxed.+const enforcesPublicReviewPosture = (provider, posture) => {+ if (!isDirectBinaryProvider(provider)) return false;+ const recipe = publicReviewRecipe(provider, posture);+ return Boolean(recipe) && recipe.enforces !== false;+};/*** Vendor ids that declare a maintained recipe for `posture`, for naming what a@@ -868,7 +934,8 @@ export function publicReviewCapableVendorIds(posture) {* The no-tool gate requires a maintained recipe: only an enforced argv can* hold a model tool-free. The sandboxed-actions stage is open to EVERY enabled* binary (CLI/TUI) provider — a vendor recipe (Codex, Antigravity, Grok,- * Claude) adds an OS-level sandbox on top, but the stage's baseline isolation+ * Claude) adds an OS-level sandbox on top (OpenCode's adds none — its row+ * exists only to name the attachable invocation), but the stage's baseline isolation* is the disposable worktree, the stripped child environment, and the* deterministic coordinator owning all forge mutations. API providers have no* binary to spawn and fail closed for both.diff --git a/server/lib/providerVendors.publicReview.test.js b/server/lib/providerVendors.publicReview.test.jsindex 5e95eaa4ba..a2140ee79d 100644--- a/server/lib/providerVendors.publicReview.test.js+++ b/server/lib/providerVendors.publicReview.test.js@@ -366,9 +366,62 @@ describe('public-review provider postures', () => {expect(supportsTuiPublicReviewActionsProvider({ id: 'codex-tui', type: 'tui', command: 'codex' })).toBe(false);expect(supportsTuiPublicReviewActionsProvider({ id: 'grok-tui', type: 'tui', command: 'grok' })).toBe(false);expect(supportsTuiPublicReviewActionsProvider(antigravity)).toBe(false);- // …as do vendors with no actions recipe at all, and non-binary records.- expect(supportsTuiPublicReviewActionsProvider({ id: 'opencode-tui', type: 'tui', command: 'opencode' })).toBe(false);+ // …as do non-binary records, whatever their vendor.expect(supportsTuiPublicReviewActionsProvider({ id: 'claude-api', type: 'api', command: 'claude' })).toBe(false);+ expect(supportsTuiPublicReviewActionsProvider({ id: 'opencode-api', type: 'api', command: 'opencode' })).toBe(false);+ });++ // #6238 — OpenCode's headless actions run is a one-shot `opencode run …`,+ // which cannot become an interactive session by dropping flags; the+ // attachable recipe is the BARE binary (OpenCode's TUI entry point) with the+ // same agent/model flags, and the spawner pastes the prompt as for any TUI.+ it('declares OpenCode attachable for the actions stage on every backend, with a bare-binary argv', () => {+ const opencodeTui = { id: 'opencode-tui', type: 'tui', command: 'opencode', args: ['--agent', 'plan', '--auto'], ollamaBacked: true };+ expect(supportsTuiPublicReviewActionsProvider(opencodeTui)).toBe(true);+ // Unlike the no-tool posture (Ollama-only — see the `mtplxBacked` cases+ // above), attachability involves no model-capability probe, so an MTPLX or+ // gateway-fronting wrapper is just as attachable.+ expect(supportsTuiPublicReviewActionsProvider({ ...opencodeTui, ollamaBacked: false, mtplxBacked: true })).toBe(true);+ expect(supportsTuiPublicReviewActionsProvider({ id: 'opencode-cli', type: 'cli', command: 'opencode' })).toBe(true);+ expect(supportsTuiPublicReviewPosture(opencodeTui, PUBLIC_REVIEW_NO_TOOL_POSTURE)).toBe(false);++ const headless = buildVendorSpawnConfig(opencodeTui, {+ effectiveModel: 'qwen3-coder:30b',+ safetyProfile: PUBLIC_REVIEW_ACTIONS_EXECUTION_PROFILE,+ });+ // The headless shape is UNCHANGED by the row: still the ordinary+ // `run`-prefixed argv with the provider's own args forwarded.+ expect(headless).toEqual({+ command: 'opencode',+ args: ['run', '--agent', 'plan', '--auto', '-m', 'ollama/qwen3-coder:30b'],+ stdinMode: 'prompt',+ });++ const tui = buildVendorSpawnConfig(opencodeTui, {+ effectiveModel: 'qwen3-coder:30b',+ safetyProfile: PUBLIC_REVIEW_ACTIONS_EXECUTION_PROFILE,+ tui: true,+ });+ expect(tui).toEqual({+ command: 'opencode',+ // No `run` subcommand: that is print mode and never renders in a PTY. The+ // tool-enabled agent is pinned on the argv, and the provider's saved args+ // (`--agent plan`, `--auto`) are NOT forwarded on the attachable path.+ args: ['--agent', 'build', '-m', 'ollama/qwen3-coder:30b'],+ stdinMode: 'prompt',+ });+ expect(tui.args).not.toContain('run');+ // The model is namespaced the same way on both shapes, so they can't drift.+ expect(tui.args.at(-1)).toBe(headless.args.at(-1));+ expect(buildVendorSpawnConfig({ ...opencodeTui, ollamaBacked: false, mtplxBacked: true }, {+ effectiveModel: 'x',+ safetyProfile: PUBLIC_REVIEW_ACTIONS_EXECUTION_PROFILE,+ tui: true,+ }).args).toEqual(['--agent', 'build', '-m', 'mtplx/x']);+ expect(buildVendorSpawnConfig(opencodeTui, {+ safetyProfile: PUBLIC_REVIEW_ACTIONS_EXECUTION_PROFILE,+ tui: true,+ }).args).toEqual(['--agent', 'build']);});it('refuses to build an attachable argv for a vendor with no attachable recipe', () => {@@ -378,7 +431,6 @@ describe('public-review provider postures', () => {for (const provider of [{ id: 'codex-tui', type: 'tui', command: 'codex' },{ id: 'grok-tui', type: 'tui', command: 'grok' },- { id: 'opencode-tui', type: 'tui', command: 'opencode' },{ id: 'antigravity-tui', type: 'tui', command: 'agy' },]) {expect(() => buildVendorSpawnConfig(provider, {diff --git a/server/services/agentLifecycle.postureGate.test.js b/server/services/agentLifecycle.postureGate.test.jsindex 136e7b4b7a..93da61c806 100644--- a/server/services/agentLifecycle.postureGate.test.js+++ b/server/services/agentLifecycle.postureGate.test.js@@ -345,6 +345,39 @@ describe('public-review posture gate — spawn behavior (#5866)', () => {);});+ // #6238 — OpenCode's actions row exists for exactly this: a Stage 3 run on an+ // OpenCode-backed TUI record gets a PTY (and so an attachable Shell session)+ // instead of being forced headless. Its no-tool gate stays blocked above.+ it('spawns the sandboxed-actions stage as a PTY on an OpenCode TUI provider', async () => {+ const { buildTuiSpawnConfig, spawnTuiAgent } = await import('./agentTuiSpawning.js');+ vi.mocked(resolveAgentProviderAndModel).mockResolvedValue({+ ok: true, provider: { ...OPENCODE_TUI, mtplxBacked: true }, selectedModel: 'example-model', modelSelection: {},+ });+ vi.mocked(buildTuiSpawnConfig).mockReturnValue({ command: 'opencode', args: [], commandLine: 'opencode' });+ reachDispatch();++ await spawnAgentForTask({+ id: 'task-public-review-actions-opencode',+ metadata: {+ executionProfile: 'public-review-actions',+ issueWatcher: { pullRequests: [{ number: 42 }] },+ pipeline: {+ securityScan: { completed: true, status: 'passed', safePrCount: 1 },+ eligibility: { complete: true, eligibleNumbers: [42] },+ },+ },+ });++ expect(postureBlockWrites()).toEqual([]);+ expect(spawnDirectly).not.toHaveBeenCalled();+ expect(spawnTuiAgent).toHaveBeenCalledTimes(1);+ expect(buildTuiSpawnConfig).toHaveBeenCalledWith(+ expect.objectContaining({ id: 'opencode-tui' }),+ 'example-model',+ expect.objectContaining({ safetyProfile: 'public-review-actions' }),+ );+ });+// The narrow half of the same rule. A vendor whose actions recipe has not been// reviewed for a PTY emits headless argv (`exec`, `--print`, `run`) that a PTY// can neither prompt nor enforce, so it stays headless rather than opening a