@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
package/dist/core/tools/grep.js
DELETED
|
@@ -1,414 +0,0 @@
|
|
|
1
|
-
import { createInterface } from "node:readline";
|
|
2
|
-
import { compressGrepOutput } from "@kolisachint/hoocode-agent-core";
|
|
3
|
-
import { Text } from "@kolisachint/hoocode-tui";
|
|
4
|
-
import { spawn } from "child_process";
|
|
5
|
-
import { readFileSync, statSync } from "fs";
|
|
6
|
-
import path from "path";
|
|
7
|
-
import { Type } from "typebox";
|
|
8
|
-
import { keyHint } from "../../modes/interactive/components/keybinding-hints.js";
|
|
9
|
-
import { ensureTool } from "../../utils/tools-manager.js";
|
|
10
|
-
import { getEmbsearchService } from "../embsearch/embsearch-service.js";
|
|
11
|
-
import { isNativeSearchForced, nativeGrep } from "./native-search.js";
|
|
12
|
-
import { resolveToCwd } from "./path-utils.js";
|
|
13
|
-
import { getTextOutput, invalidArgText, shortenPath, str } from "./render-utils.js";
|
|
14
|
-
import { wrapToolDefinition } from "./tool-definition-wrapper.js";
|
|
15
|
-
import { DEFAULT_MAX_BYTES, formatSize, GREP_MAX_LINE_LENGTH, truncateHead, truncateLine, } from "./truncate.js";
|
|
16
|
-
const grepSchema = Type.Object({
|
|
17
|
-
pattern: Type.String({ description: "Search pattern (regex or literal string)" }),
|
|
18
|
-
path: Type.Optional(Type.String({ description: "Directory or file to search (default: current directory)" })),
|
|
19
|
-
glob: Type.Optional(Type.String({ description: "Filter files by glob pattern, e.g. '*.ts' or '**/*.spec.ts'" })),
|
|
20
|
-
ignoreCase: Type.Optional(Type.Boolean({ description: "Case-insensitive search (default: false)" })),
|
|
21
|
-
literal: Type.Optional(Type.Boolean({ description: "Treat pattern as literal string instead of regex (default: false)" })),
|
|
22
|
-
context: Type.Optional(Type.Number({ description: "Number of lines to show before and after each match (default: 0)" })),
|
|
23
|
-
limit: Type.Optional(Type.Number({ description: "Maximum number of matches to return (default: 100)" })),
|
|
24
|
-
});
|
|
25
|
-
const DEFAULT_LIMIT = 100;
|
|
26
|
-
/**
|
|
27
|
-
* Match fd/rg semantics for slash-containing globs: rg matches them against the
|
|
28
|
-
* full search path (absolute here), so `src/**\/*.ts` would silently match
|
|
29
|
-
* nothing. Anchor anywhere in the tree by prepending `**\/` unless the caller
|
|
30
|
-
* already did (same normalization the search tool applies).
|
|
31
|
-
*/
|
|
32
|
-
function normalizeGrepGlob(glob) {
|
|
33
|
-
if (!glob)
|
|
34
|
-
return undefined;
|
|
35
|
-
if (glob.includes("/") && !glob.startsWith("/") && !glob.startsWith("**/")) {
|
|
36
|
-
return `**/${glob}`;
|
|
37
|
-
}
|
|
38
|
-
return glob;
|
|
39
|
-
}
|
|
40
|
-
const defaultGrepOperations = {
|
|
41
|
-
isDirectory: (p) => statSync(p).isDirectory(),
|
|
42
|
-
readFile: (p) => readFileSync(p, "utf-8"),
|
|
43
|
-
};
|
|
44
|
-
function formatGrepCall(args, theme) {
|
|
45
|
-
const pattern = str(args?.pattern);
|
|
46
|
-
const rawPath = str(args?.path);
|
|
47
|
-
const path = rawPath !== null ? shortenPath(rawPath || ".") : null;
|
|
48
|
-
const glob = str(args?.glob);
|
|
49
|
-
const limit = args?.limit;
|
|
50
|
-
const invalidArg = invalidArgText(theme);
|
|
51
|
-
let text = theme.fg("toolTitle", theme.bold("grep")) +
|
|
52
|
-
" " +
|
|
53
|
-
(pattern === null ? invalidArg : theme.fg("accent", `/${pattern || ""}/`)) +
|
|
54
|
-
theme.fg("toolOutput", ` in ${path === null ? invalidArg : path}`);
|
|
55
|
-
if (glob)
|
|
56
|
-
text += theme.fg("toolOutput", ` (${glob})`);
|
|
57
|
-
if (limit !== undefined)
|
|
58
|
-
text += theme.fg("toolOutput", ` limit ${limit}`);
|
|
59
|
-
return text;
|
|
60
|
-
}
|
|
61
|
-
function formatGrepResult(result, options, theme, showImages) {
|
|
62
|
-
const output = getTextOutput(result, showImages).trim();
|
|
63
|
-
let text = "";
|
|
64
|
-
if (output) {
|
|
65
|
-
const lines = output.split("\n");
|
|
66
|
-
const maxLines = options.expanded ? lines.length : 15;
|
|
67
|
-
const displayLines = lines.slice(0, maxLines);
|
|
68
|
-
const remaining = lines.length - maxLines;
|
|
69
|
-
text += `\n${displayLines.map((line) => theme.fg("toolOutput", line)).join("\n")}`;
|
|
70
|
-
if (remaining > 0) {
|
|
71
|
-
text += `${theme.fg("muted", `\n... (${remaining} more lines,`)} ${keyHint("app.tools.expand", "to expand")})`;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
const matchLimit = result.details?.matchLimitReached;
|
|
75
|
-
const truncation = result.details?.truncation;
|
|
76
|
-
const linesTruncated = result.details?.linesTruncated;
|
|
77
|
-
if (matchLimit || truncation?.truncated || linesTruncated) {
|
|
78
|
-
const warnings = [];
|
|
79
|
-
if (matchLimit)
|
|
80
|
-
warnings.push(`${matchLimit} matches limit`);
|
|
81
|
-
if (truncation?.truncated)
|
|
82
|
-
warnings.push(`${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit`);
|
|
83
|
-
if (linesTruncated)
|
|
84
|
-
warnings.push("some lines truncated");
|
|
85
|
-
text += `\n${theme.fg("warning", `[Truncated: ${warnings.join(", ")}]`)}`;
|
|
86
|
-
}
|
|
87
|
-
return text;
|
|
88
|
-
}
|
|
89
|
-
export function createGrepToolDefinition(cwd, options) {
|
|
90
|
-
const customOps = options?.operations;
|
|
91
|
-
return {
|
|
92
|
-
name: "grep",
|
|
93
|
-
label: "grep",
|
|
94
|
-
description: `Search file contents for a pattern. Returns matching lines with file paths and line numbers. Case-sensitive by default (set ignoreCase). The pattern is a regex; set literal: true to match plain text. Respects .gitignore; never searches .git. Truncates at ${DEFAULT_LIMIT} matches / ${DEFAULT_MAX_BYTES / 1024}KB, and long lines at ${GREP_MAX_LINE_LENGTH} chars.`,
|
|
95
|
-
promptSnippet: "Search file contents for patterns (respects .gitignore)",
|
|
96
|
-
// No promptGuidelines: buildSystemPrompt already emits the single canonical
|
|
97
|
-
// search-vs-grep guideline whenever both tools are registered. This used to
|
|
98
|
-
// restate it, so the same routing rule shipped twice every turn.
|
|
99
|
-
parameters: grepSchema,
|
|
100
|
-
async execute(_toolCallId, { pattern, path: searchDir, glob, ignoreCase, literal, context, limit, }, signal, _onUpdate, _ctx) {
|
|
101
|
-
return new Promise((resolve, reject) => {
|
|
102
|
-
if (signal?.aborted) {
|
|
103
|
-
reject(new Error("Operation aborted"));
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
let settled = false;
|
|
107
|
-
const settle = (fn) => {
|
|
108
|
-
if (!settled) {
|
|
109
|
-
settled = true;
|
|
110
|
-
fn();
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
(async () => {
|
|
114
|
-
try {
|
|
115
|
-
// An empty pattern matches every line of every file — never useful.
|
|
116
|
-
if (!pattern) {
|
|
117
|
-
settle(() => reject(new Error("pattern must not be empty")));
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
const normalizedGlob = normalizeGrepGlob(glob);
|
|
121
|
-
// rg drives the fast path; when it is unavailable (restricted
|
|
122
|
-
// environments) or forced off, a pure-JS scan produces the same
|
|
123
|
-
// match shape so the tool degrades automatically instead of failing.
|
|
124
|
-
const rgPath = isNativeSearchForced() ? undefined : await ensureTool("rg", true);
|
|
125
|
-
const searchPath = resolveToCwd(searchDir || ".", cwd);
|
|
126
|
-
const ops = customOps ?? defaultGrepOperations;
|
|
127
|
-
let isDirectory;
|
|
128
|
-
try {
|
|
129
|
-
isDirectory = await ops.isDirectory(searchPath);
|
|
130
|
-
}
|
|
131
|
-
catch {
|
|
132
|
-
settle(() => reject(new Error(`Path not found: ${searchPath}`)));
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
const contextValue = context && context > 0 ? context : 0;
|
|
136
|
-
const effectiveLimit = Math.max(1, limit ?? DEFAULT_LIMIT);
|
|
137
|
-
const formatPath = (filePath) => {
|
|
138
|
-
if (isDirectory) {
|
|
139
|
-
const relative = path.relative(searchPath, filePath);
|
|
140
|
-
if (relative && !relative.startsWith("..")) {
|
|
141
|
-
return relative.replace(/\\/g, "/");
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
return path.basename(filePath);
|
|
145
|
-
};
|
|
146
|
-
const fileCache = new Map();
|
|
147
|
-
const getFileLines = async (filePath) => {
|
|
148
|
-
let lines = fileCache.get(filePath);
|
|
149
|
-
if (!lines) {
|
|
150
|
-
try {
|
|
151
|
-
const content = await ops.readFile(filePath);
|
|
152
|
-
lines = content.replace(/\r\n/g, "\n").replace(/\r/g, "\n").split("\n");
|
|
153
|
-
}
|
|
154
|
-
catch {
|
|
155
|
-
lines = [];
|
|
156
|
-
}
|
|
157
|
-
fileCache.set(filePath, lines);
|
|
158
|
-
}
|
|
159
|
-
return lines;
|
|
160
|
-
};
|
|
161
|
-
// Match collection is shared between the rg and native paths.
|
|
162
|
-
const matches = [];
|
|
163
|
-
let matchLimitReached = false;
|
|
164
|
-
let linesTruncated = false;
|
|
165
|
-
// Format a context block around a match line. Path is omitted (emitted once per file).
|
|
166
|
-
const formatBlock = async (filePath, lineNumber) => {
|
|
167
|
-
const lines = await getFileLines(filePath);
|
|
168
|
-
if (!lines.length)
|
|
169
|
-
return [` ${lineNumber}: (unable to read file)`];
|
|
170
|
-
const block = [];
|
|
171
|
-
const start = contextValue > 0 ? Math.max(1, lineNumber - contextValue) : lineNumber;
|
|
172
|
-
const end = contextValue > 0 ? Math.min(lines.length, lineNumber + contextValue) : lineNumber;
|
|
173
|
-
for (let current = start; current <= end; current++) {
|
|
174
|
-
const lineText = lines[current - 1] ?? "";
|
|
175
|
-
const sanitized = lineText.replace(/\r/g, "");
|
|
176
|
-
const isMatchLine = current === lineNumber;
|
|
177
|
-
// Truncate long lines so grep output stays compact.
|
|
178
|
-
const { text: truncatedText, wasTruncated } = truncateLine(sanitized);
|
|
179
|
-
if (wasTruncated)
|
|
180
|
-
linesTruncated = true;
|
|
181
|
-
if (isMatchLine)
|
|
182
|
-
block.push(`${current}: ${truncatedText}`);
|
|
183
|
-
else
|
|
184
|
-
block.push(`${current}- ${truncatedText}`);
|
|
185
|
-
}
|
|
186
|
-
return block;
|
|
187
|
-
};
|
|
188
|
-
// Format the collected matches into the tool result. Shared by both paths.
|
|
189
|
-
const finalize = async () => {
|
|
190
|
-
if (matches.length === 0) {
|
|
191
|
-
const service = getEmbsearchService(cwd);
|
|
192
|
-
const hint = service?.isAvailable()
|
|
193
|
-
? "\n\n[Hint: no exact matches; use the search tool (semantic or hybrid mode) to find conceptually related code]"
|
|
194
|
-
: "";
|
|
195
|
-
settle(() => resolve({
|
|
196
|
-
content: [{ type: "text", text: `No matches found${hint}` }],
|
|
197
|
-
details: undefined,
|
|
198
|
-
}));
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
const outputLines = [];
|
|
202
|
-
// Group matches by file path, showing filename once per file.
|
|
203
|
-
const fileGroups = new Map();
|
|
204
|
-
for (const match of matches) {
|
|
205
|
-
let group = fileGroups.get(match.filePath);
|
|
206
|
-
if (!group) {
|
|
207
|
-
group = [];
|
|
208
|
-
fileGroups.set(match.filePath, group);
|
|
209
|
-
}
|
|
210
|
-
group.push(match);
|
|
211
|
-
}
|
|
212
|
-
for (const [filePath, fileMatches] of fileGroups) {
|
|
213
|
-
const relativePath = formatPath(filePath);
|
|
214
|
-
outputLines.push(relativePath);
|
|
215
|
-
for (const match of fileMatches) {
|
|
216
|
-
if (contextValue === 0 && match.lineText !== undefined) {
|
|
217
|
-
const sanitized = match.lineText
|
|
218
|
-
.replace(/\r\n/g, "\n")
|
|
219
|
-
.replace(/\r/g, "")
|
|
220
|
-
.replace(/\n$/, "");
|
|
221
|
-
const { text: truncatedText, wasTruncated } = truncateLine(sanitized);
|
|
222
|
-
if (wasTruncated)
|
|
223
|
-
linesTruncated = true;
|
|
224
|
-
outputLines.push(`${match.lineNumber}: ${truncatedText}`);
|
|
225
|
-
}
|
|
226
|
-
else {
|
|
227
|
-
const block = await formatBlock(match.filePath, match.lineNumber);
|
|
228
|
-
outputLines.push(...block);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
const rawOutput = outputLines.join("\n");
|
|
233
|
-
// Apply lossless compression then byte truncation.
|
|
234
|
-
const compressedOutput = compressGrepOutput(rawOutput);
|
|
235
|
-
// Apply byte truncation. There is no line limit here because the match limit already capped rows.
|
|
236
|
-
const truncation = truncateHead(compressedOutput, { maxLines: Number.MAX_SAFE_INTEGER });
|
|
237
|
-
let output = truncation.content;
|
|
238
|
-
const details = {};
|
|
239
|
-
// Build actionable notices for truncation and match limits.
|
|
240
|
-
const notices = [];
|
|
241
|
-
if (matchLimitReached) {
|
|
242
|
-
notices.push(`${effectiveLimit} match${effectiveLimit === 1 ? "" : "es"} limit reached. Use limit=${effectiveLimit * 2} for more, or refine pattern`);
|
|
243
|
-
details.matchLimitReached = effectiveLimit;
|
|
244
|
-
}
|
|
245
|
-
if (truncation.truncated) {
|
|
246
|
-
notices.push(`${formatSize(DEFAULT_MAX_BYTES)} limit reached`);
|
|
247
|
-
details.truncation = truncation;
|
|
248
|
-
}
|
|
249
|
-
if (linesTruncated) {
|
|
250
|
-
notices.push(`Some lines truncated to ${GREP_MAX_LINE_LENGTH} chars. Use read tool to see full lines`);
|
|
251
|
-
details.linesTruncated = true;
|
|
252
|
-
}
|
|
253
|
-
if (notices.length > 0)
|
|
254
|
-
output += `\n\n[${notices.join(". ")}]`;
|
|
255
|
-
settle(() => resolve({
|
|
256
|
-
content: [{ type: "text", text: output }],
|
|
257
|
-
details: Object.keys(details).length > 0 ? details : undefined,
|
|
258
|
-
}));
|
|
259
|
-
};
|
|
260
|
-
// --- Native fallback: no rg binary available (or forced off) ---
|
|
261
|
-
if (!rgPath) {
|
|
262
|
-
let result;
|
|
263
|
-
try {
|
|
264
|
-
result = await nativeGrep(searchPath, {
|
|
265
|
-
pattern,
|
|
266
|
-
isDirectory,
|
|
267
|
-
ignoreCase,
|
|
268
|
-
literal,
|
|
269
|
-
glob: normalizedGlob,
|
|
270
|
-
limit: effectiveLimit,
|
|
271
|
-
signal,
|
|
272
|
-
readFile: ops.readFile,
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
catch (e) {
|
|
276
|
-
if (signal?.aborted) {
|
|
277
|
-
settle(() => reject(new Error("Operation aborted")));
|
|
278
|
-
return;
|
|
279
|
-
}
|
|
280
|
-
const err = e;
|
|
281
|
-
let errorMsg = err.message || "grep failed";
|
|
282
|
-
if (err.invalidRegex && !literal) {
|
|
283
|
-
errorMsg += `\n\nThe pattern is not a valid regex. To search for it as plain text, pass literal: true (or escape the regex metacharacters).`;
|
|
284
|
-
}
|
|
285
|
-
settle(() => reject(new Error(errorMsg)));
|
|
286
|
-
return;
|
|
287
|
-
}
|
|
288
|
-
if (signal?.aborted) {
|
|
289
|
-
settle(() => reject(new Error("Operation aborted")));
|
|
290
|
-
return;
|
|
291
|
-
}
|
|
292
|
-
matches.push(...result.matches);
|
|
293
|
-
matchLimitReached = result.matchLimitReached;
|
|
294
|
-
await finalize();
|
|
295
|
-
return;
|
|
296
|
-
}
|
|
297
|
-
// --- Fast path: stream rg --json ---
|
|
298
|
-
// `!.git` because --hidden would otherwise search .git contents;
|
|
299
|
-
// --no-require-git so .gitignore is honored outside git repos too
|
|
300
|
-
// (parity with fd and the native fallback); --sort path forces a
|
|
301
|
-
// deterministic single-threaded walk so the match limit truncates
|
|
302
|
-
// the same subset on every run.
|
|
303
|
-
const args = [
|
|
304
|
-
"--json",
|
|
305
|
-
"--line-number",
|
|
306
|
-
"--color=never",
|
|
307
|
-
"--hidden",
|
|
308
|
-
"--no-require-git",
|
|
309
|
-
"--sort",
|
|
310
|
-
"path",
|
|
311
|
-
"--glob",
|
|
312
|
-
"!**/.git/**",
|
|
313
|
-
];
|
|
314
|
-
if (ignoreCase)
|
|
315
|
-
args.push("--ignore-case");
|
|
316
|
-
if (literal)
|
|
317
|
-
args.push("--fixed-strings");
|
|
318
|
-
if (normalizedGlob)
|
|
319
|
-
args.push("--glob", normalizedGlob);
|
|
320
|
-
args.push("--", pattern, searchPath);
|
|
321
|
-
const child = spawn(rgPath, args, { stdio: ["ignore", "pipe", "pipe"] });
|
|
322
|
-
const rl = createInterface({ input: child.stdout });
|
|
323
|
-
let stderr = "";
|
|
324
|
-
let matchCount = 0;
|
|
325
|
-
let aborted = false;
|
|
326
|
-
let killedDueToLimit = false;
|
|
327
|
-
const cleanup = () => {
|
|
328
|
-
rl.close();
|
|
329
|
-
signal?.removeEventListener("abort", onAbort);
|
|
330
|
-
};
|
|
331
|
-
const stopChild = (dueToLimit = false) => {
|
|
332
|
-
if (!child.killed) {
|
|
333
|
-
killedDueToLimit = dueToLimit;
|
|
334
|
-
child.kill();
|
|
335
|
-
}
|
|
336
|
-
};
|
|
337
|
-
const onAbort = () => {
|
|
338
|
-
aborted = true;
|
|
339
|
-
stopChild();
|
|
340
|
-
};
|
|
341
|
-
signal?.addEventListener("abort", onAbort, { once: true });
|
|
342
|
-
child.stderr?.on("data", (chunk) => {
|
|
343
|
-
stderr += chunk.toString();
|
|
344
|
-
});
|
|
345
|
-
// Collect matches during streaming, then format them after rg exits.
|
|
346
|
-
rl.on("line", (line) => {
|
|
347
|
-
if (!line.trim() || matchCount >= effectiveLimit)
|
|
348
|
-
return;
|
|
349
|
-
let event;
|
|
350
|
-
try {
|
|
351
|
-
event = JSON.parse(line);
|
|
352
|
-
}
|
|
353
|
-
catch {
|
|
354
|
-
return;
|
|
355
|
-
}
|
|
356
|
-
if (event.type === "match") {
|
|
357
|
-
matchCount++;
|
|
358
|
-
const filePath = event.data?.path?.text;
|
|
359
|
-
const lineNumber = event.data?.line_number;
|
|
360
|
-
const lineText = event.data?.lines?.text;
|
|
361
|
-
if (filePath && typeof lineNumber === "number")
|
|
362
|
-
matches.push({ filePath, lineNumber, lineText });
|
|
363
|
-
if (matchCount >= effectiveLimit) {
|
|
364
|
-
matchLimitReached = true;
|
|
365
|
-
stopChild(true);
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
});
|
|
369
|
-
child.on("error", (error) => {
|
|
370
|
-
cleanup();
|
|
371
|
-
settle(() => reject(new Error(`Failed to run ripgrep: ${error.message}`)));
|
|
372
|
-
});
|
|
373
|
-
child.on("close", async (code) => {
|
|
374
|
-
cleanup();
|
|
375
|
-
if (aborted) {
|
|
376
|
-
settle(() => reject(new Error("Operation aborted")));
|
|
377
|
-
return;
|
|
378
|
-
}
|
|
379
|
-
if (!killedDueToLimit && code !== 0 && code !== 1) {
|
|
380
|
-
const trimmedStderr = stderr.trim();
|
|
381
|
-
let errorMsg = trimmedStderr || `ripgrep exited with code ${code}`;
|
|
382
|
-
// A regex parse error means the pattern is not a valid regex. Point the
|
|
383
|
-
// caller at the `literal` option so they can search the text verbatim.
|
|
384
|
-
if (!literal && /regex parse error/i.test(trimmedStderr)) {
|
|
385
|
-
errorMsg += `\n\nThe pattern is not a valid regex. To search for it as plain text, pass literal: true (or escape the regex metacharacters).`;
|
|
386
|
-
}
|
|
387
|
-
settle(() => reject(new Error(errorMsg)));
|
|
388
|
-
return;
|
|
389
|
-
}
|
|
390
|
-
await finalize();
|
|
391
|
-
});
|
|
392
|
-
}
|
|
393
|
-
catch (err) {
|
|
394
|
-
settle(() => reject(err));
|
|
395
|
-
}
|
|
396
|
-
})();
|
|
397
|
-
});
|
|
398
|
-
},
|
|
399
|
-
renderCall(args, theme, context) {
|
|
400
|
-
const text = context.lastComponent ?? new Text("", 0, 0);
|
|
401
|
-
text.setText(formatGrepCall(args, theme));
|
|
402
|
-
return text;
|
|
403
|
-
},
|
|
404
|
-
renderResult(result, options, theme, context) {
|
|
405
|
-
const text = context.lastComponent ?? new Text("", 0, 0);
|
|
406
|
-
text.setText(formatGrepResult(result, options, theme, context.showImages));
|
|
407
|
-
return text;
|
|
408
|
-
},
|
|
409
|
-
};
|
|
410
|
-
}
|
|
411
|
-
export function createGrepTool(cwd, options) {
|
|
412
|
-
return wrapToolDefinition(createGrepToolDefinition(cwd, options));
|
|
413
|
-
}
|
|
414
|
-
//# sourceMappingURL=grep.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"grep.js","sourceRoot":"","sources":["../../../src/core/tools/grep.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAChD,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,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AAC,wBAAwB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC;AAAA,CAClE","sourcesContent":["import { createInterface } from \"node:readline\";\nimport type { AgentTool } from \"@kolisachint/hoocode-agent-core\";\nimport { compressGrepOutput } from \"@kolisachint/hoocode-agent-core\";\nimport { Text } from \"@kolisachint/hoocode-tui\";\nimport { spawn } from \"child_process\";\nimport { readFileSync, statSync } 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 { getEmbsearchService } from \"../embsearch/embsearch-service.js\";\nimport type { ToolDefinition, ToolRenderResultOptions } from \"../extensions/types.js\";\nimport { isNativeSearchForced, nativeGrep } 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 {\n\tDEFAULT_MAX_BYTES,\n\tformatSize,\n\tGREP_MAX_LINE_LENGTH,\n\ttype TruncationResult,\n\ttruncateHead,\n\ttruncateLine,\n} from \"./truncate.js\";\n\nconst grepSchema = Type.Object({\n\tpattern: Type.String({ description: \"Search pattern (regex or literal string)\" }),\n\tpath: Type.Optional(Type.String({ description: \"Directory or file to search (default: current directory)\" })),\n\tglob: Type.Optional(Type.String({ description: \"Filter files by glob pattern, e.g. '*.ts' or '**/*.spec.ts'\" })),\n\tignoreCase: Type.Optional(Type.Boolean({ description: \"Case-insensitive search (default: false)\" })),\n\tliteral: Type.Optional(\n\t\tType.Boolean({ description: \"Treat pattern as literal string instead of regex (default: false)\" }),\n\t),\n\tcontext: Type.Optional(\n\t\tType.Number({ description: \"Number of lines to show before and after each match (default: 0)\" }),\n\t),\n\tlimit: Type.Optional(Type.Number({ description: \"Maximum number of matches to return (default: 100)\" })),\n});\n\nexport type GrepToolInput = Static<typeof grepSchema>;\nconst DEFAULT_LIMIT = 100;\n\n/**\n * Match fd/rg semantics for slash-containing globs: rg matches them against the\n * full search path (absolute here), so `src/**\\/*.ts` would silently match\n * nothing. Anchor anywhere in the tree by prepending `**\\/` unless the caller\n * already did (same normalization the search tool applies).\n */\nfunction normalizeGrepGlob(glob: string | undefined): string | undefined {\n\tif (!glob) return undefined;\n\tif (glob.includes(\"/\") && !glob.startsWith(\"/\") && !glob.startsWith(\"**/\")) {\n\t\treturn `**/${glob}`;\n\t}\n\treturn glob;\n}\n\nexport interface GrepToolDetails {\n\ttruncation?: TruncationResult;\n\tmatchLimitReached?: number;\n\tlinesTruncated?: boolean;\n}\n\n/**\n * Pluggable operations for the grep tool.\n * Override these to delegate search to remote systems (for example SSH).\n */\nexport interface GrepOperations {\n\t/** Check if path is a directory. Throws if path does not exist. */\n\tisDirectory: (absolutePath: string) => Promise<boolean> | boolean;\n\t/** Read file contents for context lines */\n\treadFile: (absolutePath: string) => Promise<string> | string;\n}\n\nconst defaultGrepOperations: GrepOperations = {\n\tisDirectory: (p) => statSync(p).isDirectory(),\n\treadFile: (p) => readFileSync(p, \"utf-8\"),\n};\n\nexport interface GrepToolOptions {\n\t/** Custom operations for grep. Default: local filesystem plus ripgrep */\n\toperations?: GrepOperations;\n}\n\nfunction formatGrepCall(\n\targs: { pattern: string; path?: string; glob?: string; limit?: number } | undefined,\n\ttheme: typeof import(\"../../modes/interactive/theme/theme.js\").theme,\n): string {\n\tconst pattern = str(args?.pattern);\n\tconst rawPath = str(args?.path);\n\tconst path = rawPath !== null ? shortenPath(rawPath || \".\") : null;\n\tconst glob = str(args?.glob);\n\tconst limit = args?.limit;\n\tconst invalidArg = invalidArgText(theme);\n\tlet text =\n\t\ttheme.fg(\"toolTitle\", theme.bold(\"grep\")) +\n\t\t\" \" +\n\t\t(pattern === null ? invalidArg : theme.fg(\"accent\", `/${pattern || \"\"}/`)) +\n\t\ttheme.fg(\"toolOutput\", ` in ${path === null ? invalidArg : path}`);\n\tif (glob) text += theme.fg(\"toolOutput\", ` (${glob})`);\n\tif (limit !== undefined) text += theme.fg(\"toolOutput\", ` limit ${limit}`);\n\treturn text;\n}\n\nfunction formatGrepResult(\n\tresult: {\n\t\tcontent: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;\n\t\tdetails?: GrepToolDetails;\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 : 15;\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 matchLimit = result.details?.matchLimitReached;\n\tconst truncation = result.details?.truncation;\n\tconst linesTruncated = result.details?.linesTruncated;\n\tif (matchLimit || truncation?.truncated || linesTruncated) {\n\t\tconst warnings: string[] = [];\n\t\tif (matchLimit) warnings.push(`${matchLimit} matches limit`);\n\t\tif (truncation?.truncated) warnings.push(`${formatSize(truncation.maxBytes ?? DEFAULT_MAX_BYTES)} limit`);\n\t\tif (linesTruncated) warnings.push(\"some lines truncated\");\n\t\ttext += `\\n${theme.fg(\"warning\", `[Truncated: ${warnings.join(\", \")}]`)}`;\n\t}\n\treturn text;\n}\n\nexport function createGrepToolDefinition(\n\tcwd: string,\n\toptions?: GrepToolOptions,\n): ToolDefinition<typeof grepSchema, GrepToolDetails | undefined> {\n\tconst customOps = options?.operations;\n\treturn {\n\t\tname: \"grep\",\n\t\tlabel: \"grep\",\n\t\tdescription: `Search file contents for a pattern. Returns matching lines with file paths and line numbers. Case-sensitive by default (set ignoreCase). The pattern is a regex; set literal: true to match plain text. Respects .gitignore; never searches .git. Truncates at ${DEFAULT_LIMIT} matches / ${DEFAULT_MAX_BYTES / 1024}KB, and long lines at ${GREP_MAX_LINE_LENGTH} chars.`,\n\t\tpromptSnippet: \"Search file contents for patterns (respects .gitignore)\",\n\t\t// No promptGuidelines: buildSystemPrompt already emits the single canonical\n\t\t// search-vs-grep guideline whenever both tools are registered. This used to\n\t\t// restate it, so the same routing rule shipped twice every turn.\n\t\tparameters: grepSchema,\n\t\tasync execute(\n\t\t\t_toolCallId,\n\t\t\t{\n\t\t\t\tpattern,\n\t\t\t\tpath: searchDir,\n\t\t\t\tglob,\n\t\t\t\tignoreCase,\n\t\t\t\tliteral,\n\t\t\t\tcontext,\n\t\t\t\tlimit,\n\t\t\t}: {\n\t\t\t\tpattern: string;\n\t\t\t\tpath?: string;\n\t\t\t\tglob?: string;\n\t\t\t\tignoreCase?: boolean;\n\t\t\t\tliteral?: boolean;\n\t\t\t\tcontext?: number;\n\t\t\t\tlimit?: number;\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\t\t\t\tlet settled = false;\n\t\t\t\tconst settle = (fn: () => void) => {\n\t\t\t\t\tif (!settled) {\n\t\t\t\t\t\tsettled = true;\n\t\t\t\t\t\tfn();\n\t\t\t\t\t}\n\t\t\t\t};\n\n\t\t\t\t(async () => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\t// An empty pattern matches every line of every file — never useful.\n\t\t\t\t\t\tif (!pattern) {\n\t\t\t\t\t\t\tsettle(() => reject(new Error(\"pattern must not be empty\")));\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst normalizedGlob = normalizeGrepGlob(glob);\n\n\t\t\t\t\t\t// rg drives the fast path; when it is unavailable (restricted\n\t\t\t\t\t\t// environments) or forced off, a pure-JS scan produces the same\n\t\t\t\t\t\t// match shape so the tool degrades automatically instead of failing.\n\t\t\t\t\t\tconst rgPath = isNativeSearchForced() ? undefined : await ensureTool(\"rg\", true);\n\n\t\t\t\t\t\tconst searchPath = resolveToCwd(searchDir || \".\", cwd);\n\t\t\t\t\t\tconst ops = customOps ?? defaultGrepOperations;\n\t\t\t\t\t\tlet isDirectory: boolean;\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tisDirectory = await ops.isDirectory(searchPath);\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\tsettle(() => reject(new Error(`Path not found: ${searchPath}`)));\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst contextValue = context && context > 0 ? context : 0;\n\t\t\t\t\t\tconst effectiveLimit = Math.max(1, limit ?? DEFAULT_LIMIT);\n\t\t\t\t\t\tconst formatPath = (filePath: string): string => {\n\t\t\t\t\t\t\tif (isDirectory) {\n\t\t\t\t\t\t\t\tconst relative = path.relative(searchPath, filePath);\n\t\t\t\t\t\t\t\tif (relative && !relative.startsWith(\"..\")) {\n\t\t\t\t\t\t\t\t\treturn relative.replace(/\\\\/g, \"/\");\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 path.basename(filePath);\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\tconst fileCache = new Map<string, string[]>();\n\t\t\t\t\t\tconst getFileLines = async (filePath: string): Promise<string[]> => {\n\t\t\t\t\t\t\tlet lines = fileCache.get(filePath);\n\t\t\t\t\t\t\tif (!lines) {\n\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\tconst content = await ops.readFile(filePath);\n\t\t\t\t\t\t\t\t\tlines = content.replace(/\\r\\n/g, \"\\n\").replace(/\\r/g, \"\\n\").split(\"\\n\");\n\t\t\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t\t\tlines = [];\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tfileCache.set(filePath, lines);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn lines;\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\t// Match collection is shared between the rg and native paths.\n\t\t\t\t\t\tconst matches: Array<{ filePath: string; lineNumber: number; lineText?: string }> = [];\n\t\t\t\t\t\tlet matchLimitReached = false;\n\t\t\t\t\t\tlet linesTruncated = false;\n\n\t\t\t\t\t\t// Format a context block around a match line. Path is omitted (emitted once per file).\n\t\t\t\t\t\tconst formatBlock = async (filePath: string, lineNumber: number): Promise<string[]> => {\n\t\t\t\t\t\t\tconst lines = await getFileLines(filePath);\n\t\t\t\t\t\t\tif (!lines.length) return [` ${lineNumber}: (unable to read file)`];\n\t\t\t\t\t\t\tconst block: string[] = [];\n\t\t\t\t\t\t\tconst start = contextValue > 0 ? Math.max(1, lineNumber - contextValue) : lineNumber;\n\t\t\t\t\t\t\tconst end = contextValue > 0 ? Math.min(lines.length, lineNumber + contextValue) : lineNumber;\n\t\t\t\t\t\t\tfor (let current = start; current <= end; current++) {\n\t\t\t\t\t\t\t\tconst lineText = lines[current - 1] ?? \"\";\n\t\t\t\t\t\t\t\tconst sanitized = lineText.replace(/\\r/g, \"\");\n\t\t\t\t\t\t\t\tconst isMatchLine = current === lineNumber;\n\t\t\t\t\t\t\t\t// Truncate long lines so grep output stays compact.\n\t\t\t\t\t\t\t\tconst { text: truncatedText, wasTruncated } = truncateLine(sanitized);\n\t\t\t\t\t\t\t\tif (wasTruncated) linesTruncated = true;\n\t\t\t\t\t\t\t\tif (isMatchLine) block.push(`${current}: ${truncatedText}`);\n\t\t\t\t\t\t\t\telse block.push(`${current}- ${truncatedText}`);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn block;\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\t// Format the collected matches into the tool result. Shared by both paths.\n\t\t\t\t\t\tconst finalize = async () => {\n\t\t\t\t\t\t\tif (matches.length === 0) {\n\t\t\t\t\t\t\t\tconst service = getEmbsearchService(cwd);\n\t\t\t\t\t\t\t\tconst hint = service?.isAvailable()\n\t\t\t\t\t\t\t\t\t? \"\\n\\n[Hint: no exact matches; use the search tool (semantic or hybrid mode) to find conceptually related code]\"\n\t\t\t\t\t\t\t\t\t: \"\";\n\t\t\t\t\t\t\t\tsettle(() =>\n\t\t\t\t\t\t\t\t\tresolve({\n\t\t\t\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: `No matches found${hint}` }],\n\t\t\t\t\t\t\t\t\t\tdetails: undefined,\n\t\t\t\t\t\t\t\t\t}),\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\n\t\t\t\t\t\t\tconst outputLines: string[] = [];\n\t\t\t\t\t\t\t// Group matches by file path, showing filename once per file.\n\t\t\t\t\t\t\tconst fileGroups = new Map<string, typeof matches>();\n\t\t\t\t\t\t\tfor (const match of matches) {\n\t\t\t\t\t\t\t\tlet group = fileGroups.get(match.filePath);\n\t\t\t\t\t\t\t\tif (!group) {\n\t\t\t\t\t\t\t\t\tgroup = [];\n\t\t\t\t\t\t\t\t\tfileGroups.set(match.filePath, group);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tgroup.push(match);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tfor (const [filePath, fileMatches] of fileGroups) {\n\t\t\t\t\t\t\t\tconst relativePath = formatPath(filePath);\n\t\t\t\t\t\t\t\toutputLines.push(relativePath);\n\t\t\t\t\t\t\t\tfor (const match of fileMatches) {\n\t\t\t\t\t\t\t\t\tif (contextValue === 0 && match.lineText !== undefined) {\n\t\t\t\t\t\t\t\t\t\tconst sanitized = match.lineText\n\t\t\t\t\t\t\t\t\t\t\t.replace(/\\r\\n/g, \"\\n\")\n\t\t\t\t\t\t\t\t\t\t\t.replace(/\\r/g, \"\")\n\t\t\t\t\t\t\t\t\t\t\t.replace(/\\n$/, \"\");\n\t\t\t\t\t\t\t\t\t\tconst { text: truncatedText, wasTruncated } = truncateLine(sanitized);\n\t\t\t\t\t\t\t\t\t\tif (wasTruncated) linesTruncated = true;\n\t\t\t\t\t\t\t\t\t\toutputLines.push(`${match.lineNumber}: ${truncatedText}`);\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\tconst block = await formatBlock(match.filePath, match.lineNumber);\n\t\t\t\t\t\t\t\t\t\toutputLines.push(...block);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconst rawOutput = outputLines.join(\"\\n\");\n\t\t\t\t\t\t\t// Apply lossless compression then byte truncation.\n\t\t\t\t\t\t\tconst compressedOutput = compressGrepOutput(rawOutput);\n\t\t\t\t\t\t\t// Apply byte truncation. There is no line limit here because the match limit already capped rows.\n\t\t\t\t\t\t\tconst truncation = truncateHead(compressedOutput, { maxLines: Number.MAX_SAFE_INTEGER });\n\t\t\t\t\t\t\tlet output = truncation.content;\n\t\t\t\t\t\t\tconst details: GrepToolDetails = {};\n\t\t\t\t\t\t\t// Build actionable notices for truncation and match limits.\n\t\t\t\t\t\t\tconst notices: string[] = [];\n\t\t\t\t\t\t\tif (matchLimitReached) {\n\t\t\t\t\t\t\t\tnotices.push(\n\t\t\t\t\t\t\t\t\t`${effectiveLimit} match${effectiveLimit === 1 ? \"\" : \"es\"} 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.matchLimitReached = 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 (linesTruncated) {\n\t\t\t\t\t\t\t\tnotices.push(\n\t\t\t\t\t\t\t\t\t`Some lines truncated to ${GREP_MAX_LINE_LENGTH} chars. Use read tool to see full lines`,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\tdetails.linesTruncated = true;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (notices.length > 0) output += `\\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: output }],\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// --- Native fallback: no rg binary available (or forced off) ---\n\t\t\t\t\t\tif (!rgPath) {\n\t\t\t\t\t\t\tlet result: Awaited<ReturnType<typeof nativeGrep>>;\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tresult = await nativeGrep(searchPath, {\n\t\t\t\t\t\t\t\t\tpattern,\n\t\t\t\t\t\t\t\t\tisDirectory,\n\t\t\t\t\t\t\t\t\tignoreCase,\n\t\t\t\t\t\t\t\t\tliteral,\n\t\t\t\t\t\t\t\t\tglob: normalizedGlob,\n\t\t\t\t\t\t\t\t\tlimit: effectiveLimit,\n\t\t\t\t\t\t\t\t\tsignal,\n\t\t\t\t\t\t\t\t\treadFile: ops.readFile,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\t\t\tif (signal?.aborted) {\n\t\t\t\t\t\t\t\t\tsettle(() => reject(new Error(\"Operation aborted\")));\n\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tconst err = e as Error & { invalidRegex?: boolean };\n\t\t\t\t\t\t\t\tlet errorMsg = err.message || \"grep failed\";\n\t\t\t\t\t\t\t\tif (err.invalidRegex && !literal) {\n\t\t\t\t\t\t\t\t\terrorMsg += `\\n\\nThe pattern is not a valid regex. To search for it as plain text, pass literal: true (or escape the regex metacharacters).`;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tsettle(() => reject(new Error(errorMsg)));\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\tmatches.push(...result.matches);\n\t\t\t\t\t\t\tmatchLimitReached = result.matchLimitReached;\n\t\t\t\t\t\t\tawait finalize();\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// --- Fast path: stream rg --json ---\n\t\t\t\t\t\t// `!.git` because --hidden would otherwise search .git contents;\n\t\t\t\t\t\t// --no-require-git so .gitignore is honored outside git repos too\n\t\t\t\t\t\t// (parity with fd and the native fallback); --sort path forces a\n\t\t\t\t\t\t// deterministic single-threaded walk so the match limit truncates\n\t\t\t\t\t\t// the same subset on every run.\n\t\t\t\t\t\tconst args: string[] = [\n\t\t\t\t\t\t\t\"--json\",\n\t\t\t\t\t\t\t\"--line-number\",\n\t\t\t\t\t\t\t\"--color=never\",\n\t\t\t\t\t\t\t\"--hidden\",\n\t\t\t\t\t\t\t\"--no-require-git\",\n\t\t\t\t\t\t\t\"--sort\",\n\t\t\t\t\t\t\t\"path\",\n\t\t\t\t\t\t\t\"--glob\",\n\t\t\t\t\t\t\t\"!**/.git/**\",\n\t\t\t\t\t\t];\n\t\t\t\t\t\tif (ignoreCase) args.push(\"--ignore-case\");\n\t\t\t\t\t\tif (literal) args.push(\"--fixed-strings\");\n\t\t\t\t\t\tif (normalizedGlob) args.push(\"--glob\", normalizedGlob);\n\t\t\t\t\t\targs.push(\"--\", pattern, searchPath);\n\n\t\t\t\t\t\tconst child = spawn(rgPath, args, { stdio: [\"ignore\", \"pipe\", \"pipe\"] });\n\t\t\t\t\t\tconst rl = createInterface({ input: child.stdout });\n\t\t\t\t\t\tlet stderr = \"\";\n\t\t\t\t\t\tlet matchCount = 0;\n\t\t\t\t\t\tlet aborted = false;\n\t\t\t\t\t\tlet killedDueToLimit = false;\n\n\t\t\t\t\t\tconst cleanup = () => {\n\t\t\t\t\t\t\trl.close();\n\t\t\t\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\t\t};\n\t\t\t\t\t\tconst stopChild = (dueToLimit = false) => {\n\t\t\t\t\t\t\tif (!child.killed) {\n\t\t\t\t\t\t\t\tkilledDueToLimit = dueToLimit;\n\t\t\t\t\t\t\t\tchild.kill();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t};\n\t\t\t\t\t\tconst onAbort = () => {\n\t\t\t\t\t\t\taborted = true;\n\t\t\t\t\t\t\tstopChild();\n\t\t\t\t\t\t};\n\t\t\t\t\t\tsignal?.addEventListener(\"abort\", onAbort, { once: true });\n\t\t\t\t\t\tchild.stderr?.on(\"data\", (chunk) => {\n\t\t\t\t\t\t\tstderr += chunk.toString();\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\t// Collect matches during streaming, then format them after rg exits.\n\t\t\t\t\t\trl.on(\"line\", (line) => {\n\t\t\t\t\t\t\tif (!line.trim() || matchCount >= effectiveLimit) return;\n\t\t\t\t\t\t\tlet event: any;\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tevent = JSON.parse(line);\n\t\t\t\t\t\t\t} catch {\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 (event.type === \"match\") {\n\t\t\t\t\t\t\t\tmatchCount++;\n\t\t\t\t\t\t\t\tconst filePath = event.data?.path?.text;\n\t\t\t\t\t\t\t\tconst lineNumber = event.data?.line_number;\n\t\t\t\t\t\t\t\tconst lineText = event.data?.lines?.text;\n\t\t\t\t\t\t\t\tif (filePath && typeof lineNumber === \"number\")\n\t\t\t\t\t\t\t\t\tmatches.push({ filePath, lineNumber, lineText });\n\t\t\t\t\t\t\t\tif (matchCount >= effectiveLimit) {\n\t\t\t\t\t\t\t\t\tmatchLimitReached = true;\n\t\t\t\t\t\t\t\t\tstopChild(true);\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\tchild.on(\"error\", (error) => {\n\t\t\t\t\t\t\tcleanup();\n\t\t\t\t\t\t\tsettle(() => reject(new Error(`Failed to run ripgrep: ${error.message}`)));\n\t\t\t\t\t\t});\n\t\t\t\t\t\tchild.on(\"close\", async (code) => {\n\t\t\t\t\t\t\tcleanup();\n\t\t\t\t\t\t\tif (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\tif (!killedDueToLimit && code !== 0 && code !== 1) {\n\t\t\t\t\t\t\t\tconst trimmedStderr = stderr.trim();\n\t\t\t\t\t\t\t\tlet errorMsg = trimmedStderr || `ripgrep exited with code ${code}`;\n\t\t\t\t\t\t\t\t// A regex parse error means the pattern is not a valid regex. Point the\n\t\t\t\t\t\t\t\t// caller at the `literal` option so they can search the text verbatim.\n\t\t\t\t\t\t\t\tif (!literal && /regex parse error/i.test(trimmedStderr)) {\n\t\t\t\t\t\t\t\t\terrorMsg += `\\n\\nThe pattern is not a valid regex. To search for it as plain text, pass literal: true (or escape the regex metacharacters).`;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tsettle(() => reject(new Error(errorMsg)));\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tawait finalize();\n\t\t\t\t\t\t});\n\t\t\t\t\t} catch (err) {\n\t\t\t\t\t\tsettle(() => reject(err as 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(formatGrepCall(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(formatGrepResult(result as any, options, theme, context.showImages));\n\t\t\treturn text;\n\t\t},\n\t};\n}\n\nexport function createGrepTool(cwd: string, options?: GrepToolOptions): AgentTool<typeof grepSchema> {\n\treturn wrapToolDefinition(createGrepToolDefinition(cwd, options));\n}\n"]}
|
package/dist/core/tools/ls.d.ts
DELETED
|
@@ -1,49 +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 lsSchema: Type.TObject<{
|
|
6
|
-
path: Type.TOptional<Type.TString>;
|
|
7
|
-
limit: Type.TOptional<Type.TNumber>;
|
|
8
|
-
ignore: Type.TOptional<Type.TArray<Type.TString>>;
|
|
9
|
-
}>;
|
|
10
|
-
export type LsToolInput = Static<typeof lsSchema>;
|
|
11
|
-
export interface LsToolDetails {
|
|
12
|
-
truncation?: TruncationResult;
|
|
13
|
-
entryLimitReached?: number;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Pluggable operations for the ls tool.
|
|
17
|
-
* Override these to delegate directory listing to remote systems (for example SSH).
|
|
18
|
-
*/
|
|
19
|
-
export interface LsOperations {
|
|
20
|
-
/** Check if path exists */
|
|
21
|
-
exists: (absolutePath: string) => Promise<boolean> | boolean;
|
|
22
|
-
/** Get file or directory stats. Throws if not found. */
|
|
23
|
-
stat: (absolutePath: string) => Promise<{
|
|
24
|
-
isDirectory: () => boolean;
|
|
25
|
-
}> | {
|
|
26
|
-
isDirectory: () => boolean;
|
|
27
|
-
};
|
|
28
|
-
/** Read directory entries as strings (used when readdirEntries is not provided) */
|
|
29
|
-
readdir: (absolutePath: string) => Promise<string[]> | string[];
|
|
30
|
-
/**
|
|
31
|
-
* Optional: read directory entries with type info in a single syscall.
|
|
32
|
-
* When provided, eliminates per-entry stat() calls for the isDirectory check.
|
|
33
|
-
*/
|
|
34
|
-
readdirEntries?: (absolutePath: string) => Promise<Array<{
|
|
35
|
-
name: string;
|
|
36
|
-
isDirectory: () => boolean;
|
|
37
|
-
}>> | Array<{
|
|
38
|
-
name: string;
|
|
39
|
-
isDirectory: () => boolean;
|
|
40
|
-
}>;
|
|
41
|
-
}
|
|
42
|
-
export interface LsToolOptions {
|
|
43
|
-
/** Custom operations for directory listing. Default: local filesystem */
|
|
44
|
-
operations?: LsOperations;
|
|
45
|
-
}
|
|
46
|
-
export declare function createLsToolDefinition(cwd: string, options?: LsToolOptions): ToolDefinition<typeof lsSchema, LsToolDetails | undefined>;
|
|
47
|
-
export declare function createLsTool(cwd: string, options?: LsToolOptions): AgentTool<typeof lsSchema>;
|
|
48
|
-
export {};
|
|
49
|
-
//# sourceMappingURL=ls.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ls.d.ts","sourceRoot":"","sources":["../../../src/core/tools/ls.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAMjE,OAAO,EAAE,KAAK,MAAM,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,KAAK,EAAE,cAAc,EAA2B,MAAM,wBAAwB,CAAC;AAItF,OAAO,EAAiC,KAAK,gBAAgB,EAAgB,MAAM,eAAe,CAAC;AAEnG,QAAA,MAAM,QAAQ;;;;EAQZ,CAAC;AAEH,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,QAAQ,CAAC,CAAC;AAIlD,MAAM,WAAW,aAAa;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\";\nimport { existsSync, readdirSync, statSync } from \"fs\";\nimport { readdir as fsReaddir } from \"fs/promises\";\nimport { minimatch } from \"minimatch\";\nimport nodePath from \"path\";\nimport { type Static, Type } from \"typebox\";\nimport { keyHint } from \"../../modes/interactive/components/keybinding-hints.js\";\nimport type { ToolDefinition, ToolRenderResultOptions } from \"../extensions/types.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 lsSchema = Type.Object({\n\tpath: Type.Optional(Type.String({ description: \"Directory to list (default: current directory)\" })),\n\tlimit: Type.Optional(Type.Number({ description: \"Maximum number of entries to return (default: 500)\" })),\n\tignore: Type.Optional(\n\t\tType.Array(Type.String(), {\n\t\t\tdescription: \"Globs matched against entry names to exclude, e.g. ['node_modules', '*.log'].\",\n\t\t}),\n\t),\n});\n\nexport type LsToolInput = Static<typeof lsSchema>;\n\nconst DEFAULT_LIMIT = 500;\n\nexport interface LsToolDetails {\n\ttruncation?: TruncationResult;\n\tentryLimitReached?: number;\n}\n\n/**\n * Pluggable operations for the ls tool.\n * Override these to delegate directory listing to remote systems (for example SSH).\n */\nexport interface LsOperations {\n\t/** Check if path exists */\n\texists: (absolutePath: string) => Promise<boolean> | boolean;\n\t/** Get file or directory stats. Throws if not found. */\n\tstat: (absolutePath: string) => Promise<{ isDirectory: () => boolean }> | { isDirectory: () => boolean };\n\t/** Read directory entries as strings (used when readdirEntries is not provided) */\n\treaddir: (absolutePath: string) => Promise<string[]> | string[];\n\t/**\n\t * Optional: read directory entries with type info in a single syscall.\n\t * When provided, eliminates per-entry stat() calls for the isDirectory check.\n\t */\n\treaddirEntries?: (\n\t\tabsolutePath: string,\n\t) =>\n\t\t| Promise<Array<{ name: string; isDirectory: () => boolean }>>\n\t\t| Array<{ name: string; isDirectory: () => boolean }>;\n}\n\nconst defaultLsOperations: LsOperations = {\n\texists: existsSync,\n\tstat: statSync,\n\treaddir: readdirSync,\n\treaddirEntries: (p) => fsReaddir(p, { withFileTypes: true }),\n};\n\nexport interface LsToolOptions {\n\t/** Custom operations for directory listing. Default: local filesystem */\n\toperations?: LsOperations;\n}\n\nfunction formatLsCall(\n\targs: { path?: string; limit?: number } | undefined,\n\ttheme: typeof import(\"../../modes/interactive/theme/theme.js\").theme,\n): string {\n\tconst rawPath = str(args?.path);\n\tconst path = rawPath !== null ? shortenPath(rawPath || \".\") : null;\n\tconst limit = args?.limit;\n\tconst invalidArg = invalidArgText(theme);\n\tlet text = `${theme.fg(\"toolTitle\", theme.bold(\"ls\"))} ${path === null ? invalidArg : theme.fg(\"accent\", path)}`;\n\tif (limit !== undefined) {\n\t\ttext += theme.fg(\"toolOutput\", ` (limit ${limit})`);\n\t}\n\treturn text;\n}\n\nfunction formatLsResult(\n\tresult: {\n\t\tcontent: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;\n\t\tdetails?: LsToolDetails;\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 entryLimit = result.details?.entryLimitReached;\n\tconst truncation = result.details?.truncation;\n\tif (entryLimit || truncation?.truncated) {\n\t\tconst warnings: string[] = [];\n\t\tif (entryLimit) warnings.push(`${entryLimit} entries 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 createLsToolDefinition(\n\tcwd: string,\n\toptions?: LsToolOptions,\n): ToolDefinition<typeof lsSchema, LsToolDetails | undefined> {\n\tconst ops = options?.operations ?? defaultLsOperations;\n\treturn {\n\t\tname: \"ls\",\n\t\tlabel: \"ls\",\n\t\tdescription: `List one directory (not recursive), sorted alphabetically, '/' suffix for directories. Shows everything on disk including dotfiles and ignored paths; pass 'ignore' globs to skip entries. Truncates at ${DEFAULT_LIMIT} entries / ${DEFAULT_MAX_BYTES / 1024}KB.`,\n\t\tpromptSnippet: \"List directory contents\",\n\t\tparameters: lsSchema,\n\t\tasync execute(\n\t\t\t_toolCallId,\n\t\t\t{ path, limit, ignore }: { path?: string; limit?: number; ignore?: string[] },\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\tconst onAbort = () => reject(new Error(\"Operation aborted\"));\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 dirPath = resolveToCwd(path || \".\", cwd);\n\t\t\t\t\t\tconst effectiveLimit = limit ?? DEFAULT_LIMIT;\n\n\t\t\t\t\t\t// Check if path exists.\n\t\t\t\t\t\tif (!(await ops.exists(dirPath))) {\n\t\t\t\t\t\t\treject(new Error(`Path not found: ${dirPath}`));\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Check if path is a directory.\n\t\t\t\t\t\tconst stat = await ops.stat(dirPath);\n\t\t\t\t\t\tif (!stat.isDirectory()) {\n\t\t\t\t\t\t\treject(new Error(`Not a directory: ${dirPath}`));\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// Exclude entries matching any ignore glob. Match on the bare entry\n\t\t\t\t\t\t// name (ls is non-recursive) with dot:true so patterns can target\n\t\t\t\t\t\t// dotfiles like '.git'. Default behavior (no patterns) still shows\n\t\t\t\t\t\t// everything on disk.\n\t\t\t\t\t\tconst ignorePatterns = (ignore ?? []).filter((p) => typeof p === \"string\" && p.length > 0);\n\n\t\t\t\t\t\t// Fast path: use readdirEntries (single syscall with type info).\n\t\t\t\t\t\t// Slow path: fall back to readdir + per-entry stat.\n\t\t\t\t\t\tconst results: string[] = [];\n\t\t\t\t\t\tlet entryLimitReached = false;\n\n\t\t\t\t\t\tif (ops.readdirEntries) {\n\t\t\t\t\t\t\tlet dirents: Array<{ name: string; isDirectory: () => boolean }>;\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tdirents = await ops.readdirEntries(dirPath);\n\t\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t\treject(new Error(`Cannot read directory: ${dirPath}`));\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tlet filtered = dirents;\n\t\t\t\t\t\t\tif (ignorePatterns.length > 0) {\n\t\t\t\t\t\t\t\tfiltered = dirents.filter(\n\t\t\t\t\t\t\t\t\t(d) => !ignorePatterns.some((pattern) => minimatch(d.name, pattern, { dot: true })),\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tfiltered.sort((a, b) => a.name.toLowerCase().localeCompare(b.name.toLowerCase()));\n\t\t\t\t\t\t\tfor (const entry of filtered) {\n\t\t\t\t\t\t\t\tif (results.length >= effectiveLimit) {\n\t\t\t\t\t\t\t\t\tentryLimitReached = true;\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tresults.push(entry.name + (entry.isDirectory() ? \"/\" : \"\"));\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t// Fallback: readdir returns strings, stat each entry.\n\t\t\t\t\t\t\tlet entries: string[];\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tentries = await ops.readdir(dirPath);\n\t\t\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\t\t\tif (e instanceof Error) {\n\t\t\t\t\t\t\t\t\treject(new Error(`Cannot read directory: ${e.message}`));\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\treject(new Error(`Cannot read directory: ${String(e)}`));\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\tconst ignoreFiltered =\n\t\t\t\t\t\t\t\tignorePatterns.length > 0\n\t\t\t\t\t\t\t\t\t? entries.filter(\n\t\t\t\t\t\t\t\t\t\t\t(entry) => !ignorePatterns.some((pattern) => minimatch(entry, pattern, { dot: true })),\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t: entries;\n\t\t\t\t\t\t\tignoreFiltered.sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase()));\n\t\t\t\t\t\t\tfor (const entry of ignoreFiltered) {\n\t\t\t\t\t\t\t\tif (results.length >= effectiveLimit) {\n\t\t\t\t\t\t\t\t\tentryLimitReached = true;\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tconst fullPath = nodePath.join(dirPath, entry);\n\t\t\t\t\t\t\t\tlet suffix = \"\";\n\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\tconst entryStat = await ops.stat(fullPath);\n\t\t\t\t\t\t\t\t\tif (entryStat.isDirectory()) suffix = \"/\";\n\t\t\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tresults.push(entry + suffix);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\n\t\t\t\t\t\tif (results.length === 0) {\n\t\t\t\t\t\t\tresolve({ content: [{ type: \"text\", text: \"(empty directory)\" }], details: undefined });\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tconst rawOutput = results.join(\"\\n\");\n\t\t\t\t\t\t// Apply byte truncation. There is no separate line limit because entry count is already capped.\n\t\t\t\t\t\tconst truncation = truncateHead(rawOutput, { maxLines: Number.MAX_SAFE_INTEGER });\n\t\t\t\t\t\tlet output = truncation.content;\n\t\t\t\t\t\tconst details: LsToolDetails = {};\n\t\t\t\t\t\t// Build actionable notices for truncation and entry limits.\n\t\t\t\t\t\tconst notices: string[] = [];\n\t\t\t\t\t\tif (entryLimitReached) {\n\t\t\t\t\t\t\tnotices.push(`${effectiveLimit} entries limit reached. Use limit=${effectiveLimit * 2} for more`);\n\t\t\t\t\t\t\tdetails.entryLimitReached = effectiveLimit;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (truncation.truncated) {\n\t\t\t\t\t\t\tnotices.push(`${formatSize(DEFAULT_MAX_BYTES)} limit reached`);\n\t\t\t\t\t\t\tdetails.truncation = truncation;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (notices.length > 0) {\n\t\t\t\t\t\t\toutput += `\\n\\n[${notices.join(\". \")}]`;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tresolve({\n\t\t\t\t\t\t\tcontent: [{ type: \"text\", text: output }],\n\t\t\t\t\t\t\tdetails: Object.keys(details).length > 0 ? details : undefined,\n\t\t\t\t\t\t});\n\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\tsignal?.removeEventListener(\"abort\", onAbort);\n\t\t\t\t\t\treject(e);\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(formatLsCall(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(formatLsResult(result as any, options, theme, context.showImages));\n\t\t\treturn text;\n\t\t},\n\t};\n}\n\nexport function createLsTool(cwd: string, options?: LsToolOptions): AgentTool<typeof lsSchema> {\n\treturn wrapToolDefinition(createLsToolDefinition(cwd, options));\n}\n"]}
|