stopbar 1.2.0 → 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 +40 -0
- package/README.md +83 -20
- package/SECURITY.md +86 -69
- 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/build-info.json +1 -1
- package/dist/classify.js +174 -10
- package/dist/commands.js +7 -2
- package/dist/doctor.js +46 -21
- package/dist/integrations.js +41 -6
- package/dist/probe/index.js +25 -16
- package/dist/probe/sdk.js +1 -1
- package/dist/probe/stdio.js +25 -13
- package/dist/probe/wrapper.js +1 -1
- package/dist/store.js +1 -1
- package/dist/verify.js +34 -26
- package/package.json +2 -2
- package/src/probe/sdk.ts +2 -2
package/dist/probe/index.js
CHANGED
|
@@ -15,26 +15,28 @@ import {pathToFileURL} from 'node:url'
|
|
|
15
15
|
import {PKG_ROOT} from '../pkg.js'
|
|
16
16
|
import {findRepo, snapshot} from '../repo.js'
|
|
17
17
|
import {appendEvent, paths, readConfig, readState, withLock} from '../store.js'
|
|
18
|
-
|
|
18
|
+
|
|
19
19
|
import {CmdClient, commandFile, ProbeError} from './stdio.js'
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
export {ProbeError} from './stdio.js'
|
|
23
23
|
|
|
24
|
-
export const TARGETS
|
|
24
|
+
export const TARGETS = {
|
|
25
25
|
wrapper: async () => (await import('./wrapper.js')).wrapperTarget,
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
const sha = (b ) => createHash('sha256').update(b).digest('hex')
|
|
29
29
|
|
|
30
|
-
function isTarget(
|
|
31
|
-
|
|
30
|
+
function isTarget(v ) {
|
|
31
|
+
if (!v || typeof v !== 'object') return false
|
|
32
|
+
const x = v
|
|
33
|
+
return typeof x.name === 'string' && !!x.name && typeof x.description === 'string' &&
|
|
32
34
|
typeof x.generate === 'function' && typeof x.execute === 'function' &&
|
|
33
35
|
(x.mutants === undefined || (Array.isArray(x.mutants) && x.mutants.every((m ) => typeof m === 'string')))
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
/** What the runner drives: a ProbeTarget, or a --cmd target whose generate answers asynchronously and that must be closed. */
|
|
37
|
-
|
|
39
|
+
|
|
38
40
|
|
|
39
41
|
|
|
40
42
|
/** A name in TARGETS, else a .ts/.mts/.js/.mjs file (absolute, or relative to `cwd`, then to `repo`) that exports a
|
|
@@ -45,8 +47,8 @@ export async function loadTarget(spec , cwd = process.cwd(), repo
|
|
|
45
47
|
const file = cands.find((f) => existsSync(f))
|
|
46
48
|
if (!file) throw new ProbeError(`probe target ${JSON.stringify(spec)} is neither a known target (${Object.keys(TARGETS).join(', ')}) nor an existing file`)
|
|
47
49
|
if (!/\.(ts|mts|js|mjs)$/.test(file)) throw new ProbeError(`probe target ${file}: the file must end in .ts, .mts, .js or .mjs`)
|
|
48
|
-
let mod
|
|
49
|
-
try { mod = await import(pathToFileURL(file).href)
|
|
50
|
+
let mod
|
|
51
|
+
try { mod = await import(pathToFileURL(file).href) } catch (e) {
|
|
50
52
|
throw new ProbeError(`probe target ${file} does not load: ${(e )?.message ?? e}`)
|
|
51
53
|
}
|
|
52
54
|
const t = isTarget(mod?.default) ? mod.default : isTarget(mod?.target) ? mod.target : null
|
|
@@ -173,8 +175,12 @@ function defaultWork(dir ) {
|
|
|
173
175
|
/** A worker gets its share in a file in `work` (`--worker-file <path>`): the seeds as one argv JSON overflow the command
|
|
174
176
|
* line (Windows ~32 KB, Linux 128 KB per argument) at large --runs or --mutant-runs. The file goes when the worker ends. */
|
|
175
177
|
let workerFiles = 0
|
|
176
|
-
|
|
177
|
-
|
|
178
|
+
/** One result line of a worker (see share): a run or a regression, or a mutant with `mutant` set. */
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
function spawnWorker (p ) {
|
|
183
|
+
return new Promise ((ok, bad) => {
|
|
178
184
|
const file = join(p.work, `worker-${process.pid}-${++workerFiles}.json`)
|
|
179
185
|
writeFileSync(file, JSON.stringify(p))
|
|
180
186
|
const ch = spawn(process.execPath, [join(PKG_ROOT, 'bin', 'stopbar.mjs'), 'probe', '--worker-file', file], {stdio: ['ignore', 'pipe', 'inherit']})
|
|
@@ -183,9 +189,12 @@ function spawnWorker(p ) {
|
|
|
183
189
|
ch.on('error', (e) => { rmSync(file, {force: true}); bad(e) })
|
|
184
190
|
ch.on('exit', (code) => {
|
|
185
191
|
rmSync(file, {force: true, maxRetries: 5})
|
|
186
|
-
let v
|
|
192
|
+
let v
|
|
187
193
|
try { v = JSON.parse(s.trim().split('\n').pop() ) } catch { return bad(new Error(`probe worker exit ${code}: ${s.slice(0, 500)}`)) }
|
|
188
|
-
|
|
194
|
+
const error = v && typeof v === 'object' && !Array.isArray(v) ? (v ).error : undefined
|
|
195
|
+
if (typeof error === 'string') bad(new ProbeError(error))
|
|
196
|
+
else if (Array.isArray(v)) ok(v )
|
|
197
|
+
else bad(new Error(`probe worker exit ${code}: not a result list: ${s.slice(0, 500)}`))
|
|
189
198
|
})
|
|
190
199
|
})
|
|
191
200
|
}
|
|
@@ -239,25 +248,25 @@ async function probeWith(R , o , log ,
|
|
|
239
248
|
const parts = Array.from({length: jobs}, () => ({target: R.spec, ...cmdPart, seeds: [], regs: [], work}))
|
|
240
249
|
seeds.forEach((s, i) => parts[i % jobs].seeds.push(s))
|
|
241
250
|
regs.forEach((f, i) => parts[i % jobs].regs.push(f))
|
|
242
|
-
const results = (await Promise.all(parts.filter((p) => p.seeds.length || p.regs.length).map(spawnWorker))).flat()
|
|
251
|
+
const results = (await Promise.all(parts.filter((p) => p.seeds.length || p.regs.length).map((p) => spawnWorker (p)))).flat()
|
|
243
252
|
.sort((a, b) => (a.regression ? 0 : 1) - (b.regression ? 0 : 1) || a.seed - b.seed)
|
|
244
|
-
const failed = results.filter((r)
|
|
253
|
+
const failed = results.filter((r) => !r.ok)
|
|
245
254
|
for (const f of failed) {
|
|
246
255
|
const file = join(out, `repro-${f.seed}.json`)
|
|
247
256
|
const run = f.minimal ?? f.run ?? await t.generate(f.seed)
|
|
248
257
|
writeFileSync(file, JSON.stringify({target: t.name, ...(R.file ? {targetPath} : {}), ...cmdField, found: new Date().toISOString(), mismatch: f.minimalMismatch ?? f.mismatch, run}, null, 1) + '\n')
|
|
249
258
|
log(`FAIL seed ${f.seed}${f.regression ? ' (regression ' + f.regression + ')' : ''}: ${f.mismatch.what} at step ${f.mismatch.step} ${JSON.stringify(f.mismatch.action)}\n expected ${JSON.stringify(f.mismatch.expected)}\n actual ${JSON.stringify(f.mismatch.actual)}\n ${f.minimal ? 'minimal ' : ''}reproduction (${run.actions.length} steps): ${file}`)
|
|
250
259
|
}
|
|
251
|
-
const ok = results.filter((r)
|
|
260
|
+
const ok = results.filter((r) => r.ok && !r.regression)
|
|
252
261
|
const coverage = {}
|
|
253
|
-
for (const r of ok) for (const [k, v] of Object.entries(r.cov
|
|
262
|
+
for (const r of ok) for (const [k, v] of Object.entries(r.cov)) coverage[k] = (coverage[k] ?? 0) + v
|
|
254
263
|
|
|
255
264
|
// mutants: only on a passing original; each mutant in its own worker, seeds in order, the first failure kills it
|
|
256
265
|
let mutants = null
|
|
257
266
|
if (o.checkMutants && failed.length) log(`mutants: not checked, the original fails`)
|
|
258
267
|
else if (o.checkMutants) {
|
|
259
268
|
const mseeds = Array.from({length: mutantRuns}, (_, i) => seed0 + i)
|
|
260
|
-
const res = (await pool(mutantNames, jobs, (m) => spawnWorker({target: R.spec, ...cmdPart, seeds: mseeds, regs: [], work, mutant: m}))).flat()
|
|
269
|
+
const res = (await pool(mutantNames, jobs, (m) => spawnWorker ({target: R.spec, ...cmdPart, seeds: mseeds, regs: [], work, mutant: m}))).flat()
|
|
261
270
|
const details = res.map((r) => r.killed
|
|
262
271
|
? {name: r.mutant, status: 'KILLED', seed: r.seed, step: r.mismatch.step, what: r.mismatch.what, action: r.mismatch.action, runs: r.tried}
|
|
263
272
|
: {name: r.mutant, status: 'SURVIVED', runs: r.tried})
|
package/dist/probe/sdk.js
CHANGED
package/dist/probe/stdio.js
CHANGED
|
@@ -45,8 +45,9 @@ export function commandFile(cmd , cwd = process.cwd()) {
|
|
|
45
45
|
return null
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
const NAT = (n )
|
|
49
|
-
const
|
|
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)
|
|
50
51
|
|
|
51
52
|
/** One long-lived process of a --cmd target. Requests go one at a time; `close` ends stdin and kills it if needed. */
|
|
52
53
|
export class CmdClient {
|
|
@@ -55,6 +56,7 @@ export class CmdClient {
|
|
|
55
56
|
buf = ''
|
|
56
57
|
err = ''
|
|
57
58
|
exited = null
|
|
59
|
+
killed = false // set by kill(): its 'exit' may never arrive (the child is unref'd)
|
|
58
60
|
waiting = null
|
|
59
61
|
chain = Promise.resolve()
|
|
60
62
|
cwd
|
|
@@ -77,8 +79,8 @@ export class CmdClient {
|
|
|
77
79
|
}
|
|
78
80
|
|
|
79
81
|
start() {
|
|
80
|
-
if (this.ch && this.exited === null) return this.ch
|
|
81
|
-
this.buf = ''; this.err = ''; this.exited = null
|
|
82
|
+
if (this.ch && this.exited === null && !this.killed) return this.ch
|
|
83
|
+
this.buf = ''; this.err = ''; this.exited = null; this.killed = false
|
|
82
84
|
// a shell, so the command line works as typed (python, py -3, npx tsx, a script with a #!)
|
|
83
85
|
const ch = spawn(this.cmd, {cwd: this.cwd, shell: true, stdio: ['pipe', 'pipe', 'pipe'], windowsHide: true, detached: process.platform !== 'win32'})
|
|
84
86
|
this.ch = ch
|
|
@@ -128,7 +130,7 @@ export class CmdClient {
|
|
|
128
130
|
return p
|
|
129
131
|
}
|
|
130
132
|
|
|
131
|
-
async ask(msg )
|
|
133
|
+
async ask(msg ) {
|
|
132
134
|
const v = await this.request(msg)
|
|
133
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()}`)
|
|
134
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)}`)
|
|
@@ -160,11 +162,11 @@ export class CmdClient {
|
|
|
160
162
|
if (!NAT(v.steps)) this.bad('execute', 'steps must be an integer >= 0', v)
|
|
161
163
|
const cov = v.cov ?? {}
|
|
162
164
|
if (!isObj(cov) || !Object.values(cov).every(NAT)) this.bad('execute', 'cov must map names to integers >= 0', v)
|
|
163
|
-
return {ok: true, steps: v.steps, cov}
|
|
165
|
+
return {ok: true, steps: v.steps, cov: cov }
|
|
164
166
|
}
|
|
165
167
|
if (v.ok === false) {
|
|
166
168
|
const m = v.mismatch
|
|
167
|
-
if (!isObj(m) || !
|
|
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)
|
|
168
170
|
return {ok: false, mismatch: {step: m.step, action: m.action ?? null, what: m.what, expected: m.expected ?? null, actual: m.actual ?? null}}
|
|
169
171
|
}
|
|
170
172
|
return this.bad('execute', 'ok must be true or false', v)
|
|
@@ -176,6 +178,7 @@ export class CmdClient {
|
|
|
176
178
|
kill() {
|
|
177
179
|
const ch = this.ch
|
|
178
180
|
if (!ch) return
|
|
181
|
+
this.killed = true
|
|
179
182
|
if (ch.pid !== undefined && this.exited === null) {
|
|
180
183
|
let treeKilled = false
|
|
181
184
|
try {
|
|
@@ -190,18 +193,27 @@ export class CmdClient {
|
|
|
190
193
|
ch.unref()
|
|
191
194
|
}
|
|
192
195
|
|
|
193
|
-
/** Ends stdin (a well-behaved target exits on EOF); kills the process tree after `graceMs`.
|
|
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()`). */
|
|
194
200
|
async close(graceMs = 2000) {
|
|
195
201
|
const ch = this.ch
|
|
196
|
-
|
|
202
|
+
const done = () => this.killed || this.exited !== null || ch .exitCode !== null || ch .signalCode !== null
|
|
203
|
+
if (!ch || done()) return
|
|
197
204
|
await this.chain
|
|
198
|
-
if (
|
|
205
|
+
if (done()) return
|
|
199
206
|
const gone = new Promise ((ok) => ch.once('exit', () => ok()))
|
|
200
207
|
try { ch.stdin .end() } catch { /* already closed */ }
|
|
201
|
-
|
|
202
|
-
if (await Promise.race([gone.then(() => 'gone' ), timer]) === 'late') {
|
|
208
|
+
if (await settle(gone, graceMs) === 'late') {
|
|
203
209
|
this.kill() // destroys the pipes and unrefs the child even when the kill itself fails
|
|
204
|
-
await
|
|
210
|
+
await settle(gone, 1000)
|
|
205
211
|
}
|
|
206
212
|
}
|
|
207
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.2.
|
|
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",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"verify:lean": "node scripts/build.ts && node scripts/verify-lean.ts",
|
|
50
50
|
"probe": "node scripts/build.ts && node bin/stopbar.mjs probe",
|
|
51
51
|
"bench": "node bench/hook-latency.ts",
|
|
52
|
-
"typecheck": "tsc --noEmit",
|
|
52
|
+
"typecheck": "node scripts/build.ts && tsc --noEmit",
|
|
53
53
|
"prepack": "node scripts/build.ts"
|
|
54
54
|
},
|
|
55
55
|
"keywords": [
|
package/src/probe/sdk.ts
CHANGED
|
@@ -118,7 +118,7 @@ export type ActionSpec<S> = {
|
|
|
118
118
|
weight?: number
|
|
119
119
|
/** Arguments of one step: pure data that survives JSON (saved in reproductions and regressions). */
|
|
120
120
|
gen(r: Rng): unknown
|
|
121
|
-
run(state: S, args:
|
|
121
|
+
run(state: S, args: unknown, check: Check): Awaitable<void>
|
|
122
122
|
}
|
|
123
123
|
export type Invariant<S> = ((state: S, check: Check) => Awaitable<void>) | {name: string; check(state: S, check: Check): Awaitable<void>}
|
|
124
124
|
export type MutantSpec<S> = ((ctx: {seed: number; dir: string}) => Awaitable<S>) | {description?: string; setup(ctx: {seed: number; dir: string}): Awaitable<S>}
|
|
@@ -203,7 +203,7 @@ export function defineModel<S>(spec: ModelSpec<S>): ProbeTarget<ModelRun> & {mut
|
|
|
203
203
|
}
|
|
204
204
|
let out: Outcome
|
|
205
205
|
try {
|
|
206
|
-
let setup: (c:
|
|
206
|
+
let setup: (c: Ctx) => Awaitable<S> = spec.setup
|
|
207
207
|
if (mutant !== undefined) {
|
|
208
208
|
const m = mutants.get(mutant)
|
|
209
209
|
if (!m) throw new MismatchError('unknown mutant', [...mutants.keys()], mutant)
|