The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 13:15 UTC
fix(acp): ID-only command approvals keep the tracked command and grant the terminal (#26647)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 28, 2026 at 17:17 UTC
b2871029c9fbd6fab1cb90d245ca9f3e4b661fc7
5 files changed
+233
-1
apps/server/scripts/acp-mock-agent.ts
+16
@@ -38,6 +38,7 @@ const omitInitializeModelState = process.env.T3_ACP_OMIT_INITIALIZE_MODEL_STATE
38
const completeFirstPromptOnCancel = process.env.T3_ACP_COMPLETE_FIRST_PROMPT_ON_CANCEL === "1";
39
const floodStderr = process.env.T3_ACP_FLOOD_STDERR === "1";
40
const hangPromptForever = process.env.T3_ACP_HANG_PROMPT_FOREVER === "1";
41
+const emitTrackedToolCallKindThenHang = process.env.T3_ACP_EMIT_TRACKED_TOOL_CALL_KIND_THEN_HANG;
42
const clientFsProbePath = process.env.T3_ACP_CLIENT_FS_PROBE_PATH;
43
const clientFsProbeLogPath = process.env.T3_ACP_CLIENT_FS_PROBE_LOG_PATH;
44
const encodeJson = Schema.encodeSync(Schema.fromJsonString(Schema.Unknown));
@@ -1265,6 +1266,21 @@ const program = Effect.gen(function* () {
1266
return yield* AcpError.AcpRequestError.internalError("Mock prompt failure");
1267
}
1268
1269
+ if (emitTrackedToolCallKindThenHang !== undefined) {
1270
+ yield* agent.client.sessionUpdate({
1271
+ sessionId: requestedSessionId,
1272
+ update: {
1273
+ sessionUpdate: "tool_call_update",
1274
+ toolCallId: "tracked-tool-call",
1275
+ title: "git status",
1276
+ kind: emitTrackedToolCallKindThenHang as AcpSchema.ToolKind,
1277
+ status: "pending",
1278
+ rawInput: { command: "git status" },
1279
+ },
1280
+ });
1281
+ return yield* Effect.never;
1282
+ }
1283
+
1284
if (hangPromptForever || (emitEmptySuccessfulBashThenHang && promptCount === 2)) {
1285
return yield* Effect.never;
1286
}
apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts
+149
@@ -3115,6 +3115,155 @@ describe("AcpAdapterV2", () => {
3115
}).pipe(Effect.provide(layerTest), Effect.scoped),
3116
);
3117
3118
+ it.effect.each([
3119
+ {
3120
+ label: "grants an ID-only execute approval its tracked command",
3121
+ kind: "execute",
3122
+ granted: true,
3123
+ },
3124
+ {
3125
+ label: "does not grant execution to an ID-only approval of another tool",
3126
+ kind: "other",
3127
+ granted: false,
3128
+ },
3129
+ ] as const)("$label", ({ kind, granted }) =>
3130
+ Effect.gen(function* () {
3131
+ const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
3132
+ const path = yield* Path.Path;
3133
+ const selfInvocation = yield* resolveSelfInvocation();
3134
+ const mockAgentPath = yield* path.fromFileUrl(
3135
+ new URL("../../../scripts/acp-mock-agent.ts", import.meta.url),
3136
+ );
3137
+ type RuntimeService = AcpSessionRuntime.AcpSessionRuntime["Service"];
3138
+ let requestPermission: Parameters<RuntimeService["handleRequestPermission"]>[0] | undefined;
3139
+ let createTerminal: Parameters<RuntimeService["handleCreateTerminal"]>[0] | undefined;
3140
+ let runtimeInput: AcpAdapterV2RuntimeInput | undefined;
3141
+ const makeRuntime = makeMockRuntime({
3142
+ childProcessSpawner,
3143
+ mockAgentPath,
3144
+ environment: { T3_ACP_EMIT_TRACKED_TOOL_CALL_KIND_THEN_HANG: kind },
3145
+ wrapRuntime: (runtime) => ({
3146
+ ...runtime,
3147
+ handleRequestPermission: (handler) =>
3148
+ Effect.sync(() => {
3149
+ requestPermission = handler;
3150
+ }).pipe(Effect.andThen(runtime.handleRequestPermission(handler))),
3151
+ handleCreateTerminal: (handler) =>
3152
+ Effect.sync(() => {
3153
+ createTerminal = handler;
3154
+ }).pipe(Effect.andThen(runtime.handleCreateTerminal(handler))),
3155
+ }),
3156
+ });
3157
+ const instanceId = ProviderInstanceId.make("acp-test-id-only-permission");
3158
+ const adapter = yield* makeAcpAdapterV2({
3159
+ instanceId,
3160
+ flavor: {
3161
+ driver: ACP_TEST_DRIVER,
3162
+ capabilities: AcpProviderCapabilitiesV2,
3163
+ interruptPromptOnCancel: true,
3164
+ makeRuntime: (input) =>
3165
+ Effect.sync(() => {
3166
+ runtimeInput = input;
3167
+ }).pipe(Effect.andThen(makeRuntime(input))),
3168
+ },
3169
+ selfInvocation,
3170
+ clientTerminals: {},
3171
+ });
3172
+ const threadId = ThreadId.make("thread-acp-id-only-permission");
3173
+ const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
3174
+ runtimeMode: "approval-required",
3175
+ interactionMode: "default",
3176
+ cwd: process.cwd(),
3177
+ });
3178
+ const modelSelection = { instanceId, model: "default" } as const;
3179
+ const runtime = yield* adapter.openSession({
3180
+ threadId,
3181
+ providerSessionId: ProviderSessionId.make("provider-session-acp-id-only-permission"),
3182
+ modelSelection,
3183
+ runtimePolicy,
3184
+ });
3185
+ const providerThread = yield* runtime.ensureThread({
3186
+ threadId,
3187
+ modelSelection,
3188
+ runtimePolicy,
3189
+ });
3190
+ const turnFiber = yield* runtime
3191
+ .startTurn(
3192
+ makeTurnInput({
3193
+ threadId,
3194
+ providerThread,
3195
+ instanceId,
3196
+ runtimePolicy,
3197
+ now: yield* DateTime.now,
3198
+ }),
3199
+ )
3200
+ .pipe(Effect.forkScoped);
3201
+ if (requestPermission === undefined || createTerminal === undefined) {
3202
+ return yield* Effect.die("ACP runtime must register permission and terminal handlers");
3203
+ }
3204
+ yield* runtime.events.pipe(
3205
+ Stream.filter(
3206
+ (event) =>
3207
+ event.type === "turn_item.updated" &&
3208
+ event.turnItem.nativeItemRef?.nativeId === "tracked-tool-call",
3209
+ ),
3210
+ Stream.runHead,
3211
+ );
3212
+
3213
+ const permissionFiber = yield* requestPermission(
3214
+ {
3215
+ sessionId: "mock-session-1",
3216
+ toolCall: { toolCallId: "tracked-tool-call" },
3217
+ options: [{ optionId: "allow-once", name: "Allow once", kind: "allow_once" }],
3218
+ },
3219
+ { requestId: "id-only-permission-request", method: "session/request_permission" },
3220
+ ).pipe(Effect.forkScoped);
3221
+ const approvalEvent = Option.getOrThrow(
3222
+ yield* runtime.events.pipe(
3223
+ Stream.filter(
3224
+ (event) =>
3225
+ event.type === "turn_item.updated" && event.turnItem.type === "approval_request",
3226
+ ),
3227
+ Stream.runHead,
3228
+ ),
3229
+ );
3230
+ if (
3231
+ approvalEvent.type !== "turn_item.updated" ||
3232
+ approvalEvent.turnItem.type !== "approval_request" ||
3233
+ approvalEvent.turnItem.providerTurnId === null
3234
+ ) {
3235
+ return yield* Effect.die("Expected an ACP approval request");
3236
+ }
3237
+ const approval = approvalEvent.turnItem;
3238
+ const providerTurnId = approvalEvent.turnItem.providerTurnId;
3239
+ const responseFiber = yield* runtime
3240
+ .respondToRuntimeRequest({ requestId: approval.requestId, decision: "accept" })
3241
+ .pipe(Effect.forkScoped);
3242
+ assert.equal((yield* Fiber.join(permissionFiber)).outcome.outcome, "selected");
3243
+ if (runtimeInput?.onOutgoingResponse === undefined) {
3244
+ return yield* Effect.die("ACP runtime must expose native response acknowledgements");
3245
+ }
3246
+ yield* runtimeInput.onOutgoingResponse("id-only-permission-request");
3247
+ yield* Fiber.join(responseFiber);
3248
+
3249
+ const terminalExit = yield* createTerminal(
3250
+ {
3251
+ sessionId: "mock-session-1",
3252
+ command: process.execPath,
3253
+ args: ["-e", ""],
3254
+ },
3255
+ { requestId: "id-only-permission-terminal", method: "terminal/create" },
3256
+ ).pipe(Effect.exit);
3257
+ assert.deepEqual(
3258
+ { prompt: approval.prompt, terminalCreated: Exit.isSuccess(terminalExit) },
3259
+ { prompt: "git status", terminalCreated: granted },
3260
+ );
3261
+
3262
+ yield* runtime.interruptTurn({ providerThread, providerTurnId });
3263
+ yield* Fiber.join(turnFiber);
3264
+ }).pipe(Effect.provide(layerTest), Effect.scoped),
3265
+ );
3266
+
3267
it.effect("replaces the ACP session and clears conversation state on rollback", () =>
3268
Effect.gen(function* () {
3269
const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
packages/provider-acp/src/server/adapter.ts
+10
-1
@@ -76,6 +76,7 @@ import {
76
parsePermissionRequest,
77
parseSessionUpdateEvent,
78
toolCallVisibleOutputChanged,
79
+ withTrackedPermissionToolCall,
80
type AcpPlanUpdate,
81
type AcpAgentTerminalState,
82
type AcpSessionModeState,
@@ -5974,8 +5975,16 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
5975
projectAcpRuntimeSessionUpdate(handlerGeneration, rawNotification),
5976
);
5977
}
5977
- yield* targetRuntime.handleRequestPermission((params, requestContext) =>
5978
+ yield* targetRuntime.handleRequestPermission((nativeParams, requestContext) =>
5979
Effect.gen(function* () {
5980
+ const trackedTurn = yield* Ref.get(activeTurn);
5981
+ const params =
5982
+ trackedTurn !== null && nativeParams.sessionId === (yield* Ref.get(activeSessionId))
5983
+ ? withTrackedPermissionToolCall(
5984
+ nativeParams,
5985
+ trackedTurn.tools.get(nativeParams.toolCall.toolCallId),
5986
+ )
5987
+ : nativeParams;
5988
const transportRequestId = requestContext.requestId;
5989
const permissionQuestion = flavor.extractPermissionQuestion?.(params);
5990
if (permissionQuestion !== undefined) {
packages/provider-acp/src/server/runtimeModel.test.ts
+35
@@ -17,6 +17,7 @@ import {
17
sessionUpdateIsReplay,
18
syntheticLoadSessionResponseFromInitialize,
19
toolCallProgressLength,
20
+ withTrackedPermissionToolCall,
21
type AcpToolCallState,
22
} from "./runtimeModel.ts";
23
@@ -432,6 +433,40 @@ describe("AcpRuntimeModel", () => {
433
});
434
});
435
436
+ it("keeps an explicit permission request kind over the tracked tool call's kind", () => {
437
+ const request = withTrackedPermissionToolCall(
438
+ {
439
+ sessionId: "session-1",
440
+ options: [{ optionId: "allow-once", name: "Allow once", kind: "allow_once" }],
441
+ toolCall: { toolCallId: "tool-1", kind: "read" },
442
+ },
443
+ {
444
+ toolCallId: "tool-1",
445
+ kind: "execute",
446
+ data: { toolCallId: "tool-1", title: "git status", rawInput: { command: "git status" } },
447
+ },
448
+ );
449
+
450
+ expect(parsePermissionRequest(request)).toMatchObject({ kind: "read", detail: "git status" });
451
+ });
452
+
453
+ it("keeps explicitly cleared permission request fields over the tracked tool call", () => {
454
+ const request = withTrackedPermissionToolCall(
455
+ {
456
+ sessionId: "session-1",
457
+ options: [{ optionId: "allow-once", name: "Allow once", kind: "allow_once" }],
458
+ toolCall: { toolCallId: "tool-1", kind: null, title: null, rawInput: null },
459
+ },
460
+ {
461
+ toolCallId: "tool-1",
462
+ kind: "execute",
463
+ data: { toolCallId: "tool-1", title: "git status", rawInput: { command: "git status" } },
464
+ },
465
+ );
466
+
467
+ expect(parsePermissionRequest(request).kind).toBe("unknown");
468
+ });
469
+
470
it("bounds an oversized cumulative tool_call_update content buffer to a tail window", () => {
471
const hugeText = Array.from({ length: 2_000 }, (_, i) => `line ${i}: ${"x".repeat(50)}`).join(
472
"\n",
packages/provider-acp/src/server/runtimeModel.ts
+23
@@ -1179,6 +1179,29 @@ export function embeddedTerminalIdsFromSessionUpdate(
1179
return terminalIds.length === 0 ? undefined : { toolCallId: update.toolCallId, terminalIds };
1180
}
1181
1182
+/** ACP lets a permission request name its tool call by ID only; omitted (not null) fields come from the tracked call. */
1183
+export function withTrackedPermissionToolCall(
1184
+ params: EffectAcpSchema.RequestPermissionRequest,
1185
+ tracked: AcpToolCallState | undefined,
1186
+): EffectAcpSchema.RequestPermissionRequest {
1187
+ if (tracked === undefined) return params;
1188
+ const { title, kind, rawInput } = params.toolCall;
1189
+ return {
1190
+ ...params,
1191
+ toolCall: {
1192
+ ...params.toolCall,
1193
+ ...(title === undefined && typeof tracked.data.title === "string"
1194
+ ? { title: tracked.data.title }
1195
+ : {}),
1196
+ // Unrecognised kinds map to command approvals, so only a tracked execute kind may grant execution.
1197
+ ...(kind === undefined && tracked.kind === "execute" ? { kind: "execute" as const } : {}),
1198
+ ...(rawInput === undefined && tracked.data.rawInput !== undefined
1199
+ ? { rawInput: tracked.data.rawInput }
1200
+ : {}),
1201
+ },
1202
+ };
1203
+}
1204
+
1205
export function parsePermissionRequest(
1206
params: EffectAcpSchema.RequestPermissionRequest,
1207
): AcpPermissionRequest {