WASM Plugins (Experimental)
ghostdep can load community-contributed language plugins compiled as WebAssembly modules.
Status: The WASM host is functional but the plugin API is not yet formally documented. If you’re interested in writing a plugin, the information below should get you started. Expect the API to stabilize in a future release.
Plugin discovery
ghostdep looks for .wasm files in two locations:
plugins/in your project root~/.ghostdep/plugins/
Any .wasm file found is loaded automatically. If loading fails, a warning is printed and the plugin is skipped.
Expected exports
Your WASM module must export these functions:
| Function | Signature | Returns |
|---|---|---|
alloc | (len: i32) -> i32 | Pointer to allocated memory |
plugin_name | () -> i64 | Packed ptr:len string |
file_extensions | () -> i64 | Comma-separated list |
manifest_filenames | () -> i64 | Comma-separated list |
parse_manifest | (ptr: i32, len: i32) -> i64 | JSON response |
scan_imports | (ptr: i32, len: i32) -> i64 | JSON response |
is_stdlib | (ptr: i32, len: i32) -> i32 | 0 or 1 |
normalize_import | (ptr: i32, len: i32) -> i64 | Packed ptr:len string |
aliases | () -> i64 | JSON object |
String passing convention
Strings are passed through WASM linear memory. The host writes input strings using alloc, and reads output strings from packed i64 values where the high 32 bits are the pointer and the low 32 bits are the length.
JSON formats
parse_manifest receives:
{"content": "...", "path": "..."}
And returns an array of:
[{"name": "pkg", "normalized": "pkg", "group": "main"}]
scan_imports receives the same input and returns:
[{"raw": "pkg", "normalized": "pkg", "line": 1, "confidence": "high"}]
aliases returns:
{"import_name": "package_name"}
Error handling
- If a plugin fails to load, it’s skipped with a warning
- If a plugin panics during a function call, the file is skipped
- Plugin errors never crash the main process
Source reference
See src/plugin/wasm_host.rs for the full implementation.