scope-agent-workbench 0.0.0-stage → 0.2.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 +18 -0
- package/LICENSE +21 -0
- package/README.md +174 -2
- package/README.zh-CN.md +175 -0
- package/bin/scope.mjs +111 -0
- package/bridge/account-quotas.mjs +881 -0
- package/bridge/agent-email-relay.mjs +160 -0
- package/bridge/app-server-client.mjs +2522 -0
- package/bridge/app-server-websocket-transport.mjs +219 -0
- package/bridge/archive/routes.mjs +19 -0
- package/bridge/archive/service.mjs +130 -0
- package/bridge/archive/thread-lifecycle.mjs +52 -0
- package/bridge/attachment-store.mjs +184 -0
- package/bridge/auth-profile-failover.mjs +58 -0
- package/bridge/auth-profile-manager.mjs +215 -0
- package/bridge/capacity-recovery.mjs +90 -0
- package/bridge/codex-upgrade.mjs +150 -0
- package/bridge/deployment-profile.mjs +64 -0
- package/bridge/email-notifier.mjs +616 -0
- package/bridge/gpu-usage-history.mjs +322 -0
- package/bridge/host-session-restart.mjs +35 -0
- package/bridge/http.mjs +69 -0
- package/bridge/idle-sessions.mjs +185 -0
- package/bridge/inventory-scanner.mjs +517 -0
- package/bridge/local/dialogue.mjs +150 -0
- package/bridge/local/directories.mjs +40 -0
- package/bridge/local/executable.mjs +29 -0
- package/bridge/local/history.mjs +21 -0
- package/bridge/local/python-probe.mjs +35 -0
- package/bridge/local/runtime.mjs +188 -0
- package/bridge/local/transport.mjs +70 -0
- package/bridge/maintenance/install-command.mjs +141 -0
- package/bridge/maintenance/routes.mjs +21 -0
- package/bridge/maintenance/service.mjs +175 -0
- package/bridge/model-catalog.mjs +21 -0
- package/bridge/persistent-home-guard.mjs +6 -0
- package/bridge/plugins/aliyun-dlc/index.mjs +47 -0
- package/bridge/plugins/aliyun-dlc/manifest.mjs +12 -0
- package/bridge/plugins/aliyun-dlc/monitor.mjs +236 -0
- package/bridge/plugins/aliyun-dlc/probe.mjs +701 -0
- package/bridge/plugins/config-store.mjs +35 -0
- package/bridge/plugins/external.mjs +87 -0
- package/bridge/plugins/package.mjs +96 -0
- package/bridge/plugins/registry.mjs +37 -0
- package/bridge/plugins/routes.mjs +27 -0
- package/bridge/private-gateway.mjs +371 -0
- package/bridge/private-start.mjs +22 -0
- package/bridge/probes/app-server-handoff-probe.mjs +89 -0
- package/bridge/probes/app-server-writer-probe.mjs +72 -0
- package/bridge/probes/assistant-search-probe.mjs +323 -0
- package/bridge/probes/dialogue-probe.mjs +464 -0
- package/bridge/probes/history-probe.mjs +347 -0
- package/bridge/probes/index.mjs +15 -0
- package/bridge/probes/new-session-preflight.mjs +16 -0
- package/bridge/probes/profile-cancel-probe.mjs +19 -0
- package/bridge/probes/profile-delete-probe.mjs +28 -0
- package/bridge/probes/profile-list-probe.mjs +117 -0
- package/bridge/probes/profile-write-probe.mjs +111 -0
- package/bridge/probes/raw-context-probe.mjs +53 -0
- package/bridge/probes/remote-probe.mjs +636 -0
- package/bridge/probes/submission-probe.mjs +2 -0
- package/bridge/probes/takeover-probe.mjs +328 -0
- package/bridge/probes/vscode-open-preflight.mjs +23 -0
- package/bridge/profile-capacity-policy.mjs +14 -0
- package/bridge/providers/acp-forms.py +49 -0
- package/bridge/providers/antigravity-interactive.mjs +14 -0
- package/bridge/providers/antigravity-interactive.py +349 -0
- package/bridge/providers/claude-capabilities.py +52 -0
- package/bridge/providers/claude-interactive.mjs +14 -0
- package/bridge/providers/claude-interactive.py +341 -0
- package/bridge/providers/cli-command.mjs +103 -0
- package/bridge/providers/codex-workbench.mjs +164 -0
- package/bridge/providers/conversation-routes.mjs +28 -0
- package/bridge/providers/conversations.mjs +231 -0
- package/bridge/providers/native-commands.mjs +48 -0
- package/bridge/providers/native-commands.py +38 -0
- package/bridge/providers/native-models.mjs +129 -0
- package/bridge/providers/native-session-state.mjs +14 -0
- package/bridge/providers/native-session-state.py +96 -0
- package/bridge/providers/remote-cli.mjs +75 -0
- package/bridge/providers/remote-job.py +130 -0
- package/bridge/remote-app-server-command.mjs +203 -0
- package/bridge/remote-bootstrap/routes.mjs +51 -0
- package/bridge/remote-bootstrap/scope-protocol.mjs +125 -0
- package/bridge/remote-bootstrap/service.mjs +597 -0
- package/bridge/remote-bootstrap/tunnels.mjs +347 -0
- package/bridge/remote-directory-listing.mjs +148 -0
- package/bridge/remote-images.mjs +140 -0
- package/bridge/remote-profile-home.mjs +39 -0
- package/bridge/remote-rollout-locks.mjs +31 -0
- package/bridge/remote-videos.mjs +129 -0
- package/bridge/research/insights.mjs +522 -0
- package/bridge/research/scan-host.mjs +18 -0
- package/bridge/rollout-summary.mjs +159 -0
- package/bridge/routes/accounts.mjs +326 -0
- package/bridge/routes/dialogue.mjs +120 -0
- package/bridge/routes/email.mjs +50 -0
- package/bridge/routes/management.mjs +291 -0
- package/bridge/routes/models.mjs +312 -0
- package/bridge/routes/runtime.mjs +82 -0
- package/bridge/routes/session-commands.mjs +12 -0
- package/bridge/routes/session-delivery.mjs +328 -0
- package/bridge/routes/session-lifecycle.mjs +839 -0
- package/bridge/routes/system.mjs +289 -0
- package/bridge/server.mjs +3332 -0
- package/bridge/session-attachments.mjs +150 -0
- package/bridge/session-cache-archive.mjs +22 -0
- package/bridge/session-catalog/agy-history.py +249 -0
- package/bridge/session-catalog/catalog.mjs +93 -0
- package/bridge/session-catalog/probe.py +331 -0
- package/bridge/session-catalog/routes.mjs +28 -0
- package/bridge/session-profiles.mjs +115 -0
- package/bridge/shared-start.mjs +22 -0
- package/bridge/start.mjs +205 -0
- package/bridge/state-persistence.mjs +397 -0
- package/bridge/submissions/settings.mjs +50 -0
- package/bridge/terminal-gateway.mjs +171 -0
- package/bridge/tmux-delivery.mjs +390 -0
- package/bridge/tmux-session-control.mjs +29 -0
- package/bridge/transport/ssh-command.mjs +119 -0
- package/bridge/ui-server.mjs +257 -0
- package/bridge/vscode-opener.mjs +157 -0
- package/bridge/web-terminal.mjs +52 -0
- package/bridge/workbench/conversation-routes.mjs +31 -0
- package/bridge/workbench/directory-probe.mjs +41 -0
- package/bridge/workbench/directory-routes.mjs +112 -0
- package/bridge/workbench/manager-context.mjs +51 -0
- package/bridge/workbench/routes.mjs +40 -0
- package/bridge/workbench/scheduler.mjs +131 -0
- package/bridge/workbench/service.mjs +301 -0
- package/bridge/workbench/store.mjs +64 -0
- package/bridge/workbench/task-archive.mjs +46 -0
- package/dist/client/.assetsignore +2 -0
- package/dist/client/.vite/manifest.json +366 -0
- package/dist/client/_headers +3 -0
- package/dist/client/agents/LICENSE.lobe-icons +21 -0
- package/dist/client/agents/README.md +14 -0
- package/dist/client/agents/antigravity.svg +39 -0
- package/dist/client/agents/claude.svg +1 -0
- package/dist/client/agents/codex.svg +1 -0
- package/dist/client/agents/dsh.svg +4 -0
- package/dist/client/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
- package/dist/client/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
- package/dist/client/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
- package/dist/client/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
- package/dist/client/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
- package/dist/client/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
- package/dist/client/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
- package/dist/client/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
- package/dist/client/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
- package/dist/client/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
- package/dist/client/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
- package/dist/client/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
- package/dist/client/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
- package/dist/client/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
- package/dist/client/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
- package/dist/client/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
- package/dist/client/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
- package/dist/client/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
- package/dist/client/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
- package/dist/client/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
- package/dist/client/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
- package/dist/client/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
- package/dist/client/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
- package/dist/client/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
- package/dist/client/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
- package/dist/client/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
- package/dist/client/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
- package/dist/client/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
- package/dist/client/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
- package/dist/client/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
- package/dist/client/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
- package/dist/client/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
- package/dist/client/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
- package/dist/client/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
- package/dist/client/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
- package/dist/client/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
- package/dist/client/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
- package/dist/client/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
- package/dist/client/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
- package/dist/client/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
- package/dist/client/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
- package/dist/client/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
- package/dist/client/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
- package/dist/client/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
- package/dist/client/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
- package/dist/client/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
- package/dist/client/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
- package/dist/client/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
- package/dist/client/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
- package/dist/client/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
- package/dist/client/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
- package/dist/client/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
- package/dist/client/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
- package/dist/client/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
- package/dist/client/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
- package/dist/client/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
- package/dist/client/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
- package/dist/client/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
- package/dist/client/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
- package/dist/client/assets/_vinext_fonts/geist-8ac0455e797f/geist-001175b1.woff2 +0 -0
- package/dist/client/assets/_vinext_fonts/geist-8ac0455e797f/geist-52306abf.woff2 +0 -0
- package/dist/client/assets/_vinext_fonts/geist-8ac0455e797f/geist-875ccdd4.woff2 +0 -0
- package/dist/client/assets/_vinext_fonts/geist-8ac0455e797f/geist-98bbbccb.woff2 +0 -0
- package/dist/client/assets/_vinext_fonts/geist-8ac0455e797f/geist-ff2310f5.woff2 +0 -0
- package/dist/client/assets/_vinext_fonts/geist-mono-00e989178794/geist-mono-013b2f2f.woff2 +0 -0
- package/dist/client/assets/_vinext_fonts/geist-mono-00e989178794/geist-mono-0638449e.woff2 +0 -0
- package/dist/client/assets/_vinext_fonts/geist-mono-00e989178794/geist-mono-44745446.woff2 +0 -0
- package/dist/client/assets/_vinext_fonts/geist-mono-00e989178794/geist-mono-44e03052.woff2 +0 -0
- package/dist/client/assets/_vinext_fonts/geist-mono-00e989178794/geist-mono-971fb274.woff2 +0 -0
- package/dist/client/assets/_vinext_fonts/geist-mono-00e989178794/geist-mono-f6b33328.woff2 +0 -0
- package/dist/client/assets/addon-fit-BZbxZs2G.js +1 -0
- package/dist/client/assets/framework-CXnKph_e.js +9 -0
- package/dist/client/assets/index-CNnP2Ses.css +2 -0
- package/dist/client/assets/index-Enu1x0PS.js +3 -0
- package/dist/client/assets/layout-segment-context-CmJzExWq.js +1 -0
- package/dist/client/assets/page-COBv6VWj.css +1 -0
- package/dist/client/assets/page-DVjU6VG_.js +550 -0
- package/dist/client/assets/rolldown-runtime-S-ySWqyJ.js +1 -0
- package/dist/client/assets/xterm-BBgU7shl.js +36 -0
- package/dist/client/favicon.svg +6 -0
- package/dist/client/file.svg +1 -0
- package/dist/client/globe.svg +1 -0
- package/dist/client/og.png +0 -0
- package/dist/client/scope-logo.svg +11 -0
- package/dist/client/window.svg +1 -0
- package/dist/server/.vite/manifest.json +14 -0
- package/dist/server/__vite_rsc_assets_manifest.js +49 -0
- package/dist/server/assets/index-CNnP2Ses.css +2 -0
- package/dist/server/image-config.json +1 -0
- package/dist/server/index.js +15201 -0
- package/dist/server/ssr/__vite_rsc_assets_manifest.js +49 -0
- package/dist/server/ssr/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
- package/dist/server/ssr/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
- package/dist/server/ssr/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
- package/dist/server/ssr/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
- package/dist/server/ssr/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
- package/dist/server/ssr/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
- package/dist/server/ssr/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
- package/dist/server/ssr/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
- package/dist/server/ssr/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
- package/dist/server/ssr/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
- package/dist/server/ssr/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
- package/dist/server/ssr/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
- package/dist/server/ssr/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
- package/dist/server/ssr/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
- package/dist/server/ssr/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
- package/dist/server/ssr/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
- package/dist/server/ssr/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
- package/dist/server/ssr/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
- package/dist/server/ssr/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
- package/dist/server/ssr/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
- package/dist/server/ssr/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
- package/dist/server/ssr/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
- package/dist/server/ssr/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
- package/dist/server/ssr/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
- package/dist/server/ssr/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
- package/dist/server/ssr/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
- package/dist/server/ssr/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
- package/dist/server/ssr/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
- package/dist/server/ssr/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
- package/dist/server/ssr/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
- package/dist/server/ssr/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
- package/dist/server/ssr/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
- package/dist/server/ssr/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
- package/dist/server/ssr/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
- package/dist/server/ssr/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
- package/dist/server/ssr/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
- package/dist/server/ssr/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
- package/dist/server/ssr/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
- package/dist/server/ssr/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
- package/dist/server/ssr/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
- package/dist/server/ssr/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
- package/dist/server/ssr/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
- package/dist/server/ssr/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
- package/dist/server/ssr/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
- package/dist/server/ssr/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
- package/dist/server/ssr/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
- package/dist/server/ssr/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
- package/dist/server/ssr/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
- package/dist/server/ssr/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
- package/dist/server/ssr/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
- package/dist/server/ssr/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
- package/dist/server/ssr/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
- package/dist/server/ssr/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
- package/dist/server/ssr/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
- package/dist/server/ssr/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
- package/dist/server/ssr/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
- package/dist/server/ssr/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
- package/dist/server/ssr/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
- package/dist/server/ssr/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
- package/dist/server/ssr/assets/addon-fit-C09Jj0_f.js +42 -0
- package/dist/server/ssr/assets/error-boundary-Dd2ZYXA8.js +277 -0
- package/dist/server/ssr/assets/layout-segment-context-HV_Mvyzf.js +37 -0
- package/dist/server/ssr/assets/page-COBv6VWj.css +1 -0
- package/dist/server/ssr/assets/page-CYYyCnKD.js +102541 -0
- package/dist/server/ssr/assets/xterm-DgzE4ZZ1.js +10232 -0
- package/dist/server/ssr/index.js +11840 -0
- package/dist/server/ssr/vinext-server.json +1 -0
- package/dist/server/vinext-externals.json +1 -0
- package/dist/server/vinext-server.json +1 -0
- package/dist/server/wrangler.json +1 -0
- package/examples/agents/global-agreements.example.md +10 -0
- package/examples/agents/research-project.example.md +10 -0
- package/examples/agents-media-previews.md +22 -0
- package/examples/deployment.example.json +6 -0
- package/examples/leak-denylist.example.json +10 -0
- package/examples/plugins/hello/index.mjs +4 -0
- package/examples/plugins/hello/scope-plugin.json +13 -0
- package/examples/workbench.config.json +44 -0
- package/lib/account-quota.d.ts +42 -0
- package/lib/account-quota.js +121 -0
- package/lib/browser-snapshot-cache.js +61 -0
- package/lib/conversation-location.js +26 -0
- package/lib/conversation.js +62 -0
- package/lib/dialogue-refresh.js +14 -0
- package/lib/execution-host.js +22 -0
- package/lib/formula-preview.js +48 -0
- package/lib/i18n.tsx +81 -0
- package/lib/incremental-snapshot.js +324 -0
- package/lib/manager-plan.js +37 -0
- package/lib/markdown-images.js +22 -0
- package/lib/markdown-math.js +151 -0
- package/lib/markdown-url.js +13 -0
- package/lib/model-effort.js +13 -0
- package/lib/native-history.d.ts +32 -0
- package/lib/native-history.js +94 -0
- package/lib/overview-delta.js +41 -0
- package/lib/project-view.js +86 -0
- package/lib/projects.js +74 -0
- package/lib/remote-links.js +95 -0
- package/lib/runtime-config.js +70 -0
- package/lib/session-activity.js +34 -0
- package/lib/session-cache-guard.js +52 -0
- package/lib/session-filters.js +38 -0
- package/lib/ssh-config.js +26 -0
- package/lib/stable-order.js +39 -0
- package/lib/workbench-config.js +172 -0
- package/package.json +105 -4
- package/scripts/agent-email-relay.mjs +104 -0
- package/scripts/benchmark-bridge.mjs +38 -0
- package/scripts/cli-integration-smoke.mjs +64 -0
- package/scripts/email-notification-cli.mjs +28 -0
- package/scripts/enable-private-access.ps1 +109 -0
- package/scripts/export-opensource.mjs +112 -0
- package/scripts/fixtures/media/convergence.png +0 -0
- package/scripts/fixtures/media/rollout_demo.mp4 +0 -0
- package/scripts/fixtures/native-conversations.mjs +307 -0
- package/scripts/fixtures/workbench-conversations.mjs +352 -0
- package/scripts/install-remote-server.sh +67 -0
- package/scripts/lib/export-directory.mjs +38 -0
- package/scripts/lib/secret-scanner.mjs +139 -0
- package/scripts/plugin-cli.mjs +19 -0
- package/scripts/preview-workbench.mjs +669 -0
- package/scripts/probe-antigravity-acp.mjs +35 -0
- package/scripts/remote-bootstrap-cli.mjs +52 -0
- package/scripts/remote-email-tool.py +383 -0
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
2
|
+
import { EventEmitter } from "node:events";
|
|
3
|
+
import { PassThrough, Writable } from "node:stream";
|
|
4
|
+
|
|
5
|
+
const WEBSOCKET_GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
|
|
6
|
+
|
|
7
|
+
function frame(opcode, payload = Buffer.alloc(0)) {
|
|
8
|
+
const body = Buffer.isBuffer(payload) ? payload : Buffer.from(payload);
|
|
9
|
+
const mask = randomBytes(4);
|
|
10
|
+
let header;
|
|
11
|
+
if (body.length < 126) {
|
|
12
|
+
header = Buffer.alloc(2);
|
|
13
|
+
header[1] = 0x80 | body.length;
|
|
14
|
+
} else if (body.length <= 0xffff) {
|
|
15
|
+
header = Buffer.alloc(4);
|
|
16
|
+
header[1] = 0x80 | 126;
|
|
17
|
+
header.writeUInt16BE(body.length, 2);
|
|
18
|
+
} else {
|
|
19
|
+
header = Buffer.alloc(10);
|
|
20
|
+
header[1] = 0x80 | 127;
|
|
21
|
+
header.writeBigUInt64BE(BigInt(body.length), 2);
|
|
22
|
+
}
|
|
23
|
+
header[0] = 0x80 | opcode;
|
|
24
|
+
const masked = Buffer.alloc(body.length);
|
|
25
|
+
for (let index = 0; index < body.length; index += 1) {
|
|
26
|
+
masked[index] = body[index] ^ mask[index % 4];
|
|
27
|
+
}
|
|
28
|
+
return Buffer.concat([header, mask, masked]);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export class WebSocketJsonlChild extends EventEmitter {
|
|
32
|
+
constructor(
|
|
33
|
+
child,
|
|
34
|
+
{
|
|
35
|
+
path = "/",
|
|
36
|
+
host = "localhost",
|
|
37
|
+
pingIntervalMs = 25_000,
|
|
38
|
+
setIntervalFn = setInterval,
|
|
39
|
+
clearIntervalFn = clearInterval,
|
|
40
|
+
} = {},
|
|
41
|
+
) {
|
|
42
|
+
super();
|
|
43
|
+
this.child = child;
|
|
44
|
+
this.stdout = new PassThrough();
|
|
45
|
+
this.stderr = child.stderr;
|
|
46
|
+
this.killed = false;
|
|
47
|
+
this.ready = false;
|
|
48
|
+
this.closed = false;
|
|
49
|
+
this.buffer = Buffer.alloc(0);
|
|
50
|
+
this.fragments = [];
|
|
51
|
+
this.pendingWrites = [];
|
|
52
|
+
this.pingIntervalMs = Math.max(0, Number(pingIntervalMs) || 0);
|
|
53
|
+
this.setIntervalFn = setIntervalFn;
|
|
54
|
+
this.clearIntervalFn = clearIntervalFn;
|
|
55
|
+
this.pingTimer = null;
|
|
56
|
+
// Lets JsonlAppServerConnection distinguish this disposable SSH/WebSocket
|
|
57
|
+
// bridge from an actual remote app-server process exit.
|
|
58
|
+
this.scopeTransport = "ssh-websocket";
|
|
59
|
+
this.key = randomBytes(16).toString("base64");
|
|
60
|
+
this.stdin = new Writable({
|
|
61
|
+
write: (chunk, _encoding, callback) => {
|
|
62
|
+
try {
|
|
63
|
+
const payload = Buffer.from(chunk);
|
|
64
|
+
if (this.ready) this.child.stdin.write(frame(0x1, payload));
|
|
65
|
+
else this.pendingWrites.push(payload);
|
|
66
|
+
callback();
|
|
67
|
+
} catch (error) {
|
|
68
|
+
callback(error);
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
final: (callback) => {
|
|
72
|
+
try {
|
|
73
|
+
this.#stopHeartbeat();
|
|
74
|
+
if (!this.child.stdin.destroyed) {
|
|
75
|
+
if (this.ready) this.child.stdin.write(frame(0x8));
|
|
76
|
+
this.child.stdin.end();
|
|
77
|
+
}
|
|
78
|
+
callback();
|
|
79
|
+
} catch (error) {
|
|
80
|
+
callback(error);
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
child.stdout.on("data", (chunk) => this.#read(chunk));
|
|
85
|
+
child.once("error", (error) => this.emit("error", error));
|
|
86
|
+
child.once("exit", (code, signal) => {
|
|
87
|
+
this.#stopHeartbeat();
|
|
88
|
+
this.closed = true;
|
|
89
|
+
this.stdout.end();
|
|
90
|
+
this.emit("exit", code, signal);
|
|
91
|
+
});
|
|
92
|
+
child.stdin.on("error", (error) => this.stdin.destroy(error));
|
|
93
|
+
const request = [
|
|
94
|
+
`GET ${path} HTTP/1.1`,
|
|
95
|
+
`Host: ${host}`,
|
|
96
|
+
"Upgrade: websocket",
|
|
97
|
+
"Connection: Upgrade",
|
|
98
|
+
`Sec-WebSocket-Key: ${this.key}`,
|
|
99
|
+
"Sec-WebSocket-Version: 13",
|
|
100
|
+
"",
|
|
101
|
+
"",
|
|
102
|
+
].join("\r\n");
|
|
103
|
+
child.stdin.write(request);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
kill() {
|
|
107
|
+
// Compatibility with ChildProcess consumers. This intentionally closes the
|
|
108
|
+
// proxy stream instead of signalling the durable remote app-server.
|
|
109
|
+
this.killed = true;
|
|
110
|
+
this.#stopHeartbeat();
|
|
111
|
+
this.stdin.end();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
#read(chunk) {
|
|
115
|
+
this.buffer = Buffer.concat([this.buffer, Buffer.from(chunk)]);
|
|
116
|
+
if (!this.ready) {
|
|
117
|
+
const marker = this.buffer.indexOf("\r\n\r\n");
|
|
118
|
+
if (marker < 0) return;
|
|
119
|
+
const response = this.buffer.subarray(0, marker + 4).toString("utf8");
|
|
120
|
+
this.buffer = this.buffer.subarray(marker + 4);
|
|
121
|
+
const status = response.split("\r\n", 1)[0] || "";
|
|
122
|
+
const accept = response.match(/\r\nsec-websocket-accept:\s*([^\r\n]+)/i)?.[1]?.trim();
|
|
123
|
+
const expected = createHash("sha1")
|
|
124
|
+
.update(`${this.key}${WEBSOCKET_GUID}`)
|
|
125
|
+
.digest("base64");
|
|
126
|
+
if (!/^HTTP\/1\.[01] 101\b/.test(status) || accept !== expected) {
|
|
127
|
+
this.emit(
|
|
128
|
+
"error",
|
|
129
|
+
new Error(`app-server WebSocket 握手失败:${status || "无响应"}`),
|
|
130
|
+
);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
this.ready = true;
|
|
134
|
+
this.#startHeartbeat();
|
|
135
|
+
for (const payload of this.pendingWrites.splice(0)) {
|
|
136
|
+
this.child.stdin.write(frame(0x1, payload));
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
this.#drainFrames();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
#drainFrames() {
|
|
143
|
+
while (this.buffer.length >= 2) {
|
|
144
|
+
const first = this.buffer[0];
|
|
145
|
+
const second = this.buffer[1];
|
|
146
|
+
const fin = Boolean(first & 0x80);
|
|
147
|
+
const opcode = first & 0x0f;
|
|
148
|
+
const masked = Boolean(second & 0x80);
|
|
149
|
+
let length = second & 0x7f;
|
|
150
|
+
let offset = 2;
|
|
151
|
+
if (length === 126) {
|
|
152
|
+
if (this.buffer.length < 4) return;
|
|
153
|
+
length = this.buffer.readUInt16BE(2);
|
|
154
|
+
offset = 4;
|
|
155
|
+
} else if (length === 127) {
|
|
156
|
+
if (this.buffer.length < 10) return;
|
|
157
|
+
const wide = this.buffer.readBigUInt64BE(2);
|
|
158
|
+
if (wide > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
159
|
+
this.emit("error", new Error("app-server WebSocket 帧过大"));
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
length = Number(wide);
|
|
163
|
+
offset = 10;
|
|
164
|
+
}
|
|
165
|
+
const maskOffset = offset;
|
|
166
|
+
if (masked) offset += 4;
|
|
167
|
+
if (this.buffer.length < offset + length) return;
|
|
168
|
+
const mask = masked
|
|
169
|
+
? Buffer.from(this.buffer.subarray(maskOffset, maskOffset + 4))
|
|
170
|
+
: null;
|
|
171
|
+
let payload = Buffer.from(this.buffer.subarray(offset, offset + length));
|
|
172
|
+
this.buffer = this.buffer.subarray(offset + length);
|
|
173
|
+
if (mask) {
|
|
174
|
+
for (let index = 0; index < payload.length; index += 1) {
|
|
175
|
+
payload[index] ^= mask[index % 4];
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
if (opcode === 0x8) {
|
|
179
|
+
this.#stopHeartbeat();
|
|
180
|
+
if (!this.child.stdin.destroyed) this.child.stdin.end(frame(0x8));
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
if (opcode === 0x9) {
|
|
184
|
+
if (!this.child.stdin.destroyed) this.child.stdin.write(frame(0xa, payload));
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
if (opcode === 0xa) continue;
|
|
188
|
+
if (opcode === 0x1) this.fragments = [payload];
|
|
189
|
+
else if (opcode === 0x0) this.fragments.push(payload);
|
|
190
|
+
else continue;
|
|
191
|
+
if (fin) {
|
|
192
|
+
this.stdout.write(Buffer.concat(this.fragments));
|
|
193
|
+
this.stdout.write("\n");
|
|
194
|
+
this.fragments = [];
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
#startHeartbeat() {
|
|
200
|
+
if (this.pingTimer || !this.ready || this.closed || !this.pingIntervalMs) {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
this.pingTimer = this.setIntervalFn(() => {
|
|
204
|
+
if (!this.ready || this.closed || this.child.stdin.destroyed) return;
|
|
205
|
+
try {
|
|
206
|
+
this.child.stdin.write(frame(0x9));
|
|
207
|
+
} catch {
|
|
208
|
+
// The child exit/error handlers surface the real disconnect.
|
|
209
|
+
}
|
|
210
|
+
}, this.pingIntervalMs);
|
|
211
|
+
this.pingTimer?.unref?.();
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
#stopHeartbeat() {
|
|
215
|
+
if (!this.pingTimer) return;
|
|
216
|
+
this.clearIntervalFn(this.pingTimer);
|
|
217
|
+
this.pingTimer = null;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export function archiveRoutes(service, { readJsonBody, jsonResponse }) {
|
|
2
|
+
return async (req, res, url) => {
|
|
3
|
+
if (url.pathname !== "/api/session/archives") return false;
|
|
4
|
+
res.setHeader("Cache-Control", "no-store");
|
|
5
|
+
try {
|
|
6
|
+
if (req.method === "GET")
|
|
7
|
+
jsonResponse(res, 200, { records: service.list() });
|
|
8
|
+
else if (req.method === "POST") {
|
|
9
|
+
const { host, sessionId, action } = await readJsonBody(req);
|
|
10
|
+
jsonResponse(res, 200, {
|
|
11
|
+
record: await service.change(host, sessionId, action),
|
|
12
|
+
});
|
|
13
|
+
} else jsonResponse(res, 405, { error: "不支持的请求方法" });
|
|
14
|
+
} catch (error) {
|
|
15
|
+
jsonResponse(res, 409, { error: error.message });
|
|
16
|
+
}
|
|
17
|
+
return true;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/** Durable intents make lost SSH replies retryable without pretending local-only deletion succeeded. */
|
|
2
|
+
export function sessionArchiveService({
|
|
3
|
+
manager,
|
|
4
|
+
getState,
|
|
5
|
+
persist,
|
|
6
|
+
findAgent,
|
|
7
|
+
getHost,
|
|
8
|
+
executable,
|
|
9
|
+
connectionKey,
|
|
10
|
+
notify,
|
|
11
|
+
restored,
|
|
12
|
+
protectedSession = () => false,
|
|
13
|
+
}) {
|
|
14
|
+
const busy = new Set();
|
|
15
|
+
const keyOf = (host, id) => `${host}:${id}`;
|
|
16
|
+
function list() {
|
|
17
|
+
return Object.values(getState().sessions).flatMap((value) =>
|
|
18
|
+
value.archive && value.archive.phase !== "restored"
|
|
19
|
+
? [value.archive]
|
|
20
|
+
: [],
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
async function write(key, record) {
|
|
24
|
+
const sessions = getState().sessions;
|
|
25
|
+
const previous = sessions[key];
|
|
26
|
+
sessions[key] = { ...previous, archive: record };
|
|
27
|
+
try {
|
|
28
|
+
await persist();
|
|
29
|
+
} catch (error) {
|
|
30
|
+
sessions[key] = previous;
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
notify();
|
|
34
|
+
}
|
|
35
|
+
async function change(host, sessionId, action, receipt = null) {
|
|
36
|
+
if (!host || !sessionId || !["archive", "restore"].includes(action))
|
|
37
|
+
throw new Error("归档参数无效");
|
|
38
|
+
if (protectedSession(host, sessionId))
|
|
39
|
+
throw new Error("这是总调度的主会话,请从左侧归档普通项目会话或任务");
|
|
40
|
+
const key = keyOf(host, sessionId);
|
|
41
|
+
if (busy.has(key)) throw new Error("此会话的归档操作尚未完成");
|
|
42
|
+
if (!getHost(host)?.reachable)
|
|
43
|
+
throw new Error("主机当前离线,恢复连接后可归档或恢复");
|
|
44
|
+
busy.add(key);
|
|
45
|
+
let record;
|
|
46
|
+
try {
|
|
47
|
+
const previous = getState().sessions[key]?.archive;
|
|
48
|
+
if (action === "restore" && !previous) throw new Error("找不到归档记录");
|
|
49
|
+
if (action === "restore" && previous.phase === "restored")
|
|
50
|
+
return previous;
|
|
51
|
+
const agent = findAgent(host, sessionId);
|
|
52
|
+
const managed = manager
|
|
53
|
+
.sessionRecords()
|
|
54
|
+
.find((s) => s.host === host && s.sessionId === sessionId);
|
|
55
|
+
if (action === "archive") {
|
|
56
|
+
if (!agent && !managed && !receipt && !previous)
|
|
57
|
+
throw new Error("找不到对应会话");
|
|
58
|
+
if (
|
|
59
|
+
agent?.status === "working" ||
|
|
60
|
+
(!managed && (agent?.pid > 0 || agent?.pane))
|
|
61
|
+
)
|
|
62
|
+
throw new Error("会话仍由运行中的 Agent 使用,请结束后再归档");
|
|
63
|
+
if (agent?.subagents?.some((child) => child.status === "working"))
|
|
64
|
+
throw new Error("子会话仍在执行,请结束后再归档");
|
|
65
|
+
}
|
|
66
|
+
record = {
|
|
67
|
+
...previous,
|
|
68
|
+
host,
|
|
69
|
+
sessionId,
|
|
70
|
+
title:
|
|
71
|
+
previous?.title ||
|
|
72
|
+
agent?.title ||
|
|
73
|
+
agent?.rollout?.firstUser ||
|
|
74
|
+
sessionId,
|
|
75
|
+
session: managed || previous?.session || null,
|
|
76
|
+
cwd: previous?.cwd || agent?.cwd || managed?.cwd || receipt?.cwd || "",
|
|
77
|
+
executable:
|
|
78
|
+
managed?.executable ||
|
|
79
|
+
receipt?.executable ||
|
|
80
|
+
previous?.executable ||
|
|
81
|
+
executable(host),
|
|
82
|
+
connectionKey:
|
|
83
|
+
managed?.connectionKey ||
|
|
84
|
+
receipt?.connectionKey ||
|
|
85
|
+
previous?.connectionKey ||
|
|
86
|
+
(await connectionKey(host, sessionId)),
|
|
87
|
+
phase: action === "archive" ? "archiving" : "restoring",
|
|
88
|
+
error: null,
|
|
89
|
+
updatedAt: new Date().toISOString(),
|
|
90
|
+
};
|
|
91
|
+
await write(key, record);
|
|
92
|
+
if (action === "archive") {
|
|
93
|
+
await manager.archiveSession(
|
|
94
|
+
host,
|
|
95
|
+
sessionId,
|
|
96
|
+
record.executable,
|
|
97
|
+
record.connectionKey,
|
|
98
|
+
);
|
|
99
|
+
record = {
|
|
100
|
+
...record,
|
|
101
|
+
phase: "archived",
|
|
102
|
+
archivedAt: new Date().toISOString(),
|
|
103
|
+
};
|
|
104
|
+
} else {
|
|
105
|
+
const thread = await manager.unarchiveSession(
|
|
106
|
+
host,
|
|
107
|
+
sessionId,
|
|
108
|
+
record.executable,
|
|
109
|
+
record.connectionKey,
|
|
110
|
+
);
|
|
111
|
+
if (record.session)
|
|
112
|
+
await manager.resumeSession({
|
|
113
|
+
...record.session,
|
|
114
|
+
path: thread.path || null,
|
|
115
|
+
});
|
|
116
|
+
await restored(host, sessionId, thread);
|
|
117
|
+
record = { ...record, phase: "restored" };
|
|
118
|
+
}
|
|
119
|
+
await write(key, record);
|
|
120
|
+
return record;
|
|
121
|
+
} catch (error) {
|
|
122
|
+
if (record)
|
|
123
|
+
await write(key, { ...record, error: error.message }).catch(() => {});
|
|
124
|
+
throw error;
|
|
125
|
+
} finally {
|
|
126
|
+
busy.delete(key);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return { list, change };
|
|
130
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
const locks = new WeakMap();
|
|
2
|
+
export function isArchiving(manager, host, sessionId) {
|
|
3
|
+
return locks.get(manager)?.has(`${host}:${sessionId}`) || false;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
/** Archive the durable remote thread first; only then release local bookkeeping. */
|
|
7
|
+
export async function archiveThread(
|
|
8
|
+
manager,
|
|
9
|
+
host,
|
|
10
|
+
sessionId,
|
|
11
|
+
executable,
|
|
12
|
+
connectionKey,
|
|
13
|
+
) {
|
|
14
|
+
if (!locks.has(manager)) locks.set(manager, new Set());
|
|
15
|
+
const held = locks.get(manager);
|
|
16
|
+
const key = `${host}:${sessionId}`;
|
|
17
|
+
if (held.has(key)) throw new Error("正在归档,请稍后重试");
|
|
18
|
+
const session = manager.sessions.get(key);
|
|
19
|
+
if (
|
|
20
|
+
session &&
|
|
21
|
+
(session.status === "working" ||
|
|
22
|
+
session.turnStarting ||
|
|
23
|
+
session.profileHandoff ||
|
|
24
|
+
session.profileSwitching)
|
|
25
|
+
)
|
|
26
|
+
throw new Error("会话仍在执行或交接,请结束后再归档");
|
|
27
|
+
held.add(key);
|
|
28
|
+
try {
|
|
29
|
+
const connection = await manager.prepareHost(
|
|
30
|
+
host,
|
|
31
|
+
session?.executable || executable,
|
|
32
|
+
session?.connectionKey || connectionKey,
|
|
33
|
+
);
|
|
34
|
+
const { thread } = await connection.request("thread/read", {
|
|
35
|
+
threadId: sessionId,
|
|
36
|
+
includeTurns: true,
|
|
37
|
+
});
|
|
38
|
+
if (!thread) throw new Error("无法核实远端会话,未归档");
|
|
39
|
+
if (
|
|
40
|
+
thread.status?.type === "active" ||
|
|
41
|
+
thread.turns?.some((t) => t.status === "inProgress")
|
|
42
|
+
)
|
|
43
|
+
throw new Error("远端会话仍在执行,请结束后再归档");
|
|
44
|
+
// A previous reply may have been lost after the remote move succeeded.
|
|
45
|
+
if (!/[\\/]archived_sessions[\\/]/.test(thread.path || ""))
|
|
46
|
+
await connection.request("thread/archive", { threadId: sessionId });
|
|
47
|
+
manager.forgetArchivedSession(host, sessionId);
|
|
48
|
+
return thread;
|
|
49
|
+
} finally {
|
|
50
|
+
held.delete(key);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { once } from "node:events";
|
|
4
|
+
import {
|
|
5
|
+
MAX_ATTACHMENT_BYTES,
|
|
6
|
+
MAX_ATTACHMENTS_PER_TURN,
|
|
7
|
+
MAX_ATTACHMENTS_TOTAL_BYTES,
|
|
8
|
+
} from "./session-attachments.mjs";
|
|
9
|
+
|
|
10
|
+
export function attachmentHttpError(message, statusCode = 400) {
|
|
11
|
+
const error = new Error(message);
|
|
12
|
+
error.statusCode = statusCode;
|
|
13
|
+
return error;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function createAttachmentStore({
|
|
17
|
+
cleanSshError,
|
|
18
|
+
inventoryOperations,
|
|
19
|
+
sshOperationCounts,
|
|
20
|
+
SSH_TIMEOUT_MS,
|
|
21
|
+
ATTACHMENT_TTL_MS,
|
|
22
|
+
ATTACHMENT_UPLOAD_TIMEOUT_MS,
|
|
23
|
+
}) {
|
|
24
|
+
const uploadedAttachments = new Map();
|
|
25
|
+
|
|
26
|
+
function purgeExpiredAttachments(now = Date.now()) {
|
|
27
|
+
for (const [token, attachment] of uploadedAttachments) {
|
|
28
|
+
if (now - attachment.createdAt > ATTACHMENT_TTL_MS) {
|
|
29
|
+
uploadedAttachments.delete(token);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function storeUploadedAttachment(record) {
|
|
35
|
+
purgeExpiredAttachments(record.createdAt);
|
|
36
|
+
uploadedAttachments.set(record.token, record);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function resolveUploadedAttachments(value, host, expected = "") {
|
|
40
|
+
purgeExpiredAttachments();
|
|
41
|
+
if (!Array.isArray(value)) return [];
|
|
42
|
+
if (value.length > MAX_ATTACHMENTS_PER_TURN) {
|
|
43
|
+
throw attachmentHttpError(`每条消息最多 ${MAX_ATTACHMENTS_PER_TURN} 个附件`);
|
|
44
|
+
}
|
|
45
|
+
const expectedSessionId =
|
|
46
|
+
typeof expected === "string" ? expected : String(expected?.sessionId || "");
|
|
47
|
+
const expectedScope =
|
|
48
|
+
typeof expected === "object" && expected ? String(expected.scope || "") : "";
|
|
49
|
+
const resolved = [];
|
|
50
|
+
const seen = new Set();
|
|
51
|
+
let totalBytes = 0;
|
|
52
|
+
for (const item of value) {
|
|
53
|
+
const token = typeof item?.token === "string" ? item.token.trim() : "";
|
|
54
|
+
if (!token || seen.has(token)) continue;
|
|
55
|
+
seen.add(token);
|
|
56
|
+
const attachment = uploadedAttachments.get(token);
|
|
57
|
+
if (!attachment) {
|
|
58
|
+
throw attachmentHttpError("附件已过期或 Bridge 已重启,请重新上传", 410);
|
|
59
|
+
}
|
|
60
|
+
if (expectedScope) {
|
|
61
|
+
if (attachment.host !== host || attachment.sessionId || attachment.scope !== expectedScope) {
|
|
62
|
+
throw attachmentHttpError("附件不属于当前主机与会话上下文", 403);
|
|
63
|
+
}
|
|
64
|
+
} else if (attachment.host !== host || attachment.sessionId !== expectedSessionId) {
|
|
65
|
+
throw attachmentHttpError("附件不属于当前主机与 Session", 403);
|
|
66
|
+
}
|
|
67
|
+
totalBytes += attachment.size;
|
|
68
|
+
if (totalBytes > MAX_ATTACHMENTS_TOTAL_BYTES) {
|
|
69
|
+
throw attachmentHttpError("单条消息的附件总大小不能超过 100 MiB", 413);
|
|
70
|
+
}
|
|
71
|
+
resolved.push(attachment);
|
|
72
|
+
}
|
|
73
|
+
return resolved;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async function streamAttachmentToHost(alias, request, command) {
|
|
77
|
+
const inventory = inventoryOperations.get(alias);
|
|
78
|
+
if (inventory) await inventory.catch(() => {});
|
|
79
|
+
const declaredLength = Number(request.headers["content-length"] || 0);
|
|
80
|
+
if (Number.isFinite(declaredLength) && declaredLength > MAX_ATTACHMENT_BYTES) {
|
|
81
|
+
request.resume();
|
|
82
|
+
throw attachmentHttpError("单个附件不能超过 50 MiB", 413);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
sshOperationCounts.set(alias, (sshOperationCounts.get(alias) || 0) + 1);
|
|
86
|
+
const child = spawn(
|
|
87
|
+
(typeof process !== "undefined" && process.platform === "win32" ? "ssh.exe" : "ssh"),
|
|
88
|
+
[
|
|
89
|
+
"-T",
|
|
90
|
+
"-o",
|
|
91
|
+
"BatchMode=yes",
|
|
92
|
+
"-o",
|
|
93
|
+
"StrictHostKeyChecking=yes",
|
|
94
|
+
"-o",
|
|
95
|
+
"ConnectionAttempts=1",
|
|
96
|
+
"-o",
|
|
97
|
+
`ConnectTimeout=${Math.ceil(SSH_TIMEOUT_MS / 1000)}`,
|
|
98
|
+
"--",
|
|
99
|
+
alias,
|
|
100
|
+
command,
|
|
101
|
+
],
|
|
102
|
+
{ windowsHide: true },
|
|
103
|
+
);
|
|
104
|
+
let stdout = "";
|
|
105
|
+
let stderr = "";
|
|
106
|
+
let size = 0;
|
|
107
|
+
let timedOut = false;
|
|
108
|
+
const hash = createHash("sha256");
|
|
109
|
+
child.stdout.on("data", (chunk) => {
|
|
110
|
+
if (stdout.length < 16_000) stdout += chunk.toString("utf8");
|
|
111
|
+
});
|
|
112
|
+
child.stderr.on("data", (chunk) => {
|
|
113
|
+
if (stderr.length < 32_000) stderr += chunk.toString("utf8");
|
|
114
|
+
});
|
|
115
|
+
// A remote disconnect can close stdin while the browser is still streaming.
|
|
116
|
+
// `once(..., "drain")` observes this error; this listener prevents an
|
|
117
|
+
// additional unhandled stream error when no backpressure wait is active.
|
|
118
|
+
child.stdin.on("error", () => {});
|
|
119
|
+
const closePromise = new Promise((resolve) => {
|
|
120
|
+
child.on("error", (error) => {
|
|
121
|
+
stderr += `\n${error.message}`;
|
|
122
|
+
});
|
|
123
|
+
child.on("close", (code) => resolve(code ?? 1));
|
|
124
|
+
});
|
|
125
|
+
const timer = setTimeout(() => {
|
|
126
|
+
timedOut = true;
|
|
127
|
+
child.kill();
|
|
128
|
+
}, ATTACHMENT_UPLOAD_TIMEOUT_MS);
|
|
129
|
+
|
|
130
|
+
let uploadError = null;
|
|
131
|
+
try {
|
|
132
|
+
for await (const chunk of request) {
|
|
133
|
+
size += chunk.length;
|
|
134
|
+
if (size > MAX_ATTACHMENT_BYTES) {
|
|
135
|
+
uploadError = attachmentHttpError("单个附件不能超过 50 MiB", 413);
|
|
136
|
+
request.resume();
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
hash.update(chunk);
|
|
140
|
+
if (!child.stdin.write(chunk)) await once(child.stdin, "drain");
|
|
141
|
+
}
|
|
142
|
+
} catch (error) {
|
|
143
|
+
uploadError = error;
|
|
144
|
+
}
|
|
145
|
+
if (uploadError) {
|
|
146
|
+
child.stdin.destroy();
|
|
147
|
+
child.kill();
|
|
148
|
+
} else {
|
|
149
|
+
child.stdin.end();
|
|
150
|
+
}
|
|
151
|
+
const code = await closePromise;
|
|
152
|
+
clearTimeout(timer);
|
|
153
|
+
const remaining = Math.max(0, (sshOperationCounts.get(alias) || 1) - 1);
|
|
154
|
+
if (remaining) sshOperationCounts.set(alias, remaining);
|
|
155
|
+
else sshOperationCounts.delete(alias);
|
|
156
|
+
|
|
157
|
+
if (uploadError) throw uploadError;
|
|
158
|
+
if (timedOut) throw attachmentHttpError("附件上传超过 2 分钟", 504);
|
|
159
|
+
if (code !== 0) {
|
|
160
|
+
throw attachmentHttpError(
|
|
161
|
+
`远端附件写入失败:${cleanSshError(stderr || stdout)}`,
|
|
162
|
+
502,
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
const pathLine = stdout
|
|
166
|
+
.split(/\r?\n/)
|
|
167
|
+
.find((line) => line.startsWith("SCOPE_UPLOAD_PATH="));
|
|
168
|
+
const remotePath = pathLine?.slice("SCOPE_UPLOAD_PATH=".length).trim() || "";
|
|
169
|
+
if (
|
|
170
|
+
!remotePath.startsWith("/") ||
|
|
171
|
+
!remotePath.includes("/.codex/scope-attachments/")
|
|
172
|
+
) {
|
|
173
|
+
throw attachmentHttpError("远端没有返回有效的附件路径", 502);
|
|
174
|
+
}
|
|
175
|
+
return { remotePath, size, sha256: hash.digest("hex") };
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return {
|
|
179
|
+
purgeExpiredAttachments,
|
|
180
|
+
storeUploadedAttachment,
|
|
181
|
+
resolveUploadedAttachments,
|
|
182
|
+
streamAttachmentToHost,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
const DEFAULT_PROFILE_COOLDOWN_MS = 30 * 60_000;
|
|
2
|
+
|
|
3
|
+
export function orderedReadyProfileCandidates(
|
|
4
|
+
profiles,
|
|
5
|
+
activeSlug,
|
|
6
|
+
{
|
|
7
|
+
failedUntil = new Map(),
|
|
8
|
+
now = Date.now(),
|
|
9
|
+
} = {},
|
|
10
|
+
) {
|
|
11
|
+
const ready = (Array.isArray(profiles) ? profiles : []).filter(
|
|
12
|
+
(profile) => profile?.ready && typeof profile.slug === "string" && profile.slug,
|
|
13
|
+
);
|
|
14
|
+
if (ready.length < 2) return [];
|
|
15
|
+
const activeIndex = ready.findIndex((profile) => profile.slug === activeSlug);
|
|
16
|
+
const rotationBase = activeIndex >= 0 ? activeIndex : -1;
|
|
17
|
+
const candidateCount = activeIndex >= 0 ? ready.length - 1 : ready.length;
|
|
18
|
+
const ordered = [];
|
|
19
|
+
for (let offset = 1; offset <= candidateCount; offset += 1) {
|
|
20
|
+
const index = (rotationBase + offset) % ready.length;
|
|
21
|
+
const profile = ready[index];
|
|
22
|
+
if (profile.slug === activeSlug) continue;
|
|
23
|
+
if (Number(failedUntil.get(profile.slug) || 0) > now) continue;
|
|
24
|
+
ordered.push(profile);
|
|
25
|
+
}
|
|
26
|
+
return ordered;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function markProfileUnavailable(
|
|
30
|
+
failedUntil,
|
|
31
|
+
slug,
|
|
32
|
+
{
|
|
33
|
+
now = Date.now(),
|
|
34
|
+
cooldownMs = DEFAULT_PROFILE_COOLDOWN_MS,
|
|
35
|
+
} = {},
|
|
36
|
+
) {
|
|
37
|
+
if (!(failedUntil instanceof Map) || !slug) return null;
|
|
38
|
+
const until = now + Math.max(1_000, Number(cooldownMs) || DEFAULT_PROFILE_COOLDOWN_MS);
|
|
39
|
+
failedUntil.set(slug, until);
|
|
40
|
+
return until;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function publicProfileFailoverJob(job) {
|
|
44
|
+
if (!job) return null;
|
|
45
|
+
return {
|
|
46
|
+
host: job.host,
|
|
47
|
+
status: job.status,
|
|
48
|
+
failedProfile: job.failedProfile || null,
|
|
49
|
+
targetProfile: job.targetProfile || null,
|
|
50
|
+
interruptedSessions: Array.from(job.interruptedSessions || []),
|
|
51
|
+
waitingForSessions: Array.from(job.waitingForSessions || []),
|
|
52
|
+
attemptedProfiles: Array.from(job.attemptedProfiles || []),
|
|
53
|
+
nextAttemptAt: job.nextAttemptAt || null,
|
|
54
|
+
startedAt: job.startedAt,
|
|
55
|
+
completedAt: job.completedAt || null,
|
|
56
|
+
error: job.error || null,
|
|
57
|
+
};
|
|
58
|
+
}
|