@bugb-technologies/bravos 1.19.0 → 1.22.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/account.js +19 -2
- package/dist/cli.js +124 -14
- package/dist/context.js +126 -3
- package/dist/dashboard.js +9 -0
- package/dist/device.js +3 -1
- package/dist/doctor.js +4 -0
- package/dist/guide.js +5 -3
- package/dist/help.js +15 -8
- package/dist/instruction-blocks.js +2 -1
- package/dist/principles.js +279 -0
- package/dist/review-server.js +19 -4
- package/dist/review-wait.js +11 -0
- package/dist/review.js +342 -41
- package/dist/rules.js +82 -6
- package/docs/GUIDE.md +12 -2
- package/docs/UPGRADING.md +39 -0
- package/hooks/cards.mjs +20 -5
- package/hooks/lib/briefing.mjs +26 -2
- package/hooks/lib/context.mjs +57 -1
- package/hooks/lib/licence.mjs +2 -1
- package/hooks/lib/machine.mjs +77 -0
- package/hooks/lib/pre-pr.mjs +82 -1
- package/hooks/lib/principles.mjs +513 -0
- package/hooks/lib/refresh.mjs +11 -1
- package/hooks/lib/replay.mjs +218 -100
- package/package.json +1 -1
- package/skills/bravos/SKILL.md +1 -0
- package/skills/bravos-context/SKILL.md +4 -4
- package/skills/bravos-principles/SKILL.md +52 -0
- package/templates/dashboard/dashboard.html +75 -1
- package/templates/review/review.html +140 -11
- package/templates/workflows/bravos-nightly-claude.yml +1 -1
- package/templates/workflows/bravos-nightly-codex.yml +1 -1
- package/templates/workflows/bravos-pr-gate.yml +1 -1
package/dist/rules.js
CHANGED
|
@@ -16,7 +16,7 @@ export const STATUS_LABEL = {
|
|
|
16
16
|
const arr = (v) => (Array.isArray(v) ? v : []);
|
|
17
17
|
const bare = (id) => String(id ?? '').replace(/^#/, '');
|
|
18
18
|
const num = (v) => (typeof v === 'number' && Number.isFinite(v) ? v : null);
|
|
19
|
-
// @comment -- "Reads the rules out of intent.md: every bullet that starts INV-n. What follows the last ' — ' is how it was decided (draft, or who agreed), a '(source: SRC-2 \"Report access\")' names the documents it came from, and the rest is the rule's text. Table rows and prose that mention a rule are not rules."
|
|
19
|
+
// @comment -- "Reads the rules out of intent.md: every bullet that starts INV-n. What follows the last ' — ' is how it was decided (draft, or who agreed), a '(source: SRC-2 \"Report access\")' names the documents it came from, a '(principle: SDP-1)' the company principle it carries out, and the rest is the rule's text. Table rows and prose that mention a rule are not rules."
|
|
20
20
|
export function parseIntentRules(text) {
|
|
21
21
|
const out = [];
|
|
22
22
|
const seen = new Set();
|
|
@@ -33,7 +33,13 @@ export function parseIntentRules(text) {
|
|
|
33
33
|
rest = rest.slice(0, dash).trim();
|
|
34
34
|
}
|
|
35
35
|
const sources = [];
|
|
36
|
+
const principles = [];
|
|
36
37
|
rest = rest
|
|
38
|
+
.replace(/\(principles?:\s*([^)]*)\)/gi, (_all, inner) => {
|
|
39
|
+
for (const s of inner.matchAll(/\b(SDP-[1-9][0-9]{0,3})\b/g))
|
|
40
|
+
principles.push(s[1]);
|
|
41
|
+
return '';
|
|
42
|
+
})
|
|
37
43
|
.replace(/\(source:\s*([^)]*)\)/gi, (_all, inner) => {
|
|
38
44
|
for (const s of inner.matchAll(/\b(SRC-[1-9][0-9]{0,4})\b(?:\s*"([^"]{0,120})")?/g))
|
|
39
45
|
sources.push({ id: s[1], section: s[2]?.trim() || null });
|
|
@@ -43,7 +49,7 @@ export function parseIntentRules(text) {
|
|
|
43
49
|
.trim();
|
|
44
50
|
const draft = /^draft\b/i.test(attribution) || attribution === '';
|
|
45
51
|
const by = /\b(?:accepted|edited|chosen|set|confirmed) by\s+(.+)$/i.exec(attribution)?.[1]?.trim() ?? null;
|
|
46
|
-
out.push({ id: m[1], text: rest.slice(0, 600), decided: draft ? 'draft' : 'confirmed', decidedBy: draft ? null : by, sources });
|
|
52
|
+
out.push({ id: m[1], text: rest.slice(0, 600), decided: draft ? 'draft' : 'confirmed', decidedBy: draft ? null : by, sources, principles });
|
|
47
53
|
}
|
|
48
54
|
return out;
|
|
49
55
|
}
|
|
@@ -272,18 +278,81 @@ export async function gatherRules(root, env, opts = {}) {
|
|
|
272
278
|
rules.push({ id: null, text: t.description || t.name || `#${t.id}`, decided: null, decidedBy: null, sources: t.refs.filter((r) => /^design:SRC-/i.test(r)).map((r) => source({ id: r.slice(7), section: null })), threat: `#${t.id}`, severity: t.severity, refs: t.refs, status: verdict.status, why: `${verdict.why} No item in intent.md stands behind this threat: confirm it there, or remove it.`, sites });
|
|
273
279
|
}
|
|
274
280
|
rules.sort((a, b) => STATUS_ORDER.indexOf(a.status) - STATUS_ORDER.indexOf(b.status) || String(a.id ?? '~').localeCompare(String(b.id ?? '~'), undefined, { numeric: true }));
|
|
281
|
+
// THE COMPANY'S PRINCIPLES: each adopted one joined to the threats that stand for it (principle:SDP-n, or an INV
|
|
282
|
+
// rule that names it), with the places under a live exception set aside, and what it has done lately.
|
|
283
|
+
const P = await (await import('./principles.js')).principlesLib();
|
|
284
|
+
const checked = P.checkPrinciples(P.treeReader(root));
|
|
285
|
+
const now = Date.now();
|
|
286
|
+
const within = (at, days) => {
|
|
287
|
+
const t = Date.parse(String(at ?? ''));
|
|
288
|
+
return Number.isFinite(t) && now - t <= days * 86400000;
|
|
289
|
+
};
|
|
290
|
+
const stops = gateStops(root, env);
|
|
291
|
+
const principles = [];
|
|
292
|
+
for (const p of checked.adopted) {
|
|
293
|
+
const fromRules = intentRules.filter((r) => r.principles.includes(p.id));
|
|
294
|
+
const ids = [...new Set([...threats.filter((t) => t.refs.some((r) => r.toLowerCase() === `principle:${p.id.toLowerCase()}`)).map((t) => t.id), ...fromRules.map((r) => threatFor(r.id)?.id).filter((x) => !!x)])].sort();
|
|
295
|
+
const exceptions = checked.exceptions.filter((e) => e.principle === p.id);
|
|
296
|
+
const sites = ids.flatMap((id) => sitesFor(id)).map((site) => {
|
|
297
|
+
const e = P.exceptionFor(exceptions, p.id, site.file);
|
|
298
|
+
return e ? { ...site, exception: { where: e.where, by: names ? e.by : '', until: e.until } } : site;
|
|
299
|
+
});
|
|
300
|
+
const active = sites.filter((x) => !('exception' in x && x.exception));
|
|
301
|
+
const verdict = p.kind === 'guidance'
|
|
302
|
+
? { status: 'guidance', why: 'Guidance: coding agents follow it here; nothing is tested.' }
|
|
303
|
+
: !model
|
|
304
|
+
? { status: 'not-placed', why: 'GuardLink is not installed here, so where this principle is enforced is not known.' }
|
|
305
|
+
: !ids.length
|
|
306
|
+
? { status: 'not-placed', why: `No threat in the model stands for it yet: the next annotation pass adds one with the reference principle:${p.id} (or an INV rule names it).` }
|
|
307
|
+
: afterChanges(ruleStatus(active), active);
|
|
308
|
+
const mine = records.filter((r) => ids.includes(bare(r.threat)) && r.outcome?.at);
|
|
309
|
+
const count = (f) => [mine.filter((r) => f(r) && within(r.outcome.at, 30)).length, mine.filter((r) => f(r) && within(r.outcome.at, 90)).length];
|
|
310
|
+
const stopped = stops.filter((x) => x.principle === p.id);
|
|
311
|
+
principles.push({
|
|
312
|
+
id: p.id, kind: p.kind, statement: p.statement, scope: p.scope, adoptedBy: names ? p.adopters : null, threats: ids.map((id) => `#${id}`), rules: fromRules.map((r) => r.id),
|
|
313
|
+
status: verdict.status, why: `${verdict.why}${sites.length > active.length ? ` ${sites.length - active.length} place${sites.length - active.length === 1 ? ' is' : 's are'} under an approved exception.` : ''}`,
|
|
314
|
+
sites,
|
|
315
|
+
exceptions: exceptions.map((e) => ({ where: e.where, reason: e.reason, by: names ? e.by : '', approved: e.approved, until: e.until, live: P.live(e) })),
|
|
316
|
+
value: { tested: count(() => true), held: count((r) => r.outcome?.outcome === 'refuted'), caught: count((r) => r.outcome?.outcome === 'confirmed'), gateStops: [stopped.filter((x) => within(x.at, 30)).length, stopped.filter((x) => within(x.at, 90)).length], files: new Set(sites.map((x) => x.file)).size },
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
const order = (s) => (s === 'guidance' ? STATUS_ORDER.length : STATUS_ORDER.indexOf(s));
|
|
320
|
+
principles.sort((a, b) => order(a.status) - order(b.status) || Number(a.id.slice(4)) - Number(b.id.slice(4)));
|
|
321
|
+
const enforcedCount = principles.filter((p) => p.kind === 'enforced').length;
|
|
322
|
+
const principlesNote = !principles.length
|
|
323
|
+
? checked.ok ? '' : `principles.md does not match what people adopted (${checked.problems.length} problem${checked.problems.length === 1 ? '' : 's'}): bravos principles check.`
|
|
324
|
+
: `${principles.length} security design principle${principles.length === 1 ? '' : 's'} adopted (${enforcedCount} enforced)${principles.filter((p) => p.status === 'broken').length ? `, ${principles.filter((p) => p.status === 'broken').length} broken` : ''}${checked.ok ? '' : `; principles.md does not match the adoptions: bravos principles check`}.`;
|
|
275
325
|
const summary = { total: rules.length, draft: rules.filter((r) => r.decided === 'draft').length, broken: 0, 'retest-due': 0, holds: 0, unguarded: 0, 'guarded-untested': 0, 'not-placed': 0 };
|
|
276
326
|
for (const r of rules)
|
|
277
327
|
summary[r.status] += 1;
|
|
278
328
|
if (!rules.length) {
|
|
279
|
-
return { schema: 'bravos.rules/v1', state: 'none', note: 'No design rules are recorded yet. Run /bravos-context: it asks for your design documents and writes the rules they state (who may do what, what must never happen) into .guardlink/intent.md.', summary, rules };
|
|
329
|
+
return { schema: 'bravos.rules/v1', state: 'none', note: 'No design rules are recorded yet. Run /bravos-context: it asks for your design documents and writes the rules they state (who may do what, what must never happen) into .guardlink/intent.md.', summary, rules, principles, principlesNote };
|
|
280
330
|
}
|
|
281
331
|
if (!model)
|
|
282
|
-
return { schema: 'bravos.rules/v1', state: 'no-guardlink', note: 'GuardLink is not installed on this machine, so the rules are listed without where the code enforces them: run bravos setup --tools -y, then bravos dashboard again.', summary, rules };
|
|
332
|
+
return { schema: 'bravos.rules/v1', state: 'no-guardlink', note: 'GuardLink is not installed on this machine, so the rules are listed without where the code enforces them: run bravos setup --tools -y, then bravos dashboard again.', summary, rules, principles, principlesNote };
|
|
283
333
|
const said = STATUS_ORDER.filter((s) => summary[s]).map((s) => `${summary[s]} ${STATUS_LABEL[s]}`);
|
|
284
|
-
return { schema: 'bravos.rules/v1', state: 'present', note: `${rules.length} design rule${rules.length === 1 ? '' : 's'} from the intent: ${said.join(', ')}${summary.draft ? `; ${summary.draft} still a draft nobody has confirmed` : ''}.`, summary, rules };
|
|
334
|
+
return { schema: 'bravos.rules/v1', state: 'present', note: `${rules.length} design rule${rules.length === 1 ? '' : 's'} from the intent: ${said.join(', ')}${summary.draft ? `; ${summary.draft} still a draft nobody has confirmed` : ''}.`, summary, rules, principles, principlesNote };
|
|
335
|
+
}
|
|
336
|
+
// @comment -- "The pre-PR gate's record of the times it stopped a change for breaking a principle, kept on this machine under the git directory (<git-common-dir>/bravos/principles-gate.jsonl, never committed): what the dashboard counts as the changes a principle stopped. Read-only, bounded; a missing or damaged file counts nothing."
|
|
337
|
+
export function gateStops(root, env) {
|
|
338
|
+
try {
|
|
339
|
+
const common = execFileSync('git', ['rev-parse', '--path-format=absolute', '--git-common-dir'], { cwd: root, env, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'], timeout: 5000 }).trim();
|
|
340
|
+
const text = readFileSync(join(common, 'bravos', 'principles-gate.jsonl'), 'utf8').slice(-256 * 1024);
|
|
341
|
+
return text.split('\n').flatMap((l) => {
|
|
342
|
+
try {
|
|
343
|
+
const j = JSON.parse(l);
|
|
344
|
+
return typeof j.at === 'string' && typeof j.principle === 'string' && /^SDP-\d+$/.test(j.principle) ? [{ at: j.at, principle: j.principle }] : [];
|
|
345
|
+
}
|
|
346
|
+
catch {
|
|
347
|
+
return [];
|
|
348
|
+
}
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
catch {
|
|
352
|
+
return [];
|
|
353
|
+
}
|
|
285
354
|
}
|
|
286
|
-
// @comment -- "bravos rules as lines: the note, then one line per rule with its status, id, text, sources and the places it is enforced."
|
|
355
|
+
// @comment -- "bravos rules as lines: the note, then one line per rule with its status, id, text, sources and the places it is enforced; then the adopted security design principles the same way."
|
|
287
356
|
export function formatRules(doc) {
|
|
288
357
|
const lines = [doc.note];
|
|
289
358
|
for (const r of doc.rules) {
|
|
@@ -292,5 +361,12 @@ export function formatRules(doc) {
|
|
|
292
361
|
for (const s of r.sites)
|
|
293
362
|
lines.push(`${' '.repeat(19)}${s.kind === 'grant' ? 'granted in' : s.kind === 'gap' ? 'no control at' : 'enforced at'} ${s.file}${s.line ? `:${s.line}` : ''}${s.state ? ` — ${SITE_WORD[s.state]}` : ''}`);
|
|
294
363
|
}
|
|
364
|
+
if (doc.principlesNote)
|
|
365
|
+
lines.push('', doc.principlesNote);
|
|
366
|
+
for (const p of doc.principles ?? []) {
|
|
367
|
+
lines.push(`${(p.status === 'guidance' ? 'guidance' : STATUS_LABEL[p.status]).padEnd(18)} ${p.id.padEnd(7)} ${p.statement}`);
|
|
368
|
+
for (const s of p.sites)
|
|
369
|
+
lines.push(`${' '.repeat(19)}${s.kind === 'grant' ? 'granted in' : s.kind === 'gap' ? 'no control at' : 'enforced at'} ${s.file}${s.line ? `:${s.line}` : ''}${s.exception ? ` — under an exception until ${s.exception.until}` : s.state ? ` — ${SITE_WORD[s.state]}` : ''}`);
|
|
370
|
+
}
|
|
295
371
|
return lines;
|
|
296
372
|
}
|
package/docs/GUIDE.md
CHANGED
|
@@ -24,7 +24,7 @@ Claude Code and opencode: /bravos-ship. Codex: $bravos-ship. omp: /skill:bravos-
|
|
|
24
24
|
|
|
25
25
|
### Plans
|
|
26
26
|
|
|
27
|
-
Free (researcher) needs no licence: context, annotate, templatize, env, prove, recheck, report and watch, in each repository on its own, with no limit on how many. Team, licensed per developer (Solo is one seat), adds the pre-PR gate and autopilot, the CI and nightly workflows, scheduled upkeep, multi-repository workspaces, campaigns, SAST and the code graph. The briefing opens every session with a Plan: line; bravos licence shows the same in a shell. bravos account activate signs you in once in the browser and writes the licence (a 30-day Team trial, no card, when the account has no plan); bravos account import <file> installs a downloaded one. On a team plan the licence is yours and this machine's: an owner or admin assigns you a licence, each machine you activate gets its own short-lived token that bravos renews automatically (at the session start and before a paid command), bravos account devices lists your machines, bravos account revoke <id> signs one out (a lost laptop), and bravos account logout signs this one out. Removing you from the team, or taking your licence back, stops every one of your machines at its next renewal. In CI, BRAVOS_LICENCE holds a CI licence an owner or admin creates for that repository, and the CLI never renews it. Without a licence a paid command explains what it would do and how to start the trial, a paid hook stands down with one line and never blocks, and a paid skill stops at its first step and says so.
|
|
27
|
+
Free (researcher) needs no licence: context, annotate, templatize, env, prove, recheck, report and watch, in each repository on its own, with no limit on how many. Team, licensed per developer (Solo is one seat), adds the pre-PR gate and autopilot, the CI and nightly workflows, scheduled upkeep, multi-repository workspaces, campaigns, SAST and the code graph. The briefing opens every session with a Plan: line; bravos licence shows the same in a shell. bravos account activate signs you in once in the browser and writes the licence (a 30-day Team trial, no card, when the account has no plan); bravos account import <file> installs a downloaded one. On a team plan the licence is yours and this machine's: an owner or admin assigns you a licence, each machine you activate gets its own short-lived token that bravos renews automatically (at the session start and before a paid command), bravos account devices lists your machines, bravos account revoke <id> signs one out (a lost laptop), and bravos account logout signs this one out. Removing you from the team, or taking your licence back, stops every one of your machines at its next renewal. At activation and at each renewal bravos sends the account portal a one-way fingerprint of the machine (a hash of the operating system machine id, never the id itself, and none in a container or CI), which the portal uses to allow one free trial per person and machine. In CI, BRAVOS_LICENCE holds a CI licence an owner or admin creates for that repository, and the CLI never renews it. Without a licence a paid command explains what it would do and how to start the trial, a paid hook stands down with one line and never blocks, and a paid skill stops at its first step and says so.
|
|
28
28
|
|
|
29
29
|
### Effort
|
|
30
30
|
|
|
@@ -110,6 +110,12 @@ Skills: `/bravos-context`
|
|
|
110
110
|
|
|
111
111
|
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.
|
|
112
112
|
|
|
113
|
+
### Write down your company's security design principles
|
|
114
|
+
|
|
115
|
+
Skills: `/bravos-principles`
|
|
116
|
+
|
|
117
|
+
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.
|
|
118
|
+
|
|
113
119
|
### See which design rules hold
|
|
114
120
|
|
|
115
121
|
Skills: `/bravos` · `/bravos-recheck`
|
|
@@ -120,7 +126,7 @@ bravos rules lists every rule your design states (INV-n in the intent) with its
|
|
|
120
126
|
|
|
121
127
|
Skills: `/bravos-context` · `/bravos-annotate`
|
|
122
128
|
|
|
123
|
-
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. 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.
|
|
129
|
+
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.
|
|
124
130
|
|
|
125
131
|
### Updates
|
|
126
132
|
|
|
@@ -304,6 +310,10 @@ Licensed static analysis joined to guardlink claims and reachability; gates on f
|
|
|
304
310
|
|
|
305
311
|
"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.
|
|
306
312
|
|
|
313
|
+
### bravos-principles
|
|
314
|
+
|
|
315
|
+
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.
|
|
316
|
+
|
|
307
317
|
### bravos-campaign
|
|
308
318
|
|
|
309
319
|
A goal over many rounds: disjoint batches, one subagent each, a gate per batch, rests, a final before-and-after.
|
package/docs/UPGRADING.md
CHANGED
|
@@ -2,6 +2,45 @@
|
|
|
2
2
|
|
|
3
3
|
After `npm install -g @bugb-technologies/bravos`, run **`bravos setup`** in a repository you work in: it brings this machine and that repository up to date. In repositories you work in with an agent you can skip even that: the agent runs it at the start of a session. From 1.12 on you do not have to watch for releases: Bravos tells you when a newer version is out, and after you install it the agent brings each repository up to date. The notes below say what else changes, newest first. (Before 1.9 the same was `bravos setup --tools -y` per machine and `bravos sync` per repository; both still work.)
|
|
4
4
|
|
|
5
|
+
## 1.22.0
|
|
6
|
+
|
|
7
|
+
- **The intake picks up where you left off.** `bravos review intent` brings back the answers you gave when you reopen it, saves them as you go (only Confirm makes them count), and reuses the page already open instead of opening a second one. After Confirm the page stays open and says who confirmed and when.
|
|
8
|
+
- **A rewritten draft no longer loses answers.** A draft that stops asking a question someone confirmed is refused unless the new question names the old id in `replaces`, or the id is listed under `retired`. An answer given before its question changed is flagged for the person to check.
|
|
9
|
+
- **Design documents on the page.** The intake page has a "Your design documents" panel: Markdown and text are stored at once with the same checks as `bravos context add`; a PDF, Word file, slides or link waits in `.bravos/context/inbox/` (not committed) for your agent to convert.
|
|
10
|
+
- **Citations are checked against the text.** `bravos context check` refuses a `SRC-n "<section>"` the document does not have, and the page shows the cited passage under each question.
|
|
11
|
+
- **The intake travels with the repository.** `bravos doctor` and `bravos setup` warn when a `.gitignore` rule keeps `.bravos/context/` or `.guardlink/intent*` on one machine; `bravos context share --yes` narrows a blanket `.bravos/` rule.
|
|
12
|
+
- **Security design principles (Team plan).** Your company's principles, kept in each repository:
|
|
13
|
+
- **Proposed only from your side.** The new `bravos-principles` skill proposes candidates from your stored documents, rules a person already confirmed, or an optional starter list mapped to OWASP ASVS 4.0.3. `bravos review principles` refuses anything else.
|
|
14
|
+
- **Adopted by people.** Each principle is its own decision on the page (Agree, Change, No); there is no adopt-all. Bravos writes `.guardlink/principles.md` from the confirmed adoptions. Commit it with `.guardlink/principles-answers/`.
|
|
15
|
+
- **Followed everywhere.** The Bravos block in `AGENTS.md`, `CLAUDE.md` and the other instruction files gains one paragraph telling every agent to read and follow the file and never edit it. This applies on every plan.
|
|
16
|
+
- **Enforced.** An enforced principle becomes a threat with `principle:SDP-n`; `bravos rules`, the dashboard's new Security design view and the pre-PR gate treat it like a design rule, and a change that breaks it is blocked whatever the PR body says, unless a person approved an exception (`bravos principles except`, at their own terminal, at most a year).
|
|
17
|
+
- **Checked.** `bravos principles check` (free) fails a hand-edited line, an adoption nobody made or an ended exception. `bravos principles copy --from <repository>` takes the same set into another repository.
|
|
18
|
+
- **The pre-push hook checks principles too.** `bravos setup` rewrites the hook Bravos installed (v2); one you wrote yourself is left alone.
|
|
19
|
+
- Run `bravos setup` in each repository: it refreshes the hook copy, the instruction-file block and the pre-push hook.
|
|
20
|
+
|
|
21
|
+
## 1.21.0
|
|
22
|
+
|
|
23
|
+
- **`bravos account activate` sends a one-way fingerprint of this machine.** The account portal allows one free trial per person and per machine, and this is how it tells machines apart.
|
|
24
|
+
- **What is sent:** a SHA-256 hash of a fixed label and the operating system's machine id (macOS `IOPlatformUUID`, Linux `/etc/machine-id`, Windows `MachineGuid`). The id itself never leaves the machine.
|
|
25
|
+
- **When:** at activation, and with each licence renewal (as the `X-Bravos-Machine` header).
|
|
26
|
+
- **When not:** inside a container or on a CI runner, where many machines share one id, and when the id cannot be read. The portal treats "no fingerprint" as allowed.
|
|
27
|
+
- **Clearer answers when a trial cannot start.** `bravos account activate` now says so when a free trial was already used by you or on this machine (with the plans link and support address), when this version is too old to start a trial, and when a trial has to be started from the terminal.
|
|
28
|
+
- Nothing else changes. Run `bravos setup` in each repository to refresh its installed hook copy.
|
|
29
|
+
|
|
30
|
+
## 1.20.0
|
|
31
|
+
|
|
32
|
+
- **Replay can report permission and prerequisites without executing a kit.**
|
|
33
|
+
`bravos hook replay preflight run <kit.js>` (also `run-once` and `scheduled`)
|
|
34
|
+
emits `bravos.replay-preflight/v1` JSON. It shares policy, scope, target,
|
|
35
|
+
owner-word and profile checks with replay. Blocked checks refuse the run;
|
|
36
|
+
pending build/identity/launch provenance remains explicit.
|
|
37
|
+
- **Supplied replay identities must pass CXG auth verify before execution.**
|
|
38
|
+
Capture or re-import a missing or expired profile before retrying. Preflight
|
|
39
|
+
performs this same liveness check after authorization; no proof executes.
|
|
40
|
+
- See [continuous proof](continuous-proof.md#non-executing-replay-preflight-1200)
|
|
41
|
+
for the receipt contract and launch provenance limitations. Run `bravos setup`
|
|
42
|
+
in each repository to refresh its installed hook copy.
|
|
43
|
+
|
|
5
44
|
## 1.19.0
|
|
6
45
|
|
|
7
46
|
- **Teammates without Bravos get an invitation instead of your setup.** The hooks travel with the repository. On a machine without Bravos (no `bravos` command, licence or plugin), they now show only an invitation, once per session:
|
package/hooks/cards.mjs
CHANGED
|
@@ -1,12 +1,24 @@
|
|
|
1
1
|
// @comment -- "bravos threat cards PostToolUse hook entry (Claude Code and Codex): after an edit, shows the developer a card for each new critical or high exposure no test has confirmed or refuted (hooks/lib/cards.mjs), gives the agent one line to raise it, logs it for bravos watch and, when the person turned it on, sends a desktop notification. Silent when BRAVOS_THREAT_CARDS=off, when the person switched cards off (bravos prefs set cards off), or when it is the plugin's copy in a repository that registers its own. Always exits 0; a failure shows nothing."
|
|
2
2
|
import { readFileSync, realpathSync } from 'node:fs';
|
|
3
|
-
import { basename, join } from 'node:path';
|
|
3
|
+
import { basename, isAbsolute, join, relative } from 'node:path';
|
|
4
4
|
import { spawnSync } from 'node:child_process';
|
|
5
5
|
import { fileURLToPath } from 'node:url';
|
|
6
6
|
import { agentLine, decideCards, notify, readSeen, renderCard, targetRecorded, writeSeen } from './lib/cards.mjs';
|
|
7
7
|
import { gitCommonDir, readPrefs } from './lib/prefs.mjs';
|
|
8
8
|
import { audience } from './lib/audience.mjs';
|
|
9
9
|
import { logWatchEvent } from './lib/snapshot.mjs';
|
|
10
|
+
import { adoptedPrinciples, principlesForFile } from './lib/principles.mjs';
|
|
11
|
+
|
|
12
|
+
// @comment -- "The after-edit note about the company's security design principles: when the edited file matches the paths an adopted principle names, one line for the agent naming that principle and its statement, so it keeps to it while it works. Statements come from principles.md, fingerprint-checked, cleaned to one line and cut short."
|
|
13
|
+
function principleNote(root, toolInput) {
|
|
14
|
+
const file = typeof toolInput?.file_path === 'string' ? toolInput.file_path : typeof toolInput?.path === 'string' ? toolInput.path : '';
|
|
15
|
+
if (!file) return '';
|
|
16
|
+
const rel = (isAbsolute(file) ? relative(root, file) : file).split('\\').join('/');
|
|
17
|
+
if (!rel || rel.startsWith('..')) return '';
|
|
18
|
+
const hits = principlesForFile(adoptedPrinciples(root), rel).slice(0, 3);
|
|
19
|
+
if (!hits.length) return '';
|
|
20
|
+
return `${rel} is under the team's security design principles: ${hits.map((p) => `${p.id} (${p.kind}) "${p.statement.slice(0, 200)}"`).join('; ')}. Keep to ${hits.length === 1 ? 'it' : 'them'}; if this change cannot, say so and ask the person (.guardlink/principles.md).`;
|
|
21
|
+
}
|
|
10
22
|
|
|
11
23
|
async function readPayload() {
|
|
12
24
|
if (process.stdin.isTTY) return {};
|
|
@@ -52,9 +64,11 @@ async function main() {
|
|
|
52
64
|
if (top.status !== 0) throw new Error('not a repository');
|
|
53
65
|
const root = top.stdout.trim();
|
|
54
66
|
if (deferToRepo(root)) throw new Error('repo copy');
|
|
67
|
+
const note = principleNote(root, payload.tool_input);
|
|
68
|
+
if (note) out = { hookSpecificOutput: { hookEventName: 'PostToolUse', additionalContext: note } };
|
|
55
69
|
const commonDir = gitCommonDir(root);
|
|
56
70
|
const prefs = readPrefs(commonDir);
|
|
57
|
-
if (prefs.cards?.value === 'off') throw new Error('off');
|
|
71
|
+
if (prefs.cards?.value === 'off') throw new Error('cards off');
|
|
58
72
|
const harness = process.argv.includes('--harness') ? process.argv[process.argv.indexOf('--harness') + 1] : 'claude';
|
|
59
73
|
const { cards, seen } = decideCards({ root, toolName: payload.tool_name, toolInput: payload.tool_input, seen: readSeen(commonDir) });
|
|
60
74
|
if (cards.length) {
|
|
@@ -63,12 +77,13 @@ async function main() {
|
|
|
63
77
|
const shown = cards.slice(0, 3);
|
|
64
78
|
const more = cards.length - shown.length;
|
|
65
79
|
const text = ['bravos · threat card', ...shown.map((c) => renderCard(c, { target, harness })), ...(more > 0 ? [`… and ${more} more: bravos watch lists them`] : []), 'Shown once per threat. bravos watch and the dashboard keep the list.'].join('\n');
|
|
66
|
-
out = { systemMessage: text, hookSpecificOutput: { hookEventName: 'PostToolUse', additionalContext: agentLine(cards, { target, harness }) } };
|
|
80
|
+
out = { systemMessage: text, hookSpecificOutput: { hookEventName: 'PostToolUse', additionalContext: [agentLine(cards, { target, harness }), note].filter(Boolean).join('\n') } };
|
|
67
81
|
for (const c of cards) logWatchEvent(root, { summary: `card: ${c.severity.toUpperCase()} ${c.threat} on ${c.asset} · ${c.file}${c.line ? `:${c.line}` : ''} · untested`, keys: [`bravos-card:${c.threat}`] });
|
|
68
82
|
if (prefs.notify?.value === 'on' || process.env.BRAVOS_NOTIFY === 'on') notify(cards[0], basename(root));
|
|
69
83
|
}
|
|
70
|
-
} catch {
|
|
71
|
-
|
|
84
|
+
} catch (e) {
|
|
85
|
+
// Cards switched off still leave the principles note; anything else that failed shows nothing.
|
|
86
|
+
if (!(e instanceof Error && e.message === 'cards off')) out = {};
|
|
72
87
|
}
|
|
73
88
|
process.stdout.write(JSON.stringify(out) + '\n');
|
|
74
89
|
process.exit(0);
|
package/hooks/lib/briefing.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import { accessSync, constants, readFileSync } from 'node:fs';
|
|
|
4
4
|
import { homedir } from 'node:os';
|
|
5
5
|
import { basename, delimiter, dirname, join } from 'node:path';
|
|
6
6
|
import { contextGate, readContext } from './context.mjs';
|
|
7
|
+
import { adoptedPrinciples } from './principles.mjs';
|
|
7
8
|
import { legacySkills, legacySkillsLine } from './legacy-skills.mjs';
|
|
8
9
|
import { deadHooksLine, deadUserHooks } from './dead-hooks.mjs';
|
|
9
10
|
import { THEMES } from './palette.mjs';
|
|
@@ -124,17 +125,37 @@ export function readIntent(root) {
|
|
|
124
125
|
|
|
125
126
|
// @comment -- "The briefing's line about the team's design documents, when there are any: how many, by id, that the rules cite them and that only the context skill opens them; and when the intent has fallen behind a document (edited, or added since), which ones and how to refresh. Ids only, never a title or any text from a document."
|
|
126
127
|
export function contextLine(context, harness) {
|
|
127
|
-
if (!context || typeof context !== 'object'
|
|
128
|
+
if (!context || typeof context !== 'object') return null;
|
|
128
129
|
const run = harness === 'claude' ? '/bravos-context' : 'the bravos-context skill';
|
|
130
|
+
// Added on the intake page and not text the CLI could store: the agent converts each one (bravos-context step 2).
|
|
131
|
+
const inbox = context.inbox > 0 ? `${context.inbox} design document${context.inbox === 1 ? '' : 's'} added on the intake page wait${context.inbox === 1 ? 's' : ''} in .bravos/context/inbox/ for you to convert and store with bravos context add (${run} step 2)` : '';
|
|
132
|
+
if (!context.count) return inbox ? `Design documents: ${inbox}` : null;
|
|
129
133
|
const list = (ids) => (ids.length > 6 ? `${ids.slice(0, 6).join(', ')} and ${ids.length - 6} more` : ids.join(', '));
|
|
130
134
|
const behind = [
|
|
131
135
|
context.changed?.length ? `${list(context.changed)} changed since the rules were written` : '',
|
|
132
136
|
context.unread?.length ? `${list(context.unread)} not read into the intent yet` : '',
|
|
133
137
|
].filter(Boolean);
|
|
134
138
|
const head = `Design documents: ${context.count} in .bravos/context/ (${list(context.ids ?? [])})`;
|
|
135
|
-
|
|
139
|
+
const line = behind.length
|
|
136
140
|
? `${head} — ${behind.join('; ')}: refresh the intent with ${run}`
|
|
137
141
|
: `${head} — intent.md's rules cite them by id; only ${run} opens the documents themselves`;
|
|
142
|
+
return inbox ? `${line}. Also: ${inbox}` : line;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// @comment -- "The adopted security design principles as the briefing needs them: how many, which are enforced, and the ids of those that apply everywhere. Only principles whose fingerprint still matches their text count; a hand-edited one is left out, and the check reports it."
|
|
146
|
+
export function readPrinciples(root) {
|
|
147
|
+
const adopted = adoptedPrinciples(root);
|
|
148
|
+
if (!adopted.length) return null;
|
|
149
|
+
return { count: adopted.length, enforced: adopted.filter((p) => p.kind === 'enforced').map((p) => p.id), everywhere: adopted.filter((p) => !p.paths.length).map((p) => p.id), scoped: adopted.filter((p) => p.paths.length).map((p) => p.id) };
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// @comment -- "The briefing's line about the company's security design principles, when the repository has adopted ones: read .guardlink/principles.md before changing code and follow it, raise a change that would break one, and never edit it. Ids only; the principles' text stays in their file, which the agent reads itself."
|
|
153
|
+
export function principlesLine(p) {
|
|
154
|
+
if (!p || typeof p !== 'object' || !p.count) return null;
|
|
155
|
+
const ids = (xs) => (xs.length > 8 ? `${xs.slice(0, 8).join(', ')} and ${xs.length - 8} more` : xs.join(', '));
|
|
156
|
+
const enforced = p.enforced?.length ? `; enforced (tested, and the pre-PR gate stops a change that breaks them): ${ids(p.enforced)}` : '';
|
|
157
|
+
const scoped = p.scoped?.length ? `; ${ids(p.scoped)} apply only to the paths they name, and the after-edit note says when you touch one` : '';
|
|
158
|
+
return `Security design principles: ${p.count} adopted in .guardlink/principles.md${enforced}${scoped}. Read the file before changing code here and follow each one; when a change would break one, say so and ask the person first. Never edit the file, its adoptions or its exceptions.`;
|
|
138
159
|
}
|
|
139
160
|
|
|
140
161
|
// @comment -- "The briefing's Intent line. Until a named person confirms what the product is for, it tells the agent to keep annotating against its own draft (drafting one first when there is none, without waiting for answers) and to ask the person once each session to confirm it on the intake page. Right after setup (a fresh hand-off marker) it says to begin in the first reply. A recorded decline is shown with its name and date, and ends the asking."
|
|
@@ -262,6 +283,8 @@ export function buildBriefing(inputs) {
|
|
|
262
283
|
if (i.intent && typeof i.intent === 'object') tail.push(intentLine(i.intent, i.harness, i.gate, i.handoff === true));
|
|
263
284
|
const documents = contextLine(i.context, i.harness);
|
|
264
285
|
if (documents) tail.push(documents);
|
|
286
|
+
const principles = principlesLine(i.principles);
|
|
287
|
+
if (principles) tail.push(principles);
|
|
265
288
|
// The person's standing answer about commits, when they gave one (hooks/lib/prefs.mjs).
|
|
266
289
|
const commits = commitsLine(i.prefs);
|
|
267
290
|
if (commits) tail.push(commits);
|
|
@@ -590,6 +613,7 @@ export async function collect(root, env, { deadlineMs = 20000, nextCount = 3 } =
|
|
|
590
613
|
inFlight,
|
|
591
614
|
intent: readIntent(root),
|
|
592
615
|
context: readContext(root),
|
|
616
|
+
principles: readPrinciples(root),
|
|
593
617
|
gate: contextGate(root),
|
|
594
618
|
prefs: readPrefs(facts.commonDir),
|
|
595
619
|
// The background annotation pass is off for this run (BRAVOS_AUTO_ANNOTATE=off) or in CI, where the nightly annotates.
|
package/hooks/lib/context.mjs
CHANGED
|
@@ -269,6 +269,39 @@ export function commitReader(root, commit) {
|
|
|
269
269
|
// ---------------------------------------------------------------------------------------------
|
|
270
270
|
|
|
271
271
|
// Files an agent writes beside the store and that are committed with it. They are scanned for local paths only.
|
|
272
|
+
const fold = (t) => String(t ?? '').toLowerCase().replace(/[*_`~]/g, '').replace(/[“”"'‘’]/g, '').replace(/\s+/g, ' ').trim();
|
|
273
|
+
|
|
274
|
+
// @comment -- "Where a citation points in a stored document: a heading whose words match the cited section, else the paragraph that contains the cited words. Returns that passage (at most 1,200 characters) or null. Case, spacing, quotes and Markdown emphasis are ignored; nothing else is guessed, so a section that is not in the document is reported, never invented."
|
|
275
|
+
export function findSection(text, section) {
|
|
276
|
+
const want = fold(section);
|
|
277
|
+
if (!want || want.length < 3) return null;
|
|
278
|
+
const lines = String(text).split('\n');
|
|
279
|
+
const cap = (t) => (t.length > 1200 ? `${t.slice(0, 1199)}…` : t);
|
|
280
|
+
for (let i = 0; i < lines.length; i++) {
|
|
281
|
+
const h = /^(#{1,6})\s+(.*)$/.exec(lines[i]);
|
|
282
|
+
if (!h) continue;
|
|
283
|
+
const head = fold(h[2]);
|
|
284
|
+
if (head !== want && !head.includes(want)) continue;
|
|
285
|
+
const out = [lines[i]];
|
|
286
|
+
for (let k = i + 1; k < lines.length; k++) {
|
|
287
|
+
const next = /^(#{1,6})\s/.exec(lines[k]);
|
|
288
|
+
if (next && next[1].length <= h[1].length) break;
|
|
289
|
+
out.push(lines[k]);
|
|
290
|
+
}
|
|
291
|
+
return cap(out.join('\n').trim());
|
|
292
|
+
}
|
|
293
|
+
const paragraphs = String(text).split(/\n\s*\n/);
|
|
294
|
+
const hit = paragraphs.find((p) => fold(p).includes(want));
|
|
295
|
+
return hit ? cap(hit.trim()) : null;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// @comment -- "Every citation with a section in some text: SRC-n followed by a quoted section name, straight or curly quotes. Citations that name no section are not returned; they are checked by id alone."
|
|
299
|
+
export function citations(text) {
|
|
300
|
+
const out = [];
|
|
301
|
+
for (const m of String(text).matchAll(/\b(SRC-[1-9][0-9]{0,4})\b\s*[,:]?\s*["“]([^"”\n]{3,200})["”]/g)) out.push({ id: m[1], section: m[2] });
|
|
302
|
+
return out;
|
|
303
|
+
}
|
|
304
|
+
|
|
272
305
|
const WRITTEN_BESIDE = ['.guardlink/intent.md', '.guardlink/intent-draft.json'];
|
|
273
306
|
|
|
274
307
|
// @comment -- "Checks the whole store and returns what is wrong: an unreadable index, a source with no file or with two, a file that is not a regular text file, text edited since it was recorded, secrets, local paths, embedded content, a link that should not be committed, a file in the folder that no entry owns, a source cited by the intent but absent, and a folder git ignores. `problems` fail the check; `notes` do not. Nothing here prints or throws, and no finding carries the text that triggered it."
|
|
@@ -293,6 +326,7 @@ export function checkContext(root, opts = {}) {
|
|
|
293
326
|
for (const e of listing) if (!e.regular) problem({ kind: 'not-regular', file: `${SOURCES_DIR}/${e.name}`, message: 'it is a link or a folder, not a regular file: a source is one Markdown file' });
|
|
294
327
|
const names = listing.filter((e) => e.regular).map((e) => e.name);
|
|
295
328
|
const owned = new Set();
|
|
329
|
+
const stored = new Map();
|
|
296
330
|
|
|
297
331
|
for (const s of parsed.sources) {
|
|
298
332
|
const name = fileFor(s.id, names);
|
|
@@ -317,6 +351,7 @@ export function checkContext(root, opts = {}) {
|
|
|
317
351
|
continue;
|
|
318
352
|
}
|
|
319
353
|
const text = decoded.text;
|
|
354
|
+
stored.set(s.id, text);
|
|
320
355
|
if (sha256(Buffer.from(text, 'utf8')) !== s.sha256) {
|
|
321
356
|
entry.state = 'changed';
|
|
322
357
|
problem({ kind: 'changed', id: s.id, file, message: `${s.id}: edited since it was recorded: run bravos context update ${s.id}, then refresh the intent that cites it` });
|
|
@@ -337,6 +372,14 @@ export function checkContext(root, opts = {}) {
|
|
|
337
372
|
if (!buf) continue;
|
|
338
373
|
const text = buf.toString('utf8');
|
|
339
374
|
for (const m of text.matchAll(/\bSRC-[1-9][0-9]{0,4}\b/g)) if (!known.has(m[0]) && !cited.has(m[0])) cited.set(m[0], rel);
|
|
375
|
+
// A cited section must be in the document it names: a wrong section is a rule resting on nothing.
|
|
376
|
+
const seen = new Set();
|
|
377
|
+
for (const c of citations(text)) {
|
|
378
|
+
const key = `${c.id}\u0000${fold(c.section)}`;
|
|
379
|
+
if (seen.has(key) || !stored.has(c.id)) continue;
|
|
380
|
+
seen.add(key);
|
|
381
|
+
if (!findSection(stored.get(c.id), c.section)) problem({ kind: 'cited-section', id: c.id, file: rel, message: `${rel} cites ${c.id} "${cleanLine(c.section, 80)}", which is not a heading or passage in ${c.id}: correct the citation, or the rule it supports` });
|
|
382
|
+
}
|
|
340
383
|
for (const f of scanPaths(text, who)) problem({ kind: 'local-path', file: rel, line: f.line, message: `${rel}: line ${f.line} carries ${an(f.rule)}: cite the source by its SRC id, not by where the file was` });
|
|
341
384
|
}
|
|
342
385
|
for (const [id, rel] of cited) problem({ kind: 'cited-absent', id, file: rel, message: `${id} is cited in ${rel} but is not in the index` });
|
|
@@ -368,9 +411,21 @@ export function formatCheck(result) {
|
|
|
368
411
|
return lines;
|
|
369
412
|
}
|
|
370
413
|
|
|
414
|
+
export const INBOX_DIR = `${CONTEXT_DIR}/inbox`;
|
|
415
|
+
|
|
416
|
+
// @comment -- "Documents added on the intake page that the CLI does not convert (a PDF, Word file, slides or a link), waiting for the agent: one <name>.json record each in .bravos/context/inbox/, a folder git ignores. Count only, for the briefing; never a title or a name."
|
|
417
|
+
export function inboxCount(root) {
|
|
418
|
+
try {
|
|
419
|
+
const base = realpathSync(root);
|
|
420
|
+
return readdirSync(join(base, INBOX_DIR)).filter((n) => n.endsWith('.json')).length;
|
|
421
|
+
} catch {
|
|
422
|
+
return 0;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
371
426
|
// @comment -- "What a briefing needs about the store, cheaply and without ever throwing: whether it exists, the ids it lists, and which of them the intent has fallen behind. intent.md's Sources section records the hash each document had when the rules were written (`- SRC-2: … sha256 <prefix>`); a source whose text now hashes differently is `changed`, and one the section does not list is `unread`. Ids only: a document's title or text never reaches a briefing."
|
|
372
427
|
export function readContext(root) {
|
|
373
|
-
const none = { exists: false, count: 0, ids: [], changed: [], unread: [] };
|
|
428
|
+
const none = { exists: false, count: 0, ids: [], changed: [], unread: [], inbox: inboxCount(root) };
|
|
374
429
|
try {
|
|
375
430
|
const reader = treeReader(root);
|
|
376
431
|
if (!reader.exists()) return none;
|
|
@@ -382,6 +437,7 @@ export function readContext(root) {
|
|
|
382
437
|
if (intent !== null) for (const m of intent.matchAll(/^\s*[-*]\s+(SRC-[1-9][0-9]{0,4})\b.*?\bsha256\s+([a-f0-9]{8,64})\b/gm)) read.set(m[1], m[2]);
|
|
383
438
|
return {
|
|
384
439
|
exists: true,
|
|
440
|
+
inbox: inboxCount(root),
|
|
385
441
|
count: sources.length,
|
|
386
442
|
ids: sources.map((s) => s.id),
|
|
387
443
|
// With no intent yet nothing is behind: the documents are simply waiting to be read.
|
package/hooks/lib/licence.mjs
CHANGED
|
@@ -42,7 +42,7 @@ export const _setTrustedKeysForTests = (keys) => {
|
|
|
42
42
|
};
|
|
43
43
|
|
|
44
44
|
/** What this product gates on a Team (or higher) licence; everything else is free. */
|
|
45
|
-
export const PAID_FEATURES = ['pre-pr', 'ci', 'schedule', 'workspace', 'campaign', 'sast', 'codegraph'];
|
|
45
|
+
export const PAID_FEATURES = ['pre-pr', 'ci', 'schedule', 'workspace', 'campaign', 'sast', 'codegraph', 'principles'];
|
|
46
46
|
export const PAID_FEATURE_LABELS = {
|
|
47
47
|
'pre-pr': 'the pre-PR gate',
|
|
48
48
|
ci: 'CI and nightly workflows',
|
|
@@ -51,6 +51,7 @@ export const PAID_FEATURE_LABELS = {
|
|
|
51
51
|
campaign: 'campaigns',
|
|
52
52
|
sast: 'SAST',
|
|
53
53
|
codegraph: 'the code graph',
|
|
54
|
+
principles: 'security design principles',
|
|
54
55
|
};
|
|
55
56
|
|
|
56
57
|
// ---------------------------------------------------------------------------------------------
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// @comment -- "A one-way fingerprint of this machine for the account portal: sha256 of a fixed label and the operating system's own machine id (macOS IOPlatformUUID, Linux /etc/machine-id, Windows MachineGuid), so the portal can tell one machine from another for the one-free-trial rule without ever learning the id. The raw id never leaves this function. No dependency, no shell; null with a reason when the id cannot be read or would be shared (a container, a CI runner), because a shared id would wrongly refuse real people."
|
|
2
|
+
//
|
|
3
|
+
// Used by `bravos account activate` (src/account.ts) and the licence refresh
|
|
4
|
+
// (hooks/lib/refresh.mjs). Never throws.
|
|
5
|
+
//
|
|
6
|
+
// NULL IS AN ANSWER. The portal treats "no fingerprint" as allowed and flagged,
|
|
7
|
+
// never as refused, so every doubtful case below says null rather than guessing:
|
|
8
|
+
// - a container (/.dockerenv, /run/.containerenv, or a container cgroup): base
|
|
9
|
+
// images often ship ONE /etc/machine-id, so every container from an image
|
|
10
|
+
// would look like the same machine;
|
|
11
|
+
// - a CI runner (CI=true): the same, for every job on a shared image;
|
|
12
|
+
// - an id that is empty, all zeros, or the wrong shape.
|
|
13
|
+
|
|
14
|
+
import { createHash } from 'node:crypto';
|
|
15
|
+
import { execFileSync } from 'node:child_process';
|
|
16
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
17
|
+
|
|
18
|
+
export const MACHINE_LABEL = 'bravos-machine-v1:';
|
|
19
|
+
const ID_RE = /^[0-9a-fA-F-]{16,64}$/;
|
|
20
|
+
|
|
21
|
+
const readText = (file) => {
|
|
22
|
+
try {
|
|
23
|
+
return readFileSync(file, 'utf8').trim();
|
|
24
|
+
} catch {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/** Whether this process runs in a container, from the markers the common runtimes leave. */
|
|
30
|
+
export function inContainer({ exists = existsSync, read = readText } = {}) {
|
|
31
|
+
if (exists('/.dockerenv') || exists('/run/.containerenv')) return true;
|
|
32
|
+
const cgroup = read('/proc/1/cgroup') ?? '';
|
|
33
|
+
return /docker|kubepods|containerd|libpod|lxc/.test(cgroup);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** The operating system's own machine id, unhashed, or null. Kept inside this module. */
|
|
37
|
+
export function osMachineId({ platform = process.platform, read = readText, exec = execFileSync } = {}) {
|
|
38
|
+
try {
|
|
39
|
+
if (platform === 'darwin') {
|
|
40
|
+
const out = String(exec('/usr/sbin/ioreg', ['-rd1', '-c', 'IOPlatformExpertDevice'], { encoding: 'utf8', timeout: 2000, stdio: ['ignore', 'pipe', 'ignore'] }));
|
|
41
|
+
return out.match(/"IOPlatformUUID"\s*=\s*"([^"]+)"/)?.[1] ?? null;
|
|
42
|
+
}
|
|
43
|
+
if (platform === 'linux') return read('/etc/machine-id') || read('/var/lib/dbus/machine-id') || null;
|
|
44
|
+
if (platform === 'win32') {
|
|
45
|
+
const out = String(exec('reg', ['query', 'HKLM\\SOFTWARE\\Microsoft\\Cryptography', '/v', 'MachineGuid'], { encoding: 'utf8', timeout: 2000, stdio: ['ignore', 'pipe', 'ignore'], windowsHide: true }));
|
|
46
|
+
return out.match(/MachineGuid\s+REG_SZ\s+(\S+)/)?.[1] ?? null;
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
} catch {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
let cached = null;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* This machine's fingerprint: { key, reason }. `key` is 64 lowercase hex or
|
|
58
|
+
* null; `reason` says why it is null ('container', 'ci', 'unreadable').
|
|
59
|
+
* Memoised for the process; tests pass `deps` and bypass the cache.
|
|
60
|
+
*/
|
|
61
|
+
export function machineFingerprint(env = process.env, deps = null) {
|
|
62
|
+
if (!deps && cached) return cached;
|
|
63
|
+
const d = deps ?? {};
|
|
64
|
+
let answer;
|
|
65
|
+
if (env.CI === 'true' || env.CI === '1') answer = { key: null, reason: 'ci' };
|
|
66
|
+
else if (inContainer(d)) answer = { key: null, reason: 'container' };
|
|
67
|
+
else {
|
|
68
|
+
const id = osMachineId(d);
|
|
69
|
+
const clean = typeof id === 'string' ? id.trim() : '';
|
|
70
|
+
answer =
|
|
71
|
+
ID_RE.test(clean) && !/^[0-]+$/.test(clean)
|
|
72
|
+
? { key: createHash('sha256').update(MACHINE_LABEL + clean.toLowerCase()).digest('hex'), reason: null }
|
|
73
|
+
: { key: null, reason: 'unreadable' };
|
|
74
|
+
}
|
|
75
|
+
if (!deps) cached = answer;
|
|
76
|
+
return answer;
|
|
77
|
+
}
|