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/CHANGELOG.md CHANGED
@@ -1,5 +1,93 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.2.2] (2026-11-27)
4
+
5
+ `src/kernel.ts` is unchanged (sha256 `c602fc4bcf8ffb2e...`); every kernel law holds as in 1.2.1. No new dependency.
6
+ `PreToolUse` still starts no git process. A `config.json` and a `state.json` from 1.0.0–1.2.1 work without migration;
7
+ the new test-config patterns below reach an existing repository with `stopbar init --force`.
8
+
9
+ - **Husky, Lefthook and a custom `core.hooksPath` are protected.** Edit and Write of `.husky/**`, `lefthook*.yml`,
10
+ `.lefthook*.yml` (also `.yaml`, `-local`), `.lefthook/**` and of every file in the custom `core.hooksPath` are
11
+ blocked; so are shell commands that name them (`sed -i '/git-hook/d' .husky/pre-commit`, `rm -rf .husky`), matched on
12
+ path-segment boundaries (an empty, `.` or `/` value protects nothing). The hook reads `core.hooksPath` from
13
+ `<common-dir>/config` and `config.worktree` itself (`readHooksPath`), without a git process. `.husky` and `.lefthook`
14
+ join the wildcard guard (`rm -rf .hu*`), and `pre-commit`, `pre-push` and `_` the names checked inside a guarded
15
+ directory. The same files are test config in every profile, so a change made outside the agent hooks taints.
16
+ - **`stopbar doctor` reports `[FAIL] hooks git` when a Stopbar git hook is gone**: written by the last `init` or a later
17
+ `upgrade` (the events now record `gitHooksWritten`), run since the last `init` or `reset` (`hook-timing` records
18
+ `gitHook`), called by the tracked hook file in `HEAD`, or the other hook is still in place and the log does not say
19
+ that Stopbar left this one out. A hook that was never set up stays `[WARN]`. Doctor only reads `events.jsonl`.
20
+ - **Portable hook line.** The `WARN` of `init`, the refusal of `--hooks git` and `doctor` print
21
+ `npx --no-install stopbar git-hook pre-commit|pre-push` (from `--cli`) first and, without a local `node_modules`,
22
+ `node "$(git rev-parse --git-dir)/stopbar/runtime/bin/stopbar.mjs" git-hook <name>`; no absolute path into `.git`.
23
+ - **Wildcards after `$(pwd)`.** `$(pwd)`, `"$(pwd)"`, `${PWD}`, `$PWD`, `` `pwd` `` (also quoted, `pwd -L|-P`) read as `.`
24
+ before the command is split, so `rm -rf $(pwd)/.g*` is blocked as `rm -rf $PWD/.g*` was, and `cat $(pwd)/.e*` is a
25
+ secret read.
26
+ - **`find` with a pattern.** `find` with `-name`, `-iname`, `-path`, `-ipath`, `-wholename` or `-iwholename` whose
27
+ pattern reaches `.git`, an agent settings directory, `.husky`, `.lefthook`, a Lefthook file or the custom
28
+ `core.hooksPath`, together with `-delete`, `-exec`, `-execdir`, `-ok` or `-okdir`, is blocked; a pattern that reaches a
29
+ secret name (`.e*`, `*.pem`, `*.key`, `*/.env*`) with an `-exec` action is a secret read. `find . -name "*.ts" -exec
30
+ wc -l {} +` and `find . -name "*.test.ts" -delete` stay allowed.
31
+ - **`stopbar doctor --strict`**: a `[WARN]` fails too (exit 1, `RESULT: FAIL (strict: N warning(s))`, `--json`
32
+ `ok: false, strict: true`). Without the flag nothing changes.
33
+ - **`init` notes.** Without `--require-run`, `init` names `--require-run` and `doctor --strict` for CI; with
34
+ `--hooks codex` it recommends `--require-run`, because Codex CLI passes no exit status to its hooks. The default stays
35
+ `requireRun: false`.
36
+ - **`init --force` keeps `safeTools`**, and `--safe-tools "<glob>,<glob>"` sets them. A damaged previous `config.json`
37
+ never blocks `--force` (then the default list).
38
+ - **`--help` / `-h` in every subcommand** prints the help and runs nothing (`stopbar reset --help` no longer resets). A
39
+ `--help` that is the value of a flag (`--cmd --help`) is not taken as a request for help.
40
+ - **`stopbar run` on Windows** starts the gate command without the `PWD` inherited from Git Bash, so a bash inside
41
+ the gate sets its own (`PATH="$PWD/node_modules/.bin:$PATH"` broke at the colon of `C:`, exit 127). `stopbar doctor`
42
+ warns when a gate starts with a bare `bash` and the first bash on `PATH` is WSL's.
43
+ - **`import 'stopbar/probe'` without `stopbar` in the project's `node_modules`.** `stopbar probe --target <file>`
44
+ resolves that specifier to its own SDK with a module resolve hook (`registerHooks`, `node:module`), in the runner and
45
+ in each worker.
46
+ - **Docs.** The PROBE guide moved from `README.md` to [`docs/probe.md`](docs/probe.md) (in the npm package). The README
47
+ starts with one statement of what is proven, what is tested and what needs an OS sandbox, without the repeated
48
+ paragraph. `SECURITY.md`: Known limits of 1.2.2.
49
+ - No `any` in `integrations.ts` and `store.ts` (typed JSON and event entries). Version 1.2.2.
50
+
51
+ ## 1.2.1 (2026-11-27)
52
+
53
+ `src/kernel.ts` is unchanged (sha256 `c602fc4bcf8ffb2e...`); every kernel law holds as in 1.2.0. No new dependency.
54
+ A `config.json` and a `state.json` from 1.0.0–1.2.0 work without migration.
55
+
56
+ - **Custom `core.hooksPath` is not written.** When `core.hooksPath` points outside `.git/hooks` (Husky, Lefthook, a
57
+ shared or tracked hooks directory), `init --hooks <client>` writes no git hook there and prints a `WARN` with the
58
+ manual `node "<runtime>/bin/stopbar.mjs" git-hook pre-commit|pre-push` lines; explicit `--hooks git` without
59
+ `--force-hooks` fails closed (exit 2) before any hook file is written; `--force-hooks` writes the hooks and keeps a foreign
60
+ one as `<name>.stopbar-backup`. `stopbar doctor` reports `[WARN] hooks git`: it says that git commit and git push are
61
+ not gated, and prints the exact line for each missing hook. A `stopbar git-hook <name>` line chained by hand counts.
62
+ - **`stopbar status` after `baseRef` advanced.** With `testsTainted` and a non-`HEAD` `baseRef`, `status` prints
63
+ `note: no existing test or test-config file currently differs from <baseRef>; ...` when that is so, and
64
+ `status --json` has `taintedDiffersFromBaseRef` (`true`, `false`, or `null` when untainted or without `baseRef`).
65
+ The taint stays (L2.2): `status` never writes `state.json`.
66
+ - **`stopbar probe --cmd`: no silent exit.** A target that printed a banner or a non-JSON answer to `info` ended the
67
+ CLI with exit 0 (and `await probe()` with exit 13) on Linux: `close()` waited for an `exit` event of a killed,
68
+ unref'd child against an unref'd timer. `close()` now returns at once for a killed or exited process, and its timers
69
+ hold the event loop and are cleared. Regression test: banner, non-JSON and crash on `info` give exit 1 from the CLI
70
+ and a `ProbeError` from `probe()` and `loadCmd()`; exit 0 comes only with `PROBE PASS`.
71
+ - **Four bypasses closed in `src/classify.ts`.** `printenv`, a bare `env`, `Get-ChildItem Env:` and
72
+ `/proc/self/environ` are a secret read (`env VAR=1 cmd` and `set` are not). Tokens with `..` are normalised
73
+ (`cat src/../.env`), and a live wildcard that reaches a secret name is a read (`cat .en*`, `cat .en?`). `rm`, `mv`,
74
+ `del`, `Remove-Item` and the like with a wildcard on `.git` or an agent settings directory are blocked (`rm -rf .g*`,
75
+ `rm -rf .cl*`), and so is a wildcard followed by a path inside (`cp x .g*/hooks/pre-commit`). A git subcommand from
76
+ an expansion is blocked (`git $f -m x`, `p=push; git $p --no-verify`, `git "${cmd}"`). Unit tests also record the
77
+ known limits (`cat $(echo .e)nv`, `f=.e; cat ${f}nv`, `node /tmp/x.js`).
78
+ - **`stopbar doctor` names the gate mode** on the `config.json` line: `gates: hook command text (use --require-run for
79
+ exit-code-only gates)` or `gates: stopbar run only (--require-run)`. `--require-run` stays optional.
80
+ - **Tests:** HALT with `safeTools: ["*"]` still pauses Bash, Edit, Write and Read; the heredoc exceptions hold only
81
+ for `<<'EOF'` (not `<<EOF`, `<<"EOF"`, `bash -s <<'EOF'` or `sh <<'EOF'`).
82
+ - **Types:** no `any` left in `src/hook.ts`, `src/verify.ts`, `src/doctor.ts`, `src/probe/` and `src/adapters/`.
83
+ In the probe SDK, `ActionSpec.run` takes `args: unknown` (was `any`); destructured arguments such as
84
+ `run: (s, {x}, check)` still compile. `npm run typecheck` builds first, so it works on a fresh clone.
85
+ - **Release:** `.github/workflows/release.yml` publishes to npm with provenance (Trusted Publishing, OIDC) when a `v*`
86
+ tag that matches `package.json` is pushed.
87
+ - **Docs:** README and SECURITY open with what is proven, what is tested and what needs an OS sandbox, add
88
+ "Hardening: OS sandbox + client deny rules", list the default `safeTools` with a warning about broad globs, and say
89
+ what probe evidence in `attest` is. SECURITY has one "Known limits of 1.2.1" section.
90
+
3
91
  ## 1.2.0 (2026-11-26)
