Skip to content

feat(agent-hook-plugin): add Antigravity (app and agy CLI) as a host adapter - #7710

Open
fancyboi999 wants to merge 4 commits into
volcengine:mainfrom
fancyboi999:feat/agent-hook-antigravity
Open

fancyboi999 wants to merge 4 commits into
volcengine:mainfrom
fancyboi999:feat/agent-hook-antigravity

Conversation

@fancyboi999

@fancyboi999 fancyboi999 commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Description

Adds Antigravity as a host of the shared agent-hook-plugin dispatcher. One plugin covers both the Antigravity desktop app and the agy CLI, because both load plugins from ~/.gemini/config/plugins/. Before this change, Antigravity sessions neither recalled OpenViking memory nor added to it. After it:

  • SessionStart injects the profile.
  • PreInvocation recalls on the first model call of each turn.
  • Stop captures the finished turn in a detached worker, then commits.

Sessions are ag-<conversationId>.

The entry point is scripts/hook.mjs <session-start|pre-invocation|stop> antigravity. The owner module is examples/agent-hook-plugin/hosts/antigravity.mjs. The Antigravity hook contract was taken from real hook stdin and transcript files, not inferred; see #7709.

  • Antigravity runs PreInvocation before every model call, including each one in a tool loop (invocationNum > 0) and each reactive wakeup for a background task, subagent message, or Stop continuation (invocationNum 0 with a higher initialNumSteps and the earlier lastUserInput). Recall runs only when invocationNum is 0 and no MODEL step has run since the latest USER_INPUT step in transcriptPath, keyed by conversationId:(userStepIndex + 1) so each user turn injects once while genuine repeated prompts still get their turn injection.
  • Context returns as {"injectSteps":[{"systemMessage":{"systemMessage": ...}}]}. Pass-through writes {}.
  • Stop has no message text. Capture reads transcriptPath (transcript_full.jsonl) after the last captured step_index. It keeps only USER_INPUT from USER_EXPLICIT (the text inside <USER_REQUEST>) and PLANNER_RESPONSE text. Non-captured step types (such as backgrounded GENERIC tool steps that keep RUNNING, or ERROR / INVALID tool steps) advance the cursor without blocking capture; on captured turn records, an in-progress status (PENDING, QUEUED, WAITING, RUNNING, GENERATING) holds the cursor for the next Stop, while terminal non-DONE records (CANCELED, ERROR, …) are skipped. Tool output and injected SYSTEM_MESSAGE steps are never captured, and <openviking-context> blocks are stripped. The cursor moves only when every kept message was sent or queued.

This supersedes #4069, which no longer fits the #4773 hosts/<host>/ layout and uses the deprecated ephemeralMessage step.

Human Involvement

  • A human participated in the implementation or review loop
  • This PR was generated entirely by AI agents without human participation in the loop

Related Issue

Closes #7709

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Test update

Changes Made

  • hosts/antigravity.mjs: the adapter (event map, envelope, input normalisation, transcript capture).
  • hosts/antigravity/{hooks.json,plugin.json}: the Antigravity plugin template. It uses the same __OPENVIKING_PLUGIN_ROOT__ / __OPENVIKING_CLIENT_ID__ placeholders as the other hosts.
  • hosts/index.mjs, import-history.mjs: register antigravity (ag- live ids). The existing import-history contract test iterates every registered host and requires this entry.
  • install.sh: add antigravity to AGENT_HOOK_HOSTS only, so other hosts' installs do not carry its directory. --harness antigravity is left for a follow-up PR.
  • Bump agent-hook-plugin to 0.5.32 with the host manifests, as check-plugin-version-bumps.sh requires.
  • Docs (en/zh): a community-plugins section with manual install from a checkout, the overview row, and the README host notes.
  • tests/antigravity.test.mjs: the hooks.json shape, plus an end-to-end contract test against a mock server. It covers recall once per turn across concurrent calls, tool loops, and reactive wakeups (while allowing repeated user turns); capture of only user and assistant text past non-DONE tool steps and CANCELED drafts; and incremental capture that pauses on an in-flight turn step and resumes once DONE.

config-schema.mjs HARNESS_KEYS is intentionally unchanged. Adding antigravity there regenerates the shared copies in the Claude Code and Codex plugins and forces their version bumps. Defaults work without it, so it can land with the installer PR.

Testing

  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have tested this on the following platforms:
    • Linux
    • macOS
    • Windows

Commands run on macOS, Node 26:

