@bugb-technologies/bravos 1.5.2 → 1.5.3

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/artifacts.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import { createHash, createPublicKey, verify as cryptoVerify } from 'node:crypto';
3
3
  import { chmodSync, closeSync, existsSync, lstatSync, mkdirSync, openSync, readdirSync, readFileSync, realpathSync, renameSync, rmSync, symlinkSync, unlinkSync, writeSync } from 'node:fs';
4
4
  import { arch, platform } from 'node:os';
5
- import { dirname, join } from 'node:path';
5
+ import { basename, dirname, join } from 'node:path';
6
6
  import { gunzipSync } from 'node:zlib';
7
7
  import { refresh, userAgent } from './device.js';
8
8
  import { licenceLib } from './licence.js';
@@ -276,6 +276,36 @@ export function staged(env, kind) {
276
276
  }
277
277
  return null;
278
278
  }
279
+ // @comment -- "The version of a staged bundle: what its own BUNDLE.json says, else the version folder it sits in ($BRAVOS_HOME/<kind>/<version>/<target>), else null. Read-only; a bundle that names no version is never treated as old."
280
+ export function stagedVersion(root) {
281
+ const dotted = (v) => (typeof v === 'string' && /^\d+(\.\d+)+/.test(v) ? v : null);
282
+ try {
283
+ const said = dotted(JSON.parse(readFileSync(join(root, BUNDLE_FILE), 'utf8'))?.version);
284
+ if (said)
285
+ return said;
286
+ }
287
+ catch {
288
+ /* fall through to the folder name */
289
+ }
290
+ return dotted(basename(dirname(root)));
291
+ }
292
+ // @comment -- "Whether dotted version `have` is lower than `want`, comparing the numeric parts left to right; anything after the numbers (a pre-release tag) is ignored, and a version that does not parse is never older."
293
+ export function olderThan(have, want) {
294
+ const parts = (v) => {
295
+ const m = /^(\d+(?:\.\d+)*)/.exec(v);
296
+ return m ? m[1].split('.').map(Number) : null;
297
+ };
298
+ const a = parts(have);
299
+ const b = parts(want);
300
+ if (!a || !b)
301
+ return false;
302
+ for (let i = 0; i < Math.max(a.length, b.length); i++) {
303
+ const d = (a[i] ?? 0) - (b[i] ?? 0);
304
+ if (d !== 0)
305
+ return d < 0;
306
+ }
307
+ return false;
308
+ }
279
309
  /** The environment a staged bundle declares in BUNDLE.json: `env` (relative paths made absolute) and `path_prepend`. */
280
310
  export function bundleEnvironment(root, base) {
281
311
  const env = { ...base };
package/dist/cli.js CHANGED
@@ -560,6 +560,7 @@ export function buildProgram(io, result) {
560
560
  }
561
561
  const extra = args.filter((a) => a !== '--json');
562
562
  // The same document the Python CLI printed: {result} on an answer, {error, message, remedy} on a refusal, exit 2 when the graph is not built.
563
+ // A graph another session or a build holds is {error: graph_busy} with exit 1: only "not built" is exit 2, which is what callers rebuild on.
563
564
  const a = await askGraph(root, io.env, question, extra);
564
565
  if (!a)
565
566
  throw new BravosError('codegraph-mcp is not installed: bravos setup --codegraph fetches it');
package/dist/codegraph.js CHANGED
@@ -57,6 +57,18 @@ export class GraphUnavailable extends BravosError {
57
57
  super(message);
58
58
  }
59
59
  }
60
+ // @comment -- "The code graph is there and another process holds its lock: a second session reading the same snapshot, or a build in progress. codegraph-mcp 0.1.1 waits for the lock (20 s by default) and then answers this, with data.reason 'graph_busy'. It is never 'no graph': the remedy is to ask again, not to rebuild."
61
+ export class GraphBusy extends BravosError {
62
+ constructor(message) {
63
+ super(message);
64
+ }
65
+ }
66
+ /** What to tell a person, or an agent, when the graph answered busy. */
67
+ export const GRAPH_BUSY_REMEDY = 'another session or a build is using the code graph; ask again in a moment (do not rebuild it)';
68
+ // The server's own sentence, for an answer that reached us as text only (a stored error string).
69
+ const BUSY_TEXT = /code graph for project \S+ is busy/i;
70
+ /** Whether an error, or an error's text, is the graph's busy answer. */
71
+ export const isGraphBusy = (e) => e instanceof GraphBusy || BUSY_TEXT.test(typeof e === 'string' ? e : (e?.message ?? ''));
60
72
  // @comment -- "A minimal MCP stdio client: newline-delimited JSON-RPC 2.0 to a child codegraph-mcp --project-path ROOT. One session per question; the server is killed on close or timeout. stderr is kept for the error message; stdout is parsed line by line, with anything that is not a JSON-RPC message ignored."
