stopbar 1.1.3 → 1.2.1
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 +184 -0
- package/README.md +225 -31
- package/SECURITY.md +129 -39
- package/bin/stopbar.mjs +0 -0
- package/dist/adapters/antigravity.js +6 -6
- package/dist/adapters/claude.js +1 -1
- package/dist/adapters/codex.js +7 -7
- package/dist/adapters/cursor.js +6 -6
- package/dist/adapters/gemini.js +7 -7
- package/dist/adapters/index.js +4 -3
- package/dist/adapters/types.js +7 -4
- package/dist/attest.js +28 -3
- package/dist/build-info.json +2 -2
- package/dist/classify.js +356 -29
- package/dist/cli.js +39 -7
- package/dist/commands.js +36 -13
- package/dist/config.js +7 -2
- package/dist/doctor.js +63 -28
- package/dist/hook.js +59 -32
- package/dist/integrations.js +50 -6
- package/dist/probe/index.js +261 -62
- package/dist/probe/init.js +217 -0
- package/dist/probe/sdk.js +242 -0
- package/dist/probe/stdio.js +219 -0
- package/dist/probe/wrapper.js +1 -1
- package/dist/store.js +1 -1
- package/dist/verify.js +34 -26
- package/package.json +17 -2
- package/skills/stopbar/SKILL.md +126 -0
- package/src/probe/sdk.ts +241 -0
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
// Built from src/probe/stdio.ts by scripts/build.ts. Do not edit.
|
|
2
|
+
// PROBE targets in any language: `stopbar probe --cmd "<command>"` starts the command once per worker and speaks
|
|
3
|
+
// line-delimited JSON (NDJSON) with it on stdin/stdout, one request and one answer per line, in order:
|
|
4
|
+
// {"op":"info"} -> {"name":"...","description":"...","mutants":["M1",...]}
|
|
5
|
+
// {"op":"generate","seed":123} -> {"seed":123,"actions":[...]}
|
|
6
|
+
// {"op":"execute","run":{...},"dir":"...","mutant":"M1"} -> an Outcome ({"ok":true,"steps":N,"cov":{...}} or
|
|
7
|
+
// {"ok":false,"mismatch":{"step","action","what","expected","actual"}})
|
|
8
|
+
// Any answer may be {"error":"..."} instead. stdout carries only the protocol; the program logs to stderr. A process
|
|
9
|
+
// that exits, closes stdout, answers with something that is not JSON or does not answer within the timeout is an
|
|
10
|
+
// error (ProbeError with the end of its stderr), never a hung worker.
|
|
11
|
+
import {spawn, spawnSync, } from 'node:child_process'
|
|
12
|
+
import {existsSync, statSync} from 'node:fs'
|
|
13
|
+
import {resolve} from 'node:path'
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
/** A refusal of the user's input (unknown file, bad export, no mutants, a broken --cmd): the CLI exits 1 with it. */
|
|
17
|
+
export class ProbeError extends Error {}
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
/** Splits a command line into words: whitespace separates, '...' and "..." group (no escapes inside '...'). */
|
|
23
|
+
export function splitCommand(cmd ) {
|
|
24
|
+
const out = []
|
|
25
|
+
let cur = '', inWord = false, q = null
|
|
26
|
+
for (let i = 0; i < cmd.length; i++) {
|
|
27
|
+
const c = cmd[i]
|
|
28
|
+
if (q) {
|
|
29
|
+
if (c === q) q = null
|
|
30
|
+
else if (q === '"' && c === '\\' && (cmd[i + 1] === '"' || cmd[i + 1] === '\\')) cur += cmd[++i]
|
|
31
|
+
else cur += c
|
|
32
|
+
} else if (c === '"' || c === "'") { q = c; inWord = true } else if (/\s/.test(c)) { if (inWord) out.push(cur); cur = ''; inWord = false } else { cur += c; inWord = true }
|
|
33
|
+
}
|
|
34
|
+
if (inWord) out.push(cur)
|
|
35
|
+
return out
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** The file a command runs: the first word after the interpreter that names an existing file (relative to `cwd`). */
|
|
39
|
+
export function commandFile(cmd , cwd = process.cwd()) {
|
|
40
|
+
for (const w of splitCommand(cmd).slice(1)) {
|
|
41
|
+
if (w.startsWith('-')) continue
|
|
42
|
+
const f = resolve(cwd, w)
|
|
43
|
+
try { if (existsSync(f) && statSync(f).isFile()) return f } catch { /* not a file */ }
|
|
44
|
+
}
|
|
45
|
+
return null
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const NAT = (n ) => typeof n === 'number' && Number.isSafeInteger(n) && n >= 0
|
|
49
|
+
const INT = (n ) => typeof n === 'number' && Number.isSafeInteger(n)
|
|
50
|
+
const isObj = (x ) => !!x && typeof x === 'object' && !Array.isArray(x)
|
|
51
|
+
|
|
52
|
+
/** One long-lived process of a --cmd target. Requests go one at a time; `close` ends stdin and kills it if needed. */
|
|
53
|
+
export class CmdClient {
|
|
54
|
+
cmd
|
|
55
|
+
ch = null
|
|
56
|
+
buf = ''
|
|
57
|
+
err = ''
|
|
58
|
+
exited = null
|
|
59
|
+
killed = false // set by kill(): its 'exit' may never arrive (the child is unref'd)
|
|
60
|
+
waiting = null
|
|
61
|
+
chain = Promise.resolve()
|
|
62
|
+
cwd
|
|
63
|
+
timeoutMs
|
|
64
|
+
|
|
65
|
+
constructor(cmd , o = {}) {
|
|
66
|
+
if (!cmd.trim()) throw new ProbeError('--cmd needs a command, e.g. --cmd "python my_probe.py"')
|
|
67
|
+
this.cmd = cmd; this.cwd = o.cwd ?? process.cwd(); this.timeoutMs = o.timeoutMs ?? 300_000
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
stderrTail() {
|
|
71
|
+
const t = this.err.trim()
|
|
72
|
+
return t ? `; stderr: ${t.length > 600 ? '...' + t.slice(-600) : t}` : '; stderr: (empty)'
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
fail(why ) {
|
|
76
|
+
const w = this.waiting
|
|
77
|
+
this.waiting = null
|
|
78
|
+
if (w) { if (w.timer) clearTimeout(w.timer); w.bad(new ProbeError(`probe command ${JSON.stringify(this.cmd)} ${why} (waiting for the answer to ${w.op})${this.stderrTail()}`)) }
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
start() {
|
|
82
|
+
if (this.ch && this.exited === null && !this.killed) return this.ch
|
|
83
|
+
this.buf = ''; this.err = ''; this.exited = null; this.killed = false
|
|
84
|
+
// a shell, so the command line works as typed (python, py -3, npx tsx, a script with a #!)
|
|
85
|
+
const ch = spawn(this.cmd, {cwd: this.cwd, shell: true, stdio: ['pipe', 'pipe', 'pipe'], windowsHide: true, detached: process.platform !== 'win32'})
|
|
86
|
+
this.ch = ch
|
|
87
|
+
ch.stdout .setEncoding('utf8'); ch.stderr .setEncoding('utf8')
|
|
88
|
+
const live = () => this.ch === ch // handlers of an earlier process of this client do nothing
|
|
89
|
+
ch.stderr .on('data', (d ) => { if (live()) this.err = (this.err + d).slice(-4000) })
|
|
90
|
+
ch.stdout .on('data', (d ) => {
|
|
91
|
+
if (!live()) return
|
|
92
|
+
this.buf += d
|
|
93
|
+
for (let i = this.buf.indexOf('\n'); i >= 0; i = this.buf.indexOf('\n')) {
|
|
94
|
+
const line = this.buf.slice(0, i).trim()
|
|
95
|
+
this.buf = this.buf.slice(i + 1)
|
|
96
|
+
if (!line) continue
|
|
97
|
+
const w = this.waiting
|
|
98
|
+
if (!w) { this.err += `\n[stopbar] unexpected line on stdout: ${line.slice(0, 200)}`; continue }
|
|
99
|
+
let v
|
|
100
|
+
try { v = JSON.parse(line) } catch {
|
|
101
|
+
this.fail(`printed a line that is not JSON: ${JSON.stringify(line.slice(0, 200))} (stdout is for the protocol only; log to stderr)`)
|
|
102
|
+
this.kill(); return
|
|
103
|
+
}
|
|
104
|
+
this.waiting = null
|
|
105
|
+
if (w.timer) clearTimeout(w.timer)
|
|
106
|
+
w.ok(v)
|
|
107
|
+
}
|
|
108
|
+
})
|
|
109
|
+
const gone = () => { if (live() && this.waiting) this.fail(this.exited ? `${this.exited} before answering` : 'closed stdout') }
|
|
110
|
+
// stdout may end before 'exit' arrives: wait a moment so the error names the exit code
|
|
111
|
+
ch.stdout .on('end', () => setTimeout(gone, 100))
|
|
112
|
+
ch.stdin .on('error', () => { /* EPIPE after an exit: reported below */ })
|
|
113
|
+
ch.on('error', (e) => { if (!live()) return; this.exited = `failed to start: ${e.message}`; this.fail(this.exited) })
|
|
114
|
+
ch.on('exit', (code, sig) => { if (live()) this.exited = `exited with ${sig ? `signal ${sig}` : `code ${code}`}` })
|
|
115
|
+
ch.on('close', gone)
|
|
116
|
+
return ch
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Sends one request and waits for its answer line (requests are queued, one at a time). */
|
|
120
|
+
request(msg ) {
|
|
121
|
+
const go = () => new Promise ((ok, bad) => {
|
|
122
|
+
const ch = this.start()
|
|
123
|
+
const op = String(msg.op)
|
|
124
|
+
this.waiting = {op, ok, bad}
|
|
125
|
+
if (this.timeoutMs > 0) this.waiting.timer = setTimeout(() => { this.fail(`did not answer within ${this.timeoutMs} ms`); this.kill() }, this.timeoutMs)
|
|
126
|
+
try { ch.stdin .write(JSON.stringify(msg) + '\n') } catch (e) { this.fail(`does not read stdin: ${(e ).message}`) }
|
|
127
|
+
})
|
|
128
|
+
const p = this.chain.then(go, go)
|
|
129
|
+
this.chain = p.catch(() => undefined)
|
|
130
|
+
return p
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
async ask(msg ) {
|
|
134
|
+
const v = await this.request(msg)
|
|
135
|
+
if (isObj(v) && typeof v.error === 'string') throw new ProbeError(`probe command ${JSON.stringify(this.cmd)} answered ${msg.op} with an error: ${v.error}${this.stderrTail()}`)
|
|
136
|
+
if (!isObj(v)) throw new ProbeError(`probe command ${JSON.stringify(this.cmd)}: the answer to ${msg.op} is not a JSON object: ${JSON.stringify(v)?.slice(0, 200)}`)
|
|
137
|
+
return v
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
bad(op , why , v ) {
|
|
141
|
+
throw new ProbeError(`probe command ${JSON.stringify(this.cmd)}: bad answer to ${op}: ${why}; got ${JSON.stringify(v)?.slice(0, 300)}`)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
async info() {
|
|
145
|
+
const v = await this.ask({op: 'info'})
|
|
146
|
+
if (typeof v.name !== 'string' || !v.name) this.bad('info', 'name must be a non-empty string', v)
|
|
147
|
+
if (typeof v.description !== 'string') this.bad('info', 'description must be a string', v)
|
|
148
|
+
if (v.mutants !== undefined && v.mutants !== null && !(Array.isArray(v.mutants) && v.mutants.every((m ) => typeof m === 'string' && m))) this.bad('info', 'mutants must be a list of names', v)
|
|
149
|
+
return {name: v.name, description: v.description, ...(Array.isArray(v.mutants) ? {mutants: v.mutants} : {})}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
async generate(seed ) {
|
|
153
|
+
const v = await this.ask({op: 'generate', seed})
|
|
154
|
+
if (v.seed !== seed) this.bad('generate', `seed must be ${seed}`, v)
|
|
155
|
+
if (!Array.isArray(v.actions)) this.bad('generate', 'actions must be a list', v)
|
|
156
|
+
return {...v, seed, actions: v.actions}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
async execute(run , dir , mutant ) {
|
|
160
|
+
const v = await this.ask({op: 'execute', run, dir, ...(mutant === undefined ? {} : {mutant})})
|
|
161
|
+
if (v.ok === true) {
|
|
162
|
+
if (!NAT(v.steps)) this.bad('execute', 'steps must be an integer >= 0', v)
|
|
163
|
+
const cov = v.cov ?? {}
|
|
164
|
+
if (!isObj(cov) || !Object.values(cov).every(NAT)) this.bad('execute', 'cov must map names to integers >= 0', v)
|
|
165
|
+
return {ok: true, steps: v.steps, cov: cov }
|
|
166
|
+
}
|
|
167
|
+
if (v.ok === false) {
|
|
168
|
+
const m = v.mismatch
|
|
169
|
+
if (!isObj(m) || !INT(m.step) || m.step < -1 || typeof m.what !== 'string' || !m.what) this.bad('execute', 'mismatch needs step (integer >= -1) and what (non-empty string)', v)
|
|
170
|
+
return {ok: false, mismatch: {step: m.step, action: m.action ?? null, what: m.what, expected: m.expected ?? null, actual: m.actual ?? null}}
|
|
171
|
+
}
|
|
172
|
+
return this.bad('execute', 'ok must be true or false', v)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** Kills the process tree. taskkill reports a failure (no rights, a sandbox, not on PATH) by its status, not by an
|
|
176
|
+
* exception: then the direct child is killed. The pipes are always destroyed and the child unref'd, so a process
|
|
177
|
+
* that survives (a grandchild of the shell) can never hold the event loop of Stopbar open. */
|
|
178
|
+
kill() {
|
|
179
|
+
const ch = this.ch
|
|
180
|
+
if (!ch) return
|
|
181
|
+
this.killed = true
|
|
182
|
+
if (ch.pid !== undefined && this.exited === null) {
|
|
183
|
+
let treeKilled = false
|
|
184
|
+
try {
|
|
185
|
+
if (process.platform === 'win32') {
|
|
186
|
+
const r = spawnSync('taskkill', ['/pid', String(ch.pid), '/T', '/F'], {stdio: 'ignore', windowsHide: true})
|
|
187
|
+
treeKilled = !r.error && r.status === 0
|
|
188
|
+
} else { process.kill(-ch.pid, 'SIGKILL'); treeKilled = true }
|
|
189
|
+
} catch { /* fall back to the direct child below */ }
|
|
190
|
+
if (!treeKilled) try { ch.kill('SIGKILL') } catch { /* gone */ }
|
|
191
|
+
}
|
|
192
|
+
for (const s of [ch.stdin, ch.stdout, ch.stderr]) try { s?.destroy() } catch { /* closed */ }
|
|
193
|
+
ch.unref()
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** Ends stdin (a well-behaved target exits on EOF); kills the process tree after `graceMs`. Returns at once for a
|
|
197
|
+
* process that has exited or was killed. The timers here hold the event loop and are cleared when the wait ends: an
|
|
198
|
+
* unref'd timer racing an 'exit' that never comes would let Node end with the caller's error unthrown (exit 0 from
|
|
199
|
+
* the CLI, exit 13 from `await probe()`). */
|
|
200
|
+
async close(graceMs = 2000) {
|
|
201
|
+
const ch = this.ch
|
|
202
|
+
const done = () => this.killed || this.exited !== null || ch .exitCode !== null || ch .signalCode !== null
|
|
203
|
+
if (!ch || done()) return
|
|
204
|
+
await this.chain
|
|
205
|
+
if (done()) return
|
|
206
|
+
const gone = new Promise ((ok) => ch.once('exit', () => ok()))
|
|
207
|
+
try { ch.stdin .end() } catch { /* already closed */ }
|
|
208
|
+
if (await settle(gone, graceMs) === 'late') {
|
|
209
|
+
this.kill() // destroys the pipes and unrefs the child even when the kill itself fails
|
|
210
|
+
await settle(gone, 1000)
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** 'gone' when `p` settles first, else 'late' after `ms`; the timer is cleared either way. */
|
|
216
|
+
async function settle(p , ms ) {
|
|
217
|
+
let t
|
|
218
|
+
try { return await Promise.race([p.then(() => 'gone' ), new Promise ((ok) => { t = setTimeout(() => ok('late'), ms) })]) } finally { clearTimeout(t) }
|
|
219
|
+
}
|
package/dist/probe/wrapper.js
CHANGED
|
@@ -131,7 +131,7 @@ async function execute(run , dir ) {
|
|
|
131
131
|
let st = IT.init(P)
|
|
132
132
|
let modelSteps = 0
|
|
133
133
|
let head = new Map(work), counted = new Map(work), countedCopy = true
|
|
134
|
-
const view = () => R.decode(st)
|
|
134
|
+
const view = () => R.decode(st)
|
|
135
135
|
const kstep = (req ) => {
|
|
136
136
|
st = IT.step(P, st, R.encodeInput({op: 'EDIT_CODE', cost: 0, passed: false, fullSuite: false, suspicious: false, risky: false, treeChanged: false, approveRev: 0, extra: 0, ...req}, {maxRetries, cap}))
|
|
137
137
|
modelSteps++
|
package/dist/store.js
CHANGED
package/dist/verify.js
CHANGED
|
@@ -29,14 +29,20 @@ export async function loadKernel() {
|
|
|
29
29
|
return {k, gw, machine}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
32
38
|
/** The generated step function is the compileJs output of the unmutated kernel, and it agrees with the interpreter. */
|
|
33
|
-
export async function checkGenerated(steps = 3000)
|
|
39
|
+
export async function checkGenerated(steps = 3000) {
|
|
34
40
|
const {k, machine} = await loadKernel()
|
|
35
41
|
const R = k.kernel('none')
|
|
36
42
|
const js = machine.compileJs(R.machine)
|
|
37
43
|
const src = join(PKG_ROOT, 'src', 'kernel.ts')
|
|
38
44
|
const kernelSha = existsSync(src) ? sha(readFileSync(src)) : null
|
|
39
|
-
const
|
|
45
|
+
const head = {
|
|
40
46
|
machineName: G.MACHINE_NAME, machineSha256: G.MACHINE_SHA256, regeneratedSha256: sha(js),
|
|
41
47
|
sameMachine: sha(js) === G.MACHINE_SHA256 && G.MACHINE_NAME === R.machine.name,
|
|
42
48
|
kernelSourceSha256: G.KERNEL_SOURCE_SHA256, kernelSourceNow: kernelSha, sameSource: kernelSha === null ? null : kernelSha === G.KERNEL_SOURCE_SHA256,
|
|
@@ -48,7 +54,7 @@ export async function checkGenerated(steps = 3000) {
|
|
|
48
54
|
for (let run = 0; done < steps; run++) {
|
|
49
55
|
const params = {maxRetries: 1 + Math.floor(rnd() * 3), cap: 1 + Math.floor(rnd() * 12)}
|
|
50
56
|
const P = R.encodeParams(params)
|
|
51
|
-
let a = IT.init(P), b
|
|
57
|
+
let a = IT.init(P), b = G.init(params)
|
|
52
58
|
for (let i = 0; i < 25 && done < steps; i++, done++) {
|
|
53
59
|
const req = randomRequest(rnd)
|
|
54
60
|
const enc = R.encodeInput(req, params)
|
|
@@ -59,9 +65,7 @@ export async function checkGenerated(steps = 3000) {
|
|
|
59
65
|
if (JSON.stringify(a.scalars) !== JSON.stringify(b.scalars)) { mismatches++; break }
|
|
60
66
|
}
|
|
61
67
|
}
|
|
62
|
-
|
|
63
|
-
res.ok = res.sameMachine === true && res.sameSource !== false && mismatches === 0
|
|
64
|
-
return res
|
|
68
|
+
return {...head, differential: {steps: done, refused, mismatches}, ok: head.sameMachine && head.sameSource !== false && mismatches === 0}
|
|
65
69
|
}
|
|
66
70
|
|
|
67
71
|
// A concrete counterexample run for each mutant (each one found by the prover). verify
|
|
@@ -80,6 +84,7 @@ export const KNOWN_RUNS
|
|
|
80
84
|
M6: {params: {maxRetries: 1, cap: 1}, trace: [{op: 'SHELL', suspicious: true, treeChanged: true}, {op: 'RUN_TESTS', passed: true, fullSuite: true}, {op: 'APPROVE_TESTS', approveRev: 0}, {op: 'RUN_BUILD', passed: true}, {op: 'COMMIT'}]},
|
|
81
85
|
M7: {params: {maxRetries: 2, cap: 3}, trace: [{op: 'RUN_BUILD', cost: 3, passed: true}, {op: 'APPROVE_SHELL'}]},
|
|
82
86
|
}
|
|
87
|
+
|
|
83
88
|
const show = (q ) => {
|
|
84
89
|
const flags = Object.entries(q).filter(([k, x]) => k !== 'op' && x).map(([k, x]) => `${k}=${x}`)
|
|
85
90
|
return flags.length ? `${q.op}(${flags.join(',')})` : String(q.op)
|
|
@@ -90,64 +95,67 @@ export async function verify(o
|
|
|
90
95
|
const {k, gw} = await loadKernel()
|
|
91
96
|
const {kernel, laws, lemmas, MUTANTS} = k
|
|
92
97
|
const OPT = {search: {ms: 60000}}
|
|
93
|
-
const
|
|
98
|
+
const head = {gdpWired: '0.60.0', node: process.version, platform: `${process.platform} ${process.arch}`}
|
|
94
99
|
|
|
95
100
|
log('1. generated step function vs the proven rule')
|
|
96
|
-
|
|
97
|
-
log(` machine ${
|
|
98
|
-
`differential ${
|
|
101
|
+
const generated = await checkGenerated()
|
|
102
|
+
log(` machine ${generated.machineName}: same compileJs output=${generated.sameMachine}, kernel.ts hash matches=${generated.sameSource}, ` +
|
|
103
|
+
`differential ${generated.differential.steps} steps, mismatches=${generated.differential.mismatches}`)
|
|
99
104
|
|
|
100
105
|
log('2. inductive proof of the original kernel (laws + lemmas I1-I5)')
|
|
106
|
+
let original
|
|
101
107
|
{
|
|
102
108
|
const r = kernel('none'), {laws: L, stepLaws: S} = laws(r)
|
|
103
109
|
const t = Date.now()
|
|
104
110
|
const v = gw.proveSteps(r, [...L, ...lemmas(r)], S, OPT)
|
|
105
|
-
|
|
106
|
-
laws: [...L, ...lemmas(r)].map((l
|
|
111
|
+
original = {proven: v.proven, checked: v.checked, stuck: v.stuck, goal: v.goal, why: v.why, ms: Date.now() - t,
|
|
112
|
+
laws: [...L, ...lemmas(r)].map((l ) => l.name), stepLaws: S.map((l ) => l.name)}
|
|
107
113
|
log(` proven=${v.proven} checked=${v.checked} ${Date.now() - t} ms${v.goal ? ' goal=' + v.goal : ''}`)
|
|
108
114
|
}
|
|
109
115
|
|
|
110
116
|
log('3. mutants: each must fall with a counterexample run')
|
|
111
|
-
|
|
117
|
+
const mutants = {}
|
|
112
118
|
for (const m of MUTANTS.filter((x ) => x !== 'none')) {
|
|
113
119
|
const r = kernel(m), {laws: L, stepLaws: S} = laws(r)
|
|
114
120
|
const t = Date.now()
|
|
115
121
|
const v = gw.proveSteps(r, L, S, OPT)
|
|
116
|
-
const failed
|
|
122
|
+
const failed = [...L, ...S].find((l ) => v.goal?.startsWith(l.name))
|
|
117
123
|
let minimized = false
|
|
118
124
|
if (v.run && failed) { try { v.run = gw.minimizeRun(r, failed, v.run); minimized = true } catch { /* keep the unminimised run */ } }
|
|
119
|
-
const trace = (v.run?.trace ?? []).map((q
|
|
120
|
-
const op = typeof q.op === 'number' ? OPS[q.op] : q.op
|
|
125
|
+
const trace = (v.run?.trace ?? []).map((q ) => {
|
|
126
|
+
const op = typeof q.op === 'number' ? OPS[q.op] : String(q.op)
|
|
121
127
|
const flags = Object.entries(q).filter(([kk, x]) => kk !== 'op' && x).map(([kk, x]) => `${kk}=${x}`)
|
|
122
128
|
return flags.length ? `${op}(${flags.join(',')})` : op
|
|
123
129
|
})
|
|
124
130
|
// deterministic replay of the known counterexample: a law fails on the mutant and every law holds on the original
|
|
125
131
|
const known = KNOWN_RUNS[m]
|
|
126
132
|
const r0 = kernel('none'), l0 = laws(r0)
|
|
127
|
-
const enc = (rule
|
|
133
|
+
const enc = (rule ) => known.trace.map((q) => rule.encodeInput({...REQ0, ...q}, known.params))
|
|
128
134
|
const onMutant = gw.replayRefutation(r, L, S, r.encodeParams(known.params), enc(r), 1000)
|
|
129
135
|
const onOriginal = gw.replayRefutation(r0, l0.laws, l0.stepLaws, r0.encodeParams(known.params), enc(r0), 1000)
|
|
130
136
|
const killed = v.proven === false && onMutant === true && onOriginal === false
|
|
131
|
-
|
|
137
|
+
mutants[m] = {killed, proven: v.proven, goal: v.goal, ms: Date.now() - t, minimized, proverRun: v.run ? {params: v.run.params, trace} : null,
|
|
132
138
|
proverWitness: v.run ? undefined : v.witness, counterexample: {params: known.params, trace: known.trace.map(show), breaksMutant: onMutant, breaksOriginal: onOriginal}}
|
|
133
139
|
log(` ${m.padEnd(4)} ${killed ? 'KILLED' : 'SURVIVED'} by ${v.goal ?? '-'} (${Date.now() - t} ms)` +
|
|
134
140
|
`\n counterexample ${known.trace.map(show).join(' -> ')} ${JSON.stringify(known.params)}: breaks the mutant=${onMutant}, breaks the original=${onOriginal}` +
|
|
135
141
|
(trace.length ? `\n prover run (minimized=${minimized}): ${trace.join(' -> ')}` : '\n prover: inductive witness only (no run within the search budget)'))
|
|
136
142
|
}
|
|
137
143
|
|
|
144
|
+
let lean
|
|
138
145
|
if (o.lean) {
|
|
139
146
|
const {toLean} = await import('gdp-wired/lean')
|
|
140
147
|
const r = kernel('none'), {laws: L, stepLaws: S} = laws(r)
|
|
141
|
-
const
|
|
142
|
-
writeFileSync(o.lean,
|
|
143
|
-
|
|
144
|
-
log(`4. Lean export ${o.lean}: ${
|
|
148
|
+
const text = toLean([{id: 'stopbar_kernel', machine: r.machine, laws: [...L, ...lemmas(r)], stepLaws: S}], {title: 'Stopbar kernel (gdp-wired 0.60.0)'})
|
|
149
|
+
writeFileSync(o.lean, text)
|
|
150
|
+
lean = {file: o.lean, lines: text.split('\n').length, theorems: (text.match(/^\s*theorem\s/gm) ?? []).length, sorry: (text.match(/\bsorry\b/g) ?? []).length, leanChecked: false}
|
|
151
|
+
log(`4. Lean export ${o.lean}: ${lean.lines} lines, ${lean.theorems} theorems, ${lean.sorry} sorry (not checked by Lean here)`)
|
|
145
152
|
}
|
|
146
153
|
|
|
147
|
-
const killed = Object.values(
|
|
148
|
-
const total = Object.keys(
|
|
149
|
-
|
|
150
|
-
|
|
154
|
+
const killed = Object.values(mutants).filter((x) => x.killed).length
|
|
155
|
+
const total = Object.keys(mutants).length
|
|
156
|
+
const ok = generated.ok && original.proven === true && original.checked === true && killed === total && total === 10
|
|
157
|
+
const summary = `original proven=${original.proven} checked=${original.checked}; mutants killed ${killed}/${total}; generated step ok=${generated.ok}`
|
|
158
|
+
const out = {...head, generated, original, mutants, ...(lean ? {lean} : {}), ok, summary}
|
|
151
159
|
log(`RESULT: ${out.ok ? 'PASS' : 'FAIL'}: ${out.summary}`)
|
|
152
160
|
if (o.out) writeFileSync(o.out, JSON.stringify(out, null, 1) + '\n')
|
|
153
161
|
return out
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stopbar",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
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",
|
|
@@ -16,11 +16,21 @@
|
|
|
16
16
|
"bin": {
|
|
17
17
|
"stopbar": "bin/stopbar.mjs"
|
|
18
18
|
},
|
|
19
|
+
"exports": {
|
|
20
|
+
"./probe": {
|
|
21
|
+
"types": "./src/probe/sdk.ts",
|
|
22
|
+
"default": "./dist/probe/sdk.js"
|
|
23
|
+
},
|
|
24
|
+
"./package.json": "./package.json"
|
|
25
|
+
},
|
|
19
26
|
"files": [
|
|
20
27
|
"bin/",
|
|
21
|
-
"dist
|
|
28
|
+
"dist/**/*.js",
|
|
29
|
+
"dist/build-info.json",
|
|
22
30
|
"src/kernel.ts",
|
|
31
|
+
"src/probe/sdk.ts",
|
|
23
32
|
"claude-hooks.example.json",
|
|
33
|
+
"skills/",
|
|
24
34
|
"README.md",
|
|
25
35
|
"SECURITY.md",
|
|
26
36
|
"CHANGELOG.md",
|
|
@@ -39,6 +49,7 @@
|
|
|
39
49
|
"verify:lean": "node scripts/build.ts && node scripts/verify-lean.ts",
|
|
40
50
|
"probe": "node scripts/build.ts && node bin/stopbar.mjs probe",
|
|
41
51
|
"bench": "node bench/hook-latency.ts",
|
|
52
|
+
"typecheck": "node scripts/build.ts && tsc --noEmit",
|
|
42
53
|
"prepack": "node scripts/build.ts"
|
|
43
54
|
},
|
|
44
55
|
"keywords": [
|
|
@@ -56,5 +67,9 @@
|
|
|
56
67
|
],
|
|
57
68
|
"dependencies": {
|
|
58
69
|
"gdp-wired": "0.60.0"
|
|
70
|
+
},
|
|
71
|
+
"devDependencies": {
|
|
72
|
+
"@types/node": "24.19.4",
|
|
73
|
+
"typescript": "5.9.3"
|
|
59
74
|
}
|
|
60
75
|
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: stopbar
|
|
3
|
+
description: Load this skill when you work in a repository that Stopbar GATE protects (a `.git/stopbar/` directory, Stopbar hooks, or a Stopbar block message), or when you write a multi-step `stopbar probe` target to the Zero-FP standard.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Stopbar
|
|
7
|
+
|
|
8
|
+
Stopbar is an execution gate for AI coding agents. Its hooks block a commit until the build and the full test suite
|
|
9
|
+
pass at the current tree, block unapproved test changes and block risky or outbound commands after a secret read.
|
|
10
|
+
The hooks check the command text. This skill tells you how to work with them and how to write probes that find only
|
|
11
|
+
real bugs.
|
|
12
|
+
|
|
13
|
+
`<cli>` below is the Stopbar command that the block hints show. The default is `npx --no-install stopbar`; a human can
|
|
14
|
+
set another one with `stopbar init --cli "<cmd>"`.
|
|
15
|
+
|
|
16
|
+
## 1. Working under Stopbar GATE
|
|
17
|
+
|
|
18
|
+
### Gate commands
|
|
19
|
+
|
|
20
|
+
- Run `buildCmd` and `fullTestCmd` exactly as configured: the same text, alone, in the foreground. Do not add `;`,
|
|
21
|
+
`&&`, `||`, `|`, `>`, `2>&1` or `tail`, and do not run them in the background. A changed or chained command is not
|
|
22
|
+
recorded as a gate.
|
|
23
|
+
- A gate that runs longer than 10 minutes: run `<cli> run build` or `<cli> run test`. This form can run in the
|
|
24
|
+
background. Stopbar records the real exit status when the process ends and discards it if the tree changed.
|
|
25
|
+
- Always use `<cli> run build|test` when the config has `requireRun: true` (`--require-run`) and when you are Codex
|
|
26
|
+
CLI (Codex reports no exit status to hooks).
|
|
27
|
+
- Run the build and the full tests again after each change to the tree. A gate counts only at the revision where it
|
|
28
|
+
passed.
|
|
29
|
+
- `<cli> status` is read-only. Use it to see why a commit is blocked. It also shows a change that no hook has counted
|
|
30
|
+
yet; the next hook counts it, and then you run the build and the full tests again.
|
|
31
|
+
|
|
32
|
+
### Commits
|
|
33
|
+
|
|
34
|
+
- One commit is one command: `git commit -m "..."`, or a quoted heredoc:
|
|
35
|
+
|
|
36
|
+
```sh
|
|
37
|
+
git commit -m "$(cat <<'EOF'
|
|
38
|
+
Fix the parser
|
|
39
|
+
|
|
40
|
+
Body text.
|
|
41
|
+
EOF
|
|
42
|
+
)"
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
- Do not chain `git add` and `git commit`. Run them as two commands.
|
|
46
|
+
|
|
47
|
+
### Respect a block
|
|
48
|
+
|
|
49
|
+
- A block is a decision, not an error to work around. Read the reason and fix the cause.
|
|
50
|
+
- Do not bypass a block with a script, a wrapper, a generated file, an alias, `git -c alias.*`, `--no-verify` or
|
|
51
|
+
another git client.
|
|
52
|
+
- Do not edit `.git/` (hooks, `.git/stopbar/`), the hook config of any agent (`.claude/`, `.cursor/`, `.codex/`,
|
|
53
|
+
`.gemini/`, `.agents/`) or the Stopbar package.
|
|
54
|
+
|
|
55
|
+
### Human-only commands
|
|
56
|
+
|
|
57
|
+
`init`, `upgrade`, `approve-tests`, `approve-shell`, `resume` and `reset` belong to the human. Do not run them, do not
|
|
58
|
+
ask a tool or another agent to run them, and do not put them in a script. The hooks block them. `stopbar probe init`
|
|
59
|
+
(section 2) is not `init`: you can run it.
|
|
60
|
+
|
|
61
|
+
Stop and ask the human when one of these is true:
|
|
62
|
+
|
|
63
|
+
| State | Cause | What to report | Human command |
|
|
64
|
+
|---|---|---|---|
|
|
65
|
+
| `testsTainted` | you changed an existing test or test config | the changed test files and why | `stopbar approve-tests` |
|
|
66
|
+
| `secretTainted` | you read a secret file or token | the one risky or outbound call you need and why | `stopbar approve-shell` |
|
|
67
|
+
| `HALT` | retry limit or tool-call budget reached | the last failing gate and its error, in short | `stopbar resume --extra N` |
|
|
68
|
+
|
|
69
|
+
Write the report in a few lines, then wait. In `HALT`, only the tools in `config.safeTools` pass (default
|
|
70
|
+
`mcp__ccd_turn__*` and `mcp__ccd_session_mgmt__*`); use them to tell the human about the block.
|
|
71
|
+
|
|
72
|
+
## 2. Writing Zero-FP stateful probes (`stopbar probe`)
|
|
73
|
+
|
|
74
|
+
A probe runs random multi-step sequences against the system under test (SUT) and compares each step with a model.
|
|
75
|
+
Zero-FP means that every failure is a real bug.
|
|
76
|
+
|
|
77
|
+
### Start
|
|
78
|
+
|
|
79
|
+
```sh
|
|
80
|
+
stopbar probe init --lang ts --name <module> # writes probes/<module>.probe.ts
|
|
81
|
+
stopbar probe init --lang py --name <module> # writes probes/<module>_probe.py
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
- TS/JS: `defineModel` from `stopbar/probe` (`setup`, `actions` with `gen` and `run`, `invariants`, `mutants`). Run
|
|
85
|
+
with `stopbar probe --target probes/<module>.probe.ts`.
|
|
86
|
+
- Python, Go, Rust and other languages: a program that speaks NDJSON on stdin/stdout (`info`, `generate`,
|
|
87
|
+
`execute`). Run with `stopbar probe --cmd "<command>"`. stdout is for the protocol only; print logs to stderr.
|
|
88
|
+
Catch an exception of the SUT in `execute` and answer with a mismatch.
|
|
89
|
+
- Run only a prober that you wrote in this session. A prober file from outside the session (another agent, an earlier
|
|
90
|
+
session, a download) needs a human review before you run it (SECURITY.md section 4). A new prober that you wrote
|
|
91
|
+
needs a human review before its result counts as evidence in `stopbar attest`.
|
|
92
|
+
|
|
93
|
+
### The 5 Zero-FP rules
|
|
94
|
+
|
|
95
|
+
1. **Deterministic `gen`.** Draw arguments only from the seeded generator (`r` in TS, the seed in `generate`) and
|
|
96
|
+
return plain JSON data. The same seed gives the same run on every machine.
|
|
97
|
+
2. **Independent oracle.** The model is a separate, simple reference (an array, a map, a reference formula) plus
|
|
98
|
+
invariants. Never compare the SUT with itself or with a copy of its own code.
|
|
99
|
+
3. **No clock, network or global state.** Write files only in the scratch directory of the run (`dir` in
|
|
100
|
+
`execute`). Reset all state in `setup`. Do not assume a short start or answer time under CPU load: for a slow
|
|
101
|
+
`--cmd` target, set `--cmd-timeout` with a large margin.
|
|
102
|
+
4. **At least 2 realistic mutants.** Each mutant is a small, real bug (a dropped bound check, an off-by-one). Run
|
|
103
|
+
`stopbar probe ... --check-mutants` and make it pass (exit 0, no survivor) before you increase `--runs`. A
|
|
104
|
+
surviving mutant shows a weak model or weak actions; fix the probe, not the mutant.
|
|
105
|
+
5. **Shrink, then reproduce.** On a failure, use the shrunk sequence in `repro-<seed>.json` (in `--out`). Write a
|
|
106
|
+
minimal test that reproduces the bug (less than 25 lines) and look for a known issue or test before you report it.
|
|
107
|
+
Replay the file with `--regressions <dir>` after the fix.
|
|
108
|
+
|
|
109
|
+
### Before you report a finding
|
|
110
|
+
|
|
111
|
+
- Make sure that the model, not the SUT, is correct for the failing step. A model error is a false positive: fix the
|
|
112
|
+
model.
|
|
113
|
+
- Run the reproduction twice with the same seed. A result that changes is a rule 1 or rule 3 error.
|
|
114
|
+
|
|
115
|
+
### After the first finding
|
|
116
|
+
|
|
117
|
+
- Save `repro-<seed>.json`. Then add a switch to the generator that turns off the known bug category for a while, so
|
|
118
|
+
that the original passes and `--check-mutants` can run. Look for the next bug.
|
|
119
|
+
|
|
120
|
+
### Evidence
|
|
121
|
+
|
|
122
|
+
- Run `stopbar probe` in a repository with Stopbar. Each run appends a `probe:result` entry to the event log (target,
|
|
123
|
+
sha256 of the target file, tree snapshot, runs, mutants). Do not pass `--no-record`. The only exception is an
|
|
124
|
+
explicit instruction from a human (for example, an audit that must not add entries to the log).
|
|
125
|
+
- The human or CI collects the evidence with `stopbar attest --format md` or `--format json`. The `Probe evidence`
|
|
126
|
+
section shows the latest result per target and whether the tree is still the one that was probed.
|