@bugb-technologies/bravos 1.3.0 → 1.4.1

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 (42) hide show
  1. package/README.md +17 -10
  2. package/dist/ci.js +11 -3
  3. package/dist/cli.js +16 -6
  4. package/dist/doctor.js +2 -2
  5. package/dist/guide.js +2 -2
  6. package/dist/help.js +10 -14
  7. package/dist/install-proof-tool.js +117 -0
  8. package/dist/proof-tools.js +29 -0
  9. package/dist/report/check.js +4 -1
  10. package/dist/report/data.js +81 -149
  11. package/dist/report/markdown.js +1 -1
  12. package/dist/report/redact.js +16 -0
  13. package/dist/report/runs.js +169 -0
  14. package/dist/setup.js +43 -19
  15. package/dist/start/answers.js +5 -3
  16. package/dist/start/index.js +28 -14
  17. package/dist/versions.js +5 -4
  18. package/docs/GUIDE.md +2 -2
  19. package/hooks/lib/autopilot.mjs +155 -37
  20. package/hooks/lib/briefing.mjs +9 -3
  21. package/hooks/lib/nightly-stage.mjs +66 -0
  22. package/hooks/lib/nightly-tools.sh +45 -0
  23. package/hooks/lib/pre-pr.mjs +88 -17
  24. package/hooks/lib/proof-tool-pins.json +12 -0
  25. package/hooks/lib/replay.mjs +579 -0
  26. package/hooks/lib/setup.mjs +15 -6
  27. package/hooks/lib/snapshot.mjs +75 -9
  28. package/package.json +1 -1
  29. package/skills/bravos/SKILL.md +1 -1
  30. package/skills/bravos-annotate/SKILL.md +6 -5
  31. package/skills/bravos-annotate/scripts/slice.mjs +15 -8
  32. package/skills/bravos-cicd/SKILL.md +1 -1
  33. package/skills/bravos-env/SKILL.md +3 -3
  34. package/skills/bravos-prove/SKILL.md +11 -15
  35. package/skills/bravos-recheck/SKILL.md +3 -3
  36. package/skills/bravos-report/SKILL.md +1 -1
  37. package/skills/bravos-schedule/SKILL.md +1 -1
  38. package/skills/bravos-ship/SKILL.md +1 -1
  39. package/skills/bravos-templatize/SKILL.md +3 -3
  40. package/templates/workflows/bravos-nightly-claude.yml +131 -74
  41. package/templates/workflows/bravos-nightly-codex.yml +130 -73
  42. package/templates/workflows/bravos-pr-gate.yml +88 -14
@@ -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"
@@ -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": Codex 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
  # Needs the repo secret OPENAI_API_KEY, and Settings > Actions > General > "Allow GitHub
@@ -25,7 +24,98 @@ concurrency:
25
24
  cancel-in-progress: false
26
25
 
27
26
  jobs:
