@henryqw/pi-add-dir 1.0.1 → 1.0.3
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/README.md +3 -10
- package/extensions/add-dir-helpers.ts +28 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
# `@henryqw/pi-add-dir`
|
|
2
2
|
|
|
3
|
-
Give the current Pi session context, skills, and searchable files from directories outside the
|
|
3
|
+
Give the current Pi session context, skills, and searchable files from directories outside the workspace. Reuse those resources in place without copying or linking their directories.
|
|
4
4
|
|
|
5
5
|

|
|
6
6
|
|
|
7
|
-
## Why
|
|
8
|
-
|
|
9
|
-
- **Created for**: Pi users who keep reusable instructions or skills outside one repository.
|
|
10
|
-
- **Advantage**: Use those resources in place, without copying or linking their directories.
|
|
11
|
-
|
|
12
7
|
## Install
|
|
13
8
|
|
|
14
9
|
```bash
|
|
@@ -35,8 +30,6 @@ Added directories give Pi these resources:
|
|
|
35
30
|
|
|
36
31
|
`/dir-add` reloads when it finds skills. `add_directory` reports when a reload is needed.
|
|
37
32
|
|
|
38
|
-
|
|
33
|
+
## Limits and recovery
|
|
39
34
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
Pi session entry `add-dir:state` stores added directories. It is package-managed; do not edit it. Tree navigation restores the active branch's directories and reloads resources when that set changes.
|
|
35
|
+
Search supports basename and relative-path globs. It skips `.git` and `node_modules`. It uses Node filesystem traversal and returns at most 1,000 results per call.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { readdirSync, readFileSync, realpathSync, statSync } from "node:fs";
|
|
2
|
-
import {
|
|
2
|
+
import { readdir } from "node:fs/promises";
|
|
3
3
|
import { homedir } from "node:os";
|
|
4
4
|
import * as path from "node:path";
|
|
5
5
|
|
|
@@ -152,20 +152,35 @@ export async function findFiles(
|
|
|
152
152
|
const matchPath = normalizedPattern.includes(path.sep);
|
|
153
153
|
const results: string[] = [];
|
|
154
154
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
cwd: root,
|
|
158
|
-
withFileTypes: true,
|
|
159
|
-
exclude: (entry) => entry.isSymbolicLink() || (entry.isDirectory() && SKIPPED_SEARCH_DIRS.has(entry.name)),
|
|
160
|
-
})) {
|
|
155
|
+
const directories = [root];
|
|
156
|
+
while (directories.length > 0) {
|
|
161
157
|
signal?.throwIfAborted();
|
|
162
|
-
|
|
158
|
+
const dir = directories.pop()!;
|
|
159
|
+
let entries;
|
|
160
|
+
try {
|
|
161
|
+
entries = await readdir(dir, { withFileTypes: true });
|
|
162
|
+
} catch (error) {
|
|
163
|
+
signal?.throwIfAborted();
|
|
164
|
+
if (!isMissingPathError(error)) throw error;
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
signal?.throwIfAborted();
|
|
168
|
+
for (const entry of entries) {
|
|
169
|
+
signal?.throwIfAborted();
|
|
170
|
+
if (entry.isSymbolicLink()) continue;
|
|
171
|
+
|
|
172
|
+
const fullPath = path.join(dir, entry.name);
|
|
173
|
+
if (entry.isDirectory()) {
|
|
174
|
+
if (!SKIPPED_SEARCH_DIRS.has(entry.name)) directories.push(fullPath);
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
if (!entry.isFile()) continue;
|
|
163
178
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
179
|
+
const candidate = matchPath ? path.relative(root, fullPath) : entry.name;
|
|
180
|
+
if (!path.matchesGlob(candidate, normalizedPattern)) continue;
|
|
181
|
+
results.push(fullPath);
|
|
182
|
+
if (results.length >= maxResults) return results;
|
|
183
|
+
}
|
|
169
184
|
}
|
|
170
185
|
|
|
171
186
|
return results;
|