stopbar 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.1.0 (2026-11-26)
4
+
5
+ - Adapters for Cursor, Codex CLI, Gemini CLI and Antigravity CLI next to Claude Code. One internal event, one kernel;
6
+ each adapter renders the decision in the client's own protocol.
7
+ - `stopbar hook --adapter auto|claude|cursor|codex|gemini|antigravity`. `auto` (the default) detects the client from
8
+ the payload; v1.0 Claude Code settings keep working; an unknown or damaged payload fails closed.
9
+ - `stopbar init --hooks` takes `claude` (`local`), `claude-project` (`project`), `cursor`, `codex`, `gemini`,
10
+ `antigravity` (`agy`) and `git`, comma separated, and merges into existing config files.
11
+ - Git fallback: `stopbar git-hook pre-commit|pre-push`, installed by `init --hooks git` (an existing user hook is kept
12
+ unless `--force-hooks`), and `stopbar run build|test` to record gate runs for tools without hooks.
13
+ - Self-protection also covers `.cursor/hooks.json`, `.codex/hooks.json`, `.codex/config.toml`, `.gemini/*settings*.json`,
14
+ `.gemini/**/hooks.json` and `.agents/hooks.json`.
15
+ - `stopbar doctor` checks the hooks of every client it finds and the git hooks.
16
+ - `stopbar status`, `status --json` and `stopbar attest` say why the secret gate is on (pattern, file or token, tool,
17
+ revision); `events.jsonl` records the pattern and the token of every secret read, never the content.
18
+ - No secret false alarm on code: a bare token that matches only an extension pattern (`*.key`, `*.pem`) counts only if
19
+ the file exists (`claim.key` in inline code is not a read; `cat server.key` and `cat certs/server.key` are).
20
+ - `safeTools` in `config.json` (default `["mcp__ccd_turn__*"]`): local tools that are not treated as outbound.
21
+ - Antigravity CLI tool names from a live session (`write_file`, `sed_file`, `call_mcp_tool`, `list_dir`, ...).
22
+ - A gate command whose post event carries no exit status (Codex CLI) is recorded neither as a pass nor as a failure,
23
+ and the agent is told to use `stopbar run build|test`; blocked commits name `stopbar run` as the other way.
24
+ - Package metadata: repository, homepage and bugs links.
25
+
3
26
  ## 1.0.0 (2026-11-26)
4
27
 
5
28
  First public release.
package/README.md CHANGED
@@ -1,15 +1,40 @@
1
1
  # Stopbar
2
2
 
3
- Stopbar is a set of Claude Code hooks with a formally proven decision kernel. It stops a coding agent from:
3
+ Stopbar is a formally proven execution gate for AI coding agents. It runs as the hooks of Claude Code, Cursor, Codex
4
+ CLI, Gemini CLI and Antigravity CLI, and as git hooks for any other tool. It stops an agent from:
4
5
 
5
6
  - committing without a passing build and a passing **full** test suite at the current revision of the working tree;
6
7
  - weakening existing tests or test configuration without a human approval;
7
8
  - running risky or outbound commands after it read a secret, unless a human allows one call;
8
- - looping on failing builds or tests, or going past a budget of tool calls.
9
+ - looping on failing builds or tests, or going past a budget of tool calls;
10
+ - switching itself off by editing the agent's hook configuration, git hooks or its own state.
9
11
 
10
12
  The decisions come from one rule, `src/kernel.ts`. gdp-wired 0.60.0 proves its laws by induction, and 10 mutants of
11
- the rule each fall with a counterexample. The hooks run a step function generated from the same rule, without the prover.
12
- See [SECURITY.md](SECURITY.md) for what is proven, what the wrapper enforces and what needs an OS sandbox.
13
+ the rule each fall with a counterexample. Every client goes through the same rule: an adapter translates the client's
14
+ hook payload into one internal event and renders the decision in the client's own output format. See
15
+ [SECURITY.md](SECURITY.md) for what is proven, what the wrapper enforces and what needs an OS sandbox.
16
+
17
+ ## Supported agents
18
+
19
+ | Agent | Config written by `init --hooks` | Events | Block protocol | Status |
20
+ |---|---|---|---|---|
21
+ | Claude Code | `claude`: `.claude/settings.local.json` (`claude-project`: `.claude/settings.json`) | PreToolUse, PostToolUse, PostToolUseFailure, Stop | exit 2, reason on stderr | live-verified (Claude Code 2.1.326) |
22
+ | Cursor | `cursor`: `.cursor/hooks.json` (`failClosed: true`) | preToolUse, postToolUse, postToolUseFailure, stop (also beforeShellExecution, beforeMCPExecution, beforeReadFile, afterFileEdit, afterShellExecution) | exit 2 and `{"permission": "deny"}`; stop: `followup_message` | spec-tested (Cursor hooks reference) |
23
+ | Codex CLI | `codex`: `.codex/hooks.json` | PreToolUse, PostToolUse, Stop | `hookSpecificOutput.permissionDecision: "deny"`; stop: `decision: "block"` | live-verified (Codex CLI 0.172.0): denied commit and config write, tree changes, Stop. Run the gates as `npx stopbar run build` / `npx stopbar run test`, because Codex reports no exit status to hooks. Codex loads project hooks only in a trusted folder |
24
+ | Gemini CLI | `gemini`: `.gemini/settings.json` | BeforeTool, AfterTool, AfterAgent | exit 2, reason on stderr; AfterAgent: `decision: "block"` | spec-tested (Gemini CLI hooks reference) |
25
+ | Antigravity CLI | `antigravity` (alias `agy`): `.agents/hooks.json` | PreToolUse, PostToolUse, Stop | `{"decision": "deny"}`; stop: `decision: "continue"` | live-verified (Antigravity CLI 1.5.18): denied early commit and config write, build and full tests recorded, honest commit allowed, Stop |
26
+ | Any tool, via git | `git`: `.git/hooks/pre-commit`, `.git/hooks/pre-push` | commit, push | exit 1 aborts git | tested with real git (E2E) |
27
+
28
+ `live-verified` means a live agent session passed through the hooks; `spec-tested` means the adapter follows the
29
+ client's published hook schema and the E2E suite runs it with payloads in that schema. Combine targets in one call:
30
+ `--hooks claude,cursor,codex,gemini,antigravity,git`.
31
+
32
+ `stopbar hook --adapter auto` (the default) detects the client from the payload, so the v1.0 Claude Code settings keep
33
+ working. An unknown or damaged payload fails closed (exit 2). The configs written by `init` pass `--adapter` explicitly.
34
+
35
+ **Git fallback.** For a tool without hooks, run the gates through Stopbar so their real exit status counts:
36
+ `npx stopbar run build` and `npx stopbar run test`. The git hooks then allow a commit only after both passed at the
37
+ current tree, block it after an unapproved test change, and block a push after a secret read without approval.
13
38
 
