From 47e9da7eab4b037ad20ccb4b9c43e3a002e625ac Mon Sep 17 00:00:00 2001 From: Shamal Krishna <345065856+SHAMALKRISHNA@users.noreply.github.com> Date: Fri, 13 Nov 2026 01:54:30 +1100 Subject: [PATCH 1/3] feat(opencode): a Plan mode answer becomes the plan card OpenCode's plan agent answers in plain text, so OpenCode plans had no plan card and no Implement action. When a Plan mode turn completes, its final answer is re-emitted in place as the proposed plan, and an earlier plan in the thread is marked superseded. OpenCode 1.x is unchanged. Co-Authored-By: Claude Opus 5.5 --- .../Adapters/OpenCode2AdapterV2.test.ts | 90 +++++++++++++++++++ docs/user/providers-opencode.md | 3 +- .../src/server/v2/adapter.ts | 61 ++++++++++++- 3 files changed, 151 insertions(+), 3 deletions(-) diff --git a/apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.ts index 1efbbfad09d81..666f3bed52e94 100644 --- a/apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.ts @@ -744,6 +744,96 @@ it.layer(McpProviderSessions.layer)("OpenCode2 adapter", (it) => { event.turnItem.text === "DONE", ), ); + assert.isFalse( + seen.some((event) => event.type === "plan.updated" && event.plan.kind === "proposed_plan"), + ); + }).pipe(Effect.scoped), + ); + + it.effect("turns a Plan mode turn's final answer into its proposed plan", () => + Effect.gen(function* () { + const text = (message: string, ordinal: number, value: string) => + event("session.text.ended", { + sessionID: SESSION, + assistantMessageID: message, + ordinal, + text: value, + }); + const { runtime, thread } = yield* resumed([ + out("session.switchAgent", { sessionID: SESSION, agent: "plan" }), + reply("session.switchAgent", null), + out("agent.list", ""), + reply("agent.list", agentList), + out("session.update", { sessionID: SESSION, permissions: "" }), + reply("session.update", null), + out("session.prompt", { sessionID: SESSION, text: "" }), + promptAccepted, + text("msg_plan", 0, "Reading the project first."), + text("msg_plan", 1, "## Plan\n\n1. Add the store\n2. Add the list"), + event("session.execution.succeeded", { sessionID: SESSION }), + out("session.prompt", { sessionID: SESSION, text: "" }), + replyData("session.prompt", { + id: "msg_refine", + sessionID: SESSION, + time: { created: 1790656601411 }, + type: "user", + payload: { text: "refine" }, + delivery: "steer", + }), + text("msg_refined", 0, "## Plan\n\n1. Add the list"), + event("session.execution.succeeded", { sessionID: SESSION }), + ]); + const firstEnded = yield* Deferred.make(); + let terminals = 0; + const collected = yield* runtime.events.pipe( + Stream.tap((event) => + event.type === "turn.terminal" ? Deferred.succeed(firstEnded, undefined) : Effect.void, + ), + Stream.takeUntil((event) => event.type === "turn.terminal" && ++terminals === 2), + Stream.runCollect, + Effect.forkScoped, + ); + const input = turnInput(thread); + const plan = { ...input.runtimePolicy, interactionMode: "plan" as const }; + yield* runtime.startTurn({ ...input, runtimePolicy: plan }); + yield* Deferred.await(firstEnded); + yield* runtime.startTurn({ + ...input, + runId: RunId.make("run:opencode2-adapter:2"), + runOrdinal: 2, + providerTurnOrdinal: 2, + attemptId: RunAttemptId.make("attempt:opencode2-adapter:2"), + runtimePolicy: plan, + }); + const seen = yield* Fiber.join(collected); + const plans = seen.flatMap((event) => + event.type === "plan.updated" && event.plan.kind === "proposed_plan" ? [event.plan] : [], + ); + const [first, superseded, refined] = plans; + assert.deepEqual( + plans.map((each) => [each.status, each.kind === "proposed_plan" && each.markdown]), + [ + ["completed", "## Plan\n\n1. Add the store\n2. Add the list"], + ["superseded", "## Plan\n\n1. Add the store\n2. Add the list"], + ["completed", "## Plan\n\n1. Add the list"], + ], + ); + assert.equal(superseded?.id, first?.id); + assert.notEqual(refined?.id, first?.id); + const items = seen.flatMap((event) => + event.type === "turn_item.updated" ? [event.turnItem] : [], + ); + const answer = items.find( + (item) => item.type === "assistant_message" && item.text.includes("Add the store"), + ); + const card = items.find((item) => item.type === "proposed_plan" && item.planId === first?.id); + // The answer becomes the card in place, so the plan is not shown twice. + assert.equal(card?.id, answer?.id); + assert.isTrue( + items.some( + (item) => item.type === "assistant_message" && item.text === "Reading the project first.", + ), + ); }).pipe(Effect.scoped), ); diff --git a/docs/user/providers-opencode.md b/docs/user/providers-opencode.md index bcdc33fb20246..dbb733eeefd79 100644 --- a/docs/user/providers-opencode.md +++ b/docs/user/providers-opencode.md @@ -20,7 +20,8 @@ OpenCode 2 converts the shared OpenCode database to its own format the first tim runs. Don't run OpenCode 1.x and 2.x side by side on the same machine. Threads you started on 1.x continue on 2.x. -Plan mode uses OpenCode's `plan` agent. +Plan mode uses OpenCode's `plan` agent. Its final answer becomes the plan card, so you can +refine it or implement it, in this thread or a new one. OpenCode 1.x has no Plan mode. ## Compaction diff --git a/packages/provider-opencode/src/server/v2/adapter.ts b/packages/provider-opencode/src/server/v2/adapter.ts index b13f6c361bacf..92aba2501a9b4 100644 --- a/packages/provider-opencode/src/server/v2/adapter.ts +++ b/packages/provider-opencode/src/server/v2/adapter.ts @@ -31,6 +31,7 @@ import { type OrchestrationV2ProviderSession, type OrchestrationV2ProviderThread, type OrchestrationV2ProviderTurn, + type OrchestrationV2PlanArtifact, type OrchestrationV2PlanStep, type OrchestrationV2RuntimeRequest, type OrchestrationV2Subagent, @@ -171,7 +172,7 @@ const OpenCode2ProviderCapabilities = { planning: { emitsPlanUpdated: true, emitsTodoList: true, - emitsProposedPlan: false, + emitsProposedPlan: true, supportsStructuredQuestions: true, planDeltasHaveItemIds: false, }, @@ -219,7 +220,7 @@ interface TurnOwner { readonly runOrdinal: number; readonly rootNodeId: ProviderAdapter.ProviderAdapterV2TurnInput["rootNodeId"]; readonly modelSelection: ModelSelection; - readonly runtimePolicy: Pick; + readonly runtimePolicy: Pick; } interface ActiveTurn { @@ -248,6 +249,8 @@ interface ActiveTurn { compaction: { readonly nativeId: string; readonly startedAt: DateTime.Utc } | undefined; compactions: number; todoPlanId: PlanId | undefined; + // The plan agent answers in text; in Plan mode the final answer becomes the proposed plan. + answer: { readonly nativeId: string; readonly text: string; readonly startedAt: DateTime.Utc } | undefined; retry: | { readonly retry: OrchestrationV2ProviderRetry; @@ -361,6 +364,7 @@ interface ThreadState { >; readonly stoppedChildren: Set; readonly strandedSteers: Set; + proposedPlan: Extract | undefined; /** Prompts other clients queued while no T3 turn ran, shown once delivered; `leads` the next wake if no report preceded it. */ readonly externalPrompts: Map; mcp: @@ -843,6 +847,7 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr reports: new Map(), stoppedChildren: new Set(), strandedSteers: new Set(), + proposedPlan: undefined, externalPrompts: new Map(), mcp: undefined, instructions: undefined, @@ -1081,6 +1086,9 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr if (completed) turn.texts.delete(nativeId); else turn.texts.set(nativeId, entry); if (entry.text.length === 0) return; + if (completed && kind === "text") { + turn.answer = { nativeId, text: entry.text, startedAt: entry.startedAt }; + } const status = completed ? "completed" : "running"; const completedAt = completed ? updatedAt : null; const nodeKind = kind === "text" ? "assistant_message" : "reasoning"; @@ -1236,6 +1244,47 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr }); }); + // Re-emits the answer's own turn item as the plan card, so the plan is not shown twice. + const emitProposedPlan = Effect.fnUntraced(function* (state: ThreadState, turn: ActiveTurn) { + const answer = turn.answer; + // Tools or other items after the last text mean that text was narration, not the plan. + if (answer === undefined || turn.ordinals.get(answer.nativeId) !== turn.nextOrdinal - 1) { + return; + } + const markdown = answer.text.trim(); + if (markdown.length === 0) return; + const now = yield* DateTime.now; + const base = itemBase(state, turn, answer.nativeId, "completed", answer.startedAt, now, now); + const plan = { + id: yield* idAllocator.allocate.plan({ + threadId: turn.input.threadId, + ...(turn.input.runId === null ? {} : { runId: turn.input.runId }), + driver, + }), + threadId: turn.input.threadId, + runId: turn.input.runId, + nodeId: base.nodeId, + kind: "proposed_plan" as const, + status: "completed" as const, + markdown, + }; + if (state.proposedPlan !== undefined) { + yield* emit({ + type: "plan.updated", + driver, + plan: { ...state.proposedPlan, status: "superseded" }, + }); + } + state.proposedPlan = plan; + yield* emitNode(state, turn, answer.nativeId, "plan", "completed", answer.startedAt, now); + yield* emit({ type: "plan.updated", driver, plan }); + yield* emit({ + type: "turn_item.updated", + driver, + turnItem: { ...base, type: "proposed_plan", planId: plan.id, markdown, streaming: false }, + }); + }); + const emitTool = Effect.fnUntraced(function* ( state: ThreadState, turn: ActiveTurn, @@ -1451,6 +1500,7 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr compaction: undefined, compactions: 0, todoPlanId: undefined, + answer: undefined, retry: undefined, interrupted: false, unsent: false, @@ -2128,6 +2178,13 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr for (const open of turn.texts.values()) { yield* emitText(state, turn, open.block, open.kind, (text) => text, true); } + if ( + terminal.status === "completed" && + state.subagent === undefined && + turn.input.runtimePolicy.interactionMode === "plan" + ) { + yield* emitProposedPlan(state, turn); + } for (const id of turn.tools.keys()) { if ([...state.imageJobs.values()].some((job) => job.turn === turn && job.toolId === id)) continue; From d7624e7359f8eb53efa3d391162eccdf8959171e Mon Sep 17 00:00:00 2001 From: Shamal Krishna <345065856+SHAMALKRISHNA@users.noreply.github.com> Date: Fri, 13 Nov 2026 01:56:22 +1100 Subject: [PATCH 2/3] fix(opencode): a failed plan ID allocation can't fail the turn's end finishTurn never fails, so the plan card's ID allocation dies like the ACP adapter's does. Also formats the change. Co-Authored-By: Claude Opus 5.5 --- .../src/server/v2/adapter.ts | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/packages/provider-opencode/src/server/v2/adapter.ts b/packages/provider-opencode/src/server/v2/adapter.ts index 92aba2501a9b4..c052b9439ef50 100644 --- a/packages/provider-opencode/src/server/v2/adapter.ts +++ b/packages/provider-opencode/src/server/v2/adapter.ts @@ -220,7 +220,10 @@ interface TurnOwner { readonly runOrdinal: number; readonly rootNodeId: ProviderAdapter.ProviderAdapterV2TurnInput["rootNodeId"]; readonly modelSelection: ModelSelection; - readonly runtimePolicy: Pick; + readonly runtimePolicy: Pick< + ProviderAdapter.ProviderAdapterV2RuntimePolicy, + "cwd" | "interactionMode" + >; } interface ActiveTurn { @@ -250,7 +253,9 @@ interface ActiveTurn { compactions: number; todoPlanId: PlanId | undefined; // The plan agent answers in text; in Plan mode the final answer becomes the proposed plan. - answer: { readonly nativeId: string; readonly text: string; readonly startedAt: DateTime.Utc } | undefined; + answer: + | { readonly nativeId: string; readonly text: string; readonly startedAt: DateTime.Utc } + | undefined; retry: | { readonly retry: OrchestrationV2ProviderRetry; @@ -364,7 +369,9 @@ interface ThreadState { >; readonly stoppedChildren: Set; readonly strandedSteers: Set; - proposedPlan: Extract | undefined; + proposedPlan: + | Extract + | undefined; /** Prompts other clients queued while no T3 turn ran, shown once delivered; `leads` the next wake if no report preceded it. */ readonly externalPrompts: Map; mcp: @@ -1256,11 +1263,13 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr const now = yield* DateTime.now; const base = itemBase(state, turn, answer.nativeId, "completed", answer.startedAt, now, now); const plan = { - id: yield* idAllocator.allocate.plan({ - threadId: turn.input.threadId, - ...(turn.input.runId === null ? {} : { runId: turn.input.runId }), - driver, - }), + id: yield* idAllocator.allocate + .plan({ + threadId: turn.input.threadId, + ...(turn.input.runId === null ? {} : { runId: turn.input.runId }), + driver, + }) + .pipe(Effect.orDie), threadId: turn.input.threadId, runId: turn.input.runId, nodeId: base.nodeId, From fb06aebd60d6d60c66f756213c855fd22f785fc4 Mon Sep 17 00:00:00 2001 From: Shamal Krishna <345065856+SHAMALKRISHNA@users.noreply.github.com> Date: Fri, 13 Nov 2026 02:00:55 +1100 Subject: [PATCH 3/3] fix(opencode): a new plan card is active, so it offers Refine and Implement Proposed plans start active, as Claude's and Codex's do; the client only offers the plan follow-up for an active plan. Only an active plan is superseded by the next one. Co-Authored-By: Claude Opus 5.5 --- .../src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.ts | 4 ++-- packages/provider-opencode/src/server/v2/adapter.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.ts index 666f3bed52e94..2019b1148a27f 100644 --- a/apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.ts @@ -813,9 +813,9 @@ it.layer(McpProviderSessions.layer)("OpenCode2 adapter", (it) => { assert.deepEqual( plans.map((each) => [each.status, each.kind === "proposed_plan" && each.markdown]), [ - ["completed", "## Plan\n\n1. Add the store\n2. Add the list"], + ["active", "## Plan\n\n1. Add the store\n2. Add the list"], ["superseded", "## Plan\n\n1. Add the store\n2. Add the list"], - ["completed", "## Plan\n\n1. Add the list"], + ["active", "## Plan\n\n1. Add the list"], ], ); assert.equal(superseded?.id, first?.id); diff --git a/packages/provider-opencode/src/server/v2/adapter.ts b/packages/provider-opencode/src/server/v2/adapter.ts index c052b9439ef50..68286c66acd2b 100644 --- a/packages/provider-opencode/src/server/v2/adapter.ts +++ b/packages/provider-opencode/src/server/v2/adapter.ts @@ -1274,10 +1274,10 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr runId: turn.input.runId, nodeId: base.nodeId, kind: "proposed_plan" as const, - status: "completed" as const, + status: "active" as const, markdown, }; - if (state.proposedPlan !== undefined) { + if (state.proposedPlan?.status === "active") { yield* emit({ type: "plan.updated", driver,