@myrialabs/clopen 0.4.47 → 0.4.49

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 (390) hide show
  1. package/README.md +11 -11
  2. package/backend/artifacts/project/sources.ts +1 -1
  3. package/backend/auth/auth-service.ts +52 -358
  4. package/backend/auth/onboarding.test.ts +2 -3
  5. package/backend/auth/permissions.test.ts +10 -20
  6. package/backend/auth/permissions.ts +4 -290
  7. package/backend/auth/rate-limiter.test.ts +8 -9
  8. package/backend/auth/rate-limiter.ts +0 -2
  9. package/backend/auth/tokens.ts +1 -8
  10. package/backend/bootstrap.ts +7 -0
  11. package/backend/chat/attachments.test.ts +88 -0
  12. package/backend/chat/attachments.ts +159 -0
  13. package/backend/chat/engine-handoff.test.ts +0 -2
  14. package/backend/chat/message-pages.test.ts +163 -0
  15. package/backend/chat/message-pages.ts +233 -0
  16. package/backend/chat/stream-manager.ts +91 -67
  17. package/backend/chat/turn-answer.test.ts +64 -0
  18. package/backend/chat/turn-answer.ts +125 -0
  19. package/backend/chat-apps/awaiting.test.ts +39 -0
  20. package/backend/chat-apps/awaiting.ts +49 -0
  21. package/backend/chat-apps/conversation.ts +746 -0
  22. package/backend/chat-apps/inbound.ts +324 -0
  23. package/backend/chat-apps/index.ts +309 -0
  24. package/backend/chat-apps/link-events.ts +20 -0
  25. package/backend/chat-apps/media.test.ts +62 -0
  26. package/backend/chat-apps/media.ts +208 -0
  27. package/backend/chat-apps/messages.test.ts +229 -0
  28. package/backend/chat-apps/messages.ts +365 -0
  29. package/backend/chat-apps/outbound.ts +243 -0
  30. package/backend/chat-apps/pairing.test.ts +45 -0
  31. package/backend/chat-apps/pairing.ts +74 -0
  32. package/backend/chat-apps/platforms/index.ts +20 -0
  33. package/backend/chat-apps/platforms/telegram.test.ts +35 -0
  34. package/backend/chat-apps/platforms/telegram.ts +191 -0
  35. package/backend/chat-apps/platforms/types.ts +114 -0
  36. package/backend/chat-apps/questions.ts +133 -0
  37. package/backend/chat-apps/runtime.ts +572 -0
  38. package/backend/chat-apps/storage.test.ts +201 -0
  39. package/backend/chat-apps/turns.test.ts +45 -0
  40. package/backend/chat-apps/turns.ts +208 -0
  41. package/backend/containers/pty.ts +3 -11
  42. package/backend/control/actions/accounts.ts +89 -0
  43. package/backend/control/actions/files.ts +116 -0
  44. package/backend/control/actions/models.ts +188 -0
  45. package/backend/control/actions/projects.ts +272 -0
  46. package/backend/control/actions/sessions.ts +280 -0
  47. package/backend/control/actions/skills.ts +111 -0
  48. package/backend/control/control.test.ts +169 -0
  49. package/backend/control/define.ts +20 -0
  50. package/backend/control/folders.test.ts +67 -0
  51. package/backend/control/index.ts +213 -0
  52. package/backend/control/invoke.ts +44 -0
  53. package/backend/control/links.ts +35 -0
  54. package/backend/control/paging.ts +26 -0
  55. package/backend/control/types.ts +117 -0
  56. package/backend/control/workspace.ts +127 -0
  57. package/backend/database/migrations/084_create_channel_links.ts +71 -0
  58. package/backend/database/migrations/085_add_home_projects.ts +36 -0
  59. package/backend/database/migrations/086_single_owner.ts +418 -0
  60. package/backend/database/migrations/087_create_blob_line_stats.ts +37 -0
  61. package/backend/database/migrations/index.ts +28 -0
  62. package/backend/database/queries/auth-queries.ts +7 -85
  63. package/backend/database/queries/blob-line-stats-queries.ts +48 -0
  64. package/backend/database/queries/channel-queries.ts +270 -0
  65. package/backend/database/queries/db-client-connection-queries.ts +18 -56
  66. package/backend/database/queries/file-share-queries.ts +5 -23
  67. package/backend/database/queries/git-identity-queries.ts +31 -42
  68. package/backend/database/queries/graph-queries.ts +1 -1
  69. package/backend/database/queries/index.ts +15 -1
  70. package/backend/database/queries/message-queries.test.ts +146 -0
  71. package/backend/database/queries/message-queries.ts +42 -1
  72. package/backend/database/queries/permission-set-queries.ts +1 -1
  73. package/backend/database/queries/profile-queries.ts +1 -1
  74. package/backend/database/queries/project-mcp-trust-queries.ts +1 -1
  75. package/backend/database/queries/project-queries.ts +50 -63
  76. package/backend/database/queries/session-queries.ts +28 -56
  77. package/backend/database/queries/ssh-connection-queries.ts +18 -41
  78. package/backend/db-client/env/diff.ts +9 -33
  79. package/backend/db-client/env/env.test.ts +8 -8
  80. package/backend/db-client/env/service.ts +1 -1
  81. package/backend/db-client/integrations/projector.ts +0 -5
  82. package/backend/engine/adapters/claude/message-converter.test.ts +47 -0
  83. package/backend/engine/adapters/claude/message-converter.ts +25 -2
  84. package/backend/engine/adapters/cline/message-converter.ts +0 -1
  85. package/backend/engine/adapters/cline/stream.ts +11 -15
  86. package/backend/engine/adapters/codex/message-converter.ts +0 -2
  87. package/backend/engine/adapters/copilot/message-converter.ts +1 -2
  88. package/backend/engine/adapters/cursor/message-converter.ts +0 -1
  89. package/backend/engine/adapters/opencode/message-converter.ts +2 -4
  90. package/backend/engine/adapters/opencode/stream.ts +11 -0
  91. package/backend/engine/adapters/parent-scope.test.ts +38 -0
  92. package/backend/engine/adapters/parent-scope.ts +44 -0
  93. package/backend/engine/adapters/pi/message-converter.ts +0 -1
  94. package/backend/engine/adapters/pi/stream.ts +4 -5
  95. package/backend/engine/adapters/qwen/message-converter.ts +0 -2
  96. package/backend/engine/bootstrap-default-engine.ts +2 -2
  97. package/backend/engine/docs/adapter-contract.md +8 -1
  98. package/backend/engine/install-runner.ts +8 -17
  99. package/backend/files/file-shares.ts +20 -44
  100. package/backend/files/file-size-limit.ts +3 -3
  101. package/backend/files/file-watcher.ts +19 -0
  102. package/backend/files/image-processing.ts +1 -1
  103. package/backend/files/os-clipboard.ts +2 -2
  104. package/backend/git/contributors.test.ts +35 -0
  105. package/backend/git/contributors.ts +46 -0
  106. package/backend/git/git-executor.ts +25 -5
  107. package/backend/git/git-service.ts +420 -19
  108. package/backend/git/identity/credential-helper.test.ts +2 -7
  109. package/backend/git/identity/import-local.test.ts +11 -16
  110. package/backend/git/identity/import-local.ts +12 -12
  111. package/backend/git/identity/index.ts +10 -24
  112. package/backend/git/identity/resolve.ts +13 -14
  113. package/backend/git/identity/scope-config.ts +33 -28
  114. package/backend/git/identity/service.ts +44 -47
  115. package/backend/git/op-lock.test.ts +111 -0
  116. package/backend/git/op-lock.ts +180 -0
  117. package/backend/git/remote-sync.test.ts +249 -0
  118. package/backend/host/metrics.ts +1 -1
  119. package/backend/http/bearer-auth.ts +1 -2
  120. package/backend/http/files-download.test.ts +8 -9
  121. package/backend/http/files-download.ts +2 -2
  122. package/backend/http/files-shared.test.ts +62 -89
  123. package/backend/http/files-shared.ts +2 -2
  124. package/backend/http/files-upload.test.ts +3 -7
  125. package/backend/http/files-upload.ts +3 -3
  126. package/backend/http/notes-images.test.ts +15 -38
  127. package/backend/http/notes-images.ts +6 -8
  128. package/backend/http/ssh-sftp.ts +5 -10
  129. package/backend/http/static-assets.test.ts +78 -0
  130. package/backend/http/static-assets.ts +104 -0
  131. package/backend/index.ts +32 -16
  132. package/backend/integrations/accounts.ts +61 -3
  133. package/backend/integrations/index.ts +2 -2
  134. package/backend/integrations/registry/define.ts +15 -0
  135. package/backend/integrations/registry/index.ts +2 -0
  136. package/backend/integrations/registry/providers/telegram.ts +54 -0
  137. package/backend/integrations/registry/types.ts +21 -1
  138. package/backend/integrations/webhooks/gateway.ts +7 -6
  139. package/backend/integrations/webhooks/verify.test.ts +30 -0
  140. package/backend/integrations/webhooks/verify.ts +4 -0
  141. package/backend/mcp/external/project.ts +1 -1
  142. package/backend/mcp/internal/remote-server.test.ts +1 -3
  143. package/backend/mcp/internal/remote-server.ts +4 -4
  144. package/backend/mcp/internal/servers/browser-automation/actions/dialogs.ts +67 -0
  145. package/backend/mcp/internal/servers/browser-automation/actions/index.ts +3 -1
  146. package/backend/mcp/internal/servers/browser-automation/actions/input.ts +5 -5
  147. package/backend/mcp/internal/servers/browser-automation/actions/tabs.ts +157 -28
  148. package/backend/mcp/internal/servers/browser-automation/context.ts +1 -0
  149. package/backend/mcp/internal/servers/browser-automation/description.ts +5 -2
  150. package/backend/mcp/internal/servers/browser-automation/format.ts +24 -1
  151. package/backend/mcp/internal/servers/browser-automation/runner.ts +68 -3
  152. package/backend/memory/redact.ts +1 -1
  153. package/backend/notes/access.test.ts +28 -29
  154. package/backend/notes/access.ts +6 -11
  155. package/backend/permissions/service.ts +1 -1
  156. package/backend/preview/browser/browser-clipboard.test.ts +46 -0
  157. package/backend/preview/browser/browser-clipboard.ts +67 -0
  158. package/backend/preview/browser/browser-dialog-handler.ts +95 -6
  159. package/backend/preview/browser/browser-host-bridge.ts +9 -0
  160. package/backend/preview/browser/browser-interaction-handler.ts +316 -86
  161. package/backend/preview/browser/browser-mcp-control.ts +34 -0
  162. package/backend/preview/browser/browser-pool.ts +67 -6
  163. package/backend/preview/browser/browser-preview-service.ts +383 -29
  164. package/backend/preview/browser/browser-tab-manager.ts +66 -23
  165. package/backend/preview/browser/browser-video-capture.ts +92 -5
  166. package/backend/preview/browser/element-locator.ts +190 -17
  167. package/backend/preview/browser/keyboard-chords.test.ts +68 -0
  168. package/backend/preview/browser/keyboard-chords.ts +132 -0
  169. package/backend/preview/browser/paste.ts +81 -0
  170. package/backend/preview/browser/process-usage.ts +142 -0
  171. package/backend/preview/browser/profile-lock.ts +209 -0
  172. package/backend/preview/browser/scripts/host-bridge.ts +59 -0
  173. package/backend/preview/browser/scripts/video-stream.ts +58 -0
  174. package/backend/preview/browser/types.ts +40 -2
  175. package/backend/preview/browser/viewport.test.ts +45 -0
  176. package/backend/preview/browser/viewport.ts +96 -0
  177. package/backend/profiles/service.ts +2 -2
  178. package/backend/project/status-manager.ts +43 -172
  179. package/backend/projects/home.ts +61 -0
  180. package/backend/projects/project-cleanup.integration.test.ts +2 -2
  181. package/backend/projects/project-cleanup.ts +0 -8
  182. package/backend/skills/service.ts +2 -3
  183. package/backend/snapshot/blob-store.ts +9 -1
  184. package/backend/snapshot/helpers.ts +3 -11
  185. package/backend/snapshot/line-stats.test.ts +80 -0
  186. package/backend/snapshot/line-stats.ts +64 -0
  187. package/backend/snapshot/restore.ts +252 -0
  188. package/backend/snapshot/snapshot-service.ts +14 -27
  189. package/backend/snapshot/turn-changes.test.ts +10 -5
  190. package/backend/snapshot/turn-changes.ts +78 -40
  191. package/backend/ssh/ptykit.ts +1 -2
  192. package/backend/terminal/ptykit.ts +10 -8
  193. package/backend/tunnel/public-origin.ts +31 -20
  194. package/backend/utils/user-helpers.ts +0 -55
  195. package/backend/utils/ws-wire.test.ts +87 -0
  196. package/backend/utils/ws-wire.ts +189 -0
  197. package/backend/utils/ws.ts +101 -192
  198. package/backend/worktrees/branching/engine.ts +3 -16
  199. package/backend/worktrees/branching/index.ts +1 -1
  200. package/backend/worktrees/branching/projector.ts +1 -1
  201. package/backend/worktrees/branching/service.ts +13 -25
  202. package/backend/ws/access.ts +12 -21
  203. package/backend/ws/artifacts/generate.ts +2 -2
  204. package/backend/ws/auth/device.ts +16 -71
  205. package/backend/ws/auth/index.ts +4 -22
  206. package/backend/ws/auth/login.test.ts +14 -60
  207. package/backend/ws/auth/login.ts +24 -124
  208. package/backend/ws/auth/status.ts +0 -1
  209. package/backend/ws/chat/composer.ts +118 -118
  210. package/backend/ws/chat/stream.ts +105 -57
  211. package/backend/ws/chat-apps/index.ts +117 -0
  212. package/backend/ws/containers/actions.ts +11 -25
  213. package/backend/ws/containers/index.ts +3 -4
  214. package/backend/ws/containers/list.ts +10 -36
  215. package/backend/ws/containers/logs.ts +2 -2
  216. package/backend/ws/containers/tunnel.ts +1 -2
  217. package/backend/ws/db-client/access.ts +2 -16
  218. package/backend/ws/db-client/accounts.ts +5 -15
  219. package/backend/ws/db-client/connections.ts +17 -25
  220. package/backend/ws/db-client/context.ts +1 -1
  221. package/backend/ws/db-client/env.ts +7 -10
  222. package/backend/ws/db-client/index.ts +2 -2
  223. package/backend/ws/db-client/io.ts +5 -5
  224. package/backend/ws/db-client/query-history-retention.test.ts +8 -8
  225. package/backend/ws/db-client/query.ts +18 -17
  226. package/backend/ws/db-client/schema.ts +13 -13
  227. package/backend/ws/db-client/structure.ts +35 -35
  228. package/backend/ws/db-client/supabase.ts +4 -21
  229. package/backend/ws/deployments/context.ts +1 -1
  230. package/backend/ws/deployments/crud.ts +0 -5
  231. package/backend/ws/engine/access.ts +7 -20
  232. package/backend/ws/engine/claude/accounts.ts +4 -4
  233. package/backend/ws/engine/cline/accounts.ts +5 -5
  234. package/backend/ws/engine/codex/accounts.ts +3 -3
  235. package/backend/ws/engine/pi/accounts.ts +5 -5
  236. package/backend/ws/files/clipboard.ts +8 -27
  237. package/backend/ws/files/image-edit.ts +6 -6
  238. package/backend/ws/files/index.ts +1 -1
  239. package/backend/ws/files/path-access.test.ts +32 -131
  240. package/backend/ws/files/path-access.ts +8 -87
  241. package/backend/ws/files/read.ts +45 -19
  242. package/backend/ws/files/reveal.ts +3 -3
  243. package/backend/ws/files/search.ts +7 -7
  244. package/backend/ws/files/share.ts +9 -13
  245. package/backend/ws/files/state.ts +9 -12
  246. package/backend/ws/files/watch.ts +3 -3
  247. package/backend/ws/files/write.ts +30 -31
  248. package/backend/ws/git/branch.ts +80 -59
  249. package/backend/ws/git/commit.ts +63 -44
  250. package/backend/ws/git/conflict.ts +16 -18
  251. package/backend/ws/git/identity-context.ts +8 -17
  252. package/backend/ws/git/identity.ts +17 -27
  253. package/backend/ws/git/index.ts +3 -1
  254. package/backend/ws/git/log.ts +52 -0
  255. package/backend/ws/git/op-state.ts +139 -0
  256. package/backend/ws/git/remote.ts +241 -141
  257. package/backend/ws/git/repo-context.ts +67 -0
  258. package/backend/ws/git/staging.ts +18 -28
  259. package/backend/ws/git/status.ts +5 -2
  260. package/backend/ws/index.ts +5 -1
  261. package/backend/ws/instructions/crud.ts +1 -1
  262. package/backend/ws/integrations/crud.ts +1 -3
  263. package/backend/ws/mcp/crud.ts +3 -5
  264. package/backend/ws/mcp/tools.ts +1 -1
  265. package/backend/ws/memory/crud.ts +14 -46
  266. package/backend/ws/memory/index.ts +2 -2
  267. package/backend/ws/messages/crud.ts +78 -8
  268. package/backend/ws/notes/index.ts +33 -39
  269. package/backend/ws/permissions/crud.ts +3 -4
  270. package/backend/ws/ports/index.ts +1 -2
  271. package/backend/ws/ports/kill.ts +5 -10
  272. package/backend/ws/ports/list.ts +4 -10
  273. package/backend/ws/preview/access.ts +1 -1
  274. package/backend/ws/preview/browser/interact.ts +52 -79
  275. package/backend/ws/preview/browser/native-ui.ts +24 -0
  276. package/backend/ws/preview/browser/stats.ts +98 -1
  277. package/backend/ws/preview/browser/tab-info.ts +15 -0
  278. package/backend/ws/preview/browser/tab.ts +19 -4
  279. package/backend/ws/preview/index.ts +29 -0
  280. package/backend/ws/preview/watchers.ts +84 -0
  281. package/backend/ws/profiles/crud.ts +6 -8
  282. package/backend/ws/project-artifacts/index.ts +30 -31
  283. package/backend/ws/projects/crud.ts +33 -35
  284. package/backend/ws/projects/index.ts +3 -8
  285. package/backend/ws/projects/info.ts +3 -3
  286. package/backend/ws/projects/overview.ts +19 -30
  287. package/backend/ws/projects/status.ts +17 -57
  288. package/backend/ws/sessions/crud.ts +42 -57
  289. package/backend/ws/sessions/index.ts +1 -1
  290. package/backend/ws/settings/crud.ts +1 -1
  291. package/backend/ws/skills/crud.ts +3 -4
  292. package/backend/ws/skills/index.ts +1 -1
  293. package/backend/ws/snapshot/changes.ts +12 -13
  294. package/backend/ws/snapshot/restore.ts +11 -295
  295. package/backend/ws/snapshot/timeline.ts +2 -4
  296. package/backend/ws/ssh/access.ts +6 -21
  297. package/backend/ws/ssh/connections.ts +21 -31
  298. package/backend/ws/ssh/forwards.ts +12 -12
  299. package/backend/ws/ssh/sftp.ts +34 -34
  300. package/backend/ws/ssh/tunnel.ts +1 -2
  301. package/backend/ws/stack/install.ts +7 -17
  302. package/backend/ws/subagents/crud.ts +1 -1
  303. package/backend/ws/terminal/tunnel.ts +2 -2
  304. package/backend/ws/tunnel/share.ts +0 -2
  305. package/backend/ws/user/crud.ts +1 -59
  306. package/backend/ws/user/index.ts +1 -1
  307. package/backend/ws/work/context.ts +1 -1
  308. package/backend/ws/work/crud.ts +0 -5
  309. package/backend/ws/workspace/state.ts +10 -13
  310. package/backend/ws/worktrees/branching.ts +7 -36
  311. package/backend/ws/worktrees/crud.ts +2 -2
  312. package/bin/clopen.ts +46 -41
  313. package/dist/assets/addon-clipboard-wHJhZAA4.js.br +0 -0
  314. package/dist/assets/addon-clipboard-wHJhZAA4.js.gz +0 -0
  315. package/dist/assets/addon-fit-DX4qG4td.js.br +1 -0
  316. package/dist/assets/addon-fit-DX4qG4td.js.gz +0 -0
  317. package/dist/assets/addon-ligatures-DpDY8N_X.js.br +0 -0
  318. package/dist/assets/addon-ligatures-DpDY8N_X.js.gz +0 -0
  319. package/dist/assets/addon-unicode11-Bt8F3D7-.js.br +0 -0
  320. package/dist/assets/addon-unicode11-Bt8F3D7-.js.gz +0 -0
  321. package/dist/assets/addon-web-links-DIbG5aQx.js.br +0 -0
  322. package/dist/assets/addon-web-links-DIbG5aQx.js.gz +0 -0
  323. package/dist/assets/diff.worker-BoHLxmr2.js +7 -0
  324. package/dist/assets/diff.worker-BoHLxmr2.js.br +0 -0
  325. package/dist/assets/diff.worker-BoHLxmr2.js.gz +0 -0
  326. package/dist/assets/graph-layout.worker-CRFqN7ZQ.js.br +0 -0
  327. package/dist/assets/graph-layout.worker-CRFqN7ZQ.js.gz +0 -0
  328. package/dist/assets/{index-CwuKQelV.js → index-CrVWZH_D.js} +1 -1
  329. package/dist/assets/index-CrVWZH_D.js.br +0 -0
  330. package/dist/assets/index-CrVWZH_D.js.gz +0 -0
  331. package/dist/assets/{index-BTcR1byF.js → index-DD0-3EWg.js} +1 -1
  332. package/dist/assets/index-DD0-3EWg.js.br +0 -0
  333. package/dist/assets/index-DD0-3EWg.js.gz +0 -0
  334. package/dist/assets/main-D2_TmcwQ.js +1240 -0
  335. package/dist/assets/main-D2_TmcwQ.js.br +0 -0
  336. package/dist/assets/main-D2_TmcwQ.js.gz +0 -0
  337. package/dist/assets/main-Yucigcmf.css +1 -0
  338. package/dist/assets/main-Yucigcmf.css.br +0 -0
  339. package/dist/assets/main-Yucigcmf.css.gz +0 -0
  340. package/dist/assets/preview-video.worker-DcpDhCWL.js.br +0 -0
  341. package/dist/assets/preview-video.worker-DcpDhCWL.js.gz +0 -0
  342. package/dist/assets/xterm-B-qIQCd3.js.br +0 -0
  343. package/dist/assets/xterm-B-qIQCd3.js.gz +0 -0
  344. package/dist/assets/zipkit-engine-CaR0t_Uy.wasm.br +0 -0
  345. package/dist/assets/zipkit-engine-CaR0t_Uy.wasm.gz +0 -0
  346. package/dist/fonts/dm-sans.css.br +0 -0
  347. package/dist/fonts/dm-sans.css.gz +0 -0
  348. package/dist/index.html +2 -2
  349. package/dist/index.html.br +0 -0
  350. package/dist/index.html.gz +0 -0
  351. package/dist/sw.js.br +0 -0
  352. package/dist/sw.js.gz +0 -0
  353. package/package.json +3 -3
  354. package/shared/constants/attachments.ts +14 -0
  355. package/shared/constants/engine-tools.ts +1 -1
  356. package/shared/constants/preview.test.ts +259 -0
  357. package/shared/constants/preview.ts +1018 -57
  358. package/shared/constants/tool-icons.ts +5 -0
  359. package/shared/types/containers/container.ts +1 -1
  360. package/shared/types/database/schema.ts +9 -6
  361. package/shared/types/git-identity.ts +1 -1
  362. package/shared/types/git.ts +116 -0
  363. package/shared/types/integrations.ts +7 -0
  364. package/shared/types/stores/settings.ts +1 -1
  365. package/shared/types/unified/index.ts +1 -1
  366. package/shared/types/unified/message.ts +0 -7
  367. package/shared/types/unified/stream.ts +13 -5
  368. package/shared/types/unified/tool.ts +15 -1
  369. package/shared/utils/ask-user-question.test.ts +319 -0
  370. package/shared/utils/ask-user-question.ts +154 -0
  371. package/shared/utils/diff-calculator.test.ts +178 -41
  372. package/shared/utils/diff-calculator.ts +383 -100
  373. package/shared/utils/home-project.ts +25 -0
  374. package/shared/utils/logger.ts +2 -0
  375. package/shared/utils/process-supervisor.test.ts +172 -0
  376. package/shared/utils/process-supervisor.ts +251 -0
  377. package/shared/utils/ws-chunk.test.ts +33 -0
  378. package/shared/utils/ws-chunk.ts +73 -0
  379. package/shared/utils/ws-client-chunks.test.ts +45 -0
  380. package/shared/utils/ws-client.ts +43 -0
  381. package/shared/utils/ws-server.ts +49 -21
  382. package/backend/auth/session-invalidation.test.ts +0 -112
  383. package/backend/auth/session-invalidation.ts +0 -77
  384. package/backend/project/status-manager.test.ts +0 -32
  385. package/backend/ws/auth/invites.ts +0 -94
  386. package/backend/ws/auth/users.ts +0 -112
  387. package/backend/ws/projects/presence.ts +0 -46
  388. package/backend/ws/stack/access.ts +0 -31
  389. package/dist/assets/main-BiDNMWb3.css +0 -1
  390. package/dist/assets/main-BlhKWz2B.js +0 -1241
