@allocator-one/rcl 4.4.19

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 (663) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1415 -0
  3. package/dist/ci.d.ts +16 -0
  4. package/dist/ci.js +42 -0
  5. package/dist/ci.js.map +1 -0
  6. package/dist/config/data-dir.d.ts +6 -0
  7. package/dist/config/data-dir.js +12 -0
  8. package/dist/config/data-dir.js.map +1 -0
  9. package/dist/config/defaults.d.ts +82 -0
  10. package/dist/config/defaults.js +89 -0
  11. package/dist/config/defaults.js.map +1 -0
  12. package/dist/config/harness.d.ts +40 -0
  13. package/dist/config/harness.js +151 -0
  14. package/dist/config/harness.js.map +1 -0
  15. package/dist/config/loader.d.ts +13 -0
  16. package/dist/config/loader.js +131 -0
  17. package/dist/config/loader.js.map +1 -0
  18. package/dist/config/provider-concurrency.d.ts +4 -0
  19. package/dist/config/provider-concurrency.js +6 -0
  20. package/dist/config/provider-concurrency.js.map +1 -0
  21. package/dist/config/providers.d.ts +3 -0
  22. package/dist/config/providers.js +9 -0
  23. package/dist/config/providers.js.map +1 -0
  24. package/dist/config/schema.d.ts +179 -0
  25. package/dist/config/schema.js +115 -0
  26. package/dist/config/schema.js.map +1 -0
  27. package/dist/consensus/claim-contract.d.ts +9 -0
  28. package/dist/consensus/claim-contract.js +307 -0
  29. package/dist/consensus/claim-contract.js.map +1 -0
  30. package/dist/consensus/claim-identity.d.ts +5 -0
  31. package/dist/consensus/claim-identity.js +39 -0
  32. package/dist/consensus/claim-identity.js.map +1 -0
  33. package/dist/consensus/deduper.d.ts +43 -0
  34. package/dist/consensus/deduper.js +1052 -0
  35. package/dist/consensus/deduper.js.map +1 -0
  36. package/dist/consensus/finding-identity.d.ts +20 -0
  37. package/dist/consensus/finding-identity.js +49 -0
  38. package/dist/consensus/finding-identity.js.map +1 -0
  39. package/dist/consensus/gating.d.ts +215 -0
  40. package/dist/consensus/gating.js +699 -0
  41. package/dist/consensus/gating.js.map +1 -0
  42. package/dist/consensus/parser.d.ts +22 -0
  43. package/dist/consensus/parser.js +255 -0
  44. package/dist/consensus/parser.js.map +1 -0
  45. package/dist/consensus/semantic-deduper.d.ts +10 -0
  46. package/dist/consensus/semantic-deduper.js +70 -0
  47. package/dist/consensus/semantic-deduper.js.map +1 -0
  48. package/dist/consensus/types.d.ts +196 -0
  49. package/dist/consensus/types.js +2 -0
  50. package/dist/consensus/types.js.map +1 -0
  51. package/dist/consensus/verification-contract.d.ts +8 -0
  52. package/dist/consensus/verification-contract.js +95 -0
  53. package/dist/consensus/verification-contract.js.map +1 -0
  54. package/dist/consensus/voter.d.ts +29 -0
  55. package/dist/consensus/voter.js +394 -0
  56. package/dist/consensus/voter.js.map +1 -0
  57. package/dist/converge/attempt-budget.d.ts +88 -0
  58. package/dist/converge/attempt-budget.js +717 -0
  59. package/dist/converge/attempt-budget.js.map +1 -0
  60. package/dist/converge/bound-fix-recovery-source.d.ts +24 -0
  61. package/dist/converge/bound-fix-recovery-source.js +25 -0
  62. package/dist/converge/bound-fix-recovery-source.js.map +1 -0
  63. package/dist/converge/bound-fix-recovery.d.ts +15 -0
  64. package/dist/converge/bound-fix-recovery.js +65 -0
  65. package/dist/converge/bound-fix-recovery.js.map +1 -0
  66. package/dist/converge/correction-anchors.d.ts +1 -0
  67. package/dist/converge/correction-anchors.js +2 -0
  68. package/dist/converge/correction-anchors.js.map +1 -0
  69. package/dist/converge/cycle-remote.d.ts +6 -0
  70. package/dist/converge/cycle-remote.js +41 -0
  71. package/dist/converge/cycle-remote.js.map +1 -0
  72. package/dist/converge/delivery-reconciliation.d.ts +17 -0
  73. package/dist/converge/delivery-reconciliation.js +53 -0
  74. package/dist/converge/delivery-reconciliation.js.map +1 -0
  75. package/dist/converge/finding-identity.d.ts +6 -0
  76. package/dist/converge/finding-identity.js +7 -0
  77. package/dist/converge/finding-identity.js.map +1 -0
  78. package/dist/converge/fresh-review.d.ts +37 -0
  79. package/dist/converge/fresh-review.js +351 -0
  80. package/dist/converge/fresh-review.js.map +1 -0
  81. package/dist/converge/launch-guard.d.ts +55 -0
  82. package/dist/converge/launch-guard.js +363 -0
  83. package/dist/converge/launch-guard.js.map +1 -0
  84. package/dist/converge/launch-preflight.d.ts +5 -0
  85. package/dist/converge/launch-preflight.js +41 -0
  86. package/dist/converge/launch-preflight.js.map +1 -0
  87. package/dist/converge/launch-record.d.ts +136 -0
  88. package/dist/converge/launch-record.js +86 -0
  89. package/dist/converge/launch-record.js.map +1 -0
  90. package/dist/converge/legacy-launch-health.d.ts +311 -0
  91. package/dist/converge/legacy-launch-health.js +159 -0
  92. package/dist/converge/legacy-launch-health.js.map +1 -0
  93. package/dist/converge/legacy-roster.d.ts +29 -0
  94. package/dist/converge/legacy-roster.js +268 -0
  95. package/dist/converge/legacy-roster.js.map +1 -0
  96. package/dist/converge/native-lock.d.ts +18 -0
  97. package/dist/converge/native-lock.js +122 -0
  98. package/dist/converge/native-lock.js.map +1 -0
  99. package/dist/converge/ordinary-pending-export.d.ts +67 -0
  100. package/dist/converge/ordinary-pending-export.js +175 -0
  101. package/dist/converge/ordinary-pending-export.js.map +1 -0
  102. package/dist/converge/ordinary-pending-package.d.ts +28 -0
  103. package/dist/converge/ordinary-pending-package.js +36 -0
  104. package/dist/converge/ordinary-pending-package.js.map +1 -0
  105. package/dist/converge/pending-legacy-resume.d.ts +119 -0
  106. package/dist/converge/pending-legacy-resume.js +720 -0
  107. package/dist/converge/pending-legacy-resume.js.map +1 -0
  108. package/dist/converge/pending-recovery-source.d.ts +131 -0
  109. package/dist/converge/pending-recovery-source.js +71 -0
  110. package/dist/converge/pending-recovery-source.js.map +1 -0
  111. package/dist/converge/recovery-launch.d.ts +66 -0
  112. package/dist/converge/recovery-launch.js +518 -0
  113. package/dist/converge/recovery-launch.js.map +1 -0
  114. package/dist/converge/retained-report.d.ts +29 -0
  115. package/dist/converge/retained-report.js +218 -0
  116. package/dist/converge/retained-report.js.map +1 -0
  117. package/dist/converge/retry-source.d.ts +25 -0
  118. package/dist/converge/retry-source.js +13 -0
  119. package/dist/converge/retry-source.js.map +1 -0
  120. package/dist/converge/review-cycle.d.ts +49 -0
  121. package/dist/converge/review-cycle.js +26 -0
  122. package/dist/converge/review-cycle.js.map +1 -0
  123. package/dist/converge/round-gap-schema.d.ts +66 -0
  124. package/dist/converge/round-gap-schema.js +51 -0
  125. package/dist/converge/round-gap-schema.js.map +1 -0
  126. package/dist/converge/round-gap.d.ts +38 -0
  127. package/dist/converge/round-gap.js +334 -0
  128. package/dist/converge/round-gap.js.map +1 -0
  129. package/dist/converge/run-state.d.ts +224 -0
  130. package/dist/converge/run-state.js +564 -0
  131. package/dist/converge/run-state.js.map +1 -0
  132. package/dist/converge/stale-report-schema.d.ts +42 -0
  133. package/dist/converge/stale-report-schema.js +79 -0
  134. package/dist/converge/stale-report-schema.js.map +1 -0
  135. package/dist/converge/stale-report-storage.d.ts +47 -0
  136. package/dist/converge/stale-report-storage.js +172 -0
  137. package/dist/converge/stale-report-storage.js.map +1 -0
  138. package/dist/converge/stale-report.d.ts +14 -0
  139. package/dist/converge/stale-report.js +213 -0
  140. package/dist/converge/stale-report.js.map +1 -0
  141. package/dist/converge/target-ownership.d.ts +29 -0
  142. package/dist/converge/target-ownership.js +95 -0
  143. package/dist/converge/target-ownership.js.map +1 -0
  144. package/dist/converge/terminal-rejection-schema.d.ts +42 -0
  145. package/dist/converge/terminal-rejection-schema.js +39 -0
  146. package/dist/converge/terminal-rejection-schema.js.map +1 -0
  147. package/dist/converge/terminal-rejection.d.ts +13 -0
  148. package/dist/converge/terminal-rejection.js +275 -0
  149. package/dist/converge/terminal-rejection.js.map +1 -0
  150. package/dist/coordination/registry-lock.d.ts +82 -0
  151. package/dist/coordination/registry-lock.js +498 -0
  152. package/dist/coordination/registry-lock.js.map +1 -0
  153. package/dist/discuss.d.ts +53 -0
  154. package/dist/discuss.js +112 -0
  155. package/dist/discuss.js.map +1 -0
  156. package/dist/dispatch/adapter.d.ts +32 -0
  157. package/dist/dispatch/adapter.js +2 -0
  158. package/dist/dispatch/adapter.js.map +1 -0
  159. package/dist/dispatch/anthropic.d.ts +10 -0
  160. package/dist/dispatch/anthropic.js +235 -0
  161. package/dist/dispatch/anthropic.js.map +1 -0
  162. package/dist/dispatch/async-lane.d.ts +127 -0
  163. package/dist/dispatch/async-lane.js +414 -0
  164. package/dist/dispatch/async-lane.js.map +1 -0
  165. package/dist/dispatch/capture-council.d.ts +63 -0
  166. package/dist/dispatch/capture-council.js +137 -0
  167. package/dist/dispatch/capture-council.js.map +1 -0
  168. package/dist/dispatch/captured-async.d.ts +67 -0
  169. package/dist/dispatch/captured-async.js +40 -0
  170. package/dist/dispatch/captured-async.js.map +1 -0
  171. package/dist/dispatch/captured-inputs.d.ts +50 -0
  172. package/dist/dispatch/captured-inputs.js +190 -0
  173. package/dist/dispatch/captured-inputs.js.map +1 -0
  174. package/dist/dispatch/checkpoint-async-context.d.ts +27 -0
  175. package/dist/dispatch/checkpoint-async-context.js +51 -0
  176. package/dist/dispatch/checkpoint-async-context.js.map +1 -0
  177. package/dist/dispatch/checkpoint-async-execution.d.ts +22 -0
  178. package/dist/dispatch/checkpoint-async-execution.js +130 -0
  179. package/dist/dispatch/checkpoint-async-execution.js.map +1 -0
  180. package/dist/dispatch/checkpoint-async-store.d.ts +134 -0
  181. package/dist/dispatch/checkpoint-async-store.js +534 -0
  182. package/dist/dispatch/checkpoint-async-store.js.map +1 -0
  183. package/dist/dispatch/checkpoint-async-unknown.d.ts +19 -0
  184. package/dist/dispatch/checkpoint-async-unknown.js +46 -0
  185. package/dist/dispatch/checkpoint-async-unknown.js.map +1 -0
  186. package/dist/dispatch/checkpoint-async.d.ts +252 -0
  187. package/dist/dispatch/checkpoint-async.js +270 -0
  188. package/dist/dispatch/checkpoint-async.js.map +1 -0
  189. package/dist/dispatch/checkpoint-gating-execution.d.ts +26 -0
  190. package/dist/dispatch/checkpoint-gating-execution.js +84 -0
  191. package/dist/dispatch/checkpoint-gating-execution.js.map +1 -0
  192. package/dist/dispatch/checkpoint-phase-limits.d.ts +5 -0
  193. package/dist/dispatch/checkpoint-phase-limits.js +11 -0
  194. package/dist/dispatch/checkpoint-phase-limits.js.map +1 -0
  195. package/dist/dispatch/checkpoint-verification-context.d.ts +15 -0
  196. package/dist/dispatch/checkpoint-verification-context.js +48 -0
  197. package/dist/dispatch/checkpoint-verification-context.js.map +1 -0
  198. package/dist/dispatch/checkpoint-verification.d.ts +213 -0
  199. package/dist/dispatch/checkpoint-verification.js +381 -0
  200. package/dist/dispatch/checkpoint-verification.js.map +1 -0
  201. package/dist/dispatch/checkpoint.d.ts +329 -0
  202. package/dist/dispatch/checkpoint.js +1418 -0
  203. package/dist/dispatch/checkpoint.js.map +1 -0
  204. package/dist/dispatch/google.d.ts +10 -0
  205. package/dist/dispatch/google.js +158 -0
  206. package/dist/dispatch/google.js.map +1 -0
  207. package/dist/dispatch/late-audit.d.ts +23 -0
  208. package/dist/dispatch/late-audit.js +133 -0
  209. package/dist/dispatch/late-audit.js.map +1 -0
  210. package/dist/dispatch/merge.d.ts +29 -0
  211. package/dist/dispatch/merge.js +112 -0
  212. package/dist/dispatch/merge.js.map +1 -0
  213. package/dist/dispatch/openai-compat.d.ts +30 -0
  214. package/dist/dispatch/openai-compat.js +166 -0
  215. package/dist/dispatch/openai-compat.js.map +1 -0
  216. package/dist/dispatch/openai.d.ts +10 -0
  217. package/dist/dispatch/openai.js +159 -0
  218. package/dist/dispatch/openai.js.map +1 -0
  219. package/dist/dispatch/original-execution.d.ts +30 -0
  220. package/dist/dispatch/original-execution.js +91 -0
  221. package/dist/dispatch/original-execution.js.map +1 -0
  222. package/dist/dispatch/original-launch.d.ts +37 -0
  223. package/dist/dispatch/original-launch.js +117 -0
  224. package/dist/dispatch/original-launch.js.map +1 -0
  225. package/dist/dispatch/quorum.d.ts +15 -0
  226. package/dist/dispatch/quorum.js +33 -0
  227. package/dist/dispatch/quorum.js.map +1 -0
  228. package/dist/dispatch/recovery-operation.d.ts +44 -0
  229. package/dist/dispatch/recovery-operation.js +146 -0
  230. package/dist/dispatch/recovery-operation.js.map +1 -0
  231. package/dist/dispatch/recovery-policy.d.ts +54 -0
  232. package/dist/dispatch/recovery-policy.js +157 -0
  233. package/dist/dispatch/recovery-policy.js.map +1 -0
  234. package/dist/dispatch/recovery.d.ts +78 -0
  235. package/dist/dispatch/recovery.js +299 -0
  236. package/dist/dispatch/recovery.js.map +1 -0
  237. package/dist/dispatch/retained-async.d.ts +13 -0
  238. package/dist/dispatch/retained-async.js +101 -0
  239. package/dist/dispatch/retained-async.js.map +1 -0
  240. package/dist/dispatch/reviewer-identity.d.ts +10 -0
  241. package/dist/dispatch/reviewer-identity.js +19 -0
  242. package/dist/dispatch/reviewer-identity.js.map +1 -0
  243. package/dist/dispatch/runner.d.ts +76 -0
  244. package/dist/dispatch/runner.js +415 -0
  245. package/dist/dispatch/runner.js.map +1 -0
  246. package/dist/dispatch/utils.d.ts +159 -0
  247. package/dist/dispatch/utils.js +381 -0
  248. package/dist/dispatch/utils.js.map +1 -0
  249. package/dist/dispatch/verification-execution.d.ts +48 -0
  250. package/dist/dispatch/verification-execution.js +252 -0
  251. package/dist/dispatch/verification-execution.js.map +1 -0
  252. package/dist/dispatch/verification-late-audit.d.ts +17 -0
  253. package/dist/dispatch/verification-late-audit.js +117 -0
  254. package/dist/dispatch/verification-late-audit.js.map +1 -0
  255. package/dist/evidence/claim-recovery/authenticated-carrier-projection.d.ts +30 -0
  256. package/dist/evidence/claim-recovery/authenticated-carrier-projection.js +100 -0
  257. package/dist/evidence/claim-recovery/authenticated-carrier-projection.js.map +1 -0
  258. package/dist/evidence/claim-recovery/authenticated-receipts.d.ts +46 -0
  259. package/dist/evidence/claim-recovery/authenticated-receipts.js +120 -0
  260. package/dist/evidence/claim-recovery/authenticated-receipts.js.map +1 -0
  261. package/dist/evidence/claim-recovery/carrier-inventory.d.ts +49 -0
  262. package/dist/evidence/claim-recovery/carrier-inventory.js +340 -0
  263. package/dist/evidence/claim-recovery/carrier-inventory.js.map +1 -0
  264. package/dist/evidence/claim-recovery/claim-index.d.ts +12 -0
  265. package/dist/evidence/claim-recovery/claim-index.js +56 -0
  266. package/dist/evidence/claim-recovery/claim-index.js.map +1 -0
  267. package/dist/evidence/claim-recovery/confirmation.d.ts +53 -0
  268. package/dist/evidence/claim-recovery/confirmation.js +151 -0
  269. package/dist/evidence/claim-recovery/confirmation.js.map +1 -0
  270. package/dist/evidence/claim-recovery/context.d.ts +15 -0
  271. package/dist/evidence/claim-recovery/context.js +40 -0
  272. package/dist/evidence/claim-recovery/context.js.map +1 -0
  273. package/dist/evidence/claim-recovery/proof-storage.d.ts +6 -0
  274. package/dist/evidence/claim-recovery/proof-storage.js +97 -0
  275. package/dist/evidence/claim-recovery/proof-storage.js.map +1 -0
  276. package/dist/evidence/claim-recovery/validation/anchors.d.ts +20 -0
  277. package/dist/evidence/claim-recovery/validation/anchors.js +22 -0
  278. package/dist/evidence/claim-recovery/validation/anchors.js.map +1 -0
  279. package/dist/evidence/claim-recovery/validation/carrier-projection.d.ts +9 -0
  280. package/dist/evidence/claim-recovery/validation/carrier-projection.js +364 -0
  281. package/dist/evidence/claim-recovery/validation/carrier-projection.js.map +1 -0
  282. package/dist/evidence/claim-recovery/validation/carrier-types.d.ts +83 -0
  283. package/dist/evidence/claim-recovery/validation/carrier-types.js +2 -0
  284. package/dist/evidence/claim-recovery/validation/carrier-types.js.map +1 -0
  285. package/dist/evidence/claim-recovery/validation/claim-split.d.ts +57 -0
  286. package/dist/evidence/claim-recovery/validation/claim-split.js +209 -0
  287. package/dist/evidence/claim-recovery/validation/claim-split.js.map +1 -0
  288. package/dist/evidence/claim-recovery/validation/claims.d.ts +20 -0
  289. package/dist/evidence/claim-recovery/validation/claims.js +108 -0
  290. package/dist/evidence/claim-recovery/validation/claims.js.map +1 -0
  291. package/dist/evidence/claim-recovery/validation/current-projection.d.ts +36 -0
  292. package/dist/evidence/claim-recovery/validation/current-projection.js +424 -0
  293. package/dist/evidence/claim-recovery/validation/current-projection.js.map +1 -0
  294. package/dist/evidence/claim-recovery/validation/lexical.d.ts +18 -0
  295. package/dist/evidence/claim-recovery/validation/lexical.js +91 -0
  296. package/dist/evidence/claim-recovery/validation/lexical.js.map +1 -0
  297. package/dist/evidence/claim-recovery/validation/materials.d.ts +19 -0
  298. package/dist/evidence/claim-recovery/validation/materials.js +160 -0
  299. package/dist/evidence/claim-recovery/validation/materials.js.map +1 -0
  300. package/dist/evidence/claim-recovery/validation/native-material.d.ts +27 -0
  301. package/dist/evidence/claim-recovery/validation/native-material.js +35 -0
  302. package/dist/evidence/claim-recovery/validation/native-material.js.map +1 -0
  303. package/dist/evidence/claim-recovery/validation/native-occurrences.d.ts +79 -0
  304. package/dist/evidence/claim-recovery/validation/native-occurrences.js +187 -0
  305. package/dist/evidence/claim-recovery/validation/native-occurrences.js.map +1 -0
  306. package/dist/evidence/claim-recovery/validation/native-state.d.ts +45 -0
  307. package/dist/evidence/claim-recovery/validation/native-state.js +385 -0
  308. package/dist/evidence/claim-recovery/validation/native-state.js.map +1 -0
  309. package/dist/evidence/claim-recovery/validation/obligations.d.ts +15 -0
  310. package/dist/evidence/claim-recovery/validation/obligations.js +65 -0
  311. package/dist/evidence/claim-recovery/validation/obligations.js.map +1 -0
  312. package/dist/evidence/claim-recovery/validation/occurrence-source.d.ts +45 -0
  313. package/dist/evidence/claim-recovery/validation/occurrence-source.js +208 -0
  314. package/dist/evidence/claim-recovery/validation/occurrence-source.js.map +1 -0
  315. package/dist/evidence/claim-recovery/validation/occurrence-types.d.ts +101 -0
  316. package/dist/evidence/claim-recovery/validation/occurrence-types.js +2 -0
  317. package/dist/evidence/claim-recovery/validation/occurrence-types.js.map +1 -0
  318. package/dist/evidence/claim-recovery/validation/occurrence.d.ts +30 -0
  319. package/dist/evidence/claim-recovery/validation/occurrence.js +227 -0
  320. package/dist/evidence/claim-recovery/validation/occurrence.js.map +1 -0
  321. package/dist/evidence/claim-recovery/validation/primitives.d.ts +11 -0
  322. package/dist/evidence/claim-recovery/validation/primitives.js +41 -0
  323. package/dist/evidence/claim-recovery/validation/primitives.js.map +1 -0
  324. package/dist/evidence/claim-recovery/validation/receipts.d.ts +37 -0
  325. package/dist/evidence/claim-recovery/validation/receipts.js +83 -0
  326. package/dist/evidence/claim-recovery/validation/receipts.js.map +1 -0
  327. package/dist/evidence/claim-recovery/validation/recovery-json.d.ts +8 -0
  328. package/dist/evidence/claim-recovery/validation/recovery-json.js +42 -0
  329. package/dist/evidence/claim-recovery/validation/recovery-json.js.map +1 -0
  330. package/dist/evidence/claim-recovery/validation/semantic-cache.d.ts +3 -0
  331. package/dist/evidence/claim-recovery/validation/semantic-cache.js +22 -0
  332. package/dist/evidence/claim-recovery/validation/semantic-cache.js.map +1 -0
  333. package/dist/evidence/claim-recovery/validation/semantic-validation.d.ts +9 -0
  334. package/dist/evidence/claim-recovery/validation/semantic-validation.js +347 -0
  335. package/dist/evidence/claim-recovery/validation/semantic-validation.js.map +1 -0
  336. package/dist/evidence/claim-recovery/validation/sighting.d.ts +2 -0
  337. package/dist/evidence/claim-recovery/validation/sighting.js +15 -0
  338. package/dist/evidence/claim-recovery/validation/sighting.js.map +1 -0
  339. package/dist/evidence/claim-recovery/validation/sources.d.ts +15 -0
  340. package/dist/evidence/claim-recovery/validation/sources.js +2 -0
  341. package/dist/evidence/claim-recovery/validation/sources.js.map +1 -0
  342. package/dist/evidence/claim-recovery/validation/types.d.ts +126 -0
  343. package/dist/evidence/claim-recovery/validation/types.js +2 -0
  344. package/dist/evidence/claim-recovery/validation/types.js.map +1 -0
  345. package/dist/evidence/claim-split.d.ts +1 -0
  346. package/dist/evidence/claim-split.js +2 -0
  347. package/dist/evidence/claim-split.js.map +1 -0
  348. package/dist/evidence/event-receipts.d.ts +16 -0
  349. package/dist/evidence/event-receipts.js +41 -0
  350. package/dist/evidence/event-receipts.js.map +1 -0
  351. package/dist/evidence/finding-recovery.d.ts +23 -0
  352. package/dist/evidence/finding-recovery.js +74 -0
  353. package/dist/evidence/finding-recovery.js.map +1 -0
  354. package/dist/evidence/finding-retriage.d.ts +14 -0
  355. package/dist/evidence/finding-retriage.js +57 -0
  356. package/dist/evidence/finding-retriage.js.map +1 -0
  357. package/dist/evidence/format.d.ts +18 -0
  358. package/dist/evidence/format.js +152 -0
  359. package/dist/evidence/format.js.map +1 -0
  360. package/dist/evidence/original-run/decode.d.ts +30 -0
  361. package/dist/evidence/original-run/decode.js +208 -0
  362. package/dist/evidence/original-run/decode.js.map +1 -0
  363. package/dist/evidence/original-run/journal.d.ts +31 -0
  364. package/dist/evidence/original-run/journal.js +157 -0
  365. package/dist/evidence/original-run/journal.js.map +1 -0
  366. package/dist/evidence/original-run/lock-path.d.ts +17 -0
  367. package/dist/evidence/original-run/lock-path.js +116 -0
  368. package/dist/evidence/original-run/lock-path.js.map +1 -0
  369. package/dist/evidence/original-run/lock-scope.d.ts +21 -0
  370. package/dist/evidence/original-run/lock-scope.js +61 -0
  371. package/dist/evidence/original-run/lock-scope.js.map +1 -0
  372. package/dist/evidence/original-run/lock.d.ts +33 -0
  373. package/dist/evidence/original-run/lock.js +259 -0
  374. package/dist/evidence/original-run/lock.js.map +1 -0
  375. package/dist/evidence/original-run/remote.d.ts +23 -0
  376. package/dist/evidence/original-run/remote.js +110 -0
  377. package/dist/evidence/original-run/remote.js.map +1 -0
  378. package/dist/evidence/original-run/source.d.ts +61 -0
  379. package/dist/evidence/original-run/source.js +267 -0
  380. package/dist/evidence/original-run/source.js.map +1 -0
  381. package/dist/evidence/reads.d.ts +11 -0
  382. package/dist/evidence/reads.js +16 -0
  383. package/dist/evidence/reads.js.map +1 -0
  384. package/dist/evidence/recover-finding.d.ts +17 -0
  385. package/dist/evidence/recover-finding.js +65 -0
  386. package/dist/evidence/recover-finding.js.map +1 -0
  387. package/dist/evidence/recover-run.d.ts +26 -0
  388. package/dist/evidence/recover-run.js +180 -0
  389. package/dist/evidence/recover-run.js.map +1 -0
  390. package/dist/evidence/retained-time-budget.d.ts +9 -0
  391. package/dist/evidence/retained-time-budget.js +14 -0
  392. package/dist/evidence/retained-time-budget.js.map +1 -0
  393. package/dist/evidence/retriage-finding.d.ts +12 -0
  394. package/dist/evidence/retriage-finding.js +67 -0
  395. package/dist/evidence/retriage-finding.js.map +1 -0
  396. package/dist/evidence/reviewer-lineage.d.ts +35 -0
  397. package/dist/evidence/reviewer-lineage.js +293 -0
  398. package/dist/evidence/reviewer-lineage.js.map +1 -0
  399. package/dist/evidence/reviewer-original.d.ts +67 -0
  400. package/dist/evidence/reviewer-original.js +148 -0
  401. package/dist/evidence/reviewer-original.js.map +1 -0
  402. package/dist/evidence/reviewer-recovery.d.ts +74 -0
  403. package/dist/evidence/reviewer-recovery.js +179 -0
  404. package/dist/evidence/reviewer-recovery.js.map +1 -0
  405. package/dist/evidence/reviewer-status.d.ts +145 -0
  406. package/dist/evidence/reviewer-status.js +302 -0
  407. package/dist/evidence/reviewer-status.js.map +1 -0
  408. package/dist/evidence/show.d.ts +10 -0
  409. package/dist/evidence/show.js +41 -0
  410. package/dist/evidence/show.js.map +1 -0
  411. package/dist/evidence/status.d.ts +38 -0
  412. package/dist/evidence/status.js +73 -0
  413. package/dist/evidence/status.js.map +1 -0
  414. package/dist/evidence/target.d.ts +17 -0
  415. package/dist/evidence/target.js +74 -0
  416. package/dist/evidence/target.js.map +1 -0
  417. package/dist/evidence/types.d.ts +176 -0
  418. package/dist/evidence/types.js +109 -0
  419. package/dist/evidence/types.js.map +1 -0
  420. package/dist/index.d.ts +2 -0
  421. package/dist/index.js +2688 -0
  422. package/dist/index.js.map +1 -0
  423. package/dist/models/seed.d.ts +44 -0
  424. package/dist/models/seed.js +175 -0
  425. package/dist/models/seed.js.map +1 -0
  426. package/dist/models/server-stats.d.ts +80 -0
  427. package/dist/models/server-stats.js +109 -0
  428. package/dist/models/server-stats.js.map +1 -0
  429. package/dist/models/stats-store.d.ts +84 -0
  430. package/dist/models/stats-store.js +572 -0
  431. package/dist/models/stats-store.js.map +1 -0
  432. package/dist/output/artifacts.d.ts +16 -0
  433. package/dist/output/artifacts.js +29 -0
  434. package/dist/output/artifacts.js.map +1 -0
  435. package/dist/output/assembly-refusal.d.ts +8 -0
  436. package/dist/output/assembly-refusal.js +14 -0
  437. package/dist/output/assembly-refusal.js.map +1 -0
  438. package/dist/output/github.d.ts +12 -0
  439. package/dist/output/github.js +214 -0
  440. package/dist/output/github.js.map +1 -0
  441. package/dist/output/json.d.ts +3 -0
  442. package/dist/output/json.js +8 -0
  443. package/dist/output/json.js.map +1 -0
  444. package/dist/output/markdown.d.ts +3 -0
  445. package/dist/output/markdown.js +281 -0
  446. package/dist/output/markdown.js.map +1 -0
  447. package/dist/output/progress.d.ts +55 -0
  448. package/dist/output/progress.js +180 -0
  449. package/dist/output/progress.js.map +1 -0
  450. package/dist/output/sanitize.d.ts +18 -0
  451. package/dist/output/sanitize.js +46 -0
  452. package/dist/output/sanitize.js.map +1 -0
  453. package/dist/output/terminal.d.ts +2 -0
  454. package/dist/output/terminal.js +172 -0
  455. package/dist/output/terminal.js.map +1 -0
  456. package/dist/prepare/chunker.d.ts +18 -0
  457. package/dist/prepare/chunker.js +325 -0
  458. package/dist/prepare/chunker.js.map +1 -0
  459. package/dist/prepare/language.d.ts +1 -0
  460. package/dist/prepare/language.js +99 -0
  461. package/dist/prepare/language.js.map +1 -0
  462. package/dist/prepare/prompt-builder.d.ts +44 -0
  463. package/dist/prepare/prompt-builder.js +102 -0
  464. package/dist/prepare/prompt-builder.js.map +1 -0
  465. package/dist/prepare/unified-diff.d.ts +40 -0
  466. package/dist/prepare/unified-diff.js +135 -0
  467. package/dist/prepare/unified-diff.js.map +1 -0
  468. package/dist/prompts/base.d.ts +3 -0
  469. package/dist/prompts/base.js +53 -0
  470. package/dist/prompts/base.js.map +1 -0
  471. package/dist/prompts/hardening.d.ts +19 -0
  472. package/dist/prompts/hardening.js +67 -0
  473. package/dist/prompts/hardening.js.map +1 -0
  474. package/dist/prompts/languages/elixir.d.ts +1 -0
  475. package/dist/prompts/languages/elixir.js +13 -0
  476. package/dist/prompts/languages/elixir.js.map +1 -0
  477. package/dist/prompts/languages/generic.d.ts +1 -0
  478. package/dist/prompts/languages/generic.js +11 -0
  479. package/dist/prompts/languages/generic.js.map +1 -0
  480. package/dist/prompts/languages/python.d.ts +1 -0
  481. package/dist/prompts/languages/python.js +14 -0
  482. package/dist/prompts/languages/python.js.map +1 -0
  483. package/dist/prompts/languages/typescript.d.ts +1 -0
  484. package/dist/prompts/languages/typescript.js +13 -0
  485. package/dist/prompts/languages/typescript.js.map +1 -0
  486. package/dist/prompts/plan.d.ts +15 -0
  487. package/dist/prompts/plan.js +55 -0
  488. package/dist/prompts/plan.js.map +1 -0
  489. package/dist/report/aggregation-inputs.d.ts +52 -0
  490. package/dist/report/aggregation-inputs.js +114 -0
  491. package/dist/report/aggregation-inputs.js.map +1 -0
  492. package/dist/report/assembly.d.ts +43 -0
  493. package/dist/report/assembly.js +133 -0
  494. package/dist/report/assembly.js.map +1 -0
  495. package/dist/report/blocking-health.d.ts +64 -0
  496. package/dist/report/blocking-health.js +156 -0
  497. package/dist/report/blocking-health.js.map +1 -0
  498. package/dist/report/checkpoint-assembly.d.ts +10 -0
  499. package/dist/report/checkpoint-assembly.js +17 -0
  500. package/dist/report/checkpoint-assembly.js.map +1 -0
  501. package/dist/report/checkpoint-consensus.d.ts +59 -0
  502. package/dist/report/checkpoint-consensus.js +197 -0
  503. package/dist/report/checkpoint-consensus.js.map +1 -0
  504. package/dist/report/checkpoint-gating.d.ts +36 -0
  505. package/dist/report/checkpoint-gating.js +110 -0
  506. package/dist/report/checkpoint-gating.js.map +1 -0
  507. package/dist/report/checkpoint-projection.d.ts +76 -0
  508. package/dist/report/checkpoint-projection.js +122 -0
  509. package/dist/report/checkpoint-projection.js.map +1 -0
  510. package/dist/report/consensus-assembly.d.ts +37 -0
  511. package/dist/report/consensus-assembly.js +33 -0
  512. package/dist/report/consensus-assembly.js.map +1 -0
  513. package/dist/report/recovery-source.d.ts +7 -0
  514. package/dist/report/recovery-source.js +7 -0
  515. package/dist/report/recovery-source.js.map +1 -0
  516. package/dist/report/reviewer-artifact.d.ts +118 -0
  517. package/dist/report/reviewer-artifact.js +381 -0
  518. package/dist/report/reviewer-artifact.js.map +1 -0
  519. package/dist/report/reviewer-evidence-schema.d.ts +42 -0
  520. package/dist/report/reviewer-evidence-schema.js +28 -0
  521. package/dist/report/reviewer-evidence-schema.js.map +1 -0
  522. package/dist/report/reviewer-evidence.d.ts +54 -0
  523. package/dist/report/reviewer-evidence.js +229 -0
  524. package/dist/report/reviewer-evidence.js.map +1 -0
  525. package/dist/report/reviewer-health.d.ts +62 -0
  526. package/dist/report/reviewer-health.js +105 -0
  527. package/dist/report/reviewer-health.js.map +1 -0
  528. package/dist/report/run-header.d.ts +219 -0
  529. package/dist/report/run-header.js +307 -0
  530. package/dist/report/run-header.js.map +1 -0
  531. package/dist/report/supplemental-async.d.ts +19 -0
  532. package/dist/report/supplemental-async.js +85 -0
  533. package/dist/report/supplemental-async.js.map +1 -0
  534. package/dist/report/uuid.d.ts +16 -0
  535. package/dist/report/uuid.js +41 -0
  536. package/dist/report/uuid.js.map +1 -0
  537. package/dist/resolver/git.d.ts +16 -0
  538. package/dist/resolver/git.js +77 -0
  539. package/dist/resolver/git.js.map +1 -0
  540. package/dist/resolver/github-client.d.ts +82 -0
  541. package/dist/resolver/github-client.js +27 -0
  542. package/dist/resolver/github-client.js.map +1 -0
  543. package/dist/resolver/github.d.ts +29 -0
  544. package/dist/resolver/github.js +166 -0
  545. package/dist/resolver/github.js.map +1 -0
  546. package/dist/resolver/local.d.ts +3 -0
  547. package/dist/resolver/local.js +75 -0
  548. package/dist/resolver/local.js.map +1 -0
  549. package/dist/resolver/plan.d.ts +8 -0
  550. package/dist/resolver/plan.js +44 -0
  551. package/dist/resolver/plan.js.map +1 -0
  552. package/dist/resolver/target.d.ts +35 -0
  553. package/dist/resolver/target.js +112 -0
  554. package/dist/resolver/target.js.map +1 -0
  555. package/dist/resolver/types.d.ts +43 -0
  556. package/dist/resolver/types.js +2 -0
  557. package/dist/resolver/types.js.map +1 -0
  558. package/dist/roles/builtin.d.ts +4 -0
  559. package/dist/roles/builtin.js +282 -0
  560. package/dist/roles/builtin.js.map +1 -0
  561. package/dist/roles/dispatcher.d.ts +26 -0
  562. package/dist/roles/dispatcher.js +96 -0
  563. package/dist/roles/dispatcher.js.map +1 -0
  564. package/dist/roles/legacy-4.1.10.d.ts +2 -0
  565. package/dist/roles/legacy-4.1.10.js +320 -0
  566. package/dist/roles/legacy-4.1.10.js.map +1 -0
  567. package/dist/roles/legacy-4.4.9.d.ts +4 -0
  568. package/dist/roles/legacy-4.4.9.js +282 -0
  569. package/dist/roles/legacy-4.4.9.js.map +1 -0
  570. package/dist/roles/loader.d.ts +10 -0
  571. package/dist/roles/loader.js +104 -0
  572. package/dist/roles/loader.js.map +1 -0
  573. package/dist/roles/types.d.ts +13 -0
  574. package/dist/roles/types.js +2 -0
  575. package/dist/roles/types.js.map +1 -0
  576. package/dist/telemetry/abort-signal.d.ts +13 -0
  577. package/dist/telemetry/abort-signal.js +40 -0
  578. package/dist/telemetry/abort-signal.js.map +1 -0
  579. package/dist/telemetry/attest.d.ts +98 -0
  580. package/dist/telemetry/attest.js +331 -0
  581. package/dist/telemetry/attest.js.map +1 -0
  582. package/dist/telemetry/attested-retry.d.ts +79 -0
  583. package/dist/telemetry/attested-retry.js +195 -0
  584. package/dist/telemetry/attested-retry.js.map +1 -0
  585. package/dist/telemetry/attested-reviewer-delivery.d.ts +58 -0
  586. package/dist/telemetry/attested-reviewer-delivery.js +238 -0
  587. package/dist/telemetry/attested-reviewer-delivery.js.map +1 -0
  588. package/dist/telemetry/backfill.d.ts +95 -0
  589. package/dist/telemetry/backfill.js +460 -0
  590. package/dist/telemetry/backfill.js.map +1 -0
  591. package/dist/telemetry/credentials.d.ts +44 -0
  592. package/dist/telemetry/credentials.js +87 -0
  593. package/dist/telemetry/credentials.js.map +1 -0
  594. package/dist/telemetry/deliver.d.ts +152 -0
  595. package/dist/telemetry/deliver.js +662 -0
  596. package/dist/telemetry/deliver.js.map +1 -0
  597. package/dist/telemetry/envelope-validation.d.ts +13 -0
  598. package/dist/telemetry/envelope-validation.js +196 -0
  599. package/dist/telemetry/envelope-validation.js.map +1 -0
  600. package/dist/telemetry/envelope.d.ts +159 -0
  601. package/dist/telemetry/envelope.js +288 -0
  602. package/dist/telemetry/envelope.js.map +1 -0
  603. package/dist/telemetry/events.d.ts +68 -0
  604. package/dist/telemetry/events.js +79 -0
  605. package/dist/telemetry/events.js.map +1 -0
  606. package/dist/telemetry/notice.d.ts +15 -0
  607. package/dist/telemetry/notice.js +67 -0
  608. package/dist/telemetry/notice.js.map +1 -0
  609. package/dist/telemetry/outbox.d.ts +166 -0
  610. package/dist/telemetry/outbox.js +741 -0
  611. package/dist/telemetry/outbox.js.map +1 -0
  612. package/dist/telemetry/quarantine.d.ts +105 -0
  613. package/dist/telemetry/quarantine.js +224 -0
  614. package/dist/telemetry/quarantine.js.map +1 -0
  615. package/dist/telemetry/read-sink.d.ts +31 -0
  616. package/dist/telemetry/read-sink.js +25 -0
  617. package/dist/telemetry/read-sink.js.map +1 -0
  618. package/dist/telemetry/recovery/command.d.ts +16 -0
  619. package/dist/telemetry/recovery/command.js +70 -0
  620. package/dist/telemetry/recovery/command.js.map +1 -0
  621. package/dist/telemetry/recovery/discovery.d.ts +8 -0
  622. package/dist/telemetry/recovery/discovery.js +277 -0
  623. package/dist/telemetry/recovery/discovery.js.map +1 -0
  624. package/dist/telemetry/recovery/files.d.ts +20 -0
  625. package/dist/telemetry/recovery/files.js +123 -0
  626. package/dist/telemetry/recovery/files.js.map +1 -0
  627. package/dist/telemetry/recovery/plan.d.ts +10 -0
  628. package/dist/telemetry/recovery/plan.js +325 -0
  629. package/dist/telemetry/recovery/plan.js.map +1 -0
  630. package/dist/telemetry/recovery/source.d.ts +328 -0
  631. package/dist/telemetry/recovery/source.js +253 -0
  632. package/dist/telemetry/recovery/source.js.map +1 -0
  633. package/dist/telemetry/recovery/types.d.ts +100 -0
  634. package/dist/telemetry/recovery/types.js +2 -0
  635. package/dist/telemetry/recovery/types.js.map +1 -0
  636. package/dist/telemetry/recovery-request-budget.d.ts +39 -0
  637. package/dist/telemetry/recovery-request-budget.js +102 -0
  638. package/dist/telemetry/recovery-request-budget.js.map +1 -0
  639. package/dist/telemetry/report-consistency.d.ts +11 -0
  640. package/dist/telemetry/report-consistency.js +111 -0
  641. package/dist/telemetry/report-consistency.js.map +1 -0
  642. package/dist/telemetry/reviewer-delivery.d.ts +39 -0
  643. package/dist/telemetry/reviewer-delivery.js +279 -0
  644. package/dist/telemetry/reviewer-delivery.js.map +1 -0
  645. package/dist/telemetry/reviewer-preflight.d.ts +13 -0
  646. package/dist/telemetry/reviewer-preflight.js +56 -0
  647. package/dist/telemetry/reviewer-preflight.js.map +1 -0
  648. package/dist/telemetry/scrub.d.ts +53 -0
  649. package/dist/telemetry/scrub.js +205 -0
  650. package/dist/telemetry/scrub.js.map +1 -0
  651. package/dist/telemetry/sink.d.ts +212 -0
  652. package/dist/telemetry/sink.js +813 -0
  653. package/dist/telemetry/sink.js.map +1 -0
  654. package/dist/telemetry/terminal-reviewer-delivery.d.ts +18 -0
  655. package/dist/telemetry/terminal-reviewer-delivery.js +27 -0
  656. package/dist/telemetry/terminal-reviewer-delivery.js.map +1 -0
  657. package/dist/telemetry/transient-input.d.ts +2 -0
  658. package/dist/telemetry/transient-input.js +37 -0
  659. package/dist/telemetry/transient-input.js.map +1 -0
  660. package/dist/telemetry/verification.d.ts +9 -0
  661. package/dist/telemetry/verification.js +12 -0
  662. package/dist/telemetry/verification.js.map +1 -0
  663. package/package.json +73 -0
