@attalabs/vinaya 0.37.0 → 0.38.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 (174) hide show
  1. package/aeg-root/enforcement.md +5 -4
  2. package/aeg-root/roles/developer/reference.md +24 -22
  3. package/aeg-root/roles/developer.md +4 -4
  4. package/aeg-root/roles/planner/reference.md +11 -0
  5. package/aeg-root/roles/reviewer.md +5 -3
  6. package/aeg-root/roles/security.md +3 -2
  7. package/aeg-root/state-machine.md +1 -1
  8. package/aeg-root/templates/brief-template.md +4 -4
  9. package/aeg-root/tranche-model.md +6 -0
  10. package/dist/checks/bin/check-body-bare-digits.js +139 -12
  11. package/dist/checks/bin/check-branch-topology.js +171 -13
  12. package/dist/checks/bin/check-brief-shape.js +139 -12
  13. package/dist/checks/bin/check-changeset-coverage.js +177 -17
  14. package/dist/checks/bin/check-closes-n.js +171 -13
  15. package/dist/checks/bin/check-coherence.js +171 -13
  16. package/dist/checks/bin/check-dead-branch-push.js +139 -12
  17. package/dist/checks/bin/check-dispatch-readiness.js +195 -23
  18. package/dist/checks/bin/check-doc-coverage-push.js +173 -13
  19. package/dist/checks/bin/check-doc-coverage.js +180 -13
  20. package/dist/checks/bin/check-doctrine-no-procedures.js +139 -12
  21. package/dist/checks/bin/check-doctrine-portability.js +173 -13
  22. package/dist/checks/bin/check-evidence-fresh.js +173 -13
  23. package/dist/checks/bin/check-exec-bits.js +173 -13
  24. package/dist/checks/bin/check-first-push-dispatch.js +171 -13
  25. package/dist/checks/bin/check-issue-assignment.js +171 -13
  26. package/dist/checks/bin/check-issue-milestone-attach.js +139 -12
  27. package/dist/checks/bin/check-issue-objectives-numbering.js +139 -12
  28. package/dist/checks/bin/check-issue-parts-coverage.js +139 -12
  29. package/dist/checks/bin/check-issue-surface-globs.js +171 -13
  30. package/dist/checks/bin/check-issue-title-grammar.js +139 -12
  31. package/dist/checks/bin/check-issue-tranche-label.js +139 -12
  32. package/dist/checks/bin/check-main-branch-refusal.js +139 -12
  33. package/dist/checks/bin/check-no-disk-state.js +139 -12
  34. package/dist/checks/bin/check-pr-premise-reassert.js +139 -12
  35. package/dist/checks/bin/check-pr-report-density.js +139 -12
  36. package/dist/checks/bin/check-principal-test-plan-wait.js +139 -12
  37. package/dist/checks/bin/check-quoted-command.js +173 -13
  38. package/dist/checks/bin/check-reader-resolvable-prose.js +173 -13
  39. package/dist/checks/bin/check-registry-gates.js +406 -68
  40. package/dist/checks/bin/check-retired-vocabulary.js +173 -13
  41. package/dist/checks/bin/check-review-gate.js +139 -12
  42. package/dist/checks/bin/check-single-plan-pr.js +139 -12
  43. package/dist/checks/bin/check-surface-scope.js +171 -13
  44. package/dist/checks/bin/check-test-plan.js +139 -12
  45. package/dist/checks/bin/check-token-collection-wired.js +139 -12
  46. package/dist/checks/bin/check-workspace-escape.js +173 -13
  47. package/dist/checks/bin/verify-dispatch.js +3849 -0
  48. package/dist/index.js +7348 -2095
  49. package/dist/lib/pre-push-cache-test-run.js +42 -2
  50. package/dist/lib/pre-push-changed-files.js +16 -11
  51. package/dist/lib/pre-push-select-tests.js +177 -21
  52. package/package.json +1 -1
  53. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/anchored-region.ts +7 -6
  54. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/brief-render.ts +33 -15
  55. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/brief-validation.ts +51 -12
  56. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/control-store/index.ts +1 -0
  57. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/control-store/local.ts +31 -0
  58. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/control-store/records.ts +31 -2
  59. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/assess-round.ts +214 -24
  60. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/fakes.ts +11 -3
  61. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/index.ts +5 -4
  62. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/journal-reconstruction.ts +13 -13
  63. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/render-summary.ts +46 -145
  64. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/types.ts +63 -14
  65. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/docs/index.ts +3 -1
  66. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/docs/published-prose.ts +30 -0
  67. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/doctrine-portability.ts +6 -2
  68. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/gate-audience.ts +0 -1
  69. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/index.ts +56 -7
  70. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/issue-validation.ts +7 -7
  71. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/leftover-detection.ts +24 -6
  72. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/custom.ts +157 -0
  73. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/envelope.ts +44 -6
  74. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/fixtures/executions.ts +493 -0
  75. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/fixtures/fact-sheets.ts +111 -0
  76. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/fixtures/generator.ts +155 -0
  77. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/fixtures/index.ts +12 -0
  78. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/index.ts +128 -0
  79. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/catches.ts +63 -0
  80. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/checks.ts +146 -0
  81. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/common.ts +137 -0
  82. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/completion.ts +137 -0
  83. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/convergence.ts +420 -0
  84. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/determinism.ts +65 -0
  85. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/index.ts +69 -0
  86. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/judgment.ts +132 -0
  87. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/labels.ts +21 -0
  88. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/time.ts +167 -0
  89. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/usage.ts +139 -0
  90. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/schema.ts +219 -15
  91. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/store.ts +7 -7
  92. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/sync/cache-contract.ts +207 -0
  93. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/sync/contracts.ts +105 -0
  94. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/sync/engine.ts +308 -0
  95. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/sync/index.ts +34 -0
  96. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/sync/measured.ts +20 -0
  97. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/sync/memory-cache.ts +78 -0
  98. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/sync/normalize.ts +156 -0
  99. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/sync/row.ts +103 -0
  100. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/reader-resolvable-prose.ts +34 -6
  101. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/registry-checks.ts +70 -6
  102. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-input-manifest.ts +19 -14
  103. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-policy.ts +38 -3
  104. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-status.ts +5 -2
  105. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/task-phase-history.ts +46 -0
  106. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/task-tools.ts +15 -28
  107. package/studio-standalone/apps/vinaya-studio/web/.next/BUILD_ID +1 -1
  108. package/studio-standalone/apps/vinaya-studio/web/.next/build-manifest.json +3 -3
  109. package/studio-standalone/apps/vinaya-studio/web/.next/prerender-manifest.json +3 -3
  110. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
  111. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.html +1 -1
  112. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.rsc +1 -1
  113. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
  114. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  115. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  116. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  117. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  118. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page/server-reference-manifest.json +2 -2
  119. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page.js.nft.json +1 -1
  120. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  121. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page/server-reference-manifest.json +2 -2
  122. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page.js.nft.json +1 -1
  123. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page_client-reference-manifest.js +1 -1
  124. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page/server-reference-manifest.json +2 -2
  125. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page.js.nft.json +1 -1
  126. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page_client-reference-manifest.js +1 -1
  127. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page/server-reference-manifest.json +2 -2
  128. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page.js.nft.json +1 -1
  129. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page_client-reference-manifest.js +1 -1
  130. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page/server-reference-manifest.json +2 -2
  131. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page.js.nft.json +1 -1
  132. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page_client-reference-manifest.js +1 -1
  133. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page/server-reference-manifest.json +3 -3
  134. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page.js.nft.json +1 -1
  135. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page_client-reference-manifest.js +1 -1
  136. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page/server-reference-manifest.json +2 -2
  137. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page.js.nft.json +1 -1
  138. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page_client-reference-manifest.js +1 -1
  139. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page/server-reference-manifest.json +2 -2
  140. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page.js.nft.json +1 -1
  141. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page_client-reference-manifest.js +1 -1
  142. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page/server-reference-manifest.json +2 -2
  143. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page.js.nft.json +1 -1
  144. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page_client-reference-manifest.js +1 -1
  145. 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
  146. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__04adkz-._.js +1 -1
  147. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__08e39jo._.js +1 -1
  148. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__0h9yhwx._.js +1 -1
  149. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/{[root-of-the-server]__14ui9sz._.js → [root-of-the-server]__0jdjsxe._.js} +1 -1
  150. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__0ls23oh._.js +1 -1
  151. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1gjqmhq._.js +1 -1
  152. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1wc4-ip._.js +1 -1
  153. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_08onyya._.js +1 -1
  154. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_096f46i._.js +1 -1
  155. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0af2one._.js +1 -1
  156. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0e5tkdd._.js +1 -1
  157. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0kf2g72._.js +1 -1
  158. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0zf4d27._.js +1 -1
  159. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_1-wo68i._.js +1 -1
  160. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_1achbh9._.js +1 -1
  161. 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
  162. package/studio-standalone/apps/vinaya-studio/web/.next/server/middleware-build-manifest.js +3 -3
  163. package/studio-standalone/apps/vinaya-studio/web/.next/server/pages/500.html +1 -1
  164. package/studio-standalone/apps/vinaya-studio/web/.next/server/server-reference-manifest.js +1 -1
  165. package/studio-standalone/apps/vinaya-studio/web/.next/server/server-reference-manifest.json +4 -4
  166. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/1-acpmtfmrc35.js +1 -0
  167. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{3qtt1v3ya-ofe.js → 2f2y8xxok8zph.js} +1 -1
  168. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{3l56x8wjdzvaw.js → 2xevgia1h8g0y.js} +4 -4
  169. package/studio-standalone/apps/vinaya-studio/web/package.json +2 -2
  170. package/dist/checks/bin/check-token-report.js +0 -6526
  171. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/0vtfb0g813gki.js +0 -1
  172. /package/studio-standalone/apps/vinaya-studio/web/.next/static/{yR5RsCxb1OGnYggiaO09S → yNZEFRSjP9BLUfdf96Eol}/_buildManifest.js +0 -0
  173. /package/studio-standalone/apps/vinaya-studio/web/.next/static/{yR5RsCxb1OGnYggiaO09S → yNZEFRSjP9BLUfdf96Eol}/_clientMiddlewareManifest.js +0 -0
  174. /package/studio-standalone/apps/vinaya-studio/web/.next/static/{yR5RsCxb1OGnYggiaO09S → yNZEFRSjP9BLUfdf96Eol}/_ssgManifest.js +0 -0
