@attalabs/vinaya 0.33.0 → 0.35.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 (143) hide show
  1. package/LICENSE +104 -201
  2. package/README.md +1 -1
  3. package/aeg-root/enforcement.md +1 -1
  4. package/aeg-root/glossary.md +4 -0
  5. package/aeg-root/roles/developer.md +3 -0
  6. package/aeg-root/roles/operator.md +30 -10
  7. package/aeg-root/roles/planner/reference.md +3 -2
  8. package/aeg-root/roles/planner.md +3 -1
  9. package/aeg-root/templates/brief-template.md +9 -7
  10. package/aeg-root/templates/pr-report-template.md +3 -1
  11. package/dist/checks/bin/check-body-bare-digits.js +107 -28
  12. package/dist/checks/bin/check-branch-topology.js +94 -25
  13. package/dist/checks/bin/check-brief-shape.js +113 -33
  14. package/dist/checks/bin/check-changeset-coverage.js +369 -92
  15. package/dist/checks/bin/check-closes-n.js +94 -25
  16. package/dist/checks/bin/check-coherence.js +124 -29
  17. package/dist/checks/bin/check-dead-branch-push.js +79 -25
  18. package/dist/checks/bin/check-dispatch-readiness.js +122 -28
  19. package/dist/checks/bin/check-doc-coverage-push.js +365 -88
  20. package/dist/checks/bin/check-doc-coverage.js +367 -90
  21. package/dist/checks/bin/check-doctrine-no-procedures.js +107 -28
  22. package/dist/checks/bin/check-doctrine-portability.js +366 -89
  23. package/dist/checks/bin/check-evidence-fresh.js +338 -61
  24. package/dist/checks/bin/check-exec-bits.js +363 -86
  25. package/dist/checks/bin/check-first-push-dispatch.js +122 -28
  26. package/dist/checks/bin/check-issue-assignment.js +94 -25
  27. package/dist/checks/bin/check-issue-milestone-attach.js +79 -25
  28. package/dist/checks/bin/check-issue-objectives-numbering.js +606 -26
  29. package/dist/checks/bin/check-issue-parts-coverage.js +79 -25
  30. package/dist/checks/bin/check-issue-surface-globs.js +162 -34
  31. package/dist/checks/bin/check-issue-title-grammar.js +79 -25
  32. package/dist/checks/bin/check-issue-tranche-label.js +79 -25
  33. package/dist/checks/bin/check-main-branch-refusal.js +79 -25
  34. package/dist/checks/bin/check-no-disk-state.js +79 -25
  35. package/dist/checks/bin/check-pr-premise-reassert.js +107 -28
  36. package/dist/checks/bin/check-pr-report-density.js +79 -25
  37. package/dist/checks/bin/check-principal-test-plan-wait.js +79 -25
  38. package/dist/checks/bin/check-quoted-command.js +282 -39
  39. package/dist/checks/bin/check-reader-resolvable-prose.js +333 -47
  40. package/dist/checks/bin/check-registry-gates.js +79 -25
  41. package/dist/checks/bin/check-retired-vocabulary.js +282 -39
  42. package/dist/checks/bin/check-review-gate.js +111 -31
  43. package/dist/checks/bin/check-single-plan-pr.js +79 -25
  44. package/dist/checks/bin/check-surface-scope.js +94 -25
  45. package/dist/checks/bin/check-test-plan.js +79 -25
  46. package/dist/checks/bin/check-token-collection-wired.js +79 -25
  47. package/dist/checks/bin/check-token-report.js +79 -25
  48. package/dist/checks/bin/check-workspace-escape.js +364 -87
  49. package/dist/index.js +2713 -1609
  50. package/dist/lib/pre-push-cache-test-run.js +226 -16
  51. package/dist/lib/pre-push-select-tests.js +48 -5
  52. package/package.json +2 -2
  53. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/brief-render.ts +153 -37
  54. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/brief-validation.ts +87 -24
  55. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/coherence-checks.ts +9 -2
  56. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/control-store/migration.ts +13 -3
  57. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/assess-round.ts +7 -0
  58. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/index.ts +5 -2
  59. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/journal-reconstruction.ts +116 -20
  60. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/render-summary.ts +100 -4
  61. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/gate-cutovers.ts +49 -0
  62. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/index.ts +60 -4
  63. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/issue-validation.ts +138 -54
  64. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/envelope.ts +26 -3
  65. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/objectives-cutover-config.ts +31 -0
  66. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/objectives.ts +15 -6
  67. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/reader-resolvable-prose.ts +122 -23
  68. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-gate.ts +18 -3
  69. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-policy.ts +24 -0
  70. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-status.ts +15 -10
  71. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/ruling-ordinal.ts +16 -0
  72. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/task-phase-history.ts +194 -0
  73. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/task-tools.ts +312 -53
  74. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/verdict-extraction.ts +62 -8
  75. package/studio-standalone/apps/vinaya-studio/web/.next/BUILD_ID +1 -1
  76. package/studio-standalone/apps/vinaya-studio/web/.next/build-manifest.json +3 -3
  77. package/studio-standalone/apps/vinaya-studio/web/.next/prerender-manifest.json +3 -3
  78. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.html +1 -1
  79. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.rsc +1 -1
  80. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
  81. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  82. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  83. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  84. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  85. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page/server-reference-manifest.json +2 -2
  86. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page.js.nft.json +1 -1
  87. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  88. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/api/coherence/route.js.nft.json +1 -1
  89. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page/server-reference-manifest.json +2 -2
  90. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page.js.nft.json +1 -1
  91. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page_client-reference-manifest.js +1 -1
  92. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page/server-reference-manifest.json +2 -2
  93. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page.js.nft.json +1 -1
  94. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page_client-reference-manifest.js +1 -1
  95. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page/server-reference-manifest.json +2 -2
  96. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page.js.nft.json +1 -1
  97. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page_client-reference-manifest.js +1 -1
  98. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page/server-reference-manifest.json +2 -2
  99. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page.js.nft.json +1 -1
  100. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page_client-reference-manifest.js +1 -1
  101. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page/server-reference-manifest.json +3 -3
  102. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page.js.nft.json +1 -1
  103. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page_client-reference-manifest.js +1 -1
  104. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page/server-reference-manifest.json +2 -2
  105. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page.js.nft.json +1 -1
  106. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page_client-reference-manifest.js +1 -1
  107. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page/server-reference-manifest.json +2 -2
  108. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page.js.nft.json +1 -1
  109. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page_client-reference-manifest.js +1 -1
  110. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page/server-reference-manifest.json +2 -2
  111. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page.js.nft.json +1 -1
  112. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page_client-reference-manifest.js +1 -1
  113. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/[root-of-the-server]__02a-3g8._.js +4 -4
  114. 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
  115. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__074w9nf._.js +1 -1
  116. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__0ls23oh._.js +1 -1
  117. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/{[root-of-the-server]__18paley._.js → [root-of-the-server]__0zc_0gx._.js} +1 -1
  118. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1gjqmhq._.js +1 -1
  119. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1wc4-ip._.js +1 -1
  120. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_08onyya._.js +1 -1
  121. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_096f46i._.js +1 -1
  122. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0af2one._.js +1 -1
  123. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0e5tkdd._.js +1 -1
  124. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0kf2g72._.js +1 -1
  125. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0zf4d27._.js +1 -1
  126. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_1-wo68i._.js +1 -1
  127. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_15gdg48._.js +2 -2
  128. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_1achbh9._.js +1 -1
  129. 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
  130. package/studio-standalone/apps/vinaya-studio/web/.next/server/middleware-build-manifest.js +3 -3
  131. package/studio-standalone/apps/vinaya-studio/web/.next/server/pages/500.html +1 -1
  132. package/studio-standalone/apps/vinaya-studio/web/.next/server/server-reference-manifest.js +1 -1
  133. package/studio-standalone/apps/vinaya-studio/web/.next/server/server-reference-manifest.json +4 -4
  134. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/0ko698wh8xx2g.css +1 -0
  135. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{22s44f5k3ecmj.js → 3goaig_rysc6p.js} +1 -1
  136. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{1ce2dj27_cgbj.js → 3ip5z3cf43bgo.js} +4 -4
  137. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{34hhdtbp20krb.js → 3u9emqjwpd0t9.js} +1 -1
  138. package/studio-standalone/apps/vinaya-studio/web/package.json +2 -2
  139. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/0bm4nrrzwc7zi.css +0 -1
  140. /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/vinaya/studio-standalone/_node_modules/@attalabs/{aeg-core → vinaya/studio-standalone/_node_modules/@attalabs/vinaya/studio-standalone/_node_modules/@attalabs/aeg-core}/bin/verify-coherence.ts +0 -0
  141. /package/studio-standalone/apps/vinaya-studio/web/.next/static/{vl7QVqELe1AQ-9kaOd9mR → ca66rAHI_w9D7S7ceXDvR}/_buildManifest.js +0 -0
  142. /package/studio-standalone/apps/vinaya-studio/web/.next/static/{vl7QVqELe1AQ-9kaOd9mR → ca66rAHI_w9D7S7ceXDvR}/_clientMiddlewareManifest.js +0 -0
  143. /package/studio-standalone/apps/vinaya-studio/web/.next/static/{vl7QVqELe1AQ-9kaOd9mR → ca66rAHI_w9D7S7ceXDvR}/_ssgManifest.js +0 -0
@@ -17,6 +17,7 @@
17
17
  */
18
18
 
19
19
  import {
20
+ findLetteredEdgeIds,
20
21
  hasLabel,
21
22
  LABELS,
22
23
  projectFieldFromBody,
@@ -102,22 +103,60 @@ export function checkIssueRationale(body: string): IssueSectionResult {
102
103
  }
103
104
 
104
105
  /**
105
- * The Issue number from which `## Objectives` becomes mandatory (a real
106
- * incident: a merged PR left two brief Parts
107
- * undelivered and nothing named what the work had to do in a form a machine
108
- * could compare). Every task
109
- * Issue at or above this cutover number already carries the section by hand. Same shape as
110
- * `BRIEF_RULES_SINCE_PR` (`brief-validation.ts`) — a cutover by Issue number,
111
- * never a retroactive requirement on the pre-gate stock.
106
+ * **A `Depends-on`/`Conflicts-with` edge names a whole-number task id.** A
107
+ * lettered id (`7a`, `2b`) clears no gate downstream — `vinaya task run` and
108
+ * `task dispatch` refuse any non-numeric id — so a plan naming one in an edge
109
+ * builds a dependency the Operator can never start, the exact split that let a
110
+ * new adopter's `2a`/`2b` plan pass every gate and then stall. The edge grammar
111
+ * (`parse-rationale-deps.ts`'s `ID_TOKEN`/`SLUG_QUALIFIED_ID`) no longer accepts
112
+ * a lettered id; this NAMES the offending token at authoring time rather than
113
+ * silently dropping it. `findLetteredEdgeIds` reads the same declared-edge spans
114
+ * `parseRationaleDeps` does, so this can never disagree with what the parser
115
+ * treats as an edge. One error line per lettered id.
116
+ */
117
+ export function checkEdgeIdsWholeNumbers(body: string): IssueSectionResult {
118
+ const lettered = findLetteredEdgeIds(body)
119
+ if (lettered.length === 0) return { status: 'pass', errors: [] }
120
+ return {
121
+ status: 'fail',
122
+ errors: lettered.map(
123
+ (id) =>
124
+ `issue-validation edge id: \`${id}\` in a \`Depends-on\`/\`Conflicts-with\` edge is not a whole number — task ids are whole numbers (\`1\`, \`2\`), never lettered (\`2a\`). \`vinaya task run\` and \`task dispatch\` refuse a non-numeric id, so a plan naming one names a task that cannot be started.`
125
+ )
126
+ }
127
+ }
128
+
129
+ /**
130
+ * This repository's own historical Objectives cutover (a real incident: a
131
+ * merged PR left two brief Parts undelivered and nothing named what the work
132
+ * had to do in a form a machine could compare). Every task Issue at or above
133
+ * this number already carries the section by hand.
134
+ *
135
+ * **This is now the DEFAULT parameter value of `checkIssueObjectives`, not the
136
+ * value the gate reads.** The cutover is an optional `vinaya.config.json` key
137
+ * (`gateCutovers.objectivesSinceIssue`, resolved by `resolveGateCutovers` in
138
+ * `apps/cli/src/lib/config.ts`) passed into this gate as `sinceIssue`; an
139
+ * absent key resolves to `null` (NO cutover — the gate applies from Issue 1,
140
+ * O1), never to this constant. This repository restates this number as its own
141
+ * `gateCutovers.objectivesSinceIssue` so its behaviour is unchanged (O2). The
142
+ * constant stays exported as the parameter default so a caller that does not
143
+ * resolve config (a test, an authoring path) keeps this repo's behaviour. Same
144
+ * shape as `BRIEF_RULES_SINCE_PR` (`brief-validation.ts`).
112
145
  */
113
146
  export const OBJECTIVES_SINCE_ISSUE = 404
114
147
 
115
148
  /**
116
- * **The Objectives gate.** A task Issue numbered at or above
117
- * `OBJECTIVES_SINCE_ISSUE` must carry a well-formed `## Objectives` section
118
- * (`objectives.ts`'s `objectivesOf`) — one numbered, observable-outcome
119
- * sentence per line, contiguous from `O1`. Below the cutover, an Issue passes
120
- * unconditionally — the stock of older Issues stays green.
149
+ * **The Objectives gate.** A task Issue numbered at or above `sinceIssue` must
150
+ * carry a well-formed `## Objectives` section (`objectives.ts`'s
151
+ * `objectivesOf`) — one numbered, observable-outcome sentence per line,
152
+ * contiguous from `O1`. Below the cutover, an Issue passes unconditionally.
153
+ *
154
+ * `sinceIssue` is the resolved cutover: a number (grandfather Issues below it),
155
+ * or `null` for NO cutover — the gate then applies to every Issue, from 1 (a
156
+ * repository that declares no `gateCutovers`, O1). It defaults to
157
+ * `OBJECTIVES_SINCE_ISSUE` (this repo's historical value) only for a caller
158
+ * that does not resolve config; every enforcement path passes the resolved
159
+ * value, which is `null` when the key is absent.
121
160
  *
122
161
  * `issueNumber === null` (not yet known — an Issue being created has no
123
162
  * number until the write completes) is NOT exempted: fail-closed, the same
@@ -126,8 +165,12 @@ export const OBJECTIVES_SINCE_ISSUE = 404
126
165
  * far past the cutover, so this never blocks a legitimate create; what it
127
166
  * refuses is guessing an unknown number is old enough to skip.
128
167
  */
129
- export function checkIssueObjectives(body: string, issueNumber: number | null): IssueSectionResult {
130
- if (issueNumber !== null && issueNumber < OBJECTIVES_SINCE_ISSUE) return { status: 'pass', errors: [] }
168
+ export function checkIssueObjectives(
169
+ body: string,
170
+ issueNumber: number | null,
171
+ sinceIssue: number | null = OBJECTIVES_SINCE_ISSUE
172
+ ): IssueSectionResult {
173
+ if (sinceIssue !== null && issueNumber !== null && issueNumber < sinceIssue) return { status: 'pass', errors: [] }
131
174
  const result = objectivesOf(body)
132
175
  if (result.ok) return { status: 'pass', errors: [] }
133
176
  return { status: 'fail', errors: result.errors.map((e) => `issue-validation objectives: ${e}`) }
@@ -676,41 +719,59 @@ export function checkDocumentationCitesObjective(body: string): IssueSectionResu
676
719
  }
677
720
 
678
721
  /**
679
- * The Issue number from which the four judgment sections above become
680
- * mandatory — this Issue's own number, the first Issue this tranche cut.
681
- * Same cutover-by-Issue-number shape as `OBJECTIVES_SINCE_ISSUE`; a task
682
- * Issue below this number legitimately carries none of the four.
722
+ * This repository's own historical brief-sections cutover — the first Issue
723
+ * this tranche cut, from which the four judgment sections became mandatory.
724
+ * Now the DEFAULT parameter value of `checkIssueBriefSections`, not the value
725
+ * the gate reads: the cutover is `vinaya.config.json`'s optional
726
+ * `gateCutovers.briefSectionsSinceIssue` (absent → `null` → gate from Issue 1,
727
+ * O1), restated as this repo's own value (O2). Same shape as
728
+ * `OBJECTIVES_SINCE_ISSUE`.
683
729
  */
684
730
  export const BRIEF_SECTIONS_SINCE_ISSUE = 426
685
731
 
686
732
  /**
687
- * The Issue number from which `## Documentation` becomes mandatory alongside
688
- * the four sections above — deliberately one past this requirement's own
689
- * Issue (the highest Issue number in existence when it was authored),
690
- * so no open or historical Issue is invalidated by the new requirement and
691
- * `issue edit` on one never starts refusing a body it could not have carried
692
- * the section in. Never grandfathered further back than that: unlike
693
- * `BRIEF_SECTIONS_SINCE_ISSUE`'s 426, there is no stock of Issues that
694
- * already carry a literal `## Documentation` heading by hand to preserve.
733
+ * This repository's own historical `## Documentation` cutover — one past that
734
+ * requirement's own Issue (the highest Issue number in existence when it was
735
+ * authored), so no open or historical Issue was invalidated by the new
736
+ * requirement. Now the DEFAULT parameter value of `checkIssueBriefSections`'s
737
+ * `sinceDocumentation`, not the value the gate reads: the cutover is
738
+ * `vinaya.config.json`'s optional `gateCutovers.documentationSinceIssue`
739
+ * (absent → `null` → gate from Issue 1, O1), restated as this repo's own value
740
+ * (O2). Never grandfathered further back than this: unlike
741
+ * `BRIEF_SECTIONS_SINCE_ISSUE`'s 426, there is no stock of Issues that already
742
+ * carry a literal `## Documentation` heading by hand to preserve.
695
743
  */
696
744
  export const DOCUMENTATION_SINCE_ISSUE = 626
697
745
 
698
746
  /**
699
747
  * **The brief-sections gate.** A task Issue numbered at or above
700
- * `BRIEF_SECTIONS_SINCE_ISSUE` must carry all four of `## Surface`,
701
- * `## Parts`, `## Test plan`, `## Stop conditions`, each well-formed per its
702
- * own parser above. Below the cutover, an Issue passes unconditionally.
703
- * `issueNumber === null` is NOT exempted — fail-closed, the same posture
704
- * `checkIssueObjectives` takes for an Issue with no number yet.
748
+ * `sinceBriefSections` must carry all four of `## Surface`, `## Parts`,
749
+ * `## Test plan`, `## Stop conditions`, each well-formed per its own parser
750
+ * above. Below the cutover, an Issue passes unconditionally.
751
+ *
752
+ * `sinceBriefSections`/`sinceDocumentation` are the resolved cutovers: a number
753
+ * (grandfather Issues below it), or `null` for NO cutover — the gate then
754
+ * applies to every Issue, from 1 (a repository that declares no `gateCutovers`,
755
+ * O1). They default to this repo's historical constants only for a caller that
756
+ * does not resolve config; every enforcement path passes the resolved values,
757
+ * which are `null` when the key is absent. `issueNumber === null` is NOT
758
+ * exempted — fail-closed, the same posture `checkIssueObjectives` takes.
705
759
  *
706
760
  * A fifth section, `## Documentation`, is folded into this same gate rather
707
- * than a new builtin (O1) — it is graded on its own, later
708
- * cutover (`DOCUMENTATION_SINCE_ISSUE`), since no pre-existing Issue ever
709
- * carried it and requiring it retroactively on an `issue edit` would refuse a
710
- * body no author had reason to write that way.
761
+ * than a new builtin — it is graded on its own, later cutover
762
+ * (`sinceDocumentation`), since no pre-existing Issue ever carried it and
763
+ * requiring it retroactively on an `issue edit` would refuse a body no author
764
+ * had reason to write that way.
711
765
  */
712
- export function checkIssueBriefSections(body: string, issueNumber: number | null): IssueSectionResult {
713
- if (issueNumber !== null && issueNumber < BRIEF_SECTIONS_SINCE_ISSUE) return { status: 'pass', errors: [] }
766
+ export function checkIssueBriefSections(
767
+ body: string,
768
+ issueNumber: number | null,
769
+ sinceBriefSections: number | null = BRIEF_SECTIONS_SINCE_ISSUE,
770
+ sinceDocumentation: number | null = DOCUMENTATION_SINCE_ISSUE
771
+ ): IssueSectionResult {
772
+ if (sinceBriefSections !== null && issueNumber !== null && issueNumber < sinceBriefSections) {
773
+ return { status: 'pass', errors: [] }
774
+ }
714
775
 
715
776
  const errors: string[] = []
716
777
  const surface = parseIssueSurface(body)
@@ -722,7 +783,7 @@ export function checkIssueBriefSections(body: string, issueNumber: number | null
722
783
  const stopConditions = parseIssueStopConditions(body)
723
784
  if (!stopConditions.ok) errors.push(...stopConditions.errors.map((e) => `issue-validation Stop conditions: ${e}`))
724
785
 
725
- if (issueNumber === null || issueNumber >= DOCUMENTATION_SINCE_ISSUE) {
786
+ if (sinceDocumentation === null || issueNumber === null || issueNumber >= sinceDocumentation) {
726
787
  const documentation = parseIssueDocumentation(body)
727
788
  if (!documentation.ok) errors.push(...documentation.errors.map((e) => `issue-validation Documentation: ${e}`))
728
789
  else errors.push(...checkDocumentationCitesObjective(body).errors)
@@ -1266,11 +1327,15 @@ const BLAST_RADIUS_ACK_RE = /(?:\*\*)?blast-radius-ack(?:\*\*)?\s*[:—–-]/i
1266
1327
  * touch `packages/ui`") — a negation the text scan below cannot tell apart
1267
1328
  * from a real touch-claim, and a heuristic in a blocking gate is wrong in
1268
1329
  * both directions. `## Surface`'s `in:` glob list is parsed structure with
1269
- * no negation to misread: at or above `BRIEF_SECTIONS_SINCE_ISSUE`, where
1330
+ * no negation to misread: at or above the brief-sections cutover, where
1270
1331
  * every task Issue carries one, a shared domain is "named" iff a declared
1271
1332
  * `in:` glob covers it (`globCoversPath`) — never by scanning prose for the
1272
1333
  * domain's name. Below the cutover, an Issue legitimately carries no
1273
- * `## Surface` at all, so the original prose scan is unchanged.
1334
+ * `## Surface` at all, so the original prose scan is unchanged. The cutover is
1335
+ * the resolved `sinceBriefSections` (`gateCutovers.briefSectionsSinceIssue`,
1336
+ * an absent key → `null` → NO cutover, so `## Surface` decides from Issue 1,
1337
+ * O1); it defaults to `BRIEF_SECTIONS_SINCE_ISSUE` only for a caller that does
1338
+ * not resolve config.
1274
1339
  * `issueNumber` follows the same fail-closed posture as
1275
1340
  * `checkIssueObjectives`/`checkIssueBriefSections`: `null` (not yet known,
1276
1341
  * e.g. `issue create`) is NOT treated as "at or above the cutover" — it
@@ -1282,10 +1347,11 @@ export function checkBlastRadiusScope(
1282
1347
  _labels: string[],
1283
1348
  sharedPackages: string[],
1284
1349
  projectPaths: ProjectPath[],
1285
- issueNumber: number | null = null
1350
+ issueNumber: number | null = null,
1351
+ sinceBriefSections: number | null = BRIEF_SECTIONS_SINCE_ISSUE
1286
1352
  ): IssueSectionResult {
1287
1353
  if (sharedPackages.length === 0) return { status: 'pass', errors: [] }
1288
- const decideFromSurface = issueNumber !== null && issueNumber >= BRIEF_SECTIONS_SINCE_ISSUE
1354
+ const decideFromSurface = issueNumber !== null && (sinceBriefSections === null || issueNumber >= sinceBriefSections)
1289
1355
  let named: string[]
1290
1356
  if (decideFromSurface) {
1291
1357
  const surface = parseIssueSurface(body)
@@ -1476,15 +1542,24 @@ export function checkRationaleNamesDocs(body: string): IssueSectionResult {
1476
1542
  * simply does not enclose is now accepted; a pointer the surface explicitly
1477
1543
  * excludes still is not.
1478
1544
  *
1479
- * At or above `BRIEF_SECTIONS_SINCE_ISSUE` only — below it an Issue
1545
+ * At or above the brief-sections cutover only — below it an Issue
1480
1546
  * legitimately carries no `## Surface` to compare against, same cutover
1481
- * every other Surface-aware check in this module uses. Passes trivially
1482
- * when the Surface itself doesn't parse (`checkIssueBriefSections` already
1483
- * reports that malformation) or the docs field carries the `no-doc-surface`
1484
- * sentinel (nothing to compare).
1547
+ * every other Surface-aware check in this module uses. The cutover is the
1548
+ * resolved `sinceBriefSections` (`gateCutovers.briefSectionsSinceIssue`, an
1549
+ * absent key → `null` → NO cutover, so this gate applies from Issue 1 wherever
1550
+ * `## Surface` is itself required from Issue 1, O1); it defaults to
1551
+ * `BRIEF_SECTIONS_SINCE_ISSUE` only for a caller that does not resolve config.
1552
+ * Passes trivially when the Surface itself doesn't parse
1553
+ * (`checkIssueBriefSections` already reports that malformation) or the docs
1554
+ * field carries the `no-doc-surface` sentinel (nothing to compare).
1485
1555
  */
1486
- export function checkDocsWithinSurface(body: string, issueNumber: number | null): IssueSectionResult {
1487
- if (issueNumber !== null && issueNumber < BRIEF_SECTIONS_SINCE_ISSUE) return { status: 'pass', errors: [] }
1556
+ export function checkDocsWithinSurface(
1557
+ body: string,
1558
+ issueNumber: number | null,
1559
+ sinceBriefSections: number | null = BRIEF_SECTIONS_SINCE_ISSUE
1560
+ ): IssueSectionResult {
1561
+ if (sinceBriefSections !== null && issueNumber !== null && issueNumber < sinceBriefSections)
1562
+ return { status: 'pass', errors: [] }
1488
1563
  const surface = parseIssueSurface(body)
1489
1564
  if (!surface.ok) return { status: 'pass', errors: [] }
1490
1565
 
@@ -1559,11 +1634,20 @@ function nearestInGlob(path: string, inGlobs: string[]): string {
1559
1634
  * decision undid; Boundary is where "what this task touches" is actually
1560
1635
  * declared.
1561
1636
  *
1562
- * At or above `BRIEF_SECTIONS_SINCE_ISSUE` only — below it an Issue
1563
- * legitimately carries no `## Surface` to compare against.
1637
+ * At or above the brief-sections cutover only — below it an Issue
1638
+ * legitimately carries no `## Surface` to compare against. The cutover is the
1639
+ * resolved `sinceBriefSections` (`gateCutovers.briefSectionsSinceIssue`, an
1640
+ * absent key → `null` → NO cutover, so this gate applies from Issue 1 wherever
1641
+ * `## Surface` is itself required from Issue 1, O1); it defaults to
1642
+ * `BRIEF_SECTIONS_SINCE_ISSUE` only for a caller that does not resolve config.
1564
1643
  */
1565
- export function checkRationaleSurfaceCoverage(body: string, issueNumber: number | null): IssueSectionResult {
1566
- if (issueNumber !== null && issueNumber < BRIEF_SECTIONS_SINCE_ISSUE) return { status: 'pass', errors: [] }
1644
+ export function checkRationaleSurfaceCoverage(
1645
+ body: string,
1646
+ issueNumber: number | null,
1647
+ sinceBriefSections: number | null = BRIEF_SECTIONS_SINCE_ISSUE
1648
+ ): IssueSectionResult {
1649
+ if (sinceBriefSections !== null && issueNumber !== null && issueNumber < sinceBriefSections)
1650
+ return { status: 'pass', errors: [] }
1567
1651
  const surface = parseIssueSurface(body)
1568
1652
  if (!surface.ok) return { status: 'pass', errors: [] }
1569
1653
 
@@ -1579,7 +1663,7 @@ export function checkRationaleSurfaceCoverage(body: string, issueNumber: number
1579
1663
  if (surface.value.out.some((g) => globCoversPath(g, path))) continue
1580
1664
  const nearest = nearestInGlob(path, surface.value.in)
1581
1665
  errors.push(
1582
- `issue-validation Boundary: \`${path}\` is named in the Boundary rationale, but no \`## Surface\` \`in:\` glob covers it — nearest is \`${nearest}\`. Widen the Surface's \`in:\` list to cover it, or correct the path if it was mistyped.`
1666
+ `issue-validation Boundary: \`${path}\` is named in the Boundary rationale, but no \`## Surface\` \`in:\` glob covers it — nearest is \`${nearest}\`. Widen an \`in:\` directory glob to cover it (\`## Surface\` lists directories, never a file path), or correct the path if it was mistyped.`
1583
1667
  )
1584
1668
  }
1585
1669
  return { status: errors.length > 0 ? 'fail' : 'pass', errors }
@@ -20,9 +20,23 @@ function attemptFromEnv(value: string | undefined): number | null {
20
20
  return Number.isInteger(n) ? n : null
21
21
  }
22
22
 
23
- /** Only a value the caller actually asserts becomes `parent_attributed`/`self_reported` — `buildHeader` never upgrades trust on its own (see `schema.ts`'s `ProvenanceSchema` doc). */
24
- function provenanceFor(input: Pick<HeaderInput, 'provenance' | 'env'>): Provenance {
23
+ /**
24
+ * Only a value the caller actually asserts becomes
25
+ * `parent_attributed`/`self_reported` — `buildHeader` never upgrades trust
26
+ * on its own (see `schema.ts`'s `ProvenanceSchema` doc). A `branchIssue`
27
+ * deliberately does NOT count as an environment correlation: nothing about a
28
+ * checked-out branch is one. An event whose `subject.issue` came from the
29
+ * branch therefore reads `'unavailable'` EVEN WHEN the environment named a
30
+ * role, because this one field describes the whole subject and there is no
31
+ * way to say "the role was env-correlated, the issue was guessed" — reading
32
+ * `'env_correlated'` beside a branch-guessed number would present a guess as
33
+ * a correlation, and a process with `VINAYA_ROLE` set and `VINAYA_TASK`
34
+ * absent or unparseable is exactly that shape. Under-claiming about the role
35
+ * is the safe direction; over-claiming about the issue is not.
36
+ */
37
+ function provenanceFor(input: Pick<HeaderInput, 'provenance' | 'env' | 'branchIssue'>): Provenance {
25
38
  if (input.provenance) return input.provenance
39
+ if (issueFromTask(input.env.task) === null && (input.branchIssue ?? null) !== null) return 'unavailable'
26
40
  if (input.env.role || input.env.task) return 'env_correlated'
27
41
  return 'unavailable'
28
42
  }
@@ -51,6 +65,15 @@ export type HeaderInput = {
51
65
  host: Host
52
66
  hostname: string
53
67
  env: { role?: string; task?: string; round?: string; run?: string; attempt?: string; parent?: string }
68
+ /**
69
+ * The Issue the caller's own checked-out branch names, for a process that
70
+ * carries no `VINAYA_TASK` — `subject.issue`'s fallback, never its
71
+ * override: an event that names its task in the environment keeps that
72
+ * number. `null`/absent when the branch names no task or its Issue could
73
+ * not be resolved, which stays `issue: null` rather than a guess. Read
74
+ * by the caller (the sink, from `git`/`gh`); this module stays pure.
75
+ */
76
+ branchIssue?: number | null
54
77
  subject?: Partial<Subject>
55
78
  /** Stable per-event identity (O1) — generated by the caller (the sink), once per `log()` call, never here (this module stays free of non-deterministic output). */
56
79
  eventId: string
@@ -82,7 +105,7 @@ export function buildHeader(input: HeaderInput): Header {
82
105
  const role: Subject['role'] = isRole(input.env.role) ? input.env.role : 'unattributed'
83
106
  const round = roundFromEnv(input.env.round)
84
107
  const subject: Subject = {
85
- issue: issueFromTask(input.env.task),
108
+ issue: issueFromTask(input.env.task) ?? input.branchIssue ?? null,
86
109
  role,
87
110
  ...(round !== undefined ? { round } : {}),
88
111
  ...(input.subject ?? {})
@@ -0,0 +1,31 @@
1
+ import { readFileSync } from 'node:fs'
2
+ import { join } from 'node:path'
3
+
4
+ /**
5
+ * `vinaya.config.json`'s `gateCutovers.objectivesSinceIssue` — the Objectives
6
+ * gate's cutover, read as plain JSON because aeg-core cannot depend on
7
+ * `apps/cli`'s zod resolver (`resolveGateCutovers`). Kept impure and OUT of
8
+ * `gate-cutovers.ts` (which is deliberately pure — the caller resolves config
9
+ * and passes the value in); the two aeg-core authoring bins (`open-issue.ts`,
10
+ * `verify-brief.ts`) ARE such callers and share this one reader rather than
11
+ * each declaring their own (the symbol-collision gate refuses a name that
12
+ * resolves to two source files).
13
+ *
14
+ * `null` for an absent key OR a malformed/missing config: NO cutover, so the
15
+ * Objectives gate applies to every task Issue, from Issue 1 (a repository that
16
+ * declares no `gateCutovers`, O1). This repository restates its historical
17
+ * value in its own config (O2), so this returns `404` here and the gate is
18
+ * unchanged. `repoRoot` defaults to the current working directory; a caller
19
+ * that has not `chdir`'d to the repo root passes it explicitly.
20
+ */
21
+ export function readConfigObjectivesSinceIssue(repoRoot = '.'): number | null {
22
+ try {
23
+ const raw = JSON.parse(readFileSync(join(repoRoot, 'vinaya.config.json'), 'utf8')) as {
24
+ gateCutovers?: { objectivesSinceIssue?: unknown }
25
+ }
26
+ const value = raw.gateCutovers?.objectivesSinceIssue
27
+ return typeof value === 'number' && Number.isInteger(value) && value >= 0 ? value : null
28
+ } catch {
29
+ return null
30
+ }
31
+ }
@@ -270,18 +270,27 @@ export function isIssueNotFoundError(err: unknown): boolean {
270
270
  * substitutes its own fetcher for the `'issue'` case rather than this
271
271
  * function reading anything itself.
272
272
  *
273
- * `cutoverIssue` is `OBJECTIVES_SINCE_ISSUE` (`issue-validation.ts`) — passed
274
- * in, not imported, because `issue-validation.ts` already imports FROM this
275
- * module (`objectivesOf`); importing the constant back would be circular.
273
+ * `cutoverIssue` is the resolved Objectives cutover (`gateCutovers.objectivesSinceIssue`,
274
+ * resolved by `resolveGateCutovers`, `apps/cli/src/lib/config.ts`) — passed in,
275
+ * not imported, because `issue-validation.ts` already imports FROM this module
276
+ * (`objectivesOf`); importing the constant back would be circular. A number
277
+ * grandfathers Issues below it; `null` means NO cutover — objectives grading
278
+ * applies to every Issue, from 1 (a repository that declares no `gateCutovers`,
279
+ * O1).
276
280
  */
277
281
  export type ObjectivesSource = { kind: 'issue'; issue: number } | { kind: 'body' } | { kind: 'none' }
278
282
 
279
- export function resolveObjectivesSource(prBody: string, issue: number | null, cutoverIssue: number): ObjectivesSource {
283
+ export function resolveObjectivesSource(
284
+ prBody: string,
285
+ issue: number | null,
286
+ cutoverIssue: number | null
287
+ ): ObjectivesSource {
280
288
  // Checked first and unconditionally: a pre-cutover Issue is `'none'`
281
289
  // regardless of what the PR body itself carries — a pre-cutover PR must
282
290
  // keep passing unchanged, never picking up a body-level objectives list
283
- // the Issue-linked case was never subject to.
284
- if (issue !== null && issue < cutoverIssue) return { kind: 'none' }
291
+ // the Issue-linked case was never subject to. A `null` cutover means no
292
+ // grandfathering, so this branch never fires and every Issue is graded.
293
+ if (issue !== null && cutoverIssue !== null && issue < cutoverIssue) return { kind: 'none' }
285
294
  if (issue !== null) return { kind: 'issue', issue }
286
295
  if (hasObjectivesHeading(prBody)) return { kind: 'body' }
287
296
  return { kind: 'none' }
@@ -84,18 +84,63 @@ function shipsArchivePrefix(shipsPrefix: string): string {
84
84
  }
85
85
 
86
86
  /**
87
- * A per-product specs file (`apps/<product>/specs/**`) — issue-657, O6:
87
+ * The spec class's default file set, repository-relative: a root product
88
+ * spec, a root context document, and every decision record under
89
+ * `docs/adr/`. These are the durable documents a repository with no `apps/`
90
+ * tree of its own actually keeps — a spec class that collected only
91
+ * `apps/<product>/specs/**` never read them, so a root spec was free to
92
+ * carry a copy of a plan (a task list, the Issue numbers behind it) that
93
+ * went stale the moment the plan moved, which is exactly the citation this
94
+ * class exists to refuse.
95
+ *
96
+ * A folder entry matches every `.md` file under it; a file entry matches
97
+ * that one file. `README.md` is deliberately absent and must stay absent:
98
+ * the tranche-slug pattern matches the version badge a README carries for
99
+ * each framework it is built on, so a default that swept READMEs would
100
+ * refuse a shape that is not a citation at all.
101
+ */
102
+ export const DEFAULT_SPEC_PATHS: readonly string[] = ['SPEC.md', 'CONTEXT.md', 'docs/adr']
103
+
104
+ /**
105
+ * One spec-path entry in the single spelling the class matches against: no
106
+ * leading `./`, no trailing slash, no doubled separators. A configured entry
107
+ * is written by hand, so `docs/adr/` and `./docs/adr` both reach here and
108
+ * both mean the folder `docs/adr` — normalized, they match; unnormalized,
109
+ * the prefix compare below silently answered "not a spec" and the entry
110
+ * checked nothing at all. Every caller normalizes with THIS function so the
111
+ * collector's paths and the classifier's entries cannot disagree about a
112
+ * spelling.
113
+ */
114
+ export function normalizeSpecPath(entry: string): string {
115
+ let out = entry.replace(/\\/g, '/')
116
+ while (out.startsWith('./')) out = out.slice(2)
117
+ out = out.replace(/\/{2,}/g, '/')
118
+ while (out.endsWith('/')) out = out.slice(0, -1)
119
+ return out
120
+ }
121
+
122
+ /**
123
+ * A spec-class file: a per-product specs file (`apps/<product>/specs/**`),
124
+ * or any `.md` file at — or under — one of `specPaths`' entries. Both are
88
125
  * swept with the SAME rules `ships`/doctrine pages already carry (a spec is
89
126
  * as reader-facing as a doctrine page; a fork or an export reads it with no
90
- * forge to resolve a citation against, same as `aeg-root/**`). Formerly
91
- * classified `internal` (exempt) on the theory that "this reader has this
92
- * forge" — the wrong reader: a spec ships to the SAME audience doctrine
93
- * does, and a spec that opened with a tranche name, an Issue number, and
94
- * external documents as its authority reached a pull request unflagged
95
- * under the old exemption (found live, 2026-09-19).
127
+ * forge to resolve a citation against, same as `aeg-root/**`). The
128
+ * `apps/<product>/specs/**` half was formerly classified `internal`
129
+ * (exempt) on the theory that "this reader has this forge" — the wrong
130
+ * reader: a spec ships to the SAME audience doctrine does, and a spec that
131
+ * opened with a tranche name, an Issue number, and external documents as
132
+ * its authority reached a pull request unflagged under the old exemption
133
+ * (found live, 2026-09-19).
134
+ *
135
+ * `.md` is required of an entry-matched path so a folder entry carrying
136
+ * non-prose files (a fixture, an image) widens the class to its markdown
137
+ * only. Each entry is normalized before it is compared, so a hand-written
138
+ * `docs/adr/` or `./docs/adr` names the same folder a bare `docs/adr` does.
96
139
  */
97
- function isSpecFile(path: string): boolean {
98
- return path.startsWith('apps/') && path.includes('/specs/') && path.endsWith('.md')
140
+ function isSpecFile(path: string, specPaths: readonly string[]): boolean {
141
+ if (path.startsWith('apps/') && path.includes('/specs/') && path.endsWith('.md')) return true
142
+ if (!path.endsWith('.md')) return false
143
+ return specPaths.some((entry) => isUnderOrEqual(path, normalizeSpecPath(entry)))
99
144
  }
100
145
 
101
146
  /** Any `CLAUDE.md`, at any depth — same reasoning as specs: this reader has this forge. */
@@ -117,12 +162,20 @@ function isClaudeMdFile(path: string): boolean {
117
162
  * illustrations using fictional PR numbers as flavor text) that are not
118
163
  * prose in the sense this check means, hence a suffix-scoped match rather
119
164
  * than a bare prefix.
165
+ *
166
+ * `specPaths` is the spec class's own repository-relative file set beyond
167
+ * `apps/<product>/specs/**` — `DEFAULT_SPEC_PATHS` when the caller says
168
+ * nothing, so a repository that configures nothing still has its root spec,
169
+ * root context document and decision records read. A caller adding
170
+ * configured paths passes the defaults alongside them; this parameter is the
171
+ * whole set, never a delta.
120
172
  */
121
173
  export function classifyProseFile(
122
174
  path: string,
123
175
  readerFacingPrefix: string,
124
176
  readerFacingSuffix: string,
125
- shipsPrefix: string = SHIPS_PREFIX
177
+ shipsPrefix: string = SHIPS_PREFIX,
178
+ specPaths: readonly string[] = DEFAULT_SPEC_PATHS
126
179
  ): ProseFileClass | null {
127
180
  if (path.startsWith(shipsPrefix)) {
128
181
  return path.startsWith(shipsArchivePrefix(shipsPrefix)) ? 'internal' : 'ships'
@@ -131,7 +184,7 @@ export function classifyProseFile(
131
184
  return 'reader-facing'
132
185
  }
133
186
  if (isClaudeMdFile(path)) return 'internal'
134
- if (isSpecFile(path)) return 'spec'
187
+ if (isSpecFile(path, specPaths)) return 'spec'
135
188
  if (isProductScopeFile(path)) return 'product'
136
189
  return null
137
190
  }
@@ -194,6 +247,24 @@ export const FORGE_NUMBER_PATTERN = /#[0-9]{2,4}/g
194
247
  /** `example-tranche-vN`-shaped — an internal tranche slug ending `-vN`. */
195
248
  export const TRANCHE_SLUG_VN_PATTERN = /[a-z][a-z-]+-v[0-9]/g
196
249
 
250
+ /**
251
+ * `task 4`/`tasks 12`/`task #4`-shaped — a task's number out of a plan, which
252
+ * only that plan's own tracker resolves, and which moves the moment the plan
253
+ * is renumbered. The shape a durable document copies when it repeats a plan
254
+ * it should have pointed at instead, so it is checked wherever a spec is.
255
+ *
256
+ * Deliberately narrow: the word `task` or `tasks` immediately followed by a
257
+ * number. A document's own numbered structure — "Section 3", "step 2", "Part
258
+ * 1" — is not a citation and never matches, and neither does a longer word
259
+ * that merely contains these letters (`multitasking 2`), since the leading
260
+ * boundary rejects a preceding letter, digit or hyphen. Case-insensitive, so
261
+ * a heading (`## Task 4`) is caught alongside mid-sentence prose. Group 1 is
262
+ * the leading boundary character (or start-of-string) and group 2 the
263
+ * citation itself — the caller reports group 2, so the boundary character
264
+ * never leaks into a finding's message.
265
+ */
266
+ export const TASK_NUMBER_PATTERN = /(^|[^a-z0-9-])(tasks?[ \t]+#?[0-9]+)/gi
267
+
197
268
  /**
198
269
  * Builds the legacy-slug pattern from the real archived-tranche filenames
199
270
  * the adapter reads (mirrors `retired-vocabulary.test.ts`'s `legacySlugs()` —
@@ -230,7 +301,8 @@ export function checkUnresolvableReferences(
230
301
  readerFacingSuffix: string,
231
302
  legacySlugs: readonly string[] = [],
232
303
  shipsPrefix: string = SHIPS_PREFIX,
233
- specGrandfather: readonly string[] = []
304
+ specGrandfather: readonly string[] = [],
305
+ specPaths: readonly string[] = DEFAULT_SPEC_PATHS
234
306
  ): ProseFinding[] {
235
307
  const findings: ProseFinding[] = []
236
308
  const legacyPattern = legacySlugPattern(legacySlugs)
@@ -249,29 +321,54 @@ export function checkUnresolvableReferences(
249
321
  { pattern: TRANCHE_SLUG_VN_PATTERN, what: 'an internal tranche slug in product code' }
250
322
  ]
251
323
 
324
+ // A spec carries the doctrine-page patterns AND the task-number one: a
325
+ // durable document that copies a plan's task numbers goes stale the moment
326
+ // the plan is renumbered, which is the failure this class was widened for.
327
+ // The doctrine pages themselves are deliberately left out of it — their own
328
+ // report-only sweep names a much larger standing backlog, and a rule that
329
+ // blocks belongs where it can be satisfied file by file.
330
+ const specPatterns: { pattern: RegExp; what: string; group?: number }[] = [
331
+ ...patterns,
332
+ { pattern: TASK_NUMBER_PATTERN, what: 'a task number', group: 2 }
333
+ ]
334
+
252
335
  for (const file of files) {
253
- const cls = classifyProseFile(file.path, readerFacingPrefix, readerFacingSuffix, shipsPrefix)
336
+ const cls = classifyProseFile(file.path, readerFacingPrefix, readerFacingSuffix, shipsPrefix, specPaths)
254
337
  if (!cls || cls === 'internal') continue
255
338
  if (cls !== 'product' && cls !== 'spec' && !SWEPT_CLASSES.has(cls)) continue
256
- // issue-657, O6 — a spec explicitly listed by path is grandfathered
257
- // stock (already failing when this sweep was extended to specs) and is
258
- // skipped entirely, not merely down-graded: the list shrinks as later
259
- // tasks rewrite each spec's prose, never grows.
339
+ // A spec explicitly listed by path is grandfathered stock (already
340
+ // failing when this sweep was extended to specs) and is skipped
341
+ // entirely, not merely down-graded: the list shrinks as each spec's
342
+ // prose is rewritten to state its facts plainly, never grows. The list
343
+ // is matched against every spec-class file, so it exempts a default path
344
+ // (a root spec, a decision record) exactly as it exempts a
345
+ // per-product one — one exemption for the class, not one per path
346
+ // source.
260
347
  if (cls === 'spec' && grandfathered.has(file.path)) continue
261
348
  const blocking = cls === 'product' || cls === 'spec'
262
349
  const scrubbed =
263
350
  cls === 'product' ? stripNonProseForProduct(file.path, file.content) : stripNonProse(file.path, file.content)
264
- // A spec is checked with the SAME rules a doctrine page is (O6) — the
265
- // full reference pattern set, never the narrower product-code list.
266
- const patternsToRun = cls === 'product' ? productPatterns : patterns
351
+ // A spec is checked with the SAME rules a doctrine page is — the full
352
+ // reference pattern set, never the narrower product-code list — plus the
353
+ // task-number rule that applies to this class alone.
354
+ const patternsToRun = cls === 'product' ? productPatterns : cls === 'spec' ? specPatterns : patterns
267
355
  for (const { pattern, what, group } of patternsToRun) {
268
356
  pattern.lastIndex = 0
269
357
  let match: RegExpExecArray | null = pattern.exec(scrubbed)
270
358
  while (match !== null) {
271
359
  const cited = group !== undefined ? (match[group] ?? match[0]) : match[0]
360
+ // The line is the CITED text's own line, not the whole match's. A
361
+ // boundary-checked pattern consumes the character before the
362
+ // citation, and where that character is the newline ending the
363
+ // previous line — a citation that opens a line — the match begins on
364
+ // the previous line and a finding sent the reader there instead.
365
+ // `indexOf` is exact for both shapes in use: the leading boundary is
366
+ // one character that can never itself start the cited text, and an
367
+ // empty boundary (start of file) resolves to offset zero.
368
+ const citedIndex = match.index + match[0].indexOf(cited)
272
369
  findings.push({
273
370
  file: file.path,
274
- line: lineAt(scrubbed, match.index),
371
+ line: lineAt(scrubbed, citedIndex),
275
372
  message: `references ${what} ("${cited}") a reader outside this repo's tracker cannot resolve`,
276
373
  blocking
277
374
  })
@@ -540,7 +637,8 @@ export function checkReaderResolvableProse(
540
637
  readerFacingSuffix: string,
541
638
  legacySlugs: readonly string[] = [],
542
639
  shipsPrefix: string = SHIPS_PREFIX,
543
- specGrandfather: readonly string[] = []
640
+ specGrandfather: readonly string[] = [],
641
+ specPaths: readonly string[] = DEFAULT_SPEC_PATHS
544
642
  ): ProseFinding[] {
545
643
  return [
546
644
  ...checkUnresolvableReferences(
@@ -549,7 +647,8 @@ export function checkReaderResolvableProse(
549
647
  readerFacingSuffix,
550
648
  legacySlugs,
551
649
  shipsPrefix,
552
- specGrandfather
650
+ specGrandfather,
651
+ specPaths
553
652
  ),
554
653
  ...checkUndefinedVocabulary(files, glossaryTerms, readerFacingPrefix, readerFacingSuffix, shipsPrefix)
555
654
  ]