@bugb-technologies/bravos 1.24.0 → 1.26.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/bin.js +12 -0
- package/dist/cli.js +222 -16
- package/dist/context.js +4 -4
- package/dist/cursor.js +24 -5
- package/dist/dashboard-sast.js +113 -0
- package/dist/dashboard.js +22 -11
- 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/plugin-release.js +38 -12
- package/dist/prefs.js +13 -3
- package/dist/principles.js +1 -1
- package/dist/records-conflicts.js +128 -0
- 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 +97 -4
- package/dist/setup.js +6 -6
- package/dist/uninstall.js +1 -1
- package/dist/upkeep.js +3 -0
- package/docs/GUIDE.md +11 -1
- package/docs/UPGRADING.md +56 -0
- package/hooks/cards.mjs +63 -14
- package/hooks/coach.mjs +3 -1
- package/hooks/lib/agent-io.mjs +118 -0
- package/hooks/lib/briefing.mjs +94 -3
- package/hooks/lib/cards.mjs +8 -1
- 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/lib/sast.mjs +3 -1
- package/hooks/record-guard.mjs +62 -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 +198 -1
- package/templates/omp/bravos.js +85 -1
- package/templates/opencode/bravos.js +84 -1
- package/templates/plugin/workspace-hook.mjs +37 -0
- package/templates/workflows/bravos-pr-gate.yml +23 -0
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
|
@@ -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)
|
|
@@ -928,7 +935,7 @@ export function buildProgram(io, result) {
|
|
|
928
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."
|
|
929
936
|
program
|
|
930
937
|
.command('prefs <action> [args...]')
|
|
931
|
-
.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.')
|
|
932
939
|
.option('-C, --dir <dir>', 'the repository (default: the current directory)')
|
|
933
940
|
.option('--by <name>', 'set: whose answer this is')
|
|
934
941
|
.option('--json', 'get: print JSON')
|
|
@@ -937,10 +944,10 @@ export function buildProgram(io, result) {
|
|
|
937
944
|
const dir = dirArg(opts.dir);
|
|
938
945
|
if (action === 'get' && args.length === 0)
|
|
939
946
|
lines.push(...(await getPrefs(dir, io.env, !!opts.json)));
|
|
940
|
-
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)
|
|
941
948
|
lines.push(...(await setPref(dir, args[0], args[1], opts.by, io.env)));
|
|
942
949
|
else
|
|
943
|
-
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>"');
|
|
944
951
|
}));
|
|
945
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."
|
|
946
953
|
program
|
|
@@ -1024,6 +1031,194 @@ export function buildProgram(io, result) {
|
|
|
1024
1031
|
else
|
|
1025
1032
|
throw new BravosError(`unknown principles action '${action}'; use check, list, write, except or copy`);
|
|
1026
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 conflicts` lists the open exposures and SAST findings in a record\'s paths that may go against one of its rules, with why (suggestions, never a status; `records conflicts dismiss <key> --reason "<why>"` at your own terminal; Team plan); `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 === 'conflicts') {
|
|
1121
|
+
// @comment -- "bravos records conflicts: the possible conflicts between each record and the code it covers, the same list the dashboard's Decision records view shows (Team plan, like that view). dismiss <key> is a person's decision, at their own terminal where they type their name, as adopting is: recorded in .guardlink/records-dismissals.json, never as @accepts, and the exposure or finding is left as it is."
|
|
1122
|
+
await requireFeature(io.env, 'principles', 'Possible conflicts between records and the code');
|
|
1123
|
+
const C = await import('./records-conflicts.js');
|
|
1124
|
+
const doc = await (await import('./rules.js')).gatherRules(root, io.env, { names: true, details: false });
|
|
1125
|
+
const conflicts = doc.conflicts ?? [];
|
|
1126
|
+
if (args[0] === 'dismiss') {
|
|
1127
|
+
const key = args[1];
|
|
1128
|
+
if (!key || !opts.reason)
|
|
1129
|
+
throw new BravosError('usage: bravos records conflicts dismiss <key> --reason "<why it is not a conflict>"');
|
|
1130
|
+
// @mitigates #records against #forged-record using #person-only-adoption -- "A dismissal needs an interactive terminal where the person types their own name; a coding agent's shell has none, so it cannot dismiss one"
|
|
1131
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY)
|
|
1132
|
+
throw new BravosError('dismissing a possible conflict is a person\'s decision: run this yourself in a terminal, where you type your name. A coding agent cannot dismiss one.');
|
|
1133
|
+
const c = conflicts.find((x) => x.key === key);
|
|
1134
|
+
if (!c)
|
|
1135
|
+
throw new BravosError(`no possible conflict with key ${key} here (bravos records conflicts lists them)`);
|
|
1136
|
+
const rl = (await import('node:readline/promises')).createInterface({ input: process.stdin, output: process.stdout });
|
|
1137
|
+
try {
|
|
1138
|
+
io.stdout(`${c.record} ${c.rule} "${c.ruleText}"\n ${c.what} at ${c.file}${c.line ? `:${c.line}` : ''}\n why it was suggested: ${c.reason}\n your reason: ${opts.reason}`);
|
|
1139
|
+
const by = (await rl.question('Your name, dismissing this as not a conflict: ')).trim();
|
|
1140
|
+
if (!by)
|
|
1141
|
+
throw new BravosError('not dismissed: no name was typed');
|
|
1142
|
+
const d = C.addDismissal(root, c, by, opts.reason);
|
|
1143
|
+
lines.push(`Dismissed ${d.key} for ${d.record} ${d.rule}, by ${d.by} on ${d.at}, in ${C.DISMISSALS_FILE}. The exposure or finding is unchanged; commit the file so the team sees the decision.`);
|
|
1144
|
+
}
|
|
1145
|
+
finally {
|
|
1146
|
+
rl.close();
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
else
|
|
1150
|
+
lines.push(...(opts.json ? [JSON.stringify({ schema: 'bravos.records-conflicts/v1', conflicts }, null, 2)] : C.conflictLines(conflicts)));
|
|
1151
|
+
}
|
|
1152
|
+
else if (act === 'drafts' || act === 'draft') {
|
|
1153
|
+
// @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."
|
|
1154
|
+
await requireFeature(io.env, 'principles', 'Drafting security decision records');
|
|
1155
|
+
const Dr = await import('./records-drafts.js');
|
|
1156
|
+
if (act === 'drafts') {
|
|
1157
|
+
const n = opts.limit === undefined ? undefined : Number(opts.limit);
|
|
1158
|
+
if (n !== undefined && (!Number.isInteger(n) || n < 0 || n > 20))
|
|
1159
|
+
throw new BravosError('--limit takes a whole number from 0 to 20');
|
|
1160
|
+
const d = await Dr.draftsList(root, io.env, n);
|
|
1161
|
+
lines.push(...(opts.json ? [JSON.stringify(d.json, null, 2)] : d.lines));
|
|
1162
|
+
}
|
|
1163
|
+
else {
|
|
1164
|
+
if (!args.length)
|
|
1165
|
+
throw new BravosError('usage: bravos records draft "<module>" [--worktree <dir>]');
|
|
1166
|
+
lines.push(...(await Dr.draftStart(root, args.join(' '), io.env, { worktree: opts.worktree })));
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
else if (act === 'ledger') {
|
|
1170
|
+
// @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."
|
|
1171
|
+
const Lg = await import('./records-ledger.js');
|
|
1172
|
+
const sub = args[0] ?? 'list';
|
|
1173
|
+
if (sub === 'list') {
|
|
1174
|
+
const l = await Lg.ledgerList(root);
|
|
1175
|
+
lines.push(...(opts.json ? [JSON.stringify(l.json, null, 2)] : l.lines));
|
|
1176
|
+
}
|
|
1177
|
+
else if (sub === 'propose')
|
|
1178
|
+
lines.push(...(await Lg.ledgerPropose(root, !!opts.write)));
|
|
1179
|
+
else if (sub === 'add')
|
|
1180
|
+
lines.push(...(await Lg.ledgerAdd(root, args.slice(1).join(' '), opts)));
|
|
1181
|
+
else if (sub === 'remove')
|
|
1182
|
+
lines.push(...(await Lg.ledgerRemove(root, args.slice(1).join(' '))));
|
|
1183
|
+
else if (sub === 'refresh')
|
|
1184
|
+
lines.push(...(await Lg.ledgerRefresh(root)));
|
|
1185
|
+
else
|
|
1186
|
+
throw new BravosError('usage: bravos records ledger [list|propose [--write]|add "<module>" --paths … --needs yes|optional|remove "<module>"|refresh]');
|
|
1187
|
+
}
|
|
1188
|
+
else if (act === 'gaps') {
|
|
1189
|
+
await requireFeature(io.env, 'principles', 'The records gaps report');
|
|
1190
|
+
const T = await import('./records-team.js');
|
|
1191
|
+
const g = await T.recordGaps(root, io.env);
|
|
1192
|
+
lines.push(...(opts.json ? [JSON.stringify({ schema: 'bravos.records-gaps/v1', modules: g.modules }, null, 2)] : g.lines));
|
|
1193
|
+
}
|
|
1194
|
+
else if (act === 'except') {
|
|
1195
|
+
await requireFeature(io.env, 'principles', 'Exceptions to security decision records');
|
|
1196
|
+
const T = await import('./records-team.js');
|
|
1197
|
+
if (opts.clearExpired) {
|
|
1198
|
+
lines.push(...(await T.clearExpiredRecordExceptions(root)));
|
|
1199
|
+
return;
|
|
1200
|
+
}
|
|
1201
|
+
if (args.length !== 2 || !opts.where || !opts.reason || !opts.until)
|
|
1202
|
+
throw new BravosError('usage: bravos records except SDR-n R1 --where "<glob>" --reason "<why>" --until YYYY-MM-DD');
|
|
1203
|
+
// @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"
|
|
1204
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY)
|
|
1205
|
+
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.');
|
|
1206
|
+
const rl = (await import('node:readline/promises')).createInterface({ input: process.stdin, output: process.stdout });
|
|
1207
|
+
try {
|
|
1208
|
+
io.stdout(`Exception to ${args[0]} ${args[1]} for ${opts.where} until ${opts.until}: ${opts.reason}`);
|
|
1209
|
+
const by = (await rl.question('Your name, approving this exception: ')).trim();
|
|
1210
|
+
const typed = (await rl.question(`Type ${args[0]} ${args[1]} to confirm: `)).trim();
|
|
1211
|
+
if (typed !== `${args[0]} ${args[1]}`)
|
|
1212
|
+
throw new BravosError('not confirmed: the rule did not match, nothing was recorded');
|
|
1213
|
+
lines.push(...(await T.addRecordException(root, { record: args[0], rule: args[1], where: opts.where, reason: opts.reason, until: opts.until, by }, io.env)));
|
|
1214
|
+
}
|
|
1215
|
+
finally {
|
|
1216
|
+
rl.close();
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
else
|
|
1220
|
+
throw new BravosError(`unknown records action '${act}'; use list, show, for, check, new, adopt, except, gaps, codeowners, ledger, drafts, draft or conflicts`);
|
|
1221
|
+
}));
|
|
1027
1222
|
program
|
|
1028
1223
|
.command('review <kind> [dir]')
|
|
1029
1224
|
.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.")
|
|
@@ -1037,6 +1232,13 @@ export function buildProgram(io, result) {
|
|
|
1037
1232
|
checkKind(kind);
|
|
1038
1233
|
// Adopting principles is a Team feature, and it happens on the served page only: that is where the server
|
|
1039
1234
|
// records each adoption with its fingerprint (src/principles.ts withAdoptions).
|
|
1235
|
+
// Records are adopted on the served page too (or at a terminal with bravos records adopt); bravos builds the draft from the record files.
|
|
1236
|
+
if (kind === 'records' && !opts.summary) {
|
|
1237
|
+
await requireFeature(io.env, 'principles', 'Adopting security decision records on the review page');
|
|
1238
|
+
if (opts.share || opts.serve === false)
|
|
1239
|
+
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');
|
|
1240
|
+
await (await import('./records-team.js')).recordsDraft(root, io.env);
|
|
1241
|
+
}
|
|
1040
1242
|
if (kind === 'principles' && !opts.summary) {
|
|
1041
1243
|
await requireFeature(io.env, 'principles', 'Adopting security design principles');
|
|
1042
1244
|
if (opts.share || opts.serve === false)
|
|
@@ -1044,7 +1246,8 @@ export function buildProgram(io, result) {
|
|
|
1044
1246
|
}
|
|
1045
1247
|
const draft = readDraft(root, kind);
|
|
1046
1248
|
// A rewritten draft must not lose an answer somebody confirmed (review.ts lostAnswers).
|
|
1047
|
-
|
|
1249
|
+
// A records draft is rebuilt from the records each time; an adoption is kept by its fingerprint, not by the question.
|
|
1250
|
+
if (!opts.summary && kind !== 'records') {
|
|
1048
1251
|
const lost = lostAnswers(draft, readAllAnswers(root, draft).files);
|
|
1049
1252
|
if (lost.length) {
|
|
1050
1253
|
throw new BravosError(`${draftPath(kind)} no longer asks ${lost.map((l) => `${l.id} (answered by ${l.by.join(', ')})`).join('; ')}. ` +
|
|
@@ -1203,7 +1406,7 @@ export function buildProgram(io, result) {
|
|
|
1203
1406
|
lines.push(JSON.stringify({ schema: 'bravos.dashboard-run/v1', path: r.path, opened, threatModel: r.threatModel, rules: r.rules, codeGraph: r.codeGraph }, null, 2));
|
|
1204
1407
|
return;
|
|
1205
1408
|
}
|
|
1206
|
-
lines.push(`Dashboard: ${r.path}${opened ? ' (opened in your browser)' : ''}`, ` threat model: ${r.threatModel.note}`, ` design rules: ${r.rules.note}`, ` code graph: ${r.codeGraph.note}`);
|
|
1409
|
+
lines.push(`Dashboard: ${r.path}${opened ? ' (opened in your browser)' : ''}`, ` threat model: ${r.threatModel.note}`, ` design rules: ${r.rules.note}`, ` code graph: ${r.codeGraph.note}`, ` sast: ${r.sast.note}`);
|
|
1207
1410
|
if (!opened && opts.open !== false)
|
|
1208
1411
|
lines.push(' No browser could be opened here; open the file above.');
|
|
1209
1412
|
}));
|
|
@@ -1574,8 +1777,11 @@ function isEntry() {
|
|
|
1574
1777
|
return false;
|
|
1575
1778
|
}
|
|
1576
1779
|
}
|
|
1577
|
-
|
|
1780
|
+
// @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."
|
|
1781
|
+
export function main() {
|
|
1578
1782
|
run(process.argv.slice(2)).then((code) => {
|
|
1579
1783
|
process.exitCode = code;
|
|
1580
1784
|
});
|
|
1581
1785
|
}
|
|
1786
|
+
if (isEntry())
|
|
1787
|
+
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 {
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { pathToFileURL } from 'node:url';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { featureState } from './licence.js';
|
|
4
|
+
import { hooksDir } from './paths.js';
|
|
5
|
+
const lib = (name) => import(pathToFileURL(join(hooksDir(), 'lib', name)).href);
|
|
6
|
+
const MAX_ROWS = 300;
|
|
7
|
+
const str = (v, max = 300) => String(v ?? '').replace(/[\u0000-\u001f\u007f]/g, ' ').replace(/\s+/g, ' ').trim().slice(0, max);
|
|
8
|
+
const num = (v) => (typeof v === 'number' && Number.isFinite(v) ? v : null);
|
|
9
|
+
const TIERS = { t1: 'T1', t2: 'T2', t3: 'T3' };
|
|
10
|
+
// @mitigates #dashboard-sast against #secret-on-shared-page using #withhold-credentials -- "safeText scans every copied string and withholds one that looks like a credential; secret findings carry type and place only"
|
|
11
|
+
// @comment -- "Every string bound for the page goes through this: cleaned to one line and cut, then the secret scan; a string that looks like it holds a credential is replaced by what kind it looks like, so no value reaches a file people share even if an analyzer message ever quoted one."
|
|
12
|
+
function safeText(ctx) {
|
|
13
|
+
return (v, max = 300) => {
|
|
14
|
+
const s = str(v, max);
|
|
15
|
+
const hit = s ? ctx.scanSecrets(s)[0] : undefined;
|
|
16
|
+
return hit ? `[withheld: ${ctx.an(hit.rule)}]` : s;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/** The SAST part of the dashboard for this repository, never throwing: a run that cannot be read is said, not hidden. */
|
|
20
|
+
export async function buildSastPart(root, env) {
|
|
21
|
+
const f = await featureState(env, 'sast', 'The SAST view');
|
|
22
|
+
if (!f.entitled)
|
|
23
|
+
return { state: 'off', note: `SAST is on the Team plan; with it this view lists the analyzer's findings, what they reach and the threats they join. ${f.refusal}.`, view: null, issues: null, reportId: null };
|
|
24
|
+
try {
|
|
25
|
+
const S = await lib('sast.mjs');
|
|
26
|
+
const C = await lib('context.mjs');
|
|
27
|
+
const run = S.latestRun(root);
|
|
28
|
+
if (!run)
|
|
29
|
+
return { state: 'missing', note: 'No SAST run here yet. bravos sast run analyzes the repository (with the code graph built first, it also says which findings are reached); then run bravos dashboard again.', view: null, issues: null, reportId: null };
|
|
30
|
+
const summary = S.readSast(root, env);
|
|
31
|
+
const t = safeText(C);
|
|
32
|
+
const findings = (Array.isArray(run.report.findings) ? run.report.findings : []).filter((x) => x && typeof x === 'object' && !x.suppressed);
|
|
33
|
+
const view = {
|
|
34
|
+
run: t(run.name, 80),
|
|
35
|
+
at: typeof run.meta?.at === 'string' ? t(run.meta.at, 40) : null,
|
|
36
|
+
sha: typeof run.meta?.sha === 'string' && /^[0-9a-f]{7,40}$/.test(run.meta.sha) ? run.meta.sha.slice(0, 12) : null,
|
|
37
|
+
staleCommits: summary?.staleCommits ?? null,
|
|
38
|
+
analyzer: run.report.analyzer_version ? t(run.report.analyzer_version, 40) : null,
|
|
39
|
+
graph: run.report.graph_currency && typeof run.report.graph_currency === 'object' ? t(run.report.graph_currency.state, 40) || null : null,
|
|
40
|
+
total: findings.length,
|
|
41
|
+
suppressed: (Array.isArray(run.report.findings) ? run.report.findings.length : 0) - findings.length,
|
|
42
|
+
byClass: {},
|
|
43
|
+
bySeverity: {},
|
|
44
|
+
joined: [],
|
|
45
|
+
unjoined: [],
|
|
46
|
+
dependencies: [],
|
|
47
|
+
secrets: [],
|
|
48
|
+
agentConfig: { count: 0, rules: [] },
|
|
49
|
+
};
|
|
50
|
+
const issues = [];
|
|
51
|
+
findings.forEach((x, i) => {
|
|
52
|
+
const cls = t(x.finding_class || 'static_analysis', 40);
|
|
53
|
+
const severity = t(x.severity || 'unrated', 20).toLowerCase();
|
|
54
|
+
view.byClass[cls] = (view.byClass[cls] ?? 0) + 1;
|
|
55
|
+
view.bySeverity[severity] = (view.bySeverity[severity] ?? 0) + 1;
|
|
56
|
+
const key = t(x.finding_id || x.id || `${run.name}/${i}`, 120);
|
|
57
|
+
const file = x.file ? t(x.file, 400) : null;
|
|
58
|
+
const line = num(x.line);
|
|
59
|
+
const tier = TIERS[String(x.evidence_tier ?? '').slice(0, 2).toLowerCase()] ?? null;
|
|
60
|
+
if (tier && file && issues.length < 2000)
|
|
61
|
+
issues.push({ key, tier, rule: t(x.rule_id, 160), title: t(x.title || x.rule_id, 200), location: { file, line, symbol: x.enclosing_function ? t(x.enclosing_function, 160) : null } });
|
|
62
|
+
if (cls === 'agent_config') {
|
|
63
|
+
view.agentConfig.count += 1;
|
|
64
|
+
const rule = t(x.rule_id, 160);
|
|
65
|
+
if (rule && !view.agentConfig.rules.includes(rule) && view.agentConfig.rules.length < 20)
|
|
66
|
+
view.agentConfig.rules.push(rule);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (cls === 'secret') {
|
|
70
|
+
// A secret by its type and place only: never the analyzer's message, never a snippet.
|
|
71
|
+
if (view.secrets.length < MAX_ROWS)
|
|
72
|
+
view.secrets.push({ key, type: t(x.title || x.rule_id, 120), rule: t(x.rule_id, 160), file, line, inHistory: !!x.secret_in_history, remediation: t(String(x.secret_remediation ?? 'rotate the credential and remove it from the source').replace(/_/g, ' '), 160) });
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const reachable = x.reachable === true ? true : x.reachable === false ? false : null;
|
|
76
|
+
const row = {
|
|
77
|
+
key,
|
|
78
|
+
severity,
|
|
79
|
+
rule: t(x.rule_id, 160),
|
|
80
|
+
title: t(x.title || x.vuln_type || x.rule_id, 200),
|
|
81
|
+
file,
|
|
82
|
+
line,
|
|
83
|
+
reachable,
|
|
84
|
+
reach: t(x.reach_label || (reachable === true ? 'reached from an entry point' : reachable === false ? 'not reached from any entry point' : 'not known'), 200),
|
|
85
|
+
claim: x.guardlink_join && x.guardlink_join !== 'unjoined' && x.guardlink_join !== 'none' ? t(S.claimLabel(x.guardlink_join), 200) : null,
|
|
86
|
+
tier: tier ?? (x.evidence_tier ? t(x.evidence_tier, 30) : null),
|
|
87
|
+
route: x.http_method || x.http_path ? t(`${x.http_method ?? ''} ${x.http_path ?? ''}`, 200) : null,
|
|
88
|
+
function: x.enclosing_function ? t(x.enclosing_function, 160) : null,
|
|
89
|
+
};
|
|
90
|
+
if (cls === 'dependency') {
|
|
91
|
+
if (view.dependencies.length < MAX_ROWS)
|
|
92
|
+
view.dependencies.push({ ...row, manifests: (Array.isArray(x.dep_manifests) ? x.dep_manifests : []).slice(0, 10).map((m) => t(m, 200)), devOnly: !!x.dep_dev_only, vulnerableFunction: t(S.reachLabel(x.vulnerable_function_reachability), 200) });
|
|
93
|
+
}
|
|
94
|
+
else if (row.claim) {
|
|
95
|
+
if (view.joined.length < MAX_ROWS)
|
|
96
|
+
view.joined.push(row);
|
|
97
|
+
}
|
|
98
|
+
else if (view.unjoined.length < MAX_ROWS)
|
|
99
|
+
view.unjoined.push(row);
|
|
100
|
+
});
|
|
101
|
+
// Reached first, then not known, then not reached; worst severity first within each.
|
|
102
|
+
const rank = (r) => (r.reachable === true ? 0 : r.reachable === null ? 1 : 2) * 10 + (r.severity === 'error' || r.severity === 'critical' || r.severity === 'high' ? 0 : r.severity === 'warning' || r.severity === 'medium' ? 1 : 2);
|
|
103
|
+
for (const list of [view.joined, view.unjoined, view.dependencies])
|
|
104
|
+
list.sort((a, b) => rank(a) - rank(b) || String(a.file).localeCompare(String(b.file)) || (a.line ?? 0) - (b.line ?? 0));
|
|
105
|
+
const age = view.staleCommits === null ? '' : view.staleCommits === 0 ? ', at the commit checked out now' : `, ${view.staleCommits} commit${view.staleCommits === 1 ? '' : 's'} behind HEAD (bravos sast run again for the current code)`;
|
|
106
|
+
const reached = findings.filter((x) => x.reachable === true).length;
|
|
107
|
+
const note = `SAST run ${view.run}${view.at ? ` (${view.at.slice(0, 16).replace('T', ' ')} UTC)` : ''}${age}: ${view.total} finding${view.total === 1 ? '' : 's'}, ${reached} reached from an entry point, ${view.joined.length} joined to the threat model, ${view.unjoined.length} not in it yet, ${view.secrets.length} secret${view.secrets.length === 1 ? '' : 's'}.`;
|
|
108
|
+
return { state: 'present', note, view, issues, reportId: view.run };
|
|
109
|
+
}
|
|
110
|
+
catch (e) {
|
|
111
|
+
return { state: 'missing', note: `The newest SAST run could not be read (${str(e.message, 200)}); bravos sast status says more.`, view: null, issues: null, reportId: null };
|
|
112
|
+
}
|
|
113
|
+
}
|