diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 006951d..37d3aa5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,12 +2,14 @@ name: release # A release is published when a release pull request is merged: the merge # changes `version` in plugin.json on main, and this workflow tags that commit -# and publishes it. Pushing a v* tag by hand still works as a fallback. +# and publishes it. A manual run can publish the version on main. Pushing a +# v* tag by hand still works as a fallback. on: push: branches: [main] paths: ["plugin/.claude-plugin/plugin.json"] tags: ["v*"] + workflow_dispatch: permissions: contents: write @@ -19,6 +21,8 @@ concurrency: jobs: release: + # Manual release runs must use main as their source commit. + if: github.event_name != 'workflow_dispatch' || github.ref == 'refs/heads/main' runs-on: ubuntu-latest steps: - uses: actions/checkout@v5 diff --git a/AGENTS.md b/AGENTS.md index 505c38d..16bfaea 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -6,7 +6,7 @@ This file is shared project guidance for coding agents that read `AGENTS.md` (in agent-quorum coordinates coding-agent sessions that share one working tree. A local daemon tracks sessions and file claims. Agent-specific hooks are adapters around a neutral wire protocol; keep agent JSON and output formats out of the daemon and core. -Codex and Claude Code hooks are implemented. Codex support lives in `internal/adapter/codex/`, its compatibility manifest is `plugin/.codex-plugin/plugin.json`, and its hook config is `plugin/hooks/codex.json`. Codex hooks currently register sessions, record prompts, guard Bash git commands, and claim paths in `apply_patch`. Antigravity and other agents do not have adapters unless one is added explicitly; do not describe them as supported based only on this shared instruction file. +Claude Code, Codex, and Antigravity hooks are implemented. Codex support lives in `internal/adapter/codex/`, its compatibility manifest is `plugin/.codex-plugin/plugin.json`, and its hook config is `plugin/hooks/codex.json`. Codex hooks currently register sessions, record prompts, guard Bash git commands, and claim paths in `apply_patch`. Antigravity support lives in `internal/adapter/antigravity/`, its manifest is `plugin/.antigravity-plugin/plugin.json`, and its hooks are in `plugin/hooks.json`; it registers lifecycle events, records prompts, guards `run_command`, and claims paths for Antigravity's file write and edit tools. ## Working in this repository diff --git a/CLAUDE.md b/CLAUDE.md index bcc7c74..495e4b3 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -6,7 +6,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co agent-quorum is local coordination for concurrent coding-agent sessions that share **one working tree** (no worktrees): it stops sessions from editing the same uncommitted file, blocks tree-wide git commands that would clobber another session's work, and lets sessions see each other. -**Current state:** the daemon, hook client, Claude Code and Codex adapters, git guard, presence and the `check --staged` pre-commit backstop are implemented. Codex hooks cover lifecycle registration, prompt notes, Bash guards and `apply_patch` claims. `PostToolUse` detection of shell edits, the notes mailbox and MCP server, and the mod are not built. Releases are published from tags by `release.yml`; `make dev` runs the local build. +**Current state:** the daemon, hook client, Claude Code, Codex and Antigravity adapters, git guard, presence and the `check --staged` pre-commit backstop are implemented. Codex hooks cover lifecycle registration, prompt notes, Bash guards and `apply_patch` claims. Antigravity hooks register sessions, refresh peer context on prompts, guard `run_command`, and claim paths for native file write/edit tools. `PostToolUse` detection of shell edits, the notes mailbox and MCP server, and the mod are not built. Releases are published from tags by `release.yml`; `make dev` runs the local build. `docs/DESIGN.md` is the design rationale. Read the relevant section before changing behaviour, but the code wins where they differ (known differences: the hook budget is 1.5 s rather than 250 ms, and the project is no longer standard-library-only). `docs/` is in `.gitignore`, so the design doc is local-only and absent from a fresh clone and from CI. `README.md` is the public description; `CONTRIBUTING.md` holds the dev guide, the semantic versioning rules and the release SOP, which must be followed before any tag. @@ -20,6 +20,7 @@ agent-quorum is local coordination for concurrent coding-agent sessions that sha | `make vet` | `go vet` plus a gofmt check that fails on unformatted files | | `make lint` | `sh -n` and shellcheck (optional locally, enforced in CI) on all scripts; `jq` on the plugin JSON | | `make validate-plugin` | `claude plugin validate` on `./plugin` (`--strict`) and on the marketplace root | +| `make validate-antigravity-plugin` | `agy plugin validate ./plugin` (allows the expected ignored Claude hook file warning) | | `make dev` | Build, then start Claude Code with the local plugin and `AGENT_QUORUM_BIN` pointing at the local binary | | `make snapshot` | Cross-compile all four release archives into `./dist` | | `make release V=1.2.3` | Check, then open the release pull request (`release/v1.2.3`). Merging it publishes the release. | @@ -52,6 +53,7 @@ internal/core/ State, Session, Claim, decisions internal/guard/ Classify(command) Risk internal/adapter/claude/ Parse, Render internal/adapter/codex/ Parse, Render +internal/adapter/antigravity/ Parse, Render internal/daemon/ socket server, lock, snapshot, real Env internal/client/ dial, start-on-demand, deadlines internal/gitx/ thin wrappers over the git CLI @@ -80,12 +82,13 @@ internal/gitx/ thin wrappers over the git CLI The repo root is both a Claude Code and Codex marketplace (`.claude-plugin/marketplace.json`, name `agent-quorum-tools`) with one plugin at `./plugin`. -- `plugin/.claude-plugin/plugin.json` is the release version source of truth; keep its version mirrored in `plugin/.codex-plugin/plugin.json`. `make release` updates both, accepts `1.2.3` and pre-releases such as `1.2.3-rc.1`, and opens a release pull request. A version change landing on `main` is what triggers `release.yml` to tag and publish. +- `plugin/.claude-plugin/plugin.json` is the release version source of truth; keep its version mirrored in `plugin/.codex-plugin/plugin.json` and `plugin/.antigravity-plugin/plugin.json`. `make release` updates all three, accepts `1.2.3` and pre-releases such as `1.2.3-rc.1`, and opens a release pull request. A version change landing on `main` is what triggers `release.yml` to tag and publish. - `main` is protected: every change, including a release, goes through a pull request. Never push to `main`, and never create release tags by hand. - Marketplace channels are the branches `stable` and `latest`, moved only by `scripts/publish-channels.sh` from `release.yml` after the binaries are published. Never commit to them by hand. `CONTRIBUTING.md` (CI/CD) has the rules. - The plugin ships shell scripts only, in `scripts/` (a top-level `bin/` is rejected by claude.ai and Cowork). The binary is downloaded from GitHub Releases to `~/.agent-quorum/bin/agent-quorum-` by `install.sh`, with checksum verification and an atomic move. - Every hook goes through `plugin/scripts/agent-quorum.sh`, which resolves `$AGENT_QUORUM_BIN`, then the versioned installed binary, then `agent-quorum` on `PATH`, and exits 0 if none exists. - Codex hooks are declared by `plugin/.codex-plugin/plugin.json` and `plugin/hooks/codex.json`; use `${PLUGIN_ROOT}` for plugin files and keep Codex hook payload translation in `internal/adapter/codex`. +- Antigravity hooks are declared by `plugin/.antigravity-plugin/plugin.json` and `plugin/hooks.json`; keep Antigravity payload translation in `internal/adapter/antigravity` and validate the package with `make validate-antigravity-plugin` when `agy` is available. - Hooks use exec form (`args` present) and the launcher uses `exec`, so that `getppid()` in the binary is the agent process. Liveness detection depends on this; do not insert a shell between them. - Hooks for one event run in parallel, so install-then-register on `SessionStart` is one script (`session-start.sh`), not two hooks. - Scripts are POSIX `sh`, must pass shellcheck, and parse `plugin.json` with `sed` (no `jq` at runtime on user machines). diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4b8a3d6..5ec6f67 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -10,6 +10,7 @@ Thanks for helping. This file covers the dev loop, the rules the code lives by, - `shellcheck` (optional locally, enforced in CI) - the `claude` CLI, for `make validate-plugin` and for trying the plugin by hand - the `codex` CLI, for installing and checking the Codex marketplace package locally +- the `agy` CLI, for validating the Antigravity plugin (`make validate-antigravity-plugin`) - `git`, `curl`, `tar` - macOS or Linux @@ -30,6 +31,7 @@ Every make target: | `make lint` | `sh -n` and shellcheck on `plugin/scripts/*.sh` and `scripts/*.sh`, and `jq empty` on the marketplace, plugin and hooks JSON. | | `make check` | `vet`, `lint`, `test`. | | `make validate-plugin` | Validates the Claude plugin and marketplace, then discovers and installs the Codex plugin in a temporary `CODEX_HOME`. Needs the `claude`, `codex` and `jq` CLIs. | +| `make validate-antigravity-plugin` | Runs `agy plugin validate ./plugin`. Needs the Antigravity CLI (`agy`); Antigravity reports the separate Claude hook config as an expected ignored-file warning. | | `make snapshot` | Cross-compiles the four release archives (darwin and linux, amd64 and arm64) and `checksums.txt` into `./dist`. | | `make dev` | `make build`, then `AGENT_QUORUM_BIN=$PWD/bin/agent-quorum claude --plugin-dir ./plugin`. | | `make release V=1.2.3` | Runs `make check`, then `scripts/bump-version.sh`: creates `release/v1.2.3`, sets the version in `plugin.json`, commits, pushes and opens the release pull request. Merging it publishes the release. | @@ -60,12 +62,14 @@ internal/core/ State, Session, Claim, decisions and the deny/contex internal/guard/ Classify(command) Risk. Pure. internal/adapter/claude/ Parse and Render for Claude Code hook JSON. Pure. internal/adapter/codex/ Parse and Render for Codex hook JSON. Pure. +internal/adapter/antigravity/ Parse and Render for Antigravity hook JSON. Pure. internal/daemon/ socket server, flock, snapshot, the real core.Env internal/client/ dial, start-on-demand, deadlines, path normalisation internal/gitx/ thin wrappers over the git CLI -plugin/ Claude Code and Codex manifests, hooks, scripts/*.sh, skills/status +plugin/ Claude Code, Codex and Antigravity manifests, hooks, scripts/*.sh, skills/status scripts/ release-build.sh, bump-version.sh testdata/hooks/claude/ Claude Code hook payload fixtures +testdata/hooks/antigravity/ Antigravity hook payload fixtures .claude-plugin/ marketplace.json: the repo root is a marketplace for Claude Code and Codex ``` @@ -113,7 +117,7 @@ Do not break these. Review will check each one. Rules: -- Do not edit the version in either `plugin/.claude-plugin/plugin.json` or `plugin/.codex-plugin/plugin.json` in an ordinary pull request. `make release` updates both manifests together; a version change on `main` publishes a release. +- Do not edit the version in `plugin/.claude-plugin/plugin.json`, `plugin/.codex-plugin/plugin.json`, or `plugin/.antigravity-plugin/plugin.json` in an ordinary pull request. `make release` updates all three manifests together; a version change on `main` publishes a release. - Do not commit to `stable` or `latest`. They are channel branches moved by the release workflow. - Do not force-push `main` or rewrite published tags. @@ -180,7 +184,7 @@ A pre-release such as `v0.2.0-rc.1` precedes `v0.2.0` in precedence and means "c ### Where the version lives -- `plugin/.claude-plugin/plugin.json` `version` is the source of truth and `plugin/.codex-plugin/plugin.json` mirrors it. Only a release pull request, opened by `make release`, edits these fields. +- `plugin/.claude-plugin/plugin.json` `version` is the source of truth; `plugin/.codex-plugin/plugin.json` and `plugin/.antigravity-plugin/plugin.json` mirror it. Only a release pull request, opened by `make release`, edits these fields. - The git tag is `v`, annotated, created by the release workflow on the merge commit. Nobody tags by hand in the normal flow. - Binaries are stamped at build time with `-ldflags "-X main.version="`. `scripts/release-build.sh` stamps the exact version; `make build` stamps `-dev`. An unstamped `go build` reports `dev`. - Claude Code users stay on their cached copy of a plugin until the `version` string changes, so a release is a version bump or it is nothing. diff --git a/Makefile b/Makefile index c720f83..3559cc2 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ VERSION ?= $(shell jq -r .version plugin/.claude-plugin/plugin.json)-dev BIN := bin/agent-quorum -.PHONY: build test vet lint check validate-plugin snapshot dev release clean +.PHONY: build test vet lint check validate-plugin validate-antigravity-plugin snapshot dev release clean build: ## build ./bin/agent-quorum for this machine go build -trimpath -ldflags "-X main.version=$(VERSION)" -o $(BIN) ./cmd/agent-quorum @@ -16,14 +16,19 @@ vet: lint: ## shell + JSON checks (shellcheck is optional locally, required in CI) @for f in plugin/scripts/*.sh scripts/*.sh; do sh -n "$$f" || exit 1; done @command -v shellcheck >/dev/null && shellcheck plugin/scripts/*.sh scripts/*.sh || echo "shellcheck not installed, skipped" - @jq empty .claude-plugin/marketplace.json plugin/.claude-plugin/plugin.json plugin/.codex-plugin/plugin.json plugin/hooks/hooks.json plugin/hooks/codex.json - @jq -e -s '.[0].version == .[1].version' plugin/.claude-plugin/plugin.json plugin/.codex-plugin/plugin.json >/dev/null + @jq empty .claude-plugin/marketplace.json plugin/.claude-plugin/plugin.json plugin/.codex-plugin/plugin.json plugin/.antigravity-plugin/plugin.json plugin/hooks/hooks.json plugin/hooks/codex.json plugin/hooks.json + @jq -e -s '.[0].version == .[1].version and .[0].version == .[2].version' plugin/.claude-plugin/plugin.json plugin/.codex-plugin/plugin.json plugin/.antigravity-plugin/plugin.json >/dev/null validate-plugin: ## needs the claude and codex CLIs claude plugin validate ./plugin --strict claude plugin validate . scripts/validate-codex-plugin.sh +validate-antigravity-plugin: ## needs the Antigravity CLI (`agy`) + @command -v agy >/dev/null 2>&1 || { echo "agy CLI not found" >&2; exit 1; } + # Non-strict validation allows the expected warning for Claude's separate hooks/hooks.json. + agy plugin validate ./plugin + check: vet lint test ## what CI runs snapshot: ## cross-compile all release archives into ./dist diff --git a/README.md b/README.md index e976797..cd1d933 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ [![ci](https://github.com/ChristopherLiew/agent-quorum/actions/workflows/ci.yml/badge.svg)](https://github.com/ChristopherLiew/agent-quorum/actions/workflows/ci.yml) -A Claude Code and Codex plugin that lets several agent sessions work in the same repository at once without overwriting each other. +A Claude Code, Codex, and Antigravity plugin that lets several agent sessions work in the same repository at once without overwriting each other.

