Configuration
// Configure a custom FuzzyPatchMatcher
val processor = FuzzyPatchMatcher(
    contextSize = 3,
    levenshteinThresholdDivisor = 4,
    minLineLengthForFuzzyMatch = 5,
    enableFuzzyMatching = true,
    enableSnippetPatching = true,
    snippetMatchThreshold = 0.8
)

// Apply a patch
val result = processor.applyPatch(source, patch)
Output
// Source (with minor variations)
 fun calculateTotal(items: List<Item>) {
-    var total = 0
+    var total = 0.0
    var total = 0.0
     for (item in items) {
-        total += item.price
+        total += item.price * item.quantity
        total += item.price * item.quantity
     }
    return total.roundToTwoDecimals()
+    return total.roundToTwoDecimals()
 }

βœ“ Patch applied successfully
  - 2 lines modified, 1 line added
  - Fuzzy matched 3 context lines

Available Processors

Pre-configured processors optimized for different use cases and precision requirements.

πŸ”· Fuzzy (Default)

Balanced default for most languages. Uses a Levenshtein threshold divisor of 4 and 80% snippet match threshold.

PatchProcessors.Fuzzy

πŸ”’ Strict

Maximum precision. No fuzzy matching or snippet patching. Requires exact line matches with 5 lines of context.

PatchProcessors.Strict

πŸƒ Lenient

Maximum flexibility for heavily modified codebases. Very lenient thresholds and minimal context requirements.

PatchProcessors.Lenient

🐍 Python

Specialized for indentation-sensitive languages like Python and YAML. Preserves leading whitespace exactly.

PatchProcessors.Python

βš›οΈ Thermodynamic

Physics-based matching using DNA-binding principles. Calculates optimal alignment via binding energy.

PatchProcessors.Thermodynamic

πŸ”„ FullReplacement

Simple full-file replacement. Ideal for creating new files or complete rewrites where patching is unnecessary.

PatchProcessors.FullReplacement

10 Key Innovations

What makes Cognotik's patching system different from traditional diff/patch tools.

1. Bidirectional Line Linking

Lines know their neighbors, enabling context-aware matching and bidirectional traversal during the alignment phase.

2. Multi-Phase Matching

Unique line matching β†’ Adjacent line propagation β†’ Recursive subsequence linking. Adapts to code structure organically.

3. Adaptive Fuzzy Matching

Levenshtein distance with structural type checking and adaptive thresholds that scale with line length.

4. Snippet Patching

Handles AI-generated code blocks without explicit diff markers using a three-tier matching strategy.

5. Move Detection

Identifies relocated code blocks by detecting order inversions, representing them as clean delete + add operations.

6. Intelligent Context Management

Truncates large context blocks with ellipsis while preserving critical lines before and after changes.

7. No-op Annihilation

Cleans up redundant DELETE/ADD pairs where the content remains identical after processing.

8. Thermodynamic Alternative

Physics-based matching for specialized scenarios where traditional string matching fails.

9. Language-Specific Support

Dedicated processors for indentation-sensitive languages like Python and YAML.

10. Validation Integration

Seamlessly integrates with grammar validation to ensure patches don't introduce syntax errors.

Ready to Get Started?

PatchProcessor is part of the Cognotik core library. Explore the source code on GitHub or read the full technical documentation.