Repository navigation
Plugins in WASM: sandbox, host ABI, dynamic commands, plugin window, ribbon tabs and SDK - #256
Conversation
…, ribbon tabs and SDK - core: a session's registry of external commands and owned undo-step labels, without changing the static commands - crates/plugin: the folder, strict manifests, the wasmi sandbox (64 MB, fuel, 5 s, 1000 commands, 16 MB), the files permission, the log and one transaction per call - crates/plugin-sdk and plugins/area-summary: the guest SDK and the example, built for wasm32-unknown-unknown - CLI, MCP (catalog with plugin marks, bridge catalog) and the desktop (folder read on a thread) - Manage > Plugins and per-plugin ribbon tabs, translated strings, tests, docs/areas/plugins.md
…the window's restart A new or opened project rebuilds the window from the session (BimApp::reopened); it kept the session's external commands but not the plugins and their ribbon tabs, so Manage > Plugins and the plugin tab vanished until the next start. Carry them, re-register the commands and rebuild the tabs, with a UI test.
# Conflicts: # README.md # translations/ui/bimcraft-ui.pot # translations/ui/cs.po # translations/ui/de.po # translations/ui/es.po # translations/ui/fr.po # translations/ui/nl.po # translations/ui/pt.po # translations/ui/zh.po # translations/ui/zh_TW.po
# Conflicts: # CLAUDE.md # crates/core/src/engine.rs # translations/ui/bimcraft-ui.pot # translations/ui/cs.po # translations/ui/de.po # translations/ui/es.po # translations/ui/fr.po # translations/ui/nl.po # translations/ui/pt.po # translations/ui/zh.po # translations/ui/zh_TW.po
…n's report
- keep the last steps of a plugin call (command and parameters, log, info) with the fuel left at each, so a trap or an
out-of-fuel call names what it was running and the log says where the fuel went; a guzzler test covers it
- inspect {brief: true} answers without the library's types and materials, which is most of its bytes and fuel
- a function whose JSON has a string "report" opens it in the window under the button's label, with Copy and Close
- docs/areas/plugins.md explains both
FXC (the HLSL compiler behind D3D12) refuses a fragment function whose last statement is discard and which has no return after it: "error X3507: 'fs_wire': Not all control paths return a value". The function discards most pixels, so an unreachable return after discard changes nothing, but makes every path whole. This is a bug in main's gpu.wgsl, inherited by this branch when it merged dde24e2; Linux and macOS compile the WGSL with other backends and did not see it.
…t and instanced draws Two CI flakes in main's new 3D tests, unrelated to the plugins: - a view being made is Quiet for a moment and asks for a repaint after it; run() chases that to its 32-step limit on a slower runner, so the test takes one step, which is the frame it asks about. - a flat draw and an instanced one round an edge pixel differently on D3D12; one pixel is not a different picture.
# Conflicts: # crates/ui-egui/src/gpu.rs # crates/ui-egui/src/gpu.wgsl
# Conflicts: # crates/ui-egui/src/lib.rs # translations/ui/bimcraft-ui.pot # translations/ui/cs.po # translations/ui/de.po # translations/ui/es.po # translations/ui/fr.po # translations/ui/it.po # translations/ui/nl.po # translations/ui/pt.po # translations/ui/vi.po # translations/ui/zh.po # translations/ui/zh_TW.po
# Conflicts: # crates/ui-egui/src/lib.rs # translations/project/bimcraft-project.pot # translations/project/cs.po # translations/project/de.po # translations/project/es.po # translations/project/fr.po # translations/project/it.po # translations/project/nl.po # translations/project/pt.po # translations/project/sv.po # translations/ui/bimcraft-ui.pot # translations/ui/cs.po # translations/ui/de.po # translations/ui/es.po # translations/ui/fr.po # translations/ui/it.po # translations/ui/nl.po # translations/ui/pt.po # translations/ui/vi.po # translations/ui/zh.po # translations/ui/zh_TW.po
IPedrax
left a comment
There was a problem hiding this comment.
Thanks, this is careful work: a fresh instance per call, fuel and a memory limit, an import allowlist, caps on every buffer, a plugin that can't shadow a built-in command, and a failed call that takes the model and the undo history back. It merges with today's main with only the catalogs to redo. A few things need changing before it goes in, mostly around the files permission.
1. The files permission is granted by the plugin itself. Manifest::files() reads the manifest's own permissions, so any plugin that asks for it gets it, and a plugin dropped in the folder runs at the next start. It should be the user's to grant: off until they say yes in Manage > Plugins (kept beside disabled.json), with the window saying which plugin asks and why.
2. It is a list of commands to refuse, and it misses some. FILE_COMMANDS plus needs_files leave these reaching the disk without the permission:
- writing to any
path:schedule,export_crosscheck,export_fill_patterns; - reading any
path:import_fill_patterns,compare_crosscheck, and a material'stexture.path.
The list will also miss the next command that takes a path. Could it be the other way round: a mark on Command (or a list in the core, next to ALL) of the commands that touch the disk, with a test that fails when a command reads a path parameter and isn't marked? Then the plugin crate checks the mark and nothing slips through by being new.
3. Tables have no limit. StoreLimitsBuilder sets memory_size only. table_elements (and tables, instances, memories) are unbounded, so a module can declare or grow a large table. I haven't confirmed whether wasmi's fuel stops a big table.grow first, but setting .table_elements(...) and the counts is cheap, and a test with a table.grow of a large delta would show it.
4. The sample test runs the committed area_summary.wasm, not the one CI builds. tests/sample.rs loads plugins/area-summary/, whose module is the binary in the repository, while the CI step builds a fresh one into target/ that nothing loads. Please drop the binary from git and have the test load the built module (skipping with a message where the wasm32 target isn't installed), or have CI check that the built bytes equal the committed ones.
Smaller:
Runtime::invokemoves the wholeSessioninto the store. If the interpreter ever panicked,execute_external'scatch_unwindwould bring the model and the undo history back, but the session itself would be theSession::new()left in its place: its path and the plugin registry go. Swapping out only what the host functions need, or putting the session back in a guard, would close that.- Find (Ctrl+K) doesn't list plugin functions. The ribbon and the Tools palette do.
Once 1 to 4 are in, I'll run the full checks here and merge.
A plugin reaches the disk only with the `files` permission, and until now the plugin crate kept a list of the commands that do: `FILE_COMMANDS` and `needs_files`, next to the sandbox. A list of refusals misses what it doesn't name, and it did: `schedule`, `export_crosscheck` and `export_fill_patterns` wrote to any `path`, `import_fill_patterns` and `compare_crosscheck` read one, and a material's `texture.path` was read without the permission. The next command to take a path would have been missed too. So the command says it itself: `Command.files` is `None`, `Read`, `Write`, or `Conditional` for the ones that only take a path with some parameters (render, family, material, favorite), and `engine::touches_files` reads the mark and, for those, the parameters. The catalog carries it as `"files": "read"|"write"|"conditional"`, so agents see which commands need the permission. A test walks every command's parameter schema and fails when a `path`, `save` or a texture's picture isn't marked, which is what keeps a new command from slipping through.
`needs_files` checked an id against `FILE_COMMANDS` and a handful of special cases. The command itself now says whether it touches the disk (`Command.files`, `engine::touches_files`), so the sandbox asks that and the list goes: a command added since cannot be missed here, because there is nothing here to miss. The refusal says what the command wanted to do (read or write files).
`Manifest::files()` read the plugin's own `permissions`, so a plugin dropped in the folder ran at the next start with whatever it asked for — the permission was the plugin's to give itself. The manifest is now a request (`Manifest::asks_for`), and Manage > Plugins is where the user answers it: the row of a plugin that asks says so, with the plugin's own description as the reason, and a button allows or takes back the access. The answer is kept in the folder's `state.json` beside the switched-off list (an older `disabled.json` is still read, and the first write lands in the new file), so it survives a restart, a switch-off and a refresh. A grant is only possible for a plugin that asks: `Plugins::set_permission` refuses otherwise, and `register` gives the flag to a call only when both the ask and the grant are there.
`StoreLimitsBuilder` set `memory_size` alone: `table_elements`, `tables`, `instances` and `memories` were unbounded, so a module could declare or grow a large table and hold the host's memory that way. The store now limits them (16,384 elements in all tables, 4 tables, 8 instances, 1 memory), which stops a `table.grow` before it runs. A table the limiter doesn't measure at declaration is measured after the instance starts, as the memory is, so a module declaring a huge one is refused before it does anything. Two WAT fixtures cover both: one grows a table by a million, one declares a table of a hundred thousand.
…itory `tests/sample.rs` loaded `plugins/area-summary`, whose module was the binary in the repository, while the CI step built a fresh one into `target/` that nothing loaded: the test checked a file nobody rebuilt. The example goes: no plugin crate in the repository, and no `.wasm` in git. Its check does not: the guest SDK is the only crate with `unsafe` in it, and the sample was the one place that proved `export!`, the allocator and the host's pointers work against the ABI. So the plugin becomes a test fixture (`tests/sample-plugin`, a tiny `cdylib` of its own) built for `wasm32-unknown-unknown` before the tests, and the test loads that build through `bimcraft_plugin::testing`. Without the build the tests skip with the command to run; in CI (`CI=1`) a skip is a failure, and CI builds the fixture before `cargo test`. What an author needs from the example — the manifest, the crate and a handler — stays in `docs/areas/plugins.md`.
`invoke` moved the whole session into the store with `mem::replace`, and put it back only on the paths it wrote. A trap is a `Result` and came back; a panic of the interpreter did not: `execute_external`'s `catch_unwind` brought the model and the undo history back, but the slot held the `Session::new()` the replace left there, so the session's path and its plugin registry were gone. A guard takes the session out of the caller's slot for the call and puts it back when it drops — the end of the call, an early return, or a panic unwinding through it — so the slot never keeps a session the call left empty.
Ctrl+K found the tools and the views, but not a plugin's functions: the ribbon tab and the Tools palette listed them, and the one place that searches everything by name did not. `Found` gains `Plugin(id)`, `find_matches` appends the loaded plugins' functions as `«label» · «plugin»`, and a match runs the function exactly as its ribbon button does, report dialog included.
With `plugins/area-summary` gone, the window's tests cannot keep a plugin's manifest and a built module apart: the folder they hand the app holds the manifest and the module `crates/plugin/tests/sample-plugin` builds. A test finds it through `bimcraft_plugin::testing`, and skips with the command to run where it isn't built — a failure in CI, as in the plugin crate's own test. The file-access test writes the module beside its manifest, so the app's own refresh finds it as it would a plugin a user built.
`docs/areas/plugins.md` said the file commands were a list of names; it now says the permission is the user's, granted in Manage > Plugins and kept in `state.json`, and that a command's own mark in the core is what the host checks, with the catalog's `"files"` for agents. The limits gain the tables. The build section no longer points at an example that isn't there: it shows the crate, the manifest and a handler an author writes. `crates/plugin/CLAUDE.md` and `crates/plugin-sdk/CLAUDE.md` say the same for whoever works here next, and the README's plugin row too. The catalogs are regenerated for the window's new strings.
# Conflicts: # crates/core/src/commands.rs # translations/project/bimcraft-project.pot # translations/project/cs.po # translations/project/de.po # translations/project/es.po # translations/project/fr.po # translations/project/it.po # translations/project/nl.po # translations/project/pt.po # translations/project/sv.po # translations/ui/bimcraft-ui.pot # translations/ui/cs.po # translations/ui/de.po # translations/ui/es.po # translations/ui/fr.po # translations/ui/it.po # translations/ui/nl.po # translations/ui/pt.po # translations/ui/vi.po # translations/ui/zh.po # translations/ui/zh_TW.po
…s permission A ribbon button runs its function with no parameters, so a function whose manifest makes `path` required — an "Open File" button, say — was called with none and the plugin answered "`path` is required", even with the `files` permission granted. Now a click on such a function asks for the file in the system's dialog first and runs it with the chosen path; Find (`Ctrl+K`) does the same. The permission is checked before the dialog, not after: a plugin whose manifest asks for `files` and that the user hasn't allowed opens no dialog at all — the status bar says that the plugin isn't allowed to open files and that "Allow file access" in its row of Manage > Plugins is the way to allow it. `Plugins::refresh` reads the folder it was given: the refresh after a grant took the folder with it as it moved the new state into place, and a granted plugin lost its permissions with it. The sample plugin gains `open_file`, so the test runs the same shape a real plugin has: no dialog without the permission, a report in the window with it.
|
All four points and both "Smaller" ones are in, and the branch is merged with today's 1. The
|
The plugin and window tests run on Windows and macOS too, and they load the fixture's module; in CI a missing build is a failure (the tests skip only outside it), so the step guarded by `runner.os == 'Linux'` left those two runners failing at `tests/sample.rs` with "the sample plugin isn't built".
# Conflicts: # README.md # translations/project/bimcraft-project.pot # translations/project/cs.po # translations/project/de.po # translations/project/es.po # translations/project/fr.po # translations/project/it.po # translations/project/nl.po # translations/project/pt.po # translations/project/sv.po # translations/ui/bimcraft-ui.pot # translations/ui/cs.po # translations/ui/de.po # translations/ui/es.po # translations/ui/fr.po # translations/ui/it.po # translations/ui/nl.po # translations/ui/pt.po # translations/ui/vi.po # translations/ui/zh.po # translations/ui/zh_TW.po
# Conflicts: # crates/ui-egui/src/tests/gpu.rs
The Windows job died with 0xc0000005 (STATUS_ACCESS_VIOLATION) 2.7 s into the ui-egui test binary, while Linux and macOS passed the same code, and the gpu code it ran next (`a_model_with_nothing_to_draw_draws_the_ground`) is unchanged since the last green Windows run. The rerun tells a flake of the D3D12 software card apart from a real break; the checks API has no rerun for a fork's pull request.
|
Windows and macOS are green now. What broke them: the CI step that builds the guest SDK's test fixture ( The following Windows run then died once with |
…the 3D mouse, floors with openings Brings upstream's IPedrax#269 (pipe, data and earthing connectors with a place, FORMAT 18), IPedrax#270, IPedrax#290, IPedrax#256 (WASM plugins), IPedrax#283, IPedrax#307 (SpaceMouse), IPedrax#200, the UI test harness changes and floors cut round their openings. Conflicts resolved: - commands.rs: our reference_plane and edit_work_plane kept before point_cloud, which upstream made edit_files; the family command's params doc takes upstream's connector fields with ours (adaptive, options, nested...). - family.rs: upstream's Connector doc, which now says where it is and faces. - model.rs: both sides' 18 described in one paragraph for now (the next commit makes ours 19); component_room_point (ours) and component_connectors (upstream's) both kept, the latter placing through component_placement so a component hosted on a tilted plane or a face carries its connectors with it (upright, the same numbers as before). - editor.rs: ours. Upstream's Connectors tab belonged to the old dialog; connectors are now elements of the family document (editor/connectors.rs): placed from Create > Connectors, listed in the Project Browser, shown and typed in Properties when selected, deleted as forms are. IPedrax#269's UI test reaches them that way. - CLAUDE.md, README.md: both sides' lines (spacemouse.rs, Plugins row). - Cargo.lock: upstream's, with our egui_kittest features and image. - Catalogs: ours, regenerated, every translation of both parents kept where its message still exists. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01NVBR7rAfyvMsaXhi1B3YLr
Query timber framing members and clear bays around a hosted window Its tests keep their own copy of the history, as Session::history borrows the session since #256.
script: dry_run, a script tried and taken back, that says what it would make, change and remove Its tests keep their own copy of the history, as Session::history borrows the session since #256.
script: dry_run, a script tried and taken back, that says what it would make, change and remove Its check as each command runs covers the favorites through touches_files (#256), so the line pre-check main had for them goes; its favorites test stays, told the new words.
The plugin tests (#256) load the guest SDK's sample module and fail in CI without it; ci.yml builds it, release.yml didn't, so every release run's Windows, Linux and macOS tests failed.
The plugin tests (#256) load the guest SDK's sample module and fail in CI without it; ci.yml builds it, release.yml didn't, so every release run's Windows, Linux and macOS tests failed.
What this adds
BIMCraft plugins in WebAssembly: a user drops a folder into the plugin folder, the app picks it up, its functions become commands and a ribbon tab, and they run in a sandbox that reaches the model only through commands.
Video : https://youtu.be/OuOVO3mU8HE
IDEAS : ENG-01
crates/core): a session-owned registry of external commands (Session::register,external,catalog,unregister_plugin) beside the static list, with owned undo-step labels. Without plugins the catalog, errors and history are byte-for-byte as before. Read-only sessions also guard plugin calls: reads answer, changes are taken back and refused.crates/plugin: the folder and strict manifests, the wasmi sandbox of host ABI 1, permissions, log, limits and the command bridge. One call is one transaction and one undo step; a trap, out-of-fuel, memory overrun, a wrong reply, a command storm, the wall clock or bad JSON is the call's error, never a crash.crates/plugin-sdkandplugins/area-summary: the guest SDK (execute,note,host_info,export!) and a complete example (rooms' areas, a note written back, errors rolled back), built forwasm32-unknown-unknown.commands/list_commandswith apluginmark, andmcp --connectasks the window's catalog over the bridge ({"op": "catalog"}).Tab::Plugin), or its functions go in the common Plugins section; a disabled plugin's tab and commands go at once. Plugin labels are data and are not translated; the window's own strings are.docs/areas/plugins.md, crate notes, README, NOTICE (wasmi and its dependencies), CI builds the example for WASM, and the integration test runs the built module.Limits
64 MB of guest memory, 20 M fuel (about a second), 5 s of real time, 1000 commands a call, 16 MB a reply, 16 MB a module, 1 MB a manifest. Imports are limited to
bimcraft.execute,bimcraft.logandbimcraft.info; the file commands need thefilespermission, checked by the host before the command runs.Measurements (Linux x86-64, release)
bimcraft-cli: 33,121,456 bytes; wasmi/wasmparser symbols are 1,177,673 bytes (≈1.15 MB).bimcraft-cli commandsover 200 runs: 1.37 s without plugins, 1.91 s with the 82 KB example — about 2.7 ms to read, check and compile one plugin.Checks
cargo fmt --checkcargo clippy --workspace --all-targets -- -D warningscargo test --workspace(all green, including the sandbox, folder, undo, permissions, read-only, CLI/MCP and UI plugin tests)cargo i18n checkcargo build --manifest-path plugins/area-summary/Cargo.toml --target wasm32-unknown-unknown --releaseThe branch is merged with current
main. It does not touch the.bimcraftformat.