@myrialabs/clopen 0.4.4 → 0.4.5

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.
@@ -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 { 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
  export const stagingHandler = createRouter()
11
26
  .http('git:stage', {
@@ -16,18 +31,23 @@ export const stagingHandler = createRouter()
16
31
  response: t.Object({ ok: t.Boolean() })
17
32
  }, async ({ data, conn }) => {
18
33
  const project = requireProjectAccess(conn, data.projectId);
19
- await gitService.stageFile(project.path, data.filePath);
34
+ const repo = await findRepoForFile(project.path, data.filePath);
35
+ const cwd = repo?.repoPath ?? project.path;
36
+ const filePath = repo?.relativeFilePath ?? data.filePath;
37
+ await gitService.stageFile(cwd, filePath);
20
38
  return { ok: true };
21
39
  })
22
40
 
23
41
  .http('git:stage-all', {
24
42
  data: t.Object({
25
- projectId: t.String()
43
+ projectId: t.String(),
44
+ repoPath: t.Optional(t.String())
26
45
  }),
27
46
  response: t.Object({ ok: t.Boolean() })
28
47
  }, async ({ data, conn }) => {
29
48
  const project = requireProjectAccess(conn, data.projectId);
30
- await gitService.stageAll(project.path);
49
+ const cwd = data.repoPath ? (resolveRepoCwd(project.path, data.repoPath) ?? project.path) : project.path;
50
+ await gitService.stageAll(cwd);
31
51
  return { ok: true };
32
52
  })
33
53
 
@@ -39,18 +59,23 @@ export const stagingHandler = createRouter()
39
59
  response: t.Object({ ok: t.Boolean() })
40
60
  }, async ({ data, conn }) => {
41
61
  const project = requireProjectAccess(conn, data.projectId);
42
- await gitService.unstageFile(project.path, data.filePath);
62
+ const repo = await findRepoForFile(project.path, data.filePath);
63
+ const cwd = repo?.repoPath ?? project.path;
64
+ const filePath = repo?.relativeFilePath ?? data.filePath;
65
+ await gitService.unstageFile(cwd, filePath);
43
66
  return { ok: true };
44
67
  })
45
68
 
46
69
  .http('git:unstage-all', {
47
70
  data: t.Object({
48
- projectId: t.String()
71
+ projectId: t.String(),
72
+ repoPath: t.Optional(t.String())
49
73
  }),
50
74
  response: t.Object({ ok: t.Boolean() })
51
75
  }, async ({ data, conn }) => {
52
76
  const project = requireProjectAccess(conn, data.projectId);
53
- await gitService.unstageAll(project.path);
77
+ const cwd = data.repoPath ? (resolveRepoCwd(project.path, data.repoPath) ?? project.path) : project.path;
78
+ await gitService.unstageAll(cwd);
54
79
  return { ok: true };
55
80
  })
56
81
 
@@ -62,17 +87,22 @@ export const stagingHandler = createRouter()
62
87
  response: t.Object({ ok: t.Boolean() })
63
88
  }, async ({ data, conn }) => {
64
89
  const project = requireProjectAccess(conn, data.projectId);
65
- await gitService.discardFile(project.path, data.filePath);
90
+ const repo = await findRepoForFile(project.path, data.filePath);
91
+ const cwd = repo?.repoPath ?? project.path;
92
+ const filePath = repo?.relativeFilePath ?? data.filePath;
93
+ await gitService.discardFile(cwd, filePath);
66
94
  return { ok: true };
67
95
  })
68
96
 
69
97
  .http('git:discard-all', {
70
98
  data: t.Object({
71
- projectId: t.String()
99
+ projectId: t.String(),
100
+ repoPath: t.Optional(t.String())
72
101
  }),
73
102
  response: t.Object({ ok: t.Boolean() })
74
103
  }, async ({ data, conn }) => {
75
104
  const project = requireProjectAccess(conn, data.projectId);
76
- await gitService.discardAll(project.path);
105
+ const cwd = data.repoPath ? (resolveRepoCwd(project.path, data.repoPath) ?? project.path) : project.path;
106
+ await gitService.discardAll(cwd);
77
107
  return { ok: true };
78
108
  });
@@ -5,7 +5,9 @@
5
5
  import { t } from 'elysia';
6
6
  import { createRouter } from '$shared/utils/ws-server';
7
7
  import { gitService } from '../../git/git-service';
8
+ import { findNestedRepoPaths } from '../../snapshot/gitignore';
8
9
  import { requireProjectAccess } from '../access';
10
+ import { relative as pathRelative } from 'path';
9
11
 
10
12
  export const statusHandler = createRouter()
