@bugb-technologies/bravos 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/setup.js +26 -14
  2. package/package.json +1 -1
package/dist/setup.js CHANGED
@@ -3,7 +3,7 @@ import { spawnSync } from 'node:child_process';
3
3
  import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
4
4
  import { join } from 'node:path';
5
5
  import { bundleEnvironment, hostTarget, install, missingPaths, staged, VERSIONS } from './artifacts.js';
6
- import { graphBin } from './codegraph.js';
6
+ import { graphBin, graphEnv } from './codegraph.js';
7
7
  import { whichBin } from './guardlink.js';
8
8
  import { findAnalyzer } from './graphbin.js';
9
9
  import { licenceLib, requireFeature } from './licence.js';
@@ -100,20 +100,32 @@ export async function runSast(root, env, opts = {}) {
100
100
  const runDir = join(base, run);
101
101
  mkdirSync(runDir, { recursive: true });
102
102
  const sha = spawnSync('git', ['rev-parse', 'HEAD'], { cwd: root, encoding: 'utf8', timeout: 5000 }).stdout?.trim() || null;
103
- const codegraph = opts.codegraph ?? (graphBin('codegraph-mcp', env) ? 'reuse' : 'off');
104
- const argv = ['analyze', root, '--ci', '--fail-on', 'never', '--allow-incomplete-analysis', '--codegraph', codegraph, '--scip', opts.scip ?? 'off', '-f', 'json,sarif', '-o', join(runDir, 'report')];
105
- if (opts.scope?.length)
106
- argv.push('--scope', opts.scope.join(','));
107
- if (opts.exclude?.length)
108
- argv.push('--exclude', opts.exclude.join(','));
109
- if (opts.minSeverity)
110
- argv.push('--min-severity', opts.minSeverity);
111
- if (opts.timeoutS)
112
- argv.push('--timeout', String(Math.max(1, opts.timeoutS - 1)));
113
- const runEnv = dir ? bundleEnvironment(dir, env) : env;
114
- const r = spawnSync(bin, argv, { cwd: root, env: runEnv, encoding: 'utf8', timeout: (opts.timeoutS ?? 1800) * 1000, maxBuffer: 64 * 1024 * 1024, stdio: ['ignore', 'pipe', 'pipe'] });
103
+ let codegraph = opts.codegraph ?? (graphBin('codegraph-mcp', env) ? 'reuse' : 'off');
104
+ const argvFor = (graph) => {
105
+ const a = ['analyze', root, '--ci', '--fail-on', 'never', '--allow-incomplete-analysis', '--codegraph', graph, '--scip', opts.scip ?? 'off', '-f', 'json,sarif', '-o', join(runDir, 'report')];
106
+ if (opts.scope?.length)
107
+ a.push('--scope', opts.scope.join(','));
108
+ if (opts.exclude?.length)
109
+ a.push('--exclude', opts.exclude.join(','));
110
+ if (opts.minSeverity)
111
+ a.push('--min-severity', opts.minSeverity);
112
+ if (opts.timeoutS)
113
+ a.push('--timeout', String(Math.max(1, opts.timeoutS - 1)));
114
+ return a;
115
+ };
116
+ // @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."
117
+ const runEnv = dir ? bundleEnvironment(dir, graphEnv(env)) : graphEnv(env);
118
+ 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'] });
119
+ let r = spawn(codegraph);
120
+ const notes = [];
121
+ // No graph built for this commit yet: reuse refuses outright. Scan without reachability rather than fail, and say how to get it.
122
+ if (codegraph === 'reuse' && r.status === 3 && /CodeGraph unavailable|No CodeGraph/i.test(`${r.stdout}\n${r.stderr}`)) {
123
+ 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');
124
+ codegraph = 'off';
125
+ r = spawn(codegraph);
126
+ }
115
127
  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');
116
- 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')}`];
128
+ 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];
117
129
  if (r.status !== 0 && r.status !== 1)
118
130
  lines.push(` ${(r.stderr || r.stdout || '').trim().split('\n').slice(-3).join('\n ')}`);
119
131
  lines.push(' next: bravos sast candidates');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bugb-technologies/bravos",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
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",