4
92
 
5
93
  `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
- Stopbar is an execution gate for AI coding agents in two parts: a **formally proven decision kernel**
4
- (`src/kernel.ts`, about 160 lines, its laws proven by induction and checked again by `lake build` in Lean 4.34.0) and
5
- a **tested wrapper** around it: the hooks of Claude Code, Cursor, Codex CLI, Gemini CLI and Antigravity CLI, and git
6
- hooks for any other tool. The wrapper reads tool calls and command text and asks the kernel; it is covered by unit and
7
- E2E tests and stateful probing, not by the proof.
3
+ [![CI](https://github.com/polszewski-pl/stopbar/actions/workflows/ci.yml/badge.svg)](https://github.com/polszewski-pl/stopbar/actions/workflows/ci.yml)
4
+ [![npm](https://img.shields.io/npm/v/stopbar)](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, Husky and Lefthook hooks 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
@@ -18,12 +25,11 @@ It stops an agent from:
18
25
  - looping on failing builds or tests, or going past a budget of tool calls;
19
26
  - switching itself off by editing the agent's hook configuration, git hooks or its own state.
20
27
 
21
- The decisions come from one rule, `src/kernel.ts`. gdp-wired 0.60.0 proves its laws by induction, and 10 mutants of
22
- the rule each fall with a counterexample. Every client goes through the same rule: an adapter translates the client's
23
- hook payload into one internal event and renders the decision in the client's own output format.
24
-
25
28
  ## Supported agents
26
29
 
30
+ Every client goes through the same rule: an adapter translates the client's hook payload into one internal event and
31
+ renders the decision in the client's own output format.
32
+
27
33
  | Agent | Config written by `init --hooks` | Events | Block protocol | Status |
28
34
  |---|---|---|---|---|
29
35
  | 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) |
@@ -44,15 +50,6 @@ working. An unknown or damaged payload fails closed (exit 2). The configs writte
44
50
  `stopbar run build` and `stopbar run test`. The git hooks then allow a commit only after both passed at the
45
51
  current tree, block it after an unapproved test change, and block a push after a secret read without approval.
46
52
 
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
53
  ## Set up in 3 steps
57
54
 
58
55
  Requirements: Node.js 22.18 or later, git, a git repository.
@@ -111,7 +108,7 @@ EOF
111
108
 
112
109
  | Command | Who | What it does |
113
110
  |---|---|---|
114
- | `stopbar init --build "<cmd>" --test "<cmd>" [--profile p] [--base-ref <ref>] [--cli "<cmd>"] [--stop-gate block\|warn] [--require-run] [--max-retries 3] [--cap 500] [--cost 1] [--hooks <targets>] [--no-git-hooks] [--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; `git` is added to any other target unless `--no-git-hooks`. `--require-run`: the build and full test gates count only through `stopbar run build\|test`. `--build` and `--test` must be different commands. `--base-ref` sets the git ref used to judge whether a test file already existed (default `HEAD`). `--cli` sets the Stopbar command in hints (default `npx --no-install stopbar`). `--stop-gate warn` lets a turn end with unverified changes (default `block`); commit and push stay gated. |
111
+ | `stopbar init --build "<cmd>" --test "<cmd>" [--profile p] [--base-ref <ref>] [--cli "<cmd>"] [--stop-gate block\|warn] [--require-run] [--safe-tools "<glob>,<glob>"] [--max-retries 3] [--cap 500] [--cost 1] [--hooks <targets>] [--no-git-hooks] [--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; `git` is added to any other target unless `--no-git-hooks`. `--require-run`: the build and full test gates count only through `stopbar run build\|test`. `--build` and `--test` must be different commands. `--base-ref` sets the git ref used to judge whether a test file already existed (default `HEAD`). `--cli` sets the Stopbar command in hints (default `npx --no-install stopbar`). `--stop-gate warn` lets a turn end with unverified changes (default `block`); commit and push stay gated. `--safe-tools` sets `safeTools` (comma separated globs); without it `--force` keeps the list of the previous `config.json`. |
115
112
  | `stopbar upgrade [--hooks <targets>] [--force-hooks]` | human | After you update the Stopbar package: re-pins the hook runtime in `.git/stopbar/runtime` and, with `--hooks`, rewrites the hooks. `state.json`, `config.json` and the snapshots stay as they are (revision, gates, taint, budget), so an active session keeps its green gates. Use it instead of `init --force`. |
116
113
  | `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). |
