feat(antigravity): /plan selects Plan mode and keeps Antigravity read-only while planning (#22727)

## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - Plan mode lets a person ask an agent for a plan, review it as the
task's Plan document, and accept it before any work starts
> - People who use Google Antigravity agents type `/plan <request>`, as
they do in other agent tools. Paperclip sent that text to the agent, and
#22701 correctly neutralised it, so nothing happened
> - An Antigravity run in Plan mode was also not read-only: the agent
could still edit files and run commands while it "planned"
> - This pull request makes a leading `/plan` in the composer select
Plan mode, and keeps an Antigravity Plan-mode run read-only at its
permission prompt
> - The benefit is that `/plan` with an Antigravity agent gives the
normal Paperclip plan flow (Plan document, accept, then execution on the
same task), and planning cannot change the workspace

## Linked Issues or Issue Description

Refs #22701

**What happened?**
A person wrote `/plan add greeting.txt` to a Google Antigravity agent.
The agent did not plan. In Plan mode the Antigravity agent could still
edit files and run commands.

**What did you expect?**
`/plan <request>` starts Plan mode. The agent researches and proposes a
plan in the task's Plan document. It does not change files until the
person accepts the plan.

**Steps to reproduce**
1. Assign a task to a Google Antigravity agent.
2. Write `/plan Add a file greeting.txt containing hello`.
3. See that the task stays in Auto mode, and that the agent creates the
file.

## What Changed

- Task composer: a leading `/plan` in a comment or in a new task selects
Plan mode and sends the rest of the message without the command. `/plan`
alone only switches the mode. The slash menu offers "Plan". A `/plan`
anywhere else in the message (quoted, pasted, fenced, mid-sentence)
stays ordinary text and does not change the mode. This is the typed form
of the existing Plan mode control, so it works the same for every agent.
- Antigravity runner (`antigravity-plan-mode.ts`, wired in
`acpx-runtime-adapter.ts` and `runtime-host.ts`): when Paperclip runs an
Antigravity task in Plan mode (the existing read-only task policy), the
permission prompt fails closed. It allows only (a) the 1.5.2 server's
built-in research tools (file read, search, directory listing, page
read), named by the exact `Run <tool>?` prompt title, when the reported
kind also matches that tool, and (b) the tools the runner's own
Paperclip bridge registered for this run, on the runner-owned server
named `paperclip`. The provider's reported kind alone never grants a
read, and no other MCP server is trusted, runner-owned or not. It
refuses file edits, terminal commands and everything else. Paperclip's
server applies its Plan-mode rules to its own tools, and the agent
writes the Plan document through them.
- Composer command parsing moved to
`ui/src/components/task-chat/composer-commands.ts`. `/goal` and `/plan`
both use the shared rule. Both submit paths use one `/plan` decision: a
bare `/plan` sends (in Plan mode) only when an attachment can be sent
without text; otherwise it only selects Plan mode. A composer without
Plan mode (the dashboard chat starter) keeps `/plan` as text.
- Follow-up, not in this PR: the Kimi read-only gate
(`kimiReadOnlyPermissionAllowed`) trusts every runner-owned MCP server
by title prefix. It should get the same binding to the Paperclip
bridge's registered tools.
- No change to the #22701 guard. Every `/plan`, `/logout` and `/usage`
that would reach the Antigravity server is still neutralised.
- No change to the Antigravity admission patch, profile or closure
digests. No shared contract change.

### Why not the native `/plan` of Antigravity 1.5.2

I checked the pinned 1.5.2 server and SDK sources and ran it live:

- The server has no plan session mode (only `default`, `auto_edit`,
`yolo`) and no plan config option. Its only route is the `/plan` text
command, which it turns into an SDK slash-command object.
- Live on 1.5.2 (Google sign-in, `gemini-3.8-flash-low`), a task with
`Please /plan this ...` reached the model as
`Please/BuiltinSlashCommandName.PLAN this ...`. The SDK sent the enum's
string form instead of `plan`, so the harness did not enter planning
mode. Over 61 native steps (about 5 minutes) the agent wrote no plan
artifact, ran terminal commands, and searched the file system for that
unknown name. I stopped the run.
- A working native path needs a change inside the runtime (for example
in the owned admission patch), which re-pins the closures for every
platform and needs re-qualification. This PR does not do that.
Paperclip's own Plan mode gives the user-visible result now, with no
re-pin.

### Source of trust for slash commands (reused by `/swarm`)

- `parseLeadingUserCommand(text, allowlist)` in
`packages/shared/src/leading-user-command.ts` is the one rule. It
returns `{ command, argument }` or `null`.
- Trusted text: only what the signed-in user typed and submitted in the
task composer. That is a comment body or the body of a new task.
Conversations (chat) do not use it for `/plan`.
- Never trusted: agent comments, chat or connector messages, API-posted
text, issue text written by someone else, quoted or pasted parts, and
every prompt Paperclip builds for an agent. These stay text, and the
#22701 guard still neutralises any native command in them.
- Inside trusted text, only a command at the very start counts: optional
whitespace, `/name`, then whitespace or the end. The name is exact and
lower-case and must be in the allowlist. Only `plan` is enabled.
Whitespace follows the Antigravity server's Python rules (U+001C-U+001F
count; U+FEFF does not).
- A recognised command becomes a structured action (here: Plan mode). It
never reaches an agent as command text.
- Tests cover: leading whitespace and newlines, a command not at the
start, quoted, fenced, forwarded and wrapped content, a neutralised
command, case, `/planning`, `/plans`, paths and URLs, Python vs
JavaScript whitespace, and the allowlist.

