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,347 @@
1
+ import { spawn } from "node:child_process";
2
+ import { existsSync } from "node:fs";
3
+ import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
4
+ import path from "node:path";
5
+ import {
6
+ createAgentEmailRelayServer,
7
+ loadOrCreateAgentEmailRelayState,
8
+ } from "../agent-email-relay.mjs";
9
+
10
+ const DEFAULT_LOCAL_RELAY_PORT = Number(
11
+ process.env.SCOPE_AGENT_EMAIL_LOCAL_PORT || 4822,
12
+ );
13
+ const DEFAULT_REMOTE_RELAY_PORT = 4922;
14
+
15
+ function validHostAlias(host) {
16
+ return (
17
+ typeof host === "string" &&
18
+ /^[a-zA-Z0-9_][a-zA-Z0-9_.:@-]*$/.test(host)
19
+ );
20
+ }
21
+
22
+ function validPort(port) {
23
+ return Number.isInteger(port) && port >= 1024 && port <= 65_535;
24
+ }
25
+
26
+ export class RemoteTunnelManager {
27
+ constructor({
28
+ stateDir,
29
+ emailNotifier,
30
+ legacyTunnelHost = "",
31
+ localRelayPort = DEFAULT_LOCAL_RELAY_PORT,
32
+ spawnProcess = spawn,
33
+ sshBinary = process.platform === "win32" ? "ssh.exe" : "ssh",
34
+ createRelayServer = createAgentEmailRelayServer,
35
+ }) {
36
+ this.stateDir = stateDir;
37
+ this.configFile = path.join(stateDir, "remote-tunnels.json");
38
+ this.relayStateFile = path.join(stateDir, "agent-email-relay.json");
39
+ this.emailNotifier = emailNotifier;
40
+ this.legacyTunnelHost = validHostAlias(legacyTunnelHost)
41
+ ? legacyTunnelHost
42
+ : "";
43
+ this.localRelayPort = validPort(localRelayPort)
44
+ ? localRelayPort
45
+ : 4822;
46
+ this.spawnProcess = spawnProcess;
47
+ this.sshBinary = sshBinary;
48
+ this.createRelayServer = createRelayServer;
49
+
50
+ this.hosts = new Map();
51
+ this.tunnels = new Map();
52
+ this.relayState = null;
53
+ this.relayServer = null;
54
+ this.relayExternal = false;
55
+ this.relayError = null;
56
+ this.stopping = false;
57
+ this.writes = Promise.resolve();
58
+ }
59
+
60
+ async load() {
61
+ let loaded = null;
62
+ try {
63
+ loaded = JSON.parse(await readFile(this.configFile, "utf8"));
64
+ } catch (error) {
65
+ if (error?.code !== "ENOENT") throw error;
66
+ }
67
+ this.hosts.clear();
68
+ if (loaded?.hosts && typeof loaded.hosts === "object") {
69
+ for (const [host, entry] of Object.entries(loaded.hosts)) {
70
+ if (!validHostAlias(host)) continue;
71
+ const remotePort = Number(entry?.remotePort) || DEFAULT_REMOTE_RELAY_PORT;
72
+ this.hosts.set(host, {
73
+ enabled: Boolean(entry?.enabled),
74
+ remotePort: validPort(remotePort)
75
+ ? remotePort
76
+ : DEFAULT_REMOTE_RELAY_PORT,
77
+ updatedAt: entry?.updatedAt || null,
78
+ });
79
+ }
80
+ } else if (this.legacyTunnelHost) {
81
+ this.hosts.set(this.legacyTunnelHost, {
82
+ enabled: true,
83
+ remotePort: DEFAULT_REMOTE_RELAY_PORT,
84
+ updatedAt: new Date().toISOString(),
85
+ });
86
+ }
87
+ return this;
88
+ }
89
+
90
+ save() {
91
+ const payload = {
92
+ version: 1,
93
+ hosts: Object.fromEntries(this.hosts),
94
+ };
95
+ this.writes = this.writes
96
+ .catch(() => {})
97
+ .then(async () => {
98
+ await mkdir(this.stateDir, { recursive: true });
99
+ const temporary = `${this.configFile}.tmp`;
100
+ await writeFile(temporary, `${JSON.stringify(payload, null, 2)}\n`, {
101
+ encoding: "utf8",
102
+ mode: 0o600,
103
+ });
104
+ await rename(temporary, this.configFile);
105
+ });
106
+ return this.writes;
107
+ }
108
+
109
+ async ensureRelay() {
110
+ this.relayState = await loadOrCreateAgentEmailRelayState(
111
+ this.relayStateFile,
112
+ { localPort: this.localRelayPort },
113
+ );
114
+ if (this.relayServer || this.relayExternal || this.stopping) {
115
+ return {
116
+ token: this.relayState.token,
117
+ localPort: this.localRelayPort,
118
+ };
119
+ }
120
+
121
+ const server = this.createRelayServer({
122
+ token: this.relayState.token,
123
+ notifier: this.emailNotifier,
124
+ });
125
+ try {
126
+ await new Promise((resolve, reject) => {
127
+ server.once("error", reject);
128
+ server.listen(this.localRelayPort, "127.0.0.1", resolve);
129
+ });
130
+ this.relayServer = server;
131
+ this.relayError = null;
132
+ this.relayExternal = false;
133
+ } catch (error) {
134
+ if (error?.code === "EADDRINUSE") {
135
+ this.relayExternal = true;
136
+ this.relayError = null;
137
+ } else {
138
+ this.relayError = error.message;
139
+ throw error;
140
+ }
141
+ }
142
+ return {
143
+ token: this.relayState.token,
144
+ localPort: this.localRelayPort,
145
+ };
146
+ }
147
+
148
+ async start() {
149
+ this.stopping = false;
150
+ const anyEnabled = [...this.hosts.values()].some((item) => item.enabled);
151
+ if (anyEnabled || existsSync(this.relayStateFile)) {
152
+ await this.ensureRelay().catch((error) => {
153
+ this.relayError = error.message;
154
+ });
155
+ }
156
+ for (const [host, entry] of this.hosts) {
157
+ if (entry.enabled) {
158
+ this.#ensureTunnel(host, entry.remotePort);
159
+ }
160
+ }
161
+ }
162
+
163
+ async enable(host, remotePort = DEFAULT_REMOTE_RELAY_PORT) {
164
+ if (!validHostAlias(host)) throw new Error("SSH 主机名无效");
165
+ const port = Number(remotePort) || DEFAULT_REMOTE_RELAY_PORT;
166
+ if (!validPort(port)) throw new Error("远端转发端口必须在 1024 到 65535 之间");
167
+ const relay = await this.ensureRelay();
168
+ const previous = this.hosts.get(host);
169
+ this.hosts.set(host, {
170
+ enabled: true,
171
+ remotePort: port,
172
+ updatedAt: new Date().toISOString(),
173
+ });
174
+ await this.save();
175
+ if (!previous?.enabled || previous.remotePort !== port) {
176
+ this.#stopTunnel(host);
177
+ }
178
+ this.#ensureTunnel(host, port);
179
+ return relay;
180
+ }
181
+
182
+ async disable(host) {
183
+ this.#stopTunnel(host);
184
+ if (this.hosts.has(host)) {
185
+ const entry = this.hosts.get(host);
186
+ this.hosts.set(host, {
187
+ ...entry,
188
+ enabled: false,
189
+ updatedAt: new Date().toISOString(),
190
+ });
191
+ await this.save();
192
+ }
193
+ }
194
+
195
+ #ensureTunnel(host, remotePort) {
196
+ if (this.stopping) return;
197
+ const existing = this.tunnels.get(host);
198
+ if (existing && (existing.child || existing.timer)) return;
199
+ const state = existing || {
200
+ host,
201
+ remotePort,
202
+ status: "connecting",
203
+ failures: 0,
204
+ lastError: null,
205
+ connectedAt: null,
206
+ child: null,
207
+ timer: null,
208
+ };
209
+ // A stopped runtime entry survives a configuration change. Reconnect with
210
+ // the newly saved port rather than the previous entry's forwarding target.
211
+ state.remotePort = remotePort;
212
+ this.tunnels.set(host, state);
213
+ this.#connectTunnel(state);
214
+ }
215
+
216
+ #connectTunnel(state) {
217
+ if (this.stopping) return;
218
+ const entry = this.hosts.get(state.host);
219
+ if (!entry?.enabled) return;
220
+ const startedAt = Date.now();
221
+ state.status = state.failures > 0 ? "reconnecting" : "connecting";
222
+ let child;
223
+ try {
224
+ child = this.spawnProcess(
225
+ this.sshBinary,
226
+ [
227
+ "-NT",
228
+ "-o",
229
+ "BatchMode=yes",
230
+ "-o",
231
+ "StrictHostKeyChecking=yes",
232
+ "-o",
233
+ "ConnectTimeout=10",
234
+ "-o",
235
+ "ExitOnForwardFailure=yes",
236
+ "-o",
237
+ "ServerAliveInterval=30",
238
+ "-o",
239
+ "ServerAliveCountMax=3",
240
+ "-R",
241
+ `127.0.0.1:${state.remotePort}:127.0.0.1:${this.localRelayPort}`,
242
+ "--",
243
+ state.host,
244
+ ],
245
+ { windowsHide: true, stdio: ["ignore", "ignore", "pipe"] },
246
+ );
247
+ } catch (error) {
248
+ state.status = "error";
249
+ state.lastError = error.message;
250
+ return;
251
+ }
252
+
253
+ state.child = child;
254
+ let stderr = "";
255
+ child.stderr?.setEncoding("utf8");
256
+ child.stderr?.on("data", (chunk) => {
257
+ stderr = `${stderr}${chunk}`.slice(-2_000);
258
+ });
259
+ const healthyTimer = setTimeout(() => {
260
+ if (state.child === child && !this.stopping) {
261
+ state.status = "connected";
262
+ state.connectedAt = new Date().toISOString();
263
+ state.lastError = null;
264
+ }
265
+ }, 1_500);
266
+ healthyTimer.unref?.();
267
+
268
+ child.on("error", (error) => {
269
+ state.lastError = error.message;
270
+ });
271
+ child.once("close", (code) => {
272
+ clearTimeout(healthyTimer);
273
+ if (state.child !== child) return;
274
+ state.child = null;
275
+ if (this.stopping || !this.hosts.get(state.host)?.enabled) {
276
+ state.status = "stopped";
277
+ return;
278
+ }
279
+ state.failures = Date.now() - startedAt > 60_000 ? 0 : state.failures + 1;
280
+ const cleanErr = stderr.trim();
281
+ state.lastError = cleanErr || `SSH 隧道退出(code ${code ?? 1})`;
282
+ state.status = "reconnecting";
283
+ const delay = Math.min(60_000, 1_000 * 2 ** Math.min(state.failures, 6));
284
+ state.timer = setTimeout(() => {
285
+ state.timer = null;
286
+ this.#connectTunnel(state);
287
+ }, delay);
288
+ state.timer.unref?.();
289
+ });
290
+ }
291
+
292
+ #stopTunnel(host) {
293
+ const state = this.tunnels.get(host);
294
+ if (!state) return;
295
+ if (state.timer) {
296
+ clearTimeout(state.timer);
297
+ state.timer = null;
298
+ }
299
+ const child = state.child;
300
+ state.child = null;
301
+ state.status = "stopped";
302
+ if (child && !child.killed) {
303
+ try {
304
+ child.kill("SIGTERM");
305
+ } catch {
306
+ /* ignore */
307
+ }
308
+ }
309
+ }
310
+
311
+ hostStatus(host) {
312
+ const config = this.hosts.get(host);
313
+ const runtime = this.tunnels.get(host);
314
+ return {
315
+ enabled: Boolean(config?.enabled),
316
+ remotePort: config?.remotePort || DEFAULT_REMOTE_RELAY_PORT,
317
+ status: !config?.enabled
318
+ ? "disabled"
319
+ : runtime?.status || "stopped",
320
+ connectedAt: runtime?.connectedAt || null,
321
+ lastError: runtime?.lastError || null,
322
+ };
323
+ }
324
+
325
+ status(host = "") {
326
+ return {
327
+ relayListening: Boolean(this.relayServer) || this.relayExternal,
328
+ relayExternal: this.relayExternal,
329
+ relayPort: this.localRelayPort,
330
+ relayError: this.relayError,
331
+ relayTokenReady: Boolean(this.relayState?.token || existsSync(this.relayStateFile)),
332
+ ...(host ? { host: this.hostStatus(host) } : {}),
333
+ };
334
+ }
335
+
336
+ stop() {
337
+ this.stopping = true;
338
+ for (const host of this.tunnels.keys()) {
339
+ this.#stopTunnel(host);
340
+ }
341
+ if (this.relayServer) {
342
+ this.relayServer.closeAllConnections?.();
343
+ this.relayServer.close();
344
+ this.relayServer = null;
345
+ }
346
+ }
347
+ }
@@ -0,0 +1,148 @@
1
+ import { spawn } from "node:child_process";
2
+ import os from "node:os";
3
+ import path from "node:path";
4
+
5
+ const DIRECTORY_TIMEOUT_MS = 20_000;
6
+ const MAX_OUTPUT_BYTES = 2_000_000;
7
+
8
+ const DIRECTORY_PROBE = String.raw`
9
+ import json
10
+ import os
11
+ import sys
12
+
13
+ requested = sys.argv[1]
14
+ if not requested.startswith("/") or "\n" in requested or "\r" in requested:
15
+ print("工作目录必须是远端绝对路径", file=sys.stderr)
16
+ raise SystemExit(2)
17
+ resolved = os.path.realpath(requested)
18
+ if not os.path.isdir(resolved):
19
+ print("工作目录不存在:" + resolved, file=sys.stderr)
20
+ raise SystemExit(3)
21
+
22
+ directories = []
23
+ truncated = False
24
+ try:
25
+ names = sorted(os.listdir(resolved), key=lambda value: value.lower())
26
+ for name in names:
27
+ candidate = os.path.join(resolved, name)
28
+ try:
29
+ if os.path.isdir(candidate):
30
+ directories.append({"name": name, "path": candidate})
31
+ except OSError:
32
+ continue
33
+ if len(directories) >= 300:
34
+ truncated = True
35
+ break
36
+ except OSError as error:
37
+ print("无法读取工作目录:" + str(error), file=sys.stderr)
38
+ raise SystemExit(4)
39
+
40
+ parent = os.path.dirname(resolved)
41
+ print(json.dumps({
42
+ "cwd": resolved,
43
+ "parent": parent if parent != resolved else None,
44
+ "directories": directories,
45
+ "truncated": truncated,
46
+ }, ensure_ascii=False, separators=(",", ":")))
47
+ `;
48
+
49
+ function shellQuote(value) {
50
+ return `'${String(value).replaceAll("'", `'"'"'`)}'`;
51
+ }
52
+
53
+ function cleanError(value) {
54
+ return String(value || "")
55
+ .replace(/\x1b\[[0-9;]*m/g, "")
56
+ .trim()
57
+ .slice(0, 2_000);
58
+ }
59
+
60
+ export function listRemoteDirectories({
61
+ host,
62
+ requestedPath,
63
+ sshConfig = path.join(os.homedir(), ".ssh", "config"),
64
+ timeoutMs = DIRECTORY_TIMEOUT_MS,
65
+ } = {}) {
66
+ const alias = String(host || "").trim();
67
+ const remotePath = String(requestedPath || "/").trim();
68
+ if (!alias || !/^[a-zA-Z0-9_.:@-]+$/.test(alias)) {
69
+ return Promise.reject(new Error("SSH 主机名无效"));
70
+ }
71
+ if (!remotePath.startsWith("/") || /[\r\n]/.test(remotePath)) {
72
+ return Promise.reject(new Error("工作目录必须是远端绝对路径"));
73
+ }
74
+
75
+ return new Promise((resolve, reject) => {
76
+ const child = spawn(
77
+ "ssh",
78
+ [
79
+ "-F",
80
+ sshConfig,
81
+ "-o",
82
+ "BatchMode=yes",
83
+ "-o",
84
+ "ConnectTimeout=8",
85
+ "--",
86
+ alias,
87
+ `python3 - ${shellQuote(remotePath)}`,
88
+ ],
89
+ { stdio: ["pipe", "pipe", "pipe"], windowsHide: true },
90
+ );
91
+ const stdout = [];
92
+ const stderr = [];
93
+ let outputBytes = 0;
94
+ let settled = false;
95
+ let timer = null;
96
+ const finish = (error, value) => {
97
+ if (settled) return;
98
+ settled = true;
99
+ if (timer) clearTimeout(timer);
100
+ if (error) reject(error);
101
+ else resolve(value);
102
+ };
103
+ const collect = (target) => (chunk) => {
104
+ outputBytes += chunk.length;
105
+ if (outputBytes > MAX_OUTPUT_BYTES) {
106
+ child.kill();
107
+ finish(new Error("远端目录列表过大"));
108
+ return;
109
+ }
110
+ target.push(chunk);
111
+ };
112
+ child.stdout.on("data", collect(stdout));
113
+ child.stderr.on("data", collect(stderr));
114
+ child.once("error", (error) => finish(error));
115
+ child.once("exit", (code) => {
116
+ const output = Buffer.concat(stdout).toString("utf8").trim();
117
+ const errorOutput = cleanError(Buffer.concat(stderr).toString("utf8"));
118
+ if (code !== 0) {
119
+ finish(new Error(errorOutput || `SSH 目录读取退出码 ${code}`));
120
+ return;
121
+ }
122
+ try {
123
+ const listing = JSON.parse(output);
124
+ finish(null, {
125
+ host: alias,
126
+ cwd: String(listing.cwd || remotePath),
127
+ parent: listing.parent ? String(listing.parent) : null,
128
+ directories: Array.isArray(listing.directories)
129
+ ? listing.directories
130
+ .filter((entry) => entry?.name && entry?.path)
131
+ .map((entry) => ({
132
+ name: String(entry.name),
133
+ path: String(entry.path),
134
+ }))
135
+ : [],
136
+ truncated: Boolean(listing.truncated),
137
+ });
138
+ } catch {
139
+ finish(new Error("远端目录结果无法解析"));
140
+ }
141
+ });
142
+ timer = setTimeout(() => {
143
+ child.kill();
144
+ finish(new Error("读取远端目录超时"));
145
+ }, timeoutMs);
146
+ child.stdin.end(DIRECTORY_PROBE);
147
+ });
148
+ }
@@ -0,0 +1,140 @@
1
+ import { spawn } from "node:child_process";
2
+ import { readFile } from "node:fs/promises";
3
+ import os from "node:os";
4
+ import path from "node:path";
5
+ import { createHash } from "node:crypto";
6
+
7
+ export const MAX_IMAGE_BYTES = 20 * 1024 * 1024;
8
+ const MAX_CACHE_BYTES = 64 * 1024 * 1024;
9
+ const TTL = 60_000;
10
+ const cache = new Map();
11
+ const pending = new Map();
12
+ let cacheBytes = 0;
13
+ let activeReads = 0;
14
+ const waiting = [];
15
+
16
+ export function validateImagePath(value) {
17
+ if (typeof value !== "string" || !value.startsWith("/") || value.startsWith("//") || value.length > 4096 || /[\x00-\x1f]/.test(value)) {
18
+ throw new Error("图片必须使用远端绝对路径");
19
+ }
20
+ if (!/\.(png|jpe?g|gif|webp|svg|bmp|ico|avif)$/i.test(value)) throw new Error("不支持的图片格式");
21
+ return value;
22
+ }
23
+
24
+ export function imageContentType(data) {
25
+ if (data.subarray(0, 8).equals(Buffer.from([137,80,78,71,13,10,26,10]))) return "image/png";
26
+ if (data[0] === 255 && data[1] === 216 && data[2] === 255) return "image/jpeg";
27
+ if (/^GIF8[79]a/.test(data.subarray(0, 6).toString())) return "image/gif";
28
+ if (data.toString("ascii", 0, 4) === "RIFF" && data.toString("ascii", 8, 12) === "WEBP") return "image/webp";
29
+ if (data.toString("ascii", 0, 2) === "BM") return "image/bmp";
30
+ if (data.subarray(0, 4).equals(Buffer.from([0,0,1,0]))) return "image/x-icon";
31
+ if (data.toString("ascii", 4, 8) === "ftyp" && /avif|avis/.test(data.toString("ascii", 8, 32))) return "image/avif";
32
+ if (/^\s*(?:<\?xml[^>]*>\s*)?(?:<!--[\s\S]*?-->\s*)*<svg[\s>]/i.test(data.subarray(0, 4096).toString("utf8"))) return "image/svg+xml";
33
+ throw new Error("文件内容不是支持的图片");
34
+ }
35
+
36
+ const PROBE = `import os, stat, sys
37
+ p = sys.argv[1]
38
+ fd = os.open(p, os.O_RDONLY | os.O_NONBLOCK)
39
+ with os.fdopen(fd, 'rb') as f:
40
+ s = os.fstat(f.fileno())
41
+ if not stat.S_ISREG(s.st_mode): raise ValueError('Not a regular image file')
42
+ if s.st_size > ${MAX_IMAGE_BYTES}: raise ValueError('Image exceeds 20 MiB')
43
+ data = f.read(${MAX_IMAGE_BYTES + 1})
44
+ if len(data) > ${MAX_IMAGE_BYTES}: raise ValueError('Image exceeds 20 MiB')
45
+ sys.stdout.buffer.write(data)
46
+ `;
47
+
48
+ export async function configuredSshTarget(host) {
49
+ if (!/^[a-zA-Z0-9_][a-zA-Z0-9_.@:-]*$/.test(host || "")) throw new Error("SSH 主机名无效");
50
+ const sshConfig = process.env.SCOPE_SSH_CONFIG || path.join(os.homedir(), ".ssh", "config");
51
+ const config = await readFile(sshConfig, "utf8");
52
+ const aliases = [...config.matchAll(/^\s*Host\s+([^\r\n#]+)/gmi)].flatMap((m) => m[1].trim().split(/\s+/));
53
+ if (!aliases.includes(host)) throw new Error("只能读取已配置 SSH 主机的图片");
54
+ return sshConfig;
55
+ }
56
+
57
+ export async function readRemoteImage({ host, requestedPath }) {
58
+ validateImagePath(requestedPath);
59
+ const sshConfig = await configuredSshTarget(host);
60
+ const key = JSON.stringify([host, requestedPath]);
61
+ const old = cache.get(key);
62
+ if (old && Date.now() - old.time < TTL) return old;
63
+ if (pending.has(key)) return pending.get(key);
64
+ if (pending.size >= 36) throw new Error("图片加载繁忙,请稍后重试");
65
+ const slot = activeReads < 4 ? (activeReads++, Promise.resolve()) : new Promise((resolve) => waiting.push(resolve));
66
+ const work = slot.then(() => new Promise((resolve, reject) => {
67
+ const quoted = `'${requestedPath.replaceAll("'", `'"'"'`)}'`;
68
+ const child = spawn("ssh", ["-F", sshConfig, "-T", "-o", "BatchMode=yes", "-o", "ConnectTimeout=8", "--", host, `python3 - ${quoted}`], { windowsHide: true, stdio: ["pipe", "pipe", "pipe"] });
69
+ const chunks = [];
70
+ let size = 0;
71
+ let errorText = "";
72
+ let done = false;
73
+ const finish = (error, result) => {
74
+ if (done) return;
75
+ done = true;
76
+ clearTimeout(timer);
77
+ if (error) { child.kill(); reject(error); } else resolve(result);
78
+ };
79
+ const timer = setTimeout(() => finish(new Error("远端图片读取超时")), 30_000);
80
+ child.stdout.on("data", (chunk) => {
81
+ size += chunk.length;
82
+ if (size > MAX_IMAGE_BYTES) finish(new Error("图片超过 20 MiB"));
83
+ else if (!done) chunks.push(chunk);
84
+ });
85
+ child.stderr.on("data", (chunk) => { errorText = (errorText + chunk.toString()).slice(-2000); });
86
+ child.stdin.on("error", (error) => finish(error));
87
+ child.once("error", (error) => finish(error));
88
+ child.once("close", (code) => {
89
+ if (done) return;
90
+ if (code !== 0) return finish(new Error(errorText.trim() || "远端图片读取失败"));
91
+ try {
92
+ const data = Buffer.concat(chunks);
93
+ const type = imageContentType(data);
94
+ finish(null, { data, type, etag: `"${createHash("sha256").update(data).digest("hex")}"`, time: Date.now() });
95
+ } catch (error) { finish(error); }
96
+ });
97
+ child.stdin.end(PROBE);
98
+ })).finally(() => {
99
+ const next = waiting.shift();
100
+ if (next) next();
101
+ else activeReads--;
102
+ });
103
+ pending.set(key, work);
104
+ try {
105
+ const result = await work;
106
+ if (old) { cache.delete(key); cacheBytes -= old.data.length; }
107
+ while (cache.size && (cacheBytes + result.data.length > MAX_CACHE_BYTES || cache.size >= 128)) {
108
+ const first = cache.keys().next().value;
109
+ cacheBytes -= cache.get(first).data.length;
110
+ cache.delete(first);
111
+ }
112
+ cache.set(key, result);
113
+ cacheBytes += result.data.length;
114
+ return result;
115
+ } finally { pending.delete(key); }
116
+ }
117
+
118
+ export async function remoteImageResponse(request, reader = readRemoteImage) {
119
+ const url = new URL(request.url);
120
+ if (request.method !== "GET") return new Response("Method not allowed", { status: 405 });
121
+ // Prevent other sites from embedding private SSH files or reading this endpoint.
122
+ if (request.headers.get("sec-fetch-site") === "cross-site" || (request.headers.get("origin") && request.headers.get("origin") !== url.origin)) {
123
+ return new Response("Forbidden", { status: 403 });
124
+ }
125
+ try {
126
+ const result = await reader({ host: url.searchParams.get("host") || "", requestedPath: url.searchParams.get("path") || "" });
127
+ const headers = {
128
+ "Content-Type": result.type,
129
+ "Cache-Control": "private, max-age=60",
130
+ "ETag": result.etag,
131
+ "X-Content-Type-Options": "nosniff",
132
+ "Cross-Origin-Resource-Policy": "same-origin",
133
+ "Content-Security-Policy": "default-src 'none'; style-src 'unsafe-inline'; sandbox",
134
+ };
135
+ if (request.headers.get("if-none-match") === result.etag) return new Response(null, { status: 304, headers });
136
+ return new Response(result.data, { headers });
137
+ } catch (error) {
138
+ return Response.json({ error: error.message }, { status: 400, headers: { "Cache-Control": "no-store" } });
139
+ }
140
+ }
@@ -0,0 +1,39 @@
1
+ // Existing CLI homes may have their own live writers. Never move their locks.
2
+ // A dedicated SCOPE runtime shares the host's rollout/lock namespace and only
3
+ // links credentials to the selected profile (including its auth commit lock).
4
+ export function profileHomeSelection(slug) {
5
+ if (!/^[a-zA-Z0-9][a-zA-Z0-9._-]{0,47}$/.test(slug)) throw new Error("Invalid isolated profile");
6
+ return [
7
+ `profile_root="$HOME/.codex/scope-auth-profiles/${slug}"`,
8
+ 'profile_auth_home="$profile_root/home"',
9
+ 'app_codex_home="$profile_auth_home"',
10
+ 'if test -d "$profile_root/scope-home" || { test -d "$profile_auth_home/thread-writer-locks" && test ! -L "$profile_auth_home/thread-writer-locks"; }; then',
11
+ ' app_codex_home="$profile_root/scope-home"',
12
+ 'fi',
13
+ ];
14
+ }
15
+
16
+ export function prepareProfileHome(slug) {
17
+ return [
18
+ ...profileHomeSelection(slug),
19
+ 'test -f "$profile_auth_home/auth.json" || { echo "Profile is not logged in" >&2; exit 76; }',
20
+ 'if test "$app_codex_home" != "$profile_auth_home"; then',
21
+ ' (umask 077; mkdir -p "$app_codex_home")',
22
+ // FileAuthStorage writes auth.json in place; auth.lock serializes commits.
23
+ // https://github.com/openai/codex/blob/main/codex-rs/login/src/auth/storage.rs
24
+ ' for scope_auth_file in auth.json auth.lock; do',
25
+ ' scope_auth_target="$profile_auth_home/$scope_auth_file"',
26
+ ' scope_auth_link="$app_codex_home/$scope_auth_file"',
27
+ ' if test ! -e "$scope_auth_link" && test ! -L "$scope_auth_link"; then',
28
+ ' ln -s "$scope_auth_target" "$scope_auth_link" 2>/dev/null || test -L "$scope_auth_link"',
29
+ ' fi',
30
+ ' test -L "$scope_auth_link" && test "$(readlink -f "$scope_auth_link")" = "$(readlink -f "$scope_auth_target")" || { echo "SCOPE profile credential link mismatch; preserving existing files" >&2; exit 77; }',
31
+ ' done',
32
+ ' for scope_config in config.toml AGENTS.md skills memories; do',
33
+ ' if test -e "$profile_auth_home/$scope_config" && test ! -e "$app_codex_home/$scope_config" && test ! -L "$app_codex_home/$scope_config"; then',
34
+ ' ln -s "$profile_auth_home/$scope_config" "$app_codex_home/$scope_config" 2>/dev/null || test -L "$app_codex_home/$scope_config"',
35
+ ' fi',
36
+ ' done',
37
+ 'fi',
38
+ ];
39
+ }