( name: string, chain: string, pathSep: string, limits: Limits, defaultTimeoutMs: number, )
| 119 | } |
| 120 | |
| 121 | function powershellCommandSection( |
| 122 | name: string, |
| 123 | chain: string, |
| 124 | pathSep: string, |
| 125 | limits: Limits, |
| 126 | defaultTimeoutMs: number, |
| 127 | ) { |
| 128 | return `${powershellNotes(name)} |
| 129 | |
| 130 | Before executing the command, please follow these steps: |
| 131 | |
| 132 | 1. Directory Verification: |
| 133 | - If the command will create new directories or files, first use \`Test-Path -LiteralPath <parent>\` to verify the parent directory exists and is the correct location |
| 134 | - For example, before creating \`foo${pathSep}bar\`, first use \`Test-Path -LiteralPath "foo"\` to check that \`foo\` exists and is the intended parent directory |
| 135 | |
| 136 | 2. Command Execution: |
| 137 | - Always quote file paths that contain spaces with double quotes (e.g., Remove-Item -LiteralPath "path with spaces${pathSep}file.txt") |
| 138 | - Examples of proper quoting: |
| 139 | - New-Item -ItemType Directory -Path "My Documents" (correct) |
| 140 | - New-Item -ItemType Directory -Path My Documents (incorrect - path is split) |
| 141 | - & "path with spaces${pathSep}script.ps1" (correct) |
| 142 | - path with spaces${pathSep}script.ps1 (incorrect - path is split and not invoked) |
| 143 | - After ensuring proper quoting, execute the command. |
| 144 | - Capture the output of the command. |
| 145 | |
| 146 | Usage notes: |
| 147 | - The command argument is required. |
| 148 | - You can specify an optional timeout in milliseconds. If not specified, commands will time out after ${defaultTimeoutMs}ms. |
| 149 | - If the output exceeds ${limits.maxLines} lines or ${limits.maxBytes} bytes, it will be truncated and the full output will be written to a file. You can use Read with offset/limit to read specific sections or Grep to search the full content. Do NOT use \`Select-Object -First\`, \`Select-Object -Last\`, or other truncation commands to limit output; the full output will already be captured to a file for more precise searching. |
| 150 | |
| 151 | - Avoid using Shell with PowerShell file/content cmdlets unless explicitly instructed or when these cmdlets are truly necessary for the task. Instead, always prefer using the dedicated tools for these commands: |
| 152 | - File search: Use Glob (NOT Get-ChildItem) |
| 153 | - Content search: Use Grep (NOT Select-String) |
| 154 | - Read files: Use Read (NOT Get-Content) |
| 155 | - Edit files: Use Edit (NOT Set-Content) |
| 156 | - Write files: Use Write (NOT Set-Content/Out-File or here-strings) |
| 157 | - Communication: Output text directly (NOT Write-Output/Write-Host) |
| 158 | - When issuing multiple commands: |
| 159 | - If the commands are independent and can run in parallel, make multiple bash tool calls in a single message. For example, if you need to run "git status" and "git diff", send a single message with two bash tool calls in parallel. |
| 160 | - ${chain} |
| 161 | - Use \`;\` only when you need to run commands sequentially but don't care if earlier commands fail |
| 162 | - DO NOT use newlines to separate commands (newlines are ok in quoted strings) |
| 163 | - AVOID changing directories inside the command. Use the \`workdir\` parameter to change directories instead. |
| 164 | <good-example> |
| 165 | Use workdir="project${pathSep}subdir" with command: pytest tests |
| 166 | </good-example> |
| 167 | <bad-example> |
| 168 | ${name === "powershell" ? `Set-Location -LiteralPath "project${pathSep}subdir"; if ($?) { pytest tests }` : `Set-Location -LiteralPath "project${pathSep}subdir" && pytest tests`} |
| 169 | </bad-example>` |
| 170 | } |
| 171 | |
| 172 | function cmdCommandSection(chain: string, limits: Limits, defaultTimeoutMs: number) { |
| 173 | return `# cmd.exe shell notes |
no test coverage detected