@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.
package/README.md CHANGED
@@ -16,21 +16,25 @@ Requires **Node.js 20 or newer**.
16
16
 
17
17
  ```bash
18
18
  npm install -g @bugb-technologies/bravos
19
- bravos start
19
+ bravos setup
20
20
  ```
21
21
 
22
- `bravos start` guides you through licence, tools, repository and agent setup, PR checks and scheduled upkeep. It shows the changes before you choose Apply, then tells you what to type in your agent. Bravos never starts an agent itself.
22
+ `bravos setup` is the one command for setting Bravos up. Run it in a repository, in a terminal:
23
23
 
24
- For manual setup, run `bravos init` in your repository to write skills, hooks and MCP wiring. `bravos setup` installs the analyzer and code graph (Team); `bravos setup --tools -y` also installs missing or incompatible GuardLink and cxg tools.
24
+ - **The first time on a machine** it signs you in, installs the tools, then asks about the repository: which agents, PR checks, scheduled upkeep and testing. It shows the changes before you choose Apply.
25
+ - **In another repository** it skips what the machine already has and asks only that repository's questions.
26
+ - **In a repository that already has Bravos** it brings this machine and the repository up to date; `bravos setup --change` asks the repository's questions again.
27
+
28
+ Then open your agent and say anything: Bravos begins with what the app is for. Bravos never starts an agent itself.
29
+
30
+ For scripts, flags do one part without questions: `bravos setup --tools -y` installs GuardLink and cxg, `bravos setup --agent claude --autopilot --ci` sets up a repository, and `bravos setup --yes` does a first setup with the defaults.
25
31
 
26
32
  ## Core commands
27
33
 
28
34
  | Command | Purpose |
29
35
  |---|---|
30
- | `bravos start` | Guided setup. |
31
- | `bravos init` | Install skills, hooks and MCP wiring in a repository. |
32
- | `bravos sync` | Refresh installed skills and wiring after an upgrade. |
33
- | `bravos setup` | Install the tools Bravos drives. |
36
+ | `bravos setup` | Set up this machine and this repository, or bring them up to date. |
37
+ | `bravos setup --check` | Say what is installed and what setup would do; changes nothing. |
34
38
  | `bravos graph build .` | Index the repository for code graph questions. |
35
39
  | `bravos sast run` | Run static analysis against the repository. |
36
40
  | `bravos doctor` | Check installed tools and configuration. |
package/dist/ci.js CHANGED
@@ -7,7 +7,7 @@ export const WORKFLOW_MARKER = 'bravos:generated';
7
7
  export const CADENCES = ['weekday', 'daily', 'weekly'];
8
8
  // 03:17 UTC, off the hour so it does not land with everyone else's cron.
9
9
  export const CRON = { weekday: '17 3 * * 1-5', daily: '17 3 * * *', weekly: '17 3 * * 0' };
10
- /** The workflow files, by the name bravos init --workflows takes. */
10
+ /** The workflow files, by the name bravos setup --workflows takes. */
11
11
  export const WORKFLOW_NAMES = ['pr-gate', 'nightly-claude', 'nightly-codex', 'nightly-copilot'];
12
12
  // @comment -- "The files each workflow name writes. The Copilot nightly also writes copilot-setup-steps.yml, the fixed file GitHub reads to prepare Copilot's session."
