reeval 0.21.0 → 0.23.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.
- package/CHANGELOG.md +65 -0
- package/README.md +15 -15
- package/dist/{adapter-BdzhdRYo.js → adapter-Dlq3-4OS.js} +7 -50
- package/dist/adapter-Dlq3-4OS.js.map +1 -0
- package/dist/{agent-Dx-bDmlV.js → agent-OsAfayRf.js} +11 -12
- package/dist/agent-OsAfayRf.js.map +1 -0
- package/dist/{agents-l0-k7vw3.js → agents-BztvTkfM.js} +46 -37
- package/dist/agents-BztvTkfM.js.map +1 -0
- package/dist/{app-files-B-CQYB0c.js → app-files-6NHzghym.js} +3 -3
- package/dist/app-files-6NHzghym.js.map +1 -0
- package/dist/{assemble-CsZIcJo8.js → assemble-Doa1m-HW.js} +17 -15
- package/dist/{assemble-CsZIcJo8.js.map → assemble-Doa1m-HW.js.map} +1 -1
- package/dist/{assemble-CYMpN8LC.js → assemble-XrZskSNj.js} +1 -1
- package/dist/attach-BH2HdwH_.js +219 -0
- package/dist/attach-BH2HdwH_.js.map +1 -0
- package/dist/{attempt-CKfKsqqw.js → attempt-_dUsblVx.js} +2 -2
- package/dist/{attempt-CKfKsqqw.js.map → attempt-_dUsblVx.js.map} +1 -1
- package/dist/{attempt-host-BwSmNYkX.js → attempt-host-8mQV8Uee.js} +7 -7
- package/dist/{attempt-host-BwSmNYkX.js.map → attempt-host-8mQV8Uee.js.map} +1 -1
- package/dist/boat-DKRH0Gv7.js +1 -0
- package/dist/boat-DKjqo_ie.js +704 -0
- package/dist/boat-DKjqo_ie.js.map +1 -0
- package/dist/boat-images-CRN_U_eG.js +366 -0
- package/dist/boat-images-CRN_U_eG.js.map +1 -0
- package/dist/bundle-DU2aQVeq.js +780 -0
- package/dist/bundle-DU2aQVeq.js.map +1 -0
- package/dist/{capture-BqIAeFyC.js → capture-By1byHaX.js} +52 -27
- package/dist/capture-By1byHaX.js.map +1 -0
- package/dist/capture-BzjNv0qP.js +1 -0
- package/dist/{cli-s_3opn_I.js → cli-DMHOwdVr.js} +560 -1049
- package/dist/cli-DMHOwdVr.js.map +1 -0
- package/dist/{cli-spec-DxzIjmq_.js → cli-spec-D0wuUaj9.js} +179 -42
- package/dist/cli-spec-D0wuUaj9.js.map +1 -0
- package/dist/cli.js +2 -2
- package/dist/{client-C5fIzHQa.js → client-B41UK150.js} +8 -4
- package/dist/client-B41UK150.js.map +1 -0
- package/dist/{command-BJ7KqczP.js → command-8GIHYGZf.js} +9 -9
- package/dist/{command-BJ7KqczP.js.map → command-8GIHYGZf.js.map} +1 -1
- package/dist/{command-B5OAIjp7.js → command-CAmnWLFL.js} +14 -14
- package/dist/{command-B5OAIjp7.js.map → command-CAmnWLFL.js.map} +1 -1
- package/dist/{command-BXLZsEwQ.js → command-CXxckfsq.js} +13 -13
- package/dist/{command-BXLZsEwQ.js.map → command-CXxckfsq.js.map} +1 -1
- package/dist/{command-DA_SHQUQ.js → command-ao0NZ8h0.js} +16 -15
- package/dist/command-ao0NZ8h0.js.map +1 -0
- package/dist/{commands-BPvAOEmb.js → commands-B3lnIPj5.js} +1 -1
- package/dist/{commands-BKBamOcX.js → commands-ttChCsAy.js} +15 -15
- package/dist/{commands-BKBamOcX.js.map → commands-ttChCsAy.js.map} +1 -1
- package/dist/{config-C0URar0t.js → config-myJT1Qjc.js} +62 -37
- package/dist/config-myJT1Qjc.js.map +1 -0
- package/dist/{context-Sj58aJEu.js → context-DnzR9TNK.js} +2 -2
- package/dist/{context-Sj58aJEu.js.map → context-DnzR9TNK.js.map} +1 -1
- package/dist/cost-CdRX1s2p.js +1 -0
- package/dist/{cursor-catalog-FWgSo-T1.js → cursor-catalog-CUQrabJ_.js} +2 -2
- package/dist/{cursor-catalog-FWgSo-T1.js.map → cursor-catalog-CUQrabJ_.js.map} +1 -1
- package/dist/daytona-Dfhwtr9P.js +677 -0
- package/dist/daytona-Dfhwtr9P.js.map +1 -0
- package/dist/daytona-image-CnG6G00x.js +183 -0
- package/dist/daytona-image-CnG6G00x.js.map +1 -0
- package/dist/daytona-image-yJK3c4EV.js +1 -0
- package/dist/{db-BjAWxVAG.js → db-5H95sFii.js} +35 -9
- package/dist/{db-BjAWxVAG.js.map → db-5H95sFii.js.map} +1 -1
- package/dist/db-Bbg1n_2M.js +2 -0
- package/dist/{default-effort-CWlhZ6U1.js → default-effort-CtNY9CGW.js} +1 -1
- package/dist/{default-effort-Ck2GYIxX.js → default-effort-DYpCkJRk.js} +2 -2
- package/dist/{default-effort-Ck2GYIxX.js.map → default-effort-DYpCkJRk.js.map} +1 -1
- package/dist/{docker-D74l67k8.js → docker-CR0JZ1FE.js} +4 -4
- package/dist/{docker-D74l67k8.js.map → docker-CR0JZ1FE.js.map} +1 -1
- package/dist/docker-kpudeSxV.js +1 -0
- package/dist/{doctor-eFxyn6at.js → doctor-aE-RMbB_.js} +63 -76
- package/dist/doctor-aE-RMbB_.js.map +1 -0
- package/dist/{environment-CJIKz-Ud.js → environment-C8pUCD_A.js} +138 -53
- package/dist/environment-C8pUCD_A.js.map +1 -0
- package/dist/{errors-C1GBcWE2.js → errors-DPUoUTdK.js} +2 -2
- package/dist/{errors-C1GBcWE2.js.map → errors-DPUoUTdK.js.map} +1 -1
- package/dist/{eval-source-CXIRJ91v.js → eval-source-CaLIGH3U.js} +6 -6
- package/dist/{eval-source-CXIRJ91v.js.map → eval-source-CaLIGH3U.js.map} +1 -1
- package/dist/{evaluate-DA4QsrHO.js → evaluate-4kBVtwZZ.js} +250 -215
- package/dist/evaluate-4kBVtwZZ.js.map +1 -0
- package/dist/{evaluate-DHrU4Wld.d.ts → evaluate-DHaNtgVf.d.ts} +2 -2
- package/dist/events-CXxFvVMK.js +475 -0
- package/dist/events-CXxFvVMK.js.map +1 -0
- package/dist/{fake-bootstrap-CnwWG3kP.js → fake-bootstrap-CzxrCqO3.js} +2 -2
- package/dist/{fake-bootstrap-CnwWG3kP.js.map → fake-bootstrap-CzxrCqO3.js.map} +1 -1
- package/dist/files-BFnkOAhn.js +1 -0
- package/dist/files-BgQxoDlN.js +1 -0
- package/dist/{files-D6j-XpaK.js → files-BkvxIqfI.js} +4 -4
- package/dist/{files-D6j-XpaK.js.map → files-BkvxIqfI.js.map} +1 -1
- package/dist/{files-g1watgRC.js → files-CDfG8swM.js} +2 -2
- package/dist/{files-g1watgRC.js.map → files-CDfG8swM.js.map} +1 -1
- package/dist/files-CSe4VaMj.js +1 -0
- package/dist/{files-F44NRCN0.js → files-CX_mmvCc.js} +8 -8
- package/dist/{files-F44NRCN0.js.map → files-CX_mmvCc.js.map} +1 -1
- package/dist/{files-BrGVs4gY.js → files-Cs2dtb7-.js} +2 -2
- package/dist/{files-BrGVs4gY.js.map → files-Cs2dtb7-.js.map} +1 -1
- package/dist/{files-BaqXvB88.js → files-D6M7J3iX.js} +1 -1
- package/dist/{files-BVVWAS0A.js → files-DgHeTdCZ.js} +6 -6
- package/dist/{files-BVVWAS0A.js.map → files-DgHeTdCZ.js.map} +1 -1
- package/dist/{files-Bey1VAex.js → files-DpwJW3w6.js} +3 -3
- package/dist/{files-Bey1VAex.js.map → files-DpwJW3w6.js.map} +1 -1
- package/dist/gateway.d.ts +1 -1
- package/dist/{git-Jqkf9SBa.js → git-BnnNEXqh.js} +3 -3
- package/dist/{git-Jqkf9SBa.js.map → git-BnnNEXqh.js.map} +1 -1
- package/dist/harness-install-BfMBYDfP.js +53 -0
- package/dist/harness-install-BfMBYDfP.js.map +1 -0
- package/dist/harness.d.ts +1 -1
- package/dist/hosted-5Zz2peTR.js +260 -0
- package/dist/hosted-5Zz2peTR.js.map +1 -0
- package/dist/hosted-Co-waHe0.js +131 -0
- package/dist/hosted-Co-waHe0.js.map +1 -0
- package/dist/hosted-run-202QicZ-.js +1 -0
- package/dist/hosted-run-BfAPIMyT.js +230 -0
- package/dist/hosted-run-BfAPIMyT.js.map +1 -0
- package/dist/{ids-B-JKTCP8.js → ids-a6cr243_.js} +17 -12
- package/dist/ids-a6cr243_.js.map +1 -0
- package/dist/{images-Dsc4Wi-F.js → images-DtXwj2wL.js} +70 -55
- package/dist/images-DtXwj2wL.js.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +5 -5
- package/dist/init-BiL6B3S4.js +1 -0
- package/dist/{init-QB5ecPDA.js → init-Ci_IAp8p.js} +5 -5
- package/dist/{init-QB5ecPDA.js.map → init-Ci_IAp8p.js.map} +1 -1
- package/dist/{ink-list-mCJypk3d.js → ink-list-Dnh6XD3C.js} +54 -15
- package/dist/ink-list-Dnh6XD3C.js.map +1 -0
- package/dist/inputs-load-DPUP_IFL.js +95 -0
- package/dist/inputs-load-DPUP_IFL.js.map +1 -0
- package/dist/inputs-load-M-BGe7gd.js +1 -0
- package/dist/inputs-z4JqnQ5g.js +190 -0
- package/dist/inputs-z4JqnQ5g.js.map +1 -0
- package/dist/internal/vm.d.ts +16 -0
- package/dist/internal/vm.js +22 -0
- package/dist/internal/vm.js.map +1 -0
- package/dist/{invocations-BSr4lRzI.js → invocations-C1gY3E0J.js} +4 -4
- package/dist/{invocations-BSr4lRzI.js.map → invocations-C1gY3E0J.js.map} +1 -1
- package/dist/jiti-ILwyxt93.js +54 -0
- package/dist/jiti-ILwyxt93.js.map +1 -0
- package/dist/{judge-eGH39PaP.js → judge-DwzqucLS.js} +9 -6
- package/dist/{judge-eGH39PaP.js.map → judge-DwzqucLS.js.map} +1 -1
- package/dist/judge.d.ts +1 -1
- package/dist/judge.js +1 -1
- package/dist/kinds-DEKXOWVJ.js +592 -0
- package/dist/kinds-DEKXOWVJ.js.map +1 -0
- package/dist/{layout-DfQa4mJs.js → layout-nCnU9Vu2.js} +2 -2
- package/dist/{layout-DfQa4mJs.js.map → layout-nCnU9Vu2.js.map} +1 -1
- package/dist/{list-Dh6T0kdr.js → list-MK4L8tfW.js} +14 -11
- package/dist/{list-Dh6T0kdr.js.map → list-MK4L8tfW.js.map} +1 -1
- package/dist/{live-y1p3oNXH.js → live-BkPNXVmN.js} +8 -8
- package/dist/{live-y1p3oNXH.js.map → live-BkPNXVmN.js.map} +1 -1
- package/dist/{live-xTZs0c61.js → live-Dlq-S2yy.js} +7 -5
- package/dist/live-Dlq-S2yy.js.map +1 -0
- package/dist/live-gZtkBwuo.js +1 -0
- package/dist/machine-service-Byl0BlcT.js +1 -0
- package/dist/machine-service-CZiXiVsS.js +709 -0
- package/dist/machine-service-CZiXiVsS.js.map +1 -0
- package/dist/machines-Ch5bhgvk.js +279 -0
- package/dist/machines-Ch5bhgvk.js.map +1 -0
- package/dist/model-C6aoJLg_.js +1 -0
- package/dist/{model-jRKSQBg6.js → model-CRh8aiYS.js} +6 -5
- package/dist/model-CRh8aiYS.js.map +1 -0
- package/dist/{model-3pZZzloU.js → model-DRa7yv6K.js} +6 -5
- package/dist/model-DRa7yv6K.js.map +1 -0
- package/dist/{model-DNpKiHqO.js → model-LoLnq9y1.js} +2 -2
- package/dist/{model-DNpKiHqO.js.map → model-LoLnq9y1.js.map} +1 -1
- package/dist/{model-DEjwetkJ.js → model-lLaUxxno.js} +1 -1
- package/dist/{node-DM-mLGdX.js → node-BQjSQw0d.js} +19 -8
- package/dist/node-BQjSQw0d.js.map +1 -0
- package/dist/{openrouter-models-C0aRo633.js → openrouter-models-B1sIOTD2.js} +2 -2
- package/dist/{openrouter-models-C0aRo633.js.map → openrouter-models-B1sIOTD2.js.map} +1 -1
- package/dist/options-I9I3FwMl.js +1 -0
- package/dist/own-reads-CYmBlrHK.js +15 -0
- package/dist/own-reads-CYmBlrHK.js.map +1 -0
- package/dist/{patch-Bx-qp8Li.js → patch-D8X6VB-e.js} +2 -2
- package/dist/{patch-Bx-qp8Li.js.map → patch-D8X6VB-e.js.map} +1 -1
- package/dist/{plan-ChO0A-xn.js → plan-DgIVIrXJ.js} +47 -9
- package/dist/plan-DgIVIrXJ.js.map +1 -0
- package/dist/{plugins-BioMWncI.js → plugins-DvEbow6a.js} +17 -637
- package/dist/plugins-DvEbow6a.js.map +1 -0
- package/dist/{preflight-CJSGzMzc.js → preflight-BKGbxN67.js} +9 -8
- package/dist/preflight-BKGbxN67.js.map +1 -0
- package/dist/{preflight-qFCXmxha.js → preflight-Qm4wE094.js} +9 -4
- package/dist/preflight-Qm4wE094.js.map +1 -0
- package/dist/preflight-dJqs5x3r.js +1 -0
- package/dist/preflight-fyV5nnea.js +1 -0
- package/dist/prepare-BAjRSoku.js +389 -0
- package/dist/prepare-BAjRSoku.js.map +1 -0
- package/dist/prepare-CRPPfRJf.js +2 -0
- package/dist/prices-C0gKS_8G.js +1 -0
- package/dist/{prices-BrY_ihLs.js → prices-DCokI_Ka.js} +3 -3
- package/dist/{prices-BrY_ihLs.js.map → prices-DCokI_Ka.js.map} +1 -1
- package/dist/{provenance-B-flBAzR.js → provenance-CSyRCc9B.js} +4 -4
- package/dist/{provenance-B-flBAzR.js.map → provenance-CSyRCc9B.js.map} +1 -1
- package/dist/{providers-B6StVyfG.js → providers-DkaEJvF5.js} +185 -35
- package/dist/providers-DkaEJvF5.js.map +1 -0
- package/dist/providers-DxZ26YoG.js +1 -0
- package/dist/{query-CkLmJv7R.js → query-BL66BOqL.js} +2 -2
- package/dist/{query-CkLmJv7R.js.map → query-BL66BOqL.js.map} +1 -1
- package/dist/query-C9OKU1Vz.js +1 -0
- package/dist/{questions-CJIh2FSX.js → questions-boVPzGoC.js} +7 -7
- package/dist/{questions-CJIh2FSX.js.map → questions-boVPzGoC.js.map} +1 -1
- package/dist/recipe-qyIpP96r.js +128 -0
- package/dist/recipe-qyIpP96r.js.map +1 -0
- package/dist/{record-nVVujCW7.js → record-D1_D1KFY.js} +12 -4
- package/dist/record-D1_D1KFY.js.map +1 -0
- package/dist/{redact-DL2BTykw.js → redact-t-L3VGy8.js} +91 -2
- package/dist/redact-t-L3VGy8.js.map +1 -0
- package/dist/{remarks-B3wjKscW.js → remarks-DEvk5f8v.js} +7 -7
- package/dist/{remarks-B3wjKscW.js.map → remarks-DEvk5f8v.js.map} +1 -1
- package/dist/{remote-C88amFRN.js → remote-CQoBRpOv.js} +5 -5
- package/dist/{remote-C88amFRN.js.map → remote-CQoBRpOv.js.map} +1 -1
- package/dist/resolve-BdpO8BN1.js +1 -0
- package/dist/{resolve-Bul8lHaa.js → resolve-Bfo8sjd-.js} +2 -2
- package/dist/{resolve-Bul8lHaa.js.map → resolve-Bfo8sjd-.js.map} +1 -1
- package/dist/{resolve-G576PiFJ.js → resolve-D2RqmybX.js} +9 -9
- package/dist/{resolve-G576PiFJ.js.map → resolve-D2RqmybX.js.map} +1 -1
- package/dist/resources-DqdwihhT.js +62 -0
- package/dist/resources-DqdwihhT.js.map +1 -0
- package/dist/{results-zVHIW6xw.js → results-BpxzyoMd.js} +5 -5
- package/dist/{results-zVHIW6xw.js.map → results-BpxzyoMd.js.map} +1 -1
- package/dist/{resume-D_PcUXfG.js → resume-2ekm_9OB.js} +78 -7
- package/dist/resume-2ekm_9OB.js.map +1 -0
- package/dist/{retry-BvTzCxdc.js → retry-CAhpW1hH.js} +4 -4
- package/dist/{retry-BvTzCxdc.js.map → retry-CAhpW1hH.js.map} +1 -1
- package/dist/{routes-B0F2R-K7.js → routes-Cp4gAjBZ.js} +118 -70
- package/dist/routes-Cp4gAjBZ.js.map +1 -0
- package/dist/{runtime-B3r_pAq6.js → runtime-C5fKSFCz.js} +46 -5
- package/dist/runtime-C5fKSFCz.js.map +1 -0
- package/dist/sandbox/boat.d.ts +11 -3
- package/dist/sandbox/boat.js +18 -4
- package/dist/sandbox/boat.js.map +1 -1
- package/dist/sandbox/daytona.d.ts +30 -0
- package/dist/sandbox/daytona.js +49 -0
- package/dist/sandbox/daytona.js.map +1 -0
- package/dist/{sandbox-Duh3z1TV.js → sandbox-t-Q-8lA_.js} +2 -2
- package/dist/{sandbox-Duh3z1TV.js.map → sandbox-t-Q-8lA_.js.map} +1 -1
- package/dist/sandbox.d.ts +1 -1
- package/dist/sandbox.js +1 -1
- package/dist/{server-DUWMRKik.js → server-BcLg9WzE.js} +10 -10
- package/dist/{server-DUWMRKik.js.map → server-BcLg9WzE.js.map} +1 -1
- package/dist/server-Buav2-CG.js +1 -0
- package/dist/services-BG8xuU82.js +39 -0
- package/dist/services-BG8xuU82.js.map +1 -0
- package/dist/{source-CHuN4Nfg.js → source-CrXM19HD.js} +2 -2
- package/dist/{source-CHuN4Nfg.js.map → source-CrXM19HD.js.map} +1 -1
- package/dist/source-dvxkqYvk.js +1 -0
- package/dist/src-5dCrqbFd.js +2 -0
- package/dist/{src-BI0v8qlZ.js → src-Bb3k9Kn_.js} +8 -5
- package/dist/{src-BI0v8qlZ.js.map → src-Bb3k9Kn_.js.map} +1 -1
- package/dist/{src-boB6D-5T.js → src-Bf5RZlPi.js} +2 -2
- package/dist/{src-boB6D-5T.js.map → src-Bf5RZlPi.js.map} +1 -1
- package/dist/{src-BqNzHHWn.js → src-C3OhA5pw.js} +2 -2
- package/dist/{src-BqNzHHWn.js.map → src-C3OhA5pw.js.map} +1 -1
- package/dist/{src-BHJ4MWvY.js → src-C5rrQlt8.js} +2199 -771
- package/dist/src-C5rrQlt8.js.map +1 -0
- package/dist/{src-CeBhwD8k.js → src-C6MsGyD6.js} +1 -1
- package/dist/{src-De0KY5S_.js → src-Cf4vRyea.js} +2 -2
- package/dist/src-DEbNp-rx.js +1 -0
- package/dist/{src-B-HuDqpH.js → src-DNWiU__5.js} +2 -2
- package/dist/{src-B-HuDqpH.js.map → src-DNWiU__5.js.map} +1 -1
- package/dist/src-DrLbG1HM.js +2 -0
- package/dist/{src--yl1OypK.js → src-Ds1pmXTg.js} +2 -2
- package/dist/{src-DA95rM6v.js → src-DwcCKsV0.js} +2 -2
- package/dist/{src-CmA5Yev6.js → src-DwcTn4JY.js} +2 -2
- package/dist/{src-CmA5Yev6.js.map → src-DwcTn4JY.js.map} +1 -1
- package/dist/{src-CZaYu6ER.js → src-VG2IRoT4.js} +1 -1
- package/dist/{src-DL-EE4DU.js → src-c3ZQu7Uu.js} +2 -2
- package/dist/{src-DL-EE4DU.js.map → src-c3ZQu7Uu.js.map} +1 -1
- package/dist/{src-CkEiiyON.js → src-io_SKoZ5.js} +2 -2
- package/dist/ssh-pool-BorCizYw.js +1 -0
- package/dist/ssh-pool-Dvfx5GuV.js +174 -0
- package/dist/ssh-pool-Dvfx5GuV.js.map +1 -0
- package/dist/start-COB07NpH.js +718 -0
- package/dist/start-COB07NpH.js.map +1 -0
- package/dist/{state-DUBRDyMk.js → state-B319V1p8.js} +16 -16
- package/dist/{state-DUBRDyMk.js.map → state-B319V1p8.js.map} +1 -1
- package/dist/state-C5oBvmoZ.js +1 -0
- package/dist/store/local.d.ts +1 -1
- package/dist/store/s3.d.ts +1 -1
- package/dist/suite-BwJGOhCZ.js +2 -0
- package/dist/{suite-B9J6Afg6.js → suite-D1tgXZxM.js} +2 -2
- package/dist/{suite-B9J6Afg6.js.map → suite-D1tgXZxM.js.map} +1 -1
- package/dist/{summary-CSp4cfnr.js → summary-ClLns_wv.js} +8 -5
- package/dist/summary-ClLns_wv.js.map +1 -0
- package/dist/{sync-CxAY6Dki.js → sync-mOG74RXH.js} +5 -5
- package/dist/{sync-CxAY6Dki.js.map → sync-mOG74RXH.js.map} +1 -1
- package/dist/{tart-CcrrtSrp.js → tart-DMppfbEm.js} +100 -295
- package/dist/tart-DMppfbEm.js.map +1 -0
- package/dist/{tart-bake-F-6seRC9.js → tart-bake-Cva_qdir.js} +18 -62
- package/dist/tart-bake-Cva_qdir.js.map +1 -0
- package/dist/{tart-bake-RK7RaT9E.js → tart-bake-DVIoXWr_.js} +1 -1
- package/dist/{tart-cli-ClvRniLQ.js → tart-cli-D88c5YYJ.js} +1 -1
- package/dist/{tart-cli-B86Jqo1t.js → tart-cli-LzDud2Z6.js} +2 -2
- package/dist/{tart-cli-B86Jqo1t.js.map → tart-cli-LzDud2Z6.js.map} +1 -1
- package/dist/{tart-hosts-Brii7zHM.js → tart-hosts-8N6Tt7Yb.js} +1 -1
- package/dist/{tart-hosts-DPyZsg-1.js → tart-hosts-CTRY5kQ2.js} +3 -3
- package/dist/{tart-hosts-DPyZsg-1.js.map → tart-hosts-CTRY5kQ2.js.map} +1 -1
- package/dist/{tart-images-CWSf03w8.js → tart-images-JfHirU8W.js} +2 -2
- package/dist/{tart-images-CWSf03w8.js.map → tart-images-JfHirU8W.js.map} +1 -1
- package/dist/testing.d.ts +2 -2
- package/dist/testing.js +4 -4
- package/dist/{tool-class-CVDdJy0H.js → tool-class-CncfCw03.js} +2 -2
- package/dist/{tool-class-CVDdJy0H.js.map → tool-class-CncfCw03.js.map} +1 -1
- package/dist/{transcript-BP_2hji-.js → transcript-BXWZiMuC.js} +2 -2
- package/dist/{transcript-BP_2hji-.js.map → transcript-BXWZiMuC.js.map} +1 -1
- package/dist/{types-BJ0wh8wC.d.ts → types-BDo8ttQo.d.ts} +253 -5
- package/dist/types-CbcnJxCy.js.map +1 -1
- package/dist/ui-DUiVPbQ2.js +1024 -0
- package/dist/ui-DUiVPbQ2.js.map +1 -0
- package/dist/vercel-models-Ci33llXz.js +21 -0
- package/dist/vercel-models-Ci33llXz.js.map +1 -0
- package/dist/view/index.d.ts +6 -1
- package/dist/view/index.js +4 -4
- package/dist/views-B0qZR5Ef.js +2 -0
- package/dist/{views-DRxXCyIH.js → views-CiZGh3ws.js} +6 -6
- package/dist/{views-DRxXCyIH.js.map → views-CiZGh3ws.js.map} +1 -1
- package/dist/vm-container-BVn7pXfD.js +148 -0
- package/dist/vm-container-BVn7pXfD.js.map +1 -0
- package/dist/vm-images-CNk-Zl2a.js +375 -0
- package/dist/vm-images-CNk-Zl2a.js.map +1 -0
- package/dist/{worker-entry-C3Q4U63F.js → worker-entry-DmXQ2Znu.js} +31 -11
- package/dist/worker-entry-DmXQ2Znu.js.map +1 -0
- package/dist/workspace-CRgFdmgW.js +1 -0
- package/dist/{workspace-P72SXLXr.js → workspace-wwvwEHzP.js} +6 -6
- package/dist/{workspace-P72SXLXr.js.map → workspace-wwvwEHzP.js.map} +1 -1
- package/docker/Dockerfile +1 -1
- package/package.json +17 -2
- package/skills/reeval/references/environments.md +4 -3
- package/dist/adapter-BdzhdRYo.js.map +0 -1
- package/dist/agent-Dx-bDmlV.js.map +0 -1
- package/dist/agents-l0-k7vw3.js.map +0 -1
- package/dist/app-files-B-CQYB0c.js.map +0 -1
- package/dist/boat-CZpAreTB.js +0 -108
- package/dist/boat-CZpAreTB.js.map +0 -1
- package/dist/boat-su1Y7LPd.js +0 -325
- package/dist/boat-su1Y7LPd.js.map +0 -1
- package/dist/capture-BqIAeFyC.js.map +0 -1
- package/dist/capture-D0Ln5aCP.js +0 -1
- package/dist/cli-s_3opn_I.js.map +0 -1
- package/dist/cli-spec-DxzIjmq_.js.map +0 -1
- package/dist/client-C5fIzHQa.js.map +0 -1
- package/dist/command-DA_SHQUQ.js.map +0 -1
- package/dist/config-C0URar0t.js.map +0 -1
- package/dist/cost-IM80LyGD.js +0 -1
- package/dist/db-Bc4L-Wcr.js +0 -2
- package/dist/docker-CDdK6Ity.js +0 -271
- package/dist/docker-CDdK6Ity.js.map +0 -1
- package/dist/docker-DMug3l-a.js +0 -1
- package/dist/doctor-eFxyn6at.js.map +0 -1
- package/dist/environment-CJIKz-Ud.js.map +0 -1
- package/dist/evaluate-DA4QsrHO.js.map +0 -1
- package/dist/files-BjOJw4sn.js +0 -1
- package/dist/files-CNHhSyb3.js +0 -1
- package/dist/files-CW1lChNh.js +0 -1
- package/dist/ids-B-JKTCP8.js.map +0 -1
- package/dist/images-Dsc4Wi-F.js.map +0 -1
- package/dist/init-C0oUG3jh.js +0 -1
- package/dist/ink-list-mCJypk3d.js.map +0 -1
- package/dist/live-DwjWJTdn.js +0 -1
- package/dist/live-xTZs0c61.js.map +0 -1
- package/dist/model-3pZZzloU.js.map +0 -1
- package/dist/model-jRKSQBg6.js.map +0 -1
- package/dist/model-nfewGTzB.js +0 -1
- package/dist/node-DM-mLGdX.js.map +0 -1
- package/dist/options-DpsJ_5CU.js +0 -1
- package/dist/plan-ChO0A-xn.js.map +0 -1
- package/dist/plugins-BioMWncI.js.map +0 -1
- package/dist/preflight-BUjk_6wT.js +0 -1
- package/dist/preflight-CJSGzMzc.js.map +0 -1
- package/dist/preflight-DD3fI4Hz.js +0 -1
- package/dist/preflight-qFCXmxha.js.map +0 -1
- package/dist/prepare-D7oSSFNm.js +0 -268
- package/dist/prepare-D7oSSFNm.js.map +0 -1
- package/dist/prepare-xHU2BpN-.js +0 -2
- package/dist/prices-B1vm_lPk.js +0 -1
- package/dist/providers-B6StVyfG.js.map +0 -1
- package/dist/providers-Dljf6al6.js +0 -1
- package/dist/query-BAc2tQZj.js +0 -1
- package/dist/record-nVVujCW7.js.map +0 -1
- package/dist/redact-DL2BTykw.js.map +0 -1
- package/dist/resolve-DW92wpIZ.js +0 -1
- package/dist/resume-D_PcUXfG.js.map +0 -1
- package/dist/routes-B0F2R-K7.js.map +0 -1
- package/dist/runtime-B3r_pAq6.js.map +0 -1
- package/dist/server-CGEsvVRG.js +0 -1
- package/dist/source-Wz1Nrfue.js +0 -1
- package/dist/src-BHJ4MWvY.js.map +0 -1
- package/dist/src-BL-_0QoE.js +0 -1
- package/dist/src-C-mOSczH.js +0 -2
- package/dist/src-CwH_nEaw.js +0 -2
- package/dist/state-B3jex5KU.js +0 -1
- package/dist/suite-Bhs9-Z7O.js +0 -2
- package/dist/summary-CSp4cfnr.js.map +0 -1
- package/dist/tarball-CESxtK4X.js +0 -257
- package/dist/tarball-CESxtK4X.js.map +0 -1
- package/dist/tart-CcrrtSrp.js.map +0 -1
- package/dist/tart-bake-F-6seRC9.js.map +0 -1
- package/dist/views-i67V1ly3.js +0 -2
- package/dist/worker-entry-C3Q4U63F.js.map +0 -1
- package/dist/workspace-DhUOW8if.js +0 -1
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { u as ownFileURL } from "./root-BzeoyfGd.js";
|
|
2
|
-
import { existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, readlinkSync, renameSync, writeFileSync } from "node:fs";
|
|
3
|
-
import { basename, dirname, join, posix, relative, win32 } from "node:path";
|
|
2
|
+
import { existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, readlinkSync, renameSync, statSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { basename, dirname, isAbsolute, join, posix, relative, resolve, sep, win32 } from "node:path";
|
|
4
4
|
import { execFileSync, spawn } from "node:child_process";
|
|
5
5
|
import { createHash, generateKeyPairSync, randomBytes, randomInt, sign } from "node:crypto";
|
|
6
6
|
import { tmpdir } from "node:os";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
8
|
import { createHarnessSandboxTemplate } from "@ai-sdk/harness/agent";
|
|
9
|
-
import { isUtf8 } from "node:buffer";
|
|
10
9
|
import dockerignore from "@balena/dockerignore";
|
|
10
|
+
import { lstat, mkdir, readFile, readdir, readlink, symlink, utimes, writeFile } from "node:fs/promises";
|
|
11
|
+
import { isUtf8 } from "node:buffer";
|
|
11
12
|
import { Duplex, Readable, Transform } from "node:stream";
|
|
12
13
|
import net, { BlockList, isIP } from "node:net";
|
|
13
14
|
import http from "node:http";
|
|
@@ -17,6 +18,7 @@ import tls from "node:tls";
|
|
|
17
18
|
import zlib from "node:zlib";
|
|
18
19
|
import { lookup } from "node:dns/promises";
|
|
19
20
|
// ../sandbox-docker/src/engine.ts
|
|
21
|
+
const isRemoteEngine = (engine) => typeof engine === "object";
|
|
20
22
|
/**
|
|
21
23
|
* Docker's default seccomp profile, copied unmodified from moby/profiles (Apache-2.0),
|
|
22
24
|
* seccomp/default.json at 6fe7deb1b9fb7c0397a4593480d7d22b9ee8caef. Podman gets it on every
|
|
@@ -75,7 +77,8 @@ const ENGINES = {
|
|
|
75
77
|
createsWorkdir: false
|
|
76
78
|
}
|
|
77
79
|
};
|
|
78
|
-
|
|
80
|
+
/** A remote engine is Docker's CLI, as on this machine. */
|
|
81
|
+
const engineSpec = (engine = "docker") => ENGINES[isRemoteEngine(engine) ? "docker" : engine];
|
|
79
82
|
/**
|
|
80
83
|
* The `CONTAINER_HOST` that reaches a `podman machine` straight through its API socket (macOS) or
|
|
81
84
|
* named pipe (Windows), from `podman machine inspect`'s JSON.
|
|
@@ -290,7 +293,7 @@ function windowsSpawn(cmd, args, env = process.env, exists = existsSync) {
|
|
|
290
293
|
* Kills a process and everything it started: its process group on POSIX (a detached child leads
|
|
291
294
|
* one), its process tree with `taskkill` on Windows, which has neither groups nor signals.
|
|
292
295
|
*/
|
|
293
|
-
function killTree(pid) {
|
|
296
|
+
function killTree$1(pid) {
|
|
294
297
|
if (process.platform === "win32") {
|
|
295
298
|
spawn("taskkill", [
|
|
296
299
|
"/pid",
|
|
@@ -344,7 +347,7 @@ function run(cmd, args, options = {}) {
|
|
|
344
347
|
stderr += d;
|
|
345
348
|
});
|
|
346
349
|
const onAbort = () => {
|
|
347
|
-
if ((detached || process.platform === "win32") && child.pid) killTree(child.pid);
|
|
350
|
+
if ((detached || process.platform === "win32") && child.pid) killTree$1(child.pid);
|
|
348
351
|
else child.kill("SIGKILL");
|
|
349
352
|
};
|
|
350
353
|
signal?.addEventListener("abort", onAbort, { once: true });
|
|
@@ -364,6 +367,631 @@ function run(cmd, args, options = {}) {
|
|
|
364
367
|
child.stdin.end(options.input ?? "");
|
|
365
368
|
});
|
|
366
369
|
}
|
|
370
|
+
// ../sandbox-docker/src/dockerignore.ts
|
|
371
|
+
const ignore = dockerignore.default;
|
|
372
|
+
/**
|
|
373
|
+
* A pattern `@balena/dockerignore` may match differently from BuildKit: escapes, character
|
|
374
|
+
* classes and the regexp characters it doesn't escape, a `**` joined to other characters, and the
|
|
375
|
+
* whitespace Go and JavaScript trim differently. One over 1024 characters is risky too, since
|
|
376
|
+
* JavaScript refuses a regexp that long that Go accepts, and so is one with more than four `*`
|
|
377
|
+
* runs, whose JavaScript regexp can backtrack for minutes where Go's runs in linear time.
|
|
378
|
+
*/
|
|
379
|
+
const RISKY = /[\\[\]^+(){}|\u0085\uFEFF]|[^/]\*\*|\*\*[^/]/;
|
|
380
|
+
const MAX_STARS = 4;
|
|
381
|
+
/**
|
|
382
|
+
* Names `@balena/dockerignore` may match differently: `?` matches one UTF-16 unit there and one
|
|
383
|
+
* code point in BuildKit, and `.` doesn't match a line terminator there but does in Go.
|
|
384
|
+
*/
|
|
385
|
+
const ODD_NAME = /[\n\r\u2028\u2029\u{10000}-\u{10FFFF}]/u;
|
|
386
|
+
const clean = (pattern) => posix.normalize(pattern).replace(/^\/+/, "").replace(/\/+$/, "");
|
|
387
|
+
/**
|
|
388
|
+
* `.dockerignore` lines as Docker reads them: a BOM is dropped, a line starting `#` is a comment,
|
|
389
|
+
* and `!` re-includes. A path is left out when a rule excludes it and no `!` rule matches it or a
|
|
390
|
+
* directory it's in: BuildKit then excludes it whatever order the rules are in, so this never
|
|
391
|
+
* leaves out a file `docker build` sends, though it keeps some it doesn't. A risky exclusion is
|
|
392
|
+
* dropped, and a risky `!` rule keeps everything, as does one `@balena/dockerignore` would read
|
|
393
|
+
* as a comment or a pattern that cleans to a leading `!` (`!!a`, `/ !a`), which the two read
|
|
394
|
+
* differently.
|
|
395
|
+
*/
|
|
396
|
+
function parseRules(text) {
|
|
397
|
+
const excludes = [];
|
|
398
|
+
const reincludes = [];
|
|
399
|
+
for (const line of text.replace(/^\uFEFF/, "").split(/\r?\n/)) {
|
|
400
|
+
if (line.startsWith("#")) continue;
|
|
401
|
+
let pattern = line.trim();
|
|
402
|
+
const negate = pattern.startsWith("!");
|
|
403
|
+
if (negate) pattern = pattern.slice(1).trim();
|
|
404
|
+
if (!pattern) continue;
|
|
405
|
+
const cleaned = clean(pattern);
|
|
406
|
+
const risky = RISKY.test(pattern) || pattern.length > 1024 || (pattern.match(/\*+/g)?.length ?? 0) > MAX_STARS || [".", ""].includes(cleaned);
|
|
407
|
+
if (cleaned.trim().startsWith("!") || negate && pattern.startsWith("#") || negate && risky) return {
|
|
408
|
+
left: () => false,
|
|
409
|
+
literal: null
|
|
410
|
+
};
|
|
411
|
+
if (!negate) {
|
|
412
|
+
if (!risky) excludes.push(line);
|
|
413
|
+
} else reincludes.push(pattern);
|
|
414
|
+
}
|
|
415
|
+
const exclude = ignore({ ignorecase: false }).add(excludes);
|
|
416
|
+
const reinclude = ignore({ ignorecase: false }).add(reincludes);
|
|
417
|
+
return {
|
|
418
|
+
left: (path) => !ODD_NAME.test(path) && exclude.ignores(path) && !reinclude.ignores(path),
|
|
419
|
+
literal: reincludes.some((p) => /[*?]/.test(p)) ? null : reincludes.map(clean)
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
/** Whether reeval leaves `path` out of a hash under these `.dockerignore` rules. */
|
|
423
|
+
function dockerignoreMatcher(text) {
|
|
424
|
+
return parseRules(text).left;
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* Files in the build context that reeval hashes, sorted, relative to `context`: every file
|
|
428
|
+
* `docker build` sends (and some it doesn't), plus the Dockerfile and `.dockerignore`. A
|
|
429
|
+
* Dockerfile read from stdin (`dockerfile` null) has no `<Dockerfile>.dockerignore` of its own.
|
|
430
|
+
* A left-out directory is skipped only when every `!` rule is a literal path outside it. Docker
|
|
431
|
+
* doesn't apply an ignore file that's a symlink or not a file, so then every file is hashed; nor
|
|
432
|
+
* can it send what's in a directory it can't read.
|
|
433
|
+
*/
|
|
434
|
+
function contextFiles(context, dockerfile) {
|
|
435
|
+
const own = [...dockerfile ? [`${dockerfile}.dockerignore`] : [], join(context, ".dockerignore")].map((path) => ({
|
|
436
|
+
path,
|
|
437
|
+
stat: lstatSync(path, { throwIfNoEntry: false })
|
|
438
|
+
})).find(({ stat }) => stat);
|
|
439
|
+
const { left, literal } = parseRules(own?.stat?.isFile() ? readFileSync(own.path, "utf8") : "");
|
|
440
|
+
const always = [...dockerfile ? [relative(context, dockerfile)] : [], ".dockerignore"].map((path) => path.split("\\").join("/"));
|
|
441
|
+
const reach = [...always, ...literal ?? []];
|
|
442
|
+
const files = [];
|
|
443
|
+
const walk = (rel) => {
|
|
444
|
+
let entries;
|
|
445
|
+
try {
|
|
446
|
+
entries = readdirSync(join(context, rel), { withFileTypes: true });
|
|
447
|
+
} catch (error) {
|
|
448
|
+
if (rel && ["EACCES", "EPERM"].includes(error.code ?? "")) return;
|
|
449
|
+
throw error;
|
|
450
|
+
}
|
|
451
|
+
for (const entry of entries) {
|
|
452
|
+
const path = rel ? `${rel}/${entry.name}` : entry.name;
|
|
453
|
+
if (entry.isDirectory()) {
|
|
454
|
+
if (!(left(path) && literal && !reach.some((p) => p.startsWith(`${path}/`)))) walk(path);
|
|
455
|
+
} else if (!left(path) || always.includes(path)) files.push(path);
|
|
456
|
+
}
|
|
457
|
+
};
|
|
458
|
+
walk("");
|
|
459
|
+
return files.sort();
|
|
460
|
+
}
|
|
461
|
+
// ../sandbox-docker/src/tarball.ts
|
|
462
|
+
const BLOCK = 512;
|
|
463
|
+
const text$1 = (b, at, len) => {
|
|
464
|
+
const field = b.subarray(at, at + len);
|
|
465
|
+
const end = field.indexOf(0);
|
|
466
|
+
return (end < 0 ? field : field.subarray(0, end)).toString("utf8");
|
|
467
|
+
};
|
|
468
|
+
function octal(b, at, len) {
|
|
469
|
+
if ((b[at] ?? 0) & 128) {
|
|
470
|
+
let n = (b[at] ?? 0) & 127;
|
|
471
|
+
for (let i = 1; i < len; i++) n = n * 256 + (b[at + i] ?? 0);
|
|
472
|
+
return n;
|
|
473
|
+
}
|
|
474
|
+
const digits = text$1(b, at, len).trim();
|
|
475
|
+
return digits ? Number.parseInt(digits, 8) : 0;
|
|
476
|
+
}
|
|
477
|
+
/** `a/./b/` as `a/b`; null for a path that's absolute, empty or climbs out with `..`. */
|
|
478
|
+
function safeTarPath(path) {
|
|
479
|
+
if (path.startsWith("/") || /^[A-Za-z]:/.test(path) || path.includes("\\")) return null;
|
|
480
|
+
const parts = path.split("/").filter((p) => p !== "" && p !== ".");
|
|
481
|
+
if (!parts.length || parts.includes("..")) return null;
|
|
482
|
+
return parts.join("/");
|
|
483
|
+
}
|
|
484
|
+
function paxRecords(data) {
|
|
485
|
+
const out = {};
|
|
486
|
+
let at = 0;
|
|
487
|
+
while (at < data.length) {
|
|
488
|
+
const space = data.indexOf(32, at);
|
|
489
|
+
if (space < 0) break;
|
|
490
|
+
const len = Number(data.subarray(at, space).toString());
|
|
491
|
+
if (!(len > 0)) break;
|
|
492
|
+
const record = data.subarray(space + 1, at + len - 1).toString("utf8");
|
|
493
|
+
const eq = record.indexOf("=");
|
|
494
|
+
if (eq > 0) out[record.slice(0, eq)] = record.slice(eq + 1);
|
|
495
|
+
at += len;
|
|
496
|
+
}
|
|
497
|
+
return out;
|
|
498
|
+
}
|
|
499
|
+
/** The entries of an uncompressed tar, hard links resolved to copies of what they link to. */
|
|
500
|
+
function readTar(tar) {
|
|
501
|
+
const out = [];
|
|
502
|
+
const files = /* @__PURE__ */ new Map();
|
|
503
|
+
let longName;
|
|
504
|
+
let longLink;
|
|
505
|
+
let pax = {};
|
|
506
|
+
let at = 0;
|
|
507
|
+
while (at + BLOCK <= tar.length) {
|
|
508
|
+
const h = tar.subarray(at, at + BLOCK);
|
|
509
|
+
if (h.every((byte) => byte === 0)) break;
|
|
510
|
+
const type = String.fromCharCode(h[156] ?? 0);
|
|
511
|
+
const size = pax.size !== void 0 ? Number(pax.size) : octal(h, 124, 12);
|
|
512
|
+
if (!Number.isSafeInteger(size) || size < 0) break;
|
|
513
|
+
const data = tar.subarray(at + BLOCK, at + BLOCK + size);
|
|
514
|
+
at += BLOCK + Math.ceil(size / BLOCK) * BLOCK;
|
|
515
|
+
if (type === "L") {
|
|
516
|
+
longName = text$1(data, 0, data.length);
|
|
517
|
+
continue;
|
|
518
|
+
}
|
|
519
|
+
if (type === "K") {
|
|
520
|
+
longLink = text$1(data, 0, data.length);
|
|
521
|
+
continue;
|
|
522
|
+
}
|
|
523
|
+
if (type === "x") {
|
|
524
|
+
pax = {
|
|
525
|
+
...pax,
|
|
526
|
+
...paxRecords(data)
|
|
527
|
+
};
|
|
528
|
+
continue;
|
|
529
|
+
}
|
|
530
|
+
if (type === "g") continue;
|
|
531
|
+
const prefix = text$1(h, 257, 6).startsWith("ustar") ? text$1(h, 345, 155) : "";
|
|
532
|
+
const name = text$1(h, 0, 100);
|
|
533
|
+
const raw = pax.path ?? longName ?? (prefix ? `${prefix}/${name}` : name);
|
|
534
|
+
const link = pax.linkpath ?? longLink ?? text$1(h, 157, 100);
|
|
535
|
+
const mtime = pax.mtime !== void 0 ? Math.floor(Number(pax.mtime)) : octal(h, 136, 12);
|
|
536
|
+
longName = longLink = void 0;
|
|
537
|
+
pax = {};
|
|
538
|
+
const path = safeTarPath(raw);
|
|
539
|
+
if (!path) continue;
|
|
540
|
+
const mode = octal(h, 100, 8) & 4095;
|
|
541
|
+
if (type === "0" || type === "\0" || type === "7") {
|
|
542
|
+
const copy = Buffer.from(data);
|
|
543
|
+
files.set(path, copy);
|
|
544
|
+
out.push({
|
|
545
|
+
type: "file",
|
|
546
|
+
path,
|
|
547
|
+
mode,
|
|
548
|
+
mtime,
|
|
549
|
+
data: copy
|
|
550
|
+
});
|
|
551
|
+
} else if (type === "1") {
|
|
552
|
+
const target = safeTarPath(link);
|
|
553
|
+
const linked = target ? files.get(target) : void 0;
|
|
554
|
+
if (linked) out.push({
|
|
555
|
+
type: "file",
|
|
556
|
+
path,
|
|
557
|
+
mode,
|
|
558
|
+
mtime,
|
|
559
|
+
data: linked
|
|
560
|
+
});
|
|
561
|
+
} else if (type === "2") out.push({
|
|
562
|
+
type: "symlink",
|
|
563
|
+
path,
|
|
564
|
+
mode,
|
|
565
|
+
mtime,
|
|
566
|
+
target: link
|
|
567
|
+
});
|
|
568
|
+
else if (type === "5") out.push({
|
|
569
|
+
type: "dir",
|
|
570
|
+
path,
|
|
571
|
+
mode,
|
|
572
|
+
mtime
|
|
573
|
+
});
|
|
574
|
+
}
|
|
575
|
+
return out;
|
|
576
|
+
}
|
|
577
|
+
function paxEntry(fields) {
|
|
578
|
+
const body = Object.entries(fields).map(([k, v]) => {
|
|
579
|
+
const rest = ` ${k}=${v}\n`;
|
|
580
|
+
const restBytes = Buffer.byteLength(rest);
|
|
581
|
+
let len = restBytes + String(restBytes).length;
|
|
582
|
+
if (String(len).length > String(restBytes).length) len = restBytes + String(len).length;
|
|
583
|
+
return `${len}${rest}`;
|
|
584
|
+
}).join("");
|
|
585
|
+
const data = Buffer.from(body);
|
|
586
|
+
return Buffer.concat([header("PaxHeader", 420, data.length, 0, "x", ""), pad(data)]);
|
|
587
|
+
}
|
|
588
|
+
const pad = (data) => Buffer.concat([data, Buffer.alloc((BLOCK - data.length % BLOCK) % BLOCK)]);
|
|
589
|
+
function header(name, mode, size, mtime, type, link) {
|
|
590
|
+
const h = Buffer.alloc(BLOCK);
|
|
591
|
+
const put = (value, at, len) => {
|
|
592
|
+
Buffer.from(value).copy(h, at, 0, Math.min(len, Buffer.byteLength(value)));
|
|
593
|
+
};
|
|
594
|
+
const num = (value, at, len) => put(`${value.toString(8).padStart(len - 1, "0")}\0`, at, len);
|
|
595
|
+
put(name, 0, 100);
|
|
596
|
+
num(mode, 100, 8);
|
|
597
|
+
num(0, 108, 8);
|
|
598
|
+
num(0, 116, 8);
|
|
599
|
+
num(size, 124, 12);
|
|
600
|
+
num(Math.max(0, mtime), 136, 12);
|
|
601
|
+
h.fill(32, 148, 156);
|
|
602
|
+
put(type, 156, 1);
|
|
603
|
+
put(link, 157, 100);
|
|
604
|
+
put("ustar\0", 257, 6);
|
|
605
|
+
put("00", 263, 2);
|
|
606
|
+
let sum = 0;
|
|
607
|
+
for (const byte of h) sum += byte;
|
|
608
|
+
put(`${sum.toString(8).padStart(6, "0")}\0 `, 148, 8);
|
|
609
|
+
return h;
|
|
610
|
+
}
|
|
611
|
+
const fits = (s) => Buffer.byteLength(s) <= 100 && /^[\x20-\x7e]*$/.test(s);
|
|
612
|
+
/** An uncompressed tar of `entries`, with a pax header for a path or link target ustar can't hold. */
|
|
613
|
+
function writeTar(entries) {
|
|
614
|
+
const parts = [];
|
|
615
|
+
for (const e of entries) {
|
|
616
|
+
const name = e.type === "dir" ? `${e.path}/` : e.path;
|
|
617
|
+
const link = e.type === "symlink" ? e.target : "";
|
|
618
|
+
const long = {};
|
|
619
|
+
if (!fits(name)) long.path = name;
|
|
620
|
+
if (!fits(link)) long.linkpath = link;
|
|
621
|
+
if (Object.keys(long).length) parts.push(paxEntry(long));
|
|
622
|
+
const shortName = fits(name) ? name : "long-name";
|
|
623
|
+
const shortLink = fits(link) ? link : "long-link";
|
|
624
|
+
if (e.type === "file") parts.push(header(shortName, e.mode, e.data.length, e.mtime, "0", ""), pad(e.data));
|
|
625
|
+
else parts.push(header(shortName, e.mode, 0, e.mtime, e.type === "dir" ? "5" : "2", shortLink));
|
|
626
|
+
}
|
|
627
|
+
parts.push(Buffer.alloc(BLOCK * 2));
|
|
628
|
+
return Buffer.concat(parts);
|
|
629
|
+
}
|
|
630
|
+
/**
|
|
631
|
+
* Writes `entries` under `dir`, never through a symbolic link: an entry whose parent on disk is a
|
|
632
|
+
* link or a file is skipped, as is one whose path exists already, so nothing lands outside `dir`
|
|
633
|
+
* even where the filesystem folds case. An entry the platform refuses (a name Windows can't hold,
|
|
634
|
+
* a link without the right to make one) is skipped too. Returns the paths it skipped.
|
|
635
|
+
*/
|
|
636
|
+
async function extractTar(entries, dir) {
|
|
637
|
+
const root = resolve(dir);
|
|
638
|
+
const skipped = [];
|
|
639
|
+
await mkdir(root, { recursive: true });
|
|
640
|
+
const times = [];
|
|
641
|
+
const parentsAreDirs = async (parts) => {
|
|
642
|
+
let at = root;
|
|
643
|
+
for (const part of parts.slice(0, -1)) {
|
|
644
|
+
at = join(at, part);
|
|
645
|
+
const info = await lstat(at).catch(() => null);
|
|
646
|
+
if (!info) await mkdir(at);
|
|
647
|
+
else if (!info.isDirectory()) return false;
|
|
648
|
+
}
|
|
649
|
+
return true;
|
|
650
|
+
};
|
|
651
|
+
for (const e of entries) {
|
|
652
|
+
const parts = e.path.split("/");
|
|
653
|
+
const target = join(root, ...parts);
|
|
654
|
+
try {
|
|
655
|
+
if (!target.startsWith(root + sep) || !await parentsAreDirs(parts)) {
|
|
656
|
+
skipped.push(e.path);
|
|
657
|
+
continue;
|
|
658
|
+
}
|
|
659
|
+
const existing = await lstat(target).catch(() => null);
|
|
660
|
+
if (e.type === "dir") {
|
|
661
|
+
if (!existing) await mkdir(target);
|
|
662
|
+
else if (!existing.isDirectory()) skipped.push(e.path);
|
|
663
|
+
continue;
|
|
664
|
+
}
|
|
665
|
+
if (existing) {
|
|
666
|
+
skipped.push(e.path);
|
|
667
|
+
continue;
|
|
668
|
+
}
|
|
669
|
+
if (e.type === "symlink") await symlink(e.target, target);
|
|
670
|
+
else {
|
|
671
|
+
await writeFile(target, e.data, {
|
|
672
|
+
mode: e.mode & 511 || 420,
|
|
673
|
+
flag: "wx"
|
|
674
|
+
});
|
|
675
|
+
times.push([target, e.mtime]);
|
|
676
|
+
}
|
|
677
|
+
} catch {
|
|
678
|
+
skipped.push(e.path);
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
for (const [path, mtime] of times) await utimes(path, mtime, mtime).catch(() => {});
|
|
682
|
+
return skipped;
|
|
683
|
+
}
|
|
684
|
+
/** The tree under `dir` as entries, in a stable order; a symbolic link is kept as one, never followed. */
|
|
685
|
+
async function readTree(dir, prefix = "") {
|
|
686
|
+
const entries = [];
|
|
687
|
+
for (const name of (await readdir(dir)).sort()) {
|
|
688
|
+
const full = join(dir, name);
|
|
689
|
+
const path = prefix ? `${prefix}/${name}` : name;
|
|
690
|
+
const info = await lstat(full);
|
|
691
|
+
const meta = {
|
|
692
|
+
path,
|
|
693
|
+
mode: info.mode & 4095,
|
|
694
|
+
mtime: Math.floor(info.mtimeMs / 1e3)
|
|
695
|
+
};
|
|
696
|
+
if (info.isSymbolicLink()) entries.push({
|
|
697
|
+
type: "symlink",
|
|
698
|
+
...meta,
|
|
699
|
+
target: await readlink(full)
|
|
700
|
+
});
|
|
701
|
+
else if (info.isDirectory()) entries.push({
|
|
702
|
+
type: "dir",
|
|
703
|
+
...meta
|
|
704
|
+
}, ...await readTree(full, path));
|
|
705
|
+
else if (info.isFile()) entries.push({
|
|
706
|
+
type: "file",
|
|
707
|
+
...meta,
|
|
708
|
+
data: await readFile(full)
|
|
709
|
+
});
|
|
710
|
+
}
|
|
711
|
+
return entries;
|
|
712
|
+
}
|
|
713
|
+
// ../sandbox-docker/src/remote-engine.ts
|
|
714
|
+
/**
|
|
715
|
+
* The remote side of a command with an environment: its first stdin line is the base64 of the
|
|
716
|
+
* `export`s, which `read` takes a byte at a time (stdin is a pipe), so the rest of stdin is the
|
|
717
|
+
* CLI's own.
|
|
718
|
+
*/
|
|
719
|
+
const WITH_ENV = "IFS= read -r reeval_env || exit 125; reeval_env=$(printf %s \"$reeval_env\" | base64 -d) || exit 125; eval \"$reeval_env\" || exit 125; unset reeval_env; exec \"$@\"";
|
|
720
|
+
/**
|
|
721
|
+
* How to run the engine's CLI with `args`: the CLI itself here, or ssh to it on a remote engine.
|
|
722
|
+
* `env` reaches the CLI's environment, never argv: on a remote engine it's the {@link
|
|
723
|
+
* EngineCommand.preamble}.
|
|
724
|
+
*/
|
|
725
|
+
function hostCommand(engine, args, env = {}) {
|
|
726
|
+
if (!isRemoteEngine(engine)) return {
|
|
727
|
+
bin: engineSpec(engine).bin,
|
|
728
|
+
args: [...args],
|
|
729
|
+
env: {
|
|
730
|
+
...engineEnv(engine),
|
|
731
|
+
...env
|
|
732
|
+
},
|
|
733
|
+
preamble: null
|
|
734
|
+
};
|
|
735
|
+
const docker = ["docker", ...args].map(shellQuote).join(" ");
|
|
736
|
+
const names = Object.keys(env);
|
|
737
|
+
for (const name of names) if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(name)) throw new Error(`${name} isn't a variable name`);
|
|
738
|
+
const remote = names.length ? `sh -c ${shellQuote(WITH_ENV)} sh ${docker}` : `exec ${docker}`;
|
|
739
|
+
const [bin = "ssh", ...rest] = sshArgv(engine.target, remote);
|
|
740
|
+
const exports = names.map((name) => `export ${name}=${shellQuote(env[name] ?? "")}`).join("\n");
|
|
741
|
+
return {
|
|
742
|
+
bin,
|
|
743
|
+
args: rest,
|
|
744
|
+
env: {},
|
|
745
|
+
preamble: names.length ? Buffer.from(`${Buffer.from(exports).toString("base64")}\n`) : null
|
|
746
|
+
};
|
|
747
|
+
}
|
|
748
|
+
/**
|
|
749
|
+
* Spawns the engine's CLI with `args` in its own process group, its output piped and no stdin of
|
|
750
|
+
* its own; on a remote engine stdin carries only the environment.
|
|
751
|
+
*/
|
|
752
|
+
function spawnEngine(engine, args, env = {}) {
|
|
753
|
+
const command = hostCommand(engine, args, env);
|
|
754
|
+
const child = spawn(command.bin, command.args, {
|
|
755
|
+
stdio: [
|
|
756
|
+
command.preamble ? "pipe" : "ignore",
|
|
757
|
+
"pipe",
|
|
758
|
+
"pipe"
|
|
759
|
+
],
|
|
760
|
+
detached: true,
|
|
761
|
+
env: {
|
|
762
|
+
...process.env,
|
|
763
|
+
...command.env
|
|
764
|
+
}
|
|
765
|
+
});
|
|
766
|
+
if (command.preamble && child.stdin) {
|
|
767
|
+
child.stdin.on("error", () => {});
|
|
768
|
+
child.stdin.end(command.preamble);
|
|
769
|
+
}
|
|
770
|
+
return child;
|
|
771
|
+
}
|
|
772
|
+
const literal = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
773
|
+
/**
|
|
774
|
+
* ssh failing to connect to `target`, so the remote CLI never ran and running it again is safe:
|
|
775
|
+
* the whole of stderr is ssh's own message naming the machine. A connection that drops later
|
|
776
|
+
* isn't one, since the command may have run, and nor is a remote command that printed the same.
|
|
777
|
+
*/
|
|
778
|
+
const isSshFailure = (r, target) => {
|
|
779
|
+
if (r.exitCode !== 255) return false;
|
|
780
|
+
const at = `${literal(target.host)} port ${target.port}`;
|
|
781
|
+
return new RegExp(`^(?:ssh: connect to host ${at}: [^\\n]+|kex_exchange_identification: [^\\n]+\\n(?:Connection (?:closed|reset) by \\S+ port ${target.port}|banner exchange: Connection to \\S+ port ${target.port}: [^\\n]+)|Connection timed out during banner exchange\\nConnection to \\S+ port ${target.port} timed out)$`).test(r.stderr.trim());
|
|
782
|
+
};
|
|
783
|
+
/** Commands that run a container's process, whose output and exit code are that process's. */
|
|
784
|
+
const RUNS_A_PROCESS = /* @__PURE__ */ new Set([
|
|
785
|
+
"exec",
|
|
786
|
+
"run",
|
|
787
|
+
"start",
|
|
788
|
+
"attach"
|
|
789
|
+
]);
|
|
790
|
+
/** Whether `args` is safe to run again after ssh failed to connect. */
|
|
791
|
+
const retriesSafely = (args) => !RUNS_A_PROCESS.has(args[0] ?? "");
|
|
792
|
+
/** How traces and messages name the engine's CLI. */
|
|
793
|
+
const engineLabel = (engine) => isRemoteEngine(engine) ? `docker on ${engine.description}` : engineSpec(engine).bin;
|
|
794
|
+
/** Option flags of `docker build` that take a value as the next argument. */
|
|
795
|
+
const BUILD_VALUE_FLAGS = /* @__PURE__ */ new Set([
|
|
796
|
+
"--add-host",
|
|
797
|
+
"--allow",
|
|
798
|
+
"--annotation",
|
|
799
|
+
"--attest",
|
|
800
|
+
"--build-arg",
|
|
801
|
+
"--build-context",
|
|
802
|
+
"--builder",
|
|
803
|
+
"--cache-from",
|
|
804
|
+
"--cache-to",
|
|
805
|
+
"--call",
|
|
806
|
+
"--cgroup-parent",
|
|
807
|
+
"--cpu-period",
|
|
808
|
+
"--cpu-quota",
|
|
809
|
+
"--cpu-shares",
|
|
810
|
+
"-c",
|
|
811
|
+
"--cpuset-cpus",
|
|
812
|
+
"--cpuset-mems",
|
|
813
|
+
"--file",
|
|
814
|
+
"-f",
|
|
815
|
+
"--iidfile",
|
|
816
|
+
"--isolation",
|
|
817
|
+
"--label",
|
|
818
|
+
"--memory",
|
|
819
|
+
"-m",
|
|
820
|
+
"--memory-swap",
|
|
821
|
+
"--metadata-file",
|
|
822
|
+
"--network",
|
|
823
|
+
"--no-cache-filter",
|
|
824
|
+
"--output",
|
|
825
|
+
"-o",
|
|
826
|
+
"--platform",
|
|
827
|
+
"--progress",
|
|
828
|
+
"--provenance",
|
|
829
|
+
"--sbom",
|
|
830
|
+
"--secret",
|
|
831
|
+
"--security-opt",
|
|
832
|
+
"--shm-size",
|
|
833
|
+
"--ssh",
|
|
834
|
+
"--tag",
|
|
835
|
+
"-t",
|
|
836
|
+
"--target",
|
|
837
|
+
"--ulimit"
|
|
838
|
+
]);
|
|
839
|
+
/** Whether a `docker build` flag's value names a file, directory or socket on this machine. */
|
|
840
|
+
function namesLocalPath(flag, value) {
|
|
841
|
+
switch (flag) {
|
|
842
|
+
case "--iidfile":
|
|
843
|
+
case "--metadata-file":
|
|
844
|
+
case "--ssh": return true;
|
|
845
|
+
case "--secret": return !/(?:^|,)env=/.test(value);
|
|
846
|
+
case "--build-context": {
|
|
847
|
+
const source = value.slice(value.indexOf("=") + 1);
|
|
848
|
+
return source.startsWith("oci-layout://") || !/^[a-z][a-z0-9+.-]*:\/\//.test(source);
|
|
849
|
+
}
|
|
850
|
+
case "--output":
|
|
851
|
+
case "-o": return !/(?:^|,)type=/.test(value) || /(?:^|,)(?:type=(?:local|tar)|dest=)/.test(value);
|
|
852
|
+
case "--cache-to":
|
|
853
|
+
case "--cache-from": return /(?:^|,)type=local/.test(value);
|
|
854
|
+
default: return false;
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
const STDIN_DOCKERFILE = ".reeval-stdin.Dockerfile";
|
|
858
|
+
function contextEntries(context, files) {
|
|
859
|
+
const entries = [];
|
|
860
|
+
const dirs = /* @__PURE__ */ new Set();
|
|
861
|
+
for (const path of files) for (let at = path.indexOf("/"); at !== -1; at = path.indexOf("/", at + 1)) dirs.add(path.slice(0, at));
|
|
862
|
+
for (const path of [...dirs].sort()) {
|
|
863
|
+
const stat = lstatSync(join(context, path));
|
|
864
|
+
const mtime = Math.floor(stat.mtimeMs / 1e3);
|
|
865
|
+
entries.push({
|
|
866
|
+
type: "dir",
|
|
867
|
+
path,
|
|
868
|
+
mode: stat.mode & 4095,
|
|
869
|
+
mtime
|
|
870
|
+
});
|
|
871
|
+
}
|
|
872
|
+
for (const path of files) {
|
|
873
|
+
const full = join(context, path);
|
|
874
|
+
const stat = lstatSync(full, { throwIfNoEntry: false });
|
|
875
|
+
if (!stat) continue;
|
|
876
|
+
const mtime = Math.floor(stat.mtimeMs / 1e3);
|
|
877
|
+
const mode = stat.mode & 4095;
|
|
878
|
+
if (stat.isSymbolicLink()) entries.push({
|
|
879
|
+
type: "symlink",
|
|
880
|
+
path,
|
|
881
|
+
mode,
|
|
882
|
+
mtime,
|
|
883
|
+
target: readlinkSync(full)
|
|
884
|
+
});
|
|
885
|
+
else if (stat.isFile()) entries.push({
|
|
886
|
+
type: "file",
|
|
887
|
+
path,
|
|
888
|
+
mode,
|
|
889
|
+
mtime,
|
|
890
|
+
data: readFileSync(full)
|
|
891
|
+
});
|
|
892
|
+
}
|
|
893
|
+
return entries;
|
|
894
|
+
}
|
|
895
|
+
/**
|
|
896
|
+
* `docker build` arguments and input for a remote engine: a build context on this machine goes as
|
|
897
|
+
* a tar on stdin (`-`), with its `.dockerignore` rules applied by the builder as they would be
|
|
898
|
+
* here. The Dockerfile keeps its path in the context; one outside it, or one read from stdin,
|
|
899
|
+
* goes in the tar under a name of its own. Directories go as the files' parents, with their modes,
|
|
900
|
+
* so an empty one isn't sent. The context is read into memory whole. A flag that names a path on
|
|
901
|
+
* this machine (`--iidfile`, `--secret`, a local `--output`, …) is refused: the CLI would read or
|
|
902
|
+
* write it on the other one. Any other command, and a build whose context is stdin, a URL or a
|
|
903
|
+
* git repository, is as is.
|
|
904
|
+
*/
|
|
905
|
+
function remoteBuild(args, input) {
|
|
906
|
+
if (args[0] !== "build") return {
|
|
907
|
+
args: [...args],
|
|
908
|
+
input
|
|
909
|
+
};
|
|
910
|
+
let file = null;
|
|
911
|
+
let contextAt = -1;
|
|
912
|
+
for (let i = 1; i < args.length; i++) {
|
|
913
|
+
const arg = args[i];
|
|
914
|
+
const [flag = arg, joined] = arg.startsWith("--") ? arg.split(/=(.*)/s) : /^-(?:f|o)./.test(arg) ? [arg.slice(0, 2), arg.slice(2).replace(/^=/, "")] : [arg];
|
|
915
|
+
if (namesLocalPath(flag, joined ?? args[i + 1] ?? "")) throw new Error(`docker build ${flag} names a path on this machine, which a remote engine can't reach`);
|
|
916
|
+
if (BUILD_VALUE_FLAGS.has(arg)) {
|
|
917
|
+
if (arg === "--file" || arg === "-f") file = {
|
|
918
|
+
at: i + 1,
|
|
919
|
+
value: args[i + 1] ?? ""
|
|
920
|
+
};
|
|
921
|
+
i++;
|
|
922
|
+
} else if (flag === "-f" && joined !== void 0) file = {
|
|
923
|
+
at: i,
|
|
924
|
+
value: joined
|
|
925
|
+
};
|
|
926
|
+
else if (arg.startsWith("--file=")) file = {
|
|
927
|
+
at: i,
|
|
928
|
+
value: arg.slice(7)
|
|
929
|
+
};
|
|
930
|
+
else if (!arg.startsWith("-") || arg === "-") contextAt = i;
|
|
931
|
+
}
|
|
932
|
+
const context = contextAt === -1 ? null : args[contextAt];
|
|
933
|
+
if (context === null || context === "-") return {
|
|
934
|
+
args: [...args],
|
|
935
|
+
input
|
|
936
|
+
};
|
|
937
|
+
if (!statSync(context, { throwIfNoEntry: false })?.isDirectory()) return {
|
|
938
|
+
args: [...args],
|
|
939
|
+
input
|
|
940
|
+
};
|
|
941
|
+
const root = resolve(context);
|
|
942
|
+
const out = [...args];
|
|
943
|
+
out[contextAt] = "-";
|
|
944
|
+
const setFile = (value) => {
|
|
945
|
+
if (!file) out.splice(contextAt, 0, "--file", value);
|
|
946
|
+
else if (out[file.at]?.startsWith("--file=")) out[file.at] = `--file=${value}`;
|
|
947
|
+
else if (/^-f[^-]/.test(out[file.at] ?? "") && file.at !== contextAt) out[file.at] = `-f${value}`;
|
|
948
|
+
else out[file.at] = value;
|
|
949
|
+
};
|
|
950
|
+
const extra = [];
|
|
951
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
952
|
+
let dockerfile = null;
|
|
953
|
+
if (file?.value === "-") {
|
|
954
|
+
const data = Buffer.from(input ?? "");
|
|
955
|
+
extra.push({
|
|
956
|
+
type: "file",
|
|
957
|
+
path: STDIN_DOCKERFILE,
|
|
958
|
+
mode: 420,
|
|
959
|
+
mtime: now,
|
|
960
|
+
data
|
|
961
|
+
});
|
|
962
|
+
setFile(STDIN_DOCKERFILE);
|
|
963
|
+
} else {
|
|
964
|
+
dockerfile = file ? resolve(file.value) : join(root, "Dockerfile");
|
|
965
|
+
const inside = relative(root, dockerfile);
|
|
966
|
+
if (inside && !inside.startsWith("..") && !isAbsolute(inside)) {
|
|
967
|
+
if (file) setFile(inside.split(sep).join("/"));
|
|
968
|
+
} else {
|
|
969
|
+
const name = `.reeval-${createHash("sha256").update(dockerfile).digest("hex").slice(0, 12)}.Dockerfile`;
|
|
970
|
+
extra.push({
|
|
971
|
+
type: "file",
|
|
972
|
+
path: name,
|
|
973
|
+
mode: 420,
|
|
974
|
+
mtime: now,
|
|
975
|
+
data: readFileSync(dockerfile)
|
|
976
|
+
});
|
|
977
|
+
if (lstatSync(`${dockerfile}.dockerignore`, { throwIfNoEntry: false })?.isFile()) {
|
|
978
|
+
const data = readFileSync(`${dockerfile}.dockerignore`);
|
|
979
|
+
extra.push({
|
|
980
|
+
type: "file",
|
|
981
|
+
path: `${name}.dockerignore`,
|
|
982
|
+
mode: 420,
|
|
983
|
+
mtime: now,
|
|
984
|
+
data
|
|
985
|
+
});
|
|
986
|
+
}
|
|
987
|
+
setFile(name);
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
return {
|
|
991
|
+
args: out,
|
|
992
|
+
input: writeTar([...contextEntries(root, contextFiles(root, dockerfile).filter((path) => !/^\.\.(?:[\\/]|$)/.test(path) && !extra.some((e) => e.path === path))), ...extra])
|
|
993
|
+
};
|
|
994
|
+
}
|
|
367
995
|
// ../sandbox-docker/src/trace.ts
|
|
368
996
|
/** Most of each stream a trace keeps; the rest is counted. */
|
|
369
997
|
const MAX_STREAM = 4096;
|
|
@@ -433,71 +1061,254 @@ function traceDocker(args, startedAt, result, bin = "docker") {
|
|
|
433
1061
|
});
|
|
434
1062
|
} catch {}
|
|
435
1063
|
}
|
|
436
|
-
// ../sandbox-docker/src/
|
|
437
|
-
/**
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
1064
|
+
// ../sandbox-docker/src/egress/transport.ts
|
|
1065
|
+
/** Runs `command` in the sandbox to its end. */
|
|
1066
|
+
async function execRun(transport, command, options) {
|
|
1067
|
+
if (transport.run) return transport.run(command, options);
|
|
1068
|
+
const [bin = "", ...args] = transport.argv(command);
|
|
1069
|
+
const startedAt = Date.now();
|
|
1070
|
+
try {
|
|
1071
|
+
const r = await run(bin, args, {
|
|
1072
|
+
...options,
|
|
1073
|
+
env: transport.env,
|
|
1074
|
+
binary: true
|
|
1075
|
+
});
|
|
1076
|
+
transport.trace?.([bin, ...args], startedAt, {
|
|
1077
|
+
...r,
|
|
1078
|
+
stdin: options.input.length
|
|
1079
|
+
});
|
|
1080
|
+
return r;
|
|
1081
|
+
} catch (error) {
|
|
1082
|
+
transport.trace?.([bin, ...args], startedAt, { error });
|
|
1083
|
+
throw error;
|
|
456
1084
|
}
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
1085
|
+
}
|
|
1086
|
+
/** Starts `command` in the sandbox and leaves it running, its stdio piped. */
|
|
1087
|
+
function execSpawn(transport, command) {
|
|
1088
|
+
const argv = transport.argv(command);
|
|
1089
|
+
const [bin = "", ...args] = argv;
|
|
1090
|
+
const startedAt = Date.now();
|
|
1091
|
+
const child = spawn(bin, args, {
|
|
1092
|
+
stdio: "pipe",
|
|
1093
|
+
detached: true,
|
|
1094
|
+
env: {
|
|
1095
|
+
...process.env,
|
|
1096
|
+
...transport.env
|
|
1097
|
+
}
|
|
1098
|
+
});
|
|
1099
|
+
let stderr = "";
|
|
1100
|
+
child.stderr.on("data", (d) => {
|
|
1101
|
+
stderr += d;
|
|
1102
|
+
});
|
|
1103
|
+
child.once("close", (code) => transport.trace?.(argv, startedAt, {
|
|
1104
|
+
exitCode: code,
|
|
1105
|
+
stderr
|
|
1106
|
+
}));
|
|
1107
|
+
return child;
|
|
1108
|
+
}
|
|
1109
|
+
/** What every `ssh` reeval runs passes: no prompt, a dropped connection noticed within a minute. */
|
|
1110
|
+
const SSH_OPTIONS = [
|
|
1111
|
+
"-o",
|
|
1112
|
+
"BatchMode=yes",
|
|
1113
|
+
"-o",
|
|
1114
|
+
"ServerAliveInterval=15",
|
|
1115
|
+
"-o",
|
|
1116
|
+
"ServerAliveCountMax=4",
|
|
1117
|
+
"-o",
|
|
1118
|
+
"LogLevel=ERROR"
|
|
1119
|
+
];
|
|
1120
|
+
/**
|
|
1121
|
+
* Whether `dir` is a directory only this user can enter, made (0700) first with `make`. An ssh
|
|
1122
|
+
* client trusts whatever listens at its ControlPath, so a socket in a directory another user can
|
|
1123
|
+
* write lets them stand in for the host.
|
|
1124
|
+
*/
|
|
1125
|
+
function privateDir(dir, o = {}) {
|
|
1126
|
+
try {
|
|
1127
|
+
if (o.make) mkdirSync(dir, {
|
|
1128
|
+
recursive: true,
|
|
1129
|
+
mode: 448
|
|
1130
|
+
});
|
|
1131
|
+
const st = lstatSync(dir);
|
|
1132
|
+
return st.isDirectory() && st.uid === process.getuid?.() && (st.mode & 63) === 0;
|
|
1133
|
+
} catch {
|
|
1134
|
+
return false;
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
/**
|
|
1138
|
+
* Whether ssh can listen on a control socket at `path` on `platform`. A socket's path has
|
|
1139
|
+
* `sizeof(sun_path)` bytes with its NUL (104 on macOS and the BSDs, 108 on Linux), and the master
|
|
1140
|
+
* first listens on `path` plus a 17-byte random suffix. `%C` expands to a 40-character hash.
|
|
1141
|
+
*/
|
|
1142
|
+
function controlPathFits(path, platform = process.platform) {
|
|
1143
|
+
const room = platform === "linux" ? 108 : 104;
|
|
1144
|
+
return Buffer.byteLength(path.replaceAll("%C", "C".repeat(40))) + 17 < room;
|
|
1145
|
+
}
|
|
1146
|
+
/**
|
|
1147
|
+
* The options that share one connection through a control socket at `path`, kept open `persistS`
|
|
1148
|
+
* seconds after the last command; none on Windows, whose OpenSSH has no ControlMaster, when the
|
|
1149
|
+
* path is too long for a socket ({@link controlPathFits}), or when the socket's directory isn't
|
|
1150
|
+
* {@link privateDir}. `path` may end in an ssh token such as `%C`.
|
|
1151
|
+
*/
|
|
1152
|
+
function controlOptions(path, persistS) {
|
|
1153
|
+
if (!path || process.platform === "win32" || !controlPathFits(path)) return [];
|
|
1154
|
+
if (!privateDir(dirname(path))) return [];
|
|
1155
|
+
return [
|
|
1156
|
+
"-o",
|
|
1157
|
+
"ControlMaster=auto",
|
|
1158
|
+
"-o",
|
|
1159
|
+
`ControlPath=${path}`,
|
|
1160
|
+
"-o",
|
|
1161
|
+
`ControlPersist=${persistS}`
|
|
1162
|
+
];
|
|
1163
|
+
}
|
|
1164
|
+
/**
|
|
1165
|
+
* The host argv that runs `remote`, one shell command line, on `target`. ssh joins its remote
|
|
1166
|
+
* arguments into one line for the login shell, so the caller quotes it. No user config applies.
|
|
1167
|
+
*/
|
|
1168
|
+
function sshArgv(target, remote) {
|
|
1169
|
+
return [
|
|
1170
|
+
"ssh",
|
|
1171
|
+
"-T",
|
|
1172
|
+
"-F",
|
|
1173
|
+
"none",
|
|
1174
|
+
"-i",
|
|
1175
|
+
target.identityFile,
|
|
1176
|
+
"-p",
|
|
1177
|
+
String(target.port),
|
|
1178
|
+
...SSH_OPTIONS,
|
|
1179
|
+
"-o",
|
|
1180
|
+
"IdentitiesOnly=yes",
|
|
1181
|
+
"-o",
|
|
1182
|
+
"StrictHostKeyChecking=yes",
|
|
1183
|
+
"-o",
|
|
1184
|
+
`UserKnownHostsFile=${target.knownHostsFile}`,
|
|
1185
|
+
"-o",
|
|
1186
|
+
"GlobalKnownHostsFile=none",
|
|
1187
|
+
"-o",
|
|
1188
|
+
`HostKeyAlias=${target.hostKeyAlias}`,
|
|
1189
|
+
"-o",
|
|
1190
|
+
"ConnectTimeout=20",
|
|
1191
|
+
...controlOptions(target.controlPath, 300),
|
|
1192
|
+
`${target.user}@${target.host}`,
|
|
1193
|
+
remote
|
|
1194
|
+
];
|
|
1195
|
+
}
|
|
1196
|
+
/** How a command line on `target` runs as root: through `sudo -n`, unless it logs in as root. */
|
|
1197
|
+
const asRootPrefix = (target) => target.loginRoot ? "" : "sudo -n -- ";
|
|
1198
|
+
/** `ssh -T` into a VM, as root through `sudo -n` (with sudo's own `secure_path`) or as its login. */
|
|
1199
|
+
function sshTransport(target) {
|
|
1200
|
+
return {
|
|
1201
|
+
argv: (command) => sshArgv(target, `${asRootPrefix(target)}${command.map(shellQuote).join(" ")}`),
|
|
1202
|
+
trace: (argv, startedAt, end) => traceDocker(argv.slice(1), startedAt, end, "ssh")
|
|
1203
|
+
};
|
|
1204
|
+
}
|
|
1205
|
+
/** `docker exec` (or `podman exec`) into a running container, as root. */
|
|
1206
|
+
function containerTransport(containerId, engine) {
|
|
1207
|
+
const sent = /* @__PURE__ */ new WeakMap();
|
|
1208
|
+
const exec = (command) => [
|
|
1209
|
+
"exec",
|
|
1210
|
+
"--interactive",
|
|
1211
|
+
"--user",
|
|
1212
|
+
"0:0",
|
|
1213
|
+
containerId,
|
|
1214
|
+
...command
|
|
1215
|
+
];
|
|
1216
|
+
return {
|
|
1217
|
+
argv: (command) => {
|
|
1218
|
+
const host = hostCommand(engine, exec(command));
|
|
1219
|
+
const argv = [host.bin, ...host.args];
|
|
1220
|
+
sent.set(argv, exec(command));
|
|
1221
|
+
return argv;
|
|
1222
|
+
},
|
|
1223
|
+
env: hostCommand(engine, []).env,
|
|
1224
|
+
run: (command, { input, signal }) => docker(exec(command), {
|
|
1225
|
+
input,
|
|
1226
|
+
signal,
|
|
1227
|
+
engine
|
|
1228
|
+
}),
|
|
1229
|
+
trace: (argv, startedAt, end) => traceDocker(sent.get(argv) ?? argv.slice(1), startedAt, end, engineLabel(engine))
|
|
1230
|
+
};
|
|
1231
|
+
}
|
|
1232
|
+
// ../sandbox-docker/src/docker-cli.ts
|
|
1233
|
+
/** How long to wait before each retry of a command that never reached Podman. */
|
|
1234
|
+
const CONNECTION_RETRY_MS = [
|
|
1235
|
+
100,
|
|
1236
|
+
250,
|
|
1237
|
+
500,
|
|
1238
|
+
1e3,
|
|
1239
|
+
2e3
|
|
1240
|
+
];
|
|
1241
|
+
/**
|
|
1242
|
+
* Whether a podman command failed before reaching the engine: the remote client's SSH handshake
|
|
1243
|
+
* or socket connection to `podman machine`, so running it again is safe.
|
|
1244
|
+
*/
|
|
1245
|
+
const isConnectionFailure = (r) => r.exitCode === 125 && /ssh: handshake failed|unable to connect to Podman socket/.test(r.stderr);
|
|
1246
|
+
const sleep = (ms, signal) => new Promise((resolve) => {
|
|
1247
|
+
const timer = setTimeout(done, ms);
|
|
1248
|
+
function done() {
|
|
1249
|
+
clearTimeout(timer);
|
|
1250
|
+
signal?.removeEventListener("abort", done);
|
|
1251
|
+
resolve();
|
|
1252
|
+
}
|
|
1253
|
+
signal?.addEventListener("abort", done, { once: true });
|
|
1254
|
+
});
|
|
1255
|
+
/**
|
|
1256
|
+
* Runs `attempt` again, after each of `delays`, while its result is a connection failure (see
|
|
1257
|
+
* {@link isConnectionFailure}), and returns the last result.
|
|
1258
|
+
*/
|
|
463
1259
|
async function retryConnection(attempt, options = {}) {
|
|
464
|
-
const { delays = CONNECTION_RETRY_MS, signal, wait = sleep } = options;
|
|
1260
|
+
const { delays = CONNECTION_RETRY_MS, signal, wait = sleep, failed = isConnectionFailure } = options;
|
|
465
1261
|
let r = await attempt();
|
|
466
1262
|
for (const ms of delays) {
|
|
467
|
-
if (!
|
|
1263
|
+
if (!failed(r) || signal?.aborted) break;
|
|
468
1264
|
await wait(ms, signal);
|
|
469
1265
|
r = await attempt();
|
|
470
1266
|
}
|
|
471
1267
|
return r;
|
|
472
1268
|
}
|
|
473
|
-
/**
|
|
1269
|
+
/**
|
|
1270
|
+
* Runs the docker (or podman) CLI, here or on a remote engine's machine. `env` values are passed
|
|
1271
|
+
* via the CLI's environment, never argv.
|
|
1272
|
+
*/
|
|
474
1273
|
async function docker(args, options = {}) {
|
|
475
|
-
const { engine,
|
|
476
|
-
const
|
|
477
|
-
const
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
...rest.env
|
|
1274
|
+
const { engine, signal } = options;
|
|
1275
|
+
const remote = isRemoteEngine(engine);
|
|
1276
|
+
const call = remote ? remoteBuild(args, options.input) : {
|
|
1277
|
+
args,
|
|
1278
|
+
input: options.input
|
|
481
1279
|
};
|
|
1280
|
+
const command = hostCommand(engine, call.args, options.env);
|
|
1281
|
+
const input = command.preamble ? Buffer.concat([command.preamble, Buffer.from(call.input ?? "")]) : call.input;
|
|
1282
|
+
const bin = engineLabel(engine);
|
|
1283
|
+
const stdin = call.input?.length ?? 0;
|
|
482
1284
|
const once = async () => {
|
|
483
1285
|
const startedAt = Date.now();
|
|
484
1286
|
try {
|
|
485
|
-
const r = await run(bin, args, {
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
1287
|
+
const r = await run(command.bin, command.args, {
|
|
1288
|
+
env: command.env,
|
|
1289
|
+
binary: true,
|
|
1290
|
+
...input !== void 0 ? { input } : {},
|
|
1291
|
+
...signal ? { signal } : {}
|
|
489
1292
|
});
|
|
490
|
-
traceDocker(args, startedAt, {
|
|
1293
|
+
traceDocker(call.args, startedAt, {
|
|
491
1294
|
...r,
|
|
492
1295
|
stdin
|
|
493
1296
|
}, bin);
|
|
494
1297
|
return r;
|
|
495
1298
|
} catch (error) {
|
|
496
|
-
traceDocker(args, startedAt, { error }, bin);
|
|
1299
|
+
traceDocker(call.args, startedAt, { error }, bin);
|
|
497
1300
|
throw error;
|
|
498
1301
|
}
|
|
499
1302
|
};
|
|
500
|
-
|
|
1303
|
+
if (remote) {
|
|
1304
|
+
if (!retriesSafely(call.args)) return once();
|
|
1305
|
+
const { target } = engine;
|
|
1306
|
+
return retryConnection(once, {
|
|
1307
|
+
signal,
|
|
1308
|
+
failed: (r) => isSshFailure(r, target)
|
|
1309
|
+
});
|
|
1310
|
+
}
|
|
1311
|
+
return engine === "podman" ? retryConnection(once, { signal }) : once();
|
|
501
1312
|
}
|
|
502
1313
|
async function dockerOk(args, opts) {
|
|
503
1314
|
const r = await docker(args, opts);
|
|
@@ -519,12 +1330,14 @@ const REMOVAL_RETRY_MS = [
|
|
|
519
1330
|
* and tries again while it fails. Resolves either way.
|
|
520
1331
|
*/
|
|
521
1332
|
async function removeContainerDetached(id, engine, options = {}) {
|
|
522
|
-
const {
|
|
1333
|
+
const { rmForce } = engineSpec(engine);
|
|
523
1334
|
const { delays = REMOVAL_RETRY_MS, wait = sleep } = options;
|
|
524
1335
|
const args = [...rmForce, id];
|
|
1336
|
+
const command = hostCommand(engine, args);
|
|
1337
|
+
const bin = command.bin;
|
|
525
1338
|
const env = {
|
|
526
1339
|
...process.env,
|
|
527
|
-
...
|
|
1340
|
+
...command.env
|
|
528
1341
|
};
|
|
529
1342
|
const once = () => new Promise((resolve) => {
|
|
530
1343
|
const keepAlive = setInterval(() => {}, 1e3);
|
|
@@ -538,13 +1351,13 @@ async function removeContainerDetached(id, engine, options = {}) {
|
|
|
538
1351
|
traceDocker(args, startedAt, {
|
|
539
1352
|
exitCode,
|
|
540
1353
|
stderr
|
|
541
|
-
},
|
|
1354
|
+
}, engineLabel(engine));
|
|
542
1355
|
resolve({
|
|
543
1356
|
exitCode,
|
|
544
1357
|
stderr
|
|
545
1358
|
});
|
|
546
1359
|
};
|
|
547
|
-
const child = spawn(bin, args, {
|
|
1360
|
+
const child = spawn(bin, command.args, {
|
|
548
1361
|
detached: true,
|
|
549
1362
|
stdio: [
|
|
550
1363
|
"ignore",
|
|
@@ -577,6 +1390,19 @@ async function removeContainerDetached(id, engine, options = {}) {
|
|
|
577
1390
|
*/
|
|
578
1391
|
function sweepLabelDetached(label, seconds = 15, engine) {
|
|
579
1392
|
const { bin, rmForce } = engineSpec(engine);
|
|
1393
|
+
if (isRemoteEngine(engine)) {
|
|
1394
|
+
const filter = shellQuote(`label=${label}`);
|
|
1395
|
+
const loop = `for i in $(seq ${Math.max(1, Math.floor(seconds))}); do ids=$(docker ps -aq --filter ${filter}); [ -z "$ids" ] || docker ${rmForce.join(" ")} $ids >/dev/null 2>&1; sleep 1; done`;
|
|
1396
|
+
const [ssh = "ssh", ...rest] = sshArgv(engine.target, `sh -c ${shellQuote(loop)}`);
|
|
1397
|
+
const child = spawn(ssh, rest, {
|
|
1398
|
+
detached: true,
|
|
1399
|
+
stdio: "ignore",
|
|
1400
|
+
windowsHide: true
|
|
1401
|
+
});
|
|
1402
|
+
child.on("error", () => {});
|
|
1403
|
+
child.unref();
|
|
1404
|
+
return;
|
|
1405
|
+
}
|
|
580
1406
|
const child = spawn(process.execPath, [
|
|
581
1407
|
"-e",
|
|
582
1408
|
`const { execFileSync } = require('node:child_process')
|
|
@@ -680,7 +1506,7 @@ async function imageInfo(image, engine) {
|
|
|
680
1506
|
"image",
|
|
681
1507
|
"inspect",
|
|
682
1508
|
"--format",
|
|
683
|
-
`{"config":{{json .Config}},"id":{{json ${imageId}}},"repoDigests":{{json .RepoDigests}}}`,
|
|
1509
|
+
`{"config":{{json .Config}},"id":{{json ${imageId}}},"repoDigests":{{json .RepoDigests}},"os":{{json .Os}},"arch":{{json .Architecture}}}`,
|
|
684
1510
|
image
|
|
685
1511
|
], { engine }).catch((error) => {
|
|
686
1512
|
throw new Error(`${bin} image inspect ${image} couldn't run: ${error.message}`);
|
|
@@ -692,147 +1518,128 @@ async function imageInfo(image, engine) {
|
|
|
692
1518
|
}
|
|
693
1519
|
const info = JSON.parse(r.stdout.toString("utf8"));
|
|
694
1520
|
const repoDigests = (info.repoDigests ?? []).filter(isRegistryDigest);
|
|
1521
|
+
const platform = info.os && info.arch ? `${info.os}/${info.arch}` : null;
|
|
695
1522
|
return {
|
|
696
1523
|
labels: info.config?.Labels ?? {},
|
|
697
1524
|
id: normalizeImageId(info.id),
|
|
698
|
-
repoDigests
|
|
699
|
-
|
|
700
|
-
}
|
|
701
|
-
// ../sandbox-docker/src/dockerignore.ts
|
|
702
|
-
const ignore = dockerignore.default;
|
|
703
|
-
/**
|
|
704
|
-
* A pattern `@balena/dockerignore` may match differently from BuildKit: escapes, character
|
|
705
|
-
* classes and the regexp characters it doesn't escape, a `**` joined to other characters, and the
|
|
706
|
-
* whitespace Go and JavaScript trim differently. One over 1024 characters is risky too, since
|
|
707
|
-
* JavaScript refuses a regexp that long that Go accepts, and so is one with more than four `*`
|
|
708
|
-
* runs, whose JavaScript regexp can backtrack for minutes where Go's runs in linear time.
|
|
709
|
-
*/
|
|
710
|
-
const RISKY = /[\\[\]^+(){}|\u0085\uFEFF]|[^/]\*\*|\*\*[^/]/;
|
|
711
|
-
const MAX_STARS = 4;
|
|
712
|
-
/**
|
|
713
|
-
* Names `@balena/dockerignore` may match differently: `?` matches one UTF-16 unit there and one
|
|
714
|
-
* code point in BuildKit, and `.` doesn't match a line terminator there but does in Go.
|
|
715
|
-
*/
|
|
716
|
-
const ODD_NAME = /[\n\r\u2028\u2029\u{10000}-\u{10FFFF}]/u;
|
|
717
|
-
const clean = (pattern) => posix.normalize(pattern).replace(/^\/+/, "").replace(/\/+$/, "");
|
|
718
|
-
/**
|
|
719
|
-
* `.dockerignore` lines as Docker reads them: a BOM is dropped, a line starting `#` is a comment,
|
|
720
|
-
* and `!` re-includes. A path is left out when a rule excludes it and no `!` rule matches it or a
|
|
721
|
-
* directory it's in: BuildKit then excludes it whatever order the rules are in, so this never
|
|
722
|
-
* leaves out a file `docker build` sends, though it keeps some it doesn't. A risky exclusion is
|
|
723
|
-
* dropped, and a risky `!` rule keeps everything, as does one `@balena/dockerignore` would read
|
|
724
|
-
* as a comment or a pattern that cleans to a leading `!` (`!!a`, `/ !a`), which the two read
|
|
725
|
-
* differently.
|
|
726
|
-
*/
|
|
727
|
-
function parseRules(text) {
|
|
728
|
-
const excludes = [];
|
|
729
|
-
const reincludes = [];
|
|
730
|
-
for (const line of text.replace(/^\uFEFF/, "").split(/\r?\n/)) {
|
|
731
|
-
if (line.startsWith("#")) continue;
|
|
732
|
-
let pattern = line.trim();
|
|
733
|
-
const negate = pattern.startsWith("!");
|
|
734
|
-
if (negate) pattern = pattern.slice(1).trim();
|
|
735
|
-
if (!pattern) continue;
|
|
736
|
-
const cleaned = clean(pattern);
|
|
737
|
-
const risky = RISKY.test(pattern) || pattern.length > 1024 || (pattern.match(/\*+/g)?.length ?? 0) > MAX_STARS || [".", ""].includes(cleaned);
|
|
738
|
-
if (cleaned.trim().startsWith("!") || negate && pattern.startsWith("#") || negate && risky) return {
|
|
739
|
-
left: () => false,
|
|
740
|
-
literal: null
|
|
741
|
-
};
|
|
742
|
-
if (!negate) {
|
|
743
|
-
if (!risky) excludes.push(line);
|
|
744
|
-
} else reincludes.push(pattern);
|
|
745
|
-
}
|
|
746
|
-
const exclude = ignore({ ignorecase: false }).add(excludes);
|
|
747
|
-
const reinclude = ignore({ ignorecase: false }).add(reincludes);
|
|
748
|
-
return {
|
|
749
|
-
left: (path) => !ODD_NAME.test(path) && exclude.ignores(path) && !reinclude.ignores(path),
|
|
750
|
-
literal: reincludes.some((p) => /[*?]/.test(p)) ? null : reincludes.map(clean)
|
|
1525
|
+
repoDigests,
|
|
1526
|
+
platform
|
|
751
1527
|
};
|
|
752
1528
|
}
|
|
753
|
-
|
|
754
|
-
function dockerignoreMatcher(text) {
|
|
755
|
-
return parseRules(text).left;
|
|
756
|
-
}
|
|
1529
|
+
// ../sandbox-docker/src/image.ts
|
|
757
1530
|
/**
|
|
758
|
-
*
|
|
759
|
-
*
|
|
760
|
-
*
|
|
761
|
-
*
|
|
762
|
-
* doesn't apply an ignore file that's a symlink or not a file, so then every file is hashed; nor
|
|
763
|
-
* can it send what's in a directory it can't read.
|
|
764
|
-
*/
|
|
765
|
-
function contextFiles(context, dockerfile) {
|
|
766
|
-
const own = [...dockerfile ? [`${dockerfile}.dockerignore`] : [], join(context, ".dockerignore")].map((path) => ({
|
|
767
|
-
path,
|
|
768
|
-
stat: lstatSync(path, { throwIfNoEntry: false })
|
|
769
|
-
})).find(({ stat }) => stat);
|
|
770
|
-
const { left, literal } = parseRules(own?.stat?.isFile() ? readFileSync(own.path, "utf8") : "");
|
|
771
|
-
const always = [...dockerfile ? [relative(context, dockerfile)] : [], ".dockerignore"].map((path) => path.split("\\").join("/"));
|
|
772
|
-
const reach = [...always, ...literal ?? []];
|
|
773
|
-
const files = [];
|
|
774
|
-
const walk = (rel) => {
|
|
775
|
-
let entries;
|
|
776
|
-
try {
|
|
777
|
-
entries = readdirSync(join(context, rel), { withFileTypes: true });
|
|
778
|
-
} catch (error) {
|
|
779
|
-
if (rel && ["EACCES", "EPERM"].includes(error.code ?? "")) return;
|
|
780
|
-
throw error;
|
|
781
|
-
}
|
|
782
|
-
for (const entry of entries) {
|
|
783
|
-
const path = rel ? `${rel}/${entry.name}` : entry.name;
|
|
784
|
-
if (entry.isDirectory()) {
|
|
785
|
-
if (!(left(path) && literal && !reach.some((p) => p.startsWith(`${path}/`)))) walk(path);
|
|
786
|
-
} else if (!left(path) || always.includes(path)) files.push(path);
|
|
787
|
-
}
|
|
788
|
-
};
|
|
789
|
-
walk("");
|
|
790
|
-
return files.sort();
|
|
791
|
-
}
|
|
792
|
-
// ../sandbox-docker/src/image.ts
|
|
793
|
-
/**
|
|
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.
|
|
1531
|
+
* The harness adapters an image can bake, and each one's bootstrap. Each pin must match the exact
|
|
1532
|
+
* dependency (or `workspace:<version>` for this repo's own adapters); a test enforces it. `patch`
|
|
1533
|
+
* is the first 8 hex of the sha256 of the adapter's pnpm patch (`patchedDependencies` in
|
|
1534
|
+
* pnpm-workspace.yaml), whose bridge the image bakes; a test holds it to the patch file.
|
|
798
1535
|
*/
|
|
799
1536
|
const HARNESS_PACKAGES = {
|
|
800
1537
|
cursor: {
|
|
801
1538
|
name: "@reeval/harness-cursor-sdk",
|
|
802
|
-
version: "0.1.9"
|
|
1539
|
+
version: "0.1.9",
|
|
1540
|
+
bootstrap: {
|
|
1541
|
+
name: "Cursor",
|
|
1542
|
+
cli: "@cursor/sdk",
|
|
1543
|
+
probe: `node -p "'@cursor/sdk ' + require(process.env.HOME + '/.ai-sdk-harness/.harness-bootstrap/cursor-sdk/node_modules/@cursor/sdk/package.json').version"`,
|
|
1544
|
+
adapter: async () => (await import("./src-C6MsGyD6.js")).createCursorSdk()
|
|
1545
|
+
}
|
|
803
1546
|
},
|
|
804
1547
|
"claude-code": {
|
|
805
1548
|
name: "@ai-sdk/harness-claude-code",
|
|
806
1549
|
version: "1.0.176",
|
|
807
|
-
patch: "a9d56a8c"
|
|
1550
|
+
patch: "a9d56a8c",
|
|
1551
|
+
bootstrap: {
|
|
1552
|
+
name: "Claude Code",
|
|
1553
|
+
cli: "claude",
|
|
1554
|
+
adapter: async () => (await import("./dist-DeqeCUZe.js")).createClaudeCode()
|
|
1555
|
+
}
|
|
808
1556
|
},
|
|
809
1557
|
antigravity: {
|
|
810
1558
|
name: "@reeval/harness-antigravity",
|
|
811
|
-
version: "0.1.
|
|
1559
|
+
version: "0.1.16",
|
|
1560
|
+
bootstrap: {
|
|
1561
|
+
name: "Antigravity",
|
|
1562
|
+
cli: "agy",
|
|
1563
|
+
adapter: async () => (await import("./src-5dCrqbFd.js")).createAntigravity()
|
|
1564
|
+
}
|
|
812
1565
|
},
|
|
813
1566
|
opencode: {
|
|
814
1567
|
name: "@reeval/harness-opencode",
|
|
815
|
-
version: "0.2.16"
|
|
1568
|
+
version: "0.2.16",
|
|
1569
|
+
bootstrap: {
|
|
1570
|
+
name: "OpenCode",
|
|
1571
|
+
cli: "opencode",
|
|
1572
|
+
adapter: async () => (await import("./src-VG2IRoT4.js")).createOpenCode({
|
|
1573
|
+
auth: { GOOGLE_GENERATIVE_AI_API_KEY: "unused" },
|
|
1574
|
+
model: "google/unused"
|
|
1575
|
+
})
|
|
1576
|
+
}
|
|
816
1577
|
},
|
|
817
1578
|
goose: {
|
|
818
1579
|
name: "@reeval/harness-goose",
|
|
819
|
-
version: "0.1.
|
|
1580
|
+
version: "0.1.16",
|
|
1581
|
+
bootstrap: {
|
|
1582
|
+
name: "Goose",
|
|
1583
|
+
cli: "goose",
|
|
1584
|
+
adapter: async () => {
|
|
1585
|
+
const goose = await import("./src-io_SKoZ5.js");
|
|
1586
|
+
return goose.createGoose({
|
|
1587
|
+
auth: { GOOGLE_API_KEY: "unused" },
|
|
1588
|
+
provider: goose.GEMINI_PROVIDER,
|
|
1589
|
+
model: "unused"
|
|
1590
|
+
});
|
|
1591
|
+
}
|
|
1592
|
+
}
|
|
820
1593
|
},
|
|
821
1594
|
pi: {
|
|
822
1595
|
name: "@reeval/harness-pi",
|
|
823
|
-
version: "0.2.9"
|
|
1596
|
+
version: "0.2.9",
|
|
1597
|
+
bootstrap: {
|
|
1598
|
+
name: "pi",
|
|
1599
|
+
cli: "pi",
|
|
1600
|
+
adapter: async () => {
|
|
1601
|
+
const pi = await import("./src-DwcCKsV0.js");
|
|
1602
|
+
const provider = pi.piProvider("google");
|
|
1603
|
+
if ("refused" in provider) throw new Error(provider.refused);
|
|
1604
|
+
return pi.createPi({
|
|
1605
|
+
auth: { GEMINI_API_KEY: "unused" },
|
|
1606
|
+
provider
|
|
1607
|
+
});
|
|
1608
|
+
}
|
|
1609
|
+
}
|
|
824
1610
|
},
|
|
825
1611
|
codex: {
|
|
826
1612
|
name: "@reeval/harness-codex",
|
|
827
|
-
version: "0.1.
|
|
1613
|
+
version: "0.1.13",
|
|
1614
|
+
bootstrap: {
|
|
1615
|
+
name: "Codex",
|
|
1616
|
+
cli: "codex",
|
|
1617
|
+
adapter: async () => (await import("./src-Ds1pmXTg.js")).createCodex({ auth: { OPENAI_API_KEY: "unused" } })
|
|
1618
|
+
}
|
|
828
1619
|
},
|
|
829
1620
|
fx: {
|
|
830
1621
|
name: "@reeval/harness-fx",
|
|
831
|
-
version: "0.1.
|
|
1622
|
+
version: "0.1.11",
|
|
1623
|
+
bootstrap: {
|
|
1624
|
+
name: "fx",
|
|
1625
|
+
cli: "fx",
|
|
1626
|
+
adapter: async () => (await import("./src-DrLbG1HM.js")).createFx({
|
|
1627
|
+
auth: { AI_GATEWAY_API_KEY: "unused" },
|
|
1628
|
+
model: "unused/unused"
|
|
1629
|
+
})
|
|
1630
|
+
}
|
|
832
1631
|
},
|
|
833
1632
|
"grok-build": {
|
|
834
1633
|
name: "@reeval/harness-grok-build",
|
|
835
|
-
version: "0.1.
|
|
1634
|
+
version: "0.1.12",
|
|
1635
|
+
bootstrap: {
|
|
1636
|
+
name: "Grok Build",
|
|
1637
|
+
cli: "grok",
|
|
1638
|
+
adapter: async () => (await import("./src-Cf4vRyea.js")).createGrokBuild({
|
|
1639
|
+
auth: { XAI_API_KEY: "unused" },
|
|
1640
|
+
model: "unused"
|
|
1641
|
+
})
|
|
1642
|
+
}
|
|
836
1643
|
}
|
|
837
1644
|
};
|
|
838
1645
|
/** Every harness with an image, in {@link HARNESS_PACKAGES} order. */
|
|
@@ -850,7 +1657,7 @@ const imageFor = (harness) => `reeval-sandbox:${harness}-${adapterVersion(harnes
|
|
|
850
1657
|
const DEFAULT_IMAGE = imageFor("cursor");
|
|
851
1658
|
/** The `ai.reeval.harness` label value an image baked for `harness` carries. */
|
|
852
1659
|
const harnessLabel = (harness) => `${HARNESS_PACKAGES[harness].name}@${adapterVersion(harness)}`;
|
|
853
|
-
const LABEL = {
|
|
1660
|
+
const LABEL$1 = {
|
|
854
1661
|
managed: "ai.reeval.managed",
|
|
855
1662
|
run: "ai.reeval.run",
|
|
856
1663
|
/** Unique per session, so a create cut short can find what it made. */
|
|
@@ -860,7 +1667,9 @@ const LABEL = {
|
|
|
860
1667
|
/** On reeval's own images: the hash of the base image's build context, to tell a stale one. */
|
|
861
1668
|
context: "ai.reeval.context",
|
|
862
1669
|
/** 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"
|
|
1670
|
+
fromDigest: "ai.reeval.from-digest",
|
|
1671
|
+
/** On every image reeval builds: its content key, which a registry pull must match. */
|
|
1672
|
+
key: "ai.reeval.key"
|
|
864
1673
|
};
|
|
865
1674
|
/**
|
|
866
1675
|
* The user the agent, setup steps and checks run as, which every image reeval builds creates. Image
|
|
@@ -879,6 +1688,26 @@ const WORKSPACE_DIR = "workspace";
|
|
|
879
1688
|
*/
|
|
880
1689
|
const SANDBOX_STATE = "/var/lib/reeval";
|
|
881
1690
|
const BRIDGE_PORT = 43210;
|
|
1691
|
+
/** The egress forwarder's port for slot 0; slot `n` listens on this plus `n`. */
|
|
1692
|
+
const BASE_PROXY_PORT = 43128;
|
|
1693
|
+
/** Slot `slot`'s layout: slot 0's is {@link SANDBOX_USER}'s, `n` is `reeval-s<n>` in each place. */
|
|
1694
|
+
function slotLayout(slot) {
|
|
1695
|
+
if (slot === 0) return {
|
|
1696
|
+
user: SANDBOX_USER,
|
|
1697
|
+
home: SANDBOX_HOME,
|
|
1698
|
+
root: SANDBOX_ROOT,
|
|
1699
|
+
state: SANDBOX_STATE,
|
|
1700
|
+
proxyPort: BASE_PROXY_PORT
|
|
1701
|
+
};
|
|
1702
|
+
const user = `${SANDBOX_USER}-s${slot}`;
|
|
1703
|
+
return {
|
|
1704
|
+
user,
|
|
1705
|
+
home: `/home/${user}`,
|
|
1706
|
+
root: `${SANDBOX_ROOT}-s${slot}`,
|
|
1707
|
+
state: `${SANDBOX_STATE}-s${slot}`,
|
|
1708
|
+
proxyPort: BASE_PROXY_PORT + slot
|
|
1709
|
+
};
|
|
1710
|
+
}
|
|
882
1711
|
// ../sandbox-docker/src/egress/cert.ts
|
|
883
1712
|
const der = (tag, ...content) => {
|
|
884
1713
|
const body = Buffer.concat(content);
|
|
@@ -1203,7 +2032,7 @@ function createMux(options) {
|
|
|
1203
2032
|
* Pipes two duplexes into each other. An error, or one side closing before its end, tears both
|
|
1204
2033
|
* down; a clean end half-closes the other side through `pipe`.
|
|
1205
2034
|
*/
|
|
1206
|
-
function link(a, b) {
|
|
2035
|
+
function link$1(a, b) {
|
|
1207
2036
|
a.pipe(b);
|
|
1208
2037
|
b.pipe(a);
|
|
1209
2038
|
const kill = () => {
|
|
@@ -1262,7 +2091,7 @@ function forwarderMain(io, makeMux, linkStreams, proxyPort) {
|
|
|
1262
2091
|
server.listen(proxyPort, "127.0.0.1", () => mux.ready());
|
|
1263
2092
|
}
|
|
1264
2093
|
/** The `node -e` script that runs {@link forwarderMain} in the container. */
|
|
1265
|
-
const forwarderScript = (proxyPort) => `(${forwarderMain.toString()})({ net: require('node:net'), Duplex: require('node:stream').Duplex, input: process.stdin, output: process.stdout, error: (m) => process.stderr.write(m + '\\n'), exit: (c) => process.exit(c) }, ${createMux.toString()}, ${link.toString()}, ${proxyPort})`;
|
|
2094
|
+
const forwarderScript = (proxyPort) => `(${forwarderMain.toString()})({ net: require('node:net'), Duplex: require('node:stream').Duplex, input: process.stdin, output: process.stdout, error: (m) => process.stderr.write(m + '\\n'), exit: (c) => process.exit(c) }, ${createMux.toString()}, ${link$1.toString()}, ${proxyPort})`;
|
|
1266
2095
|
// ../sandbox-docker/src/egress/effort.ts
|
|
1267
2096
|
/** The paths read, in order; `*` is any key of an object (a gateway's provider name). */
|
|
1268
2097
|
const PATHS = [
|
|
@@ -2449,7 +3278,7 @@ function createEgressProxy(options) {
|
|
|
2449
3278
|
upstream.once("connect", () => {
|
|
2450
3279
|
socket.write("HTTP/1.1 200 Connection Established\r\n\r\n");
|
|
2451
3280
|
if (head.length) upstream.write(head);
|
|
2452
|
-
link(socket, upstream);
|
|
3281
|
+
link$1(socket, upstream);
|
|
2453
3282
|
});
|
|
2454
3283
|
upstream.once("error", (error) => {
|
|
2455
3284
|
log(`reeval:egress CONNECT ${host}:${port} failed (${failure(error)})`);
|
|
@@ -2739,7 +3568,7 @@ function createEgressProxy(options) {
|
|
|
2739
3568
|
socket.write(`${lines.join("\r\n")}\r\n\r\n`);
|
|
2740
3569
|
if (head.length) upSocket.write(head);
|
|
2741
3570
|
if (upHead.length) socket.write(upHead);
|
|
2742
|
-
link(socket, track(upSocket));
|
|
3571
|
+
link$1(socket, track(upSocket));
|
|
2743
3572
|
});
|
|
2744
3573
|
upstream.once("response", (up) => {
|
|
2745
3574
|
upgraded({ status: up.statusCode });
|
|
@@ -3293,13 +4122,13 @@ function createEgressProxy(options) {
|
|
|
3293
4122
|
track(upSocket);
|
|
3294
4123
|
if (!all.length) {
|
|
3295
4124
|
if (upHead.length) socket.write(upHead);
|
|
3296
|
-
return link(socket, upSocket);
|
|
4125
|
+
return link$1(socket, upSocket);
|
|
3297
4126
|
}
|
|
3298
4127
|
const frames = webSocketScrubber(all);
|
|
3299
4128
|
if (upHead.length) frames.write(upHead);
|
|
3300
4129
|
upSocket.pipe(frames);
|
|
3301
4130
|
upSocket.once("error", (error) => frames.destroy(error));
|
|
3302
|
-
link(socket, Duplex.from({
|
|
4131
|
+
link$1(socket, Duplex.from({
|
|
3303
4132
|
readable: frames,
|
|
3304
4133
|
writable: upSocket
|
|
3305
4134
|
}));
|
|
@@ -3397,176 +4226,29 @@ function createEgressProxy(options) {
|
|
|
3397
4226
|
}
|
|
3398
4227
|
};
|
|
3399
4228
|
}
|
|
3400
|
-
// ../sandbox-docker/src/egress/transport.ts
|
|
3401
|
-
/** Runs `command` in the sandbox to its end. */
|
|
3402
|
-
async function execRun(transport, command, options) {
|
|
3403
|
-
if (transport.run) return transport.run(command, options);
|
|
3404
|
-
const [bin = "", ...args] = transport.argv(command);
|
|
3405
|
-
const startedAt = Date.now();
|
|
3406
|
-
try {
|
|
3407
|
-
const r = await run(bin, args, {
|
|
3408
|
-
...options,
|
|
3409
|
-
env: transport.env,
|
|
3410
|
-
binary: true
|
|
3411
|
-
});
|
|
3412
|
-
transport.trace?.([bin, ...args], startedAt, {
|
|
3413
|
-
...r,
|
|
3414
|
-
stdin: options.input.length
|
|
3415
|
-
});
|
|
3416
|
-
return r;
|
|
3417
|
-
} catch (error) {
|
|
3418
|
-
transport.trace?.([bin, ...args], startedAt, { error });
|
|
3419
|
-
throw error;
|
|
3420
|
-
}
|
|
3421
|
-
}
|
|
3422
|
-
/** Starts `command` in the sandbox and leaves it running, its stdio piped. */
|
|
3423
|
-
function execSpawn(transport, command) {
|
|
3424
|
-
const argv = transport.argv(command);
|
|
3425
|
-
const [bin = "", ...args] = argv;
|
|
3426
|
-
const startedAt = Date.now();
|
|
3427
|
-
const child = spawn(bin, args, {
|
|
3428
|
-
stdio: "pipe",
|
|
3429
|
-
detached: true,
|
|
3430
|
-
env: {
|
|
3431
|
-
...process.env,
|
|
3432
|
-
...transport.env
|
|
3433
|
-
}
|
|
3434
|
-
});
|
|
3435
|
-
let stderr = "";
|
|
3436
|
-
child.stderr.on("data", (d) => {
|
|
3437
|
-
stderr += d;
|
|
3438
|
-
});
|
|
3439
|
-
child.once("close", (code) => transport.trace?.(argv, startedAt, {
|
|
3440
|
-
exitCode: code,
|
|
3441
|
-
stderr
|
|
3442
|
-
}));
|
|
3443
|
-
return child;
|
|
3444
|
-
}
|
|
3445
|
-
/** What every `ssh` reeval runs passes: no prompt, a dropped connection noticed within a minute. */
|
|
3446
|
-
const SSH_OPTIONS = [
|
|
3447
|
-
"-o",
|
|
3448
|
-
"BatchMode=yes",
|
|
3449
|
-
"-o",
|
|
3450
|
-
"ServerAliveInterval=15",
|
|
3451
|
-
"-o",
|
|
3452
|
-
"ServerAliveCountMax=4",
|
|
3453
|
-
"-o",
|
|
3454
|
-
"LogLevel=ERROR"
|
|
3455
|
-
];
|
|
3456
|
-
/**
|
|
3457
|
-
* Whether `dir` is a directory only this user can enter, made (0700) first with `make`. An ssh
|
|
3458
|
-
* client trusts whatever listens at its ControlPath, so a socket in a directory another user can
|
|
3459
|
-
* write lets them stand in for the host.
|
|
3460
|
-
*/
|
|
3461
|
-
function privateDir(dir, o = {}) {
|
|
3462
|
-
try {
|
|
3463
|
-
if (o.make) mkdirSync(dir, {
|
|
3464
|
-
recursive: true,
|
|
3465
|
-
mode: 448
|
|
3466
|
-
});
|
|
3467
|
-
const st = lstatSync(dir);
|
|
3468
|
-
return st.isDirectory() && st.uid === process.getuid?.() && (st.mode & 63) === 0;
|
|
3469
|
-
} catch {
|
|
3470
|
-
return false;
|
|
3471
|
-
}
|
|
3472
|
-
}
|
|
3473
|
-
/**
|
|
3474
|
-
* Whether ssh can listen on a control socket at `path` on `platform`. A socket's path has
|
|
3475
|
-
* `sizeof(sun_path)` bytes with its NUL (104 on macOS and the BSDs, 108 on Linux), and the master
|
|
3476
|
-
* first listens on `path` plus a 17-byte random suffix. `%C` expands to a 40-character hash.
|
|
3477
|
-
*/
|
|
3478
|
-
function controlPathFits(path, platform = process.platform) {
|
|
3479
|
-
const room = platform === "linux" ? 108 : 104;
|
|
3480
|
-
return Buffer.byteLength(path.replaceAll("%C", "C".repeat(40))) + 17 < room;
|
|
3481
|
-
}
|
|
3482
|
-
/**
|
|
3483
|
-
* The options that share one connection through a control socket at `path`, kept open `persistS`
|
|
3484
|
-
* seconds after the last command; none on Windows, whose OpenSSH has no ControlMaster, when the
|
|
3485
|
-
* path is too long for a socket ({@link controlPathFits}), or when the socket's directory isn't
|
|
3486
|
-
* {@link privateDir}. `path` may end in an ssh token such as `%C`.
|
|
3487
|
-
*/
|
|
3488
|
-
function controlOptions(path, persistS) {
|
|
3489
|
-
if (!path || process.platform === "win32" || !controlPathFits(path)) return [];
|
|
3490
|
-
if (!privateDir(dirname(path))) return [];
|
|
3491
|
-
return [
|
|
3492
|
-
"-o",
|
|
3493
|
-
"ControlMaster=auto",
|
|
3494
|
-
"-o",
|
|
3495
|
-
`ControlPath=${path}`,
|
|
3496
|
-
"-o",
|
|
3497
|
-
`ControlPersist=${persistS}`
|
|
3498
|
-
];
|
|
3499
|
-
}
|
|
3500
|
-
/**
|
|
3501
|
-
* The host argv that runs `remote`, one shell command line, on `target`. ssh joins its remote
|
|
3502
|
-
* arguments into one line for the login shell, so the caller quotes it. No user config applies.
|
|
3503
|
-
*/
|
|
3504
|
-
function sshArgv(target, remote) {
|
|
3505
|
-
return [
|
|
3506
|
-
"ssh",
|
|
3507
|
-
"-T",
|
|
3508
|
-
"-F",
|
|
3509
|
-
"none",
|
|
3510
|
-
"-i",
|
|
3511
|
-
target.identityFile,
|
|
3512
|
-
"-p",
|
|
3513
|
-
String(target.port),
|
|
3514
|
-
...SSH_OPTIONS,
|
|
3515
|
-
"-o",
|
|
3516
|
-
"IdentitiesOnly=yes",
|
|
3517
|
-
"-o",
|
|
3518
|
-
"StrictHostKeyChecking=yes",
|
|
3519
|
-
"-o",
|
|
3520
|
-
`UserKnownHostsFile=${target.knownHostsFile}`,
|
|
3521
|
-
"-o",
|
|
3522
|
-
"GlobalKnownHostsFile=none",
|
|
3523
|
-
"-o",
|
|
3524
|
-
`HostKeyAlias=${target.hostKeyAlias}`,
|
|
3525
|
-
"-o",
|
|
3526
|
-
"ConnectTimeout=20",
|
|
3527
|
-
...controlOptions(target.controlPath, 300),
|
|
3528
|
-
`${target.user}@${target.host}`,
|
|
3529
|
-
remote
|
|
3530
|
-
];
|
|
3531
|
-
}
|
|
3532
|
-
/** `ssh -T` into a VM, as root through `sudo -n`, with sudo's own `secure_path`. */
|
|
3533
|
-
function sshTransport(target) {
|
|
3534
|
-
return {
|
|
3535
|
-
argv: (command) => sshArgv(target, `sudo -n -- ${command.map(shellQuote).join(" ")}`),
|
|
3536
|
-
trace: (argv, startedAt, end) => traceDocker(argv.slice(1), startedAt, end, "ssh")
|
|
3537
|
-
};
|
|
3538
|
-
}
|
|
3539
|
-
/** `docker exec` (or `podman exec`) into a running container, as root. */
|
|
3540
|
-
function containerTransport(containerId, engine) {
|
|
3541
|
-
const { bin } = engineSpec(engine);
|
|
3542
|
-
const exec = (command) => [
|
|
3543
|
-
"exec",
|
|
3544
|
-
"--interactive",
|
|
3545
|
-
"--user",
|
|
3546
|
-
"0:0",
|
|
3547
|
-
containerId,
|
|
3548
|
-
...command
|
|
3549
|
-
];
|
|
3550
|
-
return {
|
|
3551
|
-
argv: (command) => [bin, ...exec(command)],
|
|
3552
|
-
env: engineEnv(engine),
|
|
3553
|
-
run: (command, { input, signal }) => docker(exec(command), {
|
|
3554
|
-
input,
|
|
3555
|
-
signal,
|
|
3556
|
-
engine
|
|
3557
|
-
}),
|
|
3558
|
-
trace: (argv, startedAt, end) => traceDocker(argv.slice(1), startedAt, end, bin)
|
|
3559
|
-
};
|
|
3560
|
-
}
|
|
3561
4229
|
// ../sandbox-docker/src/egress/gateway.ts
|
|
3562
4230
|
/** Where the forwarder listens inside the sandbox; every exec gets it as its HTTP(S) proxy. */
|
|
3563
|
-
const PROXY_PORT =
|
|
4231
|
+
const PROXY_PORT = BASE_PROXY_PORT;
|
|
3564
4232
|
/** The gateway's CA certificate in the container. The private key never leaves the host. */
|
|
3565
4233
|
const CA_PATH = "/usr/local/share/ca-certificates/reeval-egress.crt";
|
|
3566
4234
|
/** Debian's system bundle, which `update-ca-certificates` rebuilds with the gateway's CA in it. */
|
|
3567
4235
|
const CA_BUNDLE = "/etc/ssl/certs/ca-certificates.crt";
|
|
3568
4236
|
const BUNDLED = "reeval:ca-bundle";
|
|
4237
|
+
/** Held while a gateway installs its CA, so gateways sharing a machine don't rebuild the bundle at once. */
|
|
4238
|
+
const CA_LOCK = "/var/lock/reeval-egress-ca";
|
|
3569
4239
|
const READY_TIMEOUT_MS = 15e3;
|
|
4240
|
+
/** Where a gateway on `port` keeps its CA certificate, and the glob of its pid files' tags. */
|
|
4241
|
+
const placement = (port) => port === void 0 ? {
|
|
4242
|
+
port: PROXY_PORT,
|
|
4243
|
+
caPath: CA_PATH,
|
|
4244
|
+
tags: "*",
|
|
4245
|
+
tag: ""
|
|
4246
|
+
} : {
|
|
4247
|
+
port,
|
|
4248
|
+
caPath: `/usr/local/share/ca-certificates/reeval-egress-${port}.crt`,
|
|
4249
|
+
tags: `p${port}-*`,
|
|
4250
|
+
tag: `p${port}-`
|
|
4251
|
+
};
|
|
3570
4252
|
/**
|
|
3571
4253
|
* Where a forwarder a transport could orphan records its pid, one file per gateway: `ps` can't
|
|
3572
4254
|
* find it by its command line, which Linux cuts short of a long script.
|
|
@@ -3575,11 +4257,11 @@ const PID_FILE = "/tmp/reeval-egress-forwarder";
|
|
|
3575
4257
|
/** How long `close()` waits for the sandbox to stop a forwarder a transport could orphan. */
|
|
3576
4258
|
const CLOSE_TIMEOUT_MS = 1e4;
|
|
3577
4259
|
/** Runs the forwarder; under a transport that orphans it, as the shell that wrote its pid file. */
|
|
3578
|
-
function forwarderCommand(transport, tag) {
|
|
4260
|
+
function forwarderCommand(transport, tag, port) {
|
|
3579
4261
|
const node = [
|
|
3580
4262
|
"node",
|
|
3581
4263
|
"-e",
|
|
3582
|
-
forwarderScript(
|
|
4264
|
+
forwarderScript(port)
|
|
3583
4265
|
];
|
|
3584
4266
|
if (!transport.orphans) return node;
|
|
3585
4267
|
return [
|
|
@@ -3606,31 +4288,50 @@ done; true`
|
|
|
3606
4288
|
input: "",
|
|
3607
4289
|
signal
|
|
3608
4290
|
}).then(() => {}, () => {});
|
|
3609
|
-
const installCa = (transport, cert, signal) =>
|
|
3610
|
-
"
|
|
3611
|
-
"-
|
|
3612
|
-
|
|
3613
|
-
|
|
3614
|
-
|
|
3615
|
-
|
|
3616
|
-
|
|
4291
|
+
const installCa = (transport, cert, o, signal) => {
|
|
4292
|
+
const inBundle = `grep -q "$(sed -n 2p ${o.caPath})" ${CA_BUNDLE}`;
|
|
4293
|
+
const rebuild = "command -v update-ca-certificates >/dev/null && update-ca-certificates >/dev/null 2>&1";
|
|
4294
|
+
if (!o.shared) return execRun(transport, [
|
|
4295
|
+
"sh",
|
|
4296
|
+
"-c",
|
|
4297
|
+
`umask 022 && mkdir -p "$(dirname ${o.caPath})" && cat > ${o.caPath} && { ${rebuild} && ${inBundle} && echo ${BUNDLED}; true; }`
|
|
4298
|
+
], {
|
|
4299
|
+
input: cert,
|
|
4300
|
+
signal
|
|
4301
|
+
});
|
|
4302
|
+
const bundle = `{ ${inBundle} || { ${rebuild}; }; } && ${inBundle} && echo ${BUNDLED}; true`;
|
|
4303
|
+
return execRun(transport, [
|
|
4304
|
+
"sh",
|
|
4305
|
+
"-c",
|
|
4306
|
+
`umask 022 && mkdir -p "$(dirname ${o.caPath})" && cat > ${o.caPath}.$$ && mv ${o.caPath}.$$ ${o.caPath} && flock ${CA_LOCK} sh -c '${bundle}'`
|
|
4307
|
+
], {
|
|
4308
|
+
input: cert,
|
|
4309
|
+
signal
|
|
4310
|
+
});
|
|
4311
|
+
};
|
|
3617
4312
|
/**
|
|
3618
4313
|
* Starts the egress gateway for one sandbox: a forwarder inside it, tunneled over one process
|
|
3619
4314
|
* `transport` starts there, and the proxy in this process, which holds the real credentials.
|
|
3620
4315
|
*/
|
|
3621
4316
|
async function startGateway(transport, options, signal) {
|
|
4317
|
+
const { port: asked, ...proxyOptions } = options;
|
|
4318
|
+
const place = placement(asked);
|
|
4319
|
+
const { port } = place;
|
|
3622
4320
|
const ca = createCertificateAuthority();
|
|
3623
|
-
const installed = await installCa(transport, ca.cert,
|
|
4321
|
+
const installed = await installCa(transport, ca.cert, {
|
|
4322
|
+
caPath: place.caPath,
|
|
4323
|
+
shared: asked !== void 0
|
|
4324
|
+
}, signal);
|
|
3624
4325
|
if (installed.exitCode !== 0) throw new Error(`couldn't install the gateway CA: ${installed.stderr.trim()}`);
|
|
3625
4326
|
const bundled = installed.stdout.toString("utf8").includes(BUNDLED);
|
|
3626
|
-
if (transport.orphans) await killForwarders(transport,
|
|
4327
|
+
if (transport.orphans) await killForwarders(transport, place.tags, signal);
|
|
3627
4328
|
signal?.throwIfAborted();
|
|
3628
|
-
const tag = randomBytes(6).toString("hex")
|
|
4329
|
+
const tag = `${place.tag}${randomBytes(6).toString("hex")}`;
|
|
3629
4330
|
const proxy = createEgressProxy({
|
|
3630
|
-
...
|
|
4331
|
+
...proxyOptions,
|
|
3631
4332
|
ca
|
|
3632
4333
|
});
|
|
3633
|
-
const child = execSpawn(transport, forwarderCommand(transport, tag));
|
|
4334
|
+
const child = execSpawn(transport, forwarderCommand(transport, tag, port));
|
|
3634
4335
|
let stderr = "";
|
|
3635
4336
|
child.stderr.on("data", (d) => {
|
|
3636
4337
|
stderr += d;
|
|
@@ -3644,8 +4345,8 @@ async function startGateway(transport, options, signal) {
|
|
|
3644
4345
|
send: (frame) => {
|
|
3645
4346
|
if (!closed) child.stdin.write(frame);
|
|
3646
4347
|
},
|
|
3647
|
-
onOpen(stream,
|
|
3648
|
-
if (
|
|
4348
|
+
onOpen(stream, opened) {
|
|
4349
|
+
if (opened === port) proxy.handle(stream);
|
|
3649
4350
|
else stream.destroy();
|
|
3650
4351
|
},
|
|
3651
4352
|
onReady: () => {
|
|
@@ -3703,7 +4404,7 @@ async function startGateway(transport, options, signal) {
|
|
|
3703
4404
|
clearTimeout(timer);
|
|
3704
4405
|
signal?.removeEventListener("abort", onAbort);
|
|
3705
4406
|
}
|
|
3706
|
-
const proxyUrl = `http://127.0.0.1:${
|
|
4407
|
+
const proxyUrl = `http://127.0.0.1:${port}`;
|
|
3707
4408
|
const noProxy = "localhost,127.0.0.1,::1,[::1]";
|
|
3708
4409
|
return {
|
|
3709
4410
|
env: {
|
|
@@ -3713,7 +4414,7 @@ async function startGateway(transport, options, signal) {
|
|
|
3713
4414
|
http_proxy: proxyUrl,
|
|
3714
4415
|
NO_PROXY: noProxy,
|
|
3715
4416
|
no_proxy: noProxy,
|
|
3716
|
-
NODE_EXTRA_CA_CERTS:
|
|
4417
|
+
NODE_EXTRA_CA_CERTS: place.caPath,
|
|
3717
4418
|
NODE_USE_ENV_PROXY: "1",
|
|
3718
4419
|
...bundled ? {
|
|
3719
4420
|
SSL_CERT_FILE: CA_BUNDLE,
|
|
@@ -3740,7 +4441,7 @@ async function startGateway(transport, options, signal) {
|
|
|
3740
4441
|
if (stopped) return socket.destroy();
|
|
3741
4442
|
tunnels.add(socket);
|
|
3742
4443
|
socket.once("close", () => tunnels.delete(socket));
|
|
3743
|
-
link(socket, mux.open(port));
|
|
4444
|
+
link$1(socket, mux.open(port));
|
|
3744
4445
|
});
|
|
3745
4446
|
server.once("error", reject);
|
|
3746
4447
|
server.listen(0, "127.0.0.1", () => resolve(server));
|
|
@@ -4011,8 +4712,8 @@ async function networkMode(id, engine) {
|
|
|
4011
4712
|
async function createDockerSession(options) {
|
|
4012
4713
|
const nonce = randomBytes(8).toString("hex");
|
|
4013
4714
|
const labels = {
|
|
4014
|
-
[LABEL.managed]: "true",
|
|
4015
|
-
[LABEL.session]: nonce,
|
|
4715
|
+
[LABEL$1.managed]: "true",
|
|
4716
|
+
[LABEL$1.session]: nonce,
|
|
4016
4717
|
...options.labels
|
|
4017
4718
|
};
|
|
4018
4719
|
const lifetime = Math.ceil((options.lifetimeMs ?? 864e5) / 1e3);
|
|
@@ -4043,14 +4744,16 @@ async function createDockerSession(options) {
|
|
|
4043
4744
|
env,
|
|
4044
4745
|
engine
|
|
4045
4746
|
}).catch((error) => {
|
|
4046
|
-
if (signal?.aborted) sweepLabelDetached(`${LABEL.session}=${nonce}`, void 0, engine);
|
|
4747
|
+
if (signal?.aborted) sweepLabelDetached(`${LABEL$1.session}=${nonce}`, void 0, engine);
|
|
4047
4748
|
throw error;
|
|
4048
4749
|
});
|
|
4049
4750
|
let gateway;
|
|
4050
4751
|
let removed;
|
|
4752
|
+
const observers = [];
|
|
4753
|
+
const creating = /* @__PURE__ */ new Set();
|
|
4051
4754
|
const remove = () => {
|
|
4052
4755
|
gateway?.close();
|
|
4053
|
-
removed ??=
|
|
4756
|
+
removed ??= Promise.allSettled(creating).then(() => Promise.all([id, ...observers].map((c) => removeContainerDetached(c, engine)))).then(() => {});
|
|
4054
4757
|
return removed;
|
|
4055
4758
|
};
|
|
4056
4759
|
if (signal?.aborted) {
|
|
@@ -4232,33 +4935,144 @@ async function createDockerSession(options) {
|
|
|
4232
4935
|
throw error;
|
|
4233
4936
|
}
|
|
4234
4937
|
};
|
|
4235
|
-
|
|
4236
|
-
|
|
4237
|
-
|
|
4238
|
-
|
|
4239
|
-
|
|
4240
|
-
|
|
4241
|
-
"
|
|
4242
|
-
|
|
4243
|
-
|
|
4244
|
-
|
|
4245
|
-
|
|
4938
|
+
/** Runs the engine's CLI with its output streamed; `stop` ends what it started. */
|
|
4939
|
+
const streamed = (args, stop) => {
|
|
4940
|
+
const startedAt = Date.now();
|
|
4941
|
+
const child = spawnEngine(engine, args);
|
|
4942
|
+
child.stderr.resume();
|
|
4943
|
+
const exited = new Promise((resolve) => {
|
|
4944
|
+
child.once("error", () => resolve({ exitCode: 127 }));
|
|
4945
|
+
child.once("close", (code) => {
|
|
4946
|
+
traceDocker(args, startedAt, {
|
|
4947
|
+
exitCode: code,
|
|
4948
|
+
stdout: "<streamed>"
|
|
4949
|
+
}, engineLabel(engine));
|
|
4950
|
+
resolve({ exitCode: code ?? 1 });
|
|
4951
|
+
});
|
|
4246
4952
|
});
|
|
4247
|
-
return
|
|
4953
|
+
return {
|
|
4954
|
+
pid: child.pid,
|
|
4955
|
+
stdout: Readable.toWeb(child.stdout),
|
|
4956
|
+
wait: () => exited,
|
|
4957
|
+
kill: async () => {
|
|
4958
|
+
child.kill("SIGKILL");
|
|
4959
|
+
await stop();
|
|
4960
|
+
}
|
|
4961
|
+
};
|
|
4248
4962
|
};
|
|
4249
|
-
const
|
|
4250
|
-
const
|
|
4963
|
+
const spawnPrivileged = async (o) => {
|
|
4964
|
+
const marker = nextMarker();
|
|
4965
|
+
return streamed([
|
|
4251
4966
|
"exec",
|
|
4252
|
-
|
|
4967
|
+
"--user",
|
|
4968
|
+
"0:0",
|
|
4969
|
+
"--workdir",
|
|
4970
|
+
SANDBOX_STATE,
|
|
4971
|
+
"--env",
|
|
4972
|
+
`${EXEC_MARKER$1}=${marker}`,
|
|
4973
|
+
"--env",
|
|
4974
|
+
`PATH=${SYSTEM_PATH$1}`,
|
|
4253
4975
|
id,
|
|
4254
|
-
"sh",
|
|
4976
|
+
"/bin/sh",
|
|
4255
4977
|
"-c",
|
|
4256
|
-
|
|
4257
|
-
|
|
4258
|
-
|
|
4259
|
-
|
|
4260
|
-
|
|
4261
|
-
|
|
4978
|
+
o.command
|
|
4979
|
+
], () => killExec(marker, true));
|
|
4980
|
+
};
|
|
4981
|
+
const observer = {
|
|
4982
|
+
target: id,
|
|
4983
|
+
async spawn(o) {
|
|
4984
|
+
const gone = () => /* @__PURE__ */ new Error(`${spec.name} container ${id.slice(0, 12)} is gone`);
|
|
4985
|
+
if (removed) throw gone();
|
|
4986
|
+
const name = `reeval-observer-${nonce}-${observers.length + 1}`;
|
|
4987
|
+
observers.push(name);
|
|
4988
|
+
const created = docker([
|
|
4989
|
+
"create",
|
|
4990
|
+
"--rm",
|
|
4991
|
+
"--name",
|
|
4992
|
+
name,
|
|
4993
|
+
...Object.entries(labels).flatMap(([k, v]) => ["--label", `${k}=${v}`]),
|
|
4994
|
+
"--pull",
|
|
4995
|
+
"never",
|
|
4996
|
+
"--network",
|
|
4997
|
+
"none",
|
|
4998
|
+
"--cgroupns",
|
|
4999
|
+
"host",
|
|
5000
|
+
"--user",
|
|
5001
|
+
"65534:65534",
|
|
5002
|
+
"--cap-drop",
|
|
5003
|
+
"ALL",
|
|
5004
|
+
"--security-opt",
|
|
5005
|
+
"no-new-privileges",
|
|
5006
|
+
"--read-only",
|
|
5007
|
+
"--pids-limit",
|
|
5008
|
+
"16",
|
|
5009
|
+
"--entrypoint",
|
|
5010
|
+
"/bin/sh",
|
|
5011
|
+
options.image,
|
|
5012
|
+
"-c",
|
|
5013
|
+
o.command
|
|
5014
|
+
], { engine });
|
|
5015
|
+
creating.add(created);
|
|
5016
|
+
const r = await created.finally(() => creating.delete(created));
|
|
5017
|
+
if (r.exitCode !== 0) throw new Error(`${spec.bin} create failed: ${r.stderr.trim()}`);
|
|
5018
|
+
if (removed) throw gone();
|
|
5019
|
+
return streamed([
|
|
5020
|
+
"start",
|
|
5021
|
+
"--attach",
|
|
5022
|
+
name
|
|
5023
|
+
], () => removeContainerDetached(name, engine));
|
|
5024
|
+
},
|
|
5025
|
+
async run(o) {
|
|
5026
|
+
const name = observers.at(-1);
|
|
5027
|
+
if (!name) return {
|
|
5028
|
+
exitCode: 1,
|
|
5029
|
+
stdout: "",
|
|
5030
|
+
stderr: "no observer started"
|
|
5031
|
+
};
|
|
5032
|
+
const r = await docker([
|
|
5033
|
+
"exec",
|
|
5034
|
+
name,
|
|
5035
|
+
"/bin/sh",
|
|
5036
|
+
"-c",
|
|
5037
|
+
o.command
|
|
5038
|
+
], {
|
|
5039
|
+
signal: o.abortSignal,
|
|
5040
|
+
engine
|
|
5041
|
+
});
|
|
5042
|
+
return {
|
|
5043
|
+
exitCode: r.exitCode,
|
|
5044
|
+
stdout: r.stdout.toString("utf8"),
|
|
5045
|
+
stderr: r.stderr
|
|
5046
|
+
};
|
|
5047
|
+
}
|
|
5048
|
+
};
|
|
5049
|
+
const readBinaryFile = async (o) => {
|
|
5050
|
+
const r = await docker([
|
|
5051
|
+
"exec",
|
|
5052
|
+
...user,
|
|
5053
|
+
id,
|
|
5054
|
+
"cat",
|
|
5055
|
+
"--",
|
|
5056
|
+
posix.resolve(SANDBOX_ROOT, o.path)
|
|
5057
|
+
], {
|
|
5058
|
+
signal: o.abortSignal,
|
|
5059
|
+
engine
|
|
5060
|
+
});
|
|
5061
|
+
return r.exitCode === 0 ? new Uint8Array(r.stdout) : null;
|
|
5062
|
+
};
|
|
5063
|
+
const paths = pathOperations(async (script, path, abortSignal) => {
|
|
5064
|
+
const r = await docker([
|
|
5065
|
+
"exec",
|
|
5066
|
+
...user,
|
|
5067
|
+
id,
|
|
5068
|
+
"sh",
|
|
5069
|
+
"-c",
|
|
5070
|
+
script,
|
|
5071
|
+
"sh",
|
|
5072
|
+
path
|
|
5073
|
+
], {
|
|
5074
|
+
signal: abortSignal,
|
|
5075
|
+
engine
|
|
4262
5076
|
});
|
|
4263
5077
|
return {
|
|
4264
5078
|
exitCode: r.exitCode,
|
|
@@ -4338,30 +5152,20 @@ async function createDockerSession(options) {
|
|
|
4338
5152
|
oomKills: () => oomKills(id, engine, execUser(options)),
|
|
4339
5153
|
run,
|
|
4340
5154
|
runPrivileged,
|
|
5155
|
+
spawnPrivileged,
|
|
5156
|
+
observer,
|
|
4341
5157
|
spawn: (async (o) => {
|
|
4342
5158
|
if (o.stdin) throw new Error(`A ${spec.name} sandbox process has no writable stdin`);
|
|
4343
5159
|
const env = envFor(o.env);
|
|
4344
5160
|
const marker = nextMarker();
|
|
4345
5161
|
const args = execArgs(o.command, marker, o.workingDirectory, env);
|
|
4346
5162
|
const startedAt = Date.now();
|
|
4347
|
-
const child =
|
|
4348
|
-
stdio: [
|
|
4349
|
-
"ignore",
|
|
4350
|
-
"pipe",
|
|
4351
|
-
"pipe"
|
|
4352
|
-
],
|
|
4353
|
-
detached: true,
|
|
4354
|
-
env: {
|
|
4355
|
-
...process.env,
|
|
4356
|
-
...engineEnv(engine),
|
|
4357
|
-
...env
|
|
4358
|
-
}
|
|
4359
|
-
});
|
|
5163
|
+
const child = spawnEngine(engine, args, env);
|
|
4360
5164
|
const exited = new Promise((resolve) => child.on("close", (code) => {
|
|
4361
5165
|
traceDocker(args, startedAt, {
|
|
4362
5166
|
exitCode: code,
|
|
4363
5167
|
stdout: "<streamed>"
|
|
4364
|
-
},
|
|
5168
|
+
}, engineLabel(engine));
|
|
4365
5169
|
resolve({ exitCode: code ?? 1 });
|
|
4366
5170
|
}));
|
|
4367
5171
|
const kill = async () => {
|
|
@@ -4463,108 +5267,52 @@ const dockerSandboxProvider = (options) => ({
|
|
|
4463
5267
|
const PNPM_VERSION = "10.33.3";
|
|
4464
5268
|
/** Pinned so evals' installs don't move with the Node image's bundled npm. */
|
|
4465
5269
|
const NPM_VERSION = "11.20.0";
|
|
5270
|
+
const sha256 = (text) => createHash("sha256").update(text).digest("hex");
|
|
5271
|
+
/** Docker's names for Node's architectures, as image indexes list platforms. */
|
|
5272
|
+
const OCI_ARCH = {
|
|
5273
|
+
x64: "amd64",
|
|
5274
|
+
arm64: "arm64",
|
|
5275
|
+
arm: "arm",
|
|
5276
|
+
ppc64: "ppc64le"
|
|
5277
|
+
};
|
|
4466
5278
|
/**
|
|
4467
|
-
*
|
|
4468
|
-
*
|
|
4469
|
-
*
|
|
5279
|
+
* Linux on this process's architecture, as `docker image inspect` names a platform
|
|
5280
|
+
* (`.Os/.Architecture`): what Docker Desktop's and Podman's VMs run, and the fallback when the
|
|
5281
|
+
* engine doesn't say its own (`enginePlatform`).
|
|
4470
5282
|
*/
|
|
4471
|
-
const
|
|
4472
|
-
const sha256 = (text) => createHash("sha256").update(text).digest("hex");
|
|
5283
|
+
const PLATFORM = `linux/${OCI_ARCH[process.arch] ?? process.arch}`;
|
|
4473
5284
|
const slugify = (text, max) => text.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, max).replace(/-+$/, "");
|
|
4474
5285
|
/** The build context of reeval's base image, shipped in the package. */
|
|
4475
5286
|
const DOCKER_CONTEXT = fileURLToPath(ownFileURL("docker"));
|
|
4476
5287
|
/**
|
|
4477
|
-
*
|
|
4478
|
-
*
|
|
5288
|
+
* The official Node image the sandbox's Node comes from, pinned by its index digest: the base
|
|
5289
|
+
* Dockerfile's `FROM`, which the toolchain layer also copies onto a `from` image. The pin is what
|
|
5290
|
+
* makes reeval's image, and every key built on it, the same content on any machine. Node 24+
|
|
5291
|
+
* bundles undici 7, whose `EnvHttpProxyAgent` (behind `NODE_USE_ENV_PROXY`) prints no experimental
|
|
5292
|
+
* warning.
|
|
5293
|
+
*/
|
|
5294
|
+
const NODE_IMAGE = /^FROM (\S+)$/m.exec(readFileSync(join(DOCKER_CONTEXT, "Dockerfile"), "utf8"))?.[1] ?? "node";
|
|
5295
|
+
/**
|
|
5296
|
+
* How reeval bakes a harness into a Docker or Tart image, beyond the build context, the adapter and
|
|
5297
|
+
* the inputs each passes {@link bakeKey}: bump it when that changes what a baked image holds, so
|
|
5298
|
+
* every image baked before rebuilds on its next use.
|
|
4479
5299
|
*/
|
|
4480
5300
|
const BAKE_REVISION = 2;
|
|
4481
5301
|
/**
|
|
4482
|
-
* The
|
|
4483
|
-
*
|
|
4484
|
-
* or how the harness is baked builds anew.
|
|
5302
|
+
* The hash a baked image's name ends with: {@link BAKE_REVISION} and what the bake starts from and
|
|
5303
|
+
* runs, so a change to any of them bakes anew.
|
|
4485
5304
|
*/
|
|
4486
|
-
const
|
|
5305
|
+
const bakeKey = (...inputs) => sha256([BAKE_REVISION, ...inputs].join("\0")).slice(0, 8);
|
|
4487
5306
|
/**
|
|
4488
|
-
*
|
|
4489
|
-
*
|
|
5307
|
+
* The image `docker({ from })` evals run in: `from` plus Node, git and the harness's CLI. Its
|
|
5308
|
+
* {@link bakeKey} covers the toolchain layer, so a change to the sandbox user or paths builds anew.
|
|
4490
5309
|
*/
|
|
4491
|
-
const
|
|
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
|
-
};
|
|
5310
|
+
const harnessImageFor = (harness, from) => `${imageFor(harness)}-${slugify(from, 40) || "image"}-${bakeKey(toolchainDockerfile(from))}`;
|
|
4563
5311
|
/**
|
|
4564
5312
|
* The adapter whose bootstrap `harness`'s image bakes. An attempt whose adapter asks for any other
|
|
4565
5313
|
* bootstrap reinstalls the CLI at start, which a restricted egress policy can refuse.
|
|
4566
5314
|
*/
|
|
4567
|
-
const bakedAdapter = (harness) =>
|
|
5315
|
+
const bakedAdapter = (harness) => HARNESS_PACKAGES[harness].bootstrap.adapter();
|
|
4568
5316
|
/** Keeps the image's `PATH` in login shells, which Debian's `/etc/profile` resets. */
|
|
4569
5317
|
const profilePathScript = () => readFileSync(join(DOCKER_CONTEXT, "reeval-path.sh")).toString("base64");
|
|
4570
5318
|
/** `from` as it goes after `FROM`: one word, so it can't add a stage name or another instruction. */
|
|
@@ -4636,7 +5384,13 @@ function buildError(output, what, reason, keep = () => true) {
|
|
|
4636
5384
|
});
|
|
4637
5385
|
}
|
|
4638
5386
|
/** Every image reeval builds carries this label, so `reeval clean --images` can find what it left. */
|
|
4639
|
-
const BUILT_BY = ["--label", `${LABEL.managed}=image`];
|
|
5387
|
+
const BUILT_BY = ["--label", `${LABEL$1.managed}=image`];
|
|
5388
|
+
const keyLabel = (key) => ["--label", `${LABEL$1.key}=${key}`];
|
|
5389
|
+
/** Removes the image `tag` pointed at before a rebuild, once the tag points elsewhere. */
|
|
5390
|
+
async function replaced(tag, previous, engine) {
|
|
5391
|
+
if (!previous) return;
|
|
5392
|
+
if ((await imageInfo(tag, engine))?.id !== previous) await removeQuietly(previous, engine);
|
|
5393
|
+
}
|
|
4640
5394
|
/**
|
|
4641
5395
|
* Removes the images reeval built that nothing tags any more (a rebuild's old image) and the
|
|
4642
5396
|
* intermediate `-base` tags of `from` builds. Returns how many it removed.
|
|
@@ -4652,13 +5406,13 @@ async function pruneImages(engine) {
|
|
|
4652
5406
|
"--filter",
|
|
4653
5407
|
"dangling=true",
|
|
4654
5408
|
"--filter",
|
|
4655
|
-
`label=${LABEL.managed}=image`
|
|
5409
|
+
`label=${LABEL$1.managed}=image`
|
|
4656
5410
|
]), ...await list([
|
|
4657
5411
|
"-q",
|
|
4658
5412
|
"--filter",
|
|
4659
5413
|
"dangling=true",
|
|
4660
5414
|
"--filter",
|
|
4661
|
-
`label=${LABEL.harness}`
|
|
5415
|
+
`label=${LABEL$1.harness}`
|
|
4662
5416
|
])];
|
|
4663
5417
|
const bases = (await list([
|
|
4664
5418
|
"--format",
|
|
@@ -4673,13 +5427,6 @@ async function pruneImages(engine) {
|
|
|
4673
5427
|
], { engine }).catch(() => null))?.exitCode === 0) removed++;
|
|
4674
5428
|
return removed;
|
|
4675
5429
|
}
|
|
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
5430
|
/**
|
|
4684
5431
|
* A registry digest for `from` without Docker's buildx: skopeo's, which is the same digest
|
|
4685
5432
|
* buildx gives, or else this platform's manifest from `podman manifest inspect`.
|
|
@@ -4773,6 +5520,28 @@ function contextHash() {
|
|
|
4773
5520
|
return hash.digest("hex").slice(0, 16);
|
|
4774
5521
|
}
|
|
4775
5522
|
/**
|
|
5523
|
+
* reeval's image for a harness: its tag (the adapter) and its base's build context, whose `FROM` is
|
|
5524
|
+
* pinned by digest.
|
|
5525
|
+
*/
|
|
5526
|
+
const reevalImageKey = (harness) => `${imageFor(harness)}+${contextHash()}`;
|
|
5527
|
+
/**
|
|
5528
|
+
* A harness baked onto `from`: its tag and what `from` named when it was built, a registry digest
|
|
5529
|
+
* (or, for a base only this machine has, its image id, or a Dockerfile image's own key).
|
|
5530
|
+
*/
|
|
5531
|
+
const fromImageKey = (ref, digest) => `${ref}@${digest}`;
|
|
5532
|
+
/**
|
|
5533
|
+
* The key of an image only this machine can name, such as a Dockerfile built on a base that didn't
|
|
5534
|
+
* resolve: its tag and local image id. Nothing keyed on one is pulled or pushed.
|
|
5535
|
+
*/
|
|
5536
|
+
const localKey = (ref, id) => `${ref}@local:${id}`;
|
|
5537
|
+
/** Whether `key` is a {@link localKey}, or a key built on one. */
|
|
5538
|
+
const isLocalKey = (key) => key.includes("@local:");
|
|
5539
|
+
/**
|
|
5540
|
+
* An image reeval uses as is: its image id, which is content-addressed, so the same on every machine
|
|
5541
|
+
* that pulled it (and this machine's alone for one built here), whichever registries it's in.
|
|
5542
|
+
*/
|
|
5543
|
+
const imageKey = (info) => info.id;
|
|
5544
|
+
/**
|
|
4776
5545
|
* Bakes a harness's bootstrap (which installs its agent's CLI) into an image, so the image tag
|
|
4777
5546
|
* pins the CLI build. Rebuild after bumping the adapter. With `from`, the base is that toolchain
|
|
4778
5547
|
* image instead of reeval's Node image. `log` gets progress lines, `output` the build's full output
|
|
@@ -4784,9 +5553,11 @@ async function buildImage(log, options) {
|
|
|
4784
5553
|
const resolved = from ? await resolveFrom(from, signal, engine) : null;
|
|
4785
5554
|
const digest = resolved && "digest" in resolved ? resolved.digest : null;
|
|
4786
5555
|
const pinned = from && digest && resolved && "local" in resolved && !resolved.local && !from.includes("@") ? `${from}@${digest}` : from;
|
|
4787
|
-
const bootstrap =
|
|
5556
|
+
const { bootstrap } = HARNESS_PACKAGES[harness];
|
|
4788
5557
|
const base = from ? `${harnessImageFor(harness, from)}-base` : BASE_IMAGE;
|
|
4789
5558
|
const target = from ? harnessImageFor(harness, from) : imageFor(harness);
|
|
5559
|
+
const shared = !!resolved && "local" in resolved && !resolved.local;
|
|
5560
|
+
const key = options.key ?? (from ? digest && shared ? fromImageKey(target, digest) : "" : reevalImageKey(harness));
|
|
4790
5561
|
const previous = [(await imageInfo(target, engine))?.id, from ? null : (await imageInfo(base, engine))?.id];
|
|
4791
5562
|
log(`Building ${base}${from ? ` from ${from}` : ""}`);
|
|
4792
5563
|
const build = from ? await docker([
|
|
@@ -4837,11 +5608,11 @@ async function buildImage(log, options) {
|
|
|
4837
5608
|
let agentVersion;
|
|
4838
5609
|
try {
|
|
4839
5610
|
agentVersion = await bake(session, bootstrap);
|
|
4840
|
-
log(`${bootstrap.name} ${bootstrap.
|
|
5611
|
+
log(`${bootstrap.name} ${bootstrap.probe ? "" : "CLI "}${agentVersion}`);
|
|
4841
5612
|
await dockerOk([
|
|
4842
5613
|
"commit",
|
|
4843
5614
|
"--change",
|
|
4844
|
-
`LABEL ${LABEL.agentVersion}="${agentVersion}" ${LABEL.harness}="${harnessLabel(harness)}"${from ? digest ? ` ${LABEL.fromDigest}="${digest}"` : "" : ` ${LABEL.context}="${contextHash()}"`}`,
|
|
5615
|
+
`LABEL ${LABEL$1.agentVersion}="${agentVersion}" ${LABEL$1.harness}="${harnessLabel(harness)}"${from ? digest ? ` ${LABEL$1.fromDigest}="${digest}"` : "" : ` ${LABEL$1.context}="${contextHash()}"`} ${LABEL$1.key}="${key}"`,
|
|
4845
5616
|
"--change",
|
|
4846
5617
|
`WORKDIR ${SANDBOX_ROOT}`,
|
|
4847
5618
|
"--change",
|
|
@@ -4886,13 +5657,13 @@ async function buildImage(log, options) {
|
|
|
4886
5657
|
* Runs `harness`'s bootstrap in `session` (a container, or a VM reeval then keeps as an image)
|
|
4887
5658
|
* and returns the CLI version it installed.
|
|
4888
5659
|
*/
|
|
4889
|
-
const bakeHarness = (session, harness) => bake(session,
|
|
5660
|
+
const bakeHarness = (session, harness) => bake(session, HARNESS_PACKAGES[harness].bootstrap);
|
|
4890
5661
|
/**
|
|
4891
5662
|
* A hash of the bootstrap `harness`'s adapter applies (its files and commands): it changes
|
|
4892
5663
|
* whenever what the bootstrap installs does, version bump or not.
|
|
4893
5664
|
*/
|
|
4894
5665
|
async function bakedRecipe(harness) {
|
|
4895
|
-
const recipe = await (await
|
|
5666
|
+
const recipe = await (await HARNESS_PACKAGES[harness].bootstrap.adapter()).getBootstrap?.({});
|
|
4896
5667
|
if (!recipe) return "none";
|
|
4897
5668
|
const files = [...recipe.files].sort((a, b) => a.path.localeCompare(b.path)).map((f) => [f.path, f.content]);
|
|
4898
5669
|
return createHash("sha256").update(JSON.stringify([
|
|
@@ -4903,29 +5674,29 @@ async function bakedRecipe(harness) {
|
|
|
4903
5674
|
])).digest("hex").slice(0, 16);
|
|
4904
5675
|
}
|
|
4905
5676
|
/** The harness's name, as a bake's progress says it. */
|
|
4906
|
-
const bakedHarnessName = (harness) =>
|
|
5677
|
+
const bakedHarnessName = (harness) => HARNESS_PACKAGES[harness].bootstrap.name;
|
|
4907
5678
|
/** Runs the harness bootstrap in `session` and returns the CLI version it installed. */
|
|
4908
5679
|
async function bake(session, bootstrap) {
|
|
4909
5680
|
await (await createHarnessSandboxTemplate({
|
|
4910
5681
|
harnesses: [await bootstrap.adapter()],
|
|
4911
5682
|
sandboxConfig: { workDir: WORKSPACE_DIR }
|
|
4912
5683
|
}))?.prepare({ session });
|
|
4913
|
-
let probe = bootstrap.
|
|
5684
|
+
let probe = bootstrap.probe;
|
|
4914
5685
|
if (!probe) {
|
|
4915
5686
|
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
5687
|
if (!bin) throw new Error(`The harness bootstrap did not install the ${bootstrap.name} CLI`);
|
|
4917
5688
|
probe = `'${bin}' --version`;
|
|
4918
5689
|
}
|
|
4919
5690
|
const version = await session.run({ command: probe });
|
|
4920
|
-
if (bootstrap.
|
|
5691
|
+
if (bootstrap.probe && version.exitCode !== 0) throw new Error(`The harness bootstrap did not install ${bootstrap.cli}:\n${tail(version.stderr)}`);
|
|
4921
5692
|
return versionLabel(version.stdout.trim());
|
|
4922
5693
|
}
|
|
4923
5694
|
/**
|
|
4924
5695
|
* The image `docker({ install })` runs in: the commands on top of `parent`, tagged by the parent's
|
|
4925
|
-
*
|
|
5696
|
+
* content key and the exact list, so it's built once. Secrets and the workspace never exist here.
|
|
4926
5697
|
*/
|
|
4927
5698
|
const installLayerTag = (parent, steps) => `reeval-install:${sha256(JSON.stringify({
|
|
4928
|
-
parent: parent.
|
|
5699
|
+
parent: parent.key,
|
|
4929
5700
|
steps
|
|
4930
5701
|
})).slice(0, 16)}`;
|
|
4931
5702
|
/** The commands as one bash script: in order, from `/`, stopping at the first that fails. */
|
|
@@ -4939,37 +5710,40 @@ function installScript(steps) {
|
|
|
4939
5710
|
}
|
|
4940
5711
|
return `${lines.join("\n")}\n`;
|
|
4941
5712
|
}
|
|
4942
|
-
/**
|
|
4943
|
-
|
|
4944
|
-
|
|
4945
|
-
|
|
4946
|
-
|
|
4947
|
-
|
|
4948
|
-
"inspect",
|
|
4949
|
-
"--format",
|
|
4950
|
-
"{{.Created}}",
|
|
4951
|
-
tag
|
|
4952
|
-
], {
|
|
4953
|
-
signal,
|
|
4954
|
-
engine
|
|
4955
|
-
})).exitCode === 0) return tag;
|
|
4956
|
-
const script = installScript(steps);
|
|
5713
|
+
/**
|
|
5714
|
+
* The Dockerfile lines after `FROM` that run an install `script`: as root, but with the sandbox
|
|
5715
|
+
* user's home as HOME, so what an installer puts in `~` (uv, bun, rustup…) is where the agent
|
|
5716
|
+
* runs, and is then handed to that user.
|
|
5717
|
+
*/
|
|
5718
|
+
function installLayerLines(script) {
|
|
4957
5719
|
const encoded = Buffer.from(script).toString("base64");
|
|
4958
5720
|
const home = `$(getent passwd ${SANDBOX_USER} | cut -d: -f6)`;
|
|
4959
|
-
|
|
4960
|
-
`FROM ${parent.ref}`,
|
|
5721
|
+
return [
|
|
4961
5722
|
"USER root",
|
|
4962
5723
|
`RUN echo ${encoded} | base64 -d > /tmp/reeval-install.sh \\`,
|
|
4963
5724
|
` && if id -u ${SANDBOX_USER} >/dev/null 2>&1; then export HOME="${home}"; fi \\`,
|
|
4964
5725
|
" && bash /tmp/reeval-install.sh && rm /tmp/reeval-install.sh \\",
|
|
4965
5726
|
` && { ! id -u ${SANDBOX_USER} >/dev/null 2>&1 || find "$HOME" -xdev ! -user ${SANDBOX_USER} -exec chown -h ${SANDBOX_USER}: {} +; }`,
|
|
4966
5727
|
`WORKDIR ${SANDBOX_ROOT}`
|
|
4967
|
-
]
|
|
5728
|
+
];
|
|
5729
|
+
}
|
|
5730
|
+
/**
|
|
5731
|
+
* Builds the install layer if it's missing, or again with `force` (`reeval image build --force`,
|
|
5732
|
+
* whose rebuilt parent keeps its key). `output` gets the build's output, for a log file.
|
|
5733
|
+
*/
|
|
5734
|
+
async function buildInstallLayer(parent, steps, options = {}) {
|
|
5735
|
+
const { signal, engine } = options;
|
|
5736
|
+
const tag = installLayerTag(parent, steps);
|
|
5737
|
+
const previous = (await imageInfo(tag, engine))?.id;
|
|
5738
|
+
if (previous && !options.force) return tag;
|
|
5739
|
+
const script = installScript(steps);
|
|
5740
|
+
const dockerfile = [`FROM ${parent.ref}`, ...installLayerLines(script)].join("\n");
|
|
4968
5741
|
const build = await docker([
|
|
4969
5742
|
"build",
|
|
4970
5743
|
"--progress",
|
|
4971
5744
|
"plain",
|
|
4972
5745
|
...BUILT_BY,
|
|
5746
|
+
...keyLabel(tag),
|
|
4973
5747
|
"--tag",
|
|
4974
5748
|
tag,
|
|
4975
5749
|
"-"
|
|
@@ -4990,6 +5764,7 @@ async function buildInstallLayer(parent, steps, options = {}) {
|
|
|
4990
5764
|
engine
|
|
4991
5765
|
}, () => failed ? `install ${failed[1]} exited ${failed[2]}: ${clipLine(failed[3] ?? "")}` : null, (line) => !line.startsWith("reeval: install "));
|
|
4992
5766
|
}
|
|
5767
|
+
await replaced(tag, previous, engine);
|
|
4993
5768
|
return tag;
|
|
4994
5769
|
}
|
|
4995
5770
|
/** Where a plugin layer leaves each built plugin, by its build's hash. */
|
|
@@ -5018,8 +5793,8 @@ const pluginBuildKey = (b) => sha256(JSON.stringify({
|
|
|
5018
5793
|
cwd: b.cwd,
|
|
5019
5794
|
run: b.steps
|
|
5020
5795
|
}));
|
|
5021
|
-
/** The image a plugin build makes on `parent`: the parent's
|
|
5022
|
-
const pluginLayerTag = (parent, b) => `reeval-plugin:${parent.
|
|
5796
|
+
/** The image a plugin build makes on `parent`: the parent's content key, then the build's hash. */
|
|
5797
|
+
const pluginLayerTag = (parent, b) => `reeval-plugin:${sha256(parent.key).slice(0, 12)}-${pluginBuildKey(b).slice(0, 16)}`;
|
|
5023
5798
|
/** Where a plugin layer leaves the plugin's directory. */
|
|
5024
5799
|
const pluginBuildDir = (b) => `${PLUGIN_BUILDS_DIR}/${pluginBuildKey(b).slice(0, 16)}`;
|
|
5025
5800
|
/** The line a plugin build's script fails with when its `cwd` isn't in the source. */
|
|
@@ -5037,16 +5812,8 @@ const pluginBuildScript = (b, src) => installScript(b.steps).replaceAll("reeval:
|
|
|
5037
5812
|
async function buildPluginLayer(parent, b, options) {
|
|
5038
5813
|
const { signal, engine } = options;
|
|
5039
5814
|
const tag = pluginLayerTag(parent, b);
|
|
5040
|
-
|
|
5041
|
-
|
|
5042
|
-
"inspect",
|
|
5043
|
-
"--format",
|
|
5044
|
-
"{{.Created}}",
|
|
5045
|
-
tag
|
|
5046
|
-
], {
|
|
5047
|
-
signal,
|
|
5048
|
-
engine
|
|
5049
|
-
})).exitCode === 0) return tag;
|
|
5815
|
+
const previous = (await imageInfo(tag, engine))?.id;
|
|
5816
|
+
if (previous && !options.force) return tag;
|
|
5050
5817
|
const src = "/tmp/reeval-plugin-src";
|
|
5051
5818
|
const script = pluginBuildScript(b, src);
|
|
5052
5819
|
const encoded = Buffer.from(script).toString("base64");
|
|
@@ -5069,6 +5836,7 @@ async function buildPluginLayer(parent, b, options) {
|
|
|
5069
5836
|
"--progress",
|
|
5070
5837
|
"plain",
|
|
5071
5838
|
...BUILT_BY,
|
|
5839
|
+
...keyLabel(tag),
|
|
5072
5840
|
"--tag",
|
|
5073
5841
|
tag,
|
|
5074
5842
|
"-f",
|
|
@@ -5092,6 +5860,7 @@ async function buildPluginLayer(parent, b, options) {
|
|
|
5092
5860
|
engine
|
|
5093
5861
|
}, () => missing ? noCwd(b.cwd).slice(8) : failed ? `build ${failed[1]} exited ${failed[2]}: ${clipLine(failed[3] ?? "")}` : null, (line) => !line.startsWith("reeval: build "));
|
|
5094
5862
|
}
|
|
5863
|
+
await replaced(tag, previous, engine);
|
|
5095
5864
|
return tag;
|
|
5096
5865
|
}
|
|
5097
5866
|
/** The build arg a Dockerfile can start `FROM` to layer on reeval's sandbox image. */
|
|
@@ -5101,12 +5870,13 @@ const usesReevalBase = (dockerfile) => new RegExp(`\\$\\{?${REEVAL_BASE_ARG}\\b`
|
|
|
5101
5870
|
/**
|
|
5102
5871
|
* The tag of a `docker({ dockerfile })` build for a harness: a hash of the Dockerfile, every file
|
|
5103
5872
|
* of its build context (its directory, less `.dockerignore`) and, for a Dockerfile `FROM
|
|
5104
|
-
* ${REEVAL_BASE}`, the
|
|
5105
|
-
*
|
|
5873
|
+
* ${REEVAL_BASE}`, the {@link reevalImageKey} of the harness's image it names, so an edit to any of
|
|
5874
|
+
* them, or a new reeval base, builds anew, and the same files give the same tag on any machine. What
|
|
5875
|
+
* its other bases' tags name is in its key ({@link dockerfileKey}), not its tag.
|
|
5106
5876
|
*/
|
|
5107
|
-
function dockerfileTag(dockerfile, harness
|
|
5877
|
+
function dockerfileTag(dockerfile, harness) {
|
|
5108
5878
|
const context = dirname(dockerfile);
|
|
5109
|
-
const base = usesReevalBase(dockerfile) ?
|
|
5879
|
+
const base = usesReevalBase(dockerfile) ? reevalImageKey(harness) : "";
|
|
5110
5880
|
const hash = createHash("sha256").update(`${REEVAL_BASE_ARG}=${base}\0`);
|
|
5111
5881
|
for (const path of contextFiles(context, dockerfile)) {
|
|
5112
5882
|
const full = join(context, path);
|
|
@@ -5122,14 +5892,75 @@ function dockerfileTag(dockerfile, harness, reevalBase = null) {
|
|
|
5122
5892
|
};
|
|
5123
5893
|
}
|
|
5124
5894
|
/**
|
|
5895
|
+
* The images a Dockerfile's `FROM`, `COPY --from` and `--mount=…,from=` name by a tag that can
|
|
5896
|
+
* move: not `${REEVAL_BASE}`, an earlier stage, `scratch` or a digest-pinned image. `opaque` when
|
|
5897
|
+
* one names an image through any other build arg, which only the build resolves.
|
|
5898
|
+
*/
|
|
5899
|
+
function dockerfileBases(dockerfile) {
|
|
5900
|
+
const stages = /* @__PURE__ */ new Set();
|
|
5901
|
+
const bases = [];
|
|
5902
|
+
let opaque = false;
|
|
5903
|
+
const reevalBase = new RegExp(`^\\$\\{?${REEVAL_BASE_ARG}\\}?$`);
|
|
5904
|
+
const add = (image) => {
|
|
5905
|
+
const name = image.toLowerCase();
|
|
5906
|
+
if (image.includes("$")) {
|
|
5907
|
+
if (!reevalBase.test(image)) opaque = true;
|
|
5908
|
+
return;
|
|
5909
|
+
}
|
|
5910
|
+
if (stages.has(name) || name === "scratch" || /^\d+$/.test(name)) return;
|
|
5911
|
+
if (/@sha256:[0-9a-f]{64}$/.test(image) || bases.includes(image)) return;
|
|
5912
|
+
bases.push(image);
|
|
5913
|
+
};
|
|
5914
|
+
const text = readFileSync(dockerfile, "utf8").replace(/\\[ \t]*\r?\n/g, " ");
|
|
5915
|
+
for (const line of text.split("\n")) {
|
|
5916
|
+
if (/^\s*#/.test(line)) continue;
|
|
5917
|
+
const from = /^\s*FROM\s+(?:--platform=\S+\s+)?(\S+)(?:\s+AS\s+(\S+))?/i.exec(line);
|
|
5918
|
+
if (from?.[1]) {
|
|
5919
|
+
add(from[1]);
|
|
5920
|
+
if (from[2]) stages.add(from[2].toLowerCase());
|
|
5921
|
+
}
|
|
5922
|
+
if (!/^\s*(?:COPY|ADD|RUN)\s/i.test(line)) continue;
|
|
5923
|
+
for (const m of line.matchAll(/(?:^|\s)--from=(\S+)/gi)) if (m[1]) add(m[1]);
|
|
5924
|
+
for (const m of line.matchAll(/--mount=\S*?\bfrom=([^,\s]+)/gi)) if (m[1]) add(m[1]);
|
|
5925
|
+
}
|
|
5926
|
+
return {
|
|
5927
|
+
bases,
|
|
5928
|
+
opaque
|
|
5929
|
+
};
|
|
5930
|
+
}
|
|
5931
|
+
/**
|
|
5932
|
+
* The image a Dockerfile's last stage starts from, through the stages it names, as its `FROM`
|
|
5933
|
+
* writes it: `${REEVAL_BASE}` for one built on the harness's image. The built image inherits its
|
|
5934
|
+
* labels, so this says whether it already has a harness's CLI. Null with no `FROM`.
|
|
5935
|
+
*/
|
|
5936
|
+
function dockerfileFinalBase(dockerfile) {
|
|
5937
|
+
const stages = /* @__PURE__ */ new Map();
|
|
5938
|
+
let last = null;
|
|
5939
|
+
const text = readFileSync(dockerfile, "utf8").replace(/\\[ \t]*\r?\n/g, " ");
|
|
5940
|
+
for (const line of text.split("\n")) {
|
|
5941
|
+
if (/^\s*#/.test(line)) continue;
|
|
5942
|
+
const from = /^\s*FROM\s+(?:--platform=\S+\s+)?(\S+)(?:\s+AS\s+(\S+))?/i.exec(line);
|
|
5943
|
+
if (!from?.[1]) continue;
|
|
5944
|
+
last = stages.get(from[1].toLowerCase()) ?? from[1];
|
|
5945
|
+
if (from[2]) stages.set(from[2].toLowerCase(), last);
|
|
5946
|
+
}
|
|
5947
|
+
return last;
|
|
5948
|
+
}
|
|
5949
|
+
/**
|
|
5950
|
+
* A Dockerfile image's content key: its tag, plus the digest each of its {@link dockerfileBases}
|
|
5951
|
+
* named when it was built, so a base that moved upstream is another image. One whose bases can't all
|
|
5952
|
+
* be named this way is keyed on its local image id instead ({@link localKey}).
|
|
5953
|
+
*/
|
|
5954
|
+
const dockerfileKey = (tag, bases) => bases.length ? `${tag}+${bases.map((b) => `${b.ref}@${b.digest}`).join(",")}` : tag;
|
|
5955
|
+
/**
|
|
5125
5956
|
* 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
|
|
5957
|
+
* its directory, with `REEVAL_BASE` set to the harness's sandbox image.
|
|
5127
5958
|
* Rebuilds even when the tag exists with `force`, as `reeval image build` does, and then removes the
|
|
5128
5959
|
* image the tag pointed at before. `name` is the path failures name.
|
|
5129
5960
|
*/
|
|
5130
5961
|
async function buildDockerfile(dockerfile, options) {
|
|
5131
5962
|
const { harness, signal, engine } = options;
|
|
5132
|
-
const { tag } = dockerfileTag(dockerfile, harness
|
|
5963
|
+
const { tag } = dockerfileTag(dockerfile, harness);
|
|
5133
5964
|
const previous = (await imageInfo(tag, engine))?.id;
|
|
5134
5965
|
if (previous && !options.force) return tag;
|
|
5135
5966
|
const build = await docker([
|
|
@@ -5137,6 +5968,7 @@ async function buildDockerfile(dockerfile, options) {
|
|
|
5137
5968
|
"--progress",
|
|
5138
5969
|
"plain",
|
|
5139
5970
|
...BUILT_BY,
|
|
5971
|
+
...keyLabel(options.key ?? tag),
|
|
5140
5972
|
...options.pull ? ["--pull"] : [],
|
|
5141
5973
|
"--file",
|
|
5142
5974
|
dockerfile,
|
|
@@ -5168,301 +6000,610 @@ async function buildDockerfile(dockerfile, options) {
|
|
|
5168
6000
|
* and logs when it answers `initialize` (see its header). It runs in any sandbox with `node`.
|
|
5169
6001
|
*/
|
|
5170
6002
|
const MCP_TIMER = fileURLToPath(ownFileURL("bin/mcp-timer.cjs"));
|
|
5171
|
-
// ../sandbox-docker/src/
|
|
6003
|
+
// ../sandbox-docker/src/registry.ts
|
|
6004
|
+
/**
|
|
6005
|
+
* What's wrong with a registry prefix, or null: a registry host (with an optional port) and an
|
|
6006
|
+
* optional path, as `docker push` names one, without a scheme, tag or digest.
|
|
6007
|
+
*/
|
|
6008
|
+
function registryProblem(registry) {
|
|
6009
|
+
if (/^[a-z0-9.-]+(:\d+)?(\/[a-z0-9]+([._-]+[a-z0-9]+)*)*\/?$/.test(registry)) return null;
|
|
6010
|
+
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)})`;
|
|
6011
|
+
}
|
|
6012
|
+
/**
|
|
6013
|
+
* Where a layer goes in `registry`: its repository under the prefix, with its tag, plus its content
|
|
6014
|
+
* key's hash where the tag alone doesn't pin what's in it (reeval's own image and a `from` image),
|
|
6015
|
+
* and the platform, so one machine's push is another's pull only when they'd have built the same
|
|
6016
|
+
* thing for the same architecture.
|
|
6017
|
+
*/
|
|
6018
|
+
function registryRef(registry, layer, platform = PLATFORM) {
|
|
6019
|
+
const at = layer.ref.lastIndexOf(":");
|
|
6020
|
+
const repository = layer.ref.slice(0, at);
|
|
6021
|
+
const tag = layer.ref.slice(at + 1);
|
|
6022
|
+
const pinned = layer.key === layer.ref ? tag : `${tag}-${createHash("sha256").update(layer.key).digest("hex").slice(0, 12)}`;
|
|
6023
|
+
return `${registry.replace(/\/+$/, "")}/${repository}:${pinned}-${platform.replaceAll("/", "-")}`;
|
|
6024
|
+
}
|
|
6025
|
+
const firstLine = (stderr) => stderr.trim().split("\n").filter(Boolean).at(-1)?.replace(/^Error(?: response from daemon)?: /, "") ?? "";
|
|
6026
|
+
/**
|
|
6027
|
+
* The platform the engine builds and pulls for, as its server says it (a remote `DOCKER_HOST`, or
|
|
6028
|
+
* x64 Node under Rosetta, can differ from this process's), or {@link PLATFORM} when it doesn't say.
|
|
6029
|
+
*/
|
|
6030
|
+
async function enginePlatform(engine = "docker") {
|
|
6031
|
+
const r = await docker(engine === "podman" ? [
|
|
6032
|
+
"info",
|
|
6033
|
+
"--format",
|
|
6034
|
+
"{{.Host.OS}}/{{.Host.Arch}}"
|
|
6035
|
+
] : [
|
|
6036
|
+
"version",
|
|
6037
|
+
"--format",
|
|
6038
|
+
"{{.Server.Os}}/{{.Server.Arch}}"
|
|
6039
|
+
], { engine }).catch(() => null);
|
|
6040
|
+
const said = r?.exitCode === 0 ? r.stdout.toString("utf8").trim() : "";
|
|
6041
|
+
return /^[a-z0-9]+\/[a-z0-9]+$/.test(said) ? said : PLATFORM;
|
|
6042
|
+
}
|
|
6043
|
+
/**
|
|
6044
|
+
* Pulls `layer` from `registry` and tags it as its local ref, once it's checked: its
|
|
6045
|
+
* {@link LABEL.key} must be the layer's key and its platform the engine's ({@link enginePlatform}). `pulled: false` with
|
|
6046
|
+
* the reason when the registry doesn't have it, can't be reached or has another image under the
|
|
6047
|
+
* ref: the caller builds it instead. The registry is otherwise trusted: anyone who can push to it
|
|
6048
|
+
* chooses what a matching tag holds.
|
|
6049
|
+
*/
|
|
6050
|
+
async function pullLayer(registry, layer, options = {}) {
|
|
6051
|
+
const { engine, signal } = options;
|
|
6052
|
+
const platform = await enginePlatform(engine);
|
|
6053
|
+
const remote = registryRef(registry, layer, platform);
|
|
6054
|
+
const pull = await docker([
|
|
6055
|
+
"pull",
|
|
6056
|
+
"--quiet",
|
|
6057
|
+
remote
|
|
6058
|
+
], {
|
|
6059
|
+
engine,
|
|
6060
|
+
signal
|
|
6061
|
+
}).catch((error) => ({
|
|
6062
|
+
exitCode: 1,
|
|
6063
|
+
stderr: error.message
|
|
6064
|
+
}));
|
|
6065
|
+
if (pull.exitCode !== 0) return {
|
|
6066
|
+
pulled: false,
|
|
6067
|
+
remote,
|
|
6068
|
+
reason: firstLine(pull.stderr) || `exit ${pull.exitCode}`
|
|
6069
|
+
};
|
|
6070
|
+
try {
|
|
6071
|
+
const info = await imageInfo(remote, engine).catch(() => null);
|
|
6072
|
+
const key = info?.labels[LABEL$1.key];
|
|
6073
|
+
if (key !== layer.key) return {
|
|
6074
|
+
pulled: false,
|
|
6075
|
+
remote,
|
|
6076
|
+
reason: key ? `its ${LABEL$1.key} label is ${key}, not ${layer.key}` : `it has no ${LABEL$1.key} label`
|
|
6077
|
+
};
|
|
6078
|
+
if (info?.platform !== platform) return {
|
|
6079
|
+
pulled: false,
|
|
6080
|
+
remote,
|
|
6081
|
+
reason: `it's for ${info?.platform ?? "an unknown platform"}, not ${platform}`
|
|
6082
|
+
};
|
|
6083
|
+
const tag = await docker([
|
|
6084
|
+
"tag",
|
|
6085
|
+
remote,
|
|
6086
|
+
layer.ref
|
|
6087
|
+
], {
|
|
6088
|
+
engine,
|
|
6089
|
+
signal
|
|
6090
|
+
});
|
|
6091
|
+
if (tag.exitCode !== 0) return {
|
|
6092
|
+
pulled: false,
|
|
6093
|
+
remote,
|
|
6094
|
+
reason: firstLine(tag.stderr) || `exit ${tag.exitCode}`
|
|
6095
|
+
};
|
|
6096
|
+
return {
|
|
6097
|
+
pulled: true,
|
|
6098
|
+
remote
|
|
6099
|
+
};
|
|
6100
|
+
} finally {
|
|
6101
|
+
await docker([
|
|
6102
|
+
"image",
|
|
6103
|
+
"rm",
|
|
6104
|
+
remote
|
|
6105
|
+
], { engine }).catch(() => {});
|
|
6106
|
+
}
|
|
6107
|
+
}
|
|
6108
|
+
/**
|
|
6109
|
+
* Pushes `layer` to `registry` under {@link registryRef} for the platform the image says it's for
|
|
6110
|
+
* (or the engine's), and returns that ref.
|
|
6111
|
+
*/
|
|
6112
|
+
async function pushLayer(registry, layer, options = {}) {
|
|
6113
|
+
const { engine, signal } = options;
|
|
6114
|
+
const { bin } = engineSpec(engine);
|
|
6115
|
+
const own = (await imageInfo(layer.ref, engine).catch(() => null))?.platform;
|
|
6116
|
+
const remote = registryRef(registry, layer, own ?? await enginePlatform(engine));
|
|
6117
|
+
const tag = await docker([
|
|
6118
|
+
"tag",
|
|
6119
|
+
layer.ref,
|
|
6120
|
+
remote
|
|
6121
|
+
], {
|
|
6122
|
+
engine,
|
|
6123
|
+
signal
|
|
6124
|
+
});
|
|
6125
|
+
if (tag.exitCode !== 0) throw new Error(`${bin} tag ${layer.ref} ${remote} failed: ${firstLine(tag.stderr)}`);
|
|
6126
|
+
try {
|
|
6127
|
+
const push = await docker(["push", remote], {
|
|
6128
|
+
engine,
|
|
6129
|
+
signal
|
|
6130
|
+
});
|
|
6131
|
+
if (push.exitCode !== 0) throw new Error(`${bin} push ${remote} failed: ${firstLine(push.stderr)}`);
|
|
6132
|
+
} finally {
|
|
6133
|
+
await docker([
|
|
6134
|
+
"image",
|
|
6135
|
+
"rm",
|
|
6136
|
+
remote
|
|
6137
|
+
], { engine }).catch(() => {});
|
|
6138
|
+
}
|
|
6139
|
+
return remote;
|
|
6140
|
+
}
|
|
6141
|
+
// ../sandbox-docker/src/registry-api.ts
|
|
6142
|
+
const DIGEST = /^sha256:[0-9a-f]{64}$/;
|
|
6143
|
+
const LABEL = "[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?";
|
|
6144
|
+
const HOST = new RegExp(`^(?:${LABEL}(?:\\.${LABEL})*|\\[[0-9a-fA-F:]+\\])(?::\\d+)?$`);
|
|
6145
|
+
/**
|
|
6146
|
+
* The manifest types asked for, an index first: the digest is then the top-level manifest's, as
|
|
6147
|
+
* `docker buildx imagetools inspect` reports it and as `fromImageKey` keys a `from` image.
|
|
6148
|
+
*/
|
|
6149
|
+
const ACCEPT = [
|
|
6150
|
+
"application/vnd.oci.image.index.v1+json",
|
|
6151
|
+
"application/vnd.docker.distribution.manifest.list.v2+json",
|
|
6152
|
+
"application/vnd.oci.image.manifest.v1+json",
|
|
6153
|
+
"application/vnd.docker.distribution.manifest.v2+json"
|
|
6154
|
+
].join(", ");
|
|
6155
|
+
/**
|
|
6156
|
+
* `ref` as the registry API addresses it, normalized as Docker does: no registry is Docker Hub, a
|
|
6157
|
+
* one-part Docker Hub name is under `library/`, and no tag is `latest`. Null when it isn't a
|
|
6158
|
+
* reference.
|
|
6159
|
+
*/
|
|
6160
|
+
function parseImageRef(ref) {
|
|
6161
|
+
const at = ref.indexOf("@");
|
|
6162
|
+
const digest = at === -1 ? null : ref.slice(at + 1);
|
|
6163
|
+
if (digest !== null && !DIGEST.test(digest)) return null;
|
|
6164
|
+
let name = at === -1 ? ref : ref.slice(0, at);
|
|
6165
|
+
const slash = name.indexOf("/");
|
|
6166
|
+
const first = slash === -1 ? "" : name.slice(0, slash);
|
|
6167
|
+
let host = "docker.io";
|
|
6168
|
+
if (first && (first.includes(".") || first.includes(":") || first === "localhost")) {
|
|
6169
|
+
if (!HOST.test(first)) return null;
|
|
6170
|
+
host = first;
|
|
6171
|
+
name = name.slice(slash + 1);
|
|
6172
|
+
}
|
|
6173
|
+
const colon = name.lastIndexOf(":");
|
|
6174
|
+
const tag = colon === -1 ? null : name.slice(colon + 1);
|
|
6175
|
+
if (colon !== -1) name = name.slice(0, colon);
|
|
6176
|
+
if (tag !== null && !/^[\w][\w.-]{0,127}$/.test(tag)) return null;
|
|
6177
|
+
if (!/^[a-z0-9]+(?:(?:[._]|__|-+)[a-z0-9]+)*(?:\/[a-z0-9]+(?:(?:[._]|__|-+)[a-z0-9]+)*)*$/.test(name)) return null;
|
|
6178
|
+
if (host === "docker.io" || host === "index.docker.io") {
|
|
6179
|
+
host = "registry-1.docker.io";
|
|
6180
|
+
if (!name.includes("/")) name = `library/${name}`;
|
|
6181
|
+
}
|
|
6182
|
+
return {
|
|
6183
|
+
host,
|
|
6184
|
+
repository: name,
|
|
6185
|
+
reference: digest ?? tag ?? "latest"
|
|
6186
|
+
};
|
|
6187
|
+
}
|
|
6188
|
+
const loopback = (host) => /^(localhost|127\.\d+\.\d+\.\d+|\[::1\])(:\d+)?$/.test(host);
|
|
6189
|
+
/** A loopback registry speaks plain HTTP, as Docker allows without an insecure-registries entry. */
|
|
6190
|
+
const scheme = (host) => loopback(host) ? "http" : "https";
|
|
6191
|
+
/** The parameters of a `WWW-Authenticate` challenge: its scheme, lowercase, and its fields. */
|
|
6192
|
+
function challenge(header) {
|
|
6193
|
+
const match = /^\s*(\w+)\s*(.*)$/s.exec(header ?? "");
|
|
6194
|
+
const params = {};
|
|
6195
|
+
for (const [, key, quoted, bare] of (match?.[2] ?? "").matchAll(/(\w+)=(?:"((?:[^"\\]|\\.)*)"|([^\s,]*))/g)) if (key) params[key.toLowerCase()] = quoted?.replace(/\\(.)/g, "$1") ?? bare ?? "";
|
|
6196
|
+
return {
|
|
6197
|
+
scheme: match?.[1]?.toLowerCase() ?? "",
|
|
6198
|
+
params
|
|
6199
|
+
};
|
|
6200
|
+
}
|
|
6201
|
+
const basic = (c) => `Basic ${Buffer.from(`${c.username}:${c.password}`).toString("base64")}`;
|
|
6202
|
+
/**
|
|
6203
|
+
* What `ref` names in its registry now, without Docker: the digest of its top-level manifest (an
|
|
6204
|
+
* index for a multi-platform image), through the registry HTTP API. It follows the registry's
|
|
6205
|
+
* token challenge, anonymously or with `credential`'s login. A reference pinned by digest is that
|
|
6206
|
+
* digest. `error` when it doesn't resolve: no such image, access refused or no network.
|
|
6207
|
+
*/
|
|
6208
|
+
async function registryDigest(ref, options = {}) {
|
|
6209
|
+
const parsed = parseImageRef(ref);
|
|
6210
|
+
if (!parsed) return { error: `${ref} isn't an image reference` };
|
|
6211
|
+
if (DIGEST.test(parsed.reference)) return { digest: parsed.reference };
|
|
6212
|
+
const { host, repository, reference } = parsed;
|
|
6213
|
+
const fetchFn = options.fetch ?? fetch;
|
|
6214
|
+
const signal = AbortSignal.any([AbortSignal.timeout(options.timeoutMs ?? 15e3), ...options.signal ? [options.signal] : []]);
|
|
6215
|
+
const login = options.credential?.(host);
|
|
6216
|
+
const url = `${scheme(host)}://${host}/v2/${repository}/manifests/${encodeURIComponent(reference)}`;
|
|
6217
|
+
const ask = (method, authorization) => fetchFn(url, {
|
|
6218
|
+
method,
|
|
6219
|
+
headers: {
|
|
6220
|
+
accept: ACCEPT,
|
|
6221
|
+
...authorization ? { authorization } : {}
|
|
6222
|
+
},
|
|
6223
|
+
signal
|
|
6224
|
+
});
|
|
6225
|
+
try {
|
|
6226
|
+
let authorization = login && "token" in login ? `Bearer ${login.token}` : null;
|
|
6227
|
+
let response = await ask("HEAD", authorization);
|
|
6228
|
+
if (response.status === 401 && !(login && "token" in login)) {
|
|
6229
|
+
const asked = challenge(response.headers.get("www-authenticate"));
|
|
6230
|
+
if (asked.scheme === "bearer" && asked.params.realm) {
|
|
6231
|
+
const token = await bearerToken(asked.params, repository, login, fetchFn, signal);
|
|
6232
|
+
if ("error" in token) return { error: `${host} refused a token for ${repository}: ${token.error}` };
|
|
6233
|
+
authorization = `Bearer ${token.token}`;
|
|
6234
|
+
} else if (asked.scheme === "basic" && login) authorization = basic(login);
|
|
6235
|
+
if (authorization) response = await ask("HEAD", authorization);
|
|
6236
|
+
}
|
|
6237
|
+
if (response.ok) {
|
|
6238
|
+
const said = response.headers.get("docker-content-digest");
|
|
6239
|
+
if (said && DIGEST.test(said)) return { digest: said };
|
|
6240
|
+
const body = await ask("GET", authorization);
|
|
6241
|
+
if (body.ok) {
|
|
6242
|
+
const header = body.headers.get("docker-content-digest");
|
|
6243
|
+
if (header && DIGEST.test(header)) return { digest: header };
|
|
6244
|
+
const bytes = Buffer.from(await body.arrayBuffer());
|
|
6245
|
+
return { digest: `sha256:${createHash("sha256").update(bytes).digest("hex")}` };
|
|
6246
|
+
}
|
|
6247
|
+
response = body;
|
|
6248
|
+
}
|
|
6249
|
+
if (response.status === 401 || response.status === 403) return { error: `${host} refused ${repository} (${response.status}): it doesn't exist, or it's private and needs a registry login` };
|
|
6250
|
+
if (response.status === 404) return { error: `${ref} isn't in ${host}` };
|
|
6251
|
+
return { error: `${host} answered ${response.status} for ${ref}` };
|
|
6252
|
+
} catch (cause) {
|
|
6253
|
+
if (options.signal?.aborted) throw cause;
|
|
6254
|
+
return { error: `couldn't reach ${host}: ${cause instanceof Error ? cause.cause instanceof Error ? cause.cause.message : cause.message : String(cause)}` };
|
|
6255
|
+
}
|
|
6256
|
+
}
|
|
6257
|
+
async function bearerToken(params, repository, login, fetchFn, signal) {
|
|
6258
|
+
const url = new URL(params.realm);
|
|
6259
|
+
const protectedRealm = url.protocol === "https:" || loopback(url.host);
|
|
6260
|
+
if (params.service) url.searchParams.set("service", params.service);
|
|
6261
|
+
url.searchParams.set("scope", params.scope ?? `repository:${repository}:pull`);
|
|
6262
|
+
const response = await fetchFn(url, {
|
|
6263
|
+
headers: login && "username" in login && protectedRealm ? { authorization: basic(login) } : {},
|
|
6264
|
+
signal
|
|
6265
|
+
});
|
|
6266
|
+
if (!response.ok) return { error: `${response.status}` };
|
|
6267
|
+
const body = await response.json().catch(() => null);
|
|
6268
|
+
const token = body?.token ?? body?.access_token;
|
|
6269
|
+
return typeof token === "string" && token ? { token } : { error: "no token in the answer" };
|
|
6270
|
+
}
|
|
6271
|
+
// ../sandbox-docker/src/shells.ts
|
|
5172
6272
|
const SYSTEM_PATH = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin";
|
|
5173
|
-
const EXEC_MARKER = "REEVAL_EXEC_ID";
|
|
5174
6273
|
const EXEC_UMASK = "umask 022";
|
|
5175
|
-
|
|
5176
|
-
const SSH_FAILED = 255;
|
|
6274
|
+
const EXEC_MARKER = "REEVAL_EXEC_ID";
|
|
5177
6275
|
/** `NAME=value\0` for each variable, as the remote reader takes them on stdin. */
|
|
5178
6276
|
const envStream = (env) => Object.entries(env).map(([k, v]) => `${k}=${v}\0`).join("");
|
|
5179
6277
|
/**
|
|
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
|
|
6278
|
+
* Runs `$2` with bash in `$1` as the sandbox user, after exporting the variables stdin carries,
|
|
6279
|
+
* in a process group it leads. The command itself gets no stdin, as a `docker exec` without
|
|
6280
|
+
* `--interactive` would.
|
|
5182
6281
|
*/
|
|
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`;
|
|
6282
|
+
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
6283
|
/**
|
|
5185
|
-
*
|
|
5186
|
-
*
|
|
5187
|
-
*
|
|
5188
|
-
*
|
|
6284
|
+
* The Linux profile: the login user has passwordless `sudo` or is root, the agent's commands run as
|
|
6285
|
+
* {@link SANDBOX_USER} with only `user`'s variables, and reeval's own run as root in
|
|
6286
|
+
* {@link SANDBOX_STATE}. Each command carries a marker in its environment, which `kill` finds in
|
|
6287
|
+
* `/proc`. `remote` is the host argv that runs one command line as the login user (`ssh`).
|
|
5189
6288
|
*/
|
|
5190
|
-
|
|
5191
|
-
const
|
|
5192
|
-
const
|
|
5193
|
-
|
|
5194
|
-
|
|
5195
|
-
|
|
5196
|
-
|
|
5197
|
-
|
|
5198
|
-
|
|
5199
|
-
|
|
5200
|
-
|
|
5201
|
-
|
|
5202
|
-
|
|
5203
|
-
|
|
5204
|
-
|
|
5205
|
-
|
|
5206
|
-
|
|
5207
|
-
|
|
6289
|
+
function linuxShell(o) {
|
|
6290
|
+
const sandboxUser = o.layout?.user ?? "reeval";
|
|
6291
|
+
const stateDir = o.layout?.state ?? "/var/lib/reeval";
|
|
6292
|
+
const seenHome = o.user.HOME;
|
|
6293
|
+
const bind = o.layout && seenHome && o.layout.home !== seenHome ? o.layout.home : void 0;
|
|
6294
|
+
const marker = (exec) => `${o.id}-${exec}`;
|
|
6295
|
+
const sudo = o.loginRoot ? "" : "sudo -n -- ";
|
|
6296
|
+
const setpriv = `setpriv --reuid=${sandboxUser} --regid=${sandboxUser} --init-groups --`;
|
|
6297
|
+
const asSandboxUser = (command) => bind ? `${sudo}unshare --mount --propagation private /bin/sh -c ${shellQuote(`mount --bind ${shellQuote(bind)} ${shellQuote(seenHome ?? "")} && exec ${setpriv} ${command}`)}` : o.loginRoot ? `${setpriv} env -i HOME=${shellQuote(seenHome ?? "/")} PATH=${SYSTEM_PATH} ${command}` : `sudo -n -H -u ${sandboxUser} -- ${command}`;
|
|
6298
|
+
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)}`);
|
|
6299
|
+
const asRoot = (command, mark) => `${sudo}env -i PATH=${SYSTEM_PATH} HOME=/root${mark ? ` ${EXEC_MARKER}=${mark}` : ""} /bin/sh -c ${shellQuote(`cd ${stateDir} || exit 1; ${EXEC_UMASK}; ${command}`)}`;
|
|
6300
|
+
/**
|
|
6301
|
+
* Killing the host's program leaves the command running on the machine, so kill what has its
|
|
6302
|
+
* marker, and the process group of each: a process that cleared its environment (`env -i`)
|
|
6303
|
+
* keeps the group of the command that started it.
|
|
6304
|
+
*/
|
|
6305
|
+
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`);
|
|
6306
|
+
return {
|
|
6307
|
+
run: (argv, r) => o.run(argv, {
|
|
6308
|
+
...r,
|
|
6309
|
+
signal: r.signal ?? o.signal
|
|
6310
|
+
}),
|
|
6311
|
+
user: ({ command, cwd, env, exec }) => ({
|
|
6312
|
+
argv: o.remote(asUser(cwd, command)),
|
|
6313
|
+
input: envStream({
|
|
6314
|
+
...env,
|
|
6315
|
+
[EXEC_MARKER]: marker(exec)
|
|
6316
|
+
})
|
|
6317
|
+
}),
|
|
6318
|
+
privileged: ({ command, exec }) => ({
|
|
6319
|
+
argv: o.remote(asRoot(command, marker(exec))),
|
|
6320
|
+
input: ""
|
|
6321
|
+
}),
|
|
6322
|
+
kill: (exec) => ({
|
|
6323
|
+
argv: o.remote(killExec(marker(exec))),
|
|
6324
|
+
input: ""
|
|
6325
|
+
}),
|
|
6326
|
+
direct: (argv) => o.remote(asSandboxUser(argv.map(shellQuote).join(" ")))
|
|
5208
6327
|
};
|
|
5209
|
-
|
|
5210
|
-
|
|
5211
|
-
|
|
5212
|
-
|
|
5213
|
-
|
|
5214
|
-
|
|
5215
|
-
|
|
5216
|
-
|
|
5217
|
-
|
|
5218
|
-
|
|
5219
|
-
|
|
5220
|
-
|
|
5221
|
-
|
|
5222
|
-
|
|
5223
|
-
|
|
5224
|
-
|
|
5225
|
-
|
|
5226
|
-
|
|
5227
|
-
|
|
5228
|
-
|
|
5229
|
-
|
|
5230
|
-
|
|
5231
|
-
|
|
5232
|
-
|
|
5233
|
-
|
|
5234
|
-
|
|
5235
|
-
|
|
5236
|
-
|
|
5237
|
-
|
|
5238
|
-
|
|
5239
|
-
|
|
5240
|
-
|
|
5241
|
-
|
|
5242
|
-
|
|
5243
|
-
|
|
5244
|
-
|
|
5245
|
-
|
|
5246
|
-
|
|
5247
|
-
|
|
5248
|
-
|
|
5249
|
-
|
|
5250
|
-
|
|
5251
|
-
|
|
5252
|
-
|
|
5253
|
-
|
|
5254
|
-
|
|
5255
|
-
|
|
5256
|
-
|
|
5257
|
-
|
|
5258
|
-
|
|
5259
|
-
|
|
5260
|
-
|
|
5261
|
-
|
|
5262
|
-
|
|
5263
|
-
|
|
5264
|
-
|
|
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
|
|
6328
|
+
}
|
|
6329
|
+
const NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
6330
|
+
/**
|
|
6331
|
+
* A command as one script on stdin, so variables (and what a secret holds) never reach a
|
|
6332
|
+
* command line on the host or in the machine. The shell records its pid for {@link killTree}.
|
|
6333
|
+
*/
|
|
6334
|
+
function execScript(o) {
|
|
6335
|
+
const exports = Object.entries(o.env).filter(([k]) => NAME.test(k)).map(([k, v]) => `export ${k}=${shellQuote(v)}`);
|
|
6336
|
+
return [[
|
|
6337
|
+
`echo $$ > ${shellQuote(o.pidFile)}`,
|
|
6338
|
+
`export PATH=${shellQuote(o.path)}:"$PATH"`,
|
|
6339
|
+
...exports,
|
|
6340
|
+
"umask 022",
|
|
6341
|
+
`cd ${shellQuote(o.cwd)} || exit 1`
|
|
6342
|
+
].join("; "), o.command].join("\n");
|
|
6343
|
+
}
|
|
6344
|
+
/**
|
|
6345
|
+
* Reads the script {@link execScript} wrote from stdin and runs it, with stdin then empty, in a
|
|
6346
|
+
* process group its shell leads, so the pid the script records is also the group's.
|
|
6347
|
+
*/
|
|
6348
|
+
const RUN_SCRIPT = [
|
|
6349
|
+
"/usr/bin/perl",
|
|
6350
|
+
"-e",
|
|
6351
|
+
"setpgrp(0, 0); exec @ARGV",
|
|
6352
|
+
"/bin/bash",
|
|
6353
|
+
"-c",
|
|
6354
|
+
"s=$(cat); eval \"$s\" </dev/null"
|
|
6355
|
+
];
|
|
6356
|
+
/**
|
|
6357
|
+
* Kills the command whose shell wrote `pidFile` and everything it started: macOS has no `/proc`
|
|
6358
|
+
* to find them by a marker, so it stops and kills the shell's process group, which keeps a
|
|
6359
|
+
* process its parent left behind (a double fork's), and walks the tree from the shell for one
|
|
6360
|
+
* that moved to a group of its own (a job-control shell's job). Anything but a pid above 1 in the
|
|
6361
|
+
* file kills nothing: `kill -9 -1` is every process the user can signal.
|
|
6362
|
+
*/
|
|
6363
|
+
const killTree = (pidFile) => `f=${shellQuote(pidFile)}; [ -f "$f" ] || exit 0; p=$(cat "$f")
|
|
6364
|
+
case $p in ''|*[!0-9]*) rm -f "$f"; exit 0 ;; esac; [ "$p" -gt 1 ] || { rm -f "$f"; exit 0; }
|
|
6365
|
+
tree() { kill -STOP "$1" 2>/dev/null; for c in $(pgrep -P "$1"); do tree "$c"; done; kill -9 "$1" 2>/dev/null; }
|
|
6366
|
+
kill -STOP "-$p" 2>/dev/null; tree "$p"; kill -9 "-$p" 2>/dev/null; rm -f "$f"; true`;
|
|
6367
|
+
/**
|
|
6368
|
+
* The darwin profile: macOS has no `useradd`, so every command, reeval's own included, runs as
|
|
6369
|
+
* the image's user, reeval's in `stateDir`. Each gets its variables in a script on stdin
|
|
6370
|
+
* ({@link execScript}) and writes its pid there, which `kill` walks the process tree from.
|
|
6371
|
+
* `guest` is the host argv that runs an argv on the machine with its stdin piped.
|
|
6372
|
+
*/
|
|
6373
|
+
function darwinShell(o) {
|
|
6374
|
+
const pidFile = (exec) => posix.join(o.stateDir, `exec-${exec}.pid`);
|
|
6375
|
+
const script = (command, cwd, env, exec) => ({
|
|
6376
|
+
argv: o.guest(RUN_SCRIPT),
|
|
6377
|
+
input: execScript({
|
|
6378
|
+
command,
|
|
6379
|
+
cwd,
|
|
6380
|
+
env,
|
|
6381
|
+
pidFile: pidFile(exec),
|
|
6382
|
+
path: o.path
|
|
6383
|
+
})
|
|
5297
6384
|
});
|
|
6385
|
+
return {
|
|
6386
|
+
run: o.run,
|
|
6387
|
+
user: ({ command, cwd, env, exec }) => script(command, cwd, env, exec),
|
|
6388
|
+
privileged: ({ command, exec }) => script(command, o.stateDir, {}, exec),
|
|
6389
|
+
kill: (exec) => ({
|
|
6390
|
+
argv: o.guest([
|
|
6391
|
+
"/bin/sh",
|
|
6392
|
+
"-c",
|
|
6393
|
+
killTree(pidFile(exec))
|
|
6394
|
+
]),
|
|
6395
|
+
input: ""
|
|
6396
|
+
}),
|
|
6397
|
+
direct: (argv) => o.guest(argv)
|
|
6398
|
+
};
|
|
6399
|
+
}
|
|
6400
|
+
// ../sandbox-docker/src/transport-session.ts
|
|
6401
|
+
/** How long killing an aborted command may take. */
|
|
6402
|
+
const KILL_TIMEOUT_MS = 3e4;
|
|
6403
|
+
const text = (r) => ({
|
|
6404
|
+
exitCode: r.exitCode,
|
|
6405
|
+
stdout: r.stdout.toString("utf8"),
|
|
6406
|
+
stderr: r.stderr
|
|
6407
|
+
});
|
|
6408
|
+
/**
|
|
6409
|
+
* A harness sandbox session on a machine reeval reaches through host programs (`ssh`, `tart
|
|
6410
|
+
* exec`): everything but how a command gets there, which {@link SessionShell} says.
|
|
6411
|
+
*/
|
|
6412
|
+
function transportSession(o) {
|
|
6413
|
+
const { shell, gateway, description } = o;
|
|
5298
6414
|
let execs = 0;
|
|
5299
|
-
const
|
|
5300
|
-
const
|
|
5301
|
-
|
|
5302
|
-
|
|
5303
|
-
|
|
5304
|
-
|
|
5305
|
-
|
|
5306
|
-
|
|
5307
|
-
|
|
6415
|
+
const at = (path) => path ? posix.resolve(o.defaultWorkingDirectory, path) : o.defaultWorkingDirectory;
|
|
6416
|
+
const runHost = (c, signal) => shell.run(c.argv, {
|
|
6417
|
+
input: c.input,
|
|
6418
|
+
signal
|
|
6419
|
+
});
|
|
6420
|
+
const kill = (exec) => runHost(shell.kill(exec), AbortSignal.timeout(KILL_TIMEOUT_MS)).then(() => {}, () => {});
|
|
6421
|
+
const execute = async (exec, c, signal) => {
|
|
6422
|
+
let killed;
|
|
6423
|
+
const onAbort = () => {
|
|
6424
|
+
killed = kill(exec);
|
|
5308
6425
|
};
|
|
6426
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
5309
6427
|
try {
|
|
5310
|
-
|
|
5311
|
-
return {
|
|
5312
|
-
exitCode: r.exitCode,
|
|
5313
|
-
stdout: r.stdout.toString("utf8"),
|
|
5314
|
-
stderr: r.stderr
|
|
5315
|
-
};
|
|
6428
|
+
return text(await runHost(c, signal));
|
|
5316
6429
|
} catch (error) {
|
|
5317
|
-
if (
|
|
6430
|
+
if (signal?.aborted) {
|
|
6431
|
+
await killed;
|
|
6432
|
+
await kill(exec);
|
|
6433
|
+
}
|
|
5318
6434
|
throw error;
|
|
6435
|
+
} finally {
|
|
6436
|
+
signal?.removeEventListener("abort", onAbort);
|
|
5319
6437
|
}
|
|
5320
6438
|
};
|
|
5321
|
-
|
|
5322
|
-
|
|
5323
|
-
|
|
5324
|
-
|
|
5325
|
-
|
|
5326
|
-
|
|
5327
|
-
|
|
5328
|
-
|
|
5329
|
-
|
|
5330
|
-
|
|
5331
|
-
|
|
5332
|
-
|
|
5333
|
-
}
|
|
6439
|
+
/** Starts a host program with its output streamed; its kill ends command `exec` in the machine too. */
|
|
6440
|
+
const streamed = (exec, c) => {
|
|
6441
|
+
const [bin = "", ...args] = c.argv;
|
|
6442
|
+
const startedAt = Date.now();
|
|
6443
|
+
const child = spawn(bin, args, {
|
|
6444
|
+
stdio: [
|
|
6445
|
+
"pipe",
|
|
6446
|
+
"pipe",
|
|
6447
|
+
"pipe"
|
|
6448
|
+
],
|
|
6449
|
+
detached: true
|
|
6450
|
+
});
|
|
6451
|
+
child.stdin.on("error", () => {});
|
|
6452
|
+
child.stdin.end(c.input);
|
|
6453
|
+
const exited = new Promise((resolve) => {
|
|
6454
|
+
child.once("error", () => resolve({ exitCode: 127 }));
|
|
6455
|
+
child.once("close", (code) => {
|
|
6456
|
+
traceDocker(args, startedAt, {
|
|
6457
|
+
exitCode: code,
|
|
6458
|
+
stdout: "<streamed>"
|
|
6459
|
+
}, bin);
|
|
6460
|
+
resolve({ exitCode: code ?? 1 });
|
|
6461
|
+
});
|
|
6462
|
+
});
|
|
6463
|
+
return {
|
|
6464
|
+
pid: child.pid,
|
|
6465
|
+
stdout: Readable.toWeb(child.stdout),
|
|
6466
|
+
stderr: Readable.toWeb(child.stderr),
|
|
6467
|
+
wait: () => exited,
|
|
6468
|
+
kill: async () => {
|
|
6469
|
+
child.kill("SIGKILL");
|
|
6470
|
+
await kill(exec);
|
|
6471
|
+
}
|
|
6472
|
+
};
|
|
5334
6473
|
};
|
|
5335
|
-
const
|
|
5336
|
-
|
|
5337
|
-
|
|
5338
|
-
|
|
6474
|
+
const readBinaryFile = async (r) => {
|
|
6475
|
+
const read = await shell.run(shell.direct([
|
|
6476
|
+
"/bin/cat",
|
|
6477
|
+
"--",
|
|
6478
|
+
at(r.path)
|
|
6479
|
+
]), { signal: r.abortSignal }).catch(() => null);
|
|
6480
|
+
return read?.exitCode === 0 ? new Uint8Array(read.stdout) : null;
|
|
5339
6481
|
};
|
|
5340
|
-
const writeBinaryFile = async (
|
|
5341
|
-
const
|
|
5342
|
-
const
|
|
5343
|
-
|
|
5344
|
-
|
|
6482
|
+
const writeBinaryFile = async (w) => {
|
|
6483
|
+
const target = at(w.path);
|
|
6484
|
+
const r = await shell.run(shell.direct([
|
|
6485
|
+
"/bin/sh",
|
|
6486
|
+
"-c",
|
|
6487
|
+
"umask 022 && mkdir -p \"$(dirname \"$1\")\" && cat > \"$1\"",
|
|
6488
|
+
"sh",
|
|
6489
|
+
target
|
|
6490
|
+
]), {
|
|
6491
|
+
input: w.content,
|
|
6492
|
+
signal: w.abortSignal
|
|
6493
|
+
});
|
|
6494
|
+
if (r.exitCode !== 0) throw new Error(`Couldn't write ${target} in ${o.name ?? description}: ${r.stderr.trim()}`);
|
|
5345
6495
|
};
|
|
5346
|
-
const paths = pathOperations(async (script, path, abortSignal) =>
|
|
5347
|
-
|
|
5348
|
-
|
|
5349
|
-
|
|
5350
|
-
|
|
5351
|
-
|
|
5352
|
-
|
|
5353
|
-
});
|
|
6496
|
+
const paths = pathOperations(async (script, path, abortSignal) => text(await shell.run(shell.direct([
|
|
6497
|
+
"/bin/sh",
|
|
6498
|
+
"-c",
|
|
6499
|
+
script,
|
|
6500
|
+
"sh",
|
|
6501
|
+
path
|
|
6502
|
+
]), { signal: abortSignal })), o.defaultWorkingDirectory);
|
|
5354
6503
|
const brokering = gateway ? {
|
|
5355
6504
|
async setNetworkPolicy(policy) {
|
|
5356
|
-
gateway
|
|
6505
|
+
gateway.setPolicy(policy);
|
|
5357
6506
|
},
|
|
5358
6507
|
async addRequestTransformations(rules) {
|
|
5359
|
-
gateway
|
|
6508
|
+
gateway.addTransformations(rules);
|
|
5360
6509
|
},
|
|
5361
6510
|
async setRequestTransformations(rules) {
|
|
5362
|
-
gateway
|
|
5363
|
-
}
|
|
5364
|
-
} : {};
|
|
5365
|
-
const substituting = gateway ? {
|
|
6511
|
+
gateway.setTransformations(rules);
|
|
6512
|
+
},
|
|
5366
6513
|
async setSubstitutions(subs) {
|
|
5367
|
-
gateway
|
|
6514
|
+
gateway.setSubstitutions(subs);
|
|
5368
6515
|
},
|
|
5369
6516
|
traffic: () => gateway.traffic()
|
|
5370
6517
|
} : {};
|
|
6518
|
+
const run = (r) => {
|
|
6519
|
+
const exec = ++execs;
|
|
6520
|
+
return execute(exec, shell.user({
|
|
6521
|
+
command: r.command,
|
|
6522
|
+
cwd: at(r.workingDirectory),
|
|
6523
|
+
env: o.env(r.env),
|
|
6524
|
+
exec
|
|
6525
|
+
}), r.abortSignal);
|
|
6526
|
+
};
|
|
5371
6527
|
const session = {
|
|
5372
|
-
id:
|
|
5373
|
-
description
|
|
5374
|
-
defaultWorkingDirectory:
|
|
6528
|
+
id: o.id,
|
|
6529
|
+
description,
|
|
6530
|
+
defaultWorkingDirectory: o.defaultWorkingDirectory,
|
|
5375
6531
|
ports: [BRIDGE_PORT],
|
|
5376
6532
|
get egress() {
|
|
5377
|
-
if (egress?.active && gateway?.stopped) return {
|
|
6533
|
+
if (o.egress?.active && gateway?.stopped) return {
|
|
5378
6534
|
active: false,
|
|
5379
6535
|
reason: gateway.stopped
|
|
5380
6536
|
};
|
|
5381
|
-
return egress;
|
|
6537
|
+
return o.egress;
|
|
5382
6538
|
},
|
|
5383
6539
|
...brokering,
|
|
5384
|
-
...substituting,
|
|
5385
6540
|
oomKills: async () => null,
|
|
5386
|
-
run
|
|
5387
|
-
runPrivileged
|
|
5388
|
-
|
|
5389
|
-
|
|
5390
|
-
|
|
5391
|
-
|
|
5392
|
-
|
|
5393
|
-
|
|
5394
|
-
|
|
5395
|
-
|
|
5396
|
-
const
|
|
5397
|
-
const
|
|
5398
|
-
|
|
5399
|
-
|
|
5400
|
-
|
|
5401
|
-
|
|
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 });
|
|
6541
|
+
run,
|
|
6542
|
+
runPrivileged: (r) => {
|
|
6543
|
+
const exec = ++execs;
|
|
6544
|
+
return execute(exec, shell.privileged({
|
|
6545
|
+
command: r.command,
|
|
6546
|
+
exec
|
|
6547
|
+
}), r.abortSignal);
|
|
6548
|
+
},
|
|
6549
|
+
spawn: (async (s) => {
|
|
6550
|
+
if (s.stdin) throw new Error(`A process in ${description} has no writable stdin`);
|
|
6551
|
+
const exec = ++execs;
|
|
6552
|
+
const p = streamed(exec, shell.user({
|
|
6553
|
+
command: s.command,
|
|
6554
|
+
cwd: at(s.workingDirectory),
|
|
6555
|
+
env: o.env(s.env),
|
|
6556
|
+
exec
|
|
5413
6557
|
}));
|
|
5414
|
-
|
|
5415
|
-
|
|
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
|
-
};
|
|
6558
|
+
s.abortSignal?.addEventListener("abort", () => void p.kill(), { once: true });
|
|
6559
|
+
return p;
|
|
5426
6560
|
}),
|
|
6561
|
+
spawnPrivileged: async (s) => {
|
|
6562
|
+
const exec = ++execs;
|
|
6563
|
+
return streamed(exec, shell.privileged({
|
|
6564
|
+
command: s.command,
|
|
6565
|
+
exec
|
|
6566
|
+
}));
|
|
6567
|
+
},
|
|
5427
6568
|
readBinaryFile,
|
|
5428
|
-
async readFile(
|
|
5429
|
-
const bytes = await readBinaryFile(
|
|
6569
|
+
async readFile(r) {
|
|
6570
|
+
const bytes = await readBinaryFile(r);
|
|
5430
6571
|
return bytes === null ? null : Readable.toWeb(Readable.from([bytes]));
|
|
5431
6572
|
},
|
|
5432
|
-
async readTextFile(
|
|
5433
|
-
const bytes = await readBinaryFile(
|
|
6573
|
+
async readTextFile(r) {
|
|
6574
|
+
const bytes = await readBinaryFile(r);
|
|
5434
6575
|
if (bytes === null) return null;
|
|
5435
|
-
const
|
|
5436
|
-
if (
|
|
5437
|
-
return
|
|
6576
|
+
const content = Buffer.from(bytes).toString("utf8");
|
|
6577
|
+
if (r.startLine === void 0 && r.endLine === void 0) return content;
|
|
6578
|
+
return content.split("\n").slice((r.startLine ?? 1) - 1, r.endLine).join("\n");
|
|
5438
6579
|
},
|
|
5439
6580
|
...paths,
|
|
5440
6581
|
writeBinaryFile,
|
|
5441
|
-
writeTextFile: (
|
|
5442
|
-
...
|
|
5443
|
-
content: Buffer.from(
|
|
6582
|
+
writeTextFile: (w) => writeBinaryFile({
|
|
6583
|
+
...w,
|
|
6584
|
+
content: Buffer.from(w.content, "utf8")
|
|
5444
6585
|
}),
|
|
5445
|
-
async writeFile(
|
|
6586
|
+
async writeFile(w) {
|
|
5446
6587
|
const chunks = [];
|
|
5447
|
-
for await (const chunk of
|
|
6588
|
+
for await (const chunk of w.content) chunks.push(chunk);
|
|
5448
6589
|
await writeBinaryFile({
|
|
5449
|
-
...
|
|
6590
|
+
...w,
|
|
5450
6591
|
content: Buffer.concat(chunks)
|
|
5451
6592
|
});
|
|
5452
6593
|
},
|
|
5453
6594
|
async getPortEndpoint({ port, protocol = "ws" }) {
|
|
5454
6595
|
const scheme = protocol === "ws" ? "ws" : "http";
|
|
5455
|
-
if (
|
|
5456
|
-
return { url: await
|
|
6596
|
+
if (gateway && !gateway.stopped) return { url: await gateway.portUrl(port, scheme) };
|
|
6597
|
+
return { url: await o.portWithoutGateway(port, scheme) };
|
|
5457
6598
|
},
|
|
5458
|
-
async getPortUrl(
|
|
5459
|
-
return (await session.getPortEndpoint(
|
|
6599
|
+
async getPortUrl(p) {
|
|
6600
|
+
return (await session.getPortEndpoint(p)).url;
|
|
5460
6601
|
},
|
|
5461
|
-
stop: destroy,
|
|
5462
|
-
destroy,
|
|
6602
|
+
stop: o.destroy,
|
|
6603
|
+
destroy: o.destroy,
|
|
5463
6604
|
restricted: () => {
|
|
5464
|
-
const {
|
|
5465
|
-
const {
|
|
6605
|
+
const { readFile, readTextFile, writeFile, writeTextFile, stat, listDirectory } = session;
|
|
6606
|
+
const { deleteFile, spawn: spawnIn, run: runIn } = session;
|
|
5466
6607
|
return {
|
|
5467
6608
|
description,
|
|
5468
6609
|
readFile,
|
|
@@ -5474,13 +6615,300 @@ async function createSshSession(options) {
|
|
|
5474
6615
|
stat,
|
|
5475
6616
|
listDirectory,
|
|
5476
6617
|
deleteFile,
|
|
5477
|
-
spawn,
|
|
5478
|
-
run
|
|
6618
|
+
spawn: spawnIn,
|
|
6619
|
+
run: runIn
|
|
5479
6620
|
};
|
|
5480
6621
|
}
|
|
5481
6622
|
};
|
|
5482
6623
|
return session;
|
|
5483
6624
|
}
|
|
5484
|
-
|
|
6625
|
+
// ../sandbox-docker/src/ssh-session.ts
|
|
6626
|
+
/** ssh's own exit status: it couldn't connect, or the connection dropped. */
|
|
6627
|
+
const SSH_FAILED = 255;
|
|
6628
|
+
/** Held while one slot sets up, so slots sharing a machine don't install the same things at once. */
|
|
6629
|
+
const SETUP_LOCK = "/var/lock/reeval-setup";
|
|
6630
|
+
/** The machine's homes, root's: `home-<label>.tar`, and the `.lock` its installer holds. */
|
|
6631
|
+
const HOMES = "/var/lib/reeval-pool";
|
|
6632
|
+
const RESTORED = "reeval:home-restored";
|
|
6633
|
+
const CLAIMED = "reeval:install-claimed";
|
|
6634
|
+
const WAITING = "reeval:install-waiting";
|
|
6635
|
+
const COPY_FAILED = "reeval:home-copy-failed";
|
|
6636
|
+
const FRESH = "reeval:install-fresh";
|
|
6637
|
+
/** How long a slot waits for another's install, past the install's own deadline of 10 minutes. */
|
|
6638
|
+
const INSTALL_WAIT_MS = 66e4;
|
|
6639
|
+
const homeFiles = (label) => {
|
|
6640
|
+
const base = `${HOMES}/home-${label.replace(/[^A-Za-z0-9._-]/g, "_")}`;
|
|
6641
|
+
return {
|
|
6642
|
+
tar: `${base}.tar`,
|
|
6643
|
+
lock: `${base}.lock`
|
|
6644
|
+
};
|
|
6645
|
+
};
|
|
6646
|
+
/**
|
|
6647
|
+
* Root commands that keep the sandbox user's home as the machine's copy for `label`, which a slot
|
|
6648
|
+
* unpacks into its own home rather than installing: what an image with the install baked in runs.
|
|
6649
|
+
*/
|
|
6650
|
+
const keepHomeCopy = (label) => `mkdir -p ${shellQuote(HOMES)} && chmod 700 ${shellQuote(HOMES)} && tar -C ${shellQuote(posix.dirname(SANDBOX_HOME))} -cf ${shellQuote(homeFiles(label).tar)} ${shellQuote(posix.basename(SANDBOX_HOME))}`;
|
|
6651
|
+
/**
|
|
6652
|
+
* Root commands that empty a slot's home back to the skeleton. The directory itself stays: on a
|
|
6653
|
+
* shared machine, slot 0's is where the other slots' commands see their own homes.
|
|
6654
|
+
*/
|
|
6655
|
+
const skeletonHome = (layout) => {
|
|
6656
|
+
const [u, home] = [shellQuote(layout.user), shellQuote(layout.home)];
|
|
6657
|
+
return `mkdir -p ${home} && find ${home} -mindepth 1 -delete && cp -a /etc/skel/. ${home}/ && chown -R -h ${u}:${u} ${home} && chmod 700 ${home}`;
|
|
6658
|
+
};
|
|
6659
|
+
/**
|
|
6660
|
+
* Root commands that put a used slot back as a new one finds it: none of its user's processes,
|
|
6661
|
+
* cron or at jobs, lingering, temporary files, locks or message queues, an empty working root and
|
|
6662
|
+
* state directory, and the skeleton home.
|
|
6663
|
+
*/
|
|
6664
|
+
function resetSlot(layout) {
|
|
6665
|
+
const u = shellQuote(layout.user);
|
|
6666
|
+
return [
|
|
6667
|
+
`if id -u ${u} >/dev/null 2>&1; then`,
|
|
6668
|
+
`for i in 1 2 3 4 5 6 7 8 9 10; do pkill -KILL -u ${u} || break; sleep 0.2; done`,
|
|
6669
|
+
`crontab -r -u ${u} 2>/dev/null`,
|
|
6670
|
+
`atq 2>/dev/null | awk -v u=${u} '$NF == u { print $1 }' | xargs -r atrm 2>/dev/null`,
|
|
6671
|
+
`loginctl disable-linger ${u} 2>/dev/null`,
|
|
6672
|
+
`find /tmp /var/tmp /dev/shm /run/lock /dev/mqueue -xdev -mindepth 1 -user ${u} -delete 2>/dev/null`,
|
|
6673
|
+
`rm -rf ${shellQuote(layout.root)} ${shellQuote(layout.state)}`,
|
|
6674
|
+
skeletonHome(layout),
|
|
6675
|
+
"fi; true"
|
|
6676
|
+
].join("\n");
|
|
6677
|
+
}
|
|
6678
|
+
/**
|
|
6679
|
+
* The root script that gives a slot the machine's home for `label`. With a copy kept, it unpacks
|
|
6680
|
+
* it into the slot's home ({@link RESTORED}): every slot sees its home at one path, so the copy
|
|
6681
|
+
* needs no change. With none, the slot takes the install's lock and holds it, in the process that
|
|
6682
|
+
* then reads its stdin until the installer closes it ({@link CLAIMED}); a slot that finds it held
|
|
6683
|
+
* says {@link WAITING} and blocks until the kernel releases it, when its holder finishes or dies.
|
|
6684
|
+
* A copy that won't unpack is deleted ({@link COPY_FAILED}) and the slot goes for the lock again,
|
|
6685
|
+
* or installs on its own ({@link FRESH}).
|
|
6686
|
+
*/
|
|
6687
|
+
function slotHome(layout, label) {
|
|
6688
|
+
const f = homeFiles(label);
|
|
6689
|
+
const [tar, lock] = [shellQuote(f.tar), shellQuote(f.lock)];
|
|
6690
|
+
const [u, home] = [shellQuote(layout.user), shellQuote(layout.home)];
|
|
6691
|
+
const restore = `find ${home} -mindepth 1 -delete && tar -C ${home} --strip-components=1 -xpf ${tar} && chown -R -h ${u}:${u} ${home} && chmod 700 ${home}`;
|
|
6692
|
+
return [
|
|
6693
|
+
`mkdir -p ${shellQuote(HOMES)} && chmod 700 ${shellQuote(HOMES)} && exec 9>>${lock} || exit 1`,
|
|
6694
|
+
"for try in 1 2; do",
|
|
6695
|
+
`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`,
|
|
6696
|
+
`if [ ! -f ${tar} ]; then echo ${CLAIMED}; exec cat >/dev/null; fi`,
|
|
6697
|
+
"flock -u 9",
|
|
6698
|
+
`if ${restore}; then echo ${RESTORED}; exit 0; fi`,
|
|
6699
|
+
`echo ${COPY_FAILED}; rm -f ${tar}; ${skeletonHome(layout)} || exit 1`,
|
|
6700
|
+
"done",
|
|
6701
|
+
`echo ${FRESH}`
|
|
6702
|
+
].join("\n");
|
|
6703
|
+
}
|
|
6704
|
+
/**
|
|
6705
|
+
* Sets up a Linux VM reached over SSH for a harness session: the login user has passwordless
|
|
6706
|
+
* `sudo` or is root ({@link SshTarget.loginRoot}), and the agent, setup steps and checks run as {@link SANDBOX_USER}, a user made here with
|
|
6707
|
+
* no `sudo` and none of the login user's groups or variables. Ports are reached through the
|
|
6708
|
+
* egress gateway's tunnel. When setting up fails, the connection is closed.
|
|
6709
|
+
*/
|
|
6710
|
+
async function connectSsh(options) {
|
|
6711
|
+
const { target, abortSignal: signal } = options;
|
|
6712
|
+
const layout = options.layout ?? slotLayout(0);
|
|
6713
|
+
const baseEnv = {
|
|
6714
|
+
PATH: [
|
|
6715
|
+
`${SANDBOX_HOME}/.local/bin`,
|
|
6716
|
+
...options.path ?? [],
|
|
6717
|
+
SYSTEM_PATH
|
|
6718
|
+
].join(":"),
|
|
6719
|
+
HOME: SANDBOX_HOME,
|
|
6720
|
+
USER: layout.user,
|
|
6721
|
+
LOGNAME: layout.user,
|
|
6722
|
+
SHELL: "/bin/bash",
|
|
6723
|
+
LANG: "C.UTF-8"
|
|
6724
|
+
};
|
|
6725
|
+
const userEnv = {
|
|
6726
|
+
NPM_CONFIG_UPDATE_NOTIFIER: "false",
|
|
6727
|
+
NPM_CONFIG_PREFIX: `${SANDBOX_HOME}/.local`,
|
|
6728
|
+
...options.env
|
|
6729
|
+
};
|
|
6730
|
+
const hostRun = async (argv, o) => {
|
|
6731
|
+
const [bin = "ssh", ...args] = argv;
|
|
6732
|
+
const startedAt = Date.now();
|
|
6733
|
+
try {
|
|
6734
|
+
const r = await run(bin, args, {
|
|
6735
|
+
input: o.input ?? "",
|
|
6736
|
+
signal: o.signal,
|
|
6737
|
+
binary: true
|
|
6738
|
+
});
|
|
6739
|
+
traceDocker(args, startedAt, {
|
|
6740
|
+
...r,
|
|
6741
|
+
stdin: o.input?.length ?? 0
|
|
6742
|
+
}, "ssh");
|
|
6743
|
+
return r;
|
|
6744
|
+
} catch (error) {
|
|
6745
|
+
traceDocker(args, startedAt, { error }, "ssh");
|
|
6746
|
+
throw error;
|
|
6747
|
+
}
|
|
6748
|
+
};
|
|
6749
|
+
const ssh = (remote) => hostRun(sshArgv(target, remote), {
|
|
6750
|
+
input: "",
|
|
6751
|
+
signal
|
|
6752
|
+
});
|
|
6753
|
+
const closeConnection = async () => {
|
|
6754
|
+
if (!controlOptions(target.controlPath, 0).length) return;
|
|
6755
|
+
const [bin = "ssh", ...args] = sshArgv(target, "");
|
|
6756
|
+
await run(bin, [
|
|
6757
|
+
"-O",
|
|
6758
|
+
"exit",
|
|
6759
|
+
...args.slice(0, -1)
|
|
6760
|
+
]).catch(() => {});
|
|
6761
|
+
};
|
|
6762
|
+
const fail = async (error) => {
|
|
6763
|
+
await closeConnection();
|
|
6764
|
+
throw signal?.aborted ? signal.reason : error;
|
|
6765
|
+
};
|
|
6766
|
+
const { user } = layout;
|
|
6767
|
+
const addUser = (name) => `{ id -u ${name} >/dev/null 2>&1 || useradd --create-home --shell /bin/bash --user-group ${name}; }`;
|
|
6768
|
+
const setup = [
|
|
6769
|
+
EXEC_UMASK,
|
|
6770
|
+
...options.reset ? [`{ ${resetSlot(layout)}\n}`] : [],
|
|
6771
|
+
...layout.home === "/home/reeval" ? [addUser(user)] : [
|
|
6772
|
+
`{ 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; }`,
|
|
6773
|
+
addUser(SANDBOX_USER),
|
|
6774
|
+
`chmod 700 ${SANDBOX_HOME}`,
|
|
6775
|
+
`{ id -u ${user} >/dev/null 2>&1 || useradd --no-create-home --home-dir ${SANDBOX_HOME} --shell /bin/bash --user-group ${user}; }`,
|
|
6776
|
+
`{ [ -d ${layout.home} ] || { cp -a /etc/skel ${layout.home} && chown -R ${user}:${user} ${layout.home}; }; }`
|
|
6777
|
+
],
|
|
6778
|
+
`mkdir -p ${layout.root} && chown ${user}:${user} ${layout.root}`,
|
|
6779
|
+
`chmod 700 ${layout.root} ${layout.home}`,
|
|
6780
|
+
`mkdir -p ${layout.state} && chown 0:0 ${layout.state} && chmod 700 ${layout.state}`,
|
|
6781
|
+
...options.prepare ? [options.prepare] : []
|
|
6782
|
+
].join(" && ");
|
|
6783
|
+
const sudo = asRootPrefix(target);
|
|
6784
|
+
const asRoot = options.layout ? `${sudo}flock ${SETUP_LOCK} /bin/sh -c ${shellQuote(setup)} sh "$PATH"` : `${sudo}/bin/sh -c ${shellQuote(setup)} sh "$PATH"`;
|
|
6785
|
+
const deadline = Date.now() + (options.connectTimeoutMs ?? 6e4);
|
|
6786
|
+
for (let wait = 500;; wait = Math.min(wait * 2, 5e3)) {
|
|
6787
|
+
const made = await ssh(asRoot).catch(fail);
|
|
6788
|
+
if (made.exitCode === 0) break;
|
|
6789
|
+
if (made.exitCode !== SSH_FAILED || Date.now() + wait > deadline) {
|
|
6790
|
+
const why = made.stderr.trim() || made.stdout.toString("utf8").trim();
|
|
6791
|
+
return fail(/* @__PURE__ */ new Error(`Couldn't set up ${options.description}: ${why.slice(-500)}`));
|
|
6792
|
+
}
|
|
6793
|
+
await new Promise((resolve) => setTimeout(resolve, wait));
|
|
6794
|
+
if (signal?.aborted) return fail(signal.reason);
|
|
6795
|
+
}
|
|
6796
|
+
/** The process holding the install's lock in the machine, while this slot installs. */
|
|
6797
|
+
let holder;
|
|
6798
|
+
const release = async () => {
|
|
6799
|
+
const held = holder;
|
|
6800
|
+
holder = void 0;
|
|
6801
|
+
if (!held || held.exitCode !== null) return;
|
|
6802
|
+
const gone = new Promise((resolve) => held.once("close", resolve));
|
|
6803
|
+
held.stdin?.end();
|
|
6804
|
+
const timer = setTimeout(() => held.kill("SIGKILL"), 1e4);
|
|
6805
|
+
await gone;
|
|
6806
|
+
clearTimeout(timer);
|
|
6807
|
+
};
|
|
6808
|
+
const shell = linuxShell({
|
|
6809
|
+
run: hostRun,
|
|
6810
|
+
remote: (command) => sshArgv(target, command),
|
|
6811
|
+
id: `${target.hostKeyAlias}-${layout.user}`,
|
|
6812
|
+
user: baseEnv,
|
|
6813
|
+
signal,
|
|
6814
|
+
layout,
|
|
6815
|
+
...target.loginRoot && { loginRoot: true }
|
|
6816
|
+
});
|
|
6817
|
+
return {
|
|
6818
|
+
root: sshTransport(target),
|
|
6819
|
+
async home() {
|
|
6820
|
+
if (!options.home) return {
|
|
6821
|
+
restored: false,
|
|
6822
|
+
waitedMs: 0
|
|
6823
|
+
};
|
|
6824
|
+
const [bin = "ssh", ...args] = sshArgv(target, `${sudo}/bin/sh -c ${shellQuote(`${EXEC_UMASK}\n${slotHome(layout, options.home)}`)}`);
|
|
6825
|
+
const startedAt = Date.now();
|
|
6826
|
+
const child = spawn(bin, args, { stdio: [
|
|
6827
|
+
"pipe",
|
|
6828
|
+
"pipe",
|
|
6829
|
+
"pipe"
|
|
6830
|
+
] });
|
|
6831
|
+
let [out, err] = ["", ""];
|
|
6832
|
+
child.stderr.on("data", (d) => {
|
|
6833
|
+
err += d.toString("utf8");
|
|
6834
|
+
});
|
|
6835
|
+
const [decided, waited] = (await new Promise((resolve, reject) => {
|
|
6836
|
+
let waitingSince;
|
|
6837
|
+
const stop = () => child.kill("SIGKILL");
|
|
6838
|
+
signal?.addEventListener("abort", stop, { once: true });
|
|
6839
|
+
child.stdout.on("data", (d) => {
|
|
6840
|
+
out += d.toString("utf8");
|
|
6841
|
+
if (waitingSince === void 0 && out.includes(WAITING)) waitingSince = Date.now();
|
|
6842
|
+
const decided = [
|
|
6843
|
+
RESTORED,
|
|
6844
|
+
CLAIMED,
|
|
6845
|
+
FRESH
|
|
6846
|
+
].find((m) => out.includes(m));
|
|
6847
|
+
if (!decided) return;
|
|
6848
|
+
signal?.removeEventListener("abort", stop);
|
|
6849
|
+
resolve(`${decided} ${waitingSince === void 0 ? 0 : Date.now() - waitingSince}`);
|
|
6850
|
+
});
|
|
6851
|
+
child.once("error", reject);
|
|
6852
|
+
child.once("close", (code) => {
|
|
6853
|
+
signal?.removeEventListener("abort", stop);
|
|
6854
|
+
if (signal?.aborted) return reject(signal.reason);
|
|
6855
|
+
const why = err.trim() || out.trim() || `ssh exited with ${code}`;
|
|
6856
|
+
reject(/* @__PURE__ */ new Error(`Couldn't give ${user} the machine's home in ${options.description}: ${why.slice(-500)}`));
|
|
6857
|
+
});
|
|
6858
|
+
}).finally(() => traceDocker(args, startedAt, {
|
|
6859
|
+
exitCode: child.exitCode,
|
|
6860
|
+
stdout: out,
|
|
6861
|
+
stderr: err
|
|
6862
|
+
}, "ssh"))).split(" ");
|
|
6863
|
+
if (decided === CLAIMED) holder = child;
|
|
6864
|
+
else child.stdin.end();
|
|
6865
|
+
return {
|
|
6866
|
+
restored: decided === RESTORED,
|
|
6867
|
+
waitedMs: Number(waited),
|
|
6868
|
+
...out.includes(COPY_FAILED) && { copyFailed: err.trim().slice(-500) || "the machine's copy didn't unpack" }
|
|
6869
|
+
};
|
|
6870
|
+
},
|
|
6871
|
+
async snapshotHome() {
|
|
6872
|
+
if (!options.home || !holder) return;
|
|
6873
|
+
const f = homeFiles(options.home);
|
|
6874
|
+
const command = [
|
|
6875
|
+
EXEC_UMASK,
|
|
6876
|
+
`tar -C ${shellQuote(posix.dirname(layout.home))} -cf ${shellQuote(f.tar)}.$$ ${shellQuote(posix.basename(layout.home))}`,
|
|
6877
|
+
`mv ${shellQuote(f.tar)}.$$ ${shellQuote(f.tar)}`
|
|
6878
|
+
].join(" && ");
|
|
6879
|
+
try {
|
|
6880
|
+
const r = await ssh(`${sudo}/bin/sh -c ${shellQuote(command)}`);
|
|
6881
|
+
if (r.exitCode !== 0) throw new Error(`Couldn't keep ${layout.user}'s home in ${options.description}: ${r.stderr.trim().slice(-500)}`);
|
|
6882
|
+
} finally {
|
|
6883
|
+
await release();
|
|
6884
|
+
}
|
|
6885
|
+
},
|
|
6886
|
+
async close() {
|
|
6887
|
+
await release();
|
|
6888
|
+
await closeConnection();
|
|
6889
|
+
},
|
|
6890
|
+
session: ({ gateway, noGateway, destroy }) => transportSession({
|
|
6891
|
+
id: target.hostKeyAlias,
|
|
6892
|
+
description: options.description,
|
|
6893
|
+
defaultWorkingDirectory: layout.root,
|
|
6894
|
+
shell,
|
|
6895
|
+
env: (env) => ({
|
|
6896
|
+
...userEnv,
|
|
6897
|
+
...gateway?.env,
|
|
6898
|
+
...env
|
|
6899
|
+
}),
|
|
6900
|
+
gateway,
|
|
6901
|
+
egress: gateway ? { active: true } : {
|
|
6902
|
+
active: false,
|
|
6903
|
+
reason: noGateway ?? ""
|
|
6904
|
+
},
|
|
6905
|
+
async portWithoutGateway(port) {
|
|
6906
|
+
throw new Error(`Port ${port} of ${options.description} isn't reachable: the egress gateway ${gateway?.stopped ? `stopped: ${gateway.stopped}` : "isn't running"}`);
|
|
6907
|
+
},
|
|
6908
|
+
destroy
|
|
6909
|
+
})
|
|
6910
|
+
};
|
|
6911
|
+
}
|
|
6912
|
+
export { PRIVILEGED_CAPABILITIES as $, hostCommand as $t, dockerfileBases as A, adapterVersion as At, isLocalKey as B, imageInfo as Bt, bakedHarnessName as C, normalizeImageId as Cn, HARNESS_PACKAGES as Ct, buildInstallLayer as D, SANDBOX_STATE as Dt, buildImage as E, SANDBOX_ROOT as Et, harnessImageFor as F, docker as Ft, pruneImages as G, controlOptions as Gt, pluginBuildDir as H, isRegistryDigest as Ht, imageKey as I, dockerAvailable as It, sourceTreeHash as J, sshArgv as Jt, reevalImageKey as K, controlPathFits as Kt, installLayerLines as L, dockerCapacity as Lt, dockerfileKey as M, imageFor as Mt, dockerfileTag as N, isBakedHarness as Nt, buildPluginLayer as O, SANDBOX_USER as Ot, fromImageKey as P, slotLayout as Pt, EgressUnavailableError as Q, traceDocker as Qt, installLayerTag as R, dockerOk as Rt, bakedAdapter as S, isRemoteEngine as Sn, DEFAULT_IMAGE as St, buildDockerfile as T, SANDBOX_HOME as Tt, pluginBuildKey as U, removeContainerDetached as Ut, localKey as V, imageTags as Vt, pluginLayerTag as W, SSH_OPTIONS as Wt, usesReevalBase as X, OPAQUE_OUTPUT as Xt, toolchainDockerfile as Y, sshTransport as Yt, DEFAULT_LIMITS as Z, onDockerCommand as Zt, PLUGIN_BUILDS_DIR as _, parseBuildOutput as _n, hostAllowed as _t, darwinShell as a, readTree as an, PROXY_PORT as at, bakeHarness as b, dockerSeccompFile as bn, BASE_IMAGE as bt, enginePlatform as c, contextFiles as cn, usageReader as ct, registryProblem as d, shellQuote as dn, matches as dt, isSshFailure as en, ROOT_CAPABILITIES as et, registryRef as f, ImageBuildError as fn, onEndpoint as ft, PLATFORM as g, isTransient as gn, defaultAllowedHosts as gt, NODE_IMAGE as h, failureCause as hn, PACKAGE_HOSTS as ht, transportSession as i, readTar as in, CA_PATH as it, dockerfileFinalBase as j, harnessLabel as jt, contextHash as k, WORKSPACE_DIR as kt, pullLayer as l, dockerignoreMatcher as ln, placeholder as lt, DOCKER_CONTEXT as m, causeLine as mn, HARNESS_HOSTS as mt, keepHomeCopy as n, spawnEngine as nn, dockerSandboxProvider as nt, parseImageRef as o, safeTarPath as on, startGateway as ot, MCP_TIMER as p, RETRY_DELAYS as pn, DOCKER_EGRESS as pt, resolveFrom as q, privateDir as qt, resetSlot as r, extractTar as rn, pathOperations as rt, registryDigest as s, writeTar as sn, MODEL_FIELD as st, connectSsh as t, remoteBuild as tn, createDockerSession as tt, pushLayer as u, run as un, applyTransformations as ut, PNPM_VERSION as v, retryTransient as vn, requestFacts as vt, bakedRecipe as w, LABEL$1 as wt, bakeKey as x, engineSpec as xn, BRIDGE_PORT as xt, REEVAL_BASE_ARG as y, ENGINES as yn, BAKED_HARNESSES as yt, installScript as z, dockerState as zt };
|
|
5485
6913
|
|
|
5486
|
-
//# sourceMappingURL=src-
|
|
6914
|
+
//# sourceMappingURL=src-C5rrQlt8.js.map
|