stopbar 1.1.1 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -0
- package/README.md +36 -13
- package/SECURITY.md +21 -4
- package/dist/attest.js +3 -1
- package/dist/build-info.json +1 -1
- package/dist/cli.js +3 -0
- package/dist/commands.js +18 -7
- package/dist/config.js +45 -3
- package/dist/doctor.js +7 -2
- package/dist/hook.js +21 -7
- package/dist/pkg.js +4 -2
- package/dist/store.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.1.2 (2026-11-26)
|
|
4
|
+
|
|
5
|
+
`src/kernel.ts` is unchanged (sha256 `c602fc4bcf8ffb2e...`); every kernel law holds as in 1.1.1. A `config.json` from
|
|
6
|
+
1.0.0–1.1.1 with two different gate commands works without migration.
|
|
7
|
+
|
|
8
|
+
- **`buildCmd` and `fullTestCmd` must differ.** The classifier matches `buildCmd` first, so with two equal commands
|
|
9
|
+
(after trimming) every run was recorded as a build and the full test gate could never pass. `validateConfig` now
|
|
10
|
+
refuses such a config with a `ConfigError` that says how to fix it; `stopbar init` exits 1 before it writes a file;
|
|
11
|
+
for an existing `config.json` with equal commands the hooks fail closed and `stopbar doctor` reports
|
|
12
|
+
`[FAIL] config.json` with the fix.
|
|
13
|
+
- **Claude Desktop session tools are local.** `DEFAULT_SAFE_TOOLS` is now `["mcp__ccd_turn__*",
|
|
14
|
+
"mcp__ccd_session_mgmt__*"]`, so a message to another local session after a secret read no longer causes a false
|
|
15
|
+
`PAUSE`. Other MCP tools stay outbound. An existing `config.json` keeps its own `safeTools`: add
|
|
16
|
+
`"mcp__ccd_session_mgmt__*"` or run `stopbar init --force ...`; `stopbar doctor` shows a `[WARN] safeTools` while a
|
|
17
|
+
default entry is missing.
|
|
18
|
+
- **`stopbar init --cli "<cmd>"` (`config.cliCmd`).** The hints in the commit refusal, in the block of a background gate
|
|
19
|
+
command (`PreToolUse` and `PostToolUse`) and in the note for a gate run without an exit status (Codex CLI) name
|
|
20
|
+
`<cliCmd> run build|test`. Without `--cli` they name `npx --no-install stopbar run build|test`, which never downloads
|
|
21
|
+
the package from the npm registry (1.1.1 said `npx stopbar`). `cliCmd` must be one command without shell operators
|
|
22
|
+
and must not name `.git` or an agent-settings directory; with `--no-pin`, `init` also refuses a `cliCmd` that points
|
|
23
|
+
at the hook runtime. `<cliCmd> run test` passes the hooks; `<cliCmd> approve-tests`, `approve-shell`, `resume`,
|
|
24
|
+
`reset` and `init` stay blocked.
|
|
25
|
+
- **`stopbar init --stop-gate block|warn` (`config.stopGate`, default `block`).** `warn` changes only the `Stop` hook:
|
|
26
|
+
with uncommitted changes that are not verified (no green build or full tests at the current revision, tainted tests,
|
|
27
|
+
or a halted session) it answers exit 0 with `WARN (stopbar): ...` and logs a `stop:warn` entry (reason, revisions,
|
|
28
|
+
taint, halt) in `events.jsonl`, without a kernel step. `git commit` and `git push` in the agent hooks and in the git
|
|
29
|
+
hooks stay gated by the kernel. All five adapters render this answer without blocking the turn. `status` (text and
|
|
30
|
+
`--json`), `doctor` and `attest` (`config.stopGate` in JSON, a `Stop gate` row in Markdown when `warn`) show the mode.
|
|
31
|
+
- Tests: unit tests for the new config rules and for the non-blocking Stop answer in every adapter; E2E scenarios S31
|
|
32
|
+
(equal gate commands, session tools, `--cli` with a pinned runtime) and S32 (`--stop-gate warn` with the agent hooks,
|
|
33
|
+
the git hooks and every adapter).
|
|
34
|
+
|
|
3
35
|
## 1.1.1 (2026-11-26)
|
|
4
36
|
|
|
5
37
|
- **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
|
|
@@ -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,7 @@ 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. |
|
|
99
103
|
| `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
104
|
| `stopbar git-hook pre-commit\|pre-push` | git | The git fallback gate. Exit 1 aborts the commit or push. |
|
|
101
105
|
| `stopbar run build\|test` | human, agent, CI | Runs the configured gate command and records its real exit status. |
|
|
@@ -128,10 +132,15 @@ private snapshot index and the pinned runtime. They are outside the working tree
|
|
|
128
132
|
"testConfig": ["package.json", "pyproject.toml", ".github/workflows/**"],
|
|
129
133
|
"secrets": [".env*", "*.pem", "**/secrets/**"]
|
|
130
134
|
},
|
|
131
|
-
"safeTools": ["mcp__ccd_turn__*"]
|
|
135
|
+
"safeTools": ["mcp__ccd_turn__*", "mcp__ccd_session_mgmt__*"]
|
|
132
136
|
}
|
|
133
137
|
```
|
|
134
138
|
|
|
139
|
+
`buildCmd` and `fullTestCmd` must be different commands. A command equal to `buildCmd` is always recorded as a build,
|
|
140
|
+
so with two equal commands the full test gate could never pass. `init` refuses such a pair, and a `config.json` that has
|
|
141
|
+
one makes every hook fail closed and `stopbar doctor` report `[FAIL] config.json` with the fix. Use one command for
|
|
142
|
+
lint, types and build and one for the full test suite, for example `--build "npm run build" --test "npm test"`.
|
|
143
|
+
|
|
135
144
|
A pattern without `/` matches the file name anywhere. `**` is a whole path segment. Matching ignores case. Change a
|
|
136
145
|
profile by editing the lists: no code change is necessary.
|
|
137
146
|
|
|
@@ -146,10 +155,24 @@ profile by editing the lists: no code change is necessary.
|
|
|
146
155
|
refine new test files it added on that branch across commits without triggering `testsTainted`, while existing tests
|
|
147
156
|
from `baseRef` and all test-config files remain protected. A configured non-`HEAD` ref that cannot be resolved fails
|
|
148
157
|
closed.
|
|
149
|
-
- **`safeTools`** (optional) lists glob patterns of tool names that are local and never outbound. The default
|
|
150
|
-
`["mcp__ccd_turn__*"]
|
|
151
|
-
|
|
152
|
-
|
|
158
|
+
- **`safeTools`** (optional) lists glob patterns of tool names that are local and never outbound. The default
|
|
159
|
+
(`DEFAULT_SAFE_TOOLS`) is `["mcp__ccd_turn__*", "mcp__ccd_session_mgmt__*"]`: the task-list and turn-summary tools of
|
|
160
|
+
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
|
|
163
|
+
`PAUSE`s on the session tools after a secret read, add `"mcp__ccd_session_mgmt__*"` to `safeTools` or write the file
|
|
164
|
+
again with `stopbar init --force ...`. `stopbar doctor` shows a `[WARN] safeTools` while a default entry is missing.
|
|
165
|
+
- **`cliCmd`** (optional, set via `stopbar init --cli "<cmd>"`) is the command that starts Stopbar in the hints shown to
|
|
166
|
+
the agent (`<cliCmd> run build|test`). Without it the hints say `npx --no-install stopbar`. It must be one command
|
|
167
|
+
without shell operators and must not name a `.git` or agent-settings directory, because the agent's shell may not run
|
|
168
|
+
such a command. With `--no-pin`, `init` also refuses a `--cli` that points at the hook runtime itself. `approve-tests`,
|
|
169
|
+
`approve-shell`, `resume`, `reset` and `init` stay blocked for the agent whatever `cliCmd` is.
|
|
170
|
+
- **`stopGate`** (optional, set via `stopbar init --stop-gate block|warn`, default `block`) controls only the `Stop` hook.
|
|
171
|
+
`block`: the agent cannot declare "done" while the tree differs from `HEAD` and the gates have not passed (exit 2).
|
|
172
|
+
`warn`: for long tasks with one commit at the end, the turn may end with unverified changes (for example to ask the
|
|
173
|
+
human a question); Stopbar logs a `stop:warn` entry in `events.jsonl` and answers `WARN (stopbar): ...` without
|
|
174
|
+
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
|
|
153
176
|
tool call (exit 2) with a message that says how to repair it.
|
|
154
177
|
|
|
155
178
|
## Local use
|
|
@@ -204,8 +227,8 @@ latency. An earlier prototype that loaded the prover in every hook measured p50
|
|
|
204
227
|
|
|
205
228
|
| Platform | Node | git | Unit | E2E | `stopbar probe` | `stopbar prove` | `stopbar doctor` |
|
|
206
229
|
|---|---|---|---|---|---|---|---|
|
|
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 |
|
|
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 |
|
|
209
232
|
|
|
210
233
|
The E2E suite runs every adapter (Cursor, Codex CLI, Gemini CLI, Antigravity CLI) and the git fallback with real
|
|
211
234
|
git commits and pushes. The probe runs the same 200 seeds plus 2 regressions on both platforms, with the same 5007 steps
|
package/SECURITY.md
CHANGED
|
@@ -94,8 +94,11 @@ that tries to defeat it:
|
|
|
94
94
|
ordinary files are not seen. The exfiltration gate works on command text only. In a shell command, a bare token
|
|
95
95
|
that matches only an extension pattern such as `*.key` counts only if that file exists (a field access like
|
|
96
96
|
`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
|
-
|
|
97
|
+
Tools listed in `config.safeTools` (default: Claude Desktop's `mcp__ccd_turn__*` UI tools and its
|
|
98
|
+
`mcp__ccd_session_mgmt__*` tools for messages between local sessions) are not treated as outbound; a human who adds
|
|
99
|
+
a glob there vouches that those tools send nothing out. A message to another local session can carry text the agent
|
|
100
|
+
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
|
|
101
|
+
adds `mcp__ccd_session_mgmt__*` or runs `stopbar init --force ...`.
|
|
99
102
|
4. **Weak new tests and mutable `baseRef`.** A new test file is not suspicious. A mock of the system under test or an
|
|
100
103
|
empty assertion in a new file passes. Hard-coded answers in production code are an ordinary code edit. When
|
|
101
104
|
`config.baseRef` is a mutable local branch name (such as `main`) rather than a commit SHA, an agent with shell access
|
|
@@ -103,7 +106,11 @@ that tries to defeat it:
|
|
|
103
106
|
5. **Ignored files.** Files ignored by `.gitignore` are invisible to the snapshot (for example patches in
|
|
104
107
|
`node_modules`). A change to `.gitignore` itself is suspicious.
|
|
105
108
|
6. **Other commit paths.** Git aliases, `git commit-tree`, `gh pr create` and similar are not detected. The Stop hook
|
|
106
|
-
catches uncommitted work only.
|
|
109
|
+
catches uncommitted work only. With `config.stopGate: "warn"` it does not even block that: the turn ends with a
|
|
110
|
+
`WARN (stopbar)` answer and a `stop:warn` entry in `events.jsonl`. This mode takes no kernel step at Stop and does not
|
|
111
|
+
weaken the commit gate: `git commit` and `git push` in the agent hooks and in the git hooks are judged by the kernel
|
|
112
|
+
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
|
|
113
|
+
unverified work can stay uncommitted in the working tree.
|
|
107
114
|
7. **Concurrency and humans.** A change made between two hook calls (a background job, a human edit) is counted as the
|
|
108
115
|
agent's change at the next hook. With parallel tool calls a change can be attributed to the wrong call.
|
|
109
116
|
8. **Agent configuration.** Settings outside the repository (user settings, managed settings, `--settings`,
|
|
@@ -131,7 +138,17 @@ For a hostile-agent threat model, run the agent in a container or VM: no network
|
|
|
131
138
|
read-write, `.git/stopbar` and `.claude` mounted read-only or owned by another user, and the human commands run outside
|
|
132
139
|
the sandbox. Stopbar's kernel then gives the proven decisions and the sandbox gives the boundary.
|
|
133
140
|
|
|
134
|
-
## Known limits of 1.1.
|
|
141
|
+
## Known limits of 1.1.2
|
|
142
|
+
|
|
143
|
+
- `stopGate: "warn"`: in Cursor, Codex CLI, Gemini CLI and Antigravity CLI the WARN text is not shown to the agent,
|
|
144
|
+
because their Stop protocols have no non-blocking message (a `followup_message`, `decision: "block"` or
|
|
145
|
+
`decision: "continue"` would start another turn). The entry in `events.jsonl` and `stopbar status` show it.
|
|
146
|
+
Claude Code gets the text on stdout with exit 0.
|
|
147
|
+
- `cliCmd` is checked as text: one command, no shell operators, no `.git` or agent-settings directory. Stopbar does not
|
|
148
|
+
check that the command really starts Stopbar; a wrong `cliCmd` gives the agent a hint that does not work, and the
|
|
149
|
+
gates still count only real runs. Self-protection still blocks the human-only commands through `cliCmd`.
|
|
150
|
+
- `buildCmd` and `fullTestCmd` that differ only in whitespace at the ends count as equal and are refused. Two different
|
|
151
|
+
commands that run the same script (for example `npm test` and `npm run test`) are not detected.
|
|
135
152
|
|
|
136
153
|
- Lean: the check needs Docker and a one-time image build with network access. The base image is pinned by digest and
|
|
137
154
|
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/cli.js
CHANGED
|
@@ -11,6 +11,9 @@ 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
|
|
14
17
|
stopbar hook [--adapter auto|claude|cursor|codex|gemini|antigravity]
|
|
15
18
|
the agent hook (JSON on stdin); auto detects the client from the payload
|
|
16
19
|
stopbar git-hook pre-commit|pre-push fallback gate run by git (installed by init --hooks git)
|
package/dist/commands.js
CHANGED
|
@@ -3,12 +3,12 @@
|
|
|
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, makeConfig, PROFILES} from './config.js'
|
|
9
9
|
import {decode, initKernel, kstep, MACHINE, } from './engine.js'
|
|
10
10
|
import {whyBlocked} from './hook.js'
|
|
11
|
-
import {PKG_ROOT} from './pkg.js'
|
|
11
|
+
import {CODE_PARTS, PKG_ROOT} from './pkg.js'
|
|
12
12
|
import {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
|
|
|
@@ -56,11 +56,21 @@ export function init(o ) {
|
|
|
56
56
|
for (const [k, v] of [['--build', buildCmd], ['--test', fullTestCmd]]) {
|
|
57
57
|
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
58
|
}
|
|
59
|
-
if (
|
|
59
|
+
for (const f of ['cli', 'stop-gate']) if (o.has(f) && o.get(f) === undefined) return {code: 1, msg: `--${f} needs a value`}
|
|
60
60
|
let cfg
|
|
61
61
|
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')
|
|
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'),
|
|
63
|
+
cliCmd: o.get('cli'), stopGate: o.get('stop-gate')})
|
|
63
64
|
} catch (e) { if (e instanceof ConfigError) return {code: 1, msg: e.message}; throw e }
|
|
65
|
+
if (existsSync(paths(repo).config) && !o.has('force')) return {code: 1, msg: `already initialised (${paths(repo).config}); use --force to replace config and state`}
|
|
66
|
+
const pin = !o.has('no-pin')
|
|
67
|
+
if (cfg.cliCmd) {
|
|
68
|
+
// the hint `<cli> run test` must pass self-protection with the runtime the hooks will use
|
|
69
|
+
const rt = pin ? join(repo.stateDir, 'runtime') : PKG_ROOT
|
|
70
|
+
const protect = {gitDir: repo.gitDir, stateDir: repo.stateDir, codeDirs: CODE_PARTS.map((n) => join(rt, n))}
|
|
71
|
+
const why = protectedCommand(`${cfg.cliCmd} run test`, protect)
|
|
72
|
+
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`}
|
|
73
|
+
}
|
|
64
74
|
if (cfg.baseRef && !hasRefTree(repo.root, cfg.baseRef)) {
|
|
65
75
|
return {code: 1, msg: `--base-ref ${JSON.stringify(cfg.baseRef)} does not resolve to a commit/tree in ${repo.root}`}
|
|
66
76
|
}
|
|
@@ -70,11 +80,11 @@ export function init(o ) {
|
|
|
70
80
|
return withLock(repo, () => {
|
|
71
81
|
writeConfig(repo, cfg)
|
|
72
82
|
writeState(repo, fresh(repo, cfg))
|
|
73
|
-
const pin = !o.has('no-pin')
|
|
74
83
|
const runtime = pin ? pinRuntime(repo) : PKG_ROOT
|
|
75
84
|
const command = hookCommand(runtime)
|
|
76
85
|
appendEvent(repo, {source: 'human:init', cfg, runtime, version: VERSION, kernel: MACHINE})
|
|
77
86
|
const lines = [`Stopbar ${VERSION} initialised in ${repo.stateDir}`, ` profile ${cfg.profile}; build: ${cfg.buildCmd}; full tests: ${cfg.fullTestCmd}${cfg.baseRef ? `; base ref: ${cfg.baseRef}` : ''}`,
|
|
87
|
+
` stop gate: ${cfg.stopGate ?? 'block'}; gate hints use: ${cliOf(cfg)} run build|test`,
|
|
78
88
|
` hooks run: ${command}`]
|
|
79
89
|
if (targets.length) for (const l of installHooks(repo, targets, runtime, o.has('force-hooks'))) lines.push(` hooks written: ${l}`)
|
|
80
90
|
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))
|
|
@@ -109,6 +119,7 @@ function statusText(repo , cfg , s ) {
|
|
|
109
119
|
`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
120
|
`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
121
|
`commit ${commit}`,
|
|
122
|
+
`stop gate ${cfg.stopGate ?? 'block'}${cfg.stopGate === 'warn' ? ' (Stop only warns; git commit and git push stay blocked until the gates pass)' : ''}`,
|
|
112
123
|
...(torn ? [`event log ${torn} torn line(s) kept as they are (see stopbar doctor)`] : []),
|
|
113
124
|
].join('\n')
|
|
114
125
|
}
|
|
@@ -124,7 +135,7 @@ export function human(cmd , o ) {
|
|
|
124
135
|
}
|
|
125
136
|
const s = readState(repo)
|
|
126
137
|
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),
|
|
138
|
+
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
139
|
secretRead: decode(s.kernel).secretTainted ? secretReason(repo) : null}, null, 1) : statusText(repo, cfg, s)}
|
|
129
140
|
}
|
|
130
141
|
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 {
|
package/dist/hook.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
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
10
|
import {changesSinceHead, countedEntries, diffEntries, differsFromHead, FailClosed, findRepo, gitCalls, inRef, markCounted, snapshot} from './repo.js'
|
|
@@ -31,10 +31,13 @@ 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
|
}
|
|
@@ -125,7 +128,7 @@ function pre(ctx , input ) {
|
|
|
125
128
|
const which = k.kind === 'build' ? 'build' : 'test'
|
|
126
129
|
const gate = k.kind === 'build' ? cfg.buildCmd : cfg.fullTestCmd
|
|
127
130
|
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
|
|
131
|
+
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
132
|
}
|
|
130
133
|
return {code: 0} // the result is recorded in PostToolUse
|
|
131
134
|
}
|
|
@@ -193,7 +196,7 @@ function post(ctx , input , failure ) {
|
|
|
193
196
|
if (k.kind !== 'shell') {
|
|
194
197
|
const which = k.kind === 'build' ? 'build' : 'test'
|
|
195
198
|
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
|
|
199
|
+
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
200
|
}
|
|
198
201
|
} else if (staleRun && (k.kind === 'build' || k.kind === 'fulltest')) {
|
|
199
202
|
const curRev = decode(ctx.s.kernel).treeRev
|
|
@@ -202,7 +205,7 @@ function post(ctx , input , failure ) {
|
|
|
202
205
|
} else if (!failure && unknown && (k.kind === 'build' || k.kind === 'fulltest' || (k.kind === 'shell' && k.partialTests))) {
|
|
203
206
|
// no exit status in the client's post event: neither a pass nor a failure is recorded (no evidence either way)
|
|
204
207
|
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
|
|
208
|
+
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
209
|
} else if (k.kind === 'build') {
|
|
207
210
|
step(ctx, {op: 'RUN_BUILD', passed, cost: cfg.costPerCall}, `post:build${note}`)
|
|
208
211
|
} else if (k.kind === 'fulltest') {
|
|
@@ -222,10 +225,21 @@ function post(ctx , input , failure ) {
|
|
|
222
225
|
}
|
|
223
226
|
|
|
224
227
|
// ---------------------------------------------------------------- Stop: "I am done" = the COMMIT gate when the tree differs from HEAD
|
|
228
|
+
// stopGate 'warn': the turn may end with unverified changes (e.g. to ask the human a question). Only the Stop hook
|
|
229
|
+
// changes: no COMMIT step is taken, so `git commit` / `git push` in PreToolUse and the git hooks stay fully gated.
|
|
225
230
|
function stop(ctx , input ) {
|
|
226
231
|
if (input.stop_hook_active) return {code: 0}
|
|
227
232
|
syncTree(ctx, 0, 'stop:sync')
|
|
228
233
|
if (!differsFromHead(ctx.repo, ctx.now .entries)) return {code: 0}
|
|
234
|
+
if (ctx.cfg.stopGate === 'warn') {
|
|
235
|
+
const v = decode(ctx.s.kernel)
|
|
236
|
+
const commitOk = !v.halted && v.buildOkRev === v.treeRev && v.testsOkRev === v.treeRev && !v.testsTainted
|
|
237
|
+
if (!commitOk) {
|
|
238
|
+
const reason = v.halted ? 'session halted' : whyBlocked(v, ctx.cfg)
|
|
239
|
+
appendEvent(ctx.repo, {source: 'stop:warn', reason, treeRev: v.treeRev, buildOkRev: v.buildOkRev, testsOkRev: v.testsOkRev, testsTainted: v.testsTainted, halted: v.halted})
|
|
240
|
+
return {code: 0, msg: `WARN (stopbar): uncommitted changes are not yet verified (${reason}); commit remains blocked until gates pass.`}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
229
243
|
const {after} = step(ctx, {op: 'COMMIT'}, 'stop:declare-done')
|
|
230
244
|
return after.decision === 'ALLOW' ? {code: 0}
|
|
231
245
|
: {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/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.2",
|
|
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",
|