@bugb-technologies/bravos 1.23.0 → 1.25.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/artifacts.js +23 -8
- package/dist/bin.js +12 -0
- package/dist/cli.js +203 -21
- package/dist/context.js +4 -4
- package/dist/cursor.js +24 -5
- package/dist/dashboard.js +6 -0
- package/dist/doctor.js +29 -2
- package/dist/graphbin.js +2 -2
- package/dist/guide.js +4 -2
- package/dist/hook-launcher.js +92 -0
- package/dist/hooks.js +56 -3
- package/dist/prefs.js +18 -4
- package/dist/principles.js +1 -1
- package/dist/records-drafts.js +106 -0
- package/dist/records-ledger.js +103 -0
- package/dist/records-team.js +398 -0
- package/dist/records.js +158 -0
- package/dist/review-server.js +3 -1
- package/dist/review.js +16 -1
- package/dist/rules.js +48 -4
- package/dist/setup-route.js +1 -1
- package/dist/setup.js +57 -2
- package/dist/uninstall.js +1 -1
- package/dist/upkeep.js +3 -0
- package/dist/versions.js +3 -0
- package/docs/GUIDE.md +11 -1
- package/docs/UPGRADING.md +48 -0
- package/hooks/cards.mjs +62 -13
- package/hooks/coach.mjs +3 -1
- package/hooks/lib/agent-io.mjs +105 -0
- package/hooks/lib/briefing.mjs +94 -3
- package/hooks/lib/cards.mjs +49 -10
- package/hooks/lib/draft-check.mjs +104 -0
- package/hooks/lib/drafts.mjs +121 -0
- package/hooks/lib/ledger.mjs +270 -0
- package/hooks/lib/pre-pr.mjs +74 -0
- package/hooks/lib/prefs.mjs +7 -3
- package/hooks/lib/record-guard.mjs +272 -0
- package/hooks/lib/records.mjs +581 -0
- package/hooks/lib/replay.mjs +2 -1
- package/hooks/record-guard.mjs +60 -0
- package/hooks/session-start.mjs +4 -3
- package/package.json +2 -2
- package/skills/bravos/SKILL.md +1 -0
- package/skills/bravos-records/SKILL.md +57 -0
- package/templates/dashboard/dashboard.html +53 -0
- package/templates/omp/bravos.js +85 -1
- package/templates/opencode/bravos.js +84 -1
- package/templates/workflows/bravos-pr-gate.yml +23 -0
package/dist/artifacts.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// @comment -- "Fetches, verifies and stages the
|
|
1
|
+
// @comment -- "Fetches, verifies and stages the binary bundles bravos owns: the licensed analyzer (bravos-cli and its scanners), the code graph (codegraph-build, codegraph-mcp) and the free macOS notifier (Bravos.app). A port of the Python CLI's analyzer.py and artifact.py: each published file has a detached bravos-artifact-signature/1 statement signed under the artifact key (never the licence key), the manifest is verified before it is read, the tarball before it is opened, and the unpack refuses links, absolute paths, '..', duplicates and anything past a size ceiling. Nothing licensed touches the network without a licence the portal accepts (the notifier, on every plan, comes from the public release bucket instead, under the same signature checks): the download URLs come from the account portal, which checks the licence server-side and presigns a short-lived link to the private bucket; BRAVOS_ARTIFACT_BASE_URL points at a plain directory instead, for tests and air-gapped mirrors."
|
|
2
2
|
import { createHash, createPublicKey, verify as cryptoVerify } from 'node:crypto';
|
|
3
3
|
import { chmodSync, closeSync, existsSync, lstatSync, mkdirSync, openSync, readdirSync, readFileSync, realpathSync, renameSync, rmSync, symlinkSync, unlinkSync, writeSync } from 'node:fs';
|
|
4
4
|
import { arch, platform } from 'node:os';
|
|
@@ -7,14 +7,14 @@ import { gunzipSync } from 'node:zlib';
|
|
|
7
7
|
import { refresh, userAgent } from './device.js';
|
|
8
8
|
import { licenceLib } from './licence.js';
|
|
9
9
|
import { BravosError } from './types.js';
|
|
10
|
-
import { ANALYZER_VERSION, CODEGRAPH_VERSION } from './versions.js';
|
|
10
|
+
import { ANALYZER_VERSION, CODEGRAPH_VERSION, NOTIFIER_VERSION } from './versions.js';
|
|
11
11
|
export const MAGIC = 'bravos-artifact-signature/1';
|
|
12
12
|
export const ARTIFACT_KID = 'bugb-artifact-2026a';
|
|
13
13
|
// @comment -- "The artifact signing key's public half, fixed in the source like the licence key and distinct from it: a licence says who may run the analyzer, a signature says these bytes are the ones Bugb published. No environment variable, flag or file adds a key; tests hand verify() a throwaway set in-process."
|
|
14
14
|
export const TRUSTED_ARTIFACT_KEYS = Object.freeze({
|
|
15
15
|
[ARTIFACT_KID]: '-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VwAyEAX2x2o4eSFTU+Ti1Kkew+/t9LO4POT4D0r9aoRtJbz9o=\n-----END PUBLIC KEY-----\n',
|
|
16
16
|
});
|
|
17
|
-
export const MANIFEST_SCHEMAS = { analyzer: 'bravos-analyzer-manifest/2', codegraph: 'bravos-codegraph-manifest/1' };
|
|
17
|
+
export const MANIFEST_SCHEMAS = { analyzer: 'bravos-analyzer-manifest/2', codegraph: 'bravos-codegraph-manifest/1', notifier: 'bravos-notifier-manifest/1' };
|
|
18
18
|
export const BUNDLE_FILE = 'BUNDLE.json';
|
|
19
19
|
const MAX_MANIFEST_BYTES = 256 * 1024;
|
|
20
20
|
const MAX_SIGNATURE_BYTES = 4096;
|
|
@@ -27,12 +27,26 @@ export const TARGETS = ['aarch64-apple-darwin', 'x86_64-apple-darwin', 'x86_64-u
|
|
|
27
27
|
export const REQUIRED = {
|
|
28
28
|
analyzer: ['bravos-cli', BUNDLE_FILE, 'rules/semgrep/PACK.toml', 'rules/sinks.yaml', 'rules/middleware.yaml', 'bin/gitleaks', 'bin/osv-scanner', 'bin/kics', 'bin/zizmor', 'share/kics/assets/queries', 'licences/NOTICE'],
|
|
29
29
|
codegraph: ['codegraph-build', 'codegraph-mcp', BUNDLE_FILE],
|
|
30
|
+
notifier: ['Bravos.app/Contents/MacOS/Bravos', 'Bravos.app/Contents/Info.plist', BUNDLE_FILE],
|
|
30
31
|
};
|
|
31
32
|
export const EXECUTABLES = {
|
|
32
33
|
analyzer: ['bravos-cli', 'bin/gitleaks', 'bin/osv-scanner', 'bin/kics', 'bin/zizmor'],
|
|
33
34
|
codegraph: ['codegraph-build', 'codegraph-mcp'],
|
|
35
|
+
notifier: ['Bravos.app/Contents/MacOS/Bravos'],
|
|
34
36
|
};
|
|
35
|
-
export const VERSIONS = { analyzer: ANALYZER_VERSION, codegraph: CODEGRAPH_VERSION };
|
|
37
|
+
export const VERSIONS = { analyzer: ANALYZER_VERSION, codegraph: CODEGRAPH_VERSION, notifier: NOTIFIER_VERSION };
|
|
38
|
+
/** The notifier is one universal (arm64 + x86_64) macOS app, so its manifest names this one target. */
|
|
39
|
+
export const NOTIFIER_TARGET = 'universal-apple-darwin';
|
|
40
|
+
/** The notifier executable inside a staged bundle. */
|
|
41
|
+
export const NOTIFIER_EXECUTABLE = 'Bravos.app/Contents/MacOS/Bravos';
|
|
42
|
+
// @comment -- "Where the notifier is published: the public release bucket (the one that serves the desktop app), under bravos/notifier/<version>/. Desktop notifications are on every plan, so the notifier is fetched without a licence; what makes it safe to run is the artifact signature checked before unpacking, plus Apple's notarization of the app inside."
|
|
43
|
+
export const NOTIFIER_BASE_URL = 'https://pub-e89c47f816b54f5c8e6c54335574be9b.r2.dev/bravos';
|
|
44
|
+
// @comment -- "The build of `kind` this machine runs: the host triple for the analyzer and the code graph, the universal macOS app for the notifier (macOS only), or null when none is published for this platform."
|
|
45
|
+
export function bundleTarget(kind, os = platform()) {
|
|
46
|
+
if (kind === 'notifier')
|
|
47
|
+
return os === 'darwin' ? NOTIFIER_TARGET : null;
|
|
48
|
+
return hostTarget();
|
|
49
|
+
}
|
|
36
50
|
export function hostTarget() {
|
|
37
51
|
const p = platform();
|
|
38
52
|
const a = arch();
|
|
@@ -262,7 +276,7 @@ export function staged(env, kind) {
|
|
|
262
276
|
return null;
|
|
263
277
|
}
|
|
264
278
|
const candidates = [join(home, kind, 'current')];
|
|
265
|
-
const t =
|
|
279
|
+
const t = bundleTarget(kind);
|
|
266
280
|
if (t)
|
|
267
281
|
candidates.push(join(home, kind, VERSIONS[kind], t));
|
|
268
282
|
for (const c of candidates) {
|
|
@@ -364,7 +378,8 @@ async function get(f, url, limit, what, headers = {}) {
|
|
|
364
378
|
// @comment -- "Where the files come from. With BRAVOS_ARTIFACT_BASE_URL, a plain layout <base>/<kind>/<version>/<file> (tests, mirrors). Otherwise the account portal: GET /api/v1/cli/artifacts/<kind>/<version>/<triple> with the licence as the bearer; the portal verifies it (and, for a device or CI licence, that it has not been revoked), counts the pull, and answers presigned URLs into the private bucket. On 401 or 403 a device licence is renewed once and the request repeated once. The licence token goes to the portal origin and nowhere else; the presigned URLs carry their own authorization."
|
|
365
379
|
async function urlsFor(kind, version, target, io) {
|
|
366
380
|
const f = io.fetch ?? fetch;
|
|
367
|
-
|
|
381
|
+
// The notifier comes from the public bucket in the same plain layout, with no licence and no portal.
|
|
382
|
+
const base = (io.env[BASE_URL_ENV] || '').trim() || (kind === 'notifier' ? NOTIFIER_BASE_URL : '');
|
|
368
383
|
if (base) {
|
|
369
384
|
const root = `${base.replace(/\/+$/, '')}/${kind}/${version}`;
|
|
370
385
|
return { manifest: `${root}/manifest.json`, manifestSig: `${root}/manifest.json.sig`, artifact: (file) => `${root}/${file}`, artifactSig: (file) => `${root}/${file}.sig` };
|
|
@@ -416,9 +431,9 @@ export async function install(kind, io, opts = {}) {
|
|
|
416
431
|
if (io.env[NO_FETCH_ENV])
|
|
417
432
|
throw new BravosError(`${NO_FETCH_ENV} is set: refusing to download the ${kind} bundle`);
|
|
418
433
|
const version = opts.version ?? VERSIONS[kind];
|
|
419
|
-
const target = opts.target ??
|
|
434
|
+
const target = opts.target ?? bundleTarget(kind);
|
|
420
435
|
if (!target)
|
|
421
|
-
throw new BravosError(`no ${kind} bundle is published for this platform (${platform()} ${arch()}); the targets are ${TARGETS.join(', ')}`);
|
|
436
|
+
throw new BravosError(kind === 'notifier' ? 'the Bravos notifier is a macOS app; on Linux desktop notifications go through notify-send' : `no ${kind} bundle is published for this platform (${platform()} ${arch()}); the targets are ${TARGETS.join(', ')}`);
|
|
422
437
|
const f = io.fetch ?? fetch;
|
|
423
438
|
const keys = io.keys ?? TRUSTED_ARTIFACT_KEYS;
|
|
424
439
|
const echo = io.echo ?? (() => { });
|
package/dist/bin.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// @comment -- "The `bravos` executable. `bravos hook <name> [args]` goes straight to the hook launcher, so a hook a harness runs on every prompt and every edit does not pay for loading the CLI's commands; everything else (including `bravos hook` with no name or a flag such as --help) runs the CLI as before."
|
|
3
|
+
const argv = process.argv.slice(2);
|
|
4
|
+
if (argv[0] === 'hook' && argv[1] !== undefined && !argv[1].startsWith('-')) {
|
|
5
|
+
const { launch } = await import('./hook-launcher.js');
|
|
6
|
+
await launch(argv[1], argv.slice(2));
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
const { main } = await import('./cli.js');
|
|
10
|
+
main();
|
|
11
|
+
}
|
|
12
|
+
export {};
|
package/dist/cli.js
CHANGED
|
@@ -28,7 +28,7 @@ import { activate, importLicence } from './account.js';
|
|
|
28
28
|
import { listDevices, logout, refresh as refreshDevice, revokeDevice } from './device.js';
|
|
29
29
|
import * as graph from './codegraph.js';
|
|
30
30
|
import { askGraph } from './watch.js';
|
|
31
|
-
import { plan as setupPlan, runSast, runSetup } from './setup.js';
|
|
31
|
+
import { notifyWanted, plan as setupPlan, runSast, runSetup } from './setup.js';
|
|
32
32
|
import { isTerminal, setupRoute } from './setup-route.js';
|
|
33
33
|
import { leaveHandoff } from './prefs.js';
|
|
34
34
|
import { openInBrowser } from './open.js';
|
|
@@ -38,7 +38,7 @@ import { listBundledSkills } from './skills.js';
|
|
|
38
38
|
import { installSkills, linkSkillRoots, mirrorGuardlinkSkills, skillRootsLinked } from './install.js';
|
|
39
39
|
import { LOCK_PATH, readLock, sha256, writeLock } from './lock.js';
|
|
40
40
|
import { mergeCodexConfig, mergeMcpJson, selectServers } from './mcp.js';
|
|
41
|
-
import { hooksDir, skillsDir as bundledSkillsDir, version } from './paths.js';
|
|
41
|
+
import { hooksDir, packageRoot, skillsDir as bundledSkillsDir, version } from './paths.js';
|
|
42
42
|
import { BravosError } from './types.js';
|
|
43
43
|
// @comment -- "Which agents a repository already has Bravos installed for, read from the files Bravos wrote there: the two skills roots, the Codex and Antigravity hook registrations, and the opencode and omp plugins, and the Cursor session hook. Upkeep re-applies to exactly these, so a tool that happens to be on this machine, or an AGENTS.md someone added, never widens a team's setup."
|
|
44
44
|
export function installedAgents(root) {
|
|
@@ -628,18 +628,25 @@ export function buildProgram(io, result) {
|
|
|
628
628
|
}
|
|
629
629
|
lines.push(JSON.stringify(opts.json ? a : a.result, null, 2));
|
|
630
630
|
}));
|
|
631
|
-
// @comment -- "bravos hook <name> runs one of the scripts this install ships (
|
|
631
|
+
// @comment -- "bravos hook <name> runs one of the hook scripts this install ships (the table in src/hook-launcher.ts) with the given arguments. Run as the `bravos` executable it never reaches this command: the bin shim hands it to the launcher, which runs the script in-process with identical stdin, stdout and exit code. Here (dist/cli.js run directly, or run() in-process) the launcher runs as a child through the shim, with stdin passed through and its output relayed. An unknown name exits 0 and prints nothing, so a pointer never breaks an agent's turn; with no name it lists the hooks."
|
|
632
632
|
program
|
|
633
|
-
.command('hook
|
|
634
|
-
.description('Run one of bravos\'s hook scripts from this install
|
|
633
|
+
.command('hook [name] [args...]')
|
|
634
|
+
.description('Run one of bravos\'s hook scripts from this install, e.g. `bravos hook session-start --briefing` or `bravos hook replay preflight run <kit.js>`: what a harness, a git hook, CI or a plugin skill runs when the repository has no .bravos/hooks/ copy. The same arguments, input, output and exit code as `node .bravos/hooks/<name>.mjs`. An unknown name does nothing and exits 0; with no name, lists the hooks.')
|
|
635
635
|
.allowUnknownOption()
|
|
636
636
|
.helpOption(false)
|
|
637
|
-
.action((name, args) =>
|
|
638
|
-
const
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
637
|
+
.action((name, args) => guardedAsync(async (lines) => {
|
|
638
|
+
const { HOOKS, launcherHooksDir } = await import('./hook-launcher.js');
|
|
639
|
+
// No name, or a flag such as --help where the name goes: list the hooks.
|
|
640
|
+
if (name === undefined || name.startsWith('-')) {
|
|
641
|
+
lines.push(`bravos hook <name> [args…]: ${Object.keys(HOOKS).join(', ')}`);
|
|
642
|
+
return;
|
|
643
|
+
}
|
|
644
|
+
if (!Object.prototype.hasOwnProperty.call(HOOKS, name))
|
|
645
|
+
return;
|
|
646
|
+
if (!existsSync(pathJoin(launcherHooksDir(), HOOKS[name])))
|
|
647
|
+
return;
|
|
648
|
+
// Through the bin shim, so the script runs under the launcher as the repository's own hook, exactly as `bravos hook` does.
|
|
649
|
+
const r = spawnSync(process.execPath, [pathJoin(packageRoot(), 'dist', 'bin.js'), 'hook', name, ...args], { env: io.env, encoding: 'utf8', stdio: ['inherit', 'pipe', 'pipe'], maxBuffer: 16 * 1024 * 1024 });
|
|
643
650
|
if (r.stdout)
|
|
644
651
|
lines.push(r.stdout.replace(/\n$/, ''));
|
|
645
652
|
if (r.stderr)
|
|
@@ -745,6 +752,11 @@ export function buildProgram(io, result) {
|
|
|
745
752
|
for (const b of u.bundles) {
|
|
746
753
|
lines.push(...(await runSetup(io.env, { [b.id]: true, dryRun }, { echo: io.stdout })));
|
|
747
754
|
}
|
|
755
|
+
// @comment -- "The notifier is the one bundle upkeep may fetch when it is absent: the person's own notify answer (bravos prefs set notify on) is the go-ahead, it is on every plan, and it only replaces how a notification they asked for is shown. A failure is a line; cards fall back to osascript."
|
|
756
|
+
if (process.platform === 'darwin' && (await notifyWanted(root, io.env))) {
|
|
757
|
+
const n = await runSetup(io.env, { notifier: true, notify: true, dryRun }, { echo: io.stdout }).catch((e) => [`notifier: ${e.message.split('\n')[0]}`]);
|
|
758
|
+
lines.push(...n.filter((l) => !l.startsWith('notifier: already staged')));
|
|
759
|
+
}
|
|
748
760
|
// Absent pieces are named, never fetched here: a first install is a person's go-ahead.
|
|
749
761
|
const plan = await setupPlan(io.env);
|
|
750
762
|
for (const item of plan.items) {
|
|
@@ -759,17 +771,18 @@ export function buildProgram(io, result) {
|
|
|
759
771
|
}
|
|
760
772
|
};
|
|
761
773
|
// @comment -- "bravos setup: the one command. It looks at what was typed and whether there is a terminal (src/setup-route.ts) and does one job: the read-only check, the machine part, the user-level install, the repository part by flags, an unattended first setup, the guided wizard, or upkeep. It is declared after the wizard and repository actions it dispatches to."
|
|
762
|
-
const SETUP_FLAGS = 'bravos setup: --tools, --analyzer and --
|
|
774
|
+
const SETUP_FLAGS = 'bravos setup: --tools, --analyzer, --codegraph and --notifier set up this machine; the other flags set up a repository. Run them as two commands, for example: bravos setup --tools -y, then bravos setup --agent claude';
|
|
763
775
|
repositoryOptions(setupCommand
|
|
764
|
-
.description('Set Bravos up, here and on this machine, doing only what is missing. In a terminal it is a guided setup: sign in, install the tools, then this repository\'s agents, PR checks and testing permission; in a repository that already has Bravos it only brings this machine and the repository up to date (--change re-asks the repository\'s choices). Without a terminal (an agent, a script) a plain bravos setup only brings what is already installed up to date. Flags do one part by hand: --tools, --analyzer, --codegraph for this machine; --agent, --autopilot, --ci and the rest for the repository; --yes for an unattended first setup; --check to look and change nothing.')
|
|
776
|
+
.description('Set Bravos up, here and on this machine, doing only what is missing. In a terminal it is a guided setup: sign in, install the tools, then this repository\'s agents, PR checks and testing permission; in a repository that already has Bravos it only brings this machine and the repository up to date (--change re-asks the repository\'s choices). Without a terminal (an agent, a script) a plain bravos setup only brings what is already installed up to date. Flags do one part by hand: --tools, --analyzer, --codegraph, --notifier for this machine; --agent, --autopilot, --ci and the rest for the repository; --yes for an unattended first setup; --check to look and change nothing.')
|
|
765
777
|
.option('--change', 'ask this repository\'s questions again, with the recorded answers selected')
|
|
766
778
|
.addOption(new Option('--again', 'the earlier name of --change').hideHelp())
|
|
767
779
|
.addOption(new Option('--preset <name>', 'starting point for the guided setup').choices(['annotate', 'pr', 'everything']))
|
|
768
780
|
.option('--analyzer', 'this machine: only the analyzer bundle')
|
|
769
781
|
.option('--codegraph', 'this machine: only the code graph bundle')
|
|
782
|
+
.option('--notifier', 'this machine (macOS): only the Bravos notifier app, when desktop notifications are on (bravos prefs set notify on)')
|
|
770
783
|
.option('--tools', 'this machine: guardlink (npm) and cxg (cargo); needs -y')
|
|
771
784
|
.option('--check', 'report what is here and what setup would do; changes nothing')
|
|
772
|
-
.option('-y, --yes', 'alone: no questions, set this repository up with the defaults (or join it). With --tools, --analyzer or --
|
|
785
|
+
.option('-y, --yes', 'alone: no questions, set this repository up with the defaults (or join it). With --tools, --analyzer, --codegraph or --notifier: run the installers, and fetch a staged bundle again')
|
|
773
786
|
.option('--json', 'with --check: print the plan as JSON (bravos.setup-plan/v1)'), { guardlink: true });
|
|
774
787
|
setupCommand.action((dir, opts) => guardedAsync(async (lines) => {
|
|
775
788
|
const given = new Set(Object.keys(opts).filter((k) => setupCommand.getOptionValueSource(k) === 'cli'));
|
|
@@ -782,13 +795,15 @@ export function buildProgram(io, result) {
|
|
|
782
795
|
throw new BravosError('bravos setup asks questions here, so it needs a terminal. Without one: bravos setup --yes [--preset pr] [dir]');
|
|
783
796
|
if (route === 'check' || route === 'machine') {
|
|
784
797
|
if (dir)
|
|
785
|
-
throw new BravosError(`bravos setup ${route === 'check' ? '--check' : '--tools, --analyzer and --
|
|
798
|
+
throw new BravosError(`bravos setup ${route === 'check' ? '--check' : '--tools, --analyzer, --codegraph and --notifier'} is about this machine and takes no folder`);
|
|
786
799
|
if (route === 'check' && opts.json) {
|
|
787
800
|
const p = await setupPlan(io.env);
|
|
788
801
|
lines.push(JSON.stringify({ schema: 'bravos.setup-plan/v1', plan: p.licence.licensed ? 'licensed' : p.licence.state, items: p.items }, null, 2));
|
|
789
802
|
return;
|
|
790
803
|
}
|
|
791
|
-
|
|
804
|
+
// Whether notifications are on is read from the repository the command runs in: prefs are per clone.
|
|
805
|
+
const notify = await notifyWanted(process.cwd(), io.env);
|
|
806
|
+
lines.push(...(await runSetup(io.env, { analyzer: opts.analyzer, codegraph: opts.codegraph, notifier: opts.notifier, tools: opts.tools, check: opts.check, dryRun: opts.dryRun, yes: opts.yes, notify }, { echo: io.stdout })));
|
|
792
807
|
return;
|
|
793
808
|
}
|
|
794
809
|
if (route === 'upkeep') {
|
|
@@ -920,7 +935,7 @@ export function buildProgram(io, result) {
|
|
|
920
935
|
// @comment -- "bravos prefs: what this person told Bravos once so no session asks again. `prefs get` shows it; `prefs set commits <commit|leave|ask> --by <name>` records the answer about committing Bravos's own files, `prefs set annotate <background|off> --by <name>` whether each session starts a background annotation pass. Kept under the git directory of this clone, never committed."
|
|
921
936
|
program
|
|
922
937
|
.command('prefs <action> [args...]')
|
|
923
|
-
.description('Your standing answers for this clone, kept under its git directory and never committed: `prefs get` shows them; `prefs set commits <commit|leave|ask> --by "<your name>"` says whether your agent commits Bravos\'s own files (annotations, intent, definitions, tests) without asking, always leaves them for you, or asks each session; `prefs set annotate <background|off> --by "<your name>"` says whether each session starts one background annotation pass while coverage is incomplete (background is the default); `prefs set coach <on|off> --by "<your name>"` says whether the coach adds reminders before prompts (on is the default); `prefs set cards <on|off>` whether a threat card shows when an edit adds an untested critical or high threat (on),
|
|
938
|
+
.description('Your standing answers for this clone, kept under its git directory and never committed: `prefs get` shows them; `prefs set commits <commit|leave|ask> --by "<your name>"` says whether your agent commits Bravos\'s own files (annotations, intent, definitions, tests) without asking, always leaves them for you, or asks each session; `prefs set annotate <background|off> --by "<your name>"` says whether each session starts one background annotation pass while coverage is incomplete (background is the default); `prefs set coach <on|off> --by "<your name>"` says whether the coach adds reminders before prompts (on is the default); `prefs set cards <on|off>` whether a threat card shows when an edit adds an untested critical or high threat (on), `prefs set notify <on|off>` whether it also sends a desktop notification (off), `prefs set drafts <background|off>` whether one background pass each session drafts security decision records for the reviewed ledger\'s modules that need one (background, Team plan), and `prefs set nudge <on|off>` whether the first edit of a module the ledger says needs a security decision record, and has none, gets one line offering to draft one (on). Free; runs no model.')
|
|
924
939
|
.option('-C, --dir <dir>', 'the repository (default: the current directory)')
|
|
925
940
|
.option('--by <name>', 'set: whose answer this is')
|
|
926
941
|
.option('--json', 'get: print JSON')
|
|
@@ -929,10 +944,10 @@ export function buildProgram(io, result) {
|
|
|
929
944
|
const dir = dirArg(opts.dir);
|
|
930
945
|
if (action === 'get' && args.length === 0)
|
|
931
946
|
lines.push(...(await getPrefs(dir, io.env, !!opts.json)));
|
|
932
|
-
else if (action === 'set' && ['commits', 'annotate', 'coach', 'cards', 'notify'].includes(args[0]) && args.length === 2)
|
|
947
|
+
else if (action === 'set' && ['commits', 'annotate', 'coach', 'cards', 'notify', 'nudge', 'drafts'].includes(args[0]) && args.length === 2)
|
|
933
948
|
lines.push(...(await setPref(dir, args[0], args[1], opts.by, io.env)));
|
|
934
949
|
else
|
|
935
|
-
throw new BravosError('usage: bravos prefs get [--json] | bravos prefs set commits <commit|leave|ask> --by "<your name>" | bravos prefs set annotate <background|off> --by "<your name>" | bravos prefs set coach|cards|notify <on|off> --by "<your name>"');
|
|
950
|
+
throw new BravosError('usage: bravos prefs get [--json] | bravos prefs set commits <commit|leave|ask> --by "<your name>" | bravos prefs set annotate|drafts <background|off> --by "<your name>" | bravos prefs set coach|cards|notify|nudge <on|off> --by "<your name>"');
|
|
936
951
|
}));
|
|
937
952
|
// @comment -- "bravos rules: the design rules (INV-n in the intent, each a #inv- threat) with where the code enforces each and what testing has shown. Read-only and free; runs guardlink parse and hypothesis list, no model."
|
|
938
953
|
program
|
|
@@ -1016,6 +1031,162 @@ export function buildProgram(io, result) {
|
|
|
1016
1031
|
else
|
|
1017
1032
|
throw new BravosError(`unknown principles action '${action}'; use check, list, write, except or copy`);
|
|
1018
1033
|
}));
|
|
1034
|
+
// @comment -- "bravos records: the security decision records in this repository, one Markdown document per module under .guardlink/records/. list, show, for and check only read and are free; new writes the skeleton of a draft; adopt records a person's adoption of a record as it reads now, at an interactive terminal where they type their name and the record id. A draft binds nobody: only an adopted record is followed."
|
|
1035
|
+
program
|
|
1036
|
+
.command('records [action] [args...]')
|
|
1037
|
+
.description('Security decision records: one document per module or feature (.guardlink/records/SDR-n-<module>.md) saying what was decided there, the rules that follow, why, and what looks like a bug but is not. `records list` (the default); `records show SDR-n`; `records for <file>` says which record covers a file; `records check` verifies every record parses, that an adopted one still reads as it did when adopted and that the exceptions are sound (free; exit 1 on a problem); `records new "<module>" --paths "<glob>,<glob>"` writes the skeleton of a draft; `records adopt SDR-n` makes a record binding, approved by the person typing their name at a terminal (never by an agent), or adopt on the page with bravos review records; `records except SDR-n R1 --where "<glob>" --reason "<why>" --until YYYY-MM-DD` lets a break of one rule in one area through the pre-PR gate until that day, approved the same way; `records except --clear-expired`; `records gaps` lists modules with security claims no record covers; `records ledger` lists the module ledger (.guardlink/records/README.md: which modules make security decisions, their code, owner and record), `records ledger propose [--write]` proposes modules from the stored documents, the threat model and the folders, `records ledger add|remove|refresh` keep it (free; reviewed by a person in a pull request, never enforced); `records drafts` lists the modules of the reviewed ledger to draft a record for now (at most 2 a run, 3 waiting, one per module) and `records draft "<module>"` starts one on its own branch and worktree (Team plan; the agent drafts, pushes nothing, and opens the pull request only on the person\'s yes); `records codeowners --owner @<who>` shows the CODEOWNERS lines that make a record need that owner\'s review on GitHub (--yes writes them, after the person said so). A record is approved when its text is on the default branch (a code owner\'s review where GitHub requires one); adopting by typed name is the fallback, labelled not verified. Runs no model.')
|
|
1038
|
+
.option('-C, --dir <dir>', 'the repository (default: the current directory)')
|
|
1039
|
+
.option('--json', 'list/show/for/check: print JSON')
|
|
1040
|
+
.option('--paths <globs>', 'new: the code the record covers, as repository globs separated by commas (src/reports/**,app/api/reports/**)')
|
|
1041
|
+
.option('--where <glob>', 'except: the code the exception covers, as a repository glob (src/reports/legacy/**)')
|
|
1042
|
+
.option('--reason <why>', 'except: why this code may go against the rule for now')
|
|
1043
|
+
.option('--until <day>', 'except: the last day it holds (YYYY-MM-DD, within a year)')
|
|
1044
|
+
.option('--clear-expired', 'except: remove exceptions whose last day has passed')
|
|
1045
|
+
.option('--owner <who>', 'codeowners: the GitHub user or team that approves records (@security-leads, @org/team)')
|
|
1046
|
+
.option('--yes', 'codeowners: write the lines (only after the person said so)')
|
|
1047
|
+
.option('--offline', 'check: do not ask GitHub (gh) whether code-owner review is enforced')
|
|
1048
|
+
.option('--needs <yes|optional>', 'ledger add: whether the module makes security decisions and so needs a record')
|
|
1049
|
+
.option('--why <what>', 'ledger add: what the module decides (who can see or do what, outside connections, customer data, money)')
|
|
1050
|
+
.option('--evidence <where>', 'ledger add: where that comes from (SRC-n § section, an asset, routes)')
|
|
1051
|
+
.option('--write', 'ledger propose: add the proposed modules to the ledger')
|
|
1052
|
+
.option('--limit <n>', 'drafts: how many modules to draft in this run (default 2; at most 3 wait for review at once)')
|
|
1053
|
+
.option('--worktree <dir>', 'draft: where the draft\'s worktree goes (default: under the git directory)')
|
|
1054
|
+
.action((action, args, opts) => guardedAsync(async (lines) => {
|
|
1055
|
+
const R = await import('./records.js');
|
|
1056
|
+
const root = dirArg(opts.dir);
|
|
1057
|
+
const act = action ?? 'list';
|
|
1058
|
+
if (act === 'list') {
|
|
1059
|
+
const { result: checked, lines: said } = await R.checkRecordsAt(root, io.env);
|
|
1060
|
+
lines.push(...(opts.json ? [JSON.stringify({ schema: 'bravos.records/v1', ok: checked.ok, records: checked.records }, null, 2)] : said));
|
|
1061
|
+
}
|
|
1062
|
+
else if (act === 'check') {
|
|
1063
|
+
// Ask GitHub first (gh, as the person), so the approval the hooks and the gate read from the cache is current.
|
|
1064
|
+
if (!opts.offline) {
|
|
1065
|
+
const review = await (await import('./records-team.js')).refreshReview(root, io.env).catch(() => null);
|
|
1066
|
+
if (review && !opts.json)
|
|
1067
|
+
lines.push(`review: ${review.enforced === true ? 'enforced' : review.enforced === false ? 'not enforced' : 'unknown'} — ${review.reason}`);
|
|
1068
|
+
}
|
|
1069
|
+
const { result: checked, lines: said } = await R.checkRecordsAt(root, io.env);
|
|
1070
|
+
lines.push(...(opts.json ? [JSON.stringify(checked, null, 2)] : said));
|
|
1071
|
+
if (!checked.ok)
|
|
1072
|
+
result.code = 1;
|
|
1073
|
+
}
|
|
1074
|
+
else if (act === 'show') {
|
|
1075
|
+
if (args.length !== 1)
|
|
1076
|
+
throw new BravosError('usage: bravos records show SDR-n');
|
|
1077
|
+
const shown = await R.showRecord(root, args[0], io.env);
|
|
1078
|
+
lines.push(...(opts.json ? [JSON.stringify({ schema: 'bravos.record/v1', record: shown.record }, null, 2)] : shown.lines));
|
|
1079
|
+
}
|
|
1080
|
+
else if (act === 'for') {
|
|
1081
|
+
if (args.length !== 1)
|
|
1082
|
+
throw new BravosError('usage: bravos records for <file>');
|
|
1083
|
+
const found = await R.recordsFor(root, args[0], io.env);
|
|
1084
|
+
lines.push(...(opts.json ? [JSON.stringify({ schema: 'bravos.records-for/v1', file: found.file, records: found.records }, null, 2)] : found.lines));
|
|
1085
|
+
}
|
|
1086
|
+
else if (act === 'new') {
|
|
1087
|
+
await requireFeature(io.env, 'principles', 'Writing a security decision record');
|
|
1088
|
+
if (args.length !== 1 || !opts.paths)
|
|
1089
|
+
throw new BravosError('usage: bravos records new "<module>" --paths "<glob>,<glob>"');
|
|
1090
|
+
lines.push(...(await R.newRecord(root, args[0], opts.paths.split(',').map((p) => p.trim()).filter(Boolean))));
|
|
1091
|
+
}
|
|
1092
|
+
else if (act === 'adopt') {
|
|
1093
|
+
await requireFeature(io.env, 'principles', 'Adopting a security decision record');
|
|
1094
|
+
if (args.length !== 1)
|
|
1095
|
+
throw new BravosError('usage: bravos records adopt SDR-n');
|
|
1096
|
+
// @mitigates #records against #forged-record using #person-only-adoption -- "A record becomes binding only from an interactive terminal where the adopter types their own name and the record id; a coding agent's shell has no terminal, so it cannot adopt one"
|
|
1097
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY)
|
|
1098
|
+
throw new BravosError('adopting a record is a person\'s decision: run this yourself in a terminal, where you type your name to adopt it. A coding agent cannot adopt one.');
|
|
1099
|
+
const shown = await R.showRecord(root, args[0], io.env);
|
|
1100
|
+
const rl = (await import('node:readline/promises')).createInterface({ input: process.stdin, output: process.stdout });
|
|
1101
|
+
try {
|
|
1102
|
+
for (const l of shown.lines)
|
|
1103
|
+
io.stdout(l);
|
|
1104
|
+
io.stdout('Adopting it makes these rules the standard for that code: every coding agent here reads and follows them.');
|
|
1105
|
+
const by = (await rl.question('Your name, adopting this record: ')).trim();
|
|
1106
|
+
const typed = (await rl.question(`Type ${args[0]} to confirm: `)).trim();
|
|
1107
|
+
if (typed !== args[0])
|
|
1108
|
+
throw new BravosError('not confirmed: the record id did not match, nothing was recorded');
|
|
1109
|
+
lines.push(...(await R.adoptRecord(root, args[0], by, io.env)));
|
|
1110
|
+
}
|
|
1111
|
+
finally {
|
|
1112
|
+
rl.close();
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
else if (act === 'codeowners') {
|
|
1116
|
+
if (!opts.owner)
|
|
1117
|
+
throw new BravosError('usage: bravos records codeowners --owner @<user or org/team> [--yes]');
|
|
1118
|
+
lines.push(...(await (await import('./records-team.js')).codeownersLines(root, opts.owner, !!opts.yes)));
|
|
1119
|
+
}
|
|
1120
|
+
else if (act === 'drafts' || act === 'draft') {
|
|
1121
|
+
// @comment -- "Background drafting is on the Team plan, like writing a record: drafts lists what to draft now within the limits, draft starts one module's draft on its own branch and worktree. Neither pushes nor opens a pull request."
|
|
1122
|
+
await requireFeature(io.env, 'principles', 'Drafting security decision records');
|
|
1123
|
+
const Dr = await import('./records-drafts.js');
|
|
1124
|
+
if (act === 'drafts') {
|
|
1125
|
+
const n = opts.limit === undefined ? undefined : Number(opts.limit);
|
|
1126
|
+
if (n !== undefined && (!Number.isInteger(n) || n < 0 || n > 20))
|
|
1127
|
+
throw new BravosError('--limit takes a whole number from 0 to 20');
|
|
1128
|
+
const d = await Dr.draftsList(root, io.env, n);
|
|
1129
|
+
lines.push(...(opts.json ? [JSON.stringify(d.json, null, 2)] : d.lines));
|
|
1130
|
+
}
|
|
1131
|
+
else {
|
|
1132
|
+
if (!args.length)
|
|
1133
|
+
throw new BravosError('usage: bravos records draft "<module>" [--worktree <dir>]');
|
|
1134
|
+
lines.push(...(await Dr.draftStart(root, args.join(' '), io.env, { worktree: opts.worktree })));
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
else if (act === 'ledger') {
|
|
1138
|
+
// @comment -- "The module ledger is Free on every plan and agent-run: it proposes and lists, and only a person's review of its pull request makes it reviewed. It is never enforced."
|
|
1139
|
+
const Lg = await import('./records-ledger.js');
|
|
1140
|
+
const sub = args[0] ?? 'list';
|
|
1141
|
+
if (sub === 'list') {
|
|
1142
|
+
const l = await Lg.ledgerList(root);
|
|
1143
|
+
lines.push(...(opts.json ? [JSON.stringify(l.json, null, 2)] : l.lines));
|
|
1144
|
+
}
|
|
1145
|
+
else if (sub === 'propose')
|
|
1146
|
+
lines.push(...(await Lg.ledgerPropose(root, !!opts.write)));
|
|
1147
|
+
else if (sub === 'add')
|
|
1148
|
+
lines.push(...(await Lg.ledgerAdd(root, args.slice(1).join(' '), opts)));
|
|
1149
|
+
else if (sub === 'remove')
|
|
1150
|
+
lines.push(...(await Lg.ledgerRemove(root, args.slice(1).join(' '))));
|
|
1151
|
+
else if (sub === 'refresh')
|
|
1152
|
+
lines.push(...(await Lg.ledgerRefresh(root)));
|
|
1153
|
+
else
|
|
1154
|
+
throw new BravosError('usage: bravos records ledger [list|propose [--write]|add "<module>" --paths … --needs yes|optional|remove "<module>"|refresh]');
|
|
1155
|
+
}
|
|
1156
|
+
else if (act === 'gaps') {
|
|
1157
|
+
await requireFeature(io.env, 'principles', 'The records gaps report');
|
|
1158
|
+
const T = await import('./records-team.js');
|
|
1159
|
+
const g = await T.recordGaps(root, io.env);
|
|
1160
|
+
lines.push(...(opts.json ? [JSON.stringify({ schema: 'bravos.records-gaps/v1', modules: g.modules }, null, 2)] : g.lines));
|
|
1161
|
+
}
|
|
1162
|
+
else if (act === 'except') {
|
|
1163
|
+
await requireFeature(io.env, 'principles', 'Exceptions to security decision records');
|
|
1164
|
+
const T = await import('./records-team.js');
|
|
1165
|
+
if (opts.clearExpired) {
|
|
1166
|
+
lines.push(...(await T.clearExpiredRecordExceptions(root)));
|
|
1167
|
+
return;
|
|
1168
|
+
}
|
|
1169
|
+
if (args.length !== 2 || !opts.where || !opts.reason || !opts.until)
|
|
1170
|
+
throw new BravosError('usage: bravos records except SDR-n R1 --where "<glob>" --reason "<why>" --until YYYY-MM-DD');
|
|
1171
|
+
// @mitigates #records against #forged-record using #person-only-adoption -- "An exception to a record rule needs an interactive terminal where the approver types their own name and the rule; a coding agent's shell has no terminal, so it cannot approve one"
|
|
1172
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY)
|
|
1173
|
+
throw new BravosError('an exception is a person\'s decision: run this yourself in a terminal, where you type your name to approve it. A coding agent cannot approve one.');
|
|
1174
|
+
const rl = (await import('node:readline/promises')).createInterface({ input: process.stdin, output: process.stdout });
|
|
1175
|
+
try {
|
|
1176
|
+
io.stdout(`Exception to ${args[0]} ${args[1]} for ${opts.where} until ${opts.until}: ${opts.reason}`);
|
|
1177
|
+
const by = (await rl.question('Your name, approving this exception: ')).trim();
|
|
1178
|
+
const typed = (await rl.question(`Type ${args[0]} ${args[1]} to confirm: `)).trim();
|
|
1179
|
+
if (typed !== `${args[0]} ${args[1]}`)
|
|
1180
|
+
throw new BravosError('not confirmed: the rule did not match, nothing was recorded');
|
|
1181
|
+
lines.push(...(await T.addRecordException(root, { record: args[0], rule: args[1], where: opts.where, reason: opts.reason, until: opts.until, by }, io.env)));
|
|
1182
|
+
}
|
|
1183
|
+
finally {
|
|
1184
|
+
rl.close();
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
else
|
|
1188
|
+
throw new BravosError(`unknown records action '${act}'; use list, show, for, check, new, adopt, except, gaps, codeowners, ledger, drafts or draft`);
|
|
1189
|
+
}));
|
|
1019
1190
|
program
|
|
1020
1191
|
.command('review <kind> [dir]')
|
|
1021
1192
|
.description("Open bravos's questions (.guardlink/<kind>-draft.json, e.g. kind 'intent') as a branded page people answer in; answers are saved to .guardlink/<kind>-answers/<name>.json. Runs no model.")
|
|
@@ -1029,6 +1200,13 @@ export function buildProgram(io, result) {
|
|
|
1029
1200
|
checkKind(kind);
|
|
1030
1201
|
// Adopting principles is a Team feature, and it happens on the served page only: that is where the server
|
|
1031
1202
|
// records each adoption with its fingerprint (src/principles.ts withAdoptions).
|
|
1203
|
+
// Records are adopted on the served page too (or at a terminal with bravos records adopt); bravos builds the draft from the record files.
|
|
1204
|
+
if (kind === 'records' && !opts.summary) {
|
|
1205
|
+
await requireFeature(io.env, 'principles', 'Adopting security decision records on the review page');
|
|
1206
|
+
if (opts.share || opts.serve === false)
|
|
1207
|
+
throw new BravosError('records are adopted on the served page only (bravos review records), so each adoption is recorded with the record\'s fingerprint; --share and --no-serve are for other reviews');
|
|
1208
|
+
await (await import('./records-team.js')).recordsDraft(root, io.env);
|
|
1209
|
+
}
|
|
1032
1210
|
if (kind === 'principles' && !opts.summary) {
|
|
1033
1211
|
await requireFeature(io.env, 'principles', 'Adopting security design principles');
|
|
1034
1212
|
if (opts.share || opts.serve === false)
|
|
@@ -1036,7 +1214,8 @@ export function buildProgram(io, result) {
|
|
|
1036
1214
|
}
|
|
1037
1215
|
const draft = readDraft(root, kind);
|
|
1038
1216
|
// A rewritten draft must not lose an answer somebody confirmed (review.ts lostAnswers).
|
|
1039
|
-
|
|
1217
|
+
// A records draft is rebuilt from the records each time; an adoption is kept by its fingerprint, not by the question.
|
|
1218
|
+
if (!opts.summary && kind !== 'records') {
|
|
1040
1219
|
const lost = lostAnswers(draft, readAllAnswers(root, draft).files);
|
|
1041
1220
|
if (lost.length) {
|
|
1042
1221
|
throw new BravosError(`${draftPath(kind)} no longer asks ${lost.map((l) => `${l.id} (answered by ${l.by.join(', ')})`).join('; ')}. ` +
|
|
@@ -1566,8 +1745,11 @@ function isEntry() {
|
|
|
1566
1745
|
return false;
|
|
1567
1746
|
}
|
|
1568
1747
|
}
|
|
1569
|
-
|
|
1748
|
+
// @comment -- "Runs the CLI on this process's arguments; the bin shim (dist/bin.js) calls it, and so does running dist/cli.js directly."
|
|
1749
|
+
export function main() {
|
|
1570
1750
|
run(process.argv.slice(2)).then((code) => {
|
|
1571
1751
|
process.exitCode = code;
|
|
1572
1752
|
});
|
|
1573
1753
|
}
|
|
1754
|
+
if (isEntry())
|
|
1755
|
+
main();
|
package/dist/context.js
CHANGED
|
@@ -450,8 +450,8 @@ export function removePrePush(root, env, dryRun = false) {
|
|
|
450
450
|
}
|
|
451
451
|
}
|
|
452
452
|
// ============================ making the intake travel ============================
|
|
453
|
-
/** The paths the team's context lives at, which must reach the team through git. */
|
|
454
|
-
const MUST_TRAVEL = ['.bravos/context/sources.json', '.guardlink/intent.md', '.guardlink/intent-draft.json', '.guardlink/intent-answers/x.json'];
|
|
453
|
+
/** The paths the team's context lives at, which must reach the team through git: the design documents, the intent, and the security decision records with their adoptions. */
|
|
454
|
+
const MUST_TRAVEL = ['.bravos/context/sources.json', '.guardlink/intent.md', '.guardlink/intent-draft.json', '.guardlink/intent-answers/x.json', '.guardlink/records/x.md', '.guardlink/records-answers/x.json'];
|
|
455
455
|
// @comment -- "Which of the files the team's context lives in (.bravos/context/, .guardlink/intent*) git would never commit, and the rule that hides each (git check-ignore -v, argv array). When the cause is the common blanket `.bravos/` line in the repository's own .gitignore, the narrowest repair is offered: ignore Bravos's folder except its context. Read-only; silent without git."
|
|
456
456
|
export function contextIgnoreFix(root, env = process.env) {
|
|
457
457
|
let out = '';
|
|
@@ -482,14 +482,14 @@ export function contextIgnoreWarning(fix) {
|
|
|
482
482
|
const how = fix.fixable
|
|
483
483
|
? `run bravos context share --yes to change line ${fix.fixable.line} of .gitignore from "${fix.fixable.was}" to "${fix.fixable.becomes.join('" and "')}"`
|
|
484
484
|
: `remove or narrow the rule at ${first.file}:${first.line} ("${first.pattern}")`;
|
|
485
|
-
return `warning: ${first.file}:${first.line} ("${first.pattern}") hides ${[...new Set(fix.problems.map((p) => p.path.replace(/\/x\.json$/, '/')))].join(', ')} from git, so the intake and design documents will not reach your team; ${how}`;
|
|
485
|
+
return `warning: ${first.file}:${first.line} ("${first.pattern}") hides ${[...new Set(fix.problems.map((p) => p.path.replace(/\/x\.(?:json|md)$/, '/')))].join(', ')} from git, so the intake and design documents will not reach your team; ${how}`;
|
|
486
486
|
}
|
|
487
487
|
// @comment -- "bravos context share: says which rule keeps the team's context out of git and, with --yes, makes the narrowest repair to a blanket `.bravos/` line in the repository's own .gitignore (that one line becomes `.bravos/*` and `!.bravos/context/`; every other rule is left as the team wrote it). Without --yes it changes nothing and prints the exact edit, so a person decides."
|
|
488
488
|
export function shareContext(root, yes, env = process.env) {
|
|
489
489
|
const fix = contextIgnoreFix(root, env);
|
|
490
490
|
if (!fix.problems.length)
|
|
491
491
|
return ['context: nothing hides .bravos/context/ or .guardlink/intent* from git here; commit them and your team gets them on their next pull'];
|
|
492
|
-
const lines = fix.problems.map((p) => `${p.path.replace(/\/x\.json$/, '/')} is ignored by ${p.file}:${p.line} ("${p.pattern}")`);
|
|
492
|
+
const lines = fix.problems.map((p) => `${p.path.replace(/\/x\.(?:json|md)$/, '/')} is ignored by ${p.file}:${p.line} ("${p.pattern}")`);
|
|
493
493
|
if (!fix.fixable)
|
|
494
494
|
return [...lines, 'bravos repairs only a blanket .bravos/ line in .gitignore; change the rule above by hand so these paths are committed'];
|
|
495
495
|
const abs = join(root, '.gitignore');
|
package/dist/cursor.js
CHANGED
|
@@ -3,6 +3,7 @@ import { dirname, join } from 'node:path';
|
|
|
3
3
|
import { readLock, sha256, writeLock } from './lock.js';
|
|
4
4
|
import { bravosBlock } from './instruction-blocks.js';
|
|
5
5
|
import { MARKER, skillsRoot } from './skills.js';
|
|
6
|
+
import { editCardsCommand, editGuardCommand } from './hooks.js';
|
|
6
7
|
// @comment -- "Where bravos's Cursor rule lives; Cursor reads project rules from .cursor/rules/*.mdc."
|
|
7
8
|
export const CURSOR_RULE_PATH = '.cursor/rules/bravos.mdc';
|
|
8
9
|
// @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."
|
|
@@ -74,7 +75,9 @@ export function writeCursorPointer(root, harnesses, opts = {}) {
|
|
|
74
75
|
export const CURSOR_HOOKS_PATH = '.cursor/hooks.json';
|
|
75
76
|
// @comment -- "The session-start command Cursor runs: the repo's own hook script, found from any folder in the checkout, told it is Cursor so it prints Cursor's output shape."
|
|
76
77
|
export const CURSOR_SESSION_COMMAND = 'node "$(git rev-parse --show-toplevel)/.bravos/hooks/session-start.mjs" --harness cursor';
|
|
77
|
-
|
|
78
|
+
export const CURSOR_GUARD_MATCHER = '^(Write|Delete)$';
|
|
79
|
+
export const CURSOR_CARDS_MATCHER = '^Write$';
|
|
80
|
+
// @comment -- "Registers bravos's hooks in .cursor/hooks.json: sessionStart, so Cursor gives the agent the briefing (and the first-reply card) at session start, and the record guard (preToolUse) and cards (postToolUse) around each edit. Written when the repo has a .cursor/ folder or the person chose --agent cursor. Merges with the file's other hooks and keeps them; an unreadable or non-object file is left alone and reported. Not lock-recorded: it is shared with the team's own hooks, so uninstall removes only bravos's entry."
|
|
78
81
|
export function writeCursorHooks(root, opts = {}) {
|
|
79
82
|
if (!opts.always && !existsSync(join(root, '.cursor')))
|
|
80
83
|
return { status: 'absent' };
|
|
@@ -94,10 +97,15 @@ export function writeCursorHooks(root, opts = {}) {
|
|
|
94
97
|
}
|
|
95
98
|
}
|
|
96
99
|
const hooks = typeof doc.hooks === 'object' && doc.hooks !== null && !Array.isArray(doc.hooks) ? { ...doc.hooks } : {};
|
|
97
|
-
const
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
100
|
+
const mine = (re) => (e) => typeof e === 'object' && e !== null && re.test(String(e.command ?? ''));
|
|
101
|
+
const put = (event, re, entry) => {
|
|
102
|
+
const current = Array.isArray(hooks[event]) ? hooks[event] : [];
|
|
103
|
+
hooks[event] = [...current.filter((e) => !mine(re)(e)), entry];
|
|
104
|
+
};
|
|
105
|
+
put('sessionStart', /\.bravos\/hooks\/session-start\.mjs/, { command: CURSOR_SESSION_COMMAND });
|
|
106
|
+
// @comment -- "The record guard before an edit and the cards after one. Every agent edit reaches Cursor's hooks as Write (a delete as Delete), and its matcher is an unanchored regex, so both are anchored; postToolUse, not afterFileEdit, is the after-edit event whose additional_context reaches the model."
|
|
107
|
+
put('preToolUse', /\bbravos hook record-guard\b/, { command: editGuardCommand('cursor'), matcher: CURSOR_GUARD_MATCHER, timeout: 10 });
|
|
108
|
+
put('postToolUse', /\bbravos hook cards\b/, { command: editCardsCommand('cursor'), matcher: CURSOR_CARDS_MATCHER, timeout: 10 });
|
|
101
109
|
const next = { version: typeof doc.version === 'number' ? doc.version : 1, ...doc, hooks };
|
|
102
110
|
const text = JSON.stringify(next, null, 2) + '\n';
|
|
103
111
|
if (had && readFileSync(abs, 'utf8') === text)
|
|
@@ -108,6 +116,17 @@ export function writeCursorHooks(root, opts = {}) {
|
|
|
108
116
|
}
|
|
109
117
|
return { status: had ? 'updated' : 'written', path };
|
|
110
118
|
}
|
|
119
|
+
// @comment -- "Which of bravos's edit hooks .cursor/hooks.json registers; an absent or unreadable file reads as none."
|
|
120
|
+
export function cursorEditHooks(root) {
|
|
121
|
+
try {
|
|
122
|
+
const h = JSON.parse(readFileSync(join(root, CURSOR_HOOKS_PATH), 'utf8')).hooks ?? {};
|
|
123
|
+
const has = (event, re) => Array.isArray(h[event]) && h[event].some((e) => re.test(String(e?.command ?? '')));
|
|
124
|
+
return { guard: has('preToolUse', /\bbravos hook record-guard --harness cursor\b/), cards: has('postToolUse', /\bbravos hook cards --harness cursor\b/) };
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
return { guard: false, cards: false };
|
|
128
|
+
}
|
|
129
|
+
}
|
|
111
130
|
// @comment -- "True when .cursor/hooks.json registers bravos's session-start hook; an absent or unreadable file reads as false."
|
|
112
131
|
export function cursorHookRegistered(root) {
|
|
113
132
|
try {
|
package/dist/dashboard.js
CHANGED
|
@@ -265,6 +265,12 @@ export async function buildDashboard(root, env, opts = {}) {
|
|
|
265
265
|
rulesPart = { state: rules.state === 'none' ? 'missing' : 'present', note: rules.note };
|
|
266
266
|
// The Security design view is on the Team plan; on Free the principles stay followed (the instruction block) and
|
|
267
267
|
// the view says what would show them.
|
|
268
|
+
// The decision records view is on the Team plan too; on Free the records stay followed (the briefing, the edit hooks).
|
|
269
|
+
if (rules.records?.length) {
|
|
270
|
+
const f = await featureState(env, 'principles', 'The Decision records view');
|
|
271
|
+
if (!f.entitled)
|
|
272
|
+
rules = { ...rules, records: [], recordsNote: `${rules.records.length} record rule${rules.records.length === 1 ? ' is' : 's are'} written down here, and coding agents follow the adopted ones on every plan. ${f.refusal}.` };
|
|
273
|
+
}
|
|
268
274
|
if (rules.principles.length) {
|
|
269
275
|
const f = await featureState(env, 'principles', 'The Security design view');
|
|
270
276
|
if (!f.entitled)
|
package/dist/doctor.js
CHANGED
|
@@ -4,9 +4,11 @@ import { join } from 'node:path';
|
|
|
4
4
|
import { installedGuardlinkSkills, whichBin } from './guardlink.js';
|
|
5
5
|
import { graphBin } from './codegraph.js';
|
|
6
6
|
import { findAnalyzer, findLicence } from './graphbin.js';
|
|
7
|
-
import { ALL_AUTOPILOT_COMMANDS, ALL_CARDS_COMMANDS, ALL_COACH_COMMANDS, ALL_PRE_PR_COMMANDS, HOOK_COMMANDS, LEGACY_HOOK_COMMAND, RELATIVE_HOOK_COMMANDS, hookRegistered } from './hooks.js';
|
|
7
|
+
import { ALL_AUTOPILOT_COMMANDS, ALL_CARDS_COMMANDS, ALL_COACH_COMMANDS, ALL_PRE_PR_COMMANDS, ALL_RECORD_GUARD_COMMANDS, HOOK_COMMANDS, LEGACY_HOOK_COMMAND, RELATIVE_HOOK_COMMANDS, agyRegistered, hookRegistered } from './hooks.js';
|
|
8
8
|
import { skillsRoot } from './skills.js';
|
|
9
|
-
import { cursorHookRegistered } from './cursor.js';
|
|
9
|
+
import { cursorEditHooks, cursorHookRegistered } from './cursor.js';
|
|
10
|
+
import { OMP_EXTENSION_PATH } from './omp.js';
|
|
11
|
+
import { OPENCODE_PLUGIN_PATH } from './opencode.js';
|
|
10
12
|
import { contextIgnoreFix, contextIgnoreWarning } from './context.js';
|
|
11
13
|
import { resolveTheme } from './palette.js';
|
|
12
14
|
import { pathToFileURL } from 'node:url';
|
|
@@ -88,10 +90,34 @@ export function runDoctor(root, env = process.env) {
|
|
|
88
90
|
claude: hookRegistered(join(root, '.claude', 'settings.json'), 'PreToolUse', ALL_PRE_PR_COMMANDS),
|
|
89
91
|
codex: hookRegistered(join(root, '.codex', 'hooks.json'), 'PreToolUse', ALL_PRE_PR_COMMANDS),
|
|
90
92
|
},
|
|
93
|
+
edit_hooks: editHooks(root),
|
|
91
94
|
theme: resolveTheme(env),
|
|
92
95
|
updates: readUpdates(env),
|
|
93
96
|
};
|
|
94
97
|
}
|
|
98
|
+
// @comment -- "Which agents get the record guard and the after-edit cards here, read from the files Bravos wrote for each: the Claude Code and Codex settings, .cursor/hooks.json, .agents/hooks.json, and the opencode and omp plugin files (whose tool hooks call bravos hook). An agent Bravos has not set up here reads as null, not as missing."
|
|
99
|
+
function editHooks(root) {
|
|
100
|
+
const claude = join(root, '.claude', 'settings.json');
|
|
101
|
+
const codex = join(root, '.codex', 'hooks.json');
|
|
102
|
+
const plugin = (rel) => {
|
|
103
|
+
try {
|
|
104
|
+
const t = readFileSync(join(root, rel), 'utf8');
|
|
105
|
+
return { guard: t.includes("askBravos('record-guard'"), cards: t.includes("askBravos('cards'") };
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
const agy = existsSync(join(root, '.agents', 'hooks.json')) ? agyRegistered(root) : null;
|
|
112
|
+
return {
|
|
113
|
+
claude: existsSync(claude) ? { guard: hookRegistered(claude, 'PreToolUse', ALL_RECORD_GUARD_COMMANDS), cards: hookRegistered(claude, 'PostToolUse', ALL_CARDS_COMMANDS) } : null,
|
|
114
|
+
codex: existsSync(codex) ? { guard: hookRegistered(codex, 'PreToolUse', ALL_RECORD_GUARD_COMMANDS), cards: hookRegistered(codex, 'PostToolUse', ALL_CARDS_COMMANDS) } : null,
|
|
115
|
+
cursor: existsSync(join(root, '.cursor', 'hooks.json')) ? cursorEditHooks(root) : null,
|
|
116
|
+
antigravity: agy ? { guard: agy.guard, cards: agy.cards } : null,
|
|
117
|
+
opencode: plugin(OPENCODE_PLUGIN_PATH),
|
|
118
|
+
omp: plugin(OMP_EXTENSION_PATH),
|
|
119
|
+
};
|
|
120
|
+
}
|
|
95
121
|
// @comment -- "What the daily update check last saw (~/.bravos/update-check.json, written by hooks/lib/update-check.mjs): off, never checked, or the latest published version and when it was checked. Only a dotted version string is read from the file."
|
|
96
122
|
function readUpdates(env) {
|
|
97
123
|
const installed = packageVersion();
|
|
@@ -154,6 +180,7 @@ export function formatDoctor(r) {
|
|
|
154
180
|
`pre-pr claude: ${yn(r.pre_pr.claude)} codex: ${yn(r.pre_pr.codex)}${r.pre_pr.claude || r.pre_pr.codex ? '' : ' (opt-in: bravos setup --pre-pr-hook)'}`,
|
|
155
181
|
`autopilot claude: ${yn(r.autopilot.claude)} codex: ${yn(r.autopilot.codex)}${r.autopilot.claude || r.autopilot.codex ? '' : ' (opt-in: bravos setup --autopilot)'}`,
|
|
156
182
|
`cards claude: ${yn(r.cards.claude)} codex: ${yn(r.cards.codex)}${r.cards.claude || r.cards.codex ? (process.env.BRAVOS_THREAT_CARDS === 'off' ? ' (off for this run: BRAVOS_THREAT_CARDS=off)' : '') : ' (bravos setup adds it)'}`,
|
|
183
|
+
`edit hooks (record guard / cards) ${Object.entries(r.edit_hooks ?? {}).filter(([, v]) => v).map(([k, v]) => `${k}: ${v.guard && v.cards ? 'yes' : v.guard || v.cards ? `partly (guard ${yn(v.guard)}, cards ${yn(v.cards)})` : 'no'}`).join(' ') || 'no agent set up here'}${Object.values(r.edit_hooks ?? {}).some((v) => v && !(v.guard && v.cards)) ? ' (bravos setup wires them)' : ''}`,
|
|
157
184
|
`coach claude: ${yn(r.coach.claude)} codex: ${yn(r.coach.codex)}${r.coach.claude || r.coach.codex ? (process.env.BRAVOS_COACH === 'off' ? ' (off for this run: BRAVOS_COACH=off)' : '') : ' (bravos setup adds it)'}`,
|
|
158
185
|
...(r.dead_hooks?.length ? [`✘ dead user-level hooks ${r.dead_hooks.map((d) => `${d.file} ${d.event}: ${d.script} is gone`).join('; ')} — every session shows "hook error". Remove them (a backup is kept): bravos doctor --fix-hooks`] : r.dead_hooks ? ['✔ no dead user-level hooks'] : []),
|
|
159
186
|
...(r.legacy_skills?.length ? [`✘ old Python bravos skills ${r.legacy_skills.map((f) => `${f.root}: ${f.names.join(', ')}`).join('; ')} — your agent may load them instead of this repository's. Move them aside (reversible): ${r.legacy_command}`] : r.legacy_skills ? ['✔ no old Python bravos skills at user level'] : []),
|