@bugb-technologies/bravos 1.5.2 → 1.6.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 (38) hide show
  1. package/dist/artifacts.js +31 -1
  2. package/dist/cli.js +78 -5
  3. package/dist/codegraph.js +32 -4
  4. package/dist/context.js +351 -0
  5. package/dist/dashboard.js +35 -10
  6. package/dist/guide.js +3 -0
  7. package/dist/help.js +19 -0
  8. package/dist/report/data.js +2 -1
  9. package/dist/rules.js +218 -0
  10. package/dist/setup.js +33 -7
  11. package/dist/uninstall.js +6 -0
  12. package/dist/versions.js +1 -1
  13. package/dist/watch-frame.js +8 -1
  14. package/dist/watch.js +11 -2
  15. package/docs/GUIDE.md +18 -0
  16. package/docs/UPGRADING.md +30 -0
  17. package/hooks/lib/autopilot.mjs +29 -7
  18. package/hooks/lib/briefing.mjs +29 -5
  19. package/hooks/lib/context.mjs +522 -0
  20. package/hooks/lib/pre-pr.mjs +70 -0
  21. package/hooks/lib/setup.mjs +5 -2
  22. package/package.json +1 -1
  23. package/skills/bravos/SKILL.md +1 -1
  24. package/skills/bravos-annotate/SKILL.md +5 -3
  25. package/skills/bravos-annotate/scripts/lib/gate.mjs +45 -0
  26. package/skills/bravos-annotate/scripts/slice.mjs +10 -0
  27. package/skills/bravos-campaign/SKILL.md +1 -1
  28. package/skills/bravos-codegraph/SKILL.md +1 -1
  29. package/skills/bravos-context/SKILL.md +16 -10
  30. package/skills/bravos-context/intent.example.md +14 -1
  31. package/skills/bravos-recheck/SKILL.md +1 -1
  32. package/skills/bravos-ship/SKILL.md +2 -1
  33. package/skills/bravos-templatize/SKILL.md +1 -1
  34. package/templates/dashboard/dashboard.html +97 -0
  35. package/templates/workflows/bravos-nightly-claude.yml +36 -2
  36. package/templates/workflows/bravos-nightly-codex.yml +36 -2
  37. package/templates/workflows/bravos-nightly-copilot.yml +23 -0
  38. package/templates/workflows/bravos-pr-gate.yml +76 -0
package/docs/UPGRADING.md CHANGED
@@ -2,6 +2,36 @@
2
2
 
3
3
  After `npm install -g @bugb-technologies/bravos`, run **`bravos setup --tools -y`** once on each machine and **`bravos sync`** in each repository. The notes below say what else changes, newest first.
4
4
 
