@bugb-technologies/bravos 1.8.0 → 1.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,16 +1,16 @@
1
- // @comment -- "What bravos start asks and records: the answers, the three starting presets, the bravos init command they amount to, and the two files only start writes itself — the person's proving choice (.guardlink/proving.md, their words and name) and the saved answers (.bravos/setup.json, for --again)."
1
+ // @comment -- "What bravos setup asks and records: the answers, the three starting presets, the bravos setup command they amount to, and the two files only start writes itself — the person's proving choice (.guardlink/proving.md, their words and name) and the saved answers (.bravos/setup.json, for --again)."
2
2
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
3
3
  import { dirname, join } from 'node:path';
4
4
  export const PRESETS = {
5
5
  annotate: { label: 'Map my threats only', hint: 'annotations; nothing runs on its own', pr: 'none', autopilot: false, schedule: 'none', proving: 'none' },
6
- // @comment -- "Autopilot is on for the pr preset in the preset itself, so bravos start --yes and the interactive default agree."
6
+ // @comment -- "Autopilot is on for the pr preset in the preset itself, so bravos setup --yes and the interactive default agree."
7
7
  pr: { label: 'Map threats and check every pull request', hint: 'no AI key needed', pr: 'hook+github', autopilot: true, schedule: 'none', proving: 'ask' },
8
8
  // @comment -- "The label says what the schedule does by default: an annotation run. Scheduled testing happens only when the person picks it at the testing question."
9
9
  everything: { label: 'Everything: annotations, PR checks and a scheduled annotation run', hint: 'weekly run, autopilot on; testing is the next choice', pr: 'hook+github', autopilot: true, schedule: 'weekly', proving: 'ask' },
10
10
  };
11
11
  /** Pricing for optional CXG model generation. */
12
12
  export const PENTEST_COST_URL = 'https://bugb.io/pricing#pentest-cost';
13
- /** The bravos init arguments these answers amount to (the review step prints them). */
13
+ /** The bravos setup arguments these answers amount to (the review step prints them). */
14
14
  // @comment -- "The init flags for the chosen answers: agents, the pre-PR hook, autopilot, which workflows and the nightly cadence, and the loopback scope starter when testing is on"