117
114
  | `stopbar git-hook pre-commit\|pre-push` | git | The git fallback gate. Exit 1 aborts the commit or push. |
@@ -121,103 +118,32 @@ EOF
121
118
  | `stopbar approve-shell` | human | Allows **one** risky or outbound call after a secret read. |
122
119
  | `stopbar resume --extra N` | human | Lifts a halt (retry limit or budget) and adds N to the budget. |
123
120
  | `stopbar reset` | human | Fresh kernel state. Config and event log stay. Also repairs a damaged `state.json`. Uncommitted changes of existing tests or test config (against `baseRef`, else `HEAD`) are not forgotten: the session starts tainted, with a `WARN`, until `approve-tests`. `init --force` does the same. |
124
- | `stopbar doctor [--json]` | human | Environment, config, state, hooks and a dry run. Exit 1 on a problem. |
121
+ | `stopbar doctor [--json] [--strict]` | human, CI | Environment, config, state, hooks and a dry run. It only reads the repository's event log. Exit 1 on a problem; with `--strict` also on a warning (`RESULT: FAIL (strict: N warning(s))`, in `--json` `ok: false, strict: true`). |
125
122
  | `stopbar prove [--out f.json] [--lean f.lean]` | human, CI | PROVE: the inductive proof of the kernel and the 10 mutants. Exit 0 only if everything holds. `verify` is an alias. |
