@bugb-technologies/bravos 1.3.0 → 1.4.1

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 (42) hide show
  1. package/README.md +17 -10
  2. package/dist/ci.js +11 -3
  3. package/dist/cli.js +16 -6
  4. package/dist/doctor.js +2 -2
  5. package/dist/guide.js +2 -2
  6. package/dist/help.js +10 -14
  7. package/dist/install-proof-tool.js +117 -0
  8. package/dist/proof-tools.js +29 -0
  9. package/dist/report/check.js +4 -1
  10. package/dist/report/data.js +81 -149
  11. package/dist/report/markdown.js +1 -1
  12. package/dist/report/redact.js +16 -0
  13. package/dist/report/runs.js +169 -0
  14. package/dist/setup.js +43 -19
  15. package/dist/start/answers.js +5 -3
  16. package/dist/start/index.js +28 -14
  17. package/dist/versions.js +5 -4
  18. package/docs/GUIDE.md +2 -2
  19. package/hooks/lib/autopilot.mjs +155 -37
  20. package/hooks/lib/briefing.mjs +9 -3
  21. package/hooks/lib/nightly-stage.mjs +66 -0
  22. package/hooks/lib/nightly-tools.sh +45 -0
  23. package/hooks/lib/pre-pr.mjs +88 -17
  24. package/hooks/lib/proof-tool-pins.json +12 -0
  25. package/hooks/lib/replay.mjs +579 -0
  26. package/hooks/lib/setup.mjs +15 -6
  27. package/hooks/lib/snapshot.mjs +75 -9
  28. package/package.json +1 -1
  29. package/skills/bravos/SKILL.md +1 -1
  30. package/skills/bravos-annotate/SKILL.md +6 -5
  31. package/skills/bravos-annotate/scripts/slice.mjs +15 -8
  32. package/skills/bravos-cicd/SKILL.md +1 -1
  33. package/skills/bravos-env/SKILL.md +3 -3
  34. package/skills/bravos-prove/SKILL.md +11 -15
  35. package/skills/bravos-recheck/SKILL.md +3 -3
  36. package/skills/bravos-report/SKILL.md +1 -1
  37. package/skills/bravos-schedule/SKILL.md +1 -1
  38. package/skills/bravos-ship/SKILL.md +1 -1
  39. package/skills/bravos-templatize/SKILL.md +3 -3
  40. package/templates/workflows/bravos-nightly-claude.yml +131 -74
  41. package/templates/workflows/bravos-nightly-codex.yml +130 -73
  42. package/templates/workflows/bravos-pr-gate.yml +88 -14
@@ -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) tail.push('Autopilot: on — an end-of-turn check sends you back once if changed code lacks annotations, sits under a confirmed or stale claim, or adds exposures to prove');
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
- return `intent ${intent} · ${graph} · pre-PR ${i.prePr ? 'on' : 'off'} · auto ${i.autopilot ? 'on' : 'off'} · ${sast}${setup ? ` · setup ${setup.done}/${setup.total}` : ''}`;
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
@@ -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
+ }