15
15
  export function initArgs(a) {
16
16
  const args = ['init', a.repo, '--agent', a.agents.join(',')];
@@ -41,7 +41,7 @@ export function provingText(a, date) {
41
41
  return [
42
42
  '# How findings are proven',
43
43
  '',
44
- 'Recorded by `bravos start` from the answers below. Edit it, or run `bravos start --again`, to change it.',
44
+ 'Recorded by `bravos start` from the answers below. Edit it, or run `bravos setup --change`, to change it.',
45
45
  '',
46
46
  `choice: ${a.proving}`,
47
47
  ...(a.proving === 'auto' ? [`kits: ${a.kitPolicy ?? 'reviewed'}`] : []),
@@ -1,4 +1,4 @@
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."
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
2
  import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
3
3
  import { join, resolve } from 'node:path';
4
4
  import { resolveTheme, THEMES } from '../palette.js';
@@ -7,6 +7,7 @@ import { CRON } from '../ci.js';
7
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';
10
11
  import { prefsLib } from '../prefs.js';
11
12
  const AGENTS = [
12
13
  { value: 'claude', label: 'Claude Code' },
@@ -70,9 +71,23 @@ async function flow(opts, d) {
70
71
  if (shadow && /\.local\/bin\/bravos$|site-packages|pipx/.test(shadow)) {
71
72
  p.warn(`The old Python bravos at ${shadow} may run instead of this one. Rename it: mv ${shadow} ${shadow}-py`);
72
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;
73
87
  const has = (s, f) => !!s.lic?.unlocked.includes(f);
74
88
  const missingTools = (s) => (s.items ?? []).filter((i) => (i.id === 'guardlink' || i.id === 'cxg') && (!i.present || (i.proofTool && i.proofTool.status !== 'ready')));
75
- 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);
76
91
  // @comment -- "A repository-level question is skipped when joining: those answers are the team's, already committed."
77
92
  const team = (step) => async (s) => {
78
93
  if (!s.join)
@@ -81,8 +96,15 @@ async function flow(opts, d) {
81
96
  const steps = [
82
97
  // theme
83
98
  async (s) => {
84
- p.note(themeSample(), 'Colours');
85
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');
86
108
  const initial = s.theme ?? saved?.theme ?? detected.theme;
87
109
  s.theme = await p.select('theme', 'How does your terminal look?', [
88
110
  { value: 'dark', label: 'Dark background', recommended: detected.source !== 'default' && detected.theme === 'dark' },
@@ -93,6 +115,8 @@ async function flow(opts, d) {
93
115
  // licence
94
116
  async (s) => {
95
117
  s.lic = await d.licence();
118
+ if (!s.lic.licensed && !opts.yes)
119
+ heading('machine');
96
120
  if (!s.lic.licensed && !opts.yes) {
97
121
  const how = await p.select('licence', 'No Bravos licence on this machine yet.', [
98
122
  { value: 'activate', label: 'Sign in now', hint: 'activate your licence, or start the free 30-day Team trial', recommended: true },
@@ -119,20 +143,35 @@ async function flow(opts, d) {
119
143
  p.note(s.items.map((i) => {
120
144
  if (i.present && i.proofTool && i.proofTool.status !== 'ready')
121
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}`;
122
148
  return `${i.present ? '✔' : '✗'} ${i.id.padEnd(10)} ${i.present ? 'installed' : i.licensed === false ? 'Team plan' : `missing — ${i.action}`}`;
123
149
  }).join('\n'), 'Tools');
124
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;
125
153
  s.installTools = false;
126
- 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)
127
157
  return;
158
+ heading('machine');
128
159
  if (missingTools(s).some((i) => i.id === 'cxg') && !d.which('cargo')) {
129
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.');
130
161
  }
131
- 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);
132
163
  },
133
164
  // repository
134
165
  async (s) => {
166
+ heading('repository');
135
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
+ }
136
175
  if (repo && repoProblem(repo)) {
137
176
  p.warn(`${tildify(repo)}: ${repoProblem(repo)}`);
138
177
  repo = '';
@@ -160,11 +199,12 @@ async function flow(opts, d) {
160
199
  }
161
200
  }
162
201
  s.repo = repo;
163
- // @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 start --again is the way to change the repository's setup."
164
- s.join = !opts.again && existsSync(join(repo, '.bravos', 'skills.lock')) && existsSync(join(repo, '.bravos', 'setup.json'));
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'));
165
205
  if (s.join) {
166
206
  s.agents = readAnswers(repo)?.agents ?? s.agents;
167
- 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: bravos start --again');
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}`);
168
208
  }
169
209
  },
170
210
  // agents
@@ -249,7 +289,7 @@ async function flow(opts, d) {
249
289
  const autoReady = defaultRef.code === 0 && !!defaultRef.out.trim()
250
290
  && d.exec('git', ['rev-parse', '--verify', `${defaultRef.out.trim()}^{commit}`], { cwd: s.repo }).code === 0;
251
291
  if (!autoReady)
252
- 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.`);
253
293
  const choices = [
254
294
  { value: 'ask', label: 'Ask me every time before testing', recommended: true },
255
295
  ...(autoReady ? [
@@ -368,10 +408,10 @@ async function flow(opts, d) {
368
408
  const answers = toAnswers(s);
369
409
  const changes = [
370
410
  `Colours: ${answers.theme} (saved in ${tildify(join(d.home, 'config.json'), d.env.HOME)})`,
371
- ...(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(', ')}`] : []),
372
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)`] : []),
373
413
  `In ${tildify(answers.repo, d.env.HOME)}:`,
374
- ...(s.join ? [' ~ skills, hooks and MCP brought up to date for this machine (bravos sync)', ' = the team\'s setup, testing permission and workflows stay as they are'] : []),
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'] : []),
375
415
  ...(s.join ? [] : [
376
416
  ` + skills, hooks and MCP for ${answers.agents.join(', ')}`,
377
417
  ' + .guardlink/ threat model (guardlink init, if not there yet)',
@@ -383,7 +423,7 @@ async function flow(opts, d) {
383
423
  ...(answers.proving !== 'none' ? [' + .guardlink/scope.yaml (localhost only; authorization left for you)'] : []),
384
424
  ...(answers.name ? [` + .guardlink/proving.md (${answers.proving}${answers.target ? ` on ${answers.target}` : ''}, confirmed by ${answers.name})`] : []),
385
425
  ...(Object.keys(s.secrets).length ? [` + GitHub secrets: ${Object.keys(s.secrets).join(', ')}`] : []),
386
- ' + .bravos/setup.json (your answers, for bravos start --again)',
426
+ ` + .bravos/setup.json (your answers, for ${change})`,
387
427
  ]),
388
428
  ...(has(s, 'codegraph') ? ['Then: build the code graph for this repository'] : []),
389
429
  ];
@@ -411,13 +451,14 @@ async function flow(opts, d) {
411
451
  break;
412
452
  p.note([
413
453
  ...(answers.installTools && missingTools(s).length ? ['bravos setup --tools -y'] : []),
414
- ...(answers.installTools && missingBundles(s).length ? ['bravos setup'] : []),
415
- s.join ? `bravos sync ${JSON.stringify(answers.repo)}` : `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(' ')}`,
416
457
  ...Object.keys(s.secrets).map((n) => `gh secret set ${n} (value from your paste)`),
417
458
  ...(has(s, 'codegraph') ? [`bravos graph build ${JSON.stringify(answers.repo)} --scip no-exec`] : []),
418
459
  ].join('\n'), 'Commands');
419
460
  }
420
- 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 });
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, cxgMissing: missingTools(s).some((i) => i.id === 'cxg') });
421
462
  }
422
463
  function toAnswers(s) {
423
464
  return {
@@ -442,8 +483,20 @@ async function apply(answers, s, d, opts, has) {
442
483
  const p = d.prompter;
443
484
  const { repo, agents } = answers;
444
485
  writeTheme(d.home, answers.theme);
445
- if (answers.installTools && has.missingTools) {
446
- 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'));
486
+ // @comment -- "Apply says up front how many steps it will take and which may be slow, and numbers each one, so a person can tell it is working and roughly how far along it is. cxg is compiled from source by cargo, which is the one step that can take many minutes."
487
+ const steps = [
488
+ answers.installTools && has.missingTools && !opts.yes,
489
+ (answers.installTools || opts.yes) && has.missingBundles,
490
+ true,
491
+ has.codegraph,
492
+ ].filter(Boolean).length;
493
+ let at = 0;
494
+ const step = (label) => `[${++at}/${steps}] ${label}`;
495
+ const slowCxg = answers.installTools && has.missingTools && !opts.yes && has.cxgMissing;
496
+ const tools = slowCxg ? 'Installing guardlink and cxg (cxg is compiled from source: often 5 to 10 minutes)' : 'Installing guardlink and cxg';
497
+ p.info(`Applying: ${steps} step${steps === 1 ? '' : 's'}${slowCxg ? '. The first takes longest, because cargo compiles cxg; the clock and the line beside it show where it is' : ''}. Leave this window open until "Bravos is set up".`);
498
+ if (answers.installTools && has.missingTools && !opts.yes) {
499
+ const r = await p.spin(step(tools), (progress) => d.bravos(['setup', '--tools', '-y'], progress), (r) => (r.code ? { fail: `${tools} — failed` } : 'Installed guardlink and cxg'));
447
500
  for (const l of [...r.out, ...r.err])
448
501
  (r.code ? p.warn : p.info)(l);
449
502
  // A tool that would not install (no cargo, offline, an incompatible build) limits proving, not the
@@ -451,21 +504,22 @@ async function apply(answers, s, d, opts, has) {
451
504
  if (r.code)
452
505
  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.');
453
506
  }
454
- if (answers.installTools && has.missingBundles) {
455
- 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'));
507
+ // 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.
508
+ if ((answers.installTools || opts.yes) && has.missingBundles) {
509
+ const r = await p.spin(step('Fetching the Bravos analyzer and code graph'), (progress) => d.bravos(['setup', '--analyzer', '--codegraph'], progress), (r) => (r.code ? { fail: 'Fetching the analyzer and code graph — failed' } : 'Fetched the analyzer and code graph'));
456
510
  for (const l of [...r.out, ...r.err])
457
511
  (r.code ? p.warn : p.info)(l);
458
512
  }
459
- // @comment -- "Joining runs bravos sync, which re-applies what the repository already has and never rewrites the team's choices; a first setup runs bravos init with the flags the answers amount to."
513
+ // @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."
460
514
  const init = has.join
461
- ? 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'))
462
- : await p.spin('Setting up the repository', () => d.bravos(initArgs(answers)), (r) => (r.code ? { fail: 'Setting up the repository — failed' } : 'Repository set up'));
515
+ ? await p.spin(step('Bringing this machine up to date with the repository'), (progress) => d.bravos(['sync', repo], progress), (r) => (r.code ? { fail: 'Syncing the repository — failed' } : 'Repository in sync'))
516
+ : await p.spin(step('Setting up the repository'), (progress) => d.bravos(initArgs(answers), progress), (r) => (r.code ? { fail: 'Setting up the repository — failed' } : 'Repository set up'));
463
517
  for (const l of init.out)
464
518
  p.info(l);
465
519
  if (init.code !== 0) {
466
520
  for (const l of init.err)
467
521
  p.warn(l);
468
- p.outro(has.join ? 'Setup stopped: bravos sync did not finish. Fix the line above and run bravos start again.' : 'Setup stopped: bravos init did not finish. Fix the line above and run bravos start --again.');
522
+ 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.`);
469
523
  return init.code;
470
524
  }
471
525
  // Joining never writes the team's proving.md or setup.json: both are theirs, already committed.
@@ -492,7 +546,7 @@ async function apply(answers, s, d, opts, has) {
492
546
  (r.code ? p.warn : p.info)(r.code ? `gh secret set ${n} failed — add it in the repository's Settings → Secrets` : `secret ${n} set`);
493
547
  }
494
548
  if (has.codegraph) {
495
- const g = await p.spin('Building the code graph (a minute or two; longer on a big repository)', () => d.bravosChild(['graph', 'build', repo, '--scip', 'no-exec', '--json']), (r) => (graphSummary(r).ok ? graphSummary(r).line : { fail: graphSummary(r).line }));
549
+ const g = await p.spin(step('Building the code graph (a minute or two; longer on a big repository)'), () => d.bravosChild(['graph', 'build', repo, '--scip', 'no-exec', '--json']), (r) => (graphSummary(r).ok ? graphSummary(r).line : { fail: graphSummary(r).line }));
496
550
  const sum = graphSummary(g);
497
551
  for (const n of sum.notes)
498
552
  (sum.ok ? p.info : p.warn)(n);
@@ -514,16 +568,14 @@ async function apply(answers, s, d, opts, has) {
514
568
  const handoff = `${sigil(lead)}bravos-context`;
515
569
  // A scripted run (--yes) leaves the person's clipboard alone.
516
570
  const copied = opts.yes ? false : d.clipboard(handoff);
517
- // @comment -- "The hand-off: a dated marker in this clone's git directory tells the next agent session that setup just finished, so the briefing has the agent begin the context step itself and the person types no skill name. Harnesses that run the session hook (Claude Code, Codex, Antigravity) get that; the others are still told what to type. A marker that cannot be written only means the person types the command."
571
+ // @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."
518
572
  let begins = false;
519
- if (['claude', 'codex', 'agy'].includes(lead)) {
520
- try {
521
- const L = await prefsLib();
522
- begins = !!L.writeHandoff(L.gitCommonDir(repo, d.env), new Date().toISOString());
523
- }
524
- catch {
525
- begins = false;
526
- }
573
+ try {
574
+ const L = await prefsLib();
575
+ begins = L.readHandoff(L.gitCommonDir(repo, d.env));
576
+ }
577
+ catch {
578
+ begins = false;
527
579
  }
528
580
  const banner = 'The Bravos banner shows the next step each time you open a session.';
529
581
  p.note((begins
@@ -548,7 +600,7 @@ async function apply(answers, s, d, opts, has) {
548
600
  'Follow along in a second terminal: bravos watch',
549
601
  ]).join('\n'), 'One step left, in your agent');
550
602
  if (opts.yes && !answers.name)
551
- p.info('Testing permission was not recorded (a person has to answer it): run bravos start --again in a terminal.');
603
+ 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.`);
552
604
  p.outro('Bravos is set up.');
553
605
  return 0;
554
606
  }
@@ -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. */
@@ -132,19 +132,26 @@ export function terminalPrompter() {
132
132
  });
133
133
  return String((await ask(k, p)) ?? '');
134
134
  },
135
+ // @comment -- "A step that takes minutes must look alive: the spinner shows a running clock, and the latest line the work reports (the install step it is on) beside the label, cut to the terminal's width. This only moves if the work leaves the event loop free, which is why Apply runs its long steps as child processes (src/cli.ts)."
135
136
  spin: async (label, work, done) => {
136
- const s = clack.spinner();
137
- const t0 = Date.now();
137
+ const s = clack.spinner({ indicator: 'timer' });
138
138
  s.start(label);
139
+ const width = Math.max(40, (process.stdout.columns || 80) - 14);
140
+ const progress = (line) => {
141
+ const text = line.replace(/\x1b\[[0-9;]*m/g, '').replace(/\s+/g, ' ').trim();
142
+ if (!text)
143
+ return;
144
+ const full = `${label} — ${text}`;
145
+ s.message(full.length > width ? `${full.slice(0, width - 1)}…` : full);
146
+ };
139
147
  try {
140
- const r = await work();
141
- const secs = Math.round((Date.now() - t0) / 1000);
148
+ const r = await work(progress);
149
+ // The spinner's own clock already prints the time taken beside the final line.
142
150
  const res = done ? done(r) : label;
143
- const took = secs >= 2 ? ` (${secs}s)` : '';
144
151
  if (typeof res === 'string')
145
- s.stop(`${res}${took}`);
152
+ s.stop(res);
146
153
  else
147
- s.error(`${res.fail}${took}`);
154
+ s.error(res.fail);
148
155
  return r;
149
156
  }
150
157
  catch (e) {
@@ -155,7 +162,7 @@ export function terminalPrompter() {
155
162
  };
156
163
  }
157
164
  /**
158
- * Answers from a table, for tests and for `bravos start --yes`. An id with no answer
165
+ * Answers from a table, for tests and for `bravos setup --yes`. An id with no answer
159
166
  * takes the prompt's default (initial) when it has one, and is otherwise an error, so
160
167
  * a scripted run never silently invents an answer a person should give. '__back__'
161
168
  * answers as Esc would (once), '__cancel__' as Ctrl-C.
@@ -210,7 +217,7 @@ export function scriptedPrompter(answers, out = () => { }) {
210
217
  confirm: async (id, _m, initial) => pick(id, initial),
211
218
  secret: async (id) => String(pick(id, undefined)),
212
219
  spin: async (label, work, done) => {
213
- const r = await work();
220
+ const r = await work(() => { });
214
221
  const res = done ? done(r) : label;
215
222
  out(typeof res === 'string' ? res : `! ${res.fail}`);
216
223
  return r;
package/dist/upkeep.js CHANGED
@@ -1,4 +1,4 @@
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 bravos sync from an older bravos would roll a repository back."
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
2
  import { existsSync, readdirSync, readFileSync } from 'node:fs';
3
3
  import { join, relative } from 'node:path';
4
4
  import { olderThan, VERSIONS } from './artifacts.js';
@@ -41,7 +41,7 @@ function staleHooks(root) {
41
41
  }
42
42
  export async function gatherUpkeep(root, env) {
43
43
  const cli = version();
44
- const out = { schema: UPKEEP_SCHEMA, cli, repo: null, sync: { files: 0, sample: [], direction: 'same' }, bundles: [] };
44
+ const out = { schema: UPKEEP_SCHEMA, cli, repo: null, sync: { files: 0, sample: [], direction: 'same' }, bundles: [], unified: true };
45
45
  if (existsSync(join(root, LOCK_PATH))) {
46
46
  try {
47
47
  const lock = readLock(root);
@@ -57,7 +57,7 @@ export async function gatherUpkeep(root, env) {
57
57
  out.sync.sample = stale.slice(0, 5);
58
58
  }
59
59
  catch {
60
- /* a lock that does not read: bravos sync says why; nothing to report here */
60
+ /* a lock that does not read: bravos setup says why; nothing to report here */
61
61
  }
62
62
  }
63
63
  const L = await licenceLib();
@@ -74,13 +74,13 @@ export async function gatherUpkeep(root, env) {
74
74
  export function formatUpkeep(u) {
75
75
  const lines = [];
76
76
  if (u.repo === null)
77
- lines.push('repository: bravos is not installed here (bravos start, or bravos init)');
77
+ lines.push('repository: bravos is not installed here (bravos setup in a terminal, or bravos setup --yes)');
78
78
  else if (u.sync.files === 0)
79
79
  lines.push(`repository: up to date with bravos ${u.cli}`);
80
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 (do not run bravos sync from this older one)`);
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
82
  else
83
- lines.push(`repository: ${u.sync.files} file${u.sync.files === 1 ? '' : 's'} behind bravos ${u.cli} — bravos sync (${u.sync.sample.join(', ')}${u.sync.files > u.sync.sample.length ? ', …' : ''})`);
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
84
  for (const b of u.bundles)
85
85
  lines.push(`${b.id}: staged ${b.staged}, this bravos pins ${b.pinned} — bravos setup`);
86
86
  if (!u.bundles.length)
@@ -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…';
package/docs/GUIDE.md CHANGED
@@ -30,9 +30,9 @@ Every skill reads one dial: low, medium (default), high or max. Say it ("annotat
30
30
 
31
31
  ### Installing
32
32
 
33
- npm install -g @bugb-technologies/bravos (Node 20 or newer), then bravos start: a guided setup that asks one question at a time (colours, licence, tools, repository, AI tools, PR checks, a scheduled run, how testing is allowed), shows every change, and writes nothing until you choose Apply. Then open your agent and say anything: Bravos begins with what the app is for and goes on to your code once you confirm (where the agent runs no hooks, it tells you the one thing to type).
33
+ npm install -g @bugb-technologies/bravos (Node 20 or newer), then bravos setup: a guided setup that asks one question at a time (colours, licence, tools, repository, AI tools, PR checks, a scheduled run, how testing is allowed), shows every change, and writes nothing until you choose Apply. Then open your agent and say anything: Bravos begins with what the app is for and goes on to your code once you confirm (where the agent runs no hooks, it tells you the one thing to type).
34
34
 
35
- By hand instead: bravos account activate signs you in once in the browser and writes the licence — a 30-day Team trial when the account has no plan; skip it to stay on Free — bravos init in a repository writes the skills, hooks and MCP wiring, and bravos setup puts the analyzer and the code graph on the machine (Team plan). guardlink and cxg come from bravos setup --tools -y, or npm and cargo by hand. If you used the Python bravos, rename its command so bravos means this one: mv ~/.local/bin/bravos ~/.local/bin/bravos-py (this CLI still finds its code graph and analyzer), or remove it with pipx or uv.
35
+ By hand instead: bravos account activate signs you in once in the browser and writes the licence — a 30-day Team trial when the account has no plan; skip it to stay on Free — bravos setup --agent claude in a repository writes the skills, hooks and MCP wiring, bravos setup --analyzer --codegraph puts the analyzer and the code graph on the machine (Team plan), and guardlink and cxg come from bravos setup --tools -y, or npm and cargo by hand. If you used the Python bravos, rename its command so bravos means this one: mv ~/.local/bin/bravos ~/.local/bin/bravos-py (this CLI still finds its code graph and analyzer), or remove it with pipx or uv.
36
36
 
37
37
  ### Your first day
38
38
 
@@ -44,7 +44,7 @@ Keep bravos watch running in a second terminal pane beside your agent (free, rea
44
44
 
45
45
  ### Hands-off: autopilot
46
46
 
47
- bravos init --autopilot (or sync --autopilot) makes upkeep happen without anyone asking. At turn end the agent reviews changed code, including edits inside annotated files. It follows the recorded proving preference for affected claims. The pre-PR gate runs on every gh pr create.
47
+ bravos setup --autopilot makes upkeep happen without anyone asking. At turn end the agent reviews changed code, including edits inside annotated files. It follows the recorded proving preference for affected claims. The pre-PR gate runs on every gh pr create.
48
48
 
49
49
  Proving follows your choice, not a fixed rule: the first time it comes up the agent asks you once — prove automatically on your loopback target, ask each time, on a schedule, or not now — and records your words in .guardlink/proving.md. Say "ask me first" or "stop auto-proving" at any time to change it. Non-loopback targets still need a reviewed scope and your typed authorization every time.
50
50
 
@@ -70,7 +70,7 @@ Start by recording what the product intends (bravos-context), so severities refl
70
70
 
71
71
  Skills: `/bravos-campaign` · `/bravos-schedule` · `/bravos-cicd`
72
72
 
73
- Turn on bravos init --autopilot so the threat model keeps up as people work, with no commands to remember, and settle once with the team how findings should be proven (it is recorded in .guardlink/proving.md and shows in every briefing).
73
+ Turn on bravos setup --autopilot so the threat model keeps up as people work, with no commands to remember, and settle once with the team how findings should be proven (it is recorded in .guardlink/proving.md and shows in every briefing).
74
74
 
75
75
  Coverage and findings are visible to everyone from the repo itself. To raise coverage or clear the backlog, run bravos-campaign with a goal ("coverage 100%", "test every open exposure"): it plans disjoint batches, runs one subagent per batch, gates each, rests, and reports before-and-after numbers. Use bravos-schedule for recurring upkeep (an in-session loop or the nightly workflow) and bravos-cicd for the PR gate and code-scanning upload. Acceptances (@accepts) and entitlements are yours to write; agents never write them.
76
76
 
@@ -84,7 +84,7 @@ Run bravos first: it reads the briefing, explains the loop in five lines and rou
84
84
 
85
85
  Skills: `/bravos-cicd` · `/bravos-schedule`
86
86
 
87
- bravos init --ci writes the PR gate and nightly workflows. bravos-cicd audits existing workflows: broken guardlink calls, script injection from pull-request text, missing SARIF upload. The Claude and Codex nightlies can replay committed, bound kits when scheduled testing is authorized. The Copilot job assigns an annotation task.
87
+ bravos setup --ci writes the PR gate and nightly workflows. bravos-cicd audits existing workflows: broken guardlink calls, script injection from pull-request text, missing SARIF upload. The Claude and Codex nightlies can replay committed, bound kits when scheduled testing is authorized. The Copilot job assigns an annotation task.
88
88
 
89
89
  ## What to do, by task
90
90
 
@@ -206,13 +206,13 @@ Clone the services side by side in one folder, then run bravos workspace create
206
206
 
207
207
  Skills: `/bravos`
208
208
 
209
- Nothing to run by hand in a repository you work in with an agent: at the start of a session bravos upkeep (read-only, no network) tells the agent what is behind the installed version, and the agent runs bravos sync for the repository's skills and hooks, or bravos setup for Bravos's own bundles, without asking. If a teammate synced the repository with a newer bravos than yours, the agent syncs nothing and tells you to update. Installing guardlink and cxg (bravos setup --tools) still waits for your go-ahead.
209
+ Nothing to run by hand in a repository you work in with an agent: at the start of a session bravos upkeep (read-only, no network) tells the agent what is behind the installed version, and the agent runs bravos setup, which brings the repository's skills and hooks and Bravos's own bundles up to date, without asking. If a teammate synced the repository with a newer bravos than yours, the agent syncs nothing and tells you to update. Installing guardlink and cxg (bravos setup --tools) still waits for your go-ahead.
210
210
 
211
211
  ### Stop being asked about commits
212
212
 
213
213
  Skills: `/bravos`
214
214
 
215
- Say once whether your agent commits the files Bravos writes (annotations, intent, definitions, tests): bravos prefs set commits commit|leave|ask --by "<your name>". bravos start asks it too. The answer is kept in this clone's git directory, never committed, and your own code is never part of such a commit. bravos prefs get shows it.
215
+ Say once whether your agent commits the files Bravos writes (annotations, intent, definitions, tests): bravos prefs set commits commit|leave|ask --by "<your name>". bravos setup asks it too. The answer is kept in this clone's git directory, never committed, and your own code is never part of such a commit. bravos prefs get shows it.
216
216
 
217
217
  ### See the findings on one page
218
218
 
@@ -246,7 +246,7 @@ Bounded questions to codegraph-mcp: routes, attack surface, sinks a symbol reach
246
246
 
247
247
  ### bravos-ship
248
248
 
249
- The pre-PR gate. Optional PreToolUse hook (bravos init --pre-pr-hook) runs it on every gh pr create / gh pr ready.
249
+ The pre-PR gate. Optional PreToolUse hook (bravos setup --pre-pr-hook) runs it on every gh pr create / gh pr ready.
250
250
 
251
251
  ### bravos-templatize
252
252
 
@@ -364,10 +364,10 @@ Reads hooks from .claude/settings.json (preview), so the briefing can load there
364
364
 
365
365
  ### Every repo, or one copy of each skill
366
366
 
367
- bravos init --global installs for your user: skills in ~/.claude/skills (linked from ~/.agents/skills) and a user hook that briefs repos with a threat model but no bravos install. bravos sync --link-skills makes a repo's .agents/skills a link to .claude/skills, so tools that read both (Warp) list each skill once.
367
+ bravos setup --global installs for your user: skills in ~/.claude/skills (linked from ~/.agents/skills) and a user hook that briefs repos with a threat model but no bravos install. bravos setup --link-skills makes a repo's .agents/skills a link to .claude/skills, so tools that read both (Warp) list each skill once.
368
368
 
369
369
  ### Banner switches
370
370
 
371
371
  BRAVOS_BANNER=off hides it; BRAVOS_BANNER_COLOR=off or NO_COLOR prints it plain. The briefing for the model is unchanged either way.
372
372
 
373
- Light terminal? BRAVOS_THEME=light (or dark, or neutral) picks the colours for the banner and bravos watch; otherwise COLORFGBG, the choice saved by bravos start, then neutral. bravos doctor shows which, and the c key in bravos watch switches.
373
+ Light terminal? BRAVOS_THEME=light (or dark, or neutral) picks the colours for the banner and bravos watch; otherwise COLORFGBG, the choice saved by bravos setup, then neutral. bravos doctor shows which, and the c key in bravos watch switches.
package/docs/UPGRADING.md CHANGED
@@ -1,6 +1,34 @@
1
1
  # Upgrading Bravos
2
2
 
3
- After `npm install -g @bugb-technologies/bravos`, run **`bravos setup --tools -y`** once on each machine and **`bravos sync`** in each repository. The notes below say what else changes, newest first.
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
+
5
+ ## 1.9.1
6
+
7
+ - **Apply shows what it is doing.** After you choose Apply in `bravos setup`, the screen used to stay still while the tools installed, which can take several minutes because cargo compiles cxg. It now says how many steps there are, numbers each one, and shows a running clock and the step it is on.
8
+ - **Fixed:** two agent sessions starting at the same moment could build the same code graph twice.
9
+
10
+ ## 1.9.0
11
+
12
+ 1.9 makes **`bravos setup`** the one command for setting Bravos up. It looks at this machine and the repository you are in and does only what is missing.
13
+
14
+ - **In a terminal, `bravos setup` is the guided setup.**
15
+ - The first time on a machine it signs you in and installs the tools, then asks about the repository.
16
+ - In another repository it skips what the machine has ("This machine is ready") and asks only that repository's questions.
17
+ - In a repository that already has Bravos it brings the machine and the repository up to date. `bravos setup --change` asks the repository's questions again.
18
+ - **`bravos start`, `bravos init` and `bravos sync` still work**, with the same flags, but help and every hint name `bravos setup`: `bravos sync --ci` is `bravos setup --ci`, `bravos init --agent claude` is `bravos setup --agent claude`, `bravos start --again` is `bravos setup --change`.
19
+ - **Two things behave differently under the name `setup`:**
20
+ - A plain `bravos setup` in a terminal opens the guided setup. It used to fetch the bundles; that is `bravos setup --analyzer --codegraph`.
21
+ - `bravos setup -y` on its own is an unattended first setup of the repository you are in. Fetching a staged bundle again is `bravos setup --codegraph -y` (or `--analyzer -y`).
22
+ - **With no terminal, a plain `bravos setup` is safe upkeep.** This is what an agent or a script gets: the repository's Bravos files and Bravos's own bundles brought up to date, and nothing else. It never installs Bravos into a repository, never installs guardlink or cxg, never adds agents or MCP entries, and leaves your own `~/.claude` alone. A bundle that is missing is named, not fetched.
23
+ - **`bravos setup --yes` is the unattended first setup.** It sets up the folder it is given or run in, refuses a folder that is not a git repository, and never picks one for you. It fetches Bravos's bundles and leaves guardlink and cxg to `bravos setup --tools -y`.
24
+ - **Any first install makes the agent begin.** Installing by flags or from a script now leaves the same hand-off the guided setup does, so the next agent session starts the context step by itself.
25
+ - **Fixed:** "Install guardlink, cxg when you apply?" defaulted to No; it defaults to Yes. A bundle older than this version uses is now offered for install in the guided setup.
26
+ - `bravos next` prints "Setup N/9 for <repo>".
27
+
28
+ ## 1.8.1
29
+
30
+ - **Hooks work from any folder.** Until now the hook commands were relative to the current folder, so once your agent changed folder (`cd ios/Runner`) every hook failed with "Cannot find module": autopilot stopped, and the pre-PR check let `gh pr create` through. Claude Code's commands now start from the project root (`${CLAUDE_PROJECT_DIR}`), Codex's from the git top level. **Run `bravos sync` in each repository**: it rewrites the commands in `.claude/settings.json` and `.codex/hooks.json`, one line per hook.
31
+ - **Old skills from the Python bravos are named.** If you used the earlier Python CLI, its skills may still sit in `~/.claude/skills` and `~/.agents/skills`, and an agent can load one and follow commands this bravos does not have. The session briefing now tells the agent not to follow them, and `bravos doctor` lists them with one command that moves them aside (nothing is deleted).
4
32
 
5
33
  ## 1.8.0
6
34