14
39
  ## Four pillars
15
40
 
@@ -17,10 +42,10 @@ See [SECURITY.md](SECURITY.md) for what is proven, what the wrapper enforces and
17
42
  |---|---|---|
18
43
  | PROVE | `stopbar prove`, `npm run verify:lean` | The inductive proof of the kernel, 10 mutants that must fall with a counterexample, and (release gate) `lake build` of the Lean export in a pinned Lean 4.34.0 container without network. |
19
44
  | PROBE | `stopbar probe` | Stateful probing: at least 200 random multi-step sequences of hook events, human commands and damaged files on real git repositories, compared step by step with the proven kernel. v1.0 has one target, `wrapper` (Stopbar itself). |
20
- | GATE | `stopbar init`, `hook`, `status`, `approve-tests`, `approve-shell`, `resume`, `reset`, `doctor` | The Claude Code hooks and the human commands. |
45
+ | GATE | `stopbar init`, `hook`, `git-hook`, `run`, `status`, `approve-tests`, `approve-shell`, `resume`, `reset`, `doctor` | The agent hooks, the git fallback and the human commands. |
21
46
  | ATTEST | `stopbar attest` | A deterministic attestation of the session: HEAD, tree, gates, human actions and the sha256 of the event log. |
22
47
 
23
- ## Set up with Claude Code in 3 steps
48
+ ## Set up in 3 steps
24
49
 
25
50
  Requirements: Node.js 22.18 or later, git, a git repository.
26
51
 
@@ -30,28 +55,29 @@ Requirements: Node.js 22.18 or later, git, a git repository.
30
55
  npm install --save-dev stopbar
31
56
  ```
32
57
 
33
- 2. **Initialise** with your exact build and full-test commands, and write the hooks into the local Claude Code settings:
58
+ 2. **Initialise** with your exact build and full-test commands, and write the hooks of your agents:
34
59
 
35
60
  ```sh
36
- npx stopbar init --build "npm run build" --test "npm test" --hooks local
61
+ npx stopbar init --build "npm run build" --test "npm test" --hooks claude,cursor,git
37
62
  ```
38
63
 
39
64
  Profiles for the path patterns: `--profile default|ts|python|strict`. `init` copies the runtime to
40
- `.git/stopbar/runtime/` and points the 4 hooks (`PreToolUse`, `PostToolUse`, `PostToolUseFailure`, `Stop`) to it
41
- in `.claude/settings.local.json`. Without `--hooks`, it prints the JSON to paste. A template is in
42
- [claude-hooks.example.json](claude-hooks.example.json).
65
+ `.git/stopbar/runtime/` and points every hook to it. Existing settings and hooks in those files stay; earlier
66
+ Stopbar entries are replaced. `init` does not overwrite a git hook it did not write, unless you pass
67
+ `--force-hooks` (the old hook is kept as `<name>.stopbar-backup`). Without `--hooks`, it prints the Claude Code JSON
68
+ to paste. A template is in [claude-hooks.example.json](claude-hooks.example.json).
43
69
 
44
- 3. **Check** the setup, then restart Claude Code in the repository:
70
+ 3. **Check** the setup, then restart the agent in the repository:
45
71
 
46
72
  ```sh
47
73
  npx stopbar doctor
48
74
  ```
49
75
 
50
- `doctor` checks Node, git, the kernel link, `config.json`, `state.json`, the event log and the hooks, and makes a dry
51
- run of the real hook pipeline on a scratch repository.
76
+ `doctor` checks Node, git, the kernel link, `config.json`, `state.json`, the event log and the hooks of every client
77
+ it finds, and makes a dry run of the real hook pipeline on a scratch repository.
52
78
 
53
79
  The agent must run the gate commands exactly as configured and alone, for example `npm test` and not
54
- `npm test | tail`. Commits must be one command. The commit form that Claude Code uses is allowed:
80
+ `npm test | tail`. Commits must be one command. The quoted heredoc form that agents use is allowed:
55
81
 
56
82
  ```sh
57
83
  git commit -m "$(cat <<'EOF'
@@ -66,9 +92,11 @@ EOF
66
92
 
67
93
  | Command | Who | What it does |
68
94
  |---|---|---|
69
- | `stopbar init --build "<cmd>" --test "<cmd>" [--profile p] [--max-retries 3] [--cap 500] [--cost 1] [--hooks local\|project] [--no-pin] [--force]` | human | Writes `config.json` and a fresh state, pins the runtime, writes or prints the hooks. |
70
- | `stopbar hook` | Claude Code | The hook. JSON on stdin. Exit 0 allows, exit 2 blocks (the reason goes to the agent). |
71
- | `stopbar status [--json]` | human | Revision, gates, taint, budget, and why a commit is blocked. |
95
+ | `stopbar init --build "<cmd>" --test "<cmd>" [--profile p] [--max-retries 3] [--cap 500] [--cost 1] [--hooks <targets>] [--no-pin] [--force] [--force-hooks]` | human | Writes `config.json` and a fresh state, pins the runtime, writes or prints the hooks. Targets: `claude` (`local`), `claude-project` (`project`), `cursor`, `codex`, `gemini`, `antigravity` (`agy`), `git`, comma separated. |
96
+ | `stopbar hook [--adapter auto\|claude\|cursor\|codex\|gemini\|antigravity]` | agent | The hook. JSON on stdin; the decision in the client's format (see Supported agents). |
97
+ | `stopbar git-hook pre-commit\|pre-push` | git | The git fallback gate. Exit 1 aborts the commit or push. |
98
+ | `stopbar run build\|test` | human, agent, CI | Runs the configured gate command and records its real exit status. |
99
+ | `stopbar status [--json]` | human | Revision, gates, taint, budget, why a commit is blocked, and which file or token turned the secret gate on. |
72
100
  | `stopbar approve-tests [--rev N]` | human | You reviewed the changed tests or test config up to revision N (default: the current one). |