126
- | `stopbar probe [--target wrapper\|<file> \| --cmd "<command>" [--target-file <path>] [--cmd-timeout 300000]] [--runs 200] [--seed 1] [--jobs N] [--work dir] [--out dir] [--regressions dir] [--regressions-only] [--check-mutants] [--mutant-runs 50] [--no-record]` | human, CI | PROBE: stateful probing of the hooks against the proven kernel (`wrapper`, needs the full package with gdp-wired), of your own model in a `.ts`, `.mts`, `.js` or `.mjs` file, or of a program in any language over NDJSON (`--cmd`, see [PROBE for your project](#probe-for-your-project)). `--target` and `--cmd` exclude each other. A failure is shrunk to a minimal JSON reproduction. |
123
+ | `stopbar probe [--target wrapper\|<file> \| --cmd "<command>" [--target-file <path>] [--cmd-timeout 300000]] [--runs 200] [--seed 1] [--jobs N] [--work dir] [--out dir] [--regressions dir] [--regressions-only] [--check-mutants] [--mutant-runs 50] [--no-record]` | human, CI | PROBE: stateful probing of the hooks against the proven kernel (`wrapper`, needs the full package with gdp-wired), of your own model in a `.ts`, `.mts`, `.js` or `.mjs` file, or of a program in any language over NDJSON (`--cmd`, see [docs/probe.md](docs/probe.md)). `--target` and `--cmd` exclude each other. A failure is shrunk to a minimal JSON reproduction. |
127
124
  | `stopbar probe init [--lang ts\|py] [--name sample] [--out probes] [--force] [--repo <dir>]` | human, agent | Writes a starter target with 2 actions, 1 invariant and 2 mutants (`<name>.probe.ts` or `<name>_probe.py`) and prints the command that runs it. It does not overwrite a file without `--force`. |
128
125
  | `stopbar attest [--format json\|md]` | human, CI | ATTEST: the session attestation. The same state and log give the same output. Exit 1 if the state and the log disagree, exit 2 if a file is damaged. `probes` (Markdown: `## Probe evidence`) lists the latest `probe:result` per target since the last `init` or `reset`, with `atCurrentSnapshot`. |
129
126
 
130
- All commands take `--repo <dir>`. The agent cannot run the human commands: the hooks block them.
127
+ All commands take `--repo <dir>` and `--help` / `-h` (prints the help, runs nothing). The agent cannot run the human
128
+ commands: the hooks block them.
131
129
 
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
 
135
- ## PROBE for your project
136
-
137
- `stopbar probe --target <file>` runs a model of any TS/JS code. The file exports (as `default` or as `target`) a
138
- target; `defineModel` from `stopbar/probe` builds one from a list of actions:
139
-
140
- ```ts
141
- import {defineModel} from 'stopbar/probe'
142
-
143
- export default defineModel<{q: BoundedQueue<number>; model: number[]}>({
144
- name: 'bounded-queue', description: 'FIFO queue with capacity 4 vs an array model',
145
- setup: () => ({q: new BoundedQueue<number>(4), model: []}),
146
- actions: [
147
- {name: 'push', weight: 3, gen: (r) => ({x: r.int(0, 99)}), run: (s, {x}, check) => {
148
- const accepted = s.model.length < 4
149
- check.eq('push result', s.q.push(x), accepted)
150
- if (accepted) s.model.push(x)
151
- }},
152
- {name: 'shift', gen: () => null, run: (s, _a, check) => check.eq('shift result', s.q.shift(), s.model.shift())},
153
- ],
154
- invariants: [{name: 'size', check: (s, check) => check.eq('size', s.q.size, s.model.length)}],
155
- mutants: {M1_dropCap: () => ({q: new BoundedQueue<number>(4, {checkCap: false}), model: []})},
156
- })
157
- ```
158
-
159
- - `gen(r)` returns pure JSON data for one step. `r` is a deterministic generator (`createRng`: xorshift32, the same
160
- numbers on Windows and Linux). A run is `{seed, actions: [{t: name, args}]}` with `minSteps`..`maxSteps` steps
161
- (default 15..40).
162
- - `run(state, args, check)` drives the real code and compares it with the model: `check.eq` (deep strict equality),
163
- `check.ok`, `check.fail`. A failed check, and any exception from the code under test, is a mismatch with the step and
164
- the action, not a crash. Invariants run after `setup` (step -1) and after every step. `teardown` runs after every run
165
- whose `setup` returned, also after a failure.
166
- - A failure is shrunk (cut after the failing step, then removal of blocks of half, a quarter, ... of the run, then of
167
- single steps) and written to `repro-<seed>.json` in `--out`. `--regressions <dir>` replays such files on every run.
168
- A file target replays only the regressions you name.
169
- - `--check-mutants`: each mutant replaces `setup` with a damaged system under test. The original must pass, and every
170
- mutant must fail within `--mutant-runs` seeds (default 50). Exit 0 only then. A survivor is named in the output and
171
- in `summary.json` (`mutants.survived`). A target without mutants is refused.
172
- - In a repository with Stopbar, every run appends a `probe:result` entry to `events.jsonl` (target, sha256 of the
173
- target file, tree snapshot, runs, steps, mutants, sha256 of `summary.json`). It is not a kernel step and does not
174
- change `state.json`. `stopbar attest` shows the latest entry per target and whether the tree is still the one that
175
- was probed. `--no-record` skips the entry. Outside a Stopbar repository nothing is recorded.
176
-
177
- A complete example with two mutants: [`examples/bounded-queue.probe.ts`](examples/bounded-queue.probe.ts)
178
- (`stopbar probe --target examples/bounded-queue.probe.ts --check-mutants`). TypeScript files need Node's type
179
- stripping (Node 22.18 or later): only erasable syntax, no `enum` and no constructor parameter properties.
180
-
181
- ### Any language: `--cmd`
182
-
183
- `stopbar probe --cmd "<command>"` probes a program in any language (Python, Go, Rust, ...). Each worker (`--jobs`)
184
- starts the command once, in a shell, in the current directory, and keeps it for all its runs, so the start-up cost
185
- is paid once per worker and not once per seed. Stopbar sends one JSON object per line on stdin and reads one answer
186
- per line on stdout (NDJSON):
187
-
188
- | Request | Answer |
189
- |---|---|
190
- | `{"op":"info"}` | `{"name":"<string>","description":"<string>","mutants":["M1",...]}` (`mutants` is optional) |
191
- | `{"op":"generate","seed":123}` | `{"seed":123,"actions":[...]}`: pure JSON data, the same for the same seed |
192
- | `{"op":"execute","run":{"seed":123,"actions":[...]},"dir":"<scratch dir>","mutant":"M1"}` | `{"ok":true,"steps":N,"cov":{"push":3}}` or `{"ok":false,"mismatch":{"step":2,"action":{...},"what":"...","expected":...,"actual":...}}` |
193
-
194
- - `mutant` is sent only with `--check-mutants`. `dir` is an empty scratch directory for each execution.
195
- - Any answer can be `{"error":"<text>"}`. stdout is for the protocol only: print logs to stderr.
196
- - An exception of the code under test is a finding: catch it in `execute` and answer with a mismatch (the
197
- templates do this). A process that exits, closes stdout, prints a line that is not JSON or gives no answer within
198
- `--cmd-timeout` ms (default 300000) stops the probe with exit 1 and the end of its stderr. When the probe ends,
199
- Stopbar closes stdin; a process that does not exit within 2 s is killed.
200
- - Shrinking, `--regressions` / `--regressions-only`, `--check-mutants`, `summary.json`, `repro-<seed>.json`,
201
- `probe:result` and `attest` work as for `--target <file>`. `target` in a reproduction is the `name` from `info`;
202
- `targetCmd` is the command. A `--cmd` target replays only the regressions in `--regressions <dir>`.
203
- - `targetSha256` is the sha256 of `--target-file <path>`, else of the first word after the interpreter that is an
204
- existing file (`python examples/bounded_queue_probe.py` hashes that file), else `null`.
205
-
206
- [`examples/bounded_queue_probe.py`](examples/bounded_queue_probe.py) is the same queue model in Python, with the
207
- standard library only:
133
+ ## Parts of the package
208
134
 
209
- ```sh
210
- stopbar probe --cmd "python examples/bounded_queue_probe.py" --runs 200 --check-mutants
211
- ```
135
+ The gate (GATE, with PROVE and ATTEST) is the product. PROBE is a test tool that ships in the same package.
212
136
 
213
- ### A starter target: `stopbar probe init`
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. Guide: [docs/probe.md](docs/probe.md). |
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. |
214
143
 
215
- `stopbar probe init --lang ts` writes `probes/sample.probe.ts` (`defineModel`), and `--lang py` writes
216
- `probes/sample_probe.py` (the NDJSON protocol, standard library only: `json`, `random`, `sys`). Both hold the same
217
- model with 2 actions, 1 invariant, 2 mutants and the rules for zero false positives, and `--check-mutants` passes on
218
- them as written. The command prints the line that runs the file. `--name` takes letters, digits, `-` and `_` only;
219
- `--out` (default `probes`) is relative to `--repo`, else to the current directory; an existing file stays unless you
220
- pass `--force`.
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).
221
147
 
222
148
  ## Agent skill
223
149
 
@@ -273,9 +199,14 @@ profile by editing the lists: no code change is necessary.
273
199
  Claude Desktop and its tools for messages between local sessions. It only exempts tools from the outbound gate
274
200
  (WebFetch, WebSearch, MCP tools); shell commands, edits and reads are gated as before. Since 1.2.0 these tools also
275
201
  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. A `config.json` written by 1.0.0–1.1.1 keeps its own list and keeps working; to stop false
202
+ step. Every other tool stays paused while halted. Edit, Write, Read and the shell tools stay gated even if a glob in
203
+ `safeTools` matches them (also `["*"]`). **Keep the globs narrow**: with a broad glob such as `mcp__*`, every MCP tool
204
+ is treated as local, passes the outbound gate after a secret read and keeps working while the session is halted.
205
+ A `config.json` written by 1.0.0–1.1.1 keeps its own list and keeps working; to stop false
277
206
  `PAUSE`s on the session tools after a secret read, add `"mcp__ccd_session_mgmt__*"` to `safeTools` or write the file
278
207
  again with `stopbar init --force ...`. `stopbar doctor` shows a `[WARN] safeTools` while a default entry is missing.
208
+ `stopbar init --safe-tools "<glob>,<glob>"` sets the list. Since 1.2.2 `init --force` without `--safe-tools` keeps
209
+ the list of the previous `config.json` (when that file is valid) and says so.
279
210
  - **`cliCmd`** (optional, set via `stopbar init --cli "<cmd>"`) is the command that starts Stopbar in the hints shown to
280
211
  the agent (`<cliCmd> run build|test`). Without it the hints say `npx --no-install stopbar`. It must be one command
281
212
  without shell operators and must not name a `.git` or agent-settings directory, because the agent's shell may not run
@@ -295,6 +226,64 @@ profile by editing the lists: no code change is necessary.
295
226
  A damaged or empty `config.json` or `state.json` blocks every tool call (exit 2) with a message that says how to
296
227
  repair it.
297
228
 
229
+ `stopbar doctor` shows the gate mode on the `config.json` line: `gates: hook command text (use --require-run for
230
+ exit-code-only gates)` by default, `gates: stopbar run only (--require-run)` with `requireRun`.
231
+
232
+ **Custom `core.hooksPath`** (Husky, Lefthook, a shared hooks directory): since 1.2.1 Stopbar does not write into it.
233
+ `init --hooks <client>` then writes no git hook and prints a `WARN`; `init --hooks git` fails closed (exit 2);
234
+ `stopbar doctor` reports `[WARN] hooks git`: git commit and git push are not gated by Stopbar until a human adds one
235
+ line to each hook of the hook manager, or runs `stopbar upgrade --hooks git --force-hooks`. The line works on every
236
+ machine, so it can go into a tracked hook such as `.husky/pre-commit`:
237
+
238
+ ```sh
239
+ npx --no-install stopbar git-hook pre-commit # .husky/pre-commit
240
+ npx --no-install stopbar git-hook pre-push # .husky/pre-push
241
+ # without Stopbar in the local node_modules: the pinned runtime, relative to the git dir (also in a linked worktree)
242
+ node "$(git rev-parse --git-dir)/stopbar/runtime/bin/stopbar.mjs" git-hook pre-commit
243
+ ```
244
+
245
+ The first command follows `--cli` (default `npx --no-install stopbar`). Since 1.2.2 the agent cannot remove that
246
+ line: Edit and Write of `.husky/**`, `lefthook*.yml`, `.lefthook*.yml`, `.lefthook/**` and of every file in the
247
+ custom `core.hooksPath` are blocked, and so are shell commands that name them (`sed -i '/git-hook/d' .husky/pre-commit`,
248
+ `rm -rf .husky`, `find . -name '.hu*' -delete`). The hook reads `core.hooksPath` from the git config files itself,
249
+ without a git process. These files are also test config, so a change made outside the agent hooks taints the
250
+ session. `stopbar doctor` reports `[FAIL] hooks git` (not `[WARN]`) when a Stopbar git hook that was there is gone:
251
+ written by the last `init` or a later `upgrade`, run since the last `init` or `reset`, called by the tracked hook
252
+ in `HEAD`, or the other of the two hooks is still in place.
253
+
254
+ ## Hardening: OS sandbox + client deny rules
255
+
256
+ Stopbar reads command text. To stop an agent that tries to get around it, add two layers that do not depend on text.
257
+
258
+ 1. **Client deny rules.** The agent's own permission rules refuse a tool call before any hook. For Claude Code, in
259
+ `.claude/settings.json` (check the rule syntax against your client's documentation):
260
+
261
+ ```json
262
+ {
263
+ "permissions": {
264
+ "deny": [
265
+ "Read(./.env)", "Read(./.env.*)", "Read(./secrets/**)",
266
+ "Edit(./.git/**)", "Edit(./.claude/**)",
267
+ "Bash(curl:*)", "Bash(wget:*)", "Bash(printenv:*)",
268
+ "WebFetch"
269
+ ]
270
+ }
271
+ }
272
+ ```
273
+
274
+ 2. **OS sandbox.** Run the agent in a container, a VM or a sandbox runtime (for example Anthropic's `sandbox-runtime`
275
+ or Claude Code's Bash sandbox) without network, with only the repository writable:
276
+
277
+ ```sh
278
+ docker run --rm -it --network none -v "$PWD:/work" -v "$PWD/.claude:/work/.claude:ro" \
279
+ -v "$PWD/.git/hooks:/work/.git/hooks:ro" -w /work <agent-image>
280
+ ```
281
+
282
+ The hooks write `.git/stopbar/`. When the whole agent runs in the container, the hooks run there too, so
283
+ `.git/stopbar/` must stay writable, and the agent's shell can write it as well. A sandbox that wraps only the
284
+ agent's shell (the hooks run outside it) can deny writes to `.git/stopbar/` inside the sandbox. Run the human
285
+ commands (`approve-tests`, `approve-shell`, `resume`, `reset`) outside the sandbox.
286
+
298
287
  ## Local use
299
288
 
300
289
  - `npm run build` builds `dist/` from `src/` with Node's own type stripping and generates `dist/kernel.gen.js` from
@@ -329,10 +318,13 @@ Ubuntu, Windows and macOS (Node 24); `npm run prove`; and `lake build` of the Le
329
318
  - run: npx stopbar prove --out stopbar-prove.json
330
319
  ```
331
320
 
332
- For headless agent runs in CI, initialise Stopbar in the job and keep the evidence:
321
+ For headless agent runs in CI, initialise Stopbar in the job with `--require-run` (the gates count only through
322
+ `stopbar run build|test`), check the setup with `stopbar doctor --strict` (a warning fails the job) and keep the
323
+ evidence:
333
324
 
334
325
  ```yaml
335
- - run: npx stopbar init --build "npm run build" --test "npm test" --hooks project
326
+ - run: npx stopbar init --build "npm run build" --test "npm test" --hooks project --require-run
327
+ - run: npx stopbar doctor --strict
336
328
  - run: claude -p "<task>" --setting-sources project,local --max-turns 20
337
329
  - run: npx stopbar status --json > stopbar-status.json
338
330
  - run: npx stopbar attest --format md > stopbar-attest.md
@@ -355,11 +347,16 @@ latency. An earlier prototype that loaded the prover in every hook measured p50
355
347
 
356
348
  | Platform | Node | git | Python | Typecheck | Unit | E2E | `stopbar probe` | `--cmd` Python example | `stopbar prove` | `stopbar doctor` |
357
349
  |---|---|---|---|---|---|---|---|---|---|---|
358
- | Windows 11, Git for Windows | 24.19.0 | 2.56.0 | 3.14.7 | 0 errors | 70/70 | 443/443 | 202/202 sequences | 200/200, mutants 2/2 | proven, 10/10 mutants | OK |
359
- | Linux, Debian 13 (container, no network) | 24.21.0 | 2.47.3 | 3.13.5 | 0 errors | 70/70 | 443/443 | 202/202 sequences | 200/200, mutants 2/2 | proven, 10/10 mutants | OK |
360
- | Ubuntu, Windows, macOS (GitHub Actions) | 24 | runner | runner | CI | CI | CI | CI | – | CI (Ubuntu) | – |
350
+ | Windows 11, Git for Windows | 24.19.0 | 2.56.0 | 3.14.7 | 0 errors | 81/81 | 502/502 | 202/202 sequences | 200/200, mutants 2/2 | proven, 10/10 mutants | OK |
351
+ | Linux, Debian 13 (container, no network) | 24.21.0 | 2.47.3 | 3.13.5 | 0 errors | 81/81 | 502/502 | 202/202 sequences | 200/200, mutants 2/2 | proven, 10/10 mutants | OK |
352
+ | macOS 26.7.2 arm64 (`macos-latest`, GitHub Actions, CI of 1.2.1) | 24.22.3 | 2.56.1 | – | 0 errors | pass | 460/460 | 202/202 sequences | – | – | – |
353
+ | Ubuntu, Windows (GitHub Actions) | 24 | runner | runner | CI | CI | CI | CI | – | CI (Ubuntu) | – |
361
354
 
362
- The last row is the CI workflow: it runs after a push, so its results are on the repository's Actions page, not here.
355
+ The first two rows are runs of 1.2.2 on our machines; both also pass `stopbar probe --target
356
+ examples/bounded-queue.probe.ts --runs 50 --check-mutants` (50/50, mutants 2/2). The macOS row is the CI run of 1.2.1
357
+ (commit `fdd8360`, workflow `ci`, run #2; `.github/workflows/ci.yml`): build, typecheck, `npm test` (unit with the dot
358
+ reporter, so no count in the log) and the same `bounded-queue` probe (50/50, mutants 2/2). The `prove` job of CI runs
359
+ on Ubuntu only. CI runs after a push, so 1.2.2 has no CI run yet.
363
360
 
364
361
  The E2E suite runs every adapter (Cursor, Codex CLI, Gemini CLI, Antigravity CLI) and the git fallback with real
365
362
  git commits and pushes. The probe runs the same 200 seeds plus 2 regressions on both platforms, with the same 5020 steps
@@ -368,8 +365,9 @@ The `--cmd` column is `stopbar probe --cmd "<python> examples/bounded_queue_prob
368
365
  (3970 steps on both platforms). E2E scenario S37 runs `--cmd` with a Node target everywhere, and the Python example
369
366
  and the `--lang py` template only where `python3` or `python` is found.
370
367
  `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 does not change). `node scripts/verify-lean.ts --local`
372
- gives the same result with Lean 4.34.0 on `PATH` (checked in a Debian 13 container with the toolchain of that image).
368
+ `src/kernel.ts`, sha256 `c602fc4bcf8ffb2e...`, which 1.2.0, 1.2.1 and 1.2.2 do not change; 18 theorems in
369
+ `StopbarKernel.lean`, axioms `Classical.choice`, `Quot.sound`, `propext` only). `node scripts/verify-lean.ts --local`
370
+ is the same check with Lean 4.34.0 on `PATH`; CI uses it.
373
371
 
374
372
  ## License
375
373