The best way to control Claude Code, Codex and more from any computer or phone
fix(providers): enforce approval and settings boundaries (#37826)
Julius Marminge committed
Nov 16, 2026 at 17:15 UTC
b4e47a5a62ec056dfcb95ee579c4390dfa04b345
16 files changed
+190
-44
apps/server/src/orchestration-v2/Adapters/FxAdapterV2.test.ts
+23
-1
@@ -151,6 +151,7 @@ const openFxSession = Effect.fn("openFxSession")(function* (input: {
151
readonly frames: ReadonlyArray<Frame>;
152
readonly runtimeMode: RuntimeMode;
153
readonly model?: string;
154
+ readonly modeOptions?: ReadonlyArray<{ readonly id: string; readonly value: string }>;
155
/** Loads this fx session instead of creating one. */
156
readonly loadSessionId?: string;
157
/** Then starts a turn on this model. */
@@ -195,7 +196,7 @@ const openFxSession = Effect.fn("openFxSession")(function* (input: {
196
const selectionOn = (model: string) => ({
197
instanceId,
198
model,
198
- options: [{ id: "effort", value: "xhigh" }],
199
+ options: [{ id: "effort", value: "xhigh" }, ...(input.modeOptions ?? [])],
200
});
201
const modelSelection = selectionOn(input.model ?? "default");
202
const runtimePolicy = ProviderAdapterV2RuntimePolicy.make({
@@ -294,6 +295,27 @@ describe("FxAdapterV2", () => {
295
).pipe(Effect.provide(testLayer)),
296
);
297
298
+ it.effect("keeps supervised sessions in the mode set by their runtime policy", () =>
299
+ openFxSession({
300
+ scenario: "supervised-mode-policy",
301
+ runtimeMode: "approval-required",
302
+ modeOptions: [
303
+ { id: "_t3/session-mode", value: "auto" },
304
+ { id: "mode", value: "auto" },
305
+ ],
306
+ frames: [
307
+ ...initialize,
308
+ outbound("session/new", {
309
+ cwd: "<workspace>",
310
+ mcpServers: "<any>",
311
+ _meta: { fx: { profileMcpServers: true } },
312
+ }),
313
+ answer("session/new", fxSession({ model: FX_DEFAULT_MODEL, modes: FX_MAIN_MODES })),
314
+ ...setConfig("mode", "ask", fxConfig({ model: FX_DEFAULT_MODEL, modes: FX_MAIN_MODES })),
315
+ ],
316
+ }).pipe(Effect.provide(testLayer)),
317
+ );
318
+
319
it.effect("puts a loaded session that ran a named model back on fx's default for Default", () =>
320
openFxSession({
321
scenario: "default-model",
apps/server/src/orchestration-v2/testkit/fixtures/proposed_plan/cursor_transcript.ndjson
+1
-1
@@ -1,5 +1,5 @@
1
{"type":"transcript_start","provider":"cursor","protocol":"cursor-agent-sdk.local","version":"1","scenario":"proposed_plan","metadata":{"generatedBy":"recordCursorAgentSdkReplayTranscript","nativeAgentId":"agent-bc5d59e0-bc8b-441a-9292-b49dfff962d3"}}
2
-{"type":"expect_outbound","label":"agent.open","frame":{"type":"agent.open","operation":"create","options":{"model":{"id":"composer-2.5"},"hasName":true,"mode":"plan","local":{"hasCwd":true,"autoReview":false,"settingSources":["project","user","team","mdm","plugins"],"sandboxEnabled":true,"enableAgentRetries":true}}}}
2
+{"type":"expect_outbound","label":"agent.open","frame":{"type":"agent.open","operation":"create","options":{"model":{"id":"composer-2.5"},"hasName":true,"mode":"plan","local":{"hasCwd":true,"autoReview":false,"settingSources":["user","team","mdm","plugins"],"sandboxEnabled":true,"enableAgentRetries":true}}}}
3
{"type":"emit_inbound","label":"agent.opened","frame":{"type":"agent.opened","agentId":"agent-bc5d59e0-bc8b-441a-9292-b49dfff962d3"}}
4
{"type":"expect_outbound","label":"run.start:1","frame":{"type":"run.start","message":"Create a short implementation plan for adding deterministic replay fixtures. Do not ask questions. Present the final plan in a proposed plan block.","options":{"model":{"id":"composer-2.5"},"mode":"plan"}}}
5
{"type":"emit_inbound","label":"run.started:1","frame":{"type":"run.started","runId":"run-6fc6c9f5-f2b7-4f6e-8922-d479f68e7710","agentId":"agent-bc5d59e0-bc8b-441a-9292-b49dfff962d3"}}
apps/server/src/orchestration-v2/testkit/fixtures/subagent/cursor_transcript.ndjson
+1
-1
@@ -1,5 +1,5 @@
1
{"type":"transcript_start","provider":"cursor","protocol":"cursor-agent-sdk.local","version":"1","scenario":"subagent","metadata":{"generatedBy":"recordCursorAgentSdkReplayTranscript","nativeAgentId":"agent-ad5d6f95-fe54-4557-bba5-05b781edb500"}}
2
-{"type":"expect_outbound","label":"agent.open","frame":{"type":"agent.open","operation":"create","options":{"model":{"id":"composer-2.5"},"hasName":true,"mode":"agent","local":{"hasCwd":true,"autoReview":false,"settingSources":["project","user","team","mdm","plugins"],"sandboxEnabled":true,"enableAgentRetries":true}}}}
2
+{"type":"expect_outbound","label":"agent.open","frame":{"type":"agent.open","operation":"create","options":{"model":{"id":"composer-2.5"},"hasName":true,"mode":"agent","local":{"hasCwd":true,"autoReview":false,"settingSources":["user","team","mdm","plugins"],"sandboxEnabled":true,"enableAgentRetries":true}}}}
3
{"type":"emit_inbound","label":"agent.opened","frame":{"type":"agent.opened","agentId":"agent-ad5d6f95-fe54-4557-bba5-05b781edb500"}}
4
{"type":"expect_outbound","label":"run.start:1","frame":{"type":"run.start","message":"Spawn 2 subagents, one to read package.json and one to read tsconfig.json","options":{"model":{"id":"composer-2.5"},"mode":"agent"}}}
5
{"type":"emit_inbound","label":"run.started:1","frame":{"type":"run.started","runId":"run-5bbb2b4a-7d9e-4ba5-8419-c5e171d86477","agentId":"agent-ad5d6f95-fe54-4557-bba5-05b781edb500"}}
apps/server/src/orchestration-v2/testkit/fixtures/todo_list/cursor_transcript.ndjson
+1
-1
@@ -1,5 +1,5 @@
1
{"type":"transcript_start","provider":"cursor","protocol":"cursor-agent-sdk.local","version":"1","scenario":"todo_list","metadata":{"generatedBy":"recordCursorAgentSdkReplayTranscript","nativeAgentId":"agent-c00e62bc-d851-4af3-8b1e-9b0ea874172e"}}
2
-{"type":"expect_outbound","label":"agent.open","frame":{"type":"agent.open","operation":"create","options":{"model":{"id":"composer-2.5"},"hasName":true,"mode":"agent","local":{"hasCwd":true,"autoReview":false,"settingSources":["project","user","team","mdm","plugins"],"sandboxEnabled":true,"enableAgentRetries":true}}}}
2
+{"type":"expect_outbound","label":"agent.open","frame":{"type":"agent.open","operation":"create","options":{"model":{"id":"composer-2.5"},"hasName":true,"mode":"agent","local":{"hasCwd":true,"autoReview":false,"settingSources":["user","team","mdm","plugins"],"sandboxEnabled":true,"enableAgentRetries":true}}}}
3
{"type":"emit_inbound","label":"agent.opened","frame":{"type":"agent.opened","agentId":"agent-c00e62bc-d851-4af3-8b1e-9b0ea874172e"}}
4
{"type":"expect_outbound","label":"run.start:1","frame":{"type":"run.start","message":"Use the update_plan tool to track exactly three steps: inspect package.json, inspect tsconfig.json, report completion. Then read package.json and tsconfig.json, and answer exactly: todo list fixture complete","options":{"model":{"id":"composer-2.5"},"mode":"agent"}}}
5
{"type":"emit_inbound","label":"run.started:1","frame":{"type":"run.started","runId":"run-4bdb1471-360c-45cc-af93-3db7c9a4fd01","agentId":"agent-c00e62bc-d851-4af3-8b1e-9b0ea874172e"}}
apps/server/src/orchestration-v2/testkit/fixtures/tool_call_read_only/cursor_transcript.ndjson
+1
-1
@@ -1,5 +1,5 @@
1
{"type":"transcript_start","provider":"cursor","protocol":"cursor-agent-sdk.local","version":"1","scenario":"tool_call_read_only","metadata":{"generatedBy":"recordCursorAgentSdkReplayTranscript","nativeAgentId":"agent-8d0e0bb5-b541-4073-b092-02374fc6fd9a"}}
2
-{"type":"expect_outbound","label":"agent.open","frame":{"type":"agent.open","operation":"create","options":{"model":{"id":"composer-2.5"},"hasName":true,"mode":"agent","local":{"hasCwd":true,"autoReview":false,"settingSources":["project","user","team","mdm","plugins"],"sandboxEnabled":true,"enableAgentRetries":true}}}}
2
+{"type":"expect_outbound","label":"agent.open","frame":{"type":"agent.open","operation":"create","options":{"model":{"id":"composer-2.5"},"hasName":true,"mode":"agent","local":{"hasCwd":true,"autoReview":false,"settingSources":["user","team","mdm","plugins"],"sandboxEnabled":true,"enableAgentRetries":true}}}}
3
{"type":"emit_inbound","label":"agent.opened","frame":{"type":"agent.opened","agentId":"agent-8d0e0bb5-b541-4073-b092-02374fc6fd9a"}}
4
{"type":"expect_outbound","label":"run.start:1","frame":{"type":"run.start","message":"Read /tmp/claude-replay-tool_call_read_only/package.json and /tmp/claude-replay-tool_call_read_only/tsconfig.json, then answer exactly: read only tool fixture complete","options":{"model":{"id":"composer-2.5"},"mode":"agent"}}}
5
{"type":"emit_inbound","label":"run.started:1","frame":{"type":"run.started","runId":"run-a79fc23e-2aec-48ad-985c-aeb4c79bae16","agentId":"agent-8d0e0bb5-b541-4073-b092-02374fc6fd9a"}}
apps/server/src/orchestration-v2/testkit/fixtures/turn_interrupt_mid_tool/cursor_transcript.ndjson
+1
-1
@@ -1,5 +1,5 @@
1
{"type":"transcript_start","provider":"cursor","protocol":"cursor-agent-sdk.local","version":"1","scenario":"turn_interrupt_mid_tool","metadata":{"generatedBy":"recordCursorAgentSdkReplayTranscript","nativeAgentId":"agent-09567560-2ac7-45bc-9805-d8cb6f895c01"}}
2
-{"type":"expect_outbound","label":"agent.open","frame":{"type":"agent.open","operation":"create","options":{"model":{"id":"composer-2.5"},"hasName":true,"mode":"agent","local":{"hasCwd":true,"autoReview":false,"settingSources":["project","user","team","mdm","plugins"],"sandboxEnabled":true,"enableAgentRetries":true}}}}
2
+{"type":"expect_outbound","label":"agent.open","frame":{"type":"agent.open","operation":"create","options":{"model":{"id":"composer-2.5"},"hasName":true,"mode":"agent","local":{"hasCwd":true,"autoReview":false,"settingSources":["user","team","mdm","plugins"],"sandboxEnabled":true,"enableAgentRetries":true}}}}
3
{"type":"emit_inbound","label":"agent.opened","frame":{"type":"agent.opened","agentId":"agent-09567560-2ac7-45bc-9805-d8cb6f895c01"}}
4
{"type":"expect_outbound","label":"run.start:1","frame":{"type":"run.start","message":"Run this exact local command: `node -e \"console.log('interrupt fixture tool started'); setTimeout(() => {}, 30000)\"`. Do not answer until it completes, then respond exactly: interrupt fixture should not finish naturally.","options":{"model":{"id":"composer-2.5"},"mode":"agent"}}}
5
{"type":"emit_inbound","label":"run.started:1","frame":{"type":"run.started","runId":"run-dfd86d28-321f-4962-9bf7-7b832e19c6c1","agentId":"agent-09567560-2ac7-45bc-9805-d8cb6f895c01"}}
apps/server/src/textGeneration/ClaudeTextGeneration.test.ts
+26
@@ -62,6 +62,7 @@ function withFakeClaudeEnv<A, E, R>(
62
exitCode?: number;
63
stderr?: string;
64
argsMustContain?: string;
65
+ expectedTools?: string;
66
argsMustNotContain?: string;
67
stdinMustContain?: string;
68
configDirMustBe?: string;
@@ -83,6 +84,7 @@ function withFakeClaudeEnv<A, E, R>(
84
: undefined,
85
T3_FAKE_CLAUDE_EXIT_CODE: input.exitCode === undefined ? undefined : String(input.exitCode),
86
T3_FAKE_CLAUDE_STDERR: input.stderr,
87
+ T3_FAKE_CLAUDE_EXPECTED_TOOLS: input.expectedTools,
88
T3_FAKE_CLAUDE_ARGS_MUST_CONTAIN: input.argsMustContain,
89
T3_FAKE_CLAUDE_ARGS_MUST_NOT_CONTAIN: input.argsMustNotContain,
90
T3_FAKE_CLAUDE_STDIN_MUST_CONTAIN: input.stdinMustContain,
@@ -110,6 +112,30 @@ function withFakeClaudeEnv<A, E, R>(
112
}
113
114
it.layer(layerClaudeTextGenerationTest)("ClaudeTextGeneration", (it) => {
115
+ it.effect("loads only user settings when generating review guides", () =>
116
+ withFakeClaudeEnv(
117
+ {
118
+ output: JSON.stringify({ structured_output: { stops: [] } }),
119
+ argsMustContain: "--setting-sources user",
120
+ expectedTools: "Read,Grep,Glob,Bash",
121
+ },
122
+ (textGeneration) =>
123
+ textGeneration.generateReviewGuide({
124
+ cwd: process.cwd(),
125
+ number: 12,
126
+ title: "Review a change",
127
+ description: "",
128
+ baseBranch: "main",
129
+ baseCommit: "base",
130
+ settledReview: "",
131
+ modelSelection: createModelSelection(
132
+ ProviderInstanceId.make("claudeAgent"),
133
+ SYNTHETIC_CLAUDE_CAPABLE_MODEL,
134
+ ),
135
+ }),
136
+ ),
137
+ );
138
+
139
it.effect(
140
"keeps canonical built-in capabilities when a custom model collides with its alias",
141
() =>
apps/server/src/textGeneration/ClaudeTextGeneration.ts
+1
@@ -253,6 +253,7 @@ export const makeClaudeTextGeneration = Effect.fn("makeClaudeTextGeneration")(fu
253
CLAUDE_INVESTIGATION_DENIED,
254
]
255
: ["--tools", ""]),
256
+ ...(investigate ? ["--setting-sources", "user"] : []),
257
"--disable-slash-commands",
258
...(noSessionPersistence ? [NO_SESSION_PERSISTENCE] : []),
259
// managed-mcp.json already isolates servers and makes Claude reject this flag.
apps/server/src/textGeneration/testing/ClaudeTextGeneration.fixture.mjs
+5
-2
@@ -13,8 +13,11 @@ if (permissionIndex === -1 || argv[permissionIndex + 1] !== "dontAsk") {
13
fail("text generation must deny permission prompts", 12);
14
}
15
const toolsIndex = argv.indexOf("--tools");
16
-if (toolsIndex === -1 || argv[toolsIndex + 1] !== "") {
17
- fail("text generation must receive an explicit empty tool set", 6);
16
+if (
17
+ toolsIndex === -1 ||
18
+ argv[toolsIndex + 1] !== (process.env.T3_FAKE_CLAUDE_EXPECTED_TOOLS ?? "")
19
+) {
20
+ fail("text generation did not receive the expected tool set", 6);
21
}
22
if (argv.includes("--dangerously-skip-permissions")) {
23
fail("text generation must not bypass permissions", 7);
packages/provider-acp/src/server/adapter.ts
+16
-2
@@ -445,6 +445,7 @@ export interface AcpAdapterV2Flavor {
445
* `reasoningEffort` is its `effortLevel`).
446
*/
447
readonly ownedModelOptionIds?: ReadonlyArray<string>;
448
+ readonly lockSessionModeToPolicy?: true;
449
readonly sessionModeForPolicy?: (
450
policy: ProviderAdapter.ProviderAdapterV2RuntimePolicy,
451
) => string | undefined;
@@ -2097,6 +2098,9 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
2098
});
2099
const activeSelection = yield* Ref.make<ModelSelection | null>(null);
2100
const activeInteractionMode = yield* Ref.make<ProviderInteractionMode | null>(null);
2101
+ const configuredRuntimeMode = yield* Ref.make<
2102
+ ProviderAdapter.ProviderAdapterV2RuntimePolicy["runtimeMode"] | null
2103
+ >(null);
2104
const promptInstructionStates = yield* Ref.make(new Map<string, T3AcpInstructionState>());
2105
const promptRuntimeInstructions = yield* Ref.make(new Map<string, string>());
2106
// Unique markers keep delayed prompt completions from clearing later compactions.
@@ -7801,11 +7805,13 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
7805
yield* runtime.setConfigOption(selection.id, selection.value);
7806
}
7807
const policyMode = flavor.sessionModeForPolicy?.(runtimePolicy);
7808
+ const modeLocked = flavor.lockSessionModeToPolicy && policyMode !== undefined;
7809
if (policyMode !== undefined) {
7810
yield* runtime.setMode(policyMode);
7811
}
7812
const modeState = yield* runtime.getModeState;
7813
if (
7814
+ !modeLocked &&
7815
modeSelection !== undefined &&
7816
typeof modeSelection.value === "string" &&
7817
modeState?.availableModes.some((mode) => mode.id === modeSelection.value) === true &&
@@ -7856,6 +7862,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
7862
const nativeBuild = nativeBuildConfigurationBySessionId.get(startResult.sessionId);
7863
if (nativeBuild !== undefined) {
7864
if (
7865
+ !modeLocked &&
7866
nativeBuild.modeId !== undefined &&
7867
effectiveModeState?.currentModeId !== nativeBuild.modeId &&
7868
effectiveModeState?.availableModes.some(
@@ -7868,7 +7875,12 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
7875
const option = effectiveConfigOptions.find(
7876
(candidate) => candidate.type === "select" && candidate.id === saved.id,
7877
);
7871
- if (option === undefined || option.type !== "select") continue;
7878
+ if (
7879
+ option === undefined ||
7880
+ option.type !== "select" ||
7881
+ (modeLocked && option.category === "mode")
7882
+ )
7883
+ continue;
7884
const choices = option.options.flatMap((entry) =>
7885
"value" in entry ? [entry.value] : entry.options.map((choice) => choice.value),
7886
);
@@ -7880,6 +7892,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
7892
}
7893
}
7894
yield* validateModelSelection(modelSelection);
7895
+ yield* Ref.set(configuredRuntimeMode, runtimePolicy.runtimeMode);
7896
yield* (
7897
flavor.onSessionConfigurationUpdate?.(
7898
yield* runtime.getConfigOptions,
@@ -8546,7 +8559,8 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
8559
if (
8560
configuredSelection === null ||
8561
!modelSelectionsEqual(configuredSelection, turnInput.modelSelection) ||
8549
- configuredInteractionMode !== turnInput.runtimePolicy.interactionMode
8562
+ configuredInteractionMode !== turnInput.runtimePolicy.interactionMode ||
8563
+ (yield* Ref.get(configuredRuntimeMode)) !== turnInput.runtimePolicy.runtimeMode
8564
) {
8565
const currentSessionSetup = yield* Ref.get(activeSessionSetup);
8566
if (currentSessionSetup === null) {
packages/provider-cursor/src/server/adapter.test.ts
+45
@@ -2500,6 +2500,51 @@ describe("CursorAdapterV2", () => {
2500
assert.notInclude(logged, "secret-cursor-mcp-token");
2501
});
2502
2503
+ it("loads project settings only when runtime policy permits unrestricted execution", () => {
2504
+ const input = {
2505
+ modelSelection: { instanceId: ProviderInstanceId.make("cursor"), model: "composer-2.5" },
2506
+ threadId: ThreadId.make("cursor-project-settings"),
2507
+ mcpSession: undefined,
2508
+ platform: "linux" as const,
2509
+ };
2510
+ const policy = { cwd: "/workspace", interactionMode: "default" as const };
2511
+ for (const runtimeMode of [
2512
+ "approval-required",
2513
+ "auto",
2514
+ "auto-accept-edits",
2515
+ "full-access",
2516
+ ] as const) {
2517
+ const options = makeCursorAgentOptions({
2518
+ ...input,
2519
+ runtimePolicy: { ...policy, runtimeMode },
2520
+ });
2521
+ assert.equal(
2522
+ options.local?.settingSources?.includes("project"),
2523
+ runtimeMode === "full-access",
2524
+ );
2525
+ }
2526
+ const unrestrictedOverrides = makeCursorAgentOptions({
2527
+ ...input,
2528
+ runtimePolicy: {
2529
+ ...policy,
2530
+ runtimeMode: "auto-accept-edits",
2531
+ approvalPolicy: "never",
2532
+ sandboxPolicy: { type: "dangerFullAccess" },
2533
+ },
2534
+ });
2535
+ assert.notInclude(unrestrictedOverrides.local?.settingSources ?? [], "project");
2536
+ for (const restriction of [
2537
+ { approvalPolicy: "on-request" as const },
2538
+ { sandboxPolicy: { type: "readOnly" as const } },
2539
+ ]) {
2540
+ const options = makeCursorAgentOptions({
2541
+ ...input,
2542
+ runtimePolicy: { ...policy, runtimeMode: "full-access", ...restriction },
2543
+ });
2544
+ assert.notInclude(options.local?.settingSources ?? [], "project");
2545
+ }
2546
+ });
2547
+
2548
it.effect.skipIf(!symlinksSupported)(
2549
"starts mcp.json servers that use Cursor's workspace variables",
2550
() =>
packages/provider-cursor/src/server/adapter.ts
+6
-1
@@ -323,7 +323,12 @@ export function makeCursorAgentOptions(input: {
323
local: {
324
...(input.runtimePolicy.cwd === null ? {} : { cwd: input.runtimePolicy.cwd }),
325
autoReview: policy.autoReview,
326
- settingSources: [...CURSOR_AGENT_SETTING_SOURCES],
326
+ settingSources:
327
+ input.runtimePolicy.runtimeMode === "full-access" &&
328
+ !policy.autoReview &&
329
+ !policy.sandboxEnabled
330
+ ? [...CURSOR_AGENT_SETTING_SOURCES]
331
+ : CURSOR_AGENT_SETTING_SOURCES.filter((source) => source !== "project"),
332
sandboxOptions: {
333
enabled: policy.sandboxEnabled,
334
},
packages/provider-fx/src/server/acpSupport.ts
+1
-1
@@ -26,7 +26,7 @@ export const FX_DRIVER_KIND = ProviderDriverKind.make("fx");
26
/** T3's slug for "Default": the model `fx status` reports, never an fx model id. */
27
export const FX_DEFAULT_MODEL_SLUG = "default";
28
const FX_MODEL_CONFIG_ID = "model";
29
-const FX_MODE_CONFIG_ID = "mode";
29
+export const FX_MODE_CONFIG_ID = "mode";
30
const FX_EFFORT_CONFIG_ID = "effort";
31
const FX_DEFAULT_EFFORT = "medium";
32
packages/provider-fx/src/server/adapter.ts
+3
@@ -21,6 +21,7 @@ import {
21
FX_DRIVER_KIND,
22
FX_SESSION_META,
23
fxPermissionDisposition,
24
+ FX_MODE_CONFIG_ID,
25
fxSessionModeForPolicy,
26
makeFxAcpRuntime,
27
withFxSessionMode,
@@ -189,6 +190,8 @@ function makeFxAcpAdapterFlavor(options: FxAdapterV2Options): AcpAdapterV2Flavor
190
applyFxModelSelection(runtime, modelSelection, options.defaultModel).pipe(
191
Effect.tap(() => applyFxEffortDefault(runtime, modelSelection)),
192
),
193
+ ownedModelOptionIds: [FX_MODE_CONFIG_ID],
194
+ lockSessionModeToPolicy: true,
195
sessionModeForPolicy: fxSessionModeForPolicy,
196
permissionDisposition: fxPermissionDisposition,
197
extractSubagentUpdate: extractFxSubagentUpdate,
packages/provider-opencode/src/server/adapter.test.ts
+55
-26
@@ -161,6 +161,7 @@ const makeOpenCodeRuntimeHarness = Effect.fn("makeOpenCodeRuntimeHarness")(funct
161
readonly exitCode?: Effect.Effect<number>;
162
readonly options?: ReadonlyArray<ProviderOptionSelection>;
163
readonly interactionMode?: ProviderAdapter.ProviderAdapterV2RuntimePolicy["interactionMode"];
164
+ readonly attachments?: ProviderAdapter.ProviderAdapterV2TurnInput["message"]["attachments"];
165
} = {},
166
) {
167
const instanceId = ProviderInstanceId.make(`opencode-${suffix}`);
@@ -251,7 +252,7 @@ const makeOpenCodeRuntimeHarness = Effect.fn("makeOpenCodeRuntimeHarness")(funct
252
creationSource: continuation === undefined ? "web" : "provider",
253
messageId: MessageId.make(`message-opencode-${turnKey}`),
254
text,
254
- attachments: [],
255
+ attachments: turnSettings.attachments ?? [],
256
},
257
modelSelection: { ...modelSelection, model: continuation?.model ?? modelSelection.model },
258
runtimePolicy: turnPolicy,
@@ -3293,40 +3294,62 @@ describe("OpenCodeAdapterV2", () => {
3294
command: string;
3295
arguments: string;
3296
model: string;
3297
+ parts: ReadonlyArray<{ type: string; filename: string }>;
3298
}>();
3299
let promptCalls = 0;
3300
const sessionId = "native-command";
3299
- const harness = yield* makeOpenCodeRuntimeHarness("native-command", sessionId, {
3300
- event: {
3301
- subscribe: async (_input: unknown, options: { signal?: AbortSignal }) => {
3302
- options.signal?.addEventListener("abort", () => nativeEvents.close(), { once: true });
3303
- return { stream: nativeEvents.stream };
3304
- },
3305
- },
3306
- command: { list: async () => ({ data: [{ name: "git/review" }] }) },
3307
- session: {
3308
- create: async () => ({ data: { id: sessionId, time: { created: 1, updated: 1 } } }),
3309
- command: async (input: {
3310
- messageID: string;
3311
- command: string;
3312
- arguments: string;
3313
- model: string;
3314
- }) => {
3315
- Queue.offerUnsafe(calls, input);
3316
- await release.promise;
3317
- return { data: true };
3301
+ const harness = yield* makeOpenCodeRuntimeHarness(
3302
+ "native-command",
3303
+ sessionId,
3304
+ {
3305
+ event: {
3306
+ subscribe: async (_input: unknown, options: { signal?: AbortSignal }) => {
3307
+ options.signal?.addEventListener("abort", () => nativeEvents.close(), { once: true });
3308
+ return { stream: nativeEvents.stream };
3309
+ },
3310
},
3319
- promptAsync: async () => {
3320
- promptCalls++;
3321
- return { data: true };
3311
+ command: { list: async () => ({ data: [{ name: "git/review" }] }) },
3312
+ session: {
3313
+ create: async () => ({ data: { id: sessionId, time: { created: 1, updated: 1 } } }),
3314
+ command: async (input: {
3315
+ messageID: string;
3316
+ command: string;
3317
+ arguments: string;
3318
+ model: string;
3319
+ parts: ReadonlyArray<{ type: string; filename: string }>;
3320
+ }) => {
3321
+ Queue.offerUnsafe(calls, input);
3322
+ await release.promise;
3323
+ return { data: true };
3324
+ },
3325
+ promptAsync: async () => {
3326
+ promptCalls++;
3327
+ return { data: true };
3328
+ },
3329
},
3330
},
3324
- });
3331
+ { resolveAttachmentPath: () => "/workspace/review-notes.txt" },
3332
+ {
3333
+ attachments: [
3334
+ {
3335
+ type: "file",
3336
+ id: "notes",
3337
+ name: "review-notes.txt",
3338
+ mimeType: "text/plain",
3339
+ sizeBytes: 24,
3340
+ },
3341
+ ],
3342
+ },
3343
+ );
3344
const start = yield* harness.startTurn("/git/review staged changes").pipe(Effect.forkScoped);
3345
const call = yield* Queue.take(calls);
3346
assert.equal(call.command, "git/review");
3347
assert.equal(call.arguments, "staged changes");
3348
assert.equal(call.model, "anthropic/claude-sonnet");
3349
+ assert.deepEqual(
3350
+ call.parts.map((part) => part.filename),
3351
+ ["review-notes.txt"],
3352
+ );
3353
yield* Effect.promise(() =>
3354
nativeEvents.push({
3355
type: "message.updated",
@@ -4975,9 +4998,15 @@ describe("OpenCodeAdapterV2", () => {
4998
assert.equal(permissionAction(childRules, "task"), "deny");
4999
5000
const approvalRequiredPolicy = runtimePolicy("approval-required");
4978
- const parentRules = openCodePermissionRules(approvalRequiredPolicy);
5001
+ const initialChildRules = openCodePermissionRules(approvalRequiredPolicy).filter(
5002
+ (rule) => rule.permission === "external_directory" || rule.action === "deny",
5003
+ );
5004
+ assert.equal(permissionAction(initialChildRules, "bash"), "deny");
5005
+ assert.equal(permissionAction(initialChildRules, "edit"), "deny");
5006
+ assert.equal(permissionAction(initialChildRules, "unknown_plugin_tool"), "deny");
5007
+
5008
const childApprovalRules = openCodeChildPermissionRules(approvalRequiredPolicy, [
4980
- ...parentRules.filter((rule) => rule.action === "deny"),
5009
+ ...initialChildRules,
5010
{ permission: "task", pattern: "*", action: "deny" },
5011
]);
5012
assert.equal(permissionAction(childApprovalRules, "bash"), "ask");
packages/provider-opencode/src/server/adapter.ts
+4
-6
@@ -3491,6 +3491,7 @@ export const makeOpenCodeAdapterV2 = Effect.fn("makeOpenCodeAdapterV2")(function
3491
sessionID: string;
3492
},
3493
abortController: AbortController,
3494
+ messageText: string,
3495
) {
3496
const { variant, ...payloadWithoutVariant } = inputPayload;
3497
const selectedVariant = yield* OpenCodeRuntime.resolveOpenCodeVariant(
@@ -3504,12 +3505,7 @@ export const makeOpenCodeAdapterV2 = Effect.fn("makeOpenCodeAdapterV2")(function
3505
...payloadWithoutVariant,
3506
...(selectedVariant === undefined ? {} : { variant: selectedVariant }),
3507
};
3507
- const text = payload.parts
3508
- ?.filter((part) => part.type === "text")
3509
- .map((part) => part.text)
3510
- .join("\n")
3511
- .trim();
3512
- const match = text?.match(/^\/(\S+)(?:\s+([\s\S]*))?$/);
3508
+ const match = messageText.trim().match(/^\/(\S+)(?:\s+([\s\S]*))?$/);
3509
const command = match
3510
? (yield* OpenCodeRuntime.loadOpenCodeCommands(client).pipe(
3511
Effect.timeout("10 seconds"),
@@ -3924,6 +3920,7 @@ export const makeOpenCodeAdapterV2 = Effect.fn("makeOpenCodeAdapterV2")(function
3920
parts,
3921
},
3922
admissionAbortController!,
3923
+ turnInput.message.text,
3924
).pipe(
3925
Effect.tapError((cause) =>
3926
admissionAbortController!.signal.aborted
@@ -4069,6 +4066,7 @@ export const makeOpenCodeAdapterV2 = Effect.fn("makeOpenCodeAdapterV2")(function
4066
parts,
4067
},
4068
admissionAbortController!,
4069
+ steerInput.message.text,
4070
).pipe(
4071
Effect.tapError((error) => {
4072
if (!promptAdmissionIsCurrent(state, turn, generation)) return Effect.void;