stopbar 1.2.0 → 1.2.1
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 +40 -0
- package/README.md +83 -20
- package/SECURITY.md +86 -69
- package/bin/stopbar.mjs +0 -0
- package/dist/adapters/antigravity.js +6 -6
- package/dist/adapters/claude.js +1 -1
- package/dist/adapters/codex.js +7 -7
- package/dist/adapters/cursor.js +6 -6
- package/dist/adapters/gemini.js +7 -7
- package/dist/adapters/index.js +4 -3
- package/dist/adapters/types.js +7 -4
- package/dist/build-info.json +1 -1
- package/dist/classify.js +174 -10
- package/dist/commands.js +7 -2
- package/dist/doctor.js +46 -21
- package/dist/integrations.js +41 -6
- package/dist/probe/index.js +25 -16
- package/dist/probe/sdk.js +1 -1
- package/dist/probe/stdio.js +25 -13
- package/dist/probe/wrapper.js +1 -1
- package/dist/store.js +1 -1
- package/dist/verify.js +34 -26
- package/package.json +2 -2
- package/src/probe/sdk.ts +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,45 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.2.1 (2026-11-27)
|
|
4
|
+
|
|
5
|
+
`src/kernel.ts` is unchanged (sha256 `c602fc4bcf8ffb2e...`); every kernel law holds as in 1.2.0. No new dependency.
|
|
6
|
+
A `config.json` and a `state.json` from 1.0.0–1.2.0 work without migration.
|
|
7
|
+
|
|
8
|
+
- **Custom `core.hooksPath` is not written.** When `core.hooksPath` points outside `.git/hooks` (Husky, Lefthook, a
|
|
9
|
+
shared or tracked hooks directory), `init --hooks <client>` writes no git hook there and prints a `WARN` with the
|
|
10
|
+
manual `node "<runtime>/bin/stopbar.mjs" git-hook pre-commit|pre-push` lines; explicit `--hooks git` without
|
|
11
|
+
`--force-hooks` fails closed (exit 2) before any hook file is written; `--force-hooks` writes the hooks and keeps a foreign
|
|
12
|
+
one as `<name>.stopbar-backup`. `stopbar doctor` reports `[WARN] hooks git`: it says that git commit and git push are
|
|
13
|
+
not gated, and prints the exact line for each missing hook. A `stopbar git-hook <name>` line chained by hand counts.
|
|
14
|
+
- **`stopbar status` after `baseRef` advanced.** With `testsTainted` and a non-`HEAD` `baseRef`, `status` prints
|
|
15
|
+
`note: no existing test or test-config file currently differs from <baseRef>; ...` when that is so, and
|
|
16
|
+
`status --json` has `taintedDiffersFromBaseRef` (`true`, `false`, or `null` when untainted or without `baseRef`).
|
|
17
|
+
The taint stays (L2.2): `status` never writes `state.json`.
|
|
18
|
+
- **`stopbar probe --cmd`: no silent exit.** A target that printed a banner or a non-JSON answer to `info` ended the
|
|
19
|
+
CLI with exit 0 (and `await probe()` with exit 13) on Linux: `close()` waited for an `exit` event of a killed,
|
|
20
|
+
unref'd child against an unref'd timer. `close()` now returns at once for a killed or exited process, and its timers
|
|
21
|
+
hold the event loop and are cleared. Regression test: banner, non-JSON and crash on `info` give exit 1 from the CLI
|
|
22
|
+
and a `ProbeError` from `probe()` and `loadCmd()`; exit 0 comes only with `PROBE PASS`.
|
|
23
|
+
- **Four bypasses closed in `src/classify.ts`.** `printenv`, a bare `env`, `Get-ChildItem Env:` and
|
|
24
|
+
`/proc/self/environ` are a secret read (`env VAR=1 cmd` and `set` are not). Tokens with `..` are normalised
|
|
25
|
+
(`cat src/../.env`), and a live wildcard that reaches a secret name is a read (`cat .en*`, `cat .en?`). `rm`, `mv`,
|
|
26
|
+
`del`, `Remove-Item` and the like with a wildcard on `.git` or an agent settings directory are blocked (`rm -rf .g*`,
|
|
27
|
+
`rm -rf .cl*`), and so is a wildcard followed by a path inside (`cp x .g*/hooks/pre-commit`). A git subcommand from
|
|
28
|
+
an expansion is blocked (`git $f -m x`, `p=push; git $p --no-verify`, `git "${cmd}"`). Unit tests also record the
|
|
29
|
+
known limits (`cat $(echo .e)nv`, `f=.e; cat ${f}nv`, `node /tmp/x.js`).
|
|
30
|
+
- **`stopbar doctor` names the gate mode** on the `config.json` line: `gates: hook command text (use --require-run for
|
|
31
|
+
exit-code-only gates)` or `gates: stopbar run only (--require-run)`. `--require-run` stays optional.
|
|
32
|
+
- **Tests:** HALT with `safeTools: ["*"]` still pauses Bash, Edit, Write and Read; the heredoc exceptions hold only
|
|
33
|
+
for `<<'EOF'` (not `<<EOF`, `<<"EOF"`, `bash -s <<'EOF'` or `sh <<'EOF'`).
|
|
34
|
+
- **Types:** no `any` left in `src/hook.ts`, `src/verify.ts`, `src/doctor.ts`, `src/probe/` and `src/adapters/`.
|
|
35
|
+
In the probe SDK, `ActionSpec.run` takes `args: unknown` (was `any`); destructured arguments such as
|
|
36
|
+
`run: (s, {x}, check)` still compile. `npm run typecheck` builds first, so it works on a fresh clone.
|
|
37
|
+
- **Release:** `.github/workflows/release.yml` publishes to npm with provenance (Trusted Publishing, OIDC) when a `v*`
|
|
38
|
+
tag that matches `package.json` is pushed.
|
|
39
|
+
- **Docs:** README and SECURITY open with what is proven, what is tested and what needs an OS sandbox, add
|
|
40
|
+
"Hardening: OS sandbox + client deny rules", list the default `safeTools` with a warning about broad globs, and say
|
|
41
|
+
what probe evidence in `attest` is. SECURITY has one "Known limits of 1.2.1" section.
|
|
42
|
+
|
|
3
43
|
## 1.2.0 (2026-11-26)
|
|
4
44
|
|
|
5
45
|
`src/kernel.ts` is unchanged (sha256 `c602fc4bcf8ffb2e...`); every kernel law holds as in 1.1.3. A `config.json` and a
|
package/README.md
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
# Stopbar
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
[](https://github.com/polszewski-pl/stopbar/actions/workflows/ci.yml)
|
|
4
|
+
[](https://www.npmjs.com/package/stopbar)
|
|
5
|
+
|
|
6
|
+
Stopbar is an execution gate for AI coding agents in three parts: a **formally proven decision kernel**
|
|
7
|
+
(`src/kernel.ts`, about 160 lines, its laws proven by induction and checked again by `lake build` in Lean 4.34.0), a
|
|
8
|
+
**tested wrapper** around it (the hooks of Claude Code, Cursor, Codex CLI, Gemini CLI and Antigravity CLI, and git
|
|
9
|
+
hooks for any other tool), and an **attestation** of the session (`stopbar attest`). The wrapper reads tool calls and
|
|
10
|
+
command text and asks the kernel; it is covered by unit and E2E tests and stateful probing, not by the proof.
|
|
11
|
+
|
|
12
|
+
| Proven (Lean 4.34.0) | Tested (wrapper + E2E + PROBE) | Not covered without OS sandbox |
|
|
13
|
+
|---|---|---|
|
|
14
|
+
| The decision rule `src/kernel.ts`: no commit without a passing build and full suite at the current revision (L1); test taint until a human approval (L2.x); pause of risky and outbound calls after a secret read (L3.x); halt on budget and retries (L4.x). 10 mutants each fall with a counterexample. | How tool calls become kernel requests: exact gate commands, content snapshots of the tree, test and secret path patterns, self-protection of `.git`, agent settings and the Stopbar code, the client adapters, the git hooks. | A path or name built at run time (`f=.e; cat ${f}nv`), a script the agent wrote and runs (`node /tmp/x.js`), code that the gate commands run, secrets in files with ordinary names. See [SECURITY.md](SECURITY.md) section 3. |
|
|
8
15
|
|
|
9
16
|
**Without an OS sandbox, Stopbar stops shortcuts and mistakes of an agent; it is not a security boundary against a
|
|
10
17
|
hostile agent.** A command can build a path at run time or hide it in a script that the text rules do not see. See
|
|
@@ -44,15 +51,6 @@ working. An unknown or damaged payload fails closed (exit 2). The configs writte
|
|
|
44
51
|
`stopbar run build` and `stopbar run test`. The git hooks then allow a commit only after both passed at the
|
|
45
52
|
current tree, block it after an unapproved test change, and block a push after a secret read without approval.
|
|
46
53
|
|
|
47
|
-
## Four pillars
|
|
48
|
-
|
|
49
|
-
| Pillar | Command | What it gives you |
|
|
50
|
-
|---|---|---|
|
|
51
|
-
| 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. |
|
|
52
|
-
| 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 (target `wrapper`, Stopbar itself). Since 1.2.0 also your own project: a TS/JS model written with `defineModel` from `stopbar/probe`, or a program in any language (Python, Go, Rust, ...) that speaks NDJSON on stdin/stdout (`--cmd`), with mutants that must be caught. |
|
|
53
|
-
| GATE | `stopbar init`, `upgrade`, `hook`, `git-hook`, `run`, `status`, `approve-tests`, `approve-shell`, `resume`, `reset`, `doctor` | The agent hooks, the git fallback and the human commands. |
|
|
54
|
-
| ATTEST | `stopbar attest` | A deterministic attestation of the session: HEAD, tree, gates, human actions, probe evidence and the sha256 of the event log. |
|
|
55
|
-
|
|
56
54
|
## Set up in 3 steps
|
|
57
55
|
|
|
58
56
|
Requirements: Node.js 22.18 or later, git, a git repository.
|
|
@@ -132,6 +130,21 @@ All commands take `--repo <dir>`. The agent cannot run the human commands: the h
|
|
|
132
130
|
State, configuration and the event log are in `<repo>/.git/stopbar/`: `config.json`, `state.json`, `events.jsonl`, the
|
|
133
131
|
private snapshot index and the pinned runtime. They are outside the working tree, so they never change the tree hash.
|
|
134
132
|
|
|
133
|
+
## Parts of the package
|
|
134
|
+
|
|
135
|
+
The gate (GATE, with PROVE and ATTEST) is the product. PROBE is a test tool that ships in the same package.
|
|
136
|
+
|
|
137
|
+
| Part | Command | What it gives you |
|
|
138
|
+
|---|---|---|
|
|
139
|
+
| 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. |
|
|
140
|
+
| 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 (target `wrapper`, Stopbar itself). Since 1.2.0 also your own project: a TS/JS model written with `defineModel` from `stopbar/probe`, or a program in any language (Python, Go, Rust, ...) that speaks NDJSON on stdin/stdout (`--cmd`), with mutants that must be caught. |
|
|
141
|
+
| GATE | `stopbar init`, `upgrade`, `hook`, `git-hook`, `run`, `status`, `approve-tests`, `approve-shell`, `resume`, `reset`, `doctor` | The agent hooks, the git fallback and the human commands. |
|
|
142
|
+
| ATTEST | `stopbar attest` | A deterministic attestation of the session: HEAD, tree, gates, human actions, probe evidence and the sha256 of the event log. |
|
|
143
|
+
|
|
144
|
+
**Probe evidence** in `stopbar attest` is the recorded result of one probe run, tied to the tree snapshot and to the
|
|
145
|
+
sha256 of the prober file. It says what the prober saw on that tree. It is no proof against a hostile agent without an
|
|
146
|
+
OS sandbox: an agent that can write `events.jsonl` can also write a false entry ([SECURITY.md](SECURITY.md) section 4).
|
|
147
|
+
|
|
135
148
|
## PROBE for your project
|
|
136
149
|
|
|
137
150
|
`stopbar probe --target <file>` runs a model of any TS/JS code. The file exports (as `default` or as `target`) a
|
|
@@ -273,7 +286,10 @@ profile by editing the lists: no code change is necessary.
|
|
|
273
286
|
Claude Desktop and its tools for messages between local sessions. It only exempts tools from the outbound gate
|
|
274
287
|
(WebFetch, WebSearch, MCP tools); shell commands, edits and reads are gated as before. Since 1.2.0 these tools also
|
|
275
288
|
pass while the session is halted, so the agent can still ask a human for `stopbar resume`; they never take a kernel
|
|
276
|
-
step. Every other tool stays paused while halted.
|
|
289
|
+
step. Every other tool stays paused while halted. Edit, Write, Read and the shell tools stay gated even if a glob in
|
|
290
|
+
`safeTools` matches them (also `["*"]`). **Keep the globs narrow**: with a broad glob such as `mcp__*`, every MCP tool
|
|
291
|
+
is treated as local, passes the outbound gate after a secret read and keeps working while the session is halted.
|
|
292
|
+
A `config.json` written by 1.0.0–1.1.1 keeps its own list and keeps working; to stop false
|
|
277
293
|
`PAUSE`s on the session tools after a secret read, add `"mcp__ccd_session_mgmt__*"` to `safeTools` or write the file
|
|
278
294
|
again with `stopbar init --force ...`. `stopbar doctor` shows a `[WARN] safeTools` while a default entry is missing.
|
|
279
295
|
- **`cliCmd`** (optional, set via `stopbar init --cli "<cmd>"`) is the command that starts Stopbar in the hints shown to
|
|
@@ -295,6 +311,48 @@ profile by editing the lists: no code change is necessary.
|
|
|
295
311
|
A damaged or empty `config.json` or `state.json` blocks every tool call (exit 2) with a message that says how to
|
|
296
312
|
repair it.
|
|
297
313
|
|
|
314
|
+
`stopbar doctor` shows the gate mode on the `config.json` line: `gates: hook command text (use --require-run for
|
|
315
|
+
exit-code-only gates)` by default, `gates: stopbar run only (--require-run)` with `requireRun`.
|
|
316
|
+
|
|
317
|
+
**Custom `core.hooksPath`** (Husky, Lefthook, a shared hooks directory): since 1.2.1 Stopbar does not write into it.
|
|
318
|
+
`init --hooks <client>` then writes no git hook and prints a `WARN`; `init --hooks git` fails closed (exit 2);
|
|
319
|
+
`stopbar doctor` reports `[WARN] hooks git`: git commit and git push are not gated by Stopbar until a human adds one
|
|
320
|
+
line to each hook of the hook manager, `node "<runtime>/bin/stopbar.mjs" git-hook pre-commit` and `... git-hook
|
|
321
|
+
pre-push` (doctor prints the exact lines), or runs `stopbar upgrade --hooks git --force-hooks`.
|
|
322
|
+
|
|
323
|
+
## Hardening: OS sandbox + client deny rules
|
|
324
|
+
|
|
325
|
+
Stopbar reads command text. To stop an agent that tries to get around it, add two layers that do not depend on text.
|
|
326
|
+
|
|
327
|
+
1. **Client deny rules.** The agent's own permission rules refuse a tool call before any hook. For Claude Code, in
|
|
328
|
+
`.claude/settings.json` (check the rule syntax against your client's documentation):
|
|
329
|
+
|
|
330
|
+
```json
|
|
331
|
+
{
|
|
332
|
+
"permissions": {
|
|
333
|
+
"deny": [
|
|
334
|
+
"Read(./.env)", "Read(./.env.*)", "Read(./secrets/**)",
|
|
335
|
+
"Edit(./.git/**)", "Edit(./.claude/**)",
|
|
336
|
+
"Bash(curl:*)", "Bash(wget:*)", "Bash(printenv:*)",
|
|
337
|
+
"WebFetch"
|
|
338
|
+
]
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
2. **OS sandbox.** Run the agent in a container, a VM or a sandbox runtime (for example Anthropic's `sandbox-runtime`
|
|
344
|
+
or Claude Code's Bash sandbox) without network, with only the repository writable:
|
|
345
|
+
|
|
346
|
+
```sh
|
|
347
|
+
docker run --rm -it --network none -v "$PWD:/work" -v "$PWD/.claude:/work/.claude:ro" \
|
|
348
|
+
-v "$PWD/.git/hooks:/work/.git/hooks:ro" -w /work <agent-image>
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
The hooks write `.git/stopbar/`. When the whole agent runs in the container, the hooks run there too, so
|
|
352
|
+
`.git/stopbar/` must stay writable, and the agent's shell can write it as well. A sandbox that wraps only the
|
|
353
|
+
agent's shell (the hooks run outside it) can deny writes to `.git/stopbar/` inside the sandbox. Run the human
|
|
354
|
+
commands (`approve-tests`, `approve-shell`, `resume`, `reset`) outside the sandbox.
|
|
355
|
+
|
|
298
356
|
## Local use
|
|
299
357
|
|
|
300
358
|
- `npm run build` builds `dist/` from `src/` with Node's own type stripping and generates `dist/kernel.gen.js` from
|
|
@@ -355,11 +413,16 @@ latency. An earlier prototype that loaded the prover in every hook measured p50
|
|
|
355
413
|
|
|
356
414
|
| Platform | Node | git | Python | Typecheck | Unit | E2E | `stopbar probe` | `--cmd` Python example | `stopbar prove` | `stopbar doctor` |
|
|
357
415
|
|---|---|---|---|---|---|---|---|---|---|---|
|
|
358
|
-
| Windows 11, Git for Windows | 24.19.0 | 2.56.0 | 3.14.7 | 0 errors |
|
|
359
|
-
| Linux, Debian 13 (container, no network) | 24.21.0 | 2.47.3 | 3.13.5 | 0 errors |
|
|
360
|
-
|
|
|
416
|
+
| Windows 11, Git for Windows | 24.19.0 | 2.56.0 | 3.14.7 | 0 errors | 74/74 | 460/460 | 202/202 sequences | 200/200, mutants 2/2 | proven, 10/10 mutants | OK |
|
|
417
|
+
| Linux, Debian 13 (container, no network) | 24.21.0 | 2.47.3 | 3.13.5 | 0 errors | 74/74 | 460/460 | 202/202 sequences | 200/200, mutants 2/2 | proven, 10/10 mutants | OK |
|
|
418
|
+
| macOS 26.7.2 arm64 (`macos-latest`, GitHub Actions, CI of 1.2.0) | 24.22.3 | 2.56.1 | – | 0 errors | pass | 443/443 | 202/202 sequences | – | – | – |
|
|
419
|
+
| Ubuntu, Windows (GitHub Actions) | 24 | runner | runner | CI | CI | CI | CI | – | CI (Ubuntu) | – |
|
|
361
420
|
|
|
362
|
-
The
|
|
421
|
+
The first two rows are runs of 1.2.1 on our machines; both also pass `stopbar probe --target
|
|
422
|
+
examples/bounded-queue.probe.ts --runs 50 --check-mutants` (50/50, mutants 2/2). The macOS row is the CI run of 1.2.0
|
|
423
|
+
(commit `8bfd8cb`, workflow `.github/workflows/ci.yml`): build, typecheck, `npm test` (unit with the dot reporter, so no
|
|
424
|
+
count in the log) and the same `bounded-queue` probe (50/50, mutants 2/2). The `prove` job of CI runs on Ubuntu only.
|
|
425
|
+
CI runs after a push; the results of 1.2.1 will be on the repository's Actions page (see the CI badge).
|
|
363
426
|
|
|
364
427
|
The E2E suite runs every adapter (Cursor, Codex CLI, Gemini CLI, Antigravity CLI) and the git fallback with real
|
|
365
428
|
git commits and pushes. The probe runs the same 200 seeds plus 2 regressions on both platforms, with the same 5020 steps
|
|
@@ -368,7 +431,7 @@ The `--cmd` column is `stopbar probe --cmd "<python> examples/bounded_queue_prob
|
|
|
368
431
|
(3970 steps on both platforms). E2E scenario S37 runs `--cmd` with a Node target everywhere, and the Python example
|
|
369
432
|
and the `--lang py` template only where `python3` or `python` is found.
|
|
370
433
|
`npm run verify:lean` passes in the Lean 4.34.0 container: `lake build` exit 0, 0 errors, 0 `sorry` (run on the same
|
|
371
|
-
`src/kernel.ts`, sha256 `c602fc4bcf8ffb2e...`, which 1.2.0
|
|
434
|
+
`src/kernel.ts`, sha256 `c602fc4bcf8ffb2e...`, which 1.2.0 and 1.2.1 do not change). `node scripts/verify-lean.ts --local`
|
|
372
435
|
gives the same result with Lean 4.34.0 on `PATH` (checked in a Debian 13 container with the toolchain of that image).
|
|
373
436
|
|
|
374
437
|
## License
|
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,21 @@ 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
|
-
- **
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
+
- **Halted sessions.** While halted, every tool is paused except the tools in `config.safeTools` (default:
|
|
112
|
+
`mcp__ccd_turn__*` and `mcp__ccd_session_mgmt__*`, the local task-list, turn and session-message tools of Claude
|
|
113
|
+
Desktop), so the agent can still ask a human for `stopbar resume`. These tools never take a kernel step, so they
|
|
114
|
+
cannot change the state that laws L4.1 and L4.4 speak about. Edit, Write, Read, Bash, WebFetch and every other MCP
|
|
115
|
+
tool stay paused. Edit, Write, Read and the shell tools stay paused even when a `safeTools` glob matches them (the
|
|
116
|
+
E2E suite checks `safeTools: ["*"]`). Keep the globs narrow: a broad glob such as `mcp__*` lets every MCP tool
|
|
117
|
+
through while halted and after a secret read.
|
|
103
118
|
- **`requireRun`.** With `config.requireRun: true`, a build or full test run counts only through `stopbar run
|
|
104
119
|
build|test`; the same command from the agent's shell is recorded neither as a pass nor as a failure.
|
|
105
120
|
- **One kernel for every agent.** An adapter per client (Claude Code, Cursor, Codex CLI, Gemini CLI, Antigravity CLI)
|
|
@@ -125,8 +140,9 @@ that tries to defeat it:
|
|
|
125
140
|
test "known limits without an OS sandbox" keeps these cases visible.
|
|
126
141
|
2. **Gate commands run arbitrary code.** `buildCmd` and `fullTestCmd` run the repository's code. A new test file is
|
|
127
142
|
trusted. It can read secrets, use the network or weaken other checks at run time.
|
|
128
|
-
3. **Secrets by file name only.** Secrets in
|
|
129
|
-
|
|
143
|
+
3. **Secrets by file name only.** Secrets in files with ordinary names, or found with Grep in ordinary files, are not
|
|
144
|
+
seen. A command that prints the whole environment counts as a secret read since 1.2.1; one variable in a command
|
|
145
|
+
(`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
146
|
that matches only an extension pattern such as `*.key` counts only if that file exists (a field access like
|
|
131
147
|
`claim.key` is not a file); a command that names a `.key` file which does not exist yet is therefore not a read.
|
|
132
148
|
Tools listed in `config.safeTools` (default: Claude Desktop's `mcp__ccd_turn__*` UI tools and its
|
|
@@ -176,9 +192,19 @@ that tries to defeat it:
|
|
|
176
192
|
- Git fallback: git hooks see only commits and pushes, not reads or shell commands, so the secret gate needs an agent
|
|
177
193
|
hook to record the read. `git commit --no-verify` and `git push --no-verify` skip git hooks.
|
|
178
194
|
|
|
179
|
-
For a hostile-agent threat model,
|
|
180
|
-
|
|
181
|
-
|
|
195
|
+
**Hardening: OS sandbox + client deny rules.** For a hostile-agent threat model, add two layers that do not read
|
|
196
|
+
command text:
|
|
197
|
+
|
|
198
|
+
- Client deny rules refuse a tool call before any hook. Claude Code example in `.claude/settings.json` (check the rule
|
|
199
|
+
syntax against your client's documentation):
|
|
200
|
+
`{"permissions": {"deny": ["Read(./.env)", "Read(./.env.*)", "Read(./secrets/**)", "Edit(./.git/**)", "Edit(./.claude/**)", "Bash(curl:*)", "Bash(wget:*)", "Bash(printenv:*)", "WebFetch"]}}`.
|
|
201
|
+
- Run the agent in a container, a VM or a sandbox runtime (for example Anthropic's `sandbox-runtime` or Claude Code's
|
|
202
|
+
Bash sandbox): no network by default, the repository writable, `.claude/` and `.git/hooks/` read-only, for example
|
|
203
|
+
`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>`.
|
|
204
|
+
The hooks write `.git/stopbar/`: when they run inside the same sandbox as the agent's shell, the shell can write it
|
|
205
|
+
too. A sandbox that wraps only the agent's shell (the hooks run outside it) can deny writes to `.git/stopbar/`. Run
|
|
206
|
+
the human commands outside the sandbox. Stopbar's kernel then gives the proven decisions and the sandbox gives the
|
|
207
|
+
boundary.
|
|
182
208
|
|
|
183
209
|
## 4. PROBE, `--cmd` and probe evidence
|
|
184
210
|
|
|
@@ -191,74 +217,65 @@ the sandbox. Stopbar's kernel then gives the proven decisions and the sandbox gi
|
|
|
191
217
|
- `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
218
|
change `state.json`, so it can never allow a commit. It is appended under Stopbar's lock, like every other entry.
|
|
193
219
|
- `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`.
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
220
|
+
target file (`targetSha256`), the command (`targetCmd`), the tree snapshot and `atCurrentSnapshot`. **Probe evidence
|
|
221
|
+
is the recorded result of one run, tied to the tree snapshot and to the hash of the prober file.** It says what the
|
|
222
|
+
prober saw on that tree. It is no proof against a hostile agent without an OS sandbox: an agent that can write to
|
|
223
|
+
`events.jsonl` can also write a false entry, as for every other log line (see section 3). Compare `targetSha256`
|
|
224
|
+
with the file you reviewed.
|
|
198
225
|
- For `--cmd`, `targetSha256` covers one file only: `--target-file`, else the first existing file after the
|
|
199
226
|
interpreter, else nothing (`null`). Imports, libraries and the interpreter are not hashed.
|
|
200
227
|
|
|
201
|
-
## Known limits of 1.2.
|
|
202
|
-
|
|
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).
|
|
228
|
+
## Known limits of 1.2.1
|
|
230
229
|
|
|
231
|
-
|
|
230
|
+
What a regular expression cannot block (the unit test "1.2.1 known limits without an OS sandbox" keeps these visible):
|
|
232
231
|
|
|
233
|
-
-
|
|
234
|
-
|
|
235
|
-
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
## Known limits of 1.1.2
|
|
232
|
+
- 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
|
|
233
|
+
`nv`, never `.env`. The same holds for aliases, shell functions and a backslash inside a word (`g\it`).
|
|
234
|
+
- A script: `node /tmp/x.js`, `bash x.sh`. The text checks do not read the script.
|
|
235
|
+
- A wildcard outside the cases of section 2: `find . -name '.g*' -delete`, `echo .g* | xargs rm -rf`, a PowerShell
|
|
236
|
+
`Remove-Item * -Recurse -Force` (on Windows `*` also matches dot directories), and directory wildcards on the way to a
|
|
237
|
+
secret (`cat secre*/db.txt`). A bare `.*` in `echo .*` or `ls .*` counts as a secret read (it reaches `.env`).
|
|
238
|
+
- One variable or another program: `echo $TOKEN`, `export -p`, `declare -x`, `node -e "console.log(process.env)"`.
|
|
242
239
|
|
|
243
|
-
|
|
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.
|
|
240
|
+
Other limits:
|
|
252
241
|
|
|
253
|
-
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
242
|
+
- `safeTools` while halted: a human who adds a glob vouches that those tools are local. With a broad glob (for example
|
|
243
|
+
`mcp__*`) a halted agent keeps those tools. Edit, Write, Read and the shell stay paused whatever the list says.
|
|
244
|
+
- `--require-run` is optional (default `false`). It decides by the event's source (`stopbar run` or an agent hook), not
|
|
245
|
+
by what ran. Without it, the exact gate command from the agent's shell counts.
|
|
246
|
+
- The stdin heredoc exception holds only for one single-quoted `<<'EOF'` and trusts the command on the header line not
|
|
247
|
+
to run its stdin. Stopbar knows the common shells and interpreters (and `xargs`, `at`, `tee`, `stopbar`); another
|
|
248
|
+
program that executes stdin passes. The exception covers only the human-only checks.
|
|
249
|
+
- Git hooks: a foreign `pre-commit` or `pre-push` is kept with a `WARN` when the git hooks were added by default; that
|
|
250
|
+
git action is not gated until a human runs `stopbar upgrade --hooks git --force-hooks`. With a custom
|
|
251
|
+
`core.hooksPath` (Husky, Lefthook, a shared directory) Stopbar writes no git hook there without `--force-hooks`, so
|
|
252
|
+
git commit and git push are not gated until a human adds the `git-hook` lines that `stopbar doctor` prints.
|
|
253
|
+
`stopbar doctor` reports `[WARN] hooks git` (not `[FAIL]`) while a Stopbar git hook is missing.
|
|
254
|
+
- `baseRef`: a mutable branch name can be moved by the agent (section 3, point 4). Use a commit SHA as `--base-ref`
|
|
255
|
+
when the agent must not move the baseline. `stopbar status` prints a `note:` when the tree no longer differs from
|
|
256
|
+
`baseRef` on existing tests; it never clears the taint (L2.2).
|
|
257
|
+
- `init --force` and `reset` count all suspicious uncommitted changes as one kernel step; a branch whose tests differ
|
|
258
|
+
from `baseRef` starts tainted until `approve-tests`.
|
|
259
|
+
- `stopbar upgrade` re-pins the runtime from the package that runs the command. It does not check that the package is
|
|
260
|
+
newer, and it does not change `config.json`.
|
|
261
|
+
- `stopGate: "warn"`: in Cursor, Codex CLI, Gemini CLI and Antigravity CLI the WARN text is not shown to the agent; the
|
|
262
|
+
entry in `events.jsonl` and `stopbar status` show it.
|
|
263
|
+
- `cliCmd` is checked as text, not for whether it starts Stopbar. `buildCmd` and `fullTestCmd` that run the same script
|
|
264
|
+
under two names (`npm test` and `npm run test`) are not detected.
|
|
265
|
+
- `stopbar doctor` checks the kernel link only where `gdp-wired` resolves from the running copy; a pinned runtime
|
|
266
|
+
reports `[WARN] kernel link`.
|
|
267
|
+
- `--cmd`: the command runs through the system shell (`cmd.exe` on Windows, `/bin/sh` elsewhere). A shell can hold
|
|
268
|
+
stdout open after the program closed it; then only `--cmd-timeout` (default 300000 ms) ends the wait. Answers are
|
|
269
|
+
checked for their shape, not for meaning; mutants (`--check-mutants`) are the check that the model can fail.
|
|
270
|
+
Stopbar does not check that `generate` is deterministic.
|
|
271
|
+
- `probe init --lang py` prints `python` on Windows and `python3` elsewhere. `probe init --lang ts` runs only where
|
|
272
|
+
`stopbar/probe` resolves.
|
|
273
|
+
- Lean: the check needs Docker and a one-time image build with network access, or Lean 4.34.0 on `PATH` with
|
|
274
|
+
`node scripts/verify-lean.ts --local`. The base image and the Lean archive are pinned at the first build (trust on
|
|
275
|
+
first use). Each export is a different proof tree; the gate checks the one it exports.
|
|
257
276
|
- 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
|
|
259
|
-
|
|
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.
|
|
277
|
+
Linux (Debian 13, Node 24). macOS runs only in CI (`.github/workflows/ci.yml`).
|
|
278
|
+
- Adapters: Cursor, Codex CLI, Gemini CLI and Antigravity CLI are spec-tested; a client can change its hook schema.
|
|
262
279
|
- 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
280
|
|
|
264
281
|
## 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}
|
package/dist/adapters/claude.js
CHANGED
|
@@ -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) {
|
package/dist/adapters/codex.js
CHANGED
|
@@ -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 {
|
|
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) {
|
package/dist/adapters/cursor.js
CHANGED
|
@@ -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})}
|
package/dist/adapters/gemini.js
CHANGED
|
@@ -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) {
|