package/README.md CHANGED
@@ -26,7 +26,7 @@
26
26
  <img src="https://clopen.myrialabs.dev/images/workspace.webp" alt="Clopen workspace overview" />
27
27
  </p>
28
28
 
29
- All-in-one workspace for AI coding agents — Claude Code, OpenCode, Codex, Copilot, Qwen Code, Pi, Cline, and Cursor. Chat, terminal, git, browser preview, database client, and real-time collaboration — plus Skills, Subagents, Commands, and MCP connectors to extend every engine.
29
+ All-in-one workspace for AI coding agents — Claude Code, OpenCode, Codex, Copilot, Qwen Code, Pi, Cline, and Cursor. Chat, terminal, git, browser preview, database client, and remote access from any device — plus Skills, Subagents, Commands, and MCP connectors to extend every engine.
30
30
 
31
31
  ---
32
32
 
@@ -58,19 +58,19 @@ A complete development environment designed around AI-assisted workflows, built
58
58
 
59
59
  - **Multi-Engine Support** — Switch between Claude Code, OpenCode, Codex, GitHub Copilot, Qwen Code, Pi, Cline, and Cursor as your AI engine, per session
60
60
  - **Multi-Account Per Engine** — Manage multiple accounts per engine (personal, work, or team) and switch between them instantly per chat session
61
- - **Reasoning Effort Control** — Dial a model's thinking level right from the chat input, using that engine's own levels. Set a default per model in Settings, and the choice is remembered and synced with everyone in the session
61
+ - **Reasoning Effort Control** — Dial a model's thinking level right from the chat input, using that engine's own levels. Set a default per model in Settings, and the choice is remembered and synced across your devices
62
62
  - **Integrated Terminal** — Multi-tab xterm.js terminal with full keyboard control and complete ANSI/VT support, right inside your workspace
63
63
  - **Full Git Management** — Stage, commit, branch, push, pull, stash, log, and resolve conflicts, all from a clean UI
64
64
  - **Real Browser Preview** — A live browser preview streams directly into your workspace. Interact with your app manually, or let the AI drive: clicking, typing, and scrolling for autonomous visual testing
65
65
  - **Database Client** — Connect to PostgreSQL, MySQL, SQLite, MongoDB, and Redis. Browse schemas, run queries, and inspect data, with optional SSH tunneling for databases behind a bastion
66
66
  - **Git-Like Checkpoints** — Multi-branch undo/redo with full file snapshots. Roll back to any point in your AI conversation without touching your actual git history
67
- - **Real-Time Collaboration** — See who's working on which project, and collaborate live in the same codebase
67
+ - **Remote Access** — Add your phone, tablet, or another computer with a one-time link or QR code. Every device stays in sync live: chats, terminals, and the browser preview
68
68
  - **Monaco File Editor** — VS Code's editor right in the browser. Full syntax highlighting, autocomplete, and live file watching, beside your AI chat
69
69
  - **Cloudflare Tunnel** — One-click public HTTPS URL for your local dev server. Built-in QR code for instant mobile access. Share your work without deploying
70
70
  - **Integrations** — Connect a third-party account once and every engine and project can use it. Credentials are sealed at rest with AES-256-GCM. Includes the full MCP surface: browse the official Model Context Protocol registry, connect with OAuth or custom env/headers, control tool exposure per engine, and sync every connector across all your AI engines
71
71
  - **Skills, Commands & Subagents** — Build reusable Skills, slash Commands, delegated Subagents, shared Instructions, and tool Permissions or Profiles once, synced automatically across every engine
72
- - **Flexible Authentication** — No Login or With Login mode with admin/member roles, invite links, rate-limited login, and CLI token recovery
73
- - **Stack** — Install AI engines, Git, Chrome, and Cloudflared (for Public Tunnel) from a one-click admin panel. Engines install on demand into a clopen-managed directory (`~/.clopen/stack/engines`) — isolated from your global setup, no PATH pollution
72
+ - **Flexible Authentication** — No Login or With Login mode, one-time device pairing links, rate-limited login, and CLI token recovery
73
+ - **Stack** — Install AI engines, Git, Chrome, and Cloudflared (for Public Tunnel) from a one-click panel. Engines install on demand into a clopen-managed directory (`~/.clopen/stack/engines`) — isolated from your global setup, no PATH pollution
74
74
  - **Background Processing** — Chat, terminal, and other processes continue running even when you close the browser — come back later and pick up where you left off
