PITWALL

Extensions quick start

Preview

Preview. This page takes you from an empty folder to a tile running in Pitwall: scaffolded, reloaded on every save, checked, tested, and shared with someone else as a folder.

Before you start

You need Rust, installed with rustup, and its WebAssembly target. The target is the only addition the SDK needs: no cargo-component, no other tools.

rustup target add wasm32-wasip2

You also need Pitwall's CLI, pitwall, which comes with the app (see the CLI reference). The pitwall extension new, check and test commands work on a folder without the app running; dev and install work with the running app.

Make a tile

pitwall extension new writes a Cargo project into a new folder. The folder's name is the extension's id: lowercase letters, digits and hyphens.

pitwall extension new my-tile --template blank
cd my-tile

There are four templates:

TemplateWhat it isShows
blankA counter kept in storageElements, listeners, storage
listA checklist you add to, tick and filter; it can be opened with a list to showKeys on rows, scrolling, text fields, content, save_state
formA form that saves notes, signed with a setting; it can be opened with a draftMulti-line fields, settings, toasts
programA tile and Setup view that check Git's version after approvalprograms, exact command patterns, completion events, fake native helpers in tests

pitwall extension new my-helper --program is shorthand for --template program. Opening its Setup view runs nothing. The user grants Programs and clicks Check Git version, then approves the exact git --version command. Its harness tests use fake output and never run Git. See Programs and servers for supervision and downloads.

