mnemo_codemode/lib.rs
1//! v0.4.0 (P0-3) — Code-mode recall.
2//!
3//! Cloudflare's Code Mode MCP (announced 2026-04-24) showed that
4//! agents calling tools through generated host-side code instead of
5//! JSON tool envelopes can drop per-turn token cost by ~99.9%. The
6//! same shape applies to recall: instead of the LLM paying for
7//! `tool_call(recall, {query: "..."})` plus `tool_result([memory,
8//! memory, ...])` JSON each turn, the host hands the LLM a
9//! sandboxed wasm host whose imports it can call as plain functions.
10//!
11//! This crate ships:
12//!
13//! 1. The host-side data shapes [`CodeModeRecall`], [`RecallBundle`],
14//! [`ResourceBudget`].
15//! 2. A pure host-side runner [`run_code_mode_host`] that accepts a
16//! pre-built guest "program" (a list of recall calls) and produces
17//! a [`RecallBundle`] — used by the token-budget tests + the
18//! `mnemo recall --code-mode` CLI in the binary crate.
19//! 3. The WIT world definition under `wit/mnemo-memory.wit` describing
20//! the import/export surface a real wasm guest must implement.
21//!
22//! The wasmtime+wasi-stripping path lives behind the `wasm` feature
23//! and is wired in a follow-up; the host-side contract is fully
24//! tested today and is what mnemo-cli's `recall --code-mode`
25//! currently dispatches to.
26
27pub mod runner;
28pub mod token;
29
30pub use runner::{
31 CodeModeError, CodeModeRecall, GuestProgram, RecallBundle, RecallStep, ResourceBudget,
32 run_code_mode_host,
33};
34pub use token::estimate_tokens;