@attalabs/vinaya 0.39.0 → 0.40.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 (151) hide show
  1. package/README.md +9 -9
  2. package/aeg-root/contracts/planner-developer.md +1 -1
  3. package/aeg-root/enforcement.md +22 -22
  4. package/aeg-root/process.md +1 -1
  5. package/aeg-root/roles/archivist.md +1 -1
  6. package/aeg-root/roles/developer/reference.md +4 -1
  7. package/aeg-root/roles/developer.md +1 -1
  8. package/aeg-root/roles/planner/reference.md +18 -5
  9. package/aeg-root/roles/principal.md +1 -1
  10. package/aeg-root/roles/reviewer.md +3 -3
  11. package/aeg-root/roles/security.md +4 -4
  12. package/aeg-root/roles/tranche-archivist.md +2 -2
  13. package/aeg-root/skills/aeg/SKILL.md +1 -1
  14. package/aeg-root/state-machine.md +8 -13
  15. package/aeg-root/templates/brief-template.md +4 -1
  16. package/aeg-root/templates/decision-record-template.md +38 -0
  17. package/aeg-root/templates/issue-rationale-template.md +1 -1
  18. package/aeg-root/tranche-model.md +1 -1
  19. package/dist/checks/bin/check-body-bare-digits.js +1867 -347
  20. package/dist/checks/bin/check-branch-topology.js +1181 -237
  21. package/dist/checks/bin/check-brief-shape.js +1911 -433
  22. package/dist/checks/bin/check-changeset-coverage.js +2144 -517
  23. package/dist/checks/bin/check-ci-shard-coverage.js +12133 -11
  24. package/dist/checks/bin/check-closes-n.js +1181 -237
  25. package/dist/checks/bin/check-coherence.js +1785 -1126
  26. package/dist/checks/bin/check-dead-branch-push.js +1154 -225
  27. package/dist/checks/bin/check-dispatch-readiness.js +2068 -436
  28. package/dist/checks/bin/check-doc-claims.js +2104 -231
  29. package/dist/checks/bin/check-doc-coverage-push.js +2181 -515
  30. package/dist/checks/bin/check-doc-coverage.js +2181 -519
  31. package/dist/checks/bin/check-doctrine-no-procedures.js +1668 -345
  32. package/dist/checks/bin/check-doctrine-portability.js +2143 -516
  33. package/dist/checks/bin/check-evidence-fresh.js +2080 -465
  34. package/dist/checks/bin/check-exec-bits.js +2130 -503
  35. package/dist/checks/bin/check-first-push-dispatch.js +1845 -371
  36. package/dist/checks/bin/check-issue-assignment.js +712 -170
  37. package/dist/checks/bin/check-issue-milestone-attach.js +1145 -225
  38. package/dist/checks/bin/check-issue-objectives-numbering.js +1661 -338
  39. package/dist/checks/bin/check-issue-parts-coverage.js +1145 -225
  40. package/dist/checks/bin/check-issue-surface-globs.js +1787 -369
  41. package/dist/checks/bin/check-issue-title-grammar.js +1145 -225
  42. package/dist/checks/bin/check-issue-tranche-label.js +702 -170
  43. package/dist/checks/bin/check-main-branch-refusal.js +1157 -227
  44. package/dist/checks/bin/check-no-disk-state.js +1145 -225
  45. package/dist/checks/bin/check-pr-premise-reassert.js +1661 -338
  46. package/dist/checks/bin/check-pr-report-density.js +1145 -225
  47. package/dist/checks/bin/check-principal-test-plan-wait.js +2379 -249
  48. package/dist/checks/bin/check-quoted-command.js +2128 -501
  49. package/dist/checks/bin/check-reader-resolvable-prose.js +2170 -517
  50. package/dist/checks/bin/check-registry-gates.js +1228 -272
  51. package/dist/checks/bin/check-retired-vocabulary.js +2153 -507
  52. package/dist/checks/bin/check-review-gate.js +1932 -350
  53. package/dist/checks/bin/check-single-plan-pr.js +1208 -229
  54. package/dist/checks/bin/check-surface-scope.js +1414 -244
  55. package/dist/checks/bin/check-test-plan.js +2381 -252
  56. package/dist/checks/bin/check-token-collection-wired.js +1145 -225
  57. package/dist/checks/bin/check-workspace-escape.js +2141 -514
  58. package/dist/checks/bin/verify-coherence.js +493 -86
  59. package/dist/checks/bin/verify-dispatch.js +512 -132
  60. package/dist/checks/bin/verify-docs.js +549 -124
  61. package/dist/index.js +22702 -17900
  62. package/dist/lib/pre-push-cache-test-run.js +1026 -233
  63. package/dist/lib/pre-push-select-tests.js +922 -173
  64. package/package.json +12 -1
  65. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/anchored-region.ts +13 -2
  66. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/brief-render.ts +55 -26
  67. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/types.ts +12 -1
  68. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dispatch-gate.ts +22 -1
  69. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/doctrine-portability.ts +6 -1
  70. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/entry-point.ts +27 -0
  71. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/gate-audience.ts +2 -1
  72. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/index.ts +19 -2
  73. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/issue-validation.ts +593 -55
  74. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/narration.ts +1 -0
  75. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/pr-report-density.ts +6 -4
  76. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/retired-vocabulary.ts +19 -2
  77. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-policy.ts +32 -13
  78. package/studio-standalone/apps/vinaya-studio/web/.next/BUILD_ID +1 -1
  79. package/studio-standalone/apps/vinaya-studio/web/.next/build-manifest.json +3 -3
  80. package/studio-standalone/apps/vinaya-studio/web/.next/prerender-manifest.json +3 -3
  81. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.html +1 -1
  82. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.rsc +1 -1
  83. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
  84. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  85. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  86. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  87. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  88. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page/server-reference-manifest.json +2 -2
  89. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page.js.nft.json +1 -1
  90. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  91. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page/server-reference-manifest.json +2 -2
  92. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page.js.nft.json +1 -1
  93. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page_client-reference-manifest.js +1 -1
  94. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page/server-reference-manifest.json +2 -2
  95. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page.js +1 -1
  96. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page.js.nft.json +1 -1
  97. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page_client-reference-manifest.js +1 -1
  98. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page/server-reference-manifest.json +2 -2
  99. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page.js +1 -1
  100. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page.js.nft.json +1 -1
  101. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page_client-reference-manifest.js +1 -1
  102. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page/server-reference-manifest.json +2 -2
  103. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page.js +1 -1
  104. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page.js.nft.json +1 -1
  105. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page_client-reference-manifest.js +1 -1
  106. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page/server-reference-manifest.json +3 -3
  107. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page.js +1 -1
  108. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page.js.nft.json +1 -1
  109. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page_client-reference-manifest.js +1 -1
  110. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page/server-reference-manifest.json +2 -2
  111. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page.js +2 -2
  112. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page.js.nft.json +1 -1
  113. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page_client-reference-manifest.js +1 -1
  114. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page/server-reference-manifest.json +2 -2
  115. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page.js +1 -1
  116. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page.js.nft.json +1 -1
  117. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page_client-reference-manifest.js +1 -1
  118. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page/server-reference-manifest.json +2 -2
  119. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page.js +1 -1
  120. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page.js.nft.json +1 -1
  121. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page_client-reference-manifest.js +1 -1
  122. 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
  123. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__08e39jo._.js +1 -1
  124. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__0ls23oh._.js +1 -1
  125. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__0sxadt2._.js +13 -0
  126. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1a3j3n1._.js +57 -0
  127. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1gjqmhq._.js +1 -1
  128. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1wc4-ip._.js +1 -1
  129. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/{[root-of-the-server]__1ug9syi._.js → [root-of-the-server]__1wzfiav._.js} +1 -1
  130. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_08onyya._.js +1 -1
  131. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_096f46i._.js +1 -1
  132. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0af2one._.js +1 -1
  133. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0e5tkdd._.js +1 -1
  134. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0kf2g72._.js +1 -1
  135. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0zf4d27._.js +1 -1
  136. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_1-wo68i._.js +1 -1
  137. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_1achbh9._.js +1 -1
  138. 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
  139. package/studio-standalone/apps/vinaya-studio/web/.next/server/middleware-build-manifest.js +3 -3
  140. package/studio-standalone/apps/vinaya-studio/web/.next/server/pages/500.html +1 -1
  141. package/studio-standalone/apps/vinaya-studio/web/.next/server/server-reference-manifest.js +1 -1
  142. package/studio-standalone/apps/vinaya-studio/web/.next/server/server-reference-manifest.json +4 -4
  143. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{06_55xbp7rcbi.js → 1p3vr9qts86_b.js} +1 -1
  144. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{2brkwv169ygep.js → 21tunzmxjvm2a.js} +1 -1
  145. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{33rszkngkuoko.js → 38kom-9c-oi65.js} +1 -1
  146. package/studio-standalone/apps/vinaya-studio/web/package.json +2 -2
  147. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__04adkz-._.js +0 -57
  148. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__19jyp3m._.js +0 -13
  149. /package/studio-standalone/apps/vinaya-studio/web/.next/static/{D3LiJNIq5FWZxen7CpOSJ → Y3oaZSTSP9PivUuJvxK1W}/_buildManifest.js +0 -0
  150. /package/studio-standalone/apps/vinaya-studio/web/.next/static/{D3LiJNIq5FWZxen7CpOSJ → Y3oaZSTSP9PivUuJvxK1W}/_clientMiddlewareManifest.js +0 -0
  151. /package/studio-standalone/apps/vinaya-studio/web/.next/static/{D3LiJNIq5FWZxen7CpOSJ → Y3oaZSTSP9PivUuJvxK1W}/_ssgManifest.js +0 -0
