@myrialabs/clopen 0.4.49 → 0.4.51

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 (486) hide show
  1. package/README.md +2 -1
  2. package/backend/chat/attachments.test.ts +106 -17
  3. package/backend/chat/attachments.ts +131 -34
  4. package/backend/chat/background-wait.test.ts +28 -0
  5. package/backend/chat/engine-handoff.ts +42 -6
  6. package/backend/chat/message-pages.test.ts +17 -0
  7. package/backend/chat/message-pages.ts +6 -2
  8. package/backend/chat/stream-manager.ts +114 -19
  9. package/backend/containers/actions.ts +22 -0
  10. package/backend/control/actions/projects.ts +93 -37
  11. package/backend/control/folders.test.ts +27 -2
  12. package/backend/control/index.ts +2 -1
  13. package/backend/database/migrations/056_support_mssql_driver.ts +7 -0
  14. package/backend/database/migrations/077_create_integration_db_links.ts +7 -0
  15. package/backend/database/migrations/086_single_owner.ts +66 -73
  16. package/backend/database/migrations/088_create_messages_fts_map.ts +52 -0
  17. package/backend/database/migrations/089_add_memory_layout_tiles.ts +58 -0
  18. package/backend/database/migrations/090_create_storage_tables.ts +83 -0
  19. package/backend/database/migrations/index.ts +25 -2
  20. package/backend/database/queries/graph-queries.ts +392 -135
  21. package/backend/database/queries/integration-queries.ts +10 -0
  22. package/backend/database/queries/memory-queue-queries.ts +11 -0
  23. package/backend/database/queries/message-fts.test.ts +120 -0
  24. package/backend/database/queries/message-queries.ts +45 -9
  25. package/backend/database/queries/project-queries.ts +6 -0
  26. package/backend/database/queries/session-queries.ts +6 -2
  27. package/backend/database/queries/utils-queries.ts +3 -0
  28. package/backend/database/utils/migration-runner.test.ts +196 -0
  29. package/backend/database/utils/migration-runner.ts +61 -16
  30. package/backend/database/utils/seeder-runner.ts +22 -16
  31. package/backend/engine/adapters/claude/environment.ts +4 -0
  32. package/backend/engine/adapters/claude/input-gate.test.ts +59 -0
  33. package/backend/engine/adapters/claude/input-gate.ts +74 -0
  34. package/backend/engine/adapters/claude/message-converter.test.ts +16 -0
  35. package/backend/engine/adapters/claude/message-converter.ts +8 -0
  36. package/backend/engine/adapters/claude/stream.ts +20 -0
  37. package/backend/engine/adapters/cursor/environment.ts +1 -1
  38. package/backend/engine/adapters/qwen/session-store.ts +10 -1
  39. package/backend/engine/types.ts +7 -0
  40. package/backend/git/identity/cli.ts +35 -0
  41. package/backend/git/identity/env.test.ts +52 -1
  42. package/backend/git/identity/env.ts +69 -10
  43. package/backend/git/identity/index.ts +25 -6
  44. package/backend/git/identity/resolve.ts +2 -1
  45. package/backend/git/identity/scope-config.test.ts +7 -4
  46. package/backend/git/identity/scope-config.ts +13 -7
  47. package/backend/git-hosts/accounts.ts +106 -0
  48. package/backend/git-hosts/auth/client-ids.ts +34 -0
  49. package/backend/git-hosts/auth/connect.ts +110 -0
  50. package/backend/git-hosts/auth/endpoints.ts +130 -0
  51. package/backend/git-hosts/auth/flows.ts +355 -0
  52. package/backend/git-hosts/auth/local.ts +152 -0
  53. package/backend/git-hosts/ci.ts +18 -0
  54. package/backend/git-hosts/cli.test.ts +82 -0
  55. package/backend/git-hosts/cli.ts +342 -0
  56. package/backend/git-hosts/credentials.ts +173 -0
  57. package/backend/git-hosts/git-credential.ts +30 -0
  58. package/backend/git-hosts/health.ts +39 -0
  59. package/backend/git-hosts/http.ts +174 -0
  60. package/backend/git-hosts/index.ts +34 -0
  61. package/backend/git-hosts/providers/bitbucket.ts +186 -0
  62. package/backend/git-hosts/providers/gitea.ts +208 -0
  63. package/backend/git-hosts/providers/github.ts +270 -0
  64. package/backend/git-hosts/providers/gitlab-client.ts +70 -0
  65. package/backend/git-hosts/providers/gitlab.ts +285 -0
  66. package/backend/git-hosts/providers/locators.test.ts +68 -0
  67. package/backend/git-hosts/registry.ts +50 -0
  68. package/backend/git-hosts/service.ts +432 -0
  69. package/backend/git-hosts/types.ts +82 -0
  70. package/backend/git-hosts/urls.test.ts +42 -0
  71. package/backend/git-hosts/urls.ts +69 -0
  72. package/backend/index.ts +84 -17
  73. package/backend/integrations/accounts.ts +50 -3
  74. package/backend/integrations/registry/define.ts +9 -0
  75. package/backend/integrations/registry/index.ts +11 -0
  76. package/backend/integrations/registry/providers/bitbucket.ts +51 -0
  77. package/backend/integrations/registry/providers/gitea.ts +53 -0
  78. package/backend/integrations/registry/providers/github.ts +24 -7
  79. package/backend/integrations/registry/providers/gitlab.ts +57 -0
  80. package/backend/integrations/registry/types.ts +13 -1
  81. package/backend/mcp/internal/servers/browser-automation/actions/inspect.ts +115 -31
  82. package/backend/mcp/internal/servers/browser-automation/description.ts +5 -0
  83. package/backend/memory/README.md +7 -4
  84. package/backend/memory/layout.test.ts +377 -0
  85. package/backend/memory/layout.ts +1029 -265
  86. package/backend/memory/view.ts +257 -386
  87. package/backend/mentions/diff.ts +63 -0
  88. package/backend/mentions/index.ts +109 -0
  89. package/backend/mentions/mentions.test.ts +27 -0
  90. package/backend/mentions/shared.ts +82 -0
  91. package/backend/mentions/sources/ai-changes.ts +140 -0
  92. package/backend/mentions/sources/chats.ts +122 -0
  93. package/backend/mentions/sources/database.ts +211 -0
  94. package/backend/mentions/sources/files.ts +240 -0
  95. package/backend/mentions/sources/git.ts +308 -0
  96. package/backend/mentions/sources/notes-memory.ts +121 -0
  97. package/backend/mentions/sources/ops.ts +125 -0
  98. package/backend/mentions/sources/preview.ts +153 -0
  99. package/backend/mentions/sources/projects.ts +114 -0
  100. package/backend/mentions/sources/system.ts +135 -0
  101. package/backend/mentions/sources/terminal.ts +50 -0
  102. package/backend/mentions/types.ts +75 -0
  103. package/backend/preview/browser/bot-check-frames.test.ts +49 -0
  104. package/backend/preview/browser/bot-check-frames.ts +66 -0
  105. package/backend/preview/browser/browser-dialog-handler.ts +6 -5
  106. package/backend/preview/browser/browser-host-bridge.ts +4 -2
  107. package/backend/preview/browser/browser-native-ui-handler.ts +21 -0
  108. package/backend/preview/browser/browser-pool.ts +26 -17
  109. package/backend/preview/browser/browser-preview-service.ts +164 -2
  110. package/backend/preview/browser/browser-screenshot.test.ts +113 -0
  111. package/backend/preview/browser/browser-screenshot.ts +396 -0
  112. package/backend/preview/browser/browser-tab-manager.ts +35 -186
  113. package/backend/preview/browser/browser-video-capture.ts +12 -17
  114. package/backend/preview/browser/element-describe.ts +125 -0
  115. package/backend/preview/browser/page-binding.ts +141 -0
  116. package/backend/preview/browser/screenshot-files.test.ts +117 -0
  117. package/backend/preview/browser/screenshot-files.ts +134 -0
  118. package/backend/preview/browser/user-agent.test.ts +25 -0
  119. package/backend/preview/browser/user-agent.ts +100 -0
  120. package/backend/project/status-manager.ts +4 -2
  121. package/backend/projects/engine-transcripts.ts +153 -0
  122. package/backend/projects/folder-guard.ts +55 -0
  123. package/backend/projects/move.test.ts +208 -0
  124. package/backend/projects/move.ts +277 -0
  125. package/backend/projects/project-cleanup.integration.test.ts +3 -1
  126. package/backend/projects/project-cleanup.ts +10 -0
  127. package/backend/storage/actions.ts +260 -0
  128. package/backend/storage/chats.test.ts +57 -0
  129. package/backend/storage/chats.ts +170 -0
  130. package/backend/storage/database.ts +105 -0
  131. package/backend/storage/engine-homes.ts +145 -0
  132. package/backend/storage/fs-size.ts +111 -0
  133. package/backend/storage/history.ts +39 -0
  134. package/backend/storage/policy.ts +156 -0
  135. package/backend/storage/preview-profiles.ts +169 -0
  136. package/backend/storage/purge.ts +158 -0
  137. package/backend/storage/scanner.ts +339 -0
  138. package/backend/storage/session-index.ts +208 -0
  139. package/backend/storage/snapshots.ts +99 -0
  140. package/backend/storage/storage-flow.test.ts +137 -0
  141. package/backend/storage/transcripts/aliases.ts +75 -0
  142. package/backend/storage/transcripts/claude-dedupe.test.ts +101 -0
  143. package/backend/storage/transcripts/claude-dedupe.ts +152 -0
  144. package/backend/storage/transcripts/claude.ts +155 -0
  145. package/backend/storage/transcripts/cursor.ts +165 -0
  146. package/backend/storage/transcripts/file-stores.ts +224 -0
  147. package/backend/storage/transcripts/index.ts +207 -0
  148. package/backend/storage/transcripts/opencode.ts +124 -0
  149. package/backend/storage/transcripts/references.ts +42 -0
  150. package/backend/storage/transcripts/types.ts +58 -0
  151. package/backend/storage/worktrees.ts +114 -0
  152. package/backend/terminal/ptykit.ts +25 -0
  153. package/backend/update/registry.ts +24 -0
  154. package/backend/update/release-notes.test.ts +110 -0
  155. package/backend/update/release-notes.ts +132 -0
  156. package/backend/update/restart.ts +159 -0
  157. package/backend/utils/env.test.ts +64 -0
  158. package/backend/utils/env.ts +23 -55
  159. package/backend/utils/port-utils.ts +13 -0
  160. package/backend/work/index.ts +13 -2
  161. package/backend/work/providers/github/actions-logs.ts +1 -1
  162. package/backend/work/providers/github/adapter.ts +32 -1
  163. package/backend/work/providers/github/client.ts +7 -3
  164. package/backend/work/providers/gitlab/adapter.ts +770 -0
  165. package/backend/work/providers/gitlab/system-notes.test.ts +24 -0
  166. package/backend/work/service.ts +60 -36
  167. package/backend/work/start-work.ts +1 -1
  168. package/backend/work/types.ts +4 -0
  169. package/backend/worktrees/index.ts +1 -0
  170. package/backend/worktrees/service.ts +23 -2
  171. package/backend/ws/chat/composer.ts +47 -6
  172. package/backend/ws/chat/stream.ts +19 -10
  173. package/backend/ws/files/search.ts +1 -1
  174. package/backend/ws/files/write.ts +27 -0
  175. package/backend/ws/hosting/index.ts +231 -0
  176. package/backend/ws/index.ts +12 -2
  177. package/backend/ws/integrations/crud.ts +31 -5
  178. package/backend/ws/integrations/hosting-auth.ts +227 -0
  179. package/backend/ws/integrations/index.ts +2 -0
  180. package/backend/ws/memory/crud.ts +118 -81
  181. package/backend/ws/mentions/index.ts +81 -0
  182. package/backend/ws/messages/crud.ts +3 -1
  183. package/backend/ws/preview/browser/screenshot.ts +184 -0
  184. package/backend/ws/preview/index.ts +23 -0
  185. package/backend/ws/projects/crud.ts +66 -58
  186. package/backend/ws/sessions/crud.ts +7 -95
  187. package/backend/ws/snapshot/changes.ts +3 -3
  188. package/backend/ws/storage/index.ts +102 -0
  189. package/backend/ws/system/index.ts +7 -0
  190. package/backend/ws/system/operations.ts +125 -69
  191. package/backend/ws/work/context.ts +3 -4
  192. package/backend/ws/work/crud.ts +33 -0
  193. package/backend/ws/work/schemas.ts +4 -1
  194. package/bin/clopen.ts +18 -18
  195. package/dist/assets/{index-DD0-3EWg.js → index-B9rHDvjg.js} +1 -1
  196. package/dist/assets/index-B9rHDvjg.js.br +0 -0
  197. package/dist/assets/index-B9rHDvjg.js.gz +0 -0
  198. package/dist/assets/{index-CrVWZH_D.js → index-DFlwOd7k.js} +1 -1
  199. package/dist/assets/index-DFlwOd7k.js.br +0 -0
  200. package/dist/assets/index-DFlwOd7k.js.gz +0 -0
  201. package/dist/assets/main-Bz_brxxS.css +1 -0
  202. package/dist/assets/main-Bz_brxxS.css.br +0 -0
  203. package/dist/assets/main-Bz_brxxS.css.gz +0 -0
  204. package/dist/assets/main-DRcX9SHx.js +1273 -0
  205. package/dist/assets/main-DRcX9SHx.js.br +0 -0
  206. package/dist/assets/main-DRcX9SHx.js.gz +0 -0
  207. package/dist/assets/pdf-DfwfQPLy.js +57 -0
  208. package/dist/assets/pdf-DfwfQPLy.js.br +0 -0
  209. package/dist/assets/pdf-DfwfQPLy.js.gz +0 -0
  210. package/dist/assets/pdf.worker.min-B5Yc7dP4.mjs +27 -0
  211. package/dist/assets/pdf.worker.min-B5Yc7dP4.mjs.br +0 -0
  212. package/dist/assets/pdf.worker.min-B5Yc7dP4.mjs.gz +0 -0
  213. package/dist/assets/pdf.worker.min-BOrSNwfp.js +1 -0
  214. package/dist/index.html +2 -2
  215. package/dist/index.html.br +0 -0
  216. package/dist/index.html.gz +0 -0
  217. package/dist/vendor/pdfjs/cmaps/78-EUC-H.bcmap +0 -0
  218. package/dist/vendor/pdfjs/cmaps/78-EUC-V.bcmap +0 -0
  219. package/dist/vendor/pdfjs/cmaps/78-H.bcmap +0 -0
  220. package/dist/vendor/pdfjs/cmaps/78-RKSJ-H.bcmap +0 -0
  221. package/dist/vendor/pdfjs/cmaps/78-RKSJ-V.bcmap +0 -0
  222. package/dist/vendor/pdfjs/cmaps/78-V.bcmap +0 -0
  223. package/dist/vendor/pdfjs/cmaps/78ms-RKSJ-H.bcmap +0 -0
  224. package/dist/vendor/pdfjs/cmaps/78ms-RKSJ-V.bcmap +0 -0
  225. package/dist/vendor/pdfjs/cmaps/83pv-RKSJ-H.bcmap +0 -0
  226. package/dist/vendor/pdfjs/cmaps/90ms-RKSJ-H.bcmap +0 -0
  227. package/dist/vendor/pdfjs/cmaps/90ms-RKSJ-V.bcmap +0 -0
  228. package/dist/vendor/pdfjs/cmaps/90msp-RKSJ-H.bcmap +0 -0
  229. package/dist/vendor/pdfjs/cmaps/90msp-RKSJ-V.bcmap +0 -0
  230. package/dist/vendor/pdfjs/cmaps/90pv-RKSJ-H.bcmap +0 -0
  231. package/dist/vendor/pdfjs/cmaps/90pv-RKSJ-V.bcmap +0 -0
  232. package/dist/vendor/pdfjs/cmaps/Add-H.bcmap +0 -0
  233. package/dist/vendor/pdfjs/cmaps/Add-RKSJ-H.bcmap +0 -0
  234. package/dist/vendor/pdfjs/cmaps/Add-RKSJ-V.bcmap +0 -0
  235. package/dist/vendor/pdfjs/cmaps/Add-V.bcmap +0 -0
  236. package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-0.bcmap +0 -0
  237. package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-1.bcmap +0 -0
  238. package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-2.bcmap +0 -0
  239. package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-3.bcmap +0 -0
  240. package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-4.bcmap +0 -0
  241. package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-5.bcmap +0 -0
  242. package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-6.bcmap +0 -0
  243. package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-UCS2.bcmap +0 -0
  244. package/dist/vendor/pdfjs/cmaps/Adobe-GB1-0.bcmap +0 -0
  245. package/dist/vendor/pdfjs/cmaps/Adobe-GB1-1.bcmap +0 -0
  246. package/dist/vendor/pdfjs/cmaps/Adobe-GB1-2.bcmap +0 -0
  247. package/dist/vendor/pdfjs/cmaps/Adobe-GB1-3.bcmap +0 -0
  248. package/dist/vendor/pdfjs/cmaps/Adobe-GB1-4.bcmap +0 -0
  249. package/dist/vendor/pdfjs/cmaps/Adobe-GB1-5.bcmap +0 -0
  250. package/dist/vendor/pdfjs/cmaps/Adobe-GB1-UCS2.bcmap +0 -0
  251. package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-0.bcmap +0 -0
  252. package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-1.bcmap +0 -0
  253. package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-2.bcmap +0 -0
  254. package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-3.bcmap +0 -0
  255. package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-4.bcmap +0 -0
  256. package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-5.bcmap +0 -0
  257. package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-6.bcmap +0 -0
  258. package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-UCS2.bcmap +0 -0
  259. package/dist/vendor/pdfjs/cmaps/Adobe-Korea1-0.bcmap +0 -0
  260. package/dist/vendor/pdfjs/cmaps/Adobe-Korea1-1.bcmap +0 -0
  261. package/dist/vendor/pdfjs/cmaps/Adobe-Korea1-2.bcmap +0 -0
  262. package/dist/vendor/pdfjs/cmaps/Adobe-Korea1-UCS2.bcmap +0 -0
  263. package/dist/vendor/pdfjs/cmaps/B5-H.bcmap +0 -0
  264. package/dist/vendor/pdfjs/cmaps/B5-V.bcmap +0 -0
  265. package/dist/vendor/pdfjs/cmaps/B5pc-H.bcmap +0 -0
  266. package/dist/vendor/pdfjs/cmaps/B5pc-V.bcmap +0 -0
  267. package/dist/vendor/pdfjs/cmaps/CNS-EUC-H.bcmap +0 -0
  268. package/dist/vendor/pdfjs/cmaps/CNS-EUC-V.bcmap +0 -0
  269. package/dist/vendor/pdfjs/cmaps/CNS1-H.bcmap +0 -0
  270. package/dist/vendor/pdfjs/cmaps/CNS1-V.bcmap +0 -0
  271. package/dist/vendor/pdfjs/cmaps/CNS2-H.bcmap +0 -0
  272. package/dist/vendor/pdfjs/cmaps/CNS2-V.bcmap +3 -0
  273. package/dist/vendor/pdfjs/cmaps/ETHK-B5-H.bcmap +0 -0
  274. package/dist/vendor/pdfjs/cmaps/ETHK-B5-V.bcmap +0 -0
  275. package/dist/vendor/pdfjs/cmaps/ETen-B5-H.bcmap +0 -0
  276. package/dist/vendor/pdfjs/cmaps/ETen-B5-V.bcmap +0 -0
  277. package/dist/vendor/pdfjs/cmaps/ETenms-B5-H.bcmap +3 -0
  278. package/dist/vendor/pdfjs/cmaps/ETenms-B5-V.bcmap +0 -0
  279. package/dist/vendor/pdfjs/cmaps/EUC-H.bcmap +0 -0
  280. package/dist/vendor/pdfjs/cmaps/EUC-V.bcmap +0 -0
  281. package/dist/vendor/pdfjs/cmaps/Ext-H.bcmap +0 -0
  282. package/dist/vendor/pdfjs/cmaps/Ext-RKSJ-H.bcmap +0 -0
  283. package/dist/vendor/pdfjs/cmaps/Ext-RKSJ-V.bcmap +0 -0
  284. package/dist/vendor/pdfjs/cmaps/Ext-V.bcmap +0 -0
  285. package/dist/vendor/pdfjs/cmaps/GB-EUC-H.bcmap +0 -0
  286. package/dist/vendor/pdfjs/cmaps/GB-EUC-V.bcmap +0 -0
  287. package/dist/vendor/pdfjs/cmaps/GB-H.bcmap +6 -0
  288. package/dist/vendor/pdfjs/cmaps/GB-V.bcmap +0 -0
  289. package/dist/vendor/pdfjs/cmaps/GBK-EUC-H.bcmap +0 -0
  290. package/dist/vendor/pdfjs/cmaps/GBK-EUC-V.bcmap +0 -0
  291. package/dist/vendor/pdfjs/cmaps/GBK2K-H.bcmap +0 -0
  292. package/dist/vendor/pdfjs/cmaps/GBK2K-V.bcmap +0 -0
  293. package/dist/vendor/pdfjs/cmaps/GBKp-EUC-H.bcmap +0 -0
  294. package/dist/vendor/pdfjs/cmaps/GBKp-EUC-V.bcmap +0 -0
  295. package/dist/vendor/pdfjs/cmaps/GBT-EUC-H.bcmap +0 -0
  296. package/dist/vendor/pdfjs/cmaps/GBT-EUC-V.bcmap +0 -0
  297. package/dist/vendor/pdfjs/cmaps/GBT-H.bcmap +0 -0
  298. package/dist/vendor/pdfjs/cmaps/GBT-V.bcmap +0 -0
  299. package/dist/vendor/pdfjs/cmaps/GBTpc-EUC-H.bcmap +0 -0
  300. package/dist/vendor/pdfjs/cmaps/GBTpc-EUC-V.bcmap +0 -0
  301. package/dist/vendor/pdfjs/cmaps/GBpc-EUC-H.bcmap +0 -0
  302. package/dist/vendor/pdfjs/cmaps/GBpc-EUC-V.bcmap +0 -0
  303. package/dist/vendor/pdfjs/cmaps/H.bcmap +0 -0
  304. package/dist/vendor/pdfjs/cmaps/HKdla-B5-H.bcmap +0 -0
  305. package/dist/vendor/pdfjs/cmaps/HKdla-B5-V.bcmap +0 -0
  306. package/dist/vendor/pdfjs/cmaps/HKdlb-B5-H.bcmap +0 -0
  307. package/dist/vendor/pdfjs/cmaps/HKdlb-B5-V.bcmap +0 -0
  308. package/dist/vendor/pdfjs/cmaps/HKgccs-B5-H.bcmap +0 -0
  309. package/dist/vendor/pdfjs/cmaps/HKgccs-B5-V.bcmap +0 -0
  310. package/dist/vendor/pdfjs/cmaps/HKm314-B5-H.bcmap +0 -0
  311. package/dist/vendor/pdfjs/cmaps/HKm314-B5-V.bcmap +0 -0
  312. package/dist/vendor/pdfjs/cmaps/HKm471-B5-H.bcmap +0 -0
  313. package/dist/vendor/pdfjs/cmaps/HKm471-B5-V.bcmap +0 -0
  314. package/dist/vendor/pdfjs/cmaps/HKscs-B5-H.bcmap +0 -0
  315. package/dist/vendor/pdfjs/cmaps/HKscs-B5-V.bcmap +0 -0
  316. package/dist/vendor/pdfjs/cmaps/Hankaku.bcmap +0 -0
  317. package/dist/vendor/pdfjs/cmaps/Hiragana.bcmap +0 -0
  318. package/dist/vendor/pdfjs/cmaps/KSC-EUC-H.bcmap +0 -0
  319. package/dist/vendor/pdfjs/cmaps/KSC-EUC-V.bcmap +0 -0
  320. package/dist/vendor/pdfjs/cmaps/KSC-H.bcmap +0 -0
  321. package/dist/vendor/pdfjs/cmaps/KSC-Johab-H.bcmap +0 -0
  322. package/dist/vendor/pdfjs/cmaps/KSC-Johab-V.bcmap +0 -0
  323. package/dist/vendor/pdfjs/cmaps/KSC-V.bcmap +0 -0
  324. package/dist/vendor/pdfjs/cmaps/KSCms-UHC-H.bcmap +0 -0
  325. package/dist/vendor/pdfjs/cmaps/KSCms-UHC-HW-H.bcmap +0 -0
  326. package/dist/vendor/pdfjs/cmaps/KSCms-UHC-HW-V.bcmap +0 -0
  327. package/dist/vendor/pdfjs/cmaps/KSCms-UHC-V.bcmap +0 -0
  328. package/dist/vendor/pdfjs/cmaps/KSCpc-EUC-H.bcmap +0 -0
  329. package/dist/vendor/pdfjs/cmaps/KSCpc-EUC-V.bcmap +0 -0
  330. package/dist/vendor/pdfjs/cmaps/Katakana.bcmap +0 -0
  331. package/dist/vendor/pdfjs/cmaps/LICENSE +36 -0
  332. package/dist/vendor/pdfjs/cmaps/NWP-H.bcmap +0 -0
  333. package/dist/vendor/pdfjs/cmaps/NWP-V.bcmap +0 -0
  334. package/dist/vendor/pdfjs/cmaps/RKSJ-H.bcmap +0 -0
  335. package/dist/vendor/pdfjs/cmaps/RKSJ-V.bcmap +0 -0
  336. package/dist/vendor/pdfjs/cmaps/Roman.bcmap +0 -0
  337. package/dist/vendor/pdfjs/cmaps/UniCNS-UCS2-H.bcmap +0 -0
  338. package/dist/vendor/pdfjs/cmaps/UniCNS-UCS2-V.bcmap +0 -0
  339. package/dist/vendor/pdfjs/cmaps/UniCNS-UTF16-H.bcmap +0 -0
  340. package/dist/vendor/pdfjs/cmaps/UniCNS-UTF16-V.bcmap +0 -0
  341. package/dist/vendor/pdfjs/cmaps/UniCNS-UTF32-H.bcmap +0 -0
  342. package/dist/vendor/pdfjs/cmaps/UniCNS-UTF32-V.bcmap +0 -0
  343. package/dist/vendor/pdfjs/cmaps/UniCNS-UTF8-H.bcmap +0 -0
  344. package/dist/vendor/pdfjs/cmaps/UniCNS-UTF8-V.bcmap +0 -0
  345. package/dist/vendor/pdfjs/cmaps/UniGB-UCS2-H.bcmap +0 -0
  346. package/dist/vendor/pdfjs/cmaps/UniGB-UCS2-V.bcmap +0 -0
  347. package/dist/vendor/pdfjs/cmaps/UniGB-UTF16-H.bcmap +0 -0
  348. package/dist/vendor/pdfjs/cmaps/UniGB-UTF16-V.bcmap +0 -0
  349. package/dist/vendor/pdfjs/cmaps/UniGB-UTF32-H.bcmap +0 -0
  350. package/dist/vendor/pdfjs/cmaps/UniGB-UTF32-V.bcmap +0 -0
  351. package/dist/vendor/pdfjs/cmaps/UniGB-UTF8-H.bcmap +0 -0
  352. package/dist/vendor/pdfjs/cmaps/UniGB-UTF8-V.bcmap +0 -0
  353. package/dist/vendor/pdfjs/cmaps/UniJIS-UCS2-H.bcmap +0 -0
  354. package/dist/vendor/pdfjs/cmaps/UniJIS-UCS2-HW-H.bcmap +0 -0
  355. package/dist/vendor/pdfjs/cmaps/UniJIS-UCS2-HW-V.bcmap +0 -0
  356. package/dist/vendor/pdfjs/cmaps/UniJIS-UCS2-V.bcmap +0 -0
  357. package/dist/vendor/pdfjs/cmaps/UniJIS-UTF16-H.bcmap +0 -0
  358. package/dist/vendor/pdfjs/cmaps/UniJIS-UTF16-V.bcmap +0 -0
  359. package/dist/vendor/pdfjs/cmaps/UniJIS-UTF32-H.bcmap +0 -0
  360. package/dist/vendor/pdfjs/cmaps/UniJIS-UTF32-V.bcmap +0 -0
  361. package/dist/vendor/pdfjs/cmaps/UniJIS-UTF8-H.bcmap +0 -0
  362. package/dist/vendor/pdfjs/cmaps/UniJIS-UTF8-V.bcmap +0 -0
  363. package/dist/vendor/pdfjs/cmaps/UniJIS2004-UTF16-H.bcmap +0 -0
  364. package/dist/vendor/pdfjs/cmaps/UniJIS2004-UTF16-V.bcmap +0 -0
  365. package/dist/vendor/pdfjs/cmaps/UniJIS2004-UTF32-H.bcmap +0 -0
  366. package/dist/vendor/pdfjs/cmaps/UniJIS2004-UTF32-V.bcmap +0 -0
  367. package/dist/vendor/pdfjs/cmaps/UniJIS2004-UTF8-H.bcmap +0 -0
  368. package/dist/vendor/pdfjs/cmaps/UniJIS2004-UTF8-V.bcmap +0 -0
  369. package/dist/vendor/pdfjs/cmaps/UniJISPro-UCS2-HW-V.bcmap +0 -0
  370. package/dist/vendor/pdfjs/cmaps/UniJISPro-UCS2-V.bcmap +0 -0
  371. package/dist/vendor/pdfjs/cmaps/UniJISPro-UTF8-V.bcmap +0 -0
  372. package/dist/vendor/pdfjs/cmaps/UniJISX0213-UTF32-H.bcmap +0 -0
  373. package/dist/vendor/pdfjs/cmaps/UniJISX0213-UTF32-V.bcmap +0 -0
  374. package/dist/vendor/pdfjs/cmaps/UniJISX02132004-UTF32-H.bcmap +0 -0
  375. package/dist/vendor/pdfjs/cmaps/UniJISX02132004-UTF32-V.bcmap +0 -0
  376. package/dist/vendor/pdfjs/cmaps/UniKS-UCS2-H.bcmap +0 -0
  377. package/dist/vendor/pdfjs/cmaps/UniKS-UCS2-V.bcmap +0 -0
  378. package/dist/vendor/pdfjs/cmaps/UniKS-UTF16-H.bcmap +0 -0
  379. package/dist/vendor/pdfjs/cmaps/UniKS-UTF16-V.bcmap +0 -0
  380. package/dist/vendor/pdfjs/cmaps/UniKS-UTF32-H.bcmap +0 -0
  381. package/dist/vendor/pdfjs/cmaps/UniKS-UTF32-V.bcmap +0 -0
  382. package/dist/vendor/pdfjs/cmaps/UniKS-UTF8-H.bcmap +0 -0
  383. package/dist/vendor/pdfjs/cmaps/UniKS-UTF8-V.bcmap +0 -0
  384. package/dist/vendor/pdfjs/cmaps/V.bcmap +0 -0
  385. package/dist/vendor/pdfjs/cmaps/WP-Symbol.bcmap +0 -0
  386. package/dist/vendor/pdfjs/iccs/CGATS001Compat-v2-micro.icc +0 -0
  387. package/dist/vendor/pdfjs/iccs/LICENSE +116 -0
  388. package/dist/vendor/pdfjs/standard_fonts/FoxitDingbats.pfb +0 -0
  389. package/dist/vendor/pdfjs/standard_fonts/FoxitFixed.pfb +0 -0
  390. package/dist/vendor/pdfjs/standard_fonts/FoxitFixedBold.pfb +0 -0
  391. package/dist/vendor/pdfjs/standard_fonts/FoxitFixedBoldItalic.pfb +0 -0
  392. package/dist/vendor/pdfjs/standard_fonts/FoxitFixedItalic.pfb +0 -0
  393. package/dist/vendor/pdfjs/standard_fonts/FoxitSerif.pfb +0 -0
  394. package/dist/vendor/pdfjs/standard_fonts/FoxitSerifBold.pfb +0 -0
  395. package/dist/vendor/pdfjs/standard_fonts/FoxitSerifBoldItalic.pfb +0 -0
  396. package/dist/vendor/pdfjs/standard_fonts/FoxitSerifItalic.pfb +0 -0
  397. package/dist/vendor/pdfjs/standard_fonts/FoxitSymbol.pfb +0 -0
  398. package/dist/vendor/pdfjs/standard_fonts/LICENSE_FOXIT +27 -0
  399. package/dist/vendor/pdfjs/standard_fonts/LICENSE_LIBERATION +363 -0
  400. package/dist/vendor/pdfjs/standard_fonts/LiberationSans-Bold.ttf +0 -0
  401. package/dist/vendor/pdfjs/standard_fonts/LiberationSans-BoldItalic.ttf +0 -0
  402. package/dist/vendor/pdfjs/standard_fonts/LiberationSans-Italic.ttf +0 -0
  403. package/dist/vendor/pdfjs/standard_fonts/LiberationSans-Regular.ttf +0 -0
  404. package/dist/vendor/pdfjs/wasm/LICENSE_JBIG2 +196 -0
  405. package/dist/vendor/pdfjs/wasm/LICENSE_OPENJPEG +39 -0
  406. package/dist/vendor/pdfjs/wasm/LICENSE_PDFJS_JBIG2 +13 -0
  407. package/dist/vendor/pdfjs/wasm/LICENSE_PDFJS_OPENJPEG +22 -0
  408. package/dist/vendor/pdfjs/wasm/LICENSE_PDFJS_QCMS +19 -0
  409. package/dist/vendor/pdfjs/wasm/LICENSE_PDFJS_QUICKJS +21 -0
  410. package/dist/vendor/pdfjs/wasm/LICENSE_QCMS +21 -0
  411. package/dist/vendor/pdfjs/wasm/LICENSE_QUICKJS +22 -0
  412. package/dist/vendor/pdfjs/wasm/jbig2.wasm +0 -0
  413. package/dist/vendor/pdfjs/wasm/jbig2.wasm.br +0 -0
  414. package/dist/vendor/pdfjs/wasm/jbig2.wasm.gz +0 -0
  415. package/dist/vendor/pdfjs/wasm/jbig2_nowasm_fallback.js +2 -0
  416. package/dist/vendor/pdfjs/wasm/jbig2_nowasm_fallback.js.br +0 -0
  417. package/dist/vendor/pdfjs/wasm/jbig2_nowasm_fallback.js.gz +0 -0
  418. package/dist/vendor/pdfjs/wasm/openjpeg.wasm +0 -0
  419. package/dist/vendor/pdfjs/wasm/openjpeg.wasm.br +0 -0
  420. package/dist/vendor/pdfjs/wasm/openjpeg.wasm.gz +0 -0
  421. package/dist/vendor/pdfjs/wasm/openjpeg_nowasm_fallback.js +2 -0
  422. package/dist/vendor/pdfjs/wasm/openjpeg_nowasm_fallback.js.br +0 -0
  423. package/dist/vendor/pdfjs/wasm/openjpeg_nowasm_fallback.js.gz +0 -0
  424. package/dist/vendor/pdfjs/wasm/qcms_bg.wasm +0 -0
  425. package/dist/vendor/pdfjs/wasm/qcms_bg.wasm.br +0 -0
  426. package/dist/vendor/pdfjs/wasm/qcms_bg.wasm.gz +0 -0
  427. package/dist/vendor/pdfjs/wasm/quickjs-eval.js +16 -0
  428. package/dist/vendor/pdfjs/wasm/quickjs-eval.js.br +0 -0
  429. package/dist/vendor/pdfjs/wasm/quickjs-eval.js.gz +0 -0
  430. package/dist/vendor/pdfjs/wasm/quickjs-eval.wasm +0 -0
  431. package/dist/vendor/pdfjs/wasm/quickjs-eval.wasm.br +0 -0
  432. package/dist/vendor/pdfjs/wasm/quickjs-eval.wasm.gz +0 -0
  433. package/package.json +8 -9
  434. package/scripts/start.ts +21 -4
  435. package/shared/constants/binary-extensions.ts +20 -4
  436. package/shared/constants/support.test.ts +27 -0
  437. package/shared/constants/support.ts +79 -0
  438. package/shared/constants/tool-icons.ts +7 -1
  439. package/shared/types/database/schema.ts +6 -0
  440. package/shared/types/git-hosting.ts +241 -0
  441. package/shared/types/integrations.ts +51 -1
  442. package/shared/types/memory.ts +96 -73
  443. package/shared/types/mentions.ts +96 -0
  444. package/shared/types/release-notes.ts +31 -0
  445. package/shared/types/storage.ts +175 -0
  446. package/shared/types/stores/settings.ts +16 -0
  447. package/shared/types/unified/index.ts +2 -0
  448. package/shared/types/unified/message.ts +26 -1
  449. package/shared/types/unified/stream.ts +22 -1
  450. package/shared/types/unified/tool.ts +4 -0
  451. package/shared/types/work.ts +6 -0
  452. package/shared/utils/attachment-mentions.test.ts +39 -0
  453. package/shared/utils/attachment-mentions.ts +100 -0
  454. package/shared/utils/context-document.test.ts +53 -0
  455. package/shared/utils/context-document.ts +226 -0
  456. package/shared/utils/device-frame.test.ts +73 -0
  457. package/shared/utils/device-frame.ts +320 -0
  458. package/shared/utils/fuzzy.ts +79 -0
  459. package/shared/utils/launcher-fingerprint.test.ts +73 -0
  460. package/shared/utils/launcher-fingerprint.ts +108 -0
  461. package/shared/utils/logger.ts +2 -0
  462. package/shared/utils/page-colors.test.ts +17 -0
  463. package/shared/utils/page-colors.ts +24 -0
  464. package/shared/utils/process-supervisor.test.ts +88 -1
  465. package/shared/utils/process-supervisor.ts +123 -29
  466. package/shared/utils/process-tree.ts +99 -0
  467. package/shared/utils/restart-intent.test.ts +57 -0
  468. package/shared/utils/restart-intent.ts +80 -0
  469. package/shared/utils/semver.test.ts +33 -0
  470. package/shared/utils/semver.ts +35 -0
  471. package/shared/utils/supervised-child.ts +44 -0
  472. package/shared/utils/supervisor-protocol.ts +20 -0
  473. package/.env.example +0 -9
  474. package/dist/assets/graph-layout.worker-CRFqN7ZQ.js +0 -1
  475. package/dist/assets/graph-layout.worker-CRFqN7ZQ.js.br +0 -0
  476. package/dist/assets/graph-layout.worker-CRFqN7ZQ.js.gz +0 -0
  477. package/dist/assets/index-CrVWZH_D.js.br +0 -0
  478. package/dist/assets/index-CrVWZH_D.js.gz +0 -0
  479. package/dist/assets/index-DD0-3EWg.js.br +0 -0
  480. package/dist/assets/index-DD0-3EWg.js.gz +0 -0
  481. package/dist/assets/main-D2_TmcwQ.js +0 -1240
  482. package/dist/assets/main-D2_TmcwQ.js.br +0 -0
  483. package/dist/assets/main-D2_TmcwQ.js.gz +0 -0
  484. package/dist/assets/main-Yucigcmf.css +0 -1
  485. package/dist/assets/main-Yucigcmf.css.br +0 -0
  486. package/dist/assets/main-Yucigcmf.css.gz +0 -0
