Skip to content

Commit 3a1bda0

Browse files
committed
fix(acp): only approved execute requests let the agent open client terminals
1 parent f31ce3e commit 3a1bda0

4 files changed

Lines changed: 45 additions & 20 deletions

File tree

‎apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts‎

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4532,7 +4532,25 @@ describe("AcpAdapterV2", () => {
45324532
kind: "other",
45334533
granted: false,
45344534
},
4535-
] as const)("$label", ({ kind, granted }) =>
4535+
{
4536+
label: "grants an explicit execute approval",
4537+
kind: "execute",
4538+
requestKind: "execute",
4539+
granted: true,
4540+
},
4541+
{
4542+
label: "does not grant execution to an approved mode switch",
4543+
kind: "execute",
4544+
requestKind: "switch_mode",
4545+
granted: false,
4546+
},
4547+
{
4548+
label: "does not grant execution to an approved explicit other tool",
4549+
kind: "other",
4550+
requestKind: "other",
4551+
granted: false,
4552+
},
4553+
] as const)("$label", ({ kind, granted, ...testCase }) =>
45364554
Effect.gen(function* () {
45374555
const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
45384556
const path = yield* Path.Path;
@@ -4619,7 +4637,10 @@ describe("AcpAdapterV2", () => {
46194637
const permissionFiber = yield* requestPermission(
46204638
{
46214639
sessionId: "mock-session-1",
4622-
toolCall: { toolCallId: "tracked-tool-call" },
4640+
toolCall: {
4641+
toolCallId: "tracked-tool-call",
4642+
...("requestKind" in testCase ? { kind: testCase.requestKind } : {}),
4643+
},
46234644
options: [{ optionId: "allow-once", name: "Allow once", kind: "allow_once" }],
46244645
},
46254646
{ requestId: "id-only-permission-request", method: "session/request_permission" },
@@ -4661,8 +4682,12 @@ describe("AcpAdapterV2", () => {
46614682
{ requestId: "id-only-permission-terminal", method: "terminal/create" },
46624683
).pipe(Effect.exit);
46634684
assert.deepEqual(
4664-
{ prompt: approval.prompt, terminalCreated: Exit.isSuccess(terminalExit) },
4665-
{ prompt: "git status", terminalCreated: granted },
4685+
{
4686+
prompt: approval.prompt,
4687+
requestKind: approval.requestKind,
4688+
terminalCreated: Exit.isSuccess(terminalExit),
4689+
},
4690+
{ prompt: "git status", requestKind: "command", terminalCreated: granted },
46664691
);
46674692

46684693
yield* runtime.interruptTurn({ providerThread, providerTurnId });

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6648,12 +6648,9 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
66486648
!offeredOptions.some((option) => option.decision === "acceptForSession")
66496649
? "accept"
66506650
: answered;
6651-
if (
6652-
parsedPermission.kind !== "unknown" &&
6653-
(decision === "accept" || decision === "acceptForSession")
6654-
) {
6651+
if (decision === "accept" || decision === "acceptForSession") {
66556652
clientPolicyGrants.recordApproval({
6656-
kind: providerRequestKind(parsedPermission.kind),
6653+
toolKind: parsedPermission.kind,
66576654
scope: decision === "acceptForSession" ? "session" : "turn",
66586655
turnKey: String(context.providerTurnId),
66596656
});

‎packages/provider-acp/src/server/clientPolicy.test.ts‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -319,28 +319,29 @@ describe("client terminal disposition", () => {
319319
});
320320

321321
describe("makeAcpClientPolicyGrants", () => {
322-
it("grants terminals only from commands, never from an approved read or edit", () => {
322+
it("grants terminals only from execute approvals, never from any other approved kind", () => {
323323
const grants = makeAcpClientPolicyGrants();
324-
grants.recordApproval({ kind: "file-read", scope: "turn", turnKey: "turn-1" });
325-
grants.recordApproval({ kind: "file-change", scope: "session", turnKey: "turn-1" });
324+
for (const toolKind of ["read", "edit", "switch_mode", "other", "unknown", "browse"]) {
325+
grants.recordApproval({ toolKind, scope: "session", turnKey: "turn-1" });
326+
}
326327
assert.isFalse(grants.allowsExecute("turn-1"));
327-
grants.recordApproval({ kind: "command", scope: "turn", turnKey: "turn-1" });
328+
grants.recordApproval({ toolKind: "execute", scope: "turn", turnKey: "turn-1" });
328329
assert.isTrue(grants.allowsExecute("turn-1"));
329330
assert.isFalse(grants.allowsExecute("turn-2"));
330331
assert.isFalse(grants.allowsExecute(null));
331332
});
332333

333334
it("keeps accept-for-session command grants across turns", () => {
334335
const grants = makeAcpClientPolicyGrants();
335-
grants.recordApproval({ kind: "command", scope: "session", turnKey: "turn-1" });
336+
grants.recordApproval({ toolKind: "execute", scope: "session", turnKey: "turn-1" });
336337
assert.isTrue(grants.allowsExecute("turn-9"));
337338
assert.isTrue(grants.allowsExecute(null));
338339
});
339340

340341
it("drops a turn's command grant when a later turn approves one", () => {
341342
const grants = makeAcpClientPolicyGrants();
342-
grants.recordApproval({ kind: "command", scope: "turn", turnKey: "turn-1" });
343-
grants.recordApproval({ kind: "command", scope: "turn", turnKey: "turn-2" });
343+
grants.recordApproval({ toolKind: "execute", scope: "turn", turnKey: "turn-1" });
344+
grants.recordApproval({ toolKind: "execute", scope: "turn", turnKey: "turn-2" });
344345
assert.isFalse(grants.allowsExecute("turn-1"));
345346
assert.isTrue(grants.allowsExecute("turn-2"));
346347
});

‎packages/provider-acp/src/server/clientPolicy.ts‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// @effect-diagnostics nodeBuiltinImport:off
2-
import type { ProviderRequestKind, RuntimeMode } from "@t3tools/contracts";
2+
import type { RuntimeMode } from "@t3tools/contracts";
33
import type * as EffectAcpSchema from "effect-acp/compat";
44
import * as NodeFS from "node:fs";
55
import * as NodePath from "node:path";
@@ -222,7 +222,8 @@ export function acpClientExecuteDisposition(
222222
}
223223

224224
export interface AcpApprovalGrantInput {
225-
readonly kind: ProviderRequestKind;
225+
/** The approved request's ACP tool kind, after ID-only requests take their tracked call's kind. */
226+
readonly toolKind: string;
226227
readonly scope: "session" | "turn";
227228
readonly turnKey: string;
228229
}
@@ -232,13 +233,14 @@ export interface AcpClientPolicyGrants {
232233
readonly allowsExecute: (turnKey: string | null) => boolean;
233234
}
234235

235-
/** ACP cannot link commands to terminals; command approvals grant execution for the turn or accepted session. */
236+
/** ACP cannot link commands to terminals; approved execute requests grant execution for the turn or accepted session. */
236237
export function makeAcpClientPolicyGrants(): AcpClientPolicyGrants {
237238
let sessionExecute = false;
238239
let turnExecute: string | null = null;
239240
return {
240241
recordApproval: (input) => {
241-
if (input.kind !== "command") return;
242+
// Other kinds also show as command cards, but approving them must not open terminals.
243+
if (input.toolKind !== "execute") return;
242244
if (input.scope === "session") {
243245
sessionExecute = true;
244246
} else {

0 commit comments

Comments
 (0)