@oh-my-pi/pi-coding-agent 8.4.2 → 8.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/tools/read.ts CHANGED
@@ -16,7 +16,7 @@ import { renderCodeCell, renderOutputBlock, renderStatusLine } from "../tui";
16
16
  import { formatDimensionNote, resizeImage } from "../utils/image-resize";
17
17
  import { detectSupportedImageMimeTypeFromFile } from "../utils/mime";
18
18
  import { ensureTool } from "../utils/tools-manager";
19
- import { runFd } from "./find";
19
+ import { runRg } from "./grep";
20
20
  import { applyListLimit } from "./list-limit";
21
21
  import { LsTool } from "./ls";
22
22
  import type { OutputMeta } from "./output-meta";
@@ -164,18 +164,26 @@ async function listCandidateFiles(
164
164
  signal?: AbortSignal,
165
165
  notify?: (message: string) => void,
166
166
  ): Promise<{ files: string[]; truncated: boolean; error?: string }> {
167
- let fdPath: string | undefined;
167
+ let rgPath: string | undefined;
168
168
  try {
169
- fdPath = await ensureTool("fd", { silent: true, notify });
169
+ rgPath = await ensureTool("rg", { silent: true, notify });
170
170
  } catch {
171
- return { files: [], truncated: false, error: "fd not available" };
171
+ return { files: [], truncated: false, error: "rg not available" };
172
172
  }
173
173
 
174
- if (!fdPath) {
175
- return { files: [], truncated: false, error: "fd not available" };
174
+ if (!rgPath) {
175
+ return { files: [], truncated: false, error: "rg not available" };
176
176
  }
177
177
 
178
- const args: string[] = ["--type", "f", "--color=never", "--hidden", "--max-results", String(MAX_FUZZY_CANDIDATES)];
178
+ const args: string[] = [
179
+ "--files",
180
+ "--color=never",
181
+ "--hidden",
182
+ "--glob",
183
+ "!**/.git/**",
184
+ "--glob",
185
+ "!**/node_modules/**",
186
+ ];
179
187
 
180
188
  const gitignoreFiles = new Set<string>();
181
189
  const rootGitignore = path.join(searchRoot, ".gitignore");
@@ -185,20 +193,19 @@ async function listCandidateFiles(
185
193
 
186
194
  try {
187
195
  const gitignoreArgs = [
188
- "--type",
189
- "f",
196
+ "--files",
190
197
  "--color=never",
191
198
  "--hidden",
192
- "--absolute-path",
199
+ "--no-ignore",
200
+ "--glob",
201
+ "!**/.git/**",
202
+ "--glob",
203
+ "!**/node_modules/**",
193
204
  "--glob",
194
205
  ".gitignore",
195
- "--exclude",
196
- "node_modules",
197
- "--exclude",
198
- ".git",
199
206
  searchRoot,
200
207
  ];
201
- const { stdout } = await runFd(fdPath, gitignoreArgs, signal);
208
+ const { stdout } = await runRg(rgPath, gitignoreArgs, signal);
202
209
  const output = stdout.trim();
203
210
  if (output) {
204
211
  const nestedGitignores = output
@@ -224,15 +231,15 @@ async function listCandidateFiles(
224
231
  args.push("--ignore-file", gitignorePath);
225
232
  }
226
233
 
227
- args.push(".", searchRoot);
234
+ args.push(searchRoot);
228
235
 
229
- const { stdout, stderr, exitCode } = await runFd(fdPath, args, signal);
236
+ const { stdout, stderr, exitCode } = await runRg(rgPath, args, signal);
230
237
  const output = stdout.trim();
231
238
 
232
239
  if (!output) {
233
- // fd exit codes: 0 = found, 1 = no matches, other = error
240
+ // rg exit codes: 0 = ok, 1 = no matches, other = error
234
241
  if (exitCode !== 0 && exitCode !== 1) {
235
- return { files: [], truncated: false, error: stderr.trim() || `fd failed (exit ${exitCode})` };
242
+ return { files: [], truncated: false, error: stderr.trim() || `rg failed (exit ${exitCode})` };
236
243
  }
237
244
  return { files: [], truncated: false };
238
245
  }
@@ -242,7 +249,10 @@ async function listCandidateFiles(
242
249
  .map(line => line.replace(/\r$/, "").trim())
243
250
  .filter(line => line.length > 0);
244
251
 
245
- return { files, truncated: files.length >= MAX_FUZZY_CANDIDATES };
252
+ const truncated = files.length > MAX_FUZZY_CANDIDATES;
253
+ const limited = truncated ? files.slice(0, MAX_FUZZY_CANDIDATES) : files;
254
+
255
+ return { files: limited, truncated };
246
256
  }
247
257
 
248
258
  async function findReadPathSuggestions(