Superego

Lifecycle and versions

Lifecycle and ownership

Set up, registrations owned by the extension, torn down when its profile changes or the daemon stops, then set up again

Each set-up of an extension, in either half, has one lifetime: everything it registers is owned by it, and teardown (its profile reloaded or gone, its UI revoked, the daemon stopping) ends all of it at once.

What each kind of code may do

A thread's life

starting makes a thread (a hook may move where it works and give it state, or refuse); started; turnStart and turnEnd around each run; archiving then archived on the way to archived, unarchiving then unarchived on the way back

const state = superego.state<{ path: string; branch: string }>()
superego.facts(({ state }) => state)                   // thread.facts.worktrees
superego.thread<{ path: string; branch: string }>({   // the state its starting gives a thread
  async starting(draft) {                              // draft.options: what thread.start asked for, by extension
    if (draft.options.worktrees !== true || !draft.checkout) return
    const { path, branch } = await makeWorktree(draft.checkout.top)  // yours: git worktree add
    return { cwd: path, state: { path, branch } }
  },
  async abandoned(draft, made) {                       // a later hook refused it: undo
    if (made) await removeWorktree(made.path)               // yours too
  },
  async archived(thread) {
    const tree = await state.get(thread.id)
    if (tree && await removeIfClean(tree.path)) return { note: 'its worktree is removed' }  // yours too
  },
})

Bundled extensions also declare whether they're required, once, in about (spread into both halves):

A required extension is always on; an optional one can be switched off per machine or left out by a profile, and that thread then has none of its agent parts or UI

Only the sidebar (threads), worktrees (archiving removes a folder and unarchiving puts it back: never switched off between the two) and the core's markdown are required. Everything else is optional, ego too, and the core's own coding-tools, panes and agents-md. Where a window part and a machine part should differ, they are two extensions: threads is the required sidebar in the window, and thread-tools, the agent's thread tools, an optional one on the machine, so switching the tools off leaves the sidebar (and the rows and links naming threads). The core's panes is the agent's pane_open: switched off, the agent can't open panes, but the window's own pane kinds stay, being the required core's. An extension with a UI half only needs no daemon half: the window declares it to each machine, which lists it and lets profiles do without it.

Versions and compatibility

Three versions, each for its own question:

Version What it versions Where it's said Who checks it
The release the code a machine runs: its build, and a checkout's git commit hello.machine.build and commit, Settings → Machines ("an older Superego") the user, who updates
The extension API what the host gives extensions: superego. in either half, 'superego', 'superego/ui'; semver, EXTENSION_API in packages/protocol/src/contract.ts (a minor version adds, a major one renames or removes) hello.api the host, setting an extension up
The protocol the wire: a generation, PROTOCOL_VERSION (2), and in it the features each side announces hello.version, hello.features both ends, at hello

And each extension's own version, semver, which its other half, profiles and scripts rely on.

Declaring them

An extension says its version and the extension API it needs in about (bundled), or in its definition (a profile's):

export const about = { name: 'orders', version: '1.2.0', api: '^5', title: 'Orders' } satisfies ExtensionAbout

The host's EXTENSION_API goes up a minor when the API grows, and a major when something an extension could rely on changes or goes, which also moves every bundled extension's api.

Checking them

Each daemon announces its manifest ({ name, version, api }) for every extension set up and on there in hello.extensions, kept current by features.changed; features holds protocol features only. In the window, has reads those manifests (the protocol's offers()):

has(machine, 'ext:git')          // set up and on there, at any version
has(machine, 'ext:git@^1.2')     // at 1.2 or later in 1.x
version(machine, 'git')          // '1.3.0'; '0.0.0' when it says none; undefined when it isn't there or is off

Ranges are the usual ones: ^1.2, ~1.2, >=1.2 <3, 1.2 (1.2.x), *, joined with ||.

The major is the window's to check: it draws a UI half for a machine's threads (its slots, views, panes, tool rows, entries, links, completions; its window actions while one is shown; its settings section for that machine) only where that machine runs the extension at the UI half's own major (below 1.0, its own minor, as semver has it), as it draws none for a thread that goes without the extension. A machine that doesn't announce it (switched off there, or a UI-only extension) doesn't stop it. So a UI half asks has only for a minor it relies on (@^1.<minor>), or where it draws without a thread.

Windows declare their extensions to each machine (extension.declare), so one with no daemon half is listed there even where the daemon doesn't bundle it (the app's daemon lists each bundled one's about, so it knows them from the start). When two windows declare one differently, the newest version's word is taken, whatever order they connect in (at the same version, the two are settled by what they say, the same way each time); an older window's never takes it back.

The skew policy

What a window and a daemon of different releases do with each other:

packages/cli/skill/lifecycle.md