@bugb-technologies/bravos 1.9.2 → 1.11.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
@@ -875,22 +875,22 @@ export function buildProgram(io, result) {
875
875
  const u = await gatherUpkeep(dirArg(dir), io.env);
876
876
  lines.push(...(opts.json ? [JSON.stringify(u)] : formatUpkeep(u)));
877
877
  }));
878
- // @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. Kept under the git directory of this clone, never committed."
878
+ // @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
879
  program
880
880
  .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. Free; runs no model.')
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.')
882
882
  .option('-C, --dir <dir>', 'the repository (default: the current directory)')
883
883
  .option('--by <name>', 'set: whose answer this is')
884
884
  .option('--json', 'get: print JSON')
885
885
  .action((action, args, opts) => guardedAsync(async (lines) => {
886
- const { getPrefs, setCommits } = await import('./prefs.js');
886
+ const { getPrefs, setPref } = await import('./prefs.js');
887
887
  const dir = dirArg(opts.dir);
888
888
  if (action === 'get' && args.length === 0)
889
889
  lines.push(...(await getPrefs(dir, io.env, !!opts.json)));
890
- else if (action === 'set' && args[0] === 'commits' && args.length === 2)
891
- lines.push(...(await setCommits(dir, args[1], opts.by, io.env)));
890
+ else if (action === 'set' && (args[0] === 'commits' || args[0] === 'annotate' || args[0] === 'coach') && args.length === 2)
891
+ lines.push(...(await setPref(dir, args[0], args[1], opts.by, io.env)));
892
892
  else
893
- throw new BravosError('usage: bravos prefs get [--json] | bravos prefs set commits <commit|leave|ask> --by "<your name>"');
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>"');
894
894
  }));
895
895
  // @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
896
  program
