Skip to content

Give Antigravity NodeSpace hooks, and run the harness scenario with them (closes #3777) - #3802

Merged
malibio merged 4 commits into
mainfrom
issue-3777-antigravity-plugin
Oct 13, 2026
Merged

malibio merged 4 commits into
mainfrom
issue-3777-antigravity-plugin

Conversation

@malibio

@malibio malibio commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator

Refs #3777.

What this adds

  • plugins/antigravity/hook.ts: Antigravity's hooks over the shared session module, one command per event, with the conversation's state in <NodeSpace home>/.nodespace/antigravity-sessions/<id>.json.
    • SessionStart injects the section (project, orientation, consent rules, skill list).
    • PreInvocation numbered 0 (the first model call after a user message; Antigravity has no user-prompt event) compares the skill list and lifts a refusal; a call that follows a tool result does neither.
    • PreToolUse answers deny with the reason, or allow (which leaves the permission system to decide, checked live: a command that needs a permission is still denied in print mode).
    • PostToolUse answers {} and reads a nodespace command's output from the conversation transcript; a note for the agent waits for the next PreInvocation.
  • plugins/shared/hook-process.ts: what the hooks of a harness that runs a command per event share (host, state file, stdin and stdout). The Codex hook uses it too, so the plumbing is not copied.
  • The installer registers one keyed hook (nodespace) in ~/.gemini/config/hooks.json, the event named in each handler's command, and removes it on uninstall. Antigravity needs no trust step; the installer says nothing about one.
  • The CLI names a write's journal after ANTIGRAVITY_CONVERSATION_ID when no plugin variable is set, as it does for CODEX_THREAD_ID.
  • The scenario driver registers the installer's hooks from the checkout's .agents/hooks.json (the user's global hooks file is untouched); ANTIGRAVITY_BASELINE=1 leaves them out.

Facts found by running Antigravity 1.3.4 with a logging hook

  • A hook's injectSteps systemMessage is {"systemMessage": {"systemMessage": "..."}} and reaches the agent; the transcript records it.
  • invocationNum resets to 0 for each user message; SessionStart does not fire again when a conversation is continued.
  • The transcript at transcriptPath holds each command's output at the step PostToolUse names.
  • ANTIGRAVITY_CONVERSATION_ID equals the hooks' conversationId.

Tests

bun run --cwd packages/skill test 302 pass (a process-level suite over a fake nodespace, like Codex's), bun run test:scripts 1548 pass, scripts and skill lint and typecheck clean. The Rust change (the journal's environment variable list) cannot build in a fresh worktree here; the gate builds it.

🤖 Generated with Claude Code

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pragmatic code review: initial review (verdict: COMMENT; items 1-3 should be fixed before merge)

Summary

A clean, well-commented change. The shared extraction is faithful: I diffed Codex's hook.ts against main and the host, state file, prune, save/load and run moved without a behavioural change, and Codex's handlers read the same. needsTrust: true on Codex preserves its trust notice. The Antigravity hook models the harness differences (event as argv, invocationNum 0 as the prompt, transcript for output, deferred note) sensibly, and the test file covers the main flows. Three things can lose user data or break a tool call and are worth fixing; the rest is hardening.

Requirements

  • install registers hooks, uninstall removes them (but see item 1)
  • project, orientation, section at SessionStart / first model call
  • skill list change announced on next invocation 0
  • refusal on PreToolUse, lifted on the next user message
  • attribution via ANTIGRAVITY_CONVERSATION_ID journal fallback
  • trust settled (none; README says so, installer prints nothing more)
  • live scenario run: pending by the author, not failed here

Findings

Important (fix before merge)

  1. The nodespace key is not checked for ownership. installer.ts (syncHooksFile keyed branch, removeHooksFile keyed branch)

    • Install replaces whatever is under nodespace with ours; uninstall deletes nodespace and, if nothing else is left, deletes the file. A user's own hook named nodespace is silently overwritten and then deleted. The non-keyed path avoids this by recognising handlers by the script path; the keyed path does not.
    • Fix: only replace or remove the key when the existing value is absent, or its handlers' commands include quotedPath(script) (the named predicate already in hooksInPlace). Otherwise warn and leave it, as for an unreadable file. Principle: an installer owns only what it can identify as its own. Add tests for "a foreign nodespace key is kept on install and on uninstall".
    • Related: removing the whole file when only our key remains is fine, but compare against "empty or only ours" rather than others having no keys, so a file we did not create is not deleted just because it held one key that was ours by name.
  2. Hooks answer nothing on any failure, but two events must always answer. hook.ts handle (early return on a bad conversationId) and hook-process.ts run (the catch swallows everything)

    • Per the facts established: PreToolUse must answer a decision (and {} denies), PostToolUse must answer exactly {}. Silence is unverified territory for both: an unwritable state dir (save throws), a session.start that exceeds the 15 s PreToolUse/PostToolUse timeout on a lost-state conversation, a malformed payload, or a non-matching id all produce an empty stdout. At best that is host-defined, at worst it denies the call or aborts the tool, which is exactly what a "must not stop its harness" hook promises not to do. The test "says nothing for an event with no usable conversation id" pins the risky behaviour.
    • Fix: have the Antigravity entry emit the event's safe answer ({decision:'allow'} for PreToolUse, {} for PostToolUse, {} otherwise) from a finally/catch around handle, and test it. Also consider that ensureStarted() in PostToolUse/PreToolUse can run start (several CLI calls) inside a 15 s budget; either lower its cost or let the timeout failure fall into the safe answer above.
  3. The section is told twice when a task launched the session. hook.ts PreInvocation, const note = await session.prompt()

    • prompt() returns the launch's opening text as part of note (it is joined(handed, note)). SessionStart already injected section(), but the first prompt sees a truthy note and appends section again (note ? note + section). The isStartingNow guard only protects the no-note branch. The check should be "the skill list changed" rather than "any note", e.g. have the hook compare listVersion/skills from the snapshot before and after, or have the session expose whether the list changed. Add a test with a launched session (opening set).

Improvements

  1. Transcript read is O(file) per nodespace command, and one bad line empties the result. hook.ts outputOf

    • readFile of the whole transcript, split, and JSON.parse of every line up to the match, for every PostToolUse of a nodespace command. In a long session with a large transcript and many nodespace calls this is quadratic and competes with the 15 s timeout. A single unparseable line (a partially flushed last line is plausible) throws into the catch and loses the output for that call, though the target step may be before it.
    • Fix: skip bad lines individually; test line.includes('"step_index":N')-style prefix before JSON.parse (or scan from the end, since stepIdx is the newest step); cap what is kept from the file. Also confirm (it is unverified) that the transcript is flushed before PostToolUse fires, otherwise the read can silently see nothing; an assertion in the live run would settle it.
  2. invocationNum === 0 is a strict equality on an unvalidated field. hook.ts PreInvocation

    • If the field is missing or a string the refusal is never lifted (the user's message cannot clear it) and the section/skill note is never delivered, with no diagnostic. Lifting on "not a number > 0" would fail toward the user. At minimum log under NODESPACE_HOOK_DEBUG. Also note a stale pendingNote (from the final tool call of the previous message) is delivered at the next message's invocation 0; Codex clears it on prompt (pendingNote = null). Decide deliberately.
  3. hooksInPlace does not check the event argument. installer.ts keyed branch of hooksInPlace

    • It only checks that each handler names the script, so a handler registered under PreToolUse whose command ends PostToolUse reports "installed". Compare the full hookCommand(script, event) string. This also makes the status result reflect a Windows/quoting change after an upgrade.
  4. Windows / shell form. hookCommand is POSIX sh (if command -v ...; exec ..., single-quoted path). That is the existing Codex form, but Antigravity's hook runner shell on Windows is not established here. The harness driver deliberately uses plain bun "path". Either confirm Antigravity runs hook commands through sh on every platform it ships on, or gate the Antigravity plugin to platforms where that holds and say so in the README. I did not find a test for the quoted-path-with-apostrophe case on the keyed path (quotedPath is covered for Codex).

  5. Concurrent hooks lose a note. The load-modify-save of the state file is last-writer-wins; two tool calls dispatched together (Pre of one, Post of another) can overwrite a pendingNote that the other just set. save already skips no-op writes, but a note-carrying write can still lose. Low probability and the Codex path has the same shape; worth one line in the README's caveats rather than code.

Nitpicks

  • Nit: journal.rs test uses the string literals "CODEX_THREAD_ID" / "ANTIGRAVITY_CONVERSATION_ID"; the constant array is private but exported index would avoid drift. A test that Codex-before-Antigravity precedence holds when both are set would pin the ordering.
  • Nit: hook.ts doc comment on outputOf says "the step that follows the model's call", but the code matches step_index === stepIdx; align the wording with the established fact.
  • Nit: prompt() always rebuilds section, so session.section() is non-null after every prompt; a short comment next to isStartingNow saying that is why the guard exists would help the next reader.
  • Nit: README says a daemon that is not running means "nothing else is said", but SessionStart for an unreachable daemon still saves state with isReached: false so the first prompt retries; worth stating, it is a feature.

Test quality

Good coverage of the happy paths and the installer round trip. Missing: foreign nodespace key (item 1), empty/invalid output on failure (item 2), launched session duplicate section (item 3), malformed transcript line and large transcript (item 4), non-numeric/missing invocationNum (item 5). Tests that assert silence for an invalid id should be revisited with item 2.

Docs

README is accurate and useful. node-types / sync-boundary rules are not touched. No dead_code/lint suppressions added.

@malibio

malibio commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator Author

Pragmatic code review: re-review of 3a7e298 and 73aacb8 (verdict: COMMENT)

All six earlier findings are addressed correctly. No blockers. One real bug in the new ownership check (escaped paths) and three smaller robustness points worth taking in this PR.

Earlier findings

  1. Keyed-hook ownership (installer.ts): addressed for the common case. syncHooksFile and removeHooksFile both refuse a key whose entry does not name our script, with a warning, and the tests cover install, status and uninstall. See Improvement 1 for a defect in how ownership is tested.
  2. Always answers (hook.ts main(), SILENCE): addressed. answer is called last in every branch, after save, so an exception cannot follow a partial answer; isAnswered is set before emit, so a throwing emit cannot double-answer. An invalid session id, unreadable state and unwritable state all end in SILENCE (allow for PreToolUse, {} otherwise). The test covers both shapes.
  3. Section told once (told): addressed. told is the snapshot's section when it was reached, else null, so an unreached or lost state tells the section (correct), a launched session's opening note is not followed by a repeat, and a changed list differs from told and gets the section. The launched-then-revised test covers both directions. section only moves in start() and prompt(), so the snapshot's value is what the agent was last told.
  4. Transcript scan: addressed in effect; see Improvement 2 for the coupling it adds.
  5. Strict invocationNum === 0, pendingNote cleared at a user message: addressed and tested (undefined and '0' both stay refused). See Improvement 3 for what the clearing also drops.
  6. hooksInPlace names the event: addressed. The command is ... exec bun '<script>' <event>, so `${quotedPath(script)} ${event}` matches what hookCommand writes. Tested by rewriting one handler's event.

Suggested improvements

  1. isOurKeyedHook mis-detects ownership for a path JSON escapes (packages/skill/src/installer.ts, isOurKeyedHook). It tests JSON.stringify(entry).includes(quotedPath(script)). JSON.stringify doubles backslashes and escapes ", while quotedPath is the raw text that sits in command. For a script path with a backslash (a Windows install root) or a double quote, our own hook is judged foreign: install warns and never registers, and uninstall leaves it. The other sites (hooksInPlace, the line-868 filter) compare against handler.command, which is unescaped, so the three disagree. Test the handler commands instead, as hooksInPlace does (walk each event's handlers, grouped or not, and check command.includes(quotedPath(script))), and add a test with a backslash in the plugin root. The README says the Windows shell is unchecked, but the installer will run there.
  2. outputOf now depends on key order and spacing (hook.ts). line.startsWith('{"step_index":N,') skips every line where step_index is not first or the serializer writes a space. The failure is silent: no output is read, fetched never records the skills the agent opened, and the next "what changed" note over-reports. An order-tolerant version keeps the cheap skip: line.includes("step_index":${index},) as the prefilter, then JSON.parse and confirm step.step_index === index (already done).
  3. Clearing pendingNote at a user message also drops the item-governance note (hook.ts, PreInvocation). pendingNote holds two kinds of note. The skill-list note is superseded by the prompt's fresh readList(), as the comment says. The note checkItem returns ("What governs the item ... changed since you read it") is not: prompt() re-reads only the list, and checkItem has already moved the baseline (item = now), so after the clear nothing ever tells the agent to re-read the context. Either keep notes that come from beforeTool and drop only the list-derived one, or re-run the item check on the prompt path. If dropping is intended, the comment should say so, because it reads as covering only the list.
  4. A refusal can be lifted by a failed save (hook.ts, PreToolUse). save runs before answer. If it throws (full disk, read-only state dir), the catch in main() answers allow even though beforeTool produced a deny; the README documents this fail-open. The unpersisted state usually re-derives the refusal on the next call, but only if the check runs again against the saved baseline. A small guard keeps the verdict: wrap save in its own try/catch and answer from verdict regardless. The same ordering applies to PreInvocation at lower stakes.

Nitpicks

  • Nit: isOurKeyedHook identifies ownership by the exact current script path, so an install whose plugin root moved is treated as foreign and is not updated. The warning text ("did not write") will confuse that user; a clause naming the path mismatch would help.
  • Nit: CHOOSES_SECOND hard-codes the scenario's task title (it matches scripts/eval/harness/scenario.ts:301 today) and Antigravity's prompts now differ from the other harnesses', which weakens cross-harness comparison. A comment pointing at scenario.ts as the source of the title keeps them in step.

Live evidence

The Antigravity 1.3.4 run (four cases passing, including the live refusal "tool call denied by pre-tool hook: [NodeSpace] The item ... changed under it") covers the PreToolUse deny wire shape, the allow answer and hook registration end to end. It does not exercise the told comparison on a real launched session or a Windows-style path, so Improvements 1 and 3 are not covered by it.

Net positive and mergeable after Improvement 1; items 2 to 4 are small and worth folding in.

@malibio

malibio commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator Author

Re-review addressed (8c438e6)

Addressed

  • Keyed-hook ownership walks the handlers' commands (as hooksInPlace does), so an escaped path is recognised and a path mentioned in a foreign hook's other fields is not taken for ours; a test pins the second.
  • The transcript's step is found by "step_index":N anywhere on the line, then parsed and checked, so key order and spacing do not matter.
  • A state write that fails no longer lifts a refusal: save is tolerated on its own and the answer comes from the verdict; a test makes the state folder read-only and still gets deny.
  • A note a tool call found is told with the next model call, the call after a user message included, once; it is no longer dropped there. A test pins it.

Not changed

  • A moved plugin root is read as foreign by the exact-path ownership rule, and the warning says the hook was not written by this installer: a reinstall from a moved root names the script it would write, which is not the one in the file. Acceptable under the no-migration rule; the user removes the key.
  • CHOOSES_SECOND names the scenario's task by title: the fixture and the driver are one folder, and the title is a constant of the fixture (scenario.ts).

Live: a scenario run of Antigravity 1.3.4 with the hooks passed all four cases. The first prompt's choice and the second prompt's task name are the user's choice per the skill's first step; the watch interval is 3 seconds for this driver because the agent reads the finished task within seconds. The refusal was seen live: tool call denied by pre-tool hook: [NodeSpace] The item ... changed under it: it went from version 1 to 4. Skill tests 310 pass; the merge gate's dry run passed on the earlier head.

Re-Review Decision

Decision: NO RE-REVIEW NEEDED

Rationale: Each change is the re-review's own suggestion, narrow, and pinned by a test; the hook's answer paths are the ones the first review already read.

@malibio malibio changed the title Give Antigravity NodeSpace hooks, and run the harness scenario with them (refs #3777) Give Antigravity NodeSpace hooks, and run the harness scenario with them (closes #3777) Oct 13, 2026
malibio and others added 4 commits October 13, 2026 22:06
…hem (closes #3777)

- plugins/antigravity/hook.ts: one command per event over the shared session
  module. SessionStart injects the section, the first PreInvocation after a
  user message (invocationNum 0) compares the skill list and lifts a refusal,
  PreToolUse refuses with a decision, PostToolUse answers {} and reads a
  nodespace command's output from the conversation transcript.
- plugins/shared/hook-process.ts: what the hooks of a harness that runs a
  command per event share (host, state file, stdin/stdout); the Codex hook
  uses it too, and the process plumbing is no longer copied.
- The installer registers one keyed hook in ~/.gemini/config/hooks.json,
  names the event in each handler's command, and needs no trust step.
- The CLI names a write's journal after ANTIGRAVITY_CONVERSATION_ID when no
  plugin variable is set, as it does for CODEX_THREAD_ID.
- The scenario driver registers the installer's hooks from the checkout's
  .agents/hooks.json; ANTIGRAVITY_BASELINE=1 leaves them out.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…script scan (refs #3777)

- A hook of the user's with the key nodespace is neither replaced on install
  nor removed on uninstall; the installer warns and registers nothing.
- A hook that cannot work still answers: allow for PreToolUse (an empty answer
  denies), {} for the rest. A bad payload, an unwritable state and a failure
  inside the session no longer leave stdout empty.
- The section follows a note only when it is not what the agent was last told:
  a launched session's opening note is not a changed list.
- A pending note is dropped at a user message, as Codex's is; a payload with no
  invocationNum is not a user message.
- The transcript is scanned for the step's own line, and a line that does not
  parse is skipped.
- hooksInPlace checks the event each handler names.
- README: always-answer, the POSIX shell form, overlapping events; a journal
  test for the order of the harness variables.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
… at the pace the agent works (refs #3777)

The implementing skill's first step is that the user chooses the work, so the
first prompt makes the choice and the second names the task the scenario
finishes. The agent reads a finished task within seconds, so the watch interval
defaults to 3 seconds for this driver.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
… with the next call (refs #3777)

- A keyed hook is the installer's by what its handlers run, so a path with a
  backslash or quote, and a path mentioned elsewhere in a foreign hook, are
  told apart correctly.
- The transcript's step is found by its index, not by key order or spacing.
- A state that cannot be written no longer turns a refusal into an allow.
- A note found by a tool call is told with the next model call, including the
  call after a user message, instead of being dropped there.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@malibio
malibio force-pushed the issue-3777-antigravity-plugin branch from 8c438e6 to 8010737 Compare October 13, 2026 20:06
@malibio
malibio merged commit 6b68385 into main Oct 13, 2026
@malibio
malibio deleted the issue-3777-antigravity-plugin branch October 13, 2026 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant