[Windows] PowerShell tool guidance: prefer -LiteralPath for file paths (brackets are wildcards with -Path)

Aberta Para iniciantes
#5,340 0 comentários 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
1/5
Tempo estimado
Menos de uma hora
Facilidade para iniciantes
74/100
Tipo de issue
Funcionalidade
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
powershell

Direção de pesquisa

Encontre as orientações da ferramenta PowerShell integrada e leia as dicas existentes para Windows sobre && em comparação com ; e sobre heredocs. Acrescente orientações concisas para usar -LiteralPath em caminhos de origem concretos quando houver suporte e reservar -Path para correspondências intencionais com curingas. O trabalho estará concluído quando as orientações abordarem a distinção e os cmdlets listados para caminhos de origem, sem dar a entender que isso se aplica a parâmetros de destino.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

area:platform-windows area:tools
Describe the feature or problem you'd like to solve

On Windows, the agent often passes file names containing [ ] to cmdlets via -Path (the default), so PowerShell treats them as wildcards: commands fail, Test-Path returns a false negative, and Remove-Item can delete a different file.

Proposed solution

Add a line to the built-in PowerShell tool guidance, alongside the existing Windows tips (&& vs ;, no heredoc), for example:

For concrete filesystem paths, prefer -LiteralPath where supported; quoting -Path does not disable wildcard expansion ([ ] * ?). Use -Path only when wildcard matching is intentional. (This applies to source paths such as Get-Content, Set-Content, Test-Path, Remove-Item, Copy-Item, Move-Item, Rename-Item, Get-ChildItem; not to destination parameters.)

Benefit: fewer failed tool calls and retries, and it reduces the risk of acting on the wrong file (data loss with Remove-Item / Move-Item / Set-Content).

Example prompts or workflows
  1. "Rename the scans in this folder to yyyy-MM-dd format": files like scan[2].jpg fail with -Path; the agent then retries with -LiteralPath.
  2. "Delete del[2].jpg": Remove-Item -Path 'del[2].jpg' deletes del2.jpg if it exists, and the requested file stays.
  3. "Edit notes [draft].md": Set-Content -Path fails with "An object at the specified path ... does not exist".
Additional context

Repro (pwsh 7.6.9, Copilot CLI 1.0.105, Windows):

Set-Content -LiteralPath 'a[1].txt' x
Test-Path -Path 'a[1].txt'      # False (file exists)
Get-Content -Path 'a[1].txt'    # error: An object at the specified path a[1].txt does not exist...
Set-Content a1.txt y
Remove-Item -Path 'a[1].txt'    # deletes a1.txt, keeps a[1].txt

Docs: about_Wildcards and Supporting Wildcard Characters in Cmdlet Parameters / -LiteralPath.

Filed as a feature request rather than a bug: PowerShell behaves as designed; the ask is guidance for the model. No existing issue found for "LiteralPath".

Linguagem predominante
Python
Estrelas
11.5k
Forks
2k
Merge médio
6h 34min
PRs com merge (30d)
3

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de github/copilot-cli

Todas as issues de github/copilot-cli

Issues semelhantes

Mais issues de Python

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.