@myrialabs/clopen 0.3.8 → 0.3.10

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 (146) hide show
  1. package/README.md +22 -19
  2. package/backend/auth/auth-service.ts +56 -1
  3. package/backend/auth/permissions.ts +66 -2
  4. package/backend/auth/session-cleanup.ts +58 -0
  5. package/backend/chat/stream-manager.ts +143 -13
  6. package/backend/database/migrations/032_seed_copilot_provider.ts +19 -0
  7. package/backend/database/migrations/033_seed_codex_provider.ts +19 -0
  8. package/backend/database/migrations/034_seed_qwen_provider.ts +119 -0
  9. package/backend/database/migrations/035_add_owner_to_db_client_connections.ts +34 -0
  10. package/backend/database/migrations/index.ts +29 -1
  11. package/backend/database/queries/db-client-connection-queries.ts +160 -54
  12. package/backend/database/queries/engine-queries.ts +12 -0
  13. package/backend/database/queries/project-queries.ts +10 -5
  14. package/backend/db-client/connection-manager.ts +9 -3
  15. package/backend/engine/README.md +1702 -0
  16. package/backend/engine/adapters/claude/models.ts +141 -0
  17. package/backend/engine/adapters/claude/stream.ts +1 -1
  18. package/backend/engine/adapters/codex/credential.ts +179 -0
  19. package/backend/engine/adapters/codex/error-handler.ts +65 -0
  20. package/backend/engine/adapters/codex/index.ts +1 -0
  21. package/backend/engine/adapters/codex/message-converter.ts +646 -0
  22. package/backend/engine/adapters/codex/models.ts +105 -0
  23. package/backend/engine/adapters/codex/patch-rollout.ts +169 -0
  24. package/backend/engine/adapters/codex/session-fork.ts +149 -0
  25. package/backend/engine/adapters/codex/stream.ts +310 -0
  26. package/backend/engine/adapters/codex/usage-rollout.ts +145 -0
  27. package/backend/engine/adapters/copilot/error-handler.ts +94 -0
  28. package/backend/engine/adapters/copilot/index.ts +1 -0
  29. package/backend/engine/adapters/copilot/message-converter.ts +973 -0
  30. package/backend/engine/adapters/copilot/models.ts +92 -0
  31. package/backend/engine/adapters/copilot/session-fork.ts +111 -0
  32. package/backend/engine/adapters/copilot/stream.ts +570 -0
  33. package/backend/engine/adapters/opencode/config.ts +56 -104
  34. package/backend/engine/adapters/opencode/error-handler.ts +71 -0
  35. package/backend/engine/adapters/opencode/models.ts +79 -0
  36. package/backend/engine/adapters/opencode/presets.ts +91 -0
  37. package/backend/engine/adapters/opencode/stream.ts +8 -114
  38. package/backend/engine/adapters/qwen/credential.ts +78 -0
  39. package/backend/engine/adapters/qwen/environment.ts +84 -0
  40. package/backend/engine/adapters/qwen/error-handler.ts +71 -0
  41. package/backend/engine/adapters/qwen/index.ts +1 -0
  42. package/backend/engine/adapters/qwen/message-converter.ts +1055 -0
  43. package/backend/engine/adapters/qwen/models.ts +81 -0
  44. package/backend/engine/adapters/qwen/presets.ts +51 -0
  45. package/backend/engine/adapters/qwen/session-fork.ts +97 -0
  46. package/backend/engine/adapters/qwen/stream.ts +379 -0
  47. package/backend/engine/index.ts +35 -0
  48. package/backend/engine/install-recipes.ts +80 -1
  49. package/backend/engine/install-runner.ts +4 -0
  50. package/backend/files/path-browsing.ts +20 -0
  51. package/backend/git/git-service.ts +81 -11
  52. package/backend/git/git-spawn-validation.test.ts +75 -0
  53. package/backend/git/git-spawn-validation.ts +77 -0
  54. package/backend/index.ts +5 -0
  55. package/backend/mcp/README.md +84 -14
  56. package/backend/mcp/config.ts +218 -17
  57. package/backend/mcp/index.ts +2 -0
  58. package/backend/mcp/project-context.ts +55 -0
  59. package/backend/mcp/servers/browser-automation/actions.ts +6 -1
  60. package/backend/mcp/servers/helper.ts +13 -0
  61. package/backend/middleware/error-handler.ts +16 -2
  62. package/backend/preview/browser/browser-preview-service.ts +4 -4
  63. package/backend/preview/browser/browser-tab-manager.ts +23 -3
  64. package/backend/snapshot/gitignore.ts +4 -9
  65. package/backend/tunnel/cloudflared/binary.ts +2 -2
  66. package/backend/tunnel/global-tunnel-manager.ts +9 -3
  67. package/backend/utils/ws.ts +5 -1
  68. package/backend/ws/README.md +128 -3
  69. package/backend/ws/access.ts +56 -0
  70. package/backend/ws/auth/index.ts +14 -0
  71. package/backend/ws/auth/login.ts +3 -0
  72. package/backend/ws/auth/users.ts +61 -1
  73. package/backend/ws/chat/stream.ts +139 -22
  74. package/backend/ws/db-client/access.ts +19 -0
  75. package/backend/ws/db-client/connections.ts +31 -17
  76. package/backend/ws/db-client/io.ts +7 -9
  77. package/backend/ws/db-client/query.ts +86 -32
  78. package/backend/ws/db-client/schema.ts +9 -4
  79. package/backend/ws/db-client/structure.ts +22 -10
  80. package/backend/ws/engine/access.ts +39 -0
  81. package/backend/ws/engine/claude/accounts.ts +15 -10
  82. package/backend/ws/engine/codex/accounts.ts +516 -0
  83. package/backend/ws/engine/codex/index.ts +14 -0
  84. package/backend/ws/engine/codex/status.ts +87 -0
  85. package/backend/ws/engine/copilot/accounts.ts +122 -0
  86. package/backend/ws/engine/copilot/index.ts +13 -0
  87. package/backend/ws/engine/copilot/status.ts +54 -0
  88. package/backend/ws/engine/index.ts +7 -1
  89. package/backend/ws/engine/opencode/providers.ts +1 -1
  90. package/backend/ws/engine/qwen/accounts.ts +137 -0
  91. package/backend/ws/engine/qwen/index.ts +15 -0
  92. package/backend/ws/engine/qwen/presets.ts +40 -0
  93. package/backend/ws/engine/qwen/status.ts +54 -0
  94. package/backend/ws/files/path-access.ts +101 -0
  95. package/backend/ws/files/read.ts +26 -11
  96. package/backend/ws/files/search.ts +10 -6
  97. package/backend/ws/files/state.ts +3 -0
  98. package/backend/ws/files/watch.ts +7 -1
  99. package/backend/ws/files/write.ts +109 -15
  100. package/backend/ws/git/branch.ts +13 -19
  101. package/backend/ws/git/commit-message.ts +3 -4
  102. package/backend/ws/git/commit.ts +5 -7
  103. package/backend/ws/git/conflict.ts +7 -10
  104. package/backend/ws/git/diff.ts +7 -10
  105. package/backend/ws/git/log.ts +3 -4
  106. package/backend/ws/git/remote.ts +30 -43
  107. package/backend/ws/git/staging.ts +13 -19
  108. package/backend/ws/git/status.ts +7 -11
  109. package/backend/ws/messages/crud.ts +7 -13
  110. package/backend/ws/preview/access.ts +45 -0
  111. package/backend/ws/preview/browser/cleanup.ts +3 -11
  112. package/backend/ws/preview/browser/console.ts +7 -42
  113. package/backend/ws/preview/browser/interact.ts +2 -6
  114. package/backend/ws/preview/browser/native-ui.ts +5 -18
  115. package/backend/ws/preview/browser/stats.ts +2 -12
  116. package/backend/ws/preview/browser/tab-info.ts +4 -20
  117. package/backend/ws/preview/browser/tab.ts +4 -27
  118. package/backend/ws/preview/browser/webcodecs.ts +6 -47
  119. package/backend/ws/projects/crud.ts +15 -16
  120. package/backend/ws/projects/status.ts +5 -1
  121. package/backend/ws/sessions/crud.ts +31 -36
  122. package/backend/ws/settings/crud.ts +13 -13
  123. package/backend/ws/snapshot/restore.ts +5 -2
  124. package/backend/ws/snapshot/timeline.ts +3 -1
  125. package/backend/ws/system-tools/access.ts +28 -0
  126. package/backend/ws/system-tools/install.ts +13 -4
  127. package/backend/ws/system-tools/status.ts +5 -2
  128. package/backend/ws/terminal/access.ts +56 -0
  129. package/backend/ws/terminal/persistence.ts +13 -7
  130. package/backend/ws/terminal/session.ts +35 -14
  131. package/backend/ws/terminal/stream.ts +4 -1
  132. package/dist/assets/{index-DqAGCTFT.js → index-C1afGwHY.js} +2 -2
  133. package/dist/assets/main-CZb3Y_Z_.js +315 -0
  134. package/dist/assets/main-Cn8cX2DY.css +1 -0
  135. package/dist/index.html +2 -2
  136. package/package.json +5 -1
  137. package/shared/constants/engines.ts +45 -140
  138. package/shared/types/database/schema.ts +1 -0
  139. package/shared/types/unified/common.ts +1 -1
  140. package/shared/types/unified/engine.ts +29 -1
  141. package/shared/types/unified/index.ts +2 -0
  142. package/shared/types/unified/message.ts +1 -1
  143. package/shared/types/unified/tool.ts +17 -2
  144. package/shared/utils/ws-server.ts +14 -0
  145. package/dist/assets/main-DsED0rLr.js +0 -304
  146. package/dist/assets/main-eWY9R8g9.css +0 -1
