@bugb-technologies/bravos 1.5.3 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +81 -9
- package/dist/context.js +387 -0
- package/dist/dashboard.js +19 -5
- package/dist/guide.js +5 -2
- package/dist/help.js +19 -0
- package/dist/palette.js +4 -4
- package/dist/review-server.js +4 -4
- package/dist/review.js +103 -18
- package/dist/rules.js +218 -0
- package/dist/uninstall.js +6 -0
- package/dist/watch-frame.js +67 -42
- package/dist/watch.js +21 -7
- package/docs/GUIDE.md +20 -2
- package/docs/UPGRADING.md +28 -0
- package/hooks/lib/autopilot.mjs +29 -7
- package/hooks/lib/briefing.mjs +214 -171
- package/hooks/lib/context.mjs +522 -0
- package/hooks/lib/palette.mjs +4 -4
- package/hooks/lib/pre-pr.mjs +70 -0
- package/hooks/lib/setup.mjs +5 -2
- package/hooks/session-start.mjs +24 -2
- package/package.json +1 -1
- package/skills/bravos/SKILL.md +1 -1
- package/skills/bravos-annotate/SKILL.md +5 -3
- package/skills/bravos-annotate/scripts/lib/gate.mjs +45 -0
- package/skills/bravos-annotate/scripts/slice.mjs +10 -0
- package/skills/bravos-campaign/SKILL.md +1 -1
- package/skills/bravos-context/SKILL.md +17 -10
- package/skills/bravos-context/intent.example.md +14 -1
- package/skills/bravos-recheck/SKILL.md +1 -1
- package/skills/bravos-ship/SKILL.md +2 -1
- package/skills/bravos-templatize/SKILL.md +1 -1
- package/templates/dashboard/dashboard.html +97 -0
- package/templates/review/review.html +368 -123
- package/templates/workflows/bravos-nightly-claude.yml +36 -2
- package/templates/workflows/bravos-nightly-codex.yml +36 -2
- package/templates/workflows/bravos-nightly-copilot.yml +23 -0
- package/templates/workflows/bravos-pr-gate.yml +76 -0
package/hooks/lib/briefing.mjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { spawn, spawnSync } from 'node:child_process';
|
|
3
3
|
import { accessSync, constants, readFileSync } from 'node:fs';
|
|
4
4
|
import { basename, delimiter, dirname, join } from 'node:path';
|
|
5
|
+
import { contextGate, readContext } from './context.mjs';
|
|
5
6
|
import { THEMES } from './palette.mjs';
|
|
6
7
|
import { readProving } from './proving.mjs';
|
|
7
8
|
import { planLabel, planLine, status as licenceStatus } from './licence.mjs';
|
|
@@ -115,10 +116,28 @@ export function readIntent(root) {
|
|
|
115
116
|
return { status: drafts > 0 ? 'draft' : 'confirmed', invariants, drafts };
|
|
116
117
|
}
|
|
117
118
|
|
|
118
|
-
|
|
119
|
+
// @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."
|
|
120
|
+
export function contextLine(context, harness) {
|
|
121
|
+
if (!context || typeof context !== 'object' || !context.count) return null;
|
|
119
122
|
const run = harness === 'claude' ? '/bravos-context' : 'the bravos-context skill';
|
|
120
|
-
|
|
121
|
-
|
|
123
|
+
const list = (ids) => (ids.length > 6 ? `${ids.slice(0, 6).join(', ')} and ${ids.length - 6} more` : ids.join(', '));
|
|
124
|
+
const behind = [
|
|
125
|
+
context.changed?.length ? `${list(context.changed)} changed since the rules were written` : '',
|
|
126
|
+
context.unread?.length ? `${list(context.unread)} not read into the intent yet` : '',
|
|
127
|
+
].filter(Boolean);
|
|
128
|
+
const head = `Design documents: ${context.count} in .bravos/context/ (${list(context.ids ?? [])})`;
|
|
129
|
+
return behind.length
|
|
130
|
+
? `${head} — ${behind.join('; ')}: refresh the intent with ${run}`
|
|
131
|
+
: `${head} — intent.md's rules cite them by id; only ${run} opens the documents themselves`;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// @comment -- "The briefing's Intent line. While the context gate is closed it also says so in words an agent acts on: do not start threat-modelling, run the context skill first, and how a person declines. A recorded decline is shown with the name and date of the person who made it."
|
|
135
|
+
function intentLine(intent, harness, gate) {
|
|
136
|
+
const run = harness === 'claude' ? '/bravos-context' : 'the bravos-context skill';
|
|
137
|
+
const closed = gate && gate.open === false ? `. Context comes first: do not annotate or start a campaign until a named person has confirmed it (or run bravos context decline --by "<name>" themselves).` : '';
|
|
138
|
+
const declined = gate?.state === 'declined' ? `declined by ${gate.by} on ${gate.at}` : '';
|
|
139
|
+
if (intent.status === 'none') return declined ? `Intent: ${declined} — severities are not calibrated to the product; ${run} when the team is ready` : `Intent: none — severities are not calibrated to the product; run ${run}${closed}`;
|
|
140
|
+
if (intent.status === 'draft') return `Intent: draft (${intent.invariants} invariants, ${intent.drafts} items unconfirmed${declined ? `; context ${declined}` : ''}) — confirm with ${run}${closed}`;
|
|
122
141
|
return `Intent: confirmed (${intent.invariants} invariants)`;
|
|
123
142
|
}
|
|
124
143
|
|
|
@@ -213,7 +232,9 @@ export function buildBriefing(inputs) {
|
|
|
213
232
|
else if (i.inFlight.prs > 0 || i.inFlight.files > 0) {
|
|
214
233
|
tail.push(`In flight by teammates: ${i.inFlight.files} files in ${i.inFlight.prs} open PRs`);
|
|
215
234
|
}
|
|
216
|
-
if (i.intent && typeof i.intent === 'object') tail.push(intentLine(i.intent, i.harness));
|
|
235
|
+
if (i.intent && typeof i.intent === 'object') tail.push(intentLine(i.intent, i.harness, i.gate));
|
|
236
|
+
const documents = contextLine(i.context, i.harness);
|
|
237
|
+
if (documents) tail.push(documents);
|
|
217
238
|
if (i.proving && typeof i.proving === 'object') {
|
|
218
239
|
const p = i.proving;
|
|
219
240
|
tail.push(p.status === 'set'
|
|
@@ -462,6 +483,8 @@ export async function collect(root, env, { deadlineMs = 20000, nextCount = 3 } =
|
|
|
462
483
|
dashboard: facts.dashboard,
|
|
463
484
|
inFlight,
|
|
464
485
|
intent: readIntent(root),
|
|
486
|
+
context: readContext(root),
|
|
487
|
+
gate: contextGate(root),
|
|
465
488
|
annotationMode: readAnnotationMode(root),
|
|
466
489
|
// bravos on PATH: what its probe says (a graph for this commit or not); else codegraph-mcp on PATH means the MCP route.
|
|
467
490
|
codegraph: graphState ?? (whichOnPath('codegraph-mcp', env) ? 'unknown' : 'unavailable'),
|
|
@@ -482,7 +505,6 @@ export async function collect(root, env, { deadlineMs = 20000, nextCount = 3 } =
|
|
|
482
505
|
// Startup banner: shown to the human (systemMessage), never added to the model's context.
|
|
483
506
|
// ---------------------------------------------------------------------------------------------
|
|
484
507
|
|
|
485
|
-
const BANNER_WIDTH = 80;
|
|
486
508
|
// A large shadowed wordmark, six rows, built letter by letter so every row has the same width.
|
|
487
509
|
const GLYPHS = {
|
|
488
510
|
B: ['██████╗ ', '██╔══██╗', '██████╔╝', '██╔══██╗', '██████╔╝', '╚═════╝ '],
|
|
@@ -493,7 +515,7 @@ const GLYPHS = {
|
|
|
493
515
|
S: ['███████╗', '██╔════╝', '███████╗', '╚════██║', '███████║', '╚══════╝'],
|
|
494
516
|
};
|
|
495
517
|
export const LOGO = Array.from({ length: 6 }, (_, r) => [...'BRAVOS'].map((c) => GLYPHS[c][r]).join(''));
|
|
496
|
-
|
|
518
|
+
|
|
497
519
|
// bravos's mascot: a hooded figure with two glowing eyes, eleven rows, left-right symmetric; ▓ is the hood, █ the eyes.
|
|
498
520
|
export const MASCOT = [
|
|
499
521
|
' ▄▄▓▓▓▓▓▓▄▄ ',
|
|
@@ -508,8 +530,26 @@ export const MASCOT = [
|
|
|
508
530
|
' ▄▓▓▓▓▄▄▄▄▄▄▄▄▄▄▓▓▓▓▄ ',
|
|
509
531
|
' ▓▓▓▓▓▓▓▓ ▐ ▌ ▓▓▓▓▓▓▓▓ ',
|
|
510
532
|
];
|
|
511
|
-
|
|
512
|
-
|
|
533
|
+
// The supplied Bravos mark, sampled as two vertical pixels per terminal cell.
|
|
534
|
+
// MASCOT and LOGO above remain available to earlier review and export clients.
|
|
535
|
+
export const BRAVOS_MARK = [
|
|
536
|
+
' ▄▄██████▄▄',
|
|
537
|
+
' ▄████████████▄',
|
|
538
|
+
' ▄██████████████▄',
|
|
539
|
+
' ████████████████',
|
|
540
|
+
' ████████████████',
|
|
541
|
+
' ████████████████',
|
|
542
|
+
'████ ████████████████ ████',
|
|
543
|
+
'████ ████████████████ ████',
|
|
544
|
+
'████ ██▀ ▀████▀ ▀██ ████',
|
|
545
|
+
'████▄ ██▄ ▄████▄ ▄██ ▄████',
|
|
546
|
+
' ██████████████████████████████',
|
|
547
|
+
' ▀▀████████████████████████▀▀',
|
|
548
|
+
' ▄████▀▀████▄',
|
|
549
|
+
' ▄▄████ ████▄▄',
|
|
550
|
+
' ██████████▀ ▀██████████',
|
|
551
|
+
' ███████▀▀ ▀▀███████',
|
|
552
|
+
];
|
|
513
553
|
// Two lines, so the plan nudge below the counts has room. The pre-PR gate is named only to people who have it.
|
|
514
554
|
const INTRO_HEAD = 'bravos makes this agent a guardlink power user: it keeps the threat model beside';
|
|
515
555
|
const INTRO_TEAM = 'the code, proves exposures on targets you own, and gates pull requests.';
|
|
@@ -635,7 +675,8 @@ export function quickStart(inputs, harness) {
|
|
|
635
675
|
const picks = [];
|
|
636
676
|
if (inputs?.stale || arr(inputs?.stranded).length > 0) picks.push('bravos-resync');
|
|
637
677
|
if (arr(ci?.confirmed).length > 0) picks.push('bravos-recheck');
|
|
638
|
-
|
|
678
|
+
// Context first: with no intent, or one nobody has confirmed, the context skill is the start, ahead of everything else.
|
|
679
|
+
if (inputs?.intent?.status === 'none' || inputs?.gate?.open === false) picks.push('bravos-context');
|
|
639
680
|
const cov = ci?.summary?.coverage;
|
|
640
681
|
if (cov && num(cov.source_files) > num(cov.annotated_files)) picks.push('bravos-annotate');
|
|
641
682
|
if (arr(g.next?.queue).some((q) => q?.state === 'untested')) picks.push('bravos-templatize');
|
|
@@ -667,124 +708,180 @@ const TIPS = [
|
|
|
667
708
|
];
|
|
668
709
|
const dayNumber = () => Math.floor(Date.now() / 86400000);
|
|
669
710
|
|
|
670
|
-
function
|
|
711
|
+
function bannerMetrics(g) {
|
|
712
|
+
if (!g.ci) return null;
|
|
671
713
|
const ci = g.ci;
|
|
672
|
-
if (!ci) return 'threat counts unknown (guardlink ci unavailable)';
|
|
673
714
|
const s = ci.summary ?? {};
|
|
674
715
|
const list = arr(ci.exposures);
|
|
675
716
|
const by = s.by_severity ?? Object.fromEntries(SEVERITIES.map((k) => [k, list.filter((e) => e?.severity === k).length]));
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
717
|
+
return {
|
|
718
|
+
total: typeof s.exposures === 'number' ? s.exposures : list.length,
|
|
719
|
+
severities: SEVERITIES.filter((k) => num(by[k]) > 0).map((k) => `${num(by[k])} ${k}`),
|
|
720
|
+
confirmed: arr(ci.confirmed).length,
|
|
721
|
+
coverage: s.coverage,
|
|
722
|
+
};
|
|
681
723
|
}
|
|
682
724
|
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
const
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
const [pr, auto] = [hook(i.prePr), hook(i.autopilot)];
|
|
690
|
-
const build = (level) => {
|
|
691
|
-
const hooks = level >= 1 && pr === auto ? `hooks ${pr}` : `${level >= 2 ? 'PR' : 'pre-PR'} ${pr} · auto ${auto}`;
|
|
692
|
-
const sast = i.sast?.summary ? `sast ${i.sast.summary.reachable}${level >= 4 ? '' : level >= 3 ? ' reach.' : ' reachable'}` : i.sast?.available?.ok ? 'sast not run' : 'sast off';
|
|
693
|
-
return `intent ${intent} · ${graph} · ${hooks} · ${sast}${setup ? ` · setup ${setup.done}/${setup.total}` : ''}`;
|
|
694
|
-
};
|
|
695
|
-
for (let level = 0; level < 4; level++) if (build(level).length <= BANNER_WIDTH) return build(level);
|
|
696
|
-
return build(4);
|
|
725
|
+
function countsLine(g) {
|
|
726
|
+
const m = bannerMetrics(g);
|
|
727
|
+
if (!m) return 'threat counts unknown (guardlink ci unavailable)';
|
|
728
|
+
const c = m.coverage;
|
|
729
|
+
return `${m.total} open${m.severities.length ? ` (${m.severities.join(', ')})` : ''} · ${m.confirmed} confirmed` +
|
|
730
|
+
(c ? ` · coverage ${num(c.percent)}% (${num(c.annotated_files)}/${num(c.source_files)})` : '');
|
|
697
731
|
}
|
|
698
732
|
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
const
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
733
|
+
// Plain printable cells only: repository metadata goes into the human's terminal.
|
|
734
|
+
const clean = (s) => String(s ?? '').replace(/[\u0000-\u001f\u007f-\u009f\u202a-\u202e\u2066-\u2069]/g, ' ');
|
|
735
|
+
function cellWidth(c) {
|
|
736
|
+
if (/\p{Mark}/u.test(c)) return 0;
|
|
737
|
+
return /[\u1100-\u115f\u2e80-\ua4cf\uac00-\ud7a3\uf900-\ufaff\ufe10-\ufe19\ufe30-\ufe6f\uff01-\uff60\uffe0-\uffe6\u{20000}-\u{3fffd}]|\p{Extended_Pictographic}/u.test(c) ? 2 : 1;
|
|
738
|
+
}
|
|
739
|
+
const cells = (s) => [...s].reduce((n, c) => n + cellWidth(c), 0);
|
|
740
|
+
function clipped(value, width) {
|
|
741
|
+
const s = clean(value);
|
|
742
|
+
if (cells(s) <= width) return s;
|
|
743
|
+
let out = '';
|
|
744
|
+
let used = 0;
|
|
745
|
+
for (const c of s) {
|
|
746
|
+
used += cellWidth(c);
|
|
747
|
+
if (used >= width) break;
|
|
748
|
+
out += c;
|
|
749
|
+
}
|
|
750
|
+
return out + '…';
|
|
751
|
+
}
|
|
752
|
+
function paired(left, right, leftWidth) {
|
|
753
|
+
const l = clipped(left, leftWidth);
|
|
754
|
+
return l + ' '.repeat(leftWidth - cells(l)) + ' │ ' + right;
|
|
755
|
+
}
|
|
718
756
|
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
const out = lines.map((l) => fit(l.trimEnd(), BANNER_WIDTH));
|
|
722
|
-
return (opts.color ? colorize(out, i, opts.theme) : out).join('\n');
|
|
723
|
-
}
|
|
724
|
-
const g = i.guardlink ?? {};
|
|
725
|
-
lines.push('', countsLine(g), statusLine(i));
|
|
726
|
-
// One plan nudge at most: hooks this repo registers but this person cannot run, a lapsed licence, or what Team would add.
|
|
757
|
+
function bannerWarnings(i, plan) {
|
|
758
|
+
const lines = [];
|
|
727
759
|
if ((i.autopilot || i.prePr) && hooksLocked(i)) lines.push(`~ ${i.autopilot ? 'autopilot' : 'the pre-PR gate'} is set up here, on the Team plan for you · bravos account activate`);
|
|
728
760
|
else if (plan && !plan.licensed && i.licence.state === 'expired') lines.push(`~ licence expired: ${TEAM_ADDS} locked · bravos licence`);
|
|
729
761
|
else if (plan && !plan.licensed) lines.push(`~ Team adds ${TEAM_ADDS} · bravos account activate`);
|
|
730
|
-
if (i.stale) lines.push(`!
|
|
731
|
-
else if (arr(i.stranded).length > 0) lines.push(`~
|
|
762
|
+
if (i.stale) lines.push(`! Findings describe older code · ${i.stale.behind} behind ${clean(i.base)} · bravos-resync`);
|
|
763
|
+
else if (arr(i.stranded).length > 0) lines.push(`~ Work on ${clean(i.stranded[0].branch)} is not on ${clean(i.base)} · bravos-resync`);
|
|
732
764
|
if (i.shadow) {
|
|
733
765
|
lines.push(i.shadow.userNewer
|
|
734
766
|
? `~ repo bravos ${i.shadow.repo} is behind your ${i.shadow.user} · run: bravos sync`
|
|
735
767
|
: `! your user-level bravos ${i.shadow.user} overrides repo ${i.shadow.repo} · run: bravos sync --global`);
|
|
736
768
|
}
|
|
737
|
-
lines
|
|
769
|
+
return lines;
|
|
770
|
+
}
|
|
738
771
|
|
|
772
|
+
// Wrap at words so a warning's recovery command and a long setup instruction remain visible.
|
|
773
|
+
function wrap(text, width) {
|
|
774
|
+
const normalized = clean(text);
|
|
775
|
+
if (cells(normalized) <= width) return [normalized];
|
|
776
|
+
const rows = [''];
|
|
777
|
+
for (const word of normalized.split(/\s+/)) {
|
|
778
|
+
const i = rows.length - 1;
|
|
779
|
+
const next = rows[i] ? rows[i] + ' ' + word : word;
|
|
780
|
+
if (rows[i] && cells(next) > width) rows.push(clipped(word, width));
|
|
781
|
+
else rows[i] = clipped(next, width);
|
|
782
|
+
}
|
|
783
|
+
return rows;
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
// @comment -- "Renders the human's session briefing from collected facts. The supplied symbol and repo facts share the header; on wide terminals the real setup checklist sits beside confirmed findings. Known-free plans get free commands; missing CI counts and stale checkouts are identified before showing findings. Commands follow the harness syntax and untrusted repo text is cleaned before applying terminal colours."
|
|
787
|
+
export function buildBanner(inputs, opts = {}) {
|
|
788
|
+
const i = inputs ?? {};
|
|
789
|
+
const harness = opts.harness ?? i.harness ?? 'other';
|
|
790
|
+
const sk = (name) => (SIGIL[harness] ?? '') + name;
|
|
791
|
+
// Allow the host's four-column hook indent. Piped hooks with unknown terminal size use the 80-column design.
|
|
792
|
+
const columns = Number(opts.columns);
|
|
793
|
+
const width = Number.isSafeInteger(columns) && columns > 0 ? Math.max(1, Math.min(118, columns - 4)) : 76;
|
|
794
|
+
const wide = width >= 116;
|
|
795
|
+
const g = i.guardlink ?? {};
|
|
796
|
+
const m = bannerMetrics(g);
|
|
797
|
+
const plan = i.licence?.state ? planLabel(i.licence) : null;
|
|
798
|
+
const version = 'Bravos' + (opts.version ? ' ' + opts.version : '');
|
|
799
|
+
const coverage = m?.coverage;
|
|
800
|
+
const summary = m ? `${m.total} open${coverage ? ` · ${num(coverage.percent)}% annotation coverage` : ''}` : 'threat counts unknown';
|
|
801
|
+
const repo = [i.repo, i.sha].filter(Boolean).join(' / ');
|
|
802
|
+
const identity = [version, plan?.label].filter(Boolean).join(' · ');
|
|
803
|
+
const facts = [repo, i.branch, identity, summary, m?.severities.join(' · '),
|
|
804
|
+
coverage ? `${num(coverage.annotated_files)} / ${num(coverage.source_files)} files` : ''];
|
|
805
|
+
const brand = wide ? ['', '', ...LOGO, 'by bugb'] : ['', '', 'BRAVOS', 'by bugb', '', ''];
|
|
806
|
+
const labels = [...brand, ...facts];
|
|
807
|
+
const head = width >= 68
|
|
808
|
+
? BRAVOS_MARK.map((row, n) => row.padEnd(32) + ' ' + (labels[n] ?? ''))
|
|
809
|
+
: ['BRAVOS', 'by bugb', ...facts].filter(Boolean);
|
|
810
|
+
const lines = head.map((l) => clipped(l, width).trimEnd());
|
|
811
|
+
const render = () => (opts.color ? colorize(lines, i, opts.theme) : lines).join('\n');
|
|
812
|
+
if (i.guardlink === 'missing') {
|
|
813
|
+
lines.push(...wrap('guardlink not found on PATH — run bravos doctor', width));
|
|
814
|
+
return render();
|
|
815
|
+
}
|
|
816
|
+
for (const warning of bannerWarnings(i, plan)) lines.push(...wrap(warning, width));
|
|
817
|
+
const rule = '─'.repeat(width);
|
|
818
|
+
const leftWidth = wide ? Math.floor(width * 0.54) : width;
|
|
819
|
+
const rightWidth = wide ? width - leftWidth - 5 : width;
|
|
739
820
|
const confirmed = arr(g.ci?.confirmed).slice().sort((a, b) => sevRank(a.severity) - sevRank(b.severity));
|
|
740
|
-
|
|
741
|
-
if (confirmed.length
|
|
742
|
-
|
|
743
|
-
|
|
821
|
+
const findings = [];
|
|
822
|
+
if (confirmed.length) {
|
|
823
|
+
findings.push(`${confirmed.length} CONFIRMED FINDING${confirmed.length === 1 ? '' : 'S'}${confirmed.length > 3 ? ' · 3 shown' : ''}`);
|
|
824
|
+
for (const c of confirmed.slice(0, 3)) {
|
|
744
825
|
const file = basename(String(c?.location?.file ?? c?.file ?? '?'));
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
} else {
|
|
826
|
+
const locator = ':' + clipped(c?.location?.line ?? c?.line ?? '?', 8);
|
|
827
|
+
const threat = clipped(assetThreat(c).threat, Math.floor(leftWidth / 2));
|
|
828
|
+
findings.push(threat + ' ' + clipped(file, leftWidth - cells(threat) - cells(locator) - 2) + locator);
|
|
829
|
+
}
|
|
830
|
+
} else if (g.ci) {
|
|
831
|
+
findings.push('0 CONFIRMED FINDINGS · Top threats');
|
|
750
832
|
const top = topThreats(g.ci.exposures);
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
const roles = [['developer', 'bravos-annotate'], ['security', 'bravos-prove'], ['team lead', free ? 'bravos-report' : 'bravos-campaign'], ['new here', 'bravos']];
|
|
764
|
-
const tasks = free
|
|
765
|
-
? [['what next?', 'bravos'], ['app intent', 'bravos-context'], ['after a fix', 'bravos-recheck'], ['write it up', 'bravos-report']]
|
|
766
|
-
: [['what next?', 'bravos'], ['before a PR', 'bravos-ship'], ['after a fix', 'bravos-recheck'], ['find routes', 'bravos-codegraph']];
|
|
767
|
-
const head = lines.splice(0);
|
|
768
|
-
lines.push('', 'If you are'.padEnd(LEFT_WIDTH) + 'To');
|
|
769
|
-
for (let r = 0; r < roles.length; r++) {
|
|
770
|
-
lines.push(fit(`${roles[r][0].padEnd(11)}${sk(roles[r][1])}`, LEFT_WIDTH - 2).padEnd(LEFT_WIDTH) + `${tasks[r][0].padEnd(13)}${sk(tasks[r][1])}`);
|
|
833
|
+
for (const t of top) {
|
|
834
|
+
const tail = ' ×' + t.count;
|
|
835
|
+
findings.push(t.severity.padEnd(9) + clipped(t.threat, leftWidth - 9 - cells(tail)) + tail);
|
|
836
|
+
}
|
|
837
|
+
if (!top.length) findings.push('none open');
|
|
838
|
+
} else findings.push('Findings unavailable', 'threat counts unknown (guardlink ci unavailable)');
|
|
839
|
+
const allFindings = 'All findings bravos dashboard';
|
|
840
|
+
if (confirmed.length && !wide && width >= 72) {
|
|
841
|
+
findings.push(allFindings + ' After a fix ' + sk('bravos-recheck'));
|
|
842
|
+
} else {
|
|
843
|
+
findings.push(allFindings);
|
|
844
|
+
if (confirmed.length) findings.push('After a fix ' + sk('bravos-recheck'));
|
|
771
845
|
}
|
|
772
|
-
const setup = i.root ? readSetup(i.root, i, harness) : null;
|
|
773
|
-
// The next step with its command; the pointer to bravos next is dropped when the command is long.
|
|
774
|
-
const nextFull = setup?.next ? `Next: ${setup.next.label} → ${setup.next.cta} · more: bravos next` : null;
|
|
775
|
-
const nextLine = nextFull && nextFull.length > BANNER_WIDTH ? `Next: ${setup.next.label} → ${setup.next.cta}` : nextFull;
|
|
776
|
-
lines.push('', fit(nextLine ?? `Tip: ${TIPS[(opts.day ?? dayNumber()) % TIPS.length]}`, BANNER_WIDTH));
|
|
777
|
-
lines.push('Guide (free, no tokens): bravos guide · bravos guide roles · bravos guide tasks');
|
|
778
846
|
|
|
847
|
+
const setup = i.root ? readSetup(i.root, i, harness) : null;
|
|
848
|
+
const graph = ({ current: 'on', cli: 'available', unknown: 'unknown', unavailable: 'off', diverged: 'stale', locked: 'locked', 'not-built': 'not built' })[i.codegraph] ?? 'unknown';
|
|
849
|
+
const hook = (on) => !on ? 'off' : hooksLocked(i) ? 'locked' : 'on';
|
|
850
|
+
const sast = i.sast?.summary ? `SAST ${i.sast.summary.reachable} reachable` : i.sast?.available?.ok ? 'SAST has not run' : 'SAST off';
|
|
851
|
+
const score = setup ? `SETUP ${setup.done}/${setup.total}` : 'SETUP';
|
|
852
|
+
const intentGraph = `Intent ${i.intent?.status ?? 'unknown'} · Code graph ${graph}`;
|
|
853
|
+
const hooks = `Pre-PR ${hook(i.prePr)} · Autopilot ${hook(i.autopilot)}`;
|
|
854
|
+
const checks = wide ? [score, intentGraph, hooks, sast] : [score + ' · ' + intentGraph, hooks + ' · ' + sast];
|
|
855
|
+
if (setup?.next) {
|
|
856
|
+
const step = setup.next;
|
|
857
|
+
checks.push(...wrap(step.paid ? 'Next: activate Team → bravos account activate' : `Next: ${step.label} → ${step.cta}`, rightWidth));
|
|
858
|
+
} else if (!setup) checks.push(...wrap('Tip: ' + TIPS[(opts.day ?? dayNumber()) % TIPS.length], rightWidth));
|
|
859
|
+
else checks.push('All setup steps complete');
|
|
860
|
+
const further = 'Further setup bravos next';
|
|
861
|
+
if (setup?.next && !wide && cells(checks.at(-1)) + 4 + further.length <= width) checks[checks.length - 1] += ' ' + further;
|
|
862
|
+
else checks.push(further);
|
|
863
|
+
|
|
864
|
+
lines.push(rule);
|
|
865
|
+
if (wide) {
|
|
866
|
+
const right = checks.flatMap((row) => wrap(row, rightWidth));
|
|
867
|
+
for (let r = 0; r < Math.max(findings.length, right.length); r++) {
|
|
868
|
+
lines.push(paired(findings[r] ?? '', right[r] ?? '', leftWidth).trimEnd());
|
|
869
|
+
}
|
|
870
|
+
} else {
|
|
871
|
+
lines.push(...findings.flatMap((s) => wrap(s, width)), rule, ...checks.flatMap((s) => wrap(s, width)));
|
|
872
|
+
}
|
|
873
|
+
lines.push(rule);
|
|
874
|
+
const shortcuts = hooksLocked(i)
|
|
875
|
+
? `App intent ${sk('bravos-context')} Write report ${sk('bravos-report')}`
|
|
876
|
+
: `Before a PR ${sk('bravos-ship')} Find routes ${sk('bravos-codegraph')}`;
|
|
877
|
+
const guide = 'All commands bravos guide';
|
|
878
|
+
lines.push(...wrap(wide ? shortcuts + ' ' + guide : shortcuts, width));
|
|
879
|
+
if (!wide) lines.push(...wrap(guide, width));
|
|
779
880
|
if (i.intent?.status === 'none') {
|
|
780
|
-
lines.push(
|
|
881
|
+
lines.push(...wrap(INTRO_HEAD + ' ' + (hooksLocked(i) ? INTRO_FREE : INTRO_TEAM), width));
|
|
882
|
+
lines.push(...wrap(`Ask "help me get started" (${SIGIL[harness] ? sk('bravos') : 'the bravos skill'}). Hide with BRAVOS_BANNER=off.`, width));
|
|
781
883
|
}
|
|
782
|
-
|
|
783
|
-
// so the Next and Guide lines are never the ones cut.
|
|
784
|
-
const cap = i.intent?.status === 'none' ? 35 : 29;
|
|
785
|
-
while (head.length + left.length + lines.length > cap && left.length > 2) left.pop();
|
|
786
|
-
const out = [...head, ...left.map((row) => fit(row, BANNER_WIDTH)), ...lines].map((l) => fit(l.trimEnd(), BANNER_WIDTH)).slice(0, cap);
|
|
787
|
-
return (opts.color ? colorize(out, i, opts.theme) : out).join('\n');
|
|
884
|
+
return render();
|
|
788
885
|
}
|
|
789
886
|
|
|
790
887
|
// @comment -- "A three-line, uncoloured summary for harnesses that show a hook's message as a warning or notice rather than in the transcript (Codex)."
|
|
@@ -809,74 +906,20 @@ const fg = (hex) => (hex ? `\x1b[38;2;${parseInt(hex.slice(1, 3), 16)};${parseIn
|
|
|
809
906
|
const RESET = '\x1b[0m';
|
|
810
907
|
export const paint = (text, hex, bold = false) => (hex || bold ? `${bold ? '\x1b[1m' : ''}${fg(hex)}${text}${RESET}` : text);
|
|
811
908
|
|
|
812
|
-
// @comment -- "
|
|
813
|
-
export function colorize(lines,
|
|
814
|
-
const
|
|
815
|
-
// One
|
|
816
|
-
const
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
if (
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
flush();
|
|
828
|
-
cur = k;
|
|
829
|
-
}
|
|
830
|
-
buf += c;
|
|
831
|
-
}
|
|
832
|
-
flush();
|
|
833
|
-
return out;
|
|
834
|
-
};
|
|
835
|
-
const mascotColour = (c) => (c === '▓' ? P.slate : c === '▄' || c === '▀' ? P.steel : '█▐▌'.includes(c) ? P.green : null);
|
|
836
|
-
const wordColour = (c) => (c === '█' ? P.green : '╗╔╝╚═║'.includes(c) ? P.blue : null);
|
|
837
|
-
return lines.map((line, n) => {
|
|
838
|
-
if (n < MASCOT.length) {
|
|
839
|
-
const chars = [...line];
|
|
840
|
-
const left = runs(chars.slice(0, MASCOT_WIDTH), mascotColour);
|
|
841
|
-
const rest = chars.slice(MASCOT_WIDTH).join('');
|
|
842
|
-
if (n >= 2 && n < 2 + LOGO.length) return left + runs([...rest], wordColour);
|
|
843
|
-
if (n === MASCOT.length - 3) return left + rest.replace(/Plan: (.+)$/, (_m, label) => paint('Plan: ', P.steel) + paint(label, P.light, true));
|
|
844
|
-
if (n === MASCOT.length - 2) return left + rest.replace(/bravos( [\d.]+)?/, (m) => paint(m, P.green, true)).replace(/ · (.+)$/, (_m, r) => ` · ${paint(r, P.light, true)}`);
|
|
845
|
-
if (n === MASCOT.length - 1) return left + rest.replace(/\S.*$/, (m) => paint(m, P.steel));
|
|
846
|
-
return left + rest;
|
|
847
|
-
}
|
|
848
|
-
if (/^If you are/.test(line)) return line.replace(/^If you are/, paint('If you are', P.light, true)).replace(/To$/, paint('To', P.light, true));
|
|
849
|
-
if (/^(developer|security|team lead|new here) /.test(line)) {
|
|
850
|
-
return line.split(/((?:\/skill:|\/|\$)?bravos(?:-[a-z]+)?(?= |$))/).map((part, k) => (k % 2 ? paint(part, P.green) : part)).join('');
|
|
851
|
-
}
|
|
852
|
-
if (/^! your user-level bravos/.test(line)) return paint(line, P.red, true);
|
|
853
|
-
if (/^~ (repo bravos |Team adds |licence expired)/.test(line)) return paint(line, P.steel);
|
|
854
|
-
if (/^Tip: /.test(line)) return paint('Tip: ', P.green, true) + paint(line.slice(5), P.light);
|
|
855
|
-
if (/^Next: /.test(line)) {
|
|
856
|
-
const [what, rest = ''] = line.slice(6).split(' → ');
|
|
857
|
-
const [cta, tailText] = rest.split(' · more: ');
|
|
858
|
-
return paint('Next: ', P.green, true) + paint(what, P.light) + (cta ? ` → ${paint(cta, P.green)}` : '') + (tailText !== undefined ? ` · more: ${paint(tailText, P.green)}` : '');
|
|
859
|
-
}
|
|
860
|
-
if (/^Guide \(free/.test(line)) return line.replace(/^Guide \(free, no tokens\):/, (m) => paint(m, P.steel)).replace(/bravos guide[a-z ]*/g, (m) => paint(m, P.green));
|
|
861
|
-
if (/^(Top threats|FIX NOW)/.test(line)) {
|
|
862
|
-
return line
|
|
863
|
-
.replace(/^Top threats/, paint('Top threats', P.light, true))
|
|
864
|
-
.replace(/^FIX NOW — confirmed \(\d+\)/, (m) => paint(m, P.red, true))
|
|
865
|
-
.replace(/Quick start( \(skills\))?/, (m) => paint(m, P.light, true));
|
|
866
|
-
}
|
|
867
|
-
let l = line
|
|
868
|
-
.replace(/^(critical|high)(?= )/, (m) => paint(m, P.red, true))
|
|
869
|
-
.replace(/^medium(?= )/, (m) => paint(m, P.light))
|
|
870
|
-
.replace(/^low(?= )/, (m) => paint(m, P.steel))
|
|
871
|
-
.replace(/(\d+) (critical|high)\b/g, (m) => paint(m, P.red))
|
|
872
|
-
.replace(/\b([1-9]\d*) confirmed\b/, (m) => paint(m, P.red, true))
|
|
873
|
-
.replace(/\b0 confirmed\b/, (m) => paint(m, P.green))
|
|
874
|
-
.replace(/coverage \d+%( \(\d+\/\d+\))?/, (m) => paint(m, P.green))
|
|
875
|
-
.replace(/((?:\/skill:|\/|\$)bravos(?:-[a-z]+)?)(\s+)([^\x1b]+)$/, (_m, cmd, sp, hint) => `${paint(cmd, P.green)}${sp}${paint(hint, P.steel)}`)
|
|
876
|
-
.replace(/(?<![\w/$:-])((?:\/skill:|\/|\$)bravos(?:-[a-z]+)?)(?![\w-])(?![^\x1b]*\x1b\[0m)/g, (m) => paint(m, P.green));
|
|
877
|
-
if (/^(Start with|Hide this|bravos makes|the code, proves)/.test(line)) {
|
|
878
|
-
l = line.split(/((?:\/skill:|\/|\$)bravos-[a-z]+)/).map((part, k) => (k % 2 ? paint(part, P.green) : part ? paint(part, P.steel) : '')).join('');
|
|
879
|
-
}
|
|
880
|
-
return l;
|
|
909
|
+
// @comment -- "Applies theme colours to a finished plain-text layout. Each run of wordmark cells uses one escape. The supplied Bravos symbol, headings, severity and executable commands stay readable with colour disabled."
|
|
910
|
+
export function colorize(lines, _inputs = {}, theme = 'dark') {
|
|
911
|
+
const p = THEMES[theme] ?? THEMES.neutral;
|
|
912
|
+
// One pass over plain text; never run another replacement over terminal escapes.
|
|
913
|
+
const token = /[█▄▀]+(?: +[█▄▀]+)*|[╗╔╝╚═║]+(?: +[╗╔╝╚═║]+)*|[─│]+|\b\d+ CONFIRMED FINDINGS?\b|#[-\w]+|\b(?:\d+ )?(?:critical|high)\b|\b\d+% annotation coverage|\bSETUP\b|\bBRAVOS\b|by bugb|(?:\/skill:|\/|\$)?bravos-[\w-]+|\bbravos (?:dashboard|next|guide|doctor|sync|account activate|licence)\b/g;
|
|
914
|
+
return lines.map((line) => {
|
|
915
|
+
if (/^! /.test(line)) return paint(line, p.red, true);
|
|
916
|
+
if (/^~ /.test(line)) return paint(line, p.steel);
|
|
917
|
+
return line.replace(token, (word) => {
|
|
918
|
+
if (/^[╗╔╝╚═║]/.test(word)) return paint(word, p.blue);
|
|
919
|
+
if (/^[─│]/.test(word)) return paint(word, p.line);
|
|
920
|
+
if (/^(#|[1-9]\d* CONFIRMED)|\b(critical|high)$/.test(word)) return paint(word, p.red);
|
|
921
|
+
if (word === 'by bugb' || word.startsWith('0 CONFIRMED')) return paint(word, p.steel);
|
|
922
|
+
return paint(word, p.green);
|
|
923
|
+
});
|
|
881
924
|
});
|
|
882
925
|
}
|