@attalabs/vinaya 0.32.0 → 0.33.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 (209) hide show
  1. package/README.md +1 -1
  2. package/aeg-root/contracts/principal-operator.md +18 -5
  3. package/aeg-root/roles/operator.md +69 -16
  4. package/aeg-root/roles/planner/reference.md +1 -1
  5. package/aeg-root/roles/tranche-archivist.md +1 -0
  6. package/aeg-root/skills/aeg-context-packets/SKILL.md +1 -1
  7. package/aeg-root/skills/aeg-context-packets/examples/operator-start.md +1 -1
  8. package/dist/checks/bin/check-body-bare-digits.js +111 -15
  9. package/dist/checks/bin/check-branch-topology.js +83 -16
  10. package/dist/checks/bin/check-brief-shape.js +111 -15
  11. package/dist/checks/bin/check-changeset-coverage.js +342 -69
  12. package/dist/checks/bin/check-closes-n.js +83 -16
  13. package/dist/checks/bin/check-coherence.js +112 -16
  14. package/dist/checks/bin/check-dead-branch-push.js +82 -15
  15. package/dist/checks/bin/check-dispatch-readiness.js +112 -16
  16. package/dist/checks/bin/check-doc-coverage-push.js +342 -69
  17. package/dist/checks/bin/check-doc-coverage.js +342 -69
  18. package/dist/checks/bin/check-doctrine-no-procedures.js +111 -15
  19. package/dist/checks/bin/check-doctrine-portability.js +342 -69
  20. package/dist/checks/bin/check-evidence-fresh.js +343 -69
  21. package/dist/checks/bin/check-exec-bits.js +342 -69
  22. package/dist/checks/bin/check-first-push-dispatch.js +112 -16
  23. package/dist/checks/bin/check-issue-assignment.js +83 -16
  24. package/dist/checks/bin/check-issue-milestone-attach.js +82 -15
  25. package/dist/checks/bin/check-issue-objectives-numbering.js +82 -15
  26. package/dist/checks/bin/check-issue-parts-coverage.js +82 -15
  27. package/dist/checks/bin/check-issue-surface-globs.js +112 -16
  28. package/dist/checks/bin/check-issue-title-grammar.js +82 -15
  29. package/dist/checks/bin/check-issue-tranche-label.js +82 -15
  30. package/dist/checks/bin/check-main-branch-refusal.js +82 -15
  31. package/dist/checks/bin/check-no-disk-state.js +82 -15
  32. package/dist/checks/bin/check-pr-premise-reassert.js +111 -15
  33. package/dist/checks/bin/check-pr-report-density.js +82 -15
  34. package/dist/checks/bin/check-principal-test-plan-wait.js +82 -15
  35. package/dist/checks/bin/check-quoted-command.js +342 -69
  36. package/dist/checks/bin/check-reader-resolvable-prose.js +342 -69
  37. package/dist/checks/bin/check-registry-gates.js +82 -15
  38. package/dist/checks/bin/check-retired-vocabulary.js +342 -69
  39. package/dist/checks/bin/check-review-gate.js +179 -124
  40. package/dist/checks/bin/check-single-plan-pr.js +82 -15
  41. package/dist/checks/bin/check-surface-scope.js +83 -16
  42. package/dist/checks/bin/check-test-plan.js +82 -15
  43. package/dist/checks/bin/check-token-collection-wired.js +82 -15
  44. package/dist/checks/bin/check-token-report.js +82 -15
  45. package/dist/checks/bin/check-workspace-escape.js +342 -69
  46. package/dist/index.js +2495 -590
  47. package/dist/lib/pre-push-cache-test-run.js +317 -61
  48. package/dist/lib/pre-push-select-tests.js +91 -10
  49. package/package.json +1 -1
  50. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/actions.ts +10 -12
  51. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/anchored-region.ts +5 -5
  52. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/archive-task.ts +42 -17
  53. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/baseline-capture.ts +1 -2
  54. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/branch-topology-gate.ts +3 -3
  55. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/brief-render.ts +554 -95
  56. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/brief-validation.ts +264 -44
  57. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/claude-code-transcript.ts +9 -9
  58. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/coherence-checks.ts +211 -30
  59. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/consumer-enumeration.ts +2 -2
  60. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/control-store/index.ts +75 -0
  61. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/control-store/local.ts +961 -0
  62. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/control-store/migration.ts +212 -0
  63. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/control-store/outcomes.ts +135 -0
  64. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/control-store/records.ts +394 -0
  65. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dead-branch-push-audit.ts +1 -2
  66. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dead-branch-push-guard.ts +1 -1
  67. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/derive-section7.ts +2 -2
  68. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/assess-round.ts +514 -0
  69. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/fakes.ts +110 -0
  70. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/index.ts +27 -0
  71. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/journal-reconstruction.ts +123 -0
  72. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/render-summary.ts +27 -0
  73. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/types.ts +240 -0
  74. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/diagram-model.ts +1 -1
  75. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/direct-main-push.ts +1 -2
  76. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dispatch-gate.ts +65 -22
  77. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/doc-claim.ts +238 -0
  78. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/doc-owners.ts +14 -1
  79. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/docs/docs-coherence.ts +1 -1
  80. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/docs/legacy-anchors.ts +1 -1
  81. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/docs/node-route.ts +1 -1
  82. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/docs/surfaced-manifest.ts +1 -1
  83. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/doctrine-no-procedures.ts +1 -1
  84. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/doctrine-portability.ts +5 -5
  85. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/ensure-label.ts +1 -1
  86. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/first-push-dispatch-gate.ts +1 -1
  87. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/gate-audience.ts +14 -3
  88. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/index.ts +379 -11
  89. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/issue-assignment.ts +3 -4
  90. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/issue-validation.ts +1450 -33
  91. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/leftover-detection.ts +1 -2
  92. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/local-anchor-coverage.ts +2 -2
  93. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/envelope.ts +119 -0
  94. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/index.ts +75 -0
  95. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/redact.ts +87 -0
  96. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/schema.ts +801 -0
  97. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/store.ts +373 -0
  98. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/main-branch-refusal.ts +2 -2
  99. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/metering-io-guard.ts +1 -1
  100. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/milestone-validation.ts +2 -3
  101. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/no-disk-state.ts +2 -2
  102. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/objectives.ts +288 -0
  103. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/parse-token-report.ts +3 -3
  104. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/parse-tranche.ts +1 -1
  105. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/pr-report-density.ts +30 -16
  106. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/pr-tier.ts +17 -1
  107. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/premise-check.ts +1 -1
  108. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/quoted-command.ts +1 -1
  109. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/reader-resolvable-prose.ts +267 -19
  110. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/registry-checks.ts +91 -24
  111. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/registry-scaffold.ts +6 -6
  112. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/report-tokens.ts +4 -4
  113. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-gate.ts +239 -110
  114. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-input-manifest.ts +384 -0
  115. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-policy.ts +184 -0
  116. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-status.ts +65 -18
  117. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/ruling-ordinal.ts +76 -0
  118. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/single-plan-pr.ts +4 -4
  119. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/state-machine-model.ts +40 -27
  120. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/symbol-collisions.ts +2 -2
  121. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/task-branch-identity.ts +38 -0
  122. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/task-tools.ts +488 -0
  123. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/test-plan-gate.ts +7 -9
  124. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/test-plan-section.ts +5 -5
  125. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/types.ts +4 -4
  126. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/verdict-extraction.ts +314 -56
  127. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/waiver-label.ts +2 -3
  128. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/workspace-escape.ts +3 -3
  129. package/studio-standalone/apps/vinaya-studio/web/.next/BUILD_ID +1 -1
  130. package/studio-standalone/apps/vinaya-studio/web/.next/build-manifest.json +3 -3
  131. package/studio-standalone/apps/vinaya-studio/web/.next/prerender-manifest.json +3 -3
  132. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.html +1 -1
  133. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.rsc +1 -1
  134. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
  135. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  136. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  137. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  138. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  139. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page/server-reference-manifest.json +2 -2
  140. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page.js.nft.json +1 -1
  141. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  142. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/api/coherence/route.js +1 -1
  143. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/api/coherence/route.js.nft.json +1 -1
  144. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page/server-reference-manifest.json +2 -2
  145. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page.js.nft.json +1 -1
  146. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page_client-reference-manifest.js +1 -1
  147. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page/server-reference-manifest.json +2 -2
  148. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page.js +1 -1
  149. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page.js.nft.json +1 -1
  150. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page_client-reference-manifest.js +1 -1
  151. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page/server-reference-manifest.json +2 -2
  152. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page.js +1 -1
  153. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page.js.nft.json +1 -1
  154. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page_client-reference-manifest.js +1 -1
  155. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page/server-reference-manifest.json +2 -2
  156. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page.js +1 -1
  157. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page.js.nft.json +1 -1
  158. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page_client-reference-manifest.js +1 -1
  159. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page/server-reference-manifest.json +3 -3
  160. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page.js +2 -2
  161. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page.js.nft.json +1 -1
  162. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page_client-reference-manifest.js +1 -1
  163. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page/server-reference-manifest.json +2 -2
  164. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page.js +1 -1
  165. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page.js.nft.json +1 -1
  166. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page_client-reference-manifest.js +1 -1
  167. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page/server-reference-manifest.json +2 -2
  168. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page.js +1 -1
  169. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page.js.nft.json +1 -1
  170. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page_client-reference-manifest.js +1 -1
  171. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page/server-reference-manifest.json +2 -2
  172. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page.js +1 -1
  173. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page.js.nft.json +1 -1
  174. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page_client-reference-manifest.js +1 -1
  175. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/{[externals]__1agj1ww._.js → [externals]__0cki-x_._.js} +2 -2
  176. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/[root-of-the-server]__02a-3g8._.js +6 -6
  177. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/1q96_modules_@clerk_nextjs_dist_esm_app-router_client_keyless-creator-reader_0lom2js.js +1 -1
  178. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__074w9nf._.js +3 -0
  179. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__0ls23oh._.js +1 -1
  180. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/{[root-of-the-server]__0r7e54g._.js → [root-of-the-server]__18paley._.js} +1 -1
  181. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1gjqmhq._.js +1 -1
  182. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1wc4-ip._.js +1 -1
  183. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/{[root-of-the-server]__1r47dr7._.js → _08onyya._.js} +3 -3
  184. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_096f46i._.js +1 -1
  185. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0af2one._.js +1 -1
  186. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0e5tkdd._.js +1 -1
  187. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0kf2g72._.js +1 -1
  188. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0y1jv16._.js +1 -1
  189. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0zf4d27._.js +1 -1
  190. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_1-wo68i._.js +1 -1
  191. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_15gdg48._.js +5 -5
  192. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_1achbh9._.js +1 -1
  193. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/node_modules_@clerk_nextjs_dist_esm_app-router_server-actions_1x7vfhn.js +2 -2
  194. package/studio-standalone/apps/vinaya-studio/web/.next/server/middleware-build-manifest.js +3 -3
  195. package/studio-standalone/apps/vinaya-studio/web/.next/server/pages/500.html +1 -1
  196. package/studio-standalone/apps/vinaya-studio/web/.next/server/server-reference-manifest.js +1 -1
  197. package/studio-standalone/apps/vinaya-studio/web/.next/server/server-reference-manifest.json +4 -4
  198. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/0bjnj-5fy4e7l.js +1 -0
  199. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{1dc2_-c_gavj1.js → 1ce2dj27_cgbj.js} +4 -4
  200. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{3xg6-flovrcx-.js → 22s44f5k3ecmj.js} +1 -1
  201. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/34hhdtbp20krb.js +1 -0
  202. package/studio-standalone/apps/vinaya-studio/web/package.json +2 -2
  203. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__0hstap0._.js +0 -3
  204. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/2t_rfsztmwu6y.js +0 -1
  205. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/3ua4rm5f-a9k6.js +0 -1
  206. /package/studio-standalone/_node_modules/@attalabs/vinaya/studio-standalone/_node_modules/@attalabs/vinaya/studio-standalone/_node_modules/@attalabs/vinaya/studio-standalone/_node_modules/@attalabs/vinaya/studio-standalone/_node_modules/@attalabs/{aeg-core → vinaya/studio-standalone/_node_modules/@attalabs/aeg-core}/bin/verify-coherence.ts +0 -0
  207. /package/studio-standalone/apps/vinaya-studio/web/.next/static/{e8XbZ2vlVz40KzHmlqhwP → vl7QVqELe1AQ-9kaOd9mR}/_buildManifest.js +0 -0
  208. /package/studio-standalone/apps/vinaya-studio/web/.next/static/{e8XbZ2vlVz40KzHmlqhwP → vl7QVqELe1AQ-9kaOd9mR}/_clientMiddlewareManifest.js +0 -0
  209. /package/studio-standalone/apps/vinaya-studio/web/.next/static/{e8XbZ2vlVz40KzHmlqhwP → vl7QVqELe1AQ-9kaOd9mR}/_ssgManifest.js +0 -0
