@myrialabs/clopen 0.4.46 → 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 (328) 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/presets.ts +27 -2
  85. package/backend/engine/adapters/opencode/server.ts +6 -4
  86. package/backend/engine/adapters/opencode/stream.ts +11 -0
  87. package/backend/engine/adapters/parent-scope.test.ts +38 -0
  88. package/backend/engine/adapters/parent-scope.ts +44 -0
  89. package/backend/engine/adapters/pi/message-converter.ts +0 -1
  90. package/backend/engine/adapters/pi/stream.ts +4 -5
  91. package/backend/engine/adapters/qwen/message-converter.ts +0 -2
  92. package/backend/engine/bootstrap-default-engine.ts +2 -2
  93. package/backend/engine/docs/adapter-contract.md +8 -1
  94. package/backend/engine/install-runner.ts +8 -17
  95. package/backend/files/file-shares.ts +20 -44
  96. package/backend/files/file-size-limit.ts +3 -3
  97. package/backend/files/image-processing.ts +1 -1
  98. package/backend/files/os-clipboard.ts +2 -2
  99. package/backend/git/git-executor.ts +25 -5
  100. package/backend/git/git-service.ts +420 -19
  101. package/backend/git/identity/credential-helper.test.ts +2 -7
  102. package/backend/git/identity/import-local.test.ts +11 -16
  103. package/backend/git/identity/import-local.ts +12 -12
  104. package/backend/git/identity/index.ts +10 -24
  105. package/backend/git/identity/resolve.ts +13 -14
  106. package/backend/git/identity/scope-config.ts +33 -28
  107. package/backend/git/identity/service.ts +44 -47
  108. package/backend/git/op-lock.test.ts +111 -0
  109. package/backend/git/op-lock.ts +180 -0
  110. package/backend/git/remote-sync.test.ts +249 -0
  111. package/backend/host/metrics.ts +1 -1
  112. package/backend/http/bearer-auth.ts +1 -2
  113. package/backend/http/files-download.test.ts +8 -9
  114. package/backend/http/files-download.ts +2 -2
  115. package/backend/http/files-shared.test.ts +62 -89
  116. package/backend/http/files-shared.ts +2 -2
  117. package/backend/http/files-upload.test.ts +3 -7
  118. package/backend/http/files-upload.ts +3 -3
  119. package/backend/http/notes-images.test.ts +15 -38
  120. package/backend/http/notes-images.ts +6 -8
  121. package/backend/http/ssh-sftp.ts +5 -10
  122. package/backend/index.ts +21 -7
  123. package/backend/integrations/accounts.ts +61 -3
  124. package/backend/integrations/index.ts +2 -2
  125. package/backend/integrations/registry/define.ts +15 -0
  126. package/backend/integrations/registry/index.ts +2 -0
  127. package/backend/integrations/registry/providers/telegram.ts +54 -0
  128. package/backend/integrations/registry/types.ts +21 -1
  129. package/backend/integrations/webhooks/gateway.ts +7 -6
  130. package/backend/integrations/webhooks/verify.test.ts +30 -0
  131. package/backend/integrations/webhooks/verify.ts +4 -0
  132. package/backend/mcp/external/project.ts +1 -1
  133. package/backend/mcp/internal/remote-server.test.ts +1 -3
  134. package/backend/mcp/internal/remote-server.ts +4 -4
  135. package/backend/mcp/internal/servers/browser-automation/actions/dialogs.ts +67 -0
  136. package/backend/mcp/internal/servers/browser-automation/actions/index.ts +3 -1
  137. package/backend/mcp/internal/servers/browser-automation/actions/input.ts +5 -5
  138. package/backend/mcp/internal/servers/browser-automation/actions/tabs.ts +157 -28
  139. package/backend/mcp/internal/servers/browser-automation/context.ts +1 -0
  140. package/backend/mcp/internal/servers/browser-automation/description.ts +5 -2
  141. package/backend/mcp/internal/servers/browser-automation/format.ts +24 -1
  142. package/backend/mcp/internal/servers/browser-automation/runner.ts +68 -3
  143. package/backend/memory/redact.ts +1 -1
  144. package/backend/notes/access.test.ts +28 -29
  145. package/backend/notes/access.ts +6 -11
  146. package/backend/permissions/service.ts +1 -1
  147. package/backend/preview/browser/browser-clipboard.test.ts +46 -0
  148. package/backend/preview/browser/browser-clipboard.ts +67 -0
  149. package/backend/preview/browser/browser-dialog-handler.ts +95 -6
  150. package/backend/preview/browser/browser-host-bridge.ts +9 -0
  151. package/backend/preview/browser/browser-interaction-handler.ts +316 -86
  152. package/backend/preview/browser/browser-mcp-control.ts +34 -0
  153. package/backend/preview/browser/browser-pool.ts +67 -6
  154. package/backend/preview/browser/browser-preview-service.ts +361 -25
  155. package/backend/preview/browser/browser-tab-manager.ts +66 -23
  156. package/backend/preview/browser/browser-video-capture.ts +92 -5
  157. package/backend/preview/browser/element-locator.ts +190 -17
  158. package/backend/preview/browser/keyboard-chords.test.ts +68 -0
  159. package/backend/preview/browser/keyboard-chords.ts +132 -0
  160. package/backend/preview/browser/paste.ts +81 -0
  161. package/backend/preview/browser/process-usage.ts +142 -0
  162. package/backend/preview/browser/profile-lock.ts +209 -0
  163. package/backend/preview/browser/scripts/host-bridge.ts +59 -0
  164. package/backend/preview/browser/scripts/video-stream.ts +58 -0
  165. package/backend/preview/browser/types.ts +40 -2
  166. package/backend/preview/browser/viewport.test.ts +45 -0
  167. package/backend/preview/browser/viewport.ts +96 -0
  168. package/backend/profiles/service.ts +2 -2
  169. package/backend/project/status-manager.ts +43 -172
  170. package/backend/projects/home.ts +61 -0
  171. package/backend/projects/project-cleanup.integration.test.ts +2 -2
  172. package/backend/projects/project-cleanup.ts +0 -8
  173. package/backend/skills/service.ts +2 -3
  174. package/backend/snapshot/helpers.ts +0 -1
  175. package/backend/snapshot/restore.ts +252 -0
  176. package/backend/ssh/ptykit.ts +1 -2
  177. package/backend/terminal/ptykit.ts +5 -8
  178. package/backend/tunnel/public-origin.ts +31 -20
  179. package/backend/utils/user-helpers.ts +0 -55
  180. package/backend/utils/ws.ts +61 -154
  181. package/backend/worktrees/branching/engine.ts +3 -16
  182. package/backend/worktrees/branching/index.ts +1 -1
  183. package/backend/worktrees/branching/projector.ts +1 -1
  184. package/backend/worktrees/branching/service.ts +13 -25
  185. package/backend/ws/access.ts +12 -21
  186. package/backend/ws/artifacts/generate.ts +2 -2
  187. package/backend/ws/auth/device.ts +16 -71
  188. package/backend/ws/auth/index.ts +4 -22
  189. package/backend/ws/auth/login.test.ts +14 -60
  190. package/backend/ws/auth/login.ts +24 -124
  191. package/backend/ws/auth/status.ts +0 -1
  192. package/backend/ws/chat/composer.ts +118 -118
  193. package/backend/ws/chat/stream.ts +64 -47
  194. package/backend/ws/chat-apps/index.ts +117 -0
  195. package/backend/ws/containers/actions.ts +11 -25
  196. package/backend/ws/containers/index.ts +3 -4
  197. package/backend/ws/containers/list.ts +10 -36
  198. package/backend/ws/containers/logs.ts +2 -2
  199. package/backend/ws/containers/tunnel.ts +1 -2
  200. package/backend/ws/db-client/access.ts +2 -16
  201. package/backend/ws/db-client/accounts.ts +5 -15
  202. package/backend/ws/db-client/connections.ts +17 -25
  203. package/backend/ws/db-client/context.ts +1 -1
  204. package/backend/ws/db-client/env.ts +7 -10
  205. package/backend/ws/db-client/index.ts +2 -2
  206. package/backend/ws/db-client/io.ts +5 -5
  207. package/backend/ws/db-client/query-history-retention.test.ts +8 -8
  208. package/backend/ws/db-client/query.ts +18 -17
  209. package/backend/ws/db-client/schema.ts +13 -13
  210. package/backend/ws/db-client/structure.ts +35 -35
  211. package/backend/ws/db-client/supabase.ts +4 -21
  212. package/backend/ws/deployments/context.ts +1 -1
  213. package/backend/ws/deployments/crud.ts +0 -5
  214. package/backend/ws/engine/access.ts +7 -20
  215. package/backend/ws/engine/claude/accounts.ts +4 -4
  216. package/backend/ws/engine/cline/accounts.ts +5 -5
  217. package/backend/ws/engine/codex/accounts.ts +3 -3
  218. package/backend/ws/engine/opencode/providers.ts +2 -1
  219. package/backend/ws/engine/pi/accounts.ts +5 -5
  220. package/backend/ws/files/clipboard.ts +8 -27
  221. package/backend/ws/files/image-edit.ts +6 -6
  222. package/backend/ws/files/index.ts +1 -1
  223. package/backend/ws/files/path-access.test.ts +32 -131
  224. package/backend/ws/files/path-access.ts +8 -87
  225. package/backend/ws/files/read.ts +15 -19
  226. package/backend/ws/files/reveal.ts +3 -3
  227. package/backend/ws/files/search.ts +7 -7
  228. package/backend/ws/files/share.ts +9 -13
  229. package/backend/ws/files/state.ts +9 -12
  230. package/backend/ws/files/watch.ts +3 -3
  231. package/backend/ws/files/write.ts +30 -31
  232. package/backend/ws/git/branch.ts +80 -59
  233. package/backend/ws/git/commit.ts +63 -44
  234. package/backend/ws/git/conflict.ts +16 -18
  235. package/backend/ws/git/identity-context.ts +8 -17
  236. package/backend/ws/git/identity.ts +17 -27
  237. package/backend/ws/git/index.ts +3 -1
  238. package/backend/ws/git/op-state.ts +139 -0
  239. package/backend/ws/git/remote.ts +241 -141
  240. package/backend/ws/git/repo-context.ts +67 -0
  241. package/backend/ws/git/staging.ts +18 -28
  242. package/backend/ws/git/status.ts +5 -2
  243. package/backend/ws/index.ts +5 -1
  244. package/backend/ws/instructions/crud.ts +1 -1
  245. package/backend/ws/integrations/crud.ts +1 -3
  246. package/backend/ws/mcp/crud.ts +3 -5
  247. package/backend/ws/mcp/tools.ts +1 -1
  248. package/backend/ws/memory/crud.ts +14 -46
  249. package/backend/ws/memory/index.ts +2 -2
  250. package/backend/ws/messages/crud.ts +29 -8
  251. package/backend/ws/notes/index.ts +33 -39
  252. package/backend/ws/permissions/crud.ts +3 -4
  253. package/backend/ws/ports/index.ts +1 -2
  254. package/backend/ws/ports/kill.ts +5 -10
  255. package/backend/ws/ports/list.ts +4 -10
  256. package/backend/ws/preview/access.ts +1 -1
  257. package/backend/ws/preview/browser/interact.ts +52 -79
  258. package/backend/ws/preview/browser/native-ui.ts +24 -0
  259. package/backend/ws/preview/browser/stats.ts +98 -1
  260. package/backend/ws/preview/browser/tab-info.ts +15 -0
  261. package/backend/ws/preview/browser/tab.ts +19 -4
  262. package/backend/ws/preview/index.ts +27 -0
  263. package/backend/ws/profiles/crud.ts +6 -8
  264. package/backend/ws/project-artifacts/index.ts +30 -31
  265. package/backend/ws/projects/crud.ts +33 -35
  266. package/backend/ws/projects/index.ts +3 -8
  267. package/backend/ws/projects/info.ts +3 -3
  268. package/backend/ws/projects/overview.ts +19 -30
  269. package/backend/ws/projects/status.ts +17 -57
  270. package/backend/ws/sessions/crud.ts +34 -45
  271. package/backend/ws/sessions/index.ts +1 -1
  272. package/backend/ws/settings/crud.ts +1 -1
  273. package/backend/ws/skills/crud.ts +3 -4
  274. package/backend/ws/skills/index.ts +1 -1
  275. package/backend/ws/snapshot/changes.ts +7 -7
  276. package/backend/ws/snapshot/restore.ts +11 -295
  277. package/backend/ws/snapshot/timeline.ts +2 -4
  278. package/backend/ws/ssh/access.ts +6 -21
  279. package/backend/ws/ssh/connections.ts +21 -31
  280. package/backend/ws/ssh/forwards.ts +12 -12
  281. package/backend/ws/ssh/sftp.ts +34 -34
  282. package/backend/ws/ssh/tunnel.ts +1 -2
  283. package/backend/ws/stack/install.ts +7 -17
  284. package/backend/ws/subagents/crud.ts +1 -1
  285. package/backend/ws/tunnel/share.ts +0 -2
  286. package/backend/ws/user/crud.ts +1 -59
  287. package/backend/ws/user/index.ts +1 -1
  288. package/backend/ws/work/context.ts +1 -1
  289. package/backend/ws/work/crud.ts +0 -5
  290. package/backend/ws/workspace/state.ts +10 -13
  291. package/backend/ws/worktrees/branching.ts +7 -36
  292. package/backend/ws/worktrees/crud.ts +2 -2
  293. package/bin/clopen.ts +10 -11
  294. package/dist/assets/{index-CwuKQelV.js → index-CONlwAXZ.js} +1 -1
  295. package/dist/assets/{index-BTcR1byF.js → index-DJzwt-hq.js} +1 -1
  296. package/dist/assets/main-BUiUL3eZ.css +1 -0
  297. package/dist/assets/main-nBOb9YOA.js +1240 -0
  298. package/dist/index.html +2 -2
  299. package/package.json +2 -1
  300. package/shared/constants/attachments.ts +14 -0
  301. package/shared/constants/engine-tools.ts +1 -1
  302. package/shared/constants/preview.test.ts +259 -0
  303. package/shared/constants/preview.ts +1018 -57
  304. package/shared/constants/tool-icons.ts +5 -0
  305. package/shared/types/containers/container.ts +1 -1
  306. package/shared/types/database/schema.ts +9 -6
  307. package/shared/types/git-identity.ts +1 -1
  308. package/shared/types/git.ts +116 -0
  309. package/shared/types/integrations.ts +7 -0
  310. package/shared/types/stores/settings.ts +1 -1
  311. package/shared/types/unified/index.ts +1 -1
  312. package/shared/types/unified/message.ts +0 -7
  313. package/shared/types/unified/stream.ts +2 -4
  314. package/shared/types/unified/tool.ts +15 -1
  315. package/shared/utils/ask-user-question.test.ts +319 -0
  316. package/shared/utils/ask-user-question.ts +154 -0
  317. package/shared/utils/home-project.ts +25 -0
  318. package/shared/utils/logger.ts +2 -0
  319. package/shared/utils/ws-server.ts +32 -7
  320. package/backend/auth/session-invalidation.test.ts +0 -112
  321. package/backend/auth/session-invalidation.ts +0 -77
  322. package/backend/project/status-manager.test.ts +0 -32
  323. package/backend/ws/auth/invites.ts +0 -94
  324. package/backend/ws/auth/users.ts +0 -112
  325. package/backend/ws/projects/presence.ts +0 -46
  326. package/backend/ws/stack/access.ts +0 -31
  327. package/dist/assets/main-BiDNMWb3.css +0 -1
  328. package/dist/assets/main-BlhKWz2B.js +0 -1241
@@ -47,8 +47,6 @@ const sessionSchema = t.Object({
47
47
  // Isolation
48
48
  worktree_id: t.Optional(t.Union([t.String(), t.Null()])),
49
49
  // Activity tracking
50
- sender_id: t.Optional(t.String()),
51
- sender_name: t.Optional(t.String()),
52
50
  message_count: t.Optional(t.Number()),
53
51
  user_count: t.Optional(t.Number()),
54
52
  last_message_at: t.Optional(t.String()),
@@ -73,8 +71,6 @@ function serializeSession(session: ChatSession) {
73
71
  head_message_id: session.head_message_id ?? undefined,
74
72
  head_session_id: session.head_session_id ?? undefined,
75
73
  ended_at: session.ended_at ?? undefined,
76
- sender_id: session.sender_id ?? undefined,
77
- sender_name: session.sender_name ?? undefined,
78
74
  head_title: session.head_title ?? undefined,
79
75
  head_summary: session.head_summary ?? undefined,
80
76
  message_count: session.message_count ?? undefined,
@@ -104,15 +100,14 @@ export const crudHandler = createRouter()
104
100
  }))
105
101
  })
106
102
  }, async ({ conn }) => {
107
- const { projectId, userId } = requireCurrentProjectAccess(conn);
103
+ const { projectId } = requireCurrentProjectAccess(conn);
108
104
  const sessions = sessionQueries.getByProjectId(projectId);
109
105
 
110
- // Get the user's saved current session for this project
111
- const currentSessionId = projectQueries.getCurrentSessionId(userId, projectId);
106
+ // The saved current session for this project
107
+ const currentSessionId = projectQueries.getCurrentSessionId(projectId);
112
108
 
113
- // Get unread sessions for this user/project
114
- const unreadRows = sessionQueries.getUnreadSessions(userId, projectId);
115
- debug.log('session', `[unread] sessions:list — user=${userId}, project=${projectId}, unreadCount=${unreadRows.length}`, unreadRows);
109
+ const unreadRows = sessionQueries.getUnreadSessions(projectId);
110
+ debug.log('session', `[unread] sessions:list — project=${projectId}, unreadCount=${unreadRows.length}`, unreadRows);
116
111
 
117
112
  return {
118
113
  sessions: sessions.map(serializeSession),
@@ -163,8 +158,8 @@ export const crudHandler = createRouter()
163
158
  session: sessionSchema,
164
159
  messages: t.Array(t.Any())
165
160
  })
166
- }, async ({ data, conn }) => {
167
- const session = requireSessionAccess(conn, data.id);
161
+ }, async ({ data }) => {
162
+ const session = requireSessionAccess(data.id);
168
163
 
169
164
  // Also get messages for this session
170
165
  const messages = messageQueries.getBySessionId(data.id);
@@ -222,8 +217,8 @@ export const crudHandler = createRouter()
222
217
  end_session: t.Optional(t.Boolean())
223
218
  }),
224
219
  response: sessionSchema
225
- }, async ({ data, conn }) => {
226
- requireSessionAccess(conn, data.id);
220
+ }, async ({ data }) => {
221
+ requireSessionAccess(data.id);
227
222
 
228
223
  if (data.title) {
229
224
  sessionQueries.updateTitle(data.id, data.title);
@@ -249,8 +244,8 @@ export const crudHandler = createRouter()
249
244
  response: t.Object({
250
245
  message: t.String()
251
246
  })
252
- }, async ({ data, conn }) => {
253
- const session = requireSessionAccess(conn, data.id);
247
+ }, async ({ data }) => {
248
+ const session = requireSessionAccess(data.id);
254
249
 
255
250
  const projectId = session.project_id;
256
251
 
@@ -293,7 +288,7 @@ export const crudHandler = createRouter()
293
288
  }
294
289
  }
