stopbar 1.1.2 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,185 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.2.0 (2026-11-26)
4
+
5
+ `src/kernel.ts` is unchanged (sha256 `c602fc4bcf8ffb2e...`); every kernel law holds as in 1.1.3. A `config.json` and a
6
+ `state.json` from 1.0.0–1.1.3 work without migration. `stopbar probe --target wrapper` (the default) runs as before.
7
+ This release joins 1.2.0-rc.1 (PROBE for TS/JS) with PROBE for any language and `stopbar probe init`. No new runtime
8
+ dependency: `gdp-wired` 0.60.0 is still the only one.
9
+
10
+ Selftest fixes (8 findings of the 1.2.0 audit, each with a regression test):
11
+
12
+ - **F1 (P1) `git config` with the word `list` or `get` in a value is a write.** Only the words right after `config`
13
+ decide a read: the subcommands `list` and `get <name>`, or `--get`, `--get-all`, `--get-regexp`, `--get-urlmatch`,
14
+ `--list`, `-l` before the arguments, with scope and format flags around them. `git config core.hooksPath list` and
15
+ `git config alias.ci "commit -m list -q"` were taken for reads and are now blocked.
16
+ - **F2 (P1) git global options with a value.** `--attr-source <tree>` (also `=`), `--super-prefix`, `--list-cmds` and
17
+ any other `--opt=value` before the subcommand no longer hide `commit`, `push`, `config` or `-c alias.*`.
18
+ - **F3 (P2) `stopbar probe init` is not blocked.** The human-only check now looks for `init`, `resume`, `reset`,
19
+ `upgrade` and `doctor --fix` right after the `stopbar` program word (`stopbar`, `stopbar.mjs`, `stopbar@<version>`,
20
+ quoted or not). `stopbar init` and `npx stopbar init` stay blocked.
21
+ - **F4 (P2) `stopbar attest` with a long `events.jsonl`.** The last kernel step is found with a loop, not with
22
+ `Math.max(...events)`, which overflowed the stack at about 130 000 lines.
23
+ - **F5, F6 (P2) mixed and word-final quotes.** New `unquoteShellWords`: the text checks also read each word with its
24
+ quote pairs removed, so `'.cl'"aude"`, `.g"i"'t'`, `.e"n"'v'` and `gi"t"` are `.claude`, `.git`, `.env` and `git`
25
+ for self-protection, the secret check and the commit and push classification.
26
+ - **F7 (P2) `stopbar probe` with large `--runs` or `--mutant-runs`.** A worker gets its share in a file
27
+ (`--worker-file <path>` in the work directory, removed when the worker ends) instead of one JSON argument, which
28
+ failed with `spawn ENAMETOOLONG`. `--worker <json>` still works.
29
+ - **F8 (P2) `stopbar status` on an uncounted working tree.** `status` compares the working tree with the counted
30
+ snapshot. After a change that no hook has counted, it says so on the `revision` line and shows `commit blocked:
31
+ uncommitted working-tree changes not yet counted` instead of `allowed`. `status --json` has the new fields
32
+ `workingTreeSnapshot` and `workingTreeCounted`.
33
+ - `skills/stopbar/SKILL.md`: who runs which prober (agrees with SECURITY.md section 4), `--cmd-timeout` under CPU
34
+ load, what to do after the first finding, and when `--no-record` is allowed.
35
+ - Tests: unit tests for F1–F7 (`classify`, `attestation` on 140 000 log lines, `probe()` with 40 000 mutant seeds) and
36
+ E2E scenario S41 (F8).
37
+
38
+ Launch hardening:
39
+
40
+ - **`stopbar probe --cmd` never hangs after a failed kill.** `taskkill` reports a failure (no rights, a sandbox, not on
41
+ `PATH`) by its exit status, not by an exception; Stopbar now checks it and then kills the direct child. The pipes of
42
+ the process are always destroyed and the child is unref'd, also after the grace period of `close()`, so a process that
43
+ survives can no longer keep Stopbar's event loop open.
44
+ - **Git hooks by default.** `init --hooks <clients>` also writes `pre-commit` and `pre-push` (they close git aliases,
45
+ and before a push `merge`, `cherry-pick`, `am` and `commit-tree`). `--no-git-hooks` skips them. A foreign git hook is
46
+ kept with a `WARN` that names `--hooks git --force-hooks`; with `git` named in `--hooks` it is still an error.
47
+ `init` without `--hooks` writes nothing outside `.git/stopbar/`. `stopbar doctor` reports `[WARN] hooks git` while
48
+ one of the two Stopbar git hooks is missing, with the fix `stopbar upgrade --hooks git`.
49
+ - **`git -c alias.<name>=...` is blocked** (also `-calias.`, quoted, `--config-env alias.*` and
50
+ `GIT_CONFIG_KEY_<n>=alias.*`): a one-off alias hid the real git subcommand from the commit and push gates.
51
+ - **Quote splicing.** The secret and self-protection checks also read the command as bash joins the quoted parts of a
52
+ word: `cat .e""nv` is a read of `.env`, `rm -rf .g""it` and `cat .cl''aude/...` are blocked.
53
+ - **`--require-run`** (`config.requireRun`, default `false`): the build and full test gates count only through
54
+ `stopbar run build|test`; the same command from the agent's shell is not recorded and the hook names `stopbar run`
55
+ (`post:require-run` in the log). `status`, `doctor` and `attest` show it.
56
+ - `scripts/*test*` is a test pattern in every profile (new `config.json` files).
57
+ - **`safeTools` while halted** (telemetry): the tools in `config.safeTools` (default `mcp__ccd_turn__*`,
58
+ `mcp__ccd_session_mgmt__*`) pass in `HALT`, so the agent can ask a human for `stopbar resume`. They take no kernel
59
+ step. Read, Edit, Write, Bash, WebFetch and every other MCP tool stay paused.
60
+ - **A single-quoted heredoc as stdin is data** (telemetry): `agy -p - <<'EOF'` … `EOF` whose prompt mentions
61
+ `approve-tests` is no longer blocked as a human-only command. A shell or interpreter on the command line, a pipe, a
62
+ `>`/`>>` redirection, a variable or a command that stores or runs stdin (`xargs`, `at`, `tee`, `stopbar`) keeps the
63
+ full check; `.git`, agent settings and Stopbar code stay protected in the body.
64
+ - **No false `[WARN] kernel link`** (telemetry): `stopbar doctor` finds `gdp-wired` with `import.meta.resolve`, so a
65
+ hoisted install (`npm install stopbar`) is checked. The WARN stays for a copy where it cannot be resolved.
66
+ - `stopbar doctor` reports missing Claude Code hooks also when only the git hooks are present, if the last `init` or
67
+ `upgrade` wrote Claude Code hooks (`human:init` now logs the hook targets).
68
+ - **Typecheck.** `npm run typecheck` (`tsc --noEmit`, strict, over `src/`, `scripts/`, `tests/`, `bench/`) with
69
+ `typescript` 5.9.3 and `@types/node` 24 as devDependencies only. `src/hook.ts` has no `any` left. The build writes
70
+ `dist/*.d.ts` files that point at `src/*.ts` for the typecheck; they are not in the npm package and not in the pinned
71
+ runtime.
72
+ - **CI.** `.github/workflows/ci.yml`: build, typecheck, tests and a PROBE of `examples/bounded-queue.probe.ts` with
73
+ mutants on Ubuntu, Windows and macOS; `npm run prove`; `lake build` with Lean 4.34.0 from elan through the new
74
+ `node scripts/verify-lean.ts --local` (no Docker). The Docker mode is unchanged.
75
+ - README and SECURITY.md say in their first lines what is proven (the kernel) and what is tested (the wrapper), and
76
+ that without an OS sandbox Stopbar is no security boundary against a hostile agent.
77
+ - **Agent skill.** `skills/stopbar/SKILL.md` (Agent Skills format) tells an agent how to work under the gate and how to
78
+ write Zero-FP probes. It is in the npm package (`files`) and linked from the README.
79
+ - Tests: unit tests for the kill fallback (a stuck target with no `taskkill` on `PATH`), `git -c alias.*`, quote
80
+ splicing, the stdin heredoc and the documented limits; E2E scenarios S38 (`safeTools` in `HALT`), S39
81
+ (`--require-run`, `.e""nv`, `.g""it`, `git -c alias.*`, a heredoc prompt) and S40 (git hooks by default, foreign hooks,
82
+ `--no-git-hooks`, `[WARN] hooks git`, kernel link).
83
+
84
+ - **PROBE for any language: `stopbar probe --cmd "<command>"`.** Each worker starts the command once (in a shell) and
85
+ speaks NDJSON with it on stdin/stdout: `{"op":"info"}` (name, description, optional mutants),
86
+ `{"op":"generate","seed":N}` (a run of pure JSON actions) and `{"op":"execute","run":...,"dir":...,"mutant"?}` (an
87
+ `Outcome`). Shrinking, `--regressions` / `--regressions-only`, `--check-mutants` / `--mutant-runs`, `summary.json`,
88
+ `repro-<seed>.json`, `probe:result` and the probe evidence of `attest` work as with `--target <file>`. A reproduction
89
+ names the target by the `name` from `info`; `summary.json`, `repro-<seed>.json`, `probe:result` and `attest` also
90
+ have `targetCmd`. A `--cmd` target replays only the regressions in `--regressions <dir>`.
91
+ - `--target` and `--cmd` together exit 1 with the reason. `--target-file <path>` names the file for `targetSha256`;
92
+ without it, the first word after the interpreter that is an existing file is hashed, else `targetSha256` is `null`.
93
+ - Errors of the external process do not hang a worker: a process that exits, closes stdout, prints a line that is not
94
+ JSON, answers `{"error": ...}` or an answer of the wrong shape, or gives no answer within `--cmd-timeout` ms (default
95
+ 300000) stops the probe with exit 1 and the end of its stderr. At the end Stopbar closes stdin and kills the process
96
+ tree after 2 s.
97
+ - **`stopbar probe init [--lang ts|py] [--name sample] [--out probes] [--force] [--repo <dir>]`:** writes
98
+ `<name>.probe.ts` (`defineModel` from `stopbar/probe`) or `<name>_probe.py` (the NDJSON protocol, Python standard
99
+ library only) with 2 actions, 1 invariant, 2 mutants and the rules for zero false positives, and prints the command
100
+ that runs it. An existing file stays without `--force`; an unknown `--lang` and a `--name` with anything other than
101
+ letters, digits, `-` and `_` (for example `../`) exit 1.
102
+ - Example: `examples/bounded_queue_probe.py`, the Python counterpart of `examples/bounded-queue.probe.ts` (the same
103
+ queue model, invariants and mutants `M1_dropCap` and `M2_lifoInsteadOfFifo`).
104
+ - Tests: unit tests `tests/unit/probe-stdio.test.ts` (the NDJSON client, mutants, chunked shrinking over stdio, a
105
+ process that crashes, closes stdout, prints garbage, hangs or answers with an error, `probe init`); E2E scenario S37
106
+ (`--cmd` with a Node NDJSON target, so it runs without Python: mutants, `probe:result`, `attest` json and md, minimal
107
+ reproduction and replay, `--target` with `--cmd`, a crashing process, `probe init --lang ts|py`; with `python3` or
108
+ `python` on the machine also `examples/bounded_queue_probe.py` and the `--lang py` template).
109
+
110
+ From 1.2.0-rc.1:
111
+
112
+ - **PROBE for any TS/JS project.** `stopbar probe --target <file>` loads a `.ts`, `.mts`, `.js` or `.mjs` file and
113
+ runs its `default` export (or the export `target`) as a probe target. A missing file or an export that is not a
114
+ target exits 1 with the reason. The sha256 of the file goes into the log and into `summary.json` (`targetSha256`).
115
+ A file target replays regressions only from `--regressions <dir>`, never Stopbar's own.
116
+ - **SDK `stopbar/probe`** (`exports["./probe"]`, types from `src/probe/sdk.ts`): `defineModel` (actions with
117
+ `gen(r)` and `run(state, args, check)`, invariants, `setup` / `teardown`, mutants), `createRng` (xorshift32, the
118
+ same numbers on every platform), `MismatchError` and the types `ModelSpec`, `Rng`, `Check`, `ActionSpec`,
119
+ `ProbeTarget`, `ProbeRun`, `Outcome`, `Mismatch`. A failed check or an exception of the code under test is a
120
+ mismatch with the step and the action. The worker does not crash.
121
+ - **`--check-mutants [--mutant-runs 50]`:** the original runs first. If it passes, each mutant runs seeds from
122
+ `--seed` in order until the first failure (`KILLED`, with seed, step, check and action) or `--mutant-runs` seeds
123
+ (`SURVIVED`). Exit 0 only if the original passes and no mutant survives. `summary.json` has
124
+ `mutants: {total, killed, survived, details}`. A target without mutants is refused (exit 1).
125
+ - **Faster shrinking:** after the cut at the failing step, blocks of half, a quarter, ... of the run (at least 2
126
+ steps) go first, then single steps to a fixed point. On a 200-step run with two relevant steps: 25 executions
127
+ instead of 147 (measured by the unit test). The order is fixed, so the minimal run is the same on every platform.
128
+ - **`probe:result` in `events.jsonl`:** in a repository with a valid Stopbar `config.json` and `state.json`, every
129
+ probe run appends one entry under the lock (target, target path and sha256, tree snapshot, runs, regressions,
130
+ passed, failed, steps, ok, mutants, sha256 of `summary.json`). It has no `req`: it is not a kernel step,
131
+ `state.json` is not touched and `attest` stays consistent. `--no-record` skips it. Without Stopbar nothing is
132
+ recorded and the prober works on its own. The test suite's own probe run passes `record: false`.
133
+ - **`stopbar attest`: probe evidence.** JSON `probes: [...]` (the latest `probe:result` per target since the last
134
+ `init` / `reset`, with `atCurrentSnapshot`); Markdown `## Probe evidence` (or `- none`).
135
+ - Smaller fixes in the runner: `summary.json` and other files without a run in a regression directory are skipped;
136
+ when `--regressions` and `--out` are the same directory, the reproductions in it are kept for the replay; a failing
137
+ regression writes its own run as the reproduction; results are sorted by seed; every execution starts in an empty
138
+ directory; the default work directory follows `--repo` (in a repository without Stopbar it is a temporary
139
+ directory, so the prober creates no `.git/stopbar`); the last line of the output names `summary.json`.
140
+ - Example: `examples/bounded-queue.probe.ts` (a FIFO queue with a fixed capacity, mutants `M1_dropCap` and
141
+ `M2_lifoInsteadOfFifo`).
142
+ - Tests: unit tests `tests/unit/probe-sdk.test.ts` (`createRng`, `defineModel`, checks, teardown, mutants, chunked
143
+ `shrink`, `loadTarget`); E2E scenario S36 (file target with mutants, `probe:result`, `attest` before and after an
144
+ edit, minimal reproduction and replay, a surviving mutant, a target without mutants, `--no-record`, a repository
145
+ without Stopbar).
146
+
147
+ ## 1.1.3 (2026-11-26)
148
+
149
+ `src/kernel.ts` is unchanged (sha256 `c602fc4bcf8ffb2e...`); every kernel law holds as in 1.1.2. A `config.json` and a
150
+ `state.json` from 1.0.0–1.1.2 work without migration.
151
+
152
+ - **Security fix (`init --force` and `reset` on a dirty tree):** both start a fresh kernel on the current working tree.
153
+ Before 1.1.3, uncommitted changes of existing tests or of test config vanished with the old state, so a commit after
154
+ green gates needed no `approve-tests`. Now both commands compare the working tree with `baseRef` (else `HEAD`) by the
155
+ same rule as the hooks. When a change is suspicious, they take one kernel step `EDIT_TEST` (`suspicious: true`,
156
+ `cost: 0`), save it in `state.json` and log it in `events.jsonl` (`init:dirty-tests` / `reset:dirty-tests`, with
157
+ `req` and every kernel field, so `stopbar attest` stays consistent). The output starts a `WARN:` line with the files.
158
+ The session then starts with `testsTainted = true` at the next revision (the kernel's first revision is 1, so 2)
159
+ until a human runs `stopbar approve-tests`. On a clean tree nothing changes.
160
+ - **`stopbar upgrade [--hooks <targets>] [--force-hooks]`:** re-pins the hook runtime (`.git/stopbar/runtime`) from the
161
+ installed package and, with `--hooks`, rewrites the hook configuration. It does not touch `state.json`,
162
+ `config.json` or the snapshot indexes: revision, gates, taint and budget stay. It needs a valid `config.json` and
163
+ `state.json` (else it fails closed with the fix), validates `--hooks` before it writes, and logs `human:upgrade`
164
+ (version, runtime, kernel; no `req`, so `attest` stays consistent and lists `upgrade` in `humanActions`). The agent
165
+ cannot run it (self-protection). `stopbar doctor` now names `stopbar upgrade` in `[WARN] pinned runtime`.
166
+ - **No false taint after `checkout` / `rebase` / `cherry-pick` from `baseRef`:** with `--base-ref`, the hooks compare
167
+ the blob id of each changed test and test-config file with `baseRef` (`refEntries`, one `git ls-tree` call, only when
168
+ such a file changed). A file with the same content as in `baseRef` is not suspicious, so tests and `package.json`
169
+ taken over from a newer `main` no longer taint. A test of `baseRef` with other content, or deleted, and a test-config
170
+ file that differs from `baseRef` (also a new one) are suspicious. The file mode is ignored (Windows). The tree
171
+ revision still grows with every change (the gates must run again), and a taint is never cleared by putting a file
172
+ back (law L2.2).
173
+ - **Without `--base-ref` the rule of 1.1.2 stays:** every change of an existing test (in `HEAD`) and of test config is
174
+ suspicious, also when the file equals `HEAD`. The agent's own git commands move `HEAD` (for example
175
+ `git stash && git checkout stash@{0}` in one call), so a content match with `HEAD` is no evidence.
176
+ - `repo.ts`: `changesSinceRef(r, ref, now)` (a non-`HEAD` ref that does not resolve fails closed), `refEntries`,
177
+ `oidOf`; `changesSinceHead`, `inRef` and `inHead` stay as before.
178
+ - Tests: unit tests for the blob-id rule, for `refEntries` / `changesSinceRef` and for blocking `stopbar upgrade`;
179
+ E2E scenarios S33 (`init --force` / `reset` on a dirty tree), S34 (`stopbar upgrade`) and S35 (`checkout`,
180
+ `cherry-pick` and `rebase` with `--base-ref main`, and the `HEAD` rule). The probe model follows both changes; half
181
+ of the seeds now run with a base ref, and a new action puts a file back to its base content.
182
+
3
183
  ## 1.1.2 (2026-11-26)
