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
package/bridge/start.mjs
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import { connect } from "node:net";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
|
|
6
|
+
const UI_PORT = Number(process.env.SCOPE_UI_PORT || 3000);
|
|
7
|
+
const BRIDGE_PORT = Number(process.env.SCOPE_BRIDGE_PORT || 4815);
|
|
8
|
+
const developmentMode = process.argv.includes("--dev");
|
|
9
|
+
const forceBuild = process.argv.includes("--build");
|
|
10
|
+
const skipBuild = process.argv.includes("--skip-build");
|
|
11
|
+
|
|
12
|
+
function portIsOpen(port) {
|
|
13
|
+
return new Promise((resolve) => {
|
|
14
|
+
const socket = connect({ host: "127.0.0.1", port });
|
|
15
|
+
const finish = (open) => {
|
|
16
|
+
socket.removeAllListeners();
|
|
17
|
+
socket.destroy();
|
|
18
|
+
resolve(open);
|
|
19
|
+
};
|
|
20
|
+
socket.setTimeout(800);
|
|
21
|
+
socket.once("connect", () => finish(true));
|
|
22
|
+
socket.once("error", () => finish(false));
|
|
23
|
+
socket.once("timeout", () => finish(false));
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async function isScopeBridge() {
|
|
28
|
+
try {
|
|
29
|
+
const healthResponse = await fetch(
|
|
30
|
+
`http://127.0.0.1:${BRIDGE_PORT}/api/health`,
|
|
31
|
+
{
|
|
32
|
+
signal: AbortSignal.timeout(5_000),
|
|
33
|
+
},
|
|
34
|
+
);
|
|
35
|
+
if (healthResponse.ok) {
|
|
36
|
+
const health = await healthResponse.json();
|
|
37
|
+
if (health?.service === "scope-bridge") return true;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const response = await fetch(`http://127.0.0.1:${BRIDGE_PORT}/api/snapshot`, {
|
|
41
|
+
signal: AbortSignal.timeout(5_000),
|
|
42
|
+
});
|
|
43
|
+
if (!response.ok) return false;
|
|
44
|
+
const snapshot = await response.json();
|
|
45
|
+
return (
|
|
46
|
+
typeof snapshot?.sshConfig === "string" && Array.isArray(snapshot?.hosts)
|
|
47
|
+
);
|
|
48
|
+
} catch {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async function isScopeUi() {
|
|
54
|
+
try {
|
|
55
|
+
const response = await fetch(`http://127.0.0.1:${UI_PORT}/`, {
|
|
56
|
+
signal: AbortSignal.timeout(5_000),
|
|
57
|
+
});
|
|
58
|
+
if (!response.ok) return false;
|
|
59
|
+
const html = await response.text();
|
|
60
|
+
return html.includes("SCOPE") && (html.includes("跨项目 Agent 工作台") || html.includes("SSH Codex Monitor"));
|
|
61
|
+
} catch {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const [uiPortOpen, bridgePortOpen] = await Promise.all([
|
|
67
|
+
portIsOpen(UI_PORT),
|
|
68
|
+
portIsOpen(BRIDGE_PORT),
|
|
69
|
+
]);
|
|
70
|
+
|
|
71
|
+
if (uiPortOpen || bridgePortOpen) {
|
|
72
|
+
const [scopeUi, scopeBridge] = await Promise.all([
|
|
73
|
+
uiPortOpen ? isScopeUi() : false,
|
|
74
|
+
bridgePortOpen ? isScopeBridge() : false,
|
|
75
|
+
]);
|
|
76
|
+
if (scopeUi && scopeBridge) {
|
|
77
|
+
console.log(
|
|
78
|
+
`SCOPE 已在运行:http://localhost:${UI_PORT}(Bridge ${BRIDGE_PORT})`,
|
|
79
|
+
);
|
|
80
|
+
process.exit(0);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const occupied = [
|
|
84
|
+
uiPortOpen ? UI_PORT : null,
|
|
85
|
+
bridgePortOpen ? BRIDGE_PORT : null,
|
|
86
|
+
].filter(Boolean);
|
|
87
|
+
console.error(
|
|
88
|
+
`[scope] 无法启动:本机端口 ${occupied.join(", ")} 已被其他或不完整的服务占用。`,
|
|
89
|
+
);
|
|
90
|
+
process.exit(1);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const bridgeEntry = fileURLToPath(new URL("./server.mjs", import.meta.url));
|
|
94
|
+
const vinextEntry = fileURLToPath(
|
|
95
|
+
new URL("../node_modules/vinext/dist/cli.js", import.meta.url),
|
|
96
|
+
);
|
|
97
|
+
const uiEntry = fileURLToPath(new URL("./ui-server.mjs", import.meta.url));
|
|
98
|
+
const prebuiltServerEntry = fileURLToPath(
|
|
99
|
+
new URL("../dist/server/index.js", import.meta.url),
|
|
100
|
+
);
|
|
101
|
+
const shouldBuild =
|
|
102
|
+
!developmentMode &&
|
|
103
|
+
!skipBuild &&
|
|
104
|
+
(forceBuild || !existsSync(prebuiltServerEntry) || existsSync(vinextEntry));
|
|
105
|
+
|
|
106
|
+
if (shouldBuild && !existsSync(vinextEntry)) {
|
|
107
|
+
if (existsSync(prebuiltServerEntry)) {
|
|
108
|
+
console.log("[scope] Using prebuilt UI bundle.");
|
|
109
|
+
} else {
|
|
110
|
+
console.error("[scope] Missing prebuilt dist/ bundle and vinext build tool.");
|
|
111
|
+
process.exit(1);
|
|
112
|
+
}
|
|
113
|
+
} else if (shouldBuild) {
|
|
114
|
+
console.log("[scope] Building the stable local UI...");
|
|
115
|
+
const buildCode = await new Promise((resolve, reject) => {
|
|
116
|
+
const build = spawn(process.execPath, [vinextEntry, "build"], {
|
|
117
|
+
stdio: "inherit",
|
|
118
|
+
});
|
|
119
|
+
build.once("error", reject);
|
|
120
|
+
build.once("exit", (code) => resolve(code ?? 1));
|
|
121
|
+
});
|
|
122
|
+
if (buildCode !== 0) {
|
|
123
|
+
console.error(`[scope] UI build failed with exit code ${buildCode}`);
|
|
124
|
+
process.exit(buildCode);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const childSpecs = [
|
|
129
|
+
{ name: "Bridge", args: [bridgeEntry] },
|
|
130
|
+
{
|
|
131
|
+
name: "UI",
|
|
132
|
+
args: developmentMode
|
|
133
|
+
? [
|
|
134
|
+
vinextEntry,
|
|
135
|
+
"dev",
|
|
136
|
+
"--hostname",
|
|
137
|
+
"127.0.0.1",
|
|
138
|
+
"--port",
|
|
139
|
+
String(UI_PORT),
|
|
140
|
+
]
|
|
141
|
+
: [
|
|
142
|
+
uiEntry,
|
|
143
|
+
"--hostname",
|
|
144
|
+
"127.0.0.1",
|
|
145
|
+
"--port",
|
|
146
|
+
String(UI_PORT),
|
|
147
|
+
],
|
|
148
|
+
},
|
|
149
|
+
];
|
|
150
|
+
let stopping = false;
|
|
151
|
+
const children = new Set();
|
|
152
|
+
const restartAttempts = new Map();
|
|
153
|
+
const restartTimers = new Set();
|
|
154
|
+
|
|
155
|
+
function launchChild(spec) {
|
|
156
|
+
if (stopping) return;
|
|
157
|
+
const startedAt = Date.now();
|
|
158
|
+
const child = spawn(process.execPath, spec.args, { stdio: "inherit" });
|
|
159
|
+
children.add(child);
|
|
160
|
+
child.on("exit", (code, signal) => {
|
|
161
|
+
children.delete(child);
|
|
162
|
+
if (stopping) return;
|
|
163
|
+
const previousAttempts =
|
|
164
|
+
Date.now() - startedAt >= 60_000
|
|
165
|
+
? 0
|
|
166
|
+
: restartAttempts.get(spec.name) || 0;
|
|
167
|
+
const attempts = previousAttempts + 1;
|
|
168
|
+
restartAttempts.set(spec.name, attempts);
|
|
169
|
+
if (attempts > 5) {
|
|
170
|
+
console.error(
|
|
171
|
+
`[scope] ${spec.name} 连续退出 ${attempts} 次;停止 SCOPE 以避免重启循环`,
|
|
172
|
+
);
|
|
173
|
+
stop(code ?? 1);
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
const delay = Math.min(10_000, 1_000 * 2 ** (attempts - 1));
|
|
177
|
+
console.error(
|
|
178
|
+
`[scope] ${spec.name} exited (${signal || `code ${code ?? 1}`}); ` +
|
|
179
|
+
`${Math.round(delay / 1_000)} 秒后自动重启`,
|
|
180
|
+
);
|
|
181
|
+
const timer = setTimeout(() => {
|
|
182
|
+
restartTimers.delete(timer);
|
|
183
|
+
launchChild(spec);
|
|
184
|
+
}, delay);
|
|
185
|
+
restartTimers.add(timer);
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function stop(exitCode = 0) {
|
|
190
|
+
if (stopping) return;
|
|
191
|
+
stopping = true;
|
|
192
|
+
|
|
193
|
+
for (const timer of restartTimers) clearTimeout(timer);
|
|
194
|
+
restartTimers.clear();
|
|
195
|
+
for (const child of children) {
|
|
196
|
+
if (!child.killed) child.kill("SIGTERM");
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
setTimeout(() => process.exit(exitCode), 1_000);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
for (const spec of childSpecs) launchChild(spec);
|
|
203
|
+
|
|
204
|
+
process.on("SIGINT", () => stop(0));
|
|
205
|
+
process.on("SIGTERM", () => stop(0));
|
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { LOCAL_HOST } from "../lib/execution-host.js";
|
|
4
|
+
import { normalizeProjects } from "../lib/projects.js";
|
|
5
|
+
import { normalizeHostRuntimeConfig } from "../lib/runtime-config.js";
|
|
6
|
+
import { preserveSession } from "../lib/session-cache-guard.js";
|
|
7
|
+
import { excludeActiveSessions } from "../lib/session-filters.js";
|
|
8
|
+
import {
|
|
9
|
+
emptyGpuUsageHistory,
|
|
10
|
+
normalizeGpuUsageHistory,
|
|
11
|
+
} from "./gpu-usage-history.mjs";
|
|
12
|
+
import { archiveSessionCache } from "./session-cache-archive.mjs";
|
|
13
|
+
|
|
14
|
+
export function normalizeHistoryIndex(parsed) {
|
|
15
|
+
const normalized = {
|
|
16
|
+
version: 1,
|
|
17
|
+
updatedAt:
|
|
18
|
+
typeof parsed?.updatedAt === "string" ? parsed.updatedAt : null,
|
|
19
|
+
hosts: {},
|
|
20
|
+
};
|
|
21
|
+
if (!parsed?.hosts || typeof parsed.hosts !== "object") return normalized;
|
|
22
|
+
for (const [alias, host] of Object.entries(parsed.hosts)) {
|
|
23
|
+
if (!host?.orders || typeof host.orders !== "object") continue;
|
|
24
|
+
const orders = {};
|
|
25
|
+
for (const order of ["recent", "oldest"]) {
|
|
26
|
+
const entry = host.orders[order];
|
|
27
|
+
if (!entry || !Array.isArray(entry.sessions)) continue;
|
|
28
|
+
orders[order] = {
|
|
29
|
+
scannedAt:
|
|
30
|
+
typeof entry.scannedAt === "string" ? entry.scannedAt : null,
|
|
31
|
+
totalFiles: Number(entry.totalFiles) || 0,
|
|
32
|
+
truncated: Boolean(entry.truncated),
|
|
33
|
+
sessions: entry.sessions,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
normalized.hosts[alias] = { orders };
|
|
37
|
+
}
|
|
38
|
+
return normalized;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function createStatePersistence({
|
|
42
|
+
STATE_DIR,
|
|
43
|
+
STATE_FILE,
|
|
44
|
+
GPU_USAGE_HISTORY_FILE,
|
|
45
|
+
SNAPSHOT_CACHE_FILE,
|
|
46
|
+
HISTORY_INDEX_FILE,
|
|
47
|
+
sessionKey,
|
|
48
|
+
appServerManager,
|
|
49
|
+
localCodex,
|
|
50
|
+
historicalSessions,
|
|
51
|
+
hostNextScanAt,
|
|
52
|
+
hostFailureStreaks,
|
|
53
|
+
getSnapshot,
|
|
54
|
+
setSnapshot,
|
|
55
|
+
getManagementState,
|
|
56
|
+
setManagementState,
|
|
57
|
+
setGpuUsageHistory,
|
|
58
|
+
getGpuUsageHistory,
|
|
59
|
+
getHistoryIndex,
|
|
60
|
+
setHistoryIndex,
|
|
61
|
+
}) {
|
|
62
|
+
let stateWritePromise = Promise.resolve();
|
|
63
|
+
let gpuUsageWritePromise = Promise.resolve();
|
|
64
|
+
let snapshotWritePromise = Promise.resolve();
|
|
65
|
+
let historyIndexWritePromise = Promise.resolve();
|
|
66
|
+
let lastSnapshotPersistAt = 0;
|
|
67
|
+
|
|
68
|
+
async function loadManagementState() {
|
|
69
|
+
try {
|
|
70
|
+
const parsed = JSON.parse(await readFile(STATE_FILE, "utf8"));
|
|
71
|
+
setManagementState({
|
|
72
|
+
operatorName:
|
|
73
|
+
typeof parsed?.operatorName === "string" && parsed.operatorName.trim()
|
|
74
|
+
? parsed.operatorName.trim().slice(0, 40)
|
|
75
|
+
: "Operator",
|
|
76
|
+
sessions:
|
|
77
|
+
parsed?.sessions && typeof parsed.sessions === "object"
|
|
78
|
+
? parsed.sessions
|
|
79
|
+
: {},
|
|
80
|
+
projects: normalizeProjects(parsed?.projects),
|
|
81
|
+
hostRuntimeConfigs:
|
|
82
|
+
parsed?.hostRuntimeConfigs &&
|
|
83
|
+
typeof parsed.hostRuntimeConfigs === "object"
|
|
84
|
+
? Object.fromEntries(
|
|
85
|
+
Object.entries(parsed.hostRuntimeConfigs).map(([host, config]) => [
|
|
86
|
+
host,
|
|
87
|
+
normalizeHostRuntimeConfig(config),
|
|
88
|
+
]),
|
|
89
|
+
)
|
|
90
|
+
: {},
|
|
91
|
+
resourcePolicy: {
|
|
92
|
+
prompt:
|
|
93
|
+
typeof parsed?.resourcePolicy?.prompt === "string"
|
|
94
|
+
? parsed.resourcePolicy.prompt
|
|
95
|
+
: "",
|
|
96
|
+
updatedAt: parsed?.resourcePolicy?.updatedAt || null,
|
|
97
|
+
version: Number(parsed?.resourcePolicy?.version) || 0,
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
} catch (error) {
|
|
101
|
+
if (error?.code !== "ENOENT") {
|
|
102
|
+
console.error(`无法读取 ${STATE_FILE}: ${error.message}`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
async function loadGpuUsageHistory() {
|
|
108
|
+
try {
|
|
109
|
+
setGpuUsageHistory(
|
|
110
|
+
normalizeGpuUsageHistory(
|
|
111
|
+
JSON.parse(await readFile(GPU_USAGE_HISTORY_FILE, "utf8")),
|
|
112
|
+
),
|
|
113
|
+
);
|
|
114
|
+
} catch (error) {
|
|
115
|
+
if (error?.code !== "ENOENT") {
|
|
116
|
+
console.error(
|
|
117
|
+
`无法读取 ${GPU_USAGE_HISTORY_FILE}: ${error.message}`,
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
setGpuUsageHistory(emptyGpuUsageHistory());
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
async function loadSnapshotCache() {
|
|
125
|
+
try {
|
|
126
|
+
const parsed = JSON.parse(await readFile(SNAPSHOT_CACHE_FILE, "utf8"));
|
|
127
|
+
const cachedSnapshot = parsed?.snapshot;
|
|
128
|
+
if (!cachedSnapshot || !Array.isArray(cachedSnapshot.hosts)) return;
|
|
129
|
+
await archiveSessionCache(path.join(STATE_DIR, "session-cache-versions"), cachedSnapshot);
|
|
130
|
+
const snapshot = getSnapshot();
|
|
131
|
+
setSnapshot({
|
|
132
|
+
...snapshot,
|
|
133
|
+
...cachedSnapshot,
|
|
134
|
+
hosts: [localCodex.host(), ...cachedSnapshot.hosts.filter(h => h.alias !== LOCAL_HOST)],
|
|
135
|
+
scanning: true,
|
|
136
|
+
cached: true,
|
|
137
|
+
cacheSavedAt: parsed.savedAt || cachedSnapshot.generatedAt || null,
|
|
138
|
+
});
|
|
139
|
+
lastSnapshotPersistAt = Date.parse(parsed.savedAt || "") || 0;
|
|
140
|
+
const deferOfflineUntil = Date.now() + 60_000;
|
|
141
|
+
for (const host of cachedSnapshot.hosts) {
|
|
142
|
+
if (host?.alias && !host.reachable) {
|
|
143
|
+
hostNextScanAt.set(host.alias, deferOfflineUntil);
|
|
144
|
+
hostFailureStreaks.set(host.alias, 1);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
} catch (error) {
|
|
148
|
+
if (error?.code !== "ENOENT") {
|
|
149
|
+
console.error(`无法读取 ${SNAPSHOT_CACHE_FILE}: ${error.message}`);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
async function loadHistoryIndex() {
|
|
155
|
+
try {
|
|
156
|
+
const historyIndex = normalizeHistoryIndex(
|
|
157
|
+
JSON.parse(await readFile(HISTORY_INDEX_FILE, "utf8")),
|
|
158
|
+
);
|
|
159
|
+
setHistoryIndex(historyIndex);
|
|
160
|
+
await archiveSessionCache(path.join(STATE_DIR, "session-cache-versions"), {
|
|
161
|
+
hosts: Object.entries(historyIndex.hosts).map(([alias, host]) => ({ alias,
|
|
162
|
+
sessions: Object.values(host.orders || {}).flatMap(entry => entry.sessions.map(a => a.rollout).filter(Boolean)),
|
|
163
|
+
})),
|
|
164
|
+
});
|
|
165
|
+
for (const host of Object.values(historyIndex.hosts)) {
|
|
166
|
+
for (const entry of Object.values(host.orders || {})) {
|
|
167
|
+
for (const agent of entry.sessions || []) {
|
|
168
|
+
if (agent?.host && agent?.rollout?.id) {
|
|
169
|
+
historicalSessions.set(
|
|
170
|
+
sessionKey(agent.host, agent.rollout.id),
|
|
171
|
+
agent,
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
} catch (error) {
|
|
178
|
+
if (error?.code !== "ENOENT") {
|
|
179
|
+
console.error(`无法读取 ${HISTORY_INDEX_FILE}: ${error.message}`);
|
|
180
|
+
}
|
|
181
|
+
setHistoryIndex(normalizeHistoryIndex(null));
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function persistSnapshotCache(force = false) {
|
|
186
|
+
const now = Date.now();
|
|
187
|
+
if (!force && now - lastSnapshotPersistAt < 60_000) {
|
|
188
|
+
return snapshotWritePromise;
|
|
189
|
+
}
|
|
190
|
+
lastSnapshotPersistAt = now;
|
|
191
|
+
const savedAt = new Date(now).toISOString();
|
|
192
|
+
const cachedSnapshot = {
|
|
193
|
+
...getSnapshot(),
|
|
194
|
+
scanning: false,
|
|
195
|
+
cached: false,
|
|
196
|
+
cacheSavedAt: savedAt,
|
|
197
|
+
};
|
|
198
|
+
const serialized = `${JSON.stringify({
|
|
199
|
+
version: 1,
|
|
200
|
+
savedAt,
|
|
201
|
+
snapshot: cachedSnapshot,
|
|
202
|
+
})}\n`;
|
|
203
|
+
snapshotWritePromise = snapshotWritePromise
|
|
204
|
+
.catch(() => {})
|
|
205
|
+
.then(async () => {
|
|
206
|
+
await mkdir(STATE_DIR, { recursive: true });
|
|
207
|
+
await archiveSessionCache(path.join(STATE_DIR, "session-cache-versions"), cachedSnapshot);
|
|
208
|
+
const temporary = `${SNAPSHOT_CACHE_FILE}.tmp`;
|
|
209
|
+
await writeFile(temporary, serialized, "utf8");
|
|
210
|
+
await rename(temporary, SNAPSHOT_CACHE_FILE);
|
|
211
|
+
});
|
|
212
|
+
return snapshotWritePromise;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function persistHistoryIndex() {
|
|
216
|
+
const historyIndex = getHistoryIndex();
|
|
217
|
+
const historyToArchive = { hosts: Object.entries(historyIndex.hosts).map(([alias, host]) => ({
|
|
218
|
+
alias, sessions: Object.values(host.orders || {}).flatMap(entry => entry.sessions.map(a => a.rollout).filter(Boolean)),
|
|
219
|
+
})) };
|
|
220
|
+
const serialized = `${JSON.stringify(historyIndex)}\n`;
|
|
221
|
+
historyIndexWritePromise = historyIndexWritePromise
|
|
222
|
+
.catch(() => {})
|
|
223
|
+
.then(async () => {
|
|
224
|
+
await mkdir(STATE_DIR, { recursive: true });
|
|
225
|
+
await archiveSessionCache(path.join(STATE_DIR, "session-cache-versions"), historyToArchive);
|
|
226
|
+
const temporary = `${HISTORY_INDEX_FILE}.tmp`;
|
|
227
|
+
await writeFile(temporary, serialized, "utf8");
|
|
228
|
+
await rename(temporary, HISTORY_INDEX_FILE);
|
|
229
|
+
});
|
|
230
|
+
return historyIndexWritePromise;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function revealUnarchivedSession(host, sessionId, thread = null) {
|
|
234
|
+
const key = sessionKey(host, sessionId);
|
|
235
|
+
const current = historicalSessions.get(key);
|
|
236
|
+
const activePath =
|
|
237
|
+
thread?.path ||
|
|
238
|
+
current?.rollout?.path?.replace(
|
|
239
|
+
"/.codex/archived_sessions/",
|
|
240
|
+
"/.codex/sessions/",
|
|
241
|
+
) ||
|
|
242
|
+
"";
|
|
243
|
+
if (current?.rollout) {
|
|
244
|
+
historicalSessions.set(key, {
|
|
245
|
+
...current,
|
|
246
|
+
rollout: {
|
|
247
|
+
...current.rollout,
|
|
248
|
+
archived: false,
|
|
249
|
+
path: activePath || current.rollout.path,
|
|
250
|
+
},
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
const indexedHost = getHistoryIndex().hosts[host];
|
|
254
|
+
if (indexedHost?.orders) {
|
|
255
|
+
for (const entry of Object.values(indexedHost.orders)) {
|
|
256
|
+
if (!Array.isArray(entry?.sessions)) continue;
|
|
257
|
+
entry.sessions = entry.sessions.map((agent) =>
|
|
258
|
+
agent?.rollout?.id === sessionId
|
|
259
|
+
? {
|
|
260
|
+
...agent,
|
|
261
|
+
rollout: {
|
|
262
|
+
...agent.rollout,
|
|
263
|
+
archived: false,
|
|
264
|
+
path: activePath || agent.rollout.path,
|
|
265
|
+
},
|
|
266
|
+
}
|
|
267
|
+
: agent,
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function cachedHistoryResult(requestedHost, limit, requestedOrder) {
|
|
274
|
+
const snapshot = getSnapshot();
|
|
275
|
+
const historyIndex = getHistoryIndex();
|
|
276
|
+
const activeSessions = [
|
|
277
|
+
...snapshot.hosts.flatMap((host) =>
|
|
278
|
+
host.agents
|
|
279
|
+
.filter((agent) => agent.rollout?.id)
|
|
280
|
+
.map((agent) => ({ ...agent, host: host.alias })),
|
|
281
|
+
),
|
|
282
|
+
...appServerManager.sessionRecords(),
|
|
283
|
+
];
|
|
284
|
+
const aliases =
|
|
285
|
+
requestedHost === "all"
|
|
286
|
+
? Object.keys(historyIndex.hosts).sort()
|
|
287
|
+
: [requestedHost];
|
|
288
|
+
const hosts = [];
|
|
289
|
+
const sessions = [];
|
|
290
|
+
let scannedAt = null;
|
|
291
|
+
for (const alias of aliases) {
|
|
292
|
+
const entry = historyIndex.hosts[alias]?.orders?.[requestedOrder];
|
|
293
|
+
if (!entry) continue;
|
|
294
|
+
const hostSessions = excludeActiveSessions(
|
|
295
|
+
entry.sessions,
|
|
296
|
+
activeSessions,
|
|
297
|
+
).slice(0, limit);
|
|
298
|
+
sessions.push(...hostSessions);
|
|
299
|
+
hosts.push({
|
|
300
|
+
host: alias,
|
|
301
|
+
totalFiles: entry.totalFiles,
|
|
302
|
+
truncated: entry.truncated || entry.sessions.length > limit,
|
|
303
|
+
returned: hostSessions.length,
|
|
304
|
+
error: null,
|
|
305
|
+
cached: true,
|
|
306
|
+
});
|
|
307
|
+
if (!scannedAt || Date.parse(entry.scannedAt || "") > Date.parse(scannedAt)) {
|
|
308
|
+
scannedAt = entry.scannedAt;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
sessions.sort((left, right) => {
|
|
312
|
+
const difference =
|
|
313
|
+
(right.lastActivityAt || 0) - (left.lastActivityAt || 0);
|
|
314
|
+
return requestedOrder === "recent" ? difference : -difference;
|
|
315
|
+
});
|
|
316
|
+
return {
|
|
317
|
+
ok: true,
|
|
318
|
+
cached: hosts.length > 0,
|
|
319
|
+
scope: requestedHost,
|
|
320
|
+
limit,
|
|
321
|
+
order: requestedOrder,
|
|
322
|
+
scannedAt,
|
|
323
|
+
sessions,
|
|
324
|
+
hosts,
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function updateHistoryIndex(scans, requestedOrder, scannedAt) {
|
|
329
|
+
const historyIndex = getHistoryIndex();
|
|
330
|
+
let changed = false;
|
|
331
|
+
for (const scan of scans) {
|
|
332
|
+
if (scan.error) continue;
|
|
333
|
+
const current = historyIndex.hosts[scan.host] || { orders: {} };
|
|
334
|
+
const retained = new Map((current.orders[requestedOrder]?.sessions || []).map(a => [a.rollout?.id || a.id, a]));
|
|
335
|
+
for (const agent of scan.sessions) {
|
|
336
|
+
const id = agent.rollout?.id || agent.id;
|
|
337
|
+
const old = retained.get(id);
|
|
338
|
+
retained.set(id, { ...agent, rollout: preserveSession(old?.rollout, agent.rollout) });
|
|
339
|
+
}
|
|
340
|
+
historyIndex.hosts[scan.host] = {
|
|
341
|
+
...current,
|
|
342
|
+
orders: {
|
|
343
|
+
...current.orders,
|
|
344
|
+
[requestedOrder]: {
|
|
345
|
+
scannedAt,
|
|
346
|
+
totalFiles: scan.totalFiles,
|
|
347
|
+
truncated: scan.truncated,
|
|
348
|
+
sessions: [...retained.values()],
|
|
349
|
+
},
|
|
350
|
+
},
|
|
351
|
+
};
|
|
352
|
+
changed = true;
|
|
353
|
+
}
|
|
354
|
+
if (changed) historyIndex.updatedAt = scannedAt;
|
|
355
|
+
return changed;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
function persistManagementState() {
|
|
359
|
+
const serialized = `${JSON.stringify(getManagementState(), null, 2)}\n`;
|
|
360
|
+
stateWritePromise = stateWritePromise
|
|
361
|
+
.catch(() => {})
|
|
362
|
+
.then(async () => {
|
|
363
|
+
await mkdir(STATE_DIR, { recursive: true });
|
|
364
|
+
const temporary = `${STATE_FILE}.tmp`;
|
|
365
|
+
await writeFile(temporary, serialized, "utf8");
|
|
366
|
+
await rename(temporary, STATE_FILE);
|
|
367
|
+
});
|
|
368
|
+
return stateWritePromise;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
function persistGpuUsageHistory() {
|
|
372
|
+
const serialized = `${JSON.stringify(getGpuUsageHistory())}\n`;
|
|
373
|
+
gpuUsageWritePromise = gpuUsageWritePromise
|
|
374
|
+
.catch(() => {})
|
|
375
|
+
.then(async () => {
|
|
376
|
+
await mkdir(STATE_DIR, { recursive: true });
|
|
377
|
+
const temporary = `${GPU_USAGE_HISTORY_FILE}.tmp`;
|
|
378
|
+
await writeFile(temporary, serialized, "utf8");
|
|
379
|
+
await rename(temporary, GPU_USAGE_HISTORY_FILE);
|
|
380
|
+
});
|
|
381
|
+
return gpuUsageWritePromise;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
return {
|
|
385
|
+
loadManagementState,
|
|
386
|
+
loadGpuUsageHistory,
|
|
387
|
+
loadSnapshotCache,
|
|
388
|
+
loadHistoryIndex,
|
|
389
|
+
persistSnapshotCache,
|
|
390
|
+
persistHistoryIndex,
|
|
391
|
+
revealUnarchivedSession,
|
|
392
|
+
cachedHistoryResult,
|
|
393
|
+
updateHistoryIndex,
|
|
394
|
+
persistManagementState,
|
|
395
|
+
persistGpuUsageHistory,
|
|
396
|
+
};
|
|
397
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { jsonResponse, readJsonBody } from "../http.mjs";
|
|
4
|
+
|
|
5
|
+
export function validateSubmissionSettings(value) {
|
|
6
|
+
if (!value || typeof value.enabled !== "boolean" || typeof value.host !== "string")
|
|
7
|
+
throw new Error("请指定是否启用,以及提交主机");
|
|
8
|
+
const host = value.host.trim();
|
|
9
|
+
if (host.length > 253 || (host && !/^[a-zA-Z0-9_][a-zA-Z0-9_.:@-]*$/.test(host)) || host === "@local")
|
|
10
|
+
throw new Error("请选择 SSH 主机,或填写有效的 SSH 别名 / HostName");
|
|
11
|
+
if (value.enabled && !host) throw new Error("启用监控前请选择提交主机");
|
|
12
|
+
return { enabled: value.enabled, host };
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export class SubmissionSettings {
|
|
16
|
+
constructor({ filename, legacyHost = "" }) {
|
|
17
|
+
this.filename = filename;
|
|
18
|
+
this.value = validateSubmissionSettings({ enabled: Boolean(legacyHost), host: legacyHost });
|
|
19
|
+
try { this.value = validateSubmissionSettings(JSON.parse(readFileSync(filename, "utf8"))); }
|
|
20
|
+
catch (error) { if (error.code !== "ENOENT") throw error; }
|
|
21
|
+
}
|
|
22
|
+
read() { return { ...this.value }; }
|
|
23
|
+
save(value) {
|
|
24
|
+
const next = validateSubmissionSettings(value);
|
|
25
|
+
mkdirSync(path.dirname(this.filename), { recursive: true });
|
|
26
|
+
const temporary = `${this.filename}.tmp`;
|
|
27
|
+
writeFileSync(temporary, JSON.stringify(next, null, 2) + "\n", { mode: 0o600 });
|
|
28
|
+
renameSync(temporary, this.filename);
|
|
29
|
+
this.value = next;
|
|
30
|
+
return this.read();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function submissionSettingsRoutes({ store, isScanning, apply }) {
|
|
35
|
+
return async (request, response, url) => {
|
|
36
|
+
if (url.pathname !== "/api/submissions/settings") return false;
|
|
37
|
+
if (request.method === "GET") jsonResponse(response, 200, store.read());
|
|
38
|
+
else if (request.method === "POST") {
|
|
39
|
+
try {
|
|
40
|
+
const body = await readJsonBody(request);
|
|
41
|
+
// Check after reading the body: a scan may have started in the meantime.
|
|
42
|
+
if (isScanning()) { jsonResponse(response, 409, { error: "正在扫描,请等待扫描结束后保存监控设置" }); return true; }
|
|
43
|
+
const value = store.save(body);
|
|
44
|
+
apply(value);
|
|
45
|
+
jsonResponse(response, 200, value);
|
|
46
|
+
} catch (error) { jsonResponse(response, 400, { error: error.message }); }
|
|
47
|
+
} else jsonResponse(response, 405, { error: "不支持此操作" });
|
|
48
|
+
return true;
|
|
49
|
+
};
|
|
50
|
+
}
|