Files
PaperClipAI/packages
DottaandClaude Opus 5.5 7d26bdaa42 feat(antigravity): verified Antigravity CLI route for native swarm (inert) (#22731)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - Google Antigravity agents run through the Paperclip Runner's ACP
driver, on the registry ACP server 1.5.2
> - Google's native `/swarm` (a coordinator that starts helpers and a
verifier) exists only in the Antigravity CLI (`agy acp` 1.5.15), which
#22728 pinned and provisions
> - The CLI is a signed binary, so the registry server's owned admission
patch cannot exist there. Paperclip needs another way to verify the
session before a billable swarm starts, and a governed way to run, stop
and finish it
> - This pull request adds that CLI route to the Runner: a verified ACP
client, the checks it does in place of the patch receipt, process setup,
failure classification and a deterministic fake CLI for tests. Nothing
selects the route yet, so this PR does not change behavior
> - The benefit is that the next PR only has to add trusted `/swarm`
detection and an experimental flag

## Linked Issues or Issue Description

Refs #22728, #22701, #22727

**Subsystem affected**
Paperclip Runner, ACP driver, Google Antigravity.

**Problem or motivation**
A user who writes `/swarm <request>` to a Google Antigravity agent
should get a real native swarm in the task's workspace. The registry ACP
server does not offer `/swarm`. The Antigravity CLI does, but its
permission prompts for helpers never reach an ACP client, its model
selector groups models into a family plus a thinking level, a turn can
end while helpers still run, and some provider refusals arrive as
ordinary text that ends the turn "successfully".

**Proposed solution**
Run a trusted swarm turn on the pinned CLI through a small driver-owned
ACP client that verifies every setting it depends on, confines helpers
to the task workspace through the CLI's `auto` mode, waits for helpers,
checks the workspace after the turn, and reports typed failures in plain
language.

## What Changed

- `antigravity-swarm-guard.ts`: the checks that replace the registry
server's admission receipt. The driver verifies and records:
- agent identity and version from `initialize` equal the pinned CLI
(`Antigravity ACP Server` 1.5.15), and the CLI accepts
`systemPrompt.append`;
- the `session/new` request uses the task workspace as `cwd`, carries
Paperclip's instructions, and passes exactly one MCP server: the
runner-owned Paperclip bridge;
  - session mode reads back as `auto` after `session/set_mode`;
- model family plus thinking level read back as the agent's configured
model after `session/set_model` (for example `gemini-3.8-flash` + `low`
for `gemini-3.8-flash-low`);
- none of those change later in the session; a helper started with
workspace `share` or `branch` stops the swarm.
Any difference fails closed with a typed error and a plain message. A
sign-in without `auto` mode is reported as "swarm not available".
- `antigravity-swarm-runtime.ts`: an `AcpxRuntimePort` for the CLI
route.
- One fresh session per run. It never calls `session/load`, so Retry
after a lost process starts a fresh swarm in the same workspace.
- Prompts with `/swarm <task>` (the route is reached only through the
trusted mode). At most one swarm per run.
- Does not settle on the first `end_turn` while helpers may still run:
when helpers were started and the coordinator did not wait on the board
afterwards, it sends one bounded "wait for the helpers" follow-up (20
min default; timeout is a typed failure).
- Lists the task folder before and after the turn (asynchronous, bounded
on every visited entry, stopped with the turn, skipping `.git`,
`node_modules`, `.venv`, `__pycache__`) and shows the real changes. It
never infers required files from what helpers or the coordinator say
(helpers can misreport). Done still requires the hand-in through
Paperclip's finish tool, which the server's completion contract
enforces.
- Stops the swarm when a visible tool call would change a path outside
the task folder (`antigravity-swarm-paths.ts`): file-tool locations and
path arguments, and shell write targets (redirects, `tee`,
`cp`/`mv`/`ln` destinations, `rm`, `mkdir`, `touch`, `sed -i`, `dd
of=`), resolved relative to the task folder with `..`, `~`, `$HOME` and
symlinks of existing parents. This is a best-effort **detector, not a
boundary**: it turns visible, unambiguous outside writes into a clear
failure, uses a quote-aware lexer, and yields no finding for anything
ambiguous (command substitution, heredocs, `eval`, `cd`, interpreters,
unknown variables), so it never stops a correct swarm on a guess. It
does not prove confinement.
- Stop is installed before the first await of a turn and re-checked
before every prompt; a Stop during admission retires the CLI at once. A
test injects Stop at each await point (launch, initialize, session/new,
set_mode, set_model, workspace listing, helper wait).
- A saved conversation from the other Antigravity route (swarm ↔
ordinary turn) is refused as `ANTIGRAVITY_SAVED_STATE_INCOMPATIBLE`, the
existing typed refusal that makes the server open a fresh conversation
instead of showing Retry. So an ordinary follow-up after a swarm, a
later second `/swarm`, and Retry after a killed swarm all start a fresh
session.
- Approves only Paperclip's own tool server at a permission prompt;
every other prompt is outside the task folder in `auto` mode, so it is
refused and shown as "Blocked: …". Helper actions that the CLI timed out
are shown as blocked.
- Stop sends `session/cancel`, then retires the CLI's process group and
confirms no helper process survives.
- Usage is the coordinator's reported total, recorded as soon as each
prompt result arrives (also for failed or stopped turns), labelled as
including the helpers and not itemised.
- A settings change outside a turn becomes a typed failure that fails
admission or the next turn and retires the CLI process group; no handler
error can escape into the event loop.
- Refusals that arrive as text (402 credits, 429 quota, sign-in) become
typed provider failures.
- `antigravity-swarm-presentation.ts`: turns the coordinator's `swarm` /
`read_board` / `post_message` calls into steps such as "Started helper
writer-a: Write a.txt …", "Checked on the helpers", and drops
terminal-only hints. No raw ids.
- `antigravity-swarm-route.ts` and small hooks in `runtime-host.ts`,
`acpx-runtime-adapter.ts` and `provider-mode.ts`: the `antigravity`
provider mode accepts only `swarm`; for that mode the host installs the
pinned CLI (`resolveAntigravityCliLaunch` with `--gemini-dir <run
credential home>/antigravity-cli`, the stable endpoint
`https://cloudcode-pa.googleapis.com`, `--disable-telemetry`,
self-update off), skips the registry credential staging, and refuses
API-key connections and unpinned platforms with a plain message.
- `test-fixtures/antigravity-cli/fake-agy-acp.mjs`: a deterministic fake
`agy acp` that replays the spike's message shapes (success, live helpers
at `end_turn`, hang, blocked, misreport, workspace escape, cancel with a
real helper process, process death, 402 and 429 refusals as text,
identity/mode/model mismatches).

