Copilot CLI hooks fail on Windows: command runs under PowerShell, which can't execute te-hook

未关闭
#204 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@sykuang 已经在做这个了。

开始于 2026年11月11日。

  • #206 来自 @sykuang —— 未关闭

评估

难度
3/5
预计耗时
1-2 天
新手友好度
72/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
github, powershell, python

调研方向

Read plugin/hooks/copilot-hooks.json and the existing Windows handling in the Codex manifest. Check how Copilot hook commands are configured for bash and powershell, then verify the proposed shell lookup against the Windows environments in the report. Done means all six hooks run without errors on Windows and te status shows the repository.

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

描述

Summary

On Windows, every Copilot CLI hook from the plugin fails with exit code 1, so TokenEconomizer never runs (no state under ~/.tokeneconomizer/repos/...).

plugin/hooks/copilot-hooks.json uses only command:

"command": "\"${PLUGIN_ROOT}/scripts/te-hook\" --host copilot"

Per the Copilot hooks reference, command is copied to both bash and powershell. On Windows, Copilot CLI runs the powershell variant, and PowerShell can't execute the extensionless POSIX script te-hook (Cannot run a document in the middle of a pipeline: ...\plugin\scripts\te-hook).

docs/PLUGIN.md already notes that Copilot CLI on Windows is untested, so this may be expected. I'm filing it with a verified workaround.

Environment

  • Windows 11, Copilot CLI 1.0.107 (standalone copilot.exe)
  • Git for Windows (C:\Program Files\Git); its bin\ is not on the machine PATH by default (only Git\cmd)
  • Python 3.15 via the Python install manager
  • Plugin installed from a local clone at main (marketplace add + copilot plugin install tokeneconomizer@tokeneconomizer)

Repro

  1. Install the plugin on Windows as above.
  2. In any git repo: copilot -p "Reply with just: ok"
  3. ~/.copilot/logs/process-*.log shows, once per hook:
    [ERROR] [rust:hooks] Hook from "tokeneconomizer@tokeneconomizer" execution failed: Error: Hook command failed with code 1

What I tested

Variant Normal user PATH PATH with Git bin on it
Original command ❌ 4 hook failures ❌ 4 hook failures
"command": "sh \"${PLUGIN_ROOT}/scripts/te-hook\" ..." ❌ (sh not on PATH) ✅
Split bash + powershell with sh lookup (below) ✅ ✅

A plain sh prefix isn't enough, because Git for Windows doesn't put sh.exe on PATH by default. Deriving it from git.exe alone isn't enough either: some hosts bundle a Git whose sh.exe is under usr\bin instead of bin.

Suggested fix

Keep the POSIX command as bash, and add a powershell entry that locates sh.exe (PATH first, then next to git.exe):

{
  "type": "command",
  "bash": "\"${PLUGIN_ROOT}/scripts/te-hook\" --host copilot",
  "powershell": "$s=(Get-Command sh.exe -ErrorAction SilentlyContinue).Source; if(-not $s){$g=Split-Path (Split-Path (Get-Command git.exe -ErrorAction SilentlyContinue).Source); $s=@(\"$g\\bin\\sh.exe\",\"$g\\usr\\bin\\sh.exe\") | Where-Object {Test-Path $_} | Select-Object -First 1}; & $s \"${PLUGIN_ROOT}/scripts/te-hook\" --host copilot",
  "timeoutSec": 30
}

With this applied to all 6 events, I get no hook errors, te status shows the repo, and toolprune records the catalog. A small te-hook.ps1 wrapper would be cleaner than the inline one-liner. The Codex manifest's commandWindows handling looks like the equivalent of this for Codex.

Possibly related: #167 (te launcher on Windows/Git Bash).

主要语言
Python
星标
5.6k
派生
344
平均合并
17 小时 41 分钟
30 天内合并 PR
73

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

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

microsoft/TokenEconomizer 的其他 Issue

查看 microsoft/TokenEconomizer 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

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