The UI half
New to this? Start with the guide (superego --skill guide): the big picture, a first extension end to end, and testing; and the cheat sheet of both halves.
A profile's UI runs in the window, for that profile's threads only (on the machine it came from): panes, things beside
a thread, and how its tool calls look in the transcript. List modules in the profile's ui; each default-exports
defineUiExtension. Everything a module registers belongs to it, and goes when the profile's files change and the
window loads them again.
When the UI loads
The window loads a profile's UI as soon as it lists one of that profile's threads, in the sidebar or the navigator. It doesn't wait for one to be opened, so its badges, slots, tool rows and pane kinds are there from the start.
- Archived and hidden threads don't count.
- It loads once per profile per machine, however many threads share it. That loads the profile's daemon half too.
- Another machine's profile loads this way only if its UI was allowed here before. One never allowed waits until a thread of it is opened, which asks.
- It stays loaded until the window reloads, even once its last listed thread goes; it shows only on its own threads.
- After you change its files, it loads again when a shown thread of it moves on: send that thread a message.
A first module
// .superego/profiles/support/ui/order.tsx
import { defineUiExtension, PaneHeader, PaneMessage, PaneNote, FileTextIcon, useMethod, type PaneProps } from 'superego/ui'
function OrderPane({ machine, thread, pane }: PaneProps) {
const { id } = (pane.params ?? {}) as { id?: string }
// A read: the daemon half's method (superego.method), not an action; again as the thread moves on.
const { data: order, error } = useMethod<any>(machine.id, 'orders.find', { number: id }, { enabled: Boolean(id), refresh: thread.activeAt })
if (error) return <PaneMessage>{error.message}</PaneMessage>
if (!order) return <PaneMessage>Loading…</PaneMessage>
return <div className="order-pane"><PaneHeader><PaneNote>{order.status}</PaneNote></PaneHeader><h2>Order {id}</h2>…</div>
}
export default defineUiExtension({
name: 'support-ui',
setup(superego) {
superego.pane('order', { title: (pane) => `Order ${(pane.params as any)?.id ?? ''}`, icon: FileTextIcon, component: OrderPane })
// A row: "Found order 1234 · shipped", folded open to what the tool said.
superego.tool('find_order', {
icon: FileTextIcon, verbs: ['Found', 'Finding', 'Couldn’t find'],
subject: ({ call }) => `order ${call.arguments.number}`,
meta: ({ result }) => (result?.details as { status?: string } | undefined)?.status,
phrase: (count) => count === 1 ? 'found an order' : `found ${count} orders`,
})
},
})
Then, in profile.ts: ui: ['./ui/order.tsx'], panes: { order: 'an order, with its lines. Params: { id }' } (or, in
a daemon half's defineDaemonExtension, panes: { order: '…' }). The agent opens it with pane_open({ kind: 'order', params: { id: '1234' } }); so can you, with
superego do pane.open --params '{"thread":"<thread>","kind":"order","params":{"id":"1234"}}'.
What a module can import
'react'and'react/jsx-runtime': the window's own React (19);'react-dom'and'react-dom/client', its own too.'superego/ui': the hooks and components below: the stable surface.'superego/unstable': the window's own workings (useRegistry,useShell, …), which change with it.- Its own files, by relative path (
'./chart.ts'), plain.jsamong them: a library vendored as one ESM bundle, with React left as bare imports (esbuild --bundle --format=esm --external:react --external:react-dom …).
Nothing else: no npm packages, no CSS imports. TSX and TS are compiled by the daemon (types stripped, JSX for React),
which doesn't type-check them: superego extension test does.
The setup API
superego.pane(kind, { title, component, icon?, file?, menu?, opens?, fallback?, folders?, urls?, width? }) |
a kind of pane. title: a string, or (pane) => string. component gets { machine, thread, pane }; pane.params is what it was opened with. icon: its glyph on the pane's tab (a Phosphor icon from superego/ui). file: true: its title is a file name, and the tab shows it as one. menu: true offers it in the thread's pane menu (it needs no params). opens: (path) => boolean makes files named in the thread open in it (/\.csv$/.test(path)), ahead of the editor (fallback: true: any file no kind opens); folders: true, folders (params.path, '' for the thread's own); urls: true, web pages a thread links to, when opened beside (params.url). width: share of the row, 0.5 by default |
superego.space(kind, { title, component, icon?, match?, params?, about?, profile?, agent? }) |
a view that fills the main area, with a thread docked beside it: an app extension's or a global profile's only (window.md) |
superego.tool(name, row, { fold? }) |
how calls to a tool look in the transcript, described: { icon?, verbs?, verb?, subject?, stat?, meta?, body?, phrase?, file?, weight? }. verbs: done, working, failed (['Read', 'Reading', 'Read failed']); verb(call), a call's own instead, where one needs another. The functions get the call (below) and its state (idle, working, done, error): subject is what it acted on, after the verb (text in mono, or a node such as <ThreadRef machine id />); stat its lines { added, removed }; meta a little more at the row's end; body what it opens to. phrase(count) says what count calls did in a run's line (read 2 files); file(args) names the one file a lone call was about there; weight decides which kind leads that line. Anything left out (or returning undefined) is the default: its name, its command/path/pattern, its output; null from subject or body is nothing. fold: false shows them under their run of work, open, instead of folded into it: for what the agent shows you (as images does) |
superego.tool(name, component, { fold? }) |
draw calls to a tool whole, yourself. Gets { machine, thread, call: { id, name, arguments }, result?: { text, isError, details, images? }, live?: { status, output, details } }; text is the output, then a failed call's error message, as the user should read it (not in the <harness> wrapper the model saw); images are those the model was shown, as ImageItems: where each is in the transcript (entry), its mimeType, width and height, not its pixels; read one with call(machine.id, 'image.read', { thread: thread.id, image: { entry: entry.id, message: entry.message, block: entry.block }, thumbnail: true }) ({ data, mimeType }, base64; leave out thumbnail for the whole of it) |
superego.tool('prefix*', row | component) |
a name ending in * matches every tool whose name starts so (mcp__*), where the tool has no row of its own; the longest prefix wins. Tools of one prefix's row with a phrase count as one kind in a run's line. |
superego.link({ match, open, render?, target? }) |
claim links in Markdown: a scheme (match: 'ticket:'), a pattern (/^https:\/\/linear\.app\//), or a test (href, kind, where) => boolean that also sees inline code (kind: 'code', its text as href). open(href, { machine, thread, beside, kind, openFile, openUrl }) follows one, on a click (⌘: beside) or from ⌃O's list; return a string to say why it couldn't. render gets { href, children, code, title, where, open(beside) } (default: a link that follows it). target(href): where it goes, in ⌃O's list. scheme: the scheme a pattern or test claims ('ticket'), so HTML files keep its links, as they do a 'ticket:' match's. `[[Note#Heading |
superego.view(id, { title, icon?, context, fits, default?, component, order? }) |
a view, <name>.<view>, that the layout puts in a place: for a profile, beside (a column beside the thread), pane (the thread's pane menu; it's a pane kind of its id too) or header (right of the title). context: 'thread': component gets { place, machine, thread }. default: where it goes (a place, several, or none: offered only); the user moves, reorders or hides it (~/.superego/layout.json, which is app.layout; or a right-click on it), so don't assume one place |
superego.slot(slot, component, { order? }) |
put a component in a slot whose place behaviour decides (below) |
superego.signal |
an AbortSignal, aborted when this UI is torn down (its profile's files changed, it was revoked): for timers, listeners and fetches of its own. setup may also return a cleanup, run then. Registering after that throws. Each component it draws is drawn apart: one that throws shows " |
superego.on(event, listener) |
hear what happens in the window, in the desktop app and a browser alike; returns a function that stops it (teardown does too). 'thread.status': { machine, thread, before }, a thread's status changed (before undefined the first time the window sees it; only your profile's threads). 'select': { selection, before }, the thread shown changed. 'focus': { focused }. 'visibility': { visible }. superego.window is how things are now: { focused, visible, selection, thread, machines, threads } (threads: each machine's threads in use, by machine id) |
superego.style(css) |
bring CSS, scoped to what this profile draws (Styling). Gone at teardown; also returns a function that takes it out sooner |
superego.theme({ id, name, appearance, syntax?, terminal?, ui?, accent? }) |
a theme for code and the terminal (and the window, if it matches), offered in Settings → Appearance's picker for its appearance ('light' or 'dark'), under your extension's name (Themes). id starts with your extension's name. One that doesn't read throws, saying what's wrong. Needs extension API ^5.5 |
superego.appSetting(key) |
one of the app's settings as it is now, outside React (useAppSetting in components) |
superego.entry(kind, component) |
draw transcript entries of a kind an extension writes |
superego.settings(ui, component) |
draw below the settings section (of its daemon half) that names ui |
superego.composer.complete({ title, word, items }) |
complete a word as it's typed. word(text, caret) returns the word at the caret it completes, { start, query } (and anything of its own), or nothing; the first provider to find one wins. items(word, { machine, cwd, thread }) returns (cwd: the folder it writes for, as typed; no thread in the New thread dialog, before there's one) (or resolves to) { label, detail?, icon?, insert }[], best first (icon, a React node before the label, tells kinds apart in one menu); taken, insert replaces the word (end it with a space to go on typing). The composer draws the menu: ↑↓ pick, ⇥ or ⏎ take, esc leaves the word |
superego.composer.sentWith({ read, component?, words? }) |
draw what the daemon half's beforeSend put in sent messages. read(blocks) returns { items, blocks }: what to draw and the indexes of the blocks it found them in, which the message's text then leaves out; component gets { machine, thread, items } and draws under the message (a <Chip icon title> each, like a file's); words(text, items) returns the message's own words as Markdown to draw (mentions turns @thread:42 into a thread: link). Drawn for threads that go without the extension now too |
superego.store(key, initial, { persist?, shared? }) |
state of the extension kept in the window: get(), set(next), subscribe, and use() in a component. Give the bare key (superego.store('columns', [])): it's kept as <name>.columns, and '<name>.columns' is the same store. persist keeps it across reloads, for this window alone (each desktop window has its own), or for all of them with shared |
superego.dispatch(id, params, { machine }) |
run an action outside React |
A profile's module may draw its tool calls the way it likes; if two draw the same tool, the first stays (with a warning in the console). A profile's own wins over a bundled extension's in its threads.
Slots a profile can fill, each given { machine, thread } (and for the editor ones, path and open(path)):
| Slot | |
|---|---|
header.chips |
among the chips that say where a thread works (a branch): draw a <HeaderChip title> |
thread.badge |
after a thread's title in the sidebar: a small mark of something about it. Draw a <ThreadBadge label> around a 12px icon, or nothing (below) |
composer.above |
above the message box: something waiting on the user |
details.section |
in thread details (⌘I), after what the core says: an <h5> and what you know of the thread. |
editor.side, editor.bar |
beside a file in the editor, and in its bar |
overlay |
over everything: a dialog of your own, drawn while you want it. Mark its surface data-superego-overlay (Base UI popovers and dialogs from superego/ui are already known) so a web page in a pane, drawn above the window, steps aside while it's open |
onboarding |
on first-run setup (Set up models…), among what was found on the machine: { machine, use }, drawing a SetupRow for what yours offers to run models with, and calling use({ label, detail, model }) once it's ready (API ^5.9; model: your kind of agent's, <kind>/<model>, made the machine's default, so new threads given none run on it). Claude Agent's finds Claude Code |
A mark in the sidebar
A mark on some threads' rows goes from the daemon half to the window in four steps: the daemon half keeps what it found
in the thread's state, publishes it with facts, each ThreadInfo carries it as thread.facts.<name> (read it with
factsOf<T>(thread, name)), and a thread.badge slot draws it. The daemon half for this one is in Watching tool calls:
// ui/db.tsx; in profile.ts: extensions: ['./db.ts'], ui: ['./ui/db.tsx']
import { defineUiExtension, factsOf, TableIcon, ThreadBadge, type SlotProps } from 'superego/ui'
function DbMark({ thread }: SlotProps['thread.badge']) {
const db = factsOf<{ why: string }>(thread, 'db')
if (!db) return null
return <ThreadBadge label="touched the database" title={db.why}><TableIcon size={12} aria-hidden /></ThreadBadge>
}
export default defineUiExtension({ name: 'db', setup: (superego) => superego.slot('thread.badge', DbMark) })
The mark shows before the thread is opened: the UI loads as soon as the window lists it.
Sidebars, the rail, spaces, work dividers, window actions, app settings and New thread fields are for bundled extensions
(superego --skill bundled).
Inside a pane: <PaneHeader> puts small things in the pane's header beside its title: a <PaneNote> (a count, a path;
code, href) and <PaneButton>s (Refresh). <PaneMessage> stands in for what the pane shows while there's nothing
(Loading…, an error). useTabNote(note, key) shows a note on its tab in the strip (Changes shows
<DiffStat added removed />, +3 −1); useTabGlyph(glyph, key) shows a glyph there in place of its kind's (Browser's
spinner while a page loads: <Glyph shape="working" quiet />), null for its kind's own.
A web page in a pane: <WebView src partition="browser" title sandbox onEvent ref> shows it as Browser does, as a browser
tab on the desktop (its own cookies, back and forward through ref's go(-1), reload(), stop(), load(url), focus(); onEvent hears where it is
now, whether it's loading and how far (state.loading, state.progress), a file it saved, what it was refused), framed in a browser (sandbox is the frame's). hasWebViews() says which.
ref's run(fn, ...args) runs a self-contained function in the page ((window, ...args) => …, its source alone
goes there; on the desktop in a world of the app's own, framed only in a page of the window's origin) and gives back
what it returns; capture(rect) gives a part of the page as a PNG (none framed).
Focused, the pane keeps the keyboard until Return (or a click) passes it into the page; onWaiting(waiting) says when
it's waiting for that, for a hint.
From 'superego/ui'
Talking to the daemon:
call(machine.id, 'orders.find', params): a read, a daemon half's method (or any protocol method). A promise of its result.useDispatch()→dispatch(id, params, { machine: machine.id }): run an action (a daemon half's, or a built-in likepane.open,thread.send): something that changes things. Returns a promise of its result.useValue<T>(machine, 'orders.recent'): a daemon half's live value, kept current ({ scope: thread.id }: a scoped value's part for that thread). Undefined until it arrives, null while nothing publishes it yet (the profile hasn't loaded). However many components watch the same value, the window holds one subscription.useThreads,useAllThreads,useProjects,useSelection,useMachines: what the window knows ("Reading threads", below).
Opening things:
dispatch('pane.open', { thread: thread.id, kind: 'editor', params: { path: 'notes/a.md', line: 12 } }, { machine: machine.id })
dispatch('pane.open', { thread: thread.id, kind: 'browser', params: { url: 'http://localhost:3000' } }, { machine: machine.id })
dispatch('thread.send', { thread: thread.id, text: 'Ship it' }, { machine: machine.id })
Components: Button, IconButton, TextField, TextArea, Select, Switch, List, ListItem, Panel,
Dialog, Menu, Popover, Tooltip, StatusGlyph, StatusWord, Glyph, Markdown (an agent's text set exactly as the transcript sets it, its links followed by the same handlers: <Markdown text={answer} />; for a preview, <Markdown text={answer} compact lines={4} />: lines cuts it to that many lines with an ellipsis, compact sets it at the UI's size with tighter spacing), FileEditor (the file editor,
Markdown in live preview: <FileEditor machine={machine} thread={thread} path={path} actions={…} />; its links follow the link handlers, as a message's do), TextEditor (the same editor for text kept anywhere: <TextEditor value={text} onChange={save} mode="live" />, mode one of TEXT_MODES' (rendered, live, source); a new value from outside, the agent's edit, goes in as the least change, so the cursor stays put, and isn't told to onChange; revision takes the same value in again; place keeps the cursor and scroll; links, where its links are from; readOnly), Diff
(a unified diff, file by file: <Diff diff={text} />; parseDiff(text) for its files and counts), Picker (a dialog
with a list that narrows as you type, as the palette is: <Picker label placeholder items={list} filter={(items, query) => …} row={(item) => ({ key, title, glyph?, detail?, keys? })} onPick={(item, { beside }) => …} onClose digits? empty? footer? />;
↑↓ move, ⏎ picks, ⌘⏎ beside, digits: ⌃1–⌃9 pick the first nine), ThreadRef (a thread named as itself, kept
current: <ThreadRef machine={id} id={thread} />), SignInFlow (a sign-in flow drawn as Settings → Providers draws one,
for an action of the daemon half that answers with superego.auth.flow's { flow }: <SignInFlow machine={id} title="Signing in to Linear" start={() => dispatch('x.signIn', { … }, { machine: id })} onClose={…} />; it starts as it
mounts, opens the page in the browser, asks what the flow asks, and has Cancel), and the Phosphor icons the app
uses (ArchiveIcon, …).
Others: useComposer() (the message box), useComposerClaim({ placeholder, submit }) (take the message box over while
something waits on the user), addToComposer({ machine, thread }, { label, detail?, files }) (a chip in a thread's
composer, its files sent with the next message; it takes the keyboard), useLocalState(key, initial, { shared? }) (state kept in the window across reloads; shared by every window), useShortcut(actionId) (its key's
label), score (fuzzy matching), transcriptLinks(machine, thread) (the links a thread's transcript shows, in order: { text, href, target, open(beside) }), h (React.createElement, for modules without JSX).
Reading threads
The window follows every connected machine's threads, live, with one subscription per machine however many components read them. A profile's UI sees them all, not just its own profile's.
| Hook | Gives |
|---|---|
useThreads(machine.id) |
that machine's threads, ThreadInfo[], newest first; undefined until the machine says (or while it's away and never answered) |
useAllThreads() |
every machine's: Record<machineId, ThreadInfo[] | undefined> |
useProjects() |
{ projects, lastThread, hold }: projects in the sidebar's order, each a Project, { key, machine, root, name, threads, depth, activeAt, status } (a project's threads, depth how far each is nested under the thread that started it, status the most pressing of theirs); lastThread[key] the thread last shown in it |
useSelection() |
{ selection, select, machine, thread }: the thread shown (selection is { machine, thread } ids, thread its ThreadInfo), and select({ machine, thread }) to show another, or select(undefined) |
useMachines() |
every machine, MachineEntry: id, label, state ('connected', …) |
Archived threads aren't in the lists, nor hidden ones (an extension's own agent, like Ego's).
A ThreadInfo (type from 'superego/ui'): id, title, cwd (where it works), createdAt, activeAt (when
anything last happened in it: a dependency for useMethod's refresh), project ({ root, name }: its project),
parent (the thread that started it), profile ({ name, scope: 'user' | 'project', dir }; absent: none), model,
cost (dollars), panes and pane (what's open beside it), without (optional extensions it goes without), facts
(each extension's facts about it, by name: facts.worktrees), and status.
status is { state, kind?, msg? } (type Status). The states, most pressing first:
state |
Means | msg |
|---|---|---|
blocked |
it needs the user: kind is question (an ask_user), permission, or auth (its provider refused the credentials; it goes on by itself once signed in again) |
what it waits on |
error |
its last run failed, and nobody has looked since | why |
done |
it finished with an answer the user hasn't seen yet | what the run did, in a line (when there's a recap) |
working |
a run is going | |
idle |
nothing to see: never run, or its answer or failure seen (showing the thread marks it seen) |
So done and error turn idle once the user opens the thread: they mean "unseen", not "finished" or "failed for
good". StatusGlyph draws a status's mark as every list does (<StatusGlyph status={t.status} quiet={t.quiet} />;
quiet: a thread that reports to another, its work grey and its finished runs not new), StatusWord its word in its
colour, and statusWord(status) and statusLabel(status) say it as the app, the CLI and notifications do: "Question",
"Permission", "Sign in", "Failed", "Done", "Working" (the label adds what it did or why: "Done: Glyph
draws the same marks by name (<Glyph shape="landed" />), with a few that aren't a thread's status: queued,
stalled, landed, offline, connecting. To act on a change
outside React, superego.on('thread.status', …) (the setup API, above).
A board of one machine's threads, a column per state:
// ui/board.tsx; in profile.ts: ui: ['./ui/board.tsx'], panes: { board: "every thread on this machine, by status; no params" }
import { defineUiExtension, PaneMessage, StatusGlyph, useSelection, useThreads, type PaneProps, type Status } from 'superego/ui'
const LANES: { state: Status['state']; title: string }[] = [
{ state: 'blocked', title: 'Needs you' }, { state: 'error', title: 'Failed' }, { state: 'working', title: 'Working' },
{ state: 'done', title: 'Done' }, { state: 'idle', title: 'Idle' },
]
function Board({ machine }: PaneProps) {
const threads = useThreads(machine.id)
const { select } = useSelection()
if (!threads) return <PaneMessage>Loading…</PaneMessage>
return <div className="board">{LANES.map(({ state, title }) => (
<section key={state}>
<h3>{title}</h3>
{threads.filter((t) => t.status.state === state).map((t) => (
<button key={t.id} type="button" onClick={() => select({ machine: machine.id, thread: t.id })}>
<StatusGlyph status={t.status} /> {t.title} <small>{t.project.name}</small>
</button>
))}
</section>
))}</div>
}
export default defineUiExtension({ name: 'board', setup: (superego) => superego.pane('board', { title: 'Board', component: Board, menu: true }) })
Every machine's instead: Object.entries(useAllThreads()), with useMachines() for each one's label.
Styling
Bring styles with superego.style(css) in setup (a profile's UI can't import CSS), and use the theme's variables so
they follow light and dark mode, the user's accent, and with Match window to theme on, the chosen theme:
superego.style(`.order-pane { padding: var(--superego-space-3); color: var(--superego-muted); border-radius: var(--superego-radius); }`)
They go with the UI when it's reloaded or revoked. They apply only to what your profile draws on its machine: its panes,
views, slots, tool rows, entries, links and settings, with the menus, popovers, dialogs and PaneHeader contents those
open. The window's own UI and other profiles' don't get them, and neither does the same profile from another machine at
another version. So two profiles, or two versions of one, can use the same class names.
What that means for your CSS:
:root,htmlandbodydon't match: style your own elements.:scopematches the box-less element your component is drawn in.@media,@supports,@containerand nesting work as usual.@importdoesn't.@keyframes,@font-faceand@propertynames are still the window's: prefix them with your extension's name.- An element you portal yourself (
createPortaltodocument.body) is outside your UI and doesn't get them. Portal through the window's components (Menu,Popover,Dialog,Tooltip,PaneHeader) instead.
A <style> you append to document.head yourself still works, but it styles the whole window, every profile's threads
included. Use it only for something truly window-wide.
Useful variables: --superego-bg, --superego-raised, --superego-border, --superego-muted, --superego-faint,
--superego-accent, --superego-hover, --superego-selected, --superego-font, --superego-mono,
--superego-radius, --superego-radius-lg, --superego-space-1 … --superego-space-7. Name your own classes after
your extension (board-lane); the window's own look comes through its components (PaneMessage, HeaderChip, …), not
its class names.
A pane is a column that can be narrow (and a whole screen on a phone): lay it out to fill its parent with flex, and let it scroll.
Themes
Bring a theme for code and the terminal with superego.theme(theme). The user picks one theme for light and one for
dark in Settings → Appearance; yours is listed in the picker for its appearance, under your extension's name. Chosen,
it colours code in the editor, in messages and in rendered files, diffs, and the terminal, everywhere in the window (a
profile's theme too, not only in its own threads); the window's own backgrounds and text only with Match window to
theme on (below). accent colours the window's accent too, unless the user chose their own.
With Match window to theme on (Settings → Appearance), the window's backgrounds, text and lines follow the theme's
ground and text (ui.bg/ui.fg, else the terminal's), derived by a few fixed steps, and its links ui.link;
ui['accent-text'] is the text on its accent.
superego.theme({
id: 'moonlit.night', name: 'Moonlit Night', appearance: 'dark',
syntax: { keyword: '#ff79c6', string: '#f1fa8c', comment: '#6272a4', function: '#50fa7b' },
terminal: { bg: '#21222c', fg: '#f8f8f2', red: '#ff5555', green: '#50fa7b' },
accent: '#6d5bd0',
})
Every part but id, name and appearance is optional, and a role you leave out keeps Superego's own colour. Colours
are hex (#rrggbb, with alpha too) or CSS colour functions (rgb(), oklch(), color(display-p3 …)). The roles:
syntax:keyword,string,number,comment,function,type,tag,attribute,definition,meta,inserted,deleted(a diff's lines, in code and the Diff pane),invalid.terminal:fg,bg,cursor,selection, and the 16 ANSI colours,black…whiteandbright-black…bright-white.
The Theme type is in superego/ui. The same format is what Settings → Appearance → Import theme… reads, besides VS
Code themes and Ghostty and iTerm2 colour files.
A complete example
examples/build-queue-ui: a daemon half with a tool, a scoped value and an action, and a
UI half that draws the thread's queue beside it, with tests on superego/testing.