pub fn apply_patch_with_validation(
file_path: &Path,
start: usize,
end: usize,
new_content: &str,
workspace_dir: &Path,
language: Language,
analyzer_mode: AnalyzerMode,
strict: bool,
skip: bool,
) -> Result<(String, String)>Expand description
Apply a patch with comprehensive validation and automatic rollback.
This function:
- Pre-verification (file state, workspace resources, graph sync)
- Computes hash of original file
- Replaces [start..end] byte span with new_content
- Writes to temp file, fsyncs, atomic rename
- Runs tree-sitter reparse gate (language-specific)
- Runs compiler validation gate (language-specific)
- Runs rust-analyzer gate (if enabled and Rust)
- On any failure, rolls back atomically
§Rollback Behavior
If any validation gate fails after patching, the original content is restored atomically. The rope mutation (remove + insert) happens in memory first, then the result is written to a temp file. If validation fails, we restore the original content.
§State Tracking
before_hash: Content hash before patchingreplaced: Original bytes for rollbackafter_hash: Content hash after patching (for verification)
§Arguments
file_path- Path to the file to patchstart- Start byte offset (inclusive)end- End byte offset (exclusive)new_content- Replacement contentworkspace_dir- Directory containing project config for validationlanguage- Programming language for validation gatesanalyzer_mode- rust-analyzer mode (off/path/explicit, Rust only)
§Returns
Ok((before_hash, after_hash))- SHA-256 hashes before/after patchErr(SpliceError)- Validation failure with automatic rollback