4
184
 
5
185
  `src/kernel.ts` is unchanged (sha256 `c602fc4bcf8ffb2e...`); every kernel law holds as in 1.1.1. A `config.json` from
package/README.md CHANGED
@@ -1,7 +1,16 @@
1
1
  # Stopbar
2
2
 
3
- Stopbar is a formally proven execution gate for AI coding agents. It runs as the hooks of Claude Code, Cursor, Codex
4
- CLI, Gemini CLI and Antigravity CLI, and as git hooks for any other tool. It stops an agent from:
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.
8
+
9
+ **Without an OS sandbox, Stopbar stops shortcuts and mistakes of an agent; it is not a security boundary against a
10
+ 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
11
+ [SECURITY.md](SECURITY.md) for what is proven, what the wrapper enforces and what needs an OS sandbox.
12
+
13
+ It stops an agent from:
5
14
 
6
15
  - committing without a passing build and a passing **full** test suite at the current revision of the working tree;
7
16
  - weakening existing tests or test configuration without a human approval;
@@ -11,8 +20,7 @@ CLI, Gemini CLI and Antigravity CLI, and as git hooks for any other tool. It sto
11
20
 
12
21
  The decisions come from one rule, `src/kernel.ts`. gdp-wired 0.60.0 proves its laws by induction, and 10 mutants of