@@ -27,7 +27,8 @@ 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'
@@ -69,10 +70,37 @@ const RATIONALE_FIELDS: Array<{ name: string; pattern: string }> = [
69
70
 
70
71
  const DEPENDENCY_RATIONALE_FIELD_NAME = 'Dependency rationale'
71
72
 
73
+ /**
74
+ * The three fields a single-fix Issue — one with no tranche label — may omit.
75
+ * Each is tranche prose no gate checks and the render does not need: sizing
76
+ * against sibling tasks, a blast-radius narrative (the blast-radius gate reads
77
+ * the `**Project:**` field and the Surface instead), and the edges to siblings
78
+ * a single fix does not have. Every other field stays required: the render
79
+ * reads the Boundary, the Traps, the Suggested agent-class and the
80
+ * Stop-and-escalate, and `checkRationaleNamesDocs` reads Docs to keep coherent.
81
+ */
82
+ const SINGLE_FIX_OPTIONAL_FIELDS: ReadonlySet<string> = new Set([
83
+ 'Sizing',
84
+ 'Project(s) + blast radius',
85
+ DEPENDENCY_RATIONALE_FIELD_NAME
86
+ ])
87
+
88
+ export type IssueRationaleOptions = {
89
+ /**
90
+ * The Issue is a single fix — its labels carry no `vinaya/tranche:<slug>`.
91
+ * The caller decides from the labels, exactly as it decides whether the
92
+ * check applies at all. Defaults to `false`: the full eight-field form.
93
+ */
94
+ singleFix?: boolean
95
+ }
96
+
72
97
  /**
73
98
  * Every one of the eight Planner's-rationale fields must be present in a task
74
99
  * Issue's body. One error line per missing field, mirroring
75
- * `checkBriefSections`'s error style.
100
+ * `checkBriefSections`'s error style. With `singleFix`, the three fields in
101
+ * `SINGLE_FIX_OPTIONAL_FIELDS` may be absent; one that is present is still
102
+ * graded, so a single-fix Issue that declares edges declares them in the form
103
+ * amend-deps can edit.
76
104
  *
77
105
  * `Dependency rationale` carries a second, stricter requirement the other
78
106
  * seven fields do not: `amendRationaleDeps` (`@attalabs/aeg-forge-state`, the ONLY
@@ -84,12 +112,16 @@ const DEPENDENCY_RATIONALE_FIELD_NAME = 'Dependency rationale'
84
112
  * on the only sanctioned edit path. Importing `SECTION_HEADER` rather than a
85
113
  * second hand-written regex keeps this one grammar.
86
114
  */
87
- export function checkIssueRationale(body: string): IssueSectionResult {
115
+ export function checkIssueRationale(body: string, options: IssueRationaleOptions = {}): IssueSectionResult {
116
+ const singleFix = options.singleFix === true
88
117
  const errors: string[] = []
89
118
  for (const f of RATIONALE_FIELDS) {
90
119
  if (!hasRationaleField(body, f.pattern)) {
120
+ if (singleFix && SINGLE_FIX_OPTIONAL_FIELDS.has(f.name)) continue
91
121
  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).`
122
+ singleFix
123
+ ? `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).`
124
+ : `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
125
  )
94
126
  continue
95
127
  }
@@ -357,33 +389,116 @@ export function checkSurfaceGlobsResolve(body: string, resolvesToFile: (glob: st
357
389
  return { status: errors.length > 0 ? 'fail' : 'pass', errors }
358
390
  }
359
391
 
360
- export type SurfaceScopeViolation = { file: string; glob: string }
361
- export type SurfaceScopeResult = { ok: true } | { ok: false; violations: SurfaceScopeViolation[] }
392
+ /**
393
+ * One changed path the task's `## Surface` does not cover: it crosses an
394
+ * `out:` glob (`glob` names it — the stronger signal, decided first), or it
395
+ * matches no `in:` glob (`glob` is `null`).
396
+ */
397
+ export type BeyondSurfacePath =
398
+ | { path: string; reason: 'out'; glob: string }
399
+ | { path: string; reason: 'in'; glob: null }
362
400
 
363
401
  /**
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.
402
+ * Every path in `changedPaths` the Surface does not cover, in input order —
403
+ * the one measurement the review loop's publication records in the pull
404
+ * request body and the `surface-scope` check compares that record against.
405
+ * An `in:` list with no globs covers everything, so only `out:` crossings
406
+ * count then. Uses the SAME `globCoversPath` every other Surface reader here
407
+ * uses. Pure.
378
408
  */
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 })
409
+ export function beyondSurfacePaths(
410
+ changedPaths: readonly string[],
411
+ surface: Pick<IssueSurface, 'in' | 'out'>
412
+ ): BeyondSurfacePath[] {
413
+ const beyond: BeyondSurfacePath[] = []
414
+ for (const path of changedPaths) {
415
+ const glob = surface.out.find((g) => globCoversPath(g, path))
416
+ if (glob !== undefined) beyond.push({ path, reason: 'out', glob })
417
+ else if (surface.in.length > 0 && !surface.in.some((g) => globCoversPath(g, path)))
418
+ beyond.push({ path, reason: 'in', glob: null })
385
419
  }
386
- return violations.length > 0 ? { ok: false, violations } : { ok: true }
420
+ return beyond
421
+ }
422
+
423
+ /** The block's lead line, written only when the block lists a path. */
424
+ const BEYOND_SURFACE_LEAD =
425
+ '**Beyond the Surface** — recorded by the review-loop driver on every body write; never edit it:'
426
+
427
+ /** 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. */
428
+ function beyondSurfaceLine(entry: BeyondSurfacePath): string {
429
+ return entry.reason === 'out'
430
+ ? `- \`${entry.path}\` crosses the \`out:\` glob \`${entry.glob}\``
431
+ : `- \`${entry.path}\` matches no \`in:\` glob`
432
+ }
433
+
434
+ /** 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. */
435
+ export function renderBeyondSurfaceBlock(entries: readonly BeyondSurfacePath[]): string {
436
+ const inner = entries.length === 0 ? '' : `${[BEYOND_SURFACE_LEAD, ...entries.map(beyondSurfaceLine)].join('\n')}\n`
437
+ return `<!-- AEG:BEYOND-SURFACE:START -->\n${inner}<!-- AEG:BEYOND-SURFACE:END -->`
438
+ }
439
+
440
+ /**
441
+ * `body` with its `AEG:BEYOND-SURFACE` block rewritten to list `entries` —
442
+ * only that marked region is replaced, whatever it held. A body with no such
443
+ * block gets one in its `## Scope` section, just before the `AEG:TIER` pair
444
+ * when that pair sits there, else at the section's end; a body with no
445
+ * `## Scope` section gets one appended. Pure.
446
+ */
447
+ export function withBeyondSurfaceBlock(body: string, entries: readonly BeyondSurfacePath[]): string {
448
+ const block = renderBeyondSurfaceBlock(entries)
449
+ const existing = anchoredRegionBounds(body, 'BEYOND-SURFACE')
450
+ if (existing) return body.slice(0, existing.outerStart) + block + body.slice(existing.outerEnd)
451
+ const masked = maskCode(body)
452
+ const scope = /^##[ \t]+Scope[ \t]*$/m.exec(masked)
453
+ if (!scope) return `${body.replace(/\s*$/, '')}\n\n## Scope\n\n${block}\n`
454
+ const sectionStart = scope.index + scope[0].length
455
+ const nextHeading = /^##?[ \t]/m.exec(masked.slice(sectionStart))
456
+ const sectionEnd = nextHeading ? sectionStart + nextHeading.index : body.length
457
+ const tier = anchoredRegionBounds(body, 'TIER')
458
+ if (tier && tier.outerStart >= sectionStart && tier.outerStart < sectionEnd) {
459
+ return `${body.slice(0, tier.outerStart)}${block}\n\n${body.slice(tier.outerStart)}`
460
+ }
461
+ const before = body.slice(0, sectionEnd).replace(/\s*$/, '')
462
+ const after = body.slice(sectionEnd)
463
+ return `${before}\n\n${block}\n${after.length > 0 ? `\n${after}` : ''}`
464
+ }
465
+
466
+ /**
467
+ * The paths the body's `AEG:BEYOND-SURFACE` block lists, or `[]` when the
468
+ * body carries no such block — an absent record lists nothing.
469
+ */
470
+ export function recordedBeyondSurfacePaths(body: string): string[] {
471
+ const region = anchoredRegion(body, 'BEYOND-SURFACE')
472
+ if (region === null) return []
473
+ const paths: string[] = []
474
+ for (const line of region.split(/\r?\n/)) {
475
+ const m = /^\s*-\s+`([^`]+)`/.exec(line)
476
+ if (m?.[1]) paths.push(m[1])
477
+ }
478
+ return paths
479
+ }
480
+
481
+ export type SurfaceScopeResult = { ok: true } | { ok: false; violation: BeyondSurfacePath }
482
+
483
+ /**
484
+ * **A task-branch PR's changed files outside its Issue's Surface must be
485
+ * recorded, never hidden.** `changedFiles` is the branch's own diff;
486
+ * `recorded` is the pull request body's `AEG:BEYOND-SURFACE` list. Passes
487
+ * when every changed path beyond the Surface (`beyondSurfacePaths`) is
488
+ * recorded; otherwise fails naming the FIRST changed path that is beyond the
489
+ * Surface and not recorded, with the `out:` glob it crosses or the `in:` list
490
+ * it misses.
491
+ *
492
+ * Pure: the caller (a check-bin adapter) resolves every input.
493
+ */
494
+ export function checkSurfaceScope(
495
+ changedFiles: readonly string[],
496
+ surface: Pick<IssueSurface, 'in' | 'out'>,
497
+ recorded: readonly string[]
498
+ ): SurfaceScopeResult {
499
+ const listed = new Set(recorded)
500
+ const violation = beyondSurfacePaths(changedFiles, surface).find((entry) => !listed.has(entry.path))
501
+ return violation ? { ok: false, violation } : { ok: true }
387
502
  }
388
503
 
389
504
  /** One `Part <n> (<refs>) — <outcome>` line, anywhere in the `## Parts` section. */
