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.
Files changed (357) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/LICENSE +21 -0
  3. package/README.md +174 -2
  4. package/README.zh-CN.md +175 -0
  5. package/bin/scope.mjs +111 -0
  6. package/bridge/account-quotas.mjs +881 -0
  7. package/bridge/agent-email-relay.mjs +160 -0
  8. package/bridge/app-server-client.mjs +2522 -0
  9. package/bridge/app-server-websocket-transport.mjs +219 -0
  10. package/bridge/archive/routes.mjs +19 -0
  11. package/bridge/archive/service.mjs +130 -0
  12. package/bridge/archive/thread-lifecycle.mjs +52 -0
  13. package/bridge/attachment-store.mjs +184 -0
  14. package/bridge/auth-profile-failover.mjs +58 -0
  15. package/bridge/auth-profile-manager.mjs +215 -0
  16. package/bridge/capacity-recovery.mjs +90 -0
  17. package/bridge/codex-upgrade.mjs +150 -0
  18. package/bridge/deployment-profile.mjs +64 -0
  19. package/bridge/email-notifier.mjs +616 -0
  20. package/bridge/gpu-usage-history.mjs +322 -0
  21. package/bridge/host-session-restart.mjs +35 -0
  22. package/bridge/http.mjs +69 -0
  23. package/bridge/idle-sessions.mjs +185 -0
  24. package/bridge/inventory-scanner.mjs +517 -0
  25. package/bridge/local/dialogue.mjs +150 -0
  26. package/bridge/local/directories.mjs +40 -0
  27. package/bridge/local/executable.mjs +29 -0
  28. package/bridge/local/history.mjs +21 -0
  29. package/bridge/local/python-probe.mjs +35 -0
  30. package/bridge/local/runtime.mjs +188 -0
  31. package/bridge/local/transport.mjs +70 -0
  32. package/bridge/maintenance/install-command.mjs +141 -0
  33. package/bridge/maintenance/routes.mjs +21 -0
  34. package/bridge/maintenance/service.mjs +175 -0
  35. package/bridge/model-catalog.mjs +21 -0
  36. package/bridge/persistent-home-guard.mjs +6 -0
  37. package/bridge/plugins/aliyun-dlc/index.mjs +47 -0
  38. package/bridge/plugins/aliyun-dlc/manifest.mjs +12 -0
  39. package/bridge/plugins/aliyun-dlc/monitor.mjs +236 -0
  40. package/bridge/plugins/aliyun-dlc/probe.mjs +701 -0
  41. package/bridge/plugins/config-store.mjs +35 -0
  42. package/bridge/plugins/external.mjs +87 -0
  43. package/bridge/plugins/package.mjs +96 -0
  44. package/bridge/plugins/registry.mjs +37 -0
  45. package/bridge/plugins/routes.mjs +27 -0
  46. package/bridge/private-gateway.mjs +371 -0
  47. package/bridge/private-start.mjs +22 -0
  48. package/bridge/probes/app-server-handoff-probe.mjs +89 -0
  49. package/bridge/probes/app-server-writer-probe.mjs +72 -0
  50. package/bridge/probes/assistant-search-probe.mjs +323 -0
  51. package/bridge/probes/dialogue-probe.mjs +464 -0
  52. package/bridge/probes/history-probe.mjs +347 -0
  53. package/bridge/probes/index.mjs +15 -0
  54. package/bridge/probes/new-session-preflight.mjs +16 -0
  55. package/bridge/probes/profile-cancel-probe.mjs +19 -0
  56. package/bridge/probes/profile-delete-probe.mjs +28 -0
  57. package/bridge/probes/profile-list-probe.mjs +117 -0
  58. package/bridge/probes/profile-write-probe.mjs +111 -0
  59. package/bridge/probes/raw-context-probe.mjs +53 -0
  60. package/bridge/probes/remote-probe.mjs +636 -0
  61. package/bridge/probes/submission-probe.mjs +2 -0
  62. package/bridge/probes/takeover-probe.mjs +328 -0
  63. package/bridge/probes/vscode-open-preflight.mjs +23 -0
  64. package/bridge/profile-capacity-policy.mjs +14 -0
  65. package/bridge/providers/acp-forms.py +49 -0
  66. package/bridge/providers/antigravity-interactive.mjs +14 -0
  67. package/bridge/providers/antigravity-interactive.py +349 -0
  68. package/bridge/providers/claude-capabilities.py +52 -0
  69. package/bridge/providers/claude-interactive.mjs +14 -0
  70. package/bridge/providers/claude-interactive.py +341 -0
  71. package/bridge/providers/cli-command.mjs +103 -0
  72. package/bridge/providers/codex-workbench.mjs +164 -0
  73. package/bridge/providers/conversation-routes.mjs +28 -0
  74. package/bridge/providers/conversations.mjs +231 -0
  75. package/bridge/providers/native-commands.mjs +48 -0
  76. package/bridge/providers/native-commands.py +38 -0
  77. package/bridge/providers/native-models.mjs +129 -0
  78. package/bridge/providers/native-session-state.mjs +14 -0
  79. package/bridge/providers/native-session-state.py +96 -0
  80. package/bridge/providers/remote-cli.mjs +75 -0
  81. package/bridge/providers/remote-job.py +130 -0
  82. package/bridge/remote-app-server-command.mjs +203 -0
  83. package/bridge/remote-bootstrap/routes.mjs +51 -0
  84. package/bridge/remote-bootstrap/scope-protocol.mjs +125 -0
  85. package/bridge/remote-bootstrap/service.mjs +597 -0
  86. package/bridge/remote-bootstrap/tunnels.mjs +347 -0
  87. package/bridge/remote-directory-listing.mjs +148 -0
  88. package/bridge/remote-images.mjs +140 -0
  89. package/bridge/remote-profile-home.mjs +39 -0
  90. package/bridge/remote-rollout-locks.mjs +31 -0
  91. package/bridge/remote-videos.mjs +129 -0
  92. package/bridge/research/insights.mjs +522 -0
  93. package/bridge/research/scan-host.mjs +18 -0
  94. package/bridge/rollout-summary.mjs +159 -0
  95. package/bridge/routes/accounts.mjs +326 -0
  96. package/bridge/routes/dialogue.mjs +120 -0
  97. package/bridge/routes/email.mjs +50 -0
  98. package/bridge/routes/management.mjs +291 -0
  99. package/bridge/routes/models.mjs +312 -0
  100. package/bridge/routes/runtime.mjs +82 -0
  101. package/bridge/routes/session-commands.mjs +12 -0
  102. package/bridge/routes/session-delivery.mjs +328 -0
  103. package/bridge/routes/session-lifecycle.mjs +839 -0
  104. package/bridge/routes/system.mjs +289 -0
  105. package/bridge/server.mjs +3332 -0
  106. package/bridge/session-attachments.mjs +150 -0
  107. package/bridge/session-cache-archive.mjs +22 -0
  108. package/bridge/session-catalog/agy-history.py +249 -0
  109. package/bridge/session-catalog/catalog.mjs +93 -0
  110. package/bridge/session-catalog/probe.py +331 -0
  111. package/bridge/session-catalog/routes.mjs +28 -0
  112. package/bridge/session-profiles.mjs +115 -0
  113. package/bridge/shared-start.mjs +22 -0
  114. package/bridge/start.mjs +205 -0
  115. package/bridge/state-persistence.mjs +397 -0
  116. package/bridge/submissions/settings.mjs +50 -0
  117. package/bridge/terminal-gateway.mjs +171 -0
  118. package/bridge/tmux-delivery.mjs +390 -0
  119. package/bridge/tmux-session-control.mjs +29 -0
  120. package/bridge/transport/ssh-command.mjs +119 -0
  121. package/bridge/ui-server.mjs +257 -0
  122. package/bridge/vscode-opener.mjs +157 -0
  123. package/bridge/web-terminal.mjs +52 -0
  124. package/bridge/workbench/conversation-routes.mjs +31 -0
  125. package/bridge/workbench/directory-probe.mjs +41 -0
  126. package/bridge/workbench/directory-routes.mjs +112 -0
  127. package/bridge/workbench/manager-context.mjs +51 -0
  128. package/bridge/workbench/routes.mjs +40 -0
  129. package/bridge/workbench/scheduler.mjs +131 -0
  130. package/bridge/workbench/service.mjs +301 -0
  131. package/bridge/workbench/store.mjs +64 -0
  132. package/bridge/workbench/task-archive.mjs +46 -0
  133. package/dist/client/.assetsignore +2 -0
  134. package/dist/client/.vite/manifest.json +366 -0
  135. package/dist/client/_headers +3 -0
  136. package/dist/client/agents/LICENSE.lobe-icons +21 -0
  137. package/dist/client/agents/README.md +14 -0
  138. package/dist/client/agents/antigravity.svg +39 -0
  139. package/dist/client/agents/claude.svg +1 -0
  140. package/dist/client/agents/codex.svg +1 -0
  141. package/dist/client/agents/dsh.svg +4 -0
  142. package/dist/client/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
  143. package/dist/client/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
  144. package/dist/client/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
  145. package/dist/client/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
  146. package/dist/client/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
  147. package/dist/client/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
  148. package/dist/client/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
  149. package/dist/client/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
  150. package/dist/client/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
  151. package/dist/client/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
  152. package/dist/client/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
  153. package/dist/client/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
  154. package/dist/client/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
  155. package/dist/client/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
  156. package/dist/client/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
  157. package/dist/client/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
  158. package/dist/client/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
  159. package/dist/client/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
  160. package/dist/client/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
  161. package/dist/client/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
  162. package/dist/client/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
  163. package/dist/client/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
  164. package/dist/client/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
  165. package/dist/client/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
  166. package/dist/client/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
  167. package/dist/client/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
  168. package/dist/client/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
  169. package/dist/client/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
  170. package/dist/client/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
  171. package/dist/client/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
  172. package/dist/client/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
  173. package/dist/client/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
  174. package/dist/client/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
  175. package/dist/client/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
  176. package/dist/client/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
  177. package/dist/client/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
  178. package/dist/client/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
  179. package/dist/client/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
  180. package/dist/client/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
  181. package/dist/client/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
  182. package/dist/client/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
  183. package/dist/client/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
  184. package/dist/client/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
  185. package/dist/client/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
  186. package/dist/client/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
  187. package/dist/client/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
  188. package/dist/client/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
  189. package/dist/client/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
  190. package/dist/client/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
  191. package/dist/client/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
  192. package/dist/client/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
  193. package/dist/client/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
  194. package/dist/client/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
  195. package/dist/client/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
  196. package/dist/client/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
  197. package/dist/client/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
  198. package/dist/client/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
  199. package/dist/client/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
  200. package/dist/client/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
  201. package/dist/client/assets/_vinext_fonts/geist-8ac0455e797f/geist-001175b1.woff2 +0 -0
  202. package/dist/client/assets/_vinext_fonts/geist-8ac0455e797f/geist-52306abf.woff2 +0 -0
  203. package/dist/client/assets/_vinext_fonts/geist-8ac0455e797f/geist-875ccdd4.woff2 +0 -0
  204. package/dist/client/assets/_vinext_fonts/geist-8ac0455e797f/geist-98bbbccb.woff2 +0 -0
  205. package/dist/client/assets/_vinext_fonts/geist-8ac0455e797f/geist-ff2310f5.woff2 +0 -0
  206. package/dist/client/assets/_vinext_fonts/geist-mono-00e989178794/geist-mono-013b2f2f.woff2 +0 -0
  207. package/dist/client/assets/_vinext_fonts/geist-mono-00e989178794/geist-mono-0638449e.woff2 +0 -0
  208. package/dist/client/assets/_vinext_fonts/geist-mono-00e989178794/geist-mono-44745446.woff2 +0 -0
  209. package/dist/client/assets/_vinext_fonts/geist-mono-00e989178794/geist-mono-44e03052.woff2 +0 -0
  210. package/dist/client/assets/_vinext_fonts/geist-mono-00e989178794/geist-mono-971fb274.woff2 +0 -0
  211. package/dist/client/assets/_vinext_fonts/geist-mono-00e989178794/geist-mono-f6b33328.woff2 +0 -0
  212. package/dist/client/assets/addon-fit-BZbxZs2G.js +1 -0
  213. package/dist/client/assets/framework-CXnKph_e.js +9 -0
  214. package/dist/client/assets/index-CNnP2Ses.css +2 -0
  215. package/dist/client/assets/index-Enu1x0PS.js +3 -0
  216. package/dist/client/assets/layout-segment-context-CmJzExWq.js +1 -0
  217. package/dist/client/assets/page-COBv6VWj.css +1 -0
  218. package/dist/client/assets/page-DVjU6VG_.js +550 -0
  219. package/dist/client/assets/rolldown-runtime-S-ySWqyJ.js +1 -0
  220. package/dist/client/assets/xterm-BBgU7shl.js +36 -0
  221. package/dist/client/favicon.svg +6 -0
  222. package/dist/client/file.svg +1 -0
  223. package/dist/client/globe.svg +1 -0
  224. package/dist/client/og.png +0 -0
  225. package/dist/client/scope-logo.svg +11 -0
  226. package/dist/client/window.svg +1 -0
  227. package/dist/server/.vite/manifest.json +14 -0
  228. package/dist/server/__vite_rsc_assets_manifest.js +49 -0
  229. package/dist/server/assets/index-CNnP2Ses.css +2 -0
  230. package/dist/server/image-config.json +1 -0
  231. package/dist/server/index.js +15201 -0
  232. package/dist/server/ssr/__vite_rsc_assets_manifest.js +49 -0
  233. package/dist/server/ssr/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
  234. package/dist/server/ssr/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
  235. package/dist/server/ssr/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
  236. package/dist/server/ssr/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
  237. package/dist/server/ssr/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
  238. package/dist/server/ssr/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
  239. package/dist/server/ssr/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
  240. package/dist/server/ssr/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
  241. package/dist/server/ssr/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
  242. package/dist/server/ssr/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
  243. package/dist/server/ssr/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
  244. package/dist/server/ssr/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
  245. package/dist/server/ssr/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
  246. package/dist/server/ssr/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
  247. package/dist/server/ssr/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
  248. package/dist/server/ssr/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
  249. package/dist/server/ssr/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
  250. package/dist/server/ssr/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
  251. package/dist/server/ssr/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
  252. package/dist/server/ssr/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
  253. package/dist/server/ssr/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
  254. package/dist/server/ssr/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
  255. package/dist/server/ssr/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
  256. package/dist/server/ssr/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
  257. package/dist/server/ssr/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
  258. package/dist/server/ssr/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
  259. package/dist/server/ssr/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
  260. package/dist/server/ssr/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
  261. package/dist/server/ssr/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
  262. package/dist/server/ssr/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
  263. package/dist/server/ssr/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
  264. package/dist/server/ssr/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
  265. package/dist/server/ssr/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
  266. package/dist/server/ssr/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
  267. package/dist/server/ssr/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
  268. package/dist/server/ssr/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
  269. package/dist/server/ssr/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
  270. package/dist/server/ssr/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
  271. package/dist/server/ssr/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
  272. package/dist/server/ssr/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
  273. package/dist/server/ssr/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
  274. package/dist/server/ssr/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
  275. package/dist/server/ssr/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
  276. package/dist/server/ssr/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
  277. package/dist/server/ssr/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
  278. package/dist/server/ssr/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
  279. package/dist/server/ssr/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
  280. package/dist/server/ssr/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
  281. package/dist/server/ssr/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
  282. package/dist/server/ssr/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
  283. package/dist/server/ssr/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
  284. package/dist/server/ssr/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
  285. package/dist/server/ssr/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
  286. package/dist/server/ssr/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
  287. package/dist/server/ssr/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
  288. package/dist/server/ssr/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
  289. package/dist/server/ssr/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
  290. package/dist/server/ssr/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
  291. package/dist/server/ssr/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
  292. package/dist/server/ssr/assets/addon-fit-C09Jj0_f.js +42 -0
  293. package/dist/server/ssr/assets/error-boundary-Dd2ZYXA8.js +277 -0
  294. package/dist/server/ssr/assets/layout-segment-context-HV_Mvyzf.js +37 -0
  295. package/dist/server/ssr/assets/page-COBv6VWj.css +1 -0
  296. package/dist/server/ssr/assets/page-CYYyCnKD.js +102541 -0
  297. package/dist/server/ssr/assets/xterm-DgzE4ZZ1.js +10232 -0
  298. package/dist/server/ssr/index.js +11840 -0
  299. package/dist/server/ssr/vinext-server.json +1 -0
  300. package/dist/server/vinext-externals.json +1 -0
  301. package/dist/server/vinext-server.json +1 -0
  302. package/dist/server/wrangler.json +1 -0
  303. package/examples/agents/global-agreements.example.md +10 -0
  304. package/examples/agents/research-project.example.md +10 -0
  305. package/examples/agents-media-previews.md +22 -0
  306. package/examples/deployment.example.json +6 -0
  307. package/examples/leak-denylist.example.json +10 -0
  308. package/examples/plugins/hello/index.mjs +4 -0
  309. package/examples/plugins/hello/scope-plugin.json +13 -0
  310. package/examples/workbench.config.json +44 -0
  311. package/lib/account-quota.d.ts +42 -0
  312. package/lib/account-quota.js +121 -0
  313. package/lib/browser-snapshot-cache.js +61 -0
  314. package/lib/conversation-location.js +26 -0
  315. package/lib/conversation.js +62 -0
  316. package/lib/dialogue-refresh.js +14 -0
  317. package/lib/execution-host.js +22 -0
  318. package/lib/formula-preview.js +48 -0
  319. package/lib/i18n.tsx +81 -0
  320. package/lib/incremental-snapshot.js +324 -0
  321. package/lib/manager-plan.js +37 -0
  322. package/lib/markdown-images.js +22 -0
  323. package/lib/markdown-math.js +151 -0
  324. package/lib/markdown-url.js +13 -0
  325. package/lib/model-effort.js +13 -0
  326. package/lib/native-history.d.ts +32 -0
  327. package/lib/native-history.js +94 -0
  328. package/lib/overview-delta.js +41 -0
  329. package/lib/project-view.js +86 -0
  330. package/lib/projects.js +74 -0
  331. package/lib/remote-links.js +95 -0
  332. package/lib/runtime-config.js +70 -0
  333. package/lib/session-activity.js +34 -0
  334. package/lib/session-cache-guard.js +52 -0
  335. package/lib/session-filters.js +38 -0
  336. package/lib/ssh-config.js +26 -0
  337. package/lib/stable-order.js +39 -0
  338. package/lib/workbench-config.js +172 -0
  339. package/package.json +105 -4
  340. package/scripts/agent-email-relay.mjs +104 -0
  341. package/scripts/benchmark-bridge.mjs +38 -0
  342. package/scripts/cli-integration-smoke.mjs +64 -0
  343. package/scripts/email-notification-cli.mjs +28 -0
  344. package/scripts/enable-private-access.ps1 +109 -0
  345. package/scripts/export-opensource.mjs +112 -0
  346. package/scripts/fixtures/media/convergence.png +0 -0
  347. package/scripts/fixtures/media/rollout_demo.mp4 +0 -0
  348. package/scripts/fixtures/native-conversations.mjs +307 -0
  349. package/scripts/fixtures/workbench-conversations.mjs +352 -0
  350. package/scripts/install-remote-server.sh +67 -0
  351. package/scripts/lib/export-directory.mjs +38 -0
  352. package/scripts/lib/secret-scanner.mjs +139 -0
  353. package/scripts/plugin-cli.mjs +19 -0
  354. package/scripts/preview-workbench.mjs +669 -0
  355. package/scripts/probe-antigravity-acp.mjs +35 -0
  356. package/scripts/remote-bootstrap-cli.mjs +52 -0
  357. 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("<", "&lt;")
21
+ .replaceAll(">", "&gt;")
22
+ .replaceAll('"', "&quot;")
23
+ .replaceAll("'", "&#39;");
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
+ }