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.
Files changed (358) hide show
  1. package/CHANGELOG.md +59 -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 +36 -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 +432 -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 +637 -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 +463 -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 +177 -0
  95. package/bridge/routes/accounts.mjs +326 -0
  96. package/bridge/routes/dialogue.mjs +165 -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 +3357 -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 +388 -0
  109. package/bridge/session-catalog/catalog.mjs +110 -0
  110. package/bridge/session-catalog/probe.py +1207 -0
  111. package/bridge/session-catalog/routes.mjs +34 -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 +405 -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-BMior55c.js +3 -0
  215. package/dist/client/assets/index-CNnP2Ses.css +2 -0
  216. package/dist/client/assets/layout-segment-context-DjGudgXn.js +1 -0
  217. package/dist/client/assets/page-CJqXlhDs.js +551 -0
  218. package/dist/client/assets/page-LYzRz6_S.css +1 -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-BB9Dri2u.js +104686 -0
  296. package/dist/server/ssr/assets/page-LYzRz6_S.css +1 -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/subagent-display-prefs.ts +130 -0
  339. package/lib/workbench-config.js +172 -0
  340. package/package.json +105 -4
  341. package/scripts/agent-email-relay.mjs +104 -0
  342. package/scripts/benchmark-bridge.mjs +38 -0
  343. package/scripts/cli-integration-smoke.mjs +64 -0
  344. package/scripts/email-notification-cli.mjs +28 -0
  345. package/scripts/enable-private-access.ps1 +109 -0
  346. package/scripts/export-opensource.mjs +112 -0
  347. package/scripts/fixtures/media/convergence.png +0 -0
  348. package/scripts/fixtures/media/rollout_demo.mp4 +0 -0
  349. package/scripts/fixtures/native-conversations.mjs +465 -0
  350. package/scripts/fixtures/workbench-conversations.mjs +475 -0
  351. package/scripts/install-remote-server.sh +67 -0
  352. package/scripts/lib/export-directory.mjs +38 -0
  353. package/scripts/lib/secret-scanner.mjs +139 -0
  354. package/scripts/plugin-cli.mjs +19 -0
  355. package/scripts/preview-workbench.mjs +669 -0
  356. package/scripts/probe-antigravity-acp.mjs +35 -0
  357. package/scripts/remote-bootstrap-cli.mjs +52 -0
  358. package/scripts/remote-email-tool.py +383 -0
