claude-ide-bridge 1.1.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/LICENSE +21 -0
- package/README.md +263 -0
- package/dist/activityLog.d.ts +26 -0
- package/dist/activityLog.js +76 -0
- package/dist/activityLog.js.map +1 -0
- package/dist/bridge.d.ts +19 -0
- package/dist/bridge.js +277 -0
- package/dist/bridge.js.map +1 -0
- package/dist/config.d.ts +22 -0
- package/dist/config.js +221 -0
- package/dist/config.js.map +1 -0
- package/dist/errors.d.ts +16 -0
- package/dist/errors.js +20 -0
- package/dist/errors.js.map +1 -0
- package/dist/extensionClient.d.ts +193 -0
- package/dist/extensionClient.js +698 -0
- package/dist/extensionClient.js.map +1 -0
- package/dist/fileLock.d.ts +12 -0
- package/dist/fileLock.js +30 -0
- package/dist/fileLock.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +38 -0
- package/dist/index.js.map +1 -0
- package/dist/lockfile.d.ts +12 -0
- package/dist/lockfile.js +127 -0
- package/dist/lockfile.js.map +1 -0
- package/dist/logger.d.ts +16 -0
- package/dist/logger.js +68 -0
- package/dist/logger.js.map +1 -0
- package/dist/probe.d.ts +22 -0
- package/dist/probe.js +45 -0
- package/dist/probe.js.map +1 -0
- package/dist/server.d.ts +25 -0
- package/dist/server.js +265 -0
- package/dist/server.js.map +1 -0
- package/dist/tools/activityLog.d.ts +39 -0
- package/dist/tools/activityLog.js +49 -0
- package/dist/tools/activityLog.js.map +1 -0
- package/dist/tools/aiComments.d.ts +26 -0
- package/dist/tools/aiComments.js +196 -0
- package/dist/tools/aiComments.js.map +1 -0
- package/dist/tools/bridgeStatus.d.ts +21 -0
- package/dist/tools/bridgeStatus.js +41 -0
- package/dist/tools/bridgeStatus.js.map +1 -0
- package/dist/tools/checkDocumentDirty.d.ts +28 -0
- package/dist/tools/checkDocumentDirty.js +61 -0
- package/dist/tools/checkDocumentDirty.js.map +1 -0
- package/dist/tools/clipboard.d.ts +50 -0
- package/dist/tools/clipboard.js +82 -0
- package/dist/tools/clipboard.js.map +1 -0
- package/dist/tools/closeTabs.d.ts +49 -0
- package/dist/tools/closeTabs.js +77 -0
- package/dist/tools/closeTabs.js.map +1 -0
- package/dist/tools/debug.d.ts +154 -0
- package/dist/tools/debug.js +248 -0
- package/dist/tools/debug.js.map +1 -0
- package/dist/tools/decorations.d.ts +92 -0
- package/dist/tools/decorations.js +150 -0
- package/dist/tools/decorations.js.map +1 -0
- package/dist/tools/diffDebugger.d.ts +62 -0
- package/dist/tools/diffDebugger.js +245 -0
- package/dist/tools/diffDebugger.js.map +1 -0
- package/dist/tools/editText.d.ts +80 -0
- package/dist/tools/editText.js +274 -0
- package/dist/tools/editText.js.map +1 -0
- package/dist/tools/fileOperations.d.ts +111 -0
- package/dist/tools/fileOperations.js +280 -0
- package/dist/tools/fileOperations.js.map +1 -0
- package/dist/tools/fileWatcher.d.ts +54 -0
- package/dist/tools/fileWatcher.js +100 -0
- package/dist/tools/fileWatcher.js.map +1 -0
- package/dist/tools/findFiles.d.ts +31 -0
- package/dist/tools/findFiles.js +119 -0
- package/dist/tools/findFiles.js.map +1 -0
- package/dist/tools/fixAllLintErrors.d.ts +29 -0
- package/dist/tools/fixAllLintErrors.js +114 -0
- package/dist/tools/fixAllLintErrors.js.map +1 -0
- package/dist/tools/flowGuardian.d.ts +61 -0
- package/dist/tools/flowGuardian.js +311 -0
- package/dist/tools/flowGuardian.js.map +1 -0
- package/dist/tools/formatDocument.d.ts +30 -0
- package/dist/tools/formatDocument.js +132 -0
- package/dist/tools/formatDocument.js.map +1 -0
- package/dist/tools/formatFile.d.ts +28 -0
- package/dist/tools/formatFile.js +110 -0
- package/dist/tools/formatFile.js.map +1 -0
- package/dist/tools/getBufferContent.d.ts +38 -0
- package/dist/tools/getBufferContent.js +100 -0
- package/dist/tools/getBufferContent.js.map +1 -0
- package/dist/tools/getCurrentSelection.d.ts +43 -0
- package/dist/tools/getCurrentSelection.js +75 -0
- package/dist/tools/getCurrentSelection.js.map +1 -0
- package/dist/tools/getDiagnostics.d.ts +38 -0
- package/dist/tools/getDiagnostics.js +204 -0
- package/dist/tools/getDiagnostics.js.map +1 -0
- package/dist/tools/getDocumentSymbols.d.ts +27 -0
- package/dist/tools/getDocumentSymbols.js +133 -0
- package/dist/tools/getDocumentSymbols.js.map +1 -0
- package/dist/tools/getFileTree.d.ts +36 -0
- package/dist/tools/getFileTree.js +111 -0
- package/dist/tools/getFileTree.js.map +1 -0
- package/dist/tools/getGitDiff.d.ts +34 -0
- package/dist/tools/getGitDiff.js +57 -0
- package/dist/tools/getGitDiff.js.map +1 -0
- package/dist/tools/getGitLog.d.ts +30 -0
- package/dist/tools/getGitLog.js +65 -0
- package/dist/tools/getGitLog.js.map +1 -0
- package/dist/tools/getGitStatus.d.ts +26 -0
- package/dist/tools/getGitStatus.js +95 -0
- package/dist/tools/getGitStatus.js.map +1 -0
- package/dist/tools/getOpenEditors.d.ts +21 -0
- package/dist/tools/getOpenEditors.js +84 -0
- package/dist/tools/getOpenEditors.js.map +1 -0
- package/dist/tools/getProjectInfo.d.ts +20 -0
- package/dist/tools/getProjectInfo.js +315 -0
- package/dist/tools/getProjectInfo.js.map +1 -0
- package/dist/tools/getToolCapabilities.d.ts +23 -0
- package/dist/tools/getToolCapabilities.js +249 -0
- package/dist/tools/getToolCapabilities.js.map +1 -0
- package/dist/tools/getWorkspaceFolders.d.ts +21 -0
- package/dist/tools/getWorkspaceFolders.js +47 -0
- package/dist/tools/getWorkspaceFolders.js.map +1 -0
- package/dist/tools/gitHistory.d.ts +78 -0
- package/dist/tools/gitHistory.js +151 -0
- package/dist/tools/gitHistory.js.map +1 -0
- package/dist/tools/gitWrite.d.ts +335 -0
- package/dist/tools/gitWrite.js +859 -0
- package/dist/tools/gitWrite.js.map +1 -0
- package/dist/tools/github/actions.d.ts +67 -0
- package/dist/tools/github/actions.js +155 -0
- package/dist/tools/github/actions.js.map +1 -0
- package/dist/tools/github/index.d.ts +4 -0
- package/dist/tools/github/index.js +5 -0
- package/dist/tools/github/index.js.map +1 -0
- package/dist/tools/github/issues.d.ts +140 -0
- package/dist/tools/github/issues.js +279 -0
- package/dist/tools/github/issues.js.map +1 -0
- package/dist/tools/github/pr.d.ts +101 -0
- package/dist/tools/github/pr.js +215 -0
- package/dist/tools/github/pr.js.map +1 -0
- package/dist/tools/github/review.d.ts +101 -0
- package/dist/tools/github/review.js +292 -0
- package/dist/tools/github/review.js.map +1 -0
- package/dist/tools/github/shared.d.ts +4 -0
- package/dist/tools/github/shared.js +12 -0
- package/dist/tools/github/shared.js.map +1 -0
- package/dist/tools/github.d.ts +308 -0
- package/dist/tools/github.js +656 -0
- package/dist/tools/github.js.map +1 -0
- package/dist/tools/hoverAtCursor.d.ts +22 -0
- package/dist/tools/hoverAtCursor.js +51 -0
- package/dist/tools/hoverAtCursor.js.map +1 -0
- package/dist/tools/httpClient.d.ts +83 -0
- package/dist/tools/httpClient.js +335 -0
- package/dist/tools/httpClient.js.map +1 -0
- package/dist/tools/index.d.ts +7 -0
- package/dist/tools/index.js +246 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/inlayHints.d.ts +38 -0
- package/dist/tools/inlayHints.js +56 -0
- package/dist/tools/inlayHints.js.map +1 -0
- package/dist/tools/linters/biome.d.ts +2 -0
- package/dist/tools/linters/biome.js +44 -0
- package/dist/tools/linters/biome.js.map +1 -0
- package/dist/tools/linters/cargo.d.ts +2 -0
- package/dist/tools/linters/cargo.js +45 -0
- package/dist/tools/linters/cargo.js.map +1 -0
- package/dist/tools/linters/eslint.d.ts +2 -0
- package/dist/tools/linters/eslint.js +59 -0
- package/dist/tools/linters/eslint.js.map +1 -0
- package/dist/tools/linters/govet.d.ts +2 -0
- package/dist/tools/linters/govet.js +37 -0
- package/dist/tools/linters/govet.js.map +1 -0
- package/dist/tools/linters/pyright.d.ts +2 -0
- package/dist/tools/linters/pyright.js +34 -0
- package/dist/tools/linters/pyright.js.map +1 -0
- package/dist/tools/linters/ruff.d.ts +2 -0
- package/dist/tools/linters/ruff.js +30 -0
- package/dist/tools/linters/ruff.js.map +1 -0
- package/dist/tools/linters/types.d.ts +16 -0
- package/dist/tools/linters/types.js +2 -0
- package/dist/tools/linters/types.js.map +1 -0
- package/dist/tools/linters/typescript.d.ts +2 -0
- package/dist/tools/linters/typescript.js +38 -0
- package/dist/tools/linters/typescript.js.map +1 -0
- package/dist/tools/lsp.d.ts +310 -0
- package/dist/tools/lsp.js +684 -0
- package/dist/tools/lsp.js.map +1 -0
- package/dist/tools/notebook.d.ts +95 -0
- package/dist/tools/notebook.js +144 -0
- package/dist/tools/notebook.js.map +1 -0
- package/dist/tools/openDiff.d.ts +41 -0
- package/dist/tools/openDiff.js +116 -0
- package/dist/tools/openDiff.js.map +1 -0
- package/dist/tools/openFile.d.ts +34 -0
- package/dist/tools/openFile.js +102 -0
- package/dist/tools/openFile.js.map +1 -0
- package/dist/tools/organizeImports.d.ts +29 -0
- package/dist/tools/organizeImports.js +64 -0
- package/dist/tools/organizeImports.js.map +1 -0
- package/dist/tools/planPersistence.d.ts +196 -0
- package/dist/tools/planPersistence.js +437 -0
- package/dist/tools/planPersistence.js.map +1 -0
- package/dist/tools/replaceBlock.d.ts +40 -0
- package/dist/tools/replaceBlock.js +105 -0
- package/dist/tools/replaceBlock.js.map +1 -0
- package/dist/tools/runCommand.d.ts +43 -0
- package/dist/tools/runCommand.js +141 -0
- package/dist/tools/runCommand.js.map +1 -0
- package/dist/tools/runTests.d.ts +32 -0
- package/dist/tools/runTests.js +160 -0
- package/dist/tools/runTests.js.map +1 -0
- package/dist/tools/saveDocument.d.ts +28 -0
- package/dist/tools/saveDocument.js +58 -0
- package/dist/tools/saveDocument.js.map +1 -0
- package/dist/tools/searchAndReplace.d.ts +50 -0
- package/dist/tools/searchAndReplace.js +203 -0
- package/dist/tools/searchAndReplace.js.map +1 -0
- package/dist/tools/searchWorkspace.d.ts +52 -0
- package/dist/tools/searchWorkspace.js +159 -0
- package/dist/tools/searchWorkspace.js.map +1 -0
- package/dist/tools/setActiveWorkspaceFolder.d.ts +28 -0
- package/dist/tools/setActiveWorkspaceFolder.js +32 -0
- package/dist/tools/setActiveWorkspaceFolder.js.map +1 -0
- package/dist/tools/tasks.d.ts +56 -0
- package/dist/tools/tasks.js +89 -0
- package/dist/tools/tasks.js.map +1 -0
- package/dist/tools/terminal.d.ts +241 -0
- package/dist/tools/terminal.js +539 -0
- package/dist/tools/terminal.js.map +1 -0
- package/dist/tools/testRunners/cargoTest.d.ts +2 -0
- package/dist/tools/testRunners/cargoTest.js +123 -0
- package/dist/tools/testRunners/cargoTest.js.map +1 -0
- package/dist/tools/testRunners/goTest.d.ts +2 -0
- package/dist/tools/testRunners/goTest.js +106 -0
- package/dist/tools/testRunners/goTest.js.map +1 -0
- package/dist/tools/testRunners/pytest.d.ts +2 -0
- package/dist/tools/testRunners/pytest.js +133 -0
- package/dist/tools/testRunners/pytest.js.map +1 -0
- package/dist/tools/testRunners/types.d.ts +18 -0
- package/dist/tools/testRunners/types.js +2 -0
- package/dist/tools/testRunners/types.js.map +1 -0
- package/dist/tools/testRunners/vitestJest.d.ts +3 -0
- package/dist/tools/testRunners/vitestJest.js +178 -0
- package/dist/tools/testRunners/vitestJest.js.map +1 -0
- package/dist/tools/typeHierarchy.d.ts +45 -0
- package/dist/tools/typeHierarchy.js +65 -0
- package/dist/tools/typeHierarchy.js.map +1 -0
- package/dist/tools/utils.d.ts +54 -0
- package/dist/tools/utils.js +267 -0
- package/dist/tools/utils.js.map +1 -0
- package/dist/tools/vscodeCommands.d.ts +59 -0
- package/dist/tools/vscodeCommands.js +108 -0
- package/dist/tools/vscodeCommands.js.map +1 -0
- package/dist/tools/watchDiagnostics.d.ts +32 -0
- package/dist/tools/watchDiagnostics.js +87 -0
- package/dist/tools/watchDiagnostics.js.map +1 -0
- package/dist/tools/workspaceSettings.d.ts +67 -0
- package/dist/tools/workspaceSettings.js +102 -0
- package/dist/tools/workspaceSettings.js.map +1 -0
- package/dist/tools/workspaceSnapshots.d.ts +174 -0
- package/dist/tools/workspaceSnapshots.js +474 -0
- package/dist/tools/workspaceSnapshots.js.map +1 -0
- package/dist/transport.d.ts +57 -0
- package/dist/transport.js +417 -0
- package/dist/transport.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +3 -0
- package/dist/version.js.map +1 -0
- package/dist/wsUtils.d.ts +9 -0
- package/dist/wsUtils.js +54 -0
- package/dist/wsUtils.js.map +1 -0
- package/package.json +69 -0
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { error, execSafe, optionalBool, optionalString, requireString, resolveFilePath, success, } from "./utils.js";
|
|
4
|
+
const MAX_FILES = 100;
|
|
5
|
+
const MAX_FILE_SIZE = 2 * 1024 * 1024; // 2MB per file
|
|
6
|
+
export function createSearchAndReplaceTool(workspace) {
|
|
7
|
+
return {
|
|
8
|
+
schema: {
|
|
9
|
+
name: "searchAndReplace",
|
|
10
|
+
description: "Find and replace text across all matching files in the workspace in a single operation. " +
|
|
11
|
+
"More efficient than calling searchWorkspace + replaceBlock/editText per file. " +
|
|
12
|
+
"Returns a summary of every file modified and the replacement count per file. " +
|
|
13
|
+
"For exact string replacement, set isRegex: false (default). " +
|
|
14
|
+
"For pattern-based replacement with capture groups, set isRegex: true. " +
|
|
15
|
+
"Always dry-runs first internally to confirm matches exist before writing.",
|
|
16
|
+
annotations: { destructiveHint: true },
|
|
17
|
+
inputSchema: {
|
|
18
|
+
type: "object",
|
|
19
|
+
properties: {
|
|
20
|
+
pattern: {
|
|
21
|
+
type: "string",
|
|
22
|
+
description: "Text or regex pattern to search for",
|
|
23
|
+
},
|
|
24
|
+
replacement: {
|
|
25
|
+
type: "string",
|
|
26
|
+
description: "Replacement text. For regex mode, supports $1, $2, etc. capture group references.",
|
|
27
|
+
},
|
|
28
|
+
glob: {
|
|
29
|
+
type: "string",
|
|
30
|
+
description: "File glob pattern to limit scope (e.g. '**/*.ts', 'src/**/*.py'). Omit to search all text files.",
|
|
31
|
+
},
|
|
32
|
+
isRegex: {
|
|
33
|
+
type: "boolean",
|
|
34
|
+
description: "Treat pattern as a JavaScript regex. Default: false (literal string match).",
|
|
35
|
+
},
|
|
36
|
+
caseSensitive: {
|
|
37
|
+
type: "boolean",
|
|
38
|
+
description: "Case-sensitive match. Default: true.",
|
|
39
|
+
},
|
|
40
|
+
dryRun: {
|
|
41
|
+
type: "boolean",
|
|
42
|
+
description: "If true, returns what would change without writing any files. Useful for previewing impact. Default: false.",
|
|
43
|
+
},
|
|
44
|
+
includeIgnored: {
|
|
45
|
+
type: "boolean",
|
|
46
|
+
description: "Search inside .gitignored files (e.g. node_modules, build output). Default: false.",
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
required: ["pattern", "replacement"],
|
|
50
|
+
additionalProperties: false,
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
handler: async (args) => {
|
|
54
|
+
const pattern = requireString(args, "pattern");
|
|
55
|
+
const replacement = requireString(args, "replacement", 65536);
|
|
56
|
+
const glob = optionalString(args, "glob");
|
|
57
|
+
const isRegex = optionalBool(args, "isRegex") ?? false;
|
|
58
|
+
const caseSensitive = optionalBool(args, "caseSensitive") ?? true;
|
|
59
|
+
const dryRun = optionalBool(args, "dryRun") ?? false;
|
|
60
|
+
const includeIgnored = optionalBool(args, "includeIgnored") ?? false;
|
|
61
|
+
if (pattern.length === 0) {
|
|
62
|
+
return error("pattern must not be empty");
|
|
63
|
+
}
|
|
64
|
+
// Compile regex once (used for both counting matches and replacement)
|
|
65
|
+
let regex = null;
|
|
66
|
+
if (isRegex) {
|
|
67
|
+
try {
|
|
68
|
+
regex = new RegExp(pattern, caseSensitive ? "gm" : "gim");
|
|
69
|
+
}
|
|
70
|
+
catch (e) {
|
|
71
|
+
return error(`Invalid regex pattern: ${e instanceof Error ? e.message : String(e)}`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
// Step 1: Find files containing the pattern via rg
|
|
75
|
+
const rgArgs = ["--files-with-matches", "-l"];
|
|
76
|
+
if (includeIgnored)
|
|
77
|
+
rgArgs.push("--no-ignore-vcs");
|
|
78
|
+
if (!caseSensitive)
|
|
79
|
+
rgArgs.push("-i");
|
|
80
|
+
if (isRegex) {
|
|
81
|
+
rgArgs.push("-e", pattern);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
rgArgs.push("-F", "-e", pattern);
|
|
85
|
+
}
|
|
86
|
+
if (glob) {
|
|
87
|
+
rgArgs.push("--glob", glob);
|
|
88
|
+
}
|
|
89
|
+
rgArgs.push(workspace);
|
|
90
|
+
const findResult = await execSafe("rg", rgArgs, {
|
|
91
|
+
cwd: workspace,
|
|
92
|
+
timeout: 15_000,
|
|
93
|
+
maxBuffer: 256 * 1024,
|
|
94
|
+
});
|
|
95
|
+
const matchedFiles = findResult.stdout
|
|
96
|
+
.split("\n")
|
|
97
|
+
.map((f) => f.trim())
|
|
98
|
+
.filter(Boolean);
|
|
99
|
+
if (matchedFiles.length === 0) {
|
|
100
|
+
return success({
|
|
101
|
+
matched: 0,
|
|
102
|
+
modified: 0,
|
|
103
|
+
dryRun,
|
|
104
|
+
files: [],
|
|
105
|
+
message: "No files contain the search pattern.",
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
if (matchedFiles.length > MAX_FILES) {
|
|
109
|
+
return error(`Pattern matches ${matchedFiles.length} files — exceeds safety limit of ${MAX_FILES}. Narrow the scope with the 'glob' parameter (e.g. 'src/**/*.ts') before proceeding.`);
|
|
110
|
+
}
|
|
111
|
+
// Step 2: For each file, read, replace, and optionally write
|
|
112
|
+
// Process files in parallel batches (bounded concurrency to avoid fd exhaustion)
|
|
113
|
+
const CONCURRENCY = 10;
|
|
114
|
+
const processFile = async (filePath) => {
|
|
115
|
+
// Safety: only operate within workspace
|
|
116
|
+
try {
|
|
117
|
+
resolveFilePath(filePath, workspace); // throws if outside workspace
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
const resolved = path.resolve(filePath);
|
|
123
|
+
let content;
|
|
124
|
+
try {
|
|
125
|
+
const stat = await fs.promises.stat(resolved);
|
|
126
|
+
if (stat.size > MAX_FILE_SIZE) {
|
|
127
|
+
return {
|
|
128
|
+
file: filePath,
|
|
129
|
+
replacements: "skipped (file too large)",
|
|
130
|
+
written: false,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
content = await fs.promises.readFile(resolved, "utf-8");
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
let newContent;
|
|
139
|
+
let count = 0;
|
|
140
|
+
if (regex) {
|
|
141
|
+
regex.lastIndex = 0;
|
|
142
|
+
const matches = content.match(regex);
|
|
143
|
+
count = matches ? matches.length : 0;
|
|
144
|
+
newContent = content.replace(regex, replacement);
|
|
145
|
+
regex.lastIndex = 0;
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
const parts = content.split(pattern);
|
|
149
|
+
count = parts.length - 1;
|
|
150
|
+
newContent = parts.join(replacement);
|
|
151
|
+
}
|
|
152
|
+
if (count === 0)
|
|
153
|
+
return null;
|
|
154
|
+
if (!dryRun) {
|
|
155
|
+
try {
|
|
156
|
+
await fs.promises.writeFile(resolved, newContent, "utf-8");
|
|
157
|
+
return { file: filePath, replacements: count, written: true };
|
|
158
|
+
}
|
|
159
|
+
catch (err) {
|
|
160
|
+
return {
|
|
161
|
+
file: filePath,
|
|
162
|
+
replacements: count,
|
|
163
|
+
written: false,
|
|
164
|
+
writeError: err instanceof Error ? err.message : String(err),
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return { file: filePath, replacements: count, written: false };
|
|
169
|
+
};
|
|
170
|
+
const results = [];
|
|
171
|
+
for (let i = 0; i < matchedFiles.length; i += CONCURRENCY) {
|
|
172
|
+
const batch = matchedFiles.slice(i, i + CONCURRENCY);
|
|
173
|
+
const batchResults = await Promise.all(batch.map(processFile));
|
|
174
|
+
for (const r of batchResults) {
|
|
175
|
+
if (r !== null)
|
|
176
|
+
results.push(r);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
const totalReplacements = results.reduce((sum, r) => sum + (typeof r.replacements === "number" ? r.replacements : 0), 0);
|
|
180
|
+
const writtenCount = results.filter((r) => r.written).length;
|
|
181
|
+
const failedCount = results.filter((r) => !dryRun &&
|
|
182
|
+
!r.written &&
|
|
183
|
+
typeof r.replacements === "number" &&
|
|
184
|
+
r.replacements > 0).length;
|
|
185
|
+
return success({
|
|
186
|
+
matched: matchedFiles.length,
|
|
187
|
+
modified: writtenCount,
|
|
188
|
+
totalReplacements,
|
|
189
|
+
dryRun,
|
|
190
|
+
...(failedCount > 0 && {
|
|
191
|
+
warning: `${writtenCount} file(s) written, ${failedCount} file(s) failed to write — check per-file results`,
|
|
192
|
+
}),
|
|
193
|
+
files: results.map((r) => ({
|
|
194
|
+
file: r.file,
|
|
195
|
+
replacements: r.replacements,
|
|
196
|
+
...(dryRun ? {} : { written: r.written }),
|
|
197
|
+
...(r.writeError && { writeError: r.writeError }),
|
|
198
|
+
})),
|
|
199
|
+
});
|
|
200
|
+
},
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
//# sourceMappingURL=searchAndReplace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"searchAndReplace.js","sourceRoot":"","sources":["../../src/tools/searchAndReplace.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EACL,KAAK,EACL,QAAQ,EACR,YAAY,EACZ,cAAc,EACd,aAAa,EACb,eAAe,EACf,OAAO,GACR,MAAM,YAAY,CAAC;AAEpB,MAAM,SAAS,GAAG,GAAG,CAAC;AACtB,MAAM,aAAa,GAAG,CAAC,GAAG,IA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} from "../transport.js";
|
|
3
|
+
export declare function createSearchWorkspaceTool(workspace: string, probes: ProbeResults): {
|
|
4
|
+
schema: {
|
|
5
|
+
name: string;
|
|
6
|
+
description: string;
|
|
7
|
+
annotations: {
|
|
8
|
+
readOnlyHint: boolean;
|
|
9
|
+
};
|
|
10
|
+
inputSchema: {
|
|
11
|
+
type: "object";
|
|
12
|
+
properties: {
|
|
13
|
+
query: {
|
|
14
|
+
type: string;
|
|
15
|
+
description: string;
|
|
16
|
+
};
|
|
17
|
+
fileGlob: {
|
|
18
|
+
type: string;
|
|
19
|
+
description: string;
|
|
20
|
+
};
|
|
21
|
+
isRegex: {
|
|
22
|
+
type: string;
|
|
23
|
+
description: string;
|
|
24
|
+
};
|
|
25
|
+
caseSensitive: {
|
|
26
|
+
type: string;
|
|
27
|
+
description: string;
|
|
28
|
+
};
|
|
29
|
+
maxResults: {
|
|
30
|
+
type: string;
|
|
31
|
+
description: string;
|
|
32
|
+
minimum: number;
|
|
33
|
+
maximum: number;
|
|
34
|
+
};
|
|
35
|
+
contextLines: {
|
|
36
|
+
type: string;
|
|
37
|
+
description: string;
|
|
38
|
+
minimum: number;
|
|
39
|
+
maximum: number;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
required: string[];
|
|
43
|
+
additionalProperties: false;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
handler: (args: Record<string, unknown>, signal?: AbortSignal, progress?: ProgressFn) => Promise<{
|
|
47
|
+
content: Array<{
|
|
48
|
+
type: string;
|
|
49
|
+
text: string;
|
|
50
|
+
}>;
|
|
51
|
+
}>;
|
|
52
|
+
};
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { error, execSafe, makeRelative, optionalBool, optionalInt, optionalString, requireString, success, } from "./utils.js";
|
|
2
|
+
export function createSearchWorkspaceTool(workspace, probes) {
|
|
3
|
+
return {
|
|
4
|
+
schema: {
|
|
5
|
+
name: "searchWorkspace",
|
|
6
|
+
description: "Search for text patterns in workspace files using ripgrep (or grep fallback). Returns matching lines with file paths and line numbers.",
|
|
7
|
+
annotations: { readOnlyHint: true },
|
|
8
|
+
inputSchema: {
|
|
9
|
+
type: "object",
|
|
10
|
+
properties: {
|
|
11
|
+
query: {
|
|
12
|
+
type: "string",
|
|
13
|
+
description: "Search pattern (text or regex)",
|
|
14
|
+
},
|
|
15
|
+
fileGlob: {
|
|
16
|
+
type: "string",
|
|
17
|
+
description: "Optional glob to filter files (e.g. '*.ts')",
|
|
18
|
+
},
|
|
19
|
+
isRegex: {
|
|
20
|
+
type: "boolean",
|
|
21
|
+
description: "Treat query as regex (default: false)",
|
|
22
|
+
},
|
|
23
|
+
caseSensitive: {
|
|
24
|
+
type: "boolean",
|
|
25
|
+
description: "Case-sensitive search (default: true)",
|
|
26
|
+
},
|
|
27
|
+
maxResults: {
|
|
28
|
+
type: "integer",
|
|
29
|
+
description: "Max results to return (default: 100, max: 200)",
|
|
30
|
+
minimum: 1,
|
|
31
|
+
maximum: 200,
|
|
32
|
+
},
|
|
33
|
+
contextLines: {
|
|
34
|
+
type: "integer",
|
|
35
|
+
description: "Lines of context around matches (default: 0, max: 5)",
|
|
36
|
+
minimum: 0,
|
|
37
|
+
maximum: 5,
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
required: ["query"],
|
|
41
|
+
additionalProperties: false,
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
handler: async (args, signal, progress) => {
|
|
45
|
+
progress?.(0, 100);
|
|
46
|
+
const query = requireString(args, "query", 500);
|
|
47
|
+
if (query.trim().length === 0)
|
|
48
|
+
throw new Error("query must not be empty");
|
|
49
|
+
const fileGlob = optionalString(args, "fileGlob", 200);
|
|
50
|
+
const isRegex = optionalBool(args, "isRegex") ?? false;
|
|
51
|
+
const caseSensitive = optionalBool(args, "caseSensitive") ?? true;
|
|
52
|
+
const maxResults = optionalInt(args, "maxResults", 1, 200) ?? 100;
|
|
53
|
+
const contextLines = optionalInt(args, "contextLines", 0, 5) ?? 0;
|
|
54
|
+
// Reject patterns with nested quantifiers — these cause catastrophic backtracking (ReDoS)
|
|
55
|
+
if (isRegex) {
|
|
56
|
+
if (/\([^)]*[+*]\)[+*?]/.test(query) ||
|
|
57
|
+
/\([^)]*\{[^}]+\}\)[+*{?]/.test(query) ||
|
|
58
|
+
/[+*][+*]|\{[^}]+\}[+*]/.test(query)) {
|
|
59
|
+
return error("Pattern contains nested quantifiers (e.g. (a+)+) which can cause catastrophic backtracking (ReDoS). " +
|
|
60
|
+
"Simplify the regex — use a literal string match or a non-nested quantifier.");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (probes.rg) {
|
|
64
|
+
// Use ripgrep
|
|
65
|
+
const rgArgs = ["--json", "--max-count", String(maxResults)];
|
|
66
|
+
if (fileGlob)
|
|
67
|
+
rgArgs.push("--glob", fileGlob);
|
|
68
|
+
if (!caseSensitive)
|
|
69
|
+
rgArgs.push("-i");
|
|
70
|
+
if (!isRegex)
|
|
71
|
+
rgArgs.push("--fixed-strings");
|
|
72
|
+
if (contextLines > 0)
|
|
73
|
+
rgArgs.push("-C", String(contextLines));
|
|
74
|
+
rgArgs.push("--", query, workspace);
|
|
75
|
+
const result = await execSafe("rg", rgArgs, {
|
|
76
|
+
timeout: 15000,
|
|
77
|
+
maxBuffer: 1024 * 1024,
|
|
78
|
+
signal,
|
|
79
|
+
});
|
|
80
|
+
// Parse ripgrep JSON output
|
|
81
|
+
const matches = [];
|
|
82
|
+
for (const line of result.stdout.split("\n")) {
|
|
83
|
+
if (!line.trim())
|
|
84
|
+
continue;
|
|
85
|
+
try {
|
|
86
|
+
const entry = JSON.parse(line);
|
|
87
|
+
if (entry.type === "match") {
|
|
88
|
+
const d = entry.data;
|
|
89
|
+
const filePath = d.path?.text ?? "";
|
|
90
|
+
matches.push({
|
|
91
|
+
file: makeRelative(filePath, workspace),
|
|
92
|
+
line: d.line_number,
|
|
93
|
+
column: d.submatches?.[0]?.start ?? 0,
|
|
94
|
+
matchText: d.lines?.text?.trimEnd() ?? "",
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
/* skip unparseable lines */
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const truncated = matches.length >= maxResults;
|
|
103
|
+
return success({
|
|
104
|
+
matches,
|
|
105
|
+
totalMatches: matches.length,
|
|
106
|
+
tool: "rg",
|
|
107
|
+
...(truncated && {
|
|
108
|
+
truncated: true,
|
|
109
|
+
note: "Result limit reached — increase maxResults or narrow your query",
|
|
110
|
+
}),
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
// Fallback to grep
|
|
114
|
+
const grepArgs = ["-rn"];
|
|
115
|
+
if (fileGlob)
|
|
116
|
+
grepArgs.push("--include", fileGlob);
|
|
117
|
+
if (!caseSensitive)
|
|
118
|
+
grepArgs.push("-i");
|
|
119
|
+
if (!isRegex)
|
|
120
|
+
grepArgs.push("-F");
|
|
121
|
+
else
|
|
122
|
+
grepArgs.push("-E");
|
|
123
|
+
if (contextLines > 0)
|
|
124
|
+
grepArgs.push(`-C${contextLines}`);
|
|
125
|
+
grepArgs.push("--", query, workspace);
|
|
126
|
+
const result = await execSafe("grep", grepArgs, {
|
|
127
|
+
timeout: 15000,
|
|
128
|
+
maxBuffer: 1024 * 1024,
|
|
129
|
+
signal,
|
|
130
|
+
});
|
|
131
|
+
const matches = [];
|
|
132
|
+
for (const line of result.stdout.split("\n")) {
|
|
133
|
+
const match = line.match(/^(.+?):(\d+):(.*)$/);
|
|
134
|
+
if (match) {
|
|
135
|
+
const filePath = match[1] ?? "";
|
|
136
|
+
matches.push({
|
|
137
|
+
file: makeRelative(filePath, workspace),
|
|
138
|
+
line: Number.parseInt(match[2] ?? "0", 10),
|
|
139
|
+
matchText: match[3]?.trimEnd() ?? "",
|
|
140
|
+
});
|
|
141
|
+
if (matches.length >= maxResults)
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
const truncated = matches.length >= maxResults;
|
|
146
|
+
progress?.(100, 100);
|
|
147
|
+
return success({
|
|
148
|
+
matches,
|
|
149
|
+
totalMatches: matches.length,
|
|
150
|
+
tool: "grep",
|
|
151
|
+
...(truncated && {
|
|
152
|
+
truncated: true,
|
|
153
|
+
note: "Result limit reached — increase maxResults or narrow your query",
|
|
154
|
+
}),
|
|
155
|
+
});
|
|
156
|
+
},
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
//# sourceMappingURL=searchWorkspace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"searchWorkspace.js","sourceRoot":"","sources":["../../src/tools/searchWorkspace.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,EACL,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,cAAc,EACd,aAAa,EACb,OAAO,GACR,MAAM,YAAY,CAAC;AAEpB,MAAM,UAAU,yBAAyB,CACvC,SAAiB,EACjB,MAAoB;IAEpB,OAAO;QACL,MAAM,EAAE;YACN,IAAI,EAAE,iBAAiB;YACvB,WAAW,EACT,wIAAwI;YAC1I,WAAW,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE;YACnC,WAAW,EAAE;gBACX,IAAI,EAAE,QAAiB;gBACvB,UAAU,EAAE;oBACV,KAAK,EAAE;wBACL,IAAI,EAAE,QAAQ;wBACd,WAAW,EAAE,gCAAgC;qBAC9C;oBACD,QAAQ,EAAE;wBACR,IAAI,EAAE,QAAQ;wBACd,WAAW,EAAE,6CAA6C;qBAC3D;oBACD,OAAO,EAAE;wBACP,IAAI,EAAE,SAAS;wBACf,WAAW,EAAE,uCAAuC;qBACrD;oBACD,aAAa,EAAE;wBACb,IAAI,EAAE,SAAS;wBACf,WAAW,EAAE,uCAAuC;qBACrD;oBACD,UAAU,EAAE;wBACV,IAAI,EAAE,SAAS;wBACf,WAAW,EAAE,gDAAgD;wBAC7D,OAAO,EAAE,CAAC;wBACV,OAAO,EAAE,GAAG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Config): {
|
|
3
|
+
schema: {
|
|
4
|
+
name: string;
|
|
5
|
+
description: string;
|
|
6
|
+
annotations: {
|
|
7
|
+
idempotentHint: boolean;
|
|
8
|
+
};
|
|
9
|
+
inputSchema: {
|
|
10
|
+
$schema: string;
|
|
11
|
+
type: "object";
|
|
12
|
+
required: string[];
|
|
13
|
+
properties: {
|
|
14
|
+
path: {
|
|
15
|
+
type: "string";
|
|
16
|
+
description: string;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
additionalProperties: false;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
handler(args: Record<string, unknown>): Promise<{
|
|
23
|
+
content: Array<{
|
|
24
|
+
type: string;
|
|
25
|
+
text: string;
|
|
26
|
+
}>;
|
|
27
|
+
}>;
|
|
28
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { requireString, success } from "./utils.js";
|
|
3
|
+
export function createSetActiveWorkspaceFolderTool(config) {
|
|
4
|
+
return {
|
|
5
|
+
schema: {
|
|
6
|
+
name: "setActiveWorkspaceFolder",
|
|
7
|
+
description: "Set the active workspace folder for subsequent file operations. " +
|
|
8
|
+
"Useful in multi-root workspaces to scope Claude's work to a specific folder. " +
|
|
9
|
+
"Pass a path matching one of the workspace folders from getWorkspaceFolders.",
|
|
10
|
+
annotations: { idempotentHint: true },
|
|
11
|
+
inputSchema: {
|
|
12
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
13
|
+
type: "object",
|
|
14
|
+
required: ["path"],
|
|
15
|
+
properties: {
|
|
16
|
+
path: {
|
|
17
|
+
type: "string",
|
|
18
|
+
description: "Absolute path to the workspace folder to activate",
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
additionalProperties: false,
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
async handler(args) {
|
|
25
|
+
const folderPath = requireString(args, "path");
|
|
26
|
+
const resolved = path.resolve(folderPath);
|
|
27
|
+
config.activeWorkspaceFolder = resolved;
|
|
28
|
+
return success({ set: true, activeWorkspaceFolder: resolved });
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=setActiveWorkspaceFolder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setActiveWorkspaceFolder.js","sourceRoot":"","sources":["../../src/tools/setActiveWorkspaceFolder.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAEpD,MAAM,UAAU,kCAAkC,CAAC,MAAc;IAC/D,OAAO;QACL,MAAM,EAAE;YACN,IAAI,EAAE,0BAA0B;YAChC,WAAW,EACT,kEAAkE;gBAClE,+EAA+E;gBAC/E,6EAA6E;YAC/E,WAAW,EAAE,EAAE,cAAc,EAAE,IAAI,EAAE;YACrC,WAAW,EAAE;gBACX,OAAO,EAAE,yCAAyC;gBAClD,IAAI,EAAE,QAAiB;gBACvB,QAAQ,EAAE,CAAC,MAAM,CAAC;gBAClB,UAAU,EAAE;oBACV,IAAI,EAAE;wBACJ,IAAI,EAAE,QAAiB;wBACvB,WAAW,EAAE,mDAAmD;qBACjE;iBACF;gBACD,oBAAoB,EAAE,KAAc;aACrC;SACF;QACD,KAAK,CAAC,OAAO,CAAC,IAA6B;YACzC,MAAM,UAAU,GAAG,aAAa,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;YAC/C,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;YAC1C,MAAM,CAAC,qBAAqB,GAAG,QAAQ,CAAC;YACxC,OAAO,OAAO,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,qBAAqB,EAAE,QAAQ,EAAE,CAAC,CAAC;QACjE,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { type ExtensionClient } from "../extensionClient.js";
|
|
2
|
+
export declare function createListTasksTool(extensionClient: ExtensionClient): {
|
|
3
|
+
schema: {
|
|
4
|
+
name: string;
|
|
5
|
+
extensionRequired: boolean;
|
|
6
|
+
description: string;
|
|
7
|
+
annotations: {
|
|
8
|
+
readOnlyHint: boolean;
|
|
9
|
+
};
|
|
10
|
+
inputSchema: {
|
|
11
|
+
$schema: string;
|
|
12
|
+
type: "object";
|
|
13
|
+
additionalProperties: false;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
handler(): Promise<{
|
|
17
|
+
content: Array<{
|
|
18
|
+
type: string;
|
|
19
|
+
text: string;
|
|
20
|
+
}>;
|
|
21
|
+
}>;
|
|
22
|
+
};
|
|
23
|
+
export declare function createRunTaskTool(extensionClient: ExtensionClient): {
|
|
24
|
+
schema: {
|
|
25
|
+
name: string;
|
|
26
|
+
extensionRequired: boolean;
|
|
27
|
+
description: string;
|
|
28
|
+
inputSchema: {
|
|
29
|
+
$schema: string;
|
|
30
|
+
type: "object";
|
|
31
|
+
required: string[];
|
|
32
|
+
properties: {
|
|
33
|
+
name: {
|
|
34
|
+
type: "string";
|
|
35
|
+
description: string;
|
|
36
|
+
};
|
|
37
|
+
type: {
|
|
38
|
+
type: "string";
|
|
39
|
+
description: string;
|
|
40
|
+
};
|
|
41
|
+
timeoutMs: {
|
|
42
|
+
type: "integer";
|
|
43
|
+
description: string;
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
additionalProperties: false;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
timeoutMs: number;
|
|
50
|
+
handler(args: Record<string, unknown>): Promise<{
|
|
51
|
+
content: Array<{
|
|
52
|
+
type: string;
|
|
53
|
+
text: string;
|
|
54
|
+
}>;
|
|
55
|
+
}>;
|
|
56
|
+
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { ExtensionTimeoutError, } from "../extensionClient.js";
|
|
2
|
+
import { error, extensionRequired, optionalInt, optionalString, requireString, success, } from "./utils.js";
|
|
3
|
+
export function createListTasksTool(extensionClient) {
|
|
4
|
+
return {
|
|
5
|
+
schema: {
|
|
6
|
+
name: "listTasks",
|
|
7
|
+
extensionRequired: true,
|
|
8
|
+
description: "List all VS Code tasks defined in .vscode/tasks.json and contributed by extensions. " +
|
|
9
|
+
"Returns task names, types, and groups. Use runTask to execute one. " +
|
|
10
|
+
"Requires the VS Code extension.",
|
|
11
|
+
annotations: { readOnlyHint: true },
|
|
12
|
+
inputSchema: {
|
|
13
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
14
|
+
type: "object",
|
|
15
|
+
additionalProperties: false,
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
async handler() {
|
|
19
|
+
if (!extensionClient.isConnected()) {
|
|
20
|
+
return extensionRequired("listTasks");
|
|
21
|
+
}
|
|
22
|
+
try {
|
|
23
|
+
const result = await extensionClient.listTasks();
|
|
24
|
+
if (result === null)
|
|
25
|
+
return error("Failed to list tasks");
|
|
26
|
+
return success(result);
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
if (err instanceof ExtensionTimeoutError) {
|
|
30
|
+
return error("Extension timed out listing tasks");
|
|
31
|
+
}
|
|
32
|
+
throw err;
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
export function createRunTaskTool(extensionClient) {
|
|
38
|
+
return {
|
|
39
|
+
schema: {
|
|
40
|
+
name: "runTask",
|
|
41
|
+
extensionRequired: true,
|
|
42
|
+
description: "Run a VS Code task by name and wait for it to complete. " +
|
|
43
|
+
"Returns the exit code and duration. Use listTasks to discover available tasks. " +
|
|
44
|
+
"Requires the VS Code extension.",
|
|
45
|
+
inputSchema: {
|
|
46
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
47
|
+
type: "object",
|
|
48
|
+
required: ["name"],
|
|
49
|
+
properties: {
|
|
50
|
+
name: {
|
|
51
|
+
type: "string",
|
|
52
|
+
description: "Task name (from listTasks)",
|
|
53
|
+
},
|
|
54
|
+
type: {
|
|
55
|
+
type: "string",
|
|
56
|
+
description: "Task type to disambiguate if multiple tasks share a name",
|
|
57
|
+
},
|
|
58
|
+
timeoutMs: {
|
|
59
|
+
type: "integer",
|
|
60
|
+
description: "Max wait time in ms (default: 60000, max: 300000)",
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
additionalProperties: false,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
timeoutMs: 300_000,
|
|
67
|
+
async handler(args) {
|
|
68
|
+
if (!extensionClient.isConnected()) {
|
|
69
|
+
return extensionRequired("runTask");
|
|
70
|
+
}
|
|
71
|
+
const name = requireString(args, "name", 256);
|
|
72
|
+
const type = optionalString(args, "type", 128);
|
|
73
|
+
const timeoutMs = Math.min(optionalInt(args, "timeoutMs", 1000, 300_000) ?? 60_000, 300_000);
|
|
74
|
+
try {
|
|
75
|
+
const result = await extensionClient.runTask(name, type, timeoutMs);
|
|
76
|
+
if (result === null)
|
|
77
|
+
return error(`Task "${name}" not found or failed to start`);
|
|
78
|
+
return success(result);
|
|
79
|
+
}
|
|
80
|
+
catch (err) {
|
|
81
|
+
if (err instanceof ExtensionTimeoutError) {
|
|
82
|
+
return error(`Extension timed out running task "${name}"`);
|
|
83
|
+
}
|
|
84
|
+
throw err;
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=tasks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tasks.js","sourceRoot":"","sources":["../../src/tools/tasks.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,qBAAqB,GACtB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,KAAK,EACL,iBAAiB,EACjB,WAAW,EACX,cAAc,EACd,aAAa,EACb,OAAO,GACR,MAAM,YAAY,CAAC;AAEpB,MAAM,UAAU,mBAAmB,CAAC,eAAgC;IAClE,OAAO;Q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