13
22
  the rule each fall with a counterexample. Every client goes through the same rule: an adapter translates the client's
14
- hook payload into one internal event and renders the decision in the client's own output format. See
15
- [SECURITY.md](SECURITY.md) for what is proven, what the wrapper enforces and what needs an OS sandbox.
23
+ hook payload into one internal event and renders the decision in the client's own output format.
16
24
 
17
25
  ## Supported agents
18
26
 
@@ -41,9 +49,9 @@ current tree, block it after an unapproved test change, and block a push after a
41
49
  | Pillar | Command | What it gives you |
42
50
  |---|---|---|
43
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. |
44
- | PROBE | `stopbar probe` | Stateful probing: at least 200 random multi-step sequences of hook events, human commands and damaged files on real git repositories, compared step by step with the proven kernel. v1.0 has one target, `wrapper` (Stopbar itself). |
45
- | GATE | `stopbar init`, `hook`, `git-hook`, `run`, `status`, `approve-tests`, `approve-shell`, `resume`, `reset`, `doctor` | The agent hooks, the git fallback and the human commands. |
46
- | ATTEST | `stopbar attest` | A deterministic attestation of the session: HEAD, tree, gates, human actions and the sha256 of the event log. |
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. |
47
55
 
48
56
  ## Set up in 3 steps
