@bugb-technologies/bravos 1.7.0 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/README.md +11 -7
  2. package/dist/ci.js +1 -1
  3. package/dist/cli.js +271 -111
  4. package/dist/codegraph.js +21 -0
  5. package/dist/context.js +1 -1
  6. package/dist/doctor.js +20 -11
  7. package/dist/global.js +3 -3
  8. package/dist/graphbin.js +2 -0
  9. package/dist/guardlink.js +1 -1
  10. package/dist/guide.js +12 -10
  11. package/dist/help.js +45 -19
  12. package/dist/hooks.js +44 -21
  13. package/dist/install.js +2 -1
  14. package/dist/lock.js +1 -0
  15. package/dist/mcp.js +21 -5
  16. package/dist/palette.js +2 -2
  17. package/dist/plugin-release.js +2 -2
  18. package/dist/plugin.js +3 -3
  19. package/dist/prefs.js +66 -0
  20. package/dist/review-wait.js +76 -0
  21. package/dist/setup-route.js +37 -0
  22. package/dist/setup.js +3 -2
  23. package/dist/skills.js +1 -1
  24. package/dist/start/answers.js +36 -7
  25. package/dist/start/index.js +190 -69
  26. package/dist/start/repos.js +1 -1
  27. package/dist/start/ui.js +2 -2
  28. package/dist/upkeep.js +89 -0
  29. package/dist/watch-frame.js +1 -1
  30. package/dist/watch.js +1 -1
  31. package/docs/GUIDE.md +23 -11
  32. package/docs/UPGRADING.md +43 -1
  33. package/hooks/lib/autopilot.mjs +3 -18
  34. package/hooks/lib/briefing.mjs +93 -14
  35. package/hooks/lib/graph-autobuild.mjs +131 -0
  36. package/hooks/lib/legacy-skills.mjs +68 -0
  37. package/hooks/lib/palette.mjs +4 -4
  38. package/hooks/lib/prefs.mjs +108 -0
  39. package/hooks/lib/refresh.mjs +45 -1
  40. package/hooks/lib/setup.mjs +8 -8
  41. package/hooks/lib/snapshot.mjs +19 -1
  42. package/hooks/session-start.mjs +7 -2
  43. package/package.json +1 -1
  44. package/skills/bravos/SKILL.md +5 -4
  45. package/skills/bravos-annotate/SKILL.md +4 -4
  46. package/skills/bravos-cicd/SKILL.md +1 -1
  47. package/skills/bravos-codegraph/SKILL.md +1 -1
  48. package/skills/bravos-context/SKILL.md +6 -6
  49. package/skills/bravos-env/SKILL.md +2 -2
  50. package/skills/bravos-env/scope.example.yaml +2 -1
  51. package/skills/bravos-prove/SKILL.md +2 -2
  52. package/skills/bravos-recheck/SKILL.md +1 -1
  53. package/skills/bravos-resync/SKILL.md +1 -1
  54. package/skills/bravos-schedule/SKILL.md +1 -1
  55. package/skills/bravos-ship/SKILL.md +3 -3
  56. package/skills/bravos-templatize/SKILL.md +1 -1
  57. package/templates/review/review.html +1 -1
package/dist/palette.js CHANGED
@@ -39,7 +39,7 @@ export const bgFor = (role) => FIXED[role] ?? null;
39
39
  /* ------------------------------------------------------------------ choosing a theme */
40
40
  /** Where Bravos keeps its own settings: $BRAVOS_HOME, else ~/.bravos. */
41
41
  export const bravosHome = (env = process.env) => env.BRAVOS_HOME || join(env.HOME || homedir(), '.bravos');
