@attalabs/vinaya 0.32.0 → 0.34.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 (218) hide show
  1. package/README.md +1 -1
  2. package/aeg-root/contracts/principal-operator.md +18 -5
  3. package/aeg-root/enforcement.md +1 -1
  4. package/aeg-root/glossary.md +4 -0
  5. package/aeg-root/roles/developer.md +3 -0
  6. package/aeg-root/roles/operator.md +89 -16
  7. package/aeg-root/roles/planner/reference.md +3 -2
  8. package/aeg-root/roles/planner.md +3 -1
  9. package/aeg-root/roles/tranche-archivist.md +1 -0
  10. package/aeg-root/skills/aeg-context-packets/SKILL.md +1 -1
  11. package/aeg-root/skills/aeg-context-packets/examples/operator-start.md +1 -1
  12. package/aeg-root/templates/brief-template.md +9 -7
  13. package/aeg-root/templates/pr-report-template.md +3 -1
  14. package/dist/checks/bin/check-body-bare-digits.js +213 -41
  15. package/dist/checks/bin/check-branch-topology.js +164 -41
  16. package/dist/checks/bin/check-brief-shape.js +219 -46
  17. package/dist/checks/bin/check-changeset-coverage.js +669 -152
  18. package/dist/checks/bin/check-closes-n.js +164 -41
  19. package/dist/checks/bin/check-coherence.js +220 -43
  20. package/dist/checks/bin/check-dead-branch-push.js +159 -40
  21. package/dist/checks/bin/check-dispatch-readiness.js +218 -42
  22. package/dist/checks/bin/check-doc-coverage-push.js +665 -148
  23. package/dist/checks/bin/check-doc-coverage.js +667 -150
  24. package/dist/checks/bin/check-doctrine-no-procedures.js +213 -41
  25. package/dist/checks/bin/check-doctrine-portability.js +666 -149
  26. package/dist/checks/bin/check-evidence-fresh.js +643 -125
  27. package/dist/checks/bin/check-exec-bits.js +663 -146
  28. package/dist/checks/bin/check-first-push-dispatch.js +218 -42
  29. package/dist/checks/bin/check-issue-assignment.js +164 -41
  30. package/dist/checks/bin/check-issue-milestone-attach.js +159 -40
  31. package/dist/checks/bin/check-issue-objectives-numbering.js +685 -41
  32. package/dist/checks/bin/check-issue-parts-coverage.js +159 -40
  33. package/dist/checks/bin/check-issue-surface-globs.js +258 -48
  34. package/dist/checks/bin/check-issue-title-grammar.js +159 -40
  35. package/dist/checks/bin/check-issue-tranche-label.js +159 -40
  36. package/dist/checks/bin/check-main-branch-refusal.js +159 -40
  37. package/dist/checks/bin/check-no-disk-state.js +159 -40
  38. package/dist/checks/bin/check-pr-premise-reassert.js +213 -41
  39. package/dist/checks/bin/check-pr-report-density.js +159 -40
  40. package/dist/checks/bin/check-principal-test-plan-wait.js +159 -40
  41. package/dist/checks/bin/check-quoted-command.js +586 -103
  42. package/dist/checks/bin/check-reader-resolvable-prose.js +637 -111
  43. package/dist/checks/bin/check-registry-gates.js +159 -40
  44. package/dist/checks/bin/check-retired-vocabulary.js +586 -103
  45. package/dist/checks/bin/check-review-gate.js +284 -152
  46. package/dist/checks/bin/check-single-plan-pr.js +159 -40
  47. package/dist/checks/bin/check-surface-scope.js +164 -41
  48. package/dist/checks/bin/check-test-plan.js +159 -40
  49. package/dist/checks/bin/check-token-collection-wired.js +159 -40
  50. package/dist/checks/bin/check-token-report.js +159 -40
  51. package/dist/checks/bin/check-workspace-escape.js +664 -147
  52. package/dist/index.js +3932 -1118
  53. package/dist/lib/pre-push-cache-test-run.js +507 -72
  54. package/dist/lib/pre-push-select-tests.js +136 -13
  55. package/package.json +1 -1
  56. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/actions.ts +10 -12
  57. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/anchored-region.ts +5 -5
  58. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/archive-task.ts +42 -17
  59. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/baseline-capture.ts +1 -2
  60. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/branch-topology-gate.ts +3 -3
  61. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/brief-render.ts +554 -95
  62. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/brief-validation.ts +264 -44
  63. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/claude-code-transcript.ts +9 -9
  64. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/coherence-checks.ts +211 -30
  65. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/consumer-enumeration.ts +2 -2
  66. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/control-store/index.ts +75 -0
  67. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/control-store/local.ts +961 -0
  68. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/control-store/migration.ts +222 -0
  69. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/control-store/outcomes.ts +135 -0
  70. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/control-store/records.ts +394 -0
  71. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dead-branch-push-audit.ts +1 -2
  72. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dead-branch-push-guard.ts +1 -1
  73. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/derive-section7.ts +2 -2
  74. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/assess-round.ts +514 -0
  75. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/fakes.ts +110 -0
  76. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/index.ts +30 -0
  77. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/journal-reconstruction.ts +219 -0
  78. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/render-summary.ts +97 -0
  79. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/types.ts +240 -0
  80. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/diagram-model.ts +1 -1
  81. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/direct-main-push.ts +1 -2
  82. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dispatch-gate.ts +65 -22
  83. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/doc-claim.ts +238 -0
  84. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/doc-owners.ts +14 -1
  85. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/docs/docs-coherence.ts +1 -1
  86. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/docs/legacy-anchors.ts +1 -1
  87. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/docs/node-route.ts +1 -1
  88. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/docs/surfaced-manifest.ts +1 -1
  89. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/doctrine-no-procedures.ts +1 -1
  90. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/doctrine-portability.ts +5 -5
  91. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/ensure-label.ts +1 -1
  92. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/first-push-dispatch-gate.ts +1 -1
  93. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/gate-audience.ts +14 -3
  94. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/index.ts +425 -11
  95. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/issue-assignment.ts +3 -4
  96. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/issue-validation.ts +1450 -33
  97. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/leftover-detection.ts +1 -2
  98. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/local-anchor-coverage.ts +2 -2
  99. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/envelope.ts +119 -0
  100. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/index.ts +75 -0
  101. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/redact.ts +87 -0
  102. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/schema.ts +801 -0
  103. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/store.ts +373 -0
  104. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/main-branch-refusal.ts +2 -2
  105. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/metering-io-guard.ts +1 -1
  106. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/milestone-validation.ts +2 -3
  107. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/no-disk-state.ts +2 -2
  108. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/objectives.ts +288 -0
  109. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/parse-token-report.ts +3 -3
  110. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/parse-tranche.ts +1 -1
  111. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/pr-report-density.ts +30 -16
  112. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/pr-tier.ts +17 -1
  113. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/premise-check.ts +1 -1
  114. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/quoted-command.ts +1 -1
  115. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/reader-resolvable-prose.ts +267 -19
  116. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/registry-checks.ts +91 -24
  117. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/registry-scaffold.ts +6 -6
  118. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/report-tokens.ts +4 -4
  119. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-gate.ts +254 -110
  120. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-input-manifest.ts +384 -0
  121. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-policy.ts +208 -0
  122. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-status.ts +80 -28
  123. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/ruling-ordinal.ts +92 -0
  124. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/single-plan-pr.ts +4 -4
  125. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/state-machine-model.ts +40 -27
  126. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/symbol-collisions.ts +2 -2
  127. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/task-branch-identity.ts +38 -0
  128. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/task-phase-history.ts +194 -0
  129. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/task-tools.ts +712 -0
  130. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/test-plan-gate.ts +7 -9
  131. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/test-plan-section.ts +5 -5
  132. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/types.ts +4 -4
  133. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/verdict-extraction.ts +368 -56
  134. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/waiver-label.ts +2 -3
  135. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/workspace-escape.ts +3 -3
  136. package/studio-standalone/apps/vinaya-studio/web/.next/BUILD_ID +1 -1
  137. package/studio-standalone/apps/vinaya-studio/web/.next/build-manifest.json +3 -3
  138. package/studio-standalone/apps/vinaya-studio/web/.next/prerender-manifest.json +3 -3
  139. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.html +1 -1
  140. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.rsc +1 -1
  141. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
  142. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  143. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  144. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  145. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  146. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page/server-reference-manifest.json +2 -2
  147. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page.js.nft.json +1 -1
  148. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  149. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/api/coherence/route.js +1 -1
  150. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/api/coherence/route.js.nft.json +1 -1
  151. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page/server-reference-manifest.json +2 -2
  152. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page.js.nft.json +1 -1
  153. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page_client-reference-manifest.js +1 -1
  154. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page/server-reference-manifest.json +2 -2
  155. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page.js +1 -1
  156. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page.js.nft.json +1 -1
  157. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page_client-reference-manifest.js +1 -1
  158. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page/server-reference-manifest.json +2 -2
  159. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page.js +1 -1
  160. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page.js.nft.json +1 -1
  161. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page_client-reference-manifest.js +1 -1
  162. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page/server-reference-manifest.json +2 -2
  163. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page.js +1 -1
  164. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page.js.nft.json +1 -1
  165. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page_client-reference-manifest.js +1 -1
  166. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page/server-reference-manifest.json +3 -3
  167. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page.js +2 -2
  168. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page.js.nft.json +1 -1
  169. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page_client-reference-manifest.js +1 -1
  170. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page/server-reference-manifest.json +2 -2
  171. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page.js +1 -1
  172. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page.js.nft.json +1 -1
  173. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page_client-reference-manifest.js +1 -1
  174. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page/server-reference-manifest.json +2 -2
  175. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page.js +1 -1
  176. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page.js.nft.json +1 -1
  177. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page_client-reference-manifest.js +1 -1
  178. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page/server-reference-manifest.json +2 -2
  179. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page.js +1 -1
  180. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page.js.nft.json +1 -1
  181. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page_client-reference-manifest.js +1 -1
  182. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/{[externals]__1agj1ww._.js → [externals]__0cki-x_._.js} +2 -2
  183. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/[root-of-the-server]__02a-3g8._.js +6 -6
  184. 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
  185. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__074w9nf._.js +3 -0
  186. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/{[root-of-the-server]__0r7e54g._.js → [root-of-the-server]__07uhu5z._.js} +1 -1
  187. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__0ls23oh._.js +1 -1
  188. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1gjqmhq._.js +1 -1
  189. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1wc4-ip._.js +1 -1
  190. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/{[root-of-the-server]__1r47dr7._.js → _08onyya._.js} +3 -3
  191. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_096f46i._.js +1 -1
  192. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0af2one._.js +1 -1
  193. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0e5tkdd._.js +1 -1
  194. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0kf2g72._.js +1 -1
  195. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0y1jv16._.js +1 -1
  196. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0zf4d27._.js +1 -1
  197. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_1-wo68i._.js +1 -1
  198. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_15gdg48._.js +5 -5
  199. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_1achbh9._.js +1 -1
  200. 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
  201. package/studio-standalone/apps/vinaya-studio/web/.next/server/middleware-build-manifest.js +3 -3
  202. package/studio-standalone/apps/vinaya-studio/web/.next/server/pages/500.html +1 -1
  203. package/studio-standalone/apps/vinaya-studio/web/.next/server/server-reference-manifest.js +1 -1
  204. package/studio-standalone/apps/vinaya-studio/web/.next/server/server-reference-manifest.json +4 -4
  205. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/0bjnj-5fy4e7l.js +1 -0
  206. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/0ko698wh8xx2g.css +1 -0
  207. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{1dc2_-c_gavj1.js → 0q9p7c6vn-x2w.js} +4 -4
  208. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{3xg6-flovrcx-.js → 2174nz5he_oc4.js} +1 -1
  209. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/3xnma0-359j17.js +1 -0
  210. package/studio-standalone/apps/vinaya-studio/web/package.json +2 -2
  211. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__0hstap0._.js +0 -3
  212. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/0bm4nrrzwc7zi.css +0 -1
  213. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/2t_rfsztmwu6y.js +0 -1
  214. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/3ua4rm5f-a9k6.js +0 -1
  215. /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/vinaya/studio-standalone/_node_modules/@attalabs/aeg-core}/bin/verify-coherence.ts +0 -0
  216. /package/studio-standalone/apps/vinaya-studio/web/.next/static/{e8XbZ2vlVz40KzHmlqhwP → HmoeqXdX1E4drt7GReFOO}/_buildManifest.js +0 -0
  217. /package/studio-standalone/apps/vinaya-studio/web/.next/static/{e8XbZ2vlVz40KzHmlqhwP → HmoeqXdX1E4drt7GReFOO}/_clientMiddlewareManifest.js +0 -0
  218. /package/studio-standalone/apps/vinaya-studio/web/.next/static/{e8XbZ2vlVz40KzHmlqhwP → HmoeqXdX1E4drt7GReFOO}/_ssgManifest.js +0 -0
