@henryqw/pi-add-dir 0.1.8 → 0.1.10
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 +2 -12
- package/extensions/add-dir.ts +6 -19
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -26,16 +26,6 @@ Added directories return root `AGENTS.md`, `CLAUDE.md`, `.pi/AGENTS.md`, and `.p
|
|
|
26
26
|
|
|
27
27
|
Search uses Node filesystem traversal, skips `.git` and `node_modules`, supports basename and relative-path globs, and caps results at 1,000 per call.
|
|
28
28
|
|
|
29
|
-
##
|
|
29
|
+
## State
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
pi remove npm:@henryqw/pi-add-dir
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
## Development
|
|
36
|
-
|
|
37
|
-
```bash
|
|
38
|
-
npm test --workspace @henryqw/pi-add-dir
|
|
39
|
-
npm run typecheck --workspace @henryqw/pi-add-dir
|
|
40
|
-
npm run pack:check --workspace @henryqw/pi-add-dir
|
|
41
|
-
```
|
|
31
|
+
Pi session entry `add-dir:state` stores added directories; package-managed, do not edit.
|
package/extensions/add-dir.ts
CHANGED
|
@@ -62,23 +62,11 @@ function readState(data: unknown): AddedDir[] {
|
|
|
62
62
|
return Array.isArray(dirs) ? dirs.filter(isAddedDir) : [];
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
function cleanPath(input: string): string {
|
|
66
|
-
return input.trim();
|
|
67
|
-
}
|
|
68
|
-
|
|
69
65
|
function isWithinDir(dir: string, candidate: string): boolean {
|
|
70
66
|
const relativePath = relative(dir, candidate);
|
|
71
67
|
return relativePath === "" || (!relativePath.startsWith(`..${sep}`) && relativePath !== ".." && !isAbsolute(relativePath));
|
|
72
68
|
}
|
|
73
69
|
|
|
74
|
-
function maxResults(value: number | undefined): number {
|
|
75
|
-
const limit = value ?? DEFAULT_MAX_RESULTS;
|
|
76
|
-
if (!Number.isSafeInteger(limit) || limit < 1 || limit > MAX_RESULTS) {
|
|
77
|
-
throw new Error(`maxResults must be an integer from 1 to ${MAX_RESULTS}.`);
|
|
78
|
-
}
|
|
79
|
-
return limit;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
70
|
function contextDetails(dirCtx: DirContext, absolutePath: string): AddDirectoryDetails {
|
|
83
71
|
return {
|
|
84
72
|
directory: absolutePath,
|
|
@@ -147,7 +135,7 @@ export default function addDirExtension(pi: ExtensionAPI): void {
|
|
|
147
135
|
cwd: string,
|
|
148
136
|
ctx: ExtensionContext,
|
|
149
137
|
): { ok: boolean; message: string; hasNewSkills: boolean; absolutePath?: string; context?: DirContext } {
|
|
150
|
-
const input =
|
|
138
|
+
const input = dirPath.trim();
|
|
151
139
|
if (!input) return { ok: false, message: "Directory path must not be blank.", hasNewSkills: false };
|
|
152
140
|
|
|
153
141
|
const absolutePath = resolveDir(input, cwd);
|
|
@@ -267,7 +255,7 @@ export default function addDirExtension(pi: ExtensionAPI): void {
|
|
|
267
255
|
parameters: AddDirectoryParams,
|
|
268
256
|
|
|
269
257
|
async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
|
|
270
|
-
const inputPath =
|
|
258
|
+
const inputPath = params.path.trim();
|
|
271
259
|
const result = addDir(inputPath, ctx.cwd, ctx);
|
|
272
260
|
if (!result.ok) throw new Error(result.message);
|
|
273
261
|
|
|
@@ -294,7 +282,7 @@ export default function addDirExtension(pi: ExtensionAPI): void {
|
|
|
294
282
|
|
|
295
283
|
renderCall(args, theme) {
|
|
296
284
|
let text = theme.fg("toolTitle", theme.bold("add_directory "));
|
|
297
|
-
text += theme.fg("accent",
|
|
285
|
+
text += theme.fg("accent", args.path.trim());
|
|
298
286
|
if (args.reason) text += theme.fg("dim", ` (${args.reason})`);
|
|
299
287
|
return new Text(text, 0, 0);
|
|
300
288
|
},
|
|
@@ -339,14 +327,13 @@ export default function addDirExtension(pi: ExtensionAPI): void {
|
|
|
339
327
|
throw new Error("No external directories added. Use /dir-add or add_directory first.");
|
|
340
328
|
}
|
|
341
329
|
|
|
342
|
-
const pattern =
|
|
343
|
-
const limit =
|
|
330
|
+
const pattern = params.pattern.trim();
|
|
331
|
+
const limit = params.maxResults ?? DEFAULT_MAX_RESULTS;
|
|
344
332
|
const results: Array<{ dir: string; label: string; files: string[] }> = [];
|
|
345
333
|
let totalFound = 0;
|
|
346
334
|
|
|
347
335
|
for (const dir of addedDirs) {
|
|
348
336
|
signal?.throwIfAborted();
|
|
349
|
-
if (!dirExists(dir.absolutePath)) continue;
|
|
350
337
|
const remaining = limit - totalFound;
|
|
351
338
|
if (remaining <= 0) break;
|
|
352
339
|
|
|
@@ -385,7 +372,7 @@ export default function addDirExtension(pi: ExtensionAPI): void {
|
|
|
385
372
|
|
|
386
373
|
renderCall(args, theme) {
|
|
387
374
|
let text = theme.fg("toolTitle", theme.bold("search_external_files "));
|
|
388
|
-
text += theme.fg("accent", `"${
|
|
375
|
+
text += theme.fg("accent", `"${args.pattern.trim()}"`);
|
|
389
376
|
return new Text(text, 0, 0);
|
|
390
377
|
},
|
|
391
378
|
|