@bugb-technologies/bravos 1.5.3 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/dist/cli.js +81 -9
  2. package/dist/context.js +387 -0
  3. package/dist/dashboard.js +19 -5
  4. package/dist/guide.js +5 -2
  5. package/dist/help.js +19 -0
  6. package/dist/palette.js +4 -4
  7. package/dist/review-server.js +4 -4
  8. package/dist/review.js +103 -18
  9. package/dist/rules.js +218 -0
  10. package/dist/uninstall.js +6 -0
  11. package/dist/watch-frame.js +67 -42
  12. package/dist/watch.js +21 -7
  13. package/docs/GUIDE.md +20 -2
  14. package/docs/UPGRADING.md +28 -0
  15. package/hooks/lib/autopilot.mjs +29 -7
  16. package/hooks/lib/briefing.mjs +214 -171
  17. package/hooks/lib/context.mjs +522 -0
  18. package/hooks/lib/palette.mjs +4 -4
  19. package/hooks/lib/pre-pr.mjs +70 -0
  20. package/hooks/lib/setup.mjs +5 -2
  21. package/hooks/session-start.mjs +24 -2
  22. package/package.json +1 -1
  23. package/skills/bravos/SKILL.md +1 -1
  24. package/skills/bravos-annotate/SKILL.md +5 -3
  25. package/skills/bravos-annotate/scripts/lib/gate.mjs +45 -0
  26. package/skills/bravos-annotate/scripts/slice.mjs +10 -0
  27. package/skills/bravos-campaign/SKILL.md +1 -1
  28. package/skills/bravos-context/SKILL.md +17 -10
  29. package/skills/bravos-context/intent.example.md +14 -1
  30. package/skills/bravos-recheck/SKILL.md +1 -1
  31. package/skills/bravos-ship/SKILL.md +2 -1
  32. package/skills/bravos-templatize/SKILL.md +1 -1
  33. package/templates/dashboard/dashboard.html +97 -0
  34. package/templates/review/review.html +368 -123
  35. package/templates/workflows/bravos-nightly-claude.yml +36 -2
  36. package/templates/workflows/bravos-nightly-codex.yml +36 -2
  37. package/templates/workflows/bravos-nightly-copilot.yml +23 -0
  38. package/templates/workflows/bravos-pr-gate.yml +76 -0
@@ -118,9 +118,43 @@ jobs:
118
118
  name: bravos-replay-ledger
119
119
  path: ${{ runner.temp }}/bravos-verified-ledger/hypotheses.json
120
120
  retention-days: 1
121
+ # Context first. The annotate job runs only when a named person has confirmed what the product intends
122
+ # (.guardlink/intent.md), or recorded that the team goes without (bravos context decline). The check is one
123
+ # dependency-free script from the default branch; an agent in this workflow cannot open the gate, because nothing it
124
+ # writes under .bravos/ or to the intent is ever staged.
125
+ context:
126
+ if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
127
+ runs-on: ubuntu-latest
128
+ timeout-minutes: 5
129
+ defaults:
130
+ run:
131
+ shell: bash
132
+ outputs:
133
+ open: ${{ steps.gate.outputs.open }}
134
+ steps:
135
+ - uses: actions/checkout@v4
136
+
137
+ - uses: actions/setup-node@v4
138
+ with:
139
+ node-version: 22
140
+
141
+ - name: Context first
142
+ id: gate
143
+ run: |
144
+ if [ ! -f .bravos/hooks/lib/context.mjs ]; then
145
+ echo "::notice::This repository's bravos hook scripts predate the context check; run bravos sync. Annotating as before."
146
+ echo "open=true" >> "$GITHUB_OUTPUT"
147
+ elif node .bravos/hooks/lib/context.mjs gate . > "$RUNNER_TEMP/gate.txt"; then
148
+ echo "open=true" >> "$GITHUB_OUTPUT"
149
+ else
150
+ echo "open=false" >> "$GITHUB_OUTPUT"
151
+ { echo "### Annotation skipped: context first"; echo; cat "$RUNNER_TEMP/gate.txt"; } >> "$GITHUB_STEP_SUMMARY"
152
+ echo "::notice::Annotation skipped: no confirmed intent and no recorded decline. Replay is unaffected."
153
+ fi
154
+
121
155
  annotate:
122
- needs: replay
123
- if: always() && !cancelled() && github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
156
+ needs: [replay, context]
157
+ if: always() && !cancelled() && needs.context.outputs.open == 'true' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
124
158
  runs-on: ubuntu-latest
125
159
  env:
126
160
  BRAVOS_LICENCE: ${{ secrets.BRAVOS_LICENCE }}
@@ -113,9 +113,43 @@ jobs:
113
113
  name: bravos-replay-ledger
114
114
  path: ${{ runner.temp }}/bravos-verified-ledger/hypotheses.json
115
115
  retention-days: 1
