@xynogen/pix-find 0.1.12 → 0.1.14
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 +2 -2
- package/src/find.test.ts +14 -1
- package/src/find.ts +28 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xynogen/pix-find",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.14",
|
|
4
4
|
"description": "Pi tool — glob file search",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.ts",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"access": "public"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@xynogen/pix-pretty": "^1.7.
|
|
37
|
+
"@xynogen/pix-pretty": "^1.7.20",
|
|
38
38
|
"@xynogen/pix-data": "^0.3.0"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
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
|
@@ -18,12 +18,20 @@ import {
|
|
|
18
18
|
appendNotices,
|
|
19
19
|
fillToolBackground,
|
|
20
20
|
getTextContent,
|
|
21
|
+
hideCollapsedToolCall,
|
|
21
22
|
makeTextResult,
|
|
23
|
+
renderCollapsedToolRow,
|
|
22
24
|
renderDimPreview,
|
|
23
25
|
renderToolError,
|
|
24
26
|
setResultDetails,
|
|
25
27
|
} from "@xynogen/pix-pretty/utils";
|
|
26
28
|
|
|
29
|
+
export const DEFAULT_FIND_LIMIT = 200;
|
|
30
|
+
|
|
31
|
+
export function applyFindDefaults(params: FindParams): FindParams {
|
|
32
|
+
return params.limit === undefined ? { ...params, limit: DEFAULT_FIND_LIMIT } : params;
|
|
33
|
+
}
|
|
34
|
+
|
|
27
35
|
export function registerFindTool(
|
|
28
36
|
pi: PiPrettyApi,
|
|
29
37
|
createFindTool: ToolFactory<FindToolInput>,
|
|
@@ -35,6 +43,8 @@ export function registerFindTool(
|
|
|
35
43
|
pi.registerTool({
|
|
36
44
|
...origFind,
|
|
37
45
|
name: "find",
|
|
46
|
+
description:
|
|
47
|
+
"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
48
|
renderShell: "self",
|
|
39
49
|
|
|
40
50
|
async execute(
|
|
@@ -44,12 +54,14 @@ export function registerFindTool(
|
|
|
44
54
|
upd: unknown,
|
|
45
55
|
toolCtx: ExtensionContext,
|
|
46
56
|
) {
|
|
57
|
+
const effectiveParams = applyFindDefaults(params);
|
|
58
|
+
|
|
47
59
|
// Try FFF first (frecency-ranked, SIMD-accelerated)
|
|
48
60
|
if (fffState.finder && !fffState.finder.isDestroyed) {
|
|
49
61
|
try {
|
|
50
|
-
const effectiveLimit = Math.max(1,
|
|
51
|
-
let query =
|
|
52
|
-
if (
|
|
62
|
+
const effectiveLimit = Math.max(1, effectiveParams.limit ?? DEFAULT_FIND_LIMIT);
|
|
63
|
+
let query = effectiveParams.pattern;
|
|
64
|
+
if (effectiveParams.path) query = `${effectiveParams.path} ${query}`;
|
|
53
65
|
|
|
54
66
|
const searchResult = fffState.finder.fileSearch(query, {
|
|
55
67
|
pageSize: effectiveLimit,
|
|
@@ -69,7 +81,8 @@ export function registerFindTool(
|
|
|
69
81
|
return makeTextResult<FindResultDetails>(textContent, {
|
|
70
82
|
_type: "findResult",
|
|
71
83
|
text: textContent,
|
|
72
|
-
pattern:
|
|
84
|
+
pattern: effectiveParams.pattern,
|
|
85
|
+
path: effectiveParams.path,
|
|
73
86
|
matchCount: trimmed.length,
|
|
74
87
|
});
|
|
75
88
|
}
|
|
@@ -79,7 +92,7 @@ export function registerFindTool(
|
|
|
79
92
|
}
|
|
80
93
|
|
|
81
94
|
// SDK fallback
|
|
82
|
-
const result = await origFind.execute(tid,
|
|
95
|
+
const result = await origFind.execute(tid, effectiveParams, sig, upd as never, toolCtx);
|
|
83
96
|
const textContent = getTextContent(result);
|
|
84
97
|
const matchCount = textContent ? textContent.trim().split("\n").filter(Boolean).length : 0;
|
|
85
98
|
|
|
@@ -87,6 +100,7 @@ export function registerFindTool(
|
|
|
87
100
|
_type: "findResult",
|
|
88
101
|
text: textContent,
|
|
89
102
|
pattern: params.pattern,
|
|
103
|
+
path: params.path,
|
|
90
104
|
matchCount,
|
|
91
105
|
});
|
|
92
106
|
|
|
@@ -97,6 +111,12 @@ export function registerFindTool(
|
|
|
97
111
|
const pattern = args.pattern ?? "";
|
|
98
112
|
const path = args.path ? ` ${theme.fg("muted", `in ${sp(args.path)}`)}` : "";
|
|
99
113
|
const text = renderCtx.lastComponent ?? new TextComponent("", 0, 0);
|
|
114
|
+
if (
|
|
115
|
+
hideCollapsedToolCall(renderCtx.state as CollapseState, renderCtx.expanded, (value) =>
|
|
116
|
+
text.setText(value),
|
|
117
|
+
)
|
|
118
|
+
)
|
|
119
|
+
return text;
|
|
100
120
|
text.setText(
|
|
101
121
|
fillToolBackground(
|
|
102
122
|
`${theme.fg("toolTitle", theme.bold("find"))} ${theme.fg("accent", pattern)}${path}`,
|
|
@@ -124,7 +144,9 @@ export function registerFindTool(
|
|
|
124
144
|
const d = result.details;
|
|
125
145
|
const summary =
|
|
126
146
|
d?._type === "findResult" && d.matchCount != null ? `${d.matchCount} files` : "found";
|
|
127
|
-
|
|
147
|
+
const target = d?._type === "findResult" ? d.pattern : "";
|
|
148
|
+
const scope = d?._type === "findResult" && d.path ? ` in ${sp(d.path)}` : "";
|
|
149
|
+
text.setText(renderCollapsedToolRow(theme, "find", `${target}${scope}`, summary));
|
|
128
150
|
return text;
|
|
129
151
|
}
|
|
130
152
|
|