1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
//! # claw-branch
//!
//! A Rust library for isolated, SQLite-backed agent branch management.
//!
//! `claw-branch` gives AI agents a structured way to diverge from a shared knowledge
//! baseline, explore changes in isolation, diff and merge back, and evaluate outcomes
//! in a fully sandboxed environment — all backed by SQLite and enforced through a
//! strongly-typed async API.
//!
//! ## Core concepts
//!
//! | Concept | Description |
//! |---------|-------------|
//! | **Branch** | An isolated SQLite database snapshot with its own lifecycle state |
//! | **Trunk** | The canonical baseline branch; all other branches fork from it |
//! | **Fork** | Creates a copy-on-write snapshot of a parent branch |
//! | **Diff** | Entity-level comparison between two branches |
//! | **Merge** | Three-way merge with configurable conflict resolution strategy |
//! | **Commit** | Selective cherry-pick of entities from one branch to another |
//! | **Sandbox** | Temporary evaluation environment for speculative agent work |
//! | **DAG** | Directed acyclic graph tracking branch lineage |
//!
//! ## Quick-start
//!
//! ```rust,ignore
//! use claw_branch::prelude::*;
//! use std::path::PathBuf;
//!
//! #[tokio::main]
//! async fn main() -> anyhow::Result<()> {
//! let config = BranchConfig::builder()
//! .workspace_dir(PathBuf::from("/tmp/demo"))
//! .build()?;
//!
//! let engine = BranchEngine::new(config, std::path::Path::new("/data/source.db")).await?;
//!
//! // Fork a feature branch from trunk
//! let feature = engine.fork_trunk("feature/summariser").await?;
//!
//! // Diff against trunk
//! let trunk = engine.trunk().await?;
//! let diff = engine.diff(trunk.id, feature.id).await?;
//! println!("changed={}", diff.stats.modified);
//!
//! // Simulate an agent workload and get a recommendation
//! let report = engine.simulate(feature.id, SimulationScenario {
//! name: "trial".into(),
//! description: "test run".into(),
//! max_ops: Some(100),
//! timeout_secs: Some(30),
//! seed_data: None,
//! }, |pool| async move {
//! // agent writes to pool…
//! Ok(serde_json::json!({"status": "done"}))
//! }).await?;
//!
//! match report.recommendation {
//! Recommendation::Commit => { engine.commit_to_trunk(feature.id).await?; }
//! Recommendation::Discard => { engine.discard(feature.id).await?; }
//! Recommendation::NeedsReview(notes) => println!("Review: {notes:?}"),
//! }
//!
//! Ok(())
//! }
//! ```
/// Branch management primitives.
/// Selective commit and history helpers.
/// Shared configuration for branch operations.
/// DAG lineage graph support.
/// Diff extraction and reporting.
/// Top-level engine orchestration.
/// Error types used across the crate.
/// Guard-aware wrapper around the branch engine.
/// Merge algorithms and conflict handling.
/// Metrics collection and reporting.
/// Simulation sandbox support.
/// Snapshot creation, verification, and garbage collection.
/// Shared domain types.
// ── Primary re-exports ────────────────────────────────────────────────────────
pub use ;
pub use ;
pub use ;
pub use GuardedBranchEngine;
// types
pub use ;
// diff
pub use DiffSummary;
// merge
pub use ;
// commit
pub use ;
// sandbox
pub use ;
// metrics
pub use ;
// snapshot GC
pub use GcReport;
// ── Prelude ───────────────────────────────────────────────────────────────────
/// Convenience re-exports for typical library consumers.
///
/// ```rust,ignore
/// use claw_branch::prelude::*;
/// ```