@gpustack/loopwright 0.0.0-stage → 0.0.3

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 (477) hide show
  1. package/LICENSE +191 -0
  2. package/README.md +356 -2
  3. package/bin/loopwright.js +3 -0
  4. package/node_modules/@loopwright/agent-pi/dist/adapter-v2.d.ts +9 -0
  5. package/node_modules/@loopwright/agent-pi/dist/adapter-v2.js +122 -0
  6. package/node_modules/@loopwright/agent-pi/dist/adapter.d.ts +30 -0
  7. package/node_modules/@loopwright/agent-pi/dist/adapter.js +340 -0
  8. package/node_modules/@loopwright/agent-pi/dist/admission.d.ts +25 -0
  9. package/node_modules/@loopwright/agent-pi/dist/admission.js +65 -0
  10. package/node_modules/@loopwright/agent-pi/dist/artifacts.d.ts +15 -0
  11. package/node_modules/@loopwright/agent-pi/dist/artifacts.js +76 -0
  12. package/node_modules/@loopwright/agent-pi/dist/boundary.d.ts +18 -0
  13. package/node_modules/@loopwright/agent-pi/dist/boundary.js +113 -0
  14. package/node_modules/@loopwright/agent-pi/dist/broker-channel.d.ts +4 -0
  15. package/node_modules/@loopwright/agent-pi/dist/broker-channel.js +121 -0
  16. package/node_modules/@loopwright/agent-pi/dist/candidate.d.ts +96 -0
  17. package/node_modules/@loopwright/agent-pi/dist/candidate.js +1712 -0
  18. package/node_modules/@loopwright/agent-pi/dist/capture.d.ts +39 -0
  19. package/node_modules/@loopwright/agent-pi/dist/capture.js +146 -0
  20. package/node_modules/@loopwright/agent-pi/dist/cas.d.ts +51 -0
  21. package/node_modules/@loopwright/agent-pi/dist/cas.js +836 -0
  22. package/node_modules/@loopwright/agent-pi/dist/catalog-api.d.ts +3 -0
  23. package/node_modules/@loopwright/agent-pi/dist/catalog-api.js +2 -0
  24. package/node_modules/@loopwright/agent-pi/dist/catalog.d.ts +39 -0
  25. package/node_modules/@loopwright/agent-pi/dist/catalog.js +280 -0
  26. package/node_modules/@loopwright/agent-pi/dist/circuit-breaker-limits.d.ts +9 -0
  27. package/node_modules/@loopwright/agent-pi/dist/circuit-breaker-limits.js +12 -0
  28. package/node_modules/@loopwright/agent-pi/dist/containers.d.ts +29 -0
  29. package/node_modules/@loopwright/agent-pi/dist/containers.js +160 -0
  30. package/node_modules/@loopwright/agent-pi/dist/context.d.ts +56 -0
  31. package/node_modules/@loopwright/agent-pi/dist/context.js +351 -0
  32. package/node_modules/@loopwright/agent-pi/dist/daemon.d.ts +8 -0
  33. package/node_modules/@loopwright/agent-pi/dist/daemon.js +52 -0
  34. package/node_modules/@loopwright/agent-pi/dist/deadline.d.ts +6 -0
  35. package/node_modules/@loopwright/agent-pi/dist/deadline.js +18 -0
  36. package/node_modules/@loopwright/agent-pi/dist/decode-capture.d.ts +39 -0
  37. package/node_modules/@loopwright/agent-pi/dist/decode-capture.js +287 -0
  38. package/node_modules/@loopwright/agent-pi/dist/descriptor.d.ts +12 -0
  39. package/node_modules/@loopwright/agent-pi/dist/descriptor.js +17 -0
  40. package/node_modules/@loopwright/agent-pi/dist/docker-absence.d.ts +2 -0
  41. package/node_modules/@loopwright/agent-pi/dist/docker-absence.js +9 -0
  42. package/node_modules/@loopwright/agent-pi/dist/errors.d.ts +7 -0
  43. package/node_modules/@loopwright/agent-pi/dist/errors.js +19 -0
  44. package/node_modules/@loopwright/agent-pi/dist/event-sequence.d.ts +6 -0
  45. package/node_modules/@loopwright/agent-pi/dist/event-sequence.js +64 -0
  46. package/node_modules/@loopwright/agent-pi/dist/events.d.ts +19 -0
  47. package/node_modules/@loopwright/agent-pi/dist/events.js +132 -0
  48. package/node_modules/@loopwright/agent-pi/dist/execution-guard.d.ts +9 -0
  49. package/node_modules/@loopwright/agent-pi/dist/execution-guard.js +25 -0
  50. package/node_modules/@loopwright/agent-pi/dist/execution-lease.d.ts +24 -0
  51. package/node_modules/@loopwright/agent-pi/dist/execution-lease.js +316 -0
  52. package/node_modules/@loopwright/agent-pi/dist/execution.d.ts +32 -0
  53. package/node_modules/@loopwright/agent-pi/dist/execution.js +476 -0
  54. package/node_modules/@loopwright/agent-pi/dist/external-mcp.d.ts +87 -0
  55. package/node_modules/@loopwright/agent-pi/dist/external-mcp.js +526 -0
  56. package/node_modules/@loopwright/agent-pi/dist/factory-bootstrap.d.ts +15 -0
  57. package/node_modules/@loopwright/agent-pi/dist/factory-bootstrap.js +74 -0
  58. package/node_modules/@loopwright/agent-pi/dist/host-session.d.ts +51 -0
  59. package/node_modules/@loopwright/agent-pi/dist/host-session.js +2094 -0
  60. package/node_modules/@loopwright/agent-pi/dist/http-mcp.d.ts +32 -0
  61. package/node_modules/@loopwright/agent-pi/dist/http-mcp.js +353 -0
  62. package/node_modules/@loopwright/agent-pi/dist/index.d.ts +7 -0
  63. package/node_modules/@loopwright/agent-pi/dist/index.js +4 -0
  64. package/node_modules/@loopwright/agent-pi/dist/lifecycle.d.ts +13 -0
  65. package/node_modules/@loopwright/agent-pi/dist/lifecycle.js +11 -0
  66. package/node_modules/@loopwright/agent-pi/dist/mcp-process.d.ts +35 -0
  67. package/node_modules/@loopwright/agent-pi/dist/mcp-process.js +92 -0
  68. package/node_modules/@loopwright/agent-pi/dist/mcp-transport.d.ts +25 -0
  69. package/node_modules/@loopwright/agent-pi/dist/mcp-transport.js +63 -0
  70. package/node_modules/@loopwright/agent-pi/dist/mcp.d.ts +23 -0
  71. package/node_modules/@loopwright/agent-pi/dist/mcp.js +212 -0
  72. package/node_modules/@loopwright/agent-pi/dist/operation.d.ts +5 -0
  73. package/node_modules/@loopwright/agent-pi/dist/operation.js +28 -0
  74. package/node_modules/@loopwright/agent-pi/dist/policy-v2.d.ts +10 -0
  75. package/node_modules/@loopwright/agent-pi/dist/policy-v2.js +64 -0
  76. package/node_modules/@loopwright/agent-pi/dist/policy.d.ts +13 -0
  77. package/node_modules/@loopwright/agent-pi/dist/policy.js +260 -0
  78. package/node_modules/@loopwright/agent-pi/dist/preflight.d.ts +60 -0
  79. package/node_modules/@loopwright/agent-pi/dist/preflight.js +700 -0
  80. package/node_modules/@loopwright/agent-pi/dist/progress-summary.d.ts +1 -0
  81. package/node_modules/@loopwright/agent-pi/dist/progress-summary.js +119 -0
  82. package/node_modules/@loopwright/agent-pi/dist/protocol.d.ts +17 -0
  83. package/node_modules/@loopwright/agent-pi/dist/protocol.js +131 -0
  84. package/node_modules/@loopwright/agent-pi/dist/provider.d.ts +62 -0
  85. package/node_modules/@loopwright/agent-pi/dist/provider.js +217 -0
  86. package/node_modules/@loopwright/agent-pi/dist/receipt.d.ts +3 -0
  87. package/node_modules/@loopwright/agent-pi/dist/receipt.js +64 -0
  88. package/node_modules/@loopwright/agent-pi/dist/recovery.d.ts +6 -0
  89. package/node_modules/@loopwright/agent-pi/dist/recovery.js +188 -0
  90. package/node_modules/@loopwright/agent-pi/dist/resources.d.ts +13 -0
  91. package/node_modules/@loopwright/agent-pi/dist/resources.js +81 -0
  92. package/node_modules/@loopwright/agent-pi/dist/response.d.ts +20 -0
  93. package/node_modules/@loopwright/agent-pi/dist/response.js +259 -0
  94. package/node_modules/@loopwright/agent-pi/dist/runtime-profile.d.ts +6 -0
  95. package/node_modules/@loopwright/agent-pi/dist/runtime-profile.js +37 -0
  96. package/node_modules/@loopwright/agent-pi/dist/sdk-worker.d.ts +14 -0
  97. package/node_modules/@loopwright/agent-pi/dist/sdk-worker.js +633 -0
  98. package/node_modules/@loopwright/agent-pi/dist/sender.d.ts +46 -0
  99. package/node_modules/@loopwright/agent-pi/dist/sender.js +553 -0
  100. package/node_modules/@loopwright/agent-pi/dist/session-host.d.ts +21 -0
  101. package/node_modules/@loopwright/agent-pi/dist/session-host.js +315 -0
  102. package/node_modules/@loopwright/agent-pi/dist/snapshot-transfer.d.ts +14 -0
  103. package/node_modules/@loopwright/agent-pi/dist/snapshot-transfer.js +102 -0
  104. package/node_modules/@loopwright/agent-pi/dist/snapshot.d.ts +19 -0
  105. package/node_modules/@loopwright/agent-pi/dist/snapshot.js +121 -0
  106. package/node_modules/@loopwright/agent-pi/dist/tool-process.d.ts +32 -0
  107. package/node_modules/@loopwright/agent-pi/dist/tool-process.js +85 -0
  108. package/node_modules/@loopwright/agent-pi/dist/tool-worker.d.ts +2 -0
  109. package/node_modules/@loopwright/agent-pi/dist/tool-worker.js +105 -0
  110. package/node_modules/@loopwright/agent-pi/dist/tools.d.ts +36 -0
  111. package/node_modules/@loopwright/agent-pi/dist/tools.js +128 -0
  112. package/node_modules/@loopwright/agent-pi/dist/types-v2.d.ts +71 -0
  113. package/node_modules/@loopwright/agent-pi/dist/types-v2.js +1 -0
  114. package/node_modules/@loopwright/agent-pi/dist/types.d.ts +314 -0
  115. package/node_modules/@loopwright/agent-pi/dist/types.js +1 -0
  116. package/node_modules/@loopwright/agent-pi/dist/usage.d.ts +18 -0
  117. package/node_modules/@loopwright/agent-pi/dist/usage.js +314 -0
  118. package/node_modules/@loopwright/agent-pi/dist/workspace-mcp.d.ts +27 -0
  119. package/node_modules/@loopwright/agent-pi/dist/workspace-mcp.js +142 -0
  120. package/node_modules/@loopwright/agent-pi/package.json +24 -0
  121. package/node_modules/@loopwright/agent-pi/runtime/Dockerfile +8 -0
  122. package/node_modules/@loopwright/agent-pi/runtime/seccomp.json +1 -0
  123. package/node_modules/@loopwright/cli/dist/arguments.d.ts +19 -0
  124. package/node_modules/@loopwright/cli/dist/arguments.js +358 -0
  125. package/node_modules/@loopwright/cli/dist/closure.d.ts +93 -0
  126. package/node_modules/@loopwright/cli/dist/closure.js +230 -0
  127. package/node_modules/@loopwright/cli/dist/draft.d.ts +9 -0
  128. package/node_modules/@loopwright/cli/dist/draft.js +106 -0
  129. package/node_modules/@loopwright/cli/dist/failure-matrix.d.ts +9 -0
  130. package/node_modules/@loopwright/cli/dist/failure-matrix.js +701 -0
  131. package/node_modules/@loopwright/cli/dist/index.d.ts +6 -0
  132. package/node_modules/@loopwright/cli/dist/index.js +5 -0
  133. package/node_modules/@loopwright/cli/dist/main.d.ts +22 -0
  134. package/node_modules/@loopwright/cli/dist/main.js +1855 -0
  135. package/node_modules/@loopwright/cli/package.json +16 -0
  136. package/node_modules/@loopwright/controller/dist/acceptance.d.ts +43 -0
  137. package/node_modules/@loopwright/controller/dist/acceptance.js +446 -0
  138. package/node_modules/@loopwright/controller/dist/benchmark-gate.d.ts +273 -0
  139. package/node_modules/@loopwright/controller/dist/benchmark-gate.js +3147 -0
  140. package/node_modules/@loopwright/controller/dist/budget-observations.d.ts +25 -0
  141. package/node_modules/@loopwright/controller/dist/budget-observations.js +139 -0
  142. package/node_modules/@loopwright/controller/dist/bundle.d.ts +26 -0
  143. package/node_modules/@loopwright/controller/dist/bundle.js +64 -0
  144. package/node_modules/@loopwright/controller/dist/capture.d.ts +89 -0
  145. package/node_modules/@loopwright/controller/dist/capture.js +587 -0
  146. package/node_modules/@loopwright/controller/dist/compile.d.ts +3 -0
  147. package/node_modules/@loopwright/controller/dist/compile.js +402 -0
  148. package/node_modules/@loopwright/controller/dist/config.d.ts +22 -0
  149. package/node_modules/@loopwright/controller/dist/config.js +255 -0
  150. package/node_modules/@loopwright/controller/dist/controller.d.ts +177 -0
  151. package/node_modules/@loopwright/controller/dist/controller.js +2135 -0
  152. package/node_modules/@loopwright/controller/dist/credentials.d.ts +29 -0
  153. package/node_modules/@loopwright/controller/dist/credentials.js +189 -0
  154. package/node_modules/@loopwright/controller/dist/deadlines.d.ts +18 -0
  155. package/node_modules/@loopwright/controller/dist/deadlines.js +71 -0
  156. package/node_modules/@loopwright/controller/dist/errors.d.ts +27 -0
  157. package/node_modules/@loopwright/controller/dist/errors.js +41 -0
  158. package/node_modules/@loopwright/controller/dist/events.d.ts +52 -0
  159. package/node_modules/@loopwright/controller/dist/events.js +228 -0
  160. package/node_modules/@loopwright/controller/dist/files.d.ts +51 -0
  161. package/node_modules/@loopwright/controller/dist/files.js +386 -0
  162. package/node_modules/@loopwright/controller/dist/finalize.d.ts +25 -0
  163. package/node_modules/@loopwright/controller/dist/finalize.js +32 -0
  164. package/node_modules/@loopwright/controller/dist/gate.d.ts +84 -0
  165. package/node_modules/@loopwright/controller/dist/gate.js +640 -0
  166. package/node_modules/@loopwright/controller/dist/git-objects.d.ts +11 -0
  167. package/node_modules/@loopwright/controller/dist/git-objects.js +59 -0
  168. package/node_modules/@loopwright/controller/dist/git-reader.d.ts +17 -0
  169. package/node_modules/@loopwright/controller/dist/git-reader.js +40 -0
  170. package/node_modules/@loopwright/controller/dist/handlers.d.ts +6 -0
  171. package/node_modules/@loopwright/controller/dist/handlers.js +45 -0
  172. package/node_modules/@loopwright/controller/dist/handoff.d.ts +71 -0
  173. package/node_modules/@loopwright/controller/dist/handoff.js +554 -0
  174. package/node_modules/@loopwright/controller/dist/index.d.ts +41 -0
  175. package/node_modules/@loopwright/controller/dist/index.js +21 -0
  176. package/node_modules/@loopwright/controller/dist/inspect.d.ts +30 -0
  177. package/node_modules/@loopwright/controller/dist/inspect.js +372 -0
  178. package/node_modules/@loopwright/controller/dist/interpolation.d.ts +9 -0
  179. package/node_modules/@loopwright/controller/dist/interpolation.js +79 -0
  180. package/node_modules/@loopwright/controller/dist/ownership.d.ts +41 -0
  181. package/node_modules/@loopwright/controller/dist/ownership.js +666 -0
  182. package/node_modules/@loopwright/controller/dist/parser.d.ts +5 -0
  183. package/node_modules/@loopwright/controller/dist/parser.js +200 -0
  184. package/node_modules/@loopwright/controller/dist/progress.d.ts +41 -0
  185. package/node_modules/@loopwright/controller/dist/progress.js +904 -0
  186. package/node_modules/@loopwright/controller/dist/publication.d.ts +60 -0
  187. package/node_modules/@loopwright/controller/dist/publication.js +329 -0
  188. package/node_modules/@loopwright/controller/dist/reconcile.d.ts +26 -0
  189. package/node_modules/@loopwright/controller/dist/reconcile.js +1378 -0
  190. package/node_modules/@loopwright/controller/dist/recovery.d.ts +10 -0
  191. package/node_modules/@loopwright/controller/dist/recovery.js +315 -0
  192. package/node_modules/@loopwright/controller/dist/refusal-record.d.ts +43 -0
  193. package/node_modules/@loopwright/controller/dist/refusal-record.js +150 -0
  194. package/node_modules/@loopwright/controller/dist/registry.d.ts +6 -0
  195. package/node_modules/@loopwright/controller/dist/registry.js +374 -0
  196. package/node_modules/@loopwright/controller/dist/repair.d.ts +31 -0
  197. package/node_modules/@loopwright/controller/dist/repair.js +102 -0
  198. package/node_modules/@loopwright/controller/dist/report.d.ts +64 -0
  199. package/node_modules/@loopwright/controller/dist/report.js +596 -0
  200. package/node_modules/@loopwright/controller/dist/retained.d.ts +284 -0
  201. package/node_modules/@loopwright/controller/dist/retained.js +193 -0
  202. package/node_modules/@loopwright/controller/dist/rules.d.ts +31 -0
  203. package/node_modules/@loopwright/controller/dist/rules.js +110 -0
  204. package/node_modules/@loopwright/controller/dist/run-eval.d.ts +115 -0
  205. package/node_modules/@loopwright/controller/dist/run-eval.js +959 -0
  206. package/node_modules/@loopwright/controller/dist/scheduler.d.ts +10 -0
  207. package/node_modules/@loopwright/controller/dist/scheduler.js +41 -0
  208. package/node_modules/@loopwright/controller/dist/schema.d.ts +17 -0
  209. package/node_modules/@loopwright/controller/dist/schema.js +78 -0
  210. package/node_modules/@loopwright/controller/dist/source.d.ts +69 -0
  211. package/node_modules/@loopwright/controller/dist/source.js +872 -0
  212. package/node_modules/@loopwright/controller/dist/step.d.ts +38 -0
  213. package/node_modules/@loopwright/controller/dist/step.js +1776 -0
  214. package/node_modules/@loopwright/controller/dist/storage.d.ts +90 -0
  215. package/node_modules/@loopwright/controller/dist/storage.js +1345 -0
  216. package/node_modules/@loopwright/controller/dist/submission.d.ts +51 -0
  217. package/node_modules/@loopwright/controller/dist/submission.js +292 -0
  218. package/node_modules/@loopwright/controller/dist/types.d.ts +585 -0
  219. package/node_modules/@loopwright/controller/dist/types.js +9 -0
  220. package/node_modules/@loopwright/controller/dist/verification.d.ts +124 -0
  221. package/node_modules/@loopwright/controller/dist/verification.js +1308 -0
  222. package/node_modules/@loopwright/controller/dist/verifier-protocol.d.ts +105 -0
  223. package/node_modules/@loopwright/controller/dist/verifier-protocol.js +1312 -0
  224. package/node_modules/@loopwright/controller/dist/verifier-worker.d.ts +1 -0
  225. package/node_modules/@loopwright/controller/dist/verifier-worker.js +33 -0
  226. package/node_modules/@loopwright/controller/package.json +12 -0
  227. package/node_modules/@loopwright/core/dist/acceptance.d.ts +108 -0
  228. package/node_modules/@loopwright/core/dist/acceptance.js +327 -0
  229. package/node_modules/@loopwright/core/dist/artifacts.d.ts +63 -0
  230. package/node_modules/@loopwright/core/dist/artifacts.js +356 -0
  231. package/node_modules/@loopwright/core/dist/boundary.d.ts +21 -0
  232. package/node_modules/@loopwright/core/dist/boundary.js +484 -0
  233. package/node_modules/@loopwright/core/dist/contracts.d.ts +287 -0
  234. package/node_modules/@loopwright/core/dist/contracts.js +694 -0
  235. package/node_modules/@loopwright/core/dist/diagnostics.d.ts +21 -0
  236. package/node_modules/@loopwright/core/dist/diagnostics.js +51 -0
  237. package/node_modules/@loopwright/core/dist/evidence.d.ts +92 -0
  238. package/node_modules/@loopwright/core/dist/evidence.js +85 -0
  239. package/node_modules/@loopwright/core/dist/graph.d.ts +8 -0
  240. package/node_modules/@loopwright/core/dist/graph.js +44 -0
  241. package/node_modules/@loopwright/core/dist/identity.d.ts +162 -0
  242. package/node_modules/@loopwright/core/dist/identity.js +80 -0
  243. package/node_modules/@loopwright/core/dist/index.d.ts +30 -0
  244. package/node_modules/@loopwright/core/dist/index.js +39 -0
  245. package/node_modules/@loopwright/core/dist/limits.d.ts +99 -0
  246. package/node_modules/@loopwright/core/dist/limits.js +59 -0
  247. package/node_modules/@loopwright/core/dist/results.d.ts +161 -0
  248. package/node_modules/@loopwright/core/dist/results.js +98 -0
  249. package/node_modules/@loopwright/core/dist/scope.d.ts +13 -0
  250. package/node_modules/@loopwright/core/dist/scope.js +154 -0
  251. package/node_modules/@loopwright/core/dist/scrubber.d.ts +13 -0
  252. package/node_modules/@loopwright/core/dist/scrubber.js +63 -0
  253. package/node_modules/@loopwright/core/dist/usage.d.ts +68 -0
  254. package/node_modules/@loopwright/core/dist/usage.js +56 -0
  255. package/node_modules/@loopwright/core/package.json +12 -0
  256. package/node_modules/@loopwright/decisions/dist/benchmark.d.ts +23 -0
  257. package/node_modules/@loopwright/decisions/dist/benchmark.js +337 -0
  258. package/node_modules/@loopwright/decisions/dist/client.d.ts +74 -0
  259. package/node_modules/@loopwright/decisions/dist/client.js +292 -0
  260. package/node_modules/@loopwright/decisions/dist/index.d.ts +15 -0
  261. package/node_modules/@loopwright/decisions/dist/index.js +8 -0
  262. package/node_modules/@loopwright/decisions/dist/nodes.d.ts +63 -0
  263. package/node_modules/@loopwright/decisions/dist/nodes.js +282 -0
  264. package/node_modules/@loopwright/decisions/dist/primitives.d.ts +36 -0
  265. package/node_modules/@loopwright/decisions/dist/primitives.js +300 -0
  266. package/node_modules/@loopwright/decisions/dist/redaction.d.ts +23 -0
  267. package/node_modules/@loopwright/decisions/dist/redaction.js +146 -0
  268. package/node_modules/@loopwright/decisions/dist/router.d.ts +55 -0
  269. package/node_modules/@loopwright/decisions/dist/router.js +248 -0
  270. package/node_modules/@loopwright/decisions/dist/schema.d.ts +25 -0
  271. package/node_modules/@loopwright/decisions/dist/schema.js +536 -0
  272. package/node_modules/@loopwright/decisions/dist/types.d.ts +394 -0
  273. package/node_modules/@loopwright/decisions/dist/types.js +80 -0
  274. package/node_modules/@loopwright/decisions/package.json +12 -0
  275. package/node_modules/@loopwright/github-app/dist/action.d.ts +90 -0
  276. package/node_modules/@loopwright/github-app/dist/action.js +2429 -0
  277. package/node_modules/@loopwright/github-app/dist/config.d.ts +23 -0
  278. package/node_modules/@loopwright/github-app/dist/config.js +297 -0
  279. package/node_modules/@loopwright/github-app/dist/digests.d.ts +1 -0
  280. package/node_modules/@loopwright/github-app/dist/digests.js +1 -0
  281. package/node_modules/@loopwright/github-app/dist/index.d.ts +14 -0
  282. package/node_modules/@loopwright/github-app/dist/index.js +13 -0
  283. package/node_modules/@loopwright/github-app/dist/models-config.d.ts +1 -0
  284. package/node_modules/@loopwright/github-app/dist/models-config.js +1 -0
  285. package/node_modules/@loopwright/github-app/dist/output-format.d.ts +1 -0
  286. package/node_modules/@loopwright/github-app/dist/output-format.js +1 -0
  287. package/node_modules/@loopwright/github-app/dist/preflight.d.ts +1 -0
  288. package/node_modules/@loopwright/github-app/dist/preflight.js +1 -0
  289. package/node_modules/@loopwright/github-app/dist/publisher.d.ts +58 -0
  290. package/node_modules/@loopwright/github-app/dist/publisher.js +1368 -0
  291. package/node_modules/@loopwright/github-app/dist/qualification.d.ts +1 -0
  292. package/node_modules/@loopwright/github-app/dist/qualification.js +1 -0
  293. package/node_modules/@loopwright/github-app/dist/sandbox.d.ts +1 -0
  294. package/node_modules/@loopwright/github-app/dist/sandbox.js +1 -0
  295. package/node_modules/@loopwright/github-app/dist/schema.d.ts +1 -0
  296. package/node_modules/@loopwright/github-app/dist/schema.js +1 -0
  297. package/node_modules/@loopwright/github-app/dist/service.d.ts +52 -0
  298. package/node_modules/@loopwright/github-app/dist/service.js +1658 -0
  299. package/node_modules/@loopwright/github-app/dist/suite-pr-lookup.d.ts +90 -0
  300. package/node_modules/@loopwright/github-app/dist/suite-pr-lookup.js +392 -0
  301. package/node_modules/@loopwright/github-app/dist/taskpack.d.ts +1 -0
  302. package/node_modules/@loopwright/github-app/dist/taskpack.js +1 -0
  303. package/node_modules/@loopwright/github-app/dist/tenant-queue.d.ts +44 -0
  304. package/node_modules/@loopwright/github-app/dist/tenant-queue.js +423 -0
  305. package/node_modules/@loopwright/github-app/dist/token-broker.d.ts +50 -0
  306. package/node_modules/@loopwright/github-app/dist/token-broker.js +262 -0
  307. package/node_modules/@loopwright/github-app/dist/turnkey-memory.d.ts +35 -0
  308. package/node_modules/@loopwright/github-app/dist/turnkey-memory.js +1654 -0
  309. package/node_modules/@loopwright/github-app/dist/turnkey.d.ts +16 -0
  310. package/node_modules/@loopwright/github-app/dist/turnkey.js +34 -0
  311. package/node_modules/@loopwright/github-app/dist/types.d.ts +220 -0
  312. package/node_modules/@loopwright/github-app/dist/types.js +14 -0
  313. package/node_modules/@loopwright/github-app/dist/upstreams.d.ts +13 -0
  314. package/node_modules/@loopwright/github-app/dist/upstreams.js +65 -0
  315. package/node_modules/@loopwright/github-app/dist/webhook.d.ts +34 -0
  316. package/node_modules/@loopwright/github-app/dist/webhook.js +241 -0
  317. package/node_modules/@loopwright/github-app/dist/yaml.d.ts +1 -0
  318. package/node_modules/@loopwright/github-app/dist/yaml.js +1 -0
  319. package/node_modules/@loopwright/github-app/package.json +12 -0
  320. package/node_modules/@loopwright/hardware-runner/dist/config.d.ts +48 -0
  321. package/node_modules/@loopwright/hardware-runner/dist/config.js +719 -0
  322. package/node_modules/@loopwright/hardware-runner/dist/evaluator.d.ts +230 -0
  323. package/node_modules/@loopwright/hardware-runner/dist/evaluator.js +3178 -0
  324. package/node_modules/@loopwright/hardware-runner/dist/index.d.ts +13 -0
  325. package/node_modules/@loopwright/hardware-runner/dist/index.js +9 -0
  326. package/node_modules/@loopwright/hardware-runner/dist/provenance.d.ts +128 -0
  327. package/node_modules/@loopwright/hardware-runner/dist/provenance.js +1500 -0
  328. package/node_modules/@loopwright/hardware-runner/dist/queue.d.ts +81 -0
  329. package/node_modules/@loopwright/hardware-runner/dist/queue.js +1081 -0
  330. package/node_modules/@loopwright/hardware-runner/dist/relay-server.d.ts +13 -0
  331. package/node_modules/@loopwright/hardware-runner/dist/relay-server.js +2997 -0
  332. package/node_modules/@loopwright/hardware-runner/dist/types.d.ts +239 -0
  333. package/node_modules/@loopwright/hardware-runner/dist/types.js +12 -0
  334. package/node_modules/@loopwright/hardware-runner/dist/worker.d.ts +49 -0
  335. package/node_modules/@loopwright/hardware-runner/dist/worker.js +1648 -0
  336. package/node_modules/@loopwright/hardware-runner/package.json +12 -0
  337. package/node_modules/@loopwright/memory/dist/cas.d.ts +21 -0
  338. package/node_modules/@loopwright/memory/dist/cas.js +510 -0
  339. package/node_modules/@loopwright/memory/dist/compaction.d.ts +18 -0
  340. package/node_modules/@loopwright/memory/dist/compaction.js +110 -0
  341. package/node_modules/@loopwright/memory/dist/finalizer.d.ts +23 -0
  342. package/node_modules/@loopwright/memory/dist/finalizer.js +538 -0
  343. package/node_modules/@loopwright/memory/dist/index.d.ts +9 -0
  344. package/node_modules/@loopwright/memory/dist/index.js +8 -0
  345. package/node_modules/@loopwright/memory/dist/schema.d.ts +36 -0
  346. package/node_modules/@loopwright/memory/dist/schema.js +510 -0
  347. package/node_modules/@loopwright/memory/dist/selector.d.ts +7 -0
  348. package/node_modules/@loopwright/memory/dist/selector.js +157 -0
  349. package/node_modules/@loopwright/memory/dist/store.d.ts +51 -0
  350. package/node_modules/@loopwright/memory/dist/store.js +554 -0
  351. package/node_modules/@loopwright/memory/dist/types.d.ts +442 -0
  352. package/node_modules/@loopwright/memory/dist/types.js +8 -0
  353. package/node_modules/@loopwright/memory/dist/verifier.d.ts +5 -0
  354. package/node_modules/@loopwright/memory/dist/verifier.js +328 -0
  355. package/node_modules/@loopwright/memory/package.json +12 -0
  356. package/node_modules/@loopwright/state/dist/admission.d.ts +321 -0
  357. package/node_modules/@loopwright/state/dist/admission.js +199 -0
  358. package/node_modules/@loopwright/state/dist/boundary.d.ts +53 -0
  359. package/node_modules/@loopwright/state/dist/boundary.js +194 -0
  360. package/node_modules/@loopwright/state/dist/checkpoint.d.ts +16 -0
  361. package/node_modules/@loopwright/state/dist/checkpoint.js +84 -0
  362. package/node_modules/@loopwright/state/dist/clock.d.ts +8 -0
  363. package/node_modules/@loopwright/state/dist/clock.js +27 -0
  364. package/node_modules/@loopwright/state/dist/connection.d.ts +55 -0
  365. package/node_modules/@loopwright/state/dist/connection.js +391 -0
  366. package/node_modules/@loopwright/state/dist/errors.d.ts +13 -0
  367. package/node_modules/@loopwright/state/dist/errors.js +34 -0
  368. package/node_modules/@loopwright/state/dist/index.d.ts +3 -0
  369. package/node_modules/@loopwright/state/dist/index.js +1 -0
  370. package/node_modules/@loopwright/state/dist/journal.d.ts +119 -0
  371. package/node_modules/@loopwright/state/dist/journal.js +72 -0
  372. package/node_modules/@loopwright/state/dist/model.d.ts +40 -0
  373. package/node_modules/@loopwright/state/dist/model.js +58 -0
  374. package/node_modules/@loopwright/state/dist/ownership.d.ts +14 -0
  375. package/node_modules/@loopwright/state/dist/ownership.js +45 -0
  376. package/node_modules/@loopwright/state/dist/pages.d.ts +11 -0
  377. package/node_modules/@loopwright/state/dist/pages.js +41 -0
  378. package/node_modules/@loopwright/state/dist/receipts.d.ts +33 -0
  379. package/node_modules/@loopwright/state/dist/receipts.js +97 -0
  380. package/node_modules/@loopwright/state/dist/schema.d.ts +28 -0
  381. package/node_modules/@loopwright/state/dist/schema.js +41 -0
  382. package/node_modules/@loopwright/state/dist/settlement.d.ts +10 -0
  383. package/node_modules/@loopwright/state/dist/settlement.js +129 -0
  384. package/node_modules/@loopwright/state/dist/store.d.ts +52 -0
  385. package/node_modules/@loopwright/state/dist/store.js +100 -0
  386. package/node_modules/@loopwright/state/dist/types.d.ts +315 -0
  387. package/node_modules/@loopwright/state/dist/types.js +1 -0
  388. package/node_modules/@loopwright/state/package.json +12 -0
  389. package/node_modules/@loopwright/taskpack/dist/baseline-align.d.ts +195 -0
  390. package/node_modules/@loopwright/taskpack/dist/baseline-align.js +1847 -0
  391. package/node_modules/@loopwright/taskpack/dist/digests.d.ts +61 -0
  392. package/node_modules/@loopwright/taskpack/dist/digests.js +715 -0
  393. package/node_modules/@loopwright/taskpack/dist/index.d.ts +18 -0
  394. package/node_modules/@loopwright/taskpack/dist/index.js +17 -0
  395. package/node_modules/@loopwright/taskpack/dist/models-config.d.ts +112 -0
  396. package/node_modules/@loopwright/taskpack/dist/models-config.js +1026 -0
  397. package/node_modules/@loopwright/taskpack/dist/output-format.d.ts +28 -0
  398. package/node_modules/@loopwright/taskpack/dist/output-format.js +157 -0
  399. package/node_modules/@loopwright/taskpack/dist/preflight.d.ts +130 -0
  400. package/node_modules/@loopwright/taskpack/dist/preflight.js +1497 -0
  401. package/node_modules/@loopwright/taskpack/dist/qualification.d.ts +23 -0
  402. package/node_modules/@loopwright/taskpack/dist/qualification.js +120 -0
  403. package/node_modules/@loopwright/taskpack/dist/sandbox.d.ts +121 -0
  404. package/node_modules/@loopwright/taskpack/dist/sandbox.js +2642 -0
  405. package/node_modules/@loopwright/taskpack/dist/schema.d.ts +197 -0
  406. package/node_modules/@loopwright/taskpack/dist/schema.js +4189 -0
  407. package/node_modules/@loopwright/taskpack/dist/scrubber.d.ts +47 -0
  408. package/node_modules/@loopwright/taskpack/dist/scrubber.js +283 -0
  409. package/node_modules/@loopwright/taskpack/dist/suite.d.ts +124 -0
  410. package/node_modules/@loopwright/taskpack/dist/suite.js +3256 -0
  411. package/node_modules/@loopwright/taskpack/dist/taskpack.d.ts +154 -0
  412. package/node_modules/@loopwright/taskpack/dist/taskpack.js +3634 -0
  413. package/node_modules/@loopwright/taskpack/dist/turnkey-memory.d.ts +122 -0
  414. package/node_modules/@loopwright/taskpack/dist/turnkey-memory.js +483 -0
  415. package/node_modules/@loopwright/taskpack/dist/turnkey.d.ts +437 -0
  416. package/node_modules/@loopwright/taskpack/dist/turnkey.js +7335 -0
  417. package/node_modules/@loopwright/taskpack/dist/types.d.ts +1274 -0
  418. package/node_modules/@loopwright/taskpack/dist/types.js +99 -0
  419. package/node_modules/@loopwright/taskpack/dist/upstreams.d.ts +261 -0
  420. package/node_modules/@loopwright/taskpack/dist/upstreams.js +2242 -0
  421. package/node_modules/@loopwright/taskpack/dist/yaml.d.ts +18 -0
  422. package/node_modules/@loopwright/taskpack/dist/yaml.js +167 -0
  423. package/node_modules/@loopwright/taskpack/package.json +12 -0
  424. package/node_modules/@loopwright/taskpack-runner/dist/compile-taskpack.d.ts +137 -0
  425. package/node_modules/@loopwright/taskpack-runner/dist/compile-taskpack.js +474 -0
  426. package/node_modules/@loopwright/taskpack-runner/dist/corpus.d.ts +8 -0
  427. package/node_modules/@loopwright/taskpack-runner/dist/corpus.js +129 -0
  428. package/node_modules/@loopwright/taskpack-runner/dist/index.d.ts +13 -0
  429. package/node_modules/@loopwright/taskpack-runner/dist/index.js +7 -0
  430. package/node_modules/@loopwright/taskpack-runner/dist/intake.d.ts +149 -0
  431. package/node_modules/@loopwright/taskpack-runner/dist/intake.js +135 -0
  432. package/node_modules/@loopwright/taskpack-runner/dist/parity.d.ts +130 -0
  433. package/node_modules/@loopwright/taskpack-runner/dist/parity.js +927 -0
  434. package/node_modules/@loopwright/taskpack-runner/dist/python-bridge.d.ts +68 -0
  435. package/node_modules/@loopwright/taskpack-runner/dist/python-bridge.js +517 -0
  436. package/node_modules/@loopwright/taskpack-runner/dist/service.d.ts +149 -0
  437. package/node_modules/@loopwright/taskpack-runner/dist/service.js +1796 -0
  438. package/node_modules/@loopwright/taskpack-runner/dist/types.d.ts +29 -0
  439. package/node_modules/@loopwright/taskpack-runner/dist/types.js +11 -0
  440. package/node_modules/@loopwright/taskpack-runner/package.json +12 -0
  441. package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/README.md +77 -0
  442. package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/docs/support-records.md +57 -0
  443. package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/docs/supported-runners.md +98 -0
  444. package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/manifest.json +205 -0
  445. package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/pack/expand_matrix.sh +273 -0
  446. package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/pack/matrix.yaml +280 -0
  447. package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/pack/resolve_dockerfile.sh +24 -0
  448. package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/pyproject.toml +46 -0
  449. package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/runtime_runner/runner.py.json +5270 -0
  450. package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/fixtures/discovery/legacy-support.md +86 -0
  451. package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/fixtures/github/service.py +401 -0
  452. package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/fixtures/proposals/analysis.json +95 -0
  453. package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/fixtures/proposals/ready.json +109 -0
  454. package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/test_assemble.py +263 -0
  455. package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/test_check_draft.py +333 -0
  456. package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/test_checks.py +1099 -0
  457. package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/test_discovery.py +817 -0
  458. package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/test_proposal.py +658 -0
  459. package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/test_publish.py +987 -0
  460. package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tests/auto_sync/test_summary.py +107 -0
  461. package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/agent.py +610 -0
  462. package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/assemble.py +84 -0
  463. package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/check_draft.py +94 -0
  464. package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/checks.py +1002 -0
  465. package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/discovery.py +789 -0
  466. package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/model.py +557 -0
  467. package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/progress.py +174 -0
  468. package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/prompts/analysis.md +40 -0
  469. package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/prompts/proposal.md +65 -0
  470. package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/prompts/repair.md +17 -0
  471. package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/proposal.py +903 -0
  472. package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/publish.py +997 -0
  473. package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/summary.py +131 -0
  474. package/node_modules/@loopwright/taskpack-runner/vendor/runner-auto-sync/tools/auto_sync/tool-versions.json +133 -0
  475. package/node_modules/package-lock.json +3025 -0
  476. package/package-lock.json +3025 -0
  477. package/package.json +52 -4
