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
//! # contextgraph-core
//!
//! A versioned, git-like context store for LLM agent conversations,
//! implemented in pure Rust. It treats the conversation window as a DAG:
//! every turn is a content-addressed commit, branches are named pointers,
//! and any point in history can be checked out, diffed, or rolled back to.
//!
//! Contextgraph stores and versions context; it **never** calls a model —
//! it's the substrate an agent runtime checks context in and out of.
//!
//! ## Core concepts
//!
//! * **Commit** — an immutable, content-addressed node representing one
//! delta to the conversation state (a message, a tool call/result, or a
//! compaction event). Identical content always yields the identical id.
//! * **Branch** — a named, mutable pointer to a commit (exactly like a
//! `git` ref).
//! * **Checkout** — materializes the ordered message list a model would
//! see by walking a commit's ancestry and folding deltas (including
//! compaction ops) in order.
//! * **Bisect** — O(log n) binary search along an ancestry path for the
//! commit where a caller-supplied predicate flips.
//!
//! ## Storage
//!
//! Persistence lives behind two traits: [`CommitStore`] (the content-
//! addressed blob graph) and [`RefStore`] (the branch pointers). The
//! concrete entry point [`ContextGraph`] combines them; bring your own
//! `S: CommitStore + RefStore`.
//!
//! This crate ships two ready-made stores:
//!
//! * [`mem::InMemoryGraphStore`] — fast, no dependencies, suitable for
//! tests or short-lived processes.
//! * [`sqlite::SqliteStore`] — SQLite (WAL mode) for durable storage,
//! designed for an agent runtime.
//!
//! ## Example
//!
//! ```
//! use chrono::Utc;
//! use contextgraph_core::{
//! Author, Commit, ContextGraph, Delta, Metadata,
//! commit::{compute_commit_id, CommitId},
//! graph::CheckoutTarget,
//! mem::InMemoryGraphStore,
//! };
//!
//! # async fn run() -> Result<(), Box<dyn std::error::Error>> {
//! let store = InMemoryGraphStore::new();
//! let graph = ContextGraph::new(store);
//!
//! let meta = Metadata::new(Utc::now());
//! let id = graph
//! .commit_advancing_branch("main", Author::User, Delta::Message { content: "hi".into() }, meta)
//! .await?;
//!
//! let ctx = graph.checkout(CheckoutTarget::Branch("main".into())).await?;
//! assert_eq!(ctx.messages.len(), 1);
//! # Ok(()) }
//! ```
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;