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

未关闭 适合新手
#5,340 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
1/5
预计耗时
1 小时以内
新手友好度
74/100
Issue 类型
功能
描述清晰度
描述清楚
活跃度
活跃
技术栈
powershell

调研方向

找到内置的 PowerShell 工具指南,并阅读现有的 Windows 提示,了解 && 与 ; 的区别以及 heredoc。简要补充说明:在支持的情况下,对具体的源路径使用 -LiteralPath,仅在有意进行通配符匹配时使用 -Path。当指南涵盖了这一区别及所列的源路径 cmdlet,且没有暗示这也适用于目标参数时,即为完成。

由索引模型根据 Issue 内容生成。

描述

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

主要语言
Python
星标
11.5k
派生
2k
平均合并
6 小时 34 分钟
30 天内合并 PR
3

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

github/copilot-cli 的其他 Issue

查看 github/copilot-cli 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。