@bugb-technologies/bravos 1.6.0 → 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/watch.js CHANGED
@@ -9,9 +9,9 @@ import { openInBrowser } from './open.js';
9
9
  import { hooksDir, version } from './paths.js';
10
10
  import { readAllAnswers, readDraft } from './review.js';
11
11
  import { listReports, readMeta, reportDir } from './report/meta.js';
12
- import { renderFrame } from './watch-frame.js';
12
+ import { activityOverlay, renderFrame } from './watch-frame.js';
13
13
  import { nextTheme, themeFromBackground } from './palette.js';
14
- export { buildFrame, layoutFor, renderFrame, tailPath } from './watch-frame.js';
14
+ export { activityOverlay, buildFrame, layoutFor, renderFrame, tailPath } from './watch-frame.js';
15
15
  // @comment -- "bravos watch: a live, read-only, zero-token terminal view of a repository's security work, beside any harness. snapshot() gathers what the briefing gathers (guardlink ci, hypothesis next, tickets, git, gh, intent, proving, SAST, setup) plus the hypothesis and boundary ledgers, the model's size, review answers, branch state and the code graph's own answers; diffSnapshots() turns two snapshots into activity events in memory; watch-frame.ts draws them; handleKey() maps keys to read-only actions. Nothing here writes to the repository."
16
16
  export const WATCH_SCHEMA = 'bravos.watch/v1';
17
17
  // @comment -- "The newest report's summary for watch, from meta.json only (title, kind, check verdict and counts, exported formats) plus how many commits HEAD has moved since its evidence was gathered; null with no report. Read-only."
@@ -468,6 +468,16 @@ export function readAutopilotEvents(root) {
468
468
  }
469
469
  return out;
470
470
  }
471
+ /** Resume by event identity because the rolling log stays at 500 rows while it gains new events. */
472
+ export function newAutopilotEvents(log, last) {
473
+ if (last) {
474
+ for (let i = log.length - 1; i >= 0; i--) {
475
+ if (log[i].at === last.at && log[i].text === last.text)
476
+ return log.slice(i + 1);
477
+ }
478
+ }
479
+ return log;
480
+ }
471
481
  /* ------------------------------------------------------------------ keys */
472
482
  // @comment -- "The recorded intent for the i overlay: .guardlink/intent.md as written, under a line naming who answered the review; when there is none, how to create it. Read-only."
473
483
  export function intentOverlay(root) {
@@ -580,7 +590,7 @@ export function graphAnswer(status, stdout, failure = '') {
580
590
  }
581
591
  return [`no answer${failure ? `: ${failure}` : status !== null ? ` (exit ${status})` : ''}`];
582
592
  }
