@xynogen/pix-find 0.1.23 → 0.1.24
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 +68 -3
- package/src/find.ts +31 -18
package/package.json
CHANGED
package/src/find.test.ts
CHANGED
|
@@ -110,8 +110,73 @@ describe("registerFindTool", () => {
|
|
|
110
110
|
|
|
111
111
|
expect(result?.getText()).toContain("src/one.ts");
|
|
112
112
|
expect(result?.getText()).toContain("src/two.ts");
|
|
113
|
-
//
|
|
114
|
-
expect(result?.getText()).toContain("2 files");
|
|
113
|
+
// No floating count header in the framed view — the collapsed row carries it.
|
|
114
|
+
expect(result?.getText()).not.toContain("2 files");
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("frames single-file output like multi-file (no inline row)", () => {
|
|
118
|
+
const registered: { renderResult?: (...args: unknown[]) => MockTextComponent } = {};
|
|
119
|
+
const mockPi: PiPrettyApi = {
|
|
120
|
+
registerTool(tool: unknown) {
|
|
121
|
+
Object.assign(registered, tool);
|
|
122
|
+
},
|
|
123
|
+
registerCommand() {},
|
|
124
|
+
on() {},
|
|
125
|
+
};
|
|
126
|
+
registerFindTool(
|
|
127
|
+
mockPi,
|
|
128
|
+
() => ({ execute: async () => ({ content: [], details: undefined }) }),
|
|
129
|
+
{
|
|
130
|
+
cwd: process.cwd(),
|
|
131
|
+
sp: (p: string) => p,
|
|
132
|
+
TextComponent: MockTextComponent as unknown as TextComponentCtor,
|
|
133
|
+
fffState: {
|
|
134
|
+
module: null,
|
|
135
|
+
finder: null,
|
|
136
|
+
partialIndex: false,
|
|
137
|
+
dbDir: null,
|
|
138
|
+
} satisfies FffState,
|
|
139
|
+
cursorStore: { store: () => "", get: () => undefined } as unknown as CursorStore,
|
|
140
|
+
},
|
|
141
|
+
);
|
|
142
|
+
const theme: ThemeLike = { fg: (_k: string, v: string) => v, bold: (v: string) => v };
|
|
143
|
+
const strip = (s: string) => s.replace(/\u001b\[[0-9;]*m/g, "");
|
|
144
|
+
const result = {
|
|
145
|
+
content: [{ type: "text", text: "src/a.ts" }],
|
|
146
|
+
details: { _type: "findResult", text: "src/a.ts", pattern: "*.ts", matchCount: 1 } as never,
|
|
147
|
+
};
|
|
148
|
+
const out =
|
|
149
|
+
registered
|
|
150
|
+
.renderResult?.(result, { isPartial: false }, theme, {
|
|
151
|
+
expanded: false,
|
|
152
|
+
isError: false,
|
|
153
|
+
invalidate: () => {},
|
|
154
|
+
state: {},
|
|
155
|
+
} as unknown as RenderContextLike)
|
|
156
|
+
?.getText() ?? "";
|
|
157
|
+
// Single result is framed just like multi — one shape, no inline row.
|
|
158
|
+
expect(out).toContain("─");
|
|
159
|
+
expect(out).toContain("src/a.ts");
|
|
160
|
+
expect(strip(out)).not.toContain("file");
|
|
161
|
+
const multi = {
|
|
162
|
+
content: [{ type: "text", text: "a.ts\nb.ts\nc.ts" }],
|
|
163
|
+
details: {
|
|
164
|
+
_type: "findResult",
|
|
165
|
+
text: "a.ts\nb.ts\nc.ts",
|
|
166
|
+
pattern: "*.ts",
|
|
167
|
+
matchCount: 3,
|
|
168
|
+
} as never,
|
|
169
|
+
};
|
|
170
|
+
const multiOut =
|
|
171
|
+
registered
|
|
172
|
+
.renderResult?.(multi, { isPartial: false }, theme, {
|
|
173
|
+
expanded: false,
|
|
174
|
+
isError: false,
|
|
175
|
+
invalidate: () => {},
|
|
176
|
+
state: {},
|
|
177
|
+
} as unknown as RenderContextLike)
|
|
178
|
+
?.getText() ?? "";
|
|
179
|
+
expect(multiOut).toContain("─");
|
|
115
180
|
});
|
|
116
181
|
|
|
117
182
|
it("collapses structured errors and restores the exact diagnostic on expansion", () => {
|
|
@@ -160,7 +225,7 @@ describe("registerFindTool", () => {
|
|
|
160
225
|
?.getText() ?? "";
|
|
161
226
|
|
|
162
227
|
expect(render({ timer: 1 })).toContain(diagnostic);
|
|
163
|
-
expect(render({ collapsed: true })).toContain("✗
|
|
228
|
+
expect(render({ collapsed: true })).toContain("✗ find [ in src · failed");
|
|
164
229
|
expect(render({ collapsed: true }, true)).toContain(diagnostic);
|
|
165
230
|
});
|
|
166
231
|
});
|
package/src/find.ts
CHANGED
|
@@ -94,19 +94,35 @@ export function registerFindTool(
|
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
// SDK fallback
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
97
|
+
try {
|
|
98
|
+
const result = await origFind.execute(tid, effectiveParams, sig, upd as never, toolCtx);
|
|
99
|
+
const textContent = getTextContent(result);
|
|
100
|
+
const matchCount = textContent ? textContent.trim().split("\n").filter(Boolean).length : 0;
|
|
101
|
+
|
|
102
|
+
setResultDetails<FindResultDetails>(result, {
|
|
103
|
+
_type: "findResult",
|
|
104
|
+
text: textContent,
|
|
105
|
+
pattern: params.pattern,
|
|
106
|
+
path: params.path,
|
|
107
|
+
matchCount,
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
return result;
|
|
111
|
+
} catch (error) {
|
|
112
|
+
const text = error instanceof Error ? error.message : String(error);
|
|
113
|
+
if (sig?.aborted || /aborted/i.test(text)) throw error;
|
|
114
|
+
return {
|
|
115
|
+
content: [{ type: "text" as const, text }],
|
|
116
|
+
details: {
|
|
117
|
+
_type: "findResult" as const,
|
|
118
|
+
text,
|
|
119
|
+
pattern: params.pattern,
|
|
120
|
+
path: params.path,
|
|
121
|
+
matchCount: 0,
|
|
122
|
+
},
|
|
123
|
+
isError: true,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
110
126
|
},
|
|
111
127
|
|
|
112
128
|
renderCall(args: FindParams, theme: ThemeLike, renderCtx: RenderContextLike) {
|
|
@@ -172,14 +188,11 @@ export function registerFindTool(
|
|
|
172
188
|
}
|
|
173
189
|
|
|
174
190
|
const output = getTextContent(result) || "found";
|
|
191
|
+
// One framed shape; rules follow status color. Count lives in the collapsed row.
|
|
175
192
|
text.setText(
|
|
176
193
|
renderDimPreview(output, theme, {
|
|
177
194
|
frame: true,
|
|
178
|
-
|
|
179
|
-
header:
|
|
180
|
-
d?._type === "findResult" && d.matchCount != null
|
|
181
|
-
? pluralize(d.matchCount, "file")
|
|
182
|
-
: undefined,
|
|
195
|
+
paint: (s: string) => theme.fg(renderCtx.isError ? "error" : "success", s),
|
|
183
196
|
}),
|
|
184
197
|
);
|
|
185
198
|
return text;
|