stopbar 1.2.0 → 1.2.2

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/SECURITY.md CHANGED
@@ -7,6 +7,10 @@ is proven (section 1), what the wrapper enforces and how it is tested (section 2
7
7
  without an operating-system sandbox (section 3). Without an OS sandbox, Stopbar stops shortcuts and mistakes of an
8
8
  agent; it is not a security boundary against a hostile agent.
9
9
 
10
+ | Proven (Lean 4.34.0) | Tested (wrapper + E2E + PROBE) | Not covered without OS sandbox |
11
+ |---|---|---|
12
+ | The decision rule `src/kernel.ts`: laws L1, L2.1, L2.2, L3.1–L3.3, L4.1–L4.4 (section 1), with 10 mutants that each fall with a counterexample. | How tool calls become kernel requests (section 2): gate commands, tree snapshots, path patterns, self-protection, client adapters, git hooks. | Names built at run time, scripts the agent runs, code that the gates run, secrets in ordinary files, a writable state directory (section 3). |
13
+
10
14
  ## 1. What is proven
11
15
 
12
16
  The decision rule is `src/kernel.ts`, written in the gdp-wired 0.60.0 DSL. `stopbar prove` runs an inductive proof of
@@ -96,10 +100,32 @@ There is no proof for them.
96
100
  so a prompt may mention `approve-tests`; this does not apply when the command line pipes, redirects with `>`/`>>`,
97
101
  expands a variable, or names a shell, an interpreter, `xargs`, `at`, `tee` or
98
102
  `stopbar`. `.git`, the agent settings directories and the Stopbar code stay protected inside the body.
99
- - **Halted sessions.** While halted, every tool is paused except the tools in `config.safeTools` (default: the local
100
- task-list, turn and session-message tools of Claude Desktop), so the agent can still ask a human for `stopbar resume`.
101
- These tools never take a kernel step, so they cannot change the state that laws L4.1 and L4.4 speak about. Edit,
102
- Write, Read, Bash, WebFetch and every other MCP tool stay paused.
103
+ - **Since 1.2.1, wildcards and expansions.** A wildcard that reaches `.git` or an agent settings directory is blocked
104
+ for `rm`, `rmdir`, `unlink`, `shred`, `mv`, `del`, `erase`, `rd`, `move`, `Remove-Item` and `Move-Item` (`rm -rf
105
+ .g*`, `mv .cl* x`, `rm -rf .*`), and for any command when a path inside follows (`cp x .g*/hooks/pre-commit`). In
106
+ Bash a quoted or escaped wildcard does not expand and does not count. A git subcommand that comes from an expansion
107
+ (`git $f -m x`, `p=push; git $p`, `git "${cmd}"`, ``git `echo push` ``) is blocked, because the commit and push gates
108
+ cannot see it. A secret read is also: a command that prints the environment (`printenv`, a bare `env`,
109
+ `Get-ChildItem Env:`, `/proc/self/environ`); a path with `..` segments (`cat src/../.env`); a live wildcard that
110
+ reaches a secret name (`cat .en*`, `cat .en?`, `cat src/../.en*`). `env VAR=1 cmd` and `set` are not a read.
111
+ - **Since 1.2.2, git hook managers, `$(pwd)` and `find`.** Edit and Write may not touch `.husky/**`, `lefthook*.yml`,
112
+ `.lefthook*.yml` (also `.yaml` and `-local`), `.lefthook/**` or any file in a custom `core.hooksPath`, and a shell
113
+ command may not name them (matched on path-segment boundaries; an empty, `.` or `/` value is ignored, and a value that
114
+ is the working tree root or above it protects nothing). The hook reads `core.hooksPath` from `<common-dir>/config`
115
+ and `<git-dir>/config.worktree` (no git process; include files are not followed). These files are test config in
116
+ every profile. `.husky` and `.lefthook` are guarded against wildcards like `.git`. `$(pwd)`, `${PWD}`, `$PWD` and
117
+ `` `pwd` `` (also in double quotes) read as `.` for the wildcard and secret checks. `find` with a `-name`, `-iname`,
118
+ `-path`, `-ipath`, `-wholename` or `-iwholename` pattern (find expands it itself, also when quoted) that reaches a
119
+ guarded directory, with `-delete`, `-exec`, `-execdir`, `-ok` or `-okdir`, is blocked; one that reaches a secret name
120
+ with an `-exec` action is a secret read. `stopbar doctor` reports `[FAIL] hooks git` when a Stopbar git hook that
121
+ was written, has run, or is called in `HEAD` is gone, and `stopbar doctor --strict` fails on any `[WARN]` (CI).
122
+ - **Halted sessions.** While halted, every tool is paused except the tools in `config.safeTools` (default:
123
+ `mcp__ccd_turn__*` and `mcp__ccd_session_mgmt__*`, the local task-list, turn and session-message tools of Claude
124
+ Desktop), so the agent can still ask a human for `stopbar resume`. These tools never take a kernel step, so they
125
+ cannot change the state that laws L4.1 and L4.4 speak about. Edit, Write, Read, Bash, WebFetch and every other MCP
126
+ tool stay paused. Edit, Write, Read and the shell tools stay paused even when a `safeTools` glob matches them (the
127
+ E2E suite checks `safeTools: ["*"]`). Keep the globs narrow: a broad glob such as `mcp__*` lets every MCP tool
128
+ through while halted and after a secret read.
103
129
  - **`requireRun`.** With `config.requireRun: true`, a build or full test run counts only through `stopbar run
104
130
  build|test`; the same command from the agent's shell is recorded neither as a pass nor as a failure.
105
131
  - **One kernel for every agent.** An adapter per client (Claude Code, Cursor, Codex CLI, Gemini CLI, Antigravity CLI)
@@ -125,8 +151,9 @@ that tries to defeat it:
125
151
  test "known limits without an OS sandbox" keeps these cases visible.
126
152
  2. **Gate commands run arbitrary code.** `buildCmd` and `fullTestCmd` run the repository's code. A new test file is
127
153
  trusted. It can read secrets, use the network or weaken other checks at run time.
128
- 3. **Secrets by file name only.** Secrets in environment variables, in files with ordinary names, or found with Grep in
129
- ordinary files are not seen. The exfiltration gate works on command text only. In a shell command, a bare token
154
+ 3. **Secrets by file name only.** Secrets in files with ordinary names, or found with Grep in ordinary files, are not
155
+ seen. A command that prints the whole environment counts as a secret read since 1.2.1; one variable in a command
156
+ (`echo $TOKEN`) or a dump through another program (`export -p`, `node -e "console.log(process.env)"`) is not seen. The exfiltration gate works on command text only. In a shell command, a bare token
130
157
  that matches only an extension pattern such as `*.key` counts only if that file exists (a field access like
131
158
  `claim.key` is not a file); a command that names a `.key` file which does not exist yet is therefore not a read.
132
159
  Tools listed in `config.safeTools` (default: Claude Desktop's `mcp__ccd_turn__*` UI tools and its
@@ -176,9 +203,19 @@ that tries to defeat it:
176
203
  - Git fallback: git hooks see only commits and pushes, not reads or shell commands, so the secret gate needs an agent
177
204
  hook to record the read. `git commit --no-verify` and `git push --no-verify` skip git hooks.
178
205
 
179
- For a hostile-agent threat model, run the agent in a container or VM: no network by default, the repository mounted
180
- read-write, `.git/stopbar` and `.claude` mounted read-only or owned by another user, and the human commands run outside
181
- the sandbox. Stopbar's kernel then gives the proven decisions and the sandbox gives the boundary.
206
+ **Hardening: OS sandbox + client deny rules.** For a hostile-agent threat model, add two layers that do not read
207
+ command text:
208
+
209
+ - Client deny rules refuse a tool call before any hook. Claude Code example in `.claude/settings.json` (check the rule
210
+ syntax against your client's documentation):
211
+ `{"permissions": {"deny": ["Read(./.env)", "Read(./.env.*)", "Read(./secrets/**)", "Edit(./.git/**)", "Edit(./.claude/**)", "Bash(curl:*)", "Bash(wget:*)", "Bash(printenv:*)", "WebFetch"]}}`.
212
+ - Run the agent in a container, a VM or a sandbox runtime (for example Anthropic's `sandbox-runtime` or Claude Code's
213
+ Bash sandbox): no network by default, the repository writable, `.claude/` and `.git/hooks/` read-only, for example
214
+ `docker run --rm -it --network none -v "$PWD:/work" -v "$PWD/.claude:/work/.claude:ro" -v "$PWD/.git/hooks:/work/.git/hooks:ro" -w /work <agent-image>`.
215
+ The hooks write `.git/stopbar/`: when they run inside the same sandbox as the agent's shell, the shell can write it
216
+ too. A sandbox that wraps only the agent's shell (the hooks run outside it) can deny writes to `.git/stopbar/`. Run
217
+ the human commands outside the sandbox. Stopbar's kernel then gives the proven decisions and the sandbox gives the
218
+ boundary.
182
219
 
183
220
  ## 4. PROBE, `--cmd` and probe evidence
184
221
 
@@ -191,74 +228,75 @@ the sandbox. Stopbar's kernel then gives the proven decisions and the sandbox gi
191
228
  - `probe:result` in `events.jsonl` is evidence, not a gate. It has no `req`, it is not a kernel step and it does not
192
229
  change `state.json`, so it can never allow a commit. It is appended under Stopbar's lock, like every other entry.
193
230
  - `stopbar attest` shows the latest `probe:result` per target since the last `init` or `reset`, with the sha256 of the
194
- target file (`targetSha256`), the command (`targetCmd`), the tree snapshot and `atCurrentSnapshot`. The entry says
195
- what the prober saw on that tree. It does not prove the target file: an agent that can write to `events.jsonl` can
196
- also write a false entry, as for every other log line (see section 3). Compare `targetSha256` with the file you
197
- reviewed.
231
+ target file (`targetSha256`), the command (`targetCmd`), the tree snapshot and `atCurrentSnapshot`. **Probe evidence
232
+ is the recorded result of one run, tied to the tree snapshot and to the hash of the prober file.** It says what the
233
+ prober saw on that tree. It is no proof against a hostile agent without an OS sandbox: an agent that can write to
234
+ `events.jsonl` can also write a false entry, as for every other log line (see section 3). Compare `targetSha256`
235
+ with the file you reviewed.
198
236
  - For `--cmd`, `targetSha256` covers one file only: `--target-file`, else the first existing file after the
199
237
  interpreter, else nothing (`null`). Imports, libraries and the interpreter are not hashed.
200
238
 
201
- ## Known limits of 1.2.0
239
+ ## Known limits of 1.2.2
202
240
 
203
- - `safeTools` in `HALT`: a halted session still lets the tools in `config.safeTools` through. A human who adds a glob
204
- there vouches that those tools are local; with a broad glob (for example `mcp__*`) a halted agent keeps those tools.
205
- Edit, Write, Read, the shell and every tool outside the list stay paused.
206
- - `--require-run` decides by the event's source (`stopbar run` or an agent hook), not by what ran. Without it, the
207
- exact gate command from the agent's shell still counts, as before.
208
- - Quote splicing: only quotes inside a word are undone (`.e""nv`, `.e"n"v`, `'.cl'"aude"`, `gi"t"`). A path built at
209
- run time (`g=.g; d=$g"it"`), a backslash escape, a variable or a script (`node /tmp/x.js`) passes the text checks;
210
- section 3 point 1. Only an OS sandbox closes this.
211
- - The stdin heredoc exception trusts the command on the header line not to run its stdin. Stopbar knows the common
212
- shells and interpreters (and `xargs`, `at`, `tee`, `stopbar`); another program that executes stdin passes. The
213
- exception covers only `HUMAN_ONLY` and `STOPBAR_ADMIN`; every other check still reads the body.
214
- - Git hooks by default: a foreign `pre-commit` or `pre-push` is kept with a `WARN` when the git hooks were added by
215
- default; then that git action is not gated until a human runs `stopbar upgrade --hooks git --force-hooks`.
216
- `stopbar doctor` reports `[WARN] hooks git` while one of the two Stopbar git hooks is missing.
217
- - `stopbar doctor` checks the kernel link only where `gdp-wired` resolves from the running copy (`import.meta.resolve`).
218
- A pinned runtime outside any `node_modules` tree reports `[WARN] kernel link`; run `stopbar prove` in the package.
219
- - `--cmd`: the command runs through the system shell (`cmd.exe` on Windows, `/bin/sh` elsewhere), so quoting follows
220
- that shell. A shell can hold stdout open after the program closed it; then only `--cmd-timeout` (default 300000 ms)
221
- ends the wait.
222
- - `--cmd`: answers are checked for their shape (`name`, `seed`, `actions`, `ok`, `steps`, `cov`, `mismatch.step`,
223
- `mismatch.what`), not for meaning. A program that answers `ok: true` without running anything passes. Mutants
224
- (`--check-mutants`) are the check that the model can fail.
225
- - `--cmd`: Stopbar does not check that `generate` is deterministic. A reproduction replays the saved actions, so it
226
- stays valid, but a new run of the same seed can differ if the program uses another source of randomness.
227
- - `probe init --lang py` prints `python` on Windows and `python3` elsewhere; use the name your system has.
228
- - `probe init --lang ts` writes a file that imports `stopbar/probe`: it runs only where that import resolves (Stopbar
229
- installed in the project).
241
+ 1.2.2 closes three ways around the wrapper that 1.2.1 listed or let through: removing the `stopbar git-hook` line
242
+ from a Husky or Lefthook hook (`Edit`, `sed -i '/git-hook/d' .husky/pre-commit`) with only a `[WARN]` from doctor,
243
+ `rm -rf $(pwd)/.g*`, and `find . -name '.g*' -delete` / `find . -name '.e*' -exec cat {} +`.
230
244
 
231
- ## Known limits of 1.1.3
245
+ What a regular expression cannot block (the unit test "1.2.2 known limits without an OS sandbox" keeps these visible):
232
246
 
233
- - The blob-id comparison trusts `baseRef`: see point 4 of section 3 (a mutable branch name can be moved by the agent).
234
- Use a commit SHA as `--base-ref` when the agent must not be able to move the baseline.
235
- - `init --force` and `reset` count all suspicious uncommitted changes as one kernel step. A test file that changed in
236
- a branch commit against `baseRef` counts too, even if a human approved it in an earlier session: after `reset` such
237
- a branch starts tainted until `approve-tests`.
238
- - `stopbar upgrade` re-pins the runtime from the package that runs the command. It does not check that the package is
239
- newer, and it does not change `config.json`; new defaults (for example `safeTools`) are only named as a hint.
247
+ - A name built at run time: `cat $(echo .e)nv`, `f=.e; cat ${f}nv`, `g=.g; rm -rf $g"it"`. The hook sees `.e` and
248
+ `nv`, never `.env`. The same holds for aliases, shell functions and a backslash inside a word (`g\it`).
249
+ - A script: `node /tmp/x.js`, `bash x.sh`. The text checks do not read the script.
250
+ - A wildcard outside the cases of section 2: `echo .g* | xargs rm -rf`, `find . -delete` or `find . -type f -exec
251
+ cat {} +` without a name pattern, `find . -name config -delete` (a name inside `.git`, not `.git` itself), a PowerShell
252
+ `Remove-Item * -Recurse -Force` (on Windows `*` also matches dot directories), and directory wildcards on the way to a
253
+ secret (`cat secre*/db.txt`). A bare `.*` in `echo .*` or `ls .*` counts as a secret read (it reaches `.env`).
254
+ - One variable or another program: `echo $TOKEN`, `export -p`, `declare -x`, `node -e "console.log(process.env)"`.
240
255
 
241
- ## Known limits of 1.1.2
256
+ Other limits:
242
257
 
243
- - `stopGate: "warn"`: in Cursor, Codex CLI, Gemini CLI and Antigravity CLI the WARN text is not shown to the agent,
244
- because their Stop protocols have no non-blocking message (a `followup_message`, `decision: "block"` or
245
- `decision: "continue"` would start another turn). The entry in `events.jsonl` and `stopbar status` show it.
246
- Claude Code gets the text on stdout with exit 0.
247
- - `cliCmd` is checked as text: one command, no shell operators, no `.git` or agent-settings directory. Stopbar does not
248
- check that the command really starts Stopbar; a wrong `cliCmd` gives the agent a hint that does not work, and the
249
- gates still count only real runs. Self-protection still blocks the human-only commands through `cliCmd`.
250
- - `buildCmd` and `fullTestCmd` that differ only in whitespace at the ends count as equal and are refused. Two different
251
- commands that run the same script (for example `npm test` and `npm run test`) are not detected.
252
-
253
- - Lean: the check needs Docker and a one-time image build with network access, or (since 1.2.0, used in CI) Lean
254
- 4.34.0 on `PATH` with `node scripts/verify-lean.ts --local`. The base image is pinned by digest and
255
- the Lean archive by sha256, both recorded at the first build (trust on first use). The Lean export is not
256
- deterministic: each export is a different proof tree, and the gate checks the one it exports.
258
+ - `safeTools` while halted: a human who adds a glob vouches that those tools are local. With a broad glob (for example
259
+ `mcp__*`) a halted agent keeps those tools. Edit, Write, Read and the shell stay paused whatever the list says.
260
+ - `--require-run` is optional (default `false`). It decides by the event's source (`stopbar run` or an agent hook), not
261
+ by what ran. Without it, the exact gate command from the agent's shell counts.
262
+ - The stdin heredoc exception holds only for one single-quoted `<<'EOF'` and trusts the command on the header line not
263
+ to run its stdin. Stopbar knows the common shells and interpreters (and `xargs`, `at`, `tee`, `stopbar`); another
264
+ program that executes stdin passes. The exception covers only the human-only checks.
265
+ - Git hooks: a foreign `pre-commit` or `pre-push` is kept with a `WARN` when the git hooks were added by default; that
266
+ git action is not gated until a human runs `stopbar upgrade --hooks git --force-hooks`. With a custom
267
+ `core.hooksPath` (Husky, Lefthook, a shared directory) Stopbar writes no git hook there without `--force-hooks`, so
268
+ git commit and git push are not gated until a human adds the `git-hook` lines that `stopbar doctor` prints.
269
+ `stopbar doctor` reports `[WARN] hooks git` while a Stopbar git hook was never set up, and `[FAIL]` only once one
270
+ that was written, ran, or is in `HEAD` is gone; a hook that was added by hand, never committed and never run is
271
+ only a `[WARN]` when it disappears. A hook path built at run time (`d=.hu; sed -i d ${d}sky/pre-commit`) passes like
272
+ any name built at run time, and a hook manager that keeps its configuration elsewhere (`package.json` for Husky 4,
273
+ `simple-git-hooks`) is not covered. `npx --no-install stopbar git-hook` runs the Stopbar in the project's
274
+ `node_modules`, not the pinned runtime.
275
+ - `baseRef`: a mutable branch name can be moved by the agent (section 3, point 4). Use a commit SHA as `--base-ref`
276
+ when the agent must not move the baseline. `stopbar status` prints a `note:` when the tree no longer differs from
277
+ `baseRef` on existing tests; it never clears the taint (L2.2).
278
+ - `init --force` and `reset` count all suspicious uncommitted changes as one kernel step; a branch whose tests differ
279
+ from `baseRef` starts tainted until `approve-tests`.
280
+ - `stopbar upgrade` re-pins the runtime from the package that runs the command. It does not check that the package is
281
+ newer, and it does not change `config.json`.
282
+ - `stopGate: "warn"`: in Cursor, Codex CLI, Gemini CLI and Antigravity CLI the WARN text is not shown to the agent; the
283
+ entry in `events.jsonl` and `stopbar status` show it.
284
+ - `cliCmd` is checked as text, not for whether it starts Stopbar. `buildCmd` and `fullTestCmd` that run the same script
285
+ under two names (`npm test` and `npm run test`) are not detected.
286
+ - `stopbar doctor` checks the kernel link only where `gdp-wired` resolves from the running copy; a pinned runtime
287
+ reports `[WARN] kernel link`.
288
+ - `--cmd`: the command runs through the system shell (`cmd.exe` on Windows, `/bin/sh` elsewhere). A shell can hold
289
+ stdout open after the program closed it; then only `--cmd-timeout` (default 300000 ms) ends the wait. Answers are
290
+ checked for their shape, not for meaning; mutants (`--check-mutants`) are the check that the model can fail.
291
+ Stopbar does not check that `generate` is deterministic.
292
+ - `probe init --lang py` prints `python` on Windows and `python3` elsewhere. `probe init --lang ts` runs only where
293
+ `stopbar/probe` resolves.
294
+ - Lean: the check needs Docker and a one-time image build with network access, or Lean 4.34.0 on `PATH` with
295
+ `node scripts/verify-lean.ts --local`. The base image and the Lean archive are pinned at the first build (trust on
296
+ first use). Each export is a different proof tree; the gate checks the one it exports.
257
297
  - Platforms: the unit tests, E2E, `stopbar probe` and `stopbar prove` pass on Windows 11 with Git for Windows and on
258
- Linux (Debian 13, Node 24, git 2.47). A live Claude Code session ran on Windows. macOS runs only in CI (since
259
- 1.2.0, `.github/workflows/ci.yml`).
260
- - Adapters: Cursor, Codex CLI, Gemini CLI and Antigravity CLI are spec-tested (see the README table); a client can
261
- change its hook schema in a later version.
298
+ Linux (Debian 13, Node 24). macOS runs only in CI (`.github/workflows/ci.yml`).
299
+ - Adapters: Cursor, Codex CLI, Gemini CLI and Antigravity CLI are spec-tested; a client can change its hook schema.
262
300
  - Hook latency: Windows starts a process in 50–70 ms, so a hook with one git process takes about 120–200 ms in all.
263
301
 
264
302
  ## Reporting a vulnerability
package/bin/stopbar.mjs CHANGED
File without changes
@@ -3,7 +3,7 @@
3
3
  // hookEventName, toolCall {id, name, args}, cwd, workspacePaths; PostToolUse carries `error` when the tool failed;
4
4
  // Stop carries continuationActive. Output is JSON on stdout: PreToolUse {"decision": "deny", "reason"}; Stop
5
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'
6
+ import { str, byName, commandText, edit, json, make, outbound, pathsOf, read, shell, } from './types.js'
7
7
 
8
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
9
  const EDIT = new Set(['write_file', 'write_to_file', 'replace_file_content', 'multi_replace_file_content', 'sed_file', 'notebook_edit', 'code_action',
@@ -11,7 +11,7 @@ const EDIT = new Set(['write_file', 'write_to_file', 'replace_file_content', 'mu
11
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
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
13
 
14
- function tool(name , args ) {
14
+ function tool(name , args ) {
15
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 ?? ''), args.IsDaemon === true)
16
16
  if (EDIT.has(name)) return edit(pathsOf(args))
17
17
  if (READ.has(name)) return read(pathsOf(args))
@@ -26,13 +26,13 @@ export const antigravity = {
26
26
  normalize(i) {
27
27
  const ev = String(i.hookEventName ?? '')
28
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})}
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: str(call.name)})}
32
32
  if (ev === 'PostToolUse') {
33
33
  const failed = typeof i.error === 'string' ? i.error.length > 0 : !!i.error
34
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})}
35
+ ...tool(String(call.name ?? ''), args), tool_response: failed ? {error: i.error} : {}}, {tool: str(call.name)})}
36
36
  }
