@bugb-technologies/bravos 1.12.1 → 1.14.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/dist/cli.js CHANGED
@@ -332,6 +332,9 @@ function pipeline(root, io, opts, withGuardlink, lines) {
332
332
  for (const s of wf.skipped)
333
333
  lines.push(` skipped ${s.path} — ${s.reason}`);
334
334
  workflowWritten = [...wf.written, ...wf.updated];
335
+ // @comment -- "The nightly's team view is off until the repository variable is set; a run that writes a nightly says how to turn it on."
336
+ if (!dryRun && wf.written.some((p) => p.includes('bravos-nightly-')))
337
+ lines.push('Team view (off): gh variable set BRAVOS_THREAT_ISSUES --body on makes the nightly open an issue for each critical or high threat still untested after 2 days.');
335
338
  }
336
339
  else if (!withGuardlink) {
337
340
  // A plain sync leaves workflows alone, but says when the installed ones are older than this bravos.
@@ -878,7 +881,7 @@ export function buildProgram(io, result) {
878
881
  // @comment -- "bravos prefs: what this person told Bravos once so no session asks again. `prefs get` shows it; `prefs set commits <commit|leave|ask> --by <name>` records the answer about committing Bravos's own files, `prefs set annotate <background|off> --by <name>` whether each session starts a background annotation pass. Kept under the git directory of this clone, never committed."
879
882
  program
880
883
  .command('prefs <action> [args...]')
881
- .description('Your standing answers for this clone, kept under its git directory and never committed: `prefs get` shows them; `prefs set commits <commit|leave|ask> --by "<your name>"` says whether your agent commits Bravos\'s own files (annotations, intent, definitions, tests) without asking, always leaves them for you, or asks each session; `prefs set annotate <background|off> --by "<your name>"` says whether each session starts one background annotation pass while coverage is incomplete (background is the default); `prefs set coach <on|off> --by "<your name>"` says whether the coach adds reminders before prompts (on is the default). Free; runs no model.')
884
+ .description('Your standing answers for this clone, kept under its git directory and never committed: `prefs get` shows them; `prefs set commits <commit|leave|ask> --by "<your name>"` says whether your agent commits Bravos\'s own files (annotations, intent, definitions, tests) without asking, always leaves them for you, or asks each session; `prefs set annotate <background|off> --by "<your name>"` says whether each session starts one background annotation pass while coverage is incomplete (background is the default); `prefs set coach <on|off> --by "<your name>"` says whether the coach adds reminders before prompts (on is the default); `prefs set cards <on|off>` whether a threat card shows when an edit adds an untested critical or high threat (on), and `prefs set notify <on|off>` whether it also sends a desktop notification (off). Free; runs no model.')
882
885
  .option('-C, --dir <dir>', 'the repository (default: the current directory)')
883
886
  .option('--by <name>', 'set: whose answer this is')
884
887
  .option('--json', 'get: print JSON')
@@ -887,10 +890,10 @@ export function buildProgram(io, result) {
887
890
  const dir = dirArg(opts.dir);
888
891
  if (action === 'get' && args.length === 0)
889
892
  lines.push(...(await getPrefs(dir, io.env, !!opts.json)));
890
- else if (action === 'set' && (args[0] === 'commits' || args[0] === 'annotate' || args[0] === 'coach') && args.length === 2)
893
+ else if (action === 'set' && ['commits', 'annotate', 'coach', 'cards', 'notify'].includes(args[0]) && args.length === 2)
891
894
  lines.push(...(await setPref(dir, args[0], args[1], opts.by, io.env)));
892
895
  else
893
- throw new BravosError('usage: bravos prefs get [--json] | bravos prefs set commits <commit|leave|ask> --by "<your name>" | bravos prefs set annotate <background|off> --by "<your name>" | bravos prefs set coach <on|off> --by "<your name>"');
896
+ throw new BravosError('usage: bravos prefs get [--json] | bravos prefs set commits <commit|leave|ask> --by "<your name>" | bravos prefs set annotate <background|off> --by "<your name>" | bravos prefs set coach|cards|notify <on|off> --by "<your name>"');
894
897
  }));
895
898
  // @comment -- "bravos rules: the design rules (INV-n in the intent, each a #inv- threat) with where the code enforces each and what testing has shown. Read-only and free; runs guardlink parse and hypothesis list, no model."
896
899
  program
package/dist/doctor.js CHANGED
@@ -4,7 +4,7 @@ import { join } from 'node:path';
4
4
  import { installedGuardlinkSkills, whichBin } from './guardlink.js';
5
5
  import { graphBin } from './codegraph.js';
6
6
  import { findAnalyzer, findLicence } from './graphbin.js';
7
- import { ALL_AUTOPILOT_COMMANDS, ALL_COACH_COMMANDS, ALL_PRE_PR_COMMANDS, HOOK_COMMANDS, LEGACY_HOOK_COMMAND, RELATIVE_HOOK_COMMANDS, hookRegistered } from './hooks.js';
7
+ import { ALL_AUTOPILOT_COMMANDS, ALL_CARDS_COMMANDS, ALL_COACH_COMMANDS, ALL_PRE_PR_COMMANDS, HOOK_COMMANDS, LEGACY_HOOK_COMMAND, RELATIVE_HOOK_COMMANDS, hookRegistered } from './hooks.js';
8
8
  import { skillsRoot } from './skills.js';
9
9
  import { resolveTheme } from './palette.js';
10
10
  import { pathToFileURL } from 'node:url';
@@ -71,6 +71,10 @@ export function runDoctor(root, env = process.env) {
71
71
  claude: hookRegistered(join(root, '.claude', 'settings.json'), 'Stop', ALL_AUTOPILOT_COMMANDS),
72
72
  codex: hookRegistered(join(root, '.codex', 'hooks.json'), 'Stop', ALL_AUTOPILOT_COMMANDS),
73
73
  },
