@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
@@ -3,24 +3,17 @@
3
3
  */
4
4
 
5
5
  import { t } from 'elysia';
6
- import path from 'node:path';
7
6
  import { createRouter } from '$shared/utils/ws-server';
8
7
  import { gitService } from '../../git/git-service';
9
8
  import { findRepoForFile } from '../../git/nested-repos';
10
9
  import { requireProjectWorkspace } from '../access';
11
- import { debug } from '$shared/utils/logger';
10
+ import { gitRepoContext, withRepoLock } from './repo-context';
12
11
 
13
- function resolveRepoCwd(projectPath: string, repoPath: string | undefined): string | null {
14
- if (!repoPath) return null;
15
- const resolved = path.resolve(repoPath);
16
- const projectRoot = path.resolve(projectPath);
17
- const sep = path.sep;
18
- if (resolved !== projectRoot && !resolved.startsWith(projectRoot + sep)) {
19
- debug.warn('git', `Rejected nested repoPath outside project: ${resolved}`);
20
- return projectRoot;
21
- }
22
- return resolved;
23
- }
12
+ // Index writes queue behind each other rather than refusing: three files staged
13
+ // in quick succession are three requests the user meant.
14
+ const STAGE = { category: 'staging', label: 'Staging', queue: true } as const;
15
+ const UNSTAGE = { category: 'staging', label: 'Unstaging', queue: true } as const;
16
+ const DISCARD = { category: 'staging', label: 'Discarding changes', queue: true } as const;
24
17
 
25
18
  export const stagingHandler = createRouter()
26
19
  .http('git:stage', {
@@ -32,9 +25,9 @@ export const stagingHandler = createRouter()
32
25
  }, async ({ data, conn }) => {
33
26
  const { root } = requireProjectWorkspace(conn, data.projectId);
34
27
  const repo = await findRepoForFile(root, data.filePath);
35
- const cwd = repo?.repoPath ?? root;
28
+ const ctx = gitRepoContext(conn, data.projectId, undefined, repo?.repoPath ?? root);
36
29
  const filePath = repo?.relativeFilePath ?? data.filePath;
37
- await gitService.stageFile(cwd, filePath);
30
+ await withRepoLock(ctx, STAGE, () => gitService.stageFile(ctx.cwd, filePath));
38
31
  return { ok: true };
39
32
  })
40
33
 
@@ -45,9 +38,8 @@ export const stagingHandler = createRouter()
45
38
  }),
46
39
  response: t.Object({ ok: t.Boolean() })
47
40
  }, async ({ data, conn }) => {
48
- const { root } = requireProjectWorkspace(conn, data.projectId);
49
- const cwd = data.repoPath ? (resolveRepoCwd(root, data.repoPath) ?? root) : root;
50
- await gitService.stageAll(cwd);
41
+ const ctx = gitRepoContext(conn, data.projectId, data.repoPath);
42
+ await withRepoLock(ctx, STAGE, () => gitService.stageAll(ctx.cwd));
51
43
  return { ok: true };
52
44
  })
53
45
 
@@ -60,9 +52,9 @@ export const stagingHandler = createRouter()
60
52
  }, async ({ data, conn }) => {
61
53
  const { root } = requireProjectWorkspace(conn, data.projectId);
62
54
  const repo = await findRepoForFile(root, data.filePath);
63
- const cwd = repo?.repoPath ?? root;
55
+ const ctx = gitRepoContext(conn, data.projectId, undefined, repo?.repoPath ?? root);
64
56
  const filePath = repo?.relativeFilePath ?? data.filePath;
65
- await gitService.unstageFile(cwd, filePath);
57
+ await withRepoLock(ctx, UNSTAGE, () => gitService.unstageFile(ctx.cwd, filePath));
66
58
  return { ok: true };
67
59
  })
68
60
 
@@ -73,9 +65,8 @@ export const stagingHandler = createRouter()
73
65
  }),
74
66
  response: t.Object({ ok: t.Boolean() })
75
67
  }, async ({ data, conn }) => {
76
- const { root } = requireProjectWorkspace(conn, data.projectId);
77
- const cwd = data.repoPath ? (resolveRepoCwd(root, data.repoPath) ?? root) : root;
78
- await gitService.unstageAll(cwd);
68
+ const ctx = gitRepoContext(conn, data.projectId, data.repoPath);
69
+ await withRepoLock(ctx, UNSTAGE, () => gitService.unstageAll(ctx.cwd));
79
70
  return { ok: true };
80
71
  })
