merge_engine/lib.rs
1//! # merge-engine
2//!
3//! A non-LLM merge conflict resolver that uses program analysis techniques
4//! from recent academic research to automatically resolve git merge conflicts.
5//!
6//! ## Approach
7//!
8//! The engine applies a pipeline of increasingly sophisticated strategies:
9//!
10//! 1. **Pattern-based DSL rules** — Matches common conflict patterns
11//! (whitespace-only, identical changes, import unions, adjacent edits)
12//! and resolves them instantly with high confidence.
13//! *Based on: Svyatkovskiy et al., "Can Program Synthesis be Used to Learn
14//! Merge Conflict Resolutions?", ICSE 2021*
15//!
16//! 2. **Structured merge via tree-sitter CSTs** — Parses code into concrete
17//! syntax trees and performs three-way tree amalgamation, eliminating false
18//! conflicts that arise from formatting changes or reordering.
19//! *Based on: Duarte, Borba, Cavalcanti, "LASTMERGE — A Language-Agnostic
20//! Structured Tool for Code Integration", arXiv 2025;
21//! Neto & Borba, "On the Methodology of Three-Way Structured Merge", JSA 2023*
22//!
23//! 3. **Version Space Algebra (VSA)** — For remaining conflicts, builds a
24//! compact representation of all possible resolutions by combining edits
25//! from both sides, then enumerates and ranks candidates.
26//! *Based on: Zhu & He, "Conflict Resolution for Structured Merge via
27//! Version Space Algebra", OOPSLA 2018 / AutoMerge*
28//!
29//! 4. **Search-based resolution with parent similarity** — Uses evolutionary
30//! search (genetic algorithm) over candidate resolutions, scored by a
31//! fitness function that measures token-level similarity to both parents.
32//! *Based on: Campos Junior et al., "Towards a Feasible Evaluation Function
33//! for Search-Based Merge Conflict Resolution", ACM TOSEM, July 2025*
34//!
35//! ## Supported Languages
36//!
37//! Tree-sitter-based structured merge supports: Rust, JavaScript, TypeScript,
38//! Python, Java, Go, C, C++. Pattern-based and search-based strategies work
39//! on any text content.
40//!
41//! ## Example
42//!
43//! ```rust
44//! use merge_engine::{Resolver, ResolverConfig, Language};
45//!
46//! let config = ResolverConfig {
47//! language: Some(Language::Rust),
48//! ..Default::default()
49//! };
50//! let resolver = Resolver::new(config);
51//!
52//! let result = resolver.resolve_file(
53//! "fn main() { println!(\"hello\"); }",
54//! "fn main() { println!(\"hello world\"); }",
55//! "fn main() { println!(\"hello\"); eprintln!(\"debug\"); }",
56//! );
57//!
58//! println!("All resolved: {}", result.all_resolved);
59//! println!("Merged:\n{}", result.merged_content);
60//! ```
61
62pub mod amalgamator;
63pub mod diff3;
64pub mod matcher;
65pub mod parser;
66pub mod patterns;
67pub mod resolver;
68pub mod search;
69pub mod types;
70pub mod vsa;
71
72// Re-export primary public API
73pub use resolver::{FileResolverOutput, Resolver, ResolverConfig, ResolverOutput};
74pub use types::{
75 Confidence, Language, MergeResult, MergeScenario, ResolutionCandidate, ResolutionStrategy,
76};