@bugb-technologies/bravos 1.17.1 → 1.17.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/setup.js +49 -9
- package/docs/UPGRADING.md +13 -0
- package/hooks/lib/briefing.mjs +14 -20
- package/hooks/session-start.mjs +2 -2
- package/package.json +1 -1
package/dist/setup.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// @comment -- "bravos setup: puts the binaries bravos drives onto this machine. The analyzer and the code graph are licensed bundles fetched through the account portal (artifacts.ts); guardlink and cxg are free CLIs installed with their own package managers. --check reports without changing anything, --dry-run says what would run, and nothing is fetched or installed without a licence for it. Also the SAST runner: `bravos sast run` invokes the staged analyzer with the argv the Python CLI used and writes the run folder the briefing and `bravos sast` read."
|
|
2
2
|
import { checkProofTool, formatProofTool } from './proof-tools.js';
|
|
3
3
|
import { spawnSync } from 'node:child_process';
|
|
4
|
-
import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
4
|
+
import { existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
|
5
5
|
import { isAbsolute, join } from 'node:path';
|
|
6
6
|
import { bundleEnvironment, hostTarget, install, missingPaths, olderThan, staged, stagedVersion, VERSIONS } from './artifacts.js';
|
|
7
|
-
import { graphBin, graphEnv } from './codegraph.js';
|
|
7
|
+
import { graphBin, graphEnv, graphStore } from './codegraph.js';
|
|
8
8
|
import { whichBin } from './guardlink.js';
|
|
9
9
|
import { findAnalyzer } from './graphbin.js';
|
|
10
10
|
import { licenceLib, requireFeature } from './licence.js';
|
|
@@ -135,7 +135,43 @@ export function selfTest(kind, dir, env) {
|
|
|
135
135
|
}
|
|
136
136
|
return out;
|
|
137
137
|
}
|
|
138
|
-
// @comment -- "
|
|
138
|
+
// @comment -- "Whether this process can create entries in dir: makes and removes one empty probe folder. False for a missing folder or one a sandbox (Codex's workspace-write, Seatbelt) refuses, which a mode-bit check would not see."
|
|
139
|
+
function canWriteIn(dir) {
|
|
140
|
+
if (!dir)
|
|
141
|
+
return false;
|
|
142
|
+
try {
|
|
143
|
+
rmSync(mkdtempSync(join(dir, '.bravos-write-probe-')), { recursive: true, force: true });
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
// @comment -- "Where a SAST run keeps its caches, all inside the repository under .bravos/sast/cache/ (owner-only, gitignored), so the run works in a sandbox that allows writes only in the workspace: the analyzer's scan workspace (--workspace), Semgrep's settings, log and version cache (SEMGREP_SETTINGS_FILE, SEMGREP_LOG_FILE, SEMGREP_VERSION_CACHE_PATH, unless set), and, when the shared code-graph store cannot be written, the analyzer's own graph store (BRAVOS_CODEGRAPH_DIR), which holds the extraction cache the analyzer writes even when it only reads a graph. The shared store stays in use while it is writable, so the analyzer keeps reading the graph bravos graph build wrote; a BRAVOS_CODEGRAPH_DIR the caller set is always used as given."
|
|
151
|
+
export function sastCache(root, env) {
|
|
152
|
+
const dir = join(root, '.bravos', 'sast', 'cache');
|
|
153
|
+
const workspace = join(dir, 'workspace');
|
|
154
|
+
const semgrep = join(dir, 'semgrep');
|
|
155
|
+
for (const d of [dir, workspace, semgrep])
|
|
156
|
+
mkdirSync(d, { recursive: true, mode: 0o700 });
|
|
157
|
+
const out = {};
|
|
158
|
+
const set = (k, v) => {
|
|
159
|
+
if (!env[k])
|
|
160
|
+
out[k] = v;
|
|
161
|
+
};
|
|
162
|
+
set('SEMGREP_SETTINGS_FILE', join(semgrep, 'settings.yml'));
|
|
163
|
+
set('SEMGREP_LOG_FILE', join(semgrep, 'semgrep.log'));
|
|
164
|
+
set('SEMGREP_VERSION_CACHE_PATH', join(semgrep, 'semgrep_version'));
|
|
165
|
+
const sharedStore = env.BRAVOS_CODEGRAPH_DIR ? null : graphStore(env);
|
|
166
|
+
const ownGraph = !env.BRAVOS_CODEGRAPH_DIR && !canWriteIn(sharedStore);
|
|
167
|
+
if (ownGraph) {
|
|
168
|
+
const store = join(dir, 'codegraph');
|
|
169
|
+
mkdirSync(store, { recursive: true, mode: 0o700 });
|
|
170
|
+
out.BRAVOS_CODEGRAPH_DIR = store;
|
|
171
|
+
}
|
|
172
|
+
return { dir, workspace, env: out, ownGraph, sharedStore };
|
|
173
|
+
}
|
|
174
|
+
// @comment -- "Runs the analyzer the way the Python adapter did: bravos-cli analyze ROOT --ci --fail-on never --allow-incomplete-analysis --codegraph <reuse when a graph store exists, auto when it keeps its own> --scip off --workspace .bravos/sast/cache/workspace -f json,sarif -o .bravos/sast/<run>/report, under the bundle's environment with its caches in the repository (sastCache), then writes meta.json (sha, exit, at, cache, graphStore) so the briefing's SAST line and bravos sast candidates read it. The exit code is a health signal; findings are read from the report."
|
|
139
175
|
export async function runSast(root, env, opts = {}) {
|
|
140
176
|
const licence = await requireFeature(env, 'sast', 'bravos sast run');
|
|
141
177
|
const dir = staged(env, 'analyzer');
|
|
@@ -155,9 +191,11 @@ export async function runSast(root, env, opts = {}) {
|
|
|
155
191
|
const runDir = join(base, run);
|
|
156
192
|
mkdirSync(runDir, { recursive: true });
|
|
157
193
|
const sha = spawnSync('git', ['rev-parse', 'HEAD'], { cwd: root, encoding: 'utf8', timeout: 5000 }).stdout?.trim() || null;
|
|
158
|
-
|
|
194
|
+
const cache = sastCache(root, env);
|
|
195
|
+
// @comment -- "A graph store of the analyzer's own starts empty, so reuse would refuse every first run: let the analyzer build the graph there (auto) unless the caller chose a mode."
|
|
196
|
+
let codegraph = opts.codegraph ?? (cache.ownGraph ? 'auto' : graphBin('codegraph-mcp', env) ? 'reuse' : 'off');
|
|
159
197
|
const argvFor = (graph) => {
|
|
160
|
-
const a = ['analyze', root, '--ci', '--fail-on', 'never', '--allow-incomplete-analysis', '--codegraph', graph, '--scip', opts.scip ?? 'off', '-f', 'json,sarif', '-o', join(runDir, 'report')];
|
|
198
|
+
const a = ['analyze', root, '--ci', '--fail-on', 'never', '--allow-incomplete-analysis', '--codegraph', graph, '--scip', opts.scip ?? 'off', '--workspace', cache.workspace, '-f', 'json,sarif', '-o', join(runDir, 'report')];
|
|
161
199
|
if (opts.scope?.length)
|
|
162
200
|
a.push('--scope', opts.scope.join(','));
|
|
163
201
|
// @comment -- ".bravos/ is always excluded: it holds the hooks bravos setup copied into the repository and the SAST runs themselves, which are bravos's code, not the customer's, and would otherwise surface as findings 'not in the threat model'."
|
|
@@ -168,22 +206,24 @@ export async function runSast(root, env, opts = {}) {
|
|
|
168
206
|
a.push('--timeout', String(Math.max(1, opts.timeoutS - 1)));
|
|
169
207
|
return a;
|
|
170
208
|
};
|
|
171
|
-
// @comment -- "The analyzer reads the code graph from the same store bravos graph build writes to, so it runs with BRAVOS_CODEGRAPH_DIR set (graphEnv): without it, --codegraph reuse looks in the analyzer's own default store and finds no graph even when one was just built."
|
|
172
|
-
const baseEnv = graphEnv(env);
|
|
209
|
+
// @comment -- "The analyzer reads the code graph from the same store bravos graph build writes to, so it runs with BRAVOS_CODEGRAPH_DIR set (graphEnv): without it, --codegraph reuse looks in the analyzer's own default store and finds no graph even when one was just built. sastCache's variables go on top: the in-repository caches, and an in-repository store only when the shared one cannot be written."
|
|
210
|
+
const baseEnv = { ...graphEnv(env), ...cache.env };
|
|
173
211
|
// @comment -- "The analyzer looks for its licence only in $BRAVOS_HOME or $BRAVOS_LICENCE, while bravos also falls back to ~/.bravos and ~/.bugb. Hand it the licence file bravos found (the path, never the token), so a SAST run never refuses a licence bravos accepted."
|
|
174
212
|
if (!env.BRAVOS_LICENCE && !env.BRAVOS_LICENSE && isAbsolute(licence.source) && existsSync(licence.source))
|
|
175
213
|
baseEnv.BRAVOS_LICENCE = licence.source;
|
|
176
214
|
const runEnv = dir ? bundleEnvironment(dir, baseEnv) : baseEnv;
|
|
177
215
|
const spawn = (graph) => spawnSync(bin, argvFor(graph), { cwd: root, env: runEnv, encoding: 'utf8', timeout: (opts.timeoutS ?? 1800) * 1000, maxBuffer: 64 * 1024 * 1024, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
178
|
-
let r = spawn(codegraph);
|
|
179
216
|
const notes = [];
|
|
217
|
+
if (cache.ownGraph)
|
|
218
|
+
notes.push(` ${cache.sharedStore ? `the shared code-graph store ${cache.sharedStore} is not writable here (a sandbox that allows writes only in the workspace?)` : 'there is no shared code-graph store'}, so the analyzer kept its graph in ${cache.env.BRAVOS_CODEGRAPH_DIR}`);
|
|
219
|
+
let r = spawn(codegraph);
|
|
180
220
|
// No graph built for this commit yet: reuse refuses outright. Scan without reachability rather than fail, and say how to get it.
|
|
181
221
|
if (codegraph === 'reuse' && r.status === 3 && /CodeGraph unavailable|No CodeGraph/i.test(`${r.stdout}\n${r.stderr}`)) {
|
|
182
222
|
notes.push(' no code graph for this commit yet, so the scan ran without reachability; bravos graph build . --scip no-exec first, then bravos sast run again, to see which findings are reached');
|
|
183
223
|
codegraph = 'off';
|
|
184
224
|
r = spawn(codegraph);
|
|
185
225
|
}
|
|
186
|
-
writeFileSync(join(runDir, 'meta.json'), JSON.stringify({ sha, base: null, scope: opts.scope?.length ? opts.scope.join(',') : 'all', exit: r.status, at: new Date().toISOString(), analyzer: bin, codegraph }, null, 2) + '\n');
|
|
226
|
+
writeFileSync(join(runDir, 'meta.json'), JSON.stringify({ sha, base: null, scope: opts.scope?.length ? opts.scope.join(',') : 'all', exit: r.status, at: new Date().toISOString(), analyzer: bin, codegraph, cache: cache.dir, graphStore: runEnv.BRAVOS_CODEGRAPH_DIR ?? null }, null, 2) + '\n');
|
|
187
227
|
const lines = [`SAST run ${run}: bravos-cli exited ${r.status ?? 'by signal'} (0 clean at the level, 1 findings, 3 licence refused or analysis failed, 4 a stage failed)`, ` report: ${join(runDir, 'report.json')}`, ...notes];
|
|
188
228
|
// @comment -- "Keep analyzer diagnostics in the gitignored run folder with owner-only permissions, including warnings on exit 0/1. Failure summaries show both ends so trailing progress cannot hide the cause; spawn errors have no stderr."
|
|
189
229
|
if (r.stderr) {
|
package/docs/UPGRADING.md
CHANGED
|
@@ -2,6 +2,19 @@
|
|
|
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. From 1.12 on you do not have to watch for releases: Bravos tells you when a newer version is out, and after you install it the agent brings each repository up to date. 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.17.2
|
|
6
|
+
|
|
7
|
+
- **Codex's first reply opens with the full Bravos card.** It is the same content as the Claude Code banner, without the logo art, in a text block:
|
|
8
|
+
- the findings and how many claims are untested;
|
|
9
|
+
- the top threats;
|
|
10
|
+
- each setup step's state, and the next step.
|
|
11
|
+
|
|
12
|
+
It still appears once per new Codex session, not on resume or compact, and not with `BRAVOS_BANNER=off`.
|
|
13
|
+
- **`bravos sast run` works inside Codex's sandbox.** Before, it failed with "extraction cache I/O failed: Operation not permitted" until you granted Full Access, because the analyzer wrote its caches outside the repository. It now keeps them in `.bravos/sast/cache/`, which is ignored by git.
|
|
14
|
+
- **The shared code graph is still used when it can be written to.** Inside a sandbox, the scan builds its own copy in that folder and says so in one line.
|
|
15
|
+
- **Any `BRAVOS_CODEGRAPH_DIR` or Semgrep path you set yourself is respected.**
|
|
16
|
+
- **To get both:** run `bravos setup` in each repository.
|
|
17
|
+
|
|
5
18
|
## 1.17.1
|
|
6
19
|
|
|
7
20
|
- **Codex now shows you the Bravos status.** Codex folds a hook's message into its warnings ("⚠ warnings · f2 to view"), and a hook cannot print to the Codex transcript, so the startup summary was easy to miss.
|
package/hooks/lib/briefing.mjs
CHANGED
|
@@ -1057,32 +1057,26 @@ export function buildSummary(inputs, opts = {}) {
|
|
|
1057
1057
|
return `${head} · ${countsLine(i.guardlink ?? {})}\n${plan ? `plan ${plan.label} · ` : ''}intent ${i.intent?.status ?? 'unknown'} · skills: ${next}\n${third}${update}`;
|
|
1058
1058
|
}
|
|
1059
1059
|
|
|
1060
|
-
// @comment -- "The
|
|
1061
|
-
export function
|
|
1062
|
-
|
|
1063
|
-
const
|
|
1064
|
-
|
|
1065
|
-
const
|
|
1066
|
-
|
|
1067
|
-
const
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
if (m.coverage) parts.push(`coverage ${num(m.coverage.percent)}%`);
|
|
1073
|
-
} else parts.push('threat counts unknown');
|
|
1074
|
-
const setup = i.root ? readSetup(i.root, i, opts.harness) : null;
|
|
1075
|
-
if (setup) {
|
|
1076
|
-
parts.push(`setup ${setup.done}/${setup.total}`);
|
|
1077
|
-
if (setup.next) parts.push(`next: ${setup.next.paid ? 'activate Team → bravos account activate' : `${setup.next.label} → ${setup.next.cta}`}`);
|
|
1060
|
+
// @comment -- "The startup picture for a harness that shows the hook's summary only as a folded warning (Codex puts a hook's systemMessage behind F2 and has no field that prints to the transcript). statusCard is the Claude Code banner without the logo art: the banner's narrow layout in the harness's skill syntax, uncoloured, its header facts packed into rows of 64, with backticks swapped for quotes so it cannot close the code block it is shown in. firstReplyStatus wraps the card as the briefing's instruction to open the agent's first reply with it, once; null on a resume or compact, or with BRAVOS_BANNER=off."
|
|
1061
|
+
export function statusCard(inputs, opts = {}) {
|
|
1062
|
+
// 68 columns leaves 64 for the layout: under the logo's 68, so the card is text only.
|
|
1063
|
+
const lines = buildBanner(inputs, { harness: opts.harness, version: opts.version, columns: 68 }).replace(/`/g, "'").split('\n');
|
|
1064
|
+
// The narrow header gives each fact its own row; in a reply, pack them into as few rows of 64 as fit.
|
|
1065
|
+
const end = lines.findIndex((l, n) => n > 1 && /^[!~─]/.test(l));
|
|
1066
|
+
if (lines[0] !== 'BRAVOS' || lines[1] !== 'by bugb' || end < 2) return lines.join('\n');
|
|
1067
|
+
const rows = ['BRAVOS by bugb'];
|
|
1068
|
+
for (const fact of lines.slice(2, end)) {
|
|
1069
|
+
const joined = rows.at(-1) + (rows.length === 1 ? ' · ' : ' · ') + fact;
|
|
1070
|
+
if (cells(joined) <= 64) rows[rows.length - 1] = joined;
|
|
1071
|
+
else rows.push(fact);
|
|
1078
1072
|
}
|
|
1079
|
-
return
|
|
1073
|
+
return [...rows, ...lines.slice(end)].join('\n');
|
|
1080
1074
|
}
|
|
1081
1075
|
|
|
1082
1076
|
export function firstReplyStatus(inputs, opts = {}) {
|
|
1083
1077
|
const source = inputs?.source;
|
|
1084
1078
|
if (source === 'resume' || source === 'compact' || opts.env?.BRAVOS_BANNER === 'off') return null;
|
|
1085
|
-
return `Status for the person: this harness shows Bravos's startup
|
|
1079
|
+
return `Status for the person: this harness shows Bravos's startup banner only as a folded warning, so open your first reply with the card below, copied exactly, inside a text code block, then answer their message; never repeat it later in the session.\n\`\`\`text\n${statusCard(inputs, opts)}\n\`\`\``;
|
|
1086
1080
|
}
|
|
1087
1081
|
|
|
1088
1082
|
// Brand palette by theme (hooks/lib/palette.mjs). Colour is truecolor ANSI, added after
|
package/hooks/session-start.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// @comment -- "SessionStart hook entry (--global: the user-level copy, silent where the repo has its own bravos hook or no .guardlink/; --briefing prints only the briefing text, for a skill that runs it by hand): reads the hook payload from stdin (bounded wait, bad input ignored; source, and Antigravity's workspacePaths), awaits collect() (read-only guardlink, git and gh facts under a shared 20 s deadline) and, where autopilot is registered, the session-start snapshot of the working tree (.bravos/watch/turn-base), and prints one JSON envelope: the briefing as additionalContext for the model, plus on a fresh start a banner as systemMessage for the human (brand-coloured; a three-line summary for Codex, whose briefing also asks the agent to open its first reply with a
|
|
1
|
+
// @comment -- "SessionStart hook entry (--global: the user-level copy, silent where the repo has its own bravos hook or no .guardlink/; --briefing prints only the briefing text, for a skill that runs it by hand): reads the hook payload from stdin (bounded wait, bad input ignored; source, and Antigravity's workspacePaths), awaits collect() (read-only guardlink, git and gh facts under a shared 20 s deadline) and, where autopilot is registered, the session-start snapshot of the working tree (.bravos/watch/turn-base), and prints one JSON envelope: the briefing as additionalContext for the model, plus on a fresh start a banner as systemMessage for the human (brand-coloured; a three-line summary for Codex, whose briefing also asks the agent to open its first reply with the banner as a text card, since Codex folds a hook's message away as a warning). With --harness agy it prints Antigravity's injectSteps instead. Always exits 0 so a session never fails to start."
|
|
2
2
|
import { closeSync, existsSync, openSync, realpathSync } from 'node:fs';
|
|
3
3
|
import { WriteStream } from 'node:tty';
|
|
4
4
|
import { dirname, join } from 'node:path';
|
|
@@ -112,7 +112,7 @@ async function main() {
|
|
|
112
112
|
// @comment -- "Starts the daily check for a newer Bravos in a detached process (hooks/lib/update-check.mjs); this session never waits on it, and the next prompt's coach or the next session reads its answer."
|
|
113
113
|
checkUpdates({ env });
|
|
114
114
|
text = buildBriefing(inputs);
|
|
115
|
-
// @comment -- "Codex shows the summary below only as a folded warning (F2) and no hook field prints to its transcript, so on a fresh start the briefing asks the agent to open its first reply with the
|
|
115
|
+
// @comment -- "Codex shows the summary below only as a folded warning (F2) and no hook field prints to its transcript, so on a fresh start the briefing asks the agent to open its first reply with the banner as a text card."
|
|
116
116
|
if (harness === 'codex') {
|
|
117
117
|
const status = firstReplyStatus(inputs, { harness, env, version: readVersion(dirname(fileURLToPath(import.meta.url))) });
|
|
118
118
|
if (status) text += '\n' + status;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bugb-technologies/bravos",
|
|
3
|
-
"version": "1.17.
|
|
3
|
+
"version": "1.17.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",
|