81
72
 
@@ -88,9 +79,9 @@ export const stagingHandler = createRouter()
88
79
  }, async ({ data, conn }) => {
89
80
  const { root } = requireProjectWorkspace(conn, data.projectId);
90
81
  const repo = await findRepoForFile(root, data.filePath);
91
- const cwd = repo?.repoPath ?? root;
82
+ const ctx = gitRepoContext(conn, data.projectId, undefined, repo?.repoPath ?? root);
92
83
  const filePath = repo?.relativeFilePath ?? data.filePath;
93
- await gitService.discardFile(cwd, filePath);
84
+ await withRepoLock(ctx, DISCARD, () => gitService.discardFile(ctx.cwd, filePath));
94
85
  return { ok: true };
95
86
  })
96
87
 
@@ -101,8 +92,7 @@ export const stagingHandler = createRouter()
101
92
  }),
102
93
  response: t.Object({ ok: t.Boolean() })
103
94
  }, async ({ data, conn }) => {
104
- const { root } = requireProjectWorkspace(conn, data.projectId);
105
- const cwd = data.repoPath ? (resolveRepoCwd(root, data.repoPath) ?? root) : root;
106
- await gitService.discardAll(cwd);
95
+ const ctx = gitRepoContext(conn, data.projectId, data.repoPath);
96
+ await withRepoLock(ctx, DISCARD, () => gitService.discardAll(ctx.cwd));
107
97
  return { ok: true };
108
98
  });
@@ -6,6 +6,7 @@ import { t } from 'elysia';
6
6
  import { createRouter } from '$shared/utils/ws-server';
7
7
  import { gitService } from '../../git/git-service';
8
8
  import { findNestedRepoPaths } from '../../git/nested-repos';
9
+ import { gitRepoContext, withRepoLock } from './repo-context';
9
10
  import { requireProjectWorkspace } from '../access';
10
11
  import { relative as pathRelative } from 'path';
11
12
 
@@ -126,8 +127,10 @@ export const statusHandler = createRouter()
126
127
  }),
127
128
  response: t.Object({ ok: t.Boolean() })
128
129
  }, async ({ data, conn }) => {
129
- const { root } = requireProjectWorkspace(conn, data.projectId);
130
- await gitService.init(root, data.defaultBranch);
130
+ const ctx = gitRepoContext(conn, data.projectId);
131
+ await withRepoLock(ctx, { category: 'configure', label: 'Initialize repository' }, () =>
132
+ gitService.init(ctx.root, data.defaultBranch)
133
+ );
131
134
  return { ok: true };
132
135
  })
133
136
 
@@ -48,6 +48,7 @@ import { worktreesRouter } from './worktrees';
48
48
  import { notesRouter } from './notes';
49
49
  import { workRouter } from './work';
50
50
  import { deploymentsRouter } from './deployments';
51
+ import { chatAppsRouter } from './chat-apps';
51
52
 
52
53
  // ============================================
53
54
  // Main App Router - Merge All Module Routers
@@ -130,7 +131,10 @@ export const wsRouter = createRouter()
130
131
  .merge(workRouter)
131
132
 
132
133
  // Deployments surface — builds, logs and what is live, for the current project
133
- .merge(deploymentsRouter);
134
+ .merge(deploymentsRouter)
135
+
136
+ // Notification channels — pairing a chat with a connected bot, per user
137
+ .merge(chatAppsRouter);
134
138
 
135
139
  // Export API type for frontend type-safe access
136
140
  export type WSAPI = typeof wsRouter['$api'];
@@ -5,7 +5,7 @@
5
5
  * - instructions:get-project / save-project
6
6
  *
7
7
  * The managed block is injected into each engine's memory file as a
8
- * marker-region; hand-written content is preserved. Mutations are admin-gated.
8
+ * marker-region; hand-written content is preserved.
9
9
  */
10
10
 
11
11
  import { t } from 'elysia';
@@ -9,9 +9,7 @@
9
9
  * integrations:health — probe one account
