Inventory of the 29 core plugins (22 done, 2 partial, 5 missing), 80 community plugins with a verdict each, a ranked roadmap with 8 ready briefs, the Bases spec (D1-D13) and 20 tasks, ASCII wireframes of the Bases screens (PaperCraft was not running). crates/bases is registered at layer L2. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2.7 KiB
TASK wasm-plugin-dice: the first first-party wasm plugin (Dice roller), proving the SDK path
Runs through OpenCode (specs/agents/opencode-runbook.md is attached automatically).
OWNER STEP 0 (before this brief runs; agents may not edit Cargo files)
rustup target add wasm32-unknown-unknown; in the root Cargo.toml add exclude = ["plugins"] to [workspace] so plugins/* crates build alone. Without it, stop and report.
OWNS
plugins/dice/Cargo.toml(own[workspace],crate-type = ["cdylib"], no dependencies,opt-level = "s",panic = "abort"),plugins/dice/src/lib.rs,plugins/dice/manifest.json,plugins/dice/build.sh,plugins/dice/README.md(the ONE doc this brief may create: the ABI walkthrough for plugin authors)crates/engine/tests/plugin_dice.rs
FILES TO OPEN
crates/plugins/src/lib.rs(ABI summary),crates/plugins/src/sandbox/abi.rs(exportsns_abi_version, alloc and command entry, packed(ptr<<32)|lenresults),crates/plugins/src/host.rs(HOST_CALLS)crates/plugins/tests/fixtures/good.watandcrates/plugins/tests/abi.rs(what a conforming module looks like and how it is driven)crates/engine/src/builtin/plugin_commands.rs,crates/engine/src/plugin_host/plugins.rs(howplugin.<id>.<command>is registered and run)
GOAL / API
A no_std-style Rust module implementing the ABI by hand (no wasm-bindgen): export ns_abi_version() -> 1, the allocator export the host expects, and one command roll: args {"expr":"2d6+3"} -> result {"total":n,"rolls":[..],"text":"2d6+3 = 10 [4,3] +3"}; supports NdM, +/- constant, kh/kl NOT supported (error). N at most 100, M at most 1 000. Randomness: ns.now() as the seed of an xorshift (no other entropy exists in the sandbox; say so in the README). With permission editor the command also calls insert_text with text. manifest.json: id dice, commands [{"id":"roll","name":"Roll dice"}], permissions ["editor"].
TESTS
crates/engine/tests/plugin_dice.rs: build step is NOT run by the test; the test loads plugins/dice/dice.wasm if present and is #[ignore] otherwise with the reason printed; asserts: ABI version, roll {"expr":"1d1"} gives total 1, 0d6 and 101d6 and 1d1001 are errors (guest error code, not a trap), insert_text is called once with the text, the plugin stays under the default fuel for 100d1000.
VERIFY
cd plugins/dice && ./build.sh # cargo build --release --target wasm32-unknown-unknown; copies dice.wasm next to manifest.json
cd - && cargo test -p notescraft-engine --test plugin_dice -- --include-ignored
DO NOT
Edit crates/plugins (if the ABI is awkward, list the pain points in the report: that is the point of this brief); commit the .wasm; add dependencies to the plugin.