Repository navigation
Conversation
Antigravity was treated as a rules-only target on the assumption that it
has no programmatic hook. It does: `agy` dispatches a `PreToolUse`
lifecycle event and honours a handler that rewrites the tool call. The
contract ships inside the binary itself:
strings $(which agy) | sed -n '/Lifecycle Hooks/,/PostInvocation Contract/p'
Until now `rtk init --agent antigravity` only wrote a Markdown rule
asking the model to type `rtk` itself, so savings depended on the model
remembering an instruction.
- `rtk hook antigravity` parses the camelCase `toolCall.args.CommandLine`
payload and answers with a top-level `overwrite.CommandLine`, which
Antigravity shallow-merges into the tool call before executing it.
- `rtk init [-g] --agent antigravity` installs a real `hooks.json` into
the workspace root (`.agents/`) or the global one
(`~/.gemini/config/`), claiming only the `rtk` namespace so a user's
own hooks survive. `-g` was previously rejected outright.
- Everything RTK does not deny answers `allow`. `Host::Antigravity`
defers permissions to the host, so every command reaches Defer/Ask;
answering `ask` there would add an approval prompt that did not exist
before RTK was installed and would hard-fail headless runs. `allow`
cannot widen permissions: Antigravity re-checks its own rules against
the rewritten call afterwards.
- Because that check runs *after* the rewrite, an existing
`command(git status)` allow-rule stops matching once RTK prefixes the
command. `init` now warns about this and the README documents it.
Verified end-to-end on Antigravity CLI 1.1.27: a headless `agy --print`
run told to execute `git status`, with no mention of rtk, produced a
`rtk git status` row in `rtk gain --history`.
README, the supported-agents guide and the awareness note all described Antigravity as a prompt-level integration with no rewrite guarantee. It now has one, plus the post-rewrite permission caveat users will hit.
📊 Automated PR Analysis
SummaryAdds a native lifecycle hook for Google Antigravity CLI, replacing the previous assumption that Antigravity has no programmatic hook. It implements Review Checklist
Analyzed automatically by wshm · This is an automated analysis, not a human review. |
|
|
DUPLICATE, recommend closing — #3711 is the survivorThank you for this: the Where the two differ, and why #3711 is the one being taken forward:
Two of your judgment calls are the same in #3711 and were checked there: The two things you deliberately left out are tracked: the "No hook installed" warning for non-Claude agents is #913 (the Antigravity arm is noted there now), and the Codex The recommendation is to close this one in favour of #3711; the CLA is also unsigned here, which would have to be settled before anything could merge from this branch. If you see something in this design that #3711 gets wrong, please say so on #3711. |
Summary
hooks/antigravity/README.mdandsrc/hooks/init.rsstate that Antigravity has no programmatic hook, sortk init --agent antigravityonly writes a Markdown rule asking the model to typertkitself. Antigravity does have one — this PR adds it.rtk hook antigravity: reads thePreToolUsepayload, answers withoverwrite.CommandLine, which Antigravity shallow-merges into the tool call before it executes.rtk init [-g] --agent antigravitynow installs a realhooks.jsoninto the workspace root (.agents/) or the global one (~/.gemini/config/), merging into any existing file.-gwas previously rejected with "Antigravity is project-scoped".Why I opened this
I use Antigravity CLI daily for cheap agentic work and wanted RTK's savings there. Nothing was being intercepted, so I went looking and found the assumption in your source rather than a bug.
Antigravity ships its own hook documentation inside the
agybinary. It is reproducible on any machine with Antigravity installed:Relevant excerpts (verified on
agy1.1.27, macOS arm64):Two changelog entries in the same binary confirm both roots: one fixes
/hookswriting to~/.gemini/antigravity-cli/hooks.json"instead of the shared~/.gemini/config/hooks.json", another fixes workspace-local hooks in<workspace>/.agents/hooks.jsonnot loading after trusting a folder.Evidence it works end-to-end
Not just unit tests — a real headless session that was never told about RTK:
The model typed
git status; the hook rewrote it.Two judgment calls I'd like your read on
1. Everything not denied answers
allow.Host::Antigravitycarries no rules of its own (likeHost::Vibe), so every command lands onDefer/AskRewrite. Mirroringrun_gemini_inner_impl'sask_userlooked right, but the built binary then answered{"decision":"ask"}togit status— that adds an approval prompt that did not exist before RTK was installed, and hard-fails headless runs.allowcannot widen permissions here, and that is measured rather than assumed: the headless run above was denied while the hook answeredallow, because Antigravity re-checks its ownpermissionsrules against the rewritten call afterwards. Soallowreads as "RTK has no objection", not "skip the prompt". Happy to move this behind a config toggle if you'd rather.2. The post-rewrite permission check is a real user-facing gotcha. Because Antigravity evaluates
permissions.allowagainst the modified tool call, an existingcommand(git status)rule stops matching the moment RTK prefixes the command — a surprise prompt interactively, a hard denial in CI.PreToolUseoutput does supportpermissionOverrides, which would paper over it, but emitting that unconditionally means RTK auto-granting permission for commands the user never approved. I chose not to:rtk initprints a warning and the README documents it. Your call if you'd prefer the override.Scope
Feature + its own docs only. Two things I deliberately left out, happy to send separately:
src/hooks/hook_check.rs::status()only inspects Claude Code, sortk gainwarns "No hook installed" at any user whose agent is Antigravity, Gemini, Cursor or Droid. Independent defect, cross-cutting fix, wrong to bundle here.hooks/codex/README.mdcarries the same "no programmatic hook" claim, andcodex features listreportshooks stable truewith aPreToolUseschema that already matches whatrtk hook claudeemits (hookSpecificOutput+updatedInput). Worth its own PR.Test plan
cargo fmt --all && cargo clippy --all-targets -- -D warnings && cargo test— clean; 3406 tests pass, 13 of them newrtk hook antigravityagainst real payloads — rewrite, passthrough for non-rewritable commands, non-run_commandtools ignored, idempotent on already-prefixed input, UTF-8 BOM toleratedrtk init --agent antigravitywrites a valid.agents/hooks.json; a pre-existing foreign hook namespace in that file survives (covered bytest_antigravity_hook_preserves_foreign_namespaces)initdoes not duplicate handlers