@@ -3,6 +3,7 @@ import { createRouter } from '$shared/utils/ws-server';
3
3
  import { debug } from '$shared/utils/logger';
4
4
  import { join, extname, basename, relative } from 'path';
5
5
  import { readdir } from 'fs/promises';
6
+ import { requireProjectPathAccess } from './path-access';
6
7
 
7
8
  // Directories to skip during search
8
9
  const SKIP_DIRS = new Set([
@@ -347,14 +348,15 @@ export const fileSearchHandler = createRouter()
347
348
  query: t.String()
348
349
  }),
349
350
  response: t.Array(FileSearchResultSchema)
350
- }, async ({ data }) => {
351
+ }, async ({ data, conn }) => {
351
352
  const { project_path, query } = data;
353
+ const project = requireProjectPathAccess(conn, project_path);
352
354
 
353
355
  if (!query || query.trim().length === 0) {
354
356
  return [];
355
357
  }
356
358
 
357
- return await searchFilesByName(project_path, query);
359
+ return await searchFilesByName(project.path, query);
358
360
  })
359
361
  .http('files:search-code', {
360
362
  data: t.Object({
@@ -376,7 +378,7 @@ export const fileSearchHandler = createRouter()
376
378
  })),
377
379
  totalMatches: t.Number()
378
380
  }))
