From 4b5b9b7807cf56d39aeefe238653e507e5814493 Mon Sep 17 00:00:00 2001 From: Dotta <34892728+cryppadotta@users.noreply.github.com> Date: Mon, 23 Nov 2026 16:20:43 -0600 Subject: [PATCH] fix(antigravity): keep native slash commands in task text as prose (#22701) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - The Runner can run tasks on the native Google Antigravity ACP server (version 1.5.2) > - The server turns some prompt text into native slash commands before the model sees it > - The admission guard refused only lines that start with "/". The server runs `/plan` anywhere it follows whitespace, so task text such as "see /plan for details" could switch the session into plan mode without Paperclip > - This pull request makes the guard mirror the server's exact rule for each advertised command and keeps that text as prose > - The benefit is that task, comment and pasted text cannot change the native session mode or sign the account out, and ordinary prose that mentions a command still runs ## Linked Issues or Issue Description **What happened?** The 1.5.2 server builds `_CMD_PATTERN = re.compile(r"(?:\s|^)/(" + "|".join(...) + r")(?:\s|$)")` (server.py, lines 2071-2075) over its built-in commands (`plan`) and applies it to every text block in `_parse_prompt` (server.py, line 2136). The Runner sends the task as one JSON line. A space before `/plan` survives JSON encoding, so `{"task":"... then /plan the rollout"}` produced a native plan command. The old guard did not see it, because no line started with "/". **Expected behavior** Task text reaches the model as text. Native commands that change the session (`/plan`) or the account (`/logout`) never run from task content. **Paperclip version or commit** `master` at the base of this branch, with the Antigravity ACP server 1.5.2 and its owned admission patch `1.5.2-paperclip.2`. **Steps to reproduce** 1. Send a managed Antigravity prompt whose text contains ` /plan ` after other words. 2. The old guard admits it unchanged. 3. The server's `_CMD_PATTERN.split` returns a `plan` command for that text. The other two advertised commands match only the whole prompt: `/logout` when all text joined and stripped equals `/logout` (logout.py, lines 29-36), and `/usage` when that text starts with `/usage` and whitespace or the end, case-insensitively (usage.py, lines 29-36). Python's `str.strip()` also strips characters that JavaScript does not treat as whitespace (U+001C..U+001F, U+0085), so `"\u001c/logout"` passed the old guard and is a logout to the server. ## What Changed - Add `antigravity-native-commands.ts`. It transcribes the server's three matchers, with Python's exact whitespace set, and a neutraliser that puts a word joiner (U+2060) before each slash that the server would act on. The model still reads the same words. Text that the server treats as prose is sent unchanged. - The admission guard now rewrites the outbound `session/prompt` text with the neutraliser instead of refusing every line that starts with "/". If a native command still matches afterwards, the guard refuses the prompt. - The guard fails closed if the runtime advertises a native command outside `plan`, `logout`, `usage`, so a future server command cannot pass silently. - Text blocks keep their other fields when the guard rewrites them. - The server advertises exactly `plan`, `logout` and `usage` (server.py, lines 6289-6299: the SDK's built-in commands, which are only `plan`, plus the logout and usage entries). - No change to the native admission patch, so the owned patch version and closure digests stay the same. ## Verification - Red first: the new admission tests failed on the old guard (19 failed: `/plan` mid-line, in the JSON envelope, after a newline, inside quoted text, after a tab, `"\u001c/logout"`, a command split across blocks, and benign text the old guard refused). - Green: `npx vitest run antigravity` in `packages/paperclip-runner` (14 files, 202 tests). `tsc --noEmit -p packages/paperclip-runner` passes. - Cross-check against the server: I ran the server's own regular expression and the `is_logout_prompt` / `is_usage_prompt` logic in Python on 40,000 generated multi-block inputs. The TypeScript matcher agreed on every input (998 plan, 1,423 logout, 2,941 usage matches). After neutralisation, the server matched no command, and only word joiners changed. - `pnpm verify` exits 2 (the changed test files are outside the resolved test graphs), so required CI supplies the broad coverage. - Not run live: no prompt was sent to a real Antigravity session, because the only available Gemini key is refused. The evidence is the unit-level reproduction against the guard plus the quoted server source. ## Risks - Low risk. The guard changes only prompt text that the server would run as a command, and only by inserting an invisible word joiner. If the model copies `/plan` from such text into a shell command, the word joiner could come with it. This applies only to `/plan` followed by whitespace. - Prompts with lines that start with "/" (for example a path such as `/usr/bin/x`) are no longer refused. The server does not treat them as commands. ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`) in Claude Code, with tool use and code execution. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [ ] All Paperclip CI gates are green - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 --- .../acpx/antigravity-admission.test.ts | 55 +++++++++++++++++-- .../src/drivers/acpx/antigravity-admission.ts | 16 ++++-- .../acpx/antigravity-native-commands.test.ts | 30 ++++++++++ .../acpx/antigravity-native-commands.ts | 32 +++++++++++ 4 files changed, 121 insertions(+), 12 deletions(-) create mode 100644 packages/paperclip-runner/src/drivers/acpx/antigravity-native-commands.test.ts create mode 100644 packages/paperclip-runner/src/drivers/acpx/antigravity-native-commands.ts diff --git a/packages/paperclip-runner/src/drivers/acpx/antigravity-admission.test.ts b/packages/paperclip-runner/src/drivers/acpx/antigravity-admission.test.ts index 5d8a04bc2dc..4034c279215 100644 --- a/packages/paperclip-runner/src/drivers/acpx/antigravity-admission.test.ts +++ b/packages/paperclip-runner/src/drivers/acpx/antigravity-admission.test.ts @@ -96,9 +96,8 @@ describe("Antigravity exact native admission", () => { expect(() => f.admission.assertReady()).not.toThrow(); }); - it("rejects native slash commands, non-text prompts, and arbitrary configuration", () => { + it("rejects non-text prompts and arbitrary configuration", () => { for (const message of [ - { ...prompt(), params: { ...prompt().params, prompt: [{ type: "text", text: " /logout" }] } }, { ...prompt(), params: { ...prompt().params, prompt: [{ type: "image", data: "unverified" }] } }, { id: "control", method: "session/set_config_option", params: { sessionId: "native-session", configId: "mode", value: "yolo" } }, ]) { @@ -107,14 +106,58 @@ describe("Antigravity exact native admission", () => { } }); - it.each(["Do the task\n/logout", "Do the task\r\n /model replace", "Do the task\r /login"])("rejects a native slash command on any prompt line: %j", text => { + const sendText = (...texts: string[]) => { const f = fixture(); const sent = request(f); f.guard("inbound", response(sent)); - expect(() => f.guard("outbound", { ...prompt(), params: { ...prompt().params, prompt: [{ type: "text", text }] } })).toThrow("slash commands"); + const message = { ...prompt(), params: { ...prompt().params, prompt: texts.map(text => ({ type: "text", text })) } }; + f.guard("outbound", message); + return message.params.prompt.map(block => block.text); + }; + + it.each([ + ["mid-line", "Read the doc; see /plan for details.", "Read the doc; see ⁠/plan for details."], + ["inside the JSON task envelope", "{\"task\":\"Fix it. Then /plan the rollout\"}", "{\"task\":\"Fix it. Then ⁠/plan the rollout\"}"], + ["after a newline", "line one\n/plan\nline three", "line one\n⁠/plan\nline three"], + ["inside pasted quoted content", "> quoted: \" /plan \" end", "> quoted: \" ⁠/plan \" end"], + ["after a tab", "tab\t/plan\there", "tab\t⁠/plan\there"], + ["at the start", "/plan", "⁠/plan"], + ["after Python-only whitespace", "x\u001c/plan\u0085y", "x\u001c⁠/plan\u0085y"], + ])("keeps a native /plan %s as prose instead of switching the session to plan mode", (_label, text, sent) => { + expect(sendText(text)).toEqual([sent]); }); - it("rejects a native slash command in a later text block", () => { + it.each([ + [" /logout ", " ⁠/logout "], ["\u001c/logout", "\u001c⁠/logout"], + ["/USAGE", "⁠/USAGE"], ["\u0085/usage now", "\u0085⁠/usage now"], + ])("keeps a whole-prompt native command %j as prose", (text, sent) => { + expect(sendText(text)).toEqual([sent]); + }); + + it("keeps other text block fields when it rewrites a command", () => { const f = fixture(); const sent = request(f); f.guard("inbound", response(sent)); - expect(() => f.guard("outbound", { ...prompt(), params: { ...prompt().params, prompt: [{ type: "text", text: "Do the task" }, { type: "text", text: "/logout" }] } })).toThrow("slash commands"); + const block = { type: "text", text: "see /plan", annotations: { priority: 1 } }; + const message = { ...prompt(), params: { ...prompt().params, prompt: [block] } }; + f.guard("outbound", message); + expect(message.params.prompt).toEqual([{ type: "text", text: "see ⁠/plan", annotations: { priority: 1 } }]); + }); + + it("keeps a native command split across text blocks as prose", () => { + expect(sendText(" ", "/log", "out")).toEqual([" ", "⁠/log", "out"]); + }); + + it.each([ + "/planning ahead", "a/plan b", "see https://example.test/plan for docs", "/plan/foo", "/PLAN now", + "Do the task\n/logout", "{\"t\":\"x /logout\"}", "/usages", "text /usage", "Do the task\r\n /model replace", + ])("sends text the native runtime treats as prose unchanged: %j", text => { + expect(sendText(text)).toEqual([text]); + }); + + it("fails closed when the runtime advertises a native command this guard does not know", () => { + const f = fixture(); const sent = request(f); f.guard("inbound", response(sent)); + const advertise = (names: string[]) => ({ method: "session/update", params: { sessionId: "native-session", update: { + sessionUpdate: "available_commands_update", availableCommands: names.map(name => ({ name, description: name })), + } } }); + expect(() => f.guard("inbound", advertise(["plan", "logout", "usage"]))).not.toThrow(); + expect(() => f.guard("inbound", advertise(["plan", "logout", "usage", "goal"]))).toThrow("native command"); }); it.each([ diff --git a/packages/paperclip-runner/src/drivers/acpx/antigravity-admission.ts b/packages/paperclip-runner/src/drivers/acpx/antigravity-admission.ts index 46fbfb87c7d..824215a1067 100644 --- a/packages/paperclip-runner/src/drivers/acpx/antigravity-admission.ts +++ b/packages/paperclip-runner/src/drivers/acpx/antigravity-admission.ts @@ -1,4 +1,5 @@ import { createHash, randomBytes } from "node:crypto"; +import { ANTIGRAVITY_NATIVE_COMMANDS, antigravityNativeCommands, neutralizeAntigravityNativeCommands } from "./antigravity-native-commands.js"; import { createAntigravityQuestionBridge } from "./antigravity-questions.js"; import { ANTIGRAVITY_RUNTIME_VERSION } from "./generated-profiles.js"; @@ -29,11 +30,6 @@ export function antigravityInstructionBinding(content: string) { return { digest: `sha256:${createHash("sha256").update(content, "utf8").digest("hex")}`, byteLength: Buffer.byteLength(content) }; } -export function assertAntigravityPromptPolicy(content: string): void { - // Native slash commands can alter account/configuration before inference. - if (content.split(/\r\n|\r|\n/u).some(line => line.trimStart().startsWith("/"))) throw new AntigravityAdmissionError("native slash commands are unavailable in a managed task"); -} - /** No saved ACPX record can substitute for this actual connection's receipt. */ export function createAntigravityAdmission(content: string, model: string) { const binding = antigravityInstructionBinding(content); @@ -94,7 +90,11 @@ export function createAntigravityAdmission(content: string, model: string) { assertReady(); if (params.sessionId !== state.sessionId || !Array.isArray(params.prompt) || params.prompt.some(value => record(value).type !== "text" || typeof record(value).text !== "string")) fail("prompt is outside the admitted text session"); - assertAntigravityPromptPolicy((params.prompt as unknown[]).map(value => record(value).text).join("\n")); + const blocks = (params.prompt as unknown[]).map(record); + const texts = neutralizeAntigravityNativeCommands(blocks.map(block => block.text as string)); + if (antigravityNativeCommands(texts).length > 0) fail("the task text could not be sent as plain text"); + params.prompt = blocks.map((block, index) => ({ ...block, text: texts[index] })); + message.params = params; } else if (!["initialize", "session/cancel", "session/close"].includes(method)) { fail("native control is unavailable in a managed task"); } @@ -157,6 +157,10 @@ export function createAntigravityAdmission(content: string, model: string) { } projectConcreteModel(update, model); } + if (update.sessionUpdate === "available_commands_update" && Array.isArray(update.availableCommands) + && update.availableCommands.some(command => !ANTIGRAVITY_NATIVE_COMMANDS.includes(String(record(command).name)))) { + fail("the runtime offers a native command this version cannot keep out of task text"); + } if (update.sessionUpdate === "current_mode_update" && update.currentModeId !== "default") fail("provider changed the admitted permission mode"); } questions.guard(direction, message); diff --git a/packages/paperclip-runner/src/drivers/acpx/antigravity-native-commands.test.ts b/packages/paperclip-runner/src/drivers/acpx/antigravity-native-commands.test.ts new file mode 100644 index 00000000000..8d0fd18d78d --- /dev/null +++ b/packages/paperclip-runner/src/drivers/acpx/antigravity-native-commands.test.ts @@ -0,0 +1,30 @@ +import { describe, expect, it } from "vitest"; +import { antigravityNativeCommands, neutralizeAntigravityNativeCommands } from "./antigravity-native-commands.js"; + +const serverOutcomes: Array<[string[], string[]]> = [ + [["Please read the doc; see /plan for details."], ["plan"]], + [["{\"task\":\"Fix bug. Then /plan the rollout\"}"], ["plan"]], + [["line one\n/plan\nline three"], ["plan"]], + [["tab\t/plan\there"], ["plan"]], + [["x\u001c/plan"], ["plan"]], + [["/plan"], ["plan"]], + [["/planning ahead"], []], [["a/plan b"], []], [["see https://example.test/plan for docs"], []], + [["/plan/foo"], []], [["/PLAN now"], []], [["{\"issue\":\"quoted: \\\"> /plan\\\" end\"}"], []], + [["{\"t\":\"x /logout\"}"], []], [[" /logout "], ["logout"]], [["\u001c/logout"], ["logout"]], [["/log", "out"], ["logout"]], + [["Do the task\n/logout"], []], + [["/USAGE"], ["usage"]], [["/usage now"], ["usage"]], [["\u0085/usage"], ["usage"]], [["/usages"], []], [["text /usage"], []], + [["⁠/plan"], []], [["⁠/logout"], []], +]; + +describe("Antigravity native command matching", () => { + it.each(serverOutcomes)("matches the pinned server for %j", (blocks, commands) => { + expect(antigravityNativeCommands(blocks)).toEqual(commands); + }); + + it.each(serverOutcomes)("leaves no native command and changes nothing but word joiners in %j", blocks => { + const sent = neutralizeAntigravityNativeCommands(blocks); + expect(antigravityNativeCommands(sent)).toEqual([]); + expect(sent.map(text => text.replaceAll("⁠", ""))).toEqual(blocks.map(text => text.replaceAll("⁠", ""))); + if (antigravityNativeCommands(blocks).length === 0) expect(sent).toEqual(blocks); + }); +}); diff --git a/packages/paperclip-runner/src/drivers/acpx/antigravity-native-commands.ts b/packages/paperclip-runner/src/drivers/acpx/antigravity-native-commands.ts new file mode 100644 index 00000000000..1ba5113cbca --- /dev/null +++ b/packages/paperclip-runner/src/drivers/acpx/antigravity-native-commands.ts @@ -0,0 +1,32 @@ +export const ANTIGRAVITY_NATIVE_COMMANDS: readonly string[] = ["plan", "logout", "usage"]; + +const PYTHON_WHITESPACE = "\\t\\n\\v\\f\\r\\x1c-\\x1f \\x85\\xa0\\u1680\\u2000-\\u200a\\u2028\\u2029\\u202f\\u205f\\u3000"; +const PLAN_COMMAND = `(^|[${PYTHON_WHITESPACE}])/(?=plan(?:[${PYTHON_WHITESPACE}]|$))`; +const LEADING_WHITESPACE = new RegExp(`^[${PYTHON_WHITESPACE}]*`); +const PYTHON_STRIP = new RegExp(`^[${PYTHON_WHITESPACE}]+|[${PYTHON_WHITESPACE}]+$`, "g"); +const STARTS_WITH_WHITESPACE = new RegExp(`^[${PYTHON_WHITESPACE}]`); +const WORD_JOINER = "⁠"; + +export function antigravityNativeCommands(blocks: readonly string[]): string[] { + const found: string[] = []; + if (blocks.some(text => new RegExp(PLAN_COMMAND).test(text))) found.push("plan"); + const joined = blocks.join("").replace(PYTHON_STRIP, ""); + if (joined === "/logout") found.push("logout"); + if (joined.slice(0, 6).toLowerCase() === "/usage" && (joined.length === 6 || STARTS_WITH_WHITESPACE.test(joined.slice(6)))) found.push("usage"); + return found; +} + +export function neutralizeAntigravityNativeCommands(blocks: readonly string[]): string[] { + const result = blocks.map(text => text.replace(new RegExp(PLAN_COMMAND, "g"), `$1${WORD_JOINER}/`)); + if (antigravityNativeCommands(result).length === 0) return result; + const index = result.findIndex(text => leadingWhitespace(text) < text.length); + if (index === -1) return result; + const text = result[index] as string; + const lead = leadingWhitespace(text); + result[index] = `${text.slice(0, lead)}${WORD_JOINER}${text.slice(lead)}`; + return result; +} + +function leadingWhitespace(text: string): number { + return LEADING_WHITESPACE.exec(text)?.[0].length ?? 0; +}