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,219 @@
1
+ import { createHash, randomBytes } from "node:crypto";
2
+ import { EventEmitter } from "node:events";
3
+ import { PassThrough, Writable } from "node:stream";
4
+
5
+ const WEBSOCKET_GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
6
+
7
+ function frame(opcode, payload = Buffer.alloc(0)) {
8
+ const body = Buffer.isBuffer(payload) ? payload : Buffer.from(payload);
9
+ const mask = randomBytes(4);
10
+ let header;
11
+ if (body.length < 126) {
12
+ header = Buffer.alloc(2);
13
+ header[1] = 0x80 | body.length;
14
+ } else if (body.length <= 0xffff) {
15
+ header = Buffer.alloc(4);
16
+ header[1] = 0x80 | 126;
17
+ header.writeUInt16BE(body.length, 2);
18
+ } else {
19
+ header = Buffer.alloc(10);
20
+ header[1] = 0x80 | 127;
21
+ header.writeBigUInt64BE(BigInt(body.length), 2);
22
+ }
23
+ header[0] = 0x80 | opcode;
24
+ const masked = Buffer.alloc(body.length);
25
+ for (let index = 0; index < body.length; index += 1) {
26
+ masked[index] = body[index] ^ mask[index % 4];
27
+ }
28
+ return Buffer.concat([header, mask, masked]);
29
+ }
30
+
31
+ export class WebSocketJsonlChild extends EventEmitter {
32
+ constructor(
33
+ child,
34
+ {
35
+ path = "/",
36
+ host = "localhost",
37
+ pingIntervalMs = 25_000,
38
+ setIntervalFn = setInterval,
39
+ clearIntervalFn = clearInterval,
40
+ } = {},
41
+ ) {
42
+ super();
43
+ this.child = child;
44
+ this.stdout = new PassThrough();
45
+ this.stderr = child.stderr;
46
+ this.killed = false;
47
+ this.ready = false;
48
+ this.closed = false;
49
+ this.buffer = Buffer.alloc(0);
50
+ this.fragments = [];
51
+ this.pendingWrites = [];
52
+ this.pingIntervalMs = Math.max(0, Number(pingIntervalMs) || 0);
53
+ this.setIntervalFn = setIntervalFn;
54
+ this.clearIntervalFn = clearIntervalFn;
55
+ this.pingTimer = null;
56
+ // Lets JsonlAppServerConnection distinguish this disposable SSH/WebSocket
57
+ // bridge from an actual remote app-server process exit.
58
+ this.scopeTransport = "ssh-websocket";
59
+ this.key = randomBytes(16).toString("base64");
60
+ this.stdin = new Writable({
61
+ write: (chunk, _encoding, callback) => {
62
+ try {
63
+ const payload = Buffer.from(chunk);
64
+ if (this.ready) this.child.stdin.write(frame(0x1, payload));
65
+ else this.pendingWrites.push(payload);
66
+ callback();
67
+ } catch (error) {
68
+ callback(error);
69
+ }
70
+ },
71
+ final: (callback) => {
72
+ try {
73
+ this.#stopHeartbeat();
74
+ if (!this.child.stdin.destroyed) {
75
+ if (this.ready) this.child.stdin.write(frame(0x8));
76
+ this.child.stdin.end();
77
+ }
78
+ callback();
79
+ } catch (error) {
80
+ callback(error);
81
+ }
82
+ },
83
+ });
84
+ child.stdout.on("data", (chunk) => this.#read(chunk));
85
+ child.once("error", (error) => this.emit("error", error));
86
+ child.once("exit", (code, signal) => {
87
+ this.#stopHeartbeat();
88
+ this.closed = true;
89
+ this.stdout.end();
90
+ this.emit("exit", code, signal);
91
+ });
92
+ child.stdin.on("error", (error) => this.stdin.destroy(error));
93
+ const request = [
94
+ `GET ${path} HTTP/1.1`,
95
+ `Host: ${host}`,
96
+ "Upgrade: websocket",
97
+ "Connection: Upgrade",
98
+ `Sec-WebSocket-Key: ${this.key}`,
99
+ "Sec-WebSocket-Version: 13",
100
+ "",
101
+ "",
102
+ ].join("\r\n");
103
+ child.stdin.write(request);
104
+ }
105
+
106
+ kill() {
107
+ // Compatibility with ChildProcess consumers. This intentionally closes the
108
+ // proxy stream instead of signalling the durable remote app-server.
109
+ this.killed = true;
110
+ this.#stopHeartbeat();
111
+ this.stdin.end();
112
+ }
113
+
114
+ #read(chunk) {
115
+ this.buffer = Buffer.concat([this.buffer, Buffer.from(chunk)]);
116
+ if (!this.ready) {
117
+ const marker = this.buffer.indexOf("\r\n\r\n");
118
+ if (marker < 0) return;
119
+ const response = this.buffer.subarray(0, marker + 4).toString("utf8");
120
+ this.buffer = this.buffer.subarray(marker + 4);
121
+ const status = response.split("\r\n", 1)[0] || "";
122
+ const accept = response.match(/\r\nsec-websocket-accept:\s*([^\r\n]+)/i)?.[1]?.trim();
123
+ const expected = createHash("sha1")
124
+ .update(`${this.key}${WEBSOCKET_GUID}`)
125
+ .digest("base64");
126
+ if (!/^HTTP\/1\.[01] 101\b/.test(status) || accept !== expected) {
127
+ this.emit(
128
+ "error",
129
+ new Error(`app-server WebSocket 握手失败:${status || "无响应"}`),
130
+ );
131
+ return;
132
+ }
133
+ this.ready = true;
134
+ this.#startHeartbeat();
135
+ for (const payload of this.pendingWrites.splice(0)) {
136
+ this.child.stdin.write(frame(0x1, payload));
137
+ }
138
+ }
139
+ this.#drainFrames();
140
+ }
141
+
142
+ #drainFrames() {
143
+ while (this.buffer.length >= 2) {
144
+ const first = this.buffer[0];
145
+ const second = this.buffer[1];
146
+ const fin = Boolean(first & 0x80);
147
+ const opcode = first & 0x0f;
148
+ const masked = Boolean(second & 0x80);
149
+ let length = second & 0x7f;
150
+ let offset = 2;
151
+ if (length === 126) {
152
+ if (this.buffer.length < 4) return;
153
+ length = this.buffer.readUInt16BE(2);
154
+ offset = 4;
155
+ } else if (length === 127) {
156
+ if (this.buffer.length < 10) return;
157
+ const wide = this.buffer.readBigUInt64BE(2);
158
+ if (wide > BigInt(Number.MAX_SAFE_INTEGER)) {
159
+ this.emit("error", new Error("app-server WebSocket 帧过大"));
160
+ return;
161
+ }
162
+ length = Number(wide);
163
+ offset = 10;
164
+ }
165
+ const maskOffset = offset;
166
+ if (masked) offset += 4;
167
+ if (this.buffer.length < offset + length) return;
168
+ const mask = masked
169
+ ? Buffer.from(this.buffer.subarray(maskOffset, maskOffset + 4))
170
+ : null;
171
+ let payload = Buffer.from(this.buffer.subarray(offset, offset + length));
172
+ this.buffer = this.buffer.subarray(offset + length);
173
+ if (mask) {
174
+ for (let index = 0; index < payload.length; index += 1) {
175
+ payload[index] ^= mask[index % 4];
176
+ }
177
+ }
178
+ if (opcode === 0x8) {
179
+ this.#stopHeartbeat();
180
+ if (!this.child.stdin.destroyed) this.child.stdin.end(frame(0x8));
181
+ continue;
182
+ }
183
+ if (opcode === 0x9) {
184
+ if (!this.child.stdin.destroyed) this.child.stdin.write(frame(0xa, payload));
185
+ continue;
186
+ }
187
+ if (opcode === 0xa) continue;
188
+ if (opcode === 0x1) this.fragments = [payload];
189
+ else if (opcode === 0x0) this.fragments.push(payload);
190
+ else continue;
191
+ if (fin) {
192
+ this.stdout.write(Buffer.concat(this.fragments));
193
+ this.stdout.write("\n");
194
+ this.fragments = [];
195
+ }
196
+ }
197
+ }
198
+
199
+ #startHeartbeat() {
200
+ if (this.pingTimer || !this.ready || this.closed || !this.pingIntervalMs) {
201
+ return;
202
+ }
203
+ this.pingTimer = this.setIntervalFn(() => {
204
+ if (!this.ready || this.closed || this.child.stdin.destroyed) return;
205
+ try {
206
+ this.child.stdin.write(frame(0x9));
207
+ } catch {
208
+ // The child exit/error handlers surface the real disconnect.
209
+ }
210
+ }, this.pingIntervalMs);
211
+ this.pingTimer?.unref?.();
212
+ }
213
+
214
+ #stopHeartbeat() {
215
+ if (!this.pingTimer) return;
216
+ this.clearIntervalFn(this.pingTimer);
217
+ this.pingTimer = null;
218
+ }
219
+ }
@@ -0,0 +1,19 @@
1
+ export function archiveRoutes(service, { readJsonBody, jsonResponse }) {
2
+ return async (req, res, url) => {
3
+ if (url.pathname !== "/api/session/archives") return false;
4
+ res.setHeader("Cache-Control", "no-store");
5
+ try {
6
+ if (req.method === "GET")
7
+ jsonResponse(res, 200, { records: service.list() });
8
+ else if (req.method === "POST") {
9
+ const { host, sessionId, action } = await readJsonBody(req);
10
+ jsonResponse(res, 200, {
11
+ record: await service.change(host, sessionId, action),
12
+ });
13
+ } else jsonResponse(res, 405, { error: "不支持的请求方法" });
14
+ } catch (error) {
15
+ jsonResponse(res, 409, { error: error.message });
16
+ }
17
+ return true;
18
+ };
19
+ }
@@ -0,0 +1,130 @@
1
+ /** Durable intents make lost SSH replies retryable without pretending local-only deletion succeeded. */
2
+ export function sessionArchiveService({
3
+ manager,
4
+ getState,
5
+ persist,
6
+ findAgent,
7
+ getHost,
8
+ executable,
9
+ connectionKey,
10
+ notify,
11
+ restored,
12
+ protectedSession = () => false,
13
+ }) {
14
+ const busy = new Set();
15
+ const keyOf = (host, id) => `${host}:${id}`;
16
+ function list() {
17
+ return Object.values(getState().sessions).flatMap((value) =>
18
+ value.archive && value.archive.phase !== "restored"
19
+ ? [value.archive]
20
+ : [],
21
+ );
22
+ }
23
+ async function write(key, record) {
24
+ const sessions = getState().sessions;
25
+ const previous = sessions[key];
26
+ sessions[key] = { ...previous, archive: record };
27
+ try {
28
+ await persist();
29
+ } catch (error) {
30
+ sessions[key] = previous;
31
+ throw error;
32
+ }
33
+ notify();
34
+ }
35
+ async function change(host, sessionId, action, receipt = null) {
36
+ if (!host || !sessionId || !["archive", "restore"].includes(action))
37
+ throw new Error("归档参数无效");
38
+ if (protectedSession(host, sessionId))
39
+ throw new Error("这是总调度的主会话,请从左侧归档普通项目会话或任务");
40
+ const key = keyOf(host, sessionId);
41
+ if (busy.has(key)) throw new Error("此会话的归档操作尚未完成");
42
+ if (!getHost(host)?.reachable)
43
+ throw new Error("主机当前离线,恢复连接后可归档或恢复");
44
+ busy.add(key);
45
+ let record;
46
+ try {
47
+ const previous = getState().sessions[key]?.archive;
48
+ if (action === "restore" && !previous) throw new Error("找不到归档记录");
49
+ if (action === "restore" && previous.phase === "restored")
50
+ return previous;
51
+ const agent = findAgent(host, sessionId);
52
+ const managed = manager
53
+ .sessionRecords()
54
+ .find((s) => s.host === host && s.sessionId === sessionId);
55
+ if (action === "archive") {
56
+ if (!agent && !managed && !receipt && !previous)
57
+ throw new Error("找不到对应会话");
58
+ if (
59
+ agent?.status === "working" ||
60
+ (!managed && (agent?.pid > 0 || agent?.pane))
61
+ )
62
+ throw new Error("会话仍由运行中的 Agent 使用,请结束后再归档");
63
+ if (agent?.subagents?.some((child) => child.status === "working"))
64
+ throw new Error("子会话仍在执行,请结束后再归档");
65
+ }
66
+ record = {
67
+ ...previous,
68
+ host,
69
+ sessionId,
70
+ title:
71
+ previous?.title ||
72
+ agent?.title ||
73
+ agent?.rollout?.firstUser ||
74
+ sessionId,
75
+ session: managed || previous?.session || null,
76
+ cwd: previous?.cwd || agent?.cwd || managed?.cwd || receipt?.cwd || "",
77
+ executable:
78
+ managed?.executable ||
79
+ receipt?.executable ||
80
+ previous?.executable ||
81
+ executable(host),
82
+ connectionKey:
83
+ managed?.connectionKey ||
84
+ receipt?.connectionKey ||
85
+ previous?.connectionKey ||
86
+ (await connectionKey(host, sessionId)),
87
+ phase: action === "archive" ? "archiving" : "restoring",
88
+ error: null,
89
+ updatedAt: new Date().toISOString(),
90
+ };
91
+ await write(key, record);
92
+ if (action === "archive") {
93
+ await manager.archiveSession(
94
+ host,
95
+ sessionId,
96
+ record.executable,
97
+ record.connectionKey,
98
+ );
99
+ record = {
100
+ ...record,
101
+ phase: "archived",
102
+ archivedAt: new Date().toISOString(),
103
+ };
104
+ } else {
105
+ const thread = await manager.unarchiveSession(
106
+ host,
107
+ sessionId,
108
+ record.executable,
109
+ record.connectionKey,
110
+ );
111
+ if (record.session)
112
+ await manager.resumeSession({
113
+ ...record.session,
114
+ path: thread.path || null,
115
+ });
116
+ await restored(host, sessionId, thread);
117
+ record = { ...record, phase: "restored" };
118
+ }
119
+ await write(key, record);
120
+ return record;
121
+ } catch (error) {
122
+ if (record)
123
+ await write(key, { ...record, error: error.message }).catch(() => {});
124
+ throw error;
125
+ } finally {
126
+ busy.delete(key);
127
+ }
128
+ }
129
+ return { list, change };
130
+ }
@@ -0,0 +1,52 @@
1
+ const locks = new WeakMap();
2
+ export function isArchiving(manager, host, sessionId) {
3
+ return locks.get(manager)?.has(`${host}:${sessionId}`) || false;
4
+ }
5
+
6
+ /** Archive the durable remote thread first; only then release local bookkeeping. */
7
+ export async function archiveThread(
8
+ manager,
9
+ host,
10
+ sessionId,
11
+ executable,
12
+ connectionKey,
13
+ ) {
14
+ if (!locks.has(manager)) locks.set(manager, new Set());
15
+ const held = locks.get(manager);
16
+ const key = `${host}:${sessionId}`;
17
+ if (held.has(key)) throw new Error("正在归档,请稍后重试");
18
+ const session = manager.sessions.get(key);
19
+ if (
20
+ session &&
21
+ (session.status === "working" ||
22
+ session.turnStarting ||
23
+ session.profileHandoff ||
24
+ session.profileSwitching)
25
+ )
26
+ throw new Error("会话仍在执行或交接,请结束后再归档");
27
+ held.add(key);
28
+ try {
29
+ const connection = await manager.prepareHost(
30
+ host,
31
+ session?.executable || executable,
32
+ session?.connectionKey || connectionKey,
33
+ );
34
+ const { thread } = await connection.request("thread/read", {
35
+ threadId: sessionId,
36
+ includeTurns: true,
37
+ });
38
+ if (!thread) throw new Error("无法核实远端会话,未归档");
39
+ if (
40
+ thread.status?.type === "active" ||
41
+ thread.turns?.some((t) => t.status === "inProgress")
42
+ )
43
+ throw new Error("远端会话仍在执行,请结束后再归档");
44
+ // A previous reply may have been lost after the remote move succeeded.
45
+ if (!/[\\/]archived_sessions[\\/]/.test(thread.path || ""))
46
+ await connection.request("thread/archive", { threadId: sessionId });
47
+ manager.forgetArchivedSession(host, sessionId);
48
+ return thread;
49
+ } finally {
50
+ held.delete(key);
51
+ }
52
+ }
@@ -0,0 +1,184 @@
1
+ import { spawn } from "node:child_process";
2
+ import { createHash } from "node:crypto";
3
+ import { once } from "node:events";
4
+ import {
5
+ MAX_ATTACHMENT_BYTES,
6
+ MAX_ATTACHMENTS_PER_TURN,
7
+ MAX_ATTACHMENTS_TOTAL_BYTES,
8
+ } from "./session-attachments.mjs";
9
+
10
+ export function attachmentHttpError(message, statusCode = 400) {
11
+ const error = new Error(message);
12
+ error.statusCode = statusCode;
13
+ return error;
14
+ }
15
+
16
+ export function createAttachmentStore({
17
+ cleanSshError,
18
+ inventoryOperations,
19
+ sshOperationCounts,
20
+ SSH_TIMEOUT_MS,
21
+ ATTACHMENT_TTL_MS,
22
+ ATTACHMENT_UPLOAD_TIMEOUT_MS,
23
+ }) {
24
+ const uploadedAttachments = new Map();
25
+
26
+ function purgeExpiredAttachments(now = Date.now()) {
27
+ for (const [token, attachment] of uploadedAttachments) {
28
+ if (now - attachment.createdAt > ATTACHMENT_TTL_MS) {
29
+ uploadedAttachments.delete(token);
30
+ }
31
+ }
32
+ }
33
+
34
+ function storeUploadedAttachment(record) {
35
+ purgeExpiredAttachments(record.createdAt);
36
+ uploadedAttachments.set(record.token, record);
37
+ }
38
+
39
+ function resolveUploadedAttachments(value, host, expected = "") {
40
+ purgeExpiredAttachments();
41
+ if (!Array.isArray(value)) return [];
42
+ if (value.length > MAX_ATTACHMENTS_PER_TURN) {
43
+ throw attachmentHttpError(`每条消息最多 ${MAX_ATTACHMENTS_PER_TURN} 个附件`);
44
+ }
45
+ const expectedSessionId =
46
+ typeof expected === "string" ? expected : String(expected?.sessionId || "");
47
+ const expectedScope =
48
+ typeof expected === "object" && expected ? String(expected.scope || "") : "";
49
+ const resolved = [];
50
+ const seen = new Set();
51
+ let totalBytes = 0;
52
+ for (const item of value) {
53
+ const token = typeof item?.token === "string" ? item.token.trim() : "";
54
+ if (!token || seen.has(token)) continue;
55
+ seen.add(token);
56
+ const attachment = uploadedAttachments.get(token);
57
+ if (!attachment) {
58
+ throw attachmentHttpError("附件已过期或 Bridge 已重启,请重新上传", 410);
59
+ }
60
+ if (expectedScope) {
61
+ if (attachment.host !== host || attachment.sessionId || attachment.scope !== expectedScope) {
62
+ throw attachmentHttpError("附件不属于当前主机与会话上下文", 403);
63
+ }
64
+ } else if (attachment.host !== host || attachment.sessionId !== expectedSessionId) {
65
+ throw attachmentHttpError("附件不属于当前主机与 Session", 403);
66
+ }
67
+ totalBytes += attachment.size;
68
+ if (totalBytes > MAX_ATTACHMENTS_TOTAL_BYTES) {
69
+ throw attachmentHttpError("单条消息的附件总大小不能超过 100 MiB", 413);
70
+ }
71
+ resolved.push(attachment);
72
+ }
73
+ return resolved;
74
+ }
75
+
76
+ async function streamAttachmentToHost(alias, request, command) {
77
+ const inventory = inventoryOperations.get(alias);
78
+ if (inventory) await inventory.catch(() => {});
79
+ const declaredLength = Number(request.headers["content-length"] || 0);
80
+ if (Number.isFinite(declaredLength) && declaredLength > MAX_ATTACHMENT_BYTES) {
81
+ request.resume();
82
+ throw attachmentHttpError("单个附件不能超过 50 MiB", 413);
83
+ }
84
+
85
+ sshOperationCounts.set(alias, (sshOperationCounts.get(alias) || 0) + 1);
86
+ const child = spawn(
87
+ (typeof process !== "undefined" && process.platform === "win32" ? "ssh.exe" : "ssh"),
88
+ [
89
+ "-T",
90
+ "-o",
91
+ "BatchMode=yes",
92
+ "-o",
93
+ "StrictHostKeyChecking=yes",
94
+ "-o",
95
+ "ConnectionAttempts=1",
96
+ "-o",
97
+ `ConnectTimeout=${Math.ceil(SSH_TIMEOUT_MS / 1000)}`,
98
+ "--",
99
+ alias,
100
+ command,
101
+ ],
102
+ { windowsHide: true },
103
+ );
104
+ let stdout = "";
105
+ let stderr = "";
106
+ let size = 0;
107
+ let timedOut = false;
108
+ const hash = createHash("sha256");
109
+ child.stdout.on("data", (chunk) => {
110
+ if (stdout.length < 16_000) stdout += chunk.toString("utf8");
111
+ });
112
+ child.stderr.on("data", (chunk) => {
113
+ if (stderr.length < 32_000) stderr += chunk.toString("utf8");
114
+ });
115
+ // A remote disconnect can close stdin while the browser is still streaming.
116
+ // `once(..., "drain")` observes this error; this listener prevents an
117
+ // additional unhandled stream error when no backpressure wait is active.
118
+ child.stdin.on("error", () => {});
119
+ const closePromise = new Promise((resolve) => {
120
+ child.on("error", (error) => {
121
+ stderr += `\n${error.message}`;
122
+ });
123
+ child.on("close", (code) => resolve(code ?? 1));
124
+ });
125
+ const timer = setTimeout(() => {
126
+ timedOut = true;
127
+ child.kill();
128
+ }, ATTACHMENT_UPLOAD_TIMEOUT_MS);
129
+
130
+ let uploadError = null;
131
+ try {
132
+ for await (const chunk of request) {
133
+ size += chunk.length;
134
+ if (size > MAX_ATTACHMENT_BYTES) {
135
+ uploadError = attachmentHttpError("单个附件不能超过 50 MiB", 413);
136
+ request.resume();
137
+ break;
138
+ }
139
+ hash.update(chunk);
140
+ if (!child.stdin.write(chunk)) await once(child.stdin, "drain");
141
+ }
142
+ } catch (error) {
143
+ uploadError = error;
144
+ }
145
+ if (uploadError) {
146
+ child.stdin.destroy();
147
+ child.kill();
148
+ } else {
149
+ child.stdin.end();
150
+ }
151
+ const code = await closePromise;
152
+ clearTimeout(timer);
153
+ const remaining = Math.max(0, (sshOperationCounts.get(alias) || 1) - 1);
154
+ if (remaining) sshOperationCounts.set(alias, remaining);
155
+ else sshOperationCounts.delete(alias);
156
+
157
+ if (uploadError) throw uploadError;
158
+ if (timedOut) throw attachmentHttpError("附件上传超过 2 分钟", 504);
159
+ if (code !== 0) {
160
+ throw attachmentHttpError(
161
+ `远端附件写入失败:${cleanSshError(stderr || stdout)}`,
162
+ 502,
163
+ );
164
+ }
165
+ const pathLine = stdout
166
+ .split(/\r?\n/)
167
+ .find((line) => line.startsWith("SCOPE_UPLOAD_PATH="));
168
+ const remotePath = pathLine?.slice("SCOPE_UPLOAD_PATH=".length).trim() || "";
169
+ if (
170
+ !remotePath.startsWith("/") ||
171
+ !remotePath.includes("/.codex/scope-attachments/")
172
+ ) {
173
+ throw attachmentHttpError("远端没有返回有效的附件路径", 502);
174
+ }
175
+ return { remotePath, size, sha256: hash.digest("hex") };
176
+ }
177
+
178
+ return {
179
+ purgeExpiredAttachments,
180
+ storeUploadedAttachment,
181
+ resolveUploadedAttachments,
182
+ streamAttachmentToHost,
183
+ };
184
+ }
@@ -0,0 +1,58 @@
1
+ const DEFAULT_PROFILE_COOLDOWN_MS = 30 * 60_000;
2
+
3
+ export function orderedReadyProfileCandidates(
4
+ profiles,
5
+ activeSlug,
6
+ {
7
+ failedUntil = new Map(),
8
+ now = Date.now(),
9
+ } = {},
10
+ ) {
11
+ const ready = (Array.isArray(profiles) ? profiles : []).filter(
12
+ (profile) => profile?.ready && typeof profile.slug === "string" && profile.slug,
13
+ );
14
+ if (ready.length < 2) return [];
15
+ const activeIndex = ready.findIndex((profile) => profile.slug === activeSlug);
16
+ const rotationBase = activeIndex >= 0 ? activeIndex : -1;
17
+ const candidateCount = activeIndex >= 0 ? ready.length - 1 : ready.length;
18
+ const ordered = [];
19
+ for (let offset = 1; offset <= candidateCount; offset += 1) {
20
+ const index = (rotationBase + offset) % ready.length;
21
+ const profile = ready[index];
22
+ if (profile.slug === activeSlug) continue;
23
+ if (Number(failedUntil.get(profile.slug) || 0) > now) continue;
24
+ ordered.push(profile);
25
+ }
26
+ return ordered;
27
+ }
28
+
29
+ export function markProfileUnavailable(
30
+ failedUntil,
31
+ slug,
32
+ {
33
+ now = Date.now(),
34
+ cooldownMs = DEFAULT_PROFILE_COOLDOWN_MS,
35
+ } = {},
36
+ ) {
37
+ if (!(failedUntil instanceof Map) || !slug) return null;
38
+ const until = now + Math.max(1_000, Number(cooldownMs) || DEFAULT_PROFILE_COOLDOWN_MS);
39
+ failedUntil.set(slug, until);
40
+ return until;
41
+ }
42
+
43
+ export function publicProfileFailoverJob(job) {
44
+ if (!job) return null;
45
+ return {
46
+ host: job.host,
47
+ status: job.status,
48
+ failedProfile: job.failedProfile || null,
49
+ targetProfile: job.targetProfile || null,
50
+ interruptedSessions: Array.from(job.interruptedSessions || []),
51
+ waitingForSessions: Array.from(job.waitingForSessions || []),
52
+ attemptedProfiles: Array.from(job.attemptedProfiles || []),
53
+ nextAttemptAt: job.nextAttemptAt || null,
54
+ startedAt: job.startedAt,
55
+ completedAt: job.completedAt || null,
56
+ error: job.error || null,
57
+ };
58
+ }