75
75
  - **Works on Any Device** — Fully responsive across desktop, laptop, tablet, and mobile. Open your workspace from any device and continue exactly where you left off
76
76
 
@@ -115,23 +115,23 @@ Starts the server on `http://localhost:9141`.
115
115
 
116
116
  On first launch, a setup wizard guides you through:
117
117
 
118
- 1. **Authentication mode** — Choose between **No Login** (no authentication required, ideal for personal/local use) or **With Login** (login with Personal Access Token, supports team collaboration)
119
- 2. **Admin account** — If With Login mode is selected, create your admin account and save the generated PAT
118
+ 1. **Authentication mode** — Choose between **No Login** (no authentication required, ideal for personal/local use) or **With Login** (login with a Personal Access Token, recommended when Clopen is reachable from other devices or the internet)
119
+ 2. **Account** — If With Login mode is selected, create your account and save the generated PAT
120
120
  3. **Stack** — Install Git, Chrome, Cloudflared, and any AI engine you don't have yet — straight from the wizard, no terminal needed
121
121
  4. **AI Engines** — Check installation status for every engine and sign in to the ones you'll use. An engine that isn't installed yet links straight back to the Stack step
122
122
  5. **Preferences** — Set dark mode, font size, sound notifications, and message layout (Classic cards or Compact lines)
123
123
 
124
- You can change the authentication mode anytime in **Settings → Security → Authentication**.
124
+ You can change the authentication mode anytime in **Settings → Sign-in & Devices**.
125
125
 
126
- To invite team members (With Login mode), go to **Settings → Team → Invite** and generate an invite link (valid for 15 minutes).
126
+ To sign in another of your devices, open **Remote Access → Add a device** and scan the one-time link (valid for 5 minutes).
127
127
 
128
- If you lose your admin token:
128
+ If you lose your token:
129
129
 
130
130
  ```bash
131
131
  clopen reset-pat
132
132
  ```
133
133
 
134
- This regenerates and displays a new admin PAT.
134
+ This regenerates and displays a new PAT.
135
135
 
136
136
  ---
137
137
 
@@ -78,7 +78,7 @@ export const PROJECT_SOURCES: readonly ProjectSource[] = [
78
78
  { id: 'cursor-rules', kind: 'instruction', path: '.cursor/rules', layout: 'md-dir', native: [] },
79
79
  { id: 'clinerules', kind: 'instruction', path: '.clinerules', layout: 'file', native: [] },
80
80
 
81
- // ── MCP ── `.agents/mcp.json` is Clopen's convention, delivered after an admin trusts it.
81
+ // ── MCP ── `.agents/mcp.json` is Clopen's convention, delivered once it is trusted.
82
82
  { id: 'agents-mcp', kind: 'mcp', path: '.agents/mcp.json', layout: 'file', native: [], editable: true },
83
83
  { id: 'root-mcp', kind: 'mcp', path: '.mcp.json', layout: 'file', native: ['claude'] }
84
84
  ];
@@ -1,19 +1,25 @@
1
1
  /**
2
2
  * Auth Service
3
3
  *
4
- * Core authentication logic: user creation, session management, invite handling.
4
+ * Core authentication logic. Clopen has exactly one account — the owner — who
5
+ * signs in from any number of devices; every device is an auth session.
5
6
  */
6
7
 
7
- import { authQueries, projectQueries } from '$backend/database/queries';
8
+ import { authQueries } from '$backend/database/queries';
8
9
  import { readSystemSettings, writeSystemSettings } from '$backend/settings/system-settings';
9
- import type { Project } from '$shared/types/database/schema';
10
- import { generateSessionToken, generatePAT, generateInviteToken, generateDeviceCode, hashToken, getTokenType } from './tokens';
10
+ import { generateSessionToken, generatePAT, generateDeviceCode, hashToken, getTokenType } from './tokens';
11
11
  import { generateColorFromString, getInitials } from '$backend/utils/user-helpers';
12
12
  import { debug } from '$shared/utils/logger';
13
13
 
14
14
  /** Default session lifetime in days */
15
15
  const DEFAULT_SESSION_DAYS = 30;
16
16
 
17
+ /**
18
+ * The owner's account name. Clopen has one account, so nobody is ever asked
19
+ * for a name — the row still needs one.
20
+ */
21
+ const OWNER_NAME = 'Owner';
22
+
17
23
  /** How long a device-pairing code stays claimable before it expires (minutes). */
18
24
  const DEVICE_CODE_TTL_MINUTES = 5;
19
25
 
@@ -22,7 +28,6 @@ export interface AuthUser {
22
28
  name: string;
23
29
  color: string;
24
30
  avatar: string;
25
- role: 'admin' | 'member';
26
31
  createdAt: string;
27
32
  }
28
33
 
@@ -36,13 +41,12 @@ export interface SetupResult extends AuthResult {
36
41
  personalAccessToken: string;
37
42
  }
38
43
 