74
+ cards: {
75
+ claude: hookRegistered(join(root, '.claude', 'settings.json'), 'PostToolUse', ALL_CARDS_COMMANDS),
76
+ codex: hookRegistered(join(root, '.codex', 'hooks.json'), 'PostToolUse', ALL_CARDS_COMMANDS),
77
+ },
74
78
  coach: {
75
79
  claude: hookRegistered(join(root, '.claude', 'settings.json'), 'UserPromptSubmit', ALL_COACH_COMMANDS),
76
80
  codex: hookRegistered(join(root, '.codex', 'hooks.json'), 'UserPromptSubmit', ALL_COACH_COMMANDS),
@@ -142,6 +146,7 @@ export function formatDoctor(r) {
142
146
  `hooks claude: ${yn(r.hooks.claude)} codex: ${yn(r.hooks.codex)}`,
143
147
  `pre-pr claude: ${yn(r.pre_pr.claude)} codex: ${yn(r.pre_pr.codex)}${r.pre_pr.claude || r.pre_pr.codex ? '' : ' (opt-in: bravos setup --pre-pr-hook)'}`,
144
148
  `autopilot claude: ${yn(r.autopilot.claude)} codex: ${yn(r.autopilot.codex)}${r.autopilot.claude || r.autopilot.codex ? '' : ' (opt-in: bravos setup --autopilot)'}`,
149
+ `cards claude: ${yn(r.cards.claude)} codex: ${yn(r.cards.codex)}${r.cards.claude || r.cards.codex ? (process.env.BRAVOS_THREAT_CARDS === 'off' ? ' (off for this run: BRAVOS_THREAT_CARDS=off)' : '') : ' (bravos setup adds it)'}`,
145
150
  `coach claude: ${yn(r.coach.claude)} codex: ${yn(r.coach.codex)}${r.coach.claude || r.coach.codex ? (process.env.BRAVOS_COACH === 'off' ? ' (off for this run: BRAVOS_COACH=off)' : '') : ' (bravos setup adds it)'}`,
146
151
  ...(r.legacy_skills?.length ? [`✘ old Python bravos skills ${r.legacy_skills.map((f) => `${f.root}: ${f.names.join(', ')}`).join('; ')} — your agent may load them instead of this repository's. Move them aside (reversible): ${r.legacy_command}`] : r.legacy_skills ? ['✔ no old Python bravos skills at user level'] : []),
147
152
  ...(r.updates ? [updatesLine(r.updates)] : []),
package/dist/guide.js CHANGED
@@ -102,6 +102,7 @@ export const GUIDE_TOPICS = [
102
102
  skills: ['bravos-cicd', 'bravos-schedule'],
103
103
  body: [
104
104
  'bravos setup --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.',
105
+ 'The team view is opt-in, in every nightly: set the repository variable BRAVOS_THREAT_ISSUES to on (gh variable set BRAVOS_THREAT_ISSUES --body on; bravos setup asks) and the nightly opens one GitHub issue for each critical or high threat still untested two days after it was committed, labelled bravos, the severity, untested and its CWE. The issue says what to do: test it with bravos-prove, fix it with a @mitigates, or have a named person accept it. A refuted result, a fix, an acceptance or removing the claim closes it by itself. A confirmed result keeps it open, relabelled confirmed, until it is fixed or accepted; a claim whose code changed after its result reopens the issue. BRAVOS_THREAT_ISSUES_DAYS changes the delay.',
105
106
  ],
106
107
  },
107
108
  ],
@@ -117,6 +118,7 @@ export const GUIDE_TOPICS = [
117
118
  { name: 'See which design rules hold', skills: ['bravos', 'bravos-recheck'], body: ['bravos rules lists every rule your design states (INV-n in the intent) with its status: broken (a test got through), retest due (the code under it changed since it was tested), unguarded (it can break somewhere and nothing stops it), guarded but untested, not placed (no code is tied to it yet), or holds (a test tried and was refused everywhere it is enforced). Each line names the document the rule came from and the places it is enforced. bravos dashboard shows the same as its Design rules tab, worst first, beside GuardLink\'s threat model. Free, read-only, no model; --json prints bravos.rules/v1. On the Team plan the pre-PR check and the PR workflow hold a pull request that changes a file a holding rule is enforced in (the check, or the role table that grants the permission) after that rule was last tested, until its test is replayed or the PR body names the rule; the after-edit note says the same while you work.'] },
118
119
  { name: 'The intake asks, it never blocks', skills: ['bravos-context', 'bravos-annotate'], body: ['Annotation starts in the first session. With no confirmed intent, the agent drafts what the product is for from the README, docs and code (.guardlink/intent.md, every item marked draft), annotates against that draft, and opens the intake page without waiting. Each session asks once for a person to confirm it (bravos review intent, a few minutes) until someone confirms or declines; the agent never confirms for you. Rules drafted from the design are tested and can block a pull request right away; bravos rules and the block message label them draft until a person confirms them. When the answers arrive, the agent re-judges what they changed: an item you mark intended by design is annotated as intended, not as a finding. A team that chooses to go without records that under a name, bravos context decline --by "<name>", which is committed like the intent and ends the asking; a coding agent is told never to decline for you. bravos context gate says which state a repository is in.'] },
119
120
  { name: 'Updates', skills: ['bravos'], body: ['Bravos tells you when it is updated. At most once a day a session start asks the npm registry, in a background process the session never waits on, for the latest published version: the same request npm install makes, with only the package name. A newer version shows in the banner and the briefing, and the coach tells a session that is already running, once. Installing it is yours to do (npm install -g @bugb-technologies/bravos); once it is installed the coach has the agent run bravos setup in the repository, which brings its Bravos files up to date. bravos doctor shows the last check. BRAVOS_UPDATE_CHECK=off stops the check, and it never runs in CI.'] },
121
+ { name: 'Threat cards', skills: ['bravos-prove', 'bravos-env'], body: ['When an edit adds a critical or high threat to the threat model (an @exposes claim) that no test has confirmed or refuted, a hook that runs after the edit shows you a card in the terminal straight away: the severity, what the threat is, the claim and where it is, its state, and one next step (bravos-env to set up a test target, where you type the authorization, then bravos-prove). The agent is told to raise it in the same reply and recommend confirming it; it never confirms, refutes or accepts a threat itself. Only lines that are not in the last commit count, so existing claims never raise a card, and each threat raises one card per clone. The hook reads the edited files, their committed copy and the local ledger; it runs no guardlink, no test and no network. bravos watch lists every card. BRAVOS_THREAT_CARDS=off turns cards off for a run and bravos prefs set cards off --by "<your name>" for the clone; bravos prefs set notify on --by "<your name>" adds a desktop notification (macOS and Linux).'] },
120
122
  { name: 'The coach', skills: ['bravos'], body: ['Bravos does not wait to be asked. Before each prompt a fast hook (it runs no guardlink and no network) may add one line for the agent. A question about issues, threats, vulnerabilities, findings or risks builds the dashboard while the agent answers, and opens it in your browser the first time in a session; later questions rebuild it and give the path. From the second prompt on it reminds, each topic once a session and at most one per prompt: claims waiting to be confirmed, with the next step (bravos-env to set up a target, where you type the authorization, then bravos-prove); how much of the code the threat model covers, with the next round; and a dashboard that is older than the model. Skills end every round the same way. bravos watch lists each reminder. BRAVOS_COACH=off turns it off for one run, and bravos prefs set coach off --by "<your name>" for this clone.'] },
121
123
  { name: 'Background annotation', skills: ['bravos-annotate'], body: ['While coverage is under 100%, each new session asks the agent to start one annotation pass in a background subagent (one slice at the default budget) beside whatever you asked, and to tell you in one line. It writes annotations only, never code; it commits only as your commits answer allows (bravos prefs set commits), and otherwise leaves its files for you; it reports the files it covered and the coverage change in one line. It does not run again on resume or compact, nor in CI, where the nightly annotates. bravos prefs set annotate off --by "<your name>" switches it off for this clone (background turns it back on), and BRAVOS_AUTO_ANNOTATE=off for one run. In a harness without subagents the agent offers the pass instead.'] },
122
124
  { name: 'Threat-model someone else\'s project', skills: ['bravos-context', 'bravos-annotate'], body: ['bravos-context assumes you are researching software you do not own (an open-source project, a vendor\'s code): it drafts the intent from upstream\'s own docs with links and asks only the scope decisions — which configuration to rate against (shipped defaults or the hardened setup upstream recommends), single organisation or multi-tenant, which attackers are in scope, and the intended-looking behaviours upstream does not document. intent.md records them as Assumptions, and severities are rated against them. Say "this is our product" for the owner interview instead.'] },
package/dist/help.js CHANGED
@@ -172,6 +172,15 @@ Background annotation
172
172
  switches it off for this clone (background turns it back on); BRAVOS_AUTO_ANNOTATE=off
173
173
  for one run.
174
174
 
175
+ Threat cards
176
+ When an edit adds a critical or high threat (an @exposes claim) that no test has
177
+ confirmed or refuted, a card appears in your terminal right away: what it is, where,
178
+ and the next step (bravos-env for a target, then bravos-prove). The agent raises it in
179
+ the same reply. One card per threat per clone; claims already committed never raise one.
180
+ It reads files and the local ledger only. BRAVOS_THREAT_CARDS=off or
181
+ bravos prefs set cards off turns it off; bravos prefs set notify on adds a desktop
182
+ notification.
183
+
175
184
  The coach
176
185
  Before each prompt a fast hook (no guardlink, no network) may add one line for the agent.
177
186
  A question about issues, threats or vulnerabilities builds the dashboard as the agent
@@ -368,6 +377,13 @@ Flags in depth
368
377
  current scheduled choice and reviewed scope. Configure
369
378
  BRAVOS_SCAN_TARGET, BRAVOS_APP_START for a local build,
370
379
  and BRAVOS_SCAN_AUTH plus private session state for roles.
380
+ Team view, off by default, in every nightly: with the repository variable
381
+ BRAVOS_THREAT_ISSUES=on the nightly opens one GitHub issue per critical or high
382
+ @exposes claim still untested BRAVOS_THREAT_ISSUES_DAYS days (default 2) after it was
383
+ committed (labels bravos, the severity, untested and the CWE). A confirmed claim keeps
384
+ its issue, relabelled confirmed; the issue closes once the claim is refuted, fixed,
385
+ accepted or removed, and reopens when it is untested again. Its job uses only its own
386
+ token: gh variable set BRAVOS_THREAT_ISSUES --body on (bravos setup asks).
371
387
  Needs repository secret CLAUDE_CODE_OAUTH_TOKEN (Claude Code on your Claude plan; run
372
388
  'claude setup-token' once) or OPENAI_API_KEY (Codex), and Settings > Actions >
373
389
  "Allow GitHub Actions to create and approve pull requests". Workflows you wrote or
package/dist/hooks.js CHANGED
@@ -69,6 +69,16 @@ const coach = (h) => ({
69
69
  command: COACH_COMMANDS[h],
70
70
  group: { hooks: [{ type: 'command', command: COACH_COMMANDS[h], timeout: 5 }] },
71
71
  });
72
+ // @comment -- "Threat cards: a PostToolUse hook, registered with the briefing in every repository, that shows the developer a card when an edit adds a critical or high exposure no test has settled (hooks/lib/cards.mjs). Claude Code runs it after its file-editing tools only; Codex names its edit tool differently across versions, so it runs after every tool and the script reads the files from the payload or the working tree."
73
+ export const CARDS_COMMANDS = { claude: hookCommand('claude', 'cards.mjs', HARNESS_ARG.claude), agents: hookCommand('agents', 'cards.mjs', HARNESS_ARG.agents) };
74
+ export const ALL_CARDS_COMMANDS = Object.values(CARDS_COMMANDS);
75
+ const cards = (h) => ({
76
+ event: 'PostToolUse',
77
+ command: CARDS_COMMANDS[h],
78
+ group: h === 'claude'
79
+ ? { matcher: 'Edit|Write|MultiEdit|NotebookEdit', hooks: [{ type: 'command', command: CARDS_COMMANDS[h], timeout: 10 }] }
80
+ : { hooks: [{ type: 'command', command: CARDS_COMMANDS[h], timeout: 10 }] },
81
+ });
72
82
  // The hook script itself only acts on commands that run gh pr create or gh pr ready.
73
83
  const prePr = (h) => ({
74
84
  event: 'PreToolUse',
@@ -205,7 +215,7 @@ function planAgy(root) {
205
215
  const { [OLD_NAME]: _old, ...rest } = doc;
206
216
  return { file: AGY_HOOKS_FILE, changed: true, doc: { ...rest, bravos: AGY_GROUP } };
207
217
  }
208
- // @comment -- "Copies the hook scripts into <root>/.bravos/hooks and registers the SessionStart briefing and the UserPromptSubmit coach, plus the PreToolUse pre-PR gate when prePr is set, for Claude Code (.claude/settings.json), Codex (.codex/hooks.json) and Antigravity (.agents/hooks.json); settings files are validated before anything is written and existing keys and groups are preserved."
218
+ // @comment -- "Copies the hook scripts into <root>/.bravos/hooks and registers the SessionStart briefing, the UserPromptSubmit coach and the PostToolUse threat cards, plus the PreToolUse pre-PR gate when prePr is set, for Claude Code (.claude/settings.json), Codex (.codex/hooks.json) and Antigravity (.agents/hooks.json); settings files are validated before anything is written and existing keys and groups are preserved."
209
219
  export function installHook(root, harnesses, opts = {}) {
210
220
  const src = opts.hooksDir ?? packageHooksDir();
211
221
  const files = listFiles(src).map((abs) => relative(src, abs).split('\\').join('/')).sort();
@@ -214,7 +224,7 @@ export function installHook(root, harnesses, opts = {}) {
214
224
  const withAutopilot = opts.autopilot && !opts.globalHome;
215
225
  const plans = [...new Set(harnesses)].map((h) => planRegistration(root, SETTINGS_FILE[h], [
216
226
  sessionStart(h, opts.globalHome),
217
- ...(opts.globalHome ? [] : [coach(h)]),
227
+ ...(opts.globalHome ? [] : [coach(h), cards(h)]),
218
228
  ...(withPrePr ? [prePr(h)] : []),
219
229
  ...(withAutopilot ? [autopilot(h)] : []),
220
230
  ], [
package/dist/plugin.js CHANGED
@@ -24,7 +24,7 @@ function walk(dir) {
24
24
  }
25
25
  return out;
26
26
  }
27
- // @comment -- "Every file of both plugin builds, computed and not written. plugin/ (Claude Code): skills rendered with ${CLAUDE_SKILL_DIR} and ${CLAUDE_PLUGIN_ROOT}, the hook scripts, a Claude hooks.json, .mcp.json and .claude-plugin/plugin.json. plugin-codex/ (Codex, Agent Plugins layout): skills rendered with repo-relative .agents/skills paths, the hook scripts, hooks/hooks.json in the shape .codex/hooks.json takes with the command under ${PLUGIN_ROOT}, mcp.json and a root plugin.json. Both register SessionStart and the UserPromptSubmit coach (the pre-PR gate stays opt-in through bravos setup) and the guardlink MCP server only. Plus both marketplaces."
27
+ // @comment -- "Every file of both plugin builds, computed and not written. plugin/ (Claude Code): skills rendered with ${CLAUDE_SKILL_DIR} and ${CLAUDE_PLUGIN_ROOT}, the hook scripts, a Claude hooks.json, .mcp.json and .claude-plugin/plugin.json. plugin-codex/ (Codex, Agent Plugins layout): skills rendered with repo-relative .agents/skills paths, the hook scripts, hooks/hooks.json in the shape .codex/hooks.json takes with the command under ${PLUGIN_ROOT}, mcp.json and a root plugin.json. Both register SessionStart, the UserPromptSubmit coach and the PostToolUse threat cards (the pre-PR gate stays opt-in through bravos setup) and the guardlink MCP server only. Plus both marketplaces."
28
28
  export function pluginFiles(opts = {}) {
29
29
  const v = version();
30
30
  const files = [];
@@ -51,12 +51,14 @@ export function pluginFiles(opts = {}) {
51
51
  }],
52
52
  // The coach; its plugin copy stays quiet in a repository that registers its own.
53
53
  UserPromptSubmit: [{ hooks: [{ type: 'command', command: 'node "${CLAUDE_PLUGIN_ROOT}/hooks/coach.mjs" --harness claude', timeout: 5 }] }],
54
+ // Threat cards; the plugin copy also defers to a repository's own.
55
+ PostToolUse: [{ matcher: 'Edit|Write|MultiEdit|NotebookEdit', hooks: [{ type: 'command', command: 'node "${CLAUDE_PLUGIN_ROOT}/hooks/cards.mjs" --harness claude', timeout: 10 }] }],
54
56
  },
55
57
  }));
56
58
  // Codex substitutes ${PLUGIN_ROOT} in plugin hooks; the group is otherwise the one bravos setup writes.
57
59
  const start = sessionStart('agents');
58
60
  const codexStart = { ...start.group, hooks: start.group.hooks.map((h) => ({ ...h, command: 'node "${PLUGIN_ROOT}/hooks/session-start.mjs" --harness codex' })) };
59
- add(`${CODEX_PLUGIN_DIR}/hooks/hooks.json`, json({ hooks: { [start.event]: [codexStart], UserPromptSubmit: [{ hooks: [{ type: 'command', command: 'node "${PLUGIN_ROOT}/hooks/coach.mjs" --harness codex', timeout: 5 }] }] } }));
61
+ add(`${CODEX_PLUGIN_DIR}/hooks/hooks.json`, json({ hooks: { [start.event]: [codexStart], UserPromptSubmit: [{ hooks: [{ type: 'command', command: 'node "${PLUGIN_ROOT}/hooks/coach.mjs" --harness codex', timeout: 5 }] }], PostToolUse: [{ hooks: [{ type: 'command', command: 'node "${PLUGIN_ROOT}/hooks/cards.mjs" --harness codex', timeout: 10 }] }] } }));
60
62
  // guardlink only: cxg and codegraph-mcp are optional, and a server that fails to start on every
61
63
  // machine without its binary is noise. bravos setup adds them per repo when they are installed.
62
64
  const servers = { guardlink: SERVERS.guardlink };
package/dist/prefs.js CHANGED
@@ -16,6 +16,14 @@ const COACH_WHAT = {
16
16
  on: 'add a reminder before a prompt when one is due (coverage, findings to confirm, the dashboard), each once a session',
17
17
  off: 'add no reminders before prompts; the session-start briefing still speaks',
18
18
  };
19
+ const CARDS_WHAT = {
20
+ on: 'show a threat card when an edit adds a critical or high threat no test has confirmed',
21
+ off: 'show no threat cards; bravos watch and the dashboard still list untested threats',
22
+ };
23
+ const NOTIFY_WHAT = {
24
+ on: 'also send a desktop notification for each threat card',
25
+ off: 'send no desktop notifications',
26
+ };
19
27
  const ANNOTATE_WHAT = {
20
28
  background: 'start one background annotation pass each session while coverage is incomplete',
21
29
  off: 'start no background annotation pass; annotate when asked and after your edits',
@@ -34,6 +42,8 @@ export async function getPrefs(root, env, json = false) {
34
42
  return [
35
43
  c ? `commits: ${c.value} — ${WHAT[c.value]} (${c.by}, ${c.at})` : `commits: not recorded — the agent asks before the first commit of each session`,
36
44
  a ? `annotate: ${a.value} — ${ANNOTATE_WHAT[a.value]} (${a.by}, ${a.at})` : `annotate: not recorded — ${ANNOTATE_WHAT.background} (the default)`,
45
+ prefs.cards ? `cards: ${prefs.cards.value} — ${CARDS_WHAT[prefs.cards.value]} (${prefs.cards.by}, ${prefs.cards.at})` : `cards: not recorded — ${CARDS_WHAT.on} (the default)`,
46
+ prefs.notify ? `notify: ${prefs.notify.value} — ${NOTIFY_WHAT[prefs.notify.value]} (${prefs.notify.by}, ${prefs.notify.at})` : `notify: not recorded — ${NOTIFY_WHAT.off} (the default)`,
37
47
  prefs.coach ? `coach: ${prefs.coach.value} — ${COACH_WHAT[prefs.coach.value]} (${prefs.coach.by}, ${prefs.coach.at})` : `coach: not recorded — ${COACH_WHAT.on} (the default)`,
38
48
  `kept in ${L.prefsFile(dir)} (this clone only; never committed)`,
39
49
  ];
@@ -47,9 +57,9 @@ export async function setCommits(root, value, by, env, now = new Date()) {
47
57
  // @mitigates #person-prefs against #governance-forgery using #prefs-outside-tree -- "Every answer is written under the git directory with the name of the person who gave it."
48
58
  export async function setPref(root, key, value, by, env, now = new Date()) {
49
59
  const L = await prefsLib();
50
- const choices = key === 'commits' || key === 'annotate' || key === 'coach' ? L.PREF_CHOICES[key] : null;
60
+ const choices = key === 'commits' || key === 'annotate' || key === 'coach' || key === 'cards' || key === 'notify' ? L.PREF_CHOICES[key] : null;
51
61
  if (!choices)
52
- throw new BravosError('usage: bravos prefs set commits <commit|leave|ask> --by "<your name>" | bravos prefs set annotate <background|off> --by "<your name>" | bravos prefs set coach <on|off> --by "<your name>"');
62
+ throw new BravosError('usage: bravos prefs set commits <commit|leave|ask> --by "<your name>" | bravos prefs set annotate <background|off> --by "<your name>" | bravos prefs set coach|cards|notify <on|off> --by "<your name>"');
53
63
  if (!choices.includes(value))
54
64
  throw new BravosError(`usage: bravos prefs set ${key} <${choices.join('|')}> --by "<your name>"`);
55
65
  if (!by?.trim())
@@ -64,7 +74,7 @@ export async function setPref(root, key, value, by, env, now = new Date()) {
64
74
  catch (e) {
65
75
  throw new BravosError(e instanceof Error ? e.message : String(e));
66
76
  }
67
- const what = key === 'commits' ? WHAT[value] : key === 'coach' ? COACH_WHAT[value] : ANNOTATE_WHAT[value];
77
+ const what = key === 'commits' ? WHAT[value] : key === 'coach' ? COACH_WHAT[value] : key === 'cards' ? CARDS_WHAT[value] : key === 'notify' ? NOTIFY_WHAT[value] : ANNOTATE_WHAT[value];
68
78
  return [`${key}: ${value} — from now on the agent will ${what}`, `recorded in ${file} (this clone only; never committed)`];
69
79
  }
70
80
  // @comment -- "Leaves the hand-off marker after a first install, from the install pipeline itself (which is synchronous, so it cannot load the hook library): the same file and shape hooks/lib/prefs.mjs writeHandoff writes and readHandoff reads, under the clone's git directory. It is what makes the next agent session begin the context step by itself, whichever way Bravos was installed: the guided setup, flags from a script, or the website's setup skill. Returns whether it was written; a folder that is not a git repository, or git not answering, only means the person types the first command."
@@ -28,6 +28,10 @@ export function initArgs(a) {
28
28
  args.push('--scope');
29
29
  return args;
30
30
  }
31
+ /** How many days a critical or high threat may stay untested before the nightly's team view opens an issue for it, unless BRAVOS_THREAT_ISSUES_DAYS says otherwise. */
32
+ export const THREAT_ISSUE_DAYS = 2;
33
+ // @comment -- "The one gh call that turns the nightly's team view on: the repository variable the threat-issues job reads. A variable, not a secret: it holds no credential, and the job's own token opens the issues."
34
+ export const THREAT_ISSUES_VARIABLE = ['variable', 'set', 'BRAVOS_THREAT_ISSUES', '--body', 'on'];
31
35
  /** The secrets and variables the nightly needs, by name. */
32
36
  // @comment -- "The repository secrets a scheduled run needs: the Bravos licence, plus CLAUDE_CODE_OAUTH_TOKEN for Claude Code (from claude setup-token, so the run uses the person's Claude plan) or OPENAI_API_KEY for Codex, whose action takes no other sign-in. For Copilot only COPILOT_ASSIGN_TOKEN, a user's token that assigns the issue; the licence goes to the Agents secrets, which gh secret set does not reach"
33
37
  export function nightlySecrets(a) {
@@ -4,7 +4,7 @@ import { join, resolve } from 'node:path';
4
4
  import { resolveTheme, THEMES } from '../palette.js';
5
5
  import { detectHarnesses } from '../detect.js';
6
6
  import { CRON } from '../ci.js';
7
- import { initArgs, nightlySecrets, normalTarget, PRESETS, provingText, readAnswers, currentSetup, describeSetup, targetProblem, writeAnswers, writeTheme, } from './answers.js';
7
+ import { initArgs, nightlySecrets, normalTarget, PRESETS, provingText, readAnswers, currentSetup, describeSetup, targetProblem, THREAT_ISSUE_DAYS, THREAT_ISSUES_VARIABLE, writeAnswers, writeTheme, } from './answers.js';
8
8
  import { findRepos, isGitRepo, repoHint, repoProblem, tildify } from './repos.js';
9
9
  import { Back, Cancelled } from './ui.js';
10
10
  import { BravosError } from '../types.js';
@@ -301,6 +301,20 @@ async function flow(opts, d) {
301
301
  { value: 'codex', label: 'Codex', hint: 'needs an OpenAI API key', recommended: usual === 'codex' },
302
302
  ], saved?.nightlyAgent ?? usual);
303
303
  }),
304
+ // the team view: an issue for each severe threat left untested
305
+ // @comment -- "The nightly's opt-in team view, asked only with a schedule: whether the nightly opens a GitHub issue for each critical or high threat still untested THREAT_ISSUE_DAYS days after it is committed, keeps a confirmed one open, and closes it once it is refuted, fixed or accepted. Off unless the person says yes; Apply sets the repository variable BRAVOS_THREAT_ISSUES with gh. An unattended run keeps what was saved."
306
+ team(async (s) => {
307
+ if (s.schedule === 'none') {
308
+ s.threatIssues = false;
309
+ return;
310
+ }
311
+ const before = s.threatIssues ?? saved?.threatIssues ?? false;
312
+ if (opts.yes) {
313
+ s.threatIssues = before;
314
+ return;
315
+ }
316
+ s.threatIssues = await p.confirm('threat-issues', `Should the scheduled run also open a GitHub issue for each critical or high threat still untested ${THREAT_ISSUE_DAYS} days after it is committed? Each closes by itself once the threat is refuted, fixed or accepted; a confirmed one stays open until it is fixed.`, before);
317
+ }),
304
318
  // testing permission
305
319
  team(async (s) => {
306
320
  if (opts.yes) {
@@ -446,6 +460,7 @@ async function flow(opts, d) {
446
460
  ...(answers.proving !== 'none' ? [' + .guardlink/scope.yaml (localhost only; authorization left for you)'] : []),
447
461
  ...(answers.name ? [` + .guardlink/proving.md (${answers.proving}${answers.target ? ` on ${answers.target}` : ''}, confirmed by ${answers.name})`] : []),
448
462
  ...(Object.keys(s.secrets).length ? [` + GitHub secrets: ${Object.keys(s.secrets).join(', ')}`] : []),
463
+ ...(answers.threatIssues ? [` + GitHub variable BRAVOS_THREAT_ISSUES=on (an issue for each critical or high threat untested after ${THREAT_ISSUE_DAYS} days)`] : []),
449
464
  ` + .bravos/setup.json (your answers, for ${change})`,
450
465
  ]),
451
466
  ...(has(s, 'codegraph') ? ['Then: build the code graph for this repository'] : []),
@@ -478,6 +493,7 @@ async function flow(opts, d) {
478
493
  // Shown as the one command a person would type; Apply runs the same install underneath.
479
494
  s.join ? `bravos setup ${JSON.stringify(answers.repo)} (brings it up to date)` : `bravos ${['setup', ...initArgs(answers).slice(1)].map((x) => (/\s/.test(x) ? JSON.stringify(x) : x)).join(' ')}`,
480
495
  ...Object.keys(s.secrets).map((n) => `gh secret set ${n} (value from your paste)`),
496
+ ...(answers.threatIssues ? [`gh ${THREAT_ISSUES_VARIABLE.join(' ')}`] : []),
481
497
  ...(has(s, 'codegraph') ? [`bravos graph build ${JSON.stringify(answers.repo)} --scip no-exec`] : []),
482
498
  ].join('\n'), 'Commands');
483
499
  }
@@ -494,6 +510,7 @@ function toAnswers(s) {
494
510
  autopilot: !!s.autopilot,
495
511
  schedule: s.schedule ?? 'none',
496
512
  nightlyAgent: s.nightlyAgent ?? 'claude',
513
+ ...(s.threatIssues && (s.schedule ?? 'none') !== 'none' ? { threatIssues: true } : {}),
497
514
  proving: s.proving ?? 'none',
498
515
  ...(s.proving === 'auto' ? { kitPolicy: s.kitPolicy } : {}),
499
516
  generation: false,
@@ -571,6 +588,15 @@ async function apply(answers, s, d, opts, has) {
571
588
  const r = d.exec('gh', ['secret', 'set', n], { input: v, cwd: repo });
572
589
  (r.code ? p.warn : p.info)(r.code ? `gh secret set ${n} failed — add it in the repository's Settings → Secrets` : `secret ${n} set`);
573
590
  }
591
+ // @comment -- "Turns the nightly's team view on with the one repository variable it reads, through gh as the person; a failure or a machine without gh says how to set it by hand, and setup carries on."
592
+ if (answers.threatIssues && !has.join) {
593
+ const by = `gh ${THREAT_ISSUES_VARIABLE.join(' ')}`;
594
+ const r = d.which('gh') ? d.exec('gh', THREAT_ISSUES_VARIABLE, { cwd: repo }) : { code: 1, out: '' };
595
+ if (r.code)
596
+ p.warn(`The team view is not on yet: run ${by} (or Settings → Secrets and variables → Actions → Variables).`);
597
+ else
598
+ p.info('variable BRAVOS_THREAT_ISSUES set to on: the scheduled run opens issues for threats left untested');
599
+ }
574
600
  if (has.codegraph) {
575
601
  const g = await p.spin(step('Building the code graph (a minute or two; longer on a big repository)'), () => d.bravosChild(['graph', 'build', repo, '--scip', 'no-exec', '--json']), (r) => (graphSummary(r).ok ? graphSummary(r).line : { fail: graphSummary(r).line }));
576
602
  const sum = graphSummary(g);
package/dist/uninstall.js CHANGED
@@ -5,7 +5,7 @@ import { removePrePush } from './context.js';
5
5
  import { BravosError } from './types.js';
6
6
  const isObject = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
7
7
  // Any command bravos registers: the per-repo relative forms and the user-level absolute one.
8
- const isBravosCommand = (c) => typeof c === 'string' && /\.bravos\/hooks\/(session-start|pre-pr|autopilot|coach)\.mjs/.test(c);
8
+ const isBravosCommand = (c) => typeof c === 'string' && /\.bravos\/hooks\/(session-start|pre-pr|autopilot|coach|cards)\.mjs/.test(c);
9
9
  function readJson(root, rel) {
10
10
  const abs = join(root, rel);
11
11
  if (!existsSync(abs))
package/docs/GUIDE.md CHANGED
@@ -86,6 +86,8 @@ Skills: `/bravos-cicd` · `/bravos-schedule`
86
86
 
87
87
  bravos setup --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
+ The team view is opt-in, in every nightly: set the repository variable BRAVOS_THREAT_ISSUES to on (gh variable set BRAVOS_THREAT_ISSUES --body on; bravos setup asks) and the nightly opens one GitHub issue for each critical or high threat still untested two days after it was committed, labelled bravos, the severity, untested and its CWE. The issue says what to do: test it with bravos-prove, fix it with a @mitigates, or have a named person accept it. A refuted result, a fix, an acceptance or removing the claim closes it by itself. A confirmed result keeps it open, relabelled confirmed, until it is fixed or accepted; a claim whose code changed after its result reopens the issue. BRAVOS_THREAT_ISSUES_DAYS changes the delay.
90
+
89
91
  ## What to do, by task
90
92
 
91
93
  ### Where do I start? What is open?
@@ -124,6 +126,12 @@ Skills: `/bravos`
124
126
 
125
127
  Bravos tells you when it is updated. At most once a day a session start asks the npm registry, in a background process the session never waits on, for the latest published version: the same request npm install makes, with only the package name. A newer version shows in the banner and the briefing, and the coach tells a session that is already running, once. Installing it is yours to do (npm install -g @bugb-technologies/bravos); once it is installed the coach has the agent run bravos setup in the repository, which brings its Bravos files up to date. bravos doctor shows the last check. BRAVOS_UPDATE_CHECK=off stops the check, and it never runs in CI.
126
128
 
129
+ ### Threat cards
130
+
131
+ Skills: `/bravos-prove` · `/bravos-env`
132
+
133
+ When an edit adds a critical or high threat to the threat model (an @exposes claim) that no test has confirmed or refuted, a hook that runs after the edit shows you a card in the terminal straight away: the severity, what the threat is, the claim and where it is, its state, and one next step (bravos-env to set up a test target, where you type the authorization, then bravos-prove). The agent is told to raise it in the same reply and recommend confirming it; it never confirms, refutes or accepts a threat itself. Only lines that are not in the last commit count, so existing claims never raise a card, and each threat raises one card per clone. The hook reads the edited files, their committed copy and the local ledger; it runs no guardlink, no test and no network. bravos watch lists every card. BRAVOS_THREAT_CARDS=off turns cards off for a run and bravos prefs set cards off --by "<your name>" for the clone; bravos prefs set notify on --by "<your name>" adds a desktop notification (macOS and Linux).
134
+
127
135
  ### The coach
128
136
 
129
137
  Skills: `/bravos`
package/docs/UPGRADING.md CHANGED
@@ -2,6 +2,36 @@
2
2
 
3
3
  After `npm install -g @bugb-technologies/bravos`, run **`bravos setup`** in a repository you work in: it brings this machine and that repository up to date. In repositories you work in with an agent you can skip even that: the agent runs it at the start of a session. From 1.12 on you do not have to watch for releases: Bravos tells you when a newer version is out, and after you install it the agent brings each repository up to date. The notes below say what else changes, newest first. (Before 1.9 the same was `bravos setup --tools -y` per machine and `bravos sync` per repository; both still work.)
4
4
 
5
+ ## 1.14.0
6
+
7
+ - **Issues for the team, opt-in.** The nightly can open one GitHub issue for each critical or high threat that is still untested a few days after its annotation was committed. The default is 2 days; the repository variable `BRAVOS_THREAT_ISSUES_DAYS` changes it.
8
+ - **Turning it on:** answer yes in `bravos setup` (asked with the schedule), or set the variable yourself: `gh variable set BRAVOS_THREAT_ISSUES --body on`.
9
+ - **Each issue** gives the claim, a link to its line, and how to close it: test it with `bravos-prove`, fix it with a `@mitigates`, or have a named person accept it.
10
+ - **When it closes:** by itself, once the threat is refuted, fixed, accepted, lowered below high or removed.
11
+ - **A confirmed threat stays open** and is relabelled `confirmed`.
12
+ - **A claim whose code changed after its last test** reopens its issue, if the nightly had closed it.
13
+ - **Your own decisions stand:** an issue a person closed or reopened is left as they left it.
14
+ - **No flood:** at most 10 new issues a run, so turning it on over a backlog spreads them over a few nights.
15
+ - **Hardening:** the job runs no agent, needs no secret, and holds only `contents: read` and `issues: write`. Annotation text reaches GitHub only as arguments and files, never as a shell line.
16
+ - **To get the job:** refresh a repository's nightly with `bravos setup --ci`.
17
+ - **Not tried live yet:** this has run only against stand-ins for `gh` and `guardlink`. Watch the first nightly's run summary on a repository where it is on.
18
+
19
+ ## 1.13.0
20
+
21
+ - **Threat cards.** When an edit adds a critical or high threat to the threat model (an `@exposes` claim) that no test has confirmed or refuted, a card appears in your terminal straight away.
22
+ - **The card shows:** the severity, what the threat is, the claim and where it is, "untested", and one next step: `bravos-env` to set up a test target (you type the authorization), then `bravos-prove`.
23
+ - **The agent** is told to raise it in the same reply and recommend confirming it. It never confirms, refutes or accepts a threat itself.
24
+ - **What counts:** only lines that aren't in the last commit, so existing claims never raise a card. Each threat raises one card per clone.
25
+ - **Where else it shows:** `bravos watch` lists every card.
26
+ - **Where it runs:** Claude Code, after its file-editing tools; Codex, after every tool. In every repository `bravos setup` brings up to date, and in both plugins.
27
+ - **What it reads:** the edited files, their committed copy and the local ledger. No guardlink, no test, no network.
28
+ - **Turning it off:** `BRAVOS_THREAT_CARDS=off` for a run, or `bravos prefs set cards off --by "<your name>"` for the clone.
29
+ - **Desktop notifications** are opt-in, on macOS and Linux: `bravos prefs set notify on --by "<your name>"`.
30
+ - **For scripts:**
31
+ - `.claude/settings.json` and `.codex/hooks.json` gain a `PostToolUse` entry;
32
+ - `bravos prefs get --json` gains `cards` and `notify`;
33
+ - `bravos doctor --json` gains `cards`.
34
+
5
35
  ## 1.12.1
6
36
 
7
37
  - **Bravos finds cxg when your PATH doesn't have it.** cargo installs cxg into its own folder (`~/.cargo/bin`, or `CARGO_HOME`/`CARGO_INSTALL_ROOT`). A session started from a desktop app or a non-interactive shell often lacks that folder on PATH, and Bravos used to read that as "cxg is not installed".
@@ -0,0 +1,74 @@
1
+ // @comment -- "bravos threat cards PostToolUse hook entry (Claude Code and Codex): after an edit, shows the developer a card for each new critical or high exposure no test has confirmed or refuted (hooks/lib/cards.mjs), gives the agent one line to raise it, logs it for bravos watch and, when the person turned it on, sends a desktop notification. Silent when BRAVOS_THREAT_CARDS=off, when the person switched cards off (bravos prefs set cards off), or when it is the plugin's copy in a repository that registers its own. Always exits 0; a failure shows nothing."
2
+ import { readFileSync, realpathSync } from 'node:fs';
3
+ import { basename, join } from 'node:path';
4
+ import { spawnSync } from 'node:child_process';
5
+ import { fileURLToPath } from 'node:url';
6
+ import { agentLine, decideCards, notify, readSeen, renderCard, targetRecorded, writeSeen } from './lib/cards.mjs';
7
+ import { gitCommonDir, readPrefs } from './lib/prefs.mjs';
8
+ import { logWatchEvent } from './lib/snapshot.mjs';
9
+
10
+ async function readPayload() {
11
+ if (process.stdin.isTTY) return {};
12
+ const read = (async () => {
13
+ const chunks = [];
14
+ for await (const c of process.stdin) chunks.push(c);
15
+ return Buffer.concat(chunks).toString('utf8');
16
+ })().catch(() => '');
17
+ const raw = await Promise.race([read, new Promise((r) => setTimeout(() => r(''), 1000).unref())]);
18
+ try {
19
+ const p = JSON.parse(raw);
20
+ return p && typeof p === 'object' ? p : {};
21
+ } catch {
22
+ return {};
23
+ }
24
+ }
25
+
26
+ function deferToRepo(root) {
27
+ try {
28
+ if (realpathSync(fileURLToPath(import.meta.url)) === realpathSync(join(root, '.bravos', 'hooks', 'cards.mjs'))) return false;
29
+ } catch {
30
+ /* no repository copy */
31
+ }
32
+ for (const f of ['.claude/settings.json', '.codex/hooks.json']) {
33
+ try {
34
+ if (readFileSync(join(root, f), 'utf8').includes('.bravos/hooks/cards.mjs')) return true;
35
+ } catch {
36
+ /* not registered there */
37
+ }
38
+ }
39
+ return false;
40
+ }
41
+
42
+ async function main() {
43
+ let out = {};
44
+ try {
45
+ if (process.env.BRAVOS_THREAT_CARDS === 'off') throw new Error('off');
46
+ const payload = await readPayload();
47
+ const cwd = typeof payload.cwd === 'string' ? payload.cwd : process.env.CLAUDE_PROJECT_DIR || process.cwd();
48
+ const top = spawnSync('git', ['rev-parse', '--show-toplevel'], { cwd, encoding: 'utf8', timeout: 3000, stdio: ['ignore', 'pipe', 'ignore'] });
49
+ if (top.status !== 0) throw new Error('not a repository');
50
+ const root = top.stdout.trim();
51
+ if (deferToRepo(root)) throw new Error('repo copy');
52
+ const commonDir = gitCommonDir(root);
53
+ const prefs = readPrefs(commonDir);
54
+ if (prefs.cards?.value === 'off') throw new Error('off');
55
+ const harness = process.argv.includes('--harness') ? process.argv[process.argv.indexOf('--harness') + 1] : 'claude';
56
+ const { cards, seen } = decideCards({ root, toolName: payload.tool_name, toolInput: payload.tool_input, seen: readSeen(commonDir) });
57
+ if (cards.length) {
58
+ writeSeen(commonDir, seen);
59
+ const target = targetRecorded(root);
60
+ const shown = cards.slice(0, 3);
61
+ const more = cards.length - shown.length;
62
+ const text = ['bravos · threat card', ...shown.map((c) => renderCard(c, { target, harness })), ...(more > 0 ? [`… and ${more} more: bravos watch lists them`] : []), 'Shown once per threat. bravos watch and the dashboard keep the list.'].join('\n');
63
+ out = { systemMessage: text, hookSpecificOutput: { hookEventName: 'PostToolUse', additionalContext: agentLine(cards, { target, harness }) } };
64
+ for (const c of cards) logWatchEvent(root, { summary: `card: ${c.severity.toUpperCase()} ${c.threat} on ${c.asset} · ${c.file}${c.line ? `:${c.line}` : ''} · untested`, keys: [`bravos-card:${c.threat}`] });
65
+ if (prefs.notify?.value === 'on' || process.env.BRAVOS_NOTIFY === 'on') notify(cards[0], basename(root));
66
+ }
67
+ } catch {
68
+ out = {};
69
+ }
70
+ process.stdout.write(JSON.stringify(out) + '\n');
71
+ process.exit(0);
72
+ }
73
+
74
+ main();