@@ -249,11 +249,28 @@ export function checkDocUpdateList(prBody: string): BriefSectionResult {
249
249
  return headingCheck(prBody, '(?:documentation|doc)[- ]update(?:\\s+list)?', 'Documentation-update list')
250
250
  }
251
251
 
252
+ /**
253
+ * Step 0 no longer creates the worktree (`git worktree add`) — the driver does
254
+ * that before the first Developer dispatch — and no longer enters one either
255
+ * (`cd .worktrees/<branch> && …`): O2, the dispatched session's own `cwd` IS
256
+ * that worktree, so Step 0 is just `bun install --frozen-lockfile …`. Accepts
257
+ * ALL THREE shapes so a brief rendered at any generation passes — the oldest
258
+ * (`git worktree add`), the middle one (`cd .worktrees/`), and the newest
259
+ * (a bare frozen-lockfile install). This gate judges presence of a Step 0
260
+ * marker, never which generation rendered it.
261
+ */
252
262
  export function checkWorktreeStep0(prBody: string): BriefSectionResult {
253
- if (/git worktree add/.test(prBody)) return { status: 'pass', errors: [] }
263
+ if (
264
+ /git worktree add/.test(prBody) ||
265
+ /cd \.worktrees\//.test(prBody) ||
266
+ /bun install --frozen-lockfile/.test(prBody)
267
+ )
268
+ return { status: 'pass', errors: [] }
254
269
  return {
255
270
  status: 'fail',
256
- errors: ['brief-validation worktree Step 0: no `git worktree add` command found in the PR body.']
271
+ errors: [
272
+ 'brief-validation worktree Step 0: no `git worktree add`, `cd .worktrees/`, or `bun install --frozen-lockfile` command found in the PR body.'
273
+ ]
257
274
  }
258
275
  }
