[Bug] Windows path checks are case-sensitive: a trusted folder is untrusted under another spelling, and file tools reject valid paths
Description
Windows paths are case-insensitive, but Nanocoder compares them as plain text. path.resolve keeps the drive letter and folder case as given, and then === and startsWith are used. So c:\work\proj and C:\Work\Proj look like different folders. A folder you already trusted shows the trust prompt again, and file tools throw Invalid file path for a correct absolute path that only differs in case.
Environment
- OS: Windows 11 (10.0.26300)
- Node version: 22.22.3
- Nanocoder version: 1.31.0 (main at 6eaff7af)
- Provider: Ollama
- Model: qwen2.5:1.5b
Steps to Reproduce
- Trust a folder:
cd C:\Work\Proj, thenset NANOCODER_TRUST_DIRECTORY=1and runnanocoder run "hi". - Run
nanocoder run "hi"from the same folder, but with the working directory spelledc:\Work\Proj(lowercase drive letter only). - Run it again from
c:\work\proj(all lowercase). - In a session started in
C:\Work\Proj, ask a file tool to readc:\Work\Proj\a.txt.
Expected Behavior
All spellings are treated as the same folder. The folder stays trusted and the file is read.
Actual Behavior
Step 1 saves C:\...\Proj to trustedDirectories. Steps 2 and 3 are refused:
Directory c:\Users\...\n12\Proj is not trusted. Pass --trust-directory or set NANOCODER_TRUS...
The same folder from its original spelling still runs. Step 4 throws Invalid file path: c:\Users\...\a.txt. These unit-level checks also fail:
isPathInside("c:\...\ZZ-N12-xxxx\a.txt", "C:\...\ZZ-N12-xxxx") -> false
resolveFilePath("c:\...\ZZ-N12-xxxx\a.txt", "C:\...\ZZ-N12-xxxx") -> throws Invalid file path
isDirectoryTrusted("c:\work\proj", {trustedDirectories: ["C:\Work\Proj"]}) -> false
Suggested Fix
- Add one helper, for example
normalizeForCompare(p):path.resolve(p), lowercased onwin32. - Use it in
isPathInside(source/utils/path-validation.ts:184-194, which also feedsisValidFilePathandresolveFilePath), inisDirectoryTrusted(source/config/preferences.ts, around lines 176-184) and inisProjectTrusted(source/plugins/host.ts, around lines 60-66). - Keep the stored value as the user's original spelling; only compare in the normalized form.
- Add Windows-only tests like the three above.
Additional Context
- Related: #1240 (drive roots, closed), #1636 (symlinks). Open PR #1676 changes the same trust functions, so coordinate with it.
plugins/host.tsuses the same comparison; I read it but did not run the VS Code/ACP path.- [x] I have searched existing issues to ensure this is not a duplicate
- [x] I can reproduce this issue consistently
- [x] This issue occurs with the latest version of nanocoder
Hi! I have a fix ready for this: a toComparablePath helper (resolve, then lowercase on win32 only) used by isPathInside, isDirectoryTrusted and isProjectTrusted, with stored trust entries keeping the user's spelling, tests for all three, and a changeset. It was built with an AI coding assistant (Claude Code) and checked on Windows. Heads-up: it touches preferences.ts, which open PR #1676 also edits. Happy to open it now or rebase after #1676, whichever you prefer.
I can work on this one. I'd compare paths case-insensitively on Windows (normalizing drive letter and folder case after path.resolve) in both the trusted-directory check and the file tool path validation, keeping the original spelling for what's saved and shown, with tests built on path.win32 covering the spellings from your steps so they run on any OS. Could you assign me?