@@ -908,7 +908,7 @@ export function buildProgram(io, result) {
908
908
  .option('--no-serve', 'write the page as a file instead of serving it; Save then downloads the answers')
909
909
  .option('--no-open', 'do not open a browser, only print the URL')
910
910
  .option('--share', 'render the page for a shared claude.ai artifact (Claude Code only; the agent publishes it)')
911
- .option('--wait [seconds]', 'serve the page, then wait until the person presses Done and print everyone\'s answers; after the wait (default 90 seconds) it says "review: waiting" and exits 0, and running it again keeps waiting on the same page')
911
+ .option('--wait [seconds]', 'serve the page, then wait until the person presses Confirm and print everyone\'s answers; after the wait (default 90 seconds) it says "review: waiting" and exits 0, and running it again keeps waiting on the same page')
912
912
  .action((kind, dir, opts) => guardedAsync(async (lines) => {
913
913
  const root = dirArg(dir);
914
914
  checkKind(kind);
@@ -934,7 +934,7 @@ export function buildProgram(io, result) {
934
934
  openInBrowser(pathJoin(root, rel), io.env);
935
935
  return;
936
936
  }
937
- // @comment -- "With --wait the command stays until the person presses Done (the page's server exits), then prints the answers, so an agent continues without anyone typing 'done'. What it prints before waiting goes out at once, because the agent's shell shows nothing until the command ends otherwise. A page already open for this review is waited on, never opened twice."
937
+ // @comment -- "With --wait the command stays until the person presses Confirm (the page's server exits after saving), then prints the answers, so an agent continues without anyone typing 'done'. What it prints before waiting goes out at once, because the agent's shell shows nothing until the command ends otherwise. A page already open for this review is waited on, never opened twice."
938
938
  const RW = await import('./review-wait.js');
939
939
  let waitFor = null;
940
940
  if (opts.wait !== undefined) {
@@ -949,7 +949,7 @@ export function buildProgram(io, result) {
949
949
  const say = (l) => (waitFor === null ? lines.push(l) : io.stdout(l));
950
950
  let live = waitFor === null ? null : RW.readLive(commonDir, kind);
951
951
  if (live)
952
- say(`Review page: ${live.url} (already open; waiting for Done)`);
952
+ say(`Review page: ${live.url} (already open; waiting for Confirm)`);
953
953
  else {
954
954
  const port = await freePort();
955
955
  const token = newToken();
@@ -963,7 +963,7 @@ export function buildProgram(io, result) {
963
963
  RW.writeLive(commonDir, kind, live);
964
964
  }
965
965
  say(`Review page: ${url}`);
966
- say(`Answers save to .guardlink/${kind}-answers/<name>.json. Teammates run bravos review ${kind} after pulling. The page stops on Done or after 30 minutes idle.`);
966
+ say(`Answers save to .guardlink/${kind}-answers/<name>.json. Teammates run bravos review ${kind} after pulling. The page stops on Confirm or after 30 minutes idle.`);
967
967
  if (waitFor === null)
968
968
  lines.push(`When everyone is done: bravos review ${kind} --summary`);
969
969
  if (opts.open !== false)
package/dist/context.js CHANGED
@@ -306,7 +306,7 @@ export async function checkSources(dir, env) {
306
306
  export async function gateFor(dir, env) {
307
307
  return (await contextLib()).contextGate(storeRoot(dir, env));
308
308
  }
309
- // @comment -- "bravos context decline --by <name>: records, in the committed .bravos/context/status.json, that a named person chose to threat-model this repository without design context. It is the one way past the context gate other than doing the context step, so the name is required and never taken from git's configuration: it is a person's decision, and a coding agent is told never to make it for them."
309
+ // @comment -- "bravos context decline --by <name>: records, in the committed .bravos/context/status.json, that a named person chose to threat-model this repository without design context. It ends the asking for the intake each session, as a confirmation would, so the name is required and never taken from git's configuration: it is a person's decision, and a coding agent is told never to make it for them."
310
310
  export async function declineContext(dir, opts, env) {
311
311
  const L = await contextLib();
312
312
  const root = storeRoot(dir, env);
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_PRE_PR_COMMANDS, HOOK_COMMANDS, LEGACY_HOOK_COMMAND, RELATIVE_HOOK_COMMANDS, hookRegistered } from './hooks.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';
8
8
  import { skillsRoot } from './skills.js';
9
9
  import { resolveTheme } from './palette.js';
10
10
  import { pathToFileURL } from 'node:url';
@@ -63,6 +63,10 @@ export function runDoctor(root, env = process.env) {
63
63
  claude: hookRegistered(join(root, '.claude', 'settings.json'), 'Stop', ALL_AUTOPILOT_COMMANDS),
64
64
  codex: hookRegistered(join(root, '.codex', 'hooks.json'), 'Stop', ALL_AUTOPILOT_COMMANDS),
65
65
  },
66
+ coach: {
67
+ claude: hookRegistered(join(root, '.claude', 'settings.json'), 'UserPromptSubmit', ALL_COACH_COMMANDS),
68
+ codex: hookRegistered(join(root, '.codex', 'hooks.json'), 'UserPromptSubmit', ALL_COACH_COMMANDS),
69
+ },
66
70
  pre_pr: {
67
71
  claude: hookRegistered(join(root, '.claude', 'settings.json'), 'PreToolUse', ALL_PRE_PR_COMMANDS),
68
72
  codex: hookRegistered(join(root, '.codex', 'hooks.json'), 'PreToolUse', ALL_PRE_PR_COMMANDS),
@@ -93,6 +97,7 @@ export function formatDoctor(r) {
93
97
  `hooks claude: ${yn(r.hooks.claude)} codex: ${yn(r.hooks.codex)}`,
94
98
  `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)'}`,
95
99
  `autopilot claude: ${yn(r.autopilot.claude)} codex: ${yn(r.autopilot.codex)}${r.autopilot.claude || r.autopilot.codex ? '' : ' (opt-in: bravos setup --autopilot)'}`,
100
+ `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)'}`,
96
101
  ...(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'] : []),
97
102
  ...(r.theme ? [`colours ${r.theme.theme} (${r.theme.source})${r.theme.source.startsWith('default') ? ' — pick yours: BRAVOS_THEME=light or dark, or bravos setup' : ''}`] : []),
98
103
  ].join('\n');
package/dist/guide.js CHANGED
@@ -115,9 +115,11 @@ export const GUIDE_TOPICS = [
115
115
  { name: 'Teach bravos what the app is for', skills: ['bravos-context'], body: ['Writes .guardlink/intent.md: invariants (INV-n) that become threats, and intended-by-design items (INT-n) that get an "intended?" audit instead of a high rating.'] },
116
116
  { name: 'Start from your design documents', skills: ['bravos-context'], body: ['Give bravos-context your PRDs, design documents or an earlier threat model, as files or links. Each is kept in the repository as Markdown under .bravos/context/ (bravos context add; committed, so the team can keep it current) after a check for secrets and local paths; a link is kept beside its snapshot. Every rule then names the document it came from (INV-4, source: SRC-2), including who may do what: "sales may see every report except the revenue report" becomes a rule that can be tested, where a scan would see nothing wrong. bravos context list shows the documents, bravos context check re-checks them, and a pre-push check stops a push that would send a secret in one. Free; the CLI runs no model and fetches nothing: your agent converts and fetches with your own access.'] },
117
117
  { 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
- { name: 'Context comes first', skills: ['bravos-context', 'bravos-annotate'], body: ['Threat-modelling starts only when a named person has confirmed what the product intends: bravos-annotate, campaigns and the nightly workflows wait until at least one item in .guardlink/intent.md is confirmed (run bravos-context; it asks for your design documents and a few decisions). A team that chooses to go without records that under a name, bravos context decline --by "<name>", which is committed like the intent; a coding agent is told never to decline for you. bravos context gate says which state a repository is in. Rechecks, retests and the ship check are not held back: they maintain a model that already exists.'] },
118
+ { 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
+ { 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.'] },
120
+ { 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.'] },
119
121
  { 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.'] },
120
- { name: 'Answer bravos\'s questions as a team', skills: ['bravos-context'], body: ['bravos-context opens its questions as a bravos page (bravos review intent): pre-filled with bravos\'s suggestions and their sources; change what is wrong, make the calls marked \'needs your call\' (Confirm stays off until you do), and the facts bravos drafted stay folded unless you open one to object. The role-by-action matrix links each documented permission to its question. In local reviews, open a cited SRC document to read its verified text. The saved HTML can contain these documents. Each person\'s answers save to .guardlink/intent-answers/<name>.json; teammates run bravos review intent after pulling and commit theirs. Press Done when you are finished: the agent runs bravos review intent --wait and carries on by itself. bravos review intent --summary shows where people agree and disagree; only what a named person agreed to is marked confirmed. On Claude Code, --share prepares an artifact with the draft and its citations. Publish that artifact to share it.'] },
122
+ { name: 'Answer bravos\'s questions as a team', skills: ['bravos-context'], body: ['bravos-context opens its questions as a bravos page (bravos review intent): pre-filled with bravos\'s suggestions and their sources; change what is wrong, make the calls marked \'needs your call\' (Confirm stays off until you do), and the facts bravos drafted stay folded unless you open one to object. The role-by-action matrix links each documented permission to its question. In local reviews, open a cited SRC document to read its verified text. The saved HTML can contain these documents. Each person\'s answers save to .guardlink/intent-answers/<name>.json; teammates run bravos review intent after pulling and commit theirs. Press Confirm when you are finished: that saves your answers and the agent, waiting on bravos review intent --wait, carries on by itself. bravos review intent --summary shows where people agree and disagree; only what a named person agreed to is marked confirmed. On Claude Code, --share prepares an artifact with the draft and its citations. Publish that artifact to share it.'] },
121
123
  { name: 'I wrote security-relevant code', skills: ['bravos-annotate'], body: ['Annotates what you changed to guardlink\'s evidence bar and runs the lint gate until clean.'] },
122
124
  { name: 'Cover the whole repo', skills: ['bravos-campaign'], body: ['Rounds of batches with subagents and rests, until the coverage goal or until you stop it.'] },
123
125
  { name: 'Is this exposure real?', skills: ['bravos-templatize', 'bravos-env', 'bravos-prove'], body: ['Template → authorized target → run. Only a reproduced run confirms; reading code never does.'] },
package/dist/help.js CHANGED
@@ -155,11 +155,31 @@ Upkeep
155
155
  repository's own build scripts are not run). One build per repository at a time; never in
156
156
  CI; BRAVOS_GRAPH_AUTOBUILD=off turns it off.
157
157
 
158
- Context comes first
159
- bravos-annotate, campaigns and the nightly workflows start only when a named person has
160
- confirmed at least one item of .guardlink/intent.md, or has recorded that the team goes
161
- without: bravos context decline --by "<name>". bravos context gate says which it is.
162
- Rechecks, retests and the ship check are never held back.
158
+ The intake asks, it never blocks
159
+ Annotation starts in the first session. With no confirmed intent, the agent drafts what
160
+ the app is for (.guardlink/intent.md, every item marked draft), annotates against that
161
+ draft, and asks once each session for a person to confirm it: bravos review intent.
162
+ Rules drafted from the design are tested and can block a pull request, labelled draft.
163
+ When answers arrive, the agent re-judges what they changed. A team that goes without
164
+ records it under a name: bravos context decline --by "<name>". bravos context gate says
165
+ which state a repository is in.
166
+
167
+ Background annotation
168
+ While coverage is under 100%, each new session asks the agent to start one annotation pass
169
+ in a background subagent (one slice) beside whatever you asked, and to say so. It writes
170
+ annotations only, commits only as your commits answer allows, and reports in one line.
171
+ Not on resume or compact, not in CI. bravos prefs set annotate off --by "<your name>"
172
+ switches it off for this clone (background turns it back on); BRAVOS_AUTO_ANNOTATE=off
173
+ for one run.
174
+
175
+ The coach
176
+ Before each prompt a fast hook (no guardlink, no network) may add one line for the agent.
177
+ A question about issues, threats or vulnerabilities builds the dashboard as the agent
178
+ answers, opening it in your browser the first time in a session. After the first prompt it
179
+ reminds, each once a session and one at a time: claims waiting to be confirmed (with the
180
+ next step: bravos-env for a target, then bravos-prove), how much of the code the threat
181
+ model covers, and a dashboard older than the model. bravos watch shows each reminder.
182
+ BRAVOS_COACH=off for one run; bravos prefs set coach off --by "<your name>" for this clone.
163
183
 
164
184
  Session start
165
185
  One hook run returns two things. The briefing (counts, FIX NOW, what to test next, stale
package/dist/hooks.js CHANGED
@@ -61,6 +61,14 @@ const autopilot = (h) => ({
61
61
  replaces: [OLD_HOOK_COMMANDS.autopilot, AUTOPILOT_COMMAND],
62
62
  group: { hooks: [{ type: 'command', command: AUTOPILOT_COMMANDS[h], timeout: 30 }] },
63
63
  });
64
+ // @comment -- "The coach: a UserPromptSubmit hook, registered with the SessionStart briefing in every repository (not opt-in), that adds a dashboard instruction or one reminder before a prompt when one is due (hooks/lib/coach.mjs). It runs no guardlink and no network, so its timeout is short."
65
+ export const COACH_COMMANDS = { claude: hookCommand('claude', 'coach.mjs', HARNESS_ARG.claude), agents: hookCommand('agents', 'coach.mjs', HARNESS_ARG.agents) };
66
+ export const ALL_COACH_COMMANDS = Object.values(COACH_COMMANDS);
67
+ const coach = (h) => ({
68
+ event: 'UserPromptSubmit',
69
+ command: COACH_COMMANDS[h],
70
+ group: { hooks: [{ type: 'command', command: COACH_COMMANDS[h], timeout: 5 }] },
71
+ });
64
72
  // The hook script itself only acts on commands that run gh pr create or gh pr ready.
65
73
  const prePr = (h) => ({
66
74
  event: 'PreToolUse',
@@ -197,7 +205,7 @@ function planAgy(root) {
197
205
  const { [OLD_NAME]: _old, ...rest } = doc;
198
206
  return { file: AGY_HOOKS_FILE, changed: true, doc: { ...rest, bravos: AGY_GROUP } };
199
207
  }
200
- // @comment -- "Copies the hook scripts into <root>/.bravos/hooks and registers the SessionStart briefing, 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."
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."
201
209
  export function installHook(root, harnesses, opts = {}) {
202
210
  const src = opts.hooksDir ?? packageHooksDir();
203
211
  const files = listFiles(src).map((abs) => relative(src, abs).split('\\').join('/')).sort();
@@ -206,6 +214,7 @@ export function installHook(root, harnesses, opts = {}) {
206
214
  const withAutopilot = opts.autopilot && !opts.globalHome;
207
215
  const plans = [...new Set(harnesses)].map((h) => planRegistration(root, SETTINGS_FILE[h], [
208
216
  sessionStart(h, opts.globalHome),
217
+ ...(opts.globalHome ? [] : [coach(h)]),
209
218
  ...(withPrePr ? [prePr(h)] : []),
210
219
  ...(withAutopilot ? [autopilot(h)] : []),
211
220
  ], [
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 only (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 and the UserPromptSubmit coach (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 = [];
@@ -49,12 +49,14 @@ export function pluginFiles(opts = {}) {
49
49
  matcher: 'startup|resume|clear|compact',
50
50
  hooks: [{ type: 'command', command: 'node "${CLAUDE_PLUGIN_ROOT}/hooks/session-start.mjs" --harness claude', timeout: 30 }],
51
51
  }],
52
+ // The coach; its plugin copy stays quiet in a repository that registers its own.
53
+ UserPromptSubmit: [{ hooks: [{ type: 'command', command: 'node "${CLAUDE_PLUGIN_ROOT}/hooks/coach.mjs" --harness claude', timeout: 5 }] }],
52
54
  },
53
55
  }));
54
56
  // Codex substitutes ${PLUGIN_ROOT} in plugin hooks; the group is otherwise the one bravos setup writes.
55
57
  const start = sessionStart('agents');
56
58
  const codexStart = { ...start.group, hooks: start.group.hooks.map((h) => ({ ...h, command: 'node "${PLUGIN_ROOT}/hooks/session-start.mjs" --harness codex' })) };
57
- add(`${CODEX_PLUGIN_DIR}/hooks/hooks.json`, json({ hooks: { [start.event]: [codexStart] } }));
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 }] }] } }));
58
60
  // guardlink only: cxg and codegraph-mcp are optional, and a server that fails to start on every
59
61
  // machine without its binary is noise. bravos setup adds them per repo when they are installed.
60
62
  const servers = { guardlink: SERVERS.guardlink };
package/dist/prefs.js CHANGED
@@ -1,4 +1,4 @@
1
- // @comment -- "bravos prefs: a person's standing answers for one clone, read and written through hooks/lib/prefs.mjs so the CLI and the session hook agree on the file and its shape. `prefs get` prints what is recorded; `prefs set commits <commit|leave|ask> --by <name>` records what a named person said about committing Bravos's own files. The file is under the git directory, never in the working tree."
1
+ // @comment -- "bravos prefs: a person's standing answers for one clone, read and written through hooks/lib/prefs.mjs so the CLI and the session hook agree on the file and its shape. `prefs get` prints what is recorded; `prefs set commits <commit|leave|ask> --by <name>` records what a named person said about committing Bravos's own files, and `prefs set annotate <background|off> --by <name>` whether each session starts a background annotation pass. The file is under the git directory, never in the working tree."
2
2
  import { spawnSync } from 'node:child_process';
3
3
  import { mkdirSync, writeFileSync } from 'node:fs';
4
4
  import { pathToFileURL } from 'node:url';
@@ -12,6 +12,14 @@ const WHAT = {
12
12
  leave: "leave Bravos's own files uncommitted and list them",
13
13
  ask: 'ask before the first commit of each session',
14
14
  };
15
+ const COACH_WHAT = {
16
+ on: 'add a reminder before a prompt when one is due (coverage, findings to confirm, the dashboard), each once a session',
17
+ off: 'add no reminders before prompts; the session-start briefing still speaks',
18
+ };
19
+ const ANNOTATE_WHAT = {
20
+ background: 'start one background annotation pass each session while coverage is incomplete',
21
+ off: 'start no background annotation pass; annotate when asked and after your edits',
22
+ };
15
23
  /** What is recorded for this clone, as text or JSON. */
16
24
  export async function getPrefs(root, env, json = false) {
17
25
  const L = await prefsLib();
@@ -22,17 +30,28 @@ export async function getPrefs(root, env, json = false) {
22
30
  if (json)
23
31
  return [JSON.stringify({ schema: L.PREFS_SCHEMA, file: L.prefsFile(dir), ...prefs }, null, 2)];
24
32
  const c = prefs.commits;
33
+ const a = prefs.annotate;
25
34
  return [
26
35
  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
+ a ? `annotate: ${a.value} — ${ANNOTATE_WHAT[a.value]} (${a.by}, ${a.at})` : `annotate: not recorded — ${ANNOTATE_WHAT.background} (the default)`,
37
+ 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)`,
27
38
  `kept in ${L.prefsFile(dir)} (this clone only; never committed)`,
28
39
  ];
29
40
  }
30
41
  // @comment -- "Records what a named person said about commits. --by is required and never taken from git: the name is the person's own, given when they answered, so an agent cannot record an answer nobody gave without also inventing a name (the skills forbid both)."
31
42
  // @mitigates #person-prefs against #governance-forgery using #prefs-outside-tree -- "The answer is written under the git directory with the name of the person who gave it; nothing in a repository's tree can set it."
32
43
  export async function setCommits(root, value, by, env, now = new Date()) {
44
+ return setPref(root, 'commits', value, by, env, now);
45
+ }
46
+ // @comment -- "Records one standing answer a named person gave (commits or annotate), with the same rules as commits: --by is required and never taken from git."
47
+ // @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
+ export async function setPref(root, key, value, by, env, now = new Date()) {
33
49
  const L = await prefsLib();
34
- if (!L.COMMIT_CHOICES.includes(value))
35
- throw new BravosError(`usage: bravos prefs set commits <${L.COMMIT_CHOICES.join('|')}> --by "<your name>"`);
50
+ const choices = key === 'commits' || key === 'annotate' || key === 'coach' ? L.PREF_CHOICES[key] : null;
51
+ 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>"');
53
+ if (!choices.includes(value))
54
+ throw new BravosError(`usage: bravos prefs set ${key} <${choices.join('|')}> --by "<your name>"`);
36
55
  if (!by?.trim())
37
56
  throw new BravosError('say whose answer this is: --by "<your name>" (it is a person\'s decision; an agent never records one nobody gave)');
38
57
  const dir = L.gitCommonDir(root, env);
@@ -40,12 +59,13 @@ export async function setCommits(root, value, by, env, now = new Date()) {
40
59
  throw new BravosError(`${root} is not a git repository: preferences are kept under its git directory`);
41
60
  let file;
42
61
  try {
43
- file = L.writeCommits(dir, value, by, now.toISOString().slice(0, 10));
62
+ file = L.writePref(dir, key, value, by, now.toISOString().slice(0, 10));
44
63
  }
45
64
  catch (e) {
46
65
  throw new BravosError(e instanceof Error ? e.message : String(e));
47
66
  }
48
- return [`commits: ${value} — from now on the agent will ${WHAT[value]}`, `recorded in ${file} (this clone only; never committed)`];
67
+ const what = key === 'commits' ? WHAT[value] : key === 'coach' ? COACH_WHAT[value] : ANNOTATE_WHAT[value];
68
+ return [`${key}: ${value} — from now on the agent will ${what}`, `recorded in ${file} (this clone only; never committed)`];
49
69
  }
50
70
  // @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."
51
71
  // @mitigates #person-prefs against #governance-forgery using #prefs-outside-tree -- "The marker is written under the git directory, where no commit, clone or pull can put one."
package/dist/review.js CHANGED
@@ -243,7 +243,9 @@ function effective(q, a) {
243
243
  return 'no';
244
244
  const legacy = a.verdict === 'choice' ? a.choice : a.verdict === 'change' ? a.text : undefined;
245
245
  const asIs = a.verdict === 'accepted' || a.verdict === 'agree' ? (q.suggested ?? 'agree') : undefined;
246
- const v = a.value ?? legacy ?? asIs ?? a.verdict;
246
+ // An answer in the reviewer's own words (a choice or multi question none of whose options fit) is carried as text.
247
+ const own = a.verdict === 'edited' && a.value === undefined && a.text ? `own answer: "${a.text}"` : undefined;
248
+ const v = a.value ?? legacy ?? asIs ?? own ?? a.verdict;
247
249
  return Array.isArray(v) ? [...v].sort().join(', ') : String(v);
248
250
  }
249
251
  // @comment -- "Plain-text summary for the agent, most important first: disagreements, edits and rejections, the must-touch decisions with who made them, unanswered questions, then one line per group of suggestions accepted as is, with names; no model involved."
@@ -608,8 +608,8 @@ async function apply(answers, s, d, opts, has) {
608
608
  ? [
609
609
  `Open ${tool} in ${tildify(repo, d.env.HOME)} and say anything, for example "let's start".`,
610
610
  '',
611
- ' Bravos begins by learning what the app is for: it asks for your design documents,',
612
- ' then opens a page for you to confirm. After that it maps the threats in your code.',
611
+ ' Bravos starts mapping the threats right away, against its own draft of what the app',
612
+ ' is for, and asks you to confirm that draft on a page (a few minutes, whenever suits).',
613
613
  '',
614
614
  'Autopilot can review later changes in your agent. Live testing follows the preference and target you authorized.',
615
615
  copied ? `If it does not begin by itself, type ${handoff} (it is on your clipboard). ${banner}` : `If it does not begin by itself, type ${handoff}. ${banner}`,
@@ -618,7 +618,7 @@ async function apply(answers, s, d, opts, has) {
618
618
  : [
619
619
  `Open ${tool} in ${tildify(repo, d.env.HOME)} and type:`,
620
620
  '',
621
- ` ${handoff} learns what the app is for (asks you a few questions)`,
621
+ ` ${handoff} drafts what the app is for and asks you to confirm it`,
622
622
  ` ${sigil(lead)}bravos-annotate maps the threats in your code`,
623
623
  '',
624
624
  'Autopilot can review later changes in your agent. Live testing follows the preference and target you authorized.',
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)\.mjs/.test(c);
8
+ const isBravosCommand = (c) => typeof c === 'string' && /\.bravos\/hooks\/(session-start|pre-pr|autopilot|coach)\.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
@@ -112,11 +112,23 @@ Skills: `/bravos` · `/bravos-recheck`
112
112
 
113
113
  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.
114
114
 
115
- ### Context comes first
115
+ ### The intake asks, it never blocks
116
116
 
117
117
  Skills: `/bravos-context` · `/bravos-annotate`
118
118
 
119
- Threat-modelling starts only when a named person has confirmed what the product intends: bravos-annotate, campaigns and the nightly workflows wait until at least one item in .guardlink/intent.md is confirmed (run bravos-context; it asks for your design documents and a few decisions). A team that chooses to go without records that under a name, bravos context decline --by "<name>", which is committed like the intent; a coding agent is told never to decline for you. bravos context gate says which state a repository is in. Rechecks, retests and the ship check are not held back: they maintain a model that already exists.
119
+ 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.
120
+
121
+ ### The coach
122
+
123
+ Skills: `/bravos`
124
+
125
+ 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.
126
+
127
+ ### Background annotation
128
+
129
+ Skills: `/bravos-annotate`
130
+
131
+ 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.
120
132
 
121
133
  ### Threat-model someone else's project
122
134
 
@@ -128,7 +140,7 @@ bravos-context assumes you are researching software you do not own (an open-sour
128
140
 
129
141
  Skills: `/bravos-context`
130
142
 
131
- bravos-context opens its questions as a bravos page (bravos review intent): pre-filled with bravos's suggestions and their sources; change what is wrong, make the calls marked 'needs your call' (Confirm stays off until you do), and the facts bravos drafted stay folded unless you open one to object. The role-by-action matrix links each documented permission to its question. In local reviews, open a cited SRC document to read its verified text. The saved HTML can contain these documents. Each person's answers save to .guardlink/intent-answers/<name>.json; teammates run bravos review intent after pulling and commit theirs. Press Done when you are finished: the agent runs bravos review intent --wait and carries on by itself. bravos review intent --summary shows where people agree and disagree; only what a named person agreed to is marked confirmed. On Claude Code, --share prepares an artifact with the draft and its citations. Publish that artifact to share it.
143
+ bravos-context opens its questions as a bravos page (bravos review intent): pre-filled with bravos's suggestions and their sources; change what is wrong, make the calls marked 'needs your call' (Confirm stays off until you do), and the facts bravos drafted stay folded unless you open one to object. The role-by-action matrix links each documented permission to its question. In local reviews, open a cited SRC document to read its verified text. The saved HTML can contain these documents. Each person's answers save to .guardlink/intent-answers/<name>.json; teammates run bravos review intent after pulling and commit theirs. Press Confirm when you are finished: that saves your answers and the agent, waiting on bravos review intent --wait, carries on by itself. bravos review intent --summary shows where people agree and disagree; only what a named person agreed to is marked confirmed. On Claude Code, --share prepares an artifact with the draft and its citations. Publish that artifact to share it.
132
144
 
133
145
  ### I wrote security-relevant code
134
146
 
package/docs/UPGRADING.md CHANGED
@@ -2,6 +2,54 @@
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. 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.11.0
6
+
7
+ 1.11 makes Bravos speak up instead of waiting to be asked.
8
+
9
+ - **The coach.** Before each prompt, a fast hook may add one line for your agent. It runs no guardlink and no network.
10
+ - **A question about the security picture** (issues, threats, vulnerabilities, findings or risks) builds the dashboard while the agent answers. It opens in your browser the first time in a session; later questions rebuild it and give the path.
11
+ - **Reminders, from the second prompt on.** Each topic comes once a session, at most one per prompt:
12
+ - claims waiting to be confirmed, with the next step: `bravos-env` to set up a target (you type the authorization), then `bravos-prove`;
13
+ - how much of the code the threat model covers, with the next round;
14
+ - a dashboard older than the threat model.
15
+ - **Where it runs:** Claude Code and Codex, in every repository `bravos setup` brings up to date, and in both plugins.
16
+ - **Seeing it:** `bravos doctor` shows it, `bravos watch` lists each reminder, and `bravos uninstall` removes it.
17
+ - **Turning it off:** `BRAVOS_COACH=off` for one run, or `bravos prefs set coach off --by "<your name>"` for the clone.
18
+ - **Every round ends with a next step.** Annotation, proving, rechecks and campaigns end three ways:
19
+ - with the coverage ("N of K files annotated");
20
+ - with the dashboard rebuilt;
21
+ - with one recommendation, such as "let's confirm the top three now", rather than a list of what testing needs.
22
+ - **The session-start coaching steps up.** Every security-relevant reply ends with one concrete next step, and each reminder comes at most once a session.
23
+ - **For scripts:**
24
+ - `bravos prefs get --json` gains `coach`;
25
+ - `bravos doctor --json` gains `coach`;
26
+ - `.claude/settings.json` and `.codex/hooks.json` gain a `UserPromptSubmit` entry.
27
+
28
+ ## 1.10.0
29
+
30
+ 1.10 stops the intake from holding annotation back. Bravos maps threats from the first session, and asks you to confirm what the app is for without waiting on it.
31
+
32
+ - **Annotation no longer waits for the intake.** With no confirmed intent, the agent drafts what the app is for from the README, docs and code. It writes the draft to `.guardlink/intent.md` with every item marked `— draft`, annotates against it, and opens the intake page without waiting.
33
+ - Every session asks you once to confirm it (`bravos review intent`, a few minutes) until someone confirms or declines.
34
+ - `bravos context decline --by "<name>"` still ends the asking.
35
+ - The agent never confirms or declines for you.
36
+ - **Your answers are applied when they arrive.** After you confirm, the agent rewrites the intent from your answers and rechecks the findings they change. For example, something you mark as intended by design is annotated as intended, not as a finding.
37
+ - **Rules drafted from your design count straight away.** They are tested, and they can block a pull request like confirmed rules. `bravos rules` marks them `[draft]`, and the block message says "INV-4 (draft: not yet confirmed by a person)".
38
+ - **The nightly workflows annotate whatever the intake's state.** The context job now only reports the state in the run summary. `bravos setup` tells you when a repository's workflows are older than this version; `bravos setup --ci` refreshes them (the nightly and the PR gate, which gains the draft label).
39
+ - **One background annotation pass each session.** While coverage is under 100%, the agent starts one annotation slice in a background subagent in its first reply, alongside what you asked, and says so.
40
+ - It writes annotations only and commits only as your commits answer allows.
41
+ - It does not run on resume, on compact or in CI.
42
+ - `bravos prefs set annotate off --by "<your name>"` switches it off for the clone, and `BRAVOS_AUTO_ANNOTATE=off` switches it off for one session.
43
+ - **The intake page has one button.** Confirm saves your answers and finishes, and the agent carries on from there. Done is gone.
44
+ - **For scripts:**
45
+ - the annotate skill's `slice.mjs` no longer exits 3; its JSON gains `context: {state, confirmed}`;
46
+ - `bravos prefs get --json` gains `annotate`.
47
+
48
+ ## 1.9.3
49
+
50
+ - **Answer in your own words on the context page.** A question with set options (for example "What should bravos rate this against?") now has **✎ My own answer**. Your text is the decision, and the agent receives it as written. Before, typing into the comment box was the only option, and it did not count, so Confirm stayed off.
51
+ - **Done is honest.** Pressing Done before Confirm says what is still open instead of closing as if your answers had been saved.
52
+
5
53
  ## 1.9.2
6
54
 
7
55
  - **Joining a repository shows its setup.** In a repository that already has Bravos, `bravos setup` lists what it is set up with (agents, pull-request checks, autopilot, schedule, testing) and asks whether to keep it or change it. Keep is the default and changes nothing; Change asks the repository's questions with what is there selected.
@@ -0,0 +1,85 @@
1
+ // @comment -- "bravos coach UserPromptSubmit hook entry (Claude Code and Codex): reads the prompt payload with a bounded wait, decides what to add for the agent (hooks/lib/coach.mjs) and prints it as additionalContext, logging each reminder for bravos watch. Never runs guardlink or the network. Silent when BRAVOS_COACH=off, when the person switched the coach off (bravos prefs set coach off), or when it is the plugin's copy in a repository that registers its own. Always exits 0; a failure adds nothing."
2
+ import { realpathSync, readFileSync } from 'node:fs';
3
+ import { join } from 'node:path';
4
+ import { spawnSync } from 'node:child_process';
5
+ import { fileURLToPath } from 'node:url';
6
+ import { coachTurn, newestModelChange, readCoach, writeCoach } from './lib/coach.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
+ const git = (cwd, args) => {
27
+ const r = spawnSync('git', args, { cwd, encoding: 'utf8', timeout: 3000, stdio: ['ignore', 'pipe', 'ignore'] });
28
+ return r.status === 0 ? r.stdout.trim() : '';
29
+ };
30
+
31
+ // The plugin's copy stays quiet where the repository registers its own coach, so the agent never hears it twice.
32
+ function deferToRepo(root) {
33
+ try {
34
+ if (realpathSync(fileURLToPath(import.meta.url)) === realpathSync(join(root, '.bravos', 'hooks', 'coach.mjs'))) return false;
35
+ } catch {
36
+ /* no repository copy */
37
+ }
38
+ for (const f of ['.claude/settings.json', '.codex/hooks.json']) {
39
+ try {
40
+ if (readFileSync(join(root, f), 'utf8').includes('.bravos/hooks/coach.mjs')) return true;
41
+ } catch {
42
+ /* not registered there */
43
+ }
44
+ }
45
+ return false;
46
+ }
47
+
48
+ function readDashboard(root) {
49
+ try {
50
+ const m = JSON.parse(readFileSync(join(root, '.bravos', 'dashboard', 'meta.json'), 'utf8'));
51
+ const at = Date.parse(m?.generatedAt);
52
+ return Number.isFinite(at) ? { generatedAt: at, commit: typeof m.commit === 'string' && /^[0-9a-f]{7,40}$/.test(m.commit) ? m.commit : null } : null;
53
+ } catch {
54
+ return null;
55
+ }
56
+ }
57
+
58
+ async function main() {
59
+ let out = {};
60
+ try {
61
+ if (process.env.BRAVOS_COACH === 'off') throw new Error('off');
62
+ const payload = await readPayload();
63
+ const cwd = typeof payload.cwd === 'string' ? payload.cwd : process.env.CLAUDE_PROJECT_DIR || process.cwd();
64
+ const root = git(cwd, ['rev-parse', '--show-toplevel']) || cwd;
65
+ if (deferToRepo(root)) throw new Error('repo copy');
66
+ const commonDir = gitCommonDir(root);
67
+ if (readPrefs(commonDir).coach?.value === 'off') throw new Error('off');
68
+ const harness = process.argv.includes('--harness') ? process.argv[process.argv.indexOf('--harness') + 1] : process.env.CLAUDE_PROJECT_DIR ? 'claude' : 'other';
69
+ const record = readCoach(commonDir, payload.session_id) ?? { facts: { coverage: null, queued: 0, top: [], target: false, licensed: null, harness: harness === 'claude' ? 'claude' : 'other' }, raised: [], prompts: 0, opened: false };
70
+ const dashboard = readDashboard(root);
71
+ const r = coachTurn({ record, prompt: payload.prompt, dashboard, modelChangedAt: dashboard ? newestModelChange(root) : 0, head: dashboard?.commit ? git(root, ['rev-parse', 'HEAD']) : null });
72
+ const { facts, ...rest } = r.record;
73
+ writeCoach(commonDir, payload.session_id, { facts, ...rest });
74
+ if (r.text) {
75
+ out = { hookSpecificOutput: { hookEventName: 'UserPromptSubmit', additionalContext: r.text } };
76
+ logWatchEvent(root, { summary: `coach: ${r.topics.join(', ')}`, keys: r.topics.map((t) => `bravos-coach:${t}`) });
77
+ }
78
+ } catch {
79
+ out = {};
80
+ }
81
+ process.stdout.write(JSON.stringify(out) + '\n');
82
+ process.exit(0);
83
+ }
84
+
85
+ main();
@@ -181,20 +181,15 @@ export async function runAutopilot({ root, env = process.env, payload = {}, run
181
181
  }
182
182
  const paths = rows => arr(rows).map(w => typeof w === 'string' ? w : w?.file ?? w?.path)
183
183
  .filter(path => changedSource(path) && !isGenerated(path) && !configFiles.has(path));
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.
184
+ // @comment -- "Changed files are put forward for annotation whatever the intake's state. While nobody has confirmed what the product is for, one more note (raised once a session, like every note) asks the agent to ask the person to confirm the draft: the intake informs, it never holds annotation back."
187
185
  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
- }
186
+ if (!gate.open && (paths(wl?.worklist).length || paths(wl?.annotated).length)) add(`context:${gate.state}`, gate.message);
187
+ for (const path of paths(wl?.worklist)) {
188
+ add(`unannotated:${path}`, `${path} has no GuardLink annotation: review the change with bravos-annotate; record any security-relevant behavior.`);
189
+ }
190
+ for (const path of paths(wl?.annotated)) {
191
+ const ranges = hunks.get(path)?.map(h => h.start === h.end ? h.start : `${h.start}-${h.end}`).join(', ');
192
+ 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.`);
198
193
  }
199
194
 
200
195
  const excluded = new Set(arr(wl?.excluded).map(e => e?.path ?? e?.file));