Skip to content

Phase 3b: WASM plugin runtime for custom suggest rules #144

@Kadajett

Description

@Kadajett

Context

Part of the --suggest recommendations engine (see #135). Depends on #137, #142. This is the advanced extensibility layer — declarative YAML rules (#142) cover 80% of use cases; WASM covers the remaining 20% that need programmatic logic.

What to Build

1. WASM plugin interface via wasmtime

Add wasmtime dependency. Plugin contract:

Input: JSON-serialized SuggestContext (symbols, call graph, metrics) passed to WASM module's exported evaluate function.

Output: JSON array of Recommendation structs returned from the WASM function.

// src/suggest/wasm_runtime.rs
pub struct WasmPluginRunner {
    engine: wasmtime::Engine,
    plugins: Vec<WasmPlugin>,
}

pub struct WasmPlugin {
    name: String,
    module: wasmtime::Module,
}

impl WasmPluginRunner {
    pub fn load_plugins(dir: &Path) -> Result<Self>;
    pub fn evaluate(&self, ctx: &SuggestContext) -> Vec<Recommendation>;
}

2. Plugin discovery

  • Load .wasm files from .semfora/plugins/
  • Each WASM module must export: fn evaluate(context_json: &str) -> String (JSON in, JSON out)
  • Provide a manifest format (.semfora/plugins/manifest.yaml) for metadata (name, group, description)

3. SDK / template

  • Provide a Rust template project (semfora-plugin-template) that compiles to WASM
  • Include helper types matching Recommendation, SuggestContext as a shared crate
  • README with instructions for building plugins in Rust, AssemblyScript, or Go

4. Security

  • WASM runs sandboxed (no filesystem, no network by default)
  • Configurable memory limit per plugin
  • Timeout per plugin evaluation (default: 5s)

Acceptance Criteria

  • wasmtime integrated, plugins load from .semfora/plugins/
  • A sample Rust WASM plugin compiles and produces recommendations
  • Plugin timeout and memory limits enforced
  • Plugins register alongside built-in and declarative rules in SuggestEngine
  • --suggest flag behind wasm cargo feature (optional dependency)
  • Documentation for writing WASM plugins

Notes

  • This is a lower priority than Phase 3a. Consider making it a cargo feature (--features wasm-plugins) so it's opt-in.
  • wasmtime adds ~10MB to binary size — feature-gate it.

References

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions