@attalabs/vinaya 0.39.0 → 0.41.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 (186) hide show
  1. package/README.md +9 -9
  2. package/aeg-root/contracts/developer-reviewer.md +2 -2
  3. package/aeg-root/contracts/planner-developer.md +5 -5
  4. package/aeg-root/enforcement.md +22 -22
  5. package/aeg-root/process.md +4 -4
  6. package/aeg-root/roles/archivist.md +1 -1
  7. package/aeg-root/roles/developer/reference.md +7 -1
  8. package/aeg-root/roles/developer.md +1 -1
  9. package/aeg-root/roles/planner/reference.md +18 -5
  10. package/aeg-root/roles/principal.md +1 -1
  11. package/aeg-root/roles/reviewer.md +3 -3
  12. package/aeg-root/roles/security.md +4 -4
  13. package/aeg-root/roles/tranche-archivist.md +2 -2
  14. package/aeg-root/skills/aeg/SKILL.md +1 -1
  15. package/aeg-root/state-machine.md +10 -15
  16. package/aeg-root/templates/brief-template.md +5 -2
  17. package/aeg-root/templates/decision-record-template.md +38 -0
  18. package/aeg-root/templates/issue-rationale-template.md +1 -1
  19. package/aeg-root/tranche-model.md +1 -1
  20. package/dist/checks/bin/check-body-bare-digits.js +1974 -354
  21. package/dist/checks/bin/check-branch-topology.js +1296 -243
  22. package/dist/checks/bin/check-brief-shape.js +2038 -460
  23. package/dist/checks/bin/check-changeset-coverage.js +2411 -564
  24. package/dist/checks/bin/check-ci-shard-coverage.js +12391 -15
  25. package/dist/checks/bin/check-closes-n.js +1296 -243
  26. package/dist/checks/bin/check-coherence.js +1914 -1155
  27. package/dist/checks/bin/check-dead-branch-push.js +1242 -230
  28. package/dist/checks/bin/check-dispatch-readiness.js +2222 -460
  29. package/dist/checks/bin/check-doc-claims.js +2233 -260
  30. package/dist/checks/bin/check-doc-coverage-push.js +2436 -550
  31. package/dist/checks/bin/check-doc-coverage.js +2434 -552
  32. package/dist/checks/bin/check-doctrine-no-procedures.js +1776 -353
  33. package/dist/checks/bin/check-doctrine-portability.js +2408 -561
  34. package/dist/checks/bin/check-evidence-fresh.js +2370 -508
  35. package/dist/checks/bin/check-exec-bits.js +2407 -560
  36. package/dist/checks/bin/check-first-push-dispatch.js +1984 -380
  37. package/dist/checks/bin/check-issue-assignment.js +712 -170
  38. package/dist/checks/bin/check-issue-milestone-attach.js +1233 -230
  39. package/dist/checks/bin/check-issue-objectives-numbering.js +1769 -346
  40. package/dist/checks/bin/check-issue-parts-coverage.js +1233 -230
  41. package/dist/checks/bin/check-issue-surface-globs.js +1926 -378
  42. package/dist/checks/bin/check-issue-title-grammar.js +1233 -230
  43. package/dist/checks/bin/check-issue-tranche-label.js +702 -170
  44. package/dist/checks/bin/check-main-branch-refusal.js +1245 -232
  45. package/dist/checks/bin/check-no-disk-state.js +1233 -230
  46. package/dist/checks/bin/check-pr-premise-reassert.js +1769 -346
  47. package/dist/checks/bin/check-pr-report-density.js +1233 -230
  48. package/dist/checks/bin/check-principal-test-plan-wait.js +2489 -259
  49. package/dist/checks/bin/check-quoted-command.js +2391 -544
  50. package/dist/checks/bin/check-reader-resolvable-prose.js +2437 -564
  51. package/dist/checks/bin/check-registry-gates.js +1380 -296
  52. package/dist/checks/bin/check-retired-vocabulary.js +2416 -550
  53. package/dist/checks/bin/check-review-gate.js +2073 -371
  54. package/dist/checks/bin/check-single-plan-pr.js +1297 -235
  55. package/dist/checks/bin/check-surface-scope.js +1531 -252
  56. package/dist/checks/bin/check-test-plan.js +2487 -258
  57. package/dist/checks/bin/check-token-collection-wired.js +1233 -230
  58. package/dist/checks/bin/check-workspace-escape.js +2408 -561
  59. package/dist/checks/bin/verify-coherence.js +597 -97
  60. package/dist/checks/bin/verify-dispatch.js +632 -152
  61. package/dist/checks/bin/verify-docs.js +642 -132
  62. package/dist/index.js +25948 -16630
  63. package/dist/lib/pre-push-cache-test-run.js +1813 -297
  64. package/dist/lib/pre-push-changed-files.js +65 -19
  65. package/dist/lib/pre-push-mode.js +466 -0
  66. package/dist/lib/pre-push-progress-dir.js +4205 -0
  67. package/dist/lib/pre-push-record-tests.js +446 -0
  68. package/dist/lib/pre-push-select-tests.js +2353 -632
  69. package/dist/lib/push-progress-observer.js +4213 -0
  70. package/package.json +22 -5
  71. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/anchored-region.ts +17 -3
  72. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/brief-render.ts +73 -30
  73. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/brief-validation.ts +3 -3
  74. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/coherence-checks.ts +2 -2
  75. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/control-store/local.ts +88 -5
  76. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/control-store/records.ts +34 -2
  77. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/assess-round.ts +26 -4
  78. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/fakes.ts +7 -2
  79. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/index.ts +7 -1
  80. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/types.ts +29 -3
  81. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dispatch-gate.ts +35 -18
  82. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/docs/index.ts +1 -1
  83. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/docs/published-prose.ts +70 -45
  84. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/doctrine-portability.ts +6 -1
  85. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/entry-point.ts +27 -0
  86. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/gate-audience.ts +3 -5
  87. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/index.ts +96 -9
  88. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/issue-assignment.ts +24 -54
  89. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/issue-validation.ts +809 -106
  90. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/live-record.ts +179 -0
  91. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/envelope.ts +8 -2
  92. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/index.ts +1 -0
  93. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/narration.ts +2 -0
  94. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/schema-digest.ts +225 -0
  95. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/schema.ts +7 -1
  96. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/main-branch-refusal.ts +23 -1
  97. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/pr-report-density.ts +6 -4
  98. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/principals-config.ts +44 -0
  99. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/prose-rules.ts +532 -0
  100. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/protected-paths.ts +31 -0
  101. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/reader-resolvable-prose.ts +157 -80
  102. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/registry-checks.ts +8 -12
  103. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/retired-vocabulary.ts +53 -93
  104. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-gate.ts +46 -17
  105. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-input-manifest.ts +85 -1
  106. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-policy.ts +32 -13
  107. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/ruling-ordinal.ts +46 -0
  108. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/task-branch-identity.ts +2 -4
  109. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/test-plan-gate.ts +63 -8
  110. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/verdict-extraction.ts +24 -0
  111. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/waiver-label.ts +0 -1
  112. package/studio-standalone/apps/vinaya-studio/web/.next/BUILD_ID +1 -1
  113. package/studio-standalone/apps/vinaya-studio/web/.next/build-manifest.json +3 -3
  114. package/studio-standalone/apps/vinaya-studio/web/.next/prerender-manifest.json +3 -3
  115. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.html +1 -1
  116. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.rsc +1 -1
  117. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
  118. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  119. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  120. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  121. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  122. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page/server-reference-manifest.json +2 -2
  123. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page.js.nft.json +1 -1
  124. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  125. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page/server-reference-manifest.json +2 -2
  126. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page.js.nft.json +1 -1
  127. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page_client-reference-manifest.js +1 -1
  128. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page/server-reference-manifest.json +2 -2
  129. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page.js +1 -1
  130. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page.js.nft.json +1 -1
  131. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page_client-reference-manifest.js +1 -1
  132. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page/server-reference-manifest.json +2 -2
  133. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page.js +1 -1
  134. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page.js.nft.json +1 -1
  135. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page_client-reference-manifest.js +1 -1
  136. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page/server-reference-manifest.json +2 -2
  137. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page.js +1 -1
  138. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page.js.nft.json +1 -1
  139. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page_client-reference-manifest.js +1 -1
  140. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page/server-reference-manifest.json +3 -3
  141. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page.js +1 -1
  142. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page.js.nft.json +1 -1
  143. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page_client-reference-manifest.js +1 -1
  144. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page/server-reference-manifest.json +2 -2
  145. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page.js +2 -2
  146. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page.js.nft.json +1 -1
  147. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page_client-reference-manifest.js +1 -1
  148. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page/server-reference-manifest.json +2 -2
  149. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page.js +1 -1
  150. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page.js.nft.json +1 -1
  151. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page_client-reference-manifest.js +1 -1
  152. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page/server-reference-manifest.json +2 -2
  153. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page.js +1 -1
  154. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page.js.nft.json +1 -1
  155. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page_client-reference-manifest.js +1 -1
  156. 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
  157. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__08e39jo._.js +1 -1
  158. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__0ls23oh._.js +1 -1
  159. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__0sxadt2._.js +13 -0
  160. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1a3j3n1._.js +57 -0
  161. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/{[root-of-the-server]__1ug9syi._.js → [root-of-the-server]__1d4eth3._.js} +1 -1
  162. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1gjqmhq._.js +1 -1
  163. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1snpgaw._.js +3 -3
  164. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1wc4-ip._.js +1 -1
  165. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_08onyya._.js +2 -2
  166. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_096f46i._.js +1 -1
  167. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0af2one._.js +1 -1
  168. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0e5tkdd._.js +1 -1
  169. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0kf2g72._.js +1 -1
  170. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0zf4d27._.js +3 -3
  171. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_1-wo68i._.js +1 -1
  172. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_1achbh9._.js +1 -1
  173. 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
  174. package/studio-standalone/apps/vinaya-studio/web/.next/server/middleware-build-manifest.js +3 -3
  175. package/studio-standalone/apps/vinaya-studio/web/.next/server/pages/500.html +1 -1
  176. package/studio-standalone/apps/vinaya-studio/web/.next/server/server-reference-manifest.js +1 -1
  177. package/studio-standalone/apps/vinaya-studio/web/.next/server/server-reference-manifest.json +4 -4
  178. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{33rszkngkuoko.js → 0x7u6si-ai179.js} +1 -1
  179. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{06_55xbp7rcbi.js → 2fu7mfsj4oima.js} +1 -1
  180. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{2brkwv169ygep.js → 34b4ruddunn3q.js} +1 -1
  181. package/studio-standalone/apps/vinaya-studio/web/package.json +2 -2
  182. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__04adkz-._.js +0 -57
  183. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__19jyp3m._.js +0 -13
  184. /package/studio-standalone/apps/vinaya-studio/web/.next/static/{D3LiJNIq5FWZxen7CpOSJ → 2ZARxTwpuRew8-SvYsRdU}/_buildManifest.js +0 -0
  185. /package/studio-standalone/apps/vinaya-studio/web/.next/static/{D3LiJNIq5FWZxen7CpOSJ → 2ZARxTwpuRew8-SvYsRdU}/_clientMiddlewareManifest.js +0 -0
  186. /package/studio-standalone/apps/vinaya-studio/web/.next/static/{D3LiJNIq5FWZxen7CpOSJ → 2ZARxTwpuRew8-SvYsRdU}/_ssgManifest.js +0 -0
