Skip to content

Commit 4f66d94

Browse files
Merge pull request #5814 from chezsmithy/feat-terminal-with-platform-and-shell
feat: ✨ Make the terminal command aware of its OS, platform and shell
2 parents e4829bf + 1a786f6 commit 4f66d94

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

core/tools/definitions/runTerminalCommand.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,27 @@
11
import { Tool } from "../..";
22
import { BUILT_IN_GROUP_NAME, BuiltInToolNames } from "../builtIn";
33

4+
import os from 'os';
5+
6+
/**
7+
* Get the preferred shell for the current platform
8+
* @returns The preferred shell command or path
9+
*/
10+
export function getPreferredShell(): string {
11+
const platform = os.platform();
12+
13+
if (platform === 'win32') {
14+
return process.env.COMSPEC || 'cmd.exe';
15+
} else if (platform === 'darwin') {
16+
return process.env.SHELL || '/bin/zsh';
17+
} else {
18+
// Linux and other Unix-like systems
19+
return process.env.SHELL || '/bin/bash';
20+
}
21+
}
22+
23+
export const PLATFORM_INFO = `Choose terminal commands and scripts optimized for ${os.platform} and ${os.arch} and shell ${getPreferredShell()}.`
24+
425
export const runTerminalCommandTool: Tool = {
526
type: "function",
627
displayTitle: "Run Terminal Command",
@@ -12,11 +33,12 @@ export const runTerminalCommandTool: Tool = {
1233
function: {
1334
name: BuiltInToolNames.RunTerminalCommand,
1435
description:
15-
"Run a terminal command in the current directory.\
36+
`Run a terminal command in the current directory.\
1637
The shell is not stateful and will not remember any previous commands.\
1738
When a command is run in the background ALWAYS suggest using shell commands to stop it; NEVER suggest using Ctrl+C.\
1839
When suggesting subsequent shell commands ALWAYS format them in shell command blocks.\
19-
Do NOT perform actions requiring special/admin privileges.",
40+
Do NOT perform actions requiring special/admin privileges.\
41+
${PLATFORM_INFO}`,
2042
parameters: {
2143
type: "object",
2244
required: ["command"],

0 commit comments

Comments
 (0)