Skip to main content

amberfork_judge/
lib.rs

1//! The explain layer: a local, optional model that narrates a fork `amberfork-align` already
2//! computed (issue #10, Phase 2 / Zone 3 of the design doc).
3//!
4//! The deterministic aligner stays the headline. This crate never localizes — it reads a
5//! finished [`amberfork_model::DiffResult`] plus a narrow content window and only ever
6//! describes or speculates. Two guardrails are enforced in the types rather than left to
7//! convention:
8//!
9//! - [`ExplainContext`] hands a [`Judge`] the fork step (+ `k` neighbours) it is scoped to
10//!   reason about, never the two full trajectories — a judge cannot hunt for a different fork
11//!   because it never sees content outside the window.
12//! - [`ground`] validates a judge's claimed fork index against the `DiffResult` it was asked
13//!   about before the result is trusted; an explanation that contradicts the aligner is
14//!   rejected, never rendered.
15//!
16//! Alongside the trait: [`ScriptedJudge`] (the in-process test double that keeps `cargo test
17//! --workspace` offline) and [`OllamaJudge`] (the live provider — a local Ollama server, no
18//! cloud call, no API key). `tokio` is deliberately absent from this crate's own dependencies:
19//! `Judge::explain` is a plain async fn, and the runtime that drives it belongs to the caller
20//! (the CLI), the same I/O-edge quarantine `amberfork-replay` uses.
21
22mod context;
23mod grounding;
24mod judge;
25mod ollama;
26mod prompt;
27mod scripted;
28
29pub use context::{ExplainContext, Side, StepSnapshot};
30pub use grounding::{Grounded, GroundingError, ground};
31pub use judge::{Explanation, Judge, JudgeError};
32pub use ollama::OllamaJudge;
33pub use scripted::ScriptedJudge;