zidane 7.2.5 → 8.0.4
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/LICENSE +21 -0
- package/README.md +34 -6
- package/dist/{acp-D-tVyUjw.js → acp-DQDhi2dj.js} +230 -77
- package/dist/acp-DQDhi2dj.js.map +1 -0
- package/dist/acp-cli.d.ts +1 -1
- package/dist/acp-cli.js +9 -66
- package/dist/acp-cli.js.map +1 -1
- package/dist/acp.d.ts +10 -590
- package/dist/acp.d.ts.map +1 -1
- package/dist/acp.js +3 -3
- package/dist/{agent-D0zZnGbt.js → agent-DSLNmBp0.js} +14401 -13214
- package/dist/agent-DSLNmBp0.js.map +1 -0
- package/dist/agent.d.ts +1 -1
- package/dist/agent.js +3 -2
- package/dist/aliasing-lVFbm81n.js +217 -0
- package/dist/aliasing-lVFbm81n.js.map +1 -0
- package/dist/{anthropic-C2aole0G.js → anthropic-CD00LhUP.js} +1442 -1264
- package/dist/anthropic-CD00LhUP.js.map +1 -0
- package/dist/artifacts-CV2hUKnL.js.map +1 -1
- package/dist/{atomic-write-B7zr1ddF.js → atomic-write-Ijgf2Mhc.js} +13 -3
- package/dist/atomic-write-Ijgf2Mhc.js.map +1 -0
- package/dist/call-tool-dHlbGOIY.js +70 -0
- package/dist/call-tool-dHlbGOIY.js.map +1 -0
- package/dist/chat/pure.d.ts +372 -6
- package/dist/chat/pure.d.ts.map +1 -1
- package/dist/chat/pure.js +35 -244
- package/dist/chat/pure.js.map +1 -1
- package/dist/{approvals-DKaJZYlm.js → chat-JPJJ8uu5.js} +15879 -14631
- package/dist/chat-JPJJ8uu5.js.map +1 -0
- package/dist/chat.d.ts +4 -6
- package/dist/chat.js +23 -12
- package/dist/cli-shared-C-YCaglL.js +159 -0
- package/dist/cli-shared-C-YCaglL.js.map +1 -0
- package/dist/client-core-BQSyDALT.d.ts +2115 -0
- package/dist/client-core-BQSyDALT.d.ts.map +1 -0
- package/dist/codemode-worker.d.ts +1 -0
- package/dist/codemode-worker.js +155 -0
- package/dist/codemode-worker.js.map +1 -0
- package/dist/codemode.d.ts +352 -0
- package/dist/codemode.d.ts.map +1 -0
- package/dist/codemode.js +5 -0
- package/dist/connection-Dr-Js4yZ.d.ts +28 -0
- package/dist/connection-Dr-Js4yZ.d.ts.map +1 -0
- package/dist/connection-loop-gdh22LTI.js +112 -0
- package/dist/connection-loop-gdh22LTI.js.map +1 -0
- package/dist/context-segments-BHKlagL6.js +1016 -0
- package/dist/context-segments-BHKlagL6.js.map +1 -0
- package/dist/{context-transport-T_6AYIvy.js → context-transport-DSMTUsK1.js} +3 -3
- package/dist/{context-transport-T_6AYIvy.js.map → context-transport-DSMTUsK1.js.map} +1 -1
- package/dist/contexts/daytona.d.ts +19 -8
- package/dist/contexts/daytona.d.ts.map +1 -1
- package/dist/contexts/daytona.js +1 -440
- package/dist/contexts/docker.d.ts +36 -7
- package/dist/contexts/docker.d.ts.map +1 -1
- package/dist/contexts/docker.js +1 -456
- package/dist/contexts/e2b.d.ts +68 -13
- package/dist/contexts/e2b.d.ts.map +1 -1
- package/dist/contexts/e2b.js +1 -382
- package/dist/contexts/sandbox.d.ts +1 -1
- package/dist/contexts/sandbox.js +5 -0
- package/dist/contexts/sandbox.js.map +1 -1
- package/dist/{contexts-CRE9pw07.js → contexts-d7UolYot.js} +1059 -524
- package/dist/contexts-d7UolYot.js.map +1 -0
- package/dist/contexts.d.ts +3 -3
- package/dist/contexts.js +1 -1
- package/dist/cred-keys-GpBg71cP.js +105 -0
- package/dist/cred-keys-GpBg71cP.js.map +1 -0
- package/dist/{auth-BG2rVKSt.js → credentials-JttEuRON.js} +55 -206
- package/dist/credentials-JttEuRON.js.map +1 -0
- package/dist/{cursor-iojRXHF9.js → cursor-CdjaQTBW.js} +3 -3
- package/dist/{cursor-iojRXHF9.js.map → cursor-CdjaQTBW.js.map} +1 -1
- package/dist/daemon-cli.d.ts +1 -1
- package/dist/daemon-cli.js +3 -2
- package/dist/daemon-cli.js.map +1 -1
- package/dist/daytona-DG3omipZ.js +513 -0
- package/dist/daytona-DG3omipZ.js.map +1 -0
- package/dist/defaults-Cx3zvDOV.js +23 -0
- package/dist/defaults-Cx3zvDOV.js.map +1 -0
- package/dist/dispatcher-BMlu2BmZ.js +4941 -0
- package/dist/dispatcher-BMlu2BmZ.js.map +1 -0
- package/dist/docker-BZhMMJUp.js +727 -0
- package/dist/docker-BZhMMJUp.js.map +1 -0
- package/dist/e2b-CEVOdRib.js +480 -0
- package/dist/e2b-CEVOdRib.js.map +1 -0
- package/dist/edit-utils-EGosADZq.js +234 -0
- package/dist/edit-utils-EGosADZq.js.map +1 -0
- package/dist/environment-8wsKE2Ln.js +214 -0
- package/dist/environment-8wsKE2Ln.js.map +1 -0
- package/dist/eval-BNcvle_J.js +1595 -0
- package/dist/eval-BNcvle_J.js.map +1 -0
- package/dist/eval.d.ts +2 -2
- package/dist/eval.js +1 -1489
- package/dist/executor-Cx5-8yqi.js +621 -0
- package/dist/executor-Cx5-8yqi.js.map +1 -0
- package/dist/extension-authoring-DyGGmq9V.js +385 -0
- package/dist/extension-authoring-DyGGmq9V.js.map +1 -0
- package/dist/extensions.d.ts +2 -2
- package/dist/extensions.js +3 -3
- package/dist/{fetch-url-DX75gpL0.js → fetch-url-Ct2TjDWt.js} +4 -4
- package/dist/{fetch-url-DX75gpL0.js.map → fetch-url-Ct2TjDWt.js.map} +1 -1
- package/dist/{format-BF745pLL.js → format-C2NQEVUH.js} +39 -2
- package/dist/format-C2NQEVUH.js.map +1 -0
- package/dist/format-bytes-C7tfc3Zm.js +55 -0
- package/dist/format-bytes-C7tfc3Zm.js.map +1 -0
- package/dist/headless-C_rNUuYC.js +960 -0
- package/dist/headless-C_rNUuYC.js.map +1 -0
- package/dist/headless.d.ts +1 -1
- package/dist/headless.js +1 -413
- package/dist/{history-search-C4bk1Wz_.js → history-search-CcYzF8-0.js} +7 -3
- package/dist/history-search-CcYzF8-0.js.map +1 -0
- package/dist/history-search-worker.d.ts +1 -1
- package/dist/history-search-worker.js +1 -1
- package/dist/host-D7NrI03V.js +378 -0
- package/dist/host-D7NrI03V.js.map +1 -0
- package/dist/host-signals-BcP5QKUD.js +118 -0
- package/dist/host-signals-BcP5QKUD.js.map +1 -0
- package/dist/identity-CwfO8K-t.js +26 -0
- package/dist/identity-CwfO8K-t.js.map +1 -0
- package/dist/{index-BgN1T3lk.d.ts → index-BGe1fQT7.d.ts} +10987 -9320
- package/dist/index-BGe1fQT7.d.ts.map +1 -0
- package/dist/index-BVQsIKGn.d.ts +448 -0
- package/dist/index-BVQsIKGn.d.ts.map +1 -0
- package/dist/{index-C6NEd5y_.d.ts → index-CHABJd-L.d.ts} +3386 -502
- package/dist/index-CHABJd-L.d.ts.map +1 -0
- package/dist/{index-C37_ppWv.d.ts → index-D6a7qXpg.d.ts} +2 -3
- package/dist/index-D6a7qXpg.d.ts.map +1 -0
- package/dist/index.d.ts +6 -6
- package/dist/index.js +27 -23
- package/dist/{completion-core-BRo86R_L.js → inline-ghost-BVRQeGoL.js} +50 -2
- package/dist/inline-ghost-BVRQeGoL.js.map +1 -0
- package/dist/ipc/remote.d.ts +313 -0
- package/dist/ipc/remote.d.ts.map +1 -0
- package/dist/ipc/remote.js +4 -0
- package/dist/ipc.d.ts +6 -964
- package/dist/ipc.js +403 -4
- package/dist/ipc.js.map +1 -0
- package/dist/{isolation-Kfoof0MM.d.ts → isolation-D9L650W5.d.ts} +100 -15
- package/dist/isolation-D9L650W5.d.ts.map +1 -0
- package/dist/json-rpc--HXQti1E.js +350 -0
- package/dist/json-rpc--HXQti1E.js.map +1 -0
- package/dist/links-j8rED1sR.js +603 -0
- package/dist/links-j8rED1sR.js.map +1 -0
- package/dist/local-terminal-D8QThwo_.js +252 -0
- package/dist/local-terminal-D8QThwo_.js.map +1 -0
- package/dist/{logger--C1VQjwJ.js → logger-Gtqlayx8.js} +199 -173
- package/dist/logger-Gtqlayx8.js.map +1 -0
- package/dist/logs-view-CWG8aUAG.js.map +1 -1
- package/dist/{mcp-CgNd-f3F.js → mcp-_wecH9Qe.js} +608 -562
- package/dist/mcp-_wecH9Qe.js.map +1 -0
- package/dist/mcp.d.ts +2 -2
- package/dist/mcp.js +2 -2
- package/dist/media-sniff-UKijEaiQ.js.map +1 -1
- package/dist/{messages-2jcOA_5R.js → messages-BqiwcD2Q.js} +1017 -1014
- package/dist/messages-BqiwcD2Q.js.map +1 -0
- package/dist/{oauth-DxHO17JE.js → oauth-Px_pBB9W.js} +5 -5
- package/dist/{oauth-DxHO17JE.js.map → oauth-Px_pBB9W.js.map} +1 -1
- package/dist/{openai-compat-Dy56weK8.js → openai-compat-CFrpH7uq.js} +432 -589
- package/dist/openai-compat-CFrpH7uq.js.map +1 -0
- package/dist/orchestration-BCGmB8Ps.js +511 -0
- package/dist/orchestration-BCGmB8Ps.js.map +1 -0
- package/dist/output/stream-json.d.ts +1 -2
- package/dist/output/stream-json.d.ts.map +1 -1
- package/dist/output/stream-json.js +1 -1
- package/dist/output/terminal.d.ts +1 -2
- package/dist/output/terminal.d.ts.map +1 -1
- package/dist/output/terminal.js +13 -7
- package/dist/output/terminal.js.map +1 -1
- package/dist/{plugins-gbI7SBA6.js → plugins-DS7mahzZ.js} +20 -101
- package/dist/plugins-DS7mahzZ.js.map +1 -0
- package/dist/plugins.d.ts +1 -1
- package/dist/plugins.js +1 -2
- package/dist/prelude-Cxo4t74B.js +517 -0
- package/dist/prelude-Cxo4t74B.js.map +1 -0
- package/dist/presets.d.ts +1 -1
- package/dist/presets.js +1 -2
- package/dist/project-root-B8zADr4o.js +167 -0
- package/dist/project-root-B8zADr4o.js.map +1 -0
- package/dist/project-user-paths-BSgtrRxl.js +58 -0
- package/dist/project-user-paths-BSgtrRxl.js.map +1 -0
- package/dist/{prompts-Pqc3JdW_.d.ts → prompts-DYcvqShf.d.ts} +14 -11
- package/dist/prompts-DYcvqShf.d.ts.map +1 -0
- package/dist/protocol-DnhqqSmE.js +13 -0
- package/dist/protocol-DnhqqSmE.js.map +1 -0
- package/dist/providers/anthropic.d.ts +2 -2
- package/dist/providers/anthropic.js +1 -2
- package/dist/providers/arcee.d.ts +1 -1
- package/dist/providers/arcee.js +1 -1
- package/dist/providers/baseten.d.ts +1 -1
- package/dist/providers/baseten.js +1 -1
- package/dist/providers/cerebras.d.ts +1 -1
- package/dist/providers/cerebras.js +3 -2
- package/dist/providers/cerebras.js.map +1 -1
- package/dist/providers/local.d.ts +1 -1
- package/dist/providers/local.js +1 -1
- package/dist/providers/openai-compat.d.ts +1 -1
- package/dist/providers/openai-compat.js +1 -2
- package/dist/providers/openai.d.ts +1 -1
- package/dist/providers/openai.js +15 -12
- package/dist/providers/openai.js.map +1 -1
- package/dist/providers/openrouter.d.ts +1 -1
- package/dist/providers/openrouter.js +3 -2
- package/dist/providers/openrouter.js.map +1 -1
- package/dist/providers/xai.d.ts +1 -1
- package/dist/providers/xai.js +3 -3
- package/dist/{providers-BVhnFyiY.js → providers-XUR7F4Hi.js} +4 -4
- package/dist/{providers-BVhnFyiY.js.map → providers-XUR7F4Hi.js.map} +1 -1
- package/dist/providers.d.ts +1 -1
- package/dist/providers.js +4 -4
- package/dist/registry-D6ShBWJU.js +5234 -0
- package/dist/registry-D6ShBWJU.js.map +1 -0
- package/dist/remote-hosts-BtA_9ZGp.js +97 -0
- package/dist/remote-hosts-BtA_9ZGp.js.map +1 -0
- package/dist/restate.d.ts +2 -3
- package/dist/restate.d.ts.map +1 -1
- package/dist/restate.js +631 -572
- package/dist/restate.js.map +1 -1
- package/dist/run-summary-CklLiZ4y.js +288 -0
- package/dist/run-summary-CklLiZ4y.js.map +1 -0
- package/dist/{sandbox-BH0WQkXn.d.ts → sandbox-C5dR5DwQ.d.ts} +6 -3
- package/dist/sandbox-C5dR5DwQ.d.ts.map +1 -0
- package/dist/session/sqlite.d.ts +1 -2
- package/dist/session/sqlite.d.ts.map +1 -1
- package/dist/session/sqlite.js +1 -616
- package/dist/session-factory-BUGY5P40.js +1576 -0
- package/dist/session-factory-BUGY5P40.js.map +1 -0
- package/dist/{session-BqRP1hS7.js → session-xh9JXu6i.js} +94 -52
- package/dist/session-xh9JXu6i.js.map +1 -0
- package/dist/session.d.ts +1 -1
- package/dist/session.js +2 -2
- package/dist/settings-keys-Ckf29NeM.js +677 -0
- package/dist/settings-keys-Ckf29NeM.js.map +1 -0
- package/dist/shell-path-Dqaoow2J.js +412 -0
- package/dist/shell-path-Dqaoow2J.js.map +1 -0
- package/dist/{skills-BC3dodWp.js → skills-DKqZJm4X.js} +430 -470
- package/dist/skills-DKqZJm4X.js.map +1 -0
- package/dist/skills.d.ts +2 -2
- package/dist/skills.js +1 -2
- package/dist/source-mPExaUm8.js +381 -0
- package/dist/source-mPExaUm8.js.map +1 -0
- package/dist/sqlite-DV1DQzN2.js +698 -0
- package/dist/sqlite-DV1DQzN2.js.map +1 -0
- package/dist/{src-CkNQKFKr.js → src-BRMYRJib.js} +903 -1121
- package/dist/src-BRMYRJib.js.map +1 -0
- package/dist/{stdio-DPpBDPx5.js → stdio-C6YyoW3I.js} +4 -4
- package/dist/{stdio-DPpBDPx5.js.map → stdio-C6YyoW3I.js.map} +1 -1
- package/dist/{stdio-loader-Bbx19dMZ.js → stdio-loader-C830Vg-Z.js} +4 -4
- package/dist/{stdio-loader-Bbx19dMZ.js.map → stdio-loader-C830Vg-Z.js.map} +1 -1
- package/dist/system-prompt-MNVHatSD.d.ts.map +1 -1
- package/dist/timeout-DEaqslLO.d.ts.map +1 -1
- package/dist/todo-edits-Dn251YUP.js +1790 -0
- package/dist/todo-edits-Dn251YUP.js.map +1 -0
- package/dist/{turn-operations-DrbJlpq9.js → tool-formatters-IQFDrdrs.js} +1456 -2120
- package/dist/tool-formatters-IQFDrdrs.js.map +1 -0
- package/dist/tool-state-Dku6YqAB.js +989 -0
- package/dist/tool-state-Dku6YqAB.js.map +1 -0
- package/dist/tools/fetch-url.d.ts +1 -2
- package/dist/tools/fetch-url.d.ts.map +1 -1
- package/dist/tools/fetch-url.js +1 -2
- package/dist/tools/prompts.d.ts +1 -1
- package/dist/tools/prompts.js +7 -7
- package/dist/tools/prompts.js.map +1 -1
- package/dist/tools/web-search.d.ts +1 -2
- package/dist/tools/web-search.d.ts.map +1 -1
- package/dist/tools/web-search.js +2 -2
- package/dist/tools/web-search.js.map +1 -1
- package/dist/tools-_DnT3AGM.js +578 -0
- package/dist/tools-_DnT3AGM.js.map +1 -0
- package/dist/tools.d.ts +3 -3
- package/dist/tools.js +4 -2
- package/dist/tui.d.ts +534 -517
- package/dist/tui.d.ts.map +1 -1
- package/dist/tui.js +34933 -27243
- package/dist/tui.js.map +1 -1
- package/dist/turn-operations-B8sokwi5.js +333 -0
- package/dist/turn-operations-B8sokwi5.js.map +1 -0
- package/dist/turn-operations-DQX5ZZni.d.ts +3089 -0
- package/dist/turn-operations-DQX5ZZni.d.ts.map +1 -0
- package/dist/types-C7ZFOztE.d.ts +132 -0
- package/dist/types-C7ZFOztE.d.ts.map +1 -0
- package/dist/types-CH5XpIHw.js +114 -0
- package/dist/types-CH5XpIHw.js.map +1 -0
- package/dist/{types-CWgENVLY.js → types-Cu0ZGDu9.js} +10 -6
- package/dist/types-Cu0ZGDu9.js.map +1 -0
- package/dist/types-IqegbJEE.d.ts +624 -0
- package/dist/types-IqegbJEE.d.ts.map +1 -0
- package/dist/types.d.ts +4 -4
- package/dist/types.js +1 -1
- package/dist/url-D8HCl65b.js +1259 -0
- package/dist/url-D8HCl65b.js.map +1 -0
- package/dist/wasm-BVT-j5cl.js +33 -0
- package/dist/wasm-BVT-j5cl.js.map +1 -0
- package/dist/workspace-exec-stream-SV2R9d5S.js +355 -0
- package/dist/workspace-exec-stream-SV2R9d5S.js.map +1 -0
- package/dist/ws-CIHMvlSh.js +952 -0
- package/dist/ws-CIHMvlSh.js.map +1 -0
- package/dist/ws-client-N7NxzvQp.js +230 -0
- package/dist/ws-client-N7NxzvQp.js.map +1 -0
- package/dist/{xai-CazjStOK.js → xai-CvJTeLrI.js} +165 -5
- package/dist/xai-CvJTeLrI.js.map +1 -0
- package/dist/xdg-zweed0-t.js +117 -0
- package/dist/xdg-zweed0-t.js.map +1 -0
- package/docs/ACP.md +52 -0
- package/docs/ARCHITECTURE.md +103 -6
- package/docs/ARTIFACTS.md +8 -4
- package/docs/CHAT.md +165 -14
- package/docs/EXECUTION_CONTEXT.md +8 -0
- package/docs/EXTENSIONS.md +123 -2
- package/docs/HEADLESS.md +2 -0
- package/docs/IPC.md +775 -64
- package/docs/MACHINES.md +456 -0
- package/docs/PANELS.md +3 -0
- package/docs/README.md +4 -0
- package/docs/RESTATE.md +3 -2
- package/docs/RUN_IN_BACKGROUND.md +10 -2
- package/docs/SERVER.md +1085 -0
- package/docs/SKILL.md +6 -1
- package/docs/TERMINAL.md +75 -0
- package/docs/TUI.md +65 -14
- package/package.json +58 -26
- package/scripts/eval.ts +4 -0
- package/dist/acp-D-tVyUjw.js.map +0 -1
- package/dist/agent-D0zZnGbt.js.map +0 -1
- package/dist/anthropic-C2aole0G.js.map +0 -1
- package/dist/approvals-DKaJZYlm.js.map +0 -1
- package/dist/atomic-write-B7zr1ddF.js.map +0 -1
- package/dist/auth-BG2rVKSt.js.map +0 -1
- package/dist/completion-core-BRo86R_L.js.map +0 -1
- package/dist/contexts/daytona.js.map +0 -1
- package/dist/contexts/docker.js.map +0 -1
- package/dist/contexts/e2b.js.map +0 -1
- package/dist/contexts-CRE9pw07.js.map +0 -1
- package/dist/eval.js.map +0 -1
- package/dist/format-BF745pLL.js.map +0 -1
- package/dist/glob-DluQFSw1.js +0 -270
- package/dist/glob-DluQFSw1.js.map +0 -1
- package/dist/headless.js.map +0 -1
- package/dist/history-search-C4bk1Wz_.js.map +0 -1
- package/dist/index-BgN1T3lk.d.ts.map +0 -1
- package/dist/index-C37_ppWv.d.ts.map +0 -1
- package/dist/index-C6NEd5y_.d.ts.map +0 -1
- package/dist/ipc-BKVIIOqH.js +0 -331
- package/dist/ipc-BKVIIOqH.js.map +0 -1
- package/dist/ipc.d.ts.map +0 -1
- package/dist/isolation-Kfoof0MM.d.ts.map +0 -1
- package/dist/json-rpc-rSWMUh9b.js +0 -192
- package/dist/json-rpc-rSWMUh9b.js.map +0 -1
- package/dist/logger--C1VQjwJ.js.map +0 -1
- package/dist/mcp-CgNd-f3F.js.map +0 -1
- package/dist/messages-2jcOA_5R.js.map +0 -1
- package/dist/openai-compat-Dy56weK8.js.map +0 -1
- package/dist/output-cap-C9zukcCj.js +0 -100
- package/dist/output-cap-C9zukcCj.js.map +0 -1
- package/dist/panels-B6gRk4bf.js +0 -789
- package/dist/panels-B6gRk4bf.js.map +0 -1
- package/dist/plugins-gbI7SBA6.js.map +0 -1
- package/dist/prompts-Pqc3JdW_.d.ts.map +0 -1
- package/dist/run-summary-BU_NgwUT.js +0 -269
- package/dist/run-summary-BU_NgwUT.js.map +0 -1
- package/dist/sandbox-BH0WQkXn.d.ts.map +0 -1
- package/dist/session/sqlite.js.map +0 -1
- package/dist/session-BqRP1hS7.js.map +0 -1
- package/dist/shell-path-DfdXrGg9.js +0 -1549
- package/dist/shell-path-DfdXrGg9.js.map +0 -1
- package/dist/skills-BC3dodWp.js.map +0 -1
- package/dist/src-CkNQKFKr.js.map +0 -1
- package/dist/todo-edits-UOwgxGKu.js +0 -528
- package/dist/todo-edits-UOwgxGKu.js.map +0 -1
- package/dist/tool-formatters-DoRLnfuD.d.ts +0 -759
- package/dist/tool-formatters-DoRLnfuD.d.ts.map +0 -1
- package/dist/transcript-anchors-BeudMbXx.d.ts +0 -1762
- package/dist/transcript-anchors-BeudMbXx.d.ts.map +0 -1
- package/dist/turn-operations-C8bMBDl_.d.ts +0 -1258
- package/dist/turn-operations-C8bMBDl_.d.ts.map +0 -1
- package/dist/turn-operations-DrbJlpq9.js.map +0 -1
- package/dist/types-CWgENVLY.js.map +0 -1
- package/dist/xai-CazjStOK.js.map +0 -1
|
@@ -0,0 +1,621 @@
|
|
|
1
|
+
import { t as resolveStorageDirs } from "./xdg-zweed0-t.js";
|
|
2
|
+
import { t as createProcessContext } from "./contexts-d7UolYot.js";
|
|
3
|
+
import { Qt as MACHINE_STREAM_CHUNK_BYTES } from "./tool-formatters-IQFDrdrs.js";
|
|
4
|
+
import { _ as workspacePath } from "./environment-8wsKE2Ln.js";
|
|
5
|
+
import { Xt as resolveSandboxForRoots, Zt as sandboxUnreadableDirs, fn as createWorkspaceConfinement, nr as teardownWorktree, pn as isInside, tr as prepareWorktree } from "./chat-JPJJ8uu5.js";
|
|
6
|
+
import { Buffer } from "node:buffer";
|
|
7
|
+
import { chmodSync, closeSync, constants, fstatSync, lstatSync, mkdirSync, openSync, readFileSync, realpathSync, statSync } from "node:fs";
|
|
8
|
+
import { isAbsolute, join, resolve } from "node:path";
|
|
9
|
+
import { homedir } from "node:os";
|
|
10
|
+
//#region src/ipc/machine/params.ts
|
|
11
|
+
function paramsOf(value) {
|
|
12
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("Invalid params: expected an object.");
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
function str(params, key) {
|
|
16
|
+
const value = params[key];
|
|
17
|
+
if (typeof value !== "string") throw new Error(`Invalid params: "${key}" must be a string.`);
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
function optStr(params, key) {
|
|
21
|
+
const value = params[key];
|
|
22
|
+
if (value === void 0) return void 0;
|
|
23
|
+
if (typeof value !== "string") throw new Error(`Invalid params: "${key}" must be a string.`);
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
function optNum(params, key) {
|
|
27
|
+
const value = params[key];
|
|
28
|
+
if (value === void 0) return void 0;
|
|
29
|
+
if (typeof value !== "number" || !Number.isFinite(value)) throw new Error(`Invalid params: "${key}" must be a number.`);
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
function num(params, key) {
|
|
33
|
+
const value = optNum(params, key);
|
|
34
|
+
if (value === void 0) throw new Error(`Invalid params: "${key}" must be a number.`);
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
37
|
+
function optEnv(params, key) {
|
|
38
|
+
const value = params[key];
|
|
39
|
+
if (value === void 0) return void 0;
|
|
40
|
+
if (!value || typeof value !== "object" || Array.isArray(value) || Object.values(value).some((v) => typeof v !== "string")) throw new Error(`Invalid params: "${key}" must map names to strings.`);
|
|
41
|
+
return value;
|
|
42
|
+
}
|
|
43
|
+
function handleRef(params) {
|
|
44
|
+
const handle = params.handle;
|
|
45
|
+
if (!handle || typeof handle.id !== "string" || typeof handle.cwd !== "string" || handle.id.length > 200) throw new Error("Invalid params: \"handle\" must be { id, cwd }.");
|
|
46
|
+
return {
|
|
47
|
+
id: handle.id,
|
|
48
|
+
cwd: handle.cwd
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/ipc/machine/streams.ts
|
|
53
|
+
function createMachineStreams(options) {
|
|
54
|
+
const streams = /* @__PURE__ */ new Map();
|
|
55
|
+
async function pump(callId, name, source) {
|
|
56
|
+
if (!source) return;
|
|
57
|
+
for await (const chunk of source) for (let at = 0; at < chunk.byteLength; at += MACHINE_STREAM_CHUNK_BYTES) {
|
|
58
|
+
const data = Buffer.from(chunk.subarray(at, at + MACHINE_STREAM_CHUNK_BYTES)).toString("base64");
|
|
59
|
+
if (!options.send("exec.stream.data", {
|
|
60
|
+
callId,
|
|
61
|
+
stream: name,
|
|
62
|
+
data
|
|
63
|
+
})) streams.get(callId)?.kill();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const kill = (callId) => {
|
|
67
|
+
const stream = streams.get(callId);
|
|
68
|
+
if (!stream) return false;
|
|
69
|
+
stream.kill().catch(() => void 0);
|
|
70
|
+
return true;
|
|
71
|
+
};
|
|
72
|
+
return {
|
|
73
|
+
async start(context, handle, { callId, command, cwd, env }) {
|
|
74
|
+
if (!context.execStream) throw new Error("This machine cannot stream processes.");
|
|
75
|
+
if (streams.has(callId)) throw new Error(`A stream "${callId}" already runs.`);
|
|
76
|
+
if (streams.size >= 16) throw new Error(`This machine already runs 16 live processes.`);
|
|
77
|
+
const stream = await context.execStream(handle, command, {
|
|
78
|
+
...cwd ? { cwd } : {},
|
|
79
|
+
...env ? { env } : {}
|
|
80
|
+
});
|
|
81
|
+
streams.set(callId, stream);
|
|
82
|
+
Promise.all([
|
|
83
|
+
pump(callId, "stdout", stream.stdout),
|
|
84
|
+
pump(callId, "stderr", stream.stderr),
|
|
85
|
+
stream.exited
|
|
86
|
+
]).catch(() => void 0).then(async () => {
|
|
87
|
+
const code = await stream.exited;
|
|
88
|
+
streams.delete(callId);
|
|
89
|
+
options.send("exec.stream.exit", {
|
|
90
|
+
callId,
|
|
91
|
+
code
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
return { pid: stream.pid };
|
|
95
|
+
},
|
|
96
|
+
async write(callId, data) {
|
|
97
|
+
const stream = streams.get(callId);
|
|
98
|
+
if (!stream) throw new Error(`No live process "${callId}" on this machine.`);
|
|
99
|
+
const bytes = Buffer.from(data, "base64");
|
|
100
|
+
if (bytes.byteLength > 262144) throw new Error(`exec.stream.write: at most ${MACHINE_STREAM_CHUNK_BYTES} bytes per call.`);
|
|
101
|
+
await stream.write(bytes);
|
|
102
|
+
},
|
|
103
|
+
kill,
|
|
104
|
+
linkLost() {
|
|
105
|
+
for (const callId of streams.keys()) kill(callId);
|
|
106
|
+
},
|
|
107
|
+
async closeAll() {
|
|
108
|
+
const all = [...streams.values()];
|
|
109
|
+
streams.clear();
|
|
110
|
+
await Promise.all(all.map((stream) => stream.kill().catch(() => void 0)));
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
//#endregion
|
|
115
|
+
//#region src/ipc/machine/task-logs.ts
|
|
116
|
+
/**
|
|
117
|
+
* The machine's background-task logs (`<data dir>/tasks/`): the one place in
|
|
118
|
+
* its data dir the host may read, and only the logs of tasks this machine
|
|
119
|
+
* started. A command run for the host can reach that folder (no sandbox, or
|
|
120
|
+
* a sandbox that allows the data dir's parent), so a log path is never
|
|
121
|
+
* trusted as a path: it is opened without following a symlink, must be a
|
|
122
|
+
* regular file, and its real path must be the same file inside the tasks
|
|
123
|
+
* dir. Otherwise `ln -sf ~/.zidane/credentials.json <log>` would make the
|
|
124
|
+
* (unsandboxed) machine process read anything for the host.
|
|
125
|
+
*/
|
|
126
|
+
const NO_FOLLOW = constants.O_NOFOLLOW ?? 0;
|
|
127
|
+
/** `path` made (or kept) an owner-only real folder; a symlink there is refused, never followed. */
|
|
128
|
+
function ownerOnlyDir(path) {
|
|
129
|
+
mkdirSync(path, {
|
|
130
|
+
recursive: true,
|
|
131
|
+
mode: 448
|
|
132
|
+
});
|
|
133
|
+
const stat = lstatSync(path);
|
|
134
|
+
if (!stat.isDirectory() || stat.isSymbolicLink()) throw new Error(`${path} is not a folder of this machine's task logs.`);
|
|
135
|
+
chmodSync(path, 448);
|
|
136
|
+
}
|
|
137
|
+
function createTaskLogs(dataDir) {
|
|
138
|
+
const dir = join(dataDir, "tasks");
|
|
139
|
+
ownerOnlyDir(dir);
|
|
140
|
+
const realDir = realpathSync.native(dir);
|
|
141
|
+
const known = /* @__PURE__ */ new Set();
|
|
142
|
+
const refused = (path) => /* @__PURE__ */ new Error(`${path} is not a task log of this machine.`);
|
|
143
|
+
/** An fd on the log at `path`, checked as the module header says; the caller closes it. */
|
|
144
|
+
const open = (path) => {
|
|
145
|
+
let fd;
|
|
146
|
+
try {
|
|
147
|
+
fd = openSync(path, constants.O_RDONLY | NO_FOLLOW);
|
|
148
|
+
} catch {
|
|
149
|
+
throw refused(path);
|
|
150
|
+
}
|
|
151
|
+
try {
|
|
152
|
+
const opened = fstatSync(fd);
|
|
153
|
+
const real = realpathSync.native(path);
|
|
154
|
+
const named = statSync(real);
|
|
155
|
+
if (!opened.isFile() || !isInside(realDir, real) || named.ino !== opened.ino || named.dev !== opened.dev) throw refused(path);
|
|
156
|
+
return fd;
|
|
157
|
+
} catch {
|
|
158
|
+
closeSync(fd);
|
|
159
|
+
throw refused(path);
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
const withLog = (path, fn) => {
|
|
163
|
+
const fd = open(path);
|
|
164
|
+
try {
|
|
165
|
+
return fn(fd);
|
|
166
|
+
} finally {
|
|
167
|
+
closeSync(fd);
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
return {
|
|
171
|
+
outputDir(handleId) {
|
|
172
|
+
const path = join(dir, Buffer.from(handleId).toString("hex").slice(0, 64));
|
|
173
|
+
ownerOnlyDir(path);
|
|
174
|
+
if (!isInside(realDir, realpathSync.native(path))) throw new Error(`${path} is not a folder of this machine's task logs.`);
|
|
175
|
+
return path;
|
|
176
|
+
},
|
|
177
|
+
add: (path) => void known.add(path),
|
|
178
|
+
has: (path) => known.has(path),
|
|
179
|
+
count: () => known.size,
|
|
180
|
+
read: (path, binary) => withLog(path, (fd) => binary ? readFileSync(fd).toString("base64") : readFileSync(fd, "utf8")),
|
|
181
|
+
size: (path) => withLog(path, (fd) => fstatSync(fd).size)
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
function createMachineTerminals(options) {
|
|
185
|
+
const terminals = /* @__PURE__ */ new Map();
|
|
186
|
+
const graceMs = options.graceMs ?? 3e5;
|
|
187
|
+
const entry = (terminalId) => {
|
|
188
|
+
const found = terminals.get(terminalId);
|
|
189
|
+
if (!found) throw new Error(`No terminal "${terminalId}" on this machine.`);
|
|
190
|
+
return found;
|
|
191
|
+
};
|
|
192
|
+
const remember = (e, data) => {
|
|
193
|
+
e.backlog.push(Buffer.from(data));
|
|
194
|
+
e.backlogBytes += data.byteLength;
|
|
195
|
+
e.total += data.byteLength;
|
|
196
|
+
while (e.backlogBytes > 262144 && e.backlog.length > 1) e.backlogBytes -= e.backlog.shift().byteLength;
|
|
197
|
+
};
|
|
198
|
+
const kill = async (terminalId) => {
|
|
199
|
+
const e = terminals.get(terminalId);
|
|
200
|
+
if (!e) return;
|
|
201
|
+
terminals.delete(terminalId);
|
|
202
|
+
clearTimeout(e.graceTimer);
|
|
203
|
+
await e.process.kill().catch(() => void 0);
|
|
204
|
+
};
|
|
205
|
+
return {
|
|
206
|
+
async open(context, handle, { cols, rows, cwd }) {
|
|
207
|
+
if (!context.openTerminal) throw new Error("This machine has no terminal support (it needs Bun).");
|
|
208
|
+
if (terminals.size >= 16) throw new Error(`This machine already runs 16 terminals.`);
|
|
209
|
+
const holder = {};
|
|
210
|
+
const pending = [];
|
|
211
|
+
const process = await context.openTerminal(handle, {
|
|
212
|
+
cols,
|
|
213
|
+
rows,
|
|
214
|
+
...cwd ? { cwd } : {},
|
|
215
|
+
onData: (data) => {
|
|
216
|
+
const e = holder.id ? terminals.get(holder.id) : void 0;
|
|
217
|
+
if (!e) {
|
|
218
|
+
pending.push(data);
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
remember(e, data);
|
|
222
|
+
options.send("terminal.data", {
|
|
223
|
+
terminalId: holder.id,
|
|
224
|
+
data: Buffer.from(data).toString("base64")
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
holder.id = process.id;
|
|
229
|
+
const e = {
|
|
230
|
+
process,
|
|
231
|
+
backlog: [],
|
|
232
|
+
backlogBytes: 0,
|
|
233
|
+
total: 0
|
|
234
|
+
};
|
|
235
|
+
terminals.set(process.id, e);
|
|
236
|
+
for (const data of pending) remember(e, data);
|
|
237
|
+
process.exited.then((code) => {
|
|
238
|
+
if (terminals.get(process.id) !== e) return;
|
|
239
|
+
terminals.delete(process.id);
|
|
240
|
+
clearTimeout(e.graceTimer);
|
|
241
|
+
options.send("terminal.exit", {
|
|
242
|
+
terminalId: process.id,
|
|
243
|
+
code
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
return process.id;
|
|
247
|
+
},
|
|
248
|
+
attach(terminalId) {
|
|
249
|
+
const e = terminals.get(terminalId);
|
|
250
|
+
if (!e) return {
|
|
251
|
+
attached: false,
|
|
252
|
+
backlog: "",
|
|
253
|
+
total: 0
|
|
254
|
+
};
|
|
255
|
+
clearTimeout(e.graceTimer);
|
|
256
|
+
e.graceTimer = void 0;
|
|
257
|
+
return {
|
|
258
|
+
attached: true,
|
|
259
|
+
backlog: Buffer.concat(e.backlog).toString("base64"),
|
|
260
|
+
total: e.total
|
|
261
|
+
};
|
|
262
|
+
},
|
|
263
|
+
write: (terminalId, data) => entry(terminalId).process.write(Buffer.from(data, "base64")),
|
|
264
|
+
resize: (terminalId, cols, rows) => entry(terminalId).process.resize(cols, rows),
|
|
265
|
+
kill,
|
|
266
|
+
linkLost() {
|
|
267
|
+
for (const [id, e] of terminals) {
|
|
268
|
+
clearTimeout(e.graceTimer);
|
|
269
|
+
e.graceTimer = setTimeout(() => void kill(id), graceMs);
|
|
270
|
+
e.graceTimer.unref?.();
|
|
271
|
+
}
|
|
272
|
+
},
|
|
273
|
+
async closeAll() {
|
|
274
|
+
await Promise.all([...terminals.keys()].map(kill));
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
const MACHINE_TASK_OUTPUT_BYTES = 8388608;
|
|
279
|
+
const MAX_PENDING_EXITS = 256;
|
|
280
|
+
const GLOB_CHARS = /[*?[\]{}]/;
|
|
281
|
+
/**
|
|
282
|
+
* What file operations never reach, whatever the roots (`docs/MACHINES.md` §
|
|
283
|
+
* Security model): zidane's own folders as this process resolves them (data,
|
|
284
|
+
* config, state, cache: credentials, tokens, extensions, plugins, skills,
|
|
285
|
+
* mcps.json, SYSTEM.md, the machine's data, sync files), the default
|
|
286
|
+
* `~/.zidane`, the given data dir (a server's `--data-dir`), and the
|
|
287
|
+
* credential folders the sandbox hides (`~/.ssh`, `~/.aws`, …).
|
|
288
|
+
*/
|
|
289
|
+
function machinePrivateDirs(zidaneDataDir) {
|
|
290
|
+
const storage = resolveStorageDirs();
|
|
291
|
+
return [.../* @__PURE__ */ new Set([
|
|
292
|
+
...zidaneDataDir ? [zidaneDataDir] : [],
|
|
293
|
+
storage.dataDir,
|
|
294
|
+
storage.configDir,
|
|
295
|
+
storage.stateDir,
|
|
296
|
+
storage.cacheDir,
|
|
297
|
+
join(homedir(), ".zidane"),
|
|
298
|
+
...sandboxUnreadableDirs(zidaneDataDir)
|
|
299
|
+
])];
|
|
300
|
+
}
|
|
301
|
+
/** The static directory of a glob (`/a/b/**\/*.ts` → `/a/b`). */
|
|
302
|
+
function globBase(path) {
|
|
303
|
+
const segments = path.split("/");
|
|
304
|
+
const index = segments.findIndex((s) => GLOB_CHARS.test(s));
|
|
305
|
+
return index < 0 ? path : segments.slice(0, index).join("/") || "/";
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* A folder a user offers to share (`zidane machine share --root`, a share
|
|
309
|
+
* link): its real path must exist and not be, or be inside, a private
|
|
310
|
+
* folder (a root there would lend what {@link machinePrivateDirs} keeps out).
|
|
311
|
+
* Returns the real path.
|
|
312
|
+
*/
|
|
313
|
+
function shareableRoot(root, zidaneDataDir) {
|
|
314
|
+
let real;
|
|
315
|
+
try {
|
|
316
|
+
real = realpathSync.native(root);
|
|
317
|
+
} catch {
|
|
318
|
+
throw new Error(`${root} does not exist.`);
|
|
319
|
+
}
|
|
320
|
+
const hidden = machinePrivateDirs(zidaneDataDir).map(realPathOr).find((dir) => isInside(dir, real));
|
|
321
|
+
if (hidden) throw new Error(`${root} is inside ${hidden} (zidane's own data or credentials): share a folder outside it.`);
|
|
322
|
+
return real;
|
|
323
|
+
}
|
|
324
|
+
function realPathOr(path) {
|
|
325
|
+
try {
|
|
326
|
+
return realpathSync.native(path);
|
|
327
|
+
} catch {
|
|
328
|
+
return path;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
function machineConfinement(roots, dataDir, privateDirs = []) {
|
|
332
|
+
const worktrees = join(dataDir, "worktrees");
|
|
333
|
+
mkdirSync(worktrees, { recursive: true });
|
|
334
|
+
return createWorkspaceConfinement([...roots.map((root) => root.path), worktrees], {
|
|
335
|
+
dataDir,
|
|
336
|
+
privateDirs,
|
|
337
|
+
names: {
|
|
338
|
+
roots: "the machine's roots",
|
|
339
|
+
dataDir: "the machine's data dir, which the host can't reach"
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* A listing's entries whose real path is reachable: a traversal can follow a
|
|
345
|
+
* symlinked folder out of the roots, or walk into a private one, from a base
|
|
346
|
+
* that passed the check.
|
|
347
|
+
*/
|
|
348
|
+
function reachableEntries(confinement, base, entries) {
|
|
349
|
+
return entries.filter((entry) => {
|
|
350
|
+
const path = typeof entry === "string" ? entry : entry.path;
|
|
351
|
+
if (typeof path !== "string") return false;
|
|
352
|
+
try {
|
|
353
|
+
confinement.checkPath(isAbsolute(path) ? path : resolve(base, path));
|
|
354
|
+
return true;
|
|
355
|
+
} catch {
|
|
356
|
+
return false;
|
|
357
|
+
}
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
/** `fs.list`: a path or glob under the handle's cwd, no `..` in a pattern, only reachable entries back. */
|
|
361
|
+
async function listReachable(context, confinement, handle, params) {
|
|
362
|
+
const pattern = str(params, "path");
|
|
363
|
+
if (GLOB_CHARS.test(pattern) && pattern.split(/[/\\]/).includes("..")) throw new Error(`"${pattern}": a pattern can't climb with "..".`);
|
|
364
|
+
const path = workspacePath(handle.cwd, pattern);
|
|
365
|
+
confinement.checkPath(globBase(path));
|
|
366
|
+
const raw = params.options && typeof params.options === "object" ? params.options : {};
|
|
367
|
+
const listOptions = {
|
|
368
|
+
...typeof raw.glob === "boolean" ? { glob: raw.glob } : {},
|
|
369
|
+
...typeof raw.limit === "number" ? { limit: raw.limit } : {},
|
|
370
|
+
...typeof raw.metadata === "boolean" ? { metadata: raw.metadata } : {},
|
|
371
|
+
...typeof raw.gitignore === "boolean" ? { gitignore: raw.gitignore } : {}
|
|
372
|
+
};
|
|
373
|
+
return reachableEntries(confinement, globBase(path), await context.listFiles(handle, path, listOptions));
|
|
374
|
+
}
|
|
375
|
+
/** One process context for every handle, under the machine user's own sandbox when it is on. */
|
|
376
|
+
function sandboxedContext(options, confinement) {
|
|
377
|
+
const sandbox = resolveSandboxForRoots(options.sandbox ?? { sandbox: false }, confinement.roots, { ...options.credentialsDataDir ? { dataDir: options.credentialsDataDir } : {} });
|
|
378
|
+
return {
|
|
379
|
+
sandbox,
|
|
380
|
+
context: createProcessContext({
|
|
381
|
+
cwd: confinement.roots[0],
|
|
382
|
+
...sandbox.isolation ? { isolation: sandbox.isolation } : {}
|
|
383
|
+
})
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
function createMachineExecutor(options) {
|
|
387
|
+
const confinement = machineConfinement(options.roots, options.dataDir, machinePrivateDirs(options.credentialsDataDir));
|
|
388
|
+
const { sandbox, context } = sandboxedContext(options, confinement);
|
|
389
|
+
const handles = /* @__PURE__ */ new Map();
|
|
390
|
+
const calls = /* @__PURE__ */ new Map();
|
|
391
|
+
const taskLogs = createTaskLogs(options.dataDir);
|
|
392
|
+
const pendingExits = [];
|
|
393
|
+
const terminals = createMachineTerminals({
|
|
394
|
+
send: options.notify,
|
|
395
|
+
...options.terminalGraceMs !== void 0 ? { graceMs: options.terminalGraceMs } : {}
|
|
396
|
+
});
|
|
397
|
+
const streams = createMachineStreams({ send: options.notify });
|
|
398
|
+
/** A handle's cwd, checked on every call (not only at spawn): the host names it each time. */
|
|
399
|
+
async function handleFor(params) {
|
|
400
|
+
const ref = handleRef(params);
|
|
401
|
+
const cwd = confinement.resolveFolder(ref.cwd);
|
|
402
|
+
const existing = handles.get(ref.id);
|
|
403
|
+
if (existing && existing.cwd === cwd) return existing;
|
|
404
|
+
const handle = await context.spawn({ cwd });
|
|
405
|
+
handles.set(ref.id, handle);
|
|
406
|
+
if (existing) await context.destroy(existing).catch(() => void 0);
|
|
407
|
+
return handle;
|
|
408
|
+
}
|
|
409
|
+
/** `path` resolved like the context resolves it, then confined. */
|
|
410
|
+
function checked(handle, path) {
|
|
411
|
+
const absolute = workspacePath(handle.cwd, path);
|
|
412
|
+
confinement.checkPath(absolute);
|
|
413
|
+
return absolute;
|
|
414
|
+
}
|
|
415
|
+
/** A log of a task this machine started, by its path (never through the context: see `./task-logs.ts`). */
|
|
416
|
+
const taskLog = (handle, path) => {
|
|
417
|
+
const absolute = workspacePath(handle.cwd, path);
|
|
418
|
+
return taskLogs.has(absolute) ? absolute : void 0;
|
|
419
|
+
};
|
|
420
|
+
const cwdOption = (handle, params) => {
|
|
421
|
+
const cwd = optStr(params, "cwd");
|
|
422
|
+
return cwd === void 0 ? {} : { cwd: confinement.resolveFolder(workspacePath(handle.cwd, cwd)) };
|
|
423
|
+
};
|
|
424
|
+
const sendExit = (exit) => {
|
|
425
|
+
if (options.notify("task.exit", exit)) return;
|
|
426
|
+
pendingExits.push(exit);
|
|
427
|
+
if (pendingExits.length > MAX_PENDING_EXITS) pendingExits.shift();
|
|
428
|
+
};
|
|
429
|
+
const methods = {
|
|
430
|
+
"machine.ping": async () => ({ ok: true }),
|
|
431
|
+
"exec.spawn": async (params) => {
|
|
432
|
+
const handle = await handleFor(params);
|
|
433
|
+
return {
|
|
434
|
+
id: handleRef(params).id,
|
|
435
|
+
cwd: handle.cwd
|
|
436
|
+
};
|
|
437
|
+
},
|
|
438
|
+
"exec.run": async (params) => {
|
|
439
|
+
const handle = await handleFor(params);
|
|
440
|
+
const callId = str(params, "callId");
|
|
441
|
+
if (calls.has(callId)) throw new Error(`A call "${callId}" is already running.`);
|
|
442
|
+
const controller = new AbortController();
|
|
443
|
+
calls.set(callId, controller);
|
|
444
|
+
try {
|
|
445
|
+
const env = optEnv(params, "env");
|
|
446
|
+
const timeout = optNum(params, "timeout");
|
|
447
|
+
return await context.exec(handle, str(params, "command"), {
|
|
448
|
+
...cwdOption(handle, params),
|
|
449
|
+
...env ? { env } : {},
|
|
450
|
+
...timeout !== void 0 ? { timeout } : {},
|
|
451
|
+
signal: controller.signal
|
|
452
|
+
});
|
|
453
|
+
} finally {
|
|
454
|
+
calls.delete(callId);
|
|
455
|
+
}
|
|
456
|
+
},
|
|
457
|
+
"exec.cancel": async (params) => {
|
|
458
|
+
const callId = str(params, "callId");
|
|
459
|
+
const controller = calls.get(callId);
|
|
460
|
+
controller?.abort();
|
|
461
|
+
return { cancelled: controller !== void 0 || streams.kill(callId) };
|
|
462
|
+
},
|
|
463
|
+
"exec.stream": async (params) => {
|
|
464
|
+
const handle = await handleFor(params);
|
|
465
|
+
const env = optEnv(params, "env");
|
|
466
|
+
return streams.start(context, handle, {
|
|
467
|
+
callId: str(params, "callId"),
|
|
468
|
+
command: str(params, "command"),
|
|
469
|
+
...cwdOption(handle, params),
|
|
470
|
+
...env ? { env } : {}
|
|
471
|
+
});
|
|
472
|
+
},
|
|
473
|
+
"exec.stream.write": async (params) => {
|
|
474
|
+
await streams.write(str(params, "callId"), str(params, "data"));
|
|
475
|
+
return { ok: true };
|
|
476
|
+
},
|
|
477
|
+
"exec.destroy": async (params) => {
|
|
478
|
+
const ref = handleRef(params);
|
|
479
|
+
const handle = handles.get(ref.id);
|
|
480
|
+
handles.delete(ref.id);
|
|
481
|
+
if (handle) await context.destroy(handle);
|
|
482
|
+
return { ok: true };
|
|
483
|
+
},
|
|
484
|
+
"fs.read": async (params) => {
|
|
485
|
+
const handle = await handleFor(params);
|
|
486
|
+
const log = taskLog(handle, str(params, "path"));
|
|
487
|
+
if (log) return { content: taskLogs.read(log, params.binary === true) };
|
|
488
|
+
const path = checked(handle, str(params, "path"));
|
|
489
|
+
if (params.binary === true) return { content: Buffer.from(await context.readFileBinary(handle, path)).toString("base64") };
|
|
490
|
+
return { content: await context.readFile(handle, path) };
|
|
491
|
+
},
|
|
492
|
+
"fs.write": async (params) => {
|
|
493
|
+
const handle = await handleFor(params);
|
|
494
|
+
await context.writeFile(handle, checked(handle, str(params, "path")), Buffer.from(str(params, "content"), "base64"));
|
|
495
|
+
return { ok: true };
|
|
496
|
+
},
|
|
497
|
+
"fs.list": async (params) => ({ entries: await listReachable(context, confinement, await handleFor(params), params) }),
|
|
498
|
+
"fs.size": async (params) => {
|
|
499
|
+
const handle = await handleFor(params);
|
|
500
|
+
const log = taskLog(handle, str(params, "path"));
|
|
501
|
+
return { size: log ? taskLogs.size(log) : await context.fileSize(handle, checked(handle, str(params, "path"))) };
|
|
502
|
+
},
|
|
503
|
+
"bg.start": async (params) => {
|
|
504
|
+
const handle = await handleFor(params);
|
|
505
|
+
const running = (await context.listBackground(handle)).filter((t) => t.status === "running").length;
|
|
506
|
+
if (taskLogs.count() >= 256 || running >= 64) throw new Error(`This machine already runs 64 background tasks.`);
|
|
507
|
+
const env = optEnv(params, "env");
|
|
508
|
+
const cap = optNum(params, "maxOutputBytes");
|
|
509
|
+
const task = await context.execBackground(handle, str(params, "command"), {
|
|
510
|
+
...cwdOption(handle, params),
|
|
511
|
+
...env ? { env } : {},
|
|
512
|
+
outputDir: taskLogs.outputDir(handleRef(params).id),
|
|
513
|
+
maxOutputBytes: Math.min(cap && cap > 0 ? cap : MACHINE_TASK_OUTPUT_BYTES, MACHINE_TASK_OUTPUT_BYTES),
|
|
514
|
+
onExit: (info) => sendExit({
|
|
515
|
+
taskId: info.taskId,
|
|
516
|
+
exit: { ...info }
|
|
517
|
+
})
|
|
518
|
+
});
|
|
519
|
+
taskLogs.add(task.outputPath);
|
|
520
|
+
return {
|
|
521
|
+
taskId: task.taskId,
|
|
522
|
+
pid: task.pid,
|
|
523
|
+
outputPath: task.outputPath
|
|
524
|
+
};
|
|
525
|
+
},
|
|
526
|
+
"bg.list": async (params) => ({ tasks: await context.listBackground(await handleFor(params)) }),
|
|
527
|
+
"bg.kill": async (params) => ({ exit: await context.killBackground(await handleFor(params), str(params, "taskId")) }),
|
|
528
|
+
"bg.wait": async (params) => {
|
|
529
|
+
const timeoutMs = optNum(params, "timeoutMs");
|
|
530
|
+
return { exit: await context.waitBackground(await handleFor(params), str(params, "taskId"), timeoutMs !== void 0 ? { timeoutMs } : {}) };
|
|
531
|
+
},
|
|
532
|
+
"terminal.open": async (params) => {
|
|
533
|
+
const handle = await handleFor(params);
|
|
534
|
+
return { terminalId: await terminals.open(context, handle, {
|
|
535
|
+
cols: num(params, "cols"),
|
|
536
|
+
rows: num(params, "rows"),
|
|
537
|
+
...cwdOption(handle, params)
|
|
538
|
+
}) };
|
|
539
|
+
},
|
|
540
|
+
"terminal.attach": async (params) => terminals.attach(str(params, "terminalId")),
|
|
541
|
+
"terminal.write": async (params) => {
|
|
542
|
+
terminals.write(str(params, "terminalId"), str(params, "data"));
|
|
543
|
+
return { ok: true };
|
|
544
|
+
},
|
|
545
|
+
"terminal.resize": async (params) => {
|
|
546
|
+
terminals.resize(str(params, "terminalId"), num(params, "cols"), num(params, "rows"));
|
|
547
|
+
return { ok: true };
|
|
548
|
+
},
|
|
549
|
+
"terminal.kill": async (params) => {
|
|
550
|
+
await terminals.kill(str(params, "terminalId"));
|
|
551
|
+
return { ok: true };
|
|
552
|
+
},
|
|
553
|
+
"terminal.detach": async () => ({ ok: true }),
|
|
554
|
+
"env.checkFolder": async (params) => ({ cwd: confinement.resolveFolder(str(params, "cwd")) }),
|
|
555
|
+
"env.prepareWorktree": async (params) => {
|
|
556
|
+
const cwd = confinement.resolveFolder(str(params, "cwd"));
|
|
557
|
+
const config = params.config && typeof params.config === "object" ? params.config : {};
|
|
558
|
+
const base = optStr(params, "base");
|
|
559
|
+
const prepared = await prepareWorktree({
|
|
560
|
+
cwd,
|
|
561
|
+
environment: {
|
|
562
|
+
kind: "worktree",
|
|
563
|
+
state: "provisioning",
|
|
564
|
+
branch: str(params, "branch"),
|
|
565
|
+
...base ? { base } : {}
|
|
566
|
+
},
|
|
567
|
+
config
|
|
568
|
+
}, options.dataDir);
|
|
569
|
+
const ref = prepared.environment?.ref;
|
|
570
|
+
confinement.resolveFolder(ref.path);
|
|
571
|
+
return {
|
|
572
|
+
cwd: prepared.cwd ?? ref.path,
|
|
573
|
+
branch: prepared.environment?.branch,
|
|
574
|
+
base: prepared.environment?.base,
|
|
575
|
+
ref
|
|
576
|
+
};
|
|
577
|
+
},
|
|
578
|
+
"env.teardownWorktree": async (params) => {
|
|
579
|
+
const ref = params.ref ?? {};
|
|
580
|
+
if (typeof ref.path !== "string" || typeof ref.repoRoot !== "string") throw new Error("Invalid params: \"ref\" must be { path, repoRoot }.");
|
|
581
|
+
confinement.checkPath(ref.path);
|
|
582
|
+
confinement.resolveFolder(ref.repoRoot);
|
|
583
|
+
const config = params.config && typeof params.config === "object" ? params.config : {};
|
|
584
|
+
return teardownWorktree({
|
|
585
|
+
path: ref.path,
|
|
586
|
+
repoRoot: ref.repoRoot
|
|
587
|
+
}, optStr(params, "branch"), config);
|
|
588
|
+
}
|
|
589
|
+
};
|
|
590
|
+
return {
|
|
591
|
+
async handle(method, raw) {
|
|
592
|
+
if (!Object.hasOwn(methods, method)) throw new Error(`Unknown machine method "${method}".`);
|
|
593
|
+
return methods[method](paramsOf(raw));
|
|
594
|
+
},
|
|
595
|
+
linkUp() {
|
|
596
|
+
while (pendingExits.length > 0) {
|
|
597
|
+
if (!options.notify("task.exit", pendingExits[0])) return;
|
|
598
|
+
pendingExits.shift();
|
|
599
|
+
}
|
|
600
|
+
},
|
|
601
|
+
sandbox: {
|
|
602
|
+
on: sandbox.isolation !== void 0,
|
|
603
|
+
...sandbox.warning ? { warning: sandbox.warning } : {}
|
|
604
|
+
},
|
|
605
|
+
linkLost: () => {
|
|
606
|
+
terminals.linkLost();
|
|
607
|
+
streams.linkLost();
|
|
608
|
+
},
|
|
609
|
+
async close() {
|
|
610
|
+
for (const controller of calls.values()) controller.abort();
|
|
611
|
+
await streams.closeAll();
|
|
612
|
+
await terminals.closeAll();
|
|
613
|
+
await Promise.all([...handles.values()].map((handle) => context.destroy(handle).catch(() => void 0)));
|
|
614
|
+
handles.clear();
|
|
615
|
+
}
|
|
616
|
+
};
|
|
617
|
+
}
|
|
618
|
+
//#endregion
|
|
619
|
+
export { createMachineExecutor, shareableRoot };
|
|
620
|
+
|
|
621
|
+
//# sourceMappingURL=executor-Cx5-8yqi.js.map
|