Skip to main content

brokk_acp_sandbox/
lib.rs

1//! Pure-parsing logic for `brokk-acp-rust`, exported both as a Rust
2//! library (linked directly into the native binary) and -- via the
3//! companion binary in `src/bin/sandbox.rs` -- as a `wasm32-wasip2`
4//! component that the native binary spawns under wasmtime for
5//! sandboxed parsing of untrusted inputs.
6//!
7//! Everything here is dependency-light, has no fs/network/process
8//! access, and runs on every target Rust supports. The only inputs
9//! are owned strings or byte slices; the only outputs are `Serialize`
10//! data structures. Each function is a candidate for the wasm
11//! sandbox because the failure modes we care about are:
12//!
13//!   - YAML bombs / billion-laughs against `serde_yaml`
14//!   - Malformed frontmatter that triggers panics in third-party crates
15//!   - Future regex/zip parsers that can blow CPU or memory
16//!
17//! Adding a new parser to this crate is the standard path for getting
18//! "wasm-by-default with native fallback" coverage in `brokk-acp-rust`.
19
20pub mod search;
21pub mod skills;
22pub mod zip_reader;
23
24pub use search::{SearchError, SearchMatch, SearchOutcome, search as search_file_contents};
25pub use skills::{ParsedFrontmatter, parse_frontmatter, split_frontmatter};
26pub use zip_reader::{
27    ZipReadError, list_entry_names as list_zip_entry_names,
28    read_entries_with_prefix as read_zip_entries_with_prefix,
29    read_entry_bytes as read_zip_entry_bytes, read_entry_text as read_zip_entry_text,
30};
31
32/// Bytes of the `wasm32-wasip2` binary form of this crate. The host
33/// embeds these in wasmtime to run the same parsers inside a sandbox.
34/// Shipped as a committed artifact (see `wasm/brokk-acp-sandbox.wasm`)
35/// so consumers do not need the wasm toolchain to build against this
36/// crate.
37///
38/// Rebuild and re-commit when this crate's source changes:
39/// `cargo build --release --bin brokk-acp-sandbox --target wasm32-wasip2`
40/// then copy the artifact to `wasm/brokk-acp-sandbox.wasm`.
41pub const WASM_BYTES: &[u8] = include_bytes!("../wasm/brokk-acp-sandbox.wasm");