@bugb-technologies/bravos 1.2.1 → 1.4.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.
Files changed (47) hide show
  1. package/README.md +17 -10
  2. package/dist/ci.js +11 -3
  3. package/dist/cli.js +50 -8
  4. package/dist/doctor.js +4 -16
  5. package/dist/guide.js +5 -3
  6. package/dist/help.js +16 -16
  7. package/dist/hooks.js +21 -0
  8. package/dist/install-proof-tool.js +117 -0
  9. package/dist/proof-tools.js +29 -0
  10. package/dist/report/check.js +4 -1
  11. package/dist/report/data.js +81 -149
  12. package/dist/report/markdown.js +1 -1
  13. package/dist/report/redact.js +16 -0
  14. package/dist/report/runs.js +169 -0
  15. package/dist/resync.js +272 -0
  16. package/dist/setup.js +31 -16
  17. package/dist/start/answers.js +5 -3
  18. package/dist/start/index.js +28 -14
  19. package/dist/versions.js +4 -3
  20. package/docs/GUIDE.md +12 -2
  21. package/hooks/lib/autopilot.mjs +216 -77
  22. package/hooks/lib/briefing.mjs +36 -5
  23. package/hooks/lib/nightly-stage.mjs +66 -0
  24. package/hooks/lib/nightly-tools.sh +45 -0
  25. package/hooks/lib/pre-pr.mjs +88 -17
  26. package/hooks/lib/proof-tool-pins.json +12 -0
  27. package/hooks/lib/replay.mjs +579 -0
  28. package/hooks/lib/resync.mjs +78 -0
  29. package/hooks/lib/setup.mjs +15 -6
  30. package/hooks/lib/snapshot.mjs +189 -0
  31. package/hooks/session-start.mjs +7 -3
  32. package/package.json +1 -1
  33. package/skills/bravos/SKILL.md +2 -1
  34. package/skills/bravos-annotate/SKILL.md +6 -5
  35. package/skills/bravos-annotate/scripts/slice.mjs +15 -8
  36. package/skills/bravos-cicd/SKILL.md +1 -1
  37. package/skills/bravos-env/SKILL.md +3 -3
  38. package/skills/bravos-prove/SKILL.md +11 -15
  39. package/skills/bravos-recheck/SKILL.md +3 -3
  40. package/skills/bravos-report/SKILL.md +1 -1
  41. package/skills/bravos-resync/SKILL.md +52 -0
  42. package/skills/bravos-schedule/SKILL.md +1 -1
  43. package/skills/bravos-ship/SKILL.md +1 -1
  44. package/skills/bravos-templatize/SKILL.md +3 -3
  45. package/templates/workflows/bravos-nightly-claude.yml +131 -74
  46. package/templates/workflows/bravos-nightly-codex.yml +130 -73
  47. package/templates/workflows/bravos-pr-gate.yml +88 -14
@@ -16,9 +16,9 @@ description: "Keep findings from going stale after code changes: list the claims
16
16
  2. List what went stale: run `guardlink ci -f json` and take each `stale[]` entry whose file is in `git diff --name-only <base>...HEAD`. Then widen it past the changed files. With the code graph (its MCP tools, or `bravos graph <question> --json` — same answers; see bravos-codegraph) (briefing `Code graph:` says `current`; rebuild with `no-exec` when `diverged`): `codegraph_impact` on each changed symbol, and `codegraph_callers` where a control moved, give the code whose path runs through the change; add the claims in those files to the list. A fix that removes the only route to a sink (`codegraph_entry_reach` now says unreachable) is a reason to replay its kit and refute it with a run, never a refutation by itself. Read `verdict` and `confidence` first. Without the graph, say "code graph unavailable; rechecking the changed files only". When SAST is available and a run exists, rerun it on the changed files (bravos-sast, `--scope <file>` for each) and compare with `bravos-cli diff <new>.json <old>.json`: a finding that is gone is a reason to replay its kit and refute it with a run, never a refutation by itself. With SAST unavailable, say so and skip it.
17
17
  3. For each stale claim, re-read the code beneath it and decide whether the claim still says what the code does. If it does not, fix the annotation in this session with bravos-annotate's rules (write an `@audit` beside a claim you did not write rather than editing it).
18
18
  4. Re-lock only the claims you re-read and still hold: preview with `guardlink verify <file:line> --dry-run`, then run `guardlink verify <file:line>`. Never re-lock a claim you did not read.
19
- 5. List confirmed threats on the changed files: `guardlink hypothesis list --state confirmed --json`, keeping those in the diff.
20
- 6. Replay each one's retest kit against the authorized target from bravos-env: `cxg pentest run --codebase . --target <url> --auth <profile> --template-dir .guardlink/cxg-replay/ --scope-file .guardlink/scope.yaml --attestation "<the human's words>" --session-dir .guardlink/pentest-findings/<run> --ci`. Copy the attestation verbatim from what the human typed; leave the flag off on loopback if they gave none. No kit yet: hand the threat to bravos-templatize first.
21
- 7. Read the result as bravos-prove does. Still confirmed: the fix did not hold; say so. Refuted with the same request: record it with `guardlink hypothesis refute <file:line> --evidence "<request sent and response received>"`, and tell the user the confirmation line in the source is theirs to remove. Killed, refused or not run: nothing was rechecked.
19
+ 5. Use `guardlink hypothesis list --json` to select the affected exposure keys, including retest and previously tested claims whose result expired. Resolve a sidecar declaration against the logical application source in the model. Include affected callers and shared controls even when the route itself did not move.
20
+ 6. Follow bravos-prove with the previously bound kit and original positive control. Check the committed .guardlink/scope.yaml and the effective proving policy. Rebuild or restart the authorized target from the changed code before replay. If no matching kit exists, use bravos-templatize. Replaying with the same test bytes gives a comparable result.
21
+ 7. Confirm the ledger records this run on the intended claim. A previously reproduced exploit that no longer triggers is still pending until the engine supplies conclusive evidence that the control held. Report partial, refused and unrecorded outcomes individually. Preserve the earlier reproduction in history.
22
22
  8. Check the fix added nothing: `guardlink diff <base> --fail-on-new --markdown`, then `guardlink lint . --since <base> --json`, applying each `fix` only to lines this session wrote.
