codex_patcher/lib.rs
1//! Codex Patcher: Automated code patching system for Rust
2//!
3//! A robust patching system built on byte-span replacement primitives with
4//! tree-sitter and ast-grep integration for structural code queries.
5//!
6//! # Architecture
7//!
8//! All edit operations compile down to a single primitive: [`Edit`], which
9//! represents a verified byte-span replacement. Intelligence lives in span
10//! acquisition (via tree-sitter, ast-grep, compiler diagnostics), not in
11//! the application logic.
12//!
13//! # Safety
14//!
15//! - All edits verify expected before-text before applying
16//! - Atomic file writes (tempfile + fsync + rename)
17//! - Workspace boundary enforcement
18//! - UTF-8 validation
19//! - Idempotent operations
20//!
21//! # Example
22//!
23//! ```no_run
24//! use codex_patcher::{Edit, EditVerification};
25//! use std::path::PathBuf;
26//!
27//! let edit = Edit::new(
28//! PathBuf::from("src/main.rs"),
29//! 0,
30//! 5,
31//! "HELLO",
32//! "hello",
33//! );
34//!
35//! match edit.apply() {
36//! Ok(result) => println!("Edit applied: {:?}", result),
37//! Err(e) => eprintln!("Edit failed: {}", e),
38//! }
39//! ```
40
41pub mod cache;
42pub mod compiler;
43pub mod config;
44pub mod edit;
45pub mod fuzzy;
46pub mod pool;
47pub mod safety;
48pub mod sg;
49pub mod toml;
50pub mod ts;
51pub mod validate;
52
53// Re-exports
54pub use config::{
55 apply_patches, load_from_path, load_from_str, matches_requirement, ApplicationError,
56 ConfigError, PatchConfig, PatchResult, VersionError,
57};
58pub use edit::{Edit, EditError, EditResult, EditVerification};
59pub use safety::{SafetyError, WorkspaceGuard};
60pub use ts::{
61 LocatorResult, QueryEngine, QueryMatch, RustParser, StructuralLocator, StructuralTarget,
62 TreeSitterError,
63};
64pub use validate::{
65 syn_validate, ErrorLocation, ParseValidator, SelectorValidator, ValidatedEdit, ValidationError,
66};