Repository navigation
Give Antigravity NodeSpace hooks, and run the harness scenario with them (closes #3777) - #3802
Conversation
malibio
left a comment
There was a problem hiding this comment.
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_IDjournal 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)
-
The
nodespacekey is not checked for ownership.installer.ts(syncHooksFilekeyed branch,removeHooksFilekeyed branch)- Install replaces whatever is under
nodespacewith ours; uninstall deletesnodespaceand, if nothing else is left, deletes the file. A user's own hook namednodespaceis 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)(thenamedpredicate already inhooksInPlace). 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 foreignnodespacekey 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
othershaving no keys, so a file we did not create is not deleted just because it held one key that was ours by name.
- Install replaces whatever is under
-
Hooks answer nothing on any failure, but two events must always answer.
hook.tshandle(early return on a badconversationId) andhook-process.tsrun(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 (savethrows), asession.startthat 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 afinally/catch aroundhandle, and test it. Also consider thatensureStarted()in PostToolUse/PreToolUse can runstart(several CLI calls) inside a 15 s budget; either lower its cost or let the timeout failure fall into the safe answer above.
- Per the facts established: PreToolUse must answer a decision (and
-
The section is told twice when a task launched the session.
hook.tsPreInvocation,const note = await session.prompt()prompt()returns the launch'sopeningtext as part ofnote(it isjoined(handed, note)). SessionStart already injectedsection(), but the first prompt sees a truthynoteand appendssectionagain (note ? note + section). TheisStartingNowguard only protects the no-note branch. The check should be "the skill list changed" rather than "any note", e.g. have the hook comparelistVersion/skillsfrom the snapshot before and after, or have the session expose whether the list changed. Add a test with a launched session (openingset).
Improvements
-
Transcript read is O(file) per
nodespacecommand, and one bad line empties the result.hook.tsoutputOfreadFileof the whole transcript,split, andJSON.parseof every line up to the match, for every PostToolUse of a nodespace command. In a long session with a large transcript and manynodespacecalls 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 beforeJSON.parse(or scan from the end, sincestepIdxis 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.
-
invocationNum === 0is a strict equality on an unvalidated field.hook.tsPreInvocation- 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 stalependingNote(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.
- 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
-
hooksInPlacedoes not check the event argument.installer.tskeyed branch ofhooksInPlace- It only checks that each handler names the script, so a handler registered under
PreToolUsewhose command endsPostToolUsereports "installed". Compare the fullhookCommand(script, event)string. This also makes the status result reflect a Windows/quoting change after an upgrade.
- It only checks that each handler names the script, so a handler registered under
-
Windows / shell form.
hookCommandis POSIXsh(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 plainbun "path". Either confirm Antigravity runs hook commands throughshon 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 (quotedPathis covered for Codex). -
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
pendingNotethat the other just set.savealready 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.rstest 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.tsdoc comment onoutputOfsays "the step that follows the model's call", but the code matchesstep_index === stepIdx; align the wording with the established fact. - Nit:
prompt()always rebuildssection, sosession.section()is non-null after every prompt; a short comment next toisStartingNowsaying 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: falseso 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.
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
Suggested improvements
Nitpicks
Live evidenceThe 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 Net positive and mergeable after Improvement 1; items 2 to 4 are small and worth folding in. |
Re-review addressed (8c438e6)Addressed
Not changed
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: Re-Review DecisionDecision: 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. |
…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]>
8c438e6 to
8010737
Compare
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.SessionStartinjects the section (project, orientation, consent rules, skill list).PreInvocationnumbered 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.PreToolUseanswersdenywith the reason, orallow(which leaves the permission system to decide, checked live: a command that needs a permission is still denied in print mode).PostToolUseanswers{}and reads anodespacecommand's output from the conversation transcript; a note for the agent waits for the nextPreInvocation.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.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.ANTIGRAVITY_CONVERSATION_IDwhen no plugin variable is set, as it does forCODEX_THREAD_ID..agents/hooks.json(the user's global hooks file is untouched);ANTIGRAVITY_BASELINE=1leaves them out.Facts found by running Antigravity 1.3.4 with a logging hook
injectStepssystemMessageis{"systemMessage": {"systemMessage": "..."}}and reaches the agent; the transcript records it.invocationNumresets to 0 for each user message;SessionStartdoes not fire again when a conversation is continued.transcriptPathholds each command's output at the stepPostToolUsenames.ANTIGRAVITY_CONVERSATION_IDequals the hooks'conversationId.Tests
bun run --cwd packages/skill test302 pass (a process-level suite over a fakenodespace, like Codex's),bun run test:scripts1548 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