@thevinci/web 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (337) hide show
  1. package/README.md +197 -0
  2. package/bin/cli-entry.js +55 -0
  3. package/bin/cli-output.js +145 -0
  4. package/bin/cli.js +4887 -0
  5. package/bin/cli.test.js +64 -0
  6. package/dist/apple-touch-icon-120x120.png +0 -0
  7. package/dist/apple-touch-icon-152x152.png +0 -0
  8. package/dist/apple-touch-icon-167x167.png +0 -0
  9. package/dist/apple-touch-icon-180x180.png +0 -0
  10. package/dist/apple-touch-icon.png +0 -0
  11. package/dist/apple-touch-icon.svg +528 -0
  12. package/dist/assets/JsonTreeView-CSm9OzXG.js +1 -0
  13. package/dist/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
  14. package/dist/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
  15. package/dist/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
  16. package/dist/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
  17. package/dist/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
  18. package/dist/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
  19. package/dist/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
  20. package/dist/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
  21. package/dist/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
  22. package/dist/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
  23. package/dist/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
  24. package/dist/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
  25. package/dist/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
  26. package/dist/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
  27. package/dist/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
  28. package/dist/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
  29. package/dist/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
  30. package/dist/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
  31. package/dist/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
  32. package/dist/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
  33. package/dist/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
  34. package/dist/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
  35. package/dist/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
  36. package/dist/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
  37. package/dist/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
  38. package/dist/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
  39. package/dist/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
  40. package/dist/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
  41. package/dist/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
  42. package/dist/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
  43. package/dist/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
  44. package/dist/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
  45. package/dist/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
  46. package/dist/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
  47. package/dist/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
  48. package/dist/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
  49. package/dist/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
  50. package/dist/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
  51. package/dist/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
  52. package/dist/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
  53. package/dist/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
  54. package/dist/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
  55. package/dist/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
  56. package/dist/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
  57. package/dist/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
  58. package/dist/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
  59. package/dist/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
  60. package/dist/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
  61. package/dist/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
  62. package/dist/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
  63. package/dist/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
  64. package/dist/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
  65. package/dist/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
  66. package/dist/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
  67. package/dist/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
  68. package/dist/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
  69. package/dist/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
  70. package/dist/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
  71. package/dist/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
  72. package/dist/assets/MarkdownRendererImpl-DensKOLc.js +6 -0
  73. package/dist/assets/MultiRunWindow-Bo7THayo.js +1 -0
  74. package/dist/assets/OnboardingScreen-BDqmzTVR.js +2 -0
  75. package/dist/assets/SettingsWindow-coz__Ykw.js +1 -0
  76. package/dist/assets/TerminalView-DrZ-i3Dr.js +1 -0
  77. package/dist/assets/ToolOutputDialog-Eglzslt3.js +16 -0
  78. package/dist/assets/es-4o9ciP61.js +15 -0
  79. package/dist/assets/ibm-plex-mono-latin-400-normal-CvHOgSBP.woff +0 -0
  80. package/dist/assets/ibm-plex-mono-latin-400-normal-DMJ8VG8y.woff2 +0 -0
  81. package/dist/assets/ibm-plex-mono-latin-500-normal-CB9ihrfo.woff +0 -0
  82. package/dist/assets/ibm-plex-mono-latin-500-normal-DSY6xOcd.woff2 +0 -0
  83. package/dist/assets/ibm-plex-mono-latin-600-normal-BgSNZQsw.woff2 +0 -0
  84. package/dist/assets/ibm-plex-mono-latin-600-normal-DWFSQ4vo.woff +0 -0
  85. package/dist/assets/ibm-plex-sans-latin-400-normal-CDDApCn2.woff2 +0 -0
  86. package/dist/assets/ibm-plex-sans-latin-400-normal-CYLoc0-x.woff +0 -0
  87. package/dist/assets/ibm-plex-sans-latin-500-normal-6ng42L7E.woff2 +0 -0
  88. package/dist/assets/ibm-plex-sans-latin-500-normal-BgVn5rGT.woff +0 -0
  89. package/dist/assets/ibm-plex-sans-latin-600-normal-Cu4Hd6ag.woff +0 -0
  90. package/dist/assets/ibm-plex-sans-latin-600-normal-CuJfVYMP.woff2 +0 -0
  91. package/dist/assets/index-DLTDToSP.css +1 -0
  92. package/dist/assets/index-DgiFEKGN.js +1 -0
  93. package/dist/assets/ko-B20imCHE.js +15 -0
  94. package/dist/assets/main-BV3KOtdA.css +1 -0
  95. package/dist/assets/main-CDKJj0sH.js +226 -0
  96. package/dist/assets/main-LC-PSNVM.js +2 -0
  97. package/dist/assets/miniChat-CQUiG_cr.js +2 -0
  98. package/dist/assets/modelPrefsAutoSave-Dm799vzR.js +6986 -0
  99. package/dist/assets/pl-DQJ7LSzj.js +15 -0
  100. package/dist/assets/pt-BR-OmjHUz9y.js +15 -0
  101. package/dist/assets/renderElectronMiniChatApp-CARbeW0G.js +2 -0
  102. package/dist/assets/uk-BNFxOlO4.js +15 -0
  103. package/dist/assets/vendor--DBfsbEis.css +1 -0
  104. package/dist/assets/vendor-.bun-B9l0ZNi2.js +4094 -0
  105. package/dist/assets/wasm-CG6Dc4jp.js +1 -0
  106. package/dist/assets/wasmSttWorker-Dtlxac_K.js +1 -0
  107. package/dist/assets/wasmSttWorker-oo7Dm_jy.js +1806 -0
  108. package/dist/assets/worker-CbT6TVo7.js +155 -0
  109. package/dist/assets/zh-CN-C6T-Ac7F.js +15 -0
  110. package/dist/favicon-16.png +0 -0
  111. package/dist/favicon-32.png +0 -0
  112. package/dist/favicon.png +0 -0
  113. package/dist/favicon.svg +528 -0
  114. package/dist/index.html +607 -0
  115. package/dist/logo-dark-192x192.png +0 -0
  116. package/dist/logo-dark-512x512.png +0 -0
  117. package/dist/logo-dark-512x512.svg +528 -0
  118. package/dist/logo-light-192x192.png +0 -0
  119. package/dist/logo-light-512x512.png +0 -0
  120. package/dist/logo-light-512x512.svg +528 -0
  121. package/dist/mini-chat.html +16 -0
  122. package/dist/pwa-192.png +0 -0
  123. package/dist/pwa-512.png +0 -0
  124. package/dist/pwa-maskable-192.png +0 -0
  125. package/dist/pwa-maskable-512.png +0 -0
  126. package/dist/site.webmanifest +21 -0
  127. package/dist/sw.js +1 -0
  128. package/package.json +118 -0
  129. package/public/apple-touch-icon-120x120.png +0 -0
  130. package/public/apple-touch-icon-152x152.png +0 -0
  131. package/public/apple-touch-icon-167x167.png +0 -0
  132. package/public/apple-touch-icon-180x180.png +0 -0
  133. package/public/apple-touch-icon.png +0 -0
  134. package/public/apple-touch-icon.svg +528 -0
  135. package/public/favicon-16.png +0 -0
  136. package/public/favicon-32.png +0 -0
  137. package/public/favicon.png +0 -0
  138. package/public/favicon.svg +528 -0
  139. package/public/logo-dark-192x192.png +0 -0
  140. package/public/logo-dark-512x512.png +0 -0
  141. package/public/logo-dark-512x512.svg +528 -0
  142. package/public/logo-light-192x192.png +0 -0
  143. package/public/logo-light-512x512.png +0 -0
  144. package/public/logo-light-512x512.svg +528 -0
  145. package/public/pwa-192.png +0 -0
  146. package/public/pwa-512.png +0 -0
  147. package/public/pwa-maskable-192.png +0 -0
  148. package/public/pwa-maskable-512.png +0 -0
  149. package/public/site.webmanifest +21 -0
  150. package/server/TERMINAL_WS_PROTOCOL.md +48 -0
  151. package/server/index.d.ts +39 -0
  152. package/server/index.js +1311 -0
  153. package/server/lib/cloudflare-tunnel.js +650 -0
  154. package/server/lib/event-stream/DOCUMENTATION.md +61 -0
  155. package/server/lib/event-stream/directory-ws-bridge.js +185 -0
  156. package/server/lib/event-stream/global-hub.js +158 -0
  157. package/server/lib/event-stream/global-hub.test.js +140 -0
  158. package/server/lib/event-stream/global-ws-bridge.js +206 -0
  159. package/server/lib/event-stream/index.js +25 -0
  160. package/server/lib/event-stream/protocol.js +131 -0
  161. package/server/lib/event-stream/protocol.test.js +182 -0
  162. package/server/lib/event-stream/runtime.js +180 -0
  163. package/server/lib/event-stream/runtime.test.js +512 -0
  164. package/server/lib/event-stream/upstream-reader.js +226 -0
  165. package/server/lib/event-stream/upstream-reader.test.js +276 -0
  166. package/server/lib/fs/DOCUMENTATION.md +36 -0
  167. package/server/lib/fs/routes.js +1040 -0
  168. package/server/lib/fs/search.js +238 -0
  169. package/server/lib/git/DOCUMENTATION.md +152 -0
  170. package/server/lib/git/credentials.js +74 -0
  171. package/server/lib/git/identity-storage.js +112 -0
  172. package/server/lib/git/index.js +6 -0
  173. package/server/lib/git/routes.js +972 -0
  174. package/server/lib/git/service.js +3432 -0
  175. package/server/lib/git/service.test.js +39 -0
  176. package/server/lib/github/DOCUMENTATION.md +171 -0
  177. package/server/lib/github/auth.js +307 -0
  178. package/server/lib/github/device-flow.js +50 -0
  179. package/server/lib/github/index.js +24 -0
  180. package/server/lib/github/octokit.js +10 -0
  181. package/server/lib/github/pr-status.js +519 -0
  182. package/server/lib/github/repo/fork-detection.js +102 -0
  183. package/server/lib/github/repo/index.js +55 -0
  184. package/server/lib/github/routes.js +1560 -0
  185. package/server/lib/magic-prompts/routes.js +63 -0
  186. package/server/lib/magic-prompts/runtime.js +119 -0
  187. package/server/lib/notifications/DOCUMENTATION.md +122 -0
  188. package/server/lib/notifications/emitter-runtime.js +102 -0
  189. package/server/lib/notifications/index.js +4 -0
  190. package/server/lib/notifications/message.js +52 -0
  191. package/server/lib/notifications/message.test.js +34 -0
  192. package/server/lib/notifications/push-runtime.js +304 -0
  193. package/server/lib/notifications/routes.js +315 -0
  194. package/server/lib/notifications/runtime.js +566 -0
  195. package/server/lib/notifications/template-runtime.js +349 -0
  196. package/server/lib/notifications/template-runtime.test.js +26 -0
  197. package/server/lib/opencode/DOCUMENTATION.md +362 -0
  198. package/server/lib/opencode/agents.js +634 -0
  199. package/server/lib/opencode/auth-state-runtime.js +88 -0
  200. package/server/lib/opencode/auth.js +83 -0
  201. package/server/lib/opencode/bootstrap-runtime.js +131 -0
  202. package/server/lib/opencode/cli-entry-runtime.js +43 -0
  203. package/server/lib/opencode/cli-options.js +128 -0
  204. package/server/lib/opencode/commands.js +339 -0
  205. package/server/lib/opencode/config-entity-routes.js +370 -0
  206. package/server/lib/opencode/core-routes.js +500 -0
  207. package/server/lib/opencode/core-routes.test.js +26 -0
  208. package/server/lib/opencode/env-config.js +74 -0
  209. package/server/lib/opencode/env-keys.js +68 -0
  210. package/server/lib/opencode/env-runtime.js +1162 -0
  211. package/server/lib/opencode/env-runtime.test.js +116 -0
  212. package/server/lib/opencode/feature-routes-runtime.js +244 -0
  213. package/server/lib/opencode/hmr-state-runtime.js +85 -0
  214. package/server/lib/opencode/index.js +66 -0
  215. package/server/lib/opencode/lifecycle.js +1019 -0
  216. package/server/lib/opencode/lifecycle.test.js +240 -0
  217. package/server/lib/opencode/mcp.js +278 -0
  218. package/server/lib/opencode/network-runtime.js +104 -0
  219. package/server/lib/opencode/network-runtime.test.js +37 -0
  220. package/server/lib/opencode/opencode-resolution-runtime.js +71 -0
  221. package/server/lib/opencode/path-utils.js +100 -0
  222. package/server/lib/opencode/path-utils.test.js +71 -0
  223. package/server/lib/opencode/project-directory-runtime.js +124 -0
  224. package/server/lib/opencode/project-icon-routes.js +399 -0
  225. package/server/lib/opencode/project-icon-routes.test.js +107 -0
  226. package/server/lib/opencode/providers.js +96 -0
  227. package/server/lib/opencode/proxy.js +445 -0
  228. package/server/lib/opencode/pwa-manifest-routes.js +257 -0
  229. package/server/lib/opencode/pwa-manifest-routes.test.js +133 -0
  230. package/server/lib/opencode/routes.js +541 -0
  231. package/server/lib/opencode/server-startup-runtime.js +156 -0
  232. package/server/lib/opencode/server-utils-runtime.js +168 -0
  233. package/server/lib/opencode/server-utils-runtime.test.js +135 -0
  234. package/server/lib/opencode/session-runtime.js +356 -0
  235. package/server/lib/opencode/session-runtime.test.js +151 -0
  236. package/server/lib/opencode/settings-helpers.js +770 -0
  237. package/server/lib/opencode/settings-helpers.test.js +109 -0
  238. package/server/lib/opencode/settings-normalization-runtime.js +428 -0
  239. package/server/lib/opencode/settings-runtime.js +826 -0
  240. package/server/lib/opencode/settings-runtime.test.js +85 -0
  241. package/server/lib/opencode/shared.js +615 -0
  242. package/server/lib/opencode/shutdown-runtime.js +139 -0
  243. package/server/lib/opencode/shutdown-runtime.test.js +58 -0
  244. package/server/lib/opencode/skill-routes.js +701 -0
  245. package/server/lib/opencode/skills.js +548 -0
  246. package/server/lib/opencode/startup-pipeline-runtime.js +130 -0
  247. package/server/lib/opencode/static-routes-runtime.js +65 -0
  248. package/server/lib/opencode/theme-runtime.js +167 -0
  249. package/server/lib/opencode/tunnel-auth.js +591 -0
  250. package/server/lib/opencode/tunnel-wiring-runtime.js +94 -0
  251. package/server/lib/opencode/vinci-routes.js +76 -0
  252. package/server/lib/opencode/watcher.js +115 -0
  253. package/server/lib/opencode/watcher.test.js +239 -0
  254. package/server/lib/preview/proxy-runtime.js +1333 -0
  255. package/server/lib/preview/proxy-runtime.test.js +144 -0
  256. package/server/lib/projects/project-config.js +567 -0
  257. package/server/lib/projects/project-config.test.js +175 -0
  258. package/server/lib/projects/project-id.js +13 -0
  259. package/server/lib/quota/DOCUMENTATION.md +58 -0
  260. package/server/lib/quota/index.js +25 -0
  261. package/server/lib/quota/providers/claude.js +107 -0
  262. package/server/lib/quota/providers/codex.js +113 -0
  263. package/server/lib/quota/providers/copilot.js +165 -0
  264. package/server/lib/quota/providers/google/api.js +92 -0
  265. package/server/lib/quota/providers/google/auth.js +108 -0
  266. package/server/lib/quota/providers/google/index.js +124 -0
  267. package/server/lib/quota/providers/google/transforms.js +109 -0
  268. package/server/lib/quota/providers/index.js +168 -0
  269. package/server/lib/quota/providers/interface.js +55 -0
  270. package/server/lib/quota/providers/kimi.js +108 -0
  271. package/server/lib/quota/providers/minimax-cn-coding-plan.js +140 -0
  272. package/server/lib/quota/providers/minimax-coding-plan.js +139 -0
  273. package/server/lib/quota/providers/nanogpt.js +124 -0
  274. package/server/lib/quota/providers/ollama-cloud.js +112 -0
  275. package/server/lib/quota/providers/openai.js +91 -0
  276. package/server/lib/quota/providers/openrouter.js +92 -0
  277. package/server/lib/quota/providers/zai.js +91 -0
  278. package/server/lib/quota/providers/zhipuai-coding-plan.js +133 -0
  279. package/server/lib/quota/providers/zhipuai.js +114 -0
  280. package/server/lib/quota/routes.js +27 -0
  281. package/server/lib/quota/utils/auth.js +50 -0
  282. package/server/lib/quota/utils/formatters.js +85 -0
  283. package/server/lib/quota/utils/formatters.test.js +54 -0
  284. package/server/lib/quota/utils/index.js +10 -0
  285. package/server/lib/quota/utils/transformers.js +55 -0
  286. package/server/lib/scheduled-tasks/DOCUMENTATION.md +44 -0
  287. package/server/lib/scheduled-tasks/routes.js +235 -0
  288. package/server/lib/scheduled-tasks/runtime.js +773 -0
  289. package/server/lib/scheduled-tasks/runtime.test.js +100 -0
  290. package/server/lib/security/request-security.js +115 -0
  291. package/server/lib/session-folders/routes.js +63 -0
  292. package/server/lib/session-folders/routes.test.js +102 -0
  293. package/server/lib/skills-catalog/DOCUMENTATION.md +178 -0
  294. package/server/lib/skills-catalog/cache.js +29 -0
  295. package/server/lib/skills-catalog/clawdhub/api.js +158 -0
  296. package/server/lib/skills-catalog/clawdhub/index.js +30 -0
  297. package/server/lib/skills-catalog/clawdhub/install.js +238 -0
  298. package/server/lib/skills-catalog/clawdhub/scan.js +113 -0
  299. package/server/lib/skills-catalog/curated-sources.js +21 -0
  300. package/server/lib/skills-catalog/git.js +77 -0
  301. package/server/lib/skills-catalog/index.js +42 -0
  302. package/server/lib/skills-catalog/install.js +294 -0
  303. package/server/lib/skills-catalog/scan.js +221 -0
  304. package/server/lib/skills-catalog/source.js +87 -0
  305. package/server/lib/terminal/DOCUMENTATION.md +76 -0
  306. package/server/lib/terminal/index.js +31 -0
  307. package/server/lib/terminal/output-replay-buffer.js +78 -0
  308. package/server/lib/terminal/output-replay-buffer.test.js +75 -0
  309. package/server/lib/terminal/runtime.js +850 -0
  310. package/server/lib/terminal/runtime.test.js +96 -0
  311. package/server/lib/terminal/terminal-ws-protocol.js +68 -0
  312. package/server/lib/terminal/terminal-ws-protocol.test.js +145 -0
  313. package/server/lib/text/DOCUMENTATION.md +35 -0
  314. package/server/lib/text/summarization.js +138 -0
  315. package/server/lib/text/summarization.test.js +34 -0
  316. package/server/lib/tts/DOCUMENTATION.md +146 -0
  317. package/server/lib/tts/base-url.js +62 -0
  318. package/server/lib/tts/capability-runtime.js +31 -0
  319. package/server/lib/tts/index.js +19 -0
  320. package/server/lib/tts/routes.js +261 -0
  321. package/server/lib/tts/routes.test.js +53 -0
  322. package/server/lib/tts/service.js +178 -0
  323. package/server/lib/tts/stt.js +75 -0
  324. package/server/lib/tunnels/DOCUMENTATION.md +18 -0
  325. package/server/lib/tunnels/index.js +166 -0
  326. package/server/lib/tunnels/managed-config.js +201 -0
  327. package/server/lib/tunnels/providers/cloudflare.js +260 -0
  328. package/server/lib/tunnels/registry.js +51 -0
  329. package/server/lib/tunnels/routes.js +605 -0
  330. package/server/lib/tunnels/types.js +219 -0
  331. package/server/lib/ui-auth/DOCUMENTATION.md +38 -0
  332. package/server/lib/ui-auth/ui-auth.js +673 -0
  333. package/server/lib/ui-auth/ui-passkeys.js +545 -0
  334. package/server/opencode-proxy.test.js +151 -0
  335. package/server/proxy-headers.js +61 -0
  336. package/server/proxy-headers.test.js +58 -0
  337. package/server/sse-routes.test.js +152 -0