@@ -0,0 +1,1308 @@
1
+ import { Worker } from 'node:worker_threads';
2
+ import { closeSync, constants, fstatSync, lstatSync, openSync, readSync } from 'node:fs';
3
+ import { open } from 'node:fs/promises';
4
+ import { isAbsolute, join } from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
6
+ import { bindSubject, digestArtifact, validateDocument, } from '@loopwright/core';
7
+ import { checkedRef, stateValue } from './storage.js';
8
+ import { readBoundedFile } from './files.js';
9
+ import { descriptor, encodeInventory, encodePacket, fileHash, inventoryEncodedBytes, JSON_FILE_BYTES, maxPacketBytes, overlayProtocolBounds, ownedBytes, packetSize, checkedHeader, HEADER_BYTES, RFC6901_POINTER_PATTERN, } from './verifier-protocol.js';
10
+ import { checkedDetail, checkedFindings, checkedMetrics } from './gate.js';
11
+ import { canonical, freeze, hash, integer, isRecord, list, record, same, text } from './schema.js';
12
+ import { parsePrivateJson } from './parser.js';
13
+ import { ControllerFailure, refuse } from './errors.js';
14
+ import { verifierOperationId, phaseCheckpointId, ProgressStore, validateProgress, journal } from './progress.js';
15
+ import { sizeJob, VerifierSizingFailure, checkedRefusalRecord } from './refusal-record.js';
16
+ const preparedJobs = new WeakMap();
17
+ function validateInventoryAlignment(input, overlay) {
18
+ const bounds = overlayProtocolBounds(overlay);
19
+ descriptor(input.manifest, input.ref, overlay);
20
+ const maxEntries = input.manifest.spec.baseTree !== undefined ? bounds.maxOverlayEntries : bounds.maxClassicEntries;
21
+ if (input.files.length !== input.manifest.spec.entries.length ||
22
+ input.files.length > maxEntries) {
23
+ refuse('ARTIFACT_INVALID', '', 'verification');
24
+ }
25
+ const byName = new Map();
26
+ for (const file of input.files) {
27
+ if (byName.has(file.name))
28
+ refuse('ARTIFACT_INVALID', '', 'verification');
29
+ byName.set(file.name, file);
30
+ }
31
+ let total = 0;
32
+ const validated = new Map();
33
+ for (const entry of input.manifest.spec.entries) {
34
+ const file = byName.get(entry.name);
35
+ if (!file || (total += entry.byteLength) > bounds.maxTotalBytes)
36
+ refuse('ARTIFACT_INVALID', '', 'verification');
37
+ if ('bytes' in file) {
38
+ if ('blobPath' in file)
39
+ refuse('ARTIFACT_INVALID', '', 'verification');
40
+ const bytes = ownedBytes(file.bytes, bounds.maxTotalBytes);
41
+ if (bytes.byteLength !== entry.byteLength || !same(fileHash(bytes), entry.digest))
42
+ refuse('ARTIFACT_INVALID', '', 'verification');
43
+ validated.set(entry.name, { name: entry.name, bytes });
44
+ }
45
+ else {
46
+ if (typeof file.blobPath !== 'string' ||
47
+ !isAbsolute(file.blobPath) ||
48
+ file.blobPath.length > 4096 ||
49
+ /[\0\r\n]/.test(file.blobPath) ||
50
+ file.byteLength !== entry.byteLength ||
51
+ !same(file.digest, entry.digest)) {
52
+ refuse('ARTIFACT_INVALID', '', 'verification');
53
+ }
54
+ validated.set(entry.name, file);
55
+ }
56
+ }
57
+ return validated;
58
+ }
59
+ function resolveTargetOverlayFileSync(file) {
60
+ if ('bytes' in file) {
61
+ return {
62
+ logicalBytes: file.bytes.byteLength,
63
+ bytes: file.bytes.byteLength > JSON_FILE_BYTES ? null : file.bytes,
64
+ };
65
+ }
66
+ if (file.byteLength > JSON_FILE_BYTES) {
67
+ return { logicalBytes: file.byteLength, bytes: null };
68
+ }
69
+ let before;
70
+ try {
71
+ before = lstatSync(file.blobPath);
72
+ }
73
+ catch {
74
+ refuse('ARTIFACT_INVALID', '', 'verification');
75
+ }
76
+ if (before.isSymbolicLink() ||
77
+ !before.isFile() ||
78
+ before.nlink !== 1 ||
79
+ before.uid !== process.getuid?.() ||
80
+ (before.mode & 0o222) !== 0 ||
81
+ before.size !== file.byteLength) {
82
+ refuse('ARTIFACT_INVALID', '', 'verification');
83
+ }
84
+ let fd;
85
+ try {
86
+ fd = openSync(file.blobPath, constants.O_RDONLY | constants.O_NOFOLLOW);
87
+ }
88
+ catch {
89
+ refuse('ARTIFACT_INVALID', '', 'verification');
90
+ }
91
+ try {
92
+ const info = fstatSync(fd);
93
+ if (!info.isFile() ||
94
+ info.nlink !== 1 ||
95
+ info.dev !== before.dev ||
96
+ info.ino !== before.ino ||
97
+ info.size !== file.byteLength ||
98
+ (info.mode & 0o222) !== 0) {
99
+ refuse('ARTIFACT_INVALID', '', 'verification');
100
+ }
101
+ const raw = Buffer.alloc(info.size + 1);
102
+ let offset = 0;
103
+ while (offset < raw.length) {
104
+ const bytesRead = readSync(fd, raw, offset, raw.length - offset, offset);
105
+ if (bytesRead <= 0)
106
+ break;
107
+ offset += bytesRead;
108
+ }
109
+ const after = fstatSync(fd);
110
+ if (offset !== info.size ||
111
+ after.nlink !== 1 ||
112
+ after.size !== info.size ||
113
+ after.mtimeMs !== info.mtimeMs ||
114
+ after.ctimeMs !== info.ctimeMs) {
115
+ refuse('ARTIFACT_INVALID', '', 'verification');
116
+ }
117
+ const slice = new Uint8Array(raw.buffer, raw.byteOffset, offset);
118
+ if (!same(fileHash(slice), file.digest))
119
+ refuse('ARTIFACT_INVALID', '', 'verification');
120
+ return { logicalBytes: slice.byteLength, bytes: slice };
121
+ }
122
+ finally {
123
+ closeSync(fd);
124
+ }
125
+ }
126
+ function validateBaselineProof(proof, baseTree) {
127
+ const blobBytes = ownedBytes(proof.blob, 8_388_608);
128
+ const treeBytes = proof.trees.map(tree => ownedBytes(tree, 4_194_304));
129
+ const oidPattern = baseTree.objectFormat === 'sha256' ? /^[0-9a-f]{64}$/ : /^[0-9a-f]{40}$/;
130
+ if (!Number.isSafeInteger(proof.byteLength) || proof.byteLength < 0 || !oidPattern.test(proof.oid)) {
131
+ refuse('ARTIFACT_INVALID', '', 'verification');
132
+ }
133
+ if (proof.mode !== '100644' && proof.mode !== '100755')
134
+ refuse('ARTIFACT_INVALID', '', 'verification');
135
+ if (proof.treeCount !== undefined && (!Number.isSafeInteger(proof.treeCount) || proof.treeCount < 0)) {
136
+ refuse('ARTIFACT_INVALID', '', 'verification');
137
+ }
138
+ if (proof.treeProofBytes !== undefined && (!Number.isSafeInteger(proof.treeProofBytes) || proof.treeProofBytes < 0)) {
139
+ refuse('ARTIFACT_INVALID', '', 'verification');
140
+ }
141
+ const treeCount = proof.treeCount ?? treeBytes.length;
142
+ const treeProofBytes = proof.treeProofBytes ?? treeBytes.reduce((sum, tree) => sum + tree.byteLength, 0);
143
+ const isOversizeProof = treeCount > 16 || treeProofBytes > 262_144 || proof.byteLength > 4_194_304;
144
+ if (!isOversizeProof && blobBytes.byteLength !== proof.byteLength)
145
+ refuse('ARTIFACT_INVALID', '', 'verification');
146
+ return {
147
+ mode: proof.mode,
148
+ oid: proof.oid,
149
+ byteLength: proof.byteLength,
150
+ blob: blobBytes,
151
+ trees: treeBytes,
152
+ merkle: { treeCount, treeProofBytes },
153
+ logicalBytes: proof.byteLength > blobBytes.byteLength ? proof.byteLength : blobBytes.byteLength,
154
+ };
155
+ }
156
+ function writeProofSection(payload, view, startOffset, proof) {
157
+ let offset = startOffset;
158
+ view.setUint32(offset, proof.blob.byteLength);
159
+ offset += 4;
160
+ payload.set(proof.blob, offset);
161
+ offset += proof.blob.byteLength;
162
+ view.setUint32(offset, proof.trees.length);
163
+ offset += 4;
164
+ for (const tree of proof.trees) {
165
+ view.setUint32(offset, tree.byteLength);
166
+ offset += 4;
167
+ payload.set(tree, offset);
168
+ offset += tree.byteLength;
169
+ }
170
+ return offset;
171
+ }
172
+ /** Pure byte preflight: no owner, state intent, Worker, timer, credential or network operation. */
173
+ export function prepareVerification(plan, lock, slotId, source, candidate, generation, producerNonce) {
174
+ if (!same(plan.task, lock.spec.contract) || !/^[a-f0-9]{32}$/.test(producerNonce))
175
+ refuse('ARTIFACT_INVALID', '', 'verification');
176
+ integer(generation, 0, plan.capacity.V - 1);
177
+ const slot = plan.verifierSlots.find(item => item.id === slotId);
178
+ if (!slot || slot.handler.kind !== 'check')
179
+ refuse('CAPABILITY_UNSUPPORTED', '', 'verification');
180
+ const overlay = lock.spec.contract.spec.budgets.overlay;
181
+ const overlayOpts = overlay ? { overlay } : undefined;
182
+ const sourceFiles = validateInventoryAlignment(source, overlay);
183
+ const files = validateInventoryAlignment(candidate, overlay);
184
+ const subject = bindSubject(lock, candidate.manifest, overlayOpts);
185
+ if (!subject.ok)
186
+ refuse('ARTIFACT_INVALID', '', 'verification');
187
+ if ((source.manifest.spec.baseTree === undefined) !== (candidate.manifest.spec.baseTree === undefined) ||
188
+ !same(source.manifest.spec.baseTree ?? null, candidate.manifest.spec.baseTree ?? null)) {
189
+ refuse('ARTIFACT_INVALID', '', 'verification');
190
+ }
191
+ const operationId = verifierOperationId(lock.spec.runId, slotId, generation);
192
+ const handler = slot.handler.implementation;
193
+ const firstInvBytes = inventoryEncodedBytes(source.manifest);
194
+ const secondInvBytes = inventoryEncodedBytes(candidate.manifest);
195
+ const invSizing = { firstBytes: firstInvBytes, secondBytes: secondInvBytes };
196
+ let parameters;
197
+ let payload;
198
+ let payloadKind;
199
+ let jsonBytes;
200
+ let merkle;
201
+ if (handler === 'json-artifact.v1') {
202
+ payloadKind = 'json';
203
+ const path = text(slot.handler.parameters.path);
204
+ const overlaySelected = candidate.manifest.spec.entries.find(entry => entry.name === path) ?? null;
205
+ const baseTree = candidate.manifest.spec.baseTree;
206
+ const isDeleted = (candidate.manifest.spec.deleted ?? []).includes(path);
207
+ const rawProof = !overlaySelected && !isDeleted && baseTree !== undefined && source.baselineProofs && Object.hasOwn(source.baselineProofs, path)
208
+ ? source.baselineProofs[path] ?? null
209
+ : null;
210
+ let expected = overlaySelected;
211
+ let selected;
212
+ let validatedProof = null;
213
+ if (baseTree !== undefined && !overlaySelected) {
214
+ if (isDeleted || rawProof === null) {
215
+ expected = null;
216
+ jsonBytes = 0;
217
+ }
218
+ else {
219
+ validatedProof = validateBaselineProof(rawProof, baseTree);
220
+ expected = { baseline: true, mode: validatedProof.mode, oid: validatedProof.oid, byteLength: validatedProof.byteLength };
221
+ jsonBytes = validatedProof.logicalBytes;
222
+ merkle = validatedProof.merkle;
223
+ }
224
+ }
225
+ else if (overlaySelected) {
226
+ const resolved = resolveTargetOverlayFileSync(files.get(path));
227
+ selected = resolved.bytes;
228
+ jsonBytes = resolved.logicalBytes;
229
+ }
230
+ else {
231
+ selected = undefined;
232
+ jsonBytes = 0;
233
+ }
234
+ parameters = {
235
+ path,
236
+ expected,
237
+ required: slot.handler.parameters.required,
238
+ equals: slot.handler.parameters.equals,
239
+ };
240
+ const targetBytes = validatedProof !== null
241
+ ? 4 + validatedProof.blob.byteLength + 4 + validatedProof.trees.reduce((sum, tree) => sum + 4 + tree.byteLength, 0)
242
+ : 4 + jsonBytes;
243
+ const sizedPayloadBytes = firstInvBytes + secondInvBytes + targetBytes;
244
+ const header = checkedHeader({
245
+ version: 1,
246
+ jobId: 'job.' + hash(operationId + '\0' + producerNonce).hex.slice(0, 40),
247
+ handler,
248
+ handlerVersion: 1,
249
+ handlerDigest: slot.handler.digest,
250
+ checkId: slot.checkId,
251
+ producerNonce,
252
+ operationId,
253
+ dispatchId: 'unbound',
254
+ generation,
255
+ subject: subject.value,
256
+ source: descriptor(source.manifest, source.ref, overlay),
257
+ candidate: descriptor(candidate.manifest, candidate.ref, overlay),
258
+ parameters,
259
+ payloadKind,
260
+ ...(overlay !== undefined ? { overlay } : {}),
261
+ });
262
+ sizeJob(header, sizedPayloadBytes, jsonBytes, merkle, invSizing);
263
+ const firstInv = encodeInventory(source.manifest, overlay);
264
+ const secondInv = encodeInventory(candidate.manifest, overlay);
265
+ payload = new Uint8Array(sizedPayloadBytes);
266
+ const view = new DataView(payload.buffer);
267
+ let offset = 0;
268
+ payload.set(firstInv, offset);
269
+ offset += firstInv.byteLength;
270
+ payload.set(secondInv, offset);
271
+ offset += secondInv.byteLength;
272
+ if (validatedProof !== null) {
273
+ writeProofSection(payload, view, offset, validatedProof);
274
+ }
275
+ else {
276
+ view.setUint32(offset, selected?.byteLength ?? 0);
277
+ offset += 4;
278
+ if (selected)
279
+ payload.set(selected, offset);
280
+ }
281
+ const packetBytes = packetSize(header, payload.byteLength);
282
+ const requestDigest = hash('loopwright.dev/controller/verifier-request/v1\0' + canonical({ planDigest: plan.planDigest, header, payloadDigest: hash(payload) }));
283
+ const sealed = freeze(checkedHeader(parsePrivateJson(Buffer.from(canonical(header)), HEADER_BYTES)));
284
+ const value = freeze({ version: 1, slotId, generation, operationId, producerNonce, packetBytes, requestDigest });
285
+ preparedJobs.set(value, { header: sealed, payload, slot });
286
+ return value;
287
+ }
288
+ if (handler === 'json-keys-guard.v1' || handler === 'line-section-guard.v1') {
289
+ payloadKind = 'guard';
290
+ const path = text(slot.handler.parameters.path);
291
+ const baseTree = candidate.manifest.spec.baseTree;
292
+ const sourceSelected = source.manifest.spec.entries.find(entry => entry.name === path) ?? null;
293
+ const sourceDeleted = (source.manifest.spec.deleted ?? []).includes(path);
294
+ const candSelected = candidate.manifest.spec.entries.find(entry => entry.name === path) ?? null;
295
+ const candDeleted = (candidate.manifest.spec.deleted ?? []).includes(path);
296
+ let baselineParam;
297
+ let baseOverlayBytes;
298
+ let hasBaseOverlay = false;
299
+ let validatedProof = null;
300
+ let baseLogicalBytes = 0;
301
+ if (!baseTree) {
302
+ if (sourceSelected !== null) {
303
+ const resolved = resolveTargetOverlayFileSync(sourceFiles.get(path));
304
+ baseOverlayBytes = resolved.bytes;
305
+ hasBaseOverlay = true;
306
+ baselineParam = { kind: 'overlay', entry: sourceSelected };
307
+ baseLogicalBytes = resolved.logicalBytes;
308
+ }
309
+ else {
310
+ baselineParam = { kind: 'missing' };
311
+ }
312
+ }
313
+ else if (sourceSelected !== null) {
314
+ const resolved = resolveTargetOverlayFileSync(sourceFiles.get(path));
315
+ baseOverlayBytes = resolved.bytes;
316
+ hasBaseOverlay = true;
317
+ baselineParam = { kind: 'overlay', entry: sourceSelected };
318
+ baseLogicalBytes = resolved.logicalBytes;
319
+ }
320
+ else if (sourceDeleted) {
321
+ baselineParam = { kind: 'missing' };
322
+ }
323
+ else {
324
+ const rawProof = source.baselineProofs && Object.hasOwn(source.baselineProofs, path) ? source.baselineProofs[path] ?? null : null;
325
+ if (rawProof === null) {
326
+ baselineParam = { kind: 'missing' };
327
+ }
328
+ else {
329
+ validatedProof = validateBaselineProof(rawProof, source.manifest.spec.baseTree);
330
+ baselineParam = { kind: 'merkle_blob', mode: validatedProof.mode, oid: validatedProof.oid, byteLength: validatedProof.byteLength };
331
+ baseLogicalBytes = validatedProof.logicalBytes;
332
+ merkle = validatedProof.merkle;
333
+ }
334
+ }
335
+ let candidateParam;
336
+ let candOverlayBytes;
337
+ let hasCandOverlay = false;
338
+ let candLogicalBytes = 0;
339
+ if (!baseTree) {
340
+ if (candSelected !== null) {
341
+ const resolved = resolveTargetOverlayFileSync(files.get(path));
342
+ candOverlayBytes = resolved.bytes;
343
+ hasCandOverlay = true;
344
+ candidateParam = { kind: 'overlay', entry: candSelected };
345
+ candLogicalBytes = resolved.logicalBytes;
346
+ }
347
+ else {
348
+ candidateParam = { kind: 'missing' };
349
+ }
350
+ }
351
+ else if (candSelected !== null) {
352
+ const resolved = resolveTargetOverlayFileSync(files.get(path));
353
+ candOverlayBytes = resolved.bytes;
354
+ hasCandOverlay = true;
355
+ candidateParam = { kind: 'overlay', entry: candSelected };
356
+ candLogicalBytes = resolved.logicalBytes;
357
+ }
358
+ else if (candDeleted) {
359
+ candidateParam = { kind: 'deleted' };
360
+ }
361
+ else {
362
+ candidateParam = { kind: 'unchanged_baseline' };
363
+ }
364
+ jsonBytes = Math.max(baseLogicalBytes, candLogicalBytes);
365
+ parameters = (handler === 'json-keys-guard.v1'
366
+ ? { path, baseline: baselineParam, candidate: candidateParam, allowedPointers: slot.handler.parameters.allowedPointers }
367
+ : {
368
+ path,
369
+ baseline: baselineParam,
370
+ candidate: candidateParam,
371
+ startMarker: slot.handler.parameters.startMarker,
372
+ endMarker: slot.handler.parameters.endMarker,
373
+ });
374
+ const baseSectionBytes = validatedProof !== null
375
+ ? 4 + validatedProof.blob.byteLength + 4 + validatedProof.trees.reduce((sum, tree) => sum + 4 + tree.byteLength, 0)
376
+ : hasBaseOverlay
377
+ ? 4 + baseLogicalBytes
378
+ : 0;
379
+ const candSectionBytes = hasCandOverlay ? 4 + candLogicalBytes : 0;
380
+ const sizedPayloadBytes = firstInvBytes + secondInvBytes + baseSectionBytes + candSectionBytes;
381
+ const header = checkedHeader({
382
+ version: 1,
383
+ jobId: 'job.' + hash(operationId + '\0' + producerNonce).hex.slice(0, 40),
384
+ handler,
385
+ handlerVersion: 1,
386
+ handlerDigest: slot.handler.digest,
387
+ checkId: slot.checkId,
388
+ producerNonce,
389
+ operationId,
390
+ dispatchId: 'unbound',
391
+ generation,
392
+ subject: subject.value,
393
+ source: descriptor(source.manifest, source.ref, overlay),
394
+ candidate: descriptor(candidate.manifest, candidate.ref, overlay),
395
+ parameters,
396
+ payloadKind,
397
+ ...(overlay !== undefined ? { overlay } : {}),
398
+ });
399
+ sizeJob(header, sizedPayloadBytes, jsonBytes, merkle, invSizing);
400
+ const firstInv = encodeInventory(source.manifest, overlay);
401
+ const secondInv = encodeInventory(candidate.manifest, overlay);
402
+ payload = new Uint8Array(sizedPayloadBytes);
403
+ const view = new DataView(payload.buffer);
404
+ let offset = 0;
405
+ payload.set(firstInv, offset);
406
+ offset += firstInv.byteLength;
407
+ payload.set(secondInv, offset);
408
+ offset += secondInv.byteLength;
409
+ if (validatedProof !== null) {
410
+ offset = writeProofSection(payload, view, offset, validatedProof);
411
+ }
412
+ else if (baseOverlayBytes) {
413
+ view.setUint32(offset, baseOverlayBytes.byteLength);
414
+ offset += 4;
415
+ payload.set(baseOverlayBytes, offset);
416
+ offset += baseOverlayBytes.byteLength;
417
+ }
418
+ if (candOverlayBytes) {
419
+ view.setUint32(offset, candOverlayBytes.byteLength);
420
+ offset += 4;
421
+ payload.set(candOverlayBytes, offset);
422
+ }
423
+ const packetBytes = packetSize(header, payload.byteLength);
424
+ const requestDigest = hash('loopwright.dev/controller/verifier-request/v1\0' + canonical({ planDigest: plan.planDigest, header, payloadDigest: hash(payload) }));
425
+ const sealed = freeze(checkedHeader(parsePrivateJson(Buffer.from(canonical(header)), HEADER_BYTES)));
426
+ const value = freeze({ version: 1, slotId, generation, operationId, producerNonce, packetBytes, requestDigest });
427
+ preparedJobs.set(value, { header: sealed, payload, slot });
428
+ return value;
429
+ }
430
+ if (!['scope.v1', 'no-change.v1'].includes(handler))
431
+ refuse('CAPABILITY_UNSUPPORTED', '', 'verification');
432
+ payloadKind = 'inventories';
433
+ parameters = handler === 'scope.v1' ? { contract: plan.task } : {};
434
+ const sizedPayloadBytes = firstInvBytes + secondInvBytes;
435
+ const header = checkedHeader({
436
+ version: 1,
437
+ jobId: 'job.' + hash(operationId + '\0' + producerNonce).hex.slice(0, 40),
438
+ handler,
439
+ handlerVersion: 1,
440
+ handlerDigest: slot.handler.digest,
441
+ checkId: slot.checkId,
442
+ producerNonce,
443
+ operationId,
444
+ dispatchId: 'unbound',
445
+ generation,
446
+ subject: subject.value,
447
+ source: descriptor(source.manifest, source.ref, overlay),
448
+ candidate: descriptor(candidate.manifest, candidate.ref, overlay),
449
+ parameters,
450
+ payloadKind,
451
+ ...(overlay !== undefined ? { overlay } : {}),
452
+ });
453
+ sizeJob(header, sizedPayloadBytes, null, undefined, invSizing);
454
+ const firstInv = encodeInventory(source.manifest, overlay);
455
+ const secondInv = encodeInventory(candidate.manifest, overlay);
456
+ payload = new Uint8Array(sizedPayloadBytes);
457
+ payload.set(firstInv, 0);
458
+ payload.set(secondInv, firstInv.byteLength);
459
+ const packetBytes = packetSize(header, payload.byteLength);
460
+ const requestDigest = hash('loopwright.dev/controller/verifier-request/v1\0' + canonical({ planDigest: plan.planDigest, header, payloadDigest: hash(payload) }));
461
+ const sealed = freeze(checkedHeader(parsePrivateJson(Buffer.from(canonical(header)), HEADER_BYTES)));
462
+ const value = freeze({ version: 1, slotId, generation, operationId, producerNonce, packetBytes, requestDigest });
463
+ preparedJobs.set(value, { header: sealed, payload, slot });
464
+ return value;
465
+ }
466
+ const refusalPreparations = new WeakMap();
467
+ /** Ready jobs keep the original API. Only the dedicated pure sizing exception can create a negative preparation. */
468
+ export function preflightVerification(plan, lock, slotId, source, candidate, generation, producerNonce) {
469
+ const { planDigest, ...unsigned } = plan;
470
+ if (!same(hash('loopwright.dev/controller/plan/v1\0' + canonical(unsigned)), planDigest) || !validateDocument(lock, 'TaskLock').ok) {
471
+ refuse('ARTIFACT_INVALID', '', 'verification');
472
+ }
473
+ const slot = plan.verifierSlots.find(item => item.id === slotId);
474
+ if (!slot || slot.handler.kind !== 'check')
475
+ refuse('CAPABILITY_UNSUPPORTED', '', 'verification');
476
+ const parameters = slot.handler.parameters;
477
+ if (slot.handler.implementation === 'json-artifact.v1') {
478
+ record(parameters, ['checkId', 'path', 'required', 'equals']);
479
+ if (parameters.checkId !== slot.checkId || !digestArtifact(text(parameters.path), new Uint8Array()).ok) {
480
+ refuse('CAPABILITY_UNSUPPORTED', '', 'verification');
481
+ }
482
+ const required = list(parameters.required, '', 128).map(value => text(value, '', 128));
483
+ if (new Set(required).size !== required.length ||
484
+ parameters.equals === null ||
485
+ typeof parameters.equals !== 'object' ||
486
+ Array.isArray(parameters.equals)) {
487
+ refuse('CAPABILITY_UNSUPPORTED', '', 'verification');
488
+ }
489
+ const equals = record(parameters.equals, Object.keys(parameters.equals));
490
+ if (Object.keys(equals).length > 128 ||
491
+ Object.values(equals).some(value => (value !== null && !['string', 'boolean', 'number'].includes(typeof value)) || (typeof value === 'number' && !Number.isSafeInteger(value)))) {
492
+ refuse('CAPABILITY_UNSUPPORTED', '', 'verification');
493
+ }
494
+ }
495
+ else if (slot.handler.implementation === 'json-keys-guard.v1') {
496
+ record(parameters, ['checkId', 'path', 'allowedPointers']);
497
+ if (parameters.checkId !== slot.checkId || !digestArtifact(text(parameters.path, '', 1024), new Uint8Array()).ok) {
498
+ refuse('CAPABILITY_UNSUPPORTED', '', 'verification');
499
+ }
500
+ const pointers = list(parameters.allowedPointers, '', 128).map(value => text(value, '', 256));
501
+ if (pointers.length < 1 || pointers.some(ptr => !RFC6901_POINTER_PATTERN.test(ptr))) {
502
+ refuse('CAPABILITY_UNSUPPORTED', '', 'verification');
503
+ }
504
+ }
505
+ else if (slot.handler.implementation === 'line-section-guard.v1') {
506
+ record(parameters, ['checkId', 'path', 'startMarker', 'endMarker']);
507
+ if (parameters.checkId !== slot.checkId || !digestArtifact(text(parameters.path, '', 1024), new Uint8Array()).ok) {
508
+ refuse('CAPABILITY_UNSUPPORTED', '', 'verification');
509
+ }
510
+ const startMarker = text(parameters.startMarker, '', 256);
511
+ const endMarker = text(parameters.endMarker, '', 256);
512
+ if (startMarker.length < 1 ||
513
+ endMarker.length < 1 ||
514
+ startMarker === endMarker ||
515
+ /[\r\n]/.test(startMarker) ||
516
+ /[\r\n]/.test(endMarker)) {
517
+ refuse('CAPABILITY_UNSUPPORTED', '', 'verification');
518
+ }
519
+ }
520
+ else {
521
+ record(parameters, ['checkId']);
522
+ if (!['scope.v1', 'no-change.v1'].includes(slot.handler.implementation) ||
523
+ parameters.checkId !== (slot.implicit === null ? slot.checkId : null)) {
524
+ refuse('CAPABILITY_UNSUPPORTED', '', 'verification');
525
+ }
526
+ }
527
+ try {
528
+ return { kind: 'ready', job: prepareVerification(plan, lock, slotId, source, candidate, generation, producerNonce) };
529
+ }
530
+ catch (error) {
531
+ if (!(error instanceof VerifierSizingFailure))
532
+ throw error;
533
+ const overlay = lock.spec.contract.spec.budgets.overlay;
534
+ const overlayOpts = overlay ? { overlay } : undefined;
535
+ const subject = bindSubject(lock, candidate.manifest, overlayOpts);
536
+ if (!subject.ok)
537
+ refuse('ARTIFACT_INVALID', '', 'verification');
538
+ const prospectiveOperationId = verifierOperationId(lock.spec.runId, slotId, generation);
539
+ const value = freeze({
540
+ version: 1,
541
+ kind: 'controller_preflight_refusal',
542
+ planDigest,
543
+ handlerDigest: slot.handler.digest,
544
+ slotId,
545
+ checkId: slot.checkId,
546
+ generation,
547
+ prospectiveOperationId,
548
+ producerNonce,
549
+ subject: subject.value,
550
+ source: descriptor(source.manifest, source.ref, overlay),
551
+ candidate: descriptor(candidate.manifest, candidate.ref, overlay),
552
+ code: 'OUTPUT_LIMIT',
553
+ limits: error.sizing,
554
+ });
555
+ const prepared = freeze({ slotId, generation, prospectiveOperationId, producerNonce });
556
+ refusalPreparations.set(prepared, {
557
+ value: freeze(parsePrivateJson(Buffer.from(canonical(value)), 65536)),
558
+ plan,
559
+ source,
560
+ candidate,
561
+ slot,
562
+ });
563
+ return { kind: 'refused', prepared };
564
+ }
565
+ }
566
+ const refusalObservations = new WeakMap();
567
+ export function authenticatedRefusal(input) {
568
+ const value = refusalObservations.get(input);
569
+ if (!value)
570
+ refuse('EVIDENCE_UNAVAILABLE', '', 'verification');
571
+ return value;
572
+ }
573
+ /** Private containment primitive. Production always supplies the fixed verifier module, never a task/config path. */
574
+ export function boundedWorker(module, packet, signal, ports = {}) {
575
+ signal.throwIfAborted();
576
+ const expectedOldMb = ports.maxOldGenerationSizeMb ?? 64;
577
+ const timeoutMs = ports.timeoutMs ?? 2000;
578
+ const started = performance.now();
579
+ const worker = new Worker(module, {
580
+ workerData: packet,
581
+ transferList: [packet.buffer],
582
+ env: {},
583
+ execArgv: [],
584
+ resourceLimits: { maxOldGenerationSizeMb: expectedOldMb, maxYoungGenerationSizeMb: 8, stackSizeMb: 2 },
585
+ });
586
+ const threadId = worker.threadId;
587
+ let limits = {
588
+ oldMb: worker.resourceLimits?.maxOldGenerationSizeMb ?? -1,
589
+ youngMb: worker.resourceLimits?.maxYoungGenerationSizeMb ?? -1,
590
+ stackMb: worker.resourceLimits?.stackSizeMb ?? -1,
591
+ };
592
+ let reply = null;
593
+ let count = 0;
594
+ let kind = 'reply';
595
+ let invalid = false;
596
+ let errorCode = null;
597
+ return new Promise((resolve, reject) => {
598
+ let stopTimer = null;
599
+ let finished = false;
600
+ const stop = (next) => {
601
+ if (finished || stopTimer)
602
+ return;
603
+ kind = next;
604
+ stopTimer = setTimeout(() => {
605
+ if (!finished) {
606
+ finished = true;
607
+ clearTimeout(timer);
608
+ signal.removeEventListener('abort', abort);
609
+ reject(new ControllerFailure({
610
+ version: 1,
611
+ code: 'CLEANUP_FAILED',
612
+ phase: 'verification',
613
+ path: '',
614
+ stateCode: null,
615
+ piCode: null,
616
+ effect: 'possible',
617
+ retryable: false,
618
+ }));
619
+ }
620
+ }, 1000);
621
+ void worker.terminate().catch(() => {
622
+ /* Exact exit or cleanup timeout decides; no replacement Worker. */
623
+ });
624
+ };
625
+ const abort = () => stop('cancelled');
626
+ const timer = setTimeout(() => stop('timeout'), timeoutMs);
627
+ signal.addEventListener('abort', abort, { once: true });
628
+ worker.on('message', (raw) => {
629
+ if (++count !== 1 || !(raw instanceof Uint8Array) || raw.byteLength > 65536 || raw.buffer instanceof SharedArrayBuffer) {
630
+ invalid = true;
631
+ stop('failed');
632
+ }
633
+ else {
634
+ reply = ownedBytes(raw, 65536);
635
+ }
636
+ });
637
+ worker.once('error', (error) => {
638
+ errorCode = error.code === 'ERR_WORKER_OUT_OF_MEMORY' ? error.code : 'WORKER_ERROR';
639
+ if (kind === 'reply')
640
+ kind = 'failed';
641
+ });
642
+ worker.once('exit', exit => {
643
+ if (finished)
644
+ return;
645
+ finished = true;
646
+ clearTimeout(timer);
647
+ if (stopTimer)
648
+ clearTimeout(stopTimer);
649
+ signal.removeEventListener('abort', abort);
650
+ if ((exit !== 0 && kind === 'reply') || invalid || (count !== 1 && kind === 'reply'))
651
+ kind = 'failed';
652
+ resolve({ kind, reply, threadId, exit, errorCode, limits, elapsedMs: performance.now() - started });
653
+ });
654
+ if (ports.limits) {
655
+ try {
656
+ const observed = ports.limits(worker.resourceLimits);
657
+ limits = {
658
+ oldMb: observed?.maxOldGenerationSizeMb ?? -1,
659
+ youngMb: observed?.maxYoungGenerationSizeMb ?? -1,
660
+ stackMb: observed?.stackSizeMb ?? -1,
661
+ };
662
+ }
663
+ catch {
664
+ invalid = true;
665
+ stop('failed');
666
+ }
667
+ }
668
+ if (limits.oldMb !== expectedOldMb || limits.youngMb !== 8 || limits.stackMb !== 2)
669
+ stop('failed');
670
+ else if (signal.aborted)
671
+ abort();
672
+ });
673
+ }
674
+ const observations = new WeakMap();
675
+ export function authenticatedCheck(value) {
676
+ const trusted = observations.get(value);
677
+ if (!trusted)
678
+ refuse('EVIDENCE_UNAVAILABLE', '', 'verification');
679
+ return trusted;
680
+ }
681
+ const EXPECTED_METHODS = {
682
+ 'scope.v1': 'verify_scope',
683
+ 'no-change.v1': 'verify_no_change',
684
+ 'json-artifact.v1': 'verify_json',
685
+ 'json-keys-guard.v1': 'verify_json_keys_guard',
686
+ 'line-section-guard.v1': 'verify_line_section_guard',
687
+ };
688
+ const ALLOWED_REASONS = {
689
+ 'scope.v1': ['outside_scope'],
690
+ 'no-change.v1': ['candidate_changed'],
691
+ 'json-artifact.v1': ['missing_file', 'invalid_json', 'property_missing', 'property_mismatch'],
692
+ 'json-keys-guard.v1': ['missing_file', 'invalid_json', 'disallowed_json_pointer'],
693
+ 'line-section-guard.v1': ['missing_file', 'invalid_utf8', 'missing_markers', 'unbalanced_markers', 'outside_section_modified'],
694
+ };
695
+ function checkedReply(input, header, packetDigest) {
696
+ if (!isRecord(input))
697
+ refuse('RECOVERY_REQUIRED', '', 'verification');
698
+ const hasDetail = Object.hasOwn(input, 'detail') && input.detail !== undefined;
699
+ const hasMetrics = Object.hasOwn(input, 'metrics') && input.metrics !== undefined;
700
+ const hasFindings = Object.hasOwn(input, 'findings') && input.findings !== undefined;
701
+ const raw = record(input, [
702
+ 'version', 'jobId', 'handler', 'handlerDigest', 'checkId', 'producerNonce',
703
+ 'operationId', 'dispatchId', 'generation', 'subject', 'packetDigest', 'status', 'reason', 'method', 'allocationBytes',
704
+ ...(hasDetail ? ['detail'] : []),
705
+ ...(hasMetrics ? ['metrics'] : []),
706
+ ...(hasFindings ? ['findings'] : []),
707
+ ]);
708
+ const expected = {
709
+ version: 1,
710
+ jobId: header.jobId,
711
+ handler: header.handler,
712
+ handlerDigest: header.handlerDigest,
713
+ checkId: header.checkId,
714
+ producerNonce: header.producerNonce,
715
+ operationId: header.operationId,
716
+ dispatchId: header.dispatchId,
717
+ generation: header.generation,
718
+ subject: header.subject,
719
+ packetDigest,
720
+ };
721
+ const binding = Object.fromEntries(Object.keys(expected).map(key => [key, raw[key]]));
722
+ if (!same(binding, expected) ||
723
+ !['passed', 'failed'].includes(text(raw.status)) ||
724
+ (raw.status === 'passed') !== (raw.reason === null) ||
725
+ raw.method !== EXPECTED_METHODS[header.handler]) {
726
+ refuse('RECOVERY_REQUIRED', '', 'verification');
727
+ }
728
+ const bounds = overlayProtocolBounds(header.overlay);
729
+ integer(raw.allocationBytes, 0, bounds.allocationMaxBytes);
730
+ if (raw.reason !== null && !ALLOWED_REASONS[header.handler].includes(text(raw.reason))) {
731
+ refuse('RECOVERY_REQUIRED', '', 'verification');
732
+ }
733
+ let detail;
734
+ let metrics;
735
+ let findings;
736
+ try {
737
+ if (hasDetail)
738
+ detail = checkedDetail(raw.detail);
739
+ if (hasMetrics)
740
+ metrics = checkedMetrics(raw.metrics);
741
+ if (hasFindings)
742
+ findings = checkedFindings(raw.findings);
743
+ }
744
+ catch {
745
+ refuse('RECOVERY_REQUIRED', '', 'verification');
746
+ }
747
+ return {
748
+ status: raw.status,
749
+ reason: raw.reason,
750
+ method: text(raw.method),
751
+ response: raw,
752
+ ...(detail !== undefined ? { detail } : {}),
753
+ ...(metrics !== undefined ? { metrics } : {}),
754
+ ...(findings !== undefined ? { findings } : {}),
755
+ };
756
+ }
757
+ const verifierModule = new URL('./verifier-worker.js', import.meta.url);
758
+ export class Verifier {
759
+ store;
760
+ authority;
761
+ artifacts;
762
+ plan;
763
+ lock;
764
+ currentSubject;
765
+ ports;
766
+ constructor(store, authority, artifacts, plan, lock, currentSubject, ports = {}) {
767
+ this.store = store;
768
+ this.authority = authority;
769
+ this.artifacts = artifacts;
770
+ this.plan = plan;
771
+ this.lock = lock;
772
+ this.currentSubject = currentSubject;
773
+ this.ports = ports;
774
+ }
775
+ #identity() {
776
+ const view = stateValue(this.store.inspect());
777
+ if (view.storeId !== this.authority.storeId ||
778
+ view.runId !== this.lock.spec.runId ||
779
+ !same(view.lockHash, this.lock.spec.lockHash) ||
780
+ this.artifacts.owner.runId !== view.runId ||
781
+ !same(this.artifacts.owner.planDigest, this.plan.planDigest)) {
782
+ refuse('AUTHORITY_REFUSED', '', 'verification');
783
+ }
784
+ return view;
785
+ }
786
+ #operationAbsent(operationId) {
787
+ const result = this.store.getOperation(operationId);
788
+ if (result.ok || result.error.code !== 'RECORD_NOT_FOUND')
789
+ refuse('RECOVERY_REQUIRED', '', 'verification');
790
+ }
791
+ async #refusalContext(prepared) {
792
+ const data = refusalPreparations.get(prepared);
793
+ if (!data || data.plan !== this.plan || this.plan.verifierSlots.find(slot => slot.id === prepared.slotId) !== data.slot) {
794
+ refuse('EVIDENCE_UNAVAILABLE', '', 'verification');
795
+ }
796
+ const repeated = preflightVerification(this.plan, this.lock, prepared.slotId, data.source, data.candidate, prepared.generation, prepared.producerNonce);
797
+ if (repeated.kind !== 'refused' || !same(refusalPreparations.get(repeated.prepared).value, data.value)) {
798
+ refuse('RECOVERY_REQUIRED', '', 'verification');
799
+ }
800
+ await this.artifacts.owner.assertCurrent();
801
+ stateValue(this.store.renew(this.authority));
802
+ const view = this.#identity();
803
+ if (view.clockStatus !== 'trusted' ||
804
+ view.owner.ownerId !== this.authority.ownerId ||
805
+ view.owner.generation !== this.authority.generation ||
806
+ view.counts.dispatchedRequests ||
807
+ view.counts.unresolvedRequests ||
808
+ view.counts.unresolvedOperations ||
809
+ view.ledger.violations.length ||
810
+ !same(this.currentSubject(), data.value.subject)) {
811
+ refuse('RECOVERY_REQUIRED', '', 'verification');
812
+ }
813
+ this.#operationAbsent(prepared.prospectiveOperationId);
814
+ const bounds = overlayProtocolBounds(this.lock.spec.contract.spec.budgets.overlay);
815
+ for (const input of [data.source, data.candidate]) {
816
+ if (!Buffer.from(await this.artifacts.read(input.ref, bounds.manifestMaxBytes)).equals(Buffer.from(canonical(input.manifest)))) {
817
+ refuse('ARTIFACT_INVALID', '', 'verification');
818
+ }
819
+ }
820
+ const records = journal(this.store);
821
+ const latest = records.checkpoints.filter(cp => cp.additionalArtifacts.length === 4).at(-1);
822
+ if (!latest)
823
+ refuse('RECOVERY_REQUIRED', '', 'verification');
824
+ const progress = new ProgressStore(this.store, this.authority, this.artifacts, this.plan, this.lock, latest.additionalArtifacts[2], latest.additionalArtifacts[3]);
825
+ const head = await progress.read();
826
+ const source = parsePrivateJson(await this.artifacts.read(progress.sourceRef, 262144), 262144);
827
+ if (!head ||
828
+ head.progress.candidate.generation !== prepared.generation ||
829
+ !same(head.checkpoint.subject, data.value.subject) ||
830
+ !same(head.progress.candidate.manifest, data.candidate.ref) ||
831
+ !same(source.manifest, data.source.ref)) {
832
+ refuse('RECOVERY_REQUIRED', '', 'verification');
833
+ }
834
+ await this.artifacts.owner.assertCurrent();
835
+ stateValue(this.store.renew(this.authority));
836
+ this.#operationAbsent(prepared.prospectiveOperationId);
837
+ if (!same(this.currentSubject(), data.value.subject))
838
+ refuse('RECOVERY_REQUIRED', '', 'verification');
839
+ const finalView = this.#identity();
840
+ if (finalView.clockStatus !== 'trusted' ||
841
+ finalView.owner.ownerId !== this.authority.ownerId ||
842
+ finalView.owner.generation !== this.authority.generation ||
843
+ finalView.counts.dispatchedRequests ||
844
+ finalView.counts.unresolvedRequests ||
845
+ finalView.counts.unresolvedOperations ||
846
+ finalView.ledger.violations.length) {
847
+ refuse('RECOVERY_REQUIRED', '', 'verification');
848
+ }
849
+ return { data, progress, head, view: finalView };
850
+ }
851
+ /** Durable negative bytes only; neither this row nor an orphan file can authorize acceptance. */
852
+ async storeRefusal(prepared) {
853
+ const { data, view } = await this.#refusalContext(prepared);
854
+ if (view.owner.mode !== 'active')
855
+ refuse('AUTHORITY_REFUSED', '', 'verification');
856
+ const ref = await this.artifacts.json('verifier-refusal', data.value, 65536);
857
+ this.#operationAbsent(prepared.prospectiveOperationId);
858
+ return freeze({
859
+ slot: prepared.slotId,
860
+ generation: prepared.generation,
861
+ prospectiveOperationId: prepared.prospectiveOperationId,
862
+ producerNonce: prepared.producerNonce,
863
+ subject: data.value.subject,
864
+ record: ref,
865
+ });
866
+ }
867
+ /** Validate an existing pre anchor without granting a negative observation or allocating a new slot. */
868
+ async validateStoredRefusal(prepared, row) {
869
+ const { data, head } = await this.#refusalContext(prepared);
870
+ const original = head.progress.verifierRefusals.find(item => item.slot === prepared.slotId && item.generation === prepared.generation);
871
+ if (!same(original, row))
872
+ refuse('RECOVERY_REQUIRED', '', 'recovery');
873
+ const value = checkedRefusalRecord(parsePrivateJson(await this.artifacts.read(row.record, 65536), 65536), this.plan, this.lock, row);
874
+ if (!same(value, data.value))
875
+ refuse('RECOVERY_REQUIRED', '', 'recovery');
876
+ }
877
+ /** Original pre/post anchors plus pure size reproduction; no Worker, operation intent, receipt or permit. */
878
+ async restoreRefusal(prepared, row) {
879
+ await this.validateStoredRefusal(prepared, row);
880
+ const { data, head, view } = await this.#refusalContext(prepared);
881
+ const ordinal = this.plan.verifierSlots.findIndex(slot => slot.id === prepared.slotId);
882
+ const phase = 'verify.' + prepared.generation + '.' + ordinal;
883
+ const pre = stateValue(this.store.getCheckpoint(phaseCheckpointId(this.lock.spec.runId, phase + '.pre')));
884
+ const post = stateValue(this.store.getCheckpoint(phaseCheckpointId(this.lock.spec.runId, phase + '.post')));
885
+ if (post.sequence !== pre.sequence + 1 ||
886
+ pre.counts.requests !== post.counts.requests ||
887
+ pre.counts.operations !== post.counts.operations ||
888
+ !same(pre.ledger, post.ledger) ||
889
+ !same(pre.clockBasis, view.clock.basis) ||
890
+ !same(post.clockBasis, view.clock.basis) ||
891
+ !same(pre.subject, data.value.subject) ||
892
+ !same(post.subject, data.value.subject) ||
893
+ !head.progress.stage.consumed.includes(phase + '.pre') ||
894
+ !head.progress.stage.consumed.includes(phase + '.post')) {
895
+ refuse('RECOVERY_REQUIRED', '', 'recovery');
896
+ }
897
+ const wideProgress = this.plan.capacity.D > 64;
898
+ const pMaxBytes = wideProgress ? 262_144 : 65_536;
899
+ const pCollectionLimit = wideProgress ? 1024 : 256;
900
+ for (const [checkpoint, suffix] of [
901
+ [pre, 'pre'],
902
+ [post, 'post'],
903
+ ]) {
904
+ if (checkpoint.additionalArtifacts.length !== 4 || !same(checkpoint.additionalArtifacts.slice(2), head.checkpoint.additionalArtifacts.slice(2))) {
905
+ refuse('RECOVERY_REQUIRED', '', 'recovery');
906
+ }
907
+ const progress = validateProgress(parsePrivateJson(await this.artifacts.read(checkpoint.additionalArtifacts[0], pMaxBytes), pMaxBytes, pCollectionLimit), this.plan, this.lock);
908
+ if (progress.stage.phase !== phase + '.' + suffix ||
909
+ !same(progress.verifierRefusals.find(item => item.slot === row.slot && item.generation === row.generation), row)) {
910
+ refuse('RECOVERY_REQUIRED', '', 'recovery');
911
+ }
912
+ }
913
+ this.#operationAbsent(row.prospectiveOperationId);
914
+ const value = freeze({
915
+ slotId: row.slot,
916
+ checkId: data.slot.checkId,
917
+ generation: row.generation,
918
+ prospectiveOperationId: row.prospectiveOperationId,
919
+ producerNonce: row.producerNonce,
920
+ status: 'blocked',
921
+ reason: 'verifier_' + data.value.limits.reason,
922
+ record: row.record,
923
+ });
924
+ refusalObservations.set(value, { value: data.value, row, storeId: view.storeId, clockBasis: view.clock.basis });
925
+ return value;
926
+ }
927
+ #permit(permit, expected, target) {
928
+ stateValue(this.store.renew(this.authority));
929
+ const view = stateValue(this.store.inspect());
930
+ const operation = stateValue(this.store.getOperation(permit.operationId));
931
+ if (!same(this.currentSubject(), expected) ||
932
+ view.clockStatus !== 'trusted' ||
933
+ view.owner.mode !== 'active' ||
934
+ view.owner.ownerId !== this.authority.ownerId ||
935
+ view.owner.generation !== this.authority.generation ||
936
+ permit.generation !== this.authority.generation ||
937
+ permit.clockEpoch !== view.clock.basis.clockEpoch ||
938
+ view.storeId !== permit.storeId ||
939
+ view.runId !== permit.runId ||
940
+ !same(view.lockHash, permit.lockHash) ||
941
+ BigInt(view.clock.sampledNow.monotonicMs) >= BigInt(permit.notAfterMonotonicMs) ||
942
+ BigInt(view.clock.sampledNow.monotonicMs) >= BigInt(view.clock.basis.taskDeadlineMonotonicMs) ||
943
+ operation.state !== 'dispatch_uncertain' ||
944
+ operation.dispatch?.dispatchId !== permit.dispatchId ||
945
+ operation.intent.targetIdentity !== target) {
946
+ refuse('AUTHORITY_REFUSED', '', 'verification');
947
+ }
948
+ }
949
+ async #marker(operationId, nonce, kind, value) {
950
+ await this.artifacts.owner.assertCurrent();
951
+ const name = 'producer-' + hash(operationId + '\0' + nonce).hex + '.' + kind + '.json';
952
+ const path = join(this.artifacts.directory, name);
953
+ const bytes = Buffer.from(canonical(value));
954
+ if (bytes.byteLength > 1048576)
955
+ refuse('OUTPUT_LIMIT', '', 'verification');
956
+ this.artifacts.vault.assertClean(bytes);
957
+ let file;
958
+ try {
959
+ file = await open(path, constants.O_CREAT | constants.O_EXCL | constants.O_WRONLY | constants.O_NOFOLLOW, 0o600);
960
+ }
961
+ catch (error) {
962
+ if (error.code !== 'EEXIST' || !Buffer.from(await readBoundedFile(path, 1048576, true)).equals(bytes)) {
963
+ refuse('RECOVERY_REQUIRED', '', 'verification');
964
+ }
965
+ return;
966
+ }
967
+ try {
968
+ await file.writeFile(bytes);
969
+ await file.sync();
970
+ }
971
+ finally {
972
+ await file.close();
973
+ }
974
+ const parent = await open(this.artifacts.directory, constants.O_RDONLY | constants.O_NOFOLLOW);
975
+ try {
976
+ await parent.sync();
977
+ }
978
+ finally {
979
+ await parent.close();
980
+ }
981
+ }
982
+ async run(job, signal) {
983
+ const prepared = preparedJobs.get(job);
984
+ if (!prepared || this.plan.verifierSlots.find(slot => slot.id === job.slotId) !== prepared.slot) {
985
+ refuse('EVIDENCE_UNAVAILABLE', '', 'verification');
986
+ }
987
+ signal.throwIfAborted();
988
+ await this.artifacts.owner.assertCurrent();
989
+ if (!same(this.currentSubject(), prepared.header.subject))
990
+ refuse('ARTIFACT_INVALID', '', 'verification');
991
+ const done = await this.artifacts.owner.holdLocalActivity();
992
+ let closed = true;
993
+ try {
994
+ const target = 'verifier:' + job.slotId + ':' + job.generation + ':' + prepared.header.subject.candidateDigest.hex;
995
+ const before = this.#identity();
996
+ if (before.owner.mode !== 'active')
997
+ refuse('AUTHORITY_REFUSED', '', 'verification');
998
+ if (before.counts.dispatchedRequests || before.counts.unresolvedRequests || before.counts.unresolvedOperations || before.ledger.violations.length) {
999
+ refuse('RECOVERY_REQUIRED', '', 'verification');
1000
+ }
1001
+ stateValue(this.store.putIntent(this.authority, {
1002
+ operationId: job.operationId,
1003
+ nodeId: this.plan.orderedDAG[0].id,
1004
+ attemptId: prepared.header.jobId,
1005
+ effect: 'read_only',
1006
+ requestDigest: job.requestDigest,
1007
+ targetIdentity: target,
1008
+ }));
1009
+ const dispatched = stateValue(this.store.authorizeOperationDispatch(this.authority, job.operationId));
1010
+ if (dispatched.kind !== 'new_dispatch')
1011
+ refuse('RECOVERY_REQUIRED', '', 'verification');
1012
+ const permit = dispatched.permit;
1013
+ const header = { ...prepared.header, dispatchId: permit.dispatchId };
1014
+ const packet = encodePacket(header, prepared.payload);
1015
+ const packetDigest = hash(packet);
1016
+ const maxJobPacket = maxPacketBytes(header);
1017
+ const jobRef = await this.artifacts.put('verifier-job', packet, maxJobPacket);
1018
+ const moduleDigest = hash(await readBoundedFile(fileURLToPath(verifierModule), 1048576, false));
1019
+ const operation = stateValue(this.store.getOperation(job.operationId));
1020
+ await this.#marker(job.operationId, job.producerNonce, 'binding', {
1021
+ version: 1,
1022
+ planDigest: this.plan.planDigest,
1023
+ operationId: job.operationId,
1024
+ producerNonce: job.producerNonce,
1025
+ requestDigest: job.requestDigest,
1026
+ intentDigest: operation.intentDigest,
1027
+ subject: header.subject,
1028
+ generation: job.generation,
1029
+ job: jobRef,
1030
+ packetDigest,
1031
+ moduleDigest,
1032
+ dispatchReceipt: {
1033
+ generation: permit.generation,
1034
+ dispatchId: permit.dispatchId,
1035
+ revision: permit.authorizedRevision,
1036
+ clockEpoch: permit.clockEpoch,
1037
+ },
1038
+ });
1039
+ this.ports.beforeWorker?.(packet);
1040
+ signal.throwIfAborted();
1041
+ await this.artifacts.owner.assertCurrent();
1042
+ this.#permit(permit, header.subject, target);
1043
+ const workerBounds = overlayProtocolBounds(header.overlay);
1044
+ const isWideOverlay = header.overlay !== undefined && (workerBounds.maxOverlayEntries > 128 || workerBounds.maxTotalBytes > 4_194_304);
1045
+ const maxOldGenerationSizeMb = isWideOverlay
1046
+ ? Math.min(192, Math.max(64, Math.ceil(workerBounds.allocationMaxBytes / (1024 * 1024)) + 32))
1047
+ : 64;
1048
+ const timeoutMs = isWideOverlay ? 15_000 : 2_000;
1049
+ const running = boundedWorker(verifierModule, packet, signal, { maxOldGenerationSizeMb, timeoutMs });
1050
+ closed = false;
1051
+ const observed = await running;
1052
+ closed = true;
1053
+ this.#permit(permit, header.subject, target);
1054
+ let disposition;
1055
+ if (observed.kind === 'reply' && observed.reply) {
1056
+ const replyBytes = this.ports.afterReply?.(observed.reply) ?? observed.reply;
1057
+ disposition = checkedReply(parsePrivateJson(replyBytes, 65536), header, packetDigest);
1058
+ }
1059
+ else {
1060
+ const status = 'blocked';
1061
+ const reason = 'worker_' + observed.kind;
1062
+ disposition = { status, reason, method: 'worker_runtime', response: { version: 1, status, reason } };
1063
+ }
1064
+ const output = await this.artifacts.json('verifier-output', {
1065
+ version: 1,
1066
+ binding: header,
1067
+ packetDigest,
1068
+ moduleDigest,
1069
+ observation: {
1070
+ kind: observed.kind,
1071
+ threadId: observed.threadId,
1072
+ exit: observed.exit,
1073
+ errorCode: observed.errorCode,
1074
+ limits: observed.limits,
1075
+ elapsedMs: Math.ceil(observed.elapsedMs),
1076
+ },
1077
+ response: disposition.response,
1078
+ }, 65536);
1079
+ const suffix = hash(job.operationId + '\0' + job.producerNonce).hex.slice(0, 40);
1080
+ const evidenceSpec = {
1081
+ checkId: prepared.slot.checkId,
1082
+ observedStatus: disposition.status,
1083
+ producerId: 'loopwright.byte-verifier.v1',
1084
+ method: disposition.method,
1085
+ level: 'local_execution',
1086
+ subject: header.subject,
1087
+ artifacts: [output],
1088
+ reason: disposition.reason,
1089
+ ...(disposition.detail !== undefined ? { detail: disposition.detail } : {}),
1090
+ ...(disposition.metrics !== undefined ? { metrics: disposition.metrics } : {}),
1091
+ ...(disposition.findings !== undefined ? { findings: disposition.findings } : {}),
1092
+ };
1093
+ const evidenceResult = validateDocument({ apiVersion: 'loopwright.dev/v1alpha1', kind: 'Evidence', metadata: { id: 'evidence.' + suffix }, spec: evidenceSpec }, 'Evidence');
1094
+ if (!evidenceResult.ok)
1095
+ refuse('RECOVERY_REQUIRED', '', 'verification');
1096
+ const current = stateValue(this.store.inspect());
1097
+ const receipt = {
1098
+ receiptId: 'receipt.' + suffix,
1099
+ outcome: observed.kind === 'reply' ? 'succeeded' : 'failed',
1100
+ evidence: {
1101
+ evidenceId: 'receipt-evidence.' + suffix,
1102
+ producerId: 'loopwright.byte-verifier.v1',
1103
+ method: disposition.method,
1104
+ subject: {
1105
+ storeId: current.storeId,
1106
+ runId: current.runId,
1107
+ lockHash: current.lockHash,
1108
+ operationId: job.operationId,
1109
+ requestId: null,
1110
+ intentDigest: operation.intentDigest,
1111
+ dispatchGeneration: permit.generation,
1112
+ dispatchId: permit.dispatchId,
1113
+ },
1114
+ artifact: output,
1115
+ },
1116
+ };
1117
+ const receiptRef = await this.artifacts.json('verifier-receipt', receipt, 65536);
1118
+ await this.#marker(job.operationId, job.producerNonce, 'proof', { version: 1, job: jobRef, output, receipt: receiptRef, evidence: evidenceResult.value });
1119
+ this.ports.afterReceiptBytes?.();
1120
+ this.#permit(permit, header.subject, target);
1121
+ stateValue(this.store.recordOperationReceipt(this.authority, job.operationId, receipt));
1122
+ const value = freeze({
1123
+ slotId: job.slotId,
1124
+ checkId: prepared.slot.checkId,
1125
+ generation: job.generation,
1126
+ operationId: job.operationId,
1127
+ producerNonce: job.producerNonce,
1128
+ status: disposition.status,
1129
+ reason: disposition.reason,
1130
+ output,
1131
+ receipt: receiptRef,
1132
+ });
1133
+ observations.set(value, {
1134
+ evidence: freeze(evidenceResult.value),
1135
+ subject: header.subject,
1136
+ outputBytes: await this.artifacts.read(output, 65536),
1137
+ receipt: freeze(receipt),
1138
+ header: freeze(header),
1139
+ planDigest: this.plan.planDigest,
1140
+ requestDigest: job.requestDigest,
1141
+ });
1142
+ return value;
1143
+ }
1144
+ finally {
1145
+ if (closed)
1146
+ done();
1147
+ }
1148
+ }
1149
+ /** Original private producer proof only. No Worker, new intent, permit reconstruction or transport retry. */
1150
+ async restore(job) {
1151
+ const prepared = preparedJobs.get(job);
1152
+ if (!prepared || this.plan.verifierSlots.find(slot => slot.id === job.slotId) !== prepared.slot) {
1153
+ refuse('EVIDENCE_UNAVAILABLE', '', 'recovery');
1154
+ }
1155
+ await this.artifacts.owner.assertCurrent();
1156
+ if (!same(this.currentSubject(), prepared.header.subject))
1157
+ refuse('RECOVERY_REQUIRED', '', 'recovery');
1158
+ const operation = stateValue(this.store.getOperation(job.operationId));
1159
+ const view = this.#identity();
1160
+ const dispatch = operation.dispatch;
1161
+ if (!dispatch ||
1162
+ view.clockStatus !== 'trusted' ||
1163
+ operation.intent.effect !== 'read_only' ||
1164
+ operation.linkedRequestId !== null ||
1165
+ !same(operation.intent.requestDigest, job.requestDigest) ||
1166
+ operation.intent.attemptId !== prepared.header.jobId ||
1167
+ operation.intent.nodeId !== this.plan.orderedDAG[0].id ||
1168
+ operation.intent.targetIdentity !== 'verifier:' + job.slotId + ':' + job.generation + ':' + prepared.header.subject.candidateDigest.hex) {
1169
+ refuse('RECOVERY_REQUIRED', '', 'recovery');
1170
+ }
1171
+ const prefix = join(this.artifacts.directory, 'producer-' + hash(job.operationId + '\0' + job.producerNonce).hex);
1172
+ const binding = record(parsePrivateJson(await readBoundedFile(prefix + '.binding.json', 1048576, true), 1048576), [
1173
+ 'version', 'planDigest', 'operationId', 'producerNonce', 'requestDigest', 'intentDigest',
1174
+ 'subject', 'generation', 'job', 'packetDigest', 'moduleDigest', 'dispatchReceipt',
1175
+ ]);
1176
+ const proof = record(parsePrivateJson(await readBoundedFile(prefix + '.proof.json', 1048576, true), 1048576), [
1177
+ 'version', 'job', 'output', 'receipt', 'evidence',
1178
+ ]);
1179
+ const receiptBinding = record(binding.dispatchReceipt, ['generation', 'dispatchId', 'revision', 'clockEpoch']);
1180
+ if (receiptBinding.generation !== dispatch.generation ||
1181
+ receiptBinding.dispatchId !== dispatch.dispatchId ||
1182
+ receiptBinding.revision !== dispatch.revision ||
1183
+ receiptBinding.clockEpoch !== view.clock.basis.clockEpoch) {
1184
+ refuse('RECOVERY_REQUIRED', '', 'recovery');
1185
+ }
1186
+ const header = freeze({ ...prepared.header, dispatchId: dispatch.dispatchId });
1187
+ const expectedPacket = encodePacket(header, prepared.payload);
1188
+ const packetDigest = hash(expectedPacket);
1189
+ const jobRef = checkedRef(binding.job);
1190
+ const maxJobPacket = maxPacketBytes(header);
1191
+ const moduleDigest = hash(await readBoundedFile(fileURLToPath(verifierModule), 1048576, false));
1192
+ if (binding.version !== 1 ||
1193
+ proof.version !== 1 ||
1194
+ !same(binding.planDigest, this.plan.planDigest) ||
1195
+ binding.operationId !== job.operationId ||
1196
+ binding.producerNonce !== job.producerNonce ||
1197
+ binding.generation !== job.generation ||
1198
+ !same(binding.subject, header.subject) ||
1199
+ !same(binding.requestDigest, job.requestDigest) ||
1200
+ !same(binding.intentDigest, operation.intentDigest) ||
1201
+ !same(binding.packetDigest, packetDigest) ||
1202
+ !same(binding.moduleDigest, moduleDigest) ||
1203
+ !same(binding.job, proof.job) ||
1204
+ !Buffer.from(await this.artifacts.read(jobRef, maxJobPacket)).equals(Buffer.from(expectedPacket))) {
1205
+ refuse('RECOVERY_REQUIRED', '', 'recovery');
1206
+ }
1207
+ const output = checkedRef(proof.output);
1208
+ const receiptRef = checkedRef(proof.receipt);
1209
+ const outputBytes = await this.artifacts.read(output, 65536);
1210
+ const saved = record(parsePrivateJson(outputBytes, 65536), ['version', 'binding', 'packetDigest', 'moduleDigest', 'observation', 'response']);
1211
+ const observed = record(saved.observation, ['kind', 'threadId', 'exit', 'errorCode', 'limits', 'elapsedMs']);
1212
+ integer(observed.threadId, 1, Number.MAX_SAFE_INTEGER);
1213
+ integer(observed.exit, 0, 255);
1214
+ integer(observed.elapsedMs, 0, Number.MAX_SAFE_INTEGER);
1215
+ if (saved.version !== 1 ||
1216
+ !same(saved.binding, header) ||
1217
+ !same(saved.packetDigest, packetDigest) ||
1218
+ !same(saved.moduleDigest, moduleDigest) ||
1219
+ !['reply', 'timeout', 'cancelled', 'failed'].includes(text(observed.kind)) ||
1220
+ (observed.errorCode !== null && !['ERR_WORKER_OUT_OF_MEMORY', 'WORKER_ERROR'].includes(text(observed.errorCode)))) {
1221
+ refuse('RECOVERY_REQUIRED', '', 'recovery');
1222
+ }
1223
+ let disposition;
1224
+ if (observed.kind === 'reply') {
1225
+ if (observed.exit !== 0 || observed.errorCode !== null || !same(observed.limits, { oldMb: 64, youngMb: 8, stackMb: 2 })) {
1226
+ refuse('RECOVERY_REQUIRED', '', 'recovery');
1227
+ }
1228
+ disposition = checkedReply(saved.response, header, packetDigest);
1229
+ }
1230
+ else {
1231
+ const response = { version: 1, status: 'blocked', reason: 'worker_' + observed.kind };
1232
+ if (!same(saved.response, response))
1233
+ refuse('RECOVERY_REQUIRED', '', 'recovery');
1234
+ disposition = { status: 'blocked', reason: response.reason, method: 'worker_runtime', response };
1235
+ }
1236
+ const suffix = hash(job.operationId + '\0' + job.producerNonce).hex.slice(0, 40);
1237
+ const evidenceSpec = {
1238
+ checkId: prepared.slot.checkId,
1239
+ observedStatus: disposition.status,
1240
+ producerId: 'loopwright.byte-verifier.v1',
1241
+ method: disposition.method,
1242
+ level: 'local_execution',
1243
+ subject: header.subject,
1244
+ artifacts: [output],
1245
+ reason: disposition.reason,
1246
+ ...(disposition.detail !== undefined ? { detail: disposition.detail } : {}),
1247
+ ...(disposition.metrics !== undefined ? { metrics: disposition.metrics } : {}),
1248
+ ...(disposition.findings !== undefined ? { findings: disposition.findings } : {}),
1249
+ };
1250
+ const evidence = validateDocument({ apiVersion: 'loopwright.dev/v1alpha1', kind: 'Evidence', metadata: { id: 'evidence.' + suffix }, spec: evidenceSpec }, 'Evidence');
1251
+ if (!evidence.ok || !same(evidence.value, proof.evidence))
1252
+ refuse('RECOVERY_REQUIRED', '', 'recovery');
1253
+ const receipt = {
1254
+ receiptId: 'receipt.' + suffix,
1255
+ outcome: observed.kind === 'reply' ? 'succeeded' : 'failed',
1256
+ evidence: {
1257
+ evidenceId: 'receipt-evidence.' + suffix,
1258
+ producerId: 'loopwright.byte-verifier.v1',
1259
+ method: disposition.method,
1260
+ subject: {
1261
+ storeId: view.storeId,
1262
+ runId: view.runId,
1263
+ lockHash: view.lockHash,
1264
+ operationId: job.operationId,
1265
+ requestId: null,
1266
+ intentDigest: operation.intentDigest,
1267
+ dispatchGeneration: dispatch.generation,
1268
+ dispatchId: dispatch.dispatchId,
1269
+ },
1270
+ artifact: output,
1271
+ },
1272
+ };
1273
+ if (!same(parsePrivateJson(await this.artifacts.read(receiptRef, 65536), 65536), receipt))
1274
+ refuse('RECOVERY_REQUIRED', '', 'recovery');
1275
+ await this.artifacts.owner.assertCurrent();
1276
+ if (!same(this.currentSubject(), header.subject))
1277
+ refuse('RECOVERY_REQUIRED', '', 'recovery');
1278
+ stateValue(this.store.renew(this.authority));
1279
+ if (operation.state === 'confirmed') {
1280
+ if (!same(operation.reconciliation ?? operation.initialReceipt, receipt))
1281
+ refuse('RECOVERY_REQUIRED', '', 'recovery');
1282
+ }
1283
+ else {
1284
+ stateValue(this.store.reconcileOperation(this.authority, job.operationId, receipt));
1285
+ }
1286
+ const value = freeze({
1287
+ slotId: job.slotId,
1288
+ checkId: prepared.slot.checkId,
1289
+ generation: job.generation,
1290
+ operationId: job.operationId,
1291
+ producerNonce: job.producerNonce,
1292
+ status: disposition.status,
1293
+ reason: disposition.reason,
1294
+ output,
1295
+ receipt: receiptRef,
1296
+ });
1297
+ observations.set(value, {
1298
+ evidence: freeze(evidence.value),
1299
+ subject: header.subject,
1300
+ outputBytes,
1301
+ receipt: freeze(receipt),
1302
+ header,
1303
+ planDigest: this.plan.planDigest,
1304
+ requestDigest: job.requestDigest,
1305
+ });
1306
+ return value;
1307
+ }
1308
+ }