From d791a5345fa6f09f38dc1bec95ab10a905502955 Mon Sep 17 00:00:00 2001 From: Roo Code Date: Sun, 13 Jul 2025 11:35:37 +0000 Subject: [PATCH] feat: add platform-specific terminal context (#5659) - Enhanced system prompt with platform-specific terminal guidance - Added shell-specific command examples and best practices - Improved execute_command tool with platform-appropriate examples - Supports Windows (PowerShell/CMD), macOS (Zsh/Bash), and Linux (Zsh/Bash) - Provides command syntax, operators, path separators, and tool recommendations - Updated test snapshots to include new platform context Fixes #5659 --- .../architect-mode-prompt.snap | 10 +++ .../ask-mode-prompt.snap | 10 +++ .../mcp-server-creation-disabled.snap | 10 +++ .../mcp-server-creation-enabled.snap | 10 +++ .../partial-reads-enabled.snap | 10 +++ .../consistent-system-prompt.snap | 10 +++ .../with-computer-use-support.snap | 10 +++ .../with-diff-enabled-false.snap | 10 +++ .../system-prompt/with-diff-enabled-true.snap | 10 +++ .../with-diff-enabled-undefined.snap | 10 +++ .../with-different-viewport-size.snap | 10 +++ .../system-prompt/with-mcp-hub-provided.snap | 10 +++ .../system-prompt/with-undefined-mcp-hub.snap | 10 +++ src/core/prompts/sections/system-info.ts | 84 +++++++++++++++++++ src/core/prompts/tools/execute-command.ts | 66 ++++++++++++++- 15 files changed, 277 insertions(+), 3 deletions(-) diff --git a/src/core/prompts/__tests__/__snapshots__/add-custom-instructions/architect-mode-prompt.snap b/src/core/prompts/__tests__/__snapshots__/add-custom-instructions/architect-mode-prompt.snap index e80857d354d..aafe6c4f0ba 100644 --- a/src/core/prompts/__tests__/__snapshots__/add-custom-instructions/architect-mode-prompt.snap +++ b/src/core/prompts/__tests__/__snapshots__/add-custom-instructions/architect-mode-prompt.snap @@ -520,6 +520,16 @@ Default Shell: /bin/zsh Home Directory: /home/user Current Workspace Directory: /test/path +**Platform-Specific Terminal Context (Linux Zsh):** +- Use Unix/POSIX commands: ls, cp, mv, rm, mkdir, rmdir +- Use forward slashes (/) for path separators +- Use Zsh-specific features: extended globbing, parameter expansion +- Use Linux-specific commands: systemctl, journalctl, ps, top, htop +- Use package managers: apt, yum, dnf, pacman, zypper (distribution-specific) +- Chain commands with && (success) or || (failure) or ; (always) +- Use Unix environment variables: $PATH, $HOME, $USER +- Use Zsh redirection: > for output, 2>/dev/null for error suppression + The Current Workspace Directory is the active VS Code project directory, and is therefore the default directory for all tool operations. New terminals will be created in the current workspace directory, however if you change directories in a terminal it will then have a different working directory; changing directories in a terminal does not modify the workspace directory, because you do not have access to change the workspace directory. When the user initially gives you a task, a recursive list of all filepaths in the current workspace directory ('/test/path') will be included in environment_details. This provides an overview of the project's file structure, offering key insights into the project from directory/file names (how developers conceptualize and organize their code) and file extensions (the language used). This can also guide decision-making on which files to explore further. If you need to further explore directories such as outside the current workspace directory, you can use the list_files tool. If you pass 'true' for the recursive parameter, it will list files recursively. Otherwise, it will list files at the top level, which is better suited for generic directories where you don't necessarily need the nested structure, like the Desktop. ==== diff --git a/src/core/prompts/__tests__/__snapshots__/add-custom-instructions/ask-mode-prompt.snap b/src/core/prompts/__tests__/__snapshots__/add-custom-instructions/ask-mode-prompt.snap index a169a1f3af5..9c1e28702cb 100644 --- a/src/core/prompts/__tests__/__snapshots__/add-custom-instructions/ask-mode-prompt.snap +++ b/src/core/prompts/__tests__/__snapshots__/add-custom-instructions/ask-mode-prompt.snap @@ -417,6 +417,16 @@ Default Shell: /bin/zsh Home Directory: /home/user Current Workspace Directory: /test/path +**Platform-Specific Terminal Context (Linux Zsh):** +- Use Unix/POSIX commands: ls, cp, mv, rm, mkdir, rmdir +- Use forward slashes (/) for path separators +- Use Zsh-specific features: extended globbing, parameter expansion +- Use Linux-specific commands: systemctl, journalctl, ps, top, htop +- Use package managers: apt, yum, dnf, pacman, zypper (distribution-specific) +- Chain commands with && (success) or || (failure) or ; (always) +- Use Unix environment variables: $PATH, $HOME, $USER +- Use Zsh redirection: > for output, 2>/dev/null for error suppression + The Current Workspace Directory is the active VS Code project directory, and is therefore the default directory for all tool operations. New terminals will be created in the current workspace directory, however if you change directories in a terminal it will then have a different working directory; changing directories in a terminal does not modify the workspace directory, because you do not have access to change the workspace directory. When the user initially gives you a task, a recursive list of all filepaths in the current workspace directory ('/test/path') will be included in environment_details. This provides an overview of the project's file structure, offering key insights into the project from directory/file names (how developers conceptualize and organize their code) and file extensions (the language used). This can also guide decision-making on which files to explore further. If you need to further explore directories such as outside the current workspace directory, you can use the list_files tool. If you pass 'true' for the recursive parameter, it will list files recursively. Otherwise, it will list files at the top level, which is better suited for generic directories where you don't necessarily need the nested structure, like the Desktop. ==== diff --git a/src/core/prompts/__tests__/__snapshots__/add-custom-instructions/mcp-server-creation-disabled.snap b/src/core/prompts/__tests__/__snapshots__/add-custom-instructions/mcp-server-creation-disabled.snap index 8563bef9cca..2f3adbd8f63 100644 --- a/src/core/prompts/__tests__/__snapshots__/add-custom-instructions/mcp-server-creation-disabled.snap +++ b/src/core/prompts/__tests__/__snapshots__/add-custom-instructions/mcp-server-creation-disabled.snap @@ -582,6 +582,16 @@ Default Shell: /bin/zsh Home Directory: /home/user Current Workspace Directory: /test/path +**Platform-Specific Terminal Context (Linux Zsh):** +- Use Unix/POSIX commands: ls, cp, mv, rm, mkdir, rmdir +- Use forward slashes (/) for path separators +- Use Zsh-specific features: extended globbing, parameter expansion +- Use Linux-specific commands: systemctl, journalctl, ps, top, htop +- Use package managers: apt, yum, dnf, pacman, zypper (distribution-specific) +- Chain commands with && (success) or || (failure) or ; (always) +- Use Unix environment variables: $PATH, $HOME, $USER +- Use Zsh redirection: > for output, 2>/dev/null for error suppression + The Current Workspace Directory is the active VS Code project directory, and is therefore the default directory for all tool operations. New terminals will be created in the current workspace directory, however if you change directories in a terminal it will then have a different working directory; changing directories in a terminal does not modify the workspace directory, because you do not have access to change the workspace directory. When the user initially gives you a task, a recursive list of all filepaths in the current workspace directory ('/test/path') will be included in environment_details. This provides an overview of the project's file structure, offering key insights into the project from directory/file names (how developers conceptualize and organize their code) and file extensions (the language used). This can also guide decision-making on which files to explore further. If you need to further explore directories such as outside the current workspace directory, you can use the list_files tool. If you pass 'true' for the recursive parameter, it will list files recursively. Otherwise, it will list files at the top level, which is better suited for generic directories where you don't necessarily need the nested structure, like the Desktop. ==== diff --git a/src/core/prompts/__tests__/__snapshots__/add-custom-instructions/mcp-server-creation-enabled.snap b/src/core/prompts/__tests__/__snapshots__/add-custom-instructions/mcp-server-creation-enabled.snap index fd8ef4dc983..da186b7f781 100644 --- a/src/core/prompts/__tests__/__snapshots__/add-custom-instructions/mcp-server-creation-enabled.snap +++ b/src/core/prompts/__tests__/__snapshots__/add-custom-instructions/mcp-server-creation-enabled.snap @@ -588,6 +588,16 @@ Default Shell: /bin/zsh Home Directory: /home/user Current Workspace Directory: /test/path +**Platform-Specific Terminal Context (Linux Zsh):** +- Use Unix/POSIX commands: ls, cp, mv, rm, mkdir, rmdir +- Use forward slashes (/) for path separators +- Use Zsh-specific features: extended globbing, parameter expansion +- Use Linux-specific commands: systemctl, journalctl, ps, top, htop +- Use package managers: apt, yum, dnf, pacman, zypper (distribution-specific) +- Chain commands with && (success) or || (failure) or ; (always) +- Use Unix environment variables: $PATH, $HOME, $USER +- Use Zsh redirection: > for output, 2>/dev/null for error suppression + The Current Workspace Directory is the active VS Code project directory, and is therefore the default directory for all tool operations. New terminals will be created in the current workspace directory, however if you change directories in a terminal it will then have a different working directory; changing directories in a terminal does not modify the workspace directory, because you do not have access to change the workspace directory. When the user initially gives you a task, a recursive list of all filepaths in the current workspace directory ('/test/path') will be included in environment_details. This provides an overview of the project's file structure, offering key insights into the project from directory/file names (how developers conceptualize and organize their code) and file extensions (the language used). This can also guide decision-making on which files to explore further. If you need to further explore directories such as outside the current workspace directory, you can use the list_files tool. If you pass 'true' for the recursive parameter, it will list files recursively. Otherwise, it will list files at the top level, which is better suited for generic directories where you don't necessarily need the nested structure, like the Desktop. ==== diff --git a/src/core/prompts/__tests__/__snapshots__/add-custom-instructions/partial-reads-enabled.snap b/src/core/prompts/__tests__/__snapshots__/add-custom-instructions/partial-reads-enabled.snap index 0d172d756b1..b918de3dfeb 100644 --- a/src/core/prompts/__tests__/__snapshots__/add-custom-instructions/partial-reads-enabled.snap +++ b/src/core/prompts/__tests__/__snapshots__/add-custom-instructions/partial-reads-enabled.snap @@ -525,6 +525,16 @@ Default Shell: /bin/zsh Home Directory: /home/user Current Workspace Directory: /test/path +**Platform-Specific Terminal Context (Linux Zsh):** +- Use Unix/POSIX commands: ls, cp, mv, rm, mkdir, rmdir +- Use forward slashes (/) for path separators +- Use Zsh-specific features: extended globbing, parameter expansion +- Use Linux-specific commands: systemctl, journalctl, ps, top, htop +- Use package managers: apt, yum, dnf, pacman, zypper (distribution-specific) +- Chain commands with && (success) or || (failure) or ; (always) +- Use Unix environment variables: $PATH, $HOME, $USER +- Use Zsh redirection: > for output, 2>/dev/null for error suppression + The Current Workspace Directory is the active VS Code project directory, and is therefore the default directory for all tool operations. New terminals will be created in the current workspace directory, however if you change directories in a terminal it will then have a different working directory; changing directories in a terminal does not modify the workspace directory, because you do not have access to change the workspace directory. When the user initially gives you a task, a recursive list of all filepaths in the current workspace directory ('/test/path') will be included in environment_details. This provides an overview of the project's file structure, offering key insights into the project from directory/file names (how developers conceptualize and organize their code) and file extensions (the language used). This can also guide decision-making on which files to explore further. If you need to further explore directories such as outside the current workspace directory, you can use the list_files tool. If you pass 'true' for the recursive parameter, it will list files recursively. Otherwise, it will list files at the top level, which is better suited for generic directories where you don't necessarily need the nested structure, like the Desktop. ==== diff --git a/src/core/prompts/__tests__/__snapshots__/system-prompt/consistent-system-prompt.snap b/src/core/prompts/__tests__/__snapshots__/system-prompt/consistent-system-prompt.snap index e80857d354d..aafe6c4f0ba 100644 --- a/src/core/prompts/__tests__/__snapshots__/system-prompt/consistent-system-prompt.snap +++ b/src/core/prompts/__tests__/__snapshots__/system-prompt/consistent-system-prompt.snap @@ -520,6 +520,16 @@ Default Shell: /bin/zsh Home Directory: /home/user Current Workspace Directory: /test/path +**Platform-Specific Terminal Context (Linux Zsh):** +- Use Unix/POSIX commands: ls, cp, mv, rm, mkdir, rmdir +- Use forward slashes (/) for path separators +- Use Zsh-specific features: extended globbing, parameter expansion +- Use Linux-specific commands: systemctl, journalctl, ps, top, htop +- Use package managers: apt, yum, dnf, pacman, zypper (distribution-specific) +- Chain commands with && (success) or || (failure) or ; (always) +- Use Unix environment variables: $PATH, $HOME, $USER +- Use Zsh redirection: > for output, 2>/dev/null for error suppression + The Current Workspace Directory is the active VS Code project directory, and is therefore the default directory for all tool operations. New terminals will be created in the current workspace directory, however if you change directories in a terminal it will then have a different working directory; changing directories in a terminal does not modify the workspace directory, because you do not have access to change the workspace directory. When the user initially gives you a task, a recursive list of all filepaths in the current workspace directory ('/test/path') will be included in environment_details. This provides an overview of the project's file structure, offering key insights into the project from directory/file names (how developers conceptualize and organize their code) and file extensions (the language used). This can also guide decision-making on which files to explore further. If you need to further explore directories such as outside the current workspace directory, you can use the list_files tool. If you pass 'true' for the recursive parameter, it will list files recursively. Otherwise, it will list files at the top level, which is better suited for generic directories where you don't necessarily need the nested structure, like the Desktop. ==== diff --git a/src/core/prompts/__tests__/__snapshots__/system-prompt/with-computer-use-support.snap b/src/core/prompts/__tests__/__snapshots__/system-prompt/with-computer-use-support.snap index 576bf0ddd5a..63db04458d6 100644 --- a/src/core/prompts/__tests__/__snapshots__/system-prompt/with-computer-use-support.snap +++ b/src/core/prompts/__tests__/__snapshots__/system-prompt/with-computer-use-support.snap @@ -576,6 +576,16 @@ Default Shell: /bin/zsh Home Directory: /home/user Current Workspace Directory: /test/path +**Platform-Specific Terminal Context (Linux Zsh):** +- Use Unix/POSIX commands: ls, cp, mv, rm, mkdir, rmdir +- Use forward slashes (/) for path separators +- Use Zsh-specific features: extended globbing, parameter expansion +- Use Linux-specific commands: systemctl, journalctl, ps, top, htop +- Use package managers: apt, yum, dnf, pacman, zypper (distribution-specific) +- Chain commands with && (success) or || (failure) or ; (always) +- Use Unix environment variables: $PATH, $HOME, $USER +- Use Zsh redirection: > for output, 2>/dev/null for error suppression + The Current Workspace Directory is the active VS Code project directory, and is therefore the default directory for all tool operations. New terminals will be created in the current workspace directory, however if you change directories in a terminal it will then have a different working directory; changing directories in a terminal does not modify the workspace directory, because you do not have access to change the workspace directory. When the user initially gives you a task, a recursive list of all filepaths in the current workspace directory ('/test/path') will be included in environment_details. This provides an overview of the project's file structure, offering key insights into the project from directory/file names (how developers conceptualize and organize their code) and file extensions (the language used). This can also guide decision-making on which files to explore further. If you need to further explore directories such as outside the current workspace directory, you can use the list_files tool. If you pass 'true' for the recursive parameter, it will list files recursively. Otherwise, it will list files at the top level, which is better suited for generic directories where you don't necessarily need the nested structure, like the Desktop. ==== diff --git a/src/core/prompts/__tests__/__snapshots__/system-prompt/with-diff-enabled-false.snap b/src/core/prompts/__tests__/__snapshots__/system-prompt/with-diff-enabled-false.snap index e80857d354d..aafe6c4f0ba 100644 --- a/src/core/prompts/__tests__/__snapshots__/system-prompt/with-diff-enabled-false.snap +++ b/src/core/prompts/__tests__/__snapshots__/system-prompt/with-diff-enabled-false.snap @@ -520,6 +520,16 @@ Default Shell: /bin/zsh Home Directory: /home/user Current Workspace Directory: /test/path +**Platform-Specific Terminal Context (Linux Zsh):** +- Use Unix/POSIX commands: ls, cp, mv, rm, mkdir, rmdir +- Use forward slashes (/) for path separators +- Use Zsh-specific features: extended globbing, parameter expansion +- Use Linux-specific commands: systemctl, journalctl, ps, top, htop +- Use package managers: apt, yum, dnf, pacman, zypper (distribution-specific) +- Chain commands with && (success) or || (failure) or ; (always) +- Use Unix environment variables: $PATH, $HOME, $USER +- Use Zsh redirection: > for output, 2>/dev/null for error suppression + The Current Workspace Directory is the active VS Code project directory, and is therefore the default directory for all tool operations. New terminals will be created in the current workspace directory, however if you change directories in a terminal it will then have a different working directory; changing directories in a terminal does not modify the workspace directory, because you do not have access to change the workspace directory. When the user initially gives you a task, a recursive list of all filepaths in the current workspace directory ('/test/path') will be included in environment_details. This provides an overview of the project's file structure, offering key insights into the project from directory/file names (how developers conceptualize and organize their code) and file extensions (the language used). This can also guide decision-making on which files to explore further. If you need to further explore directories such as outside the current workspace directory, you can use the list_files tool. If you pass 'true' for the recursive parameter, it will list files recursively. Otherwise, it will list files at the top level, which is better suited for generic directories where you don't necessarily need the nested structure, like the Desktop. ==== diff --git a/src/core/prompts/__tests__/__snapshots__/system-prompt/with-diff-enabled-true.snap b/src/core/prompts/__tests__/__snapshots__/system-prompt/with-diff-enabled-true.snap index 6fc7ad69cef..1021f591220 100644 --- a/src/core/prompts/__tests__/__snapshots__/system-prompt/with-diff-enabled-true.snap +++ b/src/core/prompts/__tests__/__snapshots__/system-prompt/with-diff-enabled-true.snap @@ -608,6 +608,16 @@ Default Shell: /bin/zsh Home Directory: /home/user Current Workspace Directory: /test/path +**Platform-Specific Terminal Context (Linux Zsh):** +- Use Unix/POSIX commands: ls, cp, mv, rm, mkdir, rmdir +- Use forward slashes (/) for path separators +- Use Zsh-specific features: extended globbing, parameter expansion +- Use Linux-specific commands: systemctl, journalctl, ps, top, htop +- Use package managers: apt, yum, dnf, pacman, zypper (distribution-specific) +- Chain commands with && (success) or || (failure) or ; (always) +- Use Unix environment variables: $PATH, $HOME, $USER +- Use Zsh redirection: > for output, 2>/dev/null for error suppression + The Current Workspace Directory is the active VS Code project directory, and is therefore the default directory for all tool operations. New terminals will be created in the current workspace directory, however if you change directories in a terminal it will then have a different working directory; changing directories in a terminal does not modify the workspace directory, because you do not have access to change the workspace directory. When the user initially gives you a task, a recursive list of all filepaths in the current workspace directory ('/test/path') will be included in environment_details. This provides an overview of the project's file structure, offering key insights into the project from directory/file names (how developers conceptualize and organize their code) and file extensions (the language used). This can also guide decision-making on which files to explore further. If you need to further explore directories such as outside the current workspace directory, you can use the list_files tool. If you pass 'true' for the recursive parameter, it will list files recursively. Otherwise, it will list files at the top level, which is better suited for generic directories where you don't necessarily need the nested structure, like the Desktop. ==== diff --git a/src/core/prompts/__tests__/__snapshots__/system-prompt/with-diff-enabled-undefined.snap b/src/core/prompts/__tests__/__snapshots__/system-prompt/with-diff-enabled-undefined.snap index e80857d354d..aafe6c4f0ba 100644 --- a/src/core/prompts/__tests__/__snapshots__/system-prompt/with-diff-enabled-undefined.snap +++ b/src/core/prompts/__tests__/__snapshots__/system-prompt/with-diff-enabled-undefined.snap @@ -520,6 +520,16 @@ Default Shell: /bin/zsh Home Directory: /home/user Current Workspace Directory: /test/path +**Platform-Specific Terminal Context (Linux Zsh):** +- Use Unix/POSIX commands: ls, cp, mv, rm, mkdir, rmdir +- Use forward slashes (/) for path separators +- Use Zsh-specific features: extended globbing, parameter expansion +- Use Linux-specific commands: systemctl, journalctl, ps, top, htop +- Use package managers: apt, yum, dnf, pacman, zypper (distribution-specific) +- Chain commands with && (success) or || (failure) or ; (always) +- Use Unix environment variables: $PATH, $HOME, $USER +- Use Zsh redirection: > for output, 2>/dev/null for error suppression + The Current Workspace Directory is the active VS Code project directory, and is therefore the default directory for all tool operations. New terminals will be created in the current workspace directory, however if you change directories in a terminal it will then have a different working directory; changing directories in a terminal does not modify the workspace directory, because you do not have access to change the workspace directory. When the user initially gives you a task, a recursive list of all filepaths in the current workspace directory ('/test/path') will be included in environment_details. This provides an overview of the project's file structure, offering key insights into the project from directory/file names (how developers conceptualize and organize their code) and file extensions (the language used). This can also guide decision-making on which files to explore further. If you need to further explore directories such as outside the current workspace directory, you can use the list_files tool. If you pass 'true' for the recursive parameter, it will list files recursively. Otherwise, it will list files at the top level, which is better suited for generic directories where you don't necessarily need the nested structure, like the Desktop. ==== diff --git a/src/core/prompts/__tests__/__snapshots__/system-prompt/with-different-viewport-size.snap b/src/core/prompts/__tests__/__snapshots__/system-prompt/with-different-viewport-size.snap index 6ccccedefeb..51253b4370f 100644 --- a/src/core/prompts/__tests__/__snapshots__/system-prompt/with-different-viewport-size.snap +++ b/src/core/prompts/__tests__/__snapshots__/system-prompt/with-different-viewport-size.snap @@ -576,6 +576,16 @@ Default Shell: /bin/zsh Home Directory: /home/user Current Workspace Directory: /test/path +**Platform-Specific Terminal Context (Linux Zsh):** +- Use Unix/POSIX commands: ls, cp, mv, rm, mkdir, rmdir +- Use forward slashes (/) for path separators +- Use Zsh-specific features: extended globbing, parameter expansion +- Use Linux-specific commands: systemctl, journalctl, ps, top, htop +- Use package managers: apt, yum, dnf, pacman, zypper (distribution-specific) +- Chain commands with && (success) or || (failure) or ; (always) +- Use Unix environment variables: $PATH, $HOME, $USER +- Use Zsh redirection: > for output, 2>/dev/null for error suppression + The Current Workspace Directory is the active VS Code project directory, and is therefore the default directory for all tool operations. New terminals will be created in the current workspace directory, however if you change directories in a terminal it will then have a different working directory; changing directories in a terminal does not modify the workspace directory, because you do not have access to change the workspace directory. When the user initially gives you a task, a recursive list of all filepaths in the current workspace directory ('/test/path') will be included in environment_details. This provides an overview of the project's file structure, offering key insights into the project from directory/file names (how developers conceptualize and organize their code) and file extensions (the language used). This can also guide decision-making on which files to explore further. If you need to further explore directories such as outside the current workspace directory, you can use the list_files tool. If you pass 'true' for the recursive parameter, it will list files recursively. Otherwise, it will list files at the top level, which is better suited for generic directories where you don't necessarily need the nested structure, like the Desktop. ==== diff --git a/src/core/prompts/__tests__/__snapshots__/system-prompt/with-mcp-hub-provided.snap b/src/core/prompts/__tests__/__snapshots__/system-prompt/with-mcp-hub-provided.snap index fd8ef4dc983..da186b7f781 100644 --- a/src/core/prompts/__tests__/__snapshots__/system-prompt/with-mcp-hub-provided.snap +++ b/src/core/prompts/__tests__/__snapshots__/system-prompt/with-mcp-hub-provided.snap @@ -588,6 +588,16 @@ Default Shell: /bin/zsh Home Directory: /home/user Current Workspace Directory: /test/path +**Platform-Specific Terminal Context (Linux Zsh):** +- Use Unix/POSIX commands: ls, cp, mv, rm, mkdir, rmdir +- Use forward slashes (/) for path separators +- Use Zsh-specific features: extended globbing, parameter expansion +- Use Linux-specific commands: systemctl, journalctl, ps, top, htop +- Use package managers: apt, yum, dnf, pacman, zypper (distribution-specific) +- Chain commands with && (success) or || (failure) or ; (always) +- Use Unix environment variables: $PATH, $HOME, $USER +- Use Zsh redirection: > for output, 2>/dev/null for error suppression + The Current Workspace Directory is the active VS Code project directory, and is therefore the default directory for all tool operations. New terminals will be created in the current workspace directory, however if you change directories in a terminal it will then have a different working directory; changing directories in a terminal does not modify the workspace directory, because you do not have access to change the workspace directory. When the user initially gives you a task, a recursive list of all filepaths in the current workspace directory ('/test/path') will be included in environment_details. This provides an overview of the project's file structure, offering key insights into the project from directory/file names (how developers conceptualize and organize their code) and file extensions (the language used). This can also guide decision-making on which files to explore further. If you need to further explore directories such as outside the current workspace directory, you can use the list_files tool. If you pass 'true' for the recursive parameter, it will list files recursively. Otherwise, it will list files at the top level, which is better suited for generic directories where you don't necessarily need the nested structure, like the Desktop. ==== diff --git a/src/core/prompts/__tests__/__snapshots__/system-prompt/with-undefined-mcp-hub.snap b/src/core/prompts/__tests__/__snapshots__/system-prompt/with-undefined-mcp-hub.snap index e80857d354d..aafe6c4f0ba 100644 --- a/src/core/prompts/__tests__/__snapshots__/system-prompt/with-undefined-mcp-hub.snap +++ b/src/core/prompts/__tests__/__snapshots__/system-prompt/with-undefined-mcp-hub.snap @@ -520,6 +520,16 @@ Default Shell: /bin/zsh Home Directory: /home/user Current Workspace Directory: /test/path +**Platform-Specific Terminal Context (Linux Zsh):** +- Use Unix/POSIX commands: ls, cp, mv, rm, mkdir, rmdir +- Use forward slashes (/) for path separators +- Use Zsh-specific features: extended globbing, parameter expansion +- Use Linux-specific commands: systemctl, journalctl, ps, top, htop +- Use package managers: apt, yum, dnf, pacman, zypper (distribution-specific) +- Chain commands with && (success) or || (failure) or ; (always) +- Use Unix environment variables: $PATH, $HOME, $USER +- Use Zsh redirection: > for output, 2>/dev/null for error suppression + The Current Workspace Directory is the active VS Code project directory, and is therefore the default directory for all tool operations. New terminals will be created in the current workspace directory, however if you change directories in a terminal it will then have a different working directory; changing directories in a terminal does not modify the workspace directory, because you do not have access to change the workspace directory. When the user initially gives you a task, a recursive list of all filepaths in the current workspace directory ('/test/path') will be included in environment_details. This provides an overview of the project's file structure, offering key insights into the project from directory/file names (how developers conceptualize and organize their code) and file extensions (the language used). This can also guide decision-making on which files to explore further. If you need to further explore directories such as outside the current workspace directory, you can use the list_files tool. If you pass 'true' for the recursive parameter, it will list files recursively. Otherwise, it will list files at the top level, which is better suited for generic directories where you don't necessarily need the nested structure, like the Desktop. ==== diff --git a/src/core/prompts/sections/system-info.ts b/src/core/prompts/sections/system-info.ts index 8adc90a160e..76436b2fdb8 100644 --- a/src/core/prompts/sections/system-info.ts +++ b/src/core/prompts/sections/system-info.ts @@ -3,7 +3,90 @@ import osName from "os-name" import { getShell } from "../../../utils/shell" +function getPlatformSpecificTerminalGuidance(): string { + const platform = os.platform() + const shell = getShell() + + if (platform === "win32") { + // Windows-specific guidance + if (shell.toLowerCase().includes("powershell") || shell.toLowerCase().includes("pwsh")) { + return ` +**Platform-Specific Terminal Context (Windows PowerShell):** +- Use PowerShell cmdlets and syntax (e.g., Get-ChildItem instead of ls, Set-Location instead of cd) +- Use PowerShell operators: -eq, -ne, -like, -match for comparisons +- Use PowerShell path separators: backslashes or forward slashes (both work) +- For file operations: Copy-Item, Move-Item, Remove-Item, New-Item +- For process management: Get-Process, Stop-Process, Start-Process +- Use PowerShell variables with $ prefix: $env:PATH, $PSVersionTable +- Chain commands with semicolons (;) or pipeline operators (|) +- Use PowerShell-specific redirection: > for output, 2>&1 for error redirection` + } else { + return ` +**Platform-Specific Terminal Context (Windows Command Prompt):** +- Use Windows CMD commands: dir, copy, move, del, md, rd +- Use Windows path separators: backslashes (\\) +- Use Windows environment variables: %PATH%, %USERPROFILE%, %TEMP% +- Chain commands with && (success) or || (failure) or & (always) +- Use Windows-specific tools: where, findstr, tasklist, taskkill +- For file operations: copy, xcopy, robocopy, del, ren +- Use CMD redirection: > for output, 2>nul for error suppression` + } + } else if (platform === "darwin") { + // macOS-specific guidance + if (shell.includes("zsh")) { + return ` +**Platform-Specific Terminal Context (macOS Zsh):** +- Use Unix/POSIX commands: ls, cp, mv, rm, mkdir, rmdir +- Use forward slashes (/) for path separators +- Use Zsh-specific features: extended globbing, parameter expansion +- Use macOS-specific commands: open, pbcopy, pbpaste, say, osascript +- Use Homebrew package manager commands: brew install, brew update +- Chain commands with && (success) or || (failure) or ; (always) +- Use Unix environment variables: $PATH, $HOME, $USER +- Use Zsh redirection: > for output, 2>/dev/null for error suppression` + } else { + return ` +**Platform-Specific Terminal Context (macOS Bash):** +- Use Unix/POSIX commands: ls, cp, mv, rm, mkdir, rmdir +- Use forward slashes (/) for path separators +- Use Bash-specific features: arrays, functions, conditionals +- Use macOS-specific commands: open, pbcopy, pbpaste, say, osascript +- Use package managers: brew (Homebrew), port (MacPorts) +- Chain commands with && (success) or || (failure) or ; (always) +- Use Unix environment variables: $PATH, $HOME, $USER +- Use Bash redirection: > for output, 2>/dev/null for error suppression` + } + } else { + // Linux and other Unix-like systems + if (shell.includes("zsh")) { + return ` +**Platform-Specific Terminal Context (Linux Zsh):** +- Use Unix/POSIX commands: ls, cp, mv, rm, mkdir, rmdir +- Use forward slashes (/) for path separators +- Use Zsh-specific features: extended globbing, parameter expansion +- Use Linux-specific commands: systemctl, journalctl, ps, top, htop +- Use package managers: apt, yum, dnf, pacman, zypper (distribution-specific) +- Chain commands with && (success) or || (failure) or ; (always) +- Use Unix environment variables: $PATH, $HOME, $USER +- Use Zsh redirection: > for output, 2>/dev/null for error suppression` + } else { + return ` +**Platform-Specific Terminal Context (Linux Bash):** +- Use Unix/POSIX commands: ls, cp, mv, rm, mkdir, rmdir +- Use forward slashes (/) for path separators +- Use Bash-specific features: arrays, functions, conditionals +- Use Linux-specific commands: systemctl, journalctl, ps, top, htop +- Use package managers: apt, yum, dnf, pacman, zypper (distribution-specific) +- Chain commands with && (success) or || (failure) or ; (always) +- Use Unix environment variables: $PATH, $HOME, $USER +- Use Bash redirection: > for output, 2>/dev/null for error suppression` + } + } +} + export function getSystemInfoSection(cwd: string): string { + const platformGuidance = getPlatformSpecificTerminalGuidance() + let details = `==== SYSTEM INFORMATION @@ -12,6 +95,7 @@ Operating System: ${osName()} Default Shell: ${getShell()} Home Directory: ${os.homedir().toPosix()} Current Workspace Directory: ${cwd.toPosix()} +${platformGuidance} The Current Workspace Directory is the active VS Code project directory, and is therefore the default directory for all tool operations. New terminals will be created in the current workspace directory, however if you change directories in a terminal it will then have a different working directory; changing directories in a terminal does not modify the workspace directory, because you do not have access to change the workspace directory. When the user initially gives you a task, a recursive list of all filepaths in the current workspace directory ('/test/path') will be included in environment_details. This provides an overview of the project's file structure, offering key insights into the project from directory/file names (how developers conceptualize and organize their code) and file extensions (the language used). This can also guide decision-making on which files to explore further. If you need to further explore directories such as outside the current workspace directory, you can use the list_files tool. If you pass 'true' for the recursive parameter, it will list files recursively. Otherwise, it will list files at the top level, which is better suited for generic directories where you don't necessarily need the nested structure, like the Desktop.` diff --git a/src/core/prompts/tools/execute-command.ts b/src/core/prompts/tools/execute-command.ts index c1fc1ea3f19..14252299acd 100644 --- a/src/core/prompts/tools/execute-command.ts +++ b/src/core/prompts/tools/execute-command.ts @@ -1,10 +1,69 @@ +import os from "os" +import { getShell } from "../../../utils/shell" import { ToolArgs } from "./types" +function getPlatformSpecificExamples(): string { + const platform = os.platform() + const shell = getShell() + + if (platform === "win32") { + if (shell.toLowerCase().includes("powershell") || shell.toLowerCase().includes("pwsh")) { + return ` +**Platform-Specific Examples (Windows PowerShell):** + +Get-ChildItem -Path . -Recurse -Name "*.js" + + + +Copy-Item -Path "./source.txt" -Destination "./backup.txt" + + + +npm install; npm run build +` + } else { + return ` +**Platform-Specific Examples (Windows Command Prompt):** + +dir /s /b *.js + + + +copy ".\\source.txt" ".\\backup.txt" + + + +npm install && npm run build +` + } + } else { + // Unix-like systems (macOS, Linux) + return ` +**Platform-Specific Examples (Unix/Linux):** + +find . -name "*.js" -type f + + + +cp ./source.txt ./backup.txt + + + +npm install && npm run build +` + } +} + export function getExecuteCommandDescription(args: ToolArgs): string | undefined { + const platformExamples = getPlatformSpecificExamples() + return `## 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, e.g: \`touch ./testdata/example.file\`, \`dir ./examples/model1/data/yaml\`, or \`go test ./cmd/front --config ./cmd/front/config.yml\`. If directed by the user, you may open a terminal in a different directory by using the \`cwd\` parameter. + +**IMPORTANT:** Always use commands appropriate for the current platform and shell. Refer to the Platform-Specific Terminal Context in the SYSTEM INFORMATION section for guidance on the correct syntax, commands, and conventions for your environment. + 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. +- command: (required) The CLI command to execute. This should be valid for the current operating system and shell. Ensure the command is properly formatted and does not contain any harmful instructions. - cwd: (optional) The working directory to execute the command in (default: ${args.cwd}) Usage: @@ -17,9 +76,10 @@ Example: Requesting to execute npm run dev npm run dev -Example: Requesting to execute ls in a specific directory if directed +Example: Requesting to execute directory listing in a specific directory ls -la /home/user/projects -` + +${platformExamples}` }