Two agent sessions want the same file. agent-quorum lets the first edit it and blocks the second, which is told who holds the file. @@ -31,7 +31,7 @@ agent-quorum: /src/app/auth.go is being edited by another agent session (claude: ## Install -Requires macOS or Linux and Claude Code or Codex. +Requires macOS or Linux and Claude Code, Codex, or Antigravity. ```bash claude plugin marketplace add ChristopherLiew/agent-quorum#stable @@ -47,8 +47,18 @@ codex plugin add agent-quorum@agent-quorum-tools The plugin downloads its binary on the next session start and verifies it against the release checksums. Codex loads the hooks from its compatibility manifest. Review and trust the bundled hooks in Codex before they run. +For Antigravity, clone this repository and install the bundled plugin directory: + +```bash +git clone https://github.com/ChristopherLiew/agent-quorum.git +agy plugin install ./agent-quorum/plugin +``` + +Antigravity loads the plugin hooks for session startup, prompts, file writes and edits, shell commands, and the end of an agent run. The next prompt in a still-open conversation registers again and refreshes peer context. + - **Update:** `claude plugin update agent-quorum@agent-quorum-tools` - **Codex update:** `codex plugin marketplace upgrade agent-quorum-tools` +- **Antigravity update:** reinstall the local plugin directory after updating the repository checkout. - **Release candidates:** add the marketplace with `#latest` instead of `#stable`. - **Terminal CLI** (optional): the binary is installed at `~/.agent-quorum/bin/agent-quorum-`. Symlink it onto your `PATH` as `agent-quorum`. @@ -73,11 +83,11 @@ claude:3b80d4c2 pid 4310 idle 2m5s /src/app "add retry to the http client" ## How it works -The plugin adds hooks to Claude Code. Each hook call asks a small local daemon, shared by every session on your machine, whether the edit or git command is safe. The daemon starts by itself on the first hook and keeps its state in `~/.agent-quorum`. +Each agent plugin uses native hooks to ask a small local daemon, shared by every session on your machine, whether the edit or git command is safe. The daemon starts by itself on the first hook and keeps its state in `~/.agent-quorum`. ```mermaid sequenceDiagram - participant C as Claude Code session + participant C as agent session participant D as agent-quorum daemon Note over C: session starts C->>D: SessionStart (starts the daemon if it is not running) @@ -93,10 +103,10 @@ sequenceDiagram - **Holding a file.** The first edit takes a claim. It lasts while the holder's process is alive and the file has uncommitted changes, plus a 120 second grace period after the last edit. - **Crashes.** If a session dies without exiting cleanly, its files free up the next time anyone asks for them. - **Daemon restarts.** If the daemon stops, the next hook starts a new one and reloads the saved claims. -- **Fails open.** If agent-quorum is broken or missing, your agents behave as if it were not installed. It never auto-approves anything, so Claude Code's own permission prompts still apply. +- **Fails open.** If agent-quorum is broken or missing, your agents behave as if it were not installed. It never auto-approves anything, so each agent's own permission prompts still apply. - **Privacy.** The first 80 characters of each prompt are stored locally so sessions can see what the others are working on. Nothing leaves your machine. Set `AGENT_QUORUM_NO_NOTES=1` to turn it off. -Limits: it coordinates cooperating agents and is not a security boundary. Shell writes such as `sed -i` are not intercepted, edits you make in an editor are not seen, and it works on one machine for one user. Codex file claims cover `apply_patch`; shell writes remain outside hook coverage. +Limits: it coordinates cooperating agents and is not a security boundary. Shell writes such as `sed -i` are not intercepted, edits you make in an editor are not seen, and it works on one machine for one user. Codex file claims cover `apply_patch`; Antigravity claims cover `write_to_file`, `replace_file_content`, and `multi_replace_file_content`. Shell writes remain outside hook coverage. ## Debugging diff --git a/cmd/agent-quorum/hook.go b/cmd/agent-quorum/hook.go index 8e4a877..274e9f8 100644 --- a/cmd/agent-quorum/hook.go +++ b/cmd/agent-quorum/hook.go @@ -7,6 +7,7 @@ import ( "github.com/bytedance/sonic" + "github.com/ChristopherLiew/agent-quorum/internal/adapter/antigravity" "github.com/ChristopherLiew/agent-quorum/internal/adapter/claude" "github.com/ChristopherLiew/agent-quorum/internal/adapter/codex" "github.com/ChristopherLiew/agent-quorum/internal/client" @@ -53,6 +54,13 @@ func runHook(args []string, stdin io.Reader, stdout io.Writer) (code int) { } return 0 } + if agent == "antigravity" { + out := hookAntigravity(payload) + if len(out) > 0 { + _, _ = stdout.Write(out) + } + return 0 + } if agent != "claude" { return 0 // no adapter for this agent yet } @@ -88,6 +96,30 @@ var hookCodex = func(payload []byte) []byte { return codex.Render(ev, resp).Stdout } +var hookAntigravity = func(payload []byte) []byte { + ev, err := antigravity.Parse(payload) + if err != nil || !ev.HasReq { + return nil + } + req := ev.Req + if req.Op == proto.OpNote && os.Getenv("AGENT_QUORUM_NO_NOTES") == "1" { + return nil + } + req.PID = agentPID() + for i, p := range req.Paths { + req.Paths[i] = client.NormalizePath(p) + } + timeout := hookTimeout + if req.Op == proto.OpBye { + timeout = byeTimeout + } + resp, err := client.Do(req, client.Options{Timeout: timeout, Start: req.Op != proto.OpBye && os.Getenv("AGENT_QUORUM_NO_START") != "1"}) + if err != nil { + return nil + } + return antigravity.Render(ev, resp).Stdout +} + // hookClaude is swapped in tests to prove that a panicking adapter fails open. var hookClaude = func(payload []byte) []byte { ev, err := claude.Parse(payload) diff --git a/cmd/agent-quorum/main_test.go b/cmd/agent-quorum/main_test.go index 026f252..edaf9cf 100644 --- a/cmd/agent-quorum/main_test.go +++ b/cmd/agent-quorum/main_test.go @@ -57,13 +57,51 @@ func TestHookFailsOpen(t *testing.T) { } func TestHookPanicFailsOpen(t *testing.T) { - orig := hookClaude - t.Cleanup(func() { hookClaude = orig }) + origClaude := hookClaude + t.Cleanup(func() { hookClaude = origClaude }) hookClaude = func([]byte) []byte { panic("boom") } var out, errb bytes.Buffer if code := run([]string{"hook", "--agent", "claude"}, strings.NewReader(`{}`), &out, &errb); code != 0 || out.Len() != 0 { t.Fatalf("run(hook, panicking adapter) = %d, stdout %q, want 0 and empty", code, out.String()) } + + origAntigravity := hookAntigravity + t.Cleanup(func() { hookAntigravity = origAntigravity }) + hookAntigravity = func([]byte) []byte { panic("boom") } + out.Reset() + errb.Reset() + if code := run([]string{"hook", "--agent", "antigravity"}, strings.NewReader(`{}`), &out, &errb); code != 0 || out.Len() != 0 { + t.Fatalf("run(hook, panicking antigravity adapter) = %d, stdout %q, want 0 and empty", code, out.String()) + } +} + +func TestHookAntigravityFailsOpen(t *testing.T) { + t.Setenv("AGENT_QUORUM_HOME", shortTemp(t)) + t.Setenv("AGENT_QUORUM_NO_START", "1") + edit := `{"conversationId":"s1","cwd":"/tmp","hookEventName":"PreToolUse","toolCall":{"name":"edit_file","args":{"Path":"/tmp/x.go"}}}` + cases := map[string]string{ + "no session": `{"hookEventName":"PreToolUse","toolCall":{"name":"edit_file"}}`, + "no daemon": edit, + "invalid json": `{"hookEventName":`, + "empty": ``, + "unknown tool": `{"conversationId":"s1","hookEventName":"PreToolUse","toolCall":{"name":"read_file"}}`, + "wrong types": `{"conversationId":42,"hookEventName":["x"]}`, + } + for name, in := range cases { + t.Run(name, func(t *testing.T) { + var out, errb bytes.Buffer + start := time.Now() + if code := run([]string{"hook", "--agent", "antigravity"}, strings.NewReader(in), &out, &errb); code != 0 { + t.Errorf("run(hook --agent antigravity %s) = %d, want 0", name, code) + } + if out.Len() != 0 { + t.Errorf("run(hook --agent antigravity %s) stdout = %q, want empty", name, out.String()) + } + if d := time.Since(start); d > 400*time.Millisecond { + t.Errorf("run(hook --agent antigravity %s) took %v, want <= 400ms", name, d) + } + }) + } } func TestUnknownAgentFailsOpen(t *testing.T) { diff --git a/internal/adapter/antigravity/antigravity.go b/internal/adapter/antigravity/antigravity.go new file mode 100644 index 0000000..e32e754 --- /dev/null +++ b/internal/adapter/antigravity/antigravity.go @@ -0,0 +1,300 @@ +// Package antigravity translates Antigravity lifecycle hook JSON to the neutral quorum protocol. +package antigravity + +import ( + "bytes" + "path/filepath" + "strings" + + "github.com/bytedance/sonic" + + "github.com/ChristopherLiew/agent-quorum/internal/proto" +) + +// Agent is the value of proto.Request.Agent for this adapter. +const Agent = "antigravity" + +var plainJSON = sonic.Config{SortMapKeys: true, EscapeHTML: false, ValidateString: true}.Froze() + +const genericDeny = "agent-quorum: denied because another agent session holds this file." + +// Event is the parsed Antigravity hook call. +type Event struct { + HookEvent string + Tool string + Req proto.Request + HasReq bool +} + +// Output is what the hook process writes and how it exits. +type Output struct { + Stdout []byte + Exit int +} + +type hookInput struct { + ConversationID string `json:"conversationId"` + SessionID string `json:"sessionId"` + LegacySession string `json:"session_id"` + WorkspacePaths []string `json:"workspacePaths"` + CWD string `json:"cwd"` + HookEvent string `json:"hookEventName"` + LegacyEvent string `json:"hook_event_name"` + LastUserInput string `json:"lastUserInput"` + LegacyPrompt string `json:"prompt"` + FullyIdle bool `json:"fullyIdle"` + ToolCall *toolCall `json:"toolCall"` + ToolName string `json:"tool_name"` + ToolInput sonic.NoCopyRawMessage `json:"tool_input"` +} + +type toolCall struct { + ID string `json:"id"` + Name string `json:"name"` + Args sonic.NoCopyRawMessage `json:"args"` +} + +// Parse turns one Antigravity hook payload into an Event. It returns an error +// only for input that is not valid JSON. Missing sessions or unhandled tools +// return HasReq: false (no opinion). +func Parse(raw []byte) (Event, error) { + var in hookInput + if err := sonic.ConfigStd.Unmarshal(raw, &in); err != nil { + return Event{}, err + } + + sessionID := in.ConversationID + if sessionID == "" { + sessionID = in.SessionID + } + if sessionID == "" { + sessionID = in.LegacySession + } + + hookEvent := in.HookEvent + if hookEvent == "" { + hookEvent = in.LegacyEvent + } + + toolName := in.ToolName + toolArgs := in.ToolInput + if in.ToolCall != nil { + if in.ToolCall.Name != "" { + toolName = in.ToolCall.Name + } + if len(in.ToolCall.Args) > 0 { + toolArgs = in.ToolCall.Args + } + } + + ev := Event{HookEvent: hookEvent, Tool: toolName} + if sessionID == "" { + return ev, nil + } + + cwd := workingDirectory(in, toolArgs, toolName) + req := proto.Request{V: proto.Version, Agent: Agent, Session: sessionID, CWD: cwd} + + switch hookEvent { + case "SessionStart": + req.Op = proto.OpHello + case "Stop": + if !in.FullyIdle { + return ev, nil + } + req.Op = proto.OpBye + case "SessionEnd": + req.Op = proto.OpBye + case "PreInvocation", "UserPromptSubmit": + prompt := in.LastUserInput + if prompt == "" { + prompt = in.LegacyPrompt + } + if prompt == "" { + return ev, nil + } + // Re-register on each prompt. Antigravity's Stop event ends the current + // run, and a later prompt in the same conversation must register again. + req.Op, req.Note = proto.OpHello, prompt + case "PreToolUse": + switch toolName { + case "run_command", "Bash", "bash": + cmd := field(toolArgs, "CommandLine") + if cmd == "" { + cmd = field(toolArgs, "command") + } + if cmd == "" { + return ev, nil + } + req.Op, req.Command = proto.OpGuard, cmd + case "write_to_file", "replace_file_content", "multi_replace_file_content", + "write_file", "edit_file": + p := firstField(toolArgs, "TargetFile", "AbsolutePath", "Path", "path", "file_path") + if p == "" { + return ev, nil + } + p = absolutePath(p, cwd) + if p == "" { + return ev, nil + } + req.Op, req.Paths = proto.OpClaim, []string{p} + case "Edit", "Write", "MultiEdit", "NotebookEdit": + p := firstField(toolArgs, "file_path", "notebook_path", "Path", "path") + if p == "" { + return ev, nil + } + p = absolutePath(p, cwd) + if p == "" { + return ev, nil + } + req.Op, req.Paths = proto.OpClaim, []string{p} + case "apply_patch": + patch := field(toolArgs, "command") + if patch == "" { + patch = field(toolArgs, "patch") + } + for _, line := range strings.Split(patch, "\n") { + name := "" + if strings.HasPrefix(line, "*** Update File: ") { + name = strings.TrimPrefix(line, "*** Update File: ") + } + if strings.HasPrefix(line, "*** Add File: ") { + name = strings.TrimPrefix(line, "*** Add File: ") + } + if strings.HasPrefix(line, "*** Delete File: ") { + name = strings.TrimPrefix(line, "*** Delete File: ") + } + if strings.HasPrefix(line, "*** Move to: ") { + name = strings.TrimPrefix(line, "*** Move to: ") + } + if name != "" { + p := absolutePath(name, cwd) + if p != "" { + req.Paths = append(req.Paths, p) + } + } + } + if len(req.Paths) == 0 { + return ev, nil + } + req.Op = proto.OpClaim + default: + return ev, nil + } + default: + return ev, nil + } + + ev.Req, ev.HasReq = req, true + return ev, nil +} + +func workingDirectory(in hookInput, args sonic.NoCopyRawMessage, tool string) string { + if tool == "run_command" { + if cwd := firstField(args, "Cwd", "cwd"); filepath.IsAbs(cwd) { + return filepath.Clean(cwd) + } + } + if filepath.IsAbs(in.CWD) { + return filepath.Clean(in.CWD) + } + for _, p := range in.WorkspacePaths { + if filepath.IsAbs(p) { + return filepath.Clean(p) + } + } + return "" +} + +func absolutePath(path, cwd string) string { + if filepath.IsAbs(path) { + return filepath.Clean(path) + } + if !filepath.IsAbs(cwd) { + return "" + } + return filepath.Clean(filepath.Join(cwd, path)) +} + +func firstField(raw sonic.NoCopyRawMessage, keys ...string) string { + for _, key := range keys { + if value := field(raw, key); value != "" { + return value + } + } + return "" +} + +func field(raw sonic.NoCopyRawMessage, key string) string { + if len(raw) == 0 { + return "" + } + var m map[string]sonic.NoCopyRawMessage + if sonic.ConfigStd.Unmarshal(raw, &m) != nil { + return "" + } + val, ok := m[key] + if !ok || len(val) == 0 { + return "" + } + var s string + if sonic.ConfigStd.Unmarshal(val, &s) != nil { + return "" + } + return s +} + +type denyOutput struct { + Decision string `json:"decision"` + Reason string `json:"reason"` +} + +type sessionStartOutput struct { + InjectSteps []injectedStep `json:"injectSteps"` +} + +type injectedStep struct { + SystemMessage systemMessage `json:"systemMessage"` +} + +type systemMessage struct { + SystemMessage string `json:"systemMessage"` +} + +// Render turns the daemon's response into Antigravity hook stdout. +// A PreToolUse deny emits {"decision":"deny","reason":"..."}. +// A SessionStart with context injects a system message. +// All other cases return empty stdout (no opinion). +func Render(ev Event, r proto.Response) Output { + if !r.OK { + return Output{} + } + switch { + case ev.HookEvent == "PreToolUse" && r.Decision == proto.Deny: + reason := r.Reason + if reason == "" { + reason = genericDeny + } + var b bytes.Buffer + enc := plainJSON.NewEncoder(&b) + if enc.Encode(denyOutput{Decision: "deny", Reason: reason}) != nil { + return Output{} + } + return Output{Stdout: b.Bytes()} + case (ev.HookEvent == "SessionStart" || ev.HookEvent == "PreInvocation") && r.Context != "": + var b bytes.Buffer + enc := plainJSON.NewEncoder(&b) + out := sessionStartOutput{ + InjectSteps: []injectedStep{ + { + SystemMessage: systemMessage{SystemMessage: r.Context}, + }, + }, + } + if enc.Encode(out) != nil { + return Output{} + } + return Output{Stdout: b.Bytes()} + } + return Output{} +} diff --git a/internal/adapter/antigravity/antigravity_test.go b/internal/adapter/antigravity/antigravity_test.go new file mode 100644 index 0000000..104ac20 --- /dev/null +++ b/internal/adapter/antigravity/antigravity_test.go @@ -0,0 +1,302 @@ +package antigravity + +import ( + "bytes" + "os" + "path/filepath" + "reflect" + "testing" + + "github.com/ChristopherLiew/agent-quorum/internal/proto" +) + +const fixtureDir = "../../../testdata/hooks/antigravity" + +func req(op string, mod func(*proto.Request)) *proto.Request { + r := &proto.Request{ + V: proto.Version, + Op: op, + Agent: Agent, + Session: "ag-conv-001", + CWD: "/home/user/my-project", + } + if mod != nil { + mod(r) + } + return r +} + +func paths(p ...string) func(*proto.Request) { return func(r *proto.Request) { r.Paths = p } } +func command(c string) func(*proto.Request) { return func(r *proto.Request) { r.Command = c } } + +var golden = map[string]struct { + event, tool string + want *proto.Request +}{ + "session_start.json": {event: "SessionStart", tool: "", want: req(proto.OpHello, nil)}, + "stop.json": {event: "Stop", tool: "", want: req(proto.OpBye, nil)}, + "stop_not_idle.json": {event: "Stop", tool: "", want: nil}, + "pre_edit.json": {event: "PreToolUse", tool: "replace_file_content", want: req(proto.OpClaim, paths("/home/user/my-project/internal/auth/token.go"))}, + "pre_edit_relative.json": {event: "PreToolUse", tool: "multi_replace_file_content", want: req(proto.OpClaim, paths("/home/user/my-project/internal/auth/token.go"))}, + "pre_write.json": {event: "PreToolUse", tool: "write_to_file", want: req(proto.OpClaim, paths("/home/user/my-project/docs/notes.md"))}, + "pre_command_git.json": {event: "PreToolUse", tool: "run_command", want: req(proto.OpGuard, command("git stash && git pull --rebase"))}, + "pre_command_nongit.json": {event: "PreToolUse", tool: "run_command", want: req(proto.OpGuard, command("go test ./..."))}, + "pre_invocation.json": {event: "PreInvocation", tool: "", want: req(proto.OpHello, func(r *proto.Request) { r.Note = "refactor token refresh in internal/auth" })}, + "pre_read.json": {event: "PreToolUse", tool: "view_file", want: nil}, + "pre_edit_no_path.json": {event: "PreToolUse", tool: "replace_file_content", want: nil}, +} + +func TestParseGolden(t *testing.T) { + files, err := filepath.Glob(filepath.Join(fixtureDir, "*.json")) + if err != nil || len(files) == 0 { + t.Fatalf("Glob(%s) = %d files, err %v, want at least one fixture", fixtureDir, len(files), err) + } + seen := map[string]bool{} + for _, f := range files { + name := filepath.Base(f) + seen[name] = true + t.Run(name, func(t *testing.T) { + g, ok := golden[name] + if !ok { + t.Fatalf("golden[%s] missing, want an entry for every fixture", name) + } + raw, err := os.ReadFile(f) + if err != nil { + t.Fatal(err) + } + ev, err := Parse(raw) + if err != nil { + t.Fatalf("Parse(%s) err = %v, want nil", name, err) + } + if ev.HookEvent != g.event || ev.Tool != g.tool { + t.Errorf("event/tool = %q/%q, want %q/%q", ev.HookEvent, ev.Tool, g.event, g.tool) + } + if g.want == nil { + if ev.HasReq { + t.Errorf("Parse(%s).HasReq = true (req %+v), want false", name, ev.Req) + } + return + } + if !ev.HasReq { + t.Fatalf("Parse(%s).HasReq = false, want true with req %+v", name, *g.want) + } + if !reflect.DeepEqual(ev.Req, *g.want) { + t.Errorf("Parse(%s).Req = %+v, want %+v", name, ev.Req, *g.want) + } + if ev.Req.PID != 0 { + t.Errorf("Parse(%s).Req.PID = %d, want 0", name, ev.Req.PID) + } + }) + } + for name := range golden { + if !seen[name] { + t.Errorf("fixture for golden[%s] missing, want a file in %s", name, fixtureDir) + } + } +} + +func TestParse(t *testing.T) { + tests := []struct { + name string + input string + wantOp string + wantPaths []string + wantCommand string + wantNote string + wantReq bool + }{ + { + name: "session start with sessionId", + input: `{"sessionId":"s1","cwd":"/repo","hookEventName":"SessionStart"}`, + wantOp: proto.OpHello, + wantReq: true, + }, + { + name: "session start with legacy session_id and hook_event_name", + input: `{"session_id":"s1","cwd":"/repo","hook_event_name":"SessionStart"}`, + wantOp: proto.OpHello, + wantReq: true, + }, + { + name: "run_command with CommandLine", + input: `{"conversationId":"s1","cwd":"/repo","hookEventName":"PreToolUse","toolCall":{"name":"run_command","args":{"CommandLine":"git status"}}}`, + wantOp: proto.OpGuard, + wantCommand: "git status", + wantReq: true, + }, + { + name: "run_command with fallback tool_name and tool_input", + input: `{"conversationId":"s1","cwd":"/repo","hookEventName":"PreToolUse","tool_name":"run_command","tool_input":{"command":"git diff"}}`, + wantOp: proto.OpGuard, + wantCommand: "git diff", + wantReq: true, + }, + { + name: "edit_file relative path joined with absolute CWD", + input: `{"conversationId":"s1","cwd":"/repo","hookEventName":"PreToolUse","toolCall":{"name":"edit_file","args":{"Path":"foo/bar.go"}}}`, + wantOp: proto.OpClaim, + wantPaths: []string{"/repo/foo/bar.go"}, + wantReq: true, + }, + { + name: "write_to_file TargetFile relative to workspace path", + input: `{"conversationId":"s1","workspacePaths":["/repo"],"hookEventName":"PreToolUse","toolCall":{"name":"write_to_file","args":{"TargetFile":"docs/new.txt"}}}`, + wantOp: proto.OpClaim, + wantPaths: []string{"/repo/docs/new.txt"}, + wantReq: true, + }, + { + name: "run_command uses command Cwd", + input: `{"conversationId":"s1","workspacePaths":["/other"],"hookEventName":"PreToolUse","toolCall":{"name":"run_command","args":{"CommandLine":"git status","Cwd":"/repo"}}}`, + wantOp: proto.OpGuard, + wantCommand: "git status", + wantReq: true, + }, + { + name: "edit_file relative path with non-absolute CWD", + input: `{"conversationId":"s1","cwd":"repo","hookEventName":"PreToolUse","toolCall":{"name":"edit_file","args":{"Path":"foo/bar.go"}}}`, + }, + { + name: "write_file with path field", + input: `{"conversationId":"s1","cwd":"/repo","hookEventName":"PreToolUse","toolCall":{"name":"write_file","args":{"path":"/repo/new.txt"}}}`, + wantOp: proto.OpClaim, + wantPaths: []string{"/repo/new.txt"}, + wantReq: true, + }, + { + name: "apply_patch support", + input: `{"conversationId":"s1","cwd":"/repo","hookEventName":"PreToolUse","toolCall":{"name":"apply_patch","args":{"command":"*** Update File: a.go\n*** Move to: b.go\n"}}}`, + wantOp: proto.OpClaim, + wantPaths: []string{"/repo/a.go", "/repo/b.go"}, + wantReq: true, + }, + { + name: "prompt note from UserPromptSubmit", + input: `{"conversationId":"s1","cwd":"/repo","hookEventName":"UserPromptSubmit","prompt":"run tests"}`, + wantOp: proto.OpHello, + wantNote: "run tests", + wantReq: true, + }, + { + name: "missing session", + input: `{"cwd":"/repo","hookEventName":"SessionStart"}`, + }, + { + name: "unknown tool", + input: `{"conversationId":"s1","cwd":"/repo","hookEventName":"PreToolUse","toolCall":{"name":"unknown_tool","args":{}}}`, + }, + { + name: "run_command with empty CommandLine", + input: `{"conversationId":"s1","cwd":"/repo","hookEventName":"PreToolUse","toolCall":{"name":"run_command","args":{"CommandLine":""}}}`, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + ev, err := Parse([]byte(tt.input)) + if err != nil { + t.Fatalf("Parse() error = %v, want nil", err) + } + if got := ev.HasReq; got != tt.wantReq { + t.Fatalf("HasReq = %t, want %t", got, tt.wantReq) + } + if !tt.wantReq { + return + } + if got := ev.Req.Agent; got != Agent { + t.Errorf("Agent = %q, want %q", got, Agent) + } + if got := ev.Req.Op; got != tt.wantOp { + t.Errorf("Op = %q, want %q", got, tt.wantOp) + } + if got := ev.Req.Paths; !equal(got, tt.wantPaths) { + t.Errorf("Paths = %q, want %q", got, tt.wantPaths) + } + if got := ev.Req.Command; got != tt.wantCommand { + t.Errorf("Command = %q, want %q", got, tt.wantCommand) + } + if got := ev.Req.Note; got != tt.wantNote { + t.Errorf("Note = %q, want %q", got, tt.wantNote) + } + }) + } +} + +func TestParseInvalidJSON(t *testing.T) { + if _, err := Parse([]byte("{")); err == nil { + t.Fatal("Parse() error = nil, want non-nil") + } +} + +func TestRender(t *testing.T) { + tests := []struct { + name string + event Event + response proto.Response + want string + }{ + { + name: "deny with custom reason", + event: Event{HookEvent: "PreToolUse"}, + response: proto.Response{OK: true, Decision: proto.Deny, Reason: "held by peer"}, + want: `{"decision":"deny","reason":"held by peer"}` + "\n", + }, + { + name: "deny with generic reason", + event: Event{HookEvent: "PreToolUse"}, + response: proto.Response{OK: true, Decision: proto.Deny}, + want: `{"decision":"deny","reason":"` + genericDeny + `"}` + "\n", + }, + { + name: "session start context", + event: Event{HookEvent: "SessionStart"}, + response: proto.Response{OK: true, Context: "welcome to quorum"}, + want: `{"injectSteps":[{"systemMessage":{"systemMessage":"welcome to quorum"}}]}` + "\n", + }, + { + name: "pre-invocation refreshes peer context", + event: Event{HookEvent: "PreInvocation"}, + response: proto.Response{OK: true, Context: "another session is active"}, + want: `{"injectSteps":[{"systemMessage":{"systemMessage":"another session is active"}}]}` + "\n", + }, + { + name: "allow pre tool use emits empty stdout", + event: Event{HookEvent: "PreToolUse"}, + response: proto.Response{OK: true, Decision: proto.Grant}, + want: "", + }, + { + name: "session start empty context emits empty stdout", + event: Event{HookEvent: "SessionStart"}, + response: proto.Response{OK: true, Context: ""}, + want: "", + }, + { + name: "error response emits empty stdout", + event: Event{HookEvent: "PreToolUse"}, + response: proto.Response{OK: false, Decision: proto.Deny}, + want: "", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := Render(tt.event, tt.response).Stdout + if !bytes.Equal(got, []byte(tt.want)) { + t.Errorf("Render() = %q, want %q", got, tt.want) + } + }) + } +} + +func equal(got, want []string) bool { + if len(got) != len(want) { + return false + } + for i := range got { + if got[i] != want[i] { + return false + } + } + return true +} diff --git a/plugin/.antigravity-plugin/plugin.json b/plugin/.antigravity-plugin/plugin.json new file mode 100644 index 0000000..968ded2 --- /dev/null +++ b/plugin/.antigravity-plugin/plugin.json @@ -0,0 +1,17 @@ +{ + "$schema": "https://antigravity.google/schemas/v1/plugin.json", + "name": "agent-quorum", + "displayName": "agent-quorum", + "version": "0.2.0", + "description": "Stops concurrent agent sessions on one machine from editing the same files or clobbering each other's git state", + "suggestedPrompts": [ + "Check which other agent sessions are working in this repository" + ], + "logo": "assets/icon.png", + "author": { + "name": "ImmutablyChris", + "url": "https://github.com/ChristopherLiew" + }, + "repository": "https://github.com/ChristopherLiew/agent-quorum", + "homepage": "https://github.com/ChristopherLiew/agent-quorum" +} diff --git a/plugin/README.md b/plugin/README.md new file mode 100644 index 0000000..21d8425 --- /dev/null +++ b/plugin/README.md @@ -0,0 +1,22 @@ +# agent-quorum for Antigravity + +This plugin connects Antigravity sessions to the local agent-quorum daemon. +It registers sessions, shares peer context before prompts, guards risky +`run_command` commands, and claims files before Antigravity's native write and +edit tools run. + +## Install from a checkout + +Clone the repository and install this directory with the Antigravity CLI: + +```sh +agy plugin install ./plugin +``` + +The first session start downloads the matching `agent-quorum` binary from the +GitHub release and verifies its checksum. Enable the plugin in Antigravity if +the CLI leaves it disabled. + +Antigravity file claims cover `write_to_file`, `replace_file_content`, and +`multi_replace_file_content`. Shell edits and changes made outside Antigravity +are not intercepted. diff --git a/plugin/assets/icon.png b/plugin/assets/icon.png new file mode 100644 index 0000000..96e82bb Binary files /dev/null and b/plugin/assets/icon.png differ diff --git a/plugin/hooks.json b/plugin/hooks.json new file mode 100644 index 0000000..f70ab9f --- /dev/null +++ b/plugin/hooks.json @@ -0,0 +1,37 @@ +{ + "agent-quorum": { + "SessionStart": [ + { + "type": "command", + "command": "./scripts/antigravity-session-start.sh", + "timeout": 60 + } + ], + "PreInvocation": [ + { + "type": "command", + "command": "./scripts/agent-quorum.sh hook --agent antigravity", + "timeout": 5 + } + ], + "PreToolUse": [ + { + "matcher": "run_command|write_to_file|replace_file_content|multi_replace_file_content|apply_patch", + "hooks": [ + { + "type": "command", + "command": "./scripts/agent-quorum.sh hook --agent antigravity", + "timeout": 5 + } + ] + } + ], + "Stop": [ + { + "type": "command", + "command": "./scripts/agent-quorum.sh hook --agent antigravity", + "timeout": 5 + } + ] + } +} diff --git a/plugin/scripts/agent-quorum.sh b/plugin/scripts/agent-quorum.sh index 15858ee..ecd97d9 100755 --- a/plugin/scripts/agent-quorum.sh +++ b/plugin/scripts/agent-quorum.sh @@ -13,8 +13,10 @@ if [ -n "${AGENT_QUORUM_BIN:-}" ] && [ -x "$AGENT_QUORUM_BIN" ]; then exec "$AGENT_QUORUM_BIN" "$@" fi +manifest="$root/.claude-plugin/plugin.json" +[ -f "$manifest" ] || manifest="$root/.antigravity-plugin/plugin.json" ver=$(sed -n '/"version"/{s/.*"version"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p;q;}' \ - "$root/.claude-plugin/plugin.json" 2>/dev/null) + "$manifest" 2>/dev/null) bin="${AGENT_QUORUM_HOME:-$HOME/.agent-quorum}/bin/agent-quorum-$ver" if [ -n "$ver" ] && [ -x "$bin" ]; then exec "$bin" "$@" diff --git a/plugin/scripts/antigravity-session-start.sh b/plugin/scripts/antigravity-session-start.sh new file mode 100755 index 0000000..d732603 --- /dev/null +++ b/plugin/scripts/antigravity-session-start.sh @@ -0,0 +1,4 @@ +#!/bin/sh +dir="${0%/*}" +"$dir/install.sh" /dev/null 2>&1 || true +exec "$dir/agent-quorum.sh" hook --agent antigravity diff --git a/plugin/scripts/install.sh b/plugin/scripts/install.sh index 72a17a8..0856f51 100755 --- a/plugin/scripts/install.sh +++ b/plugin/scripts/install.sh @@ -7,8 +7,10 @@ set -eu REPO="ChristopherLiew/agent-quorum" root="${0%/*}/.." +manifest="$root/.claude-plugin/plugin.json" +[ -f "$manifest" ] || manifest="$root/.antigravity-plugin/plugin.json" ver=$(sed -n '/"version"/{s/.*"version"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p;q;}' \ - "$root/.claude-plugin/plugin.json") + "$manifest") [ -n "$ver" ] || { echo "install: no version in plugin.json" >&2; exit 1; } home="${AGENT_QUORUM_HOME:-$HOME/.agent-quorum}" diff --git a/plugin/skills/status/SKILL.md b/plugin/skills/status/SKILL.md index 81ddd97..3b4b1d9 100644 --- a/plugin/skills/status/SKILL.md +++ b/plugin/skills/status/SKILL.md @@ -1,4 +1,5 @@ --- +name: status description: Shows which other coding-agent sessions are active on this machine and which files each one holds, and explains what to do about a held file. Use when an edit or a git command was denied by agent-quorum, before starting work that touches many files, before a tree-wide git command (stash, checkout, reset, rebase, add -A, commit -a), or when the user asks who else is working in the repo or why something was blocked. --- @@ -7,7 +8,7 @@ description: Shows which other coding-agent sessions are active on this machine Run this and read the result: ```bash -"${CLAUDE_PLUGIN_ROOT}/scripts/agent-quorum.sh" status +"${CLAUDE_PLUGIN_ROOT:-${PLUGIN_ROOT}}/scripts/agent-quorum.sh" status ``` ## Reading the output diff --git a/scripts/bump-version.sh b/scripts/bump-version.sh index c06203c..edc72c3 100755 --- a/scripts/bump-version.sh +++ b/scripts/bump-version.sh @@ -8,6 +8,7 @@ set -eu ver="${1:?usage: bump-version.sh }" manifest=plugin/.claude-plugin/plugin.json codex_manifest=plugin/.codex-plugin/plugin.json +antigravity_manifest=plugin/.antigravity-plugin/plugin.json branch="release/v$ver" "${0%/*}/semver.sh" check "$ver" @@ -28,7 +29,9 @@ jq --arg v "$ver" '.version = $v' "$manifest" > "$tmp" mv "$tmp" "$manifest" jq --arg v "$ver" '.version = $v' "$codex_manifest" > "$tmp" mv "$tmp" "$codex_manifest" -git add "$manifest" "$codex_manifest" +jq --arg v "$ver" '.version = $v' "$antigravity_manifest" > "$tmp" +mv "$tmp" "$antigravity_manifest" +git add "$manifest" "$codex_manifest" "$antigravity_manifest" git commit -q -m "release v$ver" if [ -n "${NO_PUSH:-}" ]; then diff --git a/testdata/hooks/antigravity/README.md b/testdata/hooks/antigravity/README.md new file mode 100644 index 0000000..f63fc95 --- /dev/null +++ b/testdata/hooks/antigravity/README.md @@ -0,0 +1,3 @@ +These fixtures follow the shapes in the Antigravity lifecycle hooks reference. +The adapter's golden test in internal/adapter/antigravity/antigravity_test.go +enforces bidirectional coverage against every fixture here. diff --git a/testdata/hooks/antigravity/pre_command_git.json b/testdata/hooks/antigravity/pre_command_git.json new file mode 100644 index 0000000..1a288c6 --- /dev/null +++ b/testdata/hooks/antigravity/pre_command_git.json @@ -0,0 +1,12 @@ +{ + "conversationId": "ag-conv-001", + "hookEventName": "PreToolUse", + "toolCall": { + "id": "toolu_03", + "name": "run_command", + "args": { + "Cwd": "/home/user/my-project", + "CommandLine": "git stash && git pull --rebase" + } + } +} diff --git a/testdata/hooks/antigravity/pre_command_nongit.json b/testdata/hooks/antigravity/pre_command_nongit.json new file mode 100644 index 0000000..fbebcf8 --- /dev/null +++ b/testdata/hooks/antigravity/pre_command_nongit.json @@ -0,0 +1,12 @@ +{ + "conversationId": "ag-conv-001", + "hookEventName": "PreToolUse", + "toolCall": { + "id": "toolu_04", + "name": "run_command", + "args": { + "Cwd": "/home/user/my-project", + "CommandLine": "go test ./..." + } + } +} diff --git a/testdata/hooks/antigravity/pre_edit.json b/testdata/hooks/antigravity/pre_edit.json new file mode 100644 index 0000000..76afdb1 --- /dev/null +++ b/testdata/hooks/antigravity/pre_edit.json @@ -0,0 +1,14 @@ +{ + "conversationId": "ag-conv-001", + "workspacePaths": ["/home/user/my-project"], + "hookEventName": "PreToolUse", + "toolCall": { + "id": "toolu_01", + "name": "replace_file_content", + "args": { + "TargetFile": "/home/user/my-project/internal/auth/token.go", + "TargetContent": "return nil", + "ReplacementContent": "return err" + } + } +} diff --git a/testdata/hooks/antigravity/pre_edit_no_path.json b/testdata/hooks/antigravity/pre_edit_no_path.json new file mode 100644 index 0000000..481396d --- /dev/null +++ b/testdata/hooks/antigravity/pre_edit_no_path.json @@ -0,0 +1,12 @@ +{ + "conversationId": "ag-conv-001", + "workspacePaths": ["/home/user/my-project"], + "hookEventName": "PreToolUse", + "toolCall": { + "id": "toolu_06", + "name": "replace_file_content", + "args": { + "TargetContent": "foo" + } + } +} diff --git a/testdata/hooks/antigravity/pre_edit_relative.json b/testdata/hooks/antigravity/pre_edit_relative.json new file mode 100644 index 0000000..bdd8e13 --- /dev/null +++ b/testdata/hooks/antigravity/pre_edit_relative.json @@ -0,0 +1,13 @@ +{ + "conversationId": "ag-conv-001", + "workspacePaths": ["/home/user/my-project"], + "hookEventName": "PreToolUse", + "toolCall": { + "id": "toolu_07", + "name": "multi_replace_file_content", + "args": { + "TargetFile": "internal/auth/token.go", + "ReplacementChunks": [] + } + } +} diff --git a/testdata/hooks/antigravity/pre_invocation.json b/testdata/hooks/antigravity/pre_invocation.json new file mode 100644 index 0000000..a0c3530 --- /dev/null +++ b/testdata/hooks/antigravity/pre_invocation.json @@ -0,0 +1,6 @@ +{ + "conversationId": "ag-conv-001", + "workspacePaths": ["/home/user/my-project"], + "hookEventName": "PreInvocation", + "lastUserInput": "refactor token refresh in internal/auth" +} diff --git a/testdata/hooks/antigravity/pre_read.json b/testdata/hooks/antigravity/pre_read.json new file mode 100644 index 0000000..ec6d6fc --- /dev/null +++ b/testdata/hooks/antigravity/pre_read.json @@ -0,0 +1,12 @@ +{ + "conversationId": "ag-conv-001", + "workspacePaths": ["/home/user/my-project"], + "hookEventName": "PreToolUse", + "toolCall": { + "id": "toolu_05", + "name": "view_file", + "args": { + "AbsolutePath": "/home/user/my-project/internal/auth/token.go" + } + } +} diff --git a/testdata/hooks/antigravity/pre_write.json b/testdata/hooks/antigravity/pre_write.json new file mode 100644 index 0000000..4aee26c --- /dev/null +++ b/testdata/hooks/antigravity/pre_write.json @@ -0,0 +1,13 @@ +{ + "conversationId": "ag-conv-001", + "workspacePaths": ["/home/user/my-project"], + "hookEventName": "PreToolUse", + "toolCall": { + "id": "toolu_02", + "name": "write_to_file", + "args": { + "TargetFile": "/home/user/my-project/docs/notes.md", + "CodeContent": "hello world" + } + } +} diff --git a/testdata/hooks/antigravity/session_start.json b/testdata/hooks/antigravity/session_start.json new file mode 100644 index 0000000..ee10e3a --- /dev/null +++ b/testdata/hooks/antigravity/session_start.json @@ -0,0 +1,7 @@ +{ + "conversationId": "ag-conv-001", + "workspacePaths": [ + "/home/user/my-project" + ], + "hookEventName": "SessionStart" +} diff --git a/testdata/hooks/antigravity/stop.json b/testdata/hooks/antigravity/stop.json new file mode 100644 index 0000000..d614acb --- /dev/null +++ b/testdata/hooks/antigravity/stop.json @@ -0,0 +1,6 @@ +{ + "conversationId": "ag-conv-001", + "workspacePaths": ["/home/user/my-project"], + "hookEventName": "Stop", + "fullyIdle": true +} diff --git a/testdata/hooks/antigravity/stop_not_idle.json b/testdata/hooks/antigravity/stop_not_idle.json new file mode 100644 index 0000000..8bdc11d --- /dev/null +++ b/testdata/hooks/antigravity/stop_not_idle.json @@ -0,0 +1,6 @@ +{ + "conversationId": "ag-conv-001", + "workspacePaths": ["/home/user/my-project"], + "hookEventName": "Stop", + "fullyIdle": false +}