@myrialabs/clopen 0.4.30 → 0.4.32
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.test.ts +0 -1
- package/backend/auth/permissions.ts +0 -4
- package/backend/chat/stream-manager.ts +28 -12
- package/backend/database/migrations/068_create_engine_config_revision.test.ts +121 -0
- package/backend/database/migrations/068_create_engine_config_revision.ts +117 -0
- package/backend/database/migrations/index.ts +7 -0
- package/backend/engine/README.md +16 -0
- package/backend/engine/adapters/claude/stream.ts +89 -49
- package/backend/engine/adapters/cline/stream.ts +62 -24
- package/backend/engine/adapters/codex/stream.ts +51 -21
- package/backend/engine/adapters/copilot/stream.ts +96 -52
- package/backend/engine/adapters/cursor/stream.ts +74 -34
- package/backend/engine/adapters/opencode/server.ts +512 -126
- package/backend/engine/adapters/opencode/stream.ts +131 -79
- package/backend/engine/adapters/pi/stream.ts +63 -24
- package/backend/engine/adapters/qwen/stream.ts +91 -58
- package/backend/engine/adapters/run-registry.test.ts +75 -0
- package/backend/engine/adapters/run-registry.ts +63 -0
- package/backend/engine/bootstrap-default-engine.ts +67 -38
- package/backend/engine/config-revision.ts +150 -0
- package/backend/engine/docs/adapter-contract.md +40 -9
- package/backend/engine/docs/adding-an-engine.md +8 -0
- package/backend/engine/docs/frontend-and-chat.md +39 -0
- package/backend/engine/docs/lessons-learned.md +70 -0
- package/backend/engine/docs/quick-reference.md +3 -1
- package/backend/engine/engine-cli.ts +313 -0
- package/backend/engine/engine-setup.ts +40 -3
- package/backend/engine/hot-reload.ts +99 -0
- package/backend/engine/index.ts +96 -24
- package/backend/engine/install-recipes.test.ts +99 -5
- package/backend/engine/install-recipes.ts +47 -11
- package/backend/engine/install-runner.ts +34 -16
- package/backend/engine/stack-project.ts +72 -0
- package/backend/engine/types.ts +17 -5
- package/backend/git/git-executor.ts +22 -3
- package/backend/git/git-service.ts +1 -1
- package/backend/git/nested-repos.test.ts +121 -0
- package/backend/git/nested-repos.ts +301 -0
- package/backend/index.ts +7 -0
- package/backend/snapshot/gitignore.ts +10 -174
- package/backend/utils/path-enrich.ts +2 -0
- package/backend/ws/chat/stream.ts +24 -0
- package/backend/ws/engine/claude/accounts.ts +9 -4
- package/backend/ws/engine/codex/accounts.ts +8 -17
- package/backend/ws/engine/codex/status.ts +10 -17
- package/backend/ws/engine/copilot/accounts.ts +0 -10
- package/backend/ws/engine/cursor/accounts.ts +0 -10
- package/backend/ws/engine/index.ts +17 -2
- package/backend/ws/engine/opencode/providers.ts +0 -52
- package/backend/ws/files/read.ts +1 -1
- package/backend/ws/git/conflict.ts +1 -1
- package/backend/ws/git/diff.ts +1 -1
- package/backend/ws/git/staging.ts +1 -1
- package/backend/ws/git/status.ts +1 -1
- package/backend/ws/settings/crud.ts +1 -1
- package/backend/ws/stack/access.ts +5 -2
- package/dist/assets/{index-DYwQ5bP8.js → index-DSvGoxp2.js} +1 -1
- package/dist/assets/{index-DUc5T21e.js → index-hu17G6tX.js} +1 -1
- package/dist/assets/main-BccclZsC.js +1031 -0
- package/dist/assets/{main-VgdjTBLR.css → main-Ciuw0wF0.css} +1 -1
- package/dist/index.html +2 -2
- package/package.json +1 -1
- package/backend/ws/engine/restart.ts +0 -54
- package/dist/assets/main-r0iv2PDz.js +0 -1044
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Nested git repo discovery — the single source of truth for "which sub-repos
|
|
3
|
+
* live inside this project".
|
|
4
|
+
*
|
|
5
|
+
* Used by the Git panel (status/branches/conflicts aggregation), by the file
|
|
6
|
+
* handlers that must run git inside the owning repo, and by the snapshot
|
|
7
|
+
* scanner. Every caller MUST go through `findNestedRepoPaths` so they all agree
|
|
8
|
+
* on what counts as a sub-repo.
|
|
9
|
+
*
|
|
10
|
+
* ## What counts as a sub-repo
|
|
11
|
+
*
|
|
12
|
+
* A directory with its own `.git` that the user actually works in — a theme or
|
|
13
|
+
* plugin extracted into its own repo, a submodule, a worktree.
|
|
14
|
+
*
|
|
15
|
+
* What does NOT count: the hundreds of repos a package manager clones into a
|
|
16
|
+
* build or cache directory (Swift Package Manager's
|
|
17
|
+
* `build/…/SourcePackages/checkouts/*`, Carthage, Go module caches, …). They
|
|
18
|
+
* are machine-generated, the user never commits them, and listing them floods
|
|
19
|
+
* the Changes tab with thousands of foreign files.
|
|
20
|
+
*
|
|
21
|
+
* Two signals separate the two, both applied while walking:
|
|
22
|
+
*
|
|
23
|
+
* 1. **Name** — directories in `HARD_SKIP_DIRS` are dependency/build caches by
|
|
24
|
+
* definition; never descend into them.
|
|
25
|
+
* 2. **Ignore state** — a directory the enclosing repo ignores is not part of
|
|
26
|
+
* the project's own structure. We still peek `IGNORED_DESCENT_LEVELS` level
|
|
27
|
+
* into it, because an embedded repo is commonly placed directly under an
|
|
28
|
+
* ignored parent (`wp-content/themes/` ignored, the theme repo inside it),
|
|
29
|
+
* but generated checkouts always sit much deeper.
|
|
30
|
+
*
|
|
31
|
+
* A repo found this way resets the ignore budget: its own contents are then
|
|
32
|
+
* judged by its own `.gitignore`, not the outer repo's.
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
import fs from 'fs/promises';
|
|
36
|
+
import path from 'path';
|
|
37
|
+
import { debug } from '$shared/utils/logger';
|
|
38
|
+
import { execGit } from './git-executor';
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Directories that never hold a user's own repo — VCS internals, dependency
|
|
42
|
+
* caches, and package-manager checkout dirs. Pruned by name at any depth,
|
|
43
|
+
* whether or not the enclosing repo ignores them (a project may well commit
|
|
44
|
+
* its `Pods/`, and it still isn't where sub-repos live).
|
|
45
|
+
*/
|
|
46
|
+
const HARD_SKIP_DIRS = new Set([
|
|
47
|
+
'.git', '.svn', '.hg',
|
|
48
|
+
'node_modules', 'bower_components', '.yarn', '.pnpm-store',
|
|
49
|
+
'Pods', 'Carthage', 'DerivedData', 'SourcePackages', '.build',
|
|
50
|
+
'.gradle', '.m2', '.cargo', '.pub-cache', '.dart_tool', '.expo',
|
|
51
|
+
'.venv', 'venv', '__pycache__', '.tox', '.stack-work',
|
|
52
|
+
'.next', '.nuxt', '.svelte-kit', '.turbo', '.angular', '.parcel-cache',
|
|
53
|
+
'.terraform', '.serverless', '.vercel', '.netlify', '.cache'
|
|
54
|
+
]);
|
|
55
|
+
|
|
56
|
+
/** How many levels below an ignored directory we still look for a repo. */
|
|
57
|
+
const IGNORED_DESCENT_LEVELS = 1;
|
|
58
|
+
|
|
59
|
+
/** Depth limit below the project root — a runaway walk helps nobody. */
|
|
60
|
+
const MAX_DEPTH = 12;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Upper bound on reported sub-repos. A project with more than this is either
|
|
64
|
+
* pathological or hit a detection hole; either way the UI cannot usefully show
|
|
65
|
+
* them, so we stop and log instead of flooding it.
|
|
66
|
+
*/
|
|
67
|
+
const MAX_REPOS = 50;
|
|
68
|
+
|
|
69
|
+
/** One directory queued for inspection during the breadth-first walk. */
|
|
70
|
+
interface WalkEntry {
|
|
71
|
+
/** Absolute path of the directory whose children we will inspect. */
|
|
72
|
+
dirPath: string;
|
|
73
|
+
/** Absolute path of the nearest enclosing git repo (for ignore checks). */
|
|
74
|
+
repoRoot: string;
|
|
75
|
+
/**
|
|
76
|
+
* Remaining levels we may descend while inside an ignored tree, or `null`
|
|
77
|
+
* when this directory is part of the enclosing repo's own structure.
|
|
78
|
+
*/
|
|
79
|
+
ignoredBudget: number | null;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Ask the enclosing repo which of `relPaths` it ignores. Returns the ignored
|
|
84
|
+
* subset. Batched so a walk costs one git call per repo per depth level, not
|
|
85
|
+
* one per directory.
|
|
86
|
+
*/
|
|
87
|
+
async function filterIgnored(repoRoot: string, relPaths: string[]): Promise<Set<string>> {
|
|
88
|
+
const ignored = new Set<string>();
|
|
89
|
+
if (relPaths.length === 0) return ignored;
|
|
90
|
+
|
|
91
|
+
try {
|
|
92
|
+
// Paths go in over stdin: no argv limit, no quoting rules. Exit 1 just
|
|
93
|
+
// means "none of these are ignored" — not a failure.
|
|
94
|
+
const result = await execGit(['check-ignore', '-z', '--stdin'], repoRoot, {
|
|
95
|
+
stdin: relPaths.join('\0'),
|
|
96
|
+
okExitCodes: [1]
|
|
97
|
+
});
|
|
98
|
+
if (result.exitCode === 0) {
|
|
99
|
+
for (const p of result.stdout.split('\0')) {
|
|
100
|
+
if (p) ignored.add(p.replace(/\\/g, '/'));
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
} catch {
|
|
104
|
+
// Not a repo, or git unavailable — treat as "nothing ignored" and let
|
|
105
|
+
// the name-based prune carry the walk.
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return ignored;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** Whether `dirPath` is a git repo (`.git` is a dir for clones, a file for worktrees/submodules). */
|
|
112
|
+
async function isRepoDir(dirPath: string): Promise<boolean> {
|
|
113
|
+
try {
|
|
114
|
+
await fs.access(path.join(dirPath, '.git'));
|
|
115
|
+
return true;
|
|
116
|
+
} catch {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Find every nested git repo under `rootPath`, skipping dependency caches and
|
|
123
|
+
* ignored trees (see the module comment for the exact policy). Does NOT scan
|
|
124
|
+
* the repos — just returns their absolute paths, sorted for stable UI order.
|
|
125
|
+
*/
|
|
126
|
+
export async function findNestedRepoPaths(rootPath: string): Promise<string[]> {
|
|
127
|
+
const found: string[] = [];
|
|
128
|
+
let level: WalkEntry[] = [{ dirPath: rootPath, repoRoot: rootPath, ignoredBudget: null }];
|
|
129
|
+
let truncated = false;
|
|
130
|
+
|
|
131
|
+
for (let depth = 0; depth < MAX_DEPTH && level.length > 0 && !truncated; depth++) {
|
|
132
|
+
// Collect this level's candidate children, grouped by enclosing repo so
|
|
133
|
+
// the ignore check can be batched per repo.
|
|
134
|
+
const candidates: Array<{ parent: WalkEntry; fullPath: string; relPath: string }> = [];
|
|
135
|
+
for (const entry of level) {
|
|
136
|
+
let entries;
|
|
137
|
+
try {
|
|
138
|
+
entries = await fs.readdir(entry.dirPath, { withFileTypes: true });
|
|
139
|
+
} catch {
|
|
140
|
+
continue; // unreadable dir — skip, never fail the whole walk
|
|
141
|
+
}
|
|
142
|
+
for (const child of entries) {
|
|
143
|
+
// `isDirectory()` is false for symlinks, which also keeps the
|
|
144
|
+
// walk free of symlink cycles.
|
|
145
|
+
if (!child.isDirectory()) continue;
|
|
146
|
+
if (HARD_SKIP_DIRS.has(child.name)) continue;
|
|
147
|
+
const fullPath = path.join(entry.dirPath, child.name);
|
|
148
|
+
candidates.push({
|
|
149
|
+
parent: entry,
|
|
150
|
+
fullPath,
|
|
151
|
+
relPath: path.relative(entry.repoRoot, fullPath).replace(/\\/g, '/')
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (candidates.length === 0) break;
|
|
156
|
+
|
|
157
|
+
// Ignore state is only needed for candidates that are not repos
|
|
158
|
+
// themselves and whose parent isn't already inside an ignored tree.
|
|
159
|
+
const repoFlags = await Promise.all(candidates.map((c) => isRepoDir(c.fullPath)));
|
|
160
|
+
const needIgnoreCheck = new Map<string, string[]>();
|
|
161
|
+
candidates.forEach((c, i) => {
|
|
162
|
+
if (repoFlags[i] || c.parent.ignoredBudget !== null) return;
|
|
163
|
+
const list = needIgnoreCheck.get(c.parent.repoRoot) ?? [];
|
|
164
|
+
list.push(c.relPath);
|
|
165
|
+
needIgnoreCheck.set(c.parent.repoRoot, list);
|
|
166
|
+
});
|
|
167
|
+
const ignoredByRepo = new Map<string, Set<string>>();
|
|
168
|
+
for (const [repoRoot, relPaths] of needIgnoreCheck) {
|
|
169
|
+
ignoredByRepo.set(repoRoot, await filterIgnored(repoRoot, relPaths));
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const next: WalkEntry[] = [];
|
|
173
|
+
candidates.forEach((c, i) => {
|
|
174
|
+
if (repoFlags[i]) {
|
|
175
|
+
if (found.length >= MAX_REPOS) {
|
|
176
|
+
truncated = true;
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
found.push(c.fullPath);
|
|
180
|
+
// Inside a repo, its own ignore rules apply from scratch.
|
|
181
|
+
next.push({ dirPath: c.fullPath, repoRoot: c.fullPath, ignoredBudget: null });
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
let budget = c.parent.ignoredBudget;
|
|
186
|
+
if (budget === null) {
|
|
187
|
+
const ignored = ignoredByRepo.get(c.parent.repoRoot);
|
|
188
|
+
if (!ignored?.has(c.relPath)) {
|
|
189
|
+
// Part of the project's own structure — descend freely.
|
|
190
|
+
next.push({ dirPath: c.fullPath, repoRoot: c.parent.repoRoot, ignoredBudget: null });
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
budget = IGNORED_DESCENT_LEVELS;
|
|
194
|
+
} else {
|
|
195
|
+
budget -= 1;
|
|
196
|
+
}
|
|
197
|
+
// Inside an ignored tree: keep looking only while the budget lasts.
|
|
198
|
+
if (budget > 0) {
|
|
199
|
+
next.push({ dirPath: c.fullPath, repoRoot: c.parent.repoRoot, ignoredBudget: budget });
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
level = next;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (truncated) {
|
|
207
|
+
debug.warn('git', `Nested repo scan of ${rootPath} stopped at ${MAX_REPOS} repos`);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
found.sort();
|
|
211
|
+
return found;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Read the outer repo's `.gitmodules` file and return the set of relative
|
|
216
|
+
* submodule paths. Returns an empty set when the file is missing or unreadable
|
|
217
|
+
* (e.g. the project isn't a git repo at all, or has no submodules).
|
|
218
|
+
*
|
|
219
|
+
* The format is INI-like:
|
|
220
|
+
* [submodule "vendor/foo"]
|
|
221
|
+
* path = vendor/foo
|
|
222
|
+
* url = git@example.com:vendor/foo.git
|
|
223
|
+
*
|
|
224
|
+
* The `path =` value is what we return — the directory inside the project root
|
|
225
|
+
* where the submodule is checked out. If a section omits `path =`, git falls
|
|
226
|
+
* back to the section name; we mirror that.
|
|
227
|
+
*/
|
|
228
|
+
export async function findSubmodulePaths(rootPath: string): Promise<Set<string>> {
|
|
229
|
+
const out = new Set<string>();
|
|
230
|
+
let raw: string;
|
|
231
|
+
try {
|
|
232
|
+
raw = await fs.readFile(path.join(rootPath, '.gitmodules'), 'utf8');
|
|
233
|
+
} catch {
|
|
234
|
+
return out; // file missing → no submodules
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// Two-pass parse: collect per-section { name, path? } then resolve.
|
|
238
|
+
// Single-pass is simpler but needs careful handling of the implicit
|
|
239
|
+
// section-name fallback; the two-pass version reads more clearly.
|
|
240
|
+
const sections: Array<{ name: string; path?: string }> = [];
|
|
241
|
+
let current: { name: string; path?: string } | null = null;
|
|
242
|
+
for (const line of raw.split(/\r?\n/)) {
|
|
243
|
+
const trimmed = line.trim();
|
|
244
|
+
if (!trimmed || trimmed.startsWith('#')) continue;
|
|
245
|
+
|
|
246
|
+
const sectionMatch = trimmed.match(/^\[submodule\s+"([^"]+)"\]\s*$/);
|
|
247
|
+
if (sectionMatch) {
|
|
248
|
+
if (current) sections.push(current);
|
|
249
|
+
current = { name: sectionMatch[1] };
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
if (!current) continue;
|
|
253
|
+
|
|
254
|
+
const pathMatch = trimmed.match(/^path\s*=\s*(.+?)\s*$/);
|
|
255
|
+
if (pathMatch) current.path = pathMatch[1].replace(/\\/g, '/');
|
|
256
|
+
}
|
|
257
|
+
if (current) sections.push(current);
|
|
258
|
+
|
|
259
|
+
for (const s of sections) {
|
|
260
|
+
out.add(s.path ?? s.name);
|
|
261
|
+
}
|
|
262
|
+
return out;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Given a file path relative to the project root, find the deepest nested
|
|
267
|
+
* git repo that contains it. Returns the repo's absolute path and the file
|
|
268
|
+
* path relative to that repo, or `null` if the file lives in the outer repo.
|
|
269
|
+
*
|
|
270
|
+
* Used by git staging/discard handlers so that `git add` / `git restore` /
|
|
271
|
+
* `git rm` run inside the correct repo (the outer repo's `git` would skip
|
|
272
|
+
* or fail on files that are tracked by a nested repo).
|
|
273
|
+
*/
|
|
274
|
+
export async function findRepoForFile(
|
|
275
|
+
projectPath: string,
|
|
276
|
+
filePath: string
|
|
277
|
+
): Promise<{ repoPath: string; relativeFilePath: string } | null> {
|
|
278
|
+
const normalizedFilePath = filePath.replace(/\\/g, '/');
|
|
279
|
+
const nestedRepoPaths = await findNestedRepoPaths(projectPath);
|
|
280
|
+
|
|
281
|
+
let bestMatch: { repoPath: string; relativeFilePath: string } | null = null;
|
|
282
|
+
let bestRepoRelLen = -1;
|
|
283
|
+
|
|
284
|
+
for (const repoPath of nestedRepoPaths) {
|
|
285
|
+
const repoRel = path.relative(projectPath, repoPath).replace(/\\/g, '/');
|
|
286
|
+
// File is inside this repo if its path starts with `repoRel/`
|
|
287
|
+
if (normalizedFilePath === repoRel || normalizedFilePath.startsWith(repoRel + '/')) {
|
|
288
|
+
if (repoRel.length > bestRepoRelLen) {
|
|
289
|
+
bestMatch = {
|
|
290
|
+
repoPath,
|
|
291
|
+
relativeFilePath: normalizedFilePath === repoRel
|
|
292
|
+
? ''
|
|
293
|
+
: normalizedFilePath.substring(repoRel.length + 1)
|
|
294
|
+
};
|
|
295
|
+
bestRepoRelLen = repoRel.length;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
return bestMatch;
|
|
301
|
+
}
|
package/backend/index.ts
CHANGED
|
@@ -24,6 +24,8 @@ import { loggerMiddleware } from './middleware/logger';
|
|
|
24
24
|
// Database initialization
|
|
25
25
|
import { initializeDatabase, closeDatabase } from './database';
|
|
26
26
|
import { bootstrapAfterDbInit } from './bootstrap';
|
|
27
|
+
import { startEngineConfigWatcher } from './engine/config-revision';
|
|
28
|
+
import { startEngineHotReload } from './engine/hot-reload';
|
|
27
29
|
import { disposeAllEngines } from './engine';
|
|
28
30
|
import { connectionManager } from './db-client/connection-manager';
|
|
29
31
|
import { refreshProcessPath } from './utils/path-enrich';
|
|
@@ -250,6 +252,11 @@ async function startServer() {
|
|
|
250
252
|
// Start expired session cleanup now that the database is ready
|
|
251
253
|
sessionCleanupScheduler.start();
|
|
252
254
|
uploadTempCleanup.start();
|
|
255
|
+
// Watch for engine-affecting config edits and apply them on their own.
|
|
256
|
+
// Long-lived, so it belongs here rather than in bootstrapAfterDbInit(),
|
|
257
|
+
// which also runs on the live process during "Clear All Data".
|
|
258
|
+
startEngineHotReload();
|
|
259
|
+
startEngineConfigWatcher();
|
|
253
260
|
} catch (error) {
|
|
254
261
|
console.error('❌ Database initialization failed — refusing to start:', error);
|
|
255
262
|
console.error(` Data directory: ${SERVER_ENV.DATA_DIR}`);
|
|
@@ -12,6 +12,7 @@ import fs from 'fs/promises';
|
|
|
12
12
|
import path from 'path';
|
|
13
13
|
import { debug } from '$shared/utils/logger';
|
|
14
14
|
import { execGit } from '../git/git-executor';
|
|
15
|
+
import { findNestedRepoPaths } from '../git/nested-repos';
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* Safety-net directories to always exclude regardless of .gitignore.
|
|
@@ -22,137 +23,6 @@ const ALWAYS_EXCLUDE_DIRS = new Set([
|
|
|
22
23
|
'node_modules',
|
|
23
24
|
]);
|
|
24
25
|
|
|
25
|
-
/**
|
|
26
|
-
* Find paths of all nested git repos (directories with their own `.git`) at any
|
|
27
|
-
* depth under `rootPath`. Walks into nested repos to find deeply nested ones.
|
|
28
|
-
* Does NOT scan the repos — just returns their absolute paths.
|
|
29
|
-
*
|
|
30
|
-
* Used by callers that need to run git commands inside each nested repo
|
|
31
|
-
* (e.g. `git:status` aggregating changes from nested repos into the Changes
|
|
32
|
-
* tab of the Git panel).
|
|
33
|
-
*/
|
|
34
|
-
export async function findNestedRepoPaths(rootPath: string): Promise<string[]> {
|
|
35
|
-
const paths: string[] = [];
|
|
36
|
-
|
|
37
|
-
const walk = async (currentPath: string): Promise<void> => {
|
|
38
|
-
let entries;
|
|
39
|
-
try {
|
|
40
|
-
entries = await fs.readdir(currentPath, { withFileTypes: true });
|
|
41
|
-
} catch {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
for (const entry of entries) {
|
|
46
|
-
if (!entry.isDirectory()) continue;
|
|
47
|
-
if (ALWAYS_EXCLUDE_DIRS.has(entry.name)) continue;
|
|
48
|
-
|
|
49
|
-
const fullPath = path.join(currentPath, entry.name);
|
|
50
|
-
|
|
51
|
-
// Check if this directory is itself a git repo
|
|
52
|
-
try {
|
|
53
|
-
await fs.access(path.join(fullPath, '.git'));
|
|
54
|
-
paths.push(fullPath);
|
|
55
|
-
// Fall through to also walk into it for deeper nested repos
|
|
56
|
-
} catch {
|
|
57
|
-
// Not a git repo
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
await walk(fullPath);
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
await walk(rootPath);
|
|
65
|
-
return paths;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Read the outer repo's `.gitmodules` file and return the set of relative
|
|
70
|
-
* submodule paths. Returns an empty set when the file is missing or unreadable
|
|
71
|
-
* (e.g. the project isn't a git repo at all, or has no submodules).
|
|
72
|
-
*
|
|
73
|
-
* The format is INI-like:
|
|
74
|
-
* [submodule "vendor/foo"]
|
|
75
|
-
* path = vendor/foo
|
|
76
|
-
* url = git@example.com:vendor/foo.git
|
|
77
|
-
*
|
|
78
|
-
* The `path =` value is what we return — the directory inside the project root
|
|
79
|
-
* where the submodule is checked out. If a section omits `path =`, git falls
|
|
80
|
-
* back to the section name; we mirror that.
|
|
81
|
-
*/
|
|
82
|
-
export async function findSubmodulePaths(rootPath: string): Promise<Set<string>> {
|
|
83
|
-
const out = new Set<string>();
|
|
84
|
-
let raw: string;
|
|
85
|
-
try {
|
|
86
|
-
raw = await fs.readFile(path.join(rootPath, '.gitmodules'), 'utf8');
|
|
87
|
-
} catch {
|
|
88
|
-
return out; // file missing → no submodules
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// Two-pass parse: collect per-section { name, path? } then resolve.
|
|
92
|
-
// Single-pass is simpler but needs careful handling of the implicit
|
|
93
|
-
// section-name fallback; the two-pass version reads more clearly.
|
|
94
|
-
const sections: Array<{ name: string; path?: string }> = [];
|
|
95
|
-
let current: { name: string; path?: string } | null = null;
|
|
96
|
-
for (const line of raw.split(/\r?\n/)) {
|
|
97
|
-
const trimmed = line.trim();
|
|
98
|
-
if (!trimmed || trimmed.startsWith('#')) continue;
|
|
99
|
-
|
|
100
|
-
const sectionMatch = trimmed.match(/^\[submodule\s+"([^"]+)"\]\s*$/);
|
|
101
|
-
if (sectionMatch) {
|
|
102
|
-
if (current) sections.push(current);
|
|
103
|
-
current = { name: sectionMatch[1] };
|
|
104
|
-
continue;
|
|
105
|
-
}
|
|
106
|
-
if (!current) continue;
|
|
107
|
-
|
|
108
|
-
const pathMatch = trimmed.match(/^path\s*=\s*(.+?)\s*$/);
|
|
109
|
-
if (pathMatch) current.path = pathMatch[1].replace(/\\/g, '/');
|
|
110
|
-
}
|
|
111
|
-
if (current) sections.push(current);
|
|
112
|
-
|
|
113
|
-
for (const s of sections) {
|
|
114
|
-
out.add(s.path ?? s.name);
|
|
115
|
-
}
|
|
116
|
-
return out;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Given a file path relative to the project root, find the deepest nested
|
|
121
|
-
* git repo that contains it. Returns the repo's absolute path and the file
|
|
122
|
-
* path relative to that repo, or `null` if the file lives in the outer repo.
|
|
123
|
-
*
|
|
124
|
-
* Used by git staging/discard handlers so that `git add` / `git restore` /
|
|
125
|
-
* `git rm` run inside the correct repo (the outer repo's `git` would skip
|
|
126
|
-
* or fail on files that are tracked by a nested repo).
|
|
127
|
-
*/
|
|
128
|
-
export async function findRepoForFile(
|
|
129
|
-
projectPath: string,
|
|
130
|
-
filePath: string
|
|
131
|
-
): Promise<{ repoPath: string; relativeFilePath: string } | null> {
|
|
132
|
-
const normalizedFilePath = filePath.replace(/\\/g, '/');
|
|
133
|
-
const nestedRepoPaths = await findNestedRepoPaths(projectPath);
|
|
134
|
-
|
|
135
|
-
let bestMatch: { repoPath: string; relativeFilePath: string } | null = null;
|
|
136
|
-
let bestRepoRelLen = -1;
|
|
137
|
-
|
|
138
|
-
for (const repoPath of nestedRepoPaths) {
|
|
139
|
-
const repoRel = path.relative(projectPath, repoPath).replace(/\\/g, '/');
|
|
140
|
-
// File is inside this repo if its path starts with `repoRel/`
|
|
141
|
-
if (normalizedFilePath === repoRel || normalizedFilePath.startsWith(repoRel + '/')) {
|
|
142
|
-
if (repoRel.length > bestRepoRelLen) {
|
|
143
|
-
bestMatch = {
|
|
144
|
-
repoPath,
|
|
145
|
-
relativeFilePath: normalizedFilePath === repoRel
|
|
146
|
-
? ''
|
|
147
|
-
: normalizedFilePath.substring(repoRel.length + 1)
|
|
148
|
-
};
|
|
149
|
-
bestRepoRelLen = repoRel.length;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
return bestMatch;
|
|
155
|
-
}
|
|
156
26
|
|
|
157
27
|
/**
|
|
158
28
|
* Get list of snapshot-eligible files using git (preferred) or manual scan.
|
|
@@ -236,52 +106,18 @@ async function scanSingleGitRepo(dirPath: string): Promise<string[]> {
|
|
|
236
106
|
}
|
|
237
107
|
|
|
238
108
|
/**
|
|
239
|
-
*
|
|
240
|
-
*
|
|
241
|
-
*
|
|
242
|
-
*
|
|
243
|
-
*
|
|
244
|
-
*
|
|
245
|
-
* NOT respect .gitignore, because the nested repo we're looking for may itself
|
|
246
|
-
* be gitignored by the parent. Once a nested repo is found, its own
|
|
247
|
-
* `git ls-files --exclude-standard` handles its .gitignore rules.
|
|
109
|
+
* Scan every nested git repo inside the project and return their files.
|
|
110
|
+
* Discovery is delegated to `findNestedRepoPaths` — the same source of truth
|
|
111
|
+
* the Git panel uses — so a repo the panel shows is a repo the snapshot
|
|
112
|
+
* captures, and a package-manager checkout neither of them touches. Each repo
|
|
113
|
+
* is then scanned with its own `git ls-files --exclude-standard`, which applies
|
|
114
|
+
* that repo's .gitignore rules.
|
|
248
115
|
*/
|
|
249
116
|
async function findAndScanNestedRepos(rootPath: string): Promise<string[]> {
|
|
250
117
|
const files: string[] = [];
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
try {
|
|
255
|
-
entries = await fs.readdir(currentPath, { withFileTypes: true });
|
|
256
|
-
} catch {
|
|
257
|
-
return;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
for (const entry of entries) {
|
|
261
|
-
if (!entry.isDirectory()) continue;
|
|
262
|
-
if (ALWAYS_EXCLUDE_DIRS.has(entry.name)) continue;
|
|
263
|
-
|
|
264
|
-
const fullPath = path.join(currentPath, entry.name);
|
|
265
|
-
|
|
266
|
-
// Check if this directory is itself a git repo (`.git` can be a
|
|
267
|
-
// directory or a file — the latter for worktrees/submodules).
|
|
268
|
-
try {
|
|
269
|
-
await fs.access(path.join(fullPath, '.git'));
|
|
270
|
-
// Nested repo found — scan it independently, then continue
|
|
271
|
-
// walking into it to find even deeper nested repos.
|
|
272
|
-
const nestedFiles = await scanSingleGitRepo(fullPath);
|
|
273
|
-
files.push(...nestedFiles);
|
|
274
|
-
await walk(fullPath);
|
|
275
|
-
continue;
|
|
276
|
-
} catch {
|
|
277
|
-
// Not a git repo — recurse to find deeper nested repos
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
await walk(fullPath);
|
|
281
|
-
}
|
|
282
|
-
};
|
|
283
|
-
|
|
284
|
-
await walk(rootPath);
|
|
118
|
+
for (const repoPath of await findNestedRepoPaths(rootPath)) {
|
|
119
|
+
files.push(...await scanSingleGitRepo(repoPath));
|
|
120
|
+
}
|
|
285
121
|
return files;
|
|
286
122
|
}
|
|
287
123
|
|
|
@@ -84,6 +84,8 @@ function windowsKnownDirs(): string[] {
|
|
|
84
84
|
join(home, '.bun', 'bin'),
|
|
85
85
|
join(home, '.deno', 'bin'),
|
|
86
86
|
join(home, '.cargo', 'bin'),
|
|
87
|
+
// install-script target (Open Code), the Windows twin of the posix entry
|
|
88
|
+
join(home, '.opencode', 'bin'),
|
|
87
89
|
join(home, 'scoop', 'shims'),
|
|
88
90
|
join(localAppData, 'Microsoft', 'WinGet', 'Links'),
|
|
89
91
|
join(localAppData, 'Programs', 'Git', 'cmd'),
|