259
276
 
@@ -502,16 +519,26 @@ export function isBriefShaped(prBody: string): boolean {
502
519
  }
503
520
 
504
521
  /**
505
- * The branch a brief declares for itself, read from its Step 0 command. At
506
- * authoring time there is no `BRANCH` env var and no branch yet — but every
507
- * brief carries `git worktree add <path> -b <branch> origin/main`, so the brief
508
- * states what it is going to be, and `verify-brief --body-file` can grade it as
509
- * that. Matched on the RAW body, not `stripCode`'s output: Step 0 lives inside a
510
- * fence in every real brief, so the stripped text never contains it.
522
+ * The branch a brief declares for itself. Older generations stated it in
523
+ * their Step 0 command — `git worktree add <path> -b <branch> origin/main`
524
+ * (oldest) or `cd .worktrees/<branch> && …` (the driver creates the worktree,
525
+ * Step 0 only enters it) — so those are read first, on the RAW body (Step 0
526
+ * lives inside a fence, so `stripCode`'s output never contains it); the `-b`
527
+ * form is tried first so an OLD brief quoting both shapes still reads the
528
+ * worktree-creation branch, not a later, unrelated `cd`. O2: the newest
529
+ * generation's Step 0 carries no branch at all — it is a bare `bun install`,
530
+ * run from a `cwd` already inside the worktree — so this falls back to §2's own
531
+ * `Branch \`<branch>\`` identity line, the one other place every brief states
532
+ * its branch, letting `verify-brief --body-file` grade a brief of any
533
+ * generation.
511
534
  */
