From b72bdb6ab6854844d0f92ca5093dfbacfe306d30 Mon Sep 17 00:00:00 2001 From: Mohamed Boudra Date: Thu, 19 Nov 2026 07:23:51 +0100 Subject: [PATCH] fix(antigravity): preserve Full access in ACP sessions Keep unattended Antigravity runs working through the shared ACP permission policy. Commit a Full access change only when the session is idle and retire unanswered approvals when a turn ends. --- .../src/server/acp-internal/connection.ts | 137 +++++++++++++++--- packages/plugin/src/server/acp.test.ts | 130 +++++++++++++++++ packages/plugin/src/server/acp.ts | 7 + .../server/provider.test.ts | 5 +- .../antigravity-provider/server/provider.ts | 20 ++- public-docs/plugins/providers.md | 5 + .../supported-providers/antigravity.md | 4 +- .../supported-providers/antigravity.zh-CN.md | 4 +- 8 files changed, 282 insertions(+), 30 deletions(-) diff --git a/packages/plugin/src/server/acp-internal/connection.ts b/packages/plugin/src/server/acp-internal/connection.ts index a47a91c387..6255897fae 100644 --- a/packages/plugin/src/server/acp-internal/connection.ts +++ b/packages/plugin/src/server/acp-internal/connection.ts @@ -207,9 +207,11 @@ async function dispatch(input: ProviderInput, state: AcpConnectionState): Promis case "session.open": await openSession(input, state); return; - case "session.prompt": - await requireSession(state, input.sessionId).runtime.prompt(input); + case "session.prompt": { + const session = requireSession(state, input.sessionId); + await mutateSession(session, () => session.runtime.prompt(input)); return; + } case "session.interrupt": await requireSession(state, input.sessionId).runtime.interrupt(); state.emit({ type: "request.completed", requestId: input.requestId }); @@ -356,6 +358,12 @@ interface StartRuntimeOptions { emit(event: ProviderEvent): void; } +interface PendingPermission { + request: RequestPermissionRequest; + turnId: string | undefined; + resolve(response: RequestPermissionResponse): void; +} + class AcpRuntime { readonly connection: ClientSideConnection; agentCapabilities: AgentCapabilities = {}; @@ -367,10 +375,7 @@ class AcpRuntime { // Running tool rows published by transformers; the turn's terminal closes any left open. private readonly vendorToolCalls = new Map(); private readonly pendingCompactions = new Set(); - private readonly permissions = new Map< - string, - { request: RequestPermissionRequest; resolve(response: RequestPermissionResponse): void } - >(); + private readonly permissions = new Map(); private readonly transformers: readonly AcpTransformer[]; private configOptions: SessionConfigOption[] = []; private modes: NewSessionResponse["modes"] = null; @@ -399,7 +404,7 @@ class AcpRuntime { private stagedTransformerConfig: ProviderConfigState | null = null; private readonly closeConnector: () => Promise; private notificationLane: Promise = Promise.resolve(); - private promptLane: Promise = Promise.resolve(); + private autoAccept = false; private activePrompt: { turnId: string; settled: Promise } | null = null; private lastUsage: ProviderUsage = {}; @@ -553,6 +558,7 @@ class AcpRuntime { const sessionCapabilities = connectionCapabilities.filter( (capability) => capability !== "session.configure" || + this.options.options.acpOptions?.autoAcceptMode !== undefined || this.modes !== null || this.configOptions.length > 0 || this.transformers.some((transformer) => transformer.configure !== undefined), @@ -589,18 +595,17 @@ class AcpRuntime { this.nativeSessionId = response.sessionId; this.modes = response.modes ?? null; this.configOptions = response.configOptions ?? []; - return toProviderCatalog(response.modes, response.configOptions ?? []); + const catalog = toProviderCatalog(this.modes, this.configOptions); + const autoAcceptMode = this.options.options.acpOptions?.autoAcceptMode; + if (!autoAcceptMode) return catalog; + return { + ...catalog, + modes: [...catalog.modes, { ...autoAcceptMode.mode, isUnattended: true }], + defaultMode: autoAcceptMode.default ? autoAcceptMode.mode.id : catalog.defaultMode, + }; } - prompt(input: Extract): Promise { - const admission = this.promptLane.then(() => this.admitPrompt(input)); - this.promptLane = admission.catch(() => undefined); - return admission; - } - - private async admitPrompt( - input: Extract, - ): Promise { + async prompt(input: Extract): Promise { const active = this.activePrompt; if (active) { await this.interrupt(); @@ -659,6 +664,7 @@ class AcpRuntime { const state = response.stopReason === "cancelled" ? "canceled" : "completed"; this.fallbackChunkIds.clear(); this.terminalizeTransientItems(state); + this.finishTurnPermissions(turnId); this.emit({ type: "session.turn", sessionId: this.options.boundarySessionId, @@ -671,6 +677,7 @@ class AcpRuntime { await this.drainNotifications(); this.fallbackChunkIds.clear(); this.terminalizeTransientItems("failed"); + this.finishTurnPermissions(turnId); this.emit({ type: "session.turn", sessionId: this.options.boundarySessionId, @@ -712,12 +719,28 @@ class AcpRuntime { `ACP permission action '${response.selectedActionId}' does not exist or does not match '${response.behavior}' behavior`, ); } - this.permissions.delete(permissionId); - pending.resolve({ + this.resolvePermission(permissionId, pending, { outcome: selected ? { outcome: "selected", optionId: selected.optionId } : { outcome: "cancelled" }, }); + } + + private finishTurnPermissions(turnId: string): void { + for (const [permissionId, pending] of this.permissions) { + if (pending.turnId === turnId) { + this.resolvePermission(permissionId, pending, { outcome: { outcome: "cancelled" } }); + } + } + } + + private resolvePermission( + permissionId: string, + pending: PendingPermission, + response: RequestPermissionResponse, + ): void { + this.permissions.delete(permissionId); + pending.resolve(response); this.emit({ type: "session.permission_resolved", sessionId: this.options.boundarySessionId, @@ -728,6 +751,17 @@ class AcpRuntime { async configure( changes: Extract["changes"], ): Promise { + const autoAcceptMode = this.options.options.acpOptions?.autoAcceptMode; + if ( + autoAcceptMode && + changes.mode !== undefined && + (changes.mode === autoAcceptMode.mode.id) !== this.autoAccept && + (this.activePrompt || this.permissions.size > 0) + ) { + throw new Error( + `Finish or stop the current turn before switching to or from ${autoAcceptMode.mode.label}.`, + ); + } const requested: AcpConfigChange[] = []; if (changes.model !== undefined) requested.push({ target: "model", value: changes.model }); if (changes.mode !== undefined) requested.push({ target: "mode", value: changes.mode }); @@ -738,6 +772,7 @@ class AcpRuntime { requested.push({ target: "setting", id, value }); } const ordered = this.inAgentOrder(requested); + const previousAutoAccept = this.autoAccept; const previousModes = this.modes ? structuredClone(this.modes) : null; const previousOptions = structuredClone(this.configOptions); this.configTransaction = true; @@ -763,6 +798,7 @@ class AcpRuntime { await this.close(); throw failure; } + this.autoAccept = previousAutoAccept; this.modes = previousModes; this.configOptions = previousOptions; this.stagedTransformerConfig = null; @@ -805,7 +841,9 @@ class AcpRuntime { private async applyInitialConfig(config: ProviderSessionConfig): Promise { const requested: AcpConfigChange[] = []; if (config.model) requested.push({ target: "model", value: config.model }); - if (config.mode) requested.push({ target: "mode", value: config.mode }); + const autoAcceptMode = this.options.options.acpOptions?.autoAcceptMode; + const mode = config.mode ?? (autoAcceptMode?.default ? autoAcceptMode.mode.id : undefined); + if (mode) requested.push({ target: "mode", value: mode }); if (config.thinkingOption) { requested.push({ target: "thinking", value: config.thinkingOption }); } @@ -836,6 +874,24 @@ class AcpRuntime { } private async applyConfigChange(change: AcpConfigChange): Promise { + const autoAcceptMode = this.options.options.acpOptions?.autoAcceptMode; + if ( + change.target === "mode" && + autoAcceptMode && + (this.autoAccept || change.value === autoAcceptMode.mode.id) + ) { + const enableAutoAccept = change.value === autoAcceptMode.mode.id; + const nativeMode = enableAutoAccept ? autoAcceptMode.nativeMode : change.value; + this.autoAccept = false; + if (nativeMode !== this.nativeModeId()) { + await this.applyNativeConfigChange({ target: "mode", value: nativeMode }); + } + if (nativeMode !== this.nativeModeId()) { + throw new Error(`ACP agent did not switch to mode '${nativeMode}'`); + } + this.autoAccept = enableAutoAccept; + return; + } const access = this.configAccess(); for (const transformer of this.transformers) { if ( @@ -909,7 +965,20 @@ class AcpRuntime { this.emitConfigSnapshot(toProviderConfigState(this.modes, this.configOptions)); } + private nativeModeId(): string | undefined { + return selectedValue(modeOption(this.configOptions)) ?? this.modes?.currentModeId; + } + private emitConfigSnapshot(config: ProviderConfigState): void { + const autoAcceptMode = this.options.options.acpOptions?.autoAcceptMode; + if (autoAcceptMode) { + if (this.nativeModeId() !== autoAcceptMode.nativeMode) this.autoAccept = false; + config = { + ...config, + mode: this.autoAccept ? autoAcceptMode.mode.id : config.mode, + modes: [...config.modes, { ...autoAcceptMode.mode, isUnattended: true }], + }; + } this.emit({ type: "session.config", sessionId: this.options.boundarySessionId, @@ -947,10 +1016,28 @@ class AcpRuntime { } } - private requestPermission(request: RequestPermissionRequest): Promise { + private async requestPermission( + request: RequestPermissionRequest, + ): Promise { + await this.notificationLane; + if (this.closing || this.processFailed) return { outcome: { outcome: "cancelled" } }; + if ( + this.autoAccept && + request.sessionId === this.nativeSessionId && + this.nativeModeId() === this.options.options.acpOptions?.autoAcceptMode?.nativeMode + ) { + const allowOptions = request.options.filter((option) => option.kind.startsWith("allow")); + const allowOnce = allowOptions.find((option) => option.kind === "allow_once"); + if ( + allowOnce && + new Set(allowOptions.map((option) => option.kind)).size === allowOptions.length + ) { + return { outcome: { outcome: "selected", optionId: allowOnce.optionId } }; + } + } const permissionId = `permission:${request.toolCall.toolCallId}`; return new Promise((resolve) => { - this.permissions.set(permissionId, { request, resolve }); + this.permissions.set(permissionId, { request, resolve, turnId: this.activePrompt?.turnId }); this.emit({ type: "session.permission", sessionId: this.options.boundarySessionId, @@ -1111,6 +1198,12 @@ class AcpRuntime { return; } if (update.sessionUpdate === "current_mode_update") { + const option = modeOption(this.configOptions); + if (option?.type === "select") { + this.configOptions = this.configOptions.map((candidate) => + candidate === option ? { ...option, currentValue: update.currentModeId } : candidate, + ); + } if (this.modes) this.modes = { ...this.modes, currentModeId: update.currentModeId }; this.emitConfig(); return; diff --git a/packages/plugin/src/server/acp.test.ts b/packages/plugin/src/server/acp.test.ts index bd0ad2e73b..f5a583f304 100644 --- a/packages/plugin/src/server/acp.test.ts +++ b/packages/plugin/src/server/acp.test.ts @@ -303,6 +303,136 @@ describe("runAcpProvider", () => { }, ); + it("auto-accepts ordinary permissions only in the unattended mode and refuses to switch while busy", async () => { + const modeConfig = { + id: "mode", + name: "Mode", + category: "mode", + type: "select", + currentValue: "default", + options: [ + { value: "default", name: "Default" }, + { value: "plan", name: "Plan" }, + ], + }; + const approval = { + sessionId: "connector-session", + toolCall: { toolCallId: "tool", title: "Write a file", rawInput: {} }, + options: [ + { optionId: "always", name: "Always allow", kind: "allow_always" }, + { optionId: "once", name: "Allow once", kind: "allow_once" }, + { optionId: "deny", name: "Deny", kind: "reject_once" }, + ], + }; + let finishPrompt: (() => void) | undefined; + let nativePrompt: AcpRequestMessage | undefined; + const outcomes: unknown[] = []; + const { connector } = connectorHarness({ + configOptions: [modeConfig], + handleMessage(runtime, message) { + if (!("method" in message) || message.method !== "session/cancel" || !nativePrompt) + return false; + runtime.respond(nativePrompt, { stopReason: "cancelled" }); + return true; + }, + handleRequest(runtime, request) { + if (request.method !== "session/prompt") return false; + nativePrompt = request; + void runtime.request("session/request_permission", approval).then((outcome) => { + outcomes.push(outcome); + finishPrompt = () => runtime.respond(request, { stopReason: "end_turn" }); + return undefined; + }); + return true; + }, + }); + const connection = await runAcpProvider({ + id: "unattended", + label: "Unattended", + connector, + acpOptions: { + autoAcceptMode: { + mode: { id: "full-access", label: "Full access" }, + nativeMode: "default", + default: true, + }, + }, + }).connect({ + versions: [1], + capabilities: ["prompt.message", "session.configure", "permission"], + }); + const events: ProviderEvent[] = []; + connection.onEvent((event) => events.push(event)); + const configure = async (requestId: string, mode: string) => { + await connection.send({ + type: "session.configure", + requestId, + sessionId: "session-1", + changes: { mode }, + }); + return waitForEvent(events, (event) => "requestId" in event && event.requestId === requestId); + }; + const prompt = (id: string) => + connection.send({ + type: "session.prompt", + sessionId: "session-1", + prompt: { + clientMessageId: id, + delivery: "auto", + input: { type: "message", content: [{ type: "text", text: id }] }, + }, + }); + try { + await connection.send({ type: "catalog", requestId: "catalog" }); + expect(await waitForEvent(events, (event) => event.type === "catalog")).toMatchObject({ + catalog: { + defaultMode: "full-access", + modes: expect.arrayContaining([ + { id: "full-access", label: "Full access", isUnattended: true }, + ]), + }, + }); + await connection.send(openInput()); + await waitForEvent(events, (event) => event.type === "session.ready"); + await prompt("unattended"); + await expect + .poll(() => outcomes[0]) + .toEqual({ outcome: { outcome: "selected", optionId: "once" } }); + expect(events.some((event) => event.type === "session.permission")).toBe(false); + expect(await configure("busy", "plan")).toMatchObject({ type: "request.failed" }); + finishPrompt!(); + await waitForEvent( + events, + (event) => event.type === "session.turn" && event.state === "completed", + ); + expect(await configure("leave", "default")).toMatchObject({ type: "request.completed" }); + + await prompt("interactive"); + await waitForEvent(events, (event) => event.type === "session.permission"); + expect(await configure("pending", "full-access")).toMatchObject({ type: "request.failed" }); + expect(outcomes).toHaveLength(1); + await connection.send({ + type: "session.interrupt", + requestId: "stop", + sessionId: "session-1", + }); + await waitForEvent( + events, + (event) => + event.type === "session.turn" && + event.turnId === "acp:interactive" && + event.state === "canceled", + ); + await expect.poll(() => outcomes[1]).toEqual({ outcome: { outcome: "cancelled" } }); + expect(await configure("enter", "full-access")).toMatchObject({ type: "request.completed" }); + expect( + events.filter((event) => event.type === "session.config").map((event) => event.config.mode), + ).toEqual(["full-access", "default", "full-access"]); + } finally { + await connection.close(); + } + }); + it("accepts a prompt as soon as the session reports ready", async () => { const { connector } = connectorHarness(); const connection = await runAcpProvider({ diff --git a/packages/plugin/src/server/acp.ts b/packages/plugin/src/server/acp.ts index 3081d84edc..3b2cfa6fc7 100644 --- a/packages/plugin/src/server/acp.ts +++ b/packages/plugin/src/server/acp.ts @@ -3,6 +3,7 @@ import type { ProviderCatalog, ProviderCommand, ProviderConfigState, + ProviderMode, ProviderNotice, ProviderPersistence, ProviderRegistration, @@ -52,6 +53,12 @@ export interface AcpOptions { initialCommandsTimeoutMs?: number; /** Allow delayed session/load updates before publishing the session as ready. */ loadReplayQuietPeriodMs?: number; + /** An unattended mode that approves ACP allow-once requests in the specified native mode. */ + autoAcceptMode?: { + mode: Omit; + nativeMode: string; + default?: boolean; + }; } export interface AcpContext { diff --git a/plugins/antigravity-provider/server/provider.test.ts b/plugins/antigravity-provider/server/provider.test.ts index d96f80244a..351925c308 100644 --- a/plugins/antigravity-provider/server/provider.test.ts +++ b/plugins/antigravity-provider/server/provider.test.ts @@ -136,7 +136,10 @@ it.each([true, false])( expect.objectContaining({ type: "session.config", config: expect.objectContaining({ - mode: "default", + mode: "full-access", + modes: expect.arrayContaining([ + expect.objectContaining({ id: "full-access", isUnattended: true }), + ]), model: "gemini-3.8-flash", thinkingOption: "high", }), diff --git a/plugins/antigravity-provider/server/provider.ts b/plugins/antigravity-provider/server/provider.ts index 885f6e4f0f..4b6c81d0c3 100644 --- a/plugins/antigravity-provider/server/provider.ts +++ b/plugins/antigravity-provider/server/provider.ts @@ -44,10 +44,6 @@ const antigravity: AcpTransformer = { }, async configure(change, { apply, catalog }) { // COMPAT(antigravityStreamJson): added in v0.16.2, remove after 2027-11-19. - if (change.target === "mode" && change.value === "full-access") { - await apply({ target: "mode", value: "default" }); - return "handled"; - } if (change.target === "model" && change.value) { const legacyModel = /^(.*)-(xhigh|high|medium|low|minimal)$/.exec(change.value); if (legacyModel) { @@ -76,7 +72,21 @@ export function createAntigravityProvider(): ProviderRegistration { description: "Antigravity CLI on your host", icon: "icon.svg", command: ["agy", "acp", "--disable-telemetry"], - acpOptions: { waitForInitialCommands: true, loadReplayQuietPeriodMs: 200 }, + acpOptions: { + waitForInitialCommands: true, + loadReplayQuietPeriodMs: 200, + autoAcceptMode: { + mode: { + id: "full-access", + label: "Full access", + description: "Approve tool requests without asking.", + icon: "ShieldOff", + colorTier: "dangerous", + }, + nativeMode: "default", + default: true, + }, + }, transformers: [antigravity], }); return { diff --git a/public-docs/plugins/providers.md b/public-docs/plugins/providers.md index bc358ccfce..698b8a8426 100644 --- a/public-docs/plugins/providers.md +++ b/public-docs/plugins/providers.md @@ -500,6 +500,11 @@ Set `acpOptions.loadReplayQuietPeriodMs` for an agent that streams history after response. Paseo waits for that interval without session updates before it publishes the session as ready. The wait is bounded at five times the interval. +Set `acpOptions.autoAcceptMode` to offer an unattended mode backed by a specific native mode. +The adapter selects an unambiguous ACP `allow_once` action without opening a Paseo approval. +Set `default: true` to make this the default for new sessions. The adapter requires an idle +session without pending approvals before it switches to or from this mode. + ## Test and publish Test the provider against the real agent, not only mocked frames: diff --git a/public-docs/supported-providers/antigravity.md b/public-docs/supported-providers/antigravity.md index dd719ca89e..b21eb355a5 100644 --- a/public-docs/supported-providers/antigravity.md +++ b/public-docs/supported-providers/antigravity.md @@ -35,7 +35,9 @@ If you already override the command, add `acp` to the command arguments. See [Cu Paseo connects to `agy acp` and shows the permission modes the CLI offers. In **Default**, Paseo shows approval requests for edits and commands that Antigravity policy requires you to approve. In **Accept edits**, Antigravity approves workspace edits and still asks about commands that require approval. **Plan** lets Antigravity plan before it acts. -Existing Paseo chats saved in **Full access** reopen in **Default**. Antigravity has no unattended mode in Paseo. If a scheduled run reaches an approval request, the run fails at that request. +**Full access** is the default. Paseo approves tool requests that offer a single **Allow once** action. Antigravity still enforces its own tool policy. Existing chats saved in **Full access** keep that mode, and scheduled runs can use it without a person to approve each tool call. + +Finish or stop the current turn before you switch to or from **Full access**. ## Sessions and tools diff --git a/public-docs/supported-providers/antigravity.zh-CN.md b/public-docs/supported-providers/antigravity.zh-CN.md index 8711e17738..d47e491470 100644 --- a/public-docs/supported-providers/antigravity.zh-CN.md +++ b/public-docs/supported-providers/antigravity.zh-CN.md @@ -33,7 +33,9 @@ nav: Antigravity Paseo 连接到 `agy acp`,并显示 CLI 提供的权限模式。在 **Default** 模式下,如果 Antigravity 的权限策略要求批准编辑或命令,Paseo 会显示审批请求。在 **Accept edits** 模式下,Antigravity 会自动批准工作区内的编辑,仍会询问是否批准需要审批的命令。**Plan** 模式让 Antigravity 先规划,再执行。 -以前以 **Full access** 模式保存的 Paseo 聊天会以 **Default** 模式重新打开。Paseo 不提供 Antigravity 的无人值守模式。如果计划任务遇到审批请求,本次运行就会失败。 +**Full access** 是默认模式。如果工具请求只提供一个 **Allow once** 操作,Paseo 会自动批准。Antigravity 仍会执行自己的工具策略。以前以 **Full access** 模式保存的聊天会保留该模式,计划任务也可以使用该模式,无需人为逐次审批。 + +切换到 **Full access** 或从该模式切换到其他模式前,请先完成或停止当前轮次。 ## 会话和工具 {#sessions-and-tools}