37
37
  if (ev === 'Stop') return {kind: 'stop', event: make('antigravity', i, ev, {hook_event_name: 'Stop', cwd, stop_hook_active: i.continuationActive === true})}
38
38
  return {kind: 'other', event: null}
@@ -9,7 +9,7 @@ export const claude = {
9
9
  name: 'claude',
10
10
  detect: (i) => typeof i.hook_event_name === 'string',
11
11
  normalize(i) {
12
- const kind = KIND[i.hook_event_name] ?? 'other'
12
+ const kind = KIND[String(i.hook_event_name)] ?? 'other'
13
13
  return {kind, event: kind === 'other' ? null : (i )}
14
14
  },
15
15
  render(_kind, out) {
@@ -3,11 +3,11 @@
3
3
  // (pre-tool-use / post-tool-use / stop .command.input and .command.output): every input carries turn_id and model.
4
4
  // There is no failure event: PostToolUse also follows a failed command, so a gate passes only with an exit code 0
5
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'
6
+ import { str, byName, commandText, edit, exitCodeIn, json, make, patchPaths, shell, } from './types.js'
7
7
 
8
8
  const SHELL = new Set(['Bash', 'shell', 'exec_command', 'local_shell', 'unified_exec', 'shell_command', 'container.exec'])
9
9
 
10
- function tool(name , ti ) {
10
+ function tool(name , ti ) {
11
11
  if (SHELL.has(name)) return shell(commandText(ti.command ?? ti.cmd ?? ti.argv))
12
12
  if (name === 'apply_patch') return edit(patchPaths(ti.input ?? ti.patch ?? ti.command))
13
13
  if (name.startsWith('mcp__')) return {tool_name: name, tool_input: ti}
@@ -19,20 +19,20 @@ export const codex = {
19
19
  name: 'codex',
20
20
  detect: (i) => typeof i.hook_event_name === 'string' && typeof i.turn_id === 'string',
21
21
  normalize(i) {
22
- const ev = i.hook_event_name, ti = (i.tool_input && typeof i.tool_input === 'object' ? i.tool_input : {})
22
+ const ev = i.hook_event_name, ti = (i.tool_input && typeof i.tool_input === 'object' ? i.tool_input : {})
23
23
  if (ev === 'PreToolUse') {
24
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})}
25
+ return {kind: 'pre-tool', event: make('codex', i, ev, {hook_event_name: 'PreToolUse', cwd: str(i.cwd), ...t}, {tool: str(i.tool_name)})}
26
26
  }
27
27
  if (ev === 'PostToolUse') {
28
28
  const t = tool(String(i.tool_name ?? ''), ti)
29
29
  const code = exitCodeIn(i.tool_response)
30
30
  const failed = code !== undefined && code !== 0
31
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})}
32
+ event: make('codex', i, ev, {hook_event_name: failed ? 'PostToolUseFailure' : 'PostToolUse', cwd: str(i.cwd), ...t,
33
+ tool_response: code === undefined ? i.tool_response : {exitCode: code}}, {requireExitCode: true, tool: str(i.tool_name)})}
34
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})}
35
+ if (ev === 'Stop') return {kind: 'stop', event: make('codex', i, ev, {hook_event_name: 'Stop', cwd: str(i.cwd), stop_hook_active: i.stop_hook_active === true})}
36
36
  return {kind: 'other', event: null}