295
290
 
296
- // Broadcast to all project members so other users see the deletion
291
+ // Broadcast to the project so other devices see the deletion
297
292
  debug.log('session', `Broadcasting session deleted: ${data.id} in project: ${projectId}`);
298
293
  ws.emit.project(projectId, 'sessions:session-deleted', {
299
294
  sessionId: data.id,
@@ -394,57 +389,52 @@ export const crudHandler = createRouter()
394
389
  };
395
390
  })
396
391
 
397
- // Persist user's current session choice (for refresh restore)
392
+ // Persist the current session choice (for refresh restore)
398
393
  .on('sessions:set-current', {
399
394
  data: t.Object({
400
395
  sessionId: t.String()
401
396
  })
402
397
  }, async ({ data, conn }) => {
403
- const { projectId, userId } = requireCurrentProjectAccess(conn);
404
- requireSessionAccess(conn, data.sessionId);
405
- projectQueries.setCurrentSessionId(userId, projectId, data.sessionId);
406
- debug.log('session', `User ${userId} set current session to ${data.sessionId} in project ${projectId}`);
398
+ const { projectId } = requireCurrentProjectAccess(conn);
399
+ requireSessionAccess(data.sessionId);
400
+ projectQueries.setCurrentSessionId(projectId, data.sessionId);
401
+ debug.log('session', `Current session set to ${data.sessionId} in project ${projectId}`);
407
402
  })
408
403
 
409
- // Mark a session as read for the current user
410
404
  .on('sessions:mark-read', {
411
405
  data: t.Object({
412
406
  sessionId: t.String()
413
407
  })
414
- }, async ({ data, conn }) => {
415
- const userId = ws.getUserId(conn);
416
- requireSessionAccess(conn, data.sessionId);
417
- sessionQueries.markRead(userId, data.sessionId);
418
- debug.log('session', `[unread] Marked session ${data.sessionId} as READ for user ${userId}`);
408
+ }, async ({ data }) => {
409
+ requireSessionAccess(data.sessionId);
410
+ sessionQueries.markRead(data.sessionId);
411
+ debug.log('session', `[unread] Marked session ${data.sessionId} as READ`);
419
412
  })
420
413
 
421
- // Mark a session as unread for the current user
422
414
  .on('sessions:mark-unread', {
423
415
  data: t.Object({
424
416
  sessionId: t.String(),
425
417
  projectId: t.String()
426
418
  })
427
- }, async ({ data, conn }) => {
428
- const userId = ws.getUserId(conn);
429
- const session = requireSessionAccess(conn, data.sessionId);
430
- requireProjectAccess(conn, data.projectId);
419
+ }, async ({ data }) => {
420
+ const session = requireSessionAccess(data.sessionId);
421
+ requireProjectAccess(data.projectId);
431
422
  if (session.project_id !== data.projectId) {
432
423
  throw new Error('Access denied');
433
424
  }
434
- sessionQueries.markUnread(userId, data.sessionId, data.projectId);
435
- debug.log('session', `[unread] Marked session ${data.sessionId} as UNREAD for user ${userId} in project ${data.projectId}`);
425
+ sessionQueries.markUnread(data.sessionId, data.projectId);
426
+ debug.log('session', `[unread] Marked session ${data.sessionId} as UNREAD in project ${data.projectId}`);
436
427
  })
437
428
 
438
- // Mark every session in a project as read for the current user
429
+ // Mark every session in a project as read
439
430
  .on('sessions:mark-all-read', {
440
431
  data: t.Object({
441
432
  projectId: t.String()
442
433
  })
443
- }, async ({ data, conn }) => {
444
- const userId = ws.getUserId(conn);
445
- requireProjectAccess(conn, data.projectId);
446
- sessionQueries.markAllRead(userId, data.projectId);
447
- debug.log('session', `[unread] Marked ALL sessions as READ for user ${userId} in project ${data.projectId}`);
434
+ }, async ({ data }) => {
435
+ requireProjectAccess(data.projectId);
436
+ sessionQueries.markAllRead(data.projectId);
437
+ debug.log('session', `[unread] Marked ALL sessions as READ in project ${data.projectId}`);
448
438
  })
