Transform the apply_diff tool into a highly reliable, production-ready code editing tool for LLM usage with hierarchical fallback strategies, improved parameter structure, and automatic file creation capabilities.
- Parameter restructuring:
filePath→description→startLine→endLine→search→replace - Multiple diff support: Maintain array-based multiple diff operations
- File creation: Auto-create files if they don't exist
- Hierarchical validation: Strict-first with progressive fallbacks
- Enhanced diagnostics: Show expected vs. actual content clearly
- Post-validation: Ensure structural integrity after changes
- Production reliability: Minimize real-world usage errors
Confidence: 10/10
- [✅] Change
originalContent→search - [✅] Change
newContent→replace - [✅] Reorder parameters:
filePath,description,startLine,endLine,search,replace - [✅] Update TypeScript interfaces (
DiffSection,ApplyDiffArgs) - [✅] Update Zod validation schema in tool registration
- [✅] Add parameter mapping to handle both old and new parameter names temporarily
- [✅] Add deprecation warnings for old parameter usage
- [✅] Plan removal timeline for old parameters
Confidence: 9/10
- [✅] Add file existence check at the start of
applyDiff() - [✅] If file doesn't exist, create empty file using existing
createWorkspaceFile() - [✅] Ensure proper directory structure creation (create parent directories if needed)
- [✅] Log file creation activities for debugging
- [✅] Handle edge case where search content is provided for empty file
- [✅] Default behavior: if file is empty and search content provided, treat as "insert at beginning"
- [✅] Add validation to prevent nonsensical operations on newly created files
Confidence: 8/10
- [✅] Exact match: Character-for-character matching including whitespace
- [✅] Line-hinted exact match: Use
startLine/endLineas hints for exact matching - [✅] Case-sensitive exact match: No tolerance for case differences
- [✅] Whitespace-normalized matching: Ignore leading/trailing whitespace
- [✅] Indentation-normalized matching: Normalize tabs vs spaces
- [✅] Case-insensitive matching: Try case-insensitive if case-sensitive fails
- [✅] Similarity matching: Use existing Levenshtein distance (threshold: 0.9→0.8→0.7)
- [✅] Contextual matching: Look at surrounding code context
- [✅] Partial matching: Allow matching subsets of the search content
- [✅] Create
ValidationHierarchyclass to manage fallback progression - [✅] Log each attempt level with detailed diagnostics
- [✅] Stop at first successful match
- [✅] Aggregate all failure reasons for final error reporting
Confidence: 9/10
interface DiagnosticInfo {
expected: string; // What we were searching for
actualContent: string[]; // What we found at various locations
searchLocations: number[]; // Line numbers where we looked
confidence: number; // Best match confidence
strategy: string; // Which strategy found the best match
}- [✅] Header: Clear problem statement
- [✅] Expected Content: Show exactly what was being searched for (first)
- [✅] Actual Content: Show what was found instead (last)
- [✅] Suggestions: Actionable next steps
- [✅] Line Context: Show surrounding lines where partial matches occurred
- [✅] Level 1 errors: Simple "not found" with suggestion to check line numbers
- [✅] Level 2 errors: Show best partial matches with confidence scores
- [✅] Level 3 errors: Full diagnostic with all attempted strategies
Confidence: 7/10
- [✅] Brace matching: Count
{and}before/after changes - [✅] Parentheses matching: Count
(and)before/after changes - [✅] Bracket matching: Count
[and]before/after changes - [✅] Quote matching: Basic quote pairing validation
- [✅] TypeScript/JavaScript: Check for basic syntax validity
- [✅] JSON: Validate JSON structure if file extension is
.json - [✅] Generic: Ensure no obvious structural corruption
- [✅] Add warnings (not errors) for potential structural issues
- [✅] Allow user to proceed with warnings
- [✅] Log structural changes for debugging
Confidence: 8/10
- [✅] Line-boundary respect: Ensure matches respect line boundaries
- [✅] Whitespace preservation: Keep original formatting in replacements (implemented with line ending detection and indentation preservation)
- [✅] Multi-line handling: Improve handling of multi-line search patterns
- [✅] Use
startLine/endLineas strong hints, not absolute requirements - [✅] Search in expanding radius from hinted lines (±1, ±2, ±5, entire file)
- [✅] Prefer matches closer to hinted lines when multiple matches found
- [✅] Pre-scan: Identify if search content appears multiple times in file
- [✅] Disambiguation: Use line hints to choose correct instance
- [✅] Warning system: Alert when multiple identical matches found
Confidence: 9/10
- [✅] Early termination: Stop searching once high-confidence match found (implemented with configurable confidence threshold)
- [✅] Caching: Cache file content during multi-diff operations (5-second TTL cache implemented)
- [✅] Automatic retry: Retry failed operations with different strategies (implemented via ValidationHierarchy)
- [✅] Partial success handling: Apply successful diffs even if some fail (partialSuccess flag implemented)
- [✅] Structured logging: JSON-formatted logs for debugging (StructuredLogger class implemented)
- [✅] Performance metrics: Track time spent in each validation level (duration tracking in all operations)
- [✅] Success rate tracking: Monitor tool reliability over time (getPerformanceMetrics() method)
Confidence: 8/10
- [✅] Detailed progress steps: Show current validation level being attempted (vscode.window.withProgress implemented)
- [✅] File creation notifications: Clear indication when files are auto-created (log messages and progress updates)
- [✅] Match confidence display: Show confidence scores in diff preview (status bar button with detailed tooltip)
- [✅] Syntax highlighting: Maintain code highlighting in diff view (VS Code's built-in diff viewer)
- [✅] Line numbers: Show original line numbers in diff (VS Code's diff viewer shows this)
- [✅] Change summary: Count of additions, deletions, modifications (shown in status bar info button)
- [✅] Validation warnings: Allow proceeding with warnings vs. errors (structural warnings are non-blocking)
- [✅] Match alternatives: When multiple matches found, show options (handled by line hint disambiguation)
Confidence: 9/10
- [✅] Unit tests: Test each validation level independently
- [✅] Integration tests: Test full workflow with various file types
- [✅] Edge case tests: Empty files, binary files, very large files
- [✅] Error condition tests: Network issues, permission problems, etc.
- [✅] Common patterns: Test with typical code editing scenarios
- [✅] Language variety: Test with TypeScript, JavaScript, JSON, Markdown, etc.
- [✅] Stress testing: Multiple simultaneous diff operations
- [✅] Parameter compatibility: Ensure old parameter names still work
- [✅] Behavior consistency: Verify no regressions in existing functionality
Confidence: 10/10
- [✅] Parameter documentation: Update tool description with new parameter order
- Usage examples: Provide clear examples of common use cases
- Error handling guide: Document common error scenarios and solutions
- Best practices: Guidelines for reliable tool usage
- Troubleshooting: Common issues and solutions
- File size recommendations: Guidelines for optimal performance
- Batch operation best practices: How to structure multiple diff operations
- Error recovery procedures: What to do when operations fail
Timeline: High Priority
- Interface restructuring
- File creation integration
- Hierarchical validation strategy
Timeline: High Priority
- Error diagnostics improvement
- Content matching refinement
Timeline: Medium Priority
- Structural integrity validation
- Performance optimizations
- User experience improvements
Timeline: Medium Priority
- Comprehensive testing
- Documentation updates
- [✅] 99%+ success rate on well-formed search/replace operations
- [✅] Zero false positives in exact matching mode
- [✅] Graceful degradation through fallback hierarchy
- [✅] Clear error messages that lead to actionable solutions
- [✅] <2 seconds for single diff operations on files <1000 lines
- [✅] <5 seconds for multi-diff operations with up to 10 diffs
- [✅] Memory efficient operation on files up to 10MB
- [✅] Intuitive parameter order that matches natural workflow
- [✅] Automatic file creation eliminates manual file creation step
- [✅] Progressive disclosure of error information (simple to detailed)
- [✅] High confidence in tool reliability for production LLM usage
- Complex fuzzy matching: Mitigate with extensive testing and conservative thresholds
- File system edge cases: Handle permissions, network drives, symlinks gracefully
- Memory usage with large files: Implement streaming and chunked processing
- Breaking changes: Provide backward compatibility and clear migration path
- Over-engineering: Keep fallback strategies simple and predictable
- Performance regression: Benchmark against current implementation
- Data loss: Implement proper backup/rollback mechanisms
- Concurrent access: Handle multiple editors/processes accessing same files
- Error cascading: Ensure single diff failure doesn't break entire operation
- Fail fast, fail clearly: Quick identification of unsolvable problems
- Progressive enhancement: Start simple, add sophistication gradually
- Defensive programming: Assume inputs may be imperfect
- Comprehensive logging: Every decision point should be logged
- User-centric errors: Error messages should guide toward solutions
- Test-driven development: Write tests before implementation
- Incremental delivery: Each task should be independently deployable
- Performance monitoring: Track metrics throughout development
- User feedback integration: Collect and respond to real-world usage patterns
This plan transforms apply_diff into a production-ready, highly reliable tool that will serve as your primary code editing interface with minimal errors and maximum confidence.