27
+ replay:
28
+ # Scheduled evidence comes only from reviewed default-branch code. This fresh runner never runs an authoring agent.
29
+ if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
30
+ runs-on: ubuntu-latest
31
+ timeout-minutes: 90
32
+ permissions:
33
+ contents: read
34
+ outputs:
35
+ drafts: ${{ steps.ready.outputs.drafts }}
36
+ ledger: ${{ steps.scan.outputs.ledger }}
37
+ summary: ${{ steps.scan.outputs.summary }}
38
+ env:
39
+ BRAVOS_DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
40
+ BRAVOS_SCAN_TARGET: ${{ vars.BRAVOS_SCAN_TARGET }}
41
+ steps:
42
+ - uses: actions/checkout@v4
43
+ - uses: actions/setup-node@v4
44
+ with:
45
+ node-version: 22
46
+ - name: Check current scheduled consent
47
+ id: ready
48
+ env:
49
+ BRAVOS_APP_START: ${{ vars.BRAVOS_APP_START }}
50
+ run: |
51
+ echo "drafts=$(node .bravos/hooks/lib/replay.mjs scheduled-drafts)" >> "$GITHUB_OUTPUT"
52
+ if [ -n "$BRAVOS_SCAN_TARGET" ]; then
53
+ python3 -m venv "$RUNNER_TEMP/bravos-python"
54
+ "$RUNNER_TEMP/bravos-python/bin/pip" install "PyYAML==6.0.2"
55
+ export CXG_PYTHON="$RUNNER_TEMP/bravos-python/bin/python"
56
+ echo "CXG_PYTHON=$CXG_PYTHON" >> "$GITHUB_ENV"
57
+ fi
58
+ mode=$(node .bravos/hooks/lib/replay.mjs scheduled-ready)
59
+ echo "mode=$mode" >> "$GITHUB_OUTPUT"
60
+ - uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
61
+ if: steps.ready.outputs.mode != 'disabled'
62
+ with:
63
+ path: ${{ runner.temp }}/bravos-cxg
64
+ # Only this job (no authoring agent) writes the replay key, so a binary another job touched never reaches it.
65
+ key: bravos-cxg-replay-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('.bravos/hooks/lib/proof-tool-pins.json') }}
66
+ - name: Install replay tools
67
+ if: steps.ready.outputs.mode != 'disabled'
68
+ run: bash .bravos/hooks/lib/nightly-tools.sh replay
69
+ - name: Start the reviewed loopback build
70
+ if: steps.ready.outputs.mode == 'loopback'
71
+ env:
72
+ BRAVOS_APP_START: ${{ vars.BRAVOS_APP_START }}
73
+ run: |
74
+ test "$(node .bravos/hooks/lib/replay.mjs scheduled-ready)" = loopback
75
+ node .bravos/hooks/lib/replay.mjs check-port "$BRAVOS_SCAN_TARGET"
76
+ env -i PATH="$PATH" HOME="$HOME" CI=true bash -c "$BRAVOS_APP_START" > "$RUNNER_TEMP/bravos-app.log" 2>&1 &
77
+ for _ in $(seq 1 60); do
78
+ if curl --silent --max-time 2 --output /dev/null "$BRAVOS_SCAN_TARGET"; then
79
+ # Witness the tree once the app is up, so files its start writes into the checkout match at replay.
80
+ node .bravos/hooks/lib/replay.mjs build "$BRAVOS_SCAN_TARGET" > "$RUNNER_TEMP/bravos-build.json"
81
+ exit 0
82
+ fi
83
+ sleep 2
84
+ done
85
+ exit 1
86
+ - name: Replay reviewed kits
87
+ id: scan
88
+ env:
89
+ MODE: ${{ steps.ready.outputs.mode }}
90
+ BRAVOS_SCAN_AUTH: ${{ vars.BRAVOS_SCAN_AUTH }}
91
+ BRAVOS_AUTH_STATE: ${{ secrets.BRAVOS_AUTH_STATE }}
92
+ BRAVOS_AUTH_STATES: ${{ secrets.BRAVOS_AUTH_STATES }}
93
+ run: |
94
+ if [ "$MODE" = disabled ]; then
95
+ echo "summary=Scheduled proof skipped. See the consent check." >> "$GITHUB_OUTPUT"
96
+ exit 0
97
+ fi
98
+ if [ "$MODE" = loopback ]; then
99
+ BRAVOS_REPLAY_BUILD=$(cat "$RUNNER_TEMP/bravos-build.json")
100
+ export BRAVOS_REPLAY_BUILD
101
+ fi
102
+ result=0
103
+ node .bravos/hooks/lib/replay.mjs scheduled || result=$?
104
+ if [ -f .guardlink/hypotheses.json ] && [ -n "$(git status --porcelain -- .guardlink/hypotheses.json)" ]; then
105
+ mkdir -p "$RUNNER_TEMP/bravos-verified-ledger"
106
+ cp .guardlink/hypotheses.json "$RUNNER_TEMP/bravos-verified-ledger/hypotheses.json"
107
+ echo "ledger=yes" >> "$GITHUB_OUTPUT"
108
+ fi
109
+ exit "$result"
110
+ - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
111
+ if: always() && steps.scan.outputs.ledger == 'yes'
112
+ with:
113
+ name: bravos-replay-ledger
114
+ path: ${{ runner.temp }}/bravos-verified-ledger/hypotheses.json
115
+ retention-days: 1
28
116
  annotate:
