From 10fc29525149cadf9c9afb07752e9d19affd4d22 Mon Sep 17 00:00:00 2001 From: eyeveil <64274427+eyeveil@users.noreply.github.com> Date: Sun, 22 Nov 2026 21:16:13 +0100 Subject: [PATCH 1/2] Accept Codex approval requests in full-access threads without asking --- .../Adapters/CodexAdapterV2.test.ts | 149 ++++++++++++++++-- .../Adapters/CodexAdapterV2.ts | 22 ++- 2 files changed, 156 insertions(+), 15 deletions(-) diff --git a/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts index cd5e51a32f616..21a1e41beddfd 100644 --- a/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts @@ -1836,6 +1836,122 @@ describe("CodexAdapterV2 post-settle continuation", () => { ), ); + it.effect("accepts command, file and permission approvals in full access without asking", () => + Effect.gen(function* () { + const nativeThreadId = "full-access-approval-thread"; + const nativeTurnId = "full-access-approval-turn"; + const prompt = "Clean the scratch folder."; + const pending = yield* Queue.unbounded(); + const permissions = { + fileSystem: { entries: [{ access: "write", path: { type: "path", path: "/outside" } }] }, + } as const; + const harness = yield* makeCodexReplayHarness( + makeCodexReplayTranscript({ + scenario: "full-access-approvals", + entries: [ + ...codexReplayPreamble({ nativeThreadId, nativeTurnId, prompt }), + { + type: "emit_inbound", + frame: { + id: 0, + method: "item/commandExecution/requestApproval", + params: { + threadId: nativeThreadId, + turnId: nativeTurnId, + itemId: "exec-rm", + startedAtMs: 1, + command: "rm -rf -- /tmp/scratch", + }, + }, + }, + { + type: "expect_outbound", + frame: { id: 0, result: { decision: "acceptForSession" } }, + }, + { + type: "emit_inbound", + frame: { + id: 1, + method: "item/fileChange/requestApproval", + params: { + threadId: nativeThreadId, + turnId: nativeTurnId, + itemId: "patch", + startedAtMs: 2, + }, + }, + }, + { + type: "expect_outbound", + frame: { id: 1, result: { decision: "acceptForSession" } }, + }, + { + type: "emit_inbound", + frame: { + id: 2, + method: "item/permissions/requestApproval", + params: { + threadId: nativeThreadId, + turnId: nativeTurnId, + itemId: "permissions", + cwd: "/workspace", + startedAtMs: 3, + permissions, + }, + }, + }, + { + type: "expect_outbound", + frame: { id: 2, result: { permissions, scope: "session" } }, + }, + { + type: "emit_inbound", + frame: { + method: "turn/completed", + params: { + threadId: nativeThreadId, + turn: makeCodexReplayTurn({ id: nativeTurnId, status: "completed" }), + }, + }, + }, + ], + }), + (event) => + event.type === "runtime_request.updated" && event.runtimeRequest.status === "pending" + ? Queue.offer(pending, event.runtimeRequest) + : Effect.void, + ); + yield* harness.runtime.startTurn( + makeCodexTestTurnInput({ + threadId: harness.threadId, + providerThread: harness.providerThread, + now: yield* DateTime.now, + attemptId: RunAttemptId.make("full-access-approvals-attempt"), + text: prompt, + }), + ); + const request = yield* Effect.raceFirst( + harness.firstTerminal.pipe(Effect.as(undefined)), + Queue.take(pending), + ); + assert.isUndefined(request, "Full access must not wait for an approval"); + assert.deepEqual( + harness.terminalEvents().map((event) => event.status), + ["completed"], + ); + }).pipe( + Effect.scoped, + Effect.provide( + Layer.mergeAll( + IdAllocator.layer, + McpProviderSessions.layer, + NodeServices.layer, + NodeCrypto.layer, + ), + ), + ), + ); + it.effect.each(["native", "ordinary"] as const)( "resumes Codex without a prompt only for an existing conversation (%s)", (mode) => @@ -12487,22 +12603,35 @@ describe("CodexAdapterV2 post-settle continuation", () => { const harness = yield* makeCodexReplayHarness( makeCodexReplayTranscript({ scenario, - entries: [...codexReplayPreamble({ nativeThreadId, nativeTurnId, prompt }), ...entries], + entries: [ + ...codexReplayPreamble({ + nativeThreadId, + nativeTurnId, + prompt, + turnPolicy: { + approvalPolicy: "on-request", + sandboxPolicy: { type: "workspaceWrite" }, + }, + }), + ...entries, + ], }), (event) => event.type === "runtime_request.updated" && event.runtimeRequest.status === "pending" ? Queue.offer(pending, event.runtimeRequest) : Effect.void, ); - yield* harness.runtime.startTurn( - makeCodexTestTurnInput({ - threadId: harness.threadId, - providerThread: harness.providerThread, - now: yield* DateTime.now, - attemptId: RunAttemptId.make(`${scenario}-attempt`), - text: prompt, - }), - ); + const turnInput = makeCodexTestTurnInput({ + threadId: harness.threadId, + providerThread: harness.providerThread, + now: yield* DateTime.now, + attemptId: RunAttemptId.make(`${scenario}-attempt`), + text: prompt, + }); + yield* harness.runtime.startTurn({ + ...turnInput, + runtimePolicy: { ...turnInput.runtimePolicy, runtimeMode: "auto-accept-edits" }, + }); return { harness, answerNext: Queue.take(pending).pipe( diff --git a/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts b/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts index 09036b09e3f77..69e642c9c182d 100644 --- a/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts +++ b/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts @@ -798,6 +798,11 @@ function codexRuntimeModeTurnDefaults(runtimeMode: RuntimeMode): { } } +// Codex still asks under full access's granular policy, for example before `rm -rf`. +const isFullAccess = (context: { + readonly input: { readonly runtimePolicy: { readonly runtimeMode: RuntimeMode } }; +}) => context.input.runtimePolicy.runtimeMode === "full-access"; + const isCodexCyberAccessProgram = Schema.is(CodexSchema.V2TurnStartParams__CyberAccessProgram); function codexCyberAccess( @@ -5988,7 +5993,7 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* ( ); } const allowance = sessionAllowance(payload.threadId, context); - if (allowance.has("command")) { + if (allowance.has("command") || isFullAccess(context)) { return { decision: "acceptForSession", } satisfies CodexSchema.CommandExecutionRequestApprovalResponse; @@ -6059,7 +6064,7 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* ( ); } const allowance = sessionAllowance(payload.threadId, context); - if (allowance.has("file-change")) { + if (allowance.has("file-change") || isFullAccess(context)) { return { decision: "acceptForSession", } satisfies CodexSchema.FileChangeRequestApprovalResponse; @@ -6131,6 +6136,13 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* ( ); } + if (isFullAccess(context)) { + return permissionsResponseFromDecision({ + decision: "acceptForSession", + permissions: payload.permissions, + }); + } + const requestKind = providerRequestKindFromPermissions(payload.permissions); const artifacts = yield* buildApprovalRequestArtifacts({ context, @@ -6208,7 +6220,7 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* ( } satisfies CodexSchema.McpServerElicitationRequestResponse; } - if (context.input.runtimePolicy.runtimeMode === "full-access") { + if (isFullAccess(context)) { return acceptance; } @@ -6276,7 +6288,7 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* ( ); } const allowance = sessionAllowance(payload.conversationId, context); - if (allowance.has("command")) { + if (allowance.has("command") || isFullAccess(context)) { return { decision: "approved_for_session", } satisfies CodexSchema.ExecCommandApprovalResponse; @@ -6345,7 +6357,7 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* ( ); } const allowance = sessionAllowance(payload.conversationId, context); - if (allowance.has("file-change")) { + if (allowance.has("file-change") || isFullAccess(context)) { return { decision: "approved_for_session", } satisfies CodexSchema.ApplyPatchApprovalResponse; From 7597f61f585d3769eeef628cbf260fd9cd6987d6 Mon Sep 17 00:00:00 2001 From: eyeveil <64274427+eyeveil@users.noreply.github.com> Date: Sun, 22 Nov 2026 21:50:04 +0100 Subject: [PATCH 2/2] Answer approvals in full-access threads on Claude, Muse, Kiro, Pi and OpenCode --- .../Adapters/ClaudeAdapterV2.test.ts | 156 ++++++++---------- .../Adapters/ClaudeAdapterV2.ts | 17 +- .../Adapters/KiroAdapterV2.test.ts | 12 +- .../Adapters/OpenCode2AdapterV2.test.ts | 13 +- .../provider-kiro/src/server/acpSupport.ts | 12 +- .../provider-muse/src/server/adapter.test.ts | 63 +++++-- packages/provider-muse/src/server/adapter.ts | 6 +- .../src/server/adapter.test.ts | 9 + .../provider-opencode/src/server/adapter.ts | 15 ++ .../src/server/v2/adapter.ts | 14 ++ .../provider-pi/src/server/adapter.test.ts | 58 ++++++- packages/provider-pi/src/server/adapter.ts | 12 ++ 12 files changed, 263 insertions(+), 124 deletions(-) diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts index b4b808d19c6f0..a65943b78985e 100644 --- a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts @@ -52,6 +52,7 @@ import { ProviderTurnId, RunAttemptId, RunId, + type RuntimeMode, ThreadId, } from "@t3tools/contracts"; import { mcpAppFromToolItem } from "@t3tools/shared/toolOutput"; @@ -2245,22 +2246,14 @@ describe("ClaudeAdapterV2 resume compaction", () => { Effect.map((event) => ({ type: "approval", event }) as const), ), ); - assert.equal(safety.type, askRule ? "approval" : "decision"); + // Full access answers the user's own ask rule without a card. + assert.equal(safety.type, "decision"); if (safety.type === "decision") { - assert.equal(safety.result?.behavior, "deny"); + assert.equal(safety.result?.behavior, askRule ? "allow" : "deny"); if (safety.result?.behavior === "deny") { assert.include(safety.result.message, reason); assert.notInclude(safety.result.message, "\u001b["); } - } else if ( - Option.isSome(safety.event) && - safety.event.value.type === "runtime_request.updated" - ) { - yield* runtime.respondToRuntimeRequest({ - requestId: safety.event.value.runtimeRequest.id, - decision: "decline", - }); - assert.equal((yield* Fiber.join(safetyDecision))?.behavior, "deny"); } yield* Fiber.interrupt(safetyRequest); } @@ -5223,18 +5216,9 @@ describe("ClaudeAdapterV2 background wake turns", () => { Effect.map((result) => ({ type: "decision", result }) as const), ), ); - assert.equal( - first.type, - "request", - "Full access must not auto-allow a policy-restricted command", - ); - if (first.type !== "request") return; - assert.equal(first.event.runtimeRequest.kind, "command"); - yield* harness.runtime.respondToRuntimeRequest({ - requestId: first.event.runtimeRequest.id, - decision: "decline", - }); - assert.equal((yield* Fiber.join(decision))?.behavior, "deny"); + // Full access answers asks itself, even when settings disable bypass. + assert.equal(first.type, "decision", "Full access must not ask"); + assert.equal(first.type === "decision" ? first.result?.behavior : undefined, "allow"); assert.equal(openedOptions.permissionMode, "auto"); assert.isUndefined(openedOptions.allowDangerouslySkipPermissions); @@ -5265,8 +5249,7 @@ describe("ClaudeAdapterV2 background wake turns", () => { yield* start("/unrestricted"); assert.equal(harness.getOpenedOptions()?.permissionMode, "bypassPermissions"); assert.equal(harness.getOpenedOptions()?.allowDangerouslySkipPermissions, true); - // Forwarded asks (including ask rules and settings fallback) still need a decision - // before queued init/status frames arrive. + // Forwarded asks are answered from T3's runtime mode before init/status frames arrive. for (const { phase, frame } of [ { phase: "init", @@ -5310,17 +5293,10 @@ describe("ClaudeAdapterV2 background wake turns", () => { ), ); assert.equal( - forwardedFirst.type, - "request", - `CLI-forwarded Bash must ask before the queued ${phase} frame reaches the adapter`, + forwardedFirst.type === "decision" ? forwardedFirst.result?.behavior : undefined, + "allow", + `CLI-forwarded Bash must not ask before the queued ${phase} frame reaches the adapter`, ); - if (forwardedFirst.type !== "request") return; - assert.equal(forwardedFirst.event.runtimeRequest.kind, "command"); - yield* harness.runtime.respondToRuntimeRequest({ - requestId: forwardedFirst.event.runtimeRequest.id, - decision: "decline", - }); - assert.equal((yield* Fiber.join(forwardedDecision))?.behavior, "deny"); yield* harness.offerAndWait(frame); } const fallbackDecision = yield* Effect.promise(() => @@ -5340,15 +5316,14 @@ describe("ClaudeAdapterV2 background wake turns", () => { Queue.take(harness.runtimeRequestReceipts).pipe( Effect.map((event) => ({ type: "request", event }) as const), ), - Fiber.join(fallbackDecision).pipe(Effect.map(() => ({ type: "decision" }) as const)), + Fiber.join(fallbackDecision).pipe( + Effect.map((result) => ({ type: "decision", result }) as const), + ), + ); + assert.equal( + fallbackFirst.type === "decision" ? fallbackFirst.result?.behavior : undefined, + "allow", ); - assert.equal(fallbackFirst.type, "request"); - if (fallbackFirst.type !== "request") return; - yield* harness.runtime.respondToRuntimeRequest({ - requestId: fallbackFirst.event.runtimeRequest.id, - decision: "decline", - }); - assert.equal((yield* Fiber.join(fallbackDecision))?.behavior, "deny"); yield* finish; const unrestrictedOptions = harness.getOpenedOptions(); yield* start("/unrestricted"); @@ -5400,14 +5375,10 @@ describe("ClaudeAdapterV2 background wake turns", () => { Effect.map((result) => ({ type: "decision", result }) as const), ), ); - assert.equal(restoredFirst.type, "request"); - if (restoredFirst.type !== "request") return; - assert.equal(restoredFirst.event.runtimeRequest.kind, "command"); - yield* harness.runtime.respondToRuntimeRequest({ - requestId: restoredFirst.event.runtimeRequest.id, - decision: "decline", - }); - assert.equal((yield* Fiber.join(restoredDecision))?.behavior, "deny"); + assert.equal( + restoredFirst.type === "decision" ? restoredFirst.result?.behavior : undefined, + "allow", + ); yield* finish; assert.equal(harness.terminalEvents().at(-1)?.status, "completed"); } @@ -5756,7 +5727,7 @@ describe("ClaudeAdapterV2 background wake turns", () => { behavior: "allow", }, { - runtimeMode: "full-access", + runtimeMode: "auto", toolName: "Bash", toolInput: { command: "echo after > target.txt" }, kind: "command", @@ -5794,33 +5765,35 @@ describe("ClaudeAdapterV2 background wake turns", () => { ), ); - it.effect("denies Plan writes without asking when approvals are never allowed", () => - Effect.gen(function* () { - const turn = yield* openPlanTurn("full-access", "never"); - const permission = yield* requestWrite(turn, "Bash", { - command: "echo after > target.txt", - }); - assert.equal(permission.first.type, "decision", "Never raised an approval request"); - if (permission.first.type !== "decision") return; - assert.equal(permission.first.result?.behavior, "deny"); - }).pipe( - Effect.scoped, - Effect.provide( - Layer.mergeAll( - IdAllocator.layer, - McpProviderSessions.layer, - NodeServices.layer, - NodeCrypto.layer, + it.effect.each(["never", undefined] as const)( + "denies full-access Plan writes without asking (approvalPolicy %s)", + (approvalPolicy) => + Effect.gen(function* () { + const turn = yield* openPlanTurn("full-access", approvalPolicy); + const permission = yield* requestWrite(turn, "Bash", { + command: "echo after > target.txt", + }); + assert.equal(permission.first.type, "decision", "Never raised an approval request"); + if (permission.first.type !== "decision") return; + assert.equal(permission.first.result?.behavior, "deny"); + }).pipe( + Effect.scoped, + Effect.provide( + Layer.mergeAll( + IdAllocator.layer, + McpProviderSessions.layer, + NodeServices.layer, + NodeCrypto.layer, + ), ), ), - ), ); it.effect( "returns approval feedback to the requesting tool without sending a parent prompt", () => Effect.gen(function* () { - const turn = yield* openPlanTurn("full-access"); + const turn = yield* openPlanTurn("auto"); const parentPermission = yield* requestWrite( turn, "Bash", @@ -6631,12 +6604,7 @@ describe("ClaudeAdapterV2 background wake turns", () => { }, ), ).pipe(Effect.forkScoped); - const request = yield* Queue.take(harness.runtimeRequestReceipts); - yield* harness.runtime.respondToRuntimeRequest({ - requestId: request.runtimeRequest.id, - decision: "accept", - }); - yield* Fiber.join(permission); + assert.equal((yield* Fiber.join(permission))?.behavior, "allow"); yield* harness.offerAndWait( claudeSdkFrame({ type: "assistant", @@ -7847,18 +7815,21 @@ describe("ClaudeAdapterV2 background wake turns", () => { const startElicitationTurn = Effect.fnUntraced(function* ( options?: Parameters[0], + runtimeMode: RuntimeMode = "auto-accept-edits", ) { const harness = yield* makeWakeHarnessWithOptions(options); - yield* harness.runtime.startTurn( - makeClaudeTestTurnInput({ - threadId: harness.threadId, - providerThread: harness.providerThread, - now: yield* DateTime.now, - attemptId: RunAttemptId.make("attempt-claude-elicitation"), - text: "Deploy web.", - attachments: [], - }), - ); + const turnInput = makeClaudeTestTurnInput({ + threadId: harness.threadId, + providerThread: harness.providerThread, + now: yield* DateTime.now, + attemptId: RunAttemptId.make("attempt-claude-elicitation"), + text: "Deploy web.", + attachments: [], + }); + yield* harness.runtime.startTurn({ + ...turnInput, + runtimePolicy: { ...turnInput.runtimePolicy, runtimeMode }, + }); const onElicitation = harness.getOpenedOptions()?.onElicitation; if (onElicitation === undefined) throw new Error("The Claude query has no onElicitation."); const runtimeRequests = () => @@ -7878,6 +7849,17 @@ describe("ClaudeAdapterV2 background wake turns", () => { return { harness, elicit, awaitCard, runtimeRequests }; }); + it.effect("accepts in full access without a card", () => + Effect.gen(function* () { + const { elicit, runtimeRequests } = yield* startElicitationTurn(undefined, "full-access"); + assert.deepEqual(yield* Fiber.join(yield* elicit(approvalOnly)), { + action: "accept", + content: {}, + }); + assert.equal(runtimeRequests().length, 0); + }).pipe(Effect.scoped, Effect.provide(testLayer)), + ); + it.effect("shows an approval-only form and accepts only after Approve", () => Effect.gen(function* () { const { harness, elicit, awaitCard } = yield* startElicitationTurn(); diff --git a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts index 3ab93931ea340..0c64ed7ad5cfa 100644 --- a/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts +++ b/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts @@ -12698,9 +12698,10 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* ( } satisfies PermissionResult; } + const fullAccess = context.input.runtimePolicy.runtimeMode === "full-access"; if ( context.input.runtimePolicy.interactionMode === "plan" && - context.input.runtimePolicy.approvalPolicy === "never" + (context.input.runtimePolicy.approvalPolicy === "never" || fullAccess) ) { return { behavior: "deny", @@ -12740,6 +12741,15 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* ( } satisfies PermissionResult; } + // Full access answers every ask the CLI still forwards, ask rules and checks included. + if (fullAccess) { + return { + behavior: "allow", + updatedInput: toolInput, + toolUseID: callbackOptions.toolUseID, + } satisfies PermissionResult; + } + const requestKind = providerRequestKindFromClaudeTool(toolName); // The user approves the command itself; Claude's title and description only summarize it. const command = inputRecordValue(nativeToolInput, "command"); @@ -12844,7 +12854,10 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* ( return { action: "cancel" } satisfies ElicitationResult; } const grantKey = `${request.serverName}\u0000${request.message}`; - if ((yield* Ref.get(mcpElicitationSessionGrants)).has(grantKey)) { + if ( + context.input.runtimePolicy.runtimeMode === "full-access" || + (yield* Ref.get(mcpElicitationSessionGrants)).has(grantKey) + ) { return acceptance; } // The CLI waits on this answer, so a turn held for its prompt echo diff --git a/apps/server/src/orchestration-v2/Adapters/KiroAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/KiroAdapterV2.test.ts index fb2f20bddd2eb..4380da8375d15 100644 --- a/apps/server/src/orchestration-v2/Adapters/KiroAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/KiroAdapterV2.test.ts @@ -1443,7 +1443,7 @@ describe("Kiro permission policy", () => { options, }); - it("never lets a policy approval persist Kiro's workspace-wide allow_always", () => { + it("saves Kiro's allow_always only when Full access has no one-time choice", () => { const fullAccess = policy({ runtimeMode: "full-access" }); assert.equal( kiroPermissionDisposition( @@ -1455,13 +1455,17 @@ describe("Kiro permission policy", () => { ), "allow", ); - // With no one-time choice, approving would save a rule beyond the thread, - // so the request goes to the user, whose card can still allow it. const alwaysOnly = writeRequest([ { optionId: "always-accept", name: "Always allow", kind: "allow_always" }, { optionId: "reject", name: "Deny", kind: "reject_once" }, ]); - assert.equal(kiroPermissionDisposition(fullAccess, alwaysOnly), "ask"); + // Full access never asks, even when approving saves a rule beyond the thread. + assert.equal(kiroPermissionDisposition(fullAccess, alwaysOnly), "allow"); + // Other modes send that request to the user, whose card can still allow it. + assert.equal( + kiroPermissionDisposition(policy({ runtimeMode: "auto-accept-edits" }), alwaysOnly), + "ask", + ); assert.deepEqual( kiroApprovalOptions(alwaysOnly).map((option) => option.decision), ["acceptForSession", "decline", "cancel"], diff --git a/apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.ts index 88563aeb43492..9284552a28b1f 100644 --- a/apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.ts @@ -4320,11 +4320,14 @@ it.layer(McpProviderSessions.layer)("OpenCode2 adapter", (it) => { [ ...backgroundLaunch(CHILD), event("permission.asked", permission), + // Full access answers the permission at once; the form is a question and waits. + out("permission.reply", { sessionID: CHILD, requestID: permission.id, decision: "once" }), + reply("permission.reply", null), event("form.created", { form }), ...reconnected({ [SESSION]: { type: "running" }, [CHILD]: { type: "running" } }), ...openRequests([]), out("permission.list", { sessionID: CHILD }), - replyData("permission.list", [permission]), + replyData("permission.list", []), out("session.form.list", { sessionID: CHILD }), replyData("session.form.list", [form]), out("session.interrupt", { sessionID: SESSION }), @@ -4333,8 +4336,6 @@ it.layer(McpProviderSessions.layer)("OpenCode2 adapter", (it) => { sessionID: SESSION, model: { providerID: "opencode", id: "recovered" }, }), - out("permission.reply", { sessionID: CHILD, requestID: permission.id, decision: "once" }), - reply("permission.reply", null), out("session.form.reply", { sessionID: CHILD, formID: form.id, answer: { q0: "Red" } }), reply("session.form.reply", null), ], @@ -4375,12 +4376,8 @@ it.layer(McpProviderSessions.layer)("OpenCode2 adapter", (it) => { yield* Deferred.succeed(resume, undefined); yield* Deferred.await(recovered); assert.isTrue(yield* runtime.hasPendingBackgroundWorkForThread!(thread)); - assert.equal(requests.get(permission.id)?.status, "pending"); + assert.isUndefined(requests.get(permission.id)); assert.equal(requests.get(form.id)?.status, "pending"); - yield* runtime.respondToRuntimeRequest({ - requestId: requests.get(permission.id)!.id, - decision: "accept", - }); yield* runtime.respondToRuntimeRequest({ requestId: requests.get(form.id)!.id, answers: { q0: "Red" }, diff --git a/packages/provider-kiro/src/server/acpSupport.ts b/packages/provider-kiro/src/server/acpSupport.ts index 43d8c06b77a98..ab6f3e9a92a4e 100644 --- a/packages/provider-kiro/src/server/acpSupport.ts +++ b/packages/provider-kiro/src/server/acpSupport.ts @@ -109,10 +109,10 @@ export function kiroApprovalOptions( } /** - * T3's answer to a Kiro permission request. A policy approval may only use - * Kiro's `allow_once`: its `allow_always` saves a consent rule for the whole - * workspace or wider, which would outlive the thread. When Kiro offers no - * one-time choice, the request goes to the user instead of persisting a grant. + * T3's answer to a Kiro permission request. Outside full access a policy + * approval may only use Kiro's `allow_once`, because `allow_always` saves a + * workspace-wide consent rule; without a one-time choice the user decides. + * Full access never asks, so it takes `allow_always` when that is all Kiro offers. */ export function kiroPermissionDisposition( policy: AcpRuntimePolicy, @@ -122,7 +122,9 @@ export function kiroPermissionDisposition( const offersOnce = request.options.some( (option) => option.kind === "allow_once" && option.optionId.trim().length > 0, ); - return disposition === "allow" && !offersOnce ? "ask" : disposition; + return disposition === "allow" && !offersOnce && policy.runtimeMode !== "full-access" + ? "ask" + : disposition; } export interface KiroAcpRuntimeInput extends Omit< diff --git a/packages/provider-muse/src/server/adapter.test.ts b/packages/provider-muse/src/server/adapter.test.ts index f23f7ca84d7ea..220a3fb3d0ecb 100644 --- a/packages/provider-muse/src/server/adapter.test.ts +++ b/packages/provider-muse/src/server/adapter.test.ts @@ -62,6 +62,11 @@ const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ interactionMode: "default", cwd: null, }); +// Full access answers every approval itself, so tests of the card use a mode that asks. +const askingPolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ + ...runtimePolicy, + runtimeMode: "approval-required", +}); const modelSelection = (instanceId = INSTANCE_ID) => ({ instanceId, model: MODEL, @@ -774,7 +779,14 @@ describe("MuseAdapterV2", () => { it.effect("settles partial messages and pending approvals before a provider failure", () => Effect.gen(function* () { const fake = yield* makeFakeMuse(); - const harness = yield* makeHarness(fake); + const harness = yield* makeHarness( + fake, + INSTANCE_ID, + undefined, + undefined, + undefined, + askingPolicy, + ); const { nativeId } = yield* startConversation(harness, fake); yield* fake.emit("item/started", { turnId: nativeId, @@ -930,7 +942,14 @@ describe("MuseAdapterV2", () => { connectionClosed = true; }); yield* Effect.gen(function* () { - const harness = yield* makeHarness(fake); + const harness = yield* makeHarness( + fake, + INSTANCE_ID, + undefined, + undefined, + undefined, + askingPolicy, + ); const { nativeId } = yield* startConversation(harness, fake); yield* fake.emit("approval/requested", approval(nativeId)); yield* harness.takeEvent( @@ -985,7 +1004,14 @@ describe("MuseAdapterV2", () => { it.effect("settles an active turn once when both the connection and host exit unexpectedly", () => Effect.gen(function* () { const fake = yield* makeFakeMuse(); - const harness = yield* makeHarness(fake); + const harness = yield* makeHarness( + fake, + INSTANCE_ID, + undefined, + undefined, + undefined, + askingPolicy, + ); const first = yield* startConversation(harness, fake); yield* fake.emit("item/started", { turnId: first.nativeId, @@ -1076,7 +1102,14 @@ describe("MuseAdapterV2", () => { it.effect("uses the latest native approval requirement and waits for its resolution event", () => Effect.gen(function* () { const fake = yield* makeFakeMuse(); - const harness = yield* makeHarness(fake); + const harness = yield* makeHarness( + fake, + INSTANCE_ID, + undefined, + undefined, + undefined, + askingPolicy, + ); const { nativeId } = yield* startConversation(harness, fake); yield* fake.emit("approval/requested", approval(nativeId)); const first = yield* harness.takeEvent( @@ -1124,7 +1157,14 @@ describe("MuseAdapterV2", () => { it.effect("keeps the user's decision when Muse settles before acknowledging it", () => Effect.gen(function* () { const fake = yield* makeFakeMuse(); - const harness = yield* makeHarness(fake); + const harness = yield* makeHarness( + fake, + INSTANCE_ID, + undefined, + undefined, + undefined, + askingPolicy, + ); const { nativeId } = yield* startConversation(harness, fake); yield* fake.emit("approval/requested", approval(nativeId)); const pending = yield* harness.takeEvent( @@ -1162,7 +1202,7 @@ describe("MuseAdapterV2", () => { undefined, undefined, undefined, - runtimePolicy, + askingPolicy, { continuationRequests: { offer: (request) => Effect.sync(() => offers.push(request)) } }, ); yield* fake.emit("turn/started", { turnId: "report-1" }); @@ -1221,14 +1261,11 @@ describe("MuseAdapterV2", () => { approvalId: "parent-approval", currentRequirementId: { approvalId: "parent-approval", sourceIndex: 0 }, }; + // Full access answers the root approval the same way, without a card. yield* fake.emit("approval/requested", parent); - const shown = yield* harness.takeEvent("runtime_request.updated"); - assert.strictEqual(shown.runtimeRequest.status, "pending"); - yield* harness.takeEvent("provider_session.updated"); - yield* fake.emit("approval/resolved", parent); - // The child remains unacknowledged when the visible request stops blocking the turn. - const session = yield* harness.takeEvent("provider_session.updated"); - assert.strictEqual(session.providerSession.status, "running"); + const parentDecision = yield* fake.takeCall("approval/decide"); + assert.strictEqual(parentDecision.params.choiceId, "once"); + assert.deepStrictEqual(harness.allEvents.slice(before), []); } yield* fake.emit("approval/resolved", child); const resolved = yield* harness.takeEvent("runtime_request.updated"); diff --git a/packages/provider-muse/src/server/adapter.ts b/packages/provider-muse/src/server/adapter.ts index 0b5835e0bad12..bf86971291130 100644 --- a/packages/provider-muse/src/server/adapter.ts +++ b/packages/provider-muse/src/server/adapter.ts @@ -1309,8 +1309,10 @@ export const makeMuseAdapterV2 = Effect.fn("makeMuseAdapterV2")(function* ( required: true, })), }; - // Muse does not propagate allowAll to workflow children; T3 answers for them. - const autoApprove = child && input.runtimePolicy.runtimeMode === "full-access"; + // Muse does not propagate allowAll to workflow children, and can still ask under it. + const autoApprove = + input.runtimePolicy.runtimeMode === "full-access" && + (child || native.type === "approval"); const entry: PendingRequest = { native, request: runtimeRequest, diff --git a/packages/provider-opencode/src/server/adapter.test.ts b/packages/provider-opencode/src/server/adapter.test.ts index 3cd83ac152f8c..c21c9cf5cba2f 100644 --- a/packages/provider-opencode/src/server/adapter.test.ts +++ b/packages/provider-opencode/src/server/adapter.test.ts @@ -2161,6 +2161,15 @@ describe("OpenCodeAdapterV2", () => { ); } assert.equal(replies.length, 2); + // Full access answers the permission itself; only the question reaches the user. + assert.isFalse( + events.some( + (event) => + event.type === "runtime_request.updated" && + event.runtimeRequest.kind !== "user_input", + ), + ); + assert.deepInclude(replies, { requestID: "wake-permission", reply: "once" }); yield* push(status("idle")); yield* awaitTerminal; assert.equal(promptIds.length, 1); diff --git a/packages/provider-opencode/src/server/adapter.ts b/packages/provider-opencode/src/server/adapter.ts index d0e1d27cc2a7b..2f4b68a725b7f 100644 --- a/packages/provider-opencode/src/server/adapter.ts +++ b/packages/provider-opencode/src/server/adapter.ts @@ -2052,6 +2052,21 @@ export const makeOpenCodeAdapterV2 = Effect.fn("makeOpenCodeAdapterV2")(function ) { if (pendingRequestsByNativeId.has(nativeRequestId)) return; const { state, turn, subagent } = owner; + // Full access installs allow-all rules, but OpenCode can still ask before they apply. + if (request.type === "permission" && turn.runtimePolicy.runtimeMode === "full-access") { + const replied = yield* sdkCall( + "permission.reply", + { requestID: nativeRequestId, reply: "once" }, + (signal) => + client.permission.reply({ requestID: nativeRequestId, reply: "once" }, { signal }), + ).pipe( + Effect.timeout("10 seconds"), + Effect.as(true), + // A failed reply falls back to the card so the request cannot hang unseen. + Effect.orElseSucceed(() => false), + ); + if (replied) return; + } const now = yield* DateTime.now; const requestId = yield* idAllocator.allocate.runtimeRequest({ driver: OPENCODE_PROVIDER, diff --git a/packages/provider-opencode/src/server/v2/adapter.ts b/packages/provider-opencode/src/server/v2/adapter.ts index 9e14f8c4ef36b..fdb56638f1a81 100644 --- a/packages/provider-opencode/src/server/v2/adapter.ts +++ b/packages/provider-opencode/src/server/v2/adapter.ts @@ -2602,6 +2602,20 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr if (target === undefined) return; const { state, turn } = target; if ([...pending.values()].some((entry) => entry.native.id === native.id)) return; + // Full access installs allow-all rules, but OpenCode can still ask before they apply. + if (native.type === "permission" && rootOf(state).policy.runtimeMode === "full-access") { + const replied = yield* deliver( + client.permission + .reply({ + sessionID: Session.ID.make(sessionId), + requestID: Permission.ID.make(native.id), + decision: "once", + }) + .pipe(Effect.catchTags(permissionGone)), + ); + // A failed reply falls back to the card so the request cannot hang unseen. + if (replied) return; + } const now = yield* DateTime.now; const requestId = yield* idAllocator.allocate.runtimeRequest({ driver, diff --git a/packages/provider-pi/src/server/adapter.test.ts b/packages/provider-pi/src/server/adapter.test.ts index 50708ddc767b5..6a000744cd7f6 100644 --- a/packages/provider-pi/src/server/adapter.test.ts +++ b/packages/provider-pi/src/server/adapter.test.ts @@ -147,8 +147,9 @@ function uncapturedTurns( ]; } +// Full access confirms dialogs itself, so tests of the dialog card use a mode that asks. const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ - runtimeMode: "full-access", + runtimeMode: "approval-required", interactionMode: "default", cwd: null, }); @@ -569,13 +570,14 @@ const openRuntime = Effect.fnUntraced(function* ( forkFake?: FakePi, continuationRequests?: PiAdapterV2Options["continuationRequests"], initialNativeThreadId?: string, + policy = runtimePolicy, ) { const adapter = yield* makeAdapter(fake, "", forkFake, continuationRequests); const runtime = yield* adapter.openSession({ threadId, providerSessionId, modelSelection: modelSelection(model), - runtimePolicy, + runtimePolicy: policy, ...(initialNativeThreadId === undefined ? {} : { initialNativeThreadId }), }); const emitted = yield* Queue.unbounded(); @@ -2175,7 +2177,7 @@ describe("PiAdapterV2", () => { assert.isTrue(extensions.some((path) => path?.endsWith("pi-t3-mcp-extension.ts"))); assert.equal(spawn.env.T3_MCP_URL, "http://127.0.0.1:43123/mcp"); assert.equal(spawn.env.T3_MCP_BEARER_TOKEN, "secret-pi-token"); - assert.equal(spawn.env.T3_PI_RUNTIME_MODE, "full-access"); + assert.equal(spawn.env.T3_PI_RUNTIME_MODE, runtimePolicy.runtimeMode); assert.equal(spawn.env.T3CODE_THREAD_ID, THREAD_ID); }).pipe(Effect.scoped, Effect.provide(layerTest)), ); @@ -4916,6 +4918,56 @@ describe("PiAdapterV2", () => { }).pipe(Effect.scoped, Effect.provide(layerTest)), ); + it.effect("confirms extension dialogs in full access and still asks its questions", () => + Effect.gen(function* () { + const fake = yield* makeFakePi; + const fullAccess = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({ + ...runtimePolicy, + runtimeMode: "full-access", + }); + const { runtime, takeEvent } = yield* openRuntime( + fake, + "default", + THREAD_ID, + SESSION_ID, + undefined, + undefined, + undefined, + fullAccess, + ); + yield* runtime.ensureThread({ + threadId: THREAD_ID, + modelSelection: modelSelection("default"), + runtimePolicy: fullAccess, + }); + yield* fake.emit({ + type: "extension_ui_request", + id: "ui-trust", + method: "confirm", + title: "Run project extensions?", + message: "This project has .pi/extensions.", + }); + const confirmed = yield* fake.takeRequest("extension_ui_response"); + assert.equal(confirmed["id"], "ui-trust"); + assert.equal(confirmed["confirmed"], true); + yield* fake.emit({ + type: "extension_ui_request", + id: "ui-pick", + method: "select", + title: "Pick a target", + options: ["staging", "production"], + }); + const asked = yield* takeEvent( + (event) => + event.type === "runtime_request.updated" && event.runtimeRequest.status === "pending", + ); + assert.equal( + asked.type === "runtime_request.updated" ? asked.runtimeRequest.kind : undefined, + "user_input", + ); + }).pipe(Effect.scoped, Effect.provide(layerTest)), + ); + it.effect("cancels startup dialogs when Pi exits before a turn exists", () => Effect.gen(function* () { const fake = yield* makeFakePi; diff --git a/packages/provider-pi/src/server/adapter.ts b/packages/provider-pi/src/server/adapter.ts index eae7f3eb6c2fa..95a5925ffcac3 100644 --- a/packages/provider-pi/src/server/adapter.ts +++ b/packages/provider-pi/src/server/adapter.ts @@ -1843,6 +1843,18 @@ export const makePiAdapterV2 = Effect.fn("makePiAdapterV2")(function* ( } const state = threadState; const turn = state?.activeTurn ?? null; + // A confirm is a yes/no approval; select, input and editor ask for an answer and still show. + if ( + method === "confirm" && + (turn?.turnInput.runtimePolicy ?? input.runtimePolicy).runtimeMode === "full-access" + ) { + yield* connection.send({ + type: "extension_ui_response", + id: nativeRequestId, + confirmed: true, + }); + return; + } const createdAt = yield* DateTime.now; const timeout = recordNumber(event, "timeout"); // Pi treats zero as no timeout and negative durations as immediate expiry.