@@ -0,0 +1,384 @@
1
+ /**
2
+ * The review-input manifest. One typed
3
+ * snapshot of every fact a verdict is judged against — head, the frozen
4
+ * brief's own hash, the objectives version, the newest ruling ordinal, and
5
+ * the effective review policy's digest — built by the driver from forge
6
+ * facts BEFORE reviewers are dispatched (`buildReviewInputManifest`), and
7
+ * the one comparison (`compareManifest`) both the merge gate
8
+ * (`review-gate.ts`'s `checkReviewGate`) and the loop's own publication
9
+ * self-check (`apps/cli/src/lib/dev-review-loop.ts`) call to decide whether
10
+ * a verdict still covers the current state of the world.
11
+ *
12
+ * Pure — no `fs`, no `fetch`, no `process.env`. `node:crypto`'s `createHash`
13
+ * is used the same way `objectives.ts`/`premise-check.ts`/`claude-code-transcript.ts`
14
+ * already do in this package: a deterministic digest is not I/O.
15
+ *
16
+ * Base identity (O1). The manifest now
17
+ * carries `baseSha` — the base commit the round's candidate was judged
18
+ * against — a field deliberately deferred until a durable control-store
19
+ * landed a home for it (that store is now built;
20
+ * see `packages/aeg-core/src/control-store/`). Its acceptance is BOUNDED, not
21
+ * a sixth always-checked equality (Traps to avoid: "same patch text on a new
22
+ * base is not automatically equivalent"; "preserve the existing comparison
23
+ * function ownership; explicitly document any narrowed acceptance"):
24
+ *
25
+ * - When the candidate binds by an EXACT head sha, the base is required to
26
+ * match too — a base-only change (identical candidate, moved base) now
27
+ * INVALIDATES where it silently kept before. This is the one narrowed
28
+ * acceptance this task documents: an exact-head match no longer carries a
29
+ * verdict across a base move.
30
+ * - When the candidate binds by PATCH IDENTITY (a genuine equivalent rebase
31
+ * — the diff itself proven byte-identical), a base move is TOLERATED,
32
+ * exactly as the rebase-equivalence rule already allowed (`loop.md`, "The
33
+ * same-patch rebase equivalence, and its limit"). The patch is what the
34
+ * reviewer judged; the base is only where it sat. CI at the new head, which
35
+ * the gate already requires green, remains the guard for a semantic
36
+ * conflict a moved base could hide — unchanged by this task.
37
+ *
38
+ * Patch identity is NOT a stored field here — it is a property of a PAIR of
39
+ * heads (the judged one, the current one), never of one manifest alone, so
40
+ * `compareManifest` accepts an optional `patchIdOf` and resolves it for both
41
+ * sides at comparison time, exactly as `review-gate.ts` already did before
42
+ * this task.
43
+ */
44
+
45
+ import { createHash } from 'node:crypto'
46
+ import type { ReviewPolicy } from './review-policy'
47
+
48
+ /**
49
+ * `sha256` of the frozen brief's own text as it appears posted, below its
50
+ * header lines — moved here from `apps/cli/src/lib/dispatch-task.ts` (one
51
+ * implementation, not two now that a pure-package caller
52
+ * needs the identical fact). The hashed content is `brief + '\n'`, exactly
53
+ * what `@attalabs/aeg-core`'s `frozenBriefContent`/`contentAfterNLines`
54
+ * reconstruct from a live posted comment — computing the hash any other way
55
+ * would make the writer and every reader of "the frozen brief's hash"
56
+ * disagree on a real, once-posted comment.
57
+ */
58
+ export function briefHash(brief: string): string {
59
+ return createHash('sha256').update(`${brief}\n`).digest('hex')
60
+ }
61
+
62
+ /**
63
+ * `sha256` of the effective review policy — one canonical field order
64
+ * (`codeReviewThreshold`, `securityThreshold`, then `maxRounds`) so two
65
+ * callers resolving the identical `ReviewPolicy` value always agree on its
66
+ * digest regardless of how they built the object literal.
67
+ *
68
+ * `maxRounds` — the incoming round-policy field (O1; Traps to avoid: "include the incoming round-policy field in the
69
+ * relevant configuration identity") — is part of the digest so the policy
70
+ * identity a verdict binds against is the COMPLETE effective policy, not just
71
+ * its two severity thresholds. A run whose round cap changed under a verdict
72
+ * is a policy change the gate must see, the same as a threshold change. The
73
+ * one-time cost is the same fail-closed transition every other field in this
74
+ * family already paid: a verdict cast before this field entered the digest
75
+ * carries the old digest and needs one fresh review round.
76
+ */
77
+ export function policyDigest(policy: ReviewPolicy): string {
78
+ return createHash('sha256')
79
+ .update(
80
+ JSON.stringify({
81
+ codeReviewThreshold: policy.codeReviewThreshold,
82
+ securityThreshold: policy.securityThreshold,
83
+ maxRounds: policy.maxRounds
84
+ })
85
+ )
86
+ .digest('hex')
87
+ }
88
+
89
+ /**
90
+ * One review-input snapshot. `briefHash`/`objectivesVersion` are `null`
91
+ * exactly when nothing is resolvable to bind against yet (no linked Issue,
92
+ * no frozen brief, no `## Objectives` section) — the same "skip the
93
+ * binding" meaning `objectivesVersion` already carried on `ReviewGateInput`
94
+ * before this task. `rulingOrdinal`/`policyDigest` are never null: a PR
95
+ * either has rulings or doesn't (`0` says so), and a policy is always
96
+ * either configured or defaulted.
97
+ */
98
+ export type ReviewInputManifest = {
99
+ /** The candidate identity — the round's judged head (O1: "base and candidate identity"). */
100
+ headSha: string
101
+ /**
102
+ * The base identity — the base commit the candidate was judged against
103
+ * (O1). `null` exactly when no base is
104
+ * resolvable to bind against (a caller with no git/base context, or a
105
+ * pre-cutover verdict that echoed no `Judged base:` line) — the same
106
+ * "nothing to bind against" shape `briefHash`/`objectivesVersion` already
107
+ * carry, keyed on the CURRENT side so a real base still fails a null echo.
108
+ */
109
+ baseSha: string | null
110
+ briefHash: string | null
111
+ objectivesVersion: string | null
112
+ rulingOrdinal: number
113
+ policyDigest: string
114
+ }
115
+
116
+ export type ReviewInputManifestFacts = {
117
+ headSha: string
118
+ /** The base commit the candidate is judged against (O1) — `null` when the caller cannot resolve one, never a thrown refusal. */
119
+ baseSha: string | null
120
+ /** The frozen brief's own text (already header-stripped, e.g. `resolveNewestFrozenBrief(...).content`), or `null` when none is resolvable for this task/PR — `briefHash` is `null` in that case, never a thrown refusal. */
121
+ briefContent: string | null
122
+ objectivesVersion: string | null
123
+ rulingOrdinal: number
124
+ policy: ReviewPolicy
125
+ }
126
+
127
+ /** The one builder — every call site that used to compute these facts as separate, ad hoc values now builds this instead. */
128
+ export function buildReviewInputManifest(facts: ReviewInputManifestFacts): ReviewInputManifest {
129
+ return {
130
+ headSha: facts.headSha,
131
+ baseSha: facts.baseSha,
132
+ briefHash: facts.briefContent === null ? null : briefHash(facts.briefContent),
133
+ objectivesVersion: facts.objectivesVersion,
134
+ rulingOrdinal: facts.rulingOrdinal,
135
+ policyDigest: policyDigest(facts.policy)
136
+ }
137
+ }
138
+
139
+ /**
140
+ * What a verdict/escalation comment echoes back — read off the rendered
141
+ * text by the same extractors `compareManifest`'s two callers both use
142
+ * (`extractCodeReviewVerdict`/`extractSecurityReviewVerdict`,
143
+ * `verdict-extraction.ts`). `null` on any field means no structural line
144
+ * for it was found in the comment's own read window — the pre-cutover
145
+ * legacy shape for `headSha`/`objectivesVersion`/`rulingOrdinal`, and the
146
+ * "this comment predates the feature" shape for `briefHash`/`policyDigest`,
147
+ * which render unconditionally on every verdict from this task forward.
148
+ *
149
+ * Never trust an echoed value as provenance (Traps to avoid) — it is the
150
+ * PARENT's own dispatch-time fact, stamped into the rendered comment and
151
+ * read back only to confirm the comment still covers the CURRENT manifest.
152
+ * A mismatch is reported; the echo itself never substitutes for a live
153
+ * fact anywhere.
154
+ */
155
+ export type EchoedManifest = {
156
+ headSha: string | null
157
+ /** `null` when no `Judged base:` line was found (O1) — pre-cutover legacy stock, or a stripped line. */
158
+ baseSha: string | null
159
+ briefHash: string | null
160
+ objectivesVersion: string | null
161
+ rulingOrdinal: number | null
162
+ policyDigest: string | null
163
+ }
164
+
165
+ /** `manifest`'s own fields, reshaped as an `EchoedManifest` — for a same-process comparison (the loop's pre-hold self-check) where the "echo" is simply the in-memory manifest a verdict was rendered from, never a round-trip through the rendered text. */
166
+ export function manifestAsEchoed(manifest: ReviewInputManifest): EchoedManifest {
167
+ return {
168
+ headSha: manifest.headSha,
169
+ baseSha: manifest.baseSha,
170
+ briefHash: manifest.briefHash,
171
+ objectivesVersion: manifest.objectivesVersion,
172
+ rulingOrdinal: manifest.rulingOrdinal,
173
+ policyDigest: manifest.policyDigest
174
+ }
175
+ }
176
+
177
+ /**
178
+ * True when `echoed.headSha` covers `headSha` — an exact match, or
179
+ * `headSha` starting with `echoed.headSha` (the abbreviated-sha case).
180
+ * `false` when `echoed.headSha` is `null` — an unbound verdict never counts
181
+ * as covering anything. Moved here verbatim from `review-gate.ts`'s own
182
+ * `isBoundToHead` (one comparison, not two).
183
+ */
184
+ export function isBoundToHead(echoed: { headSha: string | null }, headSha: string): boolean {
185
+ if (!echoed.headSha) return false
186
+ return headSha.toLowerCase().startsWith(echoed.headSha.toLowerCase())
187
+ }
188
+
189
+ /**
190
+ * True when the judged head and the current head carry the SAME patch.
191
+ * Fails closed on every uncertainty — `null` on either side is "git could
192
+ * not answer", never "they match." Moved here verbatim from
193
+ * `review-gate.ts`'s own `isBoundByPatchIdentity`.
194
+ *
195
+ * Callers that use this to decide whether a base move is TOLERATED (a
196
+ * genuine rebase) must only consult it when the candidate is NOT already
197
+ * an exact-head match (a round-3 review BLOCKER finding) — see
198
+ * `compareManifest`'s own comment on `patchHead`. Called with the SAME sha
199
+ * on both sides (an unchanged head), `patchIdOf` trivially reports equal
200
+ * values for any deterministic implementation, which is never evidence of
201
+ * an actual rebase; this function itself has no way to tell that case
202
+ * apart from a real one since it only ever sees the two shas, so the
203
+ * exact-head short-circuit belongs at the call site, not here.
204
+ */
205
+ function isBoundByPatchIdentity(
206
+ echoed: { headSha: string | null },
207
+ headSha: string,
208
+ patchIdOf?: (sha: string) => string | null
209
+ ): boolean {
210
+ if (patchIdOf === undefined || !echoed.headSha) return false
211
+ const judged = patchIdOf(echoed.headSha)
212
+ const current = patchIdOf(headSha)
213
+ if (judged === null || current === null) return false
214
+ return judged === current
215
+ }
216
+
217
+ /** A verdict covers the current head when its sha binds it, or its patch identity does. */
218
+ export function isBoundToPatch(
219
+ echoed: { headSha: string | null },
220
+ headSha: string,
221
+ patchIdOf?: (sha: string) => string | null
222
+ ): boolean {
223
+ return isBoundToHead(echoed, headSha) || isBoundByPatchIdentity(echoed, headSha, patchIdOf)
224
+ }
225
+
226
+ /**
227
+ * True when the echoed base identity covers the current one (O1).
228
+ * `currentBase === null` skips the binding (no base resolvable to judge
229
+ * against — the same "nothing to bind against" shape `isBoundToObjectives`/
230
+ * `isBoundToBriefHash` use for their own current-side null, and what keeps
231
+ * every caller that predates base identity, and every fixture that never sets
232
+ * a base, unaffected). Against a REAL current base, a `null` echo (a verdict
233
+ * that carried no `Judged base:` line — pre-cutover stock) is unbound, the
234
+ * same fail-closed treatment `isBoundToBriefHash` gives a null echo against a
235
+ * resolvable current hash — a one-time cost of one fresh review round, never
236
+ * a permanent exemption. An abbreviated echo is tolerated the same way
237
+ * `isBoundToHead` already tolerates one — `extractBaseSha`'s own pattern
238
+ * (`verdict-extraction.ts`) accepts a 7-40 char hex `Judged base:` value, so a
239
+ * correctly-abbreviated echo must bind here too, never silently fail a real
240
+ * base it does cover. The BOUNDED part (base is required only when the head
241
+ * bound by an exact sha, never on a proven patch-identity rebase) lives in
242
+ * `compareManifest`, where both sides of the pair are in view.
243
+ */
244
+ export function isBoundToBase(echoed: { baseSha: string | null }, currentBase: string | null): boolean {
245
+ if (currentBase === null) return true
246
+ if (!echoed.baseSha) return false
247
+ return currentBase.toLowerCase().startsWith(echoed.baseSha.toLowerCase())
248
+ }
249
+
250
+ /**
251
+ * True when the echoed objectives version covers the current one.
252
+ * `currentVersion === null` skips the binding entirely (nothing to judge
253
+ * against). Moved here verbatim from `review-gate.ts`'s own
254
+ * `isBoundToObjectives`.
255
+ */
256
+ export function isBoundToObjectives(
257
+ echoed: { objectivesVersion: string | null },
258
+ currentVersion: string | null
259
+ ): boolean {
260
+ if (currentVersion === null) return true
261
+ return echoed.objectivesVersion === currentVersion
262
+ }
263
+
264
+ /**
265
+ * True when the echoed ruling ordinal covers the current newest one. `null`
266
+ * on the echo (pre-cutover stock) binds only when `currentOrdinal` is `0`.
267
+ * Moved here verbatim from `review-gate.ts`'s own `isBoundToRulings`.
268
+ */
269
+ export function isBoundToRulings(echoed: { rulingOrdinal: number | null }, currentOrdinal: number): boolean {
270
+ if (echoed.rulingOrdinal === null) return currentOrdinal === 0
271
+ return echoed.rulingOrdinal === currentOrdinal
272
+ }
273
+
274
+ /**
275
+ * True when the echoed brief hash covers the current one. `currentHash ===
276
+ * null` skips the binding (no frozen brief resolvable for this task/PR at
277
+ * all — the same "nothing to judge against" shape `isBoundToObjectives`
278
+ * already uses for its own current-side null). Unlike objectives/ruling,
279
+ * there is no partial-legacy stock to grandfather on the echoed side: a
280
+ * `null` echo against a resolvable current hash is simply unbound.
281
+ */
282
+ export function isBoundToBriefHash(echoed: { briefHash: string | null }, currentHash: string | null): boolean {
283
+ if (currentHash === null) return true
284
+ return echoed.briefHash === currentHash
285
+ }
286
+
287
+ /**
288
+ * True when the echoed policy digest covers the current one. A MEDIUM
289
+ * security-review finding: NEVER grandfathers a `null` echo, unlike a first read
290
+ * of "a policy is ALWAYS resolvable, so grandfather on the echoed side
291
+ * instead" might suggest — every other field in this family grandfathers
292
+ * only when there is a genuine sentinel for "nothing to compare" on the
293
+ * CURRENT side (`currentHash`/`currentVersion === null` for brief/
294
+ * objectives, `currentOrdinal === 0` for rulings, each a real fact about
295
+ * that PR/Issue that can itself change and un-grandfather the binding
296
+ * later). A policy has no such sentinel: `currentDigest` is never null, so
297
+ * a blanket "null echo always binds" never re-evaluates and can never
298
+ * un-grandfather — exactly the asymmetry `isBoundToBriefHash`'s own doc
299
+ * comment already warns against ("there is no partial-legacy stock to
300
+ * grandfather on the echoed side: a `null` echo against a resolvable
301
+ * current [value] is simply unbound"), just not yet applied here. A `null`
302
+ * echo (a comment predating `Policy digest:` rendering, or one stripped of
303
+ * the line) is simply unbound, the same as any other mismatch — the one-
304
+ * time cost is that a PR opened before this task merged needs one fresh
305
+ * review round, not a permanent exemption from the O5 guarantee.
306
+ */
307
+ export function isBoundToPolicy(echoed: { policyDigest: string | null }, currentDigest: string): boolean {
308
+ return echoed.policyDigest === currentDigest
309
+ }
310
+
311
+ export type ManifestBindingResult = {
312
+ /** `true` iff every field below binds. */
313
+ bound: boolean
314
+ head: boolean
315
+ /**
316
+ * The bounded base-identity result (O1) — `true` when the base is
317
+ * satisfied under the acceptance rule, NOT a bare `isBoundTobase` equality:
318
+ * a proven patch-identity rebase reports `true` here even across a base move
319
+ * (the diff itself is what was judged), while an exact-head match across a
320
+ * changed base reports `false`. `false` iff a base-only change (or a missing
321
+ * base echo against a real current base) is what broke the binding.
322
+ */
323
+ base: boolean
324
+ briefHash: boolean
325
+ objectivesVersion: boolean
326
+ rulingOrdinal: boolean
327
+ policyDigest: boolean
328
+ }
329
+
330
+ /**
331
+ * The ONE comparison behind both the merge gate (`checkReviewGate`) and the
332
+ * loop's own publication self-check — reported field
333
+ * by field so a caller can name exactly which fact drifted, the same way
334
+ * `checkReviewGate`'s own `problems` array already does.
335
+ */
336
+ export function compareManifest(
337
+ echoed: EchoedManifest,
338
+ current: ReviewInputManifest,
339
+ patchIdOf?: (sha: string) => string | null
340
+ ): ManifestBindingResult {
341
+ // The head/base pair, bound together under the acceptance rule (O1).
342
+ // A verdict judges the pull request; a move of the base branch alone never
343
+ // invalidates it. Base identity is still recorded for audit, but is only
344
+ // a blocking check when the head itself does not bind: when the candidate
345
+ // binds by an EXACT head sha OR by PATCH IDENTITY (a genuine equivalent
346
+ // rebase), a base move is TOLERATED — the reviewer judged the patch or the
347
+ // specific head, not the base; CI at the new head is the guard. When the
348
+ // head does not bind at all (a different revision, not an equivalent
349
+ // rebase), we check whether the base matches as a separate fact — still a
350
+ // fail-closed binding. The tolerance applies only to full-length SHAs: an
351
+ // abbreviated echoed base that does not prefix the current base remains
352
+ // fail-closed (corrupt or stale abbreviation).
353
+ //
354
+ // `patchHead` is only ever consulted when `exactHead` is false (a round-3
355
+ // review BLOCKER finding) — a genuine rebase is "different revision,
356
+ // same patch." Computing `isBoundByPatchIdentity` unconditionally and
357
+ // gating `base`'s bypass on its bare result was wrong: on an UNCHANGED
358
+ // head, `patchIdOf` is called with the identical sha on both sides,
359
+ // trivially reporting equal for any deterministic implementation — not
360
+ // evidence of a rebase, just a self-comparison. That made `patchHead`
361
+ // true whenever `exactHead` already was, silently defeating the binding
362
+ // check. Short-circuiting here means the patch-identity path only ever
363
+ // runs for a genuinely different candidate.
364
+ const exactHead = isBoundToHead(echoed, current.headSha)
365
+ const patchHead = exactHead ? false : isBoundByPatchIdentity(echoed, current.headSha, patchIdOf)
366
+ const head = exactHead || patchHead
367
+ const echoedShaLen = echoed.baseSha?.length ?? 0
368
+ const currentShaLen = current.baseSha?.length ?? 0
369
+ const bothFullShas = echoedShaLen >= 40 && currentShaLen >= 40
370
+ const base = patchHead || (exactHead && bothFullShas) ? true : isBoundToBase(echoed, current.baseSha)
371
+ const briefHashBound = isBoundToBriefHash(echoed, current.briefHash)
372
+ const objectivesVersion = isBoundToObjectives(echoed, current.objectivesVersion)
373
+ const rulingOrdinal = isBoundToRulings(echoed, current.rulingOrdinal)
374
+ const policyDigestBound = isBoundToPolicy(echoed, current.policyDigest)
375
+ return {
376
+ bound: head && base && briefHashBound && objectivesVersion && rulingOrdinal && policyDigestBound,
377
+ head,
378
+ base,
379
+ briefHash: briefHashBound,
380
+ objectivesVersion,
381
+ rulingOrdinal,
382
+ policyDigest: policyDigestBound
383
+ }
384
+ }
@@ -0,0 +1,184 @@
1
+ /**
2
+ * Which severities block is repository policy. One pure evaluator behind every site that derives, accepts, or
3
+ * judges a review verdict — `review post`'s derivation and its contradiction
4
+ * check, the dev-review-loop's assessment of a round and its publication
5
+ * self-check, and the merge gate — so no path applies a weaker rule than
6
+ * another.
7
+ *
8
+ * Pure — no `fs`, no `fetch`, no `process.env`, no config read, no agent
9
+ * call. The caller resolves the effective policy once (`resolveReviewPolicy`,
10
+ * `apps/cli/src/lib/config.ts`) and passes it in; this module never reads
11
+ * config itself (Traps to avoid).
12
+ *
13
+ * One ordered scale per role, one threshold per scale — never booleans per
14
+ * severity, never two copies of one threshold (Traps to avoid). A finding AT
15
+ * OR ABOVE the threshold (i.e. at the threshold's own rank, or a more severe
16
+ * rank preceding it on the scale) blocks; everything below it does not.
17
+ */
18
+
19
+ export const CODE_REVIEW_SEVERITY_ORDER = ['BLOCKER', 'MAJOR', 'MINOR'] as const
20
+ export type CodeReviewSeverity = (typeof CODE_REVIEW_SEVERITY_ORDER)[number]
21
+
22
+ export const SECURITY_SEVERITY_ORDER = ['CRITICAL', 'HIGH', 'MEDIUM', 'LOW'] as const
23
+ export type SecuritySeverity = (typeof SECURITY_SEVERITY_ORDER)[number]
24
+
25
+ /** The dev-review-loop's own round cap, default — replaces the `assess-round.ts` constant this once was; overridable via `reviewPolicy.maxRounds` in `vinaya.config.json`. */
26
+ export const DEFAULT_MAX_ROUNDS = 3
27
+
28
+ /** An omitted policy means today's behaviour: code review at `BLOCKER`, security at `HIGH`, `DEFAULT_MAX_ROUNDS` rounds. */
29
+ export const DEFAULT_REVIEW_POLICY: ReviewPolicy = {
30
+ codeReviewThreshold: 'BLOCKER',
31
+ securityThreshold: 'HIGH',
32
+ maxRounds: DEFAULT_MAX_ROUNDS
33
+ }
34
+
35
+ export type ReviewPolicy = {
36
+ codeReviewThreshold: CodeReviewSeverity
37
+ securityThreshold: SecuritySeverity
38
+ /** The dev-review-loop's own round cap — repository policy, not a hardcoded constant. Resolved once per loop run, same trust class as the two thresholds above. */
39
+ maxRounds: number
40
+ }
41
+
42
+ /** The minimal shape the evaluator needs — every real finding type (review-post.ts's `Finding`, a gate-side severity-only extraction) satisfies it. `location` is optional so a caller with no location to report (an older extraction shape) still type-checks; such a finding is simply never prose-capped (O5, below). */
43
+ export type PolicyFinding = { severity: string; location?: string }
44
+
45
+ /**
46
+ * A location shaped like a real file reference — a path ending in a
47
+ * `.<ext>` segment, optionally followed by `:<line>` — the shape every
48
+ * `findings.txt` location actually takes (`SEVERITY|file:line|description`).
49
+ * Round 2 review, BLOCKER: `/\bcomment\b/i` alone matched `comment` as a
50
+ * plain substring, so a real test file whose NAME happens to contain the
51
+ * word (`apps/cli/tests/commands/pr-create-brief-comment.test.ts`) was
52
+ * wrongly treated as "the finding's location is a comment" and capped to
53
+ * `MINOR` — exactly the trap O5's own brief forbids (never cap a source or
54
+ * test file). Gating the comment pattern on "does NOT also look like a real
55
+ * file" closes this: a genuine PR/review-comment location the reviewer
56
+ * writes (`PR comment`, `a review comment`, bare `comment`) never carries a
57
+ * file extension, so it is unaffected.
58
+ */
59
+ const FILE_SHAPED_LOCATION = /\.[a-zA-Z0-9]{1,10}(:\d+)?\s*$/
60
+
61
+ /**
62
+ * `true` when `location` names the
63
+ * PR body or a PR/review comment — prose surfaces this evaluator caps at
64
+ * `MINOR` before counting a finding toward the blocking threshold, regardless
65
+ * of the severity the reviewer actually reported. Each of these, gated on
66
+ * `FILE_SHAPED_LOCATION` below (a LOW round-2 review finding): a real file
67
+ * whose own name happens to contain one of these words or phrases —
68
+ * `apps/cli/tests/commands/pr-create-brief-comment.test.ts`, or any of the
69
+ * repo's own `pr-body-*.md` fixtures — is a source or test file, never
70
+ * prose, no matter which of these patterns its path text also matches. The
71
+ * `aeg-root/roles/` pattern is deliberately NOT in this group and is checked
72
+ * separately, ungated: it IS a real file, and is still prose by this task's
73
+ * own design (see `isProseLocation` below).
74
+ */
75
+ const PROSE_LOCATION_PATTERNS = [/\bpr\s*body\b/i, /\bcomment\b/i] as const
76
+
77
+ /** A role doc IS a file, yet still counts as prose — the one deliberate exception the file-shape gate never applies to. */
78
+ const ROLE_FILE_LOCATION = /(^|\/)aeg-root\/roles\//i
79
+
80
+ export function isProseLocation(location: string): boolean {
81
+ if (ROLE_FILE_LOCATION.test(location)) return true
82
+ if (FILE_SHAPED_LOCATION.test(location)) return false
83
+ return PROSE_LOCATION_PATTERNS.some((pattern) => pattern.test(location))
84
+ }
85
+
86
+ /**
87
+ * The severity every prose-located finding is evaluated at, regardless of
88
+ * scale — literally `'MINOR'`, not "the bottom rung of whichever scale
89
+ * applies": on the code-review scale this is the least severe rank; on the
90
+ * security scale `'MINOR'` is not a member at all, so `blockingSeverities`'s
91
+ * `Set` never contains it and a prose-located security finding never blocks
92
+ * under any configured threshold. Exported so callers rendering a capped
93
+ * finding's effective severity (never its own reported one) share this one
94
+ * literal rather than a second copy of it.
95
+ */
96
+ export const PROSE_CAP_SEVERITY = 'MINOR'
97
+
98
+ export type PolicyEvaluation<F extends PolicyFinding> = {
99
+ outcome: 'clean' | 'blocked'
100
+ /** The findings responsible for blocking — `[]` iff `outcome === 'clean'`. */
101
+ blockingFindings: F[]
102
+ }
103
+
104
+ /**
105
+ * Every severity on `scale` at or above `threshold`'s own rank — `scale`
106
+ * ordered most-to-least severe, so this is the prefix of `scale` ending at
107
+ * `threshold` inclusive. Throws if `threshold` is not on `scale`: an unknown
108
+ * threshold value is a caller defect, never silently treated as "nothing
109
+ * blocks" or "everything blocks."
110
+ */
111
+ export function blockingSeverities(scale: readonly string[], threshold: string): string[] {
112
+ const idx = scale.indexOf(threshold)
113
+ if (idx === -1) {
114
+ throw new Error(`blockingSeverities: threshold "${threshold}" is not one of ${scale.join(' > ')}`)
115
+ }
116
+ return scale.slice(0, idx + 1)
117
+ }
118
+
119
+ /**
120
+ * The one pure evaluator. Takes validated findings and an effective
121
+ * policy threshold on an ordered severity scale; returns the outcome and the
122
+ * findings responsible for blocking. Throws if any finding's own severity is
123
+ * not on `scale` — findings reaching this function are expected to already
124
+ * be validated against the same scale (`parseFindingsFile`, a gate-side
125
+ * extraction), so an unrecognized severity here is a caller defect, not a
126
+ * value to silently ignore.
127
+ */
128
+ export function evaluateReviewFindings<F extends PolicyFinding>(
129
+ findings: readonly F[],
130
+ scale: readonly string[],
131
+ threshold: string
132
+ ): PolicyEvaluation<F> {
133
+ const blocking = new Set(blockingSeverities(scale, threshold))
134
+ const blockingFindings = findings.filter((f) => {
135
+ if (!scale.includes(f.severity)) {
136
+ throw new Error(`evaluateReviewFindings: severity "${f.severity}" is not one of ${scale.join(' > ')}`)
137
+ }
138
+ // Prose never blocks: a finding whose own location is the PR
139
+ // body, a comment, or a role file is evaluated at `PROSE_CAP_SEVERITY`,
140
+ // never its own reported severity — a source or test file location is
141
+ // never capped, and the finding's own reported severity is unchanged
142
+ // (only how it counts toward THIS threshold check is affected).
143
+ const effectiveSeverity = f.location !== undefined && isProseLocation(f.location) ? PROSE_CAP_SEVERITY : f.severity
144
+ return blocking.has(effectiveSeverity)
145
+ })
146
+ return { outcome: blockingFindings.length > 0 ? 'blocked' : 'clean', blockingFindings }
147
+ }
148
+
149
+ /** `evaluateReviewFindings` fixed to the code-review scale and `policy.codeReviewThreshold`. */
150
+ export function evaluateCodeReview<F extends PolicyFinding>(
151
+ findings: readonly F[],
152
+ policy: ReviewPolicy
153
+ ): PolicyEvaluation<F> {
154
+ return evaluateReviewFindings(findings, CODE_REVIEW_SEVERITY_ORDER, policy.codeReviewThreshold)
155
+ }
156
+
157
+ /** `evaluateReviewFindings` fixed to the security scale and `policy.securityThreshold`. */
158
+ export function evaluateSecurityReview<F extends PolicyFinding>(
159
+ findings: readonly F[],
160
+ policy: ReviewPolicy
161
+ ): PolicyEvaluation<F> {
162
+ return evaluateReviewFindings(findings, SECURITY_SEVERITY_ORDER, policy.securityThreshold)
163
+ }
164
+
165
+ /** The code-review scale's blocking subset under `policy` — `blockingSeverities(CODE_REVIEW_SEVERITY_ORDER, policy.codeReviewThreshold)`. */
166
+ export function codeReviewBlockingSeverities(policy: ReviewPolicy): string[] {
167
+ return blockingSeverities(CODE_REVIEW_SEVERITY_ORDER, policy.codeReviewThreshold)
168
+ }
169
+
170
+ /** The security scale's blocking subset under `policy` — `blockingSeverities(SECURITY_SEVERITY_ORDER, policy.securityThreshold)`. */
171
+ export function securityBlockingSeverities(policy: ReviewPolicy): string[] {
172
+ return blockingSeverities(SECURITY_SEVERITY_ORDER, policy.securityThreshold)
173
+ }
174
+
175
+ /**
176
+ * `true` when `value` is one of `scale`'s own members — the runtime check
177
+ * behind O1's "an unknown severity or threshold value refuses at config
178
+ * load, never falls back." Exported so `apps/cli/src/lib/config.ts`'s
179
+ * `resolveReviewPolicy` can validate a configured threshold against the
180
+ * SAME scale this module evaluates against, rather than a second copy.
181
+ */
182
+ export function isKnownSeverity(scale: readonly string[], value: string): boolean {
183
+ return scale.includes(value)
184
+ }