Skip to content

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 ​

sh
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 ​

sh
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 appContent
modules/acme-disk/Cargo.toml, modules/acme-disk/src/lib.rsThe Rust module with one operation, uptime (runs uptime -p)
src/modules/acme-disk/index.ts, src/modules/acme-disk/AcmeDiskPage.tsxThe page
src-tauri/Cargo.toml, src-tauri/src/lib.rs, src/modules.tsDependency, .register(acme_disk::AcmeDisk) and the UI import
ossiframe.jsonThe localModules entry

3. Change the operation ​

Edit modules/acme-disk/src/lib.rs:

  • Rename the operation to root-usage in OPERATIONS and in the check at the top of run.
  • 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 _args to args.
  • 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 ​

sh
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 ​

sh
cargo run -q --manifest-path $OSSIFRAME/Cargo.toml -p ossiframe-cli -- remove /tmp/acme acme-disk

The 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.

ExportMeaning
moduleUi: ModuleUiOne page. Or
moduleUis: ModuleUi[]Several pages
hooksOptional { 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:

FieldMeaning
idThe Rust module id, or <id>/<page> for several pages
titlePage title
PageComponent receiving { serverId, connected }
groupSidebar group heading. Pages without one are listed at the top level
sectionPages sharing a section become one sidebar entry with tabs
iconA lucide-react icon for the entry
offlinePage 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 the ai-assistant provider.

Core contract reference ​

Source: crates/ossiframe-core/src.

ItemContract
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
ModuleManifestid: ModuleId, name, version, description, dependencies: Vec<ModuleId>. Metadata, not a sandbox
OperationInfoid: &'static str, description: &'static str
OperationContextexec: &dyn Executor, cancel: &CancelToken, observed_at (RFC 3339, set by the dispatcher). An operation reaches a server only through this
CommandSpecProgram, 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
PrivilegeUser (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
ReadOnlyWrapper 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
RegistryRegistry::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
OperationErrorInvalidArguments(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, or HEAD of the checkout (refused with uncommitted changes). The generator does no network access, so push the commit first or cargo build fails. Verified to build, connect and show inventory on a real server (record).
  • Local (--ossiframe-local <path>). path dependencies into your checkout, for local testing only. Switch to a published rev before 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.

Released under the MIT License.