@bugb-technologies/bravos 1.24.0 → 1.26.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/bin.js +12 -0
- package/dist/cli.js +222 -16
- package/dist/context.js +4 -4
- package/dist/cursor.js +24 -5
- package/dist/dashboard-sast.js +113 -0
- package/dist/dashboard.js +22 -11
- package/dist/doctor.js +29 -2
- package/dist/graphbin.js +2 -2
- package/dist/guide.js +4 -2
- package/dist/hook-launcher.js +92 -0
- package/dist/hooks.js +56 -3
- package/dist/plugin-release.js +38 -12
- package/dist/prefs.js +13 -3
- package/dist/principles.js +1 -1
- package/dist/records-conflicts.js +128 -0
- package/dist/records-drafts.js +106 -0
- package/dist/records-ledger.js +103 -0
- package/dist/records-team.js +398 -0
- package/dist/records.js +158 -0
- package/dist/review-server.js +3 -1
- package/dist/review.js +16 -1
- package/dist/rules.js +97 -4
- package/dist/setup.js +6 -6
- package/dist/uninstall.js +1 -1
- package/dist/upkeep.js +3 -0
- package/docs/GUIDE.md +11 -1
- package/docs/UPGRADING.md +56 -0
- package/hooks/cards.mjs +63 -14
- package/hooks/coach.mjs +3 -1
- package/hooks/lib/agent-io.mjs +118 -0
- package/hooks/lib/briefing.mjs +94 -3
- package/hooks/lib/cards.mjs +8 -1
- package/hooks/lib/draft-check.mjs +104 -0
- package/hooks/lib/drafts.mjs +121 -0
- package/hooks/lib/ledger.mjs +270 -0
- package/hooks/lib/pre-pr.mjs +74 -0
- package/hooks/lib/prefs.mjs +7 -3
- package/hooks/lib/record-guard.mjs +272 -0
- package/hooks/lib/records.mjs +581 -0
- package/hooks/lib/replay.mjs +2 -1
- package/hooks/lib/sast.mjs +3 -1
- package/hooks/record-guard.mjs +62 -0
- package/hooks/session-start.mjs +4 -3
- package/package.json +2 -2
- package/skills/bravos/SKILL.md +1 -0
- package/skills/bravos-records/SKILL.md +57 -0
- package/templates/dashboard/dashboard.html +198 -1
- package/templates/omp/bravos.js +85 -1
- package/templates/opencode/bravos.js +84 -1
- package/templates/plugin/workspace-hook.mjs +37 -0
- package/templates/workflows/bravos-pr-gate.yml +23 -0
package/dist/dashboard.js
CHANGED
|
@@ -8,6 +8,7 @@ import { templatesDir, version } from './paths.js';
|
|
|
8
8
|
import { BravosError } from './types.js';
|
|
9
9
|
import { gatherRules } from './rules.js';
|
|
10
10
|
import { intakeSummary } from './review.js';
|
|
11
|
+
import { buildSastPart } from './dashboard-sast.js';
|
|
11
12
|
export const DASHBOARD_DIR = '.bravos/dashboard';
|
|
12
13
|
export const DASHBOARD_PATH = `${DASHBOARD_DIR}/index.html`;
|
|
13
14
|
/** What the saved page was built from, for the session briefing to tell a current page from an old one. */
|
|
@@ -111,8 +112,8 @@ export function scrubAnswers(value, opts) {
|
|
|
111
112
|
};
|
|
112
113
|
return walk(value, '', '');
|
|
113
114
|
}
|
|
114
|
-
// @comment -- "Pure: turns the graph's answers into the message each Code graph page is drawn from, with the rules the VS Code extension's host applies (siete: pagesPanel.ts `load`). A page whose main question was not answered gets a 'refused' message carrying the graph's own words, never an empty drawing; a secondary answer that is missing is passed through as not-ok so the page says so itself. Every message lists the command lines it came from.
|
|
115
|
-
export function codeGraphStore(answers) {
|
|
115
|
+
// @comment -- "Pure: turns the graph's answers into the message each Code graph page is drawn from, with the rules the VS Code extension's host applies (siete: pagesPanel.ts `load`). A page whose main question was not answered gets a 'refused' message carrying the graph's own words, never an empty drawing; a secondary answer that is missing is passed through as not-ok so the page says so itself. Every message lists the command lines it came from. The newest SAST run's findings (src/dashboard-sast.ts) are the issues the Map's Findings lens and the Attack surface's pinned column draw; with no run (or on Free) none are supplied and both pages say so."
|
|
116
|
+
export function codeGraphStore(answers, sast = null) {
|
|
116
117
|
const got = (q) => {
|
|
117
118
|
const a = answers[QUESTIONS[q].tool];
|
|
118
119
|
if (!a)
|
|
@@ -126,7 +127,7 @@ export function codeGraphStore(answers) {
|
|
|
126
127
|
const asked = (...qs) => qs.map(commandLine);
|
|
127
128
|
const [threat, hot, mix, co, surface, entries, access] = [got('threat'), got('hotspots'), got('mix'), got('coChange'), got('surface'), got('entries'), got('access')];
|
|
128
129
|
return {
|
|
129
|
-
map: codemap.ok ? { type: 'map', codemap: codemap.value, asked: asked('codemap'), findings: null } : refused('map', 'The map could not be built', codemap),
|
|
130
|
+
map: codemap.ok ? { type: 'map', codemap: codemap.value, asked: asked('codemap'), findings: sast?.issues ? { issues: sast.issues, reportId: sast.reportId } : null } : refused('map', 'The map could not be built', codemap),
|
|
130
131
|
trust: codemap.ok ? { type: 'trust', codemap: codemap.value, threatModel: threat, asked: asked('codemap', 'threat') } : refused('trust', 'The graph could not describe itself', codemap),
|
|
131
132
|
owners: !hot.ok
|
|
132
133
|
? refused('owners', 'Churn and ownership are not available', hot)
|
|
@@ -134,7 +135,7 @@ export function codeGraphStore(answers) {
|
|
|
134
135
|
? refused('owners', 'Churn and ownership are not available', codemap)
|
|
135
136
|
: { type: 'owners', hotspots: hot.value, codemap: codemap.value, commitMix: mix, asked: asked('hotspots', 'codemap', 'mix') },
|
|
136
137
|
coupling: co.ok ? { type: 'coupling', coChange: co.value, codemap, asked: asked('coChange', 'codemap') } : refused('coupling', 'Co-change coupling is not available', co),
|
|
137
|
-
surface: surface.ok ? { type: 'surface', attackSurface: surface.value, issues: null, asked: asked('surface') } : refused('surface', 'The attack surface is not available', surface),
|
|
138
|
+
surface: surface.ok ? { type: 'surface', attackSurface: surface.value, issues: sast?.issues ?? null, asked: asked('surface') } : refused('surface', 'The attack surface is not available', surface),
|
|
138
139
|
entries: entries.ok ? { type: 'entries', entryPoints: entries.value, access, asked: asked('entries', 'access') } : refused('entries', 'Entry points are not available', entries),
|
|
139
140
|
links: { type: 'links', entryPoints: entries, asked: asked('entries') },
|
|
140
141
|
};
|
|
@@ -214,7 +215,7 @@ export async function buildCodeGraph(root, env, opts = {}) {
|
|
|
214
215
|
if (errors.every(Boolean))
|
|
215
216
|
return note('failed', `The code graph answered none of the questions (${errors[0].slice(0, 200)}).`);
|
|
216
217
|
// Scrubbed first, so the pages that share the code map still share one object and it is stored once.
|
|
217
|
-
const store = codeGraphStore(scrubAnswers(answered.answers, { root: resolve(root), repo: repoName(root, env), names: opts.names !== false }));
|
|
218
|
+
const store = codeGraphStore(scrubAnswers(answered.answers, { root: resolve(root), repo: repoName(root, env), names: opts.names !== false }), opts.sast ?? null);
|
|
218
219
|
const states = Object.values(answered.answers).map((a) => ('result' in a ? text(obj(obj(a.result).graph_currency).state) : '')).filter(Boolean);
|
|
219
220
|
const stale = states.find((x) => x !== 'current');
|
|
220
221
|
return { state: 'present', store, note: `The code graph's answers when this page was built: the map, owners and history, coupling, trust, attack surface, entry points and links.${rebuilt}${stale ? ` The graph is ${stale}: the code has moved since it was built, so rebuild it with bravos graph build .` : ''}` };
|
|
@@ -232,7 +233,7 @@ export function shareCodeMap(store) {
|
|
|
232
233
|
return { codemap: shared, pages };
|
|
233
234
|
}
|
|
234
235
|
// @comment -- "Renders the one-file dashboard: the page template with its facts and GuardLink's page each embedded as JSON in a non-executing script tag, every '<' escaped so none can close its tag. When there are code graph answers, they and the vendored Code graph pages (script and stylesheet) are embedded the same way; the page assembles them into a second sandboxed frame. Both go in through one pass with a function replacer, so nothing in either is read as a placeholder or a replacement pattern."
|
|
235
|
-
export function renderDashboard(data, threatModelHtml, store = null, rules = null) {
|
|
236
|
+
export function renderDashboard(data, threatModelHtml, store = null, rules = null, sast = null) {
|
|
236
237
|
const template = readFileSync(join(templatesDir(), 'dashboard', 'dashboard.html'), 'utf8');
|
|
237
238
|
// One pass over the template, so text inside either value that looks like a placeholder is never filled in turn.
|
|
238
239
|
// The pages' script and stylesheet travel only with a page that has graph answers to draw.
|
|
@@ -244,8 +245,9 @@ export function renderDashboard(data, threatModelHtml, store = null, rules = nul
|
|
|
244
245
|
PAGES_JS: () => asset('codegraph-pages.js'),
|
|
245
246
|
PAGES_CSS: () => asset('codegraph-pages.css'),
|
|
246
247
|
RULES: () => rules,
|
|
248
|
+
SAST: () => sast,
|
|
247
249
|
};
|
|
248
|
-
return template.replace(/__BRAVOS_(DATA|THREAT_MODEL|CODEGRAPH|PAGES_JS|PAGES_CSS|RULES)__/g, (_m, which) => inert(fill[which]()));
|
|
250
|
+
return template.replace(/__BRAVOS_(DATA|THREAT_MODEL|CODEGRAPH|PAGES_JS|PAGES_CSS|RULES|SAST)__/g, (_m, which) => inert(fill[which]()));
|
|
249
251
|
}
|
|
250
252
|
// @comment -- "bravos dashboard: gathers the repository's facts (read-only git, this machine's plan label), builds GuardLink's page and, on the Team plan, the Code graph pages from the graph's answers, and writes one self-contained HTML file. By default that is .bravos/dashboard/index.html beside a .gitignore of '*', since the page can carry git identities and findings; with `out` nothing is written inside the repository. A page is written even when GuardLink has nothing to show, so the person always gets a file that says what to do next."
|
|
251
253
|
export async function buildDashboard(root, env, opts = {}) {
|
|
@@ -255,7 +257,9 @@ export async function buildDashboard(root, env, opts = {}) {
|
|
|
255
257
|
}
|
|
256
258
|
const base = opts.since ?? baseRef(root, env);
|
|
257
259
|
const tm = buildThreatModel(root, env, { base, blame: opts.blame !== false });
|
|
258
|
-
|
|
260
|
+
// The newest SAST run, for its own view and for the Code graph pages' findings (Team plan; a line on Free).
|
|
261
|
+
const sast = await buildSastPart(root, env);
|
|
262
|
+
const cg = await buildCodeGraph(root, env, { names: opts.blame !== false, refresh: opts.graphBuild !== false, onProgress: opts.onProgress, sast });
|
|
259
263
|
// The design rules: free on every plan, read from the intent, GuardLink's model and its test ledger. A failure
|
|
260
264
|
// here is a note on that view, never a failed page.
|
|
261
265
|
let rules = null;
|
|
@@ -265,6 +269,12 @@ export async function buildDashboard(root, env, opts = {}) {
|
|
|
265
269
|
rulesPart = { state: rules.state === 'none' ? 'missing' : 'present', note: rules.note };
|
|
266
270
|
// The Security design view is on the Team plan; on Free the principles stay followed (the instruction block) and
|
|
267
271
|
// the view says what would show them.
|
|
272
|
+
// The decision records view is on the Team plan too; on Free the records stay followed (the briefing, the edit hooks).
|
|
273
|
+
if (rules.records?.length) {
|
|
274
|
+
const f = await featureState(env, 'principles', 'The Decision records view');
|
|
275
|
+
if (!f.entitled)
|
|
276
|
+
rules = { ...rules, records: [], conflicts: [], conflictsNote: '', recordsNote: `${rules.records.length} record rule${rules.records.length === 1 ? ' is' : 's are'} written down here, and coding agents follow the adopted ones on every plan. ${f.refusal}.` };
|
|
277
|
+
}
|
|
268
278
|
if (rules.principles.length) {
|
|
269
279
|
const f = await featureState(env, 'principles', 'The Security design view');
|
|
270
280
|
if (!f.entitled)
|
|
@@ -293,9 +303,10 @@ export async function buildDashboard(root, env, opts = {}) {
|
|
|
293
303
|
threatModel: { state: tm.state, note: tm.note, blame: tm.blame, since: tm.since },
|
|
294
304
|
codeGraph: { state: cg.state, note: cg.note },
|
|
295
305
|
rules: rulesPart,
|
|
306
|
+
sast: { state: sast.state === 'off' ? 'locked' : sast.state, note: sast.note },
|
|
296
307
|
intake: intakeSummary(root),
|
|
297
308
|
};
|
|
298
|
-
const page = renderDashboard(data, tm.html, cg.store, rules);
|
|
309
|
+
const page = renderDashboard(data, tm.html, cg.store, rules, sast.view);
|
|
299
310
|
let path;
|
|
300
311
|
if (opts.out) {
|
|
301
312
|
path = resolve(opts.out);
|
|
@@ -309,9 +320,9 @@ export async function buildDashboard(root, env, opts = {}) {
|
|
|
309
320
|
writeFileSync(ignore, '*\n');
|
|
310
321
|
path = join(root, DASHBOARD_PATH);
|
|
311
322
|
// Beside the page: what it was built from, so the session briefing can say when it has fallen behind.
|
|
312
|
-
const meta = { schema: 'bravos.dashboard-meta/v1', generatedAt: data.generatedAt, commit: git(root, env, ['rev-parse', 'HEAD']), branch: data.branch, threatModel: tm.state, codeGraph: cg.state, rules: rulesPart.state };
|
|
323
|
+
const meta = { schema: 'bravos.dashboard-meta/v1', generatedAt: data.generatedAt, commit: git(root, env, ['rev-parse', 'HEAD']), branch: data.branch, threatModel: tm.state, codeGraph: cg.state, rules: rulesPart.state, sast: sast.state };
|
|
313
324
|
writeFileSync(join(root, DASHBOARD_META), `${JSON.stringify(meta, null, 2)}\n`);
|
|
314
325
|
}
|
|
315
326
|
writeFileSync(path, page);
|
|
316
|
-
return { path, threatModel: { state: tm.state, note: tm.note }, codeGraph: { state: cg.state, note: cg.note }, rules: rulesPart };
|
|
327
|
+
return { path, threatModel: { state: tm.state, note: tm.note }, codeGraph: { state: cg.state, note: cg.note }, rules: rulesPart, sast: { state: sast.state === 'off' ? 'locked' : sast.state, note: sast.note } };
|
|
317
328
|
}
|
package/dist/doctor.js
CHANGED
|
@@ -4,9 +4,11 @@ import { join } from 'node:path';
|
|
|
4
4
|
import { installedGuardlinkSkills, whichBin } from './guardlink.js';
|
|
5
5
|
import { graphBin } from './codegraph.js';
|
|
6
6
|
import { findAnalyzer, findLicence } from './graphbin.js';
|
|
7
|
-
import { ALL_AUTOPILOT_COMMANDS, ALL_CARDS_COMMANDS, ALL_COACH_COMMANDS, ALL_PRE_PR_COMMANDS, HOOK_COMMANDS, LEGACY_HOOK_COMMAND, RELATIVE_HOOK_COMMANDS, hookRegistered } from './hooks.js';
|
|
7
|
+
import { ALL_AUTOPILOT_COMMANDS, ALL_CARDS_COMMANDS, ALL_COACH_COMMANDS, ALL_PRE_PR_COMMANDS, ALL_RECORD_GUARD_COMMANDS, HOOK_COMMANDS, LEGACY_HOOK_COMMAND, RELATIVE_HOOK_COMMANDS, agyRegistered, hookRegistered } from './hooks.js';
|
|
8
8
|
import { skillsRoot } from './skills.js';
|
|
9
|
-
import { cursorHookRegistered } from './cursor.js';
|
|
9
|
+
import { cursorEditHooks, cursorHookRegistered } from './cursor.js';
|
|
10
|
+
import { OMP_EXTENSION_PATH } from './omp.js';
|
|
11
|
+
import { OPENCODE_PLUGIN_PATH } from './opencode.js';
|
|
10
12
|
import { contextIgnoreFix, contextIgnoreWarning } from './context.js';
|
|
11
13
|
import { resolveTheme } from './palette.js';
|
|
12
14
|
import { pathToFileURL } from 'node:url';
|
|
@@ -88,10 +90,34 @@ export function runDoctor(root, env = process.env) {
|
|
|
88
90
|
claude: hookRegistered(join(root, '.claude', 'settings.json'), 'PreToolUse', ALL_PRE_PR_COMMANDS),
|
|
89
91
|
codex: hookRegistered(join(root, '.codex', 'hooks.json'), 'PreToolUse', ALL_PRE_PR_COMMANDS),
|
|
90
92
|
},
|
|
93
|
+
edit_hooks: editHooks(root),
|
|
91
94
|
theme: resolveTheme(env),
|
|
92
95
|
updates: readUpdates(env),
|
|
93
96
|
};
|
|
94
97
|
}
|
|
98
|
+
// @comment -- "Which agents get the record guard and the after-edit cards here, read from the files Bravos wrote for each: the Claude Code and Codex settings, .cursor/hooks.json, .agents/hooks.json, and the opencode and omp plugin files (whose tool hooks call bravos hook). An agent Bravos has not set up here reads as null, not as missing."
|
|
99
|
+
function editHooks(root) {
|
|
100
|
+
const claude = join(root, '.claude', 'settings.json');
|
|
101
|
+
const codex = join(root, '.codex', 'hooks.json');
|
|
102
|
+
const plugin = (rel) => {
|
|
103
|
+
try {
|
|
104
|
+
const t = readFileSync(join(root, rel), 'utf8');
|
|
105
|
+
return { guard: t.includes("askBravos('record-guard'"), cards: t.includes("askBravos('cards'") };
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
const agy = existsSync(join(root, '.agents', 'hooks.json')) ? agyRegistered(root) : null;
|
|
112
|
+
return {
|
|
113
|
+
claude: existsSync(claude) ? { guard: hookRegistered(claude, 'PreToolUse', ALL_RECORD_GUARD_COMMANDS), cards: hookRegistered(claude, 'PostToolUse', ALL_CARDS_COMMANDS) } : null,
|
|
114
|
+
codex: existsSync(codex) ? { guard: hookRegistered(codex, 'PreToolUse', ALL_RECORD_GUARD_COMMANDS), cards: hookRegistered(codex, 'PostToolUse', ALL_CARDS_COMMANDS) } : null,
|
|
115
|
+
cursor: existsSync(join(root, '.cursor', 'hooks.json')) ? cursorEditHooks(root) : null,
|
|
116
|
+
antigravity: agy ? { guard: agy.guard, cards: agy.cards } : null,
|
|
117
|
+
opencode: plugin(OPENCODE_PLUGIN_PATH),
|
|
118
|
+
omp: plugin(OMP_EXTENSION_PATH),
|
|
119
|
+
};
|
|
120
|
+
}
|
|
95
121
|
// @comment -- "What the daily update check last saw (~/.bravos/update-check.json, written by hooks/lib/update-check.mjs): off, never checked, or the latest published version and when it was checked. Only a dotted version string is read from the file."
|
|
96
122
|
function readUpdates(env) {
|
|
97
123
|
const installed = packageVersion();
|
|
@@ -154,6 +180,7 @@ export function formatDoctor(r) {
|
|
|
154
180
|
`pre-pr claude: ${yn(r.pre_pr.claude)} codex: ${yn(r.pre_pr.codex)}${r.pre_pr.claude || r.pre_pr.codex ? '' : ' (opt-in: bravos setup --pre-pr-hook)'}`,
|
|
155
181
|
`autopilot claude: ${yn(r.autopilot.claude)} codex: ${yn(r.autopilot.codex)}${r.autopilot.claude || r.autopilot.codex ? '' : ' (opt-in: bravos setup --autopilot)'}`,
|
|
156
182
|
`cards claude: ${yn(r.cards.claude)} codex: ${yn(r.cards.codex)}${r.cards.claude || r.cards.codex ? (process.env.BRAVOS_THREAT_CARDS === 'off' ? ' (off for this run: BRAVOS_THREAT_CARDS=off)' : '') : ' (bravos setup adds it)'}`,
|
|
183
|
+
`edit hooks (record guard / cards) ${Object.entries(r.edit_hooks ?? {}).filter(([, v]) => v).map(([k, v]) => `${k}: ${v.guard && v.cards ? 'yes' : v.guard || v.cards ? `partly (guard ${yn(v.guard)}, cards ${yn(v.cards)})` : 'no'}`).join(' ') || 'no agent set up here'}${Object.values(r.edit_hooks ?? {}).some((v) => v && !(v.guard && v.cards)) ? ' (bravos setup wires them)' : ''}`,
|
|
157
184
|
`coach claude: ${yn(r.coach.claude)} codex: ${yn(r.coach.codex)}${r.coach.claude || r.coach.codex ? (process.env.BRAVOS_COACH === 'off' ? ' (off for this run: BRAVOS_COACH=off)' : '') : ' (bravos setup adds it)'}`,
|
|
158
185
|
...(r.dead_hooks?.length ? [`✘ dead user-level hooks ${r.dead_hooks.map((d) => `${d.file} ${d.event}: ${d.script} is gone`).join('; ')} — every session shows "hook error". Remove them (a backup is kept): bravos doctor --fix-hooks`] : r.dead_hooks ? ['✔ no dead user-level hooks'] : []),
|
|
159
186
|
...(r.legacy_skills?.length ? [`✘ old Python bravos skills ${r.legacy_skills.map((f) => `${f.root}: ${f.names.join(', ')}`).join('; ')} — your agent may load them instead of this repository's. Move them aside (reversible): ${r.legacy_command}`] : r.legacy_skills ? ['✔ no old Python bravos skills at user level'] : []),
|
package/dist/graphbin.js
CHANGED
|
@@ -19,8 +19,8 @@ export function pythonBravos(env = process.env) {
|
|
|
19
19
|
const real = realpathSync(file);
|
|
20
20
|
if (real.startsWith(self + '/'))
|
|
21
21
|
continue;
|
|
22
|
-
// An npm shim (a shell script that execs node on this package's dist/cli.js) is not the Python CLI either.
|
|
23
|
-
if (readFileSync(real, 'utf8')
|
|
22
|
+
// An npm shim (a shell script that execs node on this package's dist/bin.js, or dist/cli.js before 1.25) is not the Python CLI either.
|
|
23
|
+
if (/dist\/(?:bin|cli)\.js/.test(readFileSync(real, 'utf8')))
|
|
24
24
|
continue;
|
|
25
25
|
return file;
|
|
26
26
|
}
|
package/dist/guide.js
CHANGED
|
@@ -117,6 +117,7 @@ export const GUIDE_TOPICS = [
|
|
|
117
117
|
{ name: 'Teach bravos what the app is for', skills: ['bravos-context'], body: ['Writes .guardlink/intent.md: invariants (INV-n) that become threats, and intended-by-design items (INT-n) that get an "intended?" audit instead of a high rating.'] },
|
|
118
118
|
{ name: 'Start from your design documents', skills: ['bravos-context'], body: ['Give bravos-context your PRDs, design documents or an earlier threat model, as files or links. Each is kept in the repository as Markdown under .bravos/context/ (bravos context add; committed, so the team can keep it current) after a check for secrets and local paths; a link is kept beside its snapshot. Every rule then names the document it came from (INV-4, source: SRC-2), including who may do what: "sales may see every report except the revenue report" becomes a rule that can be tested, where a scan would see nothing wrong. bravos context list shows the documents, bravos context check re-checks them, and a pre-push check stops a push that would send a secret in one. Free; the CLI runs no model and fetches nothing: your agent converts and fetches with your own access.'] },
|
|
119
119
|
{ name: 'Write down your company\'s security design principles', skills: ['bravos-principles'], body: ['Ask for "our security design principles". bravos-principles proposes candidates only from your stored documents (cited by section, checked against the text), INV rules a person already confirmed in this or another repository, or an optional starter list mapped to OWASP ASVS 4.0.3, which is never pre-selected; bravos review principles refuses anything else. On the page each principle is its own decision (Agree, Change the wording, or No); there is no adopt-all. Confirm records your adoption with the exact wording and a fingerprint, and bravos writes .guardlink/principles.md from the adoptions: committed, so every developer who pulls gets it, and the Bravos block in AGENTS.md and CLAUDE.md tells every coding agent to read and follow it and never edit it. A principle is enforced (it becomes a threat with principle:SDP-n, is tested, and the pre-PR gate stops a change that breaks it, whatever the PR body says) or guidance (followed, not tested). bravos principles check (free; the pre-push hook and the gate run it) fails a hand-edited line, an adoption nobody made, or an exception past its date. An exception is approved by a person at their own terminal: bravos principles except SDP-n --where "<glob>" --reason "<why>" --until <date>, at most a year, never extended; a coding agent cannot run it. bravos principles copy --from <repository> takes the same set into another repository, and check says when the source changes. The dashboard\'s Security design view shows each principle, where it is enforced, its exceptions, and what it caught or stopped in the last 30 and 90 days. Team plan for authoring, the gate and the view; adopted principles are followed on every plan.'] },
|
|
120
|
+
{ name: 'Write down what was decided for one module', skills: ['bravos-records'], body: ['Ask for "a security decision record for <module>". bravos-records drafts one document for that module (.guardlink/records/SDR-n-<module>.md) from what you tell it, your documents and confirmed rules: the decision, the rules that follow, why, and what looks like a bug but is not. It is a draft until its text reaches the default branch: approved when a code owner reviews the pull request that merges it (bravos records check asks GitHub with gh whether the branch requires that review, and offers CODEOWNERS lines for .guardlink/records/ that it writes only after you say yes: bravos records codeowners --owner @you). Without that review, a record on the default branch reads \'on main, review not enforced\'; the weaker fallback is a person running bravos records adopt SDR-n at their own terminal and typing their name, which shows who said so, not that anyone reviewed it. An agent cannot approve or adopt one. From then on every coding agent asks bravos records for <file> before changing covered code and follows the record; in Claude Code, Codex, Cursor, Antigravity, opencode and omp the first edit of a covered file in a session is refused once with the record in full (each in its own hook shape, through the installed CLI; any hook error lets the edit through), so it is read before anything changes. A change that goes against a rule is raised with you first and shows as a decision-record card after the edit, as does a removed check, and a record edited on a branch is a proposal: the default branch\'s text binds until the edit is approved, and only the branch that edits it waits (bravos records check). In CI, the PR gate checks with the workflow\'s GITHUB_TOKEN that a code owner approved the last change to each record and reports what it could not prove. A module ledger, .guardlink/records/README.md, lists which modules of the application make security decisions: the agent proposes it (bravos records ledger propose: features found from the stored documents, the threat model and the folders, with the code graph\'s routes on the Team plan; without the graph a feature split over folders with different names can show as two modules, so the boundaries are for a person to review), a person reviews it in its pull request, and Bravos keeps its Record and Owner columns (bravos records ledger refresh, owners from CODEOWNERS). It is never enforced. From the first session the briefing counts it ("9 modules, 2 with records"), and the first edit in a session to a module it says needs a record, and has none, gets one line offering to draft one, never a block; the company principles apply either way (bravos prefs set nudge off silences it). On the Team plan, once a person has reviewed the ledger, the agent drafts records for the modules that need one in the background: a subagent runs bravos records drafts (at most 2 a run, 3 waiting for review at once, never two for one module) and bravos records draft "<module>", which starts each draft on its own branch and worktree so your checkout is never touched. A draft states only what your documents (SRC-n § Section), confirmed intent rules or people said, cited on the line; what the code does today is marked observed and kept as guidance; Not a bug is never filled from code. bravos records check holds every citation to the repository. The agent pushes nothing and asks you before opening each draft\'s pull request; it binds nobody until a code owner approves it, and only that branch waits. bravos prefs set drafts off stops it. bravos rules lists each rule with its status. On the Team plan the pre-PR gate holds a change that breaks an adopted enforced rule whatever the PR body says, until the code is fixed, a person approves a dated exception (bravos records except SDR-n R1, at their own terminal), or the record is changed and the new text approved; people can adopt on a page with bravos review records (Agree, Change or No per rule); bravos records gaps lists modules no record covers; and the dashboard has a Decision records view, with possible conflicts: open exposures and SAST findings in a record\'s paths whose kind of weakness bears on one of its rules, each with the reason (bravos records conflicts lists the same; they never change a rule\'s status, and a person dismisses one at their own terminal). Reading and following records is free; writing, adopting, exceptions, the gate, gaps and the view are on the Team plan.'] },
|
|
120
121
|
{ name: 'See which design rules hold', skills: ['bravos', 'bravos-recheck'], body: ['bravos rules lists every rule your design states (INV-n in the intent) with its status: broken (a test got through), retest due (the code under it changed since it was tested), unguarded (it can break somewhere and nothing stops it), guarded but untested, not placed (no code is tied to it yet), or holds (a test tried and was refused everywhere it is enforced). Each line names the document the rule came from and the places it is enforced. bravos dashboard shows the same under Threat model, as Design rules in GuardLink\'s sidebar beside Exposures, worst first. Free, read-only, no model; --json prints bravos.rules/v1. On the Team plan the pre-PR check and the PR workflow hold a pull request that changes a file a holding rule is enforced in (the check, or the role table that grants the permission) after that rule was last tested, until its test is replayed or the PR body names the rule; the after-edit note says the same while you work.'] },
|
|
121
122
|
{ name: 'The intake asks, it never blocks', skills: ['bravos-context', 'bravos-annotate'], body: ['Annotation starts in the first session. With no confirmed intent, the agent drafts what the product is for from the README, docs and code (.guardlink/intent.md, every item marked draft), annotates against that draft, and opens the intake page without waiting. Each session asks once for a person to confirm it (bravos review intent, a few minutes) until someone confirms or declines; the agent never confirms for you. Rules drafted from the design are tested and can block a pull request right away; bravos rules and the block message label them draft until a person confirms them. When the answers arrive, the agent re-judges what they changed: an item you mark intended by design is annotated as intended, not as a finding. The intake page brings back the answers each person gave when they reopen it, and saves them as they go; only Confirm makes them count, and it records who and when. Design documents (a PRD, a design document, an earlier threat model) can be added on the page itself: Markdown and text are stored with the usual checks, and a PDF, Word file, slides or link waits for the agent to convert. Every rule cites the section of the document it came from, the page shows that passage under the question, and bravos context check refuses a section the document does not have. The intake and the documents are committed so the team gets them on their next pull; bravos doctor warns when a .gitignore rule keeps them on one machine, and bravos context share --yes narrows a blanket .bravos/ rule. A team that chooses to go without records that under a name, bravos context decline --by "<name>", which is committed like the intent and ends the asking; a coding agent is told never to decline for you. bravos context gate says which state a repository is in.'] },
|
|
122
123
|
{ name: 'Updates', skills: ['bravos'], body: ['Bravos tells you when it is updated. At most once a day a session start asks the npm registry, in a background process the session never waits on, for the latest published version: the same request npm install makes, with only the package name. A newer version shows in the banner and the briefing, and the coach tells a session that is already running, once. Installing it is yours to do (npm install -g @bugb-technologies/bravos); once it is installed the coach has the agent run bravos setup in the repository, which brings its Bravos files up to date. bravos doctor shows the last check. BRAVOS_UPDATE_CHECK=off stops the check, and it never runs in CI.'] },
|
|
@@ -139,14 +140,14 @@ export const GUIDE_TOPICS = [
|
|
|
139
140
|
{ name: 'An app made of several repositories (microservices)', skills: ['bravos-annotate', 'bravos-codegraph', 'bravos-prove'], body: ['Clone the services side by side in one folder, then run bravos workspace create NAME --member ./gateway=gateway@http://127.0.0.1:8080 --member ./orders=orders@http://127.0.0.1:8081 (bravos workspace plus guardlink link-project plus bravos in each repo and in the shared folder). Work on a service from its own repo; ask questions that cross services from the shared folder, where the briefing and bravos watch show every service. Declare each call to another service as @flows #<this>-<x> -> #<other>-<y> via http (plain ids, not #repo.tag). Build the code graph over the shared folder so it links one service\'s client calls to another\'s handlers. bravos report data --workspace writes one report across the services.'] },
|
|
140
141
|
{ name: 'After updating bravos', skills: ['bravos'], body: ['Nothing to run by hand in a repository you work in with an agent: at the start of a session bravos upkeep (read-only, no network) tells the agent what is behind the installed version, and the agent runs bravos setup, which brings the repository\'s skills and hooks and Bravos\'s own bundles up to date, without asking. If a teammate synced the repository with a newer bravos than yours, the agent syncs nothing and tells you to update. Installing guardlink and cxg (bravos setup --tools) still waits for your go-ahead.'] },
|
|
141
142
|
{ name: 'Stop being asked about commits', skills: ['bravos'], body: ['Say once whether your agent commits the files Bravos writes (annotations, intent, definitions, tests): bravos prefs set commits commit|leave|ask --by "<your name>". bravos setup asks it too. The answer is kept in this clone\'s git directory, never committed, and your own code is never part of such a commit. bravos prefs get shows it.'] },
|
|
142
|
-
{ name: 'See the findings on one page', skills: ['bravos'], body: ['Run bravos dashboard (free, no model): it writes one self-contained page under .bravos/dashboard/ (git-ignored) and opens it in your browser. It is GuardLink\'s threat model with who introduced and fixed each exposure and what changed since the default branch; on the Team plan, with the code graph built, a second tab shows the code graph: a map of where the risk sits, owners and history, coupling, trust, the attack surface, entry points and links. Run it again whenever you want the picture: it rebuilds from the code as it stands, rebuilding a code graph that is missing or behind first, and a saved page says when it is more than half a day old. --no-blame leaves git names out of a page you will share; --no-open only prints the path. Or ask your agent "show me the findings".'] },
|
|
143
|
+
{ name: 'See the findings on one page', skills: ['bravos'], body: ['Run bravos dashboard (free, no model): it writes one self-contained page under .bravos/dashboard/ (git-ignored) and opens it in your browser. It is GuardLink\'s threat model with who introduced and fixed each exposure and what changed since the default branch; on the Team plan, with the code graph built, a second tab shows the code graph: a map of where the risk sits, owners and history, coupling, trust, the attack surface, entry points and links. Run it again whenever you want the picture: it rebuilds from the code as it stands, rebuilding a code graph that is missing or behind first, and a saved page says when it is more than half a day old. --no-blame leaves git names out of a page you will share; --no-open only prints the path. Or ask your agent "show me the findings". With a SAST run (Team plan), a SAST view lists its findings, those joined to a claim, those not in the threat model yet, dependencies and secrets (by type and place, never the value), with how many commits the run is behind; the code graph Map\'s Findings lens draws the same findings.'] },
|
|
143
144
|
{ name: 'Write up the assessment, a finding or a retest', skills: ['bravos-report'], body: ['Ask "write the assessment report" (or a finding, a retest, an executive brief). bravos report data gathers the evidence; the agent writes report.md in the eight-section reading order, with every proof claim citing its evidence; bravos report check refuses a finding labelled reproduced without a run or ledger record; bravos report export writes md, txt, html and pdf. bravos watch shows the newest report (p to read it, o to open the pdf or html).'] },
|
|
144
145
|
],
|
|
145
146
|
},
|
|
146
147
|
{
|
|
147
148
|
id: 'skills',
|
|
148
149
|
title: 'Every skill',
|
|
149
|
-
summary: 'all
|
|
150
|
+
summary: 'all eighteen skills, what each does and leaves for the next',
|
|
150
151
|
items: [
|
|
151
152
|
{ name: 'bravos', body: ['Front door: reads the security picture, explains the evidence loop, routes to the right skill.'] },
|
|
152
153
|
{ name: 'bravos-context', body: ['Learns what the product intends from the repo and a short interview; records invariants, intended behaviour, actors, assets and boundaries.'] },
|
|
@@ -161,6 +162,7 @@ export const GUIDE_TOPICS = [
|
|
|
161
162
|
{ name: 'bravos-sast', body: ['Licensed static analysis joined to guardlink claims and reachability; gates on findings new since the base.'] },
|
|
162
163
|
{ name: 'bravos-threat-hunt', body: ['"Identify all the threats": maps the attack surface with the code graph, runs SAST, records every finding in the threat model with bravos-annotate, rebuilds the dashboard and reports from what was recorded, then recommends confirming the top three.'] },
|
|
163
164
|
{ name: 'bravos-principles', body: ['Your company\'s security design principles, from your own documents and confirmed rules (or an optional starter list mapped to OWASP ASVS): proposed on the review page, adopted one by one by named people, written by bravos to .guardlink/principles.md, followed by every coding agent, and enforced ones tested and held to by the pre-PR gate.'] },
|
|
165
|
+
{ name: 'bravos-records', body: ['Security decision records, one document per module or feature: what was decided there, the rules that follow, why, and what looks like a bug but is not. Drafted from what the team states, approved through a code owner\'s pull-request review (or, weaker, a name typed at a person\'s own terminal), read by every coding agent before it changes covered code, and listed rule by rule in bravos rules.'] },
|
|
164
166
|
{ name: 'bravos-campaign', body: ['A goal over many rounds: disjoint batches, one subagent each, a gate per batch, rests, a final before-and-after.'] },
|
|
165
167
|
{ name: 'bravos-schedule', body: ['Recurring upkeep with each harness\'s own mechanism; never live tests from a loop.'] },
|
|
166
168
|
{ name: 'bravos-cicd', body: ['Audits and writes the security workflows.'] },
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// @comment -- "The hook launcher: runs one of the hook scripts this installed bravos ships, by name, in this same Node process, so a hook registered as `bravos hook <name>` behaves byte for byte like `node .bravos/hooks/<name>.mjs` (same stdin, stdout, stderr and exit code) without a repository copy. It imports nothing of bravos's own beyond node built-ins, so the bin shim can reach it without loading the CLI's commands. Only names in the fixed table run; any other name, or none, exits 0 with no output, so a pointer to a hook a later or earlier bravos does not ship never breaks an agent's turn."
|
|
2
|
+
import { spawnSync } from 'node:child_process';
|
|
3
|
+
import { existsSync, realpathSync } from 'node:fs';
|
|
4
|
+
import { homedir } from 'node:os';
|
|
5
|
+
import { dirname, join, resolve } from 'node:path';
|
|
6
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
7
|
+
// @comment -- "Every script a repository copy of the hooks can be run as today: the agent hooks the harnesses register, the invitation snooze, the library commands the skills, git hooks and CI workflows call, and the nightly tools bootstrap. A name maps to a path inside this package's hooks/ folder; nothing a caller passes becomes part of a path."
|
|
8
|
+
export const HOOKS = Object.freeze({
|
|
9
|
+
'session-start': 'session-start.mjs',
|
|
10
|
+
coach: 'coach.mjs',
|
|
11
|
+
cards: 'cards.mjs',
|
|
12
|
+
autopilot: 'autopilot.mjs',
|
|
13
|
+
'pre-pr': 'pre-pr.mjs',
|
|
14
|
+
invite: 'invite.mjs',
|
|
15
|
+
replay: 'lib/replay.mjs',
|
|
16
|
+
context: 'lib/context.mjs',
|
|
17
|
+
principles: 'lib/principles.mjs',
|
|
18
|
+
'threat-issues': 'lib/threat-issues.mjs',
|
|
19
|
+
'nightly-stage': 'lib/nightly-stage.mjs',
|
|
20
|
+
'nightly-tools': 'lib/nightly-tools.sh',
|
|
21
|
+
'record-guard': 'record-guard.mjs',
|
|
22
|
+
records: 'lib/records.mjs',
|
|
23
|
+
});
|
|
24
|
+
// @comment -- "The hooks a harness runs on its own events (session start, each prompt, each edit, end of turn, before a pull request). As a pointer they may run in a repository Bravos is not set up in; there they do nothing, as no repository copy would exist to run. An explicit `session-start --briefing` is a request, not an event, and always answers."
|
|
25
|
+
export const AGENT_EVENTS = new Set(['session-start', 'coach', 'cards', 'autopilot', 'pre-pr', 'record-guard']);
|
|
26
|
+
// @comment -- "Hook scripts that run only through the installed CLI (bravos hook <name>) and are never copied into a repository's .bravos/hooks/, so moving the hooks out of repositories has nothing more to migrate."
|
|
27
|
+
export const CLI_ONLY_HOOKS = Object.freeze(['record-guard.mjs']);
|
|
28
|
+
// @comment -- "Whether the repository a hook event is about is set up with Bravos or GuardLink: the folder the harness names (CLAUDE_PROJECT_DIR) or the working folder, walked up to the top of its git checkout, holds GuardLink's .guardlink/config.json, or a repository's own Bravos marker (.bravos/skills.lock or .bravos/setup.json). The machine's own Bravos folder never counts: the home folder's .bravos/ and BRAVOS_HOME hold this machine's configuration and its user-level install, not a repository, so an agent opened in the home folder is not briefed. An empty .bravos/ is not a set-up repository either. File-system checks only: the event's stdin payload is left unread for the hook itself."
|
|
29
|
+
// @mitigates #hook-launcher against #home-folder-briefing using #repository-marker -- "A harness event counts as being in a Bravos repository only on a repository marker (.guardlink/config.json, .bravos/skills.lock, .bravos/setup.json), and never on the home folder's or BRAVOS_HOME's own .bravos/"
|
|
30
|
+
export function repoHasBravos(env = process.env, cwd = process.cwd()) {
|
|
31
|
+
const real = (p) => {
|
|
32
|
+
try {
|
|
33
|
+
return realpathSync(p);
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return resolve(p);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const start = real(env.CLAUDE_PROJECT_DIR || cwd);
|
|
40
|
+
let dir = start;
|
|
41
|
+
for (;;) {
|
|
42
|
+
if (existsSync(join(dir, '.git')))
|
|
43
|
+
break;
|
|
44
|
+
const up = dirname(dir);
|
|
45
|
+
if (up === dir) {
|
|
46
|
+
dir = start;
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
dir = up;
|
|
50
|
+
}
|
|
51
|
+
if (existsSync(join(dir, '.guardlink', 'config.json')))
|
|
52
|
+
return true;
|
|
53
|
+
const own = real(join(dir, '.bravos'));
|
|
54
|
+
const machine = [env.BRAVOS_HOME, env.HOME ? join(env.HOME, '.bravos') : null, join(homedir(), '.bravos')].filter((p) => !!p).map(real);
|
|
55
|
+
if (machine.includes(own))
|
|
56
|
+
return false;
|
|
57
|
+
return existsSync(join(dir, '.bravos', 'skills.lock')) || existsSync(join(dir, '.bravos', 'setup.json'));
|
|
58
|
+
}
|
|
59
|
+
/** The marker a hook reads to know it runs as the repository's registered hook, not as a plugin's or a user-level copy. Set in this process only, never in the environment, so a child process or a caller cannot fake it. */
|
|
60
|
+
export const LAUNCHER_MARK = Symbol.for('bravos.hook-launcher');
|
|
61
|
+
/** This package's hooks/ folder: beside dist/ in an install, beside src/ in a checkout. */
|
|
62
|
+
export function launcherHooksDir() {
|
|
63
|
+
return join(dirname(dirname(fileURLToPath(import.meta.url))), 'hooks');
|
|
64
|
+
}
|
|
65
|
+
// @comment -- "Runs the named hook with the given arguments. A known .mjs hook is imported in this process after process.argv is set to exactly what `node <script> <args>` would give it (the script's real path first), so its own entry guard, its argument parsing and its reading of stdin are unchanged, and it sets the exit code or exits itself as it does today. The nightly tools script runs under bash with stdin, stdout and stderr passed straight through and its exit code kept. An unknown name, no name, a script missing from this install, or a harness event in a folder not set up with Bravos or GuardLink exits 0 with no output, so a pointer never blocks an agent. A script that throws ends the process with code 1, as it does when run directly."
|
|
66
|
+
// @mitigates #hook-launcher against #hook-name-injection using #fixed-hook-table -- "Only names in the fixed table run, each mapped to a constant path inside this package; an unknown or crafted name runs nothing and prints nothing"
|
|
67
|
+
export async function launch(name, args) {
|
|
68
|
+
const rel = typeof name === 'string' && Object.prototype.hasOwnProperty.call(HOOKS, name) ? HOOKS[name] : null;
|
|
69
|
+
if (!rel) {
|
|
70
|
+
process.exitCode = 0;
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (AGENT_EVENTS.has(name) && !(name === 'session-start' && args.includes('--briefing')) && !repoHasBravos()) {
|
|
74
|
+
process.exitCode = 0;
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const file = join(launcherHooksDir(), rel);
|
|
78
|
+
if (!existsSync(file)) {
|
|
79
|
+
process.exitCode = 0;
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const real = realpathSync(file);
|
|
83
|
+
if (rel.endsWith('.sh')) {
|
|
84
|
+
const r = spawnSync('bash', [real, ...args], { stdio: 'inherit' });
|
|
85
|
+
process.exitCode = r.status ?? 1;
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
process.argv = [process.argv[0], real, ...args];
|
|
89
|
+
globalThis[LAUNCHER_MARK] = true;
|
|
90
|
+
// A script that throws while it runs ends this process with Node's own uncaught-error exit (code 1), as it would run directly.
|
|
91
|
+
await import(pathToFileURL(real).href);
|
|
92
|
+
}
|
package/dist/hooks.js
CHANGED
|
@@ -3,6 +3,7 @@ import { dirname, join, relative } from 'node:path';
|
|
|
3
3
|
import { hooksDir as packageHooksDir } from './paths.js';
|
|
4
4
|
import { OLD_HOOK_COMMANDS, OLD_NAME, oldGlobalHookCommand } from './migrate.js';
|
|
5
5
|
import { BravosError } from './types.js';
|
|
6
|
+
import { CLI_ONLY_HOOKS } from './hook-launcher.js';
|
|
6
7
|
// @comment -- "The SessionStart command before 0.5.0; init and sync replace it with the per-harness form, and doctor still accepts it."
|
|
7
8
|
export const LEGACY_HOOK_COMMAND = 'node .bravos/hooks/session-start.mjs';
|
|
8
9
|
// @comment -- "Where a hook command finds the repository's .bravos/hooks. Until 1.8 the commands were relative (node .bravos/hooks/x.mjs), and a harness runs a hook in the session's current folder: once the agent changed folder (cd ios/Runner), every hook failed with 'Cannot find module', autopilot stopped running and the pre-PR gate let gh pr create through unchecked. Claude Code gives the project root as ${CLAUDE_PROJECT_DIR}; Codex documents resolving from the git top level. Both are quoted, so a path with a space works. Antigravity runs its hook in the workspace and keeps the relative form."
|
|
@@ -79,6 +80,20 @@ const cards = (h) => ({
|
|
|
79
80
|
? { matcher: 'Edit|Write|MultiEdit|NotebookEdit', hooks: [{ type: 'command', command: CARDS_COMMANDS[h], timeout: 10 }] }
|
|
80
81
|
: { hooks: [{ type: 'command', command: CARDS_COMMANDS[h], timeout: 10 }] },
|
|
81
82
|
});
|
|
83
|
+
// @comment -- "The record guard: a PreToolUse hook on Claude Code's file-edit tools and Codex's apply_patch that refuses the first edit in a session to a file an adopted security decision record covers, once, with the record in full (hooks/record-guard.mjs). It runs only through the installed CLI (bravos hook record-guard), and the command checks first that the repository keeps records and that bravos is on PATH, so a repository without records, or a teammate without Bravos, pays nothing and is never blocked."
|
|
84
|
+
export const RECORD_GUARD_COMMANDS = {
|
|
85
|
+
claude: 'if [ -d "${CLAUDE_PROJECT_DIR}/.guardlink/records" ] && command -v bravos >/dev/null 2>&1; then bravos hook record-guard --harness claude; fi',
|
|
86
|
+
agents: 'r="$(git rev-parse --show-toplevel 2>/dev/null)"; if [ -n "$r" ] && [ -d "$r/.guardlink/records" ] && command -v bravos >/dev/null 2>&1; then bravos hook record-guard --harness codex; fi',
|
|
87
|
+
};
|
|
88
|
+
// Claude Code's file-edit tools; Codex edits through apply_patch (its patch text names the files).
|
|
89
|
+
const RECORD_GUARD_MATCHER = { claude: 'Edit|Write|MultiEdit|NotebookEdit', agents: 'apply_patch|Edit|Write' };
|
|
90
|
+
export const ALL_RECORD_GUARD_COMMANDS = Object.values(RECORD_GUARD_COMMANDS).filter((c) => !!c);
|
|
91
|
+
const recordGuard = (h) => {
|
|
92
|
+
const command = RECORD_GUARD_COMMANDS[h];
|
|
93
|
+
if (!command)
|
|
94
|
+
return [];
|
|
95
|
+
return [{ event: 'PreToolUse', command, group: { matcher: RECORD_GUARD_MATCHER[h], hooks: [{ type: 'command', command, timeout: 10 }] } }];
|
|
96
|
+
};
|
|
82
97
|
// The hook script itself only acts on commands that run gh pr create or gh pr ready.
|
|
83
98
|
const prePr = (h) => ({
|
|
84
99
|
event: 'PreToolUse',
|
|
@@ -190,9 +205,44 @@ export function installedOptIns(root) {
|
|
|
190
205
|
prePr: files.some((f) => hookRegistered(f, 'PreToolUse', ALL_PRE_PR_COMMANDS)),
|
|
191
206
|
};
|
|
192
207
|
}
|
|
193
|
-
|
|
208
|
+
// @comment -- "The edit hooks for agents whose hooks file Bravos writes as shell commands (Cursor, Antigravity): the record guard and the cards run only through the installed CLI (bravos hook <name>), never a repository copy, so the hooks migration has nothing to move. The guard runs only where the repository keeps records and bravos is on PATH; otherwise, like any failure, it answers {} and the edit goes ahead (Cursor blocks an edit on output that is not JSON)."
|
|
209
|
+
export const editGuardCommand = (harness) => `r="$(git rev-parse --show-toplevel 2>/dev/null)"; if [ -n "$r" ] && [ -d "$r/.guardlink/records" ] && command -v bravos >/dev/null 2>&1; then bravos hook record-guard --harness ${harness}; else echo '{}'; fi`;
|
|
210
|
+
export const editCardsCommand = (harness, args = '') => `if command -v bravos >/dev/null 2>&1; then bravos hook cards --harness ${harness}${args ? ` ${args}` : ''}; else echo '{}'; fi`;
|
|
211
|
+
// @comment -- "Antigravity runs a hook with its working directory set to the folder holding hooks.json (.agents/), so the session-start path is found from the git top level; the relative form 1.24 and earlier wrote never resolved there."
|
|
212
|
+
export const AGY_HOOK_COMMAND = `node "$(git rev-parse --show-toplevel)/.bravos/hooks/session-start.mjs" --harness agy`;
|
|
213
|
+
/** The relative form 1.24 and earlier registered; doctor still recognises it, setup replaces it. */
|
|
214
|
+
export const AGY_LEGACY_HOOK_COMMAND = `${LEGACY_HOOK_COMMAND} --harness agy`;
|
|
194
215
|
export const AGY_HOOKS_FILE = '.agents/hooks.json';
|
|
195
|
-
|
|
216
|
+
// @comment -- "Antigravity's edit tools: the agy CLI's write_file and edit_file (args Path), and the names its web docs list for the app and IDE (write_to_file, replace_file_content, multi_replace_file_content; args TargetFile). Anchored, since how its RE2 matcher anchors is not documented."
|
|
217
|
+
export const AGY_EDIT_MATCHER = '^(write_file|edit_file|write_to_file|replace_file_content|multi_replace_file_content)$';
|
|
218
|
+
// @comment -- "Bravos's named hook in .agents/hooks.json: the briefing at SessionStart; the record guard before an edit (PreToolUse, decision deny); after an edit the cards and the no-record nudge, which PostToolUse cannot hand the model, so they wait for the next model call (PreInvocation, injectSteps)."
|
|
219
|
+
export const AGY_GROUP = {
|
|
220
|
+
SessionStart: [{ type: 'command', command: AGY_HOOK_COMMAND, timeout: 30 }],
|
|
221
|
+
PreToolUse: [{ matcher: AGY_EDIT_MATCHER, hooks: [{ type: 'command', command: editGuardCommand('agy'), timeout: 10 }] }],
|
|
222
|
+
PostToolUse: [{ matcher: AGY_EDIT_MATCHER, hooks: [{ type: 'command', command: editCardsCommand('agy'), timeout: 10 }] }],
|
|
223
|
+
PreInvocation: [{ type: 'command', command: editCardsCommand('agy', '--deliver'), timeout: 5 }],
|
|
224
|
+
};
|
|
225
|
+
/** What .agents/hooks.json registers for Bravos: the session start, and the before- and after-edit hooks. */
|
|
226
|
+
export function agyRegistered(root) {
|
|
227
|
+
try {
|
|
228
|
+
const b = JSON.parse(readFileSync(join(root, AGY_HOOKS_FILE), 'utf8')).bravos;
|
|
229
|
+
// Every command in the group, whether listed flat (SessionStart, PreInvocation) or under a matcher (the tool events).
|
|
230
|
+
const commands = [];
|
|
231
|
+
for (const list of Object.values(b ?? {})) {
|
|
232
|
+
for (const e of Array.isArray(list) ? list : []) {
|
|
233
|
+
const entries = isObject(e) && Array.isArray(e.hooks) ? e.hooks : [e];
|
|
234
|
+
for (const h of entries)
|
|
235
|
+
if (isObject(h) && typeof h.command === 'string')
|
|
236
|
+
commands.push(h.command);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
const any = (re) => commands.some((c) => re.test(c));
|
|
240
|
+
return { session: any(/session-start\.mjs"? --harness agy/), guard: any(/\bbravos hook record-guard --harness agy\b/), cards: any(/\bbravos hook cards --harness agy --deliver\b/) && any(/\bbravos hook cards --harness agy;/) };
|
|
241
|
+
}
|
|
242
|
+
catch {
|
|
243
|
+
return { session: false, guard: false, cards: false };
|
|
244
|
+
}
|
|
245
|
+
}
|
|
196
246
|
// @comment -- "Plans bravos's entry in Antigravity's workspace hooks file, whose top-level keys are named hook groups; only the 'bravos' key is bravos's, every other key is kept, and a malformed file is refused before anything is written."
|
|
197
247
|
function planAgy(root) {
|
|
198
248
|
const abs = join(root, AGY_HOOKS_FILE);
|
|
@@ -218,7 +268,8 @@ function planAgy(root) {
|
|
|
218
268
|
// @comment -- "Copies the hook scripts into <root>/.bravos/hooks and registers the SessionStart briefing, the UserPromptSubmit coach and the PostToolUse threat cards, plus the PreToolUse pre-PR gate when prePr is set, for Claude Code (.claude/settings.json), Codex (.codex/hooks.json) and Antigravity (.agents/hooks.json); settings files are validated before anything is written and existing keys and groups are preserved."
|
|
219
269
|
export function installHook(root, harnesses, opts = {}) {
|
|
220
270
|
const src = opts.hooksDir ?? packageHooksDir();
|
|
221
|
-
|
|
271
|
+
// A hook that runs only through the installed CLI (record-guard) is never copied into the repository.
|
|
272
|
+
const files = listFiles(src).map((abs) => relative(src, abs).split('\\').join('/')).filter((f) => !CLI_ONLY_HOOKS.includes(f)).sort();
|
|
222
273
|
const copied = files.map((f) => `.bravos/hooks/${f}`);
|
|
223
274
|
const withPrePr = (opts.prePr || opts.autopilot) && !opts.globalHome;
|
|
224
275
|
const withAutopilot = opts.autopilot && !opts.globalHome;
|
|
@@ -227,6 +278,8 @@ export function installHook(root, harnesses, opts = {}) {
|
|
|
227
278
|
...(opts.globalHome ? [] : [coach(h), cards(h)]),
|
|
228
279
|
...(withPrePr ? [prePr(h)] : []),
|
|
229
280
|
...(withAutopilot ? [autopilot(h)] : []),
|
|
281
|
+
// After the opt-in gate, so an existing PreToolUse list keeps the gate first.
|
|
282
|
+
...(opts.globalHome ? [] : recordGuard(h)),
|
|
230
283
|
], [
|
|
231
284
|
...(withPrePr ? [] : [{ event: 'PreToolUse', commands: [OLD_HOOK_COMMANDS.prePr] }]),
|
|
232
285
|
...(withAutopilot ? [] : [{ event: 'Stop', commands: [OLD_HOOK_COMMANDS.autopilot] }]),
|
package/dist/plugin-release.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { dirname, join, relative } from 'node:path';
|
|
3
|
+
import { AGY_EDIT_MATCHER } from './hooks.js';
|
|
3
4
|
import { SERVERS } from './mcp.js';
|
|
4
5
|
import { hooksDir, packageRoot, version } from './paths.js';
|
|
5
6
|
import { listBundledSkills, renderPluginSkillFile, renderPortableSkillFile, viaCliHooks } from './skills.js';
|
|
@@ -16,8 +17,8 @@ const KEYWORDS = ['security', 'threat-modeling', 'guardlink', 'pentest', 'cxg',
|
|
|
16
17
|
const SESSION_MATCHER = 'startup|resume|clear|compact';
|
|
17
18
|
const json = (v) => Buffer.from(JSON.stringify(v, null, 2) + '\n');
|
|
18
19
|
const text = (s) => Buffer.from(s.endsWith('\n') ? s : s + '\n');
|
|
19
|
-
// @comment -- "The hook files a plugin ships: the session-start
|
|
20
|
-
export function hookClosure(hooks,
|
|
20
|
+
// @comment -- "The hook files a plugin ships: the session-start and cards scripts and every file they import, followed through relative imports. The record guard, the pre-PR gate and autopilot run through the installed CLI (bravos hook), so their scripts are not shipped where a reviewer would have to read them."
|
|
21
|
+
export function hookClosure(hooks, entries = ['session-start.mjs', 'cards.mjs']) {
|
|
21
22
|
const seen = new Set();
|
|
22
23
|
const visit = (abs) => {
|
|
23
24
|
if (seen.has(abs))
|
|
@@ -27,11 +28,18 @@ export function hookClosure(hooks, entry = 'session-start.mjs') {
|
|
|
27
28
|
for (const m of src.matchAll(/(?:from\s+|import\s*\(\s*)['"](\.{1,2}\/[^'"]+)['"]/g))
|
|
28
29
|
visit(join(dirname(abs), m[1]));
|
|
29
30
|
};
|
|
30
|
-
|
|
31
|
+
for (const entry of Array.isArray(entries) ? entries : [entries])
|
|
32
|
+
visit(join(hooks, entry));
|
|
31
33
|
return [...seen].sort();
|
|
32
34
|
}
|
|
35
|
+
// @comment -- "The edit hooks a plugin registers, the same protection bravos setup writes into a repository: the record guard before an edit, through the installed CLI only and with --plugin, so it stays quiet where the repository registers its own; and the cards (threat cards, record cards, the no-record nudge) after one, from the plugin's own copy, which defers to a repository's. The guard runs only where the repository keeps records and bravos is on PATH; any failure lets the edit through."
|
|
36
|
+
const CLAUDE_EDIT_MATCHER = 'Edit|Write|MultiEdit|NotebookEdit';
|
|
37
|
+
const CODEX_EDIT_MATCHER = 'apply_patch|Edit|Write';
|
|
38
|
+
export const pluginGuardCommand = (harness) => harness === 'claude'
|
|
39
|
+
? 'if [ -d "${CLAUDE_PROJECT_DIR}/.guardlink/records" ] && command -v bravos >/dev/null 2>&1; then bravos hook record-guard --harness claude --plugin; fi'
|
|
40
|
+
: 'r="$(git rev-parse --show-toplevel 2>/dev/null)"; if [ -n "$r" ] && [ -d "$r/.guardlink/records" ] && command -v bravos >/dev/null 2>&1; then bravos hook record-guard --harness codex --plugin; fi';
|
|
33
41
|
const guardlinkServer = () => ({ type: 'stdio', command: SERVERS.guardlink.command, args: [...SERVERS.guardlink.args] });
|
|
34
|
-
// @comment -- "Every file of the public plugin repository, computed and not written. Skills: Claude Code's copy uses ${CLAUDE_SKILL_DIR} and ${CLAUDE_PLUGIN_ROOT}, which it substitutes; every other copy uses the portable SKILL_DIR wording. In every copy a skill's `node .bravos/hooks/<hook>.mjs` is `bravos hook <hook>`, because a plugin install has no .bravos/hooks/. Session hooks are registered where the harness's plugin format and SessionStart output are known: Claude Code, Codex, Gemini CLI and Antigravity. Copilot, VS Code and Cursor get the skills and MCP, and the bravos skill loads the briefing itself."
|
|
42
|
+
// @comment -- "Every file of the public plugin repository, computed and not written. Skills: Claude Code's copy uses ${CLAUDE_SKILL_DIR} and ${CLAUDE_PLUGIN_ROOT}, which it substitutes; every other copy uses the portable SKILL_DIR wording. In every copy a skill's `node .bravos/hooks/<hook>.mjs` is `bravos hook <hook>`, because a plugin install has no .bravos/hooks/. Session hooks are registered where the harness's plugin format and SessionStart output are known: Claude Code, Codex, Gemini CLI and Antigravity; the edit hooks (record guard, cards) for Claude Code, Codex and Antigravity, whose edit-hook contracts were checked. Gemini CLI, Copilot, VS Code and Cursor plugins get no edit hooks yet; Copilot, VS Code and Cursor get the skills and MCP, and the bravos skill loads the briefing itself."
|
|
35
43
|
export function releaseFiles(opts = {}) {
|
|
36
44
|
const v = version();
|
|
37
45
|
const files = [];
|
|
@@ -60,7 +68,11 @@ export function releaseFiles(opts = {}) {
|
|
|
60
68
|
// Claude Code: claude/, listed by .claude-plugin/marketplace.json.
|
|
61
69
|
addSkills('claude/', (c, rel) => viaCliHooks(renderPluginSkillFile(c, rel)));
|
|
62
70
|
addHookScripts('claude/');
|
|
63
|
-
add('claude/hooks/hooks.json', json({ hooks: {
|
|
71
|
+
add('claude/hooks/hooks.json', json({ hooks: {
|
|
72
|
+
SessionStart: [sessionArgs('${CLAUDE_PLUGIN_ROOT}/hooks/session-start.mjs', 'claude')],
|
|
73
|
+
PreToolUse: [{ matcher: CLAUDE_EDIT_MATCHER, hooks: [{ type: 'command', command: pluginGuardCommand('claude'), timeout: 10 }] }],
|
|
74
|
+
PostToolUse: [{ matcher: CLAUDE_EDIT_MATCHER, hooks: [{ type: 'command', command: 'node', args: ['${CLAUDE_PLUGIN_ROOT}/hooks/cards.mjs', '--harness', 'claude'], timeout: 10 }] }],
|
|
75
|
+
} }));
|
|
64
76
|
add('claude/.claude-plugin/icon.png', icon);
|
|
65
77
|
add('claude/.mcp.json', json({ mcpServers: { guardlink: SERVERS.guardlink } }));
|
|
66
78
|
// Claude's directory shows these links on the listing; the pages are the company site's own.
|
|
@@ -73,7 +85,7 @@ export function releaseFiles(opts = {}) {
|
|
|
73
85
|
termsOfServiceUrl: 'https://www.bugb.io/terms',
|
|
74
86
|
}));
|
|
75
87
|
add('claude/LICENSE', licence);
|
|
76
|
-
add('claude/README.md', text(readme(v)));
|
|
88
|
+
add('claude/README.md', text(readme(v, skills.length)));
|
|
77
89
|
add('.claude-plugin/marketplace.json', json({
|
|
78
90
|
name: NAME,
|
|
79
91
|
owner: AUTHOR,
|
|
@@ -83,7 +95,12 @@ export function releaseFiles(opts = {}) {
|
|
|
83
95
|
// Codex: codex/, listed by .agents/plugins/marketplace.json. Hooks at the plugin root, as Codex's own plugins keep them.
|
|
84
96
|
addSkills('codex/', renderPortableSkillFile);
|
|
85
97
|
addHookScripts('codex/');
|
|
86
|
-
|
|
98
|
+
// Codex names its edit tool differently across versions, so cards run after every tool and read the files from the payload or the working tree.
|
|
99
|
+
add('codex/hooks.json', json({ hooks: {
|
|
100
|
+
SessionStart: [sessionGroup('node "${PLUGIN_ROOT}/hooks/session-start.mjs" --harness codex')],
|
|
101
|
+
PreToolUse: [{ matcher: CODEX_EDIT_MATCHER, hooks: [{ type: 'command', command: pluginGuardCommand('codex'), timeout: 10 }] }],
|
|
102
|
+
PostToolUse: [{ hooks: [{ type: 'command', command: 'node "${PLUGIN_ROOT}/hooks/cards.mjs" --harness codex', timeout: 10 }] }],
|
|
103
|
+
} }));
|
|
87
104
|
add('codex/.mcp.json', json({ mcpServers: { guardlink: guardlinkServer() } }));
|
|
88
105
|
add('codex/.codex-plugin/plugin.json', json({
|
|
89
106
|
...base,
|
|
@@ -150,13 +167,20 @@ export function releaseFiles(opts = {}) {
|
|
|
150
167
|
logo: 'assets/icon.png',
|
|
151
168
|
suggestedPrompts: ['Where do I start on security here?', 'Threat-model this repository', 'Is this PR safe to open?'],
|
|
152
169
|
}));
|
|
153
|
-
|
|
170
|
+
// The guard goes through a small workspace shim: a plugin's hooks run in the plugin's folder, and bravos hook finds the repository from where it runs. PostToolUse cannot reach the model, so the cards' note waits for PreInvocation.
|
|
171
|
+
add('hooks/workspace-hook.mjs', readFileSync(join(packageRoot(), 'templates', 'plugin', 'workspace-hook.mjs')));
|
|
172
|
+
add('hooks.json', json({ bravos: {
|
|
173
|
+
SessionStart: [{ type: 'command', command: 'node hooks/session-start.mjs --harness agy', timeout: 30 }],
|
|
174
|
+
PreToolUse: [{ matcher: AGY_EDIT_MATCHER, hooks: [{ type: 'command', command: 'node hooks/workspace-hook.mjs record-guard --harness agy --plugin', timeout: 10 }] }],
|
|
175
|
+
PostToolUse: [{ matcher: AGY_EDIT_MATCHER, hooks: [{ type: 'command', command: 'node hooks/cards.mjs --harness agy', timeout: 10 }] }],
|
|
176
|
+
PreInvocation: [{ type: 'command', command: 'node hooks/cards.mjs --harness agy --deliver', timeout: 5 }],
|
|
177
|
+
} }));
|
|
154
178
|
// Antigravity loads a plugin's context only from rules/; GEMINI.md is Gemini CLI's.
|
|
155
179
|
add('rules/bravos.md', text(GEMINI_CONTEXT));
|
|
156
180
|
add('mcp_config.json', json({ mcpServers: { guardlink: { command: SERVERS.guardlink.command, args: [...SERVERS.guardlink.args] } } }));
|
|
157
181
|
add('assets/icon.png', icon);
|
|
158
182
|
add('LICENSE', licence);
|
|
159
|
-
add('README.md', text(readme(v)));
|
|
183
|
+
add('README.md', text(readme(v, skills.length)));
|
|
160
184
|
return files.sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0));
|
|
161
185
|
}
|
|
162
186
|
const GEMINI_CONTEXT = `# Bravos
|
|
@@ -170,12 +194,14 @@ The skills drive the \`bravos\` CLI (\`npm install -g @bugb-technologies/bravos\
|
|
|
170
194
|
\`guardlink\` and \`cxg\`. Never send a request to a host other than loopback
|
|
171
195
|
without a committed, reviewed \`.guardlink/scope.yaml\` and the user's own typed
|
|
172
196
|
authorization naming the target.`;
|
|
173
|
-
function readme(v) {
|
|
197
|
+
function readme(v, n) {
|
|
174
198
|
return `# Bravos plugins
|
|
175
199
|
|
|
176
|
-
Bravos ${v} for the coding agent you already use. Each plugin carries the same
|
|
200
|
+
Bravos ${v} for the coding agent you already use. Each plugin carries the same ${n}
|
|
177
201
|
skills and the guardlink MCP server; the session-start briefing loads by itself
|
|
178
|
-
where the agent supports it.
|
|
202
|
+
where the agent supports it. In Claude Code, Codex and Antigravity the plugin also
|
|
203
|
+
reads a security decision record before the first edit to the code it covers, and
|
|
204
|
+
shows threat and record cards after an edit.
|
|
179
205
|
|
|
180
206
|
**First, install the CLI** (Node 20 or newer). The skills drive it:
|
|
181
207
|
|