@@ -0,0 +1,134 @@
1
+ import { type FrozenCheckpointPlan } from './checkpoint.js';
2
+ import { type SealedAsyncProof } from './checkpoint-async-context.js';
3
+ import { type NativeTargetOwnership } from '../converge/target-ownership.js';
4
+ import { type AsyncCall, type AsyncIntent, type AsyncPlan, type AsyncProof, type AsyncResult, type AsyncState } from './checkpoint-async.js';
5
+ interface LocationInput {
6
+ commonDir: string;
7
+ namespace: string;
8
+ plan: FrozenCheckpointPlan;
9
+ }
10
+ export interface InitializeAsyncInput extends LocationInput {
11
+ ownership: NativeTargetOwnership;
12
+ calls: readonly AsyncCall[];
13
+ maxPhysicalCalls: number;
14
+ maxAttemptsPerCall: number;
15
+ expiresAtMs: number;
16
+ }
17
+ export interface AsyncDelegate {
18
+ version: 1;
19
+ commonDir: string;
20
+ namespace: string;
21
+ target: string;
22
+ checkpointPath: string;
23
+ planDigest: string;
24
+ callIndex: number;
25
+ token: string;
26
+ }
27
+ export interface AsyncWriter {
28
+ claim(prompts: {
29
+ systemPrompt: string;
30
+ userPrompt: string;
31
+ }, afterIntent?: (intent: AsyncIntent) => {
32
+ reviewBytes: string;
33
+ } | void): Promise<AsyncIntent | undefined>;
34
+ recordResult(attemptId: string, reviewBytes: string): Promise<'observed' | 'late'>;
35
+ }
36
+ interface OpinionCycle {
37
+ version: 1;
38
+ cycleId: string | null;
39
+ }
40
+ export interface AsyncPhaseSnapshot {
41
+ plan: AsyncPlan;
42
+ state: AsyncState;
43
+ }
44
+ export type CheckpointAsyncExecutionState = {
45
+ kind: 'phase';
46
+ phase: AsyncPhaseSnapshot;
47
+ } | {
48
+ kind: 'unknown';
49
+ proof: SealedAsyncProof;
50
+ };
51
+ export interface AsyncLateRecord {
52
+ sequence: number;
53
+ previousDigest: string;
54
+ digest: string;
55
+ sealedProofSha256: string;
56
+ result: AsyncResult;
57
+ }
58
+ export interface AsyncLateFailure {
59
+ sequence: number;
60
+ kind: 'late_audit_failure';
61
+ callIndex: number;
62
+ attemptId: string;
63
+ digest: string;
64
+ }
65
+ /** Only initialization under live native ownership may create restricted per-call delegations. */
66
+ export declare function initializeAsyncPhase(input: InitializeAsyncInput): Promise<{
67
+ delegates: readonly AsyncDelegate[];
68
+ plan: AsyncPlan;
69
+ }>;
70
+ /** Delegates cannot mutate native state, reviewer history, phase plan, cutoff or another call. */
71
+ export declare function openAsyncDelegate(input: AsyncDelegate): Promise<AsyncWriter>;
72
+ /** Parent-only cutoff is atomic with all delegated intent/retry admission. */
73
+ export declare function sealAsyncPhase(input: LocationInput & {
74
+ ownership: NativeTargetOwnership;
75
+ }): Promise<AsyncProof>;
76
+ /** Structural local read; this does not authenticate capture matrix, producer or server authority. */
77
+ export declare function readAsyncPhase(input: LocationInput): Promise<AsyncPhaseSnapshot>;
78
+ /** Read the exact stored original-async evidence without creating or sealing state. */
79
+ export declare function inspectCheckpointAsyncExecution(input: LocationInput): Promise<CheckpointAsyncExecutionState | undefined>;
80
+ /** Read only terminal execution evidence; an open phase is deliberately not a proof. */
81
+ export declare function readCheckpointAsyncExecution(input: LocationInput): Promise<SealedAsyncProof | undefined>;
82
+ /**
83
+ * Seal a real phase or retain an explicit unknown outcome after a finalized,
84
+ * expired original launch. The unknown form never creates intents or claims
85
+ * that any captured async call did or did not dispatch.
86
+ */
87
+ export declare function resolveFinalizedAsyncExecution(input: LocationInput & {
88
+ ownership: NativeTargetOwnership;
89
+ nowMs?: () => number;
90
+ }): Promise<SealedAsyncProof | undefined>;
91
+ export declare function readAsyncLateAudit(input: LocationInput): Promise<readonly AsyncLateRecord[]>;
92
+ /** Record a bounded private diagnostic when a late result cannot be audited. */
93
+ export declare function recordAsyncLateFailure(input: AsyncDelegate, attemptId: string): Promise<void>;
94
+ /** Structural private diagnostic read; entries contain no provider error bytes. */
95
+ export declare function readAsyncLateFailures(input: LocationInput): Promise<readonly AsyncLateFailure[]>;
96
+ /** Authenticated restricted executor input, read only from the same journal and captured matrix. */
97
+ export declare function openCapturedAsyncDelegate(input: AsyncDelegate): Promise<{
98
+ writer: AsyncWriter;
99
+ plan: {
100
+ version: 1;
101
+ context: {
102
+ runId: string;
103
+ target: string;
104
+ planDigest: string;
105
+ capturedInputsSha256: string;
106
+ launchSha256: string;
107
+ startedAtMs: number;
108
+ expiresAtMs: number;
109
+ reviewerReservedCalls: number;
110
+ };
111
+ calls: {
112
+ id: string;
113
+ assignment: string;
114
+ chunk: number;
115
+ chunkSha256: string;
116
+ provider: string;
117
+ model: string;
118
+ role: string;
119
+ systemPromptSha256: string;
120
+ userPromptSha256: string;
121
+ }[];
122
+ maxPhysicalCalls: number;
123
+ maxAttemptsPerCall: number;
124
+ expiresAtMs: number;
125
+ };
126
+ call: {
127
+ ref: AsyncCall;
128
+ assignment: import("../roles/types.js").ReviewAssignment;
129
+ prompt: import("../prepare/prompt-builder.js").BuiltPrompt;
130
+ };
131
+ timeoutMs: number;
132
+ opinionCycle: OpinionCycle;
133
+ }>;
134
+ export {};
@@ -0,0 +1,534 @@
1
+ import { loadConvergeRunState } from '../converge/run-state.js';
2
+ import { loadConvergeAttemptState } from '../converge/attempt-budget.js';
3
+ import { assertReviewCyclePair } from '../converge/fresh-review.js';
4
+ import { decodeOriginalLaunch } from './original-launch.js';
5
+ import { createHmac, randomBytes, randomUUID, timingSafeEqual } from 'node:crypto';
6
+ import { constants } from 'node:fs';
7
+ import { link, lstat, mkdir, open, readdir, realpath, rename, rm, unlink } from 'node:fs/promises';
8
+ import { dirname, join, resolve } from 'node:path';
9
+ import { z } from 'zod';
10
+ import { CheckpointJournal, checkpointPath, freezeCheckpointPlan } from './checkpoint.js';
11
+ import { CAPTURED_INPUT_LIMITS } from './captured-inputs.js';
12
+ import { asyncContextForBindings, assertCapturedAsyncPlan } from './checkpoint-async-context.js';
13
+ import { decodeAsyncOutcomeUnknown, encodeAsyncOutcomeUnknown } from './checkpoint-async-unknown.js';
14
+ import { withOwnedNativeOperation } from '../converge/target-ownership.js';
15
+ import { syncNativeDirectory, withNativeLock } from '../converge/native-lock.js';
16
+ import { readStable } from '../telemetry/recovery/files.js';
17
+ import { writeExclusiveBytes } from '../evidence/original-run/journal.js';
18
+ import { MAX_ARTIFACT_BYTES } from '../telemetry/envelope-validation.js';
19
+ import { hasCheckpointIntentCapacity, MAX_ASYNC_PHASE_RECORDS } from './checkpoint-phase-limits.js';
20
+ import { sha256Hex, stableStringify } from '../report/run-header.js';
21
+ import { appendAsyncRecordToValidatedState, assertAsyncReviewBytes, asyncCallAdmission, asyncRefuse, decodeAsyncProof, encodeAsyncProof, freezeAsync, parseAsyncReview, validateAsyncNotDispatched, validateAsyncPlan, validateAsyncRecords, validateAsyncResult } from './checkpoint-async.js';
22
+ const delegateSchema = z.object({ version: z.literal(1), commonDir: z.string().min(1), namespace: z.string().min(1), target: z.string().min(1),
23
+ checkpointPath: z.string().min(1), planDigest: z.string().regex(/^[a-f0-9]{64}$/), callIndex: z.number().int().nonnegative().safe(), token: z.string().regex(/^[a-f0-9]{64}$/) }).strict();
24
+ const metadataSchema = z.object({ version: z.literal(1), plan: z.unknown(), grants: z.array(z.string().regex(/^[a-f0-9]{64}$/)).min(1).max(8),
25
+ opinionCycle: z.object({ version: z.literal(1), cycleId: z.string().uuid().nullable() }).strict().optional() }).strict();
26
+ const filename = (index) => `${String(index).padStart(8, '0')}.json`;
27
+ const isMissing = (error) => error?.code === 'ENOENT';
28
+ const unknownFilename = 'async-outcome-unknown.json';
29
+ async function privateDirectory(path) {
30
+ const stat = await lstat(path);
31
+ asyncRefuse(stat.isDirectory() && !stat.isSymbolicLink() && await realpath(path) === path &&
32
+ (stat.mode & 0o7777) === 0o700 && (!process.geteuid || stat.uid === process.geteuid()), 'unsafe_directory');
33
+ }
34
+ async function child(parent, name) {
35
+ await privateDirectory(parent);
36
+ const path = join(parent, name);
37
+ try {
38
+ await mkdir(path, { mode: 0o700 });
39
+ }
40
+ catch (error) {
41
+ if (error.code !== 'EEXIST')
42
+ throw error;
43
+ }
44
+ await privateDirectory(path);
45
+ await syncNativeDirectory(parent);
46
+ return path;
47
+ }
48
+ async function safeRead(path) {
49
+ await privateDirectory(dirname(path));
50
+ const before = await lstat(path);
51
+ asyncRefuse(before.isFile() && !before.isSymbolicLink() && (before.mode & 0o7777) === 0o600 && (!process.geteuid || before.uid === process.geteuid()), 'unsafe_file');
52
+ const { raw } = await readStable(path, MAX_ARTIFACT_BYTES), after = await lstat(path);
53
+ asyncRefuse(before.ino === after.ino && before.dev === after.dev && before.ctimeMs === after.ctimeMs && before.mtimeMs === after.mtimeMs && before.size === after.size, 'changing_file');
54
+ return new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(raw);
55
+ }
56
+ async function resync(path, bytes) {
57
+ asyncRefuse(await safeRead(path) === bytes, 'conflict');
58
+ const before = await lstat(path), handle = await open(path, constants.O_RDWR | constants.O_NOFOLLOW);
59
+ try {
60
+ const stat = await handle.stat();
61
+ asyncRefuse(stat.ino === before.ino && stat.dev === before.dev && stat.size === before.size && stat.ctimeMs === before.ctimeMs, 'changing_file');
62
+ await handle.sync();
63
+ }
64
+ finally {
65
+ await handle.close();
66
+ }
67
+ asyncRefuse(await safeRead(path) === bytes, 'changing_file');
68
+ await syncNativeDirectory(dirname(path));
69
+ }
70
+ /** Stage, fsync, then link exclusively; readers never observe a partially written event. */
71
+ async function publish(phase, destination, bytes) {
72
+ asyncRefuse(Buffer.byteLength(bytes, 'utf8') <= MAX_ARTIFACT_BYTES, 'too_large');
73
+ try {
74
+ await lstat(destination);
75
+ await resync(destination, bytes);
76
+ return;
77
+ }
78
+ catch (error) {
79
+ if (!isMissing(error))
80
+ throw error;
81
+ }
82
+ const staging = await child(phase, '.staging'), temporary = join(staging, `${randomUUID()}.pending`);
83
+ await writeExclusiveBytes(temporary, Buffer.from(bytes));
84
+ try {
85
+ await link(temporary, destination);
86
+ await syncNativeDirectory(dirname(destination));
87
+ }
88
+ finally {
89
+ await unlink(temporary);
90
+ await syncNativeDirectory(staging);
91
+ }
92
+ await resync(destination, bytes);
93
+ }
94
+ function snapshotLocation(input) {
95
+ const plan = freezeCheckpointPlan(input.plan);
96
+ asyncRefuse(stableStringify(plan) === stableStringify(input.plan), 'plan');
97
+ const commonDir = resolve(input.commonDir), path = checkpointPath(commonDir, plan.target, input.namespace);
98
+ return { commonDir, namespace: input.namespace, checkpointPath: path, phasePath: join(path, 'async'), plan };
99
+ }
100
+ async function contextAt(location) {
101
+ asyncRefuse(await realpath(location.commonDir) === location.commonDir, 'alias');
102
+ const journal = await CheckpointJournal.openRead(location.checkpointPath, location.plan), bindings = await journal.readBindings();
103
+ const bound = asyncContextForBindings(location.plan, bindings);
104
+ asyncRefuse(bound.context.runId === location.namespace, 'parent_binding');
105
+ return { journal, ...bound };
106
+ }
107
+ async function metadataAt(location) {
108
+ const bytes = await safeRead(join(location.phasePath, 'phase.json'));
109
+ let raw;
110
+ try {
111
+ raw = JSON.parse(bytes);
112
+ }
113
+ catch {
114
+ throw new Error('checkpoint_async_invalid_metadata');
115
+ }
116
+ const parsed = metadataSchema.safeParse(raw);
117
+ asyncRefuse(parsed.success && stableStringify(parsed.data) + '\n' === bytes, 'invalid_metadata');
118
+ const plan = validateAsyncPlan(parsed.data.plan), { context, captured } = await contextAt(location);
119
+ assertCapturedAsyncPlan(plan, captured);
120
+ asyncRefuse(stableStringify(plan.context) === stableStringify(context) && parsed.data.grants.length === plan.calls.length && new Set(parsed.data.grants).size === plan.calls.length, 'parent_binding');
121
+ for (const call of plan.calls)
122
+ asyncRefuse(location.plan.chunks.find(chunk => chunk.index === call.chunk)?.digest === call.chunkSha256, 'call');
123
+ return { version: 1, plan, grants: parsed.data.grants, ...(parsed.data.opinionCycle ? { opinionCycle: parsed.data.opinionCycle } : {}) };
124
+ }
125
+ async function recordsAt(location, plan) {
126
+ const directory = join(location.phasePath, 'events');
127
+ await privateDirectory(directory);
128
+ const names = (await readdir(directory)).sort();
129
+ asyncRefuse(names.length <= MAX_ASYNC_PHASE_RECORDS, 'too_many_records');
130
+ let total = 0;
131
+ const records = [];
132
+ for (const [index, name] of names.entries()) {
133
+ asyncRefuse(name === filename(index + 1), 'sequence');
134
+ const bytes = await safeRead(join(directory, name));
135
+ total += Buffer.byteLength(bytes);
136
+ asyncRefuse(total <= MAX_ARTIFACT_BYTES, 'too_large');
137
+ let record;
138
+ try {
139
+ record = JSON.parse(bytes);
140
+ }
141
+ catch {
142
+ throw new Error('checkpoint_async_invalid_record');
143
+ }
144
+ asyncRefuse(stableStringify(record) + '\n' === bytes, 'noncanonical_record');
145
+ records.push(record);
146
+ }
147
+ return validateAsyncRecords(records, plan);
148
+ }
149
+ async function locked(location, work) {
150
+ await privateDirectory(location.phasePath);
151
+ return withNativeLock(join(location.phasePath, 'locks'), 'phase', async () => {
152
+ const metadata = await metadataAt(location), state = await recordsAt(location, metadata.plan);
153
+ return work(metadata, state);
154
+ });
155
+ }
156
+ async function append(location, state, plan, event) {
157
+ const record = appendAsyncRecordToValidatedState(state, event, plan);
158
+ await publish(location.phasePath, join(location.phasePath, 'events', filename(record.sequence)), stableStringify(record) + '\n');
159
+ return record;
160
+ }
161
+ function logicalCutoffMs(plan, state) {
162
+ let cutoffMs = Math.max(Date.now(), plan.context.startedAtMs);
163
+ for (const intent of state.intents)
164
+ cutoffMs = Math.max(cutoffMs, intent.startedAtMs);
165
+ for (const outcome of state.outcomes)
166
+ cutoffMs = Math.max(cutoffMs, outcome.finishedAtMs);
167
+ for (const result of state.notDispatched)
168
+ cutoffMs = Math.max(cutoffMs, result.finishedAtMs);
169
+ asyncRefuse(Number.isSafeInteger(cutoffMs), 'clock');
170
+ return cutoffMs;
171
+ }
172
+ /** Freeze derivative opinion routing while the original native claim is still owned. */
173
+ async function originalOpinionCycle(location, journal) {
174
+ const native = await loadConvergeRunState(location.commonDir, location.plan.target);
175
+ const attempts = await loadConvergeAttemptState(location.commonDir, location.plan.target);
176
+ if (native || attempts) {
177
+ const launch = decodeOriginalLaunch((await journal.readBindings()).launch);
178
+ const claim = launch.originalNativeClaim, pending = native?.lastLaunch;
179
+ asyncRefuse(native && attempts && pending?.status === 'pending' &&
180
+ pending.attempt === claim.attempt && pending.round === claim.round &&
181
+ pending.headSha === location.plan.headSha && attempts.attemptsUsed === claim.attempt &&
182
+ attempts.attempts.some(attempt => attempt.attempt === claim.attempt) &&
183
+ (pending.runId === undefined || pending.runId === location.namespace), 'native_claim');
184
+ await assertReviewCyclePair(location.commonDir, location.plan.target, native.cycle);
185
+ }
186
+ // Owned local/legacy initialization has no cycle. Never infer a cycle later.
187
+ return { version: 1, cycleId: native?.cycle?.id ?? null };
188
+ }
189
+ /** Only initialization under live native ownership may create restricted per-call delegations. */
190
+ export function initializeAsyncPhase(input) {
191
+ const location = snapshotLocation(input), calls = structuredClone(input.calls), { ownership, maxPhysicalCalls, maxAttemptsPerCall, expiresAtMs } = input;
192
+ return withOwnedNativeOperation(ownership, location.commonDir, location.plan.target, async () => {
193
+ const { journal, context, captured } = await contextAt(location), state = await journal.read();
194
+ asyncRefuse(!state.finalized && !state.records.some(row => row.type === 'intent'), 'initialization_closed');
195
+ try {
196
+ await lstat(join(location.checkpointPath, 'terminal-report'));
197
+ throw new Error('checkpoint_async_initialization_closed');
198
+ }
199
+ catch (error) {
200
+ if (!isMissing(error))
201
+ throw error;
202
+ }
203
+ const plan = validateAsyncPlan({ version: 1, context, calls, maxPhysicalCalls, maxAttemptsPerCall, expiresAtMs });
204
+ assertCapturedAsyncPlan(plan, captured);
205
+ asyncRefuse(Date.now() >= context.startedAtMs && Date.now() < plan.expiresAtMs, 'deadline');
206
+ for (const call of plan.calls)
207
+ asyncRefuse(location.plan.chunks.find(chunk => chunk.index === call.chunk)?.digest === call.chunkSha256, 'call');
208
+ try {
209
+ await lstat(location.phasePath);
210
+ throw new Error('checkpoint_async_already_initialized');
211
+ }
212
+ catch (error) {
213
+ if (!isMissing(error))
214
+ throw error;
215
+ }
216
+ const opinionCycle = await originalOpinionCycle(location, journal);
217
+ const bindingDigest = privateDelegateDigest({ plan, opinionCycle });
218
+ const tokens = calls.map(() => randomBytes(32).toString('hex'));
219
+ const metadata = { version: 1, plan, grants: tokens.map(token => delegateGrant(token, bindingDigest)), opinionCycle };
220
+ // The visible async directory is the initialization commit point. Preparing
221
+ // elsewhere cannot make main finalization depend on missing metadata.
222
+ const staging = await child(location.checkpointPath, '.staging');
223
+ const prepared = await child(staging, `async-${randomUUID()}.pending`), identity = await lstat(prepared);
224
+ let published = false;
225
+ try {
226
+ await child(prepared, 'events');
227
+ await child(prepared, 'late');
228
+ await child(prepared, 'failures');
229
+ await publish(prepared, join(prepared, 'phase.json'), stableStringify(metadata) + '\n');
230
+ await syncNativeDirectory(prepared);
231
+ // Native ownership serializes initializers. Never replace an existing
232
+ // phase, including an empty, malformed or symlinked path.
233
+ try {
234
+ await lstat(location.phasePath);
235
+ throw new Error('checkpoint_async_already_initialized');
236
+ }
237
+ catch (error) {
238
+ if (!isMissing(error))
239
+ throw error;
240
+ }
241
+ await rename(prepared, location.phasePath);
242
+ published = true;
243
+ await syncNativeDirectory(location.checkpointPath);
244
+ await syncNativeDirectory(staging);
245
+ }
246
+ finally {
247
+ if (!published) {
248
+ const current = await lstat(prepared);
249
+ asyncRefuse(current.ino === identity.ino && current.dev === identity.dev && !current.isSymbolicLink(), 'changing_file');
250
+ await rm(prepared, { recursive: true });
251
+ await syncNativeDirectory(staging);
252
+ }
253
+ }
254
+ const delegates = tokens.map((token, callIndex) => ({ version: 1, commonDir: location.commonDir, namespace: location.namespace,
255
+ target: location.plan.target, checkpointPath: location.checkpointPath, planDigest: bindingDigest, callIndex, token }));
256
+ return freezeAsync({ delegates, plan });
257
+ });
258
+ }
259
+ async function delegatedLocation(input) {
260
+ const parsed = delegateSchema.safeParse(input);
261
+ asyncRefuse(parsed.success, 'invalid_delegate');
262
+ const delegate = freezeAsync(parsed.data);
263
+ asyncRefuse(resolve(delegate.commonDir) === delegate.commonDir && checkpointPath(delegate.commonDir, delegate.target, delegate.namespace) === delegate.checkpointPath, 'delegate_path');
264
+ const journal = await CheckpointJournal.inspectRead(delegate.checkpointPath);
265
+ asyncRefuse(journal.getPlan().target === delegate.target, 'delegate_target');
266
+ return { location: snapshotLocation({ commonDir: delegate.commonDir, namespace: delegate.namespace, plan: journal.getPlan() }), delegate };
267
+ }
268
+ function privateDelegateDigest(metadata) {
269
+ asyncRefuse(metadata.opinionCycle, 'opinion_cycle_missing');
270
+ return sha256Hex(stableStringify({ plan: metadata.plan, opinionCycle: metadata.opinionCycle }));
271
+ }
272
+ function delegateGrant(token, bindingDigest) {
273
+ return createHmac('sha256', Buffer.from(token, 'hex')).update(bindingDigest).digest('hex');
274
+ }
275
+ function authorize(metadata, delegate) {
276
+ const expected = metadata.grants[delegate.callIndex], bindingDigest = privateDelegateDigest(metadata);
277
+ asyncRefuse(expected && bindingDigest === delegate.planDigest &&
278
+ timingSafeEqual(Buffer.from(expected, 'hex'), Buffer.from(delegateGrant(delegate.token, bindingDigest), 'hex')), 'invalid_delegate');
279
+ }
280
+ /** Delegates cannot mutate native state, reviewer history, phase plan, cutoff or another call. */
281
+ export async function openAsyncDelegate(input) {
282
+ const snapshot = structuredClone(input), { location, delegate } = await delegatedLocation(snapshot);
283
+ await locked(location, async (metadata) => authorize(metadata, delegate));
284
+ return Object.freeze({
285
+ claim: async (prompts, afterIntent) => {
286
+ const system = prompts.systemPrompt, user = prompts.userPrompt;
287
+ return locked(location, async (metadata, state) => {
288
+ authorize(metadata, delegate);
289
+ const call = metadata.plan.calls[delegate.callIndex];
290
+ asyncRefuse([system, user].every(value => typeof value === 'string' && Buffer.byteLength(value, 'utf8') <= CAPTURED_INPUT_LIMITS.bytes &&
291
+ Buffer.from(value, 'utf8').toString('utf8') === value) && sha256Hex(system) === call.systemPromptSha256 && sha256Hex(user) === call.userPromptSha256, 'prompt_mismatch');
292
+ const now = Date.now();
293
+ asyncRefuse(Number.isSafeInteger(now) && now >= metadata.plan.context.startedAtMs, 'clock');
294
+ const admission = asyncCallAdmission(state, delegate.callIndex);
295
+ const { last, outcome, declined } = admission;
296
+ if (state.cutoffMs !== undefined || now >= metadata.plan.expiresAtMs || admission.billedTotal >= metadata.plan.maxPhysicalCalls ||
297
+ admission.billedForCall >= metadata.plan.maxAttemptsPerCall ||
298
+ !hasCheckpointIntentCapacity(state.records.length, state.uncertain.length, state.notDispatched.length, MAX_ASYNC_PHASE_RECORDS) ||
299
+ last && !declined && (!outcome || parseAsyncReview(outcome.reviewBytes, call).status === 'success'))
300
+ return undefined;
301
+ const intent = { callIndex: delegate.callIndex, attemptId: `async-${randomUUID()}`, startedAtMs: now };
302
+ const intentRecord = await append(location, state, metadata.plan, { type: 'intent', intent });
303
+ // A retained executor may synchronously start dispatch after fsync while
304
+ // this same cutoff lock is held. Never await provider work under the lock.
305
+ const frozen = freezeAsync(intent), undispatched = afterIntent?.(frozen);
306
+ if (undispatched) {
307
+ const claimed = validateAsyncRecords([...state.records, intentRecord], metadata.plan);
308
+ const result = validateAsyncNotDispatched({ callIndex: delegate.callIndex, attemptId: intent.attemptId,
309
+ reviewBytes: undispatched.reviewBytes, reviewSha256: sha256Hex(undispatched.reviewBytes),
310
+ finishedAtMs: Date.now() }, metadata.plan, claimed.intents);
311
+ await append(location, claimed, metadata.plan, { type: 'not-dispatched', result });
312
+ }
313
+ return frozen;
314
+ });
315
+ },
316
+ recordResult: async (attemptId, reviewBytes) => {
317
+ assertAsyncReviewBytes(reviewBytes);
318
+ const finishedAtMs = Date.now();
319
+ return locked(location, async (metadata, state) => {
320
+ authorize(metadata, delegate);
321
+ const existing = state.outcomes.find(row => row.attemptId === attemptId);
322
+ const result = validateAsyncResult({ callIndex: delegate.callIndex, attemptId, reviewBytes, reviewSha256: sha256Hex(reviewBytes), possiblyBilled: true,
323
+ finishedAtMs: existing?.finishedAtMs ?? finishedAtMs }, metadata.plan, state.intents);
324
+ if (existing) {
325
+ asyncRefuse(stableStringify(existing) === stableStringify(result), 'result_conflict');
326
+ const record = state.records.find(row => row.event.type === 'result' && row.event.result.attemptId === attemptId);
327
+ await resync(join(location.phasePath, 'events', filename(record.sequence)), stableStringify(record) + '\n');
328
+ return 'observed';
329
+ }
330
+ if (state.cutoffMs === undefined) {
331
+ await append(location, state, metadata.plan, { type: 'result', result });
332
+ return 'observed';
333
+ }
334
+ await appendLate(location, encodeAsyncProof(metadata.plan, state.records), result);
335
+ return 'late';
336
+ });
337
+ },
338
+ });
339
+ }
340
+ /** Parent-only cutoff is atomic with all delegated intent/retry admission. */
341
+ export function sealAsyncPhase(input) {
342
+ const location = snapshotLocation(input);
343
+ return withOwnedNativeOperation(input.ownership, location.commonDir, location.plan.target, () => locked(location, async (metadata, state) => {
344
+ let records = state.records;
345
+ if (state.cutoffMs === undefined)
346
+ records = [...records, await append(location, state, metadata.plan, { type: 'seal', cutoffMs: logicalCutoffMs(metadata.plan, state) })];
347
+ for (const record of records)
348
+ await resync(join(location.phasePath, 'events', filename(record.sequence)), stableStringify(record) + '\n');
349
+ return decodeAsyncProof(encodeAsyncProof(metadata.plan, records).bytes, metadata.plan.context);
350
+ }));
351
+ }
352
+ /** Structural local read; this does not authenticate capture matrix, producer or server authority. */
353
+ export function readAsyncPhase(input) {
354
+ const location = snapshotLocation(input);
355
+ return locked(location, async (metadata, state) => freezeAsync({ plan: metadata.plan, state }));
356
+ }
357
+ async function pathExists(path) {
358
+ try {
359
+ await lstat(path);
360
+ return true;
361
+ }
362
+ catch (error) {
363
+ if (isMissing(error))
364
+ return false;
365
+ throw error;
366
+ }
367
+ }
368
+ /** Read the exact stored original-async evidence without creating or sealing state. */
369
+ export async function inspectCheckpointAsyncExecution(input) {
370
+ const location = snapshotLocation(input);
371
+ const [hasPhase, hasUnknown] = await Promise.all([
372
+ pathExists(location.phasePath), pathExists(join(location.checkpointPath, unknownFilename)),
373
+ ]);
374
+ asyncRefuse(!(hasPhase && hasUnknown), 'conflicting_execution_evidence');
375
+ if (hasPhase) {
376
+ return freezeAsync({ kind: 'phase', phase: await readAsyncPhase(input) });
377
+ }
378
+ if (!hasUnknown)
379
+ return undefined;
380
+ const { journal, context, captured } = await contextAt(location), root = await journal.exportProof();
381
+ const bytes = await safeRead(join(location.checkpointPath, unknownFilename));
382
+ const unknown = decodeAsyncOutcomeUnknown(bytes, root, context, captured);
383
+ return freezeAsync({ kind: 'unknown',
384
+ proof: freezeAsync({ bytes: unknown.bytes, digest: unknown.digest }) });
385
+ }
386
+ /** Read only terminal execution evidence; an open phase is deliberately not a proof. */
387
+ export async function readCheckpointAsyncExecution(input) {
388
+ const stored = await inspectCheckpointAsyncExecution(input);
389
+ if (stored === undefined)
390
+ return undefined;
391
+ if (stored.kind === 'unknown')
392
+ return stored.proof;
393
+ const proof = encodeAsyncProof(stored.phase.plan, stored.phase.state.records);
394
+ return freezeAsync({ bytes: proof.bytes, digest: proof.digest });
395
+ }
396
+ /**
397
+ * Seal a real phase or retain an explicit unknown outcome after a finalized,
398
+ * expired original launch. The unknown form never creates intents or claims
399
+ * that any captured async call did or did not dispatch.
400
+ */
401
+ export async function resolveFinalizedAsyncExecution(input) {
402
+ const location = snapshotLocation(input);
403
+ return withOwnedNativeOperation(input.ownership, location.commonDir, location.plan.target, async (ownership) => {
404
+ const { journal, context, captured } = await contextAt(location);
405
+ const [hasPhase, hasUnknown] = await Promise.all([
406
+ pathExists(location.phasePath), pathExists(join(location.checkpointPath, unknownFilename)),
407
+ ]);
408
+ asyncRefuse(!(hasPhase && hasUnknown), 'conflicting_execution_evidence');
409
+ if (captured.async === undefined) {
410
+ asyncRefuse(!hasPhase && !hasUnknown, 'unexpected_execution_evidence');
411
+ return undefined;
412
+ }
413
+ const state = await journal.read();
414
+ asyncRefuse(state.finalized, 'unknown_unfinalized_checkpoint');
415
+ if (hasPhase)
416
+ return sealAsyncPhase({ ...input, ownership });
417
+ const now = (input.nowMs ?? Date.now)();
418
+ asyncRefuse(Number.isSafeInteger(now) && now >= context.expiresAtMs, 'unknown_live_launch');
419
+ if (hasUnknown)
420
+ return readCheckpointAsyncExecution(input);
421
+ asyncRefuse(!await pathExists(join(location.checkpointPath, 'terminal-report')), 'unknown_terminal_report');
422
+ const root = await journal.exportProof(), unknown = encodeAsyncOutcomeUnknown(root, context, captured);
423
+ await publish(location.checkpointPath, join(location.checkpointPath, unknownFilename), unknown.bytes);
424
+ const readback = await readCheckpointAsyncExecution(input);
425
+ asyncRefuse(readback?.bytes === unknown.bytes && readback.digest === unknown.digest, 'unknown_readback');
426
+ return readback;
427
+ });
428
+ }
429
+ async function lateAt(location, proof) {
430
+ const directory = join(location.phasePath, 'late');
431
+ await privateDirectory(directory);
432
+ const names = (await readdir(directory)).sort();
433
+ asyncRefuse(names.length <= proof.state.uncertain.length, 'late_cap');
434
+ const rows = [];
435
+ const seen = new Set();
436
+ let previous = proof.digest, total = 0;
437
+ for (const [index, name] of names.entries()) {
438
+ asyncRefuse(name === filename(index + 1), 'late_sequence');
439
+ const bytes = await safeRead(join(directory, name));
440
+ total += Buffer.byteLength(bytes);
441
+ asyncRefuse(total <= MAX_ARTIFACT_BYTES, 'late_too_large');
442
+ let row;
443
+ try {
444
+ row = JSON.parse(bytes);
445
+ }
446
+ catch {
447
+ throw new Error('checkpoint_async_invalid_late');
448
+ }
449
+ asyncRefuse(row && typeof row === 'object' && Object.keys(row).sort().join(',') === 'digest,previousDigest,result,sealedProofSha256,sequence', 'invalid_late');
450
+ const { digest, ...unsigned } = row;
451
+ asyncRefuse(stableStringify(row) + '\n' === bytes && row.sequence === index + 1 && row.previousDigest === previous && row.sealedProofSha256 === proof.digest && sha256Hex(stableStringify(unsigned)) === digest, 'invalid_late');
452
+ validateAsyncResult(row.result, proof.plan, proof.state.uncertain);
453
+ asyncRefuse(!seen.has(row.result.attemptId), 'duplicate_late');
454
+ seen.add(row.result.attemptId);
455
+ rows.push(row);
456
+ previous = digest;
457
+ }
458
+ return freezeAsync(rows);
459
+ }
460
+ async function appendLate(location, proof, result) {
461
+ const rows = await lateAt(location, proof), existing = rows.find(row => row.result.attemptId === result.attemptId);
462
+ if (existing) {
463
+ asyncRefuse(stableStringify(existing.result) === stableStringify({ ...result, finishedAtMs: existing.result.finishedAtMs }), 'late_conflict');
464
+ await resync(join(location.phasePath, 'late', filename(existing.sequence)), stableStringify(existing) + '\n');
465
+ return;
466
+ }
467
+ validateAsyncResult(result, proof.plan, proof.state.uncertain);
468
+ const unsigned = { sequence: rows.length + 1, previousDigest: rows.at(-1)?.digest ?? proof.digest, sealedProofSha256: proof.digest, result };
469
+ const record = { ...unsigned, digest: sha256Hex(stableStringify(unsigned)) };
470
+ asyncRefuse(Buffer.byteLength(stableStringify([...rows, record])) <= MAX_ARTIFACT_BYTES, 'late_too_large');
471
+ await publish(location.phasePath, join(location.phasePath, 'late', filename(record.sequence)), stableStringify(record) + '\n');
472
+ }
473
+ export function readAsyncLateAudit(input) {
474
+ const location = snapshotLocation(input);
475
+ return locked(location, (metadata, state) => lateAt(location, encodeAsyncProof(metadata.plan, state.records)));
476
+ }
477
+ async function lateFailuresAt(location, plan, state) {
478
+ const directory = join(location.phasePath, 'failures');
479
+ await privateDirectory(directory);
480
+ const names = (await readdir(directory)).sort();
481
+ asyncRefuse(names.length <= plan.maxPhysicalCalls, 'late_failure_cap');
482
+ const rows = [];
483
+ for (const name of names) {
484
+ const bytes = await safeRead(join(directory, name));
485
+ let row;
486
+ try {
487
+ row = JSON.parse(bytes);
488
+ }
489
+ catch {
490
+ throw new Error('checkpoint_async_invalid_late_failure');
491
+ }
492
+ asyncRefuse(row && typeof row === 'object' && Object.keys(row).sort().join(',') === 'attemptId,callIndex,digest,kind,sequence', 'invalid_late_failure');
493
+ const candidate = row, { digest, ...unsigned } = candidate;
494
+ const intent = state.intents[candidate.sequence - 1];
495
+ asyncRefuse(stableStringify(candidate) + '\n' === bytes && candidate.sequence >= 1 && name === filename(candidate.sequence) &&
496
+ candidate.kind === 'late_audit_failure' && intent?.attemptId === candidate.attemptId && intent.callIndex === candidate.callIndex &&
497
+ sha256Hex(stableStringify(unsigned)) === digest, 'invalid_late_failure');
498
+ rows.push(candidate);
499
+ }
500
+ return freezeAsync(rows);
501
+ }
502
+ /** Record a bounded private diagnostic when a late result cannot be audited. */
503
+ export async function recordAsyncLateFailure(input, attemptId) {
504
+ const { location, delegate } = await delegatedLocation(structuredClone(input));
505
+ await locked(location, async (metadata, state) => {
506
+ authorize(metadata, delegate);
507
+ const intentIndex = state.intents.findIndex(value => value.attemptId === attemptId), intent = state.intents[intentIndex];
508
+ asyncRefuse(intent?.callIndex === delegate.callIndex, 'late_failure_intent');
509
+ // Bind the marker path to the immutable physical-intent position. Exact
510
+ // replay reaches one file directly instead of rereading every prior marker.
511
+ const sequence = intentIndex + 1;
512
+ const unsigned = { sequence, kind: 'late_audit_failure', callIndex: delegate.callIndex, attemptId };
513
+ const record = { ...unsigned, digest: sha256Hex(stableStringify(unsigned)) };
514
+ await publish(location.phasePath, join(location.phasePath, 'failures', filename(sequence)), stableStringify(record) + '\n');
515
+ });
516
+ }
517
+ /** Structural private diagnostic read; entries contain no provider error bytes. */
518
+ export function readAsyncLateFailures(input) {
519
+ const location = snapshotLocation(input);
520
+ return locked(location, (metadata, state) => lateFailuresAt(location, metadata.plan, state));
521
+ }
522
+ /** Authenticated restricted executor input, read only from the same journal and captured matrix. */
523
+ export async function openCapturedAsyncDelegate(input) {
524
+ const { location, delegate } = await delegatedLocation(structuredClone(input));
525
+ const execution = await locked(location, async (metadata) => {
526
+ authorize(metadata, delegate);
527
+ const { captured } = await contextAt(location);
528
+ // Historical phases remain readable as evidence, but cannot guess routing authority.
529
+ asyncRefuse(metadata.opinionCycle, 'opinion_cycle_missing');
530
+ return freezeAsync({ plan: metadata.plan, call: captured.async.calls[delegate.callIndex], timeoutMs: captured.async.timeoutMs, opinionCycle: metadata.opinionCycle });
531
+ });
532
+ return { ...execution, writer: await openAsyncDelegate(delegate) };
533
+ }
534
+ //# sourceMappingURL=checkpoint-async-store.js.map