Skip to content
Closed
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
46 changes: 39 additions & 7 deletions core/tools/definitions/runTerminalCommand.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import os from "os";
import { Tool } from "../..";
import { BUILT_IN_GROUP_NAME, BuiltInToolNames } from "../builtIn";
import {
evaluateTerminalCommandSecurity,
ToolPolicy,
} from "@continuedev/terminal-security";
import os from "os";
import { Tool } from "../..";
import { BUILT_IN_GROUP_NAME, BuiltInToolNames } from "../builtIn";

/**
* Get the preferred shell for the current platform
Expand All @@ -23,7 +23,36 @@ function getPreferredShell(): string {
}
}

const PLATFORM_INFO = `Choose terminal commands and scripts optimized for ${os.platform()} and ${os.arch()} and shell ${getPreferredShell()}.`;
/**
* Get platform-specific command syntax guidance
*/
function getPlatformCommandGuidance(): string {
const platform = os.platform();

if (platform === "win32") {
return `CRITICAL: Commands are executed via PowerShell. Use PowerShell syntax:
- Multiple commands: Use semicolons (;) NOT && or ||
Example: "cd folder; mkdir subfolder; ls"
- Create directories: Use comma-separated list or New-Item
Example: "mkdir dir1, dir2, dir3" or "New-Item -ItemType Directory dir1, dir2"
- Path navigation: Both "./" and relative paths work
Example: "cd subfolder" or "cd ./subfolder" both work
- Environment variables: Use $env:VARIABLE
Example: "echo $env:USERPROFILE"
- Common aliases work: cd, ls, pwd, mkdir, rm, cp, mv
- Native PowerShell: Get-ChildItem, New-Item, Remove-Item, Copy-Item, Move-Item
- Redirection works: > >> < | but prefer PowerShell cmdlets for complex operations`;
} else {
return `Commands are executed via ${getPreferredShell()}. Use standard Unix shell syntax:
- Multiple commands: Use && or ; for chaining
- Paths: Use forward slashes and ./ for relative paths
- Environment variables: Use $VARIABLE`;
}
}

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

${getPlatformCommandGuidance()}`;

const RUN_COMMAND_NOTES = `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.\
Expand All @@ -48,8 +77,9 @@ export const runTerminalCommandTool: Tool = {
properties: {
command: {
type: "string",
description:
"The command to run. This will be passed directly into the IDE shell.",
description: os.platform() === "win32"
? "The PowerShell command to run. Use PowerShell syntax (semicolons for multiple commands, comma-separated mkdir args, etc.)"
: "The shell command to run. This will be passed directly into the shell.",
},
waitForCompletion: {
type: "boolean",
Expand All @@ -74,6 +104,8 @@ export const runTerminalCommandTool: Tool = {
${RUN_COMMAND_NOTES}
You can also optionally include the waitForCompletion argument set to false to run the command in the background.
For example, to see the git log, you could respond with:`,
exampleArgs: [["command", "git log"]],
exampleArgs: os.platform() === "win32"
? [["command", "git log"], ["command", "cd src; ls; pwd"], ["command", "mkdir components, utils, types"], ["command", "Get-ChildItem -Recurse *.js"]]
: [["command", "git log"], ["command", "cd src && ls && pwd"], ["command", "mkdir components utils types"]],
},
};
Loading