Skip to main content

agent_frame/
lib.rs

1//! **agent-frame** — the derivation kernel.
2//!
3//! Not "context management with a hash on it". This is a content-addressed
4//! *derivation* system whose principal output happens to be a model's working
5//! frame. Nothing in the core mentions context windows; it is about **what a
6//! derived thing may assert, what it owes its source, and how far it may travel
7//! from that source before it stops being accountable.**
8//!
9//! It is the third question in a stack: `agent-bridle` asks what am I allowed
10//! to do, `agent-mesh` asks who am I talking to, **agent-frame asks what do I
11//! know and how do I know it**, and `agent-store` holds durable ordering.
12//!
13//! # A unit's address is self-validating
14//!
15//! The single property this crate exists to provide: **given a unit's id and
16//! the source bytes, a consumer who did not run the build can establish which
17//! material the unit represents and how it was derived.**
18//!
19//! That is a claim about the *hash*, not about a comment. A [`Unit`]'s id is
20//! the id of its [`Derivation`] — `{ op, source, span, elided, root }` — so two
21//! elisions over different sources, or over different ranges of one source,
22//! cannot collide. [`verify::verify_unit`] recomputes all three claims from the
23//! bytes and compares.
24//!
25//! An earlier revision failed this. It hashed `{ op, depth, root_kind, life,
26//! addressed }`, which names no material: every elision with the same root kind
27//! minted the *same* id, and `addressed: true` was a declaration rather than an
28//! address. See `docs/decisions/agent-frame-v0-monorepo.md`.
29//!
30//! # The admission boundary is closed
31//!
32//! [`Unit`] does not implement [`serde::Deserialize`]. Foreign bytes decode to
33//! [`RawUnit`] and cross into a `Unit` only through the fallible
34//! [`TryFrom`] impl, which enforces the v0 contract. Deriving `Deserialize`
35//! made the constructor one path of two, and the decoder was the unchecked one.
36//!
37//! [`Packet`] is closed the same way and for the same reason. It is a
38//! [`MerkleNode`], which carries a parent *set*; v0 mints a **chain**, whose
39//! Lean referent has no multi-parent constructor. Decoding therefore lands in
40//! [`RawPacket`] and admission refuses two or more parents — the state that
41//! satisfied `is_genesis() == false` and `prior() == None` at once.
42//!
43//! [`MerkleNode`]: content_addressable::MerkleNode
44//!
45//! # The machine-checked referent
46//!
47//! Every table in [`op`] and every rule in [`unit`] mirrors
48//! `formal/ContextOps/Basic.lean`, which CI builds.
49//!
50//! ```text
51//! Op          concise | elide | generate
52//! depthAfter  generate => d+1 ;  concise, elide => d
53//! Unit.wf     depth <= 1
54//! checkOf     .elide = .rederive
55//! ```
56//!
57//! # v0 mints elision only
58//!
59//! [`Op::Concise`] and [`Op::Generate`] exist in the type; [`Unit::seal`] and
60//! the admission boundary both refuse them. The referent is `checkOf .elide =
61//! .rederive`: elision asserts nothing and is verified by re-derivation, so
62//! **every v0 assertion is a deterministic recompute** — and
63//! [`verify::verify_unit`] is that recompute, not a word for one.
64//!
65//! # What this crate is not
66//!
67//! No daemon, no socket, no async, no wire format, no storage. A layer is a
68//! crate. `tests/no_service_edge.rs` asserts the absence of any HTTP or
69//! inference dependency edge, so the crate stays daemon-able for free without
70//! being a daemon today.
71
72#![forbid(unsafe_code)]
73#![warn(missing_docs)]
74
75/// Derivations: the addressed fact a unit's identity is computed over.
76pub mod derivation;
77/// Causal events: observations, interventions, and checked derivation ancestry.
78pub mod event;
79/// The operation algebra: what was done, what it asserts, how it is checked.
80pub mod op;
81/// Packets: the chain, and identity over the whole body.
82pub mod packet;
83/// Roots: which event caused a derivation.
84pub mod root;
85/// Units: what a derived thing is, and what it owes its source.
86pub mod unit;
87/// The one verification decision, and its resolver seam.
88pub mod verify;
89
90pub use derivation::{Derivation, Span};
91pub use event::{Event, EventBody, EventError, EventKind, EventOrigin, RawEvent, ReplyVerdict};
92pub use op::{Check, Op};
93pub use packet::{Packet, PacketAdmitError, PacketBody, PacketId, RawPacket, UnitId};
94pub use root::{RootEvent, RootKind};
95pub use unit::{AdmitError, Life, RawUnit, SealError, Unit};
96pub use verify::{verify_unit, verify_unit_with, Mismatch, SourceResolver, Verified, VerifyError};