10
10
  * integrations:secrets-health — state of secrets at rest, for the hub banner
11
11
  *
12
- * Admin-gated in `backend/auth/permissions.ts`, matching the MCP surface it
13
- * absorbs: connecting an account changes what every engine and every project
14
- * can reach.
12
+ * Connecting an account changes what every engine and every project can reach.
15
13
  */
16
14
 
17
15
  import { t } from 'elysia';
@@ -7,8 +7,7 @@
7
7
  * - mcp:toggle — enable / disable
8
8
  * - mcp:uninstall — remove
9
9
  *
10
- * Mutations are admin-gated in `backend/auth/permissions.ts`. Changes take
11
- * effect on the next chat stream (engines read MCP config when a stream starts).
10
+ * Changes take effect on the next chat stream (engines read MCP config when a stream starts).
12
11
  */
13
12
 
14
13
  import { t } from 'elysia';
@@ -52,9 +51,8 @@ const INSTALLED_SERVER_SCHEMA = t.Object({
52
51
  transport: TRANSPORT_SCHEMA,
53
52
  command: t.Union([t.String(), t.Null()]),
54
53
  args: t.Array(t.String()),
55
- // Full values are returned (not redacted): the whole MCP surface is
56
- // admin-only (see auth/permissions.ts), and the Settings UI shows values so
57
- // admins can review and edit what each engine receives.
54
+ // Full values are returned (not redacted): the Settings UI shows values so
55
+ // the owner can review and edit what each engine receives.
58
56
  env: t.Record(t.String(), t.String()),
59
57
  headers: t.Record(t.String(), t.String()),
60
58
  configSchema: t.Array(CONFIG_FIELD_SCHEMA),
@@ -8,7 +8,7 @@
8
8
  *
9
9
  * All three go through the SAME upstream introspection path the bridge uses
10
10
  * (`backend/mcp/external/proxy.ts`), so what Settings shows matches what the
11
- * engines receive. Mutations are admin-gated in `backend/auth/permissions.ts`.
11
+ * engines receive.
12
12
  */
13
13
 
14
14
  import { t } from 'elysia';
@@ -12,16 +12,12 @@
12
12
  * - memory:status / memory:retry-failed
13
13
  * - memory:config / memory:save-config
14
14
  *
15
- * Reads are open to any authenticated user, because the graph is what explains
16
- * the project to whoever is working on it. Mutations are admin-gated in
17
- * `backend/auth/permissions.ts`, matching skills / mcp_servers / subagents:
18
- * memory is instance-global, so one member editing it changes what every agent
19
- * is told on every future turn.
15
+ * Memory is instance-global, so an edit changes what every agent is told on
16
+ * every future turn.
20
17
  */
21
18
 
22
19
  import { t } from 'elysia';
23
- import { createRouter, type WSConnection } from '$shared/utils/ws-server';
24
- import { ws } from '$backend/utils/ws';
20
+ import { createRouter } from '$shared/utils/ws-server';
25
21
  import { projectContextService } from '$backend/mcp/internal/project-context';
26
22
  import { debug } from '$shared/utils/logger';
27
23
  import { graphQueries, graphLayoutQueries } from '$backend/database/queries/graph-queries';
@@ -133,39 +129,12 @@ const READINESS = t.Object({
133
129
  })
134
130
  });
135
131
 
136
- /**
137
- * How the modal's project multi-select reaches a query.
138
- *
139
- * `projectIds` is tri-state on the wire and each state means something
140
- * different: ABSENT is "every project" (the cross-project view), an EMPTY array
141
- * is "global only" — nothing selected is a narrowing, not the absence of one —
142
- * and a non-empty array is those projects plus the globals that apply inside
143
- * every one of them.
144
- *
145
- * Cross-project is admin-only. Reads are otherwise open, because the graph is
146
- * what explains a project to whoever is working on it and withholding that would
147
- * defeat the feature. But "every project at once" is a different request: memory
148
- * is instance-global, so it would show a member everything every other team has
149
- * ever worked on, including repositories they have no access to. Narrowing to
150
- * the caller's current project is the honest degradation — they still see
151
- * everything that applies where they are, plus the globals.
152
- *
153
- * Mutations are gated separately, in `backend/auth/permissions.ts`.
154
- */
155
- function scopeForRole(conn: WSConnection, requested: string[] | undefined): string[] | undefined {
156
- if (requested !== undefined) return requested;
157
- if (ws.getRole(conn) === 'admin') return undefined;
158
-
159
- const current = projectContextService.getCurrentProjectId();
160
- debug.log('path', 'memory: cross-project read narrowed to current project (not admin)');
161
- // No project selected and not an admin: global-scope memories only, which an
162
- // empty selection already means.
163
- return current ? [current] : [];
164
- }
165
-
166
132
  export const memoryCrudHandler = createRouter()