23
23
  9. Re-read the queue with `guardlink hypothesis next --json` and name the next item.
24
24
 
@@ -18,7 +18,7 @@ description: "Write a crisp, evidence-bound white-box VAPT write-up in this sess
18
18
  3. Read `.guardlink/intent.md` (in the bundle as `intent.text`): its Assumptions name the attacker starting positions, the configuration baseline and the scope decisions. Keep the tester's access (source code, admin credentials, the loopback target) apart from what an attacker needs: every finding states the attacker's prerequisites, never the tester's. Then collect what a reader needs to rebuild the test, from the run folders the bundle lists, `.guardlink/proving.md` (target and start command), `.guardlink/scope.yaml` and the session's own history: how the product was built; every config and feature-flag change; how keys and accounts were made and which permission each held; what was seeded; and every helper written to test it (a stub handler, a gRPC client or worker), with how to install and run it. Copy the config files and scripts, never keys or tokens, into the run folder so the report can point at them.
19
19
  4. Consolidate before you write: group exposures that share one root cause into one finding (cite every EXP id it covers); order findings by remediation priority (exposure, asset sensitivity, prerequisites, compensating controls), kept apart from technical severity; build an attack narrative only from steps the evidence links (a run's chained steps, flows in the model, a code-graph call chain), and cite each step.
20
20
  5. Write `.bravos/reports/<id>/report.md` from the template for the kind: `{{SKILL_DIR}}/assessment.md`, `{{SKILL_DIR}}/finding.md`, `{{SKILL_DIR}}/retest.md` or `{{SKILL_DIR}}/brief.md`, in the voice `{{SKILL_DIR}}/style.md` sets. Write for the team that has to act on it: plain words first; what the attacker wants and what they need; why it is a vulnerability; the weaknesses one by one and how they chain step by step; the environment and the roles table; a cxg reproduction (`cargo install cert-x-gen`, the template, the exact `cxg scan` command and its expected output); granular manual steps; what held; and the fix with how to check it. Evidence ids go in the closing Evidence section, not in the prose. When the proof is a script rather than a cxg template, hand it to bravos-templatize to become one, and have bravos-prove replay it under the person's authorization before you quote its output; otherwise say the cxg command was not run.
21
- 6. Give each finding a `**Status:**` line with the bundle's computed level for what it cites, word for word: `reproduced at runtime`, `control held at runtime`, `established by code or configuration review`, or `suspected, awaiting validation`. Repeat it in the Evidence section with the evidence ids in parentheses (the top line may say "see Evidence"). A weaker label than the evidence supports is allowed; a stronger one is not. "Not reproduced" names the conditions tested, from the run's not-run causes.
21
+ 6. Use each candidate’s current evidence level. A stale result describes the earlier build and needs a replay. Scanner-template observations, execution-status rows, ambiguous probes and missing sessions cannot establish a runtime verdict. Cite the native engine finding or positive mitigation evidence for a replay and record skipped, refused and truncated coverage. Give each finding a `**Status:**` line with the bundle's computed level for what it cites, word for word: `reproduced at runtime`, `control held at runtime`, `established by code or configuration review`, or `suspected, awaiting validation`. Repeat it in the Evidence section with the evidence ids in parentheses (the top line may say "see Evidence"). A weaker label than the evidence supports is allowed; a stronger one is not. "Not reproduced" names the conditions tested, from the run's not-run causes.
22
22
  7. Write coverage with its denominator ("cross-tenant reads exercised on 3 of 11 routes"; "83% of files, 1,417 of 1,712"), list the controls that held next to the weaknesses, and keep raw tool output in the appendices. Quote requests and responses from the run evidence with tokens and credentials redacted; the bundle already redacts what it recognises.
23
23
  8. Severity: give the rating and its rationale in this application's context. Use CVSS only when you can state the version and the full vector from facts in the bundle; never a bare score.
24
24
  9. Check: `bravos report check <id>`. Fix every error and rerun until it passes; read the warnings (long paragraphs, vague titles) and fix the ones that would slow a reader down.
@@ -0,0 +1,52 @@
1
+ ---
2
+ name: bravos-resync
3
+ description: "Carry annotation work that never reached the base branch onto it, and keep it true: when the briefing or autopilot says this checkout is far behind its base or lists idle branches with annotation work, or the user moved, rebased or abandoned a branch with annotations on it. Saves uncommitted work first, runs `bravos resync` to copy the sidecars and definitions and reanchor them, maps ids that duplicate the base's, re-reads every carried claim on code that changed since it was written, drops what lost its code, and opens a PR. Use before annotating or proving on a stale checkout, and before running `bravos resync`."
4
+ ---
5
+ # Bravos resync: old annotation work is a lead, not a fact
6
+
7
+ ## When
8
+
9
+ - The briefing says `Branch: … is N commits behind`, or lists `Annotation work not on <base>`.
10
+ - Autopilot says this checkout is behind its base.
11
+ - The user switched, rebased or abandoned a branch that carried annotations, or found old annotation work and asks whether it is still useful.
12
+
13
+ ## Do
14
+
15
+ 1. Find the base: `git symbolic-ref -q --short refs/remotes/origin/HEAD` prints `origin/<base>` (if empty, use `origin/main`). Run `bravos resync --list` to see how far this checkout is behind and which idle branches carry `.guardlink/` work the base lacks. Tell the user what you found in two lines and ask before you move their checkout.
16
+ 2. Make uncommitted work safe before anything else: on the old branch, commit it as it is with a message that says it is unreviewed work in progress (`git add -A` then `git commit -m "wip: unreviewed annotation drafts, kept for bravos resync"`). That commit is the only copy; a stash can be popped by another session, so never stash.
17
+ 3. Start fresh from the base: `git fetch origin`, then `git switch -c resync/<old-branch> origin/<base>` (in a worktree when this checkout is shared with another session).
18
+ 4. Preview: `bravos resync --from <old-branch>`. Read the counts: sidecars to carry, sidecars both sides have, definitions to carry, possible duplicates, and files changed since the claims were written. With inline annotations it copies nothing and says to bring the commits over with `git cherry-pick` or `git merge` instead; do that, then continue at step 7.
19
+ 5. Apply: `bravos resync --from <old-branch> --apply`. It writes the sidecars and a marked block of carried definitions, runs `guardlink reanchor . --apply`, validates, and saves the full lists to `.bravos/resync/last.json`.
20
+ 6. Map each possible duplicate: read both definitions. When they name the same thing, replace the carried id with the base's in the carried sidecars and delete its line from the carried block. When you are not sure, keep both and list the pair for the user.
21
+ 7. Re-read every annotation in each file on the changed-since list against today's code, with bravos-annotate's rules: a claim that no longer says what the code does is corrected, or removed when its code is gone. Do the same for each sidecar on the symbol-gone list. Use the code graph (bravos-codegraph) to find where moved code went.
22
+ 8. For a file both sides annotate (`both` in the report), compare the two sidecars and carry over only the claims the base's lacks, by hand.
23
+ 9. Check the result: `guardlink validate .`, then `guardlink lint . --since origin/<base>` and fix each finding on lines you carried, then `guardlink diff origin/<base>` to list the exposures this brings back.
24
+ 10. Open a PR from the resync branch. The body says which branch and commit the work came from, how many sidecars and definitions were carried, which ids were mapped, how many files were re-read, what was dropped, and every exposure it reopens, each marked unverified.
25
+
26
+ ## Never
27
+
28
+ - Delete, reset or force-push the old branch or its uncommitted work; that is the user's call, after the PR merges.
29
+ - Stash work to move a checkout, or switch a checkout another session is using.
30
+ - Re-lock a carried claim with `guardlink verify` unless you re-read its code in this session.
31
+ - Write `@accepts`, `@entitles` or `@confirmed` for carried work, or keep an old `@confirmed` line without a replay that reproduces it today.
32
+ - Merge two ids because their names look alike; map only what you read and know is the same.
33
+ - Call carried exposures findings: they are claims about older code until re-read and proven.
34
+
35
+ ## Done when
36
+
37
+ - The old work is in a commit on its branch, and the resync branch starts from the current base.
38
+ - Every possible duplicate is mapped or listed for the user.
39
+ - Every changed-since file and every symbol-gone sidecar was re-read, and each claim corrected, kept or removed.
40
+ - `guardlink validate .` reports no errors, and the PR lists what was carried, mapped, dropped and reopened.
41
+
42
+ ## What it leaves for the next skill
43
+
44
+ - Exposures the carried work reopens, for bravos-prove or bravos-templatize to test.
45
+ - Confirmed claims that came with it, for bravos-recheck to replay.
46
+ - Files still without annotations, for bravos-annotate.
47
+
48
+ ## Go deeper
49
+
50
+ - `{{SKILLS_ROOT}}/bravos-annotate/SKILL.md` — the rules for correcting or removing a claim.
51
+ - `{{SKILLS_ROOT}}/bravos-recheck/SKILL.md` — re-verifying claims after code changes.
52
+ - `{{SKILLS_ROOT}}/bravos-codegraph/SKILL.md` — finding where moved code went.
@@ -19,7 +19,7 @@ description: "Set up recurring security upkeep with each harness's own mechanism
19
19
  3. Nightly workflow: run `bravos init --ci` (or `bravos sync --ci` in a repo bravos already set up), keep the variant for the team's harness (`bravos-nightly-claude.yml` or `bravos-nightly-codex.yml`) and delete the other. A team on GitHub Copilot uses `bravos init --workflows nightly-copilot` instead: it opens an issue each night and assigns it to Copilot's cloud agent, which needs the secret `COPILOT_ASSIGN_TOKEN` (a Copilot user's personal access token) and `BRAVOS_LICENCE` as an Agents secret. Tell the user the secret it needs (`CLAUDE_CODE_OAUTH_TOKEN` for Claude Code, made once with `claude setup-token` so the run uses their Claude plan, or `OPENAI_API_KEY` for Codex) and to allow GitHub Actions to create pull requests in the repo settings.
20
20
  4. Cloud scheduled task: a skill cannot create one. Give the user the prompt to paste into `/schedule`: follow bravos-annotate in slice mode on the next unannotated files, run its lint gate, and open one pull request whose body carries bravos-ship's Security gate section. Tell them the task clones the default branch and runs at most hourly.
21
21
  5. State the spend before the user starts any of them: files per run (the default slice is five) times runs per day, and that each run spends model tokens.
22
- 6. Nightly scan, opt-in: it replays the kits in `.guardlink/cxg-replay/` and records outcomes through `guardlink hypothesis confirm --from-scan`, and it runs only when `.guardlink/scope.yaml` is committed with an `authorization_attestation` a human typed and reviewed in a PR, and the repo variable `BRAVOS_SCAN_TARGET` is a loopback URL the job starts (repo variable `BRAVOS_APP_START`) or a host in that scope's `host_allowlist`. Otherwise the step prints why it skipped. Tell the user which variables to set and that the scope file is their standing authorization.
22
+ 6. For the Claude Code and Codex nightlies, select scheduled proving in the committed human policy and review the scope and exact target. Only checked-in, bound JavaScript kits are eligible. Configure BRAVOS_SCAN_TARGET and BRAVOS_APP_START for the disposable local build and the identities each kit requires. Keep session state in CI secrets. A disabled or ask-only policy skips the scan. Report missing prerequisites, partial executions and unrecorded results separately. Copilot schedules annotation only.
23
23
 
24
24
  ## Never
25
25
 
@@ -19,7 +19,7 @@ description: "The no-mistakes security gate before a pull request: validate the
19
19
  3. Run `guardlink lint . --since <base> --json`. This judges every claim on the branch, not only yours. Apply an entry's `fix` only to a line this session wrote, and rerun until `summary.errors` is 0. For `accepts-written`, `entitles-written` or `confirmed-without-evidence` on any other line, do not touch it: stop and report it to the user.
20
20
  4. Run `guardlink diff <base> --fail-on-new --markdown`. Exit 0 means no new unmitigated exposure. A non-zero exit lists new exposures with no `@mitigates`; an `@exposes` plus `@audit` written on this branch is new exposure and stays listed by design. Do not try to turn it green: report each listed exposure as open in the Security gate section and stop there for that exposure. Fixing the code or accepting the risk is the human's decision.
21
21
  5. Run `guardlink paths --json` and report how many undefended source-to-sink paths it lists. This is informational in this version and does not block. In a bravos workspace, also read the cross-service edges (`bravos workspace show --json`, `export.edges`) whose `dstMember` is this service and whose target id is declared in a file this branch changed: report them as "callers in other services" in the Security gate section, so the reviewer checks those callers too.
22
- 6. If the code graph is present, call `codegraph_annotation_gaps` on the changed files and send each gap to bravos-annotate (diff playbook).
22
+ 6. Review the security behavior in the changed hunks, including changes inside already annotated handlers. Check callers, affected guards and source or sidecar locations. If the graph is unavailable or reports incomplete resolution, inspect the changed code with the GuardLink diff playbook and report the gap. If the code graph is present, call `codegraph_annotation_gaps` on the changed files and send each gap to bravos-annotate (diff playbook).
23
23
  7. Run `guardlink ci -f json`. A `confirmed[]` entry whose `location.file` is in `git diff --name-only <base>...HEAD` blocks the PR unless a `@ticket` line written by a human carries it. Check who wrote the `@ticket` line with the MCP tool `guardlink_blame` on the file, or `git log -L <line>,<line>:<file>`, or ask the user. A code change does not clear it: only a human removes the confirmation after a reproduction shows the exploit no longer works. If it blocks, tell the user the threat, asset and file:line, and do not ship.
24
24
  8. Rerun steps 2–4 until validate and lint exit 0, and diff exits 0 or every new exposure it lists is reported as open.
25
25
  9. If the repo has `.guardlink/report.json`, refresh it with `guardlink parse . -o .guardlink/report.json` and include it in the change.
@@ -12,13 +12,13 @@ description: "Turn the threat model's open exposures into correct, testable cxg
12
12
 
13
13
  ## Do
14
14
 
15
- 1. Read the open exposures: `guardlink ci -f json` (`exposures[]`, `confirmed[]`) or the MCP tool `guardlink_lookup` with `unmitigated`. Pick the ones a request or a local invocation can show, and leave pure design or process gaps for an `@audit` note. Read the effort: the user's words ("at high"), else a `bravos effort: <level>` line in `AGENTS.md` / `CLAUDE.md`, else medium. It sets a starting budget, not a limit; go beyond it when the work needs it and say why in one line. Starting budget — low: exposures in changed files; medium: the top 5 from `guardlink hypothesis next --json`; high: the top 20; max: every open exposure.
16
- 2. Get the method, in this order. First open `{{SKILLS_ROOT}}/guardlink-translate/SKILL.md` and follow it (`guardlink sync` writes it; if it is missing, say `guardlink sync` would add it). Else call the MCP tool `guardlink_translate` (server `guardlink`) with `prompt: "<scope>"`; it returns the prompt, its output locations and a separate execution step. Else, from a shell, run `guardlink translate --stdout "<scope>"` only if `guardlink translate --help` lists `--stdout`, and follow the prompt it prints. You are the agent: do the work here. If none of the three is available, tell the user this guardlink offers no way to hand the method to the agent already in session (guardlink PR #98 adds `--stdout` back), and stop. Never fall back to a bare `guardlink translate`: it launches Claude Code.
15
+ 1. Select affected keys from `guardlink hypothesis list --json` or the ranked `guardlink hypothesis next --json`. Include untested exposures with declared controls and previously confirmed claims marked retest. Use the pentest SARIF export to resolve the exact logical source reference. A pure design claim can stay pending with its reason. Read the effort: the user's words ("at high"), else a `bravos effort: <level>` line in `AGENTS.md` / `CLAUDE.md`, else medium. It sets a starting budget, not a limit; go beyond it when the work needs it and say why in one line. Starting budget — low: exposures in changed files; medium: the top 5 from `guardlink hypothesis next --json`; high: the top 20; max: every open exposure.
16
+ 2. Follow the installed `{{SKILLS_ROOT}}/guardlink-translate/SKILL.md`. Request the probe contract for web runtime proof, with the exact threat reference and the known route, roles and intended assertion. Use the guardlink_translate MCP tool or `guardlink translate --stdout --contract probe --threat <threat@file:line>` to obtain instructions for the current agent. With named profiles, supply the per-threat context pack. Use the scanner contract for ordinary scanner observations. If in-session translation is unavailable, run `bravos doctor` and report the missing interface. The active coding agent writes the test.
17
17
  3. Find the request that reaches each sink before you write its template. With the code graph (its MCP tools, or `bravos graph <question> --json` — same answers; see bravos-codegraph) (the briefing's `Code graph:` line says `current`, or `diverged` until a `no-exec` rebuild, bravos-codegraph step 2): `codegraph_call_chain` from the entry points (`codegraph_entry_points`, `codegraph_routes`) to the claim's symbol gives the route or RPC method, its handler and the parameters that flow into the sink; `codegraph_auth_boundary` on that route gives the identity the request needs (anonymous, a signed-in tenant, admin). Target that route with those parameters and the matching auth profile, put the chain (entry → … → sink) in the template's notes, and when several entry points reach the sink template the least privileged first. When `codegraph_entry_reach` says no entry point reaches it at high confidence, write no template: record "unreachable from any entry point per code graph" in the README and hand the claim to bravos-annotate to re-rate. Read `verdict` and `confidence` first; `unknown` or `insufficient_resolution` is not determined, never unreachable. Without the graph, trace the route from the handler by reading the code and say "code graph unavailable; traced by reading". A SAST finding joined to the claim (`bravos sast candidates`) gives its `route`, `entryPoint` and taint path too; use it alongside the graph's chain, and note it in the template. SAST findings not in the threat model go to bravos-annotate first, since templates come from claims. With no SAST report or SAST unavailable, carry on without it.
18
18
  4. Write the templates under `.guardlink/cxg-templates/`, one per threat, following the engine contract and evidence shape the method gives. Keep every check non-destructive and scoped to confirming its one threat. Scanner templates (YAML, Python, shell) go there; JavaScript probes (`async function cxgProbe(cxg)`, `--contract probe`) go under `.guardlink/cxg-replay/` instead, because `cxg scan --template-dir` runs any probe it finds under cxg's default scope, not `.guardlink/scope.yaml`. In a probe, reach the target only through `cxg.fetch*` with well-formed arguments: cxg refuses at run time a probe that uses WebSocket, XMLHttpRequest, EventSource, `navigator.sendBeacon`, dynamic `import()`, or script or `innerHTML` injection, and `cxg template validate` does not catch it.
19
19
  5. Validate: `cxg template validate .guardlink/cxg-templates/ --recursive --json`, and the same for `.guardlink/cxg-replay/`. It exits 1 when any template fails; a banner line can precede the JSON, so read from the first `{` or `[`. Fix each error and rerun until it reports none.
20
20
  6. Record repo context for cxg's own generator. Copy `{{SKILL_DIR}}/operator-guidance.md` to `.guardlink/operator-guidance.md` if it is not there, and fill each section from the code: framework, auth shape, test identities, known false positives, out-of-bounds routes. bravos-prove passes it as `--skills-file` when cxg generates probes for exposures that have no kit.
21
- 7. For a confirmed threat that needs a retest kit, write a hand-written replay probe under `.guardlink/cxg-replay/`, kept apart from the scan templates. It carries `// @attach_scheme: path`, a `// @requires_identities:` line naming every login it needs (both sides of an IDOR; `anonymous` is the reserved no-login role), and no claim-identity stamps, so `--template-dir .guardlink/cxg-replay/` replays it against the same route. Keep that folder JavaScript probes only (a README is fine): one scanner file (`.yaml`, `.py`, `.sh`) there makes cxg refuse the whole replay run before it starts. cxg reads the folder recursively.
21
+ 7. For a first test or regression kit, write a single JavaScript probe in .guardlink/cxg-replay/. Include an exact `// @guardlink_threat: threat@logical/file:line`, `// @attach_scheme: path`, the required identity names, and a precise test with a positive control. Run `bravos hook replay bind <kit.js>` before executing it. The binding command associates the kit with the key of the current GuardLink exposure. Review that mapping when the claim is edited or moved. Leave native CXG identity stamps to the engine.
22
22
  8. Apply the oracle rule: a vulnerability class cxg cannot judge from a response has no oracle. Record it in `.guardlink/cxg-templates/README.md` as unsupported, with the threat id and why, instead of writing a template that pretends to prove it. An invariant threat (`#inv-…`, from intent.md) maps to the cxg class that can judge it: another user's or tenant's data → `idor`; a role or permission gained → `privilege_escalation`; a field the caller should not set → `mass_assignment`; a check bypassed by concurrent requests → `race_condition`; a workflow step skipped or reordered → `business_logic`. Record each invariant's class in the README.
23
23
  9. Commit the templates, the README and the filled guidance together, and hand the template ids and threat ids to bravos-prove.
24
24
 
@@ -1,9 +1,8 @@
1
1
  # bravos:generated — written by `bravos init --ci`; `bravos sync --ci` refreshes it while this line stays.
2
2
  # The nightly "bulk bee": Claude Code covers the next slice of unannotated files with the
3
3
  # bravos-annotate skill, the lint gate checks what it wrote, and the job opens one small PR.
4
- # Optionally it then replays the committed retest kits against the target the reviewed
5
- # .guardlink/scope.yaml authorizes (see the "Authorized scan (gated)" step); without that scope
6
- # file's human-written attestation the scan step skips and the job annotates only.
4
+ # A separate clean runner first replays reviewed kits under a current scheduled grant.
5
+ # The author can then draft new kits in the annotation PR. Review and merge before replay.
7
6
  # The nightly is on the Team plan: add the repo secret BRAVOS_LICENCE (the token from
8
7
  # account.bugb.io/dashboard/license) so the agent's paid skills run; without it they say so and stop.
9
8
  # Claude Code here signs in with your Claude plan, so the run uses that plan like a session would:
@@ -30,7 +29,98 @@ concurrency:
30
29
  cancel-in-progress: false
31
30
 
32
31
  jobs:
32
+ replay:
33
+ # Scheduled evidence comes only from reviewed default-branch code. This fresh runner never runs an authoring agent.
34
+ if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
35
+ runs-on: ubuntu-latest
36
+ timeout-minutes: 90
37
+ permissions:
38
+ contents: read
39
+ outputs:
40
+ drafts: ${{ steps.ready.outputs.drafts }}
41
+ ledger: ${{ steps.scan.outputs.ledger }}
42
+ summary: ${{ steps.scan.outputs.summary }}
43
+ env:
44
+ BRAVOS_DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
45
+ BRAVOS_SCAN_TARGET: ${{ vars.BRAVOS_SCAN_TARGET }}
46
+ steps:
47
+ - uses: actions/checkout@v4
48
+ - uses: actions/setup-node@v4
49
+ with:
50
+ node-version: 22
51
+ - name: Check current scheduled consent
52
+ id: ready
53
+ env:
54
+ BRAVOS_APP_START: ${{ vars.BRAVOS_APP_START }}
55
+ run: |
56
+ echo "drafts=$(node .bravos/hooks/lib/replay.mjs scheduled-drafts)" >> "$GITHUB_OUTPUT"
57
+ if [ -n "$BRAVOS_SCAN_TARGET" ]; then
58
+ python3 -m venv "$RUNNER_TEMP/bravos-python"
59
+ "$RUNNER_TEMP/bravos-python/bin/pip" install "PyYAML==6.0.2"
60
+ export CXG_PYTHON="$RUNNER_TEMP/bravos-python/bin/python"
61
+ echo "CXG_PYTHON=$CXG_PYTHON" >> "$GITHUB_ENV"
62
+ fi
63
+ mode=$(node .bravos/hooks/lib/replay.mjs scheduled-ready)
64
+ echo "mode=$mode" >> "$GITHUB_OUTPUT"
65
+ - uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
66
+ if: steps.ready.outputs.mode != 'disabled'
67
+ with:
68
+ path: ${{ runner.temp }}/bravos-cxg
69
+ # Only this job (no authoring agent) writes the replay key, so a binary another job touched never reaches it.
70
+ key: bravos-cxg-replay-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('.bravos/hooks/lib/proof-tool-pins.json') }}
71
+ - name: Install replay tools
72
+ if: steps.ready.outputs.mode != 'disabled'
73
+ run: bash .bravos/hooks/lib/nightly-tools.sh replay
74
+ - name: Start the reviewed loopback build
75
+ if: steps.ready.outputs.mode == 'loopback'
76
+ env:
77
+ BRAVOS_APP_START: ${{ vars.BRAVOS_APP_START }}
78
+ run: |
79
+ test "$(node .bravos/hooks/lib/replay.mjs scheduled-ready)" = loopback
80
+ node .bravos/hooks/lib/replay.mjs check-port "$BRAVOS_SCAN_TARGET"
81
+ env -i PATH="$PATH" HOME="$HOME" CI=true bash -c "$BRAVOS_APP_START" > "$RUNNER_TEMP/bravos-app.log" 2>&1 &
82
+ for _ in $(seq 1 60); do
83
+ if curl --silent --max-time 2 --output /dev/null "$BRAVOS_SCAN_TARGET"; then
84
+ # Witness the tree once the app is up, so files its start writes into the checkout match at replay.
85
+ node .bravos/hooks/lib/replay.mjs build "$BRAVOS_SCAN_TARGET" > "$RUNNER_TEMP/bravos-build.json"
86
+ exit 0
87
+ fi
88
+ sleep 2
89
+ done
90
+ exit 1
91
+ - name: Replay reviewed kits
92
+ id: scan
93
+ env:
94
+ MODE: ${{ steps.ready.outputs.mode }}
95
+ BRAVOS_SCAN_AUTH: ${{ vars.BRAVOS_SCAN_AUTH }}
96
+ BRAVOS_AUTH_STATE: ${{ secrets.BRAVOS_AUTH_STATE }}
97
+ BRAVOS_AUTH_STATES: ${{ secrets.BRAVOS_AUTH_STATES }}
98
+ run: |
99
+ if [ "$MODE" = disabled ]; then
100
+ echo "summary=Scheduled proof skipped. See the consent check." >> "$GITHUB_OUTPUT"
101
+ exit 0
102
+ fi
103
+ if [ "$MODE" = loopback ]; then
104
+ BRAVOS_REPLAY_BUILD=$(cat "$RUNNER_TEMP/bravos-build.json")
105
+ export BRAVOS_REPLAY_BUILD
106
+ fi
107
+ result=0
108
+ node .bravos/hooks/lib/replay.mjs scheduled || result=$?
109
+ if [ -f .guardlink/hypotheses.json ] && [ -n "$(git status --porcelain -- .guardlink/hypotheses.json)" ]; then
110
+ mkdir -p "$RUNNER_TEMP/bravos-verified-ledger"
111
+ cp .guardlink/hypotheses.json "$RUNNER_TEMP/bravos-verified-ledger/hypotheses.json"
112
+ echo "ledger=yes" >> "$GITHUB_OUTPUT"
113
+ fi
114
+ exit "$result"
115
+ - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
116
+ if: always() && steps.scan.outputs.ledger == 'yes'
117
+ with:
118
+ name: bravos-replay-ledger
119
+ path: ${{ runner.temp }}/bravos-verified-ledger/hypotheses.json
120
+ retention-days: 1
33
121
  annotate:
122
+ needs: replay
123
+ if: always() && !cancelled() && github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
34
124
  runs-on: ubuntu-latest
35
125
  env:
36
126
  BRAVOS_LICENCE: ${{ secrets.BRAVOS_LICENCE }}
@@ -47,8 +137,18 @@ jobs:
47
137
  with:
48
138
  node-version: 22
49
139
 
50
- - name: Install guardlink
51
- run: npm install -g guardlink
140
+ - name: Install annotation tools
141
+ if: needs.replay.outputs.drafts != 'yes'
142
+ run: bash .bravos/hooks/lib/nightly-tools.sh annotate
143
+ - uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
144
+ if: needs.replay.outputs.drafts == 'yes'
145
+ with:
146
+ path: ${{ runner.temp }}/bravos-cxg
147
+ # The authoring job's own key: whatever its agent leaves here is never restored by the replay job.
148
+ key: bravos-cxg-author-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('.bravos/hooks/lib/proof-tool-pins.json') }}
149
+ - name: Install in-session translation and probe validation
150
+ if: needs.replay.outputs.drafts == 'yes'
151
+ run: bash .bravos/hooks/lib/nightly-tools.sh author
52
152
 