## Verification

- `pnpm --filter @paperclipai/paperclip-runner exec vitest run
src/drivers/acpx/antigravity-plan-mode.test.ts
src/drivers/acpx/acpx-runtime-adapter.test.ts
src/drivers/acpx/antigravity-native-commands.test.ts
src/drivers/acpx/antigravity-admission.test.ts`: 250 passed.
- `pnpm --filter @paperclipai/shared exec vitest run
src/leading-user-command.test.ts`: 8 passed (red first: module missing).
- `pnpm --filter @paperclipai/ui exec vitest run
src/components/task-chat/TaskChatComposer.test.tsx
src/components/MarkdownEditor.autocomplete.test.tsx`: all passed
(TaskChatComposer 155).
- Red before the fix: the adapter test showed an Antigravity Plan-mode
run approved a file write and a terminal command (`allow_once`), and the
four composer `/plan` tests failed. The negative test (a `/plan` inside
the message stays text) passed before and after.
- Runner and UI typecheck pass (`tsc --noEmit`; the UI's only errors are
the existing ungenerated Storybook catalog files).
- `pnpm verify` returned exit 2 (runner files outside the local test
graph), so required CI supplies the broad coverage.
- Live, on THIS branch: a local instance running this branch, Google
sign-in, `gemini-3.8-flash-low`, driven in the browser through the task
composer:
1. `/plan Create a file named plan-proof.txt containing the single line
OK` in a new task: the task was created in Plan mode with the command
removed. Plan run 3 min 34 s, terminal state **succeeded** (the agent
handed in through `paperclip_finish`; run result accepted, waiting for
plan approval). The Plan document and a Confirm / Request changes card
appeared. One `ls -la` was refused by the read-only gate. No file was
written.
2. Request changes ("Name the file plan-proof-2.txt instead."): revision
run 28 s, succeeded. Plan document revision 2 named the new file; a new
Confirm / Request changes card appeared. Still no file.
3. Confirm: execution run 55 s, succeeded; task Done; `plan-proof-2.txt`
contains exactly `OK` plus a newline.
4. Normal task whose text contains a pasted `"we usually /plan things
like this first"`: created in standard mode, text unchanged; run 68 s,
succeeded, Done; `negative-proof.txt` = `NEG`; no refused tool call.
5. Dashboard "Start a chat" box: NOT run live. The box renders only with
an experimental instance setting that is off on this instance, and I did
not change instance settings. A unit test covers it (a composer without
Plan mode keeps `/plan` as text).
6. Stop during a Plan-mode run: the run was cancelled about 1 s after
Stop and did not revive (no new run for over 3 min); no file. Killing
only the native Antigravity server process mid Plan-mode run: the run
failed with a provider error, showed "Continuing automatically", and a
continuation run started 36 s later and settled (succeeded, 3 min 17 s,
response wake). No duplicate comments; the Plan document has one
revision; no file written; the gate refused one shell command in each
run.
- Found live, NOT fixed here: in the recovered run of step 6 the model
settled with "waiting for plan review" but did not open the Confirm card
(in steps 1 and 2 it did). Paperclip creates that card automatically
only from a harness's own plan proposal (Codex, Claude). For Antigravity
it depends on the agent. Recommended follow-up: when a Plan-mode run
settles with a new plan revision and no pending plan confirmation, the
server opens the card itself.
- To be clear: this is not Antigravity's native plan mode. Native plan
mode on runtime 1.5.2 does not work (see above). This PR gives
Paperclip's Plan mode, started by a trusted `/plan`, with the
Antigravity run held read-only.

