@attalabs/vinaya 0.31.0 → 0.33.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 (212) hide show
  1. package/README.md +2 -3
  2. package/aeg-root/contracts/principal-operator.md +18 -5
  3. package/aeg-root/roles/developer/reference.md +3 -3
  4. package/aeg-root/roles/operator.md +69 -16
  5. package/aeg-root/roles/planner/reference.md +1 -1
  6. package/aeg-root/roles/tranche-archivist.md +1 -0
  7. package/aeg-root/skills/aeg-context-packets/SKILL.md +1 -1
  8. package/aeg-root/skills/aeg-context-packets/examples/operator-start.md +1 -1
  9. package/aeg-root/templates/pr-report-template.md +7 -2
  10. package/dist/checks/bin/check-body-bare-digits.js +340 -101
  11. package/dist/checks/bin/check-branch-topology.js +184 -105
  12. package/dist/checks/bin/check-brief-shape.js +333 -94
  13. package/dist/checks/bin/check-changeset-coverage.js +1028 -248
  14. package/dist/checks/bin/check-ci-shard-coverage.js +82 -0
  15. package/dist/checks/bin/check-closes-n.js +184 -105
  16. package/dist/checks/bin/check-coherence.js +345 -145
  17. package/dist/checks/bin/check-dead-branch-push.js +179 -59
  18. package/dist/checks/bin/check-dispatch-readiness.js +350 -150
  19. package/dist/checks/bin/check-doc-coverage-push.js +1011 -231
  20. package/dist/checks/bin/check-doc-coverage.js +1015 -235
  21. package/dist/checks/bin/check-doctrine-no-procedures.js +333 -94
  22. package/dist/checks/bin/check-doctrine-portability.js +1013 -233
  23. package/dist/checks/bin/check-evidence-fresh.js +1010 -222
  24. package/dist/checks/bin/check-exec-bits.js +1009 -229
  25. package/dist/checks/bin/check-first-push-dispatch.js +343 -145
  26. package/dist/checks/bin/check-issue-assignment.js +186 -107
  27. package/dist/checks/bin/check-issue-milestone-attach.js +176 -56
  28. package/dist/checks/bin/check-issue-objectives-numbering.js +176 -56
  29. package/dist/checks/bin/check-issue-parts-coverage.js +176 -56
  30. package/dist/checks/bin/check-issue-surface-globs.js +363 -143
  31. package/dist/checks/bin/check-issue-title-grammar.js +176 -56
  32. package/dist/checks/bin/check-issue-tranche-label.js +176 -56
  33. package/dist/checks/bin/check-main-branch-refusal.js +176 -56
  34. package/dist/checks/bin/check-no-disk-state.js +176 -56
  35. package/dist/checks/bin/check-pr-premise-reassert.js +333 -92
  36. package/dist/checks/bin/check-pr-report-density.js +176 -56
  37. package/dist/checks/bin/check-principal-test-plan-wait.js +176 -54
  38. package/dist/checks/bin/check-quoted-command.js +999 -217
  39. package/dist/checks/bin/check-reader-resolvable-prose.js +1011 -229
  40. package/dist/checks/bin/check-registry-gates.js +186 -56
  41. package/dist/checks/bin/check-retired-vocabulary.js +997 -215
  42. package/dist/checks/bin/check-review-gate.js +403 -203
  43. package/dist/checks/bin/check-single-plan-pr.js +176 -56
  44. package/dist/checks/bin/check-surface-scope.js +184 -105
  45. package/dist/checks/bin/check-test-plan.js +176 -54
  46. package/dist/checks/bin/check-token-collection-wired.js +182 -57
  47. package/dist/checks/bin/check-token-report.js +178 -58
  48. package/dist/checks/bin/check-workspace-escape.js +1011 -229
  49. package/dist/index.js +5971 -3489
  50. package/dist/lib/pre-push-cache-test-run.js +4431 -0
  51. package/dist/lib/pre-push-select-tests.js +799 -110
  52. package/package.json +3 -2
  53. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/actions.ts +10 -12
  54. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/anchored-region.ts +5 -5
  55. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/archive-task.ts +42 -17
  56. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/baseline-capture.ts +1 -2
  57. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/branch-topology-gate.ts +3 -3
  58. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/brief-render.ts +554 -95
  59. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/brief-validation.ts +264 -44
  60. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/claude-code-transcript.ts +9 -9
  61. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/coherence-checks.ts +211 -30
  62. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/consumer-enumeration.ts +2 -2
  63. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/control-store/index.ts +75 -0
  64. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/control-store/local.ts +961 -0
  65. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/control-store/migration.ts +212 -0
  66. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/control-store/outcomes.ts +135 -0
  67. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/control-store/records.ts +394 -0
  68. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dead-branch-push-audit.ts +1 -2
  69. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dead-branch-push-guard.ts +1 -1
  70. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/derive-section7.ts +2 -2
  71. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/assess-round.ts +514 -0
  72. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/fakes.ts +110 -0
  73. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/index.ts +27 -0
  74. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/journal-reconstruction.ts +123 -0
  75. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/render-summary.ts +27 -0
  76. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/types.ts +240 -0
  77. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/diagram-model.ts +1 -1
  78. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/direct-main-push.ts +1 -2
  79. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dispatch-gate.ts +65 -22
  80. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/doc-claim.ts +238 -0
  81. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/doc-owners.ts +14 -1
  82. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/docs/docs-coherence.ts +1 -1
  83. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/docs/legacy-anchors.ts +1 -1
  84. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/docs/node-route.ts +1 -1
  85. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/docs/surfaced-manifest.ts +1 -1
  86. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/doctrine-no-procedures.ts +1 -1
  87. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/doctrine-portability.ts +5 -5
  88. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/ensure-label.ts +1 -1
  89. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/first-push-dispatch-gate.ts +1 -1
  90. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/gate-audience.ts +14 -3
  91. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/index.ts +379 -11
  92. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/issue-assignment.ts +3 -4
  93. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/issue-validation.ts +1450 -33
  94. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/leftover-detection.ts +1 -2
  95. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/local-anchor-coverage.ts +2 -2
  96. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/envelope.ts +119 -0
  97. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/index.ts +75 -0
  98. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/redact.ts +87 -0
  99. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/schema.ts +801 -0
  100. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/store.ts +373 -0
  101. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/main-branch-refusal.ts +2 -2
  102. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/metering-io-guard.ts +1 -1
  103. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/milestone-validation.ts +2 -3
  104. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/no-disk-state.ts +2 -2
  105. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/objectives.ts +288 -0
  106. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/parse-token-report.ts +3 -3
  107. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/parse-tranche.ts +1 -1
  108. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/pr-report-density.ts +30 -16
  109. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/pr-tier.ts +17 -1
  110. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/premise-check.ts +1 -1
  111. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/quoted-command.ts +1 -1
  112. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/reader-resolvable-prose.ts +267 -19
  113. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/registry-checks.ts +91 -24
  114. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/registry-scaffold.ts +6 -6
  115. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/report-tokens.ts +4 -4
  116. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-gate.ts +239 -110
  117. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-input-manifest.ts +384 -0
  118. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-policy.ts +184 -0
  119. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-status.ts +65 -18
  120. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/ruling-ordinal.ts +76 -0
  121. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/single-plan-pr.ts +4 -4
  122. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/state-machine-model.ts +40 -27
  123. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/symbol-collisions.ts +2 -2
  124. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/task-branch-identity.ts +38 -0
  125. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/task-tools.ts +488 -0
  126. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/test-plan-gate.ts +7 -9
  127. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/test-plan-section.ts +5 -5
  128. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/types.ts +4 -4
  129. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/verdict-extraction.ts +314 -56
  130. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/waiver-label.ts +2 -3
  131. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/workspace-escape.ts +3 -3
  132. package/studio-standalone/apps/vinaya-studio/web/.next/BUILD_ID +1 -1
  133. package/studio-standalone/apps/vinaya-studio/web/.next/build-manifest.json +3 -3
  134. package/studio-standalone/apps/vinaya-studio/web/.next/prerender-manifest.json +3 -3
  135. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.html +1 -1
  136. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.rsc +1 -1
  137. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
  138. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  139. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  140. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  141. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  142. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page/server-reference-manifest.json +2 -2
  143. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page.js.nft.json +1 -1
  144. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  145. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/api/coherence/route.js +1 -1
  146. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/api/coherence/route.js.nft.json +1 -1
  147. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page/server-reference-manifest.json +2 -2
  148. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page.js.nft.json +1 -1
  149. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page_client-reference-manifest.js +1 -1
  150. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page/server-reference-manifest.json +2 -2
  151. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page.js +1 -1
  152. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page.js.nft.json +1 -1
  153. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page_client-reference-manifest.js +1 -1
  154. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page/server-reference-manifest.json +2 -2
  155. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page.js +1 -1
  156. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page.js.nft.json +1 -1
  157. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page_client-reference-manifest.js +1 -1
  158. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page/server-reference-manifest.json +2 -2
  159. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page.js +1 -1
  160. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page.js.nft.json +1 -1
  161. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page_client-reference-manifest.js +1 -1
  162. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page/server-reference-manifest.json +3 -3
  163. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page.js +2 -2
  164. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page.js.nft.json +1 -1
  165. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page_client-reference-manifest.js +1 -1
  166. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page/server-reference-manifest.json +2 -2
  167. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page.js +1 -1
  168. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page.js.nft.json +1 -1
  169. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page_client-reference-manifest.js +1 -1
  170. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page/server-reference-manifest.json +2 -2
  171. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page.js +1 -1
  172. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page.js.nft.json +1 -1
  173. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page_client-reference-manifest.js +1 -1
  174. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page/server-reference-manifest.json +2 -2
  175. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page.js +1 -1
  176. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page.js.nft.json +1 -1
  177. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page_client-reference-manifest.js +1 -1
  178. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/{[externals]__1agj1ww._.js → [externals]__0cki-x_._.js} +2 -2
  179. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/[root-of-the-server]__02a-3g8._.js +6 -6
  180. 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
  181. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__074w9nf._.js +3 -0
  182. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__0ls23oh._.js +1 -1
  183. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/{[root-of-the-server]__0r7e54g._.js → [root-of-the-server]__18paley._.js} +1 -1
  184. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1gjqmhq._.js +1 -1
  185. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1wc4-ip._.js +1 -1
  186. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/{[root-of-the-server]__1r47dr7._.js → _08onyya._.js} +3 -3
  187. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_096f46i._.js +1 -1
  188. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0af2one._.js +1 -1
  189. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0e5tkdd._.js +1 -1
  190. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0kf2g72._.js +1 -1
  191. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0y1jv16._.js +1 -1
  192. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0zf4d27._.js +1 -1
  193. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_1-wo68i._.js +1 -1
  194. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_15gdg48._.js +5 -5
  195. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_1achbh9._.js +1 -1
  196. 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
  197. package/studio-standalone/apps/vinaya-studio/web/.next/server/middleware-build-manifest.js +3 -3
  198. package/studio-standalone/apps/vinaya-studio/web/.next/server/pages/500.html +1 -1
  199. package/studio-standalone/apps/vinaya-studio/web/.next/server/server-reference-manifest.js +1 -1
  200. package/studio-standalone/apps/vinaya-studio/web/.next/server/server-reference-manifest.json +4 -4
  201. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/0bjnj-5fy4e7l.js +1 -0
  202. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{1dc2_-c_gavj1.js → 1ce2dj27_cgbj.js} +4 -4
  203. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{3xg6-flovrcx-.js → 22s44f5k3ecmj.js} +1 -1
  204. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/34hhdtbp20krb.js +1 -0
  205. package/studio-standalone/apps/vinaya-studio/web/package.json +2 -2
  206. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__0hstap0._.js +0 -3
  207. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/2t_rfsztmwu6y.js +0 -1
  208. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/3ua4rm5f-a9k6.js +0 -1
  209. /package/studio-standalone/_node_modules/@attalabs/vinaya/studio-standalone/_node_modules/@attalabs/vinaya/studio-standalone/_node_modules/@attalabs/vinaya/studio-standalone/_node_modules/@attalabs/vinaya/studio-standalone/_node_modules/@attalabs/{aeg-core → vinaya/studio-standalone/_node_modules/@attalabs/aeg-core}/bin/verify-coherence.ts +0 -0
  210. /package/studio-standalone/apps/vinaya-studio/web/.next/static/{e8XbZ2vlVz40KzHmlqhwP → vl7QVqELe1AQ-9kaOd9mR}/_buildManifest.js +0 -0
  211. /package/studio-standalone/apps/vinaya-studio/web/.next/static/{e8XbZ2vlVz40KzHmlqhwP → vl7QVqELe1AQ-9kaOd9mR}/_clientMiddlewareManifest.js +0 -0
  212. /package/studio-standalone/apps/vinaya-studio/web/.next/static/{e8XbZ2vlVz40KzHmlqhwP → vl7QVqELe1AQ-9kaOd9mR}/_ssgManifest.js +0 -0