49
57
 
@@ -63,9 +71,13 @@ Requirements: Node.js 22.18 or later, git, a git repository.
63
71
 
64
72
  Profiles for the path patterns: `--profile default|ts|python|strict`. `init` copies the runtime to
65
73
  `.git/stopbar/runtime/` and points every hook to it. Existing settings and hooks in those files stay; earlier
66
- Stopbar entries are replaced. `init` does not overwrite a git hook it did not write, unless you pass
67
- `--force-hooks` (the old hook is kept as `<name>.stopbar-backup`). Without `--hooks`, it prints the Claude Code JSON
68
- to paste. A template is in [claude-hooks.example.json](claude-hooks.example.json).
74
+ Stopbar entries are replaced. Since 1.2.0, `--hooks <clients>` also writes the git hooks (`pre-commit`,
75
+ `pre-push`): they close git aliases, and before a push `merge`, `cherry-pick`, `am` and `commit-tree`, which an
76
+ agent hook does not see. Pass `--no-git-hooks` to skip them. `init` does not overwrite a git hook it did not write:
77
+ when the git hooks were added by default, it keeps the foreign hook and prints a `WARN`; when you named `git` in
78
+ `--hooks`, it stops with an error. `--hooks git --force-hooks` replaces it (the old hook is kept as
79
+ `<name>.stopbar-backup`). Without `--hooks`, `init` writes nothing outside `.git/stopbar/` and prints the Claude
80
+ Code JSON to paste. A template is in [claude-hooks.example.json](claude-hooks.example.json).
69
81
 