53
153
  - name: Starting point
54
154
  id: start
@@ -68,8 +168,13 @@ jobs:
68
168
  the work in this session and never run guardlink annotate with an agent flag. Stop when
69
169
  `guardlink lint . --since ${{ steps.start.outputs.sha }} --json` reports 0 errors and
70
170
  `guardlink validate .` passes. Leave the changes uncommitted; a later step commits them
71
- and opens the pull request.
72
- claude_args: --allowedTools "Read,Edit,Write,Glob,Grep,Bash(guardlink:*),Bash(node:*),Bash(git status:*),Bash(git diff:*),Bash(git log:*),Bash(git rev-parse:*),Bash(git symbolic-ref:*)"
171
+ and opens the pull request. Draft kits this run: ${{ needs.replay.outputs.drafts }}.
172
+ Only when yes, for each newly testable exposure use the GuardLink translate method
173
+ in this session to author or update one scoped JavaScript probe under .guardlink/cxg-replay/,
174
+ validate it with the installed CXG validator and run the Bravos replay bind helper on that kit.
175
+ Also repair existing kits with missing or stale bindings after verifying their behaviour and source.
176
+ Do not start a target or run a probe. The separate replay job uses reviewed kits after merge.
177
+ claude_args: --allowedTools "Read,Edit,Write,Glob,Grep,Bash(guardlink:*),Bash(cxg template validate:*),Bash(node:*),Bash(git status:*),Bash(git diff:*),Bash(git log:*),Bash(git rev-parse:*),Bash(git symbolic-ref:*)"
73
178
 
