nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Bug] The documented formatter command "$FILE" silently does nothing on Windows

Open addyCooks opened this issue 1 month ago • 2 comments

Description

The formatter docs tell users to write commands like npx biome format --write "$FILE". On Windows, formatter and hook commands run through cmd.exe (shell: true), and cmd.exe expands %FILE%, not $FILE. So the formatter receives the literal text $FILE, the file stays unformatted, and the tool result says nothing. The docs only mention cmd.exe once, and every example is written for sh.

Environment

  • OS: Windows 11 (10.0.26300)
  • Node version: 22.22.3
  • Nanocoder version: 1.31.0 (main at 6eaff7af)
  • Provider / Model: not relevant (reproduced by calling formatWrittenFile directly)

Steps to Reproduce

  1. On Windows, create a project with fmt.js. It saves its first argument to formatter-received.txt and upper-cases that file if it exists.
  2. Add to agents.config.json: {"nanocoder": {"formatters": [{"match": ["**/*.js"], "command": "node fmt.js \"$FILE\"", "name": "fmt"}]}}.
  3. Let the agent write a.js.
  4. Change the command to node fmt.js \"%FILE%\" and repeat.

Expected Behavior

The command shown in the docs formats the file, or the docs show the form that works on Windows.

Actual Behavior

With "$FILE" the formatter gets the literal text and the file is not touched:

command : node fmt.js "$FILE"
received: argv[2]="$FILE"
file now: "const hello = \"world\";\n"
tool note: "File written."

With "%FILE%" it works:

command : node fmt.js "%FILE%"
received: argv[2]="C:\\...\\proj\\a.js"
file now: "CONST HELLO = \"WORLD\";\n"
tool note: "File written.\n\nNote: a.js was reformatted by fmt. ..."

Suggested Fix

  • Docs: in docs/configuration/index.md (examples at lines 455-456, explanation at line 462) and docs/features/hooks.md (line 67 and the examples), add a short Windows note: use "%FILE%" and "%NANOCODER_FILE%" on Windows, or run a script with node script.js.
  • Code, optional: source/services/formatters.ts (the env block near the runHookCommand call) only passes the path through environment variables. It could also substitute $FILE itself, but be careful to quote it safely. The comment in source/services/lifecycle-hooks.ts:563-567 explains why only hook.command may be parsed by the shell.
  • Add a Windows-only test like the one above, based on source/services/formatters.spec.ts.

Additional Context

  • Formatters came from #1567 and #1483. Related: #1652 (formatter errors are only written to the log in run mode).
  • I used a stand-in script, not Biome. Hook commands use the same runner, so $NANOCODER_FILE in docs/features/hooks.md should have the same problem. I did not test hooks separately.
  • [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

addyCooks avatar Oct 09 '26 18:10 addyCooks

I'd like to pick this up — planning to substitute $FILE with a properly quoted path before running the formatter (following the cmd.exe quoting from #1108), so it works on Windows without changing POSIX behaviour. Will open a PR shortly.

TheNetherWatcher avatar Oct 09 '26 19:10 TheNetherWatcher

Thanks @TheNetherWatcher for the fix in #1693, gonna review it this time. For next time: please comment on an issue and wait to be assigned before opening a PR, even for a small fix. It keeps two people from working on the same thing.

addyCooks avatar Oct 12 '26 09:10 addyCooks