Skip to main content

axon/
lib.rs

1//! AXON runtime library — exposes the full AXON runtime: compiler
2//! frontend (re-exported from `axon-frontend`), handlers, runtime
3//! primitives, ESK, HTTP/WebSocket servers, persistence, OTS pipelines.
4//!
5//! Used by the `axon` binary and by integration tests.
6//!
7//! # Frontend vs runtime
8//!
9//! §Fase 12.a — the compiler frontend (lexer, parser, AST, type checker,
10//! IR generator, top-level checker, and the closed catalogs used by the
11//! type checker) lives in the sibling crate `axon-frontend`, which has
12//! zero runtime dependencies. This crate re-exports those modules
13//! transparently so every existing caller (76 call sites across 26
14//! files) keeps compiling without changes. The crate `axon-lsp`
15//! consumes `axon-frontend` directly, skipping the runtime surface.
16
17// ── §Fase 12.a — frontend re-exports (transparent to callers) ───────
18pub use axon_frontend::{
19    ast,
20    checker,
21    epistemic,
22    ir_generator,
23    ir_nodes,
24    legal_basis,
25    lexer,
26    parser,
27    refinement,
28    // §Fase 41.a — the session-type algebra (duality, regular-coinductive
29    // equality, §41.c credit-refined backpressure, §41.e SSE-polarity
30    // predicate). Re-exported so downstream consumers (the enterprise
31    // server's §Fase 41.f WS surface in `axon-enterprise`) reach it via the
32    // single `axon = …` workspace dep without an extra `axon-frontend`
33    // dependency line.
34    session,
35    // §Fase 41.h — multiparty session types (global types + projection).
36    // The orchestration story for n-agent skill/tool topologies: declare
37    // a `GlobalType`, project per role, drive each role's binary
38    // `SessionType` over the §41.d/41.f runtime — composition stays in
39    // lock-step by construction.
40    multiparty,
41    store_introspect,
42    store_schema,
43    store_schema_manifest,
44    stream_effect,
45    tokens,
46    type_checker,
47};
48
49// `ots_catalog` is the compile-time slug catalog; the runtime `ots`
50// module (below) re-exports these constants for backward compatibility.
51
52// ── Runtime modules (stay in this crate) ────────────────────────────
53
54pub mod anchor_checker;
55pub mod api_keys;
56pub mod audit_trail;
57pub mod auth_middleware;
58pub mod axon_server;
59pub mod backend;
60pub mod backend_error;
61pub mod circuit_breaker;
62pub mod compiler;
63pub mod config_persistence;
64pub mod conversation;
65pub mod cors;
66pub mod cost_estimator;
67pub mod db_pool;
68pub mod deployer;
69pub mod emcp;
70pub mod event_bus;
71/// §λ-L-E Fase 2 — Handler layer (Free Monad + CPS). Port of `axon/runtime/handlers/`.
72pub mod handlers;
73/// §λ-L-E Fase 3 + 5 runtime primitives. Port of `axon/runtime/` (lease kernel,
74/// reconcile loop, ensemble aggregator, immune kernels).
75pub mod runtime;
76/// §Fase 41.d — the **runtime** of a session-typed dialogue. The static
77/// algebra (`axon_frontend::session`: duality, regular-coinductive
78/// equality, credit-refined backpressure index `!ⁿA.S`) gets a dynamic
79/// counterpart here: an operational state machine (`SessionRuntime`)
80/// with one method per algebra rule, a wire envelope (`Frame`), and an
81/// RFC 6455 WebSocket carrier (`ws::drive`) that runs a session type
82/// against a peer. Carrier-agnostic core; the WS layer is one binding.
83pub mod session_runtime;
84/// §Fase 23.f — Algebraic effects runtime. FSM dispatch loop +
85/// handler stack + Free-Monad interpretation of CPS-lowered IR
86/// (consumes the JSON IR emitted by the Python frontend in 23.b/c/d).
87pub mod effects;
88/// §Fase 24.b — Native Rust LLM backends. Per-provider async clients
89/// behind a `Backend` trait + `Registry`. Per-provider modules
90/// (anthropic.rs / openai.rs / gemini.rs / kimi.rs / glm.rs / ollama.rs
91/// / openrouter.rs) land in 24.c–24.i; this module ships the shared
92/// infra (trait + types + error + retry + observability + locked_model
93/// + tokens dispatch).
94pub mod backends;
95/// §Fase 36.b — the Backend Resolution Contract (D1): the pure,
96/// deterministic precedence ladder that resolves a flow's execution
97/// backend (request → axonendpoint `backend:` → server default →
98/// environment-available `auto` → honest failure).
99pub mod backend_resolution;
100/// §ESK Fase 6 — Epistemic Security Kernel. Port of `axon/runtime/esk/`.
101pub mod esk;
102/// §Fase 51 — Proof-Carrying Code. apx/axonendpoint carry a portable,
103/// machine-checkable proof object an INDEPENDENT verifier checks
104/// against the artifact WITHOUT trusting the compiler that produced it
105/// (the move from `esk`'s builder-signed attestation to a consumer-
106/// verifiable proof). §51.a ships the kernel + the ComplianceCoverage
107/// property class.
108pub mod pcc;
109/// CLI handlers for the ESK audit commands (dossier, sbom, audit, evidence-package).
110pub mod audit_cli;
111/// §Fase 51.f — CLI handlers for the PCC commands (`axon pcc prove` /
112/// `axon pcc verify`). Closes the Proof-Carrying Code loop at the
113/// command line: generate a proof bundle from source, then
114/// independently verify it against a recompile of that source.
115pub mod pcc_cli;
116pub mod flow_inspect;
117/// §Fase 33.x.g — Closed-catalog runtime warnings for the SSE
118/// production path. Surfaces `axon-W002 streaming-not-supported`
119/// when the async streaming path falls back to legacy synchronous
120/// delivery (D5 — no silent degradation).
121pub mod runtime_warnings;
122/// §Fase 33.x.h — Process-wide runtime opt-in flags. Today carries
123/// the `tokenizer_fallback` flag that gates BPE-tokenized chunking
124/// on the SSE LEGACY path (D9 — opt-in; defaults OFF for v1.24.0
125/// wire byte-compat).
126pub mod runtime_flags;
127/// §Fase 33.x.b — Streaming-shaped execution plan extractor. Builds
128/// `StreamingExecutionPlan` from `.axon` source for the production
129/// async SSE path; pre-resolves per-step `BackpressurePolicy` via
130/// `stream_effect_dispatcher` so the hot per-chunk loop in
131/// `axon_server::server_execute_streaming_async` does not re-walk
132/// the AST per chunk. Rejects flows that use 33.x.b-unsupported
133/// features (anchors / lambda apply / let bindings / mid-stream
134/// use_tool / hibernate / pix) with a closed-catalog `PlanFallback`
135/// so the SSE handler can route them to the legacy synchronous path.
136pub mod flow_plan;
137/// §Fase 33.y.b — Per-IRFlowNode async dispatcher skeleton. Closed-
138/// catalog, compiler-enforced exhaustive match over the 45-variant
139/// `IRFlowNode` enum. Subsequent sub-fases 33.y.c–j replace the
140/// transitional legacy shim with real per-variant async handlers.
141/// 33.y.l retires the shim + the `LegacyShimHandled` outcome variant
142/// once every IR variant has its real handler.
143pub mod flow_dispatcher;
144/// §Fase 33.z.b — Streaming-via-dispatcher graft skeleton. Lifts
145/// `flow_dispatcher::dispatch_node` (Fase 33.y, 45/45 structurally
146/// complete) into the production SSE hot path behind the
147/// `AXON_STREAMING_VIA_DISPATCHER` runtime flag (default OFF;
148/// flip to ON for v1.27.0 stable in 33.z.c; legacy path retired
149/// in 33.z.e).
150pub mod streaming_via_dispatcher;
151pub mod flow_version;
152pub mod epistemic_capture;
153pub mod exec_context;
154pub mod graceful_shutdown;
155pub mod graph_export;
156pub mod health_check;
157pub mod hooks;
158pub mod http_tool;
159pub mod inspect;
160pub mod lambda_data;
161pub mod lambda_runtime;
162pub mod logging;
163pub mod migrations;
164pub mod output;
165pub mod parallel;
166pub mod plan_diff;
167pub mod plan_export;
168pub mod rate_limiter;
169pub mod request_binding;
170pub mod request_log;
171pub mod request_middleware;
172pub mod repl;
173pub mod replay;
174pub mod request_tracing;
175// §Fase 32.c — Body schema validation for first-class axonendpoint
176// routes. `route_schema` hosts the pure `validate_body` primitive +
177// `collect_type_table` walker. The fallback handler in `axon_server`
178// consults the table at request time per (method, path).
179pub mod route_schema;
180// §Fase 32.f — Idempotency-Key store for POST/PUT axonendpoint routes.
181// Stripe-compatible. Cross-tenant isolation via (client_id, path, key)
182// composite key. 24h default retention. Same-key-different-body
183// returns 422 per industry convention.
184pub mod idempotency;
185// §Fase 32.g — Auth scope (capability subset matching) for first-class
186// axonendpoint routes. `requires: [admin, legal.read, ...]` declarations
187// gate dispatch on declared_requires ⊆ token_capabilities. Closed slug
188// grammar shared with `axon_frontend::parser`. Mirror of Python
189// `_is_valid_capability_slug`.
190pub mod auth_scope;
191// §Fase 32.h — Replay-token binding for first-class axonendpoint routes.
192// Append-only log keyed by trace_id; populated on every successful 2xx
193// POST/PUT where `replay:` resolves to true. `GET /v1/replay/<trace_id>`
194// returns the original request body + response body + metadata for
195// regulatory audit (PCI DSS Req 10, FedRAMP AU-2, FRE 502, 21 CFR Part 11).
196pub mod axonendpoint_replay;
197// §Fase 33.b — Layer 1: flow execution event stream. Closed catalog of
198// {FlowStart, StepStart, StepToken, StepComplete, FlowComplete,
199// FlowError} per D2. Consumed by execute_sse_handler (33.c) for live
200// SSE forwarding; cross-stack drift-gated against the Python mirror.
201pub mod flow_execution_event;
202pub mod resilient_backend;
203pub mod retry_policy;
204pub mod runner;
205// §Fase 40.b — public shield-scanner registration hook. OSS ships no
206// scanners (identity); enterprise vertical crates register HIPAA/legal/AML
207// scanners here at boot. The `shield apply` handler consults it.
208pub mod shield_registry;
209pub mod server_config;
210pub mod server_metrics;
211pub mod session_scope;
212pub mod session_store;
213pub mod step_deps;
214pub mod storage;
215pub mod storage_postgres;
216// §Fase 35 — the `axonstore` cognitive data plane runtime. 35.b ships
217// `store::filter` (the parameterized where-expression compiler).
218pub mod store;
219pub mod stdlib;
220pub mod tenant;
221pub mod tenant_secrets;
222// §Fase 10.e — JWT signature verification + JWKS client. Used by
223// tenant::tenant_extractor_middleware when AXON_JWT_JWKS_URL is set.
224pub mod jwt_verifier;
225// §λ-L-E Fase 11.a runtime — `trust_verifiers` holds the runtime
226// implementations that the compiler recognises; `stream_runtime` is
227// the Stream<T> channel with policy dispatch. The compile-time
228// `refinement` and `stream_effect` catalogs live in `axon-frontend`.
229pub mod trust_verifiers;
230pub mod stream_runtime;
231// §Fase 33.e — Stream-effect dispatcher (Layer 4 of the Fase 33 cycle).
232// Bridges the `effects: <stream:<policy>>` declarations on tool
233// definitions to actual runtime backpressure behavior on the SSE
234// wire. The dispatcher itself is a thin composition over
235// `stream_runtime::Stream<T>` (which carries the policy semantics)
236// and the AST resolver (which extracts the declared policy from the
237// tool referenced by each step).
238pub mod stream_effect_dispatcher;
239// §Fase 33.f — Cooperative cancellation primitives (D6 cancel-safety).
240// `CancellationFlag` + `CancelOnDrop` are the building blocks that
241// bind SSE response lifetime to the executor's spawn_blocking task:
242// when the wire client disconnects, the consumer cancels the flag,
243// which the producer observes between event emissions and exits
244// early instead of running the flow to completion against a dropped
245// channel.
246pub mod cancel_token;
247// §Fase 33.z.k (v1.28.0) — Wire-format adapter framework.
248// `wire_format` defines the WireFormatAdapter trait + per-dialect
249// adapters (axon / openai / anthropic). The SSE producer in
250// `axon_server::execute_sse_handler` uses `select_adapter(dialect)`
251// to translate internal FlowExecutionEvents into the dialect-
252// specific wire shape adopters' SDKs expect.
253pub mod wire_format;
254// §Fase 39.b — Pure Silicon Cognition wire envelope. The canonical
255// `FlowEnvelope` payload for `transport: json` axonendpoint responses
256// + legacy `POST /v1/execute`. Isomorphic serialization of the
257// ψ-vector `⟨T, V, E⟩`. See `docs/fase/fase_39_pure_silicon_cognition.md`.
258pub mod wire_envelope;
259// §Fase 39.c — Wire envelope producer helpers. Closed-taxonomy
260// translators from runtime execution metadata into the wire envelope's
261// epistemic fields (`provenance_chain` + `blame_attribution`).
262pub mod wire_envelope_producers;
263// §Fase 39.f — Rust CLI binary parity. New subcommands that closed
264// the gap vs the Python CLI (`axon parse` aggregator + `axon fmt`
265// round-trip formatter).
266pub mod cli_parse;
267pub mod cli_fmt;
268// §λ-L-E Fase 11.b — Zero-Copy Multimodal Buffers.
269// `buffer` defines ZeroCopyBuffer (Arc<[u8]>-backed) + BufferKind
270// (open registry) + BufferPool (slab allocator with per-tenant
271// soft-limit accounting). `ingest` hosts the network deposit paths
272// (multipart/form-data streaming parser, WebSocket binary-frame
273// accumulator) that populate buffers without intermediate copies.
274pub mod buffer;
275pub mod ingest;
276// §λ-L-E Fase 11.c runtime — `replay_token` hosts ReplayToken canonical
277// hashing + pluggable ReplayLog + ReplayExecutor for re-running from
278// any token. The compile-time `legal_basis` catalog lives in
279// `axon-frontend`.
280pub mod replay_token;
281// §λ-L-E Fase 11.d — Stateful PEM over WebSocket. `pem::state`
282// defines CognitiveState with Q32.32 fixed-point float encoding
283// so density-matrix round-trips are bit-identical across reconnects.
284// `pem::continuity_token` is an HMAC-signed handshake that proves
285// a reconnecting client is the original party. `pem::backend`
286// exposes the PersistenceBackend async trait + in-memory impl;
287// production uses axon_enterprise::cognitive_states (Postgres +
288// envelope encryption).
289pub mod pem;
290// §λ-L-E Fase 11.e — Ontological Tool Synthesis binary pipelines.
291// `ots::pipeline` hosts Transformer trait + TransformerRegistry +
292// Dijkstra-based path search. `ots::native` seeds μ-law ↔ PCM16
293// + resample (8k/16k/48k ladder). `ots::subprocess::ffmpeg` is
294// the subprocess fallback with warm-pool + availability detection.
295// The compile-time slug catalog lives in `axon-frontend::ots_catalog`.
296pub mod ots;
297pub mod tool_executor;
298pub mod tool_registry;
299// §Fase 34.b (v1.29.0) — Tool trait + ToolChunk closed-catalog
300// surface for tools-as-stream-producers. Bridges adopter-source
301// `effects: <stream:<policy>>` declarations into the runtime via
302// the dispatcher's per-chunk wire emission path (Fase 34.d/g lands
303// the wiring; this module is the structural foundation).
304pub mod tool_trait;
305// §Fase 34.d (v1.29.0) — Bridge from ToolEntry (registry shape) to
306// Tool trait impls (dispatcher's streaming surface). The dispatcher's
307// `pure_shape::run_step` calls `tool_dispatch_bridge::resolve_streaming_tool`
308// for is_streaming-flagged tools + drains the resulting Stream<ToolChunk>
309// chunk-by-chunk into the wire.
310pub mod tool_dispatch_bridge;
311pub mod tool_validator;
312pub mod trace_export;
313pub mod trace_store;
314pub mod trace_stats;
315pub mod tracer;
316pub mod version_diff;
317pub mod webhook_delivery;
318pub mod webhooks;