13
13
  export const WORKFLOW_FILES = {
package/dist/cli.js CHANGED
@@ -7,8 +7,8 @@ import { checkProofTool, formatProofTool } from './proof-tools.js';
7
7
  import { DOCTOR_HELP, INIT_HELP, PROGRAM_HELP, SYNC_HELP } from './help.js';
8
8
  import { Command, CommanderError, InvalidArgumentError, Option } from 'commander';
9
9
  import { CADENCES, CRON, WORKFLOW_NAMES, writeWorkflows } from './ci.js';
10
- import { writeCursorPointer } from './cursor.js';
11
- import { writeOmpExtension } from './omp.js';
10
+ import { CURSOR_RULE_PATH, writeCursorPointer } from './cursor.js';
11
+ import { OMP_EXTENSION_PATH, writeOmpExtension } from './omp.js';
12
12
  import { homeOf, installGlobal } from './global.js';
13
13
  import { uninstall } from './uninstall.js';
14
14
  import { checkKind, newToken, prepareReview, readAllAnswers, readDraft, renderReview, summarize, writePage } from './review.js';
@@ -17,26 +17,51 @@ import { formatRules, gatherRules } from './rules.js';
17
17
  import { spawn as spawnChild, spawnSync } from 'node:child_process';
18
18
  import { createServer as netServer } from 'node:net';
19
19
  import { dirname as pathDirname, join as pathJoin } from 'node:path';
20
- import { OPENCODE_CONFIG, writeOpencode } from './opencode.js';
20
+ import { OPENCODE_CONFIG, OPENCODE_PLUGIN_PATH, writeOpencode } from './opencode.js';
21
21
  import { GUIDE_TOPIC_IDS, renderGuide, renderGuideMarkdown } from './guide.js';
22
22
  import { detectHarnesses } from './detect.js';
23
- import { formatDoctor, runDoctor, withLicence } from './doctor.js';
23
+ import { formatDoctor, runDoctor, withLegacySkills, withLicence } from './doctor.js';
24
24
  import { ensureGuardlink, registerPrePr, whichBin, writeScope } from './guardlink.js';
25
- import { installHook, installedOptIns } from './hooks.js';
25
+ import { AGY_HOOKS_FILE, ALL_SESSION_COMMANDS, hookRegistered, installHook, installedOptIns } from './hooks.js';
26
26
  import { activate, importLicence } from './account.js';
27
27
  import { listDevices, logout, refresh as refreshDevice, revokeDevice } from './device.js';
28
28
  import * as graph from './codegraph.js';
29
29
  import { askGraph } from './watch.js';
30
30
  import { plan as setupPlan, runSast, runSetup } from './setup.js';
31
+ import { isTerminal, setupRoute } from './setup-route.js';
32
+ import { leaveHandoff } from './prefs.js';
31
33
  import { openInBrowser } from './open.js';
32
34
  import { licenceDocument, licenceLib, licenceLines, requireFeature } from './licence.js';
33
35
  import { migrateFromOldName, OLD_DIR, reportMigration } from './migrate.js';
34
36
  import { listBundledSkills } from './skills.js';
35
37
  import { installSkills, linkSkillRoots, mirrorGuardlinkSkills, skillRootsLinked } from './install.js';
36
- import { readLock, sha256, writeLock } from './lock.js';
38
+ import { LOCK_PATH, readLock, sha256, writeLock } from './lock.js';
37
39
  import { mergeCodexConfig, mergeMcpJson, selectServers } from './mcp.js';
38
40
  import { hooksDir, skillsDir as bundledSkillsDir, version } from './paths.js';
39
41
  import { BravosError } from './types.js';
42
+ // @comment -- "Which agents a repository already has Bravos installed for, read from the files Bravos wrote there: the two skills roots, the Codex and Antigravity hook registrations, and the opencode and omp plugins. Upkeep re-applies to exactly these, so a tool that happens to be on this machine, or an AGENTS.md someone added, never widens a team's setup."
43
+ export function installedAgents(root) {
44
+ const has = (rel) => existsSync(join(root, rel));
45
+ const out = [];
46
+ if (has('.claude/skills/bravos/SKILL.md'))
47
+ out.push('claude');
48
+ if (has('.agents/skills/bravos/SKILL.md')) {
49
+ if (hookRegistered(join(root, '.codex', 'hooks.json'), 'SessionStart', ALL_SESSION_COMMANDS))
50
+ out.push('agents');
51
+ try {
52
+ if ('bravos' in JSON.parse(readFileSync(join(root, AGY_HOOKS_FILE), 'utf8')))
53
+ out.push('agy');
54
+ }
55
+ catch {
56
+ /* no Antigravity registration */
57
+ }
58
+ }
59
+ if (has(OPENCODE_PLUGIN_PATH))
60
+ out.push('opencode');
61
+ if (has(OMP_EXTENSION_PATH))
62
+ out.push('omp');
63
+ return out;
64
+ }
40
65
  // @comment -- "Parses --workflows pr-gate,nightly-claude,nightly-codex,nightly-copilot; anything else is a usage error"
41
66
  function parseWorkflows(value) {
42
67
  const out = [];
@@ -105,7 +130,7 @@ function oldHookReferences(root) {
105
130
  for (const [rel, agent] of files) {
106
131
  try {
107
132
  if (readFileSync(join(root, rel), 'utf8').includes(`${OLD_DIR}/hooks/`)) {
108
- out.push(`Hooks: ${rel} still runs the old ${OLD_DIR}/hooks scripts, which are gone; run bravos sync --agent ${agent} to replace them, or remove those entries.`);
133
+ out.push(`Hooks: ${rel} still runs the old ${OLD_DIR}/hooks scripts, which are gone; run bravos setup --agent ${agent} to replace them, or remove those entries.`);
109
134
  }
110
135
  }
111
136
  catch {
@@ -116,10 +141,15 @@ function oldHookReferences(root) {
116
141
  }
117
142
  function pipeline(root, io, opts, withGuardlink, lines) {
118
143
  const dryRun = !!opts.dryRun;
144
+ // Whether Bravos was here before this run: only a first install leaves the hand-off below.
145
+ const hadLock = existsSync(join(root, LOCK_PATH));
119
146
  if (dryRun)
120
147
  lines.push('dry-run: nothing written');
121
- // @comment -- "The move from the old name runs whatever --agent selects: it removes only old-name files the old lock vouches for and moves the data folders, and creates nothing for an agent that was not chosen. bravos start always passes --agent, so skipping it there would leave every old install unmigrated."
148
+ // @comment -- "The move from the old name runs whatever --agent selects: it removes only old-name files the old lock vouches for and moves the data folders, and creates nothing for an agent that was not chosen. the guided setup always passes --agent, so skipping it there would leave every old install unmigrated."
122
149
  reportMigration(migrateFromOldName(root, { dryRun, ownSkills: listBundledSkills(io.skillsDir).map((s) => s.name) }), lines);
150
+ // Upkeep names the agents itself, from what is installed, so nothing below is decided by detection or by this machine's tools.
151
+ if (opts.refreshOnly)
152
+ opts = { ...opts, agent: installedAgents(root) };
123
153
  const detected = detectHarnesses(root);
124
154
  // @comment -- "Explicit --agent limits agent-specific writes, independent of detection and shared skill roots. Antigravity and Codex share .agents/skills but have separate hook registrations; omp/opencode alone use that skills root without installing Codex."
125
155
  const explicit = opts.agent !== undefined;
@@ -208,7 +238,8 @@ function pipeline(root, io, opts, withGuardlink, lines) {
208
238
  for (const s of mirror.skipped)
209
239
  lines.push(` skipped ${s.path} — ${s.reason}`);
210
240
  }
211
- const cursor = explicit ? { status: 'absent' } : writeCursorPointer(root, harnesses, { force: opts.force, dryRun });
241
+ // With --agent the Cursor pointer is left alone; upkeep still refreshes one that is already there.
242
+ const cursor = explicit && !(opts.refreshOnly && existsSync(join(root, CURSOR_RULE_PATH))) ? { status: 'absent' } : writeCursorPointer(root, harnesses, { force: opts.force, dryRun });
212
243
  if (cursor.status === 'skipped')
213
244
  lines.push(`Cursor: skipped ${cursor.path} — ${cursor.reason}`);
214
245
  else if (cursor.status === 'no-skills')
@@ -242,8 +273,8 @@ function pipeline(root, io, opts, withGuardlink, lines) {
242
273
  for (const r of hook.registered)
243
274
  lines.push(`Hooks: ${r.file} ${r.changed ? 'registered' : 'already registered'}`);
244
275
  // A repository that keeps design documents gets the pre-push check in every clone that runs init or sync, not only
245
- // in the clone of whoever added the first one.
246
- if (!dryRun && !opts.global && existsSync(join(root, '.bravos', 'context', 'sources.json')))
276
+ // in the clone of whoever added the first one. Upkeep leaves the clone's git hooks to a person.
277
+ if (!dryRun && !opts.global && !opts.refreshOnly && existsSync(join(root, '.bravos', 'context', 'sources.json')))
247
278
  lines.push(...installPrePush(root, io.env));
248
279
  // An agent left out of --agent keeps its own settings, which may still run the old-name hook the migration moved.
249
280
  for (const w of oldHookReferences(root))
@@ -252,7 +283,7 @@ function pipeline(root, io, opts, withGuardlink, lines) {
252
283
  if (opts.prePrHook) {
253
284
  const p = registerPrePr(root, { dryRun });
254
285
  if (p.status === 'no-config')
255
- lines.push(`pre_pr: ${p.path} absent, bravos's gate not listed in guardlink's agent block (run guardlink init, then bravos sync --pre-pr-hook)`);
286
+ lines.push(`pre_pr: ${p.path} absent, bravos's gate not listed in guardlink's agent block (run guardlink init, then bravos setup --pre-pr-hook)`);
256
287
  else if (p.status === 'already-registered')
257
288
  lines.push(`pre_pr: ${p.path} already lists bravos's gate`);
258
289
  else {
@@ -275,7 +306,7 @@ function pipeline(root, io, opts, withGuardlink, lines) {
275
306
  }
276
307
  const { selected, deferred } = selectServers(io.env);
277
308
  // opencode lists skills only through its skill tool and runs no hooks: commands, a plugin and MCP.
278
- const oc = explicit && !forceOpencode ? { status: 'absent' } : writeOpencode(root, io.env, selected, { force: opts.force, dryRun, skillsDir: io.skillsDir, always: forceOpencode });
309
+ const oc = explicit && !forceOpencode ? { status: 'absent' } : writeOpencode(root, io.env, opts.refreshOnly ? {} : selected, { force: opts.force, dryRun, skillsDir: io.skillsDir, always: forceOpencode });
279
310
  if (oc.status === 'done') {
280
311
  lines.push(`opencode: ${oc.written.length} written, ${oc.unchanged.length} unchanged, ${oc.skipped.length} skipped (plugin, /bravos commands)${oc.mcpAdded.length ? `; ${OPENCODE_CONFIG} mcp added ${oc.mcpAdded.join(', ')}` : ''}${oc.mcpUpdated?.length ? `; ${OPENCODE_CONFIG} mcp refreshed ${oc.mcpUpdated.join(', ')}` : ''}`);
281
312
  for (const s of oc.skipped)
@@ -283,9 +314,9 @@ function pipeline(root, io, opts, withGuardlink, lines) {
283
314
  }
284
315
  const mcpLine = (m) => lines.push(`MCP: ${m.path} added ${names(m.added)}; kept ${names(m.kept)}${m.updated?.length ? `; refreshed ${names(m.updated)} (it pointed at another bravos install or graph store)` : ''}`);
285
316
  if (!explicit || harnesses.includes('claude'))
286
- mcpLine(mergeMcpJson(root, selected, { dryRun }));
317
+ mcpLine(mergeMcpJson(root, selected, { dryRun, onlyExisting: opts.refreshOnly }));
287
318
  if (codex)
288
- mcpLine(mergeCodexConfig(root, selected, { dryRun }));
319
+ mcpLine(mergeCodexConfig(root, selected, { dryRun, onlyExisting: opts.refreshOnly }));
289
320
  if (deferred.length) {
290
321
  const tools = runDoctor(root, io.env).tools;
291
322
  const bin = { cxg: 'cxg', codegraph: 'codegraph-mcp' };
@@ -306,7 +337,7 @@ function pipeline(root, io, opts, withGuardlink, lines) {
306
337
  // A plain sync leaves workflows alone, but says when the installed ones are older than this bravos.
307
338
  const stale = writeWorkflows(root, { dryRun: true, installedOnly: true }).updated;
308
339
  if (stale.length)
309
- lines.push(`Workflows: ${stale.length} bravos workflow(s) are older than this bravos (${stale.join(', ')}); run bravos sync --ci to refresh them.`);
340
+ lines.push(`Workflows: ${stale.length} bravos workflow(s) are older than this bravos (${stale.join(', ')}); run bravos setup --ci to refresh them.`);
310
341
  }
311
342
  const cursorWritten = cursor.status === 'written' || cursor.status === 'updated' ? [cursor.path] : [];
312
343
  const ompWritten = omp.status === 'written' || omp.status === 'updated' ? [omp.path] : [];
@@ -326,7 +357,7 @@ function pipeline(root, io, opts, withGuardlink, lines) {
326
357
  // A user-level install of another version silently replaces these skills in Claude Code, so a
327
358
  // repo sync brings an existing one up to date too (never creates one; a dry run only reports;
328
359
  // BRAVOS_SYNC_GLOBAL=off keeps the two separate).
329
- // @comment -- "When the person already has a user-level install (bravos init --global) of another version, a repo sync re-applies it through installGlobal, so an older ~/.claude/skills copy never shadows the repo's; it never creates a user-level install, and BRAVOS_SYNC_GLOBAL=off opts out."
360
+ // @comment -- "When the person already has a user-level install (bravos setup --global) of another version, a repo sync re-applies it through installGlobal, so an older ~/.claude/skills copy never shadows the repo's; it never creates a user-level install, and BRAVOS_SYNC_GLOBAL=off opts out."
330
361
  let userVersion = null;
331
362
  try {
332
363
  userVersion = JSON.parse(readFileSync(pathJoin(homeOf(io.env), '.bravos', 'skills.lock'), 'utf8'))?.bravos_version ?? null;
@@ -337,13 +368,16 @@ function pipeline(root, io, opts, withGuardlink, lines) {
337
368
  if (userVersion && userVersion !== version() && resolve(homeOf(io.env)) !== resolve(root)) {
338
369
  if (dryRun)
339
370
  lines.push(`user-level bravos is ${userVersion}: a real sync would bring it to ${version()} too`);
371
+ // Upkeep writes inside the repository only: the person's own folders are theirs to update.
372
+ else if (opts.refreshOnly)
373
+ lines.push(`note: your user-level bravos (~/.claude/skills) is ${userVersion}, not ${version()}; upkeep left it alone. In your own terminal run: bravos setup --global`);
340
374
  else if (io.env.BRAVOS_SYNC_GLOBAL === 'off') {
341
- lines.push(`warning: your user-level bravos (~/.claude/skills) is ${userVersion}; Claude Code prefers it over this repo's ${version()}. Run: bravos sync --global`);
375
+ lines.push(`warning: your user-level bravos (~/.claude/skills) is ${userVersion}; Claude Code prefers it over this repo's ${version()}. Run: bravos setup --global`);
342
376
  }
343
377
  else if (io.env.CLAUDECODE) {
344
378
  // Inside a Claude Code session, writes under ~/.claude can be held back by its sandbox while the
345
379
  // lock in ~/.bravos still lands, which would mark a stale copy current. Leave the user install alone.
346
- lines.push(`warning: your user-level bravos is ${userVersion}, older than ${version()}; this runs inside a Claude Code session, which may not write ~/.claude, so it was left alone. In your own terminal run: bravos sync --global`);
380
+ lines.push(`warning: your user-level bravos is ${userVersion}, older than ${version()}; this runs inside a Claude Code session, which may not write ~/.claude, so it was left alone. In your own terminal run: bravos setup --global`);
347
381
  }
348
382
  else {
349
383
  try {
@@ -351,18 +385,22 @@ function pipeline(root, io, opts, withGuardlink, lines) {
351
385
  installGlobal(io.env, sub, { skillsDir: io.skillsDir, hooksDir: io.hooksDir });
352
386
  const skipped = sub.filter((l) => l.startsWith(' skipped'));
353
387
  if (skipped.length) {
354
- lines.push(`warning: user-level bravos only partly updated; ${skipped.length} file(s) were not written. Run: bravos sync --global`);
388
+ lines.push(`warning: user-level bravos only partly updated; ${skipped.length} file(s) were not written. Run: bravos setup --global`);
355
389
  lines.push(...skipped);
356
390
  }
357
391
  else
358
392
  lines.push(`user-level bravos updated ${userVersion} → ${version()} (~/.claude/skills, ~/.bravos/hooks), so Claude Code does not use an older copy. BRAVOS_SYNC_GLOBAL=off keeps them separate.`);
359
393
  }
360
394
  catch (e) {
361
- lines.push(`warning: could not update your user-level bravos (${e instanceof Error ? e.message : String(e)}). Run: bravos sync --global`);
395
+ lines.push(`warning: could not update your user-level bravos (${e instanceof Error ? e.message : String(e)}). Run: bravos setup --global`);
362
396
  }
363
397
  }
364
398
  }
365
- lines.push('Next: open a session. The banner and briefing load by themselves; /bravos is only for the next step.');
399
+ // @comment -- "A first install, by any route, leaves the hand-off: the next session of an agent that runs the session hook begins the context step by itself. Not for a re-apply, a dry run, a workspace member, or agents that run no hook."
400
+ const handed = withGuardlink && !hadLock && !dryRun && opts.handoff !== false && (hookHarnesses.length > 0 || agy) && leaveHandoff(root, io.env);
401
+ lines.push(handed
402
+ ? 'Next: open a session and say anything. Bravos begins by learning what the app is for, then maps the threats in your code.'
403
+ : 'Next: open a session. The banner and briefing load by themselves; /bravos is only for the next step.');
366
404
  }
367
405
  // @comment -- "Builds the commander program (init, sync, doctor); exit-code mapping lives in run()."
368
406
  export function buildProgram(io, result) {
@@ -418,52 +456,44 @@ export function buildProgram(io, result) {
418
456
  for (const l of lines)
419
457
  io.stdout(l);
420
458
  };
421
- program
422
- .command('init [dir]')
423
- .description('First install: detect agents, run guardlink init if needed, install skills, hooks and MCP wiring.')
424
- .addHelpText('after', INIT_HELP)
425
- .option('--agent <list>', 'comma-separated agents: claude,codex,agy,opencode,omp, or all', parseAgents)
426
- .addOption(new Option('--guardlink-mode <mode>', 'guardlink annotation mode (default: GuardLink chooses)').choices(['inline', 'external']))
427
- .option('--no-guardlink-init', 'do not run guardlink init')
428
- .option('--force', 'overwrite edited or authored skill files')
429
- .option('--pre-pr-hook', 'also register the PreToolUse gate that checks gh pr create / gh pr ready')
430
- .option('--ci', 'also write the PR gate and nightly GitHub Actions workflows into .github/workflows/')
431
- .option('--workflows <list>', `which workflows --ci writes: ${WORKFLOW_NAMES.join(',')} (implies --ci)`, parseWorkflows)
432
- .addOption(new Option('--schedule <cadence>', 'how often the nightly workflow runs (implies --ci)').choices(CADENCES))
433
- .option('--scope', 'also write the loopback-only cxg scope starter to .guardlink/scope.yaml when absent')
434
- .option('--link-skills', 'make .agents/skills a link to .claude/skills so each skill exists once')
435
- .option('--global', 'install for your user (home folder) instead of a repository')
436
- .option('--autopilot', 'end-of-turn check plus the pre-PR gate, so upkeep happens without being asked')
437
- .option('--dry-run', 'report what would change without writing')
438
- .action((dir, opts) => guardedAsync(async (lines) => {
439
- await gateInstallFlags(opts, 'init');
459
+ // Registered first so it leads the command list in help; its options and action are attached below, once the parts it dispatches to exist.
460
+ const setupCommand = program.command('setup [dir]');
461
+ // @comment -- "The options that set Bravos up in a repository, defined once: bravos setup takes them, and so do the older init and sync, which stay registered but hidden from help so scripts, the website's setup skill and 1.8 briefings that name them keep working unchanged."
462
+ const repositoryOptions = (cmd, o) => {
463
+ cmd.option('--agent <list>', 'comma-separated agents: claude,codex,agy,opencode,omp, or all', parseAgents);
464
+ if (o.guardlink) {
465
+ cmd.addOption(new Option('--guardlink-mode <mode>', 'guardlink annotation mode (default: GuardLink chooses)').choices(['inline', 'external']));
466
+ cmd.option('--no-guardlink-init', 'do not run guardlink init');
467
+ }
468
+ return cmd
469
+ .option('--force', 'overwrite edited or authored skill files')
470
+ .option('--pre-pr-hook', 'also register the PreToolUse gate that checks gh pr create / gh pr ready')
471
+ .option('--ci', 'also write the PR gate and nightly GitHub Actions workflows into .github/workflows/')
472
+ .option('--workflows <list>', `which workflows --ci writes: ${WORKFLOW_NAMES.join(',')} (implies --ci)`, parseWorkflows)
473
+ .addOption(new Option('--schedule <cadence>', 'how often the nightly workflow runs (implies --ci)').choices(CADENCES))
474
+ .option('--scope', 'also write the loopback-only cxg scope starter to .guardlink/scope.yaml when absent')
475
+ .option('--link-skills', 'make .agents/skills a link to .claude/skills so each skill exists once')
476
+ .option('--global', 'install for your user (home folder) instead of a repository')
477
+ .option('--autopilot', 'end-of-turn check plus the pre-PR gate, so upkeep happens without being asked')
478
+ .option('--dry-run', 'report what would change without writing')
479
+ .addOption(new Option('--no-handoff', 'do not leave the marker that makes the next agent session begin by itself').hideHelp());
480
+ };
481
+ // @comment -- "The repository part: the licence gate for the paid flags first, then the user-level install for --global, else the install pipeline. `first` is true for a first install (it runs guardlink init); the refusal names the command the person typed."
482
+ const repositoryAction = async (name, dir, opts, first, lines) => {
483
+ await gateInstallFlags(opts, name);
440
484
  if (opts.global)
441
485
  installGlobal(io.env, lines, { force: opts.force, dryRun: opts.dryRun, skillsDir: io.skillsDir, hooksDir: io.hooksDir });
442
486
  else
443
- pipeline(dirArg(dir), io, opts, true, lines);
444
- }));
445
- program
446
- .command('sync [dir]')
487
+ pipeline(dirArg(dir), io, opts, first, lines);
488
+ };
489
+ repositoryOptions(program
490
+ .command('init [dir]', { hidden: true })
491
+ .description('First install: detect agents, run guardlink init if needed, install skills, hooks and MCP wiring.')
492
+ .addHelpText('after', INIT_HELP), { guardlink: true }).action((dir, opts) => guardedAsync((lines) => repositoryAction('init', dir, opts, true, lines)));
493
+ repositoryOptions(program
494
+ .command('sync [dir]', { hidden: true })
447
495
  .description('Re-apply the installed bravos version to a repository (never runs guardlink init).')
448
- .addHelpText('after', SYNC_HELP)
449
- .option('--agent <list>', 'comma-separated agents: claude,codex,agy,opencode,omp, or all', parseAgents)
450
- .option('--force', 'overwrite edited or authored skill files')
451
- .option('--pre-pr-hook', 'also register the PreToolUse gate that checks gh pr create / gh pr ready')
452
- .option('--ci', 'also write the PR gate and nightly GitHub Actions workflows into .github/workflows/')
453
- .option('--workflows <list>', `which workflows --ci writes: ${WORKFLOW_NAMES.join(',')} (implies --ci)`, parseWorkflows)
454
- .addOption(new Option('--schedule <cadence>', 'how often the nightly workflow runs (implies --ci)').choices(CADENCES))
455
- .option('--scope', 'also write the loopback-only cxg scope starter to .guardlink/scope.yaml when absent')
456
- .option('--link-skills', 'make .agents/skills a link to .claude/skills so each skill exists once')
457
- .option('--global', 'install for your user (home folder) instead of a repository')
458
- .option('--autopilot', 'end-of-turn check plus the pre-PR gate, so upkeep happens without being asked')
459
- .option('--dry-run', 'report what would change without writing')
460
- .action((dir, opts) => guardedAsync(async (lines) => {
461
- await gateInstallFlags(opts, 'sync');
462
- if (opts.global)
463
- installGlobal(io.env, lines, { force: opts.force, dryRun: opts.dryRun, skillsDir: io.skillsDir, hooksDir: io.hooksDir });
464
- else
465
- pipeline(dirArg(dir), io, opts, false, lines);
466
- }));
496
+ .addHelpText('after', SYNC_HELP), { guardlink: false }).action((dir, opts) => guardedAsync((lines) => repositoryAction('sync', dir, opts, false, lines)));
467
497
  program
468
498
  .command('licence')
469
499
  .alias('license')
@@ -518,24 +548,6 @@ export function buildProgram(io, result) {
518
548
  else
519
549
  throw new BravosError(`unknown account action ${JSON.stringify(action)}: activate, import <file>, status, refresh, devices, revoke <id> or logout`);
520
550
  }));
521
- program
522
- .command('setup')
523
- .description('Put the binaries bravos drives on this machine: the analyzer (bravos-cli, SAST) and the code graph (codegraph-build, codegraph-mcp) are licensed bundles fetched through the account portal, verified and staged under $BRAVOS_HOME; --tools adds guardlink and cxg through npm and cargo.')
524
- .option('--analyzer', 'only the analyzer bundle')
525
- .option('--codegraph', 'only the code graph bundle')
526
- .option('--tools', 'also guardlink (npm) and cxg (cargo); needs -y')
527
- .option('--check', 'report what is here and what setup would do; changes nothing')
528
- .option('--dry-run', 'say what would be fetched or run; changes nothing')
529
- .option('-y, --yes', 'run the package-manager installs, and refetch a bundle that is already staged')
530
- .option('--json', 'with --check: print the plan as JSON (bravos.setup-plan/v1)')
531
- .action((opts) => guardedAsync(async (lines) => {
532
- if (opts.check && opts.json) {
533
- const p = await setupPlan(io.env);
534
- lines.push(JSON.stringify({ schema: 'bravos.setup-plan/v1', plan: p.licence.licensed ? 'licensed' : p.licence.state, items: p.items }, null, 2));
535
- return;
536
- }
537
- lines.push(...(await runSetup(io.env, opts, { echo: io.stdout })));
538
- }));
539
551
  program
540
552
  .command('graph [question] [args...]')
541
553
  .description('Ask the code graph (Team plan): `graph build [DIR] [--scip MODE]` indexes a repository; `graph <question> [args] --json` asks it (attack-surface, entry-points, callers <file::symbol>, reachable-sinks, call-chain, …; the same answers as the codegraph_ MCP tools); `graph mcp` serves those tools over MCP on stdio (what .mcp.json registers); `graph --json` lists every question this machine\'s binary answers.')
@@ -612,30 +624,40 @@ export function buildProgram(io, result) {
612
624
  io.stderr(r.stderr.replace(/\n$/, ''));
613
625
  result.code = r.status ?? 1;
614
626
  }));
615
- // @comment -- "bravos start: the guided first run (src/start). Interactive in a terminal; --yes takes every default and never invents what a person must answer. It installs through these same commands, run in-process."
616
- program
617
- .command('start [dir]')
618
- .description('Guided first-run setup: licence, tools, repository, agents, PR checks, schedule and testing permission, one question at a time. Nothing changes until you confirm.')
619
- .option('--again', 'ask again, with your previous answers selected')
620
- .option('-y, --yes', 'no questions: take every default (testing permission stays unrecorded)')
621
- .addOption(new Option('--preset <name>', 'starting point').choices(['annotate', 'pr', 'everything']))
622
- .action((dir, opts) => guardedAsync(async () => {
627
+ // @comment -- "bravos setup: the guided first run (src/start). Interactive in a terminal; --yes takes every default and never invents what a person must answer. It installs through these same commands, run in-process."
628
+ // @comment -- "The guided setup (and its unattended --yes form), shared by bravos setup and the older bravos start: builds what the wizard needs (a prompter for a terminal or a scripted one, this CLI run in-process and as a child, the licence, the clipboard) and runs it. Without a terminal and without --yes it refuses, naming the command that was typed."
629
+ const wizardAction = async (name, dir, opts) => {
623
630
  const { runStart } = await import('./start/index.js');
624
631
  const ui = await import('./start/ui.js');
625
632
  const { plan: startPlan } = await import('./setup.js');
626
633
  const { licenceStatus } = await import('./licence.js');
627
634
  const { bravosHome } = await import('./palette.js');
628
- const interactive = !opts.yes && !!process.stdout.isTTY && !!process.stdin.isTTY;
635
+ const interactive = !opts.yes && isTerminal(io);
629
636
  if (!opts.yes && !interactive)
630
- throw new BravosError('bravos start asks questions, so it needs a terminal. In a script use: bravos start --yes --preset pr <dir>');
637
+ throw new BravosError(`bravos ${name} asks questions, so it needs a terminal. In a script use: bravos ${name} --yes --preset pr <dir>`);
631
638
  const prompter = interactive ? ui.terminalPrompter() : ui.scriptedPrompter({}, io.stdout);
632
- const capture = async (argv) => {
639
+ // @comment -- "Every bravos command Apply runs is a child of this same node and cli.js, no shell, with its output captured line by line and each line passed to the spinner as it arrives. Run in this process instead, the installs (npm, and cargo compiling cxg for minutes) block it, the spinner cannot redraw and the screen looks frozen; guardlink init would also print straight into the terminal under it. The child gets no terminal, so nothing it runs can ask a question."
640
+ const capture = (argv, onLine) => new Promise((done) => {
633
641
  const out = [];
634
642
  const err = [];
635
- const code = await run(argv, { ...io, stdout: (x) => out.push(x), stderr: (x) => err.push(x) });
636
- return { code, out, err };
637
- };
638
- result.code = await runStart({ dir, again: opts.again, yes: opts.yes, preset: opts.preset }, {
643
+ const child = spawnChild(process.execPath, [fileURLToPath(import.meta.url), ...argv], { env: io.env, stdio: ['ignore', 'pipe', 'pipe'] });
644
+ const lines = (into) => {
645
+ let rest = '';
646
+ return (b) => {
647
+ const parts = (rest + b.toString('utf8')).split('\n');
648
+ rest = parts.pop() ?? '';
649
+ for (const l of parts) {
650
+ into.push(l);
651
+ onLine?.(l);
652
+ }
653
+ };
654
+ };
655
+ child.stdout.on('data', lines(out));
656
+ child.stderr.on('data', lines(err));
657
+ child.on('error', (e) => done({ code: 1, out, err: [...err, e.message] }));
658
+ child.on('close', (code) => done({ code: code ?? 1, out, err }));
659
+ });
660
+ result.code = await runStart({ dir, again: opts.again, yes: opts.yes, preset: opts.preset, command: name }, {
639
661
  prompter,
640
662
  env: io.env,
641
663
  cwd: process.cwd(),
@@ -672,6 +694,93 @@ export function buildProgram(io, result) {
672
694
  },
673
695
  today: () => new Date().toISOString().slice(0, 10),
674
696
  });
697
+ };
698
+ program
699
+ .command('start [dir]', { hidden: true })
700
+ .description('Guided first-run setup: licence, tools, repository, agents, PR checks, schedule and testing permission, one question at a time. Nothing changes until you confirm.')
701
+ .option('--again', 'ask again, with your previous answers selected')
702
+ .option('-y, --yes', 'no questions: take every default (testing permission stays unrecorded)')
703
+ .addOption(new Option('--preset <name>', 'starting point').choices(['annotate', 'pr', 'everything']))
704
+ .action((dir, opts) => guardedAsync(() => wizardAction('start', dir, opts)));
705
+ // @comment -- "Upkeep: what a plain bravos setup does where nobody can be asked (an agent's shell, a script, a pipe). It brings what is already installed up to date and nothing more. The repository's Bravos files are re-applied only where Bravos is installed and this bravos is not the older side, and only for the agents the repository already has (refreshOnly). Bravos's own signed bundles are fetched only when they are behind the version this bravos pins. It never installs Bravos into a repository, never runs the guardlink and cxg installers, never writes to the person's own folders, and it exits 0 with a line for everything it left to a person, so a session briefing can tell an agent to run it without asking."
706
+ const upkeepAction = async (root, dryRun, lines) => {
707
+ const { gatherUpkeep } = await import('./upkeep.js');
708
+ const u = await gatherUpkeep(root, io.env);
709
+ lines.push('bravos setup: no terminal here, so this is upkeep only: nothing is asked and nothing new is installed. In a terminal, bravos setup is the guided setup.');
710
+ if (u.repo === null)
711
+ lines.push(`repository: Bravos is not set up in ${root}; nothing was changed. A person sets it up: bravos setup in a terminal, or bravos setup --yes ${JSON.stringify(root)}`);
712
+ else if (u.sync.files === 0)
713
+ lines.push(`repository: up to date with bravos ${u.cli}`);
714
+ else if (u.sync.direction === 'repo-newer')
715
+ lines.push(`repository: its Bravos files are from ${u.repo}, newer than this bravos (${u.cli}); nothing was changed, because an older bravos would roll them back. Update bravos: npm install -g @bugb-technologies/bravos@latest`);
716
+ else {
717
+ lines.push(`repository: ${u.sync.files} file${u.sync.files === 1 ? '' : 's'} behind bravos ${u.cli}${dryRun ? ' would be' : ''} brought up to date`);
718
+ const sub = [];
719
+ pipeline(root, io, { refreshOnly: true, dryRun }, false, sub);
720
+ // The pipeline's own closing line is for a person after a first install; everything else it said is the record of what changed.
721
+ lines.push(...sub.filter((l) => !l.startsWith('Next: open a session')).map((l) => ` ${l}`));
722
+ }
723
+ for (const b of u.bundles) {
724
+ lines.push(...(await runSetup(io.env, { [b.id]: true, dryRun }, { echo: io.stdout })));
725
+ }
726
+ // Absent pieces are named, never fetched here: a first install is a person's go-ahead.
727
+ const plan = await setupPlan(io.env);
728
+ for (const item of plan.items) {
729
+ if (item.present)
730
+ continue;
731
+ if (item.id === 'analyzer' || item.id === 'codegraph') {
732
+ if (item.licensed)
733
+ lines.push(`${item.id}: not installed; left for a person's go-ahead: bravos setup --${item.id}`);
734
+ }
735
+ else
736
+ lines.push(`${item.id}: not installed; left for a person's go-ahead: bravos setup --tools -y`);
737
+ }
738
+ };
739
+ // @comment -- "bravos setup: the one command. It looks at what was typed and whether there is a terminal (src/setup-route.ts) and does one job: the read-only check, the machine part, the user-level install, the repository part by flags, an unattended first setup, the guided wizard, or upkeep. It is declared after the wizard and repository actions it dispatches to."
740
+ const SETUP_FLAGS = 'bravos setup: --tools, --analyzer and --codegraph set up this machine; the other flags set up a repository. Run them as two commands, for example: bravos setup --tools -y, then bravos setup --agent claude';
741
+ repositoryOptions(setupCommand
742
+ .description('Set Bravos up, here and on this machine, doing only what is missing. In a terminal it is a guided setup: sign in, install the tools, then this repository\'s agents, PR checks and testing permission; in a repository that already has Bravos it only brings this machine and the repository up to date (--change re-asks the repository\'s choices). Without a terminal (an agent, a script) a plain bravos setup only brings what is already installed up to date. Flags do one part by hand: --tools, --analyzer, --codegraph for this machine; --agent, --autopilot, --ci and the rest for the repository; --yes for an unattended first setup; --check to look and change nothing.')
743
+ .option('--change', 'ask this repository\'s questions again, with the recorded answers selected')
744
+ .addOption(new Option('--again', 'the earlier name of --change').hideHelp())
745
+ .addOption(new Option('--preset <name>', 'starting point for the guided setup').choices(['annotate', 'pr', 'everything']))
746
+ .option('--analyzer', 'this machine: only the analyzer bundle')
747
+ .option('--codegraph', 'this machine: only the code graph bundle')
748
+ .option('--tools', 'this machine: guardlink (npm) and cxg (cargo); needs -y')
749
+ .option('--check', 'report what is here and what setup would do; changes nothing')
750
+ .option('-y, --yes', 'alone: no questions, set this repository up with the defaults (or join it). With --tools, --analyzer or --codegraph: run the installers, and fetch a staged bundle again')
751
+ .option('--json', 'with --check: print the plan as JSON (bravos.setup-plan/v1)'), { guardlink: true });
752
+ setupCommand.action((dir, opts) => guardedAsync(async (lines) => {
753
+ const given = new Set(Object.keys(opts).filter((k) => setupCommand.getOptionValueSource(k) === 'cli'));
754
+ if (given.has('again'))
755
+ given.add('change');
756
+ const route = setupRoute(given, isTerminal(io));
757
+ if (route === 'conflict')
758
+ throw new BravosError(SETUP_FLAGS);
759
+ if (route === 'needs-terminal')
760
+ throw new BravosError('bravos setup asks questions here, so it needs a terminal. Without one: bravos setup --yes [--preset pr] [dir]');
761
+ if (route === 'check' || route === 'machine') {
762
+ if (dir)
763
+ throw new BravosError(`bravos setup ${route === 'check' ? '--check' : '--tools, --analyzer and --codegraph'} is about this machine and takes no folder`);
764
+ if (route === 'check' && opts.json) {
765
+ const p = await setupPlan(io.env);
766
+ lines.push(JSON.stringify({ schema: 'bravos.setup-plan/v1', plan: p.licence.licensed ? 'licensed' : p.licence.state, items: p.items }, null, 2));
767
+ return;
768
+ }
769
+ lines.push(...(await runSetup(io.env, { analyzer: opts.analyzer, codegraph: opts.codegraph, tools: opts.tools, check: opts.check, dryRun: opts.dryRun, yes: opts.yes }, { echo: io.stdout })));
770
+ return;
771
+ }
772
+ if (route === 'upkeep') {
773
+ await upkeepAction(dirArg(dir), !!opts.dryRun, lines);
774
+ return;
775
+ }
776
+ if (route === 'global' || route === 'repository') {
777
+ // A repository that has Bravos is re-applied to (as sync did); one that does not gets a first install (as init did).
778
+ const first = !existsSync(join(dirArg(dir), LOCK_PATH));
779
+ await repositoryAction('setup', dir, opts, first, lines);
780
+ return;
781
+ }
782
+ // unattended or wizard
783
+ await wizardAction('setup', dir, { again: opts.change || opts.again, yes: route === 'unattended', preset: opts.preset });
675
784
  }));
676
785
  program
677
786
  .command('doctor [dir]')
@@ -680,7 +789,7 @@ export function buildProgram(io, result) {
680
789
  .action((dir) => guardedAsync(async (lines) => {
681
790
  const L = await licenceLib();
682
791
  const v = L.status(io.env);
683
- lines.push(formatDoctor(withLicence(runDoctor(dirArg(dir), io.env), L.planLine(v), v.licensed)));
792
+ lines.push(formatDoctor(await withLegacySkills(withLicence(runDoctor(dirArg(dir), io.env), L.planLine(v), v.licensed), io.env)));
684
793
  for (const name of ['guardlink', 'cxg'])
685
794
  lines.push(formatProofTool(checkProofTool(name, io.env)));
686
795
  }));
@@ -756,10 +865,10 @@ export function buildProgram(io, result) {
756
865
  else
757
866
  throw new BravosError(`unknown context action '${action}'; use add, update, list, check, gate or decline`);
758
867
  }));
759
- // @comment -- "bravos upkeep: what has fallen behind the installed bravos, here and on this machine: the repository's copies of the skills and hooks (bravos sync), and staged bundles older than this version pins (bravos setup). Read-only, no network, free; the session hook asks it at every start so the agent can run those two commands itself."
868
+ // @comment -- "bravos upkeep: what has fallen behind the installed bravos, here and on this machine: the repository's copies of the skills and hooks, and staged bundles older than this version pins; bravos setup brings both up to date. Read-only, no network, free; the session hook asks it at every start so the agent can run those two commands itself."
760
869
  program
761
870
  .command('upkeep [dir]')
762
- .description('Say what is behind the installed bravos: this repository\'s copies of the skills and hooks (fixed by bravos sync) and staged bundles older than this version pins (fixed by bravos setup). Read-only; no network; free; runs no model.')
871
+ .description('Say what is behind the installed bravos: this repository\'s copies of the skills and hooks, and staged bundles older than this version pins. bravos setup brings both up to date. Read-only; no network; free; runs no model.')
763
872
  .option('--json', 'print bravos.upkeep/v1')
764
873
  .action((dir, opts) => guardedAsync(async (lines) => {
765
874
  const { gatherUpkeep, formatUpkeep } = await import('./upkeep.js');
@@ -885,7 +994,8 @@ export function buildProgram(io, result) {
885
994
  lines.push(JSON.stringify(s, null, 2));
886
995
  return;
887
996
  }
888
- lines.push(`bravos setup ${s.done}/${s.total} for ${inputs.repo}`);
997
+ // "Setup", not "bravos setup": that is the name of a command now.
998
+ lines.push(`Setup ${s.done}/${s.total} for ${inputs.repo}`);
889
999
  // Which plan this machine is on, so the Team-plan steps below read as a choice and not a fault.
890
1000
  try {
891
1001
  if (inputs.licence?.state)
@@ -990,11 +1100,11 @@ export function buildProgram(io, result) {
990
1100
  const ws = await import('./workspace.js');
991
1101
  const env = io.env;
992
1102
  const cwd = process.cwd();
993
- // bravos init (no bravos yet) or sync in one folder, in-process, summarised to one line.
1103
+ // bravos setup (no bravos yet) or sync in one folder, in-process, summarised to one line.
994
1104
  const install = async (path, appFolder = false) => {
995
1105
  const out = [];
996
1106
  const fresh = !appFolder && !existsSync(pathJoin(path, '.bravos', 'skills.lock'));
997
- const code = await run([fresh ? 'init' : 'sync', path], { ...io, stdout: (s) => out.push(s), stderr: (s) => out.push(s) });
1107
+ const code = await run([fresh ? 'init' : 'sync', path, ...(fresh ? ['--no-handoff'] : [])], { ...io, stdout: (s) => out.push(s), stderr: (s) => out.push(s) });
998
1108
  return `${code === 0 ? '✔' : '✘'} bravos ${fresh ? 'init' : 'sync'} ${path}${code === 0 ? '' : `: ${out.filter(Boolean).slice(-1)[0] ?? `exit ${code}`}`}`;
999
1109
  };
1000
1110
  const known = (name) => {
@@ -1292,7 +1402,7 @@ export async function run(argv, io = {}) {
1292
1402
  const result = { code: 0 };
1293
1403
  // @comment -- "Bare bravos in a repository bravos has not set up yet points at the guided setup first"
1294
1404
  if (argv.length === 0 && !existsSync(join(process.cwd(), '.bravos')))
1295
- full.stdout('New here? Run bravos start: a guided setup, one question at a time.\n');
1405
+ full.stdout('New here? Run bravos setup: a guided setup, one question at a time.\n');
1296
1406
  try {
1297
1407
  await buildProgram(full, result).parseAsync(argv, { from: 'user' });
1298
1408
  }
package/dist/context.js CHANGED
@@ -362,7 +362,7 @@ export function installPrePush(root, env) {
362
362
  mkdirSync(dir, { recursive: true });
363
363
  writeFileSync(file, PRE_PUSH_SCRIPT, { mode: 0o755 });
364
364
  chmodSync(file, 0o755);
365
- return ['A pre-push check now runs in this clone: a push that changes the design documents is stopped if one carries a secret or a local path (teammates get it from bravos sync).'];
365
+ return ['A pre-push check now runs in this clone: a push that changes the design documents is stopped if one carries a secret or a local path (teammates get it from bravos setup).'];
366
366
  }
367
367
  catch (e) {
368
368
  return [`The pre-push check could not be installed (${e.message.split('\n')[0]}); bravos context check does the same by hand.`];