@myrialabs/clopen 0.4.34 → 0.4.36

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 (125) hide show
  1. package/backend/artifacts/sync.test.ts +63 -0
  2. package/backend/artifacts/sync.ts +56 -3
  3. package/backend/auth/permissions.ts +7 -0
  4. package/backend/containers/actions.ts +316 -0
  5. package/backend/containers/disk-usage.test.ts +68 -0
  6. package/backend/containers/disk-usage.ts +170 -0
  7. package/backend/containers/logs.ts +335 -0
  8. package/backend/containers/monitor.ts +410 -0
  9. package/backend/containers/parse.test.ts +599 -0
  10. package/backend/containers/parse.ts +905 -0
  11. package/backend/containers/port-index.test.ts +91 -0
  12. package/backend/containers/port-index.ts +198 -0
  13. package/backend/containers/prune-job.test.ts +148 -0
  14. package/backend/containers/prune-job.ts +129 -0
  15. package/backend/containers/pty-backend.ts +337 -0
  16. package/backend/containers/pty.ts +114 -0
  17. package/backend/containers/runtime.ts +218 -0
  18. package/backend/containers/scan.ts +293 -0
  19. package/backend/database/migrations/070_create_worktrees_table.ts +67 -0
  20. package/backend/database/migrations/index.ts +7 -0
  21. package/backend/database/queries/index.ts +1 -0
  22. package/backend/database/queries/session-queries.ts +50 -11
  23. package/backend/database/queries/worktree-queries.ts +148 -0
  24. package/backend/engine/adapters/opencode/server.ts +389 -83
  25. package/backend/engine/adapters/opencode/stream.ts +14 -14
  26. package/backend/engine/hot-reload.ts +25 -10
  27. package/backend/files/file-watcher.test.ts +105 -0
  28. package/backend/files/file-watcher.ts +80 -10
  29. package/backend/git/git-service.test.ts +33 -0
  30. package/backend/git/git-service.ts +7 -3
  31. package/backend/git/nested-repos.test.ts +292 -1
  32. package/backend/git/nested-repos.ts +330 -17
  33. package/backend/host/metrics.test.ts +110 -0
  34. package/backend/host/metrics.ts +235 -0
  35. package/backend/{ports → host}/runner.ts +19 -10
  36. package/backend/index.ts +16 -4
  37. package/backend/mcp/internal/servers/browser-automation/context.ts +16 -2
  38. package/backend/ports/attribute.test.ts +3 -2
  39. package/backend/ports/attribute.ts +6 -45
  40. package/backend/ports/kill.ts +1 -1
  41. package/backend/ports/monitor.ts +1 -1
  42. package/backend/ports/processes.ts +1 -1
  43. package/backend/ports/scan-host.ts +77 -8
  44. package/backend/ports/scan.test.ts +1 -1
  45. package/backend/ports/scan.ts +1 -1
  46. package/backend/ports/ssh-lineage.ts +1 -1
  47. package/backend/preview/browser/browser-pool.ts +81 -0
  48. package/backend/preview/browser/browser-preview-service.ts +142 -32
  49. package/backend/preview/browser/browser-tab-manager.ts +350 -113
  50. package/backend/preview/browser/browser-video-capture.ts +84 -31
  51. package/backend/preview/browser/types.ts +9 -0
  52. package/backend/projects/project-cleanup.integration.test.ts +1 -1
  53. package/backend/projects/project-cleanup.ts +7 -1
  54. package/backend/projects/shell-ownership.ts +65 -0
  55. package/backend/snapshot/snapshot-service.ts +6 -2
  56. package/backend/terminal/ptykit.ts +35 -6
  57. package/backend/utils/ws.ts +21 -1
  58. package/backend/worktrees/clone.ts +222 -0
  59. package/backend/worktrees/index.ts +29 -0
  60. package/backend/worktrees/merge.test.ts +93 -0
  61. package/backend/worktrees/merge.ts +232 -0
  62. package/backend/worktrees/paths.test.ts +60 -0
  63. package/backend/worktrees/paths.ts +60 -0
  64. package/backend/worktrees/resolve.ts +67 -0
  65. package/backend/worktrees/service.ts +315 -0
  66. package/backend/worktrees/tree.ts +59 -0
  67. package/backend/ws/access.ts +18 -0
  68. package/backend/ws/artifacts/generate.ts +2 -2
  69. package/backend/ws/chat/stream.ts +9 -2
  70. package/backend/ws/containers/actions.ts +156 -0
  71. package/backend/ws/containers/index.ts +43 -0
  72. package/backend/ws/containers/list.ts +146 -0
  73. package/backend/ws/containers/logs.ts +43 -0
  74. package/backend/ws/containers/tunnel.ts +101 -0
  75. package/backend/ws/files/panel-state-scope.test.ts +102 -0
  76. package/backend/ws/files/path-access.test.ts +93 -1
  77. package/backend/ws/files/path-access.ts +54 -5
  78. package/backend/ws/files/read.ts +15 -10
  79. package/backend/ws/files/search.ts +7 -7
  80. package/backend/ws/files/state.ts +70 -8
  81. package/backend/ws/files/watch.ts +16 -14
  82. package/backend/ws/git/branch-name.ts +3 -3
  83. package/backend/ws/git/branch.ts +15 -15
  84. package/backend/ws/git/commit-message.ts +3 -3
  85. package/backend/ws/git/commit.ts +17 -17
  86. package/backend/ws/git/conflict.ts +10 -10
  87. package/backend/ws/git/diff.ts +9 -9
  88. package/backend/ws/git/ignored.ts +9 -9
  89. package/backend/ws/git/log.ts +6 -4
  90. package/backend/ws/git/remote.ts +43 -43
  91. package/backend/ws/git/staging.ts +16 -16
  92. package/backend/ws/git/status.ts +47 -37
  93. package/backend/ws/index.ts +6 -0
  94. package/backend/ws/message-rate-limiter.test.ts +45 -0
  95. package/backend/ws/message-rate-limiter.ts +34 -3
  96. package/backend/ws/preview/access.ts +11 -3
  97. package/backend/ws/projects/index.ts +5 -1
  98. package/backend/ws/projects/info.test.ts +54 -0
  99. package/backend/ws/projects/info.ts +398 -0
  100. package/backend/ws/sessions/crud.ts +21 -6
  101. package/backend/ws/snapshot/restore.ts +11 -14
  102. package/backend/ws/ssh/connections.ts +8 -0
  103. package/backend/ws/system/device-info.ts +70 -96
  104. package/backend/ws/worktrees/crud.ts +187 -0
  105. package/backend/ws/worktrees/index.ts +33 -0
  106. package/backend/ws/worktrees/transfer.ts +88 -0
  107. package/dist/assets/{index-vW2RpdHu.js → index-Bg-SUCFg.js} +1 -1
  108. package/dist/assets/{index-gGTMFUa8.js → index-Cz4YpHVi.js} +1 -1
  109. package/dist/assets/main-9G7IpQpK.css +1 -0
  110. package/dist/assets/main-BofFsH8E.js +1085 -0
  111. package/dist/index.html +2 -2
  112. package/dist/manifest.json +9 -2
  113. package/package.json +1 -1
  114. package/shared/types/containers/container.ts +366 -0
  115. package/shared/types/containers/index.ts +5 -0
  116. package/shared/types/database/schema.ts +26 -0
  117. package/shared/types/host/index.ts +18 -0
  118. package/shared/types/ports/port.ts +47 -9
  119. package/shared/utils/logger.ts +3 -0
  120. package/shared/utils/workspace-scope.test.ts +80 -0
  121. package/shared/utils/workspace-scope.ts +57 -0
  122. package/shared/utils/ws-client.ts +92 -17
  123. package/shared/utils/ws-server.ts +83 -16
  124. package/dist/assets/main-CYCMEbXB.css +0 -1
  125. package/dist/assets/main-ZCojSzvW.js +0 -1060
