reeval 0.23.0 → 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (574) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/README.md +17 -17
  3. package/THIRD_PARTY_NOTICES.md +0 -2068
  4. package/assets/package.json +1 -1
  5. package/assets/pnpm-lock.yaml +65 -50
  6. package/dist/{adapter-Dlq3-4OS.js → adapter-vLxVtLdk.js} +6 -6
  7. package/dist/{adapter-Dlq3-4OS.js.map → adapter-vLxVtLdk.js.map} +1 -1
  8. package/dist/{agent-OsAfayRf.js → agent-DN36i629.js} +9 -9
  9. package/dist/{agent-OsAfayRf.js.map → agent-DN36i629.js.map} +1 -1
  10. package/dist/{agents-BztvTkfM.js → agents-Bp40Y7Lk.js} +47 -59
  11. package/dist/agents-Bp40Y7Lk.js.map +1 -0
  12. package/dist/{analysis-BnG_1x_O.js → analysis-8vvMnUJB.js} +4 -5
  13. package/dist/analysis-8vvMnUJB.js.map +1 -0
  14. package/dist/api-ZeGnedB3.js +141 -0
  15. package/dist/api-ZeGnedB3.js.map +1 -0
  16. package/dist/assemble-ChNVeWNr.js +1 -0
  17. package/dist/{assemble-Doa1m-HW.js → assemble-DsllweEG.js} +132 -68
  18. package/dist/assemble-DsllweEG.js.map +1 -0
  19. package/dist/{attach-BH2HdwH_.js → attach-DFf2hFl7.js} +18 -10
  20. package/dist/attach-DFf2hFl7.js.map +1 -0
  21. package/dist/{attempt-_dUsblVx.js → attempt-CfwXgF2q.js} +3 -3
  22. package/dist/{attempt-_dUsblVx.js.map → attempt-CfwXgF2q.js.map} +1 -1
  23. package/dist/{attempt-host-8mQV8Uee.js → attempt-host-XyyFR6jc.js} +37 -14
  24. package/dist/attempt-host-XyyFR6jc.js.map +1 -0
  25. package/dist/boat-BCNNEJni.js +298 -0
  26. package/dist/boat-BCNNEJni.js.map +1 -0
  27. package/dist/{boat-DKjqo_ie.js → boat-CNUnhvWH.js} +117 -197
  28. package/dist/boat-CNUnhvWH.js.map +1 -0
  29. package/dist/boat-DRTQHXlj.js +1 -0
  30. package/dist/{boat-images-CRN_U_eG.js → boat-images-B0MsRBFx.js} +18 -22
  31. package/dist/boat-images-B0MsRBFx.js.map +1 -0
  32. package/dist/{bundle-DU2aQVeq.js → bundle-B1v8DEEX.js} +26 -15
  33. package/dist/bundle-B1v8DEEX.js.map +1 -0
  34. package/dist/{capture-By1byHaX.js → capture-BAtaw-L-.js} +20 -19
  35. package/dist/{capture-By1byHaX.js.map → capture-BAtaw-L-.js.map} +1 -1
  36. package/dist/capture-DOHR_KXl.js +1 -0
  37. package/dist/cases-Bsp-G-ZL.js +1 -0
  38. package/dist/{cases-CM-MQRQp.js → cases-C6vnV-gn.js} +61 -43
  39. package/dist/cases-C6vnV-gn.js.map +1 -0
  40. package/dist/classify-BIJQ2Xqo.js +163 -0
  41. package/dist/classify-BIJQ2Xqo.js.map +1 -0
  42. package/dist/{cli-DMHOwdVr.js → cli-BFfZy9Ax.js} +385 -178
  43. package/dist/cli-BFfZy9Ax.js.map +1 -0
  44. package/dist/{cli-spec-D0wuUaj9.js → cli-spec-Bj2z-4Pa.js} +242 -39
  45. package/dist/cli-spec-Bj2z-4Pa.js.map +1 -0
  46. package/dist/cli.js +6 -2
  47. package/dist/cli.js.map +1 -1
  48. package/dist/client-Dj65gXG3.js +105 -0
  49. package/dist/client-Dj65gXG3.js.map +1 -0
  50. package/dist/cloud-DgMSxpCk.js +154 -0
  51. package/dist/cloud-DgMSxpCk.js.map +1 -0
  52. package/dist/{hosted-5Zz2peTR.js → cloud-TuNUlZ0L.js} +31 -31
  53. package/dist/cloud-TuNUlZ0L.js.map +1 -0
  54. package/dist/cloud-files-BjoNhDJs.js +301 -0
  55. package/dist/cloud-files-BjoNhDJs.js.map +1 -0
  56. package/dist/cloud-project-B1lN8D9m.js +1 -0
  57. package/dist/cloud-project-Dh17iadw.js +110 -0
  58. package/dist/cloud-project-Dh17iadw.js.map +1 -0
  59. package/dist/cloud-push-CdYqsM34.js +817 -0
  60. package/dist/cloud-push-CdYqsM34.js.map +1 -0
  61. package/dist/cloud-push-GXvEYHoa.js +1 -0
  62. package/dist/cloud-run-BfFCs6Fm.js +1 -0
  63. package/dist/cloud-run-CZOpabN1.js +517 -0
  64. package/dist/cloud-run-CZOpabN1.js.map +1 -0
  65. package/dist/cloud-secrets-BskXM_2n.js +1 -0
  66. package/dist/cloud-secrets-DrrgGOF_.js +345 -0
  67. package/dist/cloud-secrets-DrrgGOF_.js.map +1 -0
  68. package/dist/{command-CXxckfsq.js → command-Bic6f84Y.js} +28 -130
  69. package/dist/command-Bic6f84Y.js.map +1 -0
  70. package/dist/{command-CAmnWLFL.js → command-C7m3ZoXS.js} +93 -27
  71. package/dist/command-C7m3ZoXS.js.map +1 -0
  72. package/dist/command-DHrT6YVl.js +183 -0
  73. package/dist/command-DHrT6YVl.js.map +1 -0
  74. package/dist/command-DMwSLfJT.js +141 -0
  75. package/dist/command-DMwSLfJT.js.map +1 -0
  76. package/dist/{command-ao0NZ8h0.js → command-DP8sQ-dk.js} +29 -23
  77. package/dist/command-DP8sQ-dk.js.map +1 -0
  78. package/dist/{commands-ttChCsAy.js → commands-BPLexk6R.js} +62 -41
  79. package/dist/commands-BPLexk6R.js.map +1 -0
  80. package/dist/commands-D8D7ZJ0I.js +1 -0
  81. package/dist/{config-myJT1Qjc.js → config-DQqcGmz7.js} +67 -47
  82. package/dist/config-DQqcGmz7.js.map +1 -0
  83. package/dist/core-BXYzOEyQ.js +2058 -0
  84. package/dist/core-BXYzOEyQ.js.map +1 -0
  85. package/dist/{slug-IHh3f770.js → cost-DQ0ayy6h.js} +37 -2
  86. package/dist/cost-DQ0ayy6h.js.map +1 -0
  87. package/dist/{cost-C21gGrju.js → cost-Dp-xFGJ1.js} +2 -2
  88. package/dist/{cost-C21gGrju.js.map → cost-Dp-xFGJ1.js.map} +1 -1
  89. package/dist/{cost-CdRX1s2p.js → cost-a_rUSdsf.js} +1 -1
  90. package/dist/{cursor-catalog-CUQrabJ_.js → cursor-catalog-DQCmwsX3.js} +4 -4
  91. package/dist/{cursor-catalog-CUQrabJ_.js.map → cursor-catalog-DQCmwsX3.js.map} +1 -1
  92. package/dist/{daytona-Dfhwtr9P.js → daytona-DOeJzXl_.js} +27 -19
  93. package/dist/daytona-DOeJzXl_.js.map +1 -0
  94. package/dist/{daytona-image-CnG6G00x.js → daytona-image-B9JpVeP5.js} +5 -4
  95. package/dist/daytona-image-B9JpVeP5.js.map +1 -0
  96. package/dist/daytona-image-BsCbvDGn.js +1 -0
  97. package/dist/db-BqFlDMmS.js +1 -0
  98. package/dist/{db-5H95sFii.js → db-DU3fgU0h.js} +32 -120
  99. package/dist/db-DU3fgU0h.js.map +1 -0
  100. package/dist/debug-CGg7KHKq.js +1 -0
  101. package/dist/{debug-CIXzB4wK.js → debug-T29p6HOX.js} +2 -10
  102. package/dist/debug-T29p6HOX.js.map +1 -0
  103. package/dist/{default-effort-DYpCkJRk.js → default-effort-BFl6WLBi.js} +3 -3
  104. package/dist/{default-effort-DYpCkJRk.js.map → default-effort-BFl6WLBi.js.map} +1 -1
  105. package/dist/{default-effort-CtNY9CGW.js → default-effort-C6Gcd-Fy.js} +1 -1
  106. package/dist/{dist-DeqeCUZe.js → dist-DCG7vZGQ.js} +3 -3
  107. package/dist/{dist-DeqeCUZe.js.map → dist-DCG7vZGQ.js.map} +1 -1
  108. package/dist/{docker-kpudeSxV.js → docker-B5YBmpPz.js} +1 -1
  109. package/dist/{docker-CR0JZ1FE.js → docker-hIo_H0W0.js} +4 -4
  110. package/dist/{docker-CR0JZ1FE.js.map → docker-hIo_H0W0.js.map} +1 -1
  111. package/dist/{doctor-aE-RMbB_.js → doctor-DGWbvYtu.js} +29 -29
  112. package/dist/{doctor-aE-RMbB_.js.map → doctor-DGWbvYtu.js.map} +1 -1
  113. package/dist/duration-Bz2H7pXb.js +34 -0
  114. package/dist/duration-Bz2H7pXb.js.map +1 -0
  115. package/dist/{environment-C8pUCD_A.js → environment-WC8PrLoe.js} +14 -11
  116. package/dist/environment-WC8PrLoe.js.map +1 -0
  117. package/dist/errors-BjzEWESY.js +93 -0
  118. package/dist/errors-BjzEWESY.js.map +1 -0
  119. package/dist/{errors-DPUoUTdK.js → errors-Cda7UzRA.js} +2 -2
  120. package/dist/{errors-DPUoUTdK.js.map → errors-Cda7UzRA.js.map} +1 -1
  121. package/dist/{eval-source-CaLIGH3U.js → eval-source-DL1HOi8U.js} +6 -6
  122. package/dist/{eval-source-CaLIGH3U.js.map → eval-source-DL1HOi8U.js.map} +1 -1
  123. package/dist/{evaluate-4kBVtwZZ.js → evaluate-DHnD8yzq.js} +280 -59
  124. package/dist/evaluate-DHnD8yzq.js.map +1 -0
  125. package/dist/{evaluate-DHaNtgVf.d.ts → evaluate-Nnh0iPuo.d.ts} +2 -3
  126. package/dist/{events-CXxFvVMK.js → events-oe84EOLK.js} +153 -34
  127. package/dist/{events-CXxFvVMK.js.map → events-oe84EOLK.js.map} +1 -1
  128. package/dist/{fake-bootstrap-CzxrCqO3.js → fake-bootstrap-Ct1qEs-Z.js} +2 -2
  129. package/dist/{fake-bootstrap-CzxrCqO3.js.map → fake-bootstrap-Ct1qEs-Z.js.map} +1 -1
  130. package/dist/files-2fO6iaJG.js +1 -0
  131. package/dist/{files-DpwJW3w6.js → files-4Qt4KUyR.js} +3 -3
  132. package/dist/{files-DpwJW3w6.js.map → files-4Qt4KUyR.js.map} +1 -1
  133. package/dist/{files-DgHeTdCZ.js → files-4XWe_gow.js} +27 -41
  134. package/dist/files-4XWe_gow.js.map +1 -0
  135. package/dist/files-63CNzRBF.js +1 -0
  136. package/dist/files-BDkCNIEh.js +1 -0
  137. package/dist/{files-CDfG8swM.js → files-Bv6ipFjc.js} +27 -18
  138. package/dist/files-Bv6ipFjc.js.map +1 -0
  139. package/dist/{files-Cs2dtb7-.js → files-ClUbQPj9.js} +2 -2
  140. package/dist/{files-Cs2dtb7-.js.map → files-ClUbQPj9.js.map} +1 -1
  141. package/dist/files-CzgXLYGq.js +1609 -0
  142. package/dist/files-CzgXLYGq.js.map +1 -0
  143. package/dist/files-DCcRkJN4.js +1 -0
  144. package/dist/{files-BkvxIqfI.js → files-DW8y3WCx.js} +5 -5
  145. package/dist/{files-BkvxIqfI.js.map → files-DW8y3WCx.js.map} +1 -1
  146. package/dist/gateway.d.ts +2 -3
  147. package/dist/{git-BnnNEXqh.js → git-CiCya2yZ.js} +3 -3
  148. package/dist/{git-BnnNEXqh.js.map → git-CiCya2yZ.js.map} +1 -1
  149. package/dist/{harness-FcTyyPco.js → harness-Dcd3ffkY.js} +3 -2
  150. package/dist/harness-Dcd3ffkY.js.map +1 -0
  151. package/dist/{harness-nwnyghJZ.js → harness-DvqNGwl6.js} +3 -3
  152. package/dist/{harness-nwnyghJZ.js.map → harness-DvqNGwl6.js.map} +1 -1
  153. package/dist/{harness-install-BfMBYDfP.js → harness-install-BSet5fE5.js} +4 -3
  154. package/dist/harness-install-BSet5fE5.js.map +1 -0
  155. package/dist/harness.d.ts +2 -3
  156. package/dist/harness.js +1 -1
  157. package/dist/http-DtlSzw4A.js +96 -0
  158. package/dist/http-DtlSzw4A.js.map +1 -0
  159. package/dist/{ids-a6cr243_.js → ids-CtxRn13a.js} +3 -2
  160. package/dist/ids-CtxRn13a.js.map +1 -0
  161. package/dist/{images-DtXwj2wL.js → images-BkJn7NHU.js} +13 -13
  162. package/dist/{images-DtXwj2wL.js.map → images-BkJn7NHU.js.map} +1 -1
  163. package/dist/index.d.ts +9 -5
  164. package/dist/index.js +4 -5
  165. package/dist/init-BOYNr3Ql.js +1 -0
  166. package/dist/{init-Ci_IAp8p.js → init-CAJvEKEt.js} +6 -6
  167. package/dist/{init-Ci_IAp8p.js.map → init-CAJvEKEt.js.map} +1 -1
  168. package/dist/{ink-list-Dnh6XD3C.js → ink-list-BJIKlKpN.js} +3 -3
  169. package/dist/{ink-list-Dnh6XD3C.js.map → ink-list-BJIKlKpN.js.map} +1 -1
  170. package/dist/{inputs-z4JqnQ5g.js → inputs-CjhDEzr4.js} +6 -6
  171. package/dist/{inputs-z4JqnQ5g.js.map → inputs-CjhDEzr4.js.map} +1 -1
  172. package/dist/inputs-load-C8HEtAej.js +1 -0
  173. package/dist/{inputs-load-DPUP_IFL.js → inputs-load-DQRC3dUA.js} +3 -3
  174. package/dist/{inputs-load-DPUP_IFL.js.map → inputs-load-DQRC3dUA.js.map} +1 -1
  175. package/dist/internal/vm-api/boat.d.ts +46 -0
  176. package/dist/internal/vm-api/boat.js +1 -0
  177. package/dist/internal/vm-api/daytona.d.ts +26 -0
  178. package/dist/internal/vm-api/daytona.js +220 -0
  179. package/dist/internal/vm-api/daytona.js.map +1 -0
  180. package/dist/internal/vm-api.d.ts +86 -0
  181. package/dist/internal/vm-api.js +3 -0
  182. package/dist/internal/vm.d.ts +7 -8
  183. package/dist/internal/vm.js +6 -6
  184. package/dist/internal/vm.js.map +1 -1
  185. package/dist/{invocations-C1gY3E0J.js → invocations-DUFiIb_S.js} +6 -6
  186. package/dist/{invocations-C1gY3E0J.js.map → invocations-DUFiIb_S.js.map} +1 -1
  187. package/dist/issue-BKMnnit3.js +120 -0
  188. package/dist/issue-BKMnnit3.js.map +1 -0
  189. package/dist/issue-esBvB5Df.js +1 -0
  190. package/dist/{jiti-ILwyxt93.js → jiti-aNfS_lSj.js} +2 -2
  191. package/dist/{jiti-ILwyxt93.js.map → jiti-aNfS_lSj.js.map} +1 -1
  192. package/dist/{judge-DwzqucLS.js → judge-_fsdF4YB.js} +7 -4
  193. package/dist/judge-_fsdF4YB.js.map +1 -0
  194. package/dist/judge.d.ts +5 -6
  195. package/dist/judge.js +1 -1
  196. package/dist/{judgments-Cj8bFaDG.js → judgments-CVCUWT-g.js} +8 -5
  197. package/dist/{judgments-Cj8bFaDG.js.map → judgments-CVCUWT-g.js.map} +1 -1
  198. package/dist/{kinds-DEKXOWVJ.js → kinds-5utDFJ15.js} +37 -12
  199. package/dist/kinds-5utDFJ15.js.map +1 -0
  200. package/dist/labels-Dtyf5-pd.js +251 -0
  201. package/dist/labels-Dtyf5-pd.js.map +1 -0
  202. package/dist/{layout-nCnU9Vu2.js → layout-Co4tPHWI.js} +3 -3
  203. package/dist/{layout-nCnU9Vu2.js.map → layout-Co4tPHWI.js.map} +1 -1
  204. package/dist/link-Dat_O7Gn.js +128 -0
  205. package/dist/link-Dat_O7Gn.js.map +1 -0
  206. package/dist/{list-MK4L8tfW.js → list-CjcNH-5e.js} +13 -8
  207. package/dist/list-CjcNH-5e.js.map +1 -0
  208. package/dist/live-BElpkw5b.js +56 -0
  209. package/dist/live-BElpkw5b.js.map +1 -0
  210. package/dist/{live-Dlq-S2yy.js → live-BRF0ogR6.js} +3 -5
  211. package/dist/live-BRF0ogR6.js.map +1 -0
  212. package/dist/{machine-service-Byl0BlcT.js → machine-service-Cymfk7E-.js} +1 -1
  213. package/dist/{machine-service-CZiXiVsS.js → machine-service-DYdTM_rW.js} +146 -13
  214. package/dist/machine-service-DYdTM_rW.js.map +1 -0
  215. package/dist/{machines-Ch5bhgvk.js → machines-B6rS9-Xu.js} +38 -38
  216. package/dist/{machines-Ch5bhgvk.js.map → machines-B6rS9-Xu.js.map} +1 -1
  217. package/dist/markdown-COts-jxf.js +653 -0
  218. package/dist/markdown-COts-jxf.js.map +1 -0
  219. package/dist/{model-lLaUxxno.js → model-BdLvfSQO.js} +1 -1
  220. package/dist/{model-DRa7yv6K.js → model-CIMBjBS7.js} +5 -5
  221. package/dist/{model-DRa7yv6K.js.map → model-CIMBjBS7.js.map} +1 -1
  222. package/dist/model-CrsA2Evf.js +1 -0
  223. package/dist/{model-CRh8aiYS.js → model-oBFmfzES.js} +4 -4
  224. package/dist/{model-CRh8aiYS.js.map → model-oBFmfzES.js.map} +1 -1
  225. package/dist/{model-LoLnq9y1.js → model-xemZQ7DK.js} +251 -65
  226. package/dist/model-xemZQ7DK.js.map +1 -0
  227. package/dist/{node-BQjSQw0d.js → node-DyRPGAT5.js} +19 -8
  228. package/dist/{node-BQjSQw0d.js.map → node-DyRPGAT5.js.map} +1 -1
  229. package/dist/options-CeIRZslO.js +1 -0
  230. package/dist/otlp-ehLWBhVL.js +123 -0
  231. package/dist/otlp-ehLWBhVL.js.map +1 -0
  232. package/dist/outcome-1LBk2e3w.js +38 -0
  233. package/dist/outcome-1LBk2e3w.js.map +1 -0
  234. package/dist/{patch-D8X6VB-e.js → patch-BgSw3TXR.js} +3 -3
  235. package/dist/{patch-D8X6VB-e.js.map → patch-BgSw3TXR.js.map} +1 -1
  236. package/dist/{patch-C7yBztZj.js → patch-uwo6t4Zy.js} +26 -2
  237. package/dist/patch-uwo6t4Zy.js.map +1 -0
  238. package/dist/{pi-providers-HygmL1y-.js → pi-providers-BjcQv2A1.js} +23 -9
  239. package/dist/{pi-providers-HygmL1y-.js.map → pi-providers-BjcQv2A1.js.map} +1 -1
  240. package/dist/{plain-Ctn8oUdp.js → plain-DXUNwqpO.js} +2 -2
  241. package/dist/{plain-Ctn8oUdp.js.map → plain-DXUNwqpO.js.map} +1 -1
  242. package/dist/{plan-DgIVIrXJ.js → plan-x-_vZMQH.js} +11 -11
  243. package/dist/{plan-DgIVIrXJ.js.map → plan-x-_vZMQH.js.map} +1 -1
  244. package/dist/{plugins-DvEbow6a.js → plugins-0DuNw_c5.js} +7 -7
  245. package/dist/{plugins-DvEbow6a.js.map → plugins-0DuNw_c5.js.map} +1 -1
  246. package/dist/{preflight-dJqs5x3r.js → preflight-0Wt3wufx.js} +1 -1
  247. package/dist/preflight-CKrvQ-of.js +1 -0
  248. package/dist/{preflight-BKGbxN67.js → preflight-CUc-Y1d3.js} +9 -9
  249. package/dist/{preflight-BKGbxN67.js.map → preflight-CUc-Y1d3.js.map} +1 -1
  250. package/dist/{preflight-Qm4wE094.js → preflight-Cce8YEPE.js} +4 -4
  251. package/dist/{preflight-Qm4wE094.js.map → preflight-Cce8YEPE.js.map} +1 -1
  252. package/dist/{prepare-CRPPfRJf.js → prepare-Bj8KzeBU.js} +2 -2
  253. package/dist/{prepare-BAjRSoku.js → prepare-FXc1YcxO.js} +8 -8
  254. package/dist/{prepare-BAjRSoku.js.map → prepare-FXc1YcxO.js.map} +1 -1
  255. package/dist/prices-CfnkJOth.js +1 -0
  256. package/dist/{prices-DCokI_Ka.js → prices-CoLymMRd.js} +3 -3
  257. package/dist/{prices-DCokI_Ka.js.map → prices-CoLymMRd.js.map} +1 -1
  258. package/dist/process-B86Nvm4J.js +118 -0
  259. package/dist/process-B86Nvm4J.js.map +1 -0
  260. package/dist/provenance-Cylt_YxT.d.ts +222 -0
  261. package/dist/{provenance-CSyRCc9B.js → provenance-DDZGWE4O.js} +6 -6
  262. package/dist/{provenance-CSyRCc9B.js.map → provenance-DDZGWE4O.js.map} +1 -1
  263. package/dist/provider-B24hZX95.js +1 -0
  264. package/dist/{provider-ieWOn4YS.js → provider-Cn7lmECy.js} +2 -2
  265. package/dist/{provider-ieWOn4YS.js.map → provider-Cn7lmECy.js.map} +1 -1
  266. package/dist/{provider-stop-CxzWW7Ft.js → provider-stop-DjBMfZW5.js} +2 -2
  267. package/dist/{provider-stop-CxzWW7Ft.js.map → provider-stop-DjBMfZW5.js.map} +1 -1
  268. package/dist/{providers-DxZ26YoG.js → providers-BPujoqQM.js} +1 -1
  269. package/dist/{providers-DkaEJvF5.js → providers-Cqb25Aq1.js} +35 -35
  270. package/dist/{providers-DkaEJvF5.js.map → providers-Cqb25Aq1.js.map} +1 -1
  271. package/dist/{query-BL66BOqL.js → query-C_lwW-ok.js} +2 -2
  272. package/dist/{query-BL66BOqL.js.map → query-C_lwW-ok.js.map} +1 -1
  273. package/dist/query-DzS1Z4bw.js +1 -0
  274. package/dist/{questions-boVPzGoC.js → questions-DRPM7pky.js} +19 -13
  275. package/dist/questions-DRPM7pky.js.map +1 -0
  276. package/dist/{recipe-qyIpP96r.js → recipe-CV_EifJk.js} +4 -4
  277. package/dist/{recipe-qyIpP96r.js.map → recipe-CV_EifJk.js.map} +1 -1
  278. package/dist/{record-D1_D1KFY.js → record-Cj3yWR0E.js} +50 -13
  279. package/dist/record-Cj3yWR0E.js.map +1 -0
  280. package/dist/{redact-t-L3VGy8.js → redact-DMueYS-v.js} +28 -6
  281. package/dist/redact-DMueYS-v.js.map +1 -0
  282. package/dist/{remarks-DqriPKxm.js → remarks-BPKGorBW.js} +4 -2
  283. package/dist/remarks-BPKGorBW.js.map +1 -0
  284. package/dist/{remarks-DEvk5f8v.js → remarks-Bded6YeV.js} +22 -12
  285. package/dist/{remarks-DEvk5f8v.js.map → remarks-Bded6YeV.js.map} +1 -1
  286. package/dist/{remote-CQoBRpOv.js → remote-DMuAUedR.js} +9 -7
  287. package/dist/{remote-CQoBRpOv.js.map → remote-DMuAUedR.js.map} +1 -1
  288. package/dist/renderer/ascii.d.ts +6 -0
  289. package/dist/renderer/ascii.js +7 -0
  290. package/dist/renderer/ascii.js.map +1 -0
  291. package/dist/renderer/markdown.d.ts +31 -0
  292. package/dist/renderer/markdown.js +1 -0
  293. package/dist/report-BSi-R8hC.js +941 -0
  294. package/dist/report-BSi-R8hC.js.map +1 -0
  295. package/dist/report-inputs-JhiwKAZH.js +113 -0
  296. package/dist/report-inputs-JhiwKAZH.js.map +1 -0
  297. package/dist/{resolve-Bfo8sjd-.js → resolve-BEltmYhD.js} +23 -7
  298. package/dist/resolve-BEltmYhD.js.map +1 -0
  299. package/dist/resolve-s6JzFZu0.js +1 -0
  300. package/dist/{resolve-D2RqmybX.js → resolve-usf6ejs_.js} +64 -19
  301. package/dist/resolve-usf6ejs_.js.map +1 -0
  302. package/dist/{results-BpxzyoMd.js → results-rYLTGa1F.js} +11 -7
  303. package/dist/{results-BpxzyoMd.js.map → results-rYLTGa1F.js.map} +1 -1
  304. package/dist/{resume-2ekm_9OB.js → resume-aGIZhM58.js} +7 -7
  305. package/dist/{resume-2ekm_9OB.js.map → resume-aGIZhM58.js.map} +1 -1
  306. package/dist/{retry-CAhpW1hH.js → retry-BNFAHTES.js} +5 -5
  307. package/dist/{retry-CAhpW1hH.js.map → retry-BNFAHTES.js.map} +1 -1
  308. package/dist/{root-BzeoyfGd.js → root-Co0jhOT5.js} +2 -2
  309. package/dist/{root-BzeoyfGd.js.map → root-Co0jhOT5.js.map} +1 -1
  310. package/dist/run-DSKRllpd.js +127 -0
  311. package/dist/run-DSKRllpd.js.map +1 -0
  312. package/dist/{client-B41UK150.js → runtime-B2zv9GPL.js} +525 -105
  313. package/dist/runtime-B2zv9GPL.js.map +1 -0
  314. package/dist/sandbox/boat.d.ts +4 -5
  315. package/dist/sandbox/boat.js +2 -2
  316. package/dist/sandbox/daytona.d.ts +4 -5
  317. package/dist/sandbox/daytona.js +1 -1
  318. package/dist/{sandbox-t-Q-8lA_.js → sandbox-DbTHBA7g.js} +3 -3
  319. package/dist/{sandbox-t-Q-8lA_.js.map → sandbox-DbTHBA7g.js.map} +1 -1
  320. package/dist/sandbox.d.ts +4 -5
  321. package/dist/sandbox.js +1 -1
  322. package/dist/secrets-file-BEScYC3S.js +100 -0
  323. package/dist/secrets-file-BEScYC3S.js.map +1 -0
  324. package/dist/secrets-file-take-BXfYMTM-.js +33 -0
  325. package/dist/secrets-file-take-BXfYMTM-.js.map +1 -0
  326. package/dist/server-BIqAFNjF.js +1 -0
  327. package/dist/server-Dc-V_-C1.js +204 -0
  328. package/dist/server-Dc-V_-C1.js.map +1 -0
  329. package/dist/{services-BG8xuU82.js → services-CHh83UDC.js} +4 -2
  330. package/dist/services-CHh83UDC.js.map +1 -0
  331. package/dist/shared-B3iLKAiu.d.ts +1 -0
  332. package/dist/{shared-DtZwIAfy.js → shared-bXaqVxk-.js} +5 -34
  333. package/dist/shared-bXaqVxk-.js.map +1 -0
  334. package/dist/skill-dirs-B7o83G5I.js +63 -0
  335. package/dist/skill-dirs-B7o83G5I.js.map +1 -0
  336. package/dist/{source-CrXM19HD.js → source-BodZTD70.js} +33 -18
  337. package/dist/source-BodZTD70.js.map +1 -0
  338. package/dist/source-BtdFbZLW.js +1 -0
  339. package/dist/spans-C3FlFC22.js +1 -0
  340. package/dist/spans-Dq3fo6HM.js +6 -0
  341. package/dist/spans-Dq3fo6HM.js.map +1 -0
  342. package/dist/spans-WvAmJF2z.js +72 -0
  343. package/dist/spans-WvAmJF2z.js.map +1 -0
  344. package/dist/{src-C6MsGyD6.js → src-AAdLbAn2.js} +1 -1
  345. package/dist/{src-VG2IRoT4.js → src-BbaLTc-p.js} +2 -2
  346. package/dist/src-BjiNaGf5.js +2 -0
  347. package/dist/{src-Cf4vRyea.js → src-BkkdN2w0.js} +2 -2
  348. package/dist/{src-C5rrQlt8.js → src-BzeiF5Lh.js} +197 -138
  349. package/dist/src-BzeiF5Lh.js.map +1 -0
  350. package/dist/{src-Ds1pmXTg.js → src-CfPSD_GS.js} +2 -2
  351. package/dist/{src-C-ChdnG6.js → src-ClMhIgi3.js} +2 -2
  352. package/dist/{src-C-ChdnG6.js.map → src-ClMhIgi3.js.map} +1 -1
  353. package/dist/{src-io_SKoZ5.js → src-D5i8gCa3.js} +2 -2
  354. package/dist/{src-Bb3k9Kn_.js → src-DDIV_RfE.js} +65 -10
  355. package/dist/{src-Bb3k9Kn_.js.map → src-DDIV_RfE.js.map} +1 -1
  356. package/dist/src-DXZXofCJ.js +1 -0
  357. package/dist/src-Db01fVzc.js +2 -0
  358. package/dist/{src-DwcTn4JY.js → src-DhZuOcgq.js} +5 -5
  359. package/dist/{src-DwcTn4JY.js.map → src-DhZuOcgq.js.map} +1 -1
  360. package/dist/{src-DwcCKsV0.js → src-DiBd7r1i.js} +3 -3
  361. package/dist/{src-DNWiU__5.js → src-Dm2YIeXn.js} +8 -8
  362. package/dist/{src-DNWiU__5.js.map → src-Dm2YIeXn.js.map} +1 -1
  363. package/dist/{src-c3ZQu7Uu.js → src-NYxoDS3b.js} +5 -5
  364. package/dist/{src-c3ZQu7Uu.js.map → src-NYxoDS3b.js.map} +1 -1
  365. package/dist/{src-C3OhA5pw.js → src-Y4AiZxLt.js} +5 -5
  366. package/dist/{src-C3OhA5pw.js.map → src-Y4AiZxLt.js.map} +1 -1
  367. package/dist/{src-Bf5RZlPi.js → src-YpmRtJmP.js} +2 -2
  368. package/dist/{src-Bf5RZlPi.js.map → src-YpmRtJmP.js.map} +1 -1
  369. package/dist/{ssh-pool-Dvfx5GuV.js → ssh-pool-B2c2vxzx.js} +20 -16
  370. package/dist/ssh-pool-B2c2vxzx.js.map +1 -0
  371. package/dist/ssh-pool-mcCYe6RO.js +1 -0
  372. package/dist/{start-COB07NpH.js → start-DyXCyHGX.js} +64 -12
  373. package/dist/start-DyXCyHGX.js.map +1 -0
  374. package/dist/{state-B319V1p8.js → state-CiR8Ema7.js} +21 -38
  375. package/dist/state-CiR8Ema7.js.map +1 -0
  376. package/dist/state-DBuFimCA.js +1 -0
  377. package/dist/store/local.d.ts +2 -3
  378. package/dist/store/s3.d.ts +2 -3
  379. package/dist/studio-share-C05twqpy.js +209 -0
  380. package/dist/studio-share-C05twqpy.js.map +1 -0
  381. package/dist/suite-fO-u8jlS.js +2 -0
  382. package/dist/{suite-D1tgXZxM.js → suite-oH7uiCRq.js} +108 -107
  383. package/dist/suite-oH7uiCRq.js.map +1 -0
  384. package/dist/summary-CTMWfnOF.js +75 -0
  385. package/dist/summary-CTMWfnOF.js.map +1 -0
  386. package/dist/{sync-mOG74RXH.js → sync-r8EvW6Hr.js} +6 -6
  387. package/dist/{sync-mOG74RXH.js.map → sync-r8EvW6Hr.js.map} +1 -1
  388. package/dist/{tart-DMppfbEm.js → tart-BUh58nxA.js} +37 -10
  389. package/dist/tart-BUh58nxA.js.map +1 -0
  390. package/dist/{tart-DmVuVsmX.js → tart-DNrumWZu.js} +1 -1
  391. package/dist/{tart-CzViW3WZ.js → tart-Duqp33Zh.js} +2 -2
  392. package/dist/{tart-CzViW3WZ.js.map → tart-Duqp33Zh.js.map} +1 -1
  393. package/dist/{tart-bake-Cva_qdir.js → tart-bake-ChrVpjuF.js} +8 -7
  394. package/dist/tart-bake-ChrVpjuF.js.map +1 -0
  395. package/dist/{tart-bake-DVIoXWr_.js → tart-bake-LwdUVOzS.js} +1 -1
  396. package/dist/{tart-cli-LzDud2Z6.js → tart-cli-Dv3dNC13.js} +3 -2
  397. package/dist/tart-cli-Dv3dNC13.js.map +1 -0
  398. package/dist/{tart-cli-D88c5YYJ.js → tart-cli-S388NU-r.js} +1 -1
  399. package/dist/{tart-hosts-CTRY5kQ2.js → tart-hosts-B-dQEGpc.js} +7 -6
  400. package/dist/tart-hosts-B-dQEGpc.js.map +1 -0
  401. package/dist/{tart-hosts-8N6Tt7Yb.js → tart-hosts-_nHGB4mC.js} +1 -1
  402. package/dist/{tart-images-JfHirU8W.js → tart-images-DAEYoC_M.js} +3 -3
  403. package/dist/{tart-images-JfHirU8W.js.map → tart-images-DAEYoC_M.js.map} +1 -1
  404. package/dist/testing.d.ts +13 -5
  405. package/dist/testing.js +4 -4
  406. package/dist/{tool-class-CncfCw03.js → tool-class-CB-m4PiF.js} +2 -2
  407. package/dist/{tool-class-CncfCw03.js.map → tool-class-CB-m4PiF.js.map} +1 -1
  408. package/dist/{trace-BpXByD7W.js → trace-CJQLlAbB.js} +2 -2
  409. package/dist/{trace-BpXByD7W.js.map → trace-CJQLlAbB.js.map} +1 -1
  410. package/dist/{traits-CCD8XsmI.js → traits-DPIffsN8.js} +2 -2
  411. package/dist/{traits-CCD8XsmI.js.map → traits-DPIffsN8.js.map} +1 -1
  412. package/dist/{transcript-BXWZiMuC.js → transcript-CW02A4s9.js} +3 -3
  413. package/dist/{transcript-BXWZiMuC.js.map → transcript-CW02A4s9.js.map} +1 -1
  414. package/dist/{resources-DqdwihhT.js → turn-error-Dmv_Muj7.js} +15 -2
  415. package/dist/turn-error-Dmv_Muj7.js.map +1 -0
  416. package/dist/{types-BDo8ttQo.d.ts → types-BZaItiui.d.ts} +209 -28
  417. package/dist/types-Buut5yGe.js +29 -0
  418. package/dist/types-Buut5yGe.js.map +1 -0
  419. package/dist/types-C48zuZbT.d.ts +156 -0
  420. package/dist/types-CYz4dqAd.d.ts +1366 -0
  421. package/dist/{ui-DUiVPbQ2.js → ui-CJvbt2Cc.js} +15 -14
  422. package/dist/ui-CJvbt2Cc.js.map +1 -0
  423. package/dist/vertex-D4H9bKHD.d.ts +2 -0
  424. package/dist/{vertex-BEWxHoxH.js → vertex-DQQGhUn7.js} +2 -2
  425. package/dist/{vertex-BEWxHoxH.js.map → vertex-DQQGhUn7.js.map} +1 -1
  426. package/dist/vertex-DtWe0Xf6.js +1 -0
  427. package/dist/view/index.d.ts +142 -810
  428. package/dist/view/index.js +17 -12
  429. package/dist/view/report/index.d.ts +217 -0
  430. package/dist/view/report/index.js +4 -0
  431. package/dist/{views-CiZGh3ws.js → views-CtnOlABJ.js} +6 -6
  432. package/dist/{views-CiZGh3ws.js.map → views-CtnOlABJ.js.map} +1 -1
  433. package/dist/views-crppDW_B.js +2 -0
  434. package/dist/{vm-container-BVn7pXfD.js → vm-container-DwroMAXW.js} +13 -10
  435. package/dist/vm-container-DwroMAXW.js.map +1 -0
  436. package/dist/{vm-images-CNk-Zl2a.js → vm-images-y0BcVyv3.js} +19 -21
  437. package/dist/vm-images-y0BcVyv3.js.map +1 -0
  438. package/dist/wait-CixM6W0G.js +65 -0
  439. package/dist/wait-CixM6W0G.js.map +1 -0
  440. package/dist/{worker-entry-DmXQ2Znu.js → worker-entry-8KHmPzr4.js} +7 -7
  441. package/dist/{worker-entry-DmXQ2Znu.js.map → worker-entry-8KHmPzr4.js.map} +1 -1
  442. package/dist/workspace-JlgoGyR0.js +1 -0
  443. package/dist/{workspace-wwvwEHzP.js → workspace-xCQ6VDR-.js} +9 -8
  444. package/dist/workspace-xCQ6VDR-.js.map +1 -0
  445. package/package.json +33 -9
  446. package/skills/reeval/SKILL.md +2 -2
  447. package/skills/reeval/references/cli.md +1 -1
  448. package/skills/reeval/references/config.md +1 -1
  449. package/skills/reeval/references/environments.md +1 -1
  450. package/skills/setup/SKILL.md +1 -1
  451. package/dist/agents-BztvTkfM.js.map +0 -1
  452. package/dist/analysis-BnG_1x_O.js.map +0 -1
  453. package/dist/app-files-6NHzghym.js +0 -10
  454. package/dist/app-files-6NHzghym.js.map +0 -1
  455. package/dist/assemble-Doa1m-HW.js.map +0 -1
  456. package/dist/assemble-XrZskSNj.js +0 -1
  457. package/dist/attach-BH2HdwH_.js.map +0 -1
  458. package/dist/attempt-host-8mQV8Uee.js.map +0 -1
  459. package/dist/boat-DKRH0Gv7.js +0 -1
  460. package/dist/boat-DKjqo_ie.js.map +0 -1
  461. package/dist/boat-images-CRN_U_eG.js.map +0 -1
  462. package/dist/bundle-DU2aQVeq.js.map +0 -1
  463. package/dist/capture-BzjNv0qP.js +0 -1
  464. package/dist/cases-CM-MQRQp.js.map +0 -1
  465. package/dist/cases-FvhbM8M5.js +0 -1
  466. package/dist/cli-DMHOwdVr.js.map +0 -1
  467. package/dist/cli-spec-D0wuUaj9.js.map +0 -1
  468. package/dist/client-B41UK150.js.map +0 -1
  469. package/dist/command-8GIHYGZf.js +0 -298
  470. package/dist/command-8GIHYGZf.js.map +0 -1
  471. package/dist/command-CAmnWLFL.js.map +0 -1
  472. package/dist/command-CXxckfsq.js.map +0 -1
  473. package/dist/command-ao0NZ8h0.js.map +0 -1
  474. package/dist/commands-B3lnIPj5.js +0 -1
  475. package/dist/commands-ttChCsAy.js.map +0 -1
  476. package/dist/config-myJT1Qjc.js.map +0 -1
  477. package/dist/context-DnzR9TNK.js +0 -120
  478. package/dist/context-DnzR9TNK.js.map +0 -1
  479. package/dist/daytona-Dfhwtr9P.js.map +0 -1
  480. package/dist/daytona-image-CnG6G00x.js.map +0 -1
  481. package/dist/daytona-image-yJK3c4EV.js +0 -1
  482. package/dist/db-5H95sFii.js.map +0 -1
  483. package/dist/db-Bbg1n_2M.js +0 -2
  484. package/dist/debug-CF4p4Lp_.js +0 -1
  485. package/dist/debug-CIXzB4wK.js.map +0 -1
  486. package/dist/environment-C8pUCD_A.js.map +0 -1
  487. package/dist/evaluate-4kBVtwZZ.js.map +0 -1
  488. package/dist/files-BFnkOAhn.js +0 -1
  489. package/dist/files-BgQxoDlN.js +0 -1
  490. package/dist/files-CDfG8swM.js.map +0 -1
  491. package/dist/files-CSe4VaMj.js +0 -1
  492. package/dist/files-CX_mmvCc.js +0 -775
  493. package/dist/files-CX_mmvCc.js.map +0 -1
  494. package/dist/files-D6M7J3iX.js +0 -1
  495. package/dist/files-DgHeTdCZ.js.map +0 -1
  496. package/dist/gate-CgYdaprG.js +0 -49
  497. package/dist/gate-CgYdaprG.js.map +0 -1
  498. package/dist/harness-FcTyyPco.js.map +0 -1
  499. package/dist/harness-install-BfMBYDfP.js.map +0 -1
  500. package/dist/hosted-5Zz2peTR.js.map +0 -1
  501. package/dist/hosted-Co-waHe0.js +0 -131
  502. package/dist/hosted-Co-waHe0.js.map +0 -1
  503. package/dist/hosted-run-202QicZ-.js +0 -1
  504. package/dist/hosted-run-BfAPIMyT.js +0 -230
  505. package/dist/hosted-run-BfAPIMyT.js.map +0 -1
  506. package/dist/ids-a6cr243_.js.map +0 -1
  507. package/dist/init-BiL6B3S4.js +0 -1
  508. package/dist/inputs-load-M-BGe7gd.js +0 -1
  509. package/dist/judge-DwzqucLS.js.map +0 -1
  510. package/dist/kinds-DEKXOWVJ.js.map +0 -1
  511. package/dist/list-MK4L8tfW.js.map +0 -1
  512. package/dist/live-BkPNXVmN.js +0 -120
  513. package/dist/live-BkPNXVmN.js.map +0 -1
  514. package/dist/live-Dlq-S2yy.js.map +0 -1
  515. package/dist/live-gZtkBwuo.js +0 -1
  516. package/dist/machine-service-CZiXiVsS.js.map +0 -1
  517. package/dist/model-C6aoJLg_.js +0 -1
  518. package/dist/model-LoLnq9y1.js.map +0 -1
  519. package/dist/options-I9I3FwMl.js +0 -1
  520. package/dist/pairs-BGb134Vu.js +0 -230
  521. package/dist/pairs-BGb134Vu.js.map +0 -1
  522. package/dist/patch-C7yBztZj.js.map +0 -1
  523. package/dist/paths-Dwmi7L4X.js +0 -75
  524. package/dist/paths-Dwmi7L4X.js.map +0 -1
  525. package/dist/preflight-fyV5nnea.js +0 -1
  526. package/dist/prices-C0gKS_8G.js +0 -1
  527. package/dist/provider-DHT20Gl8.js +0 -1
  528. package/dist/query-C9OKU1Vz.js +0 -1
  529. package/dist/questions-boVPzGoC.js.map +0 -1
  530. package/dist/record-D1_D1KFY.js.map +0 -1
  531. package/dist/redact-t-L3VGy8.js.map +0 -1
  532. package/dist/remarks-DqriPKxm.js.map +0 -1
  533. package/dist/resolve-BdpO8BN1.js +0 -1
  534. package/dist/resolve-Bfo8sjd-.js.map +0 -1
  535. package/dist/resolve-D2RqmybX.js.map +0 -1
  536. package/dist/resources-DqdwihhT.js.map +0 -1
  537. package/dist/runtime-C5fKSFCz.js +0 -457
  538. package/dist/runtime-C5fKSFCz.js.map +0 -1
  539. package/dist/server-BcLg9WzE.js +0 -284
  540. package/dist/server-BcLg9WzE.js.map +0 -1
  541. package/dist/server-Buav2-CG.js +0 -1
  542. package/dist/services-BG8xuU82.js.map +0 -1
  543. package/dist/shared-CHvO7eLi.d.ts +0 -1
  544. package/dist/shared-DtZwIAfy.js.map +0 -1
  545. package/dist/slug-IHh3f770.js.map +0 -1
  546. package/dist/source-CrXM19HD.js.map +0 -1
  547. package/dist/source-dvxkqYvk.js +0 -1
  548. package/dist/src-5dCrqbFd.js +0 -2
  549. package/dist/src-C5rrQlt8.js.map +0 -1
  550. package/dist/src-DEbNp-rx.js +0 -1
  551. package/dist/src-DrLbG1HM.js +0 -2
  552. package/dist/ssh-pool-BorCizYw.js +0 -1
  553. package/dist/ssh-pool-Dvfx5GuV.js.map +0 -1
  554. package/dist/start-COB07NpH.js.map +0 -1
  555. package/dist/state-B319V1p8.js.map +0 -1
  556. package/dist/state-C5oBvmoZ.js +0 -1
  557. package/dist/suite-BwJGOhCZ.js +0 -2
  558. package/dist/suite-D1tgXZxM.js.map +0 -1
  559. package/dist/summary-ClLns_wv.js +0 -169
  560. package/dist/summary-ClLns_wv.js.map +0 -1
  561. package/dist/tart-DMppfbEm.js.map +0 -1
  562. package/dist/tart-bake-Cva_qdir.js.map +0 -1
  563. package/dist/tart-cli-LzDud2Z6.js.map +0 -1
  564. package/dist/tart-hosts-CTRY5kQ2.js.map +0 -1
  565. package/dist/types-CbcnJxCy.js +0 -15
  566. package/dist/types-CbcnJxCy.js.map +0 -1
  567. package/dist/ui-DUiVPbQ2.js.map +0 -1
  568. package/dist/vertex-C7PI-WPc.d.ts +0 -3
  569. package/dist/vertex-DXfcXYKn.js +0 -1
  570. package/dist/views-B0qZR5Ef.js +0 -2
  571. package/dist/vm-container-BVn7pXfD.js.map +0 -1
  572. package/dist/vm-images-CNk-Zl2a.js.map +0 -1
  573. package/dist/workspace-CRgFdmgW.js +0 -1
  574. package/dist/workspace-wwvwEHzP.js.map +0 -1
