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 accept;
41pub mod backend;
42pub mod bundle;
43pub mod caps;
44pub mod catalog;
45pub mod dag;
46pub mod documents;
47pub mod fetch;
48pub mod handles;
49pub mod hex;
50pub mod images;
51pub mod infer;
52pub mod ledger;
53#[cfg(feature = "llamacpp")]
54pub mod llamacpp;
55pub mod module_cache;
56pub mod ollama;
57pub mod pipeline;
58
59/// The shared Rhai interpreter's compiled bytes, embedded at compile time.
60///
61/// This is a checked-in binary asset (`assets/rhai-interpreter.wasm`), not
62/// built dynamically as part of an ordinary `cargo build --workspace` —
63/// `include_bytes!` is resolved by rustc while compiling *this* crate, so
64/// the file must already exist on disk before this crate compiles, and
65/// Cargo has no built-in way to cross-compile a sibling workspace member to
66/// `wasm32-unknown-unknown` first as part of building this one natively.
67/// Regenerate it with `scripts/rebuild-rhai-interpreter.sh` whenever
68/// `blocks/rhai-interpreter`'s source changes, and commit the result — CI
69/// independently checks the asset hasn't drifted (see
70/// `.github/workflows/ci.yml`).
71pub fn embedded_rhai_interpreter_bytes() -> &'static [u8] {
72 include_bytes!("../assets/rhai-interpreter.wasm")
73}
74/// Rendering PDF pages out-of-process, so a renderer crash cannot take the
75/// daemon with it.
76///
77/// Compiled unconditionally, unlike the rendering it performs. A binary that
78/// *might* be spawned as a worker has to recognise the worker argument even
79/// when it cannot render, or it falls through to its own argument parsing
80/// and answers a render request with usage text — which then surfaces as a
81/// per-item job failure reading `Error: usage: cuttlefishd <spec> ...` and
82/// says nothing about the real mismatch.
83pub mod render_worker;
84pub mod runner;
85pub mod warehouse;