@myrialabs/clopen 0.4.4 → 0.4.6
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/auth/permissions.ts +15 -1
- package/backend/database/migrations/044_create_skills_table.ts +29 -0
- package/backend/database/migrations/index.ts +7 -0
- package/backend/database/queries/index.ts +3 -1
- package/backend/database/queries/skill-queries.ts +105 -0
- package/backend/engine/adapters/claude/stream.ts +5 -0
- package/backend/engine/adapters/codex/credential.ts +120 -13
- package/backend/engine/adapters/codex/stream.ts +34 -8
- package/backend/engine/adapters/copilot/stream.ts +4 -0
- package/backend/engine/adapters/opencode/stream.ts +4 -0
- package/backend/engine/adapters/qwen/stream.ts +3 -0
- package/backend/engine/docs/lessons-learned.md +54 -50
- package/backend/git/git-service.ts +40 -0
- package/backend/index.ts +10 -1
- package/backend/mcp/README.md +77 -24
- package/backend/mcp/external/config.ts +82 -101
- package/backend/mcp/external/parse.test.ts +190 -0
- package/backend/mcp/external/parse.ts +293 -0
- package/backend/mcp/external/proxy.ts +202 -0
- package/backend/mcp/index.ts +6 -3
- package/backend/mcp/internal/remote-server.ts +103 -55
- package/backend/skills/index.ts +21 -0
- package/backend/skills/marketplace.ts +172 -0
- package/backend/skills/service.ts +245 -0
- package/backend/skills/spec.ts +214 -0
- package/backend/skills/store.ts +99 -0
- package/backend/skills/sync.ts +187 -0
- package/backend/snapshot/gitignore.ts +230 -7
- package/backend/snapshot/helpers.ts +34 -10
- package/backend/ws/files/read.ts +10 -1
- package/backend/ws/git/branch-name.ts +20 -4
- package/backend/ws/git/branch.ts +66 -11
- package/backend/ws/git/commit-message.ts +18 -3
- package/backend/ws/git/commit.ts +50 -16
- package/backend/ws/git/conflict.ts +47 -5
- package/backend/ws/git/diff.ts +38 -4
- package/backend/ws/git/log.ts +22 -2
- package/backend/ws/git/remote.ts +82 -33
- package/backend/ws/git/staging.ts +39 -9
- package/backend/ws/git/status.ts +52 -0
- package/backend/ws/index.ts +5 -1
- package/backend/ws/mcp/crud.ts +30 -1
- package/backend/ws/skills/catalog.ts +79 -0
- package/backend/ws/skills/crud.ts +123 -0
- package/backend/ws/skills/index.ts +15 -0
- package/backend/ws/snapshot/timeline.ts +1 -1
- package/dist/assets/main-BkMrek4_.css +1 -0
- package/dist/assets/{main-AqTMkV9D.js → main-TYNK6Orl.js} +332 -295
- package/dist/index.html +2 -2
- package/package.json +1 -1
- package/shared/types/git.ts +20 -0
- package/shared/utils/logger.ts +1 -0
- package/dist/assets/main-DJf71Zum.css +0 -1
package/backend/ws/git/branch.ts
CHANGED
|
@@ -3,9 +3,11 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import { t } from 'elysia';
|
|
6
|
+
import path from 'node:path';
|
|
6
7
|
import { createRouter } from '$shared/utils/ws-server';
|
|
7
8
|
import { gitService } from '../../git/git-service';
|
|
8
9
|
import { requireProjectAccess } from '../access';
|
|
10
|
+
import { debug } from '$shared/utils/logger';
|
|
9
11
|
|
|
10
12
|
const BranchSchema = t.Object({
|
|
11
13
|
name: t.String(),
|
|
@@ -17,6 +19,42 @@ const BranchSchema = t.Object({
|
|
|
17
19
|
lastCommit: t.Optional(t.String())
|
|
18
20
|
});
|
|
19
21
|
|
|
22
|
+
/** Subset of GitNestedRepoInfo we expose to the client (mirrors shared type). */
|
|
23
|
+
const NestedRepoInfoSchema = t.Object({
|
|
24
|
+
path: t.String(),
|
|
25
|
+
relPath: t.String(),
|
|
26
|
+
isSubmodule: t.Boolean(),
|
|
27
|
+
info: t.Object({
|
|
28
|
+
current: t.String(),
|
|
29
|
+
local: t.Array(BranchSchema),
|
|
30
|
+
remote: t.Array(BranchSchema),
|
|
31
|
+
ahead: t.Number(),
|
|
32
|
+
behind: t.Number(),
|
|
33
|
+
detached: t.Optional(t.Boolean()),
|
|
34
|
+
operation: t.Optional(t.Union([t.String(), t.Null()]))
|
|
35
|
+
}),
|
|
36
|
+
error: t.Optional(t.String())
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Resolve the working directory for a git operation. Defaults to the project
|
|
41
|
+
* root; when `repoPath` is provided it must already be inside the project
|
|
42
|
+
* (these paths come from the backend's own `getBranches` response, but we
|
|
43
|
+
* re-validate to defend against a tampered/mismatched client).
|
|
44
|
+
*/
|
|
45
|
+
function resolveRepoCwd(projectPath: string, repoPath: string | undefined): string {
|
|
46
|
+
if (!repoPath) return projectPath;
|
|
47
|
+
const resolved = path.resolve(repoPath);
|
|
48
|
+
const projectRoot = path.resolve(projectPath);
|
|
49
|
+
const sep = path.sep;
|
|
50
|
+
// Must equal project root or live strictly inside it — no `..` escape.
|
|
51
|
+
if (resolved !== projectRoot && !resolved.startsWith(projectRoot + sep)) {
|
|
52
|
+
debug.warn('git', `Rejected nested repoPath outside project: ${resolved}`);
|
|
53
|
+
return projectPath;
|
|
54
|
+
}
|
|
55
|
+
return resolved;
|
|
56
|
+
}
|
|
57
|
+
|
|
20
58
|
export const branchHandler = createRouter()
|
|
21
59
|
.http('git:branches', {
|
|
22
60
|
data: t.Object({
|
|
@@ -28,7 +66,10 @@ export const branchHandler = createRouter()
|
|
|
28
66
|
local: t.Array(BranchSchema),
|
|
29
67
|
remote: t.Array(BranchSchema),
|
|
30
68
|
ahead: t.Number(),
|
|
31
|
-
behind: t.Number()
|
|
69
|
+
behind: t.Number(),
|
|
70
|
+
detached: t.Optional(t.Boolean()),
|
|
71
|
+
operation: t.Optional(t.Union([t.String(), t.Null()])),
|
|
72
|
+
nested: t.Optional(t.Array(NestedRepoInfoSchema))
|
|
32
73
|
})
|
|
33
74
|
}, async ({ data, conn }) => {
|
|
34
75
|
const project = requireProjectAccess(conn, data.projectId);
|
|
@@ -39,36 +80,45 @@ export const branchHandler = createRouter()
|
|
|
39
80
|
data: t.Object({
|
|
40
81
|
projectId: t.String(),
|
|
41
82
|
name: t.String({ minLength: 1 }),
|
|
42
|
-
startPoint: t.Optional(t.String())
|
|
83
|
+
startPoint: t.Optional(t.String()),
|
|
84
|
+
/** Absolute path of a nested repo inside the project (e.g. "packages/web").
|
|
85
|
+
* Defaults to the outer repo when omitted. */
|
|
86
|
+
repoPath: t.Optional(t.String())
|
|
43
87
|
}),
|
|
44
88
|
response: t.Object({ ok: t.Boolean() })
|
|
45
89
|
}, async ({ data, conn }) => {
|
|
46
90
|
const project = requireProjectAccess(conn, data.projectId);
|
|
47
|
-
|
|
91
|
+
const cwd = resolveRepoCwd(project.path, data.repoPath);
|
|
92
|
+
await gitService.createBranch(cwd, data.name, data.startPoint);
|
|
48
93
|
return { ok: true };
|
|
49
94
|
})
|
|
50
95
|
|
|
51
96
|
.http('git:switch-branch', {
|
|
52
97
|
data: t.Object({
|
|
53
98
|
projectId: t.String(),
|
|
54
|
-
name: t.String()
|
|
99
|
+
name: t.String(),
|
|
100
|
+
/** Absolute path of a nested repo inside the project. */
|
|
101
|
+
repoPath: t.Optional(t.String())
|
|
55
102
|
}),
|
|
56
103
|
response: t.Object({ ok: t.Boolean() })
|
|
57
104
|
}, async ({ data, conn }) => {
|
|
58
105
|
const project = requireProjectAccess(conn, data.projectId);
|
|
59
|
-
|
|
106
|
+
const cwd = resolveRepoCwd(project.path, data.repoPath);
|
|
107
|
+
await gitService.switchBranch(cwd, data.name);
|
|
60
108
|
return { ok: true };
|
|
61
109
|
})
|
|
62
110
|
|
|
63
111
|
.http('git:checkout-commit', {
|
|
64
112
|
data: t.Object({
|
|
65
113
|
projectId: t.String(),
|
|
66
|
-
commitHash: t.String()
|
|
114
|
+
commitHash: t.String(),
|
|
115
|
+
repoPath: t.Optional(t.String())
|
|
67
116
|
}),
|
|
68
117
|
response: t.Object({ ok: t.Boolean() })
|
|
69
118
|
}, async ({ data, conn }) => {
|
|
70
119
|
const project = requireProjectAccess(conn, data.projectId);
|
|
71
|
-
|
|
120
|
+
const cwd = resolveRepoCwd(project.path, data.repoPath);
|
|
121
|
+
await gitService.checkoutCommit(cwd, data.commitHash);
|
|
72
122
|
return { ok: true };
|
|
73
123
|
})
|
|
74
124
|
|
|
@@ -76,12 +126,15 @@ export const branchHandler = createRouter()
|
|
|
76
126
|
data: t.Object({
|
|
77
127
|
projectId: t.String(),
|
|
78
128
|
name: t.String(),
|
|
79
|
-
force: t.Optional(t.Boolean())
|
|
129
|
+
force: t.Optional(t.Boolean()),
|
|
130
|
+
/** Absolute path of a nested repo inside the project. */
|
|
131
|
+
repoPath: t.Optional(t.String())
|
|
80
132
|
}),
|
|
81
133
|
response: t.Object({ ok: t.Boolean() })
|
|
82
134
|
}, async ({ data, conn }) => {
|
|
83
135
|
const project = requireProjectAccess(conn, data.projectId);
|
|
84
|
-
|
|
136
|
+
const cwd = resolveRepoCwd(project.path, data.repoPath);
|
|
137
|
+
await gitService.deleteBranch(cwd, data.name, data.force);
|
|
85
138
|
return { ok: true };
|
|
86
139
|
})
|
|
87
140
|
|
|
@@ -102,7 +155,8 @@ export const branchHandler = createRouter()
|
|
|
102
155
|
data: t.Object({
|
|
103
156
|
projectId: t.String(),
|
|
104
157
|
branchName: t.String(),
|
|
105
|
-
noFastForward: t.Optional(t.Boolean())
|
|
158
|
+
noFastForward: t.Optional(t.Boolean()),
|
|
159
|
+
repoPath: t.Optional(t.String())
|
|
106
160
|
}),
|
|
107
161
|
response: t.Object({
|
|
108
162
|
success: t.Boolean(),
|
|
@@ -110,5 +164,6 @@ export const branchHandler = createRouter()
|
|
|
110
164
|
})
|
|
111
165
|
}, async ({ data, conn }) => {
|
|
112
166
|
const project = requireProjectAccess(conn, data.projectId);
|
|
113
|
-
|
|
167
|
+
const cwd = resolveRepoCwd(project.path, data.repoPath);
|
|
168
|
+
return await gitService.mergeBranch(cwd, data.branchName, data.noFastForward ?? false);
|
|
114
169
|
});
|
|
@@ -43,6 +43,19 @@ const COMMIT_MESSAGE_SCHEMA = {
|
|
|
43
43
|
},
|
|
44
44
|
required: ['type', 'scope', 'subject', 'body']
|
|
45
45
|
};
|
|
46
|
+
import path from 'node:path';
|
|
47
|
+
|
|
48
|
+
function resolveRepoCwd(projectPath: string, repoPath: string | undefined): string {
|
|
49
|
+
if (!repoPath) return projectPath;
|
|
50
|
+
const resolved = path.resolve(repoPath);
|
|
51
|
+
const projectRoot = path.resolve(projectPath);
|
|
52
|
+
const sep = path.sep;
|
|
53
|
+
if (resolved !== projectRoot && !resolved.startsWith(projectRoot + sep)) {
|
|
54
|
+
debug.warn('git', `Rejected nested repoPath outside project: ${resolved}`);
|
|
55
|
+
return projectPath;
|
|
56
|
+
}
|
|
57
|
+
return resolved;
|
|
58
|
+
}
|
|
46
59
|
|
|
47
60
|
export const commitMessageHandler = createRouter()
|
|
48
61
|
.http('git:generate-commit-message', {
|
|
@@ -52,16 +65,18 @@ export const commitMessageHandler = createRouter()
|
|
|
52
65
|
providerSlug: t.String(),
|
|
53
66
|
modelId: t.String(),
|
|
54
67
|
format: t.Union([t.Literal('single-line'), t.Literal('multi-line')]),
|
|
55
|
-
customPrompt: t.Optional(t.String())
|
|
68
|
+
customPrompt: t.Optional(t.String()),
|
|
69
|
+
repoPath: t.Optional(t.String())
|
|
56
70
|
}),
|
|
57
71
|
response: t.Object({
|
|
58
72
|
message: t.String()
|
|
59
73
|
})
|
|
60
74
|
}, async ({ data, conn }) => {
|
|
61
75
|
const project = requireProjectAccess(conn, data.projectId);
|
|
76
|
+
const cwd = resolveRepoCwd(project.path, data.repoPath);
|
|
62
77
|
|
|
63
78
|
// Get raw staged diff text
|
|
64
|
-
const diffResult = await execGit(['diff', '--cached'],
|
|
79
|
+
const diffResult = await execGit(['diff', '--cached'], cwd);
|
|
65
80
|
const rawDiff = diffResult.stdout;
|
|
66
81
|
|
|
67
82
|
if (!rawDiff.trim()) {
|
|
@@ -102,7 +117,7 @@ ${rawDiff}`;
|
|
|
102
117
|
providerSlug: data.providerSlug,
|
|
103
118
|
modelId: data.modelId,
|
|
104
119
|
schema: COMMIT_MESSAGE_SCHEMA,
|
|
105
|
-
projectPath:
|
|
120
|
+
projectPath: cwd
|
|
106
121
|
});
|
|
107
122
|
|
|
108
123
|
// Format structured output into conventional commit string
|
package/backend/ws/git/commit.ts
CHANGED
|
@@ -3,55 +3,80 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import { t } from 'elysia';
|
|
6
|
+
import path from 'node:path';
|
|
6
7
|
import { createRouter } from '$shared/utils/ws-server';
|
|
7
8
|
import { gitService } from '../../git/git-service';
|
|
8
9
|
import { requireProjectAccess } from '../access';
|
|
10
|
+
import { debug } from '$shared/utils/logger';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Resolve the working directory for a git operation. Defaults to the project
|
|
14
|
+
* root; when `repoPath` is provided it must already be inside the project.
|
|
15
|
+
*/
|
|
16
|
+
function resolveRepoCwd(projectPath: string, repoPath: string | undefined): string {
|
|
17
|
+
if (!repoPath) return projectPath;
|
|
18
|
+
const resolved = path.resolve(repoPath);
|
|
19
|
+
const projectRoot = path.resolve(projectPath);
|
|
20
|
+
const sep = path.sep;
|
|
21
|
+
if (resolved !== projectRoot && !resolved.startsWith(projectRoot + sep)) {
|
|
22
|
+
debug.warn('git', `Rejected nested repoPath outside project: ${resolved}`);
|
|
23
|
+
return projectPath;
|
|
24
|
+
}
|
|
25
|
+
return resolved;
|
|
26
|
+
}
|
|
9
27
|
|
|
10
28
|
export const commitHandler = createRouter()
|
|
11
29
|
.http('git:commit', {
|
|
12
30
|
data: t.Object({
|
|
13
31
|
projectId: t.String(),
|
|
14
|
-
message: t.String({ minLength: 1 })
|
|
32
|
+
message: t.String({ minLength: 1 }),
|
|
33
|
+
repoPath: t.Optional(t.String())
|
|
15
34
|
}),
|
|
16
35
|
response: t.Object({
|
|
17
36
|
hash: t.String()
|
|
18
37
|
})
|
|
19
38
|
}, async ({ data, conn }) => {
|
|
20
39
|
const project = requireProjectAccess(conn, data.projectId);
|
|
21
|
-
const
|
|
40
|
+
const cwd = resolveRepoCwd(project.path, data.repoPath);
|
|
41
|
+
const hash = await gitService.commit(cwd, data.message);
|
|
22
42
|
return { hash };
|
|
23
43
|
})
|
|
24
44
|
|
|
25
45
|
.http('git:amend', {
|
|
26
46
|
data: t.Object({
|
|
27
47
|
projectId: t.String(),
|
|
28
|
-
message: t.Optional(t.String())
|
|
48
|
+
message: t.Optional(t.String()),
|
|
49
|
+
repoPath: t.Optional(t.String())
|
|
29
50
|
}),
|
|
30
51
|
response: t.Object({
|
|
31
52
|
hash: t.String()
|
|
32
53
|
})
|
|
33
54
|
}, async ({ data, conn }) => {
|
|
34
55
|
const project = requireProjectAccess(conn, data.projectId);
|
|
35
|
-
const
|
|
56
|
+
const cwd = resolveRepoCwd(project.path, data.repoPath);
|
|
57
|
+
const hash = await gitService.amendCommit(cwd, data.message);
|
|
36
58
|
return { hash };
|
|
37
59
|
})
|
|
38
60
|
|
|
39
61
|
.http('git:undo-commit', {
|
|
40
62
|
data: t.Object({
|
|
41
63
|
projectId: t.String(),
|
|
42
|
-
mode: t.Union([t.Literal('soft'), t.Literal('mixed'), t.Literal('hard')])
|
|
64
|
+
mode: t.Union([t.Literal('soft'), t.Literal('mixed'), t.Literal('hard')]),
|
|
65
|
+
repoPath: t.Optional(t.String())
|
|
43
66
|
}),
|
|
44
67
|
response: t.Object({ ok: t.Boolean() })
|
|
45
68
|
}, async ({ data, conn }) => {
|
|
46
69
|
const project = requireProjectAccess(conn, data.projectId);
|
|
47
|
-
|
|
70
|
+
const cwd = resolveRepoCwd(project.path, data.repoPath);
|
|
71
|
+
await gitService.undoLastCommit(cwd, data.mode);
|
|
48
72
|
return { ok: true };
|
|
49
73
|
})
|
|
50
74
|
|
|
51
75
|
.http('git:revert', {
|
|
52
76
|
data: t.Object({
|
|
53
77
|
projectId: t.String(),
|
|
54
|
-
ref: t.Optional(t.String())
|
|
78
|
+
ref: t.Optional(t.String()),
|
|
79
|
+
repoPath: t.Optional(t.String())
|
|
55
80
|
}),
|
|
56
81
|
response: t.Object({
|
|
57
82
|
success: t.Boolean(),
|
|
@@ -59,13 +84,15 @@ export const commitHandler = createRouter()
|
|
|
59
84
|
})
|
|
60
85
|
}, async ({ data, conn }) => {
|
|
61
86
|
const project = requireProjectAccess(conn, data.projectId);
|
|
62
|
-
|
|
87
|
+
const cwd = resolveRepoCwd(project.path, data.repoPath);
|
|
88
|
+
return await gitService.revertCommit(cwd, data.ref);
|
|
63
89
|
})
|
|
64
90
|
|
|
65
91
|
.http('git:cherry-pick', {
|
|
66
92
|
data: t.Object({
|
|
67
93
|
projectId: t.String(),
|
|
68
|
-
hashes: t.Array(t.String(), { minItems: 1 })
|
|
94
|
+
hashes: t.Array(t.String(), { minItems: 1 }),
|
|
95
|
+
repoPath: t.Optional(t.String())
|
|
69
96
|
}),
|
|
70
97
|
response: t.Object({
|
|
71
98
|
success: t.Boolean(),
|
|
@@ -73,35 +100,41 @@ export const commitHandler = createRouter()
|
|
|
73
100
|
})
|
|
74
101
|
}, async ({ data, conn }) => {
|
|
75
102
|
const project = requireProjectAccess(conn, data.projectId);
|
|
76
|
-
|
|
103
|
+
const cwd = resolveRepoCwd(project.path, data.repoPath);
|
|
104
|
+
return await gitService.cherryPick(cwd, data.hashes);
|
|
77
105
|
})
|
|
78
106
|
|
|
79
107
|
.http('git:clean', {
|
|
80
108
|
data: t.Object({
|
|
81
|
-
projectId: t.String()
|
|
109
|
+
projectId: t.String(),
|
|
110
|
+
repoPath: t.Optional(t.String())
|
|
82
111
|
}),
|
|
83
112
|
response: t.Object({ message: t.String() })
|
|
84
113
|
}, async ({ data, conn }) => {
|
|
85
114
|
const project = requireProjectAccess(conn, data.projectId);
|
|
86
|
-
const
|
|
115
|
+
const cwd = resolveRepoCwd(project.path, data.repoPath);
|
|
116
|
+
const message = await gitService.cleanUntracked(cwd);
|
|
87
117
|
return { message };
|
|
88
118
|
})
|
|
89
119
|
|
|
90
120
|
.http('git:gc', {
|
|
91
121
|
data: t.Object({
|
|
92
|
-
projectId: t.String()
|
|
122
|
+
projectId: t.String(),
|
|
123
|
+
repoPath: t.Optional(t.String())
|
|
93
124
|
}),
|
|
94
125
|
response: t.Object({ message: t.String() })
|
|
95
126
|
}, async ({ data, conn }) => {
|
|
96
127
|
const project = requireProjectAccess(conn, data.projectId);
|
|
97
|
-
const
|
|
128
|
+
const cwd = resolveRepoCwd(project.path, data.repoPath);
|
|
129
|
+
const message = await gitService.optimize(cwd);
|
|
98
130
|
return { message };
|
|
99
131
|
})
|
|
100
132
|
|
|
101
133
|
.http('git:npm-version', {
|
|
102
134
|
data: t.Object({
|
|
103
135
|
projectId: t.String(),
|
|
104
|
-
bump: t.Union([t.Literal('patch'), t.Literal('minor'), t.Literal('major')])
|
|
136
|
+
bump: t.Union([t.Literal('patch'), t.Literal('minor'), t.Literal('major')]),
|
|
137
|
+
repoPath: t.Optional(t.String())
|
|
105
138
|
}),
|
|
106
139
|
response: t.Object({
|
|
107
140
|
success: t.Boolean(),
|
|
@@ -110,5 +143,6 @@ export const commitHandler = createRouter()
|
|
|
110
143
|
})
|
|
111
144
|
}, async ({ data, conn }) => {
|
|
112
145
|
const project = requireProjectAccess(conn, data.projectId);
|
|
113
|
-
|
|
146
|
+
const cwd = resolveRepoCwd(project.path, data.repoPath);
|
|
147
|
+
return await gitService.npmVersion(cwd, data.bump);
|
|
114
148
|
});
|
|
@@ -3,9 +3,24 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import { t } from 'elysia';
|
|
6
|
+
import path from 'node:path';
|
|
6
7
|
import { createRouter } from '$shared/utils/ws-server';
|
|
7
8
|
import { gitService } from '../../git/git-service';
|
|
9
|
+
import { findNestedRepoPaths, findRepoForFile } from '../../snapshot/gitignore';
|
|
8
10
|
import { requireProjectAccess } from '../access';
|
|
11
|
+
import { debug } from '$shared/utils/logger';
|
|
12
|
+
|
|
13
|
+
function resolveRepoCwd(projectPath: string, repoPath: string | undefined): string | null {
|
|
14
|
+
if (!repoPath) return null;
|
|
15
|
+
const resolved = path.resolve(repoPath);
|
|
16
|
+
const projectRoot = path.resolve(projectPath);
|
|
17
|
+
const sep = path.sep;
|
|
18
|
+
if (resolved !== projectRoot && !resolved.startsWith(projectRoot + sep)) {
|
|
19
|
+
debug.warn('git', `Rejected nested repoPath outside project: ${resolved}`);
|
|
20
|
+
return projectRoot;
|
|
21
|
+
}
|
|
22
|
+
return resolved;
|
|
23
|
+
}
|
|
9
24
|
|
|
10
25
|
const ConflictMarkerSchema = t.Object({
|
|
11
26
|
ourStart: t.Number(),
|
|
@@ -31,7 +46,29 @@ export const conflictHandler = createRouter()
|
|
|
31
46
|
}))
|
|
32
47
|
}, async ({ data, conn }) => {
|
|
33
48
|
const project = requireProjectAccess(conn, data.projectId);
|
|
34
|
-
|
|
49
|
+
const conflicts = await gitService.getConflictFiles(project.path);
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
const nestedRepoPaths = await findNestedRepoPaths(project.path);
|
|
53
|
+
for (const repoPath of nestedRepoPaths) {
|
|
54
|
+
try {
|
|
55
|
+
const nestedConflicts = await gitService.getConflictFiles(repoPath);
|
|
56
|
+
const prefix = path.relative(project.path, repoPath).replace(/\\/g, '/') + '/';
|
|
57
|
+
for (const conflict of nestedConflicts) {
|
|
58
|
+
conflicts.push({
|
|
59
|
+
...conflict,
|
|
60
|
+
path: prefix + conflict.path
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
} catch {
|
|
64
|
+
// Skip nested repos whose conflict status fails
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
} catch {
|
|
68
|
+
// Skip finding nested repos if it fails
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return conflicts;
|
|
35
72
|
})
|
|
36
73
|
|
|
37
74
|
.http('git:resolve-conflict', {
|
|
@@ -44,9 +81,12 @@ export const conflictHandler = createRouter()
|
|
|
44
81
|
response: t.Object({ ok: t.Boolean() })
|
|
45
82
|
}, async ({ data, conn }) => {
|
|
46
83
|
const project = requireProjectAccess(conn, data.projectId);
|
|
84
|
+
const repo = await findRepoForFile(project.path, data.filePath);
|
|
85
|
+
const cwd = repo?.repoPath ?? project.path;
|
|
86
|
+
const filePath = repo?.relativeFilePath ?? data.filePath;
|
|
47
87
|
await gitService.resolveConflict(
|
|
48
|
-
|
|
49
|
-
|
|
88
|
+
cwd,
|
|
89
|
+
filePath,
|
|
50
90
|
data.resolution,
|
|
51
91
|
data.customContent
|
|
52
92
|
);
|
|
@@ -55,11 +95,13 @@ export const conflictHandler = createRouter()
|
|
|
55
95
|
|
|
56
96
|
.http('git:abort-merge', {
|
|
57
97
|
data: t.Object({
|
|
58
|
-
projectId: t.String()
|
|
98
|
+
projectId: t.String(),
|
|
99
|
+
repoPath: t.Optional(t.String())
|
|
59
100
|
}),
|
|
60
101
|
response: t.Object({ ok: t.Boolean() })
|
|
61
102
|
}, async ({ data, conn }) => {
|
|
62
103
|
const project = requireProjectAccess(conn, data.projectId);
|
|
63
|
-
|
|
104
|
+
const cwd = resolveRepoCwd(project.path, data.repoPath) ?? project.path;
|
|
105
|
+
await gitService.abortMerge(cwd);
|
|
64
106
|
return { ok: true };
|
|
65
107
|
});
|
package/backend/ws/git/diff.ts
CHANGED
|
@@ -3,9 +3,12 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import { t } from 'elysia';
|
|
6
|
+
import path from 'node:path';
|
|
6
7
|
import { createRouter } from '$shared/utils/ws-server';
|
|
7
8
|
import { gitService } from '../../git/git-service';
|
|
9
|
+
import { findRepoForFile } from '../../snapshot/gitignore';
|
|
8
10
|
import { requireProjectAccess } from '../access';
|
|
11
|
+
import { debug } from '$shared/utils/logger';
|
|
9
12
|
|
|
10
13
|
const DiffHunkLineSchema = t.Object({
|
|
11
14
|
type: t.Union([t.Literal('add'), t.Literal('delete'), t.Literal('context'), t.Literal('header')]),
|
|
@@ -31,6 +34,22 @@ const FileDiffSchema = t.Object({
|
|
|
31
34
|
isBinary: t.Boolean()
|
|
32
35
|
});
|
|
33
36
|
|
|
37
|
+
/**
|
|
38
|
+
* Resolve the working directory for a git operation. Defaults to the project
|
|
39
|
+
* root; when `repoPath` is provided it must already be inside the project.
|
|
40
|
+
*/
|
|
41
|
+
function resolveRepoCwd(projectPath: string, repoPath: string | undefined): string {
|
|
42
|
+
if (!repoPath) return projectPath;
|
|
43
|
+
const resolved = path.resolve(repoPath);
|
|
44
|
+
const projectRoot = path.resolve(projectPath);
|
|
45
|
+
const sep = path.sep;
|
|
46
|
+
if (resolved !== projectRoot && !resolved.startsWith(projectRoot + sep)) {
|
|
47
|
+
debug.warn('git', `Rejected nested repoPath outside project: ${resolved}`);
|
|
48
|
+
return projectPath;
|
|
49
|
+
}
|
|
50
|
+
return resolved;
|
|
51
|
+
}
|
|
52
|
+
|
|
34
53
|
export const diffHandler = createRouter()
|
|
35
54
|
.http('git:diff-unstaged', {
|
|
36
55
|
data: t.Object({
|
|
@@ -40,7 +59,15 @@ export const diffHandler = createRouter()
|
|
|
40
59
|
response: t.Array(FileDiffSchema)
|
|
41
60
|
}, async ({ data, conn }) => {
|
|
42
61
|
const project = requireProjectAccess(conn, data.projectId);
|
|
43
|
-
|
|
62
|
+
// Route the diff to the nested repo that owns the file (if any) —
|
|
63
|
+
// the outer repo's `git diff` returns nothing for files that are
|
|
64
|
+
// tracked inside a nested repo and gitignored by the parent.
|
|
65
|
+
const repo = data.filePath
|
|
66
|
+
? await findRepoForFile(project.path, data.filePath)
|
|
67
|
+
: null;
|
|
68
|
+
const cwd = repo?.repoPath ?? project.path;
|
|
69
|
+
const filePath = repo?.relativeFilePath ?? data.filePath;
|
|
70
|
+
return await gitService.getDiffUnstaged(cwd, filePath);
|
|
44
71
|
})
|
|
45
72
|
|
|
46
73
|
.http('git:diff-staged', {
|
|
@@ -51,16 +78,23 @@ export const diffHandler = createRouter()
|
|
|
51
78
|
response: t.Array(FileDiffSchema)
|
|
52
79
|
}, async ({ data, conn }) => {
|
|
53
80
|
const project = requireProjectAccess(conn, data.projectId);
|
|
54
|
-
|
|
81
|
+
const repo = data.filePath
|
|
82
|
+
? await findRepoForFile(project.path, data.filePath)
|
|
83
|
+
: null;
|
|
84
|
+
const cwd = repo?.repoPath ?? project.path;
|
|
85
|
+
const filePath = repo?.relativeFilePath ?? data.filePath;
|
|
86
|
+
return await gitService.getDiffStaged(cwd, filePath);
|
|
55
87
|
})
|
|
56
88
|
|
|
57
89
|
.http('git:diff-commit', {
|
|
58
90
|
data: t.Object({
|
|
59
91
|
projectId: t.String(),
|
|
60
|
-
commitHash: t.String()
|
|
92
|
+
commitHash: t.String(),
|
|
93
|
+
repoPath: t.Optional(t.String())
|
|
61
94
|
}),
|
|
62
95
|
response: t.Array(FileDiffSchema)
|
|
63
96
|
}, async ({ data, conn }) => {
|
|
64
97
|
const project = requireProjectAccess(conn, data.projectId);
|
|
65
|
-
|
|
98
|
+
const cwd = resolveRepoCwd(project.path, data.repoPath);
|
|
99
|
+
return await gitService.getDiffCommit(cwd, data.commitHash);
|
|
66
100
|
});
|
package/backend/ws/git/log.ts
CHANGED
|
@@ -3,9 +3,27 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import { t } from 'elysia';
|
|
6
|
+
import path from 'node:path';
|
|
6
7
|
import { createRouter } from '$shared/utils/ws-server';
|
|
7
8
|
import { gitService } from '../../git/git-service';
|
|
8
9
|
import { requireProjectAccess } from '../access';
|
|
10
|
+
import { debug } from '$shared/utils/logger';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Resolve the working directory for a git operation. Defaults to the project
|
|
14
|
+
* root; when `repoPath` is provided it must already be inside the project.
|
|
15
|
+
*/
|
|
16
|
+
function resolveRepoCwd(projectPath: string, repoPath: string | undefined): string {
|
|
17
|
+
if (!repoPath) return projectPath;
|
|
18
|
+
const resolved = path.resolve(repoPath);
|
|
19
|
+
const projectRoot = path.resolve(projectPath);
|
|
20
|
+
const sep = path.sep;
|
|
21
|
+
if (resolved !== projectRoot && !resolved.startsWith(projectRoot + sep)) {
|
|
22
|
+
debug.warn('git', `Rejected nested repoPath outside project: ${resolved}`);
|
|
23
|
+
return projectPath;
|
|
24
|
+
}
|
|
25
|
+
return resolved;
|
|
26
|
+
}
|
|
9
27
|
|
|
10
28
|
export const logHandler = createRouter()
|
|
11
29
|
.http('git:log', {
|
|
@@ -13,7 +31,8 @@ export const logHandler = createRouter()
|
|
|
13
31
|
projectId: t.String(),
|
|
14
32
|
limit: t.Optional(t.Number()),
|
|
15
33
|
skip: t.Optional(t.Number()),
|
|
16
|
-
branch: t.Optional(t.String())
|
|
34
|
+
branch: t.Optional(t.String()),
|
|
35
|
+
repoPath: t.Optional(t.String())
|
|
17
36
|
}),
|
|
18
37
|
response: t.Object({
|
|
19
38
|
commits: t.Array(t.Object({
|
|
@@ -31,8 +50,9 @@ export const logHandler = createRouter()
|
|
|
31
50
|
})
|
|
32
51
|
}, async ({ data, conn }) => {
|
|
33
52
|
const project = requireProjectAccess(conn, data.projectId);
|
|
53
|
+
const cwd = resolveRepoCwd(project.path, data.repoPath);
|
|
34
54
|
return await gitService.getLog(
|
|
35
|
-
|
|
55
|
+
cwd,
|
|
36
56
|
data.limit ?? 50,
|
|
37
57
|
data.skip ?? 0,
|
|
38
58
|
data.branch
|