116
+ # Context first. The annotate job runs only when a named person has confirmed what the product intends
117
+ # (.guardlink/intent.md), or recorded that the team goes without (bravos context decline). The check is one
118
+ # dependency-free script from the default branch; an agent in this workflow cannot open the gate, because nothing it
119
+ # writes under .bravos/ or to the intent is ever staged.
120
+ context:
121
+ if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
122
+ runs-on: ubuntu-latest
123
+ timeout-minutes: 5
124
+ defaults:
125
+ run:
126
+ shell: bash
127
+ outputs:
128
+ open: ${{ steps.gate.outputs.open }}
129
+ steps:
130
+ - uses: actions/checkout@v4
131
+
132
+ - uses: actions/setup-node@v4
133
+ with:
134
+ node-version: 22
135
+
136
+ - name: Context first
137
+ id: gate
138
+ run: |
139
+ if [ ! -f .bravos/hooks/lib/context.mjs ]; then
140
+ echo "::notice::This repository's bravos hook scripts predate the context check; run bravos sync. Annotating as before."
141
+ echo "open=true" >> "$GITHUB_OUTPUT"
142
+ elif node .bravos/hooks/lib/context.mjs gate . > "$RUNNER_TEMP/gate.txt"; then
143
+ echo "open=true" >> "$GITHUB_OUTPUT"
144
+ else
145
+ echo "open=false" >> "$GITHUB_OUTPUT"
146
+ { echo "### Annotation skipped: context first"; echo; cat "$RUNNER_TEMP/gate.txt"; } >> "$GITHUB_STEP_SUMMARY"
147
+ echo "::notice::Annotation skipped: no confirmed intent and no recorded decline. Replay is unaffected."
148
+ fi
149
+
116
150
  annotate:
117
- needs: replay
118
- if: always() && !cancelled() && github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
151
+ needs: [replay, context]
152
+ if: always() && !cancelled() && needs.context.outputs.open == 'true' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
119
153
  runs-on: ubuntu-latest
120
154
  env:
121
155
  BRAVOS_LICENCE: ${{ secrets.BRAVOS_LICENCE }}
@@ -38,7 +38,30 @@ jobs:
38
38
  run:
39
39
  shell: bash
40
40
  steps:
41
+ - uses: actions/checkout@v4
42
+
43
+ - uses: actions/setup-node@v4
44
+ with:
45
+ node-version: 22
46
+
47
+ # Context first: Copilot is asked for a slice only when a named person has confirmed what the product intends
48
+ # (.guardlink/intent.md), or recorded that the team goes without (bravos context decline).
49
+ - name: Context first
50
+ id: gate
51
+ run: |
52
+ if [ ! -f .bravos/hooks/lib/context.mjs ]; then
53
+ echo "::notice::This repository's bravos hook scripts predate the context check; run bravos sync. Asking Copilot as before."
54
+ echo "open=true" >> "$GITHUB_OUTPUT"
55
+ elif node .bravos/hooks/lib/context.mjs gate . > "$RUNNER_TEMP/gate.txt"; then
56
+ echo "open=true" >> "$GITHUB_OUTPUT"
57
+ else
58
+ echo "open=false" >> "$GITHUB_OUTPUT"
59
+ { echo "### No slice requested: context first"; echo; cat "$RUNNER_TEMP/gate.txt"; } >> "$GITHUB_STEP_SUMMARY"
60
+ echo "::notice::No slice requested: no confirmed intent and no recorded decline."
61
+ fi
62
+
41
63
  - name: Ask Copilot for the next slice
64
+ if: steps.gate.outputs.open == 'true'
42
65
  env:
43
66
  GH_TOKEN: ${{ secrets.COPILOT_ASSIGN_TOKEN }}
44
67
  REPO: ${{ github.repository }}
@@ -162,6 +162,82 @@ jobs:
162
162
  exit 1
163
163
  fi
164
164
 