117
+ needs: replay
118
+ if: always() && !cancelled() && github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
29
119
  runs-on: ubuntu-latest
30
120
  env:
31
121
  BRAVOS_LICENCE: ${{ secrets.BRAVOS_LICENCE }}
@@ -42,8 +132,18 @@ jobs:
42
132
  with:
43
133
  node-version: 22
44
134
 
45
- - name: Install guardlink
46
- run: npm install -g guardlink
135
+ - name: Install annotation tools
136
+ if: needs.replay.outputs.drafts != 'yes'
137
+ run: bash .bravos/hooks/lib/nightly-tools.sh annotate
138
+ - uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
139
+ if: needs.replay.outputs.drafts == 'yes'
140
+ with:
141
+ path: ${{ runner.temp }}/bravos-cxg
142
+ # The authoring job's own key: whatever its agent leaves here is never restored by the replay job.
143
+ key: bravos-cxg-author-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('.bravos/hooks/lib/proof-tool-pins.json') }}
144
+ - name: Install in-session translation and probe validation
145
+ if: needs.replay.outputs.drafts == 'yes'
146
+ run: bash .bravos/hooks/lib/nightly-tools.sh author
47
147
 
48
148
  - name: Starting point
49
149
  id: start
@@ -64,7 +164,12 @@ jobs:
64
164
  the work in this session and never run guardlink annotate with an agent flag. Stop when
65
165
  `guardlink lint . --since ${{ steps.start.outputs.sha }} --json` reports 0 errors and
66
166
  `guardlink validate .` passes. Leave the changes uncommitted; a later step commits them
67
- and opens the pull request.
167
+ and opens the pull request. Draft kits this run: ${{ needs.replay.outputs.drafts }}.
168
+ Only when yes, for each newly testable exposure use the GuardLink translate method
169
+ in this session to author or update one scoped JavaScript probe under .guardlink/cxg-replay/,
170
+ validate it with the installed CXG validator and run the Bravos replay bind helper on that kit.
171
+ Also repair existing kits with missing or stale bindings after verifying their behaviour and source.
172
+ Do not start a target or run a probe. The separate replay job uses reviewed kits after merge.
68
173
 
69
174
  - name: Gate what the agent wrote
70
175
  env:
@@ -79,71 +184,26 @@ jobs:
79
184
  exit 1
80
185
  fi
81
186
 