@@ -27,12 +27,14 @@ import {
27
27
  SECTION_HEADER,
28
28
  splitSlugQualifiedEdge
29
29
  } from '@attalabs/aeg-forge-state'
30
- import { stripCode } from './anchored-region'
30
+ import { maskCode } from '@attalabs/aeg-forge-state/strip-code'
31
+ import { anchoredRegion, anchoredRegionBounds, stripCode } from './anchored-region'
31
32
  import { checkTestPlan, extractFencedBlocks } from './brief-validation'
32
33
  import { type ClaimBinding, type ClaimVoice, evaluateClaimBindings } from './doc-claim'
33
34
  import { DOC_OWNERS_PATH, isUrlPointer, parseDocOwners, pointerToPath } from './doc-owners'
34
35
  import { globsOverlap } from './derive-section7'
35
36
  import { objectivesOf, objectivesVersion } from './objectives'
37
+ import { isProtectedAdminPath, normalizeTouchedPath } from './protected-paths'
36
38
  import { isValidCitedFilePath } from './quoted-command'
37
39
  import { locateTestPlanSection } from './test-plan-section'
38
40
 
@@ -69,10 +71,37 @@ const RATIONALE_FIELDS: Array<{ name: string; pattern: string }> = [
69
71
 
70
72
  const DEPENDENCY_RATIONALE_FIELD_NAME = 'Dependency rationale'
71
73
 
74
+ /**
75
+ * The three fields a single-fix Issue — one with no tranche label — may omit.
76
+ * Each is tranche prose no gate checks and the render does not need: sizing
77
+ * against sibling tasks, a blast-radius narrative (the blast-radius gate reads
78
+ * the `**Project:**` field and the Surface instead), and the edges to siblings
79
+ * a single fix does not have. Every other field stays required: the render
80
+ * reads the Boundary, the Traps, the Suggested agent-class and the
81
+ * Stop-and-escalate, and `checkRationaleNamesDocs` reads Docs to keep coherent.
82
+ */
83
+ const SINGLE_FIX_OPTIONAL_FIELDS: ReadonlySet<string> = new Set([
84
+ 'Sizing',
85
+ 'Project(s) + blast radius',
86
+ DEPENDENCY_RATIONALE_FIELD_NAME
87
+ ])
88
+
89
+ export type IssueRationaleOptions = {
90
+ /**
91
+ * The Issue is a single fix — its labels carry no `vinaya/tranche:<slug>`.
92
+ * The caller decides from the labels, exactly as it decides whether the
93
+ * check applies at all. Defaults to `false`: the full eight-field form.
94
+ */
95
+ singleFix?: boolean
96
+ }
97
+
72
98
  /**
73
99
  * Every one of the eight Planner's-rationale fields must be present in a task
74
100
  * Issue's body. One error line per missing field, mirroring
75
- * `checkBriefSections`'s error style.
101
+ * `checkBriefSections`'s error style. With `singleFix`, the three fields in
102
+ * `SINGLE_FIX_OPTIONAL_FIELDS` may be absent; one that is present is still
103
+ * graded, so a single-fix Issue that declares edges declares them in the form
104
+ * amend-deps can edit.
76
105
  *
77
106
  * `Dependency rationale` carries a second, stricter requirement the other
78
107
  * seven fields do not: `amendRationaleDeps` (`@attalabs/aeg-forge-state`, the ONLY
@@ -84,12 +113,16 @@ const DEPENDENCY_RATIONALE_FIELD_NAME = 'Dependency rationale'
84
113
  * on the only sanctioned edit path. Importing `SECTION_HEADER` rather than a
85
114
  * second hand-written regex keeps this one grammar.
86
115
  */
87
- export function checkIssueRationale(body: string): IssueSectionResult {
116
+ export function checkIssueRationale(body: string, options: IssueRationaleOptions = {}): IssueSectionResult {
117
+ const singleFix = options.singleFix === true
88
118
  const errors: string[] = []
89
119
  for (const f of RATIONALE_FIELDS) {
90
120
  if (!hasRationaleField(body, f.pattern)) {
121
+ if (singleFix && SINGLE_FIX_OPTIONAL_FIELDS.has(f.name)) continue
91
122
  errors.push(
92
- `issue-validation ${f.name}: rationale field not found in the Issue body — every task Issue carries the full Planner's rationale (aeg-root/contracts/planner-brief.md).`
123
+ singleFix
124
+ ? `issue-validation ${f.name}: rationale field not found in the Issue body — a single-fix Issue carries every Planner's-rationale field except Sizing, Project(s) + blast radius and Dependency rationale (aeg-root/templates/issue-rationale-template.md).`
125
+ : `issue-validation ${f.name}: rationale field not found in the Issue body — every task Issue carries the full Planner's rationale (aeg-root/contracts/planner-brief.md).`
93
126
  )
94
127
  continue
95
128
  }
@@ -262,7 +295,16 @@ function splitGlobList(raw: string): string[] {
262
295
 
263
296
  export type IssueSurface = { in: string[]; out: string[] }
264
297
  export type IssuePart = { n: number; objectiveIds: number[]; text: string }
265
- export type IssueTestPlan = { kind: 'unit-tests-only' } | { kind: 'commands'; lines: string[]; principal: string[] }
298
+ /**
299
+ * A `## Test plan`'s three kinds of check: `lines`, the fenced commands the
300
+ * Developer runs; `principal`, the items only a person can judge; and
301
+ * `live`, the commands that need real signed-in agent sessions and that the
302
+ * review loop runs itself, on its own host, only on a head both reviewers
303
+ * approved.
304
+ */
305
+ export type IssueTestPlan =
306
+ | { kind: 'unit-tests-only' }
307
+ | { kind: 'commands'; lines: string[]; principal: string[]; live: string[] }
266
308
 
267
309
  type ParsedIssueSection<T> = { ok: true; value: T } | { ok: false; errors: string[] }
268
310
 
@@ -324,14 +366,13 @@ export function globCoversPath(glob: string, path: string): boolean {
324
366
 
325
367
  /**
326
368
  * **O1 — a declared Surface glob must resolve.** Every `## Surface` `in:`
327
- * glob must match at least one real tracked file, or a Surface that cannot
328
- * render a file list is caught at authoring time instead of at dispatch
329
- * (`brief-assembly.ts`'s own render-time sanity check, which currently
330
- * catches the identical defect too late). `resolvesToFile` is injected —
331
- * this module stays pure, no `git`/`fs` — and the caller
369
+ * glob must either match a real tracked file or contain a file pinned by the
370
+ * Boundary. The latter permits a task to create a new directory while still
371
+ * refusing a typo'd or otherwise empty Surface entry. `resolvesToFile` is
372
+ * injected — this module stays pure, no `git`/`fs` — and the caller
332
373
  * (`forge-write.ts`) passes the SAME `expandGlob` predicate
333
- * `brief-assembly.ts` already uses to render, so the gate and the renderer
334
- * can never disagree about whether a glob resolves.
374
+ * `brief-assembly.ts` uses alongside `boundaryPinnedFiles`, so the gate and
375
+ * both render paths share this resolution rule.
335
376
  *
336
377
  * A backtick-wrapped glob (`` `packages/foo/**` ``) is not stripped or
337
378
  * specially refused here: the literal backticks are part of the string
@@ -343,12 +384,23 @@ export function globCoversPath(glob: string, path: string): boolean {
343
384
  * does not yet exist (a directory not yet created) is a legitimate
344
385
  * exclusion, not a defect.
345
386
  */
387
+ export function surfaceEntryResolves(
388
+ entry: string,
389
+ resolvesToFile: (glob: string) => boolean,
390
+ pinnedFiles: readonly string[]
391
+ ): boolean {
392
+ if (resolvesToFile(entry)) return true
393
+ const directory = entry.replace(/\/\*\*?$/, '').replace(/\/+$/, '')
394
+ return pinnedFiles.some((path) => path.startsWith(`${directory}/`))
395
+ }
396
+
346
397
  export function checkSurfaceGlobsResolve(body: string, resolvesToFile: (glob: string) => boolean): IssueSectionResult {
347
398
  const surface = parseIssueSurface(body)
348
399
  if (!surface.ok) return { status: 'pass', errors: [] }
400
+ const pinnedFiles = boundaryPinnedFiles(body)
349
401
  const errors: string[] = []
350
402
  for (const glob of surface.value.in) {
351
- if (!resolvesToFile(glob)) {
403
+ if (!surfaceEntryResolves(glob, resolvesToFile, pinnedFiles)) {
352
404
  errors.push(
353
405
  `issue-validation Surface: \`${glob}\` in \`## Surface\`'s \`in:\` list matches no tracked file — a Surface that cannot resolve cannot render a brief's file list.`
354
406
  )
@@ -357,33 +409,135 @@ export function checkSurfaceGlobsResolve(body: string, resolvesToFile: (glob: st
357
409
  return { status: errors.length > 0 ? 'fail' : 'pass', errors }
358
410
  }
359
411
 
360
- export type SurfaceScopeViolation = { file: string; glob: string }
361
- export type SurfaceScopeResult = { ok: true } | { ok: false; violations: SurfaceScopeViolation[] }
412
+ /**
413
+ * One changed path the task's `## Surface` does not cover: it crosses an
414
+ * `out:` glob (`glob` names it — the stronger signal, decided first), or it
415
+ * matches no `in:` glob (`glob` is `null`).
416
+ */
417
+ export type BeyondSurfacePath =
418
+ | { path: string; reason: 'out'; glob: string }
419
+ | { path: string; reason: 'in'; glob: null }
420
+
421
+ /**
422
+ * Every path in `changedPaths` the Surface does not cover, in input order —
423
+ * the one measurement the review loop's publication records in the pull
424
+ * request body and the `surface-scope` check compares that record against.
425
+ * An `in:` list with no globs covers everything, so only `out:` crossings
426
+ * count then. Uses the SAME `globCoversPath` every other Surface reader here
427
+ * uses. Pure.
428
+ */
429
+ export function beyondSurfacePaths(
430
+ changedPaths: readonly string[],
431
+ surface: Pick<IssueSurface, 'in' | 'out'>
432
+ ): BeyondSurfacePath[] {
433
+ const beyond: BeyondSurfacePath[] = []
434
+ for (const path of changedPaths) {
435
+ const glob = surface.out.find((g) => globCoversPath(g, path))
436
+ if (glob !== undefined) beyond.push({ path, reason: 'out', glob })
437
+ else if (surface.in.length > 0 && !surface.in.some((g) => globCoversPath(g, path)))
438
+ beyond.push({ path, reason: 'in', glob: null })
439
+ }
440
+ return beyond
441
+ }
442
+
443
+ /** The block's lead line, written only when the block lists a path. */
444
+ const BEYOND_SURFACE_LEAD =
445
+ '**Beyond the Surface** — recorded by the review-loop driver on every body write; never edit it:'
446
+
447
+ /** One recorded path's line — the path first, in a code span, so the reader below can recover it and the body's bare-digit rule never sees a digit in it. */
448
+ function beyondSurfaceLine(entry: BeyondSurfacePath): string {
449
+ return entry.reason === 'out'
450
+ ? `- \`${entry.path}\` crosses the \`out:\` glob \`${entry.glob}\``
451
+ : `- \`${entry.path}\` matches no \`in:\` glob`
452
+ }
453
+
454
+ /** The whole marked block — the `AEG:BEYOND-SURFACE` pair around the lead line and one line per entry, or around nothing when there is none. */
455
+ export function renderBeyondSurfaceBlock(entries: readonly BeyondSurfacePath[]): string {
456
+ const inner = entries.length === 0 ? '' : `${[BEYOND_SURFACE_LEAD, ...entries.map(beyondSurfaceLine)].join('\n')}\n`
457
+ return `<!-- AEG:BEYOND-SURFACE:START -->\n${inner}<!-- AEG:BEYOND-SURFACE:END -->`
458
+ }
362
459
 
363
460
  /**
364
- * **O7 — a task-branch PR's changed files must stay inside its Issue's
365
- * declared surface.** `outGlobs` is the Issue's own `## Surface` `out:`
366
- * list (parsed by the caller via `parseIssueSurface`, same reuse discipline
367
- * as everything else here); `changedFiles` is the PR/branch's own diff.
368
- * Every changed file crossing a declared `out:` glob is a violation, naming
369
- * both the file and the glob it crosses — collected in one pass (O12's own
370
- * discipline), never only the first. Uses the SAME `globCoversPath`
371
- * predicate O4/O6 already use to decide whether a Surface glob covers a
372
- * path, so "does this file cross the boundary" can never disagree with how
373
- * the boundary itself is read elsewhere in this module.
374
- *
375
- * Pure: takes the already-resolved file list and glob list, never reads
376
- * disk or the forge itself — the caller (a check-bin adapter) resolves
377
- * both.
461
+ * `body` with its `AEG:BEYOND-SURFACE` block rewritten to list `entries` —
462
+ * only that marked region is replaced, whatever it held. A body with no such
463
+ * block gets one in its `## Scope` section, just before the `AEG:TIER` pair
464
+ * when that pair sits there, else at the section's end; a body with no
465
+ * `## Scope` section gets one appended. Pure.
466
+ */
467
+ export function withBeyondSurfaceBlock(body: string, entries: readonly BeyondSurfacePath[]): string {
468
+ const block = renderBeyondSurfaceBlock(entries)
469
+ const existing = anchoredRegionBounds(body, 'BEYOND-SURFACE')
470
+ if (existing) return body.slice(0, existing.outerStart) + block + body.slice(existing.outerEnd)
471
+ const masked = maskCode(body)
472
+ const scope = /^##[ \t]+Scope[ \t]*$/m.exec(masked)
473
+ if (!scope) return `${body.replace(/\s*$/, '')}\n\n## Scope\n\n${block}\n`
474
+ const sectionStart = scope.index + scope[0].length
475
+ const nextHeading = /^##?[ \t]/m.exec(masked.slice(sectionStart))
476
+ const sectionEnd = nextHeading ? sectionStart + nextHeading.index : body.length
477
+ const tier = anchoredRegionBounds(body, 'TIER')
478
+ if (tier && tier.outerStart >= sectionStart && tier.outerStart < sectionEnd) {
479
+ return `${body.slice(0, tier.outerStart)}${block}\n\n${body.slice(tier.outerStart)}`
480
+ }
481
+ const before = body.slice(0, sectionEnd).replace(/\s*$/, '')
482
+ const after = body.slice(sectionEnd)
483
+ return `${before}\n\n${block}\n${after.length > 0 ? `\n${after}` : ''}`
484
+ }
485
+
486
+ /**
487
+ * The paths the body's `AEG:BEYOND-SURFACE` block lists, or `[]` when the
488
+ * body carries no such block — an absent record lists nothing.
378
489
  */
379
- export function checkSurfaceScope(changedFiles: string[], outGlobs: string[]): SurfaceScopeResult {
380
- if (outGlobs.length === 0) return { ok: true }
381
- const violations: SurfaceScopeViolation[] = []
382
- for (const file of changedFiles) {
383
- const glob = outGlobs.find((g) => globCoversPath(g, file))
384
- if (glob) violations.push({ file, glob })
490
+ export function recordedBeyondSurfacePaths(body: string): string[] {
491
+ const region = anchoredRegion(body, 'BEYOND-SURFACE')
492
+ if (region === null) return []
493
+ const paths: string[] = []
494
+ for (const line of region.split(/\r?\n/)) {
495
+ const m = /^\s*-\s+`([^`]+)`/.exec(line)
496
+ if (m?.[1]) paths.push(m[1])
497
+ }
498
+ return paths
499
+ }
500
+
501
+ /** A changed path that is a protected administrative path no `in:` glob of the Surface covers. */
502
+ export type ProtectedPathViolation = { path: string; reason: 'protected' }
503
+
504
+ export type SurfaceScopeResult =
505
+ | { ok: true }
506
+ | { ok: false; violation: BeyondSurfacePath }
507
+ | { ok: false; violation: ProtectedPathViolation }
508
+
509
+ /**
510
+ * **A task-branch PR's changed files outside its Issue's Surface must be
511
+ * recorded, never hidden.** `changedFiles` is the branch's own diff;
512
+ * `recorded` is the pull request body's `AEG:BEYOND-SURFACE` list. Passes
513
+ * when every changed path beyond the Surface (`beyondSurfacePaths`) is
514
+ * recorded; otherwise fails naming the FIRST changed path that is beyond the
515
+ * Surface and not recorded, with the `out:` glob it crosses or the `in:` list
516
+ * it misses.
517
+ *
518
+ * Decided first, and never excused by the record: a changed path that, once
519
+ * normalized, is a protected administrative path and is covered by no `in:`
520
+ * glob. An empty `in:` list covers no protected path — the broker's rule —
521
+ * unlike `beyondSurfacePaths`, where an empty `in:` covers everything. The
522
+ * `out:` globs play no part, as in the broker.
523
+ *
524
+ * Pure: the caller (a check-bin adapter) resolves every input.
525
+ */
526
+ export function checkSurfaceScope(
527
+ changedFiles: readonly string[],
528
+ surface: Pick<IssueSurface, 'in' | 'out'>,
529
+ recorded: readonly string[]
530
+ ): SurfaceScopeResult {
531
+ for (const path of changedFiles) {
532
+ if (!isProtectedAdminPath(path)) continue
533
+ const normalized = normalizeTouchedPath(path)
534
+ if (!surface.in.some((glob) => globCoversPath(glob, normalized))) {
535
+ return { ok: false, violation: { path, reason: 'protected' } }
536
+ }
385
537
  }
386
- return violations.length > 0 ? { ok: false, violations } : { ok: true }
538
+ const listed = new Set(recorded)
539
+ const violation = beyondSurfacePaths(changedFiles, surface).find((entry) => !listed.has(entry.path))
540
+ return violation ? { ok: false, violation } : { ok: true }
387
541
  }
388
542
 
389
543
  /** One `Part <n> (<refs>) — <outcome>` line, anywhere in the `## Parts` section. */
@@ -466,6 +620,8 @@ export function checkPartsCiteDefinedObjectives(body: string): IssueSectionResul
466
620
  }
467
621
 
468
622
  const ISSUE_PRINCIPAL_LINE_RE = /^-\s*\[[ xX]\]\s*\*{2}\[principal\]\*{2}(.*)$/gim
623
+ /** `- **[live]** <command>` — never a checkbox: a machine judges it, so there is no box for anyone to tick. */
624
+ const ISSUE_LIVE_LINE_RE = /^-\s*\*{2}\[live\]\*{2}(.*)$/gim
469
625
  const UNIT_TESTS_ONLY_SENTINEL_RE = /(?:\*\*)?Test plan(?:\*\*)?\s*:\s*(?:\*\*)?\s*unit-tests-only/i
470
626
 
471
627
  /**
@@ -542,10 +698,33 @@ function isWholeSuiteTestPlanLine(line: string): boolean {
542
698
  return false
543
699
  }
544
700
 
701
+ /** A `[live]` item's command: the item's text, one enclosing code span removed. */
702
+ function liveCommand(text: string): string {
703
+ const trimmed = text.trim()
704
+ const span = /^(`+)(.+)\1$/.exec(trimmed)
705
+ return span ? (span[2] as string).trim() : trimmed
706
+ }
707
+
708
+ function liveItemsIn(region: string): string[] {
709
+ return [...region.matchAll(ISSUE_LIVE_LINE_RE)].map((m) => liveCommand(m[1] ?? '')).filter(Boolean)
710
+ }
711
+
712
+ /**
713
+ * The `[live]` commands of a body's Test plan section — an Issue's
714
+ * `## Test plan` or a rendered brief's `## 9. Test Plan` — in order, `[]`
715
+ * when it has none. Reads those items alone, so the review loop's live check
716
+ * never depends on how the rest of the plan parses.
717
+ */
718
+ export function parseLiveTestPlanItems(body: string): string[] {
719
+ const located = locateTestPlanSection(body)
720
+ return located.found ? liveItemsIn(located.section) : []
721
+ }
722
+
545
723
  /**
546
724
  * `## Test plan` — reuses `checkTestPlan`/`extractFencedBlocks`
547
725
  * (`brief-validation.ts`) rather than a second parser: the `unit-tests-only`
548
- * sentinel, or a fenced command list plus optional `**[principal]**` items.
726
+ * sentinel, or a fenced command list plus optional `**[principal]**` and
727
+ * `**[live]**` items.
549
728
  * The two forms are mutually exclusive, same rule `checkTestPlanExclusivity`
550
729
  * applies to a PR body's Test Plan.
551
730
  */
@@ -589,15 +768,128 @@ export function parseIssueTestPlan(body: string): ParsedIssueSection<IssueTestPl
589
768
  }
590
769
 
591
770
  const principal = [...region.matchAll(ISSUE_PRINCIPAL_LINE_RE)].map((m) => (m[1] ?? '').trim()).filter(Boolean)
592
- if (lines.length === 0 && principal.length === 0) {
771
+ const live = liveItemsIn(region)
772
+ if (lines.length === 0 && principal.length === 0 && live.length === 0) {
593
773
  return {
594
774
  ok: false,
595
775
  errors: [
596
- '`## Test plan` carries neither the `unit-tests-only` sentinel, a fenced command list, nor a `**[principal]**` item.'
776
+ '`## Test plan` carries neither the `unit-tests-only` sentinel, a fenced command list, a `**[principal]**` item, nor a `**[live]**` item.'
597
777
  ]
598
778
  }
599
779
  }
600
- return { ok: true, value: { kind: 'commands', lines, principal } }
780
+ return { ok: true, value: { kind: 'commands', lines, principal, live } }
781
+ }
782
+
783
+ /**
784
+ * The foreign binaries a dispatched Developer cannot run, as the leading
785
+ * tokens of a command statement: no forge credential for `gh`, no push, no
786
+ * shell outside the sandbox. The reference describes this CLI only, so these
787
+ * stay typed; every operation of the CLI itself is judged by the `needs` its
788
+ * command declares in the command reference (`developerUnrunnableCommand`).
789
+ */
790
+ const DEVELOPER_UNRUNNABLE_FOREIGN_PREFIXES: readonly (readonly string[])[] = [
791
+ ['gh', 'pr', 'merge'],
792
+ ['gh', 'pr', 'review'],
793
+ ['git', 'push'],
794
+ ['ssh']
795
+ ]
796
+
797
+ /** The two spellings the CLI is invoked with: repository source, and the installed binary. */
798
+ const CLI_INVOCATION_PREFIXES: readonly (readonly string[])[] = [['bun', 'apps/cli/src/index.ts'], ['vinaya']]
799
+
800
+ /** What each declared need means for the Developer, named in the refusal. */
801
+ const DEVELOPER_LACKS: Record<string, string> = {
802
+ forge: 'a forge credential',
803
+ 'default-branch': 'a default-branch checkout',
804
+ 'operator-seat': "the Operator's seat"
805
+ }
806
+
807
+ /** `NAME=value` — an environment assignment before the command itself, never the command. */
808
+ const ENV_ASSIGNMENT_RE = /^[A-Za-z_][A-Za-z0-9_]*=/
809
+
810
+ /**
811
+ * The command this statement runs when the reference declares it needs
812
+ * something the Developer lacks, with the need named, or `null`. The
813
+ * longest declared command name that prefixes the tokens after the CLI
814
+ * invocation wins, so `issue objectives edit` is never read as `issue`.
815
+ */
816
+ function developerUnrunnableCommand(
817
+ tokens: string[],
818
+ reference: CommandReferenceFacts
819
+ ): { name: string; lacks: string } | null {
820
+ const invocation = CLI_INVOCATION_PREFIXES.find((p) => p.every((token, i) => tokens[i] === token))
821
+ if (invocation === undefined) return null
822
+ const rest = tokens.slice(invocation.length)
823
+ let best: CommandReferenceEntry | null = null
824
+ for (const command of reference.commands) {
825
+ const words = command.name.split(' ')
826
+ if (!words.every((w, i) => rest[i] === w)) continue
827
+ if (best === null || words.length > best.name.split(' ').length) best = command
828
+ }
829
+ if (best === null || best.needs.length === 0) return null
830
+ return { name: best.name, lacks: best.needs.map((n) => DEVELOPER_LACKS[n] ?? n).join(' and ') }
831
+ }
832
+
833
+ /** The prefix this statement starts with, or `null` — leading env assignments skipped, tokens compared exactly. */
834
+ function developerUnrunnablePrefix(
835
+ statement: string,
836
+ reference: CommandReferenceFacts
837
+ ): { name: string; lacks: string | null } | null {
838
+ const tokens = statement.trim().split(/\s+/).filter(Boolean)
839
+ while (tokens.length > 0 && ENV_ASSIGNMENT_RE.test(tokens[0] as string)) tokens.shift()
840
+ for (const prefix of DEVELOPER_UNRUNNABLE_FOREIGN_PREFIXES) {
841
+ if (prefix.every((token, i) => tokens[i] === token)) return { name: prefix.join(' '), lacks: null }
842
+ }
843
+ return developerUnrunnableCommand(tokens, reference)
844
+ }
845
+
846
+ /**
847
+ * **A Test plan line is one the dispatched Developer can run.** Reads the
848
+ * fenced command lines of `## Test plan` and judges each one statement at a
849
+ * time — `commandStatements`/`stripLineComment`, the same split the
850
+ * whole-suite rule uses, plus an unquoted `|` so a piped command is judged
851
+ * too — by its leading tokens against `DEVELOPER_UNRUNNABLE_PREFIXES`. Prose
852
+ * outside the fence is never judged. Passes when the section is absent or
853
+ * carries the `unit-tests-only` sentinel; `parseIssueTestPlan` reports those
854
+ * shapes.
855
+ */
856
+ export function checkTestPlanDeveloperRunnable(body: string, reference: CommandReferenceFacts): IssueSectionResult {
857
+ const located = locateTestPlanSection(body)
858
+ if (!located.found) return { status: 'pass', errors: [] }
859
+ const lines = extractFencedBlocks(located.section).flatMap((b) =>
860
+ b.content
861
+ .split('\n')
862
+ .map((l) => l.trim())
863
+ .filter((l) => l.length > 0)
864
+ )
865
+ const errors: string[] = []
866
+ for (const line of lines) {
867
+ const statements = commandStatements(line).flatMap((raw) => {
868
+ const stmt = stripLineComment(raw)
869
+ const masked = maskQuoted(stmt)
870
+ const pieces: string[] = []
871
+ let last = 0
872
+ for (let i = 0; i < masked.length; i++) {
873
+ if (masked[i] === '|') {
874
+ pieces.push(stmt.slice(last, i))
875
+ last = i + 1
876
+ }
877
+ }
878
+ pieces.push(stmt.slice(last))
879
+ return pieces
880
+ })
881
+ const hit = statements.map((st) => developerUnrunnablePrefix(st, reference)).find((p) => p !== null)
882
+ if (hit !== undefined && hit !== null) {
883
+ const why =
884
+ hit.lacks === null
885
+ ? 'it holds no forge credential and no shell outside its sandbox'
886
+ : `the command reference declares it needs ${hit.lacks}, which the Developer does not hold`
887
+ errors.push(
888
+ `issue-validation Test plan/developer-runnable: \`${line}\` runs \`${hit.name}\`, which the dispatched Developer cannot run — ${why}. Put it under \`**[principal]**\`; a line the Developer cannot run can only block the task.`
889
+ )
890
+ }
891
+ }
892
+ return { status: errors.length > 0 ? 'fail' : 'pass', errors }
601
893
  }
602
894
 
603
895
  /** `## Stop conditions` — a bullet list, each item the outcome-agnostic condition under which the executing agent must stop and escalate. */
@@ -1034,13 +1326,13 @@ const OBJECTIVES_HEADING_RE = /^##[ \t]*Objectives[ \t]*$/im
1034
1326
 
1035
1327
  /**
1036
1328
  * **O1 — is this body task-Issue-shaped at all?** The
1037
- * forge-write label gate (`forge-write.ts`'s `refuseUnlabeledTaskShapedBody`,
1038
- * and `bin/open-issue.ts`'s mirrored inline check) uses this to catch a
1039
- * Planner's mistake `isTaskIssueLabelSet`-gated validation cannot see: a body
1040
- * that carries the Planner's judgment sections but no `vinaya/tranche:*`
1041
- * label reads, to every check gated behind `isTaskIssueLabelSet`, as "not a
1042
- * task Issue" and sails through unvalidated — the exact hole a task Issue
1043
- * never reaching the forge unlabeled falls through.
1329
+ * Issue create and edit gates (`forge-write.ts`'s `writeValidatedIssueEdit`
1330
+ * and the `issue create`/`issue edit` commands) widen brief-schema
1331
+ * validation with this beyond `isTaskIssueLabelSet`: a body that carries the
1332
+ * Planner's judgment sections but no `vinaya/tranche:*` label — a backlog
1333
+ * Issue — would otherwise read, to every check gated behind
1334
+ * `isTaskIssueLabelSet` alone, as "not a task Issue" and sail through
1335
+ * unvalidated.
1044
1336
  *
1045
1337
  * Two signals, either sufficient: a real `## Objectives` heading, or any ONE
1046
1338
  * of the eight Planner's-rationale fields (`hasRationaleField` — the same
@@ -1060,30 +1352,6 @@ export function isTaskIssueBodyShaped(body: string): boolean {
1060
1352
  return RATIONALE_FIELDS.some((f) => hasRationaleField(text, f.pattern))
1061
1353
  }
1062
1354
 
1063
- /**
1064
- * task 17, O2 — one of the six write-only rules given a name apart: a task-
1065
- * shaped Issue body reaching the forge with no `vinaya/tranche:*` label. Pure
1066
- * over `isTaskIssueBodyShaped`/`isTaskIssueLabelSet` — the exact predicate
1067
- * `forge-write.ts`'s `refuseUnlabeledTaskShapedBody` and `bin/open-issue.ts`'s
1068
- * mirrored inline check already enforce; this names it once so a registered
1069
- * `issue`-scope check and the coherence sweep can both call the SAME
1070
- * function instead of re-deriving the same two-line condition.
1071
- *
1072
- * **Retired to an always-pass check.** A task-
1073
- * shaped body reaching the forge with no `vinaya/tranche:*` label is no
1074
- * longer, by itself, evidence of a mistake — it is the exact shape of a
1075
- * legitimate backlog Issue (`task run --issue <n>`'s own dispatch target),
1076
- * which carries the same body grammar as a tranche task with the label
1077
- * simply omitted. The invariant this rule enforced ("a task Issue never
1078
- * reaches the forge unlabeled") no longer holds; kept as a function (never
1079
- * deleted) so every caller above stays wired to one place rather than three
1080
- * independently-updated copies, and so a future rule needing this exact
1081
- * shape has somewhere to register itself apart from a fresh predicate.
1082
- */
1083
- export function checkTrancheLabelPresence(_body: string, _labels: string[]): IssueSectionResult {
1084
- return { status: 'pass', errors: [] }
1085
- }
1086
-
1087
1355
  /**
1088
1356
  * task 17, O2 — the Milestone-attach rule's validating half. The auto-attach
1089
1357
  * ACTION (`resolveMilestoneAttachArgs`/`resolveMilestoneTitleForCreate` in
@@ -1568,11 +1836,11 @@ const BLAST_RADIUS_ACK_RE = /(?:\*\*)?blast-radius-ack(?:\*\*)?\s*[:—–-]/i
1568
1836
  * an absent key → `null` → NO cutover, so `## Surface` decides from Issue 1,
1569
1837
  * O1); it defaults to `BRIEF_SECTIONS_SINCE_ISSUE` only for a caller that does
1570
1838
  * not resolve config.
1571
- * `issueNumber` follows the same fail-closed posture as
1572
- * `checkIssueObjectives`/`checkIssueBriefSections`: `null` (not yet known,
1573
- * e.g. `issue create`) is NOT treated as "at or above the cutover" — it
1574
- * falls back to the prose scan, since a not-yet-created Issue's own
1575
- * `## Surface` cannot yet be trusted to be the mandatory kind.
1839
+ * `issueNumber` follows the same posture as every other cutover-gated rule
1840
+ * here: `null` (not yet known, e.g. `issue create`) is treated as newer than
1841
+ * every cutover, so a new Issue's `## Surface` is judged at creation exactly
1842
+ * as it is on `issue edit` and at dispatch. Only a number below the cutover
1843
+ * keeps the prose scan.
1576
1844
  */
1577
1845
  export function checkBlastRadiusScope(
1578
1846
  body: string,
@@ -1583,7 +1851,7 @@ export function checkBlastRadiusScope(
1583
1851
  sinceBriefSections: number | null = BRIEF_SECTIONS_SINCE_ISSUE
1584
1852
  ): IssueSectionResult {
1585
1853
  if (sharedPackages.length === 0) return { status: 'pass', errors: [] }
1586
- const decideFromSurface = issueNumber !== null && (sinceBriefSections === null || issueNumber >= sinceBriefSections)
1854
+ const decideFromSurface = issueNumber === null || sinceBriefSections === null || issueNumber >= sinceBriefSections
1587
1855
  let named: string[]
1588
1856
  if (decideFromSurface) {
1589
1857
  const surface = parseIssueSurface(body)
@@ -2349,7 +2617,7 @@ export function checkObjectivesRespectBoundary(body: string): IssueSectionResult
2349
2617
 
2350
2618
  const testPlan = parseIssueTestPlan(body)
2351
2619
  if (testPlan.ok && testPlan.value.kind === 'commands') {
2352
- for (const line of [...testPlan.value.lines, ...testPlan.value.principal]) {
2620
+ for (const line of [...testPlan.value.lines, ...testPlan.value.principal, ...testPlan.value.live]) {
2353
2621
  for (const path of namedPathsInCommandLine(line)) {
2354
2622
  const excluder = excludes(path)
2355
2623
  if (excluder) {
@@ -2407,6 +2675,185 @@ export function checkNoForeignTaskOwnership(body: string): IssueSectionResult {
2407
2675
  return { status: errors.length > 0 ? 'fail' : 'pass', errors }
2408
2676
  }
2409
2677
 
2678
+ /**
2679
+ * One prose field split into sentences: each line, then each `.`/`!`/`?`
2680
+ * followed by whitespace. A dot with no space after it — `issue-validation.ts`,
2681
+ * `checks.timeoutMs` — never ends a sentence, so a backticked path or dotted
2682
+ * value stays inside the sentence that names it.
2683
+ */
2684
+ function proseSentences(text: string): string[] {
2685
+ return text
2686
+ .split('\n')
2687
+ .flatMap((line) => line.split(/(?<=[.!?])\s+/))
2688
+ .map((s) => s.trim())
2689
+ .filter((s) => s.length > 0)
2690
+ }
2691
+
2692
+ /**
2693
+ * The closed list of phrasings that forbid an edit or tell the Developer to
2694
+ * stop on one. Exact, case-insensitive, whitespace-tolerant — never a
2695
+ * classifier: a sentence trips this rule only by carrying one of these
2696
+ * phrases verbatim. Extending the list is a code change, reviewed like any
2697
+ * other, never a heuristic that drifts.
2698
+ */
2699
+ const SURFACE_PROHIBITION_PHRASES: ReadonlyArray<{ phrase: string; re: RegExp }> = [
2700
+ { phrase: 'do not edit', re: /\bdo\s+not\s+edit\b/i },
2701
+ { phrase: 'do not change', re: /\bdo\s+not\s+change\b/i },
2702
+ { phrase: 'do not touch', re: /\bdo\s+not\s+touch\b/i },
2703
+ { phrase: 'never edit', re: /\bnever\s+edit\b/i },
2704
+ { phrase: 'stop if', re: /\bstop\s+if\b/i },
2705
+ { phrase: 'escalate if … cannot', re: /\bescalate\s+if\b.*\bcannot\b/i }
2706
+ ]
2707
+
2708
+ /** A pinned file's module name — its basename up to the first `.` (`issue-validation.test.ts` → `issue-validation`). */
2709
+ function moduleNameOf(file: string): string {
2710
+ const base = file.slice(file.lastIndexOf('/') + 1)
2711
+ const dot = base.indexOf('.')
2712
+ return dot > 0 ? base.slice(0, dot) : base
2713
+ }
2714
+
2715
+ /** Does `sentence` name `module` as `<module> module` (the name optionally backticked)? Whole token only. */
2716
+ function namesModule(sentence: string, module: string): boolean {
2717
+ const escaped = module.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
2718
+ return new RegExp(`(?<![\\w./-])\`?${escaped}\`?\\s+module\\b`, 'i').test(sentence)
2719
+ }
2720
+
2721
+ /**
2722
+ * **A task's prose never forbids a beyond-Surface edit.** The shipped rule is
2723
+ * that a change to a path no Surface `in:` glob covers, or one an `out:` glob
2724
+ * covers, is published anyway: the review-loop driver records it in the pull
2725
+ * request body's beyond-Surface block and the reviewers judge it like any
2726
+ * change. A `Traps to avoid`, `Stop-and-escalate` or `## Stop conditions`
2727
+ * sentence that says "do not edit" such a path, or "stop if" it needs a
2728
+ * change, overrides that rule from inside the brief — and a dispatched task
2729
+ * once paused for a ruling it never needed on exactly that sentence.
2730
+ *
2731
+ * Lexical, and closed: a sentence is refused only when it carries one of
2732
+ * `SURFACE_PROHIBITION_PHRASES` AND names, in the same sentence, a backticked
2733
+ * repository path — or `<module> module` for a Boundary-pinned file — that
2734
+ * `beyondSurfacePaths` (the same measurement the publication records) puts
2735
+ * outside the Surface. Code is never parsed; a sentence about a path an `in:`
2736
+ * glob covers passes. Dormant when `## Surface` does not parse — its own gate
2737
+ * reports that.
2738
+ */
2739
+ export function checkProseAllowsBeyondSurfaceEdit(body: string): IssueSectionResult {
2740
+ const surface = parseIssueSurface(body)
2741
+ if (!surface.ok) return { status: 'pass', errors: [] }
2742
+
2743
+ const text = PATH_TEXT(body)
2744
+ const fields: Array<[string, string]> = [
2745
+ ['Traps to avoid', rationaleFieldText(text, 'Traps')],
2746
+ ['Stop-and-escalate', rationaleFieldText(text, 'Stop-and-escalate')],
2747
+ ['Stop conditions', topLevelSectionText(text, 'Stop conditions') ?? '']
2748
+ ]
2749
+ const outsideModules = beyondSurfacePaths(boundaryPinnedFiles(body), surface.value).map((entry) => ({
2750
+ module: moduleNameOf(entry.path),
2751
+ entry
2752
+ }))
2753
+
2754
+ const errors: string[] = []
2755
+ for (const [name, fieldText] of fields) {
2756
+ for (const sentence of proseSentences(fieldText)) {
2757
+ const prohibition = SURFACE_PROHIBITION_PHRASES.find((p) => p.re.test(sentence))
2758
+ if (!prohibition) continue
2759
+ const beyond = beyondSurfacePaths(namedPathsIn(sentence), surface.value)
2760
+ for (const { module, entry } of outsideModules) {
2761
+ if (namesModule(sentence, module) && !beyond.some((b) => b.path === entry.path)) beyond.push(entry)
2762
+ }
2763
+ for (const entry of beyond) {
2764
+ const why =
2765
+ entry.reason === 'out'
2766
+ ? `the Surface's \`out:\` glob \`${entry.glob}\` covers`
2767
+ : 'no Surface `in:` glob covers'
2768
+ errors.push(
2769
+ `issue-validation ${name}: "${sentence}" says "${prohibition.phrase}" about \`${entry.path}\`, which ${why} — but a change beyond the Surface is never refused: it is published, and the review-loop driver records it in the pull request body's beyond-Surface block for the reviewers to judge. Rewrite the sentence so it no longer forbids, or stops on, that change.`
2770
+ )
2771
+ }
2772
+ }
2773
+ }
2774
+ return { status: errors.length > 0 ? 'fail' : 'pass', errors }
2775
+ }
2776
+
2777
+ /** A bare identifier — `camelCase`, `snake_case`, `kebab-case`, `a.dotted.member` — never a flag, a path or a command line. */
2778
+ const CROSS_TASK_IDENTIFIER_RE = /^[A-Za-z_$][\w$]*(?:[.-][A-Za-z_$][\w$]*)*$/
2779
+ /** A quoted string literal with no whitespace, quote or backslash inside it. */
2780
+ const CROSS_TASK_STRING_LITERAL_RE = /^(['"])([^'"`\s\\]+)\1$/
2781
+
2782
+ /**
2783
+ * The words a sentence uses when THIS task creates the value it names. A
2784
+ * closed list, matched as whole words: a sentence carrying one is the task
2785
+ * stating what it introduces, never what it relies on.
2786
+ */
2787
+ const CREATES_VALUE_RE = /\b(?:add|adds|create|creates|introduce|introduces|define|defines|declare|declares|new)\b/i
2788
+
2789
+ /**
2790
+ * The value one backticked span names, when it reads as an identifier or a
2791
+ * string literal — the literal's contents for a quoted span — or `null` for a
2792
+ * path (`/`), a filename (a file-extension last segment), a command (any
2793
+ * whitespace) or a flag.
2794
+ */
2795
+ function crossTaskValueOf(span: string): string | null {
2796
+ const literal = CROSS_TASK_STRING_LITERAL_RE.exec(span)
2797
+ if (!literal && !CROSS_TASK_IDENTIFIER_RE.test(span)) return null
2798
+ const value = literal ? (literal[2] as string) : span
2799
+ if (value.length < 2 || value.includes('/')) return null
2800
+ const segments = value.split('.')
2801
+ if (segments.length > 1 && FILE_EXTENSIONS.has((segments[segments.length - 1] as string).toLowerCase())) return null
2802
+ return value
2803
+ }
2804
+
2805
+ /**
2806
+ * **A value another task creates is pinned by a premise.** A task that
2807
+ * declares `Depends-on` and names, in its Objectives or its Traps, a
2808
+ * backticked identifier or string literal that no file of the default branch
2809
+ * contains is relying on a task it depends on to create it. That reliance is
2810
+ * a fact about another task's output, so it is written as one: a premise
2811
+ * `after #<n>: `<path>` contains `<value>`` on a task this Issue declares in
2812
+ * `Depends-on`, checked at dispatch. A later task once relied on component
2813
+ * kinds an earlier task never created, and nothing refused it before dispatch.
2814
+ *
2815
+ * Mechanical throughout, no judgment of what the prose means: the value must
2816
+ * be a backticked span `crossTaskValueOf` reads as an identifier or literal,
2817
+ * `existsInTree` (the gate's injected tracked-tree probe) must find it in no
2818
+ * file, and its sentence must carry none of `CREATES_VALUE_RE`'s words — a
2819
+ * sentence saying this task adds the value is the task's own introduction.
2820
+ * Dormant for an Issue that declares no `Depends-on`: with no task to rely on,
2821
+ * a value missing from the tree is this task's own to create.
2822
+ */
2823
+ export function checkCrossTaskValuesPinned(body: string, existsInTree: (token: string) => boolean): IssueSectionResult {
2824
+ const dependsOn = parseRationaleDeps(body).dependsOn
2825
+ if (dependsOn.length === 0) return { status: 'pass', errors: [] }
2826
+ const declared = new Set(dependsOn.map((edge) => (splitSlugQualifiedEdge(edge)?.bareId ?? edge).replace(/^#/, '')))
2827
+ const premises = parseIssuePremises(body)
2828
+ const pinned = (premises.ok ? premises.value : []).filter(
2829
+ (p) => p.afterIssue !== null && declared.has(String(p.afterIssue))
2830
+ )
2831
+
2832
+ const sources: Array<{ where: string; text: string }> = []
2833
+ const objectives = objectivesOf(body)
2834
+ if (objectives.ok) for (const o of objectives.objectives) sources.push({ where: o.id, text: o.text })
2835
+ sources.push({ where: 'Traps to avoid', text: rationaleFieldText(PATH_TEXT(body), 'Traps') })
2836
+
2837
+ const errors: string[] = []
2838
+ const reported = new Set<string>()
2839
+ for (const { where, text } of sources) {
2840
+ for (const sentence of proseSentences(text)) {
2841
+ if (CREATES_VALUE_RE.test(sentence.replace(/`[^`\n]*`/g, ' '))) continue
2842
+ for (const span of backtickedSpans(sentence)) {
2843
+ const value = crossTaskValueOf(span)
2844
+ if (value === null || reported.has(value)) continue
2845
+ if (pinned.some((p) => p.text.includes(value))) continue
2846
+ if (existsInTree(value)) continue
2847
+ reported.add(value)
2848
+ errors.push(
2849
+ `issue-validation Premises/cross-task value: ${where} relies on \`${value}\`, which no file of the default branch contains and no sentence of this Issue says it creates — so a task it depends on (\`Depends-on: ${dependsOn.join(', ')}\`) must. Pin it in \`## Premises\` as \`after #<n>: \`<path>\` contains \`${value}\`\` on the \`Depends-on\` task that creates it, or state in the same sentence that this task adds it.`
2850
+ )
2851
+ }
2852
+ }
2853
+ }
2854
+ return { status: errors.length > 0 ? 'fail' : 'pass', errors }
2855
+ }
2856
+
2410
2857
  /**
2411
2858
  * **Parts and Objectives agree by construction, the other half.** A Part
2412
2859
  * citing an objective `## Objectives` does not define is already refused by
@@ -2475,7 +2922,12 @@ export function checkPartsCoverageAndSequence(body: string): IssueSectionResult
2475
2922
  // ---------------------------------------------------------------------------
2476
2923
 
2477
2924
  /** One command as the command reference records it — its name (`issue create`) and the flags it documents. */
2478
- export type CommandReferenceEntry = { name: string; flags: string[] }
2925
+ export type CommandReferenceEntry = {
2926
+ name: string
2927
+ flags: string[]
2928
+ /** What the command needs beyond the Developer's sandbox (`forge`, `default-branch`, `operator-seat`); empty ⇒ runnable by the Developer. */
2929
+ needs: readonly string[]
2930
+ }
2479
2931
 
2480
2932
  /**
2481
2933
  * The command reference as the caller resolved it. `file` is the tracked file
@@ -2855,44 +3307,135 @@ export function boundaryPinnedFiles(body: string): string[] {
2855
3307
  }
2856
3308
 
2857
3309
  /**
2858
- * **A pinned file's importers are in the Surface, or deliberately out of
3310
+ * What a task decided about one importer of a pinned file: an `in:` glob
3311
+ * reaches it (`by` is that glob), the Boundary's `Out:` clause names it or its
3312
+ * directory (`by` is the named path), or neither (`fix` is the directory glob
3313
+ * that would reach it).
3314
+ */
3315
+ export type PinnedImporterDecision =
3316
+ | { importer: string; state: 'reached'; by: string }
3317
+ | { importer: string; state: 'disclaimed'; by: string }
3318
+ | { importer: string; state: 'uncovered'; fix: string }
3319
+
3320
+ /** One pinned file and the decision made about each of its importers. */
3321
+ export type PinnedFileDecisions = { file: string; importers: PinnedImporterDecision[] }
3322
+
3323
+ /**
3324
+ * Decides every importer of every pinned file against the body's `## Surface`
3325
+ * `in:` globs and its Boundary's `Out:` clause — the one function both the
3326
+ * write gate (`checkPinnedFileImportersCovered`) and the planning report
3327
+ * (`surfaceForcedSet`) read, so the report can never call an importer covered
3328
+ * where the gate calls it uncovered. `null` when `## Surface` does not parse.
3329
+ *
3330
+ * Only those two count. A `## Surface` `out:` glob claims a directory is
3331
+ * untouched, which is exactly what a forced call-site edit contradicts, so it
3332
+ * never excuses an importer; the Boundary's `Out:` clause is the sentence a
3333
+ * Planner writes on purpose to leave one out.
3334
+ */
3335
+ export function decidePinnedFileImporters(
3336
+ body: string,
3337
+ importers: PinnedFileImporters[]
3338
+ ): PinnedFileDecisions[] | null {
3339
+ const surface = parseIssueSurface(body)
3340
+ if (!surface.ok) return null
3341
+ const disclaimed = namedPathsIn(boundaryOutText(body))
3342
+ return importers.map(({ file, importers: found }) => ({
3343
+ file,
3344
+ importers: found.map((importer): PinnedImporterDecision => {
3345
+ const glob = surface.value.in.find((g) => globCoversPath(g, importer))
3346
+ if (glob !== undefined) return { importer, state: 'reached', by: glob }
3347
+ const named = disclaimed.find((d) => globCoversPath(d, importer))
3348
+ if (named !== undefined) return { importer, state: 'disclaimed', by: named }
3349
+ return { importer, state: 'uncovered', fix: directoryGlobFor(importer) }
3350
+ })
3351
+ }))
3352
+ }
3353
+
3354
+ /**
3355
+ * **Every importer of a pinned file is in the Surface, or deliberately out of
2859
3356
  * it.** Changing a file other tracked sources import almost always forces a
2860
- * change at the call site; a Surface that reaches the pinned file and none of
2861
- * its importers is the shape that cost one adopter task five rounds and two
2862
- * rulings, because the caller that had to pass the new signal sat outside it.
2863
- *
2864
- * An importer counts as covered when any `in:` glob covers it, or when the
2865
- * Boundary's `Out:` clause names it or its directory — those two, and no
2866
- * third. The Boundary is where a task says what it deliberately leaves out of
2867
- * work it is otherwise committed to, and saying it there is a sentence the
2868
- * Planner writes on purpose; a `## Surface` `out:` glob is a coarser
2869
- * declaration that the task does not touch a directory at all, which is
2870
- * exactly the claim a forced call-site edit contradicts. Reading `out:` as an
2871
- * excuse let a pinned file's only importer sit under a directory the Issue had
2872
- * merely declared untouched, and the refusal this rule exists for never fired.
2873
- * Refused only when NONE of a pinned file's importers is covered either way:
2874
- * one importer in the Surface means the task already reaches its call sites.
3357
+ * change at the call site; a Surface that reaches the pinned file and leaves
3358
+ * one of its importers undecided is the shape that pauses a task at publish,
3359
+ * because the caller — or the inventory test that lists the changed thing —
3360
+ * that had to change sat outside it.
3361
+ *
3362
+ * Each importer is decided by `decidePinnedFileImporters`: reached by an `in:`
3363
+ * glob, or named (itself or its directory) in the Boundary's `Out:` clause.
3364
+ * Refused when ANY importer is neither — one covered importer no longer
3365
+ * speaks for the others, since a call site in one directory says nothing
3366
+ * about a test in another.
2875
3367
  */
2876
3368
  export function checkPinnedFileImportersCovered(body: string, importers: PinnedFileImporters[]): IssueSectionResult {
2877
3369
  if (importers.length === 0) return { status: 'pass', errors: [] }
2878
- const surface = parseIssueSurface(body)
2879
- if (!surface.ok) return { status: 'pass', errors: [] }
2880
- const disclaimed = namedPathsIn(boundaryOutText(body))
3370
+ const decided = decidePinnedFileImporters(body, importers)
3371
+ if (decided === null) return { status: 'pass', errors: [] }
2881
3372
 
2882
3373
  const errors: string[] = []
2883
- for (const { file, importers: found } of importers) {
2884
- if (found.length === 0) continue
2885
- const uncovered = found.filter(
2886
- (i) => !surface.value.in.some((g) => globCoversPath(g, i)) && !disclaimed.some((d) => globCoversPath(d, i))
3374
+ for (const { file, importers: decisions } of decided) {
3375
+ const uncovered = decisions.filter(
3376
+ (d): d is Extract<PinnedImporterDecision, { state: 'uncovered' }> => d.state === 'uncovered'
2887
3377
  )
2888
- if (uncovered.length < found.length) continue
2889
- const globs = [...new Set(uncovered.map(directoryGlobFor))]
3378
+ if (uncovered.length === 0) continue
2890
3379
  errors.push(
2891
- `issue-validation Surface/importers: the Boundary pins \`${file}\`, which is imported by ${uncovered.map((i) => `\`${i}\``).join(', ')} — and no \`## Surface\` \`in:\` glob covers any of them, nor does the Boundary's \`Out:\` clause name one. Add ${globs.map((g) => `\`${g}\``).join(' or ')} to \`in:\`, or name the importer in the Boundary's \`Out:\` clause to exclude it deliberately (a \`## Surface\` \`out:\` glob is not that statement — it claims the directory is untouched, which a forced call-site edit contradicts).`
3380
+ `issue-validation Surface/importers: the Boundary pins \`${file}\`, and ${uncovered.length === 1 ? 'its importer' : 'its importers'} ${uncovered.map((d) => `\`${d.importer}\` (add \`${d.fix}\` to \`in:\`)`).join(', ')} ${uncovered.length === 1 ? 'is' : 'are'} neither reached by a \`## Surface\` \`in:\` glob nor named in the Boundary's \`Out:\` clause. Add the named glob to \`in:\`, or name the importer (or its directory) in the Boundary's \`Out:\` clause to exclude it deliberately (a \`## Surface\` \`out:\` glob is not that statement — it claims the directory is untouched, which a forced call-site edit contradicts). \`vinaya issue surface --body-file <path>\` prints every importer and its decision.`
2892
3381
  )
2893
3382
  }
2894
3383
  return { status: errors.length > 0 ? 'fail' : 'pass', errors }
2895
3384
  }
3385
+ /** One registered check whose declared file scope covers a pinned file, and the scope entry that does. */
3386
+ export type PinnedFileCheck = { check: string; covers: string }
3387
+
3388
+ /** A pinned file, the checks whose declared scope covers it, and the checks that declare no scope (so no scope can be resolved for them). */
3389
+ export type PinnedFileChecks = { file: string; checks: PinnedFileCheck[]; unresolved: string[] }
3390
+
3391
+ /** A pinned file's covering check and whether the Issue carries a decision for it. */
3392
+ export type PinnedCheckDecision = { check: string; covers: string; decided: boolean }
3393
+
3394
+ /** One pinned file and the decision state of each check that covers it. */
3395
+ export type PinnedFileCheckDecisions = { file: string; checks: PinnedCheckDecision[]; unresolved: string[] }
3396
+
3397
+ /**
3398
+ * Does the body carry a decision for `check`? A decision names the check in
3399
+ * backticks and follows it with `:` or a dash and a sentence saying how the
3400
+ * change satisfies it. A bare mention in a list of names is not a decision.
3401
+ */
3402
+ function hasCheckDecision(body: string, check: string): boolean {
3403
+ const escaped = check.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
3404
+ return new RegExp(`\`${escaped}\`\\s*(?::|—|–|-)\\s*\\S+(?:\\s+\\S+){2,}`).test(body)
3405
+ }
3406
+
3407
+ /** Decides, for every pinned file, whether each check covering it carries a decision in the body. */
3408
+ export function decidePinnedFileChecks(body: string, pinned: PinnedFileChecks[]): PinnedFileCheckDecisions[] {
3409
+ return pinned.map(({ file, checks, unresolved }) => ({
3410
+ file,
3411
+ unresolved,
3412
+ checks: checks.map((c) => ({ ...c, decided: hasCheckDecision(body, c.check) }))
3413
+ }))
3414
+ }
3415
+
3416
+ /**
3417
+ * **Every check whose declared scope covers a pinned file has a decision in
3418
+ * the Issue.** A check that fires at push on a file the Issue pins pauses the
3419
+ * task there unless the Planner already decided how the change satisfies it;
3420
+ * the report lists the covering checks, and this refuses the Issue until each
3421
+ * carries a decision naming the check and how the change satisfies it. A
3422
+ * check that declares no scope is reported as not resolvable and never
3423
+ * refused. Dormant when `## Surface` does not parse or no pinned file has a
3424
+ * covering check.
3425
+ */
3426
+ export function checkPinnedFileChecksDecided(body: string, pinned: PinnedFileChecks[]): IssueSectionResult {
3427
+ if (pinned.length === 0 || !parseIssueSurface(body).ok) return { status: 'pass', errors: [] }
3428
+ const errors: string[] = []
3429
+ for (const { file, checks } of decidePinnedFileChecks(body, pinned)) {
3430
+ const undecided = checks.filter((c) => !c.decided)
3431
+ if (undecided.length === 0) continue
3432
+ errors.push(
3433
+ `issue-validation Surface/checks: the Boundary pins \`${file}\`, and ${undecided.length === 1 ? 'the check' : 'the checks'} ${undecided.map((c) => `\`${c.check}\` (scope \`${c.covers}\`)`).join(', ')} cover${undecided.length === 1 ? 's' : ''} it with no decision in the Issue. For each, add a line naming the check in backticks, then a colon and how the change satisfies it (for example \`${undecided[0]?.check}\`: <how the change satisfies it>). \`vinaya issue surface --body-file <path>\` lists every covering check.`
3434
+ )
3435
+ }
3436
+ return { status: errors.length > 0 ? 'fail' : 'pass', errors }
3437
+ }
3438
+
2896
3439
  /** The CI shard directory a new CLI test file must be listed in, and one file in it for the Surface-coverage test. */
2897
3440
  const CI_SHARD_DIR = 'apps/cli/tests/ci-shards'
2898
3441
  const CI_SHARD_PROBE = `${CI_SHARD_DIR}/shard-1.txt`
@@ -2974,6 +3517,63 @@ export function checkNewLoopFilesCoverInvariantMap(body: string, tracked: string
2974
3517
  }
2975
3518
  }
2976
3519
 
3520
+ /** A forced companion file and whether an `in:` glob already reaches it. */
3521
+ export type ForcedCompanion = { path: string; reached: boolean }
3522
+
3523
+ /** What a draft Issue's Boundary pins force on its Surface — the `vinaya issue surface` report. */
3524
+ export type SurfaceForcedSet = {
3525
+ /** Every importer of every pinned file, decided by `decidePinnedFileImporters` — the write gate's own reading. */
3526
+ importers: PinnedFileDecisions[]
3527
+ /** The CI shard requirement, present only when a pinned CLI test file is new. */
3528
+ ciShards: { newFiles: string[]; companion: ForcedCompanion; fix: string } | null
3529
+ /** The loop invariant map requirement, present only when a pinned loop file is new. */
3530
+ loopInvariantMap: { newFiles: string[]; companions: ForcedCompanion[]; fix: string[] } | null
3531
+ /** Every check whose declared scope covers a pinned file, with whether the Issue decides it — the write gate's own reading. */
3532
+ checks: PinnedFileCheckDecisions[]
3533
+ }
3534
+
3535
+ /**
3536
+ * Everything a draft Issue's Boundary pins force, computed from the same
3537
+ * functions the write gate refuses with: `decidePinnedFileImporters` for the
3538
+ * importers, and the new-file readings of `checkNewTestFilesCoverShards` and
3539
+ * `checkNewLoopFilesCoverInvariantMap` for the shard list and the loop map.
3540
+ * Writes nothing; `null` when `## Surface` does not parse. With no tracked
3541
+ * tree the new-file companions are unknown and reported absent, exactly as
3542
+ * the two rules go dormant.
3543
+ */
3544
+ export function surfaceForcedSet(
3545
+ body: string,
3546
+ importers: PinnedFileImporters[],
3547
+ tracked: string[],
3548
+ checks: PinnedFileChecks[] = []
3549
+ ): SurfaceForcedSet | null {
3550
+ const surface = parseIssueSurface(body)
3551
+ const decided = decidePinnedFileImporters(body, importers)
3552
+ if (!surface.ok || decided === null) return null
3553
+ const reached = (path: string): ForcedCompanion => ({
3554
+ path,
3555
+ reached: surface.value.in.some((g) => globCoversPath(g, path))
3556
+ })
3557
+
3558
+ const newTests = tracked.length === 0 ? [] : newPinnedFiles(body, tracked, isCliTestPath)
3559
+ const newLoop = tracked.length === 0 ? [] : newPinnedFiles(body, tracked, isLoopSurfacePath)
3560
+ const loopCompanions = [LOOP_INVARIANT_FIXTURE, LOOP_INVARIANT_SPEC].map(reached)
3561
+ return {
3562
+ importers: decided,
3563
+ checks: decidePinnedFileChecks(body, checks),
3564
+ ciShards:
3565
+ newTests.length === 0 ? null : { newFiles: newTests, companion: reached(CI_SHARD_PROBE), fix: CI_SHARD_DIR },
3566
+ loopInvariantMap:
3567
+ newLoop.length === 0
3568
+ ? null
3569
+ : {
3570
+ newFiles: newLoop,
3571
+ companions: loopCompanions,
3572
+ fix: [...new Set(loopCompanions.filter((c) => !c.reached).map((c) => directoryGlobFor(c.path)))]
3573
+ }
3574
+ }
3575
+ }
3576
+
2977
3577
  /**
2978
3578
  * Is this URL host a loopback, link-local, private-range or otherwise
2979
3579
  * non-public address? A Documentation source is public documentation; probing
@@ -3003,7 +3603,10 @@ export function isNonPublicHost(hostname: string): boolean {
3003
3603
  }
3004
3604
 
3005
3605
  /** What an unauthenticated fetch of a Documentation URL came to. */
3006
- export type DocumentationProbe = { kind: 'readable' } | { kind: 'unreadable'; detail: string } | { kind: 'unknown' }
3606
+ export type DocumentationProbe =
3607
+ | { kind: 'readable' }
3608
+ | { kind: 'unreadable'; detail: string }
3609
+ | { kind: 'unknown'; reason?: 'rate-limited' }
3007
3610
 
3008
3611
  const DOCUMENTATION_URL_RE = /https?:\/\/[^\s<>()`'"\]]+/g
3009
3612
 
@@ -3083,6 +3686,10 @@ export function checkDocumentationReadable(
3083
3686
  errors.push(
3084
3687
  `issue-validation Documentation/readable: \`${url}\` is not publicly readable (${result.detail}) — an unauthenticated fetch must answer with a success status on its own host. Put that knowledge in an in-repository spec and cite the spec instead.`
3085
3688
  )
3689
+ } else if (result.kind === 'unknown' && result.reason === 'rate-limited') {
3690
+ warnings.push(
3691
+ `issue-validation Documentation/readable: \`${url}\` answered with a rate limit, so its public readability was not checked now. It is re-checked on the next gate run; confirm by hand that it answers an unauthenticated fetch if the limit persists.`
3692
+ )
3086
3693
  } else if (result.kind === 'unknown') {
3087
3694
  warnings.push(
3088
3695
  `issue-validation Documentation/readable: \`${url}\` could not be reached in time, so its public readability was not checked. Confirm by hand that it answers an unauthenticated fetch, or cite an in-repository spec instead.`
@@ -3092,6 +3699,102 @@ export function checkDocumentationReadable(
3092
3699
  return { status: errors.length > 0 ? 'fail' : 'pass', errors, warnings }
3093
3700
  }
3094
3701
 
3702
+ /** A source carrying a URL scheme (`https://`, `file://`, …) is never read as a repository path. */
3703
+ const DOCUMENTATION_SOURCE_SCHEME_RE = /[a-z][a-z0-9+.-]*:\/\//i
3704
+
3705
+ /** A repository-path source's path: its first inline code span when it has one, else the whole source, with a `#fragment` dropped. */
3706
+ function documentationSourcePath(source: string): string {
3707
+ const span = /`([^`]+)`/.exec(source)
3708
+ return (span ? (span[1] as string) : source).trim().replace(/#.*$/, '')
3709
+ }
3710
+
3711
+ /**
3712
+ * Where a required source is read from, decided from its `## Documentation`
3713
+ * text alone: a public `https://` or `http://` page, a path in this
3714
+ * repository, or neither. A source with any other scheme, an absolute path,
3715
+ * or a path climbing out of the repository (`..`) names nothing the
3716
+ * controller can prepare, so it is `unresolvable` with the reason spelled out.
3717
+ */
3718
+ export type RequiredSourceLocator =
3719
+ | { kind: 'url'; url: string }
3720
+ | { kind: 'repository'; path: string }
3721
+ | { kind: 'unresolvable'; detail: string }
3722
+
3723
+ export function classifyDocumentationSource(source: string): RequiredSourceLocator {
3724
+ const trimmed = source.trim()
3725
+ if (/^https?:\/\//i.test(trimmed)) return { kind: 'url', url: trimmed }
3726
+ if (DOCUMENTATION_SOURCE_SCHEME_RE.test(trimmed)) {
3727
+ return {
3728
+ kind: 'unresolvable',
3729
+ detail: `\`${trimmed}\` carries a scheme that is neither a web page nor a repository path`
3730
+ }
3731
+ }
3732
+ const path = documentationSourcePath(trimmed)
3733
+ if (path.length === 0) return { kind: 'unresolvable', detail: 'the source names no page and no repository path' }
3734
+ if (path.startsWith('/') || path.split('/').includes('..')) {
3735
+ return { kind: 'unresolvable', detail: `\`${path}\` is not a path inside this repository` }
3736
+ }
3737
+ return { kind: 'repository', path: path.replace(/^\.\//, '') }
3738
+ }
3739
+
3740
+ /**
3741
+ * Why a required source could not be prepared before the Developer's turn —
3742
+ * the typed reason a `missing_source` pause carries for each one.
3743
+ *
3744
+ * - `login_required` — the page asked for credentials (HTTP 401, 403 or 407)
3745
+ * or redirected to a sign-in page; a private document is never read.
3746
+ * - `other_host` — the page answered from a different host than the one the
3747
+ * task names, so what would be read is not the named source.
3748
+ * - `not_a_document` — the answer was an error status, too little text to be
3749
+ * the document, or a body whose end was never declared.
3750
+ * - `fetch_refused` — the fetch itself was refused: not https, a non-public
3751
+ * address, a disallowed content type, an oversized body, too many redirects.
3752
+ * - `unreachable` — a timeout or a dropped connection, still failing after
3753
+ * the provider's bounded retries.
3754
+ * - `missing_in_repository` — the repository path does not exist at the
3755
+ * frozen base revision.
3756
+ * - `unresolvable` — the source names neither a page nor a repository path.
3757
+ */
3758
+ export const REQUIRED_SOURCE_MISSING_REASONS = [
3759
+ 'login_required',
3760
+ 'other_host',
3761
+ 'not_a_document',
3762
+ 'fetch_refused',
3763
+ 'unreachable',
3764
+ 'missing_in_repository',
3765
+ 'unresolvable'
3766
+ ] as const
3767
+ export type RequiredSourceMissingReason = (typeof REQUIRED_SOURCE_MISSING_REASONS)[number]
3768
+
3769
+ /**
3770
+ * **An in-repository Documentation source exists in the checkout.** A source
3771
+ * carrying a URL scheme belongs to `checkDocumentationReadable` and is never
3772
+ * probed here; any other source is a repository path — its first inline code
3773
+ * span when it has one, else the whole source, with a `#fragment` dropped —
3774
+ * read through the injected `readFile` (this module reads no `fs`), and
3775
+ * refused when the read answers `null`. Passes on the `None` sentinel and on
3776
+ * a section that does not parse; `parseIssueDocumentation` reports that.
3777
+ */
3778
+ export function checkDocumentationPathsExist(
3779
+ body: string,
3780
+ readFile: (path: string) => string | null
3781
+ ): IssueSectionResult {
3782
+ const documentation = parseIssueDocumentation(body)
3783
+ if (!documentation.ok || documentation.value.kind === 'none') return { status: 'pass', errors: [] }
3784
+ const errors: string[] = []
3785
+ for (const { source } of documentation.value.sources) {
3786
+ if (DOCUMENTATION_SOURCE_SCHEME_RE.test(source)) continue
3787
+ const path = documentationSourcePath(source)
3788
+ if (path.length === 0) continue
3789
+ if (readFile(path) === null) {
3790
+ errors.push(
3791
+ `issue-validation Documentation/exists: \`${path}\` is an in-repository Documentation source the checkout does not contain — a source without a URL scheme is read as a repository file path, and the Developer is told to read it.`
3792
+ )
3793
+ }
3794
+ }
3795
+ return { status: errors.length > 0 ? 'fail' : 'pass', errors }
3796
+ }
3797
+
3095
3798
  // ---------------------------------------------------------------------------
3096
3799
  // O3 — an edit that changes
3097
3800
  // `## Objectives`, `## Surface`, or `## Parts` on a task Issue whose brief is