pi-agent-ide 0.9.2 → 0.9.4

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.
Files changed (153) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +8 -4
  3. package/dist/chunk-2TTSJOLO.js +23 -0
  4. package/dist/{chunk-X2WFNMQR.js → chunk-6P7LTQZT.js} +1 -1
  5. package/dist/chunk-7C73WVPB.js +1 -0
  6. package/dist/chunk-7OUML24Z.js +13 -0
  7. package/dist/{chunk-IOGWZNWT.js → chunk-AP2BOC24.js} +1 -1
  8. package/dist/chunk-AVJVTF5H.js +1 -0
  9. package/dist/chunk-CJPS4GXD.js +1 -0
  10. package/dist/{chunk-O7V6G3OO.js → chunk-DAZQSXUW.js} +1 -1
  11. package/dist/chunk-DEWWWKUF.js +6 -0
  12. package/dist/chunk-DFXXT6MJ.js +17 -0
  13. package/dist/{chunk-4GBFIGH3.js → chunk-GHO6TCPJ.js} +1 -1
  14. package/dist/{chunk-H7WAM5RH.js → chunk-ICIRQLZ4.js} +2 -2
  15. package/dist/{chunk-HKYVP2Q6.js → chunk-JWSJCEIB.js} +1 -1
  16. package/dist/chunk-K5M65CAF.js +1 -0
  17. package/dist/{chunk-3LVBARLW.js → chunk-KWJD7FBS.js} +1 -1
  18. package/dist/{chunk-VNWGT367.js → chunk-LIQ4BVOB.js} +1 -1
  19. package/dist/chunk-LLP3EIJL.js +1 -0
  20. package/dist/chunk-MJFY4RGT.js +22 -0
  21. package/dist/{chunk-DVNL5NZE.js → chunk-MKDOT76B.js} +1 -1
  22. package/dist/chunk-OTVNO5SX.js +1 -0
  23. package/dist/{chunk-OUCVZBOR.js → chunk-U2N73BUY.js} +9 -9
  24. package/dist/chunk-UGWRUW77.js +6 -0
  25. package/dist/chunk-UI4KSKS3.js +9 -0
  26. package/dist/chunk-XHFAV2NI.js +1 -0
  27. package/dist/entry-0.js +1 -1
  28. package/dist/entry-18.js +1 -1
  29. package/dist/entry-35.js +1 -1
  30. package/dist/entry-47.js +1 -1
  31. package/dist/entry-52.js +1 -1
  32. package/dist/entry-57.js +1 -1
  33. package/dist/entry-58.js +1 -1
  34. package/dist/entry-59.js +1 -1
  35. package/dist/entry-85.js +1 -1
  36. package/dist/entry-93.js +1 -1
  37. package/dist/pi-agent-ide.js +14 -14
  38. package/docs/agent-guides/ssh.md +1 -1
  39. package/docs/architecture.md +1 -1
  40. package/docs/configuration.md +17 -17
  41. package/docs/settings-help.md +1 -1
  42. package/docs/tools.md +1 -1
  43. package/node_modules/pi-agent-doctor/package.json +1 -1
  44. package/node_modules/pi-agent-documentation/package.json +1 -1
  45. package/node_modules/pi-agent-filesystem/package.json +7 -7
  46. package/node_modules/pi-agent-filesystem-image/package.json +3 -3
  47. package/node_modules/pi-agent-filesystem-jq/package.json +5 -5
  48. package/node_modules/pi-agent-filesystem-pdf/package.json +3 -3
  49. package/node_modules/pi-agent-filesystem-text/package.json +3 -3
  50. package/node_modules/pi-agent-ide-ast/package.json +13 -13
  51. package/node_modules/pi-agent-ide-changes/package.json +8 -8
  52. package/node_modules/pi-agent-ide-formatter/package.json +3 -3
  53. package/node_modules/pi-agent-ide-languages/package.json +2 -2
  54. package/node_modules/pi-agent-ide-lint/package.json +7 -7
  55. package/node_modules/pi-agent-ide-lsp/package.json +12 -12
  56. package/node_modules/pi-agent-image/package.json +2 -2
  57. package/node_modules/pi-agent-invariant/package.json +1 -1
  58. package/node_modules/pi-agent-pdf/package.json +2 -2
  59. package/node_modules/pi-agent-pdf/src/pdf-converter.ts +2 -1
  60. package/node_modules/pi-agent-read/package.json +7 -7
  61. package/node_modules/pi-agent-read/src/core/extension.ts +1 -1
  62. package/node_modules/pi-agent-read/src/core/read-core.ts +5 -1
  63. package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +15 -3
  64. package/node_modules/pi-agent-resource/package.json +1 -1
  65. package/node_modules/pi-agent-search/package.json +5 -5
  66. package/node_modules/pi-agent-search/src/core/extension.ts +3 -3
  67. package/node_modules/pi-agent-search-text/package.json +10 -10
  68. package/node_modules/pi-agent-text/package.json +2 -2
  69. package/node_modules/pi-agent-text-anchor-constant/package.json +3 -3
  70. package/node_modules/pi-agent-text-anchor-exact/package.json +3 -3
  71. package/node_modules/pi-agent-text-anchor-line-hash/package.json +5 -5
  72. package/node_modules/pi-agent-text-editor/package.json +9 -9
  73. package/node_modules/pi-agent-text-editor-renderer/index.ts +4 -3
  74. package/node_modules/pi-agent-text-editor-renderer/package.json +5 -5
  75. package/node_modules/pi-agent-text-editor-renderer/src/renderer.ts +6 -2
  76. package/node_modules/pi-agent-text-editor-stale-anchor/package.json +5 -5
  77. package/node_modules/pi-agent-tool-call-interception/package.json +2 -2
  78. package/node_modules/pi-agent-tool-ui/package.json +1 -1
  79. package/node_modules/pi-agent-web/package.json +7 -7
  80. package/node_modules/pi-agent-web-html/package.json +2 -2
  81. package/node_modules/pi-agent-web-image/package.json +3 -3
  82. package/node_modules/pi-agent-web-pdf/package.json +3 -3
  83. package/node_modules/pi-agent-web-text/package.json +3 -3
  84. package/package.json +35 -35
  85. package/skills/configure-agent-ide/SKILL.md +1 -1
  86. package/src/code-review/extension.ts +5 -2
  87. package/src/composite/builtin-extensions.ts +1 -0
  88. package/src/composite/live-presentation.ts +22 -0
  89. package/src/composite/module-labels.ts +4 -0
  90. package/src/composite/module-settings-store.ts +3 -2
  91. package/src/composite/module-settings.ts +118 -30
  92. package/src/composite/nested-tool-rendering.ts +9 -2
  93. package/src/composite/preferences.ts +12 -0
  94. package/src/composite/presets.ts +1 -0
  95. package/src/composite/reload-required.ts +75 -0
  96. package/src/composite/selection.ts +1 -0
  97. package/src/composite/settings-documentation.ts +1 -1
  98. package/src/composite/settings-panel.ts +1 -1
  99. package/src/core/extension.ts +4 -6
  100. package/src/core/live-feature-flag.ts +25 -0
  101. package/src/doctor/arguments.ts +1 -1
  102. package/src/doctor/extension.ts +3 -3
  103. package/src/doctor/run.ts +1 -1
  104. package/src/doctor/tip-provider.ts +1 -1
  105. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +7 -7
  106. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/package.json +3 -3
  107. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/package.json +5 -5
  108. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/package.json +3 -3
  109. package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/package.json +3 -3
  110. package/src/extensions/pi-agent-read/extensions/pi-agent-web/package.json +7 -7
  111. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/package.json +2 -2
  112. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/package.json +3 -3
  113. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/package.json +3 -3
  114. package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/package.json +3 -3
  115. package/src/extensions/pi-agent-read/package.json +7 -7
  116. package/src/extensions/pi-agent-read/src/core/extension.ts +1 -1
  117. package/src/extensions/pi-agent-read/src/core/read-core.ts +5 -1
  118. package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +15 -3
  119. package/src/extensions/pi-agent-search/package.json +5 -5
  120. package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +10 -10
  121. package/src/extensions/pi-agent-search/src/core/extension.ts +3 -3
  122. package/src/extensions/pi-agent-text-editor/package.json +9 -9
  123. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/package.json +3 -3
  124. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/package.json +3 -3
  125. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/package.json +5 -5
  126. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/index.ts +4 -3
  127. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/package.json +5 -5
  128. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/renderer.ts +6 -2
  129. package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +5 -5
  130. package/src/pi-agent-ide.ts +19 -4
  131. package/src/plugins/pi-agent-ide-ast/package.json +13 -13
  132. package/src/plugins/pi-agent-ide-changes/package.json +8 -8
  133. package/src/plugins/pi-agent-ide-formatter/package.json +3 -3
  134. package/src/plugins/pi-agent-ide-languages/package.json +2 -2
  135. package/src/plugins/pi-agent-ide-lint/package.json +7 -7
  136. package/src/plugins/pi-agent-ide-lsp/package.json +12 -12
  137. package/src/plugins/pi-agent-ide-processes/index.ts +4 -0
  138. package/src/plugins/pi-agent-ide-processes/src/ui.ts +9 -1
  139. package/src/plugins/pi-agent-ide-semantic/src/backend.ts +335 -0
  140. package/src/plugins/pi-agent-ide-semantic/src/vera-backend.ts +459 -0
  141. package/src/plugins/pi-agent-ide-terminal/index.ts +2 -1
  142. package/src/plugins/pi-agent-ide-terminal/src/tools.ts +15 -3
  143. package/src/semantic/engine.ts +8 -0
  144. package/src/semantic/extension.ts +186 -0
  145. package/src/semantic/index.ts +65 -0
  146. package/dist/chunk-IUJUECXH.js +0 -9
  147. package/dist/chunk-OBTT5INC.js +0 -6
  148. package/dist/chunk-PCGBM2D6.js +0 -17
  149. package/dist/chunk-RIOPUTUJ.js +0 -6
  150. package/dist/chunk-RIZARTUM.js +0 -23
  151. package/dist/chunk-W7CASEO3.js +0 -1
  152. package/dist/chunk-WAJW4G4F.js +0 -22
  153. package/dist/chunk-XUYIK4TX.js +0 -1
