@bugb-technologies/bravos 1.18.0 → 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.
- package/dist/cli.js +9 -1
- package/dist/cursor.js +4 -2
- package/dist/guide.js +2 -0
- package/dist/instruction-blocks.js +256 -0
- package/dist/uninstall.js +9 -2
- package/docs/GUIDE.md +6 -0
- package/docs/UPGRADING.md +24 -0
- package/hooks/autopilot.mjs +2 -1
- package/hooks/cards.mjs +3 -0
- package/hooks/coach.mjs +3 -0
- package/hooks/invite.mjs +10 -0
- package/hooks/lib/audience.mjs +83 -0
- package/hooks/lib/briefing.mjs +57 -0
- package/hooks/lib/display.mjs +11 -0
- package/hooks/pre-pr.mjs +3 -0
- package/hooks/session-start.mjs +35 -7
- package/package.json +1 -1
- package/templates/omp/bravos.js +10 -1
- package/templates/opencode/bravos.js +11 -2
package/dist/cli.js
CHANGED
|
@@ -8,6 +8,7 @@ import { DOCTOR_HELP, INIT_HELP, PROGRAM_HELP, SYNC_HELP } from './help.js';
|
|
|
8
8
|
import { Command, CommanderError, InvalidArgumentError, Option } from 'commander';
|
|
9
9
|
import { CADENCES, CRON, WORKFLOW_NAMES, writeWorkflows } from './ci.js';
|
|
10
10
|
import { CURSOR_RULE_PATH, cursorHookRegistered, writeCursorHooks, writeCursorPointer } from './cursor.js';
|
|
11
|
+
import { writeInstructionBlocks } from './instruction-blocks.js';
|
|
11
12
|
import { OMP_EXTENSION_PATH, writeOmpExtension } from './omp.js';
|
|
12
13
|
import { homeOf, installGlobal } from './global.js';
|
|
13
14
|
import { uninstall } from './uninstall.js';
|
|
@@ -255,6 +256,10 @@ function pipeline(root, io, opts, withGuardlink, lines) {
|
|
|
255
256
|
lines.push(`Cursor: ${cursor.path} not written — no skills root was installed for it to point at`);
|
|
256
257
|
else if (cursor.status !== 'absent')
|
|
257
258
|
lines.push(`Cursor: ${cursor.path} ${cursor.status}`);
|
|
259
|
+
// @comment -- "The Bravos block in the instruction files every agent reads (AGENTS.md, CLAUDE.md, GEMINI.md, Copilot's, Windsurf's rule), for agents and surfaces with no hook or whose hook output may not show. Each file is written under its own condition; with an explicit --agent only the files its agents read (and those no --agent can name), and upkeep refreshes a block already there."
|
|
260
|
+
const blocks = writeInstructionBlocks(root, { harnesses, agents: explicit ? opts.agent : undefined, refreshOnly: opts.refreshOnly, dryRun, force: opts.force });
|
|
261
|
+
for (const b of blocks)
|
|
262
|
+
lines.push(b.status === 'skipped' ? `Instructions: skipped ${b.path} — ${b.reason}` : `Instructions: ${b.path} ${b.status} (Bravos block)`);
|
|
258
263
|
const omp = explicit && !forceOmp ? { status: 'absent' } : writeOmpExtension(root, io.env, { force: opts.force, dryRun, always: forceOmp });
|
|
259
264
|
if (omp.status === 'skipped')
|
|
260
265
|
lines.push(`omp: skipped ${omp.path} — ${omp.reason}`);
|
|
@@ -352,9 +357,10 @@ function pipeline(root, io, opts, withGuardlink, lines) {
|
|
|
352
357
|
lines.push(`Workflows: ${stale.length} bravos workflow(s) are older than this bravos (${stale.join(', ')}); run bravos setup --ci to refresh them.`);
|
|
353
358
|
}
|
|
354
359
|
const cursorWritten = [cursor, cursorHooks].flatMap((c) => (c.status === 'written' || c.status === 'updated' ? [c.path] : []));
|
|
360
|
+
const blocksWritten = blocks.flatMap((b) => (b.status === 'written' || b.status === 'updated' ? [b.path] : []));
|
|
355
361
|
const ompWritten = omp.status === 'written' || omp.status === 'updated' ? [omp.path] : [];
|
|
356
362
|
const ocWritten = oc.status === 'done' ? [...oc.written, ...(oc.mcpAdded.length ? [OPENCODE_CONFIG] : [])] : [];
|
|
357
|
-
const written = [...skills.written, ...skills.updated, ...mirror.written, ...mirror.updated, ...cursorWritten, ...ompWritten, ...ocWritten, ...workflowWritten, ...hook.copied, ...hook.registered.map((r) => r.file), ...guardlinkWritten];
|
|
363
|
+
const written = [...skills.written, ...skills.updated, ...mirror.written, ...mirror.updated, ...cursorWritten, ...blocksWritten, ...ompWritten, ...ocWritten, ...workflowWritten, ...hook.copied, ...hook.registered.map((r) => r.file), ...guardlinkWritten];
|
|
358
364
|
lines.push(...gitignoreWarnings(root, written, io.env));
|
|
359
365
|
if (autopilotKept)
|
|
360
366
|
lines.push('autopilot: kept (already installed); BRAVOS_AUTOPILOT=off pauses the check.');
|
|
@@ -835,6 +841,8 @@ export function buildProgram(io, result) {
|
|
|
835
841
|
lines.push(` ${p}`);
|
|
836
842
|
for (const u of r.unregistered)
|
|
837
843
|
lines.push(`Unregistered bravos's hooks from ${u}`);
|
|
844
|
+
for (const u of r.unblocked)
|
|
845
|
+
lines.push(`Removed the Bravos block from ${u}; the rest of the file is kept`);
|
|
838
846
|
for (const k of r.kept)
|
|
839
847
|
lines.push(`Kept ${k.path} — ${k.reason}`);
|
|
840
848
|
for (const n of r.notes)
|
package/dist/cursor.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { dirname, join } from 'node:path';
|
|
3
3
|
import { readLock, sha256, writeLock } from './lock.js';
|
|
4
|
+
import { bravosBlock } from './instruction-blocks.js';
|
|
4
5
|
import { MARKER, skillsRoot } from './skills.js';
|
|
5
6
|
// @comment -- "Where bravos's Cursor rule lives; Cursor reads project rules from .cursor/rules/*.mdc."
|
|
6
7
|
export const CURSOR_RULE_PATH = '.cursor/rules/bravos.mdc';
|
|
7
|
-
// @comment -- "The rule body for one skills root: a pointer to the bravos skills there
|
|
8
|
+
// @comment -- "The rule body for one skills root: a pointer to the bravos skills there, the two rules that hold everywhere, and the same Bravos block the other instruction files carry (so a session whose hook output did not arrive still runs the briefing); no method is copied here, so it cannot drift from the skills."
|
|
8
9
|
export const cursorRule = (root) => `---
|
|
9
10
|
description: bravos security workflow skills for this repo (guardlink, cxg, code graph)
|
|
10
11
|
globs:
|
|
@@ -25,7 +26,8 @@ Two rules hold everywhere:
|
|
|
25
26
|
follow the method in this session.
|
|
26
27
|
- Never write \`@accepts\`, \`@entitles\` or \`@confirmed\`. Acceptance and entitlement are a human's
|
|
27
28
|
decision, and only a reproduced run confirms an exposure.
|
|
28
|
-
|
|
29
|
+
|
|
30
|
+
${bravosBlock()}`;
|
|
29
31
|
// @comment -- "The skills root the pointer names: .claude/skills when Claude Code's root was installed, else .agents/skills, else none."
|
|
30
32
|
export function cursorSkillsRoot(harnesses) {
|
|
31
33
|
if (harnesses.includes('claude'))
|
package/dist/guide.js
CHANGED
|
@@ -14,6 +14,7 @@ export const GUIDE_TOPICS = [
|
|
|
14
14
|
body: [
|
|
15
15
|
'A hook gathers the repo\'s security picture (open exposures, confirmed exploits, what to test next, stale claims, tickets, teammates\' open PRs, intent) and hands it to the model, so you never need a command to load it. On a fresh start you also see the banner; the model does not.',
|
|
16
16
|
'Every agent shows the same Bravos picture, through the best channel it has. Claude Code shows the banner above the first prompt, and Gemini shows it at session start. omp shows it above the editor until your first prompt. Codex shows the Bravos card (the banner without the logo) with your first message. Cursor and opencode cannot draw anything at launch, so the agent opens its first reply with the card. Antigravity gets the briefing for the model only. Anywhere else, the bravos skill loads the briefing when you run it.',
|
|
17
|
+
'Teammates without Bravos: the hooks travel with the repository, but on a machine without Bravos (no bravos command, licence or plugin) they show only an invitation, once per session: the repository\'s own numbers from the committed threat model and the one command to join. Nothing else runs for them: no briefing, coach, threat cards, checks or background work, and nothing is sent anywhere. Their agent offers setup once and runs it only on a yes; "not now" hides it for 7 days in that clone (node .bravos/hooks/invite.mjs snooze). A team switches it off with {"invite": "off"} in .bravos/config.json.',
|
|
17
18
|
],
|
|
18
19
|
},
|
|
19
20
|
{
|
|
@@ -199,6 +200,7 @@ export const GUIDE_TOPICS = [
|
|
|
199
200
|
{ name: 'opencode', body: ['Finds the skills in .claude/skills and .agents/skills through its skill tool; bravos adds /bravos… commands in .opencode/commands that load them, a plugin in .opencode/plugins (opencode 2.x) that adds the briefing to the system prompt, and guardlink MCP in opencode.json.'] },
|
|
200
201
|
{ name: 'Antigravity (agy)', body: ['Reads .agents/skills; .agents/hooks.json carries a bravos SessionStart group that injects the briefing.'] },
|
|
201
202
|
{ name: 'Cursor', body: ['When the repo has a .cursor/ folder (or with --agent cursor): .cursor/rules/bravos.mdc points at the skills, and a sessionStart hook in .cursor/hooks.json gives the agent the briefing and the Bravos card for its first reply.'] },
|
|
203
|
+
{ name: 'Agents without hooks', body: ['A short Bravos block, between <!-- bravos:begin --> and <!-- bravos:end -->, in AGENTS.md and CLAUDE.md (when they exist or their skills are installed), GEMINI.md and .github/copilot-instructions.md (when they exist), and .windsurf/rules/bravos.md (with a .windsurf/ folder): an agent that got no briefing from a hook runs node .bravos/hooks/session-start.mjs --briefing. Setup replaces only that block; uninstall removes it.'] },
|
|
202
204
|
{ name: 'VS Code (Copilot agent)', body: ['Reads hooks from .claude/settings.json (preview), so the briefing can load there too.'] },
|
|
203
205
|
{ name: 'Every repo, or one copy of each skill', body: ['bravos setup --global installs for your user: skills in ~/.claude/skills (linked from ~/.agents/skills) and a user hook that briefs repos with a threat model but no bravos install. bravos setup --link-skills makes a repo\'s .agents/skills a link to .claude/skills, so tools that read both (Warp) list each skill once.'] },
|
|
204
206
|
{ name: 'Banner switches', body: ['BRAVOS_BANNER=off hides it; BRAVOS_BANNER_COLOR=off or NO_COLOR prints it plain. The briefing for the model is unchanged either way.', 'Light terminal? BRAVOS_THEME=light (or dark, or neutral) picks the colours for the banner and bravos watch; otherwise COLORFGBG, the choice saved by bravos setup, then neutral. bravos doctor shows which, and the c key in bravos watch switches.'] },
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import { existsSync, lstatSync, mkdirSync, readFileSync, realpathSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { dirname, join, relative, isAbsolute } from 'node:path';
|
|
3
|
+
import { readLock, sha256, writeLock } from './lock.js';
|
|
4
|
+
import { MARKER, skillsRoot } from './skills.js';
|
|
5
|
+
// @comment -- "The markers around Bravos's block in an instruction file other people also edit. Distinct from GuardLink's <!-- guardlink:begin --> / <!-- guardlink:end -->, so neither tool's sync can mistake the other's block for its own."
|
|
6
|
+
export const BLOCK_BEGIN = '<!-- bravos:begin -->';
|
|
7
|
+
export const BLOCK_END = '<!-- bravos:end -->';
|
|
8
|
+
const GUARDLINK_BEGIN = '<!-- guardlink:begin -->';
|
|
9
|
+
const GUARDLINK_END = '<!-- guardlink:end -->';
|
|
10
|
+
// @comment -- "The block's text, written for an agent: what Bravos is, the one command that brings the briefing (or, on a machine without Bravos, the invitation) when no hook delivered it, what to say when node is missing, and that nothing is installed without the person's go-ahead. Fixed text: no repository or user content is ever spliced in."
|
|
11
|
+
export const BLOCK_BODY = [
|
|
12
|
+
'## Bravos',
|
|
13
|
+
'',
|
|
14
|
+
'This repository uses Bravos, a security workflow for coding agents.',
|
|
15
|
+
'- If no Bravos briefing reached you through a hook at session start, run `node .bravos/hooks/session-start.mjs --briefing` from the repository root once, at the start of the session, and follow what it prints: the security briefing, or an invitation to show the person when Bravos is not installed on this machine.',
|
|
16
|
+
'- If `node` is not available, tell the person once that this repository uses Bravos (`npm install -g @bugb-technologies/bravos && bravos setup`), then continue.',
|
|
17
|
+
'- Never install anything without the person\'s go-ahead.',
|
|
18
|
+
];
|
|
19
|
+
// @comment -- "The whole delimited block, ending with one line break, in the file's own line ending."
|
|
20
|
+
export function bravosBlock(eol = '\n') {
|
|
21
|
+
return [BLOCK_BEGIN, ...BLOCK_BODY, BLOCK_END].join(eol) + eol;
|
|
22
|
+
}
|
|
23
|
+
// @comment -- "Where Bravos's Windsurf rule lives: Windsurf reads workspace rules from .windsurf/rules/*.md, and trigger: always_on puts it in every Cascade session. The whole file is Bravos's, so it is lock-recorded and uninstall deletes it when unchanged."
|
|
24
|
+
export const WINDSURF_RULE_PATH = '.windsurf/rules/bravos.md';
|
|
25
|
+
export const windsurfRule = () => `---\ntrigger: always_on\n---\n${MARKER}\n${bravosBlock()}`;
|
|
26
|
+
// @comment -- "The shared instruction files that carry the block, the agents that read each, and when each is created: AGENTS.md and CLAUDE.md also when their agent's skills root is installed, GEMINI.md and Copilot's file only when they already exist."
|
|
27
|
+
export const SHARED_FILES = [
|
|
28
|
+
{ path: 'AGENTS.md', agents: ['agents', 'agy', 'opencode', 'omp', 'cursor'], skills: 'agents' },
|
|
29
|
+
{ path: 'CLAUDE.md', agents: ['claude'], skills: 'claude' },
|
|
30
|
+
{ path: 'GEMINI.md', agents: ['agy'] },
|
|
31
|
+
{ path: '.github/copilot-instructions.md', agents: [] },
|
|
32
|
+
];
|
|
33
|
+
/** [start, end) ranges of GuardLink's own blocks, where a Bravos marker is never looked for. */
|
|
34
|
+
function guardlinkRanges(text) {
|
|
35
|
+
const out = [];
|
|
36
|
+
let from = 0;
|
|
37
|
+
for (;;) {
|
|
38
|
+
const b = text.indexOf(GUARDLINK_BEGIN, from);
|
|
39
|
+
if (b === -1)
|
|
40
|
+
return out;
|
|
41
|
+
const e = text.indexOf(GUARDLINK_END, b);
|
|
42
|
+
if (e === -1) {
|
|
43
|
+
out.push([b, text.length]);
|
|
44
|
+
return out;
|
|
45
|
+
}
|
|
46
|
+
out.push([b, e + GUARDLINK_END.length]);
|
|
47
|
+
from = e + GUARDLINK_END.length;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/** The first index of `needle` at or after `from` that is not inside a GuardLink block, or -1. */
|
|
51
|
+
function indexOutside(text, needle, from, ranges) {
|
|
52
|
+
for (let i = text.indexOf(needle, from); i !== -1; i = text.indexOf(needle, i + 1)) {
|
|
53
|
+
if (!ranges.some(([s, e]) => i >= s && i < e))
|
|
54
|
+
return i;
|
|
55
|
+
}
|
|
56
|
+
return -1;
|
|
57
|
+
}
|
|
58
|
+
/** Where Bravos's block sits in `text`: its begin and end-marker offsets, null when absent, or an error for a begin with no end. */
|
|
59
|
+
function findBlock(text) {
|
|
60
|
+
const ranges = guardlinkRanges(text);
|
|
61
|
+
const begin = indexOutside(text, BLOCK_BEGIN, 0, ranges);
|
|
62
|
+
if (begin === -1)
|
|
63
|
+
return null;
|
|
64
|
+
const end = indexOutside(text, BLOCK_END, begin, ranges);
|
|
65
|
+
if (end === -1)
|
|
66
|
+
return { error: `has ${BLOCK_BEGIN} with no ${BLOCK_END} after it; fix it and run bravos setup again` };
|
|
67
|
+
return { begin, end };
|
|
68
|
+
}
|
|
69
|
+
// @comment -- "Puts the block into an instruction file's text: replaces the existing Bravos block in place, or appends it after everything else with one blank line before it. Text outside the markers, GuardLink's block included, is kept byte for byte."
|
|
70
|
+
export function upsertBlock(text) {
|
|
71
|
+
const eol = text.includes('\r\n') ? '\r\n' : '\n';
|
|
72
|
+
const block = bravosBlock(eol);
|
|
73
|
+
const at = findBlock(text);
|
|
74
|
+
if (at && 'error' in at)
|
|
75
|
+
return at;
|
|
76
|
+
if (at) {
|
|
77
|
+
// The block ends with one line break the previous write put there; drop exactly that one so a re-run is unchanged.
|
|
78
|
+
const tail = text.slice(at.end + BLOCK_END.length).replace(/^\r?\n/, '');
|
|
79
|
+
return { text: text.slice(0, at.begin) + block + tail };
|
|
80
|
+
}
|
|
81
|
+
if (text === '')
|
|
82
|
+
return { text: block };
|
|
83
|
+
const sep = text.endsWith('\n') ? eol : eol + eol;
|
|
84
|
+
return { text: text + sep + block };
|
|
85
|
+
}
|
|
86
|
+
// @comment -- "Takes the block out of an instruction file's text, with the line break that ends it and the blank line upsertBlock put before it; returns null when the file holds no Bravos block. Nothing else is changed."
|
|
87
|
+
export function removeBlock(text) {
|
|
88
|
+
const at = findBlock(text);
|
|
89
|
+
if (!at || 'error' in at)
|
|
90
|
+
return null;
|
|
91
|
+
let head = text.slice(0, at.begin);
|
|
92
|
+
const tail = text.slice(at.end + BLOCK_END.length).replace(/^\r?\n/, '');
|
|
93
|
+
if (/(\r?\n){2}$/.test(head))
|
|
94
|
+
head = head.replace(/\r?\n$/, '');
|
|
95
|
+
return head + tail;
|
|
96
|
+
}
|
|
97
|
+
// @comment -- "Resolves an instruction file for writing: absent, a regular file whose real path stays inside the repository, or a reason to leave it alone (a folder, a link that leaves the repository)."
|
|
98
|
+
// @exposes #instruction-blocks to #out-of-repo-write [medium] cwe:CWE-59 -- "AGENTS.md, CLAUDE.md and the rest come from the cloned repository, and any of them can be a link."
|
|
99
|
+
// @mitigates #instruction-blocks against #out-of-repo-write using #in-repo-target -- "A link such as CLAUDE.md -> AGENTS.md is followed only when it ends at a regular file inside the repository; anything else is reported and never written."
|
|
100
|
+
function target(root, rel) {
|
|
101
|
+
const abs = join(root, rel);
|
|
102
|
+
let st;
|
|
103
|
+
try {
|
|
104
|
+
st = lstatSync(abs);
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
// Absent: the parent must also stay inside the repository (a linked .github/ or .windsurf/ is not followed out).
|
|
108
|
+
try {
|
|
109
|
+
const parent = realpathSync(dirname(abs));
|
|
110
|
+
const rp = relative(realpathSync(root), parent);
|
|
111
|
+
if (rp.startsWith('..') || isAbsolute(rp))
|
|
112
|
+
return { reason: 'its folder is a link that leaves the repository' };
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
/* the folder does not exist yet; mkdir creates it inside root */
|
|
116
|
+
}
|
|
117
|
+
return { exists: false };
|
|
118
|
+
}
|
|
119
|
+
if (st.isSymbolicLink()) {
|
|
120
|
+
let real;
|
|
121
|
+
try {
|
|
122
|
+
real = realpathSync(abs);
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
return { reason: 'a link to a file that does not exist' };
|
|
126
|
+
}
|
|
127
|
+
const rp = relative(realpathSync(root), real);
|
|
128
|
+
if (rp.startsWith('..') || isAbsolute(rp))
|
|
129
|
+
return { reason: 'a link that leaves the repository' };
|
|
130
|
+
if (!lstatSync(real).isFile())
|
|
131
|
+
return { reason: 'not a regular file' };
|
|
132
|
+
return { exists: true };
|
|
133
|
+
}
|
|
134
|
+
if (!st.isFile())
|
|
135
|
+
return { reason: 'not a regular file' };
|
|
136
|
+
return { exists: true };
|
|
137
|
+
}
|
|
138
|
+
const lexists = (abs) => {
|
|
139
|
+
try {
|
|
140
|
+
lstatSync(abs);
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
// @comment -- "Writes or refreshes the Bravos block in each shared instruction file under its condition: the file exists, or (AGENTS.md, CLAUDE.md) that agent's skills root is installed. With an explicit --agent a file is written only when one of its agents was chosen, or when no --agent can name it (Copilot's file); upkeep also refreshes a block already present. Shared files are never lock-recorded, since people edit them."
|
|
148
|
+
export function writeInstructionBlocks(root, opts) {
|
|
149
|
+
const out = [];
|
|
150
|
+
const seen = new Set();
|
|
151
|
+
for (const f of SHARED_FILES) {
|
|
152
|
+
const t = target(root, f.path);
|
|
153
|
+
const has = 'exists' in t && t.exists;
|
|
154
|
+
const chosen = opts.agents === undefined || f.agents.length === 0 || f.agents.some((a) => opts.agents.includes(a));
|
|
155
|
+
const text = has ? readFileSync(join(root, f.path), 'utf8') : '';
|
|
156
|
+
const present = has && findBlock(text) !== null;
|
|
157
|
+
if (!chosen && !(opts.refreshOnly && present))
|
|
158
|
+
continue;
|
|
159
|
+
const installed = f.skills !== undefined && (opts.harnesses.includes(f.skills) || existsSync(join(root, skillsRoot(f.skills), 'bravos', 'SKILL.md')));
|
|
160
|
+
if ('reason' in t) {
|
|
161
|
+
if (installed || lexists(join(root, f.path)))
|
|
162
|
+
out.push({ path: f.path, status: 'skipped', reason: t.reason });
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
if (!has && !installed)
|
|
166
|
+
continue;
|
|
167
|
+
// CLAUDE.md linked to AGENTS.md is one file: it gets one block.
|
|
168
|
+
const real = has ? realpathSync(join(root, f.path)) : join(root, f.path);
|
|
169
|
+
if (seen.has(real)) {
|
|
170
|
+
out.push({ path: f.path, status: 'unchanged' });
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
seen.add(real);
|
|
174
|
+
const next = upsertBlock(text);
|
|
175
|
+
if ('error' in next) {
|
|
176
|
+
out.push({ path: f.path, status: 'skipped', reason: next.error });
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
if (has && next.text === text) {
|
|
180
|
+
out.push({ path: f.path, status: 'unchanged' });
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
if (!opts.dryRun) {
|
|
184
|
+
mkdirSync(dirname(join(root, f.path)), { recursive: true });
|
|
185
|
+
writeFileSync(join(root, f.path), next.text);
|
|
186
|
+
}
|
|
187
|
+
out.push({ path: f.path, status: has ? 'updated' : 'written' });
|
|
188
|
+
}
|
|
189
|
+
const w = writeWindsurfRule(root, opts);
|
|
190
|
+
if (w)
|
|
191
|
+
out.push(w);
|
|
192
|
+
return out;
|
|
193
|
+
}
|
|
194
|
+
// @comment -- "Writes .windsurf/rules/bravos.md when the repo has a .windsurf/ folder. Windsurf has no --agent value, so it follows the folder alone. The file is Bravos's whole: replaced only when the lock vouches for it or it carries the generated marker, unless --force, and the lock records what was written."
|
|
195
|
+
export function writeWindsurfRule(root, opts = {}) {
|
|
196
|
+
if (!existsSync(join(root, '.windsurf')))
|
|
197
|
+
return null;
|
|
198
|
+
const path = WINDSURF_RULE_PATH;
|
|
199
|
+
const t = target(root, path);
|
|
200
|
+
if ('reason' in t)
|
|
201
|
+
return { path, status: 'skipped', reason: t.reason };
|
|
202
|
+
const abs = join(root, path);
|
|
203
|
+
const content = Buffer.from(windsurfRule());
|
|
204
|
+
const hash = sha256(content);
|
|
205
|
+
const lock = readLock(root);
|
|
206
|
+
let status = 'written';
|
|
207
|
+
if (t.exists) {
|
|
208
|
+
const disk = readFileSync(abs);
|
|
209
|
+
const diskHash = sha256(disk);
|
|
210
|
+
if (diskHash === hash)
|
|
211
|
+
return { path, status: 'unchanged' };
|
|
212
|
+
const locked = lock.files[path];
|
|
213
|
+
if (locked !== undefined && diskHash !== locked && !opts.force)
|
|
214
|
+
return { path, status: 'skipped', reason: 'edited since last install (use --force to overwrite)' };
|
|
215
|
+
if (locked === undefined && !disk.toString('utf8').includes(MARKER) && !opts.force)
|
|
216
|
+
return { path, status: 'skipped', reason: 'authored file, not managed by bravos (use --force to overwrite)' };
|
|
217
|
+
status = 'updated';
|
|
218
|
+
}
|
|
219
|
+
if (!opts.dryRun) {
|
|
220
|
+
mkdirSync(dirname(abs), { recursive: true });
|
|
221
|
+
writeFileSync(abs, content);
|
|
222
|
+
writeLock(root, { ...lock, files: { ...lock.files, [path]: hash } });
|
|
223
|
+
}
|
|
224
|
+
return { path, status };
|
|
225
|
+
}
|
|
226
|
+
// @comment -- "Uninstall's part: takes the Bravos block out of each shared instruction file and keeps every other line; a file left holding nothing but blank space (Bravos created it) is deleted. The Windsurf rule is lock-recorded, so the lock pass removes it when unchanged. Links that leave the repository are not followed."
|
|
227
|
+
export function removeInstructionBlocks(root, opts = {}) {
|
|
228
|
+
const cleaned = [];
|
|
229
|
+
const deleted = [];
|
|
230
|
+
const seen = new Set();
|
|
231
|
+
for (const f of SHARED_FILES) {
|
|
232
|
+
const t = target(root, f.path);
|
|
233
|
+
if (!('exists' in t) || !t.exists)
|
|
234
|
+
continue;
|
|
235
|
+
const abs = join(root, f.path);
|
|
236
|
+
const real = realpathSync(abs);
|
|
237
|
+
if (seen.has(real))
|
|
238
|
+
continue;
|
|
239
|
+
seen.add(real);
|
|
240
|
+
const text = readFileSync(abs, 'utf8');
|
|
241
|
+
const next = removeBlock(text);
|
|
242
|
+
if (next === null)
|
|
243
|
+
continue;
|
|
244
|
+
if (next.trim() === '' && !lstatSync(abs).isSymbolicLink()) {
|
|
245
|
+
deleted.push(f.path);
|
|
246
|
+
if (!opts.dryRun)
|
|
247
|
+
unlinkSync(abs);
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
cleaned.push(f.path);
|
|
251
|
+
if (!opts.dryRun)
|
|
252
|
+
writeFileSync(abs, next);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
return { cleaned, deleted };
|
|
256
|
+
}
|
package/dist/uninstall.js
CHANGED
|
@@ -2,6 +2,7 @@ import { existsSync, lstatSync, readFileSync, readdirSync, readlinkSync, rmdirSy
|
|
|
2
2
|
import { dirname, join } from 'node:path';
|
|
3
3
|
import { LOCK_PATH, readLock, sha256 } from './lock.js';
|
|
4
4
|
import { removePrePush } from './context.js';
|
|
5
|
+
import { removeInstructionBlocks } from './instruction-blocks.js';
|
|
5
6
|
import { BravosError } from './types.js';
|
|
6
7
|
const isObject = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
7
8
|
// Any command bravos registers: the per-repo relative forms and the user-level absolute one.
|
|
@@ -88,10 +89,10 @@ function pruneEmpty(root, rel) {
|
|
|
88
89
|
dir = dirname(dir);
|
|
89
90
|
}
|
|
90
91
|
}
|
|
91
|
-
// @comment -- "Removes what bravos installed under root: every file its lock records that is unchanged (edited ones are kept and listed unless --force), bravos's hook entries in .claude/settings.json, .codex/hooks.json and .cursor/hooks.json, its group in .agents/hooks.json, its pre_pr entry in .guardlink/config.json, and .bravos/ itself; with home set, also the ~/.agents/skills/bravos* links. Never removes guardlink's own files, a reviewed scope.yaml, or MCP entries (which may predate bravos); those are listed. Hooks files are validated before anything is removed."
|
|
92
|
+
// @comment -- "Removes what bravos installed under root: every file its lock records that is unchanged (edited ones are kept and listed unless --force), the Bravos block in the shared instruction files, bravos's hook entries in .claude/settings.json, .codex/hooks.json and .cursor/hooks.json, its group in .agents/hooks.json, its pre_pr entry in .guardlink/config.json, and .bravos/ itself; with home set, also the ~/.agents/skills/bravos* links. Never removes guardlink's own files, a reviewed scope.yaml, or MCP entries (which may predate bravos); those are listed. Hooks files are validated before anything is removed."
|
|
92
93
|
export function uninstall(root, opts = {}) {
|
|
93
94
|
const dryRun = !!opts.dryRun;
|
|
94
|
-
const report = { removed: [], kept: [], unregistered: [], notes: [] };
|
|
95
|
+
const report = { removed: [], kept: [], unregistered: [], unblocked: [], notes: [] };
|
|
95
96
|
if (!existsSync(join(root, '.bravos'))) {
|
|
96
97
|
throw new BravosError(`bravos is not installed in ${root} (no .bravos/ folder); nothing was removed`);
|
|
97
98
|
}
|
|
@@ -150,6 +151,12 @@ export function uninstall(root, opts = {}) {
|
|
|
150
151
|
report.notes.push('run guardlink sync to drop the gate from the agent instruction files');
|
|
151
152
|
}
|
|
152
153
|
}
|
|
154
|
+
// @comment -- "The Bravos block comes out of the shared instruction files (AGENTS.md, CLAUDE.md, GEMINI.md, Copilot's) and every other line stays; a file that held only the block is deleted. Windsurf's rule went with the lock pass above."
|
|
155
|
+
if (!opts.home) {
|
|
156
|
+
const b = removeInstructionBlocks(root, { dryRun });
|
|
157
|
+
report.unblocked.push(...b.cleaned);
|
|
158
|
+
report.removed.push(...b.deleted);
|
|
159
|
+
}
|
|
153
160
|
if (opts.home) {
|
|
154
161
|
const dir = join(root, '.agents', 'skills');
|
|
155
162
|
let entries = [];
|
package/docs/GUIDE.md
CHANGED
|
@@ -16,6 +16,8 @@ A hook gathers the repo's security picture (open exposures, confirmed exploits,
|
|
|
16
16
|
|
|
17
17
|
Every agent shows the same Bravos picture, through the best channel it has. Claude Code shows the banner above the first prompt, and Gemini shows it at session start. omp shows it above the editor until your first prompt. Codex shows the Bravos card (the banner without the logo) with your first message. Cursor and opencode cannot draw anything at launch, so the agent opens its first reply with the card. Antigravity gets the briefing for the model only. Anywhere else, the bravos skill loads the briefing when you run it.
|
|
18
18
|
|
|
19
|
+
Teammates without Bravos: the hooks travel with the repository, but on a machine without Bravos (no bravos command, licence or plugin) they show only an invitation, once per session: the repository's own numbers from the committed threat model and the one command to join. Nothing else runs for them: no briefing, coach, threat cards, checks or background work, and nothing is sent anywhere. Their agent offers setup once and runs it only on a yes; "not now" hides it for 7 days in that clone (node .bravos/hooks/invite.mjs snooze). A team switches it off with {"invite": "off"} in .bravos/config.json.
|
|
20
|
+
|
|
19
21
|
### Running a skill
|
|
20
22
|
|
|
21
23
|
Claude Code and opencode: /bravos-ship. Codex: $bravos-ship. omp: /skill:bravos-ship. Elsewhere, ask for it by name ("use the bravos-ship skill"). You can also just say what you want ("is this PR safe to open?") and the agent picks the skill.
|
|
@@ -388,6 +390,10 @@ Reads .agents/skills; .agents/hooks.json carries a bravos SessionStart group tha
|
|
|
388
390
|
|
|
389
391
|
When the repo has a .cursor/ folder (or with --agent cursor): .cursor/rules/bravos.mdc points at the skills, and a sessionStart hook in .cursor/hooks.json gives the agent the briefing and the Bravos card for its first reply.
|
|
390
392
|
|
|
393
|
+
### Agents without hooks
|
|
394
|
+
|
|
395
|
+
A short Bravos block, between <!-- bravos:begin --> and <!-- bravos:end -->, in AGENTS.md and CLAUDE.md (when they exist or their skills are installed), GEMINI.md and .github/copilot-instructions.md (when they exist), and .windsurf/rules/bravos.md (with a .windsurf/ folder): an agent that got no briefing from a hook runs node .bravos/hooks/session-start.mjs --briefing. Setup replaces only that block; uninstall removes it.
|
|
396
|
+
|
|
391
397
|
### VS Code (Copilot agent)
|
|
392
398
|
|
|
393
399
|
Reads hooks from .claude/settings.json (preview), so the briefing can load there too.
|
package/docs/UPGRADING.md
CHANGED
|
@@ -2,6 +2,30 @@
|
|
|
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.19.0
|
|
6
|
+
|
|
7
|
+
- **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:
|
|
8
|
+
- **What it shows:** the repository's own numbers from its committed threat model, what Bravos would do for that person, and the one command to join (Free, no account needed).
|
|
9
|
+
- **What runs for them:** nothing else. No briefing, coach, threat cards, pre-PR gate, autopilot or background work, and nothing is sent anywhere.
|
|
10
|
+
- **Their agent** offers setup once and runs it only if they say yes. "Not now" hides the invitation in that clone for 7 days (`node .bravos/hooks/invite.mjs snooze`, kept under `.git`).
|
|
11
|
+
- **To switch it off for the team:** add `{"invite": "off"}` to `.bravos/config.json`. CI always counts as having Bravos, so the nightly and PR workflows are unchanged.
|
|
12
|
+
- **Agents without hooks get Bravos too.** `bravos setup` keeps a short Bravos block in the instruction files agents read: `AGENTS.md`, `CLAUDE.md`, `GEMINI.md`, `.github/copilot-instructions.md`, `.windsurf/rules/bravos.md` and the Cursor rule.
|
|
13
|
+
- The block tells an agent that got no Bravos briefing from a hook to run `node .bravos/hooks/session-start.mjs --briefing`. That prints the briefing, or the invitation on a machine without Bravos.
|
|
14
|
+
- Your own text in those files is kept, GuardLink's block is left alone, and `bravos uninstall` removes only Bravos's block.
|
|
15
|
+
- **Where the card shows now depends on the surface, not just the agent:**
|
|
16
|
+
|
|
17
|
+
| Agent | Where you see it |
|
|
18
|
+
|---|---|
|
|
19
|
+
| Claude Code in a terminal | the banner, at launch |
|
|
20
|
+
| Claude Code desktop app and IDE extensions | the agent's first reply opens with the card (before, a banner these surfaces don't draw) |
|
|
21
|
+
| omp | the banner, above the editor until your first prompt |
|
|
22
|
+
| Gemini | the banner, at session start |
|
|
23
|
+
| Codex | the card itself, shown as "↳ Hook ·" with your first message |
|
|
24
|
+
| Cursor, OpenCode, Antigravity | the agent's first reply opens with the card |
|
|
25
|
+
| Windsurf, Copilot and other agents without hooks | the agent runs the briefing from the repository's instruction files, then opens its reply with the card |
|
|
26
|
+
- **A Team trial warns in its last 5 days.** The banner says how many days are left and to ask your admin to keep Team.
|
|
27
|
+
- **To get it:** run `bravos setup` in each repository (it writes the instruction-file blocks), commit what it changes, then start a new session in each agent.
|
|
28
|
+
|
|
5
29
|
## 1.18.0
|
|
6
30
|
|
|
7
31
|
- **Every agent now shows the same Bravos card,** through the best channel that agent has:
|
package/hooks/autopilot.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// @comment -- "bravos autopilot Stop hook entry (Claude Code and Codex): reads the Stop payload from stdin with a bounded wait, resolves the repo as git's top level for the payload cwd, runs the end-of-turn check, and prints {} to allow or {decision:'block', reason} to send the agent back once, logging the nudge for bravos watch. Always exits 0; a failure allows."
|
|
2
2
|
import { entitled, status as licenceStatus } from './lib/licence.mjs';
|
|
3
|
+
import { audience } from './lib/audience.mjs';
|
|
3
4
|
import { resolveRoot } from './lib/pre-pr.mjs';
|
|
4
5
|
import { logWatchEvent, runAutopilot } from './lib/autopilot.mjs';
|
|
5
6
|
|
|
@@ -22,7 +23,7 @@ async function readPayload() {
|
|
|
22
23
|
async function main() {
|
|
23
24
|
let out = {};
|
|
24
25
|
// Autopilot is part of the pre-PR gate feature; without the licence the Stop hook answers nothing and the turn ends normally.
|
|
25
|
-
if (!entitled(licenceStatus(process.env), 'pre-pr')) {
|
|
26
|
+
if (audience(process.env).kind === 'none' || !entitled(licenceStatus(process.env), 'pre-pr')) {
|
|
26
27
|
process.stdout.write('{}\n');
|
|
27
28
|
process.exit(0);
|
|
28
29
|
}
|
package/hooks/cards.mjs
CHANGED
|
@@ -5,6 +5,7 @@ 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
|
+
import { audience } from './lib/audience.mjs';
|
|
8
9
|
import { logWatchEvent } from './lib/snapshot.mjs';
|
|
9
10
|
|
|
10
11
|
async function readPayload() {
|
|
@@ -43,6 +44,8 @@ async function main() {
|
|
|
43
44
|
let out = {};
|
|
44
45
|
try {
|
|
45
46
|
if (process.env.BRAVOS_THREAT_CARDS === 'off') throw new Error('off');
|
|
47
|
+
// A machine without Bravos gets only the session-start invitation: no threat cards.
|
|
48
|
+
if (audience(process.env).kind === 'none') throw new Error('off');
|
|
46
49
|
const payload = await readPayload();
|
|
47
50
|
const cwd = typeof payload.cwd === 'string' ? payload.cwd : process.env.CLAUDE_PROJECT_DIR || process.cwd();
|
|
48
51
|
const top = spawnSync('git', ['rev-parse', '--show-toplevel'], { cwd, encoding: 'utf8', timeout: 3000, stdio: ['ignore', 'pipe', 'ignore'] });
|
package/hooks/coach.mjs
CHANGED
|
@@ -6,6 +6,7 @@ import { spawnSync } from 'node:child_process';
|
|
|
6
6
|
import { fileURLToPath } from 'node:url';
|
|
7
7
|
import { coachTurn, newestModelChange, readCoach, writeCoach } from './lib/coach.mjs';
|
|
8
8
|
import { gitCommonDir, readPrefs } from './lib/prefs.mjs';
|
|
9
|
+
import { audience } from './lib/audience.mjs';
|
|
9
10
|
import { logWatchEvent } from './lib/snapshot.mjs';
|
|
10
11
|
import { cliVersion, readUpdate, repoVersion } from './lib/update-check.mjs';
|
|
11
12
|
|
|
@@ -61,6 +62,8 @@ async function main() {
|
|
|
61
62
|
let out = {};
|
|
62
63
|
try {
|
|
63
64
|
if (process.env.BRAVOS_COACH === 'off') throw new Error('off');
|
|
65
|
+
// A machine without Bravos gets only the session-start invitation: no coaching.
|
|
66
|
+
if (audience(process.env).kind === 'none') throw new Error('off');
|
|
64
67
|
const payload = await readPayload();
|
|
65
68
|
const cwd = typeof payload.cwd === 'string' ? payload.cwd : process.env.CLAUDE_PROJECT_DIR || process.cwd();
|
|
66
69
|
const root = git(cwd, ['rev-parse', '--show-toplevel']) || cwd;
|
package/hooks/invite.mjs
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// @comment -- "The one thing a person without Bravos can ask of it: node .bravos/hooks/invite.mjs snooze hides the invitation in this clone for seven days. Their agent runs it when they say 'not now'. Writes only <git-common-dir>/bravos/invite.json; prints one line; always exits 0."
|
|
2
|
+
import { gitCommonDir } from './lib/prefs.mjs';
|
|
3
|
+
import { snoozeInvite } from './lib/audience.mjs';
|
|
4
|
+
|
|
5
|
+
const root = process.env.CLAUDE_PROJECT_DIR || process.cwd();
|
|
6
|
+
if (process.argv[2] === 'snooze') {
|
|
7
|
+
const file = snoozeInvite(gitCommonDir(root));
|
|
8
|
+
process.stdout.write(file ? 'Bravos invitation hidden in this clone for 7 days.\n' : 'Not a git repository: nothing recorded.\n');
|
|
9
|
+
} else process.stdout.write('usage: node .bravos/hooks/invite.mjs snooze\n');
|
|
10
|
+
process.exit(0);
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// @comment -- "Who is in this session, for what the hooks show and do: a machine without Bravos (none: a teammate who cloned a repository that uses it), Free, a Team trial, a Team seat, or an expired licence. Installed means the Bravos CLI is on PATH, a licence is on this machine, or the Claude Code or Codex plugin is installed; a Bravos folder alone does not count, since older hooks wrote one for anyone. CI always counts as installed: Bravos's own workflows run the agents there. Read-only, dependency-free."
|
|
2
|
+
import { mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { cliVersion } from './update-check.mjs';
|
|
5
|
+
import { status as licenceStatus } from './licence.mjs';
|
|
6
|
+
|
|
7
|
+
const SNOOZE_DAYS = 7;
|
|
8
|
+
|
|
9
|
+
// @comment -- "True when the Claude Code or Codex plugin cache holds a Bravos plugin: someone installed it from a marketplace without the npm CLI."
|
|
10
|
+
function pluginInstalled(home) {
|
|
11
|
+
if (!home) return false;
|
|
12
|
+
for (const cache of [join(home, '.claude', 'plugins', 'cache'), join(home, '.codex', 'plugins', 'cache')]) {
|
|
13
|
+
let entries = [];
|
|
14
|
+
try {
|
|
15
|
+
entries = readdirSync(cache, { withFileTypes: true });
|
|
16
|
+
} catch {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
for (const e of entries) {
|
|
20
|
+
if (!e.isDirectory()) continue;
|
|
21
|
+
if (/^bravos/i.test(e.name)) return true;
|
|
22
|
+
try {
|
|
23
|
+
if (readdirSync(join(cache, e.name)).some((n) => /^bravos/i.test(n))) return true;
|
|
24
|
+
} catch {
|
|
25
|
+
/* unreadable marketplace folder */
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// @comment -- "Whether this machine has Bravos: CI, the CLI on PATH, a licence, or a plugin install. BRAVOS_AUDIENCE=installed or none states it outright (tests, mirrors)."
|
|
33
|
+
export function bravosInstalled(env = process.env, licence = licenceStatus(env)) {
|
|
34
|
+
if (env.BRAVOS_AUDIENCE === 'installed') return true;
|
|
35
|
+
if (env.BRAVOS_AUDIENCE === 'none') return false;
|
|
36
|
+
if (env.CI || env.GITHUB_ACTIONS) return true;
|
|
37
|
+
if (cliVersion(env)) return true;
|
|
38
|
+
if (licence && licence.state && licence.state !== 'absent') return true;
|
|
39
|
+
return pluginInstalled(env.HOME);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// @comment -- "The audience: { kind: none | free | trial | team | expired, licence, daysLeft }. daysLeft is set for a trial."
|
|
43
|
+
export function audience(env = process.env, now = Math.floor(Date.now() / 1000)) {
|
|
44
|
+
const licence = licenceStatus(env);
|
|
45
|
+
if (!bravosInstalled(env, licence)) return { kind: 'none', licence };
|
|
46
|
+
if (licence.licensed) {
|
|
47
|
+
if (licence.trial) return { kind: 'trial', licence, daysLeft: Math.max(0, Math.ceil((Number(licence.trial.endsAt) - now) / 86400)) };
|
|
48
|
+
return { kind: 'team', licence };
|
|
49
|
+
}
|
|
50
|
+
if (licence.state === 'expired') return { kind: 'expired', licence };
|
|
51
|
+
return { kind: 'free', licence };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// @comment -- "Whether the invitation may show in this clone: the team can switch it off in the committed .bravos/config.json (\"invite\": \"off\"), and a person can snooze it for seven days (<git-common-dir>/bravos/invite.json, which no commit can write). BRAVOS_BANNER=off hides it as it hides the banner."
|
|
55
|
+
export function inviteAllowed(root, commonDir, env = process.env, now = Date.now()) {
|
|
56
|
+
if (env.BRAVOS_BANNER === 'off') return false;
|
|
57
|
+
try {
|
|
58
|
+
const cfg = JSON.parse(readFileSync(join(root, '.bravos', 'config.json'), 'utf8'));
|
|
59
|
+
if (cfg && cfg.invite === 'off') return false;
|
|
60
|
+
} catch {
|
|
61
|
+
/* no team setting: on */
|
|
62
|
+
}
|
|
63
|
+
if (!commonDir) return true;
|
|
64
|
+
try {
|
|
65
|
+
const j = JSON.parse(readFileSync(inviteFile(commonDir), 'utf8'));
|
|
66
|
+
const at = Date.parse(j?.snoozedAt);
|
|
67
|
+
if (j?.schema === 'bravos.invite/v1' && Number.isFinite(at) && at <= now + 60000 && now - at < SNOOZE_DAYS * 86400000) return false;
|
|
68
|
+
} catch {
|
|
69
|
+
/* never snoozed */
|
|
70
|
+
}
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export const inviteFile = (commonDir) => join(commonDir, 'bravos', 'invite.json');
|
|
75
|
+
|
|
76
|
+
// @comment -- "Records that the person said 'not now' to the invitation, for seven days, in this clone's git directory. The agent runs it through hooks/invite.mjs, since a person without Bravos has no bravos command."
|
|
77
|
+
export function snoozeInvite(commonDir, now = new Date()) {
|
|
78
|
+
if (!commonDir) return null;
|
|
79
|
+
const file = inviteFile(commonDir);
|
|
80
|
+
mkdirSync(join(file, '..'), { recursive: true, mode: 0o700 });
|
|
81
|
+
writeFileSync(file, JSON.stringify({ schema: 'bravos.invite/v1', snoozedAt: now.toISOString() }) + '\n', { mode: 0o600 });
|
|
82
|
+
return file;
|
|
83
|
+
}
|
package/hooks/lib/briefing.mjs
CHANGED
|
@@ -895,6 +895,11 @@ function bannerWarnings(i, plan) {
|
|
|
895
895
|
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`);
|
|
896
896
|
else if (plan && !plan.licensed && i.licence.state === 'expired') lines.push(`~ licence expired: ${TEAM_ADDS} locked · bravos licence`);
|
|
897
897
|
else if (plan && !plan.licensed) lines.push(`~ Team adds ${TEAM_ADDS} · bravos account activate`);
|
|
898
|
+
// A trial in its last days says so, so keeping Team is the person's (or their admin's) decision, not a surprise.
|
|
899
|
+
else if (plan && i.licence?.trial) {
|
|
900
|
+
const left = Math.ceil((Number(i.licence.trial.endsAt) - Math.floor(Date.now() / 1000)) / 86400);
|
|
901
|
+
if (Number.isFinite(left) && left <= 5) lines.push(`~ Team trial ends in ${Math.max(0, left)} day${left === 1 ? '' : 's'}: ask your admin to keep Team · bravos licence`);
|
|
902
|
+
}
|
|
898
903
|
if (i.stale) lines.push(`! Findings describe older code · ${i.stale.behind} behind ${clean(i.base)} · bravos-resync`);
|
|
899
904
|
else if (arr(i.stranded).length > 0) lines.push(`~ Work on ${clean(i.stranded[0].branch)} is not on ${clean(i.base)} · bravos-resync`);
|
|
900
905
|
if (i.shadow) {
|
|
@@ -1079,6 +1084,58 @@ export function firstReplyStatus(inputs, opts = {}) {
|
|
|
1079
1084
|
return `Status for the person: this agent cannot show Bravos's startup banner to the person, so open your first reply with the card below, copied exactly, inside a text code block, then answer their message. Show it once: skip it when this conversation already shows it.\n\`\`\`text\n${statusCard(inputs, opts)}\n\`\`\``;
|
|
1080
1085
|
}
|
|
1081
1086
|
|
|
1087
|
+
const INSTALL = 'npm install -g @bugb-technologies/bravos';
|
|
1088
|
+
const KNOWN_SEVERITY = ['critical', 'high', 'medium', 'low'];
|
|
1089
|
+
|
|
1090
|
+
// @comment -- "The repository's own numbers for the invitation, read from the committed GuardLink report (.guardlink/report.json), so a machine with no Bravos and no GuardLink still shows them: recorded threats by severity, confirmed exploits and annotated files. Null when there is no report or it cannot be read. Only counts and a cleaned project name leave the file."
|
|
1091
|
+
export function readCommittedReport(root) {
|
|
1092
|
+
try {
|
|
1093
|
+
const j = JSON.parse(readFileSync(join(root, '.guardlink', 'report.json'), 'utf8'));
|
|
1094
|
+
const exposures = Array.isArray(j?.exposures) ? j.exposures : [];
|
|
1095
|
+
const by = Object.fromEntries(KNOWN_SEVERITY.map((k) => [k, exposures.filter((e) => e?.severity === k).length]));
|
|
1096
|
+
const files = (v) => (Array.isArray(v) ? v.length : Number.isFinite(v) ? v : null);
|
|
1097
|
+
return {
|
|
1098
|
+
project: typeof j?.project === 'string' ? clean(j.project).trim().slice(0, 40) : null,
|
|
1099
|
+
threats: exposures.length,
|
|
1100
|
+
by,
|
|
1101
|
+
confirmed: Array.isArray(j?.confirmed) ? j.confirmed.length : 0,
|
|
1102
|
+
annotated: files(j?.annotated_files),
|
|
1103
|
+
source: files(j?.source_files),
|
|
1104
|
+
};
|
|
1105
|
+
} catch {
|
|
1106
|
+
return null;
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
// @comment -- "The invitation a person without Bravos sees, in the card's plain 64-column style: that their team protects this repository with Bravos, the repository's real numbers when a report is committed, what Bravos would do for them, and the one command that sets it up (Free, no account). Nothing in it comes from the repository but counts and a cleaned name."
|
|
1111
|
+
export function inviteCard(root) {
|
|
1112
|
+
const r = readCommittedReport(root);
|
|
1113
|
+
const name = r?.project || clean(basename(root)).trim().slice(0, 40) || 'this repository';
|
|
1114
|
+
const rows = ['BRAVOS by bugb · your team protects this repository'];
|
|
1115
|
+
if (r && r.threats > 0) {
|
|
1116
|
+
const sev = KNOWN_SEVERITY.filter((k) => r.by[k] > 0).map((k) => `${r.by[k]} ${k}`).join(' · ');
|
|
1117
|
+
rows.push(clipped(`${name}: ${r.threats} threats recorded${sev ? ` · ${sev}` : ''}`, 64));
|
|
1118
|
+
const cover = r.annotated !== null && r.source ? `${r.annotated} / ${r.source} files annotated · ` : '';
|
|
1119
|
+
rows.push(`${cover}${r.confirmed} confirmed exploitable`);
|
|
1120
|
+
} else rows.push(clipped(`${name} keeps a security threat model with Bravos`, 64));
|
|
1121
|
+
const rule = '─'.repeat(64);
|
|
1122
|
+
rows.push(rule, 'With Bravos, your coding agent:', ' · knows these threats before it edits the code', ' · checks each pull request for new exposure', ' · proves which threats are real, on your own machine', rule);
|
|
1123
|
+
rows.push(`Join your team: ${INSTALL}`, ' then: bravos setup', 'Free, no account needed. Say "not now" to hide this for 7 days.');
|
|
1124
|
+
return rows.map((l) => l.replace(/`/g, "'")).join('\n');
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
// @comment -- "What the agent of a person without Bravos is told: no security briefing, threat cards or checks run on this machine; show the invitation once (in the first reply, unless the person already saw it on screen); offer setup once and run it only on a yes; on 'not now', snooze it with node .bravos/hooks/invite.mjs snooze and say no more; never let it delay or block their request."
|
|
1128
|
+
export function inviteBriefing(card, { shownOnScreen = false } = {}) {
|
|
1129
|
+
const show = shownOnScreen
|
|
1130
|
+
? 'The person has already seen the Bravos invitation on screen; do not repeat it.'
|
|
1131
|
+
: `Open your first reply with the card below, copied exactly, inside a text code block, then answer their message. Show it once: skip it when this conversation already shows it.\n\`\`\`text\n${card}\n\`\`\``;
|
|
1132
|
+
return [
|
|
1133
|
+
'Bravos: this repository uses Bravos (security workflow for coding agents), but this machine does not have it installed, so no security briefing, threat cards or checks run here.',
|
|
1134
|
+
show,
|
|
1135
|
+
`After answering, offer once, in one sentence, to set Bravos up so this person gets what their team has: \`${INSTALL}\`, then \`bravos setup\` in this repository. Run them only if the person says yes. If they say no or not now, run \`node .bravos/hooks/invite.mjs snooze\` (it hides the invitation in this clone for 7 days) and do not mention Bravos again this session. Never let this delay or block what they asked for.`,
|
|
1136
|
+
].join('\n');
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1082
1139
|
// Brand palette by theme (hooks/lib/palette.mjs). Colour is truecolor ANSI, added after
|
|
1083
1140
|
// layout so widths are measured on plain text. A null colour is the terminal's own
|
|
1084
1141
|
// foreground, so it is readable on whatever background the terminal has.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// @comment -- "Where the person sees Bravos's startup picture, per agent and surface. The agent's own reply is the one channel every surface shows, so anything not known to draw a hook's message natively gets the card in the agent's first reply. banner: the hook's systemMessage holds the banner (the Claude Code CLI in a terminal, Gemini CLI); hook-card: the hook's systemMessage holds the card, drawn inline with the first prompt (Codex); reply: the agent opens its first reply with the card (Claude Code's desktop app, IDE extensions and SDK, Cursor, Antigravity). A run with no known harness (a manual run, an unknown host) keeps the banner, as before. Pure."
|
|
2
|
+
export function displayMode(harness, env = process.env) {
|
|
3
|
+
if (harness === 'claude') {
|
|
4
|
+
// Claude Code says where it runs; an older CLI that does not say is the terminal.
|
|
5
|
+
const entry = String(env.CLAUDE_CODE_ENTRYPOINT ?? '');
|
|
6
|
+
return entry === '' || entry === 'cli' ? 'banner' : 'reply';
|
|
7
|
+
}
|
|
8
|
+
if (harness === 'codex') return 'hook-card';
|
|
9
|
+
if (harness === 'gemini' || harness === 'other') return 'banner';
|
|
10
|
+
return 'reply';
|
|
11
|
+
}
|
package/hooks/pre-pr.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// @comment -- "bravos's pre-PR gate entry, two ways. As the opt-in PreToolUse hook it reads the hook payload from stdin, gates only Bash commands that run gh pr create or gh pr ready, and exits 2 with the reason on stderr to block; every other command, unparseable input and BRAVOS_PRE_PR=off exit 0. Run by hand (--check, or no stdin / a TTY) it gates the current branch before any PR exists: exit 2 on lint errors, a confirmed claim on a changed file without a @ticket, or an input that fails; new exposures are printed to disclose, not blocked on. The repo root is git's top level for the working directory, never the payload cwd as given."
|
|
2
2
|
import { entitled, refusal, status as licenceStatus } from './lib/licence.mjs';
|
|
3
|
+
import { audience } from './lib/audience.mjs';
|
|
3
4
|
import { prAction, resolveRoot, runGate } from './lib/pre-pr.mjs';
|
|
4
5
|
|
|
5
6
|
async function readStdin() {
|
|
@@ -21,6 +22,8 @@ function finish({ decision, reason }, check) {
|
|
|
21
22
|
async function main() {
|
|
22
23
|
const env = process.env;
|
|
23
24
|
if (env.BRAVOS_PRE_PR === 'off') process.exit(0);
|
|
25
|
+
// A machine without Bravos: the gate is the team's Bravos feature, not this person's; say nothing and block nothing.
|
|
26
|
+
if (audience(env).kind === 'none') process.exit(0);
|
|
24
27
|
// Without a Team licence the gate stands down: one line on stderr (never a block), so a teammate
|
|
25
28
|
// without a seat still opens their PR and knows why nothing was checked.
|
|
26
29
|
const lic = licenceStatus(env);
|
package/hooks/session-start.mjs
CHANGED
|
@@ -3,7 +3,9 @@ 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, collect, firstReplyStatus, readVersion, sessionHookRegistered, statusCard } 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';
|
|
@@ -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,
|
|
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
|
-
|
|
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,12 +131,12 @@ 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 -- "
|
|
116
|
-
if (
|
|
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') &&
|
|
139
|
+
if (env.BRAVOS_BANNER !== 'off' && (source === null || source === 'startup') && mode !== 'reply') {
|
|
121
140
|
const version = readVersion(dirname(fileURLToPath(import.meta.url)));
|
|
122
141
|
// Gemini and Codex draw a hook's message as plain text, so they get no colour codes.
|
|
123
142
|
const color = !env.NO_COLOR && env.BRAVOS_BANNER_COLOR !== 'off' && harness !== 'gemini' && harness !== 'codex';
|
|
@@ -125,11 +144,20 @@ async function main() {
|
|
|
125
144
|
const { theme } = resolveTheme(env);
|
|
126
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."
|
|
127
146
|
// The leading newline puts the logo on its own lines: Claude Code prefixes the first line with "SessionStart:startup says:".
|
|
128
|
-
out.systemMessage =
|
|
147
|
+
out.systemMessage = mode === 'hook-card' ? statusCard(inputs, { harness, version }) : '\n' + buildBanner(inputs, { harness, version, color, theme, columns: terminalColumns(env) });
|
|
129
148
|
}
|
|
130
149
|
} catch (e) {
|
|
131
150
|
text = `bravos briefing failed: ${e instanceof Error ? e.message : String(e)}`;
|
|
132
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
|
+
}
|
|
133
161
|
if (harness === 'cursor') {
|
|
134
162
|
// Cursor's sessionStart output: additional_context reaches the model; nothing is shown to the person.
|
|
135
163
|
process.stdout.write(JSON.stringify({ additional_context: text }) + '\n');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bugb-technologies/bravos",
|
|
3
|
-
"version": "1.
|
|
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",
|
package/templates/omp/bravos.js
CHANGED
|
@@ -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. 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. 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
|
|
|
@@ -12,6 +12,13 @@ export default {
|
|
|
12
12
|
const ready = (async () => {
|
|
13
13
|
try {
|
|
14
14
|
const lib = await import(pathToFileURL(join(root, '.bravos', 'hooks', 'lib', 'briefing.mjs')).href);
|
|
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
|
+
}
|
|
15
22
|
const inputs = await lib.collect(root, process.env);
|
|
16
23
|
briefing = lib.buildBriefing(inputs);
|
|
17
24
|
// An older .bravos/hooks copy has no card yet; the briefing still goes in.
|
|
@@ -22,7 +29,9 @@ export default {
|
|
|
22
29
|
})();
|
|
23
30
|
const add = (withCard) => async (request) => {
|
|
24
31
|
await ready;
|
|
25
|
-
|
|
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 });
|
|
26
35
|
};
|
|
27
36
|
const handles = [];
|
|
28
37
|
for (const [name, withCard] of [['context', true], ['compaction', false]]) {
|