@bugb-technologies/bravos 1.9.0 → 1.9.2
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/dist/cli.js +19 -4
- package/dist/install-proof-tool.js +26 -0
- package/dist/setup.js +7 -1
- package/dist/start/answers.js +53 -0
- package/dist/start/index.js +56 -13
- package/dist/start/ui.js +15 -8
- package/docs/UPGRADING.md +11 -0
- package/hooks/lib/graph-autobuild.mjs +20 -6
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -636,12 +636,27 @@ export function buildProgram(io, result) {
|
|
|
636
636
|
if (!opts.yes && !interactive)
|
|
637
637
|
throw new BravosError(`bravos ${name} asks questions, so it needs a terminal. In a script use: bravos ${name} --yes --preset pr <dir>`);
|
|
638
638
|
const prompter = interactive ? ui.terminalPrompter() : ui.scriptedPrompter({}, io.stdout);
|
|
639
|
-
|
|
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) => {
|
|
640
641
|
const out = [];
|
|
641
642
|
const err = [];
|
|
642
|
-
const
|
|
643
|
-
|
|
644
|
-
|
|
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
|
+
});
|
|
645
660
|
result.code = await runStart({ dir, again: opts.again, yes: opts.yes, preset: opts.preset, command: name }, {
|
|
646
661
|
prompter,
|
|
647
662
|
env: io.env,
|
|
@@ -23,6 +23,27 @@ const prerequisites = {
|
|
|
23
23
|
tar: 'install tar for the pinned GuardLink grammar build',
|
|
24
24
|
cargo: 'install the Rust toolchain (cargo and rustc) and a native linker',
|
|
25
25
|
};
|
|
26
|
+
// @comment -- "Where cargo puts what it installs (CARGO_INSTALL_ROOT, else CARGO_HOME, else ~/.cargo, then /bin), and whether that folder is on PATH. A cargo from Homebrew or a package manager runs fine while that folder is missing from PATH, so cxg builds for minutes and then nothing can find it; setup checks first and says the one line to add."
|
|
27
|
+
export function cargoBinDir(env) {
|
|
28
|
+
const root = env.CARGO_INSTALL_ROOT || env.CARGO_HOME || (env.HOME ? join(env.HOME, '.cargo') : null);
|
|
29
|
+
return root ? join(isAbsolute(root) ? root : resolve(root), 'bin') : null;
|
|
30
|
+
}
|
|
31
|
+
export function cargoBinOnPath(env) {
|
|
32
|
+
const dir = cargoBinDir(env);
|
|
33
|
+
if (!dir)
|
|
34
|
+
return true;
|
|
35
|
+
return (env.PATH ?? '').split(delimiter).some((p) => p && resolve(p) === dir);
|
|
36
|
+
}
|
|
37
|
+
/** The line that puts cargo's folder on PATH, for the person's own shell profile. */
|
|
38
|
+
export function cargoPathFix(env) {
|
|
39
|
+
const dir = cargoBinDir(env) ?? '~/.cargo/bin';
|
|
40
|
+
const shown = env.HOME && dir.startsWith(env.HOME + '/') ? `$HOME${dir.slice(env.HOME.length)}` : dir;
|
|
41
|
+
const shell = (env.SHELL ?? '').split('/').pop();
|
|
42
|
+
const profile = shell === 'zsh' ? '~/.zshrc' : shell === 'bash' ? '~/.bash_profile' : shell === 'fish' ? null : '~/.profile';
|
|
43
|
+
return profile
|
|
44
|
+
? `echo 'export PATH="${shown}:$PATH"' >> ${profile}, then open a new terminal`
|
|
45
|
+
: `fish_add_path ${shown}, then open a new terminal`;
|
|
46
|
+
}
|
|
26
47
|
// @comment -- "Use fixed package-manager argv in a private scratch directory, outside the customer repository. Ignore inherited Git working-tree overrides and relative PATH entries, so the checkout cannot supply a .cargo/config.toml, .npmrc, Git config or executable for the install."
|
|
27
48
|
export function installProofTool(name, env, echo, pins = PROOF_TOOL_PINS) {
|
|
28
49
|
const pin = pins[name];
|
|
@@ -47,6 +68,8 @@ export function installProofTool(name, env, echo, pins = PROOF_TOOL_PINS) {
|
|
|
47
68
|
}
|
|
48
69
|
const work = mkdtempSync(join(tmpdir(), 'bravos-tools-'));
|
|
49
70
|
function invoke(command, args, cwd, step) {
|
|
71
|
+
// Each step is said before it runs, so whoever is watching (the guided setup's spinner) knows what the wait is for.
|
|
72
|
+
echo(`${name}: ${step}${command === 'cargo' ? ' (cargo compiles it from source; this is the long step)' : ''}…`);
|
|
50
73
|
const result = spawnSync(executables.get(command) ?? command, args, {
|
|
51
74
|
cwd, env: installEnv, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: 32 * 1024 * 1024, timeout: 30 * 60 * 1000,
|
|
52
75
|
});
|
|
@@ -101,6 +124,9 @@ export function installProofTool(name, env, echo, pins = PROOF_TOOL_PINS) {
|
|
|
101
124
|
// Check the user's PATH again after installation, before invoking any post-install command on the selected binary.
|
|
102
125
|
const found = whichBin(name, installEnv);
|
|
103
126
|
const status = checkProofTool(name, installEnv);
|
|
127
|
+
if (!found && name === 'cxg' && !cargoBinOnPath(env)) {
|
|
128
|
+
throw new BravosError(`cxg was built and installed in ${cargoBinDir(env)}, but that folder is not on your PATH, so nothing can run it. Add it once: ${cargoPathFix(env)}; then run bravos setup --check.`);
|
|
129
|
+
}
|
|
104
130
|
if (!found || status.status !== 'ready') {
|
|
105
131
|
const destination = name === 'guardlink' ? 'the bin directory under npm prefix --global' : 'the bin directory under your Cargo install root (normally ~/.cargo/bin)';
|
|
106
132
|
throw new BravosError(`${name} was installed but ${found ?? 'no executable'} is selected on PATH (${status.status}). Put ${destination} first, check which -a ${name}, then run bravos setup --check.`);
|
package/dist/setup.js
CHANGED
|
@@ -10,7 +10,7 @@ import { findAnalyzer } from './graphbin.js';
|
|
|
10
10
|
import { licenceLib, requireFeature } from './licence.js';
|
|
11
11
|
import { BravosError } from './types.js';
|
|
12
12
|
import { PROOF_TOOL_PINS } from './versions.js';
|
|
13
|
-
import { installProofTool, proofToolAction } from './install-proof-tool.js';
|
|
13
|
+
import { cargoBinDir, cargoBinOnPath, cargoPathFix, installProofTool, proofToolAction } from './install-proof-tool.js';
|
|
14
14
|
// @comment -- "The version of a staged bundle when it is older than the one this bravos pins, else null. An existing install keeps working on the old bundle until setup runs; this is how setup, and its --check, know there is a newer one to fetch. Read-only."
|
|
15
15
|
export function behindPin(env, kind) {
|
|
16
16
|
const dir = staged(env, kind);
|
|
@@ -103,6 +103,12 @@ export async function runSetup(env, opts, io) {
|
|
|
103
103
|
lines.push(formatProofTool(check), i.id + ': already compatible at ' + i.present);
|
|
104
104
|
continue;
|
|
105
105
|
}
|
|
106
|
+
// A cxg already built into cargo's folder, which is not on PATH: building it again ends the same way, so say how to put it on PATH instead.
|
|
107
|
+
const built = cargoBinDir(env);
|
|
108
|
+
if (i.id === 'cxg' && !i.present && built && !cargoBinOnPath(env) && existsSync(join(built, 'cxg'))) {
|
|
109
|
+
lines.push(`cxg: already built at ${join(built, 'cxg')}, but that folder is not on your PATH, so nothing can run it. Add it once: ${cargoPathFix(env)}; no need to build it again.`);
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
106
112
|
if (opts.dryRun || !opts.yes) {
|
|
107
113
|
const state = i.present ? check.status + ' at ' + i.present : 'absent';
|
|
108
114
|
lines.push(i.id + ': ' + state + ' — ' + i.action + (opts.yes ? '' : ' (add -y to run it here)'));
|
package/dist/start/answers.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
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
|
+
import { CRON } from '../ci.js';
|
|
4
5
|
export const PRESETS = {
|
|
5
6
|
annotate: { label: 'Map my threats only', hint: 'annotations; nothing runs on its own', pr: 'none', autopilot: false, schedule: 'none', proving: 'none' },
|
|
6
7
|
// @comment -- "Autopilot is on for the pr preset in the preset itself, so bravos setup --yes and the interactive default agree."
|
|
@@ -114,3 +115,55 @@ export function targetProblem(value) {
|
|
|
114
115
|
}
|
|
115
116
|
/** The target as replay compares it (URL.href), or undefined when none was given. */
|
|
116
117
|
export const normalTarget = (value) => (value?.trim() ? new URL(value.trim()).href : undefined);
|
|
118
|
+
// @comment -- "What a repository that already has Bravos is set up with, read from the files it carries: the agents whose skills are installed, the pull-request checks (the pre-PR hook, the PR workflow), autopilot, the scheduled run and its cadence, and the recorded testing choice. The guided setup shows it when someone joins, and preselects it when they choose to change it; a repository installed by flags has no setup.json, so this is the only record of its choices."
|
|
119
|
+
export function currentSetup(repo, opts) {
|
|
120
|
+
const has = (rel) => existsSync(join(repo, rel));
|
|
121
|
+
const agents = [];
|
|
122
|
+
if (has('.claude/skills/bravos/SKILL.md'))
|
|
123
|
+
agents.push('claude');
|
|
124
|
+
if (has('.codex/hooks.json') && has('.agents/skills/bravos/SKILL.md'))
|
|
125
|
+
agents.push('codex');
|
|
126
|
+
if (has('.agents/hooks.json') && has('.agents/skills/bravos/SKILL.md'))
|
|
127
|
+
agents.push('agy');
|
|
128
|
+
if (has('.opencode/plugins/bravos.js'))
|
|
129
|
+
agents.push('opencode');
|
|
130
|
+
if (has('.omp/extensions/bravos.js'))
|
|
131
|
+
agents.push('omp');
|
|
132
|
+
const gate = has('.github/workflows/bravos-pr-gate.yml');
|
|
133
|
+
const nightly = ['claude', 'codex', 'copilot'].find((a) => has(`.github/workflows/bravos-nightly-${a}.yml`));
|
|
134
|
+
let schedule = 'none';
|
|
135
|
+
if (nightly) {
|
|
136
|
+
const text = readFileSync(join(repo, `.github/workflows/bravos-nightly-${nightly}.yml`), 'utf8');
|
|
137
|
+
schedule = Object.keys(CRON).find((c) => text.includes(CRON[c])) ?? 'weekly';
|
|
138
|
+
}
|
|
139
|
+
let proving;
|
|
140
|
+
try {
|
|
141
|
+
const m = /^choice:\s*(auto|ask|schedule|none)\b/m.exec(readFileSync(join(repo, '.guardlink', 'proving.md'), 'utf8'));
|
|
142
|
+
if (m)
|
|
143
|
+
proving = m[1];
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
/* no testing choice recorded */
|
|
147
|
+
}
|
|
148
|
+
return {
|
|
149
|
+
...(agents.length ? { agents } : {}),
|
|
150
|
+
pr: gate ? 'hook+github' : opts.prePr || opts.autopilot ? 'hook' : 'none',
|
|
151
|
+
autopilot: opts.autopilot,
|
|
152
|
+
schedule,
|
|
153
|
+
...(nightly ? { nightlyAgent: nightly } : {}),
|
|
154
|
+
...(proving ? { proving } : {}),
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
/** The repository's setup in a few plain lines, for the guided setup to show before asking whether to keep it. */
|
|
158
|
+
export function describeSetup(a) {
|
|
159
|
+
const label = { claude: 'Claude Code', codex: 'Codex', agy: 'Antigravity', opencode: 'opencode', omp: 'oh-my-pi' };
|
|
160
|
+
const pr = { none: 'none', hook: 'checked before your agent opens a PR', 'hook+github': 'checked before your agent opens a PR, and every PR in GitHub' };
|
|
161
|
+
const proving = { ask: 'ask every time', auto: 'test the local app as you build', schedule: 'only in the scheduled run', none: 'never test, just annotate' };
|
|
162
|
+
return [
|
|
163
|
+
`Agents: ${(a.agents ?? []).map((x) => label[x] ?? x).join(', ') || 'none found'}`,
|
|
164
|
+
`Pull requests: ${pr[a.pr ?? 'none']}`,
|
|
165
|
+
`Autopilot: ${a.autopilot ? 'on: changed code is reviewed at the end of each agent turn' : 'off'}`,
|
|
166
|
+
`Schedule: ${a.schedule && a.schedule !== 'none' ? `${a.schedule}, run by ${a.nightlyAgent ?? 'claude'} in GitHub Actions` : 'none'}`,
|
|
167
|
+
`Testing: ${a.proving ? proving[a.proving] : 'not recorded yet (your agent asks when testing comes up)'}`,
|
|
168
|
+
];
|
|
169
|
+
}
|
package/dist/start/index.js
CHANGED
|
@@ -4,11 +4,13 @@ import { join, resolve } from 'node:path';
|
|
|
4
4
|
import { resolveTheme, THEMES } from '../palette.js';
|
|
5
5
|
import { detectHarnesses } from '../detect.js';
|
|
6
6
|
import { CRON } from '../ci.js';
|
|
7
|
-
import { initArgs, nightlySecrets, normalTarget, PRESETS, provingText, readAnswers, targetProblem, writeAnswers, writeTheme, } from './answers.js';
|
|
7
|
+
import { initArgs, nightlySecrets, normalTarget, PRESETS, provingText, readAnswers, currentSetup, describeSetup, targetProblem, writeAnswers, writeTheme, } from './answers.js';
|
|
8
8
|
import { findRepos, isGitRepo, repoHint, repoProblem, tildify } from './repos.js';
|
|
9
9
|
import { Back, Cancelled } from './ui.js';
|
|
10
10
|
import { BravosError } from '../types.js';
|
|
11
11
|
import { prefsLib } from '../prefs.js';
|
|
12
|
+
import { installedOptIns } from '../hooks.js';
|
|
13
|
+
import { cargoBinDir, cargoBinOnPath, cargoPathFix } from '../install-proof-tool.js';
|
|
12
14
|
const AGENTS = [
|
|
13
15
|
{ value: 'claude', label: 'Claude Code' },
|
|
14
16
|
{ value: 'codex', label: 'Codex' },
|
|
@@ -61,7 +63,8 @@ export async function runStart(opts, d) {
|
|
|
61
63
|
}
|
|
62
64
|
async function flow(opts, d) {
|
|
63
65
|
const p = d.prompter;
|
|
64
|
-
|
|
66
|
+
// The repository's recorded answers, preselected when its questions are asked again (--change, or choosing Change when joining).
|
|
67
|
+
let saved = opts.again ? readAnswers(opts.dir ? resolve(opts.dir) : d.cwd) : null;
|
|
65
68
|
p.intro(`Bravos ${d.version} setup`);
|
|
66
69
|
p.info('About five minutes. Esc goes back a step, Ctrl-C quits. Signing in happens when you choose it; everything else waits for your OK at the end.');
|
|
67
70
|
const major = Number(process.versions.node.split('.')[0]);
|
|
@@ -85,7 +88,9 @@ async function flow(opts, d) {
|
|
|
85
88
|
};
|
|
86
89
|
let themeKept = false;
|
|
87
90
|
const has = (s, f) => !!s.lic?.unlocked.includes(f);
|
|
88
|
-
|
|
91
|
+
// cxg already built into cargo's folder, which is not on PATH: building it again would take minutes and end the same way, so it is not offered for install; the tools step says how to put it on PATH instead.
|
|
92
|
+
const strandedCxg = (s) => (s.items ?? []).some((i) => i.id === 'cxg' && !i.present) && !cargoBinOnPath(d.env) && !!cargoBinDir(d.env) && existsSync(join(cargoBinDir(d.env), 'cxg'));
|
|
93
|
+
const missingTools = (s) => (s.items ?? []).filter((i) => (i.id === 'guardlink' || i.id === 'cxg') && (!i.present || (i.proofTool && i.proofTool.status !== 'ready')) && !(i.id === 'cxg' && strandedCxg(s)));
|
|
89
94
|
// A bundle older than this version pins counts as missing: setting up again after an upgrade must bring it up to date.
|
|
90
95
|
const missingBundles = (s) => (s.items ?? []).filter((i) => (i.id === 'analyzer' || i.id === 'codegraph') && (!i.present || !!i.behind) && i.licensed);
|
|
91
96
|
// @comment -- "A repository-level question is skipped when joining: those answers are the team's, already committed."
|
|
@@ -145,9 +150,13 @@ async function flow(opts, d) {
|
|
|
145
150
|
return `✗ ${i.id.padEnd(10)} ${i.present} needs a compatible build for ${i.proofTool.capability}`;
|
|
146
151
|
if (i.present && i.behind && i.licensed)
|
|
147
152
|
return `↑ ${i.id.padEnd(10)} ${i.behind} installed, this version uses ${i.wanted}`;
|
|
153
|
+
if (i.id === 'cxg' && strandedCxg(s))
|
|
154
|
+
return `! cxg built, but not on your PATH`;
|
|
148
155
|
return `${i.present ? '✔' : '✗'} ${i.id.padEnd(10)} ${i.present ? 'installed' : i.licensed === false ? 'Team plan' : `missing — ${i.action}`}`;
|
|
149
156
|
}).join('\n'), 'Tools');
|
|
150
157
|
const missing = [...missingTools(s), ...missingBundles(s)];
|
|
158
|
+
if (strandedCxg(s))
|
|
159
|
+
p.warn(`cxg is already built at ${join(cargoBinDir(d.env), 'cxg')}, but that folder is not on your PATH, so nothing can run it. No need to build it again: ${cargoPathFix(d.env)}.`);
|
|
151
160
|
// @comment -- "The answer given before (Esc returns here) is kept as the default; the first time the default is yes. It used to be reset to no before the question, so Enter skipped the install. An unattended run is never asked: it fetches Bravos's own bundles at Apply and leaves guardlink and cxg, whose installers are other people's, to a person."
|
|
152
161
|
const before = s.installTools;
|
|
153
162
|
s.installTools = false;
|
|
@@ -159,6 +168,10 @@ async function flow(opts, d) {
|
|
|
159
168
|
if (missingTools(s).some((i) => i.id === 'cxg') && !d.which('cargo')) {
|
|
160
169
|
p.warn('cxg (the test engine) installs with Rust\'s cargo, which is not here. Install Rust first: curl --proto \'=https\' --tlsv1.2 -sSf https://sh.rustup.rs | sh — or skip cxg for now; annotations work without it.');
|
|
161
170
|
}
|
|
171
|
+
// cargo is here, but where it installs is not on PATH: cxg would build for minutes and then not be found. Said before the question, with the fix.
|
|
172
|
+
if (missingTools(s).some((i) => i.id === 'cxg') && d.which('cargo') && !cargoBinOnPath(d.env)) {
|
|
173
|
+
p.warn(`cxg installs into ${cargoBinDir(d.env)}, which is not on your PATH, so after it builds nothing will find it. Add it first: ${cargoPathFix(d.env)}, and run bravos setup there. Or install now and add it afterwards.`);
|
|
174
|
+
}
|
|
162
175
|
s.installTools = await p.confirm('tools', `Install ${missing.map((i) => i.id).join(', ')} when you apply?`, before ?? true);
|
|
163
176
|
},
|
|
164
177
|
// repository
|
|
@@ -203,8 +216,18 @@ async function flow(opts, d) {
|
|
|
203
216
|
// The lock alone means Bravos is here, whichever way it was installed (the guided setup, or flags, which leave no setup.json): bravos setup in such a repository brings it up to date, and only --change asks its questions.
|
|
204
217
|
s.join = !opts.again && existsSync(join(repo, '.bravos', 'skills.lock'));
|
|
205
218
|
if (s.join) {
|
|
206
|
-
|
|
207
|
-
|
|
219
|
+
// @comment -- "Joining a repository that has Bravos: say what it is set up with (agents, pull-request checks, autopilot, schedule, testing) and ask once whether to keep that or change it, so the repository's choices are one Enter away instead of behind a flag. Keep is the default and changes nothing the team decided; Change asks the repository's questions with what is there now selected. An unattended run keeps."
|
|
220
|
+
const now = { ...currentSetup(repo, installedOptIns(repo)), ...(readAnswers(repo) ?? {}) };
|
|
221
|
+
s.agents = now.agents ?? s.agents;
|
|
222
|
+
p.note(describeSetup(now).join('\n'), 'This repository is already set up');
|
|
223
|
+
const keep = opts.yes ? 'keep' : await p.select('repo-setup', 'Keep this repository\'s setup, or change it?', [
|
|
224
|
+
{ value: 'keep', label: 'Keep it', hint: 'set up this machine only; the team\'s choices stay as they are', recommended: true },
|
|
225
|
+
{ value: 'change', label: 'Change it', hint: 'agents, pull-request checks, autopilot, schedule, testing' },
|
|
226
|
+
], s.join ? 'keep' : 'change');
|
|
227
|
+
if (keep === 'change') {
|
|
228
|
+
s.join = false;
|
|
229
|
+
saved = { ...now, ...(saved ?? {}) };
|
|
230
|
+
}
|
|
208
231
|
}
|
|
209
232
|
},
|
|
210
233
|
// agents
|
|
@@ -458,7 +481,7 @@ async function flow(opts, d) {
|
|
|
458
481
|
...(has(s, 'codegraph') ? [`bravos graph build ${JSON.stringify(answers.repo)} --scip no-exec`] : []),
|
|
459
482
|
].join('\n'), 'Commands');
|
|
460
483
|
}
|
|
461
|
-
return apply(toAnswers(s), s, d, opts, { missingTools: missingTools(s).length > 0, missingBundles: missingBundles(s).length > 0, codegraph: has(s, 'codegraph'), join: !!s.join, commits: s.commits });
|
|
484
|
+
return apply(toAnswers(s), s, d, opts, { missingTools: missingTools(s).length > 0, missingBundles: missingBundles(s).length > 0, codegraph: has(s, 'codegraph'), join: !!s.join, commits: s.commits, cxgMissing: missingTools(s).some((i) => i.id === 'cxg'), toolNames: missingTools(s).map((i) => i.id) });
|
|
462
485
|
}
|
|
463
486
|
function toAnswers(s) {
|
|
464
487
|
return {
|
|
@@ -483,26 +506,41 @@ async function apply(answers, s, d, opts, has) {
|
|
|
483
506
|
const p = d.prompter;
|
|
484
507
|
const { repo, agents } = answers;
|
|
485
508
|
writeTheme(d.home, answers.theme);
|
|
509
|
+
// @comment -- "Apply says up front how many steps it will take and which may be slow, and numbers each one, so a person can tell it is working and roughly how far along it is. cxg is compiled from source by cargo, which is the one step that can take many minutes."
|
|
510
|
+
const steps = [
|
|
511
|
+
answers.installTools && has.missingTools && !opts.yes,
|
|
512
|
+
(answers.installTools || opts.yes) && has.missingBundles,
|
|
513
|
+
true,
|
|
514
|
+
has.codegraph,
|
|
515
|
+
].filter(Boolean).length;
|
|
516
|
+
let at = 0;
|
|
517
|
+
const step = (label) => `[${++at}/${steps}] ${label}`;
|
|
518
|
+
const slowCxg = answers.installTools && has.missingTools && !opts.yes && has.cxgMissing;
|
|
519
|
+
// Named for what is actually missing: a step that installs only cxg says so.
|
|
520
|
+
const what = has.toolNames?.length ? has.toolNames.join(' and ') : 'guardlink and cxg';
|
|
521
|
+
const tools = slowCxg ? `Installing ${what} (cxg is compiled from source: often 5 to 10 minutes)` : `Installing ${what}`;
|
|
522
|
+
p.info(`Applying: ${steps} step${steps === 1 ? '' : 's'}${slowCxg ? '. The first takes longest, because cargo compiles cxg; the clock and the line beside it show where it is' : ''}. Leave this window open until "Bravos is set up".`);
|
|
486
523
|
if (answers.installTools && has.missingTools && !opts.yes) {
|
|
487
|
-
const r = await p.spin(
|
|
524
|
+
const r = await p.spin(step(tools), (progress) => d.bravos(['setup', '--tools', '-y'], progress), (r) => (r.code ? { fail: `${tools} — failed` } : `Installed ${what}`));
|
|
488
525
|
for (const l of [...r.out, ...r.err])
|
|
489
526
|
(r.code ? p.warn : p.info)(l);
|
|
490
527
|
// A tool that would not install (no cargo, offline, an incompatible build) limits proving, not the
|
|
491
528
|
// rest of setup: carry on, and say what still needs doing instead of leaving the repo unset.
|
|
492
529
|
if (r.code)
|
|
493
|
-
p.warn(
|
|
530
|
+
p.warn(`Carrying on without ${what}: annotation and the briefing work now; proving needs guardlink and cxg. Fix the line above, then run bravos setup --tools -y.`);
|
|
494
531
|
}
|
|
495
532
|
// The bundles are named: a bare `bravos setup` is the whole setup now, and would start this wizard again. An unattended run fetches them too; they are Bravos's own, signed.
|
|
496
533
|
if ((answers.installTools || opts.yes) && has.missingBundles) {
|
|
497
|
-
const r = await p.spin('Fetching the Bravos analyzer and code graph', () => d.bravos(['setup', '--analyzer', '--codegraph']), (r) => (r.code ? { fail: 'Fetching the analyzer and code graph — failed' } : 'Fetched the analyzer and code graph'));
|
|
534
|
+
const r = await p.spin(step('Fetching the Bravos analyzer and code graph'), (progress) => d.bravos(['setup', '--analyzer', '--codegraph'], progress), (r) => (r.code ? { fail: 'Fetching the analyzer and code graph — failed' } : 'Fetched the analyzer and code graph'));
|
|
498
535
|
for (const l of [...r.out, ...r.err])
|
|
499
536
|
(r.code ? p.warn : p.info)(l);
|
|
500
537
|
}
|
|
501
538
|
// @comment -- "Joining runs bravos setup, which re-applies what the repository already has and never rewrites the team's choices; a first setup runs bravos setup with the flags the answers amount to."
|
|
502
539
|
const init = has.join
|
|
503
|
-
? await p.spin('Bringing this machine up to date with the repository', () => d.bravos(['sync', repo]), (r) => (r.code ? { fail: 'Syncing the repository — failed' } : 'Repository in sync'))
|
|
504
|
-
: await p.spin('Setting up the repository', () => d.bravos(initArgs(answers)), (r) => (r.code ? { fail: 'Setting up the repository — failed' } : 'Repository set up'));
|
|
505
|
-
|
|
540
|
+
? await p.spin(step('Bringing this machine up to date with the repository'), (progress) => d.bravos(['sync', repo], progress), (r) => (r.code ? { fail: 'Syncing the repository — failed' } : 'Repository in sync'))
|
|
541
|
+
: await p.spin(step('Setting up the repository'), (progress) => d.bravos(initArgs(answers), progress), (r) => (r.code ? { fail: 'Setting up the repository — failed' } : 'Repository set up'));
|
|
542
|
+
// @comment -- "What the repository step printed is shown only where it matters: a change, a warning or something to do. A re-apply that changed nothing is the one line on the spinner; the install log's own closing 'Next: open a session' is left out, because the guided setup ends with its own."
|
|
543
|
+
for (const l of init.code === 0 ? worthShowing(init.out) : init.out)
|
|
506
544
|
p.info(l);
|
|
507
545
|
if (init.code !== 0) {
|
|
508
546
|
for (const l of init.err)
|
|
@@ -534,7 +572,7 @@ async function apply(answers, s, d, opts, has) {
|
|
|
534
572
|
(r.code ? p.warn : p.info)(r.code ? `gh secret set ${n} failed — add it in the repository's Settings → Secrets` : `secret ${n} set`);
|
|
535
573
|
}
|
|
536
574
|
if (has.codegraph) {
|
|
537
|
-
const g = await p.spin('Building the code graph (a minute or two; longer on a big repository)', () => d.bravosChild(['graph', 'build', repo, '--scip', 'no-exec', '--json']), (r) => (graphSummary(r).ok ? graphSummary(r).line : { fail: graphSummary(r).line }));
|
|
575
|
+
const g = await p.spin(step('Building the code graph (a minute or two; longer on a big repository)'), () => d.bravosChild(['graph', 'build', repo, '--scip', 'no-exec', '--json']), (r) => (graphSummary(r).ok ? graphSummary(r).line : { fail: graphSummary(r).line }));
|
|
538
576
|
const sum = graphSummary(g);
|
|
539
577
|
for (const n of sum.notes)
|
|
540
578
|
(sum.ok ? p.info : p.warn)(n);
|
|
@@ -592,6 +630,11 @@ async function apply(answers, s, d, opts, has) {
|
|
|
592
630
|
p.outro('Bravos is set up.');
|
|
593
631
|
return 0;
|
|
594
632
|
}
|
|
633
|
+
// @comment -- "Lines from the install that tell a person something: a file written or updated, a warning, something skipped or left to do. 'Unchanged', 'already registered' and the install's own closing line are left out."
|
|
634
|
+
export function worthShowing(lines) {
|
|
635
|
+
const quiet = [/^Next: open a session/, /already registered$/, /already lists/, /^Harnesses: /, /\b0 written, 0 updated, \d+ unchanged, 0 skipped\b/, /\bunchanged \(/, /added none; kept/, /^autopilot: kept/, /^guardlink: present$/];
|
|
636
|
+
return lines.filter((l) => l.trim() && !quiet.some((q) => q.test(l)));
|
|
637
|
+
}
|
|
595
638
|
function provingLabel(p) {
|
|
596
639
|
return { ask: 'Ask me every time before testing', auto: 'Test my local app automatically', schedule: 'Only in the scheduled run', none: 'Never test, just annotate' }[p];
|
|
597
640
|
}
|
package/dist/start/ui.js
CHANGED
|
@@ -132,19 +132,26 @@ export function terminalPrompter() {
|
|
|
132
132
|
});
|
|
133
133
|
return String((await ask(k, p)) ?? '');
|
|
134
134
|
},
|
|
135
|
+
// @comment -- "A step that takes minutes must look alive: the spinner shows a running clock, and the latest line the work reports (the install step it is on) beside the label, cut to the terminal's width. This only moves if the work leaves the event loop free, which is why Apply runs its long steps as child processes (src/cli.ts)."
|
|
135
136
|
spin: async (label, work, done) => {
|
|
136
|
-
const s = clack.spinner();
|
|
137
|
-
const t0 = Date.now();
|
|
137
|
+
const s = clack.spinner({ indicator: 'timer' });
|
|
138
138
|
s.start(label);
|
|
139
|
+
const width = Math.max(40, (process.stdout.columns || 80) - 14);
|
|
140
|
+
const progress = (line) => {
|
|
141
|
+
const text = line.replace(/\x1b\[[0-9;]*m/g, '').replace(/\s+/g, ' ').trim();
|
|
142
|
+
if (!text)
|
|
143
|
+
return;
|
|
144
|
+
const full = `${label} — ${text}`;
|
|
145
|
+
s.message(full.length > width ? `${full.slice(0, width - 1)}…` : full);
|
|
146
|
+
};
|
|
139
147
|
try {
|
|
140
|
-
const r = await work();
|
|
141
|
-
|
|
148
|
+
const r = await work(progress);
|
|
149
|
+
// The spinner's own clock already prints the time taken beside the final line.
|
|
142
150
|
const res = done ? done(r) : label;
|
|
143
|
-
const took = secs >= 2 ? ` (${secs}s)` : '';
|
|
144
151
|
if (typeof res === 'string')
|
|
145
|
-
s.stop(
|
|
152
|
+
s.stop(res);
|
|
146
153
|
else
|
|
147
|
-
s.error(
|
|
154
|
+
s.error(res.fail);
|
|
148
155
|
return r;
|
|
149
156
|
}
|
|
150
157
|
catch (e) {
|
|
@@ -210,7 +217,7 @@ export function scriptedPrompter(answers, out = () => { }) {
|
|
|
210
217
|
confirm: async (id, _m, initial) => pick(id, initial),
|
|
211
218
|
secret: async (id) => String(pick(id, undefined)),
|
|
212
219
|
spin: async (label, work, done) => {
|
|
213
|
-
const r = await work();
|
|
220
|
+
const r = await work(() => { });
|
|
214
221
|
const res = done ? done(r) : label;
|
|
215
222
|
out(typeof res === 'string' ? res : `! ${res.fail}`);
|
|
216
223
|
return r;
|
package/docs/UPGRADING.md
CHANGED
|
@@ -2,6 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
After `npm install -g @bugb-technologies/bravos`, run **`bravos setup`** in a repository you work in: it brings this machine and that repository up to date. In repositories you work in with an agent you can skip even that: the agent runs it at the start of a session. The notes below say what else changes, newest first. (Before 1.9 the same was `bravos setup --tools -y` per machine and `bravos sync` per repository; both still work.)
|
|
4
4
|
|
|
5
|
+
## 1.9.2
|
|
6
|
+
|
|
7
|
+
- **Joining a repository shows its setup.** In a repository that already has Bravos, `bravos setup` lists what it is set up with (agents, pull-request checks, autopilot, schedule, testing) and asks whether to keep it or change it. Keep is the default and changes nothing; Change asks the repository's questions with what is there selected.
|
|
8
|
+
- **cxg and cargo's folder.** cargo installs into `~/.cargo/bin`, which a cargo from Homebrew does not put on PATH, so cxg could build for minutes and then not be found. Setup now warns before the build, with the line to add for your shell, and does not build a cxg that is already there again.
|
|
9
|
+
- The re-apply step prints only what changed or needs doing.
|
|
10
|
+
|
|
11
|
+
## 1.9.1
|
|
12
|
+
|
|
13
|
+
- **Apply shows what it is doing.** After you choose Apply in `bravos setup`, the screen used to stay still while the tools installed, which can take several minutes because cargo compiles cxg. It now says how many steps there are, numbers each one, and shows a running clock and the step it is on.
|
|
14
|
+
- **Fixed:** two agent sessions starting at the same moment could build the same code graph twice.
|
|
15
|
+
|
|
5
16
|
## 1.9.0
|
|
6
17
|
|
|
7
18
|
1.9 makes **`bravos setup`** the one command for setting Bravos up. It looks at this machine and the repository you are in and does only what is missing.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// @comment -- "The background code graph build. A graph is keyed to the commit it was built at, so after every commit there is none, and until now only a person or an agent told to do so rebuilt it. When the session hook finds no graph for the commit, it starts one quiet build here: a detached process that runs `bravos graph build <root> --scip no-exec` (no model, no network, and no-exec means the repository's own build scripts are never run), records how it ended, tells bravos watch, and exits. One build per repository at a time, whatever the number of sessions: the runner takes an exclusive lock under $BRAVOS_HOME/autobuild/<repository>/ before it builds. It starts only on the Team plan, only in a repository that installed Bravos (never from the user-level or plugin copy of the hook), never in CI, and never when BRAVOS_GRAPH_AUTOBUILD=off. A build that failed is not retried for the same commit for six hours."
|
|
2
2
|
import { spawn, spawnSync } from 'node:child_process';
|
|
3
3
|
import { createHash } from 'node:crypto';
|
|
4
|
-
import { existsSync,
|
|
4
|
+
import { existsSync, linkSync, mkdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
5
5
|
import { join } from 'node:path';
|
|
6
6
|
import { fileURLToPath } from 'node:url';
|
|
7
7
|
import { bravosHome } from './licence.mjs';
|
|
@@ -43,10 +43,22 @@ const alive = (pid) => {
|
|
|
43
43
|
|
|
44
44
|
const justBuilt = (last, sha, now) => !!last && last.ok === true && last.sha === sha && typeof last.at === 'number' && now - last.at >= 0 && now - last.at < JUST_BUILT_MS;
|
|
45
45
|
|
|
46
|
+
/** A lock can be seen before its contents are (a runner of 1.8 created it empty and filled it after): one that young is a build starting, not a dead one. */
|
|
47
|
+
export const LOCK_SETTLE_MS = 10 * 1000;
|
|
48
|
+
|
|
46
49
|
/** The build running for this repository, if any: a lock whose process is alive and which is not older than a build can be. */
|
|
47
50
|
export function runningBuild(dir, now = Date.now()) {
|
|
48
51
|
const lock = dir ? readJson(join(dir, 'lock')) : null;
|
|
49
|
-
if (!lock || typeof lock.at !== 'number')
|
|
52
|
+
if (!lock || typeof lock.at !== 'number') {
|
|
53
|
+
// @comment -- "A lock with no readable contents is a build starting if it was made in the last few seconds, and a dead one's only after that; read sooner as dead, a second runner removed it and built too."
|
|
54
|
+
try {
|
|
55
|
+
const made = statSync(join(dir, 'lock')).mtimeMs;
|
|
56
|
+
if (now - made < LOCK_SETTLE_MS) return { pid: null, sha: null, at: made };
|
|
57
|
+
} catch {
|
|
58
|
+
/* no lock */
|
|
59
|
+
}
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
50
62
|
return alive(lock.pid) && now - lock.at < LOCK_STALE_MS ? { pid: lock.pid, sha: typeof lock.sha === 'string' ? lock.sha : null, at: lock.at } : null;
|
|
51
63
|
}
|
|
52
64
|
|
|
@@ -94,15 +106,17 @@ export function runBuild(root, dir, sha, { env = process.env, now = () => Date.n
|
|
|
94
106
|
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
95
107
|
// A lock left by a build that died is cleared first; a live one stops us.
|
|
96
108
|
if (existsSync(lock) && !runningBuild(dir, now())) rmSync(lock, { force: true });
|
|
97
|
-
|
|
109
|
+
// @comment -- "The lock is created with its contents already in it: written to a file of this process's own, then hard-linked to the lock name, which fails if the lock exists. Created empty and filled afterwards, a second runner could read it in between, take the empty lock for one a dead build left, remove it and build as well: two sessions starting together then built the same graph twice."
|
|
110
|
+
const mine = `${lock}.${process.pid}`;
|
|
98
111
|
try {
|
|
99
|
-
|
|
112
|
+
writeFileSync(mine, JSON.stringify({ pid: process.pid, sha, at: now() }), { mode: 0o600 });
|
|
113
|
+
linkSync(mine, lock);
|
|
100
114
|
} catch {
|
|
101
115
|
return { ran: false };
|
|
116
|
+
} finally {
|
|
117
|
+
rmSync(mine, { force: true });
|
|
102
118
|
}
|
|
103
119
|
try {
|
|
104
|
-
writeFileSync(fd, JSON.stringify({ pid: process.pid, sha, at: now() }));
|
|
105
|
-
closeSync(fd);
|
|
106
120
|
// Another runner may have finished this very commit between our session's probe and now: one build is enough.
|
|
107
121
|
if (justBuilt(readJson(join(dir, 'last.json')), sha, now())) return { ran: false };
|
|
108
122
|
logWatchEvent(root, { summary: `code graph: building in the background for ${sha}`, keys: ['graph'] });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bugb-technologies/bravos",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.2",
|
|
4
4
|
"description": "Skills pack and installer that make Claude Code and Codex power users of guardlink (threat-model-as-code) and cert-x-gen (pentest-as-code).",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"security",
|