165
+ # A design rule (a threat whose id starts inv-, written from the team's intent) that was holding, on a file
166
+ # this PR changed after the rule's last refused test, must be named in the PR body by its INV id or its
167
+ # threat id: the held result no longer describes the code. The same check as the pre-PR hook, at file
168
+ # level, with git and jq. A rule no test has tried yet is listed in the summary, never blocked.
169
+ - name: No untested change under a design rule
170
+ env:
171
+ PR_BODY: ${{ github.event.pull_request.body }}
172
+ BASE_SHA: ${{ steps.base.outputs.sha }}
173
+ run: |
174
+ [[ -e .guardlink/intent.md ]] || exit 0
175
+ model="$RUNNER_TEMP/bravos-rules-model.json"
176
+ if ! guardlink parse . > "$model" || ! jq -e 'type == "object"' "$model" > /dev/null; then
177
+ echo "::error::unknown: guardlink parse failed"
178
+ exit 1
179
+ fi
180
+ ledger="$RUNNER_TEMP/bravos-rules-ledger.json"
181
+ echo '{"records":[]}' > "$ledger"
182
+ if [[ -e .guardlink/hypotheses.json ]]; then
183
+ if ! guardlink hypothesis list --json > "$ledger" || ! jq -e '.ledger == "present" and (.records | type == "array")' "$ledger" > /dev/null; then
184
+ echo "::error::unknown: GuardLink hypothesis ledger unreadable"
185
+ exit 1
186
+ fi
187
+ fi
188
+ git diff --name-only -z "$BASE_SHA"...HEAD | jq -Rs 'split("\u0000") | map(select(length > 0))' > "$RUNNER_TEMP/bravos-rules-changed.json"
189
+ # Each rule with the changed files that hold a place it is enforced, and the time of its oldest refused test.
190
+ touched="$RUNNER_TEMP/bravos-rules-touched.json"
191
+ jq --slurpfile changed "$RUNNER_TEMP/bravos-rules-changed.json" --slurpfile ledger "$ledger" '
192
+ def bare: (. // "") | tostring | ltrimstr("#");
193
+ ((.exposures // []) + (.mitigations // [])) as $sites |
194
+ [(.threats // [])[] | select((.id | bare) | test("^inv-"; "i")) | (.id | bare) as $id |
195
+ { threat: ("#" + $id),
196
+ inv: ([(.external_refs // [])[] | tostring | (capture("^intent:(?<n>INV-[0-9]+)$"; "i") | .n)?] | .[0]),
197
+ files: ([$sites[] | select((.threat | bare) == $id) | (.location.file, .location.origin_file) | strings
198
+ | select(. as $f | $changed[0] | index($f))] | unique),
199
+ tested: ([$ledger[0].records[] | select((.threat | bare) == $id and .outcome.outcome == "refuted")
200
+ | .outcome.at | strings | (sub("\\.[0-9]+Z$"; "Z") | fromdateiso8601)?] | min) }
201
+ | select(.files | length > 0)]
202
+ ' "$model" > "$touched"
203
+ # The last commit in this PR that touched each of those files, in seconds.
204
+ times="$RUNNER_TEMP/bravos-rules-times.json"
205
+ echo '{}' > "$times"
206
+ while IFS= read -r -d '' file; do
207
+ at=$(git log -1 --format=%ct "$BASE_SHA"..HEAD -- "$file")
208
+ jq --arg f "$file" --argjson t "${at:-0}" '. + {($f): $t}' "$times" > "$times.next"
209
+ cat "$times.next" > "$times"
210
+ done < <(jq -j '[.[].files[]] | unique | .[] + "\u0000"' "$touched")
211
+ jq -r '.[] | select(.tested == null) |
212
+ " " + ([.inv, .threat, (.files | join(", ")), "no test has tried this design rule yet"] | tojson)
213
+ ' "$touched" >> "$GITHUB_STEP_SUMMARY"
214
+ jq -r -L "$RUNNER_TEMP" --arg body "$PR_BODY" --slurpfile times "$times" 'include "named";
215
+ .[] | select(.tested != null) | . as $r | .files |= map(select(($times[0][.] // 0) > $r.tested))
216
+ | select(.files | length > 0)
217
+ | select((named($body; .threat) or named($body; .inv)) | not)
218
+ | "\(.inv // "rule") \(.threat) — \(.files | join(", ")) (last tested \(.tested | todate | .[0:10]))"
219
+ ' "$touched" > "$RUNNER_TEMP/bravos-rules-lapsed.txt"
220
+ if [ -s "$RUNNER_TEMP/bravos-rules-lapsed.txt" ]; then
221
+ echo "::error::This PR changes code under a design rule that was holding, after the rule was last tested. Replay its test (bravos-recheck), or name each rule (its INV id or threat id) in the PR body:"
222
+ cat "$RUNNER_TEMP/bravos-rules-lapsed.txt"
223
+ exit 1
224
+ fi
225
+
226
+ # The design documents under .bravos/context/ are committed for the whole team to read. They are checked for
227
+ # secrets and local paths here as well as before a push, by the one self-contained script as the base branch
228
+ # has it: this PR's own copy of that script is never run.
229
+ - name: Design documents carry no secret or local path
230
+ env:
231
+ BASE_SHA: ${{ steps.base.outputs.sha }}
232
+ run: |
233
+ [[ -d .bravos/context ]] || exit 0
234
+ if ! git cat-file -e "$BASE_SHA:.bravos/hooks/lib/context.mjs" 2> /dev/null; then
235
+ echo "The base branch has no context check yet (bravos sync adds it); the design documents were not checked here." >> "$GITHUB_STEP_SUMMARY"
236
+ exit 0
237
+ fi
238
+ git show "$BASE_SHA:.bravos/hooks/lib/context.mjs" > "$RUNNER_TEMP/bravos-context.mjs"
239
+ node "$RUNNER_TEMP/bravos-context.mjs" check .
240
+
165
241
  - name: Changed source to review
166
242
  if: always() && steps.base.outcome == 'success'
167
243
  continue-on-error: true