512
535
  export function inferBranchFromBody(prBody: string): string {
513
- const m = prBody.match(/git worktree add\s+\S+\s+-b\s+(\S+)/)
514
- return m?.[1] ?? ''
536
+ const created = prBody.match(/git worktree add\s+\S+\s+-b\s+(\S+)/)
537
+ if (created) return created[1] ?? ''
538
+ const entered = prBody.match(/cd \.worktrees\/(\S+?)(?=\s|&&|$)/)
539
+ if (entered?.[1]) return entered[1]
540
+ const declared = prBody.match(/Branch `([^`]+)`/)
541
+ return declared?.[1] ?? ''
515
542
  }
516
543
 
517
544
  /**
@@ -783,9 +810,21 @@ function isCommandBlock(content: string): boolean {
783
810
  return (COMMAND_WORDS as readonly string[]).includes(commandWordOf(firstNonBlankLine(content)))
784
811
  }
785
812
 
786
- /** The Step 0 exemption — `git worktree add …` is a command with no separate output block by convention. */
813
+ /**
814
+ * The Step 0 exemption — a command with no separate output block by
815
+ * convention. Matches any generation: `git worktree add …` (an older
816
+ * rendering), `cd .worktrees/… && …` (the driver creates the worktree, Step 0
817
+ * only enters it), or a bare `bun install --frozen-lockfile …` (O2: the driver
818
+ * now ALSO places the Developer's own `cwd` inside that worktree, so Step 0 no
819
+ * longer enters one either — it is just the install).
820
+ */
787
821
  function isStep0Block(content: string): boolean {
788
- return firstNonBlankLine(content).startsWith('git worktree add')
822
+ const first = firstNonBlankLine(content)
823
+ return (
824
+ first.startsWith('git worktree add') ||
825
+ first.startsWith('cd .worktrees/') ||
826
+ first.startsWith('bun install --frozen-lockfile')
827
+ )
789
828
  }
790
829
 
791
830
  /**
@@ -40,6 +40,7 @@ export {
40
40
  markEffectUncertain,
41
41
  mkdirNoSymlinks,
42
42
  readCurrentOwnership,
43
+ readEarliestOwnership,
43
44
  readEffect,
44
45
  readEscalation,
45
46
  readInput,
@@ -536,6 +536,37 @@ export function readCurrentOwnership(
536
536
  return { epoch: best ? bestEpoch : 0, record: best, corruptEpochs }
537
537
  }
538
538
 
539
+ /**
540
+ * The EARLIEST ownership epoch validly recorded for `task`, and when it was
541
+ * acquired — `null` for a task nothing has ever claimed.
542
+ *
543
+ * Every epoch file is created with `O_EXCL` and never overwritten
544
+ * (`attemptEpochClaim`), so epoch 1's `acquiredAt` is the oldest durable
545
+ * timestamp the control store holds for a task and survives every driver
546
+ * restart, re-exec and takeover. That makes it the floor a caller measuring a
547
+ * task's total wall-clock time falls back to when nothing better was recorded:
548
+ * an epoch is claimed the first time the task writes anything durable, so the
549
+ * real start is at or before it, never after — the safe direction for a
550
+ * budget, which then fires no earlier than it should.
551
+ *
552
+ * A corrupt epoch file is skipped rather than reported: this read exists to
553
+ * find the oldest timestamp available, and a torn file carries none. Callers
554
+ * that need to know about corruption read `readCurrentOwnership`, which
555
+ * reports it.
556
+ */
557
+ export function readEarliestOwnership(deps: Pick<ControlStoreDeps, 'root'>, task: number): OwnershipRecord | null {
558
+ const dir = ownershipDir(deps.root(), task)
559
+ if (!existsSync(dir)) return null
560
+ let best: OwnershipRecord | null = null
561
+ for (const entry of readdirSync(dir)) {
562
+ if (!EPOCH_FILENAME.exec(entry)) continue
563
+ const parsed = parseOwnershipRecord(readIfExists(join(dir, entry)))
564
+ if (parsed.status !== 'ok') continue
565
+ if (best === null || parsed.value.epoch < best.epoch) best = parsed.value
566
+ }
567
+ return best
568
+ }
569
+
539
570
  export type AcquireResult =
540
571
  | { acquired: true; epoch: number; record: OwnershipRecord }
541
572
  | { acquired: false; currentEpoch: number; currentOwnerId: string | null }
@@ -119,8 +119,10 @@ export type TransitionRecord = z.infer<typeof TransitionRecordSchema>
119
119
  * against: repository and work (the PR/branch this round belongs to), base and
120
120
  * candidate (`baseSha`/`headSha`), instruction and criteria versions
121
121
  * (`briefHash`/`objectivesVersion`), rulings (`rulingOrdinal`), and the
122
- * complete effective policy identity (`policyDigest`, which folds in the
123
- * round-policy field). `baseSha`/`briefHash`/`objectivesVersion` are nullable
122
+ * blocking-threshold policy identity (`policyDigest`, which covers
123
+ * `codeReviewThreshold`/`securityThreshold` only — the loop's own limits
124
+ * `maxRounds`/`maxTaskMinutes` are left out; see `review-input-manifest.ts`).
125
+ * `baseSha`/`briefHash`/`objectivesVersion` are nullable
124
126
  * exactly where the manifest itself is (`review-input-manifest.ts`'s own
125
127
  * `null` = "nothing resolvable to bind against"); `rulingOrdinal`/
126
128
  * `policyDigest` are never null, the same as on the manifest.
@@ -223,6 +225,33 @@ export const LoopStateRecordSchema = z
223
225
  })
224
226
  .strict()
225
227
  .optional(),
228
+ /** The original or deliberately advanced task-branch base used by publication checks. */
229
+ publicationExpectedBase: z
230
+ .string()
231
+ .regex(/^[0-9a-f]{40}$/)
232
+ .nullable()
233
+ .optional(),
234
+ /**
235
+ * When the loop FIRST started on this task, as the first driver to persist
236
+ * state for it recorded — carried forward unchanged by every later write,
237
+ * including writes by a driver that took the task over, so the task's own
238
+ * wall-clock budget is measured from one fixed instant rather than
239
+ * restarting with each process. Optional: a record written before this
240
+ * field existed reads back as no recorded start, which a caller reads as
241
+ * "fall back to the earliest ownership epoch" rather than as a corrupt
242
+ * record.
243
+ */
244
+ taskStartedAt: isoTimestamp.optional(),
245
+ /**
246
+ * Milliseconds the loop has recorded against each phase it worked in,
247
+ * keyed by the same `phase` vocabulary the field above uses. Accumulated
248
+ * across driver restarts (each write carries the running totals it read
249
+ * back), and narration only: the task's budget is decided on elapsed time,
250
+ * never on this map, so a run whose earlier phases were recorded by a
251
+ * driver that has since died still stops on time and simply reports less
252
+ * about where the time went.
253
+ */
254
+ phaseMs: z.record(z.string(), z.number().nonnegative()).optional(),
226
255
  recordedAt: isoTimestamp
227
256
  })
228
257
  .strict()
@@ -21,8 +21,10 @@
21
21
  * - The three exits are decided here and nowhere else: an id previously
22
22
  * `resolved` reported again (`stop_condition_met` `condition: 'reappearance'`),
23
23
  * a confidence collapse per the rule above (`condition: 'confidence'`), and
24
- * rounds over 3 (`condition: 'max_rounds'`) — distinct `condition` values a
25
- * 2026-09-06 amendment adds to `stop_condition_met.condition` so a reader
24
+ * a round that reaches the cap without going green (`condition: 'max_rounds'`;
25
+ * the default cap is 3, so rounds 1–3 run and the loop pauses after round
26
+ * 3's review, and a green round at the cap still publishes) — distinct
27
+ * `condition` values a 2026-09-06 amendment adds to `stop_condition_met.condition` so a reader
26
28
  * tells a confidence collapse and a finding reappearance apart from each
27
29
  * other and from the round cap. A fourth exit once lived here too — two
28
30
  * consecutive rounds resolving no id (`condition: 'no_progress'`) — but it
@@ -40,6 +42,17 @@
40
42
  * that resolves nothing but raises only new findings still continues, and
41
43
  * a round whose repeated finding is non-blocking continues too. Both name
42
44
  * what repeated in the pause's own `detail`.
45
+ * - One further exit bounds the task by TIME rather than by rounds or repeats:
46
+ * the task's ACTIVE working time — the sum of the phases a driver spent
47
+ * developing, reviewing and awaiting confidence, never the hours it sat
48
+ * paused, published or driverless — passing `ReviewPolicy.maxTaskMinutes`
49
+ * (`condition: 'time_budget'`). It is the one exit a loop cannot outrun by
50
+ * never advancing — the round cap bounds review rounds, and a loop stuck
51
+ * pushing, rebasing and retrying advances no round at all — and the one whose
52
+ * measurement this module cannot make itself: the caller reads the clock and
53
+ * hands it in (`TaskClock.elapsedMs`, already the active sum), since the
54
+ * per-phase times that survive a driver restart live in the durable control
55
+ * records, which nothing in this package may read.
43
56
  *
44
57
  * Reuse, not a second counter: the id-state map for each round is built by
45
58
  * calling `groupRounds` (`../review-status`) with synthetic same-key
@@ -52,7 +65,9 @@
52
65
  * there and nowhere else"), built on the reused map.
53
66
  */
54
67
 
68
+ import { CODE_TOKEN_PATTERN, ROLE_VALUES, type Role } from '../log/schema'
55
69
  import { groupRounds, type Round, type VerdictComment } from '../review-status'
70
+ import { isActiveBudgetPhase, taskPhaseLabel } from '../task-phase-history'
56
71
  import {
57
72
  SEVERITY_COLUMNS,
58
73
  type Confidence,
@@ -66,6 +81,7 @@ import {
66
81
  type RoundOutcome,
67
82
  type RoundRecord,
68
83
  type RoundStats,
84
+ type TaskClock,
69
85
  type VerdictObservation
70
86
  } from './types'
71
87
 
@@ -158,6 +174,39 @@ function toReviewFinding(f: VerdictObservation['findings'][number]): {
158
174
  }
159
175
  }
160
176
 
177
+ /** The doctrine role a verdict's own role names — `VerdictObservation.role` says `'reviewer'` where the log's role vocabulary says `'code-reviewer'`. */
178
+ function verdictLogRole(role: VerdictObservation['role']): Role {
179
+ return role === 'reviewer' ? 'code-reviewer' : role
180
+ }
181
+
182
+ /**
183
+ * One entry per reviewer role the loop held or expected a verdict from, taken
184
+ * from the verdicts themselves (never from the findings): a role that
185
+ * approved with no findings appears, and a configured role with no verdict
186
+ * reads `not_reviewed`. A blocking verdict contributes one blocker, so the
187
+ * entries add up to the event's own `blockers`; an `ESCALATE` verdict is not
188
+ * an approval and not a counted blocker, so it reads `changes_requested`
189
+ * with none.
190
+ */
191
+ function reviewerEntries(
192
+ state: LoopState,
193
+ verdicts: VerdictObservation[]
194
+ ): NonNullable<Extract<DevReviewLoopEventInput, { event: 'verdicts_read' }>['reviewers']> {
195
+ const held = new Map(verdicts.map((v) => [verdictLogRole(v.role), v]))
196
+ const isRole = (value: string): value is Role => (ROLE_VALUES as readonly string[]).includes(value)
197
+ const roles = [...new Set([...state.config.reviewers.filter(isRole), ...held.keys()])]
198
+ return roles.map((role) => {
199
+ const v = held.get(role)
200
+ const entry =
201
+ v === undefined
202
+ ? { outcome: 'not_reviewed' as const, blockers: 0 }
203
+ : v.verdict === 'APPROVE' || v.verdict === 'PASS'
204
+ ? { outcome: 'approve' as const, blockers: 0 }
205
+ : { outcome: 'changes_requested' as const, blockers: v.verdict === 'ESCALATE' ? 0 : 1 }
206
+ return { role, ...entry }
207
+ })
208
+ }
209
+
161
210
  function verdictsReadEvent(state: LoopState, round: number, verdicts: VerdictObservation[]): DevReviewLoopEventInput {
162
211
  const allApprove = verdicts.every((v) => v.verdict === 'APPROVE' || v.verdict === 'PASS')
163
212
  const head = pendingHead(state, round)
@@ -170,7 +219,8 @@ function verdictsReadEvent(state: LoopState, round: number, verdicts: VerdictObs
170
219
  head,
171
220
  all_approve: allApprove,
172
221
  blockers,
173
- findings
222
+ findings,
223
+ reviewers: reviewerEntries(state, verdicts)
174
224
  }
175
225
  }
176
226
 
@@ -192,6 +242,7 @@ function stopConditionMetEvent(
192
242
  | 'reappearance'
193
243
  | 'repeat_finding'
194
244
  | 'repeat_failure'
245
+ | 'time_budget'
195
246
  ): DevReviewLoopEventInput {
196
247
  return { ...loopEventEnvelope(state), event: 'stop_condition_met', round, condition }
197
248
  }
@@ -199,9 +250,16 @@ function stopConditionMetEvent(
199
250
  function pausedEvent(
200
251
  state: LoopState,
201
252
  round: number,
202
- reason: 'escalation' | 'principal_item'
253
+ reason: 'escalation' | 'principal_item',
254
+ reasonCode: string
203
255
  ): DevReviewLoopEventInput {
204
- return { ...loopEventEnvelope(state), event: 'paused', round, reason }
256
+ return {
257
+ ...loopEventEnvelope(state),
258
+ event: 'paused',
259
+ round,
260
+ reason,
261
+ reason_code: CODE_TOKEN_PATTERN.test(reasonCode) ? reasonCode : 'unknown'
262
+ }
205
263
  }
206
264
 
207
265
  function roundEndedEvent(
@@ -254,8 +312,8 @@ function buildRoundRecord(
254
312
  ): RoundRecord {
255
313
  // Every column this round MEASURED, seeded at zero before a single finding
256
314
  // is counted — so a round the loop assessed and found nothing in is a
257
- // recorded zero, not an absent count. The published table needs the two told
258
- // apart (`countCells`, `render-summary.ts`): a round rebuilt from the pull
315
+ // recorded zero, not an absent count. A reader needs the two told
316
+ // apart: a round rebuilt from the pull
259
317
  // request's markers after a restart has no counts at all, and must report
260
318
  // nothing rather than a zero a reader would take for a clean round.
261
319
  const countsBySeverity: Record<string, number> = {}
@@ -284,9 +342,7 @@ function buildRoundRecord(
284
342
  * below-threshold confidence sent the developer back — has no findings from any
285
343
  * source. Unlike `buildRoundRecord`, it records NO counts (an empty
286
344
  * `countsBySeverity`, the shape a marker-reconstructed round also carries), so
287
- * the published table reports `—` for every severity column through the
288
- * renderer's existing "counts have no source" path, never a `0` a reader would
289
- * take for a clean review (`countCells`, `render-summary.ts`). `outcome` is left
345
+ * no severity column reads as a `0` a reader would take for a clean review. `outcome` is left
290
346
  * exactly as this round would otherwise carry — the `round_ended` log event is
291
347
  * unchanged — and `notReviewed` names why no reviewer saw it for the table's
292
348
  * outcome cell.
@@ -456,7 +512,7 @@ function assessGate(
456
512
  const { failure, repeat } = matchFailure(state, obs.failure)
457
513
  if (repeat && failure !== null) {
458
514
  events.push(stopConditionMetEvent(state, obs.round, 'repeat_failure'))
459
- events.push(pausedEvent(state, obs.round, 'principal_item'))
515
+ events.push(pausedEvent(state, obs.round, 'principal_item', 'repeat_failure'))
460
516
  events.push(roundEndedEvent(state, obs.round, obs.stats, 'changes_requested'))
461
517
  const record = buildUnreviewedRecord(obs.round, null, 'stopped', 'checks_red')
462
518
  const preFinalize: LoopState = {
@@ -510,7 +566,7 @@ function assessGate(
510
566
  if (confidence === 'absent') {
511
567
  if (priorAskCount >= 1) {
512
568
  events.push(stopConditionMetEvent(state, obs.round, 'confidence'))
513
- events.push(pausedEvent(state, obs.round, 'principal_item'))
569
+ events.push(pausedEvent(state, obs.round, 'principal_item', 'confidence'))
514
570
  events.push(roundEndedEvent(state, obs.round, obs.stats, 'changes_requested'))
515
571
  const record = buildRoundRecord(obs.round, [], null, 'stopped')
516
572
  const preFinalize: LoopState = {
@@ -536,7 +592,7 @@ function assessGate(
536
592
  if (confidence.value < 50) {
537
593
  if (state.extraTurnUsed) {
538
594
  events.push(stopConditionMetEvent(state, obs.round, 'confidence'))
539
- events.push(pausedEvent(state, obs.round, 'principal_item'))
595
+ events.push(pausedEvent(state, obs.round, 'principal_item', 'confidence'))
540
596
  events.push(roundEndedEvent(state, obs.round, obs.stats, 'changes_requested'))
541
597
  const record = buildRoundRecord(obs.round, [], confidence, 'stopped')
542
598
  const preFinalize: LoopState = {
@@ -598,7 +654,7 @@ function assessVerdicts(
598
654
  const hasEscalate = obs.verdicts.some((v) => v.verdict === 'ESCALATE')
599
655
  if (hasEscalate) {
600
656
  events.push(stopConditionMetEvent(state, obs.round, 'escalated'))
601
- events.push(pausedEvent(state, obs.round, 'escalation'))
657
+ events.push(pausedEvent(state, obs.round, 'escalation', 'escalation'))
602
658
  events.push(roundEndedEvent(state, obs.round, pending.stats, 'escalated'))
603
659
  const record = buildRoundRecord(obs.round, obs.verdicts, confidence, 'escalated')
604
660
  const preFinalize: LoopState = {
@@ -635,7 +691,7 @@ function assessVerdicts(
635
691
 
636
692
  if (fc.recurring.length > 0) {
637
693
  events.push(stopConditionMetEvent(state, obs.round, 'reappearance'))
638
- events.push(pausedEvent(state, obs.round, 'principal_item'))
694
+ events.push(pausedEvent(state, obs.round, 'principal_item', 'reappearance'))
639
695
  events.push(roundEndedEvent(state, obs.round, pending.stats, 'changes_requested'))
640
696
  const record = buildRoundRecord(obs.round, obs.verdicts, confidence, 'stopped')
641
697
  const preFinalize: LoopState = {
@@ -652,7 +708,7 @@ function assessVerdicts(
652
708
 
653
709
  if (repeatedBlocking.length > 0) {
654
710
  events.push(stopConditionMetEvent(state, obs.round, 'repeat_finding'))
655
- events.push(pausedEvent(state, obs.round, 'principal_item'))
711
+ events.push(pausedEvent(state, obs.round, 'principal_item', 'repeat_finding'))
656
712
  events.push(roundEndedEvent(state, obs.round, pending.stats, 'changes_requested'))
657
713
  const record = buildRoundRecord(obs.round, obs.verdicts, confidence, 'stopped')
658
714
  const preFinalize: LoopState = {
@@ -677,9 +733,9 @@ function assessVerdicts(
677
733
  }
678
734
  }
679
735
 
680
- if (obs.round > state.config.maxRounds) {
736
+ if (obs.round >= state.config.maxRounds) {
681
737
  events.push(stopConditionMetEvent(state, obs.round, 'max_rounds'))
682
- events.push(pausedEvent(state, obs.round, 'principal_item'))
738
+ events.push(pausedEvent(state, obs.round, 'principal_item', 'max_rounds'))
683
739
  events.push(roundEndedEvent(state, obs.round, pending.stats, 'changes_requested'))
684
740
  const record = buildRoundRecord(obs.round, obs.verdicts, confidence, 'stopped')
685
741
  const preFinalize: LoopState = {
@@ -731,7 +787,7 @@ function assessMechanicalFailure(
731
787
  if (repeat && failure !== null) {
732
788
  const events: DevReviewLoopEventInput[] = [
733
789
  stopConditionMetEvent(state, obs.round, 'repeat_failure'),
734
- pausedEvent(state, obs.round, 'principal_item'),
790
+ pausedEvent(state, obs.round, 'principal_item', 'repeat_failure'),
735
791
  roundEndedEvent(state, obs.round, obs.stats, 'changes_requested')
736
792
  ]
737
793
  const record = buildUnreviewedRecord(obs.round, null, 'stopped', 'mechanical_failure')
@@ -752,17 +808,151 @@ function assessMechanicalFailure(
752
808
  return { decision: { type: 'dispatch_developer' }, state: { ...state, lastFailure: failure }, events: [] }
753
809
  }
754
810
 
811
+ // --- the task's own wall-clock budget --------------------------------------
812
+
813
+ /** Whole minutes, rounded to the nearest — every figure the time stop names a reader in. */
814
+ function minutesOf(ms: number): number {
815
+ return Math.round(ms / 60_000)
816
+ }
817
+
818
+ /**
819
+ * `true` when the task has spent longer than `maxTaskMinutes` in ACTIVE work —
820
+ * `clock.elapsedMs`, which the caller has already summed from the active phases
821
+ * alone (`activeBudgetMs`), so paused, publishing and driverless time can never
822
+ * blow the budget. `0` — and any value below it, which `resolveReviewPolicy`
823
+ * refuses at config load and this predicate still treats as off rather than as
824
+ * a budget already blown — turns the budget off: the loop then bounds rounds
825
+ * only, exactly as it did before this budget existed.
826
+ *
827
+ * The comparison is strictly greater, so a task sitting exactly on its budget
828
+ * has not passed it. The round cap reads the other way: a round that REACHES
829
+ * `state.config.maxRounds` without going green pauses, since the cap is the
830
+ * number of rounds that run.
831
+ */
832
+ export function taskBudgetExceeded(maxTaskMinutes: number, clock: TaskClock): boolean {
833
+ if (maxTaskMinutes <= 0) return false
834
+ return clock.elapsedMs > maxTaskMinutes * 60_000
835
+ }
836
+
837
+ /**
838
+ * Where the time went, longest phase first — `developing 190 min, reviewing
839
+ * 22 min`. Phases are named with `taskPhaseLabel`, the SAME vocabulary
840
+ * `task status` renders a live run's phase in, so the pause and the status
841
+ * table call one phase by one name; a phase that vocabulary does not know
842
+ * reads back as the loop's own recorded word rather than as a guess.
843
+ *
844
+ * A phase that accrued under a minute is still listed, at `0 min`: the loop
845
+ * recorded time there, and a reader is better served by a short row than by a
846
+ * phase silently missing. An empty breakdown renders `no phase times
847
+ * recorded` — the honest answer for a run whose earlier phases were recorded
848
+ * by a driver that has since died, never a fabricated single row covering the
849
+ * whole elapsed time.
850
+ */
851
+ export function renderPhaseBreakdown(byPhaseMs: Record<string, number>): string {
852
+ const entries = Object.entries(byPhaseMs).filter(([, ms]) => ms >= 0)
853
+ if (entries.length === 0) return 'no phase times recorded'
854
+ return entries
855
+ .sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]))
856
+ .map(([phase, ms]) => `${taskPhaseLabel(phase)} ${minutesOf(ms)} min`)
857
+ .join(', ')
858
+ }
859
+
860
+ /**
861
+ * The `'time_budget'` pause's own `detail` — the budget, the ACTIVE time
862
+ * actually spent, and the breakdown of the active phases that time was summed
863
+ * from, in that order, so a Principal reading it learns whether the budget is
864
+ * too tight or one working phase ran away without opening the run's log.
865
+ *
866
+ * `spent` is `clock.elapsedMs` — the very figure `taskBudgetExceeded` compared
867
+ * against the budget — and the breakdown names ONLY the active phases
868
+ * (`isActiveBudgetPhase`), so the numbers in the breakdown sum to the number
869
+ * reported as spent. Time the task sat `paused` or `publishing` is in
870
+ * `byPhaseMs` (the full record) but is deliberately absent here: it never
871
+ * counted toward the budget, so the pause never names it as time the budget
872
+ * spent.
873
+ */
874
+ export function renderTaskBudgetDetail(maxTaskMinutes: number, clock: TaskClock): string {
875
+ const activePhaseMs: Record<string, number> = {}
876
+ for (const [phase, ms] of Object.entries(clock.byPhaseMs)) {
877
+ if (isActiveBudgetPhase(phase)) activePhaseMs[phase] = ms
878
+ }
879
+ return `task time budget: ${maxTaskMinutes} min, spent ${minutesOf(clock.elapsedMs)} min — ${renderPhaseBreakdown(activePhaseMs)}`
880
+ }
881
+
755
882
  /**
756
- * `assessRound(state, observations) → { decision, state, events }` — pure,
757
- * no I/O. `events` is the `DevReviewLoopEventInput[]` the caller passes,
883
+ * The time stop, built in the same four-event shape every other bounded pause
884
+ * here emits (`stop_condition_met`, `paused`, `round_ended`,
885
+ * `journal_finalized`) so a reader — or a machine parsing the outbox — sees a
886
+ * complete pause record, not a special case.
887
+ *
888
+ * The round it lands on is a round no reviewer saw, and records as one
889
+ * (`notReviewed: 'time_budget'`, no counts): this
890
+ * stop is only ever checked at a round boundary or a mechanical retry, never
891
+ * on a `verdicts` observation, so verdicts already back from reviewers are
892
+ * never thrown away by it. `lastFailure` is left exactly as it stands — the
893
+ * budget running out says nothing about whether the previous attempt's
894
+ * mechanical failure has cleared.
895
+ */
896
+ function timeBudgetPause(
897
+ state: LoopState,
898
+ obs: { round: number; stats: RoundStats },
899
+ clock: TaskClock
900
+ ): { decision: Decision; state: LoopState; events: DevReviewLoopEventInput[] } {
901
+ const events: DevReviewLoopEventInput[] = [
902
+ stopConditionMetEvent(state, obs.round, 'time_budget'),
903
+ pausedEvent(state, obs.round, 'principal_item', 'time_budget'),
904
+ roundEndedEvent(state, obs.round, obs.stats, 'changes_requested')
905
+ ]
906
+ const record = buildUnreviewedRecord(obs.round, null, 'stopped', 'time_budget')
907
+ const preFinalize: LoopState = {
908
+ ...state,
909
+ rounds: [...state.rounds, record],
910
+ pending: null,
911
+ ...withRoundStats(state, obs.stats)
912
+ }
913
+ events.push(journalFinalizedEvent(preFinalize, obs.stats.head, 'stopped'))
914
+ return {
915
+ decision: {
916
+ type: 'pause',
917
+ reason: 'time_budget',
918
+ detail: renderTaskBudgetDetail(state.config.maxTaskMinutes, clock)
919
+ },
920
+ state: preFinalize,
921
+ events
922
+ }
923
+ }
924
+
925
+ /**
926
+ * `assessRound(state, observations, clock?) → { decision, state, events }` —
927
+ * pure, no I/O. `events` is the `DevReviewLoopEventInput[]` the caller passes,
758
928
  * unchanged, to the injected `log()`; `assessRound` itself never calls
759
929
  * it.
930
+ *
931
+ * `clock` is the task's own wall clock, read by the caller (this module has
932
+ * none). Supplied, it arms the `'time_budget'` stop below; omitted, the
933
+ * assessment is exactly the round-and-repeat-bounded one it was — so a caller
934
+ * that cannot measure the task's first start honestly passes nothing rather
935
+ * than a clock starting at its own process's start, which would mean a loop
936
+ * restarted often enough never approaches its budget.
937
+ *
938
+ * The budget is checked on a `gate` observation and on a `mechanical_failure`
939
+ * observation, and on neither of those does a round's review exist yet: those
940
+ * two kinds are exactly the round boundaries and the mechanical retries, so a
941
+ * phase stuck short of review cannot outrun the budget by more than the one
942
+ * attempt in flight when it ran out. A `verdicts` observation is deliberately
943
+ * NOT checked — reviewers have already done the round's work by then, and
944
+ * discarding their verdicts to save minutes the round has already spent would
945
+ * buy nothing.
760
946
  */
761
947
  export function assessRound(
762
948
  state: LoopState,
763
- observations: Observations
949
+ observations: Observations,
950
+ clock?: TaskClock
764
951
  ): { decision: Decision; state: LoopState; events: DevReviewLoopEventInput[] } {
952
+ if (observations.kind === 'verdicts') return assessVerdicts(state, observations)
953
+ if (clock !== undefined && taskBudgetExceeded(state.config.maxTaskMinutes, clock)) {
954
+ return timeBudgetPause(state, observations, clock)
955
+ }
765
956
  if (observations.kind === 'gate') return assessGate(state, observations)
766
- if (observations.kind === 'mechanical_failure') return assessMechanicalFailure(state, observations)
767
- return assessVerdicts(state, observations)
957
+ return assessMechanicalFailure(state, observations)
768
958
  }
@@ -14,6 +14,7 @@ import type {
14
14
  LoopState,
15
15
  Observations,
16
16
  RoundStats,
17
+ TaskClock,
17
18
  VerdictObservation
18
19
  } from './types'
19
20
 
@@ -97,16 +98,23 @@ export function notMetVerdict(role: 'reviewer' | 'security', objectiveIds: strin
97
98
  * state forward and concatenating every emitted event — the shape Part 1's
98
99
  * byte-for-byte event-list assertion needs. Returns the final state, the flat
99
100
  * event list, and every decision returned along the way (in order).
101
+ *
102
+ * `clockAt` is the task's wall clock as the real driver would read it before
103
+ * each step, by step index — the scripted equivalent of a run whose elapsed
104
+ * time grows between observations. Omitted, no clock is passed at all, which
105
+ * is exactly a caller that cannot measure the task's first start: the time
106
+ * budget is then never armed and every existing scenario behaves as before.
100
107
  */
101
108
  export function runScenario(
102
109
  initial: LoopState,
103
- steps: Observations[]
110
+ steps: Observations[],
111
+ clockAt?: (index: number) => TaskClock | undefined
104
112
  ): { state: LoopState; events: DevReviewLoopEventInput[]; decisions: Decision[] } {
105
113
  let state = initial
106
114
  const events: DevReviewLoopEventInput[] = []
107
115
  const decisions: Decision[] = []
108
- for (const step of steps) {
109
- const result = assessRound(state, step)
116
+ for (const [index, step] of steps.entries()) {
117
+ const result = assessRound(state, step, clockAt?.(index))
110
118
  state = result.state
111
119
  events.push(...result.events)
112
120
  decisions.push(result.decision)
@@ -1,5 +1,5 @@
1
- export { assessRound } from './assess-round'
2
- export { parseSummaryConfidenceRows, renderSummary } from './render-summary'
1
+ export { assessRound, renderPhaseBreakdown, renderTaskBudgetDetail, taskBudgetExceeded } from './assess-round'
2
+ export { parseSummaryConfidenceRows, renderPublishedMarker } from './render-summary'
3
3
  export type { SummaryConfidenceRow } from './render-summary'
4
4
  export { initialLoopState } from './types'
5
5
  export {
@@ -7,8 +7,8 @@ export {
7
7
  isConcludedJournal,
8
8
  isPublishedSummaryComment,
9
9
  nextRoundNumber,
10
- reconstructRounds,
11
- SUMMARY_TABLE_HEADER
10
+ PUBLISHED_MARKER_LINE,
11
+ reconstructRounds
12
12
  } from './journal-reconstruction'
13
13
  export type { ReconstructedJournal, ReconstructionInput, ReviewGateFact } from './journal-reconstruction'
14
14
  export type {
@@ -28,5 +28,6 @@ export type {
28
28
  RoundOutcome,
29
29
  RoundRecord,
30
30
  RoundStats,
31
+ TaskClock,
31
32
  VerdictObservation
32
33
  } from './types'