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,616 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { access, mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import nodemailer from "nodemailer";
|
|
6
|
+
|
|
7
|
+
const DEFAULT_COOLDOWN_MS = 15 * 60_000;
|
|
8
|
+
const DEFAULT_SECRET_FILE = "email-smtp-secret.json";
|
|
9
|
+
|
|
10
|
+
function clean(value, limit = 4_000) {
|
|
11
|
+
return String(value ?? "")
|
|
12
|
+
.replace(/\u0000/g, "")
|
|
13
|
+
.trim()
|
|
14
|
+
.slice(0, limit);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function htmlEscape(value) {
|
|
18
|
+
return clean(value, 20_000)
|
|
19
|
+
.replaceAll("&", "&")
|
|
20
|
+
.replaceAll("<", "<")
|
|
21
|
+
.replaceAll(">", ">")
|
|
22
|
+
.replaceAll('"', """)
|
|
23
|
+
.replaceAll("'", "'");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function validEmail(value) {
|
|
27
|
+
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(clean(value, 320));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function fingerprint(event) {
|
|
31
|
+
return createHash("sha256")
|
|
32
|
+
.update(
|
|
33
|
+
JSON.stringify({
|
|
34
|
+
key: event.key,
|
|
35
|
+
severity: event.severity,
|
|
36
|
+
title: event.title,
|
|
37
|
+
summary: event.summary,
|
|
38
|
+
details: event.details,
|
|
39
|
+
}),
|
|
40
|
+
)
|
|
41
|
+
.digest("hex");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async function readJson(filename, fallback) {
|
|
45
|
+
try {
|
|
46
|
+
const content = await readFile(filename, "utf8");
|
|
47
|
+
return JSON.parse(content.replace(/^\uFEFF/, ""));
|
|
48
|
+
} catch (error) {
|
|
49
|
+
if (error?.code !== "ENOENT") {
|
|
50
|
+
console.error(`无法读取 ${filename}: ${error.message}`);
|
|
51
|
+
}
|
|
52
|
+
return fallback;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async function writeJsonAtomic(filename, value, mode = 0o600) {
|
|
57
|
+
await mkdir(path.dirname(filename), { recursive: true });
|
|
58
|
+
const temporary = `${filename}.tmp`;
|
|
59
|
+
await writeFile(temporary, `${JSON.stringify(value, null, 2)}\n`, {
|
|
60
|
+
encoding: "utf8",
|
|
61
|
+
mode,
|
|
62
|
+
});
|
|
63
|
+
await rename(temporary, filename);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function runProcess(command, args, timeoutMs = 15_000) {
|
|
67
|
+
return new Promise((resolve, reject) => {
|
|
68
|
+
const child = spawn(command, args, {
|
|
69
|
+
windowsHide: true,
|
|
70
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
71
|
+
});
|
|
72
|
+
let stdout = "";
|
|
73
|
+
let stderr = "";
|
|
74
|
+
const timer = setTimeout(() => {
|
|
75
|
+
child.kill("SIGTERM");
|
|
76
|
+
reject(new Error("读取邮件凭据超时"));
|
|
77
|
+
}, timeoutMs);
|
|
78
|
+
child.stdout.setEncoding("utf8");
|
|
79
|
+
child.stderr.setEncoding("utf8");
|
|
80
|
+
child.stdout.on("data", (chunk) => {
|
|
81
|
+
stdout = `${stdout}${chunk}`.slice(-20_000);
|
|
82
|
+
});
|
|
83
|
+
child.stderr.on("data", (chunk) => {
|
|
84
|
+
stderr = `${stderr}${chunk}`.slice(-20_000);
|
|
85
|
+
});
|
|
86
|
+
child.once("error", (error) => {
|
|
87
|
+
clearTimeout(timer);
|
|
88
|
+
reject(error);
|
|
89
|
+
});
|
|
90
|
+
child.once("exit", (code) => {
|
|
91
|
+
clearTimeout(timer);
|
|
92
|
+
if (code === 0) resolve(stdout.trim());
|
|
93
|
+
else reject(new Error(clean(stderr || stdout, 1_000) || `退出码 ${code}`));
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function resolveSecretPath(config, configDirectory) {
|
|
99
|
+
const secretFile = clean(config?.smtp?.secretFile || DEFAULT_SECRET_FILE, 300);
|
|
100
|
+
const resolved = path.resolve(configDirectory, secretFile);
|
|
101
|
+
const base = path.resolve(configDirectory);
|
|
102
|
+
if (resolved !== base && !resolved.startsWith(`${base}${path.sep}`)) {
|
|
103
|
+
throw new Error("SMTP secret path escapes configuration directory");
|
|
104
|
+
}
|
|
105
|
+
return resolved;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async function loadCredential(config, configDirectory, environment) {
|
|
109
|
+
const environmentUser = clean(environment.SCOPE_EMAIL_SMTP_USER, 320);
|
|
110
|
+
const environmentPass = clean(environment.SCOPE_EMAIL_SMTP_PASS, 1_000);
|
|
111
|
+
if (environmentUser && environmentPass) {
|
|
112
|
+
return { user: environmentUser, pass: environmentPass, source: "environment" };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const secretPath = resolveSecretPath(config, configDirectory);
|
|
116
|
+
const localSecret = await readJson(secretPath, null);
|
|
117
|
+
const secretUser = clean(localSecret?.user, 320);
|
|
118
|
+
const secretPass = clean(localSecret?.pass, 1_000);
|
|
119
|
+
if (secretUser && secretPass) {
|
|
120
|
+
return { user: secretUser, pass: secretPass, source: "local-secret" };
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const credentialFile = clean(config?.smtp?.credentialFile, 1_000);
|
|
124
|
+
if (!credentialFile || process.platform !== "win32") return null;
|
|
125
|
+
const resolved = path.resolve(configDirectory, credentialFile);
|
|
126
|
+
try {
|
|
127
|
+
await access(resolved);
|
|
128
|
+
} catch {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
const credentialLiteral = resolved.replaceAll("'", "''");
|
|
132
|
+
const script = [
|
|
133
|
+
"$ErrorActionPreference='Stop'",
|
|
134
|
+
`$credential=Import-Clixml -LiteralPath '${credentialLiteral}'`,
|
|
135
|
+
"$network=$credential.GetNetworkCredential()",
|
|
136
|
+
"[Console]::Out.Write((@{user=$credential.UserName;pass=$network.Password}|ConvertTo-Json -Compress))",
|
|
137
|
+
].join("; ");
|
|
138
|
+
const output = await runProcess(
|
|
139
|
+
"powershell.exe",
|
|
140
|
+
["-NoProfile", "-NonInteractive", "-Command", script],
|
|
141
|
+
);
|
|
142
|
+
const parsed = JSON.parse(output);
|
|
143
|
+
const user = clean(parsed.user, 320);
|
|
144
|
+
const pass = clean(parsed.pass, 1_000);
|
|
145
|
+
return user && pass ? { user, pass, source: "windows-dpapi" } : null;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function normalizeRecipients(value) {
|
|
149
|
+
const values = Array.isArray(value)
|
|
150
|
+
? value
|
|
151
|
+
: String(value ?? "").split(/[\n,;]+/);
|
|
152
|
+
return [...new Set(values.map((item) => clean(item, 320)).filter(validEmail))];
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function normalizeTriggers(value) {
|
|
156
|
+
return {
|
|
157
|
+
humanRequests: value?.humanRequests !== false,
|
|
158
|
+
agentCompletion: value?.agentCompletion !== false,
|
|
159
|
+
dlcAlerts: value?.dlcAlerts !== false,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function renderMessage(event, config) {
|
|
164
|
+
const severity = clean(event.severity || "important", 40).toUpperCase();
|
|
165
|
+
const title = clean(event.title || "SCOPE notification", 240);
|
|
166
|
+
const summary = clean(event.summary, 8_000);
|
|
167
|
+
const details = Array.isArray(event.details)
|
|
168
|
+
? event.details
|
|
169
|
+
.slice(0, 30)
|
|
170
|
+
.map((detail) => clean(detail, 2_000))
|
|
171
|
+
.filter(Boolean)
|
|
172
|
+
: [];
|
|
173
|
+
const monitorUrl = clean(config?.monitorUrl || "http://localhost:3000/", 2_000);
|
|
174
|
+
const timestamp = new Date(event.timestamp || Date.now()).toISOString();
|
|
175
|
+
const subject = `[SCOPE][${severity}] ${title}`.slice(0, 300);
|
|
176
|
+
const text = [
|
|
177
|
+
title,
|
|
178
|
+
"",
|
|
179
|
+
summary,
|
|
180
|
+
...(details.length ? ["", ...details.map((detail) => `- ${detail}`)] : []),
|
|
181
|
+
"",
|
|
182
|
+
`Time: ${timestamp}`,
|
|
183
|
+
`Monitor: ${monitorUrl}`,
|
|
184
|
+
].join("\n");
|
|
185
|
+
const html = [
|
|
186
|
+
'<div style="font-family:system-ui,-apple-system,Segoe UI,sans-serif;color:#172033;line-height:1.55">',
|
|
187
|
+
`<h2 style="margin:0 0 12px">${htmlEscape(title)}</h2>`,
|
|
188
|
+
`<p style="white-space:pre-wrap">${htmlEscape(summary)}</p>`,
|
|
189
|
+
...(details.length
|
|
190
|
+
? [
|
|
191
|
+
"<ul>",
|
|
192
|
+
...details.map((detail) => `<li>${htmlEscape(detail)}</li>`),
|
|
193
|
+
"</ul>",
|
|
194
|
+
]
|
|
195
|
+
: []),
|
|
196
|
+
`<p style="color:#667085;font-size:12px">Time: ${htmlEscape(timestamp)}</p>`,
|
|
197
|
+
`<p><a href="${htmlEscape(monitorUrl)}">Open SCOPE monitor</a></p>`,
|
|
198
|
+
"</div>",
|
|
199
|
+
].join("");
|
|
200
|
+
return { subject, text, html };
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export class EmailNotifier {
|
|
204
|
+
constructor({
|
|
205
|
+
configPath,
|
|
206
|
+
statePath,
|
|
207
|
+
environment = process.env,
|
|
208
|
+
now = () => Date.now(),
|
|
209
|
+
transportFactory = (options) => nodemailer.createTransport(options),
|
|
210
|
+
}) {
|
|
211
|
+
this.configPath = configPath;
|
|
212
|
+
this.statePath = statePath;
|
|
213
|
+
this.environment = environment;
|
|
214
|
+
this.now = now;
|
|
215
|
+
this.transportFactory = transportFactory;
|
|
216
|
+
this.config = null;
|
|
217
|
+
this.state = { version: 1, events: {}, lastSentAt: null };
|
|
218
|
+
this.transport = null;
|
|
219
|
+
this.credentialSource = null;
|
|
220
|
+
this.credentialUser = "";
|
|
221
|
+
this.hasPassword = false;
|
|
222
|
+
this.lastError = null;
|
|
223
|
+
this.queue = Promise.resolve();
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
async initialize() {
|
|
227
|
+
this.transport?.close?.();
|
|
228
|
+
this.transport = null;
|
|
229
|
+
this.credentialSource = null;
|
|
230
|
+
this.credentialUser = "";
|
|
231
|
+
this.hasPassword = false;
|
|
232
|
+
this.lastError = null;
|
|
233
|
+
this.config = await readJson(this.configPath, null);
|
|
234
|
+
this.state = await readJson(this.statePath, this.state);
|
|
235
|
+
|
|
236
|
+
let credential = null;
|
|
237
|
+
let credentialError = null;
|
|
238
|
+
try {
|
|
239
|
+
credential = await loadCredential(
|
|
240
|
+
this.config,
|
|
241
|
+
path.dirname(this.configPath),
|
|
242
|
+
this.environment,
|
|
243
|
+
);
|
|
244
|
+
} catch (error) {
|
|
245
|
+
credentialError = error;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if (credential) {
|
|
249
|
+
this.credentialSource = credential.source;
|
|
250
|
+
this.credentialUser = credential.user;
|
|
251
|
+
this.hasPassword = Boolean(credential.pass);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
if (!this.config?.enabled) {
|
|
255
|
+
return this;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
const recipients = normalizeRecipients(this.config.to);
|
|
259
|
+
if (!recipients.length) {
|
|
260
|
+
this.lastError = "邮件收件地址无效";
|
|
261
|
+
return this;
|
|
262
|
+
}
|
|
263
|
+
const smtpHost = clean(this.config.smtp?.host, 320);
|
|
264
|
+
if (!smtpHost) {
|
|
265
|
+
this.lastError = "尚未配置 SMTP 服务器地址";
|
|
266
|
+
return this;
|
|
267
|
+
}
|
|
268
|
+
if (credentialError) {
|
|
269
|
+
this.lastError = `SMTP 凭据不可用:${clean(credentialError.message, 600)}`;
|
|
270
|
+
return this;
|
|
271
|
+
}
|
|
272
|
+
if (!credential) {
|
|
273
|
+
this.lastError = "尚未配置 SMTP 凭据";
|
|
274
|
+
return this;
|
|
275
|
+
}
|
|
276
|
+
try {
|
|
277
|
+
const port = Number(this.config.smtp?.port) || 465;
|
|
278
|
+
this.transport = this.transportFactory({
|
|
279
|
+
host: smtpHost,
|
|
280
|
+
port,
|
|
281
|
+
secure:
|
|
282
|
+
typeof this.config.smtp?.secure === "boolean"
|
|
283
|
+
? this.config.smtp.secure
|
|
284
|
+
: port === 465,
|
|
285
|
+
requireTLS: port !== 465,
|
|
286
|
+
auth: { user: credential.user, pass: credential.pass },
|
|
287
|
+
connectionTimeout: 15_000,
|
|
288
|
+
greetingTimeout: 15_000,
|
|
289
|
+
socketTimeout: 30_000,
|
|
290
|
+
disableFileAccess: true,
|
|
291
|
+
disableUrlAccess: true,
|
|
292
|
+
});
|
|
293
|
+
} catch (error) {
|
|
294
|
+
this.lastError = `SMTP 初始化失败:${clean(error.message, 600)}`;
|
|
295
|
+
}
|
|
296
|
+
return this;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
publicState() {
|
|
300
|
+
return {
|
|
301
|
+
enabled: Boolean(this.config?.enabled),
|
|
302
|
+
configured: Boolean(this.transport),
|
|
303
|
+
to: normalizeRecipients(this.config?.to),
|
|
304
|
+
provider: clean(this.config?.smtp?.host || "", 320),
|
|
305
|
+
credentialSource: this.credentialSource,
|
|
306
|
+
lastSentAt: this.state.lastSentAt || null,
|
|
307
|
+
lastError: this.lastError,
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
configView() {
|
|
312
|
+
const port = Number(this.config?.smtp?.port) || 465;
|
|
313
|
+
return {
|
|
314
|
+
enabled: Boolean(this.config?.enabled),
|
|
315
|
+
configured: Boolean(this.transport),
|
|
316
|
+
to: normalizeRecipients(this.config?.to),
|
|
317
|
+
from: clean(this.config?.from, 500),
|
|
318
|
+
monitorUrl: clean(this.config?.monitorUrl || "http://localhost:3000/", 2_000),
|
|
319
|
+
cooldownMinutes: Number.isFinite(Number(this.config?.cooldownMinutes))
|
|
320
|
+
? Number(this.config.cooldownMinutes)
|
|
321
|
+
: 15,
|
|
322
|
+
triggers: normalizeTriggers(this.config?.triggers),
|
|
323
|
+
smtp: {
|
|
324
|
+
host: clean(this.config?.smtp?.host, 320),
|
|
325
|
+
port,
|
|
326
|
+
secure:
|
|
327
|
+
typeof this.config?.smtp?.secure === "boolean"
|
|
328
|
+
? this.config.smtp.secure
|
|
329
|
+
: port === 465,
|
|
330
|
+
},
|
|
331
|
+
smtpUser: this.credentialUser || "",
|
|
332
|
+
hasPassword: Boolean(this.hasPassword),
|
|
333
|
+
credentialSource: this.credentialSource,
|
|
334
|
+
lastSentAt: this.state.lastSentAt || null,
|
|
335
|
+
lastError: this.lastError,
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
async saveConfig(input) {
|
|
340
|
+
if (!input || typeof input !== "object" || Array.isArray(input)) {
|
|
341
|
+
throw new Error("配置必须是对象");
|
|
342
|
+
}
|
|
343
|
+
const enabled = Boolean(input.enabled);
|
|
344
|
+
const recipients = normalizeRecipients(input.to);
|
|
345
|
+
if (enabled && !recipients.length) {
|
|
346
|
+
throw new Error("请填写至少一个有效的收件邮箱");
|
|
347
|
+
}
|
|
348
|
+
const smtpHost = clean(input.smtp?.host, 320);
|
|
349
|
+
if (enabled && !smtpHost) {
|
|
350
|
+
throw new Error("请填写 SMTP 服务器地址");
|
|
351
|
+
}
|
|
352
|
+
if (smtpHost && !/^[a-zA-Z0-9._-]+$/.test(smtpHost)) {
|
|
353
|
+
throw new Error("SMTP 服务器地址格式无效");
|
|
354
|
+
}
|
|
355
|
+
const port = input.smtp?.port === undefined || input.smtp?.port === ""
|
|
356
|
+
? 465
|
|
357
|
+
: Number(input.smtp.port);
|
|
358
|
+
if (!Number.isInteger(port) || port < 1 || port > 65_535) {
|
|
359
|
+
throw new Error("SMTP 端口必须是 1 到 65535 的整数");
|
|
360
|
+
}
|
|
361
|
+
const secure = typeof input.smtp?.secure === "boolean"
|
|
362
|
+
? input.smtp.secure
|
|
363
|
+
: port === 465;
|
|
364
|
+
const cooldownRaw = input.cooldownMinutes === undefined || input.cooldownMinutes === ""
|
|
365
|
+
? 15
|
|
366
|
+
: Number(input.cooldownMinutes);
|
|
367
|
+
if (!Number.isFinite(cooldownRaw) || cooldownRaw < 0 || cooldownRaw > 1440) {
|
|
368
|
+
throw new Error("冷却时间必须在 0 到 1440 分钟之间");
|
|
369
|
+
}
|
|
370
|
+
const monitorUrl = clean(input.monitorUrl || "http://localhost:3000/", 2_000);
|
|
371
|
+
if (monitorUrl && !/^https?:\/\//i.test(monitorUrl)) {
|
|
372
|
+
throw new Error("监控访问地址必须以 http:// 或 https:// 开头");
|
|
373
|
+
}
|
|
374
|
+
const from = clean(input.from, 500);
|
|
375
|
+
if (/[\r\n]/.test(from)) {
|
|
376
|
+
throw new Error("发件人格式无效");
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
const configDirectory = path.dirname(this.configPath);
|
|
380
|
+
const secretPath = resolveSecretPath(this.config, configDirectory);
|
|
381
|
+
if (input.clearCredentials === true) {
|
|
382
|
+
await rm(secretPath, { force: true }).catch(() => {});
|
|
383
|
+
} else {
|
|
384
|
+
const incomingUser = input.smtpUser !== undefined ? clean(input.smtpUser, 320) : undefined;
|
|
385
|
+
const incomingPass = input.smtpPass !== undefined ? clean(input.smtpPass, 1_000) : undefined;
|
|
386
|
+
if (incomingUser !== undefined || (incomingPass !== undefined && incomingPass !== "")) {
|
|
387
|
+
const existingSecret = await readJson(secretPath, null);
|
|
388
|
+
const nextUser = incomingUser !== undefined ? incomingUser : clean(existingSecret?.user || this.credentialUser, 320);
|
|
389
|
+
const nextPass = incomingPass !== undefined && incomingPass !== ""
|
|
390
|
+
? incomingPass
|
|
391
|
+
: clean(existingSecret?.pass, 1_000);
|
|
392
|
+
if (nextUser && nextPass) {
|
|
393
|
+
await writeJsonAtomic(
|
|
394
|
+
secretPath,
|
|
395
|
+
{
|
|
396
|
+
user: nextUser,
|
|
397
|
+
pass: nextPass,
|
|
398
|
+
updatedAt: new Date(this.now()).toISOString(),
|
|
399
|
+
},
|
|
400
|
+
0o600,
|
|
401
|
+
);
|
|
402
|
+
} else if (incomingPass) {
|
|
403
|
+
throw new Error("请同时填写 SMTP 登录账号与授权码");
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
const previousCredentialFile = input.clearCredentials === true
|
|
409
|
+
? undefined
|
|
410
|
+
: clean(this.config?.smtp?.credentialFile, 1_000) || undefined;
|
|
411
|
+
const nextConfig = {
|
|
412
|
+
enabled,
|
|
413
|
+
to: recipients,
|
|
414
|
+
from,
|
|
415
|
+
monitorUrl,
|
|
416
|
+
cooldownMinutes: Math.round(cooldownRaw),
|
|
417
|
+
triggers: normalizeTriggers(input.triggers),
|
|
418
|
+
smtp: {
|
|
419
|
+
host: smtpHost,
|
|
420
|
+
port,
|
|
421
|
+
secure,
|
|
422
|
+
secretFile: DEFAULT_SECRET_FILE,
|
|
423
|
+
...(previousCredentialFile ? { credentialFile: previousCredentialFile } : {}),
|
|
424
|
+
},
|
|
425
|
+
};
|
|
426
|
+
await writeJsonAtomic(this.configPath, nextConfig, 0o600);
|
|
427
|
+
await this.initialize();
|
|
428
|
+
if (enabled && !this.transport) {
|
|
429
|
+
throw new Error(this.lastError || "邮件配置已保存,但 SMTP 凭据尚未完整配置");
|
|
430
|
+
}
|
|
431
|
+
return this.configView();
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
async verify() {
|
|
435
|
+
if (!this.transport) throw new Error(this.lastError || "邮件通知尚未配置");
|
|
436
|
+
await this.transport.verify();
|
|
437
|
+
this.lastError = null;
|
|
438
|
+
return this.publicState();
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
async sendTest() {
|
|
442
|
+
if (!this.transport) {
|
|
443
|
+
await this.initialize();
|
|
444
|
+
}
|
|
445
|
+
if (!this.transport) {
|
|
446
|
+
throw new Error(this.lastError || "请先配置并启用 SMTP 与收件邮箱");
|
|
447
|
+
}
|
|
448
|
+
const recipients = normalizeRecipients(this.config?.to);
|
|
449
|
+
if (!recipients.length) {
|
|
450
|
+
throw new Error("邮件收件地址无效");
|
|
451
|
+
}
|
|
452
|
+
const message = renderMessage(
|
|
453
|
+
{
|
|
454
|
+
severity: "test",
|
|
455
|
+
title: "SCOPE notification channel verified",
|
|
456
|
+
summary: "This is a test notification sent from SCOPE settings. Your SMTP configuration is active.",
|
|
457
|
+
details: [
|
|
458
|
+
`SMTP Host: ${clean(this.config?.smtp?.host, 320)}:${Number(this.config?.smtp?.port) || 465}`,
|
|
459
|
+
`Recipients: ${recipients.join(", ")}`,
|
|
460
|
+
],
|
|
461
|
+
timestamp: new Date(this.now()).toISOString(),
|
|
462
|
+
},
|
|
463
|
+
this.config,
|
|
464
|
+
);
|
|
465
|
+
const from =
|
|
466
|
+
clean(this.config?.from, 500) ||
|
|
467
|
+
clean(this.credentialUser, 320) ||
|
|
468
|
+
clean(this.environment.SCOPE_EMAIL_SMTP_USER, 320) ||
|
|
469
|
+
recipients[0];
|
|
470
|
+
const result = await this.transport.sendMail({
|
|
471
|
+
from,
|
|
472
|
+
to: recipients,
|
|
473
|
+
...message,
|
|
474
|
+
});
|
|
475
|
+
const sentAt = new Date(this.now()).toISOString();
|
|
476
|
+
this.state.lastSentAt = sentAt;
|
|
477
|
+
this.lastError = null;
|
|
478
|
+
await writeJsonAtomic(this.statePath, this.state);
|
|
479
|
+
return { sent: true, messageId: result?.messageId || null };
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
#eventTriggerEnabled(event) {
|
|
483
|
+
const triggers = normalizeTriggers(this.config?.triggers);
|
|
484
|
+
if (event.key.startsWith("human-request:")) return triggers.humanRequests;
|
|
485
|
+
if (event.key.startsWith("agent-completion:")) return triggers.agentCompletion;
|
|
486
|
+
if (event.key.startsWith("dlc-alert:")) return triggers.dlcAlerts;
|
|
487
|
+
return true;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
async prime(events) {
|
|
491
|
+
const primedAt = new Date(this.now()).toISOString();
|
|
492
|
+
for (const event of events) {
|
|
493
|
+
if (!event?.key) continue;
|
|
494
|
+
this.state.events[event.key] = {
|
|
495
|
+
fingerprint: fingerprint(event),
|
|
496
|
+
primedAt,
|
|
497
|
+
sentAt: this.state.events[event.key]?.sentAt || null,
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
await writeJsonAtomic(this.statePath, this.state);
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
notify(event) {
|
|
504
|
+
this.queue = this.queue
|
|
505
|
+
.catch(() => {})
|
|
506
|
+
.then(() => this.#notify(event));
|
|
507
|
+
return this.queue;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
async #notify(event) {
|
|
511
|
+
if (!event?.key || !event?.title) {
|
|
512
|
+
return { sent: false, reason: "invalid-event" };
|
|
513
|
+
}
|
|
514
|
+
if (!this.#eventTriggerEnabled(event)) {
|
|
515
|
+
return { sent: false, reason: "trigger-disabled" };
|
|
516
|
+
}
|
|
517
|
+
const eventFingerprint = fingerprint(event);
|
|
518
|
+
const previous = this.state.events[event.key];
|
|
519
|
+
if (previous?.fingerprint === eventFingerprint) {
|
|
520
|
+
return { sent: false, reason: "duplicate" };
|
|
521
|
+
}
|
|
522
|
+
if (!this.transport) {
|
|
523
|
+
return { sent: false, reason: this.lastError || "not-configured" };
|
|
524
|
+
}
|
|
525
|
+
const cooldownMs = Math.max(
|
|
526
|
+
0,
|
|
527
|
+
Number(this.config.cooldownMinutes) * 60_000 || DEFAULT_COOLDOWN_MS,
|
|
528
|
+
);
|
|
529
|
+
if (
|
|
530
|
+
previous?.attemptedAt &&
|
|
531
|
+
this.now() - Date.parse(previous.attemptedAt) < cooldownMs
|
|
532
|
+
) {
|
|
533
|
+
return { sent: false, reason: "cooldown" };
|
|
534
|
+
}
|
|
535
|
+
const attemptedAt = new Date(this.now()).toISOString();
|
|
536
|
+
this.state.events[event.key] = {
|
|
537
|
+
...previous,
|
|
538
|
+
attemptedAt,
|
|
539
|
+
pendingFingerprint: eventFingerprint,
|
|
540
|
+
};
|
|
541
|
+
await writeJsonAtomic(this.statePath, this.state);
|
|
542
|
+
try {
|
|
543
|
+
const message = renderMessage(event, this.config);
|
|
544
|
+
const recipients = normalizeRecipients(this.config.to);
|
|
545
|
+
const from =
|
|
546
|
+
clean(this.config.from, 500) ||
|
|
547
|
+
clean(this.credentialUser, 320) ||
|
|
548
|
+
clean(this.environment.SCOPE_EMAIL_SMTP_USER, 320) ||
|
|
549
|
+
recipients[0];
|
|
550
|
+
const result = await this.transport.sendMail({
|
|
551
|
+
from,
|
|
552
|
+
to: recipients,
|
|
553
|
+
...message,
|
|
554
|
+
});
|
|
555
|
+
const sentAt = new Date(this.now()).toISOString();
|
|
556
|
+
this.state.events[event.key] = {
|
|
557
|
+
fingerprint: eventFingerprint,
|
|
558
|
+
attemptedAt,
|
|
559
|
+
sentAt,
|
|
560
|
+
messageId: clean(result?.messageId, 500) || null,
|
|
561
|
+
};
|
|
562
|
+
this.state.lastSentAt = sentAt;
|
|
563
|
+
this.lastError = null;
|
|
564
|
+
await writeJsonAtomic(this.statePath, this.state);
|
|
565
|
+
return { sent: true, messageId: result?.messageId || null };
|
|
566
|
+
} catch (error) {
|
|
567
|
+
this.lastError = `邮件发送失败:${clean(error.message, 600)}`;
|
|
568
|
+
await writeJsonAtomic(this.statePath, this.state);
|
|
569
|
+
console.error(this.lastError);
|
|
570
|
+
return { sent: false, reason: this.lastError };
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
export async function createEmailNotifier(options) {
|
|
576
|
+
return new EmailNotifier(options).initialize();
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
export function humanRequestEmailEvent(request) {
|
|
580
|
+
const question = request.questions?.[0];
|
|
581
|
+
const details = [
|
|
582
|
+
`Host: ${clean(request.host, 300)}`,
|
|
583
|
+
`Session: ${clean(request.threadId, 300)}`,
|
|
584
|
+
request.cwd ? `Directory: ${clean(request.cwd, 1_000)}` : "",
|
|
585
|
+
request.reason ? `Reason: ${clean(request.reason, 2_000)}` : "",
|
|
586
|
+
question ? `Question: ${clean(question.question, 2_000)}` : "",
|
|
587
|
+
].filter(Boolean);
|
|
588
|
+
return {
|
|
589
|
+
key: `human-request:${request.key}`,
|
|
590
|
+
severity: request.kind === "user-input" ? "action" : "approval",
|
|
591
|
+
title: request.title || "Codex 等待你的处理",
|
|
592
|
+
summary:
|
|
593
|
+
request.kind === "user-input"
|
|
594
|
+
? "Codex 在 WebUI 中等待你的回答。"
|
|
595
|
+
: "Codex 在 WebUI 中等待你的审批。",
|
|
596
|
+
details,
|
|
597
|
+
timestamp: request.receivedAt,
|
|
598
|
+
};
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
export function dlcAlertEmailEvent(alert, scannedAt) {
|
|
602
|
+
return {
|
|
603
|
+
key: `dlc-alert:${alert.host}:${alert.sessionId}`,
|
|
604
|
+
severity: "critical",
|
|
605
|
+
title: `DLC 高失败告警:${clean(alert.sessionTheme, 180)}`,
|
|
606
|
+
summary:
|
|
607
|
+
`${alert.total} 个关联 Job 中 ${alert.failed} 个失败或终止,` +
|
|
608
|
+
`${alert.queued} 个仍在排队,${alert.running} 个仍在运行。`,
|
|
609
|
+
details: [
|
|
610
|
+
`Host: ${clean(alert.host, 300)}`,
|
|
611
|
+
`Session: ${clean(alert.sessionId, 300)}`,
|
|
612
|
+
`Directory: ${clean(alert.cwd, 1_000)}`,
|
|
613
|
+
],
|
|
614
|
+
timestamp: scannedAt,
|
|
615
|
+
};
|
|
616
|
+
}
|