reeval 0.21.0 → 0.22.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 (336) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/README.md +15 -15
  3. package/dist/{adapter-BdzhdRYo.js → adapter-Di9H2etg.js} +5 -48
  4. package/dist/adapter-Di9H2etg.js.map +1 -0
  5. package/dist/{agent-Dx-bDmlV.js → agent-B-6GFDqA.js} +11 -12
  6. package/dist/agent-B-6GFDqA.js.map +1 -0
  7. package/dist/{agents-l0-k7vw3.js → agents-KBTYhSSh.js} +45 -36
  8. package/dist/agents-KBTYhSSh.js.map +1 -0
  9. package/dist/{app-files-B-CQYB0c.js → app-files-Cmh9FGr5.js} +3 -3
  10. package/dist/app-files-Cmh9FGr5.js.map +1 -0
  11. package/dist/{assemble-CYMpN8LC.js → assemble-CBMRIhso.js} +1 -1
  12. package/dist/{assemble-CsZIcJo8.js → assemble-DNVBTBp_.js} +11 -10
  13. package/dist/{assemble-CsZIcJo8.js.map → assemble-DNVBTBp_.js.map} +1 -1
  14. package/dist/attach-EbDGKGTO.js +152 -0
  15. package/dist/attach-EbDGKGTO.js.map +1 -0
  16. package/dist/{attempt-CKfKsqqw.js → attempt-_dUsblVx.js} +2 -2
  17. package/dist/{attempt-CKfKsqqw.js.map → attempt-_dUsblVx.js.map} +1 -1
  18. package/dist/{attempt-host-BwSmNYkX.js → attempt-host-DQvynDHk.js} +6 -6
  19. package/dist/{attempt-host-BwSmNYkX.js.map → attempt-host-DQvynDHk.js.map} +1 -1
  20. package/dist/boat-Bzz8L-KQ.js +701 -0
  21. package/dist/boat-Bzz8L-KQ.js.map +1 -0
  22. package/dist/{boat-CZpAreTB.js → boat-Dek8ftIt.js} +18 -6
  23. package/dist/boat-Dek8ftIt.js.map +1 -0
  24. package/dist/bundle-DZstHDeW.js +718 -0
  25. package/dist/bundle-DZstHDeW.js.map +1 -0
  26. package/dist/{capture-BqIAeFyC.js → capture-BkbPsfej.js} +17 -14
  27. package/dist/capture-BkbPsfej.js.map +1 -0
  28. package/dist/capture-CUAvk9KM.js +1 -0
  29. package/dist/{cli-s_3opn_I.js → cli-BgBBuxxJ.js} +276 -1018
  30. package/dist/cli-BgBBuxxJ.js.map +1 -0
  31. package/dist/{cli-spec-DxzIjmq_.js → cli-spec-B5L9n-DV.js} +93 -12
  32. package/dist/cli-spec-B5L9n-DV.js.map +1 -0
  33. package/dist/cli.js +2 -2
  34. package/dist/{client-C5fIzHQa.js → client-DMEYR3MA.js} +8 -4
  35. package/dist/client-DMEYR3MA.js.map +1 -0
  36. package/dist/{command-BJ7KqczP.js → command-BKb8eN_X.js} +8 -8
  37. package/dist/{command-BJ7KqczP.js.map → command-BKb8eN_X.js.map} +1 -1
  38. package/dist/{command-B5OAIjp7.js → command-D_w_kDpI.js} +13 -13
  39. package/dist/{command-B5OAIjp7.js.map → command-D_w_kDpI.js.map} +1 -1
  40. package/dist/{command-DA_SHQUQ.js → command-Dwlh0Vhu.js} +15 -14
  41. package/dist/command-Dwlh0Vhu.js.map +1 -0
  42. package/dist/{command-BXLZsEwQ.js → command-loXH2jHr.js} +11 -11
  43. package/dist/{command-BXLZsEwQ.js.map → command-loXH2jHr.js.map} +1 -1
  44. package/dist/{commands-BKBamOcX.js → commands-Cuf57OYb.js} +13 -13
  45. package/dist/{commands-BKBamOcX.js.map → commands-Cuf57OYb.js.map} +1 -1
  46. package/dist/{commands-BPvAOEmb.js → commands-Dqli45sR.js} +1 -1
  47. package/dist/{config-C0URar0t.js → config-C0RKt00M.js} +46 -30
  48. package/dist/config-C0RKt00M.js.map +1 -0
  49. package/dist/{context-Sj58aJEu.js → context-DrEAtUyg.js} +2 -2
  50. package/dist/{context-Sj58aJEu.js.map → context-DrEAtUyg.js.map} +1 -1
  51. package/dist/{cursor-catalog-FWgSo-T1.js → cursor-catalog-CRsFxorF.js} +2 -2
  52. package/dist/{cursor-catalog-FWgSo-T1.js.map → cursor-catalog-CRsFxorF.js.map} +1 -1
  53. package/dist/db-3o8s2EyD.js +2 -0
  54. package/dist/{db-BjAWxVAG.js → db-ErnJ-gMD.js} +34 -8
  55. package/dist/{db-BjAWxVAG.js.map → db-ErnJ-gMD.js.map} +1 -1
  56. package/dist/{default-effort-Ck2GYIxX.js → default-effort-D70cTG00.js} +2 -2
  57. package/dist/{default-effort-Ck2GYIxX.js.map → default-effort-D70cTG00.js.map} +1 -1
  58. package/dist/{default-effort-CWlhZ6U1.js → default-effort-DHzj84dD.js} +1 -1
  59. package/dist/{docker-D74l67k8.js → docker-CFWzZOEk.js} +4 -4
  60. package/dist/{docker-D74l67k8.js.map → docker-CFWzZOEk.js.map} +1 -1
  61. package/dist/docker-DrMnpL84.js +1 -0
  62. package/dist/{doctor-eFxyn6at.js → doctor-B7utCSdh.js} +56 -74
  63. package/dist/doctor-B7utCSdh.js.map +1 -0
  64. package/dist/{environment-CJIKz-Ud.js → environment-C0Gg8kyN.js} +5 -5
  65. package/dist/{environment-CJIKz-Ud.js.map → environment-C0Gg8kyN.js.map} +1 -1
  66. package/dist/{eval-source-CXIRJ91v.js → eval-source-CsW5VIXS.js} +5 -5
  67. package/dist/{eval-source-CXIRJ91v.js.map → eval-source-CsW5VIXS.js.map} +1 -1
  68. package/dist/{evaluate-DA4QsrHO.js → evaluate-BHQyAszQ.js} +238 -212
  69. package/dist/evaluate-BHQyAszQ.js.map +1 -0
  70. package/dist/{evaluate-DHrU4Wld.d.ts → evaluate-DzHq4EsU.d.ts} +2 -2
  71. package/dist/{fake-bootstrap-CnwWG3kP.js → fake-bootstrap-VpisF1WE.js} +2 -2
  72. package/dist/{fake-bootstrap-CnwWG3kP.js.map → fake-bootstrap-VpisF1WE.js.map} +1 -1
  73. package/dist/{files-Bey1VAex.js → files-BCraBodb.js} +3 -3
  74. package/dist/{files-Bey1VAex.js.map → files-BCraBodb.js.map} +1 -1
  75. package/dist/{files-BVVWAS0A.js → files-BuKWZCzY.js} +5 -5
  76. package/dist/{files-BVVWAS0A.js.map → files-BuKWZCzY.js.map} +1 -1
  77. package/dist/{files-BaqXvB88.js → files-CAzVG3Rr.js} +1 -1
  78. package/dist/{files-D6j-XpaK.js → files-Cv856jLN.js} +3 -3
  79. package/dist/{files-D6j-XpaK.js.map → files-Cv856jLN.js.map} +1 -1
  80. package/dist/files-D-Lir4aE.js +1 -0
  81. package/dist/files-DRlJ0Xr2.js +1 -0
  82. package/dist/{files-F44NRCN0.js → files-qjeqXnfE.js} +6 -6
  83. package/dist/{files-F44NRCN0.js.map → files-qjeqXnfE.js.map} +1 -1
  84. package/dist/gateway.d.ts +1 -1
  85. package/dist/{git-Jqkf9SBa.js → git-DOrOtAiD.js} +3 -3
  86. package/dist/{git-Jqkf9SBa.js.map → git-DOrOtAiD.js.map} +1 -1
  87. package/dist/harness-install-Dxho1yaU.js +53 -0
  88. package/dist/harness-install-Dxho1yaU.js.map +1 -0
  89. package/dist/harness.d.ts +1 -1
  90. package/dist/{images-Dsc4Wi-F.js → images-Ch1y1t6_.js} +69 -55
  91. package/dist/images-Ch1y1t6_.js.map +1 -0
  92. package/dist/index.d.ts +2 -2
  93. package/dist/index.js +5 -5
  94. package/dist/{init-QB5ecPDA.js → init-C2HqCwnt.js} +5 -5
  95. package/dist/{init-QB5ecPDA.js.map → init-C2HqCwnt.js.map} +1 -1
  96. package/dist/init-CM9xwyre.js +1 -0
  97. package/dist/{ink-list-mCJypk3d.js → ink-list-BbKXElcQ.js} +54 -15
  98. package/dist/ink-list-BbKXElcQ.js.map +1 -0
  99. package/dist/inputs-5UIDpjz-.js +190 -0
  100. package/dist/inputs-5UIDpjz-.js.map +1 -0
  101. package/dist/inputs-load-C82HOKnb.js +1 -0
  102. package/dist/inputs-load-CGPyigMC.js +95 -0
  103. package/dist/inputs-load-CGPyigMC.js.map +1 -0
  104. package/dist/{invocations-BSr4lRzI.js → invocations-BrZAMuTb.js} +4 -4
  105. package/dist/{invocations-BSr4lRzI.js.map → invocations-BrZAMuTb.js.map} +1 -1
  106. package/dist/jiti-radm1Soi.js +52 -0
  107. package/dist/jiti-radm1Soi.js.map +1 -0
  108. package/dist/{judge-eGH39PaP.js → judge-DwzqucLS.js} +9 -6
  109. package/dist/{judge-eGH39PaP.js.map → judge-DwzqucLS.js.map} +1 -1
  110. package/dist/judge.d.ts +1 -1
  111. package/dist/judge.js +1 -1
  112. package/dist/{layout-DfQa4mJs.js → layout-Czh5wOpz.js} +2 -2
  113. package/dist/{layout-DfQa4mJs.js.map → layout-Czh5wOpz.js.map} +1 -1
  114. package/dist/{list-Dh6T0kdr.js → list-B_C0k5ex.js} +14 -11
  115. package/dist/{list-Dh6T0kdr.js.map → list-B_C0k5ex.js.map} +1 -1
  116. package/dist/live-C9Et_BVT.js +1 -0
  117. package/dist/{live-xTZs0c61.js → live-DGgIrVw0.js} +7 -5
  118. package/dist/live-DGgIrVw0.js.map +1 -0
  119. package/dist/{live-y1p3oNXH.js → live-DgFm0H90.js} +7 -7
  120. package/dist/{live-y1p3oNXH.js.map → live-DgFm0H90.js.map} +1 -1
  121. package/dist/machine-service-2lIv5UWF.js +1 -0
  122. package/dist/machine-service-Ct_1XMMi.js +520 -0
  123. package/dist/machine-service-Ct_1XMMi.js.map +1 -0
  124. package/dist/machines-BnquHcBZ.js +120 -0
  125. package/dist/machines-BnquHcBZ.js.map +1 -0
  126. package/dist/{model-DEjwetkJ.js → model-B1tdv9-d.js} +1 -1
  127. package/dist/model-Bcy4Qjmm.js +1 -0
  128. package/dist/{model-DNpKiHqO.js → model-DF77SgZv.js} +2 -2
  129. package/dist/{model-DNpKiHqO.js.map → model-DF77SgZv.js.map} +1 -1
  130. package/dist/{model-3pZZzloU.js → model-DRa7yv6K.js} +6 -5
  131. package/dist/model-DRa7yv6K.js.map +1 -0
  132. package/dist/{model-jRKSQBg6.js → model-E5X8YBJM.js} +6 -5
  133. package/dist/model-E5X8YBJM.js.map +1 -0
  134. package/dist/{node-DM-mLGdX.js → node-BjuhqQwa.js} +16 -5
  135. package/dist/node-BjuhqQwa.js.map +1 -0
  136. package/dist/{openrouter-models-C0aRo633.js → openrouter-models-B1sIOTD2.js} +2 -2
  137. package/dist/{openrouter-models-C0aRo633.js.map → openrouter-models-B1sIOTD2.js.map} +1 -1
  138. package/dist/options-C989kuVE.js +1 -0
  139. package/dist/own-reads-CYmBlrHK.js +15 -0
  140. package/dist/own-reads-CYmBlrHK.js.map +1 -0
  141. package/dist/{patch-Bx-qp8Li.js → patch-BR8rdl7r.js} +2 -2
  142. package/dist/{patch-Bx-qp8Li.js.map → patch-BR8rdl7r.js.map} +1 -1
  143. package/dist/{plan-ChO0A-xn.js → plan-BcT4G5jj.js} +47 -9
  144. package/dist/plan-BcT4G5jj.js.map +1 -0
  145. package/dist/{plugins-BioMWncI.js → plugins-cC0sqoDA.js} +91 -122
  146. package/dist/plugins-cC0sqoDA.js.map +1 -0
  147. package/dist/preflight-BMVDBcux.js +1 -0
  148. package/dist/{preflight-qFCXmxha.js → preflight-C9OtTb7k.js} +3 -3
  149. package/dist/{preflight-qFCXmxha.js.map → preflight-C9OtTb7k.js.map} +1 -1
  150. package/dist/{preflight-CJSGzMzc.js → preflight-DySHXeFJ.js} +8 -8
  151. package/dist/preflight-DySHXeFJ.js.map +1 -0
  152. package/dist/{preflight-BUjk_6wT.js → preflight-zsAn3heN.js} +1 -1
  153. package/dist/{prepare-xHU2BpN-.js → prepare-MaRWRhNT.js} +2 -2
  154. package/dist/{prepare-D7oSSFNm.js → prepare-nbX1CXXg.js} +195 -54
  155. package/dist/prepare-nbX1CXXg.js.map +1 -0
  156. package/dist/{provenance-B-flBAzR.js → provenance-CkykifD9.js} +3 -3
  157. package/dist/{provenance-B-flBAzR.js.map → provenance-CkykifD9.js.map} +1 -1
  158. package/dist/{providers-Dljf6al6.js → providers-BkLGzaSY.js} +1 -1
  159. package/dist/{providers-B6StVyfG.js → providers-bNgfKa6m.js} +31 -23
  160. package/dist/providers-bNgfKa6m.js.map +1 -0
  161. package/dist/query-B2SQddoV.js +1 -0
  162. package/dist/{query-CkLmJv7R.js → query-DhV3a8lM.js} +2 -2
  163. package/dist/{query-CkLmJv7R.js.map → query-DhV3a8lM.js.map} +1 -1
  164. package/dist/{questions-CJIh2FSX.js → questions-Csv64WCb.js} +6 -6
  165. package/dist/{questions-CJIh2FSX.js.map → questions-Csv64WCb.js.map} +1 -1
  166. package/dist/{record-nVVujCW7.js → record--vHreTLk.js} +10 -4
  167. package/dist/record--vHreTLk.js.map +1 -0
  168. package/dist/{redact-DL2BTykw.js → redact-t-L3VGy8.js} +91 -2
  169. package/dist/redact-t-L3VGy8.js.map +1 -0
  170. package/dist/{remarks-B3wjKscW.js → remarks-CYFOsnz5.js} +6 -6
  171. package/dist/{remarks-B3wjKscW.js.map → remarks-CYFOsnz5.js.map} +1 -1
  172. package/dist/{remote-C88amFRN.js → remote-0CHog7Oq.js} +5 -5
  173. package/dist/{remote-C88amFRN.js.map → remote-0CHog7Oq.js.map} +1 -1
  174. package/dist/resolve-Bm9ZyFR-.js +1 -0
  175. package/dist/{resolve-G576PiFJ.js → resolve-DorSHDBs.js} +7 -7
  176. package/dist/{resolve-G576PiFJ.js.map → resolve-DorSHDBs.js.map} +1 -1
  177. package/dist/resources-DqdwihhT.js +62 -0
  178. package/dist/resources-DqdwihhT.js.map +1 -0
  179. package/dist/{results-zVHIW6xw.js → results-DhMgRkR0.js} +5 -5
  180. package/dist/{results-zVHIW6xw.js.map → results-DhMgRkR0.js.map} +1 -1
  181. package/dist/{resume-D_PcUXfG.js → resume-C8Ihfy-C.js} +77 -6
  182. package/dist/resume-C8Ihfy-C.js.map +1 -0
  183. package/dist/{retry-BvTzCxdc.js → retry-Bfk7pDti.js} +3 -3
  184. package/dist/{retry-BvTzCxdc.js.map → retry-Bfk7pDti.js.map} +1 -1
  185. package/dist/{routes-B0F2R-K7.js → routes-Cp4gAjBZ.js} +118 -70
  186. package/dist/routes-Cp4gAjBZ.js.map +1 -0
  187. package/dist/{runtime-B3r_pAq6.js → runtime-CPUH0Vk5.js} +44 -3
  188. package/dist/runtime-CPUH0Vk5.js.map +1 -0
  189. package/dist/sandbox/boat.d.ts +1 -1
  190. package/dist/sandbox/boat.js +1 -1
  191. package/dist/{sandbox-Duh3z1TV.js → sandbox-z8q_4Ywn.js} +2 -2
  192. package/dist/{sandbox-Duh3z1TV.js.map → sandbox-z8q_4Ywn.js.map} +1 -1
  193. package/dist/sandbox.d.ts +1 -1
  194. package/dist/sandbox.js +1 -1
  195. package/dist/{server-DUWMRKik.js → server-BsQZtuF9.js} +8 -8
  196. package/dist/{server-DUWMRKik.js.map → server-BsQZtuF9.js.map} +1 -1
  197. package/dist/server-ZaMzUNmV.js +1 -0
  198. package/dist/services-BG8xuU82.js +39 -0
  199. package/dist/services-BG8xuU82.js.map +1 -0
  200. package/dist/{source-CHuN4Nfg.js → source-9HWaTEgV.js} +2 -2
  201. package/dist/{source-CHuN4Nfg.js.map → source-9HWaTEgV.js.map} +1 -1
  202. package/dist/source-BcBDj-R0.js +1 -0
  203. package/dist/{src-CZaYu6ER.js → src-B2eHTCnp.js} +1 -1
  204. package/dist/{src-BI0v8qlZ.js → src-Bb3k9Kn_.js} +8 -5
  205. package/dist/{src-BI0v8qlZ.js.map → src-Bb3k9Kn_.js.map} +1 -1
  206. package/dist/{src-CkEiiyON.js → src-BfOlH_Bu.js} +2 -2
  207. package/dist/{src-CeBhwD8k.js → src-BuGc40IF.js} +1 -1
  208. package/dist/{src-De0KY5S_.js → src-C2K5_afU.js} +2 -2
  209. package/dist/{src-BqNzHHWn.js → src-C3OhA5pw.js} +2 -2
  210. package/dist/{src-BqNzHHWn.js.map → src-C3OhA5pw.js.map} +1 -1
  211. package/dist/{src-DA95rM6v.js → src-CSVJjghq.js} +1 -1
  212. package/dist/{src-BHJ4MWvY.js → src-CWfy8ct8.js} +1114 -411
  213. package/dist/src-CWfy8ct8.js.map +1 -0
  214. package/dist/{src--yl1OypK.js → src-CcrQQB0_.js} +2 -2
  215. package/dist/src-CotUxxQV.js +2 -0
  216. package/dist/src-D-PwBaBB.js +2 -0
  217. package/dist/{src-B-HuDqpH.js → src-DNWiU__5.js} +2 -2
  218. package/dist/{src-B-HuDqpH.js.map → src-DNWiU__5.js.map} +1 -1
  219. package/dist/{src-CmA5Yev6.js → src-DwcTn4JY.js} +2 -2
  220. package/dist/{src-CmA5Yev6.js.map → src-DwcTn4JY.js.map} +1 -1
  221. package/dist/{src-DL-EE4DU.js → src-c3ZQu7Uu.js} +2 -2
  222. package/dist/{src-DL-EE4DU.js.map → src-c3ZQu7Uu.js.map} +1 -1
  223. package/dist/src-jYqNkT-F.js +1 -0
  224. package/dist/start-Db5VRcRZ.js +660 -0
  225. package/dist/start-Db5VRcRZ.js.map +1 -0
  226. package/dist/state-CKIjZZRK.js +1 -0
  227. package/dist/{state-DUBRDyMk.js → state-DUYdzNA7.js} +14 -14
  228. package/dist/{state-DUBRDyMk.js.map → state-DUYdzNA7.js.map} +1 -1
  229. package/dist/store/local.d.ts +1 -1
  230. package/dist/store/s3.d.ts +1 -1
  231. package/dist/suite-CH1aaAbs.js +2 -0
  232. package/dist/{suite-B9J6Afg6.js → suite-DjGxmDSY.js} +2 -2
  233. package/dist/{suite-B9J6Afg6.js.map → suite-DjGxmDSY.js.map} +1 -1
  234. package/dist/{summary-CSp4cfnr.js → summary-BK5Sa_N0.js} +8 -5
  235. package/dist/summary-BK5Sa_N0.js.map +1 -0
  236. package/dist/{sync-CxAY6Dki.js → sync-DUi_P2UJ.js} +2 -2
  237. package/dist/{sync-CxAY6Dki.js.map → sync-DUi_P2UJ.js.map} +1 -1
  238. package/dist/{tarball-CESxtK4X.js → tarball-C8BSTAMk.js} +2 -2
  239. package/dist/{tarball-CESxtK4X.js.map → tarball-C8BSTAMk.js.map} +1 -1
  240. package/dist/{tart-CcrrtSrp.js → tart-BQ_Ap0l4.js} +99 -295
  241. package/dist/tart-BQ_Ap0l4.js.map +1 -0
  242. package/dist/{tart-bake-F-6seRC9.js → tart-bake-D1RttYfM.js} +18 -62
  243. package/dist/tart-bake-D1RttYfM.js.map +1 -0
  244. package/dist/{tart-bake-RK7RaT9E.js → tart-bake-DjFcsG3N.js} +1 -1
  245. package/dist/{tart-cli-ClvRniLQ.js → tart-cli-BOcluha1.js} +1 -1
  246. package/dist/{tart-cli-B86Jqo1t.js → tart-cli-gA9xEaQL.js} +2 -2
  247. package/dist/{tart-cli-B86Jqo1t.js.map → tart-cli-gA9xEaQL.js.map} +1 -1
  248. package/dist/{tart-hosts-DPyZsg-1.js → tart-hosts-CHNrfV6u.js} +3 -3
  249. package/dist/{tart-hosts-DPyZsg-1.js.map → tart-hosts-CHNrfV6u.js.map} +1 -1
  250. package/dist/{tart-hosts-Brii7zHM.js → tart-hosts-CWse-ASo.js} +1 -1
  251. package/dist/{tart-images-CWSf03w8.js → tart-images-CLBjfF9u.js} +2 -2
  252. package/dist/{tart-images-CWSf03w8.js.map → tart-images-CLBjfF9u.js.map} +1 -1
  253. package/dist/testing.d.ts +2 -2
  254. package/dist/testing.js +4 -4
  255. package/dist/{tool-class-CVDdJy0H.js → tool-class-krsmEo44.js} +2 -2
  256. package/dist/{tool-class-CVDdJy0H.js.map → tool-class-krsmEo44.js.map} +1 -1
  257. package/dist/{transcript-BP_2hji-.js → transcript-BXWZiMuC.js} +2 -2
  258. package/dist/{transcript-BP_2hji-.js.map → transcript-BXWZiMuC.js.map} +1 -1
  259. package/dist/types-CbcnJxCy.js.map +1 -1
  260. package/dist/{types-BJ0wh8wC.d.ts → types-DKK8jj--.d.ts} +110 -2
  261. package/dist/ui-DKYjTVpn.js +1455 -0
  262. package/dist/ui-DKYjTVpn.js.map +1 -0
  263. package/dist/vercel-models-Ci33llXz.js +21 -0
  264. package/dist/vercel-models-Ci33llXz.js.map +1 -0
  265. package/dist/view/index.d.ts +6 -1
  266. package/dist/view/index.js +4 -4
  267. package/dist/{views-DRxXCyIH.js → views-B1zVLJsF.js} +6 -6
  268. package/dist/{views-DRxXCyIH.js.map → views-B1zVLJsF.js.map} +1 -1
  269. package/dist/views-DCjtw1jF.js +2 -0
  270. package/dist/{worker-entry-C3Q4U63F.js → worker-entry-DrAYYt0M.js} +31 -11
  271. package/dist/worker-entry-DrAYYt0M.js.map +1 -0
  272. package/dist/workspace-CnRbV8cM.js +1 -0
  273. package/dist/{workspace-P72SXLXr.js → workspace-DwTe1zo6.js} +5 -5
  274. package/dist/{workspace-P72SXLXr.js.map → workspace-DwTe1zo6.js.map} +1 -1
  275. package/docker/Dockerfile +1 -1
  276. package/package.json +4 -1
  277. package/skills/reeval/references/environments.md +2 -2
  278. package/dist/adapter-BdzhdRYo.js.map +0 -1
  279. package/dist/agent-Dx-bDmlV.js.map +0 -1
  280. package/dist/agents-l0-k7vw3.js.map +0 -1
  281. package/dist/app-files-B-CQYB0c.js.map +0 -1
  282. package/dist/boat-CZpAreTB.js.map +0 -1
  283. package/dist/boat-su1Y7LPd.js +0 -325
  284. package/dist/boat-su1Y7LPd.js.map +0 -1
  285. package/dist/capture-BqIAeFyC.js.map +0 -1
  286. package/dist/capture-D0Ln5aCP.js +0 -1
  287. package/dist/cli-s_3opn_I.js.map +0 -1
  288. package/dist/cli-spec-DxzIjmq_.js.map +0 -1
  289. package/dist/client-C5fIzHQa.js.map +0 -1
  290. package/dist/command-DA_SHQUQ.js.map +0 -1
  291. package/dist/config-C0URar0t.js.map +0 -1
  292. package/dist/db-Bc4L-Wcr.js +0 -2
  293. package/dist/docker-CDdK6Ity.js +0 -271
  294. package/dist/docker-CDdK6Ity.js.map +0 -1
  295. package/dist/docker-DMug3l-a.js +0 -1
  296. package/dist/doctor-eFxyn6at.js.map +0 -1
  297. package/dist/evaluate-DA4QsrHO.js.map +0 -1
  298. package/dist/files-CNHhSyb3.js +0 -1
  299. package/dist/files-CW1lChNh.js +0 -1
  300. package/dist/images-Dsc4Wi-F.js.map +0 -1
  301. package/dist/init-C0oUG3jh.js +0 -1
  302. package/dist/ink-list-mCJypk3d.js.map +0 -1
  303. package/dist/live-DwjWJTdn.js +0 -1
  304. package/dist/live-xTZs0c61.js.map +0 -1
  305. package/dist/model-3pZZzloU.js.map +0 -1
  306. package/dist/model-jRKSQBg6.js.map +0 -1
  307. package/dist/model-nfewGTzB.js +0 -1
  308. package/dist/node-DM-mLGdX.js.map +0 -1
  309. package/dist/options-DpsJ_5CU.js +0 -1
  310. package/dist/plan-ChO0A-xn.js.map +0 -1
  311. package/dist/plugins-BioMWncI.js.map +0 -1
  312. package/dist/preflight-CJSGzMzc.js.map +0 -1
  313. package/dist/preflight-DD3fI4Hz.js +0 -1
  314. package/dist/prepare-D7oSSFNm.js.map +0 -1
  315. package/dist/providers-B6StVyfG.js.map +0 -1
  316. package/dist/query-BAc2tQZj.js +0 -1
  317. package/dist/record-nVVujCW7.js.map +0 -1
  318. package/dist/redact-DL2BTykw.js.map +0 -1
  319. package/dist/resolve-DW92wpIZ.js +0 -1
  320. package/dist/resume-D_PcUXfG.js.map +0 -1
  321. package/dist/routes-B0F2R-K7.js.map +0 -1
  322. package/dist/runtime-B3r_pAq6.js.map +0 -1
  323. package/dist/server-CGEsvVRG.js +0 -1
  324. package/dist/source-Wz1Nrfue.js +0 -1
  325. package/dist/src-BHJ4MWvY.js.map +0 -1
  326. package/dist/src-BL-_0QoE.js +0 -1
  327. package/dist/src-C-mOSczH.js +0 -2
  328. package/dist/src-CwH_nEaw.js +0 -2
  329. package/dist/state-B3jex5KU.js +0 -1
  330. package/dist/suite-Bhs9-Z7O.js +0 -2
  331. package/dist/summary-CSp4cfnr.js.map +0 -1
  332. package/dist/tart-CcrrtSrp.js.map +0 -1
  333. package/dist/tart-bake-F-6seRC9.js.map +0 -1
  334. package/dist/views-i67V1ly3.js +0 -2
  335. package/dist/worker-entry-C3Q4U63F.js.map +0 -1
  336. package/dist/workspace-DhUOW8if.js +0 -1
