Init files and ctx
A workspace declares its views, widgets, keys, jobs and agent tools in code, in its init file
<workspace>/.omfp/init.ts. The user’s init file ~/.config/omfp/init.ts has the same shape and runs first, in
every workspace. On its first run the daemon writes a starter one loading the default flavor (@omfp/flavor: the
threads column, the keys, the look, the ready widgets, omfp://docs/flavor) and the browser plugin; without the flavor
the window is omfp’s core alone. The daemon runs each in the workspace’s host (a worker of its own) as a plugin whose declarations
last as long as the file is loaded.
// <workspace>/.omfp/init.tsimport type { Context } from "@omfp/daemon/workspace";
export default function apply(ctx: Context) { ctx.widgets.define("tests", "./widgets/tests/index.tsx"); ctx.views.define("work", { title: "Work", layout: ["row", { sizes: [3, 1] }, ["col", {}, "omfp:header", ["tabs", { id: "main" }, "omfp:chat"]], ["tabs", { id: "side" }, "omfp:workspace", ["tests", { command: "make test" }]]], }); ctx.keys.bind("spc g w", "view.switch", "work"); ctx.jobs.define("nightly", { schedule: "0 2 * * *", prompt: { text: "Summarize yesterday's commits." } }); ctx.methods.define<{ name: string }>("hello", ({ name }) => `hello ${name}`); ctx.agents.context({ prompt: "Run the tests with `just test`." });}It default-exports apply(ctx) (or a plugin object { inject?, apply(ctx) }) and may import
@omfp/daemon/workspace (types), other @omfp/… packages (@omfp/flavor, @omfp/browser) and relative files;
ctx.plugin(plugin, options) loads a plugin.
Editing an init file does nothing by itself. It runs again — every declaration of the old run undone first, its
whole import graph loaded fresh — when the workspace reloads it: :reload-init in the window, workspaces.reload_init
over the protocol (you: omfp_call). A failing file shows its error (<file>:<line>:<column>: …) and declares
nothing; the other file keeps its declarations. workspaces.check type-checks the files and the widgets and loads
the files in a throwaway host first, without touching what runs (omfp://docs/checking).
ctx. |
Declares | Topic |
|---|---|---|
views.define(id, { title, layout }) |
A view. Views are listed in declaration order (the user’s init file, then the workspace’s, then evals; one declared again keeps its place). The view with id default opens first, else the first one. |
views |
widgets.define(name, path) |
A widget: the module at path (relative to the declaring file), used by name in layouts. |
widgets |
keys.bind(keys, command, ...args), keys.bindIn(mode, …) |
A key binding. | keys |
jobs.define(name, spec) |
A declared job: by hand, on a schedule, or kept running. | jobs |
methods.define(name, handler) |
A method widgets call with useMethod(name) (or workspace.call { workspaceId, method, params }); handler(params, caller) returns plain data, caller { client, window } (window null for a call that is no window’s). In the user’s own host: a daemon-wide method windows call with callUser (user.call { method, params }). |
sdk |
window.load(path) |
A module every window on the workspace runs. | window-modules |
agents.context({ agentsFiles?, prompt? }) |
Which AGENTS.md files agents load ("self", the default: the workspace folder’s own; or a list of more files) and a prompt added to their system prompt. |
agent-tools |
agents.tool(definition) |
A tool the workspace’s agents call, run in the host. | agent-tools |
agents.uri(scheme, { description, read, list? }) |
A URI scheme the workspace’s agents read with read, read in the host. |
uris |
agents.reader({ name, description, extensions, read }) |
A reader of the files with those extensions for the workspace’s agents’ read (<file>:<selector> inside), read in the host. |
readers |
mcp.define(name, config) |
An MCP server (an mcpServers entry) for the workspace’s threads and widgets. |
agent-tools |
on("tool/before", hook) |
A hook asked before an agent’s tool call. | agent-tools |
on("agent/call", (call) => …) |
Told after each call an agent made of a protocol method: { at, threadId, client, method, params, error }, strings in params over 200 characters cut. In the user’s own host every agent’s, in a workspace host its own agents’. Never waited for. |
|
dataDir |
The calling plugin’s own folder, made on first use and never emptied (not a declaration): <data>/plugins/<name>/ in the user’s own host, <data>/workspaces/<id>/plugins/<name>/ in a workspace’s. name is the nearest named plugin’s (ctx.plugin({ name, apply })); an init file’s own code has none and gets an error. Keep files or your own bun:sqlite database there. |
|
settings({ ui?, daemon?, agents? }) |
Settings. | settings |
shell.slot(name, ref) |
Fills a slot of the window’s shell (left, modeLine, phoneBar, main, and the chat’s transcriptRail) with a widget name or a module path (the widget shell.<slot>); from the user’s init file every window’s, a window without a workspace too. |
flavor |
omfp |
{ workspaceId, path } of the workspace (not a declaration). |
|
call(method, params) |
Calls any protocol method (omfp://protocol/methods) as the workspace (in the user’s own host: as the user); rejects with the method’s error code (unauthorized for methods only a window or an agent may call, disposed once the plugin is gone). |
|
on("window/closed", (windowId) => …) |
A window went (its connection number, the caller.window of its calls). |
|
on("thread/stopped", (threadId) => …) |
A thread stopped, was archived or deleted; in a workspace host its own threads only. | |
on("daemon/stopping", () => …) |
The daemon stops: a returned promise is awaited, up to 3 s, before the host ends. | |
threads.follow(threadId, (event) => …) |
Follows a thread: resolves to { state, summary, stop } (its state now), then calls the listener with each of its events until stop() or the plugin goes; in a workspace host its own threads only. |
|
threads.signal(threadId, name, data) |
Sends data (plain JSON) to the windows showing the thread, for this moment only: a window hears it with onThreadSignal(host, threadId, name, listener) (omfp://docs/sdk). |
|
auth.token(providerId) |
The current access token of one of pi’s providers (openai-codex, anthropic, …) from omfp’s logins, undefined without one; the user’s own host only (a plugin declaring inject: ["auth"] loads there only). |
Every define/bind/load returns a function that undoes it early. Values cross to the daemon as plain data: a
function or a class instance in a view’s layout fails the declaration. A method handler answers an error code by
throwing new RpcFailure(code, message) (from @omfp/daemon/workspace); anything else it throws is internal.
Windows see the methods a workspace declares (its views/<id> topic’s methods) and call them only then.
The daemon also loads the user’s init file once without a workspace, in the user’s own host, for its daemon-wide
settings, key bindings and methods (daemon-wide code like the default flavor’s live voice): there ctx.omfp does not
exist, so a plugin that needs it declares inject: ["omfp"] and then loads in workspaces only; ctx.auth exists
only there, so a plugin declaring inject: ["auth"] loads there only.
Trying code live: omfp_eval
Section titled “Trying code live: omfp_eval”omfp_eval { code, name? } runs TypeScript in the same live host, as the body of a plugin with ctx in scope, and
returns what the code returns. A later eval with the same name replaces it and undoes its declarations. Evals
survive a reload of the init files, not a restart of the host: what should stay goes into .omfp/init.ts.
const thread = await ctx.call("threads.create", { workspace: { id: ctx.omfp.workspaceId }, title: "Flaky tests", prompt: "Find which tests failed in the last three CI runs and why.",});await ctx.call("views.mount", { workspaceId: ctx.omfp.workspaceId, id: "ci", widget: "omfp:jobs" });return thread.id;