379
- }, async ({ data }) => {
381
+ }, async ({ data, conn }) => {
380
382
  const {
381
383
  project_path,
382
384
  query,
@@ -386,12 +388,13 @@ export const fileSearchHandler = createRouter()
386
388
  include_pattern,
387
389
  exclude_pattern
388
390
  } = data;
391
+ const project = requireProjectPathAccess(conn, project_path);
389
392
 
390
393
  if (!query || query.trim().length === 0) {
391
394
  return [];
392
395
  }
393
396
 
394
- return await searchCodeContent(project_path, query, {
397
+ return await searchCodeContent(project.path, query, {
395
398
  caseSensitive: case_sensitive,
396
399
  wholeWord: whole_word,
397
400
  useRegex: use_regex,
@@ -419,7 +422,7 @@ export const fileSearchHandler = createRouter()
419
422
  totalReplacements: t.Number(),
420
423
  totalFiles: t.Number()
421
424
  })
422
- }, async ({ data }) => {
425
+ }, async ({ data, conn }) => {
423
426
  const {
424
427
  project_path,
425
428
  search_query,
@@ -430,12 +433,13 @@ export const fileSearchHandler = createRouter()
430
433
  include_pattern,
431
434
  exclude_pattern
432
435
  } = data;
436
+ const project = requireProjectPathAccess(conn, project_path);
433
437
 
434
438
  if (!search_query || search_query.trim().length === 0) {
435
439
  return { results: [], totalReplacements: 0, totalFiles: 0 };
436
440
  }
437
441
 
438
- const results = await replaceInFiles(project_path, search_query, replace_with, {
442
+ const results = await replaceInFiles(project.path, search_query, replace_with, {
439
443
  caseSensitive: case_sensitive,
440
444
  wholeWord: whole_word,
441
445
  useRegex: use_regex,
@@ -11,6 +11,7 @@ import { t } from 'elysia';
11
11
  import { createRouter } from '$shared/utils/ws-server';
12
12
  import { projectQueries } from '../../database/queries/project-queries';
13
13
  import { ws as wsServer } from '../../utils/ws';
14
+ import { requireProjectAccess } from '../access';
14
15
 
15
16
  export const filesStateHandler = createRouter()
16
17
  .http('files:get-panel-state', {
@@ -21,6 +22,7 @@ export const filesStateHandler = createRouter()
21
22
  state: t.Union([t.String(), t.Null()])
22
23
  })
23
24
  }, async ({ data, conn }) => {
25
+ requireProjectAccess(conn, data.projectId);
24
26
  const userId = wsServer.getUserId(conn);
25
27
  const state = projectQueries.getFilesPanelState(userId, data.projectId);
26
28
  return { state };
@@ -33,6 +35,7 @@ export const filesStateHandler = createRouter()
33
35
  }),
34
36
  response: t.Object({ ok: t.Boolean() })
35
37
  }, async ({ data, conn }) => {
38
+ requireProjectAccess(conn, data.projectId);
36
39
  const userId = wsServer.getUserId(conn);
37
40
  projectQueries.setFilesPanelState(userId, data.projectId, data.state);
38
41
  return { ok: true };
@@ -12,6 +12,8 @@ import { createRouter } from '$shared/utils/ws-server';
12
12
  import { fileWatcher } from '$backend/files/file-watcher';
13
13
  import { debug } from '$shared/utils/logger';
14
14
  import { ws } from '$backend/utils/ws';
15
+ import { projectQueries } from '../../database/queries/project-queries';
16
+ import { requireProjectAccess } from '../access';
15
17
 
16
18
  export const watchHandler = createRouter()
17
19
  // Start watching a project directory
@@ -20,9 +22,13 @@ export const watchHandler = createRouter()
20
22
  projectPath: t.String({ minLength: 1 })
21
23
  })
22
24
  }, async ({ data, conn }) => {
23
- const projectId = ws.getProjectId(conn);
24
25
  const { projectPath } = data;
25
26
 
27
+ const project = projectQueries.getByPath(projectPath);
28
+ if (!project) throw new Error('Access denied');
29
+ requireProjectAccess(conn, project.id);
30
+ const projectId = project.id;
31
+
26
32
  try {
27
33
  // Check if already watching
28
34
  if (fileWatcher.isWatching(projectId)) {
@@ -23,6 +23,9 @@ import {
23
23
  uploadFileOperation,
24
24
  deleteOperation
25
25
  } from '../../files/file-operations';
26
+ import { join } from 'node:path';
27
+ import { stat as fsStat, readdir as fsReaddir, rename as fsRename, access as fsAccess } from 'node:fs/promises';
28
+ import { requireFilePathAccess, requireSharedFilePathAccess } from './path-access';
26
29
 
27
30
  export const writeHandler = createRouter()
28
31
  // Write file operation
@@ -36,12 +39,13 @@ export const writeHandler = createRouter()
36
39
  size: t.Number(),
37
40
  modified: t.String()
38
41
  })
39
- }, async ({ data }) => {
42
+ }, async ({ data, conn }) => {
43
+ const filePath = requireFilePathAccess(conn, data.filePath);
40
44
  debug.log('file', 'Write file operation:', {
41
- filePath: data.filePath,
45
+ filePath,
42
46
  contentLength: data.content.length
43
47
  });
44
- return await writeFileOperation(data.filePath, data.content);
48
+ return await writeFileOperation(filePath, data.content);
45
49
  })
46
50
 
47
51
  // Create file operation
@@ -56,8 +60,9 @@ export const writeHandler = createRouter()
56
60
  size: t.Number(),
57
61
  modified: t.String()
58
62
  })
59
- }, async ({ data }) => {
60
- return await createFileOperation(data.filePath, data.content);
63
+ }, async ({ data, conn }) => {
64
+ const filePath = requireFilePathAccess(conn, data.filePath);
65
+ return await createFileOperation(filePath, data.content);
61
66
  })
62
67
 
63
68
  // Create directory operation
@@ -70,8 +75,12 @@ export const writeHandler = createRouter()
70
75
  path: t.String(),
71
76
  modified: t.String()
72
77
  })
73
- }, async ({ data }) => {
74
- return await createDirectoryOperation(data.dirPath);
78
+ }, async ({ data, conn }) => {
79
+ // Uses the shared guard so FolderBrowser can create candidate project
80
+ // folders outside any existing project, while still preventing writes
81
+ // inside another user's project.
82
+ const dirPath = requireSharedFilePathAccess(conn, data.dirPath);
83
+ return await createDirectoryOperation(dirPath);
75
84
  })
76
85
 
77
86
  // Rename operation
@@ -86,8 +95,10 @@ export const writeHandler = createRouter()
86
95
  newPath: t.String(),
87
96
  modified: t.String()
88
97
  })
89
- }, async ({ data }) => {
90
- return await renameOperation(data.oldPath, data.newPath);
98
+ }, async ({ data, conn }) => {
99
+ const oldPath = requireFilePathAccess(conn, data.oldPath);
100
+ const newPath = requireFilePathAccess(conn, data.newPath);
101
+ return await renameOperation(oldPath, newPath);
91
102
  })