@@ -290,7 +290,7 @@ function windowsSpawn(cmd, args, env = process.env, exists = existsSync) {
290
290
  * Kills a process and everything it started: its process group on POSIX (a detached child leads
291
291
  * one), its process tree with `taskkill` on Windows, which has neither groups nor signals.
292
292
  */
293
- function killTree(pid) {
293
+ function killTree$1(pid) {
294
294
  if (process.platform === "win32") {
295
295
  spawn("taskkill", [
296
296
  "/pid",
@@ -344,7 +344,7 @@ function run(cmd, args, options = {}) {
344
344
  stderr += d;
345
345
  });
346
346
  const onAbort = () => {
347
- if ((detached || process.platform === "win32") && child.pid) killTree(child.pid);
347
+ if ((detached || process.platform === "win32") && child.pid) killTree$1(child.pid);
348
348
  else child.kill("SIGKILL");
349
349
  };
350
350
  signal?.addEventListener("abort", onAbort, { once: true });
@@ -680,7 +680,7 @@ async function imageInfo(image, engine) {
680
680
  "image",
681
681
  "inspect",
682
682
  "--format",
683
- `{"config":{{json .Config}},"id":{{json ${imageId}}},"repoDigests":{{json .RepoDigests}}}`,
683
+ `{"config":{{json .Config}},"id":{{json ${imageId}}},"repoDigests":{{json .RepoDigests}},"os":{{json .Os}},"arch":{{json .Architecture}}}`,
684
684
  image
685
685
  ], { engine }).catch((error) => {
686
686
  throw new Error(`${bin} image inspect ${image} couldn't run: ${error.message}`);
@@ -692,10 +692,12 @@ async function imageInfo(image, engine) {
692
692
  }
693
693
  const info = JSON.parse(r.stdout.toString("utf8"));
694
694
  const repoDigests = (info.repoDigests ?? []).filter(isRegistryDigest);
695
+ const platform = info.os && info.arch ? `${info.os}/${info.arch}` : null;
695
696
  return {
696
697
  labels: info.config?.Labels ?? {},
697
698
  id: normalizeImageId(info.id),
698
- repoDigests
699
+ repoDigests,
700
+ platform
699
701
  };
700
702
  }
701
703
  // ../sandbox-docker/src/dockerignore.ts
@@ -791,48 +793,118 @@ function contextFiles(context, dockerfile) {
791
793
  }
792
794
  // ../sandbox-docker/src/image.ts
793
795
  /**
794
- * The harness adapters an image can bake. Each pin must match the exact dependency (or
795
- * `workspace:<version>` for this repo's own adapters); a test enforces it. `patch` is the first 8
796
- * hex of the sha256 of the adapter's pnpm patch (`patchedDependencies` in pnpm-workspace.yaml),
797
- * whose bridge the image bakes; a test holds it to the patch file.
796
+ * The harness adapters an image can bake, and each one's bootstrap. Each pin must match the exact
797
+ * dependency (or `workspace:<version>` for this repo's own adapters); a test enforces it. `patch`
798
+ * is the first 8 hex of the sha256 of the adapter's pnpm patch (`patchedDependencies` in
799
+ * pnpm-workspace.yaml), whose bridge the image bakes; a test holds it to the patch file.
798
800
  */
799
801
  const HARNESS_PACKAGES = {
800
802
  cursor: {
801
803
  name: "@reeval/harness-cursor-sdk",
802
- version: "0.1.9"
804
+ version: "0.1.9",
805
+ bootstrap: {
806
+ name: "Cursor",
807
+ cli: "@cursor/sdk",
808
+ probe: `node -p "'@cursor/sdk ' + require(process.env.HOME + '/.ai-sdk-harness/.harness-bootstrap/cursor-sdk/node_modules/@cursor/sdk/package.json').version"`,
809
+ adapter: async () => (await import("./src-BuGc40IF.js")).createCursorSdk()
810
+ }
803
811
  },
804
812
  "claude-code": {
805
813
  name: "@ai-sdk/harness-claude-code",
806
814
  version: "1.0.176",
807
- patch: "a9d56a8c"
815
+ patch: "a9d56a8c",
816
+ bootstrap: {
817
+ name: "Claude Code",
818
+ cli: "claude",
819
+ adapter: async () => (await import("./dist-DeqeCUZe.js")).createClaudeCode()
820
+ }
808
821
  },
809
822
  antigravity: {
810
823
  name: "@reeval/harness-antigravity",
811
- version: "0.1.15"
824
+ version: "0.1.16",
825
+ bootstrap: {
826
+ name: "Antigravity",
827
+ cli: "agy",
828
+ adapter: async () => (await import("./src-CotUxxQV.js")).createAntigravity()
829
+ }
812
830
  },
813
831
  opencode: {
814
832
  name: "@reeval/harness-opencode",
815
- version: "0.2.16"
833
+ version: "0.2.16",
834
+ bootstrap: {
835
+ name: "OpenCode",
836
+ cli: "opencode",
837
+ adapter: async () => (await import("./src-B2eHTCnp.js")).createOpenCode({
838
+ auth: { GOOGLE_GENERATIVE_AI_API_KEY: "unused" },
839
+ model: "google/unused"
840
+ })
841
+ }
816
842
  },
817
843
  goose: {
818
844
  name: "@reeval/harness-goose",
819
- version: "0.1.15"
845
+ version: "0.1.16",
846
+ bootstrap: {
847
+ name: "Goose",
848
+ cli: "goose",
849
+ adapter: async () => {
850
+ const goose = await import("./src-BfOlH_Bu.js");
851
+ return goose.createGoose({
852
+ auth: { GOOGLE_API_KEY: "unused" },
853
+ provider: goose.GEMINI_PROVIDER,
854
+ model: "unused"
855
+ });
856
+ }
857
+ }
820
858
  },
821
859
  pi: {
822
860
  name: "@reeval/harness-pi",
823
- version: "0.2.9"
861
+ version: "0.2.9",
862
+ bootstrap: {
863
+ name: "pi",
864
+ cli: "pi",
865
+ adapter: async () => {
866
+ const pi = await import("./src-CSVJjghq.js");
867
+ const provider = pi.piProvider("google");
868
+ if ("refused" in provider) throw new Error(provider.refused);
869
+ return pi.createPi({
870
+ auth: { GEMINI_API_KEY: "unused" },
871
+ provider
872
+ });
873
+ }
874
+ }
824
875
  },
825
876
  codex: {
826
877
  name: "@reeval/harness-codex",
827
- version: "0.1.12"
878
+ version: "0.1.13",
879
+ bootstrap: {
880
+ name: "Codex",
881
+ cli: "codex",
882
+ adapter: async () => (await import("./src-CcrQQB0_.js")).createCodex({ auth: { OPENAI_API_KEY: "unused" } })
883
+ }
828
884
  },
829
885
  fx: {
830
886
  name: "@reeval/harness-fx",
831
- version: "0.1.10"
887
+ version: "0.1.11",
888
+ bootstrap: {
889
+ name: "fx",
890
+ cli: "fx",
891
+ adapter: async () => (await import("./src-D-PwBaBB.js")).createFx({
892
+ auth: { AI_GATEWAY_API_KEY: "unused" },
893
+ model: "unused/unused"
894
+ })
895
+ }
832
896
  },
833
897
  "grok-build": {
834
898
  name: "@reeval/harness-grok-build",
835
- version: "0.1.11"
899
+ version: "0.1.12",
900
+ bootstrap: {
901
+ name: "Grok Build",
902
+ cli: "grok",
903
+ adapter: async () => (await import("./src-C2K5_afU.js")).createGrokBuild({
904
+ auth: { XAI_API_KEY: "unused" },
905
+ model: "unused"
906
+ })
907
+ }
836
908
  }
837
909
  };
838
910
  /** Every harness with an image, in {@link HARNESS_PACKAGES} order. */
@@ -860,7 +932,9 @@ const LABEL = {
860
932
  /** On reeval's own images: the hash of the base image's build context, to tell a stale one. */
861
933
  context: "ai.reeval.context",
862
934
  /** On a `from` image: the digest (or, for a local-only base, the image id) it was built on. */
863
- fromDigest: "ai.reeval.from-digest"
935
+ fromDigest: "ai.reeval.from-digest",
936
+ /** On every image reeval builds: its content key, which a registry pull must match. */
937
+ key: "ai.reeval.key"
864
938
  };
865
939
  /**
866
940
  * The user the agent, setup steps and checks run as, which every image reeval builds creates. Image
@@ -879,6 +953,26 @@ const WORKSPACE_DIR = "workspace";
879
953
  */
880
954
  const SANDBOX_STATE = "/var/lib/reeval";
881
955
  const BRIDGE_PORT = 43210;
956
+ /** The egress forwarder's port for slot 0; slot `n` listens on this plus `n`. */
957
+ const BASE_PROXY_PORT = 43128;
958
+ /** Slot `slot`'s layout: slot 0's is {@link SANDBOX_USER}'s, `n` is `reeval-s<n>` in each place. */
959
+ function slotLayout(slot) {
960
+ if (slot === 0) return {
961
+ user: SANDBOX_USER,
962
+ home: SANDBOX_HOME,
963
+ root: SANDBOX_ROOT,
964
+ state: SANDBOX_STATE,
965
+ proxyPort: BASE_PROXY_PORT
966
+ };
967
+ const user = `${SANDBOX_USER}-s${slot}`;
968
+ return {
969
+ user,
970
+ home: `/home/${user}`,
971
+ root: `${SANDBOX_ROOT}-s${slot}`,
972
+ state: `${SANDBOX_STATE}-s${slot}`,
973
+ proxyPort: BASE_PROXY_PORT + slot
974
+ };
975
+ }
882
976
  // ../sandbox-docker/src/egress/cert.ts
883
977
  const der = (tag, ...content) => {
884
978
  const body = Buffer.concat(content);
@@ -3560,13 +3654,27 @@ function containerTransport(containerId, engine) {
3560
3654
  }
3561
3655
  // ../sandbox-docker/src/egress/gateway.ts
3562
3656
  /** Where the forwarder listens inside the sandbox; every exec gets it as its HTTP(S) proxy. */
3563
- const PROXY_PORT = 43128;
3657
+ const PROXY_PORT = BASE_PROXY_PORT;
3564
3658
  /** The gateway's CA certificate in the container. The private key never leaves the host. */
3565
3659
  const CA_PATH = "/usr/local/share/ca-certificates/reeval-egress.crt";
3566
3660
  /** Debian's system bundle, which `update-ca-certificates` rebuilds with the gateway's CA in it. */
3567
3661
  const CA_BUNDLE = "/etc/ssl/certs/ca-certificates.crt";
3568
3662
  const BUNDLED = "reeval:ca-bundle";
3663
+ /** Held while a gateway installs its CA, so gateways sharing a machine don't rebuild the bundle at once. */
3664
+ const CA_LOCK = "/var/lock/reeval-egress-ca";
3569
3665
  const READY_TIMEOUT_MS = 15e3;
3666
+ /** Where a gateway on `port` keeps its CA certificate, and the glob of its pid files' tags. */
3667
+ const placement = (port) => port === void 0 ? {
3668
+ port: PROXY_PORT,
3669
+ caPath: CA_PATH,
3670
+ tags: "*",
3671
+ tag: ""
3672
+ } : {
3673
+ port,
3674
+ caPath: `/usr/local/share/ca-certificates/reeval-egress-${port}.crt`,
3675
+ tags: `p${port}-*`,
3676
+ tag: `p${port}-`
3677
+ };
3570
3678
  /**
3571
3679
  * Where a forwarder a transport could orphan records its pid, one file per gateway: `ps` can't
3572
3680
  * find it by its command line, which Linux cuts short of a long script.
@@ -3575,11 +3683,11 @@ const PID_FILE = "/tmp/reeval-egress-forwarder";
3575
3683
  /** How long `close()` waits for the sandbox to stop a forwarder a transport could orphan. */
3576
3684
  const CLOSE_TIMEOUT_MS = 1e4;
3577
3685
  /** Runs the forwarder; under a transport that orphans it, as the shell that wrote its pid file. */
3578
- function forwarderCommand(transport, tag) {
3686
+ function forwarderCommand(transport, tag, port) {
3579
3687
  const node = [
3580
3688
  "node",
3581
3689
  "-e",
3582
- forwarderScript(PROXY_PORT)
3690
+ forwarderScript(port)
3583
3691
  ];
3584
3692
  if (!transport.orphans) return node;
3585
3693
  return [
@@ -3606,31 +3714,50 @@ done; true`
3606
3714
  input: "",
3607
3715
  signal
3608
3716
  }).then(() => {}, () => {});
3609
- const installCa = (transport, cert, signal) => execRun(transport, [
3610
- "sh",
3611
- "-c",
3612
- `umask 022 && mkdir -p "$(dirname ${CA_PATH})" && cat > ${CA_PATH} && { command -v update-ca-certificates >/dev/null && update-ca-certificates >/dev/null 2>&1 && grep -q "$(sed -n 2p ${CA_PATH})" ${CA_BUNDLE} && echo ${BUNDLED}; true; }`
3613
- ], {
3614
- input: cert,
3615
- signal
3616
- });
3717
+ const installCa = (transport, cert, o, signal) => {
3718
+ const inBundle = `grep -q "$(sed -n 2p ${o.caPath})" ${CA_BUNDLE}`;
3719
+ const rebuild = "command -v update-ca-certificates >/dev/null && update-ca-certificates >/dev/null 2>&1";
3720
+ if (!o.shared) return execRun(transport, [
3721
+ "sh",
3722
+ "-c",
3723
+ `umask 022 && mkdir -p "$(dirname ${o.caPath})" && cat > ${o.caPath} && { ${rebuild} && ${inBundle} && echo ${BUNDLED}; true; }`
3724
+ ], {
3725
+ input: cert,
3726
+ signal
3727
+ });
3728
+ const bundle = `{ ${inBundle} || { ${rebuild}; }; } && ${inBundle} && echo ${BUNDLED}; true`;
3729
+ return execRun(transport, [
3730
+ "sh",
3731
+ "-c",
3732
+ `umask 022 && mkdir -p "$(dirname ${o.caPath})" && cat > ${o.caPath}.$$ && mv ${o.caPath}.$$ ${o.caPath} && flock ${CA_LOCK} sh -c '${bundle}'`
3733
+ ], {
3734
+ input: cert,
3735
+ signal
3736
+ });
3737
+ };
3617
3738
  /**
3618
3739
  * Starts the egress gateway for one sandbox: a forwarder inside it, tunneled over one process
3619
3740
  * `transport` starts there, and the proxy in this process, which holds the real credentials.
3620
3741
  */
3621
3742
  async function startGateway(transport, options, signal) {
3743
+ const { port: asked, ...proxyOptions } = options;
3744
+ const place = placement(asked);
3745
+ const { port } = place;
3622
3746
  const ca = createCertificateAuthority();
3623
- const installed = await installCa(transport, ca.cert, signal);
3747
+ const installed = await installCa(transport, ca.cert, {
3748
+ caPath: place.caPath,
3749
+ shared: asked !== void 0
3750
+ }, signal);
3624
3751
  if (installed.exitCode !== 0) throw new Error(`couldn't install the gateway CA: ${installed.stderr.trim()}`);
3625
3752
  const bundled = installed.stdout.toString("utf8").includes(BUNDLED);
3626
- if (transport.orphans) await killForwarders(transport, "*", signal);
3753
+ if (transport.orphans) await killForwarders(transport, place.tags, signal);
3627
3754
  signal?.throwIfAborted();
3628
- const tag = randomBytes(6).toString("hex");
3755
+ const tag = `${place.tag}${randomBytes(6).toString("hex")}`;
3629
3756
  const proxy = createEgressProxy({
3630
- ...options,
3757
+ ...proxyOptions,
3631
3758
  ca
3632
3759
  });
3633
- const child = execSpawn(transport, forwarderCommand(transport, tag));
3760
+ const child = execSpawn(transport, forwarderCommand(transport, tag, port));
3634
3761
  let stderr = "";
3635
3762
  child.stderr.on("data", (d) => {
3636
3763
  stderr += d;
@@ -3644,8 +3771,8 @@ async function startGateway(transport, options, signal) {
3644
3771
  send: (frame) => {
3645
3772
  if (!closed) child.stdin.write(frame);
3646
3773
  },
3647
- onOpen(stream, port) {
3648
- if (port === 43128) proxy.handle(stream);
3774
+ onOpen(stream, opened) {
3775
+ if (opened === port) proxy.handle(stream);
3649
3776
  else stream.destroy();
3650
3777
  },
3651
3778
  onReady: () => {
@@ -3703,7 +3830,7 @@ async function startGateway(transport, options, signal) {
3703
3830
  clearTimeout(timer);
3704
3831
  signal?.removeEventListener("abort", onAbort);
3705
3832
  }
3706
- const proxyUrl = `http://127.0.0.1:${PROXY_PORT}`;
3833
+ const proxyUrl = `http://127.0.0.1:${port}`;
3707
3834
  const noProxy = "localhost,127.0.0.1,::1,[::1]";
3708
3835
  return {
3709
3836
  env: {
@@ -3713,7 +3840,7 @@ async function startGateway(transport, options, signal) {
3713
3840
  http_proxy: proxyUrl,
3714
3841
  NO_PROXY: noProxy,
3715
3842
  no_proxy: noProxy,
3716
- NODE_EXTRA_CA_CERTS: CA_PATH,
3843
+ NODE_EXTRA_CA_CERTS: place.caPath,
3717
3844
  NODE_USE_ENV_PROXY: "1",
3718
3845
  ...bundled ? {
3719
3846
  SSL_CERT_FILE: CA_BUNDLE,
@@ -4048,9 +4175,10 @@ async function createDockerSession(options) {
4048
4175
  });
4049
4176
  let gateway;
4050
4177
  let removed;
4178
+ const observers = [];
4051
4179
  const remove = () => {
4052
4180
  gateway?.close();
4053
- removed ??= removeContainerDetached(id, engine);
4181
+ removed ??= Promise.all([id, ...observers].map((c) => removeContainerDetached(c, engine))).then(() => {});
4054
4182
  return removed;
4055
4183
  };
4056
4184
  if (signal?.aborted) {
@@ -4232,6 +4360,119 @@ async function createDockerSession(options) {
4232
4360
  throw error;
4233
4361
  }
4234
4362
  };
4363
+ /** Runs the engine's CLI with its output streamed; `stop` ends what it started. */
4364
+ const streamed = (args, stop) => {
4365
+ const startedAt = Date.now();
4366
+ const child = spawn(spec.bin, args, {
4367
+ stdio: [
4368
+ "ignore",
4369
+ "pipe",
4370
+ "pipe"
4371
+ ],
4372
+ detached: true,
4373
+ env: {
4374
+ ...process.env,
4375
+ ...engineEnv(engine)
4376
+ }
4377
+ });
4378
+ child.stderr.resume();
4379
+ const exited = new Promise((resolve) => {
4380
+ child.once("error", () => resolve({ exitCode: 127 }));
4381
+ child.once("close", (code) => {
4382
+ traceDocker(args, startedAt, {
4383
+ exitCode: code,
4384
+ stdout: "<streamed>"
4385
+ }, spec.bin);
4386
+ resolve({ exitCode: code ?? 1 });
4387
+ });
4388
+ });
4389
+ return {
4390
+ pid: child.pid,
4391
+ stdout: Readable.toWeb(child.stdout),
4392
+ wait: () => exited,
4393
+ kill: async () => {
4394
+ child.kill("SIGKILL");
4395
+ await stop();
4396
+ }
4397
+ };
4398
+ };
4399
+ const spawnPrivileged = async (o) => {
4400
+ const marker = nextMarker();
4401
+ return streamed([
4402
+ "exec",
4403
+ "--user",
4404
+ "0:0",
4405
+ "--workdir",
4406
+ SANDBOX_STATE,
4407
+ "--env",
4408
+ `${EXEC_MARKER$1}=${marker}`,
4409
+ "--env",
4410
+ `PATH=${SYSTEM_PATH$1}`,
4411
+ id,
4412
+ "/bin/sh",
4413
+ "-c",
4414
+ o.command
4415
+ ], () => killExec(marker, true));
4416
+ };
4417
+ const observer = {
4418
+ target: id,
4419
+ async spawn(o) {
4420
+ if (removed) throw new Error(`${spec.name} container ${id.slice(0, 12)} is gone`);
4421
+ const name = `reeval-observer-${nonce}-${observers.length + 1}`;
4422
+ observers.push(name);
4423
+ const args = [
4424
+ "run",
4425
+ "--rm",
4426
+ "--name",
4427
+ name,
4428
+ ...Object.entries(labels).flatMap(([k, v]) => ["--label", `${k}=${v}`]),
4429
+ "--pull",
4430
+ "never",
4431
+ "--network",
4432
+ "none",
4433
+ "--cgroupns",
4434
+ "host",
4435
+ "--user",
4436
+ "65534:65534",
4437
+ "--cap-drop",
4438
+ "ALL",
4439
+ "--security-opt",
4440
+ "no-new-privileges",
4441
+ "--read-only",
4442
+ "--pids-limit",
4443
+ "16",
4444
+ "--entrypoint",
4445
+ "/bin/sh",
4446
+ options.image,
4447
+ "-c",
4448
+ o.command
4449
+ ];
4450
+ return streamed(args, () => removeContainerDetached(name, engine));
4451
+ },
4452
+ async run(o) {
4453
+ const name = observers.at(-1);
4454
+ if (!name) return {
4455
+ exitCode: 1,
4456
+ stdout: "",
4457
+ stderr: "no observer started"
4458
+ };
4459
+ const r = await docker([
4460
+ "exec",
4461
+ name,
4462
+ "/bin/sh",
4463
+ "-c",
4464
+ o.command
4465
+ ], {
4466
+ signal: o.abortSignal,
4467
+ engine
4468
+ });
4469
+ return {
4470
+ exitCode: r.exitCode,
4471
+ stdout: r.stdout.toString("utf8"),
4472
+ stderr: r.stderr
4473
+ };
4474
+ }
4475
+ };
4235
4476
  const readBinaryFile = async (o) => {
4236
4477
  const r = await docker([
4237
4478
  "exec",
@@ -4338,6 +4579,8 @@ async function createDockerSession(options) {
4338
4579
  oomKills: () => oomKills(id, engine, execUser(options)),
4339
4580
  run,
4340
4581
  runPrivileged,
4582
+ spawnPrivileged,
4583
+ observer,
4341
4584
  spawn: (async (o) => {
4342
4585
  if (o.stdin) throw new Error(`A ${spec.name} sandbox process has no writable stdin`);
4343
4586
  const env = envFor(o.env);
@@ -4463,108 +4706,52 @@ const dockerSandboxProvider = (options) => ({
4463
4706
  const PNPM_VERSION = "10.33.3";
4464
4707
  /** Pinned so evals' installs don't move with the Node image's bundled npm. */
4465
4708
  const NPM_VERSION = "11.20.0";
4709
+ const sha256 = (text) => createHash("sha256").update(text).digest("hex");
4710
+ /** Docker's names for Node's architectures, as image indexes list platforms. */
4711
+ const OCI_ARCH = {
4712
+ x64: "amd64",
4713
+ arm64: "arm64",
4714
+ arm: "arm",
4715
+ ppc64: "ppc64le"
4716
+ };
4466
4717
  /**
4467
- * The official Node image the sandbox's Node comes from: the base Dockerfile's `FROM` (a test holds
4468
- * them equal) and the toolchain layer's copy onto a `from` image. Node 24+ bundles undici 7, whose
4469
- * `EnvHttpProxyAgent` (behind `NODE_USE_ENV_PROXY`) prints no experimental warning.
4718
+ * Linux on this process's architecture, as `docker image inspect` names a platform
4719
+ * (`.Os/.Architecture`): what Docker Desktop's and Podman's VMs run, and the fallback when the
4720
+ * engine doesn't say its own (`enginePlatform`).
4470
4721
  */
4471
- const NODE_IMAGE = "node:26-bookworm-slim";
4472
- const sha256 = (text) => createHash("sha256").update(text).digest("hex");
4722
+ const PLATFORM = `linux/${OCI_ARCH[process.arch] ?? process.arch}`;
4473
4723
  const slugify = (text, max) => text.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, max).replace(/-+$/, "");
4474
4724
  /** The build context of reeval's base image, shipped in the package. */
4475
4725
  const DOCKER_CONTEXT = fileURLToPath(ownFileURL("docker"));
4476
4726
  /**
4477
- * How reeval bakes a harness into an image, beyond the build context and the adapter: bump it when
4478
- * that changes what a baked image holds, so every image baked before rebuilds on its next use.
4727
+ * The official Node image the sandbox's Node comes from, pinned by its index digest: the base
4728
+ * Dockerfile's `FROM`, which the toolchain layer also copies onto a `from` image. The pin is what
4729
+ * makes reeval's image, and every key built on it, the same content on any machine. Node 24+
4730
+ * bundles undici 7, whose `EnvHttpProxyAgent` (behind `NODE_USE_ENV_PROXY`) prints no experimental
4731
+ * warning.
4732
+ */
4733
+ const NODE_IMAGE = /^FROM (\S+)$/m.exec(readFileSync(join(DOCKER_CONTEXT, "Dockerfile"), "utf8"))?.[1] ?? "node";
4734
+ /**
4735
+ * How reeval bakes a harness into a Docker or Tart image, beyond the build context, the adapter and
4736
+ * the inputs each passes {@link bakeKey}: bump it when that changes what a baked image holds, so
4737
+ * every image baked before rebuilds on its next use.
4479
4738
  */
4480
4739
  const BAKE_REVISION = 2;
4481
4740
  /**
4482
- * The image `docker({ from })` evals run in: `from` plus Node, git and the harness's CLI. The hash
4483
- * covers the toolchain layer and {@link BAKE_REVISION} too, so a change to the sandbox user, paths
4484
- * or how the harness is baked builds anew.
4741
+ * The hash a baked image's name ends with: {@link BAKE_REVISION} and what the bake starts from and
4742
+ * runs, so a change to any of them bakes anew.
4485
4743
  */
4486
- const harnessImageFor = (harness, from) => `${imageFor(harness)}-${slugify(from, 40) || "image"}-${sha256(`${BAKE_REVISION}\0${toolchainDockerfile(from)}`).slice(0, 8)}`;
4744
+ const bakeKey = (...inputs) => sha256([BAKE_REVISION, ...inputs].join("\0")).slice(0, 8);
4487
4745
  /**
4488
- * How each harness's CLI gets into an image: its adapter's bootstrap, and the binary it leaves
4489
- * (or, for an adapter without one, a command that prints what it installed).
4746
+ * The image `docker({ from })` evals run in: `from` plus Node, git and the harness's CLI. Its
4747
+ * {@link bakeKey} covers the toolchain layer, so a change to the sandbox user or paths builds anew.
4490
4748
  */
4491
- const BOOTSTRAPS = {
4492
- cursor: {
4493
- name: "Cursor",
4494
- cli: "@cursor/sdk",
4495
- version: `node -p "'@cursor/sdk ' + require(process.env.HOME + '/.ai-sdk-harness/.harness-bootstrap/cursor-sdk/node_modules/@cursor/sdk/package.json').version"`,
4496
- adapter: async () => (await import("./src-CeBhwD8k.js")).createCursorSdk()
4497
- },
4498
- "claude-code": {
4499
- name: "Claude Code",
4500
- cli: "claude",
4501
- adapter: async () => (await import("./dist-DeqeCUZe.js")).createClaudeCode()
4502
- },
4503
- antigravity: {
4504
- name: "Antigravity",
4505
- cli: "agy",
4506
- adapter: async () => (await import("./src-C-mOSczH.js")).createAntigravity()
4507
- },
4508
- opencode: {
4509
- name: "OpenCode",
4510
- cli: "opencode",
4511
- adapter: async () => (await import("./src-CZaYu6ER.js")).createOpenCode({
4512
- auth: { GOOGLE_GENERATIVE_AI_API_KEY: "unused" },
4513
- model: "google/unused"
4514
- })
4515
- },
4516
- goose: {
4517
- name: "Goose",
4518
- cli: "goose",
4519
- adapter: async () => {
4520
- const goose = await import("./src-CkEiiyON.js");
4521
- return goose.createGoose({
4522
- auth: { GOOGLE_API_KEY: "unused" },
4523
- provider: goose.GEMINI_PROVIDER,
4524
- model: "unused"
4525
- });
4526
- }
4527
- },
4528
- pi: {
4529
- name: "pi",
4530
- cli: "pi",
4531
- adapter: async () => {
4532
- const pi = await import("./src-DA95rM6v.js");
4533
- const provider = pi.piProvider("google");
4534
- if ("refused" in provider) throw new Error(provider.refused);
4535
- return pi.createPi({
4536
- auth: { GEMINI_API_KEY: "unused" },
4537
- provider
4538
- });
4539
- }
4540
- },
4541
- codex: {
4542
- name: "Codex",
4543
- cli: "codex",
4544
- adapter: async () => (await import("./src--yl1OypK.js")).createCodex({ auth: { OPENAI_API_KEY: "unused" } })
4545
- },
4546
- fx: {
4547
- name: "fx",
4548
- cli: "fx",
4549
- adapter: async () => (await import("./src-CwH_nEaw.js")).createFx({
4550
- auth: { AI_GATEWAY_API_KEY: "unused" },
4551
- model: "unused/unused"
4552
- })
4553
- },
4554
- "grok-build": {
4555
- name: "Grok Build",
4556
- cli: "grok",
4557
- adapter: async () => (await import("./src-De0KY5S_.js")).createGrokBuild({
4558
- auth: { XAI_API_KEY: "unused" },
4559
- model: "unused"
4560
- })
4561
- }
4562
- };
4749
+ const harnessImageFor = (harness, from) => `${imageFor(harness)}-${slugify(from, 40) || "image"}-${bakeKey(toolchainDockerfile(from))}`;
4563
4750
  /**
4564
4751
  * The adapter whose bootstrap `harness`'s image bakes. An attempt whose adapter asks for any other
4565
4752
  * bootstrap reinstalls the CLI at start, which a restricted egress policy can refuse.
4566
4753
  */
4567
- const bakedAdapter = (harness) => BOOTSTRAPS[harness].adapter();
4754
+ const bakedAdapter = (harness) => HARNESS_PACKAGES[harness].bootstrap.adapter();
4568
4755
  /** Keeps the image's `PATH` in login shells, which Debian's `/etc/profile` resets. */
4569
4756
  const profilePathScript = () => readFileSync(join(DOCKER_CONTEXT, "reeval-path.sh")).toString("base64");
4570
4757
  /** `from` as it goes after `FROM`: one word, so it can't add a stage name or another instruction. */
@@ -4637,6 +4824,12 @@ function buildError(output, what, reason, keep = () => true) {
4637
4824
  }
4638
4825
  /** Every image reeval builds carries this label, so `reeval clean --images` can find what it left. */
4639
4826
  const BUILT_BY = ["--label", `${LABEL.managed}=image`];
4827
+ const keyLabel = (key) => ["--label", `${LABEL.key}=${key}`];
4828
+ /** Removes the image `tag` pointed at before a rebuild, once the tag points elsewhere. */
4829
+ async function replaced(tag, previous, engine) {
4830
+ if (!previous) return;
4831
+ if ((await imageInfo(tag, engine))?.id !== previous) await removeQuietly(previous, engine);
4832
+ }
4640
4833
  /**
4641
4834
  * Removes the images reeval built that nothing tags any more (a rebuild's old image) and the
4642
4835
  * intermediate `-base` tags of `from` builds. Returns how many it removed.
@@ -4673,13 +4866,6 @@ async function pruneImages(engine) {
4673
4866
  ], { engine }).catch(() => null))?.exitCode === 0) removed++;
4674
4867
  return removed;
4675
4868
  }
4676
- /** Docker's names for Node's architectures, as image indexes list platforms. */
4677
- const OCI_ARCH = {
4678
- x64: "amd64",
4679
- arm64: "arm64",
4680
- arm: "arm",
4681
- ppc64: "ppc64le"
4682
- };
4683
4869
  /**
4684
4870
  * A registry digest for `from` without Docker's buildx: skopeo's, which is the same digest
4685
4871
  * buildx gives, or else this platform's manifest from `podman manifest inspect`.
@@ -4773,6 +4959,28 @@ function contextHash() {
4773
4959
  return hash.digest("hex").slice(0, 16);
4774
4960
  }
4775
4961
  /**
4962
+ * reeval's image for a harness: its tag (the adapter) and its base's build context, whose `FROM` is
4963
+ * pinned by digest.
4964
+ */
4965
+ const reevalImageKey = (harness) => `${imageFor(harness)}+${contextHash()}`;
4966
+ /**
4967
+ * A harness baked onto `from`: its tag and what `from` named when it was built, a registry digest
4968
+ * (or, for a base only this machine has, its image id, or a Dockerfile image's own key).
4969
+ */
4970
+ const fromImageKey = (ref, digest) => `${ref}@${digest}`;
4971
+ /**
4972
+ * The key of an image only this machine can name, such as a Dockerfile built on a base that didn't
4973
+ * resolve: its tag and local image id. Nothing keyed on one is pulled or pushed.
4974
+ */
4975
+ const localKey = (ref, id) => `${ref}@local:${id}`;
4976
+ /** Whether `key` is a {@link localKey}, or a key built on one. */
4977
+ const isLocalKey = (key) => key.includes("@local:");
4978
+ /**
4979
+ * An image reeval uses as is: its image id, which is content-addressed, so the same on every machine
4980
+ * that pulled it (and this machine's alone for one built here), whichever registries it's in.
4981
+ */
4982
+ const imageKey = (info) => info.id;
4983
+ /**
4776
4984
  * Bakes a harness's bootstrap (which installs its agent's CLI) into an image, so the image tag
4777
4985
  * pins the CLI build. Rebuild after bumping the adapter. With `from`, the base is that toolchain
4778
4986
  * image instead of reeval's Node image. `log` gets progress lines, `output` the build's full output
@@ -4784,9 +4992,11 @@ async function buildImage(log, options) {
4784
4992
  const resolved = from ? await resolveFrom(from, signal, engine) : null;
4785
4993
  const digest = resolved && "digest" in resolved ? resolved.digest : null;
4786
4994
  const pinned = from && digest && resolved && "local" in resolved && !resolved.local && !from.includes("@") ? `${from}@${digest}` : from;
4787
- const bootstrap = BOOTSTRAPS[harness];
4995
+ const { bootstrap } = HARNESS_PACKAGES[harness];
4788
4996
  const base = from ? `${harnessImageFor(harness, from)}-base` : BASE_IMAGE;
4789
4997
  const target = from ? harnessImageFor(harness, from) : imageFor(harness);
4998
+ const shared = !!resolved && "local" in resolved && !resolved.local;
4999
+ const key = options.key ?? (from ? digest && shared ? fromImageKey(target, digest) : "" : reevalImageKey(harness));
4790
5000
  const previous = [(await imageInfo(target, engine))?.id, from ? null : (await imageInfo(base, engine))?.id];
4791
5001
  log(`Building ${base}${from ? ` from ${from}` : ""}`);
4792
5002
  const build = from ? await docker([
@@ -4837,11 +5047,11 @@ async function buildImage(log, options) {
4837
5047
  let agentVersion;
4838
5048
  try {
4839
5049
  agentVersion = await bake(session, bootstrap);
4840
- log(`${bootstrap.name} ${bootstrap.version ? "" : "CLI "}${agentVersion}`);
5050
+ log(`${bootstrap.name} ${bootstrap.probe ? "" : "CLI "}${agentVersion}`);
4841
5051
  await dockerOk([
4842
5052
  "commit",
4843
5053
  "--change",
4844
- `LABEL ${LABEL.agentVersion}="${agentVersion}" ${LABEL.harness}="${harnessLabel(harness)}"${from ? digest ? ` ${LABEL.fromDigest}="${digest}"` : "" : ` ${LABEL.context}="${contextHash()}"`}`,
5054
+ `LABEL ${LABEL.agentVersion}="${agentVersion}" ${LABEL.harness}="${harnessLabel(harness)}"${from ? digest ? ` ${LABEL.fromDigest}="${digest}"` : "" : ` ${LABEL.context}="${contextHash()}"`} ${LABEL.key}="${key}"`,
4845
5055
  "--change",
4846
5056
  `WORKDIR ${SANDBOX_ROOT}`,
4847
5057
  "--change",
@@ -4886,13 +5096,13 @@ async function buildImage(log, options) {
4886
5096
  * Runs `harness`'s bootstrap in `session` (a container, or a VM reeval then keeps as an image)
4887
5097
  * and returns the CLI version it installed.
4888
5098
  */
4889
- const bakeHarness = (session, harness) => bake(session, BOOTSTRAPS[harness]);
5099
+ const bakeHarness = (session, harness) => bake(session, HARNESS_PACKAGES[harness].bootstrap);
4890
5100
  /**
4891
5101
  * A hash of the bootstrap `harness`'s adapter applies (its files and commands): it changes
4892
5102
  * whenever what the bootstrap installs does, version bump or not.
4893
5103
  */
4894
5104
  async function bakedRecipe(harness) {
4895
- const recipe = await (await BOOTSTRAPS[harness].adapter()).getBootstrap?.({});
5105
+ const recipe = await (await HARNESS_PACKAGES[harness].bootstrap.adapter()).getBootstrap?.({});
4896
5106
  if (!recipe) return "none";
4897
5107
  const files = [...recipe.files].sort((a, b) => a.path.localeCompare(b.path)).map((f) => [f.path, f.content]);
4898
5108
  return createHash("sha256").update(JSON.stringify([
@@ -4903,29 +5113,29 @@ async function bakedRecipe(harness) {
4903
5113
  ])).digest("hex").slice(0, 16);
4904
5114
  }
4905
5115
  /** The harness's name, as a bake's progress says it. */
4906
- const bakedHarnessName = (harness) => BOOTSTRAPS[harness].name;
5116
+ const bakedHarnessName = (harness) => HARNESS_PACKAGES[harness].bootstrap.name;
4907
5117
  /** Runs the harness bootstrap in `session` and returns the CLI version it installed. */
4908
5118
  async function bake(session, bootstrap) {
4909
5119
  await (await createHarnessSandboxTemplate({
4910
5120
  harnesses: [await bootstrap.adapter()],
4911
5121
  sandboxConfig: { workDir: WORKSPACE_DIR }
4912
5122
  }))?.prepare({ session });
4913
- let probe = bootstrap.version;
5123
+ let probe = bootstrap.probe;
4914
5124
  if (!probe) {
4915
5125
  const bin = (await session.run({ command: `find "$HOME/.ai-sdk-harness" -name ${bootstrap.cli} \\( -type f -o -type l \\) -perm -u+x | head -1` })).stdout.trim();
4916
5126
  if (!bin) throw new Error(`The harness bootstrap did not install the ${bootstrap.name} CLI`);
4917
5127
  probe = `'${bin}' --version`;
4918
5128
  }
4919
5129
  const version = await session.run({ command: probe });
4920
- if (bootstrap.version && version.exitCode !== 0) throw new Error(`The harness bootstrap did not install ${bootstrap.cli}:\n${tail(version.stderr)}`);
5130
+ if (bootstrap.probe && version.exitCode !== 0) throw new Error(`The harness bootstrap did not install ${bootstrap.cli}:\n${tail(version.stderr)}`);
4921
5131
  return versionLabel(version.stdout.trim());
4922
5132
  }
4923
5133
  /**
4924
5134
  * The image `docker({ install })` runs in: the commands on top of `parent`, tagged by the parent's
4925
- * id and the exact list, so it's built once. Secrets and the workspace never exist here.
5135
+ * content key and the exact list, so it's built once. Secrets and the workspace never exist here.
4926
5136
  */
4927
5137
  const installLayerTag = (parent, steps) => `reeval-install:${sha256(JSON.stringify({
4928
- parent: parent.id,
5138
+ parent: parent.key,
4929
5139
  steps
4930
5140
  })).slice(0, 16)}`;
4931
5141
  /** The commands as one bash script: in order, from `/`, stopping at the first that fails. */
@@ -4939,20 +5149,15 @@ function installScript(steps) {
4939
5149
  }
4940
5150
  return `${lines.join("\n")}\n`;
4941
5151
  }
4942
- /** Builds the install layer if it's missing. `output` gets the build's output, for a log file. */
5152
+ /**
5153
+ * Builds the install layer if it's missing, or again with `force` (`reeval image build --force`,
5154
+ * whose rebuilt parent keeps its key). `output` gets the build's output, for a log file.
5155
+ */
4943
5156
  async function buildInstallLayer(parent, steps, options = {}) {
4944
5157
  const { signal, engine } = options;
4945
5158
  const tag = installLayerTag(parent, steps);
4946
- if ((await docker([
4947
- "image",
4948
- "inspect",
4949
- "--format",
4950
- "{{.Created}}",
4951
- tag
4952
- ], {
4953
- signal,
4954
- engine
4955
- })).exitCode === 0) return tag;
5159
+ const previous = (await imageInfo(tag, engine))?.id;
5160
+ if (previous && !options.force) return tag;
4956
5161
  const script = installScript(steps);
4957
5162
  const encoded = Buffer.from(script).toString("base64");
4958
5163
  const home = `$(getent passwd ${SANDBOX_USER} | cut -d: -f6)`;
@@ -4970,6 +5175,7 @@ async function buildInstallLayer(parent, steps, options = {}) {
4970
5175
  "--progress",
4971
5176
  "plain",
4972
5177
  ...BUILT_BY,
5178
+ ...keyLabel(tag),
4973
5179
  "--tag",
4974
5180
  tag,
4975
5181
  "-"
@@ -4990,6 +5196,7 @@ async function buildInstallLayer(parent, steps, options = {}) {
4990
5196
  engine
4991
5197
  }, () => failed ? `install ${failed[1]} exited ${failed[2]}: ${clipLine(failed[3] ?? "")}` : null, (line) => !line.startsWith("reeval: install "));
4992
5198
  }
5199
+ await replaced(tag, previous, engine);
4993
5200
  return tag;
4994
5201
  }
4995
5202
  /** Where a plugin layer leaves each built plugin, by its build's hash. */
@@ -5018,8 +5225,8 @@ const pluginBuildKey = (b) => sha256(JSON.stringify({
5018
5225
  cwd: b.cwd,
5019
5226
  run: b.steps
5020
5227
  }));
5021
- /** The image a plugin build makes on `parent`: the parent's id, then the build's hash. */
5022
- const pluginLayerTag = (parent, b) => `reeval-plugin:${parent.id.replace(/^sha256:/, "").slice(0, 12)}-${pluginBuildKey(b).slice(0, 16)}`;
5228
+ /** The image a plugin build makes on `parent`: the parent's content key, then the build's hash. */
5229
+ const pluginLayerTag = (parent, b) => `reeval-plugin:${sha256(parent.key).slice(0, 12)}-${pluginBuildKey(b).slice(0, 16)}`;
5023
5230
  /** Where a plugin layer leaves the plugin's directory. */
5024
5231
  const pluginBuildDir = (b) => `${PLUGIN_BUILDS_DIR}/${pluginBuildKey(b).slice(0, 16)}`;
5025
5232
  /** The line a plugin build's script fails with when its `cwd` isn't in the source. */
@@ -5037,16 +5244,8 @@ const pluginBuildScript = (b, src) => installScript(b.steps).replaceAll("reeval:
5037
5244
  async function buildPluginLayer(parent, b, options) {
5038
5245
  const { signal, engine } = options;
5039
5246
  const tag = pluginLayerTag(parent, b);
5040
- if ((await docker([
5041
- "image",
5042
- "inspect",
5043
- "--format",
5044
- "{{.Created}}",
5045
- tag
5046
- ], {
5047
- signal,
5048
- engine
5049
- })).exitCode === 0) return tag;
5247
+ const previous = (await imageInfo(tag, engine))?.id;
5248
+ if (previous && !options.force) return tag;
5050
5249
  const src = "/tmp/reeval-plugin-src";
5051
5250
  const script = pluginBuildScript(b, src);
5052
5251
  const encoded = Buffer.from(script).toString("base64");
@@ -5069,6 +5268,7 @@ async function buildPluginLayer(parent, b, options) {
5069
5268
  "--progress",
5070
5269
  "plain",
5071
5270
  ...BUILT_BY,
5271
+ ...keyLabel(tag),
5072
5272
  "--tag",
5073
5273
  tag,
5074
5274
  "-f",
@@ -5092,6 +5292,7 @@ async function buildPluginLayer(parent, b, options) {
5092
5292
  engine
5093
5293
  }, () => missing ? noCwd(b.cwd).slice(8) : failed ? `build ${failed[1]} exited ${failed[2]}: ${clipLine(failed[3] ?? "")}` : null, (line) => !line.startsWith("reeval: build "));
5094
5294
  }
5295
+ await replaced(tag, previous, engine);
5095
5296
  return tag;
5096
5297
  }
5097
5298
  /** The build arg a Dockerfile can start `FROM` to layer on reeval's sandbox image. */
@@ -5101,12 +5302,13 @@ const usesReevalBase = (dockerfile) => new RegExp(`\\$\\{?${REEVAL_BASE_ARG}\\b`
5101
5302
  /**
5102
5303
  * The tag of a `docker({ dockerfile })` build for a harness: a hash of the Dockerfile, every file
5103
5304
  * of its build context (its directory, less `.dockerignore`) and, for a Dockerfile `FROM
5104
- * ${REEVAL_BASE}`, the id of the harness's image it names, so an edit to any of them, or a rebuilt reeval
5105
- * image, builds anew. `reevalBase` is that id (null when it isn't built).
5305
+ * ${REEVAL_BASE}`, the {@link reevalImageKey} of the harness's image it names, so an edit to any of
5306
+ * them, or a new reeval base, builds anew, and the same files give the same tag on any machine. What
5307
+ * its other bases' tags name is in its key ({@link dockerfileKey}), not its tag.
5106
5308
  */
5107
- function dockerfileTag(dockerfile, harness, reevalBase = null) {
5309
+ function dockerfileTag(dockerfile, harness) {
5108
5310
  const context = dirname(dockerfile);
5109
- const base = usesReevalBase(dockerfile) ? `${imageFor(harness)}@${reevalBase ?? "unbuilt"}` : "";
5311
+ const base = usesReevalBase(dockerfile) ? reevalImageKey(harness) : "";
5110
5312
  const hash = createHash("sha256").update(`${REEVAL_BASE_ARG}=${base}\0`);
5111
5313
  for (const path of contextFiles(context, dockerfile)) {
5112
5314
  const full = join(context, path);
@@ -5122,14 +5324,57 @@ function dockerfileTag(dockerfile, harness, reevalBase = null) {
5122
5324
  };
5123
5325
  }
5124
5326
  /**
5327
+ * The images a Dockerfile's `FROM`, `COPY --from` and `--mount=…,from=` name by a tag that can
5328
+ * move: not `${REEVAL_BASE}`, an earlier stage, `scratch` or a digest-pinned image. `opaque` when
5329
+ * one names an image through any other build arg, which only the build resolves.
5330
+ */
5331
+ function dockerfileBases(dockerfile) {
5332
+ const stages = /* @__PURE__ */ new Set();
5333
+ const bases = [];
5334
+ let opaque = false;
5335
+ const reevalBase = new RegExp(`^\\$\\{?${REEVAL_BASE_ARG}\\}?$`);
5336
+ const add = (image) => {
5337
+ const name = image.toLowerCase();
5338
+ if (image.includes("$")) {
5339
+ if (!reevalBase.test(image)) opaque = true;
5340
+ return;
5341
+ }
5342
+ if (stages.has(name) || name === "scratch" || /^\d+$/.test(name)) return;
5343
+ if (/@sha256:[0-9a-f]{64}$/.test(image) || bases.includes(image)) return;
5344
+ bases.push(image);
5345
+ };
5346
+ const text = readFileSync(dockerfile, "utf8").replace(/\\[ \t]*\r?\n/g, " ");
5347
+ for (const line of text.split("\n")) {
5348
+ if (/^\s*#/.test(line)) continue;
5349
+ const from = /^\s*FROM\s+(?:--platform=\S+\s+)?(\S+)(?:\s+AS\s+(\S+))?/i.exec(line);
5350
+ if (from?.[1]) {
5351
+ add(from[1]);
5352
+ if (from[2]) stages.add(from[2].toLowerCase());
5353
+ }
5354
+ if (!/^\s*(?:COPY|ADD|RUN)\s/i.test(line)) continue;
5355
+ for (const m of line.matchAll(/(?:^|\s)--from=(\S+)/gi)) if (m[1]) add(m[1]);
5356
+ for (const m of line.matchAll(/--mount=\S*?\bfrom=([^,\s]+)/gi)) if (m[1]) add(m[1]);
5357
+ }
5358
+ return {
5359
+ bases,
5360
+ opaque
5361
+ };
5362
+ }
5363
+ /**
5364
+ * A Dockerfile image's content key: its tag, plus the digest each of its {@link dockerfileBases}
5365
+ * named when it was built, so a base that moved upstream is another image. One whose bases can't all
5366
+ * be named this way is keyed on its local image id instead ({@link localKey}).
5367
+ */
5368
+ const dockerfileKey = (tag, bases) => bases.length ? `${tag}+${bases.map((b) => `${b.ref}@${b.digest}`).join(",")}` : tag;
5369
+ /**
5125
5370
  * Builds the user's Dockerfile with plain `docker build` (so Docker's layer cache applies), from
5126
- * its directory, with `REEVAL_BASE` set to the harness's sandbox image (whose id is `reevalBase`).
5371
+ * its directory, with `REEVAL_BASE` set to the harness's sandbox image.
5127
5372
  * Rebuilds even when the tag exists with `force`, as `reeval image build` does, and then removes the
5128
5373
  * image the tag pointed at before. `name` is the path failures name.
5129
5374
  */
5130
5375
  async function buildDockerfile(dockerfile, options) {
5131
5376
  const { harness, signal, engine } = options;
5132
- const { tag } = dockerfileTag(dockerfile, harness, options.reevalBase ?? null);
5377
+ const { tag } = dockerfileTag(dockerfile, harness);
5133
5378
  const previous = (await imageInfo(tag, engine))?.id;
5134
5379
  if (previous && !options.force) return tag;
5135
5380
  const build = await docker([
@@ -5137,6 +5382,7 @@ async function buildDockerfile(dockerfile, options) {
5137
5382
  "--progress",
5138
5383
  "plain",
5139
5384
  ...BUILT_BY,
5385
+ ...keyLabel(options.key ?? tag),
5140
5386
  ...options.pull ? ["--pull"] : [],
5141
5387
  "--file",
5142
5388
  dockerfile,
@@ -5168,301 +5414,478 @@ async function buildDockerfile(dockerfile, options) {
5168
5414
  * and logs when it answers `initialize` (see its header). It runs in any sandbox with `node`.
5169
5415
  */
5170
5416
  const MCP_TIMER = fileURLToPath(ownFileURL("bin/mcp-timer.cjs"));
5171
- // ../sandbox-docker/src/ssh-session.ts
5417
+ // ../sandbox-docker/src/registry.ts
5418
+ /**
5419
+ * What's wrong with a registry prefix, or null: a registry host (with an optional port) and an
5420
+ * optional path, as `docker push` names one, without a scheme, tag or digest.
5421
+ */
5422
+ function registryProblem(registry) {
5423
+ if (/^[a-z0-9.-]+(:\d+)?(\/[a-z0-9]+([._-]+[a-z0-9]+)*)*\/?$/.test(registry)) return null;
5424
+ return `--registry is a registry and an optional path, such as ghcr.io/acme/reeval or localhost:5000/reeval, in lowercase without a scheme, tag or digest (got ${JSON.stringify(registry)})`;
5425
+ }
5426
+ /**
5427
+ * Where a layer goes in `registry`: its repository under the prefix, with its tag, plus its content
5428
+ * key's hash where the tag alone doesn't pin what's in it (reeval's own image and a `from` image),
5429
+ * and the platform, so one machine's push is another's pull only when they'd have built the same
5430
+ * thing for the same architecture.
5431
+ */
5432
+ function registryRef(registry, layer, platform = PLATFORM) {
5433
+ const at = layer.ref.lastIndexOf(":");
5434
+ const repository = layer.ref.slice(0, at);
5435
+ const tag = layer.ref.slice(at + 1);
5436
+ const pinned = layer.key === layer.ref ? tag : `${tag}-${createHash("sha256").update(layer.key).digest("hex").slice(0, 12)}`;
5437
+ return `${registry.replace(/\/+$/, "")}/${repository}:${pinned}-${platform.replaceAll("/", "-")}`;
5438
+ }
5439
+ const firstLine = (stderr) => stderr.trim().split("\n").filter(Boolean).at(-1)?.replace(/^Error(?: response from daemon)?: /, "") ?? "";
5440
+ /**
5441
+ * The platform the engine builds and pulls for, as its server says it (a remote `DOCKER_HOST`, or
5442
+ * x64 Node under Rosetta, can differ from this process's), or {@link PLATFORM} when it doesn't say.
5443
+ */
5444
+ async function enginePlatform(engine = "docker") {
5445
+ const r = await docker(engine === "podman" ? [
5446
+ "info",
5447
+ "--format",
5448
+ "{{.Host.OS}}/{{.Host.Arch}}"
5449
+ ] : [
5450
+ "version",
5451
+ "--format",
5452
+ "{{.Server.Os}}/{{.Server.Arch}}"
5453
+ ], { engine }).catch(() => null);
5454
+ const said = r?.exitCode === 0 ? r.stdout.toString("utf8").trim() : "";
5455
+ return /^[a-z0-9]+\/[a-z0-9]+$/.test(said) ? said : PLATFORM;
5456
+ }
5457
+ /**
5458
+ * Pulls `layer` from `registry` and tags it as its local ref, once it's checked: its
5459
+ * {@link LABEL.key} must be the layer's key and its platform the engine's ({@link enginePlatform}). `pulled: false` with
5460
+ * the reason when the registry doesn't have it, can't be reached or has another image under the
5461
+ * ref: the caller builds it instead. The registry is otherwise trusted: anyone who can push to it
5462
+ * chooses what a matching tag holds.
5463
+ */
5464
+ async function pullLayer(registry, layer, options = {}) {
5465
+ const { engine, signal } = options;
5466
+ const platform = await enginePlatform(engine);
5467
+ const remote = registryRef(registry, layer, platform);
5468
+ const pull = await docker([
5469
+ "pull",
5470
+ "--quiet",
5471
+ remote
5472
+ ], {
5473
+ engine,
5474
+ signal
5475
+ }).catch((error) => ({
5476
+ exitCode: 1,
5477
+ stderr: error.message
5478
+ }));
5479
+ if (pull.exitCode !== 0) return {
5480
+ pulled: false,
5481
+ remote,
5482
+ reason: firstLine(pull.stderr) || `exit ${pull.exitCode}`
5483
+ };
5484
+ try {
5485
+ const info = await imageInfo(remote, engine).catch(() => null);
5486
+ const key = info?.labels[LABEL.key];
5487
+ if (key !== layer.key) return {
5488
+ pulled: false,
5489
+ remote,
5490
+ reason: key ? `its ${LABEL.key} label is ${key}, not ${layer.key}` : `it has no ${LABEL.key} label`
5491
+ };
5492
+ if (info?.platform !== platform) return {
5493
+ pulled: false,
5494
+ remote,
5495
+ reason: `it's for ${info?.platform ?? "an unknown platform"}, not ${platform}`
5496
+ };
5497
+ const tag = await docker([
5498
+ "tag",
5499
+ remote,
5500
+ layer.ref
5501
+ ], {
5502
+ engine,
5503
+ signal
5504
+ });
5505
+ if (tag.exitCode !== 0) return {
5506
+ pulled: false,
5507
+ remote,
5508
+ reason: firstLine(tag.stderr) || `exit ${tag.exitCode}`
5509
+ };
5510
+ return {
5511
+ pulled: true,
5512
+ remote
5513
+ };
5514
+ } finally {
5515
+ await docker([
5516
+ "image",
5517
+ "rm",
5518
+ remote
5519
+ ], { engine }).catch(() => {});
5520
+ }
5521
+ }
5522
+ /**
5523
+ * Pushes `layer` to `registry` under {@link registryRef} for the platform the image says it's for
5524
+ * (or the engine's), and returns that ref.
5525
+ */
5526
+ async function pushLayer(registry, layer, options = {}) {
5527
+ const { engine, signal } = options;
5528
+ const { bin } = engineSpec(engine);
5529
+ const own = (await imageInfo(layer.ref, engine).catch(() => null))?.platform;
5530
+ const remote = registryRef(registry, layer, own ?? await enginePlatform(engine));
5531
+ const tag = await docker([
5532
+ "tag",
5533
+ layer.ref,
5534
+ remote
5535
+ ], {
5536
+ engine,
5537
+ signal
5538
+ });
5539
+ if (tag.exitCode !== 0) throw new Error(`${bin} tag ${layer.ref} ${remote} failed: ${firstLine(tag.stderr)}`);
5540
+ try {
5541
+ const push = await docker(["push", remote], {
5542
+ engine,
5543
+ signal
5544
+ });
5545
+ if (push.exitCode !== 0) throw new Error(`${bin} push ${remote} failed: ${firstLine(push.stderr)}`);
5546
+ } finally {
5547
+ await docker([
5548
+ "image",
5549
+ "rm",
5550
+ remote
5551
+ ], { engine }).catch(() => {});
5552
+ }
5553
+ return remote;
5554
+ }
5555
+ // ../sandbox-docker/src/shells.ts
5172
5556
  const SYSTEM_PATH = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin";
5173
- const EXEC_MARKER = "REEVAL_EXEC_ID";
5174
5557
  const EXEC_UMASK = "umask 022";
5175
- /** ssh's own exit status: it couldn't connect, or the connection dropped. */
5176
- const SSH_FAILED = 255;
5558
+ const EXEC_MARKER = "REEVAL_EXEC_ID";
5177
5559
  /** `NAME=value\0` for each variable, as the remote reader takes them on stdin. */
5178
5560
  const envStream = (env) => Object.entries(env).map(([k, v]) => `${k}=${v}\0`).join("");
5179
5561
  /**
5180
- * Runs `$2` with bash in `$1` as the sandbox user, after exporting the variables stdin carries.
5181
- * The command itself gets no stdin, as a `docker exec` without `--interactive` would.
5562
+ * Runs `$2` with bash in `$1` as the sandbox user, after exporting the variables stdin carries,
5563
+ * in a process group it leads. The command itself gets no stdin, as a `docker exec` without
5564
+ * `--interactive` would.
5182
5565
  */
5183
- const READER = `${EXEC_UMASK}; while IFS= read -r -d "" kv; do export "$kv"; done; cd -- "$1" || exit 1; exec bash -c "$2" </dev/null`;
5566
+ const READER = `${EXEC_UMASK}; while IFS= read -r -d "" kv; do export "$kv"; done; cd -- "$1" || exit 1; exec /usr/bin/perl -e 'setpgrp(0, 0); exec @ARGV' bash -c "$2" </dev/null`;
5184
5567
  /**
5185
- * A harness sandbox session on a Linux VM reached over SSH: the login user has passwordless `sudo`,
5186
- * and the agent, setup steps and checks run as {@link SANDBOX_USER}, a user made here with no
5187
- * `sudo` and none of the login user's groups or variables. Ports are reached through the egress
5188
- * gateway's tunnel, so the session always asks for the gateway.
5568
+ * The Linux profile: the login user has passwordless `sudo`, the agent's commands run as
5569
+ * {@link SANDBOX_USER} with only `user`'s variables, and reeval's own run as root in
5570
+ * {@link SANDBOX_STATE}. Each command carries a marker in its environment, which `kill` finds in
5571
+ * `/proc`. `remote` is the host argv that runs one command line as the login user (`ssh`).
5189
5572
  */
5190
- async function createSshSession(options) {
5191
- const { target, abortSignal: signal } = options;
5192
- const baseEnv = {
5193
- PATH: [
5194
- `${SANDBOX_HOME}/.local/bin`,
5195
- ...options.path ?? [],
5196
- SYSTEM_PATH
5197
- ].join(":"),
5198
- HOME: SANDBOX_HOME,
5199
- USER: SANDBOX_USER,
5200
- LOGNAME: SANDBOX_USER,
5201
- SHELL: "/bin/bash",
5202
- LANG: "C.UTF-8"
5203
- };
5204
- const userEnv = {
5205
- NPM_CONFIG_UPDATE_NOTIFIER: "false",
5206
- NPM_CONFIG_PREFIX: `${SANDBOX_HOME}/.local`,
5207
- ...options.env
5573
+ function linuxShell(o) {
5574
+ const sandboxUser = o.layout?.user ?? "reeval";
5575
+ const stateDir = o.layout?.state ?? "/var/lib/reeval";
5576
+ const seenHome = o.user.HOME;
5577
+ const bind = o.layout && seenHome && o.layout.home !== seenHome ? o.layout.home : void 0;
5578
+ const marker = (exec) => `${o.id}-${exec}`;
5579
+ const asSandboxUser = (command) => bind ? `sudo -n -- unshare --mount --propagation private /bin/sh -c ${shellQuote(`mount --bind ${shellQuote(bind)} ${shellQuote(seenHome ?? "")} && exec setpriv --reuid=${sandboxUser} --regid=${sandboxUser} --init-groups -- ${command}`)}` : `sudo -n -H -u ${sandboxUser} -- ${command}`;
5580
+ const asUser = (cwd, command) => asSandboxUser(`env -i ${Object.entries(o.user).map(([k, v]) => shellQuote(`${k}=${v}`)).join(" ")} bash -c ${shellQuote(READER)} bash ${shellQuote(cwd)} ${shellQuote(command)}`);
5581
+ const asRoot = (command, mark) => `sudo -n -- env -i PATH=${SYSTEM_PATH} HOME=/root${mark ? ` ${EXEC_MARKER}=${mark}` : ""} /bin/sh -c ${shellQuote(`cd ${stateDir} || exit 1; ${EXEC_UMASK}; ${command}`)}`;
5582
+ /**
5583
+ * Killing the host's program leaves the command running on the machine, so kill what has its
5584
+ * marker, and the process group of each: a process that cleared its environment (`env -i`)
5585
+ * keeps the group of the command that started it.
5586
+ */
5587
+ const killExec = (mark) => asRoot(`gs=; for e in /proc/[0-9]*/environ; do grep -qsxzF ${shellQuote(`${EXEC_MARKER}=${mark}`)} "$e" || continue; d=\${e%/environ}; g=$(sed 's/.*) //' "$d/stat" 2>/dev/null | cut -d' ' -f3); kill -9 "\${d#/proc/}" 2>/dev/null; [ "\${g:-0}" -gt 1 ] && gs="$gs $g"; done; for g in $gs; do kill -9 "-$g" 2>/dev/null; done; true`);
5588
+ return {
5589
+ run: (argv, r) => o.run(argv, {
5590
+ ...r,
5591
+ signal: r.signal ?? o.signal
5592
+ }),
5593
+ user: ({ command, cwd, env, exec }) => ({
5594
+ argv: o.remote(asUser(cwd, command)),
5595
+ input: envStream({
5596
+ ...env,
5597
+ [EXEC_MARKER]: marker(exec)
5598
+ })
5599
+ }),
5600
+ privileged: ({ command, exec }) => ({
5601
+ argv: o.remote(asRoot(command, marker(exec))),
5602
+ input: ""
5603
+ }),
5604
+ kill: (exec) => ({
5605
+ argv: o.remote(killExec(marker(exec))),
5606
+ input: ""
5607
+ }),
5608
+ direct: (argv) => o.remote(asSandboxUser(argv.map(shellQuote).join(" ")))
5208
5609
  };
5209
- const ssh = async (remote, input = "", abort = signal) => {
5210
- const [bin = "ssh", ...args] = sshArgv(target, remote);
5211
- const startedAt = Date.now();
5212
- try {
5213
- const r = await run(bin, args, {
5214
- input,
5215
- signal: abort,
5216
- binary: true
5217
- });
5218
- traceDocker(args, startedAt, {
5219
- ...r,
5220
- stdin: input.length
5221
- }, "ssh");
5222
- return r;
5223
- } catch (error) {
5224
- traceDocker(args, startedAt, { error }, "ssh");
5225
- throw error;
5226
- }
5227
- };
5228
- const asUser = (cwd, command) => `sudo -n -H -u ${SANDBOX_USER} -- env -i ${Object.entries(baseEnv).map(([k, v]) => shellQuote(`${k}=${v}`)).join(" ")} bash -c ${shellQuote(READER)} bash ${shellQuote(cwd)} ${shellQuote(command)}`;
5229
- const asRoot = (command, marker) => `sudo -n -- env -i PATH=${SYSTEM_PATH} HOME=/root${marker ? ` ${EXEC_MARKER}=${marker}` : ""} /bin/sh -c ${shellQuote(`cd ${SANDBOX_STATE} || exit 1; ${EXEC_UMASK}; ${command}`)}`;
5230
- const closeConnection = async () => {
5231
- if (!controlOptions(target.controlPath, 0).length) return;
5232
- const [bin = "ssh", ...args] = sshArgv(target, "");
5233
- await run(bin, [
5234
- "-O",
5235
- "exit",
5236
- ...args.slice(0, -1)
5237
- ]).catch(() => {});
5238
- };
5239
- let gateway;
5240
- let destroyed;
5241
- const destroy = () => {
5242
- destroyed ??= (async () => {
5243
- gateway?.close();
5244
- await closeConnection();
5245
- await options.onDestroy?.();
5246
- })();
5247
- return destroyed;
5248
- };
5249
- const fail = async (error) => {
5250
- await destroy().catch(() => {});
5251
- throw signal?.aborted ? signal.reason : error;
5252
- };
5253
- const setup = [
5254
- EXEC_UMASK,
5255
- `id -u ${SANDBOX_USER} >/dev/null 2>&1 || useradd --create-home --shell /bin/bash --user-group ${SANDBOX_USER}`,
5256
- `mkdir -p ${SANDBOX_ROOT} && chown ${SANDBOX_USER}:${SANDBOX_USER} ${SANDBOX_ROOT}`,
5257
- `mkdir -p ${SANDBOX_STATE} && chown 0:0 ${SANDBOX_STATE} && chmod 700 ${SANDBOX_STATE}`,
5258
- ...options.prepare ? [options.prepare] : []
5259
- ].join(" && ");
5260
- const deadline = Date.now() + (options.connectTimeoutMs ?? 6e4);
5261
- for (let wait = 500;; wait = Math.min(wait * 2, 5e3)) {
5262
- const made = await ssh(`sudo -n -- /bin/sh -c ${shellQuote(setup)}`).catch(fail);
5263
- if (made.exitCode === 0) break;
5264
- if (made.exitCode !== SSH_FAILED || Date.now() + wait > deadline) {
5265
- const why = made.stderr.trim() || made.stdout.toString("utf8").trim();
5266
- return fail(/* @__PURE__ */ new Error(`Couldn't set up ${options.description}: ${why.slice(-500)}`));
5267
- }
5268
- await new Promise((resolve) => setTimeout(resolve, wait));
5269
- if (signal?.aborted) return fail(signal.reason);
5270
- }
5271
- const egressOptions = options.egress === true ? {} : options.egress || void 0;
5272
- let egress;
5273
- if (egressOptions) {
5274
- const { policy = { mode: "allow-all" }, ...rest } = egressOptions;
5275
- try {
5276
- gateway = await startGateway(sshTransport(target), {
5277
- ...rest,
5278
- policy
5279
- }, signal);
5280
- egress = { active: true };
5281
- } catch (error) {
5282
- if (signal?.aborted || isRestricted(policy)) {
5283
- await destroy().catch(() => {});
5284
- if (signal?.aborted) throw signal.reason;
5285
- throw new EgressUnavailableError(error.message);
5286
- }
5287
- egress = {
5288
- active: false,
5289
- reason: error.message
5290
- };
5291
- }
5292
- }
5293
- const envFor = (env) => ({
5294
- ...userEnv,
5295
- ...gateway ? gateway.env : {},
5296
- ...env
5610
+ }
5611
+ const NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
5612
+ /**
5613
+ * A command as one script on stdin, so variables (and what a secret holds) never reach a
5614
+ * command line on the host or in the machine. The shell records its pid for {@link killTree}.
5615
+ */
5616
+ function execScript(o) {
5617
+ const exports = Object.entries(o.env).filter(([k]) => NAME.test(k)).map(([k, v]) => `export ${k}=${shellQuote(v)}`);
5618
+ return [[
5619
+ `echo $$ > ${shellQuote(o.pidFile)}`,
5620
+ `export PATH=${shellQuote(o.path)}:"$PATH"`,
5621
+ ...exports,
5622
+ "umask 022",
5623
+ `cd ${shellQuote(o.cwd)} || exit 1`
5624
+ ].join("; "), o.command].join("\n");
5625
+ }
5626
+ /**
5627
+ * Reads the script {@link execScript} wrote from stdin and runs it, with stdin then empty, in a
5628
+ * process group its shell leads, so the pid the script records is also the group's.
5629
+ */
5630
+ const RUN_SCRIPT = [
5631
+ "/usr/bin/perl",
5632
+ "-e",
5633
+ "setpgrp(0, 0); exec @ARGV",
5634
+ "/bin/bash",
5635
+ "-c",
5636
+ "s=$(cat); eval \"$s\" </dev/null"
5637
+ ];
5638
+ /**
5639
+ * Kills the command whose shell wrote `pidFile` and everything it started: macOS has no `/proc`
5640
+ * to find them by a marker, so it stops and kills the shell's process group, which keeps a
5641
+ * process its parent left behind (a double fork's), and walks the tree from the shell for one
5642
+ * that moved to a group of its own (a job-control shell's job). Anything but a pid above 1 in the
5643
+ * file kills nothing: `kill -9 -1` is every process the user can signal.
5644
+ */
5645
+ const killTree = (pidFile) => `f=${shellQuote(pidFile)}; [ -f "$f" ] || exit 0; p=$(cat "$f")
5646
+ case $p in ''|*[!0-9]*) rm -f "$f"; exit 0 ;; esac; [ "$p" -gt 1 ] || { rm -f "$f"; exit 0; }
5647
+ tree() { kill -STOP "$1" 2>/dev/null; for c in $(pgrep -P "$1"); do tree "$c"; done; kill -9 "$1" 2>/dev/null; }
5648
+ kill -STOP "-$p" 2>/dev/null; tree "$p"; kill -9 "-$p" 2>/dev/null; rm -f "$f"; true`;
5649
+ /**
5650
+ * The darwin profile: macOS has no `useradd`, so every command, reeval's own included, runs as
5651
+ * the image's user, reeval's in `stateDir`. Each gets its variables in a script on stdin
5652
+ * ({@link execScript}) and writes its pid there, which `kill` walks the process tree from.
5653
+ * `guest` is the host argv that runs an argv on the machine with its stdin piped.
5654
+ */
5655
+ function darwinShell(o) {
5656
+ const pidFile = (exec) => posix.join(o.stateDir, `exec-${exec}.pid`);
5657
+ const script = (command, cwd, env, exec) => ({
5658
+ argv: o.guest(RUN_SCRIPT),
5659
+ input: execScript({
5660
+ command,
5661
+ cwd,
5662
+ env,
5663
+ pidFile: pidFile(exec),
5664
+ path: o.path
5665
+ })
5297
5666
  });
5667
+ return {
5668
+ run: o.run,
5669
+ user: ({ command, cwd, env, exec }) => script(command, cwd, env, exec),
5670
+ privileged: ({ command, exec }) => script(command, o.stateDir, {}, exec),
5671
+ kill: (exec) => ({
5672
+ argv: o.guest([
5673
+ "/bin/sh",
5674
+ "-c",
5675
+ killTree(pidFile(exec))
5676
+ ]),
5677
+ input: ""
5678
+ }),
5679
+ direct: (argv) => o.guest(argv)
5680
+ };
5681
+ }
5682
+ // ../sandbox-docker/src/transport-session.ts
5683
+ /** How long killing an aborted command may take. */
5684
+ const KILL_TIMEOUT_MS = 3e4;
5685
+ const text = (r) => ({
5686
+ exitCode: r.exitCode,
5687
+ stdout: r.stdout.toString("utf8"),
5688
+ stderr: r.stderr
5689
+ });
5690
+ /**
5691
+ * A harness sandbox session on a machine reeval reaches through host programs (`ssh`, `tart
5692
+ * exec`): everything but how a command gets there, which {@link SessionShell} says.
5693
+ */
5694
+ function transportSession(o) {
5695
+ const { shell, gateway, description } = o;
5298
5696
  let execs = 0;
5299
- const nextMarker = () => `${target.hostKeyAlias}-${++execs}`;
5300
- const cwdOf = (cwd) => cwd ? posix.resolve(SANDBOX_ROOT, cwd) : SANDBOX_ROOT;
5301
- /** Killing the host's ssh leaves the command running in the VM, so kill what has its marker. */
5302
- const killExec = (marker) => ssh(asRoot(`for e in /proc/[0-9]*/environ; do grep -qsxzF ${shellQuote(`${EXEC_MARKER}=${marker}`)} "$e" && kill -9 "$(basename "$(dirname "$e")")" 2>/dev/null; done; true`), "", void 0).then(() => {}, () => {});
5303
- const run$1 = async (o) => {
5304
- const marker = nextMarker();
5305
- const env = {
5306
- ...envFor(o.env),
5307
- [EXEC_MARKER]: marker
5697
+ const at = (path) => path ? posix.resolve(o.defaultWorkingDirectory, path) : o.defaultWorkingDirectory;
5698
+ const runHost = (c, signal) => shell.run(c.argv, {
5699
+ input: c.input,
5700
+ signal
5701
+ });
5702
+ const kill = (exec) => runHost(shell.kill(exec), AbortSignal.timeout(KILL_TIMEOUT_MS)).then(() => {}, () => {});
5703
+ const execute = async (exec, c, signal) => {
5704
+ let killed;
5705
+ const onAbort = () => {
5706
+ killed = kill(exec);
5308
5707
  };
5708
+ signal?.addEventListener("abort", onAbort, { once: true });
5309
5709
  try {
5310
- const r = await ssh(asUser(cwdOf(o.workingDirectory), o.command), envStream(env), o.abortSignal);
5311
- return {
5312
- exitCode: r.exitCode,
5313
- stdout: r.stdout.toString("utf8"),
5314
- stderr: r.stderr
5315
- };
5710
+ return text(await runHost(c, signal));
5316
5711
  } catch (error) {
5317
- if (o.abortSignal?.aborted) await killExec(marker);
5712
+ if (signal?.aborted) {
5713
+ await killed;
5714
+ await kill(exec);
5715
+ }
5318
5716
  throw error;
5717
+ } finally {
5718
+ signal?.removeEventListener("abort", onAbort);
5319
5719
  }
5320
5720
  };
5321
- const runPrivileged = async (o) => {
5322
- const marker = nextMarker();
5323
- try {
5324
- const r = await ssh(asRoot(o.command, marker), "", o.abortSignal);
5325
- return {
5326
- exitCode: r.exitCode,
5327
- stdout: r.stdout.toString("utf8"),
5328
- stderr: r.stderr
5329
- };
5330
- } catch (error) {
5331
- if (o.abortSignal?.aborted) await killExec(marker);
5332
- throw error;
5333
- }
5721
+ /** Starts a host program with its output streamed; its kill ends command `exec` in the machine too. */
5722
+ const streamed = (exec, c) => {
5723
+ const [bin = "", ...args] = c.argv;
5724
+ const startedAt = Date.now();
5725
+ const child = spawn(bin, args, {
5726
+ stdio: [
5727
+ "pipe",
5728
+ "pipe",
5729
+ "pipe"
5730
+ ],
5731
+ detached: true
5732
+ });
5733
+ child.stdin.on("error", () => {});
5734
+ child.stdin.end(c.input);
5735
+ const exited = new Promise((resolve) => {
5736
+ child.once("error", () => resolve({ exitCode: 127 }));
5737
+ child.once("close", (code) => {
5738
+ traceDocker(args, startedAt, {
5739
+ exitCode: code,
5740
+ stdout: "<streamed>"
5741
+ }, bin);
5742
+ resolve({ exitCode: code ?? 1 });
5743
+ });
5744
+ });
5745
+ return {
5746
+ pid: child.pid,
5747
+ stdout: Readable.toWeb(child.stdout),
5748
+ stderr: Readable.toWeb(child.stderr),
5749
+ wait: () => exited,
5750
+ kill: async () => {
5751
+ child.kill("SIGKILL");
5752
+ await kill(exec);
5753
+ }
5754
+ };
5334
5755
  };
5335
- const asUserDirect = (command) => `sudo -n -u ${SANDBOX_USER} -- ${command}`;
5336
- const readBinaryFile = async (o) => {
5337
- const r = await ssh(asUserDirect(`cat -- ${shellQuote(posix.resolve(SANDBOX_ROOT, o.path))}`), "", o.abortSignal);
5338
- return r.exitCode === 0 ? new Uint8Array(r.stdout) : null;
5756
+ const readBinaryFile = async (r) => {
5757
+ const read = await shell.run(shell.direct([
5758
+ "/bin/cat",
5759
+ "--",
5760
+ at(r.path)
5761
+ ]), { signal: r.abortSignal }).catch(() => null);
5762
+ return read?.exitCode === 0 ? new Uint8Array(read.stdout) : null;
5339
5763
  };
5340
- const writeBinaryFile = async (o) => {
5341
- const path = posix.resolve(SANDBOX_ROOT, o.path);
5342
- const script = `${EXEC_UMASK} && mkdir -p ${shellQuote(posix.dirname(path))} && cat > ${shellQuote(path)}`;
5343
- const r = await ssh(asUserDirect(`sh -c ${shellQuote(script)}`), o.content, o.abortSignal);
5344
- if (r.exitCode !== 0) throw new Error(`Couldn't write ${path} in ${options.description}: ${r.stderr.trim()}`);
5764
+ const writeBinaryFile = async (w) => {
5765
+ const target = at(w.path);
5766
+ const r = await shell.run(shell.direct([
5767
+ "/bin/sh",
5768
+ "-c",
5769
+ "umask 022 && mkdir -p \"$(dirname \"$1\")\" && cat > \"$1\"",
5770
+ "sh",
5771
+ target
5772
+ ]), {
5773
+ input: w.content,
5774
+ signal: w.abortSignal
5775
+ });
5776
+ if (r.exitCode !== 0) throw new Error(`Couldn't write ${target} in ${o.name ?? description}: ${r.stderr.trim()}`);
5345
5777
  };
5346
- const paths = pathOperations(async (script, path, abortSignal) => {
5347
- const r = await ssh(asUserDirect(`sh -c ${shellQuote(script)} sh ${shellQuote(path)}`), "", abortSignal);
5348
- return {
5349
- exitCode: r.exitCode,
5350
- stdout: r.stdout.toString("utf8"),
5351
- stderr: r.stderr
5352
- };
5353
- });
5778
+ const paths = pathOperations(async (script, path, abortSignal) => text(await shell.run(shell.direct([
5779
+ "/bin/sh",
5780
+ "-c",
5781
+ script,
5782
+ "sh",
5783
+ path
5784
+ ]), { signal: abortSignal })), o.defaultWorkingDirectory);
5354
5785
  const brokering = gateway ? {
5355
5786
  async setNetworkPolicy(policy) {
5356
- gateway?.setPolicy(policy);
5787
+ gateway.setPolicy(policy);
5357
5788
  },
5358
5789
  async addRequestTransformations(rules) {
5359
- gateway?.addTransformations(rules);
5790
+ gateway.addTransformations(rules);
5360
5791
  },
5361
5792
  async setRequestTransformations(rules) {
5362
- gateway?.setTransformations(rules);
5363
- }
5364
- } : {};
5365
- const substituting = gateway ? {
5793
+ gateway.setTransformations(rules);
5794
+ },
5366
5795
  async setSubstitutions(subs) {
5367
- gateway?.setSubstitutions(subs);
5796
+ gateway.setSubstitutions(subs);
5368
5797
  },
5369
5798
  traffic: () => gateway.traffic()
5370
5799
  } : {};
5800
+ const run = (r) => {
5801
+ const exec = ++execs;
5802
+ return execute(exec, shell.user({
5803
+ command: r.command,
5804
+ cwd: at(r.workingDirectory),
5805
+ env: o.env(r.env),
5806
+ exec
5807
+ }), r.abortSignal);
5808
+ };
5371
5809
  const session = {
5372
- id: target.hostKeyAlias,
5373
- description: options.description,
5374
- defaultWorkingDirectory: SANDBOX_ROOT,
5810
+ id: o.id,
5811
+ description,
5812
+ defaultWorkingDirectory: o.defaultWorkingDirectory,
5375
5813
  ports: [BRIDGE_PORT],
5376
5814
  get egress() {
5377
- if (egress?.active && gateway?.stopped) return {
5815
+ if (o.egress?.active && gateway?.stopped) return {
5378
5816
  active: false,
5379
5817
  reason: gateway.stopped
5380
5818
  };
5381
- return egress;
5819
+ return o.egress;
5382
5820
  },
5383
5821
  ...brokering,
5384
- ...substituting,
5385
5822
  oomKills: async () => null,
5386
- run: run$1,
5387
- runPrivileged,
5388
- spawn: (async (o) => {
5389
- if (o.stdin) throw new Error(`A process in ${options.description} has no writable stdin`);
5390
- const marker = nextMarker();
5391
- const env = {
5392
- ...envFor(o.env),
5393
- [EXEC_MARKER]: marker
5394
- };
5395
- const [bin = "ssh", ...args] = sshArgv(target, asUser(cwdOf(o.workingDirectory), o.command));
5396
- const startedAt = Date.now();
5397
- const child = spawn(bin, args, {
5398
- stdio: [
5399
- "pipe",
5400
- "pipe",
5401
- "pipe"
5402
- ],
5403
- detached: true
5404
- });
5405
- child.stdin.on("error", () => {});
5406
- child.stdin.end(envStream(env));
5407
- const exited = new Promise((resolve) => child.on("close", (code) => {
5408
- traceDocker(args, startedAt, {
5409
- exitCode: code,
5410
- stdout: "<streamed>"
5411
- }, "ssh");
5412
- resolve({ exitCode: code ?? 1 });
5823
+ run,
5824
+ runPrivileged: (r) => {
5825
+ const exec = ++execs;
5826
+ return execute(exec, shell.privileged({
5827
+ command: r.command,
5828
+ exec
5829
+ }), r.abortSignal);
5830
+ },
5831
+ spawn: (async (s) => {
5832
+ if (s.stdin) throw new Error(`A process in ${description} has no writable stdin`);
5833
+ const exec = ++execs;
5834
+ const p = streamed(exec, shell.user({
5835
+ command: s.command,
5836
+ cwd: at(s.workingDirectory),
5837
+ env: o.env(s.env),
5838
+ exec
5413
5839
  }));
5414
- const kill = async () => {
5415
- child.kill("SIGKILL");
5416
- await killExec(marker);
5417
- };
5418
- o.abortSignal?.addEventListener("abort", () => void kill(), { once: true });
5419
- return {
5420
- pid: child.pid,
5421
- stdout: Readable.toWeb(child.stdout),
5422
- stderr: Readable.toWeb(child.stderr),
5423
- wait: () => exited,
5424
- kill
5425
- };
5840
+ s.abortSignal?.addEventListener("abort", () => void p.kill(), { once: true });
5841
+ return p;
5426
5842
  }),
5843
+ spawnPrivileged: async (s) => {
5844
+ const exec = ++execs;
5845
+ return streamed(exec, shell.privileged({
5846
+ command: s.command,
5847
+ exec
5848
+ }));
5849
+ },
5427
5850
  readBinaryFile,
5428
- async readFile(o) {
5429
- const bytes = await readBinaryFile(o);
5851
+ async readFile(r) {
5852
+ const bytes = await readBinaryFile(r);
5430
5853
  return bytes === null ? null : Readable.toWeb(Readable.from([bytes]));
5431
5854
  },
5432
- async readTextFile(o) {
5433
- const bytes = await readBinaryFile(o);
5855
+ async readTextFile(r) {
5856
+ const bytes = await readBinaryFile(r);
5434
5857
  if (bytes === null) return null;
5435
- const text = Buffer.from(bytes).toString("utf8");
5436
- if (o.startLine === void 0 && o.endLine === void 0) return text;
5437
- return text.split("\n").slice((o.startLine ?? 1) - 1, o.endLine).join("\n");
5858
+ const content = Buffer.from(bytes).toString("utf8");
5859
+ if (r.startLine === void 0 && r.endLine === void 0) return content;
5860
+ return content.split("\n").slice((r.startLine ?? 1) - 1, r.endLine).join("\n");
5438
5861
  },
5439
5862
  ...paths,
5440
5863
  writeBinaryFile,
5441
- writeTextFile: (o) => writeBinaryFile({
5442
- ...o,
5443
- content: Buffer.from(o.content, "utf8")
5864
+ writeTextFile: (w) => writeBinaryFile({
5865
+ ...w,
5866
+ content: Buffer.from(w.content, "utf8")
5444
5867
  }),
5445
- async writeFile(o) {
5868
+ async writeFile(w) {
5446
5869
  const chunks = [];
5447
- for await (const chunk of o.content) chunks.push(chunk);
5870
+ for await (const chunk of w.content) chunks.push(chunk);
5448
5871
  await writeBinaryFile({
5449
- ...o,
5872
+ ...w,
5450
5873
  content: Buffer.concat(chunks)
5451
5874
  });
5452
5875
  },
5453
5876
  async getPortEndpoint({ port, protocol = "ws" }) {
5454
5877
  const scheme = protocol === "ws" ? "ws" : "http";
5455
- if (!gateway || gateway.stopped) throw new Error(`Port ${port} of ${options.description} isn't reachable: the egress gateway ${gateway?.stopped ? `stopped: ${gateway.stopped}` : "isn't running"}`);
5456
- return { url: await gateway.portUrl(port, scheme) };
5878
+ if (gateway && !gateway.stopped) return { url: await gateway.portUrl(port, scheme) };
5879
+ return { url: await o.portWithoutGateway(port, scheme) };
5457
5880
  },
5458
- async getPortUrl(o) {
5459
- return (await session.getPortEndpoint(o)).url;
5881
+ async getPortUrl(p) {
5882
+ return (await session.getPortEndpoint(p)).url;
5460
5883
  },
5461
- stop: destroy,
5462
- destroy,
5884
+ stop: o.destroy,
5885
+ destroy: o.destroy,
5463
5886
  restricted: () => {
5464
- const { description, readFile, readBinaryFile, readTextFile, writeFile } = session;
5465
- const { writeBinaryFile, writeTextFile, stat, listDirectory, deleteFile, spawn, run } = session;
5887
+ const { readFile, readTextFile, writeFile, writeTextFile, stat, listDirectory } = session;
5888
+ const { deleteFile, spawn: spawnIn, run: runIn } = session;
5466
5889
  return {
5467
5890
  description,
5468
5891
  readFile,
@@ -5474,13 +5897,293 @@ async function createSshSession(options) {
5474
5897
  stat,
5475
5898
  listDirectory,
5476
5899
  deleteFile,
5477
- spawn,
5478
- run
5900
+ spawn: spawnIn,
5901
+ run: runIn
5479
5902
  };
5480
5903
  }
5481
5904
  };
5482
5905
  return session;
5483
5906
  }
5484
- export { hostAllowed as $, ROOT_CAPABILITIES as A, run as At, privateDir as B, dockerSeccompFile as Bt, pruneImages as C, imageInfo as Ct, DEFAULT_LIMITS as D, OPAQUE_OUTPUT as Dt, usesReevalBase as E, removeContainerDetached as Et, PROXY_PORT as F, failureCause as Ft, placeholder as G, sshTransport as H, normalizeImageId as Ht, startGateway as I, isTransient as It, onEndpoint as J, applyTransformations as K, SSH_OPTIONS as L, parseBuildOutput as Lt, dockerSandboxProvider as M, ImageBuildError as Mt, pathOperations as N, RETRY_DELAYS as Nt, EgressUnavailableError as O, onDockerCommand as Ot, CA_PATH as P, causeLine as Pt, defaultAllowedHosts as Q, controlOptions as R, retryTransient as Rt, pluginLayerTag as S, dockerState as St, sourceTreeHash as T, isRegistryDigest as Tt, MODEL_FIELD as U, sshArgv as V, engineSpec as Vt, usageReader as W, HARNESS_HOSTS as X, DOCKER_EGRESS as Y, PACKAGE_HOSTS as Z, harnessImageFor as _, dockerignoreMatcher as _t, PNPM_VERSION as a, HARNESS_PACKAGES as at, pluginBuildDir as b, dockerCapacity as bt, bakedAdapter as c, SANDBOX_ROOT as ct, buildDockerfile as d, WORKSPACE_DIR as dt, requestFacts as et, buildImage as f, adapterVersion as ft, dockerfileTag as g, contextFiles as gt, contextHash as h, isBakedHarness as ht, PLUGIN_BUILDS_DIR as i, DEFAULT_IMAGE as it, createDockerSession as j, shellQuote as jt, PRIVILEGED_CAPABILITIES as k, traceDocker as kt, bakedHarnessName as l, SANDBOX_STATE as lt, buildPluginLayer as m, imageFor as mt, MCP_TIMER as n, BASE_IMAGE as nt, REEVAL_BASE_ARG as o, LABEL as ot, buildInstallLayer as p, harnessLabel as pt, matches as q, DOCKER_CONTEXT as r, BRIDGE_PORT as rt, bakeHarness as s, SANDBOX_HOME as st, createSshSession as t, BAKED_HARNESSES as tt, bakedRecipe as u, SANDBOX_USER as ut, installLayerTag as v, docker as vt, resolveFrom as w, imageTags as wt, pluginBuildKey as x, dockerOk as xt, installScript as y, dockerAvailable as yt, controlPathFits as z, ENGINES as zt };
5907
+ // ../sandbox-docker/src/ssh-session.ts
5908
+ /** ssh's own exit status: it couldn't connect, or the connection dropped. */
5909
+ const SSH_FAILED = 255;
5910
+ /** Held while one slot sets up, so slots sharing a machine don't install the same things at once. */
5911
+ const SETUP_LOCK = "/var/lock/reeval-setup";
5912
+ /** The machine's homes, root's: `home-<label>.tar`, and the `.lock` its installer holds. */
5913
+ const HOMES = "/var/lib/reeval-pool";
5914
+ const RESTORED = "reeval:home-restored";
5915
+ const CLAIMED = "reeval:install-claimed";
5916
+ const WAITING = "reeval:install-waiting";
5917
+ const COPY_FAILED = "reeval:home-copy-failed";
5918
+ const FRESH = "reeval:install-fresh";
5919
+ /** How long a slot waits for another's install, past the install's own deadline of 10 minutes. */
5920
+ const INSTALL_WAIT_MS = 66e4;
5921
+ const homeFiles = (label) => {
5922
+ const base = `${HOMES}/home-${label.replace(/[^A-Za-z0-9._-]/g, "_")}`;
5923
+ return {
5924
+ tar: `${base}.tar`,
5925
+ lock: `${base}.lock`
5926
+ };
5927
+ };
5928
+ /**
5929
+ * Root commands that empty a slot's home back to the skeleton. The directory itself stays: on a
5930
+ * shared machine, slot 0's is where the other slots' commands see their own homes.
5931
+ */
5932
+ const skeletonHome = (layout) => {
5933
+ const [u, home] = [shellQuote(layout.user), shellQuote(layout.home)];
5934
+ return `mkdir -p ${home} && find ${home} -mindepth 1 -delete && cp -a /etc/skel/. ${home}/ && chown -R -h ${u}:${u} ${home} && chmod 700 ${home}`;
5935
+ };
5936
+ /**
5937
+ * Root commands that put a used slot back as a new one finds it: none of its user's processes,
5938
+ * cron or at jobs, lingering, temporary files, locks or message queues, an empty working root and
5939
+ * state directory, and the skeleton home.
5940
+ */
5941
+ function resetSlot(layout) {
5942
+ const u = shellQuote(layout.user);
5943
+ return [
5944
+ `if id -u ${u} >/dev/null 2>&1; then`,
5945
+ `for i in 1 2 3 4 5 6 7 8 9 10; do pkill -KILL -u ${u} || break; sleep 0.2; done`,
5946
+ `crontab -r -u ${u} 2>/dev/null`,
5947
+ `atq 2>/dev/null | awk -v u=${u} '$NF == u { print $1 }' | xargs -r atrm 2>/dev/null`,
5948
+ `loginctl disable-linger ${u} 2>/dev/null`,
5949
+ `find /tmp /var/tmp /dev/shm /run/lock /dev/mqueue -xdev -mindepth 1 -user ${u} -delete 2>/dev/null`,
5950
+ `rm -rf ${shellQuote(layout.root)} ${shellQuote(layout.state)}`,
5951
+ skeletonHome(layout),
5952
+ "fi; true"
5953
+ ].join("\n");
5954
+ }
5955
+ /**
5956
+ * The root script that gives a slot the machine's home for `label`. With a copy kept, it unpacks
5957
+ * it into the slot's home ({@link RESTORED}): every slot sees its home at one path, so the copy
5958
+ * needs no change. With none, the slot takes the install's lock and holds it, in the process that
5959
+ * then reads its stdin until the installer closes it ({@link CLAIMED}); a slot that finds it held
5960
+ * says {@link WAITING} and blocks until the kernel releases it, when its holder finishes or dies.
5961
+ * A copy that won't unpack is deleted ({@link COPY_FAILED}) and the slot goes for the lock again,
5962
+ * or installs on its own ({@link FRESH}).
5963
+ */
5964
+ function slotHome(layout, label) {
5965
+ const f = homeFiles(label);
5966
+ const [tar, lock] = [shellQuote(f.tar), shellQuote(f.lock)];
5967
+ const [u, home] = [shellQuote(layout.user), shellQuote(layout.home)];
5968
+ const restore = `find ${home} -mindepth 1 -delete && tar -C ${home} --strip-components=1 -xpf ${tar} && chown -R -h ${u}:${u} ${home} && chmod 700 ${home}`;
5969
+ return [
5970
+ `mkdir -p ${shellQuote(HOMES)} && chmod 700 ${shellQuote(HOMES)} && exec 9>>${lock} || exit 1`,
5971
+ "for try in 1 2; do",
5972
+ `if [ ! -f ${tar} ] && ! flock -x -n 9; then echo ${WAITING}; flock -x -w ${INSTALL_WAIT_MS / 1e3} 9 || { echo "another slot was still installing the harness after ${INSTALL_WAIT_MS / 6e4} minutes" >&2; exit 1; }; fi`,
5973
+ `if [ ! -f ${tar} ]; then echo ${CLAIMED}; exec cat >/dev/null; fi`,
5974
+ "flock -u 9",
5975
+ `if ${restore}; then echo ${RESTORED}; exit 0; fi`,
5976
+ `echo ${COPY_FAILED}; rm -f ${tar}; ${skeletonHome(layout)} || exit 1`,
5977
+ "done",
5978
+ `echo ${FRESH}`
5979
+ ].join("\n");
5980
+ }
5981
+ /**
5982
+ * Sets up a Linux VM reached over SSH for a harness session: the login user has passwordless
5983
+ * `sudo`, and the agent, setup steps and checks run as {@link SANDBOX_USER}, a user made here with
5984
+ * no `sudo` and none of the login user's groups or variables. Ports are reached through the
5985
+ * egress gateway's tunnel. When setting up fails, the connection is closed.
5986
+ */
5987
+ async function connectSsh(options) {
5988
+ const { target, abortSignal: signal } = options;
5989
+ const layout = options.layout ?? slotLayout(0);
5990
+ const baseEnv = {
5991
+ PATH: [
5992
+ `${SANDBOX_HOME}/.local/bin`,
5993
+ ...options.path ?? [],
5994
+ SYSTEM_PATH
5995
+ ].join(":"),
5996
+ HOME: SANDBOX_HOME,
5997
+ USER: layout.user,
5998
+ LOGNAME: layout.user,
5999
+ SHELL: "/bin/bash",
6000
+ LANG: "C.UTF-8"
6001
+ };
6002
+ const userEnv = {
6003
+ NPM_CONFIG_UPDATE_NOTIFIER: "false",
6004
+ NPM_CONFIG_PREFIX: `${SANDBOX_HOME}/.local`,
6005
+ ...options.env
6006
+ };
6007
+ const hostRun = async (argv, o) => {
6008
+ const [bin = "ssh", ...args] = argv;
6009
+ const startedAt = Date.now();
6010
+ try {
6011
+ const r = await run(bin, args, {
6012
+ input: o.input ?? "",
6013
+ signal: o.signal,
6014
+ binary: true
6015
+ });
6016
+ traceDocker(args, startedAt, {
6017
+ ...r,
6018
+ stdin: o.input?.length ?? 0
6019
+ }, "ssh");
6020
+ return r;
6021
+ } catch (error) {
6022
+ traceDocker(args, startedAt, { error }, "ssh");
6023
+ throw error;
6024
+ }
6025
+ };
6026
+ const ssh = (remote) => hostRun(sshArgv(target, remote), {
6027
+ input: "",
6028
+ signal
6029
+ });
6030
+ const closeConnection = async () => {
6031
+ if (!controlOptions(target.controlPath, 0).length) return;
6032
+ const [bin = "ssh", ...args] = sshArgv(target, "");
6033
+ await run(bin, [
6034
+ "-O",
6035
+ "exit",
6036
+ ...args.slice(0, -1)
6037
+ ]).catch(() => {});
6038
+ };
6039
+ const fail = async (error) => {
6040
+ await closeConnection();
6041
+ throw signal?.aborted ? signal.reason : error;
6042
+ };
6043
+ const { user } = layout;
6044
+ const addUser = (name) => `{ id -u ${name} >/dev/null 2>&1 || useradd --create-home --shell /bin/bash --user-group ${name}; }`;
6045
+ const setup = [
6046
+ EXEC_UMASK,
6047
+ ...options.reset ? [`{ ${resetSlot(layout)}\n}`] : [],
6048
+ ...layout.home === "/home/reeval" ? [addUser(user)] : [
6049
+ `{ command -v unshare && command -v setpriv && command -v mount; } >/dev/null || { echo "a machine shared by attempts needs unshare, setpriv and mount (util-linux)" >&2; false; }`,
6050
+ addUser(SANDBOX_USER),
6051
+ `chmod 700 ${SANDBOX_HOME}`,
6052
+ `{ id -u ${user} >/dev/null 2>&1 || useradd --no-create-home --home-dir ${SANDBOX_HOME} --shell /bin/bash --user-group ${user}; }`,
6053
+ `{ [ -d ${layout.home} ] || { cp -a /etc/skel ${layout.home} && chown -R ${user}:${user} ${layout.home}; }; }`
6054
+ ],
6055
+ `mkdir -p ${layout.root} && chown ${user}:${user} ${layout.root}`,
6056
+ `chmod 700 ${layout.root} ${layout.home}`,
6057
+ `mkdir -p ${layout.state} && chown 0:0 ${layout.state} && chmod 700 ${layout.state}`,
6058
+ ...options.prepare ? [options.prepare] : []
6059
+ ].join(" && ");
6060
+ const asRoot = options.layout ? `sudo -n -- flock ${SETUP_LOCK} /bin/sh -c ${shellQuote(setup)}` : `sudo -n -- /bin/sh -c ${shellQuote(setup)}`;
6061
+ const deadline = Date.now() + (options.connectTimeoutMs ?? 6e4);
6062
+ for (let wait = 500;; wait = Math.min(wait * 2, 5e3)) {
6063
+ const made = await ssh(asRoot).catch(fail);
6064
+ if (made.exitCode === 0) break;
6065
+ if (made.exitCode !== SSH_FAILED || Date.now() + wait > deadline) {
6066
+ const why = made.stderr.trim() || made.stdout.toString("utf8").trim();
6067
+ return fail(/* @__PURE__ */ new Error(`Couldn't set up ${options.description}: ${why.slice(-500)}`));
6068
+ }
6069
+ await new Promise((resolve) => setTimeout(resolve, wait));
6070
+ if (signal?.aborted) return fail(signal.reason);
6071
+ }
6072
+ /** The process holding the install's lock in the machine, while this slot installs. */
6073
+ let holder;
6074
+ const release = async () => {
6075
+ const held = holder;
6076
+ holder = void 0;
6077
+ if (!held || held.exitCode !== null) return;
6078
+ const gone = new Promise((resolve) => held.once("close", resolve));
6079
+ held.stdin?.end();
6080
+ const timer = setTimeout(() => held.kill("SIGKILL"), 1e4);
6081
+ await gone;
6082
+ clearTimeout(timer);
6083
+ };
6084
+ const shell = linuxShell({
6085
+ run: hostRun,
6086
+ remote: (command) => sshArgv(target, command),
6087
+ id: `${target.hostKeyAlias}-${layout.user}`,
6088
+ user: baseEnv,
6089
+ signal,
6090
+ layout
6091
+ });
6092
+ return {
6093
+ root: sshTransport(target),
6094
+ async home() {
6095
+ if (!options.home) return {
6096
+ restored: false,
6097
+ waitedMs: 0
6098
+ };
6099
+ const [bin = "ssh", ...args] = sshArgv(target, `sudo -n -- /bin/sh -c ${shellQuote(`${EXEC_UMASK}\n${slotHome(layout, options.home)}`)}`);
6100
+ const startedAt = Date.now();
6101
+ const child = spawn(bin, args, { stdio: [
6102
+ "pipe",
6103
+ "pipe",
6104
+ "pipe"
6105
+ ] });
6106
+ let [out, err] = ["", ""];
6107
+ child.stderr.on("data", (d) => {
6108
+ err += d.toString("utf8");
6109
+ });
6110
+ const [decided, waited] = (await new Promise((resolve, reject) => {
6111
+ let waitingSince;
6112
+ const stop = () => child.kill("SIGKILL");
6113
+ signal?.addEventListener("abort", stop, { once: true });
6114
+ child.stdout.on("data", (d) => {
6115
+ out += d.toString("utf8");
6116
+ if (waitingSince === void 0 && out.includes(WAITING)) waitingSince = Date.now();
6117
+ const decided = [
6118
+ RESTORED,
6119
+ CLAIMED,
6120
+ FRESH
6121
+ ].find((m) => out.includes(m));
6122
+ if (!decided) return;
6123
+ signal?.removeEventListener("abort", stop);
6124
+ resolve(`${decided} ${waitingSince === void 0 ? 0 : Date.now() - waitingSince}`);
6125
+ });
6126
+ child.once("error", reject);
6127
+ child.once("close", (code) => {
6128
+ signal?.removeEventListener("abort", stop);
6129
+ if (signal?.aborted) return reject(signal.reason);
6130
+ const why = err.trim() || out.trim() || `ssh exited with ${code}`;
6131
+ reject(/* @__PURE__ */ new Error(`Couldn't give ${user} the machine's home in ${options.description}: ${why.slice(-500)}`));
6132
+ });
6133
+ }).finally(() => traceDocker(args, startedAt, {
6134
+ exitCode: child.exitCode,
6135
+ stdout: out,
6136
+ stderr: err
6137
+ }, "ssh"))).split(" ");
6138
+ if (decided === CLAIMED) holder = child;
6139
+ else child.stdin.end();
6140
+ return {
6141
+ restored: decided === RESTORED,
6142
+ waitedMs: Number(waited),
6143
+ ...out.includes(COPY_FAILED) && { copyFailed: err.trim().slice(-500) || "the machine's copy didn't unpack" }
6144
+ };
6145
+ },
6146
+ async snapshotHome() {
6147
+ if (!options.home || !holder) return;
6148
+ const f = homeFiles(options.home);
6149
+ const command = [
6150
+ EXEC_UMASK,
6151
+ `tar -C ${shellQuote(posix.dirname(layout.home))} -cf ${shellQuote(f.tar)}.$$ ${shellQuote(posix.basename(layout.home))}`,
6152
+ `mv ${shellQuote(f.tar)}.$$ ${shellQuote(f.tar)}`
6153
+ ].join(" && ");
6154
+ try {
6155
+ const r = await ssh(`sudo -n -- /bin/sh -c ${shellQuote(command)}`);
6156
+ if (r.exitCode !== 0) throw new Error(`Couldn't keep ${layout.user}'s home in ${options.description}: ${r.stderr.trim().slice(-500)}`);
6157
+ } finally {
6158
+ await release();
6159
+ }
6160
+ },
6161
+ async close() {
6162
+ await release();
6163
+ await closeConnection();
6164
+ },
6165
+ session: ({ gateway, noGateway, destroy }) => transportSession({
6166
+ id: target.hostKeyAlias,
6167
+ description: options.description,
6168
+ defaultWorkingDirectory: layout.root,
6169
+ shell,
6170
+ env: (env) => ({
6171
+ ...userEnv,
6172
+ ...gateway?.env,
6173
+ ...env
6174
+ }),
6175
+ gateway,
6176
+ egress: gateway ? { active: true } : {
6177
+ active: false,
6178
+ reason: noGateway ?? ""
6179
+ },
6180
+ async portWithoutGateway(port) {
6181
+ throw new Error(`Port ${port} of ${options.description} isn't reachable: the egress gateway ${gateway?.stopped ? `stopped: ${gateway.stopped}` : "isn't running"}`);
6182
+ },
6183
+ destroy
6184
+ })
6185
+ };
6186
+ }
6187
+ export { startGateway as $, failureCause as $t, harnessImageFor as A, harnessLabel as At, reevalImageKey as B, dockerState as Bt, buildInstallLayer as C, LABEL as Ct, dockerfileKey as D, SANDBOX_USER as Dt, dockerfileBases as E, SANDBOX_STATE as Et, localKey as F, dockerignoreMatcher as Ft, EgressUnavailableError as G, OPAQUE_OUTPUT as Gt, sourceTreeHash as H, imageTags as Ht, pluginBuildDir as I, docker as It, createDockerSession as J, run as Jt, PRIVILEGED_CAPABILITIES as K, onDockerCommand as Kt, pluginBuildKey as L, dockerAvailable as Lt, installLayerTag as M, isBakedHarness as Mt, installScript as N, slotLayout as Nt, dockerfileTag as O, WORKSPACE_DIR as Ot, isLocalKey as P, contextFiles as Pt, PROXY_PORT as Q, causeLine as Qt, pluginLayerTag as R, dockerCapacity as Rt, buildImage as S, HARNESS_PACKAGES as St, contextHash as T, SANDBOX_ROOT as Tt, usesReevalBase as U, isRegistryDigest as Ut, resolveFrom as V, imageInfo as Vt, DEFAULT_LIMITS as W, removeContainerDetached as Wt, pathOperations as X, ImageBuildError as Xt, dockerSandboxProvider as Y, shellQuote as Yt, CA_PATH as Z, RETRY_DELAYS as Zt, bakeKey as _, requestFacts as _t, enginePlatform as a, engineSpec as an, sshTransport as at, bakedRecipe as b, BRIDGE_PORT as bt, registryProblem as c, placeholder as ct, DOCKER_CONTEXT as d, onEndpoint as dt, isTransient as en, SSH_OPTIONS as et, PLATFORM as f, DOCKER_EGRESS as ft, bakeHarness as g, hostAllowed as gt, REEVAL_BASE_ARG as h, defaultAllowedHosts as ht, darwinShell as i, dockerSeccompFile as in, sshArgv as it, imageKey as j, imageFor as jt, fromImageKey as k, adapterVersion as kt, registryRef as l, applyTransformations as lt, PNPM_VERSION as m, PACKAGE_HOSTS as mt, resetSlot as n, retryTransient as nn, controlPathFits as nt, pullLayer as o, normalizeImageId as on, MODEL_FIELD as ot, PLUGIN_BUILDS_DIR as p, HARNESS_HOSTS as pt, ROOT_CAPABILITIES as q, traceDocker as qt, transportSession as r, ENGINES as rn, privateDir as rt, pushLayer as s, usageReader as st, connectSsh as t, parseBuildOutput as tn, controlOptions as tt, MCP_TIMER as u, matches as ut, bakedAdapter as v, BAKED_HARNESSES as vt, buildPluginLayer as w, SANDBOX_HOME as wt, buildDockerfile as x, DEFAULT_IMAGE as xt, bakedHarnessName as y, BASE_IMAGE as yt, pruneImages as z, dockerOk as zt };
5485
6188
 
5486
- //# sourceMappingURL=src-BHJ4MWvY.js.map
6189
+ //# sourceMappingURL=src-CWfy8ct8.js.map