167
133
  .http('memory:graph', {
168
134
  data: t.Object({
135
+ // Tri-state, and each state means something different: ABSENT is every
136
+ // project, an EMPTY array is global only, and a non-empty array is those
137
+ // projects plus the globals that apply inside every one of them.
169
138
  projectIds: t.Optional(t.Array(t.String())),
170
139
  subkinds: t.Optional(t.Array(t.String())),
171
140
  scopes: t.Optional(t.Array(SCOPE)),
@@ -238,10 +207,10 @@ export const memoryCrudHandler = createRouter()
238
207
  totalNodes: t.Number(),
239
208
  truncated: t.Boolean()
240
209
  })
241
- }, async ({ conn, data }) => {
210
+ }, async ({ data }) => {
242
211
  debug.log('path', 'memory:graph');
243
212
  return buildGraphView({
244
- projectIds: scopeForRole(conn, data.projectIds),
213
+ projectIds: data.projectIds,
245
214
  subkinds: data.subkinds,
246
215
  scopes: data.scopes as GraphScope[] | undefined,
247
216
  sources: data.sources as GraphSource[] | undefined,
@@ -290,11 +259,11 @@ export const memoryCrudHandler = createRouter()
290
259
  vectorWeight: t.Number()
291
260
  })
292
261
  })