92
103
 
93
104
  // Duplicate operation
@@ -103,8 +114,10 @@ export const writeHandler = createRouter()
103
114
  size: t.Number(),
104
115
  modified: t.String()
105
116
  })
106
- }, async ({ data }) => {
107
- return await duplicateOperation(data.sourcePath, data.targetPath);
117
+ }, async ({ data, conn }) => {
118
+ const sourcePath = requireFilePathAccess(conn, data.sourcePath);
119
+ const targetPath = requireFilePathAccess(conn, data.targetPath);
120
+ return await duplicateOperation(sourcePath, targetPath);
108
121
  })
109
122
 
110
123
  // Upload file operation
@@ -124,8 +137,10 @@ export const writeHandler = createRouter()
124
137
  size: t.Number(),
125
138
  modified: t.String()
126
139
  })
127
- }, async ({ data }) => {
128
- return await uploadFileOperation(data.file, data.targetPath);
140
+ }, async ({ data, conn }) => {
141
+ const targetPath = requireFilePathAccess(conn, data.targetPath);
142
+ requireFilePathAccess(conn, join(targetPath, data.file.name));
143
+ return await uploadFileOperation(data.file, targetPath);
129
144
  })
130
145
 
131
146
  // Delete operation
@@ -138,6 +153,85 @@ export const writeHandler = createRouter()
138
153
  message: t.String(),
139
154
  path: t.String()
140
155
  })
141
- }, async ({ data }) => {
142
- return await deleteOperation(data.filePath, data.force);
156
+ }, async ({ data, conn }) => {
157
+ const filePath = requireFilePathAccess(conn, data.filePath);
158
+ return await deleteOperation(filePath, data.force);
159
+ })
160
+
161
+ // Delete an empty directory from FolderBrowser. Restricted to:
162
+ // - real directory (not a file)
163
+ // - empty contents (no force, no recursive)
164
+ // - shared guard (outside all projects, or inside the user's own project)
165
+ .http('files:delete-directory', {
166
+ data: t.Object({
167
+ dirPath: t.String()
168
+ }),
169
+ response: t.Object({
170
+ message: t.String(),
171
+ path: t.String()
172
+ })
173
+ }, async ({ data, conn }) => {
174
+ const dirPath = requireSharedFilePathAccess(conn, data.dirPath);
175
+
176
+ const stats = await fsStat(dirPath);
177
+ if (!stats.isDirectory()) {
178
+ throw new Error('Path is not a directory');
179
+ }
180
+ const entries = await fsReaddir(dirPath);
181
+ if (entries.length > 0) {
182
+ throw new Error('Directory is not empty');
183
+ }
184
+
185
+ return await deleteOperation(dirPath, false);
186
+ })
187
+
188
+ // Rename a directory from FolderBrowser (e.g. fix typo on a candidate
189
+ // project folder). Restricted to real directories on both sides and
190
+ // guarded by the shared path access policy. Uses fs.rename directly
191
+ // because Bun.file(...).exists() returns false for directories, which
192
+ // makes the generic renameOperation unusable here.
193
+ .http('files:rename-directory', {
194
+ data: t.Object({
195
+ oldPath: t.String(),
196
+ newPath: t.String()
197
+ }),
198
+ response: t.Object({
199
+ message: t.String(),
200
+ oldPath: t.String(),
201
+ newPath: t.String(),
202
+ modified: t.String()
203
+ })
204
+ }, async ({ data, conn }) => {
205
+ const oldPath = requireSharedFilePathAccess(conn, data.oldPath);
206
+ const newPath = requireSharedFilePathAccess(conn, data.newPath);
207
+
208
+ let oldStats;
209
+ try {
210
+ oldStats = await fsStat(oldPath);
211
+ } catch {
212
+ throw new Error('Source path does not exist');
213
+ }
214
+ if (!oldStats.isDirectory()) {
215
+ throw new Error('Source path is not a directory');
216
+ }
217
+
218
+ try {
219
+ await fsAccess(newPath);
220
+ throw new Error('Destination path already exists');
221
+ } catch (err) {
222
+ if (err instanceof Error && err.message === 'Destination path already exists') {
223
+ throw err;
224
+ }
225
+ // fsAccess threw because newPath does not exist — that is what we want.
226
+ }
227
+
228
+ await fsRename(oldPath, newPath);
229
+ const newStats = await fsStat(newPath);
230
+
231
+ return {
232
+ message: 'Directory renamed successfully',
233
+ oldPath,
234
+ newPath,
235
+ modified: newStats.mtime.toISOString()
236
+ };
143
237
  });
