nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Bug] EDITOR values with arguments fail in the setup wizards, and /setup-config passes the path through a shell

Open akramcodez opened this issue 3 weeks ago • 3 comments

Description

Opening a config file in the user's editor is implemented twice with different, partly broken rules.

  • source/wizards/base-config-wizard.tsx resolves the editor name and calls spawnSync(editor, [configPath]). When EDITOR contains arguments, such as EDITOR="code --wait", spawnSync looks for a binary literally named code --wait, fails with ENOENT, and the wizard reports the misleading message "Editor exited with an error" (the exit status is null).
  • source/commands/setup-config.tsx runs execSync(`${editor} ${JSON.stringify(filePath)}`). JSON.stringify produces a double-quoted string, and in a shell double quotes still expand $(...), backticks and $VAR, so a config path containing those characters is interpreted by the shell. It also never restores the terminal after the TUI's raw mode.

The two paths also disagree on precedence and defaults: setup-config prefers EDITOR over VISUAL, defaults to vi, and special-cases TERM_PROGRAM=vscode; the wizard defaults to nano or notepad and has no VS Code handling.

Environment

  • OS: macOS (applies to Linux and Windows too)
  • Node version: v22.23.4
  • Nanocoder version: 1.32.0 (main at 1b6571cc)
  • Provider: not relevant
  • Model: not relevant

Steps to Reproduce

  1. export EDITOR="code --wait" (or EDITOR="emacsclient -t", EDITOR="subl -w").
  2. Run a setup wizard and choose to open the config in the editor.
  3. Observe the "Editor exited with an error" message and no editor window.
  4. Separately, run /setup-config 1 with a project path that contains $ or a backtick, for example a directory named a$(touch pwned)b, and observe the substitution being evaluated by the shell.

Expected Behavior

EDITOR values with arguments work in every place nanocoder launches an editor. Paths are passed as an argument, never interpolated into a shell string. There is one shared resolver with one precedence order (VISUAL, then EDITOR, then a platform default) used by both code paths.

Actual Behavior

Wizard: spawnSync returns ENOENT for EDITOR="code --wait" (verified with Node), surfaced as a generic error. /setup-config: the filename goes through a shell and is expanded (verified command substitution inside double quotes).

Logs/Screenshots

spawnSync('code --wait', ['/tmp/agents.config.json']) returns error: ENOENT and status: null.

Additional Context

  • [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

Suggested direction: split EDITOR with a small shell-words parser (or run it through the user's shell with the path passed as a positional parameter), spawn with stdio: 'inherit' and an args array, and share the helper between the wizard and /setup-config.

akramcodez avatar Nov 12 '26 14:11 akramcodez

I'd like to pick this up: I'll follow the suggested direction (parse $EDITOR/$VISUAL into command + args before spawning) and open a PR shortly with tests for the wizards and /setup-config.

pcbeingused33 avatar Nov 12 '26 18:11 pcbeingused33

Hi @pcbeingused333, thanks for your interest in the issue! Before opening a PR, please comment on the issue first and wait to be assigned. This helps us avoid duplicate work. PRs opened without an assignment may be closed. Thanks !

addyCooks avatar Nov 14 '26 07:11 addyCooks

Thanks @addyCooks, and sorry about that: I commented here and then opened #2177 right away instead of waiting to be assigned. Could you assign this issue to me if nobody else is on it? #2177 already has the change (a shared helper that parses $EDITOR/$VISUAL into command + args and spawns without a shell, used by the wizards and /setup-config, with specs). If you would rather give the issue to someone else, I'll close the PR. From now on I'll wait for the assignment before opening anything.

This comment was drafted with AI assistance (Claude Code).

pcbeingused33 avatar Nov 14 '26 08:11 pcbeingused33