449
439
 
450
440
  // Search sessions by message content within the current project (deep search)
@@ -464,7 +454,7 @@ export const crudHandler = createRouter()
464
454
  return { results };
465
455
  })
466
456
 
467
- // Search sessions across every project the user has access to (Command Palette)
457
+ // Search sessions across every project in the workspace list (Command Palette)
468
458
  .http('sessions:search-global', {
469
459
  data: t.Object({
470
460
  query: t.String({ minLength: 1 })
@@ -472,9 +462,8 @@ export const crudHandler = createRouter()
472
462
  response: t.Object({
473
463
  sessions: t.Array(sessionSearchResultSchema)
474
464
  })
475
- }, async ({ data, conn }) => {
476
- const userId = ws.getUserId(conn);
477
- const results = sessionQueries.searchGlobal(userId, data.query);
465
+ }, async ({ data }) => {
466
+ const results = sessionQueries.searchGlobal(data.query);
478
467
  return {
479
468
  sessions: results.map(r => ({ ...serializeSession(r), matchSnippet: r.matchSnippet }))
480
469
  };
@@ -18,7 +18,7 @@ export const sessionsRouter = createRouter()
18
18
  .emit('sessions:session-available', t.Object({
19
19
  session: t.Any()
20
20
  }))
21
- // Notification: a session was deleted by another user
21
+ // Notification: a session was deleted on another device
22
22
  .emit('sessions:session-deleted', t.Object({
23
23
  sessionId: t.String(),
24
24
  projectId: t.String()
@@ -63,7 +63,7 @@ export const crudHandler = createRouter()
63
63
  return setting;
64
64
  })
65
65
 
66
- // Merge-update system settings (admin only).
66
+ // Merge-update system settings.
67
67
  // Sending only the changed keys prevents a partial update from clobbering
68
68
  // sibling fields (e.g. the onboarding marker) when a client's in-memory copy
69
69
  // of the settings is stale. The merge itself lives in the system-settings
@@ -15,9 +15,8 @@
15
15
  * - skills:adopt — link an adoptable on-disk skill into Clopen's engine dir
16
16
  * - skills:available — slash-invocable skills for the chat "/" picker
17
17
  *
18
- * Mutations are admin-gated (see backend/auth/permissions.ts) — except
19
- * `skills:available`, which any user needs in order to type a command. Changes
20
- * take effect on the next chat stream, when each engine re-syncs its skills.
18
+ * Changes take effect on the next chat stream, when each engine re-syncs its
19
+ * skills.
21
20
  */
22
21
 
23
22
  import { t } from 'elysia';
@@ -207,7 +206,7 @@ export const skillCrudHandler = createRouter()
207
206
  return { linkedTo };
208
207
  })
209
208
  .http('skills:available', {
210
- // Non-admin: slash-invocable skills for the chat "/" picker (display fields
209
+ // Slash-invocable skills for the chat "/" picker (display fields
211
210
  // only), narrowed by the session's active profile same as stream sync.
212
211
  data: t.Object({
213
212
  profileId: t.Optional(t.Union([t.Number(), t.Null()])),
@@ -5,7 +5,7 @@
5
5
  * covering model-invoked skills and user-invoked `/slash` prompts:
6
6
  * - skills:list / get / create / update / import / toggle / delete — CRUD
7
7
  * - skills:detect / adopt — on-disk skills, and linking one Clopen doesn't own
8
- * - skills:available — the chat "/" picker (the one non-admin route here)
8
+ * - skills:available — the chat "/" picker
9
9
  * - skills:catalog / install — browse + install from a marketplace provider
10
10
  */
11
11
 
@@ -139,8 +139,8 @@ export const changesHandler = createRouter()
139
139
  /** Net over the whole active path — what the chat changed, not the sum of its turns. */
140
140
  net: NET_SCHEMA
141
141
  })
142
- }, async ({ data, conn }) => {
143
- requireSessionAccess(conn, data.sessionId);
142
+ }, async ({ data }) => {
143
+ requireSessionAccess(data.sessionId);
144
144
 
145
145
  const activePath = activeCheckpoints(data.sessionId);
146
146
  const readBlob = (hash: string) => blobStore.readBlob(hash);
@@ -206,14 +206,14 @@ export const changesHandler = createRouter()
206
206
  ]),
207
207
  isBinary: t.Boolean()
208
208
  })
209
- }, async ({ data, conn }) => {
209
+ }, async ({ data }) => {
210
210
  const unchanged = { before: null, after: null, status: 'unchanged' as const, isBinary: false };
211
211
 
212
212
  const sessionId = data.messageId
213
- ? requireMessageAccess(conn, data.messageId).session_id
213
+ ? requireMessageAccess(data.messageId).session_id
214
214
  : data.sessionId;
215
215
  if (!sessionId) return unchanged;
216
- if (!data.messageId) requireSessionAccess(conn, sessionId);
216
+ if (!data.messageId) requireSessionAccess(sessionId);
217
217
 
218
218
  const session = sessionQueries.getById(sessionId);
219
219
  const root = resolveSessionRoot(sessionId)?.path
@@ -282,8 +282,8 @@ export const changesHandler = createRouter()
282
282
  /** Net over the active path including the running turn; null when it adds nothing. */
283
283
  net: t.Union([NET_SCHEMA, t.Null()])
284
284
  })
