stopbar 1.0.0 → 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 +23 -0
- package/README.md +69 -25
- package/SECURITY.md +35 -7
- 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 +3 -1
- package/dist/build-info.json +2 -2
- package/dist/classify.js +39 -10
- package/dist/cli.js +14 -4
- package/dist/commands.js +28 -46
- package/dist/config.js +11 -0
- package/dist/doctor.js +56 -4
- package/dist/githook.js +17 -0
- package/dist/hook.js +36 -15
- package/dist/integrations.js +141 -0
- package/dist/run.js +28 -0
- package/dist/store.js +1 -1
- package/package.json +15 -2
package/dist/hook.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
// Built from src/hook.ts by scripts/build.ts. Do not edit.
|
|
2
2
|
// Claude Code hooks: PreToolUse, PostToolUse, PostToolUseFailure, Stop. JSON on stdin; exit 0 = allow,
|
|
3
3
|
// exit 2 = block (stderr goes to the agent). Any wrapper error is exit 2 (fail closed).
|
|
4
|
+
import {existsSync} from 'node:fs'
|
|
4
5
|
import {resolve} from 'node:path'
|
|
5
6
|
import * as K from './classify.js'
|
|
6
|
-
|
|
7
|
+
import { DEFAULT_SAFE_TOOLS} from './config.js'
|
|
8
|
+
import {matchAny} from './glob.js'
|
|
7
9
|
import {decode, kstep, } from './engine.js'
|
|
8
10
|
import {changesSinceHead, countedEntries, diffEntries, differsFromHead, FailClosed, findRepo, gitCalls, inHead, markCounted, snapshot} from './repo.js'
|
|
9
11
|
import {appendEvent, readConfig, readState, withLock, writeState} from './store.js'
|
|
@@ -17,7 +19,7 @@ const READ_TOOLS = new Set(['Read', 'Grep', 'Glob', 'LS'])
|
|
|
17
19
|
const SHELL_TOOLS = new Set(['Bash', 'PowerShell'])
|
|
18
20
|
const OUTBOUND = (t ) => t === 'WebFetch' || t === 'WebSearch' || t.startsWith('mcp__')
|
|
19
21
|
|
|
20
|
-
function step(ctx , req , source ) {
|
|
22
|
+
function step(ctx , req , source , extra = {}) {
|
|
21
23
|
const before = decode(ctx.s.kernel)
|
|
22
24
|
ctx.s.kernel = kstep(ctx.s.params, ctx.s.kernel, req)
|
|
23
25
|
ctx.dirty = true
|
|
@@ -25,14 +27,14 @@ function step(ctx , req , source ) {
|
|
|
25
27
|
appendEvent(ctx.repo, {source, req, decision: after.decision, halted: after.halted, testsTainted: after.testsTainted,
|
|
26
28
|
secretTainted: after.secretTainted, shellToken: after.shellToken, treeRev: after.treeRev, buildOkRev: after.buildOkRev,
|
|
27
29
|
testsOkRev: after.testsOkRev, spent: after.spent, capNow: after.capNow, testFails: after.testFails, buildFails: after.buildFails,
|
|
28
|
-
commitExecuted: after.commitExecuted})
|
|
30
|
+
commitExecuted: after.commitExecuted, ...extra})
|
|
29
31
|
return {before, after}
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
export function whyBlocked(v , cfg ) {
|
|
33
35
|
const r = []
|
|
34
|
-
if (v.buildOkRev !== v.treeRev) r.push(`no passing build at revision ${v.treeRev} (run \`${cfg.buildCmd}\` exactly, alone)`)
|
|
35
|
-
if (v.testsOkRev !== v.treeRev) r.push(`no passing FULL test suite at revision ${v.treeRev} (run \`${cfg.fullTestCmd}\` exactly, alone)`)
|
|
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\`)`)
|
|
36
38
|
if (v.testsTainted) r.push(`existing tests or test config changed: a human must review and run \`stopbar approve-tests --rev ${v.treeRev}\``)
|
|
37
39
|
return r.join('; ') || 'kernel decision'
|
|
38
40
|
}
|
|
@@ -68,7 +70,8 @@ function pre(ctx , input ) {
|
|
|
68
70
|
const {repo, cfg} = ctx
|
|
69
71
|
// self-protection: unconditional, before the kernel, also when halted
|
|
70
72
|
if (EDIT_TOOLS.has(tool)) {
|
|
71
|
-
|
|
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)) {
|
|
72
75
|
const why = K.protectedPath(resolve(repo.root, p), repo.root, ctx.protect)
|
|
73
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.`) }
|
|
74
77
|
}
|
|
@@ -86,14 +89,19 @@ function pre(ctx , input ) {
|
|
|
86
89
|
}
|
|
87
90
|
const cost = cfg.costPerCall
|
|
88
91
|
if (READ_TOOLS.has(tool)) {
|
|
89
|
-
const ps = [ti.file_path, ti.path, ti.glob, ti.pattern].filter((x) => typeof x === 'string' && x)
|
|
90
|
-
|
|
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
|
+
}
|
|
91
97
|
return {code: 0}
|
|
92
98
|
}
|
|
93
99
|
if (EDIT_TOOLS.has(tool)) return {code: 0} // cost and tree change are counted in PostToolUse
|
|
94
100
|
if (SHELL_TOOLS.has(tool)) {
|
|
95
101
|
const cmd = String(ti.command ?? '')
|
|
96
|
-
const
|
|
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)
|
|
97
105
|
if (k.kind === 'commit-chained') {
|
|
98
106
|
appendEvent(repo, {source: 'pre', tool, wrapper: 'BLOCK', reason: `chained commit (${k.reason})`})
|
|
99
107
|
return block(`run \`git commit\` / \`git push\` as a single command (${k.reason}): no &&, ;, |, redirections or $(...). ` +
|
|
@@ -114,7 +122,7 @@ function pre(ctx , input ) {
|
|
|
114
122
|
}
|
|
115
123
|
return {code: 0}
|
|
116
124
|
}
|
|
117
|
-
if (k.secret) step(ctx, {op: 'READ_SECRET'}, `pre:${tool}:secret-mention
|
|
125
|
+
if (k.secret) step(ctx, {op: 'READ_SECRET'}, `pre:${tool}:secret-mention`, {secret: {pattern: k.secret.pattern, path: k.secret.token, tool}})
|
|
118
126
|
const {after} = step(ctx, {op: 'SHELL', risky: k.risky, cost}, `pre:${tool}`)
|
|
119
127
|
if (after.decision === 'PAUSE') {
|
|
120
128
|
return {code: 2, msg: after.halted ? 'PAUSE (stopbar): budget reached; a human must run `stopbar resume --extra <n>`'
|
|
@@ -123,6 +131,7 @@ function pre(ctx , input ) {
|
|
|
123
131
|
return {code: 0}
|
|
124
132
|
}
|
|
125
133
|
if (OUTBOUND(tool)) {
|
|
134
|
+
if (matchAny(tool, cfg.safeTools ?? DEFAULT_SAFE_TOOLS)) return {code: 0} // local tools listed in config.safeTools
|
|
126
135
|
const {after} = step(ctx, {op: 'SHELL', risky: true, cost}, `pre:${tool}`)
|
|
127
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\``}
|
|
128
137
|
}
|
|
@@ -145,15 +154,22 @@ function post(ctx , input , failure ) {
|
|
|
145
154
|
if (SHELL_TOOLS.has(tool)) {
|
|
146
155
|
const k = K.classifyBash(String(ti.command ?? ''), cfg, tool === 'PowerShell' ? 'powershell' : 'bash')
|
|
147
156
|
const tr = input.tool_response
|
|
148
|
-
|
|
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)}),
|
|
149
159
|
toolResponseKeys: tr && typeof tr === 'object' ? Object.keys(tr) : typeof tr})
|
|
150
160
|
const code = exitCodeOf(tr)
|
|
151
161
|
const flagged = input.is_error === true || tr?.is_error === true || tr?.interrupted === true
|
|
152
|
-
|
|
153
|
-
const
|
|
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})`
|
|
154
166
|
if (failure && input.is_interrupt === true) {
|
|
155
167
|
// Ctrl+C by the user: not a failed gate and not a retry; the tree is still checked below
|
|
156
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.`)
|
|
157
173
|
} else if (k.kind === 'build') {
|
|
158
174
|
step(ctx, {op: 'RUN_BUILD', passed, cost: cfg.costPerCall}, `post:build${note}`)
|
|
159
175
|
} else if (k.kind === 'fulltest') {
|
|
@@ -188,11 +204,16 @@ export function failMsg(e ) {
|
|
|
188
204
|
return `STOPBAR FAIL-CLOSED: ${e instanceof Error ? e.message : String(e)}`
|
|
189
205
|
}
|
|
190
206
|
|
|
191
|
-
/** One hook call
|
|
207
|
+
/** One hook call with Claude Code's JSON on stdin (the v1.0 interface). Never throws. */
|
|
192
208
|
export function runHook(raw , t0 = performance.now()) {
|
|
193
209
|
let input
|
|
194
210
|
try { input = JSON.parse(raw) } catch (e) { return {code: 2, msg: `STOPBAR FAIL-CLOSED: hook input is not JSON (${(e ).message})`} }
|
|
195
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()) {
|
|
196
217
|
try {
|
|
197
218
|
const repo = findRepo(typeof input.cwd === 'string' && input.cwd ? input.cwd : process.cwd())
|
|
198
219
|
const g0 = gitCalls
|
|
@@ -205,7 +226,7 @@ export function runHook(raw , t0 = performance.now()) {
|
|
|
205
226
|
: ev === 'PostToolUseFailure' ? post(ctx, input, true)
|
|
206
227
|
: ev === 'Stop' ? stop(ctx, input) : {code: 0}
|
|
207
228
|
if (ctx.dirty) writeState(repo, ctx.s)
|
|
208
|
-
appendEvent(repo, {source: 'hook-timing', event: ev, tool: input.tool_name, exit: res.code, gitCalls: gitCalls - g0,
|
|
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,
|
|
209
230
|
handlerMs: Math.round(performance.now() - t0), processMs: Math.round(process.uptime() * 1000)})
|
|
210
231
|
return res
|
|
211
232
|
})
|
|
@@ -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
|
+
}
|
package/dist/run.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Built from src/run.ts by scripts/build.ts. Do not edit.
|
|
2
|
+
// `stopbar run build|test`: runs the configured gate command itself and records its real exit status in the kernel.
|
|
3
|
+
// For agents without hooks (with the git fallback) this is how a build or full test run counts. The working tree is
|
|
4
|
+
// synced before the run; the result is recorded at that revision and a change made during the run is counted after it,
|
|
5
|
+
// so a run never passes a revision it did not see.
|
|
6
|
+
import {spawnSync} from 'node:child_process'
|
|
7
|
+
import {runEvent} from './hook.js'
|
|
8
|
+
import {findRepo} from './repo.js'
|
|
9
|
+
import {readConfig} from './store.js'
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
export function runGate(which , o ) {
|
|
14
|
+
if (which !== 'build' && which !== 'test') return {code: 1, msg: 'usage: stopbar run build|test'}
|
|
15
|
+
const cwd = o.get('repo') ?? process.cwd()
|
|
16
|
+
const repo = findRepo(cwd)
|
|
17
|
+
const cfg = readConfig(repo)
|
|
18
|
+
const command = which === 'build' ? cfg.buildCmd : cfg.fullTestCmd
|
|
19
|
+
const meta = (event ) => ({adapter: 'run', rawKeys: [], event})
|
|
20
|
+
const before = runEvent({hook_event_name: 'PostToolUse', cwd: repo.root, tool_name: 'Bash', tool_input: {command: ':'}, tool_response: {exitCode: 0}, stopbar: meta('sync')})
|
|
21
|
+
if (before.code !== 0 && /FAIL-CLOSED|halted/.test(before.msg ?? '')) return {code: 2, msg: before.msg}
|
|
22
|
+
const r = spawnSync(command, {cwd: repo.root, shell: true, stdio: 'inherit'})
|
|
23
|
+
const exit = r.status ?? 1
|
|
24
|
+
const after = runEvent({hook_event_name: exit === 0 ? 'PostToolUse' : 'PostToolUseFailure', cwd: repo.root, tool_name: 'Bash', tool_input: {command},
|
|
25
|
+
tool_response: {exitCode: exit}, stopbar: meta(which)})
|
|
26
|
+
const msg = `stopbar run ${which}: \`${command}\` exited ${exit}; recorded as ${exit === 0 ? 'a pass' : 'a failure'}${after.msg ? `\n${after.msg}` : ''}`
|
|
27
|
+
return {code: exit === 0 && after.code === 0 ? 0 : exit || 2, msg}
|
|
28
|
+
}
|
package/dist/store.js
CHANGED
package/package.json
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stopbar",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.1.0",
|
|
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",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/polszewski-pl/stopbar.git"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/polszewski-pl/stopbar#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/polszewski-pl/stopbar/issues"
|
|
14
|
+
},
|
|
7
15
|
"type": "module",
|
|
8
16
|
"bin": {
|
|
9
17
|
"stopbar": "bin/stopbar.mjs"
|
|
@@ -35,6 +43,11 @@
|
|
|
35
43
|
},
|
|
36
44
|
"keywords": [
|
|
37
45
|
"claude-code",
|
|
46
|
+
"cursor",
|
|
47
|
+
"codex",
|
|
48
|
+
"gemini-cli",
|
|
49
|
+
"antigravity",
|
|
50
|
+
"ai-agents",
|
|
38
51
|
"hooks",
|
|
39
52
|
"coding-agent",
|
|
40
53
|
"guardrails",
|