@@ -26,7 +26,7 @@ import { requireProjectAccess } from '../access';
26
26
  import {
27
27
  filterAccessibleExpandedPaths,
28
28
  requireFilePathAccess,
29
- requireProjectPathAccess,
29
+ requireWorkspaceRootAccess,
30
30
  requireSharedFilePathAccess
31
31
  } from './path-access';
32
32
 
@@ -72,8 +72,9 @@ export const readHandler = createRouter()
72
72
  ])
73
73
  )
74
74
  }, async ({ data, conn }) => {
75
- const project = requireProjectPathAccess(conn, data.project_path);
76
- const projectPath = project.path;
75
+ // The requested root, not the project's: for a worktree these differ, and
76
+ // listing the project would hand back the main tree's files and paths.
77
+ const { root: projectPath } = requireWorkspaceRootAccess(conn, data.project_path);
77
78
 
78
79
  if (!(await existsSync(projectPath))) {
79
80
  throw new Error('Project path does not exist');
@@ -186,6 +187,8 @@ export const readHandler = createRouter()
186
187
  .http('files:read-file-at', {
187
188
  data: t.Object({
188
189
  projectId: t.String(),
190
+ // Workspace root the file lives in; absent means the project itself.
191
+ rootPath: t.Optional(t.String()),
189
192
  filePath: t.String(),
190
193
  ref: t.Optional(t.String())
191
194
  }),
@@ -194,16 +197,18 @@ export const readHandler = createRouter()
194
197
  ref: t.String()
195
198
  })
196
199
  }, async ({ data, conn }) => {
197
- requireProjectAccess(conn, data.projectId);
198
- const project = projectQueries.getById(data.projectId);
199
- if (!project) throw new Error('Access denied');
200
+ // A worktree is its own checkout, so the gutter diff has to resolve
201
+ // against the tree the file is in rather than the project's.
202
+ const { root } = data.rootPath
203
+ ? requireWorkspaceRootAccess(conn, data.rootPath)
204
+ : { root: requireProjectAccess(conn, data.projectId).path };
200
205
 
201
206
  const ref = data.ref || 'HEAD';
202
207
 
203
- // Make filePath relative to project root for `git show`
208
+ // Make filePath relative to the workspace root for `git show`
204
209
  let relativePath = data.filePath;
205
210
  if (isAbsolute(data.filePath)) {
206
- relativePath = relative(project.path, data.filePath);
211
+ relativePath = relative(root, data.filePath);
207
212
  }
208
213
  // Normalize path separators for git
209
214
  relativePath = relativePath.replace(/\\/g, '/');
@@ -212,8 +217,8 @@ export const readHandler = createRouter()
212
217
  // repo's `git show HEAD:file` returns nothing for files tracked
213
218
  // inside a nested repo and gitignored by the parent, so the editor
214
219
  // gutter diff would silently go empty for subrepo files without this.
215
- const repo = await findRepoForFile(project.path, relativePath);
216
- const cwd = repo?.repoPath ?? project.path;
220
+ const repo = await findRepoForFile(root, relativePath);
221
+ const cwd = repo?.repoPath ?? root;
217
222
  const gitFilePath = repo?.relativeFilePath ?? relativePath;
218
223
 
219
224
  const content = await gitService.getFileAtRef(cwd, ref, gitFilePath);
@@ -3,7 +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
+ import { requireWorkspaceRootAccess } from './path-access';
7
7
  import { validateFileSize } from '../../files/file-size-limit';
8
8
 
9
9
  // Heuristic patterns that indicate potential ReDoS risk:
@@ -407,13 +407,13 @@ export const fileSearchHandler = createRouter()
407
407
  response: t.Array(FileSearchResultSchema)
408
408
  }, async ({ data, conn }) => {
409
409
  const { project_path, query } = data;
410
- const project = requireProjectPathAccess(conn, project_path);
410
+ const { root } = requireWorkspaceRootAccess(conn, project_path);
411
411
 
412
412
  if (!query || query.trim().length === 0) {
413
413
  return [];
414
414
  }
415
415
 
416
- return await searchFilesByName(project.path, query);
416
+ return await searchFilesByName(root, query);
417
417
  })