285
- }, async ({ data, conn }) => {
286
- requireSessionAccess(conn, data.sessionId);
285
+ }, async ({ data }) => {
286
+ requireSessionAccess(data.sessionId);
287
287
 
288
288
  const session = sessionQueries.getById(data.sessionId);
289
289
  if (!session) return { files: [], net: null };
@@ -4,25 +4,17 @@
4
4
  * Two-phase restore:
5
5
  * 1. Check conflicts: detect files modified by other sessions
6
6
  * 2. Execute restore: undo session-scoped changes, respecting conflict resolutions
7
+ *
8
+ * The logic lives in `backend/snapshot/restore.ts` so a chat channel can go
9
+ * back to a checkpoint exactly as the web UI does; these routes only check
10
+ * access and delegate.
7
11
  */
8
12
 
9
13
  import { t } from 'elysia';
10
14
  import { createRouter } from '$shared/utils/ws-server';
11
- import { messageQueries, sessionQueries, checkpointQueries } from '../../database/queries';
12
- import { snapshotService } from '../../snapshot/snapshot-service';
13
- import { streamManager } from '../../chat/stream-manager';
14
15
  import { debug } from '$shared/utils/logger';
15
- import type { UnifiedMessage } from '$shared/types/unified';
16
- import {
17
- buildCheckpointTree,
18
- getCheckpointPathToRoot,
19
- findCheckpointForHead,
20
- findSessionEnd,
21
- INITIAL_NODE_ID
22
- } from '../../snapshot/helpers';
23
- import { ws } from '$backend/utils/ws';
16
+ import { checkSessionRestoreConflicts, restoreSessionTo } from '../../snapshot/restore';
24
17
  import { requireSessionAccess } from '../access';
25
- import { resolveSessionRoot } from '../../worktrees';
26
18
 
27
19
  export const restoreHandler = createRouter()
28
20
  /**
@@ -47,44 +39,12 @@ export const restoreHandler = createRouter()
47
39
  })),
48
40
  checkpointsToUndo: t.Array(t.String())
49
41
  })
50
- }, async ({ data, conn }) => {
42
+ }, async ({ data }) => {
51
43
  const { messageId, sessionId } = data;
52
- requireSessionAccess(conn, sessionId);
53
-
54
- debug.log('snapshot', `Checking restore conflicts for checkpoint ${messageId} in session ${sessionId}`);
55
-
56
- // Read file contents from the tree this session actually runs in —
57
- // its worktree when it has one, the project otherwise.
58
- const projectPath = resolveSessionRoot(sessionId)?.path || undefined;
59
-
60
- // Build checkpoint path for branch-aware conflict detection
61
- let targetPath: string[] | undefined;
62
- let resolvedMessageId: string | null = messageId === INITIAL_NODE_ID ? null : messageId;
63
-
64
- if (messageId !== INITIAL_NODE_ID) {
65
- const allMessages = messageQueries.getAllBySessionId(sessionId);
66
- const { checkpoints, parentMap } = buildCheckpointTree(allMessages);
67
- const checkpointIdSet = new Set(checkpoints.map(c => c.id));
68
-
69
- const resolvedId = checkpointIdSet.has(messageId)
70
- ? messageId
71
- : findCheckpointForHead(messageId, allMessages, checkpointIdSet);
72
-
73
- if (resolvedId) {
74
- resolvedMessageId = resolvedId;
75
- targetPath = getCheckpointPathToRoot(resolvedId, parentMap);
76
- }
77
- }
78
-
79
- const result = await snapshotService.checkRestoreConflicts(
80
- sessionId,
81
- resolvedMessageId,
82
- projectPath,
83
- targetPath
84
- );
44
+ requireSessionAccess(sessionId);
85
45
 
46
+ const result = await checkSessionRestoreConflicts(sessionId, messageId);
86
47
  debug.log('snapshot', `Conflict check: ${result.conflicts.length} conflicts, ${result.checkpointsToUndo.length} checkpoints to undo`);
87
-
88
48
  return result;
89
49
  })
90
50
 
@@ -108,252 +68,8 @@ export const restoreHandler = createRouter()
108
68
  filesRestored: t.Optional(t.Number()),
109
69
  filesSkipped: t.Optional(t.Number())
110
70
  })
111
- }, async ({ data, conn }) => {
71
+ }, async ({ data }) => {
112
72
  const { messageId, sessionId, conflictResolutions } = data;
113
- const session = requireSessionAccess(conn, sessionId);
114
-
115
- // Refuse to restore while this session is still generating. Restore rewrites
116
- // the working tree and resets the in-memory baseline; doing that mid-stream
117
- // would corrupt the end-of-turn snapshot and race the engine's own writes.
118
- const activeStream = streamManager.getSessionStream(sessionId, session.project_id);
119
- if (activeStream?.status === 'active') {
120
- throw new Error('Cannot restore while the chat is still generating. Stop the stream first, then try again.');
121
- }
122
-
123
- const isInitialRestore = messageId === INITIAL_NODE_ID;
124
-
125
- debug.log('snapshot', `RESTORE - ${isInitialRestore ? 'Restoring to initial state' : 'Moving HEAD to checkpoint'}`);
126
- debug.log('snapshot', `Target: ${messageId}`);
127
- debug.log('snapshot', `Session: ${sessionId}`);
128
-
129
- // Handle restore to initial state (before any messages)
130
- if (isInitialRestore) {
131
- // Clear HEAD (no messages active)
132
- sessionQueries.clearHead(sessionId);
133
- sessionQueries.rederiveHeadSnapshot(sessionId);
134
- debug.log('snapshot', 'HEAD cleared (initial state)');
135
-
136
- // Clear head_session_id so next chat starts fresh
137
- const db = (await import('../../database')).getDatabase();
138
- db.prepare(`UPDATE chat_sessions SET head_session_id = NULL WHERE id = ?`).run(sessionId);
139
-
140
- // Clear checkpoint_tree_state
141
- checkpointQueries.deleteForSession(sessionId);
142
-
143
- // Restore file system: revert ALL session changes
144
- let filesRestored = 0;
145
- let filesSkipped = 0;
146
-
147
- const sessionRoot = resolveSessionRoot(sessionId);
148
- if (sessionRoot?.path) {
149
- const result = await snapshotService.restoreSessionScoped(
150
- sessionRoot.path,
151
- sessionId,
152
- null, // null = restore to initial (before all snapshots)
153
- conflictResolutions
154
- );
155
- filesRestored = result.restoredFiles;
156
- filesSkipped = result.skippedFiles;
157
- }
158
-
159
- // Broadcast messages-changed
160
- try {
161
- ws.emit.chatSession(sessionId, 'chat:messages-changed', {
162
- sessionId,
163
- reason: 'restore',
164
- timestamp: new Date().toISOString()
165
- });
166
- } catch (err) {
167
- debug.error('snapshot', 'Failed to broadcast messages-changed:', err);
168
- }
169
-
170
- return {
171
- restoredTo: {
172
- messageId: INITIAL_NODE_ID,
173
- timestamp: new Date().toISOString()
174
- },
175
- filesRestored,
176
- filesSkipped
177
- };
178
- }
179
-
180
- // Regular checkpoint restore
181
- // 1. Get the target message
182
- const checkpointMessage = messageQueries.getById(messageId);
183
- if (!checkpointMessage) {
184
- throw new Error('Checkpoint message not found');
185
- }
186
-
187
- // 2. Get current HEAD
188
- const currentHead = sessionQueries.getHead(sessionId);
189
- debug.log('snapshot', `Current HEAD: ${currentHead}`);
190
-
191
- // 3. Get all messages and build checkpoint tree
192
- const allMessages = messageQueries.getAllBySessionId(sessionId);
193
- const { checkpoints, parentMap } = buildCheckpointTree(allMessages);
194
-
195
- // 3b. Resolve the correct checkpoint for snapshot/tree operations
196
- // The target message may be a non-checkpoint (e.g., assistant response)
197
- // when called from edit mode. Walk back to find the nearest ancestor checkpoint.
198
- const checkpointIdSet = new Set(checkpoints.map(c => c.id));
199
- const resolvedCheckpointId = checkpointIdSet.has(messageId)
200
- ? messageId
201
- : findCheckpointForHead(messageId, allMessages, checkpointIdSet);
202
-
203
- debug.log('snapshot', `Resolved checkpoint: ${resolvedCheckpointId} (target was ${messageId})`);
204
-
205
- // 4. Find session end (last message of target's session)
206
- const sessionEnd = findSessionEnd(checkpointMessage, allMessages);
207
- debug.log('snapshot', `Session end: ${sessionEnd.id}`);
208
-
209
- // 5. Update HEAD to session end
210
- sessionQueries.updateHead(sessionId, sessionEnd.id);
211
- sessionQueries.rederiveHeadSnapshot(sessionId);
212
- debug.log('snapshot', `HEAD updated to: ${sessionEnd.id}`);
213
-
214
- // 5b. Update head_session_id so resume works correctly.
215
- // Claude Code: skip cancelled fork session_ids (partial messages from cancelStream).
216
- // OpenCode: simple walk — any session_id is valid (sessions created synchronously).
217
- //
218
- // Engine is read PER MESSAGE, not from `chat_sessions.engine`: a session can
219
- // now switch engine mid-conversation, so the session column only names the
220
- // currently selected engine. Restoring into a region driven by a different
221
- // engine must apply that region's semantics, and must not adopt an SDK
222
- // session id belonging to some other engine's store.
223
- {
224
- let foundSdkSessionId: string | null = null;
225
- const msgLookup = new Map(allMessages.map(m => [m.id, m]));
226
-
227
- const engineOf = (msg: UnifiedMessage): string | null => msg.engine?.type ?? null;
228
-
229
- // The engine that owns the restored branch head — the only engine whose
230
- // session ids are meaningful for a subsequent resume.
231
- let branchEngine: string | null = null;
232
- {
233
- let probeId: string | null = sessionEnd.id;
234
- while (probeId) {
235
- const probeMsg = msgLookup.get(probeId);
236
- if (!probeMsg) break;
237
- try {
238
- const msg = JSON.parse(probeMsg.data) as UnifiedMessage;
239
- if (msg.type !== 'user') {
240
- const type = engineOf(msg);
241
- if (type) { branchEngine = type; break; }
242
- }
243
- } catch { /* skip */ }
244
- probeId = probeMsg.parent_message_id || null;
245
- }
246
- if (!branchEngine) {
247
- branchEngine = sessionQueries.getById(sessionId)?.engine ?? null;
248
- }
249
- }
250
-
251
- const isClaudeCode = branchEngine === 'claude-code';
252
-
253
- // Claude Code only: detect cancelled stream by stopReason on sessionEnd
254
- let cancelledSessionId: string | null = null;
255
- if (isClaudeCode) {
256
- try {
257
- const endMsg = msgLookup.get(sessionEnd.id);
258
- if (endMsg) {
259
- const endParsed = JSON.parse(endMsg.data) as UnifiedMessage;
260
- if (endParsed.type === 'assistant' && endParsed.stopReason === 'interrupted') {
261
- cancelledSessionId = endParsed.sessionId || null;
262
- }
263
- }
264
- } catch { /* skip */ }
265
- }
266
-
267
- let walkId: string | null = sessionEnd.id;
268
- while (walkId) {
269
- const walkMsg = msgLookup.get(walkId);
270
- if (!walkMsg) break;
271
-
272
- try {
273
- const msg = JSON.parse(walkMsg.data) as UnifiedMessage;
274
-
275
- // Claude Code only: skip interrupted messages (from cancelled streams)
276
- if (isClaudeCode && msg.type === 'assistant' && msg.stopReason === 'interrupted') {
277
- walkId = walkMsg.parent_message_id || null;
278
- continue;
279
- }
280
-
281
- // Claude Code only: skip messages from the same cancelled fork
282
- if (isClaudeCode && cancelledSessionId && msg.sessionId === cancelledSessionId) {
283
- walkId = walkMsg.parent_message_id || null;
284
- continue;
285
- }
286
-
287
- // Any engine: message with sessionId, but only from the branch's own
288
- // engine. Crossing that line would store a foreign store's id.
289
- // A message with no engine block is pre-migration: it cannot be
290
- // proven foreign, so keep the old behaviour and accept it.
291
- const msgEngine = engineOf(msg);
292
- if (msg.sessionId && (!branchEngine || !msgEngine || msgEngine === branchEngine)) {
293
- foundSdkSessionId = msg.sessionId;
294
- break;
295
- }
296
- } catch { /* skip */ }
297
-
298
- walkId = walkMsg.parent_message_id || null;
299
- }
300
-
301
- if (foundSdkSessionId) {
302
- sessionQueries.updateSessionId(sessionId, foundSdkSessionId);
303
- debug.log('snapshot', `head_session_id updated to: ${foundSdkSessionId}`);
304
- } else {
305
- sessionQueries.clearSessionId(sessionId);
306
- debug.log('snapshot', 'head_session_id cleared (no valid session found in restored chain)');
307
- }
308
- }
309
-
310
- // 6. Update checkpoint_tree_state for ancestors
311
- // Use resolved checkpoint ID (not raw messageId which may be a non-checkpoint)
312
- // Also compute checkpointPath for branch-aware file restore
313
- let checkpointPath: string[] = [];
314
- if (resolvedCheckpointId) {
315
- checkpointPath = getCheckpointPathToRoot(resolvedCheckpointId, parentMap);
316
- if (checkpointPath.length > 1) {
317
- checkpointQueries.updateActiveChildrenAlongPath(sessionId, checkpointPath);
318
- }
319
- }
320
-
321
- // 7. Restore file system state using session-scoped restore
322
- // Use resolved checkpoint ID so the snapshot lookup matches correctly
323
- // (snapshots are keyed by checkpoint user message IDs, not assistant messages)
324
- let filesRestored = 0;
325
- let filesSkipped = 0;
326
-
327
- const sessionRoot = resolveSessionRoot(sessionId);
328
- if (sessionRoot?.path) {
329
- const result = await snapshotService.restoreSessionScoped(
330
- sessionRoot.path,
331
- sessionId,
332
- resolvedCheckpointId,
333
- conflictResolutions,
334
- checkpointPath.length > 0 ? checkpointPath : undefined
335
- );
336
- filesRestored = result.restoredFiles;
337
- filesSkipped = result.skippedFiles;
338
- }
339
-
340
- // 8. Broadcast messages-changed
341
- try {
342
- ws.emit.chatSession(sessionId, 'chat:messages-changed', {
343
- sessionId,
344
- reason: 'restore',
345
- timestamp: new Date().toISOString()
346
- });
347
- } catch (err) {
348
- debug.error('snapshot', 'Failed to broadcast messages-changed:', err);
349
- }
350
-
351
- return {
352
- restoredTo: {
353
- messageId: sessionEnd.id,
354
- timestamp: sessionEnd.created_at
355
- },
356
- filesRestored,
357
- filesSkipped
358
- };
73
+ requireSessionAccess(sessionId);
74
+ return restoreSessionTo(sessionId, messageId, conflictResolutions);
359
75
  });