5
+ ## 1.6.0
6
+
7
+ 1.6 makes threat modelling start from your design. Bravos now asks for your design documents, keeps them in the repository, turns what they state into rules it can test, and shows which rules hold.
8
+
9
+ - **Context now comes first. This changes what happens after `bravos sync`.** The annotate skill, campaigns, the after-edit notes that ask for annotation and the nightly annotate job all wait until a named person has confirmed at least one item of `.guardlink/intent.md`. A repository with no intent, or with a draft nobody confirmed, stops annotating until one of two things happens:
10
+ - you run the context step (ask your agent to "learn what this app intends"), or
11
+ - a named person records that the team goes without: `bravos context decline --by "<name>"`, then commit `.bravos/context/status.json`.
12
+
13
+ `bravos context gate` says which state a repository is in. Rechecks, retests and the ship check are not held back.
14
+ - **Design documents live in the repository.** Give the context step your PRDs, design documents or an earlier threat model, as files or links. Each is stored as Markdown under `.bravos/context/` and committed, so the team can keep it current; a link is kept beside its snapshot. `bravos context add | update | list | check`.
15
+ - A document carrying a secret, a local path or an embedded image is refused, by line number.
16
+ - A git pre-push check stops a push that would send one. It is installed in a clone only when that clone has no pre-push hook; otherwise Bravos prints the one line to add.
17
+ - Everyone with access to the repository can read these documents.
18
+ - **Rules name where they came from.** `intent.md` gains a Sources section and a "Who may do what" table, and each rule cites its document (`INV-4 … (source: SRC-2 "Report access")`).
19
+ - **A rule that holds can be tested.** The annotate skill now writes where a rule could break beside the check that stops it. Checks recorded before 1.6 show as "guarded, untested" until the next annotation pass rewrites them.
20
+ - **`bravos rules` and a Design rules tab in `bravos dashboard`** list every rule with its status: broken, retest due, unguarded, guarded but untested, not placed, or holds.
21
+ - **A change under a rule is noticed (Team plan).** The pre-PR check and the PR workflow hold a pull request that changes a file a holding rule is enforced or granted in, after that rule was last tested, until its test is replayed or the PR body names the rule (its INV id). This is conservative: an unrelated edit to such a file asks for the same.
22
+ - **For scripts:** the annotate skill's `slice.mjs` exits 3 with only `gate` and `notes` in its JSON while the gate is closed; `bravos dashboard --json` and the page's data gain a `rules` field.
23
+ - Run `bravos sync` in each repository to get the updated skills, hooks and workflows.
24
+
25
+ ## 1.5.3
26
+
27
+ 1.5.3 ships with code graph 0.1.1 (Team plan), which fixes the fault 1.5.2 worked around.
28
+
29
+ - **Run `bravos setup` once on each machine.** It now fetches the newer code graph when the one you have is older; before, it said "already staged" and you stayed on 0.1.0 unless you added `-y`. `bravos setup --check` says when a bundle is behind. If the download fails, the one you have keeps working and setup says so.
30
+ - **Several sessions on one repository all get an answer.** The graph used to tell all but one of them "No CodeGraph … Index the repository", and kept saying it to that session until it was restarted. It now waits its turn (up to 20 seconds).
31
+ - **A graph that is in use says "busy", not "no graph".** This happens while a build runs. `bravos graph` prints `graph_busy` with "ask again in a moment", `bravos watch` shows `GRAPH busy` and keeps what it last read, and `bravos dashboard` says the graph is busy and builds nothing. None of these is a reason to rebuild.
32
+ - **For scripts:** `bravos graph … --json` can now answer `{"error":"graph_busy"}` with exit 1. Exit 2 still means the graph is not built.
33
+ - Graphs built with 0.1.0 are read as they are; nothing needs rebuilding. Run `bravos sync` in each repository to get the updated code graph skill.
34
+
5
35
  ## 1.5.2
6
36
 
7
37
  - **`bravos watch` no longer says "no graph" for a graph that is there.** The code graph answers "no graph" to a question that arrives at the same moment as another one; Bravos now asks again before believing it, and `bravos watch` asks its questions in one go instead of several at once. If you rebuilt a graph because watch told you to, it was not needed.
@@ -2,6 +2,7 @@
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
+ import { contextGate } from './context.mjs';
5
6
  import { gitStaleness, staleness } from './resync.mjs';
6
7
  import { asyncRunner, changedHunks, fingerprint, readSnapshot, workingChanges } from './snapshot.mjs';
7
8
 
@@ -180,12 +181,20 @@ export async function runAutopilot({ root, env = process.env, payload = {}, run
180
181
  }
181
182
  const paths = rows => arr(rows).map(w => typeof w === 'string' ? w : w?.file ?? w?.path)
182
183
  .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.`);
184
+ // Context first. While nobody has confirmed what the product intends (or declined), changed files are not put
185
+ // forward for annotation: one note says why and what to do, in place of a note per file. Notes about claims that
186
+ // already exist (stale, to retest, removed) still follow: they maintain the model, they do not start one.
187
+ const gate = contextGate(root);
188
+ if (!gate.open) {
189
+ if (paths(wl?.worklist).length || paths(wl?.annotated).length) add(`context:${gate.state}`, `${gate.message} The files changed this turn are not being put forward for annotation until then.`);
190
+ } else {
191
+ for (const path of paths(wl?.worklist)) {
192
+ add(`unannotated:${path}`, `${path} has no GuardLink annotation: review the change with bravos-annotate; record any security-relevant behavior.`);
193
+ }
194
+ for (const path of paths(wl?.annotated)) {
195
+ const ranges = hunks.get(path)?.map(h => h.start === h.end ? h.start : `${h.start}-${h.end}`).join(', ');
196
+ 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.`);
197
+ }
189
198
  }
