@bugb-technologies/bravos 1.1.0 → 1.2.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.
- package/README.md +7 -4
- package/dist/ci.js +14 -1
- package/dist/cli.js +92 -6
- package/dist/doctor.js +3 -0
- package/dist/guide.js +2 -2
- package/dist/help.js +8 -1
- package/dist/palette.js +100 -0
- package/dist/plugin-release.js +13 -6
- package/dist/start/answers.js +82 -0
- package/dist/start/index.js +442 -0
- package/dist/start/repos.js +78 -0
- package/dist/start/ui.js +219 -0
- package/dist/watch-frame.js +28 -16
- package/dist/watch.js +40 -1
- package/docs/GUIDE.md +5 -1
- package/hooks/lib/briefing.mjs +12 -12
- package/hooks/lib/palette.mjs +115 -0
- package/hooks/session-start.mjs +4 -1
- package/package.json +3 -1
- package/templates/omp/bravos.js +5 -0
package/README.md
CHANGED
|
@@ -10,7 +10,9 @@ npm install -g @bugb-technologies/bravos
|
|
|
10
10
|
|
|
11
11
|
The command it installs is `bravos`.
|
|
12
12
|
|
|
13
|
-
Then
|
|
13
|
+
Then run **`bravos start`**: a guided setup that asks one question at a time (terminal colours, licence, tools, which repository, which AI tools, pull-request checks, a daily or weekly scheduled run in GitHub Actions, and how testing is allowed), shows every change and the equivalent `bravos init` command, and writes nothing until you choose Apply. It ends by telling you the one thing to type in your agent (`/bravos-context`, then `/bravos-annotate`); Bravos never starts an agent itself. `bravos start --again` re-asks with your previous answers selected; `bravos start --yes --preset pr <dir>` takes every default in a script (it never records a testing permission on your behalf).
|
|
14
|
+
|
|
15
|
+
By hand instead, in order: `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 this 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). Node 20 or newer; guardlink and cxg are installed by `bravos setup --tools -y` or by hand.
|
|
14
16
|
|
|
15
17
|
**Used the Python `bravos` before?** Its `bravos` command usually sits in `~/.local/bin`, which most shells search before npm's folder, so it would still answer when you type `bravos`. Keep it under another name, and this CLI keeps using its code graph and analyzer until `bravos setup` installs its own:
|
|
16
18
|
|
|
@@ -22,7 +24,8 @@ Or remove it (`pipx uninstall bravos` or `uv tool uninstall bravos`). `which -a
|
|
|
22
24
|
|
|
23
25
|
## Commands
|
|
24
26
|
|
|
25
|
-
- `bravos
|
|
27
|
+
- `bravos start [dir]`: the guided first run described above. `--again`, `--yes`, `--preset annotate|pr|everything`.
|
|
28
|
+
- `bravos init`: write skills, MCP wiring and the session-start hook into the current repo. `--agent claude,codex` picks the harnesses instead of detecting them. `--pre-pr-hook` also registers the PreToolUse gate on `gh pr create` / `gh pr ready` and lists it under `pre_pr` in `.guardlink/config.json`, so guardlink's agent block names it after `guardlink sync`; `--ci` also writes the GitHub Actions workflows (`--workflows pr-gate,nightly-claude,nightly-codex` picks which, `--schedule weekday|daily|weekly` sets how often the nightly runs; either implies `--ci`); `--scope` writes the loopback-only cxg scope starter to `.guardlink/scope.yaml` when no scope file exists (never overwritten). A repo with a `.cursor/` folder also gets `.cursor/rules/bravos.mdc`, a pointer to the skills.
|
|
26
29
|
- `bravos sync`: refresh the installed skills and wiring to match this version of bravos; it also adds the cxg and codegraph MCP servers once they are installed (bravos's own committed MCP config carries guardlink only). The codegraph server is registered by its full path with the graph store as `BRAVOS_CODEGRAPH_DIR`, so the MCP tools read the graphs `bravos graph build` writes; after a `bravos setup` that stages a new bundle, `sync` refreshes that one entry, and keeps every other existing entry as it is.
|
|
27
30
|
- `bravos setup`: puts the binaries bravos drives on this machine. The analyzer (`bravos-cli`, SAST) and the code graph (`codegraph-build`, `codegraph-mcp`) are signed bundles fetched through the account portal on the Team plan — the portal verifies the licence, the CLI verifies each file's Ed25519 signature before it unpacks, and nothing under `$BRAVOS_HOME` changes until every check has passed; `--tools -y` also installs guardlink (npm) and cxg (cargo). `--check` reports, `--dry-run` says what would happen.
|
|
28
31
|
- `bravos graph`: `graph build [DIR]` indexes a repository (`--scip no-exec` by default, so no repository code runs); `graph <question> [args] --json` asks it — the same answers as the `codegraph_` MCP tools, through a one-call MCP session on stdio; `graph --json` lists every question this machine's binary answers.
|
|
@@ -161,7 +164,7 @@ How new exposures get proven is the team's call, not a fixed rule. The first tim
|
|
|
161
164
|
|
|
162
165
|
It redraws within a couple of seconds of a file change (`fs.watch`, debounced; one snapshot at a time), re-reads boundaries, the model's size and PRs every `--interval` seconds (default 60), and asks the code graph again every `--graph-interval` seconds (default 300). Read-only and free: no model, nothing written to the repo. Autopilot logs each nudge to `.bravos/watch/events.jsonl`, a local log with its own `.gitignore`, capped at 500 lines.
|
|
163
166
|
|
|
164
|
-
Three columns from 150 wide, two from 110, one column from 80 (a split pane), a compact list below that (`--compact` forces it); the panels scroll when the terminal is shorter than they are. Keys: `n` copies the next command, `r` opens the intent review page, `d` writes guardlink's dashboard to a temp file and opens it, `g` asks the code graph a question (`bravos graph <q>`), `t` shows test-next and stale claims in full, `i` shows the recorded intent (`.guardlink/intent.md`, with who answered the review), `u` refreshes everything now, `j`/`k` (or the arrows, space, `G`) scroll, `?` the guide, `q` quits. Overlays (`t`, `i`, `?`, a graph answer) wrap to the terminal and scroll with the same keys; any other key closes them. `--once` prints one frame (and is what happens when stdout is not a terminal), `--json` one snapshot (`bravos.watch/v1`). `NO_COLOR` or `BRAVOS_WATCH_COLOR=off` prints it plain.
|
|
167
|
+
Three columns from 150 wide, two from 110, one column from 80 (a split pane), a compact list below that (`--compact` forces it); the panels scroll when the terminal is shorter than they are. Keys: `n` copies the next command, `r` opens the intent review page, `d` writes guardlink's dashboard to a temp file and opens it, `g` asks the code graph a question (`bravos graph <q>`), `t` shows test-next and stale claims in full, `i` shows the recorded intent (`.guardlink/intent.md`, with who answered the review), `u` refreshes everything now, `j`/`k` (or the arrows, space, `G`) scroll, `?` the guide, `q` quits. Overlays (`t`, `i`, `?`, a graph answer) wrap to the terminal and scroll with the same keys; any other key closes them. `--once` prints one frame (and is what happens when stdout is not a terminal), `--json` one snapshot (`bravos.watch/v1`). `c` switches the colours between dark, light and neutral. `NO_COLOR` or `BRAVOS_WATCH_COLOR=off` prints it plain; on a live terminal bravos asks it for its background colour and picks the light or dark palette (see `BRAVOS_THEME` below).
|
|
165
168
|
|
|
166
169
|
## Getting started: `bravos next`
|
|
167
170
|
|
|
@@ -173,7 +176,7 @@ Three columns from 150 wide, two from 110, one column from 80 (a split pane), a
|
|
|
173
176
|
|
|
174
177
|
## Session start: a briefing for the model, a banner for you
|
|
175
178
|
|
|
176
|
-
The session-start hook prints one JSON object. Its `additionalContext` is the briefing: open exposures by severity, coverage, confirmed findings, what to test next, stale claims, tickets, work in flight and the intent state, sent to the model on every start, resume, clear and compact. On a fresh start only (`source: startup`, or a manual run), its `systemMessage` carries a banner for the human, which the model does not see: the bravos logo, repo and branch, the counts, the top three threats (or the confirmed findings to fix now) beside a three-step quick start chosen from the repo's state, and a short introduction to bravos while `.guardlink/intent.md` is missing. It is plain text within 80 columns. The registered command carries `--harness claude` or `--harness codex` so the quick start prints `/bravos-…` or `$bravos-…`; `bravos sync` replaces the older entry without the flag, and Codex asks you to trust the changed hook once in `/hooks`. Set `BRAVOS_BANNER=off` to hide the banner; the briefing is unchanged. The banner is drawn in bravos's brand colours; `NO_COLOR` or `BRAVOS_BANNER_COLOR=off` prints it plain. Codex lists a hook's message as a warning (behind F2), so Codex gets a two-line summary instead of the art. opencode finds the skills through its skill tool but lists only its own `/commands` and runs no hooks, so when opencode is in use (`.opencode/`, `opencode.json`, or `opencode` on PATH) bravos also writes one `.opencode/commands/<skill>.md` per skill (so `/bravos`, `/bravos-ship` and the rest appear), `.opencode/plugins/bravos.js` (an opencode 2.x plugin that adds the briefing to the system prompt of each request), and guardlink under `mcp` in `opencode.json`. Antigravity (`agy`) reads `.agents/hooks.json`; bravos adds a `bravos` SessionStart group there that hands the briefing to the model, since Antigravity documents no way for a hook to show text to you.
|
|
179
|
+
The session-start hook prints one JSON object. Its `additionalContext` is the briefing: open exposures by severity, coverage, confirmed findings, what to test next, stale claims, tickets, work in flight and the intent state, sent to the model on every start, resume, clear and compact. On a fresh start only (`source: startup`, or a manual run), its `systemMessage` carries a banner for the human, which the model does not see: the bravos logo, repo and branch, the counts, the top three threats (or the confirmed findings to fix now) beside a three-step quick start chosen from the repo's state, and a short introduction to bravos while `.guardlink/intent.md` is missing. It is plain text within 80 columns. The registered command carries `--harness claude` or `--harness codex` so the quick start prints `/bravos-…` or `$bravos-…`; `bravos sync` replaces the older entry without the flag, and Codex asks you to trust the changed hook once in `/hooks`. Set `BRAVOS_BANNER=off` to hide the banner; the briefing is unchanged. The banner is drawn in bravos's brand colours; `NO_COLOR` or `BRAVOS_BANNER_COLOR=off` prints it plain. Colours follow the terminal's background: `BRAVOS_THEME=light|dark|neutral` picks them, otherwise `COLORFGBG`, the choice saved by `bravos start`, then `neutral`, whose colours read on light and dark backgrounds alike (`bravos doctor` says which and why). Codex lists a hook's message as a warning (behind F2), so Codex gets a two-line summary instead of the art. opencode finds the skills through its skill tool but lists only its own `/commands` and runs no hooks, so when opencode is in use (`.opencode/`, `opencode.json`, or `opencode` on PATH) bravos also writes one `.opencode/commands/<skill>.md` per skill (so `/bravos`, `/bravos-ship` and the rest appear), `.opencode/plugins/bravos.js` (an opencode 2.x plugin that adds the briefing to the system prompt of each request), and guardlink under `mcp` in `opencode.json`. Antigravity (`agy`) reads `.agents/hooks.json`; bravos adds a `bravos` SessionStart group there that hands the briefing to the model, since Antigravity documents no way for a hook to show text to you.
|
|
177
180
|
|
|
178
181
|
omp runs neither Claude Code's nor Codex's hooks, so when omp is in use (a `.omp/` folder, or `omp` on PATH) `bravos init` and `sync` also write `.omp/extensions/bravos.js`, which omp loads by itself: it shows the same banner above the editor at session start and hands the briefing to the model, hidden, with the first prompt. In none of these harnesses do you need to type a command for the briefing; `/bravos` is for deciding the next step. Anywhere else, the bravos skill runs `node .bravos/hooks/session-start.mjs --briefing`, which prints the briefing as plain text.
|
|
179
182
|
|
package/dist/ci.js
CHANGED
|
@@ -4,7 +4,17 @@ import { readLock, sha256, writeLock } from './lock.js';
|
|
|
4
4
|
import { templatesDir } from './paths.js';
|
|
5
5
|
// @comment -- "Token every bravos workflow carries in its first line, so an unlocked workflow can still be recognised as bravos-managed."
|
|
6
6
|
export const WORKFLOW_MARKER = 'bravos:generated';
|
|
7
|
+
export const CADENCES = ['weekday', 'daily', 'weekly'];
|
|
8
|
+
// 03:17 UTC, off the hour so it does not land with everyone else's cron.
|
|
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. */
|
|
11
|
+
export const WORKFLOW_NAMES = ['pr-gate', 'nightly-claude', 'nightly-codex'];
|
|
12
|
+
/** The template with its schedule line set to the cadence; any other file is unchanged. */
|
|
13
|
+
export function withCadence(content, cadence) {
|
|
14
|
+
return content.replace(/^(\s*- cron: )'[^']*'/m, `$1'${CRON[cadence]}'`);
|
|
15
|
+
}
|
|
7
16
|
// @comment -- "Copies each bundled templates/workflows/*.yml into .github/workflows/; an existing workflow is replaced only if bravos wrote it (lock hash or marker) unless --force, and the lock records each file written."
|
|
17
|
+
// @comment -- "Only the workflows named in `only` (all when absent) are written; `cadence` rewrites the nightly's cron line before the file is hashed and locked, so a re-sync with the same cadence finds it unchanged"
|
|
8
18
|
export function writeWorkflows(root, opts = {}) {
|
|
9
19
|
const src = join(opts.templates ?? templatesDir(), 'workflows');
|
|
10
20
|
const report = { written: [], updated: [], unchanged: [], skipped: [] };
|
|
@@ -13,9 +23,12 @@ export function writeWorkflows(root, opts = {}) {
|
|
|
13
23
|
const lock = readLock(root);
|
|
14
24
|
const record = {};
|
|
15
25
|
for (const name of readdirSync(src).filter((n) => n.endsWith('.yml')).sort()) {
|
|
26
|
+
if (opts.only && !opts.only.some((w) => name === `bravos-${w}.yml`))
|
|
27
|
+
continue;
|
|
16
28
|
const path = `.github/workflows/${name}`;
|
|
17
29
|
const abs = join(root, path);
|
|
18
|
-
const
|
|
30
|
+
const raw = readFileSync(join(src, name), 'utf8');
|
|
31
|
+
const content = Buffer.from(opts.cadence && name.startsWith('bravos-nightly-') ? withCadence(raw, opts.cadence) : raw);
|
|
19
32
|
const hash = sha256(content);
|
|
20
33
|
let status = 'written';
|
|
21
34
|
if (existsSync(abs)) {
|
package/dist/cli.js
CHANGED
|
@@ -5,7 +5,7 @@ import { resolve, join } from 'node:path';
|
|
|
5
5
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
6
6
|
import { DOCTOR_HELP, INIT_HELP, PROGRAM_HELP, SYNC_HELP } from './help.js';
|
|
7
7
|
import { Command, CommanderError, InvalidArgumentError, Option } from 'commander';
|
|
8
|
-
import { writeWorkflows } from './ci.js';
|
|
8
|
+
import { CADENCES, CRON, WORKFLOW_NAMES, writeWorkflows } from './ci.js';
|
|
9
9
|
import { writeCursorPointer } from './cursor.js';
|
|
10
10
|
import { writeOmpExtension } from './omp.js';
|
|
11
11
|
import { homeOf, installGlobal } from './global.js';
|
|
@@ -33,6 +33,17 @@ import { readLock, sha256, writeLock } from './lock.js';
|
|
|
33
33
|
import { mergeCodexConfig, mergeMcpJson, selectServers } from './mcp.js';
|
|
34
34
|
import { hooksDir, skillsDir as bundledSkillsDir, version } from './paths.js';
|
|
35
35
|
import { BravosError } from './types.js';
|
|
36
|
+
// @comment -- "Parses --workflows pr-gate,nightly-claude,nightly-codex; anything else is a usage error"
|
|
37
|
+
function parseWorkflows(value) {
|
|
38
|
+
const out = [];
|
|
39
|
+
for (const raw of value.split(',').map((x) => x.trim()).filter(Boolean)) {
|
|
40
|
+
if (!WORKFLOW_NAMES.includes(raw))
|
|
41
|
+
throw new InvalidArgumentError(`unknown workflow '${raw}' (expected ${WORKFLOW_NAMES.join(', ')})`);
|
|
42
|
+
if (!out.includes(raw))
|
|
43
|
+
out.push(raw);
|
|
44
|
+
}
|
|
45
|
+
return out;
|
|
46
|
+
}
|
|
36
47
|
const GUARDLINK_HINT = 'guardlink: not found on PATH — npm install -g guardlink';
|
|
37
48
|
// Antigravity reads the shared .agents/ root; opencode and omp get their own files on top of a skills root.
|
|
38
49
|
const AGENT_MAP = { claude: 'claude', codex: 'agents', agy: 'agents', opencode: 'opencode', omp: 'omp' };
|
|
@@ -230,8 +241,10 @@ function pipeline(root, io, opts, withGuardlink, lines) {
|
|
|
230
241
|
lines.push(`MCP deferred: ${d} — ${tools.find((t) => t.name === bin[d])?.hint ?? ''}`);
|
|
231
242
|
}
|
|
232
243
|
let workflowWritten = [];
|
|
233
|
-
if (opts.ci) {
|
|
234
|
-
const wf = writeWorkflows(root, { force: opts.force, dryRun });
|
|
244
|
+
if (opts.ci || opts.workflows || opts.schedule) {
|
|
245
|
+
const wf = writeWorkflows(root, { force: opts.force, dryRun, only: opts.workflows, cadence: opts.schedule });
|
|
246
|
+
if (opts.schedule)
|
|
247
|
+
lines.push(`Nightly schedule: ${opts.schedule} (cron ${CRON[opts.schedule]}, UTC)`);
|
|
235
248
|
lines.push(`Workflows: ${wf.written.length} written, ${wf.updated.length} updated, ${wf.unchanged.length} unchanged, ${wf.skipped.length} skipped`);
|
|
236
249
|
for (const s of wf.skipped)
|
|
237
250
|
lines.push(` skipped ${s.path} — ${s.reason}`);
|
|
@@ -320,7 +333,7 @@ export function buildProgram(io, result) {
|
|
|
320
333
|
const flags = [
|
|
321
334
|
[opts.autopilot, 'pre-pr', `bravos ${cmd} --autopilot`],
|
|
322
335
|
[opts.prePrHook, 'pre-pr', `bravos ${cmd} --pre-pr-hook`],
|
|
323
|
-
[opts.ci, 'ci', `bravos ${cmd} --ci`],
|
|
336
|
+
[opts.ci || !!opts.workflows || !!opts.schedule, 'ci', `bravos ${cmd} --ci`],
|
|
324
337
|
];
|
|
325
338
|
for (const [on, feature, what] of flags)
|
|
326
339
|
if (on)
|
|
@@ -353,6 +366,8 @@ export function buildProgram(io, result) {
|
|
|
353
366
|
.option('--force', 'overwrite edited or authored skill files')
|
|
354
367
|
.option('--pre-pr-hook', 'also register the PreToolUse gate that checks gh pr create / gh pr ready')
|
|
355
368
|
.option('--ci', 'also write the PR gate and nightly GitHub Actions workflows into .github/workflows/')
|
|
369
|
+
.option('--workflows <list>', `which workflows --ci writes: ${WORKFLOW_NAMES.join(',')} (implies --ci)`, parseWorkflows)
|
|
370
|
+
.addOption(new Option('--schedule <cadence>', 'how often the nightly workflow runs (implies --ci)').choices(CADENCES))
|
|
356
371
|
.option('--scope', 'also write the loopback-only cxg scope starter to .guardlink/scope.yaml when absent')
|
|
357
372
|
.option('--link-skills', 'make .agents/skills a link to .claude/skills so each skill exists once')
|
|
358
373
|
.option('--global', 'install for your user (home folder) instead of a repository')
|
|
@@ -373,6 +388,8 @@ export function buildProgram(io, result) {
|
|
|
373
388
|
.option('--force', 'overwrite edited or authored skill files')
|
|
374
389
|
.option('--pre-pr-hook', 'also register the PreToolUse gate that checks gh pr create / gh pr ready')
|
|
375
390
|
.option('--ci', 'also write the PR gate and nightly GitHub Actions workflows into .github/workflows/')
|
|
391
|
+
.option('--workflows <list>', `which workflows --ci writes: ${WORKFLOW_NAMES.join(',')} (implies --ci)`, parseWorkflows)
|
|
392
|
+
.addOption(new Option('--schedule <cadence>', 'how often the nightly workflow runs (implies --ci)').choices(CADENCES))
|
|
376
393
|
.option('--scope', 'also write the loopback-only cxg scope starter to .guardlink/scope.yaml when absent')
|
|
377
394
|
.option('--link-skills', 'make .agents/skills a link to .claude/skills so each skill exists once')
|
|
378
395
|
.option('--global', 'install for your user (home folder) instead of a repository')
|
|
@@ -526,6 +543,67 @@ export function buildProgram(io, result) {
|
|
|
526
543
|
io.stderr(r.stderr.replace(/\n$/, ''));
|
|
527
544
|
result.code = r.status ?? 1;
|
|
528
545
|
}));
|
|
546
|
+
// @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."
|
|
547
|
+
program
|
|
548
|
+
.command('start [dir]')
|
|
549
|
+
.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.')
|
|
550
|
+
.option('--again', 'ask again, with your previous answers selected')
|
|
551
|
+
.option('-y, --yes', 'no questions: take every default (testing permission stays unrecorded)')
|
|
552
|
+
.addOption(new Option('--preset <name>', 'starting point').choices(['annotate', 'pr', 'everything']))
|
|
553
|
+
.action((dir, opts) => guardedAsync(async () => {
|
|
554
|
+
const { runStart } = await import('./start/index.js');
|
|
555
|
+
const ui = await import('./start/ui.js');
|
|
556
|
+
const { plan: startPlan } = await import('./setup.js');
|
|
557
|
+
const { licenceStatus } = await import('./licence.js');
|
|
558
|
+
const { bravosHome } = await import('./palette.js');
|
|
559
|
+
const interactive = !opts.yes && !!process.stdout.isTTY && !!process.stdin.isTTY;
|
|
560
|
+
if (!opts.yes && !interactive)
|
|
561
|
+
throw new BravosError('bravos start asks questions, so it needs a terminal. In a script use: bravos start --yes --preset pr <dir>');
|
|
562
|
+
const prompter = interactive ? ui.terminalPrompter() : ui.scriptedPrompter({}, io.stdout);
|
|
563
|
+
const capture = async (argv) => {
|
|
564
|
+
const out = [];
|
|
565
|
+
const err = [];
|
|
566
|
+
const code = await run(argv, { ...io, stdout: (x) => out.push(x), stderr: (x) => err.push(x) });
|
|
567
|
+
return { code, out, err };
|
|
568
|
+
};
|
|
569
|
+
result.code = await runStart({ dir, again: opts.again, yes: opts.yes, preset: opts.preset }, {
|
|
570
|
+
prompter,
|
|
571
|
+
env: io.env,
|
|
572
|
+
cwd: process.cwd(),
|
|
573
|
+
version: version(),
|
|
574
|
+
home: bravosHome(io.env),
|
|
575
|
+
bravos: capture,
|
|
576
|
+
exec: (cmd, args, o = {}) => {
|
|
577
|
+
const r = spawnSync(cmd, args, { cwd: o.cwd, env: io.env, input: o.input, encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'], timeout: 60000 });
|
|
578
|
+
return { code: r.status ?? 1, out: String(r.stdout ?? '') };
|
|
579
|
+
},
|
|
580
|
+
// @comment -- "A bravos command run as a child of this same node and cli.js, no shell, output captured: the code graph build runs this way so the spinner keeps moving while it works"
|
|
581
|
+
bravosChild: (argv) => new Promise((done) => {
|
|
582
|
+
const child = spawnChild(process.execPath, [fileURLToPath(import.meta.url), ...argv], { env: io.env, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
583
|
+
let out = '';
|
|
584
|
+
let err = '';
|
|
585
|
+
child.stdout.on('data', (b) => (out += b));
|
|
586
|
+
child.stderr.on('data', (b) => (err += b));
|
|
587
|
+
child.on('error', (e) => done({ code: 1, out, err: err || e.message }));
|
|
588
|
+
child.on('close', (code) => done({ code: code ?? 1, out, err }));
|
|
589
|
+
}),
|
|
590
|
+
which: (bin) => whichBin(bin, io.env),
|
|
591
|
+
licence: () => licenceStatus(io.env),
|
|
592
|
+
setupPlan: () => startPlan(io.env),
|
|
593
|
+
activate: () => activate({ env: io.env, stdout: io.stdout }),
|
|
594
|
+
clipboard: (text) => {
|
|
595
|
+
const tools = process.platform === 'darwin' ? [['pbcopy', []]] : [['wl-copy', []], ['xclip', ['-selection', 'clipboard']], ['xsel', ['--clipboard', '--input']]];
|
|
596
|
+
for (const [bin, args] of tools) {
|
|
597
|
+
if (!whichBin(bin, io.env))
|
|
598
|
+
continue;
|
|
599
|
+
if (spawnSync(bin, args, { input: text, stdio: ['pipe', 'ignore', 'ignore'] }).status === 0)
|
|
600
|
+
return true;
|
|
601
|
+
}
|
|
602
|
+
return false;
|
|
603
|
+
},
|
|
604
|
+
today: () => new Date().toISOString().slice(0, 10),
|
|
605
|
+
});
|
|
606
|
+
}));
|
|
529
607
|
program
|
|
530
608
|
.command('doctor [dir]')
|
|
531
609
|
.description('Read-only check of the tools, licence, skills and hooks bravos relies on.')
|
|
@@ -641,8 +719,13 @@ export function buildProgram(io, result) {
|
|
|
641
719
|
const watch = await import('./watch.js');
|
|
642
720
|
const color = !io.env.NO_COLOR && io.env.BRAVOS_WATCH_COLOR !== 'off';
|
|
643
721
|
const live = !opts.once && !opts.json && process.stdout.isTTY && process.stdin.isTTY;
|
|
722
|
+
const { resolveTheme } = await import('./palette.js');
|
|
644
723
|
if (live) {
|
|
645
|
-
|
|
724
|
+
// Ask the terminal for its background only when nothing stronger has decided the theme.
|
|
725
|
+
const first = resolveTheme(io.env);
|
|
726
|
+
const detected = color && first.source.startsWith('default') ? await watch.queryBackground() : null;
|
|
727
|
+
const { theme } = resolveTheme(io.env, detected);
|
|
728
|
+
await watch.runWatch(root, io.env, { intervalSec: opts.interval, graphIntervalSec: opts.graphInterval, color, compact: !!opts.compact, theme });
|
|
646
729
|
return;
|
|
647
730
|
}
|
|
648
731
|
const sn = await watch.snapshot(root, io.env, { refreshGraph: true, refreshSlow: true });
|
|
@@ -652,7 +735,7 @@ export function buildProgram(io, result) {
|
|
|
652
735
|
}
|
|
653
736
|
const width = Number(io.env.COLUMNS) || process.stdout.columns || 100;
|
|
654
737
|
const events = watch.readAutopilotEvents(root).slice(-8);
|
|
655
|
-
lines.push(watch.buildFrame(sn, events, { width, color: color && !!process.stdout.isTTY, status: 'once', compact: !!opts.compact }));
|
|
738
|
+
lines.push(watch.buildFrame(sn, events, { width, color: color && !!process.stdout.isTTY, theme: resolveTheme(io.env).theme, status: 'once', compact: !!opts.compact }));
|
|
656
739
|
}));
|
|
657
740
|
program
|
|
658
741
|
.command('workspace <action> [args...]')
|
|
@@ -977,6 +1060,9 @@ export async function run(argv, io = {}) {
|
|
|
977
1060
|
...io,
|
|
978
1061
|
};
|
|
979
1062
|
const result = { code: 0 };
|
|
1063
|
+
// @comment -- "Bare bravos in a repository bravos has not set up yet points at the guided setup first"
|
|
1064
|
+
if (argv.length === 0 && !existsSync(join(process.cwd(), '.bravos')))
|
|
1065
|
+
full.stdout('New here? Run bravos start: a guided setup, one question at a time.\n');
|
|
980
1066
|
try {
|
|
981
1067
|
await buildProgram(full, result).parseAsync(argv, { from: 'user' });
|
|
982
1068
|
}
|
package/dist/doctor.js
CHANGED
|
@@ -6,6 +6,7 @@ import { graphBin } from './codegraph.js';
|
|
|
6
6
|
import { findAnalyzer, findLicence } from './graphbin.js';
|
|
7
7
|
import { AUTOPILOT_COMMAND, HOOK_COMMANDS, LEGACY_HOOK_COMMAND, PRE_PR_COMMAND } from './hooks.js';
|
|
8
8
|
import { skillsRoot } from './skills.js';
|
|
9
|
+
import { resolveTheme } from './palette.js';
|
|
9
10
|
const TOOLS = [
|
|
10
11
|
{ name: 'guardlink', hint: 'npm install -g guardlink' },
|
|
11
12
|
{ name: 'cxg', hint: 'cargo install cert-x-gen (or: brew tap bugb-technologies/cxg && brew install cxg)' },
|
|
@@ -76,6 +77,7 @@ export function runDoctor(root, env = process.env) {
|
|
|
76
77
|
claude: hookRegistered(join(root, '.claude', 'settings.json'), 'PreToolUse', [PRE_PR_COMMAND]),
|
|
77
78
|
codex: hookRegistered(join(root, '.codex', 'hooks.json'), 'PreToolUse', [PRE_PR_COMMAND]),
|
|
78
79
|
},
|
|
80
|
+
theme: resolveTheme(env),
|
|
79
81
|
};
|
|
80
82
|
}
|
|
81
83
|
// @comment -- "Renders a DoctorReport as one line per check, with an install hint for each missing tool and guardlink's playbook skills named per root."
|
|
@@ -95,5 +97,6 @@ export function formatDoctor(r) {
|
|
|
95
97
|
`hooks claude: ${yn(r.hooks.claude)} codex: ${yn(r.hooks.codex)}`,
|
|
96
98
|
`pre-pr claude: ${yn(r.pre_pr.claude)} codex: ${yn(r.pre_pr.codex)}${r.pre_pr.claude || r.pre_pr.codex ? '' : ' (opt-in: bravos init --pre-pr-hook)'}`,
|
|
97
99
|
`autopilot claude: ${yn(r.autopilot.claude)} codex: ${yn(r.autopilot.codex)}${r.autopilot.claude || r.autopilot.codex ? '' : ' (opt-in: bravos init --autopilot)'}`,
|
|
100
|
+
...(r.theme ? [`colours ${r.theme.theme} (${r.theme.source})${r.theme.source.startsWith('default') ? ' — pick yours: BRAVOS_THEME=light or dark, or bravos start' : ''}`] : []),
|
|
98
101
|
].join('\n');
|
|
99
102
|
}
|
package/dist/guide.js
CHANGED
|
@@ -37,7 +37,7 @@ export const GUIDE_TOPICS = [
|
|
|
37
37
|
{
|
|
38
38
|
name: 'Installing',
|
|
39
39
|
body: [
|
|
40
|
-
'npm install -g @bugb-technologies/bravos (Node 20 or newer).
|
|
40
|
+
'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.', '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.',
|
|
41
41
|
],
|
|
42
42
|
},
|
|
43
43
|
{
|
|
@@ -187,7 +187,7 @@ export const GUIDE_TOPICS = [
|
|
|
187
187
|
{ name: 'Cursor', body: ['.cursor/rules/bravos.mdc points at the skills when the repo has a .cursor/ folder.'] },
|
|
188
188
|
{ name: 'VS Code (Copilot agent)', body: ['Reads hooks from .claude/settings.json (preview), so the briefing can load there too.'] },
|
|
189
189
|
{ name: 'Every repo, or one copy of each skill', body: ['bravos init --global installs for your user: skills in ~/.claude/skills (linked from ~/.agents/skills) and a user hook that briefs repos with a threat model but no bravos install. bravos sync --link-skills makes a repo\'s .agents/skills a link to .claude/skills, so tools that read both (Warp) list each skill once.'] },
|
|
190
|
-
{ name: 'Banner switches', body: ['BRAVOS_BANNER=off hides it; BRAVOS_BANNER_COLOR=off or NO_COLOR prints it plain. The briefing for the model is unchanged either way.'] },
|
|
190
|
+
{ name: 'Banner switches', body: ['BRAVOS_BANNER=off hides it; BRAVOS_BANNER_COLOR=off or NO_COLOR prints it plain. The briefing for the model is unchanged either way.', 'Light terminal? BRAVOS_THEME=light (or dark, or neutral) picks the colours for the banner and bravos watch; otherwise COLORFGBG, the choice saved by bravos start, then neutral. bravos doctor shows which, and the c key in bravos watch switches.'] },
|
|
191
191
|
],
|
|
192
192
|
},
|
|
193
193
|
];
|
package/dist/help.js
CHANGED
|
@@ -116,7 +116,10 @@ Session start
|
|
|
116
116
|
state, and a short introduction while .guardlink/intent.md is missing. Claude Code shows
|
|
117
117
|
it above the first prompt; Codex shows it as a hook message. BRAVOS_BANNER=off hides it;
|
|
118
118
|
the briefing still reaches the model. The banner uses bravos's brand colours (truecolor);
|
|
119
|
-
NO_COLOR or BRAVOS_BANNER_COLOR=off prints it plain.
|
|
119
|
+
NO_COLOR or BRAVOS_BANNER_COLOR=off prints it plain. Colours follow the terminal's
|
|
120
|
+
background: BRAVOS_THEME=light|dark|neutral, else COLORFGBG, else the choice saved by
|
|
121
|
+
bravos start, else neutral (readable on light and dark); bravos doctor says which.
|
|
122
|
+
Codex lists a hook message as a
|
|
120
123
|
warning, so there it is a two-line summary instead of the art. Since 0.5.0 the hook is registered with
|
|
121
124
|
--harness claude or --harness codex so the banner prints /skill or $skill; sync migrates
|
|
122
125
|
the older entry, and Codex asks you to trust the changed hook once (/hooks).
|
|
@@ -180,10 +183,14 @@ Rules every skill follows
|
|
|
180
183
|
a gate exited 0.
|
|
181
184
|
|
|
182
185
|
Typical first run
|
|
186
|
+
bravos start # guided: licence, tools, repo, agents, PR checks,
|
|
187
|
+
# schedule, testing permission; nothing changes until Apply
|
|
188
|
+
Or by hand
|
|
183
189
|
bravos doctor # what is installed, what is missing
|
|
184
190
|
bravos init --dry-run # preview every write
|
|
185
191
|
bravos init # install; then open a Claude Code or Codex session
|
|
186
192
|
bravos sync --ci --pre-pr-hook # later: add CI and the pre-PR gate
|
|
193
|
+
bravos sync --workflows nightly-claude --schedule weekly # a weekly nightly only
|
|
187
194
|
In Codex, run /hooks once to trust .codex/hooks.json.
|
|
188
195
|
|
|
189
196
|
Exit codes
|
package/dist/palette.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// @comment -- "bravos watch's copy of hooks/lib/palette.mjs: the same three themes and fixed pairs, typed and synchronous for the frame renderer. tests/palette.test.ts fails if the two ever differ, so there is still one palette."
|
|
2
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
3
|
+
import { homedir } from 'node:os';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
export const THEMES = {
|
|
6
|
+
dark: {
|
|
7
|
+
green: '#33d49d', blue: '#0360a2', light: '#f0f0f0', steel: '#55899e', red: '#ea1d1d',
|
|
8
|
+
slate: '#3b6779', amber: '#f0b429', line: '#2b4f5c',
|
|
9
|
+
},
|
|
10
|
+
light: {
|
|
11
|
+
green: '#0f7a55', blue: '#0360a2', light: null, steel: '#3f6576', red: '#c41616',
|
|
12
|
+
slate: '#4d6b78', amber: '#9a6400', line: '#7d98a3',
|
|
13
|
+
},
|
|
14
|
+
neutral: {
|
|
15
|
+
green: '#1e9a6c', blue: '#2f7fc1', light: null, steel: '#4f8296', red: '#e02424',
|
|
16
|
+
slate: '#5a7d8b', amber: '#b07a00', line: '#5a7d8b',
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
export const FIXED = {
|
|
20
|
+
green: '#33d49d', blue: '#0360a2', light: '#f0f0f0', steel: '#55899e', red: '#dc1f1f',
|
|
21
|
+
slate: '#3b6779', amber: '#f0b429', line: '#2b4f5c', ink: '#0e1b21', deep: '#1f3943', white: '#ffffff',
|
|
22
|
+
};
|
|
23
|
+
export const THEME_NAMES = ['dark', 'light', 'neutral'];
|
|
24
|
+
export const isTheme = (t) => THEME_NAMES.includes(t);
|
|
25
|
+
/** The next theme in the cycle the watch `t` key steps through. */
|
|
26
|
+
export const nextTheme = (t) => THEME_NAMES[(THEME_NAMES.indexOf(t) + 1) % THEME_NAMES.length];
|
|
27
|
+
/**
|
|
28
|
+
* A segment's foreground: from the theme when it sits on the terminal's own background,
|
|
29
|
+
* from FIXED when it sits on a background of its own (a badge, a key chip, the header bar),
|
|
30
|
+
* because that pair is the same in every theme. Null: the terminal's default foreground.
|
|
31
|
+
*/
|
|
32
|
+
export function fgFor(theme, role, onOwnBackground) {
|
|
33
|
+
if (onOwnBackground)
|
|
34
|
+
return FIXED[role] ?? null;
|
|
35
|
+
const t = THEMES[theme];
|
|
36
|
+
return role in t ? t[role] : FIXED[role] ?? null;
|
|
37
|
+
}
|
|
38
|
+
export const bgFor = (role) => FIXED[role] ?? null;
|
|
39
|
+
/* ------------------------------------------------------------------ choosing a theme */
|
|
40
|
+
/** Where Bravos keeps its own settings: $BRAVOS_HOME, else ~/.bravos. */
|
|
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. */
|
|
43
|
+
export function savedTheme(env = process.env) {
|
|
44
|
+
try {
|
|
45
|
+
const file = join(bravosHome(env), 'config.json');
|
|
46
|
+
if (!existsSync(file))
|
|
47
|
+
return null;
|
|
48
|
+
const t = JSON.parse(readFileSync(file, 'utf8'))?.theme;
|
|
49
|
+
return isTheme(t) ? t : null;
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/** COLORFGBG "fg;bg": a background of 7 or 15 is light, 0–6 or 8 dark. */
|
|
56
|
+
export function themeFromColorFgBg(value) {
|
|
57
|
+
if (!value)
|
|
58
|
+
return null;
|
|
59
|
+
const bg = Number(String(value).split(';').pop());
|
|
60
|
+
if (!Number.isInteger(bg))
|
|
61
|
+
return null;
|
|
62
|
+
if (bg === 7 || bg === 15)
|
|
63
|
+
return 'light';
|
|
64
|
+
if ((bg >= 0 && bg <= 6) || bg === 8)
|
|
65
|
+
return 'dark';
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
/** An OSC 11 answer ("rgb:ffff/ffff/ffff" or "#rrggbb") as a theme, or null. */
|
|
69
|
+
export function themeFromBackground(answer) {
|
|
70
|
+
if (!answer)
|
|
71
|
+
return null;
|
|
72
|
+
let rgbv;
|
|
73
|
+
const m = /rgb:([0-9a-f]+)\/([0-9a-f]+)\/([0-9a-f]+)/i.exec(answer);
|
|
74
|
+
if (m)
|
|
75
|
+
rgbv = [m[1], m[2], m[3]].map((h) => parseInt(h, 16) / (16 ** h.length - 1));
|
|
76
|
+
else {
|
|
77
|
+
const h = /#([0-9a-f]{6})/i.exec(answer);
|
|
78
|
+
if (!h)
|
|
79
|
+
return null;
|
|
80
|
+
rgbv = [0, 2, 4].map((i) => parseInt(h[1].slice(i, i + 2), 16) / 255);
|
|
81
|
+
}
|
|
82
|
+
const lum = 0.2126 * rgbv[0] + 0.7152 * rgbv[1] + 0.0722 * rgbv[2];
|
|
83
|
+
return lum > 0.5 ? 'light' : 'dark';
|
|
84
|
+
}
|
|
85
|
+
/** Same order as hooks/lib/palette.mjs resolveTheme: BRAVOS_THEME, the terminal's answer, COLORFGBG, the saved choice, neutral. */
|
|
86
|
+
// @comment -- "Theme choice for bravos watch and doctor, in the same order as the hook's: BRAVOS_THEME, the terminal's own answer, COLORFGBG, the saved choice, neutral"
|
|
87
|
+
export function resolveTheme(env = process.env, detected = null) {
|
|
88
|
+
const asked = String(env.BRAVOS_THEME ?? '').toLowerCase();
|
|
89
|
+
if (isTheme(asked))
|
|
90
|
+
return { theme: asked, source: 'BRAVOS_THEME' };
|
|
91
|
+
if (detected && isTheme(detected))
|
|
92
|
+
return { theme: detected, source: 'terminal' };
|
|
93
|
+
const fgbg = themeFromColorFgBg(env.COLORFGBG);
|
|
94
|
+
if (fgbg)
|
|
95
|
+
return { theme: fgbg, source: 'COLORFGBG' };
|
|
96
|
+
const saved = savedTheme(env);
|
|
97
|
+
if (saved)
|
|
98
|
+
return { theme: saved, source: 'saved by bravos start' };
|
|
99
|
+
return { theme: 'neutral', source: 'default (background unknown)' };
|
|
100
|
+
}
|
package/dist/plugin-release.js
CHANGED
|
@@ -200,13 +200,20 @@ hooks and MCP wiring for every agent it finds, and commits them with the code.
|
|
|
200
200
|
|
|
201
201
|
## Where data goes
|
|
202
202
|
|
|
203
|
-
Bravos runs on your machine,
|
|
204
|
-
|
|
205
|
-
skill you run:
|
|
203
|
+
Bravos runs on your machine. Its skills, its session hook and the CLI they call
|
|
204
|
+
reach only these places:
|
|
206
205
|
|
|
207
|
-
- **account.bugb.io:**
|
|
208
|
-
|
|
209
|
-
|
|
206
|
+
- **account.bugb.io:**
|
|
207
|
+
- \`bravos account activate\` signs this machine in once, in the browser. The
|
|
208
|
+
portal records the machine under its name (its hostname), so you and your
|
|
209
|
+
team's owners and admins can see it and sign it out.
|
|
210
|
+
- While the machine is signed in, Bravos renews its licence there automatically,
|
|
211
|
+
every few days: the session hook or the CLI sends the machine's secret, and the
|
|
212
|
+
portal records the time, your CLI version and a one-way digest of your IP
|
|
213
|
+
address. Licences for CI and licences imported from a file are never renewed.
|
|
214
|
+
- \`bravos setup\` downloads the SAST analyzer and the code graph with your licence.
|
|
215
|
+
|
|
216
|
+
Your licence and machine details go there; your code does not.
|
|
210
217
|
- **GitHub:** the session briefing uses \`gh\`, if it is installed and signed in, to
|
|
211
218
|
list open pull requests in your repository. The CI workflows \`bravos sync --ci\`
|
|
212
219
|
writes run on GitHub Actions in your own repository.
|
|
@@ -0,0 +1,82 @@
|
|
|
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)."
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { dirname, join } from 'node:path';
|
|
4
|
+
export const PRESETS = {
|
|
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' },
|
|
8
|
+
};
|
|
9
|
+
/** Where the cost of one pentest is published; the continuous-pentest question links to it. */
|
|
10
|
+
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). */
|
|
12
|
+
// @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
|
+
export function initArgs(a) {
|
|
14
|
+
const args = ['init', a.repo, '--agent', a.agents.join(',')];
|
|
15
|
+
if (a.pr !== 'none')
|
|
16
|
+
args.push('--pre-pr-hook');
|
|
17
|
+
if (a.autopilot)
|
|
18
|
+
args.push('--autopilot');
|
|
19
|
+
const workflows = [...(a.pr === 'hook+github' ? ['pr-gate'] : []), ...(a.schedule !== 'none' ? [`nightly-${a.nightlyAgent}`] : [])];
|
|
20
|
+
if (workflows.length)
|
|
21
|
+
args.push('--workflows', workflows.join(','));
|
|
22
|
+
if (a.schedule !== 'none')
|
|
23
|
+
args.push('--schedule', a.schedule);
|
|
24
|
+
if (a.proving !== 'none')
|
|
25
|
+
args.push('--scope');
|
|
26
|
+
return args;
|
|
27
|
+
}
|
|
28
|
+
/** The secrets and variables the nightly needs, by name. */
|
|
29
|
+
export function nightlySecrets(a) {
|
|
30
|
+
if (a.schedule === 'none')
|
|
31
|
+
return [];
|
|
32
|
+
return ['BRAVOS_LICENCE', a.nightlyAgent === 'codex' ? 'OPENAI_API_KEY' : 'ANTHROPIC_API_KEY'];
|
|
33
|
+
}
|
|
34
|
+
// @comment -- "proving.md in the exact form the prove skill and the briefing read: choice, generation, the person's own words quoted, and confirmed by their name and the date. Setup records no target or start command: the agent finds how the app starts and where it listens (loopback only) when it tests, and writes them then."
|
|
35
|
+
export function provingText(a, date) {
|
|
36
|
+
const quoted = a.words.trim().replace(/\s+/g, ' ').replace(/"/g, "'");
|
|
37
|
+
return [
|
|
38
|
+
'# How findings are proven',
|
|
39
|
+
'',
|
|
40
|
+
'Recorded by `bravos start` from the answers below. Edit it, or run `bravos start --again`, to change it.',
|
|
41
|
+
'',
|
|
42
|
+
`choice: ${a.proving}`,
|
|
43
|
+
`generation: ${a.generation ? 'yes' : 'no'}`,
|
|
44
|
+
'',
|
|
45
|
+
`"${quoted}"`,
|
|
46
|
+
'',
|
|
47
|
+
`— confirmed by ${a.name.trim()}, ${date}`,
|
|
48
|
+
'',
|
|
49
|
+
].join('\n');
|
|
50
|
+
}
|
|
51
|
+
export const SETUP_FILE = join('.bravos', 'setup.json');
|
|
52
|
+
export function readAnswers(root) {
|
|
53
|
+
try {
|
|
54
|
+
const p = join(root, SETUP_FILE);
|
|
55
|
+
return existsSync(p) ? (JSON.parse(readFileSync(p, 'utf8'))?.answers ?? null) : null;
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/** Saved for --again; the person's words and name stay in proving.md, not here. */
|
|
62
|
+
export function writeAnswers(root, a, version, at) {
|
|
63
|
+
const p = join(root, SETUP_FILE);
|
|
64
|
+
mkdirSync(dirname(p), { recursive: true });
|
|
65
|
+
const { words: _w, name: _n, ...kept } = a;
|
|
66
|
+
writeFileSync(p, JSON.stringify({ schema: 'bravos.start/v1', bravos_version: version, at, answers: kept }, null, 2) + '\n');
|
|
67
|
+
}
|
|
68
|
+
/** Saves the colour theme in $BRAVOS_HOME/config.json, keeping anything else in it. */
|
|
69
|
+
export function writeTheme(home, theme) {
|
|
70
|
+
const p = join(home, 'config.json');
|
|
71
|
+
let cfg = {};
|
|
72
|
+
try {
|
|
73
|
+
if (existsSync(p))
|
|
74
|
+
cfg = JSON.parse(readFileSync(p, 'utf8')) ?? {};
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
cfg = {};
|
|
78
|
+
}
|
|
79
|
+
mkdirSync(home, { recursive: true, mode: 0o700 });
|
|
80
|
+
writeFileSync(p, JSON.stringify({ ...cfg, theme }, null, 2) + '\n');
|
|
81
|
+
return p;
|
|
82
|
+
}
|