418
418
  .http('files:search-code', {
419
419
  data: t.Object({
@@ -446,13 +446,13 @@ export const fileSearchHandler = createRouter()
446
446
  include_pattern,
447
447
  exclude_pattern
448
448
  } = data;
449
- const project = requireProjectPathAccess(conn, project_path);
449
+ const { root } = requireWorkspaceRootAccess(conn, project_path);
450
450
 
451
451
  if (!query || query.trim().length === 0) {
452
452
  return [];
453
453
  }
454
454
 
455
- return await searchCodeContent(project.path, query, {
455
+ return await searchCodeContent(root, query, {
456
456
  caseSensitive: case_sensitive,
457
457
  wholeWord: whole_word,
458
458
  useRegex: use_regex,
@@ -491,13 +491,13 @@ export const fileSearchHandler = createRouter()
491
491
  include_pattern,
492
492
  exclude_pattern
493
493
  } = data;
494
- const project = requireProjectPathAccess(conn, project_path);
494
+ const { root } = requireWorkspaceRootAccess(conn, project_path);
495
495
 
496
496
  if (!search_query || search_query.trim().length === 0) {
497
497
  return { results: [], totalReplacements: 0, totalFiles: 0 };
498
498
  }
499
499
 
500
- const results = await replaceInFiles(project.path, search_query, replace_with, {
500
+ const results = await replaceInFiles(root, search_query, replace_with, {
501
501
  caseSensitive: case_sensitive,
502
502
  wholeWord: whole_word,
503
503
  useRegex: use_regex,
@@ -1,10 +1,14 @@
1
1
  /**
2
2
  * Files Panel State Handlers
3
3
  *
4
- * Persist per-user-per-project files panel state (expanded folders,
5
- * open tabs, scroll positions, view mode). Single source of truth in DB
6
- * so that the state survives browser refresh and follows the user across
7
- * devices.
4
+ * Persist per-user-per-workspace files panel state (expanded folders, open
5
+ * tabs, scroll positions, view mode). Single source of truth in DB so that the
6
+ * state survives browser refresh and follows the user across devices.
7
+ *
8
+ * The row is per (user, project), but the state inside it is per workspace: a
9
+ * project and each of its worktrees keep separate entries. Sharing one entry
10
+ * carried open tabs — including unsaved buffers — from the main tree into a
11
+ * worktree, which read as the edit having crossed between them.
8
12
  */
9
13
 
10
14
  import { t } from 'elysia';
@@ -13,10 +17,50 @@ import { projectQueries } from '../../database/queries/project-queries';
13
17
  import { ws as wsServer } from '../../utils/ws';
14
18
  import { requireProjectAccess } from '../access';
15
19
 
20
+ /** Stored shape: opaque per-scope state strings under one version marker. */
21
+ interface ScopedPanelState {
22
+ v: 2;
23
+ scopes: Record<string, string>;
24
+ }
25
+
26
+ function parseStored(raw: string | null): ScopedPanelState {
27
+ if (!raw) return { v: 2, scopes: {} };
28
+
29
+ try {
30
+ const parsed = JSON.parse(raw) as ScopedPanelState | Record<string, unknown>;
31
+ if (
32
+ typeof parsed === 'object' && parsed !== null &&
33
+ (parsed as ScopedPanelState).v === 2 &&
34
+ typeof (parsed as ScopedPanelState).scopes === 'object'
35
+ ) {
36
+ return parsed as ScopedPanelState;
37
+ }
38
+ } catch {
39
+ // Fall through — anything unparseable is treated as absent.
40
+ }
41
+
42
+ // Pre-worktree state was a bare panel-state document; it belongs to the main
43
+ // tree, so existing users keep their tabs instead of starting empty.
44
+ return { v: 2, scopes: {} };
45
+ }
46
+
47
+ /** Whether `raw` is legacy (flat) state rather than the scoped envelope. */
48
+ function isLegacyState(raw: string | null): boolean {
49
+ if (!raw) return false;
50
+ try {
51
+ const parsed = JSON.parse(raw) as { v?: number };
52
+ return parsed?.v !== 2;
53
+ } catch {
54
+ return false;
55
+ }
56
+ }
57
+
16
58
  export const filesStateHandler = createRouter()
17
59
  .http('files:get-panel-state', {
18
60
  data: t.Object({
19
- projectId: t.String()
61
+ projectId: t.String(),
62
+ // Absent means the main tree, which is also where legacy state lives.
63
+ scopeKey: t.Optional(t.String())
20
64
  }),
21
65
  response: t.Object({
22
66
  state: t.Union([t.String(), t.Null()])
@@ -24,19 +68,37 @@ export const filesStateHandler = createRouter()
24
68
  }, async ({ data, conn }) => {
25
69
  requireProjectAccess(conn, data.projectId);
26
70
  const userId = wsServer.getUserId(conn);
27
- const state = projectQueries.getFilesPanelState(userId, data.projectId);
28
- return { state };
71
+ const raw = projectQueries.getFilesPanelState(userId, data.projectId);
72
+
73
+ const scopeKey = data.scopeKey || data.projectId;
74
+ if (isLegacyState(raw)) {
75
+ return { state: scopeKey === data.projectId ? raw : null };
76
+ }
77
+
78
+ return { state: parseStored(raw).scopes[scopeKey] ?? null };
29
79
  })
30
80
 
31
81
  .http('files:set-panel-state', {
32
82
  data: t.Object({
33
83
  projectId: t.String(),
84
+ scopeKey: t.Optional(t.String()),
34
85
  state: t.Union([t.String(), t.Null()])
35
86
  }),
36
87
  response: t.Object({ ok: t.Boolean() })
37
88
  }, async ({ data, conn }) => {
38
89
  requireProjectAccess(conn, data.projectId);
39
90
  const userId = wsServer.getUserId(conn);
40
- projectQueries.setFilesPanelState(userId, data.projectId, data.state);
91
+
92
+ const raw = projectQueries.getFilesPanelState(userId, data.projectId);
93
+ const scopeKey = data.scopeKey || data.projectId;
94
+
95
+ // Read-modify-write so writing one workspace never drops another's entry.
96
+ const stored = parseStored(raw);
97
+ if (isLegacyState(raw) && raw) stored.scopes[data.projectId] = raw;
98
+
99
+ if (data.state === null) delete stored.scopes[scopeKey];
100
+ else stored.scopes[scopeKey] = data.state;
101
+
102
+ projectQueries.setFilesPanelState(userId, data.projectId, JSON.stringify(stored));
41
103
  return { ok: true };
42
104
  });
@@ -12,7 +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';
15
+ import { makeScopeKey } from '$shared/utils/workspace-scope';
16
+ import { requireWorkspaceRootAccess } from './path-access';
16
17
  import { requireProjectAccess } from '../access';
17
18
 
18
19
  // Connection ids that already have a disconnect cleanup registered, so we
@@ -28,10 +29,10 @@ export const watchHandler = createRouter()
28
29
  }, async ({ data, conn }) => {
29
30
  const { projectPath } = data;
30
31
 
31
- const project = projectQueries.getByPath(projectPath);
32
- if (!project) throw new Error('Access denied');
33
- requireProjectAccess(conn, project.id);
34
- const projectId = project.id;
32
+ // The root may be the project or one of its worktrees; watchers are keyed
33
+ // per workspace so two trees of one project never share a watcher.
34
+ const { project, worktreeId } = requireWorkspaceRootAccess(conn, projectPath);
35
+ const projectId = makeScopeKey(project.id, worktreeId);
35
36
 
36
37
  try {
37
38
  const connId = ws.getConnectionId(conn);
@@ -54,7 +55,7 @@ export const watchHandler = createRouter()
54
55
 
55
56
  if (success) {
56
57
  // Broadcast confirmation (frontend filters by projectId)
57
- ws.emit.project(projectId, 'files:watching', {
58
+ ws.emit.project(project.id, 'files:watching', {
58
59
  projectId,
59
60
  watching: true,
60
61
  timestamp: Date.now()
@@ -63,14 +64,14 @@ export const watchHandler = createRouter()
63
64
  debug.log('file', `Started watching project ${projectId}`);
64
65
  } else {
65
66
  // Broadcast error (frontend filters by projectId)
66
- ws.emit.project(projectId, 'files:watch-error', {
67
+ ws.emit.project(project.id, 'files:watch-error', {
67
68
  projectId,
68
69
  error: 'Failed to start file watcher'
69
70
  });
70
71
  }
71
72
  } catch (error) {
72
73
  debug.error('file', 'Error starting file watch:', error);
73
- ws.emit.project(projectId, 'files:watch-error', {
74
+ ws.emit.project(project.id, 'files:watch-error', {
74
75
  projectId,
75
76
  error: error instanceof Error ? error.message : 'Unknown error'
76
77
  });
@@ -88,14 +89,15 @@ export const watchHandler = createRouter()
88
89
  })
89
90
  }, async ({ data, conn }) => {
90
91
  let projectId: string;
92
+ let roomProjectId: string;
91
93
  if (data.projectPath) {
92
- const project = projectQueries.getByPath(data.projectPath);
93
- if (!project) return; // unknown path — nothing to unwatch
94
- requireProjectAccess(conn, project.id);
95
- projectId = project.id;
94
+ const { project, worktreeId } = requireWorkspaceRootAccess(conn, data.projectPath);
95
+ roomProjectId = project.id;
96
+ projectId = makeScopeKey(project.id, worktreeId);
96
97
  } else {
97
98
  // Backwards-compatible fallback for callers that don't send a path.
98
- projectId = ws.getProjectId(conn);
99
+ roomProjectId = ws.getProjectId(conn);
100
+ projectId = roomProjectId;
99
101
  }
100
102
 
101
103
  try {
@@ -110,7 +112,7 @@ export const watchHandler = createRouter()
110
112
  // Broadcast the ACTUAL resulting state — other devices may still be
111
113
  // viewing this project, in which case the watcher is still alive and
112
114
  // they must not be told it stopped.
113
- ws.emit.project(projectId, 'files:watching', {
115
+ ws.emit.project(roomProjectId, 'files:watching', {
114
116
  projectId,
115
117
  watching: fileWatcher.isWatching(projectId),
116
118
  timestamp: Date.now()
@@ -19,7 +19,7 @@ import {
19
19
  TEST_BRANCH_NAME_PREFIX
20
20
  } from '$shared/constants/git';
21
21
  import { debug } from '$shared/utils/logger';
22
- import { requireProjectAccess } from '../access';
22
+ import { requireProjectWorkspace } from '../access';
23
23
 
24
24
  const INVALID_BRANCH_SEPARATOR_CHARS = /[\s\0~^:?*[\]\\]+/g;
25
25
  const GENERATED_BRANCH_PREFIXES = [
@@ -144,8 +144,8 @@ export const branchNameHandler = createRouter()
144
144
  branchName: t.String()
145
145
  })
146
146
  }, async ({ data, conn }) => {
147
- const project = requireProjectAccess(conn, data.projectId);
148
- const cwd = resolveRepoCwd(project.path, data.repoPath);
147
+ const { root } = requireProjectWorkspace(conn, data.projectId);
148
+ const cwd = resolveRepoCwd(root, data.repoPath);
149
149
 
150
150
  const diffResult = await execGit(['diff', '--cached'], cwd);
151
151
  const rawDiff = diffResult.stdout;
@@ -6,7 +6,7 @@ import { t } from 'elysia';
6
6
  import path from 'node:path';
7
7
  import { createRouter } from '$shared/utils/ws-server';
8
8
  import { gitService } from '../../git/git-service';
9
- import { requireProjectAccess } from '../access';
9
+ import { requireProjectWorkspace } from '../access';
10
10
  import { debug } from '$shared/utils/logger';
11
11
 
12
12
  const BranchSchema = t.Object({
@@ -72,8 +72,8 @@ export const branchHandler = createRouter()
72
72
  nested: t.Optional(t.Array(NestedRepoInfoSchema))
73
73
  })
74
74
  }, async ({ data, conn }) => {
75
- const project = requireProjectAccess(conn, data.projectId);
76
- return await gitService.getBranches(project.path, data.selectedRemote);
75
+ const { root } = requireProjectWorkspace(conn, data.projectId);
76
+ return await gitService.getBranches(root, data.selectedRemote);
77
77
  })
78
78
 
79
79
  .http('git:create-branch', {
@@ -87,8 +87,8 @@ export const branchHandler = createRouter()
87
87
  }),
88
88
  response: t.Object({ ok: t.Boolean() })
89
89
  }, async ({ data, conn }) => {
90
- const project = requireProjectAccess(conn, data.projectId);
91
- const cwd = resolveRepoCwd(project.path, data.repoPath);
90
+ const { root } = requireProjectWorkspace(conn, data.projectId);
91
+ const cwd = resolveRepoCwd(root, data.repoPath);
92
92
  await gitService.createBranch(cwd, data.name, data.startPoint);
93
93
  return { ok: true };
94
94
  })
@@ -102,8 +102,8 @@ export const branchHandler = createRouter()
102
102
  }),
103
103
  response: t.Object({ ok: t.Boolean() })
104
104
  }, async ({ data, conn }) => {
105
- const project = requireProjectAccess(conn, data.projectId);
106
- const cwd = resolveRepoCwd(project.path, data.repoPath);
105
+ const { root } = requireProjectWorkspace(conn, data.projectId);
106
+ const cwd = resolveRepoCwd(root, data.repoPath);
107
107
  await gitService.switchBranch(cwd, data.name);
108
108
  return { ok: true };
109
109
  })
@@ -116,8 +116,8 @@ export const branchHandler = createRouter()
116
116
  }),
117
117
  response: t.Object({ ok: t.Boolean() })
118
118
  }, async ({ data, conn }) => {
119
- const project = requireProjectAccess(conn, data.projectId);
120
- const cwd = resolveRepoCwd(project.path, data.repoPath);
119
+ const { root } = requireProjectWorkspace(conn, data.projectId);
120
+ const cwd = resolveRepoCwd(root, data.repoPath);
121
121
  await gitService.checkoutCommit(cwd, data.commitHash);
122
122
  return { ok: true };
123
123
  })
@@ -132,8 +132,8 @@ export const branchHandler = createRouter()
132
132
  }),
133
133
  response: t.Object({ ok: t.Boolean() })
134
134
  }, async ({ data, conn }) => {
135
- const project = requireProjectAccess(conn, data.projectId);
136
- const cwd = resolveRepoCwd(project.path, data.repoPath);
135
+ const { root } = requireProjectWorkspace(conn, data.projectId);
136
+ const cwd = resolveRepoCwd(root, data.repoPath);
137
137
  await gitService.deleteBranch(cwd, data.name, data.force);
138
138
  return { ok: true };
139
139
  })
@@ -147,8 +147,8 @@ export const branchHandler = createRouter()
147
147
  }),
148
148
  response: t.Object({ ok: t.Boolean() })
149
149
  }, async ({ data, conn }) => {
150
- const project = requireProjectAccess(conn, data.projectId);
151
- const cwd = resolveRepoCwd(project.path, data.repoPath);
150
+ const { root } = requireProjectWorkspace(conn, data.projectId);
151
+ const cwd = resolveRepoCwd(root, data.repoPath);
152
152
  await gitService.renameBranch(cwd, data.oldName, data.newName);
153
153
  return { ok: true };
154
154
  })
@@ -165,7 +165,7 @@ export const branchHandler = createRouter()
165
165
  message: t.String()
166
166
  })
167
167
  }, async ({ data, conn }) => {
168
- const project = requireProjectAccess(conn, data.projectId);
169
- const cwd = resolveRepoCwd(project.path, data.repoPath);
168
+ const { root } = requireProjectWorkspace(conn, data.projectId);
169
+ const cwd = resolveRepoCwd(root, data.repoPath);
170
170
  return await gitService.mergeBranch(cwd, data.branchName, data.noFastForward ?? false);
171
171
  });