190
199
 
191
200
  const excluded = new Set(arr(wl?.excluded).map(e => e?.path ?? e?.file));
@@ -228,6 +237,18 @@ export async function runAutopilot({ root, env = process.env, payload = {}, run
228
237
  if (!controls.has(pair)) controls.set(pair, []);
229
238
  controls.get(pair).push(m.location);
230
239
  }
240
+ // A claim against a design rule (a threat the team's intent states, #inv-…) is named as one, with its INV id when
241
+ // the threat carries it, so the agent knows a rule from the design is what the edit sits under.
242
+ const ruleIds = new Map();
243
+ for (const t of arr(model?.threats)) {
244
+ const id = String(t?.id ?? '').replace(/^#/, '');
245
+ if (/^inv-/i.test(id)) ruleIds.set(id, arr(t.external_refs).map(r => /^intent:(INV-\d+)$/i.exec(String(r))?.[1]).find(Boolean) ?? null);
246
+ }
247
+ const ruleOf = (threat) => {
248
+ const id = String(threat ?? '').replace(/^#/, '');
249
+ if (!/^inv-/i.test(id)) return '';
250
+ return `design rule ${ruleIds.get(id) ? `${ruleIds.get(id)} ` : ''}`;
251
+ };
231
252
  const pref = readProving(root);
232
253
  if (ledger?.ledger === 'corrupt') {
233
254
  add('ledger:corrupt', 'GuardLink could not read the hypothesis ledger. Restore its evidence before treating any claim as untested or running a retest.');
@@ -247,7 +268,8 @@ export async function runAutopilot({ root, env = process.env, payload = {}, run
247
268
  // A current refutation holds until its anchor or a separate control changes.
248
269
  if (record.state === 'refuted' && !affectedControls.length) continue;
249
270
  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)}.`);
271
+ const rule = ruleOf(record.threat);
272
+ add(`proof:${record.key}:${record.state}`, `${retest ? 'Retest' : 'Untested'} ${rule}${record.threat} on ${record.asset} at ${loc.file}:${loc.line} (claim ${record.key}): ${proofInstruction(pref, retest)}.${rule && retest ? ' If a PR is opened before it is retested, name the rule in the PR body.' : ''}`);
251
273
  }
252
274
  } else {
253
275
  // A legacy/unavailable ledger cannot report coverage of mitigated claims.
@@ -2,6 +2,7 @@
2
2
  import { spawn, spawnSync } from 'node:child_process';
3
3
  import { accessSync, constants, readFileSync } from 'node:fs';
4
4
  import { basename, delimiter, dirname, join } from 'node:path';
5
+ import { contextGate, readContext } from './context.mjs';
5
6
  import { THEMES } from './palette.mjs';
6
7
  import { readProving } from './proving.mjs';
7
8
  import { planLabel, planLine, status as licenceStatus } from './licence.mjs';
@@ -115,10 +116,28 @@ export function readIntent(root) {
115
116
  return { status: drafts > 0 ? 'draft' : 'confirmed', invariants, drafts };
116
117
  }
117
118
 
118
- function intentLine(intent, harness) {
119
+ // @comment -- "The briefing's line about the team's design documents, when there are any: how many, by id, that the rules cite them and that only the context skill opens them; and when the intent has fallen behind a document (edited, or added since), which ones and how to refresh. Ids only, never a title or any text from a document."
120
+ export function contextLine(context, harness) {
121
+ if (!context || typeof context !== 'object' || !context.count) return null;
119
122
  const run = harness === 'claude' ? '/bravos-context' : 'the bravos-context skill';
120
- if (intent.status === 'none') return `Intent: none — severities are not calibrated to the product; run ${run}`;
121
- if (intent.status === 'draft') return `Intent: draft (${intent.invariants} invariants, ${intent.drafts} items unconfirmed) — confirm with ${run}`;
123
+ const list = (ids) => (ids.length > 6 ? `${ids.slice(0, 6).join(', ')} and ${ids.length - 6} more` : ids.join(', '));
124
+ const behind = [
125
+ context.changed?.length ? `${list(context.changed)} changed since the rules were written` : '',
126
+ context.unread?.length ? `${list(context.unread)} not read into the intent yet` : '',
127
+ ].filter(Boolean);
128
+ const head = `Design documents: ${context.count} in .bravos/context/ (${list(context.ids ?? [])})`;
129
+ return behind.length
130
+ ? `${head} — ${behind.join('; ')}: refresh the intent with ${run}`
131
+ : `${head} — intent.md's rules cite them by id; only ${run} opens the documents themselves`;
132
+ }
133
+
134
+ // @comment -- "The briefing's Intent line. While the context gate is closed it also says so in words an agent acts on: do not start threat-modelling, run the context skill first, and how a person declines. A recorded decline is shown with the name and date of the person who made it."
135
+ function intentLine(intent, harness, gate) {
136
+ const run = harness === 'claude' ? '/bravos-context' : 'the bravos-context skill';
137
+ const closed = gate && gate.open === false ? `. Context comes first: do not annotate or start a campaign until a named person has confirmed it (or run bravos context decline --by "<name>" themselves).` : '';
138
+ const declined = gate?.state === 'declined' ? `declined by ${gate.by} on ${gate.at}` : '';
139
+ if (intent.status === 'none') return declined ? `Intent: ${declined} — severities are not calibrated to the product; ${run} when the team is ready` : `Intent: none — severities are not calibrated to the product; run ${run}${closed}`;
140
+ if (intent.status === 'draft') return `Intent: draft (${intent.invariants} invariants, ${intent.drafts} items unconfirmed${declined ? `; context ${declined}` : ''}) — confirm with ${run}${closed}`;
122
141
  return `Intent: confirmed (${intent.invariants} invariants)`;
123
142
  }
124
143
 
@@ -213,7 +232,9 @@ export function buildBriefing(inputs) {
213
232
  else if (i.inFlight.prs > 0 || i.inFlight.files > 0) {
214
233
  tail.push(`In flight by teammates: ${i.inFlight.files} files in ${i.inFlight.prs} open PRs`);
215
234
  }
216
- if (i.intent && typeof i.intent === 'object') tail.push(intentLine(i.intent, i.harness));
235
+ if (i.intent && typeof i.intent === 'object') tail.push(intentLine(i.intent, i.harness, i.gate));
236
+ const documents = contextLine(i.context, i.harness);
237
+ if (documents) tail.push(documents);
217
238
  if (i.proving && typeof i.proving === 'object') {
218
239
  const p = i.proving;
219
240
  tail.push(p.status === 'set'
@@ -462,6 +483,8 @@ export async function collect(root, env, { deadlineMs = 20000, nextCount = 3 } =
462
483
  dashboard: facts.dashboard,
463
484
  inFlight,
464
485
  intent: readIntent(root),
486
+ context: readContext(root),
487
+ gate: contextGate(root),
465
488
  annotationMode: readAnnotationMode(root),
466
489
  // bravos on PATH: what its probe says (a graph for this commit or not); else codegraph-mcp on PATH means the MCP route.
467
490
  codegraph: graphState ?? (whichOnPath('codegraph-mcp', env) ? 'unknown' : 'unavailable'),
@@ -635,7 +658,8 @@ export function quickStart(inputs, harness) {
635
658
  const picks = [];
636
659
  if (inputs?.stale || arr(inputs?.stranded).length > 0) picks.push('bravos-resync');
637
660
  if (arr(ci?.confirmed).length > 0) picks.push('bravos-recheck');
638
- if (inputs?.intent?.status === 'none') picks.push('bravos-context');
661
+ // Context first: with no intent, or one nobody has confirmed, the context skill is the start, ahead of everything else.
662
+ if (inputs?.intent?.status === 'none' || inputs?.gate?.open === false) picks.push('bravos-context');
639
663
  const cov = ci?.summary?.coverage;
640
664
  if (cov && num(cov.source_files) > num(cov.annotated_files)) picks.push('bravos-annotate');
641
665
  if (arr(g.next?.queue).some((q) => q?.state === 'untested')) picks.push('bravos-templatize');