Skip to content

Commit f14fa03

Browse files
only21milclaudemaria-rcks
authored
fix(opencode): steers keep the turn's agent, variant and instructions (pingdotgg#23270)
Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: maria-rcks <[email protected]>
1 parent cb79cfb commit f14fa03

2 files changed

Lines changed: 88 additions & 22 deletions

File tree

‎packages/provider-opencode/src/server/adapter.test.ts‎

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
ThreadId,
2121
type OrchestrationV2ProviderThread,
2222
type OrchestrationV2ProviderTurn,
23+
type ProviderOptionSelection,
2324
} from "@t3tools/contracts";
2425
import { OpenCodeSettings } from "../settings.ts";
2526
import * as Effect from "effect/Effect";
@@ -151,15 +152,22 @@ const makeOpenCodeRuntimeHarness = Effect.fn("makeOpenCodeRuntimeHarness")(funct
151152
nativeSessionId: string,
152153
client: object,
153154
host: Partial<ProviderHost.ProviderHost["Service"]> = {},
155+
turnSettings: {
156+
readonly options?: ReadonlyArray<ProviderOptionSelection>;
157+
readonly interactionMode?: ProviderAdapter.ProviderAdapterV2RuntimePolicy["interactionMode"];
158+
} = {},
154159
) {
155160
const instanceId = ProviderInstanceId.make(`opencode-${suffix}`);
156161
const threadId = ThreadId.make(`thread-opencode-${suffix}`);
157162
const modelSelection = {
158163
instanceId,
159164
model: "anthropic/claude-sonnet",
160-
options: [],
165+
options: turnSettings.options ?? [],
161166
};
162-
const policy = runtimePolicy("full-access", { cwd: "/workspace" });
167+
const policy = runtimePolicy("full-access", {
168+
cwd: "/workspace",
169+
interactionMode: turnSettings.interactionMode ?? "default",
170+
});
163171
const adapter = yield* makeOpenCodeAdapterV2({
164172
instanceId,
165173
settings: OPEN_CODE_TEST_SETTINGS,
@@ -200,7 +208,7 @@ const makeOpenCodeRuntimeHarness = Effect.fn("makeOpenCodeRuntimeHarness")(funct
200208
providerInstanceId: modelSelection.instanceId,
201209
modelSelection,
202210
runtimeMode: "full-access",
203-
interactionMode: "default",
211+
interactionMode: policy.interactionMode,
204212
branch: null,
205213
worktreePath: null,
206214
activeProviderThreadId: providerThread.id,
@@ -1588,6 +1596,62 @@ describe("OpenCodeAdapterV2", () => {
15881596
),
15891597
);
15901598

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+
15911655
it.effect("keeps a newly admitted prompt alive across stale idle and delayed busy evidence", () =>
15921656
Effect.gen(function* () {
15931657
const nativeEvents = asyncEventStream();

‎packages/provider-opencode/src/server/adapter.ts‎

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2943,6 +2943,25 @@ export const makeOpenCodeAdapterV2 = Effect.fn("makeOpenCodeAdapterV2")(function
29432943
};
29442944
});
29452945

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+
29462965
// Native commands await generation; user-message receipts admit their background requests.
29472966
const submitPrompt = Effect.fn("OpenCode.submitPrompt")(function* (
29482967
state: OpenCodeThreadState,
@@ -3265,32 +3284,14 @@ export const makeOpenCodeAdapterV2 = Effect.fn("makeOpenCodeAdapterV2")(function
32653284
);
32663285
return;
32673286
}
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-
);
32843287
yield* submitPrompt(
32853288
state,
32863289
turn,
32873290
{
32883291
sessionID: sessionId,
32893292
messageID: turn.admissionMessageId!,
32903293
model: parsedModel,
3291-
...(agent === undefined ? {} : { agent }),
3292-
...(variant === undefined ? {} : { variant }),
3293-
system: systemPrompt,
3294+
...turnPromptOptions(turn),
32943295
parts,
32953296
},
32963297
admissionAbortController!,
@@ -3401,6 +3402,7 @@ export const makeOpenCodeAdapterV2 = Effect.fn("makeOpenCodeAdapterV2")(function
34013402
sessionID: sessionId,
34023403
messageID: turn.admissionMessageId,
34033404
model: parsedModel,
3405+
...turnPromptOptions(turn),
34043406
parts,
34053407
},
34063408
admissionAbortController!,

0 commit comments

Comments
 (0)