scope-agent-workbench 0.0.0-stage → 0.2.3
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 +59 -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 +36 -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 +432 -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 +637 -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 +463 -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 +177 -0
- package/bridge/routes/accounts.mjs +326 -0
- package/bridge/routes/dialogue.mjs +165 -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 +3357 -0
- package/bridge/session-attachments.mjs +150 -0
- package/bridge/session-cache-archive.mjs +22 -0
- package/bridge/session-catalog/agy-history.py +388 -0
- package/bridge/session-catalog/catalog.mjs +110 -0
- package/bridge/session-catalog/probe.py +1207 -0
- package/bridge/session-catalog/routes.mjs +34 -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 +405 -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-BMior55c.js +3 -0
- package/dist/client/assets/index-CNnP2Ses.css +2 -0
- package/dist/client/assets/layout-segment-context-DjGudgXn.js +1 -0
- package/dist/client/assets/page-CJqXlhDs.js +551 -0
- package/dist/client/assets/page-LYzRz6_S.css +1 -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-BB9Dri2u.js +104686 -0
- package/dist/server/ssr/assets/page-LYzRz6_S.css +1 -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/subagent-display-prefs.ts +130 -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 +465 -0
- package/scripts/fixtures/workbench-conversations.mjs +475 -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,839 @@
|
|
|
1
|
+
import { LOCAL_HOST } from "../../lib/execution-host.js";
|
|
2
|
+
import { APP_SERVER_HANDOFF_PROBE, NEW_SESSION_PREFLIGHT } from "../probes/index.mjs";
|
|
3
|
+
import { renderInstructionWithAttachments } from "../session-attachments.mjs";
|
|
4
|
+
import {
|
|
5
|
+
buildExactTmuxTerminateCommand,
|
|
6
|
+
normalizeTmuxSessionName,
|
|
7
|
+
} from "../tmux-session-control.mjs";
|
|
8
|
+
|
|
9
|
+
/** Session creation, closing, takeover, recovery, upgrade, and SSE event stream routes. */
|
|
10
|
+
export function sessionLifecycleRoutes(context) {
|
|
11
|
+
const takeoverJobs = new Set();
|
|
12
|
+
const appServerJobs = new Set();
|
|
13
|
+
|
|
14
|
+
return async (request, response, url) => {
|
|
15
|
+
const {
|
|
16
|
+
TAKEOVER_TIMEOUT_MS,
|
|
17
|
+
appServerAuthRecoveryHosts,
|
|
18
|
+
appServerManager,
|
|
19
|
+
appServerRestoreFailures,
|
|
20
|
+
auditLifecycle,
|
|
21
|
+
cleanSshError,
|
|
22
|
+
clients,
|
|
23
|
+
codexExecutable,
|
|
24
|
+
codexUpgrades,
|
|
25
|
+
detectRemoteSessionWriter,
|
|
26
|
+
findLiveAgent,
|
|
27
|
+
getManagementState,
|
|
28
|
+
getSnapshot,
|
|
29
|
+
historicalSessions,
|
|
30
|
+
hostConfigRestarts,
|
|
31
|
+
hostRuntimeConfig,
|
|
32
|
+
jsonResponse,
|
|
33
|
+
localDirectory,
|
|
34
|
+
newSessionConnectionKey,
|
|
35
|
+
notifyClients,
|
|
36
|
+
persistAppServerSessions,
|
|
37
|
+
persistHistoryIndex,
|
|
38
|
+
persistManagementState,
|
|
39
|
+
persistSnapshotCache,
|
|
40
|
+
publishSnapshotSync,
|
|
41
|
+
readJsonBody,
|
|
42
|
+
recoverAuthenticationFailedSessions,
|
|
43
|
+
recoverHostAppServerSessions,
|
|
44
|
+
recoveryAgent,
|
|
45
|
+
rememberTmuxAgent,
|
|
46
|
+
removeEventClient,
|
|
47
|
+
resolveUploadedAttachments,
|
|
48
|
+
resumeAgentInTmux,
|
|
49
|
+
resumeManagedAppServerSession,
|
|
50
|
+
revealUnarchivedSession,
|
|
51
|
+
runSshCommand,
|
|
52
|
+
saveHostRuntimeConfig,
|
|
53
|
+
scanAll,
|
|
54
|
+
sendTmuxText,
|
|
55
|
+
sessionKey,
|
|
56
|
+
sessionProfileAssignment,
|
|
57
|
+
sessionYolo,
|
|
58
|
+
setSnapshot,
|
|
59
|
+
shellQuote,
|
|
60
|
+
snapshotInvalidationPayload,
|
|
61
|
+
snapshotSyncStore,
|
|
62
|
+
tmuxAgentForDelivery,
|
|
63
|
+
writeEventClient,
|
|
64
|
+
} = context();
|
|
65
|
+
|
|
66
|
+
if (url.pathname === "/api/session/create" && request.method === "POST") {
|
|
67
|
+
try {
|
|
68
|
+
const snapshot = getSnapshot();
|
|
69
|
+
const body = await readJsonBody(request);
|
|
70
|
+
const host = snapshot.hosts.find(
|
|
71
|
+
(candidate) => candidate.alias === body.host,
|
|
72
|
+
);
|
|
73
|
+
if (!host?.reachable) {
|
|
74
|
+
jsonResponse(response, 404, {
|
|
75
|
+
error: `主机 ${body.host || "(未选择)"} 当前不可连接`,
|
|
76
|
+
});
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
const requestedCwd =
|
|
80
|
+
typeof body.cwd === "string" ? body.cwd.trim().slice(0, 4_000) : "";
|
|
81
|
+
const prompt =
|
|
82
|
+
typeof body.prompt === "string"
|
|
83
|
+
? body.prompt.trim().slice(0, 20_000)
|
|
84
|
+
: "";
|
|
85
|
+
const attachments = resolveUploadedAttachments(
|
|
86
|
+
body.attachments,
|
|
87
|
+
host.alias,
|
|
88
|
+
{ scope: "new-session" },
|
|
89
|
+
);
|
|
90
|
+
if (!requestedCwd || (!prompt && !attachments.length)) {
|
|
91
|
+
jsonResponse(response, 400, {
|
|
92
|
+
error: "新任务需要远端工作目录和初始 instruction 或附件",
|
|
93
|
+
});
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
if (host.alias === LOCAL_HOST && (body.transport === "tmux" || body.preLaunchCommand?.trim())) throw new Error("本机 Codex 使用原生 App Server,不支持远端 tmux 或启动脚本");
|
|
97
|
+
const preflight = host.alias === LOCAL_HOST
|
|
98
|
+
? { code: 0, stdout: JSON.stringify({ cwd: await localDirectory(requestedCwd) }) }
|
|
99
|
+
: await runSshCommand(
|
|
100
|
+
host.alias,
|
|
101
|
+
`python3 - ${shellQuote(requestedCwd)}`,
|
|
102
|
+
NEW_SESSION_PREFLIGHT,
|
|
103
|
+
15_000,
|
|
104
|
+
);
|
|
105
|
+
if (preflight.code !== 0) {
|
|
106
|
+
throw new Error(cleanSshError(preflight.stderr || preflight.stdout));
|
|
107
|
+
}
|
|
108
|
+
const resolved = JSON.parse(preflight.stdout.trim());
|
|
109
|
+
const executable =
|
|
110
|
+
host.agents
|
|
111
|
+
.map((agent) => agent.executable)
|
|
112
|
+
.find(
|
|
113
|
+
(candidate) =>
|
|
114
|
+
typeof candidate === "string" &&
|
|
115
|
+
(candidate === "codex" || candidate.endsWith("/codex")),
|
|
116
|
+
) || "codex";
|
|
117
|
+
const transport = body.transport === "tmux" ? "tmux" : "app-server";
|
|
118
|
+
const runtime = await saveHostRuntimeConfig(host.alias, {
|
|
119
|
+
preLaunchCommand: body.preLaunchCommand,
|
|
120
|
+
yolo: body.yolo,
|
|
121
|
+
});
|
|
122
|
+
const sessionOptions = {
|
|
123
|
+
host: host.alias,
|
|
124
|
+
cwd: resolved.cwd,
|
|
125
|
+
model:
|
|
126
|
+
typeof body.model === "string" && body.model.trim()
|
|
127
|
+
? body.model.trim().slice(0, 200)
|
|
128
|
+
: null,
|
|
129
|
+
effort:
|
|
130
|
+
typeof body.effort === "string" && body.effort.trim()
|
|
131
|
+
? body.effort.trim().slice(0, 40)
|
|
132
|
+
: null,
|
|
133
|
+
yolo: runtime.yolo,
|
|
134
|
+
executable,
|
|
135
|
+
};
|
|
136
|
+
const session =
|
|
137
|
+
transport === "tmux"
|
|
138
|
+
? await appServerManager.createDetachedSession(sessionOptions)
|
|
139
|
+
: await appServerManager.createSession({
|
|
140
|
+
...sessionOptions,
|
|
141
|
+
connectionKey: await newSessionConnectionKey(host.alias),
|
|
142
|
+
prompt,
|
|
143
|
+
attachments,
|
|
144
|
+
});
|
|
145
|
+
if (transport === "tmux") {
|
|
146
|
+
const agent = {
|
|
147
|
+
host: host.alias,
|
|
148
|
+
cwd: session.cwd,
|
|
149
|
+
executable,
|
|
150
|
+
rollout: {
|
|
151
|
+
id: session.sessionId,
|
|
152
|
+
path: session.path,
|
|
153
|
+
model: session.model,
|
|
154
|
+
},
|
|
155
|
+
};
|
|
156
|
+
let resumed = null;
|
|
157
|
+
try {
|
|
158
|
+
resumed = await resumeAgentInTmux(
|
|
159
|
+
agent,
|
|
160
|
+
0,
|
|
161
|
+
session.model || "",
|
|
162
|
+
runtime,
|
|
163
|
+
);
|
|
164
|
+
rememberTmuxAgent(agent, resumed);
|
|
165
|
+
const delivery = await sendTmuxText(
|
|
166
|
+
tmuxAgentForDelivery(agent, resumed),
|
|
167
|
+
renderInstructionWithAttachments(prompt, attachments),
|
|
168
|
+
);
|
|
169
|
+
jsonResponse(response, 201, {
|
|
170
|
+
ok: true,
|
|
171
|
+
transport: "tmux",
|
|
172
|
+
session: { ...session, status: "working" },
|
|
173
|
+
tmux: resumed,
|
|
174
|
+
delivery,
|
|
175
|
+
});
|
|
176
|
+
setTimeout(() => scanAll({ hosts: [host.alias] }).catch(() => {}), 700);
|
|
177
|
+
return true;
|
|
178
|
+
} catch (error) {
|
|
179
|
+
// A delivery/verification failure does not prove that the pane is
|
|
180
|
+
// disposable. Keep it alive for inspection and an idempotent retry.
|
|
181
|
+
if (!appServerManager.isManaged(host.alias, session.sessionId)) {
|
|
182
|
+
try {
|
|
183
|
+
await resumeManagedAppServerSession({
|
|
184
|
+
host: host.alias,
|
|
185
|
+
sessionId: session.sessionId,
|
|
186
|
+
path: session.path,
|
|
187
|
+
cwd: session.cwd,
|
|
188
|
+
model: session.model || null,
|
|
189
|
+
effort: session.effort || null,
|
|
190
|
+
yolo: session.yolo !== false,
|
|
191
|
+
executable,
|
|
192
|
+
connectionKey: session.connectionKey,
|
|
193
|
+
});
|
|
194
|
+
} catch (rollbackError) {
|
|
195
|
+
throw new Error(
|
|
196
|
+
`${error.message};回滚 app-server 也失败:${rollbackError.message}`,
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
throw error;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
jsonResponse(response, 201, {
|
|
204
|
+
ok: true,
|
|
205
|
+
transport: "app-server",
|
|
206
|
+
session,
|
|
207
|
+
});
|
|
208
|
+
setTimeout(() => scanAll({ hosts: [host.alias] }).catch(() => {}), 700);
|
|
209
|
+
} catch (error) {
|
|
210
|
+
jsonResponse(response, 502, {
|
|
211
|
+
error: `新建任务失败:${error.message}`,
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
return true;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (url.pathname === "/api/session/close" && request.method === "POST") {
|
|
218
|
+
try {
|
|
219
|
+
const managementState = getManagementState();
|
|
220
|
+
const body = await readJsonBody(request);
|
|
221
|
+
const host = typeof body.host === "string" ? body.host.trim() : "";
|
|
222
|
+
const sessionId =
|
|
223
|
+
typeof body.sessionId === "string" ? body.sessionId.trim() : "";
|
|
224
|
+
if (!host || !sessionId) {
|
|
225
|
+
jsonResponse(response, 400, { error: "缺少主机或 Session ID" });
|
|
226
|
+
return true;
|
|
227
|
+
}
|
|
228
|
+
if (body.confirmation !== `${host}:${sessionId}`) {
|
|
229
|
+
jsonResponse(response, 400, { error: "关闭确认信息不匹配" });
|
|
230
|
+
return true;
|
|
231
|
+
}
|
|
232
|
+
if (!appServerManager.isManaged(host, sessionId)) {
|
|
233
|
+
jsonResponse(response, 409, {
|
|
234
|
+
error:
|
|
235
|
+
"只允许安全关闭 SCOPE 托管的 app-server Session;不会终止活动 tmux、CLI 或 VS Code 进程",
|
|
236
|
+
});
|
|
237
|
+
return true;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const originalWriter = await detectRemoteSessionWriter(host, sessionId);
|
|
241
|
+
const closed = await appServerManager.stopSession(host, sessionId);
|
|
242
|
+
const recoveryRecord = managementState.sessions[sessionKey(host, sessionId)]?.closedSession;
|
|
243
|
+
if (recoveryRecord && originalWriter) recoveryRecord.connectionKey = originalWriter.connectionKey;
|
|
244
|
+
await persistManagementState();
|
|
245
|
+
await persistAppServerSessions();
|
|
246
|
+
await auditLifecycle("app-server-session-stopped", {
|
|
247
|
+
host,
|
|
248
|
+
sessionId,
|
|
249
|
+
interrupted: closed.interrupted,
|
|
250
|
+
rolloutPreserved: true,
|
|
251
|
+
remoteSessionSignalSent: false,
|
|
252
|
+
sharedTransportClosed: false,
|
|
253
|
+
});
|
|
254
|
+
notifyClients();
|
|
255
|
+
jsonResponse(response, 200, {
|
|
256
|
+
ok: true,
|
|
257
|
+
host,
|
|
258
|
+
sessionId,
|
|
259
|
+
stopped: closed.stopped,
|
|
260
|
+
interrupted: closed.interrupted,
|
|
261
|
+
rolloutPreserved: true,
|
|
262
|
+
});
|
|
263
|
+
} catch (error) {
|
|
264
|
+
jsonResponse(response, 409, {
|
|
265
|
+
error: `关闭 Session 失败:${error.message}`,
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
return true;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
if (
|
|
272
|
+
url.pathname === "/api/tmux/session/terminate" &&
|
|
273
|
+
request.method === "POST"
|
|
274
|
+
) {
|
|
275
|
+
try {
|
|
276
|
+
const snapshot = getSnapshot();
|
|
277
|
+
const body = await readJsonBody(request);
|
|
278
|
+
const hostAlias = typeof body.host === "string" ? body.host.trim() : "";
|
|
279
|
+
const tmuxSession = normalizeTmuxSessionName(body.tmuxSession);
|
|
280
|
+
if (!hostAlias) {
|
|
281
|
+
jsonResponse(response, 400, { error: "缺少 SSH 主机" });
|
|
282
|
+
return true;
|
|
283
|
+
}
|
|
284
|
+
if (body.confirmation !== `${hostAlias}:${tmuxSession}`) {
|
|
285
|
+
jsonResponse(response, 400, { error: "终止确认信息不匹配" });
|
|
286
|
+
return true;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
const host = snapshot.hosts.find(
|
|
290
|
+
(candidate) => candidate.alias === hostAlias,
|
|
291
|
+
);
|
|
292
|
+
if (!host?.reachable) {
|
|
293
|
+
jsonResponse(response, 409, { error: "所选 SSH 主机当前不可连接" });
|
|
294
|
+
return true;
|
|
295
|
+
}
|
|
296
|
+
const matchingPanes = host.panes.filter(
|
|
297
|
+
(pane) => pane.session === tmuxSession,
|
|
298
|
+
);
|
|
299
|
+
if (matchingPanes.length === 0) {
|
|
300
|
+
jsonResponse(response, 409, {
|
|
301
|
+
error: "当前扫描结果中没有这个 tmux Session;请刷新后重试",
|
|
302
|
+
});
|
|
303
|
+
return true;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
const result = await runSshCommand(
|
|
307
|
+
hostAlias,
|
|
308
|
+
buildExactTmuxTerminateCommand(tmuxSession),
|
|
309
|
+
"",
|
|
310
|
+
15_000,
|
|
311
|
+
100_000,
|
|
312
|
+
);
|
|
313
|
+
if (result.code !== 0) {
|
|
314
|
+
const missing = result.code === 44 ||
|
|
315
|
+
/SCOPE_TMUX_SESSION_MISSING/.test(result.stderr || result.stdout);
|
|
316
|
+
jsonResponse(response, missing ? 409 : 502, {
|
|
317
|
+
error: missing
|
|
318
|
+
? "该 tmux Session 已经不存在;请刷新列表"
|
|
319
|
+
: `终止 tmux 失败:${cleanSshError(result.stderr || result.stdout)}`,
|
|
320
|
+
});
|
|
321
|
+
return true;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
const terminatedSessionIds = host.agents
|
|
325
|
+
.filter((agent) => agent.pane?.session === tmuxSession)
|
|
326
|
+
.map((agent) => agent.rollout?.id)
|
|
327
|
+
.filter(Boolean);
|
|
328
|
+
host.panes = host.panes.filter((pane) => pane.session !== tmuxSession);
|
|
329
|
+
host.agents = host.agents.filter(
|
|
330
|
+
(agent) => agent.pane?.session !== tmuxSession,
|
|
331
|
+
);
|
|
332
|
+
setSnapshot({
|
|
333
|
+
...snapshot,
|
|
334
|
+
generatedAt: new Date().toISOString(),
|
|
335
|
+
summary: {
|
|
336
|
+
...snapshot.summary,
|
|
337
|
+
codex: snapshot.hosts.reduce(
|
|
338
|
+
(total, candidate) => total + candidate.agents.length,
|
|
339
|
+
0,
|
|
340
|
+
),
|
|
341
|
+
tmux: snapshot.hosts.reduce(
|
|
342
|
+
(total, candidate) => total + candidate.panes.length,
|
|
343
|
+
0,
|
|
344
|
+
),
|
|
345
|
+
},
|
|
346
|
+
});
|
|
347
|
+
await auditLifecycle("tmux-session-terminated", {
|
|
348
|
+
host: hostAlias,
|
|
349
|
+
tmuxSession,
|
|
350
|
+
paneCount: matchingPanes.length,
|
|
351
|
+
sessionIds: terminatedSessionIds,
|
|
352
|
+
rolloutPreserved: true,
|
|
353
|
+
exactTarget: true,
|
|
354
|
+
});
|
|
355
|
+
persistSnapshotCache().catch(() => {});
|
|
356
|
+
notifyClients();
|
|
357
|
+
jsonResponse(response, 200, {
|
|
358
|
+
ok: true,
|
|
359
|
+
host: hostAlias,
|
|
360
|
+
tmuxSession,
|
|
361
|
+
paneCount: matchingPanes.length,
|
|
362
|
+
sessionIds: terminatedSessionIds,
|
|
363
|
+
rolloutPreserved: true,
|
|
364
|
+
});
|
|
365
|
+
setTimeout(() => scanAll({ hosts: [hostAlias] }).catch(() => {}), 700);
|
|
366
|
+
} catch (error) {
|
|
367
|
+
jsonResponse(response, 400, {
|
|
368
|
+
error: `终止 tmux 失败:${error.message}`,
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
return true;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
if (url.pathname === "/api/session/unarchive" && request.method === "POST") {
|
|
375
|
+
try {
|
|
376
|
+
const body = await readJsonBody(request);
|
|
377
|
+
const host = typeof body.host === "string" ? body.host.trim() : "";
|
|
378
|
+
const sessionId =
|
|
379
|
+
typeof body.sessionId === "string" ? body.sessionId.trim() : "";
|
|
380
|
+
if (!host || !sessionId) {
|
|
381
|
+
jsonResponse(response, 400, { error: "缺少主机或 Session ID" });
|
|
382
|
+
return true;
|
|
383
|
+
}
|
|
384
|
+
if (body.confirmation !== `${host}:${sessionId}`) {
|
|
385
|
+
jsonResponse(response, 400, { error: "恢复确认信息不匹配" });
|
|
386
|
+
return true;
|
|
387
|
+
}
|
|
388
|
+
const agent = historicalSessions.get(sessionKey(host, sessionId));
|
|
389
|
+
if (!agent?.rollout?.archived) {
|
|
390
|
+
jsonResponse(response, 409, { error: "该 Session 不在归档日志中" });
|
|
391
|
+
return true;
|
|
392
|
+
}
|
|
393
|
+
const thread = await appServerManager.unarchiveSession(
|
|
394
|
+
host,
|
|
395
|
+
sessionId,
|
|
396
|
+
agent.executable || "codex",
|
|
397
|
+
);
|
|
398
|
+
revealUnarchivedSession(host, sessionId, thread);
|
|
399
|
+
await persistHistoryIndex();
|
|
400
|
+
await auditLifecycle("app-server-session-unarchived", {
|
|
401
|
+
host,
|
|
402
|
+
sessionId,
|
|
403
|
+
rolloutPreserved: true,
|
|
404
|
+
remoteSessionSignalSent: false,
|
|
405
|
+
});
|
|
406
|
+
notifyClients();
|
|
407
|
+
jsonResponse(response, 200, {
|
|
408
|
+
ok: true,
|
|
409
|
+
host,
|
|
410
|
+
sessionId,
|
|
411
|
+
path: thread?.path || null,
|
|
412
|
+
});
|
|
413
|
+
} catch (error) {
|
|
414
|
+
jsonResponse(response, 409, {
|
|
415
|
+
error: `恢复 Session 日志失败:${error.message}`,
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
return true;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
if (url.pathname === "/api/session/takeover" && request.method === "POST") {
|
|
422
|
+
let jobKey = "";
|
|
423
|
+
let releasedAppServerSession = null;
|
|
424
|
+
try {
|
|
425
|
+
const body = await readJsonBody(request);
|
|
426
|
+
const activeAgent = findLiveAgent(body.host, body.sessionId);
|
|
427
|
+
const historicalAgentRecord = historicalSessions.get(
|
|
428
|
+
sessionKey(body.host, body.sessionId),
|
|
429
|
+
);
|
|
430
|
+
const agent = activeAgent || historicalAgentRecord;
|
|
431
|
+
if (!agent?.rollout?.id || !agent.rollout.path) {
|
|
432
|
+
jsonResponse(response, 404, {
|
|
433
|
+
error: "未找到可接管的活动或历史 Session",
|
|
434
|
+
});
|
|
435
|
+
return true;
|
|
436
|
+
}
|
|
437
|
+
if (activeAgent && !activeAgent.appServerManaged) {
|
|
438
|
+
jsonResponse(response, 409, {
|
|
439
|
+
error:
|
|
440
|
+
"安全策略禁止终止或接管活动 CLI/VS Code Session;请先让原 Session 正常退出,再从 Inactive 恢复",
|
|
441
|
+
});
|
|
442
|
+
return true;
|
|
443
|
+
}
|
|
444
|
+
if (activeAgent?.pane) {
|
|
445
|
+
jsonResponse(response, 409, {
|
|
446
|
+
error: `该 Session 已在 tmux ${activeAgent.pane.session} 中运行`,
|
|
447
|
+
});
|
|
448
|
+
return true;
|
|
449
|
+
}
|
|
450
|
+
if (
|
|
451
|
+
activeAgent &&
|
|
452
|
+
!activeAgent.appServerManaged &&
|
|
453
|
+
activeAgent.mapping?.rollout !== "open-fd"
|
|
454
|
+
) {
|
|
455
|
+
jsonResponse(response, 409, {
|
|
456
|
+
error: "当前进程没有精确匹配 rollout FD,拒绝终止",
|
|
457
|
+
});
|
|
458
|
+
return true;
|
|
459
|
+
}
|
|
460
|
+
const requestedPid = Number(body.pid) || 0;
|
|
461
|
+
if (
|
|
462
|
+
activeAgent &&
|
|
463
|
+
!activeAgent.appServerManaged &&
|
|
464
|
+
requestedPid !== activeAgent.pid
|
|
465
|
+
) {
|
|
466
|
+
jsonResponse(response, 409, {
|
|
467
|
+
error: `页面 PID 已过期:请求 ${requestedPid},当前 ${activeAgent.pid}`,
|
|
468
|
+
});
|
|
469
|
+
return true;
|
|
470
|
+
}
|
|
471
|
+
const resumedAgent = await recoveryAgent(agent, activeAgent, body.cwd);
|
|
472
|
+
const requestedRuntime = hostRuntimeConfig(agent.host, {
|
|
473
|
+
yolo:
|
|
474
|
+
typeof body.yolo === "boolean"
|
|
475
|
+
? body.yolo
|
|
476
|
+
: sessionYolo(
|
|
477
|
+
agent.rollout,
|
|
478
|
+
hostRuntimeConfig(agent.host).yolo,
|
|
479
|
+
),
|
|
480
|
+
});
|
|
481
|
+
|
|
482
|
+
jobKey = sessionKey(agent.host, agent.rollout.id);
|
|
483
|
+
if (takeoverJobs.has(jobKey)) {
|
|
484
|
+
jsonResponse(response, 409, { error: "该 Session 正在接管中" });
|
|
485
|
+
return true;
|
|
486
|
+
}
|
|
487
|
+
takeoverJobs.add(jobKey);
|
|
488
|
+
|
|
489
|
+
const wasAppServerManaged = appServerManager.isManaged(
|
|
490
|
+
agent.host,
|
|
491
|
+
agent.rollout.id,
|
|
492
|
+
);
|
|
493
|
+
if (wasAppServerManaged) {
|
|
494
|
+
releasedAppServerSession = await appServerManager.releaseSession(
|
|
495
|
+
agent.host,
|
|
496
|
+
agent.rollout.id,
|
|
497
|
+
);
|
|
498
|
+
}
|
|
499
|
+
let takeover;
|
|
500
|
+
try {
|
|
501
|
+
takeover = await resumeAgentInTmux(
|
|
502
|
+
resumedAgent,
|
|
503
|
+
0,
|
|
504
|
+
releasedAppServerSession?.model || agent.rollout.model || "",
|
|
505
|
+
{
|
|
506
|
+
...requestedRuntime,
|
|
507
|
+
yolo:
|
|
508
|
+
typeof body.yolo === "boolean"
|
|
509
|
+
? body.yolo
|
|
510
|
+
: releasedAppServerSession?.yolo !== false &&
|
|
511
|
+
requestedRuntime.yolo,
|
|
512
|
+
},
|
|
513
|
+
);
|
|
514
|
+
} catch (error) {
|
|
515
|
+
if (releasedAppServerSession) {
|
|
516
|
+
try {
|
|
517
|
+
await resumeManagedAppServerSession({
|
|
518
|
+
host: agent.host,
|
|
519
|
+
sessionId: agent.rollout.id,
|
|
520
|
+
path: agent.rollout.path,
|
|
521
|
+
cwd: resumedAgent.cwd,
|
|
522
|
+
model:
|
|
523
|
+
releasedAppServerSession.model || agent.rollout.model || null,
|
|
524
|
+
effort:
|
|
525
|
+
releasedAppServerSession.effort ||
|
|
526
|
+
agent.rollout.reasoningEffort ||
|
|
527
|
+
null,
|
|
528
|
+
yolo: releasedAppServerSession.yolo !== false,
|
|
529
|
+
executable: agent.executable || "codex",
|
|
530
|
+
connectionKey: releasedAppServerSession.connectionKey,
|
|
531
|
+
});
|
|
532
|
+
releasedAppServerSession = null;
|
|
533
|
+
} catch (rollbackError) {
|
|
534
|
+
throw new Error(
|
|
535
|
+
`${error.message};回滚 app-server 也失败:${rollbackError.message}`,
|
|
536
|
+
);
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
throw error;
|
|
540
|
+
}
|
|
541
|
+
rememberTmuxAgent(resumedAgent, takeover);
|
|
542
|
+
jsonResponse(response, 200, {
|
|
543
|
+
...takeover,
|
|
544
|
+
host: agent.host,
|
|
545
|
+
transport: "tmux",
|
|
546
|
+
switchedFrom: wasAppServerManaged ? "app-server" : "cli",
|
|
547
|
+
mode: activeAgent ? "active" : "history",
|
|
548
|
+
cwd: resumedAgent.cwd,
|
|
549
|
+
});
|
|
550
|
+
setTimeout(() => scanAll({ hosts: [agent.host] }).catch(() => {}), 700);
|
|
551
|
+
} catch (error) {
|
|
552
|
+
jsonResponse(response, error.statusCode || 502, {
|
|
553
|
+
error: `一键接管失败:${error.message}`,
|
|
554
|
+
});
|
|
555
|
+
} finally {
|
|
556
|
+
if (jobKey) takeoverJobs.delete(jobKey);
|
|
557
|
+
}
|
|
558
|
+
return true;
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
if (url.pathname === "/api/codex/upgrade" && ["GET", "POST"].includes(request.method)) {
|
|
562
|
+
try {
|
|
563
|
+
const snapshot = getSnapshot();
|
|
564
|
+
const body = request.method === "POST" ? await readJsonBody(request) : null;
|
|
565
|
+
const host = body?.host || url.searchParams.get("host");
|
|
566
|
+
if (!host || !snapshot.hosts.some((h) => h.alias === host)) throw new Error("未知 SSH 主机");
|
|
567
|
+
if (body) {
|
|
568
|
+
if (!snapshot.hosts.some((h) => h.alias === host && h.reachable)) throw new Error("主机不可连接");
|
|
569
|
+
if (body.action === "upgrade" && body.confirmation !== "upgrade:" + host) throw new Error("必须确认升级的目标主机");
|
|
570
|
+
if (hostConfigRestarts.view(host)?.status === "running" || appServerAuthRecoveryHosts.has(host)) throw new Error("主机正在恢复或迁移账号");
|
|
571
|
+
codexUpgrades.start(host, body.action);
|
|
572
|
+
}
|
|
573
|
+
jsonResponse(response, body ? 202 : 200, codexUpgrades.view(host));
|
|
574
|
+
} catch (error) { jsonResponse(response, 409, { error: error.message }); }
|
|
575
|
+
return true;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
if (url.pathname === "/api/app-server/restart-host" && ["GET", "POST"].includes(request.method)) {
|
|
579
|
+
try {
|
|
580
|
+
const snapshot = getSnapshot();
|
|
581
|
+
const body = request.method === "POST" ? await readJsonBody(request) : null;
|
|
582
|
+
const host = body?.host || url.searchParams.get("host");
|
|
583
|
+
if (!host || !snapshot.hosts.some((h) => h.alias === host)) throw new Error("未知 SSH 主机");
|
|
584
|
+
if (body) {
|
|
585
|
+
if (body.confirmation !== `restart:${host}`) throw new Error("必须确认目标主机以及当前回合影响");
|
|
586
|
+
if (codexUpgrades.view(host)?.status === "running") throw new Error("Codex 升级正在进行,请在主机设置查看进度");
|
|
587
|
+
hostConfigRestarts.start(host);
|
|
588
|
+
}
|
|
589
|
+
jsonResponse(response, body ? 202 : 200, hostConfigRestarts.view(host));
|
|
590
|
+
} catch (error) { jsonResponse(response, 409, { error: error.message }); }
|
|
591
|
+
return true;
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
if (
|
|
595
|
+
url.pathname === "/api/app-server/recover-host" &&
|
|
596
|
+
request.method === "POST"
|
|
597
|
+
) {
|
|
598
|
+
try {
|
|
599
|
+
const body = await readJsonBody(request);
|
|
600
|
+
if (sessionProfileAssignment(body.host, body.sessionId)?.desiredProfile) {
|
|
601
|
+
throw new Error("此会话已固定 Profile,请使用 App Server 恢复;tmux 尚不支持会话级账号隔离");
|
|
602
|
+
}
|
|
603
|
+
const host = typeof body.host === "string" ? body.host.trim() : "";
|
|
604
|
+
if (!host || body.confirmation !== host) {
|
|
605
|
+
jsonResponse(response, 400, {
|
|
606
|
+
error: "必须明确确认目标主机名后才能恢复主机 Session",
|
|
607
|
+
});
|
|
608
|
+
return true;
|
|
609
|
+
}
|
|
610
|
+
const result = await recoverHostAppServerSessions(host);
|
|
611
|
+
jsonResponse(response, result.ok ? 200 : 207, result);
|
|
612
|
+
} catch (error) {
|
|
613
|
+
jsonResponse(response, error.statusCode || 502, {
|
|
614
|
+
error: `恢复主机 Session 失败:${error.message}`,
|
|
615
|
+
});
|
|
616
|
+
}
|
|
617
|
+
return true;
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
if (
|
|
621
|
+
url.pathname === "/api/app-server/recover-auth-failures" &&
|
|
622
|
+
request.method === "POST"
|
|
623
|
+
) {
|
|
624
|
+
try {
|
|
625
|
+
const body = await readJsonBody(request);
|
|
626
|
+
const host = typeof body.host === "string" ? body.host.trim() : "";
|
|
627
|
+
if (!host || body.confirmation !== host) {
|
|
628
|
+
jsonResponse(response, 400, {
|
|
629
|
+
error: "必须明确确认目标主机名后才能恢复认证中断的 Session",
|
|
630
|
+
});
|
|
631
|
+
return true;
|
|
632
|
+
}
|
|
633
|
+
const sessionIds = Array.isArray(body.sessionIds)
|
|
634
|
+
? body.sessionIds.slice(0, 100)
|
|
635
|
+
: [];
|
|
636
|
+
if (!sessionIds.length) {
|
|
637
|
+
jsonResponse(response, 400, { error: "没有指定需要恢复的 Session" });
|
|
638
|
+
return true;
|
|
639
|
+
}
|
|
640
|
+
const result = await recoverAuthenticationFailedSessions(host, { sessionIds });
|
|
641
|
+
jsonResponse(response, result.ok ? 200 : 207, result);
|
|
642
|
+
} catch (error) {
|
|
643
|
+
jsonResponse(response, error.statusCode || 502, {
|
|
644
|
+
error: `恢复认证中断的 Session 失败:${error.message}`,
|
|
645
|
+
});
|
|
646
|
+
}
|
|
647
|
+
return true;
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
if (
|
|
651
|
+
url.pathname === "/api/app-server/connect" &&
|
|
652
|
+
request.method === "POST"
|
|
653
|
+
) {
|
|
654
|
+
let jobKey = "";
|
|
655
|
+
try {
|
|
656
|
+
const managementState = getManagementState();
|
|
657
|
+
const body = await readJsonBody(request);
|
|
658
|
+
const activeAgent = findLiveAgent(body.host, body.sessionId);
|
|
659
|
+
const historicalAgentRecord = historicalSessions.get(
|
|
660
|
+
sessionKey(body.host, body.sessionId),
|
|
661
|
+
);
|
|
662
|
+
const closedRecord = managementState.sessions[sessionKey(body.host, body.sessionId)]?.closedSession;
|
|
663
|
+
const agent = activeAgent || historicalAgentRecord || (closedRecord && {
|
|
664
|
+
host: closedRecord.host, cwd: closedRecord.cwd, executable: closedRecord.executable,
|
|
665
|
+
appServerManaged: true, rollout: { id: closedRecord.sessionId, path: closedRecord.path,
|
|
666
|
+
model: closedRecord.model, reasoningEffort: closedRecord.effort },
|
|
667
|
+
});
|
|
668
|
+
if (!agent?.rollout?.id || !agent.rollout.path) {
|
|
669
|
+
jsonResponse(response, 404, {
|
|
670
|
+
error: "未找到可接入 app-server 的活动或历史 Session",
|
|
671
|
+
});
|
|
672
|
+
return true;
|
|
673
|
+
}
|
|
674
|
+
if (activeAgent && !activeAgent.appServerManaged) {
|
|
675
|
+
jsonResponse(response, 409, {
|
|
676
|
+
error:
|
|
677
|
+
"安全策略禁止终止或接管活动 CLI/VS Code Session;请先让原 Session 正常退出,再从 Inactive 恢复",
|
|
678
|
+
});
|
|
679
|
+
return true;
|
|
680
|
+
}
|
|
681
|
+
if (appServerManager.isConnected(agent.host, agent.rollout.id)) {
|
|
682
|
+
jsonResponse(response, 200, {
|
|
683
|
+
ok: true,
|
|
684
|
+
alreadyConnected: true,
|
|
685
|
+
host: agent.host,
|
|
686
|
+
sessionId: agent.rollout.id,
|
|
687
|
+
});
|
|
688
|
+
return true;
|
|
689
|
+
}
|
|
690
|
+
if (
|
|
691
|
+
activeAgent &&
|
|
692
|
+
!activeAgent.appServerManaged &&
|
|
693
|
+
activeAgent.mapping?.rollout !== "open-fd"
|
|
694
|
+
) {
|
|
695
|
+
jsonResponse(response, 409, {
|
|
696
|
+
error: "当前进程没有精确匹配 rollout FD,拒绝终止",
|
|
697
|
+
});
|
|
698
|
+
return true;
|
|
699
|
+
}
|
|
700
|
+
const requestedPid = Number(body.pid) || 0;
|
|
701
|
+
if (
|
|
702
|
+
activeAgent &&
|
|
703
|
+
!activeAgent.appServerManaged &&
|
|
704
|
+
requestedPid !== activeAgent.pid
|
|
705
|
+
) {
|
|
706
|
+
jsonResponse(response, 409, {
|
|
707
|
+
error: `页面 PID 已过期:请求 ${requestedPid},当前 ${activeAgent.pid}`,
|
|
708
|
+
});
|
|
709
|
+
return true;
|
|
710
|
+
}
|
|
711
|
+
const resumedAgent = await recoveryAgent(agent, activeAgent, body.cwd);
|
|
712
|
+
const requestedYolo =
|
|
713
|
+
typeof body.yolo === "boolean"
|
|
714
|
+
? body.yolo
|
|
715
|
+
: sessionYolo(
|
|
716
|
+
agent.rollout,
|
|
717
|
+
hostRuntimeConfig(agent.host).yolo,
|
|
718
|
+
);
|
|
719
|
+
|
|
720
|
+
jobKey = sessionKey(agent.host, agent.rollout.id);
|
|
721
|
+
if (appServerJobs.has(jobKey)) {
|
|
722
|
+
jsonResponse(response, 409, {
|
|
723
|
+
error: "该 Session 正在切换到 app-server",
|
|
724
|
+
});
|
|
725
|
+
return true;
|
|
726
|
+
}
|
|
727
|
+
appServerJobs.add(jobKey);
|
|
728
|
+
|
|
729
|
+
const originalWriter = closedRecord?.connectionKey
|
|
730
|
+
? { connectionKey: closedRecord.connectionKey }
|
|
731
|
+
: await detectRemoteSessionWriter(agent.host, agent.rollout.id);
|
|
732
|
+
const recoveryConnectionKey = originalWriter?.connectionKey || await newSessionConnectionKey(agent.host);
|
|
733
|
+
// Reconnect the original SCOPE writer without killing it or scanning every FD.
|
|
734
|
+
await appServerManager.prepareHost(
|
|
735
|
+
resumedAgent.host,
|
|
736
|
+
codexExecutable(resumedAgent.executable),
|
|
737
|
+
recoveryConnectionKey,
|
|
738
|
+
);
|
|
739
|
+
|
|
740
|
+
let handoff = { killedPid: null, forced: false };
|
|
741
|
+
if (!agent.appServerManaged && !originalWriter) {
|
|
742
|
+
const pid = 0;
|
|
743
|
+
const command = [
|
|
744
|
+
"python3 -",
|
|
745
|
+
shellQuote(String(pid)),
|
|
746
|
+
shellQuote(resumedAgent.rollout.path),
|
|
747
|
+
shellQuote(resumedAgent.cwd || "."),
|
|
748
|
+
].join(" ");
|
|
749
|
+
const result = await runSshCommand(
|
|
750
|
+
agent.host,
|
|
751
|
+
command,
|
|
752
|
+
APP_SERVER_HANDOFF_PROBE,
|
|
753
|
+
TAKEOVER_TIMEOUT_MS,
|
|
754
|
+
1_000_000,
|
|
755
|
+
);
|
|
756
|
+
if (result.code !== 0) {
|
|
757
|
+
throw new Error(cleanSshError(result.stderr || result.stdout));
|
|
758
|
+
}
|
|
759
|
+
try {
|
|
760
|
+
handoff = JSON.parse(result.stdout.trim());
|
|
761
|
+
} catch {
|
|
762
|
+
throw new Error("远端 app-server 接管校验结果无法解析");
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
const session = await resumeManagedAppServerSession({
|
|
767
|
+
host: resumedAgent.host,
|
|
768
|
+
connectionKey: recoveryConnectionKey,
|
|
769
|
+
sessionId: resumedAgent.rollout.id,
|
|
770
|
+
path: resumedAgent.rollout.path,
|
|
771
|
+
cwd: resumedAgent.cwd,
|
|
772
|
+
model: resumedAgent.rollout.model || null,
|
|
773
|
+
effort: resumedAgent.rollout.reasoningEffort || null,
|
|
774
|
+
yolo: requestedYolo,
|
|
775
|
+
executable: codexExecutable(resumedAgent.executable),
|
|
776
|
+
});
|
|
777
|
+
appServerRestoreFailures.delete(jobKey);
|
|
778
|
+
jsonResponse(response, 200, {
|
|
779
|
+
ok: true,
|
|
780
|
+
alreadyConnected: false,
|
|
781
|
+
...handoff,
|
|
782
|
+
session,
|
|
783
|
+
mode: activeAgent ? "active" : "history",
|
|
784
|
+
cwd: resumedAgent.cwd,
|
|
785
|
+
});
|
|
786
|
+
setTimeout(() => scanAll({ hosts: [agent.host] }).catch(() => {}), 700);
|
|
787
|
+
} catch (error) {
|
|
788
|
+
jsonResponse(response, error.statusCode || 502, {
|
|
789
|
+
error: `切换到 app-server 失败:${error.message}`,
|
|
790
|
+
});
|
|
791
|
+
} finally {
|
|
792
|
+
if (jobKey) appServerJobs.delete(jobKey);
|
|
793
|
+
}
|
|
794
|
+
return true;
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
if (
|
|
798
|
+
url.pathname === "/api/app-server/respond" &&
|
|
799
|
+
request.method === "POST"
|
|
800
|
+
) {
|
|
801
|
+
try {
|
|
802
|
+
const body = await readJsonBody(request);
|
|
803
|
+
if (typeof body.key !== "string" || !body.key) {
|
|
804
|
+
jsonResponse(response, 400, { error: "缺少待回答问题 key" });
|
|
805
|
+
return true;
|
|
806
|
+
}
|
|
807
|
+
const result = await appServerManager.answerHumanRequest(
|
|
808
|
+
body.key,
|
|
809
|
+
body.response || { answers: body.answers },
|
|
810
|
+
);
|
|
811
|
+
jsonResponse(response, 200, { ok: true, ...result });
|
|
812
|
+
} catch (error) {
|
|
813
|
+
jsonResponse(response, 409, { error: error.message });
|
|
814
|
+
}
|
|
815
|
+
return true;
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
if (url.pathname === "/api/events" && request.method === "GET") {
|
|
819
|
+
if (snapshotSyncStore.info().revision === 0) publishSnapshotSync();
|
|
820
|
+
response.writeHead(200, {
|
|
821
|
+
"Content-Type": "text/event-stream; charset=utf-8",
|
|
822
|
+
"Cache-Control": "no-cache, no-transform",
|
|
823
|
+
Connection: "keep-alive",
|
|
824
|
+
});
|
|
825
|
+
const client = {
|
|
826
|
+
response,
|
|
827
|
+
blocked: false,
|
|
828
|
+
pending: null,
|
|
829
|
+
onDrain: null,
|
|
830
|
+
};
|
|
831
|
+
clients.set(response, client);
|
|
832
|
+
writeEventClient(client, snapshotInvalidationPayload());
|
|
833
|
+
request.once("close", () => removeEventClient(response));
|
|
834
|
+
return true;
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
return false;
|
|
838
|
+
};
|
|
839
|
+
}
|