Repository navigation
fix(windows): make CLI importable under Git Bash / MSYS - #2
Conversation
The CLI passed the shell-resolved engine path straight to Node's ESM
loader. On Windows that path is `/c/...`, so `await import("/c/...")`
throws ERR_UNSUPPORTED_ESM_URL_SCHEME because `c:` is parsed as a URL
protocol. Every such call site redirects stderr to /dev/null, so the
failure surfaced as "未找到 Jev 凭证 (exit 3)" even when the key file was
present and valid — a very expensive misdiagnosis.
Same class of bug on the temp directory: `mktemp -d` returns `/c/tmp/x`,
which ego's embedded node resolves to `C:\tmp\x`, so config.json written
by the parent was invisible to the child.
Changes:
- add _lib_to_url(): derives a file:// URL for import() only, leaving
the real path for [ -f ] checks. Handles /c/x, C:/x, already-file://
input (idempotent), and backslash normalization; POSIX is unchanged.
- route all four import() call sites through LIB_URL.
- convert $TMPD with `cygpath -m` on MSYS/Cygwin so both bash and the
embedded node resolve the same file.
- add bench/test-windows-paths.mjs: asserts every import() site uses
LIB_URL and exercises the conversion table with a stubbed uname, so
the Windows branches are covered on CI running Linux/macOS too.
Verified on Windows 11 + ego lite 0.6.0.16 (Cygwin/MSYS bash):
before, the README verification command exited 3 with "no credentials";
after, it exits 0 with success:true and jev_done.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1f8215f2a2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| file://*) printf '%s' "$p"; return 0 ;; # 调用方已给 URL,原样用 | ||
| esac | ||
| case "$(uname -s 2>/dev/null)" in | ||
| MINGW*|MSBUILD*|CYGWIN*) |
There was a problem hiding this comment.
Match the actual MSYS uname prefix
When this runs in a native MSYS shell, uname -s reports MSYS_NT-*, so this selector falls through because MSBUILD* is a different prefix; the same typo is repeated in the temporary-directory selector at lines 379-380. In that environment neither LIB_URL nor TMPD is converted, leaving both Windows failures this change is intended to fix, so both selectors need to match MSYS*.
Useful? React with 👍 / 👎.
| MINGW*|MSBUILD*|CYGWIN*) | ||
| # /c/x → C:/x(盘符大写);已有盘符的不动 | ||
| case "$p" in | ||
| /[A-Za-z]/*) p="$(printf '%s' "${p:1:1}" | tr '[:lower:]' '[:upper:]'):${p:2}" ;; |
There was a problem hiding this comment.
Convert Cygwin's default cygdrive paths
On a default Cygwin installation, SCRIPT_DIR and LIB use /cygdrive/c/..., but this rewrite only handles the /c/... form. Although the outer branch recognizes CYGWIN*, the resulting URL becomes file:////cygdrive/c/..., which native Windows Node does not map to the C: drive, so every engine import still fails; convert the path with cygpath -m or explicitly handle /cygdrive/<drive>/....
Useful? React with 👍 / 👎.
| /[A-Za-z]/*) p="$(printf '%s' "${p:1:1}" | tr '[:lower:]' '[:upper:]'):${p:2}" ;; | ||
| esac | ||
| p="${p//\\//}" | ||
| printf 'file:///%s' "$p" |
There was a problem hiding this comment.
Encode reserved characters when forming file URLs
For a valid Windows install path containing # or % (for example C:/work#1/...), concatenating the raw path emits a URL such as file:///C:/work#1/...; Node interprets #1/... as a fragment (and malformed percent escapes also fail), so the engine exists but the preflight import reports a credential error. Use a URL-aware conversion such as pathToFileURL rather than assembling the file URL as text.
Useful? React with 👍 / 👎.
| // | ||
| // 做法:不重实现一遍 shell 逻辑,而是把 CLI 里的 _lib_to_url 抽出来写进临时脚本执行, | ||
| // 这样测试与实现不会各自漂移。所有 Windows 用例都显式固定 uname 分支, | ||
| // 保证在 Linux / macOS 上跑也能覆盖 Windows 路径(否则这些分支永远测不到)。 |
There was a problem hiding this comment.
Execute the new Windows-path regression test in CI
The test claims Linux/macOS CI will exercise the Windows branches, but the unit-test step in .github/workflows/ci.yml lines 47-53 never invokes bench/test-windows-paths.mjs; the earlier loop only runs node --check, which does not execute these assertions. As a result, regressions such as an incorrect OS pattern pass every push and PR despite this test being offline and dependency-free.
Useful? React with 👍 / 👎.
Four findings from the automated review, all verified and fixed: 1. P1 — `MSBUILD*` was a typo for `MSYS*`. Native MSYS reports `MSYS_NT-*`, so on a real MSYS shell neither LIB_URL nor TMPD was converted and both original Windows failures remained. This machine happens to report `MINGW64_NT`, which is why the bug did not show up in my own testing. 2. P1 — default Cygwin mounts use `/cygdrive/c/...`, which the `/[A-Za-z]/*` rule never matched, producing `file:////cygdrive/c/...`. Now normalized explicitly. Note cygpath cannot be trusted alone here: on a Git Bash host without a /cygdrive mount it treats the path as relative and prepends cwd (observed: it produced `<bash-root>/cygdrive/c/...`), so the cygdrive prefix is rewritten before cygpath runs. 3. P2 — building the URL by string concatenation broke paths containing `#`, `%`, spaces or non-ASCII (a user directory like `C:/work#1` became a URL with a fragment, losing the real path). Now delegated to `node:url` pathToFileURL, which encodes per spec (verified against a CJK path). A manual percent-escape fallback remains for the case where node is not on PATH. 4. P2 — the new test was never executed by CI: the workflow lists test files explicitly and had no `node --check`-only coverage for this one, so it was dead weight. Added to the unit-test step. Tests: 19 assertions, 19 pass / 0 fail (was 13). New cases cover the MSYS_NT prefix, /cygdrive/c/..., `#`, spaces, and a CJK path. The cygdrive and encoding cases are the ones that actually caught two of these bugs. End-to-end unchanged: exit 0, success:true, jev_done.
|
Thanks — all four findings were correct. Verified each against the actual code, fixed all of them in 5c1cf53. P1 P1 P2 URL encoding — Confirmed, and it is the more dangerous one since a valid install path like P2 test not run in CI — Confirmed and arguably the worst of the four: the workflow enumerates test files explicitly, so my new test was dead weight and a broken OS pattern would have passed CI green. Added to the unit-test step. Tests went 13 → 19 assertions, all passing. The cygdrive and encoding cases each caught a real bug in my own code, so they were worth writing. One thing I did not change: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5c1cf53e8d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (fnMatch) { | ||
| const dir = mkdtempSync(join(tmpdir(), "ego-decision-layer-winpath-")); | ||
| // 把 uname 换成可控桩:用 $FAKE_OS 固定分支,真实调用链不变 | ||
| const stubbed = fnMatch[0].replace(/\$\(uname -s 2>\/dev\/null\)/g, '"${FAKE_OS:-$(uname -s 2>/dev/null)}"'); |
There was a problem hiding this comment.
Simulate Windows URL semantics in the cross-platform test
On the workflow's ubuntu-latest runner, replacing only uname enters the Windows branch while the spawned node still applies POSIX pathToFileURL semantics, so C:/Users/... becomes file:///workspace/ego-decision-layer/C:/Users/.... I ran node bench/test-windows-paths.mjs in this environment and it reports 11 passing / 8 failing; because .github/workflows/ci.yml:54 now executes this test, every push and PR job fails until the conversion is made host-independent or the probe also stubs the Node platform behavior.
Useful? React with 👍 / 👎.
The previous commit delegated URL encoding to `node:url` pathToFileURL. That function resolves paths using the *host platform* semantics, so on the ubuntu-latest CI runner `C:/Users/...` is treated as a relative path and becomes `file:///home/runner/work/.../C:/Users/...`. Combined with the previous commit wiring the test into CI, that would have failed every push. Now the encoding is a pure string transform: percent-encode anything outside the URL path safe set, leave the rest alone. The input is already normalized to `C:/...` before this point, so the result no longer depends on which OS node runs on. Verified the exact failure mode reported in review: pathToFileURL, posix host → file:///home/runner/work/repo/repo/C:/... string encode, any host → file:///C:/Users/someuser/x.mjs Tests: 19/19 passing. End-to-end unchanged (exit 0, jev_done).
|
Good catch on round 2. Three of the four P1/P2 items from round 1 were already addressed in 5c1cf53; the fifth finding is new and it was a genuine regression I introduced — fixed in 131a01f. Re: And because 5c1cf53 also wired this test into Fix: dropped To be clear about the other three, since they reappear in this round's list — their line numbers now point at
Current state: 19/19 assertions pass, end-to-end exits 0 with One honest limitation worth flagging: I have no Linux host here (no WSL, no docker), so I verified the platform-independence by reproducing the posix |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 131a01f341
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| # Windows(Git Bash / MSYS)下 mktemp 给的是 /c/tmp/...,而 ego 的内嵌 node 会把同一串解析成 | ||
| # C:\tmp\...,父进程写好的 config.json 在子进程里就找不到了。转成混合路径(C:/tmp/...)两边都认。 | ||
| case "$(uname -s 2>/dev/null)" in | ||
| MINGW*|MSYS*|CYGWIN*) TMPD="$(cygpath -m "$TMPD" 2>/dev/null || printf '%s' "$TMPD")" ;; |
There was a problem hiding this comment.
Convert the cache path before entering the child runtime
On Git Bash/MSYS/Cygwin when the default cache is enabled, this converts only TMPD; JEV_CACHE_FILE is still populated below from $HOME/.config/... (typically /c/Users/... or /home/...) and serialized as cfg.cacheFile. The embedded Windows Node resolves that to the wrong drive-root path, and ActionCache.load()/save() swallow the resulting filesystem errors, so Windows runs silently lose the default persistent action cache (or write it under the wrong root); convert this child-visible path with cygpath -m as well.
Useful? React with 👍 / 👎.
| href="$(node -e ' | ||
| const p = process.argv[1]; | ||
| // 保留 URL 路径中合法的字符(含盘符冒号与分隔斜杠),其余按 UTF-8 百分号编码 | ||
| process.stdout.write("file:///" + p.replace(/[^A-Za-z0-9\/._~:@!$&()*+,;=-]/gu, (c) => encodeURIComponent(c))); |
There was a problem hiding this comment.
Preserve the UNC authority when building file URLs
When the skill or repository is installed on a UNC share, cygpath -m leaves LIB in the form //server/share/..., but this unconditional prefix produces file://///server/share/... with an empty URL host. Windows Node rejects that form as an invalid absolute file URL, so all engine imports still fail for network-share installs; detect the leading //host/share form and emit file://host/share/... while encoding the path components.
Useful? React with 👍 / 👎.
Share Windows runtime path normalization between engine imports, temporary configuration files and persistent action caches. Preserve UNC server names when encoding file URLs, and pass encoder input through the environment to avoid MSYS argument conversion. Extend path regression coverage from 19 to 36 checks, including UNC paths, Cygwin home mounts, cache overrides and reserved characters. Fix the existing shell-variable comment check so the full offline CI unit suite passes.
|
Thanks for the contribution and the Windows testing so far! I've pushed the remaining cache-path and UNC fixes in I don't have a Windows environment available, so I can't independently verify the latest changes on Windows. Could you please pull the latest Please check:
Please include the shell/Node/ego versions and the commands, exit codes, and results (without credentials). Once you've confirmed the latest changes work on Windows, we'll merge this PR. |
|
在 Windows 上测了 环境1. 路径回归测试:通过包含新增的 UNC、Cygwin home 挂载、缓存覆盖和保留字符用例。 2. Wikipedia CLI 冒烟测试(默认缓存):通过这里用 3. 缓存位置、复用与覆盖:通过默认路径是
4. UNC:逻辑已验证,端到端未执行本机没有可达的网络共享。 所以我在隔离环境里验证转换链,没有把它算作通过: 服务器名作为 URL authority 保留下来,Node 能把它映射回 UNC 路径。编码器还会拒绝非法 host( 按你说的,这一项请视为仅由回归测试覆盖。 另外检查拉取 关于你的改动:把编码器入参从 |
|
感谢你的贡献!也特别感谢你耐心跟进几轮审查,并在 Windows 真机上补齐路径回归、默认缓存复用和自定义缓存位置的验证,帮助我们覆盖了本地没有的环境。UNC 端到端尚未验证的限制也说明得很清楚。PR 已合并,本地也已同步。谢谢这次细致、扎实的修复与测试! |
问题
CLI 把 shell 解析出的引擎路径直接交给 Node 的 ESM 加载器。Windows(Git Bash / MSYS / Cygwin)下该路径是
/c/...,await import("/c/...")会抛ERR_UNSUPPORTED_ESM_URL_SCHEME——c:被当成 URL 协议名。由于这几处调用都把 stderr 重定向到
/dev/null,真实错误被吞掉,症状表现为:而凭证文件其实存在且有效(
curl直连api.typesafe.ai/v1/systemone返回 200)。这条误诊线索具有很强的误导性——排查时很容易先去怀疑凭证链。同一类问题还出现在临时目录上:
mktemp -d返回/c/tmp/xxx,ego 的内嵌 node 把同一串解析成C:\tmp\xxx,于是父进程写好的config.json在子进程里读不到:改动
_lib_to_url():只为import()派生file://URL,文件存在性检查仍用真实路径。覆盖/c/x、C:/x、已是file://的输入(幂等)、反斜杠归一化;POSIX 行为完全不变。import()调用点全部改走LIB_URL(凭证前置检查、抽取 schema 校验、抽取 model 校验、主 heredoc)。$TMPD在 MSYS/Cygwin 下经cygpath -m转换,使 bash 与内嵌 node 解析到同一个文件。bench/test-windows-paths.mjs:断言所有import()点都用LIB_URL,并用 stub 掉的uname跑一遍路径转换表——这样跑在 Linux/macOS 上的 CI 也能覆盖 Windows 分支,不会因为宿主不同而永远测不到。验证
环境:Windows 11 + ego lite 0.6.0.16(Cygwin/MSYS bash)、Node v24.20.0。
端到端,README 里那条验证命令:
未找到 Jev 凭证(误报,key 有效)success: true,reason: jev_done, 落到/wiki/Jev另外确认路由接管不受影响:
wire-agent-skills.sh --checkexit 0(接管 2 / 无需 3 / 漂移 0)。范围
只动
scripts/ego-decision-layer与新增测试文件。没有触碰 app 包内任何内容,也没有改变 Linux/macOS 下的路径解析结果。附注(与本 PR 无关,供参考)
bench/test-offline-e2e.mjs与bench/test-*.mjs里import(ROOT + "/bench/lib.mjs")的写法在 Windows 上同样会失败(ROOT是/c/...),那一批脚本需要各自传file://或用pathToFileURL。如果你们希望一并处理,我可以另开一个 PR 专门收敛 bench 层的路径处理。