wave-agent-sdk 0.0.1
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/README.md +32 -0
- package/dist/agent.d.ts +96 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +286 -0
- package/dist/hooks/executor.d.ts +56 -0
- package/dist/hooks/executor.d.ts.map +1 -0
- package/dist/hooks/executor.js +312 -0
- package/dist/hooks/index.d.ts +17 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +14 -0
- package/dist/hooks/manager.d.ts +90 -0
- package/dist/hooks/manager.d.ts.map +1 -0
- package/dist/hooks/manager.js +395 -0
- package/dist/hooks/matcher.d.ts +49 -0
- package/dist/hooks/matcher.d.ts.map +1 -0
- package/dist/hooks/matcher.js +147 -0
- package/dist/hooks/settings.d.ts +46 -0
- package/dist/hooks/settings.d.ts.map +1 -0
- package/dist/hooks/settings.js +100 -0
- package/dist/hooks/types.d.ts +80 -0
- package/dist/hooks/types.d.ts.map +1 -0
- package/dist/hooks/types.js +59 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/managers/aiManager.d.ts +61 -0
- package/dist/managers/aiManager.d.ts.map +1 -0
- package/dist/managers/aiManager.js +415 -0
- package/dist/managers/backgroundBashManager.d.ts +27 -0
- package/dist/managers/backgroundBashManager.d.ts.map +1 -0
- package/dist/managers/backgroundBashManager.js +166 -0
- package/dist/managers/bashManager.d.ts +20 -0
- package/dist/managers/bashManager.d.ts.map +1 -0
- package/dist/managers/bashManager.js +66 -0
- package/dist/managers/mcpManager.d.ts +63 -0
- package/dist/managers/mcpManager.d.ts.map +1 -0
- package/dist/managers/mcpManager.js +378 -0
- package/dist/managers/messageManager.d.ts +85 -0
- package/dist/managers/messageManager.d.ts.map +1 -0
- package/dist/managers/messageManager.js +265 -0
- package/dist/managers/skillManager.d.ts +59 -0
- package/dist/managers/skillManager.d.ts.map +1 -0
- package/dist/managers/skillManager.js +317 -0
- package/dist/managers/slashCommandManager.d.ts +77 -0
- package/dist/managers/slashCommandManager.d.ts.map +1 -0
- package/dist/managers/slashCommandManager.js +208 -0
- package/dist/managers/toolManager.d.ts +23 -0
- package/dist/managers/toolManager.d.ts.map +1 -0
- package/dist/managers/toolManager.js +79 -0
- package/dist/services/aiService.d.ts +28 -0
- package/dist/services/aiService.d.ts.map +1 -0
- package/dist/services/aiService.js +180 -0
- package/dist/services/memory.d.ts +8 -0
- package/dist/services/memory.d.ts.map +1 -0
- package/dist/services/memory.js +128 -0
- package/dist/services/session.d.ts +54 -0
- package/dist/services/session.d.ts.map +1 -0
- package/dist/services/session.js +196 -0
- package/dist/tools/bashTool.d.ts +14 -0
- package/dist/tools/bashTool.d.ts.map +1 -0
- package/dist/tools/bashTool.js +351 -0
- package/dist/tools/deleteFileTool.d.ts +6 -0
- package/dist/tools/deleteFileTool.d.ts.map +1 -0
- package/dist/tools/deleteFileTool.js +67 -0
- package/dist/tools/editTool.d.ts +6 -0
- package/dist/tools/editTool.d.ts.map +1 -0
- package/dist/tools/editTool.js +168 -0
- package/dist/tools/globTool.d.ts +6 -0
- package/dist/tools/globTool.d.ts.map +1 -0
- package/dist/tools/globTool.js +113 -0
- package/dist/tools/grepTool.d.ts +6 -0
- package/dist/tools/grepTool.d.ts.map +1 -0
- package/dist/tools/grepTool.js +268 -0
- package/dist/tools/lsTool.d.ts +6 -0
- package/dist/tools/lsTool.d.ts.map +1 -0
- package/dist/tools/lsTool.js +160 -0
- package/dist/tools/multiEditTool.d.ts +6 -0
- package/dist/tools/multiEditTool.d.ts.map +1 -0
- package/dist/tools/multiEditTool.js +222 -0
- package/dist/tools/readTool.d.ts +6 -0
- package/dist/tools/readTool.d.ts.map +1 -0
- package/dist/tools/readTool.js +136 -0
- package/dist/tools/types.d.ts +35 -0
- package/dist/tools/types.d.ts.map +1 -0
- package/dist/tools/types.js +4 -0
- package/dist/tools/writeTool.d.ts +6 -0
- package/dist/tools/writeTool.d.ts.map +1 -0
- package/dist/tools/writeTool.js +138 -0
- package/dist/types.d.ts +212 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +13 -0
- package/dist/utils/bashHistory.d.ts +46 -0
- package/dist/utils/bashHistory.d.ts.map +1 -0
- package/dist/utils/bashHistory.js +236 -0
- package/dist/utils/commandArgumentParser.d.ts +34 -0
- package/dist/utils/commandArgumentParser.d.ts.map +1 -0
- package/dist/utils/commandArgumentParser.js +123 -0
- package/dist/utils/constants.d.ts +27 -0
- package/dist/utils/constants.d.ts.map +1 -0
- package/dist/utils/constants.js +28 -0
- package/dist/utils/convertMessagesForAPI.d.ts +9 -0
- package/dist/utils/convertMessagesForAPI.d.ts.map +1 -0
- package/dist/utils/convertMessagesForAPI.js +189 -0
- package/dist/utils/customCommands.d.ts +14 -0
- package/dist/utils/customCommands.d.ts.map +1 -0
- package/dist/utils/customCommands.js +71 -0
- package/dist/utils/fileFilter.d.ts +26 -0
- package/dist/utils/fileFilter.d.ts.map +1 -0
- package/dist/utils/fileFilter.js +177 -0
- package/dist/utils/markdownParser.d.ts +27 -0
- package/dist/utils/markdownParser.d.ts.map +1 -0
- package/dist/utils/markdownParser.js +109 -0
- package/dist/utils/mcpUtils.d.ts +24 -0
- package/dist/utils/mcpUtils.d.ts.map +1 -0
- package/dist/utils/mcpUtils.js +51 -0
- package/dist/utils/messageOperations.d.ts +118 -0
- package/dist/utils/messageOperations.d.ts.map +1 -0
- package/dist/utils/messageOperations.js +334 -0
- package/dist/utils/path.d.ts +25 -0
- package/dist/utils/path.d.ts.map +1 -0
- package/dist/utils/path.js +109 -0
- package/dist/utils/skillParser.d.ts +18 -0
- package/dist/utils/skillParser.d.ts.map +1 -0
- package/dist/utils/skillParser.js +147 -0
- package/dist/utils/stringUtils.d.ts +13 -0
- package/dist/utils/stringUtils.d.ts.map +1 -0
- package/dist/utils/stringUtils.js +44 -0
- package/package.json +51 -0
- package/src/agent.ts +405 -0
- package/src/hooks/executor.ts +440 -0
- package/src/hooks/index.ts +52 -0
- package/src/hooks/manager.ts +618 -0
- package/src/hooks/matcher.ts +187 -0
- package/src/hooks/settings.ts +129 -0
- package/src/hooks/types.ts +169 -0
- package/src/index.ts +24 -0
- package/src/managers/aiManager.ts +573 -0
- package/src/managers/backgroundBashManager.ts +203 -0
- package/src/managers/bashManager.ts +97 -0
- package/src/managers/mcpManager.ts +493 -0
- package/src/managers/messageManager.ts +415 -0
- package/src/managers/skillManager.ts +404 -0
- package/src/managers/slashCommandManager.ts +293 -0
- package/src/managers/toolManager.ts +106 -0
- package/src/services/aiService.ts +252 -0
- package/src/services/memory.ts +149 -0
- package/src/services/session.ts +265 -0
- package/src/tools/bashTool.ts +402 -0
- package/src/tools/deleteFileTool.ts +81 -0
- package/src/tools/editTool.ts +192 -0
- package/src/tools/globTool.ts +135 -0
- package/src/tools/grepTool.ts +326 -0
- package/src/tools/lsTool.ts +187 -0
- package/src/tools/multiEditTool.ts +268 -0
- package/src/tools/readTool.ts +165 -0
- package/src/tools/types.ts +47 -0
- package/src/tools/writeTool.ts +163 -0
- package/src/types.ts +260 -0
- package/src/utils/bashHistory.ts +303 -0
- package/src/utils/commandArgumentParser.ts +153 -0
- package/src/utils/constants.ts +37 -0
- package/src/utils/convertMessagesForAPI.ts +236 -0
- package/src/utils/customCommands.ts +85 -0
- package/src/utils/fileFilter.ts +202 -0
- package/src/utils/markdownParser.ts +156 -0
- package/src/utils/mcpUtils.ts +81 -0
- package/src/utils/messageOperations.ts +506 -0
- package/src/utils/path.ts +118 -0
- package/src/utils/skillParser.ts +188 -0
- package/src/utils/stringUtils.ts +50 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { glob } from "glob";
|
|
2
|
+
import { stat } from "fs/promises";
|
|
3
|
+
import { resolvePath, getDisplayPath } from "../utils/path.js";
|
|
4
|
+
import { getGlobIgnorePatterns } from "../utils/fileFilter.js";
|
|
5
|
+
/**
|
|
6
|
+
* Glob Tool Plugin - Fast file pattern matching
|
|
7
|
+
*/
|
|
8
|
+
export const globTool = {
|
|
9
|
+
name: "Glob",
|
|
10
|
+
config: {
|
|
11
|
+
type: "function",
|
|
12
|
+
function: {
|
|
13
|
+
name: "Glob",
|
|
14
|
+
description: '- Fast file pattern matching tool that works with any codebase size\n- Supports glob patterns like "**/*.js" or "src/**/*.ts"\n- Returns matching file paths sorted by modification time\n- Use this tool when you need to find files by name patterns\n- When you are doing an open ended search that may require multiple rounds of globbing and grepping, use the Agent tool instead\n- You have the capability to call multiple tools in a single response. It is always better to speculatively perform multiple searches as a batch that are potentially useful.',
|
|
15
|
+
parameters: {
|
|
16
|
+
type: "object",
|
|
17
|
+
properties: {
|
|
18
|
+
pattern: {
|
|
19
|
+
type: "string",
|
|
20
|
+
description: "The glob pattern to match files against",
|
|
21
|
+
},
|
|
22
|
+
path: {
|
|
23
|
+
type: "string",
|
|
24
|
+
description: 'The directory to search in. If not specified, the current working directory will be used. IMPORTANT: Omit this field to use the default directory. DO NOT enter "undefined" or "null" - simply omit it for the default behavior. Must be a valid directory path if provided.',
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
required: ["pattern"],
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
execute: async (args, context) => {
|
|
32
|
+
const pattern = args.pattern;
|
|
33
|
+
const searchPath = args.path;
|
|
34
|
+
if (!pattern || typeof pattern !== "string") {
|
|
35
|
+
return {
|
|
36
|
+
success: false,
|
|
37
|
+
content: "",
|
|
38
|
+
error: "pattern parameter is required and must be a string",
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
// Determine search directory
|
|
43
|
+
const workdir = searchPath
|
|
44
|
+
? resolvePath(searchPath, context.workdir)
|
|
45
|
+
: context.workdir;
|
|
46
|
+
// Execute glob search
|
|
47
|
+
const matches = await glob(pattern, {
|
|
48
|
+
cwd: workdir,
|
|
49
|
+
ignore: getGlobIgnorePatterns(workdir),
|
|
50
|
+
dot: false,
|
|
51
|
+
absolute: false,
|
|
52
|
+
nocase: false, // Keep case sensitive
|
|
53
|
+
});
|
|
54
|
+
if (matches.length === 0) {
|
|
55
|
+
return {
|
|
56
|
+
success: true,
|
|
57
|
+
content: "No files match the pattern",
|
|
58
|
+
shortResult: "No matches found",
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
// Get file modification time and sort
|
|
62
|
+
const filesWithStats = await Promise.allSettled(matches.map(async (file) => {
|
|
63
|
+
try {
|
|
64
|
+
const fullPath = resolvePath(file, context.workdir);
|
|
65
|
+
const stats = await stat(fullPath);
|
|
66
|
+
return {
|
|
67
|
+
path: file,
|
|
68
|
+
mtime: stats.mtime,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
// If unable to get file stats, use current time
|
|
73
|
+
return {
|
|
74
|
+
path: file,
|
|
75
|
+
mtime: new Date(),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}));
|
|
79
|
+
// Filter successful results and sort by modification time
|
|
80
|
+
const sortedFiles = filesWithStats
|
|
81
|
+
.filter((result) => result.status === "fulfilled")
|
|
82
|
+
.map((result) => result
|
|
83
|
+
.value)
|
|
84
|
+
.sort((a, b) => b.mtime.getTime() - a.mtime.getTime()) // Most recently modified files first
|
|
85
|
+
.map((item) => item.path);
|
|
86
|
+
// Format output
|
|
87
|
+
const output = sortedFiles
|
|
88
|
+
.map((file, index) => `${index + 1}. ${file}`)
|
|
89
|
+
.join("\n");
|
|
90
|
+
return {
|
|
91
|
+
success: true,
|
|
92
|
+
content: output,
|
|
93
|
+
shortResult: `Found ${sortedFiles.length} file${sortedFiles.length === 1 ? "" : "s"}`,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
return {
|
|
98
|
+
success: false,
|
|
99
|
+
content: "",
|
|
100
|
+
error: `Glob search failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
formatCompactParams: (params, context) => {
|
|
105
|
+
const pattern = params.pattern;
|
|
106
|
+
const path = params.path;
|
|
107
|
+
if (path) {
|
|
108
|
+
const displayPath = getDisplayPath(path, context.workdir);
|
|
109
|
+
return `${pattern} in ${displayPath}`;
|
|
110
|
+
}
|
|
111
|
+
return pattern || "";
|
|
112
|
+
},
|
|
113
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grepTool.d.ts","sourceRoot":"","sources":["../../src/tools/grepTool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAA2B,MAAM,YAAY,CAAC;AAMtE;;GAEG;AACH,eAAO,MAAM,QAAQ,EAAE,UA0QtB,CAAC"}
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import { spawn } from "child_process";
|
|
2
|
+
import { getGlobIgnorePatterns } from "../utils/fileFilter.js";
|
|
3
|
+
import { rgPath } from "@vscode/ripgrep";
|
|
4
|
+
import { getDisplayPath } from "../utils/path.js";
|
|
5
|
+
/**
|
|
6
|
+
* Grep tool plugin - powerful search tool based on ripgrep
|
|
7
|
+
*/
|
|
8
|
+
export const grepTool = {
|
|
9
|
+
name: "Grep",
|
|
10
|
+
config: {
|
|
11
|
+
type: "function",
|
|
12
|
+
function: {
|
|
13
|
+
name: "Grep",
|
|
14
|
+
description: 'A powerful search tool built on ripgrep\n\n Usage:\n - ALWAYS use Grep for search tasks. NEVER invoke `grep` or `rg` as a Bash command. The Grep tool has been optimized for correct permissions and access.\n - Supports full regex syntax (e.g., "log.*Error", "function\\s+\\w+")\n - Filter files with glob parameter (e.g., "*.js", "**/*.tsx") or type parameter (e.g., "js", "py", "rust")\n - Output modes: "content" shows matching lines, "files_with_matches" shows only file paths (default), "count" shows match counts\n - Use Task tool for open-ended searches requiring multiple rounds\n - Pattern syntax: Uses ripgrep (not grep) - literal braces need escaping (use `interface\\{\\}` to find `interface{}` in Go code)\n - Multiline matching: By default patterns match within single lines only. For cross-line patterns like `struct \\{[\\s\\S]*?field`, use `multiline: true`',
|
|
15
|
+
parameters: {
|
|
16
|
+
type: "object",
|
|
17
|
+
properties: {
|
|
18
|
+
pattern: {
|
|
19
|
+
type: "string",
|
|
20
|
+
description: "The regular expression pattern to search for in file contents",
|
|
21
|
+
},
|
|
22
|
+
path: {
|
|
23
|
+
type: "string",
|
|
24
|
+
description: "File or directory to search in (rg PATH). Defaults to current working directory.",
|
|
25
|
+
},
|
|
26
|
+
glob: {
|
|
27
|
+
type: "string",
|
|
28
|
+
description: 'Glob pattern to filter files (e.g. "*.js", "*.{ts,tsx}") - maps to rg --glob',
|
|
29
|
+
},
|
|
30
|
+
output_mode: {
|
|
31
|
+
type: "string",
|
|
32
|
+
enum: ["content", "files_with_matches", "count"],
|
|
33
|
+
description: 'Output mode: "content" shows matching lines (supports -A/-B/-C context, -n line numbers, head_limit), "files_with_matches" shows file paths (supports head_limit), "count" shows match counts (supports head_limit). Defaults to "files_with_matches".',
|
|
34
|
+
},
|
|
35
|
+
"-B": {
|
|
36
|
+
type: "number",
|
|
37
|
+
description: 'Number of lines to show before each match (rg -B). Requires output_mode: "content", ignored otherwise.',
|
|
38
|
+
},
|
|
39
|
+
"-A": {
|
|
40
|
+
type: "number",
|
|
41
|
+
description: 'Number of lines to show after each match (rg -A). Requires output_mode: "content", ignored otherwise.',
|
|
42
|
+
},
|
|
43
|
+
"-C": {
|
|
44
|
+
type: "number",
|
|
45
|
+
description: 'Number of lines to show before and after each match (rg -C). Requires output_mode: "content", ignored otherwise.',
|
|
46
|
+
},
|
|
47
|
+
"-n": {
|
|
48
|
+
type: "boolean",
|
|
49
|
+
description: 'Show line numbers in output (rg -n). Requires output_mode: "content", ignored otherwise.',
|
|
50
|
+
},
|
|
51
|
+
"-i": {
|
|
52
|
+
type: "boolean",
|
|
53
|
+
description: "Case insensitive search (rg -i)",
|
|
54
|
+
},
|
|
55
|
+
type: {
|
|
56
|
+
type: "string",
|
|
57
|
+
description: "File type to search (rg --type). Common types: js, py, rust, go, java, etc. More efficient than include for standard file types.",
|
|
58
|
+
},
|
|
59
|
+
head_limit: {
|
|
60
|
+
type: "number",
|
|
61
|
+
description: 'Limit output to first N lines/entries, equivalent to "| head -N". Works across all output modes: content (limits output lines), files_with_matches (limits file paths), count (limits count entries). When unspecified, shows all results from ripgrep.',
|
|
62
|
+
},
|
|
63
|
+
multiline: {
|
|
64
|
+
type: "boolean",
|
|
65
|
+
description: "Enable multiline mode where . matches newlines and patterns can span lines (rg -U --multiline-dotall). Default: false.",
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
required: ["pattern"],
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
execute: async (args, context) => {
|
|
73
|
+
const pattern = args.pattern;
|
|
74
|
+
const searchPath = args.path;
|
|
75
|
+
const globPattern = args.glob;
|
|
76
|
+
const outputMode = args.output_mode || "files_with_matches";
|
|
77
|
+
const contextBefore = args["-B"];
|
|
78
|
+
const contextAfter = args["-A"];
|
|
79
|
+
const contextAround = args["-C"];
|
|
80
|
+
const showLineNumbers = args["-n"];
|
|
81
|
+
const caseInsensitive = args["-i"];
|
|
82
|
+
const fileType = args.type;
|
|
83
|
+
const headLimit = args.head_limit;
|
|
84
|
+
const multiline = args.multiline;
|
|
85
|
+
if (!pattern || typeof pattern !== "string") {
|
|
86
|
+
return {
|
|
87
|
+
success: false,
|
|
88
|
+
content: "",
|
|
89
|
+
error: "pattern parameter is required and must be a string",
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
if (!rgPath) {
|
|
93
|
+
return {
|
|
94
|
+
success: false,
|
|
95
|
+
content: "",
|
|
96
|
+
error: "ripgrep is not available. Please install @vscode/ripgrep package.",
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
try {
|
|
100
|
+
const workdir = context.workdir;
|
|
101
|
+
const rgArgs = ["--color=never"];
|
|
102
|
+
// Set output mode
|
|
103
|
+
if (outputMode === "files_with_matches") {
|
|
104
|
+
rgArgs.push("-l");
|
|
105
|
+
}
|
|
106
|
+
else if (outputMode === "count") {
|
|
107
|
+
rgArgs.push("-c");
|
|
108
|
+
}
|
|
109
|
+
// content mode is default, no special parameters needed
|
|
110
|
+
// Add line numbers (only effective in content mode)
|
|
111
|
+
if (showLineNumbers && outputMode === "content") {
|
|
112
|
+
rgArgs.push("-n");
|
|
113
|
+
}
|
|
114
|
+
// Add file names (in content mode)
|
|
115
|
+
if (outputMode === "content") {
|
|
116
|
+
rgArgs.push("-H");
|
|
117
|
+
}
|
|
118
|
+
// Case insensitive
|
|
119
|
+
if (caseInsensitive) {
|
|
120
|
+
rgArgs.push("-i");
|
|
121
|
+
}
|
|
122
|
+
// Multiline mode
|
|
123
|
+
if (multiline) {
|
|
124
|
+
rgArgs.push("-U", "--multiline-dotall");
|
|
125
|
+
}
|
|
126
|
+
// Context lines (only effective in content mode)
|
|
127
|
+
if (outputMode === "content") {
|
|
128
|
+
if (contextAround) {
|
|
129
|
+
rgArgs.push("-C", contextAround.toString());
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
if (contextBefore) {
|
|
133
|
+
rgArgs.push("-B", contextBefore.toString());
|
|
134
|
+
}
|
|
135
|
+
if (contextAfter) {
|
|
136
|
+
rgArgs.push("-A", contextAfter.toString());
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
// File type filtering
|
|
141
|
+
if (fileType) {
|
|
142
|
+
rgArgs.push("--type", fileType);
|
|
143
|
+
}
|
|
144
|
+
// Glob pattern filtering
|
|
145
|
+
if (globPattern) {
|
|
146
|
+
rgArgs.push("--glob", globPattern);
|
|
147
|
+
}
|
|
148
|
+
// Get common ignore rules
|
|
149
|
+
const ignorePatterns = getGlobIgnorePatterns(workdir);
|
|
150
|
+
for (const exclude of ignorePatterns) {
|
|
151
|
+
rgArgs.push("--glob", `!${exclude}`);
|
|
152
|
+
}
|
|
153
|
+
// Add search pattern - use -e parameter to avoid patterns starting with - being mistaken as command line options
|
|
154
|
+
rgArgs.push("-e", pattern);
|
|
155
|
+
// Add search path
|
|
156
|
+
if (searchPath) {
|
|
157
|
+
rgArgs.push(searchPath);
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
rgArgs.push(".");
|
|
161
|
+
}
|
|
162
|
+
const result = await executeCommand(rgPath, rgArgs, workdir);
|
|
163
|
+
if (result.error && result.exitCode !== 1) {
|
|
164
|
+
// rg returns 1 for no matches, not an error
|
|
165
|
+
return {
|
|
166
|
+
success: false,
|
|
167
|
+
content: "",
|
|
168
|
+
error: `ripgrep failed: ${result.stderr}`,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
const output = result.stdout.trim();
|
|
172
|
+
if (!output) {
|
|
173
|
+
return {
|
|
174
|
+
success: true,
|
|
175
|
+
content: "No matches found",
|
|
176
|
+
shortResult: "No matches found",
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
// Apply head_limit
|
|
180
|
+
let finalOutput = output;
|
|
181
|
+
let lines = output.split("\n");
|
|
182
|
+
if (headLimit && headLimit > 0 && lines.length > headLimit) {
|
|
183
|
+
lines = lines.slice(0, headLimit);
|
|
184
|
+
finalOutput = lines.join("\n");
|
|
185
|
+
}
|
|
186
|
+
// Generate short result
|
|
187
|
+
let shortResult;
|
|
188
|
+
const totalLines = output.split("\n").length;
|
|
189
|
+
if (outputMode === "files_with_matches") {
|
|
190
|
+
shortResult = `Found ${totalLines} file${totalLines === 1 ? "" : "s"}`;
|
|
191
|
+
}
|
|
192
|
+
else if (outputMode === "count") {
|
|
193
|
+
shortResult = `Match counts for ${totalLines} file${totalLines === 1 ? "" : "s"}`;
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
shortResult = `Found ${totalLines} matching line${totalLines === 1 ? "" : "s"}`;
|
|
197
|
+
}
|
|
198
|
+
if (headLimit && totalLines > headLimit) {
|
|
199
|
+
shortResult += ` (showing first ${headLimit})`;
|
|
200
|
+
}
|
|
201
|
+
return {
|
|
202
|
+
success: true,
|
|
203
|
+
content: finalOutput,
|
|
204
|
+
shortResult,
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
catch (error) {
|
|
208
|
+
return {
|
|
209
|
+
success: false,
|
|
210
|
+
content: "",
|
|
211
|
+
error: `Search failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
},
|
|
215
|
+
formatCompactParams: (params, context) => {
|
|
216
|
+
const pattern = params.pattern;
|
|
217
|
+
const outputMode = params.output_mode;
|
|
218
|
+
const fileType = params.type;
|
|
219
|
+
const path = params.path;
|
|
220
|
+
let result = pattern || "";
|
|
221
|
+
if (fileType) {
|
|
222
|
+
result += ` ${fileType}`;
|
|
223
|
+
}
|
|
224
|
+
if (path) {
|
|
225
|
+
const displayPath = getDisplayPath(path, context.workdir);
|
|
226
|
+
result += ` in ${displayPath}`;
|
|
227
|
+
}
|
|
228
|
+
if (outputMode && outputMode !== "files_with_matches") {
|
|
229
|
+
result += ` [${outputMode}]`;
|
|
230
|
+
}
|
|
231
|
+
return result;
|
|
232
|
+
},
|
|
233
|
+
};
|
|
234
|
+
/**
|
|
235
|
+
* Execute command and return result
|
|
236
|
+
*/
|
|
237
|
+
function executeCommand(command, args, cwd) {
|
|
238
|
+
return new Promise((resolve) => {
|
|
239
|
+
const child = spawn(command, args, {
|
|
240
|
+
cwd,
|
|
241
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
242
|
+
});
|
|
243
|
+
let stdout = "";
|
|
244
|
+
let stderr = "";
|
|
245
|
+
child.stdout?.on("data", (data) => {
|
|
246
|
+
stdout += data.toString();
|
|
247
|
+
});
|
|
248
|
+
child.stderr?.on("data", (data) => {
|
|
249
|
+
stderr += data.toString();
|
|
250
|
+
});
|
|
251
|
+
child.on("close", (code) => {
|
|
252
|
+
resolve({
|
|
253
|
+
stdout,
|
|
254
|
+
stderr,
|
|
255
|
+
exitCode: code,
|
|
256
|
+
error: code !== 0 && code !== 1, // rg returns 1 for no matches, not an error
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
child.on("error", (err) => {
|
|
260
|
+
resolve({
|
|
261
|
+
stdout,
|
|
262
|
+
stderr: err.message,
|
|
263
|
+
exitCode: null,
|
|
264
|
+
error: true,
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lsTool.d.ts","sourceRoot":"","sources":["../../src/tools/lsTool.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAA2B,MAAM,YAAY,CAAC;AAGtE;;GAEG;AACH,eAAO,MAAM,MAAM,EAAE,UAiLpB,CAAC"}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import * as path from "path";
|
|
3
|
+
import { minimatch } from "minimatch";
|
|
4
|
+
import { isBinary, getDisplayPath } from "../utils/path.js";
|
|
5
|
+
/**
|
|
6
|
+
* LS Tool Plugin - List files and directories
|
|
7
|
+
*/
|
|
8
|
+
export const lsTool = {
|
|
9
|
+
name: "LS",
|
|
10
|
+
config: {
|
|
11
|
+
type: "function",
|
|
12
|
+
function: {
|
|
13
|
+
name: "LS",
|
|
14
|
+
description: "Lists files and directories in a given path. The path parameter must be an absolute path, not a relative path. You can optionally provide an array of glob patterns to ignore with the ignore parameter. You should generally prefer the Glob and Grep tools, if you know which directories to search.",
|
|
15
|
+
parameters: {
|
|
16
|
+
type: "object",
|
|
17
|
+
properties: {
|
|
18
|
+
path: {
|
|
19
|
+
type: "string",
|
|
20
|
+
description: "The absolute path to the directory to list (must be absolute, not relative)",
|
|
21
|
+
},
|
|
22
|
+
ignore: {
|
|
23
|
+
type: "array",
|
|
24
|
+
items: {
|
|
25
|
+
type: "string",
|
|
26
|
+
},
|
|
27
|
+
description: "List of glob patterns to ignore",
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
required: ["path"],
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
execute: async (args, context) => {
|
|
35
|
+
const targetPath = args.path;
|
|
36
|
+
const ignorePatterns = args.ignore;
|
|
37
|
+
// Note: context.workdir is not used as this tool requires absolute paths
|
|
38
|
+
void context.workdir;
|
|
39
|
+
if (!targetPath || typeof targetPath !== "string") {
|
|
40
|
+
return {
|
|
41
|
+
success: false,
|
|
42
|
+
content: "",
|
|
43
|
+
error: "path parameter is required and must be a string",
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
// Validate that the path is absolute
|
|
47
|
+
if (!path.isAbsolute(targetPath)) {
|
|
48
|
+
return {
|
|
49
|
+
success: false,
|
|
50
|
+
content: "",
|
|
51
|
+
error: "Path must be an absolute path, not a relative path",
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
try {
|
|
55
|
+
// Check if path exists and is a directory
|
|
56
|
+
const stats = await fs.promises.stat(targetPath);
|
|
57
|
+
if (!stats.isDirectory()) {
|
|
58
|
+
return {
|
|
59
|
+
success: false,
|
|
60
|
+
content: "",
|
|
61
|
+
error: `Path ${targetPath} is not a directory`,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
// Read directory contents
|
|
65
|
+
const entries = await fs.promises.readdir(targetPath, {
|
|
66
|
+
withFileTypes: true,
|
|
67
|
+
});
|
|
68
|
+
// Process directory items
|
|
69
|
+
const items = [];
|
|
70
|
+
for (const entry of entries) {
|
|
71
|
+
const entryPath = path.join(targetPath, entry.name);
|
|
72
|
+
// Check if it should be ignored
|
|
73
|
+
if (ignorePatterns && Array.isArray(ignorePatterns)) {
|
|
74
|
+
const shouldIgnore = ignorePatterns.some((pattern) => minimatch(entry.name, pattern) || minimatch(entryPath, pattern));
|
|
75
|
+
if (shouldIgnore) {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (entry.isDirectory()) {
|
|
80
|
+
items.push({
|
|
81
|
+
name: entry.name,
|
|
82
|
+
type: "directory",
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
else if (entry.isFile()) {
|
|
86
|
+
try {
|
|
87
|
+
const fileStats = await fs.promises.stat(entryPath);
|
|
88
|
+
items.push({
|
|
89
|
+
name: entry.name,
|
|
90
|
+
type: "file",
|
|
91
|
+
size: fileStats.size,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
// If file stats cannot be obtained, still add the file but do not display size
|
|
96
|
+
items.push({
|
|
97
|
+
name: entry.name,
|
|
98
|
+
type: "file",
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
else if (entry.isSymbolicLink()) {
|
|
103
|
+
items.push({
|
|
104
|
+
name: entry.name,
|
|
105
|
+
type: "symlink",
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
// Sort: directories first, then files, both alphabetically
|
|
110
|
+
items.sort((a, b) => {
|
|
111
|
+
if (a.type === "directory" && b.type !== "directory")
|
|
112
|
+
return -1;
|
|
113
|
+
if (a.type !== "directory" && b.type === "directory")
|
|
114
|
+
return 1;
|
|
115
|
+
return a.name.localeCompare(b.name);
|
|
116
|
+
});
|
|
117
|
+
let content = `Directory: ${targetPath}\n`;
|
|
118
|
+
content += `Total items: ${items.length}\n\n`;
|
|
119
|
+
for (const item of items) {
|
|
120
|
+
let typeIndicator;
|
|
121
|
+
switch (item.type) {
|
|
122
|
+
case "directory":
|
|
123
|
+
typeIndicator = "📁";
|
|
124
|
+
break;
|
|
125
|
+
case "symlink":
|
|
126
|
+
typeIndicator = "🔗";
|
|
127
|
+
break;
|
|
128
|
+
default:
|
|
129
|
+
typeIndicator = "📄";
|
|
130
|
+
}
|
|
131
|
+
const sizeInfo = item.size !== undefined ? ` (${item.size} bytes)` : "";
|
|
132
|
+
const binaryInfo = item.type === "file" && isBinary(item.name) ? " [binary]" : "";
|
|
133
|
+
content += `${typeIndicator} ${item.name}${sizeInfo}${binaryInfo}\n`;
|
|
134
|
+
}
|
|
135
|
+
return {
|
|
136
|
+
success: true,
|
|
137
|
+
content: content.trim(),
|
|
138
|
+
shortResult: `${items.length} items (${items.filter((i) => i.type === "directory").length} dirs, ${items.filter((i) => i.type === "file").length} files)`,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
return {
|
|
143
|
+
success: false,
|
|
144
|
+
content: "",
|
|
145
|
+
error: error instanceof Error ? error.message : String(error),
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
formatCompactParams: (params, context) => {
|
|
150
|
+
const targetPath = params.path;
|
|
151
|
+
const ignorePatterns = params.ignore;
|
|
152
|
+
let result = getDisplayPath(targetPath || "", context.workdir);
|
|
153
|
+
if (ignorePatterns &&
|
|
154
|
+
Array.isArray(ignorePatterns) &&
|
|
155
|
+
ignorePatterns.length > 0) {
|
|
156
|
+
result += ` ignore: ${ignorePatterns.join(", ")}`;
|
|
157
|
+
}
|
|
158
|
+
return result;
|
|
159
|
+
},
|
|
160
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multiEditTool.d.ts","sourceRoot":"","sources":["../../src/tools/multiEditTool.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAA2B,MAAM,YAAY,CAAC;AAwBtE;;GAEG;AACH,eAAO,MAAM,aAAa,EAAE,UAwO3B,CAAC"}
|