@xynogen/pix-find 0.1.12 → 0.1.13
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/package.json +1 -1
- package/src/find.test.ts +14 -1
- package/src/find.ts +15 -5
package/package.json
CHANGED
package/src/find.test.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, expect, it } from "bun:test";
|
|
2
2
|
import type { CursorStore, FffState } from "@xynogen/pix-pretty/fff";
|
|
3
3
|
import type { PiPrettyApi, TextComponentCtor } from "@xynogen/pix-pretty/types";
|
|
4
|
-
import { registerFindTool } from "./find";
|
|
4
|
+
import { applyFindDefaults, DEFAULT_FIND_LIMIT, registerFindTool } from "./find";
|
|
5
5
|
|
|
6
6
|
class MockTextComponent {
|
|
7
7
|
private text = "";
|
|
@@ -13,6 +13,19 @@ class MockTextComponent {
|
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
describe("applyFindDefaults", () => {
|
|
17
|
+
it("applies a conservative default without overriding an explicit limit", () => {
|
|
18
|
+
expect(applyFindDefaults({ pattern: "**/*.ts" })).toEqual({
|
|
19
|
+
pattern: "**/*.ts",
|
|
20
|
+
limit: DEFAULT_FIND_LIMIT,
|
|
21
|
+
});
|
|
22
|
+
expect(applyFindDefaults({ pattern: "**/*.ts", limit: 8 })).toEqual({
|
|
23
|
+
pattern: "**/*.ts",
|
|
24
|
+
limit: 8,
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
16
29
|
describe("registerFindTool", () => {
|
|
17
30
|
it("registers a tool named 'find'", () => {
|
|
18
31
|
const tools: string[] = [];
|
package/src/find.ts
CHANGED
|
@@ -24,6 +24,12 @@ import {
|
|
|
24
24
|
setResultDetails,
|
|
25
25
|
} from "@xynogen/pix-pretty/utils";
|
|
26
26
|
|
|
27
|
+
export const DEFAULT_FIND_LIMIT = 200;
|
|
28
|
+
|
|
29
|
+
export function applyFindDefaults(params: FindParams): FindParams {
|
|
30
|
+
return params.limit === undefined ? { ...params, limit: DEFAULT_FIND_LIMIT } : params;
|
|
31
|
+
}
|
|
32
|
+
|
|
27
33
|
export function registerFindTool(
|
|
28
34
|
pi: PiPrettyApi,
|
|
29
35
|
createFindTool: ToolFactory<FindToolInput>,
|
|
@@ -35,6 +41,8 @@ export function registerFindTool(
|
|
|
35
41
|
pi.registerTool({
|
|
36
42
|
...origFind,
|
|
37
43
|
name: "find",
|
|
44
|
+
description:
|
|
45
|
+
"Find files by glob pattern. Defaults to 200 paths; use limit to request more. Respects .gitignore and remains capped by Pi's 50KB hard limit.",
|
|
38
46
|
renderShell: "self",
|
|
39
47
|
|
|
40
48
|
async execute(
|
|
@@ -44,12 +52,14 @@ export function registerFindTool(
|
|
|
44
52
|
upd: unknown,
|
|
45
53
|
toolCtx: ExtensionContext,
|
|
46
54
|
) {
|
|
55
|
+
const effectiveParams = applyFindDefaults(params);
|
|
56
|
+
|
|
47
57
|
// Try FFF first (frecency-ranked, SIMD-accelerated)
|
|
48
58
|
if (fffState.finder && !fffState.finder.isDestroyed) {
|
|
49
59
|
try {
|
|
50
|
-
const effectiveLimit = Math.max(1,
|
|
51
|
-
let query =
|
|
52
|
-
if (
|
|
60
|
+
const effectiveLimit = Math.max(1, effectiveParams.limit ?? DEFAULT_FIND_LIMIT);
|
|
61
|
+
let query = effectiveParams.pattern;
|
|
62
|
+
if (effectiveParams.path) query = `${effectiveParams.path} ${query}`;
|
|
53
63
|
|
|
54
64
|
const searchResult = fffState.finder.fileSearch(query, {
|
|
55
65
|
pageSize: effectiveLimit,
|
|
@@ -69,7 +79,7 @@ export function registerFindTool(
|
|
|
69
79
|
return makeTextResult<FindResultDetails>(textContent, {
|
|
70
80
|
_type: "findResult",
|
|
71
81
|
text: textContent,
|
|
72
|
-
pattern:
|
|
82
|
+
pattern: effectiveParams.pattern,
|
|
73
83
|
matchCount: trimmed.length,
|
|
74
84
|
});
|
|
75
85
|
}
|
|
@@ -79,7 +89,7 @@ export function registerFindTool(
|
|
|
79
89
|
}
|
|
80
90
|
|
|
81
91
|
// SDK fallback
|
|
82
|
-
const result = await origFind.execute(tid,
|
|
92
|
+
const result = await origFind.execute(tid, effectiveParams, sig, upd as never, toolCtx);
|
|
83
93
|
const textContent = getTextContent(result);
|
|
84
94
|
const matchCount = textContent ? textContent.trim().split("\n").filter(Boolean).length : 0;
|
|
85
95
|
|