@attalabs/vinaya 0.36.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 (292) hide show
  1. package/README.md +6 -6
  2. package/aeg-root/contracts/developer-reviewer.md +1 -1
  3. package/aeg-root/contracts/planner-operator.md +1 -1
  4. package/aeg-root/contracts/principal-operator.md +6 -6
  5. package/aeg-root/contracts/security-archivist.md +1 -1
  6. package/aeg-root/enforcement.md +14 -14
  7. package/aeg-root/process.md +3 -1
  8. package/aeg-root/roles/archivist.md +2 -2
  9. package/aeg-root/roles/developer/reference.md +36 -37
  10. package/aeg-root/roles/developer.md +9 -5
  11. package/aeg-root/roles/operator.md +18 -18
  12. package/aeg-root/roles/planner/reference.md +15 -4
  13. package/aeg-root/roles/principal.md +6 -1
  14. package/aeg-root/roles/reviewer.md +14 -6
  15. package/aeg-root/roles/security.md +22 -11
  16. package/aeg-root/roles/tranche-archivist.md +14 -2
  17. package/aeg-root/state-machine.md +12 -11
  18. package/aeg-root/templates/brief-template.md +8 -6
  19. package/aeg-root/templates/pr-report-template.md +1 -9
  20. package/aeg-root/tranche-model.md +10 -4
  21. package/dist/checks/bin/check-body-bare-digits.js +823 -595
  22. package/dist/checks/bin/check-branch-topology.js +796 -478
  23. package/dist/checks/bin/check-brief-shape.js +824 -596
  24. package/dist/checks/bin/check-changeset-coverage.js +1337 -747
  25. package/dist/checks/bin/check-closes-n.js +796 -478
  26. package/dist/checks/bin/check-coherence.js +914 -611
  27. package/dist/checks/bin/check-dead-branch-push.js +705 -462
  28. package/dist/checks/bin/check-dispatch-readiness.js +941 -624
  29. package/dist/checks/bin/check-doc-coverage-push.js +1332 -742
  30. package/dist/checks/bin/check-doc-coverage.js +1339 -742
  31. package/dist/checks/bin/check-doctrine-no-procedures.js +821 -593
  32. package/dist/checks/bin/check-doctrine-portability.js +1332 -742
  33. package/dist/checks/bin/check-evidence-fresh.js +1339 -918
  34. package/dist/checks/bin/check-exec-bits.js +1331 -741
  35. package/dist/checks/bin/check-first-push-dispatch.js +917 -614
  36. package/dist/checks/bin/check-issue-assignment.js +796 -478
  37. package/dist/checks/bin/check-issue-milestone-attach.js +705 -462
  38. package/dist/checks/bin/check-issue-objectives-numbering.js +821 -593
  39. package/dist/checks/bin/check-issue-parts-coverage.js +705 -462
  40. package/dist/checks/bin/check-issue-surface-globs.js +925 -613
  41. package/dist/checks/bin/check-issue-title-grammar.js +705 -462
  42. package/dist/checks/bin/check-issue-tranche-label.js +705 -462
  43. package/dist/checks/bin/check-main-branch-refusal.js +705 -462
  44. package/dist/checks/bin/check-no-disk-state.js +705 -462
  45. package/dist/checks/bin/check-pr-premise-reassert.js +821 -593
  46. package/dist/checks/bin/check-pr-report-density.js +705 -462
  47. package/dist/checks/bin/check-principal-test-plan-wait.js +705 -462
  48. package/dist/checks/bin/check-quoted-command.js +1816 -1228
  49. package/dist/checks/bin/check-reader-resolvable-prose.js +1835 -1235
  50. package/dist/checks/bin/check-registry-gates.js +993 -526
  51. package/dist/checks/bin/check-retired-vocabulary.js +1810 -1222
  52. package/dist/checks/bin/check-review-gate.js +832 -604
  53. package/dist/checks/bin/check-single-plan-pr.js +705 -462
  54. package/dist/checks/bin/check-surface-scope.js +796 -478
  55. package/dist/checks/bin/check-test-plan.js +705 -462
  56. package/dist/checks/bin/check-token-collection-wired.js +705 -462
  57. package/dist/checks/bin/check-workspace-escape.js +1332 -742
  58. package/dist/checks/bin/verify-dispatch.js +3849 -0
  59. package/dist/index.js +20876 -10091
  60. package/dist/lib/pre-push-cache-test-run.js +1045 -682
  61. package/dist/lib/pre-push-changed-files.js +16 -11
  62. package/dist/lib/pre-push-select-tests.js +785 -500
  63. package/package.json +2 -2
  64. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/anchored-region.ts +7 -6
  65. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/brief-render.ts +71 -15
  66. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/brief-validation.ts +51 -12
  67. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/control-store/index.ts +1 -0
  68. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/control-store/local.ts +31 -0
  69. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/control-store/records.ts +50 -2
  70. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/assess-round.ts +443 -28
  71. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/fakes.ts +18 -5
  72. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/index.ts +6 -4
  73. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/journal-reconstruction.ts +13 -13
  74. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/render-summary.ts +46 -110
  75. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/types.ts +169 -11
  76. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/doc-claim.ts +32 -6
  77. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/docs/index.ts +3 -1
  78. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/docs/published-prose.ts +30 -0
  79. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/doctrine-portability.ts +6 -2
  80. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/gate-audience.ts +0 -1
  81. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/index.ts +82 -8
  82. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/issue-validation.ts +754 -7
  83. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/leftover-detection.ts +24 -6
  84. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/custom.ts +157 -0
  85. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/envelope.ts +44 -6
  86. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/fixtures/executions.ts +493 -0
  87. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/fixtures/fact-sheets.ts +111 -0
  88. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/fixtures/generator.ts +155 -0
  89. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/fixtures/index.ts +12 -0
  90. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/index.ts +128 -0
  91. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/catches.ts +63 -0
  92. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/checks.ts +146 -0
  93. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/common.ts +137 -0
  94. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/completion.ts +137 -0
  95. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/convergence.ts +420 -0
  96. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/determinism.ts +65 -0
  97. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/index.ts +69 -0
  98. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/judgment.ts +132 -0
  99. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/labels.ts +21 -0
  100. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/time.ts +167 -0
  101. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/usage.ts +139 -0
  102. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/schema.ts +226 -15
  103. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/store.ts +7 -7
  104. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/sync/cache-contract.ts +207 -0
  105. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/sync/contracts.ts +105 -0
  106. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/sync/engine.ts +308 -0
  107. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/sync/index.ts +34 -0
  108. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/sync/measured.ts +20 -0
  109. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/sync/memory-cache.ts +78 -0
  110. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/sync/normalize.ts +156 -0
  111. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/sync/row.ts +103 -0
  112. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/reader-resolvable-prose.ts +34 -6
  113. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/registry-checks.ts +70 -6
  114. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-gate.ts +52 -4
  115. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-input-manifest.ts +19 -14
  116. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-policy.ts +201 -24
  117. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-status.ts +5 -2
  118. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/task-phase-history.ts +46 -0
  119. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/task-tools.ts +15 -28
  120. package/studio-standalone/apps/vinaya-studio/web/.next/BUILD_ID +1 -1
  121. package/studio-standalone/apps/vinaya-studio/web/.next/app-path-routes-manifest.json +0 -1
  122. package/studio-standalone/apps/vinaya-studio/web/.next/build-manifest.json +3 -3
  123. package/studio-standalone/apps/vinaya-studio/web/.next/prerender-manifest.json +3 -3
  124. package/studio-standalone/apps/vinaya-studio/web/.next/required-server-files.json +0 -5
  125. package/studio-standalone/apps/vinaya-studio/web/.next/routes-manifest.json +0 -6
  126. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error/page.js +1 -1
  127. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error/page.js.nft.json +1 -1
  128. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
  129. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.html +1 -1
  130. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.rsc +1 -1
  131. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
  132. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  133. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  134. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  135. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  136. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page/server-reference-manifest.json +2 -2
  137. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page.js +1 -1
  138. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page.js.nft.json +1 -1
  139. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  140. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page/server-reference-manifest.json +2 -2
  141. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page.js +1 -1
  142. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page.js.nft.json +1 -1
  143. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page_client-reference-manifest.js +1 -1
  144. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page/server-reference-manifest.json +2 -2
  145. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page.js +3 -3
  146. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page.js.nft.json +1 -1
  147. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page_client-reference-manifest.js +1 -1
  148. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page/server-reference-manifest.json +2 -2
  149. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page.js +3 -3
  150. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page.js.nft.json +1 -1
  151. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page_client-reference-manifest.js +1 -1
  152. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page/server-reference-manifest.json +2 -2
  153. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page.js +3 -3
  154. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page.js.nft.json +1 -1
  155. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page_client-reference-manifest.js +1 -1
  156. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page/server-reference-manifest.json +3 -3
  157. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page.js +5 -5
  158. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page.js.nft.json +1 -1
  159. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page_client-reference-manifest.js +1 -1
  160. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page/server-reference-manifest.json +2 -2
  161. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page.js +3 -3
  162. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page.js.nft.json +1 -1
  163. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page_client-reference-manifest.js +1 -1
  164. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page/server-reference-manifest.json +2 -2
  165. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page.js +3 -3
  166. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page.js.nft.json +1 -1
  167. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page_client-reference-manifest.js +1 -1
  168. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page/server-reference-manifest.json +2 -2
  169. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page.js +3 -3
  170. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page.js.nft.json +1 -1
  171. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page_client-reference-manifest.js +1 -1
  172. package/studio-standalone/apps/vinaya-studio/web/.next/server/app-paths-manifest.json +0 -1
  173. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/044u_vinaya-studio_web_src_app_studio_backlog__components_BacklogTable_tsx_0oha0bt._.js +3 -0
  174. 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
  175. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/{[root-of-the-server]__1bh2awk._.js → [root-of-the-server]__038scsm._.js} +2 -2
  176. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/{[root-of-the-server]__1widio3._.js → [root-of-the-server]__03__s45._.js} +2 -2
  177. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/{_15gdg48._.js → [root-of-the-server]__04adkz-._.js} +3 -3
  178. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__05zwn98._.js +14 -0
  179. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__08e39jo._.js +3 -0
  180. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__0h9yhwx._.js +1 -1
  181. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/{[root-of-the-server]__1wy7w66._.js → [root-of-the-server]__0jdjsxe._.js} +2 -2
  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]__10riywf._.js +3 -0
  184. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/{[root-of-the-server]__13znegp._.js → [root-of-the-server]__134x-65._.js} +2 -2
  185. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/{[root-of-the-server]__13eeix2._.js → [root-of-the-server]__1_l_l1u._.js} +2 -2
  186. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1f4bb3_._.js +3 -0
  187. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1gjqmhq._.js +1 -1
  188. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/{[root-of-the-server]__1dky4g0._.js → [root-of-the-server]__1my83lt._.js} +2 -2
  189. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1ng2x88._.js +3 -0
  190. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/{[root-of-the-server]__040smoa._.js → [root-of-the-server]__1qpc6at._.js} +2 -2
  191. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1snpgaw._.js +56 -0
  192. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1wc4-ip._.js +2 -2
  193. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_06h3wbl._.js +3 -0
  194. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_08onyya._.js +1 -1
  195. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_096f46i._.js +1 -1
  196. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0af2one._.js +1 -1
  197. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0e5tkdd._.js +1 -1
  198. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0gs4gvl._.js +3 -0
  199. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0kf2g72._.js +1 -1
  200. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0zf4d27._.js +1 -1
  201. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_1-wo68i._.js +1 -1
  202. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_121lrn5._.js +3 -0
  203. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_1achbh9._.js +1 -1
  204. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_1o4v6lb._.js +3 -0
  205. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_1q7h5mz._.js +1 -1
  206. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_1ztd4i3._.js +3 -0
  207. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_209-ugd._.js +3 -0
  208. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_214d71c._.js +3 -0
  209. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/apps_vinaya-studio_web_src_app_studio_projects_[name]_tranches_[slug]_17dho0f._.js +3 -0
  210. 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
  211. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/node_modules_next_dist_1lzmr5o._.js +1 -1
  212. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/packages_ui_libraries_animate_components_index_ts_186fje1._.js +1 -1
  213. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/packages_ui_libraries_basic_components_index_ts_0xk1vda._.js +1 -1
  214. package/studio-standalone/apps/vinaya-studio/web/.next/server/middleware-build-manifest.js +3 -3
  215. package/studio-standalone/apps/vinaya-studio/web/.next/server/pages/500.html +1 -1
  216. package/studio-standalone/apps/vinaya-studio/web/.next/server/server-reference-manifest.js +1 -1
  217. package/studio-standalone/apps/vinaya-studio/web/.next/server/server-reference-manifest.json +4 -4
  218. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/09fcolor69bun.js +1 -0
  219. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/0lcwmwzxacdie.js +1 -0
  220. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/0ojry7lrbzkfd.css +1 -0
  221. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/1-acpmtfmrc35.js +1 -0
  222. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/1giu47hrbhroj.js +1 -0
  223. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/1shz6lwruld25.js +1 -0
  224. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/1ytvuy1mmnc6j.js +1 -0
  225. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{3oxhhhm_psozq.js → 21a6_5cr956wj.js} +1 -1
  226. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{2o9l0b7eqbr57.js → 2f2y8xxok8zph.js} +1 -1
  227. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/2g8mwnydod96u.js +1 -0
  228. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{3li0ueedy-ozv.js → 2nrnuawd5fwpv.js} +1 -1
  229. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/2nw47832_uvfe.js +1 -0
  230. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/2qdxnj8wk2h0s.js +1 -0
  231. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{3lqjwjrcvq481.js → 2xevgia1h8g0y.js} +2 -2
  232. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/3b9q75p-z5ma5.js +1 -0
  233. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/3cv-oe7153242.js +1 -0
  234. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/3m310lbjj4p5u.js +1 -0
  235. package/studio-standalone/apps/vinaya-studio/web/package.json +2 -2
  236. package/studio-standalone/apps/vinaya-studio/web/server.js +1 -1
  237. package/dist/checks/bin/check-token-report.js +0 -6526
  238. 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/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/bin/verify-coherence.ts +0 -1089
  239. package/studio-standalone/_node_modules/next/dist/compiled/next-server/app-route-turbo.runtime.prod.js +0 -6
  240. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/api/coherence/route/app-paths-manifest.json +0 -3
  241. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/api/coherence/route/build-manifest.json +0 -9
  242. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/api/coherence/route/server-reference-manifest.json +0 -4
  243. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/api/coherence/route.js +0 -6
  244. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/api/coherence/route.js.map +0 -5
  245. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/api/coherence/route.js.nft.json +0 -1
  246. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/api/coherence/route_client-reference-manifest.js +0 -3
  247. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/044u_vinaya-studio_web__next-internal_server_app_api_coherence_route_actions_1rnzea1.js +0 -3
  248. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/[externals]__0cki-x_._.js +0 -3
  249. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/[root-of-the-server]__02a-3g8._.js +0 -15
  250. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/[turbopack]_runtime.js +0 -903
  251. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__074w9nf._.js +0 -3
  252. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__0ln09ua._.js +0 -3
  253. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__0oegopp._.js +0 -3
  254. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__13yxbjd._.js +0 -51
  255. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1duqmtm._.js +0 -3
  256. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1z7dml9._.js +0 -9
  257. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0bfs_u4._.js +0 -3
  258. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0g8_eot._.js +0 -3
  259. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0hrh_v-._.js +0 -181
  260. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0i4-dea._.js +0 -3
  261. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0o54suy._.js +0 -3
  262. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0rxd7s0._.js +0 -3
  263. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0y1jv16._.js +0 -3
  264. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_151m4rz._.js +0 -3
  265. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_1a9dieq._.js +0 -3
  266. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_1sxsf5q._.js +0 -3
  267. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_1sy_yfr._.js +0 -3
  268. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_219v2an._.js +0 -3
  269. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/apps_vinaya-studio_web_src_app_studio_projects_[name]_tranches_[slug]_05ufo8i._.js +0 -3
  270. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/packages_ui_libraries_basic_components_form_input_tsx_0es8d8b._.js +0 -3
  271. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/packages_ui_libraries_brutal_components_index_ts_0n_lcc4._.js +0 -3
  272. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/packages_ui_libraries_retro_components_index_ts_0wvpm_z._.js +0 -3
  273. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/00z3-ljjd1gj9.js +0 -1
  274. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/0bjnj-5fy4e7l.js +0 -1
  275. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/0c8uwz_-m8s99.js +0 -165
  276. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/0ct0c-xj0baf6.js +0 -1
  277. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/0ko698wh8xx2g.css +0 -1
  278. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/0t5n_r4xm__t-.js +0 -1
  279. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/0vc2u252q5q6o.js +0 -1
  280. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/16r_o07lw0vm0.js +0 -1
  281. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/1cah7_e5a1zvu.js +0 -1
  282. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/1gjo9-6dz7nup.js +0 -1
  283. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/24tz8aro1uto4.js +0 -1
  284. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/2ef2g5fozszw7.js +0 -1
  285. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/2ka8dg687auhj.js +0 -1
  286. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/2pf3f50gbrkyv.js +0 -1
  287. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/2qq49pct3q51-.js +0 -1
  288. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/3et66z7glk65w.js +0 -1
  289. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/3y6u3prmrkea-.js +0 -1
  290. /package/studio-standalone/apps/vinaya-studio/web/.next/static/{z1fTSBP6ZlUjObzFIp-qq → yNZEFRSjP9BLUfdf96Eol}/_buildManifest.js +0 -0
  291. /package/studio-standalone/apps/vinaya-studio/web/.next/static/{z1fTSBP6ZlUjObzFIp-qq → yNZEFRSjP9BLUfdf96Eol}/_clientMiddlewareManifest.js +0 -0
  292. /package/studio-standalone/apps/vinaya-studio/web/.next/static/{z1fTSBP6ZlUjObzFIp-qq → yNZEFRSjP9BLUfdf96Eol}/_ssgManifest.js +0 -0
