@travisennis/acai 0.0.5 → 0.0.6
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 +4 -2
- package/dist/agent/index.d.ts +119 -0
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent/index.js +406 -0
- package/dist/agent/manual-loop.d.ts +41 -0
- package/dist/agent/manual-loop.d.ts.map +1 -0
- package/dist/agent/manual-loop.js +278 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +27 -33
- package/dist/commands/add-directory-command.d.ts +3 -0
- package/dist/commands/add-directory-command.d.ts.map +1 -0
- package/dist/commands/add-directory-command.js +85 -0
- package/dist/commands/application-log-command.d.ts.map +1 -1
- package/dist/commands/application-log-command.js +34 -0
- package/dist/commands/clear-command.d.ts.map +1 -1
- package/dist/commands/clear-command.js +8 -0
- package/dist/commands/compact-command.d.ts.map +1 -1
- package/dist/commands/compact-command.js +15 -2
- package/dist/commands/context-command.d.ts +3 -0
- package/dist/commands/context-command.d.ts.map +1 -0
- package/dist/commands/context-command.js +183 -0
- package/dist/commands/copy-command.d.ts.map +1 -1
- package/dist/commands/copy-command.js +28 -0
- package/dist/commands/edit-command.d.ts.map +1 -1
- package/dist/commands/edit-command.js +33 -0
- package/dist/commands/edit-prompt-command.d.ts.map +1 -1
- package/dist/commands/edit-prompt-command.js +28 -0
- package/dist/commands/exit-command.d.ts.map +1 -1
- package/dist/commands/exit-command.js +20 -0
- package/dist/commands/files-command.d.ts.map +1 -1
- package/dist/commands/files-command.js +57 -0
- package/dist/commands/generate-rules-command.d.ts.map +1 -1
- package/dist/commands/generate-rules-command.js +311 -1
- package/dist/commands/handoff-command.d.ts +3 -0
- package/dist/commands/handoff-command.d.ts.map +1 -0
- package/dist/commands/handoff-command.js +202 -0
- package/dist/commands/health-command.d.ts.map +1 -1
- package/dist/commands/health-command.js +119 -2
- package/dist/commands/help-command.d.ts.map +1 -1
- package/dist/commands/help-command.js +28 -0
- package/dist/commands/history-command.d.ts +3 -0
- package/dist/commands/history-command.d.ts.map +1 -0
- package/dist/commands/history-command.js +534 -0
- package/dist/commands/init-command.d.ts +1 -1
- package/dist/commands/init-command.d.ts.map +1 -1
- package/dist/commands/init-command.js +55 -18
- package/dist/commands/last-log-command.d.ts.map +1 -1
- package/dist/commands/last-log-command.js +27 -0
- package/dist/commands/list-directories-command.d.ts +3 -0
- package/dist/commands/list-directories-command.d.ts.map +1 -0
- package/dist/commands/list-directories-command.js +48 -0
- package/dist/commands/list-tools-command.d.ts.map +1 -1
- package/dist/commands/list-tools-command.js +66 -3
- package/dist/commands/manager.d.ts +15 -3
- package/dist/commands/manager.d.ts.map +1 -1
- package/dist/commands/manager.js +86 -26
- package/dist/commands/model-command.d.ts +22 -0
- package/dist/commands/model-command.d.ts.map +1 -1
- package/dist/commands/model-command.js +256 -0
- package/dist/commands/paste-command.d.ts.map +1 -1
- package/dist/commands/paste-command.js +92 -0
- package/dist/commands/pickup-command.d.ts +3 -0
- package/dist/commands/pickup-command.d.ts.map +1 -0
- package/dist/commands/pickup-command.js +161 -0
- package/dist/commands/prompt-command.d.ts +1 -1
- package/dist/commands/prompt-command.d.ts.map +1 -1
- package/dist/commands/prompt-command.js +117 -2
- package/dist/commands/remove-directory-command.d.ts +3 -0
- package/dist/commands/remove-directory-command.d.ts.map +1 -0
- package/dist/commands/remove-directory-command.js +87 -0
- package/dist/commands/reset-command.d.ts +1 -1
- package/dist/commands/reset-command.d.ts.map +1 -1
- package/dist/commands/reset-command.js +13 -2
- package/dist/commands/rules-command.d.ts.map +1 -1
- package/dist/commands/rules-command.js +65 -0
- package/dist/commands/save-command.d.ts.map +1 -1
- package/dist/commands/save-command.js +12 -0
- package/dist/commands/shell-command.d.ts.map +1 -1
- package/dist/commands/shell-command.js +68 -0
- package/dist/commands/types.d.ts +9 -4
- package/dist/commands/types.d.ts.map +1 -1
- package/dist/commands/usage-command.d.ts.map +1 -1
- package/dist/commands/usage-command.js +22 -0
- package/dist/config.d.ts +6 -7
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +23 -29
- package/dist/formatting.d.ts +108 -0
- package/dist/formatting.d.ts.map +1 -1
- package/dist/formatting.js +147 -0
- package/dist/index.d.ts +7 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +140 -38
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +47 -18
- package/dist/mentions.d.ts +2 -1
- package/dist/mentions.d.ts.map +1 -1
- package/dist/mentions.js +16 -1
- package/dist/messages.d.ts +8 -0
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +56 -19
- package/dist/middleware/cache.d.ts +3 -0
- package/dist/middleware/cache.d.ts.map +1 -0
- package/dist/middleware/cache.js +53 -0
- package/dist/middleware/index.d.ts +1 -0
- package/dist/middleware/index.d.ts.map +1 -1
- package/dist/middleware/index.js +1 -0
- package/dist/models/ai-config.d.ts +4 -2
- package/dist/models/ai-config.d.ts.map +1 -1
- package/dist/models/ai-config.js +12 -2
- package/dist/models/anthropic-provider.d.ts.map +1 -1
- package/dist/models/anthropic-provider.js +3 -60
- package/dist/models/manager.d.ts +2 -1
- package/dist/models/manager.d.ts.map +1 -1
- package/dist/models/manager.js +26 -2
- package/dist/models/openrouter-provider.d.ts +7 -14
- package/dist/models/openrouter-provider.d.ts.map +1 -1
- package/dist/models/openrouter-provider.js +114 -169
- package/dist/models/providers.d.ts +1 -1
- package/dist/models/providers.d.ts.map +1 -1
- package/dist/prompts.d.ts +1 -0
- package/dist/prompts.d.ts.map +1 -1
- package/dist/prompts.js +53 -4
- package/dist/repl/display-tool-messages.d.ts +1 -1
- package/dist/repl/display-tool-messages.d.ts.map +1 -1
- package/dist/repl/display-tool-messages.js +47 -44
- package/dist/repl/get-prompt-header.d.ts.map +1 -1
- package/dist/repl/get-prompt-header.js +1 -30
- package/dist/repl/project-status-line.d.ts +2 -0
- package/dist/repl/project-status-line.d.ts.map +1 -0
- package/dist/repl/project-status-line.js +31 -0
- package/dist/repl/prompt.d.ts +21 -0
- package/dist/repl/prompt.d.ts.map +1 -0
- package/dist/{repl-prompt.js → repl/prompt.js} +119 -22
- package/dist/repl/tool-call-repair.d.ts.map +1 -1
- package/dist/repl/tool-call-repair.js +8 -4
- package/dist/repl-new.d.ts +53 -0
- package/dist/repl-new.d.ts.map +1 -0
- package/dist/repl-new.js +374 -0
- package/dist/repl.d.ts +3 -5
- package/dist/repl.d.ts.map +1 -1
- package/dist/repl.js +74 -166
- package/dist/terminal/checkbox-prompt.d.ts.map +1 -1
- package/dist/terminal/checkbox-prompt.js +10 -4
- package/dist/terminal/index.d.ts +7 -0
- package/dist/terminal/index.d.ts.map +1 -1
- package/dist/terminal/index.js +94 -0
- package/dist/terminal/input-prompt.d.ts +2 -1
- package/dist/terminal/input-prompt.d.ts.map +1 -1
- package/dist/terminal/markdown.js +3 -0
- package/dist/terminal/search-prompt.d.ts.map +1 -1
- package/dist/terminal/search-prompt.js +11 -10
- package/dist/terminal/select-prompt.d.ts +2 -2
- package/dist/terminal/select-prompt.d.ts.map +1 -1
- package/dist/terminal/select-prompt.js +47 -39
- package/dist/tokens/threshold.d.ts +35 -0
- package/dist/tokens/threshold.d.ts.map +1 -0
- package/dist/tokens/threshold.js +85 -0
- package/dist/tools/advanced-edit-file.d.ts +69 -0
- package/dist/tools/advanced-edit-file.d.ts.map +1 -0
- package/dist/tools/advanced-edit-file.js +281 -0
- package/dist/tools/agent.d.ts +16 -5
- package/dist/tools/agent.d.ts.map +1 -1
- package/dist/tools/agent.js +71 -58
- package/dist/tools/bash-utils.d.ts +1 -1
- package/dist/tools/bash-utils.d.ts.map +1 -1
- package/dist/tools/bash-utils.js +14 -6
- package/dist/tools/bash.d.ts +21 -12
- package/dist/tools/bash.d.ts.map +1 -1
- package/dist/tools/bash.js +88 -135
- package/dist/tools/code-interpreter.d.ts +21 -9
- package/dist/tools/code-interpreter.d.ts.map +1 -1
- package/dist/tools/code-interpreter.js +138 -137
- package/dist/tools/delete-file.d.ts +17 -10
- package/dist/tools/delete-file.d.ts.map +1 -1
- package/dist/tools/delete-file.js +51 -95
- package/dist/tools/directory-tree.d.ts +17 -6
- package/dist/tools/directory-tree.d.ts.map +1 -1
- package/dist/tools/directory-tree.js +47 -49
- package/dist/tools/dynamic-tool-loader.d.ts +18 -8
- package/dist/tools/dynamic-tool-loader.d.ts.map +1 -1
- package/dist/tools/dynamic-tool-loader.js +121 -129
- package/dist/tools/dynamic-tool-parser.d.ts +1 -0
- package/dist/tools/dynamic-tool-parser.d.ts.map +1 -1
- package/dist/tools/dynamic-tool-parser.js +1 -0
- package/dist/tools/edit-file.d.ts +35 -15
- package/dist/tools/edit-file.d.ts.map +1 -1
- package/dist/tools/edit-file.js +112 -112
- package/dist/tools/filesystem-utils.d.ts +2 -1
- package/dist/tools/filesystem-utils.d.ts.map +1 -1
- package/dist/tools/filesystem-utils.js +31 -17
- package/dist/tools/glob.d.ts +36 -0
- package/dist/tools/glob.d.ts.map +1 -0
- package/dist/tools/glob.js +143 -0
- package/dist/tools/grep.d.ts +73 -12
- package/dist/tools/grep.d.ts.map +1 -1
- package/dist/tools/grep.js +413 -168
- package/dist/tools/index.d.ts +204 -124
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +242 -135
- package/dist/tools/llm-edit-fixer.d.ts +25 -0
- package/dist/tools/llm-edit-fixer.d.ts.map +1 -0
- package/dist/tools/llm-edit-fixer.js +150 -0
- package/dist/tools/move-file.d.ts +19 -7
- package/dist/tools/move-file.d.ts.map +1 -1
- package/dist/tools/move-file.js +40 -33
- package/dist/tools/read-file.d.ts +47 -9
- package/dist/tools/read-file.d.ts.map +1 -1
- package/dist/tools/read-file.js +74 -69
- package/dist/tools/read-multiple-files.d.ts +17 -6
- package/dist/tools/read-multiple-files.d.ts.map +1 -1
- package/dist/tools/read-multiple-files.js +76 -73
- package/dist/tools/save-file.d.ts +45 -12
- package/dist/tools/save-file.d.ts.map +1 -1
- package/dist/tools/save-file.js +58 -101
- package/dist/tools/think.d.ts +15 -7
- package/dist/tools/think.d.ts.map +1 -1
- package/dist/tools/think.js +30 -22
- package/dist/tools/types.d.ts +4 -10
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/types.js +9 -0
- package/dist/tools/utils.d.ts +14 -0
- package/dist/tools/utils.d.ts.map +1 -0
- package/dist/tools/utils.js +16 -0
- package/dist/tools/web-fetch.d.ts +11 -4
- package/dist/tools/web-fetch.d.ts.map +1 -1
- package/dist/tools/web-fetch.js +39 -38
- package/dist/tools/web-search.d.ts +15 -6
- package/dist/tools/web-search.d.ts.map +1 -1
- package/dist/tools/web-search.js +50 -32
- package/dist/tui/autocomplete.d.ts +44 -0
- package/dist/tui/autocomplete.d.ts.map +1 -0
- package/dist/tui/autocomplete.js +466 -0
- package/dist/tui/components/assistant-message.d.ts +18 -0
- package/dist/tui/components/assistant-message.d.ts.map +1 -0
- package/dist/tui/components/assistant-message.js +29 -0
- package/dist/tui/components/editor.d.ts +51 -0
- package/dist/tui/components/editor.d.ts.map +1 -0
- package/dist/tui/components/editor.js +758 -0
- package/dist/tui/components/footer.d.ts +24 -0
- package/dist/tui/components/footer.d.ts.map +1 -0
- package/dist/tui/components/footer.js +197 -0
- package/dist/tui/components/input.d.ts +14 -0
- package/dist/tui/components/input.d.ts.map +1 -0
- package/dist/tui/components/input.js +122 -0
- package/dist/tui/components/loader.d.ts +19 -0
- package/dist/tui/components/loader.d.ts.map +1 -0
- package/dist/tui/components/loader.js +45 -0
- package/dist/tui/components/markdown.d.ts +103 -0
- package/dist/tui/components/markdown.d.ts.map +1 -0
- package/dist/tui/components/markdown.js +533 -0
- package/dist/tui/components/modal.d.ts +40 -0
- package/dist/tui/components/modal.d.ts.map +1 -0
- package/dist/tui/components/modal.js +292 -0
- package/dist/tui/components/prompt-status.d.ts +16 -0
- package/dist/tui/components/prompt-status.d.ts.map +1 -0
- package/dist/tui/components/prompt-status.js +21 -0
- package/dist/tui/components/select-list.d.ts +22 -0
- package/dist/tui/components/select-list.d.ts.map +1 -0
- package/dist/tui/components/select-list.js +143 -0
- package/dist/tui/components/spacer.d.ts +16 -0
- package/dist/tui/components/spacer.d.ts.map +1 -0
- package/dist/tui/components/spacer.js +27 -0
- package/dist/tui/components/text.d.ts +26 -0
- package/dist/tui/components/text.d.ts.map +1 -0
- package/dist/tui/components/text.js +143 -0
- package/dist/tui/components/thinking-block.d.ts +14 -0
- package/dist/tui/components/thinking-block.d.ts.map +1 -0
- package/dist/tui/components/thinking-block.js +30 -0
- package/dist/tui/components/tool-execution.d.ts +17 -0
- package/dist/tui/components/tool-execution.d.ts.map +1 -0
- package/dist/tui/components/tool-execution.js +153 -0
- package/dist/tui/components/user-message.d.ts +9 -0
- package/dist/tui/components/user-message.d.ts.map +1 -0
- package/dist/tui/components/user-message.js +21 -0
- package/dist/tui/components/welcome.d.ts +6 -0
- package/dist/tui/components/welcome.d.ts.map +1 -0
- package/dist/tui/components/welcome.js +30 -0
- package/dist/tui/index.d.ts +14 -0
- package/dist/tui/index.d.ts.map +1 -0
- package/dist/tui/index.js +18 -0
- package/dist/tui/terminal.d.ts +37 -0
- package/dist/tui/terminal.d.ts.map +1 -0
- package/dist/tui/terminal.js +104 -0
- package/dist/tui/tui.d.ts +67 -0
- package/dist/tui/tui.d.ts.map +1 -0
- package/dist/tui/tui.js +184 -0
- package/dist/tui/utils.d.ts +19 -0
- package/dist/tui/utils.d.ts.map +1 -0
- package/dist/tui/utils.js +31 -0
- package/dist/utils/generators.d.ts +3 -0
- package/dist/utils/generators.d.ts.map +1 -0
- package/dist/utils/generators.js +25 -0
- package/dist/utils/iterables.d.ts +2 -0
- package/dist/utils/iterables.d.ts.map +1 -0
- package/dist/utils/iterables.js +6 -0
- package/package.json +16 -16
- package/dist/conversation-analyzer.d.ts +0 -11
- package/dist/conversation-analyzer.d.ts.map +0 -1
- package/dist/conversation-analyzer.js +0 -88
- package/dist/repl-prompt.d.ts +0 -15
- package/dist/repl-prompt.d.ts.map +0 -1
- package/dist/tokens/manage-output.d.ts +0 -34
- package/dist/tokens/manage-output.d.ts.map +0 -1
- package/dist/tokens/manage-output.js +0 -44
- package/dist/tool-executor.d.ts +0 -28
- package/dist/tool-executor.d.ts.map +0 -1
- package/dist/tool-executor.js +0 -74
- package/dist/tools/file-editing-utils.d.ts +0 -2
- package/dist/tools/file-editing-utils.d.ts.map +0 -1
- package/dist/tools/file-editing-utils.js +0 -135
package/dist/tools/index.js
CHANGED
|
@@ -1,206 +1,313 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
1
|
+
import { tool } from "ai";
|
|
2
|
+
import { AdvancedEditFileTool, createAdvancedEditFileTool, } from "./advanced-edit-file.js";
|
|
3
|
+
import { AgentTool, createAgentTools } from "./agent.js";
|
|
4
|
+
import { BashTool, createBashTool } from "./bash.js";
|
|
5
|
+
import { CodeInterpreterTool, createCodeInterpreterTool, } from "./code-interpreter.js";
|
|
6
|
+
import { createDeleteFileTool, DeleteFileTool } from "./delete-file.js";
|
|
7
|
+
import { createDirectoryTreeTool, DirectoryTreeTool, } from "./directory-tree.js";
|
|
6
8
|
import { loadDynamicTools } from "./dynamic-tool-loader.js";
|
|
7
|
-
import { createEditFileTool } from "./edit-file.js";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return (msg) => {
|
|
19
|
-
if (msgStore.has(msg.id)) {
|
|
20
|
-
msgStore.get(msg.id)?.push(msg);
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
msgStore.set(msg.id, [msg]);
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
export async function initTools({ terminal, tokenCounter, events, toolExecutor, }) {
|
|
28
|
-
const sendDataFn = sendDataHandler(events);
|
|
9
|
+
import { createEditFileTool, EditFileTool } from "./edit-file.js";
|
|
10
|
+
import { createGlobTool, GlobTool } from "./glob.js";
|
|
11
|
+
import { createGrepTool, GrepTool } from "./grep.js";
|
|
12
|
+
import { createMoveFileTool, MoveFileTool } from "./move-file.js";
|
|
13
|
+
import { createReadFileTool, ReadFileTool } from "./read-file.js";
|
|
14
|
+
import { createReadMultipleFilesTool, ReadMultipleFilesTool, } from "./read-multiple-files.js";
|
|
15
|
+
import { createSaveFileTool, SaveFileTool } from "./save-file.js";
|
|
16
|
+
import { createThinkTool, ThinkTool } from "./think.js";
|
|
17
|
+
import { createWebFetchTool, WebFetchTool } from "./web-fetch.js";
|
|
18
|
+
import { createWebSearchTool, WebSearchTool } from "./web-search.js";
|
|
19
|
+
export async function initTools({ tokenCounter, workspace, modelManager, tokenTracker, }) {
|
|
29
20
|
const readFileTool = await createReadFileTool({
|
|
30
|
-
workingDir:
|
|
31
|
-
|
|
21
|
+
workingDir: workspace.primaryDir,
|
|
22
|
+
allowedDirs: workspace.allowedDirs,
|
|
32
23
|
tokenCounter,
|
|
33
24
|
});
|
|
34
25
|
const readMultipleFilesTool = await createReadMultipleFilesTool({
|
|
35
|
-
workingDir:
|
|
36
|
-
|
|
26
|
+
workingDir: workspace.primaryDir,
|
|
27
|
+
allowedDirs: workspace.allowedDirs,
|
|
37
28
|
tokenCounter,
|
|
38
29
|
});
|
|
39
30
|
const editFileTool = await createEditFileTool({
|
|
40
|
-
workingDir:
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
31
|
+
workingDir: workspace.primaryDir,
|
|
32
|
+
allowedDirs: workspace.allowedDirs,
|
|
33
|
+
modelManager,
|
|
34
|
+
tokenTracker,
|
|
35
|
+
});
|
|
36
|
+
const advancedEditFileTool = await createAdvancedEditFileTool({
|
|
37
|
+
workingDir: workspace.primaryDir,
|
|
38
|
+
allowedDirs: workspace.allowedDirs,
|
|
44
39
|
});
|
|
45
40
|
const saveFileTool = await createSaveFileTool({
|
|
46
|
-
workingDir:
|
|
47
|
-
|
|
48
|
-
terminal,
|
|
49
|
-
toolExecutor,
|
|
41
|
+
workingDir: workspace.primaryDir,
|
|
42
|
+
allowedDirs: workspace.allowedDirs,
|
|
50
43
|
});
|
|
51
44
|
const moveFileTool = await createMoveFileTool({
|
|
52
|
-
workingDir:
|
|
53
|
-
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
45
|
+
workingDir: workspace.primaryDir,
|
|
46
|
+
allowedDirs: workspace.allowedDirs,
|
|
47
|
+
});
|
|
48
|
+
const directoryTreeTool = await createDirectoryTreeTool({
|
|
49
|
+
workingDir: workspace.primaryDir,
|
|
50
|
+
allowedDirs: workspace.allowedDirs,
|
|
51
|
+
tokenCounter,
|
|
52
|
+
});
|
|
60
53
|
const deleteFileTool = await createDeleteFileTool({
|
|
61
|
-
workingDir:
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
54
|
+
workingDir: workspace.primaryDir,
|
|
55
|
+
allowedDirs: workspace.allowedDirs,
|
|
56
|
+
});
|
|
57
|
+
const codeInterpreterTool = await createCodeInterpreterTool({
|
|
58
|
+
tokenCounter,
|
|
65
59
|
});
|
|
66
|
-
const
|
|
67
|
-
|
|
60
|
+
const globTool = createGlobTool({
|
|
61
|
+
tokenCounter,
|
|
68
62
|
});
|
|
69
63
|
const grepTool = createGrepTool({
|
|
70
|
-
sendData: sendDataFn,
|
|
71
64
|
tokenCounter,
|
|
72
65
|
});
|
|
73
|
-
const thinkTool = createThinkTool(
|
|
74
|
-
sendData: sendDataFn,
|
|
75
|
-
});
|
|
66
|
+
const thinkTool = createThinkTool();
|
|
76
67
|
const webFetchTool = createWebFetchTool({
|
|
77
|
-
sendData: sendDataFn,
|
|
78
68
|
tokenCounter,
|
|
79
69
|
});
|
|
80
70
|
const webSearchTool = createWebSearchTool({
|
|
81
|
-
sendData: sendDataFn,
|
|
82
71
|
tokenCounter,
|
|
83
72
|
});
|
|
84
73
|
const bashTool = await createBashTool({
|
|
85
|
-
baseDir:
|
|
86
|
-
|
|
74
|
+
baseDir: workspace.primaryDir,
|
|
75
|
+
allowedDirs: workspace.allowedDirs,
|
|
87
76
|
tokenCounter,
|
|
88
|
-
terminal,
|
|
89
|
-
toolExecutor,
|
|
90
77
|
});
|
|
91
78
|
const dynamicTools = await loadDynamicTools({
|
|
92
|
-
baseDir:
|
|
93
|
-
sendData: sendDataFn,
|
|
79
|
+
baseDir: workspace.primaryDir,
|
|
94
80
|
});
|
|
81
|
+
// Build tools object for AI SDK
|
|
95
82
|
const tools = {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
83
|
+
[EditFileTool.name]: tool(editFileTool.toolDef),
|
|
84
|
+
[AdvancedEditFileTool.name]: tool(advancedEditFileTool.toolDef),
|
|
85
|
+
[BashTool.name]: tool(bashTool.toolDef),
|
|
86
|
+
[SaveFileTool.name]: tool(saveFileTool.toolDef),
|
|
87
|
+
[DeleteFileTool.name]: tool(deleteFileTool.toolDef),
|
|
88
|
+
[MoveFileTool.name]: tool(moveFileTool.toolDef),
|
|
89
|
+
[ReadFileTool.name]: tool(readFileTool.toolDef),
|
|
90
|
+
[ReadMultipleFilesTool.name]: tool(readMultipleFilesTool.toolDef),
|
|
91
|
+
[GlobTool.name]: tool(globTool.toolDef),
|
|
92
|
+
[GrepTool.name]: tool(grepTool.toolDef),
|
|
93
|
+
[DirectoryTreeTool.name]: tool(directoryTreeTool.toolDef),
|
|
94
|
+
[CodeInterpreterTool.name]: tool(codeInterpreterTool.toolDef),
|
|
95
|
+
[ThinkTool.name]: tool(thinkTool.toolDef),
|
|
96
|
+
[WebFetchTool.name]: tool(webFetchTool.toolDef),
|
|
97
|
+
[WebSearchTool.name]: tool(webSearchTool.toolDef),
|
|
98
|
+
// Add dynamic tools - they already have toolDef structure
|
|
99
|
+
...Object.fromEntries(Object.entries(dynamicTools).map(([name, toolObj]) => [
|
|
100
|
+
name,
|
|
101
|
+
tool(toolObj.toolDef),
|
|
102
|
+
])),
|
|
103
|
+
};
|
|
104
|
+
// Build executors map for manual loop
|
|
105
|
+
const executors = new Map();
|
|
106
|
+
// Add bash tool
|
|
107
|
+
executors.set(BashTool.name, bashTool.execute);
|
|
108
|
+
// Add editFile tool
|
|
109
|
+
executors.set(EditFileTool.name, editFileTool.execute);
|
|
110
|
+
// Add advancedEditFile tool
|
|
111
|
+
executors.set(AdvancedEditFileTool.name, advancedEditFileTool.execute);
|
|
112
|
+
// Add saveFile tool
|
|
113
|
+
executors.set(SaveFileTool.name, saveFileTool.execute);
|
|
114
|
+
// Add deleteFile tool
|
|
115
|
+
executors.set(DeleteFileTool.name, deleteFileTool.execute);
|
|
116
|
+
// Add moveFile tool
|
|
117
|
+
executors.set(MoveFileTool.name, moveFileTool.execute);
|
|
118
|
+
// Add readFile tool
|
|
119
|
+
executors.set(ReadFileTool.name, readFileTool.execute);
|
|
120
|
+
// Add readMultipleFiles tool
|
|
121
|
+
executors.set(ReadMultipleFilesTool.name, readMultipleFilesTool.execute);
|
|
122
|
+
// Add glob tool
|
|
123
|
+
executors.set(GlobTool.name, globTool.execute);
|
|
124
|
+
// Add grep tool
|
|
125
|
+
executors.set(GrepTool.name, grepTool.execute);
|
|
126
|
+
// Add directoryTree tool
|
|
127
|
+
executors.set(DirectoryTreeTool.name, directoryTreeTool.execute);
|
|
128
|
+
// Add webFetch tool
|
|
129
|
+
executors.set(WebFetchTool.name, webFetchTool.execute);
|
|
130
|
+
// Add webSearch tool
|
|
131
|
+
executors.set(WebSearchTool.name, webSearchTool.execute);
|
|
132
|
+
// Add think tool
|
|
133
|
+
executors.set(ThinkTool.name, thinkTool.execute);
|
|
134
|
+
// Add codeInterpreter tool
|
|
135
|
+
executors.set(CodeInterpreterTool.name, codeInterpreterTool.execute);
|
|
136
|
+
// Add dynamic tools to executors
|
|
137
|
+
for (const [name, toolObj] of Object.entries(dynamicTools)) {
|
|
138
|
+
executors.set(name, toolObj.execute);
|
|
139
|
+
}
|
|
140
|
+
return {
|
|
141
|
+
toolDefs: tools,
|
|
142
|
+
executors,
|
|
110
143
|
};
|
|
111
|
-
return tools;
|
|
112
144
|
}
|
|
113
|
-
export async function initCliTools({ tokenCounter, }) {
|
|
145
|
+
export async function initCliTools({ tokenCounter, workspace, modelManager, tokenTracker, }) {
|
|
114
146
|
const readFileTool = await createReadFileTool({
|
|
115
|
-
workingDir:
|
|
116
|
-
|
|
147
|
+
workingDir: workspace.primaryDir,
|
|
148
|
+
allowedDirs: workspace.allowedDirs,
|
|
117
149
|
tokenCounter,
|
|
118
150
|
});
|
|
119
151
|
const readMultipleFilesTool = await createReadMultipleFilesTool({
|
|
120
|
-
workingDir:
|
|
121
|
-
|
|
152
|
+
workingDir: workspace.primaryDir,
|
|
153
|
+
allowedDirs: workspace.allowedDirs,
|
|
122
154
|
tokenCounter,
|
|
123
155
|
});
|
|
124
156
|
const editFileTool = await createEditFileTool({
|
|
125
|
-
workingDir:
|
|
126
|
-
|
|
127
|
-
|
|
157
|
+
workingDir: workspace.primaryDir,
|
|
158
|
+
allowedDirs: workspace.allowedDirs,
|
|
159
|
+
modelManager,
|
|
160
|
+
tokenTracker,
|
|
161
|
+
});
|
|
162
|
+
const advancedEditFileTool = await createAdvancedEditFileTool({
|
|
163
|
+
workingDir: workspace.primaryDir,
|
|
164
|
+
allowedDirs: workspace.allowedDirs,
|
|
128
165
|
});
|
|
129
166
|
const saveFileTool = await createSaveFileTool({
|
|
130
|
-
workingDir:
|
|
131
|
-
|
|
132
|
-
terminal: undefined,
|
|
167
|
+
workingDir: workspace.primaryDir,
|
|
168
|
+
allowedDirs: workspace.allowedDirs,
|
|
133
169
|
});
|
|
134
170
|
const moveFileTool = await createMoveFileTool({
|
|
135
|
-
workingDir:
|
|
136
|
-
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
171
|
+
workingDir: workspace.primaryDir,
|
|
172
|
+
allowedDirs: workspace.allowedDirs,
|
|
173
|
+
});
|
|
174
|
+
const directoryTreeTool = await createDirectoryTreeTool({
|
|
175
|
+
workingDir: workspace.primaryDir,
|
|
176
|
+
allowedDirs: workspace.allowedDirs,
|
|
177
|
+
tokenCounter,
|
|
178
|
+
});
|
|
143
179
|
const deleteFileTool = await createDeleteFileTool({
|
|
144
|
-
workingDir:
|
|
145
|
-
|
|
146
|
-
terminal: undefined,
|
|
180
|
+
workingDir: workspace.primaryDir,
|
|
181
|
+
allowedDirs: workspace.allowedDirs,
|
|
147
182
|
});
|
|
148
|
-
const codeInterpreterTool = createCodeInterpreterTool({
|
|
149
|
-
|
|
183
|
+
const codeInterpreterTool = await createCodeInterpreterTool({
|
|
184
|
+
tokenCounter,
|
|
150
185
|
});
|
|
151
|
-
const
|
|
152
|
-
sendData: undefined,
|
|
186
|
+
const globTool = createGlobTool({
|
|
153
187
|
tokenCounter,
|
|
154
188
|
});
|
|
155
|
-
const
|
|
156
|
-
|
|
189
|
+
const grepTool = createGrepTool({
|
|
190
|
+
tokenCounter,
|
|
157
191
|
});
|
|
192
|
+
const thinkTool = createThinkTool();
|
|
158
193
|
const webFetchTool = createWebFetchTool({
|
|
159
|
-
sendData: undefined,
|
|
160
194
|
tokenCounter,
|
|
161
195
|
});
|
|
162
196
|
const webSearchTool = createWebSearchTool({
|
|
163
|
-
sendData: undefined,
|
|
164
197
|
tokenCounter,
|
|
165
198
|
});
|
|
166
199
|
const bashTool = await createBashTool({
|
|
167
|
-
baseDir:
|
|
168
|
-
|
|
200
|
+
baseDir: workspace.primaryDir,
|
|
201
|
+
allowedDirs: workspace.allowedDirs,
|
|
169
202
|
tokenCounter,
|
|
170
|
-
terminal: undefined,
|
|
171
203
|
});
|
|
172
204
|
const dynamicTools = await loadDynamicTools({
|
|
173
|
-
baseDir:
|
|
174
|
-
|
|
205
|
+
baseDir: workspace.primaryDir,
|
|
206
|
+
});
|
|
207
|
+
const tools = {
|
|
208
|
+
[EditFileTool.name]: tool({
|
|
209
|
+
...editFileTool.toolDef,
|
|
210
|
+
execute: editFileTool.execute,
|
|
211
|
+
}),
|
|
212
|
+
[AdvancedEditFileTool.name]: tool({
|
|
213
|
+
...advancedEditFileTool.toolDef,
|
|
214
|
+
execute: advancedEditFileTool.execute,
|
|
215
|
+
}),
|
|
216
|
+
[BashTool.name]: tool({
|
|
217
|
+
...bashTool.toolDef,
|
|
218
|
+
execute: bashTool.execute,
|
|
219
|
+
}),
|
|
220
|
+
[SaveFileTool.name]: tool({
|
|
221
|
+
...saveFileTool.toolDef,
|
|
222
|
+
execute: saveFileTool.execute,
|
|
223
|
+
}),
|
|
224
|
+
[DeleteFileTool.name]: tool({
|
|
225
|
+
...deleteFileTool.toolDef,
|
|
226
|
+
execute: deleteFileTool.execute,
|
|
227
|
+
}),
|
|
228
|
+
[MoveFileTool.name]: tool({
|
|
229
|
+
...moveFileTool.toolDef,
|
|
230
|
+
execute: moveFileTool.execute,
|
|
231
|
+
}),
|
|
232
|
+
[ReadFileTool.name]: tool({
|
|
233
|
+
...readFileTool.toolDef,
|
|
234
|
+
execute: readFileTool.execute,
|
|
235
|
+
}),
|
|
236
|
+
[ReadMultipleFilesTool.name]: tool({
|
|
237
|
+
...readMultipleFilesTool.toolDef,
|
|
238
|
+
execute: readMultipleFilesTool.execute,
|
|
239
|
+
}),
|
|
240
|
+
[GlobTool.name]: tool({
|
|
241
|
+
...globTool.toolDef,
|
|
242
|
+
execute: globTool.execute,
|
|
243
|
+
}),
|
|
244
|
+
[GrepTool.name]: tool({
|
|
245
|
+
...grepTool.toolDef,
|
|
246
|
+
execute: grepTool.execute,
|
|
247
|
+
}),
|
|
248
|
+
[DirectoryTreeTool.name]: tool({
|
|
249
|
+
...directoryTreeTool.toolDef,
|
|
250
|
+
execute: directoryTreeTool.execute,
|
|
251
|
+
}),
|
|
252
|
+
[CodeInterpreterTool.name]: tool({
|
|
253
|
+
...codeInterpreterTool.toolDef,
|
|
254
|
+
execute: codeInterpreterTool.execute,
|
|
255
|
+
}),
|
|
256
|
+
[ThinkTool.name]: tool({
|
|
257
|
+
...thinkTool.toolDef,
|
|
258
|
+
execute: thinkTool.execute,
|
|
259
|
+
}),
|
|
260
|
+
[WebFetchTool.name]: tool({
|
|
261
|
+
...webFetchTool.toolDef,
|
|
262
|
+
execute: webFetchTool.execute,
|
|
263
|
+
}),
|
|
264
|
+
[WebSearchTool.name]: tool({
|
|
265
|
+
...webSearchTool.toolDef,
|
|
266
|
+
execute: webSearchTool.execute,
|
|
267
|
+
}),
|
|
268
|
+
// Add dynamic tools with execute functions
|
|
269
|
+
...Object.fromEntries(Object.entries(dynamicTools).map(([name, toolObj]) => [
|
|
270
|
+
name,
|
|
271
|
+
tool({
|
|
272
|
+
...toolObj.toolDef,
|
|
273
|
+
execute: toolObj.execute,
|
|
274
|
+
}),
|
|
275
|
+
])),
|
|
276
|
+
};
|
|
277
|
+
return {
|
|
278
|
+
toolDefs: tools,
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
export async function initAgents({ modelManager, tokenTracker, tokenCounter, workspace, }) {
|
|
282
|
+
const agentTools = createAgentTools({
|
|
283
|
+
modelManager,
|
|
284
|
+
tokenTracker,
|
|
285
|
+
tokenCounter,
|
|
286
|
+
workspace,
|
|
175
287
|
});
|
|
176
288
|
const tools = {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
...grepTool,
|
|
186
|
-
...thinkTool,
|
|
187
|
-
...webFetchTool,
|
|
188
|
-
...bashTool,
|
|
189
|
-
...webSearchTool,
|
|
190
|
-
...dynamicTools,
|
|
289
|
+
[AgentTool.name]: tool(agentTools.toolDef),
|
|
290
|
+
};
|
|
291
|
+
// Build executors map for manual loop
|
|
292
|
+
const executors = new Map();
|
|
293
|
+
executors.set(AgentTool.name, agentTools.execute);
|
|
294
|
+
return {
|
|
295
|
+
toolDefs: tools,
|
|
296
|
+
executors,
|
|
191
297
|
};
|
|
192
|
-
return tools;
|
|
193
298
|
}
|
|
194
|
-
export async function
|
|
195
|
-
const sendDataFn = sendDataHandler(events);
|
|
299
|
+
export async function initCliAgents({ modelManager, tokenTracker, tokenCounter, workspace, }) {
|
|
196
300
|
const agentTools = createAgentTools({
|
|
197
301
|
modelManager,
|
|
198
302
|
tokenTracker,
|
|
199
303
|
tokenCounter,
|
|
200
|
-
|
|
304
|
+
workspace,
|
|
201
305
|
});
|
|
202
306
|
const tools = {
|
|
203
|
-
|
|
307
|
+
[AgentTool.name]: tool({
|
|
308
|
+
...agentTools.toolDef,
|
|
309
|
+
execute: agentTools.execute,
|
|
310
|
+
}),
|
|
204
311
|
};
|
|
205
|
-
return tools;
|
|
312
|
+
return { toolDefs: tools };
|
|
206
313
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { ModelManager } from "../models/manager.ts";
|
|
3
|
+
declare const SearchReplaceEditSchema: z.ZodObject<{
|
|
4
|
+
search: z.ZodString;
|
|
5
|
+
replace: z.ZodString;
|
|
6
|
+
noChangesRequired: z.ZodBoolean;
|
|
7
|
+
explanation: z.ZodString;
|
|
8
|
+
}, z.core.$strip>;
|
|
9
|
+
type SearchReplaceEdit = z.infer<typeof SearchReplaceEditSchema>;
|
|
10
|
+
/**
|
|
11
|
+
* Attempts to fix a failed edit by using an LLM to generate a new search and replace pair.
|
|
12
|
+
*
|
|
13
|
+
* @param instruction The instruction for what needs to be done. If not provided, will auto-generate from oldString/newString
|
|
14
|
+
* @param oldString The original string to be replaced
|
|
15
|
+
* @param newString The original replacement string
|
|
16
|
+
* @param error The error that occurred during the initial edit
|
|
17
|
+
* @param currentContent The current content of the file
|
|
18
|
+
* @param modelManager The model manager for accessing LLM models
|
|
19
|
+
* @param tokenTracker The token tracker for usage monitoring
|
|
20
|
+
* @param abortSignal An abort signal to cancel the operation
|
|
21
|
+
* @returns A corrected search and replace pair, or null if fixing failed
|
|
22
|
+
*/
|
|
23
|
+
export declare function fixLlmEditWithInstruction(instruction: string | undefined, oldString: string, newString: string, error: string, currentContent: string, modelManager: ModelManager | undefined, abortSignal?: AbortSignal): Promise<SearchReplaceEdit | null>;
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=llm-edit-fixer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"llm-edit-fixer.d.ts","sourceRoot":"","sources":["../../source/tools/llm-edit-fixer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAyDzD,QAAA,MAAM,uBAAuB;;;;;iBAK3B,CAAC;AAEH,KAAK,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAuEjE;;;;;;;;;;;;GAYG;AACH,wBAAsB,yBAAyB,CAC7C,WAAW,EAAE,MAAM,GAAG,SAAS,EAC/B,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,EACb,cAAc,EAAE,MAAM,EACtB,YAAY,EAAE,YAAY,GAAG,SAAS,EACtC,WAAW,CAAC,EAAE,WAAW,GACxB,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC,CAyCnC"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { logger } from "../logger.js";
|
|
3
|
+
const GENERATE_JSON_TIMEOUT_MS = 40000; // 40 seconds
|
|
4
|
+
const EDIT_SYS_PROMPT = `
|
|
5
|
+
You are an expert code-editing assistant specializing in debugging and correcting failed search-and-replace operations.
|
|
6
|
+
|
|
7
|
+
# Primary Goal
|
|
8
|
+
Your task is to analyze a failed edit attempt and provide a corrected \`search\` string that will match the text in the file precisely. The correction should be as minimal as possible, staying very close to the original, failed \`search\` string. Do NOT invent a completely new edit based on the instruction; your job is to fix the provided parameters.
|
|
9
|
+
|
|
10
|
+
It is important that you do no try to figure out if the instruction is correct. DO NOT GIVE ADVICE. Your only goal here is to do your best to perform the search and replace task!
|
|
11
|
+
|
|
12
|
+
# Input Context
|
|
13
|
+
You will be given:
|
|
14
|
+
1. The high-level instruction for the original edit.
|
|
15
|
+
2. The exact \`search\` and \`replace\` strings that failed.
|
|
16
|
+
3. The error message that was produced.
|
|
17
|
+
4. The full content of the latest version of the source file.
|
|
18
|
+
|
|
19
|
+
# Rules for Correction
|
|
20
|
+
1. **Minimal Correction:** Your new \`search\` string must be a close variation of the original. Focus on fixing issues like whitespace, indentation, line endings, or small contextual differences.
|
|
21
|
+
2. **Explain the Fix:** Your \`explanation\` MUST state exactly why the original \`search\` failed and how your new \`search\` string resolves that specific failure. (e.g., "The original search failed due to incorrect indentation; the new search corrects the indentation to match the source file.").
|
|
22
|
+
3. **Preserve the \`replace\` String:** Do NOT modify the \`replace\` string unless the instruction explicitly requires it and it was the source of the error. Do not escape any characters in \`replace\`. Your primary focus is fixing the \`search\` string.
|
|
23
|
+
4. **No Changes Case:** CRUCIAL: if the change is already present in the file, set \`noChangesRequired\` to True and explain why in the \`explanation\`. It is crucial that you only do this if the changes outline in \`replace\` are already in the file and suits the instruction.
|
|
24
|
+
5. **Exactness:** The final \`search\` field must be the EXACT literal text from the file. Do not escape characters.
|
|
25
|
+
`;
|
|
26
|
+
const EDIT_USER_PROMPT = `
|
|
27
|
+
# Goal of the Original Edit
|
|
28
|
+
<instruction>
|
|
29
|
+
{instruction}
|
|
30
|
+
</instruction>
|
|
31
|
+
|
|
32
|
+
# Failed Attempt Details
|
|
33
|
+
- **Original \`search\` parameter (failed):**
|
|
34
|
+
<search>
|
|
35
|
+
{old_string}
|
|
36
|
+
</search>
|
|
37
|
+
- **Original \`replace\` parameter:**
|
|
38
|
+
<replace>
|
|
39
|
+
{new_string}
|
|
40
|
+
</replace>
|
|
41
|
+
- **Error Encountered:**
|
|
42
|
+
<error>
|
|
43
|
+
{error}
|
|
44
|
+
</error>
|
|
45
|
+
|
|
46
|
+
# Full File Content
|
|
47
|
+
<file_content>
|
|
48
|
+
{current_content}
|
|
49
|
+
</file_content>
|
|
50
|
+
|
|
51
|
+
# Your Task
|
|
52
|
+
Based on the error and the file content, provide a corrected \`search\` string that will succeed. Remember to keep your correction minimal and explain the precise reason for the failure in your \`explanation\`.
|
|
53
|
+
`;
|
|
54
|
+
// Zod schema for the LLM response
|
|
55
|
+
const SearchReplaceEditSchema = z.object({
|
|
56
|
+
search: z.string(),
|
|
57
|
+
replace: z.string(),
|
|
58
|
+
noChangesRequired: z.boolean(),
|
|
59
|
+
explanation: z.string(),
|
|
60
|
+
});
|
|
61
|
+
/**
|
|
62
|
+
* Auto-generates an instruction based on edit parameters when none is provided
|
|
63
|
+
*/
|
|
64
|
+
function autoGenerateInstruction(oldString, newString) {
|
|
65
|
+
// Create a natural language description of the edit intent
|
|
66
|
+
const oldPreview = oldString.length > 50 ? `${oldString.slice(0, 47)}...` : oldString;
|
|
67
|
+
const newPreview = newString.length > 50 ? `${newString.slice(0, 47)}...` : newString;
|
|
68
|
+
return `Replace "${oldPreview}" with "${newPreview}"`;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Generates JSON with timeout and proper error handling
|
|
72
|
+
*/
|
|
73
|
+
async function generateJsonWithTimeout(modelManager, params, timeoutMs) {
|
|
74
|
+
try {
|
|
75
|
+
const controller = new AbortController();
|
|
76
|
+
const timeoutSignal = AbortSignal.timeout(timeoutMs);
|
|
77
|
+
// Combine abort signals
|
|
78
|
+
const combinedSignal = AbortSignal.any([
|
|
79
|
+
params.abortSignal ?? new AbortController().signal,
|
|
80
|
+
timeoutSignal,
|
|
81
|
+
controller.signal,
|
|
82
|
+
]);
|
|
83
|
+
if (!modelManager) {
|
|
84
|
+
throw new Error("Edit-fix model not available");
|
|
85
|
+
}
|
|
86
|
+
const { text } = await modelManager.getText("edit-fix", params.system, params.prompt, combinedSignal);
|
|
87
|
+
// Parse the JSON response
|
|
88
|
+
try {
|
|
89
|
+
const parsed = JSON.parse(text);
|
|
90
|
+
return parsed;
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
logger.error(error, "Failed to parse LLM response as JSON.");
|
|
94
|
+
logger.info(`Response preview: ${text.slice(0, 500)}`);
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
100
|
+
logger.warn(`LLM edit fix operation timed out. Timeout: ${timeoutMs}ms`);
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
logger.error(`LLM edit fix operation failed. Error: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Attempts to fix a failed edit by using an LLM to generate a new search and replace pair.
|
|
109
|
+
*
|
|
110
|
+
* @param instruction The instruction for what needs to be done. If not provided, will auto-generate from oldString/newString
|
|
111
|
+
* @param oldString The original string to be replaced
|
|
112
|
+
* @param newString The original replacement string
|
|
113
|
+
* @param error The error that occurred during the initial edit
|
|
114
|
+
* @param currentContent The current content of the file
|
|
115
|
+
* @param modelManager The model manager for accessing LLM models
|
|
116
|
+
* @param tokenTracker The token tracker for usage monitoring
|
|
117
|
+
* @param abortSignal An abort signal to cancel the operation
|
|
118
|
+
* @returns A corrected search and replace pair, or null if fixing failed
|
|
119
|
+
*/
|
|
120
|
+
export async function fixLlmEditWithInstruction(instruction, oldString, newString, error, currentContent, modelManager, abortSignal) {
|
|
121
|
+
// If no modelManager is available, return null (LLM fix not available)
|
|
122
|
+
if (!modelManager) {
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
const finalInstruction = instruction || autoGenerateInstruction(oldString, newString);
|
|
126
|
+
// Generate the user prompt with substitutions
|
|
127
|
+
const userPrompt = EDIT_USER_PROMPT.replace("{instruction}", finalInstruction)
|
|
128
|
+
.replace("{old_string}", oldString)
|
|
129
|
+
.replace("{new_string}", newString)
|
|
130
|
+
.replace("{error}", error)
|
|
131
|
+
.replace("{current_content}", currentContent);
|
|
132
|
+
const result = await generateJsonWithTimeout(modelManager, {
|
|
133
|
+
system: EDIT_SYS_PROMPT,
|
|
134
|
+
prompt: userPrompt,
|
|
135
|
+
abortSignal,
|
|
136
|
+
}, GENERATE_JSON_TIMEOUT_MS);
|
|
137
|
+
// Validate the result with Zod schema
|
|
138
|
+
if (result) {
|
|
139
|
+
try {
|
|
140
|
+
const validatedResult = SearchReplaceEditSchema.parse(result);
|
|
141
|
+
logger.info("LLM edit fix successful.");
|
|
142
|
+
return validatedResult;
|
|
143
|
+
}
|
|
144
|
+
catch (validationError) {
|
|
145
|
+
logger.error(`LLM edit fix response validation failed. Error: ${validationError instanceof Error ? validationError.message : "Unknown validation error"}`);
|
|
146
|
+
console.info("Response:", result);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
@@ -1,14 +1,26 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ToolCallOptions } from "ai";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import type { ToolResult } from "./types.ts";
|
|
2
4
|
export declare const MoveFileTool: {
|
|
3
5
|
name: "moveFile";
|
|
4
6
|
};
|
|
5
|
-
|
|
7
|
+
declare const inputSchema: z.ZodObject<{
|
|
8
|
+
source: z.ZodString;
|
|
9
|
+
destination: z.ZodString;
|
|
10
|
+
}, z.core.$strip>;
|
|
11
|
+
type MoveFileInputSchema = z.infer<typeof inputSchema>;
|
|
12
|
+
export declare const createMoveFileTool: ({ workingDir, allowedDirs, }: {
|
|
6
13
|
workingDir: string;
|
|
7
|
-
|
|
14
|
+
allowedDirs?: string[];
|
|
8
15
|
}) => Promise<{
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
16
|
+
toolDef: {
|
|
17
|
+
description: string;
|
|
18
|
+
inputSchema: z.ZodObject<{
|
|
19
|
+
source: z.ZodString;
|
|
20
|
+
destination: z.ZodString;
|
|
21
|
+
}, z.core.$strip>;
|
|
22
|
+
};
|
|
23
|
+
execute({ source, destination }: MoveFileInputSchema, { toolCallId, abortSignal }: ToolCallOptions): AsyncGenerator<ToolResult>;
|
|
13
24
|
}>;
|
|
25
|
+
export {};
|
|
14
26
|
//# sourceMappingURL=move-file.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"move-file.d.ts","sourceRoot":"","sources":["../../source/tools/move-file.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"move-file.d.ts","sourceRoot":"","sources":["../../source/tools/move-file.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,IAAI,CAAC;AAC1C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,eAAO,MAAM,YAAY;;CAExB,CAAC;AAEF,QAAA,MAAM,WAAW;;;iBAGf,CAAC;AAEH,KAAK,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC;AAEvD,eAAO,MAAM,kBAAkB,GAAU,8BAGtC;IACD,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;CACxB;;;;;;;;qCAY8B,mBAAmB,+BACf,eAAe,GAC3C,cAAc,CAAC,UAAU,CAAC;EAkDhC,CAAC"}
|