@bugb-technologies/bravos 1.5.2 → 1.6.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/artifacts.js +31 -1
  2. package/dist/cli.js +78 -5
  3. package/dist/codegraph.js +32 -4
  4. package/dist/context.js +351 -0
  5. package/dist/dashboard.js +35 -10
  6. package/dist/guide.js +3 -0
  7. package/dist/help.js +19 -0
  8. package/dist/report/data.js +2 -1
  9. package/dist/rules.js +218 -0
  10. package/dist/setup.js +33 -7
  11. package/dist/uninstall.js +6 -0
  12. package/dist/versions.js +1 -1
  13. package/dist/watch-frame.js +8 -1
  14. package/dist/watch.js +11 -2
  15. package/docs/GUIDE.md +18 -0
  16. package/docs/UPGRADING.md +30 -0
  17. package/hooks/lib/autopilot.mjs +29 -7
  18. package/hooks/lib/briefing.mjs +29 -5
  19. package/hooks/lib/context.mjs +522 -0
  20. package/hooks/lib/pre-pr.mjs +70 -0
  21. package/hooks/lib/setup.mjs +5 -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-codegraph/SKILL.md +1 -1
  29. package/skills/bravos-context/SKILL.md +16 -10
  30. package/skills/bravos-context/intent.example.md +14 -1
  31. package/skills/bravos-recheck/SKILL.md +1 -1
  32. package/skills/bravos-ship/SKILL.md +2 -1
  33. package/skills/bravos-templatize/SKILL.md +1 -1
  34. package/templates/dashboard/dashboard.html +97 -0
  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
@@ -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