@attalabs/vinaya 0.31.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 (212) hide show
  1. package/README.md +2 -3
  2. package/aeg-root/contracts/principal-operator.md +18 -5
  3. package/aeg-root/roles/developer/reference.md +3 -3
  4. package/aeg-root/roles/operator.md +69 -16
  5. package/aeg-root/roles/planner/reference.md +1 -1
  6. package/aeg-root/roles/tranche-archivist.md +1 -0
  7. package/aeg-root/skills/aeg-context-packets/SKILL.md +1 -1
  8. package/aeg-root/skills/aeg-context-packets/examples/operator-start.md +1 -1
  9. package/aeg-root/templates/pr-report-template.md +7 -2
  10. package/dist/checks/bin/check-body-bare-digits.js +340 -101
  11. package/dist/checks/bin/check-branch-topology.js +184 -105
  12. package/dist/checks/bin/check-brief-shape.js +333 -94
  13. package/dist/checks/bin/check-changeset-coverage.js +1028 -248
  14. package/dist/checks/bin/check-ci-shard-coverage.js +82 -0
  15. package/dist/checks/bin/check-closes-n.js +184 -105
  16. package/dist/checks/bin/check-coherence.js +345 -145
  17. package/dist/checks/bin/check-dead-branch-push.js +179 -59
  18. package/dist/checks/bin/check-dispatch-readiness.js +350 -150
  19. package/dist/checks/bin/check-doc-coverage-push.js +1011 -231
  20. package/dist/checks/bin/check-doc-coverage.js +1015 -235
  21. package/dist/checks/bin/check-doctrine-no-procedures.js +333 -94
  22. package/dist/checks/bin/check-doctrine-portability.js +1013 -233
  23. package/dist/checks/bin/check-evidence-fresh.js +1010 -222
  24. package/dist/checks/bin/check-exec-bits.js +1009 -229
  25. package/dist/checks/bin/check-first-push-dispatch.js +343 -145
  26. package/dist/checks/bin/check-issue-assignment.js +186 -107
  27. package/dist/checks/bin/check-issue-milestone-attach.js +176 -56
  28. package/dist/checks/bin/check-issue-objectives-numbering.js +176 -56
  29. package/dist/checks/bin/check-issue-parts-coverage.js +176 -56
  30. package/dist/checks/bin/check-issue-surface-globs.js +363 -143
  31. package/dist/checks/bin/check-issue-title-grammar.js +176 -56
  32. package/dist/checks/bin/check-issue-tranche-label.js +176 -56
  33. package/dist/checks/bin/check-main-branch-refusal.js +176 -56
  34. package/dist/checks/bin/check-no-disk-state.js +176 -56
  35. package/dist/checks/bin/check-pr-premise-reassert.js +333 -92
  36. package/dist/checks/bin/check-pr-report-density.js +176 -56
  37. package/dist/checks/bin/check-principal-test-plan-wait.js +176 -54
  38. package/dist/checks/bin/check-quoted-command.js +999 -217
  39. package/dist/checks/bin/check-reader-resolvable-prose.js +1011 -229
  40. package/dist/checks/bin/check-registry-gates.js +186 -56
  41. package/dist/checks/bin/check-retired-vocabulary.js +997 -215
  42. package/dist/checks/bin/check-review-gate.js +403 -203
  43. package/dist/checks/bin/check-single-plan-pr.js +176 -56
  44. package/dist/checks/bin/check-surface-scope.js +184 -105
  45. package/dist/checks/bin/check-test-plan.js +176 -54
  46. package/dist/checks/bin/check-token-collection-wired.js +182 -57
  47. package/dist/checks/bin/check-token-report.js +178 -58
  48. package/dist/checks/bin/check-workspace-escape.js +1011 -229
  49. package/dist/index.js +5971 -3489
  50. package/dist/lib/pre-push-cache-test-run.js +4431 -0
  51. package/dist/lib/pre-push-select-tests.js +799 -110
  52. package/package.json +3 -2
  53. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/actions.ts +10 -12
  54. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/anchored-region.ts +5 -5
  55. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/archive-task.ts +42 -17
  56. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/baseline-capture.ts +1 -2
  57. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/branch-topology-gate.ts +3 -3
  58. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/brief-render.ts +554 -95
  59. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/brief-validation.ts +264 -44
  60. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/claude-code-transcript.ts +9 -9
  61. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/coherence-checks.ts +211 -30
  62. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/consumer-enumeration.ts +2 -2
  63. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/control-store/index.ts +75 -0
  64. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/control-store/local.ts +961 -0
  65. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/control-store/migration.ts +212 -0
  66. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/control-store/outcomes.ts +135 -0
  67. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/control-store/records.ts +394 -0
  68. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dead-branch-push-audit.ts +1 -2
  69. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dead-branch-push-guard.ts +1 -1
  70. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/derive-section7.ts +2 -2
  71. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/assess-round.ts +514 -0
  72. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/fakes.ts +110 -0
  73. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/index.ts +27 -0
  74. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/journal-reconstruction.ts +123 -0
  75. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/render-summary.ts +27 -0
  76. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/types.ts +240 -0
  77. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/diagram-model.ts +1 -1
  78. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/direct-main-push.ts +1 -2
  79. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dispatch-gate.ts +65 -22
  80. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/doc-claim.ts +238 -0
  81. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/doc-owners.ts +14 -1
  82. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/docs/docs-coherence.ts +1 -1
  83. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/docs/legacy-anchors.ts +1 -1
  84. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/docs/node-route.ts +1 -1
  85. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/docs/surfaced-manifest.ts +1 -1
  86. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/doctrine-no-procedures.ts +1 -1
  87. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/doctrine-portability.ts +5 -5
  88. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/ensure-label.ts +1 -1
  89. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/first-push-dispatch-gate.ts +1 -1
  90. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/gate-audience.ts +14 -3
  91. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/index.ts +379 -11
  92. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/issue-assignment.ts +3 -4
  93. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/issue-validation.ts +1450 -33
  94. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/leftover-detection.ts +1 -2
  95. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/local-anchor-coverage.ts +2 -2
  96. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/envelope.ts +119 -0
  97. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/index.ts +75 -0
  98. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/redact.ts +87 -0
  99. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/schema.ts +801 -0
  100. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/store.ts +373 -0
  101. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/main-branch-refusal.ts +2 -2
  102. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/metering-io-guard.ts +1 -1
  103. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/milestone-validation.ts +2 -3
  104. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/no-disk-state.ts +2 -2
  105. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/objectives.ts +288 -0
  106. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/parse-token-report.ts +3 -3
  107. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/parse-tranche.ts +1 -1
  108. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/pr-report-density.ts +30 -16
  109. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/pr-tier.ts +17 -1
  110. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/premise-check.ts +1 -1
  111. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/quoted-command.ts +1 -1
  112. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/reader-resolvable-prose.ts +267 -19
  113. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/registry-checks.ts +91 -24
  114. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/registry-scaffold.ts +6 -6
  115. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/report-tokens.ts +4 -4
  116. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-gate.ts +239 -110
  117. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-input-manifest.ts +384 -0
  118. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-policy.ts +184 -0
  119. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-status.ts +65 -18
  120. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/ruling-ordinal.ts +76 -0
  121. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/single-plan-pr.ts +4 -4
  122. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/state-machine-model.ts +40 -27
  123. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/symbol-collisions.ts +2 -2
  124. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/task-branch-identity.ts +38 -0
  125. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/task-tools.ts +488 -0
  126. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/test-plan-gate.ts +7 -9
  127. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/test-plan-section.ts +5 -5
  128. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/types.ts +4 -4
  129. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/verdict-extraction.ts +314 -56
  130. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/waiver-label.ts +2 -3
  131. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/workspace-escape.ts +3 -3
  132. package/studio-standalone/apps/vinaya-studio/web/.next/BUILD_ID +1 -1
  133. package/studio-standalone/apps/vinaya-studio/web/.next/build-manifest.json +3 -3
  134. package/studio-standalone/apps/vinaya-studio/web/.next/prerender-manifest.json +3 -3
  135. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.html +1 -1
  136. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.rsc +1 -1
  137. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
  138. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  139. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  140. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  141. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  142. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page/server-reference-manifest.json +2 -2
  143. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page.js.nft.json +1 -1
  144. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  145. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/api/coherence/route.js +1 -1
  146. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/api/coherence/route.js.nft.json +1 -1
  147. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page/server-reference-manifest.json +2 -2
  148. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page.js.nft.json +1 -1
  149. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page_client-reference-manifest.js +1 -1
  150. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page/server-reference-manifest.json +2 -2
  151. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page.js +1 -1
  152. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page.js.nft.json +1 -1
  153. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page_client-reference-manifest.js +1 -1
  154. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page/server-reference-manifest.json +2 -2
  155. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page.js +1 -1
  156. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page.js.nft.json +1 -1
  157. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page_client-reference-manifest.js +1 -1
  158. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page/server-reference-manifest.json +2 -2
  159. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page.js +1 -1
  160. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page.js.nft.json +1 -1
  161. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page_client-reference-manifest.js +1 -1
  162. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page/server-reference-manifest.json +3 -3
  163. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page.js +2 -2
  164. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page.js.nft.json +1 -1
  165. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page_client-reference-manifest.js +1 -1
  166. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page/server-reference-manifest.json +2 -2
  167. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page.js +1 -1
  168. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page.js.nft.json +1 -1
  169. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page_client-reference-manifest.js +1 -1
  170. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page/server-reference-manifest.json +2 -2
  171. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page.js +1 -1
  172. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page.js.nft.json +1 -1
  173. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page_client-reference-manifest.js +1 -1
  174. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page/server-reference-manifest.json +2 -2
  175. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page.js +1 -1
  176. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page.js.nft.json +1 -1
  177. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page_client-reference-manifest.js +1 -1
  178. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/{[externals]__1agj1ww._.js → [externals]__0cki-x_._.js} +2 -2
  179. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/[root-of-the-server]__02a-3g8._.js +6 -6
  180. 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
  181. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__074w9nf._.js +3 -0
  182. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__0ls23oh._.js +1 -1
  183. 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
  184. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1gjqmhq._.js +1 -1
  185. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1wc4-ip._.js +1 -1
  186. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/{[root-of-the-server]__1r47dr7._.js → _08onyya._.js} +3 -3
  187. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_096f46i._.js +1 -1
  188. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0af2one._.js +1 -1
  189. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0e5tkdd._.js +1 -1
  190. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0kf2g72._.js +1 -1
  191. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0y1jv16._.js +1 -1
  192. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0zf4d27._.js +1 -1
  193. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_1-wo68i._.js +1 -1
  194. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_15gdg48._.js +5 -5
  195. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_1achbh9._.js +1 -1
  196. 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
  197. package/studio-standalone/apps/vinaya-studio/web/.next/server/middleware-build-manifest.js +3 -3
  198. package/studio-standalone/apps/vinaya-studio/web/.next/server/pages/500.html +1 -1
  199. package/studio-standalone/apps/vinaya-studio/web/.next/server/server-reference-manifest.js +1 -1
  200. package/studio-standalone/apps/vinaya-studio/web/.next/server/server-reference-manifest.json +4 -4
  201. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/0bjnj-5fy4e7l.js +1 -0
  202. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{1dc2_-c_gavj1.js → 1ce2dj27_cgbj.js} +4 -4
  203. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{3xg6-flovrcx-.js → 22s44f5k3ecmj.js} +1 -1
  204. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/34hhdtbp20krb.js +1 -0
  205. package/studio-standalone/apps/vinaya-studio/web/package.json +2 -2
  206. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__0hstap0._.js +0 -3
  207. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/2t_rfsztmwu6y.js +0 -1
  208. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/3ua4rm5f-a9k6.js +0 -1
  209. /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
  210. /package/studio-standalone/apps/vinaya-studio/web/.next/static/{e8XbZ2vlVz40KzHmlqhwP → vl7QVqELe1AQ-9kaOd9mR}/_buildManifest.js +0 -0
  211. /package/studio-standalone/apps/vinaya-studio/web/.next/static/{e8XbZ2vlVz40KzHmlqhwP → vl7QVqELe1AQ-9kaOd9mR}/_clientMiddlewareManifest.js +0 -0
  212. /package/studio-standalone/apps/vinaya-studio/web/.next/static/{e8XbZ2vlVz40KzHmlqhwP → vl7QVqELe1AQ-9kaOd9mR}/_ssgManifest.js +0 -0
