@nervekit/tools 0.1.0 → 0.3.0
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/dist/execution/common/output-budget.d.ts +5 -0
- package/dist/execution/common/output-budget.d.ts.map +1 -1
- package/dist/execution/common/output-budget.js +26 -0
- package/dist/execution/common/output-budget.js.map +1 -1
- package/dist/execution/common/process-result.d.ts.map +1 -1
- package/dist/execution/common/process-result.js +55 -1
- package/dist/execution/common/process-result.js.map +1 -1
- package/dist/execution/filesystem/find.d.ts.map +1 -1
- package/dist/execution/filesystem/find.js +5 -2
- package/dist/execution/filesystem/find.js.map +1 -1
- package/dist/execution/filesystem/list.d.ts.map +1 -1
- package/dist/execution/filesystem/list.js +5 -2
- package/dist/execution/filesystem/list.js.map +1 -1
- package/dist/execution/filesystem/read.d.ts.map +1 -1
- package/dist/execution/filesystem/read.js +19 -2
- package/dist/execution/filesystem/read.js.map +1 -1
- package/dist/execution/filesystem/search.d.ts.map +1 -1
- package/dist/execution/filesystem/search.js +12 -2
- package/dist/execution/filesystem/search.js.map +1 -1
- package/dist/execution/index.d.ts +1 -1
- package/dist/execution/index.d.ts.map +1 -1
- package/dist/execution/index.js +1 -1
- package/dist/execution/index.js.map +1 -1
- package/dist/execution/shell/bash.d.ts.map +1 -1
- package/dist/execution/shell/bash.js +12 -1
- package/dist/execution/shell/bash.js.map +1 -1
- package/dist/execution/web/web-fetch.d.ts.map +1 -1
- package/dist/execution/web/web-fetch.js +39 -0
- package/dist/execution/web/web-fetch.js.map +1 -1
- package/dist/execution/web/web-search.d.ts.map +1 -1
- package/dist/execution/web/web-search.js +9 -2
- package/dist/execution/web/web-search.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/dist/catalog/orchestration/process.tools.d.ts +0 -68
- package/dist/catalog/orchestration/process.tools.d.ts.map +0 -1
- package/dist/catalog/orchestration/process.tools.js +0 -96
- package/dist/catalog/orchestration/process.tools.js.map +0 -1
- package/dist/catalog/orchestration/subagent.tools.d.ts +0 -16
- package/dist/catalog/orchestration/subagent.tools.d.ts.map +0 -1
- package/dist/catalog/orchestration/subagent.tools.js +0 -25
- package/dist/catalog/orchestration/subagent.tools.js.map +0 -1
- package/dist/definitions.d.ts +0 -2
- package/dist/definitions.d.ts.map +0 -1
- package/dist/definitions.js +0 -2
- package/dist/definitions.js.map +0 -1
- package/dist/execution/atomic-write.d.ts +0 -2
- package/dist/execution/atomic-write.d.ts.map +0 -1
- package/dist/execution/atomic-write.js +0 -7
- package/dist/execution/atomic-write.js.map +0 -1
- package/dist/execution/bash.d.ts +0 -3
- package/dist/execution/bash.d.ts.map +0 -1
- package/dist/execution/bash.js +0 -133
- package/dist/execution/bash.js.map +0 -1
- package/dist/execution/common.d.ts +0 -2
- package/dist/execution/common.d.ts.map +0 -1
- package/dist/execution/common.js +0 -6
- package/dist/execution/common.js.map +0 -1
- package/dist/execution/dispatch.d.ts +0 -4
- package/dist/execution/dispatch.d.ts.map +0 -1
- package/dist/execution/dispatch.js +0 -54
- package/dist/execution/dispatch.js.map +0 -1
- package/dist/execution/edit.d.ts +0 -9
- package/dist/execution/edit.d.ts.map +0 -1
- package/dist/execution/edit.js +0 -175
- package/dist/execution/edit.js.map +0 -1
- package/dist/execution/file-mutation-queue.d.ts +0 -2
- package/dist/execution/file-mutation-queue.d.ts.map +0 -1
- package/dist/execution/file-mutation-queue.js +0 -19
- package/dist/execution/file-mutation-queue.js.map +0 -1
- package/dist/execution/filesystem/legacy-edit.d.ts +0 -9
- package/dist/execution/filesystem/legacy-edit.d.ts.map +0 -1
- package/dist/execution/filesystem/legacy-edit.js +0 -122
- package/dist/execution/filesystem/legacy-edit.js.map +0 -1
- package/dist/execution/find.d.ts +0 -3
- package/dist/execution/find.d.ts.map +0 -1
- package/dist/execution/find.js +0 -90
- package/dist/execution/find.js.map +0 -1
- package/dist/execution/list.d.ts +0 -3
- package/dist/execution/list.d.ts.map +0 -1
- package/dist/execution/list.js +0 -46
- package/dist/execution/list.js.map +0 -1
- package/dist/execution/path.d.ts +0 -7
- package/dist/execution/path.d.ts.map +0 -1
- package/dist/execution/path.js +0 -69
- package/dist/execution/path.js.map +0 -1
- package/dist/execution/read.d.ts +0 -3
- package/dist/execution/read.d.ts.map +0 -1
- package/dist/execution/read.js +0 -97
- package/dist/execution/read.js.map +0 -1
- package/dist/execution/search-utils.d.ts +0 -8
- package/dist/execution/search-utils.d.ts.map +0 -1
- package/dist/execution/search-utils.js +0 -110
- package/dist/execution/search-utils.js.map +0 -1
- package/dist/execution/search.d.ts +0 -3
- package/dist/execution/search.d.ts.map +0 -1
- package/dist/execution/search.js +0 -131
- package/dist/execution/search.js.map +0 -1
- package/dist/execution/truncate.d.ts +0 -21
- package/dist/execution/truncate.d.ts.map +0 -1
- package/dist/execution/truncate.js +0 -94
- package/dist/execution/truncate.js.map +0 -1
- package/dist/execution/web-fetch.d.ts +0 -3
- package/dist/execution/web-fetch.d.ts.map +0 -1
- package/dist/execution/web-fetch.js +0 -132
- package/dist/execution/web-fetch.js.map +0 -1
- package/dist/execution/web-search.d.ts +0 -3
- package/dist/execution/web-search.d.ts.map +0 -1
- package/dist/execution/web-search.js +0 -59
- package/dist/execution/web-search.js.map +0 -1
- package/dist/execution/write.d.ts +0 -3
- package/dist/execution/write.d.ts.map +0 -1
- package/dist/execution/write.js +0 -21
- package/dist/execution/write.js.map +0 -1
package/dist/execution/find.js
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { execFile } from "node:child_process";
|
|
2
|
-
import { stat } from "node:fs/promises";
|
|
3
|
-
import { relative } from "node:path";
|
|
4
|
-
import { promisify } from "node:util";
|
|
5
|
-
import { numberArg } from "./common.js";
|
|
6
|
-
import { isErrnoException, pathNotFoundMessage, resolveToolPath, } from "./path.js";
|
|
7
|
-
import { globToRegExp, walkFiles } from "./search-utils.js";
|
|
8
|
-
import { truncateHead } from "./truncate.js";
|
|
9
|
-
const execFileAsync = promisify(execFile);
|
|
10
|
-
export async function executeFind(args, context) {
|
|
11
|
-
if (typeof args.pattern !== "string" || args.pattern.length === 0) {
|
|
12
|
-
throw new Error("Tool argument 'pattern' must be a non-empty string.");
|
|
13
|
-
}
|
|
14
|
-
const input = args.path ?? ".";
|
|
15
|
-
const root = resolveToolPath(context.cwd, input);
|
|
16
|
-
await stat(root).catch((error) => {
|
|
17
|
-
if (isErrnoException(error) && error.code === "ENOENT") {
|
|
18
|
-
throw new Error(pathNotFoundMessage("find", input, root));
|
|
19
|
-
}
|
|
20
|
-
throw error;
|
|
21
|
-
});
|
|
22
|
-
const limit = Math.min(numberArg(args.limit, 1000), 5000);
|
|
23
|
-
const fd = await runFd(args.pattern, root, limit).catch(() => undefined);
|
|
24
|
-
const paths = fd ?? (await fallbackFind(root, args.pattern, limit));
|
|
25
|
-
const entries = paths
|
|
26
|
-
.slice(0, limit)
|
|
27
|
-
.map((path) => ({ path, kind: "file" }));
|
|
28
|
-
const formatted = formatFind(paths, limit);
|
|
29
|
-
return {
|
|
30
|
-
path: root,
|
|
31
|
-
entries,
|
|
32
|
-
content: formatted.content,
|
|
33
|
-
contentBlocks: [{ type: "text", text: formatted.content }],
|
|
34
|
-
details: formatted.details,
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
async function runFd(pattern, root, limit) {
|
|
38
|
-
const fdArgs = [
|
|
39
|
-
"--hidden",
|
|
40
|
-
"--glob",
|
|
41
|
-
"--type",
|
|
42
|
-
"file",
|
|
43
|
-
"--color=never",
|
|
44
|
-
"--no-require-git",
|
|
45
|
-
"--max-results",
|
|
46
|
-
String(limit),
|
|
47
|
-
];
|
|
48
|
-
let effectivePattern = pattern;
|
|
49
|
-
if (pattern.includes("/")) {
|
|
50
|
-
fdArgs.push("--full-path");
|
|
51
|
-
if (!pattern.startsWith("/") && !pattern.startsWith("**/")) {
|
|
52
|
-
effectivePattern = `**/${pattern}`;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
fdArgs.push("--", effectivePattern, root);
|
|
56
|
-
const { stdout } = await execFileAsync("fd", fdArgs, {
|
|
57
|
-
timeout: 30_000,
|
|
58
|
-
maxBuffer: 1024 * 1024,
|
|
59
|
-
});
|
|
60
|
-
return stdout
|
|
61
|
-
.split(/\r?\n/)
|
|
62
|
-
.map((line) => line.trim())
|
|
63
|
-
.filter(Boolean)
|
|
64
|
-
.map((path) => (relative(root, path) || path).replaceAll("\\", "/"));
|
|
65
|
-
}
|
|
66
|
-
async function fallbackFind(root, pattern, limit) {
|
|
67
|
-
const results = [];
|
|
68
|
-
const regex = globToRegExp(pattern);
|
|
69
|
-
await walkFiles(root, root, limit, async (_absolutePath, relativePath) => {
|
|
70
|
-
if (regex.test(relativePath))
|
|
71
|
-
results.push(relativePath.replaceAll("\\", "/"));
|
|
72
|
-
}, () => results.length >= limit);
|
|
73
|
-
return results;
|
|
74
|
-
}
|
|
75
|
-
function formatFind(paths, limit) {
|
|
76
|
-
const lines = paths.slice(0, limit);
|
|
77
|
-
if (lines.length === 0)
|
|
78
|
-
lines.push("No files found.");
|
|
79
|
-
if (paths.length >= limit) {
|
|
80
|
-
lines.push("", `[Result limit ${limit} reached. Increase limit or refine the pattern for more results.]`);
|
|
81
|
-
}
|
|
82
|
-
const truncated = truncateHead(lines.join("\n"), {
|
|
83
|
-
maxLines: Number.MAX_SAFE_INTEGER,
|
|
84
|
-
});
|
|
85
|
-
return {
|
|
86
|
-
content: truncated.text,
|
|
87
|
-
details: truncated.truncated ? { truncation: truncated } : undefined,
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
//# sourceMappingURL=find.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"find.js","sourceRoot":"","sources":["../../src/execution/find.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,IAAI,EAAE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AAC;IACpC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,KAAK,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;IACtD,IAAI,KAAK,CAAC,MAAM,IAAI,KAAK,EAAE,CAAC;QAC1B,KAAK,CAAC,IAAI,CACR,EAAE,EACF,iBAAiB,KAAK,mEAAmE,CAC1F,CAAC;IACJ,CAAC;IACD,MAAM,SAAS,GAAG,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;QAC/C,QAAQ,EAAE,MAAM,CAAC,gBAAgB;KAClC,CAAC,CAAC;IACH,OAAO;QACL,OAAO,EAAE,SAAS,CAAC,IAAI;QACvB,OAAO,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,SAAS;KACrE,CAAC;AACJ,CAAC"}
|
package/dist/execution/list.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../src/execution/list.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAS7E,wBAAsB,SAAS,CAC7B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,mBAAmB,CAAC,CA2C9B"}
|
package/dist/execution/list.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { readdir, stat } from "node:fs/promises";
|
|
2
|
-
import { numberArg } from "./common.js";
|
|
3
|
-
import { isErrnoException, pathNotFoundMessage, resolveToolPath, } from "./path.js";
|
|
4
|
-
import { truncateHead } from "./truncate.js";
|
|
5
|
-
export async function executeLs(args, context) {
|
|
6
|
-
const input = args.path ?? ".";
|
|
7
|
-
const root = resolveToolPath(context.cwd, input);
|
|
8
|
-
const info = await stat(root).catch((error) => {
|
|
9
|
-
if (isErrnoException(error) && error.code === "ENOENT") {
|
|
10
|
-
throw new Error(pathNotFoundMessage("ls", input, root));
|
|
11
|
-
}
|
|
12
|
-
throw error;
|
|
13
|
-
});
|
|
14
|
-
if (!info.isDirectory())
|
|
15
|
-
throw new Error("ls path is not a directory.");
|
|
16
|
-
const limit = Math.min(numberArg(args.limit, 500), 5000);
|
|
17
|
-
const dirEntries = await readdir(root, { withFileTypes: true });
|
|
18
|
-
dirEntries.sort((a, b) => a.name.toLowerCase().localeCompare(b.name.toLowerCase()));
|
|
19
|
-
const entries = [];
|
|
20
|
-
for (const entry of dirEntries.slice(0, limit)) {
|
|
21
|
-
entries.push({
|
|
22
|
-
path: `${entry.name}${entry.isDirectory() ? "/" : ""}`,
|
|
23
|
-
kind: entry.isDirectory()
|
|
24
|
-
? "directory"
|
|
25
|
-
: entry.isFile()
|
|
26
|
-
? "file"
|
|
27
|
-
: "other",
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
let content = entries.map((entry) => entry.path).join("\n");
|
|
31
|
-
if (dirEntries.length > entries.length) {
|
|
32
|
-
content += `${content ? "\n\n" : ""}[...${dirEntries.length - entries.length} more entries. Increase limit to see more.]`;
|
|
33
|
-
}
|
|
34
|
-
const truncated = truncateHead(content, {
|
|
35
|
-
maxLines: Number.MAX_SAFE_INTEGER,
|
|
36
|
-
});
|
|
37
|
-
content = truncated.text;
|
|
38
|
-
return {
|
|
39
|
-
path: root,
|
|
40
|
-
entries,
|
|
41
|
-
content,
|
|
42
|
-
contentBlocks: [{ type: "text", text: content }],
|
|
43
|
-
details: truncated.truncated ? { truncation: truncated } : undefined,
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
//# sourceMappingURL=list.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"list.js","sourceRoot":"","sources":["../../src/execution/list.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,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/execution/path.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export declare function expandToolPathInput(input: string): string;
|
|
2
|
-
export declare function resolveToCwd(cwd: string, input: string): string;
|
|
3
|
-
export declare function resolveToolPath(cwd: string, input: unknown): string;
|
|
4
|
-
export declare function isErrnoException(error: unknown): error is NodeJS.ErrnoException;
|
|
5
|
-
export declare function pathNotFoundMessage(toolName: string, input: unknown, resolvedPath: string): string;
|
|
6
|
-
export declare function resolveReadPath(cwd: string, input: unknown): Promise<string>;
|
|
7
|
-
//# sourceMappingURL=path.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"path.d.ts","sourceRoot":"","sources":["../../src/execution/path.ts"],"names":[],"mappings":"AAMA,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAQzD;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAG/D;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,MAAM,CAKnE;AAED,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,MAAM,CAAC,cAAc,CAEhC;AAED,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,OAAO,EACd,YAAY,EAAE,MAAM,GACnB,MAAM,CAGR;AAED,wBAAsB,eAAe,CACnC,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,OAAO,GACb,OAAO,CAAC,MAAM,CAAC,CAOjB"}
|
package/dist/execution/path.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { access } from "node:fs/promises";
|
|
2
|
-
import { homedir } from "node:os";
|
|
3
|
-
import { isAbsolute, resolve } from "node:path";
|
|
4
|
-
const UNICODE_SPACES = /[\u00a0\u2007\u202f]/g;
|
|
5
|
-
export function expandToolPathInput(input) {
|
|
6
|
-
let path = input.trim().replace(UNICODE_SPACES, " ").normalize("NFC");
|
|
7
|
-
if (path.startsWith("@"))
|
|
8
|
-
path = path.slice(1);
|
|
9
|
-
if (path === "~")
|
|
10
|
-
return homedir();
|
|
11
|
-
if (path.startsWith("~/") || path.startsWith("~\\")) {
|
|
12
|
-
return resolve(homedir(), path.slice(2));
|
|
13
|
-
}
|
|
14
|
-
return path;
|
|
15
|
-
}
|
|
16
|
-
export function resolveToCwd(cwd, input) {
|
|
17
|
-
const expanded = expandToolPathInput(input);
|
|
18
|
-
return isAbsolute(expanded) ? resolve(expanded) : resolve(cwd, expanded);
|
|
19
|
-
}
|
|
20
|
-
export function resolveToolPath(cwd, input) {
|
|
21
|
-
if (typeof input !== "string" || input.trim().length === 0) {
|
|
22
|
-
throw new Error("Tool argument 'path' must be a non-empty string.");
|
|
23
|
-
}
|
|
24
|
-
return resolveToCwd(cwd, input);
|
|
25
|
-
}
|
|
26
|
-
export function isErrnoException(error) {
|
|
27
|
-
return error instanceof Error && "code" in error;
|
|
28
|
-
}
|
|
29
|
-
export function pathNotFoundMessage(toolName, input, resolvedPath) {
|
|
30
|
-
const label = typeof input === "string" ? JSON.stringify(input) : "path";
|
|
31
|
-
return `${toolName} path not found: ${label} (resolved to ${resolvedPath}).`;
|
|
32
|
-
}
|
|
33
|
-
export async function resolveReadPath(cwd, input) {
|
|
34
|
-
const initial = resolveToolPath(cwd, input);
|
|
35
|
-
const candidates = readPathCandidates(initial);
|
|
36
|
-
for (const candidate of candidates) {
|
|
37
|
-
if (await exists(candidate))
|
|
38
|
-
return candidate;
|
|
39
|
-
}
|
|
40
|
-
return initial;
|
|
41
|
-
}
|
|
42
|
-
function readPathCandidates(path) {
|
|
43
|
-
const variants = new Set([
|
|
44
|
-
path,
|
|
45
|
-
path.normalize("NFC"),
|
|
46
|
-
path.normalize("NFD"),
|
|
47
|
-
]);
|
|
48
|
-
for (const value of [...variants]) {
|
|
49
|
-
variants.add(value.replace(UNICODE_SPACES, " "));
|
|
50
|
-
}
|
|
51
|
-
// macOS screenshots sometimes use narrow no-break spaces before AM/PM.
|
|
52
|
-
for (const value of [...variants]) {
|
|
53
|
-
variants.add(value.replace(/ ([AP]M)(\.[^./]+)?$/u, "\u202f$1$2"));
|
|
54
|
-
variants.add(value.replace(/\u202f([AP]M)(\.[^./]+)?$/u, " $1$2"));
|
|
55
|
-
variants.add(value.replace(/[’‘]/g, "'"));
|
|
56
|
-
variants.add(value.replace(/'/g, "’"));
|
|
57
|
-
}
|
|
58
|
-
return [...variants].filter((candidate) => candidate.length > 0);
|
|
59
|
-
}
|
|
60
|
-
async function exists(path) {
|
|
61
|
-
try {
|
|
62
|
-
await access(path);
|
|
63
|
-
return true;
|
|
64
|
-
}
|
|
65
|
-
catch {
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
//# sourceMappingURL=path.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"path.js","sourceRoot":"","sources":["../../src/execution/path.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEhD,MAAM,cAAc,GAAG,uBAAuB,CAAC;AAE/C,MAAM,UAAU,mBAAmB,CAAC,KAAa;IAC/C,IAAI,IAAI,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,cAAc,EAAE,GAAG,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACtE,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;QAAE,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC/C,IAAI,IAAI,KAAK,GAAG;QAAE,OAAO,OAAO,EAAE,CAAC;IACnC,IAAI,IAAI,CAAC,UAAU,CAAC,IAA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AAY;IAChC,IAAI,CAAC;QACH,MAAM,MAAM,CAAC,IAAI,CAAC,CAAC;QACnB,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
|
package/dist/execution/read.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../../src/execution/read.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAyC7E,wBAAsB,WAAW,CAC/B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,mBAAmB,CAAC,CAgE9B"}
|
package/dist/execution/read.js
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { readFile } from "node:fs/promises";
|
|
2
|
-
import { numberArg } from "./common.js";
|
|
3
|
-
import { isErrnoException, pathNotFoundMessage, resolveReadPath, } from "./path.js";
|
|
4
|
-
import { DEFAULT_MAX_LINES, formatSize, truncateHead } from "./truncate.js";
|
|
5
|
-
const PNG_SIGNATURE = [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a];
|
|
6
|
-
function startsWith(buffer, bytes) {
|
|
7
|
-
if (buffer.length < bytes.length)
|
|
8
|
-
return false;
|
|
9
|
-
return bytes.every((byte, index) => buffer[index] === byte);
|
|
10
|
-
}
|
|
11
|
-
function startsWithAscii(buffer, offset, text) {
|
|
12
|
-
if (buffer.length < offset + text.length)
|
|
13
|
-
return false;
|
|
14
|
-
for (let index = 0; index < text.length; index += 1) {
|
|
15
|
-
if (buffer[offset + index] !== text.charCodeAt(index))
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
return true;
|
|
19
|
-
}
|
|
20
|
-
function detectSupportedImageMimeType(buffer) {
|
|
21
|
-
if (startsWith(buffer, [0xff, 0xd8, 0xff]))
|
|
22
|
-
return "image/jpeg";
|
|
23
|
-
if (startsWith(buffer, PNG_SIGNATURE))
|
|
24
|
-
return "image/png";
|
|
25
|
-
if (startsWithAscii(buffer, 0, "GIF"))
|
|
26
|
-
return "image/gif";
|
|
27
|
-
if (startsWithAscii(buffer, 0, "RIFF") &&
|
|
28
|
-
startsWithAscii(buffer, 8, "WEBP")) {
|
|
29
|
-
return "image/webp";
|
|
30
|
-
}
|
|
31
|
-
return null;
|
|
32
|
-
}
|
|
33
|
-
export async function executeRead(args, context) {
|
|
34
|
-
const path = await resolveReadPath(context.cwd, args.path);
|
|
35
|
-
const buffer = await readFile(path).catch((error) => {
|
|
36
|
-
if (isErrnoException(error) && error.code === "ENOENT") {
|
|
37
|
-
throw new Error(pathNotFoundMessage("read", args.path, path));
|
|
38
|
-
}
|
|
39
|
-
throw error;
|
|
40
|
-
});
|
|
41
|
-
const mimeType = detectSupportedImageMimeType(buffer);
|
|
42
|
-
if (mimeType) {
|
|
43
|
-
const content = `Read image file [${mimeType}]`;
|
|
44
|
-
return {
|
|
45
|
-
path,
|
|
46
|
-
content,
|
|
47
|
-
contentBlocks: [
|
|
48
|
-
{ type: "text", text: content },
|
|
49
|
-
{ type: "image", data: buffer.toString("base64"), mimeType },
|
|
50
|
-
],
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
const content = buffer.toString("utf8");
|
|
54
|
-
const lines = content.split(/\r?\n/);
|
|
55
|
-
const hasExplicitLimit = typeof args.limit === "number";
|
|
56
|
-
const hasExplicitOffset = typeof args.offset === "number";
|
|
57
|
-
const offset = numberArg(args.offset, 1);
|
|
58
|
-
if (hasExplicitLimit || hasExplicitOffset) {
|
|
59
|
-
const limit = Math.min(numberArg(args.limit, 1000), 5000);
|
|
60
|
-
const start = Math.max(0, offset - 1);
|
|
61
|
-
const selected = lines.slice(start, start + limit).join("\n");
|
|
62
|
-
const remaining = Math.max(0, lines.length - (start + limit));
|
|
63
|
-
const output = remaining > 0
|
|
64
|
-
? `${selected}\n\n[...${remaining} more lines. Continue with offset ${offset + limit}.]`
|
|
65
|
-
: selected;
|
|
66
|
-
return {
|
|
67
|
-
path,
|
|
68
|
-
content: output,
|
|
69
|
-
contentBlocks: [{ type: "text", text: output }],
|
|
70
|
-
details: remaining > 0
|
|
71
|
-
? {
|
|
72
|
-
truncation: {
|
|
73
|
-
omittedLines: remaining,
|
|
74
|
-
nextOffset: offset + limit,
|
|
75
|
-
},
|
|
76
|
-
}
|
|
77
|
-
: undefined,
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
const truncated = truncateHead(content);
|
|
81
|
-
let output = truncated.text;
|
|
82
|
-
if (truncated.truncated) {
|
|
83
|
-
output += `\n\n[...output truncated to ${DEFAULT_MAX_LINES} lines or ${formatSize(50 * 1024)}. Continue reading with offset ${countLines(truncated.text) + 1}.]`;
|
|
84
|
-
}
|
|
85
|
-
return {
|
|
86
|
-
path,
|
|
87
|
-
content: output,
|
|
88
|
-
contentBlocks: [{ type: "text", text: output }],
|
|
89
|
-
details: truncated.truncated ? { truncation: truncated } : undefined,
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
function countLines(text) {
|
|
93
|
-
if (text.length === 0)
|
|
94
|
-
return 0;
|
|
95
|
-
return text.split("\n").length;
|
|
96
|
-
}
|
|
97
|
-
//# sourceMappingURL=read.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"read.js","sourceRoot":"","sources":["../../src/execution/read.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,eAAe,GAChB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE5E,MAAM,aAAa,GAA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AAa,UAAU,CAAC,EAAE,GAAG,IAAI,CAAC,kCAAkC,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC;IACnK,CAAC;IACD,OAAO;QACL,IAAI;QACJ,OAAO,EAAE,MAAM;QACf,aAAa,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QAC/C,OAAO,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,SAAS;KACrE,CAAC;AACJ,CAAC;AAED,SAAS,UAAU,CAAC,IAAY;IAC9B,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,CAAC,CAAC;IAChC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC;AACjC,CAAC"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export type SearchScope = {
|
|
2
|
-
roots: string[];
|
|
3
|
-
displayRoot: string;
|
|
4
|
-
};
|
|
5
|
-
export declare function resolveSearchScope(cwd: string, args: Record<string, unknown>, toolName: string): Promise<SearchScope>;
|
|
6
|
-
export declare function walkFiles(root: string, path: string, limit: number, onFile: (absolutePath: string, relativePath: string) => Promise<void>, shouldStop?: () => boolean): Promise<void>;
|
|
7
|
-
export declare function globToRegExp(pattern: string): RegExp;
|
|
8
|
-
//# sourceMappingURL=search-utils.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"search-utils.d.ts","sourceRoot":"","sources":["../../src/execution/search-utils.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAQF,wBAAsB,kBAAkB,CACtC,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,WAAW,CAAC,CAmCtB;AA+CD,wBAAsB,SAAS,CAC7B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,CAAC,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,EACrE,UAAU,CAAC,EAAE,MAAM,OAAO,GACzB,OAAO,CAAC,IAAI,CAAC,CAef;AAED,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAqBpD"}
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { constants } from "node:fs";
|
|
2
|
-
import { access, readdir, stat } from "node:fs/promises";
|
|
3
|
-
import { dirname, isAbsolute, join, relative } from "node:path";
|
|
4
|
-
import { isErrnoException, resolveToolPath } from "./path.js";
|
|
5
|
-
export async function resolveSearchScope(cwd, args, toolName) {
|
|
6
|
-
if (args.path !== undefined && args.paths !== undefined) {
|
|
7
|
-
throw new Error(`${toolName} accepts either 'path' or 'paths', not both.`);
|
|
8
|
-
}
|
|
9
|
-
const inputs = searchScopeInputs(args, toolName);
|
|
10
|
-
const roots = [];
|
|
11
|
-
for (const input of inputs) {
|
|
12
|
-
const path = resolveToolPath(cwd, input);
|
|
13
|
-
const info = await stat(path).catch((error) => {
|
|
14
|
-
if (isErrnoException(error) && error.code === "ENOENT") {
|
|
15
|
-
throw new Error(`${toolName} path not found: ${JSON.stringify(input)} (resolved to ${path}). Pass one path in 'path' or multiple paths as 'paths': [...].`);
|
|
16
|
-
}
|
|
17
|
-
throw error;
|
|
18
|
-
});
|
|
19
|
-
if (!info.isFile() && !info.isDirectory()) {
|
|
20
|
-
throw new Error(`${toolName} path is not a file or directory: ${JSON.stringify(input)} (resolved to ${path}).`);
|
|
21
|
-
}
|
|
22
|
-
roots.push({
|
|
23
|
-
input,
|
|
24
|
-
path,
|
|
25
|
-
kind: info.isDirectory() ? "directory" : "file",
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
const rootBases = roots.map((root) => root.kind === "directory" ? root.path : dirname(root.path));
|
|
29
|
-
const displayRoot = rootBases.length === 1 ? rootBases[0] : commonAncestor(rootBases);
|
|
30
|
-
return { roots: roots.map((root) => root.path), displayRoot };
|
|
31
|
-
}
|
|
32
|
-
function searchScopeInputs(args, toolName) {
|
|
33
|
-
if (args.paths !== undefined) {
|
|
34
|
-
if (!Array.isArray(args.paths) || args.paths.length === 0) {
|
|
35
|
-
throw new Error(`${toolName} 'paths' must be a non-empty array of strings.`);
|
|
36
|
-
}
|
|
37
|
-
return args.paths.map((input) => {
|
|
38
|
-
if (typeof input !== "string" || input.trim().length === 0) {
|
|
39
|
-
throw new Error(`${toolName} 'paths' must be a non-empty array of strings.`);
|
|
40
|
-
}
|
|
41
|
-
return input;
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
if (args.path !== undefined) {
|
|
45
|
-
if (typeof args.path !== "string" || args.path.trim().length === 0) {
|
|
46
|
-
throw new Error(`${toolName} 'path' must be a non-empty string.`);
|
|
47
|
-
}
|
|
48
|
-
return [args.path];
|
|
49
|
-
}
|
|
50
|
-
return ["."];
|
|
51
|
-
}
|
|
52
|
-
function commonAncestor(paths) {
|
|
53
|
-
let current = paths[0] ?? "/";
|
|
54
|
-
for (const path of paths.slice(1)) {
|
|
55
|
-
while (!isInsideOrSame(current, path)) {
|
|
56
|
-
const parent = dirname(current);
|
|
57
|
-
if (parent === current)
|
|
58
|
-
return current;
|
|
59
|
-
current = parent;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return current;
|
|
63
|
-
}
|
|
64
|
-
function isInsideOrSame(parent, child) {
|
|
65
|
-
const rel = relative(parent, child);
|
|
66
|
-
return rel === "" || (!rel.startsWith("..") && !isAbsolute(rel));
|
|
67
|
-
}
|
|
68
|
-
export async function walkFiles(root, path, limit, onFile, shouldStop) {
|
|
69
|
-
if (shouldStop?.())
|
|
70
|
-
return;
|
|
71
|
-
const info = await stat(path);
|
|
72
|
-
if (info.isDirectory()) {
|
|
73
|
-
const entries = await readdir(path, { withFileTypes: true });
|
|
74
|
-
for (const entry of entries) {
|
|
75
|
-
if (shouldStop?.())
|
|
76
|
-
return;
|
|
77
|
-
if (entry.name === "node_modules" || entry.name === ".git")
|
|
78
|
-
continue;
|
|
79
|
-
await walkFiles(root, join(path, entry.name), limit, onFile, shouldStop);
|
|
80
|
-
}
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
if (!info.isFile())
|
|
84
|
-
return;
|
|
85
|
-
await access(path, constants.R_OK);
|
|
86
|
-
await onFile(path, relative(root, path));
|
|
87
|
-
}
|
|
88
|
-
export function globToRegExp(pattern) {
|
|
89
|
-
let output = "";
|
|
90
|
-
for (let index = 0; index < pattern.length; index += 1) {
|
|
91
|
-
const char = pattern[index];
|
|
92
|
-
const next = pattern[index + 1];
|
|
93
|
-
if (char === "*" && next === "*") {
|
|
94
|
-
output += ".*";
|
|
95
|
-
index += 1;
|
|
96
|
-
continue;
|
|
97
|
-
}
|
|
98
|
-
if (char === "*") {
|
|
99
|
-
output += "[^/]*";
|
|
100
|
-
continue;
|
|
101
|
-
}
|
|
102
|
-
if (char === "?") {
|
|
103
|
-
output += "[^/]";
|
|
104
|
-
continue;
|
|
105
|
-
}
|
|
106
|
-
output += char?.replace(/[.+^${}()|[\]\\]/g, "\\$&") ?? "";
|
|
107
|
-
}
|
|
108
|
-
return new RegExp(`^${output}$`);
|
|
109
|
-
}
|
|
110
|
-
//# sourceMappingURL=search-utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"search-utils.js","sourceRoot":"","sources":["../../src/execution/search-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC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K,GAAG,EAAE,CAAC;YACjB,MAAM,IAAI,OAAO,CAAC;YAClB,SAAS;QACX,CAAC;QACD,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;YACjB,MAAM,IAAI,MAAM,CAAC;YACjB,SAAS;QACX,CAAC;QACD,MAAM,IAAI,IAAI,EAAE,OAAO,CAAC,mBAAmB,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;IAC7D,CAAC;IACD,OAAO,IAAI,MAAM,CAAC,IAAI,MAAM,GAAG,CAAC,CAAC;AACnC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../src/execution/search.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAc7E,wBAAsB,WAAW,CAC/B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,mBAAmB,CAAC,CAgB9B"}
|
package/dist/execution/search.js
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import { execFile } from "node:child_process";
|
|
2
|
-
import { readFile, stat } from "node:fs/promises";
|
|
3
|
-
import { relative } from "node:path";
|
|
4
|
-
import { promisify } from "node:util";
|
|
5
|
-
import { numberArg } from "./common.js";
|
|
6
|
-
import { globToRegExp, resolveSearchScope, walkFiles, } from "./search-utils.js";
|
|
7
|
-
import { truncateHead, truncateLine } from "./truncate.js";
|
|
8
|
-
const execFileAsync = promisify(execFile);
|
|
9
|
-
export async function executeGrep(args, context) {
|
|
10
|
-
if (typeof args.pattern !== "string" || args.pattern.length === 0) {
|
|
11
|
-
throw new Error("Tool argument 'pattern' must be a non-empty string.");
|
|
12
|
-
}
|
|
13
|
-
const scope = await resolveSearchScope(context.cwd, args, "grep");
|
|
14
|
-
const limit = Math.min(numberArg(args.limit, 100), 2000);
|
|
15
|
-
const rg = await runRg(args, scope, limit).catch(() => undefined);
|
|
16
|
-
const matches = rg ?? (await fallbackGrep(args, scope, limit));
|
|
17
|
-
const formatted = formatMatches(matches, limit);
|
|
18
|
-
return {
|
|
19
|
-
path: scope.displayRoot,
|
|
20
|
-
matches: matches.slice(0, limit),
|
|
21
|
-
content: formatted.content,
|
|
22
|
-
contentBlocks: [{ type: "text", text: formatted.content }],
|
|
23
|
-
details: formatted.details,
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
async function runRg(args, scope, limit) {
|
|
27
|
-
const rgArgs = [
|
|
28
|
-
"--line-number",
|
|
29
|
-
"--color=never",
|
|
30
|
-
"--hidden",
|
|
31
|
-
"--with-filename",
|
|
32
|
-
];
|
|
33
|
-
if (args.ignoreCase)
|
|
34
|
-
rgArgs.push("--ignore-case");
|
|
35
|
-
if (args.literal)
|
|
36
|
-
rgArgs.push("--fixed-strings");
|
|
37
|
-
if (typeof args.glob === "string" && args.glob.length > 0) {
|
|
38
|
-
rgArgs.push("--glob", args.glob);
|
|
39
|
-
}
|
|
40
|
-
const contextLines = numberArg(args.context, 0);
|
|
41
|
-
if (contextLines > 0)
|
|
42
|
-
rgArgs.push("--context", String(contextLines));
|
|
43
|
-
rgArgs.push("--", String(args.pattern), ...scope.roots);
|
|
44
|
-
const { stdout } = await execFileAsync("rg", rgArgs, {
|
|
45
|
-
timeout: 30_000,
|
|
46
|
-
maxBuffer: 1024 * 1024 * 4,
|
|
47
|
-
});
|
|
48
|
-
const matches = [];
|
|
49
|
-
for (const line of stdout.split(/\r?\n/)) {
|
|
50
|
-
if (!line)
|
|
51
|
-
continue;
|
|
52
|
-
const match = /^(.*?):(\d+):(.*)$/.exec(line);
|
|
53
|
-
if (!match)
|
|
54
|
-
continue;
|
|
55
|
-
matches.push({
|
|
56
|
-
path: relative(scope.displayRoot, match[1] ?? "").replaceAll("\\", "/") ||
|
|
57
|
-
(match[1] ?? ""),
|
|
58
|
-
line: Number(match[2]),
|
|
59
|
-
text: match[3] ?? "",
|
|
60
|
-
});
|
|
61
|
-
if (matches.length >= limit)
|
|
62
|
-
break;
|
|
63
|
-
}
|
|
64
|
-
return matches;
|
|
65
|
-
}
|
|
66
|
-
async function fallbackGrep(args, scope, limit) {
|
|
67
|
-
const matches = [];
|
|
68
|
-
const literal = Boolean(args.literal);
|
|
69
|
-
const ignoreCase = Boolean(args.ignoreCase);
|
|
70
|
-
const pattern = String(args.pattern);
|
|
71
|
-
const regex = literal
|
|
72
|
-
? undefined
|
|
73
|
-
: new RegExp(pattern, ignoreCase ? "i" : undefined);
|
|
74
|
-
const needle = ignoreCase ? pattern.toLowerCase() : pattern;
|
|
75
|
-
const glob = typeof args.glob === "string" ? globToRegExp(args.glob) : undefined;
|
|
76
|
-
for (const root of scope.roots) {
|
|
77
|
-
await walkFiles(scope.displayRoot, root, limit, async (absolutePath, relativePath) => {
|
|
78
|
-
if (glob && !glob.test(relativePath))
|
|
79
|
-
return;
|
|
80
|
-
const info = await stat(absolutePath);
|
|
81
|
-
if (info.size > 1024 * 1024)
|
|
82
|
-
return;
|
|
83
|
-
const content = await readFile(absolutePath, "utf8").catch(() => undefined);
|
|
84
|
-
if (content === undefined)
|
|
85
|
-
return;
|
|
86
|
-
const lines = content.split(/\r?\n/);
|
|
87
|
-
for (const [index, line] of lines.entries()) {
|
|
88
|
-
const haystack = ignoreCase ? line.toLowerCase() : line;
|
|
89
|
-
if (regex ? regex.test(line) : haystack.includes(needle)) {
|
|
90
|
-
matches.push({
|
|
91
|
-
path: relativePath.replaceAll("\\", "/"),
|
|
92
|
-
line: index + 1,
|
|
93
|
-
text: line,
|
|
94
|
-
});
|
|
95
|
-
if (matches.length >= limit)
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}, () => matches.length >= limit);
|
|
100
|
-
if (matches.length >= limit)
|
|
101
|
-
break;
|
|
102
|
-
}
|
|
103
|
-
return matches;
|
|
104
|
-
}
|
|
105
|
-
function formatMatches(matches, limit) {
|
|
106
|
-
let truncatedLines = 0;
|
|
107
|
-
const lines = matches.slice(0, limit).map((match) => {
|
|
108
|
-
const text = truncateLine(match.text);
|
|
109
|
-
if (text.truncated)
|
|
110
|
-
truncatedLines += 1;
|
|
111
|
-
return `${match.path}:${match.line}: ${text.text}`;
|
|
112
|
-
});
|
|
113
|
-
if (matches.length === 0)
|
|
114
|
-
lines.push("No matches found.");
|
|
115
|
-
if (matches.length >= limit) {
|
|
116
|
-
lines.push(``, `[Match limit ${limit} reached. Increase limit or refine the pattern for more results.]`);
|
|
117
|
-
}
|
|
118
|
-
if (truncatedLines > 0) {
|
|
119
|
-
lines.push(``, `[${truncatedLines} matching line(s) truncated to 500 characters. Use read to inspect full lines.]`);
|
|
120
|
-
}
|
|
121
|
-
const truncated = truncateHead(lines.join("\n"), {
|
|
122
|
-
maxLines: Number.MAX_SAFE_INTEGER,
|
|
123
|
-
});
|
|
124
|
-
return {
|
|
125
|
-
content: truncated.text,
|
|
126
|
-
details: truncated.truncated || truncatedLines > 0
|
|
127
|
-
? { truncation: truncated, truncatedLines }
|
|
128
|
-
: undefined,
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
//# sourceMappingURL=search.js.map
|