stopbar 1.1.1 → 1.1.3
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 +68 -0
- package/README.md +46 -18
- package/SECURITY.md +55 -9
- package/dist/attest.js +3 -1
- package/dist/build-info.json +1 -1
- package/dist/classify.js +18 -5
- package/dist/cli.js +8 -1
- package/dist/commands.js +83 -16
- package/dist/config.js +45 -3
- package/dist/doctor.js +8 -3
- package/dist/hook.js +35 -11
- package/dist/pkg.js +4 -2
- package/dist/probe/wrapper.js +36 -7
- package/dist/repo.js +37 -11
- package/dist/store.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,73 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.1.3 (2026-11-26)
|
|
4
|
+
|
|
5
|
+
`src/kernel.ts` is unchanged (sha256 `c602fc4bcf8ffb2e...`); every kernel law holds as in 1.1.2. A `config.json` and a
|
|
6
|
+
`state.json` from 1.0.0–1.1.2 work without migration.
|
|
7
|
+
|
|
8
|
+
- **Security fix (`init --force` and `reset` on a dirty tree):** both start a fresh kernel on the current working tree.
|
|
9
|
+
Before 1.1.3, uncommitted changes of existing tests or of test config vanished with the old state, so a commit after
|
|
10
|
+
green gates needed no `approve-tests`. Now both commands compare the working tree with `baseRef` (else `HEAD`) by the
|
|
11
|
+
same rule as the hooks. When a change is suspicious, they take one kernel step `EDIT_TEST` (`suspicious: true`,
|
|
12
|
+
`cost: 0`), save it in `state.json` and log it in `events.jsonl` (`init:dirty-tests` / `reset:dirty-tests`, with
|
|
13
|
+
`req` and every kernel field, so `stopbar attest` stays consistent). The output starts a `WARN:` line with the files.
|
|
14
|
+
The session then starts with `testsTainted = true` at the next revision (the kernel's first revision is 1, so 2)
|
|
15
|
+
until a human runs `stopbar approve-tests`. On a clean tree nothing changes.
|
|
16
|
+
- **`stopbar upgrade [--hooks <targets>] [--force-hooks]`:** re-pins the hook runtime (`.git/stopbar/runtime`) from the
|
|
17
|
+
installed package and, with `--hooks`, rewrites the hook configuration. It does not touch `state.json`,
|
|
18
|
+
`config.json` or the snapshot indexes: revision, gates, taint and budget stay. It needs a valid `config.json` and
|
|
19
|
+
`state.json` (else it fails closed with the fix), validates `--hooks` before it writes, and logs `human:upgrade`
|
|
20
|
+
(version, runtime, kernel; no `req`, so `attest` stays consistent and lists `upgrade` in `humanActions`). The agent
|
|
21
|
+
cannot run it (self-protection). `stopbar doctor` now names `stopbar upgrade` in `[WARN] pinned runtime`.
|
|
22
|
+
- **No false taint after `checkout` / `rebase` / `cherry-pick` from `baseRef`:** with `--base-ref`, the hooks compare
|
|
23
|
+
the blob id of each changed test and test-config file with `baseRef` (`refEntries`, one `git ls-tree` call, only when
|
|
24
|
+
such a file changed). A file with the same content as in `baseRef` is not suspicious, so tests and `package.json`
|
|
25
|
+
taken over from a newer `main` no longer taint. A test of `baseRef` with other content, or deleted, and a test-config
|
|
26
|
+
file that differs from `baseRef` (also a new one) are suspicious. The file mode is ignored (Windows). The tree
|
|
27
|
+
revision still grows with every change (the gates must run again), and a taint is never cleared by putting a file
|
|
28
|
+
back (law L2.2).
|
|
29
|
+
- **Without `--base-ref` the rule of 1.1.2 stays:** every change of an existing test (in `HEAD`) and of test config is
|
|
30
|
+
suspicious, also when the file equals `HEAD`. The agent's own git commands move `HEAD` (for example
|
|
31
|
+
`git stash && git checkout stash@{0}` in one call), so a content match with `HEAD` is no evidence.
|
|
32
|
+
- `repo.ts`: `changesSinceRef(r, ref, now)` (a non-`HEAD` ref that does not resolve fails closed), `refEntries`,
|
|
33
|
+
`oidOf`; `changesSinceHead`, `inRef` and `inHead` stay as before.
|
|
34
|
+
- Tests: unit tests for the blob-id rule, for `refEntries` / `changesSinceRef` and for blocking `stopbar upgrade`;
|
|
35
|
+
E2E scenarios S33 (`init --force` / `reset` on a dirty tree), S34 (`stopbar upgrade`) and S35 (`checkout`,
|
|
36
|
+
`cherry-pick` and `rebase` with `--base-ref main`, and the `HEAD` rule). The probe model follows both changes; half
|
|
37
|
+
of the seeds now run with a base ref, and a new action puts a file back to its base content.
|
|
38
|
+
|
|
39
|
+
## 1.1.2 (2026-11-26)
|
|
40
|
+
|
|
41
|
+
`src/kernel.ts` is unchanged (sha256 `c602fc4bcf8ffb2e...`); every kernel law holds as in 1.1.1. A `config.json` from
|
|
42
|
+
1.0.0–1.1.1 with two different gate commands works without migration.
|
|
43
|
+
|
|
44
|
+
- **`buildCmd` and `fullTestCmd` must differ.** The classifier matches `buildCmd` first, so with two equal commands
|
|
45
|
+
(after trimming) every run was recorded as a build and the full test gate could never pass. `validateConfig` now
|
|
46
|
+
refuses such a config with a `ConfigError` that says how to fix it; `stopbar init` exits 1 before it writes a file;
|
|
47
|
+
for an existing `config.json` with equal commands the hooks fail closed and `stopbar doctor` reports
|
|
48
|
+
`[FAIL] config.json` with the fix.
|
|
49
|
+
- **Claude Desktop session tools are local.** `DEFAULT_SAFE_TOOLS` is now `["mcp__ccd_turn__*",
|
|
50
|
+
"mcp__ccd_session_mgmt__*"]`, so a message to another local session after a secret read no longer causes a false
|
|
51
|
+
`PAUSE`. Other MCP tools stay outbound. An existing `config.json` keeps its own `safeTools`: add
|
|
52
|
+
`"mcp__ccd_session_mgmt__*"` or run `stopbar init --force ...`; `stopbar doctor` shows a `[WARN] safeTools` while a
|
|
53
|
+
default entry is missing.
|
|
54
|
+
- **`stopbar init --cli "<cmd>"` (`config.cliCmd`).** The hints in the commit refusal, in the block of a background gate
|
|
55
|
+
command (`PreToolUse` and `PostToolUse`) and in the note for a gate run without an exit status (Codex CLI) name
|
|
56
|
+
`<cliCmd> run build|test`. Without `--cli` they name `npx --no-install stopbar run build|test`, which never downloads
|
|
57
|
+
the package from the npm registry (1.1.1 said `npx stopbar`). `cliCmd` must be one command without shell operators
|
|
58
|
+
and must not name `.git` or an agent-settings directory; with `--no-pin`, `init` also refuses a `cliCmd` that points
|
|
59
|
+
at the hook runtime. `<cliCmd> run test` passes the hooks; `<cliCmd> approve-tests`, `approve-shell`, `resume`,
|
|
60
|
+
`reset` and `init` stay blocked.
|
|
61
|
+
- **`stopbar init --stop-gate block|warn` (`config.stopGate`, default `block`).** `warn` changes only the `Stop` hook:
|
|
62
|
+
with uncommitted changes that are not verified (no green build or full tests at the current revision, tainted tests,
|
|
63
|
+
or a halted session) it answers exit 0 with `WARN (stopbar): ...` and logs a `stop:warn` entry (reason, revisions,
|
|
64
|
+
taint, halt) in `events.jsonl`, without a kernel step. `git commit` and `git push` in the agent hooks and in the git
|
|
65
|
+
hooks stay gated by the kernel. All five adapters render this answer without blocking the turn. `status` (text and
|
|
66
|
+
`--json`), `doctor` and `attest` (`config.stopGate` in JSON, a `Stop gate` row in Markdown when `warn`) show the mode.
|
|
67
|
+
- Tests: unit tests for the new config rules and for the non-blocking Stop answer in every adapter; E2E scenarios S31
|
|
68
|
+
(equal gate commands, session tools, `--cli` with a pinned runtime) and S32 (`--stop-gate warn` with the agent hooks,
|
|
69
|
+
the git hooks and every adapter).
|
|
70
|
+
|
|
3
71
|
## 1.1.1 (2026-11-26)
|
|
4
72
|
|
|
5
73
|
- **Security fix (background gate commands):** Claude Code fires `PostToolUse` immediately with `backgroundTaskId` when
|
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ hook payload into one internal event and renders the decision in the client's ow
|
|
|
20
20
|
|---|---|---|---|---|
|
|
21
21
|
| Claude Code | `claude`: `.claude/settings.local.json` (`claude-project`: `.claude/settings.json`) | PreToolUse, PostToolUse, PostToolUseFailure, Stop | exit 2, reason on stderr | live-verified (Claude Code 2.1.326) |
|
|
22
22
|
| Cursor | `cursor`: `.cursor/hooks.json` (`failClosed: true`) | preToolUse, postToolUse, postToolUseFailure, stop (also beforeShellExecution, beforeMCPExecution, beforeReadFile, afterFileEdit, afterShellExecution) | exit 2 and `{"permission": "deny"}`; stop: `followup_message` | spec-tested (Cursor hooks reference) |
|
|
23
|
-
| Codex CLI | `codex`: `.codex/hooks.json` | PreToolUse, PostToolUse, Stop | `hookSpecificOutput.permissionDecision: "deny"`; stop: `decision: "block"` | live-verified (Codex CLI 0.172.0): denied commit and config write, tree changes, Stop. Run the gates as `
|
|
23
|
+
| Codex CLI | `codex`: `.codex/hooks.json` | PreToolUse, PostToolUse, Stop | `hookSpecificOutput.permissionDecision: "deny"`; stop: `decision: "block"` | live-verified (Codex CLI 0.172.0): denied commit and config write, tree changes, Stop. Run the gates as `stopbar run build` / `stopbar run test` (the hint uses `--cli`, default `npx --no-install stopbar`), because Codex reports no exit status to hooks. Codex loads project hooks only in a trusted folder |
|
|
24
24
|
| Gemini CLI | `gemini`: `.gemini/settings.json` | BeforeTool, AfterTool, AfterAgent | exit 2, reason on stderr; AfterAgent: `decision: "block"` | spec-tested (Gemini CLI hooks reference) |
|
|
25
25
|
| Antigravity CLI | `antigravity` (alias `agy`): `.agents/hooks.json` | PreToolUse, PostToolUse, Stop | `{"decision": "deny"}`; stop: `decision: "continue"` | live-verified (Antigravity CLI 1.5.18): denied early commit and config write, build and full tests recorded, honest commit allowed, Stop |
|
|
26
26
|
| Any tool, via git | `git`: `.git/hooks/pre-commit`, `.git/hooks/pre-push` | commit, push | exit 1 aborts git | tested with real git (E2E) |
|
|
@@ -33,7 +33,7 @@ client's published hook schema and the E2E suite runs it with payloads in that s
|
|
|
33
33
|
working. An unknown or damaged payload fails closed (exit 2). The configs written by `init` pass `--adapter` explicitly.
|
|
34
34
|
|
|
35
35
|
**Git fallback.** For a tool without hooks, run the gates through Stopbar so their real exit status counts:
|
|
36
|
-
`
|
|
36
|
+
`stopbar run build` and `stopbar run test`. The git hooks then allow a commit only after both passed at the
|
|
37
37
|
current tree, block it after an unapproved test change, and block a push after a secret read without approval.
|
|
38
38
|
|
|
39
39
|
## Four pillars
|
|
@@ -42,7 +42,7 @@ current tree, block it after an unapproved test change, and block a push after a
|
|
|
42
42
|
|---|---|---|
|
|
43
43
|
| PROVE | `stopbar prove`, `npm run verify:lean` | The inductive proof of the kernel, 10 mutants that must fall with a counterexample, and (release gate) `lake build` of the Lean export in a pinned Lean 4.34.0 container without network. |
|
|
44
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. |
|
|
45
|
+
| 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. |
|
|
46
46
|
| ATTEST | `stopbar attest` | A deterministic attestation of the session: HEAD, tree, gates, human actions and the sha256 of the event log. |
|
|
47
47
|
|
|
48
48
|
## Set up in 3 steps
|
|
@@ -77,9 +77,13 @@ Requirements: Node.js 22.18 or later, git, a git repository.
|
|
|
77
77
|
it finds, and makes a dry run of the real hook pipeline on a scratch repository.
|
|
78
78
|
|
|
79
79
|
The agent must run the gate commands exactly as configured, alone and in the foreground, for example `npm test` and not
|
|
80
|
-
`npm test | tail` or with `run_in_background`. For long-running gates (>10 min), run `
|
|
81
|
-
`
|
|
82
|
-
finishes, and discards the result if the working tree changed in the meantime).
|
|
80
|
+
`npm test | tail` or with `run_in_background`. For long-running gates (>10 min), run `stopbar run build` /
|
|
81
|
+
`stopbar run test` (safe to run in the background: Stopbar records the real exit status only when the process
|
|
82
|
+
finishes, and discards the result if the working tree changed in the meantime). The hints that Stopbar shows the agent
|
|
83
|
+
name this command as `npx --no-install stopbar run build|test`: `--no-install` uses an installed Stopbar and never
|
|
84
|
+
downloads the package from the npm registry. If Stopbar is installed elsewhere (a global install or a checkout outside
|
|
85
|
+
the project), set the command with `stopbar init --cli "<cmd>"`, for example
|
|
86
|
+
`--cli "node /opt/stopbar/bin/stopbar.mjs"`; the hints then say `node /opt/stopbar/bin/stopbar.mjs run test`. Commits must be one command. The quoted
|
|
83
87
|
heredoc form that agents use is allowed:
|
|
84
88
|
|
|
85
89
|
```sh
|
|
@@ -95,7 +99,8 @@ EOF
|
|
|
95
99
|
|
|
96
100
|
| Command | Who | What it does |
|
|
97
101
|
|---|---|---|
|
|
98
|
-
| `stopbar init --build "<cmd>" --test "<cmd>" [--profile p] [--base-ref <ref>] [--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. `--base-ref` sets the git ref used to judge whether a test file already existed (default `HEAD`). |
|
|
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. |
|
|
103
|
+
| `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`. |
|
|
99
104
|
| `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). |
|
|
100
105
|
| `stopbar git-hook pre-commit\|pre-push` | git | The git fallback gate. Exit 1 aborts the commit or push. |
|
|
101
106
|
| `stopbar run build\|test` | human, agent, CI | Runs the configured gate command and records its real exit status. |
|
|
@@ -103,7 +108,7 @@ EOF
|
|
|
103
108
|
| `stopbar approve-tests [--rev N]` | human | You reviewed the changed tests or test config up to revision N (default: the current one). |
|
|
104
109
|
| `stopbar approve-shell` | human | Allows **one** risky or outbound call after a secret read. |
|
|
105
110
|
| `stopbar resume --extra N` | human | Lifts a halt (retry limit or budget) and adds N to the budget. |
|
|
106
|
-
| `stopbar reset` | human | Fresh kernel state. Config and event log stay. Also repairs a damaged `state.json`. |
|
|
111
|
+
| `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. |
|
|
107
112
|
| `stopbar doctor [--json]` | human | Environment, config, state, hooks and a dry run. Exit 1 on a problem. |
|
|
108
113
|
| `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. |
|
|
109
114
|
| `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). |
|
|
@@ -128,10 +133,15 @@ private snapshot index and the pinned runtime. They are outside the working tree
|
|
|
128
133
|
"testConfig": ["package.json", "pyproject.toml", ".github/workflows/**"],
|
|
129
134
|
"secrets": [".env*", "*.pem", "**/secrets/**"]
|
|
130
135
|
},
|
|
131
|
-
"safeTools": ["mcp__ccd_turn__*"]
|
|
136
|
+
"safeTools": ["mcp__ccd_turn__*", "mcp__ccd_session_mgmt__*"]
|
|
132
137
|
}
|
|
133
138
|
```
|
|
134
139
|
|
|
140
|
+
`buildCmd` and `fullTestCmd` must be different commands. A command equal to `buildCmd` is always recorded as a build,
|
|
141
|
+
so with two equal commands the full test gate could never pass. `init` refuses such a pair, and a `config.json` that has
|
|
142
|
+
one makes every hook fail closed and `stopbar doctor` report `[FAIL] config.json` with the fix. Use one command for
|
|
143
|
+
lint, types and build and one for the full test suite, for example `--build "npm run build" --test "npm test"`.
|
|
144
|
+
|
|
135
145
|
A pattern without `/` matches the file name anywhere. `**` is a whole path segment. Matching ignores case. Change a
|
|
136
146
|
profile by editing the lists: no code change is necessary.
|
|
137
147
|
|
|
@@ -145,11 +155,29 @@ profile by editing the lists: no code change is necessary.
|
|
|
145
155
|
file (default: `HEAD`). On a multi-commit feature branch, `--base-ref main` (or a base commit SHA) lets the agent
|
|
146
156
|
refine new test files it added on that branch across commits without triggering `testsTainted`, while existing tests
|
|
147
157
|
from `baseRef` and all test-config files remain protected. A configured non-`HEAD` ref that cannot be resolved fails
|
|
148
|
-
closed.
|
|
149
|
-
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
158
|
+
closed. With `baseRef`, Stopbar compares the content (blob id) of a changed test or test-config file with `baseRef`:
|
|
159
|
+
after `git checkout -b x main`, `git rebase main` or `git cherry-pick`, files that equal `main` do not taint, but the
|
|
160
|
+
tree revision grows and the gates must run again. Any other change of a test from `baseRef` or of test config taints,
|
|
161
|
+
and putting the file back later does not clear the taint. Without `baseRef`, every change of an existing test or of
|
|
162
|
+
test config taints, also when the file equals `HEAD`, because the agent's own git commands can move `HEAD`.
|
|
163
|
+
- **`safeTools`** (optional) lists glob patterns of tool names that are local and never outbound. The default
|
|
164
|
+
(`DEFAULT_SAFE_TOOLS`) is `["mcp__ccd_turn__*", "mcp__ccd_session_mgmt__*"]`: the task-list and turn-summary tools of
|
|
165
|
+
Claude Desktop and its tools for messages between local sessions. It only exempts tools from the outbound gate
|
|
166
|
+
(WebFetch, WebSearch, MCP tools); shell commands, edits and reads are gated as before, and a halted session still
|
|
167
|
+
blocks every tool. A `config.json` written by 1.0.0–1.1.1 keeps its own list and keeps working; to stop false
|
|
168
|
+
`PAUSE`s on the session tools after a secret read, add `"mcp__ccd_session_mgmt__*"` to `safeTools` or write the file
|
|
169
|
+
again with `stopbar init --force ...`. `stopbar doctor` shows a `[WARN] safeTools` while a default entry is missing.
|
|
170
|
+
- **`cliCmd`** (optional, set via `stopbar init --cli "<cmd>"`) is the command that starts Stopbar in the hints shown to
|
|
171
|
+
the agent (`<cliCmd> run build|test`). Without it the hints say `npx --no-install stopbar`. It must be one command
|
|
172
|
+
without shell operators and must not name a `.git` or agent-settings directory, because the agent's shell may not run
|
|
173
|
+
such a command. With `--no-pin`, `init` also refuses a `--cli` that points at the hook runtime itself. `approve-tests`,
|
|
174
|
+
`approve-shell`, `resume`, `reset` and `init` stay blocked for the agent whatever `cliCmd` is.
|
|
175
|
+
- **`stopGate`** (optional, set via `stopbar init --stop-gate block|warn`, default `block`) controls only the `Stop` hook.
|
|
176
|
+
`block`: the agent cannot declare "done" while the tree differs from `HEAD` and the gates have not passed (exit 2).
|
|
177
|
+
`warn`: for long tasks with one commit at the end, the turn may end with unverified changes (for example to ask the
|
|
178
|
+
human a question); Stopbar logs a `stop:warn` entry in `events.jsonl` and answers `WARN (stopbar): ...` without
|
|
179
|
+
blocking. `git commit` and `git push` in the agent hooks and in the git hooks stay fully gated by the kernel.
|
|
180
|
+
`status`, `doctor` and `attest` show the mode. A damaged or empty `config.json` or `state.json` blocks every
|
|
153
181
|
tool call (exit 2) with a message that says how to repair it.
|
|
154
182
|
|
|
155
183
|
## Local use
|
|
@@ -204,12 +232,12 @@ latency. An earlier prototype that loaded the prover in every hook measured p50
|
|
|
204
232
|
|
|
205
233
|
| Platform | Node | git | Unit | E2E | `stopbar probe` | `stopbar prove` | `stopbar doctor` |
|
|
206
234
|
|---|---|---|---|---|---|---|---|
|
|
207
|
-
| Windows 11, Git for Windows | 24.19.0 | 2.56.0 |
|
|
208
|
-
| Linux, Debian 13 (container, no network) | 24.21.0 | 2.47.3 |
|
|
235
|
+
| Windows 11, Git for Windows | 24.19.0 | 2.56.0 | 40/40 | 365/365 | 202/202 sequences | proven, 10/10 mutants | OK |
|
|
236
|
+
| Linux, Debian 13 (container, no network) | 24.21.0 | 2.47.3 | 40/40 | 365/365 | 202/202 sequences | proven, 10/10 mutants | OK |
|
|
209
237
|
|
|
210
238
|
The E2E suite runs every adapter (Cursor, Codex CLI, Gemini CLI, Antigravity CLI) and the git fallback with real
|
|
211
|
-
git commits and pushes. The probe runs the same 200 seeds plus 2 regressions on both platforms, with the same
|
|
212
|
-
and
|
|
239
|
+
git commits and pushes. The probe runs the same 200 seeds plus 2 regressions on both platforms, with the same 5020 steps
|
|
240
|
+
and 7152 hook calls (half of the seeds with a base ref). `stopbar doctor` passes on a fresh repository with all six `--hooks` targets.
|
|
213
241
|
`npm run verify:lean` passes in the Lean 4.34.0 container: `lake build` exit 0, 0 errors, 0 `sorry`.
|
|
214
242
|
|
|
215
243
|
## License
|
package/SECURITY.md
CHANGED
|
@@ -53,9 +53,24 @@ There is no proof for them.
|
|
|
53
53
|
- **Results from the event type.** Claude Code sends `PostToolUseFailure` for a failed command and `PostToolUse`
|
|
54
54
|
without an exit code for a successful one. A user interrupt (`is_interrupt`) does not count as a failure.
|
|
55
55
|
- **Tree changes from content.** A private git index in `.git/stopbar/` gives a content snapshot after every edit and
|
|
56
|
-
every shell call: edits, deletions and new files that are not ignored.
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
every shell call: edits, deletions and new files that are not ignored. Without `config.baseRef`, a change to a test
|
|
57
|
+
file that exists in `HEAD`, or to any test-config file, is suspicious. With `config.baseRef`, the wrapper compares the
|
|
58
|
+
blob id of each changed test and test-config file with `baseRef` (one `git ls-tree`, only when such a file changed):
|
|
59
|
+
a test of `baseRef` with other content or deleted, and a test-config file whose content differs from `baseRef` (also
|
|
60
|
+
a new one), are suspicious; a file equal to `baseRef` is not. The file mode is ignored. A configured non-`HEAD`
|
|
61
|
+
`baseRef` that cannot be resolved fails closed. Every change still raises the tree revision, so the gates must run
|
|
62
|
+
again. The path patterns are in `config.json`.
|
|
63
|
+
- **Fresh state on a dirty tree.** `stopbar init --force` and `stopbar reset` classify the uncommitted changes against
|
|
64
|
+
`baseRef` (else `HEAD`) by the same rule. A suspicious change is one kernel step `EDIT_TEST` (`suspicious: true`,
|
|
65
|
+
`cost: 0`), logged with every kernel field: the session starts tainted until `approve-tests`.
|
|
66
|
+
- **`git cherry-pick` and `git rebase`.** They are ordinary shell commands: Stopbar does not block them before the gates
|
|
67
|
+
and does not treat them as a commit, although they write commits. They change the working tree, so the next hook
|
|
68
|
+
counts a new revision and the build and full test gates must pass again. With `--base-ref`, the blob-id comparison
|
|
69
|
+
finds every change of an existing test of `baseRef` and of test config against `baseRef`, whichever command made it;
|
|
70
|
+
tests taken over unchanged from `baseRef` do not taint. Without `--base-ref`, every change of an existing test taints.
|
|
71
|
+
`git commit`, `git push` (agent hooks and git hooks) and a green `stopbar attest` still need green gates and no
|
|
72
|
+
unapproved taint. A commit that `cherry-pick` or `rebase` writes itself does not pass through the commit gate (see
|
|
73
|
+
"Other commit paths" below); a later `git push` does.
|
|
59
74
|
- **Commits.** `git commit` and `git push` must be one command without operators, also with git global options before
|
|
60
75
|
the subcommand. The one allowed form of command substitution is the quoted heredoc that Claude Code writes:
|
|
61
76
|
`git commit ... -m "$(cat <<'EOF'` … `EOF` `)"`. The delimiter is in single quotes, so bash expands nothing in the
|
|
@@ -94,16 +109,27 @@ that tries to defeat it:
|
|
|
94
109
|
ordinary files are not seen. The exfiltration gate works on command text only. In a shell command, a bare token
|
|
95
110
|
that matches only an extension pattern such as `*.key` counts only if that file exists (a field access like
|
|
96
111
|
`claim.key` is not a file); a command that names a `.key` file which does not exist yet is therefore not a read.
|
|
97
|
-
Tools listed in `config.safeTools` (default: Claude Desktop's `mcp__ccd_turn__*` UI tools
|
|
98
|
-
|
|
112
|
+
Tools listed in `config.safeTools` (default: Claude Desktop's `mcp__ccd_turn__*` UI tools and its
|
|
113
|
+
`mcp__ccd_session_mgmt__*` tools for messages between local sessions) are not treated as outbound; a human who adds
|
|
114
|
+
a glob there vouches that those tools send nothing out. A message to another local session can carry text the agent
|
|
115
|
+
has read; that session runs under its own hooks. A `config.json` from 1.0.0–1.1.1 keeps its old list until a human
|
|
116
|
+
adds `mcp__ccd_session_mgmt__*` or runs `stopbar init --force ...`.
|
|
99
117
|
4. **Weak new tests and mutable `baseRef`.** A new test file is not suspicious. A mock of the system under test or an
|
|
100
118
|
empty assertion in a new file passes. Hard-coded answers in production code are an ordinary code edit. When
|
|
101
119
|
`config.baseRef` is a mutable local branch name (such as `main`) rather than a commit SHA, an agent with shell access
|
|
102
|
-
can move that branch ref; pass a commit hash (`--base-ref <sha>`) if you want an immutable baseline.
|
|
120
|
+
can move that branch ref; pass a commit hash (`--base-ref <sha>`) if you want an immutable baseline. Since 1.1.3 this
|
|
121
|
+
matters more: a test that equals `baseRef` does not taint, so an agent that moves the `baseRef` branch to a commit
|
|
122
|
+
with weakened tests (for example `git branch -f main <commit>` or `git update-ref`) and then checks it out is not
|
|
123
|
+
flagged. Stopbar does not watch the ref itself.
|
|
103
124
|
5. **Ignored files.** Files ignored by `.gitignore` are invisible to the snapshot (for example patches in
|
|
104
125
|
`node_modules`). A change to `.gitignore` itself is suspicious.
|
|
105
|
-
6. **Other commit paths.** Git aliases, `git commit-tree`, `
|
|
106
|
-
|
|
126
|
+
6. **Other commit paths.** Git aliases, `git commit-tree`, `git stash`, `git cherry-pick`, `git rebase`, `gh pr create`
|
|
127
|
+
and similar are not detected as commits. The Stop hook
|
|
128
|
+
catches uncommitted work only. With `config.stopGate: "warn"` it does not even block that: the turn ends with a
|
|
129
|
+
`WARN (stopbar)` answer and a `stop:warn` entry in `events.jsonl`. This mode takes no kernel step at Stop and does not
|
|
130
|
+
weaken the commit gate: `git commit` and `git push` in the agent hooks and in the git hooks are judged by the kernel
|
|
131
|
+
exactly as in `block` mode (laws L1, L2.1 and L3.x). What `warn` gives up is the reminder at the end of a turn, so
|
|
132
|
+
unverified work can stay uncommitted in the working tree.
|
|
107
133
|
7. **Concurrency and humans.** A change made between two hook calls (a background job, a human edit) is counted as the
|
|
108
134
|
agent's change at the next hook. With parallel tool calls a change can be attributed to the wrong call.
|
|
109
135
|
8. **Agent configuration.** Settings outside the repository (user settings, managed settings, `--settings`,
|
|
@@ -131,7 +157,27 @@ For a hostile-agent threat model, run the agent in a container or VM: no network
|
|
|
131
157
|
read-write, `.git/stopbar` and `.claude` mounted read-only or owned by another user, and the human commands run outside
|
|
132
158
|
the sandbox. Stopbar's kernel then gives the proven decisions and the sandbox gives the boundary.
|
|
133
159
|
|
|
134
|
-
## Known limits of 1.1.
|
|
160
|
+
## Known limits of 1.1.3
|
|
161
|
+
|
|
162
|
+
- The blob-id comparison trusts `baseRef`: see point 4 of section 3 (a mutable branch name can be moved by the agent).
|
|
163
|
+
Use a commit SHA as `--base-ref` when the agent must not be able to move the baseline.
|
|
164
|
+
- `init --force` and `reset` count all suspicious uncommitted changes as one kernel step. A test file that changed in
|
|
165
|
+
a branch commit against `baseRef` counts too, even if a human approved it in an earlier session: after `reset` such
|
|
166
|
+
a branch starts tainted until `approve-tests`.
|
|
167
|
+
- `stopbar upgrade` re-pins the runtime from the package that runs the command. It does not check that the package is
|
|
168
|
+
newer, and it does not change `config.json`; new defaults (for example `safeTools`) are only named as a hint.
|
|
169
|
+
|
|
170
|
+
## Known limits of 1.1.2
|
|
171
|
+
|
|
172
|
+
- `stopGate: "warn"`: in Cursor, Codex CLI, Gemini CLI and Antigravity CLI the WARN text is not shown to the agent,
|
|
173
|
+
because their Stop protocols have no non-blocking message (a `followup_message`, `decision: "block"` or
|
|
174
|
+
`decision: "continue"` would start another turn). The entry in `events.jsonl` and `stopbar status` show it.
|
|
175
|
+
Claude Code gets the text on stdout with exit 0.
|
|
176
|
+
- `cliCmd` is checked as text: one command, no shell operators, no `.git` or agent-settings directory. Stopbar does not
|
|
177
|
+
check that the command really starts Stopbar; a wrong `cliCmd` gives the agent a hint that does not work, and the
|
|
178
|
+
gates still count only real runs. Self-protection still blocks the human-only commands through `cliCmd`.
|
|
179
|
+
- `buildCmd` and `fullTestCmd` that differ only in whitespace at the ends count as equal and are refused. Two different
|
|
180
|
+
commands that run the same script (for example `npm test` and `npm run test`) are not detected.
|
|
135
181
|
|
|
136
182
|
- Lean: the check needs Docker and a one-time image build with network access. The base image is pinned by digest and
|
|
137
183
|
the Lean archive by sha256, both recorded at the first build (trust on first use). The Lean export is not
|
package/dist/attest.js
CHANGED
|
@@ -54,7 +54,8 @@ export function attestation(repoDir ) {
|
|
|
54
54
|
stopbar: VERSION,
|
|
55
55
|
kernel: MACHINE,
|
|
56
56
|
repository: {head, headTree, snapshot: s.snapshot, workingTreeSnapshot: now.id, treeRevision: v.treeRev},
|
|
57
|
-
config: {profile: cfg.profile, buildCmd: cfg.buildCmd, fullTestCmd: cfg.fullTestCmd, maxRetries: cfg.maxRetries, cap: cfg.cap, costPerCall: cfg.costPerCall, ...(cfg.baseRef ? {baseRef: cfg.baseRef} : {})
|
|
57
|
+
config: {profile: cfg.profile, buildCmd: cfg.buildCmd, fullTestCmd: cfg.fullTestCmd, maxRetries: cfg.maxRetries, cap: cfg.cap, costPerCall: cfg.costPerCall, ...(cfg.baseRef ? {baseRef: cfg.baseRef} : {}),
|
|
58
|
+
stopGate: cfg.stopGate ?? 'block', ...(cfg.cliCmd ? {cliCmd: cfg.cliCmd} : {})},
|
|
58
59
|
gates: {build: v.buildOkRev === v.treeRev, fullTests: v.testsOkRev === v.treeRev, tainted: v.testsTainted, secretRead: v.secretTainted,
|
|
59
60
|
...(v.secretTainted ? {secretReadBy: secretReason(repo)?.text ?? 'not in the event log'} : {}),
|
|
60
61
|
shellApprovalHeld: v.shellToken, halted: v.halted, commitAllowedNow: commitNow, ...(commitNow ? {} : {why: v.halted ? 'session halted' : whyBlocked(v, cfg)}),
|
|
@@ -77,6 +78,7 @@ export function attestMarkdown(a ) {
|
|
|
77
78
|
`| Stopbar | ${a.stopbar} |`, `| Kernel | ${a.kernel.name}, kernel.ts sha256 \`${a.kernel.kernelSha256}\` |`,
|
|
78
79
|
`| HEAD | \`${a.repository.head ?? '(none)'}\` |`, `| HEAD tree | \`${a.repository.headTree ?? '(none)'}\` |`,
|
|
79
80
|
...(a.config.baseRef ? [`| Base ref | \`${a.config.baseRef}\` |`] : []),
|
|
81
|
+
...(a.config.stopGate === 'warn' ? ['| Stop gate | warn (Stop does not block a turn; git commit and git push stay gated) |'] : []),
|
|
80
82
|
`| Counted snapshot | \`${a.repository.snapshot}\` (revision ${a.repository.treeRevision}) |`,
|
|
81
83
|
`| Build gate | ${yn(g.build)} (\`${a.config.buildCmd}\`) |`, `| Full test gate | ${yn(g.fullTests)} (\`${a.config.fullTestCmd}\`) |`,
|
|
82
84
|
`| Tests tainted | ${yn(g.tainted)} |`, `| Secret read | ${g.secretRead ? `yes: ${g.secretReadBy}` : 'no'} |`, `| Halted | ${yn(g.halted)} |`,
|
package/dist/build-info.json
CHANGED
package/dist/classify.js
CHANGED
|
@@ -163,15 +163,28 @@ export function classifyBash(cmd , cfg
|
|
|
163
163
|
return {kind: 'shell', risky: isRiskyShell(c), partialTests: looksLikeTests(c), secret: secretInCommand(c, cfg.paths, exists)}
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
-
/** Kind of a tree change from a list of (status, path) and a test for "the path exists in
|
|
167
|
-
|
|
166
|
+
/** Kind of a tree change from a list of (status, path) and a test for "the path exists in the reference tree"
|
|
167
|
+
* (baseRef, else HEAD).
|
|
168
|
+
* `sameAsRef` (given with an explicit baseRef): "the file now has the same blob id as in baseRef, or is absent from
|
|
169
|
+
* both". Then a test-config file is suspicious only when its content differs from baseRef, and an existing test only
|
|
170
|
+
* when it differs from baseRef (changed or deleted), so tests taken over unchanged from baseRef (checkout, rebase,
|
|
171
|
+
* cherry-pick) do not taint. Without `sameAsRef` (no baseRef: HEAD, which the agent's own git commands can move),
|
|
172
|
+
* every change of test config and of an existing test is suspicious. */
|
|
173
|
+
export function classifyTreeChange(changes , inHead , paths , sameAsRef ) {
|
|
168
174
|
let anyTest = false, suspicious = false
|
|
169
175
|
const why = []
|
|
170
176
|
for (const {status, path} of changes) {
|
|
171
|
-
if (isTestConfigPath(path, paths)) {
|
|
177
|
+
if (isTestConfigPath(path, paths)) {
|
|
178
|
+
anyTest = true
|
|
179
|
+
if (sameAsRef?.(path)) why.push(`config ${status} ${path} (same as base ref)`)
|
|
180
|
+
else { suspicious = true; why.push(`config ${status} ${path}`) }
|
|
181
|
+
continue
|
|
182
|
+
}
|
|
172
183
|
if (isTestPath(path, paths)) {
|
|
173
184
|
anyTest = true
|
|
174
|
-
if (inHead(path))
|
|
185
|
+
if (!inHead(path)) why.push(`new test ${status} ${path}`)
|
|
186
|
+
else if (sameAsRef?.(path)) why.push(`existing test ${status} ${path} (same as base ref)`)
|
|
187
|
+
else { suspicious = true; why.push(`existing test ${status} ${path}`) }
|
|
175
188
|
}
|
|
176
189
|
}
|
|
177
190
|
return {op: anyTest ? 'EDIT_TEST' : 'EDIT_CODE' , suspicious, why}
|
|
@@ -208,7 +221,7 @@ const SEG = (name ) => new RegExp(String.raw`(^|[^a-z0-9_.\-])${name.repl
|
|
|
208
221
|
const DOT_GIT = SEG('.git')
|
|
209
222
|
const AGENT_DIRS = [[SEG('.claude'), '.claude'], [SEG('.cursor'), '.cursor'], [SEG('.codex'), '.codex'], [SEG('.gemini'), '.gemini'], [SEG('.agents'), '.agents']]
|
|
210
223
|
const HUMAN_ONLY = /\b(approve-tests|approve-shell)\b|\bSTOPBAR_[A-Z_]+/i
|
|
211
|
-
const STOPBAR_ADMIN = /stopbar[^\n]*\b(init|resume|reset|doctor\s+--fix)\b/i
|
|
224
|
+
const STOPBAR_ADMIN = /stopbar[^\n]*\b(init|resume|reset|upgrade|doctor\s+--fix)\b/i
|
|
212
225
|
|
|
213
226
|
/** Command text inspected by self-protection. For a plain single-command `git commit` (chain-free, no substitution),
|
|
214
227
|
* strips the commit message (safe heredoc body or quoted `-m` / `--message` string) because git treats it as data. */
|
package/dist/cli.js
CHANGED
|
@@ -11,6 +11,12 @@ const HELP = `stopbar ${VERSION}: proven gates for coding agents (Claude Code ho
|
|
|
11
11
|
|
|
12
12
|
stopbar init --build "<cmd>" --test "<cmd>" [--profile default|ts|python|strict] [--base-ref <ref>] [--max-retries 3] [--cap 500]
|
|
13
13
|
[--cost 1] [--hooks claude,claude-project,cursor,codex,gemini,antigravity,git] [--no-pin] [--force] [--force-hooks] [--repo <dir>]
|
|
14
|
+
[--cli "<cmd>"] [--stop-gate block|warn]
|
|
15
|
+
--cli: command that starts Stopbar in hints (default: npx --no-install stopbar)
|
|
16
|
+
--stop-gate warn: Stop only warns; git commit and git push stay blocked until the gates pass
|
|
17
|
+
stopbar upgrade [--hooks <targets>] [--force-hooks] [--repo <dir>]
|
|
18
|
+
a human re-pins the hook runtime from this package (and rewrites hooks with --hooks);
|
|
19
|
+
state, gates, taint and budget stay as they are
|
|
14
20
|
stopbar hook [--adapter auto|claude|cursor|codex|gemini|antigravity]
|
|
15
21
|
the agent hook (JSON on stdin); auto detects the client from the payload
|
|
16
22
|
stopbar git-hook pre-commit|pre-push fallback gate run by git (installed by init --hooks git)
|
|
@@ -27,7 +33,7 @@ Four pillars:
|
|
|
27
33
|
(npm run verify:lean checks the Lean export with lake build in Docker)
|
|
28
34
|
PROBE stopbar probe [--target wrapper] [--runs 200] [--seed 1] [--jobs N] [--work dir] [--out dir]
|
|
29
35
|
stateful probing of the hooks against the proven kernel on real git repositories
|
|
30
|
-
GATE init, hook, status, approve-tests, approve-shell, resume, reset, doctor (above)
|
|
36
|
+
GATE init, upgrade, hook, status, approve-tests, approve-shell, resume, reset, doctor (above)
|
|
31
37
|
ATTEST stopbar attest [--format json|md] deterministic attestation: HEAD, tree, gates, human actions, log sha256
|
|
32
38
|
All commands take --repo <dir> (default: the current directory). 'verify' is an alias of 'prove'.`
|
|
33
39
|
|
|
@@ -61,6 +67,7 @@ async function main() {
|
|
|
61
67
|
if (cmd === '--version' || cmd === 'version') return {code: 0, msg: VERSION}
|
|
62
68
|
const o = opts(argv.slice(1))
|
|
63
69
|
if (cmd === 'init') return (await import('./commands.js')).init(o)
|
|
70
|
+
if (cmd === 'upgrade') return (await import('./commands.js')).upgrade(o)
|
|
64
71
|
if (['status', 'approve-tests', 'approve-shell', 'resume', 'reset'].includes(cmd)) return (await import('./commands.js')).human(cmd, o)
|
|
65
72
|
if (cmd === 'doctor') return (await import('./doctor.js')).doctor({repo: o.get('repo'), json: o.has('json')})
|
|
66
73
|
if (cmd === 'prove' || cmd === 'verify') {
|
package/dist/commands.js
CHANGED
|
@@ -1,25 +1,51 @@
|
|
|
1
1
|
// Built from src/commands.ts by scripts/build.ts. Do not edit.
|
|
2
|
-
// Human commands: init, status, approve-tests, approve-shell, resume, reset. The agent cannot run them
|
|
2
|
+
// Human commands: init, upgrade, status, approve-tests, approve-shell, resume, reset. The agent cannot run them
|
|
3
3
|
// through its shell (classify.ts protectedCommand) and cannot edit their files (protectedPath).
|
|
4
4
|
import {cpSync, existsSync, mkdirSync, rmSync} from 'node:fs'
|
|
5
5
|
import {join} from 'node:path'
|
|
6
|
-
import {hasChain} from './classify.js'
|
|
6
|
+
import {hasChain, protectedCommand} from './classify.js'
|
|
7
7
|
import {CLAUDE_POST_MATCHER, claudeHooks, hookCommand, installHooks, parseTargets} from './integrations.js'
|
|
8
|
-
import {
|
|
8
|
+
import {cliOf, ConfigError, DEFAULT_SAFE_TOOLS, makeConfig, PROFILES} from './config.js'
|
|
9
9
|
import {decode, initKernel, kstep, MACHINE, } from './engine.js'
|
|
10
|
-
import {whyBlocked} from './hook.js'
|
|
11
|
-
import {PKG_ROOT} from './pkg.js'
|
|
12
|
-
import {findRepo, forgetSnapshots, hasRefTree, markCounted,
|
|
10
|
+
import {classifyChanges, whyBlocked} from './hook.js'
|
|
11
|
+
import {CODE_PARTS, PKG_ROOT} from './pkg.js'
|
|
12
|
+
import {changesSinceRef, findRepo, forgetSnapshots, hasRefTree, markCounted, snapshot} from './repo.js'
|
|
13
13
|
import {appendEvent, paths, readConfig, readEvents, readState, VERSION, withLock, writeConfig, writeState} from './store.js'
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
function freshWithSnap(r , c ) {
|
|
18
18
|
forgetSnapshots(r)
|
|
19
19
|
const params = {maxRetries: c.maxRetries, cap: c.cap}
|
|
20
20
|
const snap = snapshot(r)
|
|
21
21
|
markCounted(r)
|
|
22
|
-
return {version: 2, kernel: initKernel(params), snapshot: snap.id, params}
|
|
22
|
+
return {s: {version: 2, kernel: initKernel(params), snapshot: snap.id, params}, snap}
|
|
23
|
+
}
|
|
24
|
+
export const fresh = (r , c ) => freshWithSnap(r, c).s
|
|
25
|
+
|
|
26
|
+
/** `init --force` and `reset` start a fresh kernel on the current working tree. Uncommitted changes of existing tests or
|
|
27
|
+
* of test config (against baseRef, else HEAD) must not vanish with the old state: they are counted as one suspicious
|
|
28
|
+
* EDIT_TEST step of the kernel (testsTainted until `stopbar approve-tests`), written to state.json and to events.jsonl
|
|
29
|
+
* with every kernel field, so `stopbar attest` stays consistent.
|
|
30
|
+
* `dirtyTests` only reads (it fails closed on a broken baseRef before anything is written); `countDirtyTests` runs under
|
|
31
|
+
* the lock, after the human:init / human:reset entry. */
|
|
32
|
+
|
|
33
|
+
function dirtyTests(r , cfg , snap ) {
|
|
34
|
+
const ref = cfg.baseRef ?? 'HEAD'
|
|
35
|
+
const cls = classifyChanges(r, cfg, changesSinceRef(r, ref, snap.entries), snap.entries)
|
|
36
|
+
return {ref, suspicious: cls.suspicious, files: cls.why.filter((w) => !w.startsWith('new test') && !w.endsWith('(same as base ref)'))}
|
|
37
|
+
}
|
|
38
|
+
function countDirtyTests(r , s , d , source ) {
|
|
39
|
+
if (!d.suspicious) return []
|
|
40
|
+
const req = {op: 'EDIT_TEST', suspicious: true, cost: 0}
|
|
41
|
+
s.kernel = kstep(s.params, s.kernel, req)
|
|
42
|
+
writeState(r, s)
|
|
43
|
+
const a = decode(s.kernel)
|
|
44
|
+
appendEvent(r, {source, req, decision: a.decision, halted: a.halted, testsTainted: a.testsTainted,
|
|
45
|
+
secretTainted: a.secretTainted, shellToken: a.shellToken, treeRev: a.treeRev, buildOkRev: a.buildOkRev, testsOkRev: a.testsOkRev,
|
|
46
|
+
spent: a.spent, capNow: a.capNow, testFails: a.testFails, buildFails: a.buildFails, commitExecuted: a.commitExecuted, ref: d.ref, changes: d.files})
|
|
47
|
+
return [`WARN: uncommitted test or test-config changes against ${d.ref}: ${d.files.join(', ')}`,
|
|
48
|
+
` the session starts with testsTainted = true (revision ${a.treeRev}); a commit stays blocked until a human reviews them and runs \`stopbar approve-tests\``]
|
|
23
49
|
}
|
|
24
50
|
|
|
25
51
|
function humanStep(r , s , req , source ) {
|
|
@@ -56,11 +82,21 @@ export function init(o ) {
|
|
|
56
82
|
for (const [k, v] of [['--build', buildCmd], ['--test', fullTestCmd]]) {
|
|
57
83
|
if (hasChain(v)) return {code: 1, msg: `${k} ${JSON.stringify(v)} has shell operators; put it in one script (e.g. an npm script) so its exit status is the gate`}
|
|
58
84
|
}
|
|
59
|
-
if (
|
|
85
|
+
for (const f of ['cli', 'stop-gate']) if (o.has(f) && o.get(f) === undefined) return {code: 1, msg: `--${f} needs a value`}
|
|
60
86
|
let cfg
|
|
61
87
|
try {
|
|
62
|
-
cfg = makeConfig({buildCmd, fullTestCmd, profile: o.get('profile'), maxRetries: o.int('max-retries', 3), cap: o.int('cap', 500), costPerCall: o.int('cost', 1), baseRef: o.get('base-ref')
|
|
88
|
+
cfg = makeConfig({buildCmd, fullTestCmd, profile: o.get('profile'), maxRetries: o.int('max-retries', 3), cap: o.int('cap', 500), costPerCall: o.int('cost', 1), baseRef: o.get('base-ref'),
|
|
89
|
+
cliCmd: o.get('cli'), stopGate: o.get('stop-gate')})
|
|
63
90
|
} catch (e) { if (e instanceof ConfigError) return {code: 1, msg: e.message}; throw e }
|
|
91
|
+
if (existsSync(paths(repo).config) && !o.has('force')) return {code: 1, msg: `already initialised (${paths(repo).config}); use --force to replace config and state`}
|
|
92
|
+
const pin = !o.has('no-pin')
|
|
93
|
+
if (cfg.cliCmd) {
|
|
94
|
+
// the hint `<cli> run test` must pass self-protection with the runtime the hooks will use
|
|
95
|
+
const rt = pin ? join(repo.stateDir, 'runtime') : PKG_ROOT
|
|
96
|
+
const protect = {gitDir: repo.gitDir, stateDir: repo.stateDir, codeDirs: CODE_PARTS.map((n) => join(rt, n))}
|
|
97
|
+
const why = protectedCommand(`${cfg.cliCmd} run test`, protect)
|
|
98
|
+
if (why) return {code: 1, msg: `--cli ${JSON.stringify(cfg.cliCmd)}: the agent could not run \`${cfg.cliCmd} run test\` (${why}); point --cli at a Stopbar install outside the hook runtime`}
|
|
99
|
+
}
|
|
64
100
|
if (cfg.baseRef && !hasRefTree(repo.root, cfg.baseRef)) {
|
|
65
101
|
return {code: 1, msg: `--base-ref ${JSON.stringify(cfg.baseRef)} does not resolve to a commit/tree in ${repo.root}`}
|
|
66
102
|
}
|
|
@@ -68,17 +104,44 @@ export function init(o ) {
|
|
|
68
104
|
const targets = hooksOpt === undefined ? [] : parseTargets(hooksOpt) // validated before anything is written
|
|
69
105
|
mkdirSync(repo.stateDir, {recursive: true})
|
|
70
106
|
return withLock(repo, () => {
|
|
107
|
+
const {s, snap} = freshWithSnap(repo, cfg)
|
|
108
|
+
const dirty = dirtyTests(repo, cfg, snap)
|
|
71
109
|
writeConfig(repo, cfg)
|
|
72
|
-
writeState(repo,
|
|
73
|
-
const pin = !o.has('no-pin')
|
|
110
|
+
writeState(repo, s)
|
|
74
111
|
const runtime = pin ? pinRuntime(repo) : PKG_ROOT
|
|
75
112
|
const command = hookCommand(runtime)
|
|
76
113
|
appendEvent(repo, {source: 'human:init', cfg, runtime, version: VERSION, kernel: MACHINE})
|
|
114
|
+
const warn = countDirtyTests(repo, s, dirty, 'init:dirty-tests')
|
|
77
115
|
const lines = [`Stopbar ${VERSION} initialised in ${repo.stateDir}`, ` profile ${cfg.profile}; build: ${cfg.buildCmd}; full tests: ${cfg.fullTestCmd}${cfg.baseRef ? `; base ref: ${cfg.baseRef}` : ''}`,
|
|
116
|
+
` stop gate: ${cfg.stopGate ?? 'block'}; gate hints use: ${cliOf(cfg)} run build|test`,
|
|
78
117
|
` hooks run: ${command}`]
|
|
79
118
|
if (targets.length) for (const l of installHooks(repo, targets, runtime, o.has('force-hooks'))) lines.push(` hooks written: ${l}`)
|
|
80
119
|
else lines.push(' add these hooks to .claude/settings.local.json (or run init again with --hooks claude,cursor,codex,gemini,antigravity,git):', JSON.stringify(hooksConfig(command), null, 2))
|
|
81
|
-
lines.push('Next: restart the agent in this repository and run `stopbar doctor`.')
|
|
120
|
+
lines.push(...warn, 'Next: restart the agent in this repository and run `stopbar doctor`.')
|
|
121
|
+
return {code: 0, msg: lines.join('\n')}
|
|
122
|
+
})
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** `stopbar upgrade`: re-pins the hook runtime (<git-dir>/stopbar/runtime) from this package and, with --hooks, rewrites
|
|
126
|
+
* the hook configuration. state.json, config.json and the snapshots stay as they are (revision, gates, taint, budget), so
|
|
127
|
+
* active sessions keep their green gates. The log entry has no `req`: it is no kernel step and attest stays consistent. */
|
|
128
|
+
export function upgrade(o ) {
|
|
129
|
+
const repo = findRepo(o.get('repo') ?? process.cwd())
|
|
130
|
+
const hooksOpt = o.get('hooks')
|
|
131
|
+
if (o.has('hooks') && hooksOpt === undefined) return {code: 1, msg: '--hooks needs a value'}
|
|
132
|
+
const targets = hooksOpt === undefined ? [] : parseTargets(hooksOpt) // validated before anything is written
|
|
133
|
+
return withLock(repo, () => {
|
|
134
|
+
const cfg = readConfig(repo)
|
|
135
|
+
readState(repo) // a missing or damaged state fails closed here, with the fix
|
|
136
|
+
const had = existsSync(join(repo.stateDir, 'runtime'))
|
|
137
|
+
const runtime = pinRuntime(repo)
|
|
138
|
+
appendEvent(repo, {source: 'human:upgrade', version: VERSION, runtime, kernel: MACHINE, ...(targets.length ? {hooks: targets} : {})})
|
|
139
|
+
const lines = [`Stopbar ${VERSION}: hook runtime re-pinned in ${runtime}`, ' state.json, config.json and the snapshots are unchanged (revision, gates, taint, budget)']
|
|
140
|
+
if (targets.length) for (const l of installHooks(repo, targets, runtime, o.has('force-hooks'))) lines.push(` hooks written: ${l}`)
|
|
141
|
+
else if (!had) lines.push(` there was no pinned runtime (init --no-pin): the hooks still run what they ran; add --hooks <targets> to point them at ${hookCommand(runtime)}`)
|
|
142
|
+
const missing = DEFAULT_SAFE_TOOLS.filter((t) => !(cfg.safeTools ?? DEFAULT_SAFE_TOOLS).includes(t))
|
|
143
|
+
if (missing.length) lines.push(` hint: config.safeTools lacks the default ${missing.join(', ')}; a human adds them to config.json (stopbar doctor shows it)`)
|
|
144
|
+
lines.push('Next: run `stopbar doctor`.')
|
|
82
145
|
return {code: 0, msg: lines.join('\n')}
|
|
83
146
|
})
|
|
84
147
|
}
|
|
@@ -109,6 +172,7 @@ function statusText(repo , cfg , s ) {
|
|
|
109
172
|
`tainted ${yn(v.testsTainted)} secret read ${v.secretTainted ? `yes (${secretReason(repo)?.text ?? 'reason not in the event log'})` : 'no'} shell approval held ${yn(v.shellToken)}`,
|
|
110
173
|
`session ${v.halted ? 'HALTED' : 'running'} spent ${v.spent}/${v.capNow} test failures ${v.testFails}/${s.params.maxRetries} build failures ${v.buildFails}/${s.params.maxRetries}`,
|
|
111
174
|
`commit ${commit}`,
|
|
175
|
+
`stop gate ${cfg.stopGate ?? 'block'}${cfg.stopGate === 'warn' ? ' (Stop only warns; git commit and git push stay blocked until the gates pass)' : ''}`,
|
|
112
176
|
...(torn ? [`event log ${torn} torn line(s) kept as they are (see stopbar doctor)`] : []),
|
|
113
177
|
].join('\n')
|
|
114
178
|
}
|
|
@@ -118,13 +182,16 @@ export function human(cmd , o ) {
|
|
|
118
182
|
const cfg = readConfig(repo)
|
|
119
183
|
return withLock(repo, () => {
|
|
120
184
|
if (cmd === 'reset') {
|
|
121
|
-
|
|
185
|
+
const {s, snap} = freshWithSnap(repo, cfg)
|
|
186
|
+
const dirty = dirtyTests(repo, cfg, snap)
|
|
187
|
+
writeState(repo, s)
|
|
122
188
|
appendEvent(repo, {source: 'human:reset'})
|
|
123
|
-
|
|
189
|
+
const warn = countDirtyTests(repo, s, dirty, 'reset:dirty-tests')
|
|
190
|
+
return {code: 0, msg: ['Stopbar state reset: run the build and the full test suite again before a commit', ...warn].join('\n')}
|
|
124
191
|
}
|
|
125
192
|
const s = readState(repo)
|
|
126
193
|
if (cmd === 'status') {
|
|
127
|
-
return {code: 0, msg: o.has('json') ? JSON.stringify({version: VERSION, repo: repo.root, stateDir: repo.stateDir, config: cfg, snapshot: s.snapshot, params: s.params, kernel: decode(s.kernel),
|
|
194
|
+
return {code: 0, msg: o.has('json') ? JSON.stringify({version: VERSION, repo: repo.root, stateDir: repo.stateDir, config: cfg, stopGate: cfg.stopGate ?? 'block', snapshot: s.snapshot, params: s.params, kernel: decode(s.kernel),
|
|
128
195
|
secretRead: decode(s.kernel).secretTainted ? secretReason(repo) : null}, null, 1) : statusText(repo, cfg, s)}
|
|
129
196
|
}
|
|
130
197
|
let res
|
package/dist/config.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Built from src/config.ts by scripts/build.ts. Do not edit.
|
|
2
2
|
// config.json: gate commands, limits and path patterns. Lives in <git-dir>/stopbar/, out of the agent's reach.
|
|
3
|
+
import {hasChain} from './classify.js'
|
|
3
4
|
import {globToRegExp} from './glob.js'
|
|
4
5
|
|
|
5
6
|
|
|
@@ -16,7 +17,15 @@ import {globToRegExp} from './glob.js'
|
|
|
16
17
|
|
|
17
18
|
|
|
18
19
|
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
19
24
|
|
|
25
|
+
|
|
26
|
+
export const STOP_GATES = ['block', 'warn']
|
|
27
|
+
/** Hint command when config.cliCmd is not set: uses an installed stopbar only, never downloads it from the registry. */
|
|
28
|
+
export const DEFAULT_CLI = 'npx --no-install stopbar'
|
|
20
29
|
|
|
21
30
|
const TEST_COMMON = ['**/tests/**', '**/test/**', '**/__tests__/**']
|
|
22
31
|
const TEST_JS = ['**/*.test.*', '**/*.spec.*', '**/e2e/**']
|
|
@@ -47,8 +56,8 @@ export const PROFILES = {
|
|
|
47
56
|
}
|
|
48
57
|
|
|
49
58
|
export const DEFAULTS = {maxRetries: 3, cap: 500, costPerCall: 1}
|
|
50
|
-
// local
|
|
51
|
-
export const DEFAULT_SAFE_TOOLS = ['mcp__ccd_turn__*']
|
|
59
|
+
// local tools of Claude Desktop: task list and turn summary, and messages between local sessions (no network, no files)
|
|
60
|
+
export const DEFAULT_SAFE_TOOLS = ['mcp__ccd_turn__*', 'mcp__ccd_session_mgmt__*']
|
|
52
61
|
|
|
53
62
|
export class ConfigError extends Error {}
|
|
54
63
|
|
|
@@ -62,6 +71,11 @@ export function validateConfig(c ) {
|
|
|
62
71
|
for (const k of ['buildCmd', 'fullTestCmd'] ) {
|
|
63
72
|
if (typeof o[k] !== 'string' || !(o[k] ).trim()) throw new ConfigError(`config.${k} must be a non-empty string`)
|
|
64
73
|
}
|
|
74
|
+
if ((o.buildCmd ).trim() === (o.fullTestCmd ).trim()) {
|
|
75
|
+
throw new ConfigError(`config.buildCmd and config.fullTestCmd must be different commands (both are ${JSON.stringify((o.buildCmd ).trim())}): ` +
|
|
76
|
+
'a command equal to buildCmd is always recorded as a build, so the full test gate can never pass. Use one command for lint/types/build ' +
|
|
77
|
+
'and another one for the full test suite (e.g. --build "npm run build" --test "npm test")')
|
|
78
|
+
}
|
|
65
79
|
for (const k of ['maxRetries', 'cap', 'costPerCall'] ) {
|
|
66
80
|
if (!isNat(o[k])) throw new ConfigError(`config.${k} must be a safe non-negative integer`)
|
|
67
81
|
}
|
|
@@ -85,23 +99,51 @@ export function validateConfig(c ) {
|
|
|
85
99
|
if (o.baseRef !== undefined) {
|
|
86
100
|
if (typeof o.baseRef !== 'string' || !isSafeRef(o.baseRef)) throw new ConfigError(`config.baseRef must be a valid git ref (no whitespace, ranges or leading '-'), got ${JSON.stringify(o.baseRef)}`)
|
|
87
101
|
}
|
|
102
|
+
if (o.cliCmd !== undefined) {
|
|
103
|
+
const why = typeof o.cliCmd === 'string' ? cliCmdProblem(o.cliCmd) : 'must be a string'
|
|
104
|
+
if (why) throw new ConfigError(`config.cliCmd ${why}, got ${JSON.stringify(o.cliCmd)}`)
|
|
105
|
+
}
|
|
106
|
+
if (o.stopGate !== undefined && !STOP_GATES.includes(o.stopGate )) {
|
|
107
|
+
throw new ConfigError(`config.stopGate must be ${STOP_GATES.map((g) => JSON.stringify(g)).join(' or ')}, got ${JSON.stringify(o.stopGate)}`)
|
|
108
|
+
}
|
|
88
109
|
return o
|
|
89
110
|
}
|
|
90
111
|
|
|
112
|
+
// A path segment such as .git or .claude. Self-protection (classify.ts protectedCommand) blocks every shell command that
|
|
113
|
+
// names one, so a hint `<cliCmd> run test` with such a segment could never run.
|
|
114
|
+
const PROTECTED_SEGMENT = /(^|[^a-z0-9_.\-])\.(git|claude|cursor|codex|gemini|agents)([^a-z0-9_\-]|$)/i
|
|
115
|
+
|
|
116
|
+
/** Why a cliCmd value cannot be used, or null. */
|
|
117
|
+
export function cliCmdProblem(cmd ) {
|
|
118
|
+
const c = cmd.trim()
|
|
119
|
+
if (!c) return 'must be a non-empty command'
|
|
120
|
+
if (hasChain(c)) return 'must be one command without shell operators (;, &&, ||, |, redirections or $(...))'
|
|
121
|
+
const seg = PROTECTED_SEGMENT.exec(c.replace(/\\/g, '/'))
|
|
122
|
+
if (seg) return `must not name a .${seg[2].toLowerCase()} directory (the agent's shell may not run commands that name it; point it at a Stopbar install outside .git and the agent settings directories)`
|
|
123
|
+
return null
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** The command that starts the Stopbar CLI in hints shown to the agent. */
|
|
127
|
+
export const cliOf = (cfg ) => cfg.cliCmd?.trim() || DEFAULT_CLI
|
|
128
|
+
|
|
91
129
|
export function isSafeRef(ref ) {
|
|
92
130
|
return ref.length > 0 && !ref.startsWith('-') && !ref.includes('..') && !ref.endsWith('.') && !ref.endsWith('/') && /^[A-Za-z0-9._/@^~-]+$/.test(ref)
|
|
93
131
|
}
|
|
94
132
|
|
|
95
|
-
export function makeConfig(a
|
|
133
|
+
export function makeConfig(a
|
|
134
|
+
) {
|
|
96
135
|
const profile = a.profile ?? 'default'
|
|
97
136
|
const paths = PROFILES[profile]
|
|
98
137
|
if (!paths) throw new ConfigError(`unknown profile ${JSON.stringify(profile)}; known: ${Object.keys(PROFILES).join(', ')}`)
|
|
99
138
|
const baseRef = a.baseRef?.trim()
|
|
139
|
+
const cliCmd = a.cliCmd?.trim()
|
|
100
140
|
return validateConfig({
|
|
101
141
|
version: 1, profile, buildCmd: a.buildCmd.trim(), fullTestCmd: a.fullTestCmd.trim(),
|
|
102
142
|
maxRetries: a.maxRetries ?? DEFAULTS.maxRetries, cap: a.cap ?? DEFAULTS.cap, costPerCall: a.costPerCall ?? DEFAULTS.costPerCall,
|
|
103
143
|
paths: {tests: [...paths.tests], testConfig: [...paths.testConfig], secrets: [...paths.secrets]},
|
|
104
144
|
safeTools: [...DEFAULT_SAFE_TOOLS],
|
|
105
145
|
...(baseRef && baseRef !== 'HEAD' ? {baseRef} : {}),
|
|
146
|
+
...(cliCmd !== undefined ? {cliCmd} : {}),
|
|
147
|
+
...(a.stopGate !== undefined ? {stopGate: a.stopGate} : {}),
|
|
106
148
|
})
|
|
107
149
|
}
|
package/dist/doctor.js
CHANGED
|
@@ -6,7 +6,7 @@ import {existsSync, mkdirSync, readFileSync, rmSync, writeFileSync} from 'node:f
|
|
|
6
6
|
import {isAbsolute, join} from 'node:path'
|
|
7
7
|
import {hasChain} from './classify.js'
|
|
8
8
|
import {fresh, HOOK_MATCHERS} from './commands.js'
|
|
9
|
-
import {DEFAULT_SAFE_TOOLS, makeConfig} from './config.js'
|
|
9
|
+
import {cliOf, DEFAULT_SAFE_TOOLS, makeConfig} from './config.js'
|
|
10
10
|
import {decode, MACHINE} from './engine.js'
|
|
11
11
|
import {runHook} from './hook.js'
|
|
12
12
|
import {PKG_ROOT} from './pkg.js'
|
|
@@ -157,7 +157,12 @@ export async function doctor(o )
|
|
|
157
157
|
try {
|
|
158
158
|
const cfg = readConfig(repo); cfgOk = true
|
|
159
159
|
add('OK', 'config.json', `profile ${cfg.profile}; build \`${cfg.buildCmd}\`; full tests \`${cfg.fullTestCmd}\`; maxRetries ${cfg.maxRetries}; cap ${cfg.cap}; ` +
|
|
160
|
-
`${cfg.paths.tests.length}/${cfg.paths.testConfig.length}/${cfg.paths.secrets.length} test/config/secret patterns; safeTools ${JSON.stringify(cfg.safeTools ?? DEFAULT_SAFE_TOOLS)}${cfg.baseRef ? `; baseRef ${cfg.baseRef}` : ''}`
|
|
160
|
+
`${cfg.paths.tests.length}/${cfg.paths.testConfig.length}/${cfg.paths.secrets.length} test/config/secret patterns; safeTools ${JSON.stringify(cfg.safeTools ?? DEFAULT_SAFE_TOOLS)}${cfg.baseRef ? `; baseRef ${cfg.baseRef}` : ''}; ` +
|
|
161
|
+
`stopGate ${cfg.stopGate ?? 'block'}; cli ${cliOf(cfg)}`)
|
|
162
|
+
if (cfg.stopGate === 'warn') add('WARN', 'stopGate', 'warn: Stop does not block a turn with unverified changes (logged as stop:warn); git commit and git push stay blocked until the gates pass')
|
|
163
|
+
const safe = cfg.safeTools ?? DEFAULT_SAFE_TOOLS
|
|
164
|
+
const missing = DEFAULT_SAFE_TOOLS.filter((t) => !safe.includes(t))
|
|
165
|
+
if (missing.length) add('WARN', 'safeTools', `missing default ${missing.join(', ')}: these local tools count as outbound after a secret read; add them to config.safeTools or run \`stopbar init --force ...\``)
|
|
161
166
|
if (cfg.baseRef) add(hasRefTree(repo.root, cfg.baseRef) ? 'OK' : 'FAIL', 'baseRef', hasRefTree(repo.root, cfg.baseRef) ? `${cfg.baseRef} resolves to a tree` : `${cfg.baseRef} does not resolve in git (existing-test checks will fail closed)`)
|
|
162
167
|
for (const [k, v] of [['buildCmd', cfg.buildCmd], ['fullTestCmd', cfg.fullTestCmd]]) if (hasChain(v)) add('FAIL', 'config.json', `${k} has shell operators: it can never pass as a gate`)
|
|
163
168
|
try {
|
|
@@ -171,7 +176,7 @@ export async function doctor(o )
|
|
|
171
176
|
const rt = join(repo.stateDir, 'runtime', 'dist', 'kernel.gen.js')
|
|
172
177
|
if (existsSync(rt)) {
|
|
173
178
|
const same = existsSync(join(PKG_ROOT, 'dist', 'kernel.gen.js')) && sha(rt) === sha(join(PKG_ROOT, 'dist', 'kernel.gen.js'))
|
|
174
|
-
add(same ? 'OK' : 'WARN', 'pinned runtime', `${join(repo.stateDir, 'runtime')}${same ? ' (same kernel as this package)' : ' differs from this package: a human runs `stopbar
|
|
179
|
+
add(same ? 'OK' : 'WARN', 'pinned runtime', `${join(repo.stateDir, 'runtime')}${same ? ' (same kernel as this package)' : ' differs from this package: a human runs `stopbar upgrade` to re-pin (state and gates are kept)'}`)
|
|
175
180
|
} else if (cfgOk) add('WARN', 'pinned runtime', 'none: hooks run an unpinned copy (init --no-pin)')
|
|
176
181
|
const others = checkOtherClients(repo, add)
|
|
177
182
|
const claudeHas = ['settings.json', 'settings.local.json'].some((n) => { const h = hooksIn(join(repo .root, '.claude', n)); return h !== null && Object.keys(stopbarCommands(h)).length > 0 })
|
package/dist/hook.js
CHANGED
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
import {existsSync} from 'node:fs'
|
|
5
5
|
import {resolve} from 'node:path'
|
|
6
6
|
import * as K from './classify.js'
|
|
7
|
-
import {
|
|
7
|
+
import {cliOf, DEFAULT_SAFE_TOOLS} from './config.js'
|
|
8
8
|
import {matchAny} from './glob.js'
|
|
9
9
|
import {decode, kstep, } from './engine.js'
|
|
10
|
-
import {changesSinceHead, countedEntries, diffEntries, differsFromHead,
|
|
10
|
+
import {changesSinceHead, countedEntries, diffEntries, differsFromHead, FailClosed, findRepo, gitCalls, markCounted, oidOf, refEntries, snapshot} from './repo.js'
|
|
11
11
|
import {appendEvent, readConfig, readState, withLock, writeState} from './store.js'
|
|
12
12
|
import {codeDirs} from './pkg.js'
|
|
13
13
|
|
|
@@ -31,14 +31,29 @@ function step(ctx , req , source , extra
|
|
|
31
31
|
return {before, after}
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
/** `<cli> run build|test`: the Stopbar command that runs a gate and records its real exit status (config.cliCmd). */
|
|
35
|
+
export const runHint = (cfg , which ) => `${cliOf(cfg)} run ${which}`
|
|
36
|
+
|
|
37
|
+
export function whyBlocked(v , cfg ) {
|
|
35
38
|
const r = []
|
|
36
|
-
if (v.buildOkRev !== v.treeRev) r.push(`no passing build at revision ${v.treeRev} (run \`${cfg.buildCmd}\` exactly, alone, or
|
|
37
|
-
if (v.testsOkRev !== v.treeRev) r.push(`no passing FULL test suite at revision ${v.treeRev} (run \`${cfg.fullTestCmd}\` exactly, alone, or
|
|
39
|
+
if (v.buildOkRev !== v.treeRev) r.push(`no passing build at revision ${v.treeRev} (run \`${cfg.buildCmd}\` exactly, alone, or \`${runHint(cfg, 'build')}\`)`)
|
|
40
|
+
if (v.testsOkRev !== v.treeRev) r.push(`no passing FULL test suite at revision ${v.treeRev} (run \`${cfg.fullTestCmd}\` exactly, alone, or \`${runHint(cfg, 'test')}\`)`)
|
|
38
41
|
if (v.testsTainted) r.push(`existing tests or test config changed: a human must review and run \`stopbar approve-tests --rev ${v.treeRev}\``)
|
|
39
42
|
return r.join('; ') || 'kernel decision'
|
|
40
43
|
}
|
|
41
44
|
|
|
45
|
+
/** Classifies changed paths against the reference tree (baseRef, else HEAD). One git process, and only when a test or
|
|
46
|
+
* (with baseRef) a test-config file changed: a code-only change costs no git process here. With baseRef, a test or
|
|
47
|
+
* test-config file whose blob id equals baseRef's is not suspicious (taken over from baseRef by checkout, rebase or
|
|
48
|
+
* cherry-pick, or put back to it). Shared by the hooks and by `init --force` / `reset` on a dirty tree. */
|
|
49
|
+
export function classifyChanges(repo , cfg , changes , now ) {
|
|
50
|
+
const ref = cfg.baseRef ?? 'HEAD'
|
|
51
|
+
const watched = changes.map((c) => c.path).filter((p) => K.isTestConfigPath(p, cfg.paths) ? !!cfg.baseRef : K.isTestPath(p, cfg.paths))
|
|
52
|
+
const inRef = refEntries(repo.root, ref, watched)
|
|
53
|
+
const same = cfg.baseRef ? (p ) => oidOf(now.get(p)) === oidOf(inRef.get(p)) : undefined
|
|
54
|
+
return K.classifyTreeChange(changes, (p) => inRef.has(p), cfg.paths, same)
|
|
55
|
+
}
|
|
56
|
+
|
|
42
57
|
/** Counts a working-tree change the kernel has not seen yet. */
|
|
43
58
|
function syncTree(ctx , cost , source ) {
|
|
44
59
|
const {repo, s, cfg} = ctx
|
|
@@ -53,9 +68,7 @@ function syncTree(ctx , cost , source ) {
|
|
|
53
68
|
changes = changesSinceHead(repo, snap.entries)
|
|
54
69
|
appendEvent(repo, {source: `${source}:fallback-diff`, note: 'counted snapshot copy missing; diff against HEAD'})
|
|
55
70
|
}
|
|
56
|
-
const
|
|
57
|
-
const existing = testPaths.length ? inRef(repo.root, cfg.baseRef ?? 'HEAD', testPaths) : new Set ()
|
|
58
|
-
const cls = K.classifyTreeChange(changes, (p) => existing.has(p), cfg.paths)
|
|
71
|
+
const cls = classifyChanges(repo, cfg, changes, snap.entries)
|
|
59
72
|
const {before, after} = step(ctx, {op: cls.op, suspicious: cls.suspicious, cost}, `${source}:tree ${cls.why.join(', ') || `${changes.length} file(s)`}`)
|
|
60
73
|
// not executed (halted or over budget): the change stays pending and is counted later
|
|
61
74
|
if (after.treeRev > before.treeRev) { s.snapshot = snap.id; markCounted(repo); ctx.dirty = true }
|
|
@@ -125,7 +138,7 @@ function pre(ctx , input ) {
|
|
|
125
138
|
const which = k.kind === 'build' ? 'build' : 'test'
|
|
126
139
|
const gate = k.kind === 'build' ? cfg.buildCmd : cfg.fullTestCmd
|
|
127
140
|
appendEvent(repo, {source: 'pre', tool, wrapper: 'BLOCK', reason: `background gate command (${k.kind})`})
|
|
128
|
-
return block(`do not run \`${gate}\` in the background (run_in_background): the hook fires before the process finishes, so its exit status is unknown. Run \`${gate}\` in the foreground, or start
|
|
141
|
+
return block(`do not run \`${gate}\` in the background (run_in_background): the hook fires before the process finishes, so its exit status is unknown. Run \`${gate}\` in the foreground, or start \`${runHint(cfg, which)}\` in the background so Stopbar records the real exit status only when it finishes.`)
|
|
129
142
|
}
|
|
130
143
|
return {code: 0} // the result is recorded in PostToolUse
|
|
131
144
|
}
|
|
@@ -193,7 +206,7 @@ function post(ctx , input , failure ) {
|
|
|
193
206
|
if (k.kind !== 'shell') {
|
|
194
207
|
const which = k.kind === 'build' ? 'build' : 'test'
|
|
195
208
|
const gate = k.kind === 'build' ? cfg.buildCmd : cfg.fullTestCmd
|
|
196
|
-
msgs.push(`BLOCK (stopbar): \`${gate}\` was started in the background, so its exit status is not known yet and the run is not recorded. Run \`${gate}\` in the foreground, or start
|
|
209
|
+
msgs.push(`BLOCK (stopbar): \`${gate}\` was started in the background, so its exit status is not known yet and the run is not recorded. Run \`${gate}\` in the foreground, or start \`${runHint(cfg, which)}\` in the background.`)
|
|
197
210
|
}
|
|
198
211
|
} else if (staleRun && (k.kind === 'build' || k.kind === 'fulltest')) {
|
|
199
212
|
const curRev = decode(ctx.s.kernel).treeRev
|
|
@@ -202,7 +215,7 @@ function post(ctx , input , failure ) {
|
|
|
202
215
|
} else if (!failure && unknown && (k.kind === 'build' || k.kind === 'fulltest' || (k.kind === 'shell' && k.partialTests))) {
|
|
203
216
|
// no exit status in the client's post event: neither a pass nor a failure is recorded (no evidence either way)
|
|
204
217
|
appendEvent(repo, {source: 'post:gate-without-exit-code', tool, kind: k.kind})
|
|
205
|
-
if (k.kind !== 'shell') msgs.push(`NOTE (stopbar): this client does not report the exit status of \`${k.kind === 'build' ? cfg.buildCmd : cfg.fullTestCmd}\`, so the run is not recorded. Run
|
|
218
|
+
if (k.kind !== 'shell') msgs.push(`NOTE (stopbar): this client does not report the exit status of \`${k.kind === 'build' ? cfg.buildCmd : cfg.fullTestCmd}\`, so the run is not recorded. Run \`${runHint(cfg, k.kind === 'build' ? 'build' : 'test')}\` instead: it runs the same command and records its real exit status.`)
|
|
206
219
|
} else if (k.kind === 'build') {
|
|
207
220
|
step(ctx, {op: 'RUN_BUILD', passed, cost: cfg.costPerCall}, `post:build${note}`)
|
|
208
221
|
} else if (k.kind === 'fulltest') {
|
|
@@ -222,10 +235,21 @@ function post(ctx , input , failure ) {
|
|
|
222
235
|
}
|
|
223
236
|
|
|
224
237
|
// ---------------------------------------------------------------- Stop: "I am done" = the COMMIT gate when the tree differs from HEAD
|
|
238
|
+
// stopGate 'warn': the turn may end with unverified changes (e.g. to ask the human a question). Only the Stop hook
|
|
239
|
+
// changes: no COMMIT step is taken, so `git commit` / `git push` in PreToolUse and the git hooks stay fully gated.
|
|
225
240
|
function stop(ctx , input ) {
|
|
226
241
|
if (input.stop_hook_active) return {code: 0}
|
|
227
242
|
syncTree(ctx, 0, 'stop:sync')
|
|
228
243
|
if (!differsFromHead(ctx.repo, ctx.now .entries)) return {code: 0}
|
|
244
|
+
if (ctx.cfg.stopGate === 'warn') {
|
|
245
|
+
const v = decode(ctx.s.kernel)
|
|
246
|
+
const commitOk = !v.halted && v.buildOkRev === v.treeRev && v.testsOkRev === v.treeRev && !v.testsTainted
|
|
247
|
+
if (!commitOk) {
|
|
248
|
+
const reason = v.halted ? 'session halted' : whyBlocked(v, ctx.cfg)
|
|
249
|
+
appendEvent(ctx.repo, {source: 'stop:warn', reason, treeRev: v.treeRev, buildOkRev: v.buildOkRev, testsOkRev: v.testsOkRev, testsTainted: v.testsTainted, halted: v.halted})
|
|
250
|
+
return {code: 0, msg: `WARN (stopbar): uncommitted changes are not yet verified (${reason}); commit remains blocked until gates pass.`}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
229
253
|
const {after} = step(ctx, {op: 'COMMIT'}, 'stop:declare-done')
|
|
230
254
|
return after.decision === 'ALLOW' ? {code: 0}
|
|
231
255
|
: {code: 2, msg: `Not done (stopbar): uncommitted changes and ${after.halted ? 'the session is halted' : whyBlocked(after, ctx.cfg)}.`}
|
package/dist/pkg.js
CHANGED
|
@@ -7,7 +7,9 @@ import {fileURLToPath} from 'node:url'
|
|
|
7
7
|
/** Package root: the directory with bin/, dist/ and package.json (dist/pkg.js -> ..). */
|
|
8
8
|
export const PKG_ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..')
|
|
9
9
|
|
|
10
|
+
/** Parts of a Stopbar install that self-protection guards (relative to its root). */
|
|
11
|
+
export const CODE_PARTS = ['bin', 'dist', 'src', 'scripts', 'node_modules', 'package.json', 'package-lock.json']
|
|
12
|
+
|
|
10
13
|
export function codeDirs() {
|
|
11
|
-
|
|
12
|
-
return names.map((n) => join(PKG_ROOT, n)).filter((p) => existsSync(p))
|
|
14
|
+
return CODE_PARTS.map((n) => join(PKG_ROOT, n)).filter((p) => existsSync(p))
|
|
13
15
|
}
|
package/dist/probe/wrapper.js
CHANGED
|
@@ -18,6 +18,7 @@ import {runHook} from '../hook.js'
|
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
|
|
21
|
+
|
|
21
22
|
|
|
22
23
|
|
|
23
24
|
|
|
@@ -36,7 +37,9 @@ import {runHook} from '../hook.js'
|
|
|
36
37
|
|
|
37
38
|
|
|
38
39
|
|
|
39
|
-
|
|
40
|
+
// baseRef: init --base-ref on a branch at the base commit that never moves (HEAD moves with every commit); saved runs
|
|
41
|
+
// without the field run without a base ref, as before 1.1.3
|
|
42
|
+
|
|
40
43
|
|
|
41
44
|
function rng(seed ) { let x = (seed * 2654435761) >>> 0 || 7; return () => { x ^= x << 13; x >>>= 0; x ^= x >>> 17; x ^= x << 5; x >>>= 0; return x / 2 ** 32 } }
|
|
42
45
|
|
|
@@ -56,6 +59,7 @@ function genRun(seed ) {
|
|
|
56
59
|
[6, () => ({t: 'edit', tool: pick(['Write', 'Edit'] ), file: pick([...TESTS, `tests/n${Math.floor(r() * 3)}.test.mjs`, CONFIG]), content: content()})],
|
|
57
60
|
[4, () => ({t: 'shellEdit', file: anyFile(), content: content()})],
|
|
58
61
|
[2, () => ({t: 'shellDelete', file: anyFile()})],
|
|
62
|
+
[3, () => ({t: 'restore', file: r() < 0.7 ? pick([...TESTS, CONFIG]) : anyFile()})],
|
|
59
63
|
[2, () => ({t: 'humanEdit', file: anyFile(), content: content()})],
|
|
60
64
|
[10, () => ({t: 'build', outcome: pick(['pass', 'pass', 'pass', 'fail', 'interrupt', 'interrupted', 'bgPre', 'bgPost'] )})],
|
|
61
65
|
[10, () => ({t: 'fulltest', outcome: pick(['pass', 'pass', 'pass', 'fail', 'fail', 'interrupt', 'interrupted', 'bgPre', 'bgPost'] )})],
|
|
@@ -92,7 +96,8 @@ function genRun(seed ) {
|
|
|
92
96
|
let x = r() * total
|
|
93
97
|
for (const [w, f] of W) { if ((x -= w) < 0) { actions.push(f()); break } }
|
|
94
98
|
}
|
|
95
|
-
|
|
99
|
+
// baseRef from the seed's parity, not from r(): the action sequence of a seed stays what it was before 1.1.3
|
|
100
|
+
return {seed, params: {maxRetries: 1 + Math.floor(r() * 3), cap: 10 + Math.floor(r() * 60), cost: Math.floor(r() * 3), baseRef: seed % 2 === 1}, actions: actions.slice(0, 30)}
|
|
96
101
|
}
|
|
97
102
|
|
|
98
103
|
// ---------------------------------------------------------------- execution against the real wrapper + the model
|
|
@@ -101,7 +106,7 @@ async function execute(run , dir ) {
|
|
|
101
106
|
// the model needs the prover package (gdp-wired); the hooks under test never load it
|
|
102
107
|
const {kernel} = await import('../kernel.js')
|
|
103
108
|
const R = kernel('none'), IT = R.interpreter()
|
|
104
|
-
const {maxRetries, cap, cost} = run.params
|
|
109
|
+
const {maxRetries, cap, cost} = run.params, useBase = run.params.baseRef === true
|
|
105
110
|
const P = R.encodeParams({maxRetries, cap})
|
|
106
111
|
|
|
107
112
|
rmSync(dir, {recursive: true, force: true, maxRetries: 5})
|
|
@@ -114,10 +119,14 @@ async function execute(run , dir ) {
|
|
|
114
119
|
writeFileSync(join(dir, '.gitignore'), '.env\nsecrets/\n'); work.set('.gitignore', '.env\nsecrets/\n')
|
|
115
120
|
writeFileSync(join(dir, '.env'), 'X=1\n')
|
|
116
121
|
g('init', '-q'); g('config', 'core.autocrlf', 'false'); g('add', '-A'); g('commit', '-qm', 'base')
|
|
122
|
+
g('branch', 'probe-base') // the base commit; the base ref of runs with params.baseRef
|
|
117
123
|
const opts = (o ) => ({get: (k ) => o[k], has: (k ) => k in o, int: (k , d ) => (k in o ? Number(o[k]) : d)})
|
|
118
|
-
const ini = C.init(opts({repo: dir, build: 'node build.mjs', test: 'node --test', 'max-retries': String(maxRetries), cap: String(cap), cost: String(cost), 'no-pin': ''}))
|
|
124
|
+
const ini = C.init(opts({repo: dir, build: 'node build.mjs', test: 'node --test', 'max-retries': String(maxRetries), cap: String(cap), cost: String(cost), 'no-pin': '', ...(useBase ? {'base-ref': 'probe-base'} : {})}))
|
|
119
125
|
if (ini.code !== 0) throw new Error(`init failed: ${ini.msg}`)
|
|
120
126
|
|
|
127
|
+
const cov = {}
|
|
128
|
+
const inc = (k ) => { cov[k] = (cov[k] ?? 0) + 1 }
|
|
129
|
+
|
|
121
130
|
// ---- model
|
|
122
131
|
let st = IT.init(P)
|
|
123
132
|
let modelSteps = 0
|
|
@@ -130,6 +139,11 @@ async function execute(run , dir ) {
|
|
|
130
139
|
}
|
|
131
140
|
const same = (a , b ) => a.size === b.size && [...a].every(([k, v]) => b.get(k) === v)
|
|
132
141
|
const isTest = (f ) => f.startsWith('tests/')
|
|
142
|
+
const isCfg = (f ) => f === CONFIG || f === '.gitignore'
|
|
143
|
+
const baseTree = new Map(work) // the tree of the base ref (it never moves in a run)
|
|
144
|
+
// with a base ref: suspicious = test config whose content differs from the base ref, or a test of the base ref whose
|
|
145
|
+
// content differs from it (changed or deleted); a file equal to the base ref is not (checkout, rebase, cherry-pick)
|
|
146
|
+
const differsFromRef = (f , ref ) => (isCfg(f) || (isTest(f) && ref.has(f))) && work.get(f) !== ref.get(f)
|
|
133
147
|
const mSync = (c ) => {
|
|
134
148
|
if (same(work, counted)) return null
|
|
135
149
|
const base = countedCopy ? counted : head
|
|
@@ -138,7 +152,8 @@ async function execute(run , dir ) {
|
|
|
138
152
|
// the counted copy was lost and the tree equals HEAD: the wrapper still sees a new snapshot id with no changes
|
|
139
153
|
}
|
|
140
154
|
const anyTest = changed.some((f) => isTest(f) || f === CONFIG || f === '.gitignore')
|
|
141
|
-
const suspicious = changed.some((f) => f
|
|
155
|
+
const suspicious = useBase ? changed.some((f) => differsFromRef(f, baseTree)) : changed.some((f) => isCfg(f) || (isTest(f) && head.has(f)))
|
|
156
|
+
if (useBase && changed.some((f) => (isCfg(f) || (isTest(f) && baseTree.has(f))) && !differsFromRef(f, baseTree))) inc('sameAsBaseRef')
|
|
142
157
|
const before = view().treeRev
|
|
143
158
|
const after = kstep({op: anyTest ? 'EDIT_TEST' : 'EDIT_CODE', suspicious, cost: c})
|
|
144
159
|
if (after.treeRev > before) { counted = new Map(work); countedCopy = true }
|
|
@@ -154,8 +169,6 @@ async function execute(run , dir ) {
|
|
|
154
169
|
const loggedSteps = () => readFileSync(join(sd, 'events.jsonl'), 'utf8').split('\n').filter((l) => { try { return !!JSON.parse(l).req } catch { return false } }).length
|
|
155
170
|
const initSteps = loggedSteps()
|
|
156
171
|
|
|
157
|
-
const cov = {}
|
|
158
|
-
const inc = (k ) => { cov[k] = (cov[k] ?? 0) + 1 }
|
|
159
172
|
for (let i = 0; i < run.actions.length; i++) {
|
|
160
173
|
const a = run.actions[i]
|
|
161
174
|
const v0 = view()
|
|
@@ -186,6 +199,19 @@ async function execute(run , dir ) {
|
|
|
186
199
|
gotCode = hook('PostToolUse', 'Bash', {command}, okResp)
|
|
187
200
|
break
|
|
188
201
|
}
|
|
202
|
+
case 'restore': {
|
|
203
|
+
const command = `git checkout -q probe-base -- ${a.file}`
|
|
204
|
+
expCode = expectPre()
|
|
205
|
+
if (!halted()) { const v = kstep({op: 'SHELL', risky: false, cost}); if (v.decision === 'PAUSE') expCode = 2 }
|
|
206
|
+
gotCode = hook('PreToolUse', 'Bash', {command})
|
|
207
|
+
if (gotCode !== 0 || expCode !== 0) break
|
|
208
|
+
const was = baseTree.get(a.file)
|
|
209
|
+
if (was !== undefined) put(a.file, was)
|
|
210
|
+
else { rmSync(join(dir, a.file), {force: true}); work.delete(a.file) }
|
|
211
|
+
expCode = postCode(mSync(0))
|
|
212
|
+
gotCode = hook('PostToolUse', 'Bash', {command}, okResp)
|
|
213
|
+
break
|
|
214
|
+
}
|
|
189
215
|
case 'humanEdit': put(a.file, a.content); break
|
|
190
216
|
case 'build': case 'fulltest': {
|
|
191
217
|
const command = a.t === 'build' ? 'node build.mjs' : 'node --test'
|
|
@@ -289,6 +315,9 @@ async function execute(run , dir ) {
|
|
|
289
315
|
if (gotCode !== 2) break
|
|
290
316
|
if (readFileSync(join(sd, 'events.jsonl'), 'utf8') !== logBefore) { gotCode = -1; break } // fail closed writes nothing
|
|
291
317
|
st = IT.init(P); counted = new Map(work); countedCopy = true
|
|
318
|
+
// reset on a dirty tree: test or test-config changes against the base ref (else HEAD) keep the session tainted
|
|
319
|
+
const ref = useBase ? baseTree : head
|
|
320
|
+
if ([...new Set([...ref.keys(), ...work.keys()])].some((f) => differsFromRef(f, ref))) { kstep({op: 'EDIT_TEST', suspicious: true, cost: 0}); inc('resetDirtyTests') }
|
|
292
321
|
expCode = 0; gotCode = C.human('reset', opts({repo: dir})).code
|
|
293
322
|
break
|
|
294
323
|
}
|
package/dist/repo.js
CHANGED
|
@@ -143,19 +143,45 @@ export function diffEntries(a , b )
|
|
|
143
143
|
return out.sort((x, y) => (x.path < y.path ? -1 : x.path > y.path ? 1 : 0))
|
|
144
144
|
}
|
|
145
145
|
|
|
146
|
-
|
|
147
|
-
|
|
146
|
+
const refFailed = (ref ) => new FailClosed(`baseRef ${JSON.stringify(ref)} could not be resolved in git`,
|
|
147
|
+
'a human restores the ref or runs `stopbar init --force ... --base-ref <ref>`')
|
|
148
|
+
|
|
149
|
+
/** `git ls-tree -r` of `ref` as entries (path -> "<mode> <oid>", leading zeros of the mode dropped as in the index).
|
|
150
|
+
* `paths` limits the listing (literal pathspecs); null lists the whole tree. One git process.
|
|
151
|
+
* A ref that does not resolve: HEAD (no commit yet) = empty tree; any other ref fails closed. */
|
|
152
|
+
function lsTree(root , ref , paths ) {
|
|
153
|
+
const out = new Map()
|
|
154
|
+
let raw
|
|
148
155
|
try {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
156
|
+
raw = git(root, ['--literal-pathspecs', '-c', 'core.quotepath=false', 'ls-tree', '-r', '-z', '--full-tree', ref, ...(paths ? ['--', ...paths] : [])])
|
|
157
|
+
} catch {
|
|
158
|
+
if (ref === 'HEAD') return out
|
|
159
|
+
throw refFailed(ref)
|
|
160
|
+
}
|
|
161
|
+
for (const rec of raw.split('\0')) {
|
|
162
|
+
const m = /^(\d+) \w+ ([0-9a-f]+)\t(.*)$/s.exec(rec)
|
|
163
|
+
if (m) out.set(m[3], `${m[1].replace(/^0+/, '')} ${m[2]}`)
|
|
164
|
+
}
|
|
165
|
+
return out
|
|
157
166
|
}
|
|
158
167
|
|
|
168
|
+
/** The entries of `paths` in `ref` (path -> "<mode> <oid>"; a path missing from the map is not in `ref`).
|
|
169
|
+
* One git process, called only when test files or test config changed. Non-HEAD ref that does not resolve: FailClosed. */
|
|
170
|
+
export function refEntries(root , ref , paths ) {
|
|
171
|
+
return paths.length ? lsTree(root, ref, paths) : new Map()
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** The blob id of an entry "<mode> <oid>" (the mode is ignored: on Windows the file mode is not reliable). */
|
|
175
|
+
export const oidOf = (v ) => v?.split(' ')[1]
|
|
176
|
+
|
|
177
|
+
/** The current snapshot against `ref` (one git process). Non-HEAD ref that does not resolve: FailClosed. */
|
|
178
|
+
export function changesSinceRef(r , ref , now ) {
|
|
179
|
+
return diffEntries(lsTree(r.root, ref, null), now)
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** Fallback diff when the counted copy is gone: the current snapshot against HEAD (one git process). */
|
|
183
|
+
export const changesSinceHead = (r , now ) => changesSinceRef(r, 'HEAD', now)
|
|
184
|
+
|
|
159
185
|
/** Does the current private index differ from HEAD? (one git process; no HEAD = differs unless empty) */
|
|
160
186
|
export function differsFromHead(r , now ) {
|
|
161
187
|
try {
|
|
@@ -181,7 +207,7 @@ export function inRef(root , ref , paths ) {
|
|
|
181
207
|
return new Set(out.split('\0').filter(Boolean))
|
|
182
208
|
} catch {
|
|
183
209
|
if (ref === 'HEAD') return new Set()
|
|
184
|
-
throw
|
|
210
|
+
throw refFailed(ref)
|
|
185
211
|
}
|
|
186
212
|
}
|
|
187
213
|
|
package/dist/store.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stopbar",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"description": "A formally proven execution gate for AI coding agents: hooks for Claude Code, Cursor, Codex CLI, Gemini CLI and Antigravity CLI, plus git hooks. No commit without a passing build and full test suite, no silent test weakening, no exfiltration after a secret read.",
|
|
5
5
|
"author": "Paweł Olszewski <kontakt@polszewski.com>",
|
|
6
6
|
"license": "MIT",
|