Skip to content

Window modules

ctx.window.load("./window.tsx") has every window on the workspace import a module, compiled like a widget (same imports, omfp://docs/widgets), and run its default export, again whenever it changes. Before it runs again or goes away, the window removes everything the run registered through the API, so a run never undoes its own command, bind, contextMenu, views.transform, panel or on; return a cleanup function only for anything else.

import type { InitApi } from "omfp/sdk";
export default function init(omfp: InitApi) {
omfp.command({
id: "ws.tests",
title: "Run the tests",
aliases: ["tests"],
run: () => void omfp.callWorkspace("runTests"),
});
omfp.bind([{ keys: "Space T", command: "ws.tests" }, { mode: "insert", keys: "Ctrl-t", command: "ws.tests" }]);
omfp.panel("clock", ["./widgets/clock", { title: "Clock" }]);
omfp.on("attention", (thread) =>
omfp.notify({ title: thread.title ?? thread.id, body: "needs you", threadId: thread.id, tag: thread.id }),
);
const timer = setInterval(() => {}, 60_000);
return () => clearInterval(timer);
}
API What it does
file, workspaceId "user" or "workspace"; the workspace whose file this is (undefined for the user’s).
command(command) Registers a command, useCommand’s shape (omfp://docs/keys).
bind(binding | bindings) { keys, command, args?, mode? }, applied after the defaults, the user’s daemon-wide bindings and the init files’ ctx.keys.
contextMenu({ on, items }) Context menu items (omfp://docs/keys).
views.load("views.json") The workspace’s declared views, to change in this window only ("views.json" is the only name).
views.use(views) Shows views in this window instead of the declared ones.
views.transform(fn) fn(views) changes the views (or returns others): applied after use, the user’s file’s first; one that throws changes nothing.
workspace { id, folders }: the current workspace and its visible top-level folders.
panel(id, node) Floats a layout node over every view; closing it hides it until the file runs again.
on(event, listener) "attention" (a thread needs the user), "failed", "finished": listener(thread). "job_started", "job_ended", "job_failed": listener(run); notify or show, never start runs.
notify(request) Like useNotify(). Every open window runs the file, so give a listener’s notification a tag (the thread id) so the copies replace each other.
run(name, args?) Runs any command by id or alias: run("view.switch", ["logs"]).
call(method, params), callWorkspace(method, params?) Any protocol method; a method the init file defines.
callUser(method, params?) A daemon-wide method the user’s init.ts defines in the user’s own host (user.call); the method learns this window as its caller.
composer(part) Adds to the chat composer: { id, Panel?, Button?, DraftButton?, holds?(threadId), subscribe?(listener) }. Panel shows above a thread’s composer and Button among its buttons (both get { threadId, state }), DraftButton among the draft composer’s ({ disabled, ready() }); while holds(threadId) is true the thread’s composer gives way to the part (holds(undefined): the draft is read-only). subscribe tells when holds may answer otherwise. The default flavor’s live voice is one.
jobs The workspace’s declared jobs: list(), get(name), error, run(name), kill(name), enable(name, enabled).
onCleanup(fn) Called before the file runs again or goes away.
host The window’s SDK host, for anything else.

A layout node is checked like a declared view’s: an invalid one throws. Any failure — a compile error, a throw or a rejected promise of the run, a cleanup, a transform, a command or a listener — shows in a banner naming the file; the window keeps working without it, and the next clean run removes the banner. windows.state reports these errors.