293
- }, async ({ conn, data }) => {
262
+ }, async ({ data }) => {
294
263
  debug.log('path', 'memory:search');
295
264
  const result = retrieve({
296
265
  query: data.query,
297
- projectIds: scopeForRole(conn, data.projectIds),
266
+ projectIds: data.projectIds,
298
267
  subkinds: data.subkinds,
299
268
  sources: data.sources as GraphSource[] | undefined,
300
269
  limit: data.limit ?? 20,
@@ -493,9 +462,8 @@ export const memoryCrudHandler = createRouter()
493
462
  /**
494
463
  * What the extraction queue is doing.
495
464
  *
496
- * Open to any member, because it answers "is memory working right now", and a
497
- * user watching the graph fail to grow deserves an answer whether or not they
498
- * can change the setting that fixes it.
465
+ * It answers "is memory working right now" for someone watching the graph
466
+ * fail to grow.
499
467
  */
500
468
  .http('memory:status', {
501
469
  data: t.Object({}),
@@ -576,9 +544,9 @@ export const memoryCrudHandler = createRouter()
576
544
  nodes: t.Array(NODE),
577
545
  total: t.Number()
578
546
  })
579
- }, async ({ conn, data }) => {
547
+ }, async ({ data }) => {
580
548
  debug.log('path', 'memory:forgotten');
581
- const projectIds = scopeForRole(conn, data.projectIds);
549
+ const projectIds = data.projectIds;
582
550
  return {
583
551
  nodes: graphQueries.listArchived({
584
552
  projectIds,
@@ -9,8 +9,8 @@ import { memoryCrudHandler } from './crud';
9
9
  export const memoryRouter = createRouter()
10
10
  /**
11
11
  * The graph changed. Broadcast globally rather than per session, because the
12
- * memory graph is instance-wide: a memory written by one member's chat is
13
- * immediately part of what every other member's Memory view is showing.
12
+ * memory graph is instance-wide: a memory written by one chat is immediately
13
+ * part of what every device's Memory view is showing.
14
14
  *
15
15
  * The payload deliberately carries no data, only a reason. Diffing the graph
16
16
  * over the wire would mean a second serialization format to keep in step with
@@ -4,6 +4,7 @@
4
4
  * HTTP endpoints for message management:
5
5
  * - List messages (with optional include_all for history view)
6
6
  * - Get message by ID
7
+ * - Resolve which of a session's message ids are saved
7
8
  * - Delete message
8
9
  */
9
10
 
@@ -21,8 +22,8 @@ export const crudHandler = createRouter()
21
22
  include_all: t.Optional(t.Boolean())
22
23
  }),
23
24
  response: t.Array(t.Any())
24
- }, async ({ data, conn }) => {
25
- requireSessionAccess(conn, data.session_id);
25
+ }, async ({ data }) => {
26
+ requireSessionAccess(data.session_id);
26
27
  if (data.include_all) {
27
28
  // Return all messages including those in other branches (for History view)
28
29
  const allMessages = messageQueries.getAllBySessionId(data.session_id);
@@ -39,11 +40,31 @@ export const crudHandler = createRouter()
39
40
  messageId: t.String({ minLength: 1 })
40
41
  }),
41
42
  response: t.Any()
42
- }, async ({ data, conn }) => {
43
- const message = requireMessageAccess(conn, data.messageId);
43
+ }, async ({ data }) => {
44
+ const message = requireMessageAccess(data.messageId);
44
45
  return loadMessage(message);
45
46
  })
46
47
 
48
+ // Which of these ids are saved messages of the session, and what they hold.
49
+ // A sender checks the bubbles it is still showing optimistically: a send
50
+ // whose echo never arrived (socket dropped, stopped early) may still have
51
+ // been saved, or may never have reached the server at all.
52
+ .http('messages:resolve', {
53
+ data: t.Object({
54
+ session_id: t.String({ minLength: 1 }),
55
+ ids: t.Array(t.String({ minLength: 1 }), { maxItems: 100 })
56
+ }),
57
+ response: t.Array(t.Any())
58
+ }, async ({ data }) => {
59
+ requireSessionAccess(data.session_id);
60
+ const found: ReturnType<typeof loadMessage>[] = [];
61
+ for (const id of new Set(data.ids)) {
62
+ const row = messageQueries.getById(id);
63
+ if (row && row.session_id === data.session_id) found.push(loadMessage(row));
64
+ }
65
+ return found;
66
+ })
67
+
47
68
  // Get full (untrimmed) sub-agent messages nested under a message.
48
69
  // Used by the Debug modal to show complete data despite the wire trimming
49
70
  // sub-agent noise from the normal chat payload.
@@ -52,8 +73,8 @@ export const crudHandler = createRouter()
52
73
  messageId: t.String({ minLength: 1 })
53
74
  }),
54
75
  response: t.Array(t.Any())
55
- }, async ({ data, conn }) => {
56
- requireMessageAccess(conn, data.messageId);
76
+ }, async ({ data }) => {
77
+ requireMessageAccess(data.messageId);
57
78
  return messageQueries.getSubAgentMessages(data.messageId);
58
79
  })
59
80
 
@@ -65,9 +86,9 @@ export const crudHandler = createRouter()
65
86
  response: t.Object({
66
87
  message: t.String()
67
88
  })
68
- }, async ({ data, conn }) => {
89
+ }, async ({ data }) => {
69
90
  // Check if message exists first
70
- requireMessageAccess(conn, data.messageId);
91
+ requireMessageAccess(data.messageId);
71
92
 
72
93
  // Delete the message
73
94
  messageQueries.delete(data.messageId);
@@ -2,20 +2,20 @@
2
2
  * Notes Router
3
3
  *
4
4
  * Notes live in collections, and a collection carries the scope: `project`
5
- * (members of that project) or `global` (every signed-in user). Permissions are
5
+ * (inside one project) or `global` (shown in every project). Access is
6
6
  * resolved through the collection on every route — a note id is never treated
7
7
  * as a capability on its own.
8
8
  *
9
- * Writes broadcast `notes:changed` to whoever can see the collection, the same
10
- * way worktrees do: a note another member just created is invisible until the
11
- * next reload without it. The event carries ids only — a note holds up to
9
+ * Writes broadcast `notes:changed` to every device showing the collection, the
10
+ * same way worktrees do: a note just created on another device is invisible
11
+ * until the next reload without it. The event carries ids only — a note holds up to
12
12
  * 200 KB, so fanning the list out on every autosave would put megabytes on the
13
13
  * socket per keystroke of a long note.
14
14
  */
15
15
 
16
16
  import { t } from 'elysia';
17
17
  import { createRouter } from '$shared/utils/ws-server';
18
- import type { WSConnection } from '$shared/utils/ws-server';
18
+
19
19
  import type { NoteCollection } from '$shared/types/database/schema';
20
20
  import { ws as wsServer } from '../../utils/ws';
21
21
  import { requireProjectAccess } from '../access';
@@ -61,45 +61,39 @@ const noteSchema = t.Object({
61
61
  )
62
62
  });
