@bugb-technologies/bravos 1.17.2 → 1.19.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.
@@ -1,9 +1,11 @@
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, whose briefing also asks the agent to open its first reply with the banner as a text card, since Codex folds a hook's message away as a warning). With --harness agy it prints Antigravity's injectSteps instead. Always exits 0 so a session never fails to start."
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; for Codex, which draws it inline with the first prompt, the Bravos card uncoloured; for Gemini, uncoloured). With --harness agy it prints Antigravity's injectSteps instead; with --harness cursor, Cursor's { additional_context }, whose briefing asks the agent to open its first reply with the Bravos card, since Cursor shows a hook's output to nobody but the model. Always exits 0 so a session never fails to start."
2
2
  import { closeSync, existsSync, openSync, realpathSync } from 'node:fs';
3
3
  import { WriteStream } from 'node:tty';
4
4
  import { dirname, join } from 'node:path';
5
5
  import { fileURLToPath } from 'node:url';
6
- import { autopilotRegistered, buildBanner, buildBriefing, buildSummary, collect, firstReplyStatus, readVersion, sessionHookRegistered } from './lib/briefing.mjs';
6
+ import { autopilotRegistered, buildBanner, buildBriefing, collect, firstReplyStatus, inviteBriefing, inviteCard, readVersion, sessionHookRegistered, statusCard } from './lib/briefing.mjs';
7
+ import { audience, inviteAllowed } from './lib/audience.mjs';
8
+ import { displayMode } from './lib/display.mjs';
7
9
  import { resolveTheme } from './lib/palette.mjs';
8
10
  import { startGraphBuild } from './lib/graph-autobuild.mjs';
9
11
  import { takeSnapshot } from './lib/snapshot.mjs';
