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,171 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { WebSocket, WebSocketServer } from "ws";
|
|
3
|
+
import { normalizeTmuxSessionName } from "./tmux-session-control.mjs";
|
|
4
|
+
import { normalizeRemoteAbsolutePath } from "./vscode-opener.mjs";
|
|
5
|
+
import {
|
|
6
|
+
buildRemoteTerminalCommand,
|
|
7
|
+
sshTerminalArguments,
|
|
8
|
+
terminalDimension,
|
|
9
|
+
} from "./web-terminal.mjs";
|
|
10
|
+
|
|
11
|
+
export function attachTerminalGateway({
|
|
12
|
+
server,
|
|
13
|
+
host,
|
|
14
|
+
trustedOrigins,
|
|
15
|
+
getSnapshot,
|
|
16
|
+
sshTimeoutMs,
|
|
17
|
+
auditLifecycle,
|
|
18
|
+
}) {
|
|
19
|
+
const terminalWebSocketServer = new WebSocketServer({
|
|
20
|
+
noServer: true,
|
|
21
|
+
perMessageDeflate: false,
|
|
22
|
+
maxPayload: 128 * 1024,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
function rejectTerminalUpgrade(socket, statusCode, message) {
|
|
26
|
+
const reason = String(message || "Terminal connection rejected").replace(/[\r\n]+/g, " ");
|
|
27
|
+
socket.write(
|
|
28
|
+
`HTTP/1.1 ${statusCode} ${reason}\r\nConnection: close\r\nContent-Length: 0\r\n\r\n`,
|
|
29
|
+
);
|
|
30
|
+
socket.destroy();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
server.on("upgrade", (request, socket, head) => {
|
|
34
|
+
let requestUrl;
|
|
35
|
+
try {
|
|
36
|
+
requestUrl = new URL(request.url || "/", `http://${request.headers.host || host}`);
|
|
37
|
+
} catch {
|
|
38
|
+
rejectTerminalUpgrade(socket, 400, "Bad Request");
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (requestUrl.pathname !== "/terminal") {
|
|
42
|
+
rejectTerminalUpgrade(socket, 404, "Not Found");
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const origin = request.headers.origin;
|
|
46
|
+
if (origin && !trustedOrigins.has(origin)) {
|
|
47
|
+
rejectTerminalUpgrade(socket, 403, "Forbidden");
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const targetHost = (requestUrl.searchParams.get("host") || "").trim();
|
|
51
|
+
const knownHost = getSnapshot().hosts.find((candidate) => candidate.alias === targetHost);
|
|
52
|
+
if (!knownHost) {
|
|
53
|
+
rejectTerminalUpgrade(socket, 404, "Unknown SSH host");
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
let cwd = "";
|
|
57
|
+
let tmuxSession = "";
|
|
58
|
+
try {
|
|
59
|
+
const requestedCwd = (requestUrl.searchParams.get("cwd") || "").trim();
|
|
60
|
+
cwd = requestedCwd
|
|
61
|
+
? normalizeRemoteAbsolutePath(requestedCwd, "远端工作目录")
|
|
62
|
+
: "";
|
|
63
|
+
if (requestUrl.searchParams.get("mode") === "tmux") {
|
|
64
|
+
tmuxSession = normalizeTmuxSessionName(
|
|
65
|
+
requestUrl.searchParams.get("tmux") || "",
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
} catch (error) {
|
|
69
|
+
rejectTerminalUpgrade(socket, 400, error.message);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const cols = terminalDimension(requestUrl.searchParams.get("cols"), 100, 400);
|
|
73
|
+
const rows = terminalDimension(requestUrl.searchParams.get("rows"), 28, 200);
|
|
74
|
+
terminalWebSocketServer.handleUpgrade(request, socket, head, (webSocket) => {
|
|
75
|
+
terminalWebSocketServer.emit("connection", webSocket, request, {
|
|
76
|
+
host: targetHost,
|
|
77
|
+
cwd,
|
|
78
|
+
tmuxSession,
|
|
79
|
+
cols,
|
|
80
|
+
rows,
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
terminalWebSocketServer.on("connection", (webSocket, _request, target) => {
|
|
86
|
+
const command = buildRemoteTerminalCommand({
|
|
87
|
+
cwd: target.cwd,
|
|
88
|
+
tmuxSession: target.tmuxSession ? `=${target.tmuxSession}` : "",
|
|
89
|
+
cols: target.cols,
|
|
90
|
+
rows: target.rows,
|
|
91
|
+
});
|
|
92
|
+
const child = spawn(
|
|
93
|
+
(typeof process !== "undefined" && process.platform === "win32" ? "ssh.exe" : "ssh"),
|
|
94
|
+
sshTerminalArguments({
|
|
95
|
+
host: target.host,
|
|
96
|
+
command,
|
|
97
|
+
timeoutSeconds: Math.ceil(sshTimeoutMs / 1_000),
|
|
98
|
+
}),
|
|
99
|
+
{
|
|
100
|
+
windowsHide: true,
|
|
101
|
+
env: { ...process.env, TERM: "xterm-256color", COLORTERM: "truecolor" },
|
|
102
|
+
},
|
|
103
|
+
);
|
|
104
|
+
let closed = false;
|
|
105
|
+
const send = (message) => {
|
|
106
|
+
if (webSocket.readyState !== WebSocket.OPEN) return false;
|
|
107
|
+
if (webSocket.bufferedAmount > 2 * 1024 * 1024) {
|
|
108
|
+
webSocket.close(1013, "terminal output exceeded browser buffer");
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
webSocket.send(JSON.stringify(message));
|
|
112
|
+
return true;
|
|
113
|
+
};
|
|
114
|
+
const stopLocalSsh = () => {
|
|
115
|
+
if (closed) return;
|
|
116
|
+
closed = true;
|
|
117
|
+
if (!child.killed) child.kill();
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
auditLifecycle("web-terminal-opened", {
|
|
121
|
+
host: target.host,
|
|
122
|
+
cwd: target.cwd,
|
|
123
|
+
mode: target.tmuxSession ? "tmux" : "shell",
|
|
124
|
+
tmuxSession: target.tmuxSession || null,
|
|
125
|
+
remoteSessionSignalSent: false,
|
|
126
|
+
});
|
|
127
|
+
send({ type: "status", status: "connected" });
|
|
128
|
+
child.stdout.on("data", (chunk) => send({ type: "output", data: chunk.toString("utf8") }));
|
|
129
|
+
child.stderr.on("data", (chunk) => send({ type: "output", data: chunk.toString("utf8") }));
|
|
130
|
+
child.stdin.on("error", () => {});
|
|
131
|
+
child.on("error", (error) => {
|
|
132
|
+
send({ type: "error", message: `本机 SSH 启动失败:${error.message}` });
|
|
133
|
+
});
|
|
134
|
+
child.on("close", (code) => {
|
|
135
|
+
send({ type: "exit", code: code ?? 1 });
|
|
136
|
+
if (webSocket.readyState === WebSocket.OPEN) {
|
|
137
|
+
webSocket.close(1000, "ssh process exited");
|
|
138
|
+
}
|
|
139
|
+
closed = true;
|
|
140
|
+
auditLifecycle("web-terminal-closed", {
|
|
141
|
+
host: target.host,
|
|
142
|
+
mode: target.tmuxSession ? "tmux" : "shell",
|
|
143
|
+
code: code ?? 1,
|
|
144
|
+
remoteSessionSignalSent: false,
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
webSocket.on("message", (payload, binary) => {
|
|
148
|
+
if (binary || child.stdin.destroyed) return;
|
|
149
|
+
try {
|
|
150
|
+
const message = JSON.parse(payload.toString("utf8"));
|
|
151
|
+
if (message?.type !== "input" || typeof message.data !== "string") return;
|
|
152
|
+
if (Buffer.byteLength(message.data, "utf8") > 64 * 1024) {
|
|
153
|
+
send({ type: "error", message: "单次终端输入超过 64 KiB,已拒绝" });
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
child.stdin.write(message.data);
|
|
157
|
+
} catch {
|
|
158
|
+
send({ type: "error", message: "终端输入协议无效" });
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
webSocket.on("close", stopLocalSsh);
|
|
162
|
+
webSocket.on("error", stopLocalSsh);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
process.once("exit", () => {
|
|
166
|
+
for (const client of terminalWebSocketServer.clients) client.close(1001, "Bridge stopping");
|
|
167
|
+
terminalWebSocketServer.close();
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
return terminalWebSocketServer;
|
|
171
|
+
}
|
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
+
import {
|
|
3
|
+
CAPACITY_CONTINUE_PROMPT,
|
|
4
|
+
DEFAULT_CAPACITY_RETRY_DELAYS_MS,
|
|
5
|
+
countModelCapacityWarnings,
|
|
6
|
+
hasUnansweredModelCapacityWarning,
|
|
7
|
+
} from "./capacity-recovery.mjs";
|
|
8
|
+
|
|
9
|
+
export function createTmuxDelivery({
|
|
10
|
+
findAgent,
|
|
11
|
+
sessionKey,
|
|
12
|
+
shellQuote,
|
|
13
|
+
runSshCommand,
|
|
14
|
+
cleanSshError,
|
|
15
|
+
notifyClients,
|
|
16
|
+
}) {
|
|
17
|
+
const tmuxCapacityRecoveries = new Map();
|
|
18
|
+
|
|
19
|
+
function cancelTmuxCapacityRecovery(host, sessionId) {
|
|
20
|
+
const key = sessionKey(host, sessionId);
|
|
21
|
+
const recovery = tmuxCapacityRecoveries.get(key);
|
|
22
|
+
if (recovery?.timer) clearTimeout(recovery.timer);
|
|
23
|
+
tmuxCapacityRecoveries.delete(key);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function publicTmuxCapacityRecovery(agent) {
|
|
27
|
+
if (!agent?.rollout?.id) return null;
|
|
28
|
+
const recovery = tmuxCapacityRecoveries.get(
|
|
29
|
+
sessionKey(agent.host, agent.rollout.id),
|
|
30
|
+
);
|
|
31
|
+
if (!recovery) return null;
|
|
32
|
+
return {
|
|
33
|
+
status: recovery.status,
|
|
34
|
+
attempt: recovery.attempt,
|
|
35
|
+
maxAttempts: DEFAULT_CAPACITY_RETRY_DELAYS_MS.length,
|
|
36
|
+
nextRetryAt: recovery.nextRetryAt,
|
|
37
|
+
lastError: recovery.lastError,
|
|
38
|
+
lastContinueAt: recovery.lastContinueAt,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async function sendTmuxText(
|
|
43
|
+
agent,
|
|
44
|
+
text,
|
|
45
|
+
requestedDeliveryId = randomUUID(),
|
|
46
|
+
{ preserveCapacityRecovery = false } = {},
|
|
47
|
+
) {
|
|
48
|
+
if (!agent?.rollout || !agent.pane) {
|
|
49
|
+
throw new Error("该会话未精确匹配 tmux,不能安全注入输入");
|
|
50
|
+
}
|
|
51
|
+
if (!preserveCapacityRecovery) {
|
|
52
|
+
cancelTmuxCapacityRecovery(agent.host, agent.rollout.id);
|
|
53
|
+
}
|
|
54
|
+
const deliveryId = /^[a-zA-Z0-9-]{8,80}$/.test(requestedDeliveryId)
|
|
55
|
+
? requestedDeliveryId
|
|
56
|
+
: randomUUID();
|
|
57
|
+
const encoded = Buffer.from(String(text), "utf8").toString("base64");
|
|
58
|
+
const target = `${agent.pane.session}:${agent.pane.pane}`;
|
|
59
|
+
const buffer = `scope-${Date.now()}-${Math.random().toString(16).slice(2, 8)}`;
|
|
60
|
+
const deliveryOption = `@scope_delivery_${createHash("sha256")
|
|
61
|
+
.update(target)
|
|
62
|
+
.digest("hex")
|
|
63
|
+
.slice(0, 24)}`;
|
|
64
|
+
const pastedState = `pasted:${deliveryId}`;
|
|
65
|
+
const submittedState = `submitted:${deliveryId}`;
|
|
66
|
+
const acknowledge = (status) =>
|
|
67
|
+
`tmux display-message -p -t ${shellQuote(target)} ${shellQuote(
|
|
68
|
+
`SCOPE_ACK|#{pane_current_command}|#{pane_dead}|#{pane_pid}|${status}`,
|
|
69
|
+
)}`;
|
|
70
|
+
const command = [
|
|
71
|
+
`scope_state=$(tmux show-options -gqv ${shellQuote(deliveryOption)} 2>/dev/null || true);`,
|
|
72
|
+
`if [ "$scope_state" = ${shellQuote(submittedState)} ]; then ${acknowledge(
|
|
73
|
+
"deduplicated",
|
|
74
|
+
)}; exit 0; fi;`,
|
|
75
|
+
`if [ "$scope_state" = ${shellQuote(pastedState)} ]; then`,
|
|
76
|
+
`tmux send-keys -t ${shellQuote(target)} C-m`,
|
|
77
|
+
`&& tmux set-option -gq ${shellQuote(deliveryOption)} ${shellQuote(
|
|
78
|
+
submittedState,
|
|
79
|
+
)}`,
|
|
80
|
+
`&& sleep 0.2 && ${acknowledge("recovered")}; exit $?; fi;`,
|
|
81
|
+
`printf %s ${shellQuote(encoded)} | base64 -d`,
|
|
82
|
+
`| tmux load-buffer -b ${shellQuote(buffer)} -`,
|
|
83
|
+
`&& tmux paste-buffer -b ${shellQuote(buffer)} -t ${shellQuote(target)} -d`,
|
|
84
|
+
`&& tmux set-option -gq ${shellQuote(deliveryOption)} ${shellQuote(
|
|
85
|
+
pastedState,
|
|
86
|
+
)}`,
|
|
87
|
+
// Codex enables bracketed paste. Sending Enter in the same instant as the
|
|
88
|
+
// paste can be swallowed, leaving the text visibly parked in the editor.
|
|
89
|
+
`&& sleep 0.35`,
|
|
90
|
+
`&& tmux send-keys -t ${shellQuote(target)} C-m`,
|
|
91
|
+
`&& tmux set-option -gq ${shellQuote(deliveryOption)} ${shellQuote(
|
|
92
|
+
submittedState,
|
|
93
|
+
)}`,
|
|
94
|
+
`&& sleep 0.2`,
|
|
95
|
+
`&& ${acknowledge("submitted")}`,
|
|
96
|
+
].join(" ");
|
|
97
|
+
|
|
98
|
+
let result = await runSshCommand(agent.host, command, "", 15_000);
|
|
99
|
+
let ackLine = result.stdout
|
|
100
|
+
.split(/\r?\n/)
|
|
101
|
+
.find((line) => line.startsWith("SCOPE_ACK|"));
|
|
102
|
+
if (!ackLine) {
|
|
103
|
+
// Re-running the same delivery id is safe: the remote tmux option either
|
|
104
|
+
// confirms submission or completes a paste whose Enter was interrupted.
|
|
105
|
+
result = await runSshCommand(agent.host, command, "", 15_000);
|
|
106
|
+
ackLine = result.stdout
|
|
107
|
+
.split(/\r?\n/)
|
|
108
|
+
.find((line) => line.startsWith("SCOPE_ACK|"));
|
|
109
|
+
}
|
|
110
|
+
if (!ackLine) {
|
|
111
|
+
throw new Error(
|
|
112
|
+
`${cleanSshError(result.stderr || result.stdout)};可直接重试,不会重复发送`,
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
const [
|
|
116
|
+
,
|
|
117
|
+
paneCommand = "",
|
|
118
|
+
paneDead = "0",
|
|
119
|
+
panePid = "0",
|
|
120
|
+
deliveryStatus = "submitted",
|
|
121
|
+
] = ackLine.split("|");
|
|
122
|
+
if (paneDead === "1") {
|
|
123
|
+
throw new Error("目标 tmux pane 已退出,instruction 未发送");
|
|
124
|
+
}
|
|
125
|
+
return {
|
|
126
|
+
target,
|
|
127
|
+
acknowledged: true,
|
|
128
|
+
deliveryId,
|
|
129
|
+
deliveryStatus,
|
|
130
|
+
deduplicated: deliveryStatus === "deduplicated",
|
|
131
|
+
paneCommand,
|
|
132
|
+
panePid: Number(panePid) || 0,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function tmuxAccountAllowsAutoContinue() { return false; }
|
|
137
|
+
|
|
138
|
+
async function runTmuxCapacityContinuation(key, recovery) {
|
|
139
|
+
if (!tmuxAccountAllowsAutoContinue()) {
|
|
140
|
+
cancelTmuxCapacityRecovery(recovery.host, recovery.sessionId);
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
if (tmuxCapacityRecoveries.get(key) !== recovery) return;
|
|
144
|
+
recovery.timer = null;
|
|
145
|
+
recovery.nextRetryAt = null;
|
|
146
|
+
const agent = findAgent(recovery.host, recovery.sessionId);
|
|
147
|
+
if (
|
|
148
|
+
!agent?.pane ||
|
|
149
|
+
agent.appServerManaged ||
|
|
150
|
+
agent.pane.session !== recovery.paneSession ||
|
|
151
|
+
agent.pane.pane !== recovery.pane
|
|
152
|
+
) {
|
|
153
|
+
recovery.status = "failed";
|
|
154
|
+
recovery.lastError = "目标 tmux pane 已变化,未自动注入“继续”";
|
|
155
|
+
notifyClients();
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
recovery.status = "sending";
|
|
160
|
+
notifyClients();
|
|
161
|
+
try {
|
|
162
|
+
const digest = createHash("sha256")
|
|
163
|
+
.update(`${key}:${recovery.attempt}`)
|
|
164
|
+
.digest("hex")
|
|
165
|
+
.slice(0, 20);
|
|
166
|
+
await sendTmuxText(
|
|
167
|
+
agent,
|
|
168
|
+
CAPACITY_CONTINUE_PROMPT,
|
|
169
|
+
`capacity-${digest}-${recovery.attempt}`,
|
|
170
|
+
{ preserveCapacityRecovery: true },
|
|
171
|
+
);
|
|
172
|
+
if (tmuxCapacityRecoveries.get(key) !== recovery) return;
|
|
173
|
+
recovery.status = "sent";
|
|
174
|
+
recovery.lastContinueAt = new Date().toISOString();
|
|
175
|
+
recovery.lastError = "Selected model is at capacity";
|
|
176
|
+
notifyClients();
|
|
177
|
+
} catch (error) {
|
|
178
|
+
if (tmuxCapacityRecoveries.get(key) !== recovery) return;
|
|
179
|
+
recovery.status = "failed";
|
|
180
|
+
recovery.lastError = error instanceof Error ? error.message : String(error);
|
|
181
|
+
notifyClients();
|
|
182
|
+
scheduleTmuxCapacityContinuation(agent, recovery.warningCount, {
|
|
183
|
+
deliveryRetry: true,
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function scheduleTmuxCapacityContinuation(
|
|
189
|
+
agent,
|
|
190
|
+
warningCount,
|
|
191
|
+
{ deliveryRetry = false } = {},
|
|
192
|
+
) {
|
|
193
|
+
if (!agent?.pane || !agent.rollout?.id || agent.appServerManaged) return;
|
|
194
|
+
// A tmux pane does not expose a verified writer account. Fail closed.
|
|
195
|
+
if (!tmuxAccountAllowsAutoContinue()) return;
|
|
196
|
+
const key = sessionKey(agent.host, agent.rollout.id);
|
|
197
|
+
const current = tmuxCapacityRecoveries.get(key);
|
|
198
|
+
if (!deliveryRetry && current && warningCount <= current.warningCount) return;
|
|
199
|
+
if (current?.timer) clearTimeout(current.timer);
|
|
200
|
+
const attempt = current?.attempt || 0;
|
|
201
|
+
if (attempt >= DEFAULT_CAPACITY_RETRY_DELAYS_MS.length) {
|
|
202
|
+
tmuxCapacityRecoveries.set(key, {
|
|
203
|
+
...current,
|
|
204
|
+
host: agent.host,
|
|
205
|
+
sessionId: agent.rollout.id,
|
|
206
|
+
status: "exhausted",
|
|
207
|
+
nextRetryAt: null,
|
|
208
|
+
warningCount: Math.max(current?.warningCount || 0, warningCount),
|
|
209
|
+
lastError:
|
|
210
|
+
current?.lastError || "Selected model is at capacity",
|
|
211
|
+
timer: null,
|
|
212
|
+
});
|
|
213
|
+
notifyClients();
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const delay = DEFAULT_CAPACITY_RETRY_DELAYS_MS[attempt];
|
|
218
|
+
const recovery = {
|
|
219
|
+
host: agent.host,
|
|
220
|
+
sessionId: agent.rollout.id,
|
|
221
|
+
paneSession: agent.pane.session,
|
|
222
|
+
pane: agent.pane.pane,
|
|
223
|
+
warningCount: Math.max(current?.warningCount || 0, warningCount),
|
|
224
|
+
assistantBefore: agent.rollout.lastAssistant || "",
|
|
225
|
+
attempt: attempt + 1,
|
|
226
|
+
status: "scheduled",
|
|
227
|
+
nextRetryAt: new Date(Date.now() + delay).toISOString(),
|
|
228
|
+
lastError: current?.lastError || "Selected model is at capacity",
|
|
229
|
+
lastContinueAt: current?.lastContinueAt || null,
|
|
230
|
+
timer: null,
|
|
231
|
+
};
|
|
232
|
+
recovery.timer = setTimeout(
|
|
233
|
+
() => runTmuxCapacityContinuation(key, recovery),
|
|
234
|
+
delay,
|
|
235
|
+
);
|
|
236
|
+
recovery.timer.unref?.();
|
|
237
|
+
tmuxCapacityRecoveries.set(key, recovery);
|
|
238
|
+
notifyClients();
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function detectTmuxCapacityFailures(hosts) {
|
|
242
|
+
const liveKeys = new Set();
|
|
243
|
+
for (const host of hosts) {
|
|
244
|
+
for (const agent of host.agents || []) {
|
|
245
|
+
if (!agent?.pane || !agent.rollout?.id || agent.appServerManaged) continue;
|
|
246
|
+
const key = sessionKey(agent.host, agent.rollout.id);
|
|
247
|
+
liveKeys.add(key);
|
|
248
|
+
const warningCount = countModelCapacityWarnings(agent.pane.preview);
|
|
249
|
+
const current = tmuxCapacityRecoveries.get(key);
|
|
250
|
+
if (!warningCount) {
|
|
251
|
+
if (current) cancelTmuxCapacityRecovery(agent.host, agent.rollout.id);
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
const unanswered = hasUnansweredModelCapacityWarning(agent.pane.preview);
|
|
255
|
+
if (
|
|
256
|
+
current?.status === "sent" &&
|
|
257
|
+
agent.rollout.lastAssistant &&
|
|
258
|
+
agent.rollout.lastAssistant !== current.assistantBefore
|
|
259
|
+
) {
|
|
260
|
+
current.status = "recovered";
|
|
261
|
+
current.lastError = null;
|
|
262
|
+
}
|
|
263
|
+
if (unanswered && (!current || warningCount > current.warningCount)) {
|
|
264
|
+
scheduleTmuxCapacityContinuation(agent, warningCount);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
for (const [key, recovery] of tmuxCapacityRecoveries) {
|
|
269
|
+
if (liveKeys.has(key)) continue;
|
|
270
|
+
if (recovery.timer) clearTimeout(recovery.timer);
|
|
271
|
+
tmuxCapacityRecoveries.delete(key);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
async function sendTmuxSelectionKeys(agent, keys) {
|
|
276
|
+
if (!agent?.pane) throw new Error("目标 Session 没有可控 tmux pane");
|
|
277
|
+
const target = `${agent.pane.session}:${agent.pane.pane}`;
|
|
278
|
+
const allowed = new Set(["Home", "Down", "Enter"]);
|
|
279
|
+
if (!keys.length || keys.some((key) => !allowed.has(key))) {
|
|
280
|
+
throw new Error("内部模型选择按键无效");
|
|
281
|
+
}
|
|
282
|
+
const command = [
|
|
283
|
+
`tmux display-message -p -t ${shellQuote(target)} '#{pane_dead}|#{pane_current_command}'`,
|
|
284
|
+
...keys.map((key) => `tmux send-keys -t ${shellQuote(target)} ${key}`),
|
|
285
|
+
].join(" && ");
|
|
286
|
+
const result = await runSshCommand(agent.host, command, "", 15_000, 100_000);
|
|
287
|
+
if (result.code !== 0 || result.stdout.split("|")[0].trim() === "1") {
|
|
288
|
+
throw new Error(cleanSshError(result.stderr || result.stdout));
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
function selectionKeys(index) {
|
|
293
|
+
return ["Home", ...Array.from({ length: Math.max(0, index) }, () => "Down"), "Enter"];
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
async function selectTmuxModel(
|
|
297
|
+
agent,
|
|
298
|
+
selectedModel,
|
|
299
|
+
models,
|
|
300
|
+
requestedEffort = "",
|
|
301
|
+
) {
|
|
302
|
+
const prefix = randomUUID();
|
|
303
|
+
const modelName = selectedModel.model || selectedModel.id;
|
|
304
|
+
const efforts = selectedModel.supportedReasoningEfforts || [];
|
|
305
|
+
let effort = efforts.includes(requestedEffort)
|
|
306
|
+
? requestedEffort
|
|
307
|
+
: efforts.includes(agent.rollout?.reasoningEffort)
|
|
308
|
+
? agent.rollout.reasoningEffort
|
|
309
|
+
: selectedModel.defaultReasoningEffort;
|
|
310
|
+
if (!efforts.includes(effort)) effort = efforts[0] || "";
|
|
311
|
+
if (
|
|
312
|
+
[selectedModel.id, modelName].includes(agent.rollout?.model) &&
|
|
313
|
+
(!efforts.length || effort === agent.rollout?.reasoningEffort)
|
|
314
|
+
) {
|
|
315
|
+
const verified = await sendTmuxText(agent, "/status", `${prefix}-status`);
|
|
316
|
+
return {
|
|
317
|
+
target: verified.target,
|
|
318
|
+
model: selectedModel.id,
|
|
319
|
+
effort: agent.rollout?.reasoningEffort || selectedModel.defaultReasoningEffort,
|
|
320
|
+
deliveryIds: [verified.deliveryId],
|
|
321
|
+
verification: "status-requested",
|
|
322
|
+
unchanged: true,
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
const opened = await sendTmuxText(agent, "/model", `${prefix}-open`);
|
|
326
|
+
await new Promise((resolve) => setTimeout(resolve, 550));
|
|
327
|
+
|
|
328
|
+
const visible = models.filter((model) => model?.id);
|
|
329
|
+
const auto = visible
|
|
330
|
+
.filter((model) => (model.model || model.id).startsWith("codex-auto-"))
|
|
331
|
+
.sort((left, right) => {
|
|
332
|
+
const order = { "codex-auto-fast": 0, "codex-auto-balanced": 1, "codex-auto-thorough": 2 };
|
|
333
|
+
return (order[left.model || left.id] ?? 3) - (order[right.model || right.id] ?? 3);
|
|
334
|
+
});
|
|
335
|
+
const other = visible.filter(
|
|
336
|
+
(model) => !(model.model || model.id).startsWith("codex-auto-"),
|
|
337
|
+
);
|
|
338
|
+
const isAuto = modelName.startsWith("codex-auto-");
|
|
339
|
+
if (auto.length && !isAuto) {
|
|
340
|
+
await sendTmuxSelectionKeys(agent, selectionKeys(auto.length));
|
|
341
|
+
await new Promise((resolve) => setTimeout(resolve, 450));
|
|
342
|
+
const index = other.findIndex((model) => model.id === selectedModel.id);
|
|
343
|
+
if (index < 0) throw new Error("模型不在 TUI 的 All models 列表中");
|
|
344
|
+
await sendTmuxSelectionKeys(agent, selectionKeys(index));
|
|
345
|
+
} else {
|
|
346
|
+
const choices = auto.length ? auto : other;
|
|
347
|
+
const index = choices.findIndex((model) => model.id === selectedModel.id);
|
|
348
|
+
if (index < 0) throw new Error("模型不在 TUI picker 中");
|
|
349
|
+
await sendTmuxSelectionKeys(agent, selectionKeys(index));
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
const hasAdvanced = efforts.some((effort) => ["max", "ultra"].includes(effort));
|
|
353
|
+
const reasoningPopupExpected = isAuto ? hasAdvanced : efforts.length > 1;
|
|
354
|
+
if (reasoningPopupExpected) {
|
|
355
|
+
await new Promise((resolve) => setTimeout(resolve, 450));
|
|
356
|
+
const regular = efforts.filter((candidate) => !["max", "ultra"].includes(candidate));
|
|
357
|
+
if (["max", "ultra"].includes(effort)) {
|
|
358
|
+
await sendTmuxSelectionKeys(agent, selectionKeys(regular.length));
|
|
359
|
+
await new Promise((resolve) => setTimeout(resolve, 350));
|
|
360
|
+
const advanced = efforts.filter((candidate) => ["max", "ultra"].includes(candidate));
|
|
361
|
+
await sendTmuxSelectionKeys(agent, selectionKeys(advanced.indexOf(effort)));
|
|
362
|
+
} else {
|
|
363
|
+
const effortIndex = regular.indexOf(effort);
|
|
364
|
+
await sendTmuxSelectionKeys(agent, selectionKeys(Math.max(0, effortIndex)));
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
await new Promise((resolve) => setTimeout(resolve, 650));
|
|
368
|
+
const verified = await sendTmuxText(agent, "/status", `${prefix}-status`);
|
|
369
|
+
return {
|
|
370
|
+
target: opened.target,
|
|
371
|
+
model: selectedModel.id,
|
|
372
|
+
effort,
|
|
373
|
+
deliveryIds: [opened.deliveryId, verified.deliveryId],
|
|
374
|
+
verification: "status-requested",
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
return {
|
|
379
|
+
sendTmuxText,
|
|
380
|
+
publicTmuxCapacityRecovery,
|
|
381
|
+
cancelTmuxCapacityRecovery,
|
|
382
|
+
scheduleTmuxCapacityContinuation,
|
|
383
|
+
runTmuxCapacityContinuation,
|
|
384
|
+
tmuxAccountAllowsAutoContinue,
|
|
385
|
+
detectTmuxCapacityFailures,
|
|
386
|
+
sendTmuxSelectionKeys,
|
|
387
|
+
selectionKeys,
|
|
388
|
+
selectTmuxModel,
|
|
389
|
+
};
|
|
390
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const MAX_TMUX_SESSION_NAME_LENGTH = 512;
|
|
2
|
+
|
|
3
|
+
function posixShellQuote(value) {
|
|
4
|
+
return `'${String(value).replaceAll("'", `'\"'\"'`)}'`;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function normalizeTmuxSessionName(value) {
|
|
8
|
+
if (typeof value !== "string") {
|
|
9
|
+
throw new TypeError("tmux Session 名称必须是字符串");
|
|
10
|
+
}
|
|
11
|
+
if (!value || value.length > MAX_TMUX_SESSION_NAME_LENGTH) {
|
|
12
|
+
throw new Error("tmux Session 名称为空或过长");
|
|
13
|
+
}
|
|
14
|
+
if (/[\0\r\n\t]/.test(value)) {
|
|
15
|
+
throw new Error("tmux Session 名称包含非法控制字符");
|
|
16
|
+
}
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function buildExactTmuxTerminateCommand(value) {
|
|
21
|
+
const sessionName = normalizeTmuxSessionName(value);
|
|
22
|
+
const target = posixShellQuote(`=${sessionName}`);
|
|
23
|
+
return [
|
|
24
|
+
`tmux has-session -t ${target} 2>/dev/null || { printf '%s\\n' 'SCOPE_TMUX_SESSION_MISSING' >&2; exit 44; }`,
|
|
25
|
+
`tmux kill-session -t ${target} 2>/dev/null || true`,
|
|
26
|
+
`if tmux has-session -t ${target} 2>/dev/null; then printf '%s\\n' 'SCOPE_TMUX_SESSION_STILL_RUNNING' >&2; exit 45; fi`,
|
|
27
|
+
`printf '%s\\n' 'SCOPE_TMUX_SESSION_TERMINATED'`,
|
|
28
|
+
].join("; ");
|
|
29
|
+
}
|