--name "My tile" sets the name Pitwall shows (by default it comes from the folder's name). Until the SDK is on crates.io, the project takes it from Pitwall's repository on GitHub; --sdk <checkout> takes it from a local checkout instead.

The new project holds:

FileWhat
extension.jsonThe manifest: id, name, version, the tile (contributes.tiles), settings, permissions with your reasons
Cargo.tomlA library with crate-type = ["cdylib"], the pitwall-extension SDK, and pitwall-extension-test for tests
src/lib.rsThe tile: its state, render, listeners
tests/tile.rsTests that build the tile and run it in Pitwall's tile runtime
input.schema.jsonlist and form only: what the tile can be opened with, as a JSON schema
README.mdHow to develop it
LICENSEApache-2.0 license text, matching the generated manifest
AGENTS.md, .claude/skills/, .agents/skills/The authoring skill, for a coding agent working in the project (For coding agents)

The tile

This is the blank template's tile. NAME is a constant above it that new fills in with the tile's name.

#[derive(Default)]
struct App {
    clicks: u32,
}

impl Tile for App {
    fn new(_cx: &mut Cx<Self>) -> Self {
        // What the user must not lose goes in storage: on disk at once,
        // kept across restarts and updates.
        let clicks = storage::get_json("clicks").ok().flatten().unwrap_or(0);
        App { clicks }
    }

    fn render(&mut self, _view: &str, cx: &mut Cx<Self>) -> impl IntoElement {
        v_flex()
            .size_full()
            .gap_2()
            .p_3()
            .child(text(NAME).text_lg().font_semibold())
            .child(text(format!("Clicked {} times", self.clicks)).text_color(Token::Text2))
            .child(
                h_flex()
                    .gap_2()
                    .child(button("Click me").primary().on_click(cx.listener(|this, _, cx| {
                        this.set_clicks(this.clicks + 1);
                        cx.notify();
                    })))
                    .child(button("Reset").on_click(cx.listener(|this, _, cx| {
                        this.set_clicks(0);
                        cx.notify();
                    }))),
            )
    }
}

impl App {
    fn set_clicks(&mut self, n: u32) {
        self.clicks = n;
        if let Err(e) = storage::set_json("clicks", &n) {
            log::warn(format!("the count wasn't saved: {e}"));
        }
    }
}

pitwall_extension::export!(App);
  • new makes the tile's state. Here it reads the count kept in storage.
  • render returns the tree of one view. Pitwall calls it after the view opens and after a listener calls cx.notify().
  • cx.listener makes a click handler. It gets the tile, the event and the context.
  • export! makes App the component's tile, once per crate.

Tiles and UI components describes the elements, styles and events.

The manifest

extension.json describes the extension. The fields a tile project uses:

FieldMeans
vThe manifest format: 2 for extensions with tiles
idThe extension's id, the same as the folder's name
name, description, iconWhat Pitwall shows for it
versionIts version, like 0.1.0
pitwallThe oldest Pitwall it runs on, like >=0.9.0
settingsSettings Pitwall draws a form for (Platform services)
permissionsEach permission it asks for, with your reason (Permissions)
contributes.tilesIts tiles. Each has an id, a title, an icon, the component ("wasm": "tile.wasm"), the world ("world": "pitwall:tile@0.1.0") and, when it can be opened with content, its schema ("input": "input.schema.json")

An extension has one component. Every tile entry names the same tile.wasm, and each tile id is a view that component renders.

Develop with pitwall extension dev

pitwall extension dev

Each round, dev builds the tile (cargo build --release --target wasm32-wasip2), copies the component to tile.wasm beside extension.json, checks it as pitwall extension check does, and loads it into the running Pitwall. It does this once at the start and again after every save in the folder (changes in target/ and to tile.wasm are ignored), and prints one JSON line per round. --once does one round and exits, with status 1 when the build or the check failed. A round whose build or check fails loads nothing.

Loading into Pitwall. The first time, Pitwall asks you to confirm. It then lists the folder in Settings → Extensions as a development extension, loaded where it is (never copied or updated), and turns it on. Open the tile from the command palette: "Open <tile title> (<extension name>)". It opens as a tile in the layout, beside your terminals.

Reloading. Later rounds ask nothing. The running tile saves its state, a new one starts from the new build with that state, and the tiles that were open stay open. If Pitwall isn't running, dev says so, and a later round loads the tile once it is. dev is only for extensions that add tiles and run no programs; one with an adapter, a service or setup actions is loaded from Settings → Extensions instead.

The Log. What the tile logs and prints is in its Log, on its card in Settings → Extensions, and pitwall extension log <id> prints it. When a tile stops (over a deadline, a crash, a frame too large), it says why in its place, with Restart.

Keep what the user is typing or looking at across a reload with save_state. The list template keeps its filter and the item being typed:

fn save_state(&self) -> Option<SavedState> {
    // Keep what's being typed across a reload.
    SavedState::json(&(&self.filter, &self.draft))
}

and reads them back in new:

// After a reload (`pitwall extension dev`): what was being typed.
if let Some((filter, draft)) = cx.restore::<(String, String)>() {
    (list.filter, list.draft) = (filter, draft);
}

Check it with pitwall extension check

pitwall extension check .

check reads the folder without running anything: the manifest, the component's world and imports, its size (at most 20 MiB), each tile's input schema, and each permission with its reason. It exits with status 1 when something fails. You can also give it extension.json or a .wasm file alone.

Test it

The project's tests run the built tile in the same runtime Pitwall uses, with a test host: a temporary data folder, the settings and grants you give it, and the toasts and Log lines it produces. Each action waits until the tile has handled it and rendered.

#[test]
fn counts_clicks_and_keeps_them() {
    let mut tile = Harness::build(env!("CARGO_MANIFEST_DIR")).open("main");
    assert!(tile.find_text("Clicked 0 times").is_some(), "{}", tile.text_snapshot());
    tile.click_text("Click me").click_text("Click me");
    assert!(tile.find_text("Clicked 2 times").is_some());
    assert_eq!(tile.stored_json::<u32>("clicks"), Some(2));
    // Started again with the same data: the count is still there.
    tile.reload();
    assert!(tile.find_text("Clicked 2 times").is_some());
    tile.click_text("Reset");
    assert_eq!(tile.stored_json::<u32>("clicks"), Some(0));
}

Run them with cargo test, or with:

pitwall extension test .

which builds the tile, checks it, and then runs cargo test.

A test can open a view with content, as an agent would, and give it new content later:

#[test]
fn shows_a_list_it_is_opened_with() {
    let content = json!({
        "title": "Release",
        "items": [
            { "id": "a", "text": "Write the changelog" },
            { "id": "b", "text": "Tag the release", "done": true }
        ]
    });
    let mut tile = Harness::build(env!("CARGO_MANIFEST_DIR")).open_with("main", content);
    assert!(tile.find_text("Release").is_some(), "{}", tile.text_snapshot());
    assert!(tile.find_text("1 of 2").is_some());
    tile.click_key("items/a/0");
    assert!(tile.find_text("2 of 2").is_some());
    // The same view given new content (an agent showing an update).
    tile.set_content("main", json!({ "items": [{ "id": "c", "text": "Announce it" }] }));
    assert!(tile.find_text("Announce it").is_some());
    assert!(tile.find_text("Write the changelog").is_none());
}

The harness, pitwall-extension-test, can also type into fields (type_into, submit), select in them (select_text, select_in), press keys (press), let time pass for timers (wait, wait_for_text), change a setting (set_setting), reload the tile (reload), and read what it stored (stored, stored_json), logged (log_text) and toasted (toasts). text_snapshot() prints the tree, which helps when an assertion fails.

Share it

To give a tile to others, pack it and sign it: pitwall extension pack, then pitwall extension sign <file>. Send the .pwtile file and its .pwsig together. Packaging covers making a key and shipping updates, and Install covers what the other person sees.

Share a preview tile

For a quick try without a key, you can also pass a tile around as a folder: the one holding extension.json, tile.wasm and the files the manifest names (such as input.schema.json). The person you send it to installs it:

  • In Pitwall: Settings → Extensions → Install from folder…
  • From a terminal: pitwall extension install <folder>. The argument must be a path with a / in it (such as ./my-tile); a bare name is the id of an extension Pitwall ships. The terminal prints what installing changes, and you approve it in Pitwall.

Only extensions that add tiles and run no programs install this way. Pitwall checks the folder (its manifest, its files, and that tile.wasm is a component), copies it into its own extensions folder, and lists the tiles it adds and the permissions it asks for with their reasons, with the warning "Unsigned, preview: only install tiles from people you trust" (Permissions). It is installed off: turn it on in Settings → Extensions, or with pitwall extension on <id>, to use its tiles. It is never updated: installing a newer folder replaces it and keeps its settings and data. Unlike pitwall extension dev, the folder is copied, not loaded in place.

Coming in this preview: installing from the address of such a folder served over HTTPS. For now pitwall extension install refuses an address: download and unpack it, then install the folder. A marketplace comes in a later release.

Next