42
- /** The theme saved by `bravos start` ($BRAVOS_HOME/config.json), or null. Never throws. */
42
+ /** The theme saved by `bravos setup` ($BRAVOS_HOME/config.json), or null. Never throws. */
43
43
  export function savedTheme(env = process.env) {
44
44
  try {
45
45
  const file = join(bravosHome(env), 'config.json');
@@ -95,6 +95,6 @@ export function resolveTheme(env = process.env, detected = null) {
95
95
  return { theme: fgbg, source: 'COLORFGBG' };
96
96
  const saved = savedTheme(env);
97
97
  if (saved)
98
- return { theme: saved, source: 'saved by bravos start' };
98
+ return { theme: saved, source: 'saved by bravos setup' };
99
99
  return { theme: 'neutral', source: 'default (background unknown)' };
100
100
  }
@@ -195,7 +195,7 @@ Then install the plugin for your agent:
195
195
  | Antigravity | \`agy plugin install ${REPOSITORY}\` |
196
196
  | Cursor (Teams and Enterprise) | Dashboard → Plugins → Import from Repo → \`${REPOSITORY}\` |
197
197
 
198
- You do not need a plugin: \`bravos init\` in a repository installs the same skills,
198
+ You do not need a plugin: \`bravos setup\` in a repository installs the same skills,
199
199
  hooks and MCP wiring for every agent it finds, and commits them with the code.
200
200
 
201
201
  ## Where data goes
@@ -215,7 +215,7 @@ reach only these places:
215
215
 
216
216
  Your licence and machine details go there; your code does not.
217
217
  - **GitHub:** the session briefing uses \`gh\`, if it is installed and signed in, to
218
- list open pull requests in your repository. The CI workflows \`bravos sync --ci\`
218
+ list open pull requests in your repository. The CI workflows \`bravos setup --ci\`
219
219
  writes run on GitHub Actions in your own repository.
220
220
  - **A test target you own:** \`bravos-prove\` and \`bravos-recheck\` send test
221
221
  requests through cxg. Loopback by default; any other host only with a reviewed
package/dist/plugin.js CHANGED
@@ -24,7 +24,7 @@ function walk(dir) {
24
24
  }
25
25
  return out;
26
26
  }
27
- // @comment -- "Every file of both plugin builds, computed and not written. plugin/ (Claude Code): skills rendered with ${CLAUDE_SKILL_DIR} and ${CLAUDE_PLUGIN_ROOT}, the hook scripts, a Claude hooks.json, .mcp.json and .claude-plugin/plugin.json. plugin-codex/ (Codex, Agent Plugins layout): skills rendered with repo-relative .agents/skills paths, the hook scripts, hooks/hooks.json in the shape .codex/hooks.json takes with the command under ${PLUGIN_ROOT}, mcp.json and a root plugin.json. Both register SessionStart only (the pre-PR gate stays opt-in through bravos init) and the guardlink MCP server only. Plus both marketplaces."
27
+ // @comment -- "Every file of both plugin builds, computed and not written. plugin/ (Claude Code): skills rendered with ${CLAUDE_SKILL_DIR} and ${CLAUDE_PLUGIN_ROOT}, the hook scripts, a Claude hooks.json, .mcp.json and .claude-plugin/plugin.json. plugin-codex/ (Codex, Agent Plugins layout): skills rendered with repo-relative .agents/skills paths, the hook scripts, hooks/hooks.json in the shape .codex/hooks.json takes with the command under ${PLUGIN_ROOT}, mcp.json and a root plugin.json. Both register SessionStart only (the pre-PR gate stays opt-in through bravos setup) and the guardlink MCP server only. Plus both marketplaces."
28
28
  export function pluginFiles(opts = {}) {
29
29
  const v = version();
30
30
  const files = [];
@@ -51,12 +51,12 @@ export function pluginFiles(opts = {}) {
51
51
  }],
52
52
  },
53
53
  }));
54
- // Codex substitutes ${PLUGIN_ROOT} in plugin hooks; the group is otherwise the one bravos init writes.
54
+ // Codex substitutes ${PLUGIN_ROOT} in plugin hooks; the group is otherwise the one bravos setup writes.
55
55
  const start = sessionStart('agents');
56
56
  const codexStart = { ...start.group, hooks: start.group.hooks.map((h) => ({ ...h, command: 'node "${PLUGIN_ROOT}/hooks/session-start.mjs" --harness codex' })) };
57
57
  add(`${CODEX_PLUGIN_DIR}/hooks/hooks.json`, json({ hooks: { [start.event]: [codexStart] } }));
58
58
  // guardlink only: cxg and codegraph-mcp are optional, and a server that fails to start on every
59
- // machine without its binary is noise. bravos init adds them per repo when they are installed.
59
+ // machine without its binary is noise. bravos setup adds them per repo when they are installed.
60
60
  const servers = { guardlink: SERVERS.guardlink };
61
61
  add(`${PLUGIN_DIR}/.mcp.json`, json({ mcpServers: servers }));
62
62
  add(`${CODEX_PLUGIN_DIR}/mcp.json`, json({
package/dist/prefs.js ADDED
@@ -0,0 +1,66 @@
1
+ // @comment -- "bravos prefs: a person's standing answers for one clone, read and written through hooks/lib/prefs.mjs so the CLI and the session hook agree on the file and its shape. `prefs get` prints what is recorded; `prefs set commits <commit|leave|ask> --by <name>` records what a named person said about committing Bravos's own files. The file is under the git directory, never in the working tree."
2
+ import { spawnSync } from 'node:child_process';
3
+ import { mkdirSync, writeFileSync } from 'node:fs';
4
+ import { pathToFileURL } from 'node:url';
5
+ import { isAbsolute, join, resolve } from 'node:path';
6
+ import { hooksDir } from './paths.js';
7
+ import { BravosError } from './types.js';
8
+ let cached;
9
+ export const prefsLib = () => (cached ??= import(pathToFileURL(join(hooksDir(), 'lib', 'prefs.mjs')).href));
10
+ const WHAT = {
11
+ commit: "commit Bravos's own files without asking",
12
+ leave: "leave Bravos's own files uncommitted and list them",
13
+ ask: 'ask before the first commit of each session',
14
+ };
15
+ /** What is recorded for this clone, as text or JSON. */
16
+ export async function getPrefs(root, env, json = false) {
17
+ const L = await prefsLib();
18
+ const dir = L.gitCommonDir(root, env);
19
+ if (!dir)
20
+ throw new BravosError(`${root} is not a git repository: preferences are kept under its git directory`);
21
+ const prefs = L.readPrefs(dir);
22
+ if (json)
23
+ return [JSON.stringify({ schema: L.PREFS_SCHEMA, file: L.prefsFile(dir), ...prefs }, null, 2)];
24
+ const c = prefs.commits;
25
+ return [
26
+ c ? `commits: ${c.value} — ${WHAT[c.value]} (${c.by}, ${c.at})` : `commits: not recorded — the agent asks before the first commit of each session`,
27
+ `kept in ${L.prefsFile(dir)} (this clone only; never committed)`,
28
+ ];
29
+ }
30
+ // @comment -- "Records what a named person said about commits. --by is required and never taken from git: the name is the person's own, given when they answered, so an agent cannot record an answer nobody gave without also inventing a name (the skills forbid both)."
31
+ // @mitigates #person-prefs against #governance-forgery using #prefs-outside-tree -- "The answer is written under the git directory with the name of the person who gave it; nothing in a repository's tree can set it."
32
+ export async function setCommits(root, value, by, env, now = new Date()) {
33
+ const L = await prefsLib();
34
+ if (!L.COMMIT_CHOICES.includes(value))
35
+ throw new BravosError(`usage: bravos prefs set commits <${L.COMMIT_CHOICES.join('|')}> --by "<your name>"`);
36
+ if (!by?.trim())
37
+ throw new BravosError('say whose answer this is: --by "<your name>" (it is a person\'s decision; an agent never records one nobody gave)');
38
+ const dir = L.gitCommonDir(root, env);
39
+ if (!dir)
40
+ throw new BravosError(`${root} is not a git repository: preferences are kept under its git directory`);
41
+ let file;
42
+ try {
43
+ file = L.writeCommits(dir, value, by, now.toISOString().slice(0, 10));
44
+ }
45
+ catch (e) {
46
+ throw new BravosError(e instanceof Error ? e.message : String(e));
47
+ }
48
+ return [`commits: ${value} — from now on the agent will ${WHAT[value]}`, `recorded in ${file} (this clone only; never committed)`];
49
+ }
50
+ // @comment -- "Leaves the hand-off marker after a first install, from the install pipeline itself (which is synchronous, so it cannot load the hook library): the same file and shape hooks/lib/prefs.mjs writeHandoff writes and readHandoff reads, under the clone's git directory. It is what makes the next agent session begin the context step by itself, whichever way Bravos was installed: the guided setup, flags from a script, or the website's setup skill. Returns whether it was written; a folder that is not a git repository, or git not answering, only means the person types the first command."
51
+ // @mitigates #person-prefs against #governance-forgery using #prefs-outside-tree -- "The marker is written under the git directory, where no commit, clone or pull can put one."
52
+ export function leaveHandoff(root, env, at = new Date().toISOString()) {
53
+ try {
54
+ const r = spawnSync('git', ['rev-parse', '--git-common-dir'], { cwd: root, env, encoding: 'utf8', timeout: 5000, stdio: ['ignore', 'pipe', 'ignore'] });
55
+ const printed = r.status === 0 ? String(r.stdout ?? '').trim() : '';
56
+ if (!printed)
57
+ return false;
58
+ const dir = join(isAbsolute(printed) ? printed : resolve(root, printed), 'bravos');
59
+ mkdirSync(dir, { recursive: true, mode: 0o700 });
60
+ writeFileSync(join(dir, 'handoff.json'), JSON.stringify({ schema: 'bravos.handoff/v1', at }) + '\n', { mode: 0o600 });
61
+ return true;
62
+ }
63
+ catch {
64
+ return false;
65
+ }
66
+ }
@@ -0,0 +1,76 @@
1
+ // @comment -- "bravos review --wait: lets an agent's command return when the person presses Done on the review page, so nobody has to type 'done' in chat. The page's server is the detached process bravos review already starts; this only remembers which process serves which review (its pid, port and URL, in a 0600 file under the clone's git directory, never in the working tree) and watches for that process to exit. A harness whose commands time out runs the command again: it finds the same server and keeps waiting, so a second page never opens."
2
+ import { chmodSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
3
+ import { join } from 'node:path';
4
+ /** How long one --wait call holds on before it says "still waiting" and returns: under the two-minute limit most agent shells put on a command. */
5
+ export const DEFAULT_WAIT_SECONDS = 90;
6
+ export const MAX_WAIT_SECONDS = 1800;
7
+ // @comment -- "The --wait value: bare --wait is the default, a number is that many seconds within 1 second and the server's own 30-minute idle limit; anything else is refused."
8
+ export function waitSeconds(value) {
9
+ if (value === true || value === undefined)
10
+ return DEFAULT_WAIT_SECONDS;
11
+ const n = Number(value);
12
+ if (!Number.isFinite(n) || n < 1 || n > MAX_WAIT_SECONDS)
13
+ throw new Error(`--wait takes a number of seconds from 1 to ${MAX_WAIT_SECONDS}`);
14
+ return Math.floor(n);
15
+ }
16
+ /** Whether a process with this id is running (signal 0 asks without sending anything). */
17
+ export function alive(pid) {
18
+ if (!Number.isInteger(pid) || pid <= 1)
19
+ return false;
20
+ try {
21
+ process.kill(pid, 0);
22
+ return true;
23
+ }
24
+ catch (e) {
25
+ // EPERM means it exists but is someone else's: not our server.
26
+ return false;
27
+ }
28
+ }
29
+ export const reviewStateFile = (commonDir, kind) => join(commonDir, 'bravos', `review-${kind}.json`);
30
+ // @comment -- "Reads which server is showing this review, and only believes it while that process is running; a record left by a server that has gone is removed."
31
+ export function readLive(commonDir, kind) {
32
+ if (!commonDir)
33
+ return null;
34
+ const file = reviewStateFile(commonDir, kind);
35
+ try {
36
+ const j = JSON.parse(readFileSync(file, 'utf8'));
37
+ if (typeof j.pid === 'number' && typeof j.port === 'number' && typeof j.url === 'string' && /^http:\/\/127\.0\.0\.1:\d+\/\?t=[a-f0-9]+$/.test(j.url) && alive(j.pid))
38
+ return { pid: j.pid, port: j.port, url: j.url };
39
+ }
40
+ catch {
41
+ return null;
42
+ }
43
+ clearLive(commonDir, kind);
44
+ return null;
45
+ }
46
+ export function writeLive(commonDir, kind, live) {
47
+ if (!commonDir)
48
+ return;
49
+ const file = reviewStateFile(commonDir, kind);
50
+ mkdirSync(join(file, '..'), { recursive: true, mode: 0o700 });
51
+ const tmp = `${file}.tmp-${process.pid}`;
52
+ writeFileSync(tmp, JSON.stringify(live) + '\n', { mode: 0o600 });
53
+ try {
54
+ chmodSync(tmp, 0o600);
55
+ }
56
+ catch {
57
+ /* best effort on platforms without modes */
58
+ }
59
+ renameSync(tmp, file);
60
+ }
61
+ export function clearLive(commonDir, kind) {
62
+ if (!commonDir)
63
+ return;
64
+ rmSync(reviewStateFile(commonDir, kind), { force: true });
65
+ }
66
+ /** Resolves true when the process has exited, false when `ms` passed first. Asks the process table only, so the page's idle clock is never reset by the waiting. */
67
+ export async function waitGone(pid, ms, everyMs = 300) {
68
+ const until = Date.now() + ms;
69
+ for (;;) {
70
+ if (!alive(pid))
71
+ return true;
72
+ if (Date.now() >= until)
73
+ return false;
74
+ await new Promise((r) => setTimeout(r, Math.min(everyMs, Math.max(1, until - Date.now()))));
75
+ }
76
+ }
@@ -0,0 +1,37 @@
1
+ // @comment -- "bravos setup is the one command for setting Bravos up: this decides, from the flags a person actually typed and whether there is a terminal, which of its jobs to do. It is a pure function so the whole table can be tested. First match wins: a read-only check; a refusal when machine and repository flags are mixed; the machine part (bundles, tools); the user-level install; the repository part by flags; an unattended first setup; the guided wizard; and otherwise safe upkeep, which is what an agent or a script with no terminal gets. The two meanings -y had on two commands are kept apart here: with a machine flag it means 'run the installers', alone it means 'no questions, take the defaults', and that second route never runs third-party installers."
2
+ /** Flags that say "set up this machine": Bravos's own bundles and the third-party tools. */
3
+ export const MACHINE_FLAGS = ['tools', 'analyzer', 'codegraph'];
4
+ /** Flags that only mean something for a repository, so giving one says "set up (or re-apply to) this repository". */
5
+ export const REPOSITORY_FLAGS = ['agent', 'autopilot', 'prePrHook', 'ci', 'workflows', 'schedule', 'scope', 'linkSkills', 'force', 'guardlinkMode', 'guardlinkInit'];
6
+ // @comment -- "`given` holds the option names typed on the command line (commander's value source 'cli'), never defaults: --no-guardlink-init defaults to true, so truthiness would read it as given every time."
7
+ export function setupRoute(given, tty) {
8
+ const has = (k) => given.has(k);
9
+ const machine = MACHINE_FLAGS.some(has);
10
+ const repository = REPOSITORY_FLAGS.some(has);
11
+ if (has('check'))
12
+ return 'check';
13
+ if (machine && (repository || has('global') || has('change') || has('preset')))
14
+ return 'conflict';
15
+ if (machine)
16
+ return 'machine';
17
+ if (has('global'))
18
+ return 'global';
19
+ if (repository)
20
+ return 'repository';
21
+ if (has('yes'))
22
+ return 'unattended';
23
+ if (has('change') || has('preset'))
24
+ return tty ? 'wizard' : 'needs-terminal';
25
+ // A dry run is a preview, never a wizard: it shows what upkeep would do.
26
+ if (tty && !has('dryRun'))
27
+ return 'wizard';
28
+ return 'upkeep';
29
+ }
30
+ // @comment -- "Whether a person is at a terminal. An agent's shell is not one even when it is given a pseudo-terminal: Claude Code sets CLAUDECODE, and CI sets CI. Tests pass `tty` directly, because a test runner has no terminal."
31
+ export function isTerminal(io, streams = process) {
32
+ if (typeof io.tty === 'boolean')
33
+ return io.tty;
34
+ if (io.env.CLAUDECODE || io.env.CI)
35
+ return false;
36
+ return !!streams.stdout?.isTTY && !!streams.stdin?.isTTY;
37
+ }
package/dist/setup.js CHANGED
@@ -67,7 +67,8 @@ export async function runSetup(env, opts, io) {
67
67
  // "already staged" would leave an existing install on the old one for good.
68
68
  const older = behindPin(env, kind);
69
69
  if (have && !opts.yes && !older) {
70
- lines.push(`${kind}: already staged at ${have} (add -y to fetch ${VERSIONS[kind]} again)`);
70
+ // The hint names the bundle: -y on its own is the unattended setup now, not a refetch.
71
+ lines.push(`${kind}: already staged at ${have} (bravos setup --${kind} -y fetches ${VERSIONS[kind]} again)`);
71
72
  continue;
72
73
  }
73
74
  if (opts.dryRun) {
@@ -153,7 +154,7 @@ export async function runSast(root, env, opts = {}) {
153
154
  const a = ['analyze', root, '--ci', '--fail-on', 'never', '--allow-incomplete-analysis', '--codegraph', graph, '--scip', opts.scip ?? 'off', '-f', 'json,sarif', '-o', join(runDir, 'report')];
154
155
  if (opts.scope?.length)
155
156
  a.push('--scope', opts.scope.join(','));
156
- // @comment -- ".bravos/ is always excluded: it holds the hooks bravos init copied into the repository and the SAST runs themselves, which are bravos's code, not the customer's, and would otherwise surface as findings 'not in the threat model'."
157
+ // @comment -- ".bravos/ is always excluded: it holds the hooks bravos setup copied into the repository and the SAST runs themselves, which are bravos's code, not the customer's, and would otherwise surface as findings 'not in the threat model'."
157
158
  a.push('--exclude', ['.bravos', ...(opts.exclude ?? []).filter((p) => p !== '.bravos')].join(','));
158
159
  if (opts.minSeverity)
159
160
  a.push('--min-severity', opts.minSeverity);
package/dist/skills.js CHANGED
@@ -100,7 +100,7 @@ export function renderPortableSkillFile(content, rel = 'SKILL.md') {
100
100
  }
101
101
  return out;
102
102
  }
103
- // @comment -- "User-level render (bravos init --global): bravos's own paths become absolute under the home folder (skills in ~/.claude/skills, hook scripts in ~/.bravos/hooks), while {{SKILLS_ROOT}} for guardlink's generated skills stays at the repo's .claude/skills."
103
+ // @comment -- "User-level render (bravos setup --global): bravos's own paths become absolute under the home folder (skills in ~/.claude/skills, hook scripts in ~/.bravos/hooks), while {{SKILLS_ROOT}} for guardlink's generated skills stays at the repo's .claude/skills."
104
104
  export function renderGlobalSkillFile(home) {
105
105
  return (content, _harness, name, rel = 'SKILL.md') => withMarker(content, rel)
106
106
  .split('{{SKILL_DIR}}')
@@ -1,14 +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
- pr: { label: 'Map threats and check every pull request', hint: 'no AI key needed', pr: 'hook+github', autopilot: false, schedule: 'none', proving: 'ask' },
7
- everything: { label: 'Everything: annotations, PR checks and scheduled testing', hint: 'weekly nightly run, autopilot on', pr: 'hook+github', autopilot: true, schedule: 'weekly', proving: 'ask' },
6
+ // @comment -- "Autopilot is on for the pr preset in the preset itself, so bravos setup --yes and the interactive default agree."
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
+ // @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
+ 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' },
8
10
  };
9
11
  /** Pricing for optional CXG model generation. */
10
12
  export const PENTEST_COST_URL = 'https://bugb.io/pricing#pentest-cost';
11
- /** 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). */
12
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"
13
15
  export function initArgs(a) {
14
16
  const args = ['init', a.repo, '--agent', a.agents.join(',')];
@@ -39,14 +41,15 @@ export function provingText(a, date) {
39
41
  return [
40
42
  '# How findings are proven',
41
43
  '',
42
- '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.',
43
45
  '',
44
46
  `choice: ${a.proving}`,
45
47
  ...(a.proving === 'auto' ? [`kits: ${a.kitPolicy ?? 'reviewed'}`] : []),
48
+ ...(a.proving === 'auto' && a.target ? [`target: ${a.target}`] : []),
46
49
  `generation: ${a.generation ? 'yes' : 'no'}`,
47
50
  '',
48
51
  // Automatic tests need the one local app they may contact; the agent finds it (bravos-env) and a person merges it.
49
- ...(a.proving === 'auto' ? ['Automatic tests start once a `target: http://localhost:<port>/` line naming your local app is added here and merged to the default branch (bravos-env does this with you).', ''] : []),
52
+ ...(a.proving === 'auto' && !a.target ? ['Automatic tests start once a `target: http://localhost:<port>/` line naming your local app is added here and merged to the default branch (bravos-env does this with you).', ''] : []),
50
53
  JSON.stringify(a.words.trim()),
51
54
  '',
52
55
  `— confirmed by ${a.name.trim()}, ${date}`,
@@ -67,7 +70,8 @@ export function readAnswers(root) {
67
70
  export function writeAnswers(root, a, version, at) {
68
71
  const p = join(root, SETUP_FILE);
69
72
  mkdirSync(dirname(p), { recursive: true });
70
- const { words: _w, name: _n, ...kept } = a;
73
+ // @comment -- "setup.json is committed for the team, so it holds only repository-level answers: never the absolute path of the first person's checkout, their terminal theme or what their machine was missing."
74
+ const { words: _w, name: _n, repo: _r, theme: _t, installTools: _i, ...kept } = a;
71
75
  writeFileSync(p, JSON.stringify({ schema: 'bravos.start/v1', bravos_version: version, at, answers: kept }, null, 2) + '\n');
72
76
  }
73
77
  /** Saves the colour theme in $BRAVOS_HOME/config.json, keeping anything else in it. */
@@ -85,3 +89,28 @@ export function writeTheme(home, theme) {
85
89
  writeFileSync(p, JSON.stringify({ ...cfg, theme }, null, 2) + '\n');
86
90
  return p;
87
91
  }
92
+ // @comment -- "Checks the optional local app URL the wizard asks for, by the same rules replay enforces for an automatic run (hooks/lib/replay.mjs): http or https, a loopback host, no credentials, query or fragment. Empty is fine: the agent finds the target later. Returns the problem in words, or undefined."
93
+ // @mitigates #replay-target against #out-of-scope-replay using #loopback-only-scope -- "A target recorded by setup can only be the person's own loopback app; replay checks it again before every run."
94
+ export function targetProblem(value) {
95
+ const v = value.trim();
96
+ if (!v)
97
+ return undefined;
98
+ let url;
99
+ try {
100
+ url = new URL(v);
101
+ }
102
+ catch {
103
+ return 'A full address, please, like http://localhost:3000';
104
+ }
105
+ if (!['http:', 'https:'].includes(url.protocol))
106
+ return 'It must start with http:// or https://';
107
+ if (!['localhost', '127.0.0.1', '[::1]'].includes(url.hostname))
108
+ return 'Only an app on this machine: localhost, 127.0.0.1 or [::1]';
109
+ if (url.username || url.password)
110
+ return 'No user name or password in the address';
111
+ if (url.search || url.hash)
112
+ return 'No ? or # part: just where the app listens';
113
+ return undefined;
114
+ }
115
+ /** The target as replay compares it (URL.href), or undefined when none was given. */
116
+ export const normalTarget = (value) => (value?.trim() ? new URL(value.trim()).href : undefined);