37
37
  },
38
38
  render(kind , out) {
@@ -4,9 +4,9 @@
4
4
  // beforeReadFile, afterFileEdit, afterShellExecution. Permission events: exit 2 denies, and the JSON on stdout carries
5
5
  // permission "deny" with user_message and agent_message. Other non-zero exits are fail-open unless the entry sets
6
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'
7
+ import { str, byName, commandText, edit, exitCodeIn, json, make, outbound, pathsOf, read, shell, } from './types.js'
8
8
 
9
- function tool(name , ti ) {
9
+ function tool(name , ti ) {
10
10
  if (name === 'Shell') return shell(commandText(ti.command), ti.is_background === true || ti.run_in_background === true)
11
11
  if (name === 'Read') return read(pathsOf(ti))
12
12
  if (['Write', 'Edit', 'Delete', 'StrReplace', 'MultiEdit', 'ApplyPatch'].includes(name)) return edit(pathsOf(ti))
@@ -17,7 +17,7 @@ function tool(name , ti ) {
17
17
  }
18
18
  const toolInput = (x ) => {
19
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 ) : {}
20
+ return x && typeof x === 'object' ? (x ) : {}
21
21
  }
22
22
  const PERMISSION = new Set(['preToolUse', 'beforeShellExecution', 'beforeMCPExecution', 'beforeReadFile'])
23
23
 
@@ -29,7 +29,7 @@ export const cursor = {
29
29
  const cwd = typeof i.cwd === 'string' && i.cwd ? i.cwd : Array.isArray(i.workspace_roots) ? i.workspace_roots[0] : undefined
30
30
  const base = (t ) => ({cwd, ...t})
31
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})}
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: str(i.tool_name)})}
33
33
  case 'beforeShellExecution': return {kind: 'pre-tool', event: make('cursor', i, ev, {hook_event_name: 'PreToolUse', ...base(shell(commandText(i.command)))})}