@@ -1,27 +1,59 @@
1
1
  /**
2
- * Task-brief renderer (review-convergence-v1 task 12, #387). Pure — no `fs`,
2
+ * Task-brief renderer. Pure — no `fs`,
3
3
  * no `gh`/`git`, no `process.env`. Reads `aeg-root/templates/brief-template.md`
4
4
  * (passed in as `template`, read at run time by the CLI shim
5
5
  * `apps/cli/src/commands/brief.ts`) and every derivable fact (`BriefFacts`,
6
6
  * assembled by that same shim from the forge and the tree) and emits the
7
7
  * twelve-section brief skeleton with every mechanically-derivable section
8
8
  * filled. A section this module cannot derive from a stated fact is never
9
- * defaulted — `renderBrief` refuses, naming the missing fact, per Issue #387's
9
+ * defaulted — `renderBrief` refuses, naming the missing fact, per this
10
10
  * rule: "no section is written by hand; the rationale is the one hand-written
11
11
  * artefact and the Issue creation gate is its review."
12
12
  *
13
13
  * Every judgment section (Technical dependencies' free-form detail beyond the
14
14
  * Dependency-rationale field, the Pre-flight task-specific checks, the
15
15
  * Verification command list beyond the fixed full run) is out of this task's
16
- * scope — Issue #387: "NOT this task: rendering any judgment section." Those
16
+ * scope: "NOT this task: rendering any judgment section." Those
17
17
  * sections are rendered with the mechanical content this module CAN derive;
18
- * anything genuinely judgment-only is left for the Brief Author to add by
18
+ * anything genuinely judgment-only is left for the Planner to add by
19
19
  * hand after render.
20
20
  */
21
21
 
22
+ import { packagesNamedIn } from './brief-validation'
22
23
  import { deriveSection7 } from './derive-section7'
23
- import { isDocFile } from './file-classify'
24
- import { deriveTierFromDiff } from './pr-tier'
24
+ import {
25
+ BRIEF_SECTIONS_SINCE_ISSUE,
26
+ DOCUMENTATION_SINCE_ISSUE,
27
+ globCoversPath,
28
+ type IssueDocumentation,
29
+ type IssuePart,
30
+ type IssueSurface,
31
+ type IssueTestPlan,
32
+ OBJECTIVES_SINCE_ISSUE
33
+ } from './issue-validation'
34
+ import { type Objective, renderObjectives } from './objectives'
35
+ import { applyTierFloor, deriveTierFromDiff, readTierFromPrBody } from './pr-tier'
36
+
37
+ /**
38
+ * Renders the Issue's `## Documentation` section verbatim — one bullet per
39
+ * source/mechanism pair (with its `(O<n>)` citation, when present — O3),
40
+ * or the `None` sentinel line. Called only when
41
+ * `facts.documentation` is not the absent-section sentinel (see the join in
42
+ * `renderBrief`), so both variants here always have something real to print.
43
+ */
44
+ function renderDocumentation(documentation: IssueDocumentation): string {
45
+ if (documentation.kind === 'none') {
46
+ return ['## Documentation', '', 'None — no normative external source governs this task.'].join('\n')
47
+ }
48
+ return [
49
+ '## Documentation',
50
+ '',
51
+ ...documentation.sources.map((s) => {
52
+ const citation = s.objectiveIds.length > 0 ? ` (${s.objectiveIds.map((id) => `O${id}`).join(', ')})` : ''
53
+ return `- ${s.source} — ${s.mechanism}${citation}`
54
+ })
55
+ ].join('\n')
56
+ }
25
57
 