## Risks

- Low to medium. Plan mode for Antigravity now refuses terminal
commands, so the agent researches with its file read and search tools. A
planner that relied on shell reads must use those tools instead.
- Google Workspace accounts whose admin policy lets terminal commands
run in a sandbox without a prompt skip the permission prompt for
commands. That path cannot be blocked here. Personal Google accounts and
API keys always prompt.
- `/plan` as the first word of a message now selects Plan mode for every
agent. To send the literal text, write `\/plan` or put other text first.

## Model Used

- Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, with tool use (shell,
file edit, browser automation not used), in Claude Code.

## 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 <noreply@anthropic.com>
This commit is contained in:
DottaandClaude Opus 5.5 authored and GitHub committed 2026-11-23 22:33:09 -06:00
1 parent b6f1b7b4af
commit 18aa2b353d
14 files changed
+566 -70

No files matched your search

+1
View File
@@ -3150,3 +3150,4 @@ export * from "./tool-call-progress.js";
export * from "./mcp-skills.js";
export type { TailscaleConnection, TailscaleDeviceLogin } from "./types/tailscale.js";
export * from "./agent-setup-progress.js";
export { parseLeadingUserCommand, type LeadingUserCommand } from "./leading-user-command.js";
@@ -0,0 +1,60 @@
import { describe, expect, it } from "vitest";
import { parseLeadingUserCommand } from "./leading-user-command.js";
const plan = ["plan"] as const;
describe("parseLeadingUserCommand", () => {
it("reads a leading allowlisted command and its argument text", () => {
expect(parseLeadingUserCommand("/plan Add a greeting file", plan)).toEqual({ command: "plan", argument: "Add a greeting file" });
expect(parseLeadingUserCommand("/plan", plan)).toEqual({ command: "plan", argument: "" });
expect(parseLeadingUserCommand("/plan\n\nLine one\nLine two ", plan)).toEqual({ command: "plan", argument: "Line one\nLine two" });
});
it("allows leading whitespace and newlines", () => {
expect(parseLeadingUserCommand(" \n\t/plan go", plan)).toEqual({ command: "plan", argument: "go" });
});
it("uses the native server's whitespace, not JavaScript's", () => {
// Python str patterns treat U+001C-U+001F as whitespace; JavaScript \s does not.
expect(parseLeadingUserCommand("\u001c/plan\u001fgo", plan)).toEqual({ command: "plan", argument: "go" });
expect(parseLeadingUserCommand(" /plan go", plan)).toEqual({ command: "plan", argument: "go" });
// JavaScript \s includes U+FEFF; Python does not, so it is not a separator.
expect(parseLeadingUserCommand("/plan go", plan)).toBeNull();
expect(parseLeadingUserCommand("/plango", plan)).toBeNull();
});
it("ignores a command that is not at the start", () => {
expect(parseLeadingUserCommand("Please /plan this first", plan)).toBeNull();
expect(parseLeadingUserCommand("Context\n/plan this", plan)).toBeNull();
});
it("ignores quoted, pasted, forwarded or wrapped content", () => {
expect(parseLeadingUserCommand("> /plan from a quoted reply", plan)).toBeNull();
expect(parseLeadingUserCommand("```\n/plan\n```", plan)).toBeNull();
expect(parseLeadingUserCommand("`/plan` is a command", plan)).toBeNull();
expect(parseLeadingUserCommand("---------- Forwarded message ----------\n/plan x", plan)).toBeNull();
expect(parseLeadingUserCommand("<untrusted>/plan x</untrusted>", plan)).toBeNull();
expect(parseLeadingUserCommand("\\/plan ordinary text", plan)).toBeNull();
expect(parseLeadingUserCommand("⁠/plan neutralised", plan)).toBeNull();
});
it("matches the exact lower-case name only", () => {
expect(parseLeadingUserCommand("/PLAN x", plan)).toBeNull();
expect(parseLeadingUserCommand("/Plan x", plan)).toBeNull();
expect(parseLeadingUserCommand("/planning notes", plan)).toBeNull();
expect(parseLeadingUserCommand("/plans", plan)).toBeNull();
});
it("does not read a path or URL as a command", () => {
expect(parseLeadingUserCommand("/plan/2026/notes.md", plan)).toBeNull();
expect(parseLeadingUserCommand("/plan?draft=1", plan)).toBeNull();
expect(parseLeadingUserCommand("https://example.com/plan x", plan)).toBeNull();
});
it("accepts only allowlisted commands", () => {
expect(parseLeadingUserCommand("/swarm build it", plan)).toBeNull();
expect(parseLeadingUserCommand("/logout", plan)).toBeNull();
expect(parseLeadingUserCommand("/swarm build it", ["plan", "swarm"])).toEqual({ command: "swarm", argument: "build it" });
expect(parseLeadingUserCommand("/plan x", [])).toBeNull();
});
});
@@ -0,0 +1,35 @@
/**
* The one rule for reading a slash command as a real user request.
*
* Source of trust: the caller passes only text the signed-in user typed and
* submitted themselves in Paperclip's task composer (a comment body, or the
* body of a new task). Never pass agent-authored text, chat or connector
* messages, API-posted text, issue descriptions written by someone else, or
* any prompt Paperclip assembles for an agent. Those stay ordinary text, and
* harness guards (for example Antigravity's native-command neutraliser) keep
* them from acting as commands.
*
* Within that text, only a command at the very start counts: optional
* whitespace, then `/name`, then whitespace or the end. The name is exact and
* lower-case, and must be in the caller's allowlist. Whitespace follows the
* Python rules the Antigravity server uses (U+001C-U+001F count, U+FEFF does
* not), so this never accepts a command boundary the server would not.
*/
export interface LeadingUserCommand<Name extends string = string> {
command: Name;
/** The rest of the message, trimmed. Empty when only the command was sent. */
argument: string;
}
const WHITESPACE = "\\t\\n\\v\\f\\r\\x1c-\\x1f \\x85\\xa0\\u1680\\u2000-\\u200a\\u2028\\u2029\\u202f\\u205f\\u3000";
const LEADING = new RegExp(`^[${WHITESPACE}]*\\/([a-z]+)(?=[${WHITESPACE}]|$)`);
const TRIM = new RegExp(`^[${WHITESPACE}]+|[${WHITESPACE}]+$`, "g");
export function parseLeadingUserCommand<Name extends string>(
userAuthoredText: string,
allowlist: readonly Name[],
): LeadingUserCommand<Name> | null {
const match = LEADING.exec(userAuthoredText);
if (!match || !(allowlist as readonly string[]).includes(match[1]!)) return null;
return { command: match[1] as Name, argument: userAuthoredText.slice(match[0].length).replace(TRIM, "") };
}