scope-agent-workbench 0.0.0-stage → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +59 -0
- package/LICENSE +21 -0
- package/README.md +174 -2
- package/README.zh-CN.md +175 -0
- package/bin/scope.mjs +111 -0
- package/bridge/account-quotas.mjs +881 -0
- package/bridge/agent-email-relay.mjs +160 -0
- package/bridge/app-server-client.mjs +2522 -0
- package/bridge/app-server-websocket-transport.mjs +219 -0
- package/bridge/archive/routes.mjs +19 -0
- package/bridge/archive/service.mjs +130 -0
- package/bridge/archive/thread-lifecycle.mjs +52 -0
- package/bridge/attachment-store.mjs +184 -0
- package/bridge/auth-profile-failover.mjs +58 -0
- package/bridge/auth-profile-manager.mjs +215 -0
- package/bridge/capacity-recovery.mjs +90 -0
- package/bridge/codex-upgrade.mjs +150 -0
- package/bridge/deployment-profile.mjs +64 -0
- package/bridge/email-notifier.mjs +616 -0
- package/bridge/gpu-usage-history.mjs +322 -0
- package/bridge/host-session-restart.mjs +35 -0
- package/bridge/http.mjs +69 -0
- package/bridge/idle-sessions.mjs +185 -0
- package/bridge/inventory-scanner.mjs +517 -0
- package/bridge/local/dialogue.mjs +150 -0
- package/bridge/local/directories.mjs +40 -0
- package/bridge/local/executable.mjs +29 -0
- package/bridge/local/history.mjs +36 -0
- package/bridge/local/python-probe.mjs +35 -0
- package/bridge/local/runtime.mjs +188 -0
- package/bridge/local/transport.mjs +70 -0
- package/bridge/maintenance/install-command.mjs +141 -0
- package/bridge/maintenance/routes.mjs +21 -0
- package/bridge/maintenance/service.mjs +175 -0
- package/bridge/model-catalog.mjs +21 -0
- package/bridge/persistent-home-guard.mjs +6 -0
- package/bridge/plugins/aliyun-dlc/index.mjs +47 -0
- package/bridge/plugins/aliyun-dlc/manifest.mjs +12 -0
- package/bridge/plugins/aliyun-dlc/monitor.mjs +236 -0
- package/bridge/plugins/aliyun-dlc/probe.mjs +701 -0
- package/bridge/plugins/config-store.mjs +35 -0
- package/bridge/plugins/external.mjs +87 -0
- package/bridge/plugins/package.mjs +96 -0
- package/bridge/plugins/registry.mjs +37 -0
- package/bridge/plugins/routes.mjs +27 -0
- package/bridge/private-gateway.mjs +371 -0
- package/bridge/private-start.mjs +22 -0
- package/bridge/probes/app-server-handoff-probe.mjs +89 -0
- package/bridge/probes/app-server-writer-probe.mjs +72 -0
- package/bridge/probes/assistant-search-probe.mjs +323 -0
- package/bridge/probes/dialogue-probe.mjs +464 -0
- package/bridge/probes/history-probe.mjs +432 -0
- package/bridge/probes/index.mjs +15 -0
- package/bridge/probes/new-session-preflight.mjs +16 -0
- package/bridge/probes/profile-cancel-probe.mjs +19 -0
- package/bridge/probes/profile-delete-probe.mjs +28 -0
- package/bridge/probes/profile-list-probe.mjs +117 -0
- package/bridge/probes/profile-write-probe.mjs +111 -0
- package/bridge/probes/raw-context-probe.mjs +53 -0
- package/bridge/probes/remote-probe.mjs +637 -0
- package/bridge/probes/submission-probe.mjs +2 -0
- package/bridge/probes/takeover-probe.mjs +328 -0
- package/bridge/probes/vscode-open-preflight.mjs +23 -0
- package/bridge/profile-capacity-policy.mjs +14 -0
- package/bridge/providers/acp-forms.py +49 -0
- package/bridge/providers/antigravity-interactive.mjs +14 -0
- package/bridge/providers/antigravity-interactive.py +349 -0
- package/bridge/providers/claude-capabilities.py +52 -0
- package/bridge/providers/claude-interactive.mjs +14 -0
- package/bridge/providers/claude-interactive.py +463 -0
- package/bridge/providers/cli-command.mjs +103 -0
- package/bridge/providers/codex-workbench.mjs +164 -0
- package/bridge/providers/conversation-routes.mjs +28 -0
- package/bridge/providers/conversations.mjs +231 -0
- package/bridge/providers/native-commands.mjs +48 -0
- package/bridge/providers/native-commands.py +38 -0
- package/bridge/providers/native-models.mjs +129 -0
- package/bridge/providers/native-session-state.mjs +14 -0
- package/bridge/providers/native-session-state.py +96 -0
- package/bridge/providers/remote-cli.mjs +75 -0
- package/bridge/providers/remote-job.py +130 -0
- package/bridge/remote-app-server-command.mjs +203 -0
- package/bridge/remote-bootstrap/routes.mjs +51 -0
- package/bridge/remote-bootstrap/scope-protocol.mjs +125 -0
- package/bridge/remote-bootstrap/service.mjs +597 -0
- package/bridge/remote-bootstrap/tunnels.mjs +347 -0
- package/bridge/remote-directory-listing.mjs +148 -0
- package/bridge/remote-images.mjs +140 -0
- package/bridge/remote-profile-home.mjs +39 -0
- package/bridge/remote-rollout-locks.mjs +31 -0
- package/bridge/remote-videos.mjs +129 -0
- package/bridge/research/insights.mjs +522 -0
- package/bridge/research/scan-host.mjs +18 -0
- package/bridge/rollout-summary.mjs +177 -0
- package/bridge/routes/accounts.mjs +326 -0
- package/bridge/routes/dialogue.mjs +165 -0
- package/bridge/routes/email.mjs +50 -0
- package/bridge/routes/management.mjs +291 -0
- package/bridge/routes/models.mjs +312 -0
- package/bridge/routes/runtime.mjs +82 -0
- package/bridge/routes/session-commands.mjs +12 -0
- package/bridge/routes/session-delivery.mjs +328 -0
- package/bridge/routes/session-lifecycle.mjs +839 -0
- package/bridge/routes/system.mjs +289 -0
- package/bridge/server.mjs +3357 -0
- package/bridge/session-attachments.mjs +150 -0
- package/bridge/session-cache-archive.mjs +22 -0
- package/bridge/session-catalog/agy-history.py +388 -0
- package/bridge/session-catalog/catalog.mjs +110 -0
- package/bridge/session-catalog/probe.py +1207 -0
- package/bridge/session-catalog/routes.mjs +34 -0
- package/bridge/session-profiles.mjs +115 -0
- package/bridge/shared-start.mjs +22 -0
- package/bridge/start.mjs +205 -0
- package/bridge/state-persistence.mjs +405 -0
- package/bridge/submissions/settings.mjs +50 -0
- package/bridge/terminal-gateway.mjs +171 -0
- package/bridge/tmux-delivery.mjs +390 -0
- package/bridge/tmux-session-control.mjs +29 -0
- package/bridge/transport/ssh-command.mjs +119 -0
- package/bridge/ui-server.mjs +257 -0
- package/bridge/vscode-opener.mjs +157 -0
- package/bridge/web-terminal.mjs +52 -0
- package/bridge/workbench/conversation-routes.mjs +31 -0
- package/bridge/workbench/directory-probe.mjs +41 -0
- package/bridge/workbench/directory-routes.mjs +112 -0
- package/bridge/workbench/manager-context.mjs +51 -0
- package/bridge/workbench/routes.mjs +40 -0
- package/bridge/workbench/scheduler.mjs +131 -0
- package/bridge/workbench/service.mjs +301 -0
- package/bridge/workbench/store.mjs +64 -0
- package/bridge/workbench/task-archive.mjs +46 -0
- package/dist/client/.assetsignore +2 -0
- package/dist/client/.vite/manifest.json +366 -0
- package/dist/client/_headers +3 -0
- package/dist/client/agents/LICENSE.lobe-icons +21 -0
- package/dist/client/agents/README.md +14 -0
- package/dist/client/agents/antigravity.svg +39 -0
- package/dist/client/agents/claude.svg +1 -0
- package/dist/client/agents/codex.svg +1 -0
- package/dist/client/agents/dsh.svg +4 -0
- package/dist/client/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
- package/dist/client/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
- package/dist/client/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
- package/dist/client/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
- package/dist/client/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
- package/dist/client/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
- package/dist/client/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
- package/dist/client/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
- package/dist/client/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
- package/dist/client/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
- package/dist/client/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
- package/dist/client/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
- package/dist/client/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
- package/dist/client/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
- package/dist/client/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
- package/dist/client/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
- package/dist/client/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
- package/dist/client/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
- package/dist/client/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
- package/dist/client/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
- package/dist/client/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
- package/dist/client/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
- package/dist/client/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
- package/dist/client/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
- package/dist/client/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
- package/dist/client/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
- package/dist/client/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
- package/dist/client/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
- package/dist/client/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
- package/dist/client/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
- package/dist/client/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
- package/dist/client/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
- package/dist/client/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
- package/dist/client/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
- package/dist/client/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
- package/dist/client/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
- package/dist/client/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
- package/dist/client/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
- package/dist/client/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
- package/dist/client/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
- package/dist/client/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
- package/dist/client/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
- package/dist/client/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
- package/dist/client/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
- package/dist/client/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
- package/dist/client/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
- package/dist/client/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
- package/dist/client/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
- package/dist/client/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
- package/dist/client/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
- package/dist/client/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
- package/dist/client/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
- package/dist/client/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
- package/dist/client/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
- package/dist/client/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
- package/dist/client/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
- package/dist/client/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
- package/dist/client/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
- package/dist/client/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
- package/dist/client/assets/_vinext_fonts/geist-8ac0455e797f/geist-001175b1.woff2 +0 -0
- package/dist/client/assets/_vinext_fonts/geist-8ac0455e797f/geist-52306abf.woff2 +0 -0
- package/dist/client/assets/_vinext_fonts/geist-8ac0455e797f/geist-875ccdd4.woff2 +0 -0
- package/dist/client/assets/_vinext_fonts/geist-8ac0455e797f/geist-98bbbccb.woff2 +0 -0
- package/dist/client/assets/_vinext_fonts/geist-8ac0455e797f/geist-ff2310f5.woff2 +0 -0
- package/dist/client/assets/_vinext_fonts/geist-mono-00e989178794/geist-mono-013b2f2f.woff2 +0 -0
- package/dist/client/assets/_vinext_fonts/geist-mono-00e989178794/geist-mono-0638449e.woff2 +0 -0
- package/dist/client/assets/_vinext_fonts/geist-mono-00e989178794/geist-mono-44745446.woff2 +0 -0
- package/dist/client/assets/_vinext_fonts/geist-mono-00e989178794/geist-mono-44e03052.woff2 +0 -0
- package/dist/client/assets/_vinext_fonts/geist-mono-00e989178794/geist-mono-971fb274.woff2 +0 -0
- package/dist/client/assets/_vinext_fonts/geist-mono-00e989178794/geist-mono-f6b33328.woff2 +0 -0
- package/dist/client/assets/addon-fit-BZbxZs2G.js +1 -0
- package/dist/client/assets/framework-CXnKph_e.js +9 -0
- package/dist/client/assets/index-BMior55c.js +3 -0
- package/dist/client/assets/index-CNnP2Ses.css +2 -0
- package/dist/client/assets/layout-segment-context-DjGudgXn.js +1 -0
- package/dist/client/assets/page-CJqXlhDs.js +551 -0
- package/dist/client/assets/page-LYzRz6_S.css +1 -0
- package/dist/client/assets/rolldown-runtime-S-ySWqyJ.js +1 -0
- package/dist/client/assets/xterm-BBgU7shl.js +36 -0
- package/dist/client/favicon.svg +6 -0
- package/dist/client/file.svg +1 -0
- package/dist/client/globe.svg +1 -0
- package/dist/client/og.png +0 -0
- package/dist/client/scope-logo.svg +11 -0
- package/dist/client/window.svg +1 -0
- package/dist/server/.vite/manifest.json +14 -0
- package/dist/server/__vite_rsc_assets_manifest.js +49 -0
- package/dist/server/assets/index-CNnP2Ses.css +2 -0
- package/dist/server/image-config.json +1 -0
- package/dist/server/index.js +15201 -0
- package/dist/server/ssr/__vite_rsc_assets_manifest.js +49 -0
- package/dist/server/ssr/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
- package/dist/server/ssr/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
- package/dist/server/ssr/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
- package/dist/server/ssr/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
- package/dist/server/ssr/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
- package/dist/server/ssr/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
- package/dist/server/ssr/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
- package/dist/server/ssr/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
- package/dist/server/ssr/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
- package/dist/server/ssr/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
- package/dist/server/ssr/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
- package/dist/server/ssr/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
- package/dist/server/ssr/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
- package/dist/server/ssr/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
- package/dist/server/ssr/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
- package/dist/server/ssr/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
- package/dist/server/ssr/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
- package/dist/server/ssr/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
- package/dist/server/ssr/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
- package/dist/server/ssr/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
- package/dist/server/ssr/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
- package/dist/server/ssr/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
- package/dist/server/ssr/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
- package/dist/server/ssr/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
- package/dist/server/ssr/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
- package/dist/server/ssr/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
- package/dist/server/ssr/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
- package/dist/server/ssr/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
- package/dist/server/ssr/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
- package/dist/server/ssr/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
- package/dist/server/ssr/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
- package/dist/server/ssr/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
- package/dist/server/ssr/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
- package/dist/server/ssr/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
- package/dist/server/ssr/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
- package/dist/server/ssr/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
- package/dist/server/ssr/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
- package/dist/server/ssr/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
- package/dist/server/ssr/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
- package/dist/server/ssr/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
- package/dist/server/ssr/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
- package/dist/server/ssr/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
- package/dist/server/ssr/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
- package/dist/server/ssr/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
- package/dist/server/ssr/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
- package/dist/server/ssr/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
- package/dist/server/ssr/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
- package/dist/server/ssr/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
- package/dist/server/ssr/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
- package/dist/server/ssr/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
- package/dist/server/ssr/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
- package/dist/server/ssr/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
- package/dist/server/ssr/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
- package/dist/server/ssr/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
- package/dist/server/ssr/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
- package/dist/server/ssr/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
- package/dist/server/ssr/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
- package/dist/server/ssr/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
- package/dist/server/ssr/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
- package/dist/server/ssr/assets/addon-fit-C09Jj0_f.js +42 -0
- package/dist/server/ssr/assets/error-boundary-Dd2ZYXA8.js +277 -0
- package/dist/server/ssr/assets/layout-segment-context-HV_Mvyzf.js +37 -0
- package/dist/server/ssr/assets/page-BB9Dri2u.js +104686 -0
- package/dist/server/ssr/assets/page-LYzRz6_S.css +1 -0
- package/dist/server/ssr/assets/xterm-DgzE4ZZ1.js +10232 -0
- package/dist/server/ssr/index.js +11840 -0
- package/dist/server/ssr/vinext-server.json +1 -0
- package/dist/server/vinext-externals.json +1 -0
- package/dist/server/vinext-server.json +1 -0
- package/dist/server/wrangler.json +1 -0
- package/examples/agents/global-agreements.example.md +10 -0
- package/examples/agents/research-project.example.md +10 -0
- package/examples/agents-media-previews.md +22 -0
- package/examples/deployment.example.json +6 -0
- package/examples/leak-denylist.example.json +10 -0
- package/examples/plugins/hello/index.mjs +4 -0
- package/examples/plugins/hello/scope-plugin.json +13 -0
- package/examples/workbench.config.json +44 -0
- package/lib/account-quota.d.ts +42 -0
- package/lib/account-quota.js +121 -0
- package/lib/browser-snapshot-cache.js +61 -0
- package/lib/conversation-location.js +26 -0
- package/lib/conversation.js +62 -0
- package/lib/dialogue-refresh.js +14 -0
- package/lib/execution-host.js +22 -0
- package/lib/formula-preview.js +48 -0
- package/lib/i18n.tsx +81 -0
- package/lib/incremental-snapshot.js +324 -0
- package/lib/manager-plan.js +37 -0
- package/lib/markdown-images.js +22 -0
- package/lib/markdown-math.js +151 -0
- package/lib/markdown-url.js +13 -0
- package/lib/model-effort.js +13 -0
- package/lib/native-history.d.ts +32 -0
- package/lib/native-history.js +94 -0
- package/lib/overview-delta.js +41 -0
- package/lib/project-view.js +86 -0
- package/lib/projects.js +74 -0
- package/lib/remote-links.js +95 -0
- package/lib/runtime-config.js +70 -0
- package/lib/session-activity.js +34 -0
- package/lib/session-cache-guard.js +52 -0
- package/lib/session-filters.js +38 -0
- package/lib/ssh-config.js +26 -0
- package/lib/stable-order.js +39 -0
- package/lib/subagent-display-prefs.ts +130 -0
- package/lib/workbench-config.js +172 -0
- package/package.json +105 -4
- package/scripts/agent-email-relay.mjs +104 -0
- package/scripts/benchmark-bridge.mjs +38 -0
- package/scripts/cli-integration-smoke.mjs +64 -0
- package/scripts/email-notification-cli.mjs +28 -0
- package/scripts/enable-private-access.ps1 +109 -0
- package/scripts/export-opensource.mjs +112 -0
- package/scripts/fixtures/media/convergence.png +0 -0
- package/scripts/fixtures/media/rollout_demo.mp4 +0 -0
- package/scripts/fixtures/native-conversations.mjs +465 -0
- package/scripts/fixtures/workbench-conversations.mjs +475 -0
- package/scripts/install-remote-server.sh +67 -0
- package/scripts/lib/export-directory.mjs +38 -0
- package/scripts/lib/secret-scanner.mjs +139 -0
- package/scripts/plugin-cli.mjs +19 -0
- package/scripts/preview-workbench.mjs +669 -0
- package/scripts/probe-antigravity-acp.mjs +35 -0
- package/scripts/remote-bootstrap-cli.mjs +52 -0
- package/scripts/remote-email-tool.py +383 -0
|
@@ -0,0 +1,463 @@
|
|
|
1
|
+
"""One owned Claude stream-json process, with durable UI control and event snapshots."""
|
|
2
|
+
import fcntl
|
|
3
|
+
import json
|
|
4
|
+
import os
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
import selectors
|
|
7
|
+
import signal
|
|
8
|
+
import subprocess
|
|
9
|
+
import sys
|
|
10
|
+
import time
|
|
11
|
+
|
|
12
|
+
root = Path.home() / ".local/state/scope/runs" / sys.argv[1]
|
|
13
|
+
config = json.loads((root / "claude-config.json").read_text(encoding="utf-8"))
|
|
14
|
+
controls = root / "controls"
|
|
15
|
+
controls.mkdir(mode=0o700, exist_ok=True)
|
|
16
|
+
mutex = (root / "control.lock").open("a")
|
|
17
|
+
state = {"status": "running", "sessionId": config.get("resumeSessionId"), "events": [],
|
|
18
|
+
"permissions": [], "controlResults": [], "text": "", "interactive": True}
|
|
19
|
+
pending = {}
|
|
20
|
+
queue = []
|
|
21
|
+
seen = set()
|
|
22
|
+
subagents = {}
|
|
23
|
+
finished = False
|
|
24
|
+
stopping = None
|
|
25
|
+
closing = None
|
|
26
|
+
initialized = False
|
|
27
|
+
partial = ""
|
|
28
|
+
result_value = None
|
|
29
|
+
last_snapshot = None
|
|
30
|
+
signal_stage = 0
|
|
31
|
+
inflight = set()
|
|
32
|
+
session_state = None
|
|
33
|
+
|
|
34
|
+
def save():
|
|
35
|
+
global last_snapshot
|
|
36
|
+
state["permissions"] = list(pending.values())
|
|
37
|
+
state["events"] = state["events"][-300:]
|
|
38
|
+
while len(state["events"]) > 1 and len(json.dumps(state["events"])) > 800_000:
|
|
39
|
+
state["events"].pop(0)
|
|
40
|
+
state["truncated"] = True
|
|
41
|
+
state["controlResults"] = state["controlResults"][-30:]
|
|
42
|
+
sub_list = list(subagents.values())[-24:]
|
|
43
|
+
# Keep total subagent workflow buffer bounded inside interactive.json
|
|
44
|
+
while len(json.dumps(sub_list)) > 240_000:
|
|
45
|
+
trimmed = False
|
|
46
|
+
for item in sub_list:
|
|
47
|
+
steps = item.get("steps")
|
|
48
|
+
if isinstance(steps, list) and len(steps) > 4:
|
|
49
|
+
item["steps"] = ([steps[0]] + steps[2:]) if steps[0].get("kind") == "prompt" else steps[1:]
|
|
50
|
+
trimmed = True
|
|
51
|
+
if not trimmed:
|
|
52
|
+
break
|
|
53
|
+
state["subagents"] = sub_list
|
|
54
|
+
state["partial"] = partial[-60000:]
|
|
55
|
+
encoded = json.dumps(state)
|
|
56
|
+
if encoded == last_snapshot: return
|
|
57
|
+
temporary = root / "interactive.tmp"
|
|
58
|
+
temporary.write_text(encoded, encoding="utf-8")
|
|
59
|
+
temporary.replace(root / "interactive.json")
|
|
60
|
+
last_snapshot = encoded
|
|
61
|
+
|
|
62
|
+
def event(kind, **data):
|
|
63
|
+
state["events"].append({"kind": kind, "at": int(time.time() * 1000), **data})
|
|
64
|
+
|
|
65
|
+
def send(value):
|
|
66
|
+
child.stdin.write((json.dumps(value) + "\n").encode())
|
|
67
|
+
child.stdin.flush()
|
|
68
|
+
|
|
69
|
+
def user(prompt):
|
|
70
|
+
send({"type": "user", "message": {"role": "user", "content": prompt},
|
|
71
|
+
"parent_tool_use_id": None, "session_id": state.get("sessionId") or ""})
|
|
72
|
+
|
|
73
|
+
def respond(request_id, response):
|
|
74
|
+
send({"type": "control_response", "response": {"subtype": "success", "request_id": request_id, "response": response}})
|
|
75
|
+
|
|
76
|
+
def find_subagent(task_id=None, tool_id=None):
|
|
77
|
+
if tool_id and tool_id in subagents:
|
|
78
|
+
return subagents[tool_id]
|
|
79
|
+
if task_id and task_id in subagents:
|
|
80
|
+
return subagents[task_id]
|
|
81
|
+
if task_id:
|
|
82
|
+
for entry in subagents.values():
|
|
83
|
+
if entry.get("taskId") == task_id:
|
|
84
|
+
return entry
|
|
85
|
+
if tool_id:
|
|
86
|
+
for entry in subagents.values():
|
|
87
|
+
if entry.get("toolUseId") == tool_id:
|
|
88
|
+
return entry
|
|
89
|
+
return None
|
|
90
|
+
|
|
91
|
+
def subagent_tool_summary(name, raw_input):
|
|
92
|
+
if isinstance(raw_input, dict):
|
|
93
|
+
for key in ("description", "file_path", "path", "command", "cmd", "pattern", "query", "url", "glob", "prompt"):
|
|
94
|
+
val = raw_input.get(key)
|
|
95
|
+
if isinstance(val, str) and val.strip():
|
|
96
|
+
line = val.strip().splitlines()[0].strip()
|
|
97
|
+
if key in ("file_path", "path") and ("/" in line or "\\" in line):
|
|
98
|
+
return (line.replace("\\", "/").split("/")[-1] or line)[:80]
|
|
99
|
+
return line[:80]
|
|
100
|
+
return ""
|
|
101
|
+
|
|
102
|
+
def append_subagent_step(entry, step):
|
|
103
|
+
steps = entry.setdefault("steps", [])
|
|
104
|
+
steps.append(step)
|
|
105
|
+
if len(steps) > 40:
|
|
106
|
+
if steps[0].get("kind") == "prompt":
|
|
107
|
+
entry["steps"] = [steps[0]] + steps[-39:]
|
|
108
|
+
else:
|
|
109
|
+
entry["steps"] = steps[-40:]
|
|
110
|
+
entry["hasWorkflow"] = True
|
|
111
|
+
|
|
112
|
+
def frame(value):
|
|
113
|
+
global initialized, partial, result_value, finished, session_state
|
|
114
|
+
kind = value.get("type")
|
|
115
|
+
now_ms = int(time.time() * 1000)
|
|
116
|
+
if value.get("session_id"):
|
|
117
|
+
state["sessionId"] = value["session_id"]
|
|
118
|
+
if kind == "system":
|
|
119
|
+
subtype = value.get("subtype")
|
|
120
|
+
if subtype == "init": state["commands"] = [{"name": name} for name in value.get("slash_commands", [])]
|
|
121
|
+
task_id = value.get("task_id")
|
|
122
|
+
if subtype == "session_state_changed": session_state = value.get("state")
|
|
123
|
+
elif subtype == "task_started" and value.get("task_type") in ("local_agent", "local_workflow"):
|
|
124
|
+
inflight.add(task_id)
|
|
125
|
+
tool_id = value.get("tool_use_id")
|
|
126
|
+
entry = find_subagent(task_id=task_id, tool_id=tool_id)
|
|
127
|
+
if entry is None:
|
|
128
|
+
entry = {
|
|
129
|
+
"id": str(tool_id or task_id),
|
|
130
|
+
"toolUseId": str(tool_id) if tool_id else "",
|
|
131
|
+
"taskId": str(task_id),
|
|
132
|
+
"role": str(value.get("description") or "后台子代理")[:120],
|
|
133
|
+
"typeName": str(value.get("task_type") or "agent")[:60],
|
|
134
|
+
"background": True,
|
|
135
|
+
"status": "working",
|
|
136
|
+
"lastAction": "后台运行中",
|
|
137
|
+
"updatedAt": now_ms,
|
|
138
|
+
"hasWorkflow": True,
|
|
139
|
+
"steps": [],
|
|
140
|
+
"partial": "",
|
|
141
|
+
}
|
|
142
|
+
subagents[entry["id"]] = entry
|
|
143
|
+
else:
|
|
144
|
+
entry["taskId"] = str(task_id)
|
|
145
|
+
if tool_id and not entry.get("toolUseId"):
|
|
146
|
+
entry["toolUseId"] = str(tool_id)
|
|
147
|
+
entry["background"] = True
|
|
148
|
+
entry["status"] = "working"
|
|
149
|
+
entry["updatedAt"] = now_ms
|
|
150
|
+
elif subtype in ("task_progress", "task_updated"):
|
|
151
|
+
patch_status = value.get("patch", {}).get("status") if isinstance(value.get("patch"), dict) else None
|
|
152
|
+
if subtype == "task_updated" and patch_status in ("completed", "failed", "stopped"):
|
|
153
|
+
inflight.discard(task_id)
|
|
154
|
+
entry = find_subagent(task_id=task_id, tool_id=value.get("tool_use_id"))
|
|
155
|
+
if entry is not None:
|
|
156
|
+
action = value.get("last_tool_name") or value.get("description") or patch_status
|
|
157
|
+
if action: entry["lastAction"] = str(action)[:120]
|
|
158
|
+
if patch_status in ("completed", "failed", "stopped"):
|
|
159
|
+
entry["status"] = patch_status
|
|
160
|
+
entry["updatedAt"] = now_ms
|
|
161
|
+
elif subtype == "task_notification":
|
|
162
|
+
inflight.discard(task_id)
|
|
163
|
+
entry = find_subagent(task_id=task_id, tool_id=value.get("tool_use_id"))
|
|
164
|
+
if entry is None and task_id:
|
|
165
|
+
entry = {
|
|
166
|
+
"id": str(task_id),
|
|
167
|
+
"taskId": str(task_id),
|
|
168
|
+
"role": str(value.get("description") or "后台子代理")[:120],
|
|
169
|
+
"typeName": "local_agent",
|
|
170
|
+
"background": True,
|
|
171
|
+
"status": "completed",
|
|
172
|
+
"lastAction": "已完成",
|
|
173
|
+
"updatedAt": now_ms,
|
|
174
|
+
}
|
|
175
|
+
subagents[entry["id"]] = entry
|
|
176
|
+
if entry is not None:
|
|
177
|
+
done_status = value.get("status")
|
|
178
|
+
entry["status"] = done_status if done_status in ("completed", "failed", "stopped") else "completed"
|
|
179
|
+
entry["lastAction"] = str(value.get("summary") or "已完成")[:120]
|
|
180
|
+
entry["updatedAt"] = now_ms
|
|
181
|
+
if kind in ("assistant", "stream_event") and value.get("parent_tool_use_id") is None:
|
|
182
|
+
finished = False
|
|
183
|
+
if kind == "control_response" and value.get("response", {}).get("request_id") == "scope-init":
|
|
184
|
+
if value["response"].get("subtype") == "error":
|
|
185
|
+
raise RuntimeError(value["response"].get("error", "Claude initialization failed"))
|
|
186
|
+
initialized = True
|
|
187
|
+
state["commands"] = value["response"].get("response", {}).get("commands", [])
|
|
188
|
+
user(config["prompt"])
|
|
189
|
+
elif kind == "control_request":
|
|
190
|
+
request = value.get("request", {})
|
|
191
|
+
rid = value["request_id"]
|
|
192
|
+
if request.get("subtype") == "can_use_tool" and not stopping:
|
|
193
|
+
if len(json.dumps(request)) > 500_000:
|
|
194
|
+
respond(rid, {"behavior": "deny", "message": "Approval input exceeds display limit; split the operation"})
|
|
195
|
+
event("permission", text="审批内容过大,已拒绝;请拆分操作")
|
|
196
|
+
return
|
|
197
|
+
pending[rid] = {"id": rid, "tool": request.get("tool_name", "Tool"),
|
|
198
|
+
"input": request.get("input", {}), "description": request.get("description", ""),
|
|
199
|
+
"reason": request.get("decision_reason", ""), "path": request.get("blocked_path", "")}
|
|
200
|
+
state["status"] = "waiting_permission"
|
|
201
|
+
else:
|
|
202
|
+
respond(rid, {"behavior": "deny", "message": "SCOPE cannot handle this request or is stopping"})
|
|
203
|
+
elif kind == "control_cancel_request":
|
|
204
|
+
pending.pop(value.get("request_id"), None)
|
|
205
|
+
if not pending and not stopping: state["status"] = "running"
|
|
206
|
+
elif kind == "stream_event":
|
|
207
|
+
parent_id = value.get("parent_tool_use_id")
|
|
208
|
+
data = value.get("event", {})
|
|
209
|
+
if parent_id:
|
|
210
|
+
entry = find_subagent(tool_id=parent_id)
|
|
211
|
+
if entry is not None and data.get("type") == "content_block_delta" and data.get("delta", {}).get("type") == "text_delta":
|
|
212
|
+
entry["partial"] = (entry.get("partial", "") + data["delta"].get("text", ""))[-8000:]
|
|
213
|
+
entry["updatedAt"] = now_ms
|
|
214
|
+
entry["hasWorkflow"] = True
|
|
215
|
+
return
|
|
216
|
+
if data.get("type") == "content_block_delta" and data.get("delta", {}).get("type") == "text_delta":
|
|
217
|
+
partial += data["delta"].get("text", "")
|
|
218
|
+
elif kind == "assistant":
|
|
219
|
+
parent_id = value.get("parent_tool_use_id")
|
|
220
|
+
if parent_id:
|
|
221
|
+
entry = find_subagent(tool_id=parent_id)
|
|
222
|
+
if entry is not None:
|
|
223
|
+
entry["updatedAt"] = now_ms
|
|
224
|
+
entry["partial"] = ""
|
|
225
|
+
msg = value.get("message") if isinstance(value.get("message"), dict) else {}
|
|
226
|
+
if isinstance(msg.get("model"), str) and not entry.get("model"):
|
|
227
|
+
entry["model"] = msg["model"][:80]
|
|
228
|
+
for block in msg.get("content", []):
|
|
229
|
+
if not isinstance(block, dict):
|
|
230
|
+
continue
|
|
231
|
+
btype = block.get("type")
|
|
232
|
+
if btype == "thinking":
|
|
233
|
+
tval = str(block.get("thinking") or block.get("text") or "").strip()
|
|
234
|
+
if tval:
|
|
235
|
+
append_subagent_step(entry, {
|
|
236
|
+
"id": f"live-think-{now_ms}-{len(entry.get('steps', []))}",
|
|
237
|
+
"kind": "thinking",
|
|
238
|
+
"title": "思考过程",
|
|
239
|
+
"text": tval[:2500],
|
|
240
|
+
"timestamp": now_ms,
|
|
241
|
+
})
|
|
242
|
+
elif btype == "tool_use":
|
|
243
|
+
tname = str(block.get("name") or "工具调用")[:80]
|
|
244
|
+
tinput = block.get("input")
|
|
245
|
+
summary = subagent_tool_summary(tname, tinput)
|
|
246
|
+
entry["lastAction"] = f"{tname} · {summary}"[:96] if summary else tname
|
|
247
|
+
try:
|
|
248
|
+
in_str = json.dumps(tinput, ensure_ascii=False, indent=2) if tinput is not None else ""
|
|
249
|
+
except (TypeError, ValueError):
|
|
250
|
+
in_str = str(tinput)
|
|
251
|
+
append_subagent_step(entry, {
|
|
252
|
+
"id": str(block.get("id") or f"live-tool-{now_ms}-{len(entry.get('steps', []))}"),
|
|
253
|
+
"kind": "tool",
|
|
254
|
+
"toolName": tname,
|
|
255
|
+
"title": tname,
|
|
256
|
+
"summary": summary,
|
|
257
|
+
"inputPreview": in_str[:2500],
|
|
258
|
+
"output": "",
|
|
259
|
+
"isError": False,
|
|
260
|
+
"status": "running",
|
|
261
|
+
"timestamp": now_ms,
|
|
262
|
+
})
|
|
263
|
+
elif btype == "text":
|
|
264
|
+
tval = str(block.get("text") or "").strip()
|
|
265
|
+
if tval:
|
|
266
|
+
if not entry.get("lastAction"):
|
|
267
|
+
entry["lastAction"] = "生成回复中"
|
|
268
|
+
append_subagent_step(entry, {
|
|
269
|
+
"id": f"live-asst-{now_ms}-{len(entry.get('steps', []))}",
|
|
270
|
+
"kind": "assistant",
|
|
271
|
+
"title": "回复",
|
|
272
|
+
"text": tval[:6000],
|
|
273
|
+
"timestamp": now_ms,
|
|
274
|
+
})
|
|
275
|
+
return
|
|
276
|
+
partial = ""
|
|
277
|
+
for block in value.get("message", {}).get("content", []):
|
|
278
|
+
if block.get("type") == "text":
|
|
279
|
+
event("assistant", text=block.get("text", "")[-60000:])
|
|
280
|
+
elif block.get("type") == "tool_use":
|
|
281
|
+
tool_name = block.get("name")
|
|
282
|
+
tool_input = block.get("input", {})
|
|
283
|
+
if tool_name in ("Agent", "Task") and isinstance(tool_input, dict):
|
|
284
|
+
tid = str(block.get("id") or f"sub-{len(subagents) + 1}")
|
|
285
|
+
prompt_val = str(tool_input.get("prompt") or "").strip()
|
|
286
|
+
subagents[tid] = {
|
|
287
|
+
"id": tid,
|
|
288
|
+
"toolUseId": tid,
|
|
289
|
+
"role": str(tool_input.get("description") or prompt_val or "子代理任务")[:120],
|
|
290
|
+
"typeName": str(tool_input.get("subagent_type") or "agent")[:60],
|
|
291
|
+
"background": bool(tool_input.get("run_in_background")),
|
|
292
|
+
"status": "working",
|
|
293
|
+
"lastAction": "启动中",
|
|
294
|
+
"updatedAt": now_ms,
|
|
295
|
+
"hasWorkflow": True,
|
|
296
|
+
"steps": ([{"id": f"prompt-{tid}", "kind": "prompt", "title": "子代理任务", "text": prompt_val[:4000], "timestamp": now_ms}] if prompt_val else []),
|
|
297
|
+
"partial": "",
|
|
298
|
+
}
|
|
299
|
+
if len(json.dumps(tool_input)) > 60000: tool_input = {"preview": json.dumps(tool_input, ensure_ascii=False)[:60000], "truncated": True}
|
|
300
|
+
event("tool", id=block.get("id"), name=tool_name, input=tool_input)
|
|
301
|
+
elif kind == "user" and isinstance(value.get("message", {}).get("content"), list):
|
|
302
|
+
if value.get("parent_tool_use_id"):
|
|
303
|
+
entry = find_subagent(tool_id=value.get("parent_tool_use_id"))
|
|
304
|
+
if entry is not None:
|
|
305
|
+
entry["updatedAt"] = now_ms
|
|
306
|
+
for block in value["message"]["content"]:
|
|
307
|
+
if isinstance(block, dict) and block.get("type") == "tool_result":
|
|
308
|
+
tid = str(block.get("tool_use_id") or "")
|
|
309
|
+
raw_out = block.get("content", "")
|
|
310
|
+
if isinstance(raw_out, list):
|
|
311
|
+
out_text = "\n".join(
|
|
312
|
+
(p.get("text", "") if isinstance(p, dict) else str(p))
|
|
313
|
+
for p in raw_out
|
|
314
|
+
if not (isinstance(p, dict) and p.get("type") == "image")
|
|
315
|
+
)
|
|
316
|
+
elif isinstance(raw_out, str):
|
|
317
|
+
out_text = raw_out
|
|
318
|
+
else:
|
|
319
|
+
out_text = json.dumps(raw_out, ensure_ascii=False)
|
|
320
|
+
is_err = bool(block.get("is_error"))
|
|
321
|
+
for step in reversed(entry.get("steps", [])):
|
|
322
|
+
if step.get("kind") == "tool" and step.get("id") == tid:
|
|
323
|
+
step["output"] = out_text[:3000]
|
|
324
|
+
step["isError"] = is_err
|
|
325
|
+
step["status"] = "failed" if is_err else "completed"
|
|
326
|
+
break
|
|
327
|
+
return
|
|
328
|
+
for block in value["message"]["content"]:
|
|
329
|
+
if block.get("type") == "tool_result":
|
|
330
|
+
content = block.get("content", "")
|
|
331
|
+
tid = block.get("tool_use_id")
|
|
332
|
+
text_val = content if isinstance(content, str) else json.dumps(content)
|
|
333
|
+
if tid and tid in subagents:
|
|
334
|
+
entry = subagents[tid]
|
|
335
|
+
if "Async agent launched" in text_val or (entry.get("taskId") and entry["taskId"] in inflight):
|
|
336
|
+
entry["background"] = True
|
|
337
|
+
entry["lastAction"] = "后台运行中"
|
|
338
|
+
entry["updatedAt"] = now_ms
|
|
339
|
+
else:
|
|
340
|
+
entry["status"] = "failed" if block.get("is_error") else "completed"
|
|
341
|
+
entry["lastAction"] = "失败" if block.get("is_error") else "已完成"
|
|
342
|
+
entry["updatedAt"] = now_ms
|
|
343
|
+
event("tool_result", id=tid, text=text_val[-12000:])
|
|
344
|
+
elif kind == "result":
|
|
345
|
+
partial = ""
|
|
346
|
+
result_value = value
|
|
347
|
+
state["text"] = value.get("result", "")[-120000:]
|
|
348
|
+
state["error"] = (value.get("result") or "; ".join(value.get("errors", []))) if value.get("is_error") else None
|
|
349
|
+
finished = True
|
|
350
|
+
|
|
351
|
+
args = [config["executable"], "-p", "--input-format", "stream-json", "--output-format", "stream-json",
|
|
352
|
+
"--verbose", "--include-partial-messages", "--permission-prompt-tool", "stdio",
|
|
353
|
+
"--permission-mode", "acceptEdits" if config["permissionMode"] == "workspace" else config["permissionMode"]]
|
|
354
|
+
if config.get("model"): args += ["--model", config["model"]]
|
|
355
|
+
if config.get("effort"): args += ["--effort", config["effort"]]
|
|
356
|
+
if config.get("resumeSessionId"): args += ["--resume", config["resumeSessionId"]]
|
|
357
|
+
child = None
|
|
358
|
+
try:
|
|
359
|
+
with (root / "claude-stderr").open("wb") as errors:
|
|
360
|
+
child = subprocess.Popen(args, cwd=config["cwd"], stdin=subprocess.PIPE, stdout=subprocess.PIPE,
|
|
361
|
+
stderr=errors, start_new_session=True,
|
|
362
|
+
env={**os.environ, "CLAUDE_CODE_SDK_READS_SESSION_STATE": "1"})
|
|
363
|
+
save()
|
|
364
|
+
selector = selectors.DefaultSelector()
|
|
365
|
+
selector.register(child.stdout, selectors.EVENT_READ)
|
|
366
|
+
send({"type": "control_request", "request_id": "scope-init", "request": {"subtype": "initialize", "hooks": {}}})
|
|
367
|
+
buffer = b""
|
|
368
|
+
started = time.monotonic()
|
|
369
|
+
while child.poll() is None:
|
|
370
|
+
for key, _ in selector.select(0.15):
|
|
371
|
+
chunk = os.read(key.fd, 65536)
|
|
372
|
+
if not chunk: continue
|
|
373
|
+
buffer += chunk
|
|
374
|
+
if len(buffer) > 8_000_000: raise RuntimeError("Claude event exceeds size limit")
|
|
375
|
+
while b"\n" in buffer:
|
|
376
|
+
line, buffer = buffer.split(b"\n", 1)
|
|
377
|
+
try: value = json.loads(line)
|
|
378
|
+
except ValueError: continue
|
|
379
|
+
frame(value)
|
|
380
|
+
fcntl.flock(mutex, fcntl.LOCK_EX)
|
|
381
|
+
try:
|
|
382
|
+
incoming = [(file, json.loads(file.read_text())) for file in controls.glob("*.json") if file.name not in seen]
|
|
383
|
+
for file, command in sorted(incoming, key=lambda item: (item[1].get("_sequence", 0), item[0].stat().st_mtime_ns, item[0].name)):
|
|
384
|
+
seen.add(file.name)
|
|
385
|
+
try:
|
|
386
|
+
action = command["action"]
|
|
387
|
+
if closing or stopping: raise ValueError("本轮正在结束,请等待后重新发送")
|
|
388
|
+
if action == "message":
|
|
389
|
+
queue.append(command["prompt"])
|
|
390
|
+
event("user", text=command["prompt"], queued=True)
|
|
391
|
+
elif action == "permission":
|
|
392
|
+
request = pending.get(command["requestId"])
|
|
393
|
+
if not request: raise ValueError("权限请求已失效或已处理")
|
|
394
|
+
response = {"behavior": "deny", "message": "用户拒绝了这次操作"}
|
|
395
|
+
if command["decision"] == "allow":
|
|
396
|
+
original = request["input"]
|
|
397
|
+
if request["tool"] == "AskUserQuestion":
|
|
398
|
+
answers = command.get("answers", {})
|
|
399
|
+
questions = original.get("questions", [])
|
|
400
|
+
if not questions or any(not isinstance(answers.get(q["question"]), str) or not answers[q["question"]].strip() for q in questions):
|
|
401
|
+
raise ValueError("请回答所有问题后提交")
|
|
402
|
+
original = {**original, "answers": {q["question"]: answers[q["question"]] for q in questions}}
|
|
403
|
+
response = {"behavior": "allow", "updatedInput": original}
|
|
404
|
+
respond(request["id"], response)
|
|
405
|
+
pending.pop(command["requestId"], None)
|
|
406
|
+
event("permission", text=f'{request["tool"]}: ' + ("允许这次" if command["decision"] == "allow" else "已拒绝"))
|
|
407
|
+
state["status"] = "waiting_permission" if pending else "running"
|
|
408
|
+
elif action == "stop":
|
|
409
|
+
stopping = time.monotonic()
|
|
410
|
+
if queue: event("permission", text=f"已取消 {len(queue)} 条尚未执行的追加消息")
|
|
411
|
+
queue.clear()
|
|
412
|
+
for request in list(pending.values()): respond(request["id"], {"behavior": "deny", "message": "用户已停止", "interrupt": True})
|
|
413
|
+
pending.clear()
|
|
414
|
+
send({"type": "control_request", "request_id": "scope-stop", "request": {"subtype": "interrupt"}})
|
|
415
|
+
state["status"] = "stopping"
|
|
416
|
+
state["controlResults"].append({"id": command["id"], "status": "accepted"})
|
|
417
|
+
except (KeyError, ValueError) as error:
|
|
418
|
+
state["controlResults"].append({"id": command.get("id"), "status": "rejected", "error": str(error)})
|
|
419
|
+
if finished and not stopping and not closing and not pending and not inflight and session_state in (None, "idle"):
|
|
420
|
+
if queue:
|
|
421
|
+
user(queue.pop(0))
|
|
422
|
+
finished = False
|
|
423
|
+
state["status"] = "running"
|
|
424
|
+
else:
|
|
425
|
+
closing = time.monotonic()
|
|
426
|
+
state["status"] = "finishing"
|
|
427
|
+
child.stdin.close()
|
|
428
|
+
save()
|
|
429
|
+
finally: fcntl.flock(mutex, fcntl.LOCK_UN)
|
|
430
|
+
now = time.monotonic()
|
|
431
|
+
if not initialized and now - started > 30: raise RuntimeError("Claude initialization timed out")
|
|
432
|
+
if stopping:
|
|
433
|
+
elapsed = now - stopping
|
|
434
|
+
stage = 3 if elapsed > 12 else 2 if elapsed > 8 else 1 if elapsed > 2 else 0
|
|
435
|
+
if stage > signal_stage and child.poll() is None:
|
|
436
|
+
os.killpg(child.pid, [None, signal.SIGINT, signal.SIGTERM, signal.SIGKILL][stage])
|
|
437
|
+
signal_stage = stage
|
|
438
|
+
elif closing and now - closing > 15:
|
|
439
|
+
# The completed turn's CLI is owned by this worker only.
|
|
440
|
+
os.killpg(child.pid, signal.SIGTERM)
|
|
441
|
+
child.wait()
|
|
442
|
+
state["status"] = "stopped" if stopping else "failed" if not result_value or result_value.get("is_error") else "completed"
|
|
443
|
+
if state["status"] == "stopped":
|
|
444
|
+
for entry in subagents.values():
|
|
445
|
+
if entry.get("status") == "working": entry["status"] = "stopped"
|
|
446
|
+
elif state["status"] in ("completed", "failed") and not inflight:
|
|
447
|
+
for entry in subagents.values():
|
|
448
|
+
if entry.get("status") == "working":
|
|
449
|
+
entry["status"] = "completed" if state["status"] == "completed" else "failed"
|
|
450
|
+
if state["status"] == "failed" and not state.get("error"):
|
|
451
|
+
state["error"] = (root / "claude-stderr").read_text(errors="replace")[-2000:] or "Claude exited without a result"
|
|
452
|
+
except Exception as error:
|
|
453
|
+
state["status"] = "failed"
|
|
454
|
+
state["error"] = str(error)
|
|
455
|
+
finally:
|
|
456
|
+
if child and child.poll() is None:
|
|
457
|
+
os.killpg(child.pid, signal.SIGTERM)
|
|
458
|
+
try: child.wait(timeout=3)
|
|
459
|
+
except subprocess.TimeoutExpired:
|
|
460
|
+
os.killpg(child.pid, signal.SIGKILL)
|
|
461
|
+
child.wait()
|
|
462
|
+
pending.clear()
|
|
463
|
+
save()
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
export const shellQuote = (value) =>
|
|
2
|
+
`'${String(value).replaceAll("'", `'"'"'`)}'`;
|
|
3
|
+
|
|
4
|
+
export function cliCommand(task, provider) {
|
|
5
|
+
const executable = shellQuote(provider.executable);
|
|
6
|
+
const setup = String(provider?.preLaunchCommand || "").trim();
|
|
7
|
+
let command;
|
|
8
|
+
if (task.provider === "claude") {
|
|
9
|
+
command = [
|
|
10
|
+
executable,
|
|
11
|
+
"-p",
|
|
12
|
+
shellQuote(task.prompt),
|
|
13
|
+
"--output-format json",
|
|
14
|
+
`--permission-mode ${shellQuote(task.permissionMode === "workspace" ? "acceptEdits" : task.permissionMode || "auto")}`,
|
|
15
|
+
task.effort ? `--effort ${shellQuote(task.effort)}` : "",
|
|
16
|
+
"--max-turns 30",
|
|
17
|
+
provider.model ? `--model ${shellQuote(provider.model)}` : "",
|
|
18
|
+
task.resumeSessionId
|
|
19
|
+
? `--resume ${shellQuote(task.resumeSessionId)}`
|
|
20
|
+
: "",
|
|
21
|
+
]
|
|
22
|
+
.filter(Boolean)
|
|
23
|
+
.join(" ");
|
|
24
|
+
} else if (task.provider === "antigravity") {
|
|
25
|
+
command = [executable, "-p", shellQuote(task.prompt), "--output-format json",
|
|
26
|
+
task.effort ? `--effort ${shellQuote(task.effort)}` : "",
|
|
27
|
+
task.permissionMode === "auto" ? "--mode auto --sandbox" : task.permissionMode === "plan" ? "--mode plan" : "",
|
|
28
|
+
task.permissionMode === "full" ? "--dangerously-skip-permissions" : "",
|
|
29
|
+
task.permissionMode === "workspace" ? `--mode accept-edits --sandbox --settings ${shellQuote(JSON.stringify({ toolPermission: "proceed-in-sandbox", allowNonWorkspaceAccess: false, artifactReviewPolicy: "always-proceed" }))}` : "",
|
|
30
|
+
provider.model ? `--model ${shellQuote(provider.model)}` : "",
|
|
31
|
+
task.resumeSessionId ? `--conversation ${shellQuote(task.resumeSessionId)}` : "",
|
|
32
|
+
].filter(Boolean).join(" ");
|
|
33
|
+
} else if (task.provider === "dsh") {
|
|
34
|
+
command = `${executable} --profile headless ${shellQuote(task.prompt)}`;
|
|
35
|
+
} else throw new Error("此 Agent 不使用 CLI 传输");
|
|
36
|
+
// Interactive bash loads the same function/alias setup as a remote terminal.
|
|
37
|
+
// Explicit status check prevents a failed proxy hook from launching the agent.
|
|
38
|
+
const bootstrap = setup
|
|
39
|
+
? `${setup}\nscope_proxy_status=$?\nif [ "$scope_proxy_status" -ne 0 ]; then exit "$scope_proxy_status"; fi\n`
|
|
40
|
+
: "";
|
|
41
|
+
return `${bootstrap}cd -- ${shellQuote(task.cwd)} || exit 72\n${task.gpuIndices?.length ? `export CUDA_VISIBLE_DEVICES=${shellQuote(task.gpuIndices.join(","))}\n` : ""}exec ${command}`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function parseCliResult(provider, result) {
|
|
45
|
+
if (result.status === "failed" && provider === "dsh")
|
|
46
|
+
return {
|
|
47
|
+
...result,
|
|
48
|
+
text: result.stdout || "",
|
|
49
|
+
error:
|
|
50
|
+
result.error ||
|
|
51
|
+
`远端命令退出(${result.code ?? "未知退出码"}),请查看执行日志`,
|
|
52
|
+
};
|
|
53
|
+
if (!["completed", "failed"].includes(result.status)) return result;
|
|
54
|
+
if (provider === "dsh")
|
|
55
|
+
return { ...result, text: result.stdout || "任务已结束,没有文本输出。" };
|
|
56
|
+
const lines = (result.stdout || "").trim().split("\n");
|
|
57
|
+
let value;
|
|
58
|
+
for (let index = lines.length - 1; index >= 0; index--) {
|
|
59
|
+
try {
|
|
60
|
+
const candidate = JSON.parse(lines[index]);
|
|
61
|
+
if (provider === "antigravity"
|
|
62
|
+
? ["SUCCESS", "ERROR"].includes(candidate.status)
|
|
63
|
+
: candidate.type === "result") {
|
|
64
|
+
value = candidate;
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
} catch {
|
|
68
|
+
/* shell startup can print banners */
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (!value)
|
|
72
|
+
return {
|
|
73
|
+
...result,
|
|
74
|
+
status: "failed",
|
|
75
|
+
error: result.error || (result.status === "failed"
|
|
76
|
+
? `远端命令退出(${result.code ?? "未知退出码"}),请查看执行日志`
|
|
77
|
+
: `${provider} 没有返回有效结果 JSON;请检查远端输出`),
|
|
78
|
+
text: result.stdout,
|
|
79
|
+
};
|
|
80
|
+
if (provider === "antigravity" && /auto is not available|continuing in the default mode/i.test(result.stderr || "")) return {
|
|
81
|
+
...result, status: "failed", text: value.response || "", sessionId: value.conversation_id || null,
|
|
82
|
+
errorCode: "permission_mode_unavailable",
|
|
83
|
+
error: "AGY 未按所选 auto 权限执行:当前账号不支持,CLI 已退回默认权限。本轮可能已执行部分操作,请核对结果;选择可用权限后再继续。",
|
|
84
|
+
};
|
|
85
|
+
if (provider === "antigravity") return {
|
|
86
|
+
...result,
|
|
87
|
+
status: value.status === "SUCCESS" && result.status !== "failed" && !value.denied_actions?.length ? "completed" : "failed",
|
|
88
|
+
error: value.denied_actions?.length ? `部分操作需要权限,尚未执行:${value.denied_actions.map((action) => action.display_name || action.action).join("、")}。可调整下一轮权限后继续;网页当前不支持交互审批。` : value.error || (result.status === "failed" ? `Antigravity 退出(${result.code ?? "未知"})` : value.status === "SUCCESS" ? null : "Antigravity 执行失败"),
|
|
89
|
+
text: value.response || "",
|
|
90
|
+
errorCode: value.denied_actions?.length ? "permission_required" : null,
|
|
91
|
+
sessionId: value.conversation_id || null,
|
|
92
|
+
};
|
|
93
|
+
return {
|
|
94
|
+
...result,
|
|
95
|
+
status: value.is_error || result.status === "failed" || value.permission_denials?.length ? "failed" : "completed",
|
|
96
|
+
error: value.permission_denials?.length ? "Claude 的部分操作需要权限,尚未执行;可选择工作区权限继续,或在原终端审批。" : value.is_error
|
|
97
|
+
? value.result || value.errors?.join("\n") || "Claude 执行失败"
|
|
98
|
+
: result.status === "failed" ? `Claude 退出(${result.code ?? "未知"})` : null,
|
|
99
|
+
text: value.result || "",
|
|
100
|
+
errorCode: value.permission_denials?.length ? "permission_required" : null,
|
|
101
|
+
sessionId: value.session_id || null,
|
|
102
|
+
};
|
|
103
|
+
}
|