@xynogen/pix-find 0.2.2 → 0.2.4

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xynogen/pix-find",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "Pi tool — glob file search",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
@@ -13,6 +13,7 @@
13
13
  },
14
14
  "files": [
15
15
  "src",
16
+ "!src/**/*.test.*",
16
17
  "README.md",
17
18
  "LICENSE"
18
19
  ],
@@ -38,7 +39,7 @@
38
39
  "access": "public"
39
40
  },
40
41
  "dependencies": {
41
- "@xynogen/pix-pretty": "^1.11.2",
42
+ "@xynogen/pix-pretty": "^1.19.0",
42
43
  "@xynogen/pix-runtime": "^0.8.0"
43
44
  },
44
45
  "peerDependencies": {
package/src/find.ts CHANGED
@@ -17,6 +17,7 @@ import type {
17
17
  import {
18
18
  appendNotices,
19
19
  fillToolBackground,
20
+ frameToolResult,
20
21
  getTextContent,
21
22
  hideCollapsedToolCall,
22
23
  makeTextResult,
@@ -25,6 +26,7 @@ import {
25
26
  renderDimPreview,
26
27
  renderToolError,
27
28
  setResultDetails,
29
+ unframeToolResult,
28
30
  } from "@xynogen/pix-pretty/utils";
29
31
  import { type CollapseState, tickCollapse } from "@xynogen/pix-runtime/collapse";
30
32
 
@@ -170,14 +172,15 @@ export function registerFindTool(
170
172
  renderCtx: RenderContextLike,
171
173
  ) {
172
174
  resolveBaseBackground(theme);
173
- const text = renderCtx.lastComponent ?? new TextComponent("", 0, 0);
175
+ const text = unframeToolResult(renderCtx.lastComponent ?? new TextComponent("", 0, 0));
174
176
  const d = result.details;
175
177
  const isPartial = _opt?.isPartial === true;
178
+ const completed = () => frameToolResult(text, theme, renderCtx.isError);
176
179
  const structuredError = renderCtx.isError && d?._type === "findResult";
177
180
 
178
181
  if (renderCtx.isError && (!structuredError || isPartial)) {
179
182
  text.setText(renderToolError(getTextContent(result) || "Error", theme));
180
- return text;
183
+ return isPartial ? text : completed();
181
184
  }
182
185
 
183
186
  // Auto-collapse: show summary line after delay
@@ -203,14 +206,14 @@ export function registerFindTool(
203
206
 
204
207
  if (renderCtx.isError) {
205
208
  text.setText(renderToolError(getTextContent(result) || "Error", theme));
206
- return text;
209
+ return completed();
207
210
  }
208
211
 
209
212
  const output = getTextContent(result) || "found";
210
213
  // One framed shape; rules follow status color. Count lives in the collapsed row.
211
214
  text.setText(
212
215
  renderDimPreview(output, theme, {
213
- frame: true,
216
+ frame: !isPartial,
214
217
  paint: (s: string) => theme.fg(renderCtx.isError ? "error" : "success", s),
215
218
  highlight: d?._type === "findResult" ? globHighlight(d.pattern) : undefined,
216
219
  }),
package/src/find.test.ts DELETED
@@ -1,250 +0,0 @@
1
- import { describe, expect, it } from "bun:test";
2
- import type { CursorStore, FffState } from "@xynogen/pix-pretty/fff";
3
- import type {
4
- PiPrettyApi,
5
- RenderContextLike,
6
- TextComponentCtor,
7
- ThemeLike,
8
- } from "@xynogen/pix-pretty/types";
9
- import { applyFindDefaults, DEFAULT_FIND_LIMIT, globHighlight, registerFindTool } from "./find";
10
-
11
- describe("globHighlight", () => {
12
- it("keeps literal runs from a glob as case-insensitive alternatives", () => {
13
- const re = globHighlight("**/*.test.ts");
14
- expect(re).toBeInstanceOf(RegExp);
15
- expect((re as RegExp).flags).toBe("gi");
16
- expect("foo.test.ts".match(re as RegExp)).not.toBeNull();
17
- });
18
-
19
- it("highlights the extension of a simple glob", () => {
20
- expect("app.ts".match(globHighlight("*.ts") as RegExp)?.[0]).toBe(".ts");
21
- });
22
-
23
- it("returns undefined when the glob has no meaningful literal run", () => {
24
- expect(globHighlight("*")).toBeUndefined();
25
- });
26
- });
27
-
28
- class MockTextComponent {
29
- private text = "";
30
- setText(v: string) {
31
- this.text = v;
32
- }
33
- getText() {
34
- return this.text;
35
- }
36
- }
37
-
38
- describe("applyFindDefaults", () => {
39
- it("applies a conservative default without overriding an explicit limit", () => {
40
- expect(applyFindDefaults({ pattern: "**/*.ts" })).toEqual({
41
- pattern: "**/*.ts",
42
- limit: DEFAULT_FIND_LIMIT,
43
- });
44
- expect(applyFindDefaults({ pattern: "**/*.ts", limit: 8 })).toEqual({
45
- pattern: "**/*.ts",
46
- limit: 8,
47
- });
48
- });
49
- });
50
-
51
- describe("registerFindTool", () => {
52
- it("registers a tool named 'find'", () => {
53
- const tools: string[] = [];
54
- const mockPi: PiPrettyApi = {
55
- registerTool(t: unknown) {
56
- tools.push((t as { name: string }).name);
57
- },
58
- registerCommand() {},
59
- on() {},
60
- };
61
-
62
- registerFindTool(
63
- mockPi,
64
- () => ({ execute: async () => ({ content: [], details: undefined }) }),
65
- {
66
- cwd: process.cwd(),
67
- sp: (p: string) => p,
68
- TextComponent: MockTextComponent as unknown as TextComponentCtor,
69
- fffState: {
70
- module: null,
71
- finder: null,
72
- partialIndex: false,
73
- dbDir: null,
74
- } satisfies FffState,
75
- cursorStore: {
76
- store: () => "",
77
- get: () => undefined,
78
- } as unknown as CursorStore,
79
- },
80
- );
81
- expect(tools).toEqual(["find"]);
82
- });
83
-
84
- it("restores result paths when an elapsed card is expanded", () => {
85
- const registered: { renderResult?: (...args: unknown[]) => MockTextComponent } = {};
86
- const mockPi: PiPrettyApi = {
87
- registerTool(tool: unknown) {
88
- Object.assign(registered, tool);
89
- },
90
- registerCommand() {},
91
- on() {},
92
- };
93
- registerFindTool(
94
- mockPi,
95
- () => ({ execute: async () => ({ content: [], details: undefined }) }),
96
- {
97
- cwd: process.cwd(),
98
- sp: (p: string) => p,
99
- TextComponent: MockTextComponent as unknown as TextComponentCtor,
100
- fffState: { module: null, finder: null, partialIndex: false, dbDir: null },
101
- cursorStore: { store: () => "", get: () => undefined } as unknown as CursorStore,
102
- },
103
- );
104
- const theme: ThemeLike = {
105
- fg: (_key: string, value: string) => value,
106
- bold: (value: string) => value,
107
- };
108
- const result = registered.renderResult?.(
109
- {
110
- content: [{ type: "text", text: "src/one.ts\nsrc/two.ts" }],
111
- details: {
112
- _type: "findResult",
113
- text: "src/one.ts\nsrc/two.ts",
114
- pattern: "**/*.ts",
115
- matchCount: 2,
116
- },
117
- },
118
- undefined,
119
- theme,
120
- {
121
- expanded: true,
122
- isError: false,
123
- invalidate: () => {},
124
- state: { collapsed: true },
125
- } as unknown as RenderContextLike,
126
- );
127
-
128
- const strip = (s: string) => s.replace(/\u001b\[[0-9;]*m/g, "");
129
- const shown = strip(result?.getText() ?? "");
130
- expect(shown).toContain("src/one.ts");
131
- expect(shown).toContain("src/two.ts");
132
- // No floating count header in the framed view — the collapsed row carries it.
133
- expect(shown).not.toContain("2 files");
134
- });
135
-
136
- it("frames single-file output like multi-file (no inline row)", () => {
137
- const registered: { renderResult?: (...args: unknown[]) => MockTextComponent } = {};
138
- const mockPi: PiPrettyApi = {
139
- registerTool(tool: unknown) {
140
- Object.assign(registered, tool);
141
- },
142
- registerCommand() {},
143
- on() {},
144
- };
145
- registerFindTool(
146
- mockPi,
147
- () => ({ execute: async () => ({ content: [], details: undefined }) }),
148
- {
149
- cwd: process.cwd(),
150
- sp: (p: string) => p,
151
- TextComponent: MockTextComponent as unknown as TextComponentCtor,
152
- fffState: {
153
- module: null,
154
- finder: null,
155
- partialIndex: false,
156
- dbDir: null,
157
- } satisfies FffState,
158
- cursorStore: { store: () => "", get: () => undefined } as unknown as CursorStore,
159
- },
160
- );
161
- const theme: ThemeLike = { fg: (_k: string, v: string) => v, bold: (v: string) => v };
162
- const strip = (s: string) => s.replace(/\u001b\[[0-9;]*m/g, "");
163
- const result = {
164
- content: [{ type: "text", text: "src/a.ts" }],
165
- details: { _type: "findResult", text: "src/a.ts", pattern: "*.ts", matchCount: 1 } as never,
166
- };
167
- const out =
168
- registered
169
- .renderResult?.(result, { isPartial: false }, theme, {
170
- expanded: false,
171
- isError: false,
172
- invalidate: () => {},
173
- state: {},
174
- } as unknown as RenderContextLike)
175
- ?.getText() ?? "";
176
- // Single result is framed just like multi — one shape, no inline row.
177
- expect(out).toContain("─");
178
- expect(strip(out)).toContain("src/a.ts");
179
- expect(strip(out)).not.toContain("file");
180
- const multi = {
181
- content: [{ type: "text", text: "a.ts\nb.ts\nc.ts" }],
182
- details: {
183
- _type: "findResult",
184
- text: "a.ts\nb.ts\nc.ts",
185
- pattern: "*.ts",
186
- matchCount: 3,
187
- } as never,
188
- };
189
- const multiOut =
190
- registered
191
- .renderResult?.(multi, { isPartial: false }, theme, {
192
- expanded: false,
193
- isError: false,
194
- invalidate: () => {},
195
- state: {},
196
- } as unknown as RenderContextLike)
197
- ?.getText() ?? "";
198
- expect(multiOut).toContain("─");
199
- });
200
-
201
- it("collapses structured errors and restores the exact diagnostic on expansion", () => {
202
- const registered: { renderResult?: (...args: unknown[]) => MockTextComponent } = {};
203
- const mockPi: PiPrettyApi = {
204
- registerTool(tool: unknown) {
205
- Object.assign(registered, tool);
206
- },
207
- registerCommand() {},
208
- on() {},
209
- };
210
- registerFindTool(
211
- mockPi,
212
- () => ({ execute: async () => ({ content: [], details: undefined }) }),
213
- {
214
- cwd: process.cwd(),
215
- sp: (p: string) => p,
216
- TextComponent: MockTextComponent as unknown as TextComponentCtor,
217
- fffState: { module: null, finder: null, partialIndex: false, dbDir: null },
218
- cursorStore: { store: () => "", get: () => undefined } as unknown as CursorStore,
219
- },
220
- );
221
- const theme: ThemeLike = {
222
- fg: (_key: string, value: string) => value,
223
- bold: (value: string) => value,
224
- };
225
- const diagnostic = "Invalid glob pattern: [";
226
- const result = {
227
- content: [{ type: "text", text: diagnostic }],
228
- details: {
229
- _type: "findResult",
230
- text: diagnostic,
231
- pattern: "[",
232
- path: "src",
233
- matchCount: 0,
234
- },
235
- };
236
- const render = (state: Record<string, unknown>, expanded = false) =>
237
- registered
238
- .renderResult?.(result, { isPartial: false }, theme, {
239
- expanded,
240
- isError: true,
241
- invalidate: () => {},
242
- state,
243
- } as unknown as RenderContextLike)
244
- ?.getText() ?? "";
245
-
246
- expect(render({ timer: 1 })).toContain(diagnostic);
247
- expect(render({ collapsed: true })).toContain("✗ find [ in src · failed");
248
- expect(render({ collapsed: true }, true)).toContain(diagnostic);
249
- });
250
- });