@@ -0,0 +1,801 @@
1
+ /**
2
+ * The Vinaya Log's typed event schema (Linear "Tech spec — The Vinaya Log").
3
+ * This module versions the envelope to `schema: 2` and widens `kind` past
4
+ * the first three families it originally shipped with.
5
+ *
6
+ * Three families shipped first — `dispatch`, `dev_review_loop`, and
7
+ * `forge_write`. This task adds six more — `gate`, `operation`,
8
+ * `usage`, `role_attempt`, `handoff`, `effect` — and extends the
9
+ * `dispatch` family's `verdict` outcome with severity-scale/policy-
10
+ * treatment/confidence fields on each finding (O3). `kind` remains a
11
+ * closed union; `command`/`tokens` stay out of scope (`command` folds into
12
+ * `operation` above, `tokens` into `usage`).
13
+ *
14
+ * `meta.schema` is now a discriminated union: `1` (unchanged from before
15
+ * this task — every field it ever had, still required, still meaning the
16
+ * same thing) or `2` (adds `event_id`, `process_id`, `lineage`,
17
+ * `input_versions`, `provenance` — O1's "task/run/attempt/parent lineage,
18
+ * producer sequence, opaque role and process identifiers, input versions
19
+ * and trust provenance"). `buildHeader` (`envelope.ts`) builds `2` for
20
+ * every event from this task forward; `1` exists so a line already on disk
21
+ * (or a fixture recorded before this task) keeps parsing, never a schema
22
+ * violation just because it predates these fields (O1's "compatible").
23
+ * Absent per-field data on a `2` header is `null`, never invented — the
24
+ * lineage/input-version identities declared here are a real producer's job
25
+ * to fill in later; this module ships the typed slot, honestly empty until
26
+ * then.
27
+ *
28
+ * `subject.role` keeps its EXISTING closed-`Role`-or-`'unattributed'`
29
+ * meaning unchanged — it is relied on outside this module (`dispatch.ts`,
30
+ * `commands/dispatch.ts`'s argv validation) and this task does not touch
31
+ * it. The new `meta.actor_id` (v2 only) is the opaque, unvalidated
32
+ * identifier O1 asks for: whatever the environment claims, never checked
33
+ * against `ROLE_VALUES` — the two are deliberately different fields with
34
+ * different trust levels, not a replacement of one by the other.
35
+ *
36
+ * One deviation from the spec, decided in a prior task's brief: the spec's
37
+ * `subject.objectives_version` is `number`; the built form
38
+ * hashes it to a `sha256` hex
39
+ * string, so this schema types it `string`, superseding the spec.
40
+ *
41
+ * Every object here is `.strict()` — an extra key anywhere (including
42
+ * inside `payload`) is a schema violation, not a tolerated passthrough.
43
+ */
44
+
45
+ import { z } from 'zod'
46
+
47
+ /**
48
+ * The one bound shared by `gate_result_read.confidence_reason` below and the
49
+ * parser that captures it (`parseConfidenceReply`,
50
+ * `apps/cli/src/lib/dev-review-loop/round-assess.ts`) — exported so the
51
+ * capture side can truncate to the exact same length rather than only
52
+ * bounding it here: a reason captured longer than this would fail this
53
+ * schema at write time and drop the whole event, round/head/green included.
54
+ */
55
+ export const CONFIDENCE_REASON_MAX_LENGTH = 280
56
+
57
+ /** Every dispatchable doctrine role, spelled exactly as the spec's Role union (§5.1) — the doctrine-facing name (`code-reviewer`), not the `reviewer.md` filename `resolveDoctrineRootInfo` resolves it to. */
58
+ export const ROLE_VALUES = [
59
+ 'planner',
60
+ 'developer',
61
+ 'code-reviewer',
62
+ 'security',
63
+ 'principal',
64
+ 'archivist',
65
+ 'architect'
66
+ ] as const
67
+
68
+ export const RoleSchema = z.enum(ROLE_VALUES)
69
+ export type Role = z.infer<typeof RoleSchema>
70
+
71
+ export const HOST_VALUES = ['hook', 'ci', 'cli', 'loop'] as const
72
+ export const HostSchema = z.enum(HOST_VALUES)
73
+ export type Host = z.infer<typeof HostSchema>
74
+
75
+ /**
76
+ * Letters, digits, dot, underscore, hyphen — deliberately excludes `<`, `>`,
77
+ * `/`, whitespace and newlines. `run_id` is spliced raw into a flush's
78
+ * `<!-- aeg:log:<run_id>:<seq_from>-<seq_to> -->` marker (`apps/cli/specs/log.md`
79
+ * § The flush) and is attacker-reachable via `VINAYA_RUN_ID` (a security
80
+ * review finding) — a value carrying `-->` or a newline would close the
81
+ * HTML comment early or break the fenced block once posted publicly.
82
+ * Refusing it here, at write time, means an unsafe value never reaches the
83
+ * outbox at all, rather than relying on a later reader to catch it.
84
+ */
85
+ const RUN_ID_PATTERN = /^[A-Za-z0-9_.-]{1,128}$/
86
+
87
+ const headerMetaCore = {
88
+ ts: z.string(),
89
+ run_id: z.string().regex(RUN_ID_PATTERN),
90
+ seq: z.number().int().nonnegative(),
91
+ repo: z.string().nullable(),
92
+ vinaya: z.string(),
93
+ doctrine: z.string(),
94
+ host: HostSchema,
95
+ machine: z.string()
96
+ }
97
+
98
+ const HeaderMetaV1Schema = z
99
+ .object({
100
+ schema: z.literal(1),
101
+ ...headerMetaCore
102
+ })
103
+ .strict()
104
+
105
+ /** Task/run/attempt/parent lineage (O1). Each identity is `null` until a real producer fills it in — declared here, enforced by a later producer. `task` is not repeated here — `subject.issue` already carries it. */
106
+ const LineageSchema = z
107
+ .object({
108
+ run: z.string().nullable(),
109
+ attempt: z.number().int().nullable(),
110
+ parent: z.string().nullable()
111
+ })
112
+ .strict()
113
+
114
+ /** Mirrors `review-input-manifest.ts`'s own field set (`briefHash`, `objectivesVersion`, `rulingOrdinal`, `policyDigest`) — the "input versions" O1 asks the envelope to carry, snake_cased to match every other envelope field. Independent of `subject.objectives_version` (kept, unchanged, for backward compatibility); a producer may set either, both, or neither. */
115
+ const InputVersionsSchema = z
116
+ .object({
117
+ objectives_version: z.string().nullable(),
118
+ brief_hash: z.string().nullable(),
119
+ ruling_ordinal: z.number().int().nullable(),
120
+ policy_digest: z.string().nullable()
121
+ })
122
+ .strict()
123
+
124
+ /**
125
+ * Trust ordering the spec names explicitly: parent-generated dispatch/effect
126
+ * attribution is stronger than worker-controlled environment correlation;
127
+ * self-reported "Cast by" text or shared-credential authorship proves no
128
+ * authorization. `'unavailable'` is the honest default — `buildHeader` is a
129
+ * pure function with no way to confirm WHO set an environment variable, so
130
+ * it never upgrades itself to `'parent_attributed'` on its own; a future
131
+ * caller that structurally knows it just spawned this exact child
132
+ * (`dispatch.ts`) is the one place that could honestly assert it.
133
+ */
134
+ const ProvenanceSchema = z.enum(['parent_attributed', 'env_correlated', 'self_reported', 'unavailable'])
135
+
136
+ const HeaderMetaV2Schema = z
137
+ .object({
138
+ schema: z.literal(2),
139
+ ...headerMetaCore,
140
+ event_id: z.string().min(1),
141
+ process_id: z.string().min(1),
142
+ actor_id: z.string().nullable(),
143
+ lineage: LineageSchema,
144
+ input_versions: InputVersionsSchema,
145
+ provenance: ProvenanceSchema
146
+ })
147
+ .strict()
148
+
149
+ const HeaderMetaSchema = z.discriminatedUnion('schema', [HeaderMetaV1Schema, HeaderMetaV2Schema])
150
+ export { HeaderMetaV1Schema, HeaderMetaV2Schema, LineageSchema, InputVersionsSchema, ProvenanceSchema }
151
+ export type HeaderMetaV1 = z.infer<typeof HeaderMetaV1Schema>
152
+ export type HeaderMetaV2 = z.infer<typeof HeaderMetaV2Schema>
153
+ export type Lineage = z.infer<typeof LineageSchema>
154
+ export type InputVersions = z.infer<typeof InputVersionsSchema>
155
+ export type Provenance = z.infer<typeof ProvenanceSchema>
156
+
157
+ const SubjectSchema = z
158
+ .object({
159
+ issue: z.number().int().nullable(),
160
+ pr: z.number().int().optional(),
161
+ sha: z.string().optional(),
162
+ role: z.union([RoleSchema, z.literal('unattributed')]),
163
+ round: z.number().int().optional(),
164
+ // Deviation from spec (see module doc): string, not number.
165
+ objectives_version: z.string().optional()
166
+ })
167
+ .strict()
168
+
169
+ /** `buildHeader`'s return shape — the two envelope fields it fills, not the whole log line. */
170
+ export const HeaderSchema = z
171
+ .object({
172
+ meta: HeaderMetaSchema,
173
+ subject: SubjectSchema
174
+ })
175
+ .strict()
176
+ export type Header = z.infer<typeof HeaderSchema>
177
+ export type Subject = z.infer<typeof SubjectSchema>
178
+
179
+ /** Every family's shared envelope tail: present on every event, alongside `meta`/`subject`/`kind`/`event`. */
180
+ const envelopeTail = {
181
+ duration_ms: z.number().nonnegative().optional(),
182
+ // The generic body §5.1 reserves for families that need one; `dispatch`
183
+ // and `dev_review_loop` carry their real content in named fields instead,
184
+ // so it ships empty — `.strict()` still refuses a smuggled key in it.
185
+ payload: z.object({}).strict()
186
+ }
187
+
188
+ // ---------------------------------------------------------------------------
189
+ // Review finding metadata (O3) — `id` is this finding's identity AS
190
+ // REPORTED in one round's comment; it is stable within that comment only.
191
+ // A reviewer's own positional numbering (`F1`, `F2`, …) is NOT advertised
192
+ // as stable across rounds by this schema — a caller comparing findings
193
+ // across rounds needs its own reconciliation, never an assumption that the
194
+ // same `id` string names the same finding two rounds apart (Traps to
195
+ // avoid). `severity` is the value as reported — its meaning depends on
196
+ // `severity_scale` (deliberately a free string, not a closed enum: this
197
+ // doctrine already has two different scales, code-review's and security's,
198
+ // and a third reviewer type should never require a schema change to name
199
+ // its own). `policy_treatment` is a SEPARATE fact from `severity` — the
200
+ // same reported severity can bind or not bind a verdict depending on the
201
+ // effective review policy's threshold at review time; conflating the two
202
+ // is exactly what left "review reconstruction lacks severity and
203
+ // confidence data" (this task's own Boundary). `confidence` is optional,
204
+ // self-reported, and never treated as calibrated correctness — capturing
205
+ // it is not the same as trusting it.
206
+ const ReviewFindingSchema = z
207
+ .object({
208
+ id: z.string(),
209
+ severity: z.string(),
210
+ state: z.string().optional(),
211
+ severity_scale: z.string().optional(),
212
+ policy_treatment: z.enum(['blocking', 'non_blocking', 'unavailable']).optional(),
213
+ confidence: z.number().min(0).max(1).optional(),
214
+ confidence_scale: z.string().optional(),
215
+ confidence_source: z.string().optional()
216
+ })
217
+ .strict()
218
+ export type ReviewFinding = z.infer<typeof ReviewFindingSchema>
219
+
220
+ // ---------------------------------------------------------------------------
221
+ // `dispatch` family (§5.2)
222
+
223
+ const DispatchOutcomeSchema = z.discriminatedUnion('type', [
224
+ z.object({ type: z.literal('pr_opened'), pr: z.number().int(), head: z.string() }).strict(),
225
+ z
226
+ .object({
227
+ type: z.literal('round_pushed'),
228
+ pr: z.number().int(),
229
+ head: z.string(),
230
+ comment_id: z.number().int()
231
+ })
232
+ .strict(),
233
+ z
234
+ .object({
235
+ type: z.literal('verdict'),
236
+ verdict: z.enum(['APPROVE', 'REQUEST CHANGES', 'PASS', 'FAIL']),
237
+ head: z.string(),
238
+ comment_id: z.number().int(),
239
+ objectives: z.array(z.object({ id: z.string(), met: z.boolean() }).strict()),
240
+ findings: z.array(ReviewFindingSchema)
241
+ })
242
+ .strict(),
243
+ z
244
+ .object({
245
+ type: z.literal('escalation'),
246
+ class: z.enum(['authority', 'strategy', 'product']),
247
+ comment_id: z.number().int()
248
+ })
249
+ .strict(),
250
+ z.object({ type: z.literal('brief'), comment_id: z.number().int(), hash: z.string() }).strict(),
251
+ z.object({ type: z.literal('plan'), issues: z.array(z.number().int()) }).strict(),
252
+ z.object({ type: z.literal('archive'), provenance_comment_id: z.number().int() }).strict(),
253
+ // The generic "the process exited cleanly with no
254
+ // specific, identifiable forge outcome" member the module doc of
255
+ // `apps/cli/src/lib/dispatch.ts` used to name as missing — no
256
+ // role/action-specific identifier is fabricated; a successful dispatch
257
+ // that produced no PR, comment, or archive fact reports this instead of a
258
+ // placeholder borrowed from an unrelated variant.
259
+ z.object({ type: z.literal('completed') }).strict()
260
+ ])
261
+ export type DispatchOutcome = z.infer<typeof DispatchOutcomeSchema>
262
+
263
+ /** `target_role`/`model`/`round?`/`effect_id` are shared across every `dispatch` event (§5.2). */
264
+ const dispatchShared = {
265
+ meta: HeaderMetaSchema,
266
+ subject: SubjectSchema,
267
+ kind: z.literal('dispatch'),
268
+ ...envelopeTail,
269
+ target_role: RoleSchema,
270
+ model: z.string(),
271
+ round: z.number().int().optional(),
272
+ effect_id: z.string()
273
+ }
274
+
275
+ /** Shared by `outcome_received` and `dispatch_failed` — a run's token record survives the manner of its death, so the same nullable shape applies whether the run exited cleanly or was killed. */
276
+ const dispatchUsageField = z
277
+ .object({ input: z.number().nonnegative(), output: z.number().nonnegative() })
278
+ .strict()
279
+ .nullable()
280
+
281
+ export const DispatchEventSchema = z.discriminatedUnion('event', [
282
+ z.object({ ...dispatchShared, event: z.literal('dispatched'), prompt_hash: z.string() }).strict(),
283
+ z
284
+ .object({
285
+ ...dispatchShared,
286
+ event: z.literal('outcome_received'),
287
+ outcome: DispatchOutcomeSchema,
288
+ usage: dispatchUsageField
289
+ })
290
+ .strict(),
291
+ z
292
+ .object({
293
+ ...dispatchShared,
294
+ event: z.literal('dispatch_failed'),
295
+ reason: z.enum(['timeout', 'crash', 'refused', 'unattributed_write']),
296
+ usage: dispatchUsageField
297
+ })
298
+ .strict()
299
+ ])
300
+ export type DispatchEvent = z.infer<typeof DispatchEventSchema>
301
+
302
+ // ---------------------------------------------------------------------------
303
+ // `dev_review_loop` family (§5.2) — twelve events (a later addition added
304
+ // `cancelled`), `loop_id` shared on each.
305
+
306
+ const loopShared = {
307
+ meta: HeaderMetaSchema,
308
+ subject: SubjectSchema,
309
+ kind: z.literal('dev_review_loop'),
310
+ ...envelopeTail,
311
+ loop_id: z.string()
312
+ }
313
+
314
+ export const DevReviewLoopEventSchema = z.discriminatedUnion('event', [
315
+ z
316
+ .object({
317
+ ...loopShared,
318
+ event: z.literal('loop_started'),
319
+ task: z.number().int(),
320
+ policy: z
321
+ .object({
322
+ max_rounds: z.number().int().nonnegative(),
323
+ reviewers: z.array(RoleSchema),
324
+ models: z.record(RoleSchema, z.string())
325
+ })
326
+ .strict()
327
+ })
328
+ .strict(),
329
+ z
330
+ .object({ ...loopShared, event: z.literal('round_started'), round: z.number().int(), base_head: z.string() })
331
+ .strict(),
332
+ z
333
+ .object({
334
+ ...loopShared,
335
+ event: z.literal('gate_result_read'),
336
+ round: z.number().int(),
337
+ head: z.string(),
338
+ green: z.boolean(),
339
+ // The developer's stated confidence — read from round 2 on, on a
340
+ // green gate only; round 1 and a red gate set none of the four fields
341
+ // below. `confidence_value`/`confidence_reason` are the whole-number
342
+ // value and one-line reason as stated at the read; `confidence_unavailable:
343
+ // true` records a missing or malformed statement explicitly — never a
344
+ // fabricated `confidence_value` of 0. `extra_turn_spent` tells a first
345
+ // statement apart from one made after the confidence rule's one extra
346
+ // developer turn. All four optional, so a `gate_result_read` line
347
+ // logged before this field set existed still parses.
348
+ confidence_value: z.number().int().min(0).max(100).optional(),
349
+ confidence_reason: z.string().max(CONFIDENCE_REASON_MAX_LENGTH).optional(),
350
+ confidence_unavailable: z.boolean().optional(),
351
+ extra_turn_spent: z.boolean().optional()
352
+ })
353
+ .strict(),
354
+ z
355
+ .object({
356
+ ...loopShared,
357
+ event: z.literal('verdicts_read'),
358
+ round: z.number().int(),
359
+ head: z.string(),
360
+ all_approve: z.boolean(),
361
+ blockers: z.number().int().nonnegative(),
362
+ // Every finding from every verdict this round
363
+ // read, carrying its own severity_scale/policy_treatment/confidence —
364
+ // the full per-review metadata `blockers` alone could never retain
365
+ // (see `journal-reconstruction.ts`'s own doc on this gap). `blockers`
366
+ // stays, unchanged, as the cheap coarse count every existing reader
367
+ // already trusts. Optional, not required: a real `verdicts_read` line
368
+ // logged before this task carries no such field at all, and
369
+ // `log/compat.test.ts` proves that a line logged before this field existed still parses
370
+ // — a schema change is additive here, never a reason an old line on
371
+ // disk starts reading as corrupt. This task's own producer
372
+ // (`assess-round.ts`) always sets it explicitly, `[]` included.
373
+ findings: z.array(ReviewFindingSchema).optional()
374
+ })
375
+ .strict(),
376
+ z
377
+ .object({
378
+ ...loopShared,
379
+ event: z.literal('findings_compared'),
380
+ round: z.number().int(),
381
+ open: z.array(z.string()),
382
+ resolved: z.array(z.string()),
383
+ new: z.array(z.string()),
384
+ recurring: z.array(z.string())
385
+ })
386
+ .strict(),
387
+ z
388
+ .object({
389
+ ...loopShared,
390
+ event: z.literal('stop_condition_met'),
391
+ round: z.number().int(),
392
+ // `confidence` and `reappearance` widen this enum additively
393
+ // (a 2026-09-06 amendment): a
394
+ // confidence collapse and a finding-id reappearance are each their own
395
+ // condition, distinguished from the generic `no_progress` stall and
396
+ // from each other, rather than collapsing all three into one value.
397
+ condition: z.enum([
398
+ 'green',
399
+ 'max_rounds',
400
+ 'no_progress',
401
+ 'escalated',
402
+ 'principal_stop',
403
+ 'confidence',
404
+ 'reappearance'
405
+ ])
406
+ })
407
+ .strict(),
408
+ z
409
+ .object({
410
+ ...loopShared,
411
+ event: z.literal('paused'),
412
+ round: z.number().int(),
413
+ reason: z.enum(['escalation', 'principal_item', 'refreeze_needed'])
414
+ })
415
+ .strict(),
416
+ z
417
+ .object({
418
+ ...loopShared,
419
+ event: z.literal('resumed'),
420
+ round: z.number().int(),
421
+ // `'principal'` — an authenticated ruling resolved the pause.
422
+ // `'driver'` (O2) — a bare `'infrastructure'`
423
+ // recoverable-hiccup resume, authenticated as the driver's own
424
+ // recovery rather than a Principal decision (`resolveEscalation`'s
425
+ // `authenticatedBy: 'driver-self'` path, `dev-review-loop.ts`) — never
426
+ // silently reported as `'principal'` when no ruling was ever read.
427
+ by: z.enum(['principal', 'driver'])
428
+ })
429
+ .strict(),
430
+ // (O2) The cancellation twin of `resumed` above — a
431
+ // paused escalation's OTHER resolution (`resolveEscalation`'s
432
+ // `decision: 'cancel'` path, `cancelDevReviewLoop`). Always
433
+ // principal-authenticated (a cancel always requires a posted ruling,
434
+ // unlike an infrastructure resume) — no `'driver'` member here.
435
+ z
436
+ .object({
437
+ ...loopShared,
438
+ event: z.literal('cancelled'),
439
+ round: z.number().int(),
440
+ by: z.literal('principal')
441
+ })
442
+ .strict(),
443
+ // A round-2 review MAJOR finding: the
444
+ // driver's own mid-round resume of a developer who stopped without
445
+ // pushing — distinct from `resumed` above, which is `by: 'principal'`
446
+ // only (a Principal resuming a PAUSED loop). This is the driver acting on
447
+ // its own, still inside the same round, never a pause/resume pair: the
448
+ // round simply continues once the developer's next turn produces a new
449
+ // head. Named `unpushed_work_resume` per the objective's own wording so a
450
+ // Principal reading the journal can tell "stopped after real, uncommitted
451
+ // or unpushed work" apart from every other mid-round event.
452
+ z
453
+ .object({
454
+ ...loopShared,
455
+ event: z.literal('unpushed_work_resume'),
456
+ round: z.number().int(),
457
+ branch: z.string(),
458
+ detail: z.string()
459
+ })
460
+ .strict(),
461
+ z
462
+ .object({
463
+ ...loopShared,
464
+ event: z.literal('round_ended'),
465
+ round: z.number().int(),
466
+ base_head: z.string(),
467
+ head: z.string(),
468
+ files_changed: z.number().int().nonnegative(),
469
+ insertions: z.number().int().nonnegative(),
470
+ deletions: z.number().int().nonnegative(),
471
+ wall_ms: z.number().nonnegative(),
472
+ outcome: z.enum(['green', 'changes_requested', 'escalated'])
473
+ })
474
+ .strict(),
475
+ z
476
+ .object({
477
+ ...loopShared,
478
+ event: z.literal('journal_finalized'),
479
+ rounds: z.number().int().nonnegative(),
480
+ total_wall_ms: z.number().nonnegative(),
481
+ time_to_green_ms: z.number().nonnegative().nullable(),
482
+ files_changed_total: z.number().int().nonnegative(),
483
+ final_head: z.string(),
484
+ result: z.enum(['merged_ready', 'stopped'])
485
+ })
486
+ .strict(),
487
+ // (O3) A retry episode around one of the
488
+ // driver's own infrastructure-class hiccups — a pause/escalation comment
489
+ // post that failed at least once (O1), or a developer dispatch that ended
490
+ // on the launcher's own `'connection-failed'` classification (O2) — named
491
+ // by `kind`, so a run that survived a network drop can be told apart from
492
+ // one that did not. A NEW event, additive to the family: a pre-change
493
+ // line carries none of these, and parses exactly as it always did (no
494
+ // existing event's own required fields changed). Logged ONCE per episode,
495
+ // after the last attempt concludes — `'recovered'` when a later attempt
496
+ // eventually succeeded (whether or not a pause is ever reached: O2's own
497
+ // re-dispatch often lets the round continue to publish with no pause at
498
+ // all), `'exhausted'` once the shared `MAX_INFRASTRUCTURE_RETRIES` bound
499
+ // is reached with no success — never one line per attempt, which would
500
+ // make `attempts` redundant with the line count itself.
501
+ z
502
+ .object({
503
+ ...loopShared,
504
+ event: z.literal('infrastructure_retry'),
505
+ round: z.number().int(),
506
+ // Named `failure_kind`, never bare `kind` — `loopShared` already
507
+ // fixes THIS object's own `kind` at the literal `'dev_review_loop'`
508
+ // (the family discriminator every `LogEventSchema` union member
509
+ // carries); a second `kind` field here would silently shadow it.
510
+ failure_kind: z.enum(['pause_comment_post', 'developer_connection']),
511
+ attempts: z.number().int().positive(),
512
+ outcome: z.enum(['recovered', 'exhausted'])
513
+ })
514
+ .strict()
515
+ ])
516
+ export type DevReviewLoopEvent = z.infer<typeof DevReviewLoopEventSchema>
517
+
518
+ // ---------------------------------------------------------------------------
519
+ // `forge_write` family — every op `vinaya log flush` (and future forge-write
520
+ // call sites) can perform, spelled exactly as the Issue lists them.
521
+
522
+ export const ForgeOpSchema = z.enum([
523
+ 'pr.create',
524
+ 'pr.comment',
525
+ 'pr.body.replace',
526
+ 'pr.refreeze',
527
+ 'issue.create',
528
+ 'issue.edit',
529
+ 'issue.comment',
530
+ 'milestone.create',
531
+ 'milestone.edit',
532
+ 'milestone.close',
533
+ 'label.add',
534
+ 'label.remove'
535
+ ])
536
+ export type ForgeOp = z.infer<typeof ForgeOpSchema>
537
+
538
+ const ForgeWriteTargetSchema = z
539
+ .object({
540
+ issue: z.number().int().optional(),
541
+ pr: z.number().int().optional()
542
+ })
543
+ .strict()
544
+
545
+ const forgeWriteShared = {
546
+ meta: HeaderMetaSchema,
547
+ subject: SubjectSchema,
548
+ kind: z.literal('forge_write'),
549
+ ...envelopeTail,
550
+ op: ForgeOpSchema,
551
+ target: ForgeWriteTargetSchema
552
+ }
553
+
554
+ export const ForgeWriteEventSchema = z.discriminatedUnion('event', [
555
+ z.object({ ...forgeWriteShared, event: z.literal('validated') }).strict(),
556
+ z.object({ ...forgeWriteShared, event: z.literal('refused'), reason: z.string() }).strict(),
557
+ z.object({ ...forgeWriteShared, event: z.literal('written'), comment_ids: z.array(z.string()) }).strict()
558
+ ])
559
+ export type ForgeWriteEvent = z.infer<typeof ForgeWriteEventSchema>
560
+
561
+ // ---------------------------------------------------------------------------
562
+ // `gate` family (O2) — one gate runner's attempted check. `loop` (the
563
+ // spec's "loop coordinator") is already typed by `dev_review_loop` above;
564
+ // this task does not introduce a second loop schema for it.
565
+
566
+ export const GateOutcomeSchema = z.enum([
567
+ 'pass',
568
+ 'fail',
569
+ 'wait',
570
+ 'skip',
571
+ 'invalid_input',
572
+ 'unavailable_dependency',
573
+ 'timeout',
574
+ 'cancelled'
575
+ ])
576
+ export type GateOutcome = z.infer<typeof GateOutcomeSchema>
577
+
578
+ const gateShared = {
579
+ meta: HeaderMetaSchema,
580
+ subject: SubjectSchema,
581
+ kind: z.literal('gate'),
582
+ ...envelopeTail,
583
+ check: z.string(),
584
+ check_version: z.string().nullable(),
585
+ policy_version: z.string().nullable(),
586
+ input_fingerprint: z.string().nullable()
587
+ }
588
+
589
+ export const GateEventSchema = z.discriminatedUnion('event', [
590
+ z
591
+ .object({
592
+ ...gateShared,
593
+ event: z.literal('checked'),
594
+ outcome: GateOutcomeSchema,
595
+ reason: z.string().optional()
596
+ })
597
+ .strict()
598
+ ])
599
+ export type GateEvent = z.infer<typeof GateEventSchema>
600
+
601
+ // ---------------------------------------------------------------------------
602
+ // `operation` family (O2) — the spec's "command dispatcher": a normalized
603
+ // operation/tool call, result and duration, never raw secret-bearing
604
+ // arguments (`redact()` still runs over the full event regardless).
605
+
606
+ export const OperationResultSchema = z.enum(['ok', 'error', 'refused', 'timeout', 'cancelled', 'unavailable'])
607
+ export type OperationResult = z.infer<typeof OperationResultSchema>
608
+
609
+ const operationShared = {
610
+ meta: HeaderMetaSchema,
611
+ subject: SubjectSchema,
612
+ kind: z.literal('operation'),
613
+ ...envelopeTail,
614
+ operation: z.string(),
615
+ target: z.string().nullable()
616
+ }
617
+
618
+ export const OperationEventSchema = z.discriminatedUnion('event', [
619
+ z
620
+ .object({
621
+ ...operationShared,
622
+ event: z.literal('completed'),
623
+ result: OperationResultSchema,
624
+ error_class: z.string().nullable()
625
+ })
626
+ .strict()
627
+ ])
628
+ export type OperationEvent = z.infer<typeof OperationEventSchema>
629
+
630
+ // ---------------------------------------------------------------------------
631
+ // `usage` family (O2) — the spec's "usage collector". Every unit is
632
+ // `nullable`, never defaulted to `0` — "unknown usage treated as zero" is
633
+ // the exact bug the spec calls out to fix; a producer with nothing observed
634
+ // reports `null` and, when it knows why, `unknown_reason`.
635
+
636
+ const UsageUnitsSchema = z
637
+ .object({
638
+ input: z.number().nonnegative().nullable(),
639
+ output: z.number().nonnegative().nullable(),
640
+ cache: z.number().nonnegative().nullable()
641
+ })
642
+ .strict()
643
+ export type UsageUnits = z.infer<typeof UsageUnitsSchema>
644
+
645
+ const usageShared = {
646
+ meta: HeaderMetaSchema,
647
+ subject: SubjectSchema,
648
+ kind: z.literal('usage'),
649
+ ...envelopeTail,
650
+ model: z.string().nullable(),
651
+ source: z.string(),
652
+ semantics: z.enum(['cumulative', 'delta'])
653
+ }
654
+
655
+ export const UsageEventSchema = z.discriminatedUnion('event', [
656
+ z
657
+ .object({
658
+ ...usageShared,
659
+ event: z.literal('observed'),
660
+ units: UsageUnitsSchema,
661
+ unknown_reason: z.string().nullable()
662
+ })
663
+ .strict()
664
+ ])
665
+ export type UsageEvent = z.infer<typeof UsageEventSchema>
666
+
667
+ // ---------------------------------------------------------------------------
668
+ // `role_attempt` family (O2) — the spec's "role executor": a role
669
+ // ATTEMPT's own normalized outcome, distinct from the `dispatch` family's
670
+ // parent-side view of dispatching one. `actor` is deliberately an opaque
671
+ // string, never `RoleSchema` — this family, and the events it describes,
672
+ // are not limited to the closed doctrine `Role` union (this task's own
673
+ // title). Named `role_attempt`, not `role`, so it never collides with the
674
+ // existing `Role`/`RoleSchema` export from this same module.
675
+
676
+ export const RoleAttemptOutcomeSchema = z.enum([
677
+ 'completed',
678
+ 'incomplete',
679
+ 'infrastructure_failed',
680
+ 'cancelled',
681
+ 'timed_out',
682
+ 'capability_refused'
683
+ ])
684
+ export type RoleAttemptOutcome = z.infer<typeof RoleAttemptOutcomeSchema>
685
+
686
+ const roleAttemptShared = {
687
+ meta: HeaderMetaSchema,
688
+ subject: SubjectSchema,
689
+ kind: z.literal('role_attempt'),
690
+ ...envelopeTail,
691
+ actor: z.string().nullable(),
692
+ attempt: z.number().int().nullable(),
693
+ // `effect_id` mirrors the `dispatch` family's own
694
+ // field, the same value, so one attempt's `role_attempt` line and its
695
+ // `dispatch` lines are the evidence identity a reader joins on. `model` is
696
+ // the runtime's own genuine receipt when the vendor gave one, else the
697
+ // pre-completion request label — same precedence `dispatch.ts` already
698
+ // applies to the `dispatch` family's own `model` field, never guessed here
699
+ // a second way.
700
+ effect_id: z.string(),
701
+ model: z.string().nullable()
702
+ }
703
+
704
+ export const RoleAttemptEventSchema = z.discriminatedUnion('event', [
705
+ z
706
+ .object({
707
+ ...roleAttemptShared,
708
+ event: z.literal('attempted'),
709
+ outcome: RoleAttemptOutcomeSchema,
710
+ usage: dispatchUsageField
711
+ })
712
+ .strict()
713
+ ])
714
+ export type RoleAttemptEvent = z.infer<typeof RoleAttemptEventSchema>
715
+
716
+ // ---------------------------------------------------------------------------
717
+ // `handoff` family (O2) — a human handoff/escalation, raised and later
718
+ // resolved. `class` reuses the same three-value severity the `dispatch`
719
+ // family's `escalation` outcome already carries (`authority` / `strategy` /
720
+ // `product`) rather than inventing a second name for the identical concept.
721
+
722
+ const handoffShared = {
723
+ meta: HeaderMetaSchema,
724
+ subject: SubjectSchema,
725
+ kind: z.literal('handoff'),
726
+ ...envelopeTail,
727
+ class: z.enum(['authority', 'strategy', 'product']),
728
+ reason: z.string()
729
+ }
730
+
731
+ export const HandoffEventSchema = z.discriminatedUnion('event', [
732
+ z
733
+ .object({
734
+ ...handoffShared,
735
+ event: z.literal('raised'),
736
+ requested_decision: z.string().nullable()
737
+ })
738
+ .strict(),
739
+ z
740
+ .object({
741
+ ...handoffShared,
742
+ event: z.literal('resolved'),
743
+ resolution: z.string().nullable(),
744
+ resolved_by: z.string().nullable()
745
+ })
746
+ .strict()
747
+ ])
748
+ export type HandoffEvent = z.infer<typeof HandoffEventSchema>
749
+
750
+ // ---------------------------------------------------------------------------
751
+ // `effect` family (O2) — the spec's "shared effect executor": a generic
752
+ // external effect's attempted/observed/verified outcome, including failure
753
+ // and uncertainty. This is additive to, and does not replace, the existing
754
+ // `forge_write` family, which stays exactly as it was — a forge write is
755
+ // one specific effect this schema does not yet generalize `forge_write`
756
+ // into; "telemetry never substitutes for required intent" (the spec's own
757
+ // words) is why this is fail-open observation, not a fail-closed control
758
+ // store.
759
+
760
+ const EffectTargetSchema = z
761
+ .object({
762
+ kind: z.string(),
763
+ ref: z.string()
764
+ })
765
+ .strict()
766
+
767
+ const effectShared = {
768
+ meta: HeaderMetaSchema,
769
+ subject: SubjectSchema,
770
+ kind: z.literal('effect'),
771
+ ...envelopeTail,
772
+ effect_id: z.string(),
773
+ target: EffectTargetSchema
774
+ }
775
+
776
+ export const EffectEventSchema = z.discriminatedUnion('event', [
777
+ z.object({ ...effectShared, event: z.literal('attempted') }).strict(),
778
+ z
779
+ .object({ ...effectShared, event: z.literal('observed'), outcome: z.enum(['success', 'failure', 'uncertain']) })
780
+ .strict(),
781
+ z
782
+ .object({ ...effectShared, event: z.literal('verified'), outcome: z.enum(['success', 'failure', 'uncertain']) })
783
+ .strict()
784
+ ])
785
+ export type EffectEvent = z.infer<typeof EffectEventSchema>
786
+
787
+ // ---------------------------------------------------------------------------
788
+
789
+ /** Every family shipped so far: the first three (`dispatch`, `dev_review_loop`, `forge_write`) plus this task's six (`gate`, `operation`, `usage`, `role_attempt`, `handoff`, `effect`). `kind: 'command' | 'tokens'` is still refused — `command` folds into `operation`, `tokens` into `usage`, so neither name is a separate family. */
790
+ export const LogEventSchema = z.union([
791
+ DispatchEventSchema,
792
+ DevReviewLoopEventSchema,
793
+ ForgeWriteEventSchema,
794
+ GateEventSchema,
795
+ OperationEventSchema,
796
+ UsageEventSchema,
797
+ RoleAttemptEventSchema,
798
+ HandoffEventSchema,
799
+ EffectEventSchema
800
+ ])
801
+ export type LogEvent = z.infer<typeof LogEventSchema>