@@ -0,0 +1,1609 @@
1
+ import { a as fromCwd, l as relativeFile, u as sha256 } from "./ids-CtxRn13a.js";
2
+ import { t as RUN_ID } from "./api-ZeGnedB3.js";
3
+ import { o as PACKAGE_VERSION, t as BUILD_ID } from "./root-Co0jhOT5.js";
4
+ import { d as readableRecord, f as readableRemarks, n as NewerSchemaError, o as readableArchiveManifest } from "./record-Cj3yWR0E.js";
5
+ import { n as debugArchiveFile, r as debugRoot } from "./files-Bv6ipFjc.js";
6
+ import { i as TRACE_FILE, r as REQUESTS_FILE, t as DEBUG_LOG } from "./debug-T29p6HOX.js";
7
+ import { r as runHeader, t as REMARKS_FILE } from "./remarks-BPKGorBW.js";
8
+ import { r as repoTop, t as git } from "./git-CiCya2yZ.js";
9
+ import { d as maskedMatch, o as findSecrets, s as findSecretsInJson } from "./redact-DMueYS-v.js";
10
+ import { r as patchPath } from "./patch-uwo6t4Zy.js";
11
+ import { n as keptFacts, o as summaryFiles } from "./summary-CTMWfnOF.js";
12
+ import { z } from "zod";
13
+ import { createReadStream, existsSync } from "node:fs";
14
+ import { hostname } from "node:os";
15
+ import { basename, dirname, isAbsolute, join } from "node:path";
16
+ import { createHash, randomBytes } from "node:crypto";
17
+ import { link, mkdir, open, readFile, readdir, rename, rm, stat, unlink, writeFile } from "node:fs/promises";
18
+ import { crc32, deflateRawSync, inflateRawSync } from "node:zlib";
19
+ import { isDeepStrictEqual } from "node:util";
20
+ // src/archive/zip.ts
21
+ /** A zip that can't be written as asked, or can't be read. */
22
+ var ZipError = class extends Error {
23
+ name = "ZipError";
24
+ };
25
+ const LOCAL = 67324752;
26
+ const CENTRAL = 33639248;
27
+ const END = 101010256;
28
+ const END64 = 101075792;
29
+ const LOCATOR64 = 117853008;
30
+ const ZIP64_EXTRA = 1;
31
+ const U16 = 65535;
32
+ const U32 = 4294967295;
33
+ /** General-purpose flag bit 11: the name is UTF-8. */
34
+ const UTF8 = 2048;
35
+ const ENCRYPTED = 1;
36
+ const LOCAL_SIZE = 30;
37
+ const CENTRAL_SIZE = 46;
38
+ const END_SIZE = 22;
39
+ const END64_SIZE = 56;
40
+ const LOCATOR64_SIZE = 20;
41
+ /** A regular file, rw-r--r--, in the high half of the external attributes (Unix). */
42
+ const FILE_ATTRIBUTES = 33188 << 16 >>> 0;
43
+ const MADE_BY_UNIX = 768;
44
+ const METHOD_CODE = {
45
+ store: 0,
46
+ deflate: 8
47
+ };
48
+ /** `a/./b` as `a/b`; null for a path that's absolute, empty, a folder or climbs out with `..`. */
49
+ function safeZipPath(path) {
50
+ if (path.startsWith("/") || /^[A-Za-z]:/.test(path) || path.includes("\\")) return null;
51
+ if (path.endsWith("/") || path.includes("\0")) return null;
52
+ const parts = path.split("/").filter((p) => p !== "" && p !== ".");
53
+ if (!parts.length || parts.includes("..")) return null;
54
+ return parts.join("/");
55
+ }
56
+ /** CRC-32 of any length: zlib's `crc32` takes a 32-bit length, so more goes in pieces. */
57
+ function crc32Of(data, piece = 2 ** 30) {
58
+ let crc = 0;
59
+ for (let at = 0; at < data.length; at += piece) crc = crc32(data.subarray(at, at + piece), crc);
60
+ return crc;
61
+ }
62
+ /** MS-DOS date and time fields, as zip keeps them: two-second steps, 1980 to 2107, read as UTC. */
63
+ function dosTime(at) {
64
+ const ms = Math.min(Math.max(at.getTime(), Date.UTC(1980, 0, 1)), Date.UTC(2107, 11, 31, 23, 59, 58));
65
+ const d = new Date(ms);
66
+ return {
67
+ time: d.getUTCHours() << 11 | d.getUTCMinutes() << 5 | d.getUTCSeconds() >> 1,
68
+ date: d.getUTCFullYear() - 1980 << 9 | d.getUTCMonth() + 1 << 5 | d.getUTCDate()
69
+ };
70
+ }
71
+ /** Writes a zip, one entry at a time, to `sink`; `finish()` writes the central directory. */
72
+ var ZipWriter = class {
73
+ #sink;
74
+ #time;
75
+ #always;
76
+ #entries = [];
77
+ #paths = /* @__PURE__ */ new Set();
78
+ #offset = 0;
79
+ #finished = false;
80
+ constructor(sink, options) {
81
+ this.#sink = sink;
82
+ this.#time = dosTime(options.mtime);
83
+ this.#always = options.zip64 === "always";
84
+ }
85
+ async #write(bytes) {
86
+ await this.#sink(bytes);
87
+ this.#offset += bytes.length;
88
+ }
89
+ /**
90
+ * Adds a file. `deflate` (the default) stores it instead when deflating doesn't make it
91
+ * smaller, as for data that's compressed already; the entry's method says which it got.
92
+ */
93
+ async add(path, data, method = "deflate") {
94
+ if (this.#finished) throw new ZipError(`can't add ${path}: the zip is finished`);
95
+ if (safeZipPath(path) !== path) throw new ZipError(`${path} isn't a relative path in the zip`);
96
+ if (this.#paths.has(path)) throw new ZipError(`${path} is in the zip already`);
97
+ const name = Buffer.from(path, "utf8");
98
+ if (name.length > U16) throw new ZipError(`${path.slice(0, 40)}… is too long for a zip path`);
99
+ this.#paths.add(path);
100
+ let body = data;
101
+ let used = "store";
102
+ if (method === "deflate") {
103
+ const deflated = deflateRawSync(data, { level: 6 });
104
+ if (deflated.length < data.length) {
105
+ body = deflated;
106
+ used = "deflate";
107
+ }
108
+ }
109
+ const entry = {
110
+ name,
111
+ method: used,
112
+ crc: crc32Of(data),
113
+ compressedSize: body.length,
114
+ size: data.length,
115
+ offset: this.#offset
116
+ };
117
+ const zip64 = this.#always || entry.size >= U32 || entry.compressedSize >= U32;
118
+ const extra = zip64 ? zip64Extra([entry.size, entry.compressedSize]) : Buffer.alloc(0);
119
+ const header = Buffer.alloc(LOCAL_SIZE);
120
+ header.writeUInt32LE(LOCAL, 0);
121
+ header.writeUInt16LE(versionNeeded(used, zip64), 4);
122
+ header.writeUInt16LE(UTF8, 6);
123
+ header.writeUInt16LE(METHOD_CODE[used], 8);
124
+ header.writeUInt16LE(this.#time.time, 10);
125
+ header.writeUInt16LE(this.#time.date, 12);
126
+ header.writeUInt32LE(entry.crc, 14);
127
+ header.writeUInt32LE(zip64 ? U32 : entry.compressedSize, 18);
128
+ header.writeUInt32LE(zip64 ? U32 : entry.size, 22);
129
+ header.writeUInt16LE(name.length, 26);
130
+ header.writeUInt16LE(extra.length, 28);
131
+ await this.#write(Buffer.concat([
132
+ header,
133
+ name,
134
+ extra
135
+ ]));
136
+ await this.#write(body);
137
+ this.#entries.push(entry);
138
+ return used;
139
+ }
140
+ /** Writes the central directory and the end records; returns the zip's size in bytes. */
141
+ async finish() {
142
+ if (this.#finished) throw new ZipError("the zip is finished already");
143
+ this.#finished = true;
144
+ const start = this.#offset;
145
+ for (const e of this.#entries) {
146
+ const big = {
147
+ size: this.#always || e.size >= U32,
148
+ compressedSize: this.#always || e.compressedSize >= U32,
149
+ offset: this.#always || e.offset >= U32
150
+ };
151
+ const extra = zip64Extra([
152
+ ...big.size ? [e.size] : [],
153
+ ...big.compressedSize ? [e.compressedSize] : [],
154
+ ...big.offset ? [e.offset] : []
155
+ ]);
156
+ const zip64 = big.size || big.compressedSize || big.offset;
157
+ const header = Buffer.alloc(CENTRAL_SIZE);
158
+ header.writeUInt32LE(CENTRAL, 0);
159
+ header.writeUInt16LE(MADE_BY_UNIX | versionNeeded(e.method, zip64), 4);
160
+ header.writeUInt16LE(versionNeeded(e.method, zip64), 6);
161
+ header.writeUInt16LE(UTF8, 8);
162
+ header.writeUInt16LE(METHOD_CODE[e.method], 10);
163
+ header.writeUInt16LE(this.#time.time, 12);
164
+ header.writeUInt16LE(this.#time.date, 14);
165
+ header.writeUInt32LE(e.crc, 16);
166
+ header.writeUInt32LE(big.compressedSize ? U32 : e.compressedSize, 20);
167
+ header.writeUInt32LE(big.size ? U32 : e.size, 24);
168
+ header.writeUInt16LE(e.name.length, 28);
169
+ header.writeUInt16LE(zip64 ? extra.length : 0, 30);
170
+ header.writeUInt32LE(FILE_ATTRIBUTES, 38);
171
+ header.writeUInt32LE(big.offset ? U32 : e.offset, 42);
172
+ await this.#write(Buffer.concat([
173
+ header,
174
+ e.name,
175
+ zip64 ? extra : Buffer.alloc(0)
176
+ ]));
177
+ }
178
+ const size = this.#offset - start;
179
+ const count = this.#entries.length;
180
+ const zip64 = this.#always || count >= U16 || size >= U32 || start >= U32;
181
+ if (zip64) {
182
+ const end64 = Buffer.alloc(END64_SIZE);
183
+ end64.writeUInt32LE(END64, 0);
184
+ end64.writeBigUInt64LE(BigInt(44), 4);
185
+ end64.writeUInt16LE(813, 12);
186
+ end64.writeUInt16LE(45, 14);
187
+ end64.writeBigUInt64LE(BigInt(count), 24);
188
+ end64.writeBigUInt64LE(BigInt(count), 32);
189
+ end64.writeBigUInt64LE(BigInt(size), 40);
190
+ end64.writeBigUInt64LE(BigInt(start), 48);
191
+ const locator = Buffer.alloc(LOCATOR64_SIZE);
192
+ locator.writeUInt32LE(LOCATOR64, 0);
193
+ locator.writeBigUInt64LE(BigInt(this.#offset), 8);
194
+ locator.writeUInt32LE(1, 16);
195
+ await this.#write(Buffer.concat([end64, locator]));
196
+ }
197
+ const end = Buffer.alloc(END_SIZE);
198
+ end.writeUInt32LE(END, 0);
199
+ end.writeUInt16LE(zip64 ? U16 : count, 8);
200
+ end.writeUInt16LE(zip64 ? U16 : count, 10);
201
+ end.writeUInt32LE(zip64 ? U32 : size, 12);
202
+ end.writeUInt32LE(zip64 ? U32 : start, 16);
203
+ await this.#write(end);
204
+ return this.#offset;
205
+ }
206
+ };
207
+ const versionNeeded = (method, zip64) => zip64 ? 45 : method === "deflate" ? 20 : 10;
208
+ function zip64Extra(values) {
209
+ const extra = Buffer.alloc(4 + values.length * 8);
210
+ extra.writeUInt16LE(ZIP64_EXTRA, 0);
211
+ extra.writeUInt16LE(values.length * 8, 2);
212
+ for (const [i, v] of values.entries()) extra.writeBigUInt64LE(BigInt(v), 4 + i * 8);
213
+ return extra;
214
+ }
215
+ /** A zip in memory. */
216
+ const bufferSource = (bytes) => ({
217
+ size: bytes.length,
218
+ read: async (offset, length) => bytes.subarray(offset, offset + length)
219
+ });
220
+ /** A zip file, read in ranges; `close()` closes it. */
221
+ async function fileSource(path) {
222
+ const handle = await open(path, "r");
223
+ try {
224
+ const { size } = await handle.stat();
225
+ return {
226
+ size,
227
+ async read(offset, length) {
228
+ const out = Buffer.alloc(length);
229
+ let at = 0;
230
+ while (at < length) {
231
+ const { bytesRead } = await handle.read(out, at, length - at, offset + at);
232
+ if (bytesRead === 0) break;
233
+ at += bytesRead;
234
+ }
235
+ return out.subarray(0, at);
236
+ },
237
+ close: () => handle.close()
238
+ };
239
+ } catch (error) {
240
+ await handle.close();
241
+ throw error;
242
+ }
243
+ }
244
+ const u64 = (b, at, what) => {
245
+ const n = b.readBigUInt64LE(at);
246
+ if (n > BigInt(Number.MAX_SAFE_INTEGER)) throw new ZipError(`${what} is too large to read`);
247
+ return Number(n);
248
+ };
249
+ async function readExactly(source, offset, length, what) {
250
+ if (offset < 0 || offset + length > source.size) throw new ZipError(`${what} lies outside the zip (${source.size} bytes)`);
251
+ const read = await source.read(offset, length);
252
+ const bytes = Buffer.from(read.buffer, read.byteOffset, read.byteLength);
253
+ if (bytes.length !== length) throw new ZipError(`${what} was cut short`);
254
+ return bytes;
255
+ }
256
+ /** The end-of-central-directory record: the last one whose comment runs to the end. */
257
+ async function findEnd(source) {
258
+ const tailLength = Math.min(source.size, 65557);
259
+ const tail = await readExactly(source, source.size - tailLength, tailLength, "the end record");
260
+ for (let at = tail.length - END_SIZE; at >= 0; at--) {
261
+ if (tail.readUInt32LE(at) !== END) continue;
262
+ if (at + END_SIZE + tail.readUInt16LE(at + 20) !== tail.length) continue;
263
+ return {
264
+ record: tail.subarray(at, at + END_SIZE),
265
+ offset: source.size - tailLength + at
266
+ };
267
+ }
268
+ throw new ZipError("no end-of-central-directory record: not a zip, or cut short");
269
+ }
270
+ /** Reads a zip's central directory from `source`. */
271
+ async function readZip(source) {
272
+ const end = await findEnd(source);
273
+ let count = end.record.readUInt16LE(10);
274
+ let directorySize = end.record.readUInt32LE(12);
275
+ let directoryStart = end.record.readUInt32LE(16);
276
+ const locatorAt = end.offset - LOCATOR64_SIZE;
277
+ if (locatorAt >= 0) {
278
+ const locator = await readExactly(source, locatorAt, LOCATOR64_SIZE, "the zip64 locator");
279
+ if (locator.readUInt32LE(0) === LOCATOR64) {
280
+ const end64 = await readExactly(source, u64(locator, 8, "the zip64 end record offset"), END64_SIZE, "the zip64 end record");
281
+ if (end64.readUInt32LE(0) !== END64) throw new ZipError("the zip64 end record is missing");
282
+ count = u64(end64, 32, "the entry count");
283
+ directorySize = u64(end64, 40, "the central directory size");
284
+ directoryStart = u64(end64, 48, "the central directory offset");
285
+ }
286
+ }
287
+ const directory = await readExactly(source, directoryStart, directorySize, "the central directory");
288
+ const entries = [];
289
+ const byPath = /* @__PURE__ */ new Map();
290
+ const locals = /* @__PURE__ */ new Map();
291
+ let at = 0;
292
+ for (let i = 0; i < count; i++) {
293
+ if (at + CENTRAL_SIZE > directory.length || directory.readUInt32LE(at) !== CENTRAL) throw new ZipError(`central directory entry ${i + 1} of ${count} is missing`);
294
+ const flags = directory.readUInt16LE(at + 8);
295
+ const code = directory.readUInt16LE(at + 10);
296
+ const nameLength = directory.readUInt16LE(at + 28);
297
+ const extraLength = directory.readUInt16LE(at + 30);
298
+ const commentLength = directory.readUInt16LE(at + 32);
299
+ const next = at + CENTRAL_SIZE + nameLength + extraLength + commentLength;
300
+ if (next > directory.length) throw new ZipError(`central directory entry ${i + 1} is cut short`);
301
+ const nameBytes = directory.subarray(at + CENTRAL_SIZE, at + CENTRAL_SIZE + nameLength);
302
+ const raw = nameBytes.toString("utf8");
303
+ const extra = directory.subarray(at + CENTRAL_SIZE + nameLength, at + CENTRAL_SIZE + nameLength + extraLength);
304
+ let size = directory.readUInt32LE(at + 24);
305
+ let compressedSize = directory.readUInt32LE(at + 20);
306
+ let offset = directory.readUInt32LE(at + 42);
307
+ const crc = directory.readUInt32LE(at + 16);
308
+ at = next;
309
+ if (raw.endsWith("/")) continue;
310
+ const path = safeZipPath(raw);
311
+ if (path !== raw) throw new ZipError(`${JSON.stringify(raw)} isn't a relative path in the zip`);
312
+ if (flags & ENCRYPTED) throw new ZipError(`${path} is encrypted`);
313
+ const method = code === 0 ? "store" : code === 8 ? "deflate" : null;
314
+ if (!method) throw new ZipError(`${path} uses compression method ${code}, not store or deflate`);
315
+ if (size === U32 || compressedSize === U32 || offset === U32) {
316
+ const values = zip64Values(extra, path);
317
+ const take = () => {
318
+ const v = values.shift();
319
+ if (v === void 0) throw new ZipError(`${path}'s zip64 sizes are missing`);
320
+ return v;
321
+ };
322
+ if (size === U32) size = take();
323
+ if (compressedSize === U32) compressedSize = take();
324
+ if (offset === U32) offset = take();
325
+ }
326
+ if (byPath.has(path)) throw new ZipError(`${path} is in the zip twice`);
327
+ const entry = {
328
+ path,
329
+ method,
330
+ crc32: crc,
331
+ compressedSize,
332
+ size,
333
+ offset
334
+ };
335
+ entries.push(entry);
336
+ byPath.set(path, entry);
337
+ locals.set(entry, {
338
+ name: Buffer.from(nameBytes),
339
+ code
340
+ });
341
+ }
342
+ const bounds = /* @__PURE__ */ new Map();
343
+ const byOffset = [...entries].sort((a, b) => a.offset - b.offset);
344
+ for (const [i, e] of byOffset.entries()) {
345
+ const limit = byOffset[i + 1]?.offset ?? directoryStart;
346
+ if (e.offset + LOCAL_SIZE + (locals.get(e)?.name.length ?? 0) + e.compressedSize > limit) throw new ZipError(`${e.path} overlaps the next entry or the central directory`);
347
+ bounds.set(e, limit);
348
+ }
349
+ return {
350
+ entries,
351
+ get: (path) => byPath.get(path),
352
+ read: async (entry) => {
353
+ const limit = bounds.get(entry);
354
+ const local = locals.get(entry);
355
+ if (limit === void 0 || !local) throw new ZipError(`${entry.path} isn't this zip's entry`);
356
+ return readEntry(source, entry, local, limit);
357
+ }
358
+ };
359
+ }
360
+ function zip64Values(extra, path) {
361
+ for (let at = 0; at + 4 <= extra.length;) {
362
+ const id = extra.readUInt16LE(at);
363
+ const length = extra.readUInt16LE(at + 2);
364
+ if (at + 4 + length > extra.length) throw new ZipError(`${path}'s extra field is cut short`);
365
+ if (id === ZIP64_EXTRA) {
366
+ const values = [];
367
+ for (let i = 0; i + 8 <= length; i += 8) values.push(u64(extra, at + 4 + i, `${path}'s zip64 size`));
368
+ return values;
369
+ }
370
+ at += 4 + length;
371
+ }
372
+ throw new ZipError(`${path} has no zip64 extra field`);
373
+ }
374
+ async function readEntry(source, entry, central, limit) {
375
+ const header = await readExactly(source, entry.offset, LOCAL_SIZE, `${entry.path}'s header`);
376
+ if (header.readUInt32LE(0) !== LOCAL) throw new ZipError(`${entry.path}'s local header is missing`);
377
+ const nameLength = header.readUInt16LE(26);
378
+ if (!(await readExactly(source, entry.offset + LOCAL_SIZE, nameLength, entry.path)).equals(central.name) || header.readUInt16LE(8) !== central.code || header.readUInt16LE(6) & ENCRYPTED) throw new ZipError(`${entry.path}'s local header doesn't match its central directory entry`);
379
+ const dataAt = entry.offset + LOCAL_SIZE + nameLength + header.readUInt16LE(28);
380
+ if (dataAt + entry.compressedSize > limit) throw new ZipError(`${entry.path} overlaps the next entry or the central directory`);
381
+ if (entry.method === "store" && entry.compressedSize !== entry.size) throw new ZipError(`${entry.path} is stored as ${entry.compressedSize} bytes, not the ${entry.size} its entry says`);
382
+ const body = await readExactly(source, dataAt, entry.compressedSize, entry.path);
383
+ let data;
384
+ if (entry.method === "store") data = body;
385
+ else try {
386
+ data = inflateRawSync(body, { maxOutputLength: Math.max(entry.size, 1) });
387
+ } catch (error) {
388
+ throw new ZipError(`${entry.path} doesn't inflate: ${error.message}`);
389
+ }
390
+ if (data.length !== entry.size) throw new ZipError(`${entry.path} is ${data.length} bytes, not the ${entry.size} its entry says`);
391
+ if (crc32Of(data) !== entry.crc32) throw new ZipError(`${entry.path} doesn't match its CRC-32`);
392
+ return data;
393
+ }
394
+ // src/archive/index.ts
395
+ /** The manifest's path in the archive. */
396
+ const MANIFEST_FILE = "reeval-archive.json";
397
+ /** The largest manifest `openArchive` reads, far past a run of a hundred thousand files. */
398
+ const MAX_MANIFEST_BYTES = 64 * 2 ** 20;
399
+ /** Formats that are compressed already, which an archive stores rather than deflates. */
400
+ const COMPRESSED = /\.(?:png|jpe?g|gif|webp|avif|zip|gz|tgz|zst|br|xz|bz2|mp4|webm|woff2?)$/i;
401
+ /** An archive that can't be written as asked, or doesn't read as one. */
402
+ var ArchiveError = class extends Error {
403
+ name = "ArchiveError";
404
+ };
405
+ /** `20260924T152700Z` of a run id, as a date. */
406
+ function runStart(runId) {
407
+ const m = /^(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})Z_/.exec(runId);
408
+ if (!m || !RUN_ID.test(runId)) throw new ArchiveError(`${runId} isn't a run id`);
409
+ const [, y, mo, d, h, mi, s] = m.map(Number);
410
+ return new Date(Date.UTC(y, mo - 1, d, h, mi, s));
411
+ }
412
+ const recordPath = (runId) => `${runId}.json`;
413
+ /** Whether `path` belongs in an archive of `contents`: the record, or a file under the run. */
414
+ const inLayout = (contents, runId, path) => path.startsWith(`${runId}/`) || contents === "run" && path === recordPath(runId);
415
+ async function writeAll(handle, bytes) {
416
+ for (let at = 0; at < bytes.length;) {
417
+ const { bytesWritten } = await handle.write(bytes, at, bytes.length - at);
418
+ at += bytesWritten;
419
+ }
420
+ }
421
+ /**
422
+ * Writes `file`, an archive of `options.files`, through a temporary file renamed into place, so
423
+ * the archive is either all there or not there. Returns its manifest.
424
+ */
425
+ async function writeArchive(file, options) {
426
+ const { contents, runId } = options;
427
+ const mtime = runStart(runId);
428
+ if (contents === "debug" && !options.debugLevel) throw new ArchiveError(`a debug archive of ${runId} needs its debug level`);
429
+ if (contents === "run" && options.debugLevel) throw new ArchiveError(`a run archive of ${runId} has no debug level`);
430
+ const inputs = [...options.files].sort((a, b) => a.path < b.path ? -1 : a.path > b.path ? 1 : 0);
431
+ for (const [i, input] of inputs.entries()) {
432
+ if (safeZipPath(input.path) !== input.path) throw new ArchiveError(`${input.path} isn't a relative path in the archive`);
433
+ if (!inLayout(contents, runId, input.path)) throw new ArchiveError(`${input.path} doesn't belong in a ${contents} archive of ${runId}: ${contents === "run" ? `only ${recordPath(runId)} and` : "only"} files under ${runId}/ do`);
434
+ if (inputs[i - 1]?.path === input.path) throw new ArchiveError(`${input.path} is given twice`);
435
+ }
436
+ if (contents === "run" && inputs[0]?.path !== recordPath(runId)) throw new ArchiveError(`a run archive of ${runId} needs its record, ${recordPath(runId)}`);
437
+ const tmp = join(dirname(file), `.tmp-${randomBytes(6).toString("hex")}-${basename(file)}`);
438
+ const handle = await open(tmp, "wx");
439
+ let landed = false;
440
+ try {
441
+ const zip = new ZipWriter((bytes) => writeAll(handle, bytes), {
442
+ mtime,
443
+ zip64: options.zip64 ?? "auto"
444
+ });
445
+ const files = [];
446
+ for (const input of inputs) {
447
+ const data = typeof input.data === "function" ? await input.data() : input.data;
448
+ files.push({
449
+ path: input.path,
450
+ sha256: sha256(data),
451
+ bytes: data.length
452
+ });
453
+ await zip.add(input.path, data, COMPRESSED.test(input.path) ? "store" : "deflate");
454
+ }
455
+ const manifest = {
456
+ kind: "reeval-archive",
457
+ schemaVersion: 1,
458
+ contents,
459
+ runId,
460
+ revision: options.revision ?? 1,
461
+ reeval: PACKAGE_VERSION,
462
+ createdAt: options.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
463
+ ...options.debugLevel ? { debugLevel: options.debugLevel } : {},
464
+ files
465
+ };
466
+ await zip.add(MANIFEST_FILE, Buffer.from(`${JSON.stringify(manifest, null, 2)}\n`));
467
+ await zip.finish();
468
+ await handle.sync();
469
+ await handle.close();
470
+ await rename(tmp, file);
471
+ landed = true;
472
+ await syncDir(dirname(file));
473
+ return manifest;
474
+ } finally {
475
+ if (!landed) {
476
+ await handle.close().catch(() => {});
477
+ await rm(tmp, { force: true });
478
+ }
479
+ }
480
+ }
481
+ /** The rename's directory entry, flushed where the platform lets a directory be opened. */
482
+ async function syncDir(dir) {
483
+ const handle = await open(dir, "r").catch(() => null);
484
+ await handle?.sync().catch(() => {}).finally(() => handle.close().catch(() => {}));
485
+ }
486
+ /**
487
+ * What `openArchive` relies on. A field or a `debugLevel` a newer reeval added passes, as other
488
+ * readers ignore what they don't know; `contents` it doesn't know isn't an archive it can read.
489
+ */
490
+ const manifestSchema = z.looseObject({
491
+ kind: z.literal("reeval-archive"),
492
+ schemaVersion: z.literal(1),
493
+ contents: z.enum(["run", "debug"]),
494
+ runId: z.string().regex(RUN_ID, "must be a run id"),
495
+ revision: z.number().int().min(1),
496
+ reeval: z.string(),
497
+ createdAt: z.string(),
498
+ debugLevel: z.string().optional(),
499
+ files: z.array(z.object({
500
+ path: z.string(),
501
+ sha256: z.string().regex(/^[0-9a-f]{64}$/, "must be a sha256 in hex"),
502
+ bytes: z.number().int().min(0)
503
+ }))
504
+ });
505
+ /**
506
+ * Opens an archive: a file, or any `ZipSource`. Refuses one whose manifest is missing or doesn't
507
+ * fit, or whose entries aren't the manifest's files; a manifest from a newer reeval throws a
508
+ * `NewerSchemaError`.
509
+ */
510
+ async function openArchive(from, what) {
511
+ const name = what ?? (typeof from === "string" ? from : "The archive");
512
+ const file = typeof from === "string" ? await fileSource(from) : null;
513
+ const source = file ?? from;
514
+ try {
515
+ const zip = await readZip(source).catch((error) => {
516
+ throw error instanceof ZipError ? new ArchiveError(`${name} isn't a readable zip: ${error.message}`) : error;
517
+ });
518
+ const manifest = await readManifest(zip, name);
519
+ return {
520
+ manifest,
521
+ ...reader(zip, manifest, name),
522
+ close: async () => file?.close()
523
+ };
524
+ } catch (error) {
525
+ await file?.close();
526
+ throw error;
527
+ }
528
+ }
529
+ async function readManifest(zip, name) {
530
+ const entry = zip.get(MANIFEST_FILE);
531
+ if (!entry) throw new ArchiveError(`${name} has no ${MANIFEST_FILE}, so it isn't a reeval archive`);
532
+ if (Math.max(entry.size, entry.compressedSize) > MAX_MANIFEST_BYTES) {
533
+ const bytes = Math.max(entry.size, entry.compressedSize);
534
+ throw new ArchiveError(`${name}'s ${MANIFEST_FILE} is ${bytes} bytes, too large to read`);
535
+ }
536
+ let value;
537
+ try {
538
+ value = JSON.parse((await zip.read(entry)).toString("utf8"));
539
+ } catch (error) {
540
+ throw new ArchiveError(`${name}'s ${MANIFEST_FILE} doesn't read: ${error.message}`);
541
+ }
542
+ if (value?.kind !== "reeval-archive") throw new ArchiveError(`${name}'s ${MANIFEST_FILE} isn't a reeval archive manifest`);
543
+ const parsed = manifestSchema.safeParse(readableArchiveManifest(value, name));
544
+ if (!parsed.success) {
545
+ const issue = parsed.error.issues[0];
546
+ throw new ArchiveError(`${name}'s ${MANIFEST_FILE} doesn't fit: ${issue?.path.join(".") || "(root)"} ${issue?.message}`);
547
+ }
548
+ const manifest = parsed.data;
549
+ const { contents, runId } = manifest;
550
+ const listed = /* @__PURE__ */ new Set();
551
+ for (const f of manifest.files) {
552
+ if (f.path === "reeval-archive.json" || !inLayout(contents, runId, f.path)) throw new ArchiveError(`${name} lists ${f.path}, which doesn't belong in a ${contents} archive`);
553
+ if (listed.has(f.path)) throw new ArchiveError(`${name} lists ${f.path} twice`);
554
+ listed.add(f.path);
555
+ const entry = zip.get(f.path);
556
+ if (!entry) throw new ArchiveError(`${name} lists ${f.path}, which isn't in the zip`);
557
+ if (entry.size !== f.bytes) throw new ArchiveError(`${name}'s ${f.path} is ${entry.size} bytes in the zip, not the ${f.bytes} its manifest says`);
558
+ }
559
+ const extra = zip.entries.find((e) => e.path !== "reeval-archive.json" && !listed.has(e.path));
560
+ if (extra) throw new ArchiveError(`${name} holds ${extra.path}, which its manifest doesn't list`);
561
+ if (contents === "run" && !listed.has(recordPath(runId))) throw new ArchiveError(`${name} has no record, ${recordPath(runId)}`);
562
+ return manifest;
563
+ }
564
+ function reader(zip, manifest, name) {
565
+ const files = new Map(manifest.files.map((f) => [f.path, f]));
566
+ const read = async (path) => {
567
+ const f = files.get(path);
568
+ const entry = zip.get(path);
569
+ if (!f || !entry) throw new ArchiveError(`${name} has no ${path}`);
570
+ let data;
571
+ try {
572
+ data = await zip.read(entry);
573
+ } catch (error) {
574
+ if (error instanceof ZipError) throw new ArchiveError(`${name}: ${error.message}`);
575
+ throw error;
576
+ }
577
+ if (sha256(data) !== f.sha256) throw new ArchiveError(`${name}'s ${path} doesn't match the hash in its manifest`);
578
+ return data;
579
+ };
580
+ return {
581
+ has: (path) => files.has(path),
582
+ read,
583
+ verify: async () => {
584
+ for (const f of manifest.files) await read(f.path);
585
+ }
586
+ };
587
+ }
588
+ // src/history/ignore.ts
589
+ /**
590
+ * Un-ignores recorded artifacts. A parent `*.log` would otherwise drop `setup.log` and
591
+ * `checks/<n>.log` when someone `git add`s the history folder. Ignores the `.tmp-*` files a
592
+ * write keeps there while it runs, such as a claim a crashed write left.
593
+ */
594
+ const HISTORY_GITIGNORE = `# Un-ignore recorded files. A parent *.log drops setup.log and checks/*.log.
595
+ !*.json
596
+ !*.zip
597
+ !*.jsonl
598
+ !*.md
599
+ !*.patch
600
+ !*.log
601
+ # A write in progress, or one cut short: never part of history.
602
+ .tmp-*
603
+ `;
604
+ /**
605
+ * Marks recorded runs generated, so GitHub collapses them in a pull request's diff, and their
606
+ * archives binary, so git never diffs or merges one as text. Matches run ids (`RUN_ID`) only:
607
+ * `history.dir` may be a folder that holds other files too.
608
+ */
609
+ const HISTORY_GITATTRIBUTES = `# Recorded runs: GitHub collapses them in a pull request's diff.
610
+ /[0-9]*T[0-9]*Z_*.json linguist-generated=true
611
+ /[0-9]*T[0-9]*Z_*/** linguist-generated=true
612
+ /[0-9]*T[0-9]*Z_*.zip binary linguist-generated=true
613
+ `;
614
+ const historyGitignorePath = (historyDir) => join(historyDir, ".gitignore");
615
+ const historyGitattributesPath = (historyDir) => join(historyDir, ".gitattributes");
616
+ async function ensureFile(historyDir, path, content) {
617
+ try {
618
+ await readFile(path);
619
+ } catch (error) {
620
+ if (error.code !== "ENOENT") throw error;
621
+ await mkdir(historyDir, { recursive: true });
622
+ await writeFile(path, content);
623
+ }
624
+ return path;
625
+ }
626
+ /**
627
+ * Writes `content` to `path`, or adds the rules of `content` an existing file lacks, keeping
628
+ * what's there: the whole block when it has none of them.
629
+ */
630
+ async function ensureRules(historyDir, path, content) {
631
+ let existing;
632
+ try {
633
+ existing = await readFile(path, "utf8");
634
+ } catch (error) {
635
+ if (error.code !== "ENOENT") throw error;
636
+ return ensureFile(historyDir, path, content);
637
+ }
638
+ const lines = new Set(existing.split(/\r?\n/).map((l) => l.trim()));
639
+ const rules = content.split("\n").filter((l) => l && !l.startsWith("#"));
640
+ const missing = rules.filter((r) => !lines.has(r));
641
+ if (missing.length === 0) return path;
642
+ const eol = existing.includes("\r\n") ? "\r\n" : "\n";
643
+ const gap = existing === "" || existing.endsWith("\n") ? "" : eol;
644
+ const added = missing.length === rules.length ? content : `${missing.join("\n")}\n`;
645
+ await writeFile(path, `${existing}${gap}${added.replaceAll("\n", eol)}`);
646
+ return path;
647
+ }
648
+ /**
649
+ * Writes the history-folder `.gitignore` when it's missing. An existing one is the user's: a
650
+ * later `!` rule would undo their own ignores, so it only gains `!*.zip` when runs are archived.
651
+ */
652
+ async function ensureHistoryGitignore(historyDir, archive) {
653
+ const path = historyGitignorePath(historyDir);
654
+ if (!existsSync(path)) return ensureFile(historyDir, path, HISTORY_GITIGNORE);
655
+ return archive ? ensureRules(historyDir, path, "!*.zip\n") : path;
656
+ }
657
+ /** Writes the history-folder `.gitattributes`, or adds the rules of `HISTORY_GITATTRIBUTES` it lacks. */
658
+ const ensureHistoryGitattributes = (historyDir) => ensureRules(historyDir, historyGitattributesPath(historyDir), HISTORY_GITATTRIBUTES);
659
+ /** `git check-ignore -v` one line: `<source>:<line>:<pattern><TAB><pathname>`. */
660
+ function parseCheckIgnore(line) {
661
+ const tab = line.indexOf(" ");
662
+ if (tab < 0) return null;
663
+ const meta = line.slice(0, tab);
664
+ const pathname = line.slice(tab + 1);
665
+ const match = meta.match(/^(.*):(\d+):(.*)$/);
666
+ if (!match) return null;
667
+ const [, source, lineNo, rule] = match;
668
+ if (!source || !rule) return null;
669
+ if (rule.startsWith("!")) return null;
670
+ return {
671
+ path: pathname,
672
+ rule,
673
+ source: `${source}:${lineNo}`
674
+ };
675
+ }
676
+ /**
677
+ * Files among `files` that git would ignore (so `git add` of the history folder would drop them).
678
+ * Empty when this isn't a git repo or git can't tell.
679
+ */
680
+ async function ignoredRecordedFiles(root, files) {
681
+ if (files.length === 0) return [];
682
+ const top = await repoTop(root);
683
+ if (!top) return [];
684
+ const r = await git(top, [
685
+ "check-ignore",
686
+ "-v",
687
+ "--no-index",
688
+ "--stdin"
689
+ ], { input: `${files.map((f) => relativeFile(top, f)).join("\n")}\n` });
690
+ if (r.code !== 0) return [];
691
+ return r.stdout.toString("utf8").split("\n").filter(Boolean).flatMap((line) => {
692
+ const parsed = parseCheckIgnore(line);
693
+ if (!parsed) return [];
694
+ const abs = isAbsolute(parsed.path) ? parsed.path : join(top, parsed.path);
695
+ return [{
696
+ ...parsed,
697
+ path: fromCwd(abs)
698
+ }];
699
+ });
700
+ }
701
+ // src/history/secret-scan.ts
702
+ /** Findings shown per file; the rest are counted. */
703
+ const SHOWN = 5;
704
+ const HUNK = /^@@ -\d+(?:,\d+)? \+(\d+)(?:,\d+)? @@/;
705
+ /** Where line `lineIndex` of a `git diff` falls: the file it changes, and its line in the new version. */
706
+ function inPatch(lines, lineIndex) {
707
+ let file = null;
708
+ let next = null;
709
+ for (let i = 0; i <= lineIndex; i++) {
710
+ const text = lines[i];
711
+ if (text.startsWith("diff --git ")) {
712
+ let end = i + 1;
713
+ while (end < lines.length && !/^(@@|diff --git )/.test(lines[end])) end++;
714
+ file = patchPath(lines.slice(i, end).join("\n"));
715
+ next = null;
716
+ continue;
717
+ }
718
+ const hunk = HUNK.exec(text);
719
+ if (hunk) {
720
+ next = Number(hunk[1]);
721
+ continue;
722
+ }
723
+ if (next === null) continue;
724
+ if (i === lineIndex) return {
725
+ file,
726
+ line: text.startsWith("-") ? null : next
727
+ };
728
+ if (!text.startsWith("-") && !text.startsWith("\\")) next++;
729
+ }
730
+ return {
731
+ file,
732
+ line: null
733
+ };
734
+ }
735
+ const JSON_FILE = /\.(?:json|jsonl|ndjson)$/;
736
+ /**
737
+ * Every secret-looking stretch of `text`, placed: by file and line inside a patch, else by line.
738
+ * In a JSON file, only what redaction masks: its strings.
739
+ */
740
+ function scanText(path, text) {
741
+ const matches = JSON_FILE.test(path) ? findSecretsInJson(text) : findSecrets(text);
742
+ if (matches.length === 0) return [];
743
+ const lines = text.split("\n");
744
+ const starts = [];
745
+ let at = 0;
746
+ for (const line of lines) {
747
+ starts.push(at);
748
+ at += line.length + 1;
749
+ }
750
+ const lineOf = (offset) => {
751
+ let lo = 0;
752
+ let hi = starts.length - 1;
753
+ while (lo < hi) {
754
+ const mid = lo + hi + 1 >> 1;
755
+ if (starts[mid] <= offset) lo = mid;
756
+ else hi = mid - 1;
757
+ }
758
+ return lo;
759
+ };
760
+ const patch = path.endsWith(".patch");
761
+ return matches.map((m) => {
762
+ const index = lineOf(m.start);
763
+ return {
764
+ ...patch ? inPatch(lines, index) : {
765
+ file: null,
766
+ line: index + 1
767
+ },
768
+ what: maskedMatch(text, m),
769
+ rule: m.rule
770
+ };
771
+ });
772
+ }
773
+ const place = (f) => [f.file, f.line === null ? null : `line ${f.line}`].filter(Boolean).join(" ");
774
+ /** `<label> line <n>: <what>`, or `<label>: <file> line <n>: <what>` in a patch, a few per file. */
775
+ function findingLines(label, findings) {
776
+ const out = findings.slice(0, SHOWN).map((f) => {
777
+ const where = place(f);
778
+ if (!where) return `${label}: ${f.what}`;
779
+ return `${label}${f.file ? ": " : " "}${where}: ${f.what}`;
780
+ });
781
+ if (findings.length > SHOWN) out.push(`${label}: and ${findings.length - SHOWN} more`);
782
+ return out;
783
+ }
784
+ /** The findings as a recordable note: where, and which rule, never any part of the value. */
785
+ function findingSummary(findings) {
786
+ const shown = findings.slice(0, 3).map((f) => {
787
+ const where = place(f);
788
+ return `${where ? `${where}: ` : ""}${f.rule}`;
789
+ });
790
+ const more = findings.length > 3 ? `, and ${findings.length - 3} more` : "";
791
+ return `${shown.join("; ")}${more}`;
792
+ }
793
+ // src/history/files.ts
794
+ var HistoryError = class extends Error {
795
+ name = "HistoryError";
796
+ };
797
+ /** A record from a newer reeval: skipped with a warning to upgrade, never "restore or delete it". */
798
+ var NewerRecordError = class extends HistoryError {
799
+ reason;
800
+ constructor(error) {
801
+ super(error.message);
802
+ this.reason = error.reason;
803
+ }
804
+ };
805
+ /** Where `reeval run` writes runs before they're recorded. Gitignored. */
806
+ const scratchDir = (root) => join(root, ".reeval", "runs");
807
+ const cacheFile = (root) => join(root, ".reeval", "history-cache.json");
808
+ const TEXT_FILE = /\.(json|jsonl|md|patch|log|txt)$/;
809
+ const isMissing = (error) => error.code === "ENOENT";
810
+ /**
811
+ * A file another process is writing, renaming or removing right now: Windows refuses to open or
812
+ * replace one that's open elsewhere (EPERM, EBUSY). It reads fine on a later try.
813
+ */
814
+ const inFlux = (error) => [
815
+ "ENOENT",
816
+ "EPERM",
817
+ "EBUSY"
818
+ ].includes(error.code ?? "");
819
+ const tmpName = () => `${process.pid}-${randomBytes(6).toString("hex")}`;
820
+ const encodeRecord = (record) => Buffer.from(`${JSON.stringify(record, null, 2)}\n`);
821
+ function parseRecord(bytes, where) {
822
+ const value = JSON.parse(Buffer.from(bytes).toString("utf8"));
823
+ if (value?.kind !== "reeval-run") throw new HistoryError(`${where} is not a reeval run record`);
824
+ try {
825
+ return readableRecord(value, where);
826
+ } catch (error) {
827
+ if (error instanceof NewerSchemaError) throw new NewerRecordError(error);
828
+ throw error;
829
+ }
830
+ }
831
+ async function readRecord(path) {
832
+ return parseRecord(await readFile(path), path);
833
+ }
834
+ const warnedUnreadable = /* @__PURE__ */ new Set();
835
+ /**
836
+ * Says once per process that a run-named file isn't a readable record, so a run lost to a bad
837
+ * merge or a cut-short copy doesn't silently drop out of history, compare's base and queries.
838
+ */
839
+ function warnUnreadable(path, error) {
840
+ if (warnedUnreadable.has(path)) return;
841
+ warnedUnreadable.add(path);
842
+ if (error instanceof NewerRecordError) {
843
+ process.stderr.write(`warning: skipped ${fromCwd(path)}: ${error.reason}\n`);
844
+ return;
845
+ }
846
+ const why = error instanceof Error ? error.message : String(error);
847
+ process.stderr.write(`warning: skipped ${fromCwd(path)}: not a readable reeval run record (${why}). Restore it from git, or delete it.\n`);
848
+ }
849
+ /** A run's record file in a history or scratch folder. */
850
+ const recordFile = (dir, runId) => join(dir, `${runId}.json`);
851
+ /** A run's artifact directory in a history or scratch folder. */
852
+ const runDir = (dir, runId) => join(dir, runId);
853
+ /** The top-level `.json` names in `dir` (records land last and whole), sorted; null if it's missing. */
854
+ async function recordNames(dir) {
855
+ try {
856
+ return (await readdir(dir)).filter((n) => n.endsWith(".json") && !n.startsWith(".")).sort();
857
+ } catch (error) {
858
+ if (isMissing(error)) return null;
859
+ throw error;
860
+ }
861
+ }
862
+ /**
863
+ * The newest `limit` records across `dirs`, by file name (= start time), oldest first. Files that
864
+ * aren't readable records are skipped: these feed estimates, not results.
865
+ */
866
+ async function recentRecords(dirs, limit) {
867
+ const paths = [];
868
+ for (const dir of dirs) {
869
+ const names = await recordNames(dir).catch(() => null) ?? [];
870
+ paths.push(...names.map((n) => join(dir, n)));
871
+ }
872
+ const recent = paths.sort((a, b) => (a.split("/").at(-1) ?? "").localeCompare(b.split("/").at(-1) ?? "")).slice(-limit);
873
+ const records = [];
874
+ for (const path of recent) try {
875
+ records.push(await readRecord(path));
876
+ } catch {}
877
+ return records;
878
+ }
879
+ const BUILD = BUILD_ID;
880
+ async function readCache(root) {
881
+ try {
882
+ const parsed = JSON.parse(await readFile(cacheFile(root), "utf8"));
883
+ if (parsed.build === BUILD && parsed.files) return parsed;
884
+ } catch {}
885
+ return {
886
+ build: BUILD,
887
+ files: {}
888
+ };
889
+ }
890
+ /**
891
+ * Every run in `dir`, sorted by file name (= start time). Derived from the folder listing on
892
+ * every read; parsed records are cached in `.reeval/` by size and mtime, and never committed.
893
+ */
894
+ async function listRuns(root, dir, recorded) {
895
+ const names = (await recordNames(dir) ?? []).filter((n) => RUN_ID.test(n.slice(0, -5)));
896
+ if (names.length === 0) return [];
897
+ const cache = await readCache(root);
898
+ let changed = false;
899
+ const entries = [];
900
+ for (const name of names) {
901
+ const path = join(dir, name);
902
+ const key = relativeFile(root, path);
903
+ try {
904
+ const info = await stat(path);
905
+ const hit = cache.files[key];
906
+ if (hit && hit.size === info.size && hit.mtimeMs === info.mtimeMs) {
907
+ entries.push(hit.entry);
908
+ continue;
909
+ }
910
+ const entry = runHeader(await readRecord(path), recorded);
911
+ cache.files[key] = {
912
+ size: info.size,
913
+ mtimeMs: info.mtimeMs,
914
+ entry
915
+ };
916
+ entries.push(entry);
917
+ changed = true;
918
+ } catch (error) {
919
+ if (inFlux(error)) continue;
920
+ if (!(error instanceof HistoryError) && !(error instanceof SyntaxError)) throw error;
921
+ warnUnreadable(path, error);
922
+ }
923
+ }
924
+ if (changed) await writeCache(root, cache);
925
+ return entries;
926
+ }
927
+ /**
928
+ * Best-effort: another reader (a studio serving parallel requests, a second `reeval`) may be
929
+ * replacing the same file, which Windows refuses. The cache is only a speed-up.
930
+ */
931
+ async function writeCache(root, cache) {
932
+ const tmp = `${cacheFile(root)}.${tmpName()}`;
933
+ try {
934
+ await mkdir(dirname(cacheFile(root)), { recursive: true });
935
+ await writeFile(tmp, JSON.stringify(cache));
936
+ await rename(tmp, cacheFile(root));
937
+ } catch {
938
+ await rm(tmp, { force: true }).catch(() => {});
939
+ }
940
+ }
941
+ /**
942
+ * `<dir>/.tmp-<runId>.claim`: whoever creates it owns `<dir>/<runId>/` and `<dir>/<runId>.json`
943
+ * until it's removed. It holds `<pid>\n<host>\n<token>\n`, linked into place whole.
944
+ */
945
+ const claimFile = (dir, runId) => join(dir, `.tmp-${runId}.claim`);
946
+ const busy = (runId, file) => new HistoryError(`${runId} is being recorded by another process right now. Try again once it finishes; if no reeval is running, delete ${fromCwd(file)}.`);
947
+ /** A claim whose process is gone on this host. Another host's can't be probed, so it holds. */
948
+ function claimGone(held) {
949
+ const [pidLine, host] = held.split("\n");
950
+ const pid = Number(pidLine);
951
+ if (!Number.isInteger(pid) || pid <= 0 || !host) return true;
952
+ if (host !== hostname()) return false;
953
+ try {
954
+ process.kill(pid, 0);
955
+ return false;
956
+ } catch (error) {
957
+ return error.code === "ESRCH";
958
+ }
959
+ }
960
+ /**
961
+ * Removes the stale claim `held`, and only it. Breakers of one claim take
962
+ * `<claim>.<hash of held>.break` first, so only one at a time may unlink it; while `held` is in
963
+ * place nobody else can remove or replace it, so reading it then unlinking it is safe.
964
+ */
965
+ async function breakClaim(file, held, runId) {
966
+ const lock = `${file}.${sha256(held).slice(0, 12)}.break`;
967
+ try {
968
+ await writeFile(lock, "", { flag: "wx" });
969
+ } catch (error) {
970
+ if (error.code === "EEXIST" || inFlux(error)) throw busy(runId, file);
971
+ throw error;
972
+ }
973
+ try {
974
+ let now;
975
+ try {
976
+ now = await readFile(file, "utf8");
977
+ } catch (error) {
978
+ if (isMissing(error)) return;
979
+ if (inFlux(error)) throw busy(runId, file);
980
+ throw error;
981
+ }
982
+ if (now === held) await unlink(file);
983
+ } finally {
984
+ await unlink(lock).catch(() => {});
985
+ }
986
+ }
987
+ /** Takes `runId`'s claim in `dir`, breaking one a dead process left; returns its release. */
988
+ async function claimRun(dir, runId) {
989
+ const file = claimFile(dir, runId);
990
+ const body = `${process.pid}\n${hostname()}\n${randomBytes(6).toString("hex")}\n`;
991
+ const tmp = `${file}.${tmpName()}`;
992
+ await writeFile(tmp, body);
993
+ try {
994
+ for (let tries = 0; tries < 3; tries++) {
995
+ try {
996
+ await link(tmp, file);
997
+ return async () => {
998
+ if (await readFile(file, "utf8").catch(() => null) === body) await unlink(file).catch(() => {});
999
+ };
1000
+ } catch (error) {
1001
+ if (![
1002
+ "EEXIST",
1003
+ "EPERM",
1004
+ "EBUSY"
1005
+ ].includes(error.code ?? "")) throw error;
1006
+ }
1007
+ let held;
1008
+ try {
1009
+ held = await readFile(file, "utf8");
1010
+ } catch (error) {
1011
+ if (isMissing(error)) continue;
1012
+ if (inFlux(error)) throw busy(runId, file);
1013
+ throw error;
1014
+ }
1015
+ if (!claimGone(held)) throw busy(runId, file);
1016
+ await breakClaim(file, held, runId);
1017
+ }
1018
+ throw busy(runId, file);
1019
+ } finally {
1020
+ await unlink(tmp).catch(() => {});
1021
+ }
1022
+ }
1023
+ /**
1024
+ * A record its continuation replaces: the run stopped before it finished, or `next` ran one of
1025
+ * its infra errors again and keeps that error in the attempt's `retries`.
1026
+ */
1027
+ const replaceable = (bytes, where, next) => {
1028
+ try {
1029
+ const was = parseRecord(bytes, where);
1030
+ if (was.status === "interrupted" || was.status === "budget") return true;
1031
+ const now = parseRecord(next, where);
1032
+ const retried = new Map(now.evals.flatMap((e) => e.attempts).map((a) => [a.key, a.retries ?? []]));
1033
+ return was.evals.flatMap((e) => e.attempts).some((a) => a.outcome === "infra_error" && retried.get(a.key)?.some((r) => r.at === a.startedAt && r.error.message === a.error?.message));
1034
+ } catch {
1035
+ return false;
1036
+ }
1037
+ };
1038
+ const readIfThere = (path) => readFile(path).catch((error) => {
1039
+ if (isMissing(error)) return null;
1040
+ throw error;
1041
+ });
1042
+ /**
1043
+ * Claims the run, then writes `<dir>/<runId>/` (artifacts, and the snapshots `moves` brings in
1044
+ * by renaming), then `<dir>/<runId>.json` (the record). The record lands last and create-only, so a reader never sees a half-written run, and
1045
+ * a run is never rewritten, except an interrupted or budget-stopped one by its resumed run, and a
1046
+ * finished one by its `--retry-errors`.
1047
+ */
1048
+ async function writeRun(dir, record, artifacts, moves = /* @__PURE__ */ new Map()) {
1049
+ const recordPath = recordFile(dir, record.runId);
1050
+ const artifactDir = artifacts.size > 0 ? runDir(dir, record.runId) : null;
1051
+ const bytes = encodeRecord(record);
1052
+ if ((await readIfThere(recordPath))?.equals(bytes)) return {
1053
+ recordPath,
1054
+ artifactDir,
1055
+ created: false
1056
+ };
1057
+ await mkdir(dir, { recursive: true });
1058
+ const release = await claimRun(dir, record.runId);
1059
+ try {
1060
+ return await writeClaimed(dir, record.runId, bytes, artifacts, moves);
1061
+ } finally {
1062
+ await release();
1063
+ }
1064
+ }
1065
+ /** What most likely makes a run's new record differ from the recorded one, for the refusal. */
1066
+ function likelyChange(existing, bytes, runId) {
1067
+ const parse = (b) => {
1068
+ try {
1069
+ return JSON.parse(b.toString());
1070
+ } catch {
1071
+ return null;
1072
+ }
1073
+ };
1074
+ const [was, now] = [parse(existing), parse(bytes)];
1075
+ if (was && now && !isDeepStrictEqual(was.debug, now.debug)) {
1076
+ const { debug: _was, ...before } = was;
1077
+ const { debug: _now, ...after } = now;
1078
+ if (isDeepStrictEqual(before, after)) return `its debug data differs: .reeval/debug/${runId} was pruned or changed since it was recorded, or history.debug is another level`;
1079
+ }
1080
+ return "another --artifacts level?";
1081
+ }
1082
+ async function writeClaimed(dir, runId, bytes, artifacts, moves) {
1083
+ const recordPath = recordFile(dir, runId);
1084
+ const artifactDir = artifacts.size > 0 ? runDir(dir, runId) : null;
1085
+ const existing = await readIfThere(recordPath);
1086
+ if (existing?.equals(bytes)) return {
1087
+ recordPath,
1088
+ artifactDir,
1089
+ created: false
1090
+ };
1091
+ if (existing && !replaceable(existing, recordPath, bytes)) throw new HistoryError(`${runId} is already recorded with different content (${likelyChange(existing, bytes, runId)}). Recorded runs are never rewritten.`);
1092
+ const staging = artifactDir ? join(dir, `.tmp-${tmpName()}`) : null;
1093
+ try {
1094
+ if (staging) {
1095
+ for (const [path, content] of artifacts) {
1096
+ const file = join(staging, ...path.split("/"));
1097
+ await mkdir(dirname(file), { recursive: true });
1098
+ await writeFile(file, content);
1099
+ }
1100
+ for (const [path, source] of moves) {
1101
+ const target = join(staging, ...path.split("/"));
1102
+ await mkdir(dirname(target), { recursive: true });
1103
+ await rename(source, target);
1104
+ }
1105
+ }
1106
+ if (existing) {
1107
+ const old = join(dir, `.tmp-${tmpName()}`);
1108
+ const tmp = join(dir, `.tmp-${tmpName()}.json`);
1109
+ await writeFile(tmp, bytes);
1110
+ let moved = false;
1111
+ try {
1112
+ await rename(runDir(dir, runId), old).then(() => {
1113
+ moved = true;
1114
+ }, (error) => {
1115
+ if (error.code !== "ENOENT") throw error;
1116
+ });
1117
+ if (staging && artifactDir) await rename(staging, artifactDir);
1118
+ await rename(tmp, recordPath);
1119
+ } catch (error) {
1120
+ if (moved) {
1121
+ await rm(runDir(dir, runId), {
1122
+ recursive: true,
1123
+ force: true
1124
+ });
1125
+ await rename(old, runDir(dir, runId));
1126
+ }
1127
+ throw error;
1128
+ } finally {
1129
+ await rm(tmp, { force: true });
1130
+ }
1131
+ await rm(old, {
1132
+ recursive: true,
1133
+ force: true
1134
+ });
1135
+ return {
1136
+ recordPath,
1137
+ artifactDir,
1138
+ created: true
1139
+ };
1140
+ }
1141
+ await rm(runDir(dir, runId), {
1142
+ recursive: true,
1143
+ force: true
1144
+ });
1145
+ if (staging && artifactDir) await rename(staging, artifactDir);
1146
+ } finally {
1147
+ if (staging) await rm(staging, {
1148
+ recursive: true,
1149
+ force: true
1150
+ });
1151
+ }
1152
+ const tmp = join(dir, `.tmp-${tmpName()}.json`);
1153
+ await writeFile(tmp, bytes);
1154
+ try {
1155
+ await link(tmp, recordPath);
1156
+ } catch (error) {
1157
+ if (error.code === "EEXIST") throw new HistoryError(`${recordPath} was written by another process meanwhile`);
1158
+ throw error;
1159
+ } finally {
1160
+ await unlink(tmp).catch(() => {});
1161
+ }
1162
+ return {
1163
+ recordPath,
1164
+ artifactDir,
1165
+ created: true
1166
+ };
1167
+ }
1168
+ const failed = (x) => x.outcome === "fail" || x.outcome === "infra_error";
1169
+ /** Whether the attempt keeps its heavy evidence at this artifact level. */
1170
+ const keeps = (x, level) => level === "all" || level === "evidence" || level === "failures" && failed(x);
1171
+ /** Passing attempts under `evidence` drop transcript, setup, checks, and judge input. */
1172
+ const evidencePass = (a, level) => level === "evidence" && !failed(a);
1173
+ /** Each capture's PNG, then the page facts beside it. */
1174
+ const withPages = (refs) => refs.flatMap((r) => r.capture?.page ? [r, r.capture.page] : [r]);
1175
+ const attemptRefs = (a, level = "all") => {
1176
+ const files = evidencePass(a, level) ? {
1177
+ diff: a.files.diff,
1178
+ artifacts: a.files.artifacts
1179
+ } : a.files;
1180
+ return [
1181
+ ...Object.values(files).flatMap((v) => Array.isArray(v) ? withPages(v) : v ? [v] : []),
1182
+ ...evidencePass(a, level) ? [] : a.checks.flatMap((c) => c.log ? [c.log] : []),
1183
+ ...(a.answers ?? []).flatMap((q) => q.input ? [q.input] : [])
1184
+ ];
1185
+ };
1186
+ /** `<dir>/<runId>.zip`: a recorded run, its record and every file recorded with it, as one zip. */
1187
+ const archiveFile = (dir, runId) => join(dir, `${runId}.zip`);
1188
+ /** The whole of the run's `.reeval/debug/<runId>/` as its zip; none when it has no debug data. */
1189
+ async function archiveDebug(root, runId) {
1190
+ const dir = join(debugRoot(root), runId);
1191
+ if ((await pathsUnder(dir)).length === 0) return void 0;
1192
+ const release = await claimRun(debugRoot(root), runId);
1193
+ try {
1194
+ const files = [];
1195
+ for (const path of await pathsUnder(dir)) {
1196
+ const file = join(dir, ...path.split("/"));
1197
+ files.push({
1198
+ path: `${runId}/${path}`,
1199
+ sha256: await sha256File(file),
1200
+ data: () => readFile(file)
1201
+ });
1202
+ }
1203
+ if (files.length === 0) return void 0;
1204
+ return await freshArchive(debugArchiveFile(root, runId), {
1205
+ contents: "debug",
1206
+ runId,
1207
+ debugLevel: "all",
1208
+ files
1209
+ });
1210
+ } finally {
1211
+ await release();
1212
+ }
1213
+ }
1214
+ /** Every file under `dir`, by posix path, sorted. */
1215
+ async function pathsUnder(dir, at = "") {
1216
+ const entries = await readdir(join(dir, at), { withFileTypes: true }).catch(() => []);
1217
+ const out = [];
1218
+ for (const entry of entries) {
1219
+ const path = at ? `${at}/${entry.name}` : entry.name;
1220
+ if (entry.isDirectory()) out.push(...await pathsUnder(dir, path));
1221
+ else if (entry.isFile()) out.push(path);
1222
+ }
1223
+ return out.sort();
1224
+ }
1225
+ async function sha256File(file) {
1226
+ const hash = createHash("sha256");
1227
+ for await (const chunk of createReadStream(file)) hash.update(chunk);
1228
+ return hash.digest("hex");
1229
+ }
1230
+ /** What a run's archive holds of `<runId>/`: everything but what's added after recording. */
1231
+ const archived = (path) => !path.startsWith("analysis/");
1232
+ /**
1233
+ * Writes an archive of `files`, unless the one at `path` already lists exactly them. A missing
1234
+ * zip, or one that isn't a readable archive, is written at revision 1; one that lists other
1235
+ * files is written again a revision on. One a newer reeval wrote is left as it is.
1236
+ */
1237
+ async function freshArchive(path, options) {
1238
+ const wanted = new Map(options.files.map((f) => [f.path, "sha256" in f ? f.sha256 : sha256(f.data)]));
1239
+ let was = null;
1240
+ try {
1241
+ const archive = await openArchive(path);
1242
+ was = archive.manifest;
1243
+ await archive.close();
1244
+ } catch (error) {
1245
+ if (error instanceof NewerSchemaError) return {
1246
+ path,
1247
+ written: false
1248
+ };
1249
+ if (!isMissing(error) && !(error instanceof ArchiveError)) throw error;
1250
+ }
1251
+ const same = was?.files.length === wanted.size && was.files.every((f) => wanted.get(f.path) === f.sha256);
1252
+ if (was && same) return {
1253
+ path,
1254
+ written: false
1255
+ };
1256
+ await writeArchive(path, {
1257
+ ...options,
1258
+ revision: was ? was.revision + 1 : 1
1259
+ });
1260
+ return {
1261
+ path,
1262
+ written: true
1263
+ };
1264
+ }
1265
+ /**
1266
+ * The run's archive beside its record: under the run's claim, of the record and files as they
1267
+ * are in the folder, so it never holds what this reeval would write but didn't. Nothing when the
1268
+ * record there isn't `record` any more: another recording replaced it meanwhile and archives its
1269
+ * own.
1270
+ */
1271
+ async function archiveRun(dir, runId, record) {
1272
+ const release = await claimRun(dir, runId);
1273
+ try {
1274
+ const landed = await readIfThere(recordFile(dir, runId));
1275
+ if (!landed?.equals(record)) return void 0;
1276
+ return await freshArchive(archiveFile(dir, runId), {
1277
+ contents: "run",
1278
+ runId,
1279
+ files: await runArchiveFiles(dir, runId, landed)
1280
+ });
1281
+ } finally {
1282
+ await release();
1283
+ }
1284
+ }
1285
+ /**
1286
+ * A run archive's files as `runArchiveFiles` lists them, read under the run's claim so a
1287
+ * recording in progress can't mix two revisions; exit 2 while another process holds it.
1288
+ */
1289
+ async function readRunArchiveFiles(dir, runId) {
1290
+ const release = await claimRun(dir, runId);
1291
+ try {
1292
+ return await runArchiveFiles(dir, runId, await readFile(recordFile(dir, runId)));
1293
+ } finally {
1294
+ await release();
1295
+ }
1296
+ }
1297
+ /** What a run archive of `runId` holds: `record`, and the run's files in `dir` but `analysis/`. */
1298
+ async function runArchiveFiles(dir, runId, record) {
1299
+ const files = (await filesUnder(runDir(dir, runId))).filter(([path]) => archived(path));
1300
+ return [{
1301
+ path: `${runId}.json`,
1302
+ data: record
1303
+ }, ...files.map(([file, data]) => ({
1304
+ path: `${runId}/${file}`,
1305
+ data
1306
+ }))];
1307
+ }
1308
+ /** Every file under `dir`, by posix path, with its bytes. */
1309
+ async function filesUnder(dir, at = "") {
1310
+ const entries = await readdir(join(dir, at), { withFileTypes: true }).catch(() => []);
1311
+ const out = [];
1312
+ for (const entry of entries) {
1313
+ const path = at ? `${at}/${entry.name}` : entry.name;
1314
+ if (entry.isDirectory()) out.push(...await filesUnder(dir, path));
1315
+ else if (entry.isFile()) out.push([path, await readFile(join(dir, path))]);
1316
+ }
1317
+ return out;
1318
+ }
1319
+ const DEBUG_FILES = {
1320
+ requests: [REQUESTS_FILE],
1321
+ all: [
1322
+ REQUESTS_FILE,
1323
+ DEBUG_LOG,
1324
+ TRACE_FILE
1325
+ ]
1326
+ };
1327
+ /**
1328
+ * The run's debug data `level` names, from `.reeval/debug/<run>`, written to `staging` for the
1329
+ * upload; a file the secret scan finds something in is left out and named in `dropped`.
1330
+ */
1331
+ async function stageDebug(root, runId, options) {
1332
+ const wanted = DEBUG_FILES[options.level];
1333
+ const debug = {
1334
+ level: options.level,
1335
+ files: []
1336
+ };
1337
+ const dropped = [];
1338
+ await rm(options.staging, {
1339
+ recursive: true,
1340
+ force: true
1341
+ });
1342
+ for (const [path, bytes] of await filesUnder(join(debugRoot(root), runId))) {
1343
+ if (!wanted.includes(path.slice(path.lastIndexOf("/") + 1))) continue;
1344
+ const findings = scanText(path, Buffer.from(bytes).toString());
1345
+ if (findings.length > 0) {
1346
+ dropped.push({
1347
+ path,
1348
+ note: `${SECRET_NOTE} (${findingSummary(findings)})`
1349
+ });
1350
+ continue;
1351
+ }
1352
+ const file = join(options.staging, ...path.split("/"));
1353
+ await mkdir(dirname(file), { recursive: true });
1354
+ await writeFile(file, bytes);
1355
+ debug.files.push({
1356
+ path,
1357
+ sha256: sha256(bytes),
1358
+ bytes: bytes.length
1359
+ });
1360
+ }
1361
+ if (dropped.length) debug.dropped = dropped;
1362
+ return debug.files.length || dropped.length ? debug : void 0;
1363
+ }
1364
+ /** Why a patch that looked like it held a secret isn't in the record. Starts with `SECRET_NOTE`. */
1365
+ const SECRET_NOTE = "not kept: it looked like it held a secret";
1366
+ /** A file the run's record names, which must be there. */
1367
+ const runFile = (source, runId, path) => readFile(join(source, runId, ...path.split("/"))).catch((error) => {
1368
+ if (isMissing(error)) throw new HistoryError(`${runId}/${path} is missing`);
1369
+ throw error;
1370
+ });
1371
+ /** A record as compared for "already recorded with different content": its debug data aside. */
1372
+ const comparable = (record) => {
1373
+ const { debug: _, ...rest } = JSON.parse(encodeRecord(record).toString());
1374
+ return rest;
1375
+ };
1376
+ /** Why `dir`'s copy `run` isn't the run `recorded` is, rebuilt at its level; null when it is. */
1377
+ async function differs(dir, run, recorded, options) {
1378
+ if (run.status !== recorded.status) return `it's ${run.status}, the recorded run ${recorded.status}`;
1379
+ let rebuilt;
1380
+ try {
1381
+ rebuilt = (await leveled(dir, run, recorded.artifacts, {
1382
+ ...options,
1383
+ summary: false
1384
+ })).record;
1385
+ } catch (error) {
1386
+ if (error instanceof HistoryError) return error.message;
1387
+ throw error;
1388
+ }
1389
+ return isDeepStrictEqual(comparable(rebuilt), comparable(recorded)) ? null : "its record differs from the recorded one";
1390
+ }
1391
+ /**
1392
+ * The record and files a run in `source` keeps at `level`, as `recordRun` records them: each
1393
+ * file checked against its hash, the worktree patch left out when it looks like it holds a
1394
+ * secret (unless `skipSecretScan`), and the summary rendered for what's kept (unless `summary` is
1395
+ * false). Writes nothing.
1396
+ */
1397
+ async function leveled(source, run, level, options) {
1398
+ const { runId } = run;
1399
+ const record = structuredClone(run);
1400
+ record.artifacts = level;
1401
+ const files = /* @__PURE__ */ new Map();
1402
+ const keep = async (ref) => {
1403
+ const bytes = await runFile(source, runId, ref.path);
1404
+ if (sha256(bytes) !== ref.sha256) throw new HistoryError(`${runId}/${ref.path} changed since the run wrote it`);
1405
+ files.set(ref.path, bytes);
1406
+ return bytes;
1407
+ };
1408
+ for (const e of record.evals) {
1409
+ const shown = /* @__PURE__ */ new Set();
1410
+ for (const q of e.answers ?? []) {
1411
+ if (!q.input) continue;
1412
+ if (level === "none" || !keeps(e, level)) {
1413
+ delete q.input;
1414
+ continue;
1415
+ }
1416
+ const input = JSON.parse(Buffer.from(await keep(q.input)).toString());
1417
+ for (const s of input.calls.flatMap((c) => c.screenshots ?? [])) if ("path" in s && s.path) shown.add(s.path);
1418
+ }
1419
+ const whole = failed(e) && !e.attempts.some(failed);
1420
+ for (const a of e.attempts) {
1421
+ const cellFailed = e.attempts.some((b) => b.cell === a.cell && failed(b));
1422
+ const cell = e.cells.find((c) => c.key === a.cell);
1423
+ const all = whole || cell !== void 0 && failed(cell) && !cellFailed;
1424
+ if (level !== "none" && (all || keeps(a, level))) {
1425
+ for (const ref of attemptRefs(a, all ? "all" : level)) await keep(ref);
1426
+ if (evidencePass(a, level) && !all) {
1427
+ a.files = {
1428
+ ...a.files.diff ? { diff: a.files.diff } : {},
1429
+ ...a.files.artifacts?.length ? { artifacts: a.files.artifacts } : {}
1430
+ };
1431
+ for (const c of a.checks) delete c.log;
1432
+ }
1433
+ continue;
1434
+ }
1435
+ const caseFailed = e.attempts.some((b) => b.cell === a.cell && b.case === a.case && failed(b));
1436
+ const diff = level !== "none" && caseFailed ? a.files.diff : void 0;
1437
+ const screenshots = (a.files.artifacts ?? []).filter((r) => shown.has(r.path));
1438
+ a.files = {
1439
+ ...diff ? { diff } : {},
1440
+ ...screenshots.length ? { artifacts: screenshots } : {}
1441
+ };
1442
+ for (const ref of [...diff ? [diff] : [], ...withPages(screenshots)]) await keep(ref);
1443
+ for (const c of a.checks) delete c.log;
1444
+ for (const q of a.answers ?? []) delete q.input;
1445
+ }
1446
+ }
1447
+ const patch = record.git?.worktreePatch;
1448
+ let droppedPatch = [];
1449
+ let droppedPatchRules = [];
1450
+ if (patch && record.git && level !== "none") {
1451
+ const bytes = await runFile(source, runId, patch.path);
1452
+ if (sha256(bytes) !== patch.sha256) throw new HistoryError(`${runId}/${patch.path} changed since the run wrote it`);
1453
+ const findings = options.skipSecretScan ? [] : scanText(patch.path, bytes.toString());
1454
+ if (findings.length > 0) {
1455
+ droppedPatch = findingLines(patch.path, findings);
1456
+ droppedPatchRules = findingLines(patch.path, findings.map((f) => ({
1457
+ ...f,
1458
+ what: f.rule
1459
+ })));
1460
+ record.git.worktreePatch = null;
1461
+ record.git.worktreePatchNote = `${SECRET_NOTE} (${findingSummary(findings)})`;
1462
+ } else files.set(patch.path, bytes);
1463
+ } else if (patch && record.git) {
1464
+ record.git.worktreePatch = null;
1465
+ record.git.worktreePatchNote = "not kept: recorded with artifacts 'none'";
1466
+ }
1467
+ const remarkBytes = await readFile(join(source, runId, REMARKS_FILE)).catch(() => null);
1468
+ let remarks = null;
1469
+ if (remarkBytes) try {
1470
+ remarks = readableRemarks(JSON.parse(remarkBytes.toString()), REMARKS_FILE);
1471
+ files.set(REMARKS_FILE, remarkBytes);
1472
+ } catch {}
1473
+ if (record.spans) {
1474
+ const ref = record.spans;
1475
+ const bytes = level === "none" ? null : await readFile(join(source, runId, ...ref.path.split("/"))).catch(() => null);
1476
+ if (bytes && sha256(bytes) === ref.sha256) files.set(ref.path, bytes);
1477
+ else delete record.spans;
1478
+ }
1479
+ if (level !== "none" && options.summary !== false) {
1480
+ const facts = keptFacts(record, files);
1481
+ for (const [name, bytes] of summaryFiles(record, {
1482
+ remarks,
1483
+ facts
1484
+ })) files.set(name, bytes);
1485
+ }
1486
+ return {
1487
+ record,
1488
+ files,
1489
+ droppedPatch,
1490
+ droppedPatchRules
1491
+ };
1492
+ }
1493
+ /**
1494
+ * The files of a run archive of `runId` at `level`, built from `dir`'s copy of the run (the
1495
+ * history folder's or `.reeval/runs`') under its claim, as `recordRun` would keep them; nothing is
1496
+ * written or recorded. `check` sees the run's record first and may refuse it. `droppedPatch` says
1497
+ * where the worktree patch looked like it held a secret and by which rule, never any part of it.
1498
+ */
1499
+ async function leveledArchiveFiles(dir, runId, level, options) {
1500
+ const release = await claimRun(dir, runId);
1501
+ try {
1502
+ const run = await readRecord(recordFile(dir, runId));
1503
+ options.check?.(run);
1504
+ if (options.recorded) {
1505
+ const mismatch = await differs(dir, run, options.recorded, options);
1506
+ if (mismatch) return { mismatch };
1507
+ }
1508
+ let made;
1509
+ try {
1510
+ made = await leveled(dir, run, level, options);
1511
+ } catch (error) {
1512
+ if (options.recorded && error instanceof HistoryError) return { mismatch: error.message };
1513
+ throw error;
1514
+ }
1515
+ const { record, files, droppedPatchRules } = made;
1516
+ return {
1517
+ files: [{
1518
+ path: `${runId}.json`,
1519
+ data: encodeRecord(record)
1520
+ }, ...[...files].sort(([a], [b]) => a < b ? -1 : 1).map(([path, data]) => ({
1521
+ path: `${runId}/${path}`,
1522
+ data
1523
+ }))],
1524
+ droppedPatch: droppedPatchRules
1525
+ };
1526
+ } finally {
1527
+ await release();
1528
+ }
1529
+ }
1530
+ /** Promotes a scratch run into the committed history folder. reeval never commits it. */
1531
+ async function recordRun(options) {
1532
+ const { runId, artifacts: level } = options;
1533
+ const source = scratchDir(options.root);
1534
+ let scratch;
1535
+ try {
1536
+ scratch = await readRecord(join(source, `${runId}.json`));
1537
+ } catch (error) {
1538
+ if (isMissing(error)) throw new HistoryError(`No run ${runId} in .reeval/runs`);
1539
+ throw error;
1540
+ }
1541
+ if (scratch.status !== "complete" && !options.allowIncomplete) throw new HistoryError(`Run ${runId} was ${scratch.status}; pass --allow-incomplete to record it`);
1542
+ const { record, files, droppedPatch } = await leveled(source, scratch, level, options);
1543
+ const debug = options.debug && await stageDebug(options.root, runId, options.debug);
1544
+ if (debug) record.debug = debug;
1545
+ if (!options.skipSecretScan) {
1546
+ const found = [[`${runId}.json`, scanText(`${runId}.json`, encodeRecord(record).toString())], ...[...files].filter(([path]) => TEXT_FILE.test(path)).map(([path, bytes]) => [`${runId}/${path}`, scanText(path, Buffer.from(bytes).toString())])].filter(([, findings]) => findings.length > 0);
1547
+ if (found.length > 0) {
1548
+ const lines = found.flatMap(([path, findings]) => findingLines(path, findings));
1549
+ throw new HistoryError(`Refusing to record ${runId}: ${found.length} file(s) look like they contain a secret:\n${lines.map((l) => ` ${l}`).join("\n")}\nCheck them, then pass --skip-secret-scan if these are false positives.`);
1550
+ }
1551
+ }
1552
+ const committed = options.committed ?? true;
1553
+ if (committed) {
1554
+ await ensureHistoryGitignore(options.historyDir, options.archive ?? false);
1555
+ await ensureHistoryGitattributes(options.historyDir);
1556
+ }
1557
+ const written = await writeRun(options.historyDir, record, files);
1558
+ const zip = options.archive && await archiveRun(options.historyDir, runId, encodeRecord(record)).catch((error) => {
1559
+ const why = error instanceof Error ? error.message : String(error);
1560
+ throw new HistoryError(`Recorded ${runId}, but couldn't archive it: ${why}`, { cause: error });
1561
+ });
1562
+ const debugArchive = options.debugArchive && await archiveDebug(options.root, runId).catch((error) => {
1563
+ const why = error instanceof Error ? error.message : String(error);
1564
+ throw new HistoryError(`Recorded ${runId}, but couldn't archive its debug data: ${why}`, { cause: error });
1565
+ });
1566
+ const archive = {
1567
+ ...zip ? { archive: zip } : {},
1568
+ ...debugArchive ? { debugArchive } : {}
1569
+ };
1570
+ const bytes = [...files.values()].reduce((n, b) => n + b.length, encodeRecord(record).length);
1571
+ if (!committed) return {
1572
+ ...written,
1573
+ files: files.size,
1574
+ bytes,
1575
+ droppedPatch,
1576
+ ignored: [],
1577
+ ...debug ? { debug } : {},
1578
+ ...archive
1579
+ };
1580
+ const folderFiles = [historyGitignorePath(options.historyDir), historyGitattributesPath(options.historyDir)];
1581
+ if (!written.created) {
1582
+ const ignored = await ignoredRecordedFiles(options.root, folderFiles);
1583
+ return {
1584
+ ...written,
1585
+ files: files.size,
1586
+ bytes,
1587
+ droppedPatch,
1588
+ ignored,
1589
+ ...archive
1590
+ };
1591
+ }
1592
+ const writtenPaths = [
1593
+ written.recordPath,
1594
+ ...folderFiles,
1595
+ ...[...files.keys()].map((path) => join(written.artifactDir ?? options.historyDir, ...path.split("/")))
1596
+ ];
1597
+ const ignored = await ignoredRecordedFiles(options.root, writtenPaths);
1598
+ return {
1599
+ ...written,
1600
+ files: files.size,
1601
+ bytes,
1602
+ droppedPatch,
1603
+ ignored,
1604
+ ...archive
1605
+ };
1606
+ }
1607
+ export { readZip as A, scanText as C, openArchive as D, ArchiveError as E, writeArchive as O, findingLines as S, ensureHistoryGitignore as T, runArchiveFiles as _, encodeRecord as a, warnUnreadable as b, listRuns as c, readRunArchiveFiles as d, recentRecords as f, replaceable as g, recordRun as h, archiveFile as i, safeZipPath as j, bufferSource as k, parseRecord as l, recordNames as m, NewerRecordError as n, filesUnder as o, recordFile as p, SECRET_NOTE as r, leveledArchiveFiles as s, HistoryError as t, readRecord as u, runDir as v, ensureHistoryGitattributes as w, writeRun as x, scratchDir as y };
1608
+
1609
+ //# sourceMappingURL=files-CzgXLYGq.js.map