73
101
  | `stopbar approve-shell` | human | Allows **one** risky or outbound call after a secret read. |
74
102
  | `stopbar resume --extra N` | human | Lifts a halt (retry limit or budget) and adds N to the budget. |
@@ -96,12 +124,24 @@ private snapshot index and the pinned runtime. They are outside the working tree
96
124
  "tests": ["**/tests/**", "**/*.test.*", "**/test_*.py"],
97
125
  "testConfig": ["package.json", "pyproject.toml", ".github/workflows/**"],
98
126
  "secrets": [".env*", "*.pem", "**/secrets/**"]
99
- }
127
+ },
128
+ "safeTools": ["mcp__ccd_turn__*"]
100
129
  }
101
130
  ```
102
131
 
103
132
  A pattern without `/` matches the file name anywhere. `**` is a whole path segment. Matching ignores case. Change a
104
- profile by editing the lists: no code change is necessary. A damaged or empty `config.json` or `state.json` blocks every
133
+ profile by editing the lists: no code change is necessary.
134
+
135
+ - **Secrets in shell commands.** A token in a command counts as a secret read when it matches a secret pattern. For an
136
+ extension-only pattern such as `*.key` or `*.pem`, a bare token (`claim.key`, `self.pem`) counts only when that file
137
+ exists, because it is usually a field access in code; a token with a path separator (`certs/server.key`) and every
138
+ other pattern (`.env*`, `id_rsa*`) count always. `stopbar status` says why the secret gate is on, for example
139
+ `secret read yes (matched *.key (server.key) in Bash at rev 3)`; `events.jsonl` keeps the pattern and the token,
140
+ never the file content.
141
+ - **`safeTools`** (optional) lists glob patterns of tool names that are local and never outbound. The default is
142
+ `["mcp__ccd_turn__*"]`, the task-list and turn-summary tools of Claude Desktop. It only exempts tools from the
143
+ outbound gate (WebFetch, WebSearch, MCP tools); shell commands, edits and reads are gated as before, and a halted
144
+ session still blocks every tool. A damaged or empty `config.json` or `state.json` blocks every
105
145
  tool call (exit 2) with a message that says how to repair it.
106
146
 
107
147
  ## Local use
@@ -147,17 +187,21 @@ For headless agent runs in CI, initialise Stopbar in the job and keep the eviden
147
187
 
148
188
  Each hook is a separate Node process. The hooks never load the prover. `PreToolUse` makes no git call. `PostToolUse` and
149
189
  a commit check make one: `git add -A` on a private index, which the hook then reads itself. `Stop` makes two. On
150
- Windows 11 with a 330-file repository: p50 127 ms and p95 219 ms over all hook processes. An earlier prototype that
151
- loaded the prover in every hook measured p50 981 ms and p95 1613 ms. `npm run bench` repeats the measurement.
190
+ Windows 11 with a 330-file repository, in one run with 1.0.0 as the baseline: 1.1.0 p50 94 ms and p95 234 ms over all
191
+ hook processes, including Cursor and Antigravity payloads; 1.0.0 p95 247 ms. The adapter layer adds no measurable
192
+ latency. An earlier prototype that loaded the prover in every hook measured p50 981 ms and p95 1613 ms.
193
+ `npm run bench` repeats the measurement (`--baseline <cli>` compares with another build).
152
194
 
153
195
  ## Tested platforms
154
196
 
155
197
  | Platform | Node | git | Unit | E2E | `stopbar probe` | `stopbar prove` | `stopbar doctor` |
156
198
  |---|---|---|---|---|---|---|---|
157
- | Windows 11, Git for Windows | 24.19.0 | 2.56.0 | 19/19 | 149/149 | 201/201 sequences | proven, 10/10 mutants | OK |
158
- | Linux, Debian 13 (container, no network) | 24.21.0 | 2.47.3 | 19/19 | 149/149 | 201/201 sequences | proven, 10/10 mutants | OK |
199
+ | Windows 11, Git for Windows | 24.19.0 | 2.56.0 | 28/28 | 237/237 | 201/201 sequences | proven, 10/10 mutants | OK |
200
+ | Linux, Debian 13 (container, no network) | 24.21.0 | 2.47.3 | 28/28 | 237/237 | 201/201 sequences | proven, 10/10 mutants | OK |
159
201
 
160
- The probe runs the same 200 seeds plus 1 regression on both platforms, with the same 5007 steps and 7085 hook calls.
202
+ The E2E suite runs every adapter (Cursor, Codex CLI, Gemini CLI, Antigravity CLI) and the git fallback with real
203
+ git commits and pushes. The probe runs the same 200 seeds plus 1 regression on both platforms, with the same 5007 steps
204
+ and 7085 hook calls. `stopbar doctor` passes on a fresh repository with all six `--hooks` targets.
161
205
  `npm run verify:lean` passes in the Lean 4.34.0 container: `lake build` exit 0, 0 errors, 0 `sorry`.
162
206
 
163
207
  ## License
package/SECURITY.md CHANGED
@@ -56,10 +56,15 @@ There is no proof for them.
56
56
  `git commit ... -m "$(cat <<'EOF'` … `EOF` `)"`. The delimiter is in single quotes, so bash expands nothing in the
57
57
  message. Nothing else may be in the command. Unquoted `<<EOF`, any other `$(...)`, backticks and chains are blocked.
58
58
  - **Self-protection, before the kernel, also when halted.** Edit and Write may not touch any `.git/` directory (Stopbar
59
- state, git hooks, `.git/config`), `.claude/*settings*.json`, or the Stopbar code that runs the hooks. A shell command
60
- may not name a `.git` or `.claude` directory, write git config (`git config` without `--get` or `--list`), name the
61
- Stopbar code, use a `STOPBAR_*` variable, or run a human command (`approve-tests`, `approve-shell`, `stopbar
62
- init/resume/reset`).
59
+ state, git hooks, `.git/config`), the hook configuration of a supported agent (`.claude/*settings*.json`,
60
+ `.cursor/hooks.json`, `.codex/hooks.json`, `.codex/config.toml`, `.gemini/*settings*.json`, `.gemini/**/hooks.json`,
61
+ `.agents/hooks.json`, at project and user level), or the Stopbar code that runs the hooks. A shell command may not
62
+ name a `.git`, `.claude`, `.cursor`, `.codex`, `.gemini` or `.agents` directory, write git config (`git config`
63
+ without `--get` or `--list`), name the Stopbar code, use a `STOPBAR_*` variable, or run a human command
64
+ (`approve-tests`, `approve-shell`, `stopbar init/resume/reset`).
65
+ - **One kernel for every agent.** An adapter per client (Claude Code, Cursor, Codex CLI, Gemini CLI, Antigravity CLI)
66
+ translates the hook payload into one internal event and the decision into the client's output protocol. The
67
+ adapters are wrapper code: the E2E suite runs each with payloads in the client's published schema.
63
68
  - **Pinned runtime.** `stopbar init` copies the runtime to `.git/stopbar/runtime/` and points the hooks there. An agent
64
69
  that edits or rebuilds a Stopbar checkout cannot change the code that judges it.
65
70
  - **Fail closed.** Bad hook input, a missing or damaged `config.json` or `state.json`, a busy lock, or any internal
@@ -79,7 +84,11 @@ that tries to defeat it:
79
84
  2. **Gate commands run arbitrary code.** `buildCmd` and `fullTestCmd` run the repository's code. A new test file is
80
85
  trusted. It can read secrets, use the network or weaken other checks at run time.
81
86
  3. **Secrets by file name only.** Secrets in environment variables, in files with ordinary names, or found with Grep in
82
- ordinary files are not seen. The exfiltration gate works on command text only.
87
+ ordinary files are not seen. The exfiltration gate works on command text only. In a shell command, a bare token
88
+ that matches only an extension pattern such as `*.key` counts only if that file exists (a field access like
89
+ `claim.key` is not a file); a command that names a `.key` file which does not exist yet is therefore not a read.
90
+ Tools listed in `config.safeTools` (default: Claude Desktop's `mcp__ccd_turn__*` UI tools) are not treated as
91
+ outbound; a human who adds a glob there vouches that those tools send nothing out.
83
92
  4. **Weak new tests.** A new test file is not suspicious. A mock of the system under test or an empty assertion in a
84
93
  new file passes. Hard-coded answers in production code are an ordinary code edit.
85
94
  5. **Ignored files.** Files ignored by `.gitignore` are invisible to the snapshot (for example patches in
@@ -88,21 +97,40 @@ that tries to defeat it:
88
97
  catches uncommitted work only.
89
98
  7. **Concurrency and humans.** A change made between two hook calls (a background job, a human edit) is counted as the
90
99
  agent's change at the next hook. With parallel tool calls a change can be attributed to the wrong call.
91
- 8. **Claude Code configuration.** Settings outside the repository (user settings, managed settings, `--settings`,
100
+ 8. **Agent configuration.** Settings outside the repository (user settings, managed settings, `--settings`,
92
101
  `disableAllHooks`) can remove the hooks. The hooks cover what Claude Code sends to them.
93
102
  9. **Human approvals.** `approve-tests` and `approve-shell` are only as good as the human review behind them.
103
+ 10. **Client-specific limits of the adapters.**
104
+ - Cursor: a hook exit other than 0 and 2 is fail-open unless the entry sets `failClosed: true`; `init --hooks
105
+ cursor` sets it. `afterShellExecution` carries no exit code, so a gate command seen only there never passes; the
106
+ config written by `init` uses `preToolUse` and `postToolUse`.
107
+ - Codex CLI: there is no failure event, and the tool result of a shell call is the plain output without the exit
108
+ status (seen live in 0.172.0). A gate command seen there is recorded neither as a pass nor as a failure; the agent
109
+ is told to run `stopbar run build|test`, which runs the command and records its real exit status. Codex loads
110
+ `.codex/` (config and hooks) only in a trusted project and asks the user to review and trust project hooks; until
111
+ then they do not run (a live run in an untrusted folder loaded none).
112
+ - Gemini CLI: an exit other than 0 and 2 is only a warning, and invalid JSON output counts as "allow". Stopbar exits
113
+ 2 for every block and internal error, but a crash before Stopbar's own handler (for example a missing Node.js)
114
+ fails open. Gemini CLI warns when a project hook changes and treats it as untrusted.
115
+ - Antigravity CLI: hooks of a workspace load only after the folder is trusted. A message after a tool call
116
+ (PostToolUse) cannot reach the agent; it sees the reason at its next blocked call. An allowed call returns an
117
+ empty answer, so Antigravity's own permission rules still apply on top of Stopbar (checked live).
118
+ - Git fallback: git hooks see only commits and pushes, not reads or shell commands, so the secret gate needs an agent
119
+ hook to record the read. `git commit --no-verify` and `git push --no-verify` skip git hooks.
94
120
 
95
121
  For a hostile-agent threat model, run the agent in a container or VM: no network by default, the repository mounted
96
122
  read-write, `.git/stopbar` and `.claude` mounted read-only or owned by another user, and the human commands run outside
97
123
  the sandbox. Stopbar's kernel then gives the proven decisions and the sandbox gives the boundary.
98
124
 
99
- ## Known limits of 1.0.0
125
+ ## Known limits of 1.1.0
100
126
 
101
127
  - Lean: the check needs Docker and a one-time image build with network access. The base image is pinned by digest and
102
128
  the Lean archive by sha256, both recorded at the first build (trust on first use). The Lean export is not
103
129
  deterministic: each export is a different proof tree, and the gate checks the one it exports.
104
130
  - Platforms: the unit tests, E2E, `stopbar probe` and `stopbar prove` pass on Windows 11 with Git for Windows and on
105
131
  Linux (Debian 13, Node 24, git 2.47). A live Claude Code session ran on Windows. macOS is not tested.
132
+ - Adapters: Cursor, Codex CLI, Gemini CLI and Antigravity CLI are spec-tested (see the README table); a client can
133
+ change its hook schema in a later version.
106
134
  - Hook latency: Windows starts a process in 50–70 ms, so a hook with one git process takes about 120–200 ms in all.
107
135
 
108
136
  ## Reporting a vulnerability
@@ -0,0 +1,45 @@
1
+ // Built from src/adapters/antigravity.ts by scripts/build.ts. Do not edit.
2
+ // Antigravity CLI (agy; hooks.json in the customization root, e.g. <workspace>/.agents/hooks.json). camelCase payloads:
3
+ // hookEventName, toolCall {id, name, args}, cwd, workspacePaths; PostToolUse carries `error` when the tool failed;
4
+ // Stop carries continuationActive. Output is JSON on stdout: PreToolUse {"decision": "deny", "reason"}; Stop
5
+ // {"decision": "continue", "reason"} keeps the agent working. Tool names are the lower-cased step types.
6
+ import { byName, commandText, edit, json, make, outbound, pathsOf, read, shell, } from './types.js'
7
+
8
+ // names seen in a live Antigravity CLI 1.5.18 session (write_file with Path) plus the step types of its hooks spec
9
+ const EDIT = new Set(['write_file', 'write_to_file', 'replace_file_content', 'multi_replace_file_content', 'sed_file', 'notebook_edit', 'code_action',
10
+ 'file_change', 'propose_code', 'write_blob', 'edit_notebook', 'delete_directory', 'move'])
11
+ const READ = new Set(['view_file', 'view_file_outline', 'view_code_item', 'view_content_chunk', 'read_notebook', 'list_directory', 'list_dir', 'find', 'find_by_name', 'code_search', 'read_resource'])
12
+ const OUT = new Set(['read_url_content', 'search_web', 'open_browser_url', 'read_browser_page', 'execute_browser_javascript', 'click_browser_pixel', 'mcp_tool', 'call_mcp_tool'])
13
+
14
+ function tool(name , args ) {
15
+ if (name === 'run_command' || name === 'shell_exec' || name === 'send_command_input' || name === 'notebook_execution') return shell(commandText(args.CommandLine ?? args.Command ?? args.command ?? args.Input ?? ''))
16
+ if (EDIT.has(name)) return edit(pathsOf(args))
17
+ if (READ.has(name)) return read(pathsOf(args))
18
+ if (name === 'grep_search') return {tool_name: 'Grep', tool_input: {pattern: args.Query ?? args.query, path: args.SearchPath ?? args.SearchDirectory}}
19
+ if (OUT.has(name) || name.startsWith('browser_') || name.startsWith('capture_browser_')) return outbound(name === 'mcp_tool' || name === 'call_mcp_tool' ? `mcp__${args.ServerName ?? args.serverName ?? 'server'}__${args.ToolName ?? args.toolName ?? 'tool'}` : name)
20
+ return byName(name, args, args.CommandLine)
21
+ }
22
+
23
+ export const antigravity = {
24
+ name: 'antigravity',
25
+ detect: (i) => typeof i.hookEventName === 'string' || (typeof i.toolCall === 'object' && i.toolCall !== null) || typeof i.conversationId === 'string',
26
+ normalize(i) {
27
+ const ev = String(i.hookEventName ?? '')
28
+ const cwd = typeof i.cwd === 'string' && i.cwd ? i.cwd : Array.isArray(i.workspacePaths) ? i.workspacePaths[0] : undefined
29
+ const call = (i.toolCall ?? {})
30
+ const args = (call.args && typeof call.args === 'object' ? call.args : {})
31
+ if (ev === 'PreToolUse') return {kind: 'pre-tool', event: make('antigravity', i, ev, {hook_event_name: 'PreToolUse', cwd, ...tool(String(call.name ?? ''), args)}, {tool: call.name})}
32
+ if (ev === 'PostToolUse') {
33
+ const failed = typeof i.error === 'string' ? i.error.length > 0 : !!i.error
34
+ return {kind: failed ? 'post-tool-failure' : 'post-tool', event: make('antigravity', i, ev, {hook_event_name: failed ? 'PostToolUseFailure' : 'PostToolUse', cwd,
35
+ ...tool(String(call.name ?? ''), args), tool_response: failed ? {error: i.error} : {}}, {tool: call.name})}
36
+ }
37
+ if (ev === 'Stop') return {kind: 'stop', event: make('antigravity', i, ev, {hook_event_name: 'Stop', cwd, stop_hook_active: i.continuationActive === true})}
38
+ return {kind: 'other', event: null}
39
+ },
40
+ render(kind, out) {
41
+ if (kind === 'pre-tool') return out.code === 0 ? {code: 0} : {code: 0, stdout: json({decision: 'deny', reason: out.msg ?? 'blocked by stopbar'}) + '\n', stderr: (out.msg ?? '') + '\n'}
42
+ if (kind === 'stop') return out.code !== 0 && out.msg ? {code: 0, stdout: json({decision: 'continue', reason: out.msg}) + '\n'} : {code: 0, stdout: '{}\n'}
43
+ return {code: 0, stdout: '{}\n'}
44
+ },
45
+ }
@@ -0,0 +1,19 @@
1
+ // Built from src/adapters/claude.ts by scripts/build.ts. Do not edit.
2
+ // Claude Code: the payload already is the internal event (v1.0 behaviour, unchanged).
3
+ // Output: exit 0 allows, exit 2 blocks; the reason goes to stderr (stdout for exit 0 messages).
4
+
5
+
6
+ const KIND = {PreToolUse: 'pre-tool', PostToolUse: 'post-tool', PostToolUseFailure: 'post-tool-failure', Stop: 'stop'}
7
+
8
+ export const claude = {
9
+ name: 'claude',
10
+ detect: (i) => typeof i.hook_event_name === 'string',
11
+ normalize(i) {
12
+ const kind = KIND[i.hook_event_name] ?? 'other'
13
+ return {kind, event: kind === 'other' ? null : (i )}
14
+ },
15
+ render(_kind, out) {
16
+ if (!out.msg) return {code: out.code}
17
+ return out.code === 0 ? {code: 0, stdout: out.msg + '\n'} : {code: out.code, stderr: out.msg + '\n'}
18
+ },
19
+ }
@@ -0,0 +1,48 @@
1
+ // Built from src/adapters/codex.ts by scripts/build.ts. Do not edit.
2
+ // Codex CLI (hooks.json, Claude Code compatible events). Schemas from the CLI's own command-hook JSON schemas
3
+ // (pre-tool-use / post-tool-use / stop .command.input and .command.output): every input carries turn_id and model.
4
+ // There is no failure event: PostToolUse also follows a failed command, so a gate passes only with an exit code 0
5
+ // found in tool_response. Output: JSON on stdout with exit 0 (permissionDecision deny / decision block).
6
+ import { byName, commandText, edit, exitCodeIn, json, make, patchPaths, shell, } from './types.js'
7
+
8
+ const SHELL = new Set(['Bash', 'shell', 'exec_command', 'local_shell', 'unified_exec', 'shell_command', 'container.exec'])
9
+
10
+ function tool(name , ti ) {
11
+ if (SHELL.has(name)) return shell(commandText(ti.command ?? ti.cmd ?? ti.argv))
12
+ if (name === 'apply_patch') return edit(patchPaths(ti.input ?? ti.patch ?? ti.command))
13
+ if (name.startsWith('mcp__')) return {tool_name: name, tool_input: ti}
14
+ if (['Edit', 'Write', 'MultiEdit', 'Read', 'Grep', 'Glob', 'WebFetch', 'WebSearch'].includes(name)) return {tool_name: name, tool_input: ti}
15
+ return byName(name, ti, ti.command)
16
+ }
17
+
18
+ export const codex = {
19
+ name: 'codex',
20
+ detect: (i) => typeof i.hook_event_name === 'string' && typeof i.turn_id === 'string',
21
+ normalize(i) {
22
+ const ev = i.hook_event_name, ti = (i.tool_input && typeof i.tool_input === 'object' ? i.tool_input : {})
23
+ if (ev === 'PreToolUse') {
24
+ const t = tool(String(i.tool_name ?? ''), ti)
25
+ return {kind: 'pre-tool', event: make('codex', i, ev, {hook_event_name: 'PreToolUse', cwd: i.cwd, ...t}, {tool: i.tool_name})}
26
+ }
27
+ if (ev === 'PostToolUse') {
28
+ const t = tool(String(i.tool_name ?? ''), ti)
29
+ const code = exitCodeIn(i.tool_response)
30
+ const failed = code !== undefined && code !== 0
31
+ return {kind: failed ? 'post-tool-failure' : 'post-tool',
32
+ event: make('codex', i, ev, {hook_event_name: failed ? 'PostToolUseFailure' : 'PostToolUse', cwd: i.cwd, ...t,
33
+ tool_response: code === undefined ? i.tool_response : {exitCode: code}}, {requireExitCode: true, tool: i.tool_name})}
34
+ }
35
+ if (ev === 'Stop') return {kind: 'stop', event: make('codex', i, ev, {hook_event_name: 'Stop', cwd: i.cwd, stop_hook_active: i.stop_hook_active === true})}
36
+ return {kind: 'other', event: null}
37
+ },
38
+ render(kind , out) {
39
+ if (kind === 'pre-tool') {
40
+ if (out.code === 0) return {code: 0}
41
+ return {code: 0, stdout: json({hookSpecificOutput: {hookEventName: 'PreToolUse', permissionDecision: 'deny', permissionDecisionReason: out.msg ?? 'blocked by stopbar'}}) + '\n', stderr: (out.msg ?? '') + '\n'}
42
+ }
43
+ if (kind === 'post-tool' || kind === 'post-tool-failure' || kind === 'stop') {
44
+ return out.msg && out.code !== 0 ? {code: 0, stdout: json({decision: 'block', reason: out.msg}) + '\n'} : {code: 0}
45
+ }
46
+ return {code: 0}
47
+ },
48
+ }
@@ -0,0 +1,63 @@
1
+ // Built from src/adapters/cursor.ts by scripts/build.ts. Do not edit.
2
+ // Cursor (.cursor/hooks.json, version 1). Every payload carries conversation_id, generation_id and cursor_version.
3
+ // Events: preToolUse / postToolUse / postToolUseFailure / stop, and the older beforeShellExecution, beforeMCPExecution,
4
+ // beforeReadFile, afterFileEdit, afterShellExecution. Permission events: exit 2 denies, and the JSON on stdout carries
5
+ // permission "deny" with user_message and agent_message. Other non-zero exits are fail-open unless the entry sets
6
+ // failClosed: true, so `stopbar init --hooks cursor` writes failClosed: true.
7
+ import { byName, commandText, edit, exitCodeIn, json, make, outbound, pathsOf, read, shell, } from './types.js'
8
+
9
+ function tool(name , ti ) {
10
+ if (name === 'Shell') return shell(commandText(ti.command))
11
+ if (name === 'Read') return read(pathsOf(ti))
12
+ if (['Write', 'Edit', 'Delete', 'StrReplace', 'MultiEdit', 'ApplyPatch'].includes(name)) return edit(pathsOf(ti))
13
+ if (name === 'Grep' || name === 'Glob') return {tool_name: name, tool_input: {pattern: ti.pattern, path: ti.path}}
14
+ if (name.startsWith('MCP:')) return outbound(`mcp__${name.slice(4)}`)
15
+ if (name === 'WebFetch' || name === 'WebSearch') return {tool_name: name, tool_input: ti}
16
+ return byName(name, ti, ti.command)
17
+ }
18
+ const toolInput = (x ) => {
19
+ if (typeof x === 'string') { try { const o = JSON.parse(x); return o && typeof o === 'object' ? o : {} } catch { return {} } }
20
+ return x && typeof x === 'object' ? (x ) : {}
21
+ }
22
+ const PERMISSION = new Set(['preToolUse', 'beforeShellExecution', 'beforeMCPExecution', 'beforeReadFile'])
23
+
24
+ export const cursor = {
25
+ name: 'cursor',
26
+ detect: (i) => typeof i.cursor_version === 'string' || (typeof i.conversation_id === 'string' && typeof i.generation_id === 'string'),
27
+ normalize(i) {
28
+ const ev = String(i.hook_event_name ?? '')
29
+ const cwd = typeof i.cwd === 'string' && i.cwd ? i.cwd : Array.isArray(i.workspace_roots) ? i.workspace_roots[0] : undefined
30
+ const base = (t ) => ({cwd, ...t})
31
+ switch (ev) {
32
+ case 'preToolUse': return {kind: 'pre-tool', event: make('cursor', i, ev, {hook_event_name: 'PreToolUse', ...base(tool(String(i.tool_name ?? ''), toolInput(i.tool_input)))}, {tool: i.tool_name})}
33
+ case 'beforeShellExecution': return {kind: 'pre-tool', event: make('cursor', i, ev, {hook_event_name: 'PreToolUse', ...base(shell(commandText(i.command)))})}
34
+ case 'beforeMCPExecution': return {kind: 'pre-tool', event: make('cursor', i, ev, {hook_event_name: 'PreToolUse', ...base(outbound(`mcp__${i.mcp_server_name ?? 'server'}__${i.tool_name ?? 'tool'}`))})}
35
+ case 'beforeReadFile': return {kind: 'pre-tool', event: make('cursor', i, ev, {hook_event_name: 'PreToolUse', ...base(read(pathsOf(i)))})}
36
+ case 'postToolUse': {
37
+ const out = toolInput(i.tool_output)
38
+ const code = exitCodeIn(out)
39
+ const failed = code !== undefined && code !== 0
40
+ return {kind: failed ? 'post-tool-failure' : 'post-tool', event: make('cursor', i, ev, {hook_event_name: failed ? 'PostToolUseFailure' : 'PostToolUse',
41
+ ...base(tool(String(i.tool_name ?? ''), toolInput(i.tool_input))), tool_response: code === undefined ? out : {exitCode: code}}, {tool: i.tool_name})}
42
+ }
43
+ case 'postToolUseFailure': return {kind: 'post-tool-failure', event: make('cursor', i, ev, {hook_event_name: 'PostToolUseFailure',
44
+ ...base(tool(String(i.tool_name ?? ''), toolInput(i.tool_input))), is_interrupt: i.is_interrupt === true || i.failure_type === 'permission_denied'}, {tool: i.tool_name})}
45
+ case 'afterFileEdit': return {kind: 'post-tool', event: make('cursor', i, ev, {hook_event_name: 'PostToolUse', ...base(edit(pathsOf(i)))})}
46
+ // no exit code in afterShellExecution: a gate command seen only here never passes (use postToolUse)
47
+ case 'afterShellExecution': return {kind: 'post-tool', event: make('cursor', i, ev, {hook_event_name: 'PostToolUse', ...base(shell(commandText(i.command)))}, {requireExitCode: true})}
48
+ case 'stop': return {kind: 'stop', event: make('cursor', i, ev, {hook_event_name: 'Stop', cwd, stop_hook_active: Number(i.loop_count) > 0})}
49
+ default: return {kind: 'other', event: null}
50
+ }
51
+ },
52
+ render(kind, out, input) {
53
+ const ev = String(input?.hook_event_name ?? 'preToolUse')
54
+ if (kind === 'pre-tool' || PERMISSION.has(ev)) {
55
+ if (out.code === 0) return {code: 0, stdout: json({permission: 'allow'}) + '\n'}
56
+ const m = out.msg ?? 'blocked by stopbar'
57
+ return {code: 2, stdout: json({permission: 'deny', user_message: m, agent_message: m}) + '\n', stderr: m + '\n'}
58
+ }
59
+ if (kind === 'stop') return out.code !== 0 && out.msg ? {code: 0, stdout: json({followup_message: out.msg}) + '\n'} : {code: 0, stdout: '{}\n'}
60
+ if (kind === 'post-tool' || kind === 'post-tool-failure') return out.msg ? {code: 0, stdout: json({additional_context: out.msg}) + '\n'} : {code: 0, stdout: '{}\n'}
61
+ return {code: 0, stdout: '{}\n'}
62
+ },
63
+ }
@@ -0,0 +1,47 @@
1
+ // Built from src/adapters/gemini.ts by scripts/build.ts. Do not edit.
2
+ // Gemini CLI (.gemini/settings.json "hooks"). Events BeforeTool, AfterTool and AfterAgent (the end of a turn). Exit 2 is
3
+ // a system block with the reason on stderr; any other non-zero exit is only a warning and the call proceeds, and
4
+ // invalid JSON on stdout counts as "allow". Stopbar exits 2 for every block and fail-closed error.
5
+ import { byName, commandText, edit, exitCodeIn, json, make, outbound, pathsOf, read, shell, } from './types.js'
6
+
7
+ const UNIQUE = new Set(['BeforeTool', 'AfterTool', 'BeforeAgent', 'AfterAgent', 'BeforeModel', 'AfterModel', 'BeforeToolSelection', 'PreCompress', 'Notification'])
8
+
9
+ function tool(name , ti ) {
10
+ switch (name) {
11
+ case 'run_shell_command': return shell(commandText(ti.command))
12
+ case 'write_file': case 'replace': return edit(pathsOf(ti))
13
+ case 'read_file': case 'read_many_files': return read([...pathsOf(ti), ...(Array.isArray(ti.include) ? ti.include : [])])
14
+ case 'glob': return {tool_name: 'Glob', tool_input: {pattern: ti.pattern, path: ti.dir_path}}
15
+ case 'grep_search': case 'search_file_content': return {tool_name: 'Grep', tool_input: {pattern: ti.pattern, path: ti.dir_path}}
16
+ case 'web_fetch': return {tool_name: 'WebFetch', tool_input: {}}
17
+ case 'google_web_search': return {tool_name: 'WebSearch', tool_input: {}}
18
+ }
19
+ if (name.startsWith('mcp_')) return outbound(`mcp__${name.slice(4)}`)
20
+ return byName(name, ti, ti.command)
21
+ }
22
+
23
+ export const gemini = {
24
+ name: 'gemini',
25
+ detect: (i) => typeof i.hook_event_name === 'string' && (UNIQUE.has(i.hook_event_name) || (typeof i.timestamp === 'string' && /^Session(Start|End)$/.test(i.hook_event_name))),
26
+ normalize(i) {
27
+ const ev = String(i.hook_event_name), ti = (i.tool_input && typeof i.tool_input === 'object' ? i.tool_input : {})
28
+ if (ev === 'BeforeTool') return {kind: 'pre-tool', event: make('gemini', i, ev, {hook_event_name: 'PreToolUse', cwd: i.cwd, ...tool(String(i.tool_name ?? ''), ti)}, {tool: i.tool_name})}
29
+ if (ev === 'AfterTool') {
30
+ const r = (i.tool_response ?? {})
31
+ const code = exitCodeIn(r)
32
+ const failed = !!r.error || (code !== undefined && code !== 0)
33
+ return {kind: failed ? 'post-tool-failure' : 'post-tool', event: make('gemini', i, ev, {hook_event_name: failed ? 'PostToolUseFailure' : 'PostToolUse', cwd: i.cwd,
34
+ ...tool(String(i.tool_name ?? ''), ti), tool_response: code === undefined ? r : {exitCode: code}}, {tool: i.tool_name})}
35
+ }
36
+ if (ev === 'AfterAgent') return {kind: 'stop', event: make('gemini', i, ev, {hook_event_name: 'Stop', cwd: i.cwd, stop_hook_active: i.stop_hook_active === true})}
37
+ return {kind: 'other', event: null}
38
+ },
39
+ render(kind, out) {
40
+ if (kind === 'pre-tool') return out.code === 0 ? {code: 0, stdout: '{}\n'} : {code: 2, stderr: (out.msg ?? 'blocked by stopbar') + '\n'}
41
+ if (kind === 'stop') return out.code !== 0 && out.msg ? {code: 0, stdout: json({decision: 'block', reason: out.msg}) + '\n'} : {code: 0, stdout: '{}\n'}
42
+ if (kind === 'post-tool' || kind === 'post-tool-failure') {
43
+ return out.msg ? {code: 0, stdout: json({hookSpecificOutput: {hookEventName: 'AfterTool', additionalContext: out.msg}}) + '\n'} : {code: 0, stdout: '{}\n'}
44
+ }
45
+ return {code: 0, stdout: '{}\n'}
46
+ },
47
+ }
@@ -0,0 +1,45 @@
1
+ // Built from src/adapters/index.ts by scripts/build.ts. Do not edit.
2
+ // `stopbar hook --adapter auto|claude|cursor|codex|gemini|antigravity`. Auto detection is deterministic and ordered by
3
+ // the most specific marker; a payload no adapter recognises fails closed (exit 2). Claude Code payloads (v1.0) are
4
+ // detected as claude, so existing settings keep working without --adapter.
5
+ import { runEvent} from '../hook.js'
6
+ import {antigravity} from './antigravity.js'
7
+ import {claude} from './claude.js'
8
+ import {codex} from './codex.js'
9
+ import {cursor} from './cursor.js'
10
+ import {gemini} from './gemini.js'
11
+ import {ADAPTERS, } from './types.js'
12
+
13
+ export const BY_NAME = {claude, codex, cursor, gemini, antigravity}
14
+ // order matters: camelCase Antigravity, Cursor ids, Gemini-only event names, Codex turn_id, then Claude Code
15
+ const ORDER = [antigravity, cursor, gemini, codex, claude]
16
+
17
+ export function detect(input ) {
18
+ for (const a of ORDER) if (a.detect(input)) return a
19
+ return null
20
+ }
21
+
22
+ const ALIASES = {agy: 'antigravity', 'claude-code': 'claude'}
23
+ export function adapterByName(n ) {
24
+ const k = (ALIASES[n] ?? n)
25
+ return ADAPTERS.includes(k) ? BY_NAME[k] : null
26
+ }
27
+
28
+ const failClosed = (why ) => ({code: 2, msg: `STOPBAR FAIL-CLOSED: ${why}`})
29
+
30
+ /** One hook call: raw stdin JSON in, the client's exit code and output out. Never throws. */
31
+ export function handle(raw , which = 'auto', t0 = performance.now()) {
32
+ const explicit = which === 'auto' ? null : adapterByName(which)
33
+ if (which !== 'auto' && !explicit) return claude.render('pre-tool', failClosed(`unknown adapter ${JSON.stringify(which)}; known: auto, ${ADAPTERS.join(', ')}`), null)
34
+ let input
35
+ try { input = JSON.parse(raw) } catch (e) { return (explicit ?? claude).render('pre-tool', failClosed(`hook input is not JSON (${(e ).message})`), null) }
36
+ if (!input || typeof input !== 'object' || Array.isArray(input)) return (explicit ?? claude).render('pre-tool', failClosed('hook input must be a JSON object'), null)
37
+ const a = explicit ?? detect(input)
38
+ if (!a) return claude.render('pre-tool', failClosed('unknown hook payload: no adapter recognises it (use --adapter)'), null)
39
+ let n
40
+ try { n = a.normalize(input) } catch (e) { return a.render('pre-tool', failClosed(`cannot read the ${a.name} payload (${(e ).message})`), input) }
41
+ if (!n.event) return a.render('other', {code: 0}, input)
42
+ return a.render(n.kind, runEvent(n.event, t0), input)
43
+ }
44
+
45
+ export {ADAPTERS}