@@ -5,7 +5,7 @@
5
5
  import { t } from 'elysia';
6
6
  import { createRouter } from '$shared/utils/ws-server';
7
7
  import { gitService } from '../../git/git-service';
8
- import { projectQueries } from '../../database/queries/project-queries';
8
+ import { requireProjectAccess } from '../access';
9
9
 
10
10
  const BranchSchema = t.Object({
11
11
  name: t.String(),
@@ -29,9 +29,8 @@ export const branchHandler = createRouter()
29
29
  ahead: t.Number(),
30
30
  behind: t.Number()
31
31
  })
32
- }, async ({ data }) => {
33
- const project = projectQueries.getById(data.projectId);
34
- if (!project) throw new Error('Project not found');
32
+ }, async ({ data, conn }) => {
33
+ const project = requireProjectAccess(conn, data.projectId);
35
34
  return await gitService.getBranches(project.path);
36
35
  })
37
36
 
@@ -42,9 +41,8 @@ export const branchHandler = createRouter()
42
41
  startPoint: t.Optional(t.String())
43
42
  }),
44
43
  response: t.Object({ ok: t.Boolean() })
45
- }, async ({ data }) => {
46
- const project = projectQueries.getById(data.projectId);
47
- if (!project) throw new Error('Project not found');
44
+ }, async ({ data, conn }) => {
45
+ const project = requireProjectAccess(conn, data.projectId);
48
46
  await gitService.createBranch(project.path, data.name, data.startPoint);
49
47
  return { ok: true };
50
48
  })
@@ -55,9 +53,8 @@ export const branchHandler = createRouter()
55
53
  name: t.String()
56
54
  }),
57
55
  response: t.Object({ ok: t.Boolean() })
58
- }, async ({ data }) => {
59
- const project = projectQueries.getById(data.projectId);
60
- if (!project) throw new Error('Project not found');
56
+ }, async ({ data, conn }) => {
57
+ const project = requireProjectAccess(conn, data.projectId);
61
58
  await gitService.switchBranch(project.path, data.name);
62
59
  return { ok: true };
63
60
  })
@@ -69,9 +66,8 @@ export const branchHandler = createRouter()
69
66
  force: t.Optional(t.Boolean())
70
67
  }),
71
68
  response: t.Object({ ok: t.Boolean() })
72
- }, async ({ data }) => {
73
- const project = projectQueries.getById(data.projectId);
74
- if (!project) throw new Error('Project not found');
69
+ }, async ({ data, conn }) => {
70
+ const project = requireProjectAccess(conn, data.projectId);
75
71
  await gitService.deleteBranch(project.path, data.name, data.force);
76
72
  return { ok: true };
77
73
  })
@@ -83,9 +79,8 @@ export const branchHandler = createRouter()
83
79
  newName: t.String({ minLength: 1 })
84
80
  }),
85
81
  response: t.Object({ ok: t.Boolean() })
86
- }, async ({ data }) => {
87
- const project = projectQueries.getById(data.projectId);
88
- if (!project) throw new Error('Project not found');
82
+ }, async ({ data, conn }) => {
83
+ const project = requireProjectAccess(conn, data.projectId);
89
84
  await gitService.renameBranch(project.path, data.oldName, data.newName);
90
85
  return { ok: true };
91
86
  })