61
73
  export class GraphSession {
62
74
  child;
@@ -103,8 +115,11 @@ export class GraphSession {
103
115
  if (!p)
104
116
  continue;
105
117
  this.pending.delete(msg.id);
106
- if (msg.error)
107
- p.reject(new BravosError(msg.error.message ?? 'the graph answered an error'));
118
+ if (msg.error) {
119
+ const said = msg.error.message ?? 'the graph answered an error';
120
+ // The structured reason first; the sentence is the fallback for a server that sends only text.
121
+ p.reject(msg.error.data?.reason === 'graph_busy' || BUSY_TEXT.test(said) ? new GraphBusy(said) : new BravosError(said));
122
+ }
108
123
  else
109
124
  p.resolve(msg.result);
110
125
  }
@@ -222,7 +237,7 @@ export async function ask(root, env, question, argv, timeoutMs = 60000) {
222
237
  };
223
238
  return withGraphRetry(once, (o) => !!o.error && NO_GRAPH.test(o.error.message ?? ''));
224
239
  }
225
- // @comment -- "Several questions in one session: the server loads the graph once instead of once per question. A tool the binary does not offer, or one that refuses or times out, is recorded as an error for that question alone; the others are still asked. A session whose first answer is 'no graph' is run again (withGraphRetry). Throws only when no session can be opened (codegraph-mcp missing or not starting)."
240
+ // @comment -- "Several questions in one session: the server loads the graph once instead of once per question. A tool the binary does not offer, or one that refuses or times out, is recorded as an error for that question alone; the others are still asked. The exception is a busy graph: the server has already waited its whole lock wait for that answer, so the remaining questions are marked busy without being asked (asking each would wait that long again). A session whose first answer is 'no graph' is run again (withGraphRetry). Throws only when no session can be opened (codegraph-mcp missing or not starting)."
226
241
  export async function askMany(root, env, calls, timeoutMs = 60000) {
227
242
  const once = async () => {
228
243
  const s = open(root, env);
@@ -230,16 +245,26 @@ export async function askMany(root, env, calls, timeoutMs = 60000) {
230
245
  await s.initialize(Math.min(timeoutMs, 30000));
231
246
  const tools = (await s.tools(Math.min(timeoutMs, 30000))).map((t) => t.name);
232
247
  const answers = {};
248
+ let busy = null;
233
249
  for (const c of calls) {
234
250
  if (!tools.includes(c.tool)) {
235
251
  answers[c.tool] = { error: 'this code graph does not answer that question' };
236
252
  continue;
237
253
  }
254
+ if (busy) {
255
+ answers[c.tool] = { error: busy, busy: true };
256
+ continue;
257
+ }
238
258
  try {
239
259
  answers[c.tool] = { result: await s.call(c.tool, c.args ?? {}, timeoutMs) };
240
260
  }
241
261
  catch (e) {
242
- answers[c.tool] = { error: e.message };
262
+ if (isGraphBusy(e)) {
263
+ busy = e.message;
264
+ answers[c.tool] = { error: busy, busy: true };
265
+ }
266
+ else
267
+ answers[c.tool] = { error: e.message };
243
268
  }
244
269
  }
245
270
  return { tools, answers };
@@ -323,6 +348,9 @@ export async function probe(root, env, timeoutMs = 3000) {
323
348
  }
324
349
  catch (e) {
325
350
  const m = e.message ?? '';
351
+ // Busy means a graph is there (or being built): the same reading as one that is still loading.
352
+ if (isGraphBusy(e))
353
+ return 'cli';
326
354
  if (/no graph|codegraph_unavailable|not built|no CodeGraph|nothing is there/i.test(m))
327
355
  return 'not-built';
328
356
  if (e instanceof GraphUnavailable && /within \d+s/.test(m))
package/dist/dashboard.js CHANGED
@@ -138,12 +138,14 @@ export function codeGraphStore(answers) {
138
138
  };
139
139
  }
140
140
  const NOT_BUILT = /no graph|No CodeGraph|codegraph_unavailable|not built|nothing is there|not available for project/i;
141
- // @comment -- "What the code graph says about itself for this checkout, from one cheap question: current, not-built (no graph for this commit), diverged (the working tree has moved since it was built), or unknown when it cannot say. Read-only."
141
+ // @comment -- "What the code graph says about itself for this checkout, from one cheap question: current, not-built (no graph for this commit), diverged (the working tree has moved since it was built), busy (it is there and another session or a build holds it), or unknown when it cannot say. Busy is tested before not-built and is never a reason to build. Read-only."
142
142
  export async function graphState(root, env) {
143
143
  try {
144
144
  const a = (await graph.askMany(root, env, [{ tool: 'codegraph_entry_points', args: { limit: 1 } }], 60000)).answers.codegraph_entry_points;
145
145
  if (!a)
146
146
  return 'unknown';
147
+ if ('error' in a && (a.busy || graph.isGraphBusy(a.error)))
148
+ return 'busy';
147
149
  if ('error' in a)
148
150
  return NOT_BUILT.test(a.error) ? 'not-built' : 'unknown';
149
151
  const state = text(obj(obj(a.result).graph_currency).state);
@@ -154,8 +156,8 @@ export async function graphState(root, env) {
154
156
  }
155
157
  }
156
158
  // @comment -- "Makes the code graph match the code before the dashboard draws from it, so a fresh page is never drawn from an old graph: no graph for this commit is built, and one the working tree has moved away from is rebuilt for the tree as it stands (--mode build; the default mode would reuse the commit's graph). Always --scip no-exec, which runs none of the repository's code, and no model. Returns a sentence for the page, empty when nothing was needed; a failed build is said, never thrown."
157
- export async function refreshGraph(root, env, onProgress) {
158
- const state = await graphState(root, env);
159
+ export async function refreshGraph(root, env, onProgress, known) {
160
+ const state = known ?? (await graphState(root, env));
159
161
  if (state !== 'not-built' && state !== 'diverged')
160
162
  return '';
161
163
  onProgress?.(state === 'not-built' ? 'Building the code graph for this commit first (no repository code runs; minutes on a large repository)…' : 'The code has moved since the code graph was built: rebuilding it first…');
@@ -185,8 +187,13 @@ export async function buildCodeGraph(root, env, opts = {}) {
185
187
  return note('locked', 'The code graph is on the Team plan: bravos account activate starts a 30-day trial, no card. The threat model tab is complete without it.');
186
188
  if (!graph.graphBin('codegraph-mcp', env))
187
189
  return note('missing', 'The code graph is not installed on this machine: run bravos setup --codegraph, then bravos graph build . and bravos dashboard again.');
188
- // The licence and the binary are settled, so a missing or behind graph is rebuilt before it is asked.
189
- const rebuilt = opts.refresh === false ? '' : await refreshGraph(root, env, opts.onProgress);
190
+ const BUSY = 'The code graph is busy: another session or a build is using it. Nothing needs rebuilding; run bravos dashboard again in a moment.';
191
+ // The licence and the binary are settled, so a missing or behind graph is rebuilt before it is asked. A busy one
192
+ // is neither: the server already waited for it, so the page says so now and nothing is built or asked again.
193
+ const state = opts.refresh === false ? null : await graphState(root, env);
194
+ if (state === 'busy')
195
+ return note('failed', BUSY);
196
+ const rebuilt = state ? await refreshGraph(root, env, opts.onProgress, state) : '';
190
197
  let answered;
191
198
  try {
192
199
  answered = await graph.askMany(root, env, Object.values(QUESTIONS).map((q) => ({ tool: q.tool, args: { ...q.args } })), 300000);
@@ -194,6 +201,10 @@ export async function buildCodeGraph(root, env, opts = {}) {
194
201
  catch (e) {
195
202
  return note('failed', `The code graph could not be asked (${e.message.slice(0, 200)}).`);
196
203
  }
204
+ // Asked and busy: the graph is there and another session or a build holds it. Said as that, never as "not built".
205
+ if (Object.values(answered.answers).some((a) => 'error' in a && (a.busy || graph.isGraphBusy(a.error)))) {
206
+ return note('failed', `${BUSY}${rebuilt}`);
207
+ }
197
208
  const errors = Object.values(answered.answers).map((a) => ('error' in a ? a.error : ''));
198
209
  if (errors.some((m) => NOT_BUILT.test(m))) {
199
210
  return note('not-built', `No code graph is built for this repository at this commit: run bravos graph build . (a few minutes, no tokens), then bravos dashboard again.${rebuilt}`);
@@ -244,7 +244,8 @@ export async function gatherEvidence(root, env, opts) {
244
244
  items,
245
245
  runs,
246
246
  sast: sastSummary,
247
- graph: graph && 'notBuilt' in graph ? 'not-built' : graph,
247
+ // A graph in use by another session says nothing this time: the report leaves its graph facts out, as when it is not installed.
248
+ graph: graph && 'notBuilt' in graph ? 'not-built' : graph && 'busy' in graph ? null : graph,
248
249
  gaps,
249
250
  };
250
251
  }
package/dist/setup.js CHANGED
@@ -3,7 +3,7 @@ import { checkProofTool, formatProofTool } from './proof-tools.js';
3
3
  import { spawnSync } from 'node:child_process';
4
4
  import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
5
5
  import { isAbsolute, join } from 'node:path';
6
- import { bundleEnvironment, hostTarget, install, missingPaths, staged, VERSIONS } from './artifacts.js';
6
+ import { bundleEnvironment, hostTarget, install, missingPaths, olderThan, staged, stagedVersion, VERSIONS } from './artifacts.js';
7
7
  import { graphBin, graphEnv } from './codegraph.js';
8
8
  import { whichBin } from './guardlink.js';
9
9
  import { findAnalyzer } from './graphbin.js';
@@ -11,6 +11,12 @@ import { licenceLib, requireFeature } from './licence.js';
11
11
  import { BravosError } from './types.js';
12
12
  import { PROOF_TOOL_PINS } from './versions.js';
13
13
  import { installProofTool, proofToolAction } from './install-proof-tool.js';
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
+ export function behindPin(env, kind) {
16
+ const dir = staged(env, kind);
17
+ const have = dir ? stagedVersion(dir) : null;
18
+ return have && olderThan(have, VERSIONS[kind]) ? have : null;
19
+ }
14
20
  // @comment -- "What is here and what setup would do, read-only: for each piece its path when present, the pinned version, whether the licence covers it, and the one action."
15
21
  export async function plan(env) {
16
22
  const L = await licenceLib();
@@ -18,9 +24,13 @@ export async function plan(env) {
18
24
  const sast = L.entitled(v, 'sast');
19
25
  const graph = L.entitled(v, 'codegraph');
20
26
  const t = hostTarget();
27
+ const behind = (kind) => {
28
+ const have = behindPin(env, kind);
29
+ return have ? { behind: have } : {};
30
+ };
21
31
  const items = [
22
- { id: 'analyzer', present: staged(env, 'analyzer') ?? findAnalyzer(env), wanted: VERSIONS.analyzer, licensed: sast, action: !t ? 'no build for this platform' : sast ? 'fetch, verify and stage the analyzer bundle' : 'on the Team plan: bravos account activate' },
23
- { id: 'codegraph', present: staged(env, 'codegraph') ?? graphBin('codegraph-build', env), wanted: VERSIONS.codegraph, licensed: graph, action: !t ? 'no build for this platform' : graph ? 'fetch, verify and stage codegraph-build and codegraph-mcp' : 'on the Team plan: bravos account activate' },
32
+ { id: 'analyzer', present: staged(env, 'analyzer') ?? findAnalyzer(env), wanted: VERSIONS.analyzer, licensed: sast, action: !t ? 'no build for this platform' : sast ? 'fetch, verify and stage the analyzer bundle' : 'on the Team plan: bravos account activate', ...behind('analyzer') },
33
+ { id: 'codegraph', present: staged(env, 'codegraph') ?? graphBin('codegraph-build', env), wanted: VERSIONS.codegraph, licensed: graph, action: !t ? 'no build for this platform' : graph ? 'fetch, verify and stage codegraph-build and codegraph-mcp' : 'on the Team plan: bravos account activate', ...behind('codegraph') },
24
34
  ...['guardlink', 'cxg'].map(id => ({
25
35
  id, present: whichBin(id, env), wanted: PROOF_TOOL_PINS[id].revision ?? PROOF_TOOL_PINS[id].version,
26
36
  licensed: null, action: proofToolAction(id), proofTool: checkProofTool(id, env),
@@ -33,7 +43,8 @@ export const formatPlan = (items) => items.map(i => {
33
43
  return '✘ ' + i.id.padEnd(10) + ' ' + i.present + ' (' + i.proofTool.status + ') — ' + i.action;
34
44
  }
35
45
  const status = i.present ? i.present : 'absent — ' + i.action;
36
- return (i.present ? '✔ ' : '✘ ') + i.id.padEnd(10) + ' ' + status + (i.present && i.licensed === false ? ' (licence does not cover it now)' : '');
46
+ const older = i.present && i.behind ? ` (${i.behind}; this bravos pins ${i.wanted}: bravos setup fetches it)` : '';
47
+ return (i.present ? '✔ ' : '✘ ') + i.id.padEnd(10) + ' ' + status + older + (i.present && i.licensed === false ? ' (licence does not cover it now)' : '');
37
48
  });
38
49
  // @comment -- "The setup itself. Default: the two licensed bundles for a licensed machine; --tools adds guardlink and cxg; --analyzer/--codegraph narrow it. Each licensed piece passes the gate before the first request. --dry-run prints the actions; -y is required for the package-manager installs because they run other people's installers."
39
50
  export async function runSetup(env, opts, io) {
@@ -52,15 +63,30 @@ export async function runSetup(env, opts, io) {
52
63
  const what = `bravos setup --${kind}`;
53
64
  await requireFeature(env, kind === 'analyzer' ? 'sast' : 'codegraph', what, { fetch: io.fetch });
54
65
  const have = staged(env, kind);
55
- if (have && !opts.yes) {
66
+ // A bundle older than the pin is fetched without -y: the pin is what this bravos was tested with, and
67
+ // "already staged" would leave an existing install on the old one for good.
68
+ const older = behindPin(env, kind);
69
+ if (have && !opts.yes && !older) {
56
70
  lines.push(`${kind}: already staged at ${have} (add -y to fetch ${VERSIONS[kind]} again)`);
57
71
  continue;
58
72
  }
59
73
  if (opts.dryRun) {
60
- lines.push(`dry-run: would fetch ${kind} ${VERSIONS[kind]} for ${hostTarget() ?? 'this platform'} through the account portal, verify its signature and stage it under $BRAVOS_HOME/${kind}/`);
74
+ lines.push(`dry-run: would fetch ${kind} ${VERSIONS[kind]} for ${hostTarget() ?? 'this platform'} through the account portal, verify its signature and stage it under $BRAVOS_HOME/${kind}/${older ? ` (replacing ${older})` : ''}`);
75
+ continue;
76
+ }
77
+ let r;
78
+ try {
79
+ r = await install(kind, { env, fetch: io.fetch, keys: io.keys, echo: io.echo });
80
+ }
81
+ catch (e) {
82
+ // The older bundle is complete and still the one in use, so a failed upgrade is said, not thrown.
83
+ if (!older || opts.yes)
84
+ throw e;
85
+ lines.push(`${kind}: ${older} stays staged at ${have}; ${VERSIONS[kind]} could not be fetched (${e.message.split('\n')[0].slice(0, 200)}). Run bravos setup again later.`);
61
86
  continue;
62
87
  }
63
- const r = await install(kind, { env, fetch: io.fetch, keys: io.keys, echo: io.echo });
88
+ if (older)
89
+ lines.push(`${kind}: ${older} was staged; this bravos pins ${VERSIONS[kind]}`);
64
90
  const missing = missingPaths(kind, r.dir);
65
91
  lines.push(`${kind}: ${r.version} staged at ${r.dir}${missing.length ? ` — missing ${missing.join(', ')}` : ''}`);
66
92
  lines.push(...selfTest(kind, r.dir, env));
package/dist/versions.js CHANGED
@@ -5,5 +5,5 @@ import { hooksDir } from './paths.js';
5
5
  /** The licensed analyzer bundle (bravos-cli plus gitleaks, osv-scanner, kics, zizmor and the rules), published by specter-v1's analyzer-release workflow. */
6
6
  export const ANALYZER_VERSION = '0.6.2';
7
7
  /** The code graph binaries (codegraph-build, codegraph-mcp), published by specter-v1's codegraph-release workflow. */
8
- export const CODEGRAPH_VERSION = '0.1.0';
8
+ export const CODEGRAPH_VERSION = '0.1.1';
9
9
  export const PROOF_TOOL_PINS = JSON.parse(readFileSync(join(hooksDir(), 'lib', 'proof-tool-pins.json'), 'utf8'));
@@ -268,6 +268,13 @@ function graphPanel(sn, inner) {
268
268
  body: [[s(`no graph for this commit (${sn.sha})`, C.amber)], [s('bravos keys the graph to the commit: rebuild after you commit', C.steel)], [s('→ bravos graph build . --scip no-exec', C.green)]],
269
269
  };
270
270
  }
271
+ if (g.state === 'busy') {
272
+ return {
273
+ title: 'CODE GRAPH',
274
+ right: 'busy',
275
+ body: [[s('in use by another session or a build', C.steel)], [s('nothing to do: watch asks again on the next refresh', C.steel)]],
276
+ };
277
+ }
271
278
  if (!d) {
272
279
  const body = g.entryPoints !== null ? [[s(`${g.entryPoints} entry points`)]] : [[s('askable: bravos graph <question>', C.steel)]];
273
280
  return { title: 'CODE GRAPH', right: 'asking…', body };
@@ -520,7 +527,7 @@ function tileItems(sn) {
520
527
  { label: 'COVERAGE', value: sn.coverage ? `${sn.coverage.percent}%` : '?', c: (sn.coverage?.percent ?? 0) >= 80 ? C.green : C.amber },
521
528
  { label: 'STALE', value: c ? String(c.stale) : '?', c: c?.stale ? C.amber : C.green },
522
529
  { label: 'SETUP', value: `${sn.setup.done}/${sn.setup.total}`, c: C.green },
523
- { label: 'GRAPH', value: worst ? `${Math.round(worst.ratio * 100)}%` : sn.graph.state === 'not-built' ? 'none' : sn.graph.state === 'unavailable' ? 'off' : '—', c: worst ? (worst.sufficient ? C.green : C.amber) : C.steel, sub: worst ? worst.language : undefined },
530
+ { label: 'GRAPH', value: worst ? `${Math.round(worst.ratio * 100)}%` : sn.graph.state === 'not-built' ? 'none' : sn.graph.state === 'unavailable' ? 'off' : sn.graph.state === 'busy' ? 'busy' : '—', c: worst ? (worst.sufficient ? C.green : C.amber) : C.steel, sub: worst ? worst.language : undefined },
524
531
  { label: 'SAST', value: sn.sast ? String(sn.sast.total) : sn.sastAvailable ? 'ready' : 'off', c: sn.sast?.unjoinedReachable ? C.red : C.steel },
525
532
  ];
526
533
  }
package/dist/watch.js CHANGED
@@ -57,7 +57,7 @@ const fileOf = (c) => String(c.location?.file ?? c.file ?? '?');
57
57
  const lineOf = (c) => num(c.location?.line ?? c.line);
58
58
  const keyOf = (c) => `${c.threat ?? '?'}|${c.asset ?? '?'}|${fileOf(c)}`;
59
59
  const sevRank = (s) => ['critical', 'high', 'medium', 'low'].indexOf(s) >>> 0;
60
- // @comment -- "One graph question in the shape the Python CLI's `bravos graph --json` printed ({result} or {error: codegraph_unavailable}), so summarizeGraph and graphAnswer read both the old transcript fixtures and the live MCP answers alike."
60
+ // @comment -- "One graph question in the shape the Python CLI's `bravos graph --json` printed ({result} or {error: codegraph_unavailable}), so summarizeGraph and graphAnswer read both the old transcript fixtures and the live MCP answers alike. A graph another process holds is {error: graph_busy} with an ask-again remedy, never codegraph_unavailable."
61
61
  export async function askGraph(root, env, question, args = [], timeoutMs = 60000) {
62
62
  if (!graph.graphBin('codegraph-mcp', env))
63
63
  return null;
@@ -66,6 +66,9 @@ export async function askGraph(root, env, question, args = [], timeoutMs = 60000
66
66
  }
67
67
  catch (e) {
68
68
  const m = e.message ?? '';
69
+ // Before the "not built" test, and never that: a busy graph must not send anyone to rebuild it.
70
+ if (graph.isGraphBusy(e))
71
+ return { error: 'graph_busy', message: m, remedy: graph.GRAPH_BUSY_REMEDY };
69
72
  if (/no graph|No CodeGraph|codegraph_unavailable|not built/i.test(m))
70
73
  return { error: 'codegraph_unavailable', message: m, remedy: '`bravos graph build .` indexes this repository' };
71
74
  return { error: 'graph_error', message: m };
@@ -112,6 +115,9 @@ export async function graphDetail(root, env) {
112
115
  return null;
113
116
  }
114
117
  const entry = got.answers[QUESTIONS.entry];
118
+ // Busy first: the graph is there and in use, so the panel keeps what it knew and asks again on the next refresh.
119
+ if (Object.values(got.answers).some((a) => 'error' in a && (a.busy || graph.isGraphBusy(a.error))))
120
+ return { busy: true };
115
121
  if (entry && 'error' in entry && /no graph|No CodeGraph|codegraph_unavailable|not built/i.test(entry.error))
116
122
  return { notBuilt: true };
117
123
  const ok = (tool) => {
@@ -177,7 +183,7 @@ export async function snapshot(root, env, opts = {}) {
177
183
  const i = collected;
178
184
  // The graph's own answers outrank the probe: a graph that just answered five questions is there, whatever a
179
185
  // probe that collided with another session said. Set before the setup score reads it.
180
- if (graphR && !('notBuilt' in graphR) && (i.codegraph === 'not-built' || i.codegraph === 'unknown'))
186
+ if (graphR && !('notBuilt' in graphR) && !('busy' in graphR) && (i.codegraph === 'not-built' || i.codegraph === 'unknown'))
181
187
  i.codegraph = 'current';
182
188
  const g = i.guardlink === 'missing' ? null : (i.guardlink ?? {});
183
189
  const ci = g?.ci ?? null;
@@ -228,6 +234,9 @@ export async function snapshot(root, env, opts = {}) {
228
234
  graph = { state: 'unavailable', entryPoints: null, byKind: null, detail: null };
229
235
  else if (graphR && 'notBuilt' in graphR)
230
236
  graph = { state: 'not-built', entryPoints: null, byKind: null, detail: null };
237
+ // In use by another session or a build: what the last refresh read still stands; with nothing read yet, say busy.
238
+ else if (graphR && 'busy' in graphR)
239
+ graph = prev?.graph?.detail ? prev.graph : { state: 'busy', entryPoints: null, byKind: null, detail: null };
231
240
  else
232
241
  graph = { state: String(i.codegraph ?? 'unavailable'), entryPoints: graphR?.entry?.total ?? null, byKind: graphR?.entry?.byKind ?? null, detail: graphR ?? null };
233
242
  }
package/docs/UPGRADING.md CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  After `npm install -g @bugb-technologies/bravos`, run **`bravos setup --tools -y`** once on each machine and **`bravos sync`** in each repository. The notes below say what else changes, newest first.
4
4
 
5
+ ## 1.5.3
6
+
7
+ 1.5.3 ships with code graph 0.1.1 (Team plan), which fixes the fault 1.5.2 worked around.
8
+
9
+ - **Run `bravos setup` once on each machine.** It now fetches the newer code graph when the one you have is older; before, it said "already staged" and you stayed on 0.1.0 unless you added `-y`. `bravos setup --check` says when a bundle is behind. If the download fails, the one you have keeps working and setup says so.
10
+ - **Several sessions on one repository all get an answer.** The graph used to tell all but one of them "No CodeGraph … Index the repository", and kept saying it to that session until it was restarted. It now waits its turn (up to 20 seconds).
11
+ - **A graph that is in use says "busy", not "no graph".** This happens while a build runs. `bravos graph` prints `graph_busy` with "ask again in a moment", `bravos watch` shows `GRAPH busy` and keeps what it last read, and `bravos dashboard` says the graph is busy and builds nothing. None of these is a reason to rebuild.
12
+ - **For scripts:** `bravos graph … --json` can now answer `{"error":"graph_busy"}` with exit 1. Exit 2 still means the graph is not built.
13
+ - Graphs built with 0.1.0 are read as they are; nothing needs rebuilding. Run `bravos sync` in each repository to get the updated code graph skill.
14
+
5
15
  ## 1.5.2
6
16
 
7
17
  - **`bravos watch` no longer says "no graph" for a graph that is there.** The code graph answers "no graph" to a question that arrives at the same moment as another one; Bravos now asks again before believing it, and `bravos watch` asks its questions in one go instead of several at once. If you rebuilt a graph because watch told you to, it was not needed.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bugb-technologies/bravos",
3
- "version": "1.5.2",
3
+ "version": "1.5.3",
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",
@@ -16,7 +16,7 @@ description: "Ask the repo's code graph (codegraph-mcp) one bounded question —
16
16
  **Plan check first.** The code graph is on the Team plan. Run `bravos licence --json` once per session (the briefing's `Plan:` line says the same); if `licensed` is false, tell the person in two sentences what this skill would do here and that it needs a Team licence — `bravos account activate` starts a 30-day trial with no card, or https://account.bugb.io/pricing — then stop, and do nothing else from this skill. A licence in grace still counts.
17
17
 
18
18
  1. Ask the graph one bounded question per call; a graph answer replaces reading or grepping the tree. There are two ways in, with the same answers: the MCP tools (`codegraph_attack_surface` …) when the `codegraph` server is connected, or `bravos graph <question> --json` in the shell, where the question is the tool name without `codegraph_` and with hyphens (`codegraph_attack_surface` → `bravos graph attack-surface --json`, `codegraph_callers` → `bravos graph callers '<file>::<symbol>' --json`; `bravos graph --json` lists every question and its arguments). The shell route needs no MCP reconnect and works in every harness. The briefing's `Code graph:` line says which route is there. If neither is (no codegraph-mcp), set it up yourself: `bravos setup --check` reports what is missing without changing anything; show the person `bravos setup --dry-run --codegraph` and with their go-ahead run `bravos setup --codegraph` (it fetches the signed bundle through the account portal and verifies it before anything lands). If an install fails, quote its error and give the exact command for their own terminal; until then say "code graph unavailable; the other skills read the code instead" and answer by reading. Read the effort: the user's words ("at high"), else a `bravos effort: <level>` line in `AGENTS.md` / `CLAUDE.md`, else medium. It sets a starting budget, not a limit; go beyond it when the work needs it and say why in one line. Starting budget — low: the one question asked; medium: whatever questions the task needs; high: start from `codegraph_attack_surface`; max: the full attack surface plus `codegraph_impact` on every changed symbol.
19
- 2. Build or refresh the graph when an answer says there is none for this repository, or its `graph_currency` is `diverged`: `bravos graph build . --scip no-exec` indexes without running the repository's build scripts (`--scip auto` and `--isolate` run them; use those only on a repo the user trusts and only when they say so). A build that reports `semantic <language>: off` lacks that language's type checker; say that calls through interfaces may not connect and that `bravos setup --indexers` (with their go-ahead) adds it. For the MCP route, `bravos sync` registers the server from the bravos install; the person reconnects MCP (`/mcp` in Claude Code) to load it. In a bravos workspace, build one graph over the app folder (`bravos graph build <app folder> --scip no-exec`, the folder the briefing's `Workspace:` line names) and ask cross-service questions there: only a graph that holds both services links one service's HTTP, gRPC, GraphQL or OpenAPI client call to the other's handler (`callees` shows `via_framework`). A graph built inside one member stops at its own repository. The graph can also answer "No CodeGraph for project" to a question that arrives at the same moment as another one (a second terminal, `bravos watch`, `bravos dashboard`): when a graph answered moments ago, ask once more before rebuilding. A graph belongs to the commit it was built at: after a commit it answers nothing until it is rebuilt, so rebuild before the next graph question and carry on with other work while it builds. `bravos dashboard` rebuilds a missing or behind graph itself and draws it as the Code graph tab (the map, owners and history, coupling, the attack surface, entry points), which is the view to offer a person who wants to see the graph.
19
+ 2. Build or refresh the graph when an answer says there is none for this repository, or its `graph_currency` is `diverged`: `bravos graph build . --scip no-exec` indexes without running the repository's build scripts (`--scip auto` and `--isolate` run them; use those only on a repo the user trusts and only when they say so). A build that reports `semantic <language>: off` lacks that language's type checker; say that calls through interfaces may not connect and that `bravos setup --indexers` (with their go-ahead) adds it. For the MCP route, `bravos sync` registers the server from the bravos install; the person reconnects MCP (`/mcp` in Claude Code) to load it. In a bravos workspace, build one graph over the app folder (`bravos graph build <app folder> --scip no-exec`, the folder the briefing's `Workspace:` line names) and ask cross-service questions there: only a graph that holds both services links one service's HTTP, gRPC, GraphQL or OpenAPI client call to the other's handler (`callees` shows `via_framework`). A graph built inside one member stops at its own repository. An answer of `graph_busy` ("the code graph … is busy") means the graph is there and another session or a build is using it: ask again in a moment and never rebuild for it. An older graph server (code graph 0.1.0) says "No CodeGraph for project" in that case instead, and keeps saying it for that session: when a graph answered moments ago, ask once more before rebuilding, and offer `bravos setup` (it fetches the newer server). A graph belongs to the commit it was built at: after a commit it answers nothing until it is rebuilt, so rebuild before the next graph question and carry on with other work while it builds. `bravos dashboard` rebuilds a missing or behind graph itself and draws it as the Code graph tab (the map, owners and history, coupling, the attack surface, entry points), which is the view to offer a person who wants to see the graph.
20
20
  3. Pick the one tool that answers the question:
21
21
  find a symbol → `codegraph_search`
22
22
  routes → `codegraph_routes`