pi-tool-discipline 0.1.10 → 0.1.11

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.
@@ -70,13 +70,16 @@ async function walk(dir: string, out: string[], state: WalkState, signal?: Abort
70
70
  const lst = await lstat(p);
71
71
  throwIfAborted(signal);
72
72
  if (lst.isSymbolicLink()) continue; // never follow symlinks
73
- if (lst.isDirectory()) await walk(p, out, state, signal, depth + 1);
74
- else if (lst.isFile()) out.push(p); // regular files only
73
+ if (lst.isDirectory()) {
74
+ await walk(p, out, state, signal, depth + 1);
75
+ throwIfAborted(signal);
76
+ } else if (lst.isFile()) out.push(p); // regular files only
75
77
  } catch (error: any) {
76
- if (error?.message === "Operation aborted") throw error;
78
+ throwIfAborted(signal); // cancellation wins over the fs error
77
79
  // unreadable entries are skipped
78
80
  }
79
81
  }
82
+ throwIfAborted(signal); // post-recursion check
80
83
  }
81
84
 
82
85
  /**
@@ -126,13 +129,16 @@ export async function grepFiles(opts: {
126
129
  const pattern = opts.caseSensitive ? opts.pattern : opts.pattern.toLowerCase();
127
130
  const limit = opts.maxResults ?? 100;
128
131
  const { files, state } = await walkFiles(root, opts.signal);
132
+ throwIfAborted(opts.signal);
129
133
  if (state.rootError) return `Error: cannot read search root ${root}: ${state.rootError}`;
130
134
  const matches: FileMatch[] = [];
131
135
  for (const file of files) {
132
136
  throwIfAborted(opts.signal);
133
137
  if (matches.length >= limit) break;
134
138
  try {
135
- if ((await stat(file)).size > MAX_FILE_BYTES) continue; // cap only before reading content
139
+ const size = (await stat(file)).size;
140
+ throwIfAborted(opts.signal);
141
+ if (size > MAX_FILE_BYTES) continue; // cap only before reading content
136
142
  } catch (error: any) {
137
143
  throwIfAborted(opts.signal);
138
144
  continue;
@@ -175,6 +181,7 @@ export async function findFiles(opts: {
175
181
  const root = await resolveRoot(opts.cwd, opts.path, opts.signal);
176
182
  if (!root) return `Error: search path not found: ${resolve(opts.cwd, opts.path || ".")}`;
177
183
  const { files, state } = await walkFiles(root, opts.signal);
184
+ throwIfAborted(opts.signal);
178
185
  if (state.rootError) return `Error: cannot read search root ${root}: ${state.rootError}`;
179
186
  const needle = opts.pattern?.toLowerCase();
180
187
  // Match against the RELATIVE path so a pattern matching an ancestor
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-tool-discipline",
3
- "version": "0.1.10",
3
+ "version": "0.1.11",
4
4
  "description": "pi extension: enforce ffgrep/fffind-first search discipline and neutralize the default bash file-operation guideline",
5
5
  "type": "module",
6
6
  "license": "MIT",