boundgraph_slice/lib.rs
1//! Layer 4 of BoundGraph: the slicers that make context cost linear.
2//!
3//! A raw tool result might be ten thousand lines. What the next step receives is
4//! a few hundred tokens of structured summary — a [`Condensate`] — while the
5//! original stays addressable in the content store for an auditor. That single
6//! move is what turns quadratic context growth into linear growth, and it is
7//! the mechanism behind Law II.
8//!
9//! # Why naive truncation is not an option
10//!
11//! Cutting the first `n` bytes off a result is cheap and almost always wrong.
12//! The interesting part of a build log is at the end; the interesting part of a
13//! diff is spread across hunks; the interesting part of a JSON response is its
14//! shape, not its first field. Worse, a truncated result *looks* complete — it
15//! invites confidently wrong conclusions, which is precisely the failure mode
16//! this project exists to prevent.
17//!
18//! So slicing is per-kind and structure-aware. Each slicer knows what is worth
19//! keeping in its own format, and every one of them reports honestly whether it
20//! dropped anything.
21//!
22//! # The contract
23//!
24//! [`Slicer::condense`] is a provided method that preserves the original,
25//! calls the implementation, and then checks the result against the cap. An
26//! implementation cannot skip any of those, so "output never exceeds the cap"
27//! is a property of the trait rather than a promise each slicer makes
28//! separately. See [`slicer`] for the reasoning.
29//!
30//! # Status
31//!
32//! Feature 07, milestone M3. Built in dependency order rather than story order,
33//! because US-0702 degrades to US-0703's slicer and so needs it first:
34//!
35//! | Story | Module |
36//! |---|---|
37//! | US-0701 slicer trait | [`slicer`] |
38//! | US-0703 log slicer | [`log`] |
39//! | US-0704 diff slicer | [`diff`] |
40//! | US-0705 JSON slicer | [`json`] |
41//! | US-0702 AST slicer | [`ast`] (feature `ast`) |
42//!
43//! [`Condensate`]: boundgraph_core::Condensate
44
45#![doc(html_root_url = "https://docs.rs/boundgraph-slice")]
46
47pub mod diff;
48pub mod json;
49pub mod log;
50pub mod slicer;
51
52#[cfg(feature = "ast")]
53pub mod ast;
54
55#[cfg(feature = "ast")]
56pub use ast::{AstSlicer, Language};
57
58pub use diff::{DiffSlicer, FileDiff, FileStatus, Hunk};
59pub use json::{JsonSlicer, REDACTED};
60pub use log::{Level, LogLine, LogSlicer};
61pub use slicer::{
62 ByteCeiling, CommandOutcome, Estimate, MemoryStore, Raw, Slice, SliceError, Slicer, Store,
63 StoreError, TokenCount,
64};
65
66/// Re-exported so a consumer naming a slicer does not also depend on
67/// `boundgraph-core` just for its identifier.
68pub use boundgraph_core::{SchemaId, SlicerId};