@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/cli.js +4 -4
- package/dist/context.js +36 -0
- package/dist/guide.js +2 -2
- package/dist/palette.js +4 -4
- package/dist/review-server.js +4 -4
- package/dist/review.js +103 -18
- package/dist/watch-frame.js +67 -42
- package/dist/watch.js +21 -7
- package/docs/GUIDE.md +2 -2
- package/docs/UPGRADING.md +8 -0
- package/hooks/lib/briefing.mjs +185 -166
- package/hooks/lib/palette.mjs +4 -4
- package/hooks/session-start.mjs +24 -2
- package/package.json +1 -1
- package/skills/bravos-context/SKILL.md +1 -0
- package/templates/review/review.html +368 -123
package/dist/cli.js
CHANGED
|
@@ -11,7 +11,7 @@ import { writeCursorPointer } from './cursor.js';
|
|
|
11
11
|
import { writeOmpExtension } from './omp.js';
|
|
12
12
|
import { homeOf, installGlobal } from './global.js';
|
|
13
13
|
import { uninstall } from './uninstall.js';
|
|
14
|
-
import { checkKind, newToken, readAllAnswers, readDraft, renderReview, summarize, writePage } from './review.js';
|
|
14
|
+
import { checkKind, newToken, prepareReview, readAllAnswers, readDraft, renderReview, summarize, writePage } from './review.js';
|
|
15
15
|
import { addSource, checkSources, declineContext, gateFor, installPrePush, listSources, updateSource } from './context.js';
|
|
16
16
|
import { formatRules, gatherRules } from './rules.js';
|
|
17
17
|
import { spawn as spawnChild, spawnSync } from 'node:child_process';
|
|
@@ -777,7 +777,7 @@ export function buildProgram(io, result) {
|
|
|
777
777
|
return;
|
|
778
778
|
}
|
|
779
779
|
if (opts.share) {
|
|
780
|
-
const rel = writePage(root, `${kind}-share`, await renderReview(draft, { kind: 'artifact' }));
|
|
780
|
+
const rel = writePage(root, `${kind}-share`, await renderReview(await prepareReview(root, draft), { kind: 'artifact' }));
|
|
781
781
|
lines.push(`Share page: ${rel}`);
|
|
782
782
|
lines.push('Sharing publishes your security intent to claude.ai, private until you share the link; teammates need access there.');
|
|
783
783
|
lines.push('In Claude Code: publish that file with the Artifact tool and capabilities {db: {}}; share the link with the team.');
|
|
@@ -786,8 +786,8 @@ export function buildProgram(io, result) {
|
|
|
786
786
|
return;
|
|
787
787
|
}
|
|
788
788
|
if (opts.serve === false) {
|
|
789
|
-
const rel = writePage(root, kind, await renderReview(draft, { kind: 'file' }));
|
|
790
|
-
lines.push(`Review page: ${rel} (Save downloads your answers; put them in .guardlink/${kind}-answers/ and commit)`);
|
|
789
|
+
const rel = writePage(root, kind, await renderReview(await prepareReview(root, draft), { kind: 'file' }));
|
|
790
|
+
lines.push(`Review page: ${rel} (includes available cited document text; Save downloads your answers; put them in .guardlink/${kind}-answers/ and commit)`);
|
|
791
791
|
if (opts.open !== false)
|
|
792
792
|
openInBrowser(pathJoin(root, rel), io.env);
|
|
793
793
|
return;
|
package/dist/context.js
CHANGED
|
@@ -80,6 +80,42 @@ function loadIndex(root, L) {
|
|
|
80
80
|
throw new BravosError([`${L.INDEX_PATH} needs fixing before anything is added to it:`, ...parsed.problems.map((p) => ` ${p.message}`), 'bravos context check shows the same list.'].join('\n'));
|
|
81
81
|
return parsed.sources;
|
|
82
82
|
}
|
|
83
|
+
// @comment -- "Only the local review includes document bodies. Use the context store's regular-file reader, match the recorded hash and recheck the exact bytes before displaying them. The draft can cite an id, never choose a path. Keep the total payload bounded even in a large store."
|
|
84
|
+
// @mitigates #context-sources against #untrusted-index-path using #derived-source-path -- "A citation selects an indexed source by id. Its Markdown file must resolve to its own location under the store and match the recorded digest."
|
|
85
|
+
export async function reviewSources(root, cited) {
|
|
86
|
+
if (!cited.size)
|
|
87
|
+
return [];
|
|
88
|
+
const lib = await contextLib();
|
|
89
|
+
const reader = lib.treeReader(root);
|
|
90
|
+
const index = reader.read(lib.INDEX_PATH);
|
|
91
|
+
if (!index)
|
|
92
|
+
return [];
|
|
93
|
+
const parsed = lib.parseIndex(index.toString('utf8'));
|
|
94
|
+
if (parsed.problems.length)
|
|
95
|
+
return [];
|
|
96
|
+
const names = reader.list(lib.SOURCES_DIR).map((entry) => entry.name);
|
|
97
|
+
const who = whoAmI(process.env);
|
|
98
|
+
const docs = [];
|
|
99
|
+
let remaining = 8 * 1024 * 1024;
|
|
100
|
+
for (const { id, title, kind, bytes, sha256 } of parsed.sources) {
|
|
101
|
+
if (!cited.has(id) || bytes > Math.min(remaining, lib.MAX_SOURCE_BYTES))
|
|
102
|
+
continue;
|
|
103
|
+
const name = lib.fileFor(id, names);
|
|
104
|
+
const data = name ? reader.read(`${lib.SOURCES_DIR}/${name}`) : null;
|
|
105
|
+
if (!data || data.length !== bytes || lib.sha256(data) !== sha256)
|
|
106
|
+
continue;
|
|
107
|
+
try {
|
|
108
|
+
vet(Buffer.from(title), lib, who, id);
|
|
109
|
+
const text = vet(data, lib, who, id);
|
|
110
|
+
docs.push({ id, title, kind, sha256, text });
|
|
111
|
+
remaining -= bytes;
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
// The review still shows the citation. Only verified, safe text may accompany it.
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return docs;
|
|
118
|
+
}
|
|
83
119
|
function writeAtomic(abs, data) {
|
|
84
120
|
const tmp = `${abs}.writing-${process.pid}`;
|
|
85
121
|
writeFileSync(tmp, data, { mode: 0o644 });
|
package/dist/guide.js
CHANGED
|
@@ -45,7 +45,7 @@ export const GUIDE_TOPICS = [
|
|
|
45
45
|
body: [
|
|
46
46
|
'Run bravos next in a shell (free): it shows which of the nine steps are done here, in the order they build on each other — the code graph first (a machine step every later skill reads), then what the app intends, annotation coverage, SAST (which reads the annotations), how findings are proven and a test target, then the gates (autopilot, the pre-PR gate, CI, cheap to switch on any time) — what each unlocks, and the exact command for the next one. The banner shows the next step too, and every harness gives it to the agent, which offers a few starts the first time and suggests the next step at natural moments.',
|
|
47
47
|
'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.',
|
|
48
|
-
'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.',
|
|
48
|
+
'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.',
|
|
49
49
|
],
|
|
50
50
|
},
|
|
51
51
|
{
|
|
@@ -117,7 +117,7 @@ export const GUIDE_TOPICS = [
|
|
|
117
117
|
{ name: 'See which design rules hold', skills: ['bravos', 'bravos-recheck'], body: ['bravos rules lists every rule your design states (INV-n in the intent) with its status: broken (a test got through), retest due (the code under it changed since it was tested), unguarded (it can break somewhere and nothing stops it), guarded but untested, not placed (no code is tied to it yet), or holds (a test tried and was refused everywhere it is enforced). Each line names the document the rule came from and the places it is enforced. bravos dashboard shows the same as its Design rules tab, worst first, beside GuardLink\'s threat model. Free, read-only, no model; --json prints bravos.rules/v1. On the Team plan the pre-PR check and the PR workflow hold a pull request that changes a file a holding rule is enforced in (the check, or the role table that grants the permission) after that rule was last tested, until its test is replayed or the PR body names the rule; the after-edit note says the same while you work.'] },
|
|
118
118
|
{ name: 'Context comes first', skills: ['bravos-context', 'bravos-annotate'], body: ['Threat-modelling starts only when a named person has confirmed what the product intends: bravos-annotate, campaigns and the nightly workflows wait until at least one item in .guardlink/intent.md is confirmed (run bravos-context; it asks for your design documents and a few decisions). A team that chooses to go without records that under a name, bravos context decline --by "<name>", which is committed like the intent; a coding agent is told never to decline for you. bravos context gate says which state a repository is in. Rechecks, retests and the ship check are not held back: they maintain a model that already exists.'] },
|
|
119
119
|
{ name: 'Threat-model someone else\'s project', skills: ['bravos-context', 'bravos-annotate'], body: ['bravos-context assumes you are researching software you do not own (an open-source project, a vendor\'s code): it drafts the intent from upstream\'s own docs with links and asks only the scope decisions — which configuration to rate against (shipped defaults or the hardened setup upstream recommends), single organisation or multi-tenant, which attackers are in scope, and the intended-looking behaviours upstream does not document. intent.md records them as Assumptions, and severities are rated against them. Say "this is our product" for the owner interview instead.'] },
|
|
120
|
-
{ name: 'Answer bravos\'s questions as a team', skills: ['bravos-context'], body: ['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
|
|
120
|
+
{ name: 'Answer bravos\'s questions as a team', skills: ['bravos-context'], body: ['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.'] },
|
|
121
121
|
{ name: 'I wrote security-relevant code', skills: ['bravos-annotate'], body: ['Annotates what you changed to guardlink\'s evidence bar and runs the lint gate until clean.'] },
|
|
122
122
|
{ name: 'Cover the whole repo', skills: ['bravos-campaign'], body: ['Rounds of batches with subagents and rests, until the coverage goal or until you stop it.'] },
|
|
123
123
|
{ name: 'Is this exposure real?', skills: ['bravos-templatize', 'bravos-env', 'bravos-prove'], body: ['Template → authorized target → run. Only a reproduced run confirms; reading code never does.'] },
|
package/dist/palette.js
CHANGED
|
@@ -5,20 +5,20 @@ import { join } from 'node:path';
|
|
|
5
5
|
export const THEMES = {
|
|
6
6
|
dark: {
|
|
7
7
|
green: '#33d49d', blue: '#0360a2', light: '#f0f0f0', steel: '#55899e', red: '#ea1d1d',
|
|
8
|
-
slate: '#3b6779', amber: '#f0b429', line: '#2b4f5c',
|
|
8
|
+
slate: '#3b6779', amber: '#f0b429', line: '#2b4f5c', warm: '#ff9f5b', cool: '#51b2a9',
|
|
9
9
|
},
|
|
10
10
|
light: {
|
|
11
11
|
green: '#0f7a55', blue: '#0360a2', light: null, steel: '#3f6576', red: '#c41616',
|
|
12
|
-
slate: '#4d6b78', amber: '#9a6400', line: '#7d98a3',
|
|
12
|
+
slate: '#4d6b78', amber: '#9a6400', line: '#7d98a3', warm: '#88441d', cool: '#006c67',
|
|
13
13
|
},
|
|
14
14
|
neutral: {
|
|
15
15
|
green: '#1e9a6c', blue: '#2f7fc1', light: null, steel: '#4f8296', red: '#e02424',
|
|
16
|
-
slate: '#5a7d8b', amber: '#b07a00', line: '#5a7d8b',
|
|
16
|
+
slate: '#5a7d8b', amber: '#b07a00', line: '#5a7d8b', warm: '#ad6131', cool: '#2c8980',
|
|
17
17
|
},
|
|
18
18
|
};
|
|
19
19
|
export const FIXED = {
|
|
20
20
|
green: '#33d49d', blue: '#0360a2', light: '#f0f0f0', steel: '#55899e', red: '#dc1f1f',
|
|
21
|
-
slate: '#3b6779', amber: '#f0b429', line: '#2b4f5c', ink: '#0e1b21', deep: '#1f3943', white: '#ffffff',
|
|
21
|
+
slate: '#3b6779', amber: '#f0b429', line: '#2b4f5c', warm: '#ff9f5b', cool: '#51b2a9', ink: '#0e1b21', deep: '#1f3943', white: '#ffffff',
|
|
22
22
|
};
|
|
23
23
|
export const THEME_NAMES = ['dark', 'light', 'neutral'];
|
|
24
24
|
export const isTheme = (t) => THEME_NAMES.includes(t);
|
package/dist/review-server.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// @comment -- "Detached child that serves one review: argv root, kind, token, port. Started by bravos review so the command can return at once in any harness; it exits on Done or after 30 minutes idle."
|
|
2
|
-
import { readDraft, renderReview, startReviewServer } from './review.js';
|
|
2
|
+
import { prepareReview, readDraft, renderReview, startReviewServer } from './review.js';
|
|
3
3
|
const [root, kind, token, port] = process.argv.slice(2);
|
|
4
|
-
const
|
|
5
|
-
const page = await renderReview(
|
|
6
|
-
const { server } = await startReviewServer(root, draft, page, token, Number(port));
|
|
4
|
+
const review = await prepareReview(root, readDraft(root, kind));
|
|
5
|
+
const page = await renderReview(review, { kind: 'serve', token });
|
|
6
|
+
const { server } = await startReviewServer(root, review.draft, page, token, Number(port));
|
|
7
7
|
server.on('close', () => process.exit(0));
|
package/dist/review.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
1
2
|
import { randomBytes } from 'node:crypto';
|
|
2
|
-
import { existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
3
4
|
import { createServer } from 'node:http';
|
|
4
5
|
import { dirname, join } from 'node:path';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
6
|
+
import { reviewSources } from './context.js';
|
|
7
|
+
import { templatesDir } from './paths.js';
|
|
7
8
|
import { BravosError } from './types.js';
|
|
8
9
|
// @comment -- "bravos review: the drafts an agent wrote (.guardlink/<kind>-draft.json) rendered as a bravos-branded page people answer in, a loopback-only server that saves each person's answers to .guardlink/<kind>-answers/<name>.json, and a plain-text summary of agreement and disagreement for the agent. Draft text comes from repo files and is untrusted: it travels as JSON and the page renders it with textContent."
|
|
9
10
|
export const REVIEW_SCHEMA = 'bravos.review/v1';
|
|
@@ -32,9 +33,12 @@ export function validateDraft(value, kind) {
|
|
|
32
33
|
throw bad(`kind must be '${kind}'`);
|
|
33
34
|
if (!Array.isArray(value.questions) || value.questions.length === 0 || value.questions.length > 300)
|
|
34
35
|
throw bad('needs 1 to 300 questions');
|
|
36
|
+
if (value.repo !== undefined && !str(value.repo))
|
|
37
|
+
throw bad('repo must be a string');
|
|
35
38
|
if (value.perspective !== undefined && value.perspective !== 'researcher' && value.perspective !== 'owner')
|
|
36
39
|
throw bad('perspective must be researcher or owner');
|
|
37
40
|
const seen = new Set();
|
|
41
|
+
const cells = new Set();
|
|
38
42
|
for (const [n, q] of value.questions.entries()) {
|
|
39
43
|
if (!isObject(q))
|
|
40
44
|
throw bad(`question ${n + 1} is not an object`);
|
|
@@ -69,6 +73,22 @@ export function validateDraft(value, kind) {
|
|
|
69
73
|
throw bad(`${q.id}: an item needs its text`);
|
|
70
74
|
if (q.sources !== undefined && !(Array.isArray(q.sources) && q.sources.every((s) => str(s, 400))))
|
|
71
75
|
throw bad(`${q.id}: sources must be strings`);
|
|
76
|
+
if (q.permission !== undefined) {
|
|
77
|
+
const p = q.permission;
|
|
78
|
+
const label = (v) => typeof v === 'string' && v.trim().length > 0 && v.length <= 160;
|
|
79
|
+
if (!isObject(p) || !label(p.role) || !label(p.action) || (p.group !== undefined && !label(p.group)) || (p.effect !== 'allow' && p.effect !== 'deny')) {
|
|
80
|
+
throw bad(`${q.id}: permission needs a role, action and allow or deny effect`);
|
|
81
|
+
}
|
|
82
|
+
if (q.type !== 'item' || q.suggested !== 'agree' || !Array.isArray(q.sources) || !q.sources.some((s) => /\bSRC-[1-9][0-9]{0,4}\b/.test(s))) {
|
|
83
|
+
throw bad(`${q.id}: a permission must be an item with suggested agree and a stored source citation`);
|
|
84
|
+
}
|
|
85
|
+
if ((p.effect === 'deny' || q.confidence === 'low') && q.mustTouch !== true)
|
|
86
|
+
throw bad(`${q.id}: a denied or uncertain permission needs mustTouch`);
|
|
87
|
+
const key = JSON.stringify([p.group ?? (q.section || 'Permissions'), p.role, p.action]);
|
|
88
|
+
if (cells.has(key))
|
|
89
|
+
throw bad(`${q.id}: duplicate permission cell; combine its evidence in one question`);
|
|
90
|
+
cells.add(key);
|
|
91
|
+
}
|
|
72
92
|
}
|
|
73
93
|
return value;
|
|
74
94
|
}
|
|
@@ -81,7 +101,7 @@ export function validateAnswers(value, draft) {
|
|
|
81
101
|
if (!isObject(value.answers))
|
|
82
102
|
throw new BravosError('answers must be an object keyed by question id');
|
|
83
103
|
const ids = new Set(draft.questions.map((q) => q.id));
|
|
84
|
-
const answers =
|
|
104
|
+
const answers = Object.create(null);
|
|
85
105
|
for (const [id, a] of Object.entries(value.answers)) {
|
|
86
106
|
if (!ids.has(id) || !isObject(a))
|
|
87
107
|
continue;
|
|
@@ -125,9 +145,17 @@ export function readAllAnswers(root, draft) {
|
|
|
125
145
|
const skipped = [];
|
|
126
146
|
if (!existsSync(dir))
|
|
127
147
|
return { files, skipped };
|
|
148
|
+
const base = join(realpathSync(root), answersDir(draft.kind));
|
|
149
|
+
if (realpathSync(dir) !== base || !lstatSync(dir).isDirectory())
|
|
150
|
+
return { files, skipped: [answersDir(draft.kind)] };
|
|
128
151
|
for (const f of readdirSync(dir).filter((n) => n.endsWith('.json')).sort()) {
|
|
129
152
|
try {
|
|
130
|
-
|
|
153
|
+
const abs = join(base, f);
|
|
154
|
+
if (!lstatSync(abs).isFile() || realpathSync(abs) !== abs) {
|
|
155
|
+
skipped.push(f);
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
files.push(validateAnswers(JSON.parse(readFileSync(abs, 'utf8')), draft));
|
|
131
159
|
}
|
|
132
160
|
catch {
|
|
133
161
|
skipped.push(f);
|
|
@@ -135,17 +163,76 @@ export function readAllAnswers(root, draft) {
|
|
|
135
163
|
}
|
|
136
164
|
return { files, skipped };
|
|
137
165
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
166
|
+
// @comment -- "Review pages may contain a team's design documents and answers may contain names or comments. Write only below real repository directories, then atomically replace the destination so a pre-existing link cannot redirect the write."
|
|
167
|
+
function writeReviewFile(root, rel, data) {
|
|
168
|
+
let dir = realpathSync(root);
|
|
169
|
+
for (const part of dirname(rel).split(/[\\/]/)) {
|
|
170
|
+
dir = join(dir, part);
|
|
171
|
+
try {
|
|
172
|
+
mkdirSync(dir, { mode: 0o700 });
|
|
173
|
+
}
|
|
174
|
+
catch (e) {
|
|
175
|
+
if (e.code !== 'EEXIST')
|
|
176
|
+
throw e;
|
|
177
|
+
}
|
|
178
|
+
if (!lstatSync(dir).isDirectory() || realpathSync(dir) !== dir)
|
|
179
|
+
throw new BravosError(`refusing to write through a link in ${rel}`);
|
|
180
|
+
}
|
|
181
|
+
const temp = join(dir, `.bravos-${randomBytes(16).toString('hex')}.tmp`);
|
|
182
|
+
try {
|
|
183
|
+
writeFileSync(temp, data, { flag: 'wx', mode: 0o600 });
|
|
184
|
+
renameSync(temp, join(root, rel));
|
|
185
|
+
}
|
|
186
|
+
finally {
|
|
187
|
+
rmSync(temp, { force: true });
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
// @comment -- "Make the repository label a link only when the draft names the same project as this checkout's GitHub origin. Reconstruct a public HTTPS path so credentials, local paths and URL parameters never enter the page."
|
|
191
|
+
function reviewRepoUrl(root, label) {
|
|
192
|
+
if (!label)
|
|
193
|
+
return;
|
|
194
|
+
try {
|
|
195
|
+
const origin = execFileSync('git', ['config', '--get', 'remote.origin.url'], {
|
|
196
|
+
cwd: root, encoding: 'utf8', timeout: 1500, stdio: ['ignore', 'pipe', 'ignore'],
|
|
197
|
+
}).trim();
|
|
198
|
+
const match = /^(?:https:\/\/github\.com\/|git@github\.com:|ssh:\/\/git@github\.com\/)([a-z0-9-]+)\/([a-z0-9_.-]+?)\/?$/i.exec(origin);
|
|
199
|
+
if (!match)
|
|
200
|
+
return;
|
|
201
|
+
const owner = match[1], repo = match[2].replace(/\.git$/i, '');
|
|
202
|
+
if (!repo || repo === '.' || repo === '..')
|
|
203
|
+
return;
|
|
204
|
+
if (![repo, `${owner}/${repo}`].some((name) => name.toLowerCase() === label.toLowerCase()))
|
|
205
|
+
return;
|
|
206
|
+
return `https://github.com/${owner}/${repo}`;
|
|
207
|
+
}
|
|
208
|
+
catch {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
const citedIds = (q) => (q.sources ?? []).flatMap((s) => s.match(/\bSRC-[1-9][0-9]{0,4}\b/g) ?? []);
|
|
213
|
+
// @comment -- "Take one local evidence snapshot for both the page and the server that accepts answers. A permission whose citations cannot all be verified needs an explicit decision, even when the draft suggested accepting it."
|
|
214
|
+
export async function prepareReview(root, draft) {
|
|
215
|
+
const sources = await reviewSources(root, new Set(draft.questions.flatMap(citedIds)));
|
|
216
|
+
const verified = new Set(sources.map((s) => s.id));
|
|
217
|
+
const questions = draft.questions.map((q) => {
|
|
218
|
+
if (!q.permission)
|
|
219
|
+
return q;
|
|
220
|
+
const missing = [...new Set(citedIds(q).filter((id) => !verified.has(id)))];
|
|
221
|
+
if (!missing.length)
|
|
222
|
+
return q;
|
|
223
|
+
return { ...q, mustTouch: true, confidence: 'low',
|
|
224
|
+
reason: [q.reason, `Check ${missing.join(', ')} before deciding. Its source text could not be included and verified for this review.`].filter(Boolean).join(' ') };
|
|
225
|
+
});
|
|
226
|
+
return { draft: { ...draft, questions }, sources, repoUrl: reviewRepoUrl(root, draft.repo) };
|
|
142
227
|
}
|
|
143
|
-
// @comment -- "
|
|
144
|
-
export async function renderReview(
|
|
228
|
+
// @comment -- "Embed the draft as inert JSON with escaped tag delimiters. Only a local review may add verified document bodies. Shared artifacts carry the citations and excerpts already present in the draft."
|
|
229
|
+
export async function renderReview(review, mode) {
|
|
145
230
|
const template = readFileSync(join(templatesDir(), 'review', 'review.html'), 'utf8');
|
|
146
|
-
const
|
|
231
|
+
const prepared = 'schema' in review ? { draft: review, sources: [], repoUrl: undefined } : review;
|
|
232
|
+
const { draft, repoUrl } = prepared;
|
|
233
|
+
const sources = mode.kind === 'artifact' ? [] : prepared.sources;
|
|
147
234
|
const heading = draft.kind !== 'intent' ? `bravos asks: ${draft.kind}` : draft.perspective === 'owner' ? 'What does this product intend?' : `How should bravos judge ${draft.repo ?? 'this project'}?`;
|
|
148
|
-
const data = JSON.stringify({ draft, mode, heading,
|
|
235
|
+
const data = JSON.stringify({ draft, mode, heading, sources, repoUrl }).replace(/</g, '\\u003c').replace(/[\u2028\u2029]/g, (c) => `\\u${c.charCodeAt(0).toString(16)}`);
|
|
149
236
|
const page = template.replace('__BRAVOS_DATA__', () => data);
|
|
150
237
|
// On claude.ai the runtime bridge supplies the shared database, so the page drops its own CSP there.
|
|
151
238
|
return mode.kind === 'artifact' ? page.replace(/<meta http-equiv="Content-Security-Policy"[^>]*>\n?/, '') : page;
|
|
@@ -166,7 +253,7 @@ export function summarize(draft, files, skipped = []) {
|
|
|
166
253
|
if (skipped.length)
|
|
167
254
|
out.push(`skipped unreadable answer files: ${skipped.join(', ')}`);
|
|
168
255
|
const groups = { DISAGREE: [], EDITED: [], DECIDED: [], 'NO ANSWER': [] };
|
|
169
|
-
const accepted =
|
|
256
|
+
const accepted = Object.create(null);
|
|
170
257
|
let acceptedCount = 0;
|
|
171
258
|
for (const q of draft.questions) {
|
|
172
259
|
const rows = files.map((f) => ({ by: f.by, a: f.answers[q.id] })).filter((r) => !!r.a);
|
|
@@ -243,8 +330,7 @@ export function startReviewServer(root, draft, page, token, port = 0) {
|
|
|
243
330
|
if (missing.length)
|
|
244
331
|
return send(400, `these decisions still need your call: ${missing.join(', ')}`);
|
|
245
332
|
const rel = `${answersDir(draft.kind)}/${slug(a.by)}.json`;
|
|
246
|
-
|
|
247
|
-
writeFileSync(join(root, rel), JSON.stringify(a, null, 2) + '\n');
|
|
333
|
+
writeReviewFile(root, rel, JSON.stringify(a, null, 2) + '\n');
|
|
248
334
|
send(200, JSON.stringify({ saved: rel }), 'application/json');
|
|
249
335
|
}
|
|
250
336
|
catch (e) {
|
|
@@ -268,7 +354,6 @@ export const newToken = () => randomBytes(16).toString('hex');
|
|
|
268
354
|
// @comment -- "Writes the rendered page for file mode (no server) to .bravos/review/<kind>.html and returns its path."
|
|
269
355
|
export function writePage(root, kind, page) {
|
|
270
356
|
const rel = `.bravos/review/${checkKind(kind)}.html`;
|
|
271
|
-
|
|
272
|
-
writeFileSync(join(root, rel), page);
|
|
357
|
+
writeReviewFile(root, rel, page);
|
|
273
358
|
return rel;
|
|
274
359
|
}
|
package/dist/watch-frame.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { stripVTControlCharacters } from 'node:util';
|
|
1
2
|
import { bgFor, fgFor } from './palette.js';
|
|
2
3
|
// @comment -- "Draws bravos watch's frames: a header bar, a row of number tiles, bordered panels (setup, threat model, test next, top threats and assets, code graph, SAST, branch and team, the model's size, activity) arranged in three, two or one columns by terminal width, a scrollable body and a key bar. Pure: text in, text out. Colour is added per segment after layout, so the plain and coloured frames have the same characters, and every glyph that carries meaning (severity, bars) differs in plain text too."
|
|
3
4
|
/* ------------------------------------------------------------------ segments */
|
|
@@ -15,6 +16,8 @@ const C = {
|
|
|
15
16
|
amber: 'amber',
|
|
16
17
|
white: 'white',
|
|
17
18
|
line: 'line',
|
|
19
|
+
warm: 'warm',
|
|
20
|
+
cool: 'cool',
|
|
18
21
|
};
|
|
19
22
|
const s = (t, c, b, bg) => ({ t, c, b, bg });
|
|
20
23
|
const len = (l) => l.reduce((n, x) => n + [...x.t].length, 0);
|
|
@@ -97,20 +100,20 @@ function sevBar(by, width) {
|
|
|
97
100
|
big.w = Math.max(0, big.w + width - used);
|
|
98
101
|
return parts.filter((p) => p.w > 0).map((p) => s(sevGlyph[p.k].repeat(p.w), sevColor(p.k)));
|
|
99
102
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
+
// A solid warm chip signals attention (pending setup or a confirmed hypothesis).
|
|
104
|
+
// A shaded cool chip marks a completed step or a refuted hypothesis.
|
|
105
|
+
const chip = (attention) => attention ? s('██ ', C.warm) : s('░░ ', C.cool);
|
|
106
|
+
/** One chip per tested hypothesis while they fit. Beyond that, show the same
|
|
107
|
+
* distribution proportionally and retain both outcomes when both are present. */
|
|
108
|
+
function outcomeChips(confirmed, refuted, inner) {
|
|
109
|
+
const total = confirmed + refuted;
|
|
103
110
|
if (!total)
|
|
104
|
-
return [s('
|
|
105
|
-
const
|
|
106
|
-
let
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
out.push(s(p.glyph.repeat(w), p.c));
|
|
111
|
-
used += Math.max(0, w);
|
|
112
|
-
});
|
|
113
|
-
return out;
|
|
111
|
+
return [s('No tested outcomes yet', C.steel)];
|
|
112
|
+
const slots = Math.min(total, Math.floor(inner / 3));
|
|
113
|
+
let warm = Math.round(confirmed / total * slots);
|
|
114
|
+
if (confirmed && refuted)
|
|
115
|
+
warm = Math.max(1, Math.min(slots - 1, warm));
|
|
116
|
+
return Array.from({ length: slots }, (_, i) => chip(i < warm));
|
|
114
117
|
}
|
|
115
118
|
const SPARK = '▁▂▃▄▅▆▇█';
|
|
116
119
|
/** A sparkline of values, scaled between their min and max; flat when they do not move. */
|
|
@@ -163,9 +166,9 @@ function tiles(items, width) {
|
|
|
163
166
|
});
|
|
164
167
|
return rows;
|
|
165
168
|
}
|
|
166
|
-
function setupPanel(sn
|
|
169
|
+
function setupPanel(sn) {
|
|
167
170
|
const pct = sn.setup.total ? Math.round((sn.setup.done / sn.setup.total) * 100) : 0;
|
|
168
|
-
const body = [
|
|
171
|
+
const body = [sn.setup.items.map((item) => chip(!item.on)), [s(`${sn.setup.total - sn.setup.done} pending · ${sn.setup.done} complete`, C.steel)]];
|
|
169
172
|
for (const x of sn.setup.items) {
|
|
170
173
|
const isNext = sn.setup.next && x.label === sn.setup.next.label;
|
|
171
174
|
body.push(x.on ? [s('✔ ', C.green), s(x.label)] : isNext ? [s('▸ ', C.green, true), s(x.label, C.green, true)] : [s('· ', C.slate), s(x.label, C.steel)]);
|
|
@@ -177,7 +180,7 @@ function setupPanel(sn, inner) {
|
|
|
177
180
|
}
|
|
178
181
|
else
|
|
179
182
|
body.push([], [s('everything bravos can use here is on', C.green)]);
|
|
180
|
-
return { title: 'SETUP', right: `${sn.setup.done}/${sn.setup.total}
|
|
183
|
+
return { title: 'SETUP', right: `${sn.setup.done}/${sn.setup.total} · ${pct}%`, rightColor: C.green, body };
|
|
181
184
|
}
|
|
182
185
|
function modelPanel(sn, inner, history) {
|
|
183
186
|
if (!sn.counts) {
|
|
@@ -193,13 +196,10 @@ function modelPanel(sn, inner, history) {
|
|
|
193
196
|
const L = sn.ledger;
|
|
194
197
|
const total = L.untested + L.confirmed + L.refuted + L.retest;
|
|
195
198
|
body.push([]);
|
|
196
|
-
body.push([s('tested ', C.steel), s(`${L.confirmed + L.refuted}/${total}`, C.light, true)
|
|
197
|
-
body.push(
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
{ n: L.refuted, glyph: '▒', c: C.green },
|
|
201
|
-
{ n: L.untested, glyph: '░', c: C.line },
|
|
202
|
-
], inner));
|
|
199
|
+
body.push([s('tested ', C.steel), s(`${L.confirmed + L.refuted}/${total}`, C.light, true)]);
|
|
200
|
+
body.push(outcomeChips(L.confirmed, L.refuted, inner));
|
|
201
|
+
body.push([s(`${L.confirmed} confirmed`, C.warm), s(' · ', C.steel), s(`${L.refuted} refuted`, C.cool)]);
|
|
202
|
+
body.push([s(`${L.untested} untested · ${L.retest} awaiting retest`, C.steel)]);
|
|
203
203
|
}
|
|
204
204
|
if (sn.boundaries) {
|
|
205
205
|
const B = sn.boundaries;
|
|
@@ -458,17 +458,30 @@ const kindIcon = {
|
|
|
458
458
|
report: ['❏', C.green],
|
|
459
459
|
workspace: ['⇄', C.blue],
|
|
460
460
|
};
|
|
461
|
+
// @comment -- "Event text can include repository-controlled filenames and local log contents. Display it as plain text in the activity panel and detail view, without terminal control sequences or injected rows."
|
|
462
|
+
const eventText = (value) => stripVTControlCharacters(value).replace(/[\x00-\x1f\x7f-\x9f\u202a-\u202e\u2066-\u2069]/g, ' ').trim();
|
|
463
|
+
export function activityOverlay(events) {
|
|
464
|
+
const rows = [`ACTIVITY · ${events.length} retained event${events.length === 1 ? '' : 's'}`];
|
|
465
|
+
if (!events.length)
|
|
466
|
+
return [...rows, '', 'No changes recorded yet.'];
|
|
467
|
+
for (const event of [...events].reverse()) {
|
|
468
|
+
rows.push('', `${eventText(event.at)} ${eventText(event.kind)}`, eventText(event.text));
|
|
469
|
+
if (event.hint)
|
|
470
|
+
rows.push('→ ' + eventText(event.hint));
|
|
471
|
+
}
|
|
472
|
+
return rows;
|
|
473
|
+
}
|
|
461
474
|
function activityPanel(events, max, title = 'ACTIVITY') {
|
|
462
475
|
const body = [];
|
|
463
476
|
if (!events.length)
|
|
464
477
|
body.push([s('nothing yet — changes appear here as you and the agent work', C.steel)]);
|
|
465
478
|
for (const e of events.slice(-max).reverse()) {
|
|
466
479
|
const [icon, c] = kindIcon[e.kind] ?? ['·', C.steel];
|
|
467
|
-
body.push([s(time(e.at) + ' ', C.steel), s(icon + ' ', c), s(e.kind === 'autopilot' ? 'autopilot ' : '', C.green, true), s(e.text, e.kind === 'confirmed' ? C.red : undefined)]);
|
|
480
|
+
body.push([s(time(e.at) + ' ', C.steel), s(icon + ' ', c), s(e.kind === 'autopilot' ? 'autopilot ' : '', C.green, true), s(eventText(e.text), e.kind === 'confirmed' ? C.red : undefined)]);
|
|
468
481
|
if (e.hint)
|
|
469
|
-
body.push([s(' → ' + e.hint, C.slate)]);
|
|
482
|
+
body.push([s(' → ' + eventText(e.hint), C.slate)]);
|
|
470
483
|
}
|
|
471
|
-
return { title, right: `${events.length} event${events.length === 1 ? '' : 's'}`, body };
|
|
484
|
+
return { title, right: `${events.length} event${events.length === 1 ? '' : 's'} · a full log`, body };
|
|
472
485
|
}
|
|
473
486
|
/** Three columns from 150, two from 110, one bordered column from 80, compact below. */
|
|
474
487
|
export const layoutFor = (width, compact = false) => (compact || width < 80 ? 'compact' : width >= 150 ? 'wide' : width >= 110 ? 'two' : 'pane');
|
|
@@ -478,6 +491,7 @@ const KEYS = [
|
|
|
478
491
|
['d', 'dashboard'],
|
|
479
492
|
['g', 'graph'],
|
|
480
493
|
['t', 'test-next'],
|
|
494
|
+
['a', 'activity'],
|
|
481
495
|
['i', 'intent'],
|
|
482
496
|
['p', 'report'],
|
|
483
497
|
['s', 'services'],
|
|
@@ -489,7 +503,7 @@ const KEYS = [
|
|
|
489
503
|
['q', 'quit'],
|
|
490
504
|
];
|
|
491
505
|
// Keys dropped first when the bar does not fit; quit always stays.
|
|
492
|
-
const DROP_ORDER = ['c', 'u', 'o', 's', 'd', '?', 'i', 'p', 't', 'r', 'g', 'j/k', 'n'];
|
|
506
|
+
const DROP_ORDER = ['c', 'u', 'o', 's', 'd', '?', 'i', 'p', 't', 'r', 'g', 'a', 'j/k', 'n'];
|
|
493
507
|
function keyBar(width) {
|
|
494
508
|
let keys = KEYS;
|
|
495
509
|
const chips = (ks) => ks.flatMap(([k, label]) => [s(` ${k} `, C.ink, true, C.green), s(` ${label} `, C.steel)]);
|
|
@@ -500,18 +514,29 @@ function keyBar(width) {
|
|
|
500
514
|
}
|
|
501
515
|
return chips(keys);
|
|
502
516
|
}
|
|
517
|
+
// The supplied Bravos SVG sampled at 12 × 8 pixels, two vertical pixels per cell.
|
|
518
|
+
const WATCH_MARK = [' ▄████▄ ', '▄▄ ██████ ▄▄', '██▄█▄██▄█▄██', ' ▄▄██▀▀██▄▄ '];
|
|
503
519
|
function header(sn, width, opts) {
|
|
504
|
-
const
|
|
505
|
-
const
|
|
506
|
-
const
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
520
|
+
const status = s(opts.status ?? '● live', opts.status?.startsWith('updating') ? C.amber : C.green, true);
|
|
521
|
+
const plan = s(sn.plan.label, sn.plan.licensed ? C.green : C.amber);
|
|
522
|
+
const branch = `${sn.branch ?? '(detached)'} @ ${sn.sha}`;
|
|
523
|
+
const stats = opts.stats;
|
|
524
|
+
const refresh = stats ? `refresh #${stats.refreshes}${stats.lastMs !== null ? ` · ${(stats.lastMs / 1000).toFixed(1)}s` : ''} · ` : '';
|
|
525
|
+
const cost = s(refresh + '0 tokens', C.steel);
|
|
526
|
+
if (opts.compact || width < 80 || (opts.height !== undefined && opts.height < 16)) {
|
|
527
|
+
const brand = [s('bravos watch', C.green, true), s(' · by bugb', C.steel)];
|
|
528
|
+
const context = [s(` ${sn.repo} ${branch} `, C.steel), plan, s(' '), cost];
|
|
529
|
+
return [[...fitLine([...brand, ...context], Math.max(0, width - len([status]) - 2)), s(' '), status]];
|
|
530
|
+
}
|
|
531
|
+
const info = [
|
|
532
|
+
[s('bravos watch', C.light, true)], [s('by bugb', C.steel)],
|
|
533
|
+
[s(sn.repo, C.light, true), s(` ${branch}`, C.steel)], [plan],
|
|
510
534
|
];
|
|
511
|
-
const
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
535
|
+
const right = [[status], [cost], [], []];
|
|
536
|
+
return WATCH_MARK.map((mark, i) => {
|
|
537
|
+
const left = [s(mark, C.green), s(' '), ...info[i]];
|
|
538
|
+
return [...fitLine(left, width - len(right[i]), true), ...right[i]];
|
|
539
|
+
});
|
|
515
540
|
}
|
|
516
541
|
function tileItems(sn) {
|
|
517
542
|
const c = sn.counts;
|
|
@@ -554,20 +579,20 @@ export function renderFrame(sn, events, opts) {
|
|
|
554
579
|
const color = opts.color ?? false;
|
|
555
580
|
const layout = layoutFor(width, opts.compact);
|
|
556
581
|
const history = opts.history ?? [];
|
|
557
|
-
const top =
|
|
582
|
+
const top = header(sn, width, opts);
|
|
558
583
|
let body;
|
|
559
584
|
if (layout === 'compact') {
|
|
560
585
|
const c = sn.counts;
|
|
561
586
|
top.push([s(`setup ${sn.setup.done}/${sn.setup.total}`, C.green, true), s(sn.setup.next ? ` · next ${sn.setup.next.cta}` : '', C.steel)], c ? [s(`open ${c.open}`, C.amber, true), s(` · high ${(c.bySeverity.critical ?? 0) + (c.bySeverity.high ?? 0)}`, C.red), s(` · confirmed ${c.confirmed} · coverage ${sn.coverage?.percent ?? '?'}%`)] : [s('counts unknown', C.amber)]);
|
|
562
587
|
const w = width;
|
|
563
|
-
body = stack([activityPanel(events, 4, 'CHANGED JUST NOW'), ...opt(servicesPanel(sn, w - 4)), nextPanel(sn, 3, w - 4), modelPanel(sn, w - 4, history), reportPanel(sn, w - 4), setupPanel(sn
|
|
588
|
+
body = stack([activityPanel(events, 4, 'CHANGED JUST NOW'), ...opt(servicesPanel(sn, w - 4)), nextPanel(sn, 3, w - 4), modelPanel(sn, w - 4, history), reportPanel(sn, w - 4), setupPanel(sn), graphPanel(sn, w - 4), teamPanel(sn, w - 4), sastPanel(sn)], w);
|
|
564
589
|
}
|
|
565
590
|
else {
|
|
566
591
|
top.push(...tiles(tileItems(sn), width));
|
|
567
592
|
if (layout === 'pane') {
|
|
568
593
|
const w = width;
|
|
569
594
|
const inner = w - 4;
|
|
570
|
-
body = stack([activityPanel(events, 5, 'CHANGED JUST NOW'), ...opt(servicesPanel(sn, inner)), nextPanel(sn, 4, inner), modelPanel(sn, inner, history), reportPanel(sn, inner), setupPanel(sn
|
|
595
|
+
body = stack([activityPanel(events, 5, 'CHANGED JUST NOW'), ...opt(servicesPanel(sn, inner)), nextPanel(sn, 4, inner), modelPanel(sn, inner, history), reportPanel(sn, inner), setupPanel(sn), graphPanel(sn, inner), teamPanel(sn, inner), topPanel(sn, inner), sastPanel(sn), sizePanel(sn, inner)], w);
|
|
571
596
|
}
|
|
572
597
|
else if (layout === 'two') {
|
|
573
598
|
const gap = 1;
|
|
@@ -575,7 +600,7 @@ export function renderFrame(sn, events, opts) {
|
|
|
575
600
|
const w2 = width - gap - w;
|
|
576
601
|
body = joinColumns([
|
|
577
602
|
stack([activityPanel(events, 6), ...opt(servicesPanel(sn, w - 4)), nextPanel(sn, 5, w - 4), modelPanel(sn, w - 4, history), topPanel(sn, w - 4)], w),
|
|
578
|
-
stack([setupPanel(sn
|
|
603
|
+
stack([setupPanel(sn), graphPanel(sn, w2 - 4), teamPanel(sn, w2 - 4), sastPanel(sn), reportPanel(sn, w2 - 4), sizePanel(sn, w2 - 4)], w2),
|
|
579
604
|
], [w, w2], gap);
|
|
580
605
|
}
|
|
581
606
|
else {
|
|
@@ -583,7 +608,7 @@ export function renderFrame(sn, events, opts) {
|
|
|
583
608
|
const w = Math.floor((width - gap * 2) / 3);
|
|
584
609
|
const w3 = width - gap * 2 - w * 2;
|
|
585
610
|
body = joinColumns([
|
|
586
|
-
stack([setupPanel(sn
|
|
611
|
+
stack([setupPanel(sn), graphPanel(sn, w - 4), sastPanel(sn), reportPanel(sn, w - 4)], w),
|
|
587
612
|
stack([modelPanel(sn, w - 4, history), nextPanel(sn, 5, w - 4), sizePanel(sn, w - 4)], w),
|
|
588
613
|
stack([activityPanel(events, 8), ...opt(servicesPanel(sn, w3 - 4)), teamPanel(sn, w3 - 4), topPanel(sn, w3 - 4)], w3),
|
|
589
614
|
], [w, w, w3], gap);
|