@@ -600,6 +715,118 @@ export function parseIssueTestPlan(body: string): ParsedIssueSection<IssueTestPl
600
715
  return { ok: true, value: { kind: 'commands', lines, principal } }
601
716
  }
602
717
 
718
+ /**
719
+ * The foreign binaries a dispatched Developer cannot run, as the leading
720
+ * tokens of a command statement: no forge credential for `gh`, no push, no
721
+ * shell outside the sandbox. The reference describes this CLI only, so these
722
+ * stay typed; every operation of the CLI itself is judged by the `needs` its
723
+ * command declares in the command reference (`developerUnrunnableCommand`).
724
+ */
725
+ const DEVELOPER_UNRUNNABLE_FOREIGN_PREFIXES: readonly (readonly string[])[] = [
726
+ ['gh', 'pr', 'merge'],
727
+ ['gh', 'pr', 'review'],
728
+ ['git', 'push'],
729
+ ['ssh']
730
+ ]
731
+
732
+ /** The two spellings the CLI is invoked with: repository source, and the installed binary. */
733
+ const CLI_INVOCATION_PREFIXES: readonly (readonly string[])[] = [['bun', 'apps/cli/src/index.ts'], ['vinaya']]
734
+
735
+ /** What each declared need means for the Developer, named in the refusal. */
736
+ const DEVELOPER_LACKS: Record<string, string> = {
737
+ forge: 'a forge credential',
738
+ 'default-branch': 'a default-branch checkout',
739
+ 'operator-seat': "the Operator's seat"
740
+ }
741
+
742
+ /** `NAME=value` — an environment assignment before the command itself, never the command. */
743
+ const ENV_ASSIGNMENT_RE = /^[A-Za-z_][A-Za-z0-9_]*=/
744
+
745
+ /**
746
+ * The command this statement runs when the reference declares it needs
747
+ * something the Developer lacks, with the need named, or `null`. The
748
+ * longest declared command name that prefixes the tokens after the CLI
749
+ * invocation wins, so `issue objectives edit` is never read as `issue`.
750
+ */
751
+ function developerUnrunnableCommand(
752
+ tokens: string[],
753
+ reference: CommandReferenceFacts
754
+ ): { name: string; lacks: string } | null {
755
+ const invocation = CLI_INVOCATION_PREFIXES.find((p) => p.every((token, i) => tokens[i] === token))
756
+ if (invocation === undefined) return null
757
+ const rest = tokens.slice(invocation.length)
758
+ let best: CommandReferenceEntry | null = null
759
+ for (const command of reference.commands) {
760
+ const words = command.name.split(' ')
761
+ if (!words.every((w, i) => rest[i] === w)) continue
762
+ if (best === null || words.length > best.name.split(' ').length) best = command
763
+ }
764
+ if (best === null || best.needs.length === 0) return null
765
+ return { name: best.name, lacks: best.needs.map((n) => DEVELOPER_LACKS[n] ?? n).join(' and ') }
766
+ }
767
+
768
+ /** The prefix this statement starts with, or `null` — leading env assignments skipped, tokens compared exactly. */
769
+ function developerUnrunnablePrefix(
770
+ statement: string,
771
+ reference: CommandReferenceFacts
772
+ ): { name: string; lacks: string | null } | null {
773
+ const tokens = statement.trim().split(/\s+/).filter(Boolean)
774
+ while (tokens.length > 0 && ENV_ASSIGNMENT_RE.test(tokens[0] as string)) tokens.shift()
775
+ for (const prefix of DEVELOPER_UNRUNNABLE_FOREIGN_PREFIXES) {
776
+ if (prefix.every((token, i) => tokens[i] === token)) return { name: prefix.join(' '), lacks: null }
777
+ }
778
+ return developerUnrunnableCommand(tokens, reference)
779
+ }
780
+
781
+ /**
782
+ * **A Test plan line is one the dispatched Developer can run.** Reads the
783
+ * fenced command lines of `## Test plan` and judges each one statement at a
784
+ * time — `commandStatements`/`stripLineComment`, the same split the
785
+ * whole-suite rule uses, plus an unquoted `|` so a piped command is judged
786
+ * too — by its leading tokens against `DEVELOPER_UNRUNNABLE_PREFIXES`. Prose
787
+ * outside the fence is never judged. Passes when the section is absent or
788
+ * carries the `unit-tests-only` sentinel; `parseIssueTestPlan` reports those
789
+ * shapes.
790
+ */
791
+ export function checkTestPlanDeveloperRunnable(body: string, reference: CommandReferenceFacts): IssueSectionResult {
792
+ const located = locateTestPlanSection(body)
793
+ if (!located.found) return { status: 'pass', errors: [] }
794
+ const lines = extractFencedBlocks(located.section).flatMap((b) =>
795
+ b.content
796
+ .split('\n')
797
+ .map((l) => l.trim())
798
+ .filter((l) => l.length > 0)
799
+ )
800
+ const errors: string[] = []
801
+ for (const line of lines) {
802
+ const statements = commandStatements(line).flatMap((raw) => {
803
+ const stmt = stripLineComment(raw)
804
+ const masked = maskQuoted(stmt)
805
+ const pieces: string[] = []
806
+ let last = 0
807
+ for (let i = 0; i < masked.length; i++) {
808
+ if (masked[i] === '|') {
809
+ pieces.push(stmt.slice(last, i))
810
+ last = i + 1
811
+ }
812
+ }
813
+ pieces.push(stmt.slice(last))
814
+ return pieces
815
+ })
816
+ const hit = statements.map((st) => developerUnrunnablePrefix(st, reference)).find((p) => p !== null)
817
+ if (hit !== undefined && hit !== null) {
818
+ const why =
819
+ hit.lacks === null
820
+ ? 'it holds no forge credential and no shell outside its sandbox'
821
+ : `the command reference declares it needs ${hit.lacks}, which the Developer does not hold`
822
+ errors.push(
823
+ `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.`
824
+ )
825
+ }
826
+ }
827
+ return { status: errors.length > 0 ? 'fail' : 'pass', errors }
828
+ }
829
+
603
830
  /** `## Stop conditions` — a bullet list, each item the outcome-agnostic condition under which the executing agent must stop and escalate. */
