@bugb-technologies/bravos 1.7.0 → 1.8.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/dist/cli.js +78 -13
- package/dist/codegraph.js +21 -0
- package/dist/graphbin.js +2 -0
- package/dist/guide.js +6 -4
- package/dist/help.js +24 -5
- package/dist/install.js +2 -1
- package/dist/lock.js +1 -0
- package/dist/mcp.js +18 -3
- package/dist/prefs.js +47 -0
- package/dist/review-wait.js +76 -0
- package/dist/start/answers.js +33 -4
- package/dist/start/index.js +138 -57
- package/dist/upkeep.js +89 -0
- package/docs/GUIDE.md +16 -4
- package/docs/UPGRADING.md +19 -0
- package/hooks/lib/autopilot.mjs +3 -18
- package/hooks/lib/briefing.mjs +65 -7
- package/hooks/lib/graph-autobuild.mjs +131 -0
- package/hooks/lib/prefs.mjs +108 -0
- package/hooks/lib/refresh.mjs +45 -1
- package/hooks/lib/setup.mjs +1 -1
- package/hooks/lib/snapshot.mjs +19 -1
- package/hooks/session-start.mjs +5 -0
- package/package.json +1 -1
- package/skills/bravos/SKILL.md +4 -3
- package/skills/bravos-annotate/SKILL.md +2 -2
- package/skills/bravos-context/SKILL.md +6 -6
- package/skills/bravos-env/SKILL.md +2 -2
- package/skills/bravos-env/scope.example.yaml +2 -1
- package/skills/bravos-prove/SKILL.md +2 -2
- package/skills/bravos-recheck/SKILL.md +1 -1
- package/skills/bravos-resync/SKILL.md +1 -1
- package/skills/bravos-ship/SKILL.md +1 -1
- package/skills/bravos-templatize/SKILL.md +1 -1
- package/templates/review/review.html +1 -1
package/hooks/lib/briefing.mjs
CHANGED
|
@@ -4,9 +4,10 @@ import { accessSync, constants, readFileSync } from 'node:fs';
|
|
|
4
4
|
import { basename, delimiter, dirname, join } from 'node:path';
|
|
5
5
|
import { contextGate, readContext } from './context.mjs';
|
|
6
6
|
import { THEMES } from './palette.mjs';
|
|
7
|
+
import { commitsLine, commonDirFrom, readHandoff, readPrefs } from './prefs.mjs';
|
|
7
8
|
import { readProving } from './proving.mjs';
|
|
8
9
|
import { planLabel, planLine, status as licenceStatus } from './licence.mjs';
|
|
9
|
-
import { refreshIfDue } from './refresh.mjs';
|
|
10
|
+
import { readLicenceNote, refreshIfDue } from './refresh.mjs';
|
|
10
11
|
import { gitStaleness, staleLine, staleness, strandedBranches, strandedLine } from './resync.mjs';
|
|
11
12
|
import { readSast, sastAvailable, sastLine } from './sast.mjs';
|
|
12
13
|
import { hooksLocked, readSetup, setupLine, TRIAL } from './setup.mjs';
|
|
@@ -132,9 +133,11 @@ export function contextLine(context, harness) {
|
|
|
132
133
|
}
|
|
133
134
|
|
|
134
135
|
// @comment -- "The briefing's Intent line. While the context gate is closed it also says so in words an agent acts on: do not start threat-modelling, run the context skill first, and how a person declines. A recorded decline is shown with the name and date of the person who made it."
|
|
135
|
-
function intentLine(intent, harness, gate) {
|
|
136
|
+
function intentLine(intent, harness, gate, handoff = false) {
|
|
136
137
|
const run = harness === 'claude' ? '/bravos-context' : 'the bravos-context skill';
|
|
137
|
-
|
|
138
|
+
// Right after bravos start (a fresh hand-off marker), the person expects Bravos to begin: the agent starts the context step itself and goes on to annotation, unless their first message asks for something else.
|
|
139
|
+
const begin = handoff && intent.status === 'none' ? ` Setup just finished here and the person expects Bravos to begin: start ${run} in your first reply without being asked, and go on to annotation once they have confirmed. If their first message asks for something else, do that and offer this once after.` : '';
|
|
140
|
+
const closed = gate && gate.open === false ? `. Context comes first: do not annotate or start a campaign until a named person has confirmed it (or run bravos context decline --by "<name>" themselves).${begin}` : '';
|
|
138
141
|
const declined = gate?.state === 'declined' ? `declined by ${gate.by} on ${gate.at}` : '';
|
|
139
142
|
if (intent.status === 'none') return declined ? `Intent: ${declined} — severities are not calibrated to the product; ${run} when the team is ready` : `Intent: none — severities are not calibrated to the product; run ${run}${closed}`;
|
|
140
143
|
if (intent.status === 'draft') return `Intent: draft (${intent.invariants} invariants, ${intent.drafts} items unconfirmed${declined ? `; context ${declined}` : ''}) — confirm with ${run}${closed}`;
|
|
@@ -159,7 +162,8 @@ function coachLines(i) {
|
|
|
159
162
|
'How to help this person (offer, never lecture; one offer per topic per session):',
|
|
160
163
|
`- In your first reply, if setup is under 5 or intent is none, offer once in plain words three starts that fit this repo, in setup order (${i.licence?.licensed === false ? 'on the Free plan: learn what the app intends, annotate the uncovered files, prove the top threats; never lead with a Team-plan step' : 'build the code graph first if it is off, then learn what the app intends, annotate the uncovered files, run SAST, prove the top threats; or check this branch before a PR'}) and \`bravos guide\` for more; then follow their lead.`,
|
|
161
164
|
`- After you edit security-relevant code, offer to record what it exposes (${k('bravos-annotate')}); before a PR, run the ship check (${k('bravos-ship')}); after a fix, offer a recheck (${k('bravos-recheck')}).`,
|
|
162
|
-
|
|
165
|
+
// A standing answer is the briefing's Commits line; with none, ask once and (unless they chose to be asked each time) record it so no later session asks.
|
|
166
|
+
...(commitsLine(i.prefs) ? [] : [`- Commits are the person's call: before the first commit of a session ask once (commit now, or leave the files for them to review), even where a skill says to commit; skip the question only when they already asked for commits (a campaign, a schedule).${i.prefs?.commits?.value === 'ask' ? '' : ' Then ask whether that is their answer from now on, and if so record it with `bravos prefs set commits commit|leave --by "<their name>"`: their answer and their name, never yours.'}`]),
|
|
163
167
|
'- When a request would go better with the next unlock above, say what it would add, once. Plain words first, skill name second. Never send test traffic without the authorization bravos-env asks for.',
|
|
164
168
|
'- Once, when it helps them follow along, mention that `bravos watch` in a second terminal pane shows this live as you work (free, read-only), and that `bravos dashboard` opens the findings as one page in their browser (rebuilt from the code each time; never open a saved copy instead).',
|
|
165
169
|
);
|
|
@@ -232,9 +236,12 @@ export function buildBriefing(inputs) {
|
|
|
232
236
|
else if (i.inFlight.prs > 0 || i.inFlight.files > 0) {
|
|
233
237
|
tail.push(`In flight by teammates: ${i.inFlight.files} files in ${i.inFlight.prs} open PRs`);
|
|
234
238
|
}
|
|
235
|
-
if (i.intent && typeof i.intent === 'object') tail.push(intentLine(i.intent, i.harness, i.gate));
|
|
239
|
+
if (i.intent && typeof i.intent === 'object') tail.push(intentLine(i.intent, i.harness, i.gate, i.handoff === true));
|
|
236
240
|
const documents = contextLine(i.context, i.harness);
|
|
237
241
|
if (documents) tail.push(documents);
|
|
242
|
+
// The person's standing answer about commits, when they gave one (hooks/lib/prefs.mjs).
|
|
243
|
+
const commits = commitsLine(i.prefs);
|
|
244
|
+
if (commits) tail.push(commits);
|
|
238
245
|
if (i.proving && typeof i.proving === 'object') {
|
|
239
246
|
const p = i.proving;
|
|
240
247
|
tail.push(p.status === 'set'
|
|
@@ -247,6 +254,10 @@ export function buildBriefing(inputs) {
|
|
|
247
254
|
? `Note: this repo's bravos (${i.shadow.repo}) is behind the person's user-level copy (${i.shadow.user}), which Claude Code uses; suggest they run bravos sync in this repo from their own terminal`
|
|
248
255
|
: `Note: the person's user-level bravos skills (~/.claude/skills, ${i.shadow.user}) are used instead of this repo's (${i.shadow.repo}); tell them to run bravos sync --global from their own terminal, then start a new session`);
|
|
249
256
|
}
|
|
257
|
+
const upkeep = upkeepLine(i.upkeep);
|
|
258
|
+
if (upkeep) tail.push(upkeep);
|
|
259
|
+
// The portal's last refusal to renew this machine, until it is signed in again (a revocation) or renewed (a plan that ended).
|
|
260
|
+
if (i.licenceNote && (i.licenceNote.outcome === 'lapsed' || i.licence?.licensed === false)) tail.push(`Licence: ${i.licenceNote.note} Tell the person once, in plain words.`);
|
|
250
261
|
if ((i.autopilot || i.prePr) && hooksLocked(i)) {
|
|
251
262
|
// The repo registers the hooks for everyone; this person's copy answers nothing until they have a licence.
|
|
252
263
|
const which = i.autopilot ? 'Autopilot (the end-of-turn check and the pre-PR gate)' : 'The pre-PR gate';
|
|
@@ -254,6 +265,7 @@ export function buildBriefing(inputs) {
|
|
|
254
265
|
} else if (i.autopilot) tail.push('Autopilot: on — at turn end, review changed behavior in new and annotated files and follow the proving choice for affected claims');
|
|
255
266
|
if (i.codegraph === 'current') tail.push('Code graph: current');
|
|
256
267
|
else if (i.codegraph === 'cli') tail.push('Code graph: ask it with `bravos graph <question> --json` (same answers as the codegraph_ tools; e.g. attack-surface, entry-points, callers, reachable-sinks, call-chain); if it says no graph, build it: bravos graph build . (bravos-codegraph)');
|
|
268
|
+
else if (i.codegraph === 'not-built' && i.graphBuild) tail.push('Code graph: none for this commit yet — bravos is building it in the background now (no tokens, a few minutes): do not start another build. Ask the graph again in a few minutes; until then skills trace routes by reading.');
|
|
257
269
|
else if (i.codegraph === 'not-built') tail.push('Code graph: none for this commit — bravos keys a graph to the commit it was built at, so a new commit needs a rebuild: bravos graph build . --scip no-exec (bravos-codegraph; no tokens, a few minutes). Until then skills trace routes by reading.');
|
|
258
270
|
else if (i.codegraph === 'diverged') tail.push('Code graph: diverged — rebuild with codegraph-build --scip no-exec');
|
|
259
271
|
else if (i.codegraph === 'locked') tail.push('Code graph: on the Team plan (see Plan above) — skills trace routes by reading until then');
|
|
@@ -388,6 +400,43 @@ export async function probeGraph(root, env, timeoutMs = 3000) {
|
|
|
388
400
|
return 'cli';
|
|
389
401
|
}
|
|
390
402
|
|
|
403
|
+
// @comment -- "Asks the installed bravos what has fallen behind it here (bravos upkeep --json: read-only, no network, well under a second), only where the repository carries Bravos's files. Null when bravos is not on PATH, is too old to know the command, does not answer in time, or BRAVOS_UPKEEP_PROBE=off."
|
|
404
|
+
export async function probeUpkeep(root, env, timeoutMs = 3000) {
|
|
405
|
+
if (env.BRAVOS_UPKEEP_PROBE === 'off' || !whichOnPath('bravos', env)) return null;
|
|
406
|
+
try {
|
|
407
|
+
accessSync(join(root, '.bravos', 'skills.lock'), constants.R_OK);
|
|
408
|
+
} catch {
|
|
409
|
+
return null;
|
|
410
|
+
}
|
|
411
|
+
const r = await capture('bravos', ['upkeep', root, '--json'], { cwd: root, env, timeoutMs });
|
|
412
|
+
if (r.timedOut || r.error || r.status !== 0) return null;
|
|
413
|
+
try {
|
|
414
|
+
const j = JSON.parse(r.stdout);
|
|
415
|
+
return j?.schema === 'bravos.upkeep/v1' ? j : null;
|
|
416
|
+
} catch {
|
|
417
|
+
return null;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
const VERSION_RE = /^\d+(?:\.\d+){0,3}(?:-[A-Za-z0-9.]{1,20})?$/;
|
|
422
|
+
// @comment -- "The briefing's Upkeep line: what the agent repairs by itself. A repository whose Bravos files are behind the installed bravos gets `bravos sync`; a staged bundle older than this bravos pins gets `bravos setup` (Bravos's own signed bundles, nothing third-party). When the repository is the newer side the agent is told not to sync, because an older bravos would roll it back, and to tell the person to update. Only version numbers, counts and the two known bundle names from the answer reach the text."
|
|
423
|
+
export function upkeepLine(u) {
|
|
424
|
+
if (!u || typeof u !== 'object') return null;
|
|
425
|
+
const ver = (v) => (typeof v === 'string' && VERSION_RE.test(v) ? v : null);
|
|
426
|
+
const cli = ver(u.cli);
|
|
427
|
+
const parts = [];
|
|
428
|
+
const files = Number.isInteger(u.sync?.files) && u.sync.files > 0 ? u.sync.files : 0;
|
|
429
|
+
if (files && cli) {
|
|
430
|
+
const repo = ver(u.repo);
|
|
431
|
+
const count = `${files} file${files === 1 ? '' : 's'}`;
|
|
432
|
+
if (u.sync.direction === 'repo-newer') parts.push(`this repository's Bravos files${repo ? ` (${repo})` : ''} are newer than the installed bravos (${cli}): do not run bravos sync from this machine, it would roll them back; tell the person once to update with npm install -g @bugb-technologies/bravos@latest`);
|
|
433
|
+
else parts.push(`this repository's Bravos files are behind the installed bravos (${repo && repo !== cli ? `${repo} → ${cli}, ` : ''}${count}): run \`bravos sync\` now without asking and include what it changes in your next commit of Bravos's files`);
|
|
434
|
+
}
|
|
435
|
+
const bundles = (Array.isArray(u.bundles) ? u.bundles : []).filter((b) => ['analyzer', 'codegraph'].includes(b?.id) && ver(b.staged) && ver(b.pinned));
|
|
436
|
+
if (bundles.length) parts.push(`the ${bundles.map((b) => `${b.id} bundle (${b.staged} → ${b.pinned})`).join(' and ')} on this machine ${bundles.length === 1 ? 'is' : 'are'} older than this bravos pins: run \`bravos setup\` now without asking (it fetches Bravos's own signed bundles and nothing else)`);
|
|
437
|
+
return parts.length ? `Upkeep: ${parts.join('; ')}.` : null;
|
|
438
|
+
}
|
|
439
|
+
|
|
391
440
|
export async function collect(root, env, { deadlineMs = 20000, nextCount = 3 } = {}) {
|
|
392
441
|
const deadline = Date.now() + deadlineMs;
|
|
393
442
|
const budget = () => Math.min(10000, Math.max(0, deadline - Date.now()));
|
|
@@ -400,10 +449,12 @@ export async function collect(root, env, { deadlineMs = 20000, nextCount = 3 } =
|
|
|
400
449
|
return r.timedOut || r.error || r.status !== 0 ? null : r.stdout.trim();
|
|
401
450
|
};
|
|
402
451
|
const gitFacts = (async () => {
|
|
403
|
-
const [sha, ref, branch] = await Promise.all([
|
|
452
|
+
const [sha, ref, branch, common] = await Promise.all([
|
|
404
453
|
git(['rev-parse', '--short', 'HEAD']),
|
|
405
454
|
git(['symbolic-ref', '-q', '--short', 'refs/remotes/origin/HEAD']),
|
|
406
455
|
git(['rev-parse', '--abbrev-ref', 'HEAD']),
|
|
456
|
+
// Where this clone keeps its own state: the person's preferences live there, out of any commit's reach.
|
|
457
|
+
git(['rev-parse', '--git-common-dir']),
|
|
407
458
|
]);
|
|
408
459
|
const base = ref || 'origin/main';
|
|
409
460
|
const name = branch && branch !== 'HEAD' ? branch : null;
|
|
@@ -419,6 +470,7 @@ export async function collect(root, env, { deadlineMs = 20000, nextCount = 3 } =
|
|
|
419
470
|
]);
|
|
420
471
|
return {
|
|
421
472
|
sha: sha ?? 'unknown',
|
|
473
|
+
commonDir: commonDirFrom(root, common),
|
|
422
474
|
defaultBranch: defaultHead ? ref : null,
|
|
423
475
|
base,
|
|
424
476
|
branch: name,
|
|
@@ -444,12 +496,13 @@ export async function collect(root, env, { deadlineMs = 20000, nextCount = 3 } =
|
|
|
444
496
|
});
|
|
445
497
|
|
|
446
498
|
const graphRun = probeGraph(root, env, Math.min(3000, first));
|
|
499
|
+
const upkeepRun = probeUpkeep(root, env, Math.min(3000, first)).catch(() => null);
|
|
447
500
|
// A signed-in machine's device licence is renewed here when it is due, alongside the other facts and under a short timeout of its own; it fails open, so a slow or absent portal only means the held token is read as it is.
|
|
448
501
|
const renewal = refreshIfDue(env, { timeoutMs: Math.min(3000, first) }).catch(() => null);
|
|
449
502
|
// At an app folder, each member's counts come from its own guardlink ci, alongside the rest.
|
|
450
503
|
const workspace = readWorkspace(root);
|
|
451
504
|
const countsRun = workspace?.isAppFolder && hasGuardlink ? memberCounts(workspace, runJsonAsync, env, first) : Promise.resolve(null);
|
|
452
|
-
const [facts, pr, graphState, workspaceCounts, , ...gl] = await Promise.all([gitFacts, prRun, graphRun, countsRun, renewal, ...glRuns]);
|
|
505
|
+
const [facts, pr, graphState, workspaceCounts, , upkeep, ...gl] = await Promise.all([gitFacts, prRun, graphRun, countsRun, renewal, upkeepRun, ...glRuns]);
|
|
453
506
|
|
|
454
507
|
let guardlink = 'missing';
|
|
455
508
|
if (hasGuardlink) {
|
|
@@ -485,6 +538,11 @@ export async function collect(root, env, { deadlineMs = 20000, nextCount = 3 } =
|
|
|
485
538
|
intent: readIntent(root),
|
|
486
539
|
context: readContext(root),
|
|
487
540
|
gate: contextGate(root),
|
|
541
|
+
prefs: readPrefs(facts.commonDir),
|
|
542
|
+
handoff: readHandoff(facts.commonDir),
|
|
543
|
+
upkeep,
|
|
544
|
+
// Read after the renewal above has run, so a refusal that just arrived is in it.
|
|
545
|
+
licenceNote: readLicenceNote(env),
|
|
488
546
|
annotationMode: readAnnotationMode(root),
|
|
489
547
|
// bravos on PATH: what its probe says (a graph for this commit or not); else codegraph-mcp on PATH means the MCP route.
|
|
490
548
|
codegraph: graphState ?? (whichOnPath('codegraph-mcp', env) ? 'unknown' : 'unavailable'),
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// @comment -- "The background code graph build. A graph is keyed to the commit it was built at, so after every commit there is none, and until now only a person or an agent told to do so rebuilt it. When the session hook finds no graph for the commit, it starts one quiet build here: a detached process that runs `bravos graph build <root> --scip no-exec` (no model, no network, and no-exec means the repository's own build scripts are never run), records how it ended, tells bravos watch, and exits. One build per repository at a time, whatever the number of sessions: the runner takes an exclusive lock under $BRAVOS_HOME/autobuild/<repository>/ before it builds. It starts only on the Team plan, only in a repository that installed Bravos (never from the user-level or plugin copy of the hook), never in CI, and never when BRAVOS_GRAPH_AUTOBUILD=off. A build that failed is not retried for the same commit for six hours."
|
|
2
|
+
import { spawn, spawnSync } from 'node:child_process';
|
|
3
|
+
import { createHash } from 'node:crypto';
|
|
4
|
+
import { existsSync, mkdirSync, openSync, closeSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
import { bravosHome } from './licence.mjs';
|
|
8
|
+
import { logWatchEvent } from './snapshot.mjs';
|
|
9
|
+
|
|
10
|
+
/** A lock older than this belongs to a build that died without cleaning up. bravos graph build gives up at 30 minutes itself. */
|
|
11
|
+
export const LOCK_STALE_MS = 45 * 60 * 1000;
|
|
12
|
+
export const RETRY_AFTER_FAILURE_MS = 6 * 60 * 60 * 1000;
|
|
13
|
+
/** A session whose probe ran while another session's build was finishing still reads "no graph"; a build that succeeded for this commit this recently is believed over that probe. */
|
|
14
|
+
export const JUST_BUILT_MS = 10 * 60 * 1000;
|
|
15
|
+
const BUILD_TIMEOUT_MS = 35 * 60 * 1000;
|
|
16
|
+
const SHA_RE = /^[0-9a-f]{7,40}$/;
|
|
17
|
+
|
|
18
|
+
// @comment -- "Where one repository's build state lives: a folder under $BRAVOS_HOME named by a hash of the repository's path, so nothing is written into a repository for this and two clones never share a lock."
|
|
19
|
+
export function stateDir(root, env = process.env) {
|
|
20
|
+
const home = bravosHome(env);
|
|
21
|
+
if (!home) return null;
|
|
22
|
+
return join(home, 'autobuild', createHash('sha256').update(String(root)).digest('hex').slice(0, 16));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const readJson = (file) => {
|
|
26
|
+
try {
|
|
27
|
+
const j = JSON.parse(readFileSync(file, 'utf8'));
|
|
28
|
+
return j && typeof j === 'object' ? j : null;
|
|
29
|
+
} catch {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const alive = (pid) => {
|
|
35
|
+
if (!Number.isInteger(pid) || pid <= 1) return false;
|
|
36
|
+
try {
|
|
37
|
+
process.kill(pid, 0);
|
|
38
|
+
return true;
|
|
39
|
+
} catch {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const justBuilt = (last, sha, now) => !!last && last.ok === true && last.sha === sha && typeof last.at === 'number' && now - last.at >= 0 && now - last.at < JUST_BUILT_MS;
|
|
45
|
+
|
|
46
|
+
/** The build running for this repository, if any: a lock whose process is alive and which is not older than a build can be. */
|
|
47
|
+
export function runningBuild(dir, now = Date.now()) {
|
|
48
|
+
const lock = dir ? readJson(join(dir, 'lock')) : null;
|
|
49
|
+
if (!lock || typeof lock.at !== 'number') return null;
|
|
50
|
+
return alive(lock.pid) && now - lock.at < LOCK_STALE_MS ? { pid: lock.pid, sha: typeof lock.sha === 'string' ? lock.sha : null, at: lock.at } : null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// @comment -- "Decides whether to start a build, and why not when not. Pure but for reading the lock and the last result: the session hook and the tests ask it the same way."
|
|
54
|
+
export function buildDecision({ root, env = process.env, codegraph, licensed, sha, installed, now = Date.now() }) {
|
|
55
|
+
if (codegraph !== 'not-built') return { start: false, reason: 'graph-present' };
|
|
56
|
+
if (!licensed) return { start: false, reason: 'unlicensed' };
|
|
57
|
+
if (!installed) return { start: false, reason: 'not-installed-here' };
|
|
58
|
+
if (env.BRAVOS_GRAPH_AUTOBUILD === 'off') return { start: false, reason: 'switched-off' };
|
|
59
|
+
if (env.CI) return { start: false, reason: 'ci' };
|
|
60
|
+
if (typeof sha !== 'string' || !SHA_RE.test(sha)) return { start: false, reason: 'no-commit' };
|
|
61
|
+
const dir = stateDir(root, env);
|
|
62
|
+
if (!dir) return { start: false, reason: 'no-home' };
|
|
63
|
+
if (runningBuild(dir, now)) return { start: false, running: true, reason: 'already-building' };
|
|
64
|
+
const last = readJson(join(dir, 'last.json'));
|
|
65
|
+
if (justBuilt(last, sha, now)) return { start: false, reason: 'just-built' };
|
|
66
|
+
if (last && last.ok === false && last.sha === sha && typeof last.at === 'number' && now - last.at < RETRY_AFTER_FAILURE_MS) return { start: false, reason: 'failed-recently' };
|
|
67
|
+
return { start: true, dir };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// @comment -- "Starts the runner detached from the hook (which must return within its timeout) and says what happened: 'started', 'running' when a build is already going, or null. The runner is this same file, run with the node that runs the hook; it outlives the session that started it. Never throws: a build that cannot start only means the briefing prints the command, as before."
|
|
71
|
+
export function startGraphBuild(opts) {
|
|
72
|
+
let d;
|
|
73
|
+
try {
|
|
74
|
+
d = buildDecision(opts);
|
|
75
|
+
} catch {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
if (d.running) return 'running';
|
|
79
|
+
if (!d.start) return null;
|
|
80
|
+
try {
|
|
81
|
+
mkdirSync(d.dir, { recursive: true, mode: 0o700 });
|
|
82
|
+
const child = spawn(process.execPath, [fileURLToPath(import.meta.url), 'run', opts.root, d.dir, opts.sha], { cwd: opts.root, env: opts.env ?? process.env, detached: true, stdio: 'ignore' });
|
|
83
|
+
child.on('error', () => {});
|
|
84
|
+
child.unref();
|
|
85
|
+
return child.pid ? 'started' : null;
|
|
86
|
+
} catch {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// @comment -- "The runner: takes the lock (exclusive create, so of two runners started together one builds and the other exits), runs the build, writes last.json and a short log, tells bravos watch, and removes the lock. `build` is replaceable so the tests need no real graph binary."
|
|
92
|
+
export function runBuild(root, dir, sha, { env = process.env, now = () => Date.now(), build } = {}) {
|
|
93
|
+
const lock = join(dir, 'lock');
|
|
94
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
95
|
+
// A lock left by a build that died is cleared first; a live one stops us.
|
|
96
|
+
if (existsSync(lock) && !runningBuild(dir, now())) rmSync(lock, { force: true });
|
|
97
|
+
let fd;
|
|
98
|
+
try {
|
|
99
|
+
fd = openSync(lock, 'wx', 0o600);
|
|
100
|
+
} catch {
|
|
101
|
+
return { ran: false };
|
|
102
|
+
}
|
|
103
|
+
try {
|
|
104
|
+
writeFileSync(fd, JSON.stringify({ pid: process.pid, sha, at: now() }));
|
|
105
|
+
closeSync(fd);
|
|
106
|
+
// Another runner may have finished this very commit between our session's probe and now: one build is enough.
|
|
107
|
+
if (justBuilt(readJson(join(dir, 'last.json')), sha, now())) return { ran: false };
|
|
108
|
+
logWatchEvent(root, { summary: `code graph: building in the background for ${sha}`, keys: ['graph'] });
|
|
109
|
+
const run = build ?? (() => spawnSync('bravos', ['graph', 'build', root, '--scip', 'no-exec', '--json'], { cwd: root, env, encoding: 'utf8', timeout: BUILD_TIMEOUT_MS, maxBuffer: 16 * 1024 * 1024, stdio: ['ignore', 'pipe', 'pipe'] }));
|
|
110
|
+
const r = run();
|
|
111
|
+
const ok = !r.error && r.status === 0;
|
|
112
|
+
const why = ok ? '' : String(r.error?.code ?? (r.stderr || r.stdout || `exit ${r.status}`)).split('\n').map((l) => l.trim()).find((l) => l && !l.startsWith('{')) ?? `exit ${r.status}`;
|
|
113
|
+
writeFileSync(join(dir, 'last.json'), JSON.stringify({ ok, sha, at: now(), ...(ok ? {} : { why: why.slice(0, 300) }) }) + '\n', { mode: 0o600 });
|
|
114
|
+
writeFileSync(join(dir, 'build.log'), `${new Date(now()).toISOString()} ${sha} ${ok ? 'built' : 'failed'}\n${String(r.stderr ?? '').slice(-4000)}\n`, { mode: 0o600 });
|
|
115
|
+
logWatchEvent(root, { summary: ok ? `code graph: built for ${sha}` : `code graph: the background build did not finish (${why.slice(0, 160)}); bravos graph build . shows why`, keys: ['graph'] });
|
|
116
|
+
return { ran: true, ok };
|
|
117
|
+
} finally {
|
|
118
|
+
rmSync(lock, { force: true });
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Run as a script: `node graph-autobuild.mjs run <root> <stateDir> <sha>`.
|
|
123
|
+
if (process.argv[1] && fileURLToPath(import.meta.url) === process.argv[1] && process.argv[2] === 'run') {
|
|
124
|
+
const [root, dir, sha] = process.argv.slice(3);
|
|
125
|
+
try {
|
|
126
|
+
if (root && dir && SHA_RE.test(sha ?? '')) runBuild(root, dir, sha);
|
|
127
|
+
} catch {
|
|
128
|
+
/* nothing to tell: the next session's briefing prints the command */
|
|
129
|
+
}
|
|
130
|
+
process.exit(0);
|
|
131
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// @comment -- "A person's standing answers to questions Bravos would otherwise ask every session, kept per clone and never committed. Today there is one: what to do with Bravos's own files (annotations, intent, definitions, tests, the ledger) once they are written: commit them, leave them for the person, or keep asking. The file lives under the git directory (<git-common-dir>/bravos/prefs.json), which no commit, clone or pull can write, so a repository cannot ship an answer and grant itself silent commits, and every worktree of a clone shares it. Dependency-free: the session hook reads it, the CLI writes it."
|
|
2
|
+
import { spawnSync } from 'node:child_process';
|
|
3
|
+
import { chmodSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
|
|
4
|
+
import { isAbsolute, join, resolve } from 'node:path';
|
|
5
|
+
|
|
6
|
+
export const PREFS_SCHEMA = 'bravos.prefs/v1';
|
|
7
|
+
/** commit: commit Bravos's own files without asking. leave: never commit them, list them. ask: ask each session (the default when nothing is recorded). */
|
|
8
|
+
export const COMMIT_CHOICES = ['commit', 'leave', 'ask'];
|
|
9
|
+
|
|
10
|
+
// One line of visible text: a name goes into the briefing, so control and invisible characters never do.
|
|
11
|
+
const clean = (v, max) => String(v ?? '').replace(/[\u0000-\u001F\u007F-\u009F----]/g, ' ').replace(/\s+/g, ' ').trim().slice(0, max);
|
|
12
|
+
|
|
13
|
+
// @comment -- "The directory git keeps this clone's own state in, shared by its worktrees; null outside a repository or when git does not answer in time."
|
|
14
|
+
export function gitCommonDir(root, env = process.env) {
|
|
15
|
+
const r = spawnSync('git', ['rev-parse', '--git-common-dir'], { cwd: root, env, encoding: 'utf8', timeout: 5000, stdio: ['ignore', 'pipe', 'ignore'] });
|
|
16
|
+
if (r.error || r.status !== 0) return null;
|
|
17
|
+
return commonDirFrom(root, r.stdout);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** git prints the directory relative to where it ran ('.git') or absolute (a worktree); empty means none. */
|
|
21
|
+
export function commonDirFrom(root, printed) {
|
|
22
|
+
const out = String(printed ?? '').trim();
|
|
23
|
+
if (!out) return null;
|
|
24
|
+
return isAbsolute(out) ? out : resolve(root, out);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const prefsFile = (commonDir) => join(commonDir, 'bravos', 'prefs.json');
|
|
28
|
+
|
|
29
|
+
// @comment -- "Reads the preferences for a clone. Anything that is not exactly the recorded shape (another schema, an unknown choice, no name, a date that is not a date) reads as nothing recorded, so a damaged or hand-made file can only make Bravos ask again, never commit."
|
|
30
|
+
// @mitigates #person-prefs against #governance-forgery using #prefs-outside-tree -- "Only a well-formed record under the git directory counts as the person's answer."
|
|
31
|
+
export function readPrefs(commonDir) {
|
|
32
|
+
const none = { commits: null };
|
|
33
|
+
if (!commonDir) return none;
|
|
34
|
+
let doc;
|
|
35
|
+
try {
|
|
36
|
+
doc = JSON.parse(readFileSync(prefsFile(commonDir), 'utf8'));
|
|
37
|
+
} catch {
|
|
38
|
+
return none;
|
|
39
|
+
}
|
|
40
|
+
if (!doc || typeof doc !== 'object' || doc.schema !== PREFS_SCHEMA) return none;
|
|
41
|
+
const c = doc.commits;
|
|
42
|
+
if (!c || typeof c !== 'object' || !COMMIT_CHOICES.includes(c.value)) return none;
|
|
43
|
+
const by = clean(c.by, 80);
|
|
44
|
+
if (!by || by.startsWith('<') || typeof c.at !== 'string' || !/^\d{4}-\d{2}-\d{2}$/.test(c.at)) return none;
|
|
45
|
+
return { commits: { value: c.value, by, at: c.at } };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// @comment -- "Records the answer a named person gave: the choice, their name and the date, written 0600 through a temporary file and a rename. Refuses an unknown choice and an empty or placeholder name; other keys already in the file are kept."
|
|
49
|
+
export function writeCommits(commonDir, value, by, at) {
|
|
50
|
+
if (!commonDir) throw new Error('this is not a git repository: preferences are kept under its git directory');
|
|
51
|
+
if (!COMMIT_CHOICES.includes(value)) throw new Error(`the choice must be one of ${COMMIT_CHOICES.join(', ')}`);
|
|
52
|
+
const name = clean(by, 80);
|
|
53
|
+
if (!name || name.startsWith('<')) throw new Error('say whose answer this is: --by "<their name>"');
|
|
54
|
+
if (!/^\d{4}-\d{2}-\d{2}$/.test(String(at))) throw new Error('the date must be YYYY-MM-DD');
|
|
55
|
+
const file = prefsFile(commonDir);
|
|
56
|
+
let doc = {};
|
|
57
|
+
try {
|
|
58
|
+
const old = JSON.parse(readFileSync(file, 'utf8'));
|
|
59
|
+
if (old && typeof old === 'object' && old.schema === PREFS_SCHEMA) doc = old;
|
|
60
|
+
} catch {
|
|
61
|
+
/* none yet */
|
|
62
|
+
}
|
|
63
|
+
mkdirSync(join(file, '..'), { recursive: true, mode: 0o700 });
|
|
64
|
+
const tmp = `${file}.tmp-${process.pid}`;
|
|
65
|
+
writeFileSync(tmp, JSON.stringify({ ...doc, schema: PREFS_SCHEMA, commits: { value, by: name, at } }, null, 2) + '\n', { mode: 0o600 });
|
|
66
|
+
try {
|
|
67
|
+
chmodSync(tmp, 0o600);
|
|
68
|
+
} catch {
|
|
69
|
+
/* best effort on platforms without modes */
|
|
70
|
+
}
|
|
71
|
+
renameSync(tmp, file);
|
|
72
|
+
return file;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// @comment -- "The briefing's Commits line, when the person has a standing answer: what the agent does with Bravos's own files and whose answer that is. Their own code is never covered by it. Nothing recorded, or 'ask', gives no line: the agent asks, as before."
|
|
76
|
+
export function commitsLine(prefs) {
|
|
77
|
+
const c = prefs?.commits;
|
|
78
|
+
if (!c || c.value === 'ask') return null;
|
|
79
|
+
const whose = `${c.by}'s standing answer, ${c.at}; change it with bravos prefs set commits`;
|
|
80
|
+
return c.value === 'commit'
|
|
81
|
+
? `Commits: commit Bravos's own files (annotations, intent, definitions, tests, the ledger) without asking (${whose}). Never include the person's own code in such a commit; ask before committing that.`
|
|
82
|
+
: `Commits: leave Bravos's own files uncommitted and list them; do not ask (${whose}).`;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// @comment -- "The hand-off from bravos start to the first agent session: a dated marker in this clone's git directory saying setup just finished here and the person expects Bravos to begin. While it is fresh and the context gate is still closed, the briefing tells the agent to start the context step in its first reply; without it, or after a few days, the briefing only offers, so a session opened for something else is never taken over. Like the preferences, nothing in a repository's tree can write it."
|
|
86
|
+
export const HANDOFF_DAYS = 3;
|
|
87
|
+
export const handoffFile = (commonDir) => join(commonDir, 'bravos', 'handoff.json');
|
|
88
|
+
|
|
89
|
+
export function writeHandoff(commonDir, at) {
|
|
90
|
+
if (!commonDir) return null;
|
|
91
|
+
const file = handoffFile(commonDir);
|
|
92
|
+
mkdirSync(join(file, '..'), { recursive: true, mode: 0o700 });
|
|
93
|
+
writeFileSync(file, JSON.stringify({ schema: 'bravos.handoff/v1', at }) + '\n', { mode: 0o600 });
|
|
94
|
+
return file;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** True while a hand-off written by bravos start is at most HANDOFF_DAYS old. */
|
|
98
|
+
export function readHandoff(commonDir, now = Date.now()) {
|
|
99
|
+
if (!commonDir) return false;
|
|
100
|
+
try {
|
|
101
|
+
const j = JSON.parse(readFileSync(handoffFile(commonDir), 'utf8'));
|
|
102
|
+
if (j?.schema !== 'bravos.handoff/v1' || typeof j.at !== 'string') return false;
|
|
103
|
+
const t = Date.parse(j.at);
|
|
104
|
+
return Number.isFinite(t) && t <= now + 60000 && now - t <= HANDOFF_DAYS * 86400000;
|
|
105
|
+
} catch {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
}
|
package/hooks/lib/refresh.mjs
CHANGED
|
@@ -105,6 +105,46 @@ export function claimsOf(token) {
|
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
+
// @comment -- "What the portal said the last time it refused to renew this machine, kept beside the licence so the person is told even when the refusal arrived in a hook or in bravos watch, whose own output nobody reads. One small file ($BRAVOS_HOME/licence-note.json): the outcome (revoked or lapsed), the sentence for the person and the time. A successful renewal removes it."
|
|
109
|
+
export const NOTE_FILE = 'licence-note.json';
|
|
110
|
+
const NOTE_DAYS = 30;
|
|
111
|
+
const notePath = (env) => {
|
|
112
|
+
const home = bravosHome(env);
|
|
113
|
+
return home ? join(home, NOTE_FILE) : null;
|
|
114
|
+
};
|
|
115
|
+
function rememberNote(env, outcome, note, now) {
|
|
116
|
+
const file = notePath(env);
|
|
117
|
+
if (!file) return;
|
|
118
|
+
try {
|
|
119
|
+
writePrivate(file, JSON.stringify({ outcome, note, at: now }) + '\n');
|
|
120
|
+
} catch {
|
|
121
|
+
/* the note is a courtesy */
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
function forgetNote(env) {
|
|
125
|
+
const file = notePath(env);
|
|
126
|
+
if (!file) return;
|
|
127
|
+
try {
|
|
128
|
+
rmSync(file);
|
|
129
|
+
} catch {
|
|
130
|
+
/* none */
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/** The remembered refusal, or null: only the two outcomes, one line of plain text, and not older than a month. */
|
|
134
|
+
export function readLicenceNote(env = process.env, now = Math.floor(Date.now() / 1000)) {
|
|
135
|
+
const file = notePath(env);
|
|
136
|
+
if (!file) return null;
|
|
137
|
+
try {
|
|
138
|
+
const j = JSON.parse(readFileSync(file, 'utf8'));
|
|
139
|
+
if (!j || !['revoked', 'lapsed'].includes(j.outcome) || typeof j.note !== 'string' || typeof j.at !== 'number') return null;
|
|
140
|
+
if (now - j.at > NOTE_DAYS * 86400 || j.at > now + 60) return null;
|
|
141
|
+
const note = j.note.replace(/[\u0000-\u001F\u007F-\u009F]/g, ' ').replace(/\s+/g, ' ').trim().slice(0, 400);
|
|
142
|
+
return note ? { outcome: j.outcome, note, at: j.at } : null;
|
|
143
|
+
} catch {
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
108
148
|
/** True when a verified device token should be replaced: past half its term, expired, in grace, or unreadable. */
|
|
109
149
|
export function refreshDue(v, now) {
|
|
110
150
|
if (v.state !== 'valid') return true;
|
|
@@ -185,16 +225,20 @@ export async function refreshIfDue(env = process.env, opts = {}) {
|
|
|
185
225
|
writeLicence(env, fresh);
|
|
186
226
|
const did = claimsOf(fresh)?.did;
|
|
187
227
|
writeDevice(env, { origin: device.origin, device_id: isDeviceId(did) ? did : device.device_id, device_secret: device.device_secret });
|
|
228
|
+
forgetNote(env);
|
|
188
229
|
return { outcome: 'refreshed', expiresAt: nv.expiresAt };
|
|
189
230
|
}
|
|
190
231
|
if (r.status === 401 || (r.status === 403 && REVOKED_ERRORS.includes(error))) {
|
|
191
232
|
const why = r.status === 401 ? 'invalid_device' : error;
|
|
192
233
|
forgetDevice(env);
|
|
234
|
+
rememberNote(env, 'revoked', revokedNote(why), now);
|
|
193
235
|
return { outcome: 'revoked', reason: why, note: revokedNote(why) };
|
|
194
236
|
}
|
|
195
237
|
if (r.status === 402) {
|
|
196
238
|
const upgrade = sameOriginLink(body?.upgrade, device.origin, ACCOUNT_UPGRADE);
|
|
197
|
-
|
|
239
|
+
const lapsed = `Your team's plan has ended, so this machine's licence will not be renewed. Choose a plan at ${upgrade}.`;
|
|
240
|
+
rememberNote(env, 'lapsed', lapsed, now);
|
|
241
|
+
return { outcome: 'lapsed', reason: 'licence_required', note: lapsed };
|
|
198
242
|
}
|
|
199
243
|
return keep(`http-${r.status}`);
|
|
200
244
|
} catch (e) {
|
package/hooks/lib/setup.mjs
CHANGED
|
@@ -26,7 +26,7 @@ export function readSetup(root, i = {}, harness = 'other') {
|
|
|
26
26
|
label: i.codegraph === 'not-built' ? 'rebuild the code graph for this commit' : 'build the code graph',
|
|
27
27
|
cta: `say "build the code graph"`,
|
|
28
28
|
unlocks: 'every later step reads it: real routes for intent, reach for annotate, call paths for templates, callers for rechecks',
|
|
29
|
-
how: `${i.codegraph === 'not-built' ? 'bravos has no graph for this commit (it keys a graph to the commit it was built at); ' : ''}ask "build the code graph" (${skill('bravos-codegraph', harness)}): the agent builds it with bravos graph build . --scip no-exec (no tokens, a few minutes; bravos setup first if bravos is missing, with your go-ahead) and asks it through bravos graph, no reconnect needed`,
|
|
29
|
+
how: i.codegraph === 'not-built' && i.graphBuild ? 'bravos is building it in the background now (no tokens, a few minutes): nothing to run; ask the graph again shortly' : `${i.codegraph === 'not-built' ? 'bravos has no graph for this commit (it keys a graph to the commit it was built at); ' : ''}ask "build the code graph" (${skill('bravos-codegraph', harness)}): the agent builds it with bravos graph build . --scip no-exec (no tokens, a few minutes; bravos setup first if bravos is missing, with your go-ahead) and asks it through bravos graph, no reconnect needed`,
|
|
30
30
|
},
|
|
31
31
|
{
|
|
32
32
|
id: 'intent',
|
package/hooks/lib/snapshot.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// @comment -- "The session-start snapshot autopilot compares against: the working-tree changes present when a session began (path to content fingerprint) and HEAD at that moment, written to .bravos/watch/turn-base/<session_id>.json (the watch folder ignores itself), plus the read-only spawn runner both hooks use. Kept apart from autopilot.mjs because the session-start hook imports it and plugin hook bundles ship without the autopilot module."
|
|
2
2
|
import { createHash } from 'node:crypto';
|
|
3
3
|
import { spawn } from 'node:child_process';
|
|
4
|
-
import { existsSync, mkdirSync, readFileSync, readdirSync, readlinkSync, lstatSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
4
|
+
import { appendFileSync, existsSync, mkdirSync, readFileSync, readdirSync, readlinkSync, lstatSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
5
5
|
import { join } from 'node:path';
|
|
6
6
|
|
|
7
7
|
const OUTPUT_CAP = 64 * 1024 * 1024;
|
|
@@ -187,3 +187,21 @@ export function readSnapshot(root, sessionId) {
|
|
|
187
187
|
}
|
|
188
188
|
}
|
|
189
189
|
|
|
190
|
+
|
|
191
|
+
export const WATCH_LOG_CAP = 500;
|
|
192
|
+
|
|
193
|
+
// @comment -- "Appends one autopilot nudge to .bravos/watch/events.jsonl for bravos watch to show: a local log, not a state store. The folder carries its own .gitignore of *, the file keeps its newest WATCH_LOG_CAP lines, and any failure is swallowed because the nudge itself already went out."
|
|
194
|
+
export function logWatchEvent(root, { summary, keys = [] }, now = new Date()) {
|
|
195
|
+
try {
|
|
196
|
+
const dir = join(root, '.bravos', 'watch');
|
|
197
|
+
mkdirSync(dir, { recursive: true });
|
|
198
|
+
const ignore = join(dir, '.gitignore');
|
|
199
|
+
if (!existsSync(ignore)) writeFileSync(ignore, '*\n');
|
|
200
|
+
const file = join(dir, 'events.jsonl');
|
|
201
|
+
appendFileSync(file, JSON.stringify({ at: now.toISOString(), text: String(summary ?? '').slice(0, 400), keys }) + '\n');
|
|
202
|
+
const lines = readFileSync(file, 'utf8').split('\n').filter(Boolean);
|
|
203
|
+
if (lines.length > WATCH_LOG_CAP) writeFileSync(file, lines.slice(-WATCH_LOG_CAP).join('\n') + '\n');
|
|
204
|
+
} catch {
|
|
205
|
+
/* the log is a convenience for bravos watch */
|
|
206
|
+
}
|
|
207
|
+
}
|
package/hooks/session-start.mjs
CHANGED
|
@@ -5,6 +5,7 @@ import { dirname, join } from 'node:path';
|
|
|
5
5
|
import { fileURLToPath } from 'node:url';
|
|
6
6
|
import { autopilotRegistered, buildBanner, buildBriefing, buildSummary, collect, readVersion, sessionHookRegistered } from './lib/briefing.mjs';
|
|
7
7
|
import { resolveTheme } from './lib/palette.mjs';
|
|
8
|
+
import { startGraphBuild } from './lib/graph-autobuild.mjs';
|
|
8
9
|
import { takeSnapshot } from './lib/snapshot.mjs';
|
|
9
10
|
|
|
10
11
|
const STDIN_WAIT_MS = 1000;
|
|
@@ -97,6 +98,10 @@ async function main() {
|
|
|
97
98
|
// end-of-turn check judges only this session's changes (no autopilot, nothing written).
|
|
98
99
|
const snap = autopilotRegistered(root) ? takeSnapshot(root, payload.session_id, { env }) : null;
|
|
99
100
|
const [inputs] = await Promise.all([collect(root, env), snap]);
|
|
101
|
+
// @comment -- "No code graph for this commit: start one quiet background build (hooks/lib/graph-autobuild.mjs) and let the briefing say it is under way. Only this repository's own copy of the hook does it, so a user-level or plugin hook never indexes a repository that did not install Bravos."
|
|
102
|
+
if (!process.argv.includes('--global') && ownCopy(root)) {
|
|
103
|
+
inputs.graphBuild = startGraphBuild({ root, env, codegraph: inputs.codegraph, licensed: inputs.licence?.licensed === true, sha: inputs.sha, installed: true });
|
|
104
|
+
}
|
|
100
105
|
text = buildBriefing(inputs);
|
|
101
106
|
if (env.BRAVOS_BANNER !== 'off' && (source === null || source === 'startup') && harness !== 'agy') {
|
|
102
107
|
const version = readVersion(dirname(fileURLToPath(import.meta.url)));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bugb-technologies/bravos",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
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",
|
package/skills/bravos/SKILL.md
CHANGED
|
@@ -27,23 +27,24 @@ description: "Start here in any repo bravos is installed in: reads the security
|
|
|
27
27
|
proving a finding, testing whether an exposure is exploitable → bravos-prove (after bravos-env).
|
|
28
28
|
a fix landed, stale claims, closing a security ticket → bravos-recheck.
|
|
29
29
|
the briefing says the branch is far behind its base, annotation work sits on an idle branch, a branch was moved or abandoned → bravos-resync.
|
|
30
|
-
"what is open?", "show me the findings", "is there a dashboard?" → answer in two or three lines from the briefing, then
|
|
30
|
+
"what is open?", "show me the findings", "is there a dashboard?" → answer in two or three lines from the briefing, then build the page without asking and give its path: `bravos dashboard --no-open` writes one self-contained HTML page (GuardLink's threat model, who introduced and fixed each exposure, what changed since the default branch; on the Team plan with the code graph built, also a Code graph tab: a map of where the risk sits, owners and history, coupling, the attack surface and entry points) under `.bravos/dashboard/`, git-ignored. Drop `--no-open`, so it opens in their browser, only when they asked to see it; add `--no-blame` when they will share the page. Always run the command: it rebuilds the page from the code as it stands, and on the Team plan rebuilds a code graph that is missing or behind first. Never open or point to a saved page instead, and when the briefing's `Dashboard:` line says the saved page is out of date, say so.
|
|
31
31
|
write up the assessment, a finding, a retest or a brief for leadership → bravos-report.
|
|
32
32
|
static analysis, dependency, secret or IaC findings → bravos-sast; "what did SAST find" → `bravos sast candidates` (the briefing's `SAST:` line says whether a run exists, or that SAST is unavailable).
|
|
33
33
|
keep annotating while I work, nightly or periodic runs → bravos-schedule.
|
|
34
34
|
security CI, a PR check, code-scanning upload → bravos-cicd.
|
|
35
35
|
reach a goal over many rounds ("100% coverage", "test every exposure", "until done", autopilot, a campaign) → bravos-campaign.
|
|
36
36
|
The briefing's `Plan:` line says which tier this machine is on. On Free, the research loop (context, annotate, templatize, env, prove, recheck, report, watch) is all there; the pre-PR gate, CI and nightly, schedule, workspaces, campaign, SAST and the code graph are on Team. When the request needs one of those, still name the right skill, say in one sentence that it is on the Team plan (`bravos account activate` starts a 30-day trial, no card), and offer the nearest free step instead; never pretend the feature ran.
|
|
37
|
-
4. bravos adds method and memory to what you can already do; it never caps it. Budgets in the skills are defaults: exceed them when the work calls for it and say why. Effort (low, medium, high, max) comes from the user's words, else a `bravos effort: <level>` line in `AGENTS.md` / `CLAUDE.md`, else medium. Only the safety rules under each skill's Never are hard. Two of them hold in every skill: before the first commit of a session ask the person once (commit now, or leave the files for them to review), even where a skill says to commit, unless they already asked for commits (a campaign, a schedule)
|
|
37
|
+
4. bravos adds method and memory to what you can already do; it never caps it. Budgets in the skills are defaults: exceed them when the work calls for it and say why. Effort (low, medium, high, max) comes from the user's words, else a `bravos effort: <level>` line in `AGENTS.md` / `CLAUDE.md`, else medium. Only the safety rules under each skill's Never are hard. Two of them hold in every skill: before the first commit of a session ask the person once (commit now, or leave the files for them to review), even where a skill says to commit, unless they already asked for commits (a campaign, a schedule) or the briefing has a `Commits:` line, which is their standing answer for Bravos's own files: follow it without asking, and never fold their own code into such a commit. When you do ask, also ask whether that is their answer from now on and, if it is, record it with `bravos prefs set commits commit|leave --by "<their name>"`; and write annotations where the briefing's `Annotations:` line says, a `.gal` sidecar in external mode and a comment above the code in inline mode.
|
|
38
38
|
5. Name the next step in one line, taken from the briefing: a `FIX NOW` item first, then a stale claim in a file the user changed, then the top `guardlink hypothesis next` item, then coverage.
|
|
39
39
|
6. When the user takes an item to work on and it already has a ticket in their tracker, record the pick-up beside its claim so the hive can see it: write `@ticket #<threat> on #<asset> <ticket-ref> sla "<label>" by <assignee> until <YYYY-MM-DD>` directly beside the claim's `@exposes`, clauses in that order, dropping `sla "<label>"` and `until <YYYY-MM-DD>` unless the user gives them, then run `guardlink validate .`. The briefing's `Open tickets` line and `guardlink lookup tickets` show it to teammates; removing the line is how the ticket leaves the model.
|
|
40
40
|
|
|
41
41
|
## Never
|
|
42
42
|
|
|
43
|
-
- Run a setup command for the person (bravos sync --autopilot, --ci, --pre-pr-hook, bravos setup, bravos graph build with --scip auto) without their go-ahead.
|
|
43
|
+
- Run a setup command for the person (bravos sync --autopilot, --ci, --pre-pr-hook, bravos setup, bravos graph build with --scip auto) without their go-ahead. The one exception is upkeep the briefing's `Upkeep:` line names: a plain `bravos sync` that brings this repository's Bravos files up to the installed version, and a plain `bravos setup` that brings Bravos's own signed bundles up to the version it pins. Run those without asking and say what changed. A first install, `bravos setup --tools` (other people's installers) and every flag above still need the go-ahead.
|
|
44
44
|
- Run `guardlink annotate` or guardlink translate with an agent flag. Those launch a second agent outside this session; you are the agent, so do the work here.
|
|
45
45
|
- Write `@accepts`, `@entitles` or `@confirmed`. Acceptance and entitlement are a human's decision; confirmation needs a reproduced run, and reading code is not one.
|
|
46
46
|
- Call anything clean, safe or fixed unless a gate said so with exit 0.
|
|
47
|
+
- Record a commit preference (`bravos prefs set`) the person did not give in this session, or put a name to one they did not give: it is their standing answer, not yours.
|
|
47
48
|
- Invent a ticket id, SLA, assignee or due date; take each from the user or their tracker.
|
|
48
49
|
|
|
49
50
|
## Done when
|
|
@@ -26,7 +26,7 @@ description: "Keep the GuardLink threat model correct and growing, in this sessi
|
|
|
26
26
|
8. Gate: run `guardlink lint . --since <start> --json`. For each entry in `violations[]`, apply its `fix`. Repeat until `summary.errors` is 0. A violation on a line you did not write this session is not yours: leave the line as it is and report it to the user.
|
|
27
27
|
9. Run `guardlink validate .` and fix what it reports in the lines you wrote.
|
|
28
28
|
10. Run `guardlink ci -f json` again and report `+<files>, <p0>% → <p1>%, <errors> lint errors`. Deep only: repeat steps 4–10 once per round, and stop when `coverage` comes back empty or a round adds no claims.
|
|
29
|
-
11. On a normal coding turn keep annotations with the code change and preserve the user's staged and uncommitted edits. For a requested standalone coverage slice, with the person's go-ahead (ask once per session unless they already asked for commits), commit the slice on its own: `git add` only the annotated files, message `annotate: <n> files, <playbook>`. Ship it as a small PR or on the feature branch, whichever the team does.
|
|
29
|
+
11. On a normal coding turn keep annotations with the code change and preserve the user's staged and uncommitted edits. For a requested standalone coverage slice, with the person's go-ahead (the briefing's `Commits:` line is their standing answer; with no such line, ask once per session unless they already asked for commits), commit the slice on its own: `git add` only the annotated files, message `annotate: <n> files, <playbook>`. Ship it as a small PR or on the feature branch, whichever the team does.
|
|
30
30
|
12. Read `guardlink hypothesis list --json`. Keep each changed exposure's stable key, source location, sidecar location when applicable, and tested state. Include untested claims with a declared mitigation. Hand new claims to bravos-templatize for a concrete kit; expired or previously tested claims go to bravos-recheck. Apply the recorded proving choice before execution: auto follows bravos-env and bravos-prove in its authorized scope; ask seeks a decision; schedule leaves the claim queued; none records that it was not tested. Evidence from a real run is required before marking a claim confirmed or refuted. Hand the change to bravos-ship before a PR.
|
|
31
31
|
|
|
32
32
|
## Never
|
|
@@ -47,7 +47,7 @@ description: "Keep the GuardLink threat model correct and growing, in this sessi
|
|
|
47
47
|
- You reported the delta line from step 10, the files left in `skipped`, and any lint violation on a line you did not write.
|
|
48
48
|
- Each new `@exposes` carries a severity with its reason, and every "intended?" `@audit` is listed for the user.
|
|
49
49
|
- Each new claim's state is clear: open or mitigated (none accepted by you), untested (an annotation alone confirms or refutes nothing), and verified or stale per `guardlink ci`. Say what was not tested. Do not call the code clean; the lint gate judges annotations, not code.
|
|
50
|
-
- If a dashboard was built earlier (the briefing's `Dashboard:` line, or one you opened this session), you
|
|
50
|
+
- If a dashboard was built earlier (the briefing's `Dashboard:` line, or one you opened this session), you rebuilt it with `bravos dashboard --no-open` and gave the path.
|
|
51
51
|
|
|
52
52
|
## What it leaves for the next skill
|
|
53
53
|
|