@@ -12,7 +12,7 @@ import { resolveGenerationTarget } from '../../engine/resolve-model';
12
12
  import type { EngineType } from '$shared/types/unified';
13
13
  import type { GeneratedCommitMessage } from '$shared/types/git';
14
14
  import { debug } from '$shared/utils/logger';
15
- import { requireProjectAccess } from '../access';
15
+ import { requireProjectWorkspace } from '../access';
16
16
 
17
17
  // Schema is shaped to satisfy OpenAI's strict structured-output mode (used by
18
18
  // Codex via `outputSchema`): every object must declare `additionalProperties:
@@ -74,8 +74,8 @@ export const commitMessageHandler = createRouter()
74
74
  message: t.String()
75
75
  })
76
76
  }, async ({ data, conn }) => {
77
- const project = requireProjectAccess(conn, data.projectId);
78
- const cwd = resolveRepoCwd(project.path, data.repoPath);
77
+ const { root } = requireProjectWorkspace(conn, data.projectId);
78
+ const cwd = resolveRepoCwd(root, data.repoPath);
79
79
 
80
80
  // Get raw staged diff text
81
81
  const diffResult = await execGit(['diff', '--cached'], cwd);
@@ -6,7 +6,7 @@ import { t } from 'elysia';
6
6
  import path from 'node:path';
7
7
  import { createRouter } from '$shared/utils/ws-server';
8
8
  import { gitService } from '../../git/git-service';
9
- import { requireProjectAccess } from '../access';
9
+ import { requireProjectWorkspace } from '../access';
10
10
  import { debug } from '$shared/utils/logger';
11
11
 
12
12
  /**
@@ -36,8 +36,8 @@ export const commitHandler = createRouter()
36
36
  hash: t.String()
37
37
  })
38
38
  }, async ({ data, conn }) => {
39
- const project = requireProjectAccess(conn, data.projectId);
40
- const cwd = resolveRepoCwd(project.path, data.repoPath);
39
+ const { root } = requireProjectWorkspace(conn, data.projectId);
40
+ const cwd = resolveRepoCwd(root, data.repoPath);
41
41
  const hash = await gitService.commit(cwd, data.message);
42
42
  return { hash };
43
43
  })
@@ -52,8 +52,8 @@ export const commitHandler = createRouter()
52
52
  hash: t.String()
53
53
  })
54
54
  }, async ({ data, conn }) => {
55
- const project = requireProjectAccess(conn, data.projectId);
56
- const cwd = resolveRepoCwd(project.path, data.repoPath);
55
+ const { root } = requireProjectWorkspace(conn, data.projectId);
56
+ const cwd = resolveRepoCwd(root, data.repoPath);
57
57
  const hash = await gitService.amendCommit(cwd, data.message);
58
58
  return { hash };
59
59
  })
@@ -66,8 +66,8 @@ export const commitHandler = createRouter()
66
66
  }),
67
67
  response: t.Object({ ok: t.Boolean() })
68
68
  }, async ({ data, conn }) => {
69
- const project = requireProjectAccess(conn, data.projectId);
70
- const cwd = resolveRepoCwd(project.path, data.repoPath);
69
+ const { root } = requireProjectWorkspace(conn, data.projectId);
70
+ const cwd = resolveRepoCwd(root, data.repoPath);
71
71
  await gitService.undoLastCommit(cwd, data.mode);
72
72
  return { ok: true };
73
73
  })
@@ -83,8 +83,8 @@ export const commitHandler = createRouter()
83
83
  message: t.String()
84
84
  })
85
85
  }, async ({ data, conn }) => {
86
- const project = requireProjectAccess(conn, data.projectId);
87
- const cwd = resolveRepoCwd(project.path, data.repoPath);
86
+ const { root } = requireProjectWorkspace(conn, data.projectId);
87
+ const cwd = resolveRepoCwd(root, data.repoPath);
88
88
  return await gitService.revertCommit(cwd, data.ref);
89
89
  })
90
90
 
@@ -99,8 +99,8 @@ export const commitHandler = createRouter()
99
99
  message: t.String()
100
100
  })
101
101
  }, async ({ data, conn }) => {
102
- const project = requireProjectAccess(conn, data.projectId);
103
- const cwd = resolveRepoCwd(project.path, data.repoPath);
102
+ const { root } = requireProjectWorkspace(conn, data.projectId);
103
+ const cwd = resolveRepoCwd(root, data.repoPath);
104
104
  return await gitService.cherryPick(cwd, data.hashes);
105
105
  })
106
106
 
@@ -111,8 +111,8 @@ export const commitHandler = createRouter()
111
111
  }),
112
112
  response: t.Object({ message: t.String() })
113
113
  }, async ({ data, conn }) => {
114
- const project = requireProjectAccess(conn, data.projectId);
115
- const cwd = resolveRepoCwd(project.path, data.repoPath);
114
+ const { root } = requireProjectWorkspace(conn, data.projectId);
115
+ const cwd = resolveRepoCwd(root, data.repoPath);
116
116
  const message = await gitService.cleanUntracked(cwd);
117
117
  return { message };
118
118
  })
@@ -124,8 +124,8 @@ export const commitHandler = createRouter()
124
124
  }),
125
125
  response: t.Object({ message: t.String() })
126
126
  }, async ({ data, conn }) => {
127
- const project = requireProjectAccess(conn, data.projectId);
128
- const cwd = resolveRepoCwd(project.path, data.repoPath);
127
+ const { root } = requireProjectWorkspace(conn, data.projectId);
128
+ const cwd = resolveRepoCwd(root, data.repoPath);
129
129
  const message = await gitService.optimize(cwd);
130
130
  return { message };
131
131
  })
@@ -142,7 +142,7 @@ export const commitHandler = createRouter()
142
142
  message: t.String()
143
143
  })
144
144
  }, async ({ data, conn }) => {
145
- const project = requireProjectAccess(conn, data.projectId);
146
- const cwd = resolveRepoCwd(project.path, data.repoPath);
145
+ const { root } = requireProjectWorkspace(conn, data.projectId);
146
+ const cwd = resolveRepoCwd(root, data.repoPath);
147
147
  return await gitService.npmVersion(cwd, data.bump);
148
148
  });
@@ -7,7 +7,7 @@ import path from 'node:path';
7
7
  import { createRouter } from '$shared/utils/ws-server';
8
8
  import { gitService } from '../../git/git-service';
9
9
  import { findNestedRepoPaths, findRepoForFile } from '../../git/nested-repos';
10
- import { requireProjectAccess } from '../access';
10
+ import { requireProjectWorkspace } from '../access';
11
11
  import { debug } from '$shared/utils/logger';
12
12
 
13
13
  function resolveRepoCwd(projectPath: string, repoPath: string | undefined): string | null {
@@ -45,15 +45,15 @@ export const conflictHandler = createRouter()
45
45
  markers: t.Array(ConflictMarkerSchema)
46
46
  }))
47
47
  }, async ({ data, conn }) => {
48
- const project = requireProjectAccess(conn, data.projectId);
49
- const conflicts = await gitService.getConflictFiles(project.path);
48
+ const { root } = requireProjectWorkspace(conn, data.projectId);
49
+ const conflicts = await gitService.getConflictFiles(root);
50
50
 
51
51
  try {
52
- const nestedRepoPaths = await findNestedRepoPaths(project.path);
52
+ const nestedRepoPaths = await findNestedRepoPaths(root);
53
53
  for (const repoPath of nestedRepoPaths) {
54
54
  try {
55
55
  const nestedConflicts = await gitService.getConflictFiles(repoPath);
56
- const prefix = path.relative(project.path, repoPath).replace(/\\/g, '/') + '/';
56
+ const prefix = path.relative(root, repoPath).replace(/\\/g, '/') + '/';
57
57
  for (const conflict of nestedConflicts) {
58
58
  conflicts.push({
59
59
  ...conflict,
@@ -80,9 +80,9 @@ export const conflictHandler = createRouter()
80
80
  }),
81
81
  response: t.Object({ ok: t.Boolean() })
82
82
  }, async ({ data, conn }) => {
83
- const project = requireProjectAccess(conn, data.projectId);
84
- const repo = await findRepoForFile(project.path, data.filePath);
85
- const cwd = repo?.repoPath ?? project.path;
83
+ const { root } = requireProjectWorkspace(conn, data.projectId);
84
+ const repo = await findRepoForFile(root, data.filePath);
85
+ const cwd = repo?.repoPath ?? root;
86
86
  const filePath = repo?.relativeFilePath ?? data.filePath;
87
87
  await gitService.resolveConflict(
88
88
  cwd,
@@ -100,8 +100,8 @@ export const conflictHandler = createRouter()
100
100
  }),
101
101
  response: t.Object({ ok: t.Boolean() })
102
102
  }, async ({ data, conn }) => {
103
- const project = requireProjectAccess(conn, data.projectId);
104
- const cwd = resolveRepoCwd(project.path, data.repoPath) ?? project.path;
103
+ const { root } = requireProjectWorkspace(conn, data.projectId);
104
+ const cwd = resolveRepoCwd(root, data.repoPath) ?? root;
105
105
  await gitService.abortMerge(cwd);
106
106
  return { ok: true };
107
107
  });
@@ -7,7 +7,7 @@ import path from 'node:path';
7
7
  import { createRouter } from '$shared/utils/ws-server';
8
8
  import { gitService } from '../../git/git-service';
9
9
  import { findRepoForFile } from '../../git/nested-repos';
10
- import { requireProjectAccess } from '../access';
10
+ import { requireProjectWorkspace } from '../access';
11
11
  import { debug } from '$shared/utils/logger';
12
12
 
13
13
  const DiffHunkLineSchema = t.Object({
@@ -58,14 +58,14 @@ export const diffHandler = createRouter()
58
58
  }),
59
59
  response: t.Array(FileDiffSchema)
60
60
  }, async ({ data, conn }) => {
61
- const project = requireProjectAccess(conn, data.projectId);
61
+ const { root } = requireProjectWorkspace(conn, data.projectId);
62
62
  // Route the diff to the nested repo that owns the file (if any) —
63
63
  // the outer repo's `git diff` returns nothing for files that are
64
64
  // tracked inside a nested repo and gitignored by the parent.
65
65
  const repo = data.filePath
66
- ? await findRepoForFile(project.path, data.filePath)
66
+ ? await findRepoForFile(root, data.filePath)
67
67
  : null;
68
- const cwd = repo?.repoPath ?? project.path;
68
+ const cwd = repo?.repoPath ?? root;
69
69
  const filePath = repo?.relativeFilePath ?? data.filePath;
70
70
  return await gitService.getDiffUnstaged(cwd, filePath);
71
71
  })
@@ -77,11 +77,11 @@ export const diffHandler = createRouter()
77
77
  }),
78
78
  response: t.Array(FileDiffSchema)
79
79
  }, async ({ data, conn }) => {
80
- const project = requireProjectAccess(conn, data.projectId);
80
+ const { root } = requireProjectWorkspace(conn, data.projectId);
81
81
  const repo = data.filePath
82
- ? await findRepoForFile(project.path, data.filePath)
82
+ ? await findRepoForFile(root, data.filePath)
83
83
  : null;
84
- const cwd = repo?.repoPath ?? project.path;
84
+ const cwd = repo?.repoPath ?? root;
85
85
  const filePath = repo?.relativeFilePath ?? data.filePath;
86
86
  return await gitService.getDiffStaged(cwd, filePath);
87
87
  })
@@ -98,7 +98,7 @@ export const diffHandler = createRouter()
98
98
  body: t.String()
99
99
  })
100
100
  }, async ({ data, conn }) => {
101
- const project = requireProjectAccess(conn, data.projectId);
102
- const cwd = resolveRepoCwd(project.path, data.repoPath);
101
+ const { root } = requireProjectWorkspace(conn, data.projectId);
102
+ const cwd = resolveRepoCwd(root, data.repoPath);
103
103
  return await gitService.getDiffCommit(cwd, data.commitHash);
104
104
  });