26
58
  export type RationaleFieldKey =
27
59
  | 'boundary'
@@ -67,7 +99,7 @@ const RATIONALE_FIELD_NAMES: Record<RationaleFieldKey, string> = {
67
99
  * (`^\s*`), unlike the copied original — a presence-only check can tolerate
68
100
  * matching a field name mentioned in passing mid-paragraph (the field is
69
101
  * still present somewhere), but an EXTRACTION cannot: found live, self-
70
- * rendering this very task's own Issue (#387), whose "Boundary" field
102
+ * rendering this very task's own Issue, whose "Boundary" field
71
103
  * prose contains the inline aside "`For:`/`Reason:` from
72
104
  * **Suggested agent-class**" — the unanchored original matched that inline
73
105
  * mention first (it is merely preceded by literal `**` characters
@@ -83,6 +115,21 @@ function sliceRationaleField(text: string, labelPattern: string): string {
83
115
  return m ? m[0].trim() : ''
84
116
  }
85
117
 
118
+ /**
119
+ * `parseRationaleFields`' result — the five rationale fields plus the
120
+ * Issue's own declared `Tier:` field, read from
121
+ * the same `body` this function already receives. Piggybacked on this
122
+ * existing call rather than added as a new `BriefFacts` property threaded in
123
+ * by the caller: `rationale: parseRationaleFields(issueBody)` is already the
124
+ * one call site (in `apps/cli` and in this file's own tests) that has the
125
+ * raw Issue body in hand, so extending its return shape reaches
126
+ * `renderBrief` without a second, caller-side wire to keep in sync.
127
+ */
128
+ export type ParsedRationale = Partial<Record<RationaleFieldKey, string>> & {
129
+ /** `readTierFromPrBody(body)` — `null` when the Issue declares no `Tier:` field, or an invalid one. */
130
+ declaredTier?: 0 | 1 | 3 | null
131
+ }
132
+
86
133
  /**
87
134
  * Reads the five rationale fields this renderer needs out of a task Issue's
88
135
  * body, tolerant of both live serializations `checkIssueRationale` accepts
@@ -91,12 +138,51 @@ function sliceRationaleField(text: string, labelPattern: string): string {
91
138
  * so `renderBrief`'s missing-fact check can tell "absent" from "present but
92
139
  * empty".
93
140
  */
94
- export function parseRationaleFields(body: string): Partial<Record<RationaleFieldKey, string>> {
141
+ export function parseRationaleFields(body: string): ParsedRationale {
95
142
  const out: Partial<Record<RationaleFieldKey, string>> = {}
96
143
  for (const key of Object.keys(RATIONALE_FIELD_PATTERNS) as RationaleFieldKey[]) {
97
144
  const text = sliceRationaleField(body, RATIONALE_FIELD_PATTERNS[key])
98
145
  if (text) out[key] = text
99
146
  }
147
+ return { ...out, declaredTier: readTierFromPrBody(body) }
148
+ }
149
+
150
+ /**
151
+ * The backtick-wrapped, path-shaped tokens named in the Boundary field's own
152
+ * prose — the ONLY mechanical source §4 (`renderSection4`, below) draws its
153
+ * Create/Modify file list and premise pins from.
154
+ *
155
+ * `## Surface` is directory-level globs only, by design (its own grammar
156
+ * refuses file paths) — expanding those globs wholesale into §4 is the exact
157
+ * defect this replaces: live evidence, an Issue declaring `apps/cli/**`
158
+ * rendered a brief instructing the developer to modify roughly four hundred
159
+ * files, each with its own sha256 pin. The Planner's Boundary prose is where
160
+ * task authors already name the real files in scope (to justify why each is
161
+ * touched) — extracting from there, instead of from Surface, also reaches
162
+ * files a directory glob cannot express at all: this very task's own
163
+ * Boundary names `packages/aeg-core/src/brief-render.ts`, which sits outside
164
+ * every one of its Surface `in:` globs.
165
+ *
166
+ * A token counts as path-shaped when it is backtick-delimited, contains no
167
+ * space (excludes multi-word command examples like `git push -u origin
168
+ * HEAD`) or `*` (excludes glob examples like `apps/cli/**`), and ends in a
169
+ * short alphanumeric extension. Resolving a token to a real repo path (exact
170
+ * match, or a unique `git ls-files` suffix match for a bare filename elided
171
+ * from a shared directory prefix in the Boundary prose, e.g. "aeg-root/
172
+ * aeg-manual-flow.md, process.md, roles/developer.md") is the caller's job —
173
+ * this function is pure text extraction, no `fs`/`git`.
174
+ */
175
+ export function extractBoundaryFilePaths(boundaryText: string): string[] {
176
+ const out: string[] = []
177
+ const seen = new Set<string>()
178
+ for (const match of boundaryText.matchAll(/`([^`\n]+)`/g)) {
179
+ const token = (match[1] as string).trim()
180
+ if (token.length === 0 || token.includes(' ') || token.includes('*')) continue
181
+ if (!/\.[A-Za-z0-9]{1,6}$/.test(token)) continue
182
+ if (seen.has(token)) continue
183
+ seen.add(token)
184
+ out.push(token)
185
+ }
100
186
  return out
101
187
  }
102
188
 
@@ -110,14 +196,62 @@ export type SurfaceFileFact = {
110
196
  }
111
197
 
112
198
  export type BriefFacts = {
113
- trancheSlug: string
199
+ /**
200
+ * `null` for a backlog Issue with no tranche (O1) —
201
+ * the brief renders `task/issue-<n>` as its branch and the Issue's own
202
+ * title as its PR title, instead of the tranche+task-id forms below.
203
+ */
204
+ trancheSlug: string | null
114
205
  taskId: string
115
206
  title: string
116
207
  issue: number
117
208
  projects: string[]
118
209
  dependsOn: string[]
119
210
  conflictsWith: string[]
120
- rationale: Partial<Record<RationaleFieldKey, string>>
211
+ rationale: ParsedRationale
212
+ /** The Issue's `## Objectives` list (`objectives.ts`'s `objectivesOf`), copied into the brief verbatim between the header and §2. */
213
+ objectives: Objective[]
214
+ /**
215
+ * The Issue's `## Surface` section (`issue-validation.ts`'s
216
+ * `parseIssueSurface`) — feeds §4's Out of surface line and, together with
217
+ * `surfaceFiles`, its Create/Modify split. `{ in: [], out: [] }` (an empty
218
+ * `in:` list) is the absent-section sentinel: a real Surface always
219
+ * parses at least one `in:` glob, so an empty one means the Issue has no
220
+ * `## Surface` section (or it failed to parse) — the same
221
+ * empty-list-means-absent convention `objectives: []` already uses above.
222
+ */
223
+ surface: IssueSurface
224
+ /**
225
+ * The Issue's `## Parts` list (`issue-validation.ts`'s `parseIssueParts`),
226
+ * copied into §6 verbatim — one numbered Part per entry. `[]` is the
227
+ * absent-section sentinel, same convention as `objectives`/`surface`.
228
+ */
229
+ parts: IssuePart[]
230
+ /**
231
+ * The Issue's `## Test plan` section (`issue-validation.ts`'s
232
+ * `parseIssueTestPlan`), copied into §9 verbatim. `{ kind: 'commands',
233
+ * lines: [], principal: [] }` is the absent-section sentinel — a real
234
+ * `commands` plan always carries at least one line or one principal item.
235
+ */
236
+ testPlan: IssueTestPlan
237
+ /**
238
+ * The Issue's `## Stop conditions` bullets (`issue-validation.ts`'s
239
+ * `parseIssueStopConditions`), copied into §10 alongside the rationale's
240
+ * own Stop-and-escalate field. `[]` is the absent-section sentinel, same
241
+ * convention as `objectives`/`parts`.
242
+ */
243
+ stopConditions: string[]
244
+ /**
245
+ * The Issue's `## Documentation` section (`issue-validation.ts`'s
246
+ * `parseIssueDocumentation`), copied into the brief verbatim right after
247
+ * Objectives — the earliest a Developer reads anything, addressing the
248
+ * finding that a documentation obligation buried after Parts/
249
+ * Test plan/Stop conditions competes for attention it never wins.
250
+ * `{ kind: 'sources', sources: [] }` is the absent-section sentinel, same
251
+ * convention as `parts`/`stopConditions`; `{ kind: 'none' }` is the
252
+ * legitimate explicit opt-out and is rendered, never treated as absent.
253
+ */
254
+ documentation: IssueDocumentation
121
255
  dispatchReady: boolean
122
256
  dispatchBlockers: string[]
123
257
  surfaceFiles: SurfaceFileFact[]
@@ -125,20 +259,58 @@ export type BriefFacts = {
125
259
  consumersOf: (pkg: string) => string[]
126
260
  /** `.vinaya/doc-owners` file content, or `null` when the file is absent — passed through to `deriveSection7` unchanged. */
127
261
  docOwnersContent: string | null
262
+ /**
263
+ * The checkout's `HEAD` sha at the moment this brief's facts (the §4
264
+ * premise pins above all) were read (O1/O2).
265
+ * The caller (`assembleAndRenderBrief`, `apps/cli`) refuses to call
266
+ * `renderBrief` at all when this HEAD is behind the fetched remote default
267
+ * branch, or the working tree is dirty on any pinned file — by the time
268
+ * this reaches `renderBrief`, it is always the exact revision the pins
269
+ * above were computed from. Rendered into §2 (`renderSection2`) so the
270
+ * frozen comment states it, and read back out by `extractSourceRevision`
271
+ * for the review loop's reviewer-prompt facts.
272
+ */
273
+ sourceRevision: string
128
274
  }
129
275
 
130
276
  export type RenderResult = { ok: true; brief: string } | { ok: false; missing: string[] }
131
277
 
278
+ /**
279
+ * §4's surface map lists only what the Issue's own `## Surface` admits
280
+ * (O2) — a path the Boundary named inside its `Out:` clause
281
+ * was named in order to exclude it, and prose position is not a reliable
282
+ * signal of that, so the `## Surface` globs are the authority. Admitted
283
+ * means covered by at least one `in:` glob and by no `out:` glob;
284
+ * `globCoversPath` (`issue-validation.ts`) is the same glob matcher
285
+ * `checkSurfaceScope` already uses, consumed here rather than reimplemented.
286
+ */
287
+ function admittedSurfaceFiles(surfaceFiles: SurfaceFileFact[], surface: IssueSurface): SurfaceFileFact[] {
288
+ return surfaceFiles.filter((f) => {
289
+ const admitted = surface.in.some((g) => globCoversPath(g, f.path))
290
+ const excluded = surface.out.some((g) => globCoversPath(g, f.path))
291
+ return admitted && !excluded
292
+ })
293
+ }
294
+
132
295
  function bulletList(items: string[]): string {
133
296
  return items.map((i) => `- ${i}`).join('\n')
134
297
  }
135
298
 
299
+ /**
300
+ * A `## Surface` `in:` entry renders as a clean directory path, never a raw
301
+ * glob (a round-2 MINOR review finding): `globCoversPath`/`admittedSurfaceFiles` above
302
+ * already tolerate a `/**`/`/*` suffix on an `in:` entry, but Modify's
303
+ * directory-listing branch rendered the entry verbatim — the same stripping
304
+ * `globCoversPath` does internally, exposed here for display.
305
+ */
306
+ function stripSurfaceGlobSuffix(glob: string): string {
307
+ return glob.replace(/\/\*\*?$/, '').replace(/\/+$/, '')
308
+ }
309
+
136
310
  function isTestFile(path: string): boolean {
137
311
  return /\.test\.[jt]sx?$/i.test(path)
138
312
  }
139
313
 
140
- const PRINCIPAL_OBSERVATION_RE = /\bprincipal\b[^.\n]*\b(?:browser|signed-in|visual|session)\b/i
141
-
142
314
  function renderHeader(facts: BriefFacts, template: string): string {
143
315
  const introMatch = template.match(/^You are the AEG Developer\.[^\n]*$/m)
144
316
  const intro = introMatch
@@ -149,11 +321,13 @@ function renderHeader(facts: BriefFacts, template: string): string {
149
321
  : 'You are the AEG Developer. Read `aeg-root/roles/developer.md` first. Mandatory.'
150
322
 
151
323
  const reason = facts.rationale.suggestedAgentClass ?? ''
152
- // `deriveTierFromDiff` never returns `3` — Tier 3 stays a judgment call the
153
- // Brief Author raises by hand; the mechanical floor this renderer can prove
154
- // is 0 or 1, exactly the two values that check itself is capable of ruling
155
- // out for a doc/spec-touching surface.
156
- const tier = deriveTierFromDiff(facts.surfaceFiles.map((f) => f.path))
324
+ // The declared tier is a floor, not a default: raised to the mechanical
325
+ // derivation only when that derivation is higher, never lowered — a
326
+ // Planner's judgment (including a hand-raised Tier 3, which no derivation
327
+ // can reach) is never silently overridden by a derivation that cannot see
328
+ // it.
329
+ const derivedFloor = deriveTierFromDiff(facts.surfaceFiles.map((f) => f.path))
330
+ const tier = applyTierFloor(facts.rationale.declaredTier ?? null, derivedFloor)
157
331
  const lines = [
158
332
  '**For:** [model] (coding-agent CLI on a dev machine, dispatched locally, unattended)',
159
333
  `**Reason:** ${reason}`,
@@ -169,98 +343,261 @@ function renderHeader(facts: BriefFacts, template: string): string {
169
343
  return lines.join('\n')
170
344
  }
171
345
 
346
+ /** `task/<tranche>/<n>`, or `task/issue-<n>` for a backlog Issue (`facts.trancheSlug === null`). */
347
+ function developerBranchForFacts(facts: BriefFacts): string {
348
+ return facts.trancheSlug !== null ? `task/${facts.trancheSlug}/${facts.taskId}` : `task/issue-${facts.issue}`
349
+ }
350
+
172
351
  function renderSection2(facts: BriefFacts): string {
173
352
  const depends = facts.dependsOn.length > 0 ? facts.dependsOn.join(', ') : '—'
174
353
  const conflicts = facts.conflictsWith.length > 0 ? facts.conflictsWith.join(', ') : '—'
354
+ const branch = developerBranchForFacts(facts)
355
+ const identityLine =
356
+ facts.trancheSlug !== null
357
+ ? `- **Tranche:** \`${facts.trancheSlug}\`, task ${facts.taskId}, Issue #${facts.issue}. Branch \`${branch}\`. \`Depends-on: ${depends}\`, \`Conflicts-with: ${conflicts}\`. Confirm \`READY TO DISPATCH\` at your own Step 0.`
358
+ : `- **Backlog Issue:** #${facts.issue}, no tranche. Branch \`${branch}\`. \`Depends-on: ${depends}\`, \`Conflicts-with: ${conflicts}\`. Confirm \`READY TO DISPATCH\` at your own Step 0.`
175
359
  const lines = [
176
360
  '## 2. Context — read before doing anything',
177
361
  '',
178
- `- **Tranche:** \`${facts.trancheSlug}\`, task ${facts.taskId}, Issue #${facts.issue}. Branch \`task/${facts.trancheSlug}/${facts.taskId}\`. \`Depends-on: ${depends}\`, \`Conflicts-with: ${conflicts}\`. Confirm \`READY TO DISPATCH\` at your own Step 0.`,
362
+ identityLine,
179
363
  `- **Read Issue #${facts.issue} in full** for the complete rationale — do not re-derive it.`,
364
+ `- **Revision:** rendered at \`${facts.sourceRevision}\` — the checkout's HEAD equaled the remote default branch, and no pinned file below carried an uncommitted change, when these facts were read.`,
180
365
  `- ${facts.rationale.boundary}`,
181
366
  `- ${facts.rationale.trapsToAvoid}`
182
367
  ]
183
368
  return lines.join('\n')
184
369
  }
185
370
 
371
+ /**
372
+ * The exact string `renderSection2` emits, read back out of a rendered/
373
+ * frozen brief — the review loop's reviewer prompt names this revision as a
374
+ * fact rather than re-deriving it from `git`, since
375
+ * the loop's job is to judge the developer's work against the facts the
376
+ * brief actually stated, not against a revision read fresh from a tree that
377
+ * has since moved on. `null` when the text carries no such line (a brief
378
+ * from before this task).
379
+ *
380
+ * A HIGH security-review finding: an unanchored, whole-document
381
+ * regex here took the FIRST `**Revision:** rendered at \`<hex>\`` match
382
+ * anywhere in the text — including inside `## Objectives`, which is copied
383
+ * VERBATIM from the task Issue's own body (`renderObjectives`) and is
384
+ * rendered BEFORE §2's real Revision line. Any Issue author could plant a
385
+ * forged Revision fact in an objective sentence and have it win over the
386
+ * genuine one. Scoped to `## 2. Context`'s own text (ending at the next `##`
387
+ * heading) with a line-anchored match — `renderSection2` always emits the
388
+ * real Revision bullet as the FIRST line in that section, before the
389
+ * Boundary/Traps fields (which can themselves carry multi-line, Issue-author
390
+ * -controlled prose), so a duplicate planted there is never read: `exec`
391
+ * without the `g` flag returns the first match, and the real line always
392
+ * precedes any forged one within this scoped slice. Objectives text sits
393
+ * entirely outside the slice and can no longer be a source at all.
394
+ */
395
+ export function extractSourceRevision(briefText: string): string | null {
396
+ const lines = briefText.split('\n')
397
+ const start = lines.findIndex((l) => /^##\s*2\.\s*Context\b/.test(l.trim()))
398
+ if (start === -1) return null
399
+ const rest = lines.slice(start + 1)
400
+ const end = rest.findIndex((l) => /^##\s/.test(l))
401
+ const section2 = (end === -1 ? rest : rest.slice(0, end)).join('\n')
402
+ const m = /^- \*\*Revision:\*\* rendered at `([0-9a-fA-F]{7,40})`/m.exec(section2)
403
+ return m ? (m[1] as string) : null
404
+ }
405
+
186
406
  function renderSection3(facts: BriefFacts): string {
187
407
  return ['## 3. Technical dependencies', '', `${facts.rationale.dependencyRationale}`].join('\n')
188
408
  }
189
409
 
410
+ // O6: the nearest ancestor directory of `path` that is itself
411
+ // named `tests`/`specs` — e.g. `apps/cli/tests/checks/foo.test.ts` ->
412
+ // `apps/cli/tests`. `checkConsumerTests`'s validator accepts a bare
413
+ // reference to this directory as coverage evidence (same segment-equality
414
+ // convention `checkSurfaceOverlap`'s O4 exemption uses), so this is what the
415
+ // renderer names when the covering FILE itself won't appear in Modify's
416
+ // directory-only listing.
417
+ //
418
+ // Falls back to the covering FILE's own path (never a bare containing
419
+ // directory) when no ancestor segment is literally named `tests`/`specs` —
420
+ // a colocated test file (`packages/sources/src/foo.test.ts`, a real layout
421
+ // this repo's own `packages/sources` and `packages/aeg-core` already use,
422
+ // with no `tests`/`specs` ancestor to name) has no directory form
423
+ // `hasTestPathForConsumer`'s `testDirRe` accepts, but its own `.test.<ext>`
424
+ // path already matches `filePathRe` — a prior version of this fallback
425
+ // named the bare containing directory instead, satisfying neither regex and
426
+ // producing a brief `checkConsumerTests` rejected, reopening the exact class
427
+ // of bug O6 exists to close (round `2` review, BLOCKER).
428
+ function nearestTestDir(path: string): string {
429
+ const segments = path.split('/')
430
+ let idx = -1
431
+ for (let i = segments.length - 1; i >= 0; i--) {
432
+ if (segments[i] === 'tests' || segments[i] === 'specs') {
433
+ idx = i
434
+ break
435
+ }
436
+ }
437
+ if (idx !== -1) return segments.slice(0, idx + 1).join('/')
438
+ return path
439
+ }
440
+
190
441
  function renderSection4(facts: BriefFacts): string {
191
442
  const created = facts.surfaceFiles.filter((f) => f.sha256 === null).map((f) => f.path)
192
443
  const modified = facts.surfaceFiles.filter((f) => f.sha256 !== null).map((f) => f.path)
193
444
 
194
- const byPackage = new Map<string, SurfaceFileFact[]>()
195
- for (const f of facts.surfaceFiles) {
196
- if (!f.packageName) continue
197
- const list = byPackage.get(f.packageName) ?? []
198
- list.push(f)
199
- byPackage.set(f.packageName, list)
200
- }
445
+ // O7: a Boundary that named fewer files than the Issue's
446
+ // own `## Surface` `in:` list is narrower than the real scope — Boundary
447
+ // prose justifies a few files, it is never an exhaustive enumeration.
448
+ // When the Boundary names fewer files than there are `in:` directories,
449
+ // Modify lists each `in:` directory instead of the handful of files the
450
+ // prose happened to name, so a developer reads the scope as the
451
+ // directory, not the one file the rationale mentioned (a real Issue's
452
+ // own Origin: exactly this narrowing shipped two lines against ten
453
+ // objectives).
454
+ //
455
+ // A bare count comparison misses an uneven distribution (a MINOR review
456
+ // finding): two Boundary files and two `in:` directories
457
+ // pass the count check even when both files land in the SAME directory,
458
+ // leaving the other entirely unnamed anywhere in Modify. Coverage is
459
+ // checked per directory instead — `globCoversPath` is the same matcher
460
+ // `admittedSurfaceFiles` above already uses, so a directory only counts as
461
+ // covered by the exact rule that decides which files are in scope at all.
462
+ const uncoveredSurfaceDirs = facts.surface.in.filter(
463
+ (dir) => !facts.surfaceFiles.some((f) => globCoversPath(dir, f.path))
464
+ )
465
+ const boundaryNarrowsSurface = uncoveredSurfaceDirs.length > 0
466
+ // `facts.surface.in` is never empty when `boundaryNarrowsSurface` is true
467
+ // (an empty list has nothing to be uncovered), so the `- (none named)`
468
+ // arm below could never execute — removed rather than left dead (a MINOR review finding).
469
+ const modifyLines = boundaryNarrowsSurface
470
+ ? bulletList(facts.surface.in.map(stripSurfaceGlobSuffix))
471
+ : modified.length > 0
472
+ ? bulletList(modified)
473
+ : '- (none named)'
474
+
475
+ const createdBlock = created.length > 0 ? bulletList(created) : '- (none — every surface file already exists)'
476
+ const outOfSurfaceLine =
477
+ '**Out of surface:** ' +
478
+ (facts.surface.out.length > 0
479
+ ? facts.surface.out.join(', ')
480
+ : "(none named — the Issue's `## Surface` `out:` line is empty)")
481
+ const premisePinsBlock = bulletList(
482
+ facts.surfaceFiles
483
+ .filter((f): f is SurfaceFileFact & { sha256: string } => f.sha256 !== null)
484
+ .map((f) => `${f.path} sha256: ${f.sha256}`)
485
+ )
201
486
 
202
487
  // checkConsumerTests (brief-validation.ts) requires, for every workspace
203
488
  // package a touched `packages/<pkg>` consumer depends on, either a named
204
489
  // test path under that consumer OR the `consumer-tests: none — <reason>`
205
490
  // sentinel — ONE sentinel occurrence anywhere in §4 satisfies the whole
206
491
  // section, so a single combined line covers every uncovered consumer.
492
+ //
493
+ // O6: when `boundaryNarrowsSurface` is true, `modifyLines` above
494
+ // lists bare Surface DIRECTORIES, never the individual files — so a
495
+ // covered consumer's actual test FILE path never appears anywhere in §4,
496
+ // and `checkConsumerTests`'s file-path regex finds nothing even though
497
+ // real coverage exists (a real frozen brief: this renderer produced a
498
+ // brief its own validator rejected). A covered consumer gets an explicit
499
+ // line naming its covering test DIRECTORY (or the file itself, when no
500
+ // `tests`/`specs` ancestor exists to name — see `nearestTestDir`) in that
501
+ // mode — a form `checkConsumerTests` accepts either way — so the renderer
502
+ // can never again produce a brief its own validator fails.
503
+ //
504
+ // The trigger reads `packagesNamedIn` against the SAME text
505
+ // `checkConsumerTests` will re-scan (Create + Modify + Out of surface +
506
+ // Premise pins, everything but the consumer lines themselves, not yet
507
+ // computed) — never `facts.surfaceFiles`' per-file `packageName` alone.
508
+ // A Boundary that narrows Modify to bare Surface DIRECTORIES (`in:`
509
+ // globs with no individual file pinned under them) named a shared
510
+ // package nowhere a file-based scan could see, so the renderer emitted no
511
+ // consumer-tests line at all for it — reproduced live on a real brief's
512
+ // own write, before its Boundary named a consumer test file by path.
513
+ const prelude = [createdBlock, modifyLines, outOfSurfaceLine, premisePinsBlock].join('\n')
207
514
  const uncovered: string[] = []
208
- for (const pkg of byPackage.keys()) {
209
- const shortName = pkg.replace(/^@[^/]+\//, '')
210
- for (const consumer of facts.consumersOf(shortName)) {
211
- const covered = facts.surfaceFiles.some((f) => f.path.startsWith(`${consumer}/`) && isTestFile(f.path))
212
- if (!covered) uncovered.push(`${pkg} (${consumer})`)
515
+ const coveredDirLines: string[] = []
516
+ for (const pkg of packagesNamedIn(prelude)) {
517
+ for (const consumer of facts.consumersOf(pkg)) {
518
+ const coveringFile = facts.surfaceFiles.find((f) => f.path.startsWith(`${consumer}/`) && isTestFile(f.path))
519
+ if (!coveringFile) {
520
+ uncovered.push(`@attalabs/${pkg} (${consumer})`)
521
+ } else if (boundaryNarrowsSurface) {
522
+ coveredDirLines.push(`- consumer-tests: ${nearestTestDir(coveringFile.path)} (covers @attalabs/${pkg})`)
523
+ }
213
524
  }
214
525
  }
215
- const consumerLines =
216
- uncovered.length > 0
526
+ const consumerLines = [
527
+ ...(uncovered.length > 0
217
528
  ? [
218
529
  `- consumer-tests: none — no consumer test path named yet for ${uncovered.join(', ')}; name one before dispatch, or confirm no consumer-facing behavior changed.`
219
530
  ]
220
- : []
531
+ : []),
532
+ ...coveredDirLines
533
+ ]
221
534
 
222
535
  const lines = [
223
536
  '## 4. Technical surface map',
224
537
  '',
225
538
  '**Create:**',
226
- created.length > 0 ? bulletList(created) : '- (none — every surface file already exists)',
539
+ createdBlock,
227
540
  '',
228
541
  '**Modify:**',
229
- modified.length > 0 ? bulletList(modified) : '- (none named)',
542
+ modifyLines,
230
543
  ...(consumerLines.length > 0 ? ['', ...consumerLines] : []),
231
544
  '',
232
- '**Out of surface:** [named explicitly by the Brief Author — not mechanically derivable]',
545
+ outOfSurfaceLine,
233
546
  '',
234
547
  '#### Premise pins',
235
548
  '',
236
549
  '**Premise:**',
237
- bulletList(
238
- facts.surfaceFiles
239
- .filter((f): f is SurfaceFileFact & { sha256: string } => f.sha256 !== null)
240
- .map((f) => `${f.path} sha256: ${f.sha256}`)
241
- )
550
+ premisePinsBlock
242
551
  ]
243
552
  return lines.join('\n')
244
553
  }
245
554
 
246
555
  function renderSection5(facts: BriefFacts): string {
556
+ const branch = developerBranchForFacts(facts)
557
+ const verifyLine =
558
+ facts.trancheSlug !== null
559
+ ? '2. `bun packages/aeg-core/bin/verify-dispatch.ts <tranche> <n>` → `READY TO DISPATCH` (re-derived at render time: it was).'
560
+ : `2. \`bun packages/aeg-core/bin/verify-dispatch.ts --issue ${facts.issue}\` → \`READY TO DISPATCH\` (re-derived at render time: it was).`
247
561
  const lines = [
248
562
  '## 5. Pre-flight checks',
249
563
  '',
250
564
  '**Step 0 (mandatory, verbatim):**',
251
565
  '',
252
566
  '```',
253
- `git worktree add .worktrees/task/${facts.trancheSlug}/${facts.taskId} -b task/${facts.trancheSlug}/${facts.taskId} origin/main && cd .worktrees/task/${facts.trancheSlug}/${facts.taskId} && bun install --frozen-lockfile --silent`,
567
+ `git worktree add .worktrees/${branch} -b ${branch} --no-track origin/main && cd .worktrees/${branch} && git config push.autoSetupRemote true && bun install --frozen-lockfile --silent`,
254
568
  '```',
255
569
  '',
256
570
  '1. Clean status; parent `origin/main`; branch suffix literal-matches the task id.',
257
- '2. `bun packages/aeg-core/bin/verify-dispatch.ts <tranche> <n>` → `READY TO DISPATCH` (re-derived at render time: it was).',
571
+ verifyLine,
258
572
  '',
259
573
  'On any failure: STOP and report.'
260
574
  ]
261
575
  return lines.join('\n')
262
576
  }
263
577
 
578
+ /** `Part <n> (<refs>)` reconstructed from a parsed `IssuePart` — the same citation grammar `brief-validation.ts`'s `PART_CITATION_RE` reads back out of §6. */
579
+ function renderPartCitation(part: IssuePart): string {
580
+ const refs = part.objectiveIds.map((id) => `O${id}`).join(', ')
581
+ return `Part ${part.n} (${refs})`
582
+ }
583
+
584
+ /** Mirrors `brief-validation.ts`'s private `CHECK_NAME_RE` — not exported there, duplicated here for the same §4-triggers-a-§6-Defeat-cases-line rule `checkDefeatCases` enforces on the rendered output. */
585
+ const RENDER_CHECK_NAME_RE = /\bcheck-[a-z0-9-]+(?:\.ts)?\b/
586
+ /** Mirrors `brief-validation.ts`'s private `FORGE_WRITE_COMMAND_RE`. */
587
+ const RENDER_FORGE_WRITE_COMMAND_RE =
588
+ /\bgh\s+(?:pr|issue)\s+(?:create|merge|close|comment|edit|review)\b|\bgit\s+push\b|\bvinaya\s+pr\s+(?:create|report\s+--write)\b/i
589
+
590
+ /**
591
+ * §6 — one numbered Part per `IssuePart` (facts.parts), citation
592
+ * reconstructed verbatim per `renderPartCitation`. Files stay grouped by
593
+ * package exactly as before this task; a Part is zipped by position to a
594
+ * package group (Part 1 → the first touched package, Part 2 → the second,
595
+ * …) — the Issue's own Parts don't name globs, so position is the one
596
+ * mechanical link between "a Part exists" and "these files belong to it".
597
+ * A Part beyond the package-group count (an administrative Part — a
598
+ * changeset commit, the final push) renders with no Files sub-list; a
599
+ * package group beyond the Part count is appended to the last Part.
600
+ */
264
601
  function renderSection6(facts: BriefFacts): string {
265
602
  const byPackage = new Map<string, SurfaceFileFact[]>()
266
603
  const rootFiles: SurfaceFileFact[] = []
@@ -273,31 +610,46 @@ function renderSection6(facts: BriefFacts): string {
273
610
  list.push(f)
274
611
  byPackage.set(f.packageName, list)
275
612
  }
276
-
277
- const parts: string[] = []
278
- let n = 1
279
- for (const [pkg, files] of byPackage) {
280
- parts.push(
281
- [
282
- `${n}. **Part ${n}:** ${facts.rationale.boundary}`,
283
- '',
284
- ' Files:',
285
- ...files.map((f) => ` - ${f.path}`),
286
- '',
287
- ` Touches ${pkg}. The pre-push hook runs the affected suite on your one push and refuses it on failure — do not run it yourself per Part.`
288
- ].join('\n')
289
- )
290
- n++
291
- }
292
- if (rootFiles.length > 0) {
293
- parts.push(
294
- [`${n}. **Part ${n}:** doctrine/root files.`, '', ' Files:', ...rootFiles.map((f) => ` - ${f.path}`)].join(
295
- '\n'
296
- )
297
- )
298
- }
299
-
300
- return ['## 6. Numbered parts — commit after EACH part; push once, before opening the PR', '', ...parts].join('\n')
613
+ const groups: Array<{ pkg: string; files: SurfaceFileFact[] }> = [...byPackage].map(([pkg, files]) => ({
614
+ pkg,
615
+ files
616
+ }))
617
+ if (rootFiles.length > 0) groups.push({ pkg: 'the repo root', files: rootFiles })
618
+
619
+ const section4Text = renderSection4(facts)
620
+ const needsDefeatCases = RENDER_CHECK_NAME_RE.test(section4Text) || RENDER_FORGE_WRITE_COMMAND_RE.test(section4Text)
621
+
622
+ const rendered = facts.parts.map((part, i) => {
623
+ const group = i < groups.length ? groups[i] : undefined
624
+ // Every group beyond the last Part attaches to that last Part, rather
625
+ // than being silently dropped.
626
+ const extraGroups = i === facts.parts.length - 1 ? groups.slice(facts.parts.length) : []
627
+ const allGroups = group ? [group, ...extraGroups] : extraGroups
628
+ const fileLines = allGroups.flatMap((g) => [
629
+ '',
630
+ ` Files (touches ${g.pkg}):`,
631
+ ...g.files.map((f) => ` - ${f.path}`)
632
+ ])
633
+ const lines = [
634
+ `${part.n}. **${renderPartCitation(part)}:** ${part.text}`,
635
+ ...fileLines,
636
+ ...(fileLines.length > 0
637
+ ? [
638
+ '',
639
+ ' The pre-push hook runs the affected suite on your one push and refuses it on failure — do not run it yourself per Part.'
640
+ ]
641
+ : []),
642
+ ...(i === facts.parts.length - 1 && needsDefeatCases
643
+ ? [
644
+ '',
645
+ " **Defeat cases:** — see this Part's outcome text above, and the Traps to avoid field, for the inputs that would defeat the check(s)/command(s) named in §4."
646
+ ]
647
+ : [])
648
+ ]
649
+ return lines.join('\n')
650
+ })
651
+
652
+ return ['## 6. Numbered parts — commit after EACH part; push once, before opening the PR', '', ...rendered].join('\n')
301
653
  }
302
654
 
303
655
  function renderSection7(section7Pointers: string[]): string {
@@ -328,9 +680,38 @@ function renderSection8(): string {
328
680
  ].join('\n')
329
681
  }
330
682
 
683
+ /**
684
+ * A fence marker guaranteed not to be broken by `lines`' own content — one
685
+ * backtick longer than the longest run of consecutive backticks any line
686
+ * contains, minimum three (CommonMark's own floor for a fenced block).
687
+ *
688
+ * `facts.testPlan.lines` is Issue-body text (`parseIssueTestPlan`), not
689
+ * this renderer's own literal — the Issue's `## Test plan` section can
690
+ * itself be fenced with a LONGER backtick run than three (` ```` ` around a
691
+ * body containing a literal ` ``` `), which `extractFencedBlocks` reads as
692
+ * ordinary content, not a nested fence. Splicing that content between a
693
+ * *fixed* ` ``` ` here would let the embedded run close this section's own
694
+ * fence early, spilling the rest of the Issue's text out as unfenced
695
+ * prose in the rendered brief — found live reviewing this exact task.
696
+ */
697
+ function safeFence(lines: string[]): string {
698
+ let longest = 0
699
+ for (const line of lines) {
700
+ const m = line.match(/`+/g)
701
+ if (!m) continue
702
+ for (const run of m) longest = Math.max(longest, run.length)
703
+ }
704
+ return '`'.repeat(Math.max(3, longest + 1))
705
+ }
706
+
707
+ /**
708
+ * §9 — copied from the Issue's own `## Test plan` section (`facts.testPlan`),
709
+ * never re-derived from the surface file list. `renderBrief`'s missing-fact
710
+ * check refuses before this runs when the Issue carries no parseable Test
711
+ * plan, so by the time this executes `facts.testPlan` is real.
712
+ */
331
713
  function renderSection9(facts: BriefFacts): string {
332
- const runtimeFiles = facts.surfaceFiles.filter((f) => !isDocFile(f.path))
333
- if (runtimeFiles.length === 0) {
714
+ if (facts.testPlan.kind === 'unit-tests-only') {
334
715
  // Deliberately unbolded: `locateTestPlanSection`'s heading-form slicer
335
716
  // treats a bold `**Field:**`-shaped line as the START of the NEXT
336
717
  // section (`NEXT_SECTION_RE`) — a bolded `**Test Plan:** unit-tests-only`
@@ -341,29 +722,27 @@ function renderSection9(facts: BriefFacts): string {
341
722
  return ['## 9. Test Plan', '', 'Test Plan: unit-tests-only'].join('\n')
342
723
  }
343
724
 
344
- const testFiles = runtimeFiles.filter((f) => isTestFile(f.path))
345
- const commandLines =
346
- testFiles.length > 0
347
- ? testFiles.map((f) => `bun test ${f.path} → 0 fail`)
348
- : ['bunx turbo test --affected --force → summary line ends "0 fail"']
349
-
350
- const observationText = [
351
- facts.rationale.boundary ?? '',
352
- facts.rationale.trapsToAvoid ?? '',
353
- facts.rationale.stopAndEscalate ?? ''
725
+ const principalLines = facts.testPlan.principal.map((p) => `- [ ] **[principal]** ${p}`)
726
+ const fence = safeFence(facts.testPlan.lines)
727
+ return [
728
+ '## 9. Test Plan',
729
+ '',
730
+ fence,
731
+ ...facts.testPlan.lines,
732
+ fence,
733
+ ...(principalLines.length > 0 ? ['', ...principalLines] : [])
354
734
  ].join('\n')
355
- const principalLine = PRINCIPAL_OBSERVATION_RE.test(observationText)
356
- ? [
357
- '',
358
- "- [ ] **[principal]** Verify the change described in this task's rationale in a real signed-in session/browser."
359
- ]
360
- : []
361
-
362
- return ['## 9. Test Plan', '', '```', ...commandLines, '```', ...principalLine].join('\n')
363
735
  }
364
736
 
737
+ /** §10 — the Issue's own `## Stop conditions` bullets, followed by the rationale's Stop-and-escalate field, never the field alone. */
365
738
  function renderSection10(facts: BriefFacts): string {
366
- return ['## 10. Stop conditions', '', `${facts.rationale.stopAndEscalate}`].join('\n')
739
+ return [
740
+ '## 10. Stop conditions',
741
+ '',
742
+ ...facts.stopConditions.map((c) => `- ${c}`),
743
+ '',
744
+ `${facts.rationale.stopAndEscalate}`
745
+ ].join('\n')
367
746
  }
368
747
 
369
748
  function renderSection11(template: string, facts: BriefFacts): string {
@@ -383,10 +762,11 @@ function renderSection11(template: string, facts: BriefFacts): string {
383
762
  }
384
763
 
385
764
  function renderSection12(facts: BriefFacts): string {
765
+ const prTitle = facts.trancheSlug !== null ? `[${facts.trancheSlug}] ${facts.taskId} — ${facts.title}` : facts.title
386
766
  return [
387
767
  '## 12. Deliverable',
388
768
  '',
389
- `- PR title (exact): \`[${facts.trancheSlug}] ${facts.taskId} — ${facts.title}\``,
769
+ `- PR title (exact): \`${prTitle}\``,
390
770
  '- Open the PR only via `bun apps/cli/src/index.ts pr create --body-file <path> --title "<title above>"`.',
391
771
  "- PR body = the Developer's PR report (start from `aeg-root/templates/pr-report-template.md`), with this entire brief pasted as the reference copy inside a collapsed `<details>` block, and `Closes #" +
392
772
  facts.issue +
@@ -405,40 +785,119 @@ function renderSection12(facts: BriefFacts): string {
405
785
  * never copied from a hardcoded template string in this module.
406
786
  *
407
787
  * Refuses — `{ ok: false, missing }` — the moment a fact this renderer needs
408
- * is absent: never a default, per Issue #387's rule that a brief states no
788
+ * is absent: never a default, per this rule that a brief states no
409
789
  * fact it did not actually derive.
410
790
  */
411
791
  export function renderBrief(facts: BriefFacts, template: string): RenderResult {
412
792
  const missing: string[] = []
413
793
 
414
794
  if (facts.projects.length === 0) missing.push('Project (task has no Project(s) declared)')
795
+ if (!facts.sourceRevision) {
796
+ missing.push(
797
+ 'Revision (no source revision resolved — the caller must refuse before render, never render with an empty one)'
798
+ )
799
+ }
800
+ // Grandfathered the same as the Issue gate itself (`checkIssueObjectives`):
801
+ // an Issue below `OBJECTIVES_SINCE_ISSUE` legitimately has no `## Objectives`
802
+ // section, and the renderer must not newly refuse a class of Issue every
803
+ // other consumer in this task already exempts.
804
+ if (facts.objectives.length === 0 && facts.issue >= OBJECTIVES_SINCE_ISSUE) {
805
+ missing.push('Objectives (Issue has no `## Objectives` section)')
806
+ }
807
+ // Same grandfather posture as Objectives, not the four judgment sections
808
+ // below: no sufficiently old Issue ever carried a `## Documentation`
809
+ // heading, so the renderer must not newly refuse that whole stock.
810
+ // `{ kind: 'sources', sources: [] }` is the absent-section sentinel;
811
+ // `{ kind: 'none' }` is a real, valid opt-out and never reaches this branch.
812
+ if (
813
+ facts.documentation.kind === 'sources' &&
814
+ facts.documentation.sources.length === 0 &&
815
+ facts.issue >= DOCUMENTATION_SINCE_ISSUE
816
+ ) {
817
+ missing.push('Documentation (Issue has no `## Documentation` section)')
818
+ }
819
+ // The four judgment sections are NOT
820
+ // grandfathered by `BRIEF_SECTIONS_SINCE_ISSUE` here, unlike Objectives
821
+ // above: a brief genuinely needs §4's Out of surface, §6's Parts, §9's
822
+ // Test plan and §10's Stop conditions to render regardless of which Issue
823
+ // number the gate itself would exempt — the cutover governs when the
824
+ // ISSUE CREATION gate starts requiring the section, not whether a brief
825
+ // can be rendered without one. The message names the cutover so a
826
+ // pre-cutover Issue reads this as "add the section", not as a gate bug.
827
+ const cutoverNote = `the Issue predates the \`## Surface\`/\`## Parts\`/\`## Test plan\`/\`## Stop conditions\` gate cutover at #${BRIEF_SECTIONS_SINCE_ISSUE}, but a brief still needs it to render`
828
+ if (facts.surface.in.length === 0) {
829
+ missing.push(`Surface (Issue has no \`## Surface\` section with a non-empty \`in:\` list — ${cutoverNote})`)
830
+ }
831
+ if (facts.parts.length === 0) {
832
+ missing.push(`Parts (Issue has no \`## Parts\` section with well-formed Part lines — ${cutoverNote})`)
833
+ }
834
+ if (
835
+ facts.testPlan.kind === 'commands' &&
836
+ facts.testPlan.lines.length === 0 &&
837
+ facts.testPlan.principal.length === 0
838
+ ) {
839
+ missing.push(`Test plan (Issue has no \`## Test plan\` section — ${cutoverNote})`)
840
+ }
841
+ if (facts.stopConditions.length === 0) {
842
+ missing.push(`Stop conditions (Issue has no \`## Stop conditions\` section with bullet items — ${cutoverNote})`)
843
+ }
415
844
  if (!facts.dispatchReady) missing.push(...facts.dispatchBlockers)
416
845
 
417
846
  for (const key of Object.keys(RATIONALE_FIELD_PATTERNS) as RationaleFieldKey[]) {
418
847
  if (!facts.rationale[key]) missing.push(RATIONALE_FIELD_NAMES[key])
419
848
  }
420
849
 
850
+ // O2/O3: the surface map lists only what `## Surface`
851
+ // admits. When the Boundary named files but the Issue's own Surface admits
852
+ // none of them, that is the Boundary and Surface genuinely disagreeing —
853
+ // refuse at render (naming it) rather than dispatch a brief whose surface
854
+ // map would be empty, or whose Modify list would argue with its own
855
+ // Out-of-surface line.
856
+ const filteredSurfaceFiles = admittedSurfaceFiles(facts.surfaceFiles, facts.surface)
857
+ if (facts.surface.in.length > 0 && facts.surfaceFiles.length > 0 && filteredSurfaceFiles.length === 0) {
858
+ missing.push(
859
+ "Surface map (every file the Boundary named is excluded by the Issue's own `## Surface` `in:`/`out:` globs — Boundary and Surface disagree; fix the Issue rather than render an empty surface map)"
860
+ )
861
+ } else if (facts.surface.in.length > 0 && filteredSurfaceFiles.filter((f) => f.sha256 !== null).length === 0) {
862
+ // issue-657, O3 — the caller already guarantees every `## Surface` `in:`
863
+ // glob resolves to at least one real tracked file before `renderBrief`
864
+ // is ever called; if nothing the Boundary named survives to a premise
865
+ // pin (nothing was named at all, or every named file is a not-yet-
866
+ // created "Create" entry with no sha256 to pin), refuse naming the
867
+ // surface rather than render an empty `**Premise:**` block the brief's
868
+ // own `checkBriefSections` validator then rejects.
869
+ missing.push(
870
+ `Premise pins (the Issue's \`## Surface\` \`in:\` — ${facts.surface.in.join(', ')} — resolves to at least one tracked file, but the Boundary names none of them to pin; name a real in-scope file in the Boundary rationale)`
871
+ )
872
+ }
873
+
421
874
  if (missing.length > 0) return { ok: false, missing }
422
875
 
876
+ const scopedFacts: BriefFacts = { ...facts, surfaceFiles: filteredSurfaceFiles }
877
+
423
878
  const section7Pointers = facts.docOwnersContent
424
879
  ? deriveSection7Pointers(
425
- facts.surfaceFiles.map((f) => f.path),
880
+ filteredSurfaceFiles.map((f) => f.path),
426
881
  facts.docOwnersContent
427
882
  )
428
883
  : []
429
884
 
430
885
  const brief = [
431
- renderHeader(facts, template),
886
+ renderHeader(scopedFacts, template),
432
887
  '',
888
+ ...(facts.objectives.length > 0 ? [renderObjectives(facts.objectives), ''] : []),
889
+ ...(facts.documentation.kind === 'none' || facts.documentation.sources.length > 0
890
+ ? [renderDocumentation(facts.documentation), '']
891
+ : []),
433
892
  renderSection2(facts),
434
893
  '',
435
894
  renderSection3(facts),
436
895
  '',
437
- renderSection4(facts),
896
+ renderSection4(scopedFacts),
438
897
  '',
439
898
  renderSection5(facts),
440
899
  '',
441
- renderSection6(facts),
900
+ renderSection6(scopedFacts),
442
901
  '',
443
902
  renderSection7(section7Pointers),
444
903
  '',