Files
paseo/plugins/antigravity-provider/server/provider.ts
T
Mohamed Boudra 20f217b8cb fix(acp): finish Antigravity turns after recurring schedules (#10469)
Antigravity returns end_turn while a recurring schedule stays in progress. Exclude cron registration from the provider's deferred-turn blockers so waiting for a tool completion cannot strand the foreground turn.
2026-11-22 11:11:55 +07:00

159 lines
5.5 KiB
TypeScript

import { execCommand } from "@getpaseo/plugin/server";
import { runAcpProvider, type AcpTransformer } from "@getpaseo/plugin/server/acp";
import {
PROVIDER_PROTOCOL_VERSION,
type ProviderInstallationLaunch,
type ProviderRegistration,
} from "@getpaseo/plugin/server/provider";
import { z } from "zod";
import { mapToolCall } from "./tool-calls.js";
const legacySession = z.object({
version: z.literal(1),
data: z.object({ conversationId: z.string().min(1) }),
});
const systemPromptCapability = z.object({
antigravity: z.object({ systemPrompt: z.object({ append: z.literal(true) }) }),
});
// agy 1.5.13 advertises these built-in commands and its invocable skills in one ACP list.
const builtInCommands = new Set([
"goal",
"compact",
"schedule",
"browser",
"plan",
"grill-me",
"teamwork",
"learn",
"boost",
]);
const antigravity: AcpTransformer = {
command(command) {
return { ...command, kind: builtInCommands.has(command.name) ? "command" : "skill" };
},
toolCall: mapToolCall,
sessionOpen({ persistence, systemPrompt, agentMetadata }) {
// COMPAT(antigravityStreamJson): added in v0.16.2, remove after 2027-11-19.
const saved = legacySession.safeParse(persistence);
return {
sessionId: saved.success ? saved.data.data.conversationId : undefined,
metadata:
systemPrompt && systemPromptCapability.safeParse(agentMetadata).success
? { antigravity: { systemPrompt: { append: systemPrompt } } }
: undefined,
};
},
async configure(change, { apply, catalog }) {
// COMPAT(antigravityStreamJson): added in v0.16.2, remove after 2027-11-19.
if (change.target === "model" && change.value) {
const legacyModel = /^(.*)-(xhigh|high|medium|low|minimal)$/.exec(change.value);
if (legacyModel) {
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";
},
};
/** The release `agy --version` reports, or its first line when it names no release. */
async function readAgyVersion(
launch: ProviderInstallationLaunch,
signal: AbortSignal,
): Promise<string | undefined> {
// The launch ends with the `acp` subcommand and its flags; the version comes from the CLI itself.
const acp = launch.args.indexOf("acp");
const prefix = acp === -1 ? launch.args : launch.args.slice(0, acp);
const { stdout } = await execCommand(launch.command, [...prefix, "--version"], {
env: launch.env,
timeout: 5000,
maxBuffer: 8192,
signal,
});
const firstLine = stdout.trim().split("\n")[0]?.trim();
return /\b\d+\.\d+\.\d+\S*/.exec(stdout)?.[0] ?? (firstLine || undefined);
}
export function createAntigravityProvider(): ProviderRegistration {
const provider = runAcpProvider({
id: "antigravity",
label: "Antigravity",
description: "Antigravity CLI on your host",
icon: "icon.svg",
command: ["agy", "acp", "--disable-telemetry"],
acpOptions: {
waitForInitialCommands: true,
loadReplayQuietPeriodMs: 200,
// COMPAT(antigravityAcpV1DeferredTurn): added in v0.18.0, remove once Antigravity CLI supports ACP v2 state_update.
deferTurnOnRunningTools: {
keepsTurnOpen(toolCall) {
const input = toolCall.input;
if (typeof input !== "object" || input === null || Array.isArray(input)) return true;
if (input.IsDaemon === true) return false;
// agy leaves recurring schedules in progress after registering them.
const recurringSchedule =
toolCall.name === "schedule" &&
typeof input.CronExpression === "string" &&
input.CronExpression.trim().length > 0;
return !recurringSchedule;
},
},
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 {
...provider,
// agy documents no update command and no release source, so there is nothing to check or run.
installation: {
installUrl: "https://antigravity.google/docs/getting-started?tab=cli",
async inspect({ launch, signal }) {
if (!launch?.resolved) return { status: "not_installed" };
const version = await readAgyVersion(launch, signal);
return version ? { status: "installed", version } : { status: "installed" };
},
},
async status({ launch }) {
if (!launch) return { available: false, diagnostic: "Install Antigravity 1.5.0 or later." };
try {
const connection = await provider.connect({
launch,
versions: [PROVIDER_PROTOCOL_VERSION],
capabilities: [],
});
await connection.close();
return { available: true };
} catch {
return {
available: false,
diagnostic:
"Antigravity ACP did not start. Install Antigravity 1.5.0 or later. If you override the command, include the acp subcommand.",
};
}
},
};
}