diff --git a/packages/plugin/src/server/acp-internal/connection.ts b/packages/plugin/src/server/acp-internal/connection.ts index 3c4fcf36d3..a47a91c387 100644 --- a/packages/plugin/src/server/acp-internal/connection.ts +++ b/packages/plugin/src/server/acp-internal/connection.ts @@ -375,6 +375,7 @@ class AcpRuntime { private configOptions: SessionConfigOption[] = []; private modes: NewSessionResponse["modes"] = null; private commandWaiter: (() => void) | null = null; + private receivedInitialCommands = false; private messageSequence = 0; /** * Fallback ids for streamed chunks that carry no `messageId`, one per @@ -387,10 +388,11 @@ class AcpRuntime { string >(); /** - * Loaded history can arrive after session/load resolves. Treat updates as - * replay until the client sends the first prompt to this session. + * Replay updates count as history until the session reports ready. + * Once ready, suppress late replay rows until the first prompt. */ private replayWindow: "replay" | "skip" | null = null; + private lastLoadUpdateAt = 0; private closing = false; private processFailed = false; private configTransaction = false; @@ -533,6 +535,7 @@ class AcpRuntime { }), ); await this.drainNotifications(); + if (!this.options.options.acpOptions?.loadReplayQuietPeriodMs) this.replayWindow = null; } else { const newSession = await this.call( this.connection.newSession({ @@ -568,6 +571,11 @@ class AcpRuntime { if (this.options.options.acpOptions?.waitForInitialCommands) { await this.waitForInitialCommands(); } + const quietPeriod = this.options.options.acpOptions?.loadReplayQuietPeriodMs; + if (this.replayWindow && quietPeriod && quietPeriod > 0) { + await this.waitForLoadReplay(quietPeriod); + this.replayWindow = "skip"; + } return sessionCapabilities; } @@ -599,10 +607,7 @@ class AcpRuntime { await active.settled; } const prompt = toAcpPrompt(input.prompt); - if (this.replayWindow) { - await this.drainNotifications(); - this.replayWindow = null; - } + this.replayWindow = null; const turnId = `acp:${input.prompt.clientMessageId}`; this.fallbackChunkIds.clear(); this.emit({ @@ -837,11 +842,17 @@ class AcpRuntime { (await transformer.configure?.(change, { sessionId: this.options.boundarySessionId, config: access, + catalog: () => toProviderCatalog(this.modes, this.configOptions), + apply: (nativeChange) => this.applyNativeConfigChange(nativeChange), })) === "handled" ) { return; } } + await this.applyNativeConfigChange(change); + } + + private async applyNativeConfigChange(change: AcpConfigChange): Promise { if (change.target === "mode" && this.modes && !modeOption(this.configOptions)) { if (!change.value) { throw new Error("ACP session does not expose mode configuration"); @@ -961,6 +972,7 @@ class AcpRuntime { private sessionUpdate(notification: SessionNotification): void { if (notification.sessionId !== this.nativeSessionId) return; + if (this.replayWindow) this.lastLoadUpdateAt = performance.now(); if (this.replayWindow === "skip") { const update = notification.update; if ( @@ -1094,8 +1106,8 @@ class AcpRuntime { argumentHint: command.input?.hint, })); this.emit({ type: "session.commands", sessionId: this.options.boundarySessionId, commands }); + this.receivedInitialCommands = true; this.commandWaiter?.(); - this.commandWaiter = null; return; } if (update.sessionUpdate === "current_mode_update") { @@ -1263,16 +1275,28 @@ class AcpRuntime { } private waitForInitialCommands(): Promise { + if (this.receivedInitialCommands) return Promise.resolve(); const timeoutMs = this.options.options.acpOptions?.initialCommandsTimeoutMs ?? 1_000; const commands = new Promise((resolve) => { this.commandWaiter = resolve; }); - const timeout = new Promise((resolve) => { - setTimeout(resolve, timeoutMs); - }); - return Promise.race([commands, timeout]).finally(() => { - this.commandWaiter = null; - }); + return withTimeout(commands, timeoutMs, "ACP agent did not publish initial commands") + .catch(() => undefined) + .finally(() => { + this.commandWaiter = null; + }); + } + + private async waitForLoadReplay(quietPeriod: number): Promise { + const start = performance.now(); + const deadline = start + 5 * quietPeriod; + while (!this.closing && !this.processFailed) { + const idleAt = Math.max(start, this.lastLoadUpdateAt) + quietPeriod; + const remaining = Math.min(deadline, idleAt) - performance.now(); + if (remaining <= 0) return; + await new Promise((resolve) => setTimeout(resolve, remaining)); + await this.notificationLane; + } } } diff --git a/packages/plugin/src/server/acp.test.ts b/packages/plugin/src/server/acp.test.ts index 7a3ce69dff..bd0ad2e73b 100644 --- a/packages/plugin/src/server/acp.test.ts +++ b/packages/plugin/src/server/acp.test.ts @@ -229,44 +229,62 @@ describe("runAcpProvider", () => { it.each(["replay", "skip"] as const)( "handles trailing load updates with %s history", async (history) => { - const { connector, instances } = connectorHarness({ capabilities: { loadSession: true } }); - const connection = await runAcpProvider({ id: "load", label: "Load", connector }).connect({ - versions: [1], - capabilities: ["prompt.message", "session.persistence"], + const sessionId = "connector-session"; + const notifyUpdate = (runtime: ConnectorInstance, update: unknown) => + runtime.notify("session/update", { sessionId, update }); + const { connector, instances } = connectorHarness({ + capabilities: { loadSession: true }, + handleRequest(runtime, request) { + if (request.method !== "session/load") return false; + notifyUpdate(runtime, { + sessionUpdate: "available_commands_update", + availableCommands: [{ name: "help", description: "Help" }], + }); + runtime.respond(request, { configOptions: [] }); + setTimeout(() => { + notifyUpdate(runtime, { + sessionUpdate: "user_message_chunk", + content: { type: "text", text: "previous question" }, + }); + notifyUpdate(runtime, { + sessionUpdate: "agent_message_chunk", + content: { type: "text", text: "previous answer" }, + }); + }, 100); + return true; + }, }); + const connection = await runAcpProvider({ + id: "load", + label: "Load", + connector, + acpOptions: { + waitForInitialCommands: true, + initialCommandsTimeoutMs: 10_000, + loadReplayQuietPeriodMs: 200, + }, + }).connect({ versions: [1], capabilities: ["prompt.message", "session.persistence"] }); const events: ProviderEvent[] = []; connection.onEvent((event) => events.push(event)); try { - const input = { + await connection.send({ ...openInput(), history, - persistence: { version: 1, data: { sessionId: "connector-session" } }, - }; - await connection.send(input); + persistence: { version: 1, data: { sessionId } }, + }); await waitForEvent(events, (event) => event.type === "session.ready"); - const runtime = instances[1]; - runtime.notify("session/update", { - sessionId: "connector-session", - update: { - sessionUpdate: "user_message_chunk", - content: { type: "text", text: "previous question" }, - }, + notifyUpdate(instances[1], { + sessionUpdate: "agent_message_chunk", + content: { type: "text", text: "stale history outside the replay window" }, }); - runtime.notify("session/update", { - sessionId: "connector-session", - update: { - sessionUpdate: "agent_message_chunk", - content: { type: "text", text: "previous answer" }, - }, + notifyUpdate(instances[1], { + sessionUpdate: "available_commands_update", + availableCommands: [{ name: "different", description: "Different" }], }); - runtime.notify("session/update", { - sessionId: "connector-session", - update: { - sessionUpdate: "available_commands_update", - availableCommands: [{ name: "help", description: "Help" }], - }, - }); - await waitForEvent(events, (event) => event.type === "session.commands"); + await waitForEvent( + events, + (event) => event.type === "session.commands" && event.commands[0]?.name === "different", + ); const items = events .filter((event) => event.type === "timeline.item") .map((event) => event.item); diff --git a/packages/plugin/src/server/acp.ts b/packages/plugin/src/server/acp.ts index b70d6c2b4a..3081d84edc 100644 --- a/packages/plugin/src/server/acp.ts +++ b/packages/plugin/src/server/acp.ts @@ -50,6 +50,8 @@ export interface AcpOptions { workspaceOnlyCatalog?: boolean; waitForInitialCommands?: boolean; initialCommandsTimeoutMs?: number; + /** Allow delayed session/load updates before publishing the session as ready. */ + loadReplayQuietPeriodMs?: number; } export interface AcpContext { @@ -67,6 +69,8 @@ export interface AcpDiscoveryContext extends AcpContext { export interface AcpConfigureContext extends AcpContext { config: AcpConfigAccess; + catalog(): ProviderCatalog; + apply(change: AcpConfigChange): Promise; } export type AcpConfigChange = diff --git a/plugins/antigravity-provider/server/provider.test.ts b/plugins/antigravity-provider/server/provider.test.ts index 380b37158d..d96f80244a 100644 --- a/plugins/antigravity-provider/server/provider.test.ts +++ b/plugins/antigravity-provider/server/provider.test.ts @@ -47,7 +47,7 @@ it.each([true, false])( const { createInterface } = require("node:readline"); const configOptions = [ { id: "model", name: "Model", category: "model", type: "select", currentValue: "gemini-4-neon", - options: [{ value: "gemini-4-neon", name: "Gemini 4 Neon" }, { value: "gemini-3.8-flash", name: "Gemini 3.8 Flash" }] }, + options: [{ value: "gemini-4-neon", name: "Gemini 4 Neon" }, { value: "gemini-3.8-flash", name: "Gemini 3.8 Flash" }, { value: "gemini-4-neon-high", name: "Gemini 4 Neon High" }] }, { id: "thought_level", name: "Thinking", category: "thought_level", type: "select", currentValue: "low", options: [{ value: "low", name: "Low" }, { value: "high", name: "High" }] }, { id: "mode", name: "Mode", category: "mode", type: "select", currentValue: "accept-edits", @@ -151,6 +151,20 @@ it.each([true, false])( }), }), ); + await connection.send({ + type: "session.configure", + requestId: "native-model", + sessionId: "test", + changes: { model: "gemini-4-neon-high" }, + }); + await expect + .poll(() => + events.find( + (event) => + event.type === "session.config" && event.config.model === "gemini-4-neon-high", + ), + ) + .toBeDefined(); const requests = (await readFile(launch.env.CAPTURE, "utf8")) .trim() .split("\n") diff --git a/plugins/antigravity-provider/server/provider.ts b/plugins/antigravity-provider/server/provider.ts index 8cee889f6e..885f6e4f0f 100644 --- a/plugins/antigravity-provider/server/provider.ts +++ b/plugins/antigravity-provider/server/provider.ts @@ -42,18 +42,27 @@ const antigravity: AcpTransformer = { : undefined, }; }, - async configure(change, { config }) { + 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 config.set("mode", "default"); + 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) { - await config.set("model", legacyModel[1]); - await config.set("thought_level", legacyModel[2]); - return "handled"; + const { models } = catalog(); + const [, model, effort] = legacyModel; + if ( + !models.some((option) => option.id === change.value) && + models.some((option) => option.id === model) + ) { + await apply({ target: "model", value: model }); + if (catalog().thinkingOptions?.some((option) => option.id === effort)) { + await apply({ target: "thinking", value: effort }); + } + return "handled"; + } } } return "pass"; @@ -67,7 +76,7 @@ export function createAntigravityProvider(): ProviderRegistration { description: "Antigravity CLI on your host", icon: "icon.svg", command: ["agy", "acp", "--disable-telemetry"], - acpOptions: { waitForInitialCommands: true }, + acpOptions: { waitForInitialCommands: true, loadReplayQuietPeriodMs: 200 }, transformers: [antigravity], }); return { @@ -86,7 +95,7 @@ export function createAntigravityProvider(): ProviderRegistration { return { available: false, diagnostic: - "Antigravity ACP did not start. Install Antigravity 1.5.0 or later and check your CLI configuration.", + "Antigravity ACP did not start. Install Antigravity 1.5.0 or later. If you override the command, include the acp subcommand.", }; } }, diff --git a/public-docs/plugins/providers.md b/public-docs/plugins/providers.md index dd1b13d86a..bc358ccfce 100644 --- a/public-docs/plugins/providers.md +++ b/public-docs/plugins/providers.md @@ -492,6 +492,14 @@ Return `metadata` to add fields to the session request's `_meta`. If your plugin previously saved a different persistence format, return its native `sessionId`. Paseo gives its own saved session ID precedence and writes the ACP persistence format after opening. +A `configure` transformer can inspect the agent's current choices with `catalog()` and pass a +translated change to `apply(change)`. Applying a change this way uses the shared ACP configuration +mapping and skips the transformers for that change. + +Set `acpOptions.loadReplayQuietPeriodMs` for an agent that streams history after its `session/load` +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. + ## 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 ebbe645183..dd719ca89e 100644 --- a/public-docs/supported-providers/antigravity.md +++ b/public-docs/supported-providers/antigravity.md @@ -29,13 +29,13 @@ If `agy` is outside your daemon's PATH, override its command in `~/.paseo/config } ``` -See [Custom providers](/docs/custom-providers) for command and environment overrides. +If you already override the command, add `acp` to the command arguments. See [Custom providers](/docs/custom-providers) for command and environment overrides. ## Permissions 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**. +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. ## Sessions and tools diff --git a/public-docs/supported-providers/antigravity.zh-CN.md b/public-docs/supported-providers/antigravity.zh-CN.md index 0e531ea48f..8711e17738 100644 --- a/public-docs/supported-providers/antigravity.zh-CN.md +++ b/public-docs/supported-providers/antigravity.zh-CN.md @@ -27,13 +27,13 @@ nav: Antigravity } ``` -命令和环境变量覆盖见[自定义 Provider](/docs/custom-providers)。 +如果你已覆盖命令,请在命令参数中加入 `acp`。命令和环境变量覆盖见[自定义 Provider](/docs/custom-providers)。 ## 权限 {#permissions} Paseo 连接到 `agy acp`,并显示 CLI 提供的权限模式。在 **Default** 模式下,如果 Antigravity 的权限策略要求批准编辑或命令,Paseo 会显示审批请求。在 **Accept edits** 模式下,Antigravity 会自动批准工作区内的编辑,仍会询问是否批准需要审批的命令。**Plan** 模式让 Antigravity 先规划,再执行。 -以前以 **Full access** 模式保存的 Paseo 聊天会以 **Default** 模式重新打开。 +以前以 **Full access** 模式保存的 Paseo 聊天会以 **Default** 模式重新打开。Paseo 不提供 Antigravity 的无人值守模式。如果计划任务遇到审批请求,本次运行就会失败。 ## 会话和工具 {#sessions-and-tools}