reeval 0.20.0 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +841 -0
- package/README.md +15 -15
- package/assets/gateway-models.mjs +65 -31
- package/dist/{adapter-C60z3wLq.js → adapter-Di9H2etg.js} +8 -49
- package/dist/adapter-Di9H2etg.js.map +1 -0
- package/dist/{agent-BmsMXZXx.js → agent-B-6GFDqA.js} +185 -38
- package/dist/agent-B-6GFDqA.js.map +1 -0
- package/dist/{agents-DXuFxtGC.js → agents-KBTYhSSh.js} +385 -116
- package/dist/agents-KBTYhSSh.js.map +1 -0
- package/dist/{app-files-DT5mJyV4.js → app-files-Cmh9FGr5.js} +3 -3
- package/dist/app-files-Cmh9FGr5.js.map +1 -0
- package/dist/{assemble-CE4pHKIa.js → assemble-CBMRIhso.js} +1 -1
- package/dist/{assemble-DM2PNU4R.js → assemble-DNVBTBp_.js} +172 -18
- package/dist/assemble-DNVBTBp_.js.map +1 -0
- package/dist/attach-EbDGKGTO.js +152 -0
- package/dist/attach-EbDGKGTO.js.map +1 -0
- package/dist/{attempt-CAdlwlNu.js → attempt-_dUsblVx.js} +2 -2
- package/dist/{attempt-CAdlwlNu.js.map → attempt-_dUsblVx.js.map} +1 -1
- package/dist/{attempt-host-7VviAJrl.js → attempt-host-DQvynDHk.js} +17 -8
- package/dist/attempt-host-DQvynDHk.js.map +1 -0
- package/dist/boat-Bzz8L-KQ.js +701 -0
- package/dist/boat-Bzz8L-KQ.js.map +1 -0
- package/dist/{boat-BjLqFJIZ.js → boat-Dek8ftIt.js} +20 -8
- package/dist/boat-Dek8ftIt.js.map +1 -0
- package/dist/bridge/index.mjs +6 -1
- package/dist/bundle-DZstHDeW.js +718 -0
- package/dist/bundle-DZstHDeW.js.map +1 -0
- package/dist/{capture-Ccf0Hmyx.js → capture-BkbPsfej.js} +61 -32
- package/dist/capture-BkbPsfej.js.map +1 -0
- package/dist/capture-CUAvk9KM.js +1 -0
- package/dist/{cases-z9E6DCd5.js → cases-CM-MQRQp.js} +133 -19
- package/dist/cases-CM-MQRQp.js.map +1 -0
- package/dist/cases-FvhbM8M5.js +1 -0
- package/dist/{cli-DTuLSlmW.js → cli-BgBBuxxJ.js} +412 -1044
- package/dist/cli-BgBBuxxJ.js.map +1 -0
- package/dist/{cli-spec-Dsr79Qy1.js → cli-spec-B5L9n-DV.js} +199 -35
- package/dist/cli-spec-B5L9n-DV.js.map +1 -0
- package/dist/cli.js +2 -2
- package/dist/client-DMEYR3MA.js +807 -0
- package/dist/client-DMEYR3MA.js.map +1 -0
- package/dist/{command-C2C7P5qo.js → command-BKb8eN_X.js} +10 -10
- package/dist/{command-C2C7P5qo.js.map → command-BKb8eN_X.js.map} +1 -1
- package/dist/{command-DSL7I-SI.js → command-D_w_kDpI.js} +25 -21
- package/dist/command-D_w_kDpI.js.map +1 -0
- package/dist/{command-Ff0T-1Hi.js → command-Dwlh0Vhu.js} +17 -16
- package/dist/command-Dwlh0Vhu.js.map +1 -0
- package/dist/{command-D8oMB2fa.js → command-loXH2jHr.js} +16 -16
- package/dist/{command-D8oMB2fa.js.map → command-loXH2jHr.js.map} +1 -1
- package/dist/{commands-xAOi_VEk.js → commands-Cuf57OYb.js} +174 -40
- package/dist/commands-Cuf57OYb.js.map +1 -0
- package/dist/{commands-Bk9NG1s_.js → commands-Dqli45sR.js} +1 -1
- package/dist/{config-SvK8pjEK.js → config-C0RKt00M.js} +288 -106
- package/dist/config-C0RKt00M.js.map +1 -0
- package/dist/{context-BdgCao9Q.js → context-DrEAtUyg.js} +2 -2
- package/dist/{context-BdgCao9Q.js.map → context-DrEAtUyg.js.map} +1 -1
- package/dist/{cost-BdRgySQl.js → cost-C21gGrju.js} +19 -9
- package/dist/cost-C21gGrju.js.map +1 -0
- package/dist/cost-IM80LyGD.js +1 -0
- package/dist/{cursor-catalog-DEzan4IT.js → cursor-catalog-CRsFxorF.js} +4 -4
- package/dist/{cursor-catalog-DEzan4IT.js.map → cursor-catalog-CRsFxorF.js.map} +1 -1
- package/dist/db-3o8s2EyD.js +2 -0
- package/dist/{db-BzOJ4Js4.js → db-ErnJ-gMD.js} +168 -248
- package/dist/db-ErnJ-gMD.js.map +1 -0
- package/dist/debug-CIXzB4wK.js.map +1 -1
- package/dist/{default-effort-BDKIxJyC.js → default-effort-D70cTG00.js} +4 -4
- package/dist/{default-effort-BDKIxJyC.js.map → default-effort-D70cTG00.js.map} +1 -1
- package/dist/{default-effort-BBDPbJ4D.js → default-effort-DHzj84dD.js} +1 -1
- package/dist/{dist-Db7ifchA.js → dist-DeqeCUZe.js} +5 -5
- package/dist/{dist-Db7ifchA.js.map → dist-DeqeCUZe.js.map} +1 -1
- package/dist/{docker-DFrjoNs-.js → docker-CFWzZOEk.js} +4 -4
- package/dist/{docker-DFrjoNs-.js.map → docker-CFWzZOEk.js.map} +1 -1
- package/dist/docker-DrMnpL84.js +1 -0
- package/dist/{doctor-DWK4ttex.js → doctor-B7utCSdh.js} +121 -100
- package/dist/doctor-B7utCSdh.js.map +1 -0
- package/dist/{environment-cPMCOk-h.js → environment-C0Gg8kyN.js} +49 -11
- package/dist/environment-C0Gg8kyN.js.map +1 -0
- package/dist/{errors-BZgLSZtV.js → errors-C1GBcWE2.js} +2 -2
- package/dist/{errors-BZgLSZtV.js.map → errors-C1GBcWE2.js.map} +1 -1
- package/dist/{eval-source-C9b1h8L6.js → eval-source-CsW5VIXS.js} +24 -12
- package/dist/eval-source-CsW5VIXS.js.map +1 -0
- package/dist/{evaluate-B12Tosvq.js → evaluate-BHQyAszQ.js} +679 -142
- package/dist/evaluate-BHQyAszQ.js.map +1 -0
- package/dist/{evaluate-COdzf7Hl.d.ts → evaluate-DzHq4EsU.d.ts} +2 -2
- package/dist/fake-bootstrap-VpisF1WE.js +15 -0
- package/dist/fake-bootstrap-VpisF1WE.js.map +1 -0
- package/dist/{files-tiNWe8Ih.js → files-BCraBodb.js} +3 -3
- package/dist/{files-tiNWe8Ih.js.map → files-BCraBodb.js.map} +1 -1
- package/dist/files-BjOJw4sn.js +1 -0
- package/dist/{files-DgXyaAg6.js → files-BrGVs4gY.js} +2 -2
- package/dist/{files-DgXyaAg6.js.map → files-BrGVs4gY.js.map} +1 -1
- package/dist/{files-BOBdC0uI.js → files-BuKWZCzY.js} +6 -6
- package/dist/{files-BOBdC0uI.js.map → files-BuKWZCzY.js.map} +1 -1
- package/dist/files-CAzVG3Rr.js +1 -0
- package/dist/{files-F5EG0WPT.js → files-Cv856jLN.js} +5 -5
- package/dist/{files-F5EG0WPT.js.map → files-Cv856jLN.js.map} +1 -1
- package/dist/files-D-Lir4aE.js +1 -0
- package/dist/files-DRlJ0Xr2.js +1 -0
- package/dist/{files-DlQshsks.js → files-g1watgRC.js} +2 -2
- package/dist/{files-DlQshsks.js.map → files-g1watgRC.js.map} +1 -1
- package/dist/{files-s28a6czq.js → files-qjeqXnfE.js} +143 -20
- package/dist/files-qjeqXnfE.js.map +1 -0
- package/dist/gateway.d.ts +1 -1
- package/dist/{git-BpoqEgDV.js → git-DOrOtAiD.js} +3 -3
- package/dist/{git-BpoqEgDV.js.map → git-DOrOtAiD.js.map} +1 -1
- package/dist/{harness-DXv2gnaT.js → harness-FcTyyPco.js} +17 -8
- package/dist/harness-FcTyyPco.js.map +1 -0
- package/dist/harness-install-Dxho1yaU.js +53 -0
- package/dist/harness-install-Dxho1yaU.js.map +1 -0
- package/dist/{harness-C2berMiM.js → harness-nwnyghJZ.js} +14 -11
- package/dist/{harness-C2berMiM.js.map → harness-nwnyghJZ.js.map} +1 -1
- package/dist/harness.d.ts +11 -8
- package/dist/harness.js +1 -1
- package/dist/{ids-C_advdJA.js → ids-B-JKTCP8.js} +2 -2
- package/dist/{ids-C_advdJA.js.map → ids-B-JKTCP8.js.map} +1 -1
- package/dist/{images-D2jFze2v.js → images-Ch1y1t6_.js} +122 -73
- package/dist/images-Ch1y1t6_.js.map +1 -0
- package/dist/index.d.ts +46 -7
- package/dist/index.js +6 -6
- package/dist/{init-Bi1Q3lRi.js → init-C2HqCwnt.js} +33 -14
- package/dist/init-C2HqCwnt.js.map +1 -0
- package/dist/init-CM9xwyre.js +1 -0
- package/dist/{ink-list-BpfidQ1h.js → ink-list-BbKXElcQ.js} +54 -15
- package/dist/ink-list-BbKXElcQ.js.map +1 -0
- package/dist/inputs-5UIDpjz-.js +190 -0
- package/dist/inputs-5UIDpjz-.js.map +1 -0
- package/dist/inputs-load-C82HOKnb.js +1 -0
- package/dist/inputs-load-CGPyigMC.js +95 -0
- package/dist/inputs-load-CGPyigMC.js.map +1 -0
- package/dist/{invocations-CxGNOlh0.js → invocations-BrZAMuTb.js} +5 -5
- package/dist/{invocations-CxGNOlh0.js.map → invocations-BrZAMuTb.js.map} +1 -1
- package/dist/jiti-radm1Soi.js +52 -0
- package/dist/jiti-radm1Soi.js.map +1 -0
- package/dist/{judge-COMXT1Hx.js → judge-DwzqucLS.js} +17 -12
- package/dist/{judge-COMXT1Hx.js.map → judge-DwzqucLS.js.map} +1 -1
- package/dist/judge.d.ts +3 -1
- package/dist/judge.js +1 -1
- package/dist/{judgments-CzgpsTqv.js → judgments-Cj8bFaDG.js} +2 -2
- package/dist/{judgments-CzgpsTqv.js.map → judgments-Cj8bFaDG.js.map} +1 -1
- package/dist/{layout-Cm85tQYk.js → layout-Czh5wOpz.js} +14 -11
- package/dist/layout-Czh5wOpz.js.map +1 -0
- package/dist/{list-DuThsE28.js → list-B_C0k5ex.js} +33 -19
- package/dist/{list-DuThsE28.js.map → list-B_C0k5ex.js.map} +1 -1
- package/dist/live-C9Et_BVT.js +1 -0
- package/dist/{live-CgYbO4Te.js → live-DGgIrVw0.js} +7 -5
- package/dist/live-DGgIrVw0.js.map +1 -0
- package/dist/{live-DL0se4Zd.js → live-DgFm0H90.js} +9 -9
- package/dist/{live-DL0se4Zd.js.map → live-DgFm0H90.js.map} +1 -1
- package/dist/machine-service-2lIv5UWF.js +1 -0
- package/dist/machine-service-Ct_1XMMi.js +520 -0
- package/dist/machine-service-Ct_1XMMi.js.map +1 -0
- package/dist/machines-BnquHcBZ.js +120 -0
- package/dist/machines-BnquHcBZ.js.map +1 -0
- package/dist/{model-CkNVAxob.js → model-B1tdv9-d.js} +1 -1
- package/dist/model-Bcy4Qjmm.js +1 -0
- package/dist/{model-V3mMXp6x.js → model-DF77SgZv.js} +6 -6
- package/dist/{model-V3mMXp6x.js.map → model-DF77SgZv.js.map} +1 -1
- package/dist/{model-CwwkrCb7.js → model-DRa7yv6K.js} +9 -6
- package/dist/model-DRa7yv6K.js.map +1 -0
- package/dist/{model-cgt5uvu8.js → model-E5X8YBJM.js} +7 -6
- package/dist/model-E5X8YBJM.js.map +1 -0
- package/dist/model-calls-B0BoQfJ4.js +95 -0
- package/dist/model-calls-B0BoQfJ4.js.map +1 -0
- package/dist/{node-D7pAU--0.js → node-BjuhqQwa.js} +21 -10
- package/dist/node-BjuhqQwa.js.map +1 -0
- package/dist/{opencode-providers-BGiXt8_B.js → opencode-providers-ChJTQRmz.js} +5 -2
- package/dist/{opencode-providers-BGiXt8_B.js.map → opencode-providers-ChJTQRmz.js.map} +1 -1
- package/dist/{openrouter-models-Cw1z8-sq.js → openrouter-models-B1sIOTD2.js} +2 -2
- package/dist/{openrouter-models-Cw1z8-sq.js.map → openrouter-models-B1sIOTD2.js.map} +1 -1
- package/dist/options-C989kuVE.js +1 -0
- package/dist/own-reads-CYmBlrHK.js +15 -0
- package/dist/own-reads-CYmBlrHK.js.map +1 -0
- package/dist/{patch-DAi1nCuH.js → patch-BR8rdl7r.js} +2 -2
- package/dist/{patch-DAi1nCuH.js.map → patch-BR8rdl7r.js.map} +1 -1
- package/dist/pi-providers-HygmL1y-.js +552 -0
- package/dist/pi-providers-HygmL1y-.js.map +1 -0
- package/dist/{plain-BYUf_fUV.js → plain-Ctn8oUdp.js} +44 -10
- package/dist/plain-Ctn8oUdp.js.map +1 -0
- package/dist/{plan-CsPilzpk.js → plan-BcT4G5jj.js} +104 -15
- package/dist/plan-BcT4G5jj.js.map +1 -0
- package/dist/{plugins-BfnhazOv.js → plugins-cC0sqoDA.js} +608 -12
- package/dist/plugins-cC0sqoDA.js.map +1 -0
- package/dist/preflight-BMVDBcux.js +1 -0
- package/dist/{preflight-BixaE4BA.js → preflight-C9OtTb7k.js} +4 -4
- package/dist/{preflight-BixaE4BA.js.map → preflight-C9OtTb7k.js.map} +1 -1
- package/dist/{preflight-GkpgrBxP.js → preflight-DySHXeFJ.js} +9 -10
- package/dist/preflight-DySHXeFJ.js.map +1 -0
- package/dist/{preflight-D1C-iH0U.js → preflight-zsAn3heN.js} +1 -1
- package/dist/{prepare-C--rM_wO.js → prepare-MaRWRhNT.js} +2 -2
- package/dist/prepare-nbX1CXXg.js +409 -0
- package/dist/prepare-nbX1CXXg.js.map +1 -0
- package/dist/prices-B1vm_lPk.js +1 -0
- package/dist/{prices-5m3SzMZ3.js → prices-BrY_ihLs.js} +80 -22
- package/dist/prices-BrY_ihLs.js.map +1 -0
- package/dist/{provenance-BXyYwUC8.js → provenance-CkykifD9.js} +5 -5
- package/dist/{provenance-BXyYwUC8.js.map → provenance-CkykifD9.js.map} +1 -1
- package/dist/provider-DHT20Gl8.js +1 -0
- package/dist/{provider-BxzZq3Th.js → provider-ieWOn4YS.js} +2 -2
- package/dist/{provider-BxzZq3Th.js.map → provider-ieWOn4YS.js.map} +1 -1
- package/dist/provider-stop-CxzWW7Ft.js +69 -0
- package/dist/provider-stop-CxzWW7Ft.js.map +1 -0
- package/dist/providers-BkLGzaSY.js +1 -0
- package/dist/{providers-1p4HKYIp.js → providers-bNgfKa6m.js} +224 -49
- package/dist/providers-bNgfKa6m.js.map +1 -0
- package/dist/query-B2SQddoV.js +1 -0
- package/dist/{query-DhhU9ADI.js → query-DhV3a8lM.js} +2 -2
- package/dist/{query-DhhU9ADI.js.map → query-DhV3a8lM.js.map} +1 -1
- package/dist/{questions-CMAq4pr8.js → questions-Csv64WCb.js} +7 -7
- package/dist/{questions-CMAq4pr8.js.map → questions-Csv64WCb.js.map} +1 -1
- package/dist/{record-6IUzwP9K.js → record--vHreTLk.js} +11 -5
- package/dist/record--vHreTLk.js.map +1 -0
- package/dist/{redact-BhjtnjrU.js → redact-t-L3VGy8.js} +106 -2
- package/dist/redact-t-L3VGy8.js.map +1 -0
- package/dist/{remarks-D9Lcd1fF.js → remarks-BpdM_2RC.js} +2 -1
- package/dist/remarks-BpdM_2RC.js.map +1 -0
- package/dist/{remarks-BNABzemt.js → remarks-CYFOsnz5.js} +46 -11
- package/dist/remarks-CYFOsnz5.js.map +1 -0
- package/dist/remarks-CleoDlYw.js +1 -0
- package/dist/{remarks-DPCONFxZ.js → remarks-DqriPKxm.js} +3 -2
- package/dist/{remarks-DPCONFxZ.js.map → remarks-DqriPKxm.js.map} +1 -1
- package/dist/{remote-U7fNt0UP.js → remote-0CHog7Oq.js} +6 -6
- package/dist/{remote-U7fNt0UP.js.map → remote-0CHog7Oq.js.map} +1 -1
- package/dist/resolve-Bm9ZyFR-.js +1 -0
- package/dist/resolve-Bul8lHaa.js +205 -0
- package/dist/resolve-Bul8lHaa.js.map +1 -0
- package/dist/{resolve-Cx3a9UQ2.js → resolve-DorSHDBs.js} +14 -11
- package/dist/resolve-DorSHDBs.js.map +1 -0
- package/dist/resources-DqdwihhT.js +62 -0
- package/dist/resources-DqdwihhT.js.map +1 -0
- package/dist/{results-CQKXmHym.js → results-DhMgRkR0.js} +9 -22
- package/dist/results-DhMgRkR0.js.map +1 -0
- package/dist/{resume-POpZa1ge.js → resume-C8Ihfy-C.js} +166 -17
- package/dist/resume-C8Ihfy-C.js.map +1 -0
- package/dist/{retry-CmG809Mp.js → retry-Bfk7pDti.js} +4 -4
- package/dist/{retry-CmG809Mp.js.map → retry-Bfk7pDti.js.map} +1 -1
- package/dist/{root-Co0jhOT5.js → root-BzeoyfGd.js} +2 -2
- package/dist/{root-Co0jhOT5.js.map → root-BzeoyfGd.js.map} +1 -1
- package/dist/routes-Cp4gAjBZ.js +427 -0
- package/dist/routes-Cp4gAjBZ.js.map +1 -0
- package/dist/{runtime-Xm9oeC7o.js → runtime-CPUH0Vk5.js} +46 -5
- package/dist/runtime-CPUH0Vk5.js.map +1 -0
- package/dist/sandbox/boat.d.ts +1 -1
- package/dist/sandbox/boat.js +1 -1
- package/dist/{sandbox-DrlL4yqb.js → sandbox-z8q_4Ywn.js} +3 -3
- package/dist/{sandbox-DrlL4yqb.js.map → sandbox-z8q_4Ywn.js.map} +1 -1
- package/dist/sandbox.d.ts +1 -1
- package/dist/sandbox.js +1 -1
- package/dist/{server-C00zd6zl.js → server-BsQZtuF9.js} +9 -9
- package/dist/{server-C00zd6zl.js.map → server-BsQZtuF9.js.map} +1 -1
- package/dist/server-ZaMzUNmV.js +1 -0
- package/dist/services-BG8xuU82.js +39 -0
- package/dist/services-BG8xuU82.js.map +1 -0
- package/dist/{shared-Cfi45Bvy.js → shared-DtZwIAfy.js} +7 -1
- package/dist/shared-DtZwIAfy.js.map +1 -0
- package/dist/{source-DDgr48Gn.js → source-9HWaTEgV.js} +2 -2
- package/dist/{source-DDgr48Gn.js.map → source-9HWaTEgV.js.map} +1 -1
- package/dist/source-BcBDj-R0.js +1 -0
- package/dist/src-B2eHTCnp.js +3 -0
- package/dist/{src-DAzaCTcN.js → src-B5r1d23Y.js} +176 -18
- package/dist/src-B5r1d23Y.js.map +1 -0
- package/dist/{src-Dw79VLa3.js → src-Bb3k9Kn_.js} +208 -59
- package/dist/src-Bb3k9Kn_.js.map +1 -0
- package/dist/src-BfOlH_Bu.js +2 -0
- package/dist/src-BuGc40IF.js +2 -0
- package/dist/{src-CV_7DkPa.js → src-C-ChdnG6.js} +102 -13
- package/dist/src-C-ChdnG6.js.map +1 -0
- package/dist/src-C2K5_afU.js +2 -0
- package/dist/{src-YvblOrBU.js → src-C3OhA5pw.js} +87 -13
- package/dist/src-C3OhA5pw.js.map +1 -0
- package/dist/src-CSVJjghq.js +4 -0
- package/dist/{src-y0nOeRRE.js → src-CWfy8ct8.js} +1572 -487
- package/dist/src-CWfy8ct8.js.map +1 -0
- package/dist/src-CcrQQB0_.js +2 -0
- package/dist/src-CotUxxQV.js +2 -0
- package/dist/src-D-PwBaBB.js +2 -0
- package/dist/{src-Cb2MWozp.js → src-DNWiU__5.js} +276 -41
- package/dist/src-DNWiU__5.js.map +1 -0
- package/dist/{src-KxS91P7L.js → src-DwcTn4JY.js} +79 -11
- package/dist/src-DwcTn4JY.js.map +1 -0
- package/dist/{src-BNQznj4z.js → src-boB6D-5T.js} +124 -45
- package/dist/src-boB6D-5T.js.map +1 -0
- package/dist/{src-DvGns8cz.js → src-c3ZQu7Uu.js} +299 -17
- package/dist/src-c3ZQu7Uu.js.map +1 -0
- package/dist/src-jYqNkT-F.js +1 -0
- package/dist/start-Db5VRcRZ.js +660 -0
- package/dist/start-Db5VRcRZ.js.map +1 -0
- package/dist/state-CKIjZZRK.js +1 -0
- package/dist/{state-328JpnHA.js → state-DUYdzNA7.js} +21 -21
- package/dist/{state-328JpnHA.js.map → state-DUYdzNA7.js.map} +1 -1
- package/dist/store/local.d.ts +8 -0
- package/dist/store/local.js +16 -0
- package/dist/store/local.js.map +1 -0
- package/dist/store/s3.d.ts +10 -0
- package/dist/store/s3.js +18 -0
- package/dist/store/s3.js.map +1 -0
- package/dist/suite-CH1aaAbs.js +2 -0
- package/dist/{suite-COglUhPd.js → suite-DjGxmDSY.js} +6 -5
- package/dist/{suite-COglUhPd.js.map → suite-DjGxmDSY.js.map} +1 -1
- package/dist/{summary-DDy9DfyJ.js → summary-BK5Sa_N0.js} +28 -7
- package/dist/summary-BK5Sa_N0.js.map +1 -0
- package/dist/sync-DUi_P2UJ.js +559 -0
- package/dist/sync-DUi_P2UJ.js.map +1 -0
- package/dist/{tarball-CESxtK4X.js → tarball-C8BSTAMk.js} +2 -2
- package/dist/{tarball-CESxtK4X.js.map → tarball-C8BSTAMk.js.map} +1 -1
- package/dist/tart-BQ_Ap0l4.js +508 -0
- package/dist/tart-BQ_Ap0l4.js.map +1 -0
- package/dist/tart-CzViW3WZ.js +186 -0
- package/dist/tart-CzViW3WZ.js.map +1 -0
- package/dist/tart-DmVuVsmX.js +1 -0
- package/dist/tart-bake-D1RttYfM.js +148 -0
- package/dist/tart-bake-D1RttYfM.js.map +1 -0
- package/dist/tart-bake-DjFcsG3N.js +1 -0
- package/dist/tart-cli-BOcluha1.js +1 -0
- package/dist/tart-cli-gA9xEaQL.js +89 -0
- package/dist/tart-cli-gA9xEaQL.js.map +1 -0
- package/dist/tart-hosts-CHNrfV6u.js +313 -0
- package/dist/tart-hosts-CHNrfV6u.js.map +1 -0
- package/dist/tart-hosts-CWse-ASo.js +1 -0
- package/dist/{tart-images-DZ_Mbh-g.js → tart-images-CLBjfF9u.js} +64 -6
- package/dist/tart-images-CLBjfF9u.js.map +1 -0
- package/dist/testing.d.ts +36 -2
- package/dist/testing.js +4 -4
- package/dist/tool-class-krsmEo44.js +433 -0
- package/dist/tool-class-krsmEo44.js.map +1 -0
- package/dist/{trace-Dx2NBE1O.js → trace-BpXByD7W.js} +13 -2
- package/dist/{trace-Dx2NBE1O.js.map → trace-BpXByD7W.js.map} +1 -1
- package/dist/{traits-DKnYkqeK.js → traits-CCD8XsmI.js} +2 -2
- package/dist/{traits-DKnYkqeK.js.map → traits-CCD8XsmI.js.map} +1 -1
- package/dist/{transcript-CCf07UmU.js → transcript-BXWZiMuC.js} +3 -3
- package/dist/{transcript-CCf07UmU.js.map → transcript-BXWZiMuC.js.map} +1 -1
- package/dist/{types-C2mLpph3.js → types-CbcnJxCy.js} +7 -1
- package/dist/types-CbcnJxCy.js.map +1 -0
- package/dist/{types-DBwFsGem.d.ts → types-DKK8jj--.d.ts} +517 -45
- package/dist/ui-DKYjTVpn.js +1455 -0
- package/dist/ui-DKYjTVpn.js.map +1 -0
- package/dist/{usage-DJiDnh2D.js → usage-CwIRPPZ9.js} +16 -3
- package/dist/usage-CwIRPPZ9.js.map +1 -0
- package/dist/vercel-models-Ci33llXz.js +21 -0
- package/dist/vercel-models-Ci33llXz.js.map +1 -0
- package/dist/{vertex-Eb2wqahk.js → vertex-BEWxHoxH.js} +22 -6
- package/dist/{vertex-Eb2wqahk.js.map → vertex-BEWxHoxH.js.map} +1 -1
- package/dist/vertex-DXfcXYKn.js +1 -0
- package/dist/view/index.d.ts +32 -3
- package/dist/view/index.js +8 -8
- package/dist/{views-BROacjBv.js → views-B1zVLJsF.js} +6 -6
- package/dist/{views-BROacjBv.js.map → views-B1zVLJsF.js.map} +1 -1
- package/dist/views-DCjtw1jF.js +2 -0
- package/dist/{worker-entry-Smb4bNDc.js → worker-entry-DrAYYt0M.js} +37 -14
- package/dist/worker-entry-DrAYYt0M.js.map +1 -0
- package/dist/workspace-CnRbV8cM.js +1 -0
- package/dist/{workspace-DNDTEk8v.js → workspace-DwTe1zo6.js} +7 -7
- package/dist/{workspace-DNDTEk8v.js.map → workspace-DwTe1zo6.js.map} +1 -1
- package/docker/Dockerfile +1 -1
- package/package.json +15 -1
- package/skills/eval-rubric/SKILL.md +10 -0
- package/skills/reeval/SKILL.md +370 -0
- package/skills/reeval/references/capture.md +48 -0
- package/skills/reeval/references/cli.md +162 -0
- package/skills/reeval/references/compare.md +180 -0
- package/skills/reeval/references/config.md +147 -0
- package/skills/reeval/references/environments.md +218 -0
- package/skills/reeval/references/evals.md +241 -0
- package/skills/reeval/references/mistakes.md +39 -0
- package/skills/reeval/references/vocabulary.md +19 -0
- package/skills/setup/SKILL.md +219 -0
- package/skills/setup/references/templates.md +258 -0
- package/dist/adapter-C60z3wLq.js.map +0 -1
- package/dist/agent-BmsMXZXx.js.map +0 -1
- package/dist/agents-DXuFxtGC.js.map +0 -1
- package/dist/app-files-DT5mJyV4.js.map +0 -1
- package/dist/assemble-DM2PNU4R.js.map +0 -1
- package/dist/attempt-host-7VviAJrl.js.map +0 -1
- package/dist/boat-BjLqFJIZ.js.map +0 -1
- package/dist/boat-DSNgZt-t.js +0 -322
- package/dist/boat-DSNgZt-t.js.map +0 -1
- package/dist/capture-BzotD2hs.js +0 -1
- package/dist/capture-Ccf0Hmyx.js.map +0 -1
- package/dist/cases-Dy0mifal.js +0 -1
- package/dist/cases-z9E6DCd5.js.map +0 -1
- package/dist/cli-DTuLSlmW.js.map +0 -1
- package/dist/cli-spec-Dsr79Qy1.js.map +0 -1
- package/dist/client-KM4C5r5_.js +0 -387
- package/dist/client-KM4C5r5_.js.map +0 -1
- package/dist/command-DSL7I-SI.js.map +0 -1
- package/dist/command-Ff0T-1Hi.js.map +0 -1
- package/dist/commands-xAOi_VEk.js.map +0 -1
- package/dist/config-SvK8pjEK.js.map +0 -1
- package/dist/cost-BdRgySQl.js.map +0 -1
- package/dist/cost-Cr26Alhq.js +0 -1
- package/dist/db-BzOJ4Js4.js.map +0 -1
- package/dist/db-CQRZ3URX.js +0 -2
- package/dist/docker--mukta3L.js +0 -1
- package/dist/docker-DG_uFgn2.js +0 -246
- package/dist/docker-DG_uFgn2.js.map +0 -1
- package/dist/doctor-DWK4ttex.js.map +0 -1
- package/dist/environment-cPMCOk-h.js.map +0 -1
- package/dist/eval-source-C9b1h8L6.js.map +0 -1
- package/dist/evaluate-B12Tosvq.js.map +0 -1
- package/dist/files-C1Rk9FYA.js +0 -1
- package/dist/files-DMQ9-Vv5.js +0 -1
- package/dist/files-Di0xDbCc.js +0 -1
- package/dist/files-G5jf8wBp.js +0 -1
- package/dist/files-s28a6czq.js.map +0 -1
- package/dist/harness-DXv2gnaT.js.map +0 -1
- package/dist/images-D2jFze2v.js.map +0 -1
- package/dist/init-Bi1Q3lRi.js.map +0 -1
- package/dist/init-CUw65o36.js +0 -1
- package/dist/ink-list-BpfidQ1h.js.map +0 -1
- package/dist/kinds-Bh2I35id.js +0 -698
- package/dist/kinds-Bh2I35id.js.map +0 -1
- package/dist/layout-Cm85tQYk.js.map +0 -1
- package/dist/live-CgYbO4Te.js.map +0 -1
- package/dist/live-DZLmj0iG.js +0 -1
- package/dist/matchers-CXLn-1jm.js +0 -148
- package/dist/matchers-CXLn-1jm.js.map +0 -1
- package/dist/model-Cv4GuTsZ.js +0 -1
- package/dist/model-CwwkrCb7.js.map +0 -1
- package/dist/model-cgt5uvu8.js.map +0 -1
- package/dist/node-D7pAU--0.js.map +0 -1
- package/dist/options-DPUmk7v_.js +0 -1
- package/dist/plain-BYUf_fUV.js.map +0 -1
- package/dist/plan-CsPilzpk.js.map +0 -1
- package/dist/plugins-BfnhazOv.js.map +0 -1
- package/dist/preflight-Bn3ianye.js +0 -1
- package/dist/preflight-GkpgrBxP.js.map +0 -1
- package/dist/prepare-DQEDXoDp.js +0 -268
- package/dist/prepare-DQEDXoDp.js.map +0 -1
- package/dist/prices-5m3SzMZ3.js.map +0 -1
- package/dist/provider-BnUoz4KB.js +0 -1
- package/dist/providers-1p4HKYIp.js.map +0 -1
- package/dist/providers-B-ijCktf.js +0 -1
- package/dist/query-BYhyf0LR.js +0 -1
- package/dist/record-6IUzwP9K.js.map +0 -1
- package/dist/redact-BhjtnjrU.js.map +0 -1
- package/dist/remarks-BNABzemt.js.map +0 -1
- package/dist/remarks-CAvTSq16.js +0 -1
- package/dist/remarks-D9Lcd1fF.js.map +0 -1
- package/dist/resolve-C14Pmtej.js +0 -1
- package/dist/resolve-Cx3a9UQ2.js.map +0 -1
- package/dist/results-CQKXmHym.js.map +0 -1
- package/dist/resume-POpZa1ge.js.map +0 -1
- package/dist/runtime-Xm9oeC7o.js.map +0 -1
- package/dist/server-C1UJcpUh.js +0 -1
- package/dist/shared-Cfi45Bvy.js.map +0 -1
- package/dist/source-DJHmQv_j.js +0 -1
- package/dist/src-1dBuXzs4.js +0 -3
- package/dist/src-BKpioayC.js +0 -2
- package/dist/src-BNQznj4z.js.map +0 -1
- package/dist/src-BY1cCaoJ.js +0 -2
- package/dist/src-BbZYaQ8b.js +0 -2
- package/dist/src-CDFH2vVN.js +0 -2
- package/dist/src-CMW5R9Q0.js +0 -1
- package/dist/src-CV_7DkPa.js.map +0 -1
- package/dist/src-Cb2MWozp.js.map +0 -1
- package/dist/src-CrV2WA2i.js +0 -2
- package/dist/src-CsFaawcZ.js +0 -2
- package/dist/src-DAzaCTcN.js.map +0 -1
- package/dist/src-DvGns8cz.js.map +0 -1
- package/dist/src-Dw79VLa3.js.map +0 -1
- package/dist/src-KxS91P7L.js.map +0 -1
- package/dist/src-YvblOrBU.js.map +0 -1
- package/dist/src-wKwznPgt.js +0 -2
- package/dist/src-y0nOeRRE.js.map +0 -1
- package/dist/state-Ca55Gk_O.js +0 -1
- package/dist/suite-CKBa6MKt.js +0 -2
- package/dist/summary-DDy9DfyJ.js.map +0 -1
- package/dist/tart-cli-C-GsbVsQ.js +0 -1
- package/dist/tart-cli-CU0nFS-L.js +0 -55
- package/dist/tart-cli-CU0nFS-L.js.map +0 -1
- package/dist/tart-dWoJvWHc.js +0 -586
- package/dist/tart-dWoJvWHc.js.map +0 -1
- package/dist/tart-images-DZ_Mbh-g.js.map +0 -1
- package/dist/tool-target-DS5d72eH.js +0 -40
- package/dist/tool-target-DS5d72eH.js.map +0 -1
- package/dist/types-C2mLpph3.js.map +0 -1
- package/dist/usage-DJiDnh2D.js.map +0 -1
- package/dist/vercel-CGlSBv63.js +0 -344
- package/dist/vercel-CGlSBv63.js.map +0 -1
- package/dist/vertex-O88TCwgY.js +0 -1
- package/dist/views-B0Yt_Q1S.js +0 -2
- package/dist/worker-entry-Smb4bNDc.js.map +0 -1
- package/dist/workspace-C0dDP75l.js +0 -1
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { u as ownFileURL } from "./root-
|
|
2
|
-
import { existsSync, lstatSync, readFileSync, readdirSync, readlinkSync, renameSync, writeFileSync } from "node:fs";
|
|
3
|
-
import { tmpdir } from "node:os";
|
|
1
|
+
import { u as ownFileURL } from "./root-BzeoyfGd.js";
|
|
2
|
+
import { existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, readlinkSync, renameSync, writeFileSync } from "node:fs";
|
|
4
3
|
import { basename, dirname, join, posix, relative, win32 } from "node:path";
|
|
5
|
-
import
|
|
4
|
+
import { execFileSync, spawn } from "node:child_process";
|
|
6
5
|
import { createHash, generateKeyPairSync, randomBytes, randomInt, sign } from "node:crypto";
|
|
6
|
+
import { tmpdir } from "node:os";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
|
-
import { execFileSync, spawn } from "node:child_process";
|
|
9
8
|
import { createHarnessSandboxTemplate } from "@ai-sdk/harness/agent";
|
|
10
9
|
import { isUtf8 } from "node:buffer";
|
|
11
10
|
import dockerignore from "@balena/dockerignore";
|
|
12
11
|
import { Duplex, Readable, Transform } from "node:stream";
|
|
12
|
+
import net, { BlockList, isIP } from "node:net";
|
|
13
13
|
import http from "node:http";
|
|
14
14
|
import http2 from "node:http2";
|
|
15
15
|
import https from "node:https";
|
|
@@ -290,7 +290,7 @@ function windowsSpawn(cmd, args, env = process.env, exists = existsSync) {
|
|
|
290
290
|
* Kills a process and everything it started: its process group on POSIX (a detached child leads
|
|
291
291
|
* one), its process tree with `taskkill` on Windows, which has neither groups nor signals.
|
|
292
292
|
*/
|
|
293
|
-
function killTree(pid) {
|
|
293
|
+
function killTree$1(pid) {
|
|
294
294
|
if (process.platform === "win32") {
|
|
295
295
|
spawn("taskkill", [
|
|
296
296
|
"/pid",
|
|
@@ -344,7 +344,7 @@ function run(cmd, args, options = {}) {
|
|
|
344
344
|
stderr += d;
|
|
345
345
|
});
|
|
346
346
|
const onAbort = () => {
|
|
347
|
-
if ((detached || process.platform === "win32") && child.pid) killTree(child.pid);
|
|
347
|
+
if ((detached || process.platform === "win32") && child.pid) killTree$1(child.pid);
|
|
348
348
|
else child.kill("SIGKILL");
|
|
349
349
|
};
|
|
350
350
|
signal?.addEventListener("abort", onAbort, { once: true });
|
|
@@ -680,7 +680,7 @@ async function imageInfo(image, engine) {
|
|
|
680
680
|
"image",
|
|
681
681
|
"inspect",
|
|
682
682
|
"--format",
|
|
683
|
-
`{"config":{{json .Config}},"id":{{json ${imageId}}},"repoDigests":{{json .RepoDigests}}}`,
|
|
683
|
+
`{"config":{{json .Config}},"id":{{json ${imageId}}},"repoDigests":{{json .RepoDigests}},"os":{{json .Os}},"arch":{{json .Architecture}}}`,
|
|
684
684
|
image
|
|
685
685
|
], { engine }).catch((error) => {
|
|
686
686
|
throw new Error(`${bin} image inspect ${image} couldn't run: ${error.message}`);
|
|
@@ -692,10 +692,12 @@ async function imageInfo(image, engine) {
|
|
|
692
692
|
}
|
|
693
693
|
const info = JSON.parse(r.stdout.toString("utf8"));
|
|
694
694
|
const repoDigests = (info.repoDigests ?? []).filter(isRegistryDigest);
|
|
695
|
+
const platform = info.os && info.arch ? `${info.os}/${info.arch}` : null;
|
|
695
696
|
return {
|
|
696
697
|
labels: info.config?.Labels ?? {},
|
|
697
698
|
id: normalizeImageId(info.id),
|
|
698
|
-
repoDigests
|
|
699
|
+
repoDigests,
|
|
700
|
+
platform
|
|
699
701
|
};
|
|
700
702
|
}
|
|
701
703
|
// ../sandbox-docker/src/dockerignore.ts
|
|
@@ -791,48 +793,118 @@ function contextFiles(context, dockerfile) {
|
|
|
791
793
|
}
|
|
792
794
|
// ../sandbox-docker/src/image.ts
|
|
793
795
|
/**
|
|
794
|
-
* The harness adapters an image can bake. Each pin must match the exact
|
|
795
|
-
* `workspace:<version>` for this repo's own adapters); a test enforces it. `patch`
|
|
796
|
-
* hex of the sha256 of the adapter's pnpm patch (`patchedDependencies` in
|
|
797
|
-
* whose bridge the image bakes; a test holds it to the patch file.
|
|
796
|
+
* The harness adapters an image can bake, and each one's bootstrap. Each pin must match the exact
|
|
797
|
+
* dependency (or `workspace:<version>` for this repo's own adapters); a test enforces it. `patch`
|
|
798
|
+
* is the first 8 hex of the sha256 of the adapter's pnpm patch (`patchedDependencies` in
|
|
799
|
+
* pnpm-workspace.yaml), whose bridge the image bakes; a test holds it to the patch file.
|
|
798
800
|
*/
|
|
799
801
|
const HARNESS_PACKAGES = {
|
|
800
802
|
cursor: {
|
|
801
803
|
name: "@reeval/harness-cursor-sdk",
|
|
802
|
-
version: "0.1.
|
|
804
|
+
version: "0.1.9",
|
|
805
|
+
bootstrap: {
|
|
806
|
+
name: "Cursor",
|
|
807
|
+
cli: "@cursor/sdk",
|
|
808
|
+
probe: `node -p "'@cursor/sdk ' + require(process.env.HOME + '/.ai-sdk-harness/.harness-bootstrap/cursor-sdk/node_modules/@cursor/sdk/package.json').version"`,
|
|
809
|
+
adapter: async () => (await import("./src-BuGc40IF.js")).createCursorSdk()
|
|
810
|
+
}
|
|
803
811
|
},
|
|
804
812
|
"claude-code": {
|
|
805
813
|
name: "@ai-sdk/harness-claude-code",
|
|
806
814
|
version: "1.0.176",
|
|
807
|
-
patch: "
|
|
815
|
+
patch: "a9d56a8c",
|
|
816
|
+
bootstrap: {
|
|
817
|
+
name: "Claude Code",
|
|
818
|
+
cli: "claude",
|
|
819
|
+
adapter: async () => (await import("./dist-DeqeCUZe.js")).createClaudeCode()
|
|
820
|
+
}
|
|
808
821
|
},
|
|
809
822
|
antigravity: {
|
|
810
823
|
name: "@reeval/harness-antigravity",
|
|
811
|
-
version: "0.1.
|
|
824
|
+
version: "0.1.16",
|
|
825
|
+
bootstrap: {
|
|
826
|
+
name: "Antigravity",
|
|
827
|
+
cli: "agy",
|
|
828
|
+
adapter: async () => (await import("./src-CotUxxQV.js")).createAntigravity()
|
|
829
|
+
}
|
|
812
830
|
},
|
|
813
831
|
opencode: {
|
|
814
832
|
name: "@reeval/harness-opencode",
|
|
815
|
-
version: "0.2.16"
|
|
833
|
+
version: "0.2.16",
|
|
834
|
+
bootstrap: {
|
|
835
|
+
name: "OpenCode",
|
|
836
|
+
cli: "opencode",
|
|
837
|
+
adapter: async () => (await import("./src-B2eHTCnp.js")).createOpenCode({
|
|
838
|
+
auth: { GOOGLE_GENERATIVE_AI_API_KEY: "unused" },
|
|
839
|
+
model: "google/unused"
|
|
840
|
+
})
|
|
841
|
+
}
|
|
816
842
|
},
|
|
817
843
|
goose: {
|
|
818
844
|
name: "@reeval/harness-goose",
|
|
819
|
-
version: "0.1.
|
|
845
|
+
version: "0.1.16",
|
|
846
|
+
bootstrap: {
|
|
847
|
+
name: "Goose",
|
|
848
|
+
cli: "goose",
|
|
849
|
+
adapter: async () => {
|
|
850
|
+
const goose = await import("./src-BfOlH_Bu.js");
|
|
851
|
+
return goose.createGoose({
|
|
852
|
+
auth: { GOOGLE_API_KEY: "unused" },
|
|
853
|
+
provider: goose.GEMINI_PROVIDER,
|
|
854
|
+
model: "unused"
|
|
855
|
+
});
|
|
856
|
+
}
|
|
857
|
+
}
|
|
820
858
|
},
|
|
821
859
|
pi: {
|
|
822
860
|
name: "@reeval/harness-pi",
|
|
823
|
-
version: "0.2.9"
|
|
861
|
+
version: "0.2.9",
|
|
862
|
+
bootstrap: {
|
|
863
|
+
name: "pi",
|
|
864
|
+
cli: "pi",
|
|
865
|
+
adapter: async () => {
|
|
866
|
+
const pi = await import("./src-CSVJjghq.js");
|
|
867
|
+
const provider = pi.piProvider("google");
|
|
868
|
+
if ("refused" in provider) throw new Error(provider.refused);
|
|
869
|
+
return pi.createPi({
|
|
870
|
+
auth: { GEMINI_API_KEY: "unused" },
|
|
871
|
+
provider
|
|
872
|
+
});
|
|
873
|
+
}
|
|
874
|
+
}
|
|
824
875
|
},
|
|
825
876
|
codex: {
|
|
826
877
|
name: "@reeval/harness-codex",
|
|
827
|
-
version: "0.1.
|
|
878
|
+
version: "0.1.13",
|
|
879
|
+
bootstrap: {
|
|
880
|
+
name: "Codex",
|
|
881
|
+
cli: "codex",
|
|
882
|
+
adapter: async () => (await import("./src-CcrQQB0_.js")).createCodex({ auth: { OPENAI_API_KEY: "unused" } })
|
|
883
|
+
}
|
|
828
884
|
},
|
|
829
885
|
fx: {
|
|
830
886
|
name: "@reeval/harness-fx",
|
|
831
|
-
version: "0.1.
|
|
887
|
+
version: "0.1.11",
|
|
888
|
+
bootstrap: {
|
|
889
|
+
name: "fx",
|
|
890
|
+
cli: "fx",
|
|
891
|
+
adapter: async () => (await import("./src-D-PwBaBB.js")).createFx({
|
|
892
|
+
auth: { AI_GATEWAY_API_KEY: "unused" },
|
|
893
|
+
model: "unused/unused"
|
|
894
|
+
})
|
|
895
|
+
}
|
|
832
896
|
},
|
|
833
897
|
"grok-build": {
|
|
834
898
|
name: "@reeval/harness-grok-build",
|
|
835
|
-
version: "0.1.
|
|
899
|
+
version: "0.1.12",
|
|
900
|
+
bootstrap: {
|
|
901
|
+
name: "Grok Build",
|
|
902
|
+
cli: "grok",
|
|
903
|
+
adapter: async () => (await import("./src-C2K5_afU.js")).createGrokBuild({
|
|
904
|
+
auth: { XAI_API_KEY: "unused" },
|
|
905
|
+
model: "unused"
|
|
906
|
+
})
|
|
907
|
+
}
|
|
836
908
|
}
|
|
837
909
|
};
|
|
838
910
|
/** Every harness with an image, in {@link HARNESS_PACKAGES} order. */
|
|
@@ -860,7 +932,9 @@ const LABEL = {
|
|
|
860
932
|
/** On reeval's own images: the hash of the base image's build context, to tell a stale one. */
|
|
861
933
|
context: "ai.reeval.context",
|
|
862
934
|
/** On a `from` image: the digest (or, for a local-only base, the image id) it was built on. */
|
|
863
|
-
fromDigest: "ai.reeval.from-digest"
|
|
935
|
+
fromDigest: "ai.reeval.from-digest",
|
|
936
|
+
/** On every image reeval builds: its content key, which a registry pull must match. */
|
|
937
|
+
key: "ai.reeval.key"
|
|
864
938
|
};
|
|
865
939
|
/**
|
|
866
940
|
* The user the agent, setup steps and checks run as, which every image reeval builds creates. Image
|
|
@@ -879,6 +953,26 @@ const WORKSPACE_DIR = "workspace";
|
|
|
879
953
|
*/
|
|
880
954
|
const SANDBOX_STATE = "/var/lib/reeval";
|
|
881
955
|
const BRIDGE_PORT = 43210;
|
|
956
|
+
/** The egress forwarder's port for slot 0; slot `n` listens on this plus `n`. */
|
|
957
|
+
const BASE_PROXY_PORT = 43128;
|
|
958
|
+
/** Slot `slot`'s layout: slot 0's is {@link SANDBOX_USER}'s, `n` is `reeval-s<n>` in each place. */
|
|
959
|
+
function slotLayout(slot) {
|
|
960
|
+
if (slot === 0) return {
|
|
961
|
+
user: SANDBOX_USER,
|
|
962
|
+
home: SANDBOX_HOME,
|
|
963
|
+
root: SANDBOX_ROOT,
|
|
964
|
+
state: SANDBOX_STATE,
|
|
965
|
+
proxyPort: BASE_PROXY_PORT
|
|
966
|
+
};
|
|
967
|
+
const user = `${SANDBOX_USER}-s${slot}`;
|
|
968
|
+
return {
|
|
969
|
+
user,
|
|
970
|
+
home: `/home/${user}`,
|
|
971
|
+
root: `${SANDBOX_ROOT}-s${slot}`,
|
|
972
|
+
state: `${SANDBOX_STATE}-s${slot}`,
|
|
973
|
+
proxyPort: BASE_PROXY_PORT + slot
|
|
974
|
+
};
|
|
975
|
+
}
|
|
882
976
|
// ../sandbox-docker/src/egress/cert.ts
|
|
883
977
|
const der = (tag, ...content) => {
|
|
884
978
|
const body = Buffer.concat(content);
|
|
@@ -1297,35 +1391,58 @@ function walk(value, keys, at, out) {
|
|
|
1297
1391
|
for (const name of key === "*" ? Object.keys(record).sort() : [key]) if (Object.hasOwn(record, name)) walk(record[name], rest, [...at, name], out);
|
|
1298
1392
|
}
|
|
1299
1393
|
/**
|
|
1300
|
-
*
|
|
1301
|
-
* (
|
|
1302
|
-
*
|
|
1394
|
+
* The tools a request body declares: Anthropic's and OpenAI's `tools` list counts each entry,
|
|
1395
|
+
* and Gemini's (a list, or one object) each of its `functionDeclarations`. 0 when it declares
|
|
1396
|
+
* none.
|
|
1303
1397
|
*/
|
|
1304
|
-
function
|
|
1398
|
+
function toolCount(body) {
|
|
1399
|
+
const declared = (entry) => {
|
|
1400
|
+
if (!entry || typeof entry !== "object") return 1;
|
|
1401
|
+
const record = entry;
|
|
1402
|
+
const functions = record.functionDeclarations ?? record.function_declarations;
|
|
1403
|
+
return Array.isArray(functions) ? functions.length : 1;
|
|
1404
|
+
};
|
|
1405
|
+
const { tools } = body;
|
|
1406
|
+
if (Array.isArray(tools)) return tools.reduce((n, t) => n + declared(t), 0);
|
|
1407
|
+
return tools && typeof tools === "object" ? declared(tools) : 0;
|
|
1408
|
+
}
|
|
1409
|
+
/**
|
|
1410
|
+
* A model call's request body, read once: its reasoning settings (`requestedEffort`) and how
|
|
1411
|
+
* many tools it declares. Both undefined when it isn't a JSON object.
|
|
1412
|
+
*/
|
|
1413
|
+
function requestFacts(body) {
|
|
1305
1414
|
let parsed;
|
|
1306
1415
|
try {
|
|
1307
1416
|
parsed = JSON.parse(body);
|
|
1308
1417
|
} catch {
|
|
1309
|
-
return;
|
|
1418
|
+
return {};
|
|
1310
1419
|
}
|
|
1420
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return {};
|
|
1311
1421
|
const found = [];
|
|
1312
1422
|
for (const path of PATHS) walk(parsed, path.split("."), [], found);
|
|
1313
|
-
return
|
|
1423
|
+
return {
|
|
1424
|
+
...found.length ? { effort: found.map((f) => `${f.path}=${f.value}`).join(" ") } : {},
|
|
1425
|
+
tools: toolCount(parsed)
|
|
1426
|
+
};
|
|
1314
1427
|
}
|
|
1315
1428
|
// ../sandbox-docker/src/egress/policy.ts
|
|
1316
|
-
/**
|
|
1429
|
+
/**
|
|
1430
|
+
* The Docker sandbox enforces every policy through its egress gateway, records what passes, and
|
|
1431
|
+
* switches policy mid-attempt by changing the gateway's and detaching or reattaching networks.
|
|
1432
|
+
*/
|
|
1317
1433
|
const DOCKER_EGRESS = {
|
|
1318
1434
|
enforce: "allowlist",
|
|
1319
|
-
record: true
|
|
1435
|
+
record: true,
|
|
1436
|
+
switches: true
|
|
1320
1437
|
};
|
|
1321
1438
|
/** The hosts each harness's CLI talks to at runtime. */
|
|
1322
1439
|
const HARNESS_HOSTS = {
|
|
1323
1440
|
cursor: ["api2.cursor.sh", "*.cursor.sh"],
|
|
1324
1441
|
"claude-code": ["api.anthropic.com", "*.anthropic.com"],
|
|
1325
1442
|
antigravity: ["generativelanguage.googleapis.com"],
|
|
1326
|
-
opencode: ["
|
|
1327
|
-
goose: [
|
|
1328
|
-
pi: [
|
|
1443
|
+
opencode: ["mcp.exa.ai"],
|
|
1444
|
+
goose: [],
|
|
1445
|
+
pi: [],
|
|
1329
1446
|
codex: ["api.openai.com"],
|
|
1330
1447
|
fx: ["ai-gateway.vercel.sh"],
|
|
1331
1448
|
"grok-build": ["api.x.ai"]
|
|
@@ -1432,8 +1549,8 @@ const defaultLookup = async (host) => (await lookup(host, {
|
|
|
1432
1549
|
verbatim: true
|
|
1433
1550
|
})).map((a) => a.address);
|
|
1434
1551
|
/**
|
|
1435
|
-
* Decides whether `host` may be reached and which
|
|
1436
|
-
* to the
|
|
1552
|
+
* Decides whether `host` may be reached and which addresses to connect to. The gateway connects
|
|
1553
|
+
* only to the addresses it checked, so a DNS answer can't change between the check and the connect.
|
|
1437
1554
|
*/
|
|
1438
1555
|
function createPolicyCheck(policy, options = {}) {
|
|
1439
1556
|
const lookup = options.lookup ?? defaultLookup;
|
|
@@ -1465,8 +1582,7 @@ function createPolicyCheck(policy, options = {}) {
|
|
|
1465
1582
|
reason: `can't resolve ${host}: ${error.message}`
|
|
1466
1583
|
};
|
|
1467
1584
|
}
|
|
1468
|
-
|
|
1469
|
-
if (!first) return {
|
|
1585
|
+
if (!addresses.length) return {
|
|
1470
1586
|
allowed: false,
|
|
1471
1587
|
status: 502,
|
|
1472
1588
|
unresolved: true,
|
|
@@ -1489,7 +1605,7 @@ function createPolicyCheck(policy, options = {}) {
|
|
|
1489
1605
|
}
|
|
1490
1606
|
if (!custom) return {
|
|
1491
1607
|
allowed: true,
|
|
1492
|
-
|
|
1608
|
+
addresses
|
|
1493
1609
|
};
|
|
1494
1610
|
if (reached.some((a) => inList(deniedCidrs, a))) return {
|
|
1495
1611
|
allowed: false,
|
|
@@ -1503,11 +1619,11 @@ function createPolicyCheck(policy, options = {}) {
|
|
|
1503
1619
|
};
|
|
1504
1620
|
if (listed) return {
|
|
1505
1621
|
allowed: true,
|
|
1506
|
-
|
|
1622
|
+
addresses
|
|
1507
1623
|
};
|
|
1508
1624
|
if (custom.allowedCIDRs?.length && addresses.every((a) => inList(allowedCidrs, a))) return {
|
|
1509
1625
|
allowed: true,
|
|
1510
|
-
|
|
1626
|
+
addresses
|
|
1511
1627
|
};
|
|
1512
1628
|
return {
|
|
1513
1629
|
allowed: false,
|
|
@@ -1809,6 +1925,115 @@ function tokenizeResponse(derived, body, known) {
|
|
|
1809
1925
|
fields
|
|
1810
1926
|
};
|
|
1811
1927
|
}
|
|
1928
|
+
// ../sandbox-docker/src/egress/usage.ts
|
|
1929
|
+
/**
|
|
1930
|
+
* The usage fields of the model APIs the agents call: Anthropic's Messages, OpenAI's Responses
|
|
1931
|
+
* and Chat Completions (and the APIs shaped like them), and Gemini's `usageMetadata`. A nested
|
|
1932
|
+
* details object (`input_tokens_details`, `output_tokens_details`) gives its fields by their own
|
|
1933
|
+
* names.
|
|
1934
|
+
*/
|
|
1935
|
+
const FIELDS = /* @__PURE__ */ new Set([
|
|
1936
|
+
"input_tokens",
|
|
1937
|
+
"output_tokens",
|
|
1938
|
+
"cache_read_input_tokens",
|
|
1939
|
+
"cache_creation_input_tokens",
|
|
1940
|
+
"prompt_tokens",
|
|
1941
|
+
"completion_tokens",
|
|
1942
|
+
"cached_tokens",
|
|
1943
|
+
"cache_write_tokens",
|
|
1944
|
+
"reasoning_tokens",
|
|
1945
|
+
"thinking_tokens",
|
|
1946
|
+
"promptTokenCount",
|
|
1947
|
+
"candidatesTokenCount",
|
|
1948
|
+
"cachedContentTokenCount",
|
|
1949
|
+
"thoughtsTokenCount"
|
|
1950
|
+
]);
|
|
1951
|
+
/** xAI's `context_details` repeats `input_tokens` and `output_tokens` as the context counts them. */
|
|
1952
|
+
const SKIP = /* @__PURE__ */ new Set(["context_details"]);
|
|
1953
|
+
/** The model a model call's response names: Gemini's `generateContent` says `modelVersion`. */
|
|
1954
|
+
const MODEL_FIELD = /"model(?:Id|Version)?"\s*:\s*"([^"\\]{1,200})"/;
|
|
1955
|
+
const USAGE_KEY = /"(?:usage|usageMetadata)"\s*:\s*\{/g;
|
|
1956
|
+
/** How much of a chunk's end is kept while no usage object is open, so a split key is seen. */
|
|
1957
|
+
const CARRY = 64;
|
|
1958
|
+
/** The longest usage object read; a longer one is dropped. */
|
|
1959
|
+
const OBJECT_LIMIT = 65536;
|
|
1960
|
+
function flatten(value, out) {
|
|
1961
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return;
|
|
1962
|
+
for (const [key, v] of Object.entries(value)) {
|
|
1963
|
+
if (SKIP.has(key)) continue;
|
|
1964
|
+
if (typeof v === "number" && Number.isFinite(v) && FIELDS.has(key)) out[key] = v;
|
|
1965
|
+
else flatten(v, out);
|
|
1966
|
+
}
|
|
1967
|
+
}
|
|
1968
|
+
/**
|
|
1969
|
+
* Reads a response body's usage objects as it flows, whole: each `"usage"` or `"usageMetadata"`
|
|
1970
|
+
* object is parsed and its fields merged over the earlier ones', since a stream's later events
|
|
1971
|
+
* repeat its counts or replace them with the final ones (Anthropic's `message_delta`, Gemini's
|
|
1972
|
+
* last chunk, the Responses API's `response.completed`). Inside a JSON string the quotes are
|
|
1973
|
+
* escaped, so text that merely mentions a usage object doesn't match. Each call returns the
|
|
1974
|
+
* fields so far when that chunk completed an object, and null otherwise.
|
|
1975
|
+
*/
|
|
1976
|
+
function usageReader() {
|
|
1977
|
+
const fields = {};
|
|
1978
|
+
let pending = "";
|
|
1979
|
+
let object = null;
|
|
1980
|
+
let depth = 0;
|
|
1981
|
+
let inString = false;
|
|
1982
|
+
let escaped = false;
|
|
1983
|
+
return (chunk) => {
|
|
1984
|
+
let found = false;
|
|
1985
|
+
let text = object === null ? pending + chunk : chunk;
|
|
1986
|
+
let from = 0;
|
|
1987
|
+
for (;;) {
|
|
1988
|
+
if (object === null) {
|
|
1989
|
+
USAGE_KEY.lastIndex = from;
|
|
1990
|
+
const key = USAGE_KEY.exec(text);
|
|
1991
|
+
if (!key) {
|
|
1992
|
+
pending = text.slice(Math.max(from, text.length - CARRY));
|
|
1993
|
+
break;
|
|
1994
|
+
}
|
|
1995
|
+
object = "{";
|
|
1996
|
+
depth = 1;
|
|
1997
|
+
inString = false;
|
|
1998
|
+
escaped = false;
|
|
1999
|
+
from = key.index + key[0].length;
|
|
2000
|
+
}
|
|
2001
|
+
let end = -1;
|
|
2002
|
+
for (let i = from; i < text.length; i++) {
|
|
2003
|
+
const c = text[i];
|
|
2004
|
+
if (inString) {
|
|
2005
|
+
if (escaped) escaped = false;
|
|
2006
|
+
else if (c === "\\") escaped = true;
|
|
2007
|
+
else if (c === "\"") inString = false;
|
|
2008
|
+
} else if (c === "\"") inString = true;
|
|
2009
|
+
else if (c === "{") depth++;
|
|
2010
|
+
else if (c === "}" && --depth === 0) {
|
|
2011
|
+
end = i;
|
|
2012
|
+
break;
|
|
2013
|
+
}
|
|
2014
|
+
}
|
|
2015
|
+
if (end === -1) {
|
|
2016
|
+
object += text.slice(from);
|
|
2017
|
+
if (object.length > OBJECT_LIMIT) object = null;
|
|
2018
|
+
pending = "";
|
|
2019
|
+
break;
|
|
2020
|
+
}
|
|
2021
|
+
const json = object + text.slice(from, end + 1);
|
|
2022
|
+
object = null;
|
|
2023
|
+
try {
|
|
2024
|
+
const got = {};
|
|
2025
|
+
flatten(JSON.parse(json), got);
|
|
2026
|
+
if (Object.keys(got).length > 0) {
|
|
2027
|
+
Object.assign(fields, got);
|
|
2028
|
+
found = true;
|
|
2029
|
+
}
|
|
2030
|
+
} catch {}
|
|
2031
|
+
text = text.slice(end + 1);
|
|
2032
|
+
from = 0;
|
|
2033
|
+
}
|
|
2034
|
+
return found ? { ...fields } : null;
|
|
2035
|
+
};
|
|
2036
|
+
}
|
|
1812
2037
|
// ../sandbox-docker/src/egress/websocket.ts
|
|
1813
2038
|
/** The most a message may hold while its frames are gathered to be scrubbed. */
|
|
1814
2039
|
const MAX_MESSAGE = 16777216;
|
|
@@ -1938,6 +2163,53 @@ const authorityOf = (host, port) => {
|
|
|
1938
2163
|
return port === 443 ? name : `${name}:${port}`;
|
|
1939
2164
|
};
|
|
1940
2165
|
const pathOnly = (path) => path.split("?")[0];
|
|
2166
|
+
/**
|
|
2167
|
+
* Connection options that reach `target` at the addresses its policy check resolved, with no
|
|
2168
|
+
* lookup of their own. Node tries each in turn (Happy Eyeballs), so a host whose IPv6 address is
|
|
2169
|
+
* unreachable from here is still reached over IPv4.
|
|
2170
|
+
*/
|
|
2171
|
+
function reachAt(target) {
|
|
2172
|
+
const addresses = target.addresses.map((address) => ({
|
|
2173
|
+
address,
|
|
2174
|
+
family: net.isIP(address)
|
|
2175
|
+
}));
|
|
2176
|
+
const lookup = (_host, options, callback) => {
|
|
2177
|
+
const [first = {
|
|
2178
|
+
address: target.host,
|
|
2179
|
+
family: net.isIP(target.host)
|
|
2180
|
+
}] = addresses;
|
|
2181
|
+
if (options.all) callback(null, addresses);
|
|
2182
|
+
else callback(null, first.address, first.family);
|
|
2183
|
+
};
|
|
2184
|
+
return {
|
|
2185
|
+
host: target.host,
|
|
2186
|
+
lookup,
|
|
2187
|
+
autoSelectFamily: true,
|
|
2188
|
+
pinned: pinnedKey(target)
|
|
2189
|
+
};
|
|
2190
|
+
}
|
|
2191
|
+
/** The checked addresses, in a stable order, that a pooled connection to `target` was made for. */
|
|
2192
|
+
const pinnedKey = (target) => [...target.addresses].sort().join(",");
|
|
2193
|
+
/**
|
|
2194
|
+
* An agent whose pool keys a connection by the addresses its policy check reached as well as by
|
|
2195
|
+
* name, so a kept-alive connection is reused only by a request whose own check reached the same
|
|
2196
|
+
* addresses, never one checked under an earlier policy or DNS answer.
|
|
2197
|
+
*/
|
|
2198
|
+
var PinnedAgent = class extends http.Agent {
|
|
2199
|
+
getName(options) {
|
|
2200
|
+
return `${super.getName(options)}:${options?.pinned ?? ""}`;
|
|
2201
|
+
}
|
|
2202
|
+
};
|
|
2203
|
+
var PinnedHttpsAgent = class extends https.Agent {
|
|
2204
|
+
getName(options) {
|
|
2205
|
+
return `${super.getName(options)}:${options?.pinned ?? ""}`;
|
|
2206
|
+
}
|
|
2207
|
+
};
|
|
2208
|
+
/**
|
|
2209
|
+
* Why a connect failed. Happy Eyeballs fails with an `AggregateError` whose own message is empty
|
|
2210
|
+
* when every address does, so name each address's error.
|
|
2211
|
+
*/
|
|
2212
|
+
const failure = (error) => error instanceof AggregateError && error.errors.length ? error.errors.map((e) => e.message).join(", ") : error.message;
|
|
1941
2213
|
/** Refused brokered requests recorded per method and path before the rest share an entry. */
|
|
1942
2214
|
const REFUSED_PATHS = 20;
|
|
1943
2215
|
function reply(socket, status, reason) {
|
|
@@ -1959,6 +2231,14 @@ const DECODERS = {
|
|
|
1959
2231
|
/** Text a credential could be echoed into, or no type at all. */
|
|
1960
2232
|
const isText = (type) => !type.trim() || /^\s*(text\/|application\/(json|xml|javascript|x-www-form-urlencoded|x-ndjson|[\w.-]+\+(json|xml))\b)/i.test(type);
|
|
1961
2233
|
const plainHeaders = (headers) => Object.fromEntries(Object.entries(headers).flatMap(([k, v]) => v === void 0 ? [] : [[k, Array.isArray(v) ? v.map(String) : String(v)]]));
|
|
2234
|
+
/** The first of `names` set in `headers` to a finite number, as a call's cost; undefined if none is. */
|
|
2235
|
+
function headerCost(headers, names = []) {
|
|
2236
|
+
for (const name of names) {
|
|
2237
|
+
const raw = headers[name.toLowerCase()];
|
|
2238
|
+
const value = Number((Array.isArray(raw) ? raw[0] : raw)?.trim() || NaN);
|
|
2239
|
+
if (Number.isFinite(value)) return value;
|
|
2240
|
+
}
|
|
2241
|
+
}
|
|
1962
2242
|
function createEgressProxy(options) {
|
|
1963
2243
|
const log = options.log ?? (() => {});
|
|
1964
2244
|
const firstByteTimeout = options.firstByteTimeout ?? FIRST_BYTE_TIMEOUT_MS;
|
|
@@ -1977,13 +2257,20 @@ function createEgressProxy(options) {
|
|
|
1977
2257
|
const locals = options.localResponses ?? [];
|
|
1978
2258
|
const localHosts = locals.map((l) => l.match.host);
|
|
1979
2259
|
let policyCheck = createPolicyCheck(options.policy, options);
|
|
2260
|
+
/** Bumped by `switchPolicy`: a verdict reached under the policy before it is reached again. */
|
|
2261
|
+
let generation = 0;
|
|
1980
2262
|
const check = async (host) => {
|
|
1981
|
-
|
|
2263
|
+
let verdict;
|
|
2264
|
+
let at;
|
|
2265
|
+
do {
|
|
2266
|
+
at = generation;
|
|
2267
|
+
verdict = await policyCheck(host);
|
|
2268
|
+
} while (at !== generation);
|
|
1982
2269
|
emit(verdict.allowed ? {
|
|
1983
2270
|
type: "dns",
|
|
1984
2271
|
host,
|
|
1985
2272
|
allowed: true,
|
|
1986
|
-
|
|
2273
|
+
addresses: verdict.addresses
|
|
1987
2274
|
} : {
|
|
1988
2275
|
type: "dns",
|
|
1989
2276
|
host,
|
|
@@ -2000,7 +2287,8 @@ function createEgressProxy(options) {
|
|
|
2000
2287
|
const leaves = /* @__PURE__ */ new Map();
|
|
2001
2288
|
const open = /* @__PURE__ */ new Set();
|
|
2002
2289
|
const sessions = /* @__PURE__ */ new Map();
|
|
2003
|
-
const agent = new
|
|
2290
|
+
const agent = new PinnedHttpsAgent({ keepAlive: true });
|
|
2291
|
+
const plainAgent = new PinnedAgent({ keepAlive: true });
|
|
2004
2292
|
const ca = options.upstreamCA ? [...tls.rootCertificates, options.upstreamCA] : void 0;
|
|
2005
2293
|
const track = (s) => {
|
|
2006
2294
|
open.add(s);
|
|
@@ -2010,12 +2298,25 @@ function createEgressProxy(options) {
|
|
|
2010
2298
|
const contacted = /* @__PURE__ */ new Map();
|
|
2011
2299
|
const blocked = /* @__PURE__ */ new Map();
|
|
2012
2300
|
const unresolved = /* @__PURE__ */ new Map();
|
|
2301
|
+
/** The phase traffic is tagged with; unset until the first `switchPolicy`. */
|
|
2302
|
+
let phase;
|
|
2303
|
+
const tagged = () => phase === void 0 ? {} : { phase };
|
|
2304
|
+
const keyed = (key) => phase === void 0 ? key : `${phase} ${key}`;
|
|
2305
|
+
/** Each open tunnel's host, which only the policy at its start checked. */
|
|
2306
|
+
const tunnels = /* @__PURE__ */ new Map();
|
|
2307
|
+
const holdTunnel = (connection, host, port) => {
|
|
2308
|
+
tunnels.set(connection, {
|
|
2309
|
+
host,
|
|
2310
|
+
port
|
|
2311
|
+
});
|
|
2312
|
+
connection.once("close", () => tunnels.delete(connection));
|
|
2313
|
+
};
|
|
2013
2314
|
/** The host each sandbox connection's bytes count towards: its latest allowed request's. */
|
|
2014
2315
|
const counting = /* @__PURE__ */ new WeakMap();
|
|
2015
2316
|
/** Bytes a connection sent before the policy decided whose they are: the request itself. */
|
|
2016
2317
|
const unclaimed = /* @__PURE__ */ new WeakMap();
|
|
2017
2318
|
const contact = (connection, host, port) => {
|
|
2018
|
-
const key = `${host}:${port}
|
|
2319
|
+
const key = keyed(`${host}:${port}`);
|
|
2019
2320
|
let entry = contacted.get(key);
|
|
2020
2321
|
if (!entry) {
|
|
2021
2322
|
entry = {
|
|
@@ -2023,7 +2324,8 @@ function createEgressProxy(options) {
|
|
|
2023
2324
|
port,
|
|
2024
2325
|
connections: 0,
|
|
2025
2326
|
sent: 0,
|
|
2026
|
-
received: 0
|
|
2327
|
+
received: 0,
|
|
2328
|
+
...tagged()
|
|
2027
2329
|
};
|
|
2028
2330
|
contacted.set(key, entry);
|
|
2029
2331
|
}
|
|
@@ -2033,13 +2335,14 @@ function createEgressProxy(options) {
|
|
|
2033
2335
|
counting.set(connection, entry);
|
|
2034
2336
|
};
|
|
2035
2337
|
const block = (connection, host, port, verdict) => {
|
|
2036
|
-
const key = `${host}:${port}
|
|
2338
|
+
const key = keyed(`${host}:${port}`);
|
|
2037
2339
|
const into = verdict.status === 502 ? unresolved : blocked;
|
|
2038
2340
|
const entry = into.get(key) ?? {
|
|
2039
2341
|
host,
|
|
2040
2342
|
port,
|
|
2041
2343
|
connections: 0,
|
|
2042
|
-
reason: verdict.reason
|
|
2344
|
+
reason: verdict.reason,
|
|
2345
|
+
...tagged()
|
|
2043
2346
|
};
|
|
2044
2347
|
entry.connections++;
|
|
2045
2348
|
into.set(key, entry);
|
|
@@ -2056,10 +2359,10 @@ function createEgressProxy(options) {
|
|
|
2056
2359
|
*/
|
|
2057
2360
|
const blockRequest = (target, method, path, reason) => {
|
|
2058
2361
|
const host = `${target.host}:${target.port}`;
|
|
2059
|
-
let key = `${host} ${method} ${path}
|
|
2362
|
+
let key = keyed(`${host} ${method} ${path}`);
|
|
2060
2363
|
if (!blocked.has(key)) {
|
|
2061
2364
|
if (refusedPaths >= REFUSED_PATHS) {
|
|
2062
|
-
key = `${host} more
|
|
2365
|
+
key = keyed(`${host} more`);
|
|
2063
2366
|
reason = `more requests that carry a brokered credential off the endpoints reeval brokers it for, on paths past the first ${REFUSED_PATHS}`;
|
|
2064
2367
|
} else refusedPaths++;
|
|
2065
2368
|
}
|
|
@@ -2067,7 +2370,8 @@ function createEgressProxy(options) {
|
|
|
2067
2370
|
host: target.host,
|
|
2068
2371
|
port: target.port,
|
|
2069
2372
|
connections: 0,
|
|
2070
|
-
reason
|
|
2373
|
+
reason,
|
|
2374
|
+
...tagged()
|
|
2071
2375
|
};
|
|
2072
2376
|
entry.connections++;
|
|
2073
2377
|
blocked.set(key, entry);
|
|
@@ -2134,6 +2438,7 @@ function createEgressProxy(options) {
|
|
|
2134
2438
|
event.sent += n;
|
|
2135
2439
|
},
|
|
2136
2440
|
received: (n) => {
|
|
2441
|
+
if (n > 0 && event.firstByteMs === void 0) event.firstByteMs = Date.now() - startedAt;
|
|
2137
2442
|
event.received += n;
|
|
2138
2443
|
}
|
|
2139
2444
|
};
|
|
@@ -2189,10 +2494,11 @@ function createEgressProxy(options) {
|
|
|
2189
2494
|
return reply(socket, verdict.status, refusal(verdict));
|
|
2190
2495
|
}
|
|
2191
2496
|
contact(socket, host, port);
|
|
2497
|
+
holdTunnel(socket, host, port);
|
|
2192
2498
|
const target = {
|
|
2193
2499
|
host,
|
|
2194
2500
|
port,
|
|
2195
|
-
|
|
2501
|
+
addresses: verdict.addresses
|
|
2196
2502
|
};
|
|
2197
2503
|
if (decrypts(rules, host) || substitutes(allSubs(), host) || hostAllowed(tokenHosts, host) || hostAllowed(localHosts, host)) {
|
|
2198
2504
|
log(`reeval:egress CONNECT ${host}:${port} decrypt`);
|
|
@@ -2230,7 +2536,7 @@ function createEgressProxy(options) {
|
|
|
2230
2536
|
});
|
|
2231
2537
|
});
|
|
2232
2538
|
const upstream = track(net.connect({
|
|
2233
|
-
|
|
2539
|
+
...reachAt(target),
|
|
2234
2540
|
port,
|
|
2235
2541
|
allowHalfOpen: true
|
|
2236
2542
|
}));
|
|
@@ -2240,10 +2546,10 @@ function createEgressProxy(options) {
|
|
|
2240
2546
|
link(socket, upstream);
|
|
2241
2547
|
});
|
|
2242
2548
|
upstream.once("error", (error) => {
|
|
2243
|
-
log(`reeval:egress CONNECT ${host}:${port} failed (${error
|
|
2549
|
+
log(`reeval:egress CONNECT ${host}:${port} failed (${failure(error)})`);
|
|
2244
2550
|
status = 502;
|
|
2245
|
-
reason = `couldn't reach ${host}:${port}: ${error
|
|
2246
|
-
reply(socket, 502, `reeval egress gateway couldn't reach ${host}:${port}: ${error
|
|
2551
|
+
reason = `couldn't reach ${host}:${port}: ${failure(error)}`;
|
|
2552
|
+
reply(socket, 502, `reeval egress gateway couldn't reach ${host}:${port}: ${failure(error)}`);
|
|
2247
2553
|
});
|
|
2248
2554
|
});
|
|
2249
2555
|
});
|
|
@@ -2279,10 +2585,15 @@ function createEgressProxy(options) {
|
|
|
2279
2585
|
return res.writeHead(verdict.status).end(`${refusal(verdict)}\n`);
|
|
2280
2586
|
}
|
|
2281
2587
|
contact(req.socket, host, port);
|
|
2588
|
+
tunnels.set(req.socket, {
|
|
2589
|
+
host,
|
|
2590
|
+
port
|
|
2591
|
+
});
|
|
2592
|
+
res.once("close", () => tunnels.delete(req.socket));
|
|
2282
2593
|
const target = {
|
|
2283
2594
|
host,
|
|
2284
2595
|
port,
|
|
2285
|
-
|
|
2596
|
+
addresses: verdict.addresses
|
|
2286
2597
|
};
|
|
2287
2598
|
if (secure) {
|
|
2288
2599
|
const headers = {
|
|
@@ -2330,10 +2641,11 @@ function createEgressProxy(options) {
|
|
|
2330
2641
|
return reply(socket, verdict.status, refusal(verdict));
|
|
2331
2642
|
}
|
|
2332
2643
|
contact(socket, host, port);
|
|
2644
|
+
holdTunnel(socket, host, port);
|
|
2333
2645
|
onPlainUpgrade({
|
|
2334
2646
|
host,
|
|
2335
2647
|
port,
|
|
2336
|
-
|
|
2648
|
+
addresses: verdict.addresses
|
|
2337
2649
|
}, req, track(socket), head);
|
|
2338
2650
|
});
|
|
2339
2651
|
});
|
|
@@ -2345,14 +2657,15 @@ function createEgressProxy(options) {
|
|
|
2345
2657
|
const url = `http://${target.host}:${target.port}${pathOnly(path)}`;
|
|
2346
2658
|
log(`reeval:egress ${req.method} ${url}`);
|
|
2347
2659
|
const upstream = http.request({
|
|
2348
|
-
|
|
2660
|
+
...reachAt(target),
|
|
2349
2661
|
port: target.port,
|
|
2350
2662
|
method: req.method,
|
|
2351
2663
|
path,
|
|
2352
2664
|
headers: {
|
|
2353
2665
|
...endToEnd(req.headers),
|
|
2354
2666
|
host
|
|
2355
|
-
}
|
|
2667
|
+
},
|
|
2668
|
+
agent: plainAgent
|
|
2356
2669
|
});
|
|
2357
2670
|
forwardHttp1(req.pipe(counter(done.sent)), res, upstream, {
|
|
2358
2671
|
own: [],
|
|
@@ -2500,14 +2813,15 @@ function createEgressProxy(options) {
|
|
|
2500
2813
|
}
|
|
2501
2814
|
log(`reeval:egress ${method} http://${authority}${pathOnly(path)} (upgrade)`);
|
|
2502
2815
|
const upstream = http.request({
|
|
2503
|
-
|
|
2816
|
+
...reachAt(target),
|
|
2504
2817
|
port: target.port,
|
|
2505
2818
|
method,
|
|
2506
2819
|
path,
|
|
2507
2820
|
headers: {
|
|
2508
2821
|
...endToEnd(req.headers, ["upgrade", "connection"]),
|
|
2509
2822
|
host: req.headers.host ?? authority
|
|
2510
|
-
}
|
|
2823
|
+
},
|
|
2824
|
+
agent: plainAgent
|
|
2511
2825
|
});
|
|
2512
2826
|
upstream.once("upgrade", (up, upSocket, upHead) => {
|
|
2513
2827
|
upgraded({
|
|
@@ -2529,9 +2843,9 @@ function createEgressProxy(options) {
|
|
|
2529
2843
|
upstream.once("error", (error) => {
|
|
2530
2844
|
upgraded({
|
|
2531
2845
|
status: 502,
|
|
2532
|
-
reason: error
|
|
2846
|
+
reason: failure(error)
|
|
2533
2847
|
});
|
|
2534
|
-
reply(socket, 502, `reeval egress gateway: ${error
|
|
2848
|
+
reply(socket, 502, `reeval egress gateway: ${failure(error)}`);
|
|
2535
2849
|
});
|
|
2536
2850
|
upstream.end();
|
|
2537
2851
|
}
|
|
@@ -2638,7 +2952,13 @@ function createEgressProxy(options) {
|
|
|
2638
2952
|
path,
|
|
2639
2953
|
headers: {}
|
|
2640
2954
|
});
|
|
2641
|
-
|
|
2955
|
+
const readsUsage = onEndpoint(options.modelCalls ?? [], {
|
|
2956
|
+
host: target.host,
|
|
2957
|
+
method,
|
|
2958
|
+
path,
|
|
2959
|
+
headers: {}
|
|
2960
|
+
});
|
|
2961
|
+
if (scrubbedInBodies(own).length || credentialValues(rules, target.host).length || exchange || readsModel || readsUsage) delete substituted.headers["accept-encoding"];
|
|
2642
2962
|
const notes = [
|
|
2643
2963
|
replaced.length ? `set ${replaced.join(", ")}` : "",
|
|
2644
2964
|
substituted.names.length ? `substituted ${substituted.names.join(", ")}` : "",
|
|
@@ -2652,7 +2972,8 @@ function createEgressProxy(options) {
|
|
|
2652
2972
|
names: substituted.names,
|
|
2653
2973
|
credentials: replaced,
|
|
2654
2974
|
...exchange ? { exchange } : {},
|
|
2655
|
-
...readsModel ? { readsModel } : {}
|
|
2975
|
+
...readsModel ? { readsModel } : {},
|
|
2976
|
+
...readsUsage ? { readsUsage } : {}
|
|
2656
2977
|
};
|
|
2657
2978
|
}
|
|
2658
2979
|
/**
|
|
@@ -2698,8 +3019,9 @@ function createEgressProxy(options) {
|
|
|
2698
3019
|
* The response body as sent to the sandbox: decoded if the plan says so, with real values put
|
|
2699
3020
|
* back as placeholders. An error anywhere upstream of it (a corrupt encoding) errors it.
|
|
2700
3021
|
*/
|
|
2701
|
-
function responseBody(up, plan, t,
|
|
2702
|
-
if (
|
|
3022
|
+
function responseBody(up, plan, t, reads = {}) {
|
|
3023
|
+
if (reads.model && t) readModel(up, t);
|
|
3024
|
+
if (reads.usage && t) readUsage(up, t);
|
|
2703
3025
|
const into = (from, to) => {
|
|
2704
3026
|
from.once("error", (error) => to.destroy(error));
|
|
2705
3027
|
return from.pipe(to);
|
|
@@ -2781,6 +3103,27 @@ function createEgressProxy(options) {
|
|
|
2781
3103
|
};
|
|
2782
3104
|
up.on("data", onData);
|
|
2783
3105
|
}
|
|
3106
|
+
/**
|
|
3107
|
+
* Records the response body's usage (`usageReader`) and the first model it names, reading
|
|
3108
|
+
* alongside its flow.
|
|
3109
|
+
*/
|
|
3110
|
+
function readUsage(up, t) {
|
|
3111
|
+
const read = usageReader();
|
|
3112
|
+
let carry = "";
|
|
3113
|
+
let seen = 0;
|
|
3114
|
+
let model;
|
|
3115
|
+
up.on("data", (chunk) => {
|
|
3116
|
+
const text = chunk.toString("utf8");
|
|
3117
|
+
if (!model && seen <= MODEL_WINDOW) {
|
|
3118
|
+
model = MODEL_FIELD.exec(carry + text)?.[1];
|
|
3119
|
+
if (model) t.set({ usageModel: model });
|
|
3120
|
+
carry = (carry + text).slice(-256);
|
|
3121
|
+
}
|
|
3122
|
+
seen += chunk.length;
|
|
3123
|
+
const usage = read(text);
|
|
3124
|
+
if (usage) t.set({ responseUsage: usage });
|
|
3125
|
+
});
|
|
3126
|
+
}
|
|
2784
3127
|
/** Most of a request body the gateway reads for its reasoning settings: a long session's. */
|
|
2785
3128
|
const EFFORT_LIMIT = 16777216;
|
|
2786
3129
|
/**
|
|
@@ -2799,8 +3142,9 @@ function createEgressProxy(options) {
|
|
|
2799
3142
|
},
|
|
2800
3143
|
flush(done) {
|
|
2801
3144
|
if (size <= EFFORT_LIMIT) {
|
|
2802
|
-
const effort =
|
|
3145
|
+
const { effort, tools } = requestFacts(Buffer.concat(chunks).toString("utf8"));
|
|
2803
3146
|
if (effort) t.set({ requestEffort: effort });
|
|
3147
|
+
if (tools !== void 0) t.set({ requestTools: tools });
|
|
2804
3148
|
}
|
|
2805
3149
|
done();
|
|
2806
3150
|
}
|
|
@@ -2867,11 +3211,16 @@ function createEgressProxy(options) {
|
|
|
2867
3211
|
via: "decrypted",
|
|
2868
3212
|
requestHeaders: plainHeaders(req.headers)
|
|
2869
3213
|
});
|
|
2870
|
-
const { headers, path, own, names, credentials, refused, exchange, readsModel } = transformed(target, method, asked, sent, req.httpVersion);
|
|
3214
|
+
const { headers, path, own, names, credentials, refused, exchange, readsModel, readsUsage } = transformed(target, method, asked, sent, req.httpVersion);
|
|
2871
3215
|
t.set({
|
|
2872
3216
|
substituted: names,
|
|
2873
|
-
credentials
|
|
3217
|
+
credentials,
|
|
3218
|
+
...readsUsage ? { modelCall: true } : {}
|
|
2874
3219
|
});
|
|
3220
|
+
const reads = {
|
|
3221
|
+
model: !!readsModel,
|
|
3222
|
+
usage: !!readsUsage
|
|
3223
|
+
};
|
|
2875
3224
|
if (refused) {
|
|
2876
3225
|
t.refuse(refused.reason);
|
|
2877
3226
|
req.resume();
|
|
@@ -2902,7 +3251,7 @@ function createEgressProxy(options) {
|
|
|
2902
3251
|
const authority = authorityOf(target.host, target.port);
|
|
2903
3252
|
const session = req.httpVersionMajor === 2 ? await upstreamSession(target) : null;
|
|
2904
3253
|
if (!session) return forwardHttp1(body, res, https.request({
|
|
2905
|
-
|
|
3254
|
+
...reachAt(target),
|
|
2906
3255
|
servername: net.isIP(target.host) ? void 0 : target.host,
|
|
2907
3256
|
port: target.port,
|
|
2908
3257
|
method,
|
|
@@ -2919,7 +3268,7 @@ function createEgressProxy(options) {
|
|
|
2919
3268
|
url,
|
|
2920
3269
|
...exchange ? { exchange } : {},
|
|
2921
3270
|
...t ? { t } : {},
|
|
2922
|
-
|
|
3271
|
+
reads
|
|
2923
3272
|
});
|
|
2924
3273
|
const stream = session.request({
|
|
2925
3274
|
...headers,
|
|
@@ -2929,7 +3278,7 @@ function createEgressProxy(options) {
|
|
|
2929
3278
|
":authority": authority
|
|
2930
3279
|
});
|
|
2931
3280
|
const fail = (error) => {
|
|
2932
|
-
if (!res.headersSent) res.writeHead(502).end(`reeval egress gateway: ${error
|
|
3281
|
+
if (!res.headersSent) res.writeHead(502).end(`reeval egress gateway: ${failure(error)}\n`);
|
|
2933
3282
|
else res.destroy();
|
|
2934
3283
|
};
|
|
2935
3284
|
stream.once("error", fail);
|
|
@@ -2937,7 +3286,7 @@ function createEgressProxy(options) {
|
|
|
2937
3286
|
stream.once("response", (h) => {
|
|
2938
3287
|
const status = Number(h[":status"]);
|
|
2939
3288
|
if (exchange) return tokenized(exchange, url, status, h, stream, res, own, creds, t);
|
|
2940
|
-
if (!respond(status, h, stream, res, own, creds, url, t,
|
|
3289
|
+
if (!respond(status, h, stream, res, own, creds, url, t, reads)) return;
|
|
2941
3290
|
stream.once("trailers", (trailers) => res.addTrailers(scrubbedHeaders(trailers, [...own, ...creds])));
|
|
2942
3291
|
});
|
|
2943
3292
|
body.pipe(stream);
|
|
@@ -2947,7 +3296,7 @@ function createEgressProxy(options) {
|
|
|
2947
3296
|
* Sends an upstream response on to the sandbox, scrubbed. False when it was refused instead,
|
|
2948
3297
|
* already answered with a 502.
|
|
2949
3298
|
*/
|
|
2950
|
-
function respond(status, headers, up, res, own, creds, url, t,
|
|
3299
|
+
function respond(status, headers, up, res, own, creds, url, t, reads = {}) {
|
|
2951
3300
|
const plan = scrubPlan(status, headers, own, creds);
|
|
2952
3301
|
if (plan.refuse) {
|
|
2953
3302
|
refuseResponse(res, up, url, plan.refuse, t);
|
|
@@ -2955,8 +3304,10 @@ function createEgressProxy(options) {
|
|
|
2955
3304
|
}
|
|
2956
3305
|
const out = responseHeaders(headers, own, creds, plan);
|
|
2957
3306
|
t?.set({ responseHeaders: plainHeaders(out) });
|
|
3307
|
+
const cost = reads.model ? headerCost(headers, options.costHeaders) : void 0;
|
|
3308
|
+
if (cost !== void 0) t?.set({ responseCost: cost });
|
|
2958
3309
|
res.writeHead(status, out);
|
|
2959
|
-
responseBody(up, plan, t,
|
|
3310
|
+
responseBody(up, plan, t, reads).once("error", () => res.destroy()).pipe(res);
|
|
2960
3311
|
return true;
|
|
2961
3312
|
}
|
|
2962
3313
|
function forwardHttp1(req, res, upstream, to) {
|
|
@@ -2964,7 +3315,7 @@ function createEgressProxy(options) {
|
|
|
2964
3315
|
upstream.once("response", (up) => {
|
|
2965
3316
|
const status = up.statusCode ?? 502;
|
|
2966
3317
|
if (exchange) return tokenized(exchange, url, status, up.headers, up, res, own, creds, t);
|
|
2967
|
-
if (!respond(status, up.headers, up, res, own, creds, url, t, to.
|
|
3318
|
+
if (!respond(status, up.headers, up, res, own, creds, url, t, to.reads)) return;
|
|
2968
3319
|
up.once("end", () => {
|
|
2969
3320
|
if (Object.keys(up.trailers).length) res.addTrailers(scrubbedHeaders(up.trailers, [...own, ...creds]));
|
|
2970
3321
|
});
|
|
@@ -2972,9 +3323,9 @@ function createEgressProxy(options) {
|
|
|
2972
3323
|
upstream.once("error", (error) => {
|
|
2973
3324
|
t?.set({
|
|
2974
3325
|
status: 502,
|
|
2975
|
-
reason: error
|
|
3326
|
+
reason: failure(error)
|
|
2976
3327
|
});
|
|
2977
|
-
if (!res.headersSent) res.writeHead(502).end(`reeval egress gateway: ${error
|
|
3328
|
+
if (!res.headersSent) res.writeHead(502).end(`reeval egress gateway: ${failure(error)}\n`);
|
|
2978
3329
|
else res.destroy();
|
|
2979
3330
|
});
|
|
2980
3331
|
req.pipe(upstream);
|
|
@@ -3011,7 +3362,7 @@ function createEgressProxy(options) {
|
|
|
3011
3362
|
return reply(socket, refused.status, refused.reason);
|
|
3012
3363
|
}
|
|
3013
3364
|
const upstream = https.request({
|
|
3014
|
-
|
|
3365
|
+
...reachAt(target),
|
|
3015
3366
|
servername: net.isIP(target.host) ? void 0 : target.host,
|
|
3016
3367
|
port: target.port,
|
|
3017
3368
|
method,
|
|
@@ -3020,6 +3371,7 @@ function createEgressProxy(options) {
|
|
|
3020
3371
|
...headers,
|
|
3021
3372
|
host: target.host
|
|
3022
3373
|
},
|
|
3374
|
+
agent,
|
|
3023
3375
|
ca
|
|
3024
3376
|
});
|
|
3025
3377
|
upstream.once("upgrade", (up, upSocket, upHead) => {
|
|
@@ -3050,17 +3402,17 @@ function createEgressProxy(options) {
|
|
|
3050
3402
|
reply(socket, up.statusCode ?? 502, `upstream refused the upgrade (${up.statusCode})`);
|
|
3051
3403
|
up.resume();
|
|
3052
3404
|
});
|
|
3053
|
-
upstream.once("error", (error) => reply(socket, 502, `reeval egress gateway: ${error
|
|
3405
|
+
upstream.once("error", (error) => reply(socket, 502, `reeval egress gateway: ${failure(error)}`));
|
|
3054
3406
|
upstream.end();
|
|
3055
3407
|
}
|
|
3056
3408
|
/** One HTTP/2 session per upstream, or null when it doesn't speak h2. */
|
|
3057
3409
|
function upstreamSession(target) {
|
|
3058
|
-
const key = `${target.host}:${target.port}`;
|
|
3410
|
+
const key = `${target.host}:${target.port}:${pinnedKey(target)}`;
|
|
3059
3411
|
const existing = sessions.get(key);
|
|
3060
3412
|
if (existing && !existing.closed && !existing.destroyed) return Promise.resolve(existing);
|
|
3061
3413
|
return new Promise((resolve) => {
|
|
3062
3414
|
const socket = tls.connect({
|
|
3063
|
-
|
|
3415
|
+
...reachAt(target),
|
|
3064
3416
|
port: target.port,
|
|
3065
3417
|
servername: net.isIP(target.host) ? void 0 : target.host,
|
|
3066
3418
|
ALPNProtocols: ["h2", "http/1.1"],
|
|
@@ -3102,6 +3454,31 @@ function createEgressProxy(options) {
|
|
|
3102
3454
|
setPolicy(policy) {
|
|
3103
3455
|
policyCheck = createPolicyCheck(policy, options);
|
|
3104
3456
|
},
|
|
3457
|
+
async switchPolicy(policy, next) {
|
|
3458
|
+
phase = next;
|
|
3459
|
+
generation++;
|
|
3460
|
+
const recheck = createPolicyCheck(policy, options);
|
|
3461
|
+
policyCheck = recheck;
|
|
3462
|
+
await new Promise((r) => setImmediate(r));
|
|
3463
|
+
await Promise.all([...tunnels].map(async ([connection, { host, port }]) => {
|
|
3464
|
+
const verdict = await recheck(host);
|
|
3465
|
+
if (verdict.allowed || verdict.status === 502 || connection.destroyed) return;
|
|
3466
|
+
log(`reeval:egress ${host}:${port} tunnel closed (${verdict.reason})`);
|
|
3467
|
+
tunnels.delete(connection);
|
|
3468
|
+
connection.destroy();
|
|
3469
|
+
const key = keyed(`closed ${host}:${port}`);
|
|
3470
|
+
const entry = blocked.get(key) ?? {
|
|
3471
|
+
host,
|
|
3472
|
+
port,
|
|
3473
|
+
connections: 0,
|
|
3474
|
+
reason: `a tunnel opened before the ${next} phase, closed: ${verdict.reason}`,
|
|
3475
|
+
...tagged(),
|
|
3476
|
+
closed: true
|
|
3477
|
+
};
|
|
3478
|
+
entry.connections++;
|
|
3479
|
+
blocked.set(key, entry);
|
|
3480
|
+
}));
|
|
3481
|
+
},
|
|
3105
3482
|
setSubstitutions(all) {
|
|
3106
3483
|
subs = [...all];
|
|
3107
3484
|
},
|
|
@@ -3110,6 +3487,7 @@ function createEgressProxy(options) {
|
|
|
3110
3487
|
for (const s of sessions.values()) s.destroy();
|
|
3111
3488
|
sessions.clear();
|
|
3112
3489
|
agent.destroy();
|
|
3490
|
+
plainAgent.destroy();
|
|
3113
3491
|
}
|
|
3114
3492
|
};
|
|
3115
3493
|
}
|
|
@@ -3158,19 +3536,66 @@ function execSpawn(transport, command) {
|
|
|
3158
3536
|
}));
|
|
3159
3537
|
return child;
|
|
3160
3538
|
}
|
|
3539
|
+
/** What every `ssh` reeval runs passes: no prompt, a dropped connection noticed within a minute. */
|
|
3540
|
+
const SSH_OPTIONS = [
|
|
3541
|
+
"-o",
|
|
3542
|
+
"BatchMode=yes",
|
|
3543
|
+
"-o",
|
|
3544
|
+
"ServerAliveInterval=15",
|
|
3545
|
+
"-o",
|
|
3546
|
+
"ServerAliveCountMax=4",
|
|
3547
|
+
"-o",
|
|
3548
|
+
"LogLevel=ERROR"
|
|
3549
|
+
];
|
|
3161
3550
|
/**
|
|
3162
|
-
*
|
|
3163
|
-
*
|
|
3551
|
+
* Whether `dir` is a directory only this user can enter, made (0700) first with `make`. An ssh
|
|
3552
|
+
* client trusts whatever listens at its ControlPath, so a socket in a directory another user can
|
|
3553
|
+
* write lets them stand in for the host.
|
|
3164
3554
|
*/
|
|
3165
|
-
function
|
|
3166
|
-
|
|
3555
|
+
function privateDir(dir, o = {}) {
|
|
3556
|
+
try {
|
|
3557
|
+
if (o.make) mkdirSync(dir, {
|
|
3558
|
+
recursive: true,
|
|
3559
|
+
mode: 448
|
|
3560
|
+
});
|
|
3561
|
+
const st = lstatSync(dir);
|
|
3562
|
+
return st.isDirectory() && st.uid === process.getuid?.() && (st.mode & 63) === 0;
|
|
3563
|
+
} catch {
|
|
3564
|
+
return false;
|
|
3565
|
+
}
|
|
3566
|
+
}
|
|
3567
|
+
/**
|
|
3568
|
+
* Whether ssh can listen on a control socket at `path` on `platform`. A socket's path has
|
|
3569
|
+
* `sizeof(sun_path)` bytes with its NUL (104 on macOS and the BSDs, 108 on Linux), and the master
|
|
3570
|
+
* first listens on `path` plus a 17-byte random suffix. `%C` expands to a 40-character hash.
|
|
3571
|
+
*/
|
|
3572
|
+
function controlPathFits(path, platform = process.platform) {
|
|
3573
|
+
const room = platform === "linux" ? 108 : 104;
|
|
3574
|
+
return Buffer.byteLength(path.replaceAll("%C", "C".repeat(40))) + 17 < room;
|
|
3575
|
+
}
|
|
3576
|
+
/**
|
|
3577
|
+
* The options that share one connection through a control socket at `path`, kept open `persistS`
|
|
3578
|
+
* seconds after the last command; none on Windows, whose OpenSSH has no ControlMaster, when the
|
|
3579
|
+
* path is too long for a socket ({@link controlPathFits}), or when the socket's directory isn't
|
|
3580
|
+
* {@link privateDir}. `path` may end in an ssh token such as `%C`.
|
|
3581
|
+
*/
|
|
3582
|
+
function controlOptions(path, persistS) {
|
|
3583
|
+
if (!path || process.platform === "win32" || !controlPathFits(path)) return [];
|
|
3584
|
+
if (!privateDir(dirname(path))) return [];
|
|
3585
|
+
return [
|
|
3167
3586
|
"-o",
|
|
3168
3587
|
"ControlMaster=auto",
|
|
3169
3588
|
"-o",
|
|
3170
|
-
`ControlPath=${
|
|
3589
|
+
`ControlPath=${path}`,
|
|
3171
3590
|
"-o",
|
|
3172
|
-
|
|
3173
|
-
]
|
|
3591
|
+
`ControlPersist=${persistS}`
|
|
3592
|
+
];
|
|
3593
|
+
}
|
|
3594
|
+
/**
|
|
3595
|
+
* The host argv that runs `remote`, one shell command line, on `target`. ssh joins its remote
|
|
3596
|
+
* arguments into one line for the login shell, so the caller quotes it. No user config applies.
|
|
3597
|
+
*/
|
|
3598
|
+
function sshArgv(target, remote) {
|
|
3174
3599
|
return [
|
|
3175
3600
|
"ssh",
|
|
3176
3601
|
"-T",
|
|
@@ -3180,8 +3605,7 @@ function sshArgv(target, remote) {
|
|
|
3180
3605
|
target.identityFile,
|
|
3181
3606
|
"-p",
|
|
3182
3607
|
String(target.port),
|
|
3183
|
-
|
|
3184
|
-
"BatchMode=yes",
|
|
3608
|
+
...SSH_OPTIONS,
|
|
3185
3609
|
"-o",
|
|
3186
3610
|
"IdentitiesOnly=yes",
|
|
3187
3611
|
"-o",
|
|
@@ -3194,13 +3618,7 @@ function sshArgv(target, remote) {
|
|
|
3194
3618
|
`HostKeyAlias=${target.hostKeyAlias}`,
|
|
3195
3619
|
"-o",
|
|
3196
3620
|
"ConnectTimeout=20",
|
|
3197
|
-
|
|
3198
|
-
"ServerAliveInterval=15",
|
|
3199
|
-
"-o",
|
|
3200
|
-
"ServerAliveCountMax=4",
|
|
3201
|
-
"-o",
|
|
3202
|
-
"LogLevel=ERROR",
|
|
3203
|
-
...shared,
|
|
3621
|
+
...controlOptions(target.controlPath, 300),
|
|
3204
3622
|
`${target.user}@${target.host}`,
|
|
3205
3623
|
remote
|
|
3206
3624
|
];
|
|
@@ -3236,13 +3654,27 @@ function containerTransport(containerId, engine) {
|
|
|
3236
3654
|
}
|
|
3237
3655
|
// ../sandbox-docker/src/egress/gateway.ts
|
|
3238
3656
|
/** Where the forwarder listens inside the sandbox; every exec gets it as its HTTP(S) proxy. */
|
|
3239
|
-
const PROXY_PORT =
|
|
3657
|
+
const PROXY_PORT = BASE_PROXY_PORT;
|
|
3240
3658
|
/** The gateway's CA certificate in the container. The private key never leaves the host. */
|
|
3241
3659
|
const CA_PATH = "/usr/local/share/ca-certificates/reeval-egress.crt";
|
|
3242
3660
|
/** Debian's system bundle, which `update-ca-certificates` rebuilds with the gateway's CA in it. */
|
|
3243
3661
|
const CA_BUNDLE = "/etc/ssl/certs/ca-certificates.crt";
|
|
3244
3662
|
const BUNDLED = "reeval:ca-bundle";
|
|
3663
|
+
/** Held while a gateway installs its CA, so gateways sharing a machine don't rebuild the bundle at once. */
|
|
3664
|
+
const CA_LOCK = "/var/lock/reeval-egress-ca";
|
|
3245
3665
|
const READY_TIMEOUT_MS = 15e3;
|
|
3666
|
+
/** Where a gateway on `port` keeps its CA certificate, and the glob of its pid files' tags. */
|
|
3667
|
+
const placement = (port) => port === void 0 ? {
|
|
3668
|
+
port: PROXY_PORT,
|
|
3669
|
+
caPath: CA_PATH,
|
|
3670
|
+
tags: "*",
|
|
3671
|
+
tag: ""
|
|
3672
|
+
} : {
|
|
3673
|
+
port,
|
|
3674
|
+
caPath: `/usr/local/share/ca-certificates/reeval-egress-${port}.crt`,
|
|
3675
|
+
tags: `p${port}-*`,
|
|
3676
|
+
tag: `p${port}-`
|
|
3677
|
+
};
|
|
3246
3678
|
/**
|
|
3247
3679
|
* Where a forwarder a transport could orphan records its pid, one file per gateway: `ps` can't
|
|
3248
3680
|
* find it by its command line, which Linux cuts short of a long script.
|
|
@@ -3251,11 +3683,11 @@ const PID_FILE = "/tmp/reeval-egress-forwarder";
|
|
|
3251
3683
|
/** How long `close()` waits for the sandbox to stop a forwarder a transport could orphan. */
|
|
3252
3684
|
const CLOSE_TIMEOUT_MS = 1e4;
|
|
3253
3685
|
/** Runs the forwarder; under a transport that orphans it, as the shell that wrote its pid file. */
|
|
3254
|
-
function forwarderCommand(transport, tag) {
|
|
3686
|
+
function forwarderCommand(transport, tag, port) {
|
|
3255
3687
|
const node = [
|
|
3256
3688
|
"node",
|
|
3257
3689
|
"-e",
|
|
3258
|
-
forwarderScript(
|
|
3690
|
+
forwarderScript(port)
|
|
3259
3691
|
];
|
|
3260
3692
|
if (!transport.orphans) return node;
|
|
3261
3693
|
return [
|
|
@@ -3282,31 +3714,50 @@ done; true`
|
|
|
3282
3714
|
input: "",
|
|
3283
3715
|
signal
|
|
3284
3716
|
}).then(() => {}, () => {});
|
|
3285
|
-
const installCa = (transport, cert, signal) =>
|
|
3286
|
-
"
|
|
3287
|
-
"-
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
3717
|
+
const installCa = (transport, cert, o, signal) => {
|
|
3718
|
+
const inBundle = `grep -q "$(sed -n 2p ${o.caPath})" ${CA_BUNDLE}`;
|
|
3719
|
+
const rebuild = "command -v update-ca-certificates >/dev/null && update-ca-certificates >/dev/null 2>&1";
|
|
3720
|
+
if (!o.shared) return execRun(transport, [
|
|
3721
|
+
"sh",
|
|
3722
|
+
"-c",
|
|
3723
|
+
`umask 022 && mkdir -p "$(dirname ${o.caPath})" && cat > ${o.caPath} && { ${rebuild} && ${inBundle} && echo ${BUNDLED}; true; }`
|
|
3724
|
+
], {
|
|
3725
|
+
input: cert,
|
|
3726
|
+
signal
|
|
3727
|
+
});
|
|
3728
|
+
const bundle = `{ ${inBundle} || { ${rebuild}; }; } && ${inBundle} && echo ${BUNDLED}; true`;
|
|
3729
|
+
return execRun(transport, [
|
|
3730
|
+
"sh",
|
|
3731
|
+
"-c",
|
|
3732
|
+
`umask 022 && mkdir -p "$(dirname ${o.caPath})" && cat > ${o.caPath}.$$ && mv ${o.caPath}.$$ ${o.caPath} && flock ${CA_LOCK} sh -c '${bundle}'`
|
|
3733
|
+
], {
|
|
3734
|
+
input: cert,
|
|
3735
|
+
signal
|
|
3736
|
+
});
|
|
3737
|
+
};
|
|
3293
3738
|
/**
|
|
3294
3739
|
* Starts the egress gateway for one sandbox: a forwarder inside it, tunneled over one process
|
|
3295
3740
|
* `transport` starts there, and the proxy in this process, which holds the real credentials.
|
|
3296
3741
|
*/
|
|
3297
3742
|
async function startGateway(transport, options, signal) {
|
|
3743
|
+
const { port: asked, ...proxyOptions } = options;
|
|
3744
|
+
const place = placement(asked);
|
|
3745
|
+
const { port } = place;
|
|
3298
3746
|
const ca = createCertificateAuthority();
|
|
3299
|
-
const installed = await installCa(transport, ca.cert,
|
|
3747
|
+
const installed = await installCa(transport, ca.cert, {
|
|
3748
|
+
caPath: place.caPath,
|
|
3749
|
+
shared: asked !== void 0
|
|
3750
|
+
}, signal);
|
|
3300
3751
|
if (installed.exitCode !== 0) throw new Error(`couldn't install the gateway CA: ${installed.stderr.trim()}`);
|
|
3301
3752
|
const bundled = installed.stdout.toString("utf8").includes(BUNDLED);
|
|
3302
|
-
if (transport.orphans) await killForwarders(transport,
|
|
3753
|
+
if (transport.orphans) await killForwarders(transport, place.tags, signal);
|
|
3303
3754
|
signal?.throwIfAborted();
|
|
3304
|
-
const tag = randomBytes(6).toString("hex")
|
|
3755
|
+
const tag = `${place.tag}${randomBytes(6).toString("hex")}`;
|
|
3305
3756
|
const proxy = createEgressProxy({
|
|
3306
|
-
...
|
|
3757
|
+
...proxyOptions,
|
|
3307
3758
|
ca
|
|
3308
3759
|
});
|
|
3309
|
-
const child = execSpawn(transport, forwarderCommand(transport, tag));
|
|
3760
|
+
const child = execSpawn(transport, forwarderCommand(transport, tag, port));
|
|
3310
3761
|
let stderr = "";
|
|
3311
3762
|
child.stderr.on("data", (d) => {
|
|
3312
3763
|
stderr += d;
|
|
@@ -3320,8 +3771,8 @@ async function startGateway(transport, options, signal) {
|
|
|
3320
3771
|
send: (frame) => {
|
|
3321
3772
|
if (!closed) child.stdin.write(frame);
|
|
3322
3773
|
},
|
|
3323
|
-
onOpen(stream,
|
|
3324
|
-
if (
|
|
3774
|
+
onOpen(stream, opened) {
|
|
3775
|
+
if (opened === port) proxy.handle(stream);
|
|
3325
3776
|
else stream.destroy();
|
|
3326
3777
|
},
|
|
3327
3778
|
onReady: () => {
|
|
@@ -3379,7 +3830,7 @@ async function startGateway(transport, options, signal) {
|
|
|
3379
3830
|
clearTimeout(timer);
|
|
3380
3831
|
signal?.removeEventListener("abort", onAbort);
|
|
3381
3832
|
}
|
|
3382
|
-
const proxyUrl = `http://127.0.0.1:${
|
|
3833
|
+
const proxyUrl = `http://127.0.0.1:${port}`;
|
|
3383
3834
|
const noProxy = "localhost,127.0.0.1,::1,[::1]";
|
|
3384
3835
|
return {
|
|
3385
3836
|
env: {
|
|
@@ -3389,7 +3840,7 @@ async function startGateway(transport, options, signal) {
|
|
|
3389
3840
|
http_proxy: proxyUrl,
|
|
3390
3841
|
NO_PROXY: noProxy,
|
|
3391
3842
|
no_proxy: noProxy,
|
|
3392
|
-
NODE_EXTRA_CA_CERTS:
|
|
3843
|
+
NODE_EXTRA_CA_CERTS: place.caPath,
|
|
3393
3844
|
NODE_USE_ENV_PROXY: "1",
|
|
3394
3845
|
...bundled ? {
|
|
3395
3846
|
SSL_CERT_FILE: CA_BUNDLE,
|
|
@@ -3401,6 +3852,7 @@ async function startGateway(transport, options, signal) {
|
|
|
3401
3852
|
addTransformations: proxy.addTransformations,
|
|
3402
3853
|
setTransformations: proxy.setTransformations,
|
|
3403
3854
|
setPolicy: proxy.setPolicy,
|
|
3855
|
+
switchPolicy: proxy.switchPolicy,
|
|
3404
3856
|
setSubstitutions: proxy.setSubstitutions,
|
|
3405
3857
|
traffic: proxy.traffic,
|
|
3406
3858
|
get stopped() {
|
|
@@ -3540,13 +3992,18 @@ const userEnv = (options) => ({
|
|
|
3540
3992
|
NPM_CONFIG_UPDATE_NOTIFIER: "false",
|
|
3541
3993
|
...options.root ? {} : { NPM_CONFIG_PREFIX: `${SANDBOX_HOME}/.local` }
|
|
3542
3994
|
});
|
|
3543
|
-
/**
|
|
3995
|
+
/**
|
|
3996
|
+
* The gateway didn't start for a detached container, which then has no way out, or the container
|
|
3997
|
+
* has a route out no disconnect takes away (`network`): `reason` says why.
|
|
3998
|
+
*/
|
|
3544
3999
|
var EgressUnavailableError = class extends Error {
|
|
3545
4000
|
reason;
|
|
3546
|
-
|
|
4001
|
+
network;
|
|
4002
|
+
constructor(reason, o = {}) {
|
|
3547
4003
|
super(`Can't enforce the egress policy: ${reason}`);
|
|
3548
4004
|
this.name = "EgressUnavailableError";
|
|
3549
4005
|
this.reason = reason;
|
|
4006
|
+
this.network = !!o.network;
|
|
3550
4007
|
}
|
|
3551
4008
|
};
|
|
3552
4009
|
/** Root's PATH in a privileged exec: none of the sandbox user's own `bin` directories. */
|
|
@@ -3718,9 +4175,10 @@ async function createDockerSession(options) {
|
|
|
3718
4175
|
});
|
|
3719
4176
|
let gateway;
|
|
3720
4177
|
let removed;
|
|
4178
|
+
const observers = [];
|
|
3721
4179
|
const remove = () => {
|
|
3722
4180
|
gateway?.close();
|
|
3723
|
-
removed ??=
|
|
4181
|
+
removed ??= Promise.all([id, ...observers].map((c) => removeContainerDetached(c, engine))).then(() => {});
|
|
3724
4182
|
return removed;
|
|
3725
4183
|
};
|
|
3726
4184
|
if (signal?.aborted) {
|
|
@@ -3757,13 +4215,22 @@ async function createDockerSession(options) {
|
|
|
3757
4215
|
}
|
|
3758
4216
|
const egressOptions = options.egress === true ? {} : options.egress || void 0;
|
|
3759
4217
|
let egress;
|
|
3760
|
-
|
|
4218
|
+
let directNow = !!egressOptions?.direct;
|
|
4219
|
+
const direct = (policy) => directNow && !isRestricted(policy);
|
|
3761
4220
|
let detached = [];
|
|
4221
|
+
/**
|
|
4222
|
+
* Its networks, or a throw when it has a route out that no disconnect can take away: the host's
|
|
4223
|
+
* network (Docker lists it as one, Podman as a mode) or rootless Podman's slirp4netns or pasta.
|
|
4224
|
+
*/
|
|
4225
|
+
const detachable = async () => {
|
|
4226
|
+
const networks = await networksOf(id, engine);
|
|
4227
|
+
const mode = networks.includes("host") ? "host" : networks.length === 0 ? await networkMode(id, engine) : "none";
|
|
4228
|
+
if (mode !== "none") throw new EgressUnavailableError(`the container's network is ${mode}, which ${spec.name} can't detach it from, so traffic around the gateway would still have a route out`, { network: true });
|
|
4229
|
+
return networks;
|
|
4230
|
+
};
|
|
3762
4231
|
const attach = async (policy) => {
|
|
3763
4232
|
if (!direct(policy) && detached.length === 0) {
|
|
3764
|
-
detached = await
|
|
3765
|
-
const mode = detached.length === 0 ? await networkMode(id, engine) : "none";
|
|
3766
|
-
if (detached.length === 0 && mode !== "none") throw new Error(`the container's network is ${mode}, which ${spec.name} can't detach it from, so traffic around the gateway would still have a route out`);
|
|
4233
|
+
detached = await detachable();
|
|
3767
4234
|
for (const n of detached) await dockerOk([
|
|
3768
4235
|
"network",
|
|
3769
4236
|
"disconnect",
|
|
@@ -3782,18 +4249,20 @@ async function createDockerSession(options) {
|
|
|
3782
4249
|
}
|
|
3783
4250
|
};
|
|
3784
4251
|
if (egressOptions) {
|
|
3785
|
-
const { policy = { mode: "allow-all" }, direct: _, ...rest } = egressOptions;
|
|
4252
|
+
const { policy = { mode: "allow-all" }, direct: _, detachLater, ...rest } = egressOptions;
|
|
3786
4253
|
try {
|
|
3787
4254
|
await attach(policy);
|
|
4255
|
+
if (detachLater && direct(policy)) await detachable();
|
|
3788
4256
|
gateway = await startGateway(containerTransport(id, engine), {
|
|
3789
4257
|
...rest,
|
|
3790
4258
|
policy
|
|
3791
4259
|
}, signal);
|
|
3792
4260
|
egress = { active: true };
|
|
3793
4261
|
} catch (error) {
|
|
3794
|
-
if (signal?.aborted || !direct(policy)) {
|
|
4262
|
+
if (signal?.aborted || !direct(policy) || detachLater) {
|
|
3795
4263
|
await remove();
|
|
3796
4264
|
if (signal?.aborted) throw signal.reason;
|
|
4265
|
+
if (error instanceof EgressUnavailableError) throw error;
|
|
3797
4266
|
throw new EgressUnavailableError(error.message);
|
|
3798
4267
|
}
|
|
3799
4268
|
egress = {
|
|
@@ -3891,6 +4360,119 @@ async function createDockerSession(options) {
|
|
|
3891
4360
|
throw error;
|
|
3892
4361
|
}
|
|
3893
4362
|
};
|
|
4363
|
+
/** Runs the engine's CLI with its output streamed; `stop` ends what it started. */
|
|
4364
|
+
const streamed = (args, stop) => {
|
|
4365
|
+
const startedAt = Date.now();
|
|
4366
|
+
const child = spawn(spec.bin, args, {
|
|
4367
|
+
stdio: [
|
|
4368
|
+
"ignore",
|
|
4369
|
+
"pipe",
|
|
4370
|
+
"pipe"
|
|
4371
|
+
],
|
|
4372
|
+
detached: true,
|
|
4373
|
+
env: {
|
|
4374
|
+
...process.env,
|
|
4375
|
+
...engineEnv(engine)
|
|
4376
|
+
}
|
|
4377
|
+
});
|
|
4378
|
+
child.stderr.resume();
|
|
4379
|
+
const exited = new Promise((resolve) => {
|
|
4380
|
+
child.once("error", () => resolve({ exitCode: 127 }));
|
|
4381
|
+
child.once("close", (code) => {
|
|
4382
|
+
traceDocker(args, startedAt, {
|
|
4383
|
+
exitCode: code,
|
|
4384
|
+
stdout: "<streamed>"
|
|
4385
|
+
}, spec.bin);
|
|
4386
|
+
resolve({ exitCode: code ?? 1 });
|
|
4387
|
+
});
|
|
4388
|
+
});
|
|
4389
|
+
return {
|
|
4390
|
+
pid: child.pid,
|
|
4391
|
+
stdout: Readable.toWeb(child.stdout),
|
|
4392
|
+
wait: () => exited,
|
|
4393
|
+
kill: async () => {
|
|
4394
|
+
child.kill("SIGKILL");
|
|
4395
|
+
await stop();
|
|
4396
|
+
}
|
|
4397
|
+
};
|
|
4398
|
+
};
|
|
4399
|
+
const spawnPrivileged = async (o) => {
|
|
4400
|
+
const marker = nextMarker();
|
|
4401
|
+
return streamed([
|
|
4402
|
+
"exec",
|
|
4403
|
+
"--user",
|
|
4404
|
+
"0:0",
|
|
4405
|
+
"--workdir",
|
|
4406
|
+
SANDBOX_STATE,
|
|
4407
|
+
"--env",
|
|
4408
|
+
`${EXEC_MARKER$1}=${marker}`,
|
|
4409
|
+
"--env",
|
|
4410
|
+
`PATH=${SYSTEM_PATH$1}`,
|
|
4411
|
+
id,
|
|
4412
|
+
"/bin/sh",
|
|
4413
|
+
"-c",
|
|
4414
|
+
o.command
|
|
4415
|
+
], () => killExec(marker, true));
|
|
4416
|
+
};
|
|
4417
|
+
const observer = {
|
|
4418
|
+
target: id,
|
|
4419
|
+
async spawn(o) {
|
|
4420
|
+
if (removed) throw new Error(`${spec.name} container ${id.slice(0, 12)} is gone`);
|
|
4421
|
+
const name = `reeval-observer-${nonce}-${observers.length + 1}`;
|
|
4422
|
+
observers.push(name);
|
|
4423
|
+
const args = [
|
|
4424
|
+
"run",
|
|
4425
|
+
"--rm",
|
|
4426
|
+
"--name",
|
|
4427
|
+
name,
|
|
4428
|
+
...Object.entries(labels).flatMap(([k, v]) => ["--label", `${k}=${v}`]),
|
|
4429
|
+
"--pull",
|
|
4430
|
+
"never",
|
|
4431
|
+
"--network",
|
|
4432
|
+
"none",
|
|
4433
|
+
"--cgroupns",
|
|
4434
|
+
"host",
|
|
4435
|
+
"--user",
|
|
4436
|
+
"65534:65534",
|
|
4437
|
+
"--cap-drop",
|
|
4438
|
+
"ALL",
|
|
4439
|
+
"--security-opt",
|
|
4440
|
+
"no-new-privileges",
|
|
4441
|
+
"--read-only",
|
|
4442
|
+
"--pids-limit",
|
|
4443
|
+
"16",
|
|
4444
|
+
"--entrypoint",
|
|
4445
|
+
"/bin/sh",
|
|
4446
|
+
options.image,
|
|
4447
|
+
"-c",
|
|
4448
|
+
o.command
|
|
4449
|
+
];
|
|
4450
|
+
return streamed(args, () => removeContainerDetached(name, engine));
|
|
4451
|
+
},
|
|
4452
|
+
async run(o) {
|
|
4453
|
+
const name = observers.at(-1);
|
|
4454
|
+
if (!name) return {
|
|
4455
|
+
exitCode: 1,
|
|
4456
|
+
stdout: "",
|
|
4457
|
+
stderr: "no observer started"
|
|
4458
|
+
};
|
|
4459
|
+
const r = await docker([
|
|
4460
|
+
"exec",
|
|
4461
|
+
name,
|
|
4462
|
+
"/bin/sh",
|
|
4463
|
+
"-c",
|
|
4464
|
+
o.command
|
|
4465
|
+
], {
|
|
4466
|
+
signal: o.abortSignal,
|
|
4467
|
+
engine
|
|
4468
|
+
});
|
|
4469
|
+
return {
|
|
4470
|
+
exitCode: r.exitCode,
|
|
4471
|
+
stdout: r.stdout.toString("utf8"),
|
|
4472
|
+
stderr: r.stderr
|
|
4473
|
+
};
|
|
4474
|
+
}
|
|
4475
|
+
};
|
|
3894
4476
|
const readBinaryFile = async (o) => {
|
|
3895
4477
|
const r = await docker([
|
|
3896
4478
|
"exec",
|
|
@@ -3972,6 +4554,12 @@ async function createDockerSession(options) {
|
|
|
3972
4554
|
async setSubstitutions(subs) {
|
|
3973
4555
|
gateway?.setSubstitutions(subs);
|
|
3974
4556
|
},
|
|
4557
|
+
async setEgress({ policy, direct: keeps, phase }) {
|
|
4558
|
+
directNow = keeps;
|
|
4559
|
+
if (!direct(policy)) await attach(policy);
|
|
4560
|
+
await gateway?.switchPolicy(policy, phase);
|
|
4561
|
+
if (direct(policy)) await attach(policy);
|
|
4562
|
+
},
|
|
3975
4563
|
traffic: () => gateway.traffic()
|
|
3976
4564
|
} : {};
|
|
3977
4565
|
const session = {
|
|
@@ -3991,6 +4579,8 @@ async function createDockerSession(options) {
|
|
|
3991
4579
|
oomKills: () => oomKills(id, engine, execUser(options)),
|
|
3992
4580
|
run,
|
|
3993
4581
|
runPrivileged,
|
|
4582
|
+
spawnPrivileged,
|
|
4583
|
+
observer,
|
|
3994
4584
|
spawn: (async (o) => {
|
|
3995
4585
|
if (o.stdin) throw new Error(`A ${spec.name} sandbox process has no writable stdin`);
|
|
3996
4586
|
const env = envFor(o.env);
|
|
@@ -4112,99 +4702,56 @@ const dockerSandboxProvider = (options) => ({
|
|
|
4112
4702
|
}
|
|
4113
4703
|
});
|
|
4114
4704
|
// ../sandbox-docker/src/build-image.ts
|
|
4705
|
+
/** The pnpm every image and baked Tart VM has: the harness bridges install with it. */
|
|
4115
4706
|
const PNPM_VERSION = "10.33.3";
|
|
4116
4707
|
/** Pinned so evals' installs don't move with the Node image's bundled npm. */
|
|
4117
4708
|
const NPM_VERSION = "11.20.0";
|
|
4709
|
+
const sha256 = (text) => createHash("sha256").update(text).digest("hex");
|
|
4710
|
+
/** Docker's names for Node's architectures, as image indexes list platforms. */
|
|
4711
|
+
const OCI_ARCH = {
|
|
4712
|
+
x64: "amd64",
|
|
4713
|
+
arm64: "arm64",
|
|
4714
|
+
arm: "arm",
|
|
4715
|
+
ppc64: "ppc64le"
|
|
4716
|
+
};
|
|
4118
4717
|
/**
|
|
4119
|
-
*
|
|
4120
|
-
*
|
|
4121
|
-
*
|
|
4718
|
+
* Linux on this process's architecture, as `docker image inspect` names a platform
|
|
4719
|
+
* (`.Os/.Architecture`): what Docker Desktop's and Podman's VMs run, and the fallback when the
|
|
4720
|
+
* engine doesn't say its own (`enginePlatform`).
|
|
4122
4721
|
*/
|
|
4123
|
-
const
|
|
4124
|
-
const sha256 = (text) => createHash("sha256").update(text).digest("hex");
|
|
4722
|
+
const PLATFORM = `linux/${OCI_ARCH[process.arch] ?? process.arch}`;
|
|
4125
4723
|
const slugify = (text, max) => text.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, max).replace(/-+$/, "");
|
|
4126
4724
|
/** The build context of reeval's base image, shipped in the package. */
|
|
4127
4725
|
const DOCKER_CONTEXT = fileURLToPath(ownFileURL("docker"));
|
|
4128
4726
|
/**
|
|
4129
|
-
*
|
|
4130
|
-
*
|
|
4727
|
+
* The official Node image the sandbox's Node comes from, pinned by its index digest: the base
|
|
4728
|
+
* Dockerfile's `FROM`, which the toolchain layer also copies onto a `from` image. The pin is what
|
|
4729
|
+
* makes reeval's image, and every key built on it, the same content on any machine. Node 24+
|
|
4730
|
+
* bundles undici 7, whose `EnvHttpProxyAgent` (behind `NODE_USE_ENV_PROXY`) prints no experimental
|
|
4731
|
+
* warning.
|
|
4732
|
+
*/
|
|
4733
|
+
const NODE_IMAGE = /^FROM (\S+)$/m.exec(readFileSync(join(DOCKER_CONTEXT, "Dockerfile"), "utf8"))?.[1] ?? "node";
|
|
4734
|
+
/**
|
|
4735
|
+
* How reeval bakes a harness into a Docker or Tart image, beyond the build context, the adapter and
|
|
4736
|
+
* the inputs each passes {@link bakeKey}: bump it when that changes what a baked image holds, so
|
|
4737
|
+
* every image baked before rebuilds on its next use.
|
|
4131
4738
|
*/
|
|
4132
4739
|
const BAKE_REVISION = 2;
|
|
4133
4740
|
/**
|
|
4134
|
-
* The
|
|
4135
|
-
*
|
|
4136
|
-
* or how the harness is baked builds anew.
|
|
4741
|
+
* The hash a baked image's name ends with: {@link BAKE_REVISION} and what the bake starts from and
|
|
4742
|
+
* runs, so a change to any of them bakes anew.
|
|
4137
4743
|
*/
|
|
4138
|
-
const
|
|
4744
|
+
const bakeKey = (...inputs) => sha256([BAKE_REVISION, ...inputs].join("\0")).slice(0, 8);
|
|
4139
4745
|
/**
|
|
4140
|
-
*
|
|
4141
|
-
*
|
|
4746
|
+
* The image `docker({ from })` evals run in: `from` plus Node, git and the harness's CLI. Its
|
|
4747
|
+
* {@link bakeKey} covers the toolchain layer, so a change to the sandbox user or paths builds anew.
|
|
4142
4748
|
*/
|
|
4143
|
-
const
|
|
4144
|
-
cursor: {
|
|
4145
|
-
name: "Cursor",
|
|
4146
|
-
cli: "@cursor/sdk",
|
|
4147
|
-
version: `node -p "'@cursor/sdk ' + require(process.env.HOME + '/.ai-sdk-harness/.harness-bootstrap/cursor-sdk/node_modules/@cursor/sdk/package.json').version"`,
|
|
4148
|
-
adapter: async () => (await import("./src-CsFaawcZ.js")).createCursorSdk()
|
|
4149
|
-
},
|
|
4150
|
-
"claude-code": {
|
|
4151
|
-
name: "Claude Code",
|
|
4152
|
-
cli: "claude",
|
|
4153
|
-
adapter: async () => (await import("./dist-Db7ifchA.js")).createClaudeCode()
|
|
4154
|
-
},
|
|
4155
|
-
antigravity: {
|
|
4156
|
-
name: "Antigravity",
|
|
4157
|
-
cli: "agy",
|
|
4158
|
-
adapter: async () => (await import("./src-BbZYaQ8b.js")).createAntigravity()
|
|
4159
|
-
},
|
|
4160
|
-
opencode: {
|
|
4161
|
-
name: "OpenCode",
|
|
4162
|
-
cli: "opencode",
|
|
4163
|
-
adapter: async () => (await import("./src-1dBuXzs4.js")).createOpenCode({
|
|
4164
|
-
auth: { GOOGLE_GENERATIVE_AI_API_KEY: "unused" },
|
|
4165
|
-
model: "google/unused"
|
|
4166
|
-
})
|
|
4167
|
-
},
|
|
4168
|
-
goose: {
|
|
4169
|
-
name: "Goose",
|
|
4170
|
-
cli: "goose",
|
|
4171
|
-
adapter: async () => (await import("./src-BY1cCaoJ.js")).createGoose({
|
|
4172
|
-
auth: { GOOGLE_API_KEY: "unused" },
|
|
4173
|
-
model: "unused"
|
|
4174
|
-
})
|
|
4175
|
-
},
|
|
4176
|
-
pi: {
|
|
4177
|
-
name: "pi",
|
|
4178
|
-
cli: "pi",
|
|
4179
|
-
adapter: async () => (await import("./src-CrV2WA2i.js")).createPi({ auth: { GEMINI_API_KEY: "unused" } })
|
|
4180
|
-
},
|
|
4181
|
-
codex: {
|
|
4182
|
-
name: "Codex",
|
|
4183
|
-
cli: "codex",
|
|
4184
|
-
adapter: async () => (await import("./src-CDFH2vVN.js")).createCodex({ auth: { OPENAI_API_KEY: "unused" } })
|
|
4185
|
-
},
|
|
4186
|
-
fx: {
|
|
4187
|
-
name: "fx",
|
|
4188
|
-
cli: "fx",
|
|
4189
|
-
adapter: async () => (await import("./src-wKwznPgt.js")).createFx({
|
|
4190
|
-
auth: { AI_GATEWAY_API_KEY: "unused" },
|
|
4191
|
-
model: "unused/unused"
|
|
4192
|
-
})
|
|
4193
|
-
},
|
|
4194
|
-
"grok-build": {
|
|
4195
|
-
name: "Grok Build",
|
|
4196
|
-
cli: "grok",
|
|
4197
|
-
adapter: async () => (await import("./src-BKpioayC.js")).createGrokBuild({
|
|
4198
|
-
auth: { XAI_API_KEY: "unused" },
|
|
4199
|
-
model: "unused"
|
|
4200
|
-
})
|
|
4201
|
-
}
|
|
4202
|
-
};
|
|
4749
|
+
const harnessImageFor = (harness, from) => `${imageFor(harness)}-${slugify(from, 40) || "image"}-${bakeKey(toolchainDockerfile(from))}`;
|
|
4203
4750
|
/**
|
|
4204
4751
|
* The adapter whose bootstrap `harness`'s image bakes. An attempt whose adapter asks for any other
|
|
4205
4752
|
* bootstrap reinstalls the CLI at start, which a restricted egress policy can refuse.
|
|
4206
4753
|
*/
|
|
4207
|
-
const bakedAdapter = (harness) =>
|
|
4754
|
+
const bakedAdapter = (harness) => HARNESS_PACKAGES[harness].bootstrap.adapter();
|
|
4208
4755
|
/** Keeps the image's `PATH` in login shells, which Debian's `/etc/profile` resets. */
|
|
4209
4756
|
const profilePathScript = () => readFileSync(join(DOCKER_CONTEXT, "reeval-path.sh")).toString("base64");
|
|
4210
4757
|
/** `from` as it goes after `FROM`: one word, so it can't add a stage name or another instruction. */
|
|
@@ -4277,6 +4824,12 @@ function buildError(output, what, reason, keep = () => true) {
|
|
|
4277
4824
|
}
|
|
4278
4825
|
/** Every image reeval builds carries this label, so `reeval clean --images` can find what it left. */
|
|
4279
4826
|
const BUILT_BY = ["--label", `${LABEL.managed}=image`];
|
|
4827
|
+
const keyLabel = (key) => ["--label", `${LABEL.key}=${key}`];
|
|
4828
|
+
/** Removes the image `tag` pointed at before a rebuild, once the tag points elsewhere. */
|
|
4829
|
+
async function replaced(tag, previous, engine) {
|
|
4830
|
+
if (!previous) return;
|
|
4831
|
+
if ((await imageInfo(tag, engine))?.id !== previous) await removeQuietly(previous, engine);
|
|
4832
|
+
}
|
|
4280
4833
|
/**
|
|
4281
4834
|
* Removes the images reeval built that nothing tags any more (a rebuild's old image) and the
|
|
4282
4835
|
* intermediate `-base` tags of `from` builds. Returns how many it removed.
|
|
@@ -4313,13 +4866,6 @@ async function pruneImages(engine) {
|
|
|
4313
4866
|
], { engine }).catch(() => null))?.exitCode === 0) removed++;
|
|
4314
4867
|
return removed;
|
|
4315
4868
|
}
|
|
4316
|
-
/** Docker's names for Node's architectures, as image indexes list platforms. */
|
|
4317
|
-
const OCI_ARCH = {
|
|
4318
|
-
x64: "amd64",
|
|
4319
|
-
arm64: "arm64",
|
|
4320
|
-
arm: "arm",
|
|
4321
|
-
ppc64: "ppc64le"
|
|
4322
|
-
};
|
|
4323
4869
|
/**
|
|
4324
4870
|
* A registry digest for `from` without Docker's buildx: skopeo's, which is the same digest
|
|
4325
4871
|
* buildx gives, or else this platform's manifest from `podman manifest inspect`.
|
|
@@ -4413,6 +4959,28 @@ function contextHash() {
|
|
|
4413
4959
|
return hash.digest("hex").slice(0, 16);
|
|
4414
4960
|
}
|
|
4415
4961
|
/**
|
|
4962
|
+
* reeval's image for a harness: its tag (the adapter) and its base's build context, whose `FROM` is
|
|
4963
|
+
* pinned by digest.
|
|
4964
|
+
*/
|
|
4965
|
+
const reevalImageKey = (harness) => `${imageFor(harness)}+${contextHash()}`;
|
|
4966
|
+
/**
|
|
4967
|
+
* A harness baked onto `from`: its tag and what `from` named when it was built, a registry digest
|
|
4968
|
+
* (or, for a base only this machine has, its image id, or a Dockerfile image's own key).
|
|
4969
|
+
*/
|
|
4970
|
+
const fromImageKey = (ref, digest) => `${ref}@${digest}`;
|
|
4971
|
+
/**
|
|
4972
|
+
* The key of an image only this machine can name, such as a Dockerfile built on a base that didn't
|
|
4973
|
+
* resolve: its tag and local image id. Nothing keyed on one is pulled or pushed.
|
|
4974
|
+
*/
|
|
4975
|
+
const localKey = (ref, id) => `${ref}@local:${id}`;
|
|
4976
|
+
/** Whether `key` is a {@link localKey}, or a key built on one. */
|
|
4977
|
+
const isLocalKey = (key) => key.includes("@local:");
|
|
4978
|
+
/**
|
|
4979
|
+
* An image reeval uses as is: its image id, which is content-addressed, so the same on every machine
|
|
4980
|
+
* that pulled it (and this machine's alone for one built here), whichever registries it's in.
|
|
4981
|
+
*/
|
|
4982
|
+
const imageKey = (info) => info.id;
|
|
4983
|
+
/**
|
|
4416
4984
|
* Bakes a harness's bootstrap (which installs its agent's CLI) into an image, so the image tag
|
|
4417
4985
|
* pins the CLI build. Rebuild after bumping the adapter. With `from`, the base is that toolchain
|
|
4418
4986
|
* image instead of reeval's Node image. `log` gets progress lines, `output` the build's full output
|
|
@@ -4424,9 +4992,11 @@ async function buildImage(log, options) {
|
|
|
4424
4992
|
const resolved = from ? await resolveFrom(from, signal, engine) : null;
|
|
4425
4993
|
const digest = resolved && "digest" in resolved ? resolved.digest : null;
|
|
4426
4994
|
const pinned = from && digest && resolved && "local" in resolved && !resolved.local && !from.includes("@") ? `${from}@${digest}` : from;
|
|
4427
|
-
const bootstrap =
|
|
4995
|
+
const { bootstrap } = HARNESS_PACKAGES[harness];
|
|
4428
4996
|
const base = from ? `${harnessImageFor(harness, from)}-base` : BASE_IMAGE;
|
|
4429
4997
|
const target = from ? harnessImageFor(harness, from) : imageFor(harness);
|
|
4998
|
+
const shared = !!resolved && "local" in resolved && !resolved.local;
|
|
4999
|
+
const key = options.key ?? (from ? digest && shared ? fromImageKey(target, digest) : "" : reevalImageKey(harness));
|
|
4430
5000
|
const previous = [(await imageInfo(target, engine))?.id, from ? null : (await imageInfo(base, engine))?.id];
|
|
4431
5001
|
log(`Building ${base}${from ? ` from ${from}` : ""}`);
|
|
4432
5002
|
const build = from ? await docker([
|
|
@@ -4477,11 +5047,11 @@ async function buildImage(log, options) {
|
|
|
4477
5047
|
let agentVersion;
|
|
4478
5048
|
try {
|
|
4479
5049
|
agentVersion = await bake(session, bootstrap);
|
|
4480
|
-
log(`${bootstrap.name} ${bootstrap.
|
|
5050
|
+
log(`${bootstrap.name} ${bootstrap.probe ? "" : "CLI "}${agentVersion}`);
|
|
4481
5051
|
await dockerOk([
|
|
4482
5052
|
"commit",
|
|
4483
5053
|
"--change",
|
|
4484
|
-
`LABEL ${LABEL.agentVersion}="${agentVersion}" ${LABEL.harness}="${harnessLabel(harness)}"${from ? digest ? ` ${LABEL.fromDigest}="${digest}"` : "" : ` ${LABEL.context}="${contextHash()}"`}`,
|
|
5054
|
+
`LABEL ${LABEL.agentVersion}="${agentVersion}" ${LABEL.harness}="${harnessLabel(harness)}"${from ? digest ? ` ${LABEL.fromDigest}="${digest}"` : "" : ` ${LABEL.context}="${contextHash()}"`} ${LABEL.key}="${key}"`,
|
|
4485
5055
|
"--change",
|
|
4486
5056
|
`WORKDIR ${SANDBOX_ROOT}`,
|
|
4487
5057
|
"--change",
|
|
@@ -4522,28 +5092,50 @@ async function buildImage(log, options) {
|
|
|
4522
5092
|
agentVersion
|
|
4523
5093
|
};
|
|
4524
5094
|
}
|
|
4525
|
-
/**
|
|
5095
|
+
/**
|
|
5096
|
+
* Runs `harness`'s bootstrap in `session` (a container, or a VM reeval then keeps as an image)
|
|
5097
|
+
* and returns the CLI version it installed.
|
|
5098
|
+
*/
|
|
5099
|
+
const bakeHarness = (session, harness) => bake(session, HARNESS_PACKAGES[harness].bootstrap);
|
|
5100
|
+
/**
|
|
5101
|
+
* A hash of the bootstrap `harness`'s adapter applies (its files and commands): it changes
|
|
5102
|
+
* whenever what the bootstrap installs does, version bump or not.
|
|
5103
|
+
*/
|
|
5104
|
+
async function bakedRecipe(harness) {
|
|
5105
|
+
const recipe = await (await HARNESS_PACKAGES[harness].bootstrap.adapter()).getBootstrap?.({});
|
|
5106
|
+
if (!recipe) return "none";
|
|
5107
|
+
const files = [...recipe.files].sort((a, b) => a.path.localeCompare(b.path)).map((f) => [f.path, f.content]);
|
|
5108
|
+
return createHash("sha256").update(JSON.stringify([
|
|
5109
|
+
recipe.harnessId,
|
|
5110
|
+
recipe.bootstrapDir,
|
|
5111
|
+
files,
|
|
5112
|
+
recipe.commands
|
|
5113
|
+
])).digest("hex").slice(0, 16);
|
|
5114
|
+
}
|
|
5115
|
+
/** The harness's name, as a bake's progress says it. */
|
|
5116
|
+
const bakedHarnessName = (harness) => HARNESS_PACKAGES[harness].bootstrap.name;
|
|
5117
|
+
/** Runs the harness bootstrap in `session` and returns the CLI version it installed. */
|
|
4526
5118
|
async function bake(session, bootstrap) {
|
|
4527
5119
|
await (await createHarnessSandboxTemplate({
|
|
4528
5120
|
harnesses: [await bootstrap.adapter()],
|
|
4529
5121
|
sandboxConfig: { workDir: WORKSPACE_DIR }
|
|
4530
5122
|
}))?.prepare({ session });
|
|
4531
|
-
let probe = bootstrap.
|
|
5123
|
+
let probe = bootstrap.probe;
|
|
4532
5124
|
if (!probe) {
|
|
4533
5125
|
const bin = (await session.run({ command: `find "$HOME/.ai-sdk-harness" -name ${bootstrap.cli} \\( -type f -o -type l \\) -perm -u+x | head -1` })).stdout.trim();
|
|
4534
5126
|
if (!bin) throw new Error(`The harness bootstrap did not install the ${bootstrap.name} CLI`);
|
|
4535
5127
|
probe = `'${bin}' --version`;
|
|
4536
5128
|
}
|
|
4537
5129
|
const version = await session.run({ command: probe });
|
|
4538
|
-
if (bootstrap.
|
|
5130
|
+
if (bootstrap.probe && version.exitCode !== 0) throw new Error(`The harness bootstrap did not install ${bootstrap.cli}:\n${tail(version.stderr)}`);
|
|
4539
5131
|
return versionLabel(version.stdout.trim());
|
|
4540
5132
|
}
|
|
4541
5133
|
/**
|
|
4542
5134
|
* The image `docker({ install })` runs in: the commands on top of `parent`, tagged by the parent's
|
|
4543
|
-
*
|
|
5135
|
+
* content key and the exact list, so it's built once. Secrets and the workspace never exist here.
|
|
4544
5136
|
*/
|
|
4545
5137
|
const installLayerTag = (parent, steps) => `reeval-install:${sha256(JSON.stringify({
|
|
4546
|
-
parent: parent.
|
|
5138
|
+
parent: parent.key,
|
|
4547
5139
|
steps
|
|
4548
5140
|
})).slice(0, 16)}`;
|
|
4549
5141
|
/** The commands as one bash script: in order, from `/`, stopping at the first that fails. */
|
|
@@ -4557,20 +5149,15 @@ function installScript(steps) {
|
|
|
4557
5149
|
}
|
|
4558
5150
|
return `${lines.join("\n")}\n`;
|
|
4559
5151
|
}
|
|
4560
|
-
/**
|
|
5152
|
+
/**
|
|
5153
|
+
* Builds the install layer if it's missing, or again with `force` (`reeval image build --force`,
|
|
5154
|
+
* whose rebuilt parent keeps its key). `output` gets the build's output, for a log file.
|
|
5155
|
+
*/
|
|
4561
5156
|
async function buildInstallLayer(parent, steps, options = {}) {
|
|
4562
5157
|
const { signal, engine } = options;
|
|
4563
5158
|
const tag = installLayerTag(parent, steps);
|
|
4564
|
-
|
|
4565
|
-
|
|
4566
|
-
"inspect",
|
|
4567
|
-
"--format",
|
|
4568
|
-
"{{.Created}}",
|
|
4569
|
-
tag
|
|
4570
|
-
], {
|
|
4571
|
-
signal,
|
|
4572
|
-
engine
|
|
4573
|
-
})).exitCode === 0) return tag;
|
|
5159
|
+
const previous = (await imageInfo(tag, engine))?.id;
|
|
5160
|
+
if (previous && !options.force) return tag;
|
|
4574
5161
|
const script = installScript(steps);
|
|
4575
5162
|
const encoded = Buffer.from(script).toString("base64");
|
|
4576
5163
|
const home = `$(getent passwd ${SANDBOX_USER} | cut -d: -f6)`;
|
|
@@ -4588,6 +5175,7 @@ async function buildInstallLayer(parent, steps, options = {}) {
|
|
|
4588
5175
|
"--progress",
|
|
4589
5176
|
"plain",
|
|
4590
5177
|
...BUILT_BY,
|
|
5178
|
+
...keyLabel(tag),
|
|
4591
5179
|
"--tag",
|
|
4592
5180
|
tag,
|
|
4593
5181
|
"-"
|
|
@@ -4608,6 +5196,7 @@ async function buildInstallLayer(parent, steps, options = {}) {
|
|
|
4608
5196
|
engine
|
|
4609
5197
|
}, () => failed ? `install ${failed[1]} exited ${failed[2]}: ${clipLine(failed[3] ?? "")}` : null, (line) => !line.startsWith("reeval: install "));
|
|
4610
5198
|
}
|
|
5199
|
+
await replaced(tag, previous, engine);
|
|
4611
5200
|
return tag;
|
|
4612
5201
|
}
|
|
4613
5202
|
/** Where a plugin layer leaves each built plugin, by its build's hash. */
|
|
@@ -4636,8 +5225,8 @@ const pluginBuildKey = (b) => sha256(JSON.stringify({
|
|
|
4636
5225
|
cwd: b.cwd,
|
|
4637
5226
|
run: b.steps
|
|
4638
5227
|
}));
|
|
4639
|
-
/** The image a plugin build makes on `parent`: the parent's
|
|
4640
|
-
const pluginLayerTag = (parent, b) => `reeval-plugin:${parent.
|
|
5228
|
+
/** The image a plugin build makes on `parent`: the parent's content key, then the build's hash. */
|
|
5229
|
+
const pluginLayerTag = (parent, b) => `reeval-plugin:${sha256(parent.key).slice(0, 12)}-${pluginBuildKey(b).slice(0, 16)}`;
|
|
4641
5230
|
/** Where a plugin layer leaves the plugin's directory. */
|
|
4642
5231
|
const pluginBuildDir = (b) => `${PLUGIN_BUILDS_DIR}/${pluginBuildKey(b).slice(0, 16)}`;
|
|
4643
5232
|
/** The line a plugin build's script fails with when its `cwd` isn't in the source. */
|
|
@@ -4655,16 +5244,8 @@ const pluginBuildScript = (b, src) => installScript(b.steps).replaceAll("reeval:
|
|
|
4655
5244
|
async function buildPluginLayer(parent, b, options) {
|
|
4656
5245
|
const { signal, engine } = options;
|
|
4657
5246
|
const tag = pluginLayerTag(parent, b);
|
|
4658
|
-
|
|
4659
|
-
|
|
4660
|
-
"inspect",
|
|
4661
|
-
"--format",
|
|
4662
|
-
"{{.Created}}",
|
|
4663
|
-
tag
|
|
4664
|
-
], {
|
|
4665
|
-
signal,
|
|
4666
|
-
engine
|
|
4667
|
-
})).exitCode === 0) return tag;
|
|
5247
|
+
const previous = (await imageInfo(tag, engine))?.id;
|
|
5248
|
+
if (previous && !options.force) return tag;
|
|
4668
5249
|
const src = "/tmp/reeval-plugin-src";
|
|
4669
5250
|
const script = pluginBuildScript(b, src);
|
|
4670
5251
|
const encoded = Buffer.from(script).toString("base64");
|
|
@@ -4687,6 +5268,7 @@ async function buildPluginLayer(parent, b, options) {
|
|
|
4687
5268
|
"--progress",
|
|
4688
5269
|
"plain",
|
|
4689
5270
|
...BUILT_BY,
|
|
5271
|
+
...keyLabel(tag),
|
|
4690
5272
|
"--tag",
|
|
4691
5273
|
tag,
|
|
4692
5274
|
"-f",
|
|
@@ -4710,6 +5292,7 @@ async function buildPluginLayer(parent, b, options) {
|
|
|
4710
5292
|
engine
|
|
4711
5293
|
}, () => missing ? noCwd(b.cwd).slice(8) : failed ? `build ${failed[1]} exited ${failed[2]}: ${clipLine(failed[3] ?? "")}` : null, (line) => !line.startsWith("reeval: build "));
|
|
4712
5294
|
}
|
|
5295
|
+
await replaced(tag, previous, engine);
|
|
4713
5296
|
return tag;
|
|
4714
5297
|
}
|
|
4715
5298
|
/** The build arg a Dockerfile can start `FROM` to layer on reeval's sandbox image. */
|
|
@@ -4719,12 +5302,13 @@ const usesReevalBase = (dockerfile) => new RegExp(`\\$\\{?${REEVAL_BASE_ARG}\\b`
|
|
|
4719
5302
|
/**
|
|
4720
5303
|
* The tag of a `docker({ dockerfile })` build for a harness: a hash of the Dockerfile, every file
|
|
4721
5304
|
* of its build context (its directory, less `.dockerignore`) and, for a Dockerfile `FROM
|
|
4722
|
-
* ${REEVAL_BASE}`, the
|
|
4723
|
-
*
|
|
5305
|
+
* ${REEVAL_BASE}`, the {@link reevalImageKey} of the harness's image it names, so an edit to any of
|
|
5306
|
+
* them, or a new reeval base, builds anew, and the same files give the same tag on any machine. What
|
|
5307
|
+
* its other bases' tags name is in its key ({@link dockerfileKey}), not its tag.
|
|
4724
5308
|
*/
|
|
4725
|
-
function dockerfileTag(dockerfile, harness
|
|
5309
|
+
function dockerfileTag(dockerfile, harness) {
|
|
4726
5310
|
const context = dirname(dockerfile);
|
|
4727
|
-
const base = usesReevalBase(dockerfile) ?
|
|
5311
|
+
const base = usesReevalBase(dockerfile) ? reevalImageKey(harness) : "";
|
|
4728
5312
|
const hash = createHash("sha256").update(`${REEVAL_BASE_ARG}=${base}\0`);
|
|
4729
5313
|
for (const path of contextFiles(context, dockerfile)) {
|
|
4730
5314
|
const full = join(context, path);
|
|
@@ -4740,14 +5324,57 @@ function dockerfileTag(dockerfile, harness, reevalBase = null) {
|
|
|
4740
5324
|
};
|
|
4741
5325
|
}
|
|
4742
5326
|
/**
|
|
5327
|
+
* The images a Dockerfile's `FROM`, `COPY --from` and `--mount=…,from=` name by a tag that can
|
|
5328
|
+
* move: not `${REEVAL_BASE}`, an earlier stage, `scratch` or a digest-pinned image. `opaque` when
|
|
5329
|
+
* one names an image through any other build arg, which only the build resolves.
|
|
5330
|
+
*/
|
|
5331
|
+
function dockerfileBases(dockerfile) {
|
|
5332
|
+
const stages = /* @__PURE__ */ new Set();
|
|
5333
|
+
const bases = [];
|
|
5334
|
+
let opaque = false;
|
|
5335
|
+
const reevalBase = new RegExp(`^\\$\\{?${REEVAL_BASE_ARG}\\}?$`);
|
|
5336
|
+
const add = (image) => {
|
|
5337
|
+
const name = image.toLowerCase();
|
|
5338
|
+
if (image.includes("$")) {
|
|
5339
|
+
if (!reevalBase.test(image)) opaque = true;
|
|
5340
|
+
return;
|
|
5341
|
+
}
|
|
5342
|
+
if (stages.has(name) || name === "scratch" || /^\d+$/.test(name)) return;
|
|
5343
|
+
if (/@sha256:[0-9a-f]{64}$/.test(image) || bases.includes(image)) return;
|
|
5344
|
+
bases.push(image);
|
|
5345
|
+
};
|
|
5346
|
+
const text = readFileSync(dockerfile, "utf8").replace(/\\[ \t]*\r?\n/g, " ");
|
|
5347
|
+
for (const line of text.split("\n")) {
|
|
5348
|
+
if (/^\s*#/.test(line)) continue;
|
|
5349
|
+
const from = /^\s*FROM\s+(?:--platform=\S+\s+)?(\S+)(?:\s+AS\s+(\S+))?/i.exec(line);
|
|
5350
|
+
if (from?.[1]) {
|
|
5351
|
+
add(from[1]);
|
|
5352
|
+
if (from[2]) stages.add(from[2].toLowerCase());
|
|
5353
|
+
}
|
|
5354
|
+
if (!/^\s*(?:COPY|ADD|RUN)\s/i.test(line)) continue;
|
|
5355
|
+
for (const m of line.matchAll(/(?:^|\s)--from=(\S+)/gi)) if (m[1]) add(m[1]);
|
|
5356
|
+
for (const m of line.matchAll(/--mount=\S*?\bfrom=([^,\s]+)/gi)) if (m[1]) add(m[1]);
|
|
5357
|
+
}
|
|
5358
|
+
return {
|
|
5359
|
+
bases,
|
|
5360
|
+
opaque
|
|
5361
|
+
};
|
|
5362
|
+
}
|
|
5363
|
+
/**
|
|
5364
|
+
* A Dockerfile image's content key: its tag, plus the digest each of its {@link dockerfileBases}
|
|
5365
|
+
* named when it was built, so a base that moved upstream is another image. One whose bases can't all
|
|
5366
|
+
* be named this way is keyed on its local image id instead ({@link localKey}).
|
|
5367
|
+
*/
|
|
5368
|
+
const dockerfileKey = (tag, bases) => bases.length ? `${tag}+${bases.map((b) => `${b.ref}@${b.digest}`).join(",")}` : tag;
|
|
5369
|
+
/**
|
|
4743
5370
|
* Builds the user's Dockerfile with plain `docker build` (so Docker's layer cache applies), from
|
|
4744
|
-
* its directory, with `REEVAL_BASE` set to the harness's sandbox image
|
|
5371
|
+
* its directory, with `REEVAL_BASE` set to the harness's sandbox image.
|
|
4745
5372
|
* Rebuilds even when the tag exists with `force`, as `reeval image build` does, and then removes the
|
|
4746
5373
|
* image the tag pointed at before. `name` is the path failures name.
|
|
4747
5374
|
*/
|
|
4748
5375
|
async function buildDockerfile(dockerfile, options) {
|
|
4749
5376
|
const { harness, signal, engine } = options;
|
|
4750
|
-
const { tag } = dockerfileTag(dockerfile, harness
|
|
5377
|
+
const { tag } = dockerfileTag(dockerfile, harness);
|
|
4751
5378
|
const previous = (await imageInfo(tag, engine))?.id;
|
|
4752
5379
|
if (previous && !options.force) return tag;
|
|
4753
5380
|
const build = await docker([
|
|
@@ -4755,6 +5382,7 @@ async function buildDockerfile(dockerfile, options) {
|
|
|
4755
5382
|
"--progress",
|
|
4756
5383
|
"plain",
|
|
4757
5384
|
...BUILT_BY,
|
|
5385
|
+
...keyLabel(options.key ?? tag),
|
|
4758
5386
|
...options.pull ? ["--pull"] : [],
|
|
4759
5387
|
"--file",
|
|
4760
5388
|
dockerfile,
|
|
@@ -4786,301 +5414,478 @@ async function buildDockerfile(dockerfile, options) {
|
|
|
4786
5414
|
* and logs when it answers `initialize` (see its header). It runs in any sandbox with `node`.
|
|
4787
5415
|
*/
|
|
4788
5416
|
const MCP_TIMER = fileURLToPath(ownFileURL("bin/mcp-timer.cjs"));
|
|
4789
|
-
// ../sandbox-docker/src/
|
|
5417
|
+
// ../sandbox-docker/src/registry.ts
|
|
5418
|
+
/**
|
|
5419
|
+
* What's wrong with a registry prefix, or null: a registry host (with an optional port) and an
|
|
5420
|
+
* optional path, as `docker push` names one, without a scheme, tag or digest.
|
|
5421
|
+
*/
|
|
5422
|
+
function registryProblem(registry) {
|
|
5423
|
+
if (/^[a-z0-9.-]+(:\d+)?(\/[a-z0-9]+([._-]+[a-z0-9]+)*)*\/?$/.test(registry)) return null;
|
|
5424
|
+
return `--registry is a registry and an optional path, such as ghcr.io/acme/reeval or localhost:5000/reeval, in lowercase without a scheme, tag or digest (got ${JSON.stringify(registry)})`;
|
|
5425
|
+
}
|
|
5426
|
+
/**
|
|
5427
|
+
* Where a layer goes in `registry`: its repository under the prefix, with its tag, plus its content
|
|
5428
|
+
* key's hash where the tag alone doesn't pin what's in it (reeval's own image and a `from` image),
|
|
5429
|
+
* and the platform, so one machine's push is another's pull only when they'd have built the same
|
|
5430
|
+
* thing for the same architecture.
|
|
5431
|
+
*/
|
|
5432
|
+
function registryRef(registry, layer, platform = PLATFORM) {
|
|
5433
|
+
const at = layer.ref.lastIndexOf(":");
|
|
5434
|
+
const repository = layer.ref.slice(0, at);
|
|
5435
|
+
const tag = layer.ref.slice(at + 1);
|
|
5436
|
+
const pinned = layer.key === layer.ref ? tag : `${tag}-${createHash("sha256").update(layer.key).digest("hex").slice(0, 12)}`;
|
|
5437
|
+
return `${registry.replace(/\/+$/, "")}/${repository}:${pinned}-${platform.replaceAll("/", "-")}`;
|
|
5438
|
+
}
|
|
5439
|
+
const firstLine = (stderr) => stderr.trim().split("\n").filter(Boolean).at(-1)?.replace(/^Error(?: response from daemon)?: /, "") ?? "";
|
|
5440
|
+
/**
|
|
5441
|
+
* The platform the engine builds and pulls for, as its server says it (a remote `DOCKER_HOST`, or
|
|
5442
|
+
* x64 Node under Rosetta, can differ from this process's), or {@link PLATFORM} when it doesn't say.
|
|
5443
|
+
*/
|
|
5444
|
+
async function enginePlatform(engine = "docker") {
|
|
5445
|
+
const r = await docker(engine === "podman" ? [
|
|
5446
|
+
"info",
|
|
5447
|
+
"--format",
|
|
5448
|
+
"{{.Host.OS}}/{{.Host.Arch}}"
|
|
5449
|
+
] : [
|
|
5450
|
+
"version",
|
|
5451
|
+
"--format",
|
|
5452
|
+
"{{.Server.Os}}/{{.Server.Arch}}"
|
|
5453
|
+
], { engine }).catch(() => null);
|
|
5454
|
+
const said = r?.exitCode === 0 ? r.stdout.toString("utf8").trim() : "";
|
|
5455
|
+
return /^[a-z0-9]+\/[a-z0-9]+$/.test(said) ? said : PLATFORM;
|
|
5456
|
+
}
|
|
5457
|
+
/**
|
|
5458
|
+
* Pulls `layer` from `registry` and tags it as its local ref, once it's checked: its
|
|
5459
|
+
* {@link LABEL.key} must be the layer's key and its platform the engine's ({@link enginePlatform}). `pulled: false` with
|
|
5460
|
+
* the reason when the registry doesn't have it, can't be reached or has another image under the
|
|
5461
|
+
* ref: the caller builds it instead. The registry is otherwise trusted: anyone who can push to it
|
|
5462
|
+
* chooses what a matching tag holds.
|
|
5463
|
+
*/
|
|
5464
|
+
async function pullLayer(registry, layer, options = {}) {
|
|
5465
|
+
const { engine, signal } = options;
|
|
5466
|
+
const platform = await enginePlatform(engine);
|
|
5467
|
+
const remote = registryRef(registry, layer, platform);
|
|
5468
|
+
const pull = await docker([
|
|
5469
|
+
"pull",
|
|
5470
|
+
"--quiet",
|
|
5471
|
+
remote
|
|
5472
|
+
], {
|
|
5473
|
+
engine,
|
|
5474
|
+
signal
|
|
5475
|
+
}).catch((error) => ({
|
|
5476
|
+
exitCode: 1,
|
|
5477
|
+
stderr: error.message
|
|
5478
|
+
}));
|
|
5479
|
+
if (pull.exitCode !== 0) return {
|
|
5480
|
+
pulled: false,
|
|
5481
|
+
remote,
|
|
5482
|
+
reason: firstLine(pull.stderr) || `exit ${pull.exitCode}`
|
|
5483
|
+
};
|
|
5484
|
+
try {
|
|
5485
|
+
const info = await imageInfo(remote, engine).catch(() => null);
|
|
5486
|
+
const key = info?.labels[LABEL.key];
|
|
5487
|
+
if (key !== layer.key) return {
|
|
5488
|
+
pulled: false,
|
|
5489
|
+
remote,
|
|
5490
|
+
reason: key ? `its ${LABEL.key} label is ${key}, not ${layer.key}` : `it has no ${LABEL.key} label`
|
|
5491
|
+
};
|
|
5492
|
+
if (info?.platform !== platform) return {
|
|
5493
|
+
pulled: false,
|
|
5494
|
+
remote,
|
|
5495
|
+
reason: `it's for ${info?.platform ?? "an unknown platform"}, not ${platform}`
|
|
5496
|
+
};
|
|
5497
|
+
const tag = await docker([
|
|
5498
|
+
"tag",
|
|
5499
|
+
remote,
|
|
5500
|
+
layer.ref
|
|
5501
|
+
], {
|
|
5502
|
+
engine,
|
|
5503
|
+
signal
|
|
5504
|
+
});
|
|
5505
|
+
if (tag.exitCode !== 0) return {
|
|
5506
|
+
pulled: false,
|
|
5507
|
+
remote,
|
|
5508
|
+
reason: firstLine(tag.stderr) || `exit ${tag.exitCode}`
|
|
5509
|
+
};
|
|
5510
|
+
return {
|
|
5511
|
+
pulled: true,
|
|
5512
|
+
remote
|
|
5513
|
+
};
|
|
5514
|
+
} finally {
|
|
5515
|
+
await docker([
|
|
5516
|
+
"image",
|
|
5517
|
+
"rm",
|
|
5518
|
+
remote
|
|
5519
|
+
], { engine }).catch(() => {});
|
|
5520
|
+
}
|
|
5521
|
+
}
|
|
5522
|
+
/**
|
|
5523
|
+
* Pushes `layer` to `registry` under {@link registryRef} for the platform the image says it's for
|
|
5524
|
+
* (or the engine's), and returns that ref.
|
|
5525
|
+
*/
|
|
5526
|
+
async function pushLayer(registry, layer, options = {}) {
|
|
5527
|
+
const { engine, signal } = options;
|
|
5528
|
+
const { bin } = engineSpec(engine);
|
|
5529
|
+
const own = (await imageInfo(layer.ref, engine).catch(() => null))?.platform;
|
|
5530
|
+
const remote = registryRef(registry, layer, own ?? await enginePlatform(engine));
|
|
5531
|
+
const tag = await docker([
|
|
5532
|
+
"tag",
|
|
5533
|
+
layer.ref,
|
|
5534
|
+
remote
|
|
5535
|
+
], {
|
|
5536
|
+
engine,
|
|
5537
|
+
signal
|
|
5538
|
+
});
|
|
5539
|
+
if (tag.exitCode !== 0) throw new Error(`${bin} tag ${layer.ref} ${remote} failed: ${firstLine(tag.stderr)}`);
|
|
5540
|
+
try {
|
|
5541
|
+
const push = await docker(["push", remote], {
|
|
5542
|
+
engine,
|
|
5543
|
+
signal
|
|
5544
|
+
});
|
|
5545
|
+
if (push.exitCode !== 0) throw new Error(`${bin} push ${remote} failed: ${firstLine(push.stderr)}`);
|
|
5546
|
+
} finally {
|
|
5547
|
+
await docker([
|
|
5548
|
+
"image",
|
|
5549
|
+
"rm",
|
|
5550
|
+
remote
|
|
5551
|
+
], { engine }).catch(() => {});
|
|
5552
|
+
}
|
|
5553
|
+
return remote;
|
|
5554
|
+
}
|
|
5555
|
+
// ../sandbox-docker/src/shells.ts
|
|
4790
5556
|
const SYSTEM_PATH = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin";
|
|
4791
|
-
const EXEC_MARKER = "REEVAL_EXEC_ID";
|
|
4792
5557
|
const EXEC_UMASK = "umask 022";
|
|
4793
|
-
|
|
4794
|
-
const SSH_FAILED = 255;
|
|
5558
|
+
const EXEC_MARKER = "REEVAL_EXEC_ID";
|
|
4795
5559
|
/** `NAME=value\0` for each variable, as the remote reader takes them on stdin. */
|
|
4796
5560
|
const envStream = (env) => Object.entries(env).map(([k, v]) => `${k}=${v}\0`).join("");
|
|
4797
5561
|
/**
|
|
4798
|
-
* Runs `$2` with bash in `$1` as the sandbox user, after exporting the variables stdin carries
|
|
4799
|
-
* The command itself gets no stdin, as a `docker exec` without
|
|
5562
|
+
* Runs `$2` with bash in `$1` as the sandbox user, after exporting the variables stdin carries,
|
|
5563
|
+
* in a process group it leads. The command itself gets no stdin, as a `docker exec` without
|
|
5564
|
+
* `--interactive` would.
|
|
4800
5565
|
*/
|
|
4801
|
-
const READER = `${EXEC_UMASK}; while IFS= read -r -d "" kv; do export "$kv"; done; cd -- "$1" || exit 1; exec bash -c "$2" </dev/null`;
|
|
5566
|
+
const READER = `${EXEC_UMASK}; while IFS= read -r -d "" kv; do export "$kv"; done; cd -- "$1" || exit 1; exec /usr/bin/perl -e 'setpgrp(0, 0); exec @ARGV' bash -c "$2" </dev/null`;
|
|
4802
5567
|
/**
|
|
4803
|
-
*
|
|
4804
|
-
*
|
|
4805
|
-
*
|
|
4806
|
-
*
|
|
5568
|
+
* The Linux profile: the login user has passwordless `sudo`, the agent's commands run as
|
|
5569
|
+
* {@link SANDBOX_USER} with only `user`'s variables, and reeval's own run as root in
|
|
5570
|
+
* {@link SANDBOX_STATE}. Each command carries a marker in its environment, which `kill` finds in
|
|
5571
|
+
* `/proc`. `remote` is the host argv that runs one command line as the login user (`ssh`).
|
|
4807
5572
|
*/
|
|
4808
|
-
|
|
4809
|
-
const
|
|
4810
|
-
const
|
|
4811
|
-
|
|
4812
|
-
|
|
4813
|
-
|
|
4814
|
-
|
|
4815
|
-
|
|
4816
|
-
|
|
4817
|
-
|
|
4818
|
-
|
|
4819
|
-
|
|
4820
|
-
|
|
4821
|
-
|
|
4822
|
-
const
|
|
4823
|
-
|
|
4824
|
-
|
|
4825
|
-
|
|
4826
|
-
|
|
4827
|
-
|
|
4828
|
-
|
|
4829
|
-
|
|
4830
|
-
|
|
4831
|
-
|
|
4832
|
-
|
|
4833
|
-
|
|
4834
|
-
|
|
4835
|
-
|
|
4836
|
-
|
|
4837
|
-
|
|
4838
|
-
|
|
4839
|
-
|
|
4840
|
-
|
|
4841
|
-
|
|
4842
|
-
|
|
4843
|
-
|
|
4844
|
-
}
|
|
4845
|
-
};
|
|
4846
|
-
const asUser = (cwd, command) => `sudo -n -H -u ${SANDBOX_USER} -- env -i ${Object.entries(baseEnv).map(([k, v]) => shellQuote(`${k}=${v}`)).join(" ")} bash -c ${shellQuote(READER)} bash ${shellQuote(cwd)} ${shellQuote(command)}`;
|
|
4847
|
-
const asRoot = (command, marker) => `sudo -n -- env -i PATH=${SYSTEM_PATH} HOME=/root${marker ? ` ${EXEC_MARKER}=${marker}` : ""} /bin/sh -c ${shellQuote(`cd ${SANDBOX_STATE} || exit 1; ${EXEC_UMASK}; ${command}`)}`;
|
|
4848
|
-
const closeConnection = async () => {
|
|
4849
|
-
if (!target.controlPath || process.platform === "win32") return;
|
|
4850
|
-
const [bin = "ssh", ...args] = sshArgv(target, "");
|
|
4851
|
-
await run(bin, [
|
|
4852
|
-
"-O",
|
|
4853
|
-
"exit",
|
|
4854
|
-
...args.slice(0, -1)
|
|
4855
|
-
]).catch(() => {});
|
|
4856
|
-
};
|
|
4857
|
-
let gateway;
|
|
4858
|
-
let destroyed;
|
|
4859
|
-
const destroy = () => {
|
|
4860
|
-
destroyed ??= (async () => {
|
|
4861
|
-
gateway?.close();
|
|
4862
|
-
await closeConnection();
|
|
4863
|
-
await options.onDestroy?.();
|
|
4864
|
-
})();
|
|
4865
|
-
return destroyed;
|
|
4866
|
-
};
|
|
4867
|
-
const fail = async (error) => {
|
|
4868
|
-
await destroy().catch(() => {});
|
|
4869
|
-
throw signal?.aborted ? signal.reason : error;
|
|
5573
|
+
function linuxShell(o) {
|
|
5574
|
+
const sandboxUser = o.layout?.user ?? "reeval";
|
|
5575
|
+
const stateDir = o.layout?.state ?? "/var/lib/reeval";
|
|
5576
|
+
const seenHome = o.user.HOME;
|
|
5577
|
+
const bind = o.layout && seenHome && o.layout.home !== seenHome ? o.layout.home : void 0;
|
|
5578
|
+
const marker = (exec) => `${o.id}-${exec}`;
|
|
5579
|
+
const asSandboxUser = (command) => bind ? `sudo -n -- unshare --mount --propagation private /bin/sh -c ${shellQuote(`mount --bind ${shellQuote(bind)} ${shellQuote(seenHome ?? "")} && exec setpriv --reuid=${sandboxUser} --regid=${sandboxUser} --init-groups -- ${command}`)}` : `sudo -n -H -u ${sandboxUser} -- ${command}`;
|
|
5580
|
+
const asUser = (cwd, command) => asSandboxUser(`env -i ${Object.entries(o.user).map(([k, v]) => shellQuote(`${k}=${v}`)).join(" ")} bash -c ${shellQuote(READER)} bash ${shellQuote(cwd)} ${shellQuote(command)}`);
|
|
5581
|
+
const asRoot = (command, mark) => `sudo -n -- env -i PATH=${SYSTEM_PATH} HOME=/root${mark ? ` ${EXEC_MARKER}=${mark}` : ""} /bin/sh -c ${shellQuote(`cd ${stateDir} || exit 1; ${EXEC_UMASK}; ${command}`)}`;
|
|
5582
|
+
/**
|
|
5583
|
+
* Killing the host's program leaves the command running on the machine, so kill what has its
|
|
5584
|
+
* marker, and the process group of each: a process that cleared its environment (`env -i`)
|
|
5585
|
+
* keeps the group of the command that started it.
|
|
5586
|
+
*/
|
|
5587
|
+
const killExec = (mark) => asRoot(`gs=; for e in /proc/[0-9]*/environ; do grep -qsxzF ${shellQuote(`${EXEC_MARKER}=${mark}`)} "$e" || continue; d=\${e%/environ}; g=$(sed 's/.*) //' "$d/stat" 2>/dev/null | cut -d' ' -f3); kill -9 "\${d#/proc/}" 2>/dev/null; [ "\${g:-0}" -gt 1 ] && gs="$gs $g"; done; for g in $gs; do kill -9 "-$g" 2>/dev/null; done; true`);
|
|
5588
|
+
return {
|
|
5589
|
+
run: (argv, r) => o.run(argv, {
|
|
5590
|
+
...r,
|
|
5591
|
+
signal: r.signal ?? o.signal
|
|
5592
|
+
}),
|
|
5593
|
+
user: ({ command, cwd, env, exec }) => ({
|
|
5594
|
+
argv: o.remote(asUser(cwd, command)),
|
|
5595
|
+
input: envStream({
|
|
5596
|
+
...env,
|
|
5597
|
+
[EXEC_MARKER]: marker(exec)
|
|
5598
|
+
})
|
|
5599
|
+
}),
|
|
5600
|
+
privileged: ({ command, exec }) => ({
|
|
5601
|
+
argv: o.remote(asRoot(command, marker(exec))),
|
|
5602
|
+
input: ""
|
|
5603
|
+
}),
|
|
5604
|
+
kill: (exec) => ({
|
|
5605
|
+
argv: o.remote(killExec(marker(exec))),
|
|
5606
|
+
input: ""
|
|
5607
|
+
}),
|
|
5608
|
+
direct: (argv) => o.remote(asSandboxUser(argv.map(shellQuote).join(" ")))
|
|
4870
5609
|
};
|
|
4871
|
-
|
|
4872
|
-
|
|
4873
|
-
|
|
4874
|
-
|
|
4875
|
-
|
|
4876
|
-
|
|
4877
|
-
|
|
4878
|
-
const
|
|
4879
|
-
|
|
4880
|
-
|
|
4881
|
-
|
|
4882
|
-
|
|
4883
|
-
|
|
4884
|
-
|
|
4885
|
-
|
|
4886
|
-
|
|
4887
|
-
|
|
4888
|
-
|
|
4889
|
-
|
|
4890
|
-
|
|
4891
|
-
|
|
4892
|
-
|
|
4893
|
-
|
|
4894
|
-
|
|
4895
|
-
|
|
4896
|
-
|
|
4897
|
-
|
|
4898
|
-
|
|
4899
|
-
|
|
4900
|
-
|
|
4901
|
-
|
|
4902
|
-
|
|
4903
|
-
|
|
4904
|
-
|
|
4905
|
-
|
|
4906
|
-
|
|
4907
|
-
|
|
4908
|
-
|
|
4909
|
-
|
|
4910
|
-
|
|
4911
|
-
|
|
4912
|
-
|
|
4913
|
-
|
|
4914
|
-
|
|
5610
|
+
}
|
|
5611
|
+
const NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
5612
|
+
/**
|
|
5613
|
+
* A command as one script on stdin, so variables (and what a secret holds) never reach a
|
|
5614
|
+
* command line on the host or in the machine. The shell records its pid for {@link killTree}.
|
|
5615
|
+
*/
|
|
5616
|
+
function execScript(o) {
|
|
5617
|
+
const exports = Object.entries(o.env).filter(([k]) => NAME.test(k)).map(([k, v]) => `export ${k}=${shellQuote(v)}`);
|
|
5618
|
+
return [[
|
|
5619
|
+
`echo $$ > ${shellQuote(o.pidFile)}`,
|
|
5620
|
+
`export PATH=${shellQuote(o.path)}:"$PATH"`,
|
|
5621
|
+
...exports,
|
|
5622
|
+
"umask 022",
|
|
5623
|
+
`cd ${shellQuote(o.cwd)} || exit 1`
|
|
5624
|
+
].join("; "), o.command].join("\n");
|
|
5625
|
+
}
|
|
5626
|
+
/**
|
|
5627
|
+
* Reads the script {@link execScript} wrote from stdin and runs it, with stdin then empty, in a
|
|
5628
|
+
* process group its shell leads, so the pid the script records is also the group's.
|
|
5629
|
+
*/
|
|
5630
|
+
const RUN_SCRIPT = [
|
|
5631
|
+
"/usr/bin/perl",
|
|
5632
|
+
"-e",
|
|
5633
|
+
"setpgrp(0, 0); exec @ARGV",
|
|
5634
|
+
"/bin/bash",
|
|
5635
|
+
"-c",
|
|
5636
|
+
"s=$(cat); eval \"$s\" </dev/null"
|
|
5637
|
+
];
|
|
5638
|
+
/**
|
|
5639
|
+
* Kills the command whose shell wrote `pidFile` and everything it started: macOS has no `/proc`
|
|
5640
|
+
* to find them by a marker, so it stops and kills the shell's process group, which keeps a
|
|
5641
|
+
* process its parent left behind (a double fork's), and walks the tree from the shell for one
|
|
5642
|
+
* that moved to a group of its own (a job-control shell's job). Anything but a pid above 1 in the
|
|
5643
|
+
* file kills nothing: `kill -9 -1` is every process the user can signal.
|
|
5644
|
+
*/
|
|
5645
|
+
const killTree = (pidFile) => `f=${shellQuote(pidFile)}; [ -f "$f" ] || exit 0; p=$(cat "$f")
|
|
5646
|
+
case $p in ''|*[!0-9]*) rm -f "$f"; exit 0 ;; esac; [ "$p" -gt 1 ] || { rm -f "$f"; exit 0; }
|
|
5647
|
+
tree() { kill -STOP "$1" 2>/dev/null; for c in $(pgrep -P "$1"); do tree "$c"; done; kill -9 "$1" 2>/dev/null; }
|
|
5648
|
+
kill -STOP "-$p" 2>/dev/null; tree "$p"; kill -9 "-$p" 2>/dev/null; rm -f "$f"; true`;
|
|
5649
|
+
/**
|
|
5650
|
+
* The darwin profile: macOS has no `useradd`, so every command, reeval's own included, runs as
|
|
5651
|
+
* the image's user, reeval's in `stateDir`. Each gets its variables in a script on stdin
|
|
5652
|
+
* ({@link execScript}) and writes its pid there, which `kill` walks the process tree from.
|
|
5653
|
+
* `guest` is the host argv that runs an argv on the machine with its stdin piped.
|
|
5654
|
+
*/
|
|
5655
|
+
function darwinShell(o) {
|
|
5656
|
+
const pidFile = (exec) => posix.join(o.stateDir, `exec-${exec}.pid`);
|
|
5657
|
+
const script = (command, cwd, env, exec) => ({
|
|
5658
|
+
argv: o.guest(RUN_SCRIPT),
|
|
5659
|
+
input: execScript({
|
|
5660
|
+
command,
|
|
5661
|
+
cwd,
|
|
5662
|
+
env,
|
|
5663
|
+
pidFile: pidFile(exec),
|
|
5664
|
+
path: o.path
|
|
5665
|
+
})
|
|
4915
5666
|
});
|
|
5667
|
+
return {
|
|
5668
|
+
run: o.run,
|
|
5669
|
+
user: ({ command, cwd, env, exec }) => script(command, cwd, env, exec),
|
|
5670
|
+
privileged: ({ command, exec }) => script(command, o.stateDir, {}, exec),
|
|
5671
|
+
kill: (exec) => ({
|
|
5672
|
+
argv: o.guest([
|
|
5673
|
+
"/bin/sh",
|
|
5674
|
+
"-c",
|
|
5675
|
+
killTree(pidFile(exec))
|
|
5676
|
+
]),
|
|
5677
|
+
input: ""
|
|
5678
|
+
}),
|
|
5679
|
+
direct: (argv) => o.guest(argv)
|
|
5680
|
+
};
|
|
5681
|
+
}
|
|
5682
|
+
// ../sandbox-docker/src/transport-session.ts
|
|
5683
|
+
/** How long killing an aborted command may take. */
|
|
5684
|
+
const KILL_TIMEOUT_MS = 3e4;
|
|
5685
|
+
const text = (r) => ({
|
|
5686
|
+
exitCode: r.exitCode,
|
|
5687
|
+
stdout: r.stdout.toString("utf8"),
|
|
5688
|
+
stderr: r.stderr
|
|
5689
|
+
});
|
|
5690
|
+
/**
|
|
5691
|
+
* A harness sandbox session on a machine reeval reaches through host programs (`ssh`, `tart
|
|
5692
|
+
* exec`): everything but how a command gets there, which {@link SessionShell} says.
|
|
5693
|
+
*/
|
|
5694
|
+
function transportSession(o) {
|
|
5695
|
+
const { shell, gateway, description } = o;
|
|
4916
5696
|
let execs = 0;
|
|
4917
|
-
const
|
|
4918
|
-
const
|
|
4919
|
-
|
|
4920
|
-
|
|
4921
|
-
|
|
4922
|
-
|
|
4923
|
-
|
|
4924
|
-
|
|
4925
|
-
|
|
5697
|
+
const at = (path) => path ? posix.resolve(o.defaultWorkingDirectory, path) : o.defaultWorkingDirectory;
|
|
5698
|
+
const runHost = (c, signal) => shell.run(c.argv, {
|
|
5699
|
+
input: c.input,
|
|
5700
|
+
signal
|
|
5701
|
+
});
|
|
5702
|
+
const kill = (exec) => runHost(shell.kill(exec), AbortSignal.timeout(KILL_TIMEOUT_MS)).then(() => {}, () => {});
|
|
5703
|
+
const execute = async (exec, c, signal) => {
|
|
5704
|
+
let killed;
|
|
5705
|
+
const onAbort = () => {
|
|
5706
|
+
killed = kill(exec);
|
|
4926
5707
|
};
|
|
5708
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
4927
5709
|
try {
|
|
4928
|
-
|
|
4929
|
-
return {
|
|
4930
|
-
exitCode: r.exitCode,
|
|
4931
|
-
stdout: r.stdout.toString("utf8"),
|
|
4932
|
-
stderr: r.stderr
|
|
4933
|
-
};
|
|
5710
|
+
return text(await runHost(c, signal));
|
|
4934
5711
|
} catch (error) {
|
|
4935
|
-
if (
|
|
5712
|
+
if (signal?.aborted) {
|
|
5713
|
+
await killed;
|
|
5714
|
+
await kill(exec);
|
|
5715
|
+
}
|
|
4936
5716
|
throw error;
|
|
5717
|
+
} finally {
|
|
5718
|
+
signal?.removeEventListener("abort", onAbort);
|
|
4937
5719
|
}
|
|
4938
5720
|
};
|
|
4939
|
-
|
|
4940
|
-
|
|
4941
|
-
|
|
4942
|
-
|
|
4943
|
-
|
|
4944
|
-
|
|
4945
|
-
|
|
4946
|
-
|
|
4947
|
-
|
|
4948
|
-
|
|
4949
|
-
|
|
4950
|
-
|
|
4951
|
-
}
|
|
5721
|
+
/** Starts a host program with its output streamed; its kill ends command `exec` in the machine too. */
|
|
5722
|
+
const streamed = (exec, c) => {
|
|
5723
|
+
const [bin = "", ...args] = c.argv;
|
|
5724
|
+
const startedAt = Date.now();
|
|
5725
|
+
const child = spawn(bin, args, {
|
|
5726
|
+
stdio: [
|
|
5727
|
+
"pipe",
|
|
5728
|
+
"pipe",
|
|
5729
|
+
"pipe"
|
|
5730
|
+
],
|
|
5731
|
+
detached: true
|
|
5732
|
+
});
|
|
5733
|
+
child.stdin.on("error", () => {});
|
|
5734
|
+
child.stdin.end(c.input);
|
|
5735
|
+
const exited = new Promise((resolve) => {
|
|
5736
|
+
child.once("error", () => resolve({ exitCode: 127 }));
|
|
5737
|
+
child.once("close", (code) => {
|
|
5738
|
+
traceDocker(args, startedAt, {
|
|
5739
|
+
exitCode: code,
|
|
5740
|
+
stdout: "<streamed>"
|
|
5741
|
+
}, bin);
|
|
5742
|
+
resolve({ exitCode: code ?? 1 });
|
|
5743
|
+
});
|
|
5744
|
+
});
|
|
5745
|
+
return {
|
|
5746
|
+
pid: child.pid,
|
|
5747
|
+
stdout: Readable.toWeb(child.stdout),
|
|
5748
|
+
stderr: Readable.toWeb(child.stderr),
|
|
5749
|
+
wait: () => exited,
|
|
5750
|
+
kill: async () => {
|
|
5751
|
+
child.kill("SIGKILL");
|
|
5752
|
+
await kill(exec);
|
|
5753
|
+
}
|
|
5754
|
+
};
|
|
4952
5755
|
};
|
|
4953
|
-
const
|
|
4954
|
-
|
|
4955
|
-
|
|
4956
|
-
|
|
5756
|
+
const readBinaryFile = async (r) => {
|
|
5757
|
+
const read = await shell.run(shell.direct([
|
|
5758
|
+
"/bin/cat",
|
|
5759
|
+
"--",
|
|
5760
|
+
at(r.path)
|
|
5761
|
+
]), { signal: r.abortSignal }).catch(() => null);
|
|
5762
|
+
return read?.exitCode === 0 ? new Uint8Array(read.stdout) : null;
|
|
4957
5763
|
};
|
|
4958
|
-
const writeBinaryFile = async (
|
|
4959
|
-
const
|
|
4960
|
-
const
|
|
4961
|
-
|
|
4962
|
-
|
|
5764
|
+
const writeBinaryFile = async (w) => {
|
|
5765
|
+
const target = at(w.path);
|
|
5766
|
+
const r = await shell.run(shell.direct([
|
|
5767
|
+
"/bin/sh",
|
|
5768
|
+
"-c",
|
|
5769
|
+
"umask 022 && mkdir -p \"$(dirname \"$1\")\" && cat > \"$1\"",
|
|
5770
|
+
"sh",
|
|
5771
|
+
target
|
|
5772
|
+
]), {
|
|
5773
|
+
input: w.content,
|
|
5774
|
+
signal: w.abortSignal
|
|
5775
|
+
});
|
|
5776
|
+
if (r.exitCode !== 0) throw new Error(`Couldn't write ${target} in ${o.name ?? description}: ${r.stderr.trim()}`);
|
|
4963
5777
|
};
|
|
4964
|
-
const paths = pathOperations(async (script, path, abortSignal) =>
|
|
4965
|
-
|
|
4966
|
-
|
|
4967
|
-
|
|
4968
|
-
|
|
4969
|
-
|
|
4970
|
-
|
|
4971
|
-
});
|
|
5778
|
+
const paths = pathOperations(async (script, path, abortSignal) => text(await shell.run(shell.direct([
|
|
5779
|
+
"/bin/sh",
|
|
5780
|
+
"-c",
|
|
5781
|
+
script,
|
|
5782
|
+
"sh",
|
|
5783
|
+
path
|
|
5784
|
+
]), { signal: abortSignal })), o.defaultWorkingDirectory);
|
|
4972
5785
|
const brokering = gateway ? {
|
|
4973
5786
|
async setNetworkPolicy(policy) {
|
|
4974
|
-
gateway
|
|
5787
|
+
gateway.setPolicy(policy);
|
|
4975
5788
|
},
|
|
4976
5789
|
async addRequestTransformations(rules) {
|
|
4977
|
-
gateway
|
|
5790
|
+
gateway.addTransformations(rules);
|
|
4978
5791
|
},
|
|
4979
5792
|
async setRequestTransformations(rules) {
|
|
4980
|
-
gateway
|
|
4981
|
-
}
|
|
4982
|
-
} : {};
|
|
4983
|
-
const substituting = gateway ? {
|
|
5793
|
+
gateway.setTransformations(rules);
|
|
5794
|
+
},
|
|
4984
5795
|
async setSubstitutions(subs) {
|
|
4985
|
-
gateway
|
|
5796
|
+
gateway.setSubstitutions(subs);
|
|
4986
5797
|
},
|
|
4987
5798
|
traffic: () => gateway.traffic()
|
|
4988
5799
|
} : {};
|
|
5800
|
+
const run = (r) => {
|
|
5801
|
+
const exec = ++execs;
|
|
5802
|
+
return execute(exec, shell.user({
|
|
5803
|
+
command: r.command,
|
|
5804
|
+
cwd: at(r.workingDirectory),
|
|
5805
|
+
env: o.env(r.env),
|
|
5806
|
+
exec
|
|
5807
|
+
}), r.abortSignal);
|
|
5808
|
+
};
|
|
4989
5809
|
const session = {
|
|
4990
|
-
id:
|
|
4991
|
-
description
|
|
4992
|
-
defaultWorkingDirectory:
|
|
5810
|
+
id: o.id,
|
|
5811
|
+
description,
|
|
5812
|
+
defaultWorkingDirectory: o.defaultWorkingDirectory,
|
|
4993
5813
|
ports: [BRIDGE_PORT],
|
|
4994
5814
|
get egress() {
|
|
4995
|
-
if (egress?.active && gateway?.stopped) return {
|
|
5815
|
+
if (o.egress?.active && gateway?.stopped) return {
|
|
4996
5816
|
active: false,
|
|
4997
5817
|
reason: gateway.stopped
|
|
4998
5818
|
};
|
|
4999
|
-
return egress;
|
|
5819
|
+
return o.egress;
|
|
5000
5820
|
},
|
|
5001
5821
|
...brokering,
|
|
5002
|
-
...substituting,
|
|
5003
5822
|
oomKills: async () => null,
|
|
5004
|
-
run
|
|
5005
|
-
runPrivileged
|
|
5006
|
-
|
|
5007
|
-
|
|
5008
|
-
|
|
5009
|
-
|
|
5010
|
-
|
|
5011
|
-
|
|
5012
|
-
|
|
5013
|
-
|
|
5014
|
-
const
|
|
5015
|
-
const
|
|
5016
|
-
|
|
5017
|
-
|
|
5018
|
-
|
|
5019
|
-
|
|
5020
|
-
],
|
|
5021
|
-
detached: true
|
|
5022
|
-
});
|
|
5023
|
-
child.stdin.on("error", () => {});
|
|
5024
|
-
child.stdin.end(envStream(env));
|
|
5025
|
-
const exited = new Promise((resolve) => child.on("close", (code) => {
|
|
5026
|
-
traceDocker(args, startedAt, {
|
|
5027
|
-
exitCode: code,
|
|
5028
|
-
stdout: "<streamed>"
|
|
5029
|
-
}, "ssh");
|
|
5030
|
-
resolve({ exitCode: code ?? 1 });
|
|
5823
|
+
run,
|
|
5824
|
+
runPrivileged: (r) => {
|
|
5825
|
+
const exec = ++execs;
|
|
5826
|
+
return execute(exec, shell.privileged({
|
|
5827
|
+
command: r.command,
|
|
5828
|
+
exec
|
|
5829
|
+
}), r.abortSignal);
|
|
5830
|
+
},
|
|
5831
|
+
spawn: (async (s) => {
|
|
5832
|
+
if (s.stdin) throw new Error(`A process in ${description} has no writable stdin`);
|
|
5833
|
+
const exec = ++execs;
|
|
5834
|
+
const p = streamed(exec, shell.user({
|
|
5835
|
+
command: s.command,
|
|
5836
|
+
cwd: at(s.workingDirectory),
|
|
5837
|
+
env: o.env(s.env),
|
|
5838
|
+
exec
|
|
5031
5839
|
}));
|
|
5032
|
-
|
|
5033
|
-
|
|
5034
|
-
await killExec(marker);
|
|
5035
|
-
};
|
|
5036
|
-
o.abortSignal?.addEventListener("abort", () => void kill(), { once: true });
|
|
5037
|
-
return {
|
|
5038
|
-
pid: child.pid,
|
|
5039
|
-
stdout: Readable.toWeb(child.stdout),
|
|
5040
|
-
stderr: Readable.toWeb(child.stderr),
|
|
5041
|
-
wait: () => exited,
|
|
5042
|
-
kill
|
|
5043
|
-
};
|
|
5840
|
+
s.abortSignal?.addEventListener("abort", () => void p.kill(), { once: true });
|
|
5841
|
+
return p;
|
|
5044
5842
|
}),
|
|
5843
|
+
spawnPrivileged: async (s) => {
|
|
5844
|
+
const exec = ++execs;
|
|
5845
|
+
return streamed(exec, shell.privileged({
|
|
5846
|
+
command: s.command,
|
|
5847
|
+
exec
|
|
5848
|
+
}));
|
|
5849
|
+
},
|
|
5045
5850
|
readBinaryFile,
|
|
5046
|
-
async readFile(
|
|
5047
|
-
const bytes = await readBinaryFile(
|
|
5851
|
+
async readFile(r) {
|
|
5852
|
+
const bytes = await readBinaryFile(r);
|
|
5048
5853
|
return bytes === null ? null : Readable.toWeb(Readable.from([bytes]));
|
|
5049
5854
|
},
|
|
5050
|
-
async readTextFile(
|
|
5051
|
-
const bytes = await readBinaryFile(
|
|
5855
|
+
async readTextFile(r) {
|
|
5856
|
+
const bytes = await readBinaryFile(r);
|
|
5052
5857
|
if (bytes === null) return null;
|
|
5053
|
-
const
|
|
5054
|
-
if (
|
|
5055
|
-
return
|
|
5858
|
+
const content = Buffer.from(bytes).toString("utf8");
|
|
5859
|
+
if (r.startLine === void 0 && r.endLine === void 0) return content;
|
|
5860
|
+
return content.split("\n").slice((r.startLine ?? 1) - 1, r.endLine).join("\n");
|
|
5056
5861
|
},
|
|
5057
5862
|
...paths,
|
|
5058
5863
|
writeBinaryFile,
|
|
5059
|
-
writeTextFile: (
|
|
5060
|
-
...
|
|
5061
|
-
content: Buffer.from(
|
|
5864
|
+
writeTextFile: (w) => writeBinaryFile({
|
|
5865
|
+
...w,
|
|
5866
|
+
content: Buffer.from(w.content, "utf8")
|
|
5062
5867
|
}),
|
|
5063
|
-
async writeFile(
|
|
5868
|
+
async writeFile(w) {
|
|
5064
5869
|
const chunks = [];
|
|
5065
|
-
for await (const chunk of
|
|
5870
|
+
for await (const chunk of w.content) chunks.push(chunk);
|
|
5066
5871
|
await writeBinaryFile({
|
|
5067
|
-
...
|
|
5872
|
+
...w,
|
|
5068
5873
|
content: Buffer.concat(chunks)
|
|
5069
5874
|
});
|
|
5070
5875
|
},
|
|
5071
5876
|
async getPortEndpoint({ port, protocol = "ws" }) {
|
|
5072
5877
|
const scheme = protocol === "ws" ? "ws" : "http";
|
|
5073
|
-
if (
|
|
5074
|
-
return { url: await
|
|
5878
|
+
if (gateway && !gateway.stopped) return { url: await gateway.portUrl(port, scheme) };
|
|
5879
|
+
return { url: await o.portWithoutGateway(port, scheme) };
|
|
5075
5880
|
},
|
|
5076
|
-
async getPortUrl(
|
|
5077
|
-
return (await session.getPortEndpoint(
|
|
5881
|
+
async getPortUrl(p) {
|
|
5882
|
+
return (await session.getPortEndpoint(p)).url;
|
|
5078
5883
|
},
|
|
5079
|
-
stop: destroy,
|
|
5080
|
-
destroy,
|
|
5884
|
+
stop: o.destroy,
|
|
5885
|
+
destroy: o.destroy,
|
|
5081
5886
|
restricted: () => {
|
|
5082
|
-
const {
|
|
5083
|
-
const {
|
|
5887
|
+
const { readFile, readTextFile, writeFile, writeTextFile, stat, listDirectory } = session;
|
|
5888
|
+
const { deleteFile, spawn: spawnIn, run: runIn } = session;
|
|
5084
5889
|
return {
|
|
5085
5890
|
description,
|
|
5086
5891
|
readFile,
|
|
@@ -5092,13 +5897,293 @@ async function createSshSession(options) {
|
|
|
5092
5897
|
stat,
|
|
5093
5898
|
listDirectory,
|
|
5094
5899
|
deleteFile,
|
|
5095
|
-
spawn,
|
|
5096
|
-
run
|
|
5900
|
+
spawn: spawnIn,
|
|
5901
|
+
run: runIn
|
|
5097
5902
|
};
|
|
5098
5903
|
}
|
|
5099
5904
|
};
|
|
5100
5905
|
return session;
|
|
5101
5906
|
}
|
|
5102
|
-
|
|
5907
|
+
// ../sandbox-docker/src/ssh-session.ts
|
|
5908
|
+
/** ssh's own exit status: it couldn't connect, or the connection dropped. */
|
|
5909
|
+
const SSH_FAILED = 255;
|
|
5910
|
+
/** Held while one slot sets up, so slots sharing a machine don't install the same things at once. */
|
|
5911
|
+
const SETUP_LOCK = "/var/lock/reeval-setup";
|
|
5912
|
+
/** The machine's homes, root's: `home-<label>.tar`, and the `.lock` its installer holds. */
|
|
5913
|
+
const HOMES = "/var/lib/reeval-pool";
|
|
5914
|
+
const RESTORED = "reeval:home-restored";
|
|
5915
|
+
const CLAIMED = "reeval:install-claimed";
|
|
5916
|
+
const WAITING = "reeval:install-waiting";
|
|
5917
|
+
const COPY_FAILED = "reeval:home-copy-failed";
|
|
5918
|
+
const FRESH = "reeval:install-fresh";
|
|
5919
|
+
/** How long a slot waits for another's install, past the install's own deadline of 10 minutes. */
|
|
5920
|
+
const INSTALL_WAIT_MS = 66e4;
|
|
5921
|
+
const homeFiles = (label) => {
|
|
5922
|
+
const base = `${HOMES}/home-${label.replace(/[^A-Za-z0-9._-]/g, "_")}`;
|
|
5923
|
+
return {
|
|
5924
|
+
tar: `${base}.tar`,
|
|
5925
|
+
lock: `${base}.lock`
|
|
5926
|
+
};
|
|
5927
|
+
};
|
|
5928
|
+
/**
|
|
5929
|
+
* Root commands that empty a slot's home back to the skeleton. The directory itself stays: on a
|
|
5930
|
+
* shared machine, slot 0's is where the other slots' commands see their own homes.
|
|
5931
|
+
*/
|
|
5932
|
+
const skeletonHome = (layout) => {
|
|
5933
|
+
const [u, home] = [shellQuote(layout.user), shellQuote(layout.home)];
|
|
5934
|
+
return `mkdir -p ${home} && find ${home} -mindepth 1 -delete && cp -a /etc/skel/. ${home}/ && chown -R -h ${u}:${u} ${home} && chmod 700 ${home}`;
|
|
5935
|
+
};
|
|
5936
|
+
/**
|
|
5937
|
+
* Root commands that put a used slot back as a new one finds it: none of its user's processes,
|
|
5938
|
+
* cron or at jobs, lingering, temporary files, locks or message queues, an empty working root and
|
|
5939
|
+
* state directory, and the skeleton home.
|
|
5940
|
+
*/
|
|
5941
|
+
function resetSlot(layout) {
|
|
5942
|
+
const u = shellQuote(layout.user);
|
|
5943
|
+
return [
|
|
5944
|
+
`if id -u ${u} >/dev/null 2>&1; then`,
|
|
5945
|
+
`for i in 1 2 3 4 5 6 7 8 9 10; do pkill -KILL -u ${u} || break; sleep 0.2; done`,
|
|
5946
|
+
`crontab -r -u ${u} 2>/dev/null`,
|
|
5947
|
+
`atq 2>/dev/null | awk -v u=${u} '$NF == u { print $1 }' | xargs -r atrm 2>/dev/null`,
|
|
5948
|
+
`loginctl disable-linger ${u} 2>/dev/null`,
|
|
5949
|
+
`find /tmp /var/tmp /dev/shm /run/lock /dev/mqueue -xdev -mindepth 1 -user ${u} -delete 2>/dev/null`,
|
|
5950
|
+
`rm -rf ${shellQuote(layout.root)} ${shellQuote(layout.state)}`,
|
|
5951
|
+
skeletonHome(layout),
|
|
5952
|
+
"fi; true"
|
|
5953
|
+
].join("\n");
|
|
5954
|
+
}
|
|
5955
|
+
/**
|
|
5956
|
+
* The root script that gives a slot the machine's home for `label`. With a copy kept, it unpacks
|
|
5957
|
+
* it into the slot's home ({@link RESTORED}): every slot sees its home at one path, so the copy
|
|
5958
|
+
* needs no change. With none, the slot takes the install's lock and holds it, in the process that
|
|
5959
|
+
* then reads its stdin until the installer closes it ({@link CLAIMED}); a slot that finds it held
|
|
5960
|
+
* says {@link WAITING} and blocks until the kernel releases it, when its holder finishes or dies.
|
|
5961
|
+
* A copy that won't unpack is deleted ({@link COPY_FAILED}) and the slot goes for the lock again,
|
|
5962
|
+
* or installs on its own ({@link FRESH}).
|
|
5963
|
+
*/
|
|
5964
|
+
function slotHome(layout, label) {
|
|
5965
|
+
const f = homeFiles(label);
|
|
5966
|
+
const [tar, lock] = [shellQuote(f.tar), shellQuote(f.lock)];
|
|
5967
|
+
const [u, home] = [shellQuote(layout.user), shellQuote(layout.home)];
|
|
5968
|
+
const restore = `find ${home} -mindepth 1 -delete && tar -C ${home} --strip-components=1 -xpf ${tar} && chown -R -h ${u}:${u} ${home} && chmod 700 ${home}`;
|
|
5969
|
+
return [
|
|
5970
|
+
`mkdir -p ${shellQuote(HOMES)} && chmod 700 ${shellQuote(HOMES)} && exec 9>>${lock} || exit 1`,
|
|
5971
|
+
"for try in 1 2; do",
|
|
5972
|
+
`if [ ! -f ${tar} ] && ! flock -x -n 9; then echo ${WAITING}; flock -x -w ${INSTALL_WAIT_MS / 1e3} 9 || { echo "another slot was still installing the harness after ${INSTALL_WAIT_MS / 6e4} minutes" >&2; exit 1; }; fi`,
|
|
5973
|
+
`if [ ! -f ${tar} ]; then echo ${CLAIMED}; exec cat >/dev/null; fi`,
|
|
5974
|
+
"flock -u 9",
|
|
5975
|
+
`if ${restore}; then echo ${RESTORED}; exit 0; fi`,
|
|
5976
|
+
`echo ${COPY_FAILED}; rm -f ${tar}; ${skeletonHome(layout)} || exit 1`,
|
|
5977
|
+
"done",
|
|
5978
|
+
`echo ${FRESH}`
|
|
5979
|
+
].join("\n");
|
|
5980
|
+
}
|
|
5981
|
+
/**
|
|
5982
|
+
* Sets up a Linux VM reached over SSH for a harness session: the login user has passwordless
|
|
5983
|
+
* `sudo`, and the agent, setup steps and checks run as {@link SANDBOX_USER}, a user made here with
|
|
5984
|
+
* no `sudo` and none of the login user's groups or variables. Ports are reached through the
|
|
5985
|
+
* egress gateway's tunnel. When setting up fails, the connection is closed.
|
|
5986
|
+
*/
|
|
5987
|
+
async function connectSsh(options) {
|
|
5988
|
+
const { target, abortSignal: signal } = options;
|
|
5989
|
+
const layout = options.layout ?? slotLayout(0);
|
|
5990
|
+
const baseEnv = {
|
|
5991
|
+
PATH: [
|
|
5992
|
+
`${SANDBOX_HOME}/.local/bin`,
|
|
5993
|
+
...options.path ?? [],
|
|
5994
|
+
SYSTEM_PATH
|
|
5995
|
+
].join(":"),
|
|
5996
|
+
HOME: SANDBOX_HOME,
|
|
5997
|
+
USER: layout.user,
|
|
5998
|
+
LOGNAME: layout.user,
|
|
5999
|
+
SHELL: "/bin/bash",
|
|
6000
|
+
LANG: "C.UTF-8"
|
|
6001
|
+
};
|
|
6002
|
+
const userEnv = {
|
|
6003
|
+
NPM_CONFIG_UPDATE_NOTIFIER: "false",
|
|
6004
|
+
NPM_CONFIG_PREFIX: `${SANDBOX_HOME}/.local`,
|
|
6005
|
+
...options.env
|
|
6006
|
+
};
|
|
6007
|
+
const hostRun = async (argv, o) => {
|
|
6008
|
+
const [bin = "ssh", ...args] = argv;
|
|
6009
|
+
const startedAt = Date.now();
|
|
6010
|
+
try {
|
|
6011
|
+
const r = await run(bin, args, {
|
|
6012
|
+
input: o.input ?? "",
|
|
6013
|
+
signal: o.signal,
|
|
6014
|
+
binary: true
|
|
6015
|
+
});
|
|
6016
|
+
traceDocker(args, startedAt, {
|
|
6017
|
+
...r,
|
|
6018
|
+
stdin: o.input?.length ?? 0
|
|
6019
|
+
}, "ssh");
|
|
6020
|
+
return r;
|
|
6021
|
+
} catch (error) {
|
|
6022
|
+
traceDocker(args, startedAt, { error }, "ssh");
|
|
6023
|
+
throw error;
|
|
6024
|
+
}
|
|
6025
|
+
};
|
|
6026
|
+
const ssh = (remote) => hostRun(sshArgv(target, remote), {
|
|
6027
|
+
input: "",
|
|
6028
|
+
signal
|
|
6029
|
+
});
|
|
6030
|
+
const closeConnection = async () => {
|
|
6031
|
+
if (!controlOptions(target.controlPath, 0).length) return;
|
|
6032
|
+
const [bin = "ssh", ...args] = sshArgv(target, "");
|
|
6033
|
+
await run(bin, [
|
|
6034
|
+
"-O",
|
|
6035
|
+
"exit",
|
|
6036
|
+
...args.slice(0, -1)
|
|
6037
|
+
]).catch(() => {});
|
|
6038
|
+
};
|
|
6039
|
+
const fail = async (error) => {
|
|
6040
|
+
await closeConnection();
|
|
6041
|
+
throw signal?.aborted ? signal.reason : error;
|
|
6042
|
+
};
|
|
6043
|
+
const { user } = layout;
|
|
6044
|
+
const addUser = (name) => `{ id -u ${name} >/dev/null 2>&1 || useradd --create-home --shell /bin/bash --user-group ${name}; }`;
|
|
6045
|
+
const setup = [
|
|
6046
|
+
EXEC_UMASK,
|
|
6047
|
+
...options.reset ? [`{ ${resetSlot(layout)}\n}`] : [],
|
|
6048
|
+
...layout.home === "/home/reeval" ? [addUser(user)] : [
|
|
6049
|
+
`{ command -v unshare && command -v setpriv && command -v mount; } >/dev/null || { echo "a machine shared by attempts needs unshare, setpriv and mount (util-linux)" >&2; false; }`,
|
|
6050
|
+
addUser(SANDBOX_USER),
|
|
6051
|
+
`chmod 700 ${SANDBOX_HOME}`,
|
|
6052
|
+
`{ id -u ${user} >/dev/null 2>&1 || useradd --no-create-home --home-dir ${SANDBOX_HOME} --shell /bin/bash --user-group ${user}; }`,
|
|
6053
|
+
`{ [ -d ${layout.home} ] || { cp -a /etc/skel ${layout.home} && chown -R ${user}:${user} ${layout.home}; }; }`
|
|
6054
|
+
],
|
|
6055
|
+
`mkdir -p ${layout.root} && chown ${user}:${user} ${layout.root}`,
|
|
6056
|
+
`chmod 700 ${layout.root} ${layout.home}`,
|
|
6057
|
+
`mkdir -p ${layout.state} && chown 0:0 ${layout.state} && chmod 700 ${layout.state}`,
|
|
6058
|
+
...options.prepare ? [options.prepare] : []
|
|
6059
|
+
].join(" && ");
|
|
6060
|
+
const asRoot = options.layout ? `sudo -n -- flock ${SETUP_LOCK} /bin/sh -c ${shellQuote(setup)}` : `sudo -n -- /bin/sh -c ${shellQuote(setup)}`;
|
|
6061
|
+
const deadline = Date.now() + (options.connectTimeoutMs ?? 6e4);
|
|
6062
|
+
for (let wait = 500;; wait = Math.min(wait * 2, 5e3)) {
|
|
6063
|
+
const made = await ssh(asRoot).catch(fail);
|
|
6064
|
+
if (made.exitCode === 0) break;
|
|
6065
|
+
if (made.exitCode !== SSH_FAILED || Date.now() + wait > deadline) {
|
|
6066
|
+
const why = made.stderr.trim() || made.stdout.toString("utf8").trim();
|
|
6067
|
+
return fail(/* @__PURE__ */ new Error(`Couldn't set up ${options.description}: ${why.slice(-500)}`));
|
|
6068
|
+
}
|
|
6069
|
+
await new Promise((resolve) => setTimeout(resolve, wait));
|
|
6070
|
+
if (signal?.aborted) return fail(signal.reason);
|
|
6071
|
+
}
|
|
6072
|
+
/** The process holding the install's lock in the machine, while this slot installs. */
|
|
6073
|
+
let holder;
|
|
6074
|
+
const release = async () => {
|
|
6075
|
+
const held = holder;
|
|
6076
|
+
holder = void 0;
|
|
6077
|
+
if (!held || held.exitCode !== null) return;
|
|
6078
|
+
const gone = new Promise((resolve) => held.once("close", resolve));
|
|
6079
|
+
held.stdin?.end();
|
|
6080
|
+
const timer = setTimeout(() => held.kill("SIGKILL"), 1e4);
|
|
6081
|
+
await gone;
|
|
6082
|
+
clearTimeout(timer);
|
|
6083
|
+
};
|
|
6084
|
+
const shell = linuxShell({
|
|
6085
|
+
run: hostRun,
|
|
6086
|
+
remote: (command) => sshArgv(target, command),
|
|
6087
|
+
id: `${target.hostKeyAlias}-${layout.user}`,
|
|
6088
|
+
user: baseEnv,
|
|
6089
|
+
signal,
|
|
6090
|
+
layout
|
|
6091
|
+
});
|
|
6092
|
+
return {
|
|
6093
|
+
root: sshTransport(target),
|
|
6094
|
+
async home() {
|
|
6095
|
+
if (!options.home) return {
|
|
6096
|
+
restored: false,
|
|
6097
|
+
waitedMs: 0
|
|
6098
|
+
};
|
|
6099
|
+
const [bin = "ssh", ...args] = sshArgv(target, `sudo -n -- /bin/sh -c ${shellQuote(`${EXEC_UMASK}\n${slotHome(layout, options.home)}`)}`);
|
|
6100
|
+
const startedAt = Date.now();
|
|
6101
|
+
const child = spawn(bin, args, { stdio: [
|
|
6102
|
+
"pipe",
|
|
6103
|
+
"pipe",
|
|
6104
|
+
"pipe"
|
|
6105
|
+
] });
|
|
6106
|
+
let [out, err] = ["", ""];
|
|
6107
|
+
child.stderr.on("data", (d) => {
|
|
6108
|
+
err += d.toString("utf8");
|
|
6109
|
+
});
|
|
6110
|
+
const [decided, waited] = (await new Promise((resolve, reject) => {
|
|
6111
|
+
let waitingSince;
|
|
6112
|
+
const stop = () => child.kill("SIGKILL");
|
|
6113
|
+
signal?.addEventListener("abort", stop, { once: true });
|
|
6114
|
+
child.stdout.on("data", (d) => {
|
|
6115
|
+
out += d.toString("utf8");
|
|
6116
|
+
if (waitingSince === void 0 && out.includes(WAITING)) waitingSince = Date.now();
|
|
6117
|
+
const decided = [
|
|
6118
|
+
RESTORED,
|
|
6119
|
+
CLAIMED,
|
|
6120
|
+
FRESH
|
|
6121
|
+
].find((m) => out.includes(m));
|
|
6122
|
+
if (!decided) return;
|
|
6123
|
+
signal?.removeEventListener("abort", stop);
|
|
6124
|
+
resolve(`${decided} ${waitingSince === void 0 ? 0 : Date.now() - waitingSince}`);
|
|
6125
|
+
});
|
|
6126
|
+
child.once("error", reject);
|
|
6127
|
+
child.once("close", (code) => {
|
|
6128
|
+
signal?.removeEventListener("abort", stop);
|
|
6129
|
+
if (signal?.aborted) return reject(signal.reason);
|
|
6130
|
+
const why = err.trim() || out.trim() || `ssh exited with ${code}`;
|
|
6131
|
+
reject(/* @__PURE__ */ new Error(`Couldn't give ${user} the machine's home in ${options.description}: ${why.slice(-500)}`));
|
|
6132
|
+
});
|
|
6133
|
+
}).finally(() => traceDocker(args, startedAt, {
|
|
6134
|
+
exitCode: child.exitCode,
|
|
6135
|
+
stdout: out,
|
|
6136
|
+
stderr: err
|
|
6137
|
+
}, "ssh"))).split(" ");
|
|
6138
|
+
if (decided === CLAIMED) holder = child;
|
|
6139
|
+
else child.stdin.end();
|
|
6140
|
+
return {
|
|
6141
|
+
restored: decided === RESTORED,
|
|
6142
|
+
waitedMs: Number(waited),
|
|
6143
|
+
...out.includes(COPY_FAILED) && { copyFailed: err.trim().slice(-500) || "the machine's copy didn't unpack" }
|
|
6144
|
+
};
|
|
6145
|
+
},
|
|
6146
|
+
async snapshotHome() {
|
|
6147
|
+
if (!options.home || !holder) return;
|
|
6148
|
+
const f = homeFiles(options.home);
|
|
6149
|
+
const command = [
|
|
6150
|
+
EXEC_UMASK,
|
|
6151
|
+
`tar -C ${shellQuote(posix.dirname(layout.home))} -cf ${shellQuote(f.tar)}.$$ ${shellQuote(posix.basename(layout.home))}`,
|
|
6152
|
+
`mv ${shellQuote(f.tar)}.$$ ${shellQuote(f.tar)}`
|
|
6153
|
+
].join(" && ");
|
|
6154
|
+
try {
|
|
6155
|
+
const r = await ssh(`sudo -n -- /bin/sh -c ${shellQuote(command)}`);
|
|
6156
|
+
if (r.exitCode !== 0) throw new Error(`Couldn't keep ${layout.user}'s home in ${options.description}: ${r.stderr.trim().slice(-500)}`);
|
|
6157
|
+
} finally {
|
|
6158
|
+
await release();
|
|
6159
|
+
}
|
|
6160
|
+
},
|
|
6161
|
+
async close() {
|
|
6162
|
+
await release();
|
|
6163
|
+
await closeConnection();
|
|
6164
|
+
},
|
|
6165
|
+
session: ({ gateway, noGateway, destroy }) => transportSession({
|
|
6166
|
+
id: target.hostKeyAlias,
|
|
6167
|
+
description: options.description,
|
|
6168
|
+
defaultWorkingDirectory: layout.root,
|
|
6169
|
+
shell,
|
|
6170
|
+
env: (env) => ({
|
|
6171
|
+
...userEnv,
|
|
6172
|
+
...gateway?.env,
|
|
6173
|
+
...env
|
|
6174
|
+
}),
|
|
6175
|
+
gateway,
|
|
6176
|
+
egress: gateway ? { active: true } : {
|
|
6177
|
+
active: false,
|
|
6178
|
+
reason: noGateway ?? ""
|
|
6179
|
+
},
|
|
6180
|
+
async portWithoutGateway(port) {
|
|
6181
|
+
throw new Error(`Port ${port} of ${options.description} isn't reachable: the egress gateway ${gateway?.stopped ? `stopped: ${gateway.stopped}` : "isn't running"}`);
|
|
6182
|
+
},
|
|
6183
|
+
destroy
|
|
6184
|
+
})
|
|
6185
|
+
};
|
|
6186
|
+
}
|
|
6187
|
+
export { startGateway as $, failureCause as $t, harnessImageFor as A, harnessLabel as At, reevalImageKey as B, dockerState as Bt, buildInstallLayer as C, LABEL as Ct, dockerfileKey as D, SANDBOX_USER as Dt, dockerfileBases as E, SANDBOX_STATE as Et, localKey as F, dockerignoreMatcher as Ft, EgressUnavailableError as G, OPAQUE_OUTPUT as Gt, sourceTreeHash as H, imageTags as Ht, pluginBuildDir as I, docker as It, createDockerSession as J, run as Jt, PRIVILEGED_CAPABILITIES as K, onDockerCommand as Kt, pluginBuildKey as L, dockerAvailable as Lt, installLayerTag as M, isBakedHarness as Mt, installScript as N, slotLayout as Nt, dockerfileTag as O, WORKSPACE_DIR as Ot, isLocalKey as P, contextFiles as Pt, PROXY_PORT as Q, causeLine as Qt, pluginLayerTag as R, dockerCapacity as Rt, buildImage as S, HARNESS_PACKAGES as St, contextHash as T, SANDBOX_ROOT as Tt, usesReevalBase as U, isRegistryDigest as Ut, resolveFrom as V, imageInfo as Vt, DEFAULT_LIMITS as W, removeContainerDetached as Wt, pathOperations as X, ImageBuildError as Xt, dockerSandboxProvider as Y, shellQuote as Yt, CA_PATH as Z, RETRY_DELAYS as Zt, bakeKey as _, requestFacts as _t, enginePlatform as a, engineSpec as an, sshTransport as at, bakedRecipe as b, BRIDGE_PORT as bt, registryProblem as c, placeholder as ct, DOCKER_CONTEXT as d, onEndpoint as dt, isTransient as en, SSH_OPTIONS as et, PLATFORM as f, DOCKER_EGRESS as ft, bakeHarness as g, hostAllowed as gt, REEVAL_BASE_ARG as h, defaultAllowedHosts as ht, darwinShell as i, dockerSeccompFile as in, sshArgv as it, imageKey as j, imageFor as jt, fromImageKey as k, adapterVersion as kt, registryRef as l, applyTransformations as lt, PNPM_VERSION as m, PACKAGE_HOSTS as mt, resetSlot as n, retryTransient as nn, controlPathFits as nt, pullLayer as o, normalizeImageId as on, MODEL_FIELD as ot, PLUGIN_BUILDS_DIR as p, HARNESS_HOSTS as pt, ROOT_CAPABILITIES as q, traceDocker as qt, transportSession as r, ENGINES as rn, privateDir as rt, pushLayer as s, usageReader as st, connectSsh as t, parseBuildOutput as tn, controlOptions as tt, MCP_TIMER as u, matches as ut, bakedAdapter as v, BAKED_HARNESSES as vt, buildPluginLayer as w, SANDBOX_HOME as wt, buildDockerfile as x, DEFAULT_IMAGE as xt, bakedHarnessName as y, BASE_IMAGE as yt, pruneImages as z, dockerOk as zt };
|
|
5103
6188
|
|
|
5104
|
-
//# sourceMappingURL=src-
|
|
6189
|
+
//# sourceMappingURL=src-CWfy8ct8.js.map
|