@bugb-technologies/bravos 1.3.0 → 1.4.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/README.md +16 -10
- package/dist/ci.js +11 -3
- package/dist/cli.js +16 -6
- package/dist/doctor.js +2 -2
- package/dist/guide.js +2 -2
- package/dist/help.js +10 -14
- package/dist/install-proof-tool.js +117 -0
- package/dist/proof-tools.js +29 -0
- package/dist/report/check.js +4 -1
- package/dist/report/data.js +81 -149
- package/dist/report/markdown.js +1 -1
- package/dist/report/redact.js +16 -0
- package/dist/report/runs.js +169 -0
- package/dist/setup.js +31 -16
- package/dist/start/answers.js +5 -3
- package/dist/start/index.js +28 -14
- package/dist/versions.js +4 -3
- package/docs/GUIDE.md +2 -2
- package/hooks/lib/autopilot.mjs +155 -37
- package/hooks/lib/briefing.mjs +9 -3
- package/hooks/lib/nightly-stage.mjs +66 -0
- package/hooks/lib/nightly-tools.sh +45 -0
- package/hooks/lib/pre-pr.mjs +88 -17
- package/hooks/lib/proof-tool-pins.json +12 -0
- package/hooks/lib/replay.mjs +579 -0
- package/hooks/lib/setup.mjs +15 -6
- package/hooks/lib/snapshot.mjs +75 -9
- package/package.json +1 -1
- package/skills/bravos/SKILL.md +1 -1
- package/skills/bravos-annotate/SKILL.md +6 -5
- package/skills/bravos-annotate/scripts/slice.mjs +15 -8
- package/skills/bravos-cicd/SKILL.md +1 -1
- package/skills/bravos-env/SKILL.md +3 -3
- package/skills/bravos-prove/SKILL.md +11 -15
- package/skills/bravos-recheck/SKILL.md +3 -3
- package/skills/bravos-report/SKILL.md +1 -1
- package/skills/bravos-schedule/SKILL.md +1 -1
- package/skills/bravos-ship/SKILL.md +1 -1
- package/skills/bravos-templatize/SKILL.md +3 -3
- package/templates/workflows/bravos-nightly-claude.yml +131 -74
- package/templates/workflows/bravos-nightly-codex.yml +130 -73
- package/templates/workflows/bravos-pr-gate.yml +88 -14
package/dist/start/answers.js
CHANGED
|
@@ -6,7 +6,7 @@ export const PRESETS = {
|
|
|
6
6
|
pr: { label: 'Map threats and check every pull request', hint: 'no AI key needed', pr: 'hook+github', autopilot: false, schedule: 'none', proving: 'ask' },
|
|
7
7
|
everything: { label: 'Everything: annotations, PR checks and scheduled testing', hint: 'weekly nightly run, autopilot on', pr: 'hook+github', autopilot: true, schedule: 'weekly', proving: 'ask' },
|
|
8
8
|
};
|
|
9
|
-
/**
|
|
9
|
+
/** Pricing for optional CXG model generation. */
|
|
10
10
|
export const PENTEST_COST_URL = 'https://bugb.io/pricing#pentest-cost';
|
|
11
11
|
/** The bravos init arguments these answers amount to (the review step prints them). */
|
|
12
12
|
// @comment -- "The init flags for the chosen answers: agents, the pre-PR hook, autopilot, which workflows and the nightly cadence, and the loopback scope starter when testing is on"
|
|
@@ -36,16 +36,18 @@ export function nightlySecrets(a) {
|
|
|
36
36
|
}
|
|
37
37
|
// @comment -- "proving.md in the exact form the prove skill and the briefing read: choice, generation, the person's own words quoted, and confirmed by their name and the date. Setup records no target or start command: the agent finds how the app starts and where it listens (loopback only) when it tests, and writes them then."
|
|
38
38
|
export function provingText(a, date) {
|
|
39
|
-
const quoted = a.words.trim().replace(/\s+/g, ' ').replace(/"/g, "'");
|
|
40
39
|
return [
|
|
41
40
|
'# How findings are proven',
|
|
42
41
|
'',
|
|
43
42
|
'Recorded by `bravos start` from the answers below. Edit it, or run `bravos start --again`, to change it.',
|
|
44
43
|
'',
|
|
45
44
|
`choice: ${a.proving}`,
|
|
45
|
+
...(a.proving === 'auto' ? [`kits: ${a.kitPolicy ?? 'reviewed'}`] : []),
|
|
46
46
|
`generation: ${a.generation ? 'yes' : 'no'}`,
|
|
47
47
|
'',
|
|
48
|
-
|
|
48
|
+
// Automatic tests need the one local app they may contact; the agent finds it (bravos-env) and a person merges it.
|
|
49
|
+
...(a.proving === 'auto' ? ['Automatic tests start once a `target: http://localhost:<port>/` line naming your local app is added here and merged to the default branch (bravos-env does this with you).', ''] : []),
|
|
50
|
+
JSON.stringify(a.words.trim()),
|
|
49
51
|
'',
|
|
50
52
|
`— confirmed by ${a.name.trim()}, ${date}`,
|
|
51
53
|
'',
|
package/dist/start/index.js
CHANGED
|
@@ -70,7 +70,7 @@ async function flow(opts, d) {
|
|
|
70
70
|
p.warn(`The old Python bravos at ${shadow} may run instead of this one. Rename it: mv ${shadow} ${shadow}-py`);
|
|
71
71
|
}
|
|
72
72
|
const has = (s, f) => !!s.lic?.unlocked.includes(f);
|
|
73
|
-
const missingTools = (s) => (s.items ?? []).filter((i) => (i.id === 'guardlink' || i.id === 'cxg') && !i.present);
|
|
73
|
+
const missingTools = (s) => (s.items ?? []).filter((i) => (i.id === 'guardlink' || i.id === 'cxg') && (!i.present || (i.proofTool && i.proofTool.status !== 'ready')));
|
|
74
74
|
const missingBundles = (s) => (s.items ?? []).filter((i) => (i.id === 'analyzer' || i.id === 'codegraph') && !i.present && i.licensed);
|
|
75
75
|
const steps = [
|
|
76
76
|
// theme
|
|
@@ -110,7 +110,11 @@ async function flow(opts, d) {
|
|
|
110
110
|
// tools
|
|
111
111
|
async (s) => {
|
|
112
112
|
s.items = (await d.setupPlan()).items;
|
|
113
|
-
p.note(s.items.map((i) =>
|
|
113
|
+
p.note(s.items.map((i) => {
|
|
114
|
+
if (i.present && i.proofTool && i.proofTool.status !== 'ready')
|
|
115
|
+
return `✗ ${i.id.padEnd(10)} ${i.present} needs a compatible build for ${i.proofTool.capability}`;
|
|
116
|
+
return `${i.present ? '✔' : '✗'} ${i.id.padEnd(10)} ${i.present ? 'installed' : i.licensed === false ? 'Team plan' : `missing — ${i.action}`}`;
|
|
117
|
+
}).join('\n'), 'Tools');
|
|
114
118
|
const missing = [...missingTools(s), ...missingBundles(s)];
|
|
115
119
|
s.installTools = false;
|
|
116
120
|
if (!missing.length)
|
|
@@ -192,7 +196,7 @@ async function flow(opts, d) {
|
|
|
192
196
|
s.autopilot = false;
|
|
193
197
|
return;
|
|
194
198
|
}
|
|
195
|
-
s.autopilot = await p.confirm('autopilot', '
|
|
199
|
+
s.autopilot = await p.confirm('autopilot', 'Review changed code at the end of each agent turn? Autopilot asks the agent to update relevant claims and follows your testing preference.', s.autopilot ?? saved?.autopilot ?? (s.preset === 'pr' && !opts.yes ? true : PRESETS[s.preset].autopilot));
|
|
196
200
|
},
|
|
197
201
|
// scheduled run (GitHub Actions)
|
|
198
202
|
async (s) => {
|
|
@@ -202,7 +206,7 @@ async function flow(opts, d) {
|
|
|
202
206
|
s.schedule = 'none';
|
|
203
207
|
return;
|
|
204
208
|
}
|
|
205
|
-
p.info('A scheduled run has an agent annotate
|
|
209
|
+
p.info('A scheduled run has an agent annotate the next slice on GitHub. The Claude Code and Codex workflows also support authorized probe replay. Claude Code signs in there with your Claude plan and GitHub Copilot uses your Copilot plan, like a session would; Codex needs an OpenAI API key. The PR check uses no AI.');
|
|
206
210
|
s.schedule = await p.select('schedule', 'Run Bravos on a schedule in GitHub Actions?', [
|
|
207
211
|
{ value: 'none', label: 'No schedule', hint: 'no sign-in needed' },
|
|
208
212
|
{ value: 'weekly', label: 'Once a week', hint: 'Sunday night; the cheapest', recommended: true },
|
|
@@ -229,22 +233,27 @@ async function flow(opts, d) {
|
|
|
229
233
|
}
|
|
230
234
|
const choices = [
|
|
231
235
|
{ value: 'ask', label: 'Ask me every time before testing', recommended: true },
|
|
232
|
-
{ value: 'auto', label: 'Test my local app
|
|
233
|
-
|
|
236
|
+
{ value: 'auto', label: 'Test my local app as I build', hint: 'includes scoped tests written by this agent' },
|
|
237
|
+
{ value: 'auto-reviewed', label: 'Automatically replay reviewed kits only', hint: 'uses the tested kit version on the default branch' },
|
|
238
|
+
...(s.schedule !== 'none' && s.nightlyAgent !== 'copilot' ? [{ value: 'schedule', label: 'Only in the scheduled run' }] : []),
|
|
234
239
|
{ value: 'none', label: 'Never test, just annotate' },
|
|
235
240
|
];
|
|
236
241
|
p.info('Bravos only tests apps you own, on localhost; your agent finds how to start the app when it tests. Anything else needs a reviewed scope file and your own typed authorization at that time; setup never fills that in.');
|
|
237
|
-
const
|
|
238
|
-
|
|
242
|
+
const previous = s.proving ?? saved?.proving ?? PRESETS[s.preset].proving;
|
|
243
|
+
const previousKits = s.kitPolicy ?? saved?.kitPolicy ?? (saved?.generation === false ? 'reviewed' : 'session');
|
|
244
|
+
const want = previous === 'auto' && previousKits === 'reviewed' ? 'auto-reviewed' : previous;
|
|
245
|
+
const choice = await p.select('proving', 'How should Bravos handle testing?', choices, choices.some((c) => c.value === want) ? want : 'ask');
|
|
246
|
+
s.proving = choice === 'auto-reviewed' ? 'auto' : choice;
|
|
247
|
+
s.kitPolicy = choice === 'auto-reviewed' ? 'reviewed' : 'session';
|
|
239
248
|
},
|
|
240
|
-
//
|
|
249
|
+
// Optional external generation is separate from replaying harness-authored tests.
|
|
241
250
|
async (s) => {
|
|
242
251
|
if (s.proving === 'none') {
|
|
243
252
|
s.generation = false;
|
|
244
253
|
return;
|
|
245
254
|
}
|
|
246
|
-
p.info(`
|
|
247
|
-
s.generation = await p.confirm('generation', '
|
|
255
|
+
p.info(`Your coding agent can write tests in this session. Optional CXG model generation spends additional credits. See ${PENTEST_COST_URL}`);
|
|
256
|
+
s.generation = await p.confirm('generation', 'Allow CXG to generate additional probes through a paid model API?', s.generation ?? saved?.generation ?? false, { yes: 'Allow model API spend', no: 'Use the current agent and supplied tests', recommend: false });
|
|
248
257
|
},
|
|
249
258
|
// the person's own words
|
|
250
259
|
async (s) => {
|
|
@@ -333,7 +342,7 @@ async function flow(opts, d) {
|
|
|
333
342
|
...(answers.schedule !== 'none' ? [` + .github/workflows/bravos-nightly-${answers.nightlyAgent}.yml (${answers.schedule}, cron ${CRON[answers.schedule]} UTC)`] : []),
|
|
334
343
|
...(answers.schedule !== 'none' && answers.nightlyAgent === 'copilot' ? [' + .github/workflows/copilot-setup-steps.yml (prepares Copilot\'s session: Node and guardlink)'] : []),
|
|
335
344
|
...(answers.proving !== 'none' ? [' + .guardlink/scope.yaml (localhost only; authorization left for you)'] : []),
|
|
336
|
-
...(answers.name ? [` + .guardlink/proving.md (${answers.proving}${answers.generation ? ',
|
|
345
|
+
...(answers.name ? [` + .guardlink/proving.md (${answers.proving}${answers.generation ? ', model API generation allowed' : ''}, confirmed by ${answers.name})`] : []),
|
|
337
346
|
...(Object.keys(s.secrets).length ? [` + GitHub secrets: ${Object.keys(s.secrets).join(', ')}`] : []),
|
|
338
347
|
' + .bravos/setup.json (your answers, for bravos start --again)',
|
|
339
348
|
...(has(s, 'codegraph') ? ['Then: build the code graph for this repository'] : []),
|
|
@@ -382,6 +391,7 @@ function toAnswers(s) {
|
|
|
382
391
|
schedule: s.schedule ?? 'none',
|
|
383
392
|
nightlyAgent: s.nightlyAgent ?? 'claude',
|
|
384
393
|
proving: s.proving ?? 'none',
|
|
394
|
+
...(s.proving === 'auto' ? { kitPolicy: s.kitPolicy } : {}),
|
|
385
395
|
generation: !!s.generation,
|
|
386
396
|
words: s.proving === 'auto' || s.proving === 'schedule' ? (s.words ?? '') : '',
|
|
387
397
|
name: s.name ?? '',
|
|
@@ -395,6 +405,10 @@ async function apply(answers, s, d, opts, has) {
|
|
|
395
405
|
const r = await p.spin('Installing guardlink and cxg', () => d.bravos(['setup', '--tools', '-y']), (r) => (r.code ? { fail: 'Installing guardlink and cxg — failed' } : 'Installed guardlink and cxg'));
|
|
396
406
|
for (const l of [...r.out, ...r.err])
|
|
397
407
|
(r.code ? p.warn : p.info)(l);
|
|
408
|
+
// A tool that would not install (no cargo, offline, an incompatible build) limits proving, not the
|
|
409
|
+
// rest of setup: carry on, and say what still needs doing instead of leaving the repo unset.
|
|
410
|
+
if (r.code)
|
|
411
|
+
p.warn('Carrying on without them: annotation and the briefing work now; proving needs guardlink and cxg. Fix the line above, then run bravos setup --tools.');
|
|
398
412
|
}
|
|
399
413
|
if (answers.installTools && has.missingBundles) {
|
|
400
414
|
const r = await p.spin('Fetching the Bravos analyzer and code graph', () => d.bravos(['setup']), (r) => (r.code ? { fail: 'Fetching the analyzer and code graph — failed' } : 'Fetched the analyzer and code graph'));
|
|
@@ -438,9 +452,9 @@ async function apply(answers, s, d, opts, has) {
|
|
|
438
452
|
`Open ${tool} in ${tildify(repo, d.env.HOME)} and type:`,
|
|
439
453
|
'',
|
|
440
454
|
` ${handoff} learns what the app is for (asks you a few questions)`,
|
|
441
|
-
` ${sigil(lead)}bravos-annotate maps the threats in your code
|
|
455
|
+
` ${sigil(lead)}bravos-annotate maps the threats in your code`,
|
|
442
456
|
'',
|
|
443
|
-
'
|
|
457
|
+
'Autopilot can review later changes in your agent. Live testing follows the preference and target you authorized.',
|
|
444
458
|
copied ? `(${handoff} is on your clipboard.) The Bravos banner shows the next step each time you open a session.` : 'The Bravos banner shows the next step each time you open a session.',
|
|
445
459
|
'Follow along in a second terminal: bravos watch',
|
|
446
460
|
].join('\n'), 'One step left, in your agent');
|
package/dist/versions.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { hooksDir } from './paths.js';
|
|
1
4
|
// @comment -- "The versions of the two binary bundles this CLI installs. Pinned here, not read from the network: a bravos release names the analyzer and code-graph builds it was tested with, and bravos setup fetches exactly those."
|
|
2
5
|
/** The licensed analyzer bundle (bravos-cli plus gitleaks, osv-scanner, kics, zizmor and the rules), published by specter-v1's analyzer-release workflow. */
|
|
3
6
|
export const ANALYZER_VERSION = '0.6.1';
|
|
4
7
|
/** The code graph binaries (codegraph-build, codegraph-mcp), published by specter-v1's codegraph-release workflow. */
|
|
5
8
|
export const CODEGRAPH_VERSION = '0.1.0';
|
|
6
|
-
|
|
7
|
-
export const GUARDLINK_VERSION = '2.5.0';
|
|
8
|
-
export const CXG_VERSION = '1.7.0';
|
|
9
|
+
export const PROOF_TOOL_PINS = JSON.parse(readFileSync(join(hooksDir(), 'lib', 'proof-tool-pins.json'), 'utf8'));
|
package/docs/GUIDE.md
CHANGED
|
@@ -44,7 +44,7 @@ Keep bravos watch running in a second terminal pane beside your agent (free, rea
|
|
|
44
44
|
|
|
45
45
|
### Hands-off: autopilot
|
|
46
46
|
|
|
47
|
-
bravos init --autopilot (or sync --autopilot) makes upkeep happen without anyone asking. At
|
|
47
|
+
bravos init --autopilot (or sync --autopilot) makes upkeep happen without anyone asking. At turn end the agent reviews changed code, including edits inside annotated files. It follows the recorded proving preference for affected claims. The pre-PR gate runs on every gh pr create.
|
|
48
48
|
|
|
49
49
|
Proving follows your choice, not a fixed rule: the first time it comes up the agent asks you once — prove automatically on your loopback target, ask each time, on a schedule, or not now — and records your words in .guardlink/proving.md. Say "ask me first" or "stop auto-proving" at any time to change it. Non-loopback targets still need a reviewed scope and your typed authorization every time.
|
|
50
50
|
|
|
@@ -84,7 +84,7 @@ Run bravos first: it reads the briefing, explains the loop in five lines and rou
|
|
|
84
84
|
|
|
85
85
|
Skills: `/bravos-cicd` · `/bravos-schedule`
|
|
86
86
|
|
|
87
|
-
bravos init --ci writes the PR gate and nightly workflows. bravos-cicd audits existing workflows: broken guardlink calls, script injection from pull-request text, missing SARIF upload. The
|
|
87
|
+
bravos init --ci writes the PR gate and nightly workflows. bravos-cicd audits existing workflows: broken guardlink calls, script injection from pull-request text, missing SARIF upload. The Claude and Codex nightlies can replay committed, bound kits when scheduled testing is authorized. The Copilot job assigns an annotation task.
|
|
88
88
|
|
|
89
89
|
## What to do, by task
|
|
90
90
|
|
package/hooks/lib/autopilot.mjs
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
// @comment -- "bravos autopilot's end-of-turn check (Claude Code and Codex Stop hooks):
|
|
1
|
+
// @comment -- "bravos autopilot's end-of-turn check (Claude Code and Codex Stop hooks): reads session changes, the annotation worklist, current model and tested states; reports changes to review and affected claim keys, scoped to code and sidecar locations, and returns block with a short reason naming the skill to run, or allow. A nudge, not a gate: a missing tool, a timeout or bad input allows. Each finding is raised once per session, per file or claim rather than per edit (its key is looked up in the harness's transcript, which bravos only reads), and the guardlink calls share one time budget under the hook's 30 s limit. Read-only: argv spawns, no shell."
|
|
2
2
|
import { createHash } from 'node:crypto';
|
|
3
3
|
import { appendFileSync, existsSync, mkdirSync, openSync, readFileSync, readSync, closeSync, fstatSync, writeFileSync } from 'node:fs';
|
|
4
4
|
import { join } from 'node:path';
|
|
5
5
|
import { gitStaleness, staleness } from './resync.mjs';
|
|
6
|
-
import { asyncRunner, fingerprint, readSnapshot, workingChanges } from './snapshot.mjs';
|
|
6
|
+
import { asyncRunner, changedHunks, fingerprint, readSnapshot, workingChanges } from './snapshot.mjs';
|
|
7
7
|
|
|
8
8
|
export { asyncRunner, readSnapshot, safeSessionId, takeSnapshot } from './snapshot.mjs';
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
// One budget for the whole check, under the harness's 30 s hook limit.
|
|
11
|
+
export const AUTOPILOT_DEADLINE_MS = 24000;
|
|
11
12
|
const TRANSCRIPT_TAIL = 4 * 1024 * 1024;
|
|
12
13
|
const MAX_LIST = 5;
|
|
13
14
|
|
|
@@ -58,14 +59,18 @@ export async function changedFiles(root, env, run, snapshot = null) {
|
|
|
58
59
|
const now = await workingChanges(root, env, run);
|
|
59
60
|
const out = new Set();
|
|
60
61
|
if (snapshot) {
|
|
61
|
-
for (const rel of now) if (snapshot.files
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
for (const rel of now) if (!Object.hasOwn(snapshot.files, rel) || snapshot.files[rel] !== fingerprint(root, rel)) out.add(rel);
|
|
63
|
+
// Also catch a previously dirty file restored to HEAD during the session.
|
|
64
|
+
for (const path of Object.keys(snapshot.files)) if (!now.has(path) && snapshot.files[path] !== fingerprint(root, path)) out.add(path);
|
|
65
|
+
const committed = await run('git', ['diff', '--name-only', `${snapshot.head}..HEAD`, '-z', '--no-renames', '--'], { cwd: root, env });
|
|
66
|
+
if (committed.status === 0) for (const path of committed.stdout.split('\0')) if (path) out.add(path);
|
|
64
67
|
} else {
|
|
65
68
|
for (const rel of now) out.add(rel);
|
|
66
69
|
}
|
|
67
70
|
const locked = lockedFiles(root);
|
|
68
|
-
|
|
71
|
+
// Shared agent settings also carry operator-authored permissions and hooks; review
|
|
72
|
+
// those through GuardLink's config model instead of treating them as source.
|
|
73
|
+
for (const rel of [...out]) if (rel.startsWith('.bravos/') || locked.has(rel)) out.delete(rel);
|
|
69
74
|
return out;
|
|
70
75
|
}
|
|
71
76
|
|
|
@@ -88,15 +93,43 @@ function transcriptTail(path) {
|
|
|
88
93
|
}
|
|
89
94
|
}
|
|
90
95
|
|
|
91
|
-
const listOf = (all) => { const xs = [...new Set(all)]; return xs.slice(0, MAX_LIST).join(', ') + (xs.length > MAX_LIST ? ` and ${xs.length - MAX_LIST} more` : ''); };
|
|
92
96
|
const fileOf = (c) => c?.location?.file ?? c?.file;
|
|
93
97
|
|
|
98
|
+
function proofInstruction(pref, retest) {
|
|
99
|
+
const skill = retest ? 'bravos-recheck' : 'bravos-prove';
|
|
100
|
+
if (pref.status !== 'set') return 'ask the person once how they want findings proven (bravos-prove); retain these claim keys for that decision';
|
|
101
|
+
if (pref.choice === 'ask') return `ask the person before testing with ${skill}`;
|
|
102
|
+
if (pref.choice === 'schedule') return 'leave the keys for the authorized scheduled run and report that they await testing';
|
|
103
|
+
if (pref.choice === 'none') return 'report the outstanding claims; the person chose not to run tests';
|
|
104
|
+
return `use bravos-templatize for missing kits and ${skill} on ${pref.target ?? 'the recorded loopback target'} under the recorded scope and generation choice`;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// @comment -- "GuardLink hypothesis list names the authored row (a .gal line in external mode). Join the exact authored line, asset and threat to parse's current exposure or confirmation to get its logical source span. Never identify an individual claim by threat and file alone."
|
|
108
|
+
function authoredKey(file, line, asset, threat) {
|
|
109
|
+
return JSON.stringify([file, line, asset, threat]);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function overlaps(hunks, file, start, end = start) {
|
|
113
|
+
if (!hunks.has(file)) return true; // Untracked file, binary, or no patch available: review the file.
|
|
114
|
+
if (!Number.isInteger(start) || !Number.isInteger(end)) return hunks.get(file).length > 0;
|
|
115
|
+
return hunks.get(file).some(h => h.start <= end && start <= h.end);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function touches(location, changed, hunks) {
|
|
119
|
+
if (!location) return false;
|
|
120
|
+
if (changed.has(location.origin_file) && overlaps(hunks, location.origin_file, location.origin_line)) return true;
|
|
121
|
+
if (!changed.has(location.file)) return false;
|
|
122
|
+
const anchor = location.anchor;
|
|
123
|
+
return overlaps(hunks, location.file, anchor?.start_line ?? location.line, anchor?.end_line ?? location.line);
|
|
124
|
+
}
|
|
125
|
+
|
|
94
126
|
/**
|
|
95
127
|
* Runs the end-of-turn check. `payload` is the Stop hook's stdin (stop_hook_active, transcript_path).
|
|
96
128
|
* Returns { decision: 'allow' } or { decision: 'block', reason }.
|
|
97
129
|
*/
|
|
98
130
|
// @comment -- "Decides the Stop hook's answer: allow when autopilot is off, the turn was already continued by a Stop hook, guardlink is absent, nothing changed or nothing new is found; otherwise block once with one line per finding and the skill that handles it, and for new exposures the next step the recorded proving preference implies."
|
|
99
131
|
export async function runAutopilot({ root, env = process.env, payload = {}, run = asyncRunner, deadlineMs = AUTOPILOT_DEADLINE_MS }) {
|
|
132
|
+
const started = Date.now();
|
|
100
133
|
if (env.BRAVOS_AUTOPILOT === 'off') return { decision: 'allow' };
|
|
101
134
|
if (payload?.stop_hook_active === true) return { decision: 'allow' };
|
|
102
135
|
if (!existsSync(join(root, '.guardlink'))) return { decision: 'allow' };
|
|
@@ -113,12 +146,25 @@ export async function runAutopilot({ root, env = process.env, payload = {}, run
|
|
|
113
146
|
const branch = branchRef && branchRef !== 'HEAD' ? branchRef : null;
|
|
114
147
|
const behind = staleness({ ...(await gitStaleness(git, base)), branch, base });
|
|
115
148
|
|
|
116
|
-
// The
|
|
117
|
-
const
|
|
149
|
+
// The hook runs under a 30 s harness limit: the guardlink calls share what is left of one budget, not 20 s each.
|
|
150
|
+
const left = Math.max(2000, deadlineMs - (Date.now() - started));
|
|
151
|
+
const og = { ...o, timeoutMs: left };
|
|
152
|
+
const [wl, ci, ledger, model, patch] = await Promise.all([
|
|
153
|
+
json(run, ['unannotated', '--json'], og), json(run, ['ci', '-f', 'json'], og),
|
|
154
|
+
json(run, ['hypothesis', 'list', '--json'], og), json(run, ['parse', '.', '--no-pretty'], og),
|
|
155
|
+
changedHunks(root, env, run, snapshot?.head ?? 'HEAD', left),
|
|
156
|
+
]);
|
|
157
|
+
const hunks = new Map();
|
|
158
|
+
for (const path of changed) {
|
|
159
|
+
if (!patch.has(path)) continue;
|
|
160
|
+
const baseline = snapshot?.hunks?.[path];
|
|
161
|
+
const prior = new Set(Array.isArray(baseline) ? baseline : []);
|
|
162
|
+
hunks.set(path, patch.get(path).filter(h => !prior.has(h.hash)));
|
|
163
|
+
}
|
|
118
164
|
|
|
119
165
|
const findings = [];
|
|
120
|
-
|
|
121
|
-
const
|
|
166
|
+
const add = (key, line) => findings.push({ key: `[bravos-autopilot:${key.split(':')[0]}:${createHash('sha256').update(key).digest('hex').slice(0, 12)}]`, line });
|
|
167
|
+
const changedSource = path => changed.has(path) && (!hunks.has(path) || hunks.get(path).length > 0);
|
|
122
168
|
|
|
123
169
|
if (behind) {
|
|
124
170
|
add(`behind:${base}:${behind.behind}`, `this checkout is ${behind.behind} commits behind ${base}${behind.baseDate ? ` (shared base ${behind.baseDate})` : ''}, so its threat model describes older code${snapshot ? '' : ' and the changes here may predate this session'}: update the branch, or carry its annotation work to ${base} with bravos-resync, before annotating or proving here.`);
|
|
@@ -126,33 +172,93 @@ export async function runAutopilot({ root, env = process.env, payload = {}, run
|
|
|
126
172
|
if (!snapshot) return finish(findings, payload);
|
|
127
173
|
}
|
|
128
174
|
|
|
129
|
-
const
|
|
130
|
-
|
|
175
|
+
const configFiles = new Set(arr(model?.agent_config?.files).map(f => f.path));
|
|
176
|
+
for (const path of changed) {
|
|
177
|
+
if (changedSource(path) && (configFiles.has(path) || (GENERATED_FILES.has(path) && hunks.has(path)))) {
|
|
178
|
+
add('config:' + path, 'Review changed coding-agent capabilities in ' + path + ' with bravos-annotate and GuardLink’s unentitled coding-agent reach lookup. Check the capability, affected asset and approval before proposing an entitlement.');
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
const paths = rows => arr(rows).map(w => typeof w === 'string' ? w : w?.file ?? w?.path)
|
|
182
|
+
.filter(path => changedSource(path) && !isGenerated(path) && !configFiles.has(path));
|
|
183
|
+
for (const path of paths(wl?.worklist)) {
|
|
184
|
+
add(`unannotated:${path}`, `${path} has no GuardLink annotation: review the change with bravos-annotate; record any security-relevant behavior.`);
|
|
185
|
+
}
|
|
186
|
+
for (const path of paths(wl?.annotated)) {
|
|
187
|
+
const ranges = hunks.get(path)?.map(h => h.start === h.end ? h.start : `${h.start}-${h.end}`).join(', ');
|
|
188
|
+
add(`review:${path}`, `review changed code in ${path}${ranges ? ` (lines ${ranges})` : ''} with bravos-annotate. Check new behavior and guards even when another symbol in this file already has an annotation.`);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const excluded = new Set(arr(wl?.excluded).map(e => e?.path ?? e?.file));
|
|
192
|
+
for (const path of changed) {
|
|
193
|
+
if (path.endsWith('.gal') && changedSource(path)) {
|
|
194
|
+
add('sidecar:' + path, 'Review changed claims in ' + path + ' with bravos-annotate. Read the logical source named by each affected block; reconcile retired claims and their replay kits.');
|
|
195
|
+
} else if (hunks.get(path)?.some(h => h.deleted) && !excluded.has(path) && !/\.(?:md|txt|rst)$/i.test(path)) {
|
|
196
|
+
add('removed:' + path, 'Review the deletion or move of ' + path + ' with bravos-annotate. Check its previous guards, current callers and any sidecars that still describe it.');
|
|
197
|
+
}
|
|
198
|
+
}
|
|
131
199
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
200
|
+
// ci.stale gives logical file/line, but not the whole source span. Use the
|
|
201
|
+
// parse location so a stale claim in an untouched sibling is not requeued.
|
|
202
|
+
const staleLocations = new Map();
|
|
203
|
+
for (const [verb, rows] of Object.entries({ exposes: model?.exposures, mitigates: model?.mitigations, boundary: model?.boundaries, flows: model?.flows, confirmed: model?.confirmed })) {
|
|
204
|
+
for (const { location } of arr(rows)) {
|
|
205
|
+
if (!location) continue;
|
|
206
|
+
const key = JSON.stringify([verb, location.file, location.line]);
|
|
207
|
+
if (!staleLocations.has(key)) staleLocations.set(key, []);
|
|
208
|
+
staleLocations.get(key).push(location);
|
|
209
|
+
}
|
|
136
210
|
}
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
const
|
|
140
|
-
|
|
211
|
+
for (const c of arr(ci?.stale)) {
|
|
212
|
+
const file = fileOf(c);
|
|
213
|
+
const locations = staleLocations.get(JSON.stringify([c.verb, file, c.line]));
|
|
214
|
+
if (locations ? !locations.some(l => touches(l, changed, hunks)) : !changedSource(file)) continue;
|
|
215
|
+
add('stale:' + (c.key ?? authoredKey(file, c.line)), (c.verb ?? 'guard') + ' claim at ' + file + ':' + (c.line ?? c.location?.line ?? '?') + ' went stale: re-read and re-verify it with bravos-recheck.');
|
|
141
216
|
}
|
|
142
217
|
|
|
143
|
-
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
218
|
+
const byAuthored = new Map();
|
|
219
|
+
for (const entry of [...arr(model?.exposures), ...arr(model?.confirmed)]) {
|
|
220
|
+
const loc = entry.location;
|
|
221
|
+
if (!loc) continue;
|
|
222
|
+
byAuthored.set(authoredKey(loc.origin_file ?? loc.file, loc.origin_line ?? loc.line, entry.asset, entry.threat), loc);
|
|
223
|
+
}
|
|
224
|
+
const controls = new Map();
|
|
225
|
+
for (const m of arr(model?.mitigations)) {
|
|
226
|
+
if (!touches(m.location, changed, hunks)) continue;
|
|
227
|
+
const pair = JSON.stringify([m.asset, m.threat]);
|
|
228
|
+
if (!controls.has(pair)) controls.set(pair, []);
|
|
229
|
+
controls.get(pair).push(m.location);
|
|
230
|
+
}
|
|
231
|
+
const pref = readProving(root);
|
|
232
|
+
if (ledger?.ledger === 'corrupt') {
|
|
233
|
+
add('ledger:corrupt', 'GuardLink could not read the hypothesis ledger. Restore its evidence before treating any claim as untested or running a retest.');
|
|
234
|
+
} else if (Array.isArray(ledger?.records)) {
|
|
235
|
+
if (!Array.isArray(model?.exposures) && ledger.records.some(r => !r.location && r.file?.endsWith('.gal'))) {
|
|
236
|
+
add('ledger:locations', 'GuardLink source locations are unavailable for sidecar claims. Read their source blocks before selecting tests; the set of affected claims is unknown.');
|
|
237
|
+
}
|
|
238
|
+
for (const record of ledger.records) {
|
|
239
|
+
if (!record?.key) continue;
|
|
240
|
+
const loc = record.location ?? byAuthored.get(authoredKey(record.file, record.line, record.asset, record.threat));
|
|
241
|
+
if (!loc) {
|
|
242
|
+
if (changed.has(record.file)) add('unresolved:' + record.key, 'Resolve the logical source location for claim ' + record.key + ' in ' + record.file + ' before choosing a kit.');
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
const affectedControls = controls.get(JSON.stringify([record.asset, record.threat])) ?? [];
|
|
246
|
+
if (!touches(loc, changed, hunks) && !affectedControls.length) continue;
|
|
247
|
+
// A current refutation holds until its anchor or a separate control changes.
|
|
248
|
+
if (record.state === 'refuted' && !affectedControls.length) continue;
|
|
249
|
+
const retest = record.state === 'retest' || record.state === 'confirmed' || record.expired || record.state === 'refuted';
|
|
250
|
+
add(`proof:${record.key}:${record.state}`, `${retest ? 'Retest' : 'Untested'} ${record.threat} on ${record.asset} at ${loc.file}:${loc.line} (claim ${record.key}): ${proofInstruction(pref, retest)}.`);
|
|
251
|
+
}
|
|
252
|
+
} else {
|
|
253
|
+
// A legacy/unavailable ledger cannot report coverage of mitigated claims.
|
|
254
|
+
for (const c of arr(ci?.confirmed).filter(c => changedSource(fileOf(c)))) {
|
|
255
|
+
const file = fileOf(c);
|
|
256
|
+
add(`recheck:${authoredKey(file, c.location?.line, c.asset, c.threat)}`, `confirmed ${c.threat} at ${file}:${c.location?.line ?? '?'}: review with bravos-recheck; ${proofInstruction(pref, true)}.`);
|
|
257
|
+
}
|
|
258
|
+
for (const e of arr(ci?.exposures).filter(c => changedSource(fileOf(c)))) {
|
|
259
|
+
const file = fileOf(e);
|
|
260
|
+
add(`prove:${authoredKey(file, e.location?.line, e.asset, e.threat)}`, `open exposure ${e.threat} on ${e.asset} in ${file}: ${proofInstruction(pref, false)}. The hypothesis ledger was unavailable; tested state is unknown.`);
|
|
261
|
+
}
|
|
156
262
|
}
|
|
157
263
|
|
|
158
264
|
return finish(findings, payload);
|
|
@@ -164,10 +270,22 @@ function finish(findings, payload) {
|
|
|
164
270
|
const seen = transcriptTail(payload?.transcript_path);
|
|
165
271
|
const fresh2 = findings.filter((f) => !seen.includes(f.key));
|
|
166
272
|
if (fresh2.length === 0) return { decision: 'allow' };
|
|
273
|
+
// Keep large changes readable while preserving one deduplication key per distinct finding.
|
|
274
|
+
const groups = new Map();
|
|
275
|
+
for (const f of fresh2) {
|
|
276
|
+
const kind = f.key.split(':')[1];
|
|
277
|
+
if (!groups.has(kind)) groups.set(kind, []);
|
|
278
|
+
groups.get(kind).push(f);
|
|
279
|
+
}
|
|
280
|
+
const lines = [];
|
|
281
|
+
for (const [kind, group] of groups) {
|
|
282
|
+
for (const item of group.slice(0, MAX_LIST)) lines.push('- ' + item.line);
|
|
283
|
+
if (group.length > MAX_LIST) lines.push('- ' + (group.length - MAX_LIST) + ' more ' + kind + ' items: inspect the rest with the changed-file diff and guardlink hypothesis list --json.');
|
|
284
|
+
}
|
|
167
285
|
const reason = [
|
|
168
286
|
'bravos autopilot, before you finish:',
|
|
169
|
-
...
|
|
170
|
-
'
|
|
287
|
+
...lines,
|
|
288
|
+
'Finish quietly when the review finds no security change. Surface a finding, an untested claim that needs attention, or a decision the person must make.',
|
|
171
289
|
fresh2.map((f) => f.key).join(' '),
|
|
172
290
|
].join('\n');
|
|
173
291
|
const summary = `sent the agent back once: ${fresh2[0].line}${fresh2.length > 1 ? ` (+${fresh2.length - 1} more)` : ''}`;
|
package/hooks/lib/briefing.mjs
CHANGED
|
@@ -8,7 +8,7 @@ import { planLine, status as licenceStatus } from './licence.mjs';
|
|
|
8
8
|
import { refreshIfDue } from './refresh.mjs';
|
|
9
9
|
import { gitStaleness, staleLine, staleness, strandedBranches, strandedLine } from './resync.mjs';
|
|
10
10
|
import { readSast, sastAvailable, sastLine } from './sast.mjs';
|
|
11
|
-
import { readSetup, setupLine } from './setup.mjs';
|
|
11
|
+
import { hooksLocked, readSetup, setupLine, TRIAL } from './setup.mjs';
|
|
12
12
|
import { memberCounts, readWorkspace, workspaceLines } from './workspace.mjs';
|
|
13
13
|
|
|
14
14
|
const SEVERITIES = ['critical', 'high', 'medium', 'low'];
|
|
@@ -176,7 +176,11 @@ export function buildBriefing(inputs) {
|
|
|
176
176
|
? `Note: this repo's bravos (${i.shadow.repo}) is behind the person's user-level copy (${i.shadow.user}), which Claude Code uses; suggest they run bravos sync in this repo from their own terminal`
|
|
177
177
|
: `Note: the person's user-level bravos skills (~/.claude/skills, ${i.shadow.user}) are used instead of this repo's (${i.shadow.repo}); tell them to run bravos sync --global from their own terminal, then start a new session`);
|
|
178
178
|
}
|
|
179
|
-
if (i.autopilot
|
|
179
|
+
if ((i.autopilot || i.prePr) && hooksLocked(i)) {
|
|
180
|
+
// The repo registers the hooks for everyone; this person's copy answers nothing until they have a licence.
|
|
181
|
+
const which = i.autopilot ? 'Autopilot (the end-of-turn check and the pre-PR gate)' : 'The pre-PR gate';
|
|
182
|
+
tail.push(`${which}: installed in this repo but inactive for this person — it is on the Team plan and they have no licence, so nothing checks their work automatically. Tell them once, in plain words, and that ${TRIAL}; never say autopilot checked anything.`);
|
|
183
|
+
} else if (i.autopilot) tail.push('Autopilot: on — at turn end, review changed behavior in new and annotated files and follow the proving choice for affected claims');
|
|
180
184
|
if (i.codegraph === 'current') tail.push('Code graph: current');
|
|
181
185
|
else if (i.codegraph === 'cli') tail.push('Code graph: ask it with `bravos graph <question> --json` (same answers as the codegraph_ tools; e.g. attack-surface, entry-points, callers, reachable-sinks, call-chain); if it says no graph, build it: bravos graph build . (bravos-codegraph)');
|
|
182
186
|
else if (i.codegraph === 'not-built') tail.push('Code graph: none for this commit — bravos keys a graph to the commit it was built at, so a new commit needs a rebuild: bravos graph build . --scip no-exec (bravos-codegraph; no tokens, a few minutes). Until then skills trace routes by reading.');
|
|
@@ -604,7 +608,8 @@ function statusLine(i) {
|
|
|
604
608
|
const graph = i.codegraph === 'unavailable' ? 'graph off' : i.codegraph === 'not-built' ? 'graph none' : i.codegraph === 'diverged' ? 'graph stale' : 'graph on';
|
|
605
609
|
const sast = i.sast?.summary ? `sast ${i.sast.summary.reachable} reachable` : i.sast?.available?.ok ? 'sast not run' : 'sast off';
|
|
606
610
|
const setup = i.root ? readSetup(i.root, i, i.harness) : null;
|
|
607
|
-
|
|
611
|
+
const hook = (on) => (!on ? 'off' : hooksLocked(i) ? 'locked' : 'on');
|
|
612
|
+
return `intent ${intent} · ${graph} · pre-PR ${hook(i.prePr)} · auto ${hook(i.autopilot)} · ${sast}${setup ? ` · setup ${setup.done}/${setup.total}` : ''}`;
|
|
608
613
|
}
|
|
609
614
|
|
|
610
615
|
/**
|
|
@@ -632,6 +637,7 @@ export function buildBanner(inputs, opts = {}) {
|
|
|
632
637
|
}
|
|
633
638
|
const g = i.guardlink ?? {};
|
|
634
639
|
lines.push('', countsLine(g), statusLine(i));
|
|
640
|
+
if ((i.autopilot || i.prePr) && hooksLocked(i)) lines.push(`~ ${i.autopilot ? 'autopilot' : 'the pre-PR gate'} is set up here, on the Team plan for you · bravos account activate`);
|
|
635
641
|
if (i.stale) lines.push(`! ${i.branch ?? 'this checkout'} is ${i.stale.behind} behind ${i.base} · findings describe older code · bravos-resync`);
|
|
636
642
|
else if (arr(i.stranded).length > 0) lines.push(`~ annotation work on ${i.stranded[0].branch} is not on ${i.base} · bravos-resync`);
|
|
637
643
|
if (i.shadow) {
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// @comment -- "Stage only annotation changes, bound JS kits for review and the verified ledger from the separate runner. The authoring agent cannot stage arbitrary files, credentials, reports, policies, workflow edits or its own ledger."
|
|
2
|
+
import { execFileSync } from 'node:child_process';
|
|
3
|
+
import { copyFileSync, existsSync, lstatSync, readFileSync, realpathSync } from 'node:fs';
|
|
4
|
+
import { join, resolve, sep } from 'node:path';
|
|
5
|
+
|
|
6
|
+
const git = (...args) => execFileSync('git', args, { encoding: 'utf8', maxBuffer: 32 * 1024 * 1024 });
|
|
7
|
+
const root = realpathSync(git('rev-parse', '--show-toplevel').trim());
|
|
8
|
+
process.chdir(root);
|
|
9
|
+
if (!process.env.START || git('rev-parse', 'HEAD').trim() !== process.env.START) throw new Error('The author changed HEAD; only changes against the reviewed start commit may be staged.');
|
|
10
|
+
git('restore', '--staged', '--', '.');
|
|
11
|
+
const names = new Set([...git('diff', '--name-only', '-z').split('\0'), ...git('ls-files', '--others', '--exclude-standard', '-z').split('\0')]);
|
|
12
|
+
function regular(path) {
|
|
13
|
+
return existsSync(path) && resolve(path) === realpathSync(path) && lstatSync(path).isFile();
|
|
14
|
+
}
|
|
15
|
+
// @mitigates #replay-ledger against #governance-forgery using #annotation-only-staging -- "a changed line counts as an annotation only when the whole line is a comment that carries one (no code after a closing */ or -->), an agent may never add @accepts, @entitles or @confirmed, and may never remove a line carrying @accepts or @entitles; a file that breaks any of this is left unstaged and named."
|
|
16
|
+
const GOVERNANCE_ADD = /@(?:accepts|entitles|confirmed)\b/;
|
|
17
|
+
const GOVERNANCE_KEEP = /@(?:accepts|entitles)\b/;
|
|
18
|
+
// A whole comment line holding an annotation, in the comment syntaxes annotations are written in.
|
|
19
|
+
const ANNOTATION_LINE = /^(?:\/\/+|#+|--|;+|\*|\/\*+|<!--)\s*@[a-z][\w-]*\b/;
|
|
20
|
+
const COMMENT_ONLY = /^(?:\/\*\*?|\*\/|\*|\/\/+|#+|--)$/;
|
|
21
|
+
function codeAfterClose(line) {
|
|
22
|
+
const close = Math.max(line.lastIndexOf('*/'), line.lastIndexOf('-->'));
|
|
23
|
+
if (close < 0) return false;
|
|
24
|
+
return line.slice(close + (line.startsWith('-->', close) ? 3 : 2)).trim().length > 0;
|
|
25
|
+
}
|
|
26
|
+
function changedLines(name, tracked) {
|
|
27
|
+
if (!tracked) return { added: readFileSync(name, 'utf8').split('\n').map((s) => s.trim()), removed: [] };
|
|
28
|
+
const diff = git('diff', '--no-ext-diff', '--unified=0', '--', name);
|
|
29
|
+
const rows = diff.split('\n').filter((line) => /^[+-]/.test(line) && !/^(--- a\/|\+\+\+ b\/|--- \/dev\/null)/.test(line));
|
|
30
|
+
return { added: rows.filter((l) => l[0] === '+').map((l) => l.slice(1).trim()), removed: rows.filter((l) => l[0] === '-').map((l) => l.slice(1).trim()) };
|
|
31
|
+
}
|
|
32
|
+
const untrackedSet = new Set(git('ls-files', '--others', '--exclude-standard', '-z').split('\0').filter(Boolean));
|
|
33
|
+
const refused = [];
|
|
34
|
+
for (const name of names) {
|
|
35
|
+
if (!name || !regular(name) || /[\x00-\x1f]/.test(name)) continue;
|
|
36
|
+
const isSidecar = /^\.guardlink\/annotations\/.+\.gal$/.test(name);
|
|
37
|
+
const isDefinitions = /^\.guardlink\/definitions\.[a-z]+$/.test(name);
|
|
38
|
+
const isKit = /^\.guardlink\/cxg-replay\/.+\.js$/.test(name) &&
|
|
39
|
+
/^\/\/\s*@(bravos_claim_key|exposure_claim_key):\s*[0-9a-f]{64}:\d+\s*$/m.test(readFileSync(name, 'utf8'));
|
|
40
|
+
if (!(isSidecar || isDefinitions || isKit) && name.split('/').some((part) => part.startsWith('.'))) continue;
|
|
41
|
+
const { added, removed } = changedLines(name, !untrackedSet.has(name));
|
|
42
|
+
// Human decisions and confirmations are never the agent's to add, and acceptances never its to remove.
|
|
43
|
+
if (!isKit && (added.some((l) => GOVERNANCE_ADD.test(l)) || removed.some((l) => GOVERNANCE_KEEP.test(l)))) {
|
|
44
|
+
refused.push(`${name}: adds @accepts/@entitles/@confirmed or removes an @accepts/@entitles line`);
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (!(isSidecar || isDefinitions || isKit)) {
|
|
48
|
+
// Inline annotation edits may change a tracked source file, but only whole annotation or comment lines.
|
|
49
|
+
const changes = [...added, ...removed].filter(Boolean);
|
|
50
|
+
const ok = changes.some((l) => ANNOTATION_LINE.test(l)) &&
|
|
51
|
+
changes.every((l) => (COMMENT_ONLY.test(l) || ANNOTATION_LINE.test(l)) && !codeAfterClose(l));
|
|
52
|
+
if (!ok) { refused.push(`${name}: changes lines that are not whole annotation comments`); continue; }
|
|
53
|
+
}
|
|
54
|
+
git('add', '--', name);
|
|
55
|
+
}
|
|
56
|
+
for (const r of refused) console.log(`Not staged: ${r}`);
|
|
57
|
+
if (process.env.LEDGER === 'yes') {
|
|
58
|
+
const ledger = join(root, '.guardlink', 'hypotheses.json');
|
|
59
|
+
if (realpathSync(join(root, '.guardlink')) !== join(root, '.guardlink') || (lstatSync(ledger, { throwIfNoEntry: false }) && !regular(ledger))) {
|
|
60
|
+
throw new Error('Unsafe destination for verified GuardLink ledger.');
|
|
61
|
+
}
|
|
62
|
+
const incoming = join(process.env.RUNNER_TEMP, 'bravos-verified-ledger', 'hypotheses.json');
|
|
63
|
+
if (!regular(incoming) || !realpathSync(incoming).startsWith(realpathSync(process.env.RUNNER_TEMP) + sep)) throw new Error('Missing verified ledger artifact.');
|
|
64
|
+
copyFileSync(incoming, ledger);
|
|
65
|
+
git('add', '--', '.guardlink/hypotheses.json');
|
|
66
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# @comment -- "Bootstrap the pinned upstream tools on a fresh Actions runner: the released npm and crates.io versions, or, when a pin names a revision, that commit built from source."
|
|
3
|
+
set -euo pipefail
|
|
4
|
+
role=${1:?choose author or replay}
|
|
5
|
+
case "$role" in author|replay|annotate) ;; *) exit 2 ;; esac
|
|
6
|
+
pins="$(dirname "$0")/proof-tool-pins.json"
|
|
7
|
+
guardlink_version=$(jq -er '.guardlink.version' "$pins")
|
|
8
|
+
guardlink_revision=$(jq -r '.guardlink.revision // empty' "$pins")
|
|
9
|
+
guardlink_repo=$(jq -er '.guardlink.repository' "$pins")
|
|
10
|
+
cxg_version=$(jq -er '.cxg.version' "$pins")
|
|
11
|
+
cxg_revision=$(jq -r '.cxg.revision // empty' "$pins")
|
|
12
|
+
cxg_repo=$(jq -er '.cxg.repository' "$pins")
|
|
13
|
+
# Every job uses the same GuardLink: the replay and annotate jobs read the model the author wrote against.
|
|
14
|
+
if test -n "$guardlink_revision"; then
|
|
15
|
+
source_dir=$(mktemp -d "$RUNNER_TEMP/bravos-guardlink-XXXXXX")
|
|
16
|
+
git init -q "$source_dir"
|
|
17
|
+
git -C "$source_dir" fetch --quiet --depth=1 "$guardlink_repo" "$guardlink_revision"
|
|
18
|
+
git -C "$source_dir" checkout --quiet --detach FETCH_HEAD
|
|
19
|
+
test "$(git -C "$source_dir" rev-parse HEAD)" = "$guardlink_revision"
|
|
20
|
+
(
|
|
21
|
+
cd "$source_dir"
|
|
22
|
+
npm ci --include=dev --no-audit --no-fund
|
|
23
|
+
npm run build
|
|
24
|
+
tarball=$(npm pack --ignore-scripts --json | jq -re '.[0].filename')
|
|
25
|
+
npm install -g "./$tarball"
|
|
26
|
+
)
|
|
27
|
+
else
|
|
28
|
+
npm install -g "guardlink@$guardlink_version"
|
|
29
|
+
fi
|
|
30
|
+
test "$role" != annotate || exit 0
|
|
31
|
+
install_root="$RUNNER_TEMP/bravos-cxg"
|
|
32
|
+
if ! test -x "$install_root/bin/cxg"; then
|
|
33
|
+
if test -n "$cxg_revision"; then
|
|
34
|
+
cargo install --locked --root "$install_root" --git "$cxg_repo" --rev "$cxg_revision" cert-x-gen
|
|
35
|
+
else
|
|
36
|
+
cargo install --locked --root "$install_root" "cert-x-gen@$cxg_version"
|
|
37
|
+
fi
|
|
38
|
+
fi
|
|
39
|
+
export PATH="$install_root/bin:$PATH"
|
|
40
|
+
echo "$install_root/bin" >> "$GITHUB_PATH"
|
|
41
|
+
cxg pentest install
|
|
42
|
+
if test "$role" = replay; then
|
|
43
|
+
"$CXG_PYTHON" -m pip install -r "$HOME/.cert-x-gen/pentest/requirements.txt"
|
|
44
|
+
"$CXG_PYTHON" -m playwright install --with-deps chromium
|
|
45
|
+
fi
|