Skip to content

feat: ✨ Make the terminal command aware of its OS, platform and shell #5814

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions core/tools/definitions/runTerminalCommand.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
import { Tool } from "../..";
import { BUILT_IN_GROUP_NAME, BuiltInToolNames } from "../builtIn";

import os from 'os';

/**
* Get the preferred shell for the current platform
* @returns The preferred shell command or path
*/
export function getPreferredShell(): string {
const platform = os.platform();

if (platform === 'win32') {
return process.env.COMSPEC || 'cmd.exe';
} else if (platform === 'darwin') {
return process.env.SHELL || '/bin/zsh';
} else {
// Linux and other Unix-like systems
return process.env.SHELL || '/bin/bash';
}
}

export const PLATFORM_INFO = `Choose terminal commands and scripts optimized for ${os.platform} and ${os.arch} and shell ${getPreferredShell()}.`

export const runTerminalCommandTool: Tool = {
type: "function",
displayTitle: "Run Terminal Command",
Expand All @@ -12,11 +33,12 @@ export const runTerminalCommandTool: Tool = {
function: {
name: BuiltInToolNames.RunTerminalCommand,
description:
"Run a terminal command in the current directory.\
`Run a terminal command in the current directory.\
The shell is not stateful and will not remember any previous commands.\
When a command is run in the background ALWAYS suggest using shell commands to stop it; NEVER suggest using Ctrl+C.\
When suggesting subsequent shell commands ALWAYS format them in shell command blocks.\
Do NOT perform actions requiring special/admin privileges.",
Do NOT perform actions requiring special/admin privileges.\
${PLATFORM_INFO}`,
parameters: {
type: "object",
required: ["command"],
Expand Down
Loading