11
13
  .http('git:status', {
@@ -54,6 +56,56 @@ export const statusHandler = createRouter()
54
56
  }
55
57
 
56
58
  const status = await gitService.getStatus(project.path);
59
+
60
+ // Also aggregate status from nested git repos living inside the
61
+ // project (e.g. a theme extracted into its own repo, listed in the
62
+ // parent's .gitignore). The outer repo's `git status` skips them
63
+ // entirely, so without this aggregation the Changes tab would not
64
+ // show edits the AI made inside the nested repo.
65
+ try {
66
+ const nestedRepoPaths = await findNestedRepoPaths(project.path);
67
+ const nestedPrefixes = nestedRepoPaths.map(
68
+ (repoPath) => pathRelative(project.path, repoPath).replace(/\\/g, '/') + '/'
69
+ );
70
+
71
+ // Drop outer-repo entries that fall under a nested repo's prefix.
72
+ // When the outer repo already tracked files inside what later became
73
+ // a nested repo (or reports the nested dir itself as a single
74
+ // untracked entry), it surfaces those paths too — colliding with the
75
+ // nested aggregation below and producing duplicate file entries. The
76
+ // nested repo is the source of truth for its own contents, so the
77
+ // outer view of them is dropped.
78
+ if (nestedPrefixes.length > 0) {
79
+ const underNested = (f: { path: string }) =>
80
+ nestedPrefixes.some((p) => f.path === p || f.path.startsWith(p));
81
+ status.staged = status.staged.filter((f) => !underNested(f));
82
+ status.unstaged = status.unstaged.filter((f) => !underNested(f));
83
+ status.untracked = status.untracked.filter((f) => !underNested(f));
84
+ status.conflicted = status.conflicted.filter((f) => !underNested(f));
85
+ }
86
+
87
+ for (const repoPath of nestedRepoPaths) {
88
+ try {
89
+ const nestedStatus = await gitService.getStatus(repoPath);
90
+ const prefix = pathRelative(project.path, repoPath).replace(/\\/g, '/') + '/';
91
+ const withPrefix = (f: typeof nestedStatus.staged[number]) => ({
92
+ ...f,
93
+ path: prefix + f.path,
94
+ oldPath: f.oldPath ? prefix + f.oldPath : undefined
95
+ });
96
+ status.staged.push(...nestedStatus.staged.map(withPrefix));
97
+ status.unstaged.push(...nestedStatus.unstaged.map(withPrefix));
98
+ status.untracked.push(...nestedStatus.untracked.map(withPrefix));
99
+ status.conflicted.push(...nestedStatus.conflicted.map(withPrefix));
100
+ } catch {
101
+ // Skip repos whose git status fails — don't break the
102
+ // whole response because one nested repo is broken.
103
+ }
104
+ }
105
+ } catch {
106
+ // If findNestedRepoPaths itself fails, just return outer status
107
+ }
108
+
57
109
  return { isRepo: true, ...status };
58
110
  })
59
111
 
@@ -23,7 +23,8 @@ import {
23
23
  resolveServerRow,
24
24
  startAuthorization,
25
25
  completeAuthorization,
26
- getValidAccessToken
26
+ getValidAccessToken,
27
+ parseMcpConfig
27
28
  } from '$backend/mcp';
28
29
 
29
30
  const TRANSPORT_SCHEMA = t.Union([t.Literal('stdio'), t.Literal('http'), t.Literal('sse')]);
@@ -182,6 +183,34 @@ export const mcpCrudHandler = createRouter()
182
183
  debug.log('mcp', `📥 Installed external MCP server: ${slug}`);
183
184
  return { server: toDTO(row) };
184
185
  })
186
+ .http('mcp:parse-config', {
187
+ // Normalise a pasted MCP JSON snippet (Claude/Cursor/VS Code/OpenCode/…)
188
+ // into reviewable servers. Pure transform — nothing is persisted here; the
189
+ // UI shows the result, the user fills any required secrets, then installs
190
+ // via `mcp:install` with `source: 'custom'`.
191
+ data: t.Object({ text: t.String() }),
192
+ response: t.Object({
193
+ servers: t.Array(t.Object({
194
+ name: t.String(),
195
+ slug: t.String(),
196
+ transport: TRANSPORT_SCHEMA,
197
+ command: t.Optional(t.String()),
198
+ args: t.Array(t.String()),
199
+ url: t.Optional(t.String()),
200
+ fields: t.Array(t.Object({
201
+ name: t.String(),
202
+ kind: t.Union([t.Literal('env'), t.Literal('header')]),
203
+ value: t.String(),
204
+ isPlaceholder: t.Boolean()
205
+ })),
206
+ warnings: t.Array(t.String())
207
+ })),
208
+ errors: t.Array(t.String())
209
+ })
210
+ }, async ({ data }) => {
211
+ debug.log('path', 'mcp:parse-config');
212
+ return parseMcpConfig(data.text);
213
+ })
185
214
  .http('mcp:toggle', {
186
215
  data: t.Object({ id: t.Number(), enabled: t.Boolean() }),
187
216
  response: t.Object({ server: INSTALLED_SERVER_SCHEMA })
@@ -139,7 +139,7 @@ export const timelineHandler = createRouter()
139
139
  }
140
140
 
141
141
  // File stats from checkpoint's own snapshot
142
- const stats = getCheckpointFileStats(cp);
142
+ const stats = await getCheckpointFileStats(cp);
143
143
 
144
144
  const snapshot = snapshotQueries.getByMessageId(cp.id);
145
145