@@ -0,0 +1,105 @@
1
+ /**
2
+ * The three contracts every Vinaya Log reader codes against
3
+ * (`apps/cli/specs/log-sync.md`):
4
+ *
5
+ * - a **source** — where pages of stored lines come from (a log folder, a
6
+ * log server), each page with the cursor to resume from and every gap
7
+ * the source knows it cannot fill;
8
+ * - a **cache** — where normalised rows live, with each source's cursor,
9
+ * the gaps, the quarantined lines and the edits a re-read revealed;
10
+ * - a **dataset** — what a query reads: the rows, and the gaps and
11
+ * quarantine it must account for before calling an answer known.
12
+ *
13
+ * These are types only. The sender's own queue contract (`LogStore`,
14
+ * `../store.ts`) is a different thing and stays separate.
15
+ */
16
+
17
+ import type { Measured } from './measured'
18
+ import type { DatasetRow, NormalizedLine, QuarantineRecord, RowOrigin } from './row'
19
+
20
+ /** A source's opaque resume point. Only the source that issued it interprets it. */
21
+ export type SourceCursor = string
22
+
23
+ /** One stored line as a source hands it over, with its position inside that source. */
24
+ export type SourceLine = {
25
+ raw: string
26
+ /** Opaque position within the source — becomes `RowOrigin.position`. */
27
+ position: string
28
+ }
29
+
30
+ /**
31
+ * A stretch of a source's history that can no longer be read — rotated
32
+ * away, expired from a server's retention, rejected on receipt. A gap is
33
+ * reported, never skipped silently. `from`/`to` are opaque source positions
34
+ * bounding it, `null` where the bound is itself unknown.
35
+ */
36
+ export type SourceGap = {
37
+ source: string
38
+ from: string | null
39
+ to: string | null
40
+ reason: string
41
+ /** How many lines the gap lost, when the source can count them. */
42
+ lost: Measured<number>
43
+ }
44
+
45
+ /** One page read from a source. `next` is `null` when the source had nothing after this page when read. */
46
+ export type SourcePage = {
47
+ lines: readonly SourceLine[]
48
+ next: SourceCursor | null
49
+ gaps: readonly SourceGap[]
50
+ }
51
+
52
+ /** Where stored lines come from. Reading never writes to the source. */
53
+ export interface LogSource {
54
+ /** Stable across runs for the same place (for example `folder:<path>`, `server:<url>`) — the key its cursor and gaps are stored under. */
55
+ readonly id: string
56
+ /** Reads the page after `cursor` (`null` = from the beginning), at most `limit` lines. */
57
+ readPage(cursor: SourceCursor | null, limit: number): Promise<SourcePage>
58
+ }
59
+
60
+ /**
61
+ * A stored row later re-read with the same identity and different content.
62
+ * The first row is kept; the difference is recorded here, once per distinct
63
+ * content.
64
+ */
65
+ export type RowEdit = {
66
+ identity: string
67
+ /** `contentHash` of the row the cache keeps. */
68
+ keptHash: string
69
+ /** `contentHash` of the differing content that was offered. */
70
+ editedHash: string
71
+ /** Where the differing content was read from. */
72
+ origin: RowOrigin | null
73
+ }
74
+
75
+ /** What storing one normalised line did. */
76
+ export type PutOutcome =
77
+ | { type: 'row'; result: 'inserted' | 'duplicate' | 'edited' }
78
+ | { type: 'quarantine'; result: 'inserted' | 'duplicate' }
79
+
80
+ /** What a query reads. Every list is deterministic, so two backends holding the same content answer identically. */
81
+ export interface Dataset {
82
+ /** Every row exactly once, ordered by `time`, then `identity`. */
83
+ rows(): readonly DatasetRow[]
84
+ /** Every recorded gap, in the order recorded. */
85
+ gaps(): readonly SourceGap[]
86
+ /** Every quarantined line, in the order first stored. */
87
+ quarantined(): readonly QuarantineRecord[]
88
+ }
89
+
90
+ /**
91
+ * Where normalised rows live between syncs. Idempotent by identity: storing
92
+ * a row whose identity is already held adds nothing — the same content is a
93
+ * duplicate, different content is recorded as an edit against the kept row.
94
+ * A quarantine record is keyed by its `contentHash`.
95
+ */
96
+ export interface LogCache {
97
+ put(line: NormalizedLine): PutOutcome
98
+ /** The cursor last stored for `source`, or `null` when none was. */
99
+ cursor(source: string): SourceCursor | null
100
+ setCursor(source: string, cursor: SourceCursor): void
101
+ /** Records a gap; recording the same gap (same source, bounds and reason) twice keeps one. */
102
+ recordGap(gap: SourceGap): void
103
+ edits(): readonly RowEdit[]
104
+ dataset(): Dataset
105
+ }
@@ -0,0 +1,308 @@
1
+ /**
2
+ * The sync engine (`apps/cli/specs/log-sync.md`, "The sync run"): the one
3
+ * algorithm that moves a source's stored lines into a cache and is honest
4
+ * about what it could not see. It is pure — a function over a `LogSource` and
5
+ * a `LogCache` handed to it, with the clock and the bounds passed in, no I/O
6
+ * and no clock read of its own.
7
+ *
8
+ * The stored cursor is the **look-back anchor**: it trails the furthest point
9
+ * synced by at most `lookback` lines, so a run reads from it both to resume
10
+ * after a failure (O2) and to re-read the look-back span every run (O3) — the
11
+ * two are the same read. Overlap is deduplicated by identity in the cache
12
+ * (O1), a changed identity is recorded as an edit beside the first row (O3), an
13
+ * identity the cache held at a source position inside the span the run
14
+ * re-read that the source no longer returns is a deletion (O3), and a span the source itself reports lost is a
15
+ * gap, never a deletion (O4).
16
+ */
17
+
18
+ import type { LogCache, LogSource, SourceCursor, SourceGap, SourcePage } from './contracts'
19
+ import { unknownBecause } from './measured'
20
+ import { normalizeStoredLine } from './normalize'
21
+ import type { RowOrigin } from './row'
22
+
23
+ /** The default look-back span: how many trailing positions a run re-reads to find edits and deletions. */
24
+ export const DEFAULT_SYNC_LOOKBACK = 1000
25
+ /** The default page bound: how many pages one run reads before it stops and reports more is available. */
26
+ export const DEFAULT_SYNC_MAX_PAGES = 50
27
+ /** The default page size: how many lines a single `readPage` asks for. */
28
+ export const DEFAULT_SYNC_PAGE_LIMIT = 1000
29
+
30
+ /** The bounds and clock one sync run is given. The engine never reads the clock itself. */
31
+ export type SyncOptions = {
32
+ /** The run's wall-clock instant, passed in so the engine stays pure. */
33
+ now: Date
34
+ /** At most this many pages this run (default {@link DEFAULT_SYNC_MAX_PAGES}). */
35
+ maxPages?: number
36
+ /** At most this many lines per `readPage` (default {@link DEFAULT_SYNC_PAGE_LIMIT}). */
37
+ pageLimit?: number
38
+ /** The trailing span re-read every run to find edits and deletions (default {@link DEFAULT_SYNC_LOOKBACK}). */
39
+ lookback?: number
40
+ }
41
+
42
+ /** One identity the cache held in the look-back window that the source no longer returns. The stored row is kept; this is where the loss is reported. */
43
+ export type RowDeletion = {
44
+ identity: string
45
+ /** Where the row was last read from, as the cache holds it. */
46
+ origin: RowOrigin | null
47
+ }
48
+
49
+ /** What one sync run did. Every count is of this run alone; the cache holds the running totals. */
50
+ export type SyncSummary = {
51
+ /** The source's stable id. */
52
+ source: string
53
+ /** The `now` the run was given, as an ISO instant — the engine's only use of the clock it was handed. */
54
+ ranAt: string
55
+ /** Pages read from the source this run. */
56
+ pagesRead: number
57
+ /** Rows newly inserted this run. */
58
+ rowsStored: number
59
+ /** Rows offered whose identity and content the cache already held. */
60
+ duplicates: number
61
+ /** Distinct edits recorded this run: a held identity re-read with different content. */
62
+ edits: number
63
+ /** Identities found deleted this run — detailed in {@link SyncSummary.deleted}. */
64
+ deletions: number
65
+ /** Gaps recorded this run: a span the source reported it could not fill. */
66
+ gaps: number
67
+ /** Lines quarantined this run: an unknown schema version or a line that failed validation. */
68
+ quarantined: number
69
+ /** `true` when the run reached the end of the source without a failure. */
70
+ completed: boolean
71
+ /** `true` when the run stopped on its page bound with more still to read. */
72
+ moreAvailable: boolean
73
+ /** The failure that ended the run early, or `null` when none. The pages stored before it are kept. */
74
+ failure: string | null
75
+ /** Every deletion this run found. The cache keeps no deletion record, so the run's summary is where a deletion is reported. */
76
+ deleted: readonly RowDeletion[]
77
+ }
78
+
79
+ type Boundary = { cursor: SourceCursor | null; linesBefore: number }
80
+
81
+ /**
82
+ * Runs one sync of `source` into `cache`.
83
+ *
84
+ * Reads pages from the stored look-back anchor, storing every page's rows and
85
+ * quarantine records before advancing anything (O1), until the source ends, a
86
+ * page bound is hit, or a read fails (O2). The overlap with already-stored
87
+ * data deduplicates by identity and surfaces edits; a held identity gone from
88
+ * the re-read window and not covered by a reported gap is a deletion (O3, O4).
89
+ * The run returns a summary and never reads the clock.
90
+ */
91
+ export async function syncSource(source: LogSource, cache: LogCache, options: SyncOptions): Promise<SyncSummary> {
92
+ const maxPages = options.maxPages ?? DEFAULT_SYNC_MAX_PAGES
93
+ const pageLimit = options.pageLimit ?? DEFAULT_SYNC_PAGE_LIMIT
94
+ const lookback = options.lookback ?? DEFAULT_SYNC_LOOKBACK
95
+ const id = source.id
96
+
97
+ const startCursor = cache.cursor(id)
98
+ const editsBefore = cache.edits().length
99
+ const gapsBefore = cache.dataset().gaps().length
100
+
101
+ // What the cache held for this source before the run, each row with the
102
+ // source position it was last read from — used to tell a deletion from an
103
+ // untouched row.
104
+ const priorRows = new Map<string, RowOrigin>()
105
+ for (const row of cache.dataset().rows()) {
106
+ if (row.origin?.source === id) priorRows.set(row.identity, row.origin)
107
+ }
108
+
109
+ let pagesRead = 0
110
+ let rowsStored = 0
111
+ let duplicates = 0
112
+ let quarantined = 0
113
+ let failure: string | null = null
114
+ let completed = false
115
+ let sawGap = false
116
+
117
+ // Identities the source returned this run, and the span of source
118
+ // positions the run re-read — the window within which an absent held
119
+ // identity is a deletion. Never a span of event times: lines written by
120
+ // many machines arrive out of event-time order, so a time window would take
121
+ // in rows the run never re-read.
122
+ const seen = new Set<string>()
123
+ const span = new Map<string, SpanBounds>()
124
+
125
+ const boundaries: Boundary[] = []
126
+ let totalLines = 0
127
+ let cursor: SourceCursor | null = startCursor
128
+ let lastNext: SourceCursor | null = null
129
+
130
+ while (pagesRead < maxPages) {
131
+ boundaries.push({ cursor, linesBefore: totalLines })
132
+ let page: SourcePage
133
+ try {
134
+ page = await source.readPage(cursor, pageLimit)
135
+ } catch (error) {
136
+ failure = error instanceof Error ? error.message : String(error)
137
+ break
138
+ }
139
+ pagesRead++
140
+
141
+ // Store every row and quarantine record on the page before advancing the
142
+ // cursor (O1): a failure between the store and the advance would skip
143
+ // lines forever, so the store comes first and the advance is the last act.
144
+ for (const sourceLine of page.lines) {
145
+ const normalized = normalizeStoredLine(sourceLine.raw, { source: id, position: sourceLine.position })
146
+ const outcome = cache.put(normalized)
147
+ const reread = normalized.type === 'row' && priorRows.has(normalized.row.identity)
148
+ if (normalized.type === 'row') seen.add(normalized.row.identity)
149
+ widenSpan(span, sourceLine.position, reread)
150
+ if (outcome.type === 'row') {
151
+ if (outcome.result === 'inserted') rowsStored++
152
+ else if (outcome.result === 'duplicate') duplicates++
153
+ // 'edited' is counted from the cache's own edit log below.
154
+ } else if (outcome.result === 'inserted') {
155
+ quarantined++
156
+ }
157
+ totalLines++
158
+ }
159
+
160
+ for (const gap of page.gaps) {
161
+ cache.recordGap(gap)
162
+ sawGap = true
163
+ }
164
+
165
+ lastNext = page.next
166
+ cursor = page.next
167
+ if (page.next === null) {
168
+ completed = true
169
+ break
170
+ }
171
+ }
172
+
173
+ // A non-null stored cursor that returns nothing is a source whose head has
174
+ // fallen behind what the cache already consumed — a gap, not a silent reset
175
+ // (O4).
176
+ if (failure === null && startCursor !== null && totalLines === 0 && !sawGap && priorRows.size > 0) {
177
+ const headBehind: SourceGap = {
178
+ source: id,
179
+ from: startCursor,
180
+ to: null,
181
+ reason: 'the source head is behind the stored cursor',
182
+ lost: unknownBecause<number>('the source retained nothing from the stored cursor')
183
+ }
184
+ cache.recordGap(headBehind)
185
+ sawGap = true
186
+ }
187
+
188
+ const deleted = deriveDeletions({ priorRows, seen, span, sawGap })
189
+
190
+ // Advance the stored cursor to the new look-back anchor only on a clean run:
191
+ // a failure leaves it where it was, so the next run re-reads from the last
192
+ // safe point rather than past the lines it never stored (O2).
193
+ if (failure === null) {
194
+ const anchor = nextAnchor(boundaries, totalLines, lookback)
195
+ if (anchor !== null) cache.setCursor(id, anchor)
196
+ }
197
+
198
+ const moreAvailable = failure === null && !completed && lastNext !== null
199
+
200
+ return {
201
+ source: id,
202
+ ranAt: options.now.toISOString(),
203
+ pagesRead,
204
+ rowsStored,
205
+ duplicates,
206
+ edits: cache.edits().length - editsBefore,
207
+ deletions: deleted.length,
208
+ gaps: cache.dataset().gaps().length - gapsBefore,
209
+ quarantined,
210
+ completed,
211
+ moreAvailable,
212
+ failure,
213
+ deleted
214
+ }
215
+ }
216
+
217
+ /**
218
+ * A source position split into its stream and its ordinal within that stream:
219
+ * the text before its trailing run of digits, and those digits as a number —
220
+ * a server's sequence number (`"1042"`), a folder stream's byte offset
221
+ * (`"<stream>:live:8192"`). Positions are ordered only within one stream; a
222
+ * position with no trailing ordinal is ordered against nothing, so it never
223
+ * lies inside a re-read span.
224
+ */
225
+ function splitPosition(position: string): { stream: string; ordinal: number } | null {
226
+ const match = /^(.*?)(\d+)$/.exec(position)
227
+ if (match === null) return null
228
+ const ordinal = Number(match[2])
229
+ if (!Number.isSafeInteger(ordinal)) return null
230
+ return { stream: match[1] as string, ordinal }
231
+ }
232
+
233
+ /**
234
+ * One stream's re-read span: from the earliest position at which the run
235
+ * re-read a row the cache already held (`null` until it has), to the furthest
236
+ * position the run read at all.
237
+ */
238
+ type SpanBounds = { from: number | null; to: number }
239
+
240
+ /**
241
+ * Widens the run's re-read span, per stream, to take in one position the
242
+ * source returned. Only a re-read of a row the cache already held can open
243
+ * the span: lines past the stored cursor are new, so a run that re-read
244
+ * nothing before its cursor has an empty span — and a stream whose positions
245
+ * restarted (a rotated folder stream's fresh live file) opens none on its new
246
+ * lines alone.
247
+ */
248
+ function widenSpan(span: Map<string, SpanBounds>, position: string, reread: boolean): void {
249
+ const split = splitPosition(position)
250
+ if (split === null) return
251
+ const from = reread ? split.ordinal : null
252
+ const bounds = span.get(split.stream)
253
+ if (bounds === undefined) {
254
+ span.set(split.stream, { from, to: split.ordinal })
255
+ return
256
+ }
257
+ if (from !== null && (bounds.from === null || from < bounds.from)) bounds.from = from
258
+ if (split.ordinal > bounds.to) bounds.to = split.ordinal
259
+ }
260
+
261
+ /**
262
+ * The cached identities the source no longer returns whose own source
263
+ * position lies inside the span of positions the run re-read — its
264
+ * deletions. A run that saw any gap derives none: the source reported what it
265
+ * lost, and a reported loss is a gap, never a deletion (O4). A row whose
266
+ * position lies before or after the span, or in a stream the run re-read
267
+ * nothing of, was not re-read and is left untouched; a run that re-read
268
+ * nothing has an empty span and derives none.
269
+ */
270
+ function deriveDeletions(input: {
271
+ priorRows: Map<string, RowOrigin>
272
+ seen: Set<string>
273
+ span: Map<string, SpanBounds>
274
+ sawGap: boolean
275
+ }): RowDeletion[] {
276
+ const { priorRows, seen, span, sawGap } = input
277
+ if (sawGap) return []
278
+ const deleted: RowDeletion[] = []
279
+ for (const [identity, origin] of priorRows) {
280
+ if (seen.has(identity)) continue
281
+ const split = splitPosition(origin.position)
282
+ if (split === null) continue
283
+ const bounds = span.get(split.stream)
284
+ if (bounds === undefined || bounds.from === null) continue
285
+ if (split.ordinal < bounds.from || split.ordinal > bounds.to) continue
286
+ deleted.push({ identity, origin })
287
+ }
288
+ return deleted
289
+ }
290
+
291
+ /**
292
+ * The cursor to store as the next run's look-back anchor: the earliest page
293
+ * boundary that still leaves at most `lookback` lines ahead of it, so the next
294
+ * run re-reads that trailing span and no more (O6). `null` keeps the anchor
295
+ * where it was — at the start of the source — when the whole read fit inside
296
+ * the span.
297
+ */
298
+ function nextAnchor(boundaries: Boundary[], totalLines: number, lookback: number): SourceCursor | null {
299
+ const floor = totalLines - lookback
300
+ let chosen: Boundary | null = null
301
+ for (const boundary of boundaries) {
302
+ if (boundary.linesBefore >= floor) {
303
+ chosen = boundary
304
+ break
305
+ }
306
+ }
307
+ return chosen?.cursor ?? null
308
+ }
@@ -0,0 +1,34 @@
1
+ export type { CacheContractCase } from './cache-contract'
2
+ export { cacheContractCases } from './cache-contract'
3
+ export type {
4
+ Dataset,
5
+ LogCache,
6
+ LogSource,
7
+ PutOutcome,
8
+ RowEdit,
9
+ SourceCursor,
10
+ SourceGap,
11
+ SourceLine,
12
+ SourcePage
13
+ } from './contracts'
14
+ export {
15
+ DEFAULT_SYNC_LOOKBACK,
16
+ DEFAULT_SYNC_MAX_PAGES,
17
+ DEFAULT_SYNC_PAGE_LIMIT,
18
+ syncSource
19
+ } from './engine'
20
+ export type { RowDeletion, SyncOptions, SyncSummary } from './engine'
21
+ export type { Measured } from './measured'
22
+ export { known, unknownBecause } from './measured'
23
+ export { createMemoryCache } from './memory-cache'
24
+ export { isLowTrustVersion, normalizeStoredLine } from './normalize'
25
+ export type {
26
+ DatasetRow,
27
+ JsonObject,
28
+ NormalizedLine,
29
+ QuarantineRecord,
30
+ RowOrigin,
31
+ RowTrust,
32
+ UnknownableField
33
+ } from './row'
34
+ export { LOW_TRUST_BELOW_VERSION } from './row'
@@ -0,0 +1,20 @@
1
+ /**
2
+ * `Measured<T>` — the answer type every Vinaya Log reader returns: a known
3
+ * value, or unknown with the reason it cannot be stated
4
+ * (`apps/cli/specs/log-sync.md`). An unknown is never collapsed into a
5
+ * default such as `0`, `''` or `false`: a question the log cannot answer
6
+ * says so, and says why.
7
+ */
8
+ export type Measured<T> =
9
+ | { readonly known: true; readonly value: T }
10
+ | { readonly known: false; readonly reason: string }
11
+
12
+ /** A value the log states. */
13
+ export function known<T>(value: T): Measured<T> {
14
+ return { known: true, value }
15
+ }
16
+
17
+ /** A value the log cannot state, and why. */
18
+ export function unknownBecause<T = never>(reason: string): Measured<T> {
19
+ return { known: false, reason }
20
+ }
@@ -0,0 +1,78 @@
1
+ /**
2
+ * An in-memory `LogCache` (`apps/cli/specs/log-sync.md`): no I/O, no clock,
3
+ * so every later reader can be tested against it, and the shared contract
4
+ * cases (`cache-contract.ts`) fix what a durable backend must match.
5
+ */
6
+
7
+ import type { Dataset, LogCache, RowEdit, SourceCursor, SourceGap } from './contracts'
8
+ import type { DatasetRow, QuarantineRecord } from './row'
9
+
10
+ function gapKey(gap: SourceGap): string {
11
+ return JSON.stringify([gap.source, gap.from, gap.to, gap.reason])
12
+ }
13
+
14
+ export function createMemoryCache(): LogCache {
15
+ const rows = new Map<string, DatasetRow>()
16
+ const quarantine = new Map<string, QuarantineRecord>()
17
+ const cursors = new Map<string, SourceCursor>()
18
+ const gaps = new Map<string, SourceGap>()
19
+ const edits = new Map<string, RowEdit>()
20
+
21
+ const dataset: Dataset = {
22
+ rows() {
23
+ return [...rows.values()].sort((a, b) =>
24
+ a.time === b.time ? (a.identity < b.identity ? -1 : a.identity > b.identity ? 1 : 0) : a.time < b.time ? -1 : 1
25
+ )
26
+ },
27
+ gaps() {
28
+ return [...gaps.values()]
29
+ },
30
+ quarantined() {
31
+ return [...quarantine.values()]
32
+ }
33
+ }
34
+
35
+ return {
36
+ put(line) {
37
+ if (line.type === 'quarantine') {
38
+ const key = line.record.contentHash
39
+ if (quarantine.has(key)) return { type: 'quarantine', result: 'duplicate' }
40
+ quarantine.set(key, line.record)
41
+ return { type: 'quarantine', result: 'inserted' }
42
+ }
43
+ const incoming = line.row
44
+ const kept = rows.get(incoming.identity)
45
+ if (kept === undefined) {
46
+ rows.set(incoming.identity, incoming)
47
+ return { type: 'row', result: 'inserted' }
48
+ }
49
+ if (kept.contentHash === incoming.contentHash) return { type: 'row', result: 'duplicate' }
50
+ const editKey = JSON.stringify([incoming.identity, incoming.contentHash])
51
+ if (!edits.has(editKey)) {
52
+ edits.set(editKey, {
53
+ identity: incoming.identity,
54
+ keptHash: kept.contentHash,
55
+ editedHash: incoming.contentHash,
56
+ origin: incoming.origin
57
+ })
58
+ }
59
+ return { type: 'row', result: 'edited' }
60
+ },
61
+ cursor(source) {
62
+ return cursors.get(source) ?? null
63
+ },
64
+ setCursor(source, cursor) {
65
+ cursors.set(source, cursor)
66
+ },
67
+ recordGap(gap) {
68
+ const key = gapKey(gap)
69
+ if (!gaps.has(key)) gaps.set(key, gap)
70
+ },
71
+ edits() {
72
+ return [...edits.values()]
73
+ },
74
+ dataset() {
75
+ return dataset
76
+ }
77
+ }
78
+ }