forked from nicobailon/pi-web-access
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub-extract.ts
More file actions
717 lines (612 loc) · 20 KB
/
Copy pathgithub-extract.ts
File metadata and controls
717 lines (612 loc) · 20 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
import { existsSync, readFileSync, rmSync, statSync, readdirSync, openSync, readSync, closeSync, realpathSync } from "node:fs";
import { execFile, spawn, type ChildProcess } from "node:child_process";
import { extname, join, resolve as resolvePath, sep as pathSep } from "node:path";
import { activityMonitor } from "./activity.ts";
import type { ExtractedContent } from "./extract.ts";
import { checkGhAvailable, checkRepoSize, fetchViaApi, showGhHint } from "./github-api.ts";
import { getWebSearchConfigPath } from "./utils.ts";
const CONFIG_PATH = getWebSearchConfigPath();
const BINARY_EXTENSIONS = new Set([
".png", ".jpg", ".jpeg", ".gif", ".bmp", ".ico", ".webp", ".svg", ".tiff", ".tif",
".mp3", ".mp4", ".avi", ".mov", ".mkv", ".flv", ".wmv", ".wav", ".ogg", ".webm", ".flac", ".aac",
".zip", ".tar", ".gz", ".bz2", ".xz", ".7z", ".rar", ".zst",
".exe", ".dll", ".so", ".dylib", ".bin", ".o", ".a", ".lib",
".woff", ".woff2", ".ttf", ".otf", ".eot",
".pdf", ".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx",
".sqlite", ".db", ".sqlite3",
".pyc", ".pyo", ".class", ".jar", ".war",
".iso", ".img", ".dmg",
]);
const NOISE_DIRS = new Set([
"node_modules", "vendor", ".next", "dist", "build", "__pycache__",
".venv", "venv", ".tox", ".mypy_cache", ".pytest_cache",
"target", ".gradle", ".idea", ".vscode",
]);
const MAX_INLINE_FILE_CHARS = 100_000;
const MAX_TREE_ENTRIES = 200;
export interface GitHubUrlInfo {
owner: string;
repo: string;
ref?: string;
refIsFullSha: boolean;
path?: string;
type: "root" | "blob" | "tree";
}
interface CachedClone {
localPath: string;
clonePromise: Promise<string | null>;
}
interface GitHubCloneConfig {
enabled: boolean;
maxRepoSizeMB: number;
cloneTimeoutSeconds: number;
clonePath: string;
}
const cloneCache = new Map<string, CachedClone>();
let cachedConfig: GitHubCloneConfig | null = null;
function normalizeEnabled(value: unknown, fallback: boolean): boolean {
return typeof value === "boolean" ? value : fallback;
}
function normalizePositiveNumber(value: unknown, fallback: number): number {
if (typeof value !== "number" || !Number.isFinite(value)) return fallback;
return value > 0 ? value : fallback;
}
function expandPath(value: string): string {
let expanded = value;
// Expand ~ at the start of the path
if (expanded.startsWith("~/") || expanded === "~") {
expanded = expanded.replace(/^~/, process.env.HOME || process.env.USERPROFILE || "");
}
// Expand environment variables like $HOME, $USER, etc.
expanded = expanded.replace(/\$([A-Z_][A-Z0-9_]*)/gi, (match, varName) => {
return process.env[varName] ?? match;
});
return expanded;
}
function normalizeClonePath(value: unknown, fallback: string): string {
if (typeof value !== "string") return fallback;
const normalized = value.trim();
if (normalized.length === 0) return fallback;
return expandPath(normalized);
}
function loadGitHubConfig(): GitHubCloneConfig {
if (cachedConfig) return cachedConfig;
const defaults: GitHubCloneConfig = {
enabled: true,
maxRepoSizeMB: 350,
cloneTimeoutSeconds: 30,
clonePath: "/tmp/pi-github-repos",
};
if (!existsSync(CONFIG_PATH)) {
cachedConfig = defaults;
return cachedConfig;
}
const rawText = readFileSync(CONFIG_PATH, "utf-8");
let raw: { githubClone?: { enabled?: unknown; maxRepoSizeMB?: unknown; cloneTimeoutSeconds?: unknown; clonePath?: unknown } };
try {
raw = JSON.parse(rawText) as { githubClone?: { enabled?: unknown; maxRepoSizeMB?: unknown; cloneTimeoutSeconds?: unknown; clonePath?: unknown } };
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
throw new Error(`Failed to parse ${CONFIG_PATH}: ${message}`);
}
const gc = raw.githubClone ?? {};
cachedConfig = {
enabled: normalizeEnabled(gc.enabled, defaults.enabled),
maxRepoSizeMB: normalizePositiveNumber(gc.maxRepoSizeMB, defaults.maxRepoSizeMB),
cloneTimeoutSeconds: normalizePositiveNumber(gc.cloneTimeoutSeconds, defaults.cloneTimeoutSeconds),
clonePath: normalizeClonePath(gc.clonePath, defaults.clonePath),
};
return cachedConfig;
}
const NON_CODE_SEGMENTS = new Set([
"issues", "pull", "pulls", "discussions", "releases", "wiki",
"actions", "settings", "security", "projects", "graphs",
"compare", "commits", "tags", "branches", "stargazers",
"watchers", "network", "forks", "milestone", "labels",
"packages", "codespaces", "contribute", "community",
"sponsors", "invitations", "notifications", "insights",
]);
export function parseGitHubUrl(url: string): GitHubUrlInfo | null {
let parsed: URL;
try {
parsed = new URL(url);
} catch {
return null;
}
const host = parsed.hostname.toLowerCase();
if (host !== "github.com" && host !== "www.github.com") return null;
const segments = parsed.pathname
.split("/")
.filter(Boolean)
.map((segment) => {
try {
return decodeURIComponent(segment);
} catch {
return segment;
}
});
if (segments.length < 2) return null;
const owner = segments[0];
const repo = segments[1].replace(/\.git$/, "");
if (NON_CODE_SEGMENTS.has(segments[2]?.toLowerCase())) return null;
if (segments.length === 2) {
return { owner, repo, refIsFullSha: false, type: "root" };
}
const action = segments[2];
if (action !== "blob" && action !== "tree") return null;
if (segments.length < 4) return null;
const ref = segments[3];
const refIsFullSha = /^[0-9a-f]{40}$/.test(ref);
const pathParts = segments.slice(4);
const path = pathParts.length > 0 ? pathParts.join("/") : "";
return {
owner,
repo,
ref,
refIsFullSha,
path,
type: action as "blob" | "tree",
};
}
function cacheKey(owner: string, repo: string, ref?: string): string {
return ref ? `${owner}/${repo}@${ref}` : `${owner}/${repo}`;
}
function cloneDir(config: GitHubCloneConfig, owner: string, repo: string, ref?: string): string {
const dirName = ref ? `${repo}@${ref}` : repo;
return join(config.clonePath, owner, dirName);
}
const PROCESS_KILL_GRACE_MS = 3000;
function terminateProcessTree(child: ChildProcess): void {
const pid = child.pid;
if (!pid) return;
if (process.platform === "win32") {
const killer = execFile(
"taskkill",
["/pid", String(pid), "/T", "/F"],
{ windowsHide: true },
(err) => {
if (err) child.kill();
},
);
killer.unref();
return;
}
try {
// Clone commands run in their own process group so git/gh helpers cannot
// survive a timeout or cancellation and keep reading from the host TTY.
process.kill(-pid, "SIGTERM");
} catch {
child.kill();
}
// A credential helper may handle or ignore SIGTERM. Escalate against the
// entire process group so neither git nor any descendant can block forever.
const forceKill = setTimeout(() => {
try {
process.kill(-pid, "SIGKILL");
} catch {
child.kill("SIGKILL");
}
}, PROCESS_KILL_GRACE_MS);
forceKill.unref();
}
function execClone(args: string[], localPath: string, timeoutMs: number, signal?: AbortSignal): Promise<string | null> {
return new Promise((resolve) => {
let settled = false;
let timeout: ReturnType<typeof setTimeout> | undefined;
let onAbort: (() => void) | undefined;
const finish = (success: boolean) => {
if (settled) return;
settled = true;
if (timeout) clearTimeout(timeout);
if (signal && onAbort) signal.removeEventListener("abort", onAbort);
if (!success) {
try {
rmSync(localPath, { recursive: true, force: true });
} catch {
}
resolve(null);
return;
}
resolve(localPath);
};
const child = spawn(args[0], args.slice(1), {
detached: process.platform !== "win32",
env: {
...process.env,
GIT_TERMINAL_PROMPT: "0",
GCM_INTERACTIVE: "Never",
GH_PROMPT_DISABLED: "1",
},
stdio: "ignore",
windowsHide: true,
});
child.once("error", () => finish(false));
child.once("close", (code) => finish(code === 0));
timeout = setTimeout(() => terminateProcessTree(child), timeoutMs);
timeout.unref();
if (signal) {
onAbort = () => {
if (timeout) clearTimeout(timeout);
terminateProcessTree(child);
};
if (signal.aborted) onAbort();
else signal.addEventListener("abort", onAbort, { once: true });
}
});
}
async function cloneRepo(
owner: string,
repo: string,
ref: string | undefined,
config: GitHubCloneConfig,
signal?: AbortSignal,
): Promise<string | null> {
const localPath = cloneDir(config, owner, repo, ref);
try {
rmSync(localPath, { recursive: true, force: true });
} catch {
}
const timeoutMs = config.cloneTimeoutSeconds * 1000;
const hasGh = await checkGhAvailable();
if (hasGh) {
const args = ["gh", "repo", "clone", `${owner}/${repo}`, localPath, "--", "--depth", "1", "--single-branch"];
if (ref) args.push("--branch", ref);
return execClone(args, localPath, timeoutMs, signal);
}
showGhHint();
const gitUrl = `https://github.com/${owner}/${repo}.git`;
const args = ["git", "clone", "--depth", "1", "--single-branch"];
if (ref) args.push("--branch", ref);
args.push(gitUrl, localPath);
return execClone(args, localPath, timeoutMs, signal);
}
function isBinaryFile(filePath: string): boolean {
const ext = extname(filePath).toLowerCase();
if (BINARY_EXTENSIONS.has(ext)) return true;
let fd: number;
try {
fd = openSync(filePath, "r");
} catch {
return false;
}
try {
const buf = Buffer.alloc(512);
const bytesRead = readSync(fd, buf, 0, 512, 0);
for (let i = 0; i < bytesRead; i++) {
if (buf[i] === 0) return true;
}
} catch {
return false;
} finally {
closeSync(fd);
}
return false;
}
function formatFileSize(bytes: number): string {
if (bytes < 1024) return `${bytes} B`;
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
}
function resolveWithinRepo(rootPath: string, relativePath: string): string | null {
const normalizedRoot = resolvePath(rootPath);
const candidate = resolvePath(normalizedRoot, relativePath);
if (candidate !== normalizedRoot) {
const rootPrefix = normalizedRoot.endsWith(pathSep) ? normalizedRoot : normalizedRoot + pathSep;
if (!candidate.startsWith(rootPrefix)) return null;
}
if (!existsSync(candidate)) return candidate;
try {
const realRoot = realpathSync(normalizedRoot);
const realCandidate = realpathSync(candidate);
if (realCandidate === realRoot) return candidate;
const realRootPrefix = realRoot.endsWith(pathSep) ? realRoot : realRoot + pathSep;
return realCandidate.startsWith(realRootPrefix) ? candidate : null;
} catch {
return null;
}
}
function readTextFile(path: string): string | null {
try {
return readFileSync(path, "utf-8");
} catch {
return null;
}
}
function buildTree(rootPath: string): string {
const entries: string[] = [];
function walk(dir: string, relPath: string): void {
if (entries.length >= MAX_TREE_ENTRIES) return;
let items: string[];
try {
items = readdirSync(dir).sort();
} catch {
return;
}
for (const item of items) {
if (entries.length >= MAX_TREE_ENTRIES) return;
if (item === ".git") continue;
const rel = relPath ? `${relPath}/${item}` : item;
const safePath = resolveWithinRepo(rootPath, rel);
if (!safePath) {
entries.push(`${rel} [outside repo skipped]`);
continue;
}
let stat;
try {
stat = statSync(safePath);
} catch {
continue;
}
if (stat.isDirectory()) {
if (NOISE_DIRS.has(item)) {
entries.push(`${rel}/ [skipped]`);
continue;
}
entries.push(`${rel}/`);
walk(safePath, rel);
} else {
entries.push(rel);
}
}
}
walk(rootPath, "");
if (entries.length >= MAX_TREE_ENTRIES) {
entries.push(`... (truncated at ${MAX_TREE_ENTRIES} entries)`);
}
return entries.join("\n");
}
function buildDirListing(rootPath: string, subPath: string): string {
const targetPath = resolveWithinRepo(rootPath, subPath);
if (!targetPath) return "(path escapes repository root)";
const lines: string[] = [];
let items: string[];
try {
items = readdirSync(targetPath).sort();
} catch {
return "(directory not readable)";
}
for (const item of items) {
if (item === ".git") continue;
const rel = subPath ? `${subPath}/${item}` : item;
const safePath = resolveWithinRepo(rootPath, rel);
if (!safePath) {
lines.push(` ${item} (outside repo)`);
continue;
}
try {
const stat = statSync(safePath);
if (stat.isDirectory()) {
lines.push(` ${item}/`);
} else {
lines.push(` ${item} (${formatFileSize(stat.size)})`);
}
} catch {
lines.push(` ${item} (unreadable)`);
}
}
return lines.join("\n");
}
function readReadme(localPath: string): string | null {
const candidates = ["README.md", "readme.md", "README", "README.txt", "README.rst"];
for (const name of candidates) {
const readmePath = join(localPath, name);
if (existsSync(readmePath)) {
try {
const content = readFileSync(readmePath, "utf-8");
return content.length > 8192 ? content.slice(0, 8192) + "\n\n[README truncated at 8K chars]" : content;
} catch {
continue;
}
}
}
return null;
}
function generateContent(localPath: string, info: GitHubUrlInfo): string {
const lines: string[] = [];
lines.push(`Repository cloned to: ${localPath}`);
lines.push("");
if (info.type === "root") {
lines.push("## Structure");
lines.push(buildTree(localPath));
lines.push("");
const readme = readReadme(localPath);
if (readme) {
lines.push("## README.md");
lines.push(readme);
lines.push("");
}
lines.push("Use `read` and `bash` tools at the path above to explore further.");
return lines.join("\n");
}
if (info.type === "tree") {
const dirPath = info.path || "";
const fullDirPath = resolveWithinRepo(localPath, dirPath);
if (!fullDirPath || !existsSync(fullDirPath)) {
lines.push(`Path \`${dirPath}\` not found in clone. Showing repository root instead.`);
lines.push("");
lines.push("## Structure");
lines.push(buildTree(localPath));
} else {
lines.push(`## ${dirPath || "/"}`);
lines.push(buildDirListing(localPath, dirPath));
}
lines.push("");
lines.push("Use `read` and `bash` tools at the path above to explore further.");
return lines.join("\n");
}
if (info.type === "blob") {
const filePath = info.path || "";
const fullFilePath = resolveWithinRepo(localPath, filePath);
if (!fullFilePath || !existsSync(fullFilePath)) {
lines.push(`Path \`${filePath}\` not found in clone. Showing repository root instead.`);
lines.push("");
lines.push("## Structure");
lines.push(buildTree(localPath));
lines.push("");
lines.push("Use `read` and `bash` tools at the path above to explore further.");
return lines.join("\n");
}
let stat: ReturnType<typeof statSync>;
try {
stat = statSync(fullFilePath);
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
lines.push(`Could not inspect \`${filePath}\`: ${message}`);
lines.push("");
lines.push("Use `read` and `bash` tools at the path above to explore further.");
return lines.join("\n");
}
if (stat.isDirectory()) {
lines.push(`## ${filePath || "/"}`);
lines.push(buildDirListing(localPath, filePath));
lines.push("");
lines.push("Use `read` and `bash` tools at the path above to explore further.");
return lines.join("\n");
}
if (isBinaryFile(fullFilePath)) {
const ext = extname(filePath).replace(".", "");
lines.push(`## ${filePath}`);
lines.push(`Binary file (${ext}, ${formatFileSize(stat.size)}). Use \`read\` or \`bash\` tools at the path above to inspect.`);
return lines.join("\n");
}
const content = readTextFile(fullFilePath);
if (content === null) {
lines.push(`Could not read \`${filePath}\` as UTF-8 text.`);
lines.push("");
lines.push("Use `read` and `bash` tools at the path above to explore further.");
return lines.join("\n");
}
lines.push(`## ${filePath}`);
if (content.length > MAX_INLINE_FILE_CHARS) {
lines.push(content.slice(0, MAX_INLINE_FILE_CHARS));
lines.push("");
lines.push(`[File truncated at 100K chars. Full file: ${fullFilePath}]`);
} else {
lines.push(content);
}
lines.push("");
lines.push("Use `read` and `bash` tools at the path above to explore further.");
return lines.join("\n");
}
return lines.join("\n");
}
async function awaitCachedClone(
cached: CachedClone,
url: string,
owner: string,
repo: string,
info: GitHubUrlInfo,
signal?: AbortSignal,
): Promise<ExtractedContent | null> {
if (signal?.aborted) return null;
const result = await cached.clonePromise;
if (signal?.aborted) return null;
if (result) {
const content = generateContent(result, info);
const title = info.path ? `${owner}/${repo} - ${info.path}` : `${owner}/${repo}`;
return { url, title, content, error: null };
}
return fetchViaApi(url, owner, repo, info);
}
export async function extractGitHub(
url: string,
signal?: AbortSignal,
forceClone?: boolean,
): Promise<ExtractedContent | null> {
const info = parseGitHubUrl(url);
if (!info) return null;
if (signal?.aborted) return null;
const config = loadGitHubConfig();
if (!config.enabled) return null;
const { owner, repo } = info;
const key = cacheKey(owner, repo, info.ref);
const cached = cloneCache.get(key);
if (cached) return awaitCachedClone(cached, url, owner, repo, info, signal);
if (info.refIsFullSha) {
if (signal?.aborted) return null;
const sizeNote = `Note: Commit SHA URLs use the GitHub API instead of cloning.`;
return fetchViaApi(url, owner, repo, info, sizeNote);
}
const activityId = activityMonitor.logStart({ type: "fetch", url: `github.com/${owner}/${repo}` });
if (!forceClone) {
const sizeKB = await checkRepoSize(owner, repo);
if (signal?.aborted) {
activityMonitor.logComplete(activityId, 0);
return null;
}
if (sizeKB !== null) {
const sizeMB = sizeKB / 1024;
if (sizeMB > config.maxRepoSizeMB) {
if (signal?.aborted) {
activityMonitor.logComplete(activityId, 0);
return null;
}
const sizeNote =
`Note: Repository is ${Math.round(sizeMB)}MB (threshold: ${config.maxRepoSizeMB}MB). ` +
`Showing API-fetched content instead of full clone. Ask the user if they'd like to clone the full repo -- ` +
`if yes, call fetch_content again with the same URL and add forceClone: true to the params.`;
const apiView = await fetchViaApi(url, owner, repo, info, sizeNote);
if (apiView) {
activityMonitor.logComplete(activityId, 200);
return apiView;
}
activityMonitor.logError(activityId, "api fallback unavailable for oversized repository");
return null;
}
}
}
if (signal?.aborted) {
activityMonitor.logComplete(activityId, 0);
return null;
}
// Re-check: another concurrent caller may have started a clone while we awaited the size check
const cachedAfterSizeCheck = cloneCache.get(key);
if (cachedAfterSizeCheck) {
const cachedResult = await awaitCachedClone(cachedAfterSizeCheck, url, owner, repo, info, signal);
if (signal?.aborted) {
activityMonitor.logComplete(activityId, 0);
} else if (cachedResult) {
activityMonitor.logComplete(activityId, 200);
} else {
activityMonitor.logError(activityId, "clone failed");
}
return cachedResult;
}
const clonePromise = cloneRepo(owner, repo, info.ref, config, signal);
const localPath = cloneDir(config, owner, repo, info.ref);
cloneCache.set(key, { localPath, clonePromise });
const result = await clonePromise;
if (signal?.aborted) {
if (!result) cloneCache.delete(key);
activityMonitor.logComplete(activityId, 0);
return null;
}
if (!result) {
cloneCache.delete(key);
if (signal?.aborted) {
activityMonitor.logComplete(activityId, 0);
return null;
}
const apiFallback = await fetchViaApi(url, owner, repo, info);
if (apiFallback) {
activityMonitor.logComplete(activityId, 200);
return apiFallback;
}
activityMonitor.logError(activityId, "clone and API fallback failed");
return null;
}
activityMonitor.logComplete(activityId, 200);
const content = generateContent(result, info);
const title = info.path ? `${owner}/${repo} - ${info.path}` : `${owner}/${repo}`;
return { url, title, content, error: null };
}
export function clearCloneCache(): void {
for (const entry of cloneCache.values()) {
try {
rmSync(entry.localPath, { recursive: true, force: true });
} catch {
}
}
cloneCache.clear();
cachedConfig = null;
}