@@ -0,0 +1,597 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import { LOCAL_HOST } from "../../lib/execution-host.js";
3
+ import {
4
+ SCOPE_PROTOCOL_BEGIN,
5
+ SCOPE_PROTOCOL_END,
6
+ buildScopeProtocolBlock,
7
+ syncLocalScopeProtocol,
8
+ } from "./scope-protocol.mjs";
9
+
10
+ const REMOTE_EMAIL_TOOL_PATH = new URL(
11
+ "../../scripts/remote-email-tool.py",
12
+ import.meta.url,
13
+ );
14
+
15
+ const DEFAULT_REMOTE_PORT = 4922;
16
+
17
+ function validPort(value) {
18
+ const port = Number(value || DEFAULT_REMOTE_PORT);
19
+ if (!Number.isInteger(port) || port < 1024 || port > 65_535) {
20
+ throw new Error("远端端口必须在 1024 到 65535 之间");
21
+ }
22
+ return port;
23
+ }
24
+
25
+ function buildInspectScript() {
26
+ return String.raw`
27
+ import json, os, pwd, shutil, subprocess
28
+ from pathlib import Path
29
+
30
+ def _extend_path():
31
+ extra = [Path.home() / ".local" / "bin", Path.home() / ".cargo" / "bin"]
32
+ nvm_root = Path.home() / ".nvm" / "versions" / "node"
33
+ if nvm_root.is_dir():
34
+ extra.extend(sorted(nvm_root.glob("*/bin"), reverse=True))
35
+ extra.append(Path("/usr/local/bin"))
36
+ current = [p for p in os.environ.get("PATH", "").split(os.pathsep) if p]
37
+ for candidate in reversed(extra):
38
+ text = str(candidate)
39
+ if candidate.is_dir() and text not in current:
40
+ current.insert(0, text)
41
+ os.environ["PATH"] = os.pathsep.join(current)
42
+
43
+ _extend_path()
44
+
45
+ def which_cmd(name):
46
+ found = shutil.which(name)
47
+ if found:
48
+ return found
49
+ nvm_candidates = sorted((Path.home() / ".nvm" / "versions" / "node").glob(f"*/bin/{name}"), reverse=True)
50
+ for candidate in (Path.home() / ".local" / "bin" / name, Path.home() / ".cargo" / "bin" / name, *nvm_candidates, Path("/usr/local/bin") / name):
51
+ if candidate.exists() and os.access(candidate, os.X_OK):
52
+ return str(candidate)
53
+ return None
54
+
55
+ def run(args, timeout=8):
56
+ try:
57
+ r = subprocess.run(args, capture_output=True, text=True, timeout=timeout)
58
+ return r.returncode, (r.stdout or "").strip(), (r.stderr or "").strip()
59
+ except Exception as exc:
60
+ return 1, "", str(exc)
61
+
62
+ def cli_info(name):
63
+ exe = which_cmd(name)
64
+ if not exe:
65
+ return {"installed": False, "executable": None, "version": None}
66
+ code, out, err = run([exe, "--version"], timeout=10)
67
+ return {
68
+ "installed": True,
69
+ "executable": exe,
70
+ "version": (out or err).splitlines()[0][:120] if (out or err) else None,
71
+ }
72
+
73
+ home = Path.home()
74
+ user = os.environ.get("USER") or pwd.getpwuid(os.getuid()).pw_name
75
+ path_entries = [os.path.realpath(p) for p in os.environ.get("PATH", "").split(os.pathsep) if p]
76
+ local_bin = os.path.realpath(str(home / ".local" / "bin"))
77
+ local_bin_in_path = local_bin in path_entries
78
+
79
+ py_ver = run(["python3", "--version"])
80
+ node_exe = which_cmd("node")
81
+ node_ver = run([node_exe, "--version"])[1] if node_exe else None
82
+ npm_exe = which_cmd("npm")
83
+ tmux_exe = which_cmd("tmux")
84
+ gpu_code, gpu_out, _ = run(["nvidia-smi", "--query-gpu=name", "--format=csv,noheader"], timeout=5)
85
+ gpu_count = len([line for line in gpu_out.splitlines() if line.strip()]) if gpu_code == 0 else 0
86
+
87
+ systemd_code, _, _ = run(["systemctl", "--user", "show-environment"], timeout=5)
88
+ systemd_user_available = systemd_code == 0
89
+ systemd_service_active = False
90
+ if systemd_user_available:
91
+ sc, sout, _ = run(["systemctl", "--user", "is-active", "scope-notify.service"], timeout=5)
92
+ systemd_service_active = sc == 0 and sout.strip() == "active"
93
+
94
+ notify_exe = which_cmd("scope-notify")
95
+ notify_status = None
96
+ if notify_exe:
97
+ nc, nout, _ = run([notify_exe, "status"], timeout=6)
98
+ if nc == 0 and nout:
99
+ try:
100
+ notify_status = json.loads(nout)
101
+ except Exception:
102
+ notify_status = None
103
+
104
+ lock_active = False
105
+ lock_file = home / ".local" / "state" / "scope-email" / "service.lock"
106
+ if lock_file.exists():
107
+ import fcntl
108
+ try:
109
+ with lock_file.open("r", encoding="utf-8") as fh:
110
+ fcntl.flock(fh.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB)
111
+ fcntl.flock(fh.fileno(), fcntl.LOCK_UN)
112
+ except BlockingIOError:
113
+ lock_active = True
114
+ except Exception:
115
+ pass
116
+
117
+ codex_exe = which_cmd("codex")
118
+ claude_exe = which_cmd("claude")
119
+ codex_mcp = False
120
+ claude_mcp = False
121
+ if codex_exe:
122
+ codex_mcp = run([codex_exe, "mcp", "get", "scope-email"], timeout=8)[0] == 0
123
+ if claude_exe:
124
+ claude_mcp = run([claude_exe, "mcp", "get", "scope-email"], timeout=8)[0] == 0
125
+
126
+ def has_protocol(path_obj):
127
+ try:
128
+ if not path_obj.exists():
129
+ return False
130
+ text = path_obj.read_text(encoding="utf-8", errors="ignore")
131
+ return ${JSON.stringify(SCOPE_PROTOCOL_BEGIN)} in text and ${JSON.stringify(SCOPE_PROTOCOL_END)} in text
132
+ except Exception:
133
+ return False
134
+
135
+ agy_gemini = home / ".gemini" / "config" / "GEMINI.md"
136
+ agy_gemini_alt = home / ".gemini" / "GEMINI.md"
137
+
138
+ report = {
139
+ "user": user,
140
+ "isRoot": os.geteuid() == 0,
141
+ "home": str(home),
142
+ "python3": py_ver[1] if py_ver[0] == 0 else None,
143
+ "node": node_ver,
144
+ "npm": bool(npm_exe),
145
+ "tmux": bool(tmux_exe),
146
+ "gpuCount": gpu_count,
147
+ "localBinInPath": local_bin_in_path,
148
+ "systemdUserAvailable": systemd_user_available,
149
+ "clis": {
150
+ "codex": cli_info("codex"),
151
+ "claude": cli_info("claude"),
152
+ "antigravity": cli_info("agy"),
153
+ "dsh": cli_info("dsh"),
154
+ },
155
+ "scopeProtocol": {
156
+ "codex": has_protocol(home / ".codex" / "AGENTS.md"),
157
+ "claude": has_protocol(home / ".claude" / "CLAUDE.md"),
158
+ "antigravity": has_protocol(agy_gemini) or has_protocol(agy_gemini_alt),
159
+ },
160
+ "scopeNotify": {
161
+ "installed": bool(notify_exe and (home / ".config" / "scope-email" / "config.json").exists()),
162
+ "executable": notify_exe,
163
+ "daemonActive": systemd_service_active or lock_active,
164
+ "systemdServiceActive": systemd_service_active,
165
+ "relayReachable": bool(notify_status and notify_status.get("relayReachable")),
166
+ "queued": int(notify_status.get("queued", 0)) if notify_status else 0,
167
+ "lastDeliveredAt": notify_status.get("lastDeliveredAt") if notify_status else None,
168
+ "codexMcp": codex_mcp,
169
+ "claudeMcp": claude_mcp,
170
+ },
171
+ }
172
+ print("SCOPE_BOOTSTRAP_REPORT=" + json.dumps(report, ensure_ascii=False))
173
+ `;
174
+ }
175
+
176
+ const COMPLETION_BLOCK = [
177
+ "<!-- SCOPE_COMPLETION_EMAIL_BEGIN -->",
178
+ "## Completion email notifications",
179
+ "",
180
+ "For long-running or unattended work, use the `send_completion_email` MCP tool exactly once when the task completes, fails, or needs the operator's attention. Do not email routine progress updates or ordinary chat replies. Include a concise result and the experiment or session identifier when available. If MCP is unavailable, run `~/.local/bin/scope-notify send --status completed|failed|needs_attention --title ... --summary ...`.",
181
+ "<!-- SCOPE_COMPLETION_EMAIL_END -->",
182
+ ].join("\n");
183
+
184
+ function buildSyncProtocolScript({ operatorName = "" } = {}) {
185
+ const protocolBlock = buildScopeProtocolBlock({ operatorName });
186
+ return String.raw`
187
+ import json, os
188
+ from pathlib import Path
189
+
190
+ BEGIN = ${JSON.stringify(SCOPE_PROTOCOL_BEGIN)}
191
+ END = ${JSON.stringify(SCOPE_PROTOCOL_END)}
192
+ BLOCK = json.loads(${JSON.stringify(JSON.stringify(protocolBlock))})
193
+
194
+ home = Path.home()
195
+ targets = [
196
+ ("codex", home / ".codex" / "AGENTS.md"),
197
+ ("claude", home / ".claude" / "CLAUDE.md"),
198
+ ("antigravity", home / ".gemini" / "config" / "GEMINI.md"),
199
+ ]
200
+ legacy_gemini = home / ".gemini" / "GEMINI.md"
201
+ if legacy_gemini.exists() and not legacy_gemini.is_symlink():
202
+ targets.append(("antigravity", legacy_gemini))
203
+
204
+ profiles_dir = home / ".codex" / "scope-auth-profiles"
205
+ if profiles_dir.is_dir():
206
+ for sub in ("home", "scope-home"):
207
+ for profile_home in profiles_dir.glob(f"*/{sub}"):
208
+ if (profile_home / "config.toml").exists():
209
+ targets.append(("codex", profile_home / "AGENTS.md"))
210
+
211
+ seen = set()
212
+ updated_files = []
213
+ for client, filename in targets:
214
+ filename.parent.mkdir(mode=0o700, parents=True, exist_ok=True)
215
+ canonical = os.path.realpath(str(filename))
216
+ if canonical in seen:
217
+ continue
218
+ seen.add(canonical)
219
+ current = filename.read_text(encoding="utf-8") if filename.exists() else ""
220
+ if BEGIN in current and END in current:
221
+ prefix, remainder = current.split(BEGIN, 1)
222
+ _, suffix = remainder.split(END, 1)
223
+ joined_prefix = (prefix.rstrip() + "\n\n") if prefix.strip() else ""
224
+ joined_suffix = suffix if suffix.startswith("\n") else ("\n" + suffix if suffix else "\n")
225
+ updated = joined_prefix + BLOCK + joined_suffix
226
+ else:
227
+ updated = (current.rstrip() + "\n\n" + BLOCK + "\n") if current.strip() else (BLOCK + "\n")
228
+ filename.write_text(updated, encoding="utf-8")
229
+ updated_files.append({"client": client, "path": str(filename)})
230
+
231
+ print("SCOPE_PROTOCOL_SYNC_OK=" + json.dumps({"codex": True, "claude": True, "antigravity": True, "files": updated_files}, ensure_ascii=False))
232
+ `;
233
+ }
234
+
235
+ function buildDeployScript({ toolSourceBase64, remotePort, token, registerMcp, injectProtocol = true, operatorName = "" }) {
236
+ const protocolBlock = buildScopeProtocolBlock({ operatorName });
237
+ const configJson = JSON.stringify({
238
+ endpoint: `http://127.0.0.1:${remotePort}/v1/notify`,
239
+ token,
240
+ });
241
+ return String.raw`
242
+ import base64, json, os, shutil, subprocess, sys
243
+ from pathlib import Path
244
+
245
+ TOOL_B64 = ${JSON.stringify(toolSourceBase64)}
246
+ CONFIG = json.loads(${JSON.stringify(configJson)})
247
+ BLOCK = json.loads(${JSON.stringify(JSON.stringify(COMPLETION_BLOCK))})
248
+ PROTO_BEGIN = ${JSON.stringify(SCOPE_PROTOCOL_BEGIN)}
249
+ PROTO_END = ${JSON.stringify(SCOPE_PROTOCOL_END)}
250
+ PROTO_BLOCK = json.loads(${JSON.stringify(JSON.stringify(protocolBlock))})
251
+ INJECT_PROTOCOL = ${injectProtocol ? "True" : "False"}
252
+ REGISTER_MCP = ${registerMcp ? "True" : "False"}
253
+
254
+ home = Path.home()
255
+ share_dir = home / ".local" / "share" / "scope-email"
256
+ bin_dir = home / ".local" / "bin"
257
+ config_dir = home / ".config" / "scope-email"
258
+ state_dir = home / ".local" / "state" / "scope-email"
259
+ outbox_dir = state_dir / "outbox"
260
+ for directory in (share_dir, bin_dir, config_dir, state_dir, outbox_dir):
261
+ directory.mkdir(mode=0o700, parents=True, exist_ok=True)
262
+
263
+ tool_path = share_dir / "scope_notify.py"
264
+ tool_bytes = base64.b64decode(TOOL_B64).replace(b"\r\n", b"\n")
265
+ tool_path.write_bytes(tool_bytes)
266
+ os.chmod(tool_path, 0o755)
267
+
268
+ bin_link = bin_dir / "scope-notify"
269
+ if bin_link.exists() or bin_link.is_symlink():
270
+ bin_link.unlink()
271
+ bin_link.symlink_to(tool_path)
272
+
273
+ if os.geteuid() == 0 and os.access("/usr/local/bin", os.W_OK):
274
+ sys_link = Path("/usr/local/bin/scope-notify")
275
+ try:
276
+ if sys_link.exists() or sys_link.is_symlink():
277
+ sys_link.unlink()
278
+ sys_link.symlink_to(tool_path)
279
+ except Exception:
280
+ pass
281
+
282
+ config_path = config_dir / "config.json"
283
+ fd = os.open(config_path, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600)
284
+ with os.fdopen(fd, "w", encoding="utf-8") as fh:
285
+ json.dump(CONFIG, fh, indent=2)
286
+ fh.write("\n")
287
+ os.chmod(config_path, 0o600)
288
+
289
+ BEGIN = "<!-- SCOPE_COMPLETION_EMAIL_BEGIN -->"
290
+ END = "<!-- SCOPE_COMPLETION_EMAIL_END -->"
291
+
292
+ def upsert_block(text, b_mark, e_mark, payload):
293
+ if b_mark in text and e_mark in text:
294
+ prefix, remainder = text.split(b_mark, 1)
295
+ _, suffix = remainder.split(e_mark, 1)
296
+ joined_prefix = (prefix.rstrip() + "\n\n") if prefix.strip() else ""
297
+ joined_suffix = suffix if suffix.startswith("\n") else ("\n" + suffix if suffix else "\n")
298
+ return joined_prefix + payload + joined_suffix
299
+ return (text.rstrip() + "\n\n" + payload + "\n") if text.strip() else (payload + "\n")
300
+
301
+ targets = [
302
+ home / ".codex" / "AGENTS.md",
303
+ home / ".claude" / "CLAUDE.md",
304
+ home / ".gemini" / "config" / "GEMINI.md",
305
+ ]
306
+ legacy_gemini = home / ".gemini" / "GEMINI.md"
307
+ if legacy_gemini.exists() and not legacy_gemini.is_symlink():
308
+ targets.append(legacy_gemini)
309
+ profiles_dir = home / ".codex" / "scope-auth-profiles"
310
+ if profiles_dir.is_dir():
311
+ for sub in ("home", "scope-home"):
312
+ for profile_home in profiles_dir.glob(f"*/{sub}"):
313
+ if (profile_home / "config.toml").exists():
314
+ targets.append(profile_home / "AGENTS.md")
315
+
316
+ seen_targets = set()
317
+ for filename in targets:
318
+ filename.parent.mkdir(mode=0o700, parents=True, exist_ok=True)
319
+ canonical = os.path.realpath(str(filename))
320
+ if canonical in seen_targets:
321
+ continue
322
+ seen_targets.add(canonical)
323
+ current = filename.read_text(encoding="utf-8") if filename.exists() else ""
324
+ updated = upsert_block(current, BEGIN, END, BLOCK)
325
+ if INJECT_PROTOCOL:
326
+ updated = upsert_block(updated, PROTO_BEGIN, PROTO_END, PROTO_BLOCK)
327
+ filename.write_text(updated, encoding="utf-8")
328
+
329
+ def which_cmd(name):
330
+ found = shutil.which(name)
331
+ if found:
332
+ return found
333
+ for candidate in (bin_dir / name, Path("/usr/local/bin") / name):
334
+ if candidate.exists() and os.access(candidate, os.X_OK):
335
+ return str(candidate)
336
+ return None
337
+
338
+ def run(args, timeout=15):
339
+ return subprocess.run(args, capture_output=True, text=True, timeout=timeout)
340
+
341
+ if REGISTER_MCP:
342
+ codex_exe = which_cmd("codex")
343
+ if codex_exe:
344
+ run([codex_exe, "mcp", "remove", "scope-email"])
345
+ run([codex_exe, "mcp", "add", "scope-email", "--", str(bin_link), "mcp"])
346
+ claude_exe = which_cmd("claude")
347
+ if claude_exe:
348
+ run([claude_exe, "mcp", "remove", "--scope", "user", "scope-email"])
349
+ run([claude_exe, "mcp", "add", "--scope", "user", "--transport", "stdio", "scope-email", "--", str(bin_link), "mcp"])
350
+
351
+ systemd_ok = run(["systemctl", "--user", "show-environment"], timeout=5).returncode == 0
352
+ daemon_mode = "nohup"
353
+ if systemd_ok:
354
+ unit_dir = home / ".config" / "systemd" / "user"
355
+ unit_dir.mkdir(mode=0o700, parents=True, exist_ok=True)
356
+ unit_path = unit_dir / "scope-notify.service"
357
+ unit_path.write_text(
358
+ "[Unit]\nDescription=SCOPE Completion Email Retry Daemon\nAfter=network.target\n\n"
359
+ "[Service]\nType=simple\n"
360
+ f"ExecStart={sys.executable} {tool_path} service\n"
361
+ "Restart=on-failure\nRestartSec=5\n\n"
362
+ "[Install]\nWantedBy=default.target\n",
363
+ encoding="utf-8",
364
+ )
365
+ run(["systemctl", "--user", "daemon-reload"], timeout=10)
366
+ res = run(["systemctl", "--user", "enable", "--now", "scope-notify.service"], timeout=10)
367
+ if res.returncode == 0:
368
+ daemon_mode = "systemd-user"
369
+ if daemon_mode != "systemd-user":
370
+ log_path = state_dir / "service.log"
371
+ with log_path.open("a", encoding="utf-8") as log_file:
372
+ subprocess.Popen(
373
+ [sys.executable, str(tool_path), "service"],
374
+ stdin=subprocess.DEVNULL,
375
+ stdout=log_file,
376
+ stderr=log_file,
377
+ start_new_session=True,
378
+ close_fds=True,
379
+ )
380
+
381
+ status_res = run([str(bin_link), "status"], timeout=8)
382
+ print("SCOPE_DEPLOY_OK=" + json.dumps({"daemonMode": daemon_mode, "statusCode": status_res.returncode, "statusRaw": status_res.stdout.strip()}))
383
+ `;
384
+ }
385
+
386
+ function buildRemoveScript() {
387
+ return String.raw`
388
+ import json, os, shutil, subprocess
389
+ from pathlib import Path
390
+
391
+ home = Path.home()
392
+ def run(args, timeout=10):
393
+ try:
394
+ return subprocess.run(args, capture_output=True, text=True, timeout=timeout)
395
+ except Exception:
396
+ return None
397
+
398
+ if run(["systemctl", "--user", "show-environment"], timeout=5):
399
+ run(["systemctl", "--user", "disable", "--now", "scope-notify.service"], timeout=10)
400
+ unit_path = home / ".config" / "systemd" / "user" / "scope-notify.service"
401
+ if unit_path.exists():
402
+ unit_path.unlink()
403
+ run(["systemctl", "--user", "daemon-reload"], timeout=8)
404
+
405
+ for cmd_args in (["codex", "mcp", "remove", "scope-email"], ["claude", "mcp", "remove", "--scope", "user", "scope-email"]):
406
+ exe = shutil.which(cmd_args[0]) or (str(home / ".local" / "bin" / cmd_args[0]) if (home / ".local" / "bin" / cmd_args[0]).exists() else None)
407
+ if exe:
408
+ run([exe, *cmd_args[1:]], timeout=10)
409
+
410
+ BEGIN = "<!-- SCOPE_COMPLETION_EMAIL_BEGIN -->"
411
+ END = "<!-- SCOPE_COMPLETION_EMAIL_END -->"
412
+ targets = [
413
+ home / ".codex" / "AGENTS.md",
414
+ home / ".claude" / "CLAUDE.md",
415
+ home / ".gemini" / "config" / "GEMINI.md",
416
+ home / ".gemini" / "GEMINI.md",
417
+ ]
418
+ profiles_dir = home / ".codex" / "scope-auth-profiles"
419
+ if profiles_dir.is_dir():
420
+ for sub in ("home", "scope-home"):
421
+ for profile_home in profiles_dir.glob(f"*/{sub}"):
422
+ targets.append(profile_home / "AGENTS.md")
423
+ seen_remove = set()
424
+ for filename in targets:
425
+ if filename.exists():
426
+ canonical = os.path.realpath(str(filename))
427
+ if canonical in seen_remove:
428
+ continue
429
+ seen_remove.add(canonical)
430
+ text = filename.read_text(encoding="utf-8")
431
+ if BEGIN in text and END in text:
432
+ prefix, remainder = text.split(BEGIN, 1)
433
+ _, suffix = remainder.split(END, 1)
434
+ cleaned = (prefix.rstrip() + "\n" + suffix.lstrip()).strip()
435
+ filename.write_text((cleaned + "\n") if cleaned else "", encoding="utf-8")
436
+
437
+ for target in (
438
+ home / ".config" / "scope-email" / "config.json",
439
+ home / ".local" / "bin" / "scope-notify",
440
+ Path("/usr/local/bin/scope-notify"),
441
+ ):
442
+ try:
443
+ if target.exists() or target.is_symlink():
444
+ target.unlink()
445
+ except Exception:
446
+ pass
447
+
448
+ print("SCOPE_REMOVE_OK=" + json.dumps({"removed": True}))
449
+ `;
450
+ }
451
+
452
+ export class RemoteBootstrapService {
453
+ constructor({
454
+ run,
455
+ getHost,
456
+ tunnels,
457
+ getOperatorName = () => "",
458
+ readRemoteTool = () => readFile(REMOTE_EMAIL_TOOL_PATH, "utf8"),
459
+ }) {
460
+ this.run = run;
461
+ this.getHost = getHost;
462
+ this.tunnels = tunnels;
463
+ this.getOperatorName = getOperatorName;
464
+ this.readRemoteTool = readRemoteTool;
465
+ this.cache = new Map();
466
+ }
467
+
468
+ #requireRemoteHost(host) {
469
+ if (!host || host === LOCAL_HOST) {
470
+ throw new Error("请选择远端 SSH 主机");
471
+ }
472
+ const candidate = this.getHost(host);
473
+ if (!candidate) throw new Error("找不到对应 SSH 主机");
474
+ if (!candidate.reachable) throw new Error("主机当前离线");
475
+ return candidate;
476
+ }
477
+
478
+ state(host) {
479
+ const cached = host ? this.cache.get(host) || null : null;
480
+ return {
481
+ host: host || null,
482
+ report: cached?.report || null,
483
+ checkedAt: cached?.checkedAt || null,
484
+ lastAction: cached?.lastAction || null,
485
+ tunnel: host ? this.tunnels.hostStatus(host) : null,
486
+ relay: this.tunnels.status(host),
487
+ };
488
+ }
489
+
490
+ async inspect(host) {
491
+ this.#requireRemoteHost(host);
492
+ const result = await this.run(host, "python3 -", buildInspectScript(), 45_000, 1_000_000);
493
+ if (result.code !== 0) {
494
+ throw new Error(
495
+ (result.stderr || result.stdout || "远端环境检查失败").trim().slice(-800),
496
+ );
497
+ }
498
+ const line = result.stdout
499
+ .split(/\r?\n/)
500
+ .findLast((item) => item.startsWith("SCOPE_BOOTSTRAP_REPORT="));
501
+ if (!line) {
502
+ throw new Error("未收到远端环境检查结果(请确认远端已安装 Python 3)");
503
+ }
504
+ const report = JSON.parse(line.slice("SCOPE_BOOTSTRAP_REPORT=".length));
505
+ this.cache.set(host, {
506
+ report,
507
+ checkedAt: new Date().toISOString(),
508
+ lastAction: "inspect",
509
+ });
510
+ return this.state(host);
511
+ }
512
+
513
+ async deploy(host, { remotePort = DEFAULT_REMOTE_PORT, registerMcp = true, injectProtocol = true, operatorName } = {}) {
514
+ this.#requireRemoteHost(host);
515
+ const port = validPort(remotePort);
516
+ const relay = await this.tunnels.enable(host, port);
517
+ const toolSource = await this.readRemoteTool();
518
+ const effectiveOperator = operatorName ?? this.getOperatorName?.() ?? "";
519
+ const script = buildDeployScript({
520
+ toolSourceBase64: Buffer.from(toolSource, "utf8").toString("base64"),
521
+ remotePort: port,
522
+ token: relay.token,
523
+ registerMcp,
524
+ injectProtocol,
525
+ operatorName: effectiveOperator,
526
+ });
527
+ const result = await this.run(host, "python3 -", script, 60_000, 1_000_000);
528
+ if (result.code !== 0) {
529
+ throw new Error(
530
+ (result.stderr || result.stdout || "远端部署失败").trim().slice(-1_000),
531
+ );
532
+ }
533
+ // Wait briefly for reverse SSH port forwarding to bind before final inspection.
534
+ await new Promise((resolve) => setTimeout(resolve, 1_200));
535
+ const refreshed = await this.inspect(host);
536
+ this.cache.set(host, {
537
+ ...this.cache.get(host),
538
+ lastAction: "deploy",
539
+ });
540
+ return { ...refreshed, lastAction: "deploy" };
541
+ }
542
+
543
+ async syncProtocol(host, { operatorName } = {}) {
544
+ const effectiveOperator = operatorName ?? this.getOperatorName?.() ?? "";
545
+ if (host === LOCAL_HOST) {
546
+ const protocol = await syncLocalScopeProtocol(undefined, {
547
+ operatorName: effectiveOperator,
548
+ });
549
+ return {
550
+ host: LOCAL_HOST,
551
+ lastAction: "sync-protocol",
552
+ protocol,
553
+ checkedAt: new Date().toISOString(),
554
+ };
555
+ }
556
+ this.#requireRemoteHost(host);
557
+ const result = await this.run(
558
+ host,
559
+ "python3 -",
560
+ buildSyncProtocolScript({ operatorName: effectiveOperator }),
561
+ 45_000,
562
+ 1_000_000,
563
+ );
564
+ if (result.code !== 0) {
565
+ throw new Error(
566
+ (result.stderr || result.stdout || "同步三端 SCOPE 协议失败").trim().slice(-800),
567
+ );
568
+ }
569
+ const line = result.stdout
570
+ .split(/\r?\n/)
571
+ .findLast((item) => item.startsWith("SCOPE_PROTOCOL_SYNC_OK="));
572
+ const protocol = line ? JSON.parse(line.slice("SCOPE_PROTOCOL_SYNC_OK=".length)) : null;
573
+ const refreshed = await this.inspect(host);
574
+ this.cache.set(host, {
575
+ ...this.cache.get(host),
576
+ lastAction: "sync-protocol",
577
+ });
578
+ return { ...refreshed, lastAction: "sync-protocol", protocol };
579
+ }
580
+
581
+ async remove(host) {
582
+ this.#requireRemoteHost(host);
583
+ const result = await this.run(host, "python3 -", buildRemoveScript(), 45_000, 1_000_000);
584
+ if (result.code !== 0) {
585
+ throw new Error(
586
+ (result.stderr || result.stdout || "远端卸载失败").trim().slice(-800),
587
+ );
588
+ }
589
+ await this.tunnels.disable(host);
590
+ const refreshed = await this.inspect(host);
591
+ this.cache.set(host, {
592
+ ...this.cache.get(host),
593
+ lastAction: "remove",
594
+ });
595
+ return { ...refreshed, lastAction: "remove" };
596
+ }
597
+ }