39
- function toAuthUser(dbUser: { id: string; name: string; color: string; avatar: string; role: 'admin' | 'member'; created_at: string }): AuthUser {
44
+ function toAuthUser(dbUser: { id: string; name: string; color: string; avatar: string; created_at: string }): AuthUser {
40
45
  return {
41
46
  id: dbUser.id,
42
47
  name: dbUser.name,
43
48
  color: dbUser.color,
44
49
  avatar: dbUser.avatar,
45
- role: dbUser.role,
46
50
  createdAt: dbUser.created_at
47
51
  };
48
52
  }
@@ -53,8 +57,8 @@ export interface SessionMeta {
53
57
  ipAddress?: string;
54
58
  }
55
59
 
56
- /** How a session was created — surfaced in the admin "Connected devices" view. */
57
- export type SessionSource = 'setup' | 'invite' | 'device-link' | 'login' | 'pat' | 'no-auth';
60
+ /** How a session was created — surfaced in the "Your devices" list. */
61
+ export type SessionSource = 'setup' | 'device-link' | 'login' | 'pat' | 'no-auth';
58
62
 
59
63
  function createSessionForUser(userId: string, source: SessionSource, meta?: SessionMeta, sessionDays?: number): { sessionToken: string; expiresAt: string; tokenHash: string } {
60
64
  const days = sessionDays ?? DEFAULT_SESSION_DAYS;
@@ -79,7 +83,7 @@ function createSessionForUser(userId: string, source: SessionSource, meta?: Sess
79
83
  }
80
84
 
81
85
  /**
82
- * Check if the system needs initial setup (no users exist)
86
+ * Check if the system needs initial setup (the owner does not exist yet)
83
87
  */
84
88
  export function needsSetup(): boolean {
85
89
  return authQueries.countUsers() === 0;
@@ -109,12 +113,12 @@ export function getOnboardingState(): OnboardingState {
109
113
  if (stored.onboarding === 'complete' || stored.onboardingComplete === true) return 'complete';
110
114
  if (stored.onboarding === 'pending') return 'pending';
111
115
 
112
- // No marker at all. An install that already has users has, by definition,
113
- // been through setup — the wizard is what created them. Record that so a
116
+ // No marker at all. An install that already has an owner has, by
117
+ // definition, been through setup — the wizard is what created it. Record that so a
114
118
  // single missing key can never flap the whole instance back to setup.
115
119
  if (!needsSetup()) {
116
120
  markOnboardingComplete();
117
- debug.log('auth', 'Onboarding marker missing but users exist — recorded as complete');
121
+ debug.log('auth', 'Onboarding marker missing but the owner exists — recorded as complete');
118
122
  return 'complete';
119
123
  }
120
124
 
@@ -140,42 +144,36 @@ export function markOnboardingComplete(): void {
140
144
  }
141
145
 
142
146
  /**
143
- * Create a default admin user for no-auth mode.
144
- * Does not generate a PAT (not needed for no-auth).
145
- * If users already exist, returns the first admin.
147
+ * Sign in for no-auth mode: reuse the owner, creating a default one on a fresh
148
+ * install. Does not generate a PAT (not needed for no-auth).
146
149
  */
147
- export function createOrGetNoAuthAdmin(): AuthResult {
148
- // If users already exist, return the first admin
149
- const existingUsers = authQueries.getAllUsers();
150
- const existingAdmin = existingUsers.find(u => u.role === 'admin');
151
- if (existingAdmin) {
152
- const { sessionToken, expiresAt } = createSessionForUser(existingAdmin.id, 'no-auth');
153
- debug.log('auth', `No-auth mode: reusing existing admin: ${existingAdmin.name} (${existingAdmin.id})`);
150
+ export function createOrGetNoAuthOwner(): AuthResult {
151
+ const existing = authQueries.getOwner();
152
+ if (existing) {
153
+ const { sessionToken, expiresAt } = createSessionForUser(existing.id, 'no-auth');
154
+ debug.log('auth', `No-auth mode: reusing owner: ${existing.name} (${existing.id})`);
154
155
  return {
155
- user: toAuthUser(existingAdmin),
156
+ user: toAuthUser(existing),
156
157
  sessionToken,
157
158
  expiresAt
158
159
  };
159
160
  }
160
161
 
161
- // Create default admin
162
162
  const userId = `user-${crypto.randomUUID()}`;
163
163
  const now = new Date().toISOString();
164
- const defaultName = 'Admin';
165
164
 
166
165
  const dbUser = authQueries.createUser({
167
166
  id: userId,
168
- name: defaultName,
169
- color: generateColorFromString(defaultName),
170
- avatar: getInitials(defaultName),
171
- role: 'admin',
167
+ name: OWNER_NAME,
168
+ color: generateColorFromString(OWNER_NAME),
169
+ avatar: getInitials(OWNER_NAME),
172
170
  personal_access_token_hash: '', // No PAT for no-auth mode
173
171
  created_at: now
174
172
  });
175
173
 
176
174
  const { sessionToken, expiresAt } = createSessionForUser(userId, 'no-auth');
177
175
 
178
- debug.log('auth', `No-auth mode: created default admin: ${defaultName} (${userId})`);
176
+ debug.log('auth', `No-auth mode: created the owner (${userId})`);
179
177
 
180
178
  return {
181
179
  user: toAuthUser(dbUser),
@@ -185,17 +183,11 @@ export function createOrGetNoAuthAdmin(): AuthResult {
185
183
  }
186
184
 
187
185
  /**
188
- * Create the first admin user (setup flow)
189
- * Only works when no users exist.
186
+ * Create the owner account (setup flow). Only works before setup.
190
187
  */
191
- export function createAdmin(name: string, meta?: SessionMeta): SetupResult {
188
+ export function createOwner(meta?: SessionMeta): SetupResult {
192
189
  if (!needsSetup()) {
193
- throw new Error('Setup already completed. Admin account exists.');
194
- }
195
-
196
- const trimmedName = name.trim();
197
- if (trimmedName.length === 0) {
198
- throw new Error('Name cannot be empty');
190
+ throw new Error('Setup already completed. The owner account exists.');
199
191
  }
200
192
 
201
193
  const userId = `user-${crypto.randomUUID()}`;
@@ -205,91 +197,16 @@ export function createAdmin(name: string, meta?: SessionMeta): SetupResult {
205
197
 
206
198
  const dbUser = authQueries.createUser({
207
199
  id: userId,
208
- name: trimmedName,
209
- color: generateColorFromString(trimmedName),
210
- avatar: getInitials(trimmedName),
211
- role: 'admin',
200
+ name: OWNER_NAME,
201
+ color: generateColorFromString(OWNER_NAME),
202
+ avatar: getInitials(OWNER_NAME),
212
203
  personal_access_token_hash: patHash,
213
204
  created_at: now
214
205
  });
215
206
 
216
207
  const { sessionToken, expiresAt } = createSessionForUser(userId, 'setup', meta);
217
208
 
218
- debug.log('auth', `Admin account created: ${trimmedName} (${userId})`);
219
-
220
- return {
221
- user: toAuthUser(dbUser),
222
- sessionToken,
223
- expiresAt,
224
- personalAccessToken: pat
225
- };
226
- }
227
-
228
- /**
229
- * Create a user from an invite token
230
- */
231
- export function createUserFromInvite(rawInviteToken: string, name: string, meta?: SessionMeta): SetupResult {
232
- const trimmedName = name.trim();
233
- if (trimmedName.length === 0) {
234
- throw new Error('Name cannot be empty');
235
- }
236
-
237
- const inviteHash = hashToken(rawInviteToken);
238
- const invite = authQueries.getInviteByTokenHash(inviteHash);
239
-
240
- if (!invite) {
241
- throw new Error('Invalid invite token');
242
- }
243
-
244
- // Check expiry
245
- if (invite.expires_at && new Date(invite.expires_at) < new Date()) {
246
- throw new Error('Invite token has expired');
247
- }
248
-
249
- // Check max uses
250
- if (invite.max_uses > 0 && invite.use_count >= invite.max_uses) {
251
- throw new Error('Invite token has reached maximum uses');
252
- }
253
-
254
- // Only allow creating member role from invite (single admin policy)
255
- const role: 'admin' | 'member' = 'member';
256
-
257
- const userId = `user-${crypto.randomUUID()}`;
258
- const now = new Date().toISOString();
259
- const pat = generatePAT();
260
- const patHash = hashToken(pat);
261
-
262
- const dbUser = authQueries.createUser({
263
- id: userId,
264
- name: trimmedName,
265
- color: generateColorFromString(trimmedName),
266
- avatar: getInitials(trimmedName),
267
- role,
268
- personal_access_token_hash: patHash,
269
- created_at: now
270
- });
271
-
272
- // Increment invite use count
273
- authQueries.incrementUseCount(invite.id);
274
-
275
- // Apply any projects the admin pre-selected when creating the invite, so the
276
- // new member has access the moment they join (no separate assignment trip).
277
- if (invite.project_ids) {
278
- try {
279
- const projectIds: string[] = JSON.parse(invite.project_ids);
280
- for (const projectId of projectIds) {
281
- if (projectQueries.getById(projectId) && !projectQueries.userHasProject(userId, projectId)) {
282
- projectQueries.addUserProject(userId, projectId);
283
- }
284
- }
285
- } catch (err) {
286
- debug.warn('auth', 'Failed to apply invite project pre-assignment:', err);
287
- }
288
- }
289
-
290
- const { sessionToken, expiresAt } = createSessionForUser(userId, 'invite', meta);
291
-
292
- debug.log('auth', `User created from invite: ${trimmedName} (${userId}), role: ${role}`);
209
+ debug.log('auth', `Owner account created (${userId})`);
293
210
 
294
211
  return {
295
212
  user: toAuthUser(dbUser),
@@ -376,104 +293,11 @@ export function getUserById(id: string): AuthUser | null {
376
293
  }
377
294
 
378
295
  /**
379
- * List all users
380
- */
381
- export function listUsers(): AuthUser[] {
382
- return authQueries.getAllUsers().map(toAuthUser);
383
- }
384
-
385
- /**
386
- * Remove a user (prevents removing the last admin)
387
- */
388
- export function removeUser(userId: string): void {
389
- const user = authQueries.getUserById(userId);
390
- if (!user) {
391
- throw new Error('User not found');
392
- }
393
-
394
- if (user.role === 'admin' && authQueries.countAdmins() <= 1) {
395
- throw new Error('Cannot remove the last admin');
396
- }
397
-
398
- // Delete all sessions for this user
399
- authQueries.deleteSessionsByUserId(userId);
400
- // Delete the user (cascade will handle invite_tokens.created_by)
401
- authQueries.deleteUser(userId);
402
-
403
- debug.log('auth', `User removed: ${user.name} (${userId})`);
404
- }
405
-
406
- /**
407
- * Create an invite token
408
- */
409
- export function createInvite(
410
- createdBy: string,
411
- options: { label?: string; maxUses?: number; expiresInMinutes?: number; projectIds?: string[] }
412
- ): { inviteToken: string; invite: ReturnType<typeof authQueries.getInviteByTokenHash> } {
413
- const rawToken = generateInviteToken();
414
- const tokenHash = hashToken(rawToken);
415
- const now = new Date().toISOString();
416
-
417
- const expiresAt = options.expiresInMinutes
418
- ? new Date(Date.now() + options.expiresInMinutes * 60 * 1000).toISOString()
419
- : null;
420
-
421
- // Keep only project ids that actually exist so a stale pick can't wedge the join.
422
- const validProjectIds = (options.projectIds ?? []).filter((id) => projectQueries.getById(id));
423
-
424
- const invite = authQueries.createInvite({
425
- id: `invite-${crypto.randomUUID()}`,
426
- token_hash: tokenHash,
427
- role: 'member',
428
- label: options.label ?? null,
429
- created_by: createdBy,
430
- max_uses: options.maxUses ?? 1,
431
- use_count: 0,
432
- expires_at: expiresAt,
433
- created_at: now,
434
- project_ids: validProjectIds.length ? JSON.stringify(validProjectIds) : null
435
- });
436
-
437
- debug.log('auth', `Invite created by ${createdBy}: ${invite.id}`);
438
-
439
- return { inviteToken: rawToken, invite };
440
- }
441
-
442
- /**
443
- * Validate an invite token (without using it)
296
+ * The owner account, or null before setup.
444
297
  */
445
- export function validateInviteToken(rawToken: string): { valid: boolean; role?: string; error?: string } {
446
- const tokenHash = hashToken(rawToken);
447
- const invite = authQueries.getInviteByTokenHash(tokenHash);
448
-
449
- if (!invite) {
450
- return { valid: false, error: 'Invalid invite token' };
451
- }
452
-
453
- if (invite.expires_at && new Date(invite.expires_at) < new Date()) {
454
- return { valid: false, error: 'Invite has expired' };
455
- }
456
-
457
- if (invite.max_uses > 0 && invite.use_count >= invite.max_uses) {
458
- return { valid: false, error: 'Invite has reached maximum uses' };
459
- }
460
-
461
- return { valid: true, role: invite.role };
462
- }
463
-
464
- /**
465
- * List all invites
466
- */
467
- export function listInvites() {
468
- return authQueries.getAllInvites();
469
- }
470
-
471
- /**
472
- * Revoke an invite
473
- */
474
- export function revokeInvite(id: string): void {
475
- authQueries.revokeInvite(id);
476
- debug.log('auth', `Invite revoked: ${id}`);
298
+ export function getOwner(): AuthUser | null {
299
+ const user = authQueries.getOwner();
300
+ return user ? toAuthUser(user) : null;
477
301
  }
478
302
 
479
303
  /**
@@ -591,30 +415,7 @@ export function revokeDeviceCode(userId: string, rawCode: string): boolean {
591
415
  }
592
416
 
593
417
  /**
594
- * Update user display name
595
- */
596
- export function updateUserName(userId: string, newName: string): AuthUser {
597
- const trimmedName = newName.trim();
598
- if (trimmedName.length === 0) {
599
- throw new Error('Name cannot be empty');
600
- }
601
-
602
- authQueries.updateUser(userId, {
603
- name: trimmedName,
604
- color: generateColorFromString(trimmedName),
605
- avatar: getInitials(trimmedName)
606
- });
607
-
608
- const updated = authQueries.getUserById(userId);
609
- if (!updated) {
610
- throw new Error('User not found after update');
611
- }
612
-
613
- return toAuthUser(updated);
614
- }
615
-
616
- /**
617
- * Logout all sessions (all users)
418
+ * Sign out every device
618
419
  */
619
420
  export function logoutAllSessions(): number {
620
421
  const count = authQueries.deleteAllSessions();
@@ -623,62 +424,8 @@ export function logoutAllSessions(): number {
623
424
  }
624
425
 
625
426
  /**
626
- * List projects assigned to a specific user (admin view)
627
- */
628
- export function listUserProjects(userId: string): Project[] {
629
- const user = authQueries.getUserById(userId);
630
- if (!user) {
631
- throw new Error('User not found');
632
- }
633
- return projectQueries.getAllForUser(userId);
634
- }
635
-
636
- /**
637
- * Assign a project to a user. Admins are implicitly assigned to all projects
638
- * they create, but this is used to grant a member access to a project.
639
- * Returns true if a new assignment was added, false if user already had access.
640
- */
641
- export function assignProjectToUser(userId: string, projectId: string): boolean {
642
- const user = authQueries.getUserById(userId);
643
- if (!user) {
644
- throw new Error('Access denied');
645
- }
646
- const project = projectQueries.getById(projectId);
647
- if (!project) {
648
- throw new Error('Access denied');
649
- }
650
- if (projectQueries.userHasProject(userId, projectId)) {
651
- return false;
652
- }
653
- projectQueries.addUserProject(userId, projectId);
654
- debug.log('auth', `Project ${projectId} assigned to user ${userId}`);
655
- return true;
656
- }
657
-
658
- /**
659
- * Revoke a user's access to a project. Refuses to remove the last admin
660
- * association to avoid orphaning the project.
661
- */
662
- export function unassignProjectFromUser(userId: string, projectId: string): boolean {
663
- const user = authQueries.getUserById(userId);
664
- if (!user) {
665
- throw new Error('Access denied');
666
- }
667
- const project = projectQueries.getById(projectId);
668
- if (!project) {
669
- throw new Error('Access denied');
670
- }
671
- if (!projectQueries.userHasProject(userId, projectId)) {
672
- return false;
673
- }
674
- projectQueries.removeUserProject(userId, projectId);
675
- debug.log('auth', `Project ${projectId} unassigned from user ${userId}`);
676
- return true;
677
- }
678
-
679
- /**
680
- * List a user's active auth sessions (devices). `current` marks the session
681
- * matching the given token hash so the caller can flag "this device".
427
+ * A signed-in device. `current` marks the session matching the given token
428
+ * hash so the caller can flag "this device".
682
429
  */
683
430
  export interface AuthSessionInfo {
684
431
  id: string;
@@ -693,16 +440,8 @@ export interface AuthSessionInfo {
693
440
  source: string | null;
694
441
  }
695
442
 
696
- /** Admin "Connected devices" row — a session enriched with its owning user. */
697
- export interface AdminSessionInfo extends AuthSessionInfo {
698
- userId: string;
699
- userName: string;
700
- userColor: string;
701
- userRole: 'admin' | 'member';
702
- }
703
-
704
- export function listUserSessions(userId: string, currentTokenHash?: string, onlineHashes?: Set<string>): AuthSessionInfo[] {
705
- return authQueries.getSessionsByUserId(userId).map((s) => ({
443
+ export function listSessions(currentTokenHash?: string, onlineHashes?: Set<string>): AuthSessionInfo[] {
444
+ return authQueries.getAllSessions().map((s) => ({
706
445
  id: s.id,
707
446
  createdAt: s.created_at,
708
447
  lastActiveAt: s.last_active_at,
@@ -716,57 +455,16 @@ export function listUserSessions(userId: string, currentTokenHash?: string, onli
716
455
  }
717
456
 
718
457
  /**
719
- * List every session across all users (admin view), enriched with the owning
720
- * user's identity and whether the device is currently online.
721
- */
722
- export function listAllSessions(currentTokenHash?: string, onlineHashes?: Set<string>): AdminSessionInfo[] {
723
- return authQueries.getAllSessions().map((s) => {
724
- const user = authQueries.getUserById(s.user_id);
725
- return {
726
- id: s.id,
727
- createdAt: s.created_at,
728
- lastActiveAt: s.last_active_at,
729
- expiresAt: s.expires_at,
730
- current: currentTokenHash !== undefined && s.token_hash === currentTokenHash,
731
- online: onlineHashes?.has(s.token_hash) ?? false,
732
- userAgent: s.user_agent,
733
- ipAddress: s.ip_address,
734
- source: s.source,
735
- userId: s.user_id,
736
- userName: user?.name ?? 'Unknown',
737
- userColor: user?.color ?? '#888888',
738
- userRole: user?.role ?? 'member'
739
- };
740
- });
741
- }
742
-
743
- /**
744
- * Revoke one of a user's own sessions by id. Scoped to the owner so a member
745
- * can only sign out their own devices. Returns the deleted session's token hash
746
- * so the caller can kick any live WS connection bound to it.
747
- */
748
- export function revokeUserSession(userId: string, sessionId: string): { success: boolean; tokenHash?: string } {
749
- const session = authQueries.getSessionById(sessionId);
750
- if (!session || session.user_id !== userId) {
751
- return { success: false };
752
- }
753
- authQueries.deleteSession(sessionId);
754
- debug.log('auth', `Session revoked: ${sessionId} (user ${userId})`);
755
- return { success: true, tokenHash: session.token_hash };
756
- }
757
-
758
- /**
759
- * Revoke any session by id (admin-only). Unlike revokeUserSession this is not
760
- * owner-scoped — an admin can sign out any connected device. Returns the token
761
- * hash so the caller can kick the live WS connection immediately.
458
+ * Sign out one device. Returns the deleted session's token hash so the caller
459
+ * can kick any live WS connection bound to it.
762
460
  */
763
- export function revokeAnySession(sessionId: string): { success: boolean; tokenHash?: string } {
461
+ export function revokeSession(sessionId: string): { success: boolean; tokenHash?: string } {
764
462
  const session = authQueries.getSessionById(sessionId);
765
463
  if (!session) {
766
464
  return { success: false };
767
465
  }
768
466
  authQueries.deleteSession(sessionId);
769
- debug.log('auth', `Session revoked by admin: ${sessionId} (user ${session.user_id})`);
467
+ debug.log('auth', `Session revoked: ${sessionId}`);
770
468
  return { success: true, tokenHash: session.token_hash };
771
469
  }
772
470
 
@@ -774,19 +472,15 @@ export function revokeAnySession(sessionId: string): { success: boolean; tokenHa
774
472
  * Remote Access sidebar indicator: the number of *other* devices currently
775
473
  * online. "Active" means a live WS connection is bound to the session right now
776
474
  * — not merely a session row in the DB — so this mirrors Public Tunnel's live
777
- * connection count and the "Connected devices" list. A member sees their own
778
- * online devices; an admin sees the whole team's. The viewer's current device
779
- * is always excluded so the badge reads "N remote devices connected".
475
+ * connection count and the "Your devices" list. The viewer's current device is
476
+ * excluded so the badge reads "N remote devices connected".
780
477
  */
781
478
  export function getRemoteAccessSummary(
782
- userId: string,
783
- isAdmin: boolean,
784
479
  onlineHashes: Set<string>,
785
480
  currentTokenHash?: string
786
481
  ): { activeConnections: number } {
787
- const sessions = isAdmin ? authQueries.getAllSessions() : authQueries.getSessionsByUserId(userId);
788
482
  let activeConnections = 0;
789
- for (const s of sessions) {
483
+ for (const s of authQueries.getAllSessions()) {
790
484
  if (!onlineHashes.has(s.token_hash)) continue;
791
485
  if (currentTokenHash && s.token_hash === currentTokenHash) continue;
792
486
  activeConnections++;
@@ -15,7 +15,7 @@ import { getOnboardingState, markOnboardingComplete } from './auth-service';
15
15
  import { readSystemSettings, writeSystemSettings, SYSTEM_SETTINGS_KEY } from '../settings/system-settings';
16
16
  import { getClopenDir } from '../utils/paths';
17
17
  import { authQueries, settingsQueries } from '../database/queries';
18
- import { initializeDatabase, closeDatabase } from '../database';
18
+ import { initializeDatabase, closeDatabase, getDatabase } from '../database';
19
19
 
20
20
  let testUserId: string;
21
21
  let originalSettings: string | null = null;
@@ -32,14 +32,13 @@ beforeAll(async () => {
32
32
  name: 'Onboarding Test User',
33
33
  color: '#000000',
34
34
  avatar: 'OT',
35
- role: 'admin',
36
35
  personal_access_token_hash: `hash-${randomUUID()}`,
37
36
  created_at: new Date().toISOString()
38
37
  });
39
38
  });
40
39
 
41
40
  afterAll(() => {
42
- authQueries.deleteUser(testUserId);
41
+ getDatabase().prepare('DELETE FROM users WHERE id = ?').run(testUserId);
43
42
  if (originalSettings === null) {
44
43
  settingsQueries.delete(SYSTEM_SETTINGS_KEY);
45
44
  } else {