@attalabs/vinaya 0.40.0 → 0.41.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (157) hide show
  1. package/aeg-root/contracts/developer-reviewer.md +2 -2
  2. package/aeg-root/contracts/planner-developer.md +4 -4
  3. package/aeg-root/process.md +3 -3
  4. package/aeg-root/roles/developer/reference.md +3 -0
  5. package/aeg-root/state-machine.md +2 -2
  6. package/aeg-root/templates/brief-template.md +1 -1
  7. package/dist/checks/bin/check-body-bare-digits.js +165 -65
  8. package/dist/checks/bin/check-branch-topology.js +169 -60
  9. package/dist/checks/bin/check-brief-shape.js +165 -65
  10. package/dist/checks/bin/check-changeset-coverage.js +342 -122
  11. package/dist/checks/bin/check-ci-shard-coverage.js +384 -130
  12. package/dist/checks/bin/check-closes-n.js +169 -60
  13. package/dist/checks/bin/check-coherence.js +165 -65
  14. package/dist/checks/bin/check-dead-branch-push.js +142 -59
  15. package/dist/checks/bin/check-dispatch-readiness.js +211 -81
  16. package/dist/checks/bin/check-doc-claims.js +165 -65
  17. package/dist/checks/bin/check-doc-coverage-push.js +342 -122
  18. package/dist/checks/bin/check-doc-coverage.js +344 -124
  19. package/dist/checks/bin/check-doctrine-no-procedures.js +165 -65
  20. package/dist/checks/bin/check-doctrine-portability.js +342 -122
  21. package/dist/checks/bin/check-evidence-fresh.js +376 -129
  22. package/dist/checks/bin/check-exec-bits.js +342 -122
  23. package/dist/checks/bin/check-first-push-dispatch.js +208 -78
  24. package/dist/checks/bin/check-issue-milestone-attach.js +142 -59
  25. package/dist/checks/bin/check-issue-objectives-numbering.js +165 -65
  26. package/dist/checks/bin/check-issue-parts-coverage.js +142 -59
  27. package/dist/checks/bin/check-issue-surface-globs.js +218 -88
  28. package/dist/checks/bin/check-issue-title-grammar.js +142 -59
  29. package/dist/checks/bin/check-main-branch-refusal.js +142 -59
  30. package/dist/checks/bin/check-no-disk-state.js +142 -59
  31. package/dist/checks/bin/check-pr-premise-reassert.js +165 -65
  32. package/dist/checks/bin/check-pr-report-density.js +142 -59
  33. package/dist/checks/bin/check-principal-test-plan-wait.js +165 -65
  34. package/dist/checks/bin/check-quoted-command.js +338 -118
  35. package/dist/checks/bin/check-reader-resolvable-prose.js +338 -118
  36. package/dist/checks/bin/check-registry-gates.js +206 -78
  37. package/dist/checks/bin/check-retired-vocabulary.js +338 -118
  38. package/dist/checks/bin/check-review-gate.js +203 -83
  39. package/dist/checks/bin/check-single-plan-pr.js +142 -59
  40. package/dist/checks/bin/check-surface-scope.js +169 -60
  41. package/dist/checks/bin/check-test-plan.js +165 -65
  42. package/dist/checks/bin/check-token-collection-wired.js +142 -59
  43. package/dist/checks/bin/check-workspace-escape.js +340 -120
  44. package/dist/checks/bin/verify-coherence.js +153 -60
  45. package/dist/checks/bin/verify-dispatch.js +169 -69
  46. package/dist/checks/bin/verify-docs.js +142 -57
  47. package/dist/index.js +16280 -11764
  48. package/dist/lib/pre-push-cache-test-run.js +791 -68
  49. package/dist/lib/pre-push-changed-files.js +65 -19
  50. package/dist/lib/pre-push-mode.js +466 -0
  51. package/dist/lib/pre-push-progress-dir.js +4205 -0
  52. package/dist/lib/pre-push-record-tests.js +446 -0
  53. package/dist/lib/pre-push-select-tests.js +1426 -454
  54. package/dist/lib/push-progress-observer.js +4213 -0
  55. package/package.json +11 -5
  56. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/anchored-region.ts +5 -2
  57. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/brief-render.ts +18 -4
  58. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/brief-validation.ts +3 -3
  59. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/coherence-checks.ts +2 -2
  60. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/control-store/local.ts +88 -5
  61. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/control-store/records.ts +34 -2
  62. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/assess-round.ts +26 -4
  63. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/fakes.ts +7 -2
  64. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/index.ts +7 -1
  65. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/types.ts +17 -2
  66. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dispatch-gate.ts +13 -17
  67. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/docs/index.ts +1 -1
  68. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/docs/published-prose.ts +70 -45
  69. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/gate-audience.ts +1 -4
  70. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/index.ts +77 -7
  71. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/issue-assignment.ts +24 -54
  72. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/issue-validation.ts +221 -56
  73. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/live-record.ts +179 -0
  74. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/envelope.ts +8 -2
  75. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/index.ts +1 -0
  76. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/narration.ts +1 -0
  77. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/schema-digest.ts +225 -0
  78. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/schema.ts +7 -1
  79. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/main-branch-refusal.ts +23 -1
  80. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/principals-config.ts +44 -0
  81. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/prose-rules.ts +532 -0
  82. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/protected-paths.ts +31 -0
  83. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/reader-resolvable-prose.ts +157 -80
  84. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/registry-checks.ts +8 -12
  85. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/retired-vocabulary.ts +52 -109
  86. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-gate.ts +46 -17
  87. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-input-manifest.ts +85 -1
  88. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/ruling-ordinal.ts +46 -0
  89. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/task-branch-identity.ts +2 -4
  90. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/test-plan-gate.ts +63 -8
  91. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/verdict-extraction.ts +24 -0
  92. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/waiver-label.ts +0 -1
  93. package/studio-standalone/apps/vinaya-studio/web/.next/BUILD_ID +1 -1
  94. package/studio-standalone/apps/vinaya-studio/web/.next/build-manifest.json +3 -3
  95. package/studio-standalone/apps/vinaya-studio/web/.next/prerender-manifest.json +3 -3
  96. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.html +1 -1
  97. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.rsc +1 -1
  98. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
  99. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  100. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  101. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  102. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  103. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page/server-reference-manifest.json +2 -2
  104. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page.js.nft.json +1 -1
  105. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  106. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page/server-reference-manifest.json +2 -2
  107. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page.js.nft.json +1 -1
  108. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page_client-reference-manifest.js +1 -1
  109. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page/server-reference-manifest.json +2 -2
  110. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page.js.nft.json +1 -1
  111. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page_client-reference-manifest.js +1 -1
  112. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page/server-reference-manifest.json +2 -2
  113. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page.js.nft.json +1 -1
  114. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page_client-reference-manifest.js +1 -1
  115. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page/server-reference-manifest.json +2 -2
  116. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page.js.nft.json +1 -1
  117. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page_client-reference-manifest.js +1 -1
  118. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page/server-reference-manifest.json +3 -3
  119. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page.js.nft.json +1 -1
  120. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page_client-reference-manifest.js +1 -1
  121. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page/server-reference-manifest.json +2 -2
  122. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page.js.nft.json +1 -1
  123. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page_client-reference-manifest.js +1 -1
  124. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page/server-reference-manifest.json +2 -2
  125. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page.js.nft.json +1 -1
  126. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page_client-reference-manifest.js +1 -1
  127. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page/server-reference-manifest.json +2 -2
  128. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page.js.nft.json +1 -1
  129. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page_client-reference-manifest.js +1 -1
  130. 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
  131. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__08e39jo._.js +1 -1
  132. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__0ls23oh._.js +1 -1
  133. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1a3j3n1._.js +1 -1
  134. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/{[root-of-the-server]__1wzfiav._.js → [root-of-the-server]__1d4eth3._.js} +1 -1
  135. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1gjqmhq._.js +1 -1
  136. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1snpgaw._.js +3 -3
  137. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1wc4-ip._.js +1 -1
  138. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_08onyya._.js +2 -2
  139. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_096f46i._.js +1 -1
  140. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0af2one._.js +1 -1
  141. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0e5tkdd._.js +1 -1
  142. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0kf2g72._.js +1 -1
  143. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0zf4d27._.js +3 -3
  144. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_1-wo68i._.js +1 -1
  145. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_1achbh9._.js +1 -1
  146. 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
  147. package/studio-standalone/apps/vinaya-studio/web/.next/server/middleware-build-manifest.js +3 -3
  148. package/studio-standalone/apps/vinaya-studio/web/.next/server/pages/500.html +1 -1
  149. package/studio-standalone/apps/vinaya-studio/web/.next/server/server-reference-manifest.js +1 -1
  150. package/studio-standalone/apps/vinaya-studio/web/.next/server/server-reference-manifest.json +4 -4
  151. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{38kom-9c-oi65.js → 0x7u6si-ai179.js} +1 -1
  152. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{1p3vr9qts86_b.js → 2fu7mfsj4oima.js} +1 -1
  153. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{21tunzmxjvm2a.js → 34b4ruddunn3q.js} +1 -1
  154. package/studio-standalone/apps/vinaya-studio/web/package.json +2 -2
  155. /package/studio-standalone/apps/vinaya-studio/web/.next/static/{Y3oaZSTSP9PivUuJvxK1W → 2ZARxTwpuRew8-SvYsRdU}/_buildManifest.js +0 -0
  156. /package/studio-standalone/apps/vinaya-studio/web/.next/static/{Y3oaZSTSP9PivUuJvxK1W → 2ZARxTwpuRew8-SvYsRdU}/_clientMiddlewareManifest.js +0 -0
  157. /package/studio-standalone/apps/vinaya-studio/web/.next/static/{Y3oaZSTSP9PivUuJvxK1W → 2ZARxTwpuRew8-SvYsRdU}/_ssgManifest.js +0 -0
