Elffuss BraidHub

kikocis/continue public

dc42dd67a510 · 2.5 KiBRawPermalink
1import os from "os";
2import { Tool } from "../..";
3import { BUILT_IN_GROUP_NAME, BuiltInToolNames } from "../builtIn";
4
5/**
6 * Get the preferred shell for the current platform
7 * @returns The preferred shell command or path
8 */
9function getPreferredShell(): string {
10 const platform = os.platform();
11
12 if (platform === "win32") {
13 return "powershell.exe";
14 } else if (platform === "darwin") {
15 return process.env.SHELL || "/bin/zsh";
16 } else {
17 // Linux and other Unix-like systems
18 return process.env.SHELL || "/bin/bash";
19 }
20}
21
22const PLATFORM_INFO = `Choose terminal commands and scripts optimized for ${os.platform()} and ${os.arch()} and shell ${getPreferredShell()}.`;
23
24const RUN_COMMAND_NOTES = `The shell is not stateful and will not remember any previous commands.\
25 When a command is run in the background ALWAYS suggest using shell commands to stop it; NEVER suggest using Ctrl+C.\
26 When suggesting subsequent shell commands ALWAYS format them in shell command blocks.\
27 Do NOT perform actions requiring special/admin privileges.\
28 ${PLATFORM_INFO}`;
29
30export const runTerminalCommandTool: Tool = {
31 type: "function",
32 displayTitle: "Run Terminal Command",
33 wouldLikeTo: "run the following terminal command:",
34 isCurrently: "running the following terminal command:",
35 hasAlready: "ran the following terminal command:",
36 readonly: false,
37 group: BUILT_IN_GROUP_NAME,
38 function: {
39 name: BuiltInToolNames.RunTerminalCommand,
40 description: `Run a terminal command in the current directory.\n${RUN_COMMAND_NOTES}`,
41 parameters: {
42 type: "object",
43 required: ["command"],
44 properties: {
45 command: {
46 type: "string",
47 description:
48 "The command to run. This will be passed directly into the IDE shell.",
49 },
50 waitForCompletion: {
51 type: "boolean",
52 description:
53 "Whether to wait for the command to complete before returning. Default is true. Set to false to run the command in the background. Set to true to run the command in the foreground and wait to collect the output.",
54 },
55 },
56 },
57 },
58 defaultToolPolicy: "allowedWithPermission",
59 systemMessageDescription: {
60 prefix: `To run a terminal command, use the ${BuiltInToolNames.RunTerminalCommand} tool
61${RUN_COMMAND_NOTES}
62You can also optionally include the waitForCompletion argument set to false to run the command in the background.
63For example, to see the git log, you could respond with:`,
64 exampleArgs: [["command", "git log"]],
65 },
66};