@@ -33,7 +35,7 @@ async function readPayload() {
33
35
  function harnessArg(argv, env) {
34
36
  const i = argv.indexOf('--harness');
35
37
  const v = i === -1 ? null : argv[i + 1];
36
- if (v === 'claude' || v === 'codex' || v === 'omp' || v === 'agy') return v;
38
+ if (v === 'claude' || v === 'codex' || v === 'omp' || v === 'agy' || v === 'cursor' || v === 'gemini') return v;
37
39
  return env.CLAUDE_PROJECT_DIR ? 'claude' : 'other';
38
40
  }
39
41
 
@@ -71,10 +73,18 @@ async function main() {
71
73
  const env = process.env;
72
74
  const harness = harnessArg(process.argv, env);
73
75
  if (process.argv.includes('--briefing')) {
74
- // Plain text for an agent whose harness ran no hook: no JSON to parse, no banner to read past.
76
+ // Plain text for an agent whose harness ran no hook (an instruction file or a skill runs it): no JSON to parse,
77
+ // no banner to read past. Nothing drew the card for the person, so the agent is asked to show it.
75
78
  let t;
76
79
  try {
77
- t = buildBriefing(await collect(env.CLAUDE_PROJECT_DIR || process.cwd(), env));
80
+ const root = env.CLAUDE_PROJECT_DIR || process.cwd();
81
+ if (audience(env).kind === 'none') {
82
+ t = inviteAllowed(root, gitCommonDir(root, env), env) ? inviteBriefing(inviteCard(root)) : 'Bravos: this repository uses Bravos, but this machine does not have it installed; no security briefing runs here.';
83
+ } else {
84
+ const inputs = await collect(root, env);
85
+ const card = firstReplyStatus(inputs, { harness, env, version: readVersion(dirname(fileURLToPath(import.meta.url))) });
86
+ t = buildBriefing(inputs) + (card ? '\n' + card : '');
87
+ }
78
88
  } catch (e) {
79
89
  t = `bravos briefing failed: ${e instanceof Error ? e.message : String(e)}`;
80
90
  }
@@ -97,6 +107,15 @@ async function main() {
97
107
  // A copy of this hook that is not the project's own (the Claude Code or Codex plugin's) stays quiet where the
98
108
  // project registers its own: that one speaks, so the banner and the briefing never arrive twice.
99
109
  if (!ownCopy(root) && existsSync(join(root, '.bravos', 'hooks', 'session-start.mjs')) && sessionHookRegistered(root, harness)) process.exit(0);
110
+ const mode = displayMode(harness, env);
111
+ // @comment -- "A machine without Bravos (a teammate who cloned a repository that uses it) gets the invitation and nothing else: no briefing, no snapshot, no graph build, no coach record, no update check. It is shown once per fresh session, on screen where this surface draws a hook's message and otherwise in the agent's first reply; the team can switch it off and the person can snooze it."
112
+ if (audience(env).kind === 'none') {
113
+ const fresh = source === null || source === 'startup';
114
+ if (!fresh || !inviteAllowed(root, gitCommonDir(root, env), env)) emit(harness, {}, '');
115
+ const card = inviteCard(root);
116
+ const onScreen = mode === 'banner' || mode === 'hook-card';
117
+ emit(harness, onScreen ? { systemMessage: mode === 'banner' ? '\n' + card : card } : {}, inviteBriefing(card, { shownOnScreen: onScreen }));
118
+ }
100
119
  // Where autopilot is on, record what the working tree held at the start, beside the briefing, so its
101
120
  // end-of-turn check judges only this session's changes (no autopilot, nothing written).
102
121
  const snap = autopilotRegistered(root) ? takeSnapshot(root, payload.session_id, { env }) : null;
@@ -112,23 +131,38 @@ async function main() {
112
131
  // @comment -- "Starts the daily check for a newer Bravos in a detached process (hooks/lib/update-check.mjs); this session never waits on it, and the next prompt's coach or the next session reads its answer."
113
132
  checkUpdates({ env });
114
133
  text = buildBriefing(inputs);
115
- // @comment -- "Codex shows the summary below only as a folded warning (F2) and no hook field prints to its transcript, so on a fresh start the briefing asks the agent to open its first reply with the banner as a text card."
116
- if (harness === 'codex') {
134
+ // @comment -- "Where this surface does not draw a hook's message (Cursor, Antigravity, Claude Code's desktop app and IDE extensions: hooks/lib/display.mjs), the briefing asks the agent to open its first reply with the Bravos card."
135
+ if (mode === 'reply') {
117
136
  const status = firstReplyStatus(inputs, { harness, env, version: readVersion(dirname(fileURLToPath(import.meta.url))) });
118
137
  if (status) text += '\n' + status;
119
138
  }
120
- if (env.BRAVOS_BANNER !== 'off' && (source === null || source === 'startup') && harness !== 'agy') {
139
+ if (env.BRAVOS_BANNER !== 'off' && (source === null || source === 'startup') && mode !== 'reply') {
121
140
  const version = readVersion(dirname(fileURLToPath(import.meta.url)));
122
- const color = !env.NO_COLOR && env.BRAVOS_BANNER_COLOR !== 'off';
141
+ // Gemini and Codex draw a hook's message as plain text, so they get no colour codes.
142
+ const color = !env.NO_COLOR && env.BRAVOS_BANNER_COLOR !== 'off' && harness !== 'gemini' && harness !== 'codex';
123
143
  // Which palette: BRAVOS_THEME, COLORFGBG, the choice saved by bravos setup, else neutral (hooks/lib/palette.mjs).
124
144
  const { theme } = resolveTheme(env);
125
- // Codex lists a hook's message as a warning, so it gets a three-line summary, not the art.
145
+ // @comment -- "Codex draws a hook's message inline as '↳ Hook ·' when the first prompt is sent, so it gets the Bravos card (the banner without the logo art), exact and uncoloured, and the agent is not asked to repeat it."
126
146
  // The leading newline puts the logo on its own lines: Claude Code prefixes the first line with "SessionStart:startup says:".
127
- out.systemMessage = harness === 'codex' ? buildSummary(inputs, { harness, version }) : '\n' + buildBanner(inputs, { harness, version, color, theme, columns: terminalColumns(env) });
147
+ out.systemMessage = mode === 'hook-card' ? statusCard(inputs, { harness, version }) : '\n' + buildBanner(inputs, { harness, version, color, theme, columns: terminalColumns(env) });
128
148
  }
129
149
  } catch (e) {
130
150
  text = `bravos briefing failed: ${e instanceof Error ? e.message : String(e)}`;
131
151
  }
152
+ emit(harness, out, text);
153
+ }
154
+
155
+ // @comment -- "Prints the session-start answer in the shape each agent reads and exits 0: Cursor's { additional_context }, Antigravity's injectSteps, otherwise { systemMessage?, hookSpecificOutput.additionalContext }. An empty text with nothing to show prints an empty object, so the agent gets nothing."
156
+ function emit(harness, out, text) {
157
+ if (!text && !out.systemMessage) {
158
+ process.stdout.write('{}\n');
159
+ process.exit(0);
160
+ }
161
+ if (harness === 'cursor') {
162
+ // Cursor's sessionStart output: additional_context reaches the model; nothing is shown to the person.
163
+ process.stdout.write(JSON.stringify({ additional_context: text }) + '\n');
164
+ process.exit(0);
165
+ }
132
166
  if (harness === 'agy') {
133
167
  // Antigravity's SessionStart output: steps injected before the first model call.
134
168
  process.stdout.write(JSON.stringify({ injectSteps: [{ systemMessage: text, metadata: { source: 'bravos' } }] }) + '\n');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bugb-technologies/bravos",
3
- "version": "1.17.2",
3
+ "version": "1.19.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",
@@ -1,5 +1,5 @@
1
1
  // bravos (managed by bravos init/sync; edits are kept, bravos sync --force replaces them)
2
- // @comment -- "omp extension: omp runs no Claude Code or Codex hooks, so this does bravos's session start itself. On session_start it runs the repo's .bravos/hooks briefing code in-process (read-only guardlink, git and gh facts), shows the banner as a widget above the editor, and on the first prompt removes the widget and hands the briefing to the model as a hidden custom message. Never throws into omp."
2
+ // @comment -- "omp extension: omp runs no Claude Code or Codex hooks, so this does bravos's session start itself. On session_start it runs the repo's .bravos/hooks briefing code in-process (read-only guardlink, git and gh facts), shows the banner as a widget above the editor, and on the first prompt removes the widget and hands the briefing to the model as a hidden custom message. On a machine without Bravos (hooks/lib/audience.mjs) it shows the invitation instead, and hands over only the invitation's instruction. Never throws into omp."
3
3
  import { join } from 'node:path';
4
4
  import { pathToFileURL } from 'node:url';
5
5
 
@@ -10,6 +10,14 @@ export default function bravos(pi) {
10
10
  const load = (cwd) => {
11
11
  pending ??= (async () => {
12
12
  const lib = await import(pathToFileURL(join(cwd, '.bravos', 'hooks', 'lib', 'briefing.mjs')).href);
13
+ // A machine without Bravos gets the invitation, shown in the widget, and nothing else (an older install has no audience.mjs).
14
+ const aud = await import(pathToFileURL(join(cwd, '.bravos', 'hooks', 'lib', 'audience.mjs')).href).catch(() => null);
15
+ if (aud && aud.audience(process.env).kind === 'none') {
16
+ const prefs = await import(pathToFileURL(join(cwd, '.bravos', 'hooks', 'lib', 'prefs.mjs')).href);
17
+ if (!aud.inviteAllowed(cwd, prefs.gitCommonDir(cwd, process.env), process.env)) return { briefing: null, banner: null };
18
+ const card = lib.inviteCard(cwd);
19
+ return { briefing: lib.inviteBriefing(card, { shownOnScreen: true }), banner: card };
20
+ }
13
21
  const inputs = await lib.collect(cwd, process.env);
14
22
  // The palette for this terminal's background (an older install has no palette.mjs: dark, as before).
15
23
  const theme = await import(pathToFileURL(join(cwd, '.bravos', 'hooks', 'lib', 'palette.mjs')).href)
@@ -62,6 +70,7 @@ export default function bravos(pi) {
62
70
  delivered = true;
63
71
  const { briefing } = await load(ctx.cwd);
64
72
  widget(ctx, undefined);
73
+ if (!briefing) return undefined;
65
74
  return { message: { customType: 'bravos-briefing', content: briefing, display: false } };
66
75
  });
67
76
  }
@@ -1,5 +1,5 @@
1
1
  // bravos (managed by bravos init/sync; edits are kept, bravos sync --force replaces them)
2
- // @comment -- "opencode 2.x plugin (default export { id, setup }): opencode runs no Claude Code or Codex hooks, so this does bravos's session start itself. setup() runs the repo's .bravos/hooks briefing code in-process (read-only guardlink, git and gh facts) and registers session hooks that append the briefing to the system prompt of each model request and of compaction. Never throws into opencode."
2
+ // @comment -- "opencode 2.x plugin (default export { id, setup }): opencode runs no Claude Code or Codex hooks, so this does bravos's session start itself. setup() runs the repo's .bravos/hooks briefing code in-process (read-only guardlink, git and gh facts) and registers session hooks that append the briefing to the system prompt of each model request and of compaction. Each model request also carries the Bravos card with the instruction to open the agent's first reply with it, once (opencode's plugin can draw nothing in the transcript itself); compaction gets the briefing only. On a machine without Bravos (hooks/lib/audience.mjs) the requests carry only the invitation and its instruction, and compaction nothing. Never throws into opencode."
3
3
  import { join } from 'node:path';
4
4
  import { pathToFileURL } from 'node:url';
5
5
 
@@ -8,22 +8,35 @@ export default {
8
8
  setup: async (api) => {
9
9
  const root = api?.location?.directory ?? process.cwd();
10
10
  let briefing = null;
11
+ let card = null;
11
12
  const ready = (async () => {
12
13
  try {
13
14
  const lib = await import(pathToFileURL(join(root, '.bravos', 'hooks', 'lib', 'briefing.mjs')).href);
14
- briefing = lib.buildBriefing(await lib.collect(root, process.env));
15
+ // A machine without Bravos gets the invitation and nothing else (an older install has no audience.mjs).
16
+ const aud = await import(pathToFileURL(join(root, '.bravos', 'hooks', 'lib', 'audience.mjs')).href).catch(() => null);
17
+ if (aud && aud.audience(process.env).kind === 'none') {
18
+ const prefs = await import(pathToFileURL(join(root, '.bravos', 'hooks', 'lib', 'prefs.mjs')).href);
19
+ if (aud.inviteAllowed(root, prefs.gitCommonDir(root, process.env), process.env)) card = lib.inviteBriefing(lib.inviteCard(root));
20
+ return;
21
+ }
22
+ const inputs = await lib.collect(root, process.env);
23
+ briefing = lib.buildBriefing(inputs);
24
+ // An older .bravos/hooks copy has no card yet; the briefing still goes in.
25
+ card = typeof lib.firstReplyStatus === 'function' ? lib.firstReplyStatus(inputs, { harness: 'opencode', env: process.env }) : null;
15
26
  } catch (e) {
16
27
  briefing = `bravos briefing failed: ${e instanceof Error ? e.message : String(e)}`;
17
28
  }
18
29
  })();
19
- const add = async (request) => {
30
+ const add = (withCard) => async (request) => {
20
31
  await ready;
21
- if (briefing && Array.isArray(request?.system)) request.system.push({ type: 'text', text: briefing });
32
+ // Without Bravos there is no briefing: the requests carry only the invitation (card), and compaction nothing.
33
+ const text = briefing ? (withCard && card ? `${briefing}\n${card}` : briefing) : withCard ? card : null;
34
+ if (text && Array.isArray(request?.system)) request.system.push({ type: 'text', text });
22
35
  };
23
36
  const handles = [];
24
- for (const name of ['context', 'compaction']) {
37
+ for (const [name, withCard] of [['context', true], ['compaction', false]]) {
25
38
  try {
26
- handles.push(await api.session.hook(name, add));
39
+ handles.push(await api.session.hook(name, add(withCard)));
27
40
  } catch {
28
41
  /* this opencode has no such hook */
29
42
  }