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,331 @@
|
|
|
1
|
+
"""Read metadata for native CLI histories. No agent process is started."""
|
|
2
|
+
import base64
|
|
3
|
+
import glob
|
|
4
|
+
import json
|
|
5
|
+
import os
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
import re
|
|
8
|
+
import sqlite3
|
|
9
|
+
import sys
|
|
10
|
+
import time
|
|
11
|
+
from urllib.parse import unquote, urlparse
|
|
12
|
+
|
|
13
|
+
config = json.loads(base64.urlsafe_b64decode(sys.argv[1] + "=="))
|
|
14
|
+
roots = {
|
|
15
|
+
"codex": os.path.join(os.environ.get("CODEX_HOME", os.path.expanduser("~/.codex")), "sessions"),
|
|
16
|
+
"claude": os.path.join(os.environ.get("CLAUDE_CONFIG_DIR", os.path.expanduser("~/.claude")), "projects"),
|
|
17
|
+
"antigravity": os.path.expanduser("~/.gemini/antigravity-cli"),
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
def text(content):
|
|
21
|
+
if isinstance(content, str):
|
|
22
|
+
return content
|
|
23
|
+
if not isinstance(content, list):
|
|
24
|
+
return ""
|
|
25
|
+
return "\n".join(part.get("text", "") for part in content if isinstance(part, dict) and part.get("type") in ("text", "input_text", "output_text"))
|
|
26
|
+
|
|
27
|
+
def records(filename, full=False):
|
|
28
|
+
with open(filename, "rb") as handle:
|
|
29
|
+
if full:
|
|
30
|
+
# Conversation pages read only a bounded tail; never load an entire log into memory.
|
|
31
|
+
size = os.fstat(handle.fileno()).st_size
|
|
32
|
+
handle.seek(max(0, size - 2_000_000))
|
|
33
|
+
if handle.tell():
|
|
34
|
+
handle.readline()
|
|
35
|
+
data = handle.read(2_000_000)
|
|
36
|
+
else:
|
|
37
|
+
data = handle.read(24_000)
|
|
38
|
+
size = os.fstat(handle.fileno()).st_size
|
|
39
|
+
if size > 24_000:
|
|
40
|
+
data = data.rsplit(b"\n", 1)[0] + b"\n"
|
|
41
|
+
handle.seek(max(24_000, size - 24_000))
|
|
42
|
+
handle.readline()
|
|
43
|
+
data += handle.read(24_000)
|
|
44
|
+
for line in data.splitlines():
|
|
45
|
+
try:
|
|
46
|
+
value = json.loads(line)
|
|
47
|
+
if isinstance(value, dict):
|
|
48
|
+
yield value
|
|
49
|
+
except (ValueError, UnicodeError):
|
|
50
|
+
pass
|
|
51
|
+
|
|
52
|
+
def metadata(provider, filename):
|
|
53
|
+
item = {"provider": provider, "sessionId": Path(filename).stem, "path": filename,
|
|
54
|
+
"cwd": "", "title": "", "model": "", "updatedAt": int(os.path.getmtime(filename) * 1000)}
|
|
55
|
+
for row in records(filename):
|
|
56
|
+
if provider == "codex":
|
|
57
|
+
payload = row.get("payload") if isinstance(row.get("payload"), dict) else {}
|
|
58
|
+
if row.get("type") == "session_meta":
|
|
59
|
+
item.update(sessionId=payload.get("id") or item["sessionId"], cwd=payload.get("cwd") or item["cwd"])
|
|
60
|
+
if row.get("type") == "turn_context":
|
|
61
|
+
item["model"] = payload.get("model") or item["model"]
|
|
62
|
+
if row.get("type") == "response_item" and payload.get("role") == "user":
|
|
63
|
+
value = text(payload.get("content"))
|
|
64
|
+
if value and not value.lstrip().startswith(("<", "# AGENTS", "# Instructions")):
|
|
65
|
+
item["title"] = item["title"] or value[:160]
|
|
66
|
+
else:
|
|
67
|
+
item["cwd"] = row.get("cwd") or item["cwd"]
|
|
68
|
+
item["sessionId"] = row.get("sessionId") or item["sessionId"]
|
|
69
|
+
message = row.get("message") if isinstance(row.get("message"), dict) else {}
|
|
70
|
+
item["model"] = message.get("model") or item["model"]
|
|
71
|
+
if row.get("type") == "user" and not row.get("isMeta"):
|
|
72
|
+
value = text(message.get("content"))
|
|
73
|
+
if value and not value.lstrip().startswith("<"):
|
|
74
|
+
item["title"] = item["title"] or value[:160]
|
|
75
|
+
if row.get("type") == "summary":
|
|
76
|
+
item["title"] = (row.get("summary") or item["title"])[:160]
|
|
77
|
+
item["title"] = item["title"] or f"{provider} · {item['sessionId'][:8]}"
|
|
78
|
+
return item
|
|
79
|
+
|
|
80
|
+
CREATED_SUBAGENT_RE = re.compile(r'Created the following subagent:\s*\{\s*"conversationId"\s*:\s*"([a-zA-Z0-9][a-zA-Z0-9_-]{0,127})"')
|
|
81
|
+
SENDER_RE = re.compile(r'sender=([a-zA-Z0-9][a-zA-Z0-9_-]{0,127})')
|
|
82
|
+
|
|
83
|
+
def claude_subagents(filename, now_ts):
|
|
84
|
+
sub_dir = Path(filename).with_suffix("") / "subagents"
|
|
85
|
+
if not sub_dir.is_dir():
|
|
86
|
+
return []
|
|
87
|
+
files = []
|
|
88
|
+
for child in sub_dir.glob("agent-*.jsonl"):
|
|
89
|
+
try:
|
|
90
|
+
files.append((child.stat().st_mtime, child))
|
|
91
|
+
except OSError:
|
|
92
|
+
continue
|
|
93
|
+
files.sort(key=lambda item: item[0])
|
|
94
|
+
result = []
|
|
95
|
+
for mtime, child in files[-24:]:
|
|
96
|
+
role = ""
|
|
97
|
+
last_action = ""
|
|
98
|
+
stop_reason = None
|
|
99
|
+
last_type = ""
|
|
100
|
+
try:
|
|
101
|
+
with child.open("rb") as handle:
|
|
102
|
+
size = os.fstat(handle.fileno()).st_size
|
|
103
|
+
head = handle.read(min(8_192, size))
|
|
104
|
+
tail = head if size <= 16_384 else (handle.seek(max(0, size - 16_384)) and False) or handle.read(16_384)
|
|
105
|
+
if size > 16_384 and b"\n" in tail:
|
|
106
|
+
tail = tail.split(b"\n", 1)[1]
|
|
107
|
+
for raw_line in head.splitlines():
|
|
108
|
+
try:
|
|
109
|
+
row = json.loads(raw_line)
|
|
110
|
+
except (ValueError, UnicodeError):
|
|
111
|
+
continue
|
|
112
|
+
if isinstance(row, dict) and row.get("type") == "user":
|
|
113
|
+
val = text((row.get("message") or {}).get("content")).strip()
|
|
114
|
+
if val:
|
|
115
|
+
role = val.splitlines()[0][:120]
|
|
116
|
+
break
|
|
117
|
+
for raw_line in tail.splitlines():
|
|
118
|
+
try:
|
|
119
|
+
row = json.loads(raw_line)
|
|
120
|
+
except (ValueError, UnicodeError):
|
|
121
|
+
continue
|
|
122
|
+
if not isinstance(row, dict):
|
|
123
|
+
continue
|
|
124
|
+
last_type = row.get("type") or last_type
|
|
125
|
+
msg = row.get("message") if isinstance(row.get("message"), dict) else {}
|
|
126
|
+
if "stop_reason" in msg:
|
|
127
|
+
stop_reason = msg.get("stop_reason")
|
|
128
|
+
if isinstance(msg.get("content"), list):
|
|
129
|
+
for blk in msg["content"]:
|
|
130
|
+
if isinstance(blk, dict) and blk.get("type") == "tool_use" and blk.get("name"):
|
|
131
|
+
last_action = str(blk["name"])[:80]
|
|
132
|
+
except OSError:
|
|
133
|
+
continue
|
|
134
|
+
working = (now_ts - mtime < 180) and (stop_reason != "end_turn")
|
|
135
|
+
result.append({
|
|
136
|
+
"id": child.stem,
|
|
137
|
+
"role": role or f"Subagent {child.stem[:10]}",
|
|
138
|
+
"typeName": "subagent",
|
|
139
|
+
"background": True,
|
|
140
|
+
"status": "working" if working else "completed",
|
|
141
|
+
"lastAction": last_action or ("运行中" if working else "已完成"),
|
|
142
|
+
"updatedAt": int(mtime * 1000),
|
|
143
|
+
})
|
|
144
|
+
return result
|
|
145
|
+
|
|
146
|
+
def agy_active_subagents(brain_root, transcript_file, now_ts):
|
|
147
|
+
try:
|
|
148
|
+
size = transcript_file.stat().st_size
|
|
149
|
+
start = max(0, size - 131_072)
|
|
150
|
+
with transcript_file.open("rb") as h:
|
|
151
|
+
h.seek(start)
|
|
152
|
+
data = h.read(131_072)
|
|
153
|
+
if start > 0 and b"\n" in data:
|
|
154
|
+
data = data.split(b"\n", 1)[1]
|
|
155
|
+
cids, done = [], set()
|
|
156
|
+
for line in data.splitlines():
|
|
157
|
+
try:
|
|
158
|
+
row = json.loads(line)
|
|
159
|
+
except (ValueError, UnicodeError):
|
|
160
|
+
continue
|
|
161
|
+
if not isinstance(row, dict):
|
|
162
|
+
continue
|
|
163
|
+
if row.get("type") == "GENERIC" and isinstance(row.get("content"), str):
|
|
164
|
+
for m in CREATED_SUBAGENT_RE.finditer(row["content"]):
|
|
165
|
+
cid = m.group(1)
|
|
166
|
+
if cid not in cids:
|
|
167
|
+
cids.append(cid)
|
|
168
|
+
elif row.get("type") == "SYSTEM_MESSAGE" and isinstance(row.get("content"), str):
|
|
169
|
+
m = SENDER_RE.search(row["content"])
|
|
170
|
+
if m:
|
|
171
|
+
done.add(m.group(1))
|
|
172
|
+
count = 0
|
|
173
|
+
for cid in cids[-24:]:
|
|
174
|
+
if cid in done:
|
|
175
|
+
continue
|
|
176
|
+
logs = brain_root / cid / ".system_generated/logs"
|
|
177
|
+
cf = next((p for p in (logs / "transcript_full.jsonl", logs / "transcript.jsonl") if p.is_file()), None)
|
|
178
|
+
if cf is not None and (now_ts - cf.stat().st_mtime) < 180:
|
|
179
|
+
count += 1
|
|
180
|
+
return count
|
|
181
|
+
except OSError:
|
|
182
|
+
return 0
|
|
183
|
+
|
|
184
|
+
def agy_entries():
|
|
185
|
+
filename = os.path.join(roots["antigravity"], "conversation_summaries.db")
|
|
186
|
+
if not os.path.exists(filename):
|
|
187
|
+
return []
|
|
188
|
+
connection = sqlite3.connect(Path(filename).resolve().as_uri() + "?mode=ro", uri=True, timeout=2)
|
|
189
|
+
try:
|
|
190
|
+
rows = connection.execute("SELECT conversation_id,title,preview,workspace_uris,last_modified_time FROM conversation_summaries").fetchall()
|
|
191
|
+
result = []
|
|
192
|
+
now_ts = time.time()
|
|
193
|
+
brain_root = (Path(roots["antigravity"]) / "brain").resolve()
|
|
194
|
+
for sid, title, preview, workspaces, updated in rows:
|
|
195
|
+
try:
|
|
196
|
+
workspaces = json.loads(workspaces or "[]")
|
|
197
|
+
except ValueError:
|
|
198
|
+
workspaces = [workspaces] if workspaces else []
|
|
199
|
+
if isinstance(workspaces, str):
|
|
200
|
+
workspaces = [workspaces]
|
|
201
|
+
workspace = next((value for value in workspaces if isinstance(value, str)), "")
|
|
202
|
+
cwd = unquote(urlparse(workspace).path) if workspace.startswith("file:") else workspace
|
|
203
|
+
if os.name == "nt" and len(cwd) > 2 and cwd[0] == "/" and cwd[2] == ":":
|
|
204
|
+
cwd = cwd[1:]
|
|
205
|
+
item = {"provider": "antigravity", "sessionId": sid, "cwd": cwd, "title": (title or preview or sid)[:160], "preview": (preview or "")[:1000], "model": "", "updatedAt": str(updated or ""), "path": filename}
|
|
206
|
+
# Metadata only: scans never transfer conversation bodies.
|
|
207
|
+
if isinstance(sid, str) and sid and all(c.isalnum() or c in "-_" for c in sid):
|
|
208
|
+
folder = Path(roots["antigravity"]) / "brain" / sid / ".system_generated/logs"
|
|
209
|
+
for name in ("transcript_full.jsonl", "transcript.jsonl"):
|
|
210
|
+
try:
|
|
211
|
+
tf = folder / name
|
|
212
|
+
stat = tf.stat()
|
|
213
|
+
item["historyVersion"] = f"{name}:{stat.st_mtime_ns}:{stat.st_size}"
|
|
214
|
+
if now_ts - stat.st_mtime < 600:
|
|
215
|
+
active = agy_active_subagents(brain_root, tf, now_ts)
|
|
216
|
+
if active > 0:
|
|
217
|
+
item["activeSubagents"] = active
|
|
218
|
+
break
|
|
219
|
+
except OSError:
|
|
220
|
+
continue
|
|
221
|
+
result.append(item)
|
|
222
|
+
return result
|
|
223
|
+
finally:
|
|
224
|
+
connection.close()
|
|
225
|
+
|
|
226
|
+
def codex_labels():
|
|
227
|
+
root = Path(roots["codex"]).parent
|
|
228
|
+
labels = {}
|
|
229
|
+
database = root / "state_5.sqlite"
|
|
230
|
+
if database.exists():
|
|
231
|
+
connection = None
|
|
232
|
+
try:
|
|
233
|
+
connection = sqlite3.connect(database.resolve().as_uri() + "?mode=ro", uri=True, timeout=2)
|
|
234
|
+
columns = {row[1] for row in connection.execute("PRAGMA table_info(threads)")}
|
|
235
|
+
selected = [name for name in ("id", "title", "name", "model", "cwd") if name in columns]
|
|
236
|
+
if "id" in selected:
|
|
237
|
+
for row in connection.execute("SELECT " + ",".join(selected) + " FROM threads"):
|
|
238
|
+
item = dict(zip(selected, row))
|
|
239
|
+
labels[item["id"]] = item
|
|
240
|
+
except sqlite3.Error:
|
|
241
|
+
pass # The index is optional; JSONL remains the source of discoverable records.
|
|
242
|
+
finally:
|
|
243
|
+
if connection:
|
|
244
|
+
connection.close()
|
|
245
|
+
try:
|
|
246
|
+
with (root / "session_index.jsonl").open(encoding="utf-8") as handle:
|
|
247
|
+
for line in handle:
|
|
248
|
+
try:
|
|
249
|
+
item = json.loads(line)
|
|
250
|
+
if item.get("id") and item.get("thread_name"):
|
|
251
|
+
labels.setdefault(item["id"], {})["name"] = item["thread_name"]
|
|
252
|
+
except ValueError:
|
|
253
|
+
pass
|
|
254
|
+
except OSError:
|
|
255
|
+
pass
|
|
256
|
+
return labels
|
|
257
|
+
|
|
258
|
+
if config.get("operation") == "dialogue":
|
|
259
|
+
provider, filename = config["provider"], os.path.realpath(config["path"])
|
|
260
|
+
root = os.path.realpath(roots.get(provider, ""))
|
|
261
|
+
if provider not in ("codex", "claude") or os.path.commonpath([root, filename]) != root or not filename.endswith(".jsonl"):
|
|
262
|
+
raise ValueError("不支持读取这个会话路径")
|
|
263
|
+
messages = []
|
|
264
|
+
for row in records(filename, full=True):
|
|
265
|
+
message = row.get("payload", {}) if provider == "codex" and row.get("type") == "response_item" else row.get("message", {}) if provider == "claude" else {}
|
|
266
|
+
if not isinstance(message, dict):
|
|
267
|
+
continue
|
|
268
|
+
role = message.get("role")
|
|
269
|
+
value = text(message.get("content"))
|
|
270
|
+
if role in ("user", "assistant") and value:
|
|
271
|
+
messages.append({"role": role, "text": value[:30_000]})
|
|
272
|
+
payload = {"messages": messages[-100:], "limited": os.path.getsize(filename) > 2_000_000 or len(messages) > 100}
|
|
273
|
+
if provider == "claude":
|
|
274
|
+
payload["subagents"] = claude_subagents(filename, time.time())
|
|
275
|
+
print(json.dumps(payload, ensure_ascii=False))
|
|
276
|
+
else:
|
|
277
|
+
cache_file = Path.home() / ".cache" / "scope" / "session-catalog-v1.json"
|
|
278
|
+
try:
|
|
279
|
+
cache = json.loads(cache_file.read_text(encoding="utf-8"))
|
|
280
|
+
except (OSError, ValueError):
|
|
281
|
+
cache = {}
|
|
282
|
+
entries, errors, next_cache = [], [], {}
|
|
283
|
+
now_ts = time.time()
|
|
284
|
+
for provider in ("codex", "claude"):
|
|
285
|
+
for filename in glob.iglob(os.path.join(roots[provider], "**", "*.jsonl"), recursive=True):
|
|
286
|
+
if provider == "claude" and "subagents" in Path(filename).parts:
|
|
287
|
+
continue # Child transcripts share the parent sessionId; they are not resumable sessions.
|
|
288
|
+
try:
|
|
289
|
+
stat = os.stat(filename)
|
|
290
|
+
sub_dir = Path(filename).with_suffix("") / "subagents" if provider == "claude" else None
|
|
291
|
+
sub_mtime = os.stat(sub_dir).st_mtime if sub_dir and sub_dir.is_dir() else 0
|
|
292
|
+
recent = (now_ts - max(stat.st_mtime, sub_mtime)) < 600
|
|
293
|
+
stamp = [stat.st_mtime_ns, stat.st_size]
|
|
294
|
+
saved = cache.get(filename)
|
|
295
|
+
item = dict(saved["item"]) if saved and saved.get("stamp") == stamp else metadata(provider, filename)
|
|
296
|
+
next_cache[filename] = {"stamp": stamp, "item": item}
|
|
297
|
+
if provider == "claude" and recent and sub_dir and sub_dir.is_dir():
|
|
298
|
+
active = sum(1 for sub in claude_subagents(filename, now_ts) if sub["status"] == "working")
|
|
299
|
+
if active > 0:
|
|
300
|
+
item = {**item, "activeSubagents": active}
|
|
301
|
+
entries.append(item)
|
|
302
|
+
except (OSError, ValueError, TypeError) as error:
|
|
303
|
+
errors.append(f"{provider}: {type(error).__name__}")
|
|
304
|
+
labels = codex_labels()
|
|
305
|
+
for item in entries:
|
|
306
|
+
if item["provider"] != "codex":
|
|
307
|
+
continue
|
|
308
|
+
label = labels.get(item["sessionId"], {})
|
|
309
|
+
item["title"] = (label.get("name") or label.get("title") or item["title"])[:160]
|
|
310
|
+
item["cwd"] = label.get("cwd") or item["cwd"]
|
|
311
|
+
item["model"] = label.get("model") or item["model"]
|
|
312
|
+
try:
|
|
313
|
+
entries.extend(agy_entries())
|
|
314
|
+
except (sqlite3.Error, ValueError, TypeError) as error:
|
|
315
|
+
errors.append("antigravity: " + str(error))
|
|
316
|
+
for item in entries:
|
|
317
|
+
if item["provider"] in ("claude", "antigravity"):
|
|
318
|
+
try:
|
|
319
|
+
state = json.loads((Path.home() / ".local/state/scope" / (item["provider"] + "-sessions") / (item["sessionId"] + ".json")).read_text())
|
|
320
|
+
item["phase"] = state.get("phase", "active")
|
|
321
|
+
except FileNotFoundError:
|
|
322
|
+
item["phase"] = "active"
|
|
323
|
+
try:
|
|
324
|
+
cache_file.parent.mkdir(parents=True, exist_ok=True)
|
|
325
|
+
temporary = cache_file.with_suffix(f".{os.getpid()}.tmp")
|
|
326
|
+
temporary.write_text(json.dumps(next_cache, ensure_ascii=False), encoding="utf-8")
|
|
327
|
+
os.chmod(temporary, 0o600)
|
|
328
|
+
os.replace(temporary, cache_file)
|
|
329
|
+
except OSError:
|
|
330
|
+
pass
|
|
331
|
+
print(json.dumps({"entries": entries, "errors": list(dict.fromkeys(errors)), "roots": roots}, ensure_ascii=False))
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export function catalogRoutes(catalog, { jsonResponse, readJsonBody, resolveCodex }) {
|
|
2
|
+
return async (request, response, url) => {
|
|
3
|
+
if (!url.pathname.startsWith("/api/session-catalog")) return false;
|
|
4
|
+
try {
|
|
5
|
+
if (url.pathname === "/api/session-catalog" && request.method === "GET") {
|
|
6
|
+
void catalog.refresh();
|
|
7
|
+
const { state, etag } = catalog.state();
|
|
8
|
+
response.setHeader("Cache-Control", "no-cache");
|
|
9
|
+
response.setHeader("ETag", etag);
|
|
10
|
+
if (request.headers["if-none-match"] === etag) { response.writeHead(304); response.end(); }
|
|
11
|
+
else jsonResponse(response, 200, state);
|
|
12
|
+
} else if (url.pathname === "/api/session-catalog/scan" && request.method === "POST") {
|
|
13
|
+
void catalog.refresh(true);
|
|
14
|
+
jsonResponse(response, 202, { scanning: true });
|
|
15
|
+
} else if (url.pathname === "/api/session-catalog/dialogue" && request.method === "GET") {
|
|
16
|
+
response.setHeader("Cache-Control", "no-store");
|
|
17
|
+
jsonResponse(response, 200, await catalog.dialogue(url.searchParams.get("key"), {
|
|
18
|
+
before: url.searchParams.get("before"), version: url.searchParams.get("version"),
|
|
19
|
+
}));
|
|
20
|
+
} else if (url.pathname === "/api/session-catalog/select" && request.method === "POST") {
|
|
21
|
+
const entry = catalog.get((await readJsonBody(request)).key);
|
|
22
|
+
if (!entry || entry.provider !== "codex") throw new Error("不是 Codex 会话");
|
|
23
|
+
jsonResponse(response, 200, { agent: resolveCodex(entry) });
|
|
24
|
+
} else jsonResponse(response, 404, { error: "接口不存在" });
|
|
25
|
+
} catch (error) { jsonResponse(response, 400, { error: error.message }); }
|
|
26
|
+
return true;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
export function sessionProfileKey(slug) {
|
|
2
|
+
if (!/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,47}$/.test(slug || "")) {
|
|
3
|
+
throw new Error("Profile 标识无效");
|
|
4
|
+
}
|
|
5
|
+
return `account-${slug}`;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function profileFromConnection(key) {
|
|
9
|
+
if (!String(key || "").startsWith("account-")) return null;
|
|
10
|
+
const slug = key.slice(8);
|
|
11
|
+
sessionProfileKey(slug);
|
|
12
|
+
return slug;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function boundConnectionKey(binding, persistedKey = "active") {
|
|
16
|
+
// A restart between writer transfer and committing the assignment must keep
|
|
17
|
+
// the already-persisted target, not revive the previous account.
|
|
18
|
+
if (binding?.status === "switching" && binding.desiredProfile &&
|
|
19
|
+
persistedKey === sessionProfileKey(binding.desiredProfile)) return persistedKey;
|
|
20
|
+
return binding?.profile ? sessionProfileKey(binding.profile) : persistedKey;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function profileHandoffPending(binding) {
|
|
24
|
+
return Boolean(binding?.handoff && binding.status !== "applied");
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Persist intent separately from the current writer. Never claim a queued or
|
|
28
|
+
// failed migration changed the account, and never fall back to another account.
|
|
29
|
+
export class SessionProfileAssignments {
|
|
30
|
+
constructor({ read, write, session, blocked, verify, migrate,
|
|
31
|
+
hold = () => {}, release = async () => {}, restore = async () => {}, now = () => Date.now() }) {
|
|
32
|
+
Object.assign(this, { read, write, session, blocked, verify, migrate, hold, release, restore, now });
|
|
33
|
+
this.running = new Set();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async assign(host, sessionId, slug) {
|
|
37
|
+
sessionProfileKey(slug);
|
|
38
|
+
const key = `${host}:${sessionId}`;
|
|
39
|
+
if (this.running.has(key)) throw new Error("该 Session 正在切换账号,请稍后再试");
|
|
40
|
+
const current = this.session(host, sessionId);
|
|
41
|
+
if (!current) throw new Error("请先将这个 Session 恢复到 App Server");
|
|
42
|
+
if (profileHandoffPending(this.read(host, sessionId))) throw new Error("旧账号正在释放 writer;请等待或先取消交接,再选择其他账号");
|
|
43
|
+
this.running.add(key);
|
|
44
|
+
try {
|
|
45
|
+
await this.write(host, sessionId, {
|
|
46
|
+
...this.read(host, sessionId), desiredProfile: slug,
|
|
47
|
+
status: "queued", error: null,
|
|
48
|
+
});
|
|
49
|
+
} finally { this.running.delete(key); }
|
|
50
|
+
return this.apply(host, sessionId);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async cancel(host, sessionId) {
|
|
54
|
+
const key = `${host}:${sessionId}`;
|
|
55
|
+
if (this.running.has(key)) throw new Error("正在交接 writer,请等待本次检查完成后取消");
|
|
56
|
+
const current = this.read(host, sessionId);
|
|
57
|
+
if (!current || current.status === "applied") return current;
|
|
58
|
+
this.running.add(key);
|
|
59
|
+
try {
|
|
60
|
+
if (profileHandoffPending(current)) await this.restore(host, sessionId, current.handoff.source);
|
|
61
|
+
const restored = current.profile ? { profile: current.profile, desiredProfile: current.profile,
|
|
62
|
+
status: "applied", error: null } : null;
|
|
63
|
+
await this.write(host, sessionId, restored);
|
|
64
|
+
return restored;
|
|
65
|
+
} finally { this.running.delete(key); }
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async apply(host, sessionId) {
|
|
69
|
+
const key = `${host}:${sessionId}`;
|
|
70
|
+
let intent = this.read(host, sessionId);
|
|
71
|
+
if (!intent || !["queued", "switching", "waiting-writer"].includes(intent.status) || this.running.has(key)) return intent;
|
|
72
|
+
if ((intent.nextAttemptAt || 0) > this.now()) return intent;
|
|
73
|
+
const current = this.session(host, sessionId);
|
|
74
|
+
if (!current || (!profileHandoffPending(intent) && (current.status === "offline" || this.blocked(host, sessionId)))) return intent;
|
|
75
|
+
this.running.add(key);
|
|
76
|
+
try {
|
|
77
|
+
if (!profileHandoffPending(intent)) {
|
|
78
|
+
await this.write(host, sessionId, { ...intent, status: "switching", error: null });
|
|
79
|
+
const account = await this.verify(host, intent.desiredProfile, current.executable);
|
|
80
|
+
if (this.blocked(host, sessionId)) {
|
|
81
|
+
await this.write(host, sessionId, { ...intent, status: "queued", error: null });
|
|
82
|
+
return this.read(host, sessionId);
|
|
83
|
+
}
|
|
84
|
+
const latest = this.session(host, sessionId);
|
|
85
|
+
this.hold(host, sessionId);
|
|
86
|
+
const source = Object.fromEntries(["host", "sessionId", "path", "cwd", "model", "effort", "yolo", "executable", "connectionKey", "resumeOnRecovery"]
|
|
87
|
+
.map((field) => [field, latest[field]]));
|
|
88
|
+
intent = { ...intent, status: "waiting-writer", error: null, targetAccount: account,
|
|
89
|
+
handoff: { source, released: false, startedAt: this.now() } };
|
|
90
|
+
await this.write(host, sessionId, intent);
|
|
91
|
+
}
|
|
92
|
+
if (!intent.handoff.released) {
|
|
93
|
+
await this.release(host, sessionId, intent.handoff.source);
|
|
94
|
+
intent = { ...intent, handoff: { ...intent.handoff, released: true, releasedAt: this.now() } };
|
|
95
|
+
await this.write(host, sessionId, intent);
|
|
96
|
+
}
|
|
97
|
+
await this.migrate(host, sessionId, sessionProfileKey(intent.desiredProfile), current.executable, intent.handoff.source);
|
|
98
|
+
await this.write(host, sessionId, {
|
|
99
|
+
profile: intent.desiredProfile, desiredProfile: intent.desiredProfile,
|
|
100
|
+
status: "applied", account: intent.targetAccount, verifiedAt: new Date(this.now()).toISOString(), error: null,
|
|
101
|
+
});
|
|
102
|
+
} catch (error) {
|
|
103
|
+
if (profileHandoffPending(intent) && /already has an active writer|connection reset|disconnected|连接|超时|timeout|ECONN|远端 app-server 已退出/i.test(error.message)) {
|
|
104
|
+
// Crucially, do not resume the source: doing so restarts its 30 minute
|
|
105
|
+
// inactivity grace period. The timer retries only the target writer.
|
|
106
|
+
await this.write(host, sessionId, { ...intent, status: "waiting-writer",
|
|
107
|
+
error: /already has an active writer/i.test(error.message) ? null : `连接暂时不可用,后台将重试:${error.message}`,
|
|
108
|
+
nextAttemptAt: this.now() + 30_000 });
|
|
109
|
+
} else {
|
|
110
|
+
await this.write(host, sessionId, { ...intent, status: "failed", error: error.message, nextAttemptAt: null });
|
|
111
|
+
}
|
|
112
|
+
} finally { this.running.delete(key); }
|
|
113
|
+
return this.read(host, sessionId);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { isIP } from "node:net";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { createPrivateGateway, loadOrCreatePrivateAccessToken } from "./private-gateway.mjs";
|
|
6
|
+
|
|
7
|
+
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
|
8
|
+
const directory = path.join(root, ".scope", "shared-access");
|
|
9
|
+
const config = JSON.parse(await readFile(path.join(directory, "config.json"), "utf8"));
|
|
10
|
+
if (!isIP(config.host) || ["0.0.0.0", "::"].includes(config.host) ||
|
|
11
|
+
!Array.isArray(config.allowedClients) || !config.allowedClients.length ||
|
|
12
|
+
config.allowedClients.some(address => !isIP(address)) ||
|
|
13
|
+
!Number.isInteger(config.port) || config.port < 1024 || config.port > 65535) {
|
|
14
|
+
throw new Error("Shared access requires a specific local IP, port and explicit client IP allowlist");
|
|
15
|
+
}
|
|
16
|
+
const token = await loadOrCreatePrivateAccessToken(path.join(directory, "access.json"));
|
|
17
|
+
const server = createPrivateGateway({ token, allowedClients: config.allowedClients, tls: {
|
|
18
|
+
key: await readFile(path.join(directory, "server.key")),
|
|
19
|
+
cert: await readFile(path.join(directory, "server.crt")),
|
|
20
|
+
} });
|
|
21
|
+
server.listen(config.port, config.host, () => console.log(`SCOPE shared access: https://${config.host}:${config.port}`));
|
|
22
|
+
for (const signal of ["SIGINT", "SIGTERM"]) process.on(signal, () => server.close(() => process.exit(0)));
|