583
- // @comment -- "Maps one key to a read-only action: copy the next command, open the intent review or the dashboard (bravos dashboard, written outside the repository), ask the graph, show test-next, the recorded intent or the guide, scroll, refresh everything now, or quit; anything else does nothing."
593
+ // @comment -- "Maps one key to a read-only action: copy the next command, open the intent review or the dashboard (bravos dashboard, written outside the repository), ask the graph, show full retained activity, test-next, the recorded intent or the guide, scroll, refresh everything now, or quit; anything else does nothing."
584
594
  export function handleKey(key, sn, root = '.') {
585
595
  switch (key) {
586
596
  case 'n':
@@ -594,6 +604,8 @@ export function handleKey(key, sn, root = '.') {
594
604
  }
595
605
  case 'g':
596
606
  return { kind: 'overlay', what: 'graph' };
607
+ case 'a':
608
+ return { kind: 'overlay', what: 'activity' };
597
609
  case 't':
598
610
  return { kind: 'overlay', what: 'next' };
599
611
  case 'p':
@@ -705,7 +717,7 @@ export async function runWatch(root, env, opts) {
705
717
  let note = '';
706
718
  let overlay = null;
707
719
  let overlayScroll = 0;
708
- let seenAutopilot = 0;
720
+ let lastAutopilot;
709
721
  let graphPrompt = null;
710
722
  let scroll = 0;
711
723
  let maxScroll = 0;
@@ -755,9 +767,9 @@ export async function runWatch(root, env, opts) {
755
767
  lastGraph = Date.now();
756
768
  events.push(...diffSnapshots(sn, next));
757
769
  const auto = readAutopilotEvents(root);
758
- if (auto.length > seenAutopilot)
759
- events.push(...auto.slice(seenAutopilot));
760
- seenAutopilot = auto.length;
770
+ events.push(...newAutopilotEvents(auto, lastAutopilot));
771
+ if (auto.length)
772
+ lastAutopilot = auto.at(-1);
761
773
  if (events.length > 50)
762
774
  events.splice(0, events.length - 50);
763
775
  history.push({ at: next.at, open: next.counts?.open ?? null, coverage: next.coverage?.percent ?? null });
@@ -897,6 +909,8 @@ export async function runWatch(root, env, opts) {
897
909
  overlayScroll = 0;
898
910
  if (a.what === 'graph')
899
911
  graphPrompt = '';
912
+ else if (a.what === 'activity')
913
+ overlay = activityOverlay(events);
900
914
  else if (a.what === 'intent')
901
915
  overlay = intentOverlay(root);
902
916
  else if (a.what === 'report')
package/docs/GUIDE.md CHANGED
@@ -40,7 +40,7 @@ Run bravos next in a shell (free): it shows which of the nine steps are done her
40
40
 
41
41
  Or just ask the agent "help me get started" (or run /bravos, $bravos in Codex): it gives a short tour fitted to this repo. BRAVOS_COACH=off stops the coaching; the Setup line stays.
42
42
 
43
- Keep bravos watch running in a second terminal pane beside your agent (free, read-only, no model): the setup score, open and confirmed exposures, what to test next, stale claims and autopilot nudges, redrawn within seconds of a change. It also shows the hypothesis ledger, boundaries, the model's size, the code graph's call resolution and entry points, and the branch's commits. Keys: n copies the next command, r opens the intent review, d the dashboard (bravos dashboard), g asks the code graph, t shows test-next, i shows the recorded intent, u refreshes now, j and k scroll, q quits. Three columns from 150 wide, two from 110, one in an 80-column split.
43
+ Keep bravos watch running in a second terminal pane beside your agent (free, read-only, no model): the setup score, open and confirmed exposures, what to test next, stale claims and autopilot nudges, redrawn within seconds of a change. It also shows the hypothesis ledger, boundaries, the model's size, the code graph's call resolution and entry points, and the branch's commits. Keys: n copies the next command, r opens the intent review, d the dashboard (bravos dashboard), g asks the code graph, t shows test-next, i shows the recorded intent, a opens the full text of retained activity, u refreshes now, j and k scroll, q quits. Three columns from 150 wide, two from 110, one in an 80-column split.
44
44
 
45
45
  ### Hands-off: autopilot
46
46
 
@@ -128,7 +128,7 @@ bravos-context assumes you are researching software you do not own (an open-sour
128
128
 
129
129
  Skills: `/bravos-context`
130
130
 
131
- bravos-context opens its questions as a bravos page (bravos review intent): pre-filled with bravos's suggestions and their sources; change what is wrong, make the calls marked 'needs your call' (Confirm stays off until you do), and the facts bravos drafted stay folded unless you open one to object. Each person's answers save to .guardlink/intent-answers/<name>.json; teammates run bravos review intent after pulling and commit theirs. bravos review intent --summary shows where people agree and disagree; only what a named person agreed to is marked confirmed. On Claude Code, --share puts the same page on a private claude.ai link instead.
131
+ bravos-context opens its questions as a bravos page (bravos review intent): pre-filled with bravos's suggestions and their sources; change what is wrong, make the calls marked 'needs your call' (Confirm stays off until you do), and the facts bravos drafted stay folded unless you open one to object. The role-by-action matrix links each documented permission to its question. In local reviews, open a cited SRC document to read its verified text. The saved HTML can contain these documents. Each person's answers save to .guardlink/intent-answers/<name>.json; teammates run bravos review intent after pulling and commit theirs. bravos review intent --summary shows where people agree and disagree; only what a named person agreed to is marked confirmed. On Claude Code, --share prepares an artifact with the draft and its citations. Publish that artifact to share it.
132
132
 
133
133
  ### I wrote security-relevant code
134
134
 
package/docs/UPGRADING.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  After `npm install -g @bugb-technologies/bravos`, run **`bravos setup --tools -y`** once on each machine and **`bravos sync`** in each repository. The notes below say what else changes, newest first.
4
4
 
5
+ ## 1.7.0
6
+
7
+ - **SessionStart** shows the Bravos mark, repository and branch, findings and next action in a terminal layout that adapts to the available width. Existing theme, plain-text and banner switches still apply.
8
+ - **`bravos watch`** gives setup and test outcomes segmented trackers alongside the existing metrics, panels and keyboard commands. Press `a` to read long activity entries and older events in the current session.
9
+ - **`bravos review intent`** opens a redesigned owner or researcher intake. Its perspective, sections and questions come from the draft. New drafts can describe a role and action on each documented permission. Select a matrix cell to review the full rule, its exceptions and sources. Existing drafts and named answer files still work. To add a matrix to an older draft, refresh its permission items with the context skill and keep their question IDs.
10
+ - Local reviews can show verified copies of cited design documents. A `--no-serve` HTML file can contain their full text. Use `--share` to prepare an artifact containing the draft and its citations, including anything quoted in the draft itself.
11
+ - Run `bravos sync` in each installed repository to refresh the startup hook and context skill.
12
+
5
13
  ## 1.6.0
6
14
 
7
15
  1.6 makes threat modelling start from your design. Bravos now asks for your design documents, keeps them in the repository, turns what they state into rules it can test, and shows which rules hold.
@@ -505,7 +505,6 @@ export async function collect(root, env, { deadlineMs = 20000, nextCount = 3 } =
505
505
  // Startup banner: shown to the human (systemMessage), never added to the model's context.
506
506
  // ---------------------------------------------------------------------------------------------
507
507
 
508
- const BANNER_WIDTH = 80;
509
508
  // A large shadowed wordmark, six rows, built letter by letter so every row has the same width.
510
509
  const GLYPHS = {
511
510
  B: ['██████╗ ', '██╔══██╗', '██████╔╝', '██╔══██╗', '██████╔╝', '╚═════╝ '],
@@ -516,7 +515,7 @@ const GLYPHS = {
516
515
  S: ['███████╗', '██╔════╝', '███████╗', '╚════██║', '███████║', '╚══════╝'],
517
516
  };
518
517
  export const LOGO = Array.from({ length: 6 }, (_, r) => [...'BRAVOS'].map((c) => GLYPHS[c][r]).join(''));
519
- const LOGO_WIDTH = Math.max(...LOGO.map((l) => [...l].length));
518
+
520
519
  // bravos's mascot: a hooded figure with two glowing eyes, eleven rows, left-right symmetric; ▓ is the hood, █ the eyes.
521
520
  export const MASCOT = [
522
521
  ' ▄▄▓▓▓▓▓▓▄▄ ',
@@ -531,8 +530,26 @@ export const MASCOT = [
531
530
  ' ▄▓▓▓▓▄▄▄▄▄▄▄▄▄▄▓▓▓▓▄ ',
532
531
  ' ▓▓▓▓▓▓▓▓ ▐ ▌ ▓▓▓▓▓▓▓▓ ',
533
532
  ];
534
- const MASCOT_WIDTH = 26;
535
- const LEFT_WIDTH = 36;
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
+ ];
536
553
  // Two lines, so the plan nudge below the counts has room. The pre-PR gate is named only to people who have it.
537
554
  const INTRO_HEAD = 'bravos makes this agent a guardlink power user: it keeps the threat model beside';
538
555
  const INTRO_TEAM = 'the code, proves exposures on targets you own, and gates pull requests.';
@@ -691,124 +708,180 @@ const TIPS = [
691
708
  ];
692
709
  const dayNumber = () => Math.floor(Date.now() / 86400000);
693
710
 
694
- function countsLine(g) {
711
+ function bannerMetrics(g) {
712
+ if (!g.ci) return null;
695
713
  const ci = g.ci;
696
- if (!ci) return 'threat counts unknown (guardlink ci unavailable)';
697
714
  const s = ci.summary ?? {};
698
715
  const list = arr(ci.exposures);
699
716
  const by = s.by_severity ?? Object.fromEntries(SEVERITIES.map((k) => [k, list.filter((e) => e?.severity === k).length]));
700
- const total = typeof s.exposures === 'number' ? s.exposures : list.length;
701
- const sev = SEVERITIES.filter((k) => num(by[k]) > 0).map((k) => `${num(by[k])} ${k}`);
702
- let line = `${total} open${sev.length ? ` (${sev.join(', ')})` : ''} · ${arr(ci.confirmed).length} confirmed`;
703
- if (s.coverage) line += ` · coverage ${num(s.coverage.percent)}% (${num(s.coverage.annotated_files)}/${num(s.coverage.source_files)})`;
704
- return line;
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
+ };
705
723
  }
706
724
 
707
- // @comment -- "The banner's one-line state: intent, code graph, the two hooks, SAST and the setup score. A locked code graph says locked, never on. The full wording is kept while it fits 80 columns; past that it shortens in steps (one word for both hooks when they agree, PR for pre-PR, reach. for reachable, then the bare count) so the line is never cut mid-word."
708
- function statusLine(i) {
709
- const intent = i.intent?.status ?? 'unknown';
710
- const graph = i.codegraph === 'unavailable' ? 'graph off' : i.codegraph === 'not-built' ? 'graph none' : i.codegraph === 'diverged' ? 'graph stale' : i.codegraph === 'locked' ? 'graph locked' : 'graph on';
711
- const setup = i.root ? readSetup(i.root, i, i.harness) : null;
712
- const hook = (on) => (!on ? 'off' : hooksLocked(i) ? 'locked' : 'on');
713
- const [pr, auto] = [hook(i.prePr), hook(i.autopilot)];
714
- const build = (level) => {
715
- const hooks = level >= 1 && pr === auto ? `hooks ${pr}` : `${level >= 2 ? 'PR' : 'pre-PR'} ${pr} · auto ${auto}`;
716
- 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';
717
- return `intent ${intent} · ${graph} · ${hooks} · ${sast}${setup ? ` · setup ${setup.done}/${setup.total}` : ''}`;
718
- };
719
- for (let level = 0; level < 4; level++) if (build(level).length <= BANNER_WIDTH) return build(level);
720
- 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)})` : '');
721
731
  }
722
732
 
723
- /**
724
- * Builds the startup banner for the human: logo, repo and counts, top threats (or FIX NOW) beside a
725
- * state-driven quick start, and a short introduction while the product's intent is not recorded.
726
- * Plain text, no ANSI; every line ≤ 80 columns; 35 lines at most with the introduction, 29 without.
727
- */
728
- // @comment -- "Pure text builder for the user-facing startup banner; reads only the inputs collect() already gathered, never throws on partial inputs."
729
- export function buildBanner(inputs, opts = {}) {
730
- const i = inputs ?? {};
731
- const harness = opts.harness ?? (i.harness === 'claude' ? 'claude' : 'other');
732
- // The mascot on the left; the wordmark beside its face, the repo facts beside its shoulders.
733
- const room = BANNER_WIDTH - MASCOT_WIDTH - 2;
734
- const facts = [
735
- [`bravos${opts.version ? ` ${opts.version}` : ''}`, i.repo].filter(Boolean).join(' · '),
736
- [i.branch, i.sha ? `@ ${i.sha}` : ''].filter(Boolean).join(' '),
737
- ];
738
- // The plan sits on the row between the wordmark and the repo facts, so it costs no line; nothing is shown while the licence is unknown.
739
- const plan = i.licence && typeof i.licence === 'object' && i.licence.state ? planLabel(i.licence) : null;
740
- const header = ['', '', ...LOGO, plan ? `Plan: ${plan.label}` : '', ...facts];
741
- const lines = MASCOT.map((row, r) => `${row} ${fit(header[r] ?? '', room)}`);
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
+ }
742
756
 
743
- if (i.guardlink === 'missing') {
744
- lines.push('', 'guardlink not found on PATH — run bravos doctor');
745
- const out = lines.map((l) => fit(l.trimEnd(), BANNER_WIDTH));
746
- return (opts.color ? colorize(out, i, opts.theme) : out).join('\n');
747
- }
748
- const g = i.guardlink ?? {};
749
- lines.push('', countsLine(g), statusLine(i));
750
- // 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 = [];
751
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`);
752
760
  else if (plan && !plan.licensed && i.licence.state === 'expired') lines.push(`~ licence expired: ${TEAM_ADDS} locked · bravos licence`);
753
761
  else if (plan && !plan.licensed) lines.push(`~ Team adds ${TEAM_ADDS} · bravos account activate`);
754
- if (i.stale) lines.push(`! ${i.branch ?? 'this checkout'} is ${i.stale.behind} behind ${i.base} · findings describe older code · bravos-resync`);
755
- else if (arr(i.stranded).length > 0) lines.push(`~ annotation work on ${i.stranded[0].branch} is not on ${i.base} · bravos-resync`);
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`);
756
764
  if (i.shadow) {
757
765
  lines.push(i.shadow.userNewer
758
766
  ? `~ repo bravos ${i.shadow.repo} is behind your ${i.shadow.user} · run: bravos sync`
759
767
  : `! your user-level bravos ${i.shadow.user} overrides repo ${i.shadow.repo} · run: bravos sync --global`);
760
768
  }
761
- lines.push('');
769
+ return lines;
770
+ }
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
+ }
762
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;
763
820
  const confirmed = arr(g.ci?.confirmed).slice().sort((a, b) => sevRank(a.severity) - sevRank(b.severity));
764
- let left;
765
- if (confirmed.length > 0) {
766
- left = [`FIX NOW — confirmed (${confirmed.length})`, ...confirmed.slice(0, 3).map((c) => {
767
- const { threat } = assetThreat(c);
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)) {
768
825
  const file = basename(String(c?.location?.file ?? c?.file ?? '?'));
769
- return `${threat} ${file}:${c?.location?.line ?? c?.line ?? '?'}`;
770
- })];
771
- } else if (!g.ci) {
772
- left = ['Top threats', 'unknown'];
773
- } 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');
774
832
  const top = topThreats(g.ci.exposures);
775
- // The count is kept and a long threat id is shortened, so the column never loses the ×n.
776
- const row = (t) => {
777
- const head = `${t.severity.padEnd(9)}`;
778
- const tail = ` ×${t.count}`;
779
- return head + fit(t.threat, BANNER_WIDTH - head.length - tail.length) + tail;
780
- };
781
- left = ['Top threats', ...(top.length ? top.map(row) : ['none open'])];
782
- }
783
- // By role and by task: the skill each starts with, in the harness's own syntax. Campaigns, the ship check and
784
- // the code graph are on the Team plan, so an unlicensed person is shown free skills in their place.
785
- const sk = (name) => (SIGIL[harness] ?? '') + name;
786
- const free = hooksLocked(i);
787
- const roles = [['developer', 'bravos-annotate'], ['security', 'bravos-prove'], ['team lead', free ? 'bravos-report' : 'bravos-campaign'], ['new here', 'bravos']];
788
- const tasks = free
789
- ? [['what next?', 'bravos'], ['app intent', 'bravos-context'], ['after a fix', 'bravos-recheck'], ['write it up', 'bravos-report']]
790
- : [['what next?', 'bravos'], ['before a PR', 'bravos-ship'], ['after a fix', 'bravos-recheck'], ['find routes', 'bravos-codegraph']];
791
- const head = lines.splice(0);
792
- lines.push('', 'If you are'.padEnd(LEFT_WIDTH) + 'To');
793
- for (let r = 0; r < roles.length; r++) {
794
- 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'));
795
845
  }
796
- const setup = i.root ? readSetup(i.root, i, harness) : null;
797
- // The next step with its command; the pointer to bravos next is dropped when the command is long.
798
- const nextFull = setup?.next ? `Next: ${setup.next.label} → ${setup.next.cta} · more: bravos next` : null;
799
- const nextLine = nextFull && nextFull.length > BANNER_WIDTH ? `Next: ${setup.next.label} → ${setup.next.cta}` : nextFull;
800
- lines.push('', fit(nextLine ?? `Tip: ${TIPS[(opts.day ?? dayNumber()) % TIPS.length]}`, BANNER_WIDTH));
801
- lines.push('Guide (free, no tokens): bravos guide · bravos guide roles · bravos guide tasks');
802
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));
803
880
  if (i.intent?.status === 'none') {
804
- lines.push('', INTRO_HEAD, free ? INTRO_FREE : INTRO_TEAM, `Start with the Next step above, or ask "help me get started" (${SIGIL[harness] ? `${SIGIL[harness]}bravos` : 'the bravos skill'}).`, 'Hide this banner with BRAVOS_BANNER=off.');
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));
805
883
  }
806
- // When notes above the threats push the banner past its cap, threat rows give way (one always stays),
807
- // so the Next and Guide lines are never the ones cut.
808
- const cap = i.intent?.status === 'none' ? 35 : 29;
809
- while (head.length + left.length + lines.length > cap && left.length > 2) left.pop();
810
- const out = [...head, ...left.map((row) => fit(row, BANNER_WIDTH)), ...lines].map((l) => fit(l.trimEnd(), BANNER_WIDTH)).slice(0, cap);
811
- return (opts.color ? colorize(out, i, opts.theme) : out).join('\n');
884
+ return render();
812
885
  }
813
886
 
814
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)."
@@ -833,74 +906,20 @@ const fg = (hex) => (hex ? `\x1b[38;2;${parseInt(hex.slice(1, 3), 16)};${parseIn
833
906
  const RESET = '\x1b[0m';
834
907
  export const paint = (text, hex, bold = false) => (hex || bold ? `${bold ? '\x1b[1m' : ''}${fg(hex)}${text}${RESET}` : text);
835
908
 
836
- // @comment -- "Colours banner lines with the theme's palette (dark, light or neutral): the mascot's hood in slate and steel with green eyes, the wordmark in green with a blue shadow, severities by weight (critical and high in red), skills in green, and supporting text in steel; pure string transform."
837
- export function colorize(lines, inputs = {}, theme = 'dark') {
838
- const P = THEMES[theme] ?? THEMES.neutral;
839
- // One escape per run of same-coloured characters, so the banner stays far inside the 10,000-character cap.
840
- const runs = (chars, colourOf) => {
841
- let out = '';
842
- let cur = null;
843
- let buf = '';
844
- const flush = () => {
845
- if (buf) out += cur ? paint(buf, cur) : buf;
846
- buf = '';
847
- };
848
- for (const c of chars) {
849
- const k = c === ' ' ? cur : colourOf(c);
850
- if (k !== cur) {
851
- flush();
852
- cur = k;
853
- }
854
- buf += c;
855
- }
856
- flush();
857
- return out;
858
- };
859
- const mascotColour = (c) => (c === '▓' ? P.slate : c === '▄' || c === '▀' ? P.steel : '█▐▌'.includes(c) ? P.green : null);
860
- const wordColour = (c) => (c === '█' ? P.green : '╗╔╝╚═║'.includes(c) ? P.blue : null);
861
- return lines.map((line, n) => {
862
- if (n < MASCOT.length) {
863
- const chars = [...line];
864
- const left = runs(chars.slice(0, MASCOT_WIDTH), mascotColour);
865
- const rest = chars.slice(MASCOT_WIDTH).join('');
866
- if (n >= 2 && n < 2 + LOGO.length) return left + runs([...rest], wordColour);
867
- if (n === MASCOT.length - 3) return left + rest.replace(/Plan: (.+)$/, (_m, label) => paint('Plan: ', P.steel) + paint(label, P.light, true));
868
- 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)}`);
869
- if (n === MASCOT.length - 1) return left + rest.replace(/\S.*$/, (m) => paint(m, P.steel));
870
- return left + rest;
871
- }
872
- 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));
873
- if (/^(developer|security|team lead|new here) /.test(line)) {
874
- return line.split(/((?:\/skill:|\/|\$)?bravos(?:-[a-z]+)?(?= |$))/).map((part, k) => (k % 2 ? paint(part, P.green) : part)).join('');
875
- }
876
- if (/^! your user-level bravos/.test(line)) return paint(line, P.red, true);
877
- if (/^~ (repo bravos |Team adds |licence expired)/.test(line)) return paint(line, P.steel);
878
- if (/^Tip: /.test(line)) return paint('Tip: ', P.green, true) + paint(line.slice(5), P.light);
879
- if (/^Next: /.test(line)) {
880
- const [what, rest = ''] = line.slice(6).split(' → ');
881
- const [cta, tailText] = rest.split(' · more: ');
882
- return paint('Next: ', P.green, true) + paint(what, P.light) + (cta ? ` → ${paint(cta, P.green)}` : '') + (tailText !== undefined ? ` · more: ${paint(tailText, P.green)}` : '');
883
- }
884
- 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));
885
- if (/^(Top threats|FIX NOW)/.test(line)) {
886
- return line
887
- .replace(/^Top threats/, paint('Top threats', P.light, true))
888
- .replace(/^FIX NOW — confirmed \(\d+\)/, (m) => paint(m, P.red, true))
889
- .replace(/Quick start( \(skills\))?/, (m) => paint(m, P.light, true));
890
- }
891
- let l = line
892
- .replace(/^(critical|high)(?= )/, (m) => paint(m, P.red, true))
893
- .replace(/^medium(?= )/, (m) => paint(m, P.light))
894
- .replace(/^low(?= )/, (m) => paint(m, P.steel))
895
- .replace(/(\d+) (critical|high)\b/g, (m) => paint(m, P.red))
896
- .replace(/\b([1-9]\d*) confirmed\b/, (m) => paint(m, P.red, true))
897
- .replace(/\b0 confirmed\b/, (m) => paint(m, P.green))
898
- .replace(/coverage \d+%( \(\d+\/\d+\))?/, (m) => paint(m, P.green))
899
- .replace(/((?:\/skill:|\/|\$)bravos(?:-[a-z]+)?)(\s+)([^\x1b]+)$/, (_m, cmd, sp, hint) => `${paint(cmd, P.green)}${sp}${paint(hint, P.steel)}`)
900
- .replace(/(?<![\w/$:-])((?:\/skill:|\/|\$)bravos(?:-[a-z]+)?)(?![\w-])(?![^\x1b]*\x1b\[0m)/g, (m) => paint(m, P.green));
901
- if (/^(Start with|Hide this|bravos makes|the code, proves)/.test(line)) {
902
- l = line.split(/((?:\/skill:|\/|\$)bravos-[a-z]+)/).map((part, k) => (k % 2 ? paint(part, P.green) : part ? paint(part, P.steel) : '')).join('');
903
- }
904
- 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
+ });
905
924
  });
906
925
  }
@@ -22,17 +22,17 @@ export const THEMES = {
22
22
  // The original palette: for dark terminals.
23
23
  dark: {
24
24
  green: '#33d49d', blue: '#0360a2', light: '#f0f0f0', steel: '#55899e', red: '#ea1d1d',
25
- slate: '#3b6779', amber: '#f0b429', line: '#2b4f5c',
25
+ slate: '#3b6779', amber: '#f0b429', line: '#2b4f5c', warm: '#ff9f5b', cool: '#51b2a9',
26
26
  },
27
27
  // For light terminals: every text colour at least 4.5:1 on white; borders 3:1.
28
28
  light: {
29
29
  green: '#0f7a55', blue: '#0360a2', light: null, steel: '#3f6576', red: '#c41616',
30
- slate: '#4d6b78', amber: '#9a6400', line: '#7d98a3',
30
+ slate: '#4d6b78', amber: '#9a6400', line: '#7d98a3', warm: '#88441d', cool: '#006c67',
31
31
  },
32
32
  // When the background is unknown: at least 3:1 on white and on black.
33
33
  neutral: {
34
34
  green: '#1e9a6c', blue: '#2f7fc1', light: null, steel: '#4f8296', red: '#e02424',
35
- slate: '#5a7d8b', amber: '#b07a00', line: '#5a7d8b',
35
+ slate: '#5a7d8b', amber: '#b07a00', line: '#5a7d8b', warm: '#ad6131', cool: '#2c8980',
36
36
  },
37
37
  };
38
38
 
@@ -40,7 +40,7 @@ export const THEMES = {
40
40
  // deeper than the dark theme's text red so white on it keeps 4.5:1 (CRIT, HIGH).
41
41
  export const FIXED = {
42
42
  green: '#33d49d', blue: '#0360a2', light: '#f0f0f0', steel: '#55899e', red: '#dc1f1f',
43
- slate: '#3b6779', amber: '#f0b429', line: '#2b4f5c', ink: '#0e1b21', deep: '#1f3943', white: '#ffffff',
43
+ slate: '#3b6779', amber: '#f0b429', line: '#2b4f5c', warm: '#ff9f5b', cool: '#51b2a9', ink: '#0e1b21', deep: '#1f3943', white: '#ffffff',
44
44
  };
45
45
 
46
46
  export const THEME_NAMES = ['dark', 'light', 'neutral'];
@@ -1,5 +1,6 @@
1
1
  // @comment -- "SessionStart hook entry (--global: the user-level copy, silent where the repo has its own bravos hook or no .guardlink/; --briefing prints only the briefing text, for a skill that runs it by hand): reads the hook payload from stdin (bounded wait, bad input ignored; source, and Antigravity's workspacePaths), awaits collect() (read-only guardlink, git and gh facts under a shared 20 s deadline) and, where autopilot is registered, the session-start snapshot of the working tree (.bravos/watch/turn-base), and prints one JSON envelope: the briefing as additionalContext for the model, plus on a fresh start a banner as systemMessage for the human (brand-coloured; a three-line summary for Codex). With --harness agy it prints Antigravity's injectSteps instead. Always exits 0 so a session never fails to start."
2
- import { existsSync, realpathSync } from 'node:fs';
2
+ import { closeSync, existsSync, openSync, realpathSync } from 'node:fs';
3
+ import { WriteStream } from 'node:tty';
3
4
  import { dirname, join } from 'node:path';
4
5
  import { fileURLToPath } from 'node:url';
5
6
  import { autopilotRegistered, buildBanner, buildBriefing, buildSummary, collect, readVersion, sessionHookRegistered } from './lib/briefing.mjs';
@@ -41,6 +42,27 @@ function ownCopy(root) {
41
42
  }
42
43
  }
43
44
 
45
+ // @comment -- "Determines the human terminal's columns even when hook stdout carries piped JSON: use a known stream width or COLUMNS, then the process's own controlling terminal. Opens only a fixed OS device, never writes; if no terminal is attached the hook uses its 80-column layout."
46
+ function terminalColumns(env) {
47
+ const columns = process.stdout.columns || process.stderr.columns || Number(env.COLUMNS);
48
+ if (Number.isSafeInteger(columns) && columns > 0) return columns;
49
+ let fd;
50
+ try {
51
+ fd = openSync(process.platform === 'win32' ? 'CONOUT$' : '/dev/tty', 'r+');
52
+ const tty = new WriteStream(fd);
53
+ fd = undefined; // The stream now owns the descriptor.
54
+ try {
55
+ return tty.getWindowSize()[0];
56
+ } finally {
57
+ tty.destroy();
58
+ }
59
+ } catch {
60
+ return 80;
61
+ } finally {
62
+ if (fd !== undefined) closeSync(fd);
63
+ }
64
+ }
65
+
44
66
  async function main() {
45
67
  const env = process.env;
46
68
  const harness = harnessArg(process.argv, env);
@@ -83,7 +105,7 @@ async function main() {
83
105
  const { theme } = resolveTheme(env);
84
106
  // Codex lists a hook's message as a warning, so it gets a three-line summary, not the art.
85
107
  // The leading newline puts the logo on its own lines: Claude Code prefixes the first line with "SessionStart:startup says:".
86
- out.systemMessage = harness === 'codex' ? buildSummary(inputs, { harness, version }) : '\n' + buildBanner(inputs, { harness, version, color, theme });
108
+ out.systemMessage = harness === 'codex' ? buildSummary(inputs, { harness, version }) : '\n' + buildBanner(inputs, { harness, version, color, theme, columns: terminalColumns(env) });
87
109
  }
88
110
  } catch (e) {
89
111
  text = `bravos briefing failed: ${e instanceof Error ? e.message : String(e)}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bugb-technologies/bravos",
3
- "version": "1.6.0",
3
+ "version": "1.7.0",
4
4
  "description": "Skills pack and installer that make Claude Code and Codex power users of guardlink (threat-model-as-code) and cert-x-gen (pentest-as-code).",
5
5
  "keywords": [
6
6
  "security",