Skip to content

ADFA-2621 | Add file-edit tool for local LLM models - #58

Open
jatezzz wants to merge 2 commits into
mainfrom
feat/ADFA-2621-edit-file-tool
Open

ADFA-2621 | Add file-edit tool for local LLM models#58
jatezzz wants to merge 2 commits into
mainfrom
feat/ADFA-2621-edit-file-tool

Conversation

@jatezzz

@jatezzz jatezzz commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Description

What:
This PR introduces the edit_file tool to the AI Assistant, allowing models to perform surgical find-and-replace changes on project files instead of attempting to rewrite them entirely.

How:

  • Targeted Edits: The tool uses old_string and new_string arguments to locate and replace exact snippets, falling back to line-ending adaptations if needed.
  • Diff-based Review UI: Replaces the generic JSON approval dialog with a dedicated before/after diff preview for file edits.
  • Interactive Corrections: Adds a "Correct" option in the approval dialog, allowing users to reject an edit but provide written guidance back to the agent so it can retry in the same loop.
  • Buffer & Disk Safety: Applies changes directly to the active editor buffer when a file is open (preserving unsaved work and allowing Ctrl+Z undo). For closed files, it uses atomic disk writes.
  • Prompt Engineering: Updates system prompts to explicitly guide the LLM on using edit_file, emphasizing the need to copy old_string verbatim after reading the file.

Why:
Local LLMs generally lack the context window and output budget to reliably overwrite entire files using update_file. A targeted edit approach makes local, on-device models substantially more viable for iterative coding tasks.

Details

  • Added EditFileHandler, EditorBufferApplier, and AtomicFileWriter to safely manage the lifecycle of an edit.
  • Updated ToolApprovalManager to support CORRECTED states and strictly prevent edit_file from ever being granted blanket "Always Allow" session approval.
  • Introduced AgentTrace for detailed lifecycle logging of prompt, tool execution, parsing, and execution.
  • Bumped plugin version to 1.1.0.
document_5152462601887680330.mp4

Ticket

ADFA-2621

Observation

  • Security/Safety: edit_file validations explicitly block writes to .git/, keystores, and build configuration files.

Approval-gated find/replace with a before/after diff: a file open in the editor is changed through the buffer (Ctrl+Z-able), a closed one via atomic temp-then-rename. ai-core now turns native model-load failures into actionable user messages instead of a bare null-handle error.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.

Tip: disable this comment in your organization's Code Review settings.

@jatezzz

jatezzz commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

@claude review

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Code review skipped — your organization's overage spend limit has been reached.

Code review is billed via overage credits. To resume reviews, an organization admin can raise the monthly limit at claude.ai/admin-settings/claude-code.

Once credits are available, comment @claude review on this pull request to trigger a review.

Approval-gated find/replace with a before/after diff: a file open in the editor is changed through the buffer (Ctrl+Z-able), a closed one via atomic temp-then-rename. A guessed path is corrected when one candidate has no rival, and rejections name the fix, the split pair when an instruction was pasted into both args, replace_all when a bare name matched many times, so a local model recovers in one turn. Tool-call examples in the system prompts use the file the IDE actually has open, and unexpected failures log through context.logger. ai-core now turns native model-load failures into actionable user messages instead of a bare null-handle error.
@jatezzz
jatezzz force-pushed the feat/ADFA-2621-edit-file-tool branch from 381d0e3 to 1a12f78 Compare August 3, 2026 20:36
@jatezzz
jatezzz requested a review from Daniel-ADFA August 3, 2026 20:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants