@alexion42/pi-web-search 0.1.0

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