74
179
  - name: Gate what the agent wrote
75
180
  env:
@@ -84,71 +189,26 @@ jobs:
84
189
  exit 1
85
190
  fi
86
191
 
87
- # Opt-in: replays the committed retest kits against the target the reviewed scope authorizes.
88
- # It runs only when .guardlink/scope.yaml carries a human-written authorization_attestation and
89
- # vars.BRAVOS_SCAN_TARGET is loopback (started by vars.BRAVOS_APP_START) or in the scope's
90
- # host_allowlist. It replays kits only: no probe generation and no destructive classes.
91
- - name: Authorized scan (gated)
92
- id: scan
93
- env:
94
- TARGET: ${{ vars.BRAVOS_SCAN_TARGET }}
95
- APP_START: ${{ vars.BRAVOS_APP_START }}
96
- AUTH_PROFILE: ${{ vars.BRAVOS_SCAN_AUTH }}
97
- AUTH_STATE: ${{ secrets.BRAVOS_AUTH_STATE }}
98
- run: |
99
- skip() { echo "::notice::nightly scan skipped: $1"; echo "ran=false" >> "$GITHUB_OUTPUT"; exit 0; }
100
- scope=.guardlink/scope.yaml
101
- [ -n "$TARGET" ] || skip "vars.BRAVOS_SCAN_TARGET is not set"
102
- [ -f "$scope" ] || skip "$scope is not committed"
103
- attest=$(sed -n 's/^authorization_attestation:[[:space:]]*//p' "$scope" | sed 's/^"\(.*\)"$/\1/')
104
- [ -n "$attest" ] || skip "$scope has no authorization_attestation; a human must write it and get it reviewed"
105
- ls .guardlink/cxg-replay/*.js >/dev/null 2>&1 || skip "no retest kits in .guardlink/cxg-replay/"
106
- host=$(printf '%s' "$TARGET" | sed -E 's#^[a-z]+://##; s#[:/].*$##')
107
- case "$host" in
108
- 127.0.0.1|localhost|::1|'[::1]') loopback=yes ;;
109
- *) loopback=no ;;
110
- esac
111
- if [ "$loopback" = no ] && ! grep -qF "$host" <(sed -n '/^host_allowlist:/,/^[a-z_]*:/p' "$scope"); then
112
- skip "$host is neither loopback nor in the scope's host_allowlist"
113
- fi
114
- if [ "$loopback" = yes ]; then
115
- [ -n "$APP_START" ] || skip "a loopback target needs vars.BRAVOS_APP_START to start the app"
116
- bash -c "$APP_START"
117
- for i in $(seq 1 60); do curl -fsS -o /dev/null "$TARGET" && break; sleep 2; done
118
- fi
119
- cargo install --locked cert-x-gen
120
- cxg pentest install
121
- auth=()
122
- if [ -n "$AUTH_PROFILE" ]; then
123
- [ -n "$AUTH_STATE" ] || skip "vars.BRAVOS_SCAN_AUTH is set but secrets.BRAVOS_AUTH_STATE is empty"
124
- printf '%s' "$AUTH_STATE" | base64 -d > "$RUNNER_TEMP/state.json"
125
- cxg pentest auth import --storage-state "$RUNNER_TEMP/state.json" --profile "$AUTH_PROFILE" --target "$TARGET"
126
- auth=(--auth "$AUTH_PROFILE")
127
- fi
128
- guardlink sarif . --profile pentest -o whitebox/findings.sarif
129
- run=".guardlink/pentest-findings/nightly-$(date -u +%Y%m%d)"
130
- set +e
131
- cxg pentest run --codebase . --target "$TARGET" "${auth[@]}" --template-dir .guardlink/cxg-replay/ --scope-file "$scope" --attestation "$attest" --session-dir "$run" --ci
132
- code=$?
133
- set -e
134
- echo "exit=$code" >> "$GITHUB_OUTPUT"
135
- case "$code" in
136
- 0|2) guardlink hypothesis confirm --from-scan "$run/report.json" --write || true
137
- echo "ran=true" >> "$GITHUB_OUTPUT" ;;
138
- *) echo "::warning::cxg pentest run exited $code: nothing was proven"; echo "ran=false" >> "$GITHUB_OUTPUT" ;;
139
- esac
192
+ - name: Collect verified replay ledger
193
+ if: needs.replay.outputs.ledger == 'yes'
194
+ uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
195
+ with:
196
+ name: bravos-replay-ledger
197
+ path: ${{ runner.temp }}/bravos-verified-ledger
140
198
 
141
199
  - name: Open the pull request
142
200
  env:
143
- SCAN_RAN: ${{ steps.scan.outputs.ran }}
144
- SCAN_EXIT: ${{ steps.scan.outputs.exit }}
145
- SCAN_TARGET: ${{ vars.BRAVOS_SCAN_TARGET }}
201
+ LEDGER: ${{ needs.replay.outputs.ledger }}
202
+ PROOF_SUMMARY: ${{ needs.replay.outputs.summary || 'No completed replay summary. Check the replay job.' }}
146
203
  GH_TOKEN: ${{ github.token }}
147
204
  START: ${{ steps.start.outputs.sha }}
148
205
  BEFORE: ${{ steps.start.outputs.coverage }}
149
206
  run: |
150
- if [ -z "$(git status --porcelain)" ]; then
151
- echo "Nothing new to annotate."
207
+ # Load the staging helper and verified ledger from trusted inputs after the agent exits.
208
+ git show "$START:.bravos/hooks/lib/nightly-stage.mjs" > "$RUNNER_TEMP/nightly-stage.mjs"
209
+ node "$RUNNER_TEMP/nightly-stage.mjs"
210
+ if git diff --cached --quiet; then
211
+ echo "No reviewable changes."
152
212
  exit 0
153
213
  fi
154
214
  guardlink ci -f json > "$RUNNER_TEMP/ci-after.json" || true
@@ -157,20 +217,17 @@ jobs:
157
217
  branch="bravos/nightly-$(date -u +%Y%m%d-%H%M)"
158
218
  git config user.name "bravos-nightly[bot]"
159
219
  git config user.email "bravos-nightly@users.noreply.github.com"
160
- git switch -c "$branch"
161
- git add -A
162
- git commit -m "annotate: nightly coverage slice (${BEFORE}% -> ${after}%)"
163
- git push origin "$branch"
220
+ test "$(git rev-parse HEAD)" = "$START"
221
+ test "$(git ls-remote --exit-code origin "refs/heads/$base" | cut -f1)" = "$START"
222
+ tree=$(git write-tree)
223
+ commit=$(git commit-tree "$tree" -p "$START" -m "annotate: nightly coverage slice (${BEFORE}% -> ${after}%)")
224
+ git -c core.hooksPath=/dev/null push origin "$commit:refs/heads/$branch"
164
225
  {
165
226
  echo "Nightly coverage slice by bravos-annotate: ${BEFORE}% -> ${after}%."
166
227
  echo
167
228
  echo "## Security gate"
168
229
  echo "validate ✔ · lint 0 errors · exposures recorded by this slice are listed below and stay open"
169
- if [ "$SCAN_RAN" = "true" ]; then
170
- echo "Tested: retest kits replayed against $SCAN_TARGET (exit code $SCAN_EXIT); outcomes recorded in .guardlink/hypotheses.json."
171
- else
172
- echo "Not tested: the gated scan did not run (see the job's notices)."
173
- fi
230
+ echo "$PROOF_SUMMARY"
174
231
  echo
175
232
  guardlink diff "$START" --markdown || true
176
233
  } > "$RUNNER_TEMP/body.md"