@gpustack/loopwright 0.0.0-stage → 0.0.2

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 +2083 -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 +1646 -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 +2605 -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 +7313 -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 +3021 -0
  476. package/package-lock.json +3021 -0
  477. package/package.json +52 -4
@@ -0,0 +1,228 @@
1
+ import { constants } from 'node:fs';
2
+ import { open, link, unlink, lstat } from 'node:fs/promises';
3
+ import { join } from 'node:path';
4
+ import { createHash } from 'node:crypto';
5
+ import { CODES, refuse } from './errors.js';
6
+ import { canonical, freeze, hash, id, integer, record, same, text } from './schema.js';
7
+ import { checkedRef, stateValue } from './storage.js';
8
+ import { readBoundedFile } from './files.js';
9
+ import { parsePrivateJson } from './parser.js';
10
+ /** Append public-safe observations during work. Finalization seals the same inode without copying its body. */
11
+ export class ControllerEvents {
12
+ store;
13
+ artifacts;
14
+ sink;
15
+ stop;
16
+ terminalRecovery;
17
+ #sequence;
18
+ #bytes = 0;
19
+ #queued = 0;
20
+ #queueBytes = 0;
21
+ #failed = false;
22
+ #closed = false;
23
+ #terminal = false;
24
+ #tail = Promise.resolve();
25
+ #heartbeat;
26
+ #hash = createHash('sha256');
27
+ #file = null;
28
+ #initializationFailed = false;
29
+ #release = null;
30
+ #sealing = null;
31
+ #path;
32
+ #ready;
33
+ #delegatedBudget = { modelCalls: 0, formatRepairs: 0, implementationRepairs: 0 };
34
+ constructor(store, artifacts, sink, stop, sequence = 0, terminalRecovery = false) {
35
+ this.store = store;
36
+ this.artifacts = artifacts;
37
+ this.sink = sink;
38
+ this.stop = stop;
39
+ this.terminalRecovery = terminalRecovery;
40
+ this.#sequence = integer(sequence, 0, Number.MAX_SAFE_INTEGER);
41
+ this.#path = join(artifacts.directory, 'controller-events.open');
42
+ this.#ready = this.#initialize(sequence).catch(() => { this.#initializationFailed = true; this.#failed = true; this.stop(); });
43
+ this.#heartbeat = setInterval(() => { void this.push('waiting', null).catch(() => this.stop()); }, 30000);
44
+ this.#heartbeat.unref();
45
+ }
46
+ async #initialize(sequence) {
47
+ await this.artifacts.owner.assertCurrent();
48
+ this.#release = await this.artifacts.owner.holdLocalActivity();
49
+ try {
50
+ let file;
51
+ try {
52
+ if (sequence > 0) {
53
+ try {
54
+ await lstat(this.#path);
55
+ }
56
+ catch {
57
+ refuse('RECOVERY_REQUIRED', '', 'recovery');
58
+ }
59
+ }
60
+ file = await open(this.#path, constants.O_CREAT | constants.O_EXCL | constants.O_WRONLY | constants.O_APPEND | constants.O_NOFOLLOW, 0o600);
61
+ }
62
+ catch (error) {
63
+ if (error.code !== 'EEXIST')
64
+ throw error;
65
+ const before = await lstat(this.#path), bytes = await readBoundedFile(this.#path, 4194304, true), view = stateValue(this.store.inspect());
66
+ this.artifacts.vault.assertClean(bytes);
67
+ if (bytes.length && bytes.at(-1) !== 10)
68
+ refuse('RECOVERY_REQUIRED', '', 'recovery');
69
+ let count = 0;
70
+ for (const line of bytes.length ? bytes.subarray(0, -1).toString().split('\n') : []) {
71
+ const row0 = parsePrivateJson(Buffer.from(line), 4096), hasGate = Object.hasOwn(row0, 'gate'), row = record(row0, ['version', 'sequence', 'runId', 'lockHash', 'nodeId', 'attemptId', 'stage', 'code', 'budget', 'deadlineMonotonicMs', 'references', ...(hasGate ? ['gate'] : [])]);
72
+ if (Buffer.byteLength(line) + 1 > 4096 || canonical(row) !== line || row.version !== 1 || row.sequence !== ++count || row.runId !== view.runId || !same(row.lockHash, view.lockHash)
73
+ || row.deadlineMonotonicMs !== view.clock.basis.taskDeadlineMonotonicMs || !['admission', 'waiting', 'role', 'verification', 'repair', 'drain', 'terminal', 'gate_waiting', 'publication'].includes(text(row.stage)) || this.#terminal || row.stage === 'terminal' && !this.terminalRecovery
74
+ || row.code !== null && !CODES.includes(row.code))
75
+ refuse('RECOVERY_REQUIRED', '', 'recovery');
76
+ if (row.nodeId !== null)
77
+ id(row.nodeId);
78
+ if (row.attemptId !== null)
79
+ id(row.attemptId);
80
+ if (row.stage === 'terminal')
81
+ this.#terminal = true;
82
+ if (row.gate !== null && row.gate !== undefined) {
83
+ const detail = record(row.gate, ['operationId', 'gateId', 'elapsedMs', 'nextPollMs', 'deadlineMs']);
84
+ id(detail.operationId);
85
+ text(detail.gateId, '', 128);
86
+ integer(detail.elapsedMs, 0, Number.MAX_SAFE_INTEGER);
87
+ integer(detail.nextPollMs, 0, 600000);
88
+ integer(detail.deadlineMs, 0, Number.MAX_SAFE_INTEGER);
89
+ }
90
+ const budget = record(row.budget, ['admittedCalls', 'formatRepairs', 'implementationRepairs', 'transportRetries', 'chargedTokens', 'remainingTokens']);
91
+ for (const key of ['admittedCalls', 'formatRepairs', 'implementationRepairs', 'transportRetries'])
92
+ integer(budget[key], 0, 1024);
93
+ for (const key of ['chargedTokens', 'remainingTokens'])
94
+ if (!/^(?:0|[1-9][0-9]{0,39})$/.test(text(budget[key])))
95
+ refuse('RECOVERY_REQUIRED', '', 'recovery');
96
+ if (!Array.isArray(row.references) || row.references.length > 16)
97
+ refuse('RECOVERY_REQUIRED', '', 'recovery');
98
+ row.references.forEach(checkedRef);
99
+ }
100
+ if (count < sequence || bytes.length > 4190208)
101
+ refuse('RECOVERY_REQUIRED', '', 'recovery');
102
+ this.#sequence = count;
103
+ this.#bytes = bytes.length;
104
+ this.#hash.update(bytes);
105
+ file = await open(this.#path, constants.O_WRONLY | constants.O_APPEND | constants.O_NOFOLLOW);
106
+ const current = await file.stat();
107
+ if (current.dev !== before.dev || current.ino !== before.ino || current.size !== bytes.length || current.nlink !== 1 || current.mode & 0o077) {
108
+ await file.close();
109
+ refuse('RECOVERY_REQUIRED', '', 'recovery');
110
+ }
111
+ }
112
+ this.#file = file;
113
+ const parent = await open(this.artifacts.directory, constants.O_RDONLY | constants.O_NOFOLLOW);
114
+ try {
115
+ await parent.sync();
116
+ }
117
+ finally {
118
+ await parent.close();
119
+ }
120
+ }
121
+ catch (error) {
122
+ const release = this.#release;
123
+ this.#release = null;
124
+ release?.();
125
+ throw error;
126
+ }
127
+ }
128
+ async ready() { await this.#ready; if (this.#initializationFailed)
129
+ refuse('RECOVERY_REQUIRED', '', 'recovery'); }
130
+ get hasTerminal() { return this.#terminal; }
131
+ get sequence() { return this.#sequence; }
132
+ setDelegatedBudget(counts) {
133
+ this.#delegatedBudget = { modelCalls: counts.modelCalls, formatRepairs: counts.formatRepairs, implementationRepairs: counts.implementationRepairs };
134
+ }
135
+ async push(stage, code, nodeId = null, attemptId = null, refs = [], gate = null) {
136
+ await this.#ready;
137
+ if (this.#initializationFailed || this.#closed || this.#failed && stage !== 'terminal' || stage === 'terminal' && this.#terminal)
138
+ refuse('OUTPUT_LIMIT', '', 'execution');
139
+ const view = stateValue(this.store.inspect()), ledger = view.ledger;
140
+ const event = freeze({ version: 1, sequence: this.#sequence + 1, runId: id(view.runId), lockHash: view.lockHash, nodeId: nodeId === null ? null : id(nodeId), attemptId: attemptId === null ? null : id(attemptId), stage, code,
141
+ budget: { admittedCalls: ledger.admittedCalls + this.#delegatedBudget.modelCalls, formatRepairs: ledger.formatRepairs + this.#delegatedBudget.formatRepairs, implementationRepairs: ledger.implementationRepairs + this.#delegatedBudget.implementationRepairs, transportRetries: ledger.transportRetries, chargedTokens: ledger.chargedTokens.decimal, remainingTokens: ledger.remainingTokens.decimal },
142
+ deadlineMonotonicMs: view.clock.basis.taskDeadlineMonotonicMs, references: refs.map(checkedRef), gate });
143
+ const bytes = Buffer.from(canonical(event) + '\n');
144
+ this.artifacts.vault.assertClean(bytes);
145
+ const terminal = stage === 'terminal', fail = () => { this.#failed = true; this.stop(); refuse('OUTPUT_LIMIT', '', 'execution'); };
146
+ if (bytes.length > 4096 || refs.length > 16 || this.#queued >= (terminal ? 128 : 127) || this.#queueBytes + bytes.length > (terminal ? 524288 : 520192) || this.#bytes + bytes.length > (terminal ? 4194304 : 4190208))
147
+ return fail();
148
+ this.#sequence++;
149
+ this.#terminal ||= terminal;
150
+ this.#bytes += bytes.length;
151
+ this.#queued++;
152
+ this.#queueBytes += bytes.length;
153
+ const work = this.#tail.then(async () => {
154
+ await this.artifacts.owner.assertCurrent();
155
+ const held = await this.#file.stat(), path = await lstat(this.#path);
156
+ if (held.dev !== path.dev || held.ino !== path.ino || held.nlink !== 1 || path.mode & 0o077)
157
+ refuse('ARTIFACT_INVALID', '', 'execution');
158
+ await this.#file.writeFile(bytes);
159
+ await this.#file.sync();
160
+ this.#hash.update(bytes);
161
+ if (!this.sink || this.#failed)
162
+ return;
163
+ let timer;
164
+ try {
165
+ await Promise.race([this.sink(event), new Promise((_, reject) => { timer = setTimeout(() => reject(new Error('backpressure')), 1000); })]);
166
+ }
167
+ catch {
168
+ this.#failed = true;
169
+ this.stop();
170
+ refuse('OUTPUT_LIMIT', '', 'execution');
171
+ }
172
+ finally {
173
+ clearTimeout(timer);
174
+ }
175
+ }).catch(error => { this.#failed = true; this.stop(); throw error; }).finally(() => { this.#queued--; this.#queueBytes -= bytes.length; });
176
+ this.#tail = work.catch(() => { });
177
+ return work;
178
+ }
179
+ close() { return this.#sealing ??= this.#seal(); }
180
+ async suspend() {
181
+ clearInterval(this.#heartbeat);
182
+ this.#closed = true;
183
+ await this.#ready;
184
+ await this.#tail;
185
+ if (this.#initializationFailed || !this.#file)
186
+ refuse('RECOVERY_REQUIRED', '', 'execution');
187
+ await this.#file.sync();
188
+ await this.#file.close();
189
+ this.#file = null;
190
+ const release = this.#release;
191
+ this.#release = null;
192
+ release?.();
193
+ }
194
+ async #seal() {
195
+ clearInterval(this.#heartbeat);
196
+ this.#closed = true;
197
+ await this.#ready;
198
+ await this.#tail;
199
+ if (this.#initializationFailed || !this.#file)
200
+ refuse('RECOVERY_REQUIRED', '', 'finalization');
201
+ await this.#file.sync();
202
+ const info = await this.#file.stat();
203
+ await this.#file.close();
204
+ this.#file = null;
205
+ if (info.size !== this.#bytes || info.nlink !== 1)
206
+ refuse('RECOVERY_REQUIRED', '', 'finalization');
207
+ const digest = { algorithm: 'sha256', hex: this.#hash.digest('hex') }, name = 'events-' + hash('loopwright.dev/controller/artifact/events/v1\0' + digest.hex).hex + '.bin';
208
+ const ref = { name, digest, byteLength: this.#bytes }, target = join(this.artifacts.directory, name);
209
+ // link is no-overwrite; the original is removed only after the new exact inode is proven.
210
+ await this.artifacts.owner.assertCurrent();
211
+ await link(this.#path, target);
212
+ const sealed = await lstat(target);
213
+ if (sealed.ino !== info.ino || sealed.dev !== info.dev || sealed.nlink !== 2)
214
+ refuse('RECOVERY_REQUIRED', '', 'finalization');
215
+ await unlink(this.#path);
216
+ const parent = await open(this.artifacts.directory, constants.O_RDONLY | constants.O_NOFOLLOW);
217
+ try {
218
+ await parent.sync();
219
+ }
220
+ finally {
221
+ await parent.close();
222
+ }
223
+ await this.artifacts.read(ref, 4194304);
224
+ this.#release?.();
225
+ this.#release = null;
226
+ return ref;
227
+ }
228
+ }
@@ -0,0 +1,51 @@
1
+ import { open } from 'node:fs/promises';
2
+ import { type ControllerDiagnostic } from './errors.js';
3
+ export declare const STREAM_CHUNK_BYTES = 1048576;
4
+ export declare function inside(path: string, root: string): boolean;
5
+ export declare function canonicalComponents(path: string, owned?: boolean): Promise<void>;
6
+ export declare function readBoundedFile(path: string, maximum: number, owned: boolean, exactMode?: number): Promise<Buffer>;
7
+ export declare function writeAllToHandle(handle: Awaited<ReturnType<typeof open>>, chunk: Uint8Array): Promise<void>;
8
+ export interface StreamRegularFileOptions {
9
+ readonly maxBytes?: number | undefined;
10
+ readonly expectedBytes?: number | undefined;
11
+ readonly owned?: boolean | undefined;
12
+ readonly requireReadOnly?: boolean | undefined;
13
+ readonly verifyCanonicalPath?: boolean | undefined;
14
+ readonly code?: ControllerDiagnostic['code'] | undefined;
15
+ readonly limitCode?: ControllerDiagnostic['code'] | undefined;
16
+ readonly path?: string | undefined;
17
+ readonly phase?: ControllerDiagnostic['phase'] | undefined;
18
+ readonly onOpen?: ((info: {
19
+ readonly byteLength: number;
20
+ }) => void) | undefined;
21
+ }
22
+ export interface StreamedFileSummary {
23
+ readonly byteLength: number;
24
+ readonly mode: '100644' | '100755';
25
+ readonly rawMode: number;
26
+ readonly dev: number;
27
+ readonly ino: number;
28
+ readonly mtimeMs: number;
29
+ readonly ctimeMs: number;
30
+ }
31
+ export declare function streamRegularFile(path: string, options?: StreamRegularFileOptions, onChunk?: (chunk: Uint8Array) => Promise<void> | void): Promise<StreamedFileSummary>;
32
+ export interface CopyVerifiedFileOptions {
33
+ readonly maxBytes?: number | undefined;
34
+ readonly expectedBytes?: number | undefined;
35
+ readonly expectedSha256?: string | undefined;
36
+ readonly mode?: number | undefined;
37
+ readonly ownedSource?: boolean | undefined;
38
+ readonly requireReadOnlySource?: boolean | undefined;
39
+ readonly verifyCanonicalSource?: boolean | undefined;
40
+ readonly disableReflink?: boolean | undefined;
41
+ readonly code?: ControllerDiagnostic['code'] | undefined;
42
+ readonly limitCode?: ControllerDiagnostic['code'] | undefined;
43
+ readonly path?: string | undefined;
44
+ readonly phase?: ControllerDiagnostic['phase'] | undefined;
45
+ }
46
+ export interface CopiedVerifiedFile {
47
+ readonly byteLength: number;
48
+ readonly sha256: string;
49
+ readonly sourceMode: '100644' | '100755';
50
+ }
51
+ export declare function copyVerifiedFileReadOnly(srcPath: string, destPath: string, options?: CopyVerifiedFileOptions): Promise<CopiedVerifiedFile>;
@@ -0,0 +1,386 @@
1
+ import { createHash, randomBytes } from 'node:crypto';
2
+ import { constants } from 'node:fs';
3
+ import { link, lstat, open, realpath, unlink } from 'node:fs/promises';
4
+ import { dirname, isAbsolute, join, resolve, sep } from 'node:path';
5
+ import { ControllerFailure, refuse } from './errors.js';
6
+ export const STREAM_CHUNK_BYTES = 1_048_576;
7
+ export function inside(path, root) {
8
+ return path === root || path.startsWith(root.endsWith(sep) ? root : root + sep);
9
+ }
10
+ export async function canonicalComponents(path, owned = true) {
11
+ const code = owned ? 'REGISTRY_UNTRUSTED' : 'CONFIG_SYNTAX';
12
+ const path_ = owned ? '/registry' : '/config';
13
+ if (!isAbsolute(path) || resolve(path) !== path || path.length > 4096 || /[\0\r\n]/.test(path))
14
+ refuse(code, path_);
15
+ let current = path, count = 0;
16
+ while (true) {
17
+ if (++count > 128 || (await lstat(current)).isSymbolicLink())
18
+ refuse(code, path_);
19
+ const parent = dirname(current);
20
+ if (parent === current)
21
+ break;
22
+ current = parent;
23
+ }
24
+ if (await realpath(path) !== path)
25
+ refuse(code, path_);
26
+ }
27
+ export async function readBoundedFile(path, maximum, owned, exactMode) {
28
+ try {
29
+ await canonicalComponents(path, owned);
30
+ const before = await lstat(path);
31
+ if (!before.isFile() || before.nlink !== 1 || before.size > maximum)
32
+ refuse(before.size > maximum ? 'CONFIG_LIMIT' : owned ? 'REGISTRY_UNTRUSTED' : 'CONFIG_SYNTAX', owned ? '/registry' : '/config');
33
+ if (owned) {
34
+ const parent = await lstat(dirname(path));
35
+ if (before.uid !== process.getuid?.() || before.mode & 0o077 || parent.uid !== process.getuid?.() || parent.mode & 0o077)
36
+ refuse('REGISTRY_UNTRUSTED', '/registry');
37
+ }
38
+ if (exactMode !== undefined && (before.mode & 0o7777) !== exactMode) {
39
+ refuse(owned ? 'REGISTRY_UNTRUSTED' : 'CONFIG_SYNTAX', owned ? '/registry' : '/config');
40
+ }
41
+ const file = await open(path, constants.O_RDONLY | constants.O_NOFOLLOW);
42
+ try {
43
+ const info = await file.stat();
44
+ if (info.dev !== before.dev
45
+ || info.ino !== before.ino
46
+ || info.size !== before.size
47
+ || info.nlink !== 1
48
+ || !info.isFile()
49
+ || (exactMode !== undefined && (info.mode & 0o7777) !== exactMode))
50
+ refuse(owned ? 'REGISTRY_UNTRUSTED' : 'CONFIG_SYNTAX', owned ? '/registry' : '/config');
51
+ const bytes = Buffer.alloc(info.size + 1);
52
+ let size = 0;
53
+ while (size < bytes.length) {
54
+ const next = await file.read(bytes, size, bytes.length - size, size);
55
+ if (!next.bytesRead)
56
+ break;
57
+ size += next.bytesRead;
58
+ }
59
+ const after = await file.stat(), current = await lstat(path);
60
+ if (size !== info.size
61
+ || info.mtimeMs !== after.mtimeMs
62
+ || info.ctimeMs !== after.ctimeMs
63
+ || current.dev !== info.dev
64
+ || current.ino !== info.ino
65
+ || after.size !== info.size
66
+ || (exactMode !== undefined && (after.mode & 0o7777) !== exactMode))
67
+ refuse(owned ? 'REGISTRY_UNTRUSTED' : 'CONFIG_SYNTAX', owned ? '/registry' : '/config');
68
+ return bytes.subarray(0, size);
69
+ }
70
+ finally {
71
+ await file.close();
72
+ }
73
+ }
74
+ catch (error) {
75
+ if (error instanceof ControllerFailure)
76
+ throw error;
77
+ refuse(owned ? 'REGISTRY_UNTRUSTED' : 'CONFIG_SYNTAX', owned ? '/registry' : '/config');
78
+ }
79
+ }
80
+ export async function writeAllToHandle(handle, chunk) {
81
+ let written = 0;
82
+ while (written < chunk.byteLength) {
83
+ const { bytesWritten } = await handle.write(chunk, written, chunk.byteLength - written);
84
+ if (bytesWritten <= 0)
85
+ throw new Error('Short write returned zero bytesWritten');
86
+ written += bytesWritten;
87
+ }
88
+ }
89
+ export async function streamRegularFile(path, options = {}, onChunk) {
90
+ const phase = options.phase ?? 'execution';
91
+ const diagPath = options.path ?? '';
92
+ const code = options.code ?? 'ARTIFACT_INVALID';
93
+ const limitCode = options.limitCode ?? 'OUTPUT_LIMIT';
94
+ const fail = (overrideCode = code) => refuse(overrideCode, diagPath, phase);
95
+ if (typeof path !== 'string' || !isAbsolute(path) || path.length > 4096 || /[\0\r\n]/.test(path)) {
96
+ return fail();
97
+ }
98
+ let before;
99
+ try {
100
+ if (options.verifyCanonicalPath) {
101
+ await canonicalComponents(path, options.owned ?? true);
102
+ }
103
+ before = await lstat(path);
104
+ }
105
+ catch (error) {
106
+ if (error instanceof ControllerFailure && error.diagnostic.code === code && error.diagnostic.phase === phase) {
107
+ throw error;
108
+ }
109
+ return fail();
110
+ }
111
+ if (before.isSymbolicLink() || !before.isFile() || before.nlink !== 1)
112
+ return fail();
113
+ if (options.owned && before.uid !== process.getuid?.())
114
+ return fail();
115
+ if (options.requireReadOnly && (before.mode & 0o222) !== 0)
116
+ return fail();
117
+ if (options.maxBytes !== undefined && before.size > options.maxBytes)
118
+ return fail(limitCode);
119
+ if (options.expectedBytes !== undefined && before.size !== options.expectedBytes)
120
+ return fail();
121
+ let handle;
122
+ try {
123
+ handle = await open(path, constants.O_RDONLY | constants.O_NOFOLLOW);
124
+ }
125
+ catch {
126
+ return fail();
127
+ }
128
+ try {
129
+ let info;
130
+ try {
131
+ info = await handle.stat();
132
+ }
133
+ catch {
134
+ return fail();
135
+ }
136
+ if (!info.isFile()
137
+ || info.nlink !== 1
138
+ || info.dev !== before.dev
139
+ || info.ino !== before.ino
140
+ || info.size !== before.size) {
141
+ return fail();
142
+ }
143
+ if (options.owned && info.uid !== process.getuid?.())
144
+ return fail();
145
+ if (options.requireReadOnly && (info.mode & 0o222) !== 0)
146
+ return fail();
147
+ if (options.maxBytes !== undefined && info.size > options.maxBytes)
148
+ return fail(limitCode);
149
+ if (options.expectedBytes !== undefined && info.size !== options.expectedBytes)
150
+ return fail();
151
+ options.onOpen?.({ byteLength: info.size });
152
+ const buffer = Buffer.allocUnsafe(Math.min(STREAM_CHUNK_BYTES, Math.max(1, info.size)));
153
+ let offset = 0;
154
+ while (offset < info.size) {
155
+ let bytesRead = 0;
156
+ try {
157
+ const res = await handle.read(buffer, 0, Math.min(buffer.byteLength, info.size - offset), offset);
158
+ bytesRead = res.bytesRead;
159
+ }
160
+ catch {
161
+ return fail();
162
+ }
163
+ if (bytesRead <= 0)
164
+ break;
165
+ offset += bytesRead;
166
+ if (onChunk !== undefined) {
167
+ await onChunk(buffer.subarray(0, bytesRead));
168
+ }
169
+ }
170
+ let extraBytesRead = 0;
171
+ let after;
172
+ try {
173
+ const probe = Buffer.allocUnsafe(1);
174
+ extraBytesRead = (await handle.read(probe, 0, 1, offset)).bytesRead;
175
+ after = await handle.stat();
176
+ }
177
+ catch {
178
+ return fail();
179
+ }
180
+ if (extraBytesRead !== 0
181
+ || offset !== info.size
182
+ || !after.isFile()
183
+ || after.nlink !== 1
184
+ || after.dev !== info.dev
185
+ || after.ino !== info.ino
186
+ || after.size !== info.size
187
+ || after.mtimeMs !== info.mtimeMs
188
+ || after.ctimeMs !== info.ctimeMs
189
+ || (options.requireReadOnly && (after.mode & 0o222) !== 0)) {
190
+ return fail();
191
+ }
192
+ return {
193
+ byteLength: after.size,
194
+ mode: (after.mode & 0o111) !== 0 ? '100755' : '100644',
195
+ rawMode: after.mode,
196
+ dev: after.dev,
197
+ ino: after.ino,
198
+ mtimeMs: after.mtimeMs,
199
+ ctimeMs: after.ctimeMs,
200
+ };
201
+ }
202
+ finally {
203
+ await handle.close();
204
+ }
205
+ }
206
+ export async function copyVerifiedFileReadOnly(srcPath, destPath, options = {}) {
207
+ const phase = options.phase ?? 'execution';
208
+ const diagPath = options.path ?? '';
209
+ const code = options.code ?? 'ARTIFACT_INVALID';
210
+ const limitCode = options.limitCode ?? 'OUTPUT_LIMIT';
211
+ const targetMode = options.mode ?? 0o400;
212
+ const fail = (overrideCode = code) => refuse(overrideCode, diagPath, phase);
213
+ if (typeof srcPath !== 'string'
214
+ || !isAbsolute(srcPath)
215
+ || srcPath.length > 4096
216
+ || /[\0\r\n]/.test(srcPath)
217
+ || typeof destPath !== 'string'
218
+ || !isAbsolute(destPath)
219
+ || destPath.length > 4096
220
+ || /[\0\r\n]/.test(destPath)) {
221
+ return fail();
222
+ }
223
+ let destExists = false;
224
+ try {
225
+ await lstat(destPath);
226
+ destExists = true;
227
+ }
228
+ catch (error) {
229
+ if (error?.code !== 'ENOENT')
230
+ return fail();
231
+ }
232
+ if (destExists)
233
+ return fail();
234
+ const tmpPath = join(dirname(destPath), `.lw-stage-${randomBytes(12).toString('hex')}`);
235
+ let srcHandle = null;
236
+ let tmpHandle = null;
237
+ let destVerify = null;
238
+ let tmpCreated = false;
239
+ let tmpUnlinked = false;
240
+ try {
241
+ if (options.verifyCanonicalSource) {
242
+ await canonicalComponents(srcPath, options.ownedSource ?? true);
243
+ }
244
+ srcHandle = await open(srcPath, constants.O_RDONLY | constants.O_NOFOLLOW);
245
+ const srcBefore = await srcHandle.stat();
246
+ if (srcBefore.isSymbolicLink() || !srcBefore.isFile() || srcBefore.nlink !== 1)
247
+ return fail();
248
+ if (options.ownedSource && srcBefore.uid !== process.getuid?.())
249
+ return fail();
250
+ if (options.requireReadOnlySource && (srcBefore.mode & 0o222) !== 0)
251
+ return fail();
252
+ if (options.maxBytes !== undefined && srcBefore.size > options.maxBytes)
253
+ return fail(limitCode);
254
+ if (options.expectedBytes !== undefined && srcBefore.size !== options.expectedBytes)
255
+ return fail();
256
+ const sourceMode = (srcBefore.mode & 0o111) !== 0 ? '100755' : '100644';
257
+ tmpHandle = await open(tmpPath, constants.O_CREAT | constants.O_EXCL | constants.O_RDWR | constants.O_NOFOLLOW, 0o600);
258
+ tmpCreated = true;
259
+ const createdStat = await tmpHandle.stat();
260
+ if (!createdStat.isFile()
261
+ || createdStat.isSymbolicLink()
262
+ || createdStat.nlink !== 1
263
+ || (createdStat.dev === srcBefore.dev && createdStat.ino === srcBefore.ino)) {
264
+ return fail();
265
+ }
266
+ const buf = Buffer.allocUnsafe(Math.min(STREAM_CHUNK_BYTES, Math.max(1, srcBefore.size)));
267
+ const writeSha = createHash('sha256');
268
+ let writtenBytes = 0;
269
+ while (writtenBytes < srcBefore.size) {
270
+ const toRead = Math.min(buf.byteLength, srcBefore.size - writtenBytes);
271
+ const { bytesRead } = await srcHandle.read(buf, 0, toRead, writtenBytes);
272
+ if (bytesRead <= 0)
273
+ break;
274
+ const slice = buf.subarray(0, bytesRead);
275
+ writtenBytes += bytesRead;
276
+ if (options.maxBytes !== undefined && writtenBytes > options.maxBytes) {
277
+ return fail(limitCode);
278
+ }
279
+ writeSha.update(slice);
280
+ await writeAllToHandle(tmpHandle, slice);
281
+ }
282
+ const probe = Buffer.allocUnsafe(1);
283
+ const extraSrcRead = (await srcHandle.read(probe, 0, 1, writtenBytes)).bytesRead;
284
+ const srcAfter = await srcHandle.stat();
285
+ const writeShaHex = writeSha.digest('hex');
286
+ if (extraSrcRead !== 0
287
+ || !srcAfter.isFile()
288
+ || srcAfter.isSymbolicLink()
289
+ || srcAfter.nlink !== 1
290
+ || srcAfter.dev !== srcBefore.dev
291
+ || srcAfter.ino !== srcBefore.ino
292
+ || srcAfter.size !== srcBefore.size
293
+ || srcAfter.mtimeMs !== srcBefore.mtimeMs
294
+ || srcAfter.ctimeMs !== srcBefore.ctimeMs
295
+ || (options.requireReadOnlySource && (srcAfter.mode & 0o222) !== 0)
296
+ || writtenBytes !== srcBefore.size) {
297
+ return fail();
298
+ }
299
+ if (options.expectedSha256 !== undefined && writeShaHex !== options.expectedSha256) {
300
+ return fail();
301
+ }
302
+ const storedSha = createHash('sha256');
303
+ let readOffset = 0;
304
+ while (readOffset < writtenBytes) {
305
+ const toRead = Math.min(buf.byteLength, writtenBytes - readOffset);
306
+ const { bytesRead } = await tmpHandle.read(buf, 0, toRead, readOffset);
307
+ if (bytesRead <= 0)
308
+ break;
309
+ storedSha.update(buf.subarray(0, bytesRead));
310
+ readOffset += bytesRead;
311
+ }
312
+ const extraTmpRead = (await tmpHandle.read(probe, 0, 1, readOffset)).bytesRead;
313
+ const tmpAfterRead = await tmpHandle.stat();
314
+ if (extraTmpRead !== 0
315
+ || readOffset !== writtenBytes
316
+ || storedSha.digest('hex') !== writeShaHex
317
+ || !tmpAfterRead.isFile()
318
+ || tmpAfterRead.isSymbolicLink()
319
+ || tmpAfterRead.dev !== createdStat.dev
320
+ || tmpAfterRead.ino !== createdStat.ino
321
+ || tmpAfterRead.nlink !== 1
322
+ || tmpAfterRead.size !== writtenBytes) {
323
+ return fail();
324
+ }
325
+ await tmpHandle.chmod(targetMode);
326
+ await tmpHandle.sync();
327
+ const sealedStat = await tmpHandle.stat();
328
+ if (!sealedStat.isFile()
329
+ || sealedStat.isSymbolicLink()
330
+ || sealedStat.dev !== createdStat.dev
331
+ || sealedStat.ino !== createdStat.ino
332
+ || sealedStat.nlink !== 1
333
+ || sealedStat.size !== writtenBytes
334
+ || (sealedStat.mode & 0o777) !== (targetMode & 0o777)) {
335
+ return fail();
336
+ }
337
+ await link(tmpPath, destPath);
338
+ await unlink(tmpPath);
339
+ tmpUnlinked = true;
340
+ destVerify = await open(destPath, constants.O_RDONLY | constants.O_NOFOLLOW);
341
+ const destStat = await destVerify.stat();
342
+ const pinnedStat = await tmpHandle.stat();
343
+ if (!destStat.isFile()
344
+ || destStat.isSymbolicLink()
345
+ || destStat.nlink !== 1
346
+ || destStat.dev !== createdStat.dev
347
+ || destStat.ino !== createdStat.ino
348
+ || destStat.size !== writtenBytes
349
+ || (destStat.mode & 0o777) !== (targetMode & 0o777)
350
+ || pinnedStat.nlink !== 1) {
351
+ return fail();
352
+ }
353
+ await destVerify.close();
354
+ destVerify = null;
355
+ await tmpHandle.close();
356
+ tmpHandle = null;
357
+ return {
358
+ byteLength: writtenBytes,
359
+ sha256: writeShaHex,
360
+ sourceMode,
361
+ };
362
+ }
363
+ catch (error) {
364
+ if (error instanceof ControllerFailure && error.diagnostic.code === code && error.diagnostic.phase === phase) {
365
+ throw error;
366
+ }
367
+ if (error instanceof ControllerFailure && error.diagnostic.code === limitCode && error.diagnostic.phase === phase) {
368
+ throw error;
369
+ }
370
+ return fail();
371
+ }
372
+ finally {
373
+ if (destVerify) {
374
+ await destVerify.close().catch(() => { });
375
+ }
376
+ if (tmpHandle) {
377
+ await tmpHandle.close().catch(() => { });
378
+ }
379
+ if (srcHandle) {
380
+ await srcHandle.close().catch(() => { });
381
+ }
382
+ if (tmpCreated && !tmpUnlinked) {
383
+ await unlink(tmpPath).catch(() => { });
384
+ }
385
+ }
386
+ }