Skip to content

Jobs

Three ways to run a command, by who owns it:

  • Declared job (ctx.jobs.define): the workspace’s. Runs by hand, on a schedule or kept running, with or without a window or a thread. Use it for anything recurring or lasting: “read my mail every morning” (a schedule with a prompt), “watch the inbox folder” (a service), “a deploy I can run with a key” (manual). Never loop, sleep or leave a background command running for these.
  • Your background command (job_start, then job_wait): your thread’s, for work of this conversation. It wakes you when it ends; omfp:background shows it; stopping the thread stops it.
  • A widget’s command (useJob, jobs.start): a transient run a widget follows, for what it shows.
job_start { command: "npm run dev", name: "web", ready: { log: "ready on \\d+" } } # or ready: { port: 5173 }
job_start { command: "cargo watch -x test", name: "tests", notify: "^(error|FAILED)" }
job_wait { ids: ["tests"] }
read job://web # status, then its output; offset/limit page it; job:// lists your jobs
omfp_call jobs.kill { jobId: "web" }
  • name: a label unique among your running jobs; job_wait, jobs.output, jobs.kill and job:// take it for the id.
  • ready { log?, port?, host?, timeout? }: the call returns once a line matches log or port accepts (host default 127.0.0.1/::1), and the job keeps running. Not ready in timeout seconds (default 30, agents.jobs.readyTimeoutSeconds): it is killed and the call fails with its output; ended first: the call fails with its output. Use it for servers instead of sleeping.
  • notify: each output line matching it reaches you as a message while the job runs (it steers your run, or wakes you). More than 10 matches within 5 s (agents.jobs) stop the notices, the last one saying so: then read job://<name>.
  • read job://… never takes the end away: it still reaches you as a message (or through job_wait).
  • The end reaches you as a message also after your turn ended: with nothing else to do, end your turn instead of calling job_wait to stay busy; call it only when your very next step needs the job’s result.
ctx.jobs.define("test", { description: "Fast tests", command: "nix develop -c just test", cwd: "omfp" });
ctx.jobs.define("mail", {
schedule: "0 8 * * 1-5",
prompt: { text: "Read my unread mail and list what needs an answer.", thread: "reuse" },
});
ctx.jobs.define("inbox-watch", { trigger: "service", command: "./scripts/watch-inbox.sh", restart: "on-failure" });
ctx.jobs.define("digest", { schedule: "@daily", run: async ({ signal, log }) => { log("collecting"); return { done: true }; } });
Key What it is
trigger manual, schedule (the default with a schedule) or service (kept running).
schedule Five cron fields (minute hour day-of-month month day-of-week; names like mon, jan work) or @hourly, @daily, @weekly, @monthly, @yearly; the daemon host’s local time. No seconds, no @reboot (use a service).
missed skip (default) or run: a time reached more than 60 s late (daemon down, host asleep) runs once with run.
command / prompt / run Exactly one: a shell command (sh -c); { text, thread?, model?, thinkingLevel?, tools?, ephemeral? } (thread: new, the default, or reuse one thread of the job, a new one when tools changed; tools: the thread’s only tools, [] none, omfp://docs/agent-tools; ephemeral: true: each run’s thread is deleted once its run settled, not with reuse); a function run in the workspace’s host (signal aborts on stop or reload).
cwd With command: a folder relative to the workspace folder.
restart With service: on-failure (default) or always; backoff from 1 s doubling to 60 s.
enabled, description Default true; what it is for.
  • A job has at most one running run: a scheduled time while it runs records a skipped run; jobs.run then answers conflict. A reused thread that is busy also makes a skipped run.
  • Jobs belong to the workspace: stopping, archiving or deleting the thread that declared or ran one leaves it running. A declaration that goes (reload, replaced eval) stops its runs. A service stopped with jobs.kill stays stopped until run by hand, re-enabled, changed or the daemon restarts.
  • jobs.enable (:job-enable, :job-disable, the Enable/Disable of omfp:jobs) only overrides the declared enabled in the daemon’s memory, writing nothing: the override lasts until the job’s declaration changes (a reload or an eval with another definition) or the daemon restarts, then the declared enabled applies again. To keep a job off, declare it with enabled: false.
  • The daemon keeps each job’s 50 newest finished runs (a command run with its last 200 lines).
  • Methods: jobs.list, jobs.runs, jobs.run, jobs.kill, jobs.enable (omfp://protocol/methods). In the window: omfp:jobs, :job-run <name>, :jobs; bind one with ctx.keys.bind("spc d", "job.run", "deploy"). A widget: useJobs(). A window module may notify on job_started / job_ended / job_failed but must never start runs (two windows would start them twice, a closed laptop never).

Declared command jobs, background commands and useJob alike:

  • Shell: sh -c <command>, non-interactive and not a login shell: no ~/.profile, ~/.bashrc, aliases or functions. sh is the first on the daemon’s PATH; write bash -c '…' for bash syntax.
  • Working directory: the workspace folder (a declared job’s cwd): cd <folder> && … or git -C <folder> … for a project inside it.
  • Environment: the daemon’s, unchanged: whatever started the daemon decides PATH (a terminal’s shell, the desktop session’s, or a systemd user service’s, systemctl --user show-environment). No dev shell applies: write nix develop -c cargo test, direnv exec . make.
  • Input: stdin is /dev/null, no terminal: prompts read end-of-file, tools print without colours.
  • Time: no timeout. A kill sends SIGTERM to the process group, SIGKILL 2 s later; what detaches itself (setsid) is out of reach.
  • Output: lines (a line over 64 KiB is cut in pieces); the newest 1 MiB of text is kept, older lines counted in state.dropped.

useJob(command, { key? }) → { status, lines, stdout, stderr, exitCode, signal, runs, startedAt, endedAt, state, refreshing, restart, kill }. status is pending, running, succeeded (exit 0) or failed. The first mount starts the job; reloads, other windows and moving the widget follow the same one (stored as job:<command>). Without key, every distinct command is its own job, so a command built from input leaves one job per input behind: pass key (useJob(`rg -n ${query}`, { key: "search" }), stored as jobkey:<key>: { id, runs, command }) and a new command replaces the previous job.

Transient runs live in the daemon’s memory only: a workspace keeps its 32 most recently finished jobs. A daemon restart forgets them all, so useJob starts the command again on the next mount. A job replaced under a key is forgotten at once.

useTerminal(command, { cwd?, cols?, rows?, key? }) runs a program that needs a real terminal (prompts, TUIs, colour) on a daemon-owned PTY (TERM=xterm-256color), followed by every window; feed state.scrollback to the kit’s TerminalEmulator. Prefer useJob for output a widget parses. screen({ afterRevision?, waitMs? }) reads the visible text, waiting up to 30 s for a change. Never put passwords in command: agent activity shows it. Sessions live in memory (1 MiB kept); a daemon restart starts a replacement.