@xynogen/pix-find 0.1.11 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xynogen/pix-find",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "description": "Pi tool — glob file search",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
package/src/extension.ts CHANGED
@@ -4,11 +4,7 @@ import {
4
4
  type FindToolInput,
5
5
  } from "@earendil-works/pi-coding-agent";
6
6
  import { CursorStore, fffState } from "@xynogen/pix-pretty/fff";
7
- import type {
8
- PiPrettyApi,
9
- TextComponentCtor,
10
- ToolFactory,
11
- } from "@xynogen/pix-pretty/types";
7
+ import type { PiPrettyApi, TextComponentCtor, ToolFactory } from "@xynogen/pix-pretty/types";
12
8
  import { shortPath } from "@xynogen/pix-pretty/utils";
13
9
  import { registerFindTool } from "./find.js";
14
10
  import { once } from "./once.ts";
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, params.limit ?? 200);
51
- let query = params.pattern;
52
- if (params.path) query = `${params.path} ${query}`;
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,
@@ -58,12 +68,9 @@ export function registerFindTool(
58
68
  const { items, totalMatched } = searchResult.value;
59
69
  const trimmed = items.slice(0, effectiveLimit);
60
70
  const notices: string[] = [];
61
- if (fffState.partialIndex)
62
- notices.push("Warning: partial file index");
63
- if (trimmed.length >= effectiveLimit)
64
- notices.push(`${effectiveLimit} limit reached`);
65
- if (totalMatched > trimmed.length)
66
- notices.push(`${totalMatched} total matches`);
71
+ if (fffState.partialIndex) notices.push("Warning: partial file index");
72
+ if (trimmed.length >= effectiveLimit) notices.push(`${effectiveLimit} limit reached`);
73
+ if (totalMatched > trimmed.length) notices.push(`${totalMatched} total matches`);
67
74
 
68
75
  const textContent = appendNotices(
69
76
  trimmed.map((item) => item.relativePath).join("\n"),
@@ -72,7 +79,7 @@ export function registerFindTool(
72
79
  return makeTextResult<FindResultDetails>(textContent, {
73
80
  _type: "findResult",
74
81
  text: textContent,
75
- pattern: params.pattern,
82
+ pattern: effectiveParams.pattern,
76
83
  matchCount: trimmed.length,
77
84
  });
78
85
  }
@@ -82,17 +89,9 @@ export function registerFindTool(
82
89
  }
83
90
 
84
91
  // SDK fallback
85
- const result = await origFind.execute(
86
- tid,
87
- params,
88
- sig,
89
- upd as never,
90
- toolCtx,
91
- );
92
+ const result = await origFind.execute(tid, effectiveParams, sig, upd as never, toolCtx);
92
93
  const textContent = getTextContent(result);
93
- const matchCount = textContent
94
- ? textContent.trim().split("\n").filter(Boolean).length
95
- : 0;
94
+ const matchCount = textContent ? textContent.trim().split("\n").filter(Boolean).length : 0;
96
95
 
97
96
  setResultDetails<FindResultDetails>(result, {
98
97
  _type: "findResult",
@@ -104,15 +103,9 @@ export function registerFindTool(
104
103
  return result;
105
104
  },
106
105
 
107
- renderCall(
108
- args: FindParams,
109
- theme: ThemeLike,
110
- renderCtx: RenderContextLike,
111
- ) {
106
+ renderCall(args: FindParams, theme: ThemeLike, renderCtx: RenderContextLike) {
112
107
  const pattern = args.pattern ?? "";
113
- const path = args.path
114
- ? ` ${theme.fg("muted", `in ${sp(args.path)}`)}`
115
- : "";
108
+ const path = args.path ? ` ${theme.fg("muted", `in ${sp(args.path)}`)}` : "";
116
109
  const text = renderCtx.lastComponent ?? new TextComponent("", 0, 0);
117
110
  text.setText(
118
111
  fillToolBackground(
@@ -140,9 +133,7 @@ export function registerFindTool(
140
133
  if (tickCollapse("find", cs, renderCtx.invalidate)) {
141
134
  const d = result.details;
142
135
  const summary =
143
- d?._type === "findResult" && d.matchCount != null
144
- ? `${d.matchCount} files`
145
- : "found";
136
+ d?._type === "findResult" && d.matchCount != null ? `${d.matchCount} files` : "found";
146
137
  text.setText(fillToolBackground(` ${theme.fg("muted", summary)}`));
147
138
  return text;
148
139
  }