@myrialabs/clopen 0.4.47 → 0.4.48

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 (325) 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/stream-manager.ts +62 -62
  15. package/backend/chat/turn-answer.test.ts +64 -0
  16. package/backend/chat/turn-answer.ts +125 -0
  17. package/backend/chat-apps/awaiting.test.ts +39 -0
  18. package/backend/chat-apps/awaiting.ts +49 -0
  19. package/backend/chat-apps/conversation.ts +746 -0
  20. package/backend/chat-apps/inbound.ts +324 -0
  21. package/backend/chat-apps/index.ts +309 -0
  22. package/backend/chat-apps/link-events.ts +20 -0
  23. package/backend/chat-apps/media.test.ts +62 -0
  24. package/backend/chat-apps/media.ts +208 -0
  25. package/backend/chat-apps/messages.test.ts +229 -0
  26. package/backend/chat-apps/messages.ts +365 -0
  27. package/backend/chat-apps/outbound.ts +243 -0
  28. package/backend/chat-apps/pairing.test.ts +45 -0
  29. package/backend/chat-apps/pairing.ts +74 -0
  30. package/backend/chat-apps/platforms/index.ts +20 -0
  31. package/backend/chat-apps/platforms/telegram.test.ts +35 -0
  32. package/backend/chat-apps/platforms/telegram.ts +191 -0
  33. package/backend/chat-apps/platforms/types.ts +114 -0
  34. package/backend/chat-apps/questions.ts +133 -0
  35. package/backend/chat-apps/runtime.ts +572 -0
  36. package/backend/chat-apps/storage.test.ts +201 -0
  37. package/backend/chat-apps/turns.test.ts +45 -0
  38. package/backend/chat-apps/turns.ts +208 -0
  39. package/backend/containers/pty.ts +3 -11
  40. package/backend/control/actions/accounts.ts +89 -0
  41. package/backend/control/actions/files.ts +116 -0
  42. package/backend/control/actions/models.ts +188 -0
  43. package/backend/control/actions/projects.ts +272 -0
  44. package/backend/control/actions/sessions.ts +280 -0
  45. package/backend/control/actions/skills.ts +111 -0
  46. package/backend/control/control.test.ts +169 -0
  47. package/backend/control/define.ts +20 -0
  48. package/backend/control/folders.test.ts +67 -0
  49. package/backend/control/index.ts +213 -0
  50. package/backend/control/invoke.ts +44 -0
  51. package/backend/control/links.ts +35 -0
  52. package/backend/control/paging.ts +26 -0
  53. package/backend/control/types.ts +117 -0
  54. package/backend/control/workspace.ts +127 -0
  55. package/backend/database/migrations/084_create_channel_links.ts +71 -0
  56. package/backend/database/migrations/085_add_home_projects.ts +36 -0
  57. package/backend/database/migrations/086_single_owner.test.ts +170 -0
  58. package/backend/database/migrations/086_single_owner.ts +418 -0
  59. package/backend/database/migrations/index.ts +21 -0
  60. package/backend/database/queries/auth-queries.ts +7 -85
  61. package/backend/database/queries/channel-queries.ts +270 -0
  62. package/backend/database/queries/db-client-connection-queries.ts +18 -56
  63. package/backend/database/queries/file-share-queries.ts +5 -23
  64. package/backend/database/queries/git-identity-queries.ts +31 -42
  65. package/backend/database/queries/graph-queries.ts +1 -1
  66. package/backend/database/queries/index.ts +13 -1
  67. package/backend/database/queries/message-queries.test.ts +146 -0
  68. package/backend/database/queries/message-queries.ts +42 -1
  69. package/backend/database/queries/permission-set-queries.ts +1 -1
  70. package/backend/database/queries/profile-queries.ts +1 -1
  71. package/backend/database/queries/project-mcp-trust-queries.ts +1 -1
  72. package/backend/database/queries/project-queries.ts +50 -63
  73. package/backend/database/queries/session-queries.ts +28 -56
  74. package/backend/database/queries/ssh-connection-queries.ts +18 -41
  75. package/backend/db-client/integrations/projector.ts +0 -5
  76. package/backend/engine/adapters/claude/message-converter.test.ts +47 -0
  77. package/backend/engine/adapters/claude/message-converter.ts +25 -2
  78. package/backend/engine/adapters/cline/message-converter.ts +0 -1
  79. package/backend/engine/adapters/cline/stream.ts +11 -15
  80. package/backend/engine/adapters/codex/message-converter.ts +0 -2
  81. package/backend/engine/adapters/copilot/message-converter.ts +1 -2
  82. package/backend/engine/adapters/cursor/message-converter.ts +0 -1
  83. package/backend/engine/adapters/opencode/message-converter.ts +2 -4
  84. package/backend/engine/adapters/opencode/stream.ts +11 -0
  85. package/backend/engine/adapters/parent-scope.test.ts +38 -0
  86. package/backend/engine/adapters/parent-scope.ts +44 -0
  87. package/backend/engine/adapters/pi/message-converter.ts +0 -1
  88. package/backend/engine/adapters/pi/stream.ts +4 -5
  89. package/backend/engine/adapters/qwen/message-converter.ts +0 -2
  90. package/backend/engine/bootstrap-default-engine.ts +2 -2
  91. package/backend/engine/docs/adapter-contract.md +8 -1
  92. package/backend/engine/install-runner.ts +8 -17
  93. package/backend/files/file-shares.ts +20 -44
  94. package/backend/files/file-size-limit.ts +3 -3
  95. package/backend/files/image-processing.ts +1 -1
  96. package/backend/files/os-clipboard.ts +2 -2
  97. package/backend/git/git-executor.ts +25 -5
  98. package/backend/git/git-service.ts +420 -19
  99. package/backend/git/identity/credential-helper.test.ts +2 -7
  100. package/backend/git/identity/import-local.test.ts +11 -16
  101. package/backend/git/identity/import-local.ts +12 -12
  102. package/backend/git/identity/index.ts +10 -24
  103. package/backend/git/identity/resolve.ts +13 -14
  104. package/backend/git/identity/scope-config.ts +33 -28
  105. package/backend/git/identity/service.ts +44 -47
  106. package/backend/git/op-lock.test.ts +111 -0
  107. package/backend/git/op-lock.ts +180 -0
  108. package/backend/git/remote-sync.test.ts +249 -0
  109. package/backend/host/metrics.ts +1 -1
  110. package/backend/http/bearer-auth.ts +1 -2
  111. package/backend/http/files-download.test.ts +8 -9
  112. package/backend/http/files-download.ts +2 -2
  113. package/backend/http/files-shared.test.ts +62 -89
  114. package/backend/http/files-shared.ts +2 -2
  115. package/backend/http/files-upload.test.ts +3 -7
  116. package/backend/http/files-upload.ts +3 -3
  117. package/backend/http/notes-images.test.ts +15 -38
  118. package/backend/http/notes-images.ts +6 -8
  119. package/backend/http/ssh-sftp.ts +5 -10
  120. package/backend/index.ts +21 -7
  121. package/backend/integrations/accounts.ts +61 -3
  122. package/backend/integrations/index.ts +2 -2
  123. package/backend/integrations/registry/define.ts +15 -0
  124. package/backend/integrations/registry/index.ts +2 -0
  125. package/backend/integrations/registry/providers/telegram.ts +54 -0
  126. package/backend/integrations/registry/types.ts +21 -1
  127. package/backend/integrations/webhooks/gateway.ts +7 -6
  128. package/backend/integrations/webhooks/verify.test.ts +30 -0
  129. package/backend/integrations/webhooks/verify.ts +4 -0
  130. package/backend/mcp/external/project.ts +1 -1
  131. package/backend/mcp/internal/remote-server.test.ts +1 -3
  132. package/backend/mcp/internal/remote-server.ts +4 -4
  133. package/backend/mcp/internal/servers/browser-automation/actions/dialogs.ts +67 -0
  134. package/backend/mcp/internal/servers/browser-automation/actions/index.ts +3 -1
  135. package/backend/mcp/internal/servers/browser-automation/actions/input.ts +5 -5
  136. package/backend/mcp/internal/servers/browser-automation/actions/tabs.ts +157 -28
  137. package/backend/mcp/internal/servers/browser-automation/context.ts +1 -0
  138. package/backend/mcp/internal/servers/browser-automation/description.ts +5 -2
  139. package/backend/mcp/internal/servers/browser-automation/format.ts +24 -1
  140. package/backend/mcp/internal/servers/browser-automation/runner.ts +68 -3
  141. package/backend/memory/redact.ts +1 -1
  142. package/backend/notes/access.test.ts +28 -29
  143. package/backend/notes/access.ts +6 -11
  144. package/backend/permissions/service.ts +1 -1
  145. package/backend/preview/browser/browser-clipboard.test.ts +46 -0
  146. package/backend/preview/browser/browser-clipboard.ts +67 -0
  147. package/backend/preview/browser/browser-dialog-handler.ts +95 -6
  148. package/backend/preview/browser/browser-host-bridge.ts +9 -0
  149. package/backend/preview/browser/browser-interaction-handler.ts +316 -86
  150. package/backend/preview/browser/browser-mcp-control.ts +34 -0
  151. package/backend/preview/browser/browser-pool.ts +67 -6
  152. package/backend/preview/browser/browser-preview-service.ts +361 -25
  153. package/backend/preview/browser/browser-tab-manager.ts +66 -23
  154. package/backend/preview/browser/browser-video-capture.ts +92 -5
  155. package/backend/preview/browser/element-locator.ts +190 -17
  156. package/backend/preview/browser/keyboard-chords.test.ts +68 -0
  157. package/backend/preview/browser/keyboard-chords.ts +132 -0
  158. package/backend/preview/browser/paste.ts +81 -0
  159. package/backend/preview/browser/process-usage.ts +142 -0
  160. package/backend/preview/browser/profile-lock.ts +209 -0
  161. package/backend/preview/browser/scripts/host-bridge.ts +59 -0
  162. package/backend/preview/browser/scripts/video-stream.ts +58 -0
  163. package/backend/preview/browser/types.ts +40 -2
  164. package/backend/preview/browser/viewport.test.ts +45 -0
  165. package/backend/preview/browser/viewport.ts +96 -0
  166. package/backend/profiles/service.ts +2 -2
  167. package/backend/project/status-manager.ts +43 -172
  168. package/backend/projects/home.ts +61 -0
  169. package/backend/projects/project-cleanup.integration.test.ts +2 -2
  170. package/backend/projects/project-cleanup.ts +0 -8
  171. package/backend/skills/service.ts +2 -3
  172. package/backend/snapshot/helpers.ts +0 -1
  173. package/backend/snapshot/restore.ts +252 -0
  174. package/backend/ssh/ptykit.ts +1 -2
  175. package/backend/terminal/ptykit.ts +5 -8
  176. package/backend/tunnel/public-origin.ts +31 -20
  177. package/backend/utils/user-helpers.ts +0 -55
  178. package/backend/utils/ws.ts +61 -154
  179. package/backend/worktrees/branching/engine.ts +3 -16
  180. package/backend/worktrees/branching/index.ts +1 -1
  181. package/backend/worktrees/branching/projector.ts +1 -1
  182. package/backend/worktrees/branching/service.ts +13 -25
  183. package/backend/ws/access.ts +12 -21
  184. package/backend/ws/artifacts/generate.ts +2 -2
  185. package/backend/ws/auth/device.ts +16 -71
  186. package/backend/ws/auth/index.ts +4 -22
  187. package/backend/ws/auth/login.test.ts +14 -60
  188. package/backend/ws/auth/login.ts +24 -124
  189. package/backend/ws/auth/status.ts +0 -1
  190. package/backend/ws/chat/composer.ts +118 -118
  191. package/backend/ws/chat/stream.ts +64 -47
  192. package/backend/ws/chat-apps/index.ts +117 -0
  193. package/backend/ws/containers/actions.ts +11 -25
  194. package/backend/ws/containers/index.ts +3 -4
  195. package/backend/ws/containers/list.ts +10 -36
  196. package/backend/ws/containers/logs.ts +2 -2
  197. package/backend/ws/containers/tunnel.ts +1 -2
  198. package/backend/ws/db-client/access.ts +2 -16
  199. package/backend/ws/db-client/accounts.ts +5 -15
  200. package/backend/ws/db-client/connections.ts +17 -25
  201. package/backend/ws/db-client/context.ts +1 -1
  202. package/backend/ws/db-client/env.ts +7 -10
  203. package/backend/ws/db-client/index.ts +2 -2
  204. package/backend/ws/db-client/io.ts +5 -5
  205. package/backend/ws/db-client/query-history-retention.test.ts +8 -8
  206. package/backend/ws/db-client/query.ts +18 -17
  207. package/backend/ws/db-client/schema.ts +13 -13
  208. package/backend/ws/db-client/structure.ts +35 -35
  209. package/backend/ws/db-client/supabase.ts +4 -21
  210. package/backend/ws/deployments/context.ts +1 -1
  211. package/backend/ws/deployments/crud.ts +0 -5
  212. package/backend/ws/engine/access.ts +7 -20
  213. package/backend/ws/engine/claude/accounts.ts +4 -4
  214. package/backend/ws/engine/cline/accounts.ts +5 -5
  215. package/backend/ws/engine/codex/accounts.ts +3 -3
  216. package/backend/ws/engine/pi/accounts.ts +5 -5
  217. package/backend/ws/files/clipboard.ts +8 -27
  218. package/backend/ws/files/image-edit.ts +6 -6
  219. package/backend/ws/files/index.ts +1 -1
  220. package/backend/ws/files/path-access.test.ts +32 -131
  221. package/backend/ws/files/path-access.ts +8 -87
  222. package/backend/ws/files/read.ts +15 -19
  223. package/backend/ws/files/reveal.ts +3 -3
  224. package/backend/ws/files/search.ts +7 -7
  225. package/backend/ws/files/share.ts +9 -13
  226. package/backend/ws/files/state.ts +9 -12
  227. package/backend/ws/files/watch.ts +3 -3
  228. package/backend/ws/files/write.ts +30 -31
  229. package/backend/ws/git/branch.ts +80 -59
  230. package/backend/ws/git/commit.ts +63 -44
  231. package/backend/ws/git/conflict.ts +16 -18
  232. package/backend/ws/git/identity-context.ts +8 -17
  233. package/backend/ws/git/identity.ts +17 -27
  234. package/backend/ws/git/index.ts +3 -1
  235. package/backend/ws/git/op-state.ts +139 -0
  236. package/backend/ws/git/remote.ts +241 -141
  237. package/backend/ws/git/repo-context.ts +67 -0
  238. package/backend/ws/git/staging.ts +18 -28
  239. package/backend/ws/git/status.ts +5 -2
  240. package/backend/ws/index.ts +5 -1
  241. package/backend/ws/instructions/crud.ts +1 -1
  242. package/backend/ws/integrations/crud.ts +1 -3
  243. package/backend/ws/mcp/crud.ts +3 -5
  244. package/backend/ws/mcp/tools.ts +1 -1
  245. package/backend/ws/memory/crud.ts +14 -46
  246. package/backend/ws/memory/index.ts +2 -2
  247. package/backend/ws/messages/crud.ts +29 -8
  248. package/backend/ws/notes/index.ts +33 -39
  249. package/backend/ws/permissions/crud.ts +3 -4
  250. package/backend/ws/ports/index.ts +1 -2
  251. package/backend/ws/ports/kill.ts +5 -10
  252. package/backend/ws/ports/list.ts +4 -10
  253. package/backend/ws/preview/access.ts +1 -1
  254. package/backend/ws/preview/browser/interact.ts +52 -79
  255. package/backend/ws/preview/browser/native-ui.ts +24 -0
  256. package/backend/ws/preview/browser/stats.ts +98 -1
  257. package/backend/ws/preview/browser/tab-info.ts +15 -0
  258. package/backend/ws/preview/browser/tab.ts +19 -4
  259. package/backend/ws/preview/index.ts +27 -0
  260. package/backend/ws/profiles/crud.ts +6 -8
  261. package/backend/ws/project-artifacts/index.ts +30 -31
  262. package/backend/ws/projects/crud.ts +33 -35
  263. package/backend/ws/projects/index.ts +3 -8
  264. package/backend/ws/projects/info.ts +3 -3
  265. package/backend/ws/projects/overview.ts +19 -30
  266. package/backend/ws/projects/status.ts +17 -57
  267. package/backend/ws/sessions/crud.ts +34 -45
  268. package/backend/ws/sessions/index.ts +1 -1
  269. package/backend/ws/settings/crud.ts +1 -1
  270. package/backend/ws/skills/crud.ts +3 -4
  271. package/backend/ws/skills/index.ts +1 -1
  272. package/backend/ws/snapshot/changes.ts +7 -7
  273. package/backend/ws/snapshot/restore.ts +11 -295
  274. package/backend/ws/snapshot/timeline.ts +2 -4
  275. package/backend/ws/ssh/access.ts +6 -21
  276. package/backend/ws/ssh/connections.ts +21 -31
  277. package/backend/ws/ssh/forwards.ts +12 -12
  278. package/backend/ws/ssh/sftp.ts +34 -34
  279. package/backend/ws/ssh/tunnel.ts +1 -2
  280. package/backend/ws/stack/install.ts +7 -17
  281. package/backend/ws/subagents/crud.ts +1 -1
  282. package/backend/ws/tunnel/share.ts +0 -2
  283. package/backend/ws/user/crud.ts +1 -59
  284. package/backend/ws/user/index.ts +1 -1
  285. package/backend/ws/work/context.ts +1 -1
  286. package/backend/ws/work/crud.ts +0 -5
  287. package/backend/ws/workspace/state.ts +10 -13
  288. package/backend/ws/worktrees/branching.ts +7 -36
  289. package/backend/ws/worktrees/crud.ts +2 -2
  290. package/bin/clopen.ts +10 -11
  291. package/dist/assets/{index-CwuKQelV.js → index-CONlwAXZ.js} +1 -1
  292. package/dist/assets/{index-BTcR1byF.js → index-DJzwt-hq.js} +1 -1
  293. package/dist/assets/main-BUiUL3eZ.css +1 -0
  294. package/dist/assets/main-nBOb9YOA.js +1240 -0
  295. package/dist/index.html +2 -2
  296. package/package.json +2 -1
  297. package/shared/constants/attachments.ts +14 -0
  298. package/shared/constants/engine-tools.ts +1 -1
  299. package/shared/constants/preview.test.ts +259 -0
  300. package/shared/constants/preview.ts +1018 -57
  301. package/shared/constants/tool-icons.ts +5 -0
  302. package/shared/types/containers/container.ts +1 -1
  303. package/shared/types/database/schema.ts +9 -6
  304. package/shared/types/git-identity.ts +1 -1
  305. package/shared/types/git.ts +116 -0
  306. package/shared/types/integrations.ts +7 -0
  307. package/shared/types/stores/settings.ts +1 -1
  308. package/shared/types/unified/index.ts +1 -1
  309. package/shared/types/unified/message.ts +0 -7
  310. package/shared/types/unified/stream.ts +2 -4
  311. package/shared/types/unified/tool.ts +15 -1
  312. package/shared/utils/ask-user-question.test.ts +319 -0
  313. package/shared/utils/ask-user-question.ts +154 -0
  314. package/shared/utils/home-project.ts +25 -0
  315. package/shared/utils/logger.ts +2 -0
  316. package/shared/utils/ws-server.ts +32 -7
  317. package/backend/auth/session-invalidation.test.ts +0 -112
  318. package/backend/auth/session-invalidation.ts +0 -77
  319. package/backend/project/status-manager.test.ts +0 -32
  320. package/backend/ws/auth/invites.ts +0 -94
  321. package/backend/ws/auth/users.ts +0 -112
  322. package/backend/ws/projects/presence.ts +0 -46
  323. package/backend/ws/stack/access.ts +0 -31
  324. package/dist/assets/main-BiDNMWb3.css +0 -1
  325. package/dist/assets/main-BlhKWz2B.js +0 -1241