@@ -0,0 +1,650 @@
1
+ import { spawn, spawnSync } from 'child_process';
2
+ import fs from 'fs';
3
+ import os from 'os';
4
+ import path from 'path';
5
+ import { fileURLToPath } from 'url';
6
+ import yaml from 'yaml';
7
+
8
+ const __filename = fileURLToPath(import.meta.url);
9
+ const __dirname = path.dirname(__filename);
10
+
11
+ const TRY_CF_URL_REGEX = /https:\/\/[a-z0-9-]+\.trycloudflare\.com/i;
12
+
13
+ const DEFAULT_STARTUP_TIMEOUT_MS = 30000;
14
+ const MANAGED_TUNNEL_STARTUP_TIMEOUT_MS = 20000;
15
+ const MANAGED_TUNNEL_LIVENESS_FALLBACK_MS = 6000;
16
+ const TUNNEL_MODE_QUICK = 'quick';
17
+ const TUNNEL_MODE_MANAGED_REMOTE = 'managed-remote';
18
+ const TUNNEL_MODE_MANAGED_LOCAL = 'managed-local';
19
+
20
+ async function searchPathFor(command) {
21
+ const pathValue = process.env.PATH || '';
22
+ const segments = pathValue.split(path.delimiter).filter(Boolean);
23
+ const WINDOWS_EXTENSIONS = process.platform === 'win32'
24
+ ? (process.env.PATHEXT || '.EXE;.CMD;.BAT;.COM')
25
+ .split(';')
26
+ .map((ext) => ext.trim().toLowerCase())
27
+ .filter(Boolean)
28
+ .map((ext) => (ext.startsWith('.') ? ext : `.${ext}`))
29
+ : [''];
30
+
31
+ for (const dir of segments) {
32
+ for (const ext of WINDOWS_EXTENSIONS) {
33
+ const fileName = process.platform === 'win32' ? `${command}${ext}` : command;
34
+ const candidate = path.join(dir, fileName);
35
+ try {
36
+ const stats = fs.statSync(candidate);
37
+ if (stats.isFile()) {
38
+ if (process.platform !== 'win32') {
39
+ try {
40
+ fs.accessSync(candidate, fs.constants.X_OK);
41
+ } catch {
42
+ continue;
43
+ }
44
+ }
45
+ return candidate;
46
+ }
47
+ } catch {
48
+ continue;
49
+ }
50
+ }
51
+ }
52
+ return null;
53
+ }
54
+
55
+ export async function checkCloudflaredAvailable() {
56
+ const cfPath = await searchPathFor('cloudflared');
57
+ if (cfPath) {
58
+ try {
59
+ const result = spawnSync(cfPath, ['--version'], {
60
+ encoding: 'utf8',
61
+ stdio: ['pipe', 'pipe', 'pipe'],
62
+ windowsHide: true,
63
+ });
64
+ if (result.status === 0) {
65
+ return { available: true, path: cfPath, version: result.stdout.trim() };
66
+ }
67
+ } catch {
68
+ // Ignore
69
+ }
70
+ }
71
+ return { available: false, path: null, version: null };
72
+ }
73
+
74
+ export function printCloudflareTunnelInstallHelp() {
75
+ const platform = process.platform;
76
+ let installCmd = '';
77
+
78
+ if (platform === 'darwin') {
79
+ installCmd = 'brew install cloudflared';
80
+ } else if (platform === 'win32') {
81
+ installCmd = 'winget install --id Cloudflare.cloudflared';
82
+ } else {
83
+ installCmd = 'Download from https://github.com/cloudflare/cloudflared/releases';
84
+ }
85
+
86
+ console.log(`
87
+ ╔══════════════════════════════════════════════════════════════════╗
88
+ ║ Cloudflare tunnel requires 'cloudflared' to be installed ║
89
+ ╚══════════════════════════════════════════════════════════════════╝
90
+
91
+ Install instructions for your platform:
92
+
93
+ macOS: brew install cloudflared
94
+ Windows: winget install --id Cloudflare.cloudflared
95
+ Linux: Download from https://github.com/cloudflare/cloudflared/releases
96
+
97
+ Or visit: https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflared/downloads/
98
+ `);
99
+ }
100
+
101
+ const spawnCloudflared = (args, envOverrides = {}, resolvedBinaryPath = 'cloudflared') => spawn(resolvedBinaryPath, args, {
102
+ stdio: ['ignore', 'pipe', 'pipe'],
103
+ windowsHide: true,
104
+ env: {
105
+ ...process.env,
106
+ CF_TELEMETRY_DISABLE: '1',
107
+ ...envOverrides,
108
+ },
109
+ killSignal: 'SIGINT',
110
+ });
111
+
112
+ const normalizeHostname = (value) => {
113
+ if (typeof value !== 'string') {
114
+ return null;
115
+ }
116
+ const trimmed = value.trim();
117
+ if (!trimmed) {
118
+ return null;
119
+ }
120
+ try {
121
+ const parsed = trimmed.includes('://') ? new URL(trimmed) : new URL(`https://${trimmed}`);
122
+ const hostname = parsed.hostname.trim().toLowerCase();
123
+ if (!hostname || hostname.includes('*')) {
124
+ return null;
125
+ }
126
+ return hostname;
127
+ } catch {
128
+ return null;
129
+ }
130
+ };
131
+
132
+ export function normalizeCloudflareTunnelHostname(value) {
133
+ return normalizeHostname(value);
134
+ }
135
+
136
+ export async function checkCloudflareApiReachability({ fetchImpl = globalThis.fetch, timeoutMs = 5000 } = {}) {
137
+ if (typeof fetchImpl !== 'function') {
138
+ return {
139
+ reachable: false,
140
+ status: null,
141
+ error: 'Fetch API is unavailable in this runtime.',
142
+ };
143
+ }
144
+
145
+ const controller = new AbortController();
146
+ const timeout = setTimeout(() => controller.abort(), timeoutMs);
147
+ try {
148
+ const response = await fetchImpl('https://api.trycloudflare.com/', {
149
+ method: 'GET',
150
+ signal: controller.signal,
151
+ });
152
+ return {
153
+ reachable: true,
154
+ status: response.status,
155
+ error: null,
156
+ };
157
+ } catch (error) {
158
+ const message = error instanceof Error ? error.message : String(error);
159
+ return {
160
+ reachable: false,
161
+ status: null,
162
+ error: message,
163
+ };
164
+ } finally {
165
+ clearTimeout(timeout);
166
+ }
167
+ }
168
+
169
+ const READY_LOG_PATTERNS = [
170
+ /registered tunnel connection/i,
171
+ /connection[^\n]*registered/i,
172
+ /starting metrics server/i,
173
+ /connected to edge/i,
174
+ ];
175
+
176
+ const MANAGED_LOCAL_CONFIG_MAX_BYTES = 256 * 1024;
177
+ const MANAGED_LOCAL_CONFIG_ALLOWED_EXTENSIONS = new Set(['.yml', '.yaml', '.json']);
178
+
179
+ const FATAL_LOG_PATTERNS = [
180
+ /error parsing.*config/i,
181
+ /failed to .*config/i,
182
+ /invalid token/i,
183
+ /unauthorized/i,
184
+ /credentials file .* not found/i,
185
+ /provided tunnel credentials are invalid/i,
186
+ ];
187
+
188
+ function isCloudflaredReadyLogLine(line) {
189
+ if (!line) {
190
+ return false;
191
+ }
192
+ return READY_LOG_PATTERNS.some((pattern) => pattern.test(line));
193
+ }
194
+
195
+ function isCloudflaredFatalLogLine(line) {
196
+ if (!line) {
197
+ return false;
198
+ }
199
+ return FATAL_LOG_PATTERNS.some((pattern) => pattern.test(line));
200
+ }
201
+
202
+ function assertReadableFile(filePath, contextLabel) {
203
+ let stats;
204
+ try {
205
+ stats = fs.statSync(filePath);
206
+ } catch {
207
+ throw new Error(`${contextLabel} file was not found. Select a valid cloudflared config file.`);
208
+ }
209
+
210
+ if (!stats.isFile()) {
211
+ throw new Error(`${contextLabel} path is not a file. Select a cloudflared config file.`);
212
+ }
213
+
214
+ const extension = path.extname(filePath).toLowerCase();
215
+ if (!MANAGED_LOCAL_CONFIG_ALLOWED_EXTENSIONS.has(extension)) {
216
+ throw new Error(`${contextLabel} must be a .yml, .yaml, or .json file.`);
217
+ }
218
+
219
+ if (stats.size <= 0) {
220
+ throw new Error(`${contextLabel} file is empty.`);
221
+ }
222
+ if (stats.size > MANAGED_LOCAL_CONFIG_MAX_BYTES) {
223
+ throw new Error(`${contextLabel} file is too large (max ${MANAGED_LOCAL_CONFIG_MAX_BYTES} bytes).`);
224
+ }
225
+
226
+ try {
227
+ fs.accessSync(filePath, fs.constants.R_OK);
228
+ } catch {
229
+ throw new Error(`${contextLabel} file is not readable. Check file permissions and try again.`);
230
+ }
231
+ }
232
+
233
+ function extractHostnameFromCloudflaredConfigDetailed(configPath) {
234
+ if (typeof configPath !== 'string' || configPath.trim().length === 0) {
235
+ return { hostname: null, parseError: null };
236
+ }
237
+
238
+ let raw;
239
+ try {
240
+ raw = fs.readFileSync(configPath, 'utf8');
241
+ } catch {
242
+ return {
243
+ hostname: null,
244
+ parseError: new Error('Could not read the managed local tunnel config file. Check that the file exists and is accessible.'),
245
+ };
246
+ }
247
+
248
+ let parsed;
249
+ try {
250
+ parsed = yaml.parse(raw);
251
+ } catch {
252
+ return {
253
+ hostname: null,
254
+ parseError: new Error('Managed local tunnel config is invalid. Use a valid cloudflared YAML/JSON config file.'),
255
+ };
256
+ }
257
+
258
+ const ingress = Array.isArray(parsed?.ingress) ? parsed.ingress : [];
259
+ for (const rule of ingress) {
260
+ const hostname = normalizeHostname(rule?.hostname);
261
+ if (hostname) {
262
+ return { hostname, parseError: null };
263
+ }
264
+ }
265
+
266
+ return { hostname: null, parseError: null };
267
+ }
268
+
269
+ const extractHostnameFromCloudflaredConfig = (configPath) => {
270
+ return extractHostnameFromCloudflaredConfigDetailed(configPath).hostname;
271
+ };
272
+
273
+ const getDefaultCloudflaredConfigPath = () => path.join(os.homedir(), '.cloudflared', 'config.yml');
274
+
275
+ export function inspectManagedLocalCloudflareConfig({ configPath, hostname } = {}) {
276
+ const requestedPath = typeof configPath === 'string' ? configPath.trim() : '';
277
+ const effectiveConfigPath = requestedPath || getDefaultCloudflaredConfigPath();
278
+
279
+ try {
280
+ if (requestedPath) {
281
+ assertReadableFile(effectiveConfigPath, 'Managed local tunnel config');
282
+ } else {
283
+ assertReadableFile(effectiveConfigPath, 'Managed local tunnel default config');
284
+ }
285
+ } catch (error) {
286
+ return {
287
+ ok: false,
288
+ effectiveConfigPath,
289
+ resolvedHostname: null,
290
+ error: error instanceof Error ? error.message : String(error),
291
+ };
292
+ }
293
+
294
+ const configHostnameResult = extractHostnameFromCloudflaredConfigDetailed(effectiveConfigPath);
295
+ if (configHostnameResult.parseError) {
296
+ return {
297
+ ok: false,
298
+ effectiveConfigPath,
299
+ resolvedHostname: null,
300
+ error: configHostnameResult.parseError.message,
301
+ };
302
+ }
303
+
304
+ const resolvedHostname = normalizeHostname(hostname) || configHostnameResult.hostname;
305
+ if (!resolvedHostname) {
306
+ return {
307
+ ok: false,
308
+ effectiveConfigPath,
309
+ resolvedHostname: null,
310
+ error: 'Managed local tunnel hostname is required (set --hostname or include ingress hostname in config).',
311
+ };
312
+ }
313
+
314
+ return {
315
+ ok: true,
316
+ effectiveConfigPath,
317
+ resolvedHostname,
318
+ error: null,
319
+ };
320
+ }
321
+
322
+ async function waitForManagedTunnelReady(child, { modeLabel }) {
323
+ await new Promise((resolve, reject) => {
324
+ let settled = false;
325
+ let sawOutput = false;
326
+
327
+ const finish = (handler, value) => {
328
+ if (settled) {
329
+ return;
330
+ }
331
+ settled = true;
332
+ clearTimeout(fallbackTimer);
333
+ clearTimeout(hardTimeout);
334
+ child.stdout?.off('data', onStdout);
335
+ child.stderr?.off('data', onStderr);
336
+ child.off('exit', onExit);
337
+ handler(value);
338
+ };
339
+
340
+ const inspectChunk = (chunk) => {
341
+ const text = chunk.toString('utf8');
342
+ if (text.trim().length > 0) {
343
+ sawOutput = true;
344
+ }
345
+ const lines = text.split(/\r?\n/).map((line) => line.trim()).filter(Boolean);
346
+ for (const line of lines) {
347
+ if (isCloudflaredReadyLogLine(line)) {
348
+ finish(resolve, null);
349
+ return;
350
+ }
351
+ if (isCloudflaredFatalLogLine(line)) {
352
+ finish(reject, new Error(`Cloudflared failed to start ${modeLabel}: ${line}`));
353
+ return;
354
+ }
355
+ }
356
+ };
357
+
358
+ const onStdout = (chunk) => {
359
+ inspectChunk(chunk);
360
+ };
361
+
362
+ const onStderr = (chunk) => {
363
+ inspectChunk(chunk);
364
+ };
365
+
366
+ const onExit = (code) => {
367
+ finish(reject, new Error(`Cloudflared exited while starting ${modeLabel} (code ${code ?? 'unknown'})`));
368
+ };
369
+
370
+ child.stdout?.on('data', onStdout);
371
+ child.stderr?.on('data', onStderr);
372
+ child.once('exit', onExit);
373
+
374
+ const fallbackTimer = setTimeout(() => {
375
+ if (sawOutput) {
376
+ finish(resolve, null);
377
+ }
378
+ }, MANAGED_TUNNEL_LIVENESS_FALLBACK_MS);
379
+
380
+ const hardTimeout = setTimeout(() => {
381
+ finish(reject, new Error(`Timed out waiting for cloudflared to initialize ${modeLabel}. Check your tunnel config and credentials.`));
382
+ }, MANAGED_TUNNEL_STARTUP_TIMEOUT_MS);
383
+ });
384
+ }
385
+
386
+ export async function startCloudflareQuickTunnel({ originUrl }) {
387
+ const cfCheck = await checkCloudflaredAvailable();
388
+
389
+ if (!cfCheck.available) {
390
+ printCloudflareTunnelInstallHelp();
391
+ throw new Error('cloudflared is not installed');
392
+ }
393
+
394
+ console.log(`Using cloudflared: ${cfCheck.path} (${cfCheck.version})`);
395
+
396
+ const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'vinci-cf-'));
397
+
398
+ const child = spawnCloudflared(['tunnel', '--url', originUrl], { HOME: tempDir }, cfCheck.path);
399
+
400
+ let publicUrl = null;
401
+ let tunnelReady = false;
402
+
403
+ const onData = (chunk, isStderr) => {
404
+ const text = chunk.toString('utf8');
405
+
406
+ if (!tunnelReady) {
407
+ const match = text.match(TRY_CF_URL_REGEX);
408
+ if (match) {
409
+ publicUrl = match[0];
410
+ tunnelReady = true;
411
+ }
412
+ }
413
+
414
+ process.stderr.write(isStderr ? text : '');
415
+ };
416
+
417
+ child.stdout.on('data', (chunk) => onData(chunk, false));
418
+ child.stderr.on('data', (chunk) => onData(chunk, true));
419
+
420
+ child.on('error', (error) => {
421
+ console.error(`Cloudflared error: ${error.message}`);
422
+ cleanupTempDir();
423
+ });
424
+
425
+ const cleanupTempDir = () => {
426
+ try {
427
+ if (fs.existsSync(tempDir)) {
428
+ fs.rmSync(tempDir, { recursive: true, force: true });
429
+ }
430
+ } catch {
431
+ // Ignore cleanup errors
432
+ }
433
+ };
434
+
435
+ await new Promise((resolve, reject) => {
436
+ const timeout = setTimeout(() => {
437
+ if (!publicUrl) {
438
+ try { child.kill('SIGINT'); } catch { /* ignore */ }
439
+ cleanupTempDir();
440
+ reject(new Error('Tunnel URL not received within 30 seconds'));
441
+ }
442
+ }, DEFAULT_STARTUP_TIMEOUT_MS);
443
+
444
+ const checkReady = setInterval(() => {
445
+ if (publicUrl) {
446
+ clearTimeout(timeout);
447
+ clearInterval(checkReady);
448
+ resolve(null);
449
+ }
450
+ }, 100);
451
+
452
+ child.on('exit', (code) => {
453
+ clearTimeout(timeout);
454
+ clearInterval(checkReady);
455
+ cleanupTempDir();
456
+ if (code !== null && code !== 0) {
457
+ reject(new Error(`Cloudflared exited with code ${code}`));
458
+ }
459
+ });
460
+ });
461
+
462
+ return {
463
+ mode: TUNNEL_MODE_QUICK,
464
+ stop: () => {
465
+ try {
466
+ child.kill('SIGINT');
467
+ } catch {
468
+ // Ignore
469
+ }
470
+ },
471
+ process: child,
472
+ getPublicUrl: () => publicUrl,
473
+ };
474
+ }
475
+
476
+ export async function startCloudflareManagedRemoteTunnel({ token, hostname, tokenFilePath }) {
477
+ const cfCheck = await checkCloudflaredAvailable();
478
+
479
+ if (!cfCheck.available) {
480
+ printCloudflareTunnelInstallHelp();
481
+ throw new Error('cloudflared is not installed');
482
+ }
483
+
484
+ const normalizedToken = typeof token === 'string' ? token.trim() : '';
485
+ const normalizedHost = typeof hostname === 'string' ? hostname.trim().toLowerCase() : '';
486
+
487
+ if (!normalizedToken) {
488
+ throw new Error('Managed remote tunnel token is required');
489
+ }
490
+ if (!normalizedHost) {
491
+ throw new Error('Managed remote tunnel hostname is required');
492
+ }
493
+
494
+ let effectiveTokenFilePath = typeof tokenFilePath === 'string' ? tokenFilePath : null;
495
+ let tempTokenFile = null;
496
+
497
+ if (!effectiveTokenFilePath) {
498
+ const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'vinci-cf-token-'));
499
+ effectiveTokenFilePath = path.join(tempDir, 'token');
500
+ fs.writeFileSync(effectiveTokenFilePath, normalizedToken, { encoding: 'utf8', mode: 0o600 });
501
+ tempTokenFile = { dir: tempDir, path: effectiveTokenFilePath };
502
+ }
503
+
504
+ const child = spawnCloudflared(['tunnel', 'run', '--token-file', effectiveTokenFilePath], {}, cfCheck.path);
505
+ const publicUrl = `https://${normalizedHost}`;
506
+
507
+ child.stdout.on('data', () => {
508
+ // Keep stream drained, but avoid logging potentially sensitive output.
509
+ });
510
+
511
+ child.stderr.on('data', (chunk) => {
512
+ const text = chunk.toString('utf8');
513
+ process.stderr.write(text);
514
+ });
515
+
516
+ const cleanupTempTokenFile = () => {
517
+ if (tempTokenFile) {
518
+ try {
519
+ if (fs.existsSync(tempTokenFile.dir)) {
520
+ fs.rmSync(tempTokenFile.dir, { recursive: true, force: true });
521
+ }
522
+ } catch {
523
+ // Ignore cleanup errors
524
+ }
525
+ }
526
+ };
527
+
528
+ child.on('error', (error) => {
529
+ console.error(`Cloudflared error: ${error.message}`);
530
+ cleanupTempTokenFile();
531
+ });
532
+
533
+ child.on('exit', () => {
534
+ cleanupTempTokenFile();
535
+ });
536
+
537
+ try {
538
+ await waitForManagedTunnelReady(child, { modeLabel: 'managed-remote tunnel' });
539
+ } catch (error) {
540
+ try { child.kill('SIGINT'); } catch { /* ignore */ }
541
+ cleanupTempTokenFile();
542
+ throw error;
543
+ }
544
+
545
+ return {
546
+ mode: TUNNEL_MODE_MANAGED_REMOTE,
547
+ stop: () => {
548
+ try {
549
+ child.kill('SIGINT');
550
+ } catch {
551
+ // Ignore
552
+ }
553
+ cleanupTempTokenFile();
554
+ },
555
+ process: child,
556
+ getPublicUrl: () => publicUrl,
557
+ };
558
+ }
559
+
560
+ export async function startCloudflareManagedLocalTunnel({ configPath, hostname }) {
561
+ const cfCheck = await checkCloudflaredAvailable();
562
+
563
+ if (!cfCheck.available) {
564
+ printCloudflareTunnelInstallHelp();
565
+ throw new Error('cloudflared is not installed');
566
+ }
567
+
568
+ const requestedPath = typeof configPath === 'string' ? configPath.trim() : '';
569
+ const effectiveConfigPath = requestedPath || getDefaultCloudflaredConfigPath();
570
+
571
+ if (requestedPath) {
572
+ assertReadableFile(effectiveConfigPath, 'Managed local tunnel config');
573
+ } else {
574
+ assertReadableFile(effectiveConfigPath, 'Managed local tunnel default config');
575
+ }
576
+
577
+ const configHostnameResult = extractHostnameFromCloudflaredConfigDetailed(effectiveConfigPath);
578
+ if (configHostnameResult.parseError) {
579
+ throw configHostnameResult.parseError;
580
+ }
581
+
582
+ const resolvedHost = normalizeHostname(hostname) || configHostnameResult.hostname;
583
+
584
+ if (!resolvedHost) {
585
+ throw new Error('Managed local tunnel hostname is required (use --tunnel-hostname or add an ingress hostname to the cloudflared config)');
586
+ }
587
+
588
+ const args = ['tunnel'];
589
+ if (requestedPath) {
590
+ args.push('--config', effectiveConfigPath);
591
+ }
592
+ args.push('run');
593
+
594
+ const child = spawnCloudflared(args, {}, cfCheck.path);
595
+ const publicUrl = `https://${resolvedHost}`;
596
+
597
+ child.stdout.on('data', () => {
598
+ // Keep stream drained, but avoid logging potentially sensitive output.
599
+ });
600
+
601
+ child.stderr.on('data', (chunk) => {
602
+ const text = chunk.toString('utf8');
603
+ process.stderr.write(text);
604
+ });
605
+
606
+ child.on('error', (error) => {
607
+ console.error(`Cloudflared error: ${error.message}`);
608
+ });
609
+
610
+ try {
611
+ await waitForManagedTunnelReady(child, { modeLabel: 'managed-local tunnel' });
612
+ } catch (error) {
613
+ try { child.kill('SIGINT'); } catch { /* ignore */ }
614
+ throw error;
615
+ }
616
+
617
+ return {
618
+ mode: TUNNEL_MODE_MANAGED_LOCAL,
619
+ stop: () => {
620
+ try {
621
+ child.kill('SIGINT');
622
+ } catch {
623
+ // Ignore
624
+ }
625
+ },
626
+ process: child,
627
+ getPublicUrl: () => publicUrl,
628
+ getResolvedHostname: () => resolvedHost,
629
+ getEffectiveConfigPath: () => effectiveConfigPath,
630
+ };
631
+ }
632
+
633
+ export async function startCloudflareTunnel({ originUrl, port }) {
634
+ void port;
635
+ return startCloudflareQuickTunnel({ originUrl });
636
+ }
637
+
638
+ export function printTunnelWarning() {
639
+ console.log(`
640
+ ⚠️ Cloudflare Quick Tunnel Limitations:
641
+
642
+ • Maximum 200 concurrent requests
643
+ • Server-Sent Events (SSE) are NOT supported
644
+ • URLs are temporary and will expire when the tunnel stops
645
+ • Password protection is required for tunnel access
646
+
647
+ For production use, set up a managed remote Cloudflare Tunnel:
648
+ https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/
649
+ `);
650
+ }
@@ -0,0 +1,61 @@
1
+ # Event Stream Module Documentation
2
+
3
+ ## Purpose
4
+ This module contains the Vinci message-stream WebSocket protocol and runtime bridge. It keeps the browser-facing WebSocket transport separate from the upstream OpenCode SSE transport.
5
+
6
+ ## Entrypoints and structure
7
+ - `packages/web/server/lib/event-stream/index.js`: public entrypoint re-exporting protocol and runtime helpers.
8
+ - `packages/web/server/lib/event-stream/global-hub.js`: shared global upstream SSE hub for server-side subscribers and browser WS fan-out.
9
+ - `packages/web/server/lib/event-stream/global-ws-bridge.js`: browser-facing global WS bridge that subscribes clients to the shared global hub.
10
+ - `packages/web/server/lib/event-stream/directory-ws-bridge.js`: browser-facing per-directory WS bridge that owns one scoped upstream reader per connection.
11
+ - `packages/web/server/lib/event-stream/protocol.js`: path constants, SSE envelope parsing, and WebSocket frame serialization helpers.
12
+ - `packages/web/server/lib/event-stream/upstream-reader.js`: reusable upstream SSE reader with event-id tracking, stall recovery, and reconnect handling.
13
+ - `packages/web/server/lib/event-stream/runtime.js`: thin WebSocket server runtime for upgrade handling and path dispatch to the global/directory bridges.
14
+ - `packages/web/server/lib/event-stream/protocol.test.js`: unit tests for protocol helpers.
15
+ - `packages/web/server/lib/event-stream/upstream-reader.test.js`: unit tests for upstream SSE reader behavior.
16
+ - `packages/web/server/lib/event-stream/runtime.test.js`: unit tests for runtime-side broadcaster behavior.
17
+
18
+ ## Public exports
19
+
20
+ ### Protocol helpers
21
+ - `MESSAGE_STREAM_GLOBAL_WS_PATH`: `/api/global/event/ws`
22
+ - `MESSAGE_STREAM_DIRECTORY_WS_PATH`: `/api/event/ws`
23
+ - `MESSAGE_STREAM_WS_HEARTBEAT_INTERVAL_MS`: heartbeat interval for browser-facing WS connections.
24
+ - `parseSseEventEnvelope(block)`: parses an SSE block into `{ eventId, directory, payload }`.
25
+ - `sendMessageStreamWsFrame(socket, payload)`: serializes and sends a JSON WS frame.
26
+ - `sendMessageStreamWsEvent(socket, payload, options)`: sends an event frame with optional `eventId` and `directory`.
27
+
28
+ ### Runtime helpers
29
+ - `createGlobalMessageStreamHub(...)`: creates a shared `/global/event` upstream SSE hub with event/status subscribers and bounded event-id replay.
30
+ - `createGlobalUiEventBroadcaster({ sseClients, wsClients, writeSseEvent })`: returns a broadcaster that fans out the same synthetic UI event to SSE and WS clients.
31
+ - `createMessageStreamWsRuntime(...)`: mounts the message-stream WS server, upgrade handler, and SSE-to-WS bridge onto the web HTTP server.
32
+
33
+ ### Upstream reader helpers
34
+ - `DEFAULT_UPSTREAM_STALL_TIMEOUT_MS`: default idle timeout before an attached upstream SSE fetch is aborted for reconnect.
35
+ - `DEFAULT_UPSTREAM_RECONNECT_DELAY_MS`: default delay between upstream reconnect attempts.
36
+ - `createUpstreamSseReader(...)`: creates a start/stop reader for OpenCode SSE streams. The reader parses SSE blocks, tracks the latest `Last-Event-ID`, reconnects after closed or stalled upstream streams, and reports events through callbacks.
37
+
38
+ ## Runtime behavior
39
+ - Browser clients connect to the WS endpoints above.
40
+ - Vinci still fetches OpenCode upstream event streams over SSE.
41
+ - The web server creates one shared global message-stream hub. OpenCode watcher side effects and global WS clients subscribe to that hub, so there is one upstream `/global/event` SSE reader for both server-side processing and browser fan-out.
42
+ - The global hub keeps a bounded replay buffer keyed by SSE `eventId` so reconnecting browser clients can receive buffered events after their requested `Last-Event-ID`.
43
+ - Directory WS clients still attach one upstream `/event?directory=...` SSE reader per connection because directory streams are scoped.
44
+ - If an upstream SSE stream stalls after the browser WS is already ready, the reader aborts that upstream fetch and reconnects upstream with `Last-Event-ID`, keeping the browser WS alive when recovery is fast.
45
+ - Health checks are reserved for initial upstream connect failures and explicit upstream-unavailable responses, not for ordinary stall recovery on an already-established stream.
46
+ - Global synthetic events such as `vinci:session-status`, `vinci:session-activity`, `vinci:notification`, and `vinci:heartbeat` are preserved on the WS path, but heartbeat frames are emitted only while an upstream SSE stream is actively attached.
47
+ - Global UI broadcasts are fan-out capable across both SSE and WS clients.
48
+ - The reusable upstream reader centralizes SSE fetch/parsing/reconnect behavior for the WS runtime and OpenCode watcher. Additional event consumers should move to it only with parity tests for their lifecycle and error semantics.
49
+ - Browser transport concerns live in the WS bridge modules; server-side global stream ownership lives in `global-hub.js`.
50
+
51
+ ## Notes for contributors
52
+ - Keep protocol helpers pure and small so they can be unit tested without spinning up a server.
53
+ - Keep `runtime.js` focused on WebSocket upgrade and endpoint dispatch. Put global browser-client lifecycle in `global-ws-bridge.js`, directory stream lifecycle in `directory-ws-bridge.js`, and upstream stream sharing in `global-hub.js`.
54
+ - Do not change upstream OpenCode transport assumptions here; OpenCode remains SSE-based.
55
+ - Keep global replay bounded; do not turn it into an unbounded event log.
56
+
57
+ ## Testing
58
+ - Run `bun test packages/web/server/lib/event-stream/protocol.test.js`
59
+ - Run `bun test packages/web/server/lib/event-stream/upstream-reader.test.js`
60
+ - Run `bun test packages/web/server/lib/event-stream/runtime.test.js`
61
+ - Run repo validation before finalizing: `bun run type-check`, `bun run lint`, `bun run build`