@@ -31,9 +31,9 @@ export const timelineHandler = createRouter()
31
31
  nodes: t.Array(t.Any()),
32
32
  currentHeadId: t.Union([t.String(), t.Null()])
33
33
  })
34
- }, async ({ data, conn }) => {
34
+ }, async ({ data }) => {
35
35
  const { sessionId } = data;
36
- requireSessionAccess(conn, sessionId);
36
+ requireSessionAccess(sessionId);
37
37
 
38
38
  debug.log('snapshot', 'TIMELINE - Building tree view');
39
39
 
@@ -114,7 +114,6 @@ export const timelineHandler = createRouter()
114
114
  isCurrent: isAtInitialState,
115
115
  hasSnapshot: false,
116
116
  isInitial: true,
117
- senderName: null,
118
117
  filesChanged: 0,
119
118
  insertions: 0,
120
119
  deletions: 0
@@ -155,7 +154,6 @@ export const timelineHandler = createRouter()
155
154
  isOrphaned,
156
155
  isCurrent,
157
156
  hasSnapshot: !!snapshot,
158
- senderName: msg.type === 'user' ? msg.sender?.name || null : null,
159
157
  filesChanged: stats.filesChanged,
160
158
  insertions: stats.insertions,
161
159
  deletions: stats.deletions
@@ -1,31 +1,16 @@
1
- import type { WSConnection } from '$shared/utils/ws-server';
2
- import { ws } from '$backend/utils/ws';
3
1
  import { sshConnectionQueries } from '../../database/queries';
4
2
  import { sshPortForwardQueries } from '../../database/queries';
5
3
  import type { SshConnection, SshForward } from '$shared/types/ssh';
6
4
 
7
- export interface SshPrincipal {
8
- userId: string;
9
- isAdmin: boolean;
5
+ /** Full connection including secrets, or an error when it does not exist. */
6
+ export function requireSshConnection(connectionId: string): SshConnection {
7
+ return sshConnectionQueries.require(connectionId);
10
8
  }
11
9
 
12
- export function getSshPrincipal(conn: WSConnection): SshPrincipal {
13
- return { userId: ws.getUserId(conn), isAdmin: ws.getRole(conn) === 'admin' };
14
- }
15
-
16
- /** Full connection including secrets, after checking the caller owns it. */
17
- export function requireSshConnection(conn: WSConnection, connectionId: string): SshConnection {
18
- const { userId, isAdmin } = getSshPrincipal(conn);
19
- return sshConnectionQueries.ensureAccess(connectionId, userId, isAdmin);
20
- }
21
-
22
- /**
23
- * A forward is reachable exactly when its connection is, so resolve the forward
24
- * and check the owner of the host it belongs to.
25
- */
26
- export function requireSshForward(conn: WSConnection, forwardId: string): SshForward {
10
+ /** A forward, after checking the host it belongs to still exists. */
11
+ export function requireSshForward(forwardId: string): SshForward {
27
12
  const forward = sshPortForwardQueries.get(forwardId);
28
13
  if (!forward) throw new Error('ssh port forward not found');
29
- requireSshConnection(conn, forward.connectionId);
14
+ requireSshConnection(forward.connectionId);
30
15
  return forward;
31
16
  }