causa_kernel/lib.rs
1//! causa-kernel — ContextBlock conversation kernel.
2//! No dependency on a host application, a UI shell, or another agent framework.
3//!
4//! # Layering (the kernel is facts + contracts, nothing else)
5//!
6//! - **`context`** — the external rule interface: exactly what the fact
7//! machine stores and validates — block content shapes, the turn state
8//! machine and its deterministic projections, and ids. Session-level
9//! vocabulary (the `ConversationState` aggregate, its eligibility stamp,
10//! ordering, and the conversation store port) is runtime territory; the
11//! kernel keeps the facts (`TurnContext` / `TurnSnapshot`), the validated
12//! recovery entries, and the shared `merged_frame` projection.
13//! - **`ports`** — the behavior seams external implementors fill in, each
14//! self-contained: `ModelGateway` (request params, result envelope,
15//! transport error), `Tool` + `ArtifactStore` (definitions, execution
16//! context, outcome policy, limits), `DynamicToolSource`, control planes. A
17//! type belongs here iff it is the contract surface third parties
18//! implement or call against; the kernel itself consumes none of it. The
19//! reference budget/compaction and host↔driver interaction seams are the
20//! runtime components' opinions, not cross-host contracts, and live in
21//! `causa-runtime`.
22//!
23//! The execution stack, executor, hook seam, config axes, and run control
24//! live in `causa-runtime`. Anything left here is either a fact or a
25//! contract; both are load-bearing.
26//!
27//! The physical modules are private; every re-export below is the entire
28//! public contract. Nothing else is a cross-crate commitment.
29
30#![deny(unsafe_code)]
31#![deny(missing_docs)]
32
33mod context;
34mod ports;
35
36// --- context: the external rule interface ------------------------------------
37pub use context::block::{
38 BlockContent, BlockMeta, ContentPart, ContextBlock, MediaRef, TextPayload, ToolCallPayload,
39};
40pub use context::ids::{
41 BlockId, BlockSequence, ContextVersion, ConversationId, FrameId, FrameScope, InvocationId,
42 RoundId, TurnId,
43};
44pub use context::model::{ModelResponse, ModelStopReason, ToolCallDraft};
45pub use context::tool_data::{
46 ArtifactKind, ArtifactRef, ToolCallId, ToolOutput, ToolOutputMeta, ToolResultPayload,
47 ToolResultStatus, Truncation,
48};
49pub use context::turn::{
50 AppliedModelOutput, ContextError, ContextFrame, ModelContext, OrderedBlocks, TurnContext,
51 TurnLifecycle, TurnSnapshot, merged_frame, option_turn_context_as_snapshot,
52 turn_context_as_snapshot,
53};
54
55// --- ports: behavior seams for external implementors ------------------------
56pub use ports::control::{AttemptControl, CallControl, ControlError, effective_deadline};
57pub use ports::gateway::{
58 AttemptNumber, CacheDirective, GenerationOptions, ModelGateway, ModelInvokeError,
59 ModelInvokeErrorKind, ModelOutput, ModelRef, ModelRequest, ModelStream, ModelUsage,
60 ReasoningPayload, StreamDelta, ToolSurface, completed_model_stream,
61};
62pub use ports::source::{DynamicToolSource, SourceError, ToolExecutionError};
63pub use ports::tool::{
64 ArtifactHint, ArtifactStore, StoreError, Tool, ToolCallContext, ToolDefinition,
65};
66/// The cancellation primitive behind the control planes, re-exported so the
67/// port is self-contained for external drivers.
68pub use tokio_util::sync::CancellationToken;