@bugb-technologies/bravos 1.7.0 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/README.md +11 -7
  2. package/dist/ci.js +1 -1
  3. package/dist/cli.js +271 -111
  4. package/dist/codegraph.js +21 -0
  5. package/dist/context.js +1 -1
  6. package/dist/doctor.js +20 -11
  7. package/dist/global.js +3 -3
  8. package/dist/graphbin.js +2 -0
  9. package/dist/guardlink.js +1 -1
  10. package/dist/guide.js +12 -10
  11. package/dist/help.js +45 -19
  12. package/dist/hooks.js +44 -21
  13. package/dist/install.js +2 -1
  14. package/dist/lock.js +1 -0
  15. package/dist/mcp.js +21 -5
  16. package/dist/palette.js +2 -2
  17. package/dist/plugin-release.js +2 -2
  18. package/dist/plugin.js +3 -3
  19. package/dist/prefs.js +66 -0
  20. package/dist/review-wait.js +76 -0
  21. package/dist/setup-route.js +37 -0
  22. package/dist/setup.js +3 -2
  23. package/dist/skills.js +1 -1
  24. package/dist/start/answers.js +36 -7
  25. package/dist/start/index.js +190 -69
  26. package/dist/start/repos.js +1 -1
  27. package/dist/start/ui.js +2 -2
  28. package/dist/upkeep.js +89 -0
  29. package/dist/watch-frame.js +1 -1
  30. package/dist/watch.js +1 -1
  31. package/docs/GUIDE.md +23 -11
  32. package/docs/UPGRADING.md +43 -1
  33. package/hooks/lib/autopilot.mjs +3 -18
  34. package/hooks/lib/briefing.mjs +93 -14
  35. package/hooks/lib/graph-autobuild.mjs +131 -0
  36. package/hooks/lib/legacy-skills.mjs +68 -0
  37. package/hooks/lib/palette.mjs +4 -4
  38. package/hooks/lib/prefs.mjs +108 -0
  39. package/hooks/lib/refresh.mjs +45 -1
  40. package/hooks/lib/setup.mjs +8 -8
  41. package/hooks/lib/snapshot.mjs +19 -1
  42. package/hooks/session-start.mjs +7 -2
  43. package/package.json +1 -1
  44. package/skills/bravos/SKILL.md +5 -4
  45. package/skills/bravos-annotate/SKILL.md +4 -4
  46. package/skills/bravos-cicd/SKILL.md +1 -1
  47. package/skills/bravos-codegraph/SKILL.md +1 -1
  48. package/skills/bravos-context/SKILL.md +6 -6
  49. package/skills/bravos-env/SKILL.md +2 -2
  50. package/skills/bravos-env/scope.example.yaml +2 -1
  51. package/skills/bravos-prove/SKILL.md +2 -2
  52. package/skills/bravos-recheck/SKILL.md +1 -1
  53. package/skills/bravos-resync/SKILL.md +1 -1
  54. package/skills/bravos-schedule/SKILL.md +1 -1
  55. package/skills/bravos-ship/SKILL.md +3 -3
  56. package/skills/bravos-templatize/SKILL.md +1 -1
  57. package/templates/review/review.html +1 -1
@@ -1,12 +1,14 @@
1
- // @comment -- "bravos start: the guided first run. One question per step (theme, licence, tools, repository, agents, goal, PR checks, autopilot, schedule, testing permission, continuous pentest, the person's words and name, GitHub secrets), each step able to go back with Esc, then every change and the equivalent bravos init command, and nothing written until the person says Apply; signing in is the one step that acts when chosen. It then installs through the existing commands, records the proving choice in the person's own words, builds the code graph and reports what it found, and hands the first annotation to their own agent — bravos never starts an agent itself."
2
- import { mkdirSync, writeFileSync } from 'node:fs';
1
+ // @comment -- "bravos setup: the guided first run. One question per step (theme, licence, tools, repository, agents, goal, PR checks, autopilot, schedule, testing permission, continuous pentest, the person's words and name, GitHub secrets), each step able to go back with Esc, then every change and the equivalent bravos setup command, and nothing written until the person says Apply; signing in is the one step that acts when chosen. It then installs through the existing commands, records the proving choice in the person's own words, builds the code graph and reports what it found, and hands the first annotation to their own agent — bravos never starts an agent itself."
2
+ import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
3
3
  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, PENTEST_COST_URL, PRESETS, provingText, readAnswers, writeAnswers, writeTheme, } from './answers.js';
