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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
//! causa-runtime — optional components over the context kernel.
//!
//! The kernel is facts (`context`) + contracts (`ports`) only. This crate
//! is a set of optional, reference components on top of them: adopt the
//! execution stack, take a single piece, or read them as a reference and
//! build your own. Each component documents the policy it bakes in and what
//! adopting it brings along.
//!
//! - **Driver stack** (`driver`, `executor`, `hook`, `config`, `control`):
//! `TurnRunner` orchestrates turns over the kernel's ports —
//! retry scheduling, tool batch dispatch, artifact spill, traces, and
//! run control.
//! - **Budget & interaction components** (`budget`, `interaction`): the
//! frame-materialization policy (`FramePolicy`, window budget,
//! compaction, token counting) and the host↔driver `TurnInteraction`
//! seam — the component's documented opinions, not fact-layer invariants.
//! A custom host composes the kernel's lossless `TurnContext::frame`
//! differently.
//! - **Session aggregate** (`conversation`): `ConversationState` (single
//! active slot, completed-only history, commit-time `TurnSequence` as
//! `HistoryEntry`), the `SealedResult` stamp, and the `ConversationStore`
//! archive port. These are component decisions, not fact-layer invariants;
//! a custom host composes the kernel facts differently.
//! - **Session coordination** (`session`): one [`Session`] owner per
//! conversation drives accepted work through the assembled [`TurnRunner`]
//! — cloneable [`SessionHandle`]s submit / observe / wait / resume / cancel,
//! one active work at a time, per-work `TurnId`s assigned at acceptance and
//! never reused, local `request_key` dedup, explicit retained-work capacity,
//! and an observable `Faulted` state. The material-free save loop is
//! implemented: an idle or paused session exports a versioned
//! [`SessionCheckpoint`], and `SessionCheckpoint::restore` registers it
//! against freshly assembled capabilities without calling the model or a
//! tool. Multi-session coordination and per-work materials are out of
//! scope.
//! - **Tool-use filters** (`DedupFilter`, `AllowAllFilter`, `DenyAllFilter`,
//! `FilterChain`) implement this crate's `ToolUseHook` directly — the
//! trait, its consumer, and its policies share one crate. The default is
//! `PassthroughHook` (no opinion); composition and policy are opt-in.
//! - **Events** (`ContextEvent` / `project_turn`) project a finished turn's
//! facts (`TurnContext` + `TurnResult` + `TurnTrace`) into an IPC-ready
//! event sequence for UI / observability / audit consumers.
//!
//! Implementation-side note: implementing a `ModelGateway` or a `Tool`
//! requires only `causa-kernel`; this crate exists to *use the optional
//! execution components*, not to fill the kernel's ports.
//!
//! # Optional components
//!
//! Everything here is optional, and each piece is offered as a reference:
//! adopt it whole, or read it and build your own. The four responsibilities
//! below are how the crate is organized — not a promise about how finely it
//! can be split. What adopting a piece brings along is noted as cost, not as
//! a contract.
//!
//! 1. **Execution stack** — [`TurnRunner`] plus its config
//! ([`TurnRunOptions`], policy axes), resume ([`resume_turn`]), hook
//! seam, the budget ([`FramePolicy`]) and interaction
//! ([`TurnInteraction`]) components, and the session owner
//! ([`Session`] / [`SessionHandle`] / [`SessionCheckpoint`]).
//! Adopting it brings those policy components along; the defaults they
//! bake in are documented in the policy table below, not fact-layer
//! invariants.
//! 2. **Tool execution** — [`ToolExecutor::execute_with_limits`] runs one
//! call (panic isolation, deadline backstop, limit truncation, error
//! mapping) with no runner and no session; adopting it also brings the
//! config and budget vocabulary. Its catalog cache and static-name
//! priority are executor policies, documented at the impl site.
//! 3. **Session aggregate** — [`ConversationState`] owns the single-active
//! slot, completed-only history, and commit ordering ([`HistoryEntry`]).
//! A host with different session needs composes kernel facts directly.
//! 4. **Observation** — traces and [`ContextEvent`] are projections of a
//! finished turn for UI / audit consumers; reading them brings the
//! execution stack along. The host chooses what to persist; there is no
//! separate wire model.
//!
//! # Policy surface
//!
//! Every default the driver bakes in is one of two kinds — a swappable
//! policy object, or a documented opinion. No trait seams exist for
//! single-implementation policies; a seam is added only when a second real
//! shape appears.
//!
//! | Policy | Kind | Where |
//! |---|---|---|
//! | Retry schedule (disabled by default; when enabled, 500 ms base, 8 s ceiling, exponential) | config object [`RetryPolicy`] | `config` |
//! | Turn limits (10 model rounds, 64 tool calls by default) | config object [`TurnLimits`] in [`TurnPolicy`] | `config` |
//! | Frame compaction (none by default; host supplies compactor, token counter and thresholds) | config object [`FramePolicy`] | `budget` |
//! | Interaction / approval gate | port object [`NoopInteraction`] default | `config` |
//! | Tool-use filtering | port object [`HookCtx`] / [`ToolUseHook`], default [`PassthroughHook`] | `hook`, `filter` |
//! | Tool-output token estimation fallback (chars/4; frame estimation defaults to zero) | documented opinion, single home | `defaults::placeholder_token_estimate_value` (crate-internal), [`FramePolicy`] |
//! | Output truncation shape (retained head 60% + tail 40% sized to the declared token budget — notice and JSON-string wrapping measured, notice-only floor at tiny budgets; artifact spill; content replaced by a JSON string; `Truncation::Middle` marker) | documented opinion | `executor::ToolExecutor::execute_with_limits` |
//! | Unknown-outcome continuation (default `Stop`, per-executed-name overrides, explicit per-call host decisions) | config object [`UnknownOutcomeConfig`] + checkpoint [`UnknownDecision`] data | `config`, `hook`, `driver` |
//! | Batch semantics (dedup-then-parallel, per-call panic isolation → `Failed`, call-deadline backstop → `UnknownOutcome`) | documented opinion | `executor` |
//! | Session retention (256 works, rejects new work at capacity) and work deadline (none by default) | config object [`SessionConfig`] | `session` |
//! | Session admission (one active work, no queue), completed-only history and checkpoint eligibility | documented component opinions | [`Session`], [`ConversationState`], [`SessionCheckpoint`] |
//!
//! This table summarizes the main execution and session policies. Component
//! and configuration docs describe further defaults and constraints; absence
//! from this table does not make a runtime decision a kernel invariant.
// --- reference budget & interaction -----------------------------------------
pub use ;
pub use ;
// --- driver stack -----------------------------------------------------------
pub use ToolBridge;
pub use ;
pub use RunControl;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
// --- framework policies and projections --------------------------------------
pub use ;
pub use ;