34
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
35
  case 'beforeReadFile': return {kind: 'pre-tool', event: make('cursor', i, ev, {hook_event_name: 'PreToolUse', ...base(read(pathsOf(i)))})}
@@ -38,10 +38,10 @@ export const cursor = {
38
38
  const code = exitCodeIn(out)
39
39
  const failed = code !== undefined && code !== 0
40
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})}
41
+ ...base(tool(String(i.tool_name ?? ''), toolInput(i.tool_input))), tool_response: code === undefined ? out : {exitCode: code}}, {tool: str(i.tool_name)})}
42
42
  }
43
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})}
44
+ ...base(tool(String(i.tool_name ?? ''), toolInput(i.tool_input))), is_interrupt: i.is_interrupt === true || i.failure_type === 'permission_denied'}, {tool: str(i.tool_name)})}
45
45
  case 'afterFileEdit': return {kind: 'post-tool', event: make('cursor', i, ev, {hook_event_name: 'PostToolUse', ...base(edit(pathsOf(i)))})}
46
46
  // no exit code in afterShellExecution: a gate command seen only here never passes (use postToolUse)
47
47
  case 'afterShellExecution': return {kind: 'post-tool', event: make('cursor', i, ev, {hook_event_name: 'PostToolUse', ...base(shell(commandText(i.command)))}, {requireExitCode: true})}
