Elffuss BraidHub

kikocis/continue public

475fa2c6bca8 · 1.6 KiBRawPermalink
1import { runTerminalCommandTool } from "src/tools/runTerminalCommand.js";
2import { getErrorString } from "src/util/error.js";
3import { services } from "../../services/index.js";
4
5export const handleBashModeProcessing = async (
6 message: string,
7): Promise<string | null> => {
8 // Handle shell mode commands (starting with !)
9 if (!message.trimStart().startsWith("!")) {
10 return message;
11 }
12
13 // Extract the command after the !
14 const bashCommand = message.trimStart().slice(1).trim();
15
16 if (!bashCommand) {
17 return message; // No command provided, treat as regular message
18 }
19
20 // Show tool call immediately, then run asynchronously and populate result
21 const toolCallId = `shell-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
22 const toolCall = {
23 id: toolCallId,
24 type: "function" as const,
25 function: {
26 name: "Bash",
27 arguments: JSON.stringify({ command: bashCommand }),
28 },
29 };
30
31 // Add assistant message with tool call immediately
32 services.chatHistory.addAssistantMessage("", [toolCall]);
33 // Mark as calling for immediate UI feedback
34 services.chatHistory.updateToolStatus(toolCallId, "calling");
35
36 // Execute the bash command asynchronously - don't block UI
37 void runTerminalCommandTool
38 .run({
39 command: bashCommand,
40 })
41 .then((result) => {
42 services.chatHistory.addToolResult(toolCallId, result, "done");
43 })
44 .catch((error) => {
45 const errorMessage = `Bash command failed: ${getErrorString(error)}`;
46 services.chatHistory.addToolResult(toolCallId, errorMessage, "errored");
47 });
48
49 return null; // Processed, no further message handling needed
50};