Skip to main content

cuttlefish_host/
lib.rs

1//! The wasmtime host: drives proc-blocks and enforces what they may reach.
2//!
3//! This crate is where the project's security boundary actually lives. The
4//! compile-time capability check in `cuttlefish-core` exists to give spec
5//! authors good error messages; the checks in [`caps`] are what a malicious or
6//! malfunctioning block actually runs into, and they fail closed.
7//!
8//! Three pieces, in the order a job meets them:
9//!
10//! - [`caps`] — what a job may reach. Deny-by-default, and canonicalizing to
11//!   defeat traversal and symlink escapes.
12//! - [`handles`] — files held open on the guest's behalf, served as bounded
13//!   windows so that bulk data never enters guest memory.
14//! - [`runner`] — the reactor loop: the host drives the guest one command at a
15//!   time, which is what makes cancellation free and every iteration
16//!   observable.
17//!
18//! Inference reaches the runner only through [`infer::InferBackend`], so the
19//! whole loop is testable with no model present. Which implementation a job gets
20//! is decided by [`backend::Registry`], so adding a provider — an
21//! OpenAI-compatible endpoint, an embedded llama.cpp — is additive rather than a
22//! change to the runner, the parser, or the daemon. [`ollama`] is the first real
23//! one.
24//!
25//! [`catalog`] is a local, content-addressed store mapping `name@version` to
26//! a cataloged wasm block or bundle, so a pipeline can reference a block by
27//! name instead of a filesystem path. Purely local filesystem operations —
28//! no network. The daemon does consult it (resolving a spec's pipeline
29//! entries at startup, via [`pipeline::resolve_and_load`]), but the catalog
30//! itself has no daemon-specific logic: the same resolution runs identically
31//! from `cuttlefish build`.
32//!
33//! [`bundle`] packages a [`pipeline::Checked`] pipeline into the `.cfbundle`
34//! container `cuttlefish build` emits — the write side of what
35//! `catalog`'s `read_bundle_signature` reads.
36
37#![forbid(unsafe_code)]
38#![warn(missing_docs)]
39
40pub mod backend;
41pub mod bundle;
42pub mod caps;
43pub mod catalog;
44pub mod dag;
45pub mod documents;
46pub mod handles;
47pub mod infer;
48pub mod ledger;
49#[cfg(feature = "llamacpp")]
50pub mod llamacpp;
51pub mod module_cache;
52pub mod ollama;
53pub mod pipeline;
54
55/// The shared Rhai interpreter's compiled bytes, embedded at compile time.
56///
57/// This is a checked-in binary asset (`assets/rhai-interpreter.wasm`), not
58/// built dynamically as part of an ordinary `cargo build --workspace` —
59/// `include_bytes!` is resolved by rustc while compiling *this* crate, so
60/// the file must already exist on disk before this crate compiles, and
61/// Cargo has no built-in way to cross-compile a sibling workspace member to
62/// `wasm32-unknown-unknown` first as part of building this one natively.
63/// Regenerate it with `scripts/rebuild-rhai-interpreter.sh` whenever
64/// `blocks/rhai-interpreter`'s source changes, and commit the result — CI
65/// independently checks the asset hasn't drifted (see
66/// `.github/workflows/ci.yml`).
67pub fn embedded_rhai_interpreter_bytes() -> &'static [u8] {
68    include_bytes!("../assets/rhai-interpreter.wasm")
69}
70/// Rendering PDF pages out-of-process, so a renderer crash cannot take the
71/// daemon with it.
72#[cfg(feature = "pdf-render")]
73pub mod render_worker;
74pub mod runner;