@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,1312 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { types } from 'node:util';
3
+ import { LIMITS, OVERLAY_LIMITS, admitTask, identifyManifest, isWritablePath, resolveOverlayLimits, validateDocument, validateRelativePath, } from '@loopwright/core';
4
+ import { canonical, checkedRef, digestValue, freeze, hash, id, integer, isRecord, list, record, same, text } from './schema.js';
5
+ import { parsePrivateJson } from './parser.js';
6
+ import { gitObjectOid, parseGitTreeEntries } from './git-objects.js';
7
+ import { ControllerFailure, refuse } from './errors.js';
8
+ export const HEADER_BYTES = 16384;
9
+ export const PACKET_BYTES = 1048576;
10
+ export const JSON_FILE_BYTES = 1032184;
11
+ export const ALLOCATION_BYTES = 8388608;
12
+ export const OVERLAY_INVENTORY_MAGIC = 0x4c574f56;
13
+ const MAX_ABSOLUTE_PACKET_BYTES = 167_772_160;
14
+ const URI_FLAG = 0x4000;
15
+ const MEDIA_TYPE_FLAG = 0x8000;
16
+ const NAME_LEN_MASK = 0x3fff;
17
+ export const RFC6901_POINTER_PATTERN = /^(?:\/(?:[^~/]|~[01])*)+$/;
18
+ const LONE_SURROGATE_PATTERN = /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/u;
19
+ export function overlayProtocolBounds(overlay) {
20
+ if (overlay === undefined) {
21
+ return {
22
+ maxOverlayEntries: 128,
23
+ maxClassicEntries: 256,
24
+ maxManifestEntries: 256,
25
+ maxTotalBytes: 4_194_304,
26
+ manifestMaxBytes: 32_768,
27
+ inventoryMaxBytes: 32_772,
28
+ allocationMaxBytes: ALLOCATION_BYTES,
29
+ options: undefined,
30
+ };
31
+ }
32
+ const resolved = resolveOverlayLimits(overlay);
33
+ if (!resolved.ok)
34
+ refuse('ARTIFACT_INVALID', '', 'verification');
35
+ const { maxFiles, maxBytes } = resolved.value;
36
+ const extraFiles = Math.max(0, maxFiles - 128);
37
+ const manifestMaxBytes = maxFiles <= 128 ? 32_768 : Math.min(83_886_080, 32_768 + extraFiles * 4_608);
38
+ const inventoryMaxBytes = maxFiles <= 128 ? 32_772 : Math.min(83_886_080, 32_772 + extraFiles * 4_608);
39
+ const maxWidePacketEstimate = Math.min(MAX_ABSOLUTE_PACKET_BYTES, 4 + HEADER_BYTES + 2 * inventoryMaxBytes + 2 * (4 + JSON_FILE_BYTES) + 262_212);
40
+ const allocationMaxBytes = maxFiles <= 128
41
+ ? ALLOCATION_BYTES
42
+ : Math.max(ALLOCATION_BYTES, Math.max(maxWidePacketEstimate, maxFiles >= 4_096 ? MAX_ABSOLUTE_PACKET_BYTES : 0) + 2 * manifestMaxBytes + 4_194_304);
43
+ return {
44
+ maxOverlayEntries: maxFiles,
45
+ maxClassicEntries: 256,
46
+ maxManifestEntries: Math.max(256, maxFiles),
47
+ maxTotalBytes: maxBytes,
48
+ manifestMaxBytes,
49
+ inventoryMaxBytes,
50
+ allocationMaxBytes,
51
+ options: { overlay: { maxFiles, maxBytes } },
52
+ };
53
+ }
54
+ export function maxPacketBytes(header) {
55
+ const bounds = overlayProtocolBounds(header.overlay);
56
+ const inventoriesBytes = 4 + HEADER_BYTES + 2 * bounds.inventoryMaxBytes;
57
+ if (header.payloadKind === 'inventories')
58
+ return Math.min(MAX_ABSOLUTE_PACKET_BYTES, inventoriesBytes);
59
+ if (header.payloadKind === 'json') {
60
+ return Math.min(MAX_ABSOLUTE_PACKET_BYTES, inventoriesBytes + 4 + JSON_FILE_BYTES + 262_212);
61
+ }
62
+ return Math.min(MAX_ABSOLUTE_PACKET_BYTES, inventoriesBytes + 2 * (4 + JSON_FILE_BYTES) + 262_212);
63
+ }
64
+ export function packetAllocationLimit(bytes) {
65
+ if (!(bytes instanceof Uint8Array) || bytes.byteLength < 4 + HEADER_BYTES)
66
+ return ALLOCATION_BYTES;
67
+ const len = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength).getUint32(0);
68
+ if (!len || len > HEADER_BYTES)
69
+ return ALLOCATION_BYTES;
70
+ try {
71
+ const header = checkedHeader(parsePrivateJson(bytes.subarray(4, 4 + len), HEADER_BYTES, 256));
72
+ return overlayProtocolBounds(header.overlay).allocationMaxBytes;
73
+ }
74
+ catch {
75
+ return ALLOCATION_BYTES;
76
+ }
77
+ }
78
+ export class AllocationQuota {
79
+ limit;
80
+ used = 0;
81
+ constructor(limit = ALLOCATION_BYTES) {
82
+ this.limit = limit;
83
+ }
84
+ charge(length) {
85
+ integer(length, 0, this.limit);
86
+ this.used += length;
87
+ if (this.used > this.limit)
88
+ refuse('OUTPUT_LIMIT', '', 'verification');
89
+ }
90
+ allocate(length) {
91
+ this.charge(length);
92
+ return new Uint8Array(length);
93
+ }
94
+ }
95
+ export function ownedBytes(value, maximum) {
96
+ if (!ArrayBuffer.isView(value) ||
97
+ types.isProxy(value) ||
98
+ ![Uint8Array.prototype, Buffer.prototype].includes(Object.getPrototypeOf(value)) ||
99
+ types.isSharedArrayBuffer(value.buffer) ||
100
+ value.byteLength > maximum) {
101
+ refuse('ARTIFACT_INVALID', '', 'verification');
102
+ }
103
+ return new Uint8Array(value);
104
+ }
105
+ export function fileHash(bytes) {
106
+ const digest = createHash('sha256');
107
+ for (let offset = 0; offset < bytes.byteLength; offset += 1_048_576)
108
+ digest.update(bytes.subarray(offset, offset + 1_048_576));
109
+ return { algorithm: 'sha256', hex: digest.digest('hex') };
110
+ }
111
+ export function descriptor(manifest, ref, overlay) {
112
+ const bounds = overlayProtocolBounds(overlay);
113
+ const identified = identifyManifest(manifest, bounds.options);
114
+ const encoded = canonical(manifest);
115
+ if (!identified.ok ||
116
+ Buffer.byteLength(encoded) > bounds.manifestMaxBytes ||
117
+ ref.byteLength !== Buffer.byteLength(encoded) ||
118
+ !same(ref.digest, hash(encoded))) {
119
+ refuse('ARTIFACT_INVALID', '', 'verification');
120
+ }
121
+ return { metadataId: manifest.metadata.id, ref: checkedRef(ref), entryCount: manifest.spec.entries.length };
122
+ }
123
+ function document(raw, expected, quota, bounds) {
124
+ const identified = identifyManifest(raw, bounds.options);
125
+ if (!identified.ok)
126
+ refuse('ARTIFACT_INVALID', '', 'verification');
127
+ const manifest = identified.value.manifest;
128
+ const encoded = canonical(manifest);
129
+ const length = Buffer.byteLength(encoded);
130
+ quota.charge(length);
131
+ if (length > bounds.manifestMaxBytes ||
132
+ manifest.metadata.id !== expected.metadataId ||
133
+ manifest.spec.entries.length !== expected.entryCount ||
134
+ length !== expected.ref.byteLength ||
135
+ !same(hash(encoded), expected.ref.digest)) {
136
+ refuse('ARTIFACT_INVALID', '', 'verification');
137
+ }
138
+ return manifest;
139
+ }
140
+ function writeHexBytes(target, offset, hex, byteLength) {
141
+ if (hex.length !== byteLength * 2 || !/^[0-9a-f]+$/.test(hex))
142
+ refuse('ARTIFACT_INVALID', '', 'verification');
143
+ for (let index = 0; index < byteLength; index++)
144
+ target[offset + index] = Number.parseInt(hex.slice(index * 2, index * 2 + 2), 16);
145
+ return offset + byteLength;
146
+ }
147
+ function entryWireBytes(entry) {
148
+ const hasUri = Object.hasOwn(entry, 'uri') && entry.uri !== undefined;
149
+ const hasMedia = Object.hasOwn(entry, 'mediaType') && entry.mediaType !== undefined;
150
+ let size = 42 + Buffer.byteLength(entry.name);
151
+ if (hasUri)
152
+ size += 2 + (entry.uri === null ? 0 : Buffer.byteLength(entry.uri));
153
+ if (hasMedia)
154
+ size += 2 + (entry.mediaType === null ? 0 : Buffer.byteLength(entry.mediaType));
155
+ return size;
156
+ }
157
+ function encodeEntries(bytes, view, start, entries) {
158
+ let offset = start;
159
+ for (const entry of entries) {
160
+ const length = Buffer.byteLength(entry.name);
161
+ if (!length || length > 4096)
162
+ refuse('OUTPUT_LIMIT', '', 'verification');
163
+ const hasUri = Object.hasOwn(entry, 'uri') && entry.uri !== undefined;
164
+ const hasMedia = Object.hasOwn(entry, 'mediaType') && entry.mediaType !== undefined;
165
+ const headerWord = length | (hasUri ? URI_FLAG : 0) | (hasMedia ? MEDIA_TYPE_FLAG : 0);
166
+ view.setUint16(offset, headerWord);
167
+ offset += 2;
168
+ Buffer.from(bytes.buffer).write(entry.name, offset, length, 'utf8');
169
+ offset += length;
170
+ view.setBigUint64(offset, BigInt(entry.byteLength));
171
+ offset += 8;
172
+ offset = writeHexBytes(bytes, offset, entry.digest.hex, 32);
173
+ if (hasUri) {
174
+ if (entry.uri === null) {
175
+ view.setInt16(offset, -1);
176
+ offset += 2;
177
+ }
178
+ else {
179
+ const uriLen = Buffer.byteLength(entry.uri);
180
+ if (uriLen > LIMITS.artifactUri)
181
+ refuse('OUTPUT_LIMIT', '', 'verification');
182
+ view.setInt16(offset, uriLen);
183
+ offset += 2;
184
+ Buffer.from(bytes.buffer).write(entry.uri, offset, uriLen, 'utf8');
185
+ offset += uriLen;
186
+ }
187
+ }
188
+ if (hasMedia) {
189
+ if (entry.mediaType === null) {
190
+ view.setInt16(offset, -1);
191
+ offset += 2;
192
+ }
193
+ else {
194
+ const mediaLen = Buffer.byteLength(entry.mediaType);
195
+ if (mediaLen > LIMITS.mediaType)
196
+ refuse('OUTPUT_LIMIT', '', 'verification');
197
+ view.setInt16(offset, mediaLen);
198
+ offset += 2;
199
+ Buffer.from(bytes.buffer).write(entry.mediaType, offset, mediaLen, 'utf8');
200
+ offset += mediaLen;
201
+ }
202
+ }
203
+ }
204
+ return offset;
205
+ }
206
+ export function inventoryEncodedBytes(manifest) {
207
+ const baseTree = manifest.spec.baseTree;
208
+ if (!baseTree) {
209
+ return 4 + manifest.spec.entries.reduce((sum, entry) => sum + entryWireBytes(entry), 0);
210
+ }
211
+ const deleted = manifest.spec.deleted ?? [];
212
+ const oidBytes = baseTree.objectFormat === 'sha256' ? 32 : 20;
213
+ return (4 +
214
+ 1 +
215
+ oidBytes * 2 +
216
+ 4 +
217
+ manifest.spec.entries.reduce((sum, entry) => sum + entryWireBytes(entry), 0) +
218
+ 4 +
219
+ deleted.reduce((sum, name) => sum + 2 + Buffer.byteLength(name), 0));
220
+ }
221
+ export function encodeInventory(manifest, overlay) {
222
+ const bounds = overlayProtocolBounds(overlay);
223
+ const baseTree = manifest.spec.baseTree;
224
+ const size = inventoryEncodedBytes(manifest);
225
+ if (!baseTree) {
226
+ if (manifest.spec.entries.length > bounds.maxClassicEntries)
227
+ refuse('OUTPUT_LIMIT', '', 'verification');
228
+ if (size > bounds.inventoryMaxBytes)
229
+ refuse('OUTPUT_LIMIT', '', 'verification');
230
+ const bytes = new Uint8Array(size);
231
+ const view = new DataView(bytes.buffer);
232
+ view.setUint32(0, manifest.spec.entries.length);
233
+ encodeEntries(bytes, view, 4, manifest.spec.entries);
234
+ return bytes;
235
+ }
236
+ const deleted = manifest.spec.deleted ?? [];
237
+ if (manifest.spec.entries.length > bounds.maxOverlayEntries || deleted.length > bounds.maxOverlayEntries) {
238
+ refuse('OUTPUT_LIMIT', '', 'verification');
239
+ }
240
+ const oidBytes = baseTree.objectFormat === 'sha256' ? 32 : 20;
241
+ if (size > bounds.inventoryMaxBytes)
242
+ refuse('OUTPUT_LIMIT', '', 'verification');
243
+ const bytes = new Uint8Array(size);
244
+ const view = new DataView(bytes.buffer);
245
+ view.setUint32(0, OVERLAY_INVENTORY_MAGIC);
246
+ bytes[4] = baseTree.objectFormat === 'sha256' ? 2 : 1;
247
+ let offset = writeHexBytes(bytes, 5, baseTree.commitOid, oidBytes);
248
+ offset = writeHexBytes(bytes, offset, baseTree.treeOid, oidBytes);
249
+ view.setUint32(offset, manifest.spec.entries.length);
250
+ offset += 4;
251
+ offset = encodeEntries(bytes, view, offset, manifest.spec.entries);
252
+ view.setUint32(offset, deleted.length);
253
+ offset += 4;
254
+ for (const name of deleted) {
255
+ const length = Buffer.byteLength(name);
256
+ if (!length || length > 4096)
257
+ refuse('OUTPUT_LIMIT', '', 'verification');
258
+ view.setUint16(offset, length);
259
+ offset += 2;
260
+ Buffer.from(bytes.buffer).write(name, offset, length, 'utf8');
261
+ offset += length;
262
+ }
263
+ return bytes;
264
+ }
265
+ function inventoryEntries(bytes, view, take, count, bounds) {
266
+ const entries = [];
267
+ let total = 0;
268
+ const maxTotalBig = BigInt(bounds.maxTotalBytes);
269
+ const decoder = new TextDecoder('utf-8', { fatal: true });
270
+ for (let index = 0; index < count; index++) {
271
+ const headerWord = view.getUint16(take(2));
272
+ const hasUri = (headerWord & URI_FLAG) !== 0;
273
+ const hasMedia = (headerWord & MEDIA_TYPE_FLAG) !== 0;
274
+ const length = headerWord & NAME_LEN_MASK;
275
+ if (!length || length > 4096)
276
+ refuse('ARTIFACT_INVALID', '', 'verification');
277
+ const at = take(length);
278
+ let name;
279
+ try {
280
+ name = decoder.decode(bytes.subarray(at, at + length));
281
+ }
282
+ catch {
283
+ refuse('ARTIFACT_INVALID', '', 'verification');
284
+ }
285
+ const wide = view.getBigUint64(take(8));
286
+ if (wide > maxTotalBig || (total += Number(wide)) > bounds.maxTotalBytes)
287
+ refuse('ARTIFACT_INVALID', '', 'verification');
288
+ const digestAt = take(32);
289
+ const hex = Buffer.from(bytes.buffer, bytes.byteOffset + digestAt, 32).toString('hex');
290
+ const entry = { name, byteLength: Number(wide), digest: { algorithm: 'sha256', hex } };
291
+ if (hasUri) {
292
+ const uriLen = view.getInt16(take(2));
293
+ if (uriLen === -1)
294
+ entry.uri = null;
295
+ else if (uriLen < 1 || uriLen > LIMITS.artifactUri)
296
+ refuse('ARTIFACT_INVALID', '', 'verification');
297
+ else {
298
+ const uriAt = take(uriLen);
299
+ try {
300
+ entry.uri = decoder.decode(bytes.subarray(uriAt, uriAt + uriLen));
301
+ }
302
+ catch {
303
+ refuse('ARTIFACT_INVALID', '', 'verification');
304
+ }
305
+ }
306
+ }
307
+ if (hasMedia) {
308
+ const mediaLen = view.getInt16(take(2));
309
+ if (mediaLen === -1)
310
+ entry.mediaType = null;
311
+ else if (mediaLen < 1 || mediaLen > LIMITS.mediaType)
312
+ refuse('ARTIFACT_INVALID', '', 'verification');
313
+ else {
314
+ const mediaAt = take(mediaLen);
315
+ try {
316
+ entry.mediaType = decoder.decode(bytes.subarray(mediaAt, mediaAt + mediaLen));
317
+ }
318
+ catch {
319
+ refuse('ARTIFACT_INVALID', '', 'verification');
320
+ }
321
+ }
322
+ }
323
+ entries.push(entry);
324
+ }
325
+ return entries;
326
+ }
327
+ export function inventory(bytes, start, expected, quota, overlay) {
328
+ const bounds = overlayProtocolBounds(overlay);
329
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
330
+ let offset = start;
331
+ const take = (length) => {
332
+ if (offset + length > bytes.byteLength || offset - start + length > bounds.inventoryMaxBytes) {
333
+ refuse('ARTIFACT_INVALID', '', 'verification');
334
+ }
335
+ const at = offset;
336
+ offset += length;
337
+ return at;
338
+ };
339
+ const firstWord = view.getUint32(take(4));
340
+ if (firstWord !== OVERLAY_INVENTORY_MAGIC) {
341
+ if (firstWord > bounds.maxClassicEntries || firstWord !== expected.entryCount)
342
+ refuse('ARTIFACT_INVALID', '', 'verification');
343
+ const entries = inventoryEntries(bytes, view, take, firstWord, bounds);
344
+ return {
345
+ manifest: document({ apiVersion: 'loopwright.dev/v1alpha1', kind: 'ArtifactManifest', metadata: { id: expected.metadataId }, spec: { entries } }, expected, quota, bounds),
346
+ offset,
347
+ };
348
+ }
349
+ const formatByte = bytes[take(1)];
350
+ if (formatByte !== 1 && formatByte !== 2)
351
+ refuse('ARTIFACT_INVALID', '', 'verification');
352
+ const objectFormat = formatByte === 2 ? 'sha256' : 'sha1';
353
+ const oidBytes = formatByte === 2 ? 32 : 20;
354
+ const commitOid = Buffer.from(bytes.buffer, bytes.byteOffset + take(oidBytes), oidBytes).toString('hex');
355
+ const treeOid = Buffer.from(bytes.buffer, bytes.byteOffset + take(oidBytes), oidBytes).toString('hex');
356
+ const count = view.getUint32(take(4));
357
+ if (count > bounds.maxOverlayEntries || count !== expected.entryCount)
358
+ refuse('ARTIFACT_INVALID', '', 'verification');
359
+ const entries = inventoryEntries(bytes, view, take, count, bounds);
360
+ const deletedCount = view.getUint32(take(4));
361
+ if (deletedCount > bounds.maxOverlayEntries)
362
+ refuse('ARTIFACT_INVALID', '', 'verification');
363
+ const deleted = [];
364
+ const decoder = new TextDecoder('utf-8', { fatal: true });
365
+ for (let index = 0; index < deletedCount; index++) {
366
+ const length = view.getUint16(take(2));
367
+ if (!length || length > 4096)
368
+ refuse('ARTIFACT_INVALID', '', 'verification');
369
+ const at = take(length);
370
+ let name;
371
+ try {
372
+ name = decoder.decode(bytes.subarray(at, at + length));
373
+ }
374
+ catch {
375
+ refuse('ARTIFACT_INVALID', '', 'verification');
376
+ }
377
+ deleted.push(name);
378
+ }
379
+ const baseTree = { objectFormat, commitOid, treeOid };
380
+ return {
381
+ manifest: document({ apiVersion: 'loopwright.dev/v1alpha1', kind: 'ArtifactManifest', metadata: { id: expected.metadataId }, spec: { baseTree, entries, deleted } }, expected, quota, bounds),
382
+ offset,
383
+ };
384
+ }
385
+ function checkedDescriptor(raw, maxEntries) {
386
+ const value = record(raw, ['metadataId', 'ref', 'entryCount']);
387
+ return { metadataId: id(value.metadataId), ref: checkedRef(value.ref), entryCount: integer(value.entryCount, 0, maxEntries) };
388
+ }
389
+ function checkedOverlayField(raw) {
390
+ const obj = record(raw, ['maxFiles', 'maxBytes']);
391
+ const maxFiles = integer(obj.maxFiles, OVERLAY_LIMITS.minMaxFiles, OVERLAY_LIMITS.maxMaxFiles);
392
+ const maxBytes = integer(obj.maxBytes, OVERLAY_LIMITS.minMaxBytes, OVERLAY_LIMITS.maxMaxBytes);
393
+ return { maxFiles, maxBytes };
394
+ }
395
+ function expectedPayloadKind(handler) {
396
+ if (handler === 'json-artifact.v1')
397
+ return 'json';
398
+ if (handler === 'json-keys-guard.v1' || handler === 'line-section-guard.v1')
399
+ return 'guard';
400
+ return 'inventories';
401
+ }
402
+ export function checkedHeader(raw) {
403
+ if (!isRecord(raw))
404
+ refuse('ARTIFACT_INVALID', '', 'verification');
405
+ const hasOverlay = Object.hasOwn(raw, 'overlay') && raw.overlay !== undefined;
406
+ const value = record(raw, [
407
+ 'version', 'jobId', 'handler', 'handlerVersion', 'handlerDigest', 'checkId', 'producerNonce',
408
+ 'operationId', 'dispatchId', 'generation', 'subject', 'source', 'candidate', 'parameters', 'payloadKind',
409
+ ...(hasOverlay ? ['overlay'] : []),
410
+ ]);
411
+ const handlerStr = text(value.handler);
412
+ if (value.version !== 1 ||
413
+ value.handlerVersion !== 1 ||
414
+ !['scope.v1', 'no-change.v1', 'json-artifact.v1', 'json-keys-guard.v1', 'line-section-guard.v1'].includes(handlerStr) ||
415
+ !/^[a-f0-9]{32}$/.test(text(value.producerNonce)) ||
416
+ value.payloadKind !== expectedPayloadKind(handlerStr)) {
417
+ refuse('ARTIFACT_INVALID', '', 'verification');
418
+ }
419
+ const overlay = hasOverlay ? checkedOverlayField(value.overlay) : undefined;
420
+ const bounds = overlayProtocolBounds(overlay);
421
+ const subjectCheck = validateDocument({
422
+ apiVersion: 'loopwright.dev/v1alpha1',
423
+ kind: 'Evidence',
424
+ metadata: { id: 'header' },
425
+ spec: {
426
+ checkId: 'header',
427
+ observedStatus: 'blocked',
428
+ producerId: 'header',
429
+ method: 'header',
430
+ level: 'local_execution',
431
+ subject: value.subject,
432
+ artifacts: [],
433
+ reason: 'header validation',
434
+ },
435
+ }, 'Evidence');
436
+ if (!subjectCheck.ok)
437
+ refuse('ARTIFACT_INVALID', '', 'verification');
438
+ return {
439
+ version: 1,
440
+ jobId: id(value.jobId),
441
+ handler: handlerStr,
442
+ handlerVersion: 1,
443
+ handlerDigest: digestValue(value.handlerDigest),
444
+ checkId: id(value.checkId),
445
+ producerNonce: text(value.producerNonce),
446
+ operationId: id(value.operationId),
447
+ dispatchId: id(value.dispatchId),
448
+ generation: integer(value.generation, 0, 256),
449
+ subject: subjectCheck.value.spec.subject,
450
+ source: checkedDescriptor(value.source, bounds.maxManifestEntries),
451
+ candidate: checkedDescriptor(value.candidate, bounds.maxManifestEntries),
452
+ parameters: value.parameters,
453
+ payloadKind: value.payloadKind,
454
+ ...(overlay !== undefined ? { overlay } : {}),
455
+ };
456
+ }
457
+ export function packetSize(header, payloadBytes, maximalFraming = true) {
458
+ const limit = maxPacketBytes(header);
459
+ integer(payloadBytes, 0, limit);
460
+ const sized = maximalFraming
461
+ ? { ...header, jobId: 'x'.repeat(64), operationId: 'x'.repeat(64), dispatchId: 'x'.repeat(64), generation: 256 }
462
+ : header;
463
+ if (Buffer.byteLength(canonical(sized)) > HEADER_BYTES)
464
+ refuse('OUTPUT_LIMIT', '', 'verification');
465
+ const total = 4 + HEADER_BYTES + payloadBytes;
466
+ if (total > limit)
467
+ refuse('OUTPUT_LIMIT', '', 'verification');
468
+ return total;
469
+ }
470
+ export function encodePacket(header, payload) {
471
+ const size = packetSize(header, payload.byteLength, false);
472
+ const bytes = new Uint8Array(size);
473
+ const encoded = canonical(header);
474
+ const view = new DataView(bytes.buffer);
475
+ view.setUint32(0, Buffer.byteLength(encoded));
476
+ Buffer.from(bytes.buffer).write(encoded, 4, HEADER_BYTES, 'utf8');
477
+ bytes.set(payload, 4 + HEADER_BYTES);
478
+ return bytes;
479
+ }
480
+ function verifyJsonPayload(blobSlice, required, equals) {
481
+ let value;
482
+ try {
483
+ value = parsePrivateJson(blobSlice, JSON_FILE_BYTES, 128);
484
+ }
485
+ catch (error) {
486
+ if (!(error instanceof ControllerFailure))
487
+ throw error;
488
+ return 'invalid_json';
489
+ }
490
+ if (value === null || typeof value !== 'object' || Array.isArray(value))
491
+ return 'invalid_json';
492
+ const object = value;
493
+ if (required.some(key => !Object.hasOwn(object, key)))
494
+ return 'property_missing';
495
+ if (Object.entries(equals).some(([key, expected]) => !Object.hasOwn(object, key) || !same(object[key], expected)))
496
+ return 'property_mismatch';
497
+ return null;
498
+ }
499
+ function assertMatchingManifestShapes(source, candidate) {
500
+ if ((source.spec.baseTree === undefined) !== (candidate.spec.baseTree === undefined) ||
501
+ !same(source.spec.baseTree ?? null, candidate.spec.baseTree ?? null)) {
502
+ refuse('ARTIFACT_INVALID', '', 'verification');
503
+ }
504
+ }
505
+ function verifyMerkleBlobSlice(bytes, view, startPos, path, baseTree, expectedRaw, quota) {
506
+ const expected = record(expectedRaw, ['mode', 'oid', 'byteLength', ...(isRecord(expectedRaw) && Object.hasOwn(expectedRaw, 'baseline') ? ['baseline'] : []), ...(isRecord(expectedRaw) && Object.hasOwn(expectedRaw, 'kind') ? ['kind'] : [])]);
507
+ const expectedMode = expected.mode;
508
+ const expectedOid = text(expected.oid);
509
+ const expectedByteLength = integer(expected.byteLength, 0, JSON_FILE_BYTES);
510
+ const oidPattern = baseTree.objectFormat === 'sha256' ? /^[0-9a-f]{64}$/ : /^[0-9a-f]{40}$/;
511
+ if ((expectedMode !== '100644' && expectedMode !== '100755') || !oidPattern.test(expectedOid)) {
512
+ refuse('ARTIFACT_INVALID', '', 'verification');
513
+ }
514
+ let pos = startPos;
515
+ if (pos + 4 > bytes.byteLength)
516
+ refuse('ARTIFACT_INVALID', '', 'verification');
517
+ const blobLen = view.getUint32(pos);
518
+ pos += 4;
519
+ if (blobLen !== expectedByteLength || blobLen > JSON_FILE_BYTES || pos + blobLen + 4 > bytes.byteLength) {
520
+ refuse('ARTIFACT_INVALID', '', 'verification');
521
+ }
522
+ const blobSlice = bytes.subarray(pos, pos + blobLen);
523
+ pos += blobLen;
524
+ const treeCount = view.getUint32(pos);
525
+ pos += 4;
526
+ const segments = path.split('/');
527
+ if (treeCount !== segments.length || treeCount < 1 || treeCount > 16)
528
+ refuse('ARTIFACT_INVALID', '', 'verification');
529
+ const oidByteLength = baseTree.objectFormat === 'sha256' ? 32 : 20;
530
+ let currentTreeOid = baseTree.treeOid;
531
+ let totalTreeBytes = 0;
532
+ for (let index = 0; index < treeCount; index++) {
533
+ if (pos + 4 > bytes.byteLength)
534
+ refuse('ARTIFACT_INVALID', '', 'verification');
535
+ const treeLen = view.getUint32(pos);
536
+ pos += 4;
537
+ if (!treeLen || treeLen > 262144 || (totalTreeBytes += treeLen) > 262144 || pos + treeLen > bytes.byteLength) {
538
+ refuse('ARTIFACT_INVALID', '', 'verification');
539
+ }
540
+ quota.charge(treeLen);
541
+ const treeSlice = bytes.subarray(pos, pos + treeLen);
542
+ pos += treeLen;
543
+ if (gitObjectOid(baseTree.objectFormat, 'tree', treeSlice) !== currentTreeOid)
544
+ refuse('ARTIFACT_INVALID', '', 'verification');
545
+ const treeEntries = parseGitTreeEntries(treeSlice, oidByteLength, 'verification', 'ARTIFACT_INVALID');
546
+ const match = treeEntries.find(entry => entry.name === segments[index]);
547
+ if (!match)
548
+ refuse('ARTIFACT_INVALID', '', 'verification');
549
+ if (index < treeCount - 1) {
550
+ if (match.mode !== '40000')
551
+ refuse('ARTIFACT_INVALID', '', 'verification');
552
+ currentTreeOid = match.oid;
553
+ }
554
+ else {
555
+ if (match.mode !== expectedMode || match.oid !== expectedOid)
556
+ refuse('ARTIFACT_INVALID', '', 'verification');
557
+ if (gitObjectOid(baseTree.objectFormat, 'blob', blobSlice) !== match.oid)
558
+ refuse('ARTIFACT_INVALID', '', 'verification');
559
+ }
560
+ }
561
+ return { blobSlice, nextPos: pos };
562
+ }
563
+ function isPlainGuardObject(val) {
564
+ return val !== null && typeof val === 'object' && !Array.isArray(val);
565
+ }
566
+ /** Strict null-prototype JSON parser rejecting duplicate keys, trailing tokens, and non-finite numbers. */
567
+ function parseStrictGuardJson(bytes) {
568
+ if (bytes.byteLength > JSON_FILE_BYTES)
569
+ return { ok: false, message: 'JSON file exceeds byte limit' };
570
+ let source;
571
+ try {
572
+ source = new TextDecoder('utf-8', { fatal: true }).decode(bytes);
573
+ }
574
+ catch {
575
+ return { ok: false, message: 'Invalid UTF-8 encoding in JSON file' };
576
+ }
577
+ let offset = 0;
578
+ let nodes = 0;
579
+ const skipSpace = () => {
580
+ while (offset < source.length) {
581
+ const ch = source.charCodeAt(offset);
582
+ if (ch !== 0x20 && ch !== 0x09 && ch !== 0x0a && ch !== 0x0d)
583
+ break;
584
+ offset++;
585
+ }
586
+ };
587
+ const parseStr = () => {
588
+ const start = offset++;
589
+ while (offset < source.length) {
590
+ const ch = source[offset++];
591
+ if (ch === '\\') {
592
+ offset++;
593
+ continue;
594
+ }
595
+ if (ch === '"') {
596
+ const parsed = JSON.parse(source.slice(start, offset));
597
+ if (typeof parsed !== 'string')
598
+ throw new Error('Invalid string');
599
+ if (LONE_SURROGATE_PATTERN.test(parsed))
600
+ throw new Error('Invalid lone UTF-16 surrogate in JSON string');
601
+ return parsed;
602
+ }
603
+ }
604
+ throw new Error('Unterminated JSON string');
605
+ };
606
+ const parseVal = (depth) => {
607
+ if (++nodes > 131_072 || depth > 64)
608
+ throw new Error('JSON complexity limit exceeded');
609
+ skipSpace();
610
+ if (offset >= source.length)
611
+ throw new Error('Unexpected end of JSON input');
612
+ const ch = source[offset];
613
+ if (ch === '"')
614
+ return parseStr();
615
+ if (ch === '{') {
616
+ offset++;
617
+ skipSpace();
618
+ const obj = Object.create(null);
619
+ const seen = new Set();
620
+ if (source[offset] === '}') {
621
+ offset++;
622
+ return obj;
623
+ }
624
+ let count = 0;
625
+ for (;;) {
626
+ if (++count > 16_384)
627
+ throw new Error('JSON object property limit exceeded');
628
+ skipSpace();
629
+ if (source[offset] !== '"')
630
+ throw new Error('Expected JSON property name');
631
+ const key = parseStr();
632
+ if (seen.has(key))
633
+ throw new Error(`Duplicate JSON key "${key}"`);
634
+ seen.add(key);
635
+ skipSpace();
636
+ if (source[offset++] !== ':')
637
+ throw new Error('Expected ":" after property name');
638
+ obj[key] = parseVal(depth + 1);
639
+ skipSpace();
640
+ const delim = source[offset++];
641
+ if (delim === '}')
642
+ return obj;
643
+ if (delim !== ',')
644
+ throw new Error('Expected "," or "}" in JSON object');
645
+ }
646
+ }
647
+ if (ch === '[') {
648
+ offset++;
649
+ skipSpace();
650
+ const arr = [];
651
+ if (source[offset] === ']') {
652
+ offset++;
653
+ return arr;
654
+ }
655
+ let count = 0;
656
+ for (;;) {
657
+ if (++count > 16_384)
658
+ throw new Error('JSON array length limit exceeded');
659
+ arr.push(parseVal(depth + 1));
660
+ skipSpace();
661
+ const delim = source[offset++];
662
+ if (delim === ']')
663
+ return arr;
664
+ if (delim !== ',')
665
+ throw new Error('Expected "," or "]" in JSON array');
666
+ }
667
+ }
668
+ const lit = /^(?:true|false|null|-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?)/.exec(source.slice(offset));
669
+ if (!lit)
670
+ throw new Error('Invalid JSON token');
671
+ offset += lit[0].length;
672
+ if (lit[0] === 'true')
673
+ return true;
674
+ if (lit[0] === 'false')
675
+ return false;
676
+ if (lit[0] === 'null')
677
+ return null;
678
+ const num = Number(lit[0]);
679
+ if (!Number.isFinite(num))
680
+ throw new Error('Non-finite JSON number');
681
+ return Object.is(num, -0) ? 0 : num;
682
+ };
683
+ try {
684
+ const val = parseVal(1);
685
+ skipSpace();
686
+ if (offset !== source.length)
687
+ return { ok: false, message: 'Unexpected trailing tokens in JSON file' };
688
+ return { ok: true, value: val };
689
+ }
690
+ catch (err) {
691
+ return { ok: false, message: err instanceof Error ? err.message : 'Invalid JSON' };
692
+ }
693
+ }
694
+ function guardJsonSame(a, b) {
695
+ if (a === b)
696
+ return true;
697
+ if (a === null || b === null || typeof a !== 'object' || typeof b !== 'object')
698
+ return false;
699
+ if (Array.isArray(a) !== Array.isArray(b))
700
+ return false;
701
+ if (Array.isArray(a)) {
702
+ const arrB = b;
703
+ if (a.length !== arrB.length)
704
+ return false;
705
+ for (let i = 0; i < a.length; i++)
706
+ if (!guardJsonSame(a[i], arrB[i]))
707
+ return false;
708
+ return true;
709
+ }
710
+ const objA = a;
711
+ const objB = b;
712
+ const keysA = Object.keys(objA);
713
+ const keysB = Object.keys(objB);
714
+ if (keysA.length !== keysB.length)
715
+ return false;
716
+ for (const k of keysA) {
717
+ if (!Object.hasOwn(objB, k) || !guardJsonSame(objA[k], objB[k]))
718
+ return false;
719
+ }
720
+ return true;
721
+ }
722
+ function encodeRfc6901(tokens) {
723
+ if (tokens.length === 0)
724
+ return '';
725
+ return '/' + tokens.map(tok => tok.replace(/~/g, '~0').replace(/\//g, '~1')).join('/');
726
+ }
727
+ function decodeRfc6901(pointer) {
728
+ return pointer
729
+ .slice(1)
730
+ .split('/')
731
+ .map(tok => tok.replace(/~1/g, '/').replace(/~0/g, '~'));
732
+ }
733
+ function isTokensCovered(tokens, allowedList) {
734
+ if (tokens.length === 0)
735
+ return false;
736
+ return allowedList.some(allowed => allowed.length <= tokens.length && allowed.every((seg, idx) => seg === tokens[idx]));
737
+ }
738
+ function clipText(input, maxChars) {
739
+ const safe = input.replace(/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/gu, '\uFFFD');
740
+ return safe.length <= maxChars ? safe : Array.from(safe).slice(0, maxChars).join('');
741
+ }
742
+ function makeGuardFinding(title, path, evidence, line) {
743
+ const out = Object.create(null);
744
+ out.title = clipText(title, LIMITS.findingTitle);
745
+ out.severity = 'high';
746
+ out.path = path;
747
+ if (line !== undefined)
748
+ out.line = line;
749
+ out.evidence = clipText(evidence, LIMITS.findingEvidence);
750
+ return freeze(out);
751
+ }
752
+ function boundGuardFindings(findings) {
753
+ const capped = [];
754
+ let bytes = 0;
755
+ for (const item of findings.slice(0, LIMITS.findings)) {
756
+ const itemBytes = Buffer.byteLength(canonical(item));
757
+ if (bytes + itemBytes > 32_000 && capped.length > 0)
758
+ break;
759
+ bytes += itemBytes;
760
+ capped.push(item);
761
+ }
762
+ return freeze(capped);
763
+ }
764
+ function evaluateJsonKeysGuard(path, allowedPointers, baselineBytes, candidateBytes) {
765
+ if (baselineBytes === null || candidateBytes === null) {
766
+ const which = baselineBytes === null ? 'baseline' : 'candidate';
767
+ return {
768
+ reason: 'missing_file',
769
+ detail: `Guarded JSON file "${path}" is missing in ${which}`,
770
+ findings: boundGuardFindings([makeGuardFinding(`Missing guarded JSON file (${which})`, path, `File "${path}" is missing in ${which}`)]),
771
+ };
772
+ }
773
+ const parsedBase = parseStrictGuardJson(baselineBytes);
774
+ if (!parsedBase.ok) {
775
+ return {
776
+ reason: 'invalid_json',
777
+ detail: `Baseline JSON "${path}" is invalid: ${parsedBase.message}`,
778
+ findings: boundGuardFindings([makeGuardFinding('Invalid baseline JSON', path, parsedBase.message)]),
779
+ };
780
+ }
781
+ const parsedCand = parseStrictGuardJson(candidateBytes);
782
+ if (!parsedCand.ok) {
783
+ return {
784
+ reason: 'invalid_json',
785
+ detail: `Candidate JSON "${path}" is invalid: ${parsedCand.message}`,
786
+ findings: boundGuardFindings([makeGuardFinding('Invalid candidate JSON', path, parsedCand.message)]),
787
+ };
788
+ }
789
+ const allowedDecoded = allowedPointers.map(decodeRfc6901);
790
+ const violations = [];
791
+ const recordIfDisallowed = (targetTokens, kind) => {
792
+ if (violations.length >= LIMITS.findings)
793
+ return;
794
+ if (isTokensCovered(targetTokens, allowedDecoded))
795
+ return;
796
+ violations.push({ pointer: encodeRfc6901(targetTokens), kind });
797
+ };
798
+ const diffValues = (baseVal, candVal, tokens) => {
799
+ if (violations.length >= LIMITS.findings)
800
+ return;
801
+ if (guardJsonSame(baseVal, candVal))
802
+ return;
803
+ if (isTokensCovered(tokens, allowedDecoded))
804
+ return;
805
+ if (isPlainGuardObject(baseVal) && isPlainGuardObject(candVal)) {
806
+ const unionKeys = [...new Set([...Object.keys(baseVal), ...Object.keys(candVal)])].sort();
807
+ for (const k of unionKeys) {
808
+ if (violations.length >= LIMITS.findings)
809
+ return;
810
+ const inBase = Object.hasOwn(baseVal, k);
811
+ const inCand = Object.hasOwn(candVal, k);
812
+ if (!inBase)
813
+ recordIfDisallowed([...tokens, k], 'added');
814
+ else if (!inCand)
815
+ recordIfDisallowed([...tokens, k], 'removed');
816
+ else
817
+ diffValues(baseVal[k], candVal[k], [...tokens, k]);
818
+ }
819
+ return;
820
+ }
821
+ if (Array.isArray(baseVal) && Array.isArray(candVal)) {
822
+ const maxLen = Math.max(baseVal.length, candVal.length);
823
+ for (let i = 0; i < maxLen; i++) {
824
+ if (violations.length >= LIMITS.findings)
825
+ return;
826
+ if (i >= baseVal.length)
827
+ recordIfDisallowed([...tokens, String(i)], 'added');
828
+ else if (i >= candVal.length)
829
+ recordIfDisallowed([...tokens, String(i)], 'removed');
830
+ else
831
+ diffValues(baseVal[i], candVal[i], [...tokens, String(i)]);
832
+ }
833
+ return;
834
+ }
835
+ violations.push({ pointer: encodeRfc6901(tokens), kind: 'modified' });
836
+ };
837
+ diffValues(parsedBase.value, parsedCand.value, []);
838
+ if (violations.length === 0)
839
+ return { reason: null };
840
+ const findings = boundGuardFindings(violations.map(v => makeGuardFinding(`Disallowed JSON edit at ${v.pointer}`, path, `JSON pointer "${v.pointer}" was ${v.kind} outside allowedPointers`)));
841
+ const preview = violations.slice(0, 8).map(v => v.pointer).join(', ');
842
+ return {
843
+ reason: 'disallowed_json_pointer',
844
+ detail: clipText(`Disallowed JSON edits outside allowedPointers in ${path}: ${preview}`, 1024),
845
+ findings,
846
+ };
847
+ }
848
+ function extractOutsideSegments(content, startMarker, endMarker, label, path) {
849
+ const lines = content.split('\n');
850
+ const segments = [[]];
851
+ let inSection = false;
852
+ let openStartLine = 0;
853
+ let sectionCount = 0;
854
+ for (let i = 0; i < lines.length; i++) {
855
+ const line = lines[i];
856
+ const lineNo = i + 1;
857
+ const lineNoCr = line.endsWith('\r') ? line.slice(0, -1) : line;
858
+ const trimmed = lineNoCr.trim();
859
+ const isStart = lineNoCr === startMarker || trimmed === startMarker;
860
+ const isEnd = lineNoCr === endMarker || trimmed === endMarker;
861
+ if (isStart) {
862
+ if (inSection) {
863
+ const msg = `Nested startMarker "${startMarker}" in ${label} at line ${lineNo} (section opened at line ${openStartLine})`;
864
+ return { ok: false, reason: 'unbalanced_markers', detail: clipText(msg, 1024), finding: makeGuardFinding('Nested startMarker in guarded file', path, msg, lineNo) };
865
+ }
866
+ segments.at(-1).push({ text: lineNoCr, line: lineNo });
867
+ inSection = true;
868
+ openStartLine = lineNo;
869
+ sectionCount++;
870
+ }
871
+ else if (isEnd) {
872
+ if (!inSection) {
873
+ const msg = `Unmatched endMarker "${endMarker}" without startMarker in ${label} at line ${lineNo}`;
874
+ return { ok: false, reason: 'unbalanced_markers', detail: clipText(msg, 1024), finding: makeGuardFinding('Unmatched endMarker in guarded file', path, msg, lineNo) };
875
+ }
876
+ inSection = false;
877
+ segments.push([{ text: lineNoCr, line: lineNo }]);
878
+ }
879
+ else if (!inSection) {
880
+ segments.at(-1).push({ text: line, line: lineNo });
881
+ }
882
+ }
883
+ if (inSection) {
884
+ const msg = `Unclosed startMarker "${startMarker}" in ${label} opened at line ${openStartLine}`;
885
+ return { ok: false, reason: 'unbalanced_markers', detail: clipText(msg, 1024), finding: makeGuardFinding('Unclosed startMarker in guarded file', path, msg, openStartLine) };
886
+ }
887
+ if (sectionCount === 0) {
888
+ const msg = `No "${startMarker}" .. "${endMarker}" section found in ${label}`;
889
+ return { ok: false, reason: 'missing_markers', detail: clipText(msg, 1024), finding: makeGuardFinding('Missing section markers in guarded file', path, msg, 1) };
890
+ }
891
+ return { ok: true, segments };
892
+ }
893
+ function evaluateLineSectionGuard(path, startMarker, endMarker, baselineBytes, candidateBytes) {
894
+ if (baselineBytes === null || candidateBytes === null) {
895
+ const which = baselineBytes === null ? 'baseline' : 'candidate';
896
+ return {
897
+ reason: 'missing_file',
898
+ detail: `Guarded file "${path}" is missing in ${which}`,
899
+ findings: boundGuardFindings([makeGuardFinding(`Missing guarded file (${which})`, path, `File "${path}" is missing in ${which}`)]),
900
+ };
901
+ }
902
+ const decoder = new TextDecoder('utf-8', { fatal: true });
903
+ let baseText;
904
+ let candText;
905
+ try {
906
+ baseText = decoder.decode(baselineBytes);
907
+ }
908
+ catch {
909
+ return {
910
+ reason: 'invalid_utf8',
911
+ detail: `Baseline file "${path}" is not valid UTF-8`,
912
+ findings: boundGuardFindings([makeGuardFinding('Invalid UTF-8 in baseline file', path, `Baseline "${path}" failed UTF-8 decoding`)]),
913
+ };
914
+ }
915
+ try {
916
+ candText = decoder.decode(candidateBytes);
917
+ }
918
+ catch {
919
+ return {
920
+ reason: 'invalid_utf8',
921
+ detail: `Candidate file "${path}" is not valid UTF-8`,
922
+ findings: boundGuardFindings([makeGuardFinding('Invalid UTF-8 in candidate file', path, `Candidate "${path}" failed UTF-8 decoding`)]),
923
+ };
924
+ }
925
+ const baseExtracted = extractOutsideSegments(baseText, startMarker, endMarker, 'baseline', path);
926
+ if (!baseExtracted.ok) {
927
+ return { reason: baseExtracted.reason, detail: baseExtracted.detail, findings: boundGuardFindings([baseExtracted.finding]) };
928
+ }
929
+ const candExtracted = extractOutsideSegments(candText, startMarker, endMarker, 'candidate', path);
930
+ if (!candExtracted.ok) {
931
+ return { reason: candExtracted.reason, detail: candExtracted.detail, findings: boundGuardFindings([candExtracted.finding]) };
932
+ }
933
+ const baseSegs = baseExtracted.segments;
934
+ const candSegs = candExtracted.segments;
935
+ const maxSegs = Math.max(baseSegs.length, candSegs.length);
936
+ for (let s = 0; s < maxSegs; s++) {
937
+ if (s >= baseSegs.length || s >= candSegs.length) {
938
+ const lineNo = candSegs[s]?.[0]?.line ?? candSegs.at(-1)?.at(-1)?.line ?? 1;
939
+ const msg = `Guarded section count changed in "${path}" (baseline: ${baseSegs.length - 1}, candidate: ${candSegs.length - 1})`;
940
+ return {
941
+ reason: 'outside_section_modified',
942
+ detail: clipText(msg, 1024),
943
+ findings: boundGuardFindings([makeGuardFinding('Guarded section structure modified', path, msg, lineNo)]),
944
+ };
945
+ }
946
+ const bSeg = baseSegs[s];
947
+ const cSeg = candSegs[s];
948
+ const maxLines = Math.max(bSeg.length, cSeg.length);
949
+ for (let j = 0; j < maxLines; j++) {
950
+ if (j >= bSeg.length) {
951
+ const added = cSeg[j];
952
+ const msg = `Line ${added.line} added outside guarded section in "${path}": ${clipText(added.text, 200)}`;
953
+ return {
954
+ reason: 'outside_section_modified',
955
+ detail: clipText(msg, 1024),
956
+ findings: boundGuardFindings([makeGuardFinding('Line added outside guarded section', path, msg, added.line)]),
957
+ };
958
+ }
959
+ if (j >= cSeg.length) {
960
+ const removed = bSeg[j];
961
+ const reportLine = cSeg.at(-1)?.line ?? 1;
962
+ const msg = `Baseline line ${removed.line} removed outside guarded section in "${path}": ${clipText(removed.text, 200)}`;
963
+ return {
964
+ reason: 'outside_section_modified',
965
+ detail: clipText(msg, 1024),
966
+ findings: boundGuardFindings([makeGuardFinding('Line removed outside guarded section', path, msg, reportLine)]),
967
+ };
968
+ }
969
+ if (bSeg[j].text !== cSeg[j].text) {
970
+ const bLine = bSeg[j];
971
+ const cLine = cSeg[j];
972
+ const msg = `Out-of-section edit at line ${cLine.line} (baseline line ${bLine.line}) in "${path}": expected ${JSON.stringify(clipText(bLine.text, 120))}, got ${JSON.stringify(clipText(cLine.text, 120))}`;
973
+ return {
974
+ reason: 'outside_section_modified',
975
+ detail: clipText(msg, 1024),
976
+ findings: boundGuardFindings([makeGuardFinding('Line modified outside guarded section', path, msg, cLine.line)]),
977
+ };
978
+ }
979
+ }
980
+ }
981
+ return { reason: null };
982
+ }
983
+ export function evaluatePacket(bytes) {
984
+ if (!(bytes instanceof Uint8Array) ||
985
+ types.isSharedArrayBuffer(bytes.buffer) ||
986
+ bytes.byteOffset !== 0 ||
987
+ bytes.byteLength !== bytes.buffer.byteLength ||
988
+ bytes.byteLength < 16392 ||
989
+ bytes.byteLength > MAX_ABSOLUTE_PACKET_BYTES) {
990
+ refuse('ARTIFACT_INVALID', '', 'verification');
991
+ }
992
+ const view = new DataView(bytes.buffer);
993
+ const length = view.getUint32(0);
994
+ if (!length || length > HEADER_BYTES)
995
+ refuse('ARTIFACT_INVALID', '', 'verification');
996
+ for (let index = 4 + length; index < 4 + HEADER_BYTES; index++)
997
+ if (bytes[index] !== 0)
998
+ refuse('ARTIFACT_INVALID', '', 'verification');
999
+ const raw = parsePrivateJson(bytes.subarray(4, 4 + length), HEADER_BYTES, 256);
1000
+ const header = checkedHeader(raw);
1001
+ if (canonical(raw) !== canonical(header) || Buffer.byteLength(canonical(raw)) !== length)
1002
+ refuse('ARTIFACT_INVALID', '', 'verification');
1003
+ packetSize(header, bytes.byteLength - 4 - HEADER_BYTES, false);
1004
+ const bounds = overlayProtocolBounds(header.overlay);
1005
+ const quota = new AllocationQuota(bounds.allocationMaxBytes);
1006
+ quota.charge(bytes.byteLength);
1007
+ const first = inventory(bytes, 4 + HEADER_BYTES, header.source, quota, header.overlay);
1008
+ const second = inventory(bytes, first.offset, header.candidate, quota, header.overlay);
1009
+ const source = first.manifest;
1010
+ const candidate = second.manifest;
1011
+ assertMatchingManifestShapes(source, candidate);
1012
+ let reason = null;
1013
+ let method;
1014
+ let detail;
1015
+ let findings;
1016
+ if (header.payloadKind === 'inventories') {
1017
+ if (second.offset !== bytes.byteLength)
1018
+ refuse('ARTIFACT_INVALID', '', 'verification');
1019
+ const sourceByName = new Map(source.spec.entries.map(entry => [entry.name, entry]));
1020
+ const candByName = new Map(candidate.spec.entries.map(entry => [entry.name, entry]));
1021
+ const allEntryNames = new Set([...sourceByName.keys(), ...candByName.keys()]);
1022
+ const entryChanged = [...allEntryNames].filter(name => !same(sourceByName.get(name) ?? null, candByName.get(name) ?? null));
1023
+ const sourceDeleted = new Set(source.spec.deleted ?? []);
1024
+ const candidateDeleted = new Set(candidate.spec.deleted ?? []);
1025
+ const allDeletedNames = new Set([...sourceDeleted, ...candidateDeleted]);
1026
+ const deletedChanged = [...allDeletedNames].filter(name => sourceDeleted.has(name) !== candidateDeleted.has(name));
1027
+ const changed = [...new Set([...entryChanged, ...deletedChanged])];
1028
+ if (header.handler === 'no-change.v1') {
1029
+ record(header.parameters, []);
1030
+ method = 'verify_no_change';
1031
+ if (changed.length)
1032
+ reason = 'candidate_changed';
1033
+ }
1034
+ else {
1035
+ const parameters = record(header.parameters, ['contract']);
1036
+ const contract = validateDocument(parameters.contract, 'TaskContract');
1037
+ if (!contract.ok)
1038
+ refuse('ARTIFACT_INVALID', '', 'verification');
1039
+ if (!same(contract.value.spec.budgets.overlay ?? null, header.overlay ?? null))
1040
+ refuse('ARTIFACT_INVALID', '', 'verification');
1041
+ const admitted = admitTask(contract.value, { admissionId: 'header', runId: 'header' });
1042
+ if (!admitted.ok || !same(admitted.value.spec.contractHash, header.subject.contractHash))
1043
+ refuse('ARTIFACT_INVALID', '', 'verification');
1044
+ method = 'verify_scope';
1045
+ for (const name of changed) {
1046
+ const allowed = isWritablePath(contract.value, name);
1047
+ if (!allowed.ok)
1048
+ refuse('ARTIFACT_INVALID', '', 'verification');
1049
+ if (!allowed.value)
1050
+ reason = 'outside_scope';
1051
+ }
1052
+ }
1053
+ }
1054
+ else if (header.payloadKind === 'json') {
1055
+ const parameters = record(header.parameters, ['path', 'expected', 'required', 'equals']);
1056
+ const path = text(parameters.path, '', 1024);
1057
+ const vPath = validateRelativePath(path);
1058
+ if (!vPath.ok)
1059
+ refuse('ARTIFACT_INVALID', '', 'verification');
1060
+ const selected = candidate.spec.entries.find(entry => entry.name === path) ?? null;
1061
+ const required = list(parameters.required, '', 128).map(item => text(item, '', 128));
1062
+ const equals = parameters.equals;
1063
+ if (equals === null ||
1064
+ typeof equals !== 'object' ||
1065
+ Array.isArray(equals) ||
1066
+ Object.keys(equals).length > 128 ||
1067
+ Object.values(equals).some(value => value !== null && !['string', 'boolean', 'number'].includes(typeof value))) {
1068
+ refuse('ARTIFACT_INVALID', '', 'verification');
1069
+ }
1070
+ method = 'verify_json';
1071
+ const baseTree = candidate.spec.baseTree;
1072
+ const startPos = second.offset;
1073
+ if (!baseTree) {
1074
+ if (!same(parameters.expected, selected))
1075
+ refuse('ARTIFACT_INVALID', '', 'verification');
1076
+ if (startPos + 4 > bytes.byteLength)
1077
+ refuse('ARTIFACT_INVALID', '', 'verification');
1078
+ const count = view.getUint32(startPos);
1079
+ const offset = startPos + 4;
1080
+ if (count > JSON_FILE_BYTES || offset + count !== bytes.byteLength)
1081
+ refuse('ARTIFACT_INVALID', '', 'verification');
1082
+ if (selected === null) {
1083
+ if (count !== 0)
1084
+ refuse('ARTIFACT_INVALID', '', 'verification');
1085
+ reason = 'missing_file';
1086
+ }
1087
+ else {
1088
+ if (count !== selected.byteLength || !same(fileHash(bytes.subarray(offset)), selected.digest))
1089
+ refuse('ARTIFACT_INVALID', '', 'verification');
1090
+ reason = verifyJsonPayload(bytes.subarray(offset), required, equals);
1091
+ }
1092
+ }
1093
+ else if (selected !== null) {
1094
+ if (!same(parameters.expected, selected))
1095
+ refuse('ARTIFACT_INVALID', '', 'verification');
1096
+ if (startPos + 4 > bytes.byteLength)
1097
+ refuse('ARTIFACT_INVALID', '', 'verification');
1098
+ const count = view.getUint32(startPos);
1099
+ const offset = startPos + 4;
1100
+ if (count > JSON_FILE_BYTES || offset + count !== bytes.byteLength)
1101
+ refuse('ARTIFACT_INVALID', '', 'verification');
1102
+ if (count !== selected.byteLength || !same(fileHash(bytes.subarray(offset)), selected.digest))
1103
+ refuse('ARTIFACT_INVALID', '', 'verification');
1104
+ reason = verifyJsonPayload(bytes.subarray(offset), required, equals);
1105
+ }
1106
+ else if ((candidate.spec.deleted ?? []).includes(path)) {
1107
+ if (parameters.expected !== null || startPos + 4 > bytes.byteLength)
1108
+ refuse('ARTIFACT_INVALID', '', 'verification');
1109
+ const count = view.getUint32(startPos);
1110
+ const offset = startPos + 4;
1111
+ if (count !== 0 || offset !== bytes.byteLength)
1112
+ refuse('ARTIFACT_INVALID', '', 'verification');
1113
+ reason = 'missing_file';
1114
+ }
1115
+ else if (parameters.expected === null) {
1116
+ if (startPos + 4 > bytes.byteLength)
1117
+ refuse('ARTIFACT_INVALID', '', 'verification');
1118
+ const count = view.getUint32(startPos);
1119
+ const offset = startPos + 4;
1120
+ if (count !== 0 || offset !== bytes.byteLength)
1121
+ refuse('ARTIFACT_INVALID', '', 'verification');
1122
+ reason = 'missing_file';
1123
+ }
1124
+ else {
1125
+ const expectedCheck = record(parameters.expected, ['baseline', 'mode', 'oid', 'byteLength']);
1126
+ if (expectedCheck.baseline !== true)
1127
+ refuse('ARTIFACT_INVALID', '', 'verification');
1128
+ const verified = verifyMerkleBlobSlice(bytes, view, startPos, path, baseTree, parameters.expected, quota);
1129
+ if (verified.nextPos !== bytes.byteLength)
1130
+ refuse('ARTIFACT_INVALID', '', 'verification');
1131
+ reason = verifyJsonPayload(verified.blobSlice, required, equals);
1132
+ }
1133
+ }
1134
+ else {
1135
+ const isJsonKeys = header.handler === 'json-keys-guard.v1';
1136
+ const parameters = record(header.parameters, isJsonKeys ? ['path', 'baseline', 'candidate', 'allowedPointers'] : ['path', 'baseline', 'candidate', 'startMarker', 'endMarker']);
1137
+ const path = text(parameters.path, '', 1024);
1138
+ if (!validateRelativePath(path).ok)
1139
+ refuse('ARTIFACT_INVALID', '', 'verification');
1140
+ const baseTree = candidate.spec.baseTree;
1141
+ const sourceSelected = source.spec.entries.find(entry => entry.name === path) ?? null;
1142
+ const sourceDeleted = (source.spec.deleted ?? []).includes(path);
1143
+ const candSelected = candidate.spec.entries.find(entry => entry.name === path) ?? null;
1144
+ const candDeleted = (candidate.spec.deleted ?? []).includes(path);
1145
+ let pos = second.offset;
1146
+ let baselineBytes = null;
1147
+ if (!isRecord(parameters.baseline))
1148
+ refuse('ARTIFACT_INVALID', '', 'verification');
1149
+ const baseKind = text(parameters.baseline.kind, '', 32);
1150
+ if (!baseTree) {
1151
+ if (baseKind === 'missing') {
1152
+ record(parameters.baseline, ['kind']);
1153
+ if (sourceSelected !== null)
1154
+ refuse('ARTIFACT_INVALID', '', 'verification');
1155
+ }
1156
+ else if (baseKind === 'overlay') {
1157
+ const bSpec = record(parameters.baseline, ['kind', 'entry']);
1158
+ if (sourceSelected === null || !same(bSpec.entry, sourceSelected) || pos + 4 > bytes.byteLength)
1159
+ refuse('ARTIFACT_INVALID', '', 'verification');
1160
+ const len = view.getUint32(pos);
1161
+ pos += 4;
1162
+ if (len > JSON_FILE_BYTES || len !== sourceSelected.byteLength || pos + len > bytes.byteLength)
1163
+ refuse('ARTIFACT_INVALID', '', 'verification');
1164
+ const slice = bytes.subarray(pos, pos + len);
1165
+ pos += len;
1166
+ if (!same(fileHash(slice), sourceSelected.digest))
1167
+ refuse('ARTIFACT_INVALID', '', 'verification');
1168
+ baselineBytes = slice;
1169
+ }
1170
+ else {
1171
+ refuse('ARTIFACT_INVALID', '', 'verification');
1172
+ }
1173
+ }
1174
+ else if (sourceSelected !== null) {
1175
+ const bSpec = record(parameters.baseline, ['kind', 'entry']);
1176
+ if (baseKind !== 'overlay' || !same(bSpec.entry, sourceSelected) || pos + 4 > bytes.byteLength)
1177
+ refuse('ARTIFACT_INVALID', '', 'verification');
1178
+ const len = view.getUint32(pos);
1179
+ pos += 4;
1180
+ if (len > JSON_FILE_BYTES || len !== sourceSelected.byteLength || pos + len > bytes.byteLength)
1181
+ refuse('ARTIFACT_INVALID', '', 'verification');
1182
+ const slice = bytes.subarray(pos, pos + len);
1183
+ pos += len;
1184
+ if (!same(fileHash(slice), sourceSelected.digest))
1185
+ refuse('ARTIFACT_INVALID', '', 'verification');
1186
+ baselineBytes = slice;
1187
+ }
1188
+ else if (sourceDeleted) {
1189
+ record(parameters.baseline, ['kind']);
1190
+ if (baseKind !== 'missing')
1191
+ refuse('ARTIFACT_INVALID', '', 'verification');
1192
+ }
1193
+ else if (baseKind === 'missing') {
1194
+ record(parameters.baseline, ['kind']);
1195
+ }
1196
+ else if (baseKind === 'merkle_blob') {
1197
+ const verified = verifyMerkleBlobSlice(bytes, view, pos, path, source.spec.baseTree, parameters.baseline, quota);
1198
+ baselineBytes = verified.blobSlice;
1199
+ pos = verified.nextPos;
1200
+ }
1201
+ else {
1202
+ refuse('ARTIFACT_INVALID', '', 'verification');
1203
+ }
1204
+ let candidateBytes = null;
1205
+ if (!isRecord(parameters.candidate))
1206
+ refuse('ARTIFACT_INVALID', '', 'verification');
1207
+ const candKind = text(parameters.candidate.kind, '', 32);
1208
+ if (!baseTree) {
1209
+ if (candKind === 'missing') {
1210
+ record(parameters.candidate, ['kind']);
1211
+ if (candSelected !== null)
1212
+ refuse('ARTIFACT_INVALID', '', 'verification');
1213
+ }
1214
+ else if (candKind === 'overlay') {
1215
+ const cSpec = record(parameters.candidate, ['kind', 'entry']);
1216
+ if (candSelected === null || !same(cSpec.entry, candSelected) || pos + 4 > bytes.byteLength)
1217
+ refuse('ARTIFACT_INVALID', '', 'verification');
1218
+ const len = view.getUint32(pos);
1219
+ pos += 4;
1220
+ if (len > JSON_FILE_BYTES || len !== candSelected.byteLength || pos + len > bytes.byteLength)
1221
+ refuse('ARTIFACT_INVALID', '', 'verification');
1222
+ const slice = bytes.subarray(pos, pos + len);
1223
+ pos += len;
1224
+ if (!same(fileHash(slice), candSelected.digest))
1225
+ refuse('ARTIFACT_INVALID', '', 'verification');
1226
+ candidateBytes = slice;
1227
+ }
1228
+ else {
1229
+ refuse('ARTIFACT_INVALID', '', 'verification');
1230
+ }
1231
+ }
1232
+ else if (candSelected !== null) {
1233
+ const cSpec = record(parameters.candidate, ['kind', 'entry']);
1234
+ if (candKind !== 'overlay' || !same(cSpec.entry, candSelected) || pos + 4 > bytes.byteLength)
1235
+ refuse('ARTIFACT_INVALID', '', 'verification');
1236
+ const len = view.getUint32(pos);
1237
+ pos += 4;
1238
+ if (len > JSON_FILE_BYTES || len !== candSelected.byteLength || pos + len > bytes.byteLength)
1239
+ refuse('ARTIFACT_INVALID', '', 'verification');
1240
+ const slice = bytes.subarray(pos, pos + len);
1241
+ pos += len;
1242
+ if (!same(fileHash(slice), candSelected.digest))
1243
+ refuse('ARTIFACT_INVALID', '', 'verification');
1244
+ candidateBytes = slice;
1245
+ }
1246
+ else if (candDeleted) {
1247
+ record(parameters.candidate, ['kind']);
1248
+ if (candKind !== 'deleted')
1249
+ refuse('ARTIFACT_INVALID', '', 'verification');
1250
+ candidateBytes = null;
1251
+ }
1252
+ else {
1253
+ record(parameters.candidate, ['kind']);
1254
+ if (candKind !== 'unchanged_baseline')
1255
+ refuse('ARTIFACT_INVALID', '', 'verification');
1256
+ candidateBytes = baselineBytes;
1257
+ }
1258
+ if (pos !== bytes.byteLength)
1259
+ refuse('ARTIFACT_INVALID', '', 'verification');
1260
+ if (isJsonKeys) {
1261
+ const allowedPointers = list(parameters.allowedPointers, '', 128).map(item => text(item, '', 256));
1262
+ if (allowedPointers.length < 1 || allowedPointers.some(ptr => !RFC6901_POINTER_PATTERN.test(ptr))) {
1263
+ refuse('ARTIFACT_INVALID', '', 'verification');
1264
+ }
1265
+ method = 'verify_json_keys_guard';
1266
+ const guardRes = evaluateJsonKeysGuard(path, allowedPointers, baselineBytes, candidateBytes);
1267
+ reason = guardRes.reason;
1268
+ detail = guardRes.detail;
1269
+ findings = guardRes.findings;
1270
+ }
1271
+ else {
1272
+ const startMarker = text(parameters.startMarker, '', 256);
1273
+ const endMarker = text(parameters.endMarker, '', 256);
1274
+ if (startMarker.length < 1 ||
1275
+ endMarker.length < 1 ||
1276
+ startMarker === endMarker ||
1277
+ /[\r\n]/.test(startMarker) ||
1278
+ /[\r\n]/.test(endMarker)) {
1279
+ refuse('ARTIFACT_INVALID', '', 'verification');
1280
+ }
1281
+ method = 'verify_line_section_guard';
1282
+ const guardRes = evaluateLineSectionGuard(path, startMarker, endMarker, baselineBytes, candidateBytes);
1283
+ reason = guardRes.reason;
1284
+ detail = guardRes.detail;
1285
+ findings = guardRes.findings;
1286
+ }
1287
+ }
1288
+ const identified = identifyManifest(candidate, bounds.options);
1289
+ if (!identified.ok || !same(identified.value.digest, header.subject.candidateDigest))
1290
+ refuse('ARTIFACT_INVALID', '', 'verification');
1291
+ if (source.spec.entries.length !== header.source.entryCount)
1292
+ refuse('ARTIFACT_INVALID', '', 'verification');
1293
+ return {
1294
+ version: 1,
1295
+ jobId: header.jobId,
1296
+ handler: header.handler,
1297
+ handlerDigest: header.handlerDigest,
1298
+ checkId: header.checkId,
1299
+ producerNonce: header.producerNonce,
1300
+ operationId: header.operationId,
1301
+ dispatchId: header.dispatchId,
1302
+ generation: header.generation,
1303
+ subject: header.subject,
1304
+ packetDigest: hash(bytes),
1305
+ status: reason === null ? 'passed' : 'failed',
1306
+ reason,
1307
+ method,
1308
+ allocationBytes: quota.used,
1309
+ ...(detail !== undefined ? { detail } : {}),
1310
+ ...(findings !== undefined ? { findings } : {}),
1311
+ };
1312
+ }