@bugb-technologies/bravos 1.2.1 → 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.
Files changed (47) hide show
  1. package/README.md +17 -10
  2. package/dist/ci.js +11 -3
  3. package/dist/cli.js +50 -8
  4. package/dist/doctor.js +4 -16
  5. package/dist/guide.js +5 -3
  6. package/dist/help.js +16 -16
  7. package/dist/hooks.js +21 -0
  8. package/dist/install-proof-tool.js +117 -0
  9. package/dist/proof-tools.js +29 -0
  10. package/dist/report/check.js +4 -1
  11. package/dist/report/data.js +81 -149
  12. package/dist/report/markdown.js +1 -1
  13. package/dist/report/redact.js +16 -0
  14. package/dist/report/runs.js +169 -0
  15. package/dist/resync.js +272 -0
  16. package/dist/setup.js +31 -16
  17. package/dist/start/answers.js +5 -3
  18. package/dist/start/index.js +28 -14
  19. package/dist/versions.js +4 -3
  20. package/docs/GUIDE.md +12 -2
  21. package/hooks/lib/autopilot.mjs +216 -77
  22. package/hooks/lib/briefing.mjs +36 -5
  23. package/hooks/lib/nightly-stage.mjs +66 -0
  24. package/hooks/lib/nightly-tools.sh +45 -0
  25. package/hooks/lib/pre-pr.mjs +88 -17
  26. package/hooks/lib/proof-tool-pins.json +12 -0
  27. package/hooks/lib/replay.mjs +579 -0
  28. package/hooks/lib/resync.mjs +78 -0
  29. package/hooks/lib/setup.mjs +15 -6
  30. package/hooks/lib/snapshot.mjs +189 -0
  31. package/hooks/session-start.mjs +7 -3
  32. package/package.json +1 -1
  33. package/skills/bravos/SKILL.md +2 -1
  34. package/skills/bravos-annotate/SKILL.md +6 -5
  35. package/skills/bravos-annotate/scripts/slice.mjs +15 -8
  36. package/skills/bravos-cicd/SKILL.md +1 -1
  37. package/skills/bravos-env/SKILL.md +3 -3
  38. package/skills/bravos-prove/SKILL.md +11 -15
  39. package/skills/bravos-recheck/SKILL.md +3 -3
  40. package/skills/bravos-report/SKILL.md +1 -1
  41. package/skills/bravos-resync/SKILL.md +52 -0
  42. package/skills/bravos-schedule/SKILL.md +1 -1
  43. package/skills/bravos-ship/SKILL.md +1 -1
  44. package/skills/bravos-templatize/SKILL.md +3 -3
  45. package/templates/workflows/bravos-nightly-claude.yml +131 -74
  46. package/templates/workflows/bravos-nightly-codex.yml +130 -73
  47. package/templates/workflows/bravos-pr-gate.yml +88 -14
@@ -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
- /** Whether `file` (repo-relative, under root) has a `@ticket` line naming both `threat` and `asset`. */
108
- // @comment -- "The ship gate's carve-out for a confirmed claim: a @ticket line in the same file naming that threat and that asset. Who wrote it is bravos-ship's check (blame), not this hook's."
109
- export function hasTicket(root, file, threat, asset) {
110
- let text;
111
- try {
112
- text = readFileSync(isAbsolute(file) ? file : join(root, file), 'utf8');
113
- } catch {
114
- return false;
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
- return text.split('\n').some((l) => l.includes('@ticket') && mentionsId(l, threat) && mentionsId(l, asset));
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 confirmed = ci.ok ? ci.json?.confirmed : undefined;
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('\n').map((s) => s.trim()).filter(Boolean));
184
- const hits = confirmed.filter((c) => changed.has(c?.location?.file) && !hasTicket(root, c.location.file, c?.threat, c?.asset));
185
- if (hits.length > 0) {
186
- const list = hits.map((c) => ` - ${c?.severity ?? 'unrated'} ${c?.threat ?? '?'} on ${c?.asset ?? '?'} — ${c.location.file}:${c?.location?.line ?? '?'}`);
187
- blocks.push(`confirmed-exploitable claims sit on files this branch changes, with no @ticket for them in that file. A code change does not clear a confirmation; do not ship (bravos-ship step 7):\n${list.join('\n')}`);
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
+ }