@@ -34,6 +34,7 @@ import { type ClaimBinding, type ClaimVoice, evaluateClaimBindings } from './doc
34
34
  import { DOC_OWNERS_PATH, isUrlPointer, parseDocOwners, pointerToPath } from './doc-owners'
35
35
  import { globsOverlap } from './derive-section7'
36
36
  import { objectivesOf, objectivesVersion } from './objectives'
37
+ import { isProtectedAdminPath, normalizeTouchedPath } from './protected-paths'
37
38
  import { isValidCitedFilePath } from './quoted-command'
38
39
  import { locateTestPlanSection } from './test-plan-section'
39
40
 
@@ -294,7 +295,16 @@ function splitGlobList(raw: string): string[] {
294
295
 
295
296
  export type IssueSurface = { in: string[]; out: string[] }
296
297
  export type IssuePart = { n: number; objectiveIds: number[]; text: string }
297
- export type IssueTestPlan = { kind: 'unit-tests-only' } | { kind: 'commands'; lines: string[]; principal: string[] }
298
+ /**
299
+ * A `## Test plan`'s three kinds of check: `lines`, the fenced commands the
300
+ * Developer runs; `principal`, the items only a person can judge; and
301
+ * `live`, the commands that need real signed-in agent sessions and that the
302
+ * review loop runs itself, on its own host, only on a head both reviewers
303
+ * approved.
304
+ */
305
+ export type IssueTestPlan =
306
+ | { kind: 'unit-tests-only' }
307
+ | { kind: 'commands'; lines: string[]; principal: string[]; live: string[] }
298
308
 
299
309
  type ParsedIssueSection<T> = { ok: true; value: T } | { ok: false; errors: string[] }
300
310
 
@@ -356,14 +366,13 @@ export function globCoversPath(glob: string, path: string): boolean {
356
366
 
357
367
  /**
358
368
  * **O1 — a declared Surface glob must resolve.** Every `## Surface` `in:`
359
- * glob must match at least one real tracked file, or a Surface that cannot
360
- * render a file list is caught at authoring time instead of at dispatch
361
- * (`brief-assembly.ts`'s own render-time sanity check, which currently
362
- * catches the identical defect too late). `resolvesToFile` is injected —
363
- * this module stays pure, no `git`/`fs` — and the caller
369
+ * glob must either match a real tracked file or contain a file pinned by the
370
+ * Boundary. The latter permits a task to create a new directory while still
371
+ * refusing a typo'd or otherwise empty Surface entry. `resolvesToFile` is
372
+ * injected — this module stays pure, no `git`/`fs` — and the caller
364
373
  * (`forge-write.ts`) passes the SAME `expandGlob` predicate
365
- * `brief-assembly.ts` already uses to render, so the gate and the renderer
366
- * can never disagree about whether a glob resolves.
374
+ * `brief-assembly.ts` uses alongside `boundaryPinnedFiles`, so the gate and
375
+ * both render paths share this resolution rule.
367
376
  *
368
377
  * A backtick-wrapped glob (`` `packages/foo/**` ``) is not stripped or
369
378
  * specially refused here: the literal backticks are part of the string
@@ -375,12 +384,23 @@ export function globCoversPath(glob: string, path: string): boolean {
375
384
  * does not yet exist (a directory not yet created) is a legitimate
376
385
  * exclusion, not a defect.
377
386
  */
387
+ export function surfaceEntryResolves(
388
+ entry: string,
389
+ resolvesToFile: (glob: string) => boolean,
390
+ pinnedFiles: readonly string[]
391
+ ): boolean {
392
+ if (resolvesToFile(entry)) return true
393
+ const directory = entry.replace(/\/\*\*?$/, '').replace(/\/+$/, '')
394
+ return pinnedFiles.some((path) => path.startsWith(`${directory}/`))
395
+ }
396
+
378
397
  export function checkSurfaceGlobsResolve(body: string, resolvesToFile: (glob: string) => boolean): IssueSectionResult {
379
398
  const surface = parseIssueSurface(body)
380
399
  if (!surface.ok) return { status: 'pass', errors: [] }
400
+ const pinnedFiles = boundaryPinnedFiles(body)
381
401
  const errors: string[] = []
382
402
  for (const glob of surface.value.in) {
383
- if (!resolvesToFile(glob)) {
403
+ if (!surfaceEntryResolves(glob, resolvesToFile, pinnedFiles)) {
384
404
  errors.push(
385
405
  `issue-validation Surface: \`${glob}\` in \`## Surface\`'s \`in:\` list matches no tracked file — a Surface that cannot resolve cannot render a brief's file list.`
386
406
  )
@@ -478,7 +498,13 @@ export function recordedBeyondSurfacePaths(body: string): string[] {
478
498
  return paths
479
499
  }
480
500
 
481
- export type SurfaceScopeResult = { ok: true } | { ok: false; violation: BeyondSurfacePath }
501
+ /** A changed path that is a protected administrative path no `in:` glob of the Surface covers. */
502
+ export type ProtectedPathViolation = { path: string; reason: 'protected' }
503
+
504
+ export type SurfaceScopeResult =
505
+ | { ok: true }
506
+ | { ok: false; violation: BeyondSurfacePath }
507
+ | { ok: false; violation: ProtectedPathViolation }
482
508
 
483
509
  /**
484
510
  * **A task-branch PR's changed files outside its Issue's Surface must be
@@ -489,6 +515,12 @@ export type SurfaceScopeResult = { ok: true } | { ok: false; violation: BeyondSu
489
515
  * Surface and not recorded, with the `out:` glob it crosses or the `in:` list
490
516
  * it misses.
491
517
  *
518
+ * Decided first, and never excused by the record: a changed path that, once
519
+ * normalized, is a protected administrative path and is covered by no `in:`
520
+ * glob. An empty `in:` list covers no protected path — the broker's rule —
521
+ * unlike `beyondSurfacePaths`, where an empty `in:` covers everything. The
522
+ * `out:` globs play no part, as in the broker.
523
+ *
492
524
  * Pure: the caller (a check-bin adapter) resolves every input.
493
525
  */
494
526
  export function checkSurfaceScope(
@@ -496,6 +528,13 @@ export function checkSurfaceScope(
496
528
  surface: Pick<IssueSurface, 'in' | 'out'>,
497
529
  recorded: readonly string[]
498
530
  ): SurfaceScopeResult {
531
+ for (const path of changedFiles) {
532
+ if (!isProtectedAdminPath(path)) continue
533
+ const normalized = normalizeTouchedPath(path)
534
+ if (!surface.in.some((glob) => globCoversPath(glob, normalized))) {
535
+ return { ok: false, violation: { path, reason: 'protected' } }
536
+ }
537
+ }
499
538
  const listed = new Set(recorded)
500
539
  const violation = beyondSurfacePaths(changedFiles, surface).find((entry) => !listed.has(entry.path))
501
540
  return violation ? { ok: false, violation } : { ok: true }
@@ -581,6 +620,8 @@ export function checkPartsCiteDefinedObjectives(body: string): IssueSectionResul
581
620
  }
582
621
 
583
622
  const ISSUE_PRINCIPAL_LINE_RE = /^-\s*\[[ xX]\]\s*\*{2}\[principal\]\*{2}(.*)$/gim
623
+ /** `- **[live]** <command>` — never a checkbox: a machine judges it, so there is no box for anyone to tick. */
624
+ const ISSUE_LIVE_LINE_RE = /^-\s*\*{2}\[live\]\*{2}(.*)$/gim
584
625
  const UNIT_TESTS_ONLY_SENTINEL_RE = /(?:\*\*)?Test plan(?:\*\*)?\s*:\s*(?:\*\*)?\s*unit-tests-only/i
585
626
 
586
627
  /**
@@ -657,10 +698,33 @@ function isWholeSuiteTestPlanLine(line: string): boolean {
657
698
  return false
658
699
  }
659
700
 
701
+ /** A `[live]` item's command: the item's text, one enclosing code span removed. */
702
+ function liveCommand(text: string): string {
703
+ const trimmed = text.trim()
704
+ const span = /^(`+)(.+)\1$/.exec(trimmed)
705
+ return span ? (span[2] as string).trim() : trimmed
706
+ }
707
+
708
+ function liveItemsIn(region: string): string[] {
709
+ return [...region.matchAll(ISSUE_LIVE_LINE_RE)].map((m) => liveCommand(m[1] ?? '')).filter(Boolean)
710
+ }
711
+
712
+ /**
713
+ * The `[live]` commands of a body's Test plan section — an Issue's
714
+ * `## Test plan` or a rendered brief's `## 9. Test Plan` — in order, `[]`
715
+ * when it has none. Reads those items alone, so the review loop's live check
716
+ * never depends on how the rest of the plan parses.
717
+ */
718
+ export function parseLiveTestPlanItems(body: string): string[] {
719
+ const located = locateTestPlanSection(body)
720
+ return located.found ? liveItemsIn(located.section) : []
721
+ }
722
+
660
723
  /**
661
724
  * `## Test plan` — reuses `checkTestPlan`/`extractFencedBlocks`
662
725
  * (`brief-validation.ts`) rather than a second parser: the `unit-tests-only`
663
- * sentinel, or a fenced command list plus optional `**[principal]**` items.
726
+ * sentinel, or a fenced command list plus optional `**[principal]**` and
727
+ * `**[live]**` items.
664
728
  * The two forms are mutually exclusive, same rule `checkTestPlanExclusivity`
665
729
  * applies to a PR body's Test Plan.
666
730
  */
@@ -704,15 +768,16 @@ export function parseIssueTestPlan(body: string): ParsedIssueSection<IssueTestPl
704
768
  }
705
769
 
706
770
  const principal = [...region.matchAll(ISSUE_PRINCIPAL_LINE_RE)].map((m) => (m[1] ?? '').trim()).filter(Boolean)
707
- if (lines.length === 0 && principal.length === 0) {
771
+ const live = liveItemsIn(region)
772
+ if (lines.length === 0 && principal.length === 0 && live.length === 0) {
708
773
  return {
709
774
  ok: false,
710
775
  errors: [
711
- '`## Test plan` carries neither the `unit-tests-only` sentinel, a fenced command list, nor a `**[principal]**` item.'
776
+ '`## Test plan` carries neither the `unit-tests-only` sentinel, a fenced command list, a `**[principal]**` item, nor a `**[live]**` item.'
712
777
  ]
713
778
  }
714
779
  }
715
- return { ok: true, value: { kind: 'commands', lines, principal } }
780
+ return { ok: true, value: { kind: 'commands', lines, principal, live } }
716
781
  }
717
782
 
718
783
  /**
@@ -1261,13 +1326,13 @@ const OBJECTIVES_HEADING_RE = /^##[ \t]*Objectives[ \t]*$/im
1261
1326
 
1262
1327
  /**
1263
1328
  * **O1 — is this body task-Issue-shaped at all?** The
1264
- * forge-write label gate (`forge-write.ts`'s `refuseUnlabeledTaskShapedBody`,
1265
- * and `bin/open-issue.ts`'s mirrored inline check) uses this to catch a
1266
- * Planner's mistake `isTaskIssueLabelSet`-gated validation cannot see: a body
1267
- * that carries the Planner's judgment sections but no `vinaya/tranche:*`
1268
- * label reads, to every check gated behind `isTaskIssueLabelSet`, as "not a
1269
- * task Issue" and sails through unvalidated — the exact hole a task Issue
1270
- * never reaching the forge unlabeled falls through.
1329
+ * Issue create and edit gates (`forge-write.ts`'s `writeValidatedIssueEdit`
1330
+ * and the `issue create`/`issue edit` commands) widen brief-schema
1331
+ * validation with this beyond `isTaskIssueLabelSet`: a body that carries the
1332
+ * Planner's judgment sections but no `vinaya/tranche:*` label — a backlog
1333
+ * Issue — would otherwise read, to every check gated behind
1334
+ * `isTaskIssueLabelSet` alone, as "not a task Issue" and sail through
1335
+ * unvalidated.
1271
1336
  *
1272
1337
  * Two signals, either sufficient: a real `## Objectives` heading, or any ONE
1273
1338
  * of the eight Planner's-rationale fields (`hasRationaleField` — the same
@@ -1287,30 +1352,6 @@ export function isTaskIssueBodyShaped(body: string): boolean {
1287
1352
  return RATIONALE_FIELDS.some((f) => hasRationaleField(text, f.pattern))
1288
1353
  }
1289
1354
 
1290
- /**
1291
- * task 17, O2 — one of the six write-only rules given a name apart: a task-
1292
- * shaped Issue body reaching the forge with no `vinaya/tranche:*` label. Pure
1293
- * over `isTaskIssueBodyShaped`/`isTaskIssueLabelSet` — the exact predicate
1294
- * `forge-write.ts`'s `refuseUnlabeledTaskShapedBody` and `bin/open-issue.ts`'s
1295
- * mirrored inline check already enforce; this names it once so a registered
1296
- * `issue`-scope check and the coherence sweep can both call the SAME
1297
- * function instead of re-deriving the same two-line condition.
1298
- *
1299
- * **Retired to an always-pass check.** A task-
1300
- * shaped body reaching the forge with no `vinaya/tranche:*` label is no
1301
- * longer, by itself, evidence of a mistake — it is the exact shape of a
1302
- * legitimate backlog Issue (`task run --issue <n>`'s own dispatch target),
1303
- * which carries the same body grammar as a tranche task with the label
1304
- * simply omitted. The invariant this rule enforced ("a task Issue never
1305
- * reaches the forge unlabeled") no longer holds; kept as a function (never
1306
- * deleted) so every caller above stays wired to one place rather than three
1307
- * independently-updated copies, and so a future rule needing this exact
1308
- * shape has somewhere to register itself apart from a fresh predicate.
1309
- */
1310
- export function checkTrancheLabelPresence(_body: string, _labels: string[]): IssueSectionResult {
1311
- return { status: 'pass', errors: [] }
1312
- }
1313
-
1314
1355
  /**
1315
1356
  * task 17, O2 — the Milestone-attach rule's validating half. The auto-attach
1316
1357
  * ACTION (`resolveMilestoneAttachArgs`/`resolveMilestoneTitleForCreate` in
@@ -1795,11 +1836,11 @@ const BLAST_RADIUS_ACK_RE = /(?:\*\*)?blast-radius-ack(?:\*\*)?\s*[:—–-]/i
1795
1836
  * an absent key → `null` → NO cutover, so `## Surface` decides from Issue 1,
1796
1837
  * O1); it defaults to `BRIEF_SECTIONS_SINCE_ISSUE` only for a caller that does
1797
1838
  * not resolve config.
1798
- * `issueNumber` follows the same fail-closed posture as
1799
- * `checkIssueObjectives`/`checkIssueBriefSections`: `null` (not yet known,
1800
- * e.g. `issue create`) is NOT treated as "at or above the cutover" — it
1801
- * falls back to the prose scan, since a not-yet-created Issue's own
1802
- * `## Surface` cannot yet be trusted to be the mandatory kind.
1839
+ * `issueNumber` follows the same posture as every other cutover-gated rule
1840
+ * here: `null` (not yet known, e.g. `issue create`) is treated as newer than
1841
+ * every cutover, so a new Issue's `## Surface` is judged at creation exactly
1842
+ * as it is on `issue edit` and at dispatch. Only a number below the cutover
1843
+ * keeps the prose scan.
1803
1844
  */
1804
1845
  export function checkBlastRadiusScope(
1805
1846
  body: string,
@@ -1810,7 +1851,7 @@ export function checkBlastRadiusScope(
1810
1851
  sinceBriefSections: number | null = BRIEF_SECTIONS_SINCE_ISSUE
1811
1852
  ): IssueSectionResult {
1812
1853
  if (sharedPackages.length === 0) return { status: 'pass', errors: [] }
1813
- const decideFromSurface = issueNumber !== null && (sinceBriefSections === null || issueNumber >= sinceBriefSections)
1854
+ const decideFromSurface = issueNumber === null || sinceBriefSections === null || issueNumber >= sinceBriefSections
1814
1855
  let named: string[]
1815
1856
  if (decideFromSurface) {
1816
1857
  const surface = parseIssueSurface(body)
@@ -2576,7 +2617,7 @@ export function checkObjectivesRespectBoundary(body: string): IssueSectionResult
2576
2617
 
2577
2618
  const testPlan = parseIssueTestPlan(body)
2578
2619
  if (testPlan.ok && testPlan.value.kind === 'commands') {
2579
- for (const line of [...testPlan.value.lines, ...testPlan.value.principal]) {
2620
+ for (const line of [...testPlan.value.lines, ...testPlan.value.principal, ...testPlan.value.live]) {
2580
2621
  for (const path of namedPathsInCommandLine(line)) {
2581
2622
  const excluder = excludes(path)
2582
2623
  if (excluder) {
@@ -3341,6 +3382,60 @@ export function checkPinnedFileImportersCovered(body: string, importers: PinnedF
3341
3382
  }
3342
3383
  return { status: errors.length > 0 ? 'fail' : 'pass', errors }
3343
3384
  }
3385
+ /** One registered check whose declared file scope covers a pinned file, and the scope entry that does. */
3386
+ export type PinnedFileCheck = { check: string; covers: string }
3387
+
3388
+ /** A pinned file, the checks whose declared scope covers it, and the checks that declare no scope (so no scope can be resolved for them). */
3389
+ export type PinnedFileChecks = { file: string; checks: PinnedFileCheck[]; unresolved: string[] }
3390
+
3391
+ /** A pinned file's covering check and whether the Issue carries a decision for it. */
3392
+ export type PinnedCheckDecision = { check: string; covers: string; decided: boolean }
3393
+
3394
+ /** One pinned file and the decision state of each check that covers it. */
3395
+ export type PinnedFileCheckDecisions = { file: string; checks: PinnedCheckDecision[]; unresolved: string[] }
3396
+
3397
+ /**
3398
+ * Does the body carry a decision for `check`? A decision names the check in
3399
+ * backticks and follows it with `:` or a dash and a sentence saying how the
3400
+ * change satisfies it. A bare mention in a list of names is not a decision.
3401
+ */
3402
+ function hasCheckDecision(body: string, check: string): boolean {
3403
+ const escaped = check.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
3404
+ return new RegExp(`\`${escaped}\`\\s*(?::|—|–|-)\\s*\\S+(?:\\s+\\S+){2,}`).test(body)
3405
+ }
3406
+
3407
+ /** Decides, for every pinned file, whether each check covering it carries a decision in the body. */
3408
+ export function decidePinnedFileChecks(body: string, pinned: PinnedFileChecks[]): PinnedFileCheckDecisions[] {
3409
+ return pinned.map(({ file, checks, unresolved }) => ({
3410
+ file,
3411
+ unresolved,
3412
+ checks: checks.map((c) => ({ ...c, decided: hasCheckDecision(body, c.check) }))
3413
+ }))
3414
+ }
3415
+
3416
+ /**
3417
+ * **Every check whose declared scope covers a pinned file has a decision in
3418
+ * the Issue.** A check that fires at push on a file the Issue pins pauses the
3419
+ * task there unless the Planner already decided how the change satisfies it;
3420
+ * the report lists the covering checks, and this refuses the Issue until each
3421
+ * carries a decision naming the check and how the change satisfies it. A
3422
+ * check that declares no scope is reported as not resolvable and never
3423
+ * refused. Dormant when `## Surface` does not parse or no pinned file has a
3424
+ * covering check.
3425
+ */
3426
+ export function checkPinnedFileChecksDecided(body: string, pinned: PinnedFileChecks[]): IssueSectionResult {
3427
+ if (pinned.length === 0 || !parseIssueSurface(body).ok) return { status: 'pass', errors: [] }
3428
+ const errors: string[] = []
3429
+ for (const { file, checks } of decidePinnedFileChecks(body, pinned)) {
3430
+ const undecided = checks.filter((c) => !c.decided)
3431
+ if (undecided.length === 0) continue
3432
+ errors.push(
3433
+ `issue-validation Surface/checks: the Boundary pins \`${file}\`, and ${undecided.length === 1 ? 'the check' : 'the checks'} ${undecided.map((c) => `\`${c.check}\` (scope \`${c.covers}\`)`).join(', ')} cover${undecided.length === 1 ? 's' : ''} it with no decision in the Issue. For each, add a line naming the check in backticks, then a colon and how the change satisfies it (for example \`${undecided[0]?.check}\`: <how the change satisfies it>). \`vinaya issue surface --body-file <path>\` lists every covering check.`
3434
+ )
3435
+ }
3436
+ return { status: errors.length > 0 ? 'fail' : 'pass', errors }
3437
+ }
3438
+
3344
3439
  /** The CI shard directory a new CLI test file must be listed in, and one file in it for the Surface-coverage test. */
3345
3440
  const CI_SHARD_DIR = 'apps/cli/tests/ci-shards'
3346
3441
  const CI_SHARD_PROBE = `${CI_SHARD_DIR}/shard-1.txt`
@@ -3433,6 +3528,8 @@ export type SurfaceForcedSet = {
3433
3528
  ciShards: { newFiles: string[]; companion: ForcedCompanion; fix: string } | null
3434
3529
  /** The loop invariant map requirement, present only when a pinned loop file is new. */
3435
3530
  loopInvariantMap: { newFiles: string[]; companions: ForcedCompanion[]; fix: string[] } | null
3531
+ /** Every check whose declared scope covers a pinned file, with whether the Issue decides it — the write gate's own reading. */
3532
+ checks: PinnedFileCheckDecisions[]
3436
3533
  }
3437
3534
 
3438
3535
  /**
@@ -3447,7 +3544,8 @@ export type SurfaceForcedSet = {
3447
3544
  export function surfaceForcedSet(
3448
3545
  body: string,
3449
3546
  importers: PinnedFileImporters[],
3450
- tracked: string[]
3547
+ tracked: string[],
3548
+ checks: PinnedFileChecks[] = []
3451
3549
  ): SurfaceForcedSet | null {
3452
3550
  const surface = parseIssueSurface(body)
3453
3551
  const decided = decidePinnedFileImporters(body, importers)
@@ -3462,6 +3560,7 @@ export function surfaceForcedSet(
3462
3560
  const loopCompanions = [LOOP_INVARIANT_FIXTURE, LOOP_INVARIANT_SPEC].map(reached)
3463
3561
  return {
3464
3562
  importers: decided,
3563
+ checks: decidePinnedFileChecks(body, checks),
3465
3564
  ciShards:
3466
3565
  newTests.length === 0 ? null : { newFiles: newTests, companion: reached(CI_SHARD_PROBE), fix: CI_SHARD_DIR },
3467
3566
  loopInvariantMap:
@@ -3600,6 +3699,73 @@ export function checkDocumentationReadable(
3600
3699
  return { status: errors.length > 0 ? 'fail' : 'pass', errors, warnings }
3601
3700
  }
3602
3701
 
3702
+ /** A source carrying a URL scheme (`https://`, `file://`, …) is never read as a repository path. */
3703
+ const DOCUMENTATION_SOURCE_SCHEME_RE = /[a-z][a-z0-9+.-]*:\/\//i
3704
+
3705
+ /** A repository-path source's path: its first inline code span when it has one, else the whole source, with a `#fragment` dropped. */
3706
+ function documentationSourcePath(source: string): string {
3707
+ const span = /`([^`]+)`/.exec(source)
3708
+ return (span ? (span[1] as string) : source).trim().replace(/#.*$/, '')
3709
+ }
3710
+
3711
+ /**
3712
+ * Where a required source is read from, decided from its `## Documentation`
3713
+ * text alone: a public `https://` or `http://` page, a path in this
3714
+ * repository, or neither. A source with any other scheme, an absolute path,
3715
+ * or a path climbing out of the repository (`..`) names nothing the
3716
+ * controller can prepare, so it is `unresolvable` with the reason spelled out.
3717
+ */
3718
+ export type RequiredSourceLocator =
3719
+ | { kind: 'url'; url: string }
3720
+ | { kind: 'repository'; path: string }
3721
+ | { kind: 'unresolvable'; detail: string }
3722
+
3723
+ export function classifyDocumentationSource(source: string): RequiredSourceLocator {
3724
+ const trimmed = source.trim()
3725
+ if (/^https?:\/\//i.test(trimmed)) return { kind: 'url', url: trimmed }
3726
+ if (DOCUMENTATION_SOURCE_SCHEME_RE.test(trimmed)) {
3727
+ return {
3728
+ kind: 'unresolvable',
3729
+ detail: `\`${trimmed}\` carries a scheme that is neither a web page nor a repository path`
3730
+ }
3731
+ }
3732
+ const path = documentationSourcePath(trimmed)
3733
+ if (path.length === 0) return { kind: 'unresolvable', detail: 'the source names no page and no repository path' }
3734
+ if (path.startsWith('/') || path.split('/').includes('..')) {
3735
+ return { kind: 'unresolvable', detail: `\`${path}\` is not a path inside this repository` }
3736
+ }
3737
+ return { kind: 'repository', path: path.replace(/^\.\//, '') }
3738
+ }
3739
+
3740
+ /**
3741
+ * Why a required source could not be prepared before the Developer's turn —
3742
+ * the typed reason a `missing_source` pause carries for each one.
3743
+ *
3744
+ * - `login_required` — the page asked for credentials (HTTP 401, 403 or 407)
3745
+ * or redirected to a sign-in page; a private document is never read.
3746
+ * - `other_host` — the page answered from a different host than the one the
3747
+ * task names, so what would be read is not the named source.
3748
+ * - `not_a_document` — the answer was an error status, too little text to be
3749
+ * the document, or a body whose end was never declared.
3750
+ * - `fetch_refused` — the fetch itself was refused: not https, a non-public
3751
+ * address, a disallowed content type, an oversized body, too many redirects.
3752
+ * - `unreachable` — a timeout or a dropped connection, still failing after
3753
+ * the provider's bounded retries.
3754
+ * - `missing_in_repository` — the repository path does not exist at the
3755
+ * frozen base revision.
3756
+ * - `unresolvable` — the source names neither a page nor a repository path.
3757
+ */
3758
+ export const REQUIRED_SOURCE_MISSING_REASONS = [
3759
+ 'login_required',
3760
+ 'other_host',
3761
+ 'not_a_document',
3762
+ 'fetch_refused',
3763
+ 'unreachable',
3764
+ 'missing_in_repository',
3765
+ 'unresolvable'
3766
+ ] as const
3767
+ export type RequiredSourceMissingReason = (typeof REQUIRED_SOURCE_MISSING_REASONS)[number]
3768
+
3603
3769
  /**
3604
3770
  * **An in-repository Documentation source exists in the checkout.** A source
3605
3771
  * carrying a URL scheme belongs to `checkDocumentationReadable` and is never
@@ -3617,9 +3783,8 @@ export function checkDocumentationPathsExist(
3617
3783
  if (!documentation.ok || documentation.value.kind === 'none') return { status: 'pass', errors: [] }
3618
3784
  const errors: string[] = []
3619
3785
  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(/#.*$/, '')
3786
+ if (DOCUMENTATION_SOURCE_SCHEME_RE.test(source)) continue
3787
+ const path = documentationSourcePath(source)
3623
3788
  if (path.length === 0) continue
3624
3789
  if (readFile(path) === null) {
3625
3790
  errors.push(
@@ -0,0 +1,179 @@
1
+ /**
2
+ * The pull request's record of its `[live]` Test plan lines — the commands
3
+ * that need real signed-in agent sessions, which the review loop runs on its
4
+ * own host only on a head both reviewers approved (`apps/cli/specs/loop.md`,
5
+ * "The live check"). Pure: a body in, a body or the record's lines out.
6
+ *
7
+ * The record is an `AEG:LIVE` anchored region the driver owns, like
8
+ * `AEG:BEYOND-SURFACE`: rewritten by the driver after each live run, and
9
+ * carried over from the live body on every other body write, so an agent's
10
+ * edit to it never survives. One checkbox line per `[live]` command:
11
+ *
12
+ * - passed — ticked, naming the head it passed at and its pass count;
13
+ * - failed — unticked, naming the head and the exit;
14
+ * - unverified — unticked, naming the head and why the host could not run
15
+ * it. The Principal may run it and tick the box, exactly as for a
16
+ * `[principal]` item; the driver keeps that tick while the head and the
17
+ * command are unchanged.
18
+ *
19
+ * `evaluateTestPlanGate` reads each unticked line as it reads an unticked
20
+ * `[principal]` item, so the merge gate stays red while one remains. Every
21
+ * digit sits inside a code span, so the body's bare-digit rule never sees one.
22
+ */
23
+
24
+ import { maskCode } from '@attalabs/aeg-forge-state/strip-code'
25
+ import { anchoredRegion, anchoredRegionBounds } from './anchored-region'
26
+ import { locateTestPlanSection } from './test-plan-section'
27
+
28
+ export type LiveRecordEntry =
29
+ | { command: string; head: string; outcome: 'passed'; passCount: number | null }
30
+ | { command: string; head: string; outcome: 'failed'; detail: string }
31
+ | { command: string; head: string; outcome: 'unverified'; reason: string; ticked: boolean }
32
+
33
+ const LIVE_RECORD_LEAD =
34
+ '**Live checks** — recorded by the review-loop driver after each run on its own host; never edit it:'
35
+
36
+ /** `text` as a code span one backtick longer than any run inside it, padded when it starts or ends with a backtick. */
37
+ function codeSpan(text: string): string {
38
+ const longest = Math.max(0, ...(text.match(/`+/g) ?? []).map((run) => run.length))
39
+ const ticks = '`'.repeat(longest + 1)
40
+ const pad = text.startsWith('`') || text.endsWith('`') ? ' ' : ''
41
+ return `${ticks}${pad}${text}${pad}${ticks}`
42
+ }
43
+
44
+ /** One entry's line. */
45
+ export function renderLiveRecordLine(entry: LiveRecordEntry): string {
46
+ const at = `at ${codeSpan(entry.head)}`
47
+ const cmd = codeSpan(entry.command)
48
+ switch (entry.outcome) {
49
+ case 'passed':
50
+ return `- [x] **[live]** ${cmd} — passed ${at}, ${
51
+ entry.passCount === null ? 'its output naming no pass count' : `${codeSpan(String(entry.passCount))} passing`
52
+ }`
53
+ case 'failed':
54
+ return `- [ ] **[live]** ${cmd} — failed ${at}: ${entry.detail}`
55
+ case 'unverified':
56
+ return `- [${entry.ticked ? 'x' : ' '}] **[live]** ${cmd} — unverified ${at}: ${entry.reason}; the Principal runs it and ticks this box`
57
+ }
58
+ }
59
+
60
+ /** The whole marked block — the `AEG:LIVE` pair around the lead line and one line per entry, or around nothing when there is none. */
61
+ export function renderLiveRecordBlock(entries: readonly LiveRecordEntry[]): string {
62
+ const inner = entries.length === 0 ? '' : `${[LIVE_RECORD_LEAD, ...entries.map(renderLiveRecordLine)].join('\n')}\n`
63
+ return `<!-- AEG:LIVE:START -->\n${inner}<!-- AEG:LIVE:END -->`
64
+ }
65
+
66
+ const RECORD_LINE_RE =
67
+ /^-\s*\[([ xX])\]\s*\*\*\[live\]\*\*\s+(`+) ?(.+?) ?\2(?!`)\s+—\s+(passed|failed|unverified)\s+at\s+`([^`]+)`/
68
+
69
+ /** One line the record carries, as the gate and the driver read it back. */
70
+ export type LiveRecordLine = {
71
+ line: string
72
+ ticked: boolean
73
+ command: string
74
+ outcome: 'passed' | 'failed' | 'unverified'
75
+ head: string
76
+ }
77
+
78
+ /** Every `AEG:LIVE` start or end marker outside code, by position — the driver writes exactly one of each. */
79
+ function liveMarkers(body: string): { start: number; end: number }[] {
80
+ const masked = maskCode(body)
81
+ return [...masked.matchAll(/<!--\s*AEG:LIVE:(?:START|END)\s*-->/g)].map((m) => ({
82
+ start: m.index as number,
83
+ end: (m.index as number) + m[0].length
84
+ }))
85
+ }
86
+
87
+ /** The line read back from a body whose `AEG:LIVE` markers are not exactly one pair: unticked, so the merge gate holds and no run is skipped. */
88
+ const AMBIGUOUS_RECORD_LINE: LiveRecordLine = {
89
+ line: "- [ ] **[live]** the pull request body carries more than one `AEG:LIVE` marker pair, so the driver's record cannot be told apart",
90
+ ticked: false,
91
+ command: '',
92
+ outcome: 'failed',
93
+ head: ''
94
+ }
95
+
96
+ /**
97
+ * Every checkbox line inside the body's `AEG:LIVE` block — `[]` when the body
98
+ * carries none. Fails closed: a body with any marker beyond the driver's one
99
+ * pair reads as a single unticked line, never as the first pair's lines.
100
+ */
101
+ export function readLiveRecord(body: string): LiveRecordLine[] {
102
+ const markers = liveMarkers(body).length
103
+ if (markers === 0) return []
104
+ if (markers !== 2) return [AMBIGUOUS_RECORD_LINE]
105
+ const region = anchoredRegion(body, 'LIVE')
106
+ if (region === null) return []
107
+ const lines: LiveRecordLine[] = []
108
+ for (const raw of region.split('\n')) {
109
+ const line = raw.trim()
110
+ const m = RECORD_LINE_RE.exec(line)
111
+ if (!m) continue
112
+ lines.push({
113
+ line,
114
+ ticked: (m[1] as string).toLowerCase() === 'x',
115
+ command: m[3] as string,
116
+ outcome: m[4] as LiveRecordLine['outcome'],
117
+ head: m[5] as string
118
+ })
119
+ }
120
+ return lines
121
+ }
122
+
123
+ /**
124
+ * `body` with its `AEG:LIVE` block rewritten to `entries` — only that marked
125
+ * region is replaced. A body with no such block gets one at the end of its
126
+ * Test Plan section (after an `AEG:TEST-PLAN` pair when the body has one),
127
+ * else appended.
128
+ */
129
+ export function withLiveRecord(body: string, entries: readonly LiveRecordEntry[]): string {
130
+ const block = renderLiveRecordBlock(entries)
131
+ const existing = anchoredRegionBounds(body, 'LIVE')
132
+ if (existing) return body.slice(0, existing.outerStart) + block + body.slice(existing.outerEnd)
133
+ const anchoredPlan = anchoredRegionBounds(body, 'TEST-PLAN')
134
+ if (anchoredPlan) return insertAt(body, anchoredPlan.outerEnd, block)
135
+ const located = locateTestPlanSection(body)
136
+ const at = located.found ? body.indexOf(located.section) : -1
137
+ if (located.found && at >= 0) return insertAt(body, at + located.section.length, block)
138
+ return `${body.replace(/\s*$/, '')}\n\n${block}\n`
139
+ }
140
+
141
+ function insertAt(body: string, at: number, block: string): string {
142
+ const before = body.slice(0, at).replace(/\s*$/, '')
143
+ const after = body.slice(at).replace(/^\s*/, '')
144
+ return `${before}\n\n${block}\n${after.length > 0 ? `\n${after}` : ''}`
145
+ }
146
+
147
+ /**
148
+ * `next` with its `AEG:LIVE` block replaced by `current`'s — the driver's own
149
+ * record survives an agent body write, and a block the agent wrote itself
150
+ * never does: with no record on `current`, any block on `next` is removed.
151
+ */
152
+ export function carryLiveRecord(next: string, current: string | null): string {
153
+ const stripped = withoutAgentLiveRecord(next)
154
+ const kept = current === null || liveMarkers(current).length !== 2 ? null : anchoredRegionBounds(current, 'LIVE')
155
+ if (kept === null) return stripped
156
+ return withLiveRecordBlockText(stripped, (current as string).slice(kept.outerStart, kept.outerEnd))
157
+ }
158
+
159
+ /**
160
+ * `body` with every `AEG:LIVE` pair an agent wrote removed, contents and all,
161
+ * then every leftover lone marker removed — so no number of forged pairs, and
162
+ * no stray marker pairing with the driver's own, survives.
163
+ */
164
+ function withoutAgentLiveRecord(body: string): string {
165
+ let out = body
166
+ for (let pair = anchoredRegionBounds(out, 'LIVE'); pair !== null; pair = anchoredRegionBounds(out, 'LIVE')) {
167
+ const before = out.slice(0, pair.outerStart).replace(/\s*$/, '')
168
+ const after = out.slice(pair.outerEnd).replace(/^\s*/, '')
169
+ out = after.length > 0 ? `${before}\n\n${after}` : `${before}\n`
170
+ }
171
+ for (const marker of liveMarkers(out).reverse()) out = out.slice(0, marker.start) + out.slice(marker.end)
172
+ return out
173
+ }
174
+
175
+ function withLiveRecordBlockText(body: string, block: string): string {
176
+ const placeholder = withLiveRecord(body, [])
177
+ const bounds = anchoredRegionBounds(placeholder, 'LIVE') as NonNullable<ReturnType<typeof anchoredRegionBounds>>
178
+ return placeholder.slice(0, bounds.outerStart) + block + placeholder.slice(bounds.outerEnd)
179
+ }
@@ -96,6 +96,8 @@ export type HeaderInput = {
96
96
  * by the caller (the sink, from `git`/`gh`); this module stays pure.
97
97
  */
98
98
  branchIssue?: number | null
99
+ /** Commit already resolved by the caller for a gate event; absent reads null. */
100
+ revision?: string | null
99
101
  subject?: Partial<Subject>
100
102
  /** 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). */
101
103
  eventId: string
@@ -105,9 +107,11 @@ export type HeaderInput = {
105
107
  provenance?: Provenance
106
108
  /** Mirrors `review-input-manifest.ts`'s field set (camelCase, matching that module); absent fields read back `null`, never invented. */
107
109
  inputVersions?: {
110
+ manifestVersion?: 2 | null
108
111
  objectivesVersion?: string | null
109
112
  briefHash?: string | null
110
113
  rulingOrdinal?: number | null
114
+ pauseBoundRuling?: { rulingId: string; pauseId: string; contentDigest: string } | null
111
115
  policyDigest?: string | null
112
116
  }
113
117
  }
@@ -155,9 +159,11 @@ export function buildHeader(input: HeaderInput): Header {
155
159
  parent: lineageFieldFromEnv(input.env.parent)
156
160
  },
157
161
  input_versions: {
162
+ manifest_version: input.inputVersions?.manifestVersion ?? null,
158
163
  objectives_version: input.inputVersions?.objectivesVersion ?? null,
159
164
  brief_hash: input.inputVersions?.briefHash ?? null,
160
165
  ruling_ordinal: input.inputVersions?.rulingOrdinal ?? null,
166
+ pause_bound_ruling: input.inputVersions?.pauseBoundRuling ?? null,
161
167
  policy_digest: input.inputVersions?.policyDigest ?? null
162
168
  },
163
169
  provenance: provenanceFor(input),
@@ -165,8 +171,8 @@ export function buildHeader(input: HeaderInput): Header {
165
171
  // A stated reference wins; failing that the Issue number `subject.issue` already carries; never anything guessed.
166
172
  ref: lineageFieldFromEnv(input.env.workRef) ?? (issue === null ? null : String(issue)),
167
173
  repo: input.repo,
168
- change: null,
169
- revision: null
174
+ change: pr === undefined ? null : String(pr),
175
+ revision: input.revision ?? null
170
176
  },
171
177
  flow: {
172
178
  id: lineageFieldFromEnv(input.env.flow) ?? 'vinaya',
@@ -36,6 +36,7 @@ export {
36
36
  } from './fixtures'
37
37
  export type { ExecutionName, FactSheet, FixtureExecution, FixtureLine, FixtureValidity } from './fixtures'
38
38
  export { redact } from './redact'
39
+ export { describeSchema, logEventSchemaDigest, schemaDigest } from './schema-digest'
39
40
  export {
40
41
  classifyStoredLine,
41
42
  createFixtureStore,