Files
craft-anything/examples/wasm-plugin-wordcount
Brandon Thomas f64ae3bf3c Craft Anything
A native, pure-Rust app that shows anyone how a piece of software works, with
evidence-backed answers, then helps them rebuild it. It ships a desktop app, a
CLI and an MCP server, all driven by one engine.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 10:52:14 -04:00
..
2026-10-31 10:52:14 -04:00
2026-10-31 10:52:14 -04:00
2026-10-31 10:52:14 -04:00
2026-10-31 10:52:14 -04:00
2026-10-31 10:52:14 -04:00

Example WASM plugin: word count

A Craft Anything plugin with one tool, count_words, written in Rust. It implements craft-anything:plugin/tools from crates/engines/wit/plugin.wit and imports nothing, so it runs sandboxed: no files, network or environment.

Build

rustup target add wasm32-unknown-unknown
cargo build --release --target wasm32-unknown-unknown
wasm-tools component new target/wasm32-unknown-unknown/release/wasm_plugin_wordcount.wasm -o wordcount.wasm

wasm-tools turns the core module into a component (cargo install wasm-tools, or a release download). wasm-tools component wit wordcount.wasm shows what it exports.

Use

Craft Anything built with --features wasm-plugins, and in config.toml:

[[plugins.wasm]]
id = "wordcount"
path = "/full/path/to/wordcount.wasm"

Its tool is then wordcount_count_words, everywhere: the app, the CLI (craft-anything-cli wordcount-count-words --text "one two"), MCP and the agent.

Check it

CRAFT_ANYTHING_TEST_WASM_PLUGIN=/full/path/to/wordcount.wasm \
  cargo test -p craft-anything-engines --features wasm-plugins the_example_plugin