code-review-graph icon indicating copy to clipboard operation
code-review-graph copied to clipboard

apply_refactor_tool writes to files with no dry-run or confirmation step

Open dev-arctik opened this issue 7 months ago • 2 comments

Problem

apply_refactor_tool modifies files on disk directly when called via MCP. There is no dry-run mode, no diff preview before applying, and no confirmation prompt. Once invoked, changes are applied immediately.

Impact

  • An AI assistant can trigger file rewrites autonomously without the developer explicitly approving the specific changes
  • There is no undo path beyond git checkout — developers who haven't staged their work lose changes permanently
  • In an agentic workflow where multiple MCP tools are chained, apply_refactor_tool could be called as a side effect of a broader task the developer didn't intend to modify files for

Suggested Fix

  1. Add a dry_run: bool parameter to apply_refactor_tool — when true, return the diff without writing to disk
  2. Default behaviour should return a diff and require a second explicit call with confirmed: true to actually apply (two-step commit pattern)
  3. At minimum, always return the full diff in the tool response so the AI assistant can show it to the user before they accept

dev-arctik avatar Apr 09 '26 06:04 dev-arctik

Valid security/UX concern. apply_refactor_tool currently writes changes to disk immediately with no confirmation step. The suggested two-step approach (dry_run first, then confirmed=true to apply) is the right pattern for agentic workflows where side effects should be explicit.

This is a valid enhancement — a PR adding dry_run: bool parameter to apply_refactor_tool that returns a diff without writing when True would be a straightforward and valuable safety improvement.

tirth8205 avatar Apr 11 '26 08:04 tirth8205

@tirth8205 @dev-arctik can I work on this Issue and raise a PR as soon as possible??!

VaibhavDangaich avatar Apr 11 '26 16:04 VaibhavDangaich