604
831
  export function parseIssueStopConditions(body: string): ParsedIssueSection<string[]> {
605
832
  const section = topLevelSectionText(body, 'Stop conditions')
@@ -2407,6 +2634,185 @@ export function checkNoForeignTaskOwnership(body: string): IssueSectionResult {
2407
2634
  return { status: errors.length > 0 ? 'fail' : 'pass', errors }
2408
2635
  }
2409
2636
 
2637
+ /**
2638
+ * One prose field split into sentences: each line, then each `.`/`!`/`?`
2639
+ * followed by whitespace. A dot with no space after it — `issue-validation.ts`,
2640
+ * `checks.timeoutMs` — never ends a sentence, so a backticked path or dotted
2641
+ * value stays inside the sentence that names it.
2642
+ */
2643
+ function proseSentences(text: string): string[] {
2644
+ return text
2645
+ .split('\n')
2646
+ .flatMap((line) => line.split(/(?<=[.!?])\s+/))
2647
+ .map((s) => s.trim())
2648
+ .filter((s) => s.length > 0)
2649
+ }
2650
+
2651
+ /**
2652
+ * The closed list of phrasings that forbid an edit or tell the Developer to
2653
+ * stop on one. Exact, case-insensitive, whitespace-tolerant — never a
2654
+ * classifier: a sentence trips this rule only by carrying one of these
2655
+ * phrases verbatim. Extending the list is a code change, reviewed like any
2656
+ * other, never a heuristic that drifts.
2657
+ */
2658
+ const SURFACE_PROHIBITION_PHRASES: ReadonlyArray<{ phrase: string; re: RegExp }> = [
2659
+ { phrase: 'do not edit', re: /\bdo\s+not\s+edit\b/i },
2660
+ { phrase: 'do not change', re: /\bdo\s+not\s+change\b/i },
2661
+ { phrase: 'do not touch', re: /\bdo\s+not\s+touch\b/i },
2662
+ { phrase: 'never edit', re: /\bnever\s+edit\b/i },
2663
+ { phrase: 'stop if', re: /\bstop\s+if\b/i },
2664
+ { phrase: 'escalate if … cannot', re: /\bescalate\s+if\b.*\bcannot\b/i }
2665
+ ]
2666
+
2667
+ /** A pinned file's module name — its basename up to the first `.` (`issue-validation.test.ts` → `issue-validation`). */
2668
+ function moduleNameOf(file: string): string {
2669
+ const base = file.slice(file.lastIndexOf('/') + 1)
2670
+ const dot = base.indexOf('.')
2671
+ return dot > 0 ? base.slice(0, dot) : base
2672
+ }
2673
+
2674
+ /** Does `sentence` name `module` as `<module> module` (the name optionally backticked)? Whole token only. */
2675
+ function namesModule(sentence: string, module: string): boolean {
2676
+ const escaped = module.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
2677
+ return new RegExp(`(?<![\\w./-])\`?${escaped}\`?\\s+module\\b`, 'i').test(sentence)
2678
+ }
2679
+
2680
+ /**
2681
+ * **A task's prose never forbids a beyond-Surface edit.** The shipped rule is
2682
+ * that a change to a path no Surface `in:` glob covers, or one an `out:` glob
2683
+ * covers, is published anyway: the review-loop driver records it in the pull
2684
+ * request body's beyond-Surface block and the reviewers judge it like any
2685
+ * change. A `Traps to avoid`, `Stop-and-escalate` or `## Stop conditions`
2686
+ * sentence that says "do not edit" such a path, or "stop if" it needs a
2687
+ * change, overrides that rule from inside the brief — and a dispatched task
2688
+ * once paused for a ruling it never needed on exactly that sentence.
2689
+ *
2690
+ * Lexical, and closed: a sentence is refused only when it carries one of
2691
+ * `SURFACE_PROHIBITION_PHRASES` AND names, in the same sentence, a backticked
2692
+ * repository path — or `<module> module` for a Boundary-pinned file — that
2693
+ * `beyondSurfacePaths` (the same measurement the publication records) puts
2694
+ * outside the Surface. Code is never parsed; a sentence about a path an `in:`
2695
+ * glob covers passes. Dormant when `## Surface` does not parse — its own gate
2696
+ * reports that.
2697
+ */
2698
+ export function checkProseAllowsBeyondSurfaceEdit(body: string): IssueSectionResult {
2699
+ const surface = parseIssueSurface(body)
2700
+ if (!surface.ok) return { status: 'pass', errors: [] }
2701
+
2702
+ const text = PATH_TEXT(body)
2703
+ const fields: Array<[string, string]> = [
2704
+ ['Traps to avoid', rationaleFieldText(text, 'Traps')],
2705
+ ['Stop-and-escalate', rationaleFieldText(text, 'Stop-and-escalate')],
2706
+ ['Stop conditions', topLevelSectionText(text, 'Stop conditions') ?? '']
2707
+ ]
2708
+ const outsideModules = beyondSurfacePaths(boundaryPinnedFiles(body), surface.value).map((entry) => ({
2709
+ module: moduleNameOf(entry.path),
2710
+ entry
2711
+ }))
2712
+
2713
+ const errors: string[] = []
2714
+ for (const [name, fieldText] of fields) {
2715
+ for (const sentence of proseSentences(fieldText)) {
2716
+ const prohibition = SURFACE_PROHIBITION_PHRASES.find((p) => p.re.test(sentence))
2717
+ if (!prohibition) continue
2718
+ const beyond = beyondSurfacePaths(namedPathsIn(sentence), surface.value)
2719
+ for (const { module, entry } of outsideModules) {
2720
+ if (namesModule(sentence, module) && !beyond.some((b) => b.path === entry.path)) beyond.push(entry)
2721
+ }
2722
+ for (const entry of beyond) {
2723
+ const why =
2724
+ entry.reason === 'out'
2725
+ ? `the Surface's \`out:\` glob \`${entry.glob}\` covers`
2726
+ : 'no Surface `in:` glob covers'
2727
+ errors.push(
2728
+ `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.`
2729
+ )
2730
+ }
2731
+ }
2732
+ }
2733
+ return { status: errors.length > 0 ? 'fail' : 'pass', errors }
2734
+ }
2735
+
2736
+ /** A bare identifier — `camelCase`, `snake_case`, `kebab-case`, `a.dotted.member` — never a flag, a path or a command line. */
2737
+ const CROSS_TASK_IDENTIFIER_RE = /^[A-Za-z_$][\w$]*(?:[.-][A-Za-z_$][\w$]*)*$/
2738
+ /** A quoted string literal with no whitespace, quote or backslash inside it. */
2739
+ const CROSS_TASK_STRING_LITERAL_RE = /^(['"])([^'"`\s\\]+)\1$/
2740
+
2741
+ /**
2742
+ * The words a sentence uses when THIS task creates the value it names. A
2743
+ * closed list, matched as whole words: a sentence carrying one is the task
2744
+ * stating what it introduces, never what it relies on.
2745
+ */
2746
+ const CREATES_VALUE_RE = /\b(?:add|adds|create|creates|introduce|introduces|define|defines|declare|declares|new)\b/i
2747
+
2748
+ /**
2749
+ * The value one backticked span names, when it reads as an identifier or a
2750
+ * string literal — the literal's contents for a quoted span — or `null` for a
2751
+ * path (`/`), a filename (a file-extension last segment), a command (any
2752
+ * whitespace) or a flag.
2753
+ */
2754
+ function crossTaskValueOf(span: string): string | null {
2755
+ const literal = CROSS_TASK_STRING_LITERAL_RE.exec(span)
2756
+ if (!literal && !CROSS_TASK_IDENTIFIER_RE.test(span)) return null
2757
+ const value = literal ? (literal[2] as string) : span
2758
+ if (value.length < 2 || value.includes('/')) return null
2759
+ const segments = value.split('.')
2760
+ if (segments.length > 1 && FILE_EXTENSIONS.has((segments[segments.length - 1] as string).toLowerCase())) return null
2761
+ return value
2762
+ }
2763
+
2764
+ /**
2765
+ * **A value another task creates is pinned by a premise.** A task that
2766
+ * declares `Depends-on` and names, in its Objectives or its Traps, a
2767
+ * backticked identifier or string literal that no file of the default branch
2768
+ * contains is relying on a task it depends on to create it. That reliance is
2769
+ * a fact about another task's output, so it is written as one: a premise
2770
+ * `after #<n>: `<path>` contains `<value>`` on a task this Issue declares in
2771
+ * `Depends-on`, checked at dispatch. A later task once relied on component
2772
+ * kinds an earlier task never created, and nothing refused it before dispatch.
2773
+ *
2774
+ * Mechanical throughout, no judgment of what the prose means: the value must
2775
+ * be a backticked span `crossTaskValueOf` reads as an identifier or literal,
2776
+ * `existsInTree` (the gate's injected tracked-tree probe) must find it in no
2777
+ * file, and its sentence must carry none of `CREATES_VALUE_RE`'s words — a
2778
+ * sentence saying this task adds the value is the task's own introduction.
2779
+ * Dormant for an Issue that declares no `Depends-on`: with no task to rely on,
2780
+ * a value missing from the tree is this task's own to create.
2781
+ */
2782
+ export function checkCrossTaskValuesPinned(body: string, existsInTree: (token: string) => boolean): IssueSectionResult {
2783
+ const dependsOn = parseRationaleDeps(body).dependsOn
2784
+ if (dependsOn.length === 0) return { status: 'pass', errors: [] }
2785
+ const declared = new Set(dependsOn.map((edge) => (splitSlugQualifiedEdge(edge)?.bareId ?? edge).replace(/^#/, '')))
2786
+ const premises = parseIssuePremises(body)
2787
+ const pinned = (premises.ok ? premises.value : []).filter(
2788
+ (p) => p.afterIssue !== null && declared.has(String(p.afterIssue))
2789
+ )
2790
+
2791
+ const sources: Array<{ where: string; text: string }> = []
2792
+ const objectives = objectivesOf(body)
2793
+ if (objectives.ok) for (const o of objectives.objectives) sources.push({ where: o.id, text: o.text })
2794
+ sources.push({ where: 'Traps to avoid', text: rationaleFieldText(PATH_TEXT(body), 'Traps') })
2795
+
2796
+ const errors: string[] = []
2797
+ const reported = new Set<string>()
2798
+ for (const { where, text } of sources) {
2799
+ for (const sentence of proseSentences(text)) {
2800
+ if (CREATES_VALUE_RE.test(sentence.replace(/`[^`\n]*`/g, ' '))) continue
2801
+ for (const span of backtickedSpans(sentence)) {
2802
+ const value = crossTaskValueOf(span)
2803
+ if (value === null || reported.has(value)) continue
2804
+ if (pinned.some((p) => p.text.includes(value))) continue
2805
+ if (existsInTree(value)) continue
2806
+ reported.add(value)
2807
+ errors.push(
2808
+ `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.`
2809
+ )
2810
+ }
2811
+ }
2812
+ }
2813
+ return { status: errors.length > 0 ? 'fail' : 'pass', errors }
2814
+ }
2815
+
2410
2816
  /**
2411
2817
  * **Parts and Objectives agree by construction, the other half.** A Part
2412
2818
  * citing an objective `## Objectives` does not define is already refused by
@@ -2475,7 +2881,12 @@ export function checkPartsCoverageAndSequence(body: string): IssueSectionResult
2475
2881
  // ---------------------------------------------------------------------------
2476
2882
 
2477
2883
  /** 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[] }
2884
+ export type CommandReferenceEntry = {
2885
+ name: string
2886
+ flags: string[]
2887
+ /** What the command needs beyond the Developer's sandbox (`forge`, `default-branch`, `operator-seat`); empty ⇒ runnable by the Developer. */
2888
+ needs: readonly string[]
2889
+ }
2479
2890
 
2480
2891
  /**
2481
2892
  * The command reference as the caller resolved it. `file` is the tracked file
@@ -2855,40 +3266,77 @@ export function boundaryPinnedFiles(body: string): string[] {
2855
3266
  }
2856
3267
 
2857
3268
  /**
2858
- * **A pinned file's importers are in the Surface, or deliberately out of
3269
+ * What a task decided about one importer of a pinned file: an `in:` glob
3270
+ * reaches it (`by` is that glob), the Boundary's `Out:` clause names it or its
3271
+ * directory (`by` is the named path), or neither (`fix` is the directory glob
3272
+ * that would reach it).
3273
+ */
3274
+ export type PinnedImporterDecision =
3275
+ | { importer: string; state: 'reached'; by: string }
3276
+ | { importer: string; state: 'disclaimed'; by: string }
3277
+ | { importer: string; state: 'uncovered'; fix: string }
3278
+
3279
+ /** One pinned file and the decision made about each of its importers. */
3280
+ export type PinnedFileDecisions = { file: string; importers: PinnedImporterDecision[] }
3281
+
3282
+ /**
3283
+ * Decides every importer of every pinned file against the body's `## Surface`
3284
+ * `in:` globs and its Boundary's `Out:` clause — the one function both the
3285
+ * write gate (`checkPinnedFileImportersCovered`) and the planning report
3286
+ * (`surfaceForcedSet`) read, so the report can never call an importer covered
3287
+ * where the gate calls it uncovered. `null` when `## Surface` does not parse.
3288
+ *
3289
+ * Only those two count. A `## Surface` `out:` glob claims a directory is
3290
+ * untouched, which is exactly what a forced call-site edit contradicts, so it
3291
+ * never excuses an importer; the Boundary's `Out:` clause is the sentence a
3292
+ * Planner writes on purpose to leave one out.
3293
+ */
3294
+ export function decidePinnedFileImporters(
3295
+ body: string,
3296
+ importers: PinnedFileImporters[]
3297
+ ): PinnedFileDecisions[] | null {
3298
+ const surface = parseIssueSurface(body)
3299
+ if (!surface.ok) return null
3300
+ const disclaimed = namedPathsIn(boundaryOutText(body))
3301
+ return importers.map(({ file, importers: found }) => ({
3302
+ file,
3303
+ importers: found.map((importer): PinnedImporterDecision => {
3304
+ const glob = surface.value.in.find((g) => globCoversPath(g, importer))
3305
+ if (glob !== undefined) return { importer, state: 'reached', by: glob }
3306
+ const named = disclaimed.find((d) => globCoversPath(d, importer))
3307
+ if (named !== undefined) return { importer, state: 'disclaimed', by: named }
3308
+ return { importer, state: 'uncovered', fix: directoryGlobFor(importer) }
3309
+ })
3310
+ }))
3311
+ }
3312
+
3313
+ /**
3314
+ * **Every importer of a pinned file is in the Surface, or deliberately out of
2859
3315
  * 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.
3316
+ * change at the call site; a Surface that reaches the pinned file and leaves
3317
+ * one of its importers undecided is the shape that pauses a task at publish,
3318
+ * because the caller — or the inventory test that lists the changed thing —
3319
+ * that had to change sat outside it.
3320
+ *
3321
+ * Each importer is decided by `decidePinnedFileImporters`: reached by an `in:`
3322
+ * glob, or named (itself or its directory) in the Boundary's `Out:` clause.
3323
+ * Refused when ANY importer is neither — one covered importer no longer
3324
+ * speaks for the others, since a call site in one directory says nothing
3325
+ * about a test in another.
2875
3326
  */
2876
3327
  export function checkPinnedFileImportersCovered(body: string, importers: PinnedFileImporters[]): IssueSectionResult {
2877
3328
  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))
3329
+ const decided = decidePinnedFileImporters(body, importers)
3330
+ if (decided === null) return { status: 'pass', errors: [] }
2881
3331
 
2882
3332
  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))
3333
+ for (const { file, importers: decisions } of decided) {
3334
+ const uncovered = decisions.filter(
3335
+ (d): d is Extract<PinnedImporterDecision, { state: 'uncovered' }> => d.state === 'uncovered'
2887
3336
  )
2888
- if (uncovered.length < found.length) continue
2889
- const globs = [...new Set(uncovered.map(directoryGlobFor))]
3337
+ if (uncovered.length === 0) continue
2890
3338
  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).`
3339
+ `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
3340
  )
2893
3341
  }
2894
3342
  return { status: errors.length > 0 ? 'fail' : 'pass', errors }
@@ -2974,6 +3422,59 @@ export function checkNewLoopFilesCoverInvariantMap(body: string, tracked: string
2974
3422
  }
2975
3423
  }
2976
3424
 
3425
+ /** A forced companion file and whether an `in:` glob already reaches it. */
3426
+ export type ForcedCompanion = { path: string; reached: boolean }
3427
+
3428
+ /** What a draft Issue's Boundary pins force on its Surface — the `vinaya issue surface` report. */
3429
+ export type SurfaceForcedSet = {
3430
+ /** Every importer of every pinned file, decided by `decidePinnedFileImporters` — the write gate's own reading. */
3431
+ importers: PinnedFileDecisions[]
3432
+ /** The CI shard requirement, present only when a pinned CLI test file is new. */
3433
+ ciShards: { newFiles: string[]; companion: ForcedCompanion; fix: string } | null
3434
+ /** The loop invariant map requirement, present only when a pinned loop file is new. */
3435
+ loopInvariantMap: { newFiles: string[]; companions: ForcedCompanion[]; fix: string[] } | null
3436
+ }
3437
+
3438
+ /**
3439
+ * Everything a draft Issue's Boundary pins force, computed from the same
3440
+ * functions the write gate refuses with: `decidePinnedFileImporters` for the
3441
+ * importers, and the new-file readings of `checkNewTestFilesCoverShards` and
3442
+ * `checkNewLoopFilesCoverInvariantMap` for the shard list and the loop map.
3443
+ * Writes nothing; `null` when `## Surface` does not parse. With no tracked
3444
+ * tree the new-file companions are unknown and reported absent, exactly as
3445
+ * the two rules go dormant.
3446
+ */
3447
+ export function surfaceForcedSet(
3448
+ body: string,
3449
+ importers: PinnedFileImporters[],
3450
+ tracked: string[]
3451
+ ): SurfaceForcedSet | null {
3452
+ const surface = parseIssueSurface(body)
3453
+ const decided = decidePinnedFileImporters(body, importers)
3454
+ if (!surface.ok || decided === null) return null
3455
+ const reached = (path: string): ForcedCompanion => ({
3456
+ path,
3457
+ reached: surface.value.in.some((g) => globCoversPath(g, path))
3458
+ })
3459
+
3460
+ const newTests = tracked.length === 0 ? [] : newPinnedFiles(body, tracked, isCliTestPath)
3461
+ const newLoop = tracked.length === 0 ? [] : newPinnedFiles(body, tracked, isLoopSurfacePath)
3462
+ const loopCompanions = [LOOP_INVARIANT_FIXTURE, LOOP_INVARIANT_SPEC].map(reached)
3463
+ return {
3464
+ importers: decided,
3465
+ ciShards:
3466
+ newTests.length === 0 ? null : { newFiles: newTests, companion: reached(CI_SHARD_PROBE), fix: CI_SHARD_DIR },
3467
+ loopInvariantMap:
3468
+ newLoop.length === 0
3469
+ ? null
3470
+ : {
3471
+ newFiles: newLoop,
3472
+ companions: loopCompanions,
3473
+ fix: [...new Set(loopCompanions.filter((c) => !c.reached).map((c) => directoryGlobFor(c.path)))]
3474
+ }
3475
+ }
3476
+ }
3477
+
2977
3478
  /**
2978
3479
  * Is this URL host a loopback, link-local, private-range or otherwise
2979
3480
  * non-public address? A Documentation source is public documentation; probing
@@ -3003,7 +3504,10 @@ export function isNonPublicHost(hostname: string): boolean {
3003
3504
  }
3004
3505
 
3005
3506
  /** What an unauthenticated fetch of a Documentation URL came to. */
3006
- export type DocumentationProbe = { kind: 'readable' } | { kind: 'unreadable'; detail: string } | { kind: 'unknown' }
3507
+ export type DocumentationProbe =
3508
+ | { kind: 'readable' }
3509
+ | { kind: 'unreadable'; detail: string }
3510
+ | { kind: 'unknown'; reason?: 'rate-limited' }
3007
3511
 
3008
3512
  const DOCUMENTATION_URL_RE = /https?:\/\/[^\s<>()`'"\]]+/g
3009
3513
 
@@ -3083,6 +3587,10 @@ export function checkDocumentationReadable(
3083
3587
  errors.push(
3084
3588
  `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
3589
  )
3590
+ } else if (result.kind === 'unknown' && result.reason === 'rate-limited') {
3591
+ warnings.push(
3592
+ `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.`
3593
+ )
3086
3594
  } else if (result.kind === 'unknown') {
3087
3595
  warnings.push(
3088
3596
  `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 +3600,36 @@ export function checkDocumentationReadable(
3092
3600
  return { status: errors.length > 0 ? 'fail' : 'pass', errors, warnings }
3093
3601
  }
3094
3602
 
3603
+ /**
3604
+ * **An in-repository Documentation source exists in the checkout.** A source
3605
+ * carrying a URL scheme belongs to `checkDocumentationReadable` and is never
3606
+ * probed here; any other source is a repository path — its first inline code
3607
+ * span when it has one, else the whole source, with a `#fragment` dropped —
3608
+ * read through the injected `readFile` (this module reads no `fs`), and
3609
+ * refused when the read answers `null`. Passes on the `None` sentinel and on
3610
+ * a section that does not parse; `parseIssueDocumentation` reports that.
3611
+ */
3612
+ export function checkDocumentationPathsExist(
3613
+ body: string,
3614
+ readFile: (path: string) => string | null
3615
+ ): IssueSectionResult {
3616
+ const documentation = parseIssueDocumentation(body)
3617
+ if (!documentation.ok || documentation.value.kind === 'none') return { status: 'pass', errors: [] }
3618
+ const errors: string[] = []
3619
+ for (const { source } of documentation.value.sources) {
3620
+ if (/[a-z][a-z0-9+.-]*:\/\//i.test(source)) continue
3621
+ const span = /`([^`]+)`/.exec(source)
3622
+ const path = (span ? (span[1] as string) : source).trim().replace(/#.*$/, '')
3623
+ if (path.length === 0) continue
3624
+ if (readFile(path) === null) {
3625
+ errors.push(
3626
+ `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.`
3627
+ )
3628
+ }
3629
+ }
3630
+ return { status: errors.length > 0 ? 'fail' : 'pass', errors }
3631
+ }
3632
+
3095
3633
  // ---------------------------------------------------------------------------
3096
3634
  // O3 — an edit that changes
3097
3635
  // `## Objectives`, `## Surface`, or `## Parts` on a task Issue whose brief is