@devries-cameron20 / t3code-1 / commits / f14fa03d58
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(opencode): steers keep the turn's agent, variant and instructions (#23270)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net>

Victor Vogel committed Nov 1, 2026 at 15:58 UTC f14fa03d581a474aa20ea12e3599908e737343d1
2 files changed +88 -22
packages/provider-opencode/src/server/adapter.test.ts
+67 -3
@@ -20,6 +20,7 @@ import {
20 ThreadId,
21 type OrchestrationV2ProviderThread,
22 type OrchestrationV2ProviderTurn,
23 + type ProviderOptionSelection,
24 } from "@t3tools/contracts";
25 import { OpenCodeSettings } from "../settings.ts";
26 import * as Effect from "effect/Effect";
@@ -151,15 +152,22 @@ const makeOpenCodeRuntimeHarness = Effect.fn("makeOpenCodeRuntimeHarness")(funct
152 nativeSessionId: string,
153 client: object,
154 host: Partial<ProviderHost.ProviderHost["Service"]> = {},
155 + turnSettings: {
156 + readonly options?: ReadonlyArray<ProviderOptionSelection>;
157 + readonly interactionMode?: ProviderAdapter.ProviderAdapterV2RuntimePolicy["interactionMode"];
158 + } = {},
159 ) {
160 const instanceId = ProviderInstanceId.make(`opencode-${suffix}`);
161 const threadId = ThreadId.make(`thread-opencode-${suffix}`);
162 const modelSelection = {
163 instanceId,
164 model: "anthropic/claude-sonnet",
160 - options: [],
165 + options: turnSettings.options ?? [],
166 };
162 - const policy = runtimePolicy("full-access", { cwd: "/workspace" });
167 + const policy = runtimePolicy("full-access", {
168 + cwd: "/workspace",
169 + interactionMode: turnSettings.interactionMode ?? "default",
170 + });
171 const adapter = yield* makeOpenCodeAdapterV2({
172 instanceId,
173 settings: OPEN_CODE_TEST_SETTINGS,
@@ -200,7 +208,7 @@ const makeOpenCodeRuntimeHarness = Effect.fn("makeOpenCodeRuntimeHarness")(funct
208 providerInstanceId: modelSelection.instanceId,
209 modelSelection,
210 runtimeMode: "full-access",
203 - interactionMode: "default",
211 + interactionMode: policy.interactionMode,
212 branch: null,
213 worktreePath: null,
214 activeProviderThreadId: providerThread.id,
@@ -1588,6 +1596,62 @@ describe("OpenCodeAdapterV2", () => {
1596 ),
1597 );
1598
1599 + it.effect("steers with the turn's agent, reasoning variant and system instructions", () =>
1600 + Effect.gen(function* () {
1601 + const nativeEvents = asyncEventStream();
1602 + const promptInputs: Array<{ agent?: string; variant?: string; system?: string }> = [];
1603 + const harness = yield* makeOpenCodeRuntimeHarness(
1604 + "steer-agent",
1605 + "root",
1606 + {
1607 + event: { subscribe: async () => ({ stream: nativeEvents.stream }) },
1608 + session: {
1609 + create: async () => ({ data: { id: "root", time: { created: 1, updated: 1 } } }),
1610 + get: async () => ({ data: { id: "root", time: { created: 1, updated: 1 } } }),
1611 + messages: async () => ({ data: [] }),
1612 + promptAsync: async (input: { agent?: string; variant?: string; system?: string }) => {
1613 + promptInputs.push(input);
1614 + return { data: true };
1615 + },
1616 + abort: async () => ({ data: true }),
1617 + children: async () => ({ data: [] }),
1618 + },
1619 + },
1620 + {},
1621 + { options: [{ id: "variant", value: "high" }], interactionMode: "plan" },
1622 + );
1623 + yield* harness.startTurn();
1624 + const snapshot = yield* harness.runtime.readThreadSnapshot({
1625 + providerThread: harness.providerThread,
1626 + });
1627 + yield* harness.runtime.steerTurn({
1628 + threadId: harness.threadId,
1629 + runId: harness.runId,
1630 + providerThread: harness.providerThread,
1631 + providerTurnId: snapshot.providerTurns.at(-1)!.id,
1632 + message: {
1633 + messageId: MessageId.make("message-opencode-steer-agent"),
1634 + text: "also cover the README",
1635 + attachments: [],
1636 + createdBy: "user",
1637 + creationSource: "web",
1638 + },
1639 + });
1640 +
1641 + const [start, steer] = promptInputs;
1642 + assert.equal(start?.agent, "plan");
1643 + assert.equal(start?.variant, "high");
1644 + assert.include(start?.system ?? "", "OpenCode");
1645 + assert.deepEqual(
1646 + { agent: steer?.agent, variant: steer?.variant, system: steer?.system },
1647 + { agent: start?.agent, variant: start?.variant, system: start?.system },
1648 + );
1649 + }).pipe(
1650 + Effect.provide(Layer.merge(IdAllocator.layer, McpProviderSessions.layer)),
1651 + Effect.scoped,
1652 + ),
1653 + );
1654 +
1655 it.effect("keeps a newly admitted prompt alive across stale idle and delayed busy evidence", () =>
1656 Effect.gen(function* () {
1657 const nativeEvents = asyncEventStream();
packages/provider-opencode/src/server/adapter.ts
+21 -19
@@ -2943,6 +2943,25 @@ export const makeOpenCodeAdapterV2 = Effect.fn("makeOpenCodeAdapterV2")(function
2943 };
2944 });
2945
2946 + // OpenCode runs each step with the agent and system prompt of the latest
2947 + // user message, so every prompt in a turn, steers included, repeats them.
2948 + const turnPromptOptions = (turn: ActiveOpenCodeTurn) => {
2949 + const agent =
2950 + getModelSelectionStringOptionValue(turn.modelSelection, "agent") ??
2951 + (turn.runtimePolicy.interactionMode === "plan" ? "plan" : undefined);
2952 + const variant = getModelSelectionStringOptionValue(turn.modelSelection, "variant");
2953 + return {
2954 + ...(agent === undefined ? {} : { agent }),
2955 + ...(variant === undefined ? {} : { variant }),
2956 + system: [
2957 + orchestrationSystemPrompt,
2958 + buildRuntimeInstructions({ harness: "OpenCode", model: turn.modelSelection.model }),
2959 + ]
2960 + .filter(Boolean)
2961 + .join("\n\n"),
2962 + };
2963 + };
2964 +
2965 // Native commands await generation; user-message receipts admit their background requests.
2966 const submitPrompt = Effect.fn("OpenCode.submitPrompt")(function* (
2967 state: OpenCodeThreadState,
@@ -3265,22 +3284,6 @@ export const makeOpenCodeAdapterV2 = Effect.fn("makeOpenCodeAdapterV2")(function
3284 );
3285 return;
3286 }
3268 - const systemPrompt = [
3269 - orchestrationSystemPrompt,
3270 - buildRuntimeInstructions({
3271 - harness: "OpenCode",
3272 - model: turnInput.modelSelection.model,
3273 - }),
3274 - ]
3275 - .filter(Boolean)
3276 - .join("\n\n");
3277 - const agent =
3278 - getModelSelectionStringOptionValue(turnInput.modelSelection, "agent") ??
3279 - (turnInput.runtimePolicy.interactionMode === "plan" ? "plan" : undefined);
3280 - const variant = getModelSelectionStringOptionValue(
3281 - turnInput.modelSelection,
3282 - "variant",
3283 - );
3287 yield* submitPrompt(
3288 state,
3289 turn,
@@ -3288,9 +3291,7 @@ export const makeOpenCodeAdapterV2 = Effect.fn("makeOpenCodeAdapterV2")(function
3291 sessionID: sessionId,
3292 messageID: turn.admissionMessageId!,
3293 model: parsedModel,
3291 - ...(agent === undefined ? {} : { agent }),
3292 - ...(variant === undefined ? {} : { variant }),
3293 - system: systemPrompt,
3294 + ...turnPromptOptions(turn),
3295 parts,
3296 },
3297 admissionAbortController!,
@@ -3401,6 +3402,7 @@ export const makeOpenCodeAdapterV2 = Effect.fn("makeOpenCodeAdapterV2")(function
3402 sessionID: sessionId,
3403 messageID: turn.admissionMessageId,
3404 model: parsedModel,
3405 + ...turnPromptOptions(turn),
3406 parts,
3407 },
3408 admissionAbortController!,