Writing a mod
A mod is a folder with a main.js that describes native elements. Woolshed draws them on the GPU and reloads the mod every time you save.
Mods use gpui-kit (its gpui-shell): JavaScript that describes GPUI elements, a native GPU UI (div(), flex, children, .on_click). There's no DOM: the script describes, Rust draws. Background: https://gpui-kit.com. Woolshed carries its own copy with additions (frames, loop), so the type files here are the truth: gpui-kit.d.ts for elements and woolshed.d.ts for the app's data and commands. They're rewritten on every start to match this version.
A mod's folder
~/.config/woolshed/mods/<name>/
main.js the mod (required)
mod.json where it first appears: { "place": "right" | "left" | "top" | "bottom" | "none", "size": 320 }
*.js, *.svg more modules ("./ui.js"), its own icons
"focusable": trueinmod.jsonletspane.gogive a shown copy the keyboard. It gets"focus"fromnextCommand(): focus your own handle then (this.handle.focus()) and handle keys withon_key_down. The copy gets"focus"again after a popup over it closes. Leave withrun("pane.go", {direction}). Without this opt-in, navigation and clicks stay unchanged.- The first time Woolshed sees a folder, it docks one copy per
mod.jsoninto the shown layout ("none": only where a layout or another mod puts it). After that, the layouts decide. Saving any file reloads every copy in place (not files the app writes:jsconfig.json,.d.ts, hidden ones,node_modules). The old build's tasks and timers stop: a loop ends at its nextcxuse. A broken save keeps the old version running and shows inwoolshed status; its top-level code has already run, so keep side effects onglobalThisout of the module's top level. - A copy starts the first time it shows, then stays alive while its block is in the layout, shown or not (a hidden column, the other child of a stack, a pane in another tab or behind a zoom): switching back finds it as it was. Its timers keep running while hidden, so poll gently. Another layout starts its mods fresh (pane mods belong to their tab and stay); a block removed or given another mod or props starts over.
<mod>.<command>reaches shown copies only. - Images and SVGs are referenced from
~/.config/woolshed:image("mods/<name>/logo.svg")(full color),svg("mods/<name>/icon.svg")(tinted with the text color). Saving an asset undermods/updates every mod showing it, including images that were missing or invalid on first load. Each image path stays loaded until Woolshed quits, so a picture that changes often (a screen, a camera, frames written asdata/<mod>/frame-<n>.png) usesimage(path).id("screen").live(): it holds one frame, frees each one it replaces, and keeps the last on screen while the next loads;live(version)with a new version reads the same path again. - The defaults are mods too, read them as examples:
spaces,agents,tabs(the tab bar),menu,prompt,confirm,help,toast, Terminals'picker,peek, andpane(an example pane header, not used by the default layouts), andworktree(git worktrees as spaces: the space menu's and the + menu's New worktree, Open worktree (the repo's checkouts, filtered; one already shown is gone to) and Remove worktree open it as a dialog with props{space, folder?, action: "new" | "open" | "remove"}(the repo: folder, else where the space's first terminal is), or with{branch, tab?, argv?}to make one at once with that first tab (forTask: true, from the start screen: kept in shared"worktree.tasks", checkout ->{main, branch, from, task, on, at}, for Changes' clean-up); checkouts go to~/.woolshed/worktrees/<repo>/<branch>on the space's machine, a constant at its top; thespacessidebar nests worktree spaces under their repo's and shows each space's repo, branch, ahead/behind and uncommitted changes), andchat(below),history,get-started,accounts,repos,release,device,new-app,mailbox,team,issuesandautomations(below). Shipped mods are Woolshed's; duplicate withmod.clonebefore editing.
An example
import { View, div } from "gpui-kit";
import { v_flex, h_flex } from "gpui-base";
import { exec, spaces, theme, run } from "woolshed";
export default class Branches extends View {
init(_props, cx) {
this.branch = {};
cx.timer.every(3000, (cx) => this.refresh(cx));
this.refresh(cx);
}
refresh(cx) {
cx.spawn(async (cx) => {
for (const p of spaces()) {
// on: a space on another machine runs git there.
const r = await exec("git", ["branch", "--show-current"], { cwd: p.folder, on: p.machine });
this.branch[p.id] = r.stdout.trim();
}
cx.notify();
});
}
render(cx) {
const t = theme();
return v_flex().size_full().bg(t.surface).p(10).gap(4).text_size(13).children(
spaces().map((p) =>
h_flex().id(`b-${p.id}`).gap(8).hover((s) => s.bg(t.raised))
.on_click(() => run("space.select", { id: p.id }))
.child(div().text_color(p.active ? t.foreground : t.muted).child(p.name))
.child(div().text_color(t.dim).child(this.branch[p.id] ?? ""))));
}
}
Rules:
main.jsdefault-exports a class extendingView.init(props, cx)runs once;render(cx)describes the UI and runs again aftercx.notify()and whenever Woolshed's live data changes (spaces, agents, terminals, focus, theme, shared state). Don't poll those.- Never keep a
cxand use it later. Every callback gets its own:on_click((event, cx) => …),cx.spawn(async (cx) => …),cx.timer.every(ms, (cx) => …). - No
setTimeout/setInterval(usecx.timer), no top-levelawait(usecx.spawnininit). Anything slow goes throughexecorfetch. - Size: put
.id("root").on_size_change((size, cx) => { this.size = size; cx.notify(); })on the rootdiv(),h_flex()orv_flex(). It reports{width, height}in logical pixels after the first layout and whenever the size changes, even with the pointer elsewhere. It does not changeprops(). - Cleanup: an optional
async close(cx)on the exportedViewgets one final call when its pane, tab, layout-owned slot or overlay goes, and on app quit. It is not called for a hidden copy or an inactive tab. Start cleanup insideclose(); don't await work started earlier. Await cleanup directly, for exampleasync close(cx) { await exec("hc", ["kill", this.browser]); }. Closing stays responsive: cleanup has at most 250 ms (shared across copies on quit), then unfinished tasks are cancelled. On quit, useexec(...)andrun("terminal.kill", { terminal: address }): those go out before the event loop stops; other commands may not run. Anexecalready started keeps running; don't start new long-lived work inclose. This is best-effort, not a guarantee after a crash or forced termination. - Use
theme()colors so the mod follows the user's theme. - Animate natively, never with a timer. Every redraw of a mod redraws the whole window, so
cx.timer.every(90, () => cx.notify())for a spinner costs real battery. Use.frames(["⠋", "⠙", …], 90)(shows each string in turn as the element's text),svg(arc).spin(900)(turns an icon once every 900 ms: a ring spinner, e.g.mods/workspace-chrome/spinner.svg), or.loop("opacity", { from: 0.4, to: 1, period: 1200 })(also width, height, left, top), and.transition(...)for changes: they run without your script and stop when not shown. Timers are for data (a clock, a fetch), and only as often as what they show changes.
Check before you finish
woolshed check ~/.config/woolshed/mods/<name>
Loads the mod, renders it once, exits nonzero with the exact error. Run it after every change. Never call a mod done without a passing check.
Keep in mind
- A task's
cxbelongs to the copy that started it:cx.notify()redraws that copy, even when another copy woke it (a shared promise). - One mod per idea. Don't edit
AGENTS.mdor the.d.tsfiles (the app rewrites them). Don't touch other mods unless the request needs it.
Your agents read these same words: Woolshed writes this guide to ~/.config/woolshed/AGENTS.md on every start. In it, “you” is the agent and “the person” is you.