@@ -0,0 +1,335 @@
1
+ import { spawn } from "node:child_process";
2
+ import { createHash } from "node:crypto";
3
+ import { constants } from "node:fs";
4
+ import {
5
+ access,
6
+ chmod,
7
+ copyFile,
8
+ link,
9
+ mkdir,
10
+ mkdtemp,
11
+ rm,
12
+ realpath,
13
+ stat,
14
+ writeFile,
15
+ } from "node:fs/promises";
16
+ import { homedir, tmpdir } from "node:os";
17
+ import { delimiter, isAbsolute, join, relative, resolve, sep } from "node:path";
18
+ import { splitGlobList } from "pi-agent-search/api/search";
19
+
20
+ const VERSION = "1.8.5";
21
+ const RELEASE = `https://github.com/lightonai/next-plaid/releases/download/v${VERSION}`;
22
+ const ASSETS: Record<string, { name: string; sha256: string }> = {
23
+ "linux:x64": {
24
+ name: "colgrep-x86_64-unknown-linux-gnu.tar.xz",
25
+ sha256: "532e1da739f6b5d489cdaefd20c5918fa1bb0ff9f456c89098eb49a6379ae205",
26
+ },
27
+ "linux:arm64": {
28
+ name: "colgrep-aarch64-unknown-linux-gnu.tar.xz",
29
+ sha256: "90ccb4132ca34c5202ca3d9789e722446dfed85b3be6247321ee55e1a909f34b",
30
+ },
31
+ "darwin:x64": {
32
+ name: "colgrep-x86_64-apple-darwin.tar.xz",
33
+ sha256: "6f23777e87a7cee9c31846514bc0a70736df71f201abfff6aedb51dc27ec6c2a",
34
+ },
35
+ "darwin:arm64": {
36
+ name: "colgrep-aarch64-apple-darwin.tar.xz",
37
+ sha256: "2cd013c820a6ba9d4066c58ce7e6b75ea614dd77a9a18a88836e005f1ef126bc",
38
+ },
39
+ "win32:x64": {
40
+ name: "colgrep-x86_64-pc-windows-msvc.zip",
41
+ sha256: "4f8f240ccbf17740e70d36b798904cf592622719bf11e9c1c86dc01cf9f2c42d",
42
+ },
43
+ };
44
+
45
+ export interface BackendOptions {
46
+ readonly env?: NodeJS.ProcessEnv;
47
+ readonly signal?: AbortSignal;
48
+ readonly onProgress?: (message: string) => void;
49
+ }
50
+
51
+ export interface ProjectStatus {
52
+ readonly usable: boolean;
53
+ readonly executable?: string;
54
+ readonly indexPath?: string;
55
+ }
56
+
57
+ function localProject(cwd: string): string {
58
+ if (/^[a-z][a-z\d+.-]*:\/\//iu.test(cwd))
59
+ throw new Error("Semantic search supports local projects only");
60
+ return resolve(cwd);
61
+ }
62
+
63
+ function managedDirectory(env: NodeJS.ProcessEnv): string {
64
+ const home = env.HOME || env.USERPROFILE || homedir();
65
+ return process.platform === "win32"
66
+ ? join(env.LOCALAPPDATA || join(home, "AppData", "Local"), "pi-agent-ide", "bin")
67
+ : join(env.XDG_DATA_HOME || join(home, ".local", "share"), "pi-agent-ide", "bin");
68
+ }
69
+
70
+ function binaryName(): string {
71
+ return process.platform === "win32" ? "colgrep.exe" : "colgrep";
72
+ }
73
+
74
+ async function run(
75
+ command: string,
76
+ args: readonly string[],
77
+ cwd: string,
78
+ options: BackendOptions,
79
+ ): Promise<string> {
80
+ options.signal?.throwIfAborted();
81
+ return new Promise((resolveRun, reject) => {
82
+ const child = spawn(command, [...args], {
83
+ cwd,
84
+ env: options.env ?? process.env,
85
+ signal: options.signal,
86
+ windowsHide: true,
87
+ stdio: ["ignore", "pipe", "pipe"],
88
+ });
89
+ let stdout = "";
90
+ let stderr = "";
91
+ child.stdout.setEncoding("utf8");
92
+ child.stderr.setEncoding("utf8");
93
+ child.stdout.on("data", (chunk: string) => {
94
+ stdout = (stdout + chunk).slice(-4_000_000);
95
+ options.onProgress?.(chunk);
96
+ });
97
+ child.stderr.on("data", (chunk: string) => {
98
+ stderr = (stderr + chunk).slice(-64_000);
99
+ options.onProgress?.(chunk);
100
+ });
101
+ child.on("error", reject);
102
+ child.on("close", (code) =>
103
+ code === 0
104
+ ? resolveRun(stdout)
105
+ : reject(new Error(`${command} exited with code ${code}: ${stderr.trim()}`)),
106
+ );
107
+ });
108
+ }
109
+
110
+ /** Find a working user-installed or IDE-managed ColGREP without downloading anything. */
111
+ export async function findColgrep(options: BackendOptions = {}): Promise<string | undefined> {
112
+ const env = options.env ?? process.env;
113
+ const candidates = [
114
+ ...(env.PATH ?? "")
115
+ .split(delimiter)
116
+ .filter(Boolean)
117
+ .map((dir) => join(dir, binaryName())),
118
+ join(managedDirectory(env), binaryName()),
119
+ join(
120
+ env.CARGO_HOME || join(env.HOME || env.USERPROFILE || homedir(), ".cargo"),
121
+ "bin",
122
+ binaryName(),
123
+ ),
124
+ ];
125
+ for (const candidate of new Set(candidates)) {
126
+ options.signal?.throwIfAborted();
127
+ try {
128
+ await access(candidate, process.platform === "win32" ? constants.F_OK : constants.X_OK);
129
+ const version = await run(candidate, ["--version"], process.cwd(), {
130
+ ...options,
131
+ signal: options.signal
132
+ ? AbortSignal.any([options.signal, AbortSignal.timeout(5000)])
133
+ : AbortSignal.timeout(5000),
134
+ onProgress: undefined,
135
+ });
136
+ if (/^colgrep\s+\d+\.\d+\.\d+/u.test(version)) return candidate;
137
+ } catch {
138
+ options.signal?.throwIfAborted();
139
+ }
140
+ }
141
+ return undefined;
142
+ }
143
+
144
+ /** Detect the index used by ColGREP, including an existing indexed parent project. */
145
+ export async function inspectProject(
146
+ cwd: string,
147
+ options: BackendOptions = {},
148
+ ): Promise<ProjectStatus> {
149
+ const project = localProject(cwd);
150
+ const executable = await findColgrep(options);
151
+ if (!executable) return { usable: false };
152
+ try {
153
+ const status = await run(executable, ["status", "--color", "never"], project, {
154
+ ...options,
155
+ signal: options.signal
156
+ ? AbortSignal.any([options.signal, AbortSignal.timeout(5000)])
157
+ : AbortSignal.timeout(5000),
158
+ onProgress: undefined,
159
+ });
160
+ const indexPath = /^Index:\s+(.+)\s*$/mu.exec(status)?.[1]?.trim();
161
+ if (!indexPath || !(await stat(indexPath)).isDirectory()) return { usable: false, executable };
162
+ return { usable: true, executable, indexPath };
163
+ } catch {
164
+ options.signal?.throwIfAborted();
165
+ return { usable: false, executable };
166
+ }
167
+ }
168
+
169
+ /** Install the pinned, checksum-verified executable in a shared per-user location. */
170
+ async function installColgrep(options: BackendOptions): Promise<string> {
171
+ const asset = ASSETS[`${process.platform}:${process.arch}`];
172
+ if (!asset)
173
+ throw new Error(
174
+ `No ColGREP binary for ${process.platform}/${process.arch}; install colgrep yourself`,
175
+ );
176
+ options.onProgress?.(`Downloading ColGREP ${VERSION}\n`);
177
+ const response = await fetch(`${RELEASE}/${asset.name}`, { signal: options.signal });
178
+ if (!response.ok) throw new Error(`ColGREP download failed: HTTP ${response.status}`);
179
+ const bytes = Buffer.from(await response.arrayBuffer());
180
+ if (createHash("sha256").update(bytes).digest("hex") !== asset.sha256)
181
+ throw new Error("ColGREP download checksum mismatch");
182
+ const temp = await mkdtemp(join(tmpdir(), "pi-colgrep-"));
183
+ try {
184
+ const archive = join(temp, asset.name);
185
+ await writeFile(archive, bytes);
186
+ await run("tar", ["-xf", archive, "-C", temp], temp, { ...options, onProgress: undefined });
187
+ const folder = asset.name.replace(/\.(?:tar\.xz|zip)$/u, "");
188
+ const source = join(temp, folder, binaryName());
189
+ const targetDir = managedDirectory(options.env ?? process.env);
190
+ await mkdir(targetDir, { recursive: true });
191
+ const target = join(targetDir, binaryName());
192
+ const staging = await mkdtemp(join(targetDir, ".install-"));
193
+ try {
194
+ const staged = join(staging, binaryName());
195
+ await copyFile(source, staged, constants.COPYFILE_EXCL);
196
+ if (process.platform !== "win32") await chmod(staged, 0o755);
197
+ try {
198
+ await link(staged, target);
199
+ } catch (error) {
200
+ if ((error as NodeJS.ErrnoException).code !== "EEXIST") throw error;
201
+ // Another explicit setup may have completed concurrently; never overwrite it.
202
+ }
203
+ } finally {
204
+ await rm(staging, { recursive: true, force: true });
205
+ }
206
+ await run(target, ["--version"], temp, { ...options, onProgress: undefined });
207
+ return target;
208
+ } finally {
209
+ await rm(temp, { recursive: true, force: true });
210
+ }
211
+ }
212
+
213
+ /** Explicit opt-in: install only if needed, then create or incrementally update this index. */
214
+ export async function indexProject(
215
+ cwd: string,
216
+ options: BackendOptions = {},
217
+ ): Promise<ProjectStatus> {
218
+ const project = localProject(cwd);
219
+ const executable = (await findColgrep(options)) ?? (await installColgrep(options));
220
+ options.onProgress?.("Indexing project with ColGREP\n");
221
+ await run(executable, ["init", "--yes", "--color", "never"], project, options);
222
+ const status = await inspectProject(project, options);
223
+ if (!status.usable) throw new Error("ColGREP did not create a usable project index");
224
+ return status;
225
+ }
226
+
227
+ /** Search an existing index; ColGREP incrementally refreshes it before every query. */
228
+ export async function searchProject(
229
+ cwd: string,
230
+ query: string,
231
+ options: BackendOptions & {
232
+ readonly limit?: number;
233
+ readonly path?: string;
234
+ readonly include?: string;
235
+ readonly exclude?: string;
236
+ } = {},
237
+ ): Promise<string> {
238
+ const project = localProject(cwd);
239
+ if (!query.trim()) throw new Error("A semantic search query is required");
240
+ const status = await inspectProject(project, options);
241
+ if (!status.usable || !status.executable)
242
+ throw new Error("No usable semantic index for this project");
243
+ const limit = options.limit ?? 15;
244
+ if (!Number.isInteger(limit) || limit < 1 || limit > 100) throw new Error("Invalid result limit");
245
+ let scope: string | undefined;
246
+ let singleFile = false;
247
+ if (options.path !== undefined) {
248
+ if (!options.path.trim() || /^[a-z][a-z\d+.-]*:\/\//iu.test(options.path))
249
+ throw new Error("Invalid semantic search scope");
250
+ const target = resolve(project, options.path);
251
+ const root = await realpath(project);
252
+ let actual: string;
253
+ try {
254
+ actual = await realpath(target);
255
+ } catch {
256
+ throw new Error("Invalid semantic search scope: path does not exist");
257
+ }
258
+ const inside = (base: string, path: string) => {
259
+ const normalizedBase = process.platform === "win32" ? base.toLowerCase() : base;
260
+ const normalizedPath = process.platform === "win32" ? path.toLowerCase() : path;
261
+ return (
262
+ normalizedPath === normalizedBase ||
263
+ normalizedPath.startsWith(
264
+ normalizedBase.endsWith(sep) ? normalizedBase : normalizedBase + sep,
265
+ )
266
+ );
267
+ };
268
+ if (!inside(project, target) || !inside(root, actual))
269
+ throw new Error("Invalid semantic search scope: outside project");
270
+ const info = await stat(actual);
271
+ if (!info.isFile() && !info.isDirectory())
272
+ throw new Error("Invalid semantic search scope: not a file or directory");
273
+ singleFile = info.isFile();
274
+ scope = relative(project, target) || ".";
275
+ }
276
+ const args = ["search", "--json", "--yes", "--color", "never", "-k", String(limit)];
277
+ for (const pattern of splitGlobList(options.include)) args.push("--include", pattern);
278
+ for (const pattern of splitGlobList(options.exclude)) args.push("--exclude", pattern);
279
+ args.push("--", query);
280
+ if (scope !== undefined) args.push(scope);
281
+ const output = await run(status.executable, args, project, options);
282
+ const parsed: unknown = JSON.parse(output);
283
+ if (!Array.isArray(parsed)) throw new Error("Invalid ColGREP search output");
284
+ const files = new Map<string, Set<string>>();
285
+ for (const group of parsed as unknown[]) {
286
+ if (!group || typeof group !== "object" || !("unit" in group))
287
+ throw new Error("Invalid ColGREP search output");
288
+ const { unit } = group;
289
+ if (!unit || typeof unit !== "object" || !("file" in unit) || typeof unit.file !== "string")
290
+ throw new Error("Invalid ColGREP search output");
291
+ const projectPrefix = project.endsWith(sep) ? project : project + sep;
292
+ const file =
293
+ isAbsolute(unit.file) && unit.file.startsWith(projectPrefix)
294
+ ? relative(project, unit.file)
295
+ : unit.file;
296
+ const matches = "matches" in group ? group.matches : undefined;
297
+ if (matches !== undefined && !Array.isArray(matches))
298
+ throw new Error("Invalid ColGREP search output");
299
+ const candidates: unknown[] = matches?.length ? matches : [unit];
300
+ for (const match of candidates) {
301
+ if (
302
+ !match ||
303
+ typeof match !== "object" ||
304
+ !("line" in match) ||
305
+ typeof match.line !== "number" ||
306
+ !("end_line" in match) ||
307
+ typeof match.end_line !== "number" ||
308
+ !("name" in match) ||
309
+ !Number.isInteger(match.line) ||
310
+ !Number.isInteger(match.end_line) ||
311
+ match.line < 1 ||
312
+ match.end_line < match.line ||
313
+ typeof match.name !== "string"
314
+ )
315
+ throw new Error("Invalid ColGREP search output");
316
+ const ranges = files.get(file) ?? new Set<string>();
317
+ ranges.add(`${match.line}-${match.end_line}`);
318
+ files.set(file, ranges);
319
+ }
320
+ }
321
+ if (!files.size) return "No semantic search results.";
322
+ if (singleFile) {
323
+ const lines: string[] = [];
324
+ for (const [file, ranges] of files) {
325
+ const selected = [...ranges];
326
+ lines.push(...selected.slice(0, 15).map((range) => `${file}:${range}`));
327
+ if (selected.length > 15)
328
+ lines.push(`${selected.length - 15} additional retrieved ranges omitted`);
329
+ }
330
+ return `Approximate ranges (read before editing):\n${lines.join("\n")}`;
331
+ }
332
+ return [...files]
333
+ .map(([file, ranges]) => `${file} (${ranges.size} retrieved candidates)`)
334
+ .join("\n");
335
+ }