7
+ import { initArgs, nightlySecrets, normalTarget, PRESETS, provingText, readAnswers, targetProblem, 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
+ import { BravosError } from '../types.js';
11
+ import { prefsLib } from '../prefs.js';
10
12
  const AGENTS = [
11
13
  { value: 'claude', label: 'Claude Code' },
12
14
  { value: 'codex', label: 'Codex' },
@@ -69,14 +71,40 @@ async function flow(opts, d) {
69
71
  if (shadow && /\.local\/bin\/bravos$|site-packages|pipx/.test(shadow)) {
70
72
  p.warn(`The old Python bravos at ${shadow} may run instead of this one. Rename it: mv ${shadow} ${shadow}-py`);
71
73
  }
74
+ // What to type to ask the repository's questions again, in the words of the command the person used.
75
+ const change = opts.command === 'setup' ? 'bravos setup --change' : 'bravos start --again';
76
+ // @comment -- "The setup has two parts, and each says so once: this machine (colours, sign-in, tools: set once, used by every repository) and this repository (agents, checks, testing: recorded in the repository for the team). A second repository on a machine that is ready skips the first part with one line saying so."
77
+ const said = { machine: false, repository: false };
78
+ const heading = (part) => {
79
+ if (said[part])
80
+ return;
81
+ said[part] = true;
82
+ p.info(part === 'machine'
83
+ ? 'This machine — colours, sign-in and tools. Set once; every repository on this machine uses them.'
84
+ : 'This repository — which agents, pull-request checks and testing. Recorded in the repository, so your team gets the same.');
85
+ };
86
+ let themeKept = false;
72
87
  const has = (s, f) => !!s.lic?.unlocked.includes(f);
73
88
  const missingTools = (s) => (s.items ?? []).filter((i) => (i.id === 'guardlink' || i.id === 'cxg') && (!i.present || (i.proofTool && i.proofTool.status !== 'ready')));
74
- const missingBundles = (s) => (s.items ?? []).filter((i) => (i.id === 'analyzer' || i.id === 'codegraph') && !i.present && i.licensed);
89
+ // A bundle older than this version pins counts as missing: setting up again after an upgrade must bring it up to date.
90
+ const missingBundles = (s) => (s.items ?? []).filter((i) => (i.id === 'analyzer' || i.id === 'codegraph') && (!i.present || !!i.behind) && i.licensed);
91
+ // @comment -- "A repository-level question is skipped when joining: those answers are the team's, already committed."
92
+ const team = (step) => async (s) => {
93
+ if (!s.join)
94
+ await step(s);
95
+ };
75
96
  const steps = [
76
97
  // theme
77
98
  async (s) => {
78
- p.note(themeSample(), 'Colours');
79
99
  const detected = resolveTheme(d.env);
100
+ // Colours chosen in an earlier setup are kept; --change asks again.
101
+ themeKept = !opts.again && s.theme === undefined && detected.source.startsWith('saved');
102
+ if (themeKept) {
103
+ s.theme = detected.theme;
104
+ return;
105
+ }
106
+ heading('machine');
107
+ p.note(themeSample(), 'Colours');
80
108
  const initial = s.theme ?? saved?.theme ?? detected.theme;
81
109
  s.theme = await p.select('theme', 'How does your terminal look?', [
82
110
  { value: 'dark', label: 'Dark background', recommended: detected.source !== 'default' && detected.theme === 'dark' },
@@ -87,6 +115,8 @@ async function flow(opts, d) {
87
115
  // licence
88
116
  async (s) => {
89
117
  s.lic = await d.licence();
118
+ if (!s.lic.licensed && !opts.yes)
119
+ heading('machine');
90
120
  if (!s.lic.licensed && !opts.yes) {
91
121
  const how = await p.select('licence', 'No Bravos licence on this machine yet.', [
92
122
  { value: 'activate', label: 'Sign in now', hint: 'activate your licence, or start the free 30-day Team trial', recommended: true },
@@ -113,20 +143,35 @@ async function flow(opts, d) {
113
143
  p.note(s.items.map((i) => {
114
144
  if (i.present && i.proofTool && i.proofTool.status !== 'ready')
115
145
  return `✗ ${i.id.padEnd(10)} ${i.present} needs a compatible build for ${i.proofTool.capability}`;
146
+ if (i.present && i.behind && i.licensed)
147
+ return `↑ ${i.id.padEnd(10)} ${i.behind} installed, this version uses ${i.wanted}`;
116
148
  return `${i.present ? '✔' : '✗'} ${i.id.padEnd(10)} ${i.present ? 'installed' : i.licensed === false ? 'Team plan' : `missing — ${i.action}`}`;
117
149
  }).join('\n'), 'Tools');
118
150
  const missing = [...missingTools(s), ...missingBundles(s)];
151
+ // @comment -- "The answer given before (Esc returns here) is kept as the default; the first time the default is yes. It used to be reset to no before the question, so Enter skipped the install. An unattended run is never asked: it fetches Bravos's own bundles at Apply and leaves guardlink and cxg, whose installers are other people's, to a person."
152
+ const before = s.installTools;
119
153
  s.installTools = false;
120
- if (!missing.length)
154
+ if (!missing.length && themeKept && s.lic?.licensed)
155
+ p.info('This machine is ready: signed in, tools installed, colours chosen. Nothing to set up here.');
156
+ if (!missing.length || opts.yes)
121
157
  return;
158
+ heading('machine');
122
159
  if (missingTools(s).some((i) => i.id === 'cxg') && !d.which('cargo')) {
123
160
  p.warn('cxg (the test engine) installs with Rust\'s cargo, which is not here. Install Rust first: curl --proto \'=https\' --tlsv1.2 -sSf https://sh.rustup.rs | sh — or skip cxg for now; annotations work without it.');
124
161
  }
125
- s.installTools = await p.confirm('tools', `Install ${missing.map((i) => i.id).join(', ')} when you apply?`, s.installTools ?? true);
162
+ s.installTools = await p.confirm('tools', `Install ${missing.map((i) => i.id).join(', ')} when you apply?`, before ?? true);
126
163
  },
127
164
  // repository
128
165
  async (s) => {
166
+ heading('repository');
129
167
  let repo = opts.dir ? resolve(opts.dir) : '';
168
+ // @comment -- "An unattended run sets up the folder it was given, or the one it runs in, and nothing else: it never looks around for a repository to pick, because nobody is there to see which one it chose. A folder that is not a git repository is refused before anything is written."
169
+ if (opts.yes) {
170
+ repo = repo || resolve(d.cwd);
171
+ const problem = repoProblem(repo);
172
+ if (problem)
173
+ throw new BravosError(`${tildify(repo, d.home)}: ${problem}. Nothing was changed. Run it inside the repository, or name it: bravos ${opts.command ?? 'start'} --yes <dir>`);
174
+ }
130
175
  if (repo && repoProblem(repo)) {
131
176
  p.warn(`${tildify(repo)}: ${repoProblem(repo)}`);
132
177
  repo = '';
@@ -134,6 +179,7 @@ async function flow(opts, d) {
134
179
  if (!repo) {
135
180
  const found = findRepos(d.cwd, { home: d.home });
136
181
  const choices = [...found.map((r, i) => ({ value: r, label: tildify(r, d.home), hint: repoHint(r, d.cwd), recommended: i === 0 && r === d.cwd })), { value: '__path__', label: 'Type a path…' }];
182
+ // An older setup.json may still hold the path it was written with; newer ones never do.
137
183
  const prev = s.repoPicked ?? (saved?.repo && isGitRepo(saved.repo) ? saved.repo : undefined);
138
184
  const initial = prev && choices.some((c) => c.value === prev) ? prev : found[0] ?? '__path__';
139
185
  for (;;) {
@@ -153,9 +199,16 @@ async function flow(opts, d) {
153
199
  }
154
200
  }
155
201
  s.repo = repo;
202
+ // @comment -- "Joining: the repository already carries Bravos's files and the team's recorded setup, so a teammate (or a second machine) is asked only about this machine, and nothing the team decided is rewritten. bravos setup --change is the way to change the repository's setup."
203
+ // The lock alone means Bravos is here, whichever way it was installed (the guided setup, or flags, which leave no setup.json): bravos setup in such a repository brings it up to date, and only --change asks its questions.
204
+ s.join = !opts.again && existsSync(join(repo, '.bravos', 'skills.lock'));
205
+ if (s.join) {
206
+ s.agents = readAnswers(repo)?.agents ?? s.agents;
207
+ p.info(`Bravos is already set up in this repository, so only this machine is set up now; the team's choices stay as they are. To change them: ${change}`);
208
+ }
156
209
  },
157
210
  // agents
158
- async (s) => {
211
+ team(async (s) => {
159
212
  const det = detectHarnesses(s.repo);
160
213
  const seen = new Set([
161
214
  ...(det.harnesses.includes('claude') && !det.defaulted ? ['claude'] : []),
@@ -166,17 +219,17 @@ async function flow(opts, d) {
166
219
  ]);
167
220
  const agents = await p.multiselect('agents', 'Which AI coding tools do you use here?', AGENTS.map((a) => ({ ...a, hint: seen.has(a.value) ? 'found on this machine' : undefined })), s.agents ?? saved?.agents ?? (seen.size ? [...seen] : ['claude']));
168
221
  s.agents = agents.length ? agents : ['claude'];
169
- },
222
+ }),
170
223
  // goal
171
- async (s) => {
224
+ team(async (s) => {
172
225
  if (opts.preset) {
173
226
  s.preset = opts.preset;
174
227
  return;
175
228
  }
176
229
  s.preset = await p.select('preset', 'What should Bravos do for you? (you can change each part next)', Object.keys(PRESETS).map((k) => ({ value: k, label: PRESETS[k].label, hint: PRESETS[k].hint, recommended: k === 'pr' })), s.preset ?? saved?.preset ?? 'pr');
177
- },
230
+ }),
178
231
  // pull requests
179
- async (s) => {
232
+ team(async (s) => {
180
233
  const prChoices = [
181
234
  { value: 'none', label: 'Nothing' },
182
235
  ...(has(s, 'pre-pr') ? [{ value: 'hook', label: 'Check before a PR is opened', hint: 'your agent\'s gh pr create waits for annotations' }] : []),
@@ -189,17 +242,17 @@ async function flow(opts, d) {
189
242
  }
190
243
  const want = s.pr ?? saved?.pr ?? PRESETS[s.preset].pr;
191
244
  s.pr = await p.select('pr', 'When someone opens a pull request:', prChoices, prChoices.some((c) => c.value === want) ? want : 'none');
192
- },
245
+ }),
193
246
  // autopilot
194
- async (s) => {
247
+ team(async (s) => {
195
248
  if (!has(s, 'pre-pr') || s.preset === 'annotate') {
196
249
  s.autopilot = false;
197
250
  return;
198
251
  }
199
- s.autopilot = await p.confirm('autopilot', 'Review changed code at the end of each agent turn? Autopilot asks the agent to update relevant claims and follows your testing preference.', s.autopilot ?? saved?.autopilot ?? (s.preset === 'pr' && !opts.yes ? true : PRESETS[s.preset].autopilot));
200
- },
252
+ s.autopilot = await p.confirm('autopilot', 'Review changed code at the end of each agent turn? Autopilot asks the agent to update relevant claims and follows your testing preference.', s.autopilot ?? saved?.autopilot ?? PRESETS[s.preset].autopilot);
253
+ }),
201
254
  // scheduled run (GitHub Actions)
202
- async (s) => {
255
+ team(async (s) => {
203
256
  s.nightlyAgent = s.agents.includes('codex') && !s.agents.includes('claude') ? 'codex' : 'claude';
204
257
  if (!has(s, 'ci')) {
205
258
  p.info('Scheduled runs are on the Team plan.');
@@ -213,9 +266,9 @@ async function flow(opts, d) {
213
266
  { value: 'weekday', label: 'Every weekday night' },
214
267
  { value: 'daily', label: 'Every night' },
215
268
  ], s.schedule ?? saved?.schedule ?? PRESETS[s.preset].schedule);
216
- },
269
+ }),
217
270
  // which agent runs on the schedule
218
- async (s) => {
271
+ team(async (s) => {
219
272
  if (s.schedule === 'none' || opts.yes)
220
273
  return;
221
274
  const usual = s.nightlyAgent ?? 'claude';
@@ -224,9 +277,9 @@ async function flow(opts, d) {
224
277
  { value: 'copilot', label: 'GitHub Copilot', hint: 'runs on your Copilot plan; Copilot opens the pull request' },
225
278
  { value: 'codex', label: 'Codex', hint: 'needs an OpenAI API key', recommended: usual === 'codex' },
226
279
  ], saved?.nightlyAgent ?? usual);
227
- },
280
+ }),
228
281
  // testing permission
229
- async (s) => {
282
+ team(async (s) => {
230
283
  if (opts.yes) {
231
284
  s.proving = 'none';
232
285
  return;
@@ -236,7 +289,7 @@ async function flow(opts, d) {
236
289
  const autoReady = defaultRef.code === 0 && !!defaultRef.out.trim()
237
290
  && d.exec('git', ['rev-parse', '--verify', `${defaultRef.out.trim()}^{commit}`], { cwd: s.repo }).code === 0;
238
291
  if (!autoReady)
239
- p.warn('Automatic proving is unavailable: origin/HEAD is missing or unresolved. Fetch the default branch, then run git remote set-head origin --auto (or git remote set-head origin <branch>), and run bravos start --again. Use Ask me every time for a local clone.');
292
+ p.warn(`Automatic proving is unavailable: origin/HEAD is missing or unresolved. Fetch the default branch, then run git remote set-head origin --auto (or git remote set-head origin <branch>), and run ${change}. Use Ask me every time for a local clone.`);
240
293
  const choices = [
241
294
  { value: 'ask', label: 'Ask me every time before testing', recommended: true },
242
295
  ...(autoReady ? [
@@ -253,33 +306,48 @@ async function flow(opts, d) {
253
306
  const choice = await p.select('proving', 'How should Bravos handle testing?', choices, choices.some((c) => c.value === want) ? want : 'ask');
254
307
  s.proving = choice === 'auto-reviewed' ? 'auto' : choice;
255
308
  s.kitPolicy = choice === 'auto-reviewed' ? 'reviewed' : 'session';
256
- },
257
- // Optional external generation is separate from replaying harness-authored tests.
258
- async (s) => {
259
- if (s.proving === 'none') {
260
- s.generation = false;
309
+ }),
310
+ // where the app runs locally: optional, and only for automatic testing
311
+ // @comment -- "With automatic testing chosen, the person may say where their own app listens. It is checked by the rules replay enforces and written into proving.md, so the policy needs one merge and not a second one just to add the target. Empty is a fine answer: the agent finds it later (bravos-env). The model-API generation question that stood here is gone: Bravos never uses cxg's model generation, so there was nothing a yes could turn on."
312
+ team(async (s) => {
313
+ s.generation = false;
314
+ if (s.proving !== 'auto') {
315
+ s.target = undefined;
261
316
  return;
262
317
  }
263
- p.info(`Your coding agent can write tests in this session. Optional CXG model generation spends additional credits. See ${PENTEST_COST_URL}`);
264
- s.generation = await p.confirm('generation', 'Allow CXG to generate additional probes through a paid model API?', s.generation ?? saved?.generation ?? false, { yes: 'Allow model API spend', no: 'Use the current agent and supplied tests', recommend: false });
265
- },
318
+ const typed = await p.text('target', 'Where does your app run locally? (leave empty and your agent finds it)', { initial: s.target ?? saved?.target ?? '', placeholder: 'http://localhost:3000', validate: targetProblem });
319
+ s.target = normalTarget(typed);
320
+ }),
266
321
  // the person's own words
267
- async (s) => {
322
+ team(async (s) => {
268
323
  if (s.proving !== 'auto' && s.proving !== 'schedule')
269
324
  return;
270
325
  s.words = await p.text('words', 'In your own words: what may Bravos test without asking? (recorded as your authorization)', { initial: s.words, validate: (v) => (v.trim().length >= 10 ? undefined : 'Write a sentence in your own words.') });
271
- },
326
+ }),
272
327
  // who confirmed it
273
- async (s) => {
328
+ team(async (s) => {
274
329
  if (opts.yes) {
275
330
  s.name = '';
276
331
  return;
277
332
  }
278
333
  const gitName = s.name || d.exec('git', ['config', 'user.name'], { cwd: s.repo }).out.trim();
279
334
  s.name = await p.text('name', 'Your name, recorded with this choice', { initial: gitName || undefined, validate: (v) => (v.trim() ? undefined : 'Your name, please.') });
335
+ }),
336
+ // commits: asked of every person, joining or not, because the answer is theirs and stays in their clone
337
+ // @comment -- "The one question the agent used to ask at the start of every session: what to do with the files Bravos writes. Asked once here and recorded for this person in this clone (bravos prefs), so sessions follow it without asking. --yes records nothing: a person has to answer it."
338
+ async (s) => {
339
+ if (opts.yes) {
340
+ s.commits = undefined;
341
+ return;
342
+ }
343
+ s.commits = await p.select('commits', 'When Bravos writes its own files (annotations, intent, tests), should your agent commit them?', [
344
+ { value: 'commit', label: 'Yes, commit them', hint: 'never your own code; change it any time with bravos prefs', recommended: true },
345
+ { value: 'leave', label: 'No, leave them for me', hint: 'the agent lists what it wrote' },
346
+ { value: 'ask', label: 'Ask me each session' },
347
+ ], s.commits ?? 'commit');
280
348
  },
281
349
  // GitHub secrets for the scheduled run: held in memory until Apply, never written to a file.
282
- async (s) => {
350
+ team(async (s) => {
283
351
  s.secrets = {};
284
352
  const needed = nightlySecrets({ schedule: s.schedule, nightlyAgent: s.nightlyAgent });
285
353
  if (!needed.length)
@@ -313,7 +381,7 @@ async function flow(opts, d) {
313
381
  if (v.trim())
314
382
  s.secrets[n] = v.trim();
315
383
  }
316
- },
384
+ }),
317
385
  ];
318
386
  // Run the steps. Esc in a step returns to the last step that asked something.
319
387
  const s = { secrets: {} };
@@ -340,19 +408,23 @@ async function flow(opts, d) {
340
408
  const answers = toAnswers(s);
341
409
  const changes = [
342
410
  `Colours: ${answers.theme} (saved in ${tildify(join(d.home, 'config.json'), d.env.HOME)})`,
343
- ...(answers.installTools ? [`Install: ${[...missingTools(s), ...missingBundles(s)].map((i) => i.id).join(', ')}`] : []),
411
+ ...(answers.installTools ? [`Install: ${[...missingTools(s), ...missingBundles(s)].map((i) => i.id).join(', ')}`] : opts.yes && missingBundles(s).length ? [`Install: ${missingBundles(s).map((i) => i.id).join(', ')}`] : []),
412
+ ...(s.commits ? [`Commits: ${{ commit: 'your agent commits Bravos\'s own files without asking', leave: 'your agent leaves Bravos\'s files for you', ask: 'your agent asks each session' }[s.commits]} (your answer, kept in this clone only)`] : []),
344
413
  `In ${tildify(answers.repo, d.env.HOME)}:`,
345
- ` + skills, hooks and MCP for ${answers.agents.join(', ')}`,
346
- ' + .guardlink/ threat model (guardlink init, if not there yet)',
347
- ...(answers.pr !== 'none' ? [' + pre-PR check'] : []),
348
- ...(answers.pr === 'hook+github' ? [' + .github/workflows/bravos-pr-gate.yml'] : []),
349
- ...(answers.autopilot ? [' + autopilot'] : []),
350
- ...(answers.schedule !== 'none' ? [` + .github/workflows/bravos-nightly-${answers.nightlyAgent}.yml (${answers.schedule}, cron ${CRON[answers.schedule]} UTC)`] : []),
351
- ...(answers.schedule !== 'none' && answers.nightlyAgent === 'copilot' ? [' + .github/workflows/copilot-setup-steps.yml (prepares Copilot\'s session: Node and guardlink)'] : []),
352
- ...(answers.proving !== 'none' ? [' + .guardlink/scope.yaml (localhost only; authorization left for you)'] : []),
353
- ...(answers.name ? [` + .guardlink/proving.md (${answers.proving}${answers.generation ? ', model API generation allowed' : ''}, confirmed by ${answers.name})`] : []),
354
- ...(Object.keys(s.secrets).length ? [` + GitHub secrets: ${Object.keys(s.secrets).join(', ')}`] : []),
355
- ' + .bravos/setup.json (your answers, for bravos start --again)',
414
+ ...(s.join ? [' ~ skills, hooks and MCP brought up to date for this machine ', ' = the team\'s setup, testing permission and workflows stay as they are'] : []),
415
+ ...(s.join ? [] : [
416
+ ` + skills, hooks and MCP for ${answers.agents.join(', ')}`,
417
+ ' + .guardlink/ threat model (guardlink init, if not there yet)',
418
+ ...(answers.pr !== 'none' ? [' + pre-PR check'] : []),
419
+ ...(answers.pr === 'hook+github' ? [' + .github/workflows/bravos-pr-gate.yml'] : []),
420
+ ...(answers.autopilot ? [' + autopilot'] : []),
421
+ ...(answers.schedule !== 'none' ? [` + .github/workflows/bravos-nightly-${answers.nightlyAgent}.yml (${answers.schedule}, cron ${CRON[answers.schedule]} UTC)`] : []),
422
+ ...(answers.schedule !== 'none' && answers.nightlyAgent === 'copilot' ? [' + .github/workflows/copilot-setup-steps.yml (prepares Copilot\'s session: Node and guardlink)'] : []),
423
+ ...(answers.proving !== 'none' ? [' + .guardlink/scope.yaml (localhost only; authorization left for you)'] : []),
424
+ ...(answers.name ? [` + .guardlink/proving.md (${answers.proving}${answers.target ? ` on ${answers.target}` : ''}, confirmed by ${answers.name})`] : []),
425
+ ...(Object.keys(s.secrets).length ? [` + GitHub secrets: ${Object.keys(s.secrets).join(', ')}`] : []),
426
+ ` + .bravos/setup.json (your answers, for ${change})`,
427
+ ]),
356
428
  ...(has(s, 'codegraph') ? ['Then: build the code graph for this repository'] : []),
357
429
  ];
358
430
  p.note(changes.join('\n'), 'About to make these changes');
@@ -379,13 +451,14 @@ async function flow(opts, d) {
379
451
  break;
380
452
  p.note([
381
453
  ...(answers.installTools && missingTools(s).length ? ['bravos setup --tools -y'] : []),
382
- ...(answers.installTools && missingBundles(s).length ? ['bravos setup'] : []),
383
- `bravos ${initArgs(answers).map((x) => (/\s/.test(x) ? JSON.stringify(x) : x)).join(' ')}`,
454
+ ...(answers.installTools && missingBundles(s).length ? ['bravos setup --analyzer --codegraph'] : []),
455
+ // Shown as the one command a person would type; Apply runs the same install underneath.
456
+ 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(' ')}`,
384
457
  ...Object.keys(s.secrets).map((n) => `gh secret set ${n} (value from your paste)`),
385
458
  ...(has(s, 'codegraph') ? [`bravos graph build ${JSON.stringify(answers.repo)} --scip no-exec`] : []),
386
459
  ].join('\n'), 'Commands');
387
460
  }
388
- return apply(toAnswers(s), s, d, opts, { missingTools: missingTools(s).length > 0, missingBundles: missingBundles(s).length > 0, codegraph: has(s, 'codegraph') });
461
+ return apply(toAnswers(s), s, d, opts, { missingTools: missingTools(s).length > 0, missingBundles: missingBundles(s).length > 0, codegraph: has(s, 'codegraph'), join: !!s.join, commits: s.commits });
389
462
  }
390
463
  function toAnswers(s) {
391
464
  return {
@@ -400,7 +473,8 @@ function toAnswers(s) {
400
473
  nightlyAgent: s.nightlyAgent ?? 'claude',
401
474
  proving: s.proving ?? 'none',
402
475
  ...(s.proving === 'auto' ? { kitPolicy: s.kitPolicy } : {}),
403
- generation: !!s.generation,
476
+ generation: false,
477
+ ...(s.proving === 'auto' && s.target ? { target: s.target } : {}),
404
478
  words: s.proving === 'auto' || s.proving === 'schedule' ? (s.words ?? '') : '',
405
479
  name: s.name ?? '',
406
480
  };
@@ -409,7 +483,7 @@ async function apply(answers, s, d, opts, has) {
409
483
  const p = d.prompter;
410
484
  const { repo, agents } = answers;
411
485
  writeTheme(d.home, answers.theme);
412
- if (answers.installTools && has.missingTools) {
486
+ if (answers.installTools && has.missingTools && !opts.yes) {
413
487
  const r = await p.spin('Installing guardlink and cxg', () => d.bravos(['setup', '--tools', '-y']), (r) => (r.code ? { fail: 'Installing guardlink and cxg — failed' } : 'Installed guardlink and cxg'));
414
488
  for (const l of [...r.out, ...r.err])
415
489
  (r.code ? p.warn : p.info)(l);
@@ -418,24 +492,43 @@ async function apply(answers, s, d, opts, has) {
418
492
  if (r.code)
419
493
  p.warn('Carrying on without them: annotation and the briefing work now; proving needs guardlink and cxg. Fix the line above, then run bravos setup --tools.');
420
494
  }
421
- if (answers.installTools && has.missingBundles) {
422
- const r = await p.spin('Fetching the Bravos analyzer and code graph', () => d.bravos(['setup']), (r) => (r.code ? { fail: 'Fetching the analyzer and code graph — failed' } : 'Fetched the analyzer and code graph'));
495
+ // The bundles are named: a bare `bravos setup` is the whole setup now, and would start this wizard again. An unattended run fetches them too; they are Bravos's own, signed.
496
+ if ((answers.installTools || opts.yes) && has.missingBundles) {
497
+ const r = await p.spin('Fetching the Bravos analyzer and code graph', () => d.bravos(['setup', '--analyzer', '--codegraph']), (r) => (r.code ? { fail: 'Fetching the analyzer and code graph — failed' } : 'Fetched the analyzer and code graph'));
423
498
  for (const l of [...r.out, ...r.err])
424
499
  (r.code ? p.warn : p.info)(l);
425
500
  }
426
- const init = await p.spin('Setting up the repository', () => d.bravos(initArgs(answers)), (r) => (r.code ? { fail: 'Setting up the repository — failed' } : 'Repository set up'));
501
+ // @comment -- "Joining runs bravos setup, which re-applies what the repository already has and never rewrites the team's choices; a first setup runs bravos setup with the flags the answers amount to."
502
+ const init = has.join
503
+ ? await p.spin('Bringing this machine up to date with the repository', () => d.bravos(['sync', repo]), (r) => (r.code ? { fail: 'Syncing the repository — failed' } : 'Repository in sync'))
504
+ : await p.spin('Setting up the repository', () => d.bravos(initArgs(answers)), (r) => (r.code ? { fail: 'Setting up the repository — failed' } : 'Repository set up'));
427
505
  for (const l of init.out)
428
506
  p.info(l);
429
507
  if (init.code !== 0) {
430
508
  for (const l of init.err)
431
509
  p.warn(l);
432
- p.outro('Setup stopped: bravos init did not finish. Fix the line above and run bravos start --again.');
510
+ p.outro(`Setup stopped: the repository step did not finish. Fix the line above and run ${opts.command === 'setup' ? 'bravos setup' : has.join ? 'bravos start' : 'bravos start --again'} once more.`);
433
511
  return init.code;
434
512
  }
435
- if (answers.name) {
513
+ // Joining never writes the team's proving.md or setup.json: both are theirs, already committed.
514
+ if (answers.name && !has.join) {
436
515
  mkdirSync(join(repo, '.guardlink'), { recursive: true });
437
516
  writeFileSync(join(repo, '.guardlink', 'proving.md'), provingText({ ...answers, words: answers.words || provingLabel(answers.proving) }, d.today()));
438
517
  }
518
+ if (has.commits) {
519
+ // The answer carries the name of the person at this terminal: the one they gave above, else git's.
520
+ const by = answers.name || d.exec('git', ['config', 'user.name'], { cwd: repo }).out.trim();
521
+ const later = `bravos prefs set commits ${has.commits} --by "<your name>"`;
522
+ if (!by)
523
+ p.warn(`Your answer about commits was not recorded (no name to record it under). Later: ${later}`);
524
+ else {
525
+ const r = await d.bravos(['prefs', 'set', 'commits', has.commits, '--by', by, '-C', repo]);
526
+ if (r.code)
527
+ p.warn(`Your answer about commits was not recorded: ${r.err[0] ?? 'bravos prefs failed'}. Later: ${later}`);
528
+ else
529
+ p.info(r.out[0]);
530
+ }
531
+ }
439
532
  for (const [n, v] of Object.entries(s.secrets)) {
440
533
  const r = d.exec('gh', ['secret', 'set', n], { input: v, cwd: repo });
441
534
  (r.code ? p.warn : p.info)(r.code ? `gh secret set ${n} failed — add it in the repository's Settings → Secrets` : `secret ${n} set`);
@@ -446,28 +539,56 @@ async function apply(answers, s, d, opts, has) {
446
539
  for (const n of sum.notes)
447
540
  (sum.ok ? p.info : p.warn)(n);
448
541
  }
449
- writeAnswers(repo, answers, d.version, new Date().toISOString());
542
+ if (!has.join)
543
+ writeAnswers(repo, answers, d.version, new Date().toISOString());
450
544
  // hand-off
451
545
  const next = await d.bravos(['next', repo]);
452
546
  if (next.out.length)
453
547
  p.note(next.out.slice(0, 12).join('\n'), 'Setup score');
454
548
  const lead = agents.includes('claude') ? 'claude' : agents[0];
455
549
  const tool = AGENTS.find((a) => a.value === lead)?.label ?? 'your agent';
550
+ if (has.join) {
551
+ // Joining: the context and the annotations are already the team's; there is nothing to type first.
552
+ p.note([`Open ${tool} in ${tildify(repo, d.env.HOME)}: the Bravos banner shows where the team's threat model stands and the next step.`, 'Follow along in a second terminal: bravos watch'].join('\n'), 'Ready');
553
+ p.outro('This machine is set up for the repository.');
554
+ return 0;
555
+ }
456
556
  const handoff = `${sigil(lead)}bravos-context`;
457
557
  // A scripted run (--yes) leaves the person's clipboard alone.
458
558
  const copied = opts.yes ? false : d.clipboard(handoff);
459
- p.note([
460
- `Open ${tool} in ${tildify(repo, d.env.HOME)} and type:`,
461
- '',
462
- ` ${handoff} learns what the app is for (asks you a few questions)`,
463
- ` ${sigil(lead)}bravos-annotate maps the threats in your code`,
464
- '',
465
- 'Autopilot can review later changes in your agent. Live testing follows the preference and target you authorized.',
466
- copied ? `(${handoff} is on your clipboard.) The Bravos banner shows the next step each time you open a session.` : 'The Bravos banner shows the next step each time you open a session.',
467
- 'Follow along in a second terminal: bravos watch',
468
- ].join('\n'), 'One step left, in your agent');
559
+ // @comment -- "The hand-off: the install step above leaves a dated marker in this clone's git directory (src/prefs.ts leaveHandoff) where the chosen agent runs the session hook, and the briefing then has the agent begin the context step itself. Here the note to the person follows what was written: 'say anything' where the marker is there, else the command to type."
560
+ let begins = false;
561
+ try {
562
+ const L = await prefsLib();
563
+ begins = L.readHandoff(L.gitCommonDir(repo, d.env));
564
+ }
565
+ catch {
566
+ begins = false;
567
+ }
568
+ const banner = 'The Bravos banner shows the next step each time you open a session.';
569
+ p.note((begins
570
+ ? [
571
+ `Open ${tool} in ${tildify(repo, d.env.HOME)} and say anything, for example "let's start".`,
572
+ '',
573
+ ' Bravos begins by learning what the app is for: it asks for your design documents,',
574
+ ' then opens a page for you to confirm. After that it maps the threats in your code.',
575
+ '',
576
+ 'Autopilot can review later changes in your agent. Live testing follows the preference and target you authorized.',
577
+ 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}`,
578
+ 'Follow along in a second terminal: bravos watch',
579
+ ]
580
+ : [
581
+ `Open ${tool} in ${tildify(repo, d.env.HOME)} and type:`,
582
+ '',
583
+ ` ${handoff} learns what the app is for (asks you a few questions)`,
584
+ ` ${sigil(lead)}bravos-annotate maps the threats in your code`,
585
+ '',
586
+ 'Autopilot can review later changes in your agent. Live testing follows the preference and target you authorized.',
587
+ copied ? `(${handoff} is on your clipboard.) ${banner}` : banner,
588
+ 'Follow along in a second terminal: bravos watch',
589
+ ]).join('\n'), 'One step left, in your agent');
469
590
  if (opts.yes && !answers.name)
470
- p.info('Testing permission was not recorded (a person has to answer it): run bravos start --again in a terminal.');
591
+ p.info(`Testing permission was not recorded (a person has to answer it): run ${opts.command === 'setup' ? 'bravos setup --change' : 'bravos start --again'} in a terminal.`);
471
592
  p.outro('Bravos is set up.');
472
593
  return 0;
473
594
  }
@@ -1,4 +1,4 @@
1
- // @comment -- "Finds git repositories to offer in bravos start: the current folder, then repos at most two levels under the current folder's parent and the usual code folders. Read-only directory listings only, capped in count and time, never inside node_modules or dot folders."
1
+ // @comment -- "Finds git repositories to offer in bravos setup: the current folder, then repos at most two levels under the current folder's parent and the usual code folders. Read-only directory listings only, capped in count and time, never inside node_modules or dot folders."
2
2
  import { existsSync, readdirSync, statSync } from 'node:fs';
3
3
  import { homedir } from 'node:os';
4
4
  import { basename, dirname, join, resolve } from 'node:path';
package/dist/start/ui.js CHANGED
@@ -1,4 +1,4 @@
1
- // @comment -- "The prompts bravos start asks through: one small interface, a terminal implementation drawn by this file on @clack/core, and a scripted one for tests and --yes. Every prompt has an id so a test can answer it by name. The terminal one uses no dim or faint colour: markers are plain text ([x], ( ), ❯) in the terminal's own foreground, so they read on light and dark themes alike; Esc steps back, Ctrl-C quits."
1
+ // @comment -- "The prompts bravos setup asks through: one small interface, a terminal implementation drawn by this file on @clack/core, and a scripted one for tests and --yes. Every prompt has an id so a test can answer it by name. The terminal one uses no dim or faint colour: markers are plain text ([x], ( ), ❯) in the terminal's own foreground, so they read on light and dark themes alike; Esc steps back, Ctrl-C quits."
2
2
  import * as clack from '@clack/prompts';
3
3
  import { MultiSelectPrompt, PasswordPrompt, SelectPrompt, TextPrompt, isCancel } from '@clack/core';
4
4
  /** The person pressed Ctrl-C (or chose Cancel): nothing has been written. */
@@ -155,7 +155,7 @@ export function terminalPrompter() {
155
155
  };
156
156
  }
157
157
  /**
158
- * Answers from a table, for tests and for `bravos start --yes`. An id with no answer
158
+ * Answers from a table, for tests and for `bravos setup --yes`. An id with no answer
159
159
  * takes the prompt's default (initial) when it has one, and is otherwise an error, so
160
160
  * a scripted run never silently invents an answer a person should give. '__back__'
161
161
  * answers as Esc would (once), '__cancel__' as Ctrl-C.
package/dist/upkeep.js ADDED
@@ -0,0 +1,89 @@
1
+ // @comment -- "bravos upkeep: what in this repository or on this machine has fallen behind the installed bravos, read-only and without the network, fast enough for the session hook to ask at every start. Two things: the repository's own copies of the skills and hook scripts (compared file by file with what this bravos would write, so a lock that still names an old version cannot hide or invent a difference), and a staged bundle older than the version this bravos pins. It also says which side is newer, because re-applying from an older bravos would roll a repository back."
2
+ import { existsSync, readdirSync, readFileSync } from 'node:fs';
3
+ import { join, relative } from 'node:path';
4
+ import { olderThan, VERSIONS } from './artifacts.js';
5
+ import { installSkills } from './install.js';
6
+ import { licenceLib } from './licence.js';
7
+ import { LOCK_PATH, readLock } from './lock.js';
8
+ import { hooksDir as packageHooksDir, version } from './paths.js';
9
+ import { behindPin } from './setup.js';
10
+ import { skillsRoot } from './skills.js';
11
+ export const UPKEEP_SCHEMA = 'bravos.upkeep/v1';
12
+ const listFiles = (dir) => {
13
+ const out = [];
14
+ for (const e of readdirSync(dir, { withFileTypes: true })) {
15
+ const abs = join(dir, e.name);
16
+ if (e.isDirectory())
17
+ out.push(...listFiles(abs));
18
+ else if (e.isFile())
19
+ out.push(abs);
20
+ }
21
+ return out;
22
+ };
23
+ // @comment -- "The hook scripts the repository carries, against the ones this bravos ships: missing or different files, by path. Only where the repository has its own copies at all."
24
+ function staleHooks(root) {
25
+ if (!existsSync(join(root, '.bravos', 'hooks', 'session-start.mjs')))
26
+ return [];
27
+ const src = packageHooksDir();
28
+ const stale = [];
29
+ for (const abs of listFiles(src)) {
30
+ const rel = relative(src, abs).split('\\').join('/');
31
+ const dest = join(root, '.bravos', 'hooks', rel);
32
+ try {
33
+ if (!readFileSync(dest).equals(readFileSync(abs)))
34
+ stale.push(`.bravos/hooks/${rel}`);
35
+ }
36
+ catch {
37
+ stale.push(`.bravos/hooks/${rel}`);
38
+ }
39
+ }
40
+ return stale;
41
+ }
42
+ export async function gatherUpkeep(root, env) {
43
+ const cli = version();
44
+ const out = { schema: UPKEEP_SCHEMA, cli, repo: null, sync: { files: 0, sample: [], direction: 'same' }, bundles: [], unified: true };
45
+ if (existsSync(join(root, LOCK_PATH))) {
46
+ try {
47
+ const lock = readLock(root);
48
+ // The lock's own version stays behind when a sync skipped an edited file; synced_with is the bravos that last ran one.
49
+ const seen = [lock.bravos_version, lock.synced_with].filter((v) => typeof v === 'string' && !!v);
50
+ const repo = seen.reduce((a, b) => (olderThan(a, b) ? b : a), seen[0] ?? cli);
51
+ out.repo = repo;
52
+ out.sync.direction = olderThan(cli, repo) ? 'repo-newer' : olderThan(repo, cli) ? 'cli-newer' : 'same';
53
+ const harnesses = ['claude', 'agents'].filter((h) => existsSync(join(root, skillsRoot(h), 'bravos', 'SKILL.md')));
54
+ const dry = harnesses.length ? installSkills(root, harnesses, { dryRun: true }) : { written: [], updated: [] };
55
+ const stale = [...dry.updated, ...dry.written, ...staleHooks(root)];
56
+ out.sync.files = stale.length;
57
+ out.sync.sample = stale.slice(0, 5);
58
+ }
59
+ catch {
60
+ /* a lock that does not read: bravos setup says why; nothing to report here */
61
+ }
62
+ }
63
+ const L = await licenceLib();
64
+ const lic = L.status(env);
65
+ for (const [id, feature] of [['analyzer', 'sast'], ['codegraph', 'codegraph']]) {
66
+ if (!L.entitled(lic, feature))
67
+ continue;
68
+ const staged = behindPin(env, id);
69
+ if (staged)
70
+ out.bundles.push({ id, staged, pinned: VERSIONS[id] });
71
+ }
72
+ return out;
73
+ }
74
+ export function formatUpkeep(u) {
75
+ const lines = [];
76
+ if (u.repo === null)
77
+ lines.push('repository: bravos is not installed here (bravos setup in a terminal, or bravos setup --yes)');
78
+ else if (u.sync.files === 0)
79
+ lines.push(`repository: up to date with bravos ${u.cli}`);
80
+ else if (u.sync.direction === 'repo-newer')
81
+ lines.push(`repository: its Bravos files are from ${u.repo}, newer than this bravos (${u.cli}) — update bravos: npm install -g @bugb-technologies/bravos@latest (this older one leaves the repository alone)`);
82
+ else
83
+ lines.push(`repository: ${u.sync.files} file${u.sync.files === 1 ? '' : 's'} behind bravos ${u.cli} — bravos setup (${u.sync.sample.join(', ')}${u.sync.files > u.sync.sample.length ? ', …' : ''})`);
84
+ for (const b of u.bundles)
85
+ lines.push(`${b.id}: staged ${b.staged}, this bravos pins ${b.pinned} — bravos setup`);
86
+ if (!u.bundles.length)
87
+ lines.push('bundles: none behind');
88
+ return lines;
89
+ }
@@ -359,7 +359,7 @@ function teamPanel(sn, inner) {
359
359
  if (sn.review.drafted)
360
360
  body.push([s(`intent review: ${sn.review.answers.length} answered${sn.review.answers.length ? ` (${sn.review.answers.map((a) => a.by).join(', ')})` : ''}`, C.steel)]);
361
361
  if (sn.bravos?.repo && sn.bravos.repo !== sn.bravos.cli)
362
- body.push([s(`skills here ${sn.bravos.repo}, bravos ${sn.bravos.cli} → bravos sync`, C.amber)]);
362
+ body.push([s(`skills here ${sn.bravos.repo}, bravos ${sn.bravos.cli} → bravos setup`, C.amber)]);
363
363
  return { title: 'BRANCH · TEAM', body };
364
364
  }
365
365
  // @comment -- "The REPORT panel: the newest bravos-report write-up's title, kind and age, its findings by evidence level and severity, the check verdict, exported formats and how far HEAD has moved since its evidence; or how to write one."
package/dist/watch.js CHANGED
@@ -878,7 +878,7 @@ export async function runWatch(root, env, opts) {
878
878
  }
879
879
  if (a.kind === 'theme') {
880
880
  theme = nextTheme(theme);
881
- note = `colours: ${theme} — keep it with BRAVOS_THEME=${theme} or bravos start`;
881
+ note = `colours: ${theme} — keep it with BRAVOS_THEME=${theme} or bravos setup`;
882
882
  }
883
883
  if (a.kind === 'refresh') {
884
884
  note = 'refreshing everything, the code graph too…';