@myrialabs/clopen 0.4.35 → 0.4.37
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.
- package/backend/artifacts/sync.test.ts +63 -0
- package/backend/artifacts/sync.ts +56 -3
- package/backend/database/migrations/070_create_worktrees_table.ts +67 -0
- package/backend/database/migrations/index.ts +7 -0
- package/backend/database/queries/index.ts +1 -0
- package/backend/database/queries/session-queries.ts +50 -11
- package/backend/database/queries/worktree-queries.ts +148 -0
- package/backend/engine/adapters/opencode/server.ts +389 -83
- package/backend/engine/adapters/opencode/stream.ts +14 -14
- package/backend/engine/hot-reload.ts +25 -10
- package/backend/files/file-watcher.ts +35 -9
- package/backend/git/conflict-state.test.ts +396 -0
- package/backend/git/git-executor.ts +6 -0
- package/backend/git/git-parser.ts +144 -48
- package/backend/git/git-service.ts +727 -57
- package/backend/git/push-target.test.ts +264 -0
- package/backend/host/metrics.test.ts +110 -0
- package/backend/host/metrics.ts +235 -0
- package/backend/index.ts +5 -2
- package/backend/mcp/internal/servers/browser-automation/context.ts +16 -2
- package/backend/ports/attribute.test.ts +3 -2
- package/backend/ports/attribute.ts +5 -44
- package/backend/preview/browser/browser-pool.ts +81 -0
- package/backend/preview/browser/browser-preview-service.ts +142 -32
- package/backend/preview/browser/browser-tab-manager.ts +350 -113
- package/backend/preview/browser/types.ts +9 -0
- package/backend/project/status-manager.ts +20 -0
- package/backend/projects/project-cleanup.integration.test.ts +1 -1
- package/backend/projects/project-cleanup.ts +7 -1
- package/backend/projects/shell-ownership.ts +65 -0
- package/backend/snapshot/snapshot-service.ts +6 -2
- package/backend/terminal/ptykit.ts +35 -6
- package/backend/utils/ws.ts +21 -1
- package/backend/worktrees/clone.ts +222 -0
- package/backend/worktrees/index.ts +29 -0
- package/backend/worktrees/merge.test.ts +93 -0
- package/backend/worktrees/merge.ts +232 -0
- package/backend/worktrees/paths.test.ts +60 -0
- package/backend/worktrees/paths.ts +60 -0
- package/backend/worktrees/resolve.ts +67 -0
- package/backend/worktrees/service.ts +315 -0
- package/backend/worktrees/tree.ts +59 -0
- package/backend/ws/access.ts +18 -0
- package/backend/ws/artifacts/generate.ts +2 -2
- package/backend/ws/chat/stream.ts +9 -2
- package/backend/ws/files/panel-state-scope.test.ts +102 -0
- package/backend/ws/files/path-access.test.ts +93 -1
- package/backend/ws/files/path-access.ts +54 -5
- package/backend/ws/files/read.ts +15 -10
- package/backend/ws/files/search.ts +7 -7
- package/backend/ws/files/state.ts +70 -8
- package/backend/ws/files/watch.ts +16 -14
- package/backend/ws/git/branch-name.ts +9 -8
- package/backend/ws/git/branch.ts +58 -16
- package/backend/ws/git/commit-message.ts +16 -13
- package/backend/ws/git/commit.ts +17 -17
- package/backend/ws/git/conflict.ts +116 -13
- package/backend/ws/git/diff-budget.test.ts +125 -0
- package/backend/ws/git/diff-budget.ts +220 -0
- package/backend/ws/git/diff.ts +9 -9
- package/backend/ws/git/ignored.ts +9 -9
- package/backend/ws/git/log.ts +28 -3
- package/backend/ws/git/remote.ts +118 -44
- package/backend/ws/git/staging.ts +16 -16
- package/backend/ws/git/status.ts +13 -13
- package/backend/ws/index.ts +4 -0
- package/backend/ws/preview/access.ts +11 -3
- package/backend/ws/projects/index.ts +5 -1
- package/backend/ws/projects/info.test.ts +54 -0
- package/backend/ws/projects/info.ts +398 -0
- package/backend/ws/sessions/crud.ts +21 -6
- package/backend/ws/snapshot/restore.ts +11 -14
- package/backend/ws/system/device-info.ts +62 -144
- package/backend/ws/worktrees/crud.ts +187 -0
- package/backend/ws/worktrees/index.ts +33 -0
- package/backend/ws/worktrees/transfer.ts +88 -0
- package/dist/assets/{index-BRJqss6F.js → index-Bik9TCBi.js} +1 -1
- package/dist/assets/{index-B0iIhSO9.js → index-sJmS_CCm.js} +1 -1
- package/dist/assets/main-DLqolBI2.css +1 -0
- package/dist/assets/main-Df1I3hnw.js +1096 -0
- package/dist/index.html +2 -2
- package/package.json +1 -1
- package/shared/types/database/schema.ts +26 -0
- package/shared/types/git.ts +123 -0
- package/shared/utils/logger.ts +1 -0
- package/shared/utils/workspace-scope.test.ts +80 -0
- package/shared/utils/workspace-scope.ts +57 -0
- package/shared/utils/ws-client.ts +25 -5
- package/shared/utils/ws-server.ts +19 -3
- package/dist/assets/main-Buko4D0t.css +0 -1
- package/dist/assets/main-C_iGUZyL.js +0 -1078
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t } from 'elysia';
|
|
2
2
|
import { createRouter } from '$shared/utils/ws-server';
|
|
3
3
|
import { execGit } from '../../git/git-executor';
|
|
4
|
-
import {
|
|
4
|
+
import { requireProjectWorkspace } from '../access';
|
|
5
5
|
import path from 'path';
|
|
6
6
|
|
|
7
7
|
export const ignoredHandler = createRouter()
|
|
@@ -13,11 +13,11 @@ export const ignoredHandler = createRouter()
|
|
|
13
13
|
ignored: t.Array(t.String())
|
|
14
14
|
})
|
|
15
15
|
}, async ({ data, conn }) => {
|
|
16
|
-
const
|
|
16
|
+
const { root } = requireProjectWorkspace(conn, data.projectId);
|
|
17
17
|
const ignored: string[] = [];
|
|
18
18
|
|
|
19
19
|
try {
|
|
20
|
-
const isRepo = await execGit(['rev-parse', '--is-inside-work-tree'],
|
|
20
|
+
const isRepo = await execGit(['rev-parse', '--is-inside-work-tree'], root, 5_000)
|
|
21
21
|
.then(r => r.exitCode === 0)
|
|
22
22
|
.catch(() => false);
|
|
23
23
|
|
|
@@ -26,31 +26,31 @@ export const ignoredHandler = createRouter()
|
|
|
26
26
|
// Get ignored files (leaf paths)
|
|
27
27
|
const filesResult = await execGit(
|
|
28
28
|
['ls-files', '--others', '--ignored', '--exclude-standard'],
|
|
29
|
-
|
|
29
|
+
root,
|
|
30
30
|
30_000
|
|
31
31
|
);
|
|
32
32
|
if (filesResult.exitCode === 0) {
|
|
33
|
-
const sep =
|
|
33
|
+
const sep = root.includes('\\') ? '\\' : '/';
|
|
34
34
|
for (const line of filesResult.stdout.split('\n')) {
|
|
35
35
|
const relPath = line.trim();
|
|
36
36
|
if (!relPath) continue;
|
|
37
|
-
ignored.push(path.join(
|
|
37
|
+
ignored.push(path.join(root, relPath.replace(/\//g, sep)));
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
// Get ignored directories (shown with --directory flag)
|
|
42
42
|
const dirsResult = await execGit(
|
|
43
43
|
['ls-files', '--others', '--ignored', '--exclude-standard', '--directory'],
|
|
44
|
-
|
|
44
|
+
root,
|
|
45
45
|
30_000
|
|
46
46
|
);
|
|
47
47
|
if (dirsResult.exitCode === 0) {
|
|
48
48
|
const seen = new Set(ignored);
|
|
49
|
-
const sep =
|
|
49
|
+
const sep = root.includes('\\') ? '\\' : '/';
|
|
50
50
|
for (const line of dirsResult.stdout.split('\n')) {
|
|
51
51
|
const relPath = line.trim().replace(/\/$/, '');
|
|
52
52
|
if (!relPath) continue;
|
|
53
|
-
const absPath = path.join(
|
|
53
|
+
const absPath = path.join(root, relPath.replace(/\//g, sep));
|
|
54
54
|
if (!seen.has(absPath)) {
|
|
55
55
|
ignored.push(absPath);
|
|
56
56
|
seen.add(absPath);
|
package/backend/ws/git/log.ts
CHANGED
|
@@ -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 {
|
|
9
|
+
import { requireProjectWorkspace } from '../access';
|
|
10
10
|
import { debug } from '$shared/utils/logger';
|
|
11
11
|
|
|
12
12
|
/**
|
|
@@ -50,8 +50,8 @@ export const logHandler = createRouter()
|
|
|
50
50
|
hasMore: t.Boolean()
|
|
51
51
|
})
|
|
52
52
|
}, async ({ data, conn }) => {
|
|
53
|
-
const
|
|
54
|
-
const cwd = resolveRepoCwd(
|
|
53
|
+
const { root } = requireProjectWorkspace(conn, data.projectId);
|
|
54
|
+
const cwd = resolveRepoCwd(root, data.repoPath);
|
|
55
55
|
return await gitService.getLog(
|
|
56
56
|
cwd,
|
|
57
57
|
data.limit ?? 50,
|
|
@@ -59,4 +59,29 @@ export const logHandler = createRouter()
|
|
|
59
59
|
data.branch,
|
|
60
60
|
data.allBranches ?? false
|
|
61
61
|
);
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The repo's undo journal. Unlike `git log` this still lists commits that a
|
|
66
|
+
* reset, a branch delete or a rebase orphaned, so it is the recovery path for
|
|
67
|
+
* every destructive action the panel offers.
|
|
68
|
+
*/
|
|
69
|
+
.http('git:reflog', {
|
|
70
|
+
data: t.Object({
|
|
71
|
+
projectId: t.String(),
|
|
72
|
+
limit: t.Optional(t.Number()),
|
|
73
|
+
repoPath: t.Optional(t.String())
|
|
74
|
+
}),
|
|
75
|
+
response: t.Array(t.Object({
|
|
76
|
+
hash: t.String(),
|
|
77
|
+
hashShort: t.String(),
|
|
78
|
+
selector: t.String(),
|
|
79
|
+
action: t.String(),
|
|
80
|
+
subject: t.String(),
|
|
81
|
+
date: t.String()
|
|
82
|
+
}))
|
|
83
|
+
}, async ({ data, conn }) => {
|
|
84
|
+
const { root } = requireProjectWorkspace(conn, data.projectId);
|
|
85
|
+
const cwd = resolveRepoCwd(root, data.repoPath);
|
|
86
|
+
return await gitService.getReflog(cwd, data.limit ?? 100);
|
|
62
87
|
});
|
package/backend/ws/git/remote.ts
CHANGED
|
@@ -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 {
|
|
9
|
+
import { requireProjectWorkspace } from '../access';
|
|
10
10
|
import { debug } from '$shared/utils/logger';
|
|
11
11
|
|
|
12
12
|
/**
|
|
@@ -37,8 +37,8 @@ export const remoteHandler = createRouter()
|
|
|
37
37
|
pushUrl: t.String()
|
|
38
38
|
}))
|
|
39
39
|
}, async ({ data, conn }) => {
|
|
40
|
-
const
|
|
41
|
-
const cwd = resolveRepoCwd(
|
|
40
|
+
const { root } = requireProjectWorkspace(conn, data.projectId);
|
|
41
|
+
const cwd = resolveRepoCwd(root, data.repoPath);
|
|
42
42
|
return await gitService.getRemotes(cwd);
|
|
43
43
|
})
|
|
44
44
|
|
|
@@ -52,8 +52,8 @@ export const remoteHandler = createRouter()
|
|
|
52
52
|
message: t.String()
|
|
53
53
|
})
|
|
54
54
|
}, async ({ data, conn }) => {
|
|
55
|
-
const
|
|
56
|
-
const cwd = resolveRepoCwd(
|
|
55
|
+
const { root } = requireProjectWorkspace(conn, data.projectId);
|
|
56
|
+
const cwd = resolveRepoCwd(root, data.repoPath);
|
|
57
57
|
const message = await gitService.fetch(cwd, data.remote);
|
|
58
58
|
return { message };
|
|
59
59
|
})
|
|
@@ -71,8 +71,8 @@ export const remoteHandler = createRouter()
|
|
|
71
71
|
message: t.String()
|
|
72
72
|
})
|
|
73
73
|
}, async ({ data, conn }) => {
|
|
74
|
-
const
|
|
75
|
-
const cwd = resolveRepoCwd(
|
|
74
|
+
const { root } = requireProjectWorkspace(conn, data.projectId);
|
|
75
|
+
const cwd = resolveRepoCwd(root, data.repoPath);
|
|
76
76
|
return await gitService.pull(cwd, data.remote, data.branch, data.rebase);
|
|
77
77
|
})
|
|
78
78
|
|
|
@@ -94,8 +94,8 @@ export const remoteHandler = createRouter()
|
|
|
94
94
|
message: t.String()
|
|
95
95
|
})
|
|
96
96
|
}, async ({ data, conn }) => {
|
|
97
|
-
const
|
|
98
|
-
const cwd = resolveRepoCwd(
|
|
97
|
+
const { root } = requireProjectWorkspace(conn, data.projectId);
|
|
98
|
+
const cwd = resolveRepoCwd(root, data.repoPath);
|
|
99
99
|
return await gitService.pushAdvanced(cwd, data.mode, data.remote, data.branch);
|
|
100
100
|
})
|
|
101
101
|
|
|
@@ -108,8 +108,8 @@ export const remoteHandler = createRouter()
|
|
|
108
108
|
message: t.String()
|
|
109
109
|
})
|
|
110
110
|
}, async ({ data, conn }) => {
|
|
111
|
-
const
|
|
112
|
-
const cwd = resolveRepoCwd(
|
|
111
|
+
const { root } = requireProjectWorkspace(conn, data.projectId);
|
|
112
|
+
const cwd = resolveRepoCwd(root, data.repoPath);
|
|
113
113
|
const message = await gitService.fetchAll(cwd);
|
|
114
114
|
return { message };
|
|
115
115
|
})
|
|
@@ -120,6 +120,11 @@ export const remoteHandler = createRouter()
|
|
|
120
120
|
remote: t.Optional(t.String()),
|
|
121
121
|
branch: t.Optional(t.String()),
|
|
122
122
|
force: t.Optional(t.Boolean()),
|
|
123
|
+
/**
|
|
124
|
+
* Follow the branch's own upstream instead of `remote`. Default true —
|
|
125
|
+
* only set false for a deliberate "push this somewhere else" action.
|
|
126
|
+
*/
|
|
127
|
+
useUpstream: t.Optional(t.Boolean()),
|
|
123
128
|
repoPath: t.Optional(t.String())
|
|
124
129
|
}),
|
|
125
130
|
response: t.Object({
|
|
@@ -127,9 +132,61 @@ export const remoteHandler = createRouter()
|
|
|
127
132
|
message: t.String()
|
|
128
133
|
})
|
|
129
134
|
}, async ({ data, conn }) => {
|
|
130
|
-
const
|
|
131
|
-
const cwd = resolveRepoCwd(
|
|
132
|
-
return await gitService.push(cwd, data.remote, data.branch, data.force
|
|
135
|
+
const { root } = requireProjectWorkspace(conn, data.projectId);
|
|
136
|
+
const cwd = resolveRepoCwd(root, data.repoPath);
|
|
137
|
+
return await gitService.push(cwd, data.remote, data.branch, data.force, {
|
|
138
|
+
useUpstream: data.useUpstream ?? true
|
|
139
|
+
});
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
/** Where a push would actually land — drives the Push button's label. */
|
|
143
|
+
.http('git:push-target', {
|
|
144
|
+
data: t.Object({
|
|
145
|
+
projectId: t.String(),
|
|
146
|
+
branch: t.Optional(t.String()),
|
|
147
|
+
repoPath: t.Optional(t.String())
|
|
148
|
+
}),
|
|
149
|
+
response: t.Object({
|
|
150
|
+
remote: t.String(),
|
|
151
|
+
remoteBranch: t.String(),
|
|
152
|
+
hasUpstream: t.Boolean(),
|
|
153
|
+
isUrl: t.Boolean(),
|
|
154
|
+
branch: t.String()
|
|
155
|
+
})
|
|
156
|
+
}, async ({ data, conn }) => {
|
|
157
|
+
const { root } = requireProjectWorkspace(conn, data.projectId);
|
|
158
|
+
const cwd = resolveRepoCwd(root, data.repoPath);
|
|
159
|
+
return await gitService.getPushTarget(cwd, data.branch);
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
.http('git:set-upstream', {
|
|
163
|
+
data: t.Object({
|
|
164
|
+
projectId: t.String(),
|
|
165
|
+
branch: t.String({ minLength: 1 }),
|
|
166
|
+
remote: t.String({ minLength: 1 }),
|
|
167
|
+
remoteBranch: t.Optional(t.String()),
|
|
168
|
+
repoPath: t.Optional(t.String())
|
|
169
|
+
}),
|
|
170
|
+
response: t.Object({ ok: t.Boolean() })
|
|
171
|
+
}, async ({ data, conn }) => {
|
|
172
|
+
const { root } = requireProjectWorkspace(conn, data.projectId);
|
|
173
|
+
const cwd = resolveRepoCwd(root, data.repoPath);
|
|
174
|
+
await gitService.setUpstream(cwd, data.branch, data.remote, data.remoteBranch);
|
|
175
|
+
return { ok: true };
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
.http('git:unset-upstream', {
|
|
179
|
+
data: t.Object({
|
|
180
|
+
projectId: t.String(),
|
|
181
|
+
branch: t.String({ minLength: 1 }),
|
|
182
|
+
repoPath: t.Optional(t.String())
|
|
183
|
+
}),
|
|
184
|
+
response: t.Object({ ok: t.Boolean() })
|
|
185
|
+
}, async ({ data, conn }) => {
|
|
186
|
+
const { root } = requireProjectWorkspace(conn, data.projectId);
|
|
187
|
+
const cwd = resolveRepoCwd(root, data.repoPath);
|
|
188
|
+
await gitService.unsetUpstream(cwd, data.branch);
|
|
189
|
+
return { ok: true };
|
|
133
190
|
})
|
|
134
191
|
|
|
135
192
|
.http('git:add-remote', {
|
|
@@ -141,8 +198,8 @@ export const remoteHandler = createRouter()
|
|
|
141
198
|
}),
|
|
142
199
|
response: t.Object({ ok: t.Boolean() })
|
|
143
200
|
}, async ({ data, conn }) => {
|
|
144
|
-
const
|
|
145
|
-
const cwd = resolveRepoCwd(
|
|
201
|
+
const { root } = requireProjectWorkspace(conn, data.projectId);
|
|
202
|
+
const cwd = resolveRepoCwd(root, data.repoPath);
|
|
146
203
|
await gitService.addRemote(cwd, data.name, data.url);
|
|
147
204
|
return { ok: true };
|
|
148
205
|
})
|
|
@@ -156,8 +213,8 @@ export const remoteHandler = createRouter()
|
|
|
156
213
|
}),
|
|
157
214
|
response: t.Object({ ok: t.Boolean() })
|
|
158
215
|
}, async ({ data, conn }) => {
|
|
159
|
-
const
|
|
160
|
-
const cwd = resolveRepoCwd(
|
|
216
|
+
const { root } = requireProjectWorkspace(conn, data.projectId);
|
|
217
|
+
const cwd = resolveRepoCwd(root, data.repoPath);
|
|
161
218
|
await gitService.setRemoteUrl(cwd, data.name, data.url);
|
|
162
219
|
return { ok: true };
|
|
163
220
|
})
|
|
@@ -171,8 +228,8 @@ export const remoteHandler = createRouter()
|
|
|
171
228
|
}),
|
|
172
229
|
response: t.Object({ ok: t.Boolean() })
|
|
173
230
|
}, async ({ data, conn }) => {
|
|
174
|
-
const
|
|
175
|
-
const cwd = resolveRepoCwd(
|
|
231
|
+
const { root } = requireProjectWorkspace(conn, data.projectId);
|
|
232
|
+
const cwd = resolveRepoCwd(root, data.repoPath);
|
|
176
233
|
await gitService.renameRemote(cwd, data.oldName, data.newName);
|
|
177
234
|
return { ok: true };
|
|
178
235
|
})
|
|
@@ -187,8 +244,8 @@ export const remoteHandler = createRouter()
|
|
|
187
244
|
}),
|
|
188
245
|
response: t.Object({ ok: t.Boolean() })
|
|
189
246
|
}, async ({ data, conn }) => {
|
|
190
|
-
const
|
|
191
|
-
const cwd = resolveRepoCwd(
|
|
247
|
+
const { root } = requireProjectWorkspace(conn, data.projectId);
|
|
248
|
+
const cwd = resolveRepoCwd(root, data.repoPath);
|
|
192
249
|
if (data.oldName !== data.newName) {
|
|
193
250
|
await gitService.renameRemote(cwd, data.oldName, data.newName);
|
|
194
251
|
}
|
|
@@ -204,8 +261,8 @@ export const remoteHandler = createRouter()
|
|
|
204
261
|
}),
|
|
205
262
|
response: t.Object({ ok: t.Boolean() })
|
|
206
263
|
}, async ({ data, conn }) => {
|
|
207
|
-
const
|
|
208
|
-
const cwd = resolveRepoCwd(
|
|
264
|
+
const { root } = requireProjectWorkspace(conn, data.projectId);
|
|
265
|
+
const cwd = resolveRepoCwd(root, data.repoPath);
|
|
209
266
|
await gitService.removeRemote(cwd, data.name);
|
|
210
267
|
return { ok: true };
|
|
211
268
|
})
|
|
@@ -219,8 +276,8 @@ export const remoteHandler = createRouter()
|
|
|
219
276
|
}),
|
|
220
277
|
response: t.Object({ ok: t.Boolean() })
|
|
221
278
|
}, async ({ data, conn }) => {
|
|
222
|
-
const
|
|
223
|
-
const cwd = resolveRepoCwd(
|
|
279
|
+
const { root } = requireProjectWorkspace(conn, data.projectId);
|
|
280
|
+
const cwd = resolveRepoCwd(root, data.repoPath);
|
|
224
281
|
await gitService.deleteRemoteBranch(cwd, data.remote, data.branch);
|
|
225
282
|
return { ok: true };
|
|
226
283
|
})
|
|
@@ -236,8 +293,8 @@ export const remoteHandler = createRouter()
|
|
|
236
293
|
date: t.String()
|
|
237
294
|
}))
|
|
238
295
|
}, async ({ data, conn }) => {
|
|
239
|
-
const
|
|
240
|
-
const cwd = resolveRepoCwd(
|
|
296
|
+
const { root } = requireProjectWorkspace(conn, data.projectId);
|
|
297
|
+
const cwd = resolveRepoCwd(root, data.repoPath);
|
|
241
298
|
return await gitService.stashList(cwd);
|
|
242
299
|
})
|
|
243
300
|
|
|
@@ -250,8 +307,8 @@ export const remoteHandler = createRouter()
|
|
|
250
307
|
}),
|
|
251
308
|
response: t.Object({ ok: t.Boolean() })
|
|
252
309
|
}, async ({ data, conn }) => {
|
|
253
|
-
const
|
|
254
|
-
const cwd = resolveRepoCwd(
|
|
310
|
+
const { root } = requireProjectWorkspace(conn, data.projectId);
|
|
311
|
+
const cwd = resolveRepoCwd(root, data.repoPath);
|
|
255
312
|
await gitService.stashSave(cwd, data.message, data.staged);
|
|
256
313
|
return { ok: true };
|
|
257
314
|
})
|
|
@@ -268,11 +325,28 @@ export const remoteHandler = createRouter()
|
|
|
268
325
|
message: t.String()
|
|
269
326
|
})
|
|
270
327
|
}, async ({ data, conn }) => {
|
|
271
|
-
const
|
|
272
|
-
const cwd = resolveRepoCwd(
|
|
328
|
+
const { root } = requireProjectWorkspace(conn, data.projectId);
|
|
329
|
+
const cwd = resolveRepoCwd(root, data.repoPath);
|
|
273
330
|
return await gitService.stashPop(cwd, data.index);
|
|
274
331
|
})
|
|
275
332
|
|
|
333
|
+
.http('git:stash-apply', {
|
|
334
|
+
data: t.Object({
|
|
335
|
+
projectId: t.String(),
|
|
336
|
+
index: t.Optional(t.Number()),
|
|
337
|
+
repoPath: t.Optional(t.String())
|
|
338
|
+
}),
|
|
339
|
+
response: t.Object({
|
|
340
|
+
success: t.Boolean(),
|
|
341
|
+
hasConflicts: t.Boolean(),
|
|
342
|
+
message: t.String()
|
|
343
|
+
})
|
|
344
|
+
}, async ({ data, conn }) => {
|
|
345
|
+
const { root } = requireProjectWorkspace(conn, data.projectId);
|
|
346
|
+
const cwd = resolveRepoCwd(root, data.repoPath);
|
|
347
|
+
return await gitService.stashApply(cwd, data.index);
|
|
348
|
+
})
|
|
349
|
+
|
|
276
350
|
.http('git:stash-drop', {
|
|
277
351
|
data: t.Object({
|
|
278
352
|
projectId: t.String(),
|
|
@@ -281,8 +355,8 @@ export const remoteHandler = createRouter()
|
|
|
281
355
|
}),
|
|
282
356
|
response: t.Object({ ok: t.Boolean() })
|
|
283
357
|
}, async ({ data, conn }) => {
|
|
284
|
-
const
|
|
285
|
-
const cwd = resolveRepoCwd(
|
|
358
|
+
const { root } = requireProjectWorkspace(conn, data.projectId);
|
|
359
|
+
const cwd = resolveRepoCwd(root, data.repoPath);
|
|
286
360
|
await gitService.stashDrop(cwd, data.index);
|
|
287
361
|
return { ok: true };
|
|
288
362
|
})
|
|
@@ -313,8 +387,8 @@ export const remoteHandler = createRouter()
|
|
|
313
387
|
isBinary: t.Boolean()
|
|
314
388
|
}))
|
|
315
389
|
}, async ({ data, conn }) => {
|
|
316
|
-
const
|
|
317
|
-
const cwd = resolveRepoCwd(
|
|
390
|
+
const { root } = requireProjectWorkspace(conn, data.projectId);
|
|
391
|
+
const cwd = resolveRepoCwd(root, data.repoPath);
|
|
318
392
|
return await gitService.stashDiff(cwd, data.index);
|
|
319
393
|
})
|
|
320
394
|
|
|
@@ -331,8 +405,8 @@ export const remoteHandler = createRouter()
|
|
|
331
405
|
isAnnotated: t.Boolean()
|
|
332
406
|
}))
|
|
333
407
|
}, async ({ data, conn }) => {
|
|
334
|
-
const
|
|
335
|
-
const cwd = resolveRepoCwd(
|
|
408
|
+
const { root } = requireProjectWorkspace(conn, data.projectId);
|
|
409
|
+
const cwd = resolveRepoCwd(root, data.repoPath);
|
|
336
410
|
return await gitService.getTags(cwd);
|
|
337
411
|
})
|
|
338
412
|
|
|
@@ -346,8 +420,8 @@ export const remoteHandler = createRouter()
|
|
|
346
420
|
}),
|
|
347
421
|
response: t.Object({ ok: t.Boolean() })
|
|
348
422
|
}, async ({ data, conn }) => {
|
|
349
|
-
const
|
|
350
|
-
const cwd = resolveRepoCwd(
|
|
423
|
+
const { root } = requireProjectWorkspace(conn, data.projectId);
|
|
424
|
+
const cwd = resolveRepoCwd(root, data.repoPath);
|
|
351
425
|
await gitService.createTag(cwd, data.name, data.message, data.commitHash);
|
|
352
426
|
return { ok: true };
|
|
353
427
|
})
|
|
@@ -360,8 +434,8 @@ export const remoteHandler = createRouter()
|
|
|
360
434
|
}),
|
|
361
435
|
response: t.Object({ ok: t.Boolean() })
|
|
362
436
|
}, async ({ data, conn }) => {
|
|
363
|
-
const
|
|
364
|
-
const cwd = resolveRepoCwd(
|
|
437
|
+
const { root } = requireProjectWorkspace(conn, data.projectId);
|
|
438
|
+
const cwd = resolveRepoCwd(root, data.repoPath);
|
|
365
439
|
await gitService.deleteTag(cwd, data.name);
|
|
366
440
|
return { ok: true };
|
|
367
441
|
})
|
|
@@ -378,7 +452,7 @@ export const remoteHandler = createRouter()
|
|
|
378
452
|
message: t.String()
|
|
379
453
|
})
|
|
380
454
|
}, async ({ data, conn }) => {
|
|
381
|
-
const
|
|
382
|
-
const cwd = resolveRepoCwd(
|
|
455
|
+
const { root } = requireProjectWorkspace(conn, data.projectId);
|
|
456
|
+
const cwd = resolveRepoCwd(root, data.repoPath);
|
|
383
457
|
return await gitService.pushTag(cwd, data.name, data.remote);
|
|
384
458
|
});
|
|
@@ -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 {
|
|
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 {
|
|
@@ -30,9 +30,9 @@ export const stagingHandler = createRouter()
|
|
|
30
30
|
}),
|
|
31
31
|
response: t.Object({ ok: t.Boolean() })
|
|
32
32
|
}, async ({ data, conn }) => {
|
|
33
|
-
const
|
|
34
|
-
const repo = await findRepoForFile(
|
|
35
|
-
const cwd = repo?.repoPath ??
|
|
33
|
+
const { root } = requireProjectWorkspace(conn, data.projectId);
|
|
34
|
+
const repo = await findRepoForFile(root, data.filePath);
|
|
35
|
+
const cwd = repo?.repoPath ?? root;
|
|
36
36
|
const filePath = repo?.relativeFilePath ?? data.filePath;
|
|
37
37
|
await gitService.stageFile(cwd, filePath);
|
|
38
38
|
return { ok: true };
|
|
@@ -45,8 +45,8 @@ export const stagingHandler = createRouter()
|
|
|
45
45
|
}),
|
|
46
46
|
response: t.Object({ ok: t.Boolean() })
|
|
47
47
|
}, async ({ data, conn }) => {
|
|
48
|
-
const
|
|
49
|
-
const cwd = data.repoPath ? (resolveRepoCwd(
|
|
48
|
+
const { root } = requireProjectWorkspace(conn, data.projectId);
|
|
49
|
+
const cwd = data.repoPath ? (resolveRepoCwd(root, data.repoPath) ?? root) : root;
|
|
50
50
|
await gitService.stageAll(cwd);
|
|
51
51
|
return { ok: true };
|
|
52
52
|
})
|
|
@@ -58,9 +58,9 @@ export const stagingHandler = createRouter()
|
|
|
58
58
|
}),
|
|
59
59
|
response: t.Object({ ok: t.Boolean() })
|
|
60
60
|
}, async ({ data, conn }) => {
|
|
61
|
-
const
|
|
62
|
-
const repo = await findRepoForFile(
|
|
63
|
-
const cwd = repo?.repoPath ??
|
|
61
|
+
const { root } = requireProjectWorkspace(conn, data.projectId);
|
|
62
|
+
const repo = await findRepoForFile(root, data.filePath);
|
|
63
|
+
const cwd = repo?.repoPath ?? root;
|
|
64
64
|
const filePath = repo?.relativeFilePath ?? data.filePath;
|
|
65
65
|
await gitService.unstageFile(cwd, filePath);
|
|
66
66
|
return { ok: true };
|
|
@@ -73,8 +73,8 @@ export const stagingHandler = createRouter()
|
|
|
73
73
|
}),
|
|
74
74
|
response: t.Object({ ok: t.Boolean() })
|
|
75
75
|
}, async ({ data, conn }) => {
|
|
76
|
-
const
|
|
77
|
-
const cwd = data.repoPath ? (resolveRepoCwd(
|
|
76
|
+
const { root } = requireProjectWorkspace(conn, data.projectId);
|
|
77
|
+
const cwd = data.repoPath ? (resolveRepoCwd(root, data.repoPath) ?? root) : root;
|
|
78
78
|
await gitService.unstageAll(cwd);
|
|
79
79
|
return { ok: true };
|
|
80
80
|
})
|
|
@@ -86,9 +86,9 @@ export const stagingHandler = createRouter()
|
|
|
86
86
|
}),
|
|
87
87
|
response: t.Object({ ok: t.Boolean() })
|
|
88
88
|
}, async ({ data, conn }) => {
|
|
89
|
-
const
|
|
90
|
-
const repo = await findRepoForFile(
|
|
91
|
-
const cwd = repo?.repoPath ??
|
|
89
|
+
const { root } = requireProjectWorkspace(conn, data.projectId);
|
|
90
|
+
const repo = await findRepoForFile(root, data.filePath);
|
|
91
|
+
const cwd = repo?.repoPath ?? root;
|
|
92
92
|
const filePath = repo?.relativeFilePath ?? data.filePath;
|
|
93
93
|
await gitService.discardFile(cwd, filePath);
|
|
94
94
|
return { ok: true };
|
|
@@ -101,8 +101,8 @@ export const stagingHandler = createRouter()
|
|
|
101
101
|
}),
|
|
102
102
|
response: t.Object({ ok: t.Boolean() })
|
|
103
103
|
}, async ({ data, conn }) => {
|
|
104
|
-
const
|
|
105
|
-
const cwd = data.repoPath ? (resolveRepoCwd(
|
|
104
|
+
const { root } = requireProjectWorkspace(conn, data.projectId);
|
|
105
|
+
const cwd = data.repoPath ? (resolveRepoCwd(root, data.repoPath) ?? root) : root;
|
|
106
106
|
await gitService.discardAll(cwd);
|
|
107
107
|
return { ok: true };
|
|
108
108
|
});
|
package/backend/ws/git/status.ts
CHANGED
|
@@ -6,7 +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 {
|
|
9
|
+
import { requireProjectWorkspace } from '../access';
|
|
10
10
|
import { relative as pathRelative } from 'path';
|
|
11
11
|
|
|
12
12
|
export const statusHandler = createRouter()
|
|
@@ -42,9 +42,9 @@ export const statusHandler = createRouter()
|
|
|
42
42
|
}))
|
|
43
43
|
})
|
|
44
44
|
}, async ({ data, conn }) => {
|
|
45
|
-
const
|
|
45
|
+
const { root } = requireProjectWorkspace(conn, data.projectId);
|
|
46
46
|
|
|
47
|
-
const isRepo = await gitService.isRepo(
|
|
47
|
+
const isRepo = await gitService.isRepo(root);
|
|
48
48
|
if (!isRepo) {
|
|
49
49
|
return {
|
|
50
50
|
isRepo: false,
|
|
@@ -61,14 +61,14 @@ export const statusHandler = createRouter()
|
|
|
61
61
|
// findNestedRepoPaths cache + inflight dedup also keeps concurrent
|
|
62
62
|
// callers (status + branches triggered together) from walking twice.
|
|
63
63
|
const [status, nestedRepoPaths] = await Promise.all([
|
|
64
|
-
gitService.getStatus(
|
|
64
|
+
gitService.getStatus(root),
|
|
65
65
|
// Discovery failing must not cost the user the outer repo's status.
|
|
66
|
-
findNestedRepoPaths(
|
|
66
|
+
findNestedRepoPaths(root).catch(() => [] as string[])
|
|
67
67
|
]);
|
|
68
68
|
|
|
69
69
|
if (nestedRepoPaths.length > 0) {
|
|
70
70
|
const nestedPrefixes = nestedRepoPaths.map(
|
|
71
|
-
(repoPath) => pathRelative(
|
|
71
|
+
(repoPath) => pathRelative(root, repoPath).replace(/\\/g, '/') + '/'
|
|
72
72
|
);
|
|
73
73
|
|
|
74
74
|
// Drop outer-repo entries that fall under a nested repo's prefix.
|
|
@@ -103,7 +103,7 @@ export const statusHandler = createRouter()
|
|
|
103
103
|
|
|
104
104
|
for (const entry of nestedStatuses) {
|
|
105
105
|
if (!entry) continue;
|
|
106
|
-
const prefix = pathRelative(
|
|
106
|
+
const prefix = pathRelative(root, entry.repoPath).replace(/\\/g, '/') + '/';
|
|
107
107
|
const withPrefix = (f: typeof entry.nestedStatus.staged[number]) => ({
|
|
108
108
|
...f,
|
|
109
109
|
path: prefix + f.path,
|
|
@@ -126,8 +126,8 @@ export const statusHandler = createRouter()
|
|
|
126
126
|
}),
|
|
127
127
|
response: t.Object({ ok: t.Boolean() })
|
|
128
128
|
}, async ({ data, conn }) => {
|
|
129
|
-
const
|
|
130
|
-
await gitService.init(
|
|
129
|
+
const { root } = requireProjectWorkspace(conn, data.projectId);
|
|
130
|
+
await gitService.init(root, data.defaultBranch);
|
|
131
131
|
return { ok: true };
|
|
132
132
|
})
|
|
133
133
|
|
|
@@ -140,9 +140,9 @@ export const statusHandler = createRouter()
|
|
|
140
140
|
root: t.Optional(t.String())
|
|
141
141
|
})
|
|
142
142
|
}, async ({ data, conn }) => {
|
|
143
|
-
const
|
|
143
|
+
const { root } = requireProjectWorkspace(conn, data.projectId);
|
|
144
144
|
|
|
145
|
-
const isRepo = await gitService.isRepo(
|
|
146
|
-
const
|
|
147
|
-
return { isRepo, root:
|
|
145
|
+
const isRepo = await gitService.isRepo(root);
|
|
146
|
+
const repoRoot = isRepo ? await gitService.getRoot(root) : undefined;
|
|
147
|
+
return { isRepo, root: repoRoot ?? undefined };
|
|
148
148
|
});
|
package/backend/ws/index.ts
CHANGED
|
@@ -43,6 +43,7 @@ import { permissionsRouter } from './permissions';
|
|
|
43
43
|
import { profilesRouter } from './profiles';
|
|
44
44
|
import { artifactsRouter } from './artifacts';
|
|
45
45
|
import { memoryRouter } from './memory';
|
|
46
|
+
import { worktreesRouter } from './worktrees';
|
|
46
47
|
|
|
47
48
|
// ============================================
|
|
48
49
|
// Main App Router - Merge All Module Routers
|
|
@@ -64,6 +65,9 @@ export const wsRouter = createRouter()
|
|
|
64
65
|
// Snapshot System
|
|
65
66
|
.merge(snapshotRouter)
|
|
66
67
|
|
|
68
|
+
// Worktrees (isolated project copies)
|
|
69
|
+
.merge(worktreesRouter)
|
|
70
|
+
|
|
67
71
|
// CRUD Operations
|
|
68
72
|
.merge(projectsRouter)
|
|
69
73
|
.merge(sessionsRouter)
|
|
@@ -12,6 +12,7 @@ import type { WSConnection } from '$shared/utils/ws-server';
|
|
|
12
12
|
import { ws } from '$backend/utils/ws';
|
|
13
13
|
import { requireCurrentProjectAccess, requireProjectAccess } from '../access';
|
|
14
14
|
import { browserPreviewServiceManager } from '../../preview/index';
|
|
15
|
+
import { makeScopeKey, scopeProjectId } from '$shared/utils/workspace-scope';
|
|
15
16
|
|
|
16
17
|
type PreviewService = ReturnType<typeof browserPreviewServiceManager.getService>;
|
|
17
18
|
type Tab = NonNullable<ReturnType<PreviewService['getActiveTab']>>;
|
|
@@ -24,7 +25,11 @@ export interface BrowserPreviewContext {
|
|
|
24
25
|
|
|
25
26
|
export function requireBrowserPreviewAccess(conn: WSConnection): BrowserPreviewContext {
|
|
26
27
|
const { userId, projectId } = requireCurrentProjectAccess(conn);
|
|
27
|
-
|
|
28
|
+
// Tabs are scoped to the tree being viewed, so a worktree's preview never
|
|
29
|
+
// shows the main project's pages.
|
|
30
|
+
const previewService = browserPreviewServiceManager.getService(
|
|
31
|
+
makeScopeKey(projectId, ws.getWorktreeId(conn))
|
|
32
|
+
);
|
|
28
33
|
return { userId, projectId, previewService };
|
|
29
34
|
}
|
|
30
35
|
|
|
@@ -38,11 +43,14 @@ export function requireBrowserPreviewAccess(conn: WSConnection): BrowserPreviewC
|
|
|
38
43
|
*/
|
|
39
44
|
export function requireBrowserPreviewAccessFor(
|
|
40
45
|
conn: WSConnection,
|
|
41
|
-
|
|
46
|
+
scopeKey: string
|
|
42
47
|
): BrowserPreviewContext {
|
|
48
|
+
// The caller passes a workspace scope key; membership is always decided on
|
|
49
|
+
// the project it belongs to.
|
|
50
|
+
const projectId = scopeProjectId(scopeKey);
|
|
43
51
|
requireProjectAccess(conn, projectId); // throws if the caller isn't a member
|
|
44
52
|
const userId = ws.getUserId(conn);
|
|
45
|
-
const previewService = browserPreviewServiceManager.getService(
|
|
53
|
+
const previewService = browserPreviewServiceManager.getService(scopeKey);
|
|
46
54
|
return { userId, projectId, previewService };
|
|
47
55
|
}
|
|
48
56
|
|
|
@@ -13,6 +13,7 @@ import { createRouter } from '$shared/utils/ws-server';
|
|
|
13
13
|
import { crudHandler } from './crud';
|
|
14
14
|
import { statusHandler } from './status';
|
|
15
15
|
import { presenceHandler } from './presence';
|
|
16
|
+
import { infoHandler } from './info';
|
|
16
17
|
|
|
17
18
|
export const projectsRouter = createRouter()
|
|
18
19
|
// CRUD Operations (HTTP)
|
|
@@ -22,4 +23,7 @@ export const projectsRouter = createRouter()
|
|
|
22
23
|
.merge(statusHandler)
|
|
23
24
|
|
|
24
25
|
// Presence Management (HTTP + Broadcast)
|
|
25
|
-
.merge(presenceHandler)
|
|
26
|
+
.merge(presenceHandler)
|
|
27
|
+
|
|
28
|
+
// Per-project resource info (storage + process-isolated CPU/RAM)
|
|
29
|
+
.merge(infoHandler);
|