@kolisachint/hoocode-agent 0.5.49 → 0.5.51
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/CHANGELOG.md +20 -0
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +4 -6
- package/dist/cli/args.js.map +1 -1
- package/dist/core/agent-frontmatter.d.ts +5 -0
- package/dist/core/agent-frontmatter.d.ts.map +1 -1
- package/dist/core/agent-frontmatter.js +10 -7
- package/dist/core/agent-frontmatter.js.map +1 -1
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +1 -1
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/export-html/index.d.ts.map +1 -1
- package/dist/core/export-html/index.js +1 -1
- package/dist/core/export-html/index.js.map +1 -1
- package/dist/core/export-html/template.js +2 -22
- package/dist/core/extensions/index.d.ts +2 -2
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/plugins/authoring.d.ts.map +1 -1
- package/dist/core/extensions/plugins/authoring.js +1 -1
- package/dist/core/extensions/plugins/authoring.js.map +1 -1
- package/dist/core/extensions/plugins/formats/shared.d.ts +1 -1
- package/dist/core/extensions/plugins/formats/shared.d.ts.map +1 -1
- package/dist/core/extensions/plugins/formats/shared.js +1 -1
- package/dist/core/extensions/plugins/formats/shared.js.map +1 -1
- package/dist/core/extensions/plugins/formats/types.d.ts +1 -1
- package/dist/core/extensions/plugins/formats/types.d.ts.map +1 -1
- package/dist/core/extensions/plugins/formats/types.js.map +1 -1
- package/dist/core/extensions/types.d.ts +3 -33
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js +0 -9
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/external-tools.d.ts +3 -3
- package/dist/core/external-tools.d.ts.map +1 -1
- package/dist/core/external-tools.js +5 -5
- package/dist/core/external-tools.js.map +1 -1
- package/dist/core/light.d.ts +2 -2
- package/dist/core/light.d.ts.map +1 -1
- package/dist/core/light.js +2 -2
- package/dist/core/light.js.map +1 -1
- package/dist/core/sdk.d.ts +2 -2
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +4 -4
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/self-docs.d.ts +1 -1
- package/dist/core/self-docs.d.ts.map +1 -1
- package/dist/core/self-docs.js +1 -1
- package/dist/core/self-docs.js.map +1 -1
- package/dist/core/settings-types.d.ts +1 -1
- package/dist/core/settings-types.d.ts.map +1 -1
- package/dist/core/settings-types.js.map +1 -1
- package/dist/core/system-prompt.d.ts +1 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +9 -26
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tools/edit-diff.d.ts.map +1 -1
- package/dist/core/tools/edit-diff.js +326 -101
- package/dist/core/tools/edit-diff.js.map +1 -1
- package/dist/core/tools/fd-utils.d.ts +3 -17
- package/dist/core/tools/fd-utils.d.ts.map +1 -1
- package/dist/core/tools/fd-utils.js +3 -38
- package/dist/core/tools/fd-utils.js.map +1 -1
- package/dist/core/tools/index.d.ts +0 -12
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +2 -11
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/native-search.d.ts +0 -15
- package/dist/core/tools/native-search.d.ts.map +1 -1
- package/dist/core/tools/native-search.js +0 -87
- package/dist/core/tools/native-search.js.map +1 -1
- package/dist/core/tools/propose-plugin.d.ts.map +1 -1
- package/dist/core/tools/propose-plugin.js +1 -1
- package/dist/core/tools/propose-plugin.js.map +1 -1
- package/dist/core/tools/read-dedup.d.ts +14 -1
- package/dist/core/tools/read-dedup.d.ts.map +1 -1
- package/dist/core/tools/read-dedup.js +53 -1
- package/dist/core/tools/read-dedup.js.map +1 -1
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +17 -5
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/search.d.ts +3 -2
- package/dist/core/tools/search.d.ts.map +1 -1
- package/dist/core/tools/search.js +7 -6
- package/dist/core/tools/search.js.map +1 -1
- package/dist/core/tools/subagent.d.ts.map +1 -1
- package/dist/core/tools/subagent.js +1 -1
- package/dist/core/tools/subagent.js.map +1 -1
- package/dist/core/warm-subagent-pool.d.ts.map +1 -1
- package/dist/core/warm-subagent-pool.js +1 -1
- package/dist/core/warm-subagent-pool.js.map +1 -1
- package/dist/extensions/core/permission-gate.d.ts.map +1 -1
- package/dist/extensions/core/permission-gate.js +23 -5
- package/dist/extensions/core/permission-gate.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/init-templates.generated.d.ts.map +1 -1
- package/dist/init-templates.generated.js +10 -10
- package/dist/init-templates.generated.js.map +1 -1
- package/dist/modes/interactive/components/tool-chain-summary.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-chain-summary.js +1 -1
- package/dist/modes/interactive/components/tool-chain-summary.js.map +1 -1
- package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/tree-selector.js +4 -13
- package/dist/modes/interactive/components/tree-selector.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +2 -2
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/utils/tools-manager.d.ts.map +1 -1
- package/dist/utils/tools-manager.js +1 -1
- package/dist/utils/tools-manager.js.map +1 -1
- package/docs/extensions.md +2 -4
- package/docs/modes.md +1 -1
- package/docs/quickstart.md +1 -1
- package/docs/sdk.md +8 -10
- package/docs/settings.md +2 -2
- package/docs/usage.md +3 -3
- package/examples/agents/fork-reviewer.md +1 -1
- package/examples/agents/orchestrator.md +1 -1
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/minimal-mode.ts +1 -188
- package/examples/extensions/plan-mode/README.md +1 -1
- package/examples/extensions/plan-mode/index.ts +2 -2
- package/examples/extensions/preset.ts +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/truncated-tool.ts +1 -1
- package/examples/extensions/with-deps/package.json +1 -1
- package/examples/sdk/05-tools.ts +3 -3
- package/package.json +4 -4
- package/templates/agents/code-review.md +1 -1
- package/templates/agents/explore.md +2 -2
- package/templates/agents/general-purpose.md +1 -1
- package/templates/agents/plan.md +2 -2
- package/templates/agents/security-review.md +1 -1
- package/templates/modes/ask/system.md +1 -1
- package/templates/modes/debug/system.md +1 -1
- package/templates/skills/artifact-design/SKILL.md +1 -1
- package/templates/skills/canvas-design/SKILL.md +1 -1
- package/templates/skills/plugin-authoring/SKILL.md +1 -1
- package/dist/core/tools/find.d.ts +0 -40
- package/dist/core/tools/find.d.ts.map +0 -1
- package/dist/core/tools/find.js +0 -364
- package/dist/core/tools/find.js.map +0 -1
- package/dist/core/tools/grep.d.ts +0 -37
- package/dist/core/tools/grep.d.ts.map +0 -1
- package/dist/core/tools/grep.js +0 -414
- package/dist/core/tools/grep.js.map +0 -1
- package/dist/core/tools/ls.d.ts +0 -49
- package/dist/core/tools/ls.d.ts.map +0 -1
- package/dist/core/tools/ls.js +0 -211
- package/dist/core/tools/ls.js.map +0 -1
|
@@ -17,15 +17,7 @@
|
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
19
|
import type { ExtensionAPI } from "@kolisachint/hoocode-agent";
|
|
20
|
-
import {
|
|
21
|
-
createBashTool,
|
|
22
|
-
createEditTool,
|
|
23
|
-
createFindTool,
|
|
24
|
-
createGrepTool,
|
|
25
|
-
createLsTool,
|
|
26
|
-
createReadTool,
|
|
27
|
-
createWriteTool,
|
|
28
|
-
} from "@kolisachint/hoocode-agent";
|
|
20
|
+
import { createBashTool, createEditTool, createReadTool, createWriteTool } from "@kolisachint/hoocode-agent";
|
|
29
21
|
import { Text } from "@kolisachint/hoocode-tui";
|
|
30
22
|
import { homedir } from "os";
|
|
31
23
|
|
|
@@ -49,9 +41,6 @@ function createBuiltInTools(cwd: string) {
|
|
|
49
41
|
bash: createBashTool(cwd),
|
|
50
42
|
edit: createEditTool(cwd),
|
|
51
43
|
write: createWriteTool(cwd),
|
|
52
|
-
find: createFindTool(cwd),
|
|
53
|
-
grep: createGrepTool(cwd),
|
|
54
|
-
ls: createLsTool(cwd),
|
|
55
44
|
};
|
|
56
45
|
}
|
|
57
46
|
|
|
@@ -247,180 +236,4 @@ export default function (pi: ExtensionAPI) {
|
|
|
247
236
|
return new Text(`\n${theme.fg("toolOutput", text)}`, 0, 0);
|
|
248
237
|
},
|
|
249
238
|
});
|
|
250
|
-
|
|
251
|
-
// =========================================================================
|
|
252
|
-
// Find Tool
|
|
253
|
-
// =========================================================================
|
|
254
|
-
pi.registerTool({
|
|
255
|
-
name: "find",
|
|
256
|
-
label: "find",
|
|
257
|
-
description:
|
|
258
|
-
"Find files by name pattern (glob). Searches recursively from the specified path. Output limited to 200 results.",
|
|
259
|
-
parameters: getBuiltInTools(process.cwd()).find.parameters,
|
|
260
|
-
|
|
261
|
-
async execute(toolCallId, params, signal, onUpdate, ctx) {
|
|
262
|
-
const tools = getBuiltInTools(ctx.cwd);
|
|
263
|
-
return tools.find.execute(toolCallId, params, signal, onUpdate);
|
|
264
|
-
},
|
|
265
|
-
|
|
266
|
-
renderCall(args, theme, _context) {
|
|
267
|
-
const pattern = Array.isArray(args.pattern) ? args.pattern.join(", ") : args.pattern || "";
|
|
268
|
-
const path = shortenPath(args.path || ".");
|
|
269
|
-
const limit = args.limit;
|
|
270
|
-
|
|
271
|
-
let text = `${theme.fg("toolTitle", theme.bold("find"))} ${theme.fg("accent", pattern)}`;
|
|
272
|
-
text += theme.fg("toolOutput", ` in ${path}`);
|
|
273
|
-
if (limit !== undefined) {
|
|
274
|
-
text += theme.fg("toolOutput", ` (limit ${limit})`);
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
return new Text(text, 0, 0);
|
|
278
|
-
},
|
|
279
|
-
|
|
280
|
-
renderResult(result, { expanded }, theme, _context) {
|
|
281
|
-
if (!expanded) {
|
|
282
|
-
// Minimal: just show count
|
|
283
|
-
const textContent = result.content.find((c) => c.type === "text");
|
|
284
|
-
if (textContent?.type === "text") {
|
|
285
|
-
const count = textContent.text.trim().split("\n").filter(Boolean).length;
|
|
286
|
-
if (count > 0) {
|
|
287
|
-
return new Text(theme.fg("muted", ` → ${count} files`), 0, 0);
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
return new Text("", 0, 0);
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
// Expanded: show full results
|
|
294
|
-
const textContent = result.content.find((c) => c.type === "text");
|
|
295
|
-
if (!textContent || textContent.type !== "text") {
|
|
296
|
-
return new Text("", 0, 0);
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
const output = textContent.text
|
|
300
|
-
.trim()
|
|
301
|
-
.split("\n")
|
|
302
|
-
.map((line) => theme.fg("toolOutput", line))
|
|
303
|
-
.join("\n");
|
|
304
|
-
|
|
305
|
-
return new Text(`\n${output}`, 0, 0);
|
|
306
|
-
},
|
|
307
|
-
});
|
|
308
|
-
|
|
309
|
-
// =========================================================================
|
|
310
|
-
// Grep Tool
|
|
311
|
-
// =========================================================================
|
|
312
|
-
pi.registerTool({
|
|
313
|
-
name: "grep",
|
|
314
|
-
label: "grep",
|
|
315
|
-
description:
|
|
316
|
-
"Search file contents by regex pattern. Uses ripgrep for fast searching. Output limited to 200 matches.",
|
|
317
|
-
parameters: getBuiltInTools(process.cwd()).grep.parameters,
|
|
318
|
-
|
|
319
|
-
async execute(toolCallId, params, signal, onUpdate, ctx) {
|
|
320
|
-
const tools = getBuiltInTools(ctx.cwd);
|
|
321
|
-
return tools.grep.execute(toolCallId, params, signal, onUpdate);
|
|
322
|
-
},
|
|
323
|
-
|
|
324
|
-
renderCall(args, theme, _context) {
|
|
325
|
-
const pattern = args.pattern || "";
|
|
326
|
-
const path = shortenPath(args.path || ".");
|
|
327
|
-
const glob = args.glob;
|
|
328
|
-
const limit = args.limit;
|
|
329
|
-
|
|
330
|
-
let text = `${theme.fg("toolTitle", theme.bold("grep"))} ${theme.fg("accent", `/${pattern}/`)}`;
|
|
331
|
-
text += theme.fg("toolOutput", ` in ${path}`);
|
|
332
|
-
if (glob) {
|
|
333
|
-
text += theme.fg("toolOutput", ` (${glob})`);
|
|
334
|
-
}
|
|
335
|
-
if (limit !== undefined) {
|
|
336
|
-
text += theme.fg("toolOutput", ` limit ${limit}`);
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
return new Text(text, 0, 0);
|
|
340
|
-
},
|
|
341
|
-
|
|
342
|
-
renderResult(result, { expanded }, theme, _context) {
|
|
343
|
-
if (!expanded) {
|
|
344
|
-
// Minimal: just show match count
|
|
345
|
-
const textContent = result.content.find((c) => c.type === "text");
|
|
346
|
-
if (textContent?.type === "text") {
|
|
347
|
-
const count = textContent.text.trim().split("\n").filter(Boolean).length;
|
|
348
|
-
if (count > 0) {
|
|
349
|
-
return new Text(theme.fg("muted", ` → ${count} matches`), 0, 0);
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
return new Text("", 0, 0);
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
// Expanded: show full results
|
|
356
|
-
const textContent = result.content.find((c) => c.type === "text");
|
|
357
|
-
if (!textContent || textContent.type !== "text") {
|
|
358
|
-
return new Text("", 0, 0);
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
const output = textContent.text
|
|
362
|
-
.trim()
|
|
363
|
-
.split("\n")
|
|
364
|
-
.map((line) => theme.fg("toolOutput", line))
|
|
365
|
-
.join("\n");
|
|
366
|
-
|
|
367
|
-
return new Text(`\n${output}`, 0, 0);
|
|
368
|
-
},
|
|
369
|
-
});
|
|
370
|
-
|
|
371
|
-
// =========================================================================
|
|
372
|
-
// Ls Tool
|
|
373
|
-
// =========================================================================
|
|
374
|
-
pi.registerTool({
|
|
375
|
-
name: "ls",
|
|
376
|
-
label: "ls",
|
|
377
|
-
description:
|
|
378
|
-
"List directory contents with file sizes. Shows files and directories with their sizes. Output limited to 500 entries.",
|
|
379
|
-
parameters: getBuiltInTools(process.cwd()).ls.parameters,
|
|
380
|
-
|
|
381
|
-
async execute(toolCallId, params, signal, onUpdate, ctx) {
|
|
382
|
-
const tools = getBuiltInTools(ctx.cwd);
|
|
383
|
-
return tools.ls.execute(toolCallId, params, signal, onUpdate);
|
|
384
|
-
},
|
|
385
|
-
|
|
386
|
-
renderCall(args, theme, _context) {
|
|
387
|
-
const path = shortenPath(args.path || ".");
|
|
388
|
-
const limit = args.limit;
|
|
389
|
-
|
|
390
|
-
let text = `${theme.fg("toolTitle", theme.bold("ls"))} ${theme.fg("accent", path)}`;
|
|
391
|
-
if (limit !== undefined) {
|
|
392
|
-
text += theme.fg("toolOutput", ` (limit ${limit})`);
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
return new Text(text, 0, 0);
|
|
396
|
-
},
|
|
397
|
-
|
|
398
|
-
renderResult(result, { expanded }, theme, _context) {
|
|
399
|
-
if (!expanded) {
|
|
400
|
-
// Minimal: just show entry count
|
|
401
|
-
const textContent = result.content.find((c) => c.type === "text");
|
|
402
|
-
if (textContent?.type === "text") {
|
|
403
|
-
const count = textContent.text.trim().split("\n").filter(Boolean).length;
|
|
404
|
-
if (count > 0) {
|
|
405
|
-
return new Text(theme.fg("muted", ` → ${count} entries`), 0, 0);
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
return new Text("", 0, 0);
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
// Expanded: show full listing
|
|
412
|
-
const textContent = result.content.find((c) => c.type === "text");
|
|
413
|
-
if (!textContent || textContent.type !== "text") {
|
|
414
|
-
return new Text("", 0, 0);
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
const output = textContent.text
|
|
418
|
-
.trim()
|
|
419
|
-
.split("\n")
|
|
420
|
-
.map((line) => theme.fg("toolOutput", line))
|
|
421
|
-
.join("\n");
|
|
422
|
-
|
|
423
|
-
return new Text(`\n${output}`, 0, 0);
|
|
424
|
-
},
|
|
425
|
-
});
|
|
426
239
|
}
|
|
@@ -4,7 +4,7 @@ Read-only exploration mode for safe code analysis.
|
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
-
- **Read-only tools**: Restricts available tools to read, bash,
|
|
7
|
+
- **Read-only tools**: Restricts available tools to read, bash, search, question
|
|
8
8
|
- **Bash allowlist**: Only read-only bash commands are allowed
|
|
9
9
|
- **Plan extraction**: Extracts numbered steps from `Plan:` sections
|
|
10
10
|
- **Progress tracking**: Widget shows completion status during execution
|
|
@@ -19,7 +19,7 @@ import { Key } from "@kolisachint/hoocode-tui";
|
|
|
19
19
|
import { extractTodoItems, isSafeCommand, markCompletedSteps, type TodoItem } from "./utils.js";
|
|
20
20
|
|
|
21
21
|
// Tools
|
|
22
|
-
const PLAN_MODE_TOOLS = ["read", "bash", "
|
|
22
|
+
const PLAN_MODE_TOOLS = ["read", "bash", "search", "questionnaire"];
|
|
23
23
|
const NORMAL_MODE_TOOLS = ["read", "bash", "edit", "write"];
|
|
24
24
|
|
|
25
25
|
// Type guard for assistant messages
|
|
@@ -165,7 +165,7 @@ export default function planModeExtension(pi: ExtensionAPI): void {
|
|
|
165
165
|
You are in plan mode - a read-only exploration mode for safe code analysis.
|
|
166
166
|
|
|
167
167
|
Restrictions:
|
|
168
|
-
- You can only use: read, bash,
|
|
168
|
+
- You can only use: read, bash, search, questionnaire
|
|
169
169
|
- You CANNOT use: edit, write (file modifications are disabled)
|
|
170
170
|
- Bash is restricted to an allowlist of read-only commands
|
|
171
171
|
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
* "provider": "openai-codex",
|
|
17
17
|
* "model": "gpt-5.2-codex",
|
|
18
18
|
* "thinkingLevel": "high",
|
|
19
|
-
* "tools": ["read", "
|
|
20
|
-
* "instructions": "You are in PLANNING MODE. Your job is to deeply understand the problem and create a detailed implementation plan.\n\nRules:\n- DO NOT make any changes. You cannot edit or write files.\n- Read files IN FULL (no offset/limit) to get complete context. Partial reads miss critical details.\n- Explore thoroughly:
|
|
19
|
+
* "tools": ["read", "search"],
|
|
20
|
+
* "instructions": "You are in PLANNING MODE. Your job is to deeply understand the problem and create a detailed implementation plan.\n\nRules:\n- DO NOT make any changes. You cannot edit or write files.\n- Read files IN FULL (no offset/limit) to get complete context. Partial reads miss critical details.\n- Explore thoroughly: search for related code, find similar patterns, understand the architecture.\n- Ask clarifying questions if requirements are ambiguous. Do not assume.\n- Identify risks, edge cases, and dependencies before proposing solutions.\n\nOutput:\n- Create a structured plan with numbered steps.\n- For each step: what to change, why, and potential risks.\n- List files that will be modified.\n- Note any tests that should be added or updated.\n\nWhen done, ask the user if they want you to:\n1. Write the plan to a markdown file (e.g., PLAN.md)\n2. Create a GitHub issue with the plan\n3. Proceed to implementation (they should switch to 'implement' preset)"
|
|
21
21
|
* },
|
|
22
22
|
* "implement": {
|
|
23
23
|
* "provider": "anthropic",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* 4. Custom rendering of tool calls and results
|
|
12
12
|
*
|
|
13
13
|
* The `rg` tool here wraps ripgrep with proper truncation. Compare this to the
|
|
14
|
-
* built-in `
|
|
14
|
+
* built-in `search` tool in src/core/tools/search.ts for a more complete implementation.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import { mkdtemp, writeFile } from "node:fs/promises";
|
package/examples/sdk/05-tools.ts
CHANGED
|
@@ -14,14 +14,14 @@ import { createAgentSession, SessionManager } from "@kolisachint/hoocode-agent";
|
|
|
14
14
|
|
|
15
15
|
// Read-only mode (no edit/write)
|
|
16
16
|
await createAgentSession({
|
|
17
|
-
tools: ["read", "
|
|
17
|
+
tools: ["read", "search"],
|
|
18
18
|
sessionManager: SessionManager.inMemory(),
|
|
19
19
|
});
|
|
20
20
|
console.log("Read-only session created");
|
|
21
21
|
|
|
22
22
|
// Custom tool selection
|
|
23
23
|
await createAgentSession({
|
|
24
|
-
tools: ["read", "bash", "
|
|
24
|
+
tools: ["read", "bash", "search"],
|
|
25
25
|
sessionManager: SessionManager.inMemory(),
|
|
26
26
|
});
|
|
27
27
|
console.log("Custom tools session created");
|
|
@@ -38,7 +38,7 @@ console.log("Custom cwd session created");
|
|
|
38
38
|
// Or pick specific tools for custom cwd
|
|
39
39
|
await createAgentSession({
|
|
40
40
|
cwd: customCwd,
|
|
41
|
-
tools: ["read", "bash", "
|
|
41
|
+
tools: ["read", "bash", "search"],
|
|
42
42
|
sessionManager: SessionManager.inMemory(customCwd),
|
|
43
43
|
});
|
|
44
44
|
console.log("Specific tools with custom cwd session created");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kolisachint/hoocode-agent",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.51",
|
|
4
4
|
"description": "Coding agent CLI with read, bash, edit, write tools and session management",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"hoocodeConfig": {
|
|
@@ -50,9 +50,9 @@
|
|
|
50
50
|
"prepublishOnly": "npm run clean && npm run build"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@kolisachint/hoocode-agent-core": "^0.5.
|
|
54
|
-
"@kolisachint/hoocode-ai": "^0.5.
|
|
55
|
-
"@kolisachint/hoocode-tui": "^0.5.
|
|
53
|
+
"@kolisachint/hoocode-agent-core": "^0.5.51",
|
|
54
|
+
"@kolisachint/hoocode-ai": "^0.5.51",
|
|
55
|
+
"@kolisachint/hoocode-tui": "^0.5.51",
|
|
56
56
|
"@silvia-odwyer/photon-node": "^0.3.4",
|
|
57
57
|
"chalk": "^5.5.0",
|
|
58
58
|
"cli-highlight": "^2.1.11",
|
|
@@ -13,7 +13,7 @@ description: |
|
|
|
13
13
|
Output: Ranked findings, each with path:line, the defect, and how it fails.
|
|
14
14
|
Cost: Medium (reads the full diff and surrounding code)
|
|
15
15
|
Isolation: Read-only; can run in parallel with other review tasks
|
|
16
|
-
tools: read, bash,
|
|
16
|
+
tools: read, bash, search
|
|
17
17
|
model: capable
|
|
18
18
|
background: true
|
|
19
19
|
---
|
|
@@ -15,7 +15,7 @@ description: |
|
|
|
15
15
|
Output: Concise summary, file list, or plan. No code changes.
|
|
16
16
|
Cost: Low (read-only)
|
|
17
17
|
Isolation: Can run in parallel with other explore tasks
|
|
18
|
-
tools: read,
|
|
18
|
+
tools: read, search
|
|
19
19
|
model: fast
|
|
20
20
|
background: true
|
|
21
21
|
---
|
|
@@ -23,7 +23,7 @@ You are an explore-only agent running inside hoocode. You read code and produce
|
|
|
23
23
|
|
|
24
24
|
Scope:
|
|
25
25
|
- Do not modify, create, or delete files, and do not run commands.
|
|
26
|
-
- Use read
|
|
26
|
+
- Use read and search to locate and understand code.
|
|
27
27
|
|
|
28
28
|
Method:
|
|
29
29
|
1. Break the task into concrete questions.
|
|
@@ -12,7 +12,7 @@ description: |
|
|
|
12
12
|
Output: The completed result plus a summary of what was done and where.
|
|
13
13
|
Cost: Variable (read + write + run)
|
|
14
14
|
Isolation: Should not run concurrently with other write tasks on the same files
|
|
15
|
-
tools: read, bash, edit, write,
|
|
15
|
+
tools: read, bash, edit, write, search
|
|
16
16
|
model: standard
|
|
17
17
|
delegate: true
|
|
18
18
|
---
|
package/templates/agents/plan.md
CHANGED
|
@@ -14,7 +14,7 @@ description: |
|
|
|
14
14
|
Output: A concrete plan — the approach, the files to change, and the steps.
|
|
15
15
|
Cost: Low–medium (read-only)
|
|
16
16
|
Isolation: Can run in parallel with explore tasks
|
|
17
|
-
tools: read,
|
|
17
|
+
tools: read, search
|
|
18
18
|
model: standard
|
|
19
19
|
background: true
|
|
20
20
|
---
|
|
@@ -24,7 +24,7 @@ isolated context and cannot see the parent conversation.
|
|
|
24
24
|
|
|
25
25
|
Scope:
|
|
26
26
|
- Do not create, modify, or delete files, and do not run commands.
|
|
27
|
-
- Use read
|
|
27
|
+
- Use read and search to understand the code and its structure.
|
|
28
28
|
|
|
29
29
|
Method:
|
|
30
30
|
1. Restate the goal and identify what you need to learn to plan it.
|
|
@@ -14,7 +14,7 @@ description: |
|
|
|
14
14
|
fix.
|
|
15
15
|
Cost: Medium (reads the diff and traces untrusted input)
|
|
16
16
|
Isolation: Read-only; can run in parallel with other review tasks
|
|
17
|
-
tools: read, bash,
|
|
17
|
+
tools: read, bash, search
|
|
18
18
|
model: capable
|
|
19
19
|
background: true
|
|
20
20
|
---
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
You are in **ask mode** — read-only Q&A.
|
|
2
2
|
|
|
3
|
-
Permitted: read files,
|
|
3
|
+
Permitted: read files, search the codebase, explain code, trace logic, compare approaches, debug conceptually.
|
|
4
4
|
Forbidden: edit files, write files, run commands that modify state.
|
|
5
5
|
|
|
6
6
|
When answering:
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
You are in **debug mode** — root-cause analysis only, no file modifications.
|
|
2
2
|
|
|
3
3
|
Process:
|
|
4
|
-
1. **Gather evidence** — read logs, error traces, and relevant source. Run safe diagnostic commands (
|
|
4
|
+
1. **Gather evidence** — read logs, error traces, and relevant source. Run safe diagnostic commands (search, read, non-mutating shell commands).
|
|
5
5
|
2. **Reproduce** — identify the minimal condition that triggers the bug.
|
|
6
6
|
3. **Trace** — follow the full call path from entry point to failure site, citing file and line at each step.
|
|
7
7
|
4. **State the root cause** in one clear sentence.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: artifact-design
|
|
3
3
|
description: Build a self-contained HTML visual written to disk — page, report, dashboard, mockup, diagram, or poster. Load before the first line of markup or CSS whenever something has to look right, or a redesign is asked for. Not for app code the project's own design system already governs.
|
|
4
|
-
allowed-tools: read, write, edit,
|
|
4
|
+
allowed-tools: read, write, edit, search
|
|
5
5
|
---
|
|
6
6
|
|
|
7
7
|
# Designing a visual
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
name: canvas-design
|
|
3
3
|
description: How to make a canvas extension's page good — layout, styling, live state, and the dependency and token constraints the surface imposes. Read when building or editing a canvas; the /new-canvas brief points here.
|
|
4
4
|
disable-model-invocation: true
|
|
5
|
-
allowed-tools: read, write, edit,
|
|
5
|
+
allowed-tools: read, write, edit, search
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
# Designing a canvas
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: plugin-authoring
|
|
3
3
|
description: How to author a portable, reusable hoocode plugin — when a capability is worth extracting, how to name and describe it so it triggers again, and what makes content portable across repos and machines. Use before calling ProposePlugin or UpdatePlugin, or when deciding whether a recipe you just completed is worth keeping.
|
|
4
|
-
allowed-tools: read, write, edit,
|
|
4
|
+
allowed-tools: read, write, edit, search
|
|
5
5
|
---
|
|
6
6
|
|
|
7
7
|
# Authoring a plugin
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import type { AgentTool } from "@kolisachint/hoocode-agent-core";
|
|
2
|
-
import { type Static, Type } from "typebox";
|
|
3
|
-
import type { ToolDefinition } from "../extensions/types.js";
|
|
4
|
-
import { type TruncationResult } from "./truncate.js";
|
|
5
|
-
declare const findSchema: Type.TObject<{
|
|
6
|
-
pattern: Type.TUnion<[Type.TString, Type.TArray<Type.TString>]>;
|
|
7
|
-
path: Type.TOptional<Type.TString>;
|
|
8
|
-
exclude: Type.TOptional<Type.TUnion<[Type.TString, Type.TArray<Type.TString>]>>;
|
|
9
|
-
type: Type.TOptional<Type.TUnion<[Type.TLiteral<"f">, Type.TLiteral<"d">, Type.TLiteral<"l">]>>;
|
|
10
|
-
depth: Type.TOptional<Type.TNumber>;
|
|
11
|
-
limit: Type.TOptional<Type.TNumber>;
|
|
12
|
-
compress: Type.TOptional<Type.TBoolean>;
|
|
13
|
-
}>;
|
|
14
|
-
export type FindToolInput = Static<typeof findSchema>;
|
|
15
|
-
export interface FindToolDetails {
|
|
16
|
-
truncation?: TruncationResult;
|
|
17
|
-
resultLimitReached?: number;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Pluggable operations for the find tool.
|
|
21
|
-
* Override these to delegate file search to remote systems (for example SSH).
|
|
22
|
-
*/
|
|
23
|
-
export interface FindOperations {
|
|
24
|
-
/** Check if path exists */
|
|
25
|
-
exists: (absolutePath: string) => Promise<boolean> | boolean;
|
|
26
|
-
/** Find files matching one or more glob patterns. Returns relative or absolute paths. */
|
|
27
|
-
glob: (patterns: string[], cwd: string, options: {
|
|
28
|
-
ignore: string[];
|
|
29
|
-
limit: number;
|
|
30
|
-
type?: string;
|
|
31
|
-
}) => Promise<string[]> | string[];
|
|
32
|
-
}
|
|
33
|
-
export interface FindToolOptions {
|
|
34
|
-
/** Custom operations for find. Default: local filesystem plus fd */
|
|
35
|
-
operations?: FindOperations;
|
|
36
|
-
}
|
|
37
|
-
export declare function createFindToolDefinition(cwd: string, options?: FindToolOptions): ToolDefinition<typeof findSchema, FindToolDetails | undefined>;
|
|
38
|
-
export declare function createFindTool(cwd: string, options?: FindToolOptions): AgentTool<typeof findSchema>;
|
|
39
|
-
export {};
|
|
40
|
-
//# sourceMappingURL=find.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"find.d.ts","sourceRoot":"","sources":["../../../src/core/tools/find.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAKjE,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAG5C,OAAO,KAAK,EAAE,cAAc,EAA2B,MAAM,wBAAwB,CAAC;AAMtF,OAAO,EAAiC,KAAK,gBAAgB,EAAgB,MAAM,eAAe,CAAC;AAEnG,QAAA,MAAM,UAAU;;;;;;;;EAkBd,CAAC;AAEH,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,UAAU,CAAC,CAAC;AAKtD,MAAM,WAAW,eAAe;IAC/B,UAAU,CAAC,EAAE,gBAAgB,CAAC;IAC9B,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC9B,2BAA2B;IAC3B,MAAM,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;IAC7D,yFAAyF;IACzF,IAAI,EAAE,CACL,QAAQ,EAAE,MAAM,EAAE,EAClB,GAAG,EAAE,MAAM,EACX,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,EAAE,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,KACvD,OAAO,CAAC,MAAM,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC;CAClC;AAQD,MAAM,WAAW,eAAe;IAC/B,oEAAoE;IACpE,UAAU,CAAC,EAAE,cAAc,CAAC;CAC5B;AAoID,wBAAgB,wBAAwB,CACvC,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,eAAe,GACvB,cAAc,CAAC,OAAO,UAAU,EAAE,eAAe,GAAG,SAAS,CAAC,CAmPhE;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,SAAS,CAAC,OAAO,UAAU,CAAC,CAEnG","sourcesContent":["import { createInterface } from \"node:readline\";\nimport type { AgentTool } from \"@kolisachint/hoocode-agent-core\";\nimport { Text } from \"@kolisachint/hoocode-tui\";\nimport { type ChildProcess, spawn } from \"child_process\";\nimport { existsSync } from \"fs\";\nimport path from \"path\";\nimport { type Static, Type } from \"typebox\";\nimport { keyHint } from \"../../modes/interactive/components/keybinding-hints.js\";\nimport { ensureTool } from \"../../utils/tools-manager.js\";\nimport type { ToolDefinition, ToolRenderResultOptions } from \"../extensions/types.js\";\nimport { applyFdGlobPattern, relativizeFdLine, toPosixPath } from \"./fd-utils.js\";\nimport { isNativeSearchForced, nativeFind } from \"./native-search.js\";\nimport { resolveToCwd } from \"./path-utils.js\";\nimport { getTextOutput, invalidArgText, shortenPath, str } from \"./render-utils.js\";\nimport { wrapToolDefinition } from \"./tool-definition-wrapper.js\";\nimport { DEFAULT_MAX_BYTES, formatSize, type TruncationResult, truncateHead } from \"./truncate.js\";\n\nconst findSchema = Type.Object({\n\tpattern: Type.Union([Type.String(), Type.Array(Type.String())], {\n\t\tdescription: \"Glob(s) to match, e.g. 'src/**/*.spec.ts'. An array is OR'd.\",\n\t}),\n\tpath: Type.Optional(Type.String({ description: \"Directory to search in (default: cwd)\" })),\n\texclude: Type.Optional(\n\t\tType.Union([Type.String(), Type.Array(Type.String())], { description: \"Extra exclusion glob(s).\" }),\n\t),\n\ttype: Type.Optional(\n\t\tType.Union([Type.Literal(\"f\"), Type.Literal(\"d\"), Type.Literal(\"l\")], {\n\t\t\tdescription: \"f=files, d=directories, l=symlinks (default: f).\",\n\t\t}),\n\t),\n\tdepth: Type.Optional(Type.Number({ description: \"Maximum directory depth.\" })),\n\tlimit: Type.Optional(Type.Number({ description: \"Maximum results (default: 1000).\" })),\n\tcompress: Type.Optional(\n\t\tType.Boolean({ description: \"Group files by directory to shorten output (default: false).\" }),\n\t),\n});\n\nexport type FindToolInput = Static<typeof findSchema>;\n\nconst DEFAULT_LIMIT = 1000;\nconst NO_RESULTS_MESSAGE = \"No files found matching pattern\";\n\nexport interface FindToolDetails {\n\ttruncation?: TruncationResult;\n\tresultLimitReached?: number;\n}\n\n/**\n * Pluggable operations for the find tool.\n * Override these to delegate file search to remote systems (for example SSH).\n */\nexport interface FindOperations {\n\t/** Check if path exists */\n\texists: (absolutePath: string) => Promise<boolean> | boolean;\n\t/** Find files matching one or more glob patterns. Returns relative or absolute paths. */\n\tglob: (\n\t\tpatterns: string[],\n\t\tcwd: string,\n\t\toptions: { ignore: string[]; limit: number; type?: string },\n\t) => Promise<string[]> | string[];\n}\n\nconst defaultFindOperations: FindOperations = {\n\texists: existsSync,\n\t// This is a placeholder. Actual fd execution happens in execute() when no custom glob is provided.\n\tglob: () => [],\n};\n\nexport interface FindToolOptions {\n\t/** Custom operations for find. Default: local filesystem plus fd */\n\toperations?: FindOperations;\n}\n\n/**\n * Compress a list of file paths by grouping files in the same directory.\n *\n * Compression rules:\n * - If a directory has >=3 entries all sharing the same extension: fold into `dir/{stem1,stem2,stem3}.ext`\n * - If >=3 entries with mixed extensions: sub-group by extension; fold sub-groups >=3\n * - If directory has >6 total files: summarize verbatim after sub-grouping\n * - 1-2 entries: emit verbatim\n */\nfunction compressPaths(paths: string[]): string {\n\tif (paths.length === 0) return \"\";\n\n\tconst sorted = [...paths].sort();\n\n\tconst dirMap = new Map<string, string[]>();\n\tfor (const p of sorted) {\n\t\tconst dir = path.dirname(p);\n\t\tconst base = path.basename(p);\n\t\tif (!dirMap.has(dir)) dirMap.set(dir, []);\n\t\tdirMap.get(dir)!.push(base);\n\t}\n\n\tconst result: string[] = [];\n\n\tfor (const [dir, files] of dirMap) {\n\t\tif (files.length <= 2) {\n\t\t\tfor (const f of files) result.push(dir === \".\" ? f : `${dir}/${f}`);\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst extMap = new Map<string, string[]>();\n\t\tfor (const f of files) {\n\t\t\tconst ext = path.extname(f);\n\t\t\tconst stem = path.basename(f, ext);\n\t\t\tif (!extMap.has(ext)) extMap.set(ext, []);\n\t\t\textMap.get(ext)!.push(stem);\n\t\t}\n\n\t\tif (extMap.size === 1 && files.length >= 3) {\n\t\t\tconst [ext, stems] = extMap.entries().next().value!;\n\t\t\tconst displayDir = dir === \".\" ? \"\" : `${dir}/`;\n\t\t\tresult.push(`${displayDir}{${stems.join(\",\")}}${ext}`);\n\t\t\tcontinue;\n\t\t}\n\n\t\tlet anyFolded = false;\n\t\tconst subResults: string[] = [];\n\t\tfor (const [ext, stems] of extMap) {\n\t\t\tif (stems.length >= 3) {\n\t\t\t\tconst displayDir = dir === \".\" ? \"\" : `${dir}/`;\n\t\t\t\tsubResults.push(`${displayDir}{${stems.join(\",\")}}${ext}`);\n\t\t\t\tanyFolded = true;\n\t\t\t} else {\n\t\t\t\tfor (const stem of stems) subResults.push(dir === \".\" ? `${stem}${ext}` : `${dir}/${stem}${ext}`);\n\t\t\t}\n\t\t}\n\n\t\tif (anyFolded || files.length > 6) {\n\t\t\tresult.push(...subResults);\n\t\t} else {\n\t\t\tfor (const f of files) result.push(dir === \".\" ? f : `${dir}/${f}`);\n\t\t}\n\t}\n\n\treturn result.join(\"\\n\");\n}\n\nfunction formatFindCall(\n\targs: { pattern?: string | string[]; path?: string; type?: string; depth?: number; limit?: number } | undefined,\n\ttheme: typeof import(\"../../modes/interactive/theme/theme.js\").theme,\n): string {\n\tconst patterns = args?.pattern;\n\tconst patternStr = Array.isArray(patterns) ? patterns.join(\", \") : str(patterns);\n\tconst rawPath = str(args?.path);\n\tconst displayPath = rawPath !== null ? shortenPath(rawPath || \".\") : null;\n\tconst type = args?.type;\n\tconst depth = args?.depth;\n\tconst limit = args?.limit;\n\tconst invalidArg = invalidArgText(theme);\n\tlet text =\n\t\ttheme.fg(\"toolTitle\", theme.bold(\"find\")) +\n\t\t\" \" +\n\t\t(patternStr === null || patternStr === \"\" ? invalidArg : theme.fg(\"accent\", patternStr)) +\n\t\ttheme.fg(\"toolOutput\", ` in ${displayPath === null ? invalidArg : displayPath}`);\n\tif (type && type !== \"f\") {\n\t\tconst typeLabel = type === \"d\" ? \"dirs\" : type === \"l\" ? \"symlinks\" : type;\n\t\ttext += theme.fg(\"toolOutput\", ` (${typeLabel})`);\n\t}\n\tif (depth !== undefined) {\n\t\ttext += theme.fg(\"toolOutput\", ` (depth ${depth})`);\n\t}\n\tif (limit !== undefined) {\n\t\ttext += theme.fg(\"toolOutput\", ` (limit ${limit})`);\n\t}\n\treturn text;\n}\n\nfunction formatFindResult(\n\tresult: {\n\t\tcontent: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;\n\t\tdetails?: FindToolDetails;\n\t},\n\toptions: ToolRenderResultOptions,\n\ttheme: typeof import(\"../../modes/interactive/theme/theme.js\").theme,\n\tshowImages: boolean,\n): string {\n\tconst output = getTextOutput(result, showImages).trim();\n\tlet text = \"\";\n\tif (output) {\n\t\tconst lines = output.split(\"\\n\");\n\t\tconst maxLines = options.expanded ? lines.length : 20;\n\t\tconst displayLines = lines.slice(0, maxLines);\n\t\tconst remaining = lines.length - maxLines;\n\t\ttext += `\\n${displayLines.map((line) => theme.fg(\"toolOutput\", line)).join(\"\\n\")}`;\n\t\tif (remaining > 0) {\n\t\t\ttext += `${theme.fg(\"muted\", `\\n... (${remaining} more lines,`)} ${keyHint(\"app.tools.expand\", \"to expand\")})`;\n\t\t}\n\t}\n\n\tconst resultLimit = result.details?.resultLimitReached;\n\tconst truncation = result.details?.truncation;\n\tif (resultLimit || truncation?.truncated) {\n\t\tconst warnings: string[] = [];\n\t\tif (resultLimit) warnings.push(`${resultLimit} results limit`);\n\t\tif (truncation?.truncated) warnings.push(`${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit`);\n\t\ttext += `\\n${theme.fg(\"warning\", `[Truncated: ${warnings.join(\", \")}]`)}`;\n\t}\n\treturn text;\n}\n\nexport function createFindToolDefinition(\n\tcwd: string,\n\toptions?: FindToolOptions,\n): ToolDefinition<typeof findSchema, FindToolDetails | undefined> {\n\tconst customOps = options?.operations;\n\treturn {\n\t\tname: \"find\",\n\t\tlabel: \"find\",\n\t\tdescription: `Locate files by glob. Returns paths relative to the search directory. Respects .gitignore. Truncates at ${DEFAULT_LIMIT} results / ${DEFAULT_MAX_BYTES / 1024}KB.`,\n\t\tpromptSnippet: \"Find files by glob pattern (supports multiple patterns, respects .gitignore)\",\n\t\tparameters: findSchema,\n\t\tasync execute(\n\t\t\t_toolCallId,\n\t\t\t{\n\t\t\t\tpattern: rawPattern,\n\t\t\t\tpath: searchDir,\n\t\t\t\texclude: rawExclude,\n\t\t\t\ttype,\n\t\t\t\tdepth,\n\t\t\t\tlimit,\n\t\t\t\tcompress = false,\n\t\t\t}: {\n\t\t\t\tpattern: string | string[];\n\t\t\t\tpath?: string;\n\t\t\t\texclude?: string | string[];\n\t\t\t\ttype?: \"f\" | \"d\" | \"l\";\n\t\t\t\tdepth?: number;\n\t\t\t\tlimit?: number;\n\t\t\t\tcompress?: boolean;\n\t\t\t},\n\t\t\tsignal?: AbortSignal,\n\t\t\t_onUpdate?,\n\t\t\t_ctx?,\n\t\t) {\n\t\t\treturn new Promise((resolve, reject) => {\n\t\t\t\tif (signal?.aborted) {\n\t\t\t\t\treject(new Error(\"Operation aborted\"));\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tlet settled = false;\n\t\t\t\tlet stopChildren: (() => void) | undefined;\n\t\t\t\tconst settle = (fn: () => void) => {\n\t\t\t\t\tif (settled) return;\n\t\t\t\t\tsettled = true;\n\t\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\tstopChildren = undefined;\n\t\t\t\t\tfn();\n\t\t\t\t};\n\t\t\t\tconst onAbort = () => {\n\t\t\t\t\tstopChildren?.();\n\t\t\t\t\tsettle(() => reject(new Error(\"Operation aborted\")));\n\t\t\t\t};\n\t\t\t\tsignal?.addEventListener(\"abort\", onAbort, { once: true });\n\n\t\t\t\t(async () => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst searchPath = resolveToCwd(searchDir || \".\", cwd);\n\t\t\t\t\t\tconst effectiveLimit = Math.max(1, limit ?? DEFAULT_LIMIT);\n\t\t\t\t\t\tconst ops = customOps ?? defaultFindOperations;\n\n\t\t\t\t\t\tconst patterns = Array.isArray(rawPattern) ? rawPattern : [rawPattern];\n\t\t\t\t\t\tconst excludePatterns = rawExclude ? (Array.isArray(rawExclude) ? rawExclude : [rawExclude]) : [];\n\t\t\t\t\t\t// Always exclude node_modules and .git, plus any caller exclusions.\n\t\t\t\t\t\tconst allIgnore = [\"**/node_modules/**\", \"**/.git/**\", ...excludePatterns];\n\t\t\t\t\t\tconst typeFilter = type === \"d\" ? \"d\" : type === \"l\" ? \"l\" : \"f\";\n\n\t\t\t\t\t\tconst emit = (relativized: string[]) => {\n\t\t\t\t\t\t\tif (relativized.length === 0) {\n\t\t\t\t\t\t\t\tsettle(() =>\n\t\t\t\t\t\t\t\t\tresolve({ content: [{ type: \"text\", text: NO_RESULTS_MESSAGE }], details: undefined }),\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// Sources over-fetch by one so exactly-limit result sets are not\n\t\t\t\t\t\t\t// misreported as truncated.\n\t\t\t\t\t\t\tconst unique = [...new Set(relativized)].sort();\n\t\t\t\t\t\t\tconst resultLimitReached = unique.length > effectiveLimit;\n\t\t\t\t\t\t\tconst truncated = unique.slice(0, effectiveLimit);\n\t\t\t\t\t\t\tconst rawOutput = compress ? compressPaths(truncated) : truncated.join(\"\\n\");\n\t\t\t\t\t\t\tconst truncation = truncateHead(rawOutput, { maxLines: Number.MAX_SAFE_INTEGER });\n\t\t\t\t\t\t\tlet resultOutput = truncation.content;\n\t\t\t\t\t\t\tconst details: FindToolDetails = {};\n\t\t\t\t\t\t\tconst notices: string[] = [];\n\t\t\t\t\t\t\tif (resultLimitReached) {\n\t\t\t\t\t\t\t\tnotices.push(\n\t\t\t\t\t\t\t\t\t`${effectiveLimit} result${effectiveLimit === 1 ? \"\" : \"s\"} limit reached. Use limit=${effectiveLimit * 2} for more, or refine pattern`,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tdetails.resultLimitReached = effectiveLimit;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (truncation.truncated) {\n\t\t\t\t\t\t\t\tnotices.push(`${formatSize(DEFAULT_MAX_BYTES)} limit reached`);\n\t\t\t\t\t\t\t\tdetails.truncation = truncation;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (notices.length > 0) resultOutput += `\\n\\n[${notices.join(\". \")}]`;\n\t\t\t\t\t\t\tsettle(() =>\n\t\t\t\t\t\t\t\tresolve({\n\t\t\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: resultOutput }],\n\t\t\t\t\t\t\t\t\tdetails: Object.keys(details).length > 0 ? details : undefined,\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\t// If custom operations provide glob(), use that instead of fd.\n\t\t\t\t\t\tif (customOps?.glob) {\n\t\t\t\t\t\t\tif (!(await ops.exists(searchPath))) {\n\t\t\t\t\t\t\t\tsettle(() => reject(new Error(`Path not found: ${searchPath}`)));\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (signal?.aborted) {\n\t\t\t\t\t\t\t\tsettle(() => reject(new Error(\"Operation aborted\")));\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tconst results = await ops.glob(patterns, searchPath, {\n\t\t\t\t\t\t\t\tignore: allIgnore,\n\t\t\t\t\t\t\t\tlimit: effectiveLimit + 1,\n\t\t\t\t\t\t\t\ttype: typeFilter,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tif (signal?.aborted) {\n\t\t\t\t\t\t\t\tsettle(() => reject(new Error(\"Operation aborted\")));\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\temit(\n\t\t\t\t\t\t\t\tresults.map((p) => {\n\t\t\t\t\t\t\t\t\tif (p.startsWith(searchPath)) return toPosixPath(p.slice(searchPath.length + 1));\n\t\t\t\t\t\t\t\t\treturn toPosixPath(path.relative(searchPath, p));\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Default implementation uses fd, with a pure-JS fallback when fd is\n\t\t\t\t\t\t// unavailable (restricted environments) or explicitly forced.\n\t\t\t\t\t\tconst fdPath = isNativeSearchForced() ? undefined : await ensureTool(\"fd\", true);\n\t\t\t\t\t\tif (signal?.aborted) {\n\t\t\t\t\t\t\tsettle(() => reject(new Error(\"Operation aborted\")));\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (!fdPath) {\n\t\t\t\t\t\t\tif (!(await ops.exists(searchPath))) {\n\t\t\t\t\t\t\t\tsettle(() => reject(new Error(`Path not found: ${searchPath}`)));\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tconst nativeResults = nativeFind(searchPath, {\n\t\t\t\t\t\t\t\tpatterns,\n\t\t\t\t\t\t\t\ttype: typeFilter,\n\t\t\t\t\t\t\t\texcludeGlobs: allIgnore,\n\t\t\t\t\t\t\t\tmaxDepth: depth,\n\t\t\t\t\t\t\t\t// find always excludes node_modules/.git; the exclude globs above\n\t\t\t\t\t\t\t\t// cover them too, but skipping the dirs avoids descending them.\n\t\t\t\t\t\t\t\talwaysSkipDirs: new Set([\".git\", \"node_modules\"]),\n\t\t\t\t\t\t\t\tsignal,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tif (signal?.aborted) {\n\t\t\t\t\t\t\t\tsettle(() => reject(new Error(\"Operation aborted\")));\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\temit(nativeResults);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst children: ChildProcess[] = [];\n\t\t\t\t\t\tstopChildren = () => {\n\t\t\t\t\t\t\tfor (const child of children) if (!child.killed) child.kill();\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\t// Run each pattern with fd. fd errors (e.g. an invalid glob) surface as a\n\t\t\t\t\t\t// rejection when the pattern produced no output, matching the shell's\n\t\t\t\t\t\t// behavior; a non-zero exit that still produced matches is tolerated.\n\t\t\t\t\t\tconst runPattern = (pattern: string): Promise<string[]> =>\n\t\t\t\t\t\t\tnew Promise<string[]>((res, rej) => {\n\t\t\t\t\t\t\t\tconst args: string[] = [\n\t\t\t\t\t\t\t\t\t\"--glob\",\n\t\t\t\t\t\t\t\t\t\"--color=never\",\n\t\t\t\t\t\t\t\t\t\"--hidden\",\n\t\t\t\t\t\t\t\t\t\"--no-require-git\",\n\t\t\t\t\t\t\t\t\t\"--type\",\n\t\t\t\t\t\t\t\t\ttypeFilter,\n\t\t\t\t\t\t\t\t\t\"--max-results\",\n\t\t\t\t\t\t\t\t\tString(effectiveLimit + 1),\n\t\t\t\t\t\t\t\t];\n\t\t\t\t\t\t\t\tfor (const excl of allIgnore) args.push(\"--exclude\", excl);\n\t\t\t\t\t\t\t\tif (depth !== undefined) args.push(\"--max-depth\", String(depth));\n\t\t\t\t\t\t\t\tconst effectivePattern = applyFdGlobPattern(args, pattern);\n\t\t\t\t\t\t\t\targs.push(\"--\", effectivePattern, searchPath);\n\n\t\t\t\t\t\t\t\tconst child = spawn(fdPath, args, { stdio: [\"ignore\", \"pipe\", \"pipe\"] });\n\t\t\t\t\t\t\t\tchildren.push(child);\n\t\t\t\t\t\t\t\tconst rl = createInterface({ input: child.stdout! });\n\t\t\t\t\t\t\t\tlet stderr = \"\";\n\t\t\t\t\t\t\t\tconst lines: string[] = [];\n\t\t\t\t\t\t\t\tchild.stderr?.on(\"data\", (chunk) => {\n\t\t\t\t\t\t\t\t\tstderr += chunk.toString();\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\trl.on(\"line\", (line) => lines.push(line));\n\t\t\t\t\t\t\t\tchild.on(\"error\", (error) => {\n\t\t\t\t\t\t\t\t\trl.close();\n\t\t\t\t\t\t\t\t\trej(new Error(`Failed to run fd: ${error.message}`));\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\tchild.on(\"close\", (code) => {\n\t\t\t\t\t\t\t\t\trl.close();\n\t\t\t\t\t\t\t\t\tif (code !== 0 && lines.length === 0) {\n\t\t\t\t\t\t\t\t\t\trej(new Error(stderr.trim() || `fd exited with code ${code}`));\n\t\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tres(lines);\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\tconst patternResults = await Promise.all(patterns.map(runPattern));\n\t\t\t\t\t\tif (signal?.aborted) {\n\t\t\t\t\t\t\tsettle(() => reject(new Error(\"Operation aborted\")));\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst relativized: string[] = [];\n\t\t\t\t\t\tfor (const results of patternResults) {\n\t\t\t\t\t\t\tfor (const rawLine of results) {\n\t\t\t\t\t\t\t\tconst line = rawLine.replace(/\\r$/, \"\").trim();\n\t\t\t\t\t\t\t\tif (!line) continue;\n\t\t\t\t\t\t\t\trelativized.push(relativizeFdLine(line, searchPath));\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\temit(relativized);\n\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\tif (signal?.aborted) {\n\t\t\t\t\t\t\tsettle(() => reject(new Error(\"Operation aborted\")));\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst error = e instanceof Error ? e : new Error(String(e));\n\t\t\t\t\t\tsettle(() => reject(error));\n\t\t\t\t\t}\n\t\t\t\t})();\n\t\t\t});\n\t\t},\n\t\trenderCall(args, theme, context) {\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\ttext.setText(formatFindCall(args, theme));\n\t\t\treturn text;\n\t\t},\n\t\trenderResult(result, options, theme, context) {\n\t\t\tconst text = (context.lastComponent as Text | undefined) ?? new Text(\"\", 0, 0);\n\t\t\ttext.setText(formatFindResult(result as any, options, theme, context.showImages));\n\t\t\treturn text;\n\t\t},\n\t};\n}\n\nexport function createFindTool(cwd: string, options?: FindToolOptions): AgentTool<typeof findSchema> {\n\treturn wrapToolDefinition(createFindToolDefinition(cwd, options));\n}\n"]}
|