prompt-base-windows.md.hbs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. ## Windows Shell Constraints
  2. ### PowerShell only
  3. - Use **PowerShell syntax only**. Do NOT use legacy DOS / `cmd.exe` commands (`cmd`, `cmd /c`,
  4. `dir`, `type`, `copy`, `move`, `del`, `erase`, `rd`, `rmdir`, etc.). Use full PowerShell
  5. cmdlets instead (`Get-ChildItem`, `Copy-Item`, `Move-Item`, `New-Item`).
  6. - The bash tool already runs the command through the selected Windows shell. Do not wrap ordinary
  7. bash-tool commands in `powershell -Command`. If you truly must launch a nested `pwsh`/PowerShell
  8. process, prefer `pwsh -NoProfile -NonInteractive -Command '<script>'` and keep the outer
  9. `-Command` payload single-quoted so `$variables` are not expanded by the parent PowerShell.
  10. - For deletion, do not use shell delete commands; use the Trash tool or move files to a backup
  11. location.
  12. - For multi-statement PowerShell scripts, start with `$ErrorActionPreference = 'Stop'`. When the
  13. script runs native programs and must fail on non-zero exit codes, set
  14. `$PSNativeCommandUseErrorActionPreference = $true` when available, or check `$LASTEXITCODE`
  15. explicitly after the native command.
  16. - Do NOT use Bash-style `\"` to escape double quotes inside PowerShell strings. Use PowerShell
  17. quoting rules: single quotes for literal text, doubled single quotes inside single-quoted strings,
  18. double quotes only when interpolation is intended, and the backtick only for PowerShell escapes.
  19. - Wrap regex/search patterns in single quotes, especially for `rg` / `Select-String` patterns
  20. containing `|`, `(`, `)`, `\`, `$`, or other PowerShell metacharacters. Prefer the dedicated
  21. grep tool for repository searches; when shell search is necessary, keep the command simple and
  22. split complex pipelines into separate tool calls.
  23. ### File content operations — encoding safety
  24. - **Prefer the Read / Write / Edit tools for focused file reads and edits** — they operate directly
  25. in UTF-8 and bypass shell encoding issues entirely. This is the default approach for ordinary
  26. file content work; use the batch-edit exception below when dedicated tools are not efficient.
  27. - **Do NOT use `Get-Content | … | Set-Content` pipelines to modify file contents.** Windows
  28. PowerShell 5.1 defaults to the system ANSI code page (e.g. GBK / CP936 on Chinese Windows).
  29. Without `-Encoding UTF8`, `Get-Content` silently mis-decodes UTF-8 multi-byte characters as
  30. ANSI, and `Set-Content` writes the corrupted data back — destroying CJK comments, strings,
  31. and even line structure in source files. The corruption is **silent** (no error, no warning).
  32. - If you must use `Get-Content` or `Set-Content` in a shell command (e.g. reading a small config
  33. value), **always** pass `-Encoding UTF8`. Be aware that PowerShell 5.1's `-Encoding UTF8`
  34. adds a BOM (`EF BB BF`), which may affect some tools.
  35. - For batch file modifications that dedicated tools cannot express efficiently, generate a
  36. **Python script** (with `encoding='utf-8'`) instead of a PowerShell pipeline.
  37. ### Deliverable verification
  38. - To verify that a local deliverable exists before sending it, use
  39. `Test-Path -Path <path> -PathType Leaf` or read the file back.