Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Antigravity: strip the `&_a_m_p_;_` tokens that open a post-tool text run

Seyamalam7c8515716f49
diff --git a/server/drivers/acp/acp.test.ts b/server/drivers/acp/acp.test.ts
index 5316501d15..31657c7493 100644
--- a/server/drivers/acp/acp.test.ts
+++ b/server/drivers/acp/acp.test.ts
@@ -22,6 +22,7 @@ import { KimiAgentDriver } from "./kimi.ts";
import { DroidAgentDriver } from "./droid.ts";
import { CursorAgentDriver } from "./cursor.ts";
import { QwenAgentDriver } from "./qwen.ts";
+import { antigravityUpdateFilter } from "../antigravity.ts";
import { removeTempDir } from "../../testing/cleanup.ts";
import { TurnWatchdog } from "../../turn-watchdog.ts";
import { startFakeHttpMcp } from "../../testing/fake-http-mcp-server.ts";
@@ -90,6 +91,13 @@ const ClassifiedErrorDriver = createAcpDriver({
: undefined,
});
+const TextStartDriver = createAcpDriver({
+ ...SELECT_MODEL_SUPPORT,
+ driverKind: "textStartTest",
+ selectModel: undefined,
+ updateFilter: antigravityUpdateFilter,
+});
+
const CONTROL_PLANE_FIXTURE = {
OMB_CLOUD_READY_TOKEN: "ready-should-not-leak", OMB_CLOUD_BOOTSTRAP: "bootstrap-should-not-leak",
OMB_LICENSE_KEY: "license-should-not-leak", OMB_INSTALLATION_CREDENTIAL: "fleet-should-not-leak",
@@ -838,6 +846,24 @@ describe("ACP turns (fake CLI)", () => {
});
});
+ it("drops the escape artifact a text run opens with, again after a tool call", async () => {
+ const { report, send, lastTurn } = await reportingThread("text-start", TextStartDriver);
+ const say = (text: string) => ({ sessionUpdate: "agent_message_chunk", content: { type: "text", text } });
+ report(
+ say("&_a_m_p_;_\n&_a_m_p_;_"),
+ say("Prepared the reply. A mid-run &_a_m_p_;_ stays."),
+ { sessionUpdate: "tool_call", toolCallId: "call-1", title: "Ran a thing", status: "completed" },
+ say("&_a_m_p_;_ Done."),
+ );
+ await send("turn");
+ const texts = lastTurn().flatMap((event) =>
+ event.type === "item.completed" && event.itemType === "assistant_text" ? [event.text] : []);
+ // the fake's own greeting is the first assistant_text of the turn
+ expect(texts.slice(1)).toEqual(["Prepared the reply. A mid-run &_a_m_p_;_ stays.", "Done."]);
+ const streamed = lastTurn().flatMap((event) => event.type === "content.delta" ? [event.delta] : []);
+ expect(streamed.some((delta) => delta.startsWith("&_a_m_p_;_"))).toBe(false);
+ });
+
const plan = (...entries: Array<[status: string, content: string]>) => ({
sessionUpdate: "plan",
entries: entries.map(([status, content]) => ({ content, priority: "medium", status })),
diff --git a/server/drivers/antigravity.ts b/server/drivers/antigravity.ts
index 07c1344402..931bbd7bf1 100644
--- a/server/drivers/antigravity.ts
+++ b/server/drivers/antigravity.ts
@@ -61,6 +61,30 @@ export function antigravityPermissionMode(fullAuto: boolean, approvalMode?: Appr
return approvalMode === "edits" ? "auto_edit" : "default";
}
+/** agy_acp_server opens a text run after a tool call with `&_a_m_p_;_` tokens — `&` escaped
+ * entity-style — which Markdown then parses as emphasis; they are never real reply text. */
+export function cleanAntigravityTextStart(delta: string): string {
+ return delta.replace(/^(?:&_a_m_p_;_\s*)+/u, "");
+}
+
+/** The escaping can open any text run, so cleanAntigravityTextStart applies to the first text chunk
+ * after anything that is not one. */
+export function antigravityUpdateFilter(): (update: Record<string, any>) => Record<string, any> | null {
+ let runStart = true;
+ return (update) => {
+ if (update.sessionUpdate !== "agent_message_chunk" || update.content?.type === "image") {
+ runStart = true;
+ return update;
+ }
+ const text = update.content?.text;
+ if (typeof text !== "string" || !text || !runStart) return update;
+ const kept = cleanAntigravityTextStart(text);
+ if (!kept) return null;
+ runStart = false;
+ return kept === text ? update : { ...update, content: { ...update.content, text: kept } };
+ };
+}
+
const SIGN_IN_WORDS = /\bauthenticat|\bunauthenticated\b|\bsign(?:ed)?[ -]?in\b|\blog(?:ged)?[ -]?in\b|\bcredentials?\b/iu;
/** -32000 is ACP's `auth_required`, but an agent may reuse it for other failures; the text must agree. */
@@ -105,6 +129,7 @@ const support: AcpSupport = {
clientFileSystem: true,
clientReadRoots: (turn) => (turn.skillFiles ?? []).map(dirname),
sanitizeToolPayload: true,
+ updateFilter: antigravityUpdateFilter,
resolveCommand: async (env, config, instanceId) => {
const runtime = await resolveAntigravityRuntime(config.cli, env);