70
82
  3. **Check** the setup, then restart the agent in the repository:
71
83
 
@@ -99,7 +111,8 @@ EOF
99
111
 
100
112
  | Command | Who | What it does |
101
113
  |---|---|---|
102
- | `stopbar init --build "<cmd>" --test "<cmd>" [--profile p] [--base-ref <ref>] [--cli "<cmd>"] [--stop-gate block\|warn] [--max-retries 3] [--cap 500] [--cost 1] [--hooks <targets>] [--no-pin] [--force] [--force-hooks]` | human | Writes `config.json` and a fresh state, pins the runtime, writes or prints the hooks. Targets: `claude` (`local`), `claude-project` (`project`), `cursor`, `codex`, `gemini`, `antigravity` (`agy`), `git`, comma separated. `--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. |
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. |
115
+ | `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`. |
103
116
  | `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). |
104
117
  | `stopbar git-hook pre-commit\|pre-push` | git | The git fallback gate. Exit 1 aborts the commit or push. |
105
118
  | `stopbar run build\|test` | human, agent, CI | Runs the configured gate command and records its real exit status. |
@@ -107,17 +120,113 @@ EOF
107
120
  | `stopbar approve-tests [--rev N]` | human | You reviewed the changed tests or test config up to revision N (default: the current one). |