@@ -1,29 +1,19 @@
1
1
  import { describe, expect, test } from 'bun:test';
2
- import { ADMIN_ONLY_ROUTES, checkRouteAccess } from './permissions';
2
+ import { PUBLIC_ROUTES, checkRouteAccess } from './permissions';
3
3
 
4
- describe('ADMIN_ONLY_ROUTES', () => {
5
- test('includes high-impact global routes', () => {
6
- const expectedAdminRoutes = [
7
- 'auth:logout-all',
8
- 'system:clear-data',
9
- 'settings:update',
10
- 'tunnel:remote:start'
11
- ];
12
-
13
- for (const action of expectedAdminRoutes) {
14
- expect(ADMIN_ONLY_ROUTES.has(action)).toBe(true);
4
+ describe('checkRouteAccess', () => {
5
+ test('lets anyone reach the sign-in routes', () => {
6
+ for (const action of PUBLIC_ROUTES) {
7
+ expect(checkRouteAccess(action, false)).toEqual({ allowed: true });
15
8
  }
16
9
  });
17
- });
18
10
 
19
- describe('checkRouteAccess', () => {
20
- test('denies non-admin users from auth:logout-all', () => {
21
- const result = checkRouteAccess('auth:logout-all', true, 'member');
22
- expect(result).toEqual({ allowed: false, error: 'Admin access required' });
11
+ test('requires a signed-in connection for everything else', () => {
12
+ const result = checkRouteAccess('auth:logout-all', false);
13
+ expect(result).toEqual({ allowed: false, error: 'Authentication required' });
23
14
  });
24
15
 
25
- test('allows admin users to call auth:logout-all', () => {
26
- const result = checkRouteAccess('auth:logout-all', true, 'admin');
27
- expect(result).toEqual({ allowed: true });
16
+ test('lets a signed-in connection reach any route', () => {
17
+ expect(checkRouteAccess('system:clear-data', true)).toEqual({ allowed: true });
28
18
  });
29
19
  });
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * Route Permission Configuration
3
3
  *
4
- * Defines which WebSocket routes require authentication and which require admin role.
5
- * Used by the auth gate in WSRouter.handleMessage().
4
+ * Defines which WebSocket routes can be reached before signing in. Clopen has
5
+ * one account — the owner — so every other route only needs an authenticated
6
+ * connection. Used by the auth gate in WSRouter.handleMessage().
6
7
  */
7
8
 
8
9
  import { getAuthMode } from '$backend/settings/system-settings';
@@ -14,296 +15,17 @@ export const PUBLIC_ROUTES = new Set([
14
15
  'auth:setup',
15
16
  'auth:setup-no-auth',
16
17
  'auth:auto-login-no-auth',
17
- 'auth:accept-invite',
18
- 'auth:validate-invite',
19
18
  'auth:claim-device-code',
20
19
  'ws:set-context'
21
20
  ]);
22
21
 
23
- /** Routes that require admin role */
24
- export const ADMIN_ONLY_ROUTES = new Set([
25
- // Auth session controls with global impact.
26
- 'auth:logout-all',
27
- 'auth:create-invite',
28
- 'auth:list-invites',
29
- 'auth:revoke-invite',
30
- 'auth:list-all-sessions',
31
- 'auth:revoke-any-session',
32
- 'auth:list-users',
33
- 'auth:remove-user',
34
- 'auth:list-user-projects',
35
- 'auth:assign-project',
36
- 'auth:unassign-project',
37
- // Project lifecycle — members can only access projects they are assigned to
38
- // by an admin. Create/delete remain admin-only operations.
39
- 'projects:create',
40
- 'projects:delete',
41
- 'settings:update',
42
- 'settings:update-system',
43
- 'settings:update-batch',
44
- 'system:run-update',
45
- 'system:clear-data',
46
- // Port manager — anyone signed in may see what is listening, but ending a
47
- // process can take down another member's work, so stopping is admin-only.
48
- 'ports:kill',
49
- // Containers — anyone signed in may see what is running, but starting or
50
- // stopping one takes down whatever it serves for everyone else. Opening a
51
- // shell inside a container is gated separately, in the PtyKit authorize.
52
- 'containers:action',
53
- 'containers:remove',
54
- 'containers:prune',
55
- 'containers:prune-dismiss',
56
- // Stack — binary installation is an admin-only operation.
57
- 'stack:status',
58
- 'stack:status-all',
59
- 'stack:install-start',
60
- 'stack:install-cancel',
61
- 'stack:install-session',
62
- // Engine — account/provider mutations are global system credentials and
63
- // must only be changed by admins. Read-only routes (status, *-list) stay
64
- // open so any authenticated user can see what is configured.
65
- 'engine:claude-accounts-switch',
66
- 'engine:claude-accounts-delete',
67
- 'engine:claude-accounts-rename',
68
- 'engine:claude-account-setup-start',
69
- 'engine:claude-account-setup-submit',
70
- 'engine:claude-account-setup-cancel',
71
- 'engine:codex-accounts-add-api-key',
72
- 'engine:codex-accounts-switch',
73
- 'engine:codex-accounts-delete',
74
- 'engine:codex-accounts-rename',
75
- 'engine:codex-account-setup-start',
76
- 'engine:codex-account-setup-cancel',
77
- 'engine:copilot-accounts-add',
78
- 'engine:copilot-accounts-switch',
79
- 'engine:copilot-accounts-delete',
80
- 'engine:copilot-accounts-rename',
81
- 'engine:qwen-accounts-add',
82
- 'engine:qwen-accounts-switch',
83
- 'engine:qwen-accounts-delete',
84
- 'engine:qwen-accounts-rename',
85
- 'engine:pi-accounts-save',
86
- 'engine:pi-accounts-switch',
87
- 'engine:pi-accounts-delete',
88
- 'engine:pi-accounts-rename',
89
- 'engine:pi-account-login-start',
90
- 'engine:pi-account-login-submit',
91
- 'engine:pi-account-login-cancel',
92
- 'engine:cline-accounts-save',
93
- 'engine:cline-accounts-switch',
94
- 'engine:cline-accounts-delete',
95
- 'engine:cline-accounts-rename',
96
- 'engine:cline-account-login-start',
97
- 'engine:cline-account-login-submit',
98
- 'engine:cline-account-login-cancel',
99
- 'engine:opencode-provider-add',
100
- 'engine:opencode-provider-remove',
101
- 'engine:opencode-provider-toggle',
102
- 'engine:opencode-provider-update',
103
- 'engine:opencode-provider-update-options',
104
- 'engine:opencode-provider-fetch-models',
105
- 'engine:opencode-account-add',
106
- 'engine:opencode-account-switch',
107
- 'engine:opencode-account-delete',
108
- 'engine:opencode-account-rename',
109
- 'engine:opencode-models-dev-fetch',
110
- // Tunnel — remote/local management mutates global Cloudflare credentials,
111
- // cloudflared auth, and ingress rules. Quick Tunnel is ephemeral and stays
112
- // open. Read-only routes (status, *-list, ingress, auth-status) stay open so
113
- // any authenticated user can see what is active.
114
- 'tunnel:remote:config:add',
115
- 'tunnel:remote:config:remove',
116
- 'tunnel:remote:start',
117
- 'tunnel:remote:stop',
118
- 'tunnel:local:login-start',
119
- 'tunnel:local:login-cancel',
120
- 'tunnel:local:logout',
121
- 'tunnel:local:set-zone',
122
- 'tunnel:local:create',
123
- 'tunnel:local:delete',
124
- 'tunnel:local:ingress:add',
125
- 'tunnel:local:ingress:remove',
126
- 'tunnel:local:start',
127
- 'tunnel:local:stop',
128
- // External MCP — installing/removing servers from the official registry is a
129
- // global, system-wide operation (it applies to every engine and project), so
130
- // the whole surface is admin-only, mirroring Stack and Engines.
131
- 'mcp:catalog',
132
- 'mcp:list',
133
- 'mcp:parse-config',
134
- 'mcp:install',
135
- 'mcp:toggle',
136
- 'mcp:update-config',
137
- 'mcp:uninstall',
138
- 'mcp:status',
139
- 'mcp:oauth-start',
140
- 'mcp:oauth-complete',
141
- // Per-tool control + inspector — introspects/filters an installed server's
142
- // tools and can invoke them, so it stays within the admin-only MCP surface.
143
- 'mcp:tools',
144
- 'mcp:set-tool-overrides',
145
- 'mcp:call-tool',
146
- 'mcp:engine-config',
147
- // Third-party integrations. A connected account holds a credential and
148
- // projects rows onto surfaces every engine and every project can reach, so
149
- // the whole surface is admin-only for the same reason MCP is. The read
150
- // events are gated too: `integrations:list` names which services this
151
- // install is connected to, and `integrations:secrets-health` describes the
152
- // state of the key that protects them.
153
- 'integrations:providers',
154
- 'integrations:list',
155
- 'integrations:connect',
156
- 'integrations:update',
157
- 'integrations:disconnect',
158
- 'integrations:health',
159
- 'integrations:secrets-health',
160
- // Account-backed database connections. Linking reads a credential belonging
161
- // to the install rather than to the caller, and projects a connection every
162
- // admin sees — the same reason the rest of the integrations surface is
163
- // admin-only. The ordinary db-client routes stay open: a member still
164
- // manages their own hand-typed connections exactly as before.
165
- 'db-client:providers',
166
- 'db-client:remote-databases',
167
- 'db-client:create-options',
168
- // Provisions real infrastructure against the account's quota, which is as
169
- // outward-facing as anything on this surface gets. Creating an organisation
170
- // creates a BILLING entity, which is more so.
171
- 'db-client:create-group',
172
- 'db-client:create-database',
173
- // Renames a database everyone at the provider sees.
174
- 'db-client:rename-database',
175
- // Destroys a database and everything in it.
176
- 'db-client:delete-database',
177
- 'db-client:link',
178
- 'db-client:update-link',
179
- 'db-client:unlink',
180
- // Applying a migration changes a schema everyone shares, and writing types
181
- // writes a file into the repository. The Supabase READS are not listed, so
182
- // anyone who can use the connection can look.
183
- 'db-client:supabase-apply-migration',
184
- 'db-client:supabase-write-types',
185
- // Worktree database branching. Pointing a project at a parent database
186
- // commits an account's quota to it, and deleting a branch destroys a real
187
- // database — both spend a credential that belongs to the install rather than
188
- // to the caller, the same reason `db-client:link` is gated.
189
- //
190
- // `worktrees:branching-state` and `worktrees:branch-rewrite-env` are
191
- // deliberately NOT listed: a member has to be able to see whether their own
192
- // worktree got a branch, and to retry the dotenv write when it was refused.
193
- //
194
- // NEITHER ARE `worktrees:branch-parents` AND `worktrees:branching-save`, and
195
- // that is a change rather than an oversight. They used to be here because a
196
- // binding could only point at an integration account, and committing the
197
- // install's quota is an admin decision. A binding can now point at a DB
198
- // Client connection instead — a database the member themselves saved — and
199
- // refusing that would make "give this worktree its own database" an
200
- // admin-only feature for no reason that survives being stated. The account
201
- // half keeps the old rule: `listBranchSources` shows accounts to admins
202
- // only, and `requireSource` refuses anything the caller cannot see.
203
- 'worktrees:branching-clear',
204
- 'worktrees:branch-orphans',
205
- 'worktrees:branch-delete',
206
- 'worktrees:branch-forget',
207
- 'worktrees:branch-delete-remote',
208
- // Memory Graph — the graph is instance-global and is injected into every
209
- // future turn on every engine, so editing it changes what every agent is told.
210
- // Mutations only: the read surface (memory:graph / :node / :search / :stats /
211
- // :config) stays open so any member can see what the project has learned.
212
- 'memory:save-node',
213
- 'memory:archive-node',
214
- 'memory:restore-nodes',
215
- 'memory:save-config',
216
- // Writing a memory by hand. `draft-node` is gated too even though it stores
217
- // nothing: it spends a model call, and a member who cannot save the result has
218
- // no reason to be able to generate one.
219
- 'memory:draft-node',
220
- 'memory:create-node',
221
- // Hard deletes. `delete-nodes` is reached only from the forgotten list, but
222
- // `purge` empties a project — or the entire instance — in one call, which is
223
- // the most destructive action the memory surface has.
224
- 'memory:delete-nodes',
225
- 'memory:purge',
226
- // Re-running failed extractions costs model calls, so it is an admin action —
227
- // reading the queue's status is not.
228
- 'memory:retry-failed',
229
- // Agent Skills — creating/importing/installing skills writes to the shared
230
- // canonical store and applies to every engine, so the whole surface is
231
- // admin-only, mirroring MCP and Stack. This now covers what used to be a
232
- // separate Commands menu: a `/slash` prompt is a skill with a slash trigger.
233
- // `skills:available` is deliberately NOT here — every member needs it to type
234
- // a command, and it exposes display fields only.
235
- 'skills:list',
236
- 'skills:get',
237
- 'skills:create',
238
- 'skills:update',
239
- 'skills:parse-import',
240
- 'skills:import',
241
- 'skills:toggle',
242
- 'skills:delete',
243
- 'skills:catalog',
244
- 'skills:install',
245
- 'skills:detect',
246
- 'skills:adopt',
247
- // Subagents — shared canonical store applied to every engine; admin-only.
248
- 'subagents:list',
249
- 'subagents:get',
250
- 'subagents:create',
251
- 'subagents:update',
252
- 'subagents:parse-import',
253
- 'subagents:import',
254
- 'subagents:toggle',
255
- 'subagents:delete',
256
- 'subagents:detect',
257
- // Project Instructions — writes managed regions into engine memory files; admin-only.
258
- 'instructions:get-global',
259
- 'instructions:save-global',
260
- 'instructions:get-project',
261
- 'instructions:save-project',
262
- // Project artifacts — reads and in-place edits of a repository's `.agents/`,
263
- // `AGENTS.md` block and `.agents/mcp.json` (whose approval lets Clopen start
264
- // the processes it declares). Same shared-store rationale; admin-only.
265
- 'project-artifacts:scan',
266
- 'project-artifacts:read',
267
- 'project-artifacts:save-skill',
268
- 'project-artifacts:delete-skill',
269
- 'project-artifacts:save-subagent',
270
- 'project-artifacts:delete-subagent',
271
- 'project-artifacts:copy-to-agents',
272
- 'project-artifacts:get-agents-md',
273
- 'project-artifacts:save-agents-md',
274
- 'project-artifacts:get-mcp',
275
- 'project-artifacts:save-mcp',
276
- 'project-artifacts:approve-mcp',
277
- // Permissions — per-engine tool allow/deny applied to every engine/project;
278
- // same shared-store rationale as Skills/MCP, admin-only surface.
279
- 'permissions:list',
280
- 'permissions:inventory',
281
- 'permissions:save',
282
- // AI authoring of artifacts — part of the admin artifact editors.
283
- 'artifacts:generate',
284
- // Profiles — reusable artifact bundles applied to every collaborator's
285
- // sessions; same shared-store rationale as Skills/MCP, admin-only surface.
286
- // (profiles:available / profiles:project-default stay non-admin — choosing a
287
- // profile for a session is a run choice like the model.)
288
- 'profiles:list',
289
- 'profiles:get',
290
- 'profiles:inventory',
291
- 'profiles:create',
292
- 'profiles:update',
293
- 'profiles:delete',
294
- 'profiles:get-permissions',
295
- 'profiles:save-permissions',
296
- 'profiles:set-project-default'
297
- ]);
298
-
299
22
  /**
300
23
  * Check if a route action is allowed for the given auth state.
301
24
  * In no-auth mode, all routes are allowed (bypasses authentication check).
302
25
  */
303
26
  export function checkRouteAccess(
304
27
  action: string,
305
- authenticated: boolean,
306
- role: string | null
28
+ authenticated: boolean
307
29
  ): { allowed: boolean; error?: string } {
308
30
  // Public routes — always allowed
309
31
  if (PUBLIC_ROUTES.has(action)) {
@@ -315,17 +37,9 @@ export function checkRouteAccess(
315
37
  return { allowed: true };
316
38
  }
317
39
 
318
- // Must be authenticated for everything else
319
40
  if (!authenticated) {
320
41
  return { allowed: false, error: 'Authentication required' };
321
42
  }
322
43
 
323
- // Admin-only routes
324
- if (ADMIN_ONLY_ROUTES.has(action) && role !== 'admin') {
325
- return { allowed: false, error: 'Admin access required' };
326
- }
327
-
328
- // All other routes — any authenticated user
329
44
  return { allowed: true };
330
45
  }
331
-
@@ -68,19 +68,18 @@ describe('failure-based lockout tiers', () => {
68
68
  });
69
69
 
70
70
  describe('per-route isolation', () => {
71
- test('a lockout on auth:login does not block auth:validate-invite', () => {
71
+ test('a lockout on auth:login does not block auth:claim-device-code', () => {
72
72
  const id = uniqueId('route-iso');
73
73
  fail(id, 'auth:login', 5);
74
74
 
75
75
  expect(authRateLimiter.check(id, 'auth:login')).not.toBeNull();
76
- expect(authRateLimiter.check(id, 'auth:validate-invite')).toBeNull();
77
76
  expect(authRateLimiter.check(id, 'auth:claim-device-code')).toBeNull();
78
77
  });
79
78
 
80
79
  test('success on one route does not clear another route\'s failures', () => {
81
80
  const id = uniqueId('no-cross-clear');
82
81
  fail(id, 'auth:login', 5);
83
- authRateLimiter.recordSuccess(id, 'auth:validate-invite');
82
+ authRateLimiter.recordSuccess(id, 'auth:claim-device-code');
84
83
 
85
84
  expect(authRateLimiter.check(id, 'auth:login')).not.toBeNull();
86
85
  });
@@ -93,13 +92,13 @@ describe('per-route isolation', () => {
93
92
  expect(authRateLimiter.check(id, 'auth:login')).toBeNull();
94
93
  });
95
94
 
96
- test('a valid invite clears the failures from earlier mistyped ones', () => {
97
- const id = uniqueId('invite-retry');
98
- fail(id, 'auth:validate-invite', 2);
99
- authRateLimiter.recordSuccess(id, 'auth:validate-invite');
100
- fail(id, 'auth:validate-invite', 4);
95
+ test('a successful claim clears the failures from earlier mistyped codes', () => {
96
+ const id = uniqueId('device-retry');
97
+ fail(id, 'auth:claim-device-code', 2);
98
+ authRateLimiter.recordSuccess(id, 'auth:claim-device-code');
99
+ fail(id, 'auth:claim-device-code', 4);
101
100
 
102
- expect(authRateLimiter.check(id, 'auth:validate-invite')).toBeNull();
101
+ expect(authRateLimiter.check(id, 'auth:claim-device-code')).toBeNull();
103
102
  });
104
103
  });
105
104
 
@@ -21,8 +21,6 @@ import { debug } from '$shared/utils/logger';
21
21
  /** Routes that should be rate-limited. */
22
22
  const RATE_LIMITED_ROUTES = new Set([
23
23
  'auth:login',
24
- 'auth:accept-invite',
25
- 'auth:validate-invite',
26
24
  'auth:claim-device-code',
27
25
  'auth:setup'
28
26
  ]);
@@ -4,14 +4,12 @@
4
4
  * Token types:
5
5
  * - clp_ses_* — Session tokens (login sessions, 30 day expiry)
6
6
  * - clp_pat_* — Personal Access Tokens (cross-device login, permanent)
7
- * - clp_inv_* — Invite tokens (for inviting new users)
8
7
  * - clp_dev_* — Device-pairing codes (one-time, short TTL; Remote Access "Add a device")
9
8
  * - clp_fsh_* — File-share tokens (single-file download links, finite TTL)
10
9
  */
11
10
 
12
11
  const SESSION_PREFIX = 'clp_ses_';
13
12
  const PAT_PREFIX = 'clp_pat_';
14
- const INVITE_PREFIX = 'clp_inv_';
15
13
  const DEVICE_PREFIX = 'clp_dev_';
16
14
  const FILE_SHARE_PREFIX = 'clp_fsh_';
17
15
 
@@ -32,10 +30,6 @@ export function generatePAT(): string {
32
30
  return PAT_PREFIX + randomHex(TOKEN_BYTES);
33
31
  }
34
32
 
35
- export function generateInviteToken(): string {
36
- return INVITE_PREFIX + randomHex(TOKEN_BYTES);
37
- }
38
-
39
33
  export function generateDeviceCode(): string {
40
34
  return DEVICE_PREFIX + randomHex(TOKEN_BYTES);
41
35
  }
@@ -58,10 +52,9 @@ export function hashToken(token: string): string {
58
52
  /**
59
53
  * Determine token type from prefix
60
54
  */
61
- export function getTokenType(token: string): 'session' | 'pat' | 'invite' | 'device' | 'file-share' | 'unknown' {
55
+ export function getTokenType(token: string): 'session' | 'pat' | 'device' | 'file-share' | 'unknown' {
62
56
  if (token.startsWith(SESSION_PREFIX)) return 'session';
63
57
  if (token.startsWith(PAT_PREFIX)) return 'pat';
64
- if (token.startsWith(INVITE_PREFIX)) return 'invite';
65
58
  if (token.startsWith(DEVICE_PREFIX)) return 'device';
66
59
  if (token.startsWith(FILE_SHARE_PREFIX)) return 'file-share';
67
60
  return 'unknown';
@@ -21,6 +21,7 @@ import { SERVER_ENV } from './utils/env';
21
21
  import { ensureDefaultEngineInstalled } from './engine/bootstrap-default-engine';
22
22
  import { bootstrapMemoryGraph } from './memory/bootstrap';
23
23
  import { ensureMemoryModel } from './memory/model';
24
+ import { channelRuntime } from './chat-apps/runtime';
24
25
  import { debug } from '$shared/utils/logger';
25
26
 
26
27
  /**
@@ -68,5 +69,11 @@ export function bootstrapAfterDbInit(): void {
68
69
  // blocks startup.
69
70
  bootstrapMemoryGraph();
70
71
 
72
+ // Chat-channel bots are held open by the process, not by a row, so a data
73
+ // wipe leaves them running for accounts that no longer exist. Re-align them
74
+ // with the (now empty) accounts table. A no-op at startup: the runtime is
75
+ // not started yet, and starts — and reconciles — once the server listens.
76
+ void channelRuntime.reconcile();
77
+
71
78
  debug.log('server', '✅ Post-DB bootstrap complete');
72
79
  }
@@ -0,0 +1,88 @@
1
+ /**
2
+ * The one attachment rule: what the model reads inline stays inline, anything
3
+ * else lands in the session's folder and is named in the prompt.
4
+ */
5
+
6
+ import { describe, it, expect, beforeEach, afterEach } from 'bun:test';
7
+ import { existsSync, mkdtempSync, readFileSync, rmSync } from 'fs';
8
+ import { tmpdir } from 'os';
9
+ import { join } from 'path';
10
+ import type { StreamRequest } from '$shared/types/unified';
11
+ import { registerModels } from '$shared/constants/engines';
12
+ import { base64Size, isNative, normalizeAttachments } from './attachments';
13
+
14
+ const VISION = { text: true, image: true, pdf: true, audio: false, video: false };
15
+ const TEXT_ONLY = { text: true, image: false, pdf: false, audio: false, video: false };
16
+
17
+ function model(id: string, input: typeof VISION) {
18
+ return {
19
+ engine: { type: 'codex', provider: 'openai', model: { id, name: id }, account: { id: 0, name: '' } },
20
+ limit: { input: 0, output: 0 },
21
+ modalities: { input, output: TEXT_ONLY },
22
+ capabilities: { reasoning: false, tools: true, structuredOutput: false },
23
+ cost: { input: 0, output: 0 }
24
+ } as never;
25
+ }
26
+
27
+ function request(modelId: string, content: unknown[]): StreamRequest {
28
+ return {
29
+ projectPath: '/',
30
+ projectId: 'p',
31
+ chatSessionId: 's',
32
+ prompt: { type: 'user', content } as never,
33
+ engine: { type: 'codex', provider: 'openai', model: { id: modelId, name: modelId }, account: { id: 0, name: '' } }
34
+ };
35
+ }
36
+
37
+ const b64 = (text: string) => Buffer.from(text).toString('base64');
38
+
39
+ let root: string;
40
+
41
+ beforeEach(() => {
42
+ root = mkdtempSync(join(tmpdir(), 'clopen-attach-'));
43
+ registerModels('codex', [model('vision', VISION), model('text', TEXT_ONLY)]);
44
+ });
45
+
46
+ afterEach(() => rmSync(root, { recursive: true, force: true }));
47
+
48
+ describe('attachments', () => {
49
+ it('knows what a model reads inline', () => {
50
+ expect(isNative('image/png', VISION)).toBe(true);
51
+ expect(isNative('application/pdf', VISION)).toBe(true);
52
+ expect(isNative('image/png', TEXT_ONLY)).toBe(false);
53
+ expect(isNative('text/csv', VISION)).toBe(false);
54
+ expect(base64Size(b64('hello'))).toBe(5);
55
+ });
56
+
57
+ it('leaves a prompt alone when every file is native', async () => {
58
+ const input = request('vision', [{ type: 'image', mediaType: 'image/png', data: b64('png'), title: 'a.png' }, { type: 'text', text: 'what is this' }]);
59
+ expect(await normalizeAttachments(input, root)).toBe(input);
60
+ });
61
+
62
+ it('saves any other file into the session folder, ignored by git, and names it ahead of the text', async () => {
63
+ const result = await normalizeAttachments(
64
+ request('vision', [
65
+ { type: 'document', mediaType: 'text/csv', data: b64('a,b\n1,2'), title: 'data.csv' },
66
+ { type: 'text', text: 'summarise it' }
67
+ ]),
68
+ root
69
+ );
70
+ const content = result.prompt.content as Array<{ type: string; text?: string }>;
71
+ expect(content).toHaveLength(1);
72
+ expect(content[0].type).toBe('text');
73
+ const match = /saved at \.\/(\S+)\]/.exec(content[0].text!);
74
+ expect(match).not.toBeNull();
75
+ expect(readFileSync(join(root, match![1]), 'utf8')).toBe('a,b\n1,2');
76
+ expect(content[0].text).toContain('"data.csv"');
77
+ expect(content[0].text!.endsWith('summarise it')).toBe(true);
78
+ expect(readFileSync(join(root, '.clopen', '.gitignore'), 'utf8')).toBe('*\n');
79
+ });
80
+
81
+ it('saves an image for a model that cannot see, and adds a text block when there was none', async () => {
82
+ const result = await normalizeAttachments(request('text', [{ type: 'image', mediaType: 'image/png', data: b64('png'), title: 'shot.png' }]), root);
83
+ const content = result.prompt.content as Array<{ type: string; text?: string }>;
84
+ expect(content.map((block) => block.type)).toEqual(['text']);
85
+ expect(content[0].text).toContain('shot.png');
86
+ expect(existsSync(join(root, '.clopen', 'attachments'))).toBe(true);
87
+ });
88
+ });