@@ -99,8 +94,7 @@ export const branchHandler = createRouter()
99
94
  success: t.Boolean(),
100
95
  message: t.String()
101
96
  })
102
- }, async ({ data }) => {
103
- const project = projectQueries.getById(data.projectId);
104
- if (!project) throw new Error('Project not found');
97
+ }, async ({ data, conn }) => {
98
+ const project = requireProjectAccess(conn, data.projectId);
105
99
  return await gitService.mergeBranch(project.path, data.branchName);
106
100
  });
@@ -7,11 +7,11 @@
7
7
  import { t } from 'elysia';
8
8
  import { createRouter } from '$shared/utils/ws-server';
9
9
  import { execGit } from '../../git/git-executor';
10
- import { projectQueries } from '../../database/queries/project-queries';
11
10
  import { initializeEngine } from '../../engine';
12
11
  import type { EngineType } from '$shared/types/unified';
13
12
  import type { GeneratedCommitMessage } from '$shared/types/git';
14
13
  import { debug } from '$shared/utils/logger';
14
+ import { requireProjectAccess } from '../access';
15
15
 
16
16
  const COMMIT_MESSAGE_SCHEMA = {
17
17
  type: 'object',
@@ -49,9 +49,8 @@ export const commitMessageHandler = createRouter()
49
49
  response: t.Object({
50
50
  message: t.String()
51
51
  })
52
- }, async ({ data }) => {
53
- const project = projectQueries.getById(data.projectId);
54
- if (!project) throw new Error('Project not found');
52
+ }, async ({ data, conn }) => {
53
+ const project = requireProjectAccess(conn, data.projectId);
55
54
 
56
55
  // Get raw staged diff text
57
56
  const diffResult = await execGit(['diff', '--cached'], project.path);
@@ -5,7 +5,7 @@
5
5
  import { t } from 'elysia';
6
6
  import { createRouter } from '$shared/utils/ws-server';
7
7
  import { gitService } from '../../git/git-service';
8
- import { projectQueries } from '../../database/queries/project-queries';
8
+ import { requireProjectAccess } from '../access';
9
9
 
10
10
  export const commitHandler = createRouter()
11
11
  .http('git:commit', {
@@ -16,9 +16,8 @@ export const commitHandler = createRouter()
16
16
  response: t.Object({
17
17
  hash: t.String()
18
18
  })
19
- }, async ({ data }) => {
20
- const project = projectQueries.getById(data.projectId);
21
- if (!project) throw new Error('Project not found');
19
+ }, async ({ data, conn }) => {
20
+ const project = requireProjectAccess(conn, data.projectId);
22
21
  const hash = await gitService.commit(project.path, data.message);
23
22
  return { hash };
24
23
  })
@@ -31,9 +30,8 @@ export const commitHandler = createRouter()
31
30
  response: t.Object({
32
31
  hash: t.String()
33
32
  })
34
- }, async ({ data }) => {
35
- const project = projectQueries.getById(data.projectId);
36
- if (!project) throw new Error('Project not found');
33
+ }, async ({ data, conn }) => {
34
+ const project = requireProjectAccess(conn, data.projectId);
37
35
  const hash = await gitService.amendCommit(project.path, data.message);
38
36
  return { hash };
39
37
  });
@@ -5,7 +5,7 @@
5
5
  import { t } from 'elysia';
6
6
  import { createRouter } from '$shared/utils/ws-server';
7
7
  import { gitService } from '../../git/git-service';
8
- import { projectQueries } from '../../database/queries/project-queries';
8
+ import { requireProjectAccess } from '../access';
9
9
 
10
10
  const ConflictMarkerSchema = t.Object({
11
11
  ourStart: t.Number(),
@@ -29,9 +29,8 @@ export const conflictHandler = createRouter()
29
29
  content: t.String(),
30
30
  markers: t.Array(ConflictMarkerSchema)
31
31
  }))
32
- }, async ({ data }) => {
33
- const project = projectQueries.getById(data.projectId);
34
- if (!project) throw new Error('Project not found');
32
+ }, async ({ data, conn }) => {
33
+ const project = requireProjectAccess(conn, data.projectId);
35
34
  return await gitService.getConflictFiles(project.path);
36
35
  })