Check Result
node --test examples/agent-hook-plugin/tests/*.test.mjs examples/memory-plugin-shared/*.test.mjs (CI's set without the installer tests) 716 tests, 715 pass, 1 fail. The failure is install-tui.test.mjs › "what was asked for but not installed is listed again just before the onboarding link". It fails the same way on main (00c8e7b) without this change.
node --test --test-concurrency=1 install-agent-hooks.test.mjs release-marketplace.test.mjs 24/24 pass
bash .github/scripts/check-plugin-version-bumps.sh origin/main pass
node examples/memory-plugin-shared/sync.mjs and then git status no generated changes
bash -n examples/memory-plugin-shared/install.sh ok
node docs/scripts/check-docs-consistency.mjs pass
Mutation check Removing the invocationNum gate, or the DONE status check, makes the new contract test fail

Real hosts, against OpenViking server 0.5.0. The plugin was installed with the documented manual steps from this branch.

  • agy 1.5.9: a new session answered a question from recalled memory without calling tools. The hook state recorded promptEventId and lastStep. The server session ag-… holds 2 messages, and its session_commit task completed.
  • Antigravity desktop app 2.32.1: five app conversations recalled. Each showed a "Hook Json PreInvocation" system message carrying OpenViking memory, and four captured turns committed (session_commit completed). This app run used an earlier local build of the same adapter logic (same event handling, recall gate, transcript parsing and cursor). This branch's final form was re-verified on agy, which loads the same plugin directory.

Not covered: Linux and Windows; the installer path (no --harness antigravity yet).

Checklist

  • My code follows the project's coding style
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

…adapter

Antigravity runs PreInvocation before every model call, so recall runs
only on a turn's first call (invocationNum 0), deduplicated per turn.
Context returns as an injectSteps system message. Stop carries no text:
capture reads the finished steps of transcriptPath after the last
captured step, in a detached worker, and commits. Sessions are ag-.

Refs volcengine#7709
@r266-tech

Copy link
Copy Markdown
Contributor

I found a content-loss case at 1d5c15216a7b5b1023f58b73379513e5f9564485: buildAntigravityTurns() applies the user-envelope extractor to assistant replies too.

For example, these finished transcript steps:

{"step_index":0,"status":"DONE","source":"USER_EXPLICIT","type":"USER_INPUT","content":"Explain the USER_REQUEST transcript envelope."}
{"step_index":1,"status":"DONE","source":"MODEL","type":"PLANNER_RESPONSE","content":"The transcript wraps your prompt like this:\n<USER_REQUEST>your prompt</USER_REQUEST>\nKeep the following metadata separate from the request."}

cause the real scripts/hook.mjs stop antigravity entrypoint to send the assistant message as only your prompt. If the reply instead documents an empty <USER_REQUEST></USER_REQUEST> template, the entire assistant message is dropped. Both examples also reproduce with the XML inside a Markdown code fence.

I checked the requests at a loopback HTTP server, then invoked Stop again: lastStep was already 1, so the second invocation did not recover the lost reply. Plain replies and an actual wrapped user input with trailing host metadata were preserved normally.

Could the <USER_REQUEST> envelope be unwrapped only for the host's explicit user-input record, while assistant text only has the intended injected-context removal applied? A regression using an assistant explanation of this exact host format would protect the distinction.

Validation: the existing Antigravity, agent-hook-runtime and import-history tests passed (53/53). The independent hook probe had two content-loss cases and two passing controls. This was an AI-only investigation on macOS/Node 26 using synthetic transcripts and a loopback server; I did not run an Antigravity app/agy session or a real OpenViking deployment.

…input

Assistant replies that quote the host's request envelope were reduced to
the quoted text, or dropped when the quote was an empty template, and the
capture cursor had already moved past them. Unwrap only a USER_INPUT
record whose content opens with the envelope; assistant text and the
recall prompt only lose injected openviking-context blocks.
@fancyboi999

Copy link
Copy Markdown
Contributor Author

Thanks, confirmed and fixed in fc72865.

  • The <USER_REQUEST> envelope is now unwrapped only for a USER_INPUT record from USER_EXPLICIT, and only when that record opens with the envelope. The match runs to the last closing tag, so a typed request that itself contains the tags is also kept intact.
  • Assistant text and the recall prompt only have injected <openviking-context> blocks removed.
  • Regression: tests/antigravity.test.mjs now captures your two cases (a reply that quotes the envelope, and an empty template inside a code fence) through the real scripts/hook.mjs stop antigravity entry point. The new test fails on 1d5c152 and passes after the fix.

Re-checked on a real agy 1.5.9 session against OpenViking 0.5.0. The prompt and the reply both contained <USER_REQUEST>示例</USER_REQUEST>, and the archived session messages kept both verbatim.

@r266-tech

Copy link
Copy Markdown
Contributor

Thanks for the fix. I re-ran the independent probe against fc728652070ee2fa22dd5e00165bd771271770c1: both original assistant-content-loss cases now preserve the full reply, including the empty template inside a code fence. The plain-reply and wrapped-user controls also pass, and a second Stop sends no duplicates.

I also checked nested tags inside a wrapped user request, an assistant reply beginning with <USER_REQUEST>, resuming after an unfinished step, and a rejected message write followed by a successful retry. The text and cursor behaved as expected. The Antigravity, agent-hook-runtime and import-history suites pass (53/53). This resolves the content-loss finding in my earlier comment.

This was AI-only validation on macOS/Node 26 through the real Stop hook with synthetic transcripts and a loopback HTTP server; I did not run Antigravity/agy or a real OpenViking deployment.

… wakeups

When a background task, subagent reply, timer, or Stop continuation wakes an Antigravity turn, PreInvocation runs again with invocationNum 0, a higher initialNumSteps, and lastUserInput still holding the earlier prompt. Keying prompt_id by initialNumSteps bypassed promptEventId deduplication and re-injected the cached recallBlock into the trajectory on every wakeup.

Resolve the active user turn from transcriptPath instead: skip recall when a MODEL step has already run since the latest USER_EXPLICIT USER_INPUT step, and key prompt_id by that user step (step_index + 1) so each user turn injects once while still recalling on genuine repeated prompts.
…l steps

Backgrounded run_command steps (MODEL/GENERIC with status RUNNING) and failed or invalid tool steps (ERROR, INVALID) stay non-DONE permanently in Antigravity transcripts. Breaking on every non-DONE step froze lastStep before all subsequent turns in that conversation.

Advance lastStep past non-captured step types regardless of status. On captured turn records (USER_EXPLICIT USER_INPUT and PLANNER_RESPONSE), hold the cursor only while the step is in progress (PENDING, QUEUED, WAITING, RUNNING, GENERATING), and skip terminal non-DONE records (CANCELED, ERROR, INVALID, ...) without blocking later turns.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

[Feature]: Add an Antigravity (desktop app and agy CLI) host adapter to agent-hook-plugin

2 participants