stopbar 0.0.0-stage → 1.1.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 +47 -0
- package/LICENSE +21 -0
- package/README.md +208 -2
- package/SECURITY.md +139 -0
- package/bin/stopbar.mjs +6 -0
- package/claude-hooks.example.json +27 -0
- package/dist/adapters/antigravity.js +45 -0
- package/dist/adapters/claude.js +19 -0
- package/dist/adapters/codex.js +48 -0
- package/dist/adapters/cursor.js +63 -0
- package/dist/adapters/gemini.js +47 -0
- package/dist/adapters/index.js +45 -0
- package/dist/adapters/types.js +103 -0
- package/dist/attest.js +97 -0
- package/dist/build-info.json +6 -0
- package/dist/classify.js +212 -0
- package/dist/cli.js +88 -0
- package/dist/commands.js +146 -0
- package/dist/config.js +96 -0
- package/dist/doctor.js +185 -0
- package/dist/engine.js +51 -0
- package/dist/githook.js +17 -0
- package/dist/glob.js +68 -0
- package/dist/hook.js +236 -0
- package/dist/integrations.js +141 -0
- package/dist/kernel.gen.js +63 -0
- package/dist/kernel.js +162 -0
- package/dist/pkg.js +13 -0
- package/dist/probe/index.js +119 -0
- package/dist/probe/wrapper.js +311 -0
- package/dist/repo.js +177 -0
- package/dist/run.js +28 -0
- package/dist/store.js +144 -0
- package/dist/verify.js +154 -0
- package/package.json +58 -4
- package/src/kernel.ts +161 -0
package/dist/glob.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// Built from src/glob.ts by scripts/build.ts. Do not edit.
|
|
2
|
+
// Minimal glob matcher for path patterns in config.json. No dependencies.
|
|
3
|
+
// * any characters except '/'
|
|
4
|
+
// ** any number of path segments (also none), only as a whole segment: '**/x', 'a/**', 'a/**/b'
|
|
5
|
+
// ? one character except '/'
|
|
6
|
+
// {a,b} alternatives (no nesting)
|
|
7
|
+
// A pattern without '/' matches the base name of the path (like .gitignore). Matching is case-insensitive:
|
|
8
|
+
// more matches mean more gates, which is the safe direction on case-insensitive file systems.
|
|
9
|
+
|
|
10
|
+
const cache = new Map ()
|
|
11
|
+
|
|
12
|
+
function esc(c ) { return /[\\^$.*+?()[\]{}|/]/.test(c) ? '\\' + c : c }
|
|
13
|
+
|
|
14
|
+
function body(p ) {
|
|
15
|
+
let out = ''
|
|
16
|
+
for (let i = 0; i < p.length; i++) {
|
|
17
|
+
const c = p[i]
|
|
18
|
+
if (c === '*') {
|
|
19
|
+
if (p[i + 1] === '*') {
|
|
20
|
+
const atStart = i === 0 || p[i - 1] === '/'
|
|
21
|
+
const atEnd = i + 2 === p.length || p[i + 2] === '/'
|
|
22
|
+
if (!atStart || !atEnd) throw new Error(`glob ${JSON.stringify(p)}: '**' must be a whole path segment`)
|
|
23
|
+
if (i + 2 === p.length) { out += '.*'; i += 1 } else { out += '(?:[^/]*/)*'; i += 2 }
|
|
24
|
+
continue
|
|
25
|
+
}
|
|
26
|
+
out += '[^/]*'
|
|
27
|
+
} else if (c === '?') {
|
|
28
|
+
out += '[^/]'
|
|
29
|
+
} else if (c === '{') {
|
|
30
|
+
const end = p.indexOf('}', i)
|
|
31
|
+
if (end < 0) throw new Error(`glob ${JSON.stringify(p)}: unclosed '{'`)
|
|
32
|
+
const alts = p.slice(i + 1, end).split(',')
|
|
33
|
+
if (alts.some((a) => a.includes('{'))) throw new Error(`glob ${JSON.stringify(p)}: nested '{' is not supported`)
|
|
34
|
+
out += '(?:' + alts.map(body).join('|') + ')'
|
|
35
|
+
i = end
|
|
36
|
+
} else if (c === '}' ) {
|
|
37
|
+
throw new Error(`glob ${JSON.stringify(p)}: unmatched '}'`)
|
|
38
|
+
} else {
|
|
39
|
+
out += esc(c)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return out
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function globToRegExp(pattern ) {
|
|
46
|
+
let re = cache.get(pattern)
|
|
47
|
+
if (re) return re
|
|
48
|
+
if (typeof pattern !== 'string' || pattern.length === 0) throw new Error('glob pattern must be a non-empty string')
|
|
49
|
+
const p = pattern.replace(/\\/g, '/').replace(/^\.\//, '')
|
|
50
|
+
re = p.includes('/') ? new RegExp('^' + body(p.replace(/^\//, '')) + '$', 'i') : new RegExp('(?:^|/)' + body(p) + '$', 'i')
|
|
51
|
+
cache.set(pattern, re)
|
|
52
|
+
return re
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Path relative to the repository (or absolute), '/' or '\\' separated. */
|
|
56
|
+
export function matchAny(path , patterns ) {
|
|
57
|
+
const s = path.replace(/\\/g, '/').replace(/^\.\//, '')
|
|
58
|
+
for (const p of patterns) if (globToRegExp(p).test(s)) return true
|
|
59
|
+
return false
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Same, but a pattern also matches when it matches any suffix of the path (used for absolute paths). */
|
|
63
|
+
export function matchAnySuffix(path , patterns ) {
|
|
64
|
+
const s = path.replace(/\\/g, '/')
|
|
65
|
+
const parts = s.split('/')
|
|
66
|
+
for (let i = 0; i < parts.length; i++) if (matchAny(parts.slice(i).join('/'), patterns)) return true
|
|
67
|
+
return false
|
|
68
|
+
}
|
package/dist/hook.js
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
// Built from src/hook.ts by scripts/build.ts. Do not edit.
|
|
2
|
+
// Claude Code hooks: PreToolUse, PostToolUse, PostToolUseFailure, Stop. JSON on stdin; exit 0 = allow,
|
|
3
|
+
// exit 2 = block (stderr goes to the agent). Any wrapper error is exit 2 (fail closed).
|
|
4
|
+
import {existsSync} from 'node:fs'
|
|
5
|
+
import {resolve} from 'node:path'
|
|
6
|
+
import * as K from './classify.js'
|
|
7
|
+
import { DEFAULT_SAFE_TOOLS} from './config.js'
|
|
8
|
+
import {matchAny} from './glob.js'
|
|
9
|
+
import {decode, kstep, } from './engine.js'
|
|
10
|
+
import {changesSinceHead, countedEntries, diffEntries, differsFromHead, FailClosed, findRepo, gitCalls, inHead, markCounted, snapshot} from './repo.js'
|
|
11
|
+
import {appendEvent, readConfig, readState, withLock, writeState} from './store.js'
|
|
12
|
+
import {codeDirs} from './pkg.js'
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
const EDIT_TOOLS = new Set(['Edit', 'Write', 'MultiEdit', 'NotebookEdit'])
|
|
18
|
+
const READ_TOOLS = new Set(['Read', 'Grep', 'Glob', 'LS'])
|
|
19
|
+
const SHELL_TOOLS = new Set(['Bash', 'PowerShell'])
|
|
20
|
+
const OUTBOUND = (t ) => t === 'WebFetch' || t === 'WebSearch' || t.startsWith('mcp__')
|
|
21
|
+
|
|
22
|
+
function step(ctx , req , source , extra = {}) {
|
|
23
|
+
const before = decode(ctx.s.kernel)
|
|
24
|
+
ctx.s.kernel = kstep(ctx.s.params, ctx.s.kernel, req)
|
|
25
|
+
ctx.dirty = true
|
|
26
|
+
const after = decode(ctx.s.kernel)
|
|
27
|
+
appendEvent(ctx.repo, {source, req, decision: after.decision, halted: after.halted, testsTainted: after.testsTainted,
|
|
28
|
+
secretTainted: after.secretTainted, shellToken: after.shellToken, treeRev: after.treeRev, buildOkRev: after.buildOkRev,
|
|
29
|
+
testsOkRev: after.testsOkRev, spent: after.spent, capNow: after.capNow, testFails: after.testFails, buildFails: after.buildFails,
|
|
30
|
+
commitExecuted: after.commitExecuted, ...extra})
|
|
31
|
+
return {before, after}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function whyBlocked(v , cfg ) {
|
|
35
|
+
const r = []
|
|
36
|
+
if (v.buildOkRev !== v.treeRev) r.push(`no passing build at revision ${v.treeRev} (run \`${cfg.buildCmd}\` exactly, alone, or \`npx stopbar run build\`)`)
|
|
37
|
+
if (v.testsOkRev !== v.treeRev) r.push(`no passing FULL test suite at revision ${v.treeRev} (run \`${cfg.fullTestCmd}\` exactly, alone, or \`npx stopbar run test\`)`)
|
|
38
|
+
if (v.testsTainted) r.push(`existing tests or test config changed: a human must review and run \`stopbar approve-tests --rev ${v.treeRev}\``)
|
|
39
|
+
return r.join('; ') || 'kernel decision'
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Counts a working-tree change the kernel has not seen yet. */
|
|
43
|
+
function syncTree(ctx , cost , source ) {
|
|
44
|
+
const {repo, s, cfg} = ctx
|
|
45
|
+
const snap = snapshot(repo)
|
|
46
|
+
ctx.now = snap
|
|
47
|
+
if (snap.id === s.snapshot) return null
|
|
48
|
+
const base = countedEntries(repo, s.snapshot)
|
|
49
|
+
let changes
|
|
50
|
+
if (base) changes = diffEntries(base, snap.entries)
|
|
51
|
+
else {
|
|
52
|
+
// the copy of the last counted snapshot is gone or damaged: compare with HEAD instead (more changes, never fewer)
|
|
53
|
+
changes = changesSinceHead(repo, snap.entries)
|
|
54
|
+
appendEvent(repo, {source: `${source}:fallback-diff`, note: 'counted snapshot copy missing; diff against HEAD'})
|
|
55
|
+
}
|
|
56
|
+
const testPaths = changes.map((c) => c.path).filter((p) => K.isTestPath(p, cfg.paths) && !K.isTestConfigPath(p, cfg.paths))
|
|
57
|
+
const head = testPaths.length ? inHead(repo.root, testPaths) : new Set ()
|
|
58
|
+
const cls = K.classifyTreeChange(changes, (p) => head.has(p), cfg.paths)
|
|
59
|
+
const {before, after} = step(ctx, {op: cls.op, suspicious: cls.suspicious, cost}, `${source}:tree ${cls.why.join(', ') || `${changes.length} file(s)`}`)
|
|
60
|
+
// not executed (halted or over budget): the change stays pending and is counted later
|
|
61
|
+
if (after.treeRev > before.treeRev) { s.snapshot = snap.id; markCounted(repo); ctx.dirty = true }
|
|
62
|
+
return {cls, after}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const block = (reason ) => ({code: 2, msg: `BLOCK (stopbar): ${reason}`})
|
|
66
|
+
|
|
67
|
+
// ---------------------------------------------------------------- PreToolUse
|
|
68
|
+
function pre(ctx , input ) {
|
|
69
|
+
const tool = String(input.tool_name ?? ''), ti = input.tool_input ?? {}
|
|
70
|
+
const {repo, cfg} = ctx
|
|
71
|
+
// self-protection: unconditional, before the kernel, also when halted
|
|
72
|
+
if (EDIT_TOOLS.has(tool)) {
|
|
73
|
+
const list = [ti.file_path, ti.notebook_path, ti.path, ...(Array.isArray(ti.file_paths) ? ti.file_paths : [])]
|
|
74
|
+
for (const p of list.filter((x) => typeof x === 'string' && x)) {
|
|
75
|
+
const why = K.protectedPath(resolve(repo.root, p), repo.root, ctx.protect)
|
|
76
|
+
if (why) { appendEvent(repo, {source: 'pre', tool, wrapper: 'BLOCK', reason: why, path: p}); return block(`writing ${p} is not allowed: ${why}. Ask the human.`) }
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (SHELL_TOOLS.has(tool)) {
|
|
80
|
+
const cmd = String(ti.command ?? '')
|
|
81
|
+
const hd = tool === 'Bash' ? K.parseSafeHeredocCommit(cmd.trim()) : null
|
|
82
|
+
const why = K.protectedCommand(hd ? hd.prefix : cmd, ctx.protect)
|
|
83
|
+
if (why) { appendEvent(repo, {source: 'pre', tool, wrapper: 'BLOCK', reason: why}); return block(`${why}. Ask the human.`) }
|
|
84
|
+
}
|
|
85
|
+
const v = decode(ctx.s.kernel)
|
|
86
|
+
if (v.halted) {
|
|
87
|
+
appendEvent(repo, {source: 'pre', tool, wrapper: 'PAUSE', reason: 'halted'})
|
|
88
|
+
return {code: 2, msg: `PAUSE (stopbar): the session is halted (testFails=${v.testFails}, buildFails=${v.buildFails}, spent=${v.spent}/${v.capNow}). A human must run: stopbar resume --extra <n>`}
|
|
89
|
+
}
|
|
90
|
+
const cost = cfg.costPerCall
|
|
91
|
+
if (READ_TOOLS.has(tool)) {
|
|
92
|
+
const ps = [ti.file_path, ti.path, ti.glob, ti.pattern, ...(Array.isArray(ti.file_paths) ? ti.file_paths : [])].filter((x) => typeof x === 'string' && x)
|
|
93
|
+
for (const p of ps) {
|
|
94
|
+
const pattern = K.secretPattern(p, cfg.paths)
|
|
95
|
+
if (pattern) { step(ctx, {op: 'READ_SECRET', cost}, `pre:${tool}`, {secret: {pattern, path: p, tool}}); break }
|
|
96
|
+
}
|
|
97
|
+
return {code: 0}
|
|
98
|
+
}
|
|
99
|
+
if (EDIT_TOOLS.has(tool)) return {code: 0} // cost and tree change are counted in PostToolUse
|
|
100
|
+
if (SHELL_TOOLS.has(tool)) {
|
|
101
|
+
const cmd = String(ti.command ?? '')
|
|
102
|
+
const base = typeof input.cwd === 'string' && input.cwd ? input.cwd : repo.root
|
|
103
|
+
const exists = (t ) => existsSync(resolve(base, t)) || existsSync(resolve(repo.root, t))
|
|
104
|
+
const k = K.classifyBash(cmd, cfg, tool === 'PowerShell' ? 'powershell' : 'bash', exists)
|
|
105
|
+
if (k.kind === 'commit-chained') {
|
|
106
|
+
appendEvent(repo, {source: 'pre', tool, wrapper: 'BLOCK', reason: `chained commit (${k.reason})`})
|
|
107
|
+
return block(`run \`git commit\` / \`git push\` as a single command (${k.reason}): no &&, ;, |, redirections or $(...). ` +
|
|
108
|
+
`For a multi-line message use -m "..." or exactly: git commit -m "$(cat <<'EOF'\\n<message>\\nEOF\\n)" with the quoted 'EOF' delimiter and nothing else in the command.`)
|
|
109
|
+
}
|
|
110
|
+
if (k.kind === 'gate-chained') {
|
|
111
|
+
appendEvent(repo, {source: 'pre', tool, wrapper: 'BLOCK', reason: `chained gate command (${k.reason})`})
|
|
112
|
+
return block(`run \`${k.gate}\` exactly as configured, alone: no ;, &&, ||, |, redirections or $(...). Chained operators hide its exit status.`)
|
|
113
|
+
}
|
|
114
|
+
if (k.kind === 'build' || k.kind === 'fulltest') return {code: 0} // the result is recorded in PostToolUse
|
|
115
|
+
if (k.kind === 'commit') {
|
|
116
|
+
syncTree(ctx, 0, 'pre:commit-sync') // a change nobody reported (background job, human edit) is counted first
|
|
117
|
+
const {after} = step(ctx, {op: 'COMMIT', cost}, `pre:${tool}:commit${k.heredoc ? ':heredoc' : ''}`)
|
|
118
|
+
if (after.decision !== 'ALLOW') return {code: 2, msg: `${after.decision} (stopbar): commit refused: ${after.halted ? 'session halted' : whyBlocked(after, cfg)}`}
|
|
119
|
+
if (k.push) {
|
|
120
|
+
const r = step(ctx, {op: 'SHELL', risky: true}, `pre:${tool}:push`)
|
|
121
|
+
if (r.after.decision === 'PAUSE') return {code: 2, msg: 'PAUSE (stopbar): git push after a secret was read; a human must run `stopbar approve-shell`'}
|
|
122
|
+
}
|
|
123
|
+
return {code: 0}
|
|
124
|
+
}
|
|
125
|
+
if (k.secret) step(ctx, {op: 'READ_SECRET'}, `pre:${tool}:secret-mention`, {secret: {pattern: k.secret.pattern, path: k.secret.token, tool}})
|
|
126
|
+
const {after} = step(ctx, {op: 'SHELL', risky: k.risky, cost}, `pre:${tool}`)
|
|
127
|
+
if (after.decision === 'PAUSE') {
|
|
128
|
+
return {code: 2, msg: after.halted ? 'PAUSE (stopbar): budget reached; a human must run `stopbar resume --extra <n>`'
|
|
129
|
+
: 'PAUSE (stopbar): risky or outbound command after a secret was read; a human must run `stopbar approve-shell` (one call)'}
|
|
130
|
+
}
|
|
131
|
+
return {code: 0}
|
|
132
|
+
}
|
|
133
|
+
if (OUTBOUND(tool)) {
|
|
134
|
+
if (matchAny(tool, cfg.safeTools ?? DEFAULT_SAFE_TOOLS)) return {code: 0} // local tools listed in config.safeTools
|
|
135
|
+
const {after} = step(ctx, {op: 'SHELL', risky: true, cost}, `pre:${tool}`)
|
|
136
|
+
if (after.decision === 'PAUSE') return {code: 2, msg: `PAUSE (stopbar): ${tool} is outbound and a secret was read (or the budget is spent); a human runs \`stopbar approve-shell\` or \`stopbar resume\``}
|
|
137
|
+
}
|
|
138
|
+
return {code: 0}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// ---------------------------------------------------------------- PostToolUse / PostToolUseFailure
|
|
142
|
+
// Claude Code sends PostToolUse after success and PostToolUseFailure after an error (non-zero exit of Bash).
|
|
143
|
+
// PostToolUse carries no exit code: success unless is_error / interrupted. Failure is the event type itself.
|
|
144
|
+
function exitCodeOf(tr ) {
|
|
145
|
+
if (!tr || typeof tr !== 'object') return undefined
|
|
146
|
+
for (const k of ['exitCode', 'exit_code', 'returnCode', 'code']) if (typeof tr[k] === 'number') return tr[k]
|
|
147
|
+
return undefined
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function post(ctx , input , failure ) {
|
|
151
|
+
const tool = String(input.tool_name ?? ''), ti = input.tool_input ?? {}
|
|
152
|
+
const {repo, cfg} = ctx
|
|
153
|
+
const msgs = []
|
|
154
|
+
if (SHELL_TOOLS.has(tool)) {
|
|
155
|
+
const k = K.classifyBash(String(ti.command ?? ''), cfg, tool === 'PowerShell' ? 'powershell' : 'bash')
|
|
156
|
+
const tr = input.tool_response
|
|
157
|
+
const meta = input.stopbar ?? {}
|
|
158
|
+
appendEvent(repo, {source: `payload:${input.hook_event_name}`, tool, ...(meta.adapter ? {adapter: meta.adapter, rawKeys: meta.rawKeys} : {inputKeys: Object.keys(input)}),
|
|
159
|
+
toolResponseKeys: tr && typeof tr === 'object' ? Object.keys(tr) : typeof tr})
|
|
160
|
+
const code = exitCodeOf(tr)
|
|
161
|
+
const flagged = input.is_error === true || tr?.is_error === true || tr?.interrupted === true
|
|
162
|
+
// some clients send the same post event for success and failure: then only an explicit exit code 0 is a pass
|
|
163
|
+
const unknown = meta.requireExitCode === true && code === undefined
|
|
164
|
+
const passed = failure ? false : code !== undefined ? code === 0 : !flagged && !unknown
|
|
165
|
+
const note = failure ? ' (PostToolUseFailure)' : code !== undefined ? ` (exit ${code})` : unknown ? ' (no exit code: not counted as a pass)' : ` (no exit code; is_error/interrupted=${flagged})`
|
|
166
|
+
if (failure && input.is_interrupt === true) {
|
|
167
|
+
// Ctrl+C by the user: not a failed gate and not a retry; the tree is still checked below
|
|
168
|
+
appendEvent(repo, {source: 'post:user-interrupt', tool, kind: k.kind})
|
|
169
|
+
} else if (!failure && unknown && (k.kind === 'build' || k.kind === 'fulltest' || (k.kind === 'shell' && k.partialTests))) {
|
|
170
|
+
// no exit status in the client's post event: neither a pass nor a failure is recorded (no evidence either way)
|
|
171
|
+
appendEvent(repo, {source: 'post:gate-without-exit-code', tool, kind: k.kind})
|
|
172
|
+
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 \`npx stopbar run ${k.kind === 'build' ? 'build' : 'test'}\` instead: it runs the same command and records its real exit status.`)
|
|
173
|
+
} else if (k.kind === 'build') {
|
|
174
|
+
step(ctx, {op: 'RUN_BUILD', passed, cost: cfg.costPerCall}, `post:build${note}`)
|
|
175
|
+
} else if (k.kind === 'fulltest') {
|
|
176
|
+
step(ctx, {op: 'RUN_TESTS', passed, fullSuite: true, cost: cfg.costPerCall}, `post:fulltest${note}`)
|
|
177
|
+
} else if (k.kind === 'shell' && k.partialTests) {
|
|
178
|
+
step(ctx, {op: 'RUN_TESTS', passed, fullSuite: false}, `post:partial-tests${note}`)
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
if (SHELL_TOOLS.has(tool) || EDIT_TOOLS.has(tool)) {
|
|
182
|
+
// after SHELL the cost was paid in PreToolUse; an edit pays here
|
|
183
|
+
const r = syncTree(ctx, EDIT_TOOLS.has(tool) ? cfg.costPerCall : 0, `post:${tool}`)
|
|
184
|
+
if (r?.cls.suspicious) msgs.push(`PAUSE (stopbar): existing tests or test config changed (${r.cls.why.join(', ')}). Commit is blocked until a human reviews the change and runs \`stopbar approve-tests\`.`)
|
|
185
|
+
}
|
|
186
|
+
const v = decode(ctx.s.kernel)
|
|
187
|
+
if (v.halted) msgs.push(`PAUSE (stopbar): session halted (testFails=${v.testFails}, buildFails=${v.buildFails}, spent=${v.spent}/${v.capNow}). A human must run \`stopbar resume --extra <n>\`.`)
|
|
188
|
+
return msgs.length ? {code: 2, msg: msgs.join('\n')} : {code: 0}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// ---------------------------------------------------------------- Stop: "I am done" = the COMMIT gate when the tree differs from HEAD
|
|
192
|
+
function stop(ctx , input ) {
|
|
193
|
+
if (input.stop_hook_active) return {code: 0}
|
|
194
|
+
syncTree(ctx, 0, 'stop:sync')
|
|
195
|
+
if (!differsFromHead(ctx.repo, ctx.now .entries)) return {code: 0}
|
|
196
|
+
const {after} = step(ctx, {op: 'COMMIT'}, 'stop:declare-done')
|
|
197
|
+
return after.decision === 'ALLOW' ? {code: 0}
|
|
198
|
+
: {code: 2, msg: `Not done (stopbar): uncommitted changes and ${after.halted ? 'the session is halted' : whyBlocked(after, ctx.cfg)}.`}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// ---------------------------------------------------------------- entry
|
|
202
|
+
export function failMsg(e ) {
|
|
203
|
+
if (e instanceof FailClosed) return `STOPBAR FAIL-CLOSED: ${e.message}${e.fix ? `\nFix: ${e.fix}` : ''}`
|
|
204
|
+
return `STOPBAR FAIL-CLOSED: ${e instanceof Error ? e.message : String(e)}`
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** One hook call with Claude Code's JSON on stdin (the v1.0 interface). Never throws. */
|
|
208
|
+
export function runHook(raw , t0 = performance.now()) {
|
|
209
|
+
let input
|
|
210
|
+
try { input = JSON.parse(raw) } catch (e) { return {code: 2, msg: `STOPBAR FAIL-CLOSED: hook input is not JSON (${(e ).message})`} }
|
|
211
|
+
if (!input || typeof input !== 'object') return {code: 2, msg: 'STOPBAR FAIL-CLOSED: hook input must be a JSON object'}
|
|
212
|
+
return runEvent(input, t0)
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** One normalised hook event (Claude Code's shape; adapters translate other clients into it). Never throws. */
|
|
216
|
+
export function runEvent(input , t0 = performance.now()) {
|
|
217
|
+
try {
|
|
218
|
+
const repo = findRepo(typeof input.cwd === 'string' && input.cwd ? input.cwd : process.cwd())
|
|
219
|
+
const g0 = gitCalls
|
|
220
|
+
return withLock(repo, () => {
|
|
221
|
+
const cfg = readConfig(repo)
|
|
222
|
+
const ctx = {repo, cfg, s: readState(repo), protect: {gitDir: repo.gitDir, stateDir: repo.stateDir, codeDirs: codeDirs()}, dirty: false}
|
|
223
|
+
const ev = input.hook_event_name
|
|
224
|
+
const res = ev === 'PreToolUse' ? pre(ctx, input)
|
|
225
|
+
: ev === 'PostToolUse' ? post(ctx, input, false)
|
|
226
|
+
: ev === 'PostToolUseFailure' ? post(ctx, input, true)
|
|
227
|
+
: ev === 'Stop' ? stop(ctx, input) : {code: 0}
|
|
228
|
+
if (ctx.dirty) writeState(repo, ctx.s)
|
|
229
|
+
appendEvent(repo, {source: 'hook-timing', event: ev, tool: input.tool_name, ...(input.stopbar?.adapter ? {adapter: input.stopbar.adapter} : {}), exit: res.code, gitCalls: gitCalls - g0,
|
|
230
|
+
handlerMs: Math.round(performance.now() - t0), processMs: Math.round(process.uptime() * 1000)})
|
|
231
|
+
return res
|
|
232
|
+
})
|
|
233
|
+
} catch (e) {
|
|
234
|
+
return {code: 2, msg: failMsg(e)}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// Built from src/integrations.ts by scripts/build.ts. Do not edit.
|
|
2
|
+
// `stopbar init --hooks <targets>`: writes the hook configuration of each client, merging into existing files (other keys
|
|
3
|
+
// and other hooks stay; earlier Stopbar entries are replaced). Targets: claude (alias local), claude-project (alias
|
|
4
|
+
// project), cursor, codex, gemini, antigravity (alias agy), git; several at once, comma separated.
|
|
5
|
+
import {chmodSync, existsSync, mkdirSync, readFileSync, renameSync, writeFileSync} from 'node:fs'
|
|
6
|
+
import {dirname, isAbsolute, join, resolve} from 'node:path'
|
|
7
|
+
import {FailClosed, git, } from './repo.js'
|
|
8
|
+
|
|
9
|
+
export const TARGETS = ['claude', 'claude-project', 'cursor', 'codex', 'gemini', 'antigravity', 'git']
|
|
10
|
+
|
|
11
|
+
const ALIAS = {local: 'claude', project: 'claude-project', agy: 'antigravity'}
|
|
12
|
+
|
|
13
|
+
export function parseTargets(s ) {
|
|
14
|
+
const out = []
|
|
15
|
+
for (const raw of s.split(',').map((x) => x.trim()).filter(Boolean)) {
|
|
16
|
+
const t = (ALIAS[raw] ?? raw)
|
|
17
|
+
if (!TARGETS.includes(t)) throw new FailClosed(`unknown --hooks target ${JSON.stringify(raw)}; known: ${TARGETS.join(', ')} (aliases: local, project, agy)`)
|
|
18
|
+
if (!out.includes(t)) out.push(t)
|
|
19
|
+
}
|
|
20
|
+
if (!out.length) throw new FailClosed('--hooks needs at least one target')
|
|
21
|
+
return out
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const STOPBAR_HOOK = /stopbar(\.mjs)?\\?"?\s+(hook|git-hook)\b/
|
|
25
|
+
export const hookCommand = (runtimeRoot , adapter ) =>
|
|
26
|
+
`node "${join(runtimeRoot, 'bin', 'stopbar.mjs').replace(/\\/g, '/')}" hook${adapter ? ` --adapter ${adapter}` : ''}`
|
|
27
|
+
|
|
28
|
+
export const CLAUDE_POST_MATCHER = 'Edit|Write|MultiEdit|NotebookEdit|Bash|PowerShell'
|
|
29
|
+
export function claudeHooks(command ) {
|
|
30
|
+
const h = (timeout ) => [{type: 'command', command, timeout}]
|
|
31
|
+
return {
|
|
32
|
+
PreToolUse: [{matcher: '*', hooks: h(30)}],
|
|
33
|
+
PostToolUse: [{matcher: CLAUDE_POST_MATCHER, hooks: h(60)}],
|
|
34
|
+
PostToolUseFailure: [{matcher: CLAUDE_POST_MATCHER, hooks: h(60)}],
|
|
35
|
+
Stop: [{hooks: h(30)}],
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function readJson(f ) {
|
|
40
|
+
if (!existsSync(f)) return {}
|
|
41
|
+
const raw = readFileSync(f, 'utf8')
|
|
42
|
+
try { return raw.trim() ? JSON.parse(raw) : {} } catch (e) {
|
|
43
|
+
throw new FailClosed(`${f} is not valid JSON (${(e ).message}); not overwriting it`, 'fix the file by hand, then run init again')
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function writeJson(f , o ) { mkdirSync(dirname(f), {recursive: true}); writeFileSync(f, JSON.stringify(o, null, 2) + '\n') }
|
|
47
|
+
const mentions = (x ) => STOPBAR_HOOK.test(JSON.stringify(x ?? ''))
|
|
48
|
+
/** Event arrays: drop earlier Stopbar entries, append ours. */
|
|
49
|
+
function mergeEvents(hooks , want ) {
|
|
50
|
+
for (const [ev, entries] of Object.entries(want)) {
|
|
51
|
+
const kept = Array.isArray(hooks[ev]) ? hooks[ev].filter((x ) => !mentions(x)) : []
|
|
52
|
+
hooks[ev] = [...kept, ...entries]
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function claudeFile(root , file , command ) {
|
|
57
|
+
const f = join(root, '.claude', file)
|
|
58
|
+
const cur = readJson(f)
|
|
59
|
+
cur.hooks = cur.hooks && typeof cur.hooks === 'object' ? cur.hooks : {}
|
|
60
|
+
mergeEvents(cur.hooks, claudeHooks(command))
|
|
61
|
+
writeJson(f, cur)
|
|
62
|
+
return f
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function cursorFile(root , command ) {
|
|
66
|
+
const f = join(root, '.cursor', 'hooks.json')
|
|
67
|
+
const cur = readJson(f)
|
|
68
|
+
cur.version = cur.version ?? 1
|
|
69
|
+
cur.hooks = cur.hooks && typeof cur.hooks === 'object' ? cur.hooks : {}
|
|
70
|
+
const e = (timeout ) => [{command, timeout, failClosed: true}]
|
|
71
|
+
mergeEvents(cur.hooks, {preToolUse: e(30), postToolUse: e(60), postToolUseFailure: e(60), stop: e(30)})
|
|
72
|
+
writeJson(f, cur)
|
|
73
|
+
return f
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function codexFile(root , command ) {
|
|
77
|
+
const f = join(root, '.codex', 'hooks.json')
|
|
78
|
+
const cur = readJson(f)
|
|
79
|
+
cur.hooks = cur.hooks && typeof cur.hooks === 'object' ? cur.hooks : {}
|
|
80
|
+
const h = (timeout ) => [{hooks: [{type: 'command', command, timeout}]}]
|
|
81
|
+
mergeEvents(cur.hooks, {PreToolUse: h(30), PostToolUse: h(60), Stop: h(30)})
|
|
82
|
+
writeJson(f, cur)
|
|
83
|
+
return f
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function geminiFile(root , command ) {
|
|
87
|
+
const f = join(root, '.gemini', 'settings.json')
|
|
88
|
+
const cur = readJson(f)
|
|
89
|
+
cur.hooks = cur.hooks && typeof cur.hooks === 'object' ? cur.hooks : {}
|
|
90
|
+
const h = (timeout ) => [{matcher: '*', hooks: [{name: 'stopbar', type: 'command', command, timeout}]}]
|
|
91
|
+
mergeEvents(cur.hooks, {BeforeTool: h(30000), AfterTool: h(60000), AfterAgent: h(30000)})
|
|
92
|
+
writeJson(f, cur)
|
|
93
|
+
return f
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function antigravityFile(root , command ) {
|
|
97
|
+
const f = join(root, '.agents', 'hooks.json')
|
|
98
|
+
const cur = readJson(f)
|
|
99
|
+
cur.stopbar = {
|
|
100
|
+
PreToolUse: [{matcher: '*', hooks: [{type: 'command', command, timeout: 30}]}],
|
|
101
|
+
PostToolUse: [{matcher: '*', hooks: [{type: 'command', command, timeout: 60}]}],
|
|
102
|
+
Stop: [{type: 'command', command, timeout: 30}],
|
|
103
|
+
}
|
|
104
|
+
writeJson(f, cur)
|
|
105
|
+
return f
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function gitHooks(repo , runtimeRoot , force ) {
|
|
109
|
+
const rel = git(repo.root, ['rev-parse', '--git-path', 'hooks'])
|
|
110
|
+
const dir = isAbsolute(rel) ? rel : resolve(repo.root, rel)
|
|
111
|
+
mkdirSync(dir, {recursive: true})
|
|
112
|
+
const bin = join(runtimeRoot, 'bin', 'stopbar.mjs').replace(/\\/g, '/')
|
|
113
|
+
const out = []
|
|
114
|
+
for (const name of ['pre-commit', 'pre-push']) {
|
|
115
|
+
const f = join(dir, name)
|
|
116
|
+
const body = `#!/bin/sh\n# Stopbar fallback gate, written by \`stopbar init --hooks git\`.\nexec node "${bin}" git-hook ${name}\n`
|
|
117
|
+
if (existsSync(f) && !readFileSync(f, 'utf8').includes('stopbar.mjs" git-hook')) {
|
|
118
|
+
if (!force) throw new FailClosed(`${f} exists and is not a Stopbar hook; not overwriting it`, 'remove it, chain it by hand, or run init again with --force-hooks (the old hook is kept as <name>.stopbar-backup)')
|
|
119
|
+
renameSync(f, `${f}.stopbar-backup`)
|
|
120
|
+
}
|
|
121
|
+
writeFileSync(f, body)
|
|
122
|
+
chmodSync(f, 0o755)
|
|
123
|
+
out.push(f)
|
|
124
|
+
}
|
|
125
|
+
return out
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Installs every target; returns one line per written file. */
|
|
129
|
+
export function installHooks(repo , targets , runtimeRoot , force ) {
|
|
130
|
+
const lines = []
|
|
131
|
+
for (const t of targets) {
|
|
132
|
+
if (t === 'claude') lines.push(`claude: ${claudeFile(repo.root, 'settings.local.json', hookCommand(runtimeRoot))}`)
|
|
133
|
+
else if (t === 'claude-project') lines.push(`claude: ${claudeFile(repo.root, 'settings.json', hookCommand(runtimeRoot))}`)
|
|
134
|
+
else if (t === 'cursor') lines.push(`cursor: ${cursorFile(repo.root, hookCommand(runtimeRoot, 'cursor'))}`)
|
|
135
|
+
else if (t === 'codex') lines.push(`codex: ${codexFile(repo.root, hookCommand(runtimeRoot, 'codex'))}`)
|
|
136
|
+
else if (t === 'gemini') lines.push(`gemini: ${geminiFile(repo.root, hookCommand(runtimeRoot, 'gemini'))}`)
|
|
137
|
+
else if (t === 'antigravity') lines.push(`antigravity: ${antigravityFile(repo.root, hookCommand(runtimeRoot, 'antigravity'))}`)
|
|
138
|
+
else if (t === 'git') for (const f of gitHooks(repo, runtimeRoot, force)) lines.push(`git: ${f}`)
|
|
139
|
+
}
|
|
140
|
+
return lines
|
|
141
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// GENERATED by scripts/build.ts from src/kernel.ts with gdp-wired 0.60.0 compileJs. Do not edit.
|
|
2
|
+
// stopbar verify and the tests regenerate it and compare: KERNEL_SOURCE_SHA256 = sha256(src/kernel.ts),
|
|
3
|
+
// MACHINE_SHA256 = sha256(compileJs output below).
|
|
4
|
+
export const MACHINE_NAME = "stopbar_kernel_none"
|
|
5
|
+
export const KERNEL_SOURCE_SHA256 = "c602fc4bcf8ffb2e312bf838986e6d4b006af6d0e6c7447c8c61d5888adc5ef8"
|
|
6
|
+
export const MACHINE_SHA256 = "b397085e0cb13e2e50aa655c54de0744d08f2ebf500bf32af8ff3e8a11ba7321"
|
|
7
|
+
export const CODEC = {"inputs":[{"name":"op","kind":"oneOf","values":["EDIT_CODE","EDIT_TEST","RUN_BUILD","RUN_TESTS","READ_SECRET","SHELL","APPROVE_TESTS","APPROVE_SHELL","RESUME","COMMIT"]},{"name":"cost","kind":"nat"},{"name":"passed","kind":"bool"},{"name":"fullSuite","kind":"bool"},{"name":"suspicious","kind":"bool"},{"name":"risky","kind":"bool"},{"name":"treeChanged","kind":"bool"},{"name":"approveRev","kind":"nat"},{"name":"extra","kind":"nat"}],"state":[{"name":"treeRev","kind":"nat"},{"name":"buildOkRev","kind":"nat"},{"name":"testsOkRev","kind":"nat"},{"name":"testsTainted","kind":"bool"},{"name":"secretTainted","kind":"bool"},{"name":"shellToken","kind":"bool"},{"name":"buildFails","kind":"nat"},{"name":"testFails","kind":"nat"},{"name":"spent","kind":"nat"},{"name":"capNow","kind":"nat"},{"name":"halted","kind":"bool"},{"name":"decision","kind":"oneOf","values":["ALLOW","BLOCK","PAUSE"]},{"name":"commitExecuted","kind":"bool"},{"name":"gRev","kind":"nat"},{"name":"gBuildOk","kind":"bool"},{"name":"gTestsOk","kind":"bool"},{"name":"gMaxSusp","kind":"nat"},{"name":"gMaxAppr","kind":"nat"},{"name":"gBuildFails","kind":"nat"},{"name":"gTestFails","kind":"nat"}]}
|
|
8
|
+
// ---- compileJs output (unchanged) ----
|
|
9
|
+
// Generated from the machine stopbar_kernel_none. step consumes its state: keep the one it returns (fork to branch).
|
|
10
|
+
function $n(v, what) { if (typeof v !== 'number' || !Number.isSafeInteger(v) || v < 0) throw new RangeError(what + ' must be a natural below 2^53, not ' + v); return v; }
|
|
11
|
+
function $x(v) { if (v > 9007199254740991) throw new RangeError('a value passed 2^53 - 1, past which the proofs over the naturals no longer describe the run'); return v; }
|
|
12
|
+
const $wordDivisionValue = function wordDivisionValue(width, part, index, values) {
|
|
13
|
+
if (width !== 8 && width !== 16 && width !== 32 && width !== 64)
|
|
14
|
+
throw new Error('invalid word division width');
|
|
15
|
+
const n = width === 8 ? 1 : width / 16;
|
|
16
|
+
if (part !== 'q' && part !== 'r' && part !== 'c')
|
|
17
|
+
throw new Error('invalid word division part');
|
|
18
|
+
if (!Number.isSafeInteger(index) || (part === 'c' ? index < 1 || index > 2 * n : index < 0 || index >= n))
|
|
19
|
+
throw new Error('invalid word division index');
|
|
20
|
+
if (!Array.isArray(values) || values.length !== 2 * n)
|
|
21
|
+
throw new Error('invalid word division arity');
|
|
22
|
+
const base = width === 8 ? 256n : 65536n;
|
|
23
|
+
const digits = [];
|
|
24
|
+
for (const value of values) {
|
|
25
|
+
if (!Number.isSafeInteger(value) || value < 0)
|
|
26
|
+
throw new Error('invalid word division operand');
|
|
27
|
+
digits.push(BigInt(value) % base);
|
|
28
|
+
}
|
|
29
|
+
let a = 0n, b = 0n, power = 1n;
|
|
30
|
+
for (let i = 0; i < n; i++) {
|
|
31
|
+
a += digits[i] * power;
|
|
32
|
+
b += digits[n + i] * power;
|
|
33
|
+
power *= base;
|
|
34
|
+
}
|
|
35
|
+
const q = b === 0n ? 0n : a / b;
|
|
36
|
+
const r = b === 0n ? 0n : a % b;
|
|
37
|
+
if (part === 'q' || part === 'r')
|
|
38
|
+
return Number(((part === 'q' ? q : r) / (base ** BigInt(index))) % base);
|
|
39
|
+
let carry = 0n;
|
|
40
|
+
for (let col = 0; col < index; col++) {
|
|
41
|
+
let total = carry + (col < n ? (r / (base ** BigInt(col))) % base : 0n);
|
|
42
|
+
for (let j = 0; j < n; j++) {
|
|
43
|
+
const k = col - j;
|
|
44
|
+
if (k >= 0 && k < n)
|
|
45
|
+
total += ((q / (base ** BigInt(j))) % base) * digits[n + k];
|
|
46
|
+
}
|
|
47
|
+
carry = total / base;
|
|
48
|
+
}
|
|
49
|
+
return Number(carry);
|
|
50
|
+
};
|
|
51
|
+
export function init(params) {
|
|
52
|
+
const env = {"maxRetries": $n(params["maxRetries"], "param maxRetries"), "cap": $n(params["cap"], "param cap")}, s = {};
|
|
53
|
+
return {scalars: {"treeRev": 1, "buildOkRev": 0, "testsOkRev": 0, "testsTainted": 0, "secretTainted": 0, "shellToken": 0, "buildFails": 0, "testFails": 0, "spent": 0, "capNow": env["cap"], "halted": 0, "decision": 0, "commitExecuted": 0, "gRev": 1, "gBuildOk": 0, "gTestsOk": 0, "gMaxSusp": 0, "gMaxAppr": 0, "gBuildFails": 0, "gTestFails": 0}, maps: {}};
|
|
54
|
+
}
|
|
55
|
+
export function fork(state) {
|
|
56
|
+
return {scalars: {...state.scalars}, maps: Object.fromEntries(Object.entries(state.maps).map(([name, cells]) => [name, new Map(cells)])), ...(state.defaults ? {defaults: {...state.defaults}} : {})};
|
|
57
|
+
}
|
|
58
|
+
export function step(params, state, input) {
|
|
59
|
+
const env = {"maxRetries": $n(params["maxRetries"], "param maxRetries"), "cap": $n(params["cap"], "param cap"), "op": $n(input["op"], "input op"), "cost": $n(input["cost"], "input cost"), "passed": $n(input["passed"], "input passed"), "fullSuite": $n(input["fullSuite"], "input fullSuite"), "suspicious": $n(input["suspicious"], "input suspicious"), "risky": $n(input["risky"], "input risky"), "treeChanged": $n(input["treeChanged"], "input treeChanged"), "approveRev": $n(input["approveRev"], "input approveRev"), "extra": $n(input["extra"], "input extra")}, s = state.scalars, dft = {...state.defaults}, maps = state.maps;
|
|
60
|
+
if (!((env["op"] < 10) && (env["passed"] <= 1) && (env["fullSuite"] <= 1) && (env["suspicious"] <= 1) && (env["risky"] <= 1) && (env["treeChanged"] <= 1) && ((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) || (env["cost"] === 0)))) throw new RangeError("stopbar_kernel_none: the request fails the rule's assumption, so no proof covers the step it would take");
|
|
61
|
+
const scalars = {...s, "treeRev": ((((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (!(s["halted"] === 1)) && (!((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (s["capNow"] <= $x(s["spent"] + env["cost"]))))) && ((env["op"] === 0) || (env["op"] === 1) || ((env["op"] === 5) && (env["treeChanged"] === 1)))) ? $x(s["treeRev"] + 1) : s["treeRev"]), "buildOkRev": (((((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (!(s["halted"] === 1)) && (!((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (s["capNow"] <= $x(s["spent"] + env["cost"]))))) && (env["op"] === 2)) && (env["passed"] === 1)) ? s["treeRev"] : (((((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (!(s["halted"] === 1)) && (!((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (s["capNow"] <= $x(s["spent"] + env["cost"]))))) && (env["op"] === 2)) && (!(env["passed"] === 1))) ? 0 : s["buildOkRev"])), "testsOkRev": (((((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (!(s["halted"] === 1)) && (!((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (s["capNow"] <= $x(s["spent"] + env["cost"]))))) && (env["op"] === 3)) && (env["passed"] === 1) && (env["fullSuite"] === 1)) ? s["treeRev"] : (((((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (!(s["halted"] === 1)) && (!((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (s["capNow"] <= $x(s["spent"] + env["cost"]))))) && (env["op"] === 3)) && (!(env["passed"] === 1))) ? 0 : s["testsOkRev"])), "buildFails": ((env["op"] === 8) ? 0 : (((((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (!(s["halted"] === 1)) && (!((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (s["capNow"] <= $x(s["spent"] + env["cost"]))))) && (env["op"] === 2)) && (env["passed"] === 1)) ? 0 : (((((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (!(s["halted"] === 1)) && (!((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (s["capNow"] <= $x(s["spent"] + env["cost"]))))) && (env["op"] === 2)) && (!(env["passed"] === 1))) ? $x(s["buildFails"] + 1) : s["buildFails"]))), "testFails": ((env["op"] === 8) ? 0 : (((((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (!(s["halted"] === 1)) && (!((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (s["capNow"] <= $x(s["spent"] + env["cost"]))))) && (env["op"] === 3)) && (env["passed"] === 1) && (env["fullSuite"] === 1)) ? 0 : (((((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (!(s["halted"] === 1)) && (!((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (s["capNow"] <= $x(s["spent"] + env["cost"]))))) && (env["op"] === 3)) && (!(env["passed"] === 1))) ? $x(s["testFails"] + 1) : s["testFails"]))), "spent": (((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (!(s["halted"] === 1))) ? $x(s["spent"] + env["cost"]) : s["spent"]), "capNow": ((env["op"] === 8) ? $x(s["capNow"] + env["extra"]) : s["capNow"]), "gRev": ((((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (!(s["halted"] === 1)) && (!((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (s["capNow"] <= $x(s["spent"] + env["cost"]))))) && ((env["op"] === 0) || (env["op"] === 1) || ((env["op"] === 5) && (env["treeChanged"] === 1)))) ? $x(s["gRev"] + 1) : s["gRev"]), "gMaxSusp": ((((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (!(s["halted"] === 1)) && (!((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (s["capNow"] <= $x(s["spent"] + env["cost"]))))) && ((env["op"] === 1) || ((env["op"] === 5) && (env["treeChanged"] === 1))) && (env["suspicious"] === 1)) ? Math.max(s["gMaxSusp"], $x(s["gRev"] + 1)) : s["gMaxSusp"]), "gMaxAppr": (((env["op"] === 6) && (env["approveRev"] <= s["gRev"]) && (!(s["halted"] === 1))) ? Math.max(s["gMaxAppr"], env["approveRev"]) : s["gMaxAppr"]), "gBuildFails": ((env["op"] === 8) ? 0 : (((((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (!(s["halted"] === 1)) && (!((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (s["capNow"] <= $x(s["spent"] + env["cost"]))))) && (env["op"] === 2)) && (env["passed"] === 1)) ? 0 : (((((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (!(s["halted"] === 1)) && (!((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (s["capNow"] <= $x(s["spent"] + env["cost"]))))) && (env["op"] === 2)) && (!(env["passed"] === 1))) ? $x(s["gBuildFails"] + 1) : s["gBuildFails"]))), "gTestFails": ((env["op"] === 8) ? 0 : (((((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (!(s["halted"] === 1)) && (!((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (s["capNow"] <= $x(s["spent"] + env["cost"]))))) && (env["op"] === 3)) && (env["passed"] === 1) && (env["fullSuite"] === 1)) ? 0 : (((((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (!(s["halted"] === 1)) && (!((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (s["capNow"] <= $x(s["spent"] + env["cost"]))))) && (env["op"] === 3)) && (!(env["passed"] === 1))) ? $x(s["gTestFails"] + 1) : s["gTestFails"]))), "testsTainted": ((((((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (!(s["halted"] === 1)) && (!((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (s["capNow"] <= $x(s["spent"] + env["cost"]))))) && ((env["op"] === 1) || ((env["op"] === 5) && (env["treeChanged"] === 1))) && (env["suspicious"] === 1)) && (0 <= 0)) || ((!(((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (!(s["halted"] === 1)) && (!((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (s["capNow"] <= $x(s["spent"] + env["cost"]))))) && ((env["op"] === 1) || ((env["op"] === 5) && (env["treeChanged"] === 1))) && (env["suspicious"] === 1))) && ((((env["op"] === 6) && (env["approveRev"] === s["treeRev"]) && (!(s["halted"] === 1))) && (0 < 0)) || ((!((env["op"] === 6) && (env["approveRev"] === s["treeRev"]) && (!(s["halted"] === 1)))) && (s["testsTainted"] === 1))))) ? 1 : 0), "secretTainted": (((s["secretTainted"] === 1) || (((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (!(s["halted"] === 1)) && (!((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (s["capNow"] <= $x(s["spent"] + env["cost"]))))) && (env["op"] === 4))) ? 1 : 0), "shellToken": (((((env["op"] === 7) && (!(s["halted"] === 1))) && (0 <= 0)) || ((!((env["op"] === 7) && (!(s["halted"] === 1)))) && ((((((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (!(s["halted"] === 1)) && (!((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (s["capNow"] <= $x(s["spent"] + env["cost"]))))) && (env["op"] === 5) && (env["risky"] === 1)) && (s["secretTainted"] === 1)) && (0 < 0)) || ((!((((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (!(s["halted"] === 1)) && (!((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (s["capNow"] <= $x(s["spent"] + env["cost"]))))) && (env["op"] === 5) && (env["risky"] === 1)) && (s["secretTainted"] === 1))) && (s["shellToken"] === 1))))) ? 1 : 0), "halted": ((((env["op"] === 8) && (0 < 0)) || ((!(env["op"] === 8)) && ((s["halted"] === 1) || ((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (s["capNow"] <= $x(s["spent"] + env["cost"]))) || ((((((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (!(s["halted"] === 1)) && (!((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (s["capNow"] <= $x(s["spent"] + env["cost"]))))) && (env["op"] === 3)) && (!(env["passed"] === 1))) && (env["maxRetries"] <= ((env["op"] === 8) ? 0 : (((((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (!(s["halted"] === 1)) && (!((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (s["capNow"] <= $x(s["spent"] + env["cost"]))))) && (env["op"] === 3)) && (env["passed"] === 1) && (env["fullSuite"] === 1)) ? 0 : (((((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (!(s["halted"] === 1)) && (!((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (s["capNow"] <= $x(s["spent"] + env["cost"]))))) && (env["op"] === 3)) && (!(env["passed"] === 1))) ? $x(s["testFails"] + 1) : s["testFails"]))))) || (((((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (!(s["halted"] === 1)) && (!((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (s["capNow"] <= $x(s["spent"] + env["cost"]))))) && (env["op"] === 2)) && (!(env["passed"] === 1))) && (env["maxRetries"] <= ((env["op"] === 8) ? 0 : (((((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (!(s["halted"] === 1)) && (!((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (s["capNow"] <= $x(s["spent"] + env["cost"]))))) && (env["op"] === 2)) && (env["passed"] === 1)) ? 0 : (((((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (!(s["halted"] === 1)) && (!((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (s["capNow"] <= $x(s["spent"] + env["cost"]))))) && (env["op"] === 2)) && (!(env["passed"] === 1))) ? $x(s["buildFails"] + 1) : s["buildFails"]))))))))) ? 1 : 0), "decision": ((env["op"] === 8) ? 0 : ((s["halted"] === 1) ? 2 : ((env["op"] === 6) ? (((env["op"] === 6) && (env["approveRev"] === s["treeRev"]) && (!(s["halted"] === 1))) ? 0 : 1) : ((env["op"] === 7) ? 0 : ((((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (s["capNow"] <= $x(s["spent"] + env["cost"]))) || ((((((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (!(s["halted"] === 1)) && (!((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (s["capNow"] <= $x(s["spent"] + env["cost"]))))) && (env["op"] === 3)) && (!(env["passed"] === 1))) && (env["maxRetries"] <= ((env["op"] === 8) ? 0 : (((((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (!(s["halted"] === 1)) && (!((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (s["capNow"] <= $x(s["spent"] + env["cost"]))))) && (env["op"] === 3)) && (env["passed"] === 1) && (env["fullSuite"] === 1)) ? 0 : (((((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (!(s["halted"] === 1)) && (!((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (s["capNow"] <= $x(s["spent"] + env["cost"]))))) && (env["op"] === 3)) && (!(env["passed"] === 1))) ? $x(s["testFails"] + 1) : s["testFails"]))))) || (((((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (!(s["halted"] === 1)) && (!((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (s["capNow"] <= $x(s["spent"] + env["cost"]))))) && (env["op"] === 2)) && (!(env["passed"] === 1))) && (env["maxRetries"] <= ((env["op"] === 8) ? 0 : (((((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (!(s["halted"] === 1)) && (!((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (s["capNow"] <= $x(s["spent"] + env["cost"]))))) && (env["op"] === 2)) && (env["passed"] === 1)) ? 0 : (((((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (!(s["halted"] === 1)) && (!((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (s["capNow"] <= $x(s["spent"] + env["cost"]))))) && (env["op"] === 2)) && (!(env["passed"] === 1))) ? $x(s["buildFails"] + 1) : s["buildFails"])))))) || (((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (!(s["halted"] === 1)) && (!((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (s["capNow"] <= $x(s["spent"] + env["cost"]))))) && ((env["op"] === 1) || ((env["op"] === 5) && (env["treeChanged"] === 1))) && (env["suspicious"] === 1)) || ((((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (!(s["halted"] === 1)) && (!((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (s["capNow"] <= $x(s["spent"] + env["cost"]))))) && (env["op"] === 5) && (env["risky"] === 1)) && (s["secretTainted"] === 1) && (!(s["shellToken"] === 1)))) ? 2 : ((env["op"] === 9) ? ((((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (!(s["halted"] === 1)) && (!((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (s["capNow"] <= $x(s["spent"] + env["cost"]))))) && (env["op"] === 9) && (s["buildOkRev"] === s["treeRev"]) && (s["testsOkRev"] === s["treeRev"]) && (!(s["testsTainted"] === 1))) ? 0 : 1) : 0)))))), "commitExecuted": ((((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (!(s["halted"] === 1)) && (!((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (s["capNow"] <= $x(s["spent"] + env["cost"]))))) && (env["op"] === 9) && (s["buildOkRev"] === s["treeRev"]) && (s["testsOkRev"] === s["treeRev"]) && (!(s["testsTainted"] === 1))) ? 1 : 0), "gBuildOk": ((((((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (!(s["halted"] === 1)) && (!((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (s["capNow"] <= $x(s["spent"] + env["cost"]))))) && ((env["op"] === 0) || (env["op"] === 1) || ((env["op"] === 5) && (env["treeChanged"] === 1)))) && (0 < 0)) || ((!(((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (!(s["halted"] === 1)) && (!((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (s["capNow"] <= $x(s["spent"] + env["cost"]))))) && ((env["op"] === 0) || (env["op"] === 1) || ((env["op"] === 5) && (env["treeChanged"] === 1))))) && (((((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (!(s["halted"] === 1)) && (!((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (s["capNow"] <= $x(s["spent"] + env["cost"]))))) && (env["op"] === 2)) && (env["passed"] === 1)) || ((!(((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (!(s["halted"] === 1)) && (!((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (s["capNow"] <= $x(s["spent"] + env["cost"]))))) && (env["op"] === 2))) && (s["gBuildOk"] === 1))))) ? 1 : 0), "gTestsOk": ((((((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (!(s["halted"] === 1)) && (!((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (s["capNow"] <= $x(s["spent"] + env["cost"]))))) && ((env["op"] === 0) || (env["op"] === 1) || ((env["op"] === 5) && (env["treeChanged"] === 1)))) && (0 < 0)) || ((!(((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (!(s["halted"] === 1)) && (!((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (s["capNow"] <= $x(s["spent"] + env["cost"]))))) && ((env["op"] === 0) || (env["op"] === 1) || ((env["op"] === 5) && (env["treeChanged"] === 1))))) && ((((((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (!(s["halted"] === 1)) && (!((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (s["capNow"] <= $x(s["spent"] + env["cost"]))))) && (env["op"] === 3)) && (env["passed"] === 1) && (env["fullSuite"] === 1)) && (0 <= 0)) || ((!((((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (!(s["halted"] === 1)) && (!((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (s["capNow"] <= $x(s["spent"] + env["cost"]))))) && (env["op"] === 3)) && (env["passed"] === 1) && (env["fullSuite"] === 1))) && ((((((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (!(s["halted"] === 1)) && (!((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (s["capNow"] <= $x(s["spent"] + env["cost"]))))) && (env["op"] === 3)) && (!(env["passed"] === 1))) && (0 < 0)) || ((!((((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (!(s["halted"] === 1)) && (!((!((env["op"] === 6) || (env["op"] === 7) || (env["op"] === 8))) && (s["capNow"] <= $x(s["spent"] + env["cost"]))))) && (env["op"] === 3)) && (!(env["passed"] === 1)))) && (s["gTestsOk"] === 1))))))) ? 1 : 0)};
|
|
62
|
+
return Object.keys(dft).length ? {scalars, maps: state.maps, defaults: dft} : {scalars, maps: state.maps};
|
|
63
|
+
}
|