feat(auto-format): run configured formatters on files edited by write… - #1160
feat(auto-format): run configured formatters on files edited by write…#1160AniketR10 wants to merge 2 commits into
Conversation
…_file/string_replace
|
@will-lamerton @akramcodez @Avtrkrb please review |
There was a problem hiding this comment.
🟡 Changes recommended
There are verified correctness/documentation issues around {file} quoting (notably on Windows/cmd.exe) and config validation/doc mismatches that should be addressed before merge.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Adds an opt-in “auto-format after edits” hook to the conversation loop, driven by a new nanocoder.autoFormat config section, so files modified by write_file / string_replace can be reformatted automatically without involving the model.
Changes:
- Introduces
AutoFormatConfig/AutoFormatFormatterConfigand loads/validatesnanocoder.autoFormatfromagents.config.json. - Wires
processAssistantResponseto run per-turn formatting after successful edit tools and surface failures only as user-visible chat messages. - Adds AVA coverage for both the core formatter runner and the conversation-loop wiring, plus docs + changeset.
File summaries
| File | Description |
|---|---|
| source/types/config.ts | Adds config types for nanocoder.autoFormat (enabled, formatters, timeout). |
| source/hooks/chat-handler/conversation/conversation-loop.tsx | Invokes runAutoFormat() after tool execution and reports failures via InfoMessage. |
| source/hooks/chat-handler/conversation/auto-format.ts | Implements per-file formatter matching, {file} substitution, and command execution with timeout. |
| source/hooks/chat-handler/conversation/auto-format.spec.ts | Adds unit/integration tests for the auto-format runner and conversation-loop wiring. |
| source/config/index.ts | Adds config loading + validation for nanocoder.autoFormat with safe defaults. |
| source/config/index.spec.ts | Adds config resolution tests for auto-format defaults, parsing, and malformed entries. |
| docs/configuration/index.md | Documents nanocoder.autoFormat options and examples. |
| .changeset/auto-format-on-save.md | Adds changelog entry for the new auto-format feature. |
Review details
Suppressed comments (2)
source/hooks/chat-handler/conversation/auto-format.ts:98
- The doc comment claims that a "no match" is reported as a failure outcome, but the implementation silently skips files with no matching formatter (returns no outcome at all). This is misleading for future maintainers and for callers that might expect an outcome per edited file.
* Run configured formatters against every file successfully touched by an
* edit tool (`write_file`, `string_replace`) this turn. Silent on success;
* every failure (no match, non-zero exit, timeout, missing binary) is
* captured as an outcome instead of thrown, so a misconfigured or missing
* formatter never interrupts the conversation.
source/hooks/chat-handler/conversation/auto-format.ts:121
{file}is substituted using POSIX single-quote escaping (shellQuote). On Windows this code runs commands viacmd.exe(seepickShell()), where single quotes are not quoting, so paths with spaces/special characters can break formatting (and quoting is inconsistent with the shell actually used). Quote the file path appropriately for cmd.exe.
const absolutePath = isAbsolute(path) ? path : resolve(cwd, path);
const command = formatter.command.replaceAll(
'{file}',
shellQuote(absolutePath),
);
- Files reviewed: 8/8 changed files
- Comments generated: 4
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Description
runs a configured formatter on files after write_file or string_replace edits them. config is under nanocoder.autoFormat in agents.config.json. off by default. failures just show a chat message and don't block anything. closes #1009
Type of Change
Changeset
pnpm changeset) describing this change for the changelogTesting
Automated Tests
.spec.ts/tsxfilespnpm test:allcompletes successfully)Manual Testing
Checklist