@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/hooks/lib/pre-pr.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// @comment -- "The pre-PR gate behind bravos's opt-in PreToolUse hook, matching bravos-ship's rulings: recognises gh pr create / gh pr ready in a Bash command, runs guardlink validate, lint --since <base> --json, diff <base> --json (each new unmitigated exposure must be disclosed in the PR body by threat and asset id) and ci -f json (a confirmed claim on a changed file blocks unless that file carries a @ticket for it), and returns allow or block with a reason. A gate input that fails or does not parse blocks as unknown. Read-only: every command is spawned with an argv array, no shell, a per-spawn timeout and one shared deadline."
|
|
2
|
+
import { gitPatchArgs, parseChangedHunks } from './snapshot.mjs';
|
|
2
3
|
import { spawnSync } from 'node:child_process';
|
|
3
4
|
import { existsSync, readFileSync } from 'node:fs';
|
|
4
5
|
import { isAbsolute, join } from 'node:path';
|
|
@@ -67,7 +68,7 @@ export function withDeadline(run, deadlineMs = GATE_DEADLINE_MS, now = Date.now)
|
|
|
67
68
|
return (cmd, args, opts) => {
|
|
68
69
|
const left = deadline - now();
|
|
69
70
|
if (left <= 0) return { status: null, error: 'ETIMEDOUT', stdout: '', stderr: '' };
|
|
70
|
-
return run(cmd, args, { ...opts, timeoutMs: Math.min(SPAWN_CAP_MS, left) });
|
|
71
|
+
return run(cmd, args, { ...opts, timeoutMs: Math.min(opts.timeoutMs ?? SPAWN_CAP_MS, SPAWN_CAP_MS, left) });
|
|
71
72
|
};
|
|
72
73
|
}
|
|
73
74
|
|
|
@@ -104,16 +105,67 @@ export function findBase(root, env, run = spawnRunner) {
|
|
|
104
105
|
return null;
|
|
105
106
|
}
|
|
106
107
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
108
|
+
// @comment -- "The @ticket exception comes from GuardLink's parsed tickets at their logical source file. A string in product code and a sidecar for another asset or threat cannot authorize a confirmed claim."
|
|
109
|
+
export function hasTicket(tickets, claim) {
|
|
110
|
+
return tickets.some((t) => t?.file === claim.location.file && t.threat === claim.threat &&
|
|
111
|
+
t.asset === claim.asset && typeof t.ref === 'string' && t.ref.trim() !== '');
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// @comment -- "Ledger-only confirmations are first-class at the PR gate. Match the evidence to its exact physical annotation, then use the parsed logical file and origin for the Git intersection. Reproduction on an earlier anchor is a retest obligation."
|
|
115
|
+
function ledgerGateClaims(root, run, options) {
|
|
116
|
+
if (!existsSync(join(root, '.guardlink', 'hypotheses.json'))) return { claims: [] };
|
|
117
|
+
const ledger = runJson(run, 'guardlink hypothesis list', 'guardlink', ['hypothesis', 'list', '--json'], options);
|
|
118
|
+
if (!ledger.ok) return ledger;
|
|
119
|
+
if (ledger.json?.ledger !== 'present' || !Array.isArray(ledger.json.records)) return { error: 'GuardLink hypothesis ledger unreadable' };
|
|
120
|
+
const records = ledger.json.records.filter(r => ['confirmed', 'retest'].includes(r.state) && r.outcome?.outcome === 'confirmed');
|
|
121
|
+
if (!records.length) return { claims: [] };
|
|
122
|
+
const model = runJson(run, 'guardlink parse', 'guardlink', ['parse', '.'], options);
|
|
123
|
+
if (!model.ok) return model;
|
|
124
|
+
if (!Array.isArray(model.json?.exposures)) return { error: 'GuardLink model has no exposures list' };
|
|
125
|
+
const claims = [];
|
|
126
|
+
for (const r of records) {
|
|
127
|
+
const matches = model.json.exposures.filter(e => e.threat === r.threat && e.asset === r.asset &&
|
|
128
|
+
(e.location?.origin_file ?? e.location?.file) === r.file && (e.location?.origin_line ?? e.location?.line) === r.line);
|
|
129
|
+
if (matches.length !== 1 || !r.key) return { error: 'a tested GuardLink claim could not be associated with one source location' };
|
|
130
|
+
const source = r.outcome.source;
|
|
131
|
+
const status = r.expired || r.state === 'retest' ? 'retest due on changed code'
|
|
132
|
+
: source?.kind === 'scan' && source.joined_by !== 'claim-key' ? 'scan association needs review'
|
|
133
|
+
: 'confirmed in ledger';
|
|
134
|
+
claims.push({ ...matches[0], status });
|
|
135
|
+
}
|
|
136
|
+
return { claims };
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function changeReview(root, base, env, run) {
|
|
140
|
+
const o = { cwd: root, env, timeoutMs: 4000 };
|
|
141
|
+
const patch = run('git', gitPatchArgs(base, 'HEAD'), o);
|
|
142
|
+
if (patch.error || patch.status !== 0) return 'Changed-source review unavailable: Git could not read the branch patch.';
|
|
143
|
+
const ranges = parseChangedHunks(patch.stdout);
|
|
144
|
+
if (!ranges.size) return '';
|
|
145
|
+
const work = runJson(run, 'guardlink unannotated', 'guardlink', ['unannotated', '--json'], o);
|
|
146
|
+
if (!work.ok || !Array.isArray(work.json?.annotated) || !Array.isArray(work.json?.worklist)) return 'Changed-source review unavailable: GuardLink did not return its annotated files and worklist.';
|
|
147
|
+
const known = new Set(work.json.annotated);
|
|
148
|
+
const missing = new Set(work.json.worklist.map(w => w.path));
|
|
149
|
+
const removed = [...ranges.values()].filter(hunks => hunks.every(h => h.deleted)).length;
|
|
150
|
+
const sources = [...ranges].filter(([file, hunks]) => (known.has(file) || missing.has(file)) && !hunks.every(h => h.deleted));
|
|
151
|
+
const removedNote = removed ? `${removed} deleted path(s) are outside the current-file worklist; review their prior controls and callers.` : '';
|
|
152
|
+
if (!sources.length) return removedNote;
|
|
153
|
+
const lines = [`Changed source to review (${sources.length} in-scope files). Inspect these ranges for new or changed entry points, controls and sinks:`];
|
|
154
|
+
for (const [file, hunks] of sources.slice(0, 24)) {
|
|
155
|
+
const label = known.has(file) ? 'file already has annotations' : 'no file annotations';
|
|
156
|
+
const spans = hunks.slice(0, 8).map(h => h.start === h.end ? h.start : `${h.start}-${h.end}`).join(',');
|
|
157
|
+
lines.push(` ${JSON.stringify(file)}:${spans}${hunks.length > 8 ? ' (further hunks omitted)' : ''} — ${label}`);
|
|
115
158
|
}
|
|
116
|
-
|
|
159
|
+
if (removedNote) lines.push(removedNote);
|
|
160
|
+
if (sources.length > 24) lines.push(` ${sources.length - 24} further changed files omitted.`);
|
|
161
|
+
const command = `bravos graph annotation-gaps --base ${base} --json`;
|
|
162
|
+
const answer = runJson(run, 'bravos graph annotation-gaps', 'bravos', ['graph','annotation-gaps','--base',base,'--json'], {...o, timeoutMs: 1500});
|
|
163
|
+
const g = answer.json?.result;
|
|
164
|
+
if (g?.graph?.working_tree === 'current' && Array.isArray(g.gaps)) {
|
|
165
|
+
lines.push(`Code graph: ${g.gaps.length} candidate gaps; ${g.complete ? 'complete graph comparison' : 'partial graph comparison'}. Review the code for behavior the graph cannot classify.`);
|
|
166
|
+
for (const gap of g.gaps.slice(0, 8)) lines.push(` ${JSON.stringify(gap.file)}:${gap.line} — ${gap.kind}`);
|
|
167
|
+
} else lines.push(`No current graph result. On the review checkout run ${command}.`);
|
|
168
|
+
return lines.join('\n');
|
|
117
169
|
}
|
|
118
170
|
|
|
119
171
|
/**
|
|
@@ -173,18 +225,35 @@ export function runGate({ root, action, command, cwd = root, env = process.env,
|
|
|
173
225
|
|
|
174
226
|
// (c) a confirmed-exploitable claim on a changed file blocks unless that file carries a @ticket for it.
|
|
175
227
|
const ci = runJson(run, 'guardlink ci -f json', 'guardlink', ['ci', '-f', 'json'], o);
|
|
176
|
-
const
|
|
228
|
+
const ledger = ledgerGateClaims(root, run, o);
|
|
229
|
+
if (ledger.error) unknown(ledger);
|
|
230
|
+
const confirmed = ci.ok && Array.isArray(ci.json?.confirmed) ? [...(ledger.claims ?? []), ...ci.json.confirmed] : undefined;
|
|
177
231
|
if (!ci.ok) unknown(ci);
|
|
178
232
|
else if (!Array.isArray(confirmed)) unknown({ error: 'guardlink ci -f json has no confirmed[]' });
|
|
179
233
|
else if (confirmed.length > 0) {
|
|
180
|
-
const names = run('git', ['diff', '--name-only', `${base}...HEAD`], o);
|
|
234
|
+
const names = run('git', ['diff', '--name-only', '-z', `${base}...HEAD`], o);
|
|
181
235
|
if (names.error || names.status !== 0) unknown({ error: `git diff --name-only ${base}...HEAD ${why(names)}` });
|
|
182
236
|
else {
|
|
183
|
-
const changed = new Set(names.stdout.split('\
|
|
184
|
-
const
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
237
|
+
const changed = new Set(names.stdout.split('\0').filter(Boolean));
|
|
238
|
+
const relevant = confirmed.filter(c => changed.has(c?.location?.file) || changed.has(c?.location?.origin_file));
|
|
239
|
+
const sameClaimSite = (a, b) => a.threat === b.threat && a.asset === b.asset && a.location.file === b.location.file &&
|
|
240
|
+
(a.location.line === b.location.line || (a.location.anchor?.scope === 'symbol' && b.location.anchor?.scope === 'symbol' &&
|
|
241
|
+
a.location.anchor.start_line === b.location.anchor.start_line && a.location.anchor.hash === b.location.anchor.hash));
|
|
242
|
+
const affected = relevant.filter(c => c.status || !relevant.some(l => l.status && sameClaimSite(c, l)));
|
|
243
|
+
if (affected.length) {
|
|
244
|
+
const lookup = runJson(run, 'guardlink lookup tickets', 'guardlink', ['lookup', 'tickets'], o);
|
|
245
|
+
if (!lookup.ok) unknown(lookup);
|
|
246
|
+
else if (lookup.json?.type !== 'tickets' || !Array.isArray(lookup.json.results)) unknown({ error: 'guardlink lookup tickets returned no ticket list' });
|
|
247
|
+
else {
|
|
248
|
+
const hits = affected.filter(c => !hasTicket(lookup.json.results, c));
|
|
249
|
+
for (const c of affected.filter(c => c.status && hasTicket(lookup.json.results, c))) {
|
|
250
|
+
notes.push(`Tracked by @ticket: ${c.threat} on ${c.asset} at ${JSON.stringify(c.location.file)}:${c.location.line} [${c.status}].`);
|
|
251
|
+
}
|
|
252
|
+
if (hits.length) {
|
|
253
|
+
const list = hits.map(c => ` - ${c.severity ?? 'unrated'} ${c.threat} on ${c.asset} — ${c.location.file}:${c.location.line ?? '?'}${c.status ? ` [${c.status}]` : ' [source @confirmed]'}`);
|
|
254
|
+
blocks.push(`confirmed claims or unresolved retests on changed source have no matching @ticket. A code change does not clear a confirmation; do not ship (bravos-ship step 7):\n${list.join('\n')}`);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
188
257
|
}
|
|
189
258
|
}
|
|
190
259
|
}
|
|
@@ -204,6 +273,8 @@ export function runGate({ root, action, command, cwd = root, env = process.env,
|
|
|
204
273
|
else if (body !== null && !/proving preference/i.test(body)) blocks.push(`${say}, then retry.`);
|
|
205
274
|
}
|
|
206
275
|
|
|
276
|
+
const review = changeReview(root, base, env, run);
|
|
277
|
+
if (review) notes.push(review);
|
|
207
278
|
if (blocks.length > 0) return { decision: 'block', reason: ['bravos pre-PR gate: blocked.', ...blocks.map((b) => `- ${b}`), ...notes].join('\n') };
|
|
208
279
|
return { decision: 'allow', reason: notes.join('\n') };
|
|
209
280
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"guardlink": {
|
|
3
|
+
"version": "2.6.0",
|
|
4
|
+
"repository": "https://github.com/Bugb-Technologies/guardlink.git",
|
|
5
|
+
"revision": null
|
|
6
|
+
},
|
|
7
|
+
"cxg": {
|
|
8
|
+
"version": "1.8.0",
|
|
9
|
+
"repository": "https://github.com/Bugb-Technologies/cert-x-gen.git",
|
|
10
|
+
"revision": null
|
|
11
|
+
}
|
|
12
|
+
}
|