stopbar 1.1.2 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +180 -0
- package/README.md +165 -29
- package/SECURITY.md +115 -13
- package/dist/attest.js +28 -3
- package/dist/build-info.json +2 -2
- package/dist/classify.js +201 -25
- package/dist/cli.js +44 -8
- package/dist/commands.js +96 -22
- package/dist/config.js +7 -2
- package/dist/doctor.js +19 -9
- package/dist/hook.js +73 -36
- package/dist/integrations.js +14 -5
- package/dist/probe/index.js +247 -57
- package/dist/probe/init.js +217 -0
- package/dist/probe/sdk.js +242 -0
- package/dist/probe/stdio.js +207 -0
- package/dist/probe/wrapper.js +36 -7
- package/dist/repo.js +37 -11
- package/dist/store.js +1 -1
- package/package.json +17 -2
- package/skills/stopbar/SKILL.md +126 -0
- package/src/probe/sdk.ts +241 -0
package/dist/cli.js
CHANGED
|
@@ -11,9 +11,15 @@ 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]
|
|
14
|
+
[--cli "<cmd>"] [--stop-gate block|warn] [--require-run] [--no-git-hooks]
|
|
15
|
+
--hooks <clients> adds the git hooks (pre-commit, pre-push) unless --no-git-hooks;
|
|
16
|
+
a foreign git hook is kept with a warning (replace it: --hooks git --force-hooks)
|
|
15
17
|
--cli: command that starts Stopbar in hints (default: npx --no-install stopbar)
|
|
16
18
|
--stop-gate warn: Stop only warns; git commit and git push stay blocked until the gates pass
|
|
19
|
+
--require-run: build and full test gates count only through stopbar run build|test
|
|
20
|
+
stopbar upgrade [--hooks <targets>] [--force-hooks] [--repo <dir>]
|
|
21
|
+
a human re-pins the hook runtime from this package (and rewrites hooks with --hooks);
|
|
22
|
+
state, gates, taint and budget stay as they are
|
|
17
23
|
stopbar hook [--adapter auto|claude|cursor|codex|gemini|antigravity]
|
|
18
24
|
the agent hook (JSON on stdin); auto detects the client from the payload
|
|
19
25
|
stopbar git-hook pre-commit|pre-push fallback gate run by git (installed by init --hooks git)
|
|
@@ -28,10 +34,25 @@ const HELP = `stopbar ${VERSION}: proven gates for coding agents (Claude Code ho
|
|
|
28
34
|
Four pillars:
|
|
29
35
|
PROVE stopbar prove [--out f.json] [--lean f.lean] inductive proof of the kernel and the 10 mutants
|
|
30
36
|
(npm run verify:lean checks the Lean export with lake build in Docker)
|
|
31
|
-
PROBE stopbar probe [--target wrapper
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
37
|
+
PROBE stopbar probe [--target wrapper|<file> | --cmd "<command>" [--target-file <path>] [--cmd-timeout 300000]]
|
|
38
|
+
[--runs 200] [--seed 1] [--jobs N] [--work dir] [--out dir] [--regressions dir]
|
|
39
|
+
[--regressions-only] [--check-mutants] [--mutant-runs 50] [--no-record]
|
|
40
|
+
stateful probing: --target wrapper (default) checks the hooks against the proven kernel on real git
|
|
41
|
+
repositories; --target <file.ts|.mts|.js|.mjs> runs a model of any TS/JS project (defineModel from
|
|
42
|
+
'stopbar/probe', export default or export target). A failure is shrunk to repro-<seed>.json in --out.
|
|
43
|
+
--cmd: a program in any language (Python, Go, Rust, ...), one process per job, NDJSON on stdin/stdout:
|
|
44
|
+
{"op":"info"} -> {"name","description","mutants"?} {"op":"generate","seed":N} -> {"seed":N,"actions":[...]}
|
|
45
|
+
{"op":"execute","run":{...},"dir":"...","mutant"?} -> {"ok":true,"steps","cov"} | {"ok":false,"mismatch":{...}}
|
|
46
|
+
--target-file: the file hashed as targetSha256 (default: the first existing file in the command)
|
|
47
|
+
--cmd-timeout: ms to wait for one answer (0 = no limit); a crash or bad answer exits 1 with its stderr
|
|
48
|
+
--check-mutants: every mutant of the target must fail within --mutant-runs seeds (exit 0 only if all do)
|
|
49
|
+
--no-record: do not append probe:result to events.jsonl (else recorded when Stopbar is initialised)
|
|
50
|
+
stopbar probe init [--lang ts|py] [--name sample] [--out probes] [--force] [--repo <dir>]
|
|
51
|
+
writes a starter target (<name>.probe.ts or <name>_probe.py, 2 mutants) and
|
|
52
|
+
prints the command that runs it
|
|
53
|
+
GATE init, upgrade, hook, status, approve-tests, approve-shell, resume, reset, doctor (above)
|
|
54
|
+
ATTEST stopbar attest [--format json|md] deterministic attestation: HEAD, tree, gates, human actions, log sha256,
|
|
55
|
+
probe evidence (the latest probe:result per target, and whether it was taken at the current snapshot)
|
|
35
56
|
All commands take --repo <dir> (default: the current directory). 'verify' is an alias of 'prove'.`
|
|
36
57
|
|
|
37
58
|
function opts(a ) {
|
|
@@ -64,6 +85,7 @@ async function main() {
|
|
|
64
85
|
if (cmd === '--version' || cmd === 'version') return {code: 0, msg: VERSION}
|
|
65
86
|
const o = opts(argv.slice(1))
|
|
66
87
|
if (cmd === 'init') return (await import('./commands.js')).init(o)
|
|
88
|
+
if (cmd === 'upgrade') return (await import('./commands.js')).upgrade(o)
|
|
67
89
|
if (['status', 'approve-tests', 'approve-shell', 'resume', 'reset'].includes(cmd)) return (await import('./commands.js')).human(cmd, o)
|
|
68
90
|
if (cmd === 'doctor') return (await import('./doctor.js')).doctor({repo: o.get('repo'), json: o.has('json')})
|
|
69
91
|
if (cmd === 'prove' || cmd === 'verify') {
|
|
@@ -72,11 +94,25 @@ async function main() {
|
|
|
72
94
|
}
|
|
73
95
|
if (cmd === 'probe') {
|
|
74
96
|
const P = await import('./probe/index.js')
|
|
97
|
+
// a worker share: --worker-file <path> (the runner), or --worker <json> (older runners)
|
|
98
|
+
if (o.has('worker-file')) { await P.worker(JSON.parse(readFileSync(o.get('worker-file') , 'utf8'))); return {code: 0} }
|
|
75
99
|
if (o.has('worker')) { await P.worker(JSON.parse(o.get('worker') )); return {code: 0} }
|
|
76
100
|
const num = (n ) => (o.get(n) === undefined ? undefined : o.int(n, 0))
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
101
|
+
try {
|
|
102
|
+
if (argv[1] === 'init') {
|
|
103
|
+
const io = opts(argv.slice(2))
|
|
104
|
+
const r = (await import('./probe/init.js')).initProbe({lang: io.get('lang'), name: io.get('name'), out: io.get('out'), force: io.has('force'), repo: io.get('repo')})
|
|
105
|
+
return {code: 0, msg: r.message}
|
|
106
|
+
}
|
|
107
|
+
for (const f of ['target', 'cmd', 'target-file']) if (o.has(f) && o.get(f) === undefined) throw new P.ProbeError(`--${f} needs a value`)
|
|
108
|
+
const r = await P.probe({target: o.get('target'), cmd: o.get('cmd'), targetFile: o.get('target-file'), cmdTimeoutMs: num('cmd-timeout'), runs: num('runs'), seed: num('seed'), jobs: num('jobs'), work: o.get('work'), out: o.get('out'),
|
|
109
|
+
regressions: o.get('regressions'), regressionsOnly: o.has('regressions-only'), checkMutants: o.has('check-mutants'), mutantRuns: num('mutant-runs'),
|
|
110
|
+
repo: o.get('repo'), record: !o.has('no-record')})
|
|
111
|
+
return {code: r.ok ? 0 : 1}
|
|
112
|
+
} catch (e) {
|
|
113
|
+
if (e instanceof P.ProbeError) return {code: 1, msg: `stopbar probe: ${e.message}`}
|
|
114
|
+
throw e
|
|
115
|
+
}
|
|
80
116
|
}
|
|
81
117
|
if (cmd === 'attest') return (await import('./attest.js')).attest({repo: o.get('repo'), format: o.get('format')})
|
|
82
118
|
return {code: 1, msg: `unknown command ${cmd}\n\n${HELP}`}
|
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
6
|
import {hasChain, protectedCommand} from './classify.js'
|
|
7
|
-
import {CLAUDE_POST_MATCHER, claudeHooks, hookCommand, installHooks, parseTargets} from './integrations.js'
|
|
8
|
-
import {cliOf, ConfigError, makeConfig, PROFILES} from './config.js'
|
|
7
|
+
import {CLAUDE_POST_MATCHER, claudeHooks, hookCommand, installHooks, parseTargets, } from './integrations.js'
|
|
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'
|
|
10
|
+
import {classifyChanges, whyBlocked} from './hook.js'
|
|
11
11
|
import {CODE_PARTS, PKG_ROOT} from './pkg.js'
|
|
12
|
-
import {findRepo, forgetSnapshots, hasRefTree, markCounted,
|
|
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 ) {
|
|
@@ -41,7 +67,8 @@ export function pinRuntime(r ) {
|
|
|
41
67
|
const dst = join(r.stateDir, 'runtime')
|
|
42
68
|
rmSync(dst, {recursive: true, force: true})
|
|
43
69
|
mkdirSync(dst, {recursive: true})
|
|
44
|
-
|
|
70
|
+
// the .d.ts files in dist/ only type the tests (npm run typecheck); the runtime never loads them
|
|
71
|
+
for (const n of ['bin', 'dist']) cpSync(join(PKG_ROOT, n), join(dst, n), {recursive: true, filter: (f) => !f.endsWith('.d.ts')})
|
|
45
72
|
for (const n of ['package.json', 'LICENSE']) if (existsSync(join(PKG_ROOT, n))) cpSync(join(PKG_ROOT, n), join(dst, n))
|
|
46
73
|
return dst
|
|
47
74
|
}
|
|
@@ -56,11 +83,11 @@ export function init(o ) {
|
|
|
56
83
|
for (const [k, v] of [['--build', buildCmd], ['--test', fullTestCmd]]) {
|
|
57
84
|
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
85
|
}
|
|
59
|
-
for (const f of ['cli', 'stop-gate']) if (o.has(f) && o.get(f) === undefined) return {code: 1, msg: `--${f} needs a value`}
|
|
86
|
+
for (const f of ['cli', 'stop-gate', 'hooks']) if (o.has(f) && o.get(f) === undefined) return {code: 1, msg: `--${f} needs a value`}
|
|
60
87
|
let cfg
|
|
61
88
|
try {
|
|
62
89
|
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')})
|
|
90
|
+
cliCmd: o.get('cli'), stopGate: o.get('stop-gate'), requireRun: o.has('require-run')})
|
|
64
91
|
} catch (e) { if (e instanceof ConfigError) return {code: 1, msg: e.message}; throw e }
|
|
65
92
|
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
93
|
const pin = !o.has('no-pin')
|
|
@@ -75,20 +102,55 @@ export function init(o ) {
|
|
|
75
102
|
return {code: 1, msg: `--base-ref ${JSON.stringify(cfg.baseRef)} does not resolve to a commit/tree in ${repo.root}`}
|
|
76
103
|
}
|
|
77
104
|
const hooksOpt = o.get('hooks')
|
|
78
|
-
const
|
|
105
|
+
const named = hooksOpt === undefined ? [] : parseTargets(hooksOpt) // validated before anything is written
|
|
106
|
+
if (o.has('no-git-hooks') && named.includes('git')) return {code: 1, msg: '--no-git-hooks and --hooks ...git exclude each other'}
|
|
107
|
+
// the git hooks close what an agent hook cannot see (git aliases, merge, cherry-pick, am, commit-tree before a push):
|
|
108
|
+
// added to every --hooks <client> unless --no-git-hooks
|
|
109
|
+
const gitByDefault = named.length > 0 && !named.includes('git') && !o.has('no-git-hooks')
|
|
110
|
+
const targets = gitByDefault ? [...named, 'git'] : named
|
|
79
111
|
mkdirSync(repo.stateDir, {recursive: true})
|
|
80
112
|
return withLock(repo, () => {
|
|
113
|
+
const {s, snap} = freshWithSnap(repo, cfg)
|
|
114
|
+
const dirty = dirtyTests(repo, cfg, snap)
|
|
81
115
|
writeConfig(repo, cfg)
|
|
82
|
-
writeState(repo,
|
|
116
|
+
writeState(repo, s)
|
|
83
117
|
const runtime = pin ? pinRuntime(repo) : PKG_ROOT
|
|
84
118
|
const command = hookCommand(runtime)
|
|
85
|
-
appendEvent(repo, {source: 'human:init', cfg, runtime, version: VERSION, kernel: MACHINE})
|
|
119
|
+
appendEvent(repo, {source: 'human:init', cfg, runtime, version: VERSION, kernel: MACHINE, ...(targets.length ? {hooks: targets} : {})})
|
|
120
|
+
const warn = countDirtyTests(repo, s, dirty, 'init:dirty-tests')
|
|
86
121
|
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`,
|
|
122
|
+
` stop gate: ${cfg.stopGate ?? 'block'}; gate hints use: ${cliOf(cfg)} run build|test${cfg.requireRun ? '; requireRun: true (gates count only through stopbar run build|test)' : ''}`,
|
|
88
123
|
` hooks run: ${command}`]
|
|
89
|
-
|
|
124
|
+
const warns = []
|
|
125
|
+
if (targets.length) for (const l of installHooks(repo, targets, runtime, o.has('force-hooks'), {gitByDefault, warn: (w) => warns.push(w)})) lines.push(` hooks written: ${l}`)
|
|
90
126
|
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))
|
|
91
|
-
lines.push('
|
|
127
|
+
if (gitByDefault) lines.push(' git hooks (pre-commit, pre-push) were added to --hooks by default; pass --no-git-hooks to skip them')
|
|
128
|
+
else if (named.length && o.has('no-git-hooks')) lines.push(' WARN: --no-git-hooks: git aliases, merge, cherry-pick, am and commit-tree are not gated before a push; stopbar doctor reports it')
|
|
129
|
+
lines.push(...warns.map((w) => ` ${w}`), ...warn, 'Next: restart the agent in this repository and run `stopbar doctor`.')
|
|
130
|
+
return {code: 0, msg: lines.join('\n')}
|
|
131
|
+
})
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** `stopbar upgrade`: re-pins the hook runtime (<git-dir>/stopbar/runtime) from this package and, with --hooks, rewrites
|
|
135
|
+
* the hook configuration. state.json, config.json and the snapshots stay as they are (revision, gates, taint, budget), so
|
|
136
|
+
* active sessions keep their green gates. The log entry has no `req`: it is no kernel step and attest stays consistent. */
|
|
137
|
+
export function upgrade(o ) {
|
|
138
|
+
const repo = findRepo(o.get('repo') ?? process.cwd())
|
|
139
|
+
const hooksOpt = o.get('hooks')
|
|
140
|
+
if (o.has('hooks') && hooksOpt === undefined) return {code: 1, msg: '--hooks needs a value'}
|
|
141
|
+
const targets = hooksOpt === undefined ? [] : parseTargets(hooksOpt) // validated before anything is written
|
|
142
|
+
return withLock(repo, () => {
|
|
143
|
+
const cfg = readConfig(repo)
|
|
144
|
+
readState(repo) // a missing or damaged state fails closed here, with the fix
|
|
145
|
+
const had = existsSync(join(repo.stateDir, 'runtime'))
|
|
146
|
+
const runtime = pinRuntime(repo)
|
|
147
|
+
appendEvent(repo, {source: 'human:upgrade', version: VERSION, runtime, kernel: MACHINE, ...(targets.length ? {hooks: targets} : {})})
|
|
148
|
+
const lines = [`Stopbar ${VERSION}: hook runtime re-pinned in ${runtime}`, ' state.json, config.json and the snapshots are unchanged (revision, gates, taint, budget)']
|
|
149
|
+
if (targets.length) for (const l of installHooks(repo, targets, runtime, o.has('force-hooks'))) lines.push(` hooks written: ${l}`)
|
|
150
|
+
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)}`)
|
|
151
|
+
const missing = DEFAULT_SAFE_TOOLS.filter((t) => !(cfg.safeTools ?? DEFAULT_SAFE_TOOLS).includes(t))
|
|
152
|
+
if (missing.length) lines.push(` hint: config.safeTools lacks the default ${missing.join(', ')}; a human adds them to config.json (stopbar doctor shows it)`)
|
|
153
|
+
lines.push('Next: run `stopbar doctor`.')
|
|
92
154
|
return {code: 0, msg: lines.join('\n')}
|
|
93
155
|
})
|
|
94
156
|
}
|
|
@@ -105,21 +167,28 @@ export function secretReason(repo )
|
|
|
105
167
|
return {text: `matched ${pattern} (${path}) in ${tool} at rev ${hit.treeRev}`, pattern, path, tool, revision: hit.treeRev}
|
|
106
168
|
}
|
|
107
169
|
|
|
108
|
-
|
|
170
|
+
/** `now`: the working tree as it is now. A change no hook has counted yet (now.id !== s.snapshot) keeps a commit blocked
|
|
171
|
+
* at the next hook (pre:commit-sync), so status never says `allowed` then. */
|
|
172
|
+
function statusText(repo , cfg , s , now ) {
|
|
109
173
|
const v = decode(s.kernel)
|
|
110
174
|
const yn = (b ) => (b ? 'yes' : 'no')
|
|
111
175
|
const ok = (rev ) => (rev === v.treeRev ? `ok at revision ${rev}` : 'not at the current revision')
|
|
112
|
-
const
|
|
176
|
+
const uncounted = now.id !== s.snapshot
|
|
177
|
+
const green = v.buildOkRev === v.treeRev && v.testsOkRev === v.treeRev && !v.testsTainted
|
|
178
|
+
const commit = v.halted ? 'blocked: session halted' : !green ? `blocked: ${whyBlocked(v, cfg)}`
|
|
179
|
+
: uncounted ? 'blocked: uncommitted working-tree changes not yet counted (run build and full tests on the current tree)' : 'allowed'
|
|
113
180
|
const torn = readEvents(repo).torn.length
|
|
114
181
|
return [
|
|
115
182
|
`Stopbar ${VERSION} repo ${repo.root}`,
|
|
116
183
|
`revision ${v.treeRev} (tree ${s.snapshot.slice(0, 12)})${cfg.baseRef ? ` base ref ${cfg.baseRef}` : ''}`,
|
|
184
|
+
...(uncounted ? [` working tree has uncounted changes since revision ${v.treeRev}; gates will be re-checked on the next hook`] : []),
|
|
117
185
|
`build ${ok(v.buildOkRev)} (${cfg.buildCmd})`,
|
|
118
186
|
`full tests ${ok(v.testsOkRev)} (${cfg.fullTestCmd})`,
|
|
119
187
|
`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)}`,
|
|
120
188
|
`session ${v.halted ? 'HALTED' : 'running'} spent ${v.spent}/${v.capNow} test failures ${v.testFails}/${s.params.maxRetries} build failures ${v.buildFails}/${s.params.maxRetries}`,
|
|
121
189
|
`commit ${commit}`,
|
|
122
190
|
`stop gate ${cfg.stopGate ?? 'block'}${cfg.stopGate === 'warn' ? ' (Stop only warns; git commit and git push stay blocked until the gates pass)' : ''}`,
|
|
191
|
+
...(cfg.requireRun ? ['requireRun true (the build and full test gates count only through stopbar run build|test)'] : []),
|
|
123
192
|
...(torn ? [`event log ${torn} torn line(s) kept as they are (see stopbar doctor)`] : []),
|
|
124
193
|
].join('\n')
|
|
125
194
|
}
|
|
@@ -129,14 +198,19 @@ export function human(cmd , o ) {
|
|
|
129
198
|
const cfg = readConfig(repo)
|
|
130
199
|
return withLock(repo, () => {
|
|
131
200
|
if (cmd === 'reset') {
|
|
132
|
-
|
|
201
|
+
const {s, snap} = freshWithSnap(repo, cfg)
|
|
202
|
+
const dirty = dirtyTests(repo, cfg, snap)
|
|
203
|
+
writeState(repo, s)
|
|
133
204
|
appendEvent(repo, {source: 'human:reset'})
|
|
134
|
-
|
|
205
|
+
const warn = countDirtyTests(repo, s, dirty, 'reset:dirty-tests')
|
|
206
|
+
return {code: 0, msg: ['Stopbar state reset: run the build and the full test suite again before a commit', ...warn].join('\n')}
|
|
135
207
|
}
|
|
136
208
|
const s = readState(repo)
|
|
137
209
|
if (cmd === 'status') {
|
|
138
|
-
|
|
139
|
-
|
|
210
|
+
// the working tree now (read-only for state.json, as in attest: only the private snapshot index is refreshed)
|
|
211
|
+
const now = snapshot(repo)
|
|
212
|
+
return {code: 0, msg: o.has('json') ? JSON.stringify({version: VERSION, repo: repo.root, stateDir: repo.stateDir, config: cfg, stopGate: cfg.stopGate ?? 'block', ...(cfg.requireRun ? {requireRun: true} : {}), snapshot: s.snapshot, params: s.params, kernel: decode(s.kernel),
|
|
213
|
+
secretRead: decode(s.kernel).secretTainted ? secretReason(repo) : null, workingTreeSnapshot: now.id, workingTreeCounted: now.id === s.snapshot}, null, 1) : statusText(repo, cfg, s, now)}
|
|
140
214
|
}
|
|
141
215
|
let res
|
|
142
216
|
if (cmd === 'approve-tests') {
|
package/dist/config.js
CHANGED
|
@@ -21,13 +21,16 @@ import {globToRegExp} from './glob.js'
|
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
24
27
|
|
|
25
28
|
|
|
26
29
|
export const STOP_GATES = ['block', 'warn']
|
|
27
30
|
/** Hint command when config.cliCmd is not set: uses an installed stopbar only, never downloads it from the registry. */
|
|
28
31
|
export const DEFAULT_CLI = 'npx --no-install stopbar'
|
|
29
32
|
|
|
30
|
-
const TEST_COMMON = ['**/tests/**', '**/test/**', '**/__tests__/**']
|
|
33
|
+
const TEST_COMMON = ['**/tests/**', '**/test/**', '**/__tests__/**', 'scripts/*test*']
|
|
31
34
|
const TEST_JS = ['**/*.test.*', '**/*.spec.*', '**/e2e/**']
|
|
32
35
|
const TEST_PY = ['**/test_*.py', '**/*_test.py']
|
|
33
36
|
const TEST_OTHER = ['**/*_test.go', '**/*_test.rs', '**/*Test.java', '**/*Tests.cs']
|
|
@@ -106,6 +109,7 @@ export function validateConfig(c ) {
|
|
|
106
109
|
if (o.stopGate !== undefined && !STOP_GATES.includes(o.stopGate )) {
|
|
107
110
|
throw new ConfigError(`config.stopGate must be ${STOP_GATES.map((g) => JSON.stringify(g)).join(' or ')}, got ${JSON.stringify(o.stopGate)}`)
|
|
108
111
|
}
|
|
112
|
+
if (o.requireRun !== undefined && typeof o.requireRun !== 'boolean') throw new ConfigError(`config.requireRun must be true or false, got ${JSON.stringify(o.requireRun)}`)
|
|
109
113
|
return o
|
|
110
114
|
}
|
|
111
115
|
|
|
@@ -131,7 +135,7 @@ export function isSafeRef(ref ) {
|
|
|
131
135
|
}
|
|
132
136
|
|
|
133
137
|
export function makeConfig(a
|
|
134
|
-
|
|
138
|
+
) {
|
|
135
139
|
const profile = a.profile ?? 'default'
|
|
136
140
|
const paths = PROFILES[profile]
|
|
137
141
|
if (!paths) throw new ConfigError(`unknown profile ${JSON.stringify(profile)}; known: ${Object.keys(PROFILES).join(', ')}`)
|
|
@@ -145,5 +149,6 @@ export function makeConfig(a
|
|
|
145
149
|
...(baseRef && baseRef !== 'HEAD' ? {baseRef} : {}),
|
|
146
150
|
...(cliCmd !== undefined ? {cliCmd} : {}),
|
|
147
151
|
...(a.stopGate !== undefined ? {stopGate: a.stopGate} : {}),
|
|
152
|
+
...(a.requireRun === true ? {requireRun: true} : {}),
|
|
148
153
|
})
|
|
149
154
|
}
|
package/dist/doctor.js
CHANGED
|
@@ -69,8 +69,8 @@ function stopbarCommands(events )
|
|
|
69
69
|
return out
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
/** Other clients and the git fallback. Returns how many have Stopbar hooks. */
|
|
73
|
-
function checkOtherClients(repo , add )
|
|
72
|
+
/** Other clients and the git fallback. Returns how many clients have Stopbar hooks, and how many Stopbar git hooks exist. */
|
|
73
|
+
function checkOtherClients(repo , add ) {
|
|
74
74
|
let found = 0
|
|
75
75
|
const clients = [
|
|
76
76
|
['cursor', join(repo.root, '.cursor', 'hooks.json'), (j) => j.hooks, ['preToolUse', 'postToolUse', 'postToolUseFailure', 'stop']],
|
|
@@ -95,8 +95,11 @@ function checkOtherClients(repo , add
|
|
|
95
95
|
let dir = join(repo.gitDir, 'hooks')
|
|
96
96
|
try { const rel = execFileSync('git', ['rev-parse', '--git-path', 'hooks'], {cwd: repo.root, encoding: 'utf8'}).trim(); dir = isAbsolute(rel) ? rel : join(repo.root, rel) } catch { /* default */ }
|
|
97
97
|
const gh = ['pre-commit', 'pre-push'].filter((n) => existsSync(join(dir, n)) && readFileSync(join(dir, n), 'utf8').includes('stopbar.mjs" git-hook'))
|
|
98
|
-
|
|
99
|
-
|
|
98
|
+
const lacking = ['pre-commit', 'pre-push'].filter((n) => !gh.includes(n))
|
|
99
|
+
// the git hooks close what an agent hook cannot see: git aliases, and on pre-push merge, cherry-pick, am and commit-tree
|
|
100
|
+
if (!lacking.length) add('OK', 'hooks git', `pre-commit, pre-push in ${dir}`)
|
|
101
|
+
else add('WARN', 'hooks git', `no Stopbar ${lacking.join(' and ')} hook in ${dir}: the git hooks close git aliases, and on pre-push merge, cherry-pick, am and commit-tree, which an agent hook does not see; a human runs \`stopbar upgrade --hooks git\``)
|
|
102
|
+
return {clients: found, git: gh.length}
|
|
100
103
|
}
|
|
101
104
|
|
|
102
105
|
/** The real hook pipeline (in process) on a scratch repository inside <git-dir>/stopbar/doctor-run. */
|
|
@@ -142,13 +145,16 @@ export async function doctor(o )
|
|
|
142
145
|
add(maj > 22 || (maj === 22 && min >= 18) ? 'OK' : 'FAIL', 'node', `v${process.versions.node} (needs >= 22.18)`)
|
|
143
146
|
try { add('OK', 'git', execFileSync('git', ['--version'], {encoding: 'utf8'}).trim()) } catch { add('FAIL', 'git', 'git not found on PATH') }
|
|
144
147
|
add(MACHINE.name === 'stopbar_kernel_none' ? 'OK' : 'FAIL', 'kernel', `${MACHINE.name}, kernel.ts sha256 ${MACHINE.kernelSha256.slice(0, 16)}, machine sha256 ${MACHINE.machineSha256.slice(0, 16)}`)
|
|
145
|
-
|
|
148
|
+
// npm may hoist gdp-wired next to this package (npm install stopbar): resolve it as Node does, never by a fixed path
|
|
149
|
+
let prover = false
|
|
150
|
+
try { import.meta.resolve('gdp-wired/machine'); prover = true } catch { /* not resolvable: a pinned runtime has no node_modules */ }
|
|
151
|
+
if (prover && existsSync(join(PKG_ROOT, 'dist', 'kernel.js'))) {
|
|
146
152
|
try {
|
|
147
153
|
const {checkGenerated} = await import('./verify.js')
|
|
148
154
|
const g = await checkGenerated(500)
|
|
149
155
|
add(g.ok ? 'OK' : 'FAIL', 'kernel link', `compileJs(kernel.ts) == dist/kernel.gen.js: ${g.sameMachine}; kernel.ts hash: ${g.sameSource}; ${(g.differential ).steps} steps vs interpreter, ${(g.differential ).mismatches} mismatches`)
|
|
150
156
|
} catch (e) { add('WARN', 'kernel link', `not checked: ${(e ).message}`) }
|
|
151
|
-
} else add('WARN', 'kernel link', 'gdp-wired
|
|
157
|
+
} else add('WARN', 'kernel link', 'gdp-wired cannot be resolved from this copy (a pinned runtime has no node_modules): run `stopbar prove` in the package')
|
|
152
158
|
|
|
153
159
|
let repo = null
|
|
154
160
|
try { repo = findRepo(o.repo ?? process.cwd()); add('OK', 'repository', `${repo.root} (state in ${repo.stateDir})`) } catch (e) { add('FAIL', 'repository', (e ).message) }
|
|
@@ -158,7 +164,7 @@ export async function doctor(o )
|
|
|
158
164
|
const cfg = readConfig(repo); cfgOk = true
|
|
159
165
|
add('OK', 'config.json', `profile ${cfg.profile}; build \`${cfg.buildCmd}\`; full tests \`${cfg.fullTestCmd}\`; maxRetries ${cfg.maxRetries}; cap ${cfg.cap}; ` +
|
|
160
166
|
`${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)}`)
|
|
167
|
+
`stopGate ${cfg.stopGate ?? 'block'}; cli ${cliOf(cfg)}${cfg.requireRun ? '; requireRun: true' : ''}`)
|
|
162
168
|
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
169
|
const safe = cfg.safeTools ?? DEFAULT_SAFE_TOOLS
|
|
164
170
|
const missing = DEFAULT_SAFE_TOOLS.filter((t) => !safe.includes(t))
|
|
@@ -176,11 +182,15 @@ export async function doctor(o )
|
|
|
176
182
|
const rt = join(repo.stateDir, 'runtime', 'dist', 'kernel.gen.js')
|
|
177
183
|
if (existsSync(rt)) {
|
|
178
184
|
const same = existsSync(join(PKG_ROOT, 'dist', 'kernel.gen.js')) && sha(rt) === sha(join(PKG_ROOT, 'dist', 'kernel.gen.js'))
|
|
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
|
|
185
|
+
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)'}`)
|
|
180
186
|
} else if (cfgOk) add('WARN', 'pinned runtime', 'none: hooks run an unpinned copy (init --no-pin)')
|
|
181
187
|
const others = checkOtherClients(repo, add)
|
|
182
188
|
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 })
|
|
183
|
-
|
|
189
|
+
// Claude Code hooks named at the last init or upgrade must be there, also when other hooks (now the git hooks by
|
|
190
|
+
// default) exist; without any client hooks, the Claude Code ones are reported as missing (v1.0 output)
|
|
191
|
+
const named = ev.events.filter((e) => (e.source === 'human:init' || e.source === 'human:upgrade') && Array.isArray(e.hooks)).at(-1)?.hooks
|
|
192
|
+
const wantClaude = !!named?.some((t) => t === 'claude' || t === 'claude-project')
|
|
193
|
+
if (claudeHas || (others.clients === 0 && (others.git === 0 || wantClaude))) checkHooks(repo.root, add)
|
|
184
194
|
try { dryRun(repo.stateDir, add) } catch (e) { add('FAIL', 'dry run', String(e)) }
|
|
185
195
|
}
|
|
186
196
|
const fails = checks.filter((c) => c.status === 'FAIL').length, warns = checks.filter((c) => c.status === 'WARN').length
|