@@ -2,11 +2,11 @@
2
2
  // Gemini CLI (.gemini/settings.json "hooks"). Events BeforeTool, AfterTool and AfterAgent (the end of a turn). Exit 2 is
3
3
  // a system block with the reason on stderr; any other non-zero exit is only a warning and the call proceeds, and
4
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'
5
+ import { str, byName, commandText, edit, exitCodeIn, json, make, outbound, pathsOf, read, shell, } from './types.js'
6
6
 
7
7
  const UNIQUE = new Set(['BeforeTool', 'AfterTool', 'BeforeAgent', 'AfterAgent', 'BeforeModel', 'AfterModel', 'BeforeToolSelection', 'PreCompress', 'Notification'])
8
8
 
9
- function tool(name , ti ) {
9
+ function tool(name , ti ) {
10
10
  switch (name) {
11
11
  case 'run_shell_command': return shell(commandText(ti.command), ti.is_background === true || ti.run_in_background === true)
12
12
  case 'write_file': case 'replace': return edit(pathsOf(ti))
@@ -24,16 +24,16 @@ export const gemini = {
24
24
  name: 'gemini',
25
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
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})}
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: str(i.cwd), ...tool(String(i.tool_name ?? ''), ti)}, {tool: str(i.tool_name)})}
29
29
  if (ev === 'AfterTool') {
30
30
  const r = (i.tool_response ?? {})
31
31
  const code = exitCodeIn(r)
32
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})}
33
+ return {kind: failed ? 'post-tool-failure' : 'post-tool', event: make('gemini', i, ev, {hook_event_name: failed ? 'PostToolUseFailure' : 'PostToolUse', cwd: str(i.cwd),
34
+ ...tool(String(i.tool_name ?? ''), ti), tool_response: code === undefined ? r : {exitCode: code}}, {tool: str(i.tool_name)})}
35
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})}
36
+ if (ev === 'AfterAgent') return {kind: 'stop', event: make('gemini', i, ev, {hook_event_name: 'Stop', cwd: str(i.cwd), stop_hook_active: i.stop_hook_active === true})}
37
37
  return {kind: 'other', event: null}