108
121
  | `stopbar approve-shell` | human | Allows **one** risky or outbound call after a secret read. |
109
122
  | `stopbar resume --extra N` | human | Lifts a halt (retry limit or budget) and adds N to the budget. |
110
- | `stopbar reset` | human | Fresh kernel state. Config and event log stay. Also repairs a damaged `state.json`. |
123
+ | `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. |
111
124
  | `stopbar doctor [--json]` | human | Environment, config, state, hooks and a dry run. Exit 1 on a problem. |
112
125
  | `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. |
113
- | `stopbar probe [--target wrapper] [--runs 200] [--seed 1] [--jobs N] [--work dir] [--out dir]` | human, CI | PROBE: stateful probing against the proven kernel. A failure is shrunk to a minimal JSON reproduction. Needs the full package (gdp-wired). |
114
- | `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. |
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. |
127
+ | `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
+ | `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`. |
115
129
 
116
130
  All commands take `--repo <dir>`. The agent cannot run the human commands: the hooks block them.
117
131
 
118
132
  State, configuration and the event log are in `<repo>/.git/stopbar/`: `config.json`, `state.json`, `events.jsonl`, the
119
133
  private snapshot index and the pinned runtime. They are outside the working tree, so they never change the tree hash.
120
134
 
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:
208
+
209
+ ```sh
210
+ stopbar probe --cmd "python examples/bounded_queue_probe.py" --runs 200 --check-mutants
211
+ ```
212
+
213
+ ### A starter target: `stopbar probe init`
214
+
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`.
221
+
222
+ ## Agent skill
223
+
224
+ [`skills/stopbar/SKILL.md`](skills/stopbar/SKILL.md) tells an agent how to work under the gate (exact gate commands,
225
+ one-command commits, the human-only commands and when to stop and ask) and how to write a probe with zero false
226
+ positives. It uses the Agent Skills format (`SKILL.md` with `name` and `description`), so Claude Code, Codex CLI,
227
+ Cursor, Gemini CLI and Antigravity CLI can load it; copy the `skills/stopbar/` directory into the skills directory of
228
+ your agent. The npm package includes it.
229
+
121
230
  ## Configuration
122
231
 
123
232
  `config.json` keeps the gate commands, the limits and three lists of glob patterns:
@@ -154,12 +263,17 @@ profile by editing the lists: no code change is necessary.
154
263
  file (default: `HEAD`). On a multi-commit feature branch, `--base-ref main` (or a base commit SHA) lets the agent
155
264
  refine new test files it added on that branch across commits without triggering `testsTainted`, while existing tests
156
265
  from `baseRef` and all test-config files remain protected. A configured non-`HEAD` ref that cannot be resolved fails
157
- closed.
266
+ closed. With `baseRef`, Stopbar compares the content (blob id) of a changed test or test-config file with `baseRef`:
267
+ after `git checkout -b x main`, `git rebase main` or `git cherry-pick`, files that equal `main` do not taint, but the
268
+ tree revision grows and the gates must run again. Any other change of a test from `baseRef` or of test config taints,
269
+ and putting the file back later does not clear the taint. Without `baseRef`, every change of an existing test or of
270
+ test config taints, also when the file equals `HEAD`, because the agent's own git commands can move `HEAD`.
158
271
  - **`safeTools`** (optional) lists glob patterns of tool names that are local and never outbound. The default
159
272
  (`DEFAULT_SAFE_TOOLS`) is `["mcp__ccd_turn__*", "mcp__ccd_session_mgmt__*"]`: the task-list and turn-summary tools of
160
273
  Claude Desktop and its tools for messages between local sessions. It only exempts tools from the outbound gate
161
- (WebFetch, WebSearch, MCP tools); shell commands, edits and reads are gated as before, and a halted session still
162
- blocks every tool. A `config.json` written by 1.0.0–1.1.1 keeps its own list and keeps working; to stop false
274
+ (WebFetch, WebSearch, MCP tools); shell commands, edits and reads are gated as before. Since 1.2.0 these tools also
275
+ 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
163
277
  `PAUSE`s on the session tools after a secret read, add `"mcp__ccd_session_mgmt__*"` to `safeTools` or write the file
164
278
  again with `stopbar init --force ...`. `stopbar doctor` shows a `[WARN] safeTools` while a default entry is missing.
165
279
  - **`cliCmd`** (optional, set via `stopbar init --cli "<cmd>"`) is the command that starts Stopbar in the hints shown to
@@ -172,13 +286,22 @@ profile by editing the lists: no code change is necessary.
172
286
  `warn`: for long tasks with one commit at the end, the turn may end with unverified changes (for example to ask the
173
287
  human a question); Stopbar logs a `stop:warn` entry in `events.jsonl` and answers `WARN (stopbar): ...` without
174
288
  blocking. `git commit` and `git push` in the agent hooks and in the git hooks stay fully gated by the kernel.
175
- `status`, `doctor` and `attest` show the mode. A damaged or empty `config.json` or `state.json` blocks every
176
- tool call (exit 2) with a message that says how to repair it.
289
+ `status`, `doctor` and `attest` show the mode.
290
+ - **`requireRun`** (optional, set via `stopbar init --require-run`, default `false`): the build and full test gates
291
+ count only when they run through `stopbar run build` or `stopbar run test`. The same command run from the agent's own
292
+ shell is not recorded (neither a pass nor a failure); the hook answers with a `NOTE` that names `stopbar run` and logs
293
+ `post:require-run`. `status`, `doctor` and `attest` show `requireRun: true` when it is on.
294
+
295
+ A damaged or empty `config.json` or `state.json` blocks every tool call (exit 2) with a message that says how to
296
+ repair it.
177
297
 
178
298
  ## Local use
179
299
 
180
300
  - `npm run build` builds `dist/` from `src/` with Node's own type stripping and generates `dist/kernel.gen.js` from
181
- the kernel with gdp-wired's `compileJs`. There is no TypeScript compiler and no bundler.
301
+ the kernel with gdp-wired's `compileJs`. There is no bundler, and the build needs no TypeScript compiler.
302
+ - `npm run typecheck` runs `tsc --noEmit` (TypeScript is a devDependency only) over `src/`, `scripts/`, `tests/` and
303
+ `bench/` in strict mode. The build writes small `dist/*.d.ts` files that point the tests' `dist/*.js` imports at
304
+ `src/*.ts`; they are not in the npm package and not in the pinned runtime.
182
305
  - `npm test` runs the unit tests, the E2E suite (real git repositories, a separate hook process for each call) and the
183
306
  stateful fuzzer (200 random sequences of 20–30 steps, compared with the proven kernel). It takes about 3 minutes.
184
307
  In Claude Code, give the Bash tool enough time, for example `"env": {"BASH_DEFAULT_TIMEOUT_MS": "600000"}` in the
@@ -187,13 +310,18 @@ tool call (exit 2) with a message that says how to repair it.
187
310
  - `npm run verify:lean` exports the Lean project (`leanProject()` of gdp-wired) and runs `lake build` in the
188
311
  container from `docker/lean.Dockerfile` with `--network none`. It is the release gate for changes of `src/kernel.ts`,
189
312
  not part of `npm test`. Build the image once (this needs the network):
190
- `docker build -f docker/lean.Dockerfile -t stopbar-lean:4.34.0 docker`.
313
+ `docker build -f docker/lean.Dockerfile -t stopbar-lean:4.34.0 docker`. Without Docker, with Lean 4.34.0 on `PATH`
314
+ (for example from elan): `npm run build` and `node scripts/verify-lean.ts --local`. Both write
315
+ `results/lean/lean-verify.json`.
191
316
  - `npm run bench` measures the hook latency.
192
317
  - `npm run test:e2e` or `npm run test:fuzz` runs only the E2E suite or only the stateful prober.
193
318
 
194
319
  ## Use in CI
195
320
 
196
- Prove the kernel and run the tests on every change of Stopbar itself:
321
+ Stopbar's own workflow, [.github/workflows/ci.yml](.github/workflows/ci.yml), runs on every push to `main` and every
322
+ pull request: build, typecheck, the full test suite and a PROBE of `examples/bounded-queue.probe.ts` with mutants on
323
+ Ubuntu, Windows and macOS (Node 24); `npm run prove`; and `lake build` of the Lean export with Lean 4.34.0 from elan
324
+ (`node scripts/verify-lean.ts --local`). The minimum for a fork:
197
325
 
198
326
  ```yaml
199
327
  - run: npm ci
@@ -225,15 +353,23 @@ latency. An earlier prototype that loaded the prover in every hook measured p50
225
353
 
226
354
  ## Tested platforms
227
355
 
228
- | Platform | Node | git | Unit | E2E | `stopbar probe` | `stopbar prove` | `stopbar doctor` |
229
- |---|---|---|---|---|---|---|---|
230
- | Windows 11, Git for Windows | 24.19.0 | 2.56.0 | 38/38 | 305/305 | 202/202 sequences | proven, 10/10 mutants | OK |
231
- | Linux, Debian 13 (container, no network) | 24.21.0 | 2.47.3 | 38/38 | 305/305 | 202/202 sequences | proven, 10/10 mutants | OK |
356
+ | Platform | Node | git | Python | Typecheck | Unit | E2E | `stopbar probe` | `--cmd` Python example | `stopbar prove` | `stopbar doctor` |
357
+ |---|---|---|---|---|---|---|---|---|---|---|
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) | – |
361
+
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.
232
363
 
233
364
  The E2E suite runs every adapter (Cursor, Codex CLI, Gemini CLI, Antigravity CLI) and the git fallback with real
234
- git commits and pushes. The probe runs the same 200 seeds plus 2 regressions on both platforms, with the same 5007 steps
235
- and 7176 hook calls. `stopbar doctor` passes on a fresh repository with all six `--hooks` targets.
236
- `npm run verify:lean` passes in the Lean 4.34.0 container: `lake build` exit 0, 0 errors, 0 `sorry`.
365
+ git commits and pushes. The probe runs the same 200 seeds plus 2 regressions on both platforms, with the same 5020 steps
366
+ and 7152 hook calls (half of the seeds with a base ref). `stopbar doctor` passes on a fresh repository with all six `--hooks` targets.
367
+ The `--cmd` column is `stopbar probe --cmd "<python> examples/bounded_queue_probe.py" --runs 200 --check-mutants`
368
+ (3970 steps on both platforms). E2E scenario S37 runs `--cmd` with a Node target everywhere, and the Python example
369
+ and the `--lang py` template only where `python3` or `python` is found.
370
+ `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).
237
373
 
238
374
  ## License
239
375