37
36
 
@@ -43,9 +42,8 @@ export const conflictHandler = createRouter()
43
42
  customContent: t.Optional(t.String())
44
43
  }),
45
44
  response: t.Object({ ok: t.Boolean() })
46
- }, async ({ data }) => {
47
- const project = projectQueries.getById(data.projectId);
48
- if (!project) throw new Error('Project not found');
45
+ }, async ({ data, conn }) => {
46
+ const project = requireProjectAccess(conn, data.projectId);
49
47
  await gitService.resolveConflict(
50
48
  project.path,
51
49
  data.filePath,
@@ -60,9 +58,8 @@ export const conflictHandler = createRouter()
60
58
  projectId: t.String()
61
59
  }),
62
60
  response: t.Object({ ok: t.Boolean() })
63
- }, async ({ data }) => {
64
- const project = projectQueries.getById(data.projectId);
65
- if (!project) throw new Error('Project not found');
61
+ }, async ({ data, conn }) => {
62
+ const project = requireProjectAccess(conn, data.projectId);
66
63
  await gitService.abortMerge(project.path);
67
64
  return { ok: true };
68
65
  });
@@ -5,7 +5,7 @@
5
5
  import { t } from 'elysia';
6
6
  import { createRouter } from '$shared/utils/ws-server';
7
7
  import { gitService } from '../../git/git-service';
8
- import { projectQueries } from '../../database/queries/project-queries';
8
+ import { requireProjectAccess } from '../access';
9
9
 
10
10
  const DiffHunkLineSchema = t.Object({
11
11
  type: t.Union([t.Literal('add'), t.Literal('delete'), t.Literal('context'), t.Literal('header')]),
@@ -38,9 +38,8 @@ export const diffHandler = createRouter()
38
38
  filePath: t.Optional(t.String())
39
39
  }),
40
40
  response: t.Array(FileDiffSchema)
41
- }, async ({ data }) => {
42
- const project = projectQueries.getById(data.projectId);
43
- if (!project) throw new Error('Project not found');
41
+ }, async ({ data, conn }) => {
42
+ const project = requireProjectAccess(conn, data.projectId);
44
43
  return await gitService.getDiffUnstaged(project.path, data.filePath);
45
44
  })
46
45
 
@@ -50,9 +49,8 @@ export const diffHandler = createRouter()
50
49
  filePath: t.Optional(t.String())
51
50
  }),
52
51
  response: t.Array(FileDiffSchema)
53
- }, async ({ data }) => {
54
- const project = projectQueries.getById(data.projectId);
55
- if (!project) throw new Error('Project not found');
52
+ }, async ({ data, conn }) => {
53
+ const project = requireProjectAccess(conn, data.projectId);
56
54
  return await gitService.getDiffStaged(project.path, data.filePath);
57
55
  })
58
56
 
@@ -62,8 +60,7 @@ export const diffHandler = createRouter()
62
60
  commitHash: t.String()
63
61
  }),
64
62
  response: t.Array(FileDiffSchema)
65
- }, async ({ data }) => {
66
- const project = projectQueries.getById(data.projectId);
67
- if (!project) throw new Error('Project not found');
63
+ }, async ({ data, conn }) => {
64
+ const project = requireProjectAccess(conn, data.projectId);
68
65
  return await gitService.getDiffCommit(project.path, data.commitHash);
69
66
  });
@@ -5,7 +5,7 @@
5
5
  import { t } from 'elysia';
6
6
  import { createRouter } from '$shared/utils/ws-server';
7
7
  import { gitService } from '../../git/git-service';
8
- import { projectQueries } from '../../database/queries/project-queries';
8
+ import { requireProjectAccess } from '../access';
9
9
 
10
10
  export const logHandler = createRouter()
11
11
  .http('git:log', {
@@ -29,9 +29,8 @@ export const logHandler = createRouter()
29
29
  total: t.Number(),
30
30
  hasMore: t.Boolean()
31
31
  })
32
- }, async ({ data }) => {
33
- const project = projectQueries.getById(data.projectId);
34
- if (!project) throw new Error('Project not found');
32
+ }, async ({ data, conn }) => {
33
+ const project = requireProjectAccess(conn, data.projectId);
35
34
  return await gitService.getLog(
36
35
  project.path,
37
36
  data.limit ?? 50,