@@ -6,11 +6,12 @@
6
6
  */
7
7
 
8
8
  import { afterAll, describe, expect, test } from 'bun:test';
9
- import { existsSync, mkdtempSync, readFileSync, rmSync } from 'node:fs';
9
+ import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
10
10
  import { tmpdir } from 'node:os';
11
11
  import { join } from 'node:path';
12
12
 
13
13
  import { elapsedSeconds, supervise } from './process-supervisor';
14
+ import { RESTART_EXIT_CODE } from './supervisor-protocol';
14
15
 
15
16
  const posix = process.platform !== 'win32';
16
17
  const dir = mkdtempSync(join(tmpdir(), 'clopen-supervisor-'));
@@ -96,6 +97,92 @@ describe.if(posix)('supervise', () => {
96
97
  expect(() => process.kill(grandchild, 0)).toThrow(); // the grandchild went with it
97
98
  });
98
99
 
100
+ /**
101
+ * A child whose grandchild lives in another process group (like the
102
+ * preview's Chrome): on SIGTERM the child asks the grandchild to stop and
103
+ * exits at once; the grandchild takes `drainMs` (or ignores it).
104
+ */
105
+ function childWithDetachedGrandchild(name: string, drainMs: number | 'ignore'): string[] {
106
+ const grandchild = join(dir, `${name}-grandchild.ts`);
107
+ writeFileSync(
108
+ grandchild,
109
+ drainMs === 'ignore'
110
+ ? `process.on('SIGTERM', () => {}); console.log('ready'); setInterval(() => {}, 1000);`
111
+ : `process.on('SIGTERM', () => setTimeout(() => process.exit(0), ${drainMs})); console.log('ready'); setInterval(() => {}, 1000);`
112
+ );
113
+ const child = join(dir, `${name}-child.ts`);
114
+ writeFileSync(
115
+ child,
116
+ `const g = Bun.spawn(['bun', ${JSON.stringify(grandchild)}], { detached: true, stdout: 'pipe' });
117
+ for await (const chunk of g.stdout) { if (new TextDecoder().decode(chunk).includes('ready')) break; }
118
+ console.log('grandchild=' + g.pid);
119
+ process.on('SIGTERM', () => { g.kill('SIGTERM'); process.exit(0); });
120
+ setInterval(() => {}, 1000);`
121
+ );
122
+ return ['bun', child];
123
+ }
124
+
125
+ test('a stop is over only once what the child started in other groups has exited', async () => {
126
+ const out = collect();
127
+ const s = supervise({ name: 't', cmd: childWithDetachedGrandchild('drain', 400), onStdout: out.sink, log: () => {} });
128
+ await waitFor(() => out.lines.some((line) => line.startsWith('grandchild=')), 10_000);
129
+ const grandchild = Number(out.lines.find((line) => line.startsWith('grandchild='))!.split('=')[1]);
130
+
131
+ const started = Date.now();
132
+ await s.stop('SIGTERM');
133
+ expect(Date.now() - started).toBeGreaterThanOrEqual(350);
134
+ expect(() => process.kill(grandchild, 0)).toThrow();
135
+ });
136
+
137
+ test('a process that hangs past the stop timeout is killed', async () => {
138
+ const out = collect();
139
+ const s = supervise({ name: 't', cmd: childWithDetachedGrandchild('hang', 'ignore'), onStdout: out.sink, log: () => {}, stopTimeoutMs: 600 });
140
+ await waitFor(() => out.lines.some((line) => line.startsWith('grandchild=')), 10_000);
141
+ const grandchild = Number(out.lines.find((line) => line.startsWith('grandchild='))!.split('=')[1]);
142
+
143
+ await s.stop('SIGTERM');
144
+ expect(() => process.kill(grandchild, 0)).toThrow();
145
+ });
146
+
147
+ test('a supervised child stops itself when its supervisor is gone', async () => {
148
+ const marker = join(dir, 'supervisor-gone');
149
+ const child = join(dir, 'watching-child.ts');
150
+ writeFileSync(
151
+ child,
152
+ `import { watchSupervisor } from ${JSON.stringify(join(import.meta.dir, 'supervised-child.ts'))};
153
+ watchSupervisor(() => { require('node:fs').writeFileSync(${JSON.stringify(marker)}, 'gone'); process.exit(0); }, 100);
154
+ console.log('watching'); setInterval(() => {}, 1000);`
155
+ );
156
+ const supervisor = join(dir, 'doomed-supervisor.ts');
157
+ writeFileSync(
158
+ supervisor,
159
+ `import { supervise } from ${JSON.stringify(join(import.meta.dir, 'process-supervisor.ts'))};
160
+ supervise({ name: 'c', cmd: ['bun', ${JSON.stringify(child)}], log: () => {} });`
161
+ );
162
+ const proc = Bun.spawn(['bun', supervisor], { stdout: 'pipe' });
163
+ for await (const chunk of proc.stdout) if (new TextDecoder().decode(chunk).includes('watching')) break;
164
+
165
+ proc.kill('SIGKILL'); // gone without stopping anything
166
+ await waitFor(() => existsSync(marker), 5000);
167
+ expect(readFileSync(marker, 'utf8')).toBe('gone');
168
+ });
169
+
170
+ test('a child that asks for a restart comes back at once, undiagnosed and off the crash budget', async () => {
171
+ const counter = join(dir, 'restart-count');
172
+ writeFileSync(counter, '');
173
+ const logs: string[] = [];
174
+ const reportFile = join(dir, 'restart-report.log');
175
+ // Asks for a restart three times, then stays up: more than maxRestarts
176
+ // allows for crashes, and with a restart delay far longer than the test.
177
+ const script = `echo x >> ${counter}; [ $(wc -l < ${counter}) -le 3 ] && exit ${RESTART_EXIT_CODE}; sleep 30`;
178
+ const s = supervise({ name: 'server', cmd: ['sh', '-c', script], log: (line) => logs.push(line), reportFile, restartDelayMs: 60_000, maxRestarts: 1 });
179
+
180
+ await waitFor(() => readFileSync(counter, 'utf8').split('\n').filter(Boolean).length === 4);
181
+ expect(logs.filter((line) => line.includes('restarting on request'))).toHaveLength(3);
182
+ expect(existsSync(reportFile)).toBe(false);
183
+ await s.stop();
184
+ });
185
+
99
186
  test('gives up on a child that keeps dying', async () => {
100
187
  const s = supervise({ name: 't', cmd: ['sh', '-c', 'exit 3'], log: () => {}, restartDelayMs: 10, maxRestarts: 2 });
101
188
  expect(await s.done).toBe(3);
@@ -12,13 +12,23 @@
12
12
  * the difference: a server that received a stray SIGTERM shuts down cleanly
13
13
  * and exits 0. What can is whether this supervisor asked it to stop. A child
14
14
  * that keeps dying (5 times in 60 s) is given up on instead of looping.
15
- * - **Stopped on request.** SIGINT/SIGTERM to the supervisor are forwarded to
16
- * the child's whole group — what a terminal did before the child had a group
17
- * of its own — then it gets 15 s to finish before SIGKILL. A second signal
18
- * forces it; a second programmatic `stop()` does not. SIGHUP is ignored,
19
- * matching the server, which deliberately keeps running when its terminal or
20
- * SSH session closes; the supervisor stays with it, and writes to a terminal
21
- * that is gone are dropped instead of crashing.
15
+ * - **Stopped on request, completely.** SIGINT/SIGTERM to the supervisor are
16
+ * forwarded to the child's whole group — what a terminal did before the
17
+ * child had a group of its own. The stop is over only when the child AND
18
+ * every process it started (collected first: some sit in other groups, like
19
+ * the preview's Chrome) have exited, so the shell prompt comes back with the
20
+ * ports free. Only a process that hangs past `stopTimeoutMs` is SIGKILLed.
21
+ * A second Ctrl+C forces; the copy of the first one that `bun run` forwards
22
+ * is not a second press (see `stopOnSignals`).
23
+ * - **Tied to its terminal, unless run in the background.** SIGHUP (the
24
+ * terminal or SSH session closed) stops everything when the supervisor was
25
+ * started from a terminal. Run without one — `nohup`, a service, a container
26
+ * — it is ignored and the server keeps running. Writes to a terminal that is
27
+ * gone are dropped instead of crashing.
28
+ * - **Restarted on request, too.** A child that exits with RESTART_EXIT_CODE
29
+ * asked to be replaced — the server does this after an update so the new
30
+ * code takes over without anyone touching the terminal. It comes back at
31
+ * once, is not diagnosed, and does not count towards the crash budget.
22
32
  * - **Diagnosed.** Each unrequested exit is logged with its code or signal and
23
33
  * the processes started shortly before it (pid, ppid, pgid, command), to the
24
34
  * console and to `reportFile`, so the next occurrence leaves a trail. The OS
@@ -28,6 +38,8 @@
28
38
 
29
39
  import { appendFileSync, mkdirSync } from 'node:fs';
30
40
  import { dirname } from 'node:path';
41
+ import { collectDescendants, parentForwardsSignals, signalAll, waitForExit } from './process-tree';
42
+ import { RESTART_EXIT_CODE, SUPERVISOR_PID_ENV } from './supervisor-protocol';
31
43
 
32
44
  type Subprocess = ReturnType<typeof Bun.spawn>;
33
45
 
@@ -79,7 +91,10 @@ export function supervise(options: SupervisedProcessOptions): Supervisor {
79
91
  const spawnChild = () => {
80
92
  child = Bun.spawn(options.cmd, {
81
93
  cwd: options.cwd,
82
- env: options.env as Record<string, string>,
94
+ // The child stops itself if this supervisor disappears without stopping
95
+ // it (see supervised-child.ts) — killed outright, a terminal runner's own
96
+ // SIGKILL — instead of running on, unowned, holding its port.
97
+ env: { ...(options.env ?? process.env), [SUPERVISOR_PID_ENV]: String(process.pid) } as Record<string, string>,
83
98
  stdin: 'ignore',
84
99
  stdout: options.onStdout ? 'pipe' : 'inherit',
85
100
  stderr: options.onStderr ? 'pipe' : 'inherit',
@@ -95,7 +110,19 @@ export function supervise(options: SupervisedProcessOptions): Supervisor {
95
110
  if (child !== current) return;
96
111
  const signal = current.signalCode ?? null;
97
112
  if (stopping) {
98
- resolveDone(code ?? 0);
113
+ // The child is out; what it started may still be shutting down.
114
+ const survivors = await waitForExit(stopTree, Math.max(0, stopDeadline - Date.now()));
115
+ if (survivors.length > 0) {
116
+ signalAll(survivors, 'SIGKILL');
117
+ await waitForExit(survivors, 2000);
118
+ }
119
+ resolveDone(code ?? (signal ? 1 : 0));
120
+ return;
121
+ }
122
+
123
+ if (code === RESTART_EXIT_CODE && !signal) {
124
+ log(`[${options.name}] restarting on request…`);
125
+ spawnChild();
99
126
  return;
100
127
  }
101
128
 
@@ -136,25 +163,42 @@ export function supervise(options: SupervisedProcessOptions): Supervisor {
136
163
  }
137
164
  };
138
165
 
139
- const stop = (signal: NodeJS.Signals = 'SIGTERM'): Promise<number> => {
140
- if (stopping) return done;
166
+ /** The child's descendants when the stop began, and when the stop gives up waiting. */
167
+ let stopTree: number[] = [];
168
+ let stopDeadline = 0;
169
+
170
+ /** Begin stopping: remember everything the child started, before signalling it. */
171
+ const beginStop = (): boolean => {
172
+ if (stopping) return false;
141
173
  stopping = true;
142
- if (!child || child.exitCode !== null) {
174
+ stopDeadline = Date.now() + stopTimeoutMs;
175
+ if (!child || child.exitCode !== null || child.signalCode !== null) {
143
176
  resolveDone(child?.exitCode ?? 0);
144
- } else {
145
- // On Windows the child shares the console, so Ctrl+C already reached it;
146
- // forwarding would terminate it outright instead of letting it shut down.
147
- if (!(IS_WINDOWS && signal === 'SIGINT')) signalGroup(signal);
148
- const timer = setTimeout(() => signalGroup('SIGKILL'), stopTimeoutMs);
149
- timer.unref?.();
150
- void done.then(() => clearTimeout(timer));
177
+ return false;
151
178
  }
179
+ stopTree = collectDescendants(child.pid);
180
+ return true;
181
+ };
182
+
183
+ const forceKill = () => {
184
+ signalGroup('SIGKILL');
185
+ signalAll(stopTree, 'SIGKILL');
186
+ };
187
+
188
+ const stop = (signal: NodeJS.Signals = 'SIGTERM'): Promise<number> => {
189
+ if (!beginStop()) return done;
190
+ // On Windows the child shares the console, so Ctrl+C already reached it;
191
+ // forwarding would terminate it outright instead of letting it shut down.
192
+ if (!(IS_WINDOWS && signal === 'SIGINT')) signalGroup(signal);
193
+ const timer = setTimeout(forceKill, stopTimeoutMs);
194
+ timer.unref?.();
195
+ void done.then(() => clearTimeout(timer));
152
196
  return done;
153
197
  };
154
198
 
155
199
  const kill = (): Promise<number> => {
156
- void stop('SIGKILL');
157
- signalGroup('SIGKILL');
200
+ beginStop();
201
+ forceKill();
158
202
  return done;
159
203
  };
160
204
 
@@ -167,30 +211,80 @@ export function supervise(options: SupervisedProcessOptions): Supervisor {
167
211
  * all down, with the first non-zero code. Returns a function that stops them
168
212
  * the same way (for callers that end on their own terms).
169
213
  */
214
+ /** Set once a signal asked the supervisors to stop; that handler then owns the exit. */
215
+ let signalStopRequested = false;
216
+
217
+ /** Whether a signal (Ctrl+C, SIGTERM, a closed terminal) is stopping everything. */
218
+ export function stopRequestedBySignal(): boolean {
219
+ return signalStopRequested;
220
+ }
221
+
170
222
  export function stopOnSignals(supervisors: Supervisor[]): (signal?: NodeJS.Signals) => Promise<number> {
171
223
  const stopAll = async (signal: NodeJS.Signals = 'SIGTERM') => {
172
224
  const codes = await Promise.all(supervisors.map((s) => s.stop(signal)));
173
225
  return codes.find((code) => code !== 0) ?? 0;
174
226
  };
175
- let received = 0;
227
+ // Ctrl+C reaches the whole foreground group. Under `bun run` that is the
228
+ // runner AND this process, and the runner forwards its copy — so the first
229
+ // press arrives twice, 1 ms apart (later presses once). That copy is not a
230
+ // second press: treating it as one used to SIGKILL every child on a single
231
+ // Ctrl+C, and `bun run`, on its own second SIGINT, then killed this process
232
+ // and returned the prompt with the children orphaned and their ports held.
233
+ // Set at the end, once every handler is in place (see there).
234
+ let runnerCopyPending = false;
235
+ let presses = 0;
236
+ const log = (line: string) => {
237
+ try {
238
+ process.stderr.write(`${line}\n`);
239
+ } catch {
240
+ // The terminal is gone.
241
+ }
242
+ };
243
+ const begin = (signal: NodeJS.Signals) => {
244
+ signalStopRequested = true;
245
+ log('\nStopping… (press Ctrl+C again to force)');
246
+ // A stop that was asked for and completed is a clean exit, whatever
247
+ // code the children ended with on the way (130 after SIGINT made `bun
248
+ // run` report the stop as an error). Forced, it reports the interrupt.
249
+ void stopAll(signal).then(() => process.exit(presses > 1 ? 130 : 0));
250
+ };
176
251
  for (const signal of ['SIGINT', 'SIGTERM'] as const) {
177
252
  process.on(signal, () => {
178
- received++;
179
- // A second Ctrl+C means "stop waiting".
180
- if (received > 1) {
181
- for (const supervisor of supervisors) void supervisor.kill();
253
+ if (signal === 'SIGINT' && presses === 1 && runnerCopyPending) {
254
+ runnerCopyPending = false;
255
+ return;
256
+ }
257
+ presses++;
258
+ if (presses === 1) {
259
+ begin(signal);
182
260
  return;
183
261
  }
184
- void stopAll(signal).then((code) => process.exit(code));
262
+ // A second press means "stop waiting": everything goes now, and the
263
+ // exit still waits until it is gone.
264
+ log('Forcing stop…');
265
+ for (const supervisor of supervisors) void supervisor.kill();
185
266
  });
186
267
  }
187
- // The terminal closed: keep supervising (the server keeps running too).
188
- process.on('SIGHUP', () => {});
268
+ // The terminal closed. Started from one, everything goes with it — leaving
269
+ // a server running behind a closed tab is what users did not expect. Run in
270
+ // the background (`nohup`, a service: no terminal on stdout), it keeps going.
271
+ const startedInTerminal = process.stdout.isTTY === true;
272
+ process.on('SIGHUP', () => {
273
+ if (!startedInTerminal || presses > 0) return;
274
+ presses++;
275
+ begin('SIGTERM');
276
+ });
189
277
  for (const stream of [process.stdout, process.stderr]) {
190
278
  stream.on('error', () => {
191
279
  // EIO/EPIPE once the terminal is gone — nothing left to write to.
192
280
  });
193
281
  }
282
+ // Only now, with every handler installed: this runs `ps`, and until a
283
+ // handler exists a signal takes its default action — SIGHUP or SIGINT
284
+ // killed this process outright and left the child running unsupervised.
285
+ // A signal that arrives meanwhile is queued, and its handler runs after
286
+ // this returns, so it still sees the right value.
287
+ runnerCopyPending = parentForwardsSignals();
194
288
  return stopAll;
195
289
  }
196
290
 
@@ -0,0 +1,99 @@
1
+ /**
2
+ * The processes below a pid, and waiting for them to be gone.
3
+ *
4
+ * A supervised child (the server, the dev frontend) starts processes of its
5
+ * own — engine CLIs, the preview's Chrome, cloudflared — and some of those sit
6
+ * in other process groups, so a signal to the child's group does not reach
7
+ * them. Collected BEFORE anything is signalled: once their parent exits they
8
+ * are re-parented and can no longer be found by parent id.
9
+ *
10
+ * POSIX only (`ps`); on Windows the lists are empty and callers fall back to
11
+ * the single pid.
12
+ */
13
+
14
+ const IS_WINDOWS = process.platform === 'win32';
15
+
16
+ /** Every descendant of `rootPid` (not `rootPid` itself). */
17
+ export function collectDescendants(rootPid: number): number[] {
18
+ if (IS_WINDOWS || !Number.isInteger(rootPid) || rootPid <= 0) return [];
19
+ let output: string;
20
+ try {
21
+ output = new TextDecoder().decode(Bun.spawnSync(['ps', '-A', '-o', 'pid=,ppid='], { stdout: 'pipe', stderr: 'ignore' }).stdout);
22
+ } catch {
23
+ return [];
24
+ }
25
+ const children = new Map<number, number[]>();
26
+ for (const line of output.split('\n')) {
27
+ const [pid, ppid] = line.trim().split(/\s+/).map(Number);
28
+ if (!pid || ppid === undefined || Number.isNaN(ppid)) continue;
29
+ const list = children.get(ppid);
30
+ if (list) list.push(pid);
31
+ else children.set(ppid, [pid]);
32
+ }
33
+ const found = new Set<number>();
34
+ const queue = [rootPid];
35
+ while (queue.length > 0) {
36
+ const pid = queue.pop()!;
37
+ for (const child of children.get(pid) ?? []) {
38
+ if (found.has(child) || child === rootPid || child === process.pid) continue;
39
+ found.add(child);
40
+ queue.push(child);
41
+ }
42
+ }
43
+ return [...found];
44
+ }
45
+
46
+ /** Whether `pid` still exists (one we may not signal counts as existing). */
47
+ export function isAlive(pid: number): boolean {
48
+ try {
49
+ process.kill(pid, 0);
50
+ return true;
51
+ } catch (err) {
52
+ return (err as NodeJS.ErrnoException).code === 'EPERM';
53
+ }
54
+ }
55
+
56
+ /** Send `signal` to every pid still there. */
57
+ export function signalAll(pids: number[], signal: NodeJS.Signals): void {
58
+ for (const pid of pids) {
59
+ try {
60
+ process.kill(pid, signal);
61
+ } catch {
62
+ // Already gone.
63
+ }
64
+ }
65
+ }
66
+
67
+ /** Resolves once none of `pids` exists, or after `timeoutMs`; returns the survivors. */
68
+ export async function waitForExit(pids: number[], timeoutMs: number, pollMs = 50): Promise<number[]> {
69
+ const deadline = Date.now() + timeoutMs;
70
+ let alive = pids.filter(isAlive);
71
+ while (alive.length > 0 && Date.now() < deadline) {
72
+ await new Promise((resolve) => setTimeout(resolve, pollMs));
73
+ alive = alive.filter(isAlive);
74
+ }
75
+ return alive;
76
+ }
77
+
78
+ /**
79
+ * Whether this process's parent forwards terminal signals to it: a script
80
+ * runner (`bun run`, `bun x`) in the same process group. A Ctrl+C reaches the
81
+ * whole foreground group — runner and child — and the runner then forwards its
82
+ * copy, so the child receives the FIRST Ctrl+C twice (measured: 1 ms apart;
83
+ * later presses arrive once). A plain shell does not forward.
84
+ */
85
+ export function parentForwardsSignals(): boolean {
86
+ if (IS_WINDOWS) return false;
87
+ try {
88
+ const read = (pid: number, field: string) =>
89
+ new TextDecoder().decode(Bun.spawnSync(['ps', '-o', `${field}=`, '-p', String(pid)], { stdout: 'pipe', stderr: 'ignore' }).stdout).trim();
90
+ const ownGroup = read(process.pid, 'pgid');
91
+ const parentGroup = read(process.ppid, 'pgid');
92
+ if (!ownGroup || ownGroup !== parentGroup) return false;
93
+ const command = read(process.ppid, 'command');
94
+ const program = command.split(/\s+/)[0]?.split('/').pop() ?? '';
95
+ return program === 'bun' || program === 'bunx' || program === 'bun.exe';
96
+ } catch {
97
+ return false;
98
+ }
99
+ }
@@ -0,0 +1,57 @@
1
+ import { afterAll, describe, expect, test } from 'bun:test';
2
+ import { existsSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
3
+ import { tmpdir } from 'node:os';
4
+ import { join } from 'node:path';
5
+
6
+ import { clearRestartIntent, readRestartIntent, writeRestartIntent } from './restart-intent';
7
+
8
+ const dir = mkdtempSync(join(tmpdir(), 'clopen-restart-intent-'));
9
+ const file = join(dir, 'restart-intent.json');
10
+ afterAll(() => rmSync(dir, { recursive: true, force: true }));
11
+
12
+ describe('restart intent', () => {
13
+ test('is read by the child of the supervisor it names, until the server is listening', () => {
14
+ writeRestartIntent(dir, 9142, 4242);
15
+ expect(readRestartIntent(dir, 4242)?.port).toBe(9142);
16
+ // A successor that failed to start is retried, and must find it again.
17
+ expect(readRestartIntent(dir, 4242)?.port).toBe(9142);
18
+ clearRestartIntent(dir, 4242);
19
+ expect(readRestartIntent(dir, 4242)).toBeNull();
20
+ expect(existsSync(file)).toBe(false);
21
+ });
22
+
23
+ test('is not cleared by a server another supervisor started', () => {
24
+ writeRestartIntent(dir, 9142, 4242);
25
+ // A second instance on the same data directory finishing its own start.
26
+ clearRestartIntent(dir, 5555);
27
+ expect(readRestartIntent(dir, 4242)?.port).toBe(9142);
28
+ clearRestartIntent(dir, 4242);
29
+ expect(existsSync(file)).toBe(false);
30
+ });
31
+
32
+ test('is ignored, and kept, by a process another supervisor started', () => {
33
+ writeRestartIntent(dir, 9142, 4242);
34
+ // `clopen --port 9300` right after, or a second instance on this data dir.
35
+ expect(readRestartIntent(dir, 5555)).toBeNull();
36
+ expect(readRestartIntent(dir, 0)).toBeNull();
37
+ expect(existsSync(file)).toBe(true);
38
+ expect(readRestartIntent(dir, 4242)?.port).toBe(9142);
39
+ clearRestartIntent(dir, 4242);
40
+ });
41
+
42
+ test('a stale intent is ignored and removed', () => {
43
+ writeRestartIntent(dir, 9141, 4242);
44
+ expect(readRestartIntent(dir, 4242, Date.now() + 120_000)).toBeNull();
45
+ expect(existsSync(file)).toBe(false);
46
+ });
47
+
48
+ test('a corrupt or old-format intent is ignored and removed', () => {
49
+ writeFileSync(file, '{nope');
50
+ expect(readRestartIntent(dir, 4242)).toBeNull();
51
+ expect(existsSync(file)).toBe(false);
52
+
53
+ writeFileSync(file, JSON.stringify({ port: 9141, at: Date.now() }));
54
+ expect(readRestartIntent(dir, 4242)).toBeNull();
55
+ expect(existsSync(file)).toBe(false);
56
+ });
57
+ });
@@ -0,0 +1,80 @@
1
+ /**
2
+ * The note a server leaves for its successor when it restarts on purpose.
3
+ *
4
+ * scripts/start.ts normally takes the first free port from CLOPEN_PORT up.
5
+ * On a restart that is wrong twice over: the old process may still be letting
6
+ * go of its port, and the server may have been on a fallback port (9142
7
+ * because 9141 was taken) that the browser tab is connected to. Either way
8
+ * the successor would come up somewhere the tab is not looking. The intent
9
+ * says which port to come back on; start.ts waits for it instead of moving.
10
+ *
11
+ * It names the supervisor that will start the successor, and only that
12
+ * supervisor's child honours it. Anything else starting in the same data
13
+ * directory — a `clopen --port 9300` typed right after, a second instance —
14
+ * must not be pulled onto another server's port.
15
+ */
16
+
17
+ import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
18
+ import { join } from 'node:path';
19
+
20
+ export interface RestartIntent {
21
+ port: number;
22
+ /** The supervisor whose next child this is for. */
23
+ supervisorPid: number;
24
+ /** When it was written (ms epoch) — a stale note from a crash is ignored. */
25
+ at: number;
26
+ }
27
+
28
+ const FILE = 'restart-intent.json';
29
+ const MAX_AGE_MS = 60_000;
30
+
31
+ export function writeRestartIntent(dataDir: string, port: number, supervisorPid: number): void {
32
+ mkdirSync(dataDir, { recursive: true });
33
+ writeFileSync(join(dataDir, FILE), JSON.stringify({ port, supervisorPid, at: Date.now() } satisfies RestartIntent));
34
+ }
35
+
36
+ /**
37
+ * The intent left for this process — started by `supervisorPid` — or null when
38
+ * there is none, it is too old, or it is for someone else. A stale or broken
39
+ * intent is removed; a valid one stays until the server is listening again
40
+ * (clearRestartIntent), so a successor that fails to start and is retried by
41
+ * the supervisor still comes back on the same port.
42
+ */
43
+ export function readRestartIntent(dataDir: string, supervisorPid: number, now = Date.now()): RestartIntent | null {
44
+ const path = join(dataDir, FILE);
45
+ if (!existsSync(path)) return null;
46
+ let intent: Partial<RestartIntent>;
47
+ try {
48
+ intent = JSON.parse(readFileSync(path, 'utf-8')) as Partial<RestartIntent>;
49
+ } catch {
50
+ rmSync(path, { force: true });
51
+ return null;
52
+ }
53
+ if (typeof intent.port !== 'number' || typeof intent.at !== 'number' || typeof intent.supervisorPid !== 'number') {
54
+ rmSync(path, { force: true });
55
+ return null;
56
+ }
57
+ if (now - intent.at > MAX_AGE_MS) {
58
+ rmSync(path, { force: true });
59
+ return null;
60
+ }
61
+ if (!(supervisorPid > 0) || intent.supervisorPid !== supervisorPid) return null;
62
+ return { port: intent.port, supervisorPid: intent.supervisorPid, at: intent.at };
63
+ }
64
+
65
+ /**
66
+ * Called once the server is listening: the restart the intent was for is over.
67
+ * Only an intent for this server's supervisor is removed — another instance on
68
+ * the same data directory may be in the middle of its own restart.
69
+ */
70
+ export function clearRestartIntent(dataDir: string, supervisorPid: number): void {
71
+ const path = join(dataDir, FILE);
72
+ if (!existsSync(path)) return;
73
+ try {
74
+ const intent = JSON.parse(readFileSync(path, 'utf-8')) as Partial<RestartIntent>;
75
+ if (intent.supervisorPid !== supervisorPid) return;
76
+ } catch {
77
+ // Unreadable: nobody can use it.
78
+ }
79
+ rmSync(path, { force: true });
80
+ }
@@ -0,0 +1,33 @@
1
+ import { describe, expect, test } from 'bun:test';
2
+
3
+ import { compareVersions, isNewerVersion, stripVersionPrefix } from './semver';
4
+
5
+ describe('compareVersions', () => {
6
+ test('orders numerically, not as text', () => {
7
+ expect(compareVersions('0.4.10', '0.4.9')).toBeGreaterThan(0);
8
+ expect(compareVersions('0.4.9', '0.10.0')).toBeLessThan(0);
9
+ expect(compareVersions('1.0.0', '0.99.99')).toBeGreaterThan(0);
10
+ });
11
+
12
+ test('treats a v prefix and missing parts as equal', () => {
13
+ expect(compareVersions('v0.4.50', '0.4.50')).toBe(0);
14
+ expect(compareVersions('0.5', '0.5.0')).toBe(0);
15
+ });
16
+
17
+ test('ignores pre-release and build suffixes', () => {
18
+ expect(compareVersions('0.4.50-beta.1', '0.4.50')).toBe(0);
19
+ });
20
+ });
21
+
22
+ describe('isNewerVersion', () => {
23
+ test('is true only for a strictly newer candidate', () => {
24
+ expect(isNewerVersion('0.4.49', '0.4.50')).toBe(true);
25
+ expect(isNewerVersion('0.4.50', '0.4.50')).toBe(false);
26
+ expect(isNewerVersion('0.4.50', '0.4.49')).toBe(false);
27
+ });
28
+ });
29
+
30
+ test('stripVersionPrefix', () => {
31
+ expect(stripVersionPrefix('v0.4.50')).toBe('0.4.50');
32
+ expect(stripVersionPrefix('0.4.50')).toBe('0.4.50');
33
+ });
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Just enough semver for Clopen's own release numbers (`0.4.50`, `v0.4.50`).
3
+ *
4
+ * Clopen publishes plain `major.minor.patch` versions, so pre-release tags and
5
+ * build metadata are not ordered — anything after the patch number is ignored.
6
+ */
7
+
8
+ function parts(version: string): number[] {
9
+ return version
10
+ .replace(/^v/, '')
11
+ .split(/[-+]/)[0]
12
+ .split('.')
13
+ .slice(0, 3)
14
+ .map(part => Number.parseInt(part, 10) || 0);
15
+ }
16
+
17
+ /** Negative when `a` is older than `b`, positive when newer, 0 when equal. */
18
+ export function compareVersions(a: string, b: string): number {
19
+ const left = parts(a);
20
+ const right = parts(b);
21
+ for (let i = 0; i < 3; i++) {
22
+ const diff = (left[i] ?? 0) - (right[i] ?? 0);
23
+ if (diff !== 0) return diff;
24
+ }
25
+ return 0;
26
+ }
27
+
28
+ export function isNewerVersion(current: string, candidate: string): boolean {
29
+ return compareVersions(candidate, current) > 0;
30
+ }
31
+
32
+ /** `v0.4.50` → `0.4.50`. */
33
+ export function stripVersionPrefix(version: string): string {
34
+ return version.replace(/^v/, '');
35
+ }
@@ -0,0 +1,44 @@
1
+ /**
2
+ * The child's side of supervision (the server, the dev frontend). The
3
+ * supervisor's side is process-supervisor.ts, which the launcher loads; this
4
+ * file is not, so changing it never counts as a launcher change.
5
+ */
6
+
7
+ import { SUPERVISOR_PID_ENV } from './supervisor-protocol';
8
+
9
+ let supervised = false;
10
+ let supervisor = 0;
11
+
12
+ /**
13
+ * Whether this process runs under a supervisor that will start it again —
14
+ * read by watchSupervisor, so only meaningful after that has been called.
15
+ */
16
+ export function isSupervised(): boolean {
17
+ return supervised;
18
+ }
19
+
20
+ /** The supervising process, or 0 when there is none. Same caveat as isSupervised. */
21
+ export function supervisorPid(): number {
22
+ return supervisor;
23
+ }
24
+
25
+ /**
26
+ * In a supervised child: run `onGone` once the supervisor that started it is
27
+ * gone (its parent pid changes), so the child does not outlive an ungraceful
28
+ * end of its supervisor. The variable is removed from the environment at once:
29
+ * everything the child starts inherits it — terminal shells included — and a
30
+ * dev server started from one would otherwise watch the wrong supervisor.
31
+ */
32
+ export function watchSupervisor(onGone: () => void, pollMs = 1000): void {
33
+ const pid = Number(process.env[SUPERVISOR_PID_ENV]);
34
+ delete process.env[SUPERVISOR_PID_ENV];
35
+ if (!(pid > 0) || process.ppid !== pid) return;
36
+ supervised = true;
37
+ supervisor = pid;
38
+ const timer = setInterval(() => {
39
+ if (process.ppid === pid) return;
40
+ clearInterval(timer);
41
+ onGone();
42
+ }, pollMs);
43
+ timer.unref?.();
44
+ }