-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Added "script" mode for execute_command on Windows #9882
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
Open
denis-kudelin
wants to merge
2
commits into
RooCodeInc:main
Choose a base branch
from
Itexoft:windows-script-tool
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,44 +1,85 @@ | ||
| import type OpenAI from "openai" | ||
|
|
||
| const EXECUTE_COMMAND_DESCRIPTION = `Request to execute a CLI command on the system. Use this when you need to perform system operations or run specific commands to accomplish any step in the user's task. You must tailor your command to the user's system and provide a clear explanation of what the command does. For command chaining, use the appropriate chaining syntax for the user's shell. Prefer to execute complex CLI commands over creating executable scripts, as they are more flexible and easier to run. Prefer relative commands and paths that avoid location sensitivity for terminal consistency. | ||
| const buildDescription = (enableScriptMode: boolean) => `Request to execute a CLI command on the system. Use this when you need to perform system operations or run specific commands to accomplish any step in the user's task. You must tailor your command to the user's system and provide a clear explanation of what the command does. For command chaining, use the appropriate chaining syntax for the user's shell. Prefer to execute complex CLI commands over creating executable scripts, as they are more flexible and easier to run. Prefer relative commands and paths that avoid location sensitivity for terminal consistency.${ | ||
| enableScriptMode | ||
| ? " On Windows you can also provide a script body when the command would be too long or hard to escape (percent signs in cmd, nested quotes, here-strings): supply the script text via script_content and the interpreter/shell via script_runner; Roo will write it to a temporary file, run it, and remove it." | ||
| : "" | ||
| } | ||
| Parameters: | ||
| - command: (required) The CLI command to execute. This should be valid for the current operating system. Ensure the command is properly formatted and does not contain any harmful instructions. | ||
| - cwd: (optional) The working directory to execute the command in | ||
| - command: (required unless script_content is used) The CLI command to execute. This should be valid for the current operating system. Ensure the command is properly formatted and does not contain any harmful instructions. | ||
| - cwd: (optional) The working directory to execute the command in${ | ||
| enableScriptMode | ||
| ? ` | ||
| - script_content: (Windows-only, optional) The full text of the script to run when the command would be too long or requires heavy quoting. Do not pass arguments separately—put them in the script. Use multi-line text (here-strings) to avoid escaping percent signs and quotes. | ||
| - script_runner: (Windows-only, optional) The interpreter or shell to execute the temporary script file (e.g., powershell.exe, cmd.exe, python).` | ||
| : "" | ||
| } | ||
| Example: Executing npm run dev | ||
| { "command": "npm run dev", "cwd": null } | ||
| Example: Executing ls in a specific directory if directed | ||
| { "command": "ls -la", "cwd": "/home/user/projects" } | ||
| { "command": "ls -la", "cwd": "/home/user/projects" }${ | ||
| enableScriptMode | ||
| ? ` | ||
| Example: Using relative paths | ||
| { "command": "touch ./testdata/example.file", "cwd": null }` | ||
| Example: Long script executed via temporary file on Windows | ||
| { "script_content": "@' | ||
| Write-Output \"Hello\" | ||
| Write-Output \"Handles %PATH% safely\" | ||
| '@", "script_runner": "powershell.exe" }` | ||
| : "" | ||
| }` | ||
|
|
||
| const COMMAND_PARAMETER_DESCRIPTION = `Shell command to execute` | ||
|
|
||
| const CWD_PARAMETER_DESCRIPTION = `Optional working directory for the command, relative or absolute` | ||
| const SCRIPT_CONTENT_DESCRIPTION = `Windows-only: script body to write into a temporary file when the command is too long or hard to escape (percent signs, nested quotes)` | ||
| const SCRIPT_RUNNER_DESCRIPTION = `Windows-only: program/shell that should run the temporary script file (e.g., powershell.exe, cmd.exe, python)` | ||
|
|
||
| export function getExecuteCommandTool(options: { enableScriptMode: boolean }): OpenAI.Chat.ChatCompletionTool { | ||
| const properties: Record<string, any> = { | ||
| command: { | ||
| type: "string", | ||
| description: COMMAND_PARAMETER_DESCRIPTION, | ||
| }, | ||
| cwd: { | ||
| type: ["string", "null"], | ||
| description: CWD_PARAMETER_DESCRIPTION, | ||
| }, | ||
| } | ||
|
|
||
| if (options.enableScriptMode) { | ||
| properties["script_content"] = { | ||
| type: "string", | ||
| description: SCRIPT_CONTENT_DESCRIPTION, | ||
| } | ||
| properties["script_runner"] = { | ||
| type: "string", | ||
| description: SCRIPT_RUNNER_DESCRIPTION, | ||
| } | ||
| } | ||
|
|
||
| export default { | ||
| type: "function", | ||
| function: { | ||
| name: "execute_command", | ||
| description: EXECUTE_COMMAND_DESCRIPTION, | ||
| strict: true, | ||
| parameters: { | ||
| type: "object", | ||
| properties: { | ||
| command: { | ||
| type: "string", | ||
| description: COMMAND_PARAMETER_DESCRIPTION, | ||
| }, | ||
| cwd: { | ||
| type: ["string", "null"], | ||
| description: CWD_PARAMETER_DESCRIPTION, | ||
| }, | ||
| return { | ||
| type: "function", | ||
| function: { | ||
| name: "execute_command", | ||
| description: buildDescription(options.enableScriptMode), | ||
| strict: true, | ||
| parameters: { | ||
| type: "object", | ||
| properties, | ||
| required: options.enableScriptMode ? [] : ["command"], | ||
| additionalProperties: false, | ||
| ...(options.enableScriptMode | ||
| ? { | ||
| oneOf: [ | ||
| { required: ["command"] }, | ||
| { required: ["script_content", "script_runner"] }, | ||
| ], | ||
| } | ||
| : {}), | ||
denis-kudelin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| required: ["command", "cwd"], | ||
| additionalProperties: false, | ||
| }, | ||
| }, | ||
| } satisfies OpenAI.Chat.ChatCompletionTool | ||
| } satisfies OpenAI.Chat.ChatCompletionTool | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.