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

Aperta Adatta ai principianti
#5,340 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
1/5
Tempo stimato
Meno di un'ora
Idoneità per principianti
74/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
powershell

Direzione di ricerca

Individua le istruzioni integrate dello strumento PowerShell e leggi i suggerimenti esistenti per Windows su && rispetto a ; e sugli heredoc. Aggiungi indicazioni concise sull’uso di -LiteralPath per i percorsi di origine specifici, se supportato, riservando -Path alla ricerca intenzionale con caratteri jolly. Il lavoro è completo quando le indicazioni spiegano la distinzione e i cmdlet elencati per i percorsi di origine, senza far intendere che si applichi ai parametri di destinazione.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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".

Lingua principale
Python
Stelle
11.5k
Fork
2k
Merge medio
6h 34m
PR unite (30g)
3

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di github/copilot-cli

Tutte le issue di github/copilot-cli

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.