@bugb-technologies/bravos 1.2.1 → 1.4.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 +17 -10
- package/dist/ci.js +11 -3
- package/dist/cli.js +50 -8
- package/dist/doctor.js +4 -16
- package/dist/guide.js +5 -3
- package/dist/help.js +16 -16
- package/dist/hooks.js +21 -0
- package/dist/install-proof-tool.js +117 -0
- package/dist/proof-tools.js +29 -0
- package/dist/report/check.js +4 -1
- package/dist/report/data.js +81 -149
- package/dist/report/markdown.js +1 -1
- package/dist/report/redact.js +16 -0
- package/dist/report/runs.js +169 -0
- package/dist/resync.js +272 -0
- package/dist/setup.js +31 -16
- package/dist/start/answers.js +5 -3
- package/dist/start/index.js +28 -14
- package/dist/versions.js +4 -3
- package/docs/GUIDE.md +12 -2
- package/hooks/lib/autopilot.mjs +216 -77
- package/hooks/lib/briefing.mjs +36 -5
- package/hooks/lib/nightly-stage.mjs +66 -0
- package/hooks/lib/nightly-tools.sh +45 -0
- package/hooks/lib/pre-pr.mjs +88 -17
- package/hooks/lib/proof-tool-pins.json +12 -0
- package/hooks/lib/replay.mjs +579 -0
- package/hooks/lib/resync.mjs +78 -0
- package/hooks/lib/setup.mjs +15 -6
- package/hooks/lib/snapshot.mjs +189 -0
- package/hooks/session-start.mjs +7 -3
- package/package.json +1 -1
- package/skills/bravos/SKILL.md +2 -1
- package/skills/bravos-annotate/SKILL.md +6 -5
- package/skills/bravos-annotate/scripts/slice.mjs +15 -8
- package/skills/bravos-cicd/SKILL.md +1 -1
- package/skills/bravos-env/SKILL.md +3 -3
- package/skills/bravos-prove/SKILL.md +11 -15
- package/skills/bravos-recheck/SKILL.md +3 -3
- package/skills/bravos-report/SKILL.md +1 -1
- package/skills/bravos-resync/SKILL.md +52 -0
- package/skills/bravos-schedule/SKILL.md +1 -1
- package/skills/bravos-ship/SKILL.md +1 -1
- package/skills/bravos-templatize/SKILL.md +3 -3
- package/templates/workflows/bravos-nightly-claude.yml +131 -74
- package/templates/workflows/bravos-nightly-codex.yml +130 -73
- package/templates/workflows/bravos-pr-gate.yml +88 -14
package/README.md
CHANGED
|
@@ -22,12 +22,23 @@ mv ~/.local/bin/bravos ~/.local/bin/bravos-py
|
|
|
22
22
|
|
|
23
23
|
Or remove it (`pipx uninstall bravos` or `uv tool uninstall bravos`). `which -a bravos` should then show npm's copy first (its real path ends in `node_modules/@bugb-technologies/bravos/dist/cli.js`).
|
|
24
24
|
|
|
25
|
+
## Upgrading to 1.4
|
|
26
|
+
|
|
27
|
+
1.4 adds continuous proof: autopilot reviews changed code in already-annotated files, the active agent writes a test bound to the claim it affects, and Bravos replays it through cxg and records the result in GuardLink. After `npm install -g @bugb-technologies/bravos`:
|
|
28
|
+
|
|
29
|
+
1. **`bravos setup --tools -y`** installs GuardLink 2.6.0 and cxg 1.8.0, the first releases with the interfaces 1.4 uses, and refreshes cxg's pentest pipeline; `bravos doctor` shows both as ready. Browser replay also needs cxg's Python requirements and Playwright Chromium, which setup names.
|
|
30
|
+
2. **`bravos sync`** in each repository refreshes the skills and hooks and keeps the hooks you already turned on. It tells you when the workflows are older than this version; **`bravos sync --ci`** refreshes the ones you have, keeping their schedule, and adds none.
|
|
31
|
+
3. **Scheduled proving** in the nightly needs `choice: schedule` in `.guardlink/proving.md`, with a `— confirmed by <name>, <date>` line, merged to the default branch (bravos-prove records it). Until then the job summary says why scheduled proof is off.
|
|
32
|
+
4. **Test kits written before 1.4** are reported as needing review and `bind` and are not run until bound (bravos-templatize does it).
|
|
33
|
+
5. **Automatic local testing** starts once a `target: http://localhost:<port>/` line for your app is merged to the default branch, and needs an `origin` remote; without one, tests run only once each, with your typed authorization.
|
|
34
|
+
6. Teammates **without a licence** now see that autopilot and the pre-PR gate are installed but locked for them, with the trial command, instead of "on".
|
|
35
|
+
|
|
25
36
|
## Commands
|
|
26
37
|
|
|
27
38
|
- `bravos start [dir]`: the guided first run described above. `--again`, `--yes`, `--preset annotate|pr|everything`.
|
|
28
39
|
- `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, and `nightly-copilot` adds the GitHub Copilot nightly, which is never written unless named; `--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.
|
|
29
40
|
- `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.
|
|
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`
|
|
41
|
+
- `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` keeps compatible tools and installs missing or incompatible ones. Until the corresponding public releases are available, it builds GuardLink and CXG from the pinned upstream revisions in `hooks/lib/proof-tool-pins.json`. `--check` reports, `--dry-run` says what would happen.
|
|
31
42
|
- `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.
|
|
32
43
|
- `bravos sast run`: analyzes the repository with the staged analyzer into `.bravos/sast/<run>/` (not committed), which `bravos sast status` and `candidates` read. Takes the same `--agent`, `--pre-pr-hook`, `--ci` and `--scope` options as `init`, and never runs `guardlink init`.
|
|
33
44
|
- `bravos doctor`: check that the installed pieces and the underlying CLIs are present and healthy.
|
|
@@ -45,6 +56,7 @@ Or remove it (`pipx uninstall bravos` or `uv tool uninstall bravos`). `which -a
|
|
|
45
56
|
| `bravos-env` | Brings up a target the user owns: loopback by default, a reviewed `scope.yaml`, the human's typed authorization, a real session. |
|
|
46
57
|
| `bravos-prove` | Runs the authorized test and writes outcomes back only through guardlink's hypothesis ledger. |
|
|
47
58
|
| `bravos-recheck` | After a fix: re-verifies stale claims, replays retest kits, checks the fix added no exposure. |
|
|
59
|
+
| `bravos-resync` | When a checkout is far behind its base or a branch with annotations was left behind: carries the sidecars and definitions onto the base with `bravos resync`, maps duplicate ids, and re-reads every carried claim on code that changed since. |
|
|
48
60
|
| `bravos-sast` | Licensed static analysis (bravos-cli: Semgrep, request-to-sink taint, dependency CVEs, secrets, IaC) joined to the threat model and the code graph; says plainly when it is unavailable. Its runs land in `.bravos/sast/` (not committed), and `bravos sast candidates` hands them on: reachable findings joined to a claim give bravos-templatize and bravos-prove the route to target, findings not in the threat model are leads for bravos-annotate, and bravos-recheck rescans after a fix. A static finding is a lead; only a run confirms. |
|
|
49
61
|
| `bravos-schedule` | Recurring upkeep: an in-session `/loop`, the nightly workflow, or a cloud task you create. Never live tests. |
|
|
50
62
|
| `bravos-cicd` | Audits and writes the security workflows; fixes broken guardlink calls and script-injection risks. |
|
|
@@ -130,17 +142,12 @@ bravos-context no longer pastes thirty questions into chat. By default it assume
|
|
|
130
142
|
|
|
131
143
|
## Autopilot
|
|
132
144
|
|
|
133
|
-
`bravos init --autopilot` (or `sync --autopilot`) is for teams who would rather not ask. It registers an end-of-turn check, a Stop hook in Claude Code and Codex, plus the pre-PR gate.
|
|
134
|
-
- a file with no GuardLink annotation;
|
|
135
|
-
- a confirmed or stale claim on a changed file;
|
|
136
|
-
- open exposures on changed files.
|
|
137
|
-
|
|
138
|
-
It runs only guardlink's two fast calls (`unannotated` and `ci`, a few seconds even on a large repo); lint and diff stay in the pre-PR gate.
|
|
139
|
-
|
|
140
|
-
Each finding is raised once per session, and a missing tool or a timeout lets the turn finish.
|
|
145
|
+
`bravos init --autopilot` (or `sync --autopilot`) is for teams who would rather not ask. It registers an end-of-turn check, a Stop hook in Claude Code and Codex, plus the pre-PR gate. The agent reviews changes inside existing files as well as newly added code. It checks affected exposures and declared controls against GuardLink’s hypothesis ledger. A changed claim with prior evidence can need a retest even while its control remains documented.
|
|
141
146
|
|
|
142
147
|
How new exposures get proven is the team's call, not a fixed rule. The first time proving comes up, the agent asks once: prove automatically on your loopback target, ask each time, on a schedule, or not now; and whether cxg may generate probes through a model API. It records the person's words in `.guardlink/proving.md`, which every briefing shows and which a PR that changes it must mention. Non-loopback targets still need a reviewed scope and typed authorization each time. `BRAVOS_AUTOPILOT=off` pauses the check.
|
|
143
148
|
|
|
149
|
+
For a web claim, the coding agent authors one JavaScript probe with GuardLink’s translate method. It runs `bravos hook replay bind <kit.js>` to bind the test to the current exposure. At a verified fresh launch from the local worktree, `bravos hook replay build <loopback-url>` prints a build witness. Pass that JSON in `BRAVOS_REPLAY_BUILD` to the replay for that same launch. The normal automatic path is `bravos hook replay run <kit.js>`; a one-off run under an ask policy uses `run-once` with the exact target and current authorization. The helper executes the selected test through plain `cxg scan` with authoring disabled. A qualified result on the bound local build is recorded in GuardLink; remote or unidentified builds produce observations only. Raw run evidence stays outside Git. `bravos doctor` and `bravos setup --check` check the GuardLink and CXG command interfaces needed for this path.
|
|
150
|
+
|
|
144
151
|
## User-level install and one copy of each skill
|
|
145
152
|
|
|
146
153
|
`bravos init --global` (and `bravos sync --global` after an upgrade) installs bravos for your user rather than a repo: the skills once in `~/.claude/skills`, linked from `~/.agents/skills` for Codex and other shared-root agents, the session-start hook in `~/.bravos/hooks` registered in `~/.claude/settings.json` and `~/.codex/hooks.json`, and guardlink MCP in `~/.codex/config.toml`. The user hook is quiet in any repo that has its own bravos hook or no `.guardlink/`, so it briefs only repos with a threat model that bravos is not installed in. It is personal: teammates get bravos through `bravos init` in the repo. Because Claude Code prefers personal skills over a repo's, `bravos sync` in any repo also brings an existing user-level install to the same version, so an older personal copy never stands in for the repo's; it never creates one, and `BRAVOS_SYNC_GLOBAL=off` keeps the two separate.
|
|
@@ -187,7 +194,7 @@ With `--pre-pr-hook`, every `gh pr create` and `gh pr ready` an agent runs first
|
|
|
187
194
|
## Workflows (`bravos init --ci`)
|
|
188
195
|
|
|
189
196
|
- `bravos-pr-gate.yml`: the bravos-ship gate on every pull request, with the same rulings as the pre-PR hook (lint errors, undisclosed new exposure by id, a confirmed claim on a changed file without a `@ticket`; a gate input that fails is "unknown" and fails the job). guardlink and jq only, no model, no secret. Uploads guardlink's SARIF to code scanning (skipped for fork PRs).
|
|
190
|
-
- `bravos-nightly-claude.yml` / `bravos-nightly-codex.yml`: a coding agent covers the next slice of unannotated files, the lint gate checks it, and the job opens one small PR. Keep the one for your harness.
|
|
197
|
+
- `bravos-nightly-claude.yml` / `bravos-nightly-codex.yml`: a coding agent covers the next slice of unannotated files, the lint gate checks it, and the job opens one small PR. Keep the one for your harness. When the team has enabled scheduled proving, the job also replays eligible, bound JS kits on its reviewed target. Set BRAVOS_SCAN_TARGET and configure any test identity secrets that the kits require.
|
|
191
198
|
- `bravos-nightly-copilot.yml` + `copilot-setup-steps.yml` (only with `--workflows nightly-copilot`): for teams on GitHub Copilot. The scheduled job opens one issue and assigns it to Copilot's cloud agent, which annotates the next slice on the team's Copilot plan and opens the pull request; the PR gate checks it. Needs the repo secret `COPILOT_ASSIGN_TOKEN` (a Copilot user's personal access token: GitHub assigns Copilot only with a user's token) and `BRAVOS_LICENCE` as an Agents secret.
|
|
192
199
|
|
|
193
200
|
## Install as a plugin (after 1.0)
|
package/dist/ci.js
CHANGED
|
@@ -23,7 +23,7 @@ export function withCadence(content, cadence) {
|
|
|
23
23
|
return content.replace(/^(\s*- cron: )'[^']*'/m, `$1'${CRON[cadence]}'`);
|
|
24
24
|
}
|
|
25
25
|
// @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."
|
|
26
|
-
// @comment -- "Only the workflows named in `only`
|
|
26
|
+
// @comment -- "Only the workflows named in `only` are written; without it, init writes the defaults and a sync (installedOnly) refreshes only the bravos workflows already installed. `cadence` rewrites the nightly's cron line before the file is hashed and locked; without it a refresh keeps the cron the installed nightly already has."
|
|
27
27
|
export function writeWorkflows(root, opts = {}) {
|
|
28
28
|
const src = join(opts.templates ?? templatesDir(), 'workflows');
|
|
29
29
|
const report = { written: [], updated: [], unchanged: [], skipped: [] };
|
|
@@ -32,7 +32,12 @@ export function writeWorkflows(root, opts = {}) {
|
|
|
32
32
|
const lock = readLock(root);
|
|
33
33
|
const record = {};
|
|
34
34
|
const installed = (w) => WORKFLOW_FILES[w].some((f) => lock.files[`.github/workflows/${f}`] !== undefined);
|
|
35
|
-
|
|
35
|
+
// A sync refreshes the bravos workflows the repo already has; it never adds one nobody chose (a Codex nightly
|
|
36
|
+
// with no OPENAI_API_KEY fails every night). With none installed yet, --ci writes the defaults, as init does.
|
|
37
|
+
const anyInstalled = WORKFLOW_NAMES.some(installed);
|
|
38
|
+
const wanted = opts.only ?? (opts.installedOnly && anyInstalled
|
|
39
|
+
? WORKFLOW_NAMES.filter(installed)
|
|
40
|
+
: WORKFLOW_NAMES.filter((w) => !OPT_IN_WORKFLOWS.includes(w) || installed(w)));
|
|
36
41
|
const files = new Set(wanted.flatMap((w) => WORKFLOW_FILES[w]));
|
|
37
42
|
for (const name of readdirSync(src).filter((n) => n.endsWith('.yml')).sort()) {
|
|
38
43
|
if (!files.has(name))
|
|
@@ -40,7 +45,10 @@ export function writeWorkflows(root, opts = {}) {
|
|
|
40
45
|
const path = `.github/workflows/${name}`;
|
|
41
46
|
const abs = join(root, path);
|
|
42
47
|
const raw = readFileSync(join(src, name), 'utf8');
|
|
43
|
-
|
|
48
|
+
// A refresh keeps the schedule the repo already runs unless --schedule names a new one.
|
|
49
|
+
const existingCron = !opts.cadence && name.startsWith('bravos-nightly-') && existsSync(abs) ? /^\s*- cron: '([^']*)'/m.exec(readFileSync(abs, 'utf8'))?.[1] : undefined;
|
|
50
|
+
const content = Buffer.from(opts.cadence && name.startsWith('bravos-nightly-') ? withCadence(raw, opts.cadence)
|
|
51
|
+
: existingCron ? raw.replace(/^(\s*- cron: )'[^']*'/m, `$1'${existingCron}'`) : raw);
|
|
44
52
|
const hash = sha256(content);
|
|
45
53
|
let status = 'written';
|
|
46
54
|
if (existsSync(abs)) {
|
package/dist/cli.js
CHANGED
|
@@ -3,6 +3,7 @@ import { execFileSync } from 'node:child_process';
|
|
|
3
3
|
import { existsSync, mkdirSync, readFileSync, realpathSync, rmSync } from 'node:fs';
|
|
4
4
|
import { resolve, join } from 'node:path';
|
|
5
5
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
6
|
+
import { checkProofTool, formatProofTool } from './proof-tools.js';
|
|
6
7
|
import { DOCTOR_HELP, INIT_HELP, PROGRAM_HELP, SYNC_HELP } from './help.js';
|
|
7
8
|
import { Command, CommanderError, InvalidArgumentError, Option } from 'commander';
|
|
8
9
|
import { CADENCES, CRON, WORKFLOW_NAMES, writeWorkflows } from './ci.js';
|
|
@@ -19,7 +20,7 @@ import { GUIDE_TOPIC_IDS, renderGuide, renderGuideMarkdown } from './guide.js';
|
|
|
19
20
|
import { detectHarnesses } from './detect.js';
|
|
20
21
|
import { formatDoctor, runDoctor, withLicence } from './doctor.js';
|
|
21
22
|
import { ensureGuardlink, registerPrePr, whichBin, writeScope } from './guardlink.js';
|
|
22
|
-
import { installHook } from './hooks.js';
|
|
23
|
+
import { installHook, installedOptIns } from './hooks.js';
|
|
23
24
|
import { activate, importLicence } from './account.js';
|
|
24
25
|
import { listDevices, logout, refresh as refreshDevice, revokeDevice } from './device.js';
|
|
25
26
|
import * as graph from './codegraph.js';
|
|
@@ -44,7 +45,7 @@ function parseWorkflows(value) {
|
|
|
44
45
|
}
|
|
45
46
|
return out;
|
|
46
47
|
}
|
|
47
|
-
const GUARDLINK_HINT = 'guardlink: not found on PATH —
|
|
48
|
+
const GUARDLINK_HINT = 'guardlink: not found on PATH — run bravos setup --tools -y';
|
|
48
49
|
// Antigravity reads the shared .agents/ root; opencode and omp get their own files on top of a skills root.
|
|
49
50
|
const AGENT_MAP = { claude: 'claude', codex: 'agents', agy: 'agents', opencode: 'opencode', omp: 'omp' };
|
|
50
51
|
// @comment -- "Parses --agent <claude,codex>; codex maps to the .agents harness and anything else is a usage error."
|
|
@@ -185,6 +186,15 @@ function pipeline(root, io, opts, withGuardlink, lines) {
|
|
|
185
186
|
lines.push(`omp: skipped ${omp.path} — ${omp.reason}`);
|
|
186
187
|
else if (omp.status !== 'absent')
|
|
187
188
|
lines.push(`omp: ${omp.path} ${omp.status} (banner and briefing at session start)`);
|
|
189
|
+
// A hook the repo already registers stays registered: sync re-applies what is installed, so an
|
|
190
|
+
// opt-in is given once, not on every sync (removing one is bravos uninstall, or editing the settings).
|
|
191
|
+
const installed = installedOptIns(root);
|
|
192
|
+
const autopilotKept = !opts.autopilot && installed.autopilot;
|
|
193
|
+
const prePrKept = !opts.prePrHook && !opts.autopilot && installed.prePr && !installed.autopilot;
|
|
194
|
+
if (autopilotKept)
|
|
195
|
+
opts.autopilot = true;
|
|
196
|
+
if (prePrKept)
|
|
197
|
+
opts.prePrHook = true;
|
|
188
198
|
// Autopilot is the pre-PR gate plus the end-of-turn check.
|
|
189
199
|
if (opts.autopilot)
|
|
190
200
|
opts.prePrHook = true;
|
|
@@ -242,7 +252,7 @@ function pipeline(root, io, opts, withGuardlink, lines) {
|
|
|
242
252
|
}
|
|
243
253
|
let workflowWritten = [];
|
|
244
254
|
if (opts.ci || opts.workflows || opts.schedule) {
|
|
245
|
-
const wf = writeWorkflows(root, { force: opts.force, dryRun, only: opts.workflows, cadence: opts.schedule });
|
|
255
|
+
const wf = writeWorkflows(root, { force: opts.force, dryRun, only: opts.workflows, cadence: opts.schedule, installedOnly: !withGuardlink });
|
|
246
256
|
if (opts.schedule)
|
|
247
257
|
lines.push(`Nightly schedule: ${opts.schedule} (cron ${CRON[opts.schedule]}, UTC)`);
|
|
248
258
|
lines.push(`Workflows: ${wf.written.length} written, ${wf.updated.length} updated, ${wf.unchanged.length} unchanged, ${wf.skipped.length} skipped`);
|
|
@@ -250,12 +260,22 @@ function pipeline(root, io, opts, withGuardlink, lines) {
|
|
|
250
260
|
lines.push(` skipped ${s.path} — ${s.reason}`);
|
|
251
261
|
workflowWritten = [...wf.written, ...wf.updated];
|
|
252
262
|
}
|
|
263
|
+
else if (!withGuardlink) {
|
|
264
|
+
// A plain sync leaves workflows alone, but says when the installed ones are older than this bravos.
|
|
265
|
+
const stale = writeWorkflows(root, { dryRun: true, installedOnly: true }).updated;
|
|
266
|
+
if (stale.length)
|
|
267
|
+
lines.push(`Workflows: ${stale.length} bravos workflow(s) are older than this bravos (${stale.join(', ')}); run bravos sync --ci to refresh them.`);
|
|
268
|
+
}
|
|
253
269
|
const cursorWritten = cursor.status === 'written' || cursor.status === 'updated' ? [cursor.path] : [];
|
|
254
270
|
const ompWritten = omp.status === 'written' || omp.status === 'updated' ? [omp.path] : [];
|
|
255
271
|
const ocWritten = oc.status === 'done' ? [...oc.written, ...(oc.mcpAdded.length ? [OPENCODE_CONFIG] : [])] : [];
|
|
256
272
|
const written = [...skills.written, ...skills.updated, ...mirror.written, ...mirror.updated, ...cursorWritten, ...ompWritten, ...ocWritten, ...workflowWritten, ...hook.copied, ...hook.registered.map((r) => r.file), ...guardlinkWritten];
|
|
257
273
|
lines.push(...gitignoreWarnings(root, written, io.env));
|
|
258
|
-
if (
|
|
274
|
+
if (autopilotKept)
|
|
275
|
+
lines.push('autopilot: kept (already installed); BRAVOS_AUTOPILOT=off pauses the check.');
|
|
276
|
+
else if (prePrKept)
|
|
277
|
+
lines.push('pre-PR gate: kept (already installed).');
|
|
278
|
+
if (opts.autopilot && !autopilotKept) {
|
|
259
279
|
lines.push('autopilot on: an end-of-turn check (Stop hook) sends the agent back once when changed code lacks annotations, sits under a confirmed or stale claim, or adds exposures; the pre-PR gate checks every gh pr create / gh pr ready.');
|
|
260
280
|
lines.push('autopilot: the first time proving comes up, the agent asks you once how you want it handled and records your answer in .guardlink/proving.md. BRAVOS_AUTOPILOT=off pauses the check.');
|
|
261
281
|
}
|
|
@@ -526,17 +546,18 @@ export function buildProgram(io, result) {
|
|
|
526
546
|
}
|
|
527
547
|
lines.push(JSON.stringify(opts.json ? a : a.result, null, 2));
|
|
528
548
|
}));
|
|
529
|
-
// @comment -- "bravos hook <name> runs one of the
|
|
549
|
+
// @comment -- "bravos hook <name> runs one of the scripts this install ships (session-start, pre-pr, autopilot, replay) with the given arguments and stdin passed through; plugin skills use it where the repository has no .bravos/hooks/ copy. Only allowlisted entry points run; the script's own exit code is returned."
|
|
530
550
|
program
|
|
531
551
|
.command('hook <name> [args...]')
|
|
532
|
-
.description('Run one of bravos\'s hook scripts from this install (session-start, pre-pr, autopilot), e.g. `bravos hook session-start --briefing` or `bravos hook pre-pr --check`: what plugin installs use where the repository has no .bravos/hooks/.')
|
|
552
|
+
.description('Run one of bravos\'s hook scripts from this install (session-start, pre-pr, autopilot, replay), e.g. `bravos hook session-start --briefing` or `bravos hook pre-pr --check`: what plugin installs use where the repository has no .bravos/hooks/.')
|
|
533
553
|
.allowUnknownOption()
|
|
534
554
|
.helpOption(false)
|
|
535
555
|
.action((name, args) => guarded((lines) => {
|
|
536
|
-
const known = ['session-start', 'pre-pr', 'autopilot'];
|
|
556
|
+
const known = ['session-start', 'pre-pr', 'autopilot', 'replay'];
|
|
537
557
|
if (!known.includes(name))
|
|
538
558
|
throw new BravosError(`unknown hook '${name}'; use ${known.join(', ')}`);
|
|
539
|
-
const
|
|
559
|
+
const script = name === 'replay' ? 'lib/replay.mjs' : `${name}.mjs`;
|
|
560
|
+
const r = spawnSync(process.execPath, [pathJoin(hooksDir(), script), ...args], { env: io.env, encoding: 'utf8', stdio: ['inherit', 'pipe', 'pipe'], maxBuffer: 16 * 1024 * 1024 });
|
|
540
561
|
if (r.stdout)
|
|
541
562
|
lines.push(r.stdout.replace(/\n$/, ''));
|
|
542
563
|
if (r.stderr)
|
|
@@ -612,6 +633,8 @@ export function buildProgram(io, result) {
|
|
|
612
633
|
const L = await licenceLib();
|
|
613
634
|
const v = L.status(io.env);
|
|
614
635
|
lines.push(formatDoctor(withLicence(runDoctor(dirArg(dir), io.env), L.planLine(v), v.licensed)));
|
|
636
|
+
for (const name of ['guardlink', 'cxg'])
|
|
637
|
+
lines.push(formatProofTool(checkProofTool(name, io.env)));
|
|
615
638
|
}));
|
|
616
639
|
program
|
|
617
640
|
.command('uninstall [dir]')
|
|
@@ -706,6 +729,25 @@ export function buildProgram(io, result) {
|
|
|
706
729
|
}
|
|
707
730
|
lines.push('', s.next ? `Next: ${s.next.label} — ${s.next.how}` : 'Everything bravos can use here is on.', 'More: bravos guide · bravos guide roles · bravos guide tasks', 'Live view: bravos watch (in a second terminal pane)');
|
|
708
731
|
}));
|
|
732
|
+
program
|
|
733
|
+
.command('resync [dir]')
|
|
734
|
+
.description('Carry GuardLink annotation work from another branch or commit onto this checkout (external mode sidecars and the definitions they need): a dry run unless --apply; then reanchors, validates and lists what to re-read. --list shows idle branches with annotation work the base lacks. Runs no model.')
|
|
735
|
+
.option('--from <ref>', 'the branch or commit whose annotation work to carry here')
|
|
736
|
+
.option('--apply', 'write the sidecars and definitions, then reanchor and validate')
|
|
737
|
+
.option('--list', 'show this checkout\'s staleness and the idle branches with annotation work not on the base')
|
|
738
|
+
.option('--json', 'print the report as JSON (bravos.resync/v1)')
|
|
739
|
+
.action((dir, opts) => guardedAsync(async (lines) => {
|
|
740
|
+
const root = dirArg(dir);
|
|
741
|
+
const r = await import('./resync.js');
|
|
742
|
+
if (opts.list) {
|
|
743
|
+
lines.push(...(await r.listStranded(root, io.env)));
|
|
744
|
+
return;
|
|
745
|
+
}
|
|
746
|
+
if (!opts.from)
|
|
747
|
+
throw new BravosError('bravos resync: name the work to carry with --from <branch or commit>, or use --list to find it');
|
|
748
|
+
const report = r.resync(root, opts.from, { apply: !!opts.apply, env: io.env });
|
|
749
|
+
lines.push(...(opts.json ? [JSON.stringify(report, null, 2)] : r.formatReport(report)));
|
|
750
|
+
}));
|
|
709
751
|
program
|
|
710
752
|
.command('watch [dir]')
|
|
711
753
|
.description('A live, read-only view of the repository\'s security work for a second terminal pane beside any agent: setup, open and confirmed exposures, what to test next, stale claims, the code graph, SAST, teammates\' PRs and autopilot nudges. Redraws when files change. Runs no model.')
|
package/dist/doctor.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { existsSync, readdirSync
|
|
1
|
+
import { existsSync, readdirSync } from 'node:fs';
|
|
2
2
|
import { homedir } from 'node:os';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
4
|
import { installedGuardlinkSkills, whichBin } from './guardlink.js';
|
|
5
5
|
import { graphBin } from './codegraph.js';
|
|
6
6
|
import { findAnalyzer, findLicence } from './graphbin.js';
|
|
7
|
-
import { AUTOPILOT_COMMAND, HOOK_COMMANDS, LEGACY_HOOK_COMMAND, PRE_PR_COMMAND } from './hooks.js';
|
|
7
|
+
import { AUTOPILOT_COMMAND, HOOK_COMMANDS, LEGACY_HOOK_COMMAND, PRE_PR_COMMAND, hookRegistered } from './hooks.js';
|
|
8
8
|
import { skillsRoot } from './skills.js';
|
|
9
9
|
import { resolveTheme } from './palette.js';
|
|
10
10
|
const TOOLS = [
|
|
11
|
-
{ name: 'guardlink', hint: '
|
|
12
|
-
{ name: 'cxg', hint: '
|
|
11
|
+
{ name: 'guardlink', hint: 'bravos setup --tools -y installs a compatible GuardLink' },
|
|
12
|
+
{ name: 'cxg', hint: 'bravos setup --tools -y installs a compatible CXG' },
|
|
13
13
|
{ name: 'codegraph-mcp', hint: 'bravos setup --codegraph fetches codegraph-build and codegraph-mcp (Team plan); then bravos graph build .' },
|
|
14
14
|
{ name: 'bravos-cli', hint: 'the SAST analyzer: bravos setup --analyzer fetches it (Team plan; bravos account activate starts a trial)' },
|
|
15
15
|
];
|
|
@@ -37,18 +37,6 @@ function guardlinkSkills(root, harness) {
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
// @comment -- "True when a harness settings file registers one of bravos's commands under the given hook event (the per-harness SessionStart command or its pre-0.5.0 form); unreadable or malformed files read as not registered."
|
|
40
|
-
function hookRegistered(file, event, commands) {
|
|
41
|
-
try {
|
|
42
|
-
const json = JSON.parse(readFileSync(file, 'utf8'));
|
|
43
|
-
const groups = json?.hooks?.[event];
|
|
44
|
-
if (!Array.isArray(groups))
|
|
45
|
-
return false;
|
|
46
|
-
return groups.some((g) => Array.isArray(g?.hooks) && g.hooks.some((h) => typeof h?.command === 'string' && commands.includes(h.command)));
|
|
47
|
-
}
|
|
48
|
-
catch {
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
40
|
/** Read-only environment check: PATH lookups and file reads only. */
|
|
53
41
|
// @comment -- "Read-only environment check: looks up guardlink, cxg, codegraph-mcp and bravos-cli on PATH, the optional licence, guardlink initialisation, installed bravos and guardlink playbook skills per root, and hook registration; runs nothing."
|
|
54
42
|
export function runDoctor(root, env = process.env) {
|
package/dist/guide.js
CHANGED
|
@@ -51,7 +51,7 @@ export const GUIDE_TOPICS = [
|
|
|
51
51
|
{
|
|
52
52
|
name: 'Hands-off: autopilot',
|
|
53
53
|
body: [
|
|
54
|
-
'bravos init --autopilot (or sync --autopilot) makes upkeep happen without anyone asking. At
|
|
54
|
+
'bravos init --autopilot (or sync --autopilot) makes upkeep happen without anyone asking. At turn end the agent reviews changed code, including edits inside annotated files. It follows the recorded proving preference for affected claims. The pre-PR gate runs on every gh pr create.',
|
|
55
55
|
'Proving follows your choice, not a fixed rule: the first time it comes up the agent asks you once — prove automatically on your loopback target, ask each time, on a schedule, or not now — and records your words in .guardlink/proving.md. Say "ask me first" or "stop auto-proving" at any time to change it. Non-loopback targets still need a reviewed scope and your typed authorization every time.',
|
|
56
56
|
],
|
|
57
57
|
},
|
|
@@ -101,7 +101,7 @@ export const GUIDE_TOPICS = [
|
|
|
101
101
|
name: 'CI owner',
|
|
102
102
|
skills: ['bravos-cicd', 'bravos-schedule'],
|
|
103
103
|
body: [
|
|
104
|
-
'bravos init --ci writes the PR gate and nightly workflows. bravos-cicd audits existing workflows: broken guardlink calls, script injection from pull-request text, missing SARIF upload. The
|
|
104
|
+
'bravos init --ci writes the PR gate and nightly workflows. bravos-cicd audits existing workflows: broken guardlink calls, script injection from pull-request text, missing SARIF upload. The Claude and Codex nightlies can replay committed, bound kits when scheduled testing is authorized. The Copilot job assigns an annotation task.',
|
|
105
105
|
],
|
|
106
106
|
},
|
|
107
107
|
],
|
|
@@ -118,6 +118,7 @@ export const GUIDE_TOPICS = [
|
|
|
118
118
|
{ name: 'I wrote security-relevant code', skills: ['bravos-annotate'], body: ['Annotates what you changed to guardlink\'s evidence bar and runs the lint gate until clean.'] },
|
|
119
119
|
{ name: 'Cover the whole repo', skills: ['bravos-campaign'], body: ['Rounds of batches with subagents and rests, until the coverage goal or until you stop it.'] },
|
|
120
120
|
{ name: 'Is this exposure real?', skills: ['bravos-templatize', 'bravos-env', 'bravos-prove'], body: ['Template → authorized target → run. Only a reproduced run confirms; reading code never does.'] },
|
|
121
|
+
{ name: 'My branch moved, or I found old annotation work', skills: ['bravos-resync'], body: ['When the briefing says this checkout is far behind its base, or lists idle branches with annotation work the base lacks: saves uncommitted work in a commit, starts a branch from the base, carries the sidecars and definitions with bravos resync, maps ids that duplicate the base\'s, and re-reads every carried claim on code that changed since. Old annotations are leads until re-read.'] },
|
|
121
122
|
{ name: 'I fixed a finding', skills: ['bravos-recheck'], body: ['Re-verifies stale claims, replays the retest kit, and checks the fix added no new exposure.'] },
|
|
122
123
|
{ name: 'I am about to open a PR', skills: ['bravos-ship'], body: ['The no-mistakes gate: validate, lint since the merge base, disclose new exposure, block confirmed exploits on changed paths.'] },
|
|
123
124
|
{ name: 'Find the routes, callers or blast radius', skills: ['bravos-codegraph'], body: ['One bounded question to the code graph instead of grepping. Team plan: bravos setup --codegraph stages codegraph-mcp, then bravos graph build . indexes the repository. With it, other skills get sharper on their own: bravos-templatize targets the route and auth that actually reach each sink, bravos-recheck follows a fix\'s callers and blast radius into other files, bravos-context drafts the real public surface, and bravos-prove tests the most reachable exposures first. Without it they read the code and say so.'] },
|
|
@@ -132,7 +133,7 @@ export const GUIDE_TOPICS = [
|
|
|
132
133
|
{
|
|
133
134
|
id: 'skills',
|
|
134
135
|
title: 'Every skill',
|
|
135
|
-
summary: 'all
|
|
136
|
+
summary: 'all fifteen skills, what each does and leaves for the next',
|
|
136
137
|
items: [
|
|
137
138
|
{ name: 'bravos', body: ['Front door: reads the security picture, explains the evidence loop, routes to the right skill.'] },
|
|
138
139
|
{ name: 'bravos-context', body: ['Learns what the product intends from the repo and a short interview; records invariants, intended behaviour, actors, assets and boundaries.'] },
|
|
@@ -143,6 +144,7 @@ export const GUIDE_TOPICS = [
|
|
|
143
144
|
{ name: 'bravos-env', body: ['Brings up a target you own: loopback by default, a committed reviewed scope.yaml, your typed authorization, a real session captured or imported.'] },
|
|
144
145
|
{ name: 'bravos-prove', body: ['Runs the authorized test, reads cxg\'s report and exit code, writes outcomes only through guardlink\'s hypothesis ledger.'] },
|
|
145
146
|
{ name: 'bravos-recheck', body: ['After a fix: stale claims, retest-kit replay, no new exposure, what to test next.'] },
|
|
147
|
+
{ name: 'bravos-resync', body: ['A stale checkout or a left-behind branch: carries its annotation work onto the base with bravos resync, maps duplicate ids, re-reads every carried claim on changed code.'] },
|
|
146
148
|
{ name: 'bravos-sast', body: ['Licensed static analysis joined to guardlink claims and reachability; gates on findings new since the base.'] },
|
|
147
149
|
{ name: 'bravos-campaign', body: ['A goal over many rounds: disjoint batches, one subagent each, a gate per batch, rests, a final before-and-after.'] },
|
|
148
150
|
{ name: 'bravos-schedule', body: ['Recurring upkeep with each harness\'s own mechanism; never live tests from a loop.'] },
|
package/dist/help.js
CHANGED
|
@@ -11,9 +11,11 @@ What bravos is
|
|
|
11
11
|
Commands
|
|
12
12
|
init [dir] First install in a repository. Runs guardlink init if .guardlink/ is absent.
|
|
13
13
|
sync [dir] Re-apply bravos to a repository that already has it (after upgrading bravos,
|
|
14
|
-
or to add --ci / --pre-pr-hook / --scope / --autopilot later
|
|
15
|
-
guardlink init. init and sync take --global for a user-level install.
|
|
14
|
+
or to add --ci / --pre-pr-hook / --scope / --autopilot later; hooks already
|
|
15
|
+
installed stay installed). Never runs guardlink init. init and sync take --global for a user-level install.
|
|
16
16
|
doctor [dir] Read-only check of tools, licence, installed skills and hooks.
|
|
17
|
+
resync [dir] Carry annotation work from another branch onto this checkout: --from <ref>
|
|
18
|
+
(a dry run; --apply writes, reanchors and validates), or --list to find it.
|
|
17
19
|
uninstall [dir]
|
|
18
20
|
Remove bravos from a repository (--global: from your user), keeping
|
|
19
21
|
anything you edited unless --force; --dry-run lists it first.
|
|
@@ -87,6 +89,8 @@ The skills it installs (one folder each in .claude/skills/ and .agents/skills/)
|
|
|
87
89
|
bravos-prove Runs the authorized test, reads cxg's verdicts, writes outcomes back
|
|
88
90
|
only through guardlink's hypothesis ledger.
|
|
89
91
|
bravos-recheck After a fix: re-verifies stale claims, replays retest kits.
|
|
92
|
+
bravos-resync Carries annotation work a stale or abandoned branch holds onto the base,
|
|
93
|
+
then re-reads every carried claim on code that changed since.
|
|
90
94
|
bravos-sast Licensed static analysis; says plainly when it is unavailable.
|
|
91
95
|
bravos-schedule /loop while you work, the nightly workflow, or a cloud task you create.
|
|
92
96
|
bravos-cicd Writes and audits the security GitHub Actions workflows.
|
|
@@ -134,8 +138,8 @@ Session start
|
|
|
134
138
|
Autopilot (hands-off): bravos init --autopilot
|
|
135
139
|
For teams who would rather not ask. At the end of every turn a check (a Stop hook in
|
|
136
140
|
Claude Code and Codex, a few seconds) sends the agent back once when the turn's changes
|
|
137
|
-
|
|
138
|
-
|
|
141
|
+
add or change source behavior or affect a claim due for testing. The check names
|
|
142
|
+
the affected files and skill; the pre-PR gate runs on every
|
|
139
143
|
gh pr create / gh pr ready. Each finding is raised once per session; a missing tool or a
|
|
140
144
|
timeout lets the turn finish; BRAVOS_AUTOPILOT=off pauses it.
|
|
141
145
|
Proving is the team's choice, not a rule: the first time it comes up the agent asks once
|
|
@@ -239,9 +243,8 @@ Flags in depth
|
|
|
239
243
|
them up to date without the flag.
|
|
240
244
|
--autopilot
|
|
241
245
|
Upkeep without being asked. Registers an end-of-turn check (a Stop hook, Claude Code
|
|
242
|
-
and Codex)
|
|
243
|
-
|
|
244
|
-
on changed files; and the pre-PR gate (implies --pre-pr-hook), which also lints. New
|
|
246
|
+
and Codex) to review changed code in annotated and new files, plus affected claims due
|
|
247
|
+
for testing. Also registers the pre-PR gate (implies --pre-pr-hook), which also lints. New
|
|
245
248
|
exposures are handled as you choose: the first time proving comes up the agent asks
|
|
246
249
|
you once (prove automatically on your loopback target, ask each time, on a schedule,
|
|
247
250
|
or not now; and whether cxg may generate probes through a model API) and records your
|
|
@@ -278,13 +281,10 @@ Flags in depth
|
|
|
278
281
|
bravos-nightly-claude.yml Weekdays 03:17 UTC: Claude Code annotates the next slice
|
|
279
282
|
bravos-nightly-codex.yml (or Codex does), the lint gate checks it, one PR opens.
|
|
280
283
|
Keep the one for your harness and delete the other.
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
scope's host_allowlist; optional vars.BRAVOS_SCAN_AUTH +
|
|
286
|
-
secrets.BRAVOS_AUTH_STATE import a login. Otherwise it
|
|
287
|
-
skips with a notice.
|
|
284
|
+
Scheduled proof replays committed, bound JS kits under the
|
|
285
|
+
current scheduled choice and reviewed scope. Configure
|
|
286
|
+
BRAVOS_SCAN_TARGET, BRAVOS_APP_START for a local build,
|
|
287
|
+
and BRAVOS_SCAN_AUTH plus private session state for roles.
|
|
288
288
|
Needs repository secret CLAUDE_CODE_OAUTH_TOKEN (Claude Code on your Claude plan; run
|
|
289
289
|
'claude setup-token' once) or OPENAI_API_KEY (Codex), and Settings > Actions >
|
|
290
290
|
"Allow GitHub Actions to create and approve pull requests". Workflows you wrote or
|
|
@@ -343,8 +343,8 @@ Examples
|
|
|
343
343
|
export const DOCTOR_HELP = `
|
|
344
344
|
What doctor reports (read-only; writes nothing, starts nothing)
|
|
345
345
|
Tools on PATH, with an install hint for each one missing:
|
|
346
|
-
guardlink
|
|
347
|
-
cxg
|
|
346
|
+
guardlink bravos setup --tools -y
|
|
347
|
+
cxg bravos setup --tools -y
|
|
348
348
|
codegraph-mcp bravos setup --codegraph (Team plan)
|
|
349
349
|
bravos-cli bravos setup --analyzer (Team plan); the licence is BRAVOS_LICENCE or
|
|
350
350
|
licence.jwt in $BRAVOS_HOME, ~/.bravos or ~/.bugb
|
package/dist/hooks.js
CHANGED
|
@@ -111,6 +111,27 @@ function planRegistration(root, rel, regs) {
|
|
|
111
111
|
return { file: rel, changed, doc };
|
|
112
112
|
}
|
|
113
113
|
// @comment -- "The command Antigravity runs from .agents/hooks.json; --harness agy makes the hook print Antigravity's injectSteps."
|
|
114
|
+
// @comment -- "True when a harness settings file registers one of the given commands under the event; read-only, an unreadable or malformed file reads as not registered. Doctor and sync share it."
|
|
115
|
+
export function hookRegistered(file, event, commands) {
|
|
116
|
+
try {
|
|
117
|
+
const json = JSON.parse(readFileSync(file, 'utf8'));
|
|
118
|
+
const groups = json?.hooks?.[event];
|
|
119
|
+
if (!Array.isArray(groups))
|
|
120
|
+
return false;
|
|
121
|
+
return groups.some((g) => Array.isArray(g?.hooks) && g.hooks.some((h) => typeof h?.command === 'string' && commands.includes(h.command)));
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
// @comment -- "Which opt-in hooks a repository already registers for Claude Code or Codex, so sync re-applies them without the flag being given again."
|
|
128
|
+
export function installedOptIns(root) {
|
|
129
|
+
const files = [join(root, '.claude', 'settings.json'), join(root, '.codex', 'hooks.json')];
|
|
130
|
+
return {
|
|
131
|
+
autopilot: files.some((f) => hookRegistered(f, 'Stop', [AUTOPILOT_COMMAND])),
|
|
132
|
+
prePr: files.some((f) => hookRegistered(f, 'PreToolUse', [PRE_PR_COMMAND])),
|
|
133
|
+
};
|
|
134
|
+
}
|
|
114
135
|
export const AGY_HOOK_COMMAND = `${LEGACY_HOOK_COMMAND} --harness agy`;
|
|
115
136
|
export const AGY_HOOKS_FILE = '.agents/hooks.json';
|
|
116
137
|
const AGY_GROUP = { SessionStart: [{ type: 'command', command: AGY_HOOK_COMMAND, timeout: 30 }] };
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import { mkdtempSync, rmSync } from 'node:fs';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { basename, delimiter, isAbsolute, join, resolve } from 'node:path';
|
|
5
|
+
import { whichBin } from './guardlink.js';
|
|
6
|
+
import { checkProofTool } from './proof-tools.js';
|
|
7
|
+
import { BravosError } from './types.js';
|
|
8
|
+
import { PROOF_TOOL_PINS } from './versions.js';
|
|
9
|
+
// @comment -- "What setup would run for one tool, in words: the released npm or crates.io version, or a source build when the pin names a revision. Pins default to the shipped file; tests pass their own to cover both paths."
|
|
10
|
+
export function proofToolAction(name, pins = PROOF_TOOL_PINS) {
|
|
11
|
+
const { repository, revision, version } = pins[name];
|
|
12
|
+
if (name === 'guardlink')
|
|
13
|
+
return revision
|
|
14
|
+
? `build GuardLink from ${repository} at ${revision} with git and npm, then install its packed CLI globally`
|
|
15
|
+
: `npm install --global guardlink@${version}`;
|
|
16
|
+
return revision
|
|
17
|
+
? `cargo install --locked --force --git ${repository} --rev ${revision} cert-x-gen and update its pentest pipeline`
|
|
18
|
+
: `cargo install --locked --force --version =${version} cert-x-gen and update its pentest pipeline`;
|
|
19
|
+
}
|
|
20
|
+
const prerequisites = {
|
|
21
|
+
git: 'install Git and make git available on PATH',
|
|
22
|
+
npm: 'install Node.js 20 or newer with npm and make npm available on PATH',
|
|
23
|
+
tar: 'install tar for the pinned GuardLink grammar build',
|
|
24
|
+
cargo: 'install the Rust toolchain (cargo and rustc) and a native linker',
|
|
25
|
+
};
|
|
26
|
+
// @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
|
+
export function installProofTool(name, env, echo, pins = PROOF_TOOL_PINS) {
|
|
28
|
+
const pin = pins[name];
|
|
29
|
+
const installEnv = {
|
|
30
|
+
...env,
|
|
31
|
+
PATH: (env.PATH ?? '').split(delimiter).filter(isAbsolute).join(delimiter),
|
|
32
|
+
GIT_TERMINAL_PROMPT: '0',
|
|
33
|
+
};
|
|
34
|
+
for (const key of ['GIT_DIR', 'GIT_WORK_TREE', 'GIT_INDEX_FILE', 'GIT_OBJECT_DIRECTORY', 'GIT_COMMON_DIR', 'INIT_CWD', 'npm_config_local_prefix'])
|
|
35
|
+
delete installEnv[key];
|
|
36
|
+
for (const key of ['CARGO_INSTALL_ROOT', 'CARGO_HOME', 'CARGO_TARGET_DIR', 'NPM_CONFIG_PREFIX', 'npm_config_prefix']) {
|
|
37
|
+
if (installEnv[key] && !isAbsolute(installEnv[key]))
|
|
38
|
+
installEnv[key] = resolve(installEnv[key]);
|
|
39
|
+
}
|
|
40
|
+
const needed = name === 'guardlink' ? (pin.revision ? ['git', 'npm', 'tar'] : ['npm']) : ['cargo'];
|
|
41
|
+
const executables = new Map();
|
|
42
|
+
for (const command of needed) {
|
|
43
|
+
const path = whichBin(command, installEnv);
|
|
44
|
+
if (!path)
|
|
45
|
+
throw new BravosError(`${name} requires ${command}: ${prerequisites[command]}. Then run bravos setup --tools -y again.`);
|
|
46
|
+
executables.set(command, path);
|
|
47
|
+
}
|
|
48
|
+
const work = mkdtempSync(join(tmpdir(), 'bravos-tools-'));
|
|
49
|
+
function invoke(command, args, cwd, step) {
|
|
50
|
+
const result = spawnSync(executables.get(command) ?? command, args, {
|
|
51
|
+
cwd, env: installEnv, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: 32 * 1024 * 1024, timeout: 30 * 60 * 1000,
|
|
52
|
+
});
|
|
53
|
+
if (result.error || result.status !== 0) {
|
|
54
|
+
// npm/git/cargo diagnostics can include registry credentials. Name the operation so it can be retried directly.
|
|
55
|
+
const detail = result.error ? result.error.code ?? 'spawn failed' : `exit ${result.status ?? 'signal'}`;
|
|
56
|
+
const hints = {
|
|
57
|
+
cargo: 'Check cargo and rustc, the native linker, network access and the Cargo install root.',
|
|
58
|
+
git: 'Check Git and network access to the public upstream repository.',
|
|
59
|
+
npm: 'Check Node and npm, registry access, tar for grammar assets and permission to the global prefix.',
|
|
60
|
+
cxg: 'Check cxg pentest status for an existing source-managed pipeline.',
|
|
61
|
+
};
|
|
62
|
+
throw new BravosError(name + ' setup failed during ' + step + ' (' + detail + '). ' + hints[command] + ' Retry with bravos setup --tools -y.');
|
|
63
|
+
}
|
|
64
|
+
return result.stdout.trim();
|
|
65
|
+
}
|
|
66
|
+
try {
|
|
67
|
+
echo(`${name}: ${proofToolAction(name)}`);
|
|
68
|
+
if (name === 'guardlink') {
|
|
69
|
+
if (pin.revision) {
|
|
70
|
+
const src = join(work, 'guardlink');
|
|
71
|
+
invoke('git', ['init', '--quiet', src], work, 'initializing the temporary Git checkout');
|
|
72
|
+
invoke('git', ['fetch', '--quiet', '--depth=1', pin.repository, pin.revision], src, 'fetching the pinned GuardLink commit');
|
|
73
|
+
invoke('git', ['checkout', '--quiet', '--detach', 'FETCH_HEAD'], src, 'checking out GuardLink');
|
|
74
|
+
if (invoke('git', ['rev-parse', 'HEAD'], src, 'verifying the source revision') !== pin.revision) {
|
|
75
|
+
throw new BravosError('GuardLink fetched a different Git revision; installation stopped.');
|
|
76
|
+
}
|
|
77
|
+
invoke('npm', ['ci', '--include=dev', '--no-audit', '--no-fund'], src, 'installing locked GuardLink build dependencies');
|
|
78
|
+
invoke('npm', ['run', 'build'], src, 'building the CLI and grammar assets');
|
|
79
|
+
const result = invoke('npm', ['pack', '--ignore-scripts', '--json', '--pack-destination', work], src, 'packing GuardLink');
|
|
80
|
+
let packed;
|
|
81
|
+
try {
|
|
82
|
+
packed = JSON.parse(result);
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
throw new BravosError('npm pack returned an unreadable tarball manifest.');
|
|
86
|
+
}
|
|
87
|
+
const file = packed?.[0]?.filename;
|
|
88
|
+
if (typeof file !== 'string' || file !== basename(file) || !file.endsWith('.tgz') || packed.length !== 1) {
|
|
89
|
+
throw new BravosError('npm pack did not return one GuardLink tarball.');
|
|
90
|
+
}
|
|
91
|
+
invoke('npm', ['install', '--global', join(work, file)], work, 'installing the packed CLI in the npm global prefix');
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
invoke('npm', ['install', '--global', `guardlink@${pin.version}`], work, 'installing the pinned GuardLink npm release');
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
const args = pin.revision ? ['--git', pin.repository, '--rev', pin.revision] : ['--version', '=' + pin.version];
|
|
99
|
+
invoke('cargo', ['install', '--locked', '--force', ...args, 'cert-x-gen'], work, 'building and installing the pinned CXG binary');
|
|
100
|
+
}
|
|
101
|
+
// Check the user's PATH again after installation, before invoking any post-install command on the selected binary.
|
|
102
|
+
const found = whichBin(name, installEnv);
|
|
103
|
+
const status = checkProofTool(name, installEnv);
|
|
104
|
+
if (!found || status.status !== 'ready') {
|
|
105
|
+
const destination = name === 'guardlink' ? 'the bin directory under npm prefix --global' : 'the bin directory under your Cargo install root (normally ~/.cargo/bin)';
|
|
106
|
+
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.`);
|
|
107
|
+
}
|
|
108
|
+
if (name === 'cxg') {
|
|
109
|
+
executables.set('cxg', found);
|
|
110
|
+
invoke('cxg', ['--disable-update-check', 'pentest', 'update'], work, 'synchronizing the embedded pentest pipeline');
|
|
111
|
+
}
|
|
112
|
+
return found;
|
|
113
|
+
}
|
|
114
|
+
finally {
|
|
115
|
+
rmSync(work, { recursive: true, force: true });
|
|
116
|
+
}
|
|
117
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { whichBin } from './guardlink.js';
|
|
4
|
+
// @comment -- "Checks the CLI interface in the executable that will run. Release and development binaries can have identical version strings. Only fixed help arguments are passed, with no shell, bounded output and a deadline (10 s: a cold start on a busy machine can take several); no URL, credentials or template is supplied."
|
|
5
|
+
export function checkProofTool(name, env, timeoutMs = 10000) {
|
|
6
|
+
const guardlink = name === 'guardlink';
|
|
7
|
+
const capability = guardlink ? 'in-session probe translation' : 'plain scan of supplied JS probes with zero model calls';
|
|
8
|
+
const binary = whichBin(name, env);
|
|
9
|
+
if (!binary)
|
|
10
|
+
return { name, capability, status: 'missing' };
|
|
11
|
+
const args = guardlink ? ['translate', '--help'] : ['--disable-update-check', 'scan', '--help'];
|
|
12
|
+
const help = spawnSync(resolve(binary), args, { env, encoding: 'utf8', timeout: timeoutMs, maxBuffer: 512 * 1024, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
13
|
+
if (help.error || help.status !== 0)
|
|
14
|
+
return { name, capability, status: 'unavailable' };
|
|
15
|
+
const flags = guardlink ? ['--stdout', '--contract', '--threat'] : ['--no-author', '--templates', '--scope-file', '--auth-dir', '--session-dir'];
|
|
16
|
+
const supported = flags.every((flag) => new RegExp('(?:^|\\s)' + flag + '(?=\\s|,|$)', 'm').test(help.stdout))
|
|
17
|
+
&& (guardlink || /supplied JS probe/i.test(help.stdout));
|
|
18
|
+
return { name, capability, status: supported ? 'ready' : 'incompatible' };
|
|
19
|
+
}
|
|
20
|
+
export function formatProofTool(check) {
|
|
21
|
+
const what = check.name + ' · ' + check.capability;
|
|
22
|
+
if (check.status === 'ready')
|
|
23
|
+
return '✔ ' + what;
|
|
24
|
+
if (check.status === 'missing')
|
|
25
|
+
return '✘ ' + what + ' — tool missing';
|
|
26
|
+
if (check.status === 'unavailable')
|
|
27
|
+
return '✘ ' + what + ' — could not read command help';
|
|
28
|
+
return '✘ ' + what + ' — install a build supporting this interface and check which executable is first on PATH';
|
|
29
|
+
}
|
package/dist/report/check.js
CHANGED
|
@@ -35,7 +35,7 @@ const STATUS_FIELDS = ['Status', 'Evidence'];
|
|
|
35
35
|
export const RETEST_FIELDS = ['Retested build', 'Replay', 'Result', 'Bypass variants', 'Legitimate behaviour'];
|
|
36
36
|
const SEVERITIES = ['critical', 'high', 'medium', 'low', 'informational', 'info'];
|
|
37
37
|
/** Ids a report may cite: EXP-n, LED-<hex>, SAST-n, CTL-n, BND-n, ACC-n, RUN-n and RUN-n/F|X|H|N-m, EDGE-n and UNR-n; in a workspace report each may carry its service as a prefix (orders:EXP-3). */
|
|
38
|
-
export const ID_RE = /(?<![\w:-])(?:[a-z0-9][a-z0-9._-]{0,40}:)?(?:RUN-\d+(?:\/[FXHN]-\d+)?|(?:EXP|SAST|CTL|BND|ACC|EDGE|UNR)-\d+|LED-[a-f0-9]{8})\b/g;
|
|
38
|
+
export const ID_RE = /(?<![\w:-])(?:[a-z0-9][a-z0-9._-]{0,40}:)?(?:RUN-\d+(?:\/[FXHN]-\d+)?|(?:EXP|SAST|CTL|BND|ACC|EDGE|UNR)-\d+|LED-[a-f0-9]{8}(?:-\d+)?)\b/g;
|
|
39
39
|
const FINDING_HEADING = /^(#{2,4})\s+(F-\d{2,3})\s*(?:—|–|-|:)\s*(.+?)\s*$/;
|
|
40
40
|
const norm = (h) => h.replace(/^\d+\.\s*/, '').trim().toLowerCase();
|
|
41
41
|
/** The value of a `**Label:**` / `**Label**:` / `- **Label:**` line, or a `| Label | value |` table row, within lines; null when absent. */
|
|
@@ -135,6 +135,9 @@ export function checkReport(md, bundle, kind) {
|
|
|
135
135
|
err('evidence-ids', `${id} says "${LEVEL_LABEL[level]}" but cites no evidence id on a Status or Evidence line`, statusLines[0]?.line ?? at);
|
|
136
136
|
else if (!evidenceIds.some((x) => supports.get(x)?.includes(level)))
|
|
137
137
|
err('evidence-level', `${id} says "${LEVEL_LABEL[level]}" but none of ${evidenceIds.join(', ')} supports it; use the level the bundle computed`, statusLines[0]?.line ?? at);
|
|
138
|
+
else if (kind !== 'retest' && evidenceIds.some(x => /(?:^|:)EXP-\d+$/.test(x) && !supports.get(x)?.includes(level))) {
|
|
139
|
+
err('evidence-level', `${id} claims an evidence level that the cited exposure does not support on the assessed revision`, statusLines[0]?.line ?? at);
|
|
140
|
+
}
|
|
138
141
|
}
|
|
139
142
|
const sev = field(block, 'Severity');
|
|
140
143
|
const sevWord = sev ? (sev.value.toLowerCase().match(/[a-z]+/)?.[0] ?? '') : '';
|