Superego

The window

Views and the layout

The window: the rail and the open sidebar beside it, the thread with its header, transcript and composer.above, the column beside it, panes from the pane menu with the editor's bar and side; the title bar's stand-in, a phone's drawer and an overlay over everything

An extension declares views: what it offers, and the kinds of place each fits. The shell has places, and knows no extension. The layout decides what goes where: each view's default, then the user's changes, kept in the app setting app.layout as app.keys keeps shortcuts.

superego.view('threads.list', { title: 'Threads', icon: ChatsIcon, context: 'window', fits: ['sidebar'], default: 'sidebar', component: Threads, railButton: ThreadsRail })
superego.view('threads.details', { title: 'Thread details', context: 'thread', fits: ['beside', 'pane'], component: DetailsPane })
superego.view('ego.button', { title: 'Ask Ego', icon: LifebuoyIcon, context: 'window', fits: ['rail', 'drawer'], default: 'rail', narrow: 'drawer', order: 10, component: EgoButton })
Place What it is A view there gets
sidebar a button in the rail (its icon, or its own railButton component), and the sidebar while it's the open one; on a phone, the drawer. The sidebar is shown or hidden (⌘/, the open sidebar's button, its edge dragged narrow; a tight window hides it by itself): its railButton is told so (sidebarHidden), and can draw more in the rail while it's hidden (Threads' status dots); a space without one just hides { place }; a thread view, the thread shown
rail a button in the rail that isn't a sidebar (Ego's) { place }
drawer on a phone, at the drawer's foot beside Settings, where there's no rail { place }
titlebar at the title bar's start: what stands in for a sidebar while there's none (the core's thread picker) { place }
beside a column beside the thread { place, machine, thread }
pane the thread's pane menu: a thread view that fits pane is a pane kind of its id { place, machine, thread }
header right of the thread's title: a button, a badge { place, machine, thread }

Slots are places that behaviour decides, so the layout doesn't move them: a question card sits on the composer it asks for. They get { machine, thread }; the editor's also path and open(path).

Data-only views

A daemon half can declare a view as data, and the window draws it with its own components: no UI code ships, so a remote machine's, or a project profile's, needs no consent to run code in the window, as its UI code would. That's not no authority: its buttons run that machine's actions. What a view shows is blocks (Block[] from 'superego'), the schema agents draw with: markdown, callout, code, table, image, kv, list (rows: title, subtitle, detail, status, a thread to link, buttons), layout (stack, row, card, divider), inputs, buttons, and html (a sandboxed page, display only). A button runs one of the extension's own actions (action: <extension>.<name>) on that machine with its params, as the window may (one exposed to ui); the inputs' values go into the params by input id. [] or null shows "Nothing here yet."; say more with a markdown block.

// orders.ts, a daemon half: the open orders, as a sidebar, with a button on each
const open = superego.value<Block[]>('orders.open', [{ type: 'markdown', text: 'No open orders.' }])
const show = (orders: Order[]) => open.set([
  { type: 'markdown', text: `${orders.length} open` },
  { type: 'list', items: orders.map((o) => ({ title: `No. ${o.id}`, subtitle: o.customer, status: o.late ? 'blocked' : 'idle',
    buttons: [{ id: `ship-${o.id}`, label: 'Ship', action: 'orders.ship', params: { id: o.id } }] })) },
])
superego.action(defineAction({ id: 'orders.ship', title: 'Ship an order', params: obj({ id: str() }), run: async ({ id }) => show(await ship(id)) }))
superego.view('orders.open', { title: 'Orders', icon: 'list', context: 'window', fits: ['sidebar', 'beside'], default: 'sidebar', value: 'orders.open' })

Spaces

A space fills the window's main area, where a thread otherwise shows: a notes page, a canvas. An app extension's UI half registers it, or a global profile's (global: true, profiles.md); a thread-bound profile's can't, as it would have nowhere to open.

superego.space('notes.page', {
  title: (params) => String(params.name),          // the title bar, history; or a string
  icon: NotebookIcon,
  component: NotePage,                             // { machine, kind, params, thread, open(params) }
  match: 'note:',                                  // links of this scheme open it, in any Markdown (an agent's answer too)…
  params: (href) => ({ name: href.slice(5) }),     // …with these params (default { href })
  about: (params) => `The user has the note "${params.name}" open.`,  // a thread started on it is told this first
  profile: 'notes',                                // the profile that thread runs (default: the machine's)
  agent: 'docked',                                 // its thread as a column beside it, or 'floating': a card over it
})

On a phone

Below 600px wide there's no rail and no title bar. sidebar views are the drawer, with the others to switch to at its foot beside drawer views (Ego, Unread) and Settings. The thread's title opens its sheet, which holds the title bar's (header views, where it runs, archiving), the pane menu, and the beside views. With no sidebar there's no drawer: titlebar views (the thread picker) and Settings are in the bar at the top instead. narrow moves a view elsewhere on a phone.

A link in a message, in ⌃O's list, or in a Markdown file (rendered, or clicked in live preview) is followed by the first handler that claims it, asked in this order:

  1. the thread's profile's (its ui files' superego.link), only in that profile's threads;
  2. the extensions', in the order they're set up, but not those of an optional one the thread goes without (threads claims thread:<id>, and thread:<machine>/<id> for one on another machine, by its name or id);
  3. the core's, the defaults: files a thread names (relative links, inline code that reads as a path, and wikilink:), which open in the pane kind that takes the file, and web pages (http:, https:, mailto:), which open in the browser, or beside in a pane that shows web pages (urls: true, browser's Browser).

A link no handler claims opens in the browser; an HTML link of a scheme none claims there is dropped. So to open links your own way, claim them: nothing else to switch off. [[Note#Heading|alias]] reaches handlers as wikilink:Note#Heading (each part URI-encoded), saying "alias"; parseWikilink(href) gives { target: 'Note', heading: 'Heading' } (or block for #^id). A profile that keeps notes its own way, say:

// In a profile's ui/note.tsx: [[wikilinks]] open the vault's own note pane, found by the vault's rules.
superego.link({
  match: 'wikilink:',
  open(href, { machine, thread }) {
    const { target, heading } = parseWikilink(href)!
    return superego.dispatch('pane.open', { thread: thread!.id, kind: 'note', params: { path: target, heading } }, { machine })
      .then(() => undefined, (error: Error) => error.message)
  },
  target: (href) => parseWikilink(href)!.target,
})

Return (or resolve to) a string to say why it couldn't: the link is struck through with it. Claiming files is the same with a test: match: (href, kind) => /\.md$/.test(href) takes Markdown links and paths in code alike, ahead of the core's. The core's file and web handlers stay the core's rather than files' or browser's: both extensions are optional, and a link to a file or a page has to work in a thread that goes without them.

Hearing the window

on tells a UI half what happens in the window, whatever it draws. Listening is owned like everything else, and stops at teardown. A thread that goes without the extension isn't heard of; a profile hears only its own threads.

// A thread wants a look while the window is in the background: say so in the window's title.
superego.on('thread.status', ({ thread, before }) => {
  if (before === undefined || (superego.window.focused && superego.window.visible)) return
  if (unread(thread)) document.title = `• ${thread.title}`    // finished, failed or needs you
})

Notifications and the app icon's count are the app's own (Settings → Notifications): an extension needn't notify.

window is how things are as the event arrives: focused, visible, the selection and the thread it shows, the machines the window reaches and each one's threads in use (by machine id). The core marks a finished thread seen the same way, on select, focus and thread.status.

auth.rejected is a machine's provider rejecting its credentials ({ machine, rejection }, a ProviderRejection): once, however many threads it stops. Those threads are blocked with kind auth (waitingForSignIn), quiet on their own, and go on by themselves once the machine is signed in again; unread says nothing of them, and the app notifies once for all.

packages/cli/skill/window.md