38
38
  },
39
39
  render(kind, out) {
@@ -31,9 +31,10 @@ const failClosed = (why ) => ({code: 2, msg: `STOPBAR FAIL-CLOSED: $
31
31
  export function handle(raw , which = 'auto', t0 = performance.now()) {
32
32
  const explicit = which === 'auto' ? null : adapterByName(which)
33
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)
34
+ let parsed
35
+ try { parsed = JSON.parse(raw) } catch (e) { return (explicit ?? claude).render('pre-tool', failClosed(`hook input is not JSON (${(e ).message})`), null) }
36
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) return (explicit ?? claude).render('pre-tool', failClosed('hook input must be a JSON object'), null)
37
+ const input = parsed
37
38
  const a = explicit ?? detect(input)
38
39
  if (!a) return claude.render('pre-tool', failClosed('unknown hook payload: no adapter recognises it (use --adapter)'), null)
39
40
  let n
@@ -27,9 +27,9 @@ export const ADAPTERS = ['claude', 'codex', 'cursor', 'gemini', '
27
27
 
28
28
 
29
29
 
30
-
30
+
31
31
 
32
-
32
+
33
33
 
34
34
 
35
35
  // ---------------------------------------------------------------- shared tool mapping
@@ -73,14 +73,14 @@ export function pathsOf(args ) {
73
73
  /** Fallback by name for tools a client adds later: shell, edit, read or outbound by keyword, else other. */
74
74
  export function byName(name , args , command ) {
75
75
  const n = name.toLowerCase()
76
- if (/shell|terminal|command|exec|bash|run_/.test(n)) return shell(commandText(command ?? (args )?.command ?? (args )?.CommandLine ?? ''))
76
+ if (/shell|terminal|command|exec|bash|run_/.test(n)) return shell(commandText(command ?? args?.command ?? args?.CommandLine ?? ''))
77
77
  if (/write|edit|delete|replace|patch|create|move|rename|remove|change|propose|blob/.test(n)) return edit(pathsOf(args))
78
78
  if (/read|view|open_file|cat|grep|search_file|find|glob|list/.test(n)) return read(pathsOf(args))
79
79
  if (/fetch|web|browser|http|url|mcp/.test(n)) return outbound(n.startsWith('mcp') ? `mcp__${name}` : name)
80
80
  return other(name)
81
81
  }
82
82
 
83
- export function make(adapter , raw , event , base , extra = {}) {
83
+ export function make(adapter , raw , event , base , extra = {}) {
84
84
  return {...base, stopbar: {adapter, rawKeys: Object.keys(raw), event, ...extra}}
85
85
  }
86
86
 
@@ -101,3 +101,6 @@ export function exitCodeIn(r , depth = 0) {
101
101
  }
102
102
 
103
103
  export const json = (o ) => JSON.stringify(o)
104
+
105
+ /** A payload field that must be a string; anything else counts as absent. */
106
+ export const str = (x ) => (typeof x === 'string' ? x : undefined)
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.2.0",
2
+ "version": "1.2.2",
3
3
  "kernelSourceSha256": "c602fc4bcf8ffb2e312bf838986e6d4b006af6d0e6c7447c8c61d5888adc5ef8",
4
4
  "machineSha256": "b397085e0cb13e2e50aa655c54de0744d08f2ebf500bf32af8ff3e8a11ba7321",
5
5
  "files": 29