@bugb-technologies/bravos 1.7.0 → 1.8.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.
@@ -1,12 +1,13 @@
1
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';
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 { prefsLib } from '../prefs.js';
10
11
  const AGENTS = [
11
12
  { value: 'claude', label: 'Claude Code' },
12
13
  { value: 'codex', label: 'Codex' },
@@ -72,6 +73,11 @@ async function flow(opts, d) {
72
73
  const has = (s, f) => !!s.lic?.unlocked.includes(f);
73
74
  const missingTools = (s) => (s.items ?? []).filter((i) => (i.id === 'guardlink' || i.id === 'cxg') && (!i.present || (i.proofTool && i.proofTool.status !== 'ready')));
74
75
  const missingBundles = (s) => (s.items ?? []).filter((i) => (i.id === 'analyzer' || i.id === 'codegraph') && !i.present && i.licensed);
76
+ // @comment -- "A repository-level question is skipped when joining: those answers are the team's, already committed."
77
+ const team = (step) => async (s) => {
78
+ if (!s.join)
79
+ await step(s);
80
+ };
75
81
  const steps = [
76
82
  // theme
77
83
  async (s) => {
@@ -134,6 +140,7 @@ async function flow(opts, d) {
134
140
  if (!repo) {
135
141
  const found = findRepos(d.cwd, { home: d.home });
136
142
  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…' }];
143
+ // An older setup.json may still hold the path it was written with; newer ones never do.
137
144
  const prev = s.repoPicked ?? (saved?.repo && isGitRepo(saved.repo) ? saved.repo : undefined);
138
145
  const initial = prev && choices.some((c) => c.value === prev) ? prev : found[0] ?? '__path__';
139
146
  for (;;) {
@@ -153,9 +160,15 @@ async function flow(opts, d) {
153
160
  }
154
161
  }
155
162
  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'));
165
+ if (s.join) {
166
+ 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');
168
+ }
156
169
  },
157
170
  // agents
158
- async (s) => {
171
+ team(async (s) => {
159
172
  const det = detectHarnesses(s.repo);
160
173
  const seen = new Set([
161
174
  ...(det.harnesses.includes('claude') && !det.defaulted ? ['claude'] : []),
@@ -166,17 +179,17 @@ async function flow(opts, d) {
166
179
  ]);
167
180
  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
181
  s.agents = agents.length ? agents : ['claude'];
169
- },
182
+ }),
170
183
  // goal
171
- async (s) => {
184
+ team(async (s) => {
172
185
  if (opts.preset) {
173
186
  s.preset = opts.preset;
174
187
  return;
175
188
  }
176
189
  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
- },
190
+ }),
178
191
  // pull requests
179
- async (s) => {
192
+ team(async (s) => {
180
193
  const prChoices = [
181
194
  { value: 'none', label: 'Nothing' },
182
195
  ...(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 +202,17 @@ async function flow(opts, d) {
189
202
  }
190
203
  const want = s.pr ?? saved?.pr ?? PRESETS[s.preset].pr;
191
204
  s.pr = await p.select('pr', 'When someone opens a pull request:', prChoices, prChoices.some((c) => c.value === want) ? want : 'none');
192
- },
205
+ }),
193
206
  // autopilot
194
- async (s) => {
207
+ team(async (s) => {
195
208
  if (!has(s, 'pre-pr') || s.preset === 'annotate') {
196
209
  s.autopilot = false;
197
210
  return;
198
211
  }
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
- },
212
+ 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);
213
+ }),
201
214
  // scheduled run (GitHub Actions)
202
- async (s) => {
215
+ team(async (s) => {
203
216
  s.nightlyAgent = s.agents.includes('codex') && !s.agents.includes('claude') ? 'codex' : 'claude';
204
217
  if (!has(s, 'ci')) {
205
218
  p.info('Scheduled runs are on the Team plan.');
@@ -213,9 +226,9 @@ async function flow(opts, d) {
213
226
  { value: 'weekday', label: 'Every weekday night' },
214
227
  { value: 'daily', label: 'Every night' },
215
228
  ], s.schedule ?? saved?.schedule ?? PRESETS[s.preset].schedule);
216
- },
229
+ }),
217
230
  // which agent runs on the schedule
218
- async (s) => {
231
+ team(async (s) => {
219
232
  if (s.schedule === 'none' || opts.yes)
220
233
  return;
221
234
  const usual = s.nightlyAgent ?? 'claude';
@@ -224,9 +237,9 @@ async function flow(opts, d) {
224
237
  { value: 'copilot', label: 'GitHub Copilot', hint: 'runs on your Copilot plan; Copilot opens the pull request' },
225
238
  { value: 'codex', label: 'Codex', hint: 'needs an OpenAI API key', recommended: usual === 'codex' },
226
239
  ], saved?.nightlyAgent ?? usual);
227
- },
240
+ }),
228
241
  // testing permission
229
- async (s) => {
242
+ team(async (s) => {
230
243
  if (opts.yes) {
231
244
  s.proving = 'none';
232
245
  return;
@@ -253,33 +266,48 @@ async function flow(opts, d) {
253
266
  const choice = await p.select('proving', 'How should Bravos handle testing?', choices, choices.some((c) => c.value === want) ? want : 'ask');
254
267
  s.proving = choice === 'auto-reviewed' ? 'auto' : choice;
255
268
  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;
269
+ }),
270
+ // where the app runs locally: optional, and only for automatic testing
271
+ // @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."
272
+ team(async (s) => {
273
+ s.generation = false;
274
+ if (s.proving !== 'auto') {
275
+ s.target = undefined;
261
276
  return;
262
277
  }
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
- },
278
+ 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 });
279
+ s.target = normalTarget(typed);
280
+ }),
266
281
  // the person's own words
267
- async (s) => {
282
+ team(async (s) => {
268
283
  if (s.proving !== 'auto' && s.proving !== 'schedule')
269
284
  return;
270
285
  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
- },
286
+ }),
272
287
  // who confirmed it
273
- async (s) => {
288
+ team(async (s) => {
274
289
  if (opts.yes) {
275
290
  s.name = '';
276
291
  return;
277
292
  }
278
293
  const gitName = s.name || d.exec('git', ['config', 'user.name'], { cwd: s.repo }).out.trim();
279
294
  s.name = await p.text('name', 'Your name, recorded with this choice', { initial: gitName || undefined, validate: (v) => (v.trim() ? undefined : 'Your name, please.') });
295
+ }),
296
+ // commits: asked of every person, joining or not, because the answer is theirs and stays in their clone
297
+ // @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."
298
+ async (s) => {
299
+ if (opts.yes) {
300
+ s.commits = undefined;
301
+ return;
302
+ }
303
+ s.commits = await p.select('commits', 'When Bravos writes its own files (annotations, intent, tests), should your agent commit them?', [
304
+ { value: 'commit', label: 'Yes, commit them', hint: 'never your own code; change it any time with bravos prefs', recommended: true },
305
+ { value: 'leave', label: 'No, leave them for me', hint: 'the agent lists what it wrote' },
306
+ { value: 'ask', label: 'Ask me each session' },
307
+ ], s.commits ?? 'commit');
280
308
  },
281
309
  // GitHub secrets for the scheduled run: held in memory until Apply, never written to a file.
282
- async (s) => {
310
+ team(async (s) => {
283
311
  s.secrets = {};
284
312
  const needed = nightlySecrets({ schedule: s.schedule, nightlyAgent: s.nightlyAgent });
285
313
  if (!needed.length)
@@ -313,7 +341,7 @@ async function flow(opts, d) {
313
341
  if (v.trim())
314
342
  s.secrets[n] = v.trim();
315
343
  }
316
- },
344
+ }),
317
345
  ];
318
346
  // Run the steps. Esc in a step returns to the last step that asked something.
319
347
  const s = { secrets: {} };
@@ -341,18 +369,22 @@ async function flow(opts, d) {
341
369
  const changes = [
342
370
  `Colours: ${answers.theme} (saved in ${tildify(join(d.home, 'config.json'), d.env.HOME)})`,
343
371
  ...(answers.installTools ? [`Install: ${[...missingTools(s), ...missingBundles(s)].map((i) => i.id).join(', ')}`] : []),
372
+ ...(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
373
  `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)',
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'] : []),
375
+ ...(s.join ? [] : [
376
+ ` + skills, hooks and MCP for ${answers.agents.join(', ')}`,
377
+ ' + .guardlink/ threat model (guardlink init, if not there yet)',
378
+ ...(answers.pr !== 'none' ? [' + pre-PR check'] : []),
379
+ ...(answers.pr === 'hook+github' ? [' + .github/workflows/bravos-pr-gate.yml'] : []),
380
+ ...(answers.autopilot ? [' + autopilot'] : []),
381
+ ...(answers.schedule !== 'none' ? [` + .github/workflows/bravos-nightly-${answers.nightlyAgent}.yml (${answers.schedule}, cron ${CRON[answers.schedule]} UTC)`] : []),
382
+ ...(answers.schedule !== 'none' && answers.nightlyAgent === 'copilot' ? [' + .github/workflows/copilot-setup-steps.yml (prepares Copilot\'s session: Node and guardlink)'] : []),
383
+ ...(answers.proving !== 'none' ? [' + .guardlink/scope.yaml (localhost only; authorization left for you)'] : []),
384
+ ...(answers.name ? [` + .guardlink/proving.md (${answers.proving}${answers.target ? ` on ${answers.target}` : ''}, confirmed by ${answers.name})`] : []),
385
+ ...(Object.keys(s.secrets).length ? [` + GitHub secrets: ${Object.keys(s.secrets).join(', ')}`] : []),
386
+ ' + .bravos/setup.json (your answers, for bravos start --again)',
387
+ ]),
356
388
  ...(has(s, 'codegraph') ? ['Then: build the code graph for this repository'] : []),
357
389
  ];
358
390
  p.note(changes.join('\n'), 'About to make these changes');
@@ -380,12 +412,12 @@ async function flow(opts, d) {
380
412
  p.note([
381
413
  ...(answers.installTools && missingTools(s).length ? ['bravos setup --tools -y'] : []),
382
414
  ...(answers.installTools && missingBundles(s).length ? ['bravos setup'] : []),
383
- `bravos ${initArgs(answers).map((x) => (/\s/.test(x) ? JSON.stringify(x) : x)).join(' ')}`,
415
+ s.join ? `bravos sync ${JSON.stringify(answers.repo)}` : `bravos ${initArgs(answers).map((x) => (/\s/.test(x) ? JSON.stringify(x) : x)).join(' ')}`,
384
416
  ...Object.keys(s.secrets).map((n) => `gh secret set ${n} (value from your paste)`),
385
417
  ...(has(s, 'codegraph') ? [`bravos graph build ${JSON.stringify(answers.repo)} --scip no-exec`] : []),
386
418
  ].join('\n'), 'Commands');
387
419
  }
388
- return apply(toAnswers(s), s, d, opts, { missingTools: missingTools(s).length > 0, missingBundles: missingBundles(s).length > 0, codegraph: has(s, 'codegraph') });
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 });
389
421
  }
390
422
  function toAnswers(s) {
391
423
  return {
@@ -400,7 +432,8 @@ function toAnswers(s) {
400
432
  nightlyAgent: s.nightlyAgent ?? 'claude',
401
433
  proving: s.proving ?? 'none',
402
434
  ...(s.proving === 'auto' ? { kitPolicy: s.kitPolicy } : {}),
403
- generation: !!s.generation,
435
+ generation: false,
436
+ ...(s.proving === 'auto' && s.target ? { target: s.target } : {}),
404
437
  words: s.proving === 'auto' || s.proving === 'schedule' ? (s.words ?? '') : '',
405
438
  name: s.name ?? '',
406
439
  };
@@ -423,19 +456,37 @@ async function apply(answers, s, d, opts, has) {
423
456
  for (const l of [...r.out, ...r.err])
424
457
  (r.code ? p.warn : p.info)(l);
425
458
  }
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'));
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."
460
+ 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'));
427
463
  for (const l of init.out)
428
464
  p.info(l);
429
465
  if (init.code !== 0) {
430
466
  for (const l of init.err)
431
467
  p.warn(l);
432
- p.outro('Setup stopped: bravos init did not finish. Fix the line above and run bravos start --again.');
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.');
433
469
  return init.code;
434
470
  }
435
- if (answers.name) {
471
+ // Joining never writes the team's proving.md or setup.json: both are theirs, already committed.
472
+ if (answers.name && !has.join) {
436
473
  mkdirSync(join(repo, '.guardlink'), { recursive: true });
437
474
  writeFileSync(join(repo, '.guardlink', 'proving.md'), provingText({ ...answers, words: answers.words || provingLabel(answers.proving) }, d.today()));
438
475
  }
476
+ if (has.commits) {
477
+ // The answer carries the name of the person at this terminal: the one they gave above, else git's.
478
+ const by = answers.name || d.exec('git', ['config', 'user.name'], { cwd: repo }).out.trim();
479
+ const later = `bravos prefs set commits ${has.commits} --by "<your name>"`;
480
+ if (!by)
481
+ p.warn(`Your answer about commits was not recorded (no name to record it under). Later: ${later}`);
482
+ else {
483
+ const r = await d.bravos(['prefs', 'set', 'commits', has.commits, '--by', by, '-C', repo]);
484
+ if (r.code)
485
+ p.warn(`Your answer about commits was not recorded: ${r.err[0] ?? 'bravos prefs failed'}. Later: ${later}`);
486
+ else
487
+ p.info(r.out[0]);
488
+ }
489
+ }
439
490
  for (const [n, v] of Object.entries(s.secrets)) {
440
491
  const r = d.exec('gh', ['secret', 'set', n], { input: v, cwd: repo });
441
492
  (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,26 +497,56 @@ async function apply(answers, s, d, opts, has) {
446
497
  for (const n of sum.notes)
447
498
  (sum.ok ? p.info : p.warn)(n);
448
499
  }
449
- writeAnswers(repo, answers, d.version, new Date().toISOString());
500
+ if (!has.join)
501
+ writeAnswers(repo, answers, d.version, new Date().toISOString());
450
502
  // hand-off
451
503
  const next = await d.bravos(['next', repo]);
452
504
  if (next.out.length)
453
505
  p.note(next.out.slice(0, 12).join('\n'), 'Setup score');
454
506
  const lead = agents.includes('claude') ? 'claude' : agents[0];
455
507
  const tool = AGENTS.find((a) => a.value === lead)?.label ?? 'your agent';
508
+ if (has.join) {
509
+ // Joining: the context and the annotations are already the team's; there is nothing to type first.
510
+ 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');
511
+ p.outro('This machine is set up for the repository.');
512
+ return 0;
513
+ }
456
514
  const handoff = `${sigil(lead)}bravos-context`;
457
515
  // A scripted run (--yes) leaves the person's clipboard alone.
458
516
  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');
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."
518
+ 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
+ }
527
+ }
528
+ const banner = 'The Bravos banner shows the next step each time you open a session.';
529
+ p.note((begins
530
+ ? [
531
+ `Open ${tool} in ${tildify(repo, d.env.HOME)} and say anything, for example "let's start".`,
532
+ '',
533
+ ' Bravos begins by learning what the app is for: it asks for your design documents,',
534
+ ' then opens a page for you to confirm. After that it maps the threats in your code.',
535
+ '',
536
+ 'Autopilot can review later changes in your agent. Live testing follows the preference and target you authorized.',
537
+ 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}`,
538
+ 'Follow along in a second terminal: bravos watch',
539
+ ]
540
+ : [
541
+ `Open ${tool} in ${tildify(repo, d.env.HOME)} and type:`,
542
+ '',
543
+ ` ${handoff} learns what the app is for (asks you a few questions)`,
544
+ ` ${sigil(lead)}bravos-annotate maps the threats in your code`,
545
+ '',
546
+ 'Autopilot can review later changes in your agent. Live testing follows the preference and target you authorized.',
547
+ copied ? `(${handoff} is on your clipboard.) ${banner}` : banner,
548
+ 'Follow along in a second terminal: bravos watch',
549
+ ]).join('\n'), 'One step left, in your agent');
469
550
  if (opts.yes && !answers.name)
470
551
  p.info('Testing permission was not recorded (a person has to answer it): run bravos start --again in a terminal.');
471
552
  p.outro('Bravos is set up.');
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 bravos sync 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: [] };
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 sync 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 start, or bravos init)');
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 (do not run bravos sync from this older one)`);
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 ? ', …' : ''})`);
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
+ }
package/docs/GUIDE.md CHANGED
@@ -30,7 +30,7 @@ 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. It ends with the one thing to type in your agent.
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).
34
34
 
35
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.
36
36
 
@@ -128,7 +128,7 @@ bravos-context assumes you are researching software you do not own (an open-sour
128
128
 
129
129
  Skills: `/bravos-context`
130
130
 
131
- bravos-context opens its questions as a bravos page (bravos review intent): pre-filled with bravos's suggestions and their sources; change what is wrong, make the calls marked 'needs your call' (Confirm stays off until you do), and the facts bravos drafted stay folded unless you open one to object. The role-by-action matrix links each documented permission to its question. In local reviews, open a cited SRC document to read its verified text. The saved HTML can contain these documents. Each person's answers save to .guardlink/intent-answers/<name>.json; teammates run bravos review intent after pulling and commit theirs. bravos review intent --summary shows where people agree and disagree; only what a named person agreed to is marked confirmed. On Claude Code, --share prepares an artifact with the draft and its citations. Publish that artifact to share it.
131
+ bravos-context opens its questions as a bravos page (bravos review intent): pre-filled with bravos's suggestions and their sources; change what is wrong, make the calls marked 'needs your call' (Confirm stays off until you do), and the facts bravos drafted stay folded unless you open one to object. The role-by-action matrix links each documented permission to its question. In local reviews, open a cited SRC document to read its verified text. The saved HTML can contain these documents. Each person's answers save to .guardlink/intent-answers/<name>.json; teammates run bravos review intent after pulling and commit theirs. Press Done when you are finished: the agent runs bravos review intent --wait and carries on by itself. bravos review intent --summary shows where people agree and disagree; only what a named person agreed to is marked confirmed. On Claude Code, --share prepares an artifact with the draft and its citations. Publish that artifact to share it.
132
132
 
133
133
  ### I wrote security-relevant code
134
134
 
@@ -170,7 +170,7 @@ The no-mistakes gate: validate, lint since the merge base, disclose new exposure
170
170
 
171
171
  Skills: `/bravos-codegraph`
172
172
 
173
- One bounded question to the code graph instead of grepping. Team plan: bravos setup --codegraph stages codegraph-mcp, then bravos graph build . indexes the repository. With it, other skills get sharper on their own: bravos-templatize targets the route and auth that actually reach each sink, bravos-recheck follows a fix's callers and blast radius into other files, bravos-context drafts the real public surface, and bravos-prove tests the most reachable exposures first. Without it they read the code and say so.
173
+ One bounded question to the code graph instead of grepping. Team plan: bravos setup --codegraph stages codegraph-mcp, then bravos graph build . indexes the repository. With it, other skills get sharper on their own: bravos-templatize targets the route and auth that actually reach each sink, bravos-recheck follows a fix's callers and blast radius into other files, bravos-context drafts the real public surface, and bravos-prove tests the most reachable exposures first. After each commit the graph is rebuilt for you: when a session starts and the commit has none, the session hook starts one quiet background build (no tokens; one at a time; never in CI; BRAVOS_GRAPH_AUTOBUILD=off turns it off). Without it they read the code and say so.
174
174
 
175
175
  ### Scan for dependency CVEs, secrets, IaC
176
176
 
@@ -202,6 +202,18 @@ Skills: `/bravos-annotate` · `/bravos-codegraph` · `/bravos-prove`
202
202
 
203
203
  Clone the services side by side in one folder, then run bravos workspace create NAME --member ./gateway=gateway@http://127.0.0.1:8080 --member ./orders=orders@http://127.0.0.1:8081 (bravos workspace plus guardlink link-project plus bravos in each repo and in the shared folder). Work on a service from its own repo; ask questions that cross services from the shared folder, where the briefing and bravos watch show every service. Declare each call to another service as @flows #<this>-<x> -> #<other>-<y> via http (plain ids, not #repo.tag). Build the code graph over the shared folder so it links one service's client calls to another's handlers. bravos report data --workspace writes one report across the services.
204
204
 
205
+ ### After updating bravos
206
+
207
+ Skills: `/bravos`
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.
210
+
211
+ ### Stop being asked about commits
212
+
213
+ Skills: `/bravos`
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.
216
+
205
217
  ### See the findings on one page
206
218
 
207
219
  Skills: `/bravos`
@@ -314,7 +326,7 @@ Never invented. Test users and sessions are seeded or captured for real, or the
314
326
 
315
327
  ### No hidden agents
316
328
 
317
- The agent in your session does the work; bravos never spawns another agent CLI. Model-API probe generation in cxg runs only after you agree to the spend.
329
+ The agent in your session does the work; bravos never spawns another agent CLI, and never uses cxg's model-API probe generation: the tests it runs are the ones written and reviewed in your session.
318
330
 
319
331
  ### Governance
320
332
 
package/docs/UPGRADING.md CHANGED
@@ -2,6 +2,25 @@
2
2
 
3
3
  After `npm install -g @bugb-technologies/bravos`, run **`bravos setup --tools -y`** once on each machine and **`bravos sync`** in each repository. The notes below say what else changes, newest first.
4
4
 
5
+ ## 1.8.0
6
+
7
+ 1.8 removes the stops Bravos put between a developer and their code. After `bravos start`, you open your agent and say anything; Bravos asks once for what only you can decide, then keeps itself current.
8
+
9
+ - **Run `bravos sync` once in each repository, by hand.** It is the last time: from now on the agent's session briefing says when a repository is behind and the agent runs `bravos sync` (and `bravos setup` for Bravos's own bundles) itself. `bravos upkeep` shows what is behind. A bravos older than the one that last synced a repository never syncs it; it tells you to update instead. `BRAVOS_UPKEEP_PROBE=off` stops the check.
10
+ - **After `bravos start`, the agent begins by itself.** For three days, in that clone, the first session starts the context step without being asked and goes on to annotation once a named person confirms. The context gate is unchanged: nothing is annotated before that confirmation.
11
+ - **Done on the review page is enough.** `bravos review intent --wait` returns with everyone's answers when the person presses Done, so nobody types "done" in chat. Run again, it joins the same page.
12
+ - **The commit question is asked once.** `bravos start` asks whether your agent commits the files Bravos writes (annotations, intent, definitions, tests); `bravos prefs set commits commit|leave|ask --by "<your name>"` changes it. The answer is kept under the clone's git directory, never committed, and never covers your own code.
13
+ - **The code graph rebuilds itself (Team plan).** When a session starts and the commit has no graph, the session hook starts one background build (`--scip no-exec`, no tokens). One per repository at a time; never in CI; `BRAVOS_GRAPH_AUTOBUILD=off` turns it off.
14
+ - **`bravos start`:**
15
+ - `--yes` keeps autopilot on for the pull-request preset, as the interactive default does.
16
+ - In a repository that already has Bravos, it sets up only this machine and leaves the team's `proving.md` and setup alone; `bravos start --again` changes the repository's setup.
17
+ - With automatic testing it can take your local app's address and write the target, so the policy needs one merge.
18
+ - It no longer asks about cxg model generation, which Bravos never uses.
19
+ - **`.mcp.json` no longer holds a path from one machine.** The code graph server is registered as `bravos graph mcp`; the next `bravos sync` rewrites an older entry. Reconnect MCP in your agent once (`/mcp` in Claude Code). `bravos` must be on PATH where the agent runs.
20
+ - **`.bravos/setup.json` no longer records your repository path**, theme or tool install.
21
+ - **Licence:** if the portal revokes a machine or a plan ends, the briefing now says so; before, that was lost.
22
+ - **Skills:** no skill tells the agent to stash; the dashboard is built and its path given instead of offered; `bravos-resync` asks before committing your work in progress.
23
+
5
24
  ## 1.7.0
6
25
 
7
26
  - **SessionStart** shows the Bravos mark, repository and branch, findings and next action in a terminal layout that adapts to the available width. Existing theme, plain-text and banner switches still apply.
@@ -4,7 +4,7 @@ import { appendFileSync, existsSync, mkdirSync, openSync, readFileSync, readSync
4
4
  import { join } from 'node:path';
5
5
  import { contextGate } from './context.mjs';
6
6
  import { gitStaleness, staleness } from './resync.mjs';
7
- import { asyncRunner, changedHunks, fingerprint, readSnapshot, workingChanges } from './snapshot.mjs';
7
+ import { asyncRunner, changedHunks, fingerprint, logWatchEvent, readSnapshot, workingChanges } from './snapshot.mjs';
8
8
 
9
9
  export { asyncRunner, readSnapshot, safeSessionId, takeSnapshot } from './snapshot.mjs';
10
10
 
@@ -314,20 +314,5 @@ function finish(findings, payload) {
314
314
  return { decision: 'block', reason, summary, keys: fresh2.map((f) => f.key) };
315
315
  }
316
316
 
317
- export const WATCH_LOG_CAP = 500;
318
-
319
- // @comment -- "Appends one autopilot nudge to .bravos/watch/events.jsonl for bravos watch to show: a local log, not a state store. The folder carries its own .gitignore of *, the file keeps its newest WATCH_LOG_CAP lines, and any failure is swallowed because the nudge itself already went out."
320
- export function logWatchEvent(root, { summary, keys = [] }, now = new Date()) {
321
- try {
322
- const dir = join(root, '.bravos', 'watch');
323
- mkdirSync(dir, { recursive: true });
324
- const ignore = join(dir, '.gitignore');
325
- if (!existsSync(ignore)) writeFileSync(ignore, '*\n');
326
- const file = join(dir, 'events.jsonl');
327
- appendFileSync(file, JSON.stringify({ at: now.toISOString(), text: String(summary ?? '').slice(0, 400), keys }) + '\n');
328
- const lines = readFileSync(file, 'utf8').split('\n').filter(Boolean);
329
- if (lines.length > WATCH_LOG_CAP) writeFileSync(file, lines.slice(-WATCH_LOG_CAP).join('\n') + '\n');
330
- } catch {
331
- /* the log is a convenience for bravos watch */
332
- }
333
- }
317
+ // The watch log lives in snapshot.mjs so the session hook's background graph build can write to it too.
318
+ export { logWatchEvent, WATCH_LOG_CAP } from './snapshot.mjs';