63
63
 
64
- /** Resolve a collection and refuse the call unless this connection may see it. */
65
- function requireCollection(conn: WSConnection, collectionId: string): NoteCollection {
64
+ /** Resolve a collection and refuse the call unless it can be reached. */
65
+ function requireCollection(collectionId: string): NoteCollection {
66
66
  const collection = noteCollectionQueries.getById(collectionId);
67
- // Same answer for "does not exist" and "not yours", so the id space cannot be
68
- // probed for which collections are real.
69
67
  if (!collection) throw new Error('Access denied');
70
- if (!canAccessCollection(wsServer.getUserId(conn), collection)) {
68
+ if (!canAccessCollection(collection)) {
71
69
  throw new Error('Access denied');
72
70
  }
73
71
  return collection;
74
72
  }
75
73
 
76
74
  /** Resolve the collection a note belongs to, subject to the same check. */
77
- function requireNoteCollection(conn: WSConnection, noteId: string): NoteCollection {
75
+ function requireNoteCollection(noteId: string): NoteCollection {
78
76
  const collection = noteCollectionQueries.getForNote(noteId);
79
77
  if (!collection) throw new Error('Access denied');
80
- if (!canAccessCollection(wsServer.getUserId(conn), collection)) {
78
+ if (!canAccessCollection(collection)) {
81
79
  throw new Error('Access denied');
82
80
  }
83
81
  return collection;
84
82
  }
85
83
 
86
- /** Check the caller may write into `scope` before anything is created there. */
87
- function requireScope(conn: WSConnection, scope: 'project' | 'global', projectId: string | null): void {
84
+ /** Check `scope` can be written into before anything is created there. */
85
+ function requireScope(scope: 'project' | 'global', projectId: string | null): void {
88
86
  if (scope === 'project') {
89
87
  if (!projectId) throw new Error('projectId is required for the project scope');
90
- requireProjectAccess(conn, projectId);
91
- return;
88
+ requireProjectAccess(projectId);
92
89
  }
93
- // Global is instance-wide; the only requirement is a signed-in connection,
94
- // which getUserId asserts.
95
- wsServer.getUserId(conn);
96
90
  }
97
91
 
98
92
  /**
99
- * Tell everyone who can see this collection that its contents moved.
93
+ * Tell every device showing this collection that its contents moved.
100
94
  *
101
95
  * A project collection reaches the project room; a global one reaches every
102
- * connection, because that is exactly the set of people allowed to read it.
96
+ * connection.
103
97
  */
104
98
  function broadcast(collection: NoteCollection): void {
105
99
  const payload = {
@@ -126,9 +120,9 @@ export const notesRouter = createRouter()
126
120
  collections: t.Array(collectionSchema),
127
121
  notes: t.Array(noteSchema)
128
122
  })
129
- }, async ({ data, conn }) => {
123
+ }, async ({ data }) => {
130
124
  const projectId = data.projectId ?? null;
131
- requireScope(conn, data.scope, projectId);
125
+ requireScope(data.scope, projectId);
132
126
  const collections = noteCollectionQueries.listByScope(data.scope, projectId);
133
127
  return {
134
128
  collections,
@@ -145,7 +139,7 @@ export const notesRouter = createRouter()
145
139
  response: t.Object({ collection: collectionSchema })
146
140
  }, async ({ data, conn }) => {
147
141
  const projectId = data.scope === 'project' ? (data.projectId ?? null) : null;
148
- requireScope(conn, data.scope, projectId);
142
+ requireScope(data.scope, projectId);
149
143
  const collection = noteCollectionQueries.create({
150
144
  name: data.name,
151
145
  scope: data.scope,
@@ -159,8 +153,8 @@ export const notesRouter = createRouter()
159
153
  .http('notes:rename-collection', {
160
154
  data: t.Object({ id: t.String({ minLength: 1 }), name: t.String({ minLength: 1 }) }),
161
155
  response: t.Object({ collection: t.Union([collectionSchema, t.Null()]) })
162
- }, async ({ data, conn }) => {
163
- const collection = requireCollection(conn, data.id);
156
+ }, async ({ data }) => {
157
+ const collection = requireCollection(data.id);
164
158
  const renamed = noteCollectionQueries.rename(collection.id, data.name);
165
159
  if (renamed) broadcast(renamed);
166
160
  return { collection: renamed };
@@ -169,8 +163,8 @@ export const notesRouter = createRouter()
169
163
  .http('notes:delete-collection', {
170
164
  data: t.Object({ id: t.String({ minLength: 1 }) }),
171
165
  response: t.Object({ ok: t.Boolean() })
172
- }, async ({ data, conn }) => {
173
- const collection = requireCollection(conn, data.id);
166
+ }, async ({ data }) => {
167
+ const collection = requireCollection(data.id);
174
168
  // Notes and image rows cascade with the collection; the files they point
175
169
  // at do not, so the whole collection directory goes with them.
176
170
  noteCollectionQueries.delete(collection.id);
@@ -184,8 +178,8 @@ export const notesRouter = createRouter()
184
178
  .http('notes:get', {
185
179
  data: t.Object({ id: t.String({ minLength: 1 }) }),
186
180
  response: t.Object({ note: t.Union([noteSchema, t.Null()]) })
187
- }, async ({ data, conn }) => {
188
- requireNoteCollection(conn, data.id);
181
+ }, async ({ data }) => {
182
+ requireNoteCollection(data.id);
189
183
  return { note: noteQueries.getById(data.id) };
190
184
  })
191
185
 
@@ -204,11 +198,11 @@ export const notesRouter = createRouter()
204
198
  const userId = wsServer.getUserId(conn);
205
199
  let collection: NoteCollection;
206
200
  if (data.collectionId) {
207
- collection = requireCollection(conn, data.collectionId);
201
+ collection = requireCollection(data.collectionId);
208
202
  } else {
209
203
  const scope = data.scope ?? 'project';
210
204
  const projectId = scope === 'project' ? (data.projectId ?? null) : null;
211
- requireScope(conn, scope, projectId);
205
+ requireScope(scope, projectId);
212
206
  collection = noteCollectionQueries.ensureDefault(scope, projectId, userId);
213
207
  }
214
208
  const note = noteQueries.create({
@@ -229,11 +223,11 @@ export const notesRouter = createRouter()
229
223
  collectionId: t.Optional(t.String())
230
224
  }),
231
225
  response: t.Object({ note: t.Union([noteSchema, t.Null()]) })
232
- }, async ({ data, conn }) => {
233
- const from = requireNoteCollection(conn, data.id);
226
+ }, async ({ data }) => {
227
+ const from = requireNoteCollection(data.id);
234
228
  // Moving a note is only allowed between collections the caller can already
235
229
  // see, otherwise a move would be a way to read or plant one they cannot.
236
- const to = data.collectionId ? requireCollection(conn, data.collectionId) : from;
230
+ const to = data.collectionId ? requireCollection(data.collectionId) : from;
237
231
  const updated = noteQueries.update(data.id, {
238
232
  title: data.title,
239
233
  content: data.content,
@@ -248,8 +242,8 @@ export const notesRouter = createRouter()
248
242
  .http('notes:delete', {
249
243
  data: t.Object({ id: t.String({ minLength: 1 }) }),
250
244
  response: t.Object({ ok: t.Boolean() })
251
- }, async ({ data, conn }) => {
252
- const collection = requireNoteCollection(conn, data.id);
245
+ }, async ({ data }) => {
246
+ const collection = requireNoteCollection(data.id);
253
247
  noteQueries.delete(data.id);
254
248
  await removeNoteFiles(collection.id, data.id);
255
249
  broadcast(collection);
@@ -259,10 +253,10 @@ export const notesRouter = createRouter()
259
253
  .http('notes:delete-image', {
260
254
  data: t.Object({ imageId: t.String({ minLength: 1 }) }),
261
255
  response: t.Object({ ok: t.Boolean() })
262
- }, async ({ data, conn }) => {
256
+ }, async ({ data }) => {
263
257
  const img = noteImageQueries.getById(data.imageId);
264
258
  if (!img) return { ok: true };
265
- const collection = requireNoteCollection(conn, img.note_id);
259
+ const collection = requireNoteCollection(img.note_id);
266
260
  const absolute = resolveNoteImagePath(img.storage_path);
267
261
  if (absolute) await unlink(absolute).catch(() => {});
268
262
  noteImageQueries.delete(data.imageId);
@@ -6,9 +6,8 @@
6
6
  * - permissions:save — upsert one (scope, project, engine) rule set
7
7
  *
8
8
  * Rules are enforced at each engine's runtime auto-approve hook (real on
9
- * Claude/Qwen/Copilot; best-effort/unverified on OpenCode/Codex). Mutations are
10
- * admin-gated in `backend/auth/permissions.ts`. Changes take effect on the next
11
- * chat stream.
9
+ * Claude/Qwen/Copilot; best-effort/unverified on OpenCode/Codex). Changes take
10
+ * effect on the next chat stream.
12
11
  */
13
12
 
14
13
  import { t } from 'elysia';
@@ -65,7 +64,7 @@ export const permissionsCrudHandler = createRouter()
65
64
  debug.log('path', `permissions:save ${data.engine}/${data.scope}`);
66
65
  const projectId = data.scope === 'project' ? (data.projectId ?? null) : null;
67
66
  if (data.scope === 'project' && !projectId) throw new Error('A project is required for project-scoped permissions');
68
- // This admin endpoint only manages global/project scope. Profile-scoped
67
+ // This endpoint only manages global/project scope. Profile-scoped
69
68
  // permission overlays are edited through the profiles editor (profiles:save-permissions).
70
69
  permissionService.save(data.scope as PermissionScope, projectId, null, data.engine as EngineType, data.allow, data.deny);
71
70
  return { success: true };
@@ -1,8 +1,7 @@
1
1
  /**
2
2
  * Port manager WebSocket router.
3
3
  *
4
- * Reading the table is open to any signed-in user; `ports:kill` is registered
5
- * in ADMIN_ONLY_ROUTES and gated there.
4
+ * Reading the table, and stopping a process with `ports:kill`.
6
5
  */
7
6
 
8
7
  import { t } from 'elysia';
@@ -1,8 +1,8 @@
1
1
  /**
2
- * Port manager — stopping a process, admin only.
2
+ * Port manager — stopping a process.
3
3
  *
4
- * The route is listed in ADMIN_ONLY_ROUTES; this handler re-scans before
5
- * acting rather than trusting the pid the client sent. A table is up to a
4
+ * This handler re-scans before acting rather than trusting the pid the client
5
+ * sent. A table is up to a
6
6
  * second old, and a second is long enough for a pid to be recycled onto an
7
7
  * unrelated process — signalling that would be indefensible.
8
8
  */
@@ -13,7 +13,6 @@ import { LOCAL_PORT_HOST } from '$shared/types/ports';
13
13
  import { portMonitor } from '../../ports/monitor';
14
14
  import { stopPortHolder } from '../../ports/kill';
15
15
  import { sshConnectionQueries } from '../../database/queries';
16
- import { ws } from '../../utils/ws';
17
16
  import { debug } from '$shared/utils/logger';
18
17
 
19
18
  export const portsKillHandler = createRouter().http(
@@ -26,13 +25,9 @@ export const portsKillHandler = createRouter().http(
26
25
  }),
27
26
  response: t.Any()
28
27
  },
29
- async ({ data, conn }) => {
30
- const userId = ws.getUserId(conn);
28
+ async ({ data }) => {
31
29
  if (data.hostId !== LOCAL_PORT_HOST) {
32
- // The route is admin-only, but the host check still runs on the real
33
- // role rather than a hardcoded one — a gate that trusts its caller is
34
- // no gate at all.
35
- sshConnectionQueries.ensureAccess(data.hostId, userId, ws.getRole(conn) === 'admin');
30
+ sshConnectionQueries.require(data.hostId);
36
31
  }
37
32
 
38
33
  const fresh = await portMonitor.scanOnce(data.hostId);