82
- # Opt-in: replays the committed retest kits against the target the reviewed scope authorizes.
83
- # It runs only when .guardlink/scope.yaml carries a human-written authorization_attestation and
84
- # vars.BRAVOS_SCAN_TARGET is loopback (started by vars.BRAVOS_APP_START) or in the scope's
85
- # host_allowlist. It replays kits only: no probe generation and no destructive classes.
86
- - name: Authorized scan (gated)
87
- id: scan
88
- env:
89
- TARGET: ${{ vars.BRAVOS_SCAN_TARGET }}
90
- APP_START: ${{ vars.BRAVOS_APP_START }}
91
- AUTH_PROFILE: ${{ vars.BRAVOS_SCAN_AUTH }}
92
- AUTH_STATE: ${{ secrets.BRAVOS_AUTH_STATE }}
93
- run: |
94
- skip() { echo "::notice::nightly scan skipped: $1"; echo "ran=false" >> "$GITHUB_OUTPUT"; exit 0; }
95
- scope=.guardlink/scope.yaml
96
- [ -n "$TARGET" ] || skip "vars.BRAVOS_SCAN_TARGET is not set"
97
- [ -f "$scope" ] || skip "$scope is not committed"
98
- attest=$(sed -n 's/^authorization_attestation:[[:space:]]*//p' "$scope" | sed 's/^"\(.*\)"$/\1/')
99
- [ -n "$attest" ] || skip "$scope has no authorization_attestation; a human must write it and get it reviewed"
100
- ls .guardlink/cxg-replay/*.js >/dev/null 2>&1 || skip "no retest kits in .guardlink/cxg-replay/"
101
- host=$(printf '%s' "$TARGET" | sed -E 's#^[a-z]+://##; s#[:/].*$##')
102
- case "$host" in
103
- 127.0.0.1|localhost|::1|'[::1]') loopback=yes ;;
104
- *) loopback=no ;;
105
- esac
106
- if [ "$loopback" = no ] && ! grep -qF "$host" <(sed -n '/^host_allowlist:/,/^[a-z_]*:/p' "$scope"); then
107
- skip "$host is neither loopback nor in the scope's host_allowlist"
108
- fi
109
- if [ "$loopback" = yes ]; then
110
- [ -n "$APP_START" ] || skip "a loopback target needs vars.BRAVOS_APP_START to start the app"
111
- bash -c "$APP_START"
112
- for i in $(seq 1 60); do curl -fsS -o /dev/null "$TARGET" && break; sleep 2; done
113
- fi
114
- cargo install --locked cert-x-gen
115
- cxg pentest install
116
- auth=()
117
- if [ -n "$AUTH_PROFILE" ]; then
118
- [ -n "$AUTH_STATE" ] || skip "vars.BRAVOS_SCAN_AUTH is set but secrets.BRAVOS_AUTH_STATE is empty"
119
- printf '%s' "$AUTH_STATE" | base64 -d > "$RUNNER_TEMP/state.json"
120
- cxg pentest auth import --storage-state "$RUNNER_TEMP/state.json" --profile "$AUTH_PROFILE" --target "$TARGET"
121
- auth=(--auth "$AUTH_PROFILE")
122
- fi
123
- guardlink sarif . --profile pentest -o whitebox/findings.sarif
124
- run=".guardlink/pentest-findings/nightly-$(date -u +%Y%m%d)"
125
- set +e
126
- cxg pentest run --codebase . --target "$TARGET" "${auth[@]}" --template-dir .guardlink/cxg-replay/ --scope-file "$scope" --attestation "$attest" --session-dir "$run" --ci
127
- code=$?
128
- set -e
129
- echo "exit=$code" >> "$GITHUB_OUTPUT"
130
- case "$code" in
131
- 0|2) guardlink hypothesis confirm --from-scan "$run/report.json" --write || true
132
- echo "ran=true" >> "$GITHUB_OUTPUT" ;;
133
- *) echo "::warning::cxg pentest run exited $code: nothing was proven"; echo "ran=false" >> "$GITHUB_OUTPUT" ;;
134
- esac
187
+ - name: Collect verified replay ledger
188
+ if: needs.replay.outputs.ledger == 'yes'
189
+ uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
190
+ with:
191
+ name: bravos-replay-ledger
192
+ path: ${{ runner.temp }}/bravos-verified-ledger
135
193
 
136
194
  - name: Open the pull request
137
195
  env:
138
- SCAN_RAN: ${{ steps.scan.outputs.ran }}
139
- SCAN_EXIT: ${{ steps.scan.outputs.exit }}
140
- SCAN_TARGET: ${{ vars.BRAVOS_SCAN_TARGET }}
196
+ LEDGER: ${{ needs.replay.outputs.ledger }}
197
+ PROOF_SUMMARY: ${{ needs.replay.outputs.summary || 'No completed replay summary. Check the replay job.' }}
141
198
  GH_TOKEN: ${{ github.token }}
142
199
  START: ${{ steps.start.outputs.sha }}
143
200
  BEFORE: ${{ steps.start.outputs.coverage }}
144
201
  run: |
145
- if [ -z "$(git status --porcelain)" ]; then
146
- echo "Nothing new to annotate."
202
+ # Load the staging helper and verified ledger from trusted inputs after the agent exits.
203
+ git show "$START:.bravos/hooks/lib/nightly-stage.mjs" > "$RUNNER_TEMP/nightly-stage.mjs"
204
+ node "$RUNNER_TEMP/nightly-stage.mjs"
205
+ if git diff --cached --quiet; then
206
+ echo "No reviewable changes."
147
207
  exit 0
148
208
  fi
149
209
  guardlink ci -f json > "$RUNNER_TEMP/ci-after.json" || true
@@ -152,20 +212,17 @@ jobs:
152
212
  branch="bravos/nightly-$(date -u +%Y%m%d-%H%M)"
153
213
  git config user.name "bravos-nightly[bot]"
154
214
  git config user.email "bravos-nightly@users.noreply.github.com"
155
- git switch -c "$branch"
156
- git add -A
157
- git commit -m "annotate: nightly coverage slice (${BEFORE}% -> ${after}%)"
158
- git push origin "$branch"
215
+ test "$(git rev-parse HEAD)" = "$START"
216
+ test "$(git ls-remote --exit-code origin "refs/heads/$base" | cut -f1)" = "$START"
217
+ tree=$(git write-tree)
218
+ commit=$(git commit-tree "$tree" -p "$START" -m "annotate: nightly coverage slice (${BEFORE}% -> ${after}%)")
219
+ git -c core.hooksPath=/dev/null push origin "$commit:refs/heads/$branch"
159
220
  {
160
221
  echo "Nightly coverage slice by bravos-annotate: ${BEFORE}% -> ${after}%."
161
222
  echo
162
223
  echo "## Security gate"
163
224
  echo "validate ✔ · lint 0 errors · exposures recorded by this slice are listed below and stay open"
164
- if [ "$SCAN_RAN" = "true" ]; then
165
- echo "Tested: retest kits replayed against $SCAN_TARGET (exit code $SCAN_EXIT); outcomes recorded in .guardlink/hypotheses.json."
166
- else
167
- echo "Not tested: the gated scan did not run (see the job's notices)."
168
- fi
225
+ echo "$PROOF_SUMMARY"
169
226
  echo
170
227
  guardlink diff "$START" --markdown || true
171
228
  } > "$RUNNER_TEMP/body.md"
@@ -41,7 +41,7 @@ jobs:
41
41
  BASE_REF: ${{ github.base_ref }}
42
42
  run: echo "sha=$(git merge-base HEAD "origin/$BASE_REF")" >> "$GITHUB_OUTPUT"
43
43
 
44
- # Whole-token id matching shared by the disclosure and @ticket checks: `#api` is not `#api-key`.
44
+ # Whole-token id matching for PR-body disclosures: `#api` is not `#api-key`.
45
45
  - name: jq helpers
46
46
  run: |
47
47
  cat > "$RUNNER_TEMP/named.jq" <<'EOF'
@@ -109,23 +109,97 @@ jobs:
109
109
  echo "::error::unknown: guardlink ci -f json did not produce guardlink.ci JSON with confirmed[]"
110
110
  exit 1
111
111
  fi
112
- git diff --name-only "$BASE_SHA"...HEAD > changed.txt
113
- jq -r '.confirmed[] | [.location.file, (.location.line | tostring), .threat, .asset, (.severity // "unrated")] | @tsv' ci.json > confirmed.tsv
114
- hits=""
115
- while IFS=$'\t' read -r file line threat asset severity; do
116
- grep -qxF -- "$file" changed.txt || continue
117
- if [ -f "$file" ] && jq -Rne -L "$RUNNER_TEMP" --arg t "$threat" --arg a "$asset" 'include "named";
118
- [inputs | select(contains("@ticket") and named(.; $t) and named(.; $a))] | length > 0' < "$file" > /dev/null; then
119
- continue
112
+ git diff --name-only -z "$BASE_SHA"...HEAD | jq -Rs 'split("\u0000")' > "$RUNNER_TEMP/bravos-changed.json"
113
+ ledger_claims="$RUNNER_TEMP/bravos-ledger-claims.json"
114
+ echo '[]' > "$ledger_claims"
115
+ if [[ -e .guardlink/hypotheses.json ]]; then
116
+ guardlink hypothesis list --json > "$RUNNER_TEMP/bravos-ledger.json"
117
+ jq -e '.ledger == "present" and (.records | type == "array")' "$RUNNER_TEMP/bravos-ledger.json" >/dev/null || {
118
+ echo "::error::unknown: GuardLink hypothesis ledger unreadable"; exit 1;
119
+ }
120
+ jq '[.records[] | select((.state == "confirmed" or .state == "retest") and .outcome.outcome == "confirmed")]' \
121
+ "$RUNNER_TEMP/bravos-ledger.json" > "$RUNNER_TEMP/bravos-tested.json"
122
+ if jq -e 'length>0' "$RUNNER_TEMP/bravos-tested.json" >/dev/null; then
123
+ guardlink parse . > "$RUNNER_TEMP/bravos-model.json"
124
+ jq --slurpfile tested "$RUNNER_TEMP/bravos-tested.json" '
125
+ .exposures as $model | [$tested[0][] as $r | [$model[] |
126
+ select(.asset == $r.asset and .threat == $r.threat and
127
+ (.location.origin_file // .location.file) == $r.file and (.location.origin_line // .location.line) == $r.line)] |
128
+ if length != 1 or ($r.key | type) != "string" then error("unresolved tested claim")
129
+ else .[0] + {status: (if $r.expired or $r.state == "retest" then "retest due on changed code"
130
+ elif $r.outcome.source.kind == "scan" and $r.outcome.source.joined_by != "claim-key" then "scan association needs review"
131
+ else "confirmed in ledger" end)} end]
132
+ ' "$RUNNER_TEMP/bravos-model.json" > "$ledger_claims"
120
133
  fi
121
- hits+="$severity $threat on $asset — $file:$line"$'\n'
122
- done < confirmed.tsv
123
- if [ -n "$hits" ]; then
124
- echo "::error::Confirmed-exploitable claims on changed files, with no @ticket for them in that file:"
125
- printf '%s' "$hits"
134
+ fi
135
+ jq --slurpfile changed "$RUNNER_TEMP/bravos-changed.json" --slurpfile ledger "$ledger_claims" '
136
+ [(.confirmed + $ledger[0])[] | . as $c | select(any($changed[0][]; . != "" and (. == $c.location.file or . == $c.location.origin_file)))] as $rows |
137
+ [$rows[] | . as $c | select(.status != null or (any($rows[]; .status != null and
138
+ .location.file == $c.location.file and .asset == $c.asset and .threat == $c.threat and
139
+ (.location.line == $c.location.line or (.location.anchor.scope == "symbol" and $c.location.anchor.scope == "symbol" and
140
+ .location.anchor.start_line == $c.location.anchor.start_line and .location.anchor.hash == $c.location.anchor.hash))) | not))]
141
+ ' ci.json > "$RUNNER_TEMP/bravos-affected.json"
142
+ if ! jq -e 'length > 0' "$RUNNER_TEMP/bravos-affected.json" > /dev/null; then exit 0; fi
143
+ if ! guardlink lookup tickets > "$RUNNER_TEMP/bravos-tickets.json" ||
144
+ ! jq -e '.type == "tickets" and (.results | type == "array")' "$RUNNER_TEMP/bravos-tickets.json" > /dev/null; then
145
+ echo "::error::unknown: guardlink lookup tickets failed or returned no ticket list"
146
+ exit 1
147
+ fi
148
+ jq --slurpfile t "$RUNNER_TEMP/bravos-tickets.json" '
149
+ map(. as $c | . + {ticketed: any($t[0].results[];
150
+ .file == $c.location.file and .threat == $c.threat and .asset == $c.asset and
151
+ (.ref | strings | test("\\S")))})
152
+ ' "$RUNNER_TEMP/bravos-affected.json" > "$RUNNER_TEMP/bravos-classified.json"
153
+ jq -r '.[] | select(.ticketed and .status) |
154
+ " " + ([.threat, .asset, .location.file, .location.line, .status, "tracked by @ticket"] | tojson)
155
+ ' "$RUNNER_TEMP/bravos-classified.json" >> "$GITHUB_STEP_SUMMARY"
156
+ jq -r '.[] | select(.ticketed|not) |
157
+ "\(.severity // "unrated") \(.threat) on \(.asset) — \(.location.file):\(.location.line) [\(.status // "source @confirmed")]"
158
+ ' "$RUNNER_TEMP/bravos-classified.json" > "$RUNNER_TEMP/bravos-unticketed.txt"
159
+ if [ -s "$RUNNER_TEMP/bravos-unticketed.txt" ]; then
160
+ echo "::error::Confirmed claims or unresolved retests on changed source have no matching @ticket:"
161
+ cat "$RUNNER_TEMP/bravos-unticketed.txt"
126
162
  exit 1
127
163
  fi
128
164
 
165
+ - name: Changed source to review
166
+ if: always() && steps.base.outcome == 'success'
167
+ continue-on-error: true
168
+ env:
169
+ BASE_SHA: ${{ steps.base.outputs.sha }}
170
+ run: |
171
+ # Read the PR as data. The advisory executes Git and GuardLink, never the branch's scripts.
172
+ scope="$RUNNER_TEMP/bravos-source-scope.json"
173
+ if ! guardlink unannotated --json > "$scope" || ! jq -e '(.annotated|type=="array") and (.worklist|type=="array")' "$scope" >/dev/null; then
174
+ echo 'Changed-source review unavailable: GuardLink did not return its source worklist.' >> "$GITHUB_STEP_SUMMARY"; exit 0
175
+ fi
176
+ git diff --no-renames --name-only --diff-filter=AMT -z "$BASE_SHA" HEAD > "$RUNNER_TEMP/bravos-pr-paths"
177
+ summary="$RUNNER_TEMP/bravos-source-review"
178
+ : > "$summary"
179
+ count=0
180
+ jq -Rs --slurpfile scope "$scope" '
181
+ ($scope[0].annotated | INDEX(.)) as $known | ($scope[0].worklist | INDEX(.path)) as $missing |
182
+ [split("\u0000")[] | select(length>0) | . as $f |
183
+ if $known[$f] then [$f,"file already has annotations"]
184
+ elif $missing[$f] then [$f,"no file annotations"] else empty end]
185
+ ' "$RUNNER_TEMP/bravos-pr-paths" > "$RUNNER_TEMP/bravos-in-scope.json"
186
+ count=$(jq length "$RUNNER_TEMP/bravos-in-scope.json")
187
+ while IFS= read -r -d '' file && IFS= read -r -d '' status; do
188
+ ranges=$(git --literal-pathspecs diff --no-ext-diff --no-textconv --no-renames --no-color --unified=0 "$BASE_SHA" HEAD -- "$file" |
189
+ awk '/^@@ / {split($3,x,","); s=substr(x[1],2)+0; if(s<1)s=1; n=x[2]+0; if(++h<=8) printf "%s%s", (h==1 ? "" : ","), (n>1 ? s "-" (s+n-1) : s)} END{if(h>8)printf ",…"; if(!h) printf "whole file"}')
190
+ # Indented code in the summary keeps filenames inert, even when they contain Markdown or newlines.
191
+ jq -nr --arg f "$file" --arg r "$ranges" --arg s "$status" '" " + ($f|tojson) + ":" + $r + " — " + $s' >> "$summary"
192
+ done < <(jq -j '.[:24][] | .[] + "\u0000"' "$RUNNER_TEMP/bravos-in-scope.json")
193
+ removed=$(git diff --no-renames --name-only --diff-filter=D -z "$BASE_SHA" HEAD | jq -Rs 'split("\u0000")|map(select(length>0))|length')
194
+ {
195
+ echo "Changed source to review ($count in-scope files). Inspect the ranges for new or changed entry points, controls and sinks."
196
+ echo
197
+ cat "$summary"
198
+ if ((removed>0)); then echo "$removed deleted path(s) are outside the current-file worklist; review their prior controls and callers."; fi
199
+ if ((count>24)); then echo "$((count-24)) further changed files omitted."; fi
200
+ if ((count>0)); then echo "For graph-derived annotation gaps on the review checkout, run \`bravos graph annotation-gaps --base $BASE_SHA --json\`."; fi
201
+ } >> "$GITHUB_STEP_SUMMARY"
202
+
129
203
  - name: Undefended paths (informational)
130
204
  continue-on-error: true
131
205
  run: guardlink paths --json > paths.json