### Host policy inputs on the swarm route

| Input the registry route honours | Swarm route |
|---|---|
| Read-only (Plan mode) task policy | Refused before the CLI starts:
"Swarm is not available while planning" |
| Saved session / `restoringSession` (resume) | Refused as
saved-state-incompatible: the server opens a fresh conversation; a swarm
never reloads |
| Runner-owned Paperclip tool bridge | Enforced: the only MCP server,
verified in `session/new` |
| Other assigned tool servers (stdio MCP bindings) | Refused with a
plain message, never silently dropped |
| Delegation tools | (follow-up PR) removed from the bridge catalog for
a swarm turn |
| Workspace root (`cwd`), `assertWorkspaceHeld` | Enforced: `cwd` is the
task workspace, re-asserted at spawn; helpers must use `inherit` |
| Additional directories | Not passed (none are granted) |
| Credential/env scoping | Private `--gemini-dir`; registry credentials
and API keys removed from the launch environment; macOS HOME is the OS
user's home for the keychain sign-in |
| Provider-lifetime fence, process group | Enforced: verified command
lease with the lifetime fence; Stop and close retire the whole group |
| Permission mode | Replaced by the verified `auto` session mode; other
prompts are refused and shown as blocked |
| Model and thinking level | Enforced and read back
(`session/set_model`), checked for later changes |
| Abort signal | Honoured during admission and turns |

## Verification

- `pnpm --filter @paperclipai/paperclip-runner exec vitest run
src/drivers/acpx/antigravity-swarm-guard.test.ts
src/drivers/acpx/antigravity-swarm-presentation.test.ts
src/drivers/acpx/antigravity-swarm-runtime.test.ts
src/drivers/acpx/antigravity-swarm-route.test.ts`: 36 passed. Each file
was red first (module missing); the route-selection tests were also
shown red with the hooks reverted (2 failed) and green with them.
- `pnpm --filter @paperclipai/paperclip-runner exec vitest run
src/drivers/acpx/`: 117 files, 2017 passed, 9 skipped.
- `tsc -p tsconfig.json` and `tsc -p tsconfig.test.json` for the runner
package: no errors in the changed files.
- `pnpm verify` asked for broader coverage (the fixture is a broad
input); required CI supplies it.
- Live, no product code: against the real CLI 1.5.15 with the owner's
existing sign-in, `session/new` accepted the Paperclip bridge as an HTTP
MCP server with a bearer header (it called `initialize` and
`tools/list`), and `session/set_model gemini-3.8-flash-low` read back as
`gemini-3.8-flash` + `low`. One prompt returned `⚠ RESOURCE_EXHAUSTED
(code 429)` as text with `end_turn`; that shape is now a test case.
- Not run live: a full swarm through Paperclip. That proof belongs to
the follow-up PR, which turns the route on.

## Risks

- Inert: no server code sets the `swarm` mode yet, so no turn reaches
this route.
- When enabled: helpers act under Antigravity's `auto` mode. What
confines them is the CLI's own policy: file-tool writes outside the
workspace are blocked (60 s timeout, seen in the spike), and its shell
sandbox allows the workspace **plus temp directories**. Helper tool
calls never reach an ACP client, so Paperclip cannot see or block a
helper's shell command, and helper approvals are not possible.
- **Paperclip does not confine the CLI process tree on a local
computer.** Paperclip's local process sandbox
(`adapter-utils/local-process-sandbox.ts`) is used only by the classic
Claude and Codex local adapters, not by Runner ACP harnesses, so it does
not apply here on macOS or Linux. The outside-path check covers only the
coordinator's visible calls. This is why the feature stays experimental,
off by default, local only, and why the activity log says helper actions
are auto-approved.
- On macOS the CLI reads its Google sign-in from the login keychain
through the real HOME, so this route uses the sign-in of the CLI on the
computer, not Paperclip's stored Google connection. All CLI state stays
in the private `--gemini-dir`.
- Google's consumer terms have a clause about third-party tools that
access the service. A legal read is pending. This PR does not claim
compliance.
- Usage under-reports nothing that Google reports, but it cannot be
split per helper.

> For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and
discuss it in `#dev` before opening the PR. Feature PRs that overlap
with planned core work may need to be redirected — check the roadmap
first. See `CONTRIBUTING.md`.

## Model Used

- Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, with tool use (shell,
file edit) 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
- [ ] I have updated relevant documentation to reflect my changes (docs
and the qualification ledger come with the follow-up PR that enables the
route)
- [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
- [ ] 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>
2026-11-23 23:37:57 -06:00
..