Custom modules
Write your own module for a generated app without changing Core.
Tutorial
Build acme-disk, a module with one read-only operation that reports root filesystem use. You need the prerequisites and a checkout ($OSSIFRAME).
1. Generate an app
cd $OSSIFRAME
cargo run -q -p ossiframe-cli -- new /tmp/acme --name "Acme Ops" \
--identifier dev.example.acme --preset observe --ossiframe-local $OSSIFRAME--ossiframe-local is for development only (see Local mode and standalone mode).
2. Create the module
cargo run -q --manifest-path $OSSIFRAME/Cargo.toml -p ossiframe-cli -- \
new-module /tmp/acme --id acme-disk --name "Acme Disk"The CLI writes and registers:
| Path in the app | Content |
|---|---|
modules/acme-disk/Cargo.toml, modules/acme-disk/src/lib.rs | The Rust module with one operation, uptime (runs uptime -p) |
src/modules/acme-disk/index.ts, src/modules/acme-disk/AcmeDiskPage.tsx | The page |
src-tauri/Cargo.toml, src-tauri/src/lib.rs, src/modules.ts | Dependency, .register(acme_disk::AcmeDisk) and the UI import |
ossiframe.json | The localModules entry |
3. Change the operation
Edit modules/acme-disk/src/lib.rs:
- Rename the operation to
root-usageinOPERATIONSand in the check at the top ofrun. - Run a fixed command:
CommandSpec::new("df", &["-P", "/"], TIMEOUT). No user text reaches a shell. - Reject arguments:
if !args.is_null() { return Err(OperationError::InvalidArguments(...)) }, and rename_argstoargs. - Parse the second line of
df -P /(Filesystem 1024-blocks Used Available Capacity Mounted on) into a struct (size_kib,used_kib,use_percent), and return an error for output you cannot parse. - Add unit tests for a valid line and malformed lines.
4. Adjust the page
In src/modules/acme-disk/AcmeDiskPage.tsx, change the result interface to { observedAt, sizeKib, usedKib, usePercent }, call api.runOperation<RootUsage>(serverId, "acme-disk", "root-usage", null) and show the values as text in the KeyValue rows. The id in index.ts stays acme-disk.
5. Check it
cd /tmp/acme
pnpm install
pnpm exec tsc --noEmit
pnpm exec vite build
(cd src-tauri && cargo check && cargo test)
(cd modules/acme-disk && cargo test && cargo clippy -- -D warnings && cargo fmt)Observed: all steps passed, including the module's 3 tests. The module crate is its own Cargo workspace, so run its checks inside modules/acme-disk/. Apps sharing one CARGO_TARGET_DIR wait on its lock, so run steps one at a time.
The tutorial did not run the app against a server. Before calling the module done, run pnpm tauri dev, connect to a disposable server and open the page.
6. Remove the module
cargo run -q --manifest-path $OSSIFRAME/Cargo.toml -p ossiframe-cli -- remove /tmp/acme acme-diskThe CLI unregisters the module (dependency, registration, UI import) and keeps modules/acme-disk/ and src/modules/acme-disk/. Delete them to remove the module for good.
Module UI contract
src/modules/<id>/index.ts exports the items below; src/modules.ts imports each folder. Types: packages/ui/src/module-ui.ts.
| Export | Meaning |
|---|---|
moduleUi: ModuleUi | One page. Or |
moduleUis: ModuleUi[] | Several pages |
hooks | Optional { onStale, onConnected, onRemoved }, each called with a server id |
replaces: string[] | Page ids this module's pages replace. linux-audit replaces linux-inventory, and its Overview keeps that id |
ModuleUi fields:
| Field | Meaning |
|---|---|
id | The Rust module id, or <id>/<page> for several pages |
title | Page title |
Page | Component receiving { serverId, connected } |
group | Sidebar group heading. Pages without one are listed at the top level |
section | Pages sharing a section become one sidebar entry with tabs |
icon | A lucide-react icon for the entry |
offline | Page works without a connection (shows saved data) and renders while disconnected |
- Duplicate page ids throw
Duplicate module page id "<id>". - Render remote output as text.
AssistButton(@ossiframe/ui) renders nothing unless the app wraps its UI in theai-assistantprovider.
Core contract reference
Source: crates/ossiframe-core/src.
| Item | Contract |
|---|---|
Module (trait) | manifest() -> ModuleManifest, operations() -> &'static [OperationInfo], async run(operation, args, ctx) -> Result<serde_json::Value, OperationError>. run is called only with an id listed in operations(). The module validates args itself |
ModuleManifest | id: ModuleId, name, version, description, dependencies: Vec<ModuleId>. Metadata, not a sandbox |
OperationInfo | id: &'static str, description: &'static str |
OperationContext | exec: &dyn Executor, cancel: &CancelToken, observed_at (RFC 3339, set by the dispatcher). An operation reaches a server only through this |
CommandSpec | Program, arguments, timeout, Privilege and optional stdin. Built with CommandSpec::new(program, &[args], timeout) (user), privileged (root, absolute program path) or run_as (another user, absolute path). Every word is quoted; there is no shell syntax. Stdin is at most 1 MiB (MAX_STDIN_BYTES), never serialized and never in Debug output |
Privilege | User (the SSH login user), Root (sudo -n), RunAs(LinuxUserName) (sudo -n -u <user>, never root) |
Executor (trait) | async run(&CommandSpec, &CancelToken) -> Result<ExecResult, ExecError>. ExecResult has exit, stdout, stderr, truncated |
ReadOnly | Wrapper that refuses Root and RunAs with ExecError::PrivilegeDenied. It guards only code handed the wrapper, does not stop a user-level command from changing state, and is not a sandbox |
Registry | Registry::builder().register(module)....build(). Refuses duplicate ids, missing dependencies, dependency cycles and duplicate operations. run dispatches only to a listed operation of a registered module |
OperationError | InvalidArguments(String), Exec(ExecError) (converted with ?), Failed(String) (a short, redacted message, never raw command output) |
An ExecError other than PrivilegeDenied means the outcome is unknown. Never retry automatically.
Local mode and standalone mode
The generated src-tauri/Cargo.toml gets Ossiframe from one of two sources.
- Standalone (default). Git dependencies on one exact commit of
https://github.com/shojibur/Ossiframe:--rev, orHEADof the checkout (refused with uncommitted changes). The generator does no network access, so push the commit first orcargo buildfails. Verified to build, connect and show inventory on a real server (record). - Local (
--ossiframe-local <path>).pathdependencies into your checkout, for local testing only. Switch to a publishedrevbefore sharing the app. A working local build does not show that the standalone build works.
An explicit --rev must match the generator, frontend packages and template: the generator copies @ossiframe/ui, @ossiframe/client (not on npm) and the template from your checkout, while the Rust crates come from the pinned commit.