@@ -0,0 +1,212 @@
1
+ /**
2
+ * One-time migration from the dev-review-loop's pre-control-store side
3
+ * files (`apps/cli/src/lib/dev-review-loop/pause-resume.ts`'s
4
+ * `driver.pid.json`/`pause-state.json`, `publication.ts`'s
5
+ * `effect-<key>.json`) into a task's first control-store epoch.
6
+ *
7
+ * This module reads the legacy layout directly rather than importing
8
+ * `apps/cli` — the dependency runs the other way (the CLI depends on
9
+ * `@attalabs/aeg-core`, never the reverse) — so the three legacy shapes
10
+ * below are a deliberate, narrow re-statement of what those two files
11
+ * already write, not a shared implementation.
12
+ *
13
+ * Refuses rather than guesses whenever ownership would be ambiguous:
14
+ * a legacy driver whose pid still answers a liveness probe is still
15
+ * mutating those side files, so migrating underneath it would race it;
16
+ * a task that already holds a control-store epoch has already moved on
17
+ * from the legacy layout, so re-migrating it would silently overwrite
18
+ * real history. Both refuse rather than pick a side.
19
+ */
20
+
21
+ import { existsSync, readdirSync, readFileSync } from 'node:fs'
22
+ import { join } from 'node:path'
23
+ import {
24
+ acquireOwnership,
25
+ appendTransition,
26
+ type ControlStoreDeps,
27
+ readCurrentOwnership,
28
+ writeInput,
29
+ writeRun
30
+ } from './local'
31
+
32
+ type LegacyRead<T> = { status: 'ok'; value: T } | { status: 'absent' } | { status: 'corrupt'; reason: string }
33
+
34
+ function readLegacyJson<T>(path: string, isShape: (json: unknown) => json is T): LegacyRead<T> {
35
+ let raw: string
36
+ try {
37
+ raw = readFileSync(path, 'utf8')
38
+ } catch (err) {
39
+ if (typeof err === 'object' && err !== null && (err as NodeJS.ErrnoException).code === 'ENOENT') {
40
+ return { status: 'absent' }
41
+ }
42
+ return { status: 'corrupt', reason: err instanceof Error ? err.message : String(err) }
43
+ }
44
+ let json: unknown
45
+ try {
46
+ json = JSON.parse(raw)
47
+ } catch (err) {
48
+ return { status: 'corrupt', reason: `invalid JSON: ${err instanceof Error ? err.message : String(err)}` }
49
+ }
50
+ if (!isShape(json)) return { status: 'corrupt', reason: 'does not match the expected legacy shape' }
51
+ return { status: 'ok', value: json }
52
+ }
53
+
54
+ type LegacyDriverLock = { pid: number; startedAt: string }
55
+ function isLegacyDriverLock(json: unknown): json is LegacyDriverLock {
56
+ return (
57
+ typeof json === 'object' &&
58
+ json !== null &&
59
+ typeof (json as Record<string, unknown>).pid === 'number' &&
60
+ typeof (json as Record<string, unknown>).startedAt === 'string'
61
+ )
62
+ }
63
+
64
+ type LegacyPauseState = {
65
+ round: number
66
+ reason: string
67
+ detail?: string
68
+ prNumber: number
69
+ pausedAt: string
70
+ }
71
+ function isLegacyPauseState(json: unknown): json is LegacyPauseState {
72
+ const rec = json as Record<string, unknown>
73
+ return (
74
+ typeof json === 'object' &&
75
+ json !== null &&
76
+ typeof rec.round === 'number' &&
77
+ typeof rec.reason === 'string' &&
78
+ typeof rec.prNumber === 'number' &&
79
+ typeof rec.pausedAt === 'string' &&
80
+ (rec.detail === undefined || typeof rec.detail === 'string')
81
+ )
82
+ }
83
+
84
+ type LegacyEffectRecord = { effectId: string; status: 'started' | 'posted'; url?: string }
85
+ function isLegacyEffectRecord(json: unknown): json is LegacyEffectRecord {
86
+ const rec = json as Record<string, unknown>
87
+ return (
88
+ typeof json === 'object' &&
89
+ json !== null &&
90
+ typeof rec.effectId === 'string' &&
91
+ (rec.status === 'started' || rec.status === 'posted') &&
92
+ (rec.url === undefined || typeof rec.url === 'string')
93
+ )
94
+ }
95
+
96
+ function legacyTaskDir(legacyOutboxRoot: string, task: number): string {
97
+ return join(legacyOutboxRoot, 'dev-review-loop', String(task))
98
+ }
99
+
100
+ /** The same signal-0 liveness idiom `pause-resume.ts`'s `isDriverPidAlive` uses — restated here so this module never imports across the CLI/engine boundary. Used only as a one-time migration-timing safety gate, never as this store's own ownership model (that model is the epoch fence in `local.ts`). */
101
+ export function defaultIsPidAlive(pid: number): boolean {
102
+ try {
103
+ process.kill(pid, 0)
104
+ return true
105
+ } catch {
106
+ return false
107
+ }
108
+ }
109
+
110
+ export type MigrationResult =
111
+ | { status: 'migrated'; task: number; epoch: number; transitionsWritten: number }
112
+ | { status: 'nothing-to-migrate'; task: number }
113
+ | { status: 'refused'; reason: string }
114
+
115
+ export function migrateLegacyTask(
116
+ deps: ControlStoreDeps,
117
+ legacyOutboxRoot: string,
118
+ task: number,
119
+ ownerId: string,
120
+ isPidAlive: (pid: number) => boolean = defaultIsPidAlive
121
+ ): MigrationResult {
122
+ const dir = legacyTaskDir(legacyOutboxRoot, task)
123
+ if (!existsSync(dir)) return { status: 'nothing-to-migrate', task }
124
+
125
+ const driverLock = readLegacyJson(join(dir, 'driver.pid.json'), isLegacyDriverLock)
126
+ if (driverLock.status === 'corrupt') {
127
+ return { status: 'refused', reason: `legacy driver.pid.json for task ${task} is corrupt: ${driverLock.reason}` }
128
+ }
129
+ if (driverLock.status === 'ok' && isPidAlive(driverLock.value.pid)) {
130
+ return {
131
+ status: 'refused',
132
+ reason: `legacy driver pid ${driverLock.value.pid} is still live for task ${task} — migrate only after it exits`
133
+ }
134
+ }
135
+
136
+ const pauseState = readLegacyJson(join(dir, 'pause-state.json'), isLegacyPauseState)
137
+ if (pauseState.status === 'corrupt') {
138
+ return { status: 'refused', reason: `legacy pause-state.json for task ${task} is corrupt: ${pauseState.reason}` }
139
+ }
140
+
141
+ const effectFiles = readdirSync(dir)
142
+ .filter((name) => /^effect-.+\.json$/.test(name))
143
+ .sort()
144
+ const effects: { key: string; record: LegacyEffectRecord }[] = []
145
+ for (const name of effectFiles) {
146
+ const parsed = readLegacyJson(join(dir, name), isLegacyEffectRecord)
147
+ if (parsed.status === 'corrupt') {
148
+ return { status: 'refused', reason: `legacy ${name} for task ${task} is corrupt: ${parsed.reason}` }
149
+ }
150
+ if (parsed.status === 'ok') {
151
+ effects.push({ key: name.replace(/^effect-/, '').replace(/\.json$/, ''), record: parsed.value })
152
+ }
153
+ }
154
+
155
+ if (driverLock.status === 'absent' && pauseState.status === 'absent' && effects.length === 0) {
156
+ return { status: 'nothing-to-migrate', task }
157
+ }
158
+
159
+ const priorEpoch = readCurrentOwnership(deps, task)
160
+ if (priorEpoch.epoch > 0) {
161
+ return {
162
+ status: 'refused',
163
+ reason: `task ${task} already has a control-store epoch ${priorEpoch.epoch} — migration only runs against a task with no existing epoch`
164
+ }
165
+ }
166
+
167
+ const acquired = acquireOwnership(deps, task, ownerId)
168
+ if (!acquired.acquired) {
169
+ return {
170
+ status: 'refused',
171
+ reason: `task ${task} already has a control-store epoch ${acquired.currentEpoch} — migration only runs against a task with no existing epoch`
172
+ }
173
+ }
174
+ const epoch = acquired.epoch
175
+
176
+ const now = deps.now().toISOString()
177
+ writeRun(deps, task, epoch, {
178
+ runId: ownerId,
179
+ pid: driverLock.status === 'ok' ? driverLock.value.pid : deps.pid(),
180
+ host: deps.hostname(),
181
+ startedAt: driverLock.status === 'ok' ? driverLock.value.startedAt : now
182
+ })
183
+ writeInput(deps, task, epoch, {
184
+ runId: ownerId,
185
+ source: pauseState.status === 'ok' ? 'resume' : 'fresh',
186
+ pr: pauseState.status === 'ok' ? pauseState.value.prNumber : null,
187
+ round: pauseState.status === 'ok' ? pauseState.value.round : 0,
188
+ recordedAt: now
189
+ })
190
+
191
+ let transitionsWritten = 0
192
+ if (pauseState.status === 'ok') {
193
+ appendTransition(deps, task, epoch, {
194
+ from: 'active',
195
+ to: `paused:${pauseState.value.reason}`,
196
+ detail: pauseState.value.detail,
197
+ at: pauseState.value.pausedAt
198
+ })
199
+ transitionsWritten++
200
+ }
201
+ for (const { key, record } of effects) {
202
+ appendTransition(deps, task, epoch, {
203
+ from: 'pending',
204
+ to: `effect:${key}:${record.status}`,
205
+ detail: record.url,
206
+ at: now
207
+ })
208
+ transitionsWritten++
209
+ }
210
+
211
+ return { status: 'migrated', task, epoch, transitionsWritten }
212
+ }
@@ -0,0 +1,135 @@
1
+ /**
2
+ * The parent-validated outcome normalizer (O2). One pure function that turns
3
+ * the raw signals a launch leaves behind — did it time out, was it cancelled,
4
+ * did the capability refuse, did the infrastructure fail, are the required
5
+ * artifacts on disk, do the declared postconditions hold, and what exit code
6
+ * it returned — into ONE truthful outcome, drawn from a closed vocabulary:
7
+ *
8
+ * - `completed` — the work is genuinely done: the required
9
+ * artifacts exist and every declared
10
+ * postcondition holds.
11
+ * - `incomplete` — the attempt ended without the work being done:
12
+ * a required artifact is missing, or a
13
+ * postcondition is unmet. **This is the case a
14
+ * bare exit code hides:** a process that exits 0
15
+ * having produced nothing is `incomplete`, never
16
+ * `completed` — the whole point of this
17
+ * normalizer is that exit zero is never equated
18
+ * with task success.
19
+ * - `infrastructure-failed`— the launch itself failed (a crash, a spawn
20
+ * fault) before it could fairly attempt the work
21
+ * — not the task's own doing.
22
+ * - `timed-out` — the ceiling fired and the launch was killed.
23
+ * - `cancelled` — an operator or a supervisor stopped it.
24
+ * - `capability-refused` — the capability declined the work up front (a
25
+ * missing/rejected binary, a refused model) —
26
+ * distinct from an infrastructure fault mid-run.
27
+ *
28
+ * **Exit code is an INPUT, never the decider.** It is carried into the
29
+ * outcome's `reason` for the record, but the `completed`/`incomplete` split is
30
+ * decided ENTIRELY by `artifactsPresent`/`postconditionsMet` — a non-zero
31
+ * exit with the artifacts genuinely present and the postconditions met still
32
+ * reads `completed` (the artifacts are the truth), and a zero exit with a
33
+ * missing artifact still reads `incomplete`. The manner-of-death signals
34
+ * (`refused`/`cancelled`/`timedOut`/`infrastructure`) take precedence over
35
+ * the artifact read, because an attempt the ceiling killed, the operator
36
+ * stopped, or the infrastructure broke never got a fair chance to leave its
37
+ * artifacts, and misreporting it as a plain `incomplete` would blame the task
38
+ * for the environment's failure.
39
+ *
40
+ * Pure — no `fs`, no clock, no process access. The caller (a parent
41
+ * validating a launch — `apps/cli/src/lib/dispatch.ts`'s launcher, the
42
+ * dev-review-loop's recovery) supplies every signal; this only classifies.
43
+ */
44
+
45
+ /** The closed outcome vocabulary a parent-validated launch resolves to (O2). */
46
+ export type TaskOutcomeStatus =
47
+ | 'completed'
48
+ | 'incomplete'
49
+ | 'infrastructure-failed'
50
+ | 'timed-out'
51
+ | 'cancelled'
52
+ | 'capability-refused'
53
+
54
+ /**
55
+ * The raw signals a launch leaves behind, as observed by the parent that
56
+ * validates it. `exitCode` is carried for the record only — it never decides
57
+ * the `completed`/`incomplete` split (see this module's own doc). The four
58
+ * manner-of-death booleans are mutually exhaustive with "ran to a natural
59
+ * end"; when more than one is somehow set, the precedence in `normalizeOutcome`
60
+ * decides which one names the outcome.
61
+ */
62
+ export type OutcomeSignals = {
63
+ /** The process exit code, or `null` when the launch never produced one (a pre-spawn refusal, a signal death). Input only — never the decider. */
64
+ exitCode: number | null
65
+ /** The ceiling fired and the launch was killed. */
66
+ timedOut: boolean
67
+ /** An operator or supervisor stopped the launch. */
68
+ cancelled: boolean
69
+ /** The capability declined the work up front — a missing or rejected binary, a refused model — before it ever ran. */
70
+ refused: boolean
71
+ /** The launch itself failed (a crash, a spawn fault) — an environment failure, not the task's own doing. */
72
+ infrastructure: boolean
73
+ /** The required work artifacts exist — the parent's own check, never inferred from the exit code. */
74
+ artifactsPresent: boolean
75
+ /** Every declared postcondition holds — likewise the parent's own check. */
76
+ postconditionsMet: boolean
77
+ }
78
+
79
+ export type NormalizedOutcome = {
80
+ status: TaskOutcomeStatus
81
+ /** A human-readable justification carrying the deciding facts — including the exit code, so a reader sees it was considered as input without it having decided anything. */
82
+ reason: string
83
+ }
84
+
85
+ function exitCodeNote(exitCode: number | null): string {
86
+ return exitCode === null ? 'no exit code' : `exit code ${exitCode}`
87
+ }
88
+
89
+ /**
90
+ * Classify one launch's raw signals into a single truthful outcome (O2). See
91
+ * this module's own doc for the vocabulary, the exit-code-is-input-only rule,
92
+ * and why the manner-of-death signals take precedence over the artifact read.
93
+ */
94
+ export function normalizeOutcome(signals: OutcomeSignals): NormalizedOutcome {
95
+ const { exitCode, timedOut, cancelled, refused, infrastructure, artifactsPresent, postconditionsMet } = signals
96
+
97
+ // Manner-of-death first: an attempt that was refused, cancelled, timed out,
98
+ // or broke on infrastructure never got a fair chance to leave its
99
+ // artifacts, so its outcome is named by HOW it ended, never by an artifact
100
+ // read that was never going to succeed. Order among them is deliberate:
101
+ // a refusal happens before anything runs; a cancellation and a timeout are
102
+ // both external stops (cancellation is the operator's intent, checked first
103
+ // so a cancel that also tripped the ceiling still reads as the deliberate
104
+ // stop); an infrastructure fault is the catch-all launch failure.
105
+ if (refused) {
106
+ return { status: 'capability-refused', reason: `the capability refused the launch (${exitCodeNote(exitCode)})` }
107
+ }
108
+ if (cancelled) {
109
+ return { status: 'cancelled', reason: `the launch was cancelled (${exitCodeNote(exitCode)})` }
110
+ }
111
+ if (timedOut) {
112
+ return { status: 'timed-out', reason: `the launch exceeded its ceiling and was killed (${exitCodeNote(exitCode)})` }
113
+ }
114
+ if (infrastructure) {
115
+ return {
116
+ status: 'infrastructure-failed',
117
+ reason: `the launch failed on infrastructure, not the task itself (${exitCodeNote(exitCode)})`
118
+ }
119
+ }
120
+
121
+ // Ran to a natural end. The artifacts and postconditions are the truth —
122
+ // NOT the exit code, which is only reported here, never consulted for the
123
+ // decision. This is where exit-zero-with-no-artifact becomes `incomplete`.
124
+ if (artifactsPresent && postconditionsMet) {
125
+ return {
126
+ status: 'completed',
127
+ reason: `required artifacts present and postconditions met (${exitCodeNote(exitCode)} treated as input only)`
128
+ }
129
+ }
130
+ const missing = !artifactsPresent ? 'a required artifact is missing' : 'a declared postcondition is unmet'
131
+ return {
132
+ status: 'incomplete',
133
+ reason: `${missing} — ${exitCodeNote(exitCode)} does not by itself prove the work is done`
134
+ }
135
+ }