@arcforge/types 2.0.121 → 2.0.122

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@arcforge/types",
3
- "version": "2.0.121",
3
+ "version": "2.0.122",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "main": "./src/index.ts",
7
7
  "exports": {
8
8
  ".": "./src/index.ts",
9
9
  "./session": "./src/session/index.ts",
10
+ "./tui-contract": "./src/tui-contract.ts",
10
11
  "./tsconfig.base.json": "./tsconfig.base.json"
11
12
  },
12
13
  "files": [
@@ -14,6 +15,7 @@
14
15
  "tsconfig.base.json"
15
16
  ],
16
17
  "scripts": {
18
+ "contract": "bun run scripts/contract.ts",
17
19
  "deploy": "echo \"This package is published ONLY by apps/tui/scripts/release.ts, which pins workspace:* deps to concrete versions first. Publishing it directly ships an unresolvable dependency.\" && exit 1"
18
20
  },
19
21
  "dependencies": {
package/src/index.ts CHANGED
@@ -23,4 +23,5 @@ export * from "./session"
23
23
  export * from "./kernel"
24
24
  export * from "./cognet"
25
25
  export * from "./tools"
26
+ export * from "./tui"
26
27
  export * from "./bench"
@@ -0,0 +1,8 @@
1
+ // GENERATED by scripts/contract.ts from src/tui.ts — do not edit.
2
+ //
3
+ // The TUI contract as source text, for `axon prepare` to wrap in
4
+ // `declare global` and write into a profile's or extension's type frame.
5
+ // A profile has no node_modules, so its globals cannot import — they must be
6
+ // this text, inlined.
7
+
8
+ export const TUI_CONTRACT = " /**\n * The TUI extension contract — what a user's `main.ts`, a profile config, and\n * a published extension are written against.\n *\n * ── This file is copied verbatim into generated type frames ──────────────────\n *\n * `axon prepare` writes this source text into a profile's `.axon/types/` and an\n * extension's `.extension/types/` as ambient globals. That is why it declares\n * NO imports: a profile directory has no node_modules for an import to resolve\n * through (see prompt-dts.ts, which accepted the same constraint for the same\n * reason). Unlike prompts, there is no duplicated copy to keep in step — the\n * generator reads THIS file, so the contract and the globals cannot drift.\n *\n * Adding an import here breaks every profile's typecheck. Add the type instead.\n *\n * ── What this layer is for ───────────────────────────────────────────────────\n *\n * Workflow design in the terminal, and nothing more. The rule that draws the\n * boundary: an extension DRIVES the conversation, it never CONSUMES it.\n * `agents.send()` returns void — an extension that awaited model output and\n * branched on its text would be writing an agent, in the config layer, badly.\n * Agent behaviour belongs in a cognet, which the same user can build.\n *\n * The surface is deliberately small and complete against one test: everything\n * reachable from the keyboard is reachable from code. Mode keys → `mode`,\n * typing → `input`, palette navigation → `palette`, `:` → `commands`, chords →\n * `keys`, `~`/`/`/`^` → `agents`, Ctrl+C → `tui`. `keys.send()` backstops\n * whatever this missed. Nothing here renders: user surfaces are built from the\n * palette primitives, so every extension's UI is as good as the built-in one\n * and stays that way when the palette improves.\n */\n\n // ── Disposal ─────────────────────────────────────────────────────────────────\n\n /**\n * Undoes one registration.\n *\n * Every `register`/`create` returns one, and the loader tracks them per\n * extension so a hot-reload can tear the previous load down before running\n * setup again. Without this, each reload leaves its registrations behind and\n * one keystroke fires N handlers — the accumulation `Hooks().reset()` exists to\n * prevent on the agent runtime side.\n */\n type Disposer = () => void\n\n // ── Palette ──────────────────────────────────────────────────────────────────\n\n /**\n * One row in any palette — user-created or built-in.\n *\n * This is the SAME item type the TUI's own modes produce. A user palette that\n * could not express what `~` or `^` expresses would turn every gap into a\n * feature request, so the built-ins hold no privileged row shape: they are\n * simply the palettes that ship.\n */\n type PaletteItem = {\n id: string\n label: string\n description?: string\n /**\n * Independently-searchable parts of this row, for a list long enough that\n * one substring match over `label` stops being enough — every query term\n * narrows against any chunk. The model palette sets route and model id as\n * separate chunks, which is what lets ~800 rows live in one flat list with\n * no tabs or pages. Omit for ordinary rows.\n */\n chunks?: readonly string[]\n /**\n * Run on Enter. A returned promise holds the palette in its working state\n * until it settles. The signal aborts when the user escapes mid-flight —\n * actions that cannot be cancelled may ignore it.\n */\n action?: (signal: AbortSignal) => void | Promise<void>\n /** Selecting this row rewrites the query to this text instead of running `action` — descending into a group. */\n descendQuery?: string\n /** Selecting this row shows these rows as a follow-up list — a confirm/choice step. Computed at the moment it is confirmed. */\n choices?: () => PaletteItem[]\n /** Run on cursor movement, before confirming — live preview. */\n preview?: () => void\n /** Shown in the working row while an async `action` is in flight. */\n workingMessage?: string\n /**\n * Close immediately and let `action` finish in the background, rather than\n * holding the list open behind a working row.\n *\n * Only for actions whose progress has its OWN surface. An action that\n * reports nowhere else must not set this, or its failure becomes invisible.\n */\n detach?: boolean\n /** Non-selectable section header. */\n header?: boolean\n /** Non-selectable blank spacer between groups. */\n separator?: boolean\n }\n\n /** A tab in a tabbed palette. First tab is active on entry. */\n type PaletteTab = {\n id: string\n label: string\n }\n\n /** Loading/error indicator shown above the item list. */\n type PaletteStatus =\n | { kind: \"loading\"; message: string }\n | { kind: \"error\"; message: string }\n | null\n\n /**\n * What one query resolves to — items plus everything else this palette has to\n * say about that same query.\n *\n * Derived from a single call so status, breadcrumb and items can never drift\n * out of sync, which is the failure mode of computing them as independently\n * triggered fields. Returning a bare array is shorthand for `{ items }`.\n */\n type PaletteResult = {\n items: PaletteItem[]\n /** Prefix shown on every row — a path walked so far. */\n breadcrumb?: string | null\n status?: PaletteStatus\n /** True when the query cannot resolve to anything selectable — a dead-end token. */\n invalid?: boolean\n }\n\n /**\n * A user-defined palette.\n *\n * `list` is the only required member: given the query and active tab, return\n * the rows. It may be async — the palette shows its own loading state while the\n * first call is in flight, and results are cached until `refresh()` is called\n * on the handle.\n */\n type PaletteDefinition = {\n /**\n * Produce the rows for one query.\n *\n * The TUI applies its own substring filter over the returned items unless\n * `filter: false` — so a list that does not care about `query` can ignore\n * the argument entirely and still be searchable.\n */\n list: (query: string, tab: string | null) => PaletteItem[] | PaletteResult | Promise<PaletteItem[] | PaletteResult>\n /** This palette filters by query itself — the TUI must not filter again. */\n filter?: boolean\n /** Declares this palette as tabbed. Omit for a single flat list. */\n tabs?: PaletteTab[]\n /** Max visible rows before scrolling. */\n maxHeight?: number\n /**\n * \"top\" (default): newest first, cursor starts at the top. \"bottom\": items\n * are given oldest→newest, the cursor starts on the last row and up-arrow\n * walks back in time — the terminal-log feel of history and session mode.\n */\n anchor?: \"top\" | \"bottom\"\n /**\n * A mode key that opens this palette from an empty input, e.g. \"&\".\n *\n * Throws at registration if the key is already taken — a silently shadowed\n * mode key is unbearable to debug in someone else's config.\n */\n key?: string\n /** Symbol shown in the input bar while this palette is open. Defaults to `key`. */\n symbol?: string\n /** One-line description, shown in `?` (help) alongside the built-in modes. */\n description?: string\n }\n\n /** Handle on one registered palette. */\n type PaletteHandle = {\n readonly name: string\n /** Open it. Rejects if another palette is already open — see `palette.open`. */\n open: () => Promise<void>\n /** Drop the cached list so the next open recomputes it. Does not reopen. */\n refresh: () => void\n /** Unregister, closing it first if it is open. */\n dispose: Disposer\n }\n\n /** A pick option carrying a value, for `pick` over things that are not strings. */\n type PickOption<T> = {\n label: string\n description?: string\n value: T\n }\n\n /**\n * The palette — the TUI's interaction primitive, and the reason this layer can\n * stay small. Registered palettes cover \"the user opens a list\"; `pick`,\n * `confirm` and `prompt` cover \"code asks the user a question\".\n *\n * The question verbs return promises rather than taking callbacks, which is\n * what makes multi-step flows fall out for free: they are sequential awaits,\n * not a wizard framework.\n *\n * Every question resolves to a cancelled value on escape — `undefined`, or\n * `false` for `confirm`. That is in the return type deliberately: a caller is\n * forced to handle the user walking away.\n */\n type PaletteApi = {\n /** Register a palette. Throws if `name` is taken. */\n create: (name: string, definition: PaletteDefinition) => PaletteHandle\n\n /** A registered palette by name, or null. */\n get: (name: string) => PaletteHandle | null\n\n /**\n * Open a registered palette by name.\n *\n * Throws if no palette has that name, and throws if another palette is\n * already open — stealing the palette out from under someone mid-navigation\n * is exactly the kind of silent degradation that makes an extension system\n * feel haunted. Check `palette.isOpen` first if a keybind might collide.\n */\n open: (name: string) => Promise<void>\n\n /** Close whatever is open. No-op when nothing is. */\n close: () => void\n\n /** True while any palette is open, built-in or user-defined. */\n readonly isOpen: boolean\n\n /** Ask the user to choose one of a list of strings. Resolves undefined on escape. */\n pick: {\n (options: readonly string[], opts?: { placeholder?: string }): Promise<string | undefined>\n <T>(options: readonly PickOption<T>[], opts?: { placeholder?: string }): Promise<T | undefined>\n }\n\n /** Ask a yes/no question. Resolves false on escape. */\n confirm: (message: string) => Promise<boolean>\n\n /** Ask for a line of text. Resolves undefined on escape. */\n prompt: (message: string, opts?: { placeholder?: string; initial?: string }) => Promise<string | undefined>\n }\n\n // ── Commands ─────────────────────────────────────────────────────────────────\n\n /**\n * Where a command sits in the `:` tree.\n *\n * `\"deploy\"` is top level; `[\"theme\", \"set\"]` is nested under a group, which is\n * created on demand. Both forms accepted — a flat command should not have to be\n * written as a one-element array.\n */\n type CommandPath = string | readonly string[]\n\n type CommandOptions = {\n /** Shown beside the command in the palette. */\n description?: string\n /** Shown in the working row while an async command runs. */\n workingMessage?: string\n }\n\n type CommandsApi = {\n /**\n * Add a command to the `:` tree.\n *\n * Built-in commands always win a collision, and two extensions colliding is\n * first-registered-wins with a warning naming both — never silent shadowing.\n */\n register: (path: CommandPath, action: (signal: AbortSignal) => void | Promise<void>, options?: CommandOptions) => Disposer\n\n /**\n * Run a command by path, exactly as pressing Enter on it would.\n *\n * This is how an extension reaches functionality that has a command but no\n * dedicated API — one verb instead of re-exposing every command's\n * implementation. Throws if the path resolves to nothing.\n */\n run: (path: CommandPath) => Promise<void>\n\n /** Every registered command path, built-in and user. */\n list: () => readonly string[][]\n }\n\n // ── Keys ─────────────────────────────────────────────────────────────────────\n\n type KeysApi = {\n /**\n * Bind a chord, e.g. \"ctrl+o\".\n *\n * Built-in bindings win; two extensions colliding is first-wins with a\n * warning naming both. Bindings do not fire while a palette is open.\n */\n register: (chord: string, handler: () => void | Promise<void>) => Disposer\n\n /**\n * Deliver a keypress as though the user had typed it.\n *\n * The escape hatch that keeps this surface honest: anything the API forgot\n * to expose is still reachable, so a missing verb is an inconvenience\n * rather than a wall.\n */\n send: (chord: string) => void\n }\n\n // ── Modes ────────────────────────────────────────────────────────────────────\n\n /**\n * Built-in mode names. A user palette registered with a `key` adds its own\n * name to what `mode.set` accepts at runtime, which is why this is not a\n * closed union at the type level.\n */\n type BuiltinMode =\n | \"normal\"\n | \"command\"\n | \"model\"\n | \"session\"\n | \"agent\"\n | \"instance\"\n | \"voice\"\n | \"help\"\n | \"history\"\n | \"prompt\"\n | \"module\"\n | \"script\"\n\n type ModeName = BuiltinMode | (string & {})\n\n type ModeApi = {\n /** Switch modes. Throws on an unknown mode rather than silently doing nothing. */\n set: (mode: ModeName) => Promise<void>\n /** The active mode. */\n get: () => ModeName\n /** The symbol currently shown in the input bar. */\n symbol: () => string\n }\n\n // ── Input ────────────────────────────────────────────────────────────────────\n\n /** The message box the user types into. */\n type InputApi = {\n get: () => string\n set: (text: string) => void\n /** Append to the current text without clearing it — the voice-transcript behaviour. */\n append: (text: string) => void\n clear: () => void\n /**\n * Send the current input as a message to the focused agent, exactly as\n * pressing Enter would, and clear the box. No-op when it is empty.\n */\n submit: () => Promise<void>\n }\n\n // ── Agents ───────────────────────────────────────────────────────────────────\n\n /** What a running instance looks like to an extension. */\n type AgentInstance = {\n /** Stable identity of this instance. Every instance verb addresses by this. */\n readonly id: string\n /** The agent project's name — several instances may share one. */\n readonly name: string\n /** True for the instance currently on screen. */\n readonly focused: boolean\n /** Null when idle. */\n readonly activity: \"booting\" | \"rebooting\" | \"shutting-down\" | \"working\" | null\n }\n\n /** An agent that can be started — a local project or a deployment. */\n type AgentTarget = {\n readonly name: string\n readonly kind: \"local\" | \"deployed\"\n /** Running instances of this agent, most recently focused first. */\n readonly instances: readonly AgentInstance[]\n }\n\n /**\n * Agents, addressed the way the TUI addresses them: you START by name and then\n * everything else is BY INSTANCE.\n *\n * That split is not incidental. One agent can have many live instances — that\n * is what `spawn` twice gives you — so a verb taking a name has no answer for\n * \"which one\", and collapsing the two would make siblings unreachable from\n * extensions.\n */\n type AgentsApi = {\n /** Every agent that can be started, with its live instances. */\n targets: () => Promise<readonly AgentTarget[]>\n\n /** Every running instance, in spawn order. */\n list: () => readonly AgentInstance[]\n\n /** One instance by id, or null if it is not running. */\n get: (id: string) => AgentInstance | null\n\n /** The instance currently on screen, or null when nothing is running. */\n focused: () => AgentInstance | null\n\n /**\n * Boot a new instance of an agent IN THE BACKGROUND, resolving once it is\n * live. The view does not change.\n *\n * Always a NEW instance — this is the sibling verb.\n *\n * Background is the whole point: a config that booted two agents would\n * otherwise have them race for the screen, and neither asked to be looked\n * at. Showing one is a separate, explicit act — `tui.nav(name)` goes to an\n * agent (booting one if none is live), and `agents.focus(id)` goes to a\n * specific instance.\n *\n * Returns the instance, which is what makes a workflow composable: the id\n * is how every other verb here addresses it, and one agent may have many\n * live instances, so \"the one I just started\" cannot be recovered from the\n * name afterwards.\n */\n spawn: (name: string) => Promise<AgentInstance>\n\n /** Put an instance on screen. Throws if it is not running. */\n focus: (id: string) => void\n\n /**\n * Shut an instance down. The only verb here that ends a conversation.\n *\n * Omit `id` for the focused instance.\n */\n stop: (id?: string) => Promise<void>\n\n /**\n * Reload an instance's blueprint in place. The conversation survives.\n *\n * Omit `id` for the focused instance.\n */\n reboot: (id?: string) => Promise<void>\n\n /**\n * Send a message to the FOCUSED instance, as though the user had typed it\n * and pressed Enter.\n *\n * Returns when the message is DELIVERED, not when the agent has answered,\n * and yields nothing: an extension drives the conversation and never\n * consumes it. Reading a model's output to decide what to do next is an\n * agent's job — build a cognet.\n *\n * Focused rather than addressable, deliberately. Delivery is not a simple\n * dispatch — a send during a switch is QUEUED for the agent arriving rather\n * than delivered to the one being left, which is the difference between a\n * message landing in the right conversation and the wrong one. That rule is\n * defined in terms of what the user is looking at, so a per-instance send\n * would need its own answer to a question the focused path already answers\n * correctly.\n *\n * Note that `spawn()` does NOT focus what it starts, so sending to a\n * freshly spawned agent means going to it first:\n *\n * const reviewer = await agents.spawn(\"@axon/reviewer\")\n * agents.focus(reviewer.id)\n * await agents.send(\"review main\")\n */\n send: (content: string) => Promise<void>\n\n /** Interrupt the focused instance's current wake, as Escape does. True if something was interrupted. */\n interrupt: () => boolean\n }\n\n // ── The TUI itself ───────────────────────────────────────────────────────────\n\n /** Terminal dimensions in cells. */\n type TuiSize = {\n readonly width: number\n readonly height: number\n }\n\n // ── Themes ───────────────────────────────────────────────────────────────────\n\n /**\n * Every colour name the terminal can render.\n *\n * ── Generated, not written ──────────────────────────────────────────────────\n *\n * The list between the markers is produced by `scripts/contract.ts` from\n * VTerm's own colour parser — its terminal basics (`brightcyan`) plus the full\n * CSS3 named set. Do not edit it by hand; a name here that the parser does not\n * know renders as nothing, which is the failure the union exists to prevent.\n */\n type ColorName =\n // <color-names>\n | \"aliceblue\"\n | \"antiquewhite\"\n | \"aqua\"\n | \"aquamarine\"\n | \"azure\"\n | \"beige\"\n | \"bisque\"\n | \"black\"\n | \"blanchedalmond\"\n | \"blue\"\n | \"blueviolet\"\n | \"brightblack\"\n | \"brightblue\"\n | \"brightcyan\"\n | \"brightgreen\"\n | \"brightmagenta\"\n | \"brightred\"\n | \"brightwhite\"\n | \"brightyellow\"\n | \"brown\"\n | \"burlywood\"\n | \"cadetblue\"\n | \"chartreuse\"\n | \"chocolate\"\n | \"coral\"\n | \"cornflowerblue\"\n | \"cornsilk\"\n | \"crimson\"\n | \"cyan\"\n | \"darkblue\"\n | \"darkcyan\"\n | \"darkgoldenrod\"\n | \"darkgray\"\n | \"darkgreen\"\n | \"darkgrey\"\n | \"darkkhaki\"\n | \"darkmagenta\"\n | \"darkolivegreen\"\n | \"darkorange\"\n | \"darkorchid\"\n | \"darkred\"\n | \"darksalmon\"\n | \"darkseagreen\"\n | \"darkslateblue\"\n | \"darkslategray\"\n | \"darkslategrey\"\n | \"darkturquoise\"\n | \"darkviolet\"\n | \"deeppink\"\n | \"deepskyblue\"\n | \"dimgray\"\n | \"dimgrey\"\n | \"dodgerblue\"\n | \"firebrick\"\n | \"floralwhite\"\n | \"forestgreen\"\n | \"fuchsia\"\n | \"gainsboro\"\n | \"ghostwhite\"\n | \"gold\"\n | \"goldenrod\"\n | \"gray\"\n | \"green\"\n | \"greenyellow\"\n | \"grey\"\n | \"honeydew\"\n | \"hotpink\"\n | \"indianred\"\n | \"indigo\"\n | \"ivory\"\n | \"khaki\"\n | \"lavender\"\n | \"lavenderblush\"\n | \"lawngreen\"\n | \"lemonchiffon\"\n | \"lightblue\"\n | \"lightcoral\"\n | \"lightcyan\"\n | \"lightgoldenrodyellow\"\n | \"lightgray\"\n | \"lightgreen\"\n | \"lightgrey\"\n | \"lightpink\"\n | \"lightsalmon\"\n | \"lightseagreen\"\n | \"lightskyblue\"\n | \"lightslategray\"\n | \"lightslategrey\"\n | \"lightsteelblue\"\n | \"lightyellow\"\n | \"lime\"\n | \"limegreen\"\n | \"linen\"\n | \"magenta\"\n | \"maroon\"\n | \"mediumaquamarine\"\n | \"mediumblue\"\n | \"mediumorchid\"\n | \"mediumpurple\"\n | \"mediumseagreen\"\n | \"mediumslateblue\"\n | \"mediumspringgreen\"\n | \"mediumturquoise\"\n | \"mediumvioletred\"\n | \"midnightblue\"\n | \"mintcream\"\n | \"mistyrose\"\n | \"moccasin\"\n | \"navajowhite\"\n | \"navy\"\n | \"oldlace\"\n | \"olive\"\n | \"olivedrab\"\n | \"orange\"\n | \"orangered\"\n | \"orchid\"\n | \"palegoldenrod\"\n | \"palegreen\"\n | \"paleturquoise\"\n | \"palevioletred\"\n | \"papayawhip\"\n | \"peachpuff\"\n | \"peru\"\n | \"pink\"\n | \"plum\"\n | \"powderblue\"\n | \"purple\"\n | \"rebeccapurple\"\n | \"red\"\n | \"rosybrown\"\n | \"royalblue\"\n | \"saddlebrown\"\n | \"salmon\"\n | \"sandybrown\"\n | \"seagreen\"\n | \"seashell\"\n | \"sienna\"\n | \"silver\"\n | \"skyblue\"\n | \"slateblue\"\n | \"slategray\"\n | \"slategrey\"\n | \"snow\"\n | \"springgreen\"\n | \"steelblue\"\n | \"tan\"\n | \"teal\"\n | \"thistle\"\n | \"tomato\"\n | \"turquoise\"\n | \"violet\"\n | \"wheat\"\n | \"white\"\n | \"whitesmoke\"\n | \"yellow\"\n | \"yellowgreen\"\n // </color-names>\n\n /**\n * Any colour a theme token can hold.\n *\n * A named colour autocompletes; so does `transparent`, which means \"paint\n * nothing and let the real terminal show through\" — the right answer for\n * `background` in almost every theme.\n *\n * `(string & {})` keeps that autocomplete while still accepting the forms a\n * union cannot enumerate: `#1a1b26`, `rgb(26, 27, 38)`, an rgba() with alpha.\n * Unlike `syntax`, an unrecognised value here is not automatically a typo —\n * hex is the common case — so this stays open where that one is closed.\n */\n type ThemeColor =\n | ColorName\n | \"transparent\"\n | (string & {})\n\n /**\n * The seven tokens every Axon surface draws from.\n *\n * Closed on purpose. The TUI reached ~30 hard-coded colours before this — four\n * greys nobody chose deliberately, five reds — and a theme API with a field per\n * call site would preserve that forever: a \"theme\" would mean thirty decisions,\n * and no two themes would agree what any of them were for.\n *\n * Seven decisions, and every surface derives from them. That is what makes a\n * theme portable: whatever an author writes lands on the same things.\n */\n type ThemeTokens = {\n /** Accent. Selection, the input rule, focused rows, links. */\n primary: ThemeColor\n /** The terminal's own ground. */\n background: ThemeColor\n /** Ordinary foreground — what most text is. */\n text: ThemeColor\n /** Secondary foreground: paths, descriptions, timestamps, anything subordinate. */\n dim: ThemeColor\n /** Something needs attention but nothing failed. */\n warn: ThemeColor\n /** Something failed. */\n error: ThemeColor\n /**\n * Syntax highlighting for code blocks and the editor.\n *\n * A bundled theme name autocompletes — see `BundledSyntax` for the full\n * set. An author who wants their own tokenisation passes a TextMate theme\n * object instead, which is the same shape Shiki takes.\n *\n * Deliberately NOT widened with `(string & {})` the way `ThemeColor` is.\n * A colour Axon does not recognise still renders — the terminal hands it\n * to the ANSI layer and something sensible happens. A syntax theme name\n * Shiki does not have loads nothing, so an unrecognised string is always a\n * typo, and the union is what turns it into a red squiggle in the user's\n * editor instead of unhighlighted code they have to diagnose.\n */\n syntax: BundledSyntax | Record<string, unknown>\n }\n\n /** A registered theme: its tokens plus the name it is addressed by. */\n type Theme = ThemeTokens & { name: string }\n\n /**\n * Every syntax theme that ships with Axon.\n *\n * ── Generated, not written ──────────────────────────────────────────────────\n *\n * The list between the markers below is produced by `scripts/contract.ts` from\n * Shiki's own `bundledThemes`, and rewritten in place whenever that script\n * runs. Do not edit it by hand — a name here that Shiki does not have is a\n * theme that typechecks and then fails to load at runtime, which is exactly the\n * failure a literal union is supposed to prevent.\n *\n * It is a literal union rather than an import because this file is copied\n * verbatim into a profile's type frame, where there is no node_modules to\n * import Shiki through. The generator is what keeps the copy honest.\n *\n * ── Bundling all of them is nearly free ─────────────────────────────────────\n *\n * Shiki's bundle is a map of dynamic-import thunks and the highlighter is\n * constructed with ONE theme, calling `loadTheme()` for each further one a user\n * actually selects. So the cost of offering every theme is a single import at\n * the moment someone picks it — not the whole set at boot.\n */\n type BundledSyntax =\n // <bundled-syntax>\n | \"andromeeda\"\n | \"aurora-x\"\n | \"ayu-dark\"\n | \"catppuccin-frappe\"\n | \"catppuccin-latte\"\n | \"catppuccin-macchiato\"\n | \"catppuccin-mocha\"\n | \"dark-plus\"\n | \"dracula\"\n | \"dracula-soft\"\n | \"everforest-dark\"\n | \"everforest-light\"\n | \"github-dark\"\n | \"github-dark-default\"\n | \"github-dark-dimmed\"\n | \"github-dark-high-contrast\"\n | \"github-light\"\n | \"github-light-default\"\n | \"github-light-high-contrast\"\n | \"houston\"\n | \"kanagawa-dragon\"\n | \"kanagawa-lotus\"\n | \"kanagawa-wave\"\n | \"laserwave\"\n | \"light-plus\"\n | \"material-theme\"\n | \"material-theme-darker\"\n | \"material-theme-lighter\"\n | \"material-theme-ocean\"\n | \"material-theme-palenight\"\n | \"min-dark\"\n | \"min-light\"\n | \"monokai\"\n | \"night-owl\"\n | \"nord\"\n | \"one-dark-pro\"\n | \"one-light\"\n | \"plastic\"\n | \"poimandres\"\n | \"red\"\n | \"rose-pine\"\n | \"rose-pine-dawn\"\n | \"rose-pine-moon\"\n | \"slack-dark\"\n | \"slack-ochin\"\n | \"snazzy-light\"\n | \"solarized-dark\"\n | \"solarized-light\"\n | \"synthwave-84\"\n | \"tokyo-night\"\n | \"vesper\"\n | \"vitesse-black\"\n | \"vitesse-dark\"\n | \"vitesse-light\"\n // </bundled-syntax>\n /** Axon's own, and the default. */\n | \"arcnight\"\n\n /**\n * Themes — the terminal's colours, and switching between them.\n *\n * A theme is registered like a palette and applied like a mode. `\"` opens the\n * built-in picker, which previews as the cursor moves: hovering a row paints it\n * for real, because a preview that rendered differently from the result would\n * be worth nothing.\n */\n type ThemeApi = {\n /**\n * Register a theme. Throws if the name is taken. Returns a disposer.\n *\n * Name first, tokens second — the same shape as `palette.create`, so the\n * two read alike rather than one carrying its identity inside the object\n * and the other beside it.\n */\n create: (name: string, tokens: ThemeTokens) => Disposer\n\n /** Paint a theme and keep it. Throws on an unknown name. */\n set: (name: string) => void\n\n /** Every registered theme, built-ins first. */\n list: () => readonly Theme[]\n\n /** The theme currently painted. */\n readonly active: Theme\n }\n\n /**\n * Everything that belongs to the terminal rather than to one of the domains\n * above. Kept deliberately thin — a verb with a natural home in `palette`,\n * `commands`, `keys`, `mode`, `input` or `agents` belongs there.\n */\n type TuiApi = {\n /**\n * Go to an agent: focus the instance the user was last on, booting one if\n * none is live. The `~` key's behaviour.\n *\n * Name-addressed on purpose — \"take me to this agent\" is a different verb\n * from \"focus this exact instance\" (`agents.focus`), and both are real.\n */\n nav: (name: string) => Promise<void>\n\n /**\n * Register a lifecycle handler. See TuiHooks.\n *\n * Available everywhere — `main.ts`, a `plugins/` file, an extension's\n * `setup()` — because there is no capability difference between them, only\n * a timing one. `plugins/` is where hooks live by convention, not by rule.\n */\n hook: <N extends TuiHookName>(name: N, handler: TuiHooks[N]) => Disposer\n\n /**\n * A brief label on the cwd row — the same line the ctrl+c and double-esc\n * hints borrow. Flashes for 300ms by default, then the row returns to the\n * path.\n *\n * tui.info(\"deployed\")\n * tui.warn(\"nothing to do\", 600)\n * tui.error(\"command failed\")\n *\n * ── A reaction, not a message ───────────────────────────────────────────\n *\n * This row's existing tenants are both feedback about the key just pressed,\n * and these are the same thing: something to catch the eye, not something\n * to read. Longer than ~50 characters is trailed with an ellipsis, which is\n * the honest consequence of a one-line surface rather than a limit to work\n * around.\n *\n * So anything with CONTENT — a reason, a path, a stack — does not belong\n * here. Throw instead: it lands in the config error list on the chat page,\n * which is scrollable and stays put.\n *\n * The second argument is milliseconds, clamped to a few seconds. The\n * terminal's own hints outrank all three verbs — one fired during the\n * ctrl+c window waits rather than displacing the exit ladder.\n */\n info: (message: string, ms?: number) => void\n\n /** As `info`, in the warning colour. */\n warn: (message: string, ms?: number) => void\n\n /** As `info`, in the error colour. For \"that failed\" — never for why. */\n error: (message: string, ms?: number) => void\n\n readonly size: TuiSize\n\n /** The directory the TUI was launched from. */\n readonly cwd: string\n\n /** Version of the running Axon CLI. */\n readonly version: string\n\n /**\n * Quit, running the same exit guards a Ctrl+C does.\n *\n * There is deliberately no `update()`: a self-update hands off to a helper\n * that runs after the process exits, and an extension triggering that is a\n * way for a config to brick an install mid-session.\n */\n exit: () => Promise<void>\n }\n\n // ── Hooks ────────────────────────────────────────────────────────────────────\n //\n // ONE verb: `tui.hook(name, handler)`. There is deliberately no `.on()`\n // alongside it.\n //\n // A blocking `hook()` and a fire-and-forget `on()` are indistinguishable at the\n // call site — one letter apart, differing only in a consequence you cannot see\n // — and picking the wrong one buys either a race or a hang. Whether the TUI\n // waits is a property of the EVENT, not of how a handler was registered: `boot`\n // has a meaningful \"before\" to run in, `mode:changed` announces something that\n // already happened and waiting on it only delays the UI.\n //\n // So the event decides, the types say which is which, and a user who wants\n // fire-and-forget writes it where it is visible:\n //\n // tui.hook(\"tui:boot\", () => { void backgroundSync() })\n\n /**\n * Gating hooks — the TUI WAITS for these, and they can fail the operation.\n *\n * Only lifecycle transitions with a real \"before\" qualify. A slow handler here\n * delays the terminal, so the runtime bounds it: exceeding the budget reports\n * `extension X is blocking <hook>` and continues. It never hangs silently, and\n * a config that stalls boot must always say so — an unexplained frozen terminal\n * is the worst failure this feature can produce.\n */\n type TuiGateHooks = {\n /** Before the TUI becomes interactive. Registration is done; the screen is not up. */\n \"tui:boot\": () => void | Promise<void>\n /** Before shutdown proceeds. The last point at which anything can be flushed to disk. */\n \"tui:shutdown\": () => void | Promise<void>\n }\n\n /**\n * Notification hooks — announcements of something that ALREADY happened.\n *\n * Handlers return void: nothing waits, and nothing they do can alter the event.\n * That is enforced by the signature rather than documented, so the question\n * \"does the TUI block on this?\" is answered by the type instead of by reading\n * the runtime. A handler needing async work owns it (`void doThing()`), which\n * keeps the fire-and-forget visible at the call site.\n */\n type TuiNotifyHooks = {\n /** The TUI is live and interactive. */\n \"tui:ready\": () => void\n\n /**\n * The config was reloaded — `:reload`, or a file change.\n *\n * Fires on the NEW generation, after every registration is in place. The\n * old generation is already disposed and never sees it: its handlers went\n * with everything else it registered.\n *\n * Distinct from `tui:boot`, which also runs on a reload but gates it. Use\n * boot for setup that must finish first; use this to react to having been\n * reloaded — refreshing a cached palette, re-reading a file on disk.\n */\n \"tui:reloaded\": () => void\n\n /** An instance finished booting. */\n \"agent:ready\": (instance: AgentInstance) => void\n /** An instance shut down. */\n \"agent:stopped\": (instance: AgentInstance) => void\n /** A different instance came on screen. */\n \"agent:focused\": (instance: AgentInstance) => void\n\n /** The user sent a message. Fires once it is delivered. */\n \"message:sent\": (payload: { content: string; instance: AgentInstance }) => void\n /**\n * The agent finished a wake.\n *\n * Carries no content on purpose. A payload with the model's reply would\n * reopen the consumption boundary through the back door — an extension\n * reacting to WHAT was said is writing an agent, which is a cognet's job.\n * This says only THAT a wake completed.\n */\n \"message:received\": (payload: { instance: AgentInstance }) => void\n\n /** The active mode changed. */\n \"mode:changed\": (payload: { from: ModeName; to: ModeName }) => void\n }\n\n /** Every lifecycle hook, gating and notifying. */\n type TuiHooks = TuiGateHooks & TuiNotifyHooks\n\n type TuiHookName = keyof TuiHooks\n\n /**\n * A plugin file under `plugins/`.\n *\n * Plugins need no wrapper and no default export — `tui.hook(...)` at module\n * scope is the whole API, exactly as `main.ts` registers commands at module\n * scope. The file is hooks by convention rather than by ceremony, and there is\n * one way to reach every verb from every file in a profile.\n *\n * What separates a plugin from `setup()` is TIME, not capability: setup runs at\n * load, before anything is on screen, and is where registration belongs —\n * registering a command from a live hook would flicker it into a palette the\n * user is already looking at.\n *\n * A throwing handler disables its extension with a visible error. It never\n * takes the TUI down, and it is never silently swallowed.\n */\n type PluginModule = void\n\n // ── Extensions ───────────────────────────────────────────────────────────────\n\n /**\n * An extension's `extension.config.ts`.\n *\n * ── An extension is a profile, packaged ──────────────────────────────────────\n *\n * There is no `setup()`. An extension's behaviour lives in its `main.ts` and\n * its `plugins/`, registered at module scope, exactly as a user's own profile\n * does — same files, same globals, same moment. That symmetry is the point: a\n * user who has written a `main.ts` can publish it, and a reader who knows one\n * layout knows both.\n *\n * A `setup()` wrapper would have made the two differ for no gain. It exists on\n * `defineModule` because a module has data the loader must read WITHOUT\n * executing it — an options schema to validate, `emits` for typegen to merge,\n * env and policy requirements, sub-modules to flatten at manifest time. An\n * extension has none of that: its identity is package.json, and its behaviour\n * is registration.\n *\n * ── Then why does this file exist? ───────────────────────────────────────────\n *\n * It marks the directory as an extension. A kind is identified by its config\n * file (see detectKind), and `main.ts` cannot be that marker — a profile has\n * one, and so does half of npm.\n *\n * It is deliberately empty today. Keeping it means declarative, inspectable\n * per-extension data has somewhere to land later without a breaking change —\n * options schemas being the obvious candidate, if third-party configuration\n * ever needs a validated boundary rather than a user editing TypeScript.\n */\n type ExtensionConfig = {\n /**\n * Reserved. An extension declares nothing here yet — identity lives in\n * package.json and behaviour lives in main.ts.\n */\n readonly _reserved?: never\n }\n\n /** What `defineExtension()` returns. */\n type ExtensionDefinition = {\n _kind: \"extension\"\n config: ExtensionConfig\n }\n\n // ── Profile ──────────────────────────────────────────────────────────────────\n\n /**\n * One entry in `profile.config.ts`'s `extensions`.\n *\n * `\"@axon/vim\"` resolves from the registry and installs into the profile\n * frame; `\"./extensions/sketch\"` is a local directory. The object form lets an\n * extension be disabled without deleting its line — which is what makes this\n * editable by machine, the reason the enabled set is declared here rather than\n * being the side-effect of running code.\n */\n type ExtensionEntry =\n | string\n | {\n /** Registry specifier or local path. */\n source: string\n /** Default true. False keeps the entry but does not load it. */\n enabled?: boolean\n }\n\n /**\n * A user's `profile.config.ts` — what is ENABLED, declaratively.\n *\n * Declarative rather than imperative registration calls specifically so it can\n * be edited by machine: installing an extension from Fleet or the CLI is a data\n * edit to this array, which is not possible when the enabled set is the\n * side-effect of running arbitrary code.\n *\n * Behaviour lives in `main.ts`; this file only says what loads.\n */\n type ProfileConfig = {\n extensions?: ExtensionEntry[]\n }\n\n /** What `defineProfile()` returns. */\n type ProfileDefinition = {\n _kind: \"profile\"\n config: ProfileConfig\n }"
package/src/tui.ts ADDED
@@ -0,0 +1,1067 @@
1
+ /**
2
+ * The TUI extension contract — what a user's `main.ts`, a profile config, and
3
+ * a published extension are written against.
4
+ *
5
+ * ── This file is copied verbatim into generated type frames ──────────────────
6
+ *
7
+ * `axon prepare` writes this source text into a profile's `.axon/types/` and an
8
+ * extension's `.extension/types/` as ambient globals. That is why it declares
9
+ * NO imports: a profile directory has no node_modules for an import to resolve
10
+ * through (see prompt-dts.ts, which accepted the same constraint for the same
11
+ * reason). Unlike prompts, there is no duplicated copy to keep in step — the
12
+ * generator reads THIS file, so the contract and the globals cannot drift.
13
+ *
14
+ * Adding an import here breaks every profile's typecheck. Add the type instead.
15
+ *
16
+ * ── What this layer is for ───────────────────────────────────────────────────
17
+ *
18
+ * Workflow design in the terminal, and nothing more. The rule that draws the
19
+ * boundary: an extension DRIVES the conversation, it never CONSUMES it.
20
+ * `agents.send()` returns void — an extension that awaited model output and
21
+ * branched on its text would be writing an agent, in the config layer, badly.
22
+ * Agent behaviour belongs in a cognet, which the same user can build.
23
+ *
24
+ * The surface is deliberately small and complete against one test: everything
25
+ * reachable from the keyboard is reachable from code. Mode keys → `mode`,
26
+ * typing → `input`, palette navigation → `palette`, `:` → `commands`, chords →
27
+ * `keys`, `~`/`/`/`^` → `agents`, Ctrl+C → `tui`. `keys.send()` backstops
28
+ * whatever this missed. Nothing here renders: user surfaces are built from the
29
+ * palette primitives, so every extension's UI is as good as the built-in one
30
+ * and stays that way when the palette improves.
31
+ */
32
+
33
+ // ── Disposal ─────────────────────────────────────────────────────────────────
34
+
35
+ /**
36
+ * Undoes one registration.
37
+ *
38
+ * Every `register`/`create` returns one, and the loader tracks them per
39
+ * extension so a hot-reload can tear the previous load down before running
40
+ * setup again. Without this, each reload leaves its registrations behind and
41
+ * one keystroke fires N handlers — the accumulation `Hooks().reset()` exists to
42
+ * prevent on the agent runtime side.
43
+ */
44
+ export type Disposer = () => void
45
+
46
+ // ── Palette ──────────────────────────────────────────────────────────────────
47
+
48
+ /**
49
+ * One row in any palette — user-created or built-in.
50
+ *
51
+ * This is the SAME item type the TUI's own modes produce. A user palette that
52
+ * could not express what `~` or `^` expresses would turn every gap into a
53
+ * feature request, so the built-ins hold no privileged row shape: they are
54
+ * simply the palettes that ship.
55
+ */
56
+ export type PaletteItem = {
57
+ id: string
58
+ label: string
59
+ description?: string
60
+ /**
61
+ * Independently-searchable parts of this row, for a list long enough that
62
+ * one substring match over `label` stops being enough — every query term
63
+ * narrows against any chunk. The model palette sets route and model id as
64
+ * separate chunks, which is what lets ~800 rows live in one flat list with
65
+ * no tabs or pages. Omit for ordinary rows.
66
+ */
67
+ chunks?: readonly string[]
68
+ /**
69
+ * Run on Enter. A returned promise holds the palette in its working state
70
+ * until it settles. The signal aborts when the user escapes mid-flight —
71
+ * actions that cannot be cancelled may ignore it.
72
+ */
73
+ action?: (signal: AbortSignal) => void | Promise<void>
74
+ /** Selecting this row rewrites the query to this text instead of running `action` — descending into a group. */
75
+ descendQuery?: string
76
+ /** Selecting this row shows these rows as a follow-up list — a confirm/choice step. Computed at the moment it is confirmed. */
77
+ choices?: () => PaletteItem[]
78
+ /** Run on cursor movement, before confirming — live preview. */
79
+ preview?: () => void
80
+ /** Shown in the working row while an async `action` is in flight. */
81
+ workingMessage?: string
82
+ /**
83
+ * Close immediately and let `action` finish in the background, rather than
84
+ * holding the list open behind a working row.
85
+ *
86
+ * Only for actions whose progress has its OWN surface. An action that
87
+ * reports nowhere else must not set this, or its failure becomes invisible.
88
+ */
89
+ detach?: boolean
90
+ /** Non-selectable section header. */
91
+ header?: boolean
92
+ /** Non-selectable blank spacer between groups. */
93
+ separator?: boolean
94
+ }
95
+
96
+ /** A tab in a tabbed palette. First tab is active on entry. */
97
+ export type PaletteTab = {
98
+ id: string
99
+ label: string
100
+ }
101
+
102
+ /** Loading/error indicator shown above the item list. */
103
+ export type PaletteStatus =
104
+ | { kind: "loading"; message: string }
105
+ | { kind: "error"; message: string }
106
+ | null
107
+
108
+ /**
109
+ * What one query resolves to — items plus everything else this palette has to
110
+ * say about that same query.
111
+ *
112
+ * Derived from a single call so status, breadcrumb and items can never drift
113
+ * out of sync, which is the failure mode of computing them as independently
114
+ * triggered fields. Returning a bare array is shorthand for `{ items }`.
115
+ */
116
+ export type PaletteResult = {
117
+ items: PaletteItem[]
118
+ /** Prefix shown on every row — a path walked so far. */
119
+ breadcrumb?: string | null
120
+ status?: PaletteStatus
121
+ /** True when the query cannot resolve to anything selectable — a dead-end token. */
122
+ invalid?: boolean
123
+ }
124
+
125
+ /**
126
+ * A user-defined palette.
127
+ *
128
+ * `list` is the only required member: given the query and active tab, return
129
+ * the rows. It may be async — the palette shows its own loading state while the
130
+ * first call is in flight, and results are cached until `refresh()` is called
131
+ * on the handle.
132
+ */
133
+ export type PaletteDefinition = {
134
+ /**
135
+ * Produce the rows for one query.
136
+ *
137
+ * The TUI applies its own substring filter over the returned items unless
138
+ * `filter: false` — so a list that does not care about `query` can ignore
139
+ * the argument entirely and still be searchable.
140
+ */
141
+ list: (query: string, tab: string | null) => PaletteItem[] | PaletteResult | Promise<PaletteItem[] | PaletteResult>
142
+ /** This palette filters by query itself — the TUI must not filter again. */
143
+ filter?: boolean
144
+ /** Declares this palette as tabbed. Omit for a single flat list. */
145
+ tabs?: PaletteTab[]
146
+ /** Max visible rows before scrolling. */
147
+ maxHeight?: number
148
+ /**
149
+ * "top" (default): newest first, cursor starts at the top. "bottom": items
150
+ * are given oldest→newest, the cursor starts on the last row and up-arrow
151
+ * walks back in time — the terminal-log feel of history and session mode.
152
+ */
153
+ anchor?: "top" | "bottom"
154
+ /**
155
+ * A mode key that opens this palette from an empty input, e.g. "&".
156
+ *
157
+ * Throws at registration if the key is already taken — a silently shadowed
158
+ * mode key is unbearable to debug in someone else's config.
159
+ */
160
+ key?: string
161
+ /** Symbol shown in the input bar while this palette is open. Defaults to `key`. */
162
+ symbol?: string
163
+ /** One-line description, shown in `?` (help) alongside the built-in modes. */
164
+ description?: string
165
+ }
166
+
167
+ /** Handle on one registered palette. */
168
+ export type PaletteHandle = {
169
+ readonly name: string
170
+ /** Open it. Rejects if another palette is already open — see `palette.open`. */
171
+ open: () => Promise<void>
172
+ /** Drop the cached list so the next open recomputes it. Does not reopen. */
173
+ refresh: () => void
174
+ /** Unregister, closing it first if it is open. */
175
+ dispose: Disposer
176
+ }
177
+
178
+ /** A pick option carrying a value, for `pick` over things that are not strings. */
179
+ export type PickOption<T> = {
180
+ label: string
181
+ description?: string
182
+ value: T
183
+ }
184
+
185
+ /**
186
+ * The palette — the TUI's interaction primitive, and the reason this layer can
187
+ * stay small. Registered palettes cover "the user opens a list"; `pick`,
188
+ * `confirm` and `prompt` cover "code asks the user a question".
189
+ *
190
+ * The question verbs return promises rather than taking callbacks, which is
191
+ * what makes multi-step flows fall out for free: they are sequential awaits,
192
+ * not a wizard framework.
193
+ *
194
+ * Every question resolves to a cancelled value on escape — `undefined`, or
195
+ * `false` for `confirm`. That is in the return type deliberately: a caller is
196
+ * forced to handle the user walking away.
197
+ */
198
+ export type PaletteApi = {
199
+ /** Register a palette. Throws if `name` is taken. */
200
+ create: (name: string, definition: PaletteDefinition) => PaletteHandle
201
+
202
+ /** A registered palette by name, or null. */
203
+ get: (name: string) => PaletteHandle | null
204
+
205
+ /**
206
+ * Open a registered palette by name.
207
+ *
208
+ * Throws if no palette has that name, and throws if another palette is
209
+ * already open — stealing the palette out from under someone mid-navigation
210
+ * is exactly the kind of silent degradation that makes an extension system
211
+ * feel haunted. Check `palette.isOpen` first if a keybind might collide.
212
+ */
213
+ open: (name: string) => Promise<void>
214
+
215
+ /** Close whatever is open. No-op when nothing is. */
216
+ close: () => void
217
+
218
+ /** True while any palette is open, built-in or user-defined. */
219
+ readonly isOpen: boolean
220
+
221
+ /** Ask the user to choose one of a list of strings. Resolves undefined on escape. */
222
+ pick: {
223
+ (options: readonly string[], opts?: { placeholder?: string }): Promise<string | undefined>
224
+ <T>(options: readonly PickOption<T>[], opts?: { placeholder?: string }): Promise<T | undefined>
225
+ }
226
+
227
+ /** Ask a yes/no question. Resolves false on escape. */
228
+ confirm: (message: string) => Promise<boolean>
229
+
230
+ /** Ask for a line of text. Resolves undefined on escape. */
231
+ prompt: (message: string, opts?: { placeholder?: string; initial?: string }) => Promise<string | undefined>
232
+ }
233
+
234
+ // ── Commands ─────────────────────────────────────────────────────────────────
235
+
236
+ /**
237
+ * Where a command sits in the `:` tree.
238
+ *
239
+ * `"deploy"` is top level; `["theme", "set"]` is nested under a group, which is
240
+ * created on demand. Both forms accepted — a flat command should not have to be
241
+ * written as a one-element array.
242
+ */
243
+ export type CommandPath = string | readonly string[]
244
+
245
+ export type CommandOptions = {
246
+ /** Shown beside the command in the palette. */
247
+ description?: string
248
+ /** Shown in the working row while an async command runs. */
249
+ workingMessage?: string
250
+ }
251
+
252
+ export type CommandsApi = {
253
+ /**
254
+ * Add a command to the `:` tree.
255
+ *
256
+ * Built-in commands always win a collision, and two extensions colliding is
257
+ * first-registered-wins with a warning naming both — never silent shadowing.
258
+ */
259
+ register: (path: CommandPath, action: (signal: AbortSignal) => void | Promise<void>, options?: CommandOptions) => Disposer
260
+
261
+ /**
262
+ * Run a command by path, exactly as pressing Enter on it would.
263
+ *
264
+ * This is how an extension reaches functionality that has a command but no
265
+ * dedicated API — one verb instead of re-exposing every command's
266
+ * implementation. Throws if the path resolves to nothing.
267
+ */
268
+ run: (path: CommandPath) => Promise<void>
269
+
270
+ /** Every registered command path, built-in and user. */
271
+ list: () => readonly string[][]
272
+ }
273
+
274
+ // ── Keys ─────────────────────────────────────────────────────────────────────
275
+
276
+ export type KeysApi = {
277
+ /**
278
+ * Bind a chord, e.g. "ctrl+o".
279
+ *
280
+ * Built-in bindings win; two extensions colliding is first-wins with a
281
+ * warning naming both. Bindings do not fire while a palette is open.
282
+ */
283
+ register: (chord: string, handler: () => void | Promise<void>) => Disposer
284
+
285
+ /**
286
+ * Deliver a keypress as though the user had typed it.
287
+ *
288
+ * The escape hatch that keeps this surface honest: anything the API forgot
289
+ * to expose is still reachable, so a missing verb is an inconvenience
290
+ * rather than a wall.
291
+ */
292
+ send: (chord: string) => void
293
+ }
294
+
295
+ // ── Modes ────────────────────────────────────────────────────────────────────
296
+
297
+ /**
298
+ * Built-in mode names. A user palette registered with a `key` adds its own
299
+ * name to what `mode.set` accepts at runtime, which is why this is not a
300
+ * closed union at the type level.
301
+ */
302
+ export type BuiltinMode =
303
+ | "normal"
304
+ | "command"
305
+ | "model"
306
+ | "session"
307
+ | "agent"
308
+ | "instance"
309
+ | "voice"
310
+ | "help"
311
+ | "history"
312
+ | "prompt"
313
+ | "module"
314
+ | "script"
315
+
316
+ export type ModeName = BuiltinMode | (string & {})
317
+
318
+ export type ModeApi = {
319
+ /** Switch modes. Throws on an unknown mode rather than silently doing nothing. */
320
+ set: (mode: ModeName) => Promise<void>
321
+ /** The active mode. */
322
+ get: () => ModeName
323
+ /** The symbol currently shown in the input bar. */
324
+ symbol: () => string
325
+ }
326
+
327
+ // ── Input ────────────────────────────────────────────────────────────────────
328
+
329
+ /** The message box the user types into. */
330
+ export type InputApi = {
331
+ get: () => string
332
+ set: (text: string) => void
333
+ /** Append to the current text without clearing it — the voice-transcript behaviour. */
334
+ append: (text: string) => void
335
+ clear: () => void
336
+ /**
337
+ * Send the current input as a message to the focused agent, exactly as
338
+ * pressing Enter would, and clear the box. No-op when it is empty.
339
+ */
340
+ submit: () => Promise<void>
341
+ }
342
+
343
+ // ── Agents ───────────────────────────────────────────────────────────────────
344
+
345
+ /** What a running instance looks like to an extension. */
346
+ export type AgentInstance = {
347
+ /** Stable identity of this instance. Every instance verb addresses by this. */
348
+ readonly id: string
349
+ /** The agent project's name — several instances may share one. */
350
+ readonly name: string
351
+ /** True for the instance currently on screen. */
352
+ readonly focused: boolean
353
+ /** Null when idle. */
354
+ readonly activity: "booting" | "rebooting" | "shutting-down" | "working" | null
355
+ }
356
+
357
+ /** An agent that can be started — a local project or a deployment. */
358
+ export type AgentTarget = {
359
+ readonly name: string
360
+ readonly kind: "local" | "deployed"
361
+ /** Running instances of this agent, most recently focused first. */
362
+ readonly instances: readonly AgentInstance[]
363
+ }
364
+
365
+ /**
366
+ * Agents, addressed the way the TUI addresses them: you START by name and then
367
+ * everything else is BY INSTANCE.
368
+ *
369
+ * That split is not incidental. One agent can have many live instances — that
370
+ * is what `spawn` twice gives you — so a verb taking a name has no answer for
371
+ * "which one", and collapsing the two would make siblings unreachable from
372
+ * extensions.
373
+ */
374
+ export type AgentsApi = {
375
+ /** Every agent that can be started, with its live instances. */
376
+ targets: () => Promise<readonly AgentTarget[]>
377
+
378
+ /** Every running instance, in spawn order. */
379
+ list: () => readonly AgentInstance[]
380
+
381
+ /** One instance by id, or null if it is not running. */
382
+ get: (id: string) => AgentInstance | null
383
+
384
+ /** The instance currently on screen, or null when nothing is running. */
385
+ focused: () => AgentInstance | null
386
+
387
+ /**
388
+ * Boot a new instance of an agent IN THE BACKGROUND, resolving once it is
389
+ * live. The view does not change.
390
+ *
391
+ * Always a NEW instance — this is the sibling verb.
392
+ *
393
+ * Background is the whole point: a config that booted two agents would
394
+ * otherwise have them race for the screen, and neither asked to be looked
395
+ * at. Showing one is a separate, explicit act — `tui.nav(name)` goes to an
396
+ * agent (booting one if none is live), and `agents.focus(id)` goes to a
397
+ * specific instance.
398
+ *
399
+ * Returns the instance, which is what makes a workflow composable: the id
400
+ * is how every other verb here addresses it, and one agent may have many
401
+ * live instances, so "the one I just started" cannot be recovered from the
402
+ * name afterwards.
403
+ */
404
+ spawn: (name: string) => Promise<AgentInstance>
405
+
406
+ /** Put an instance on screen. Throws if it is not running. */
407
+ focus: (id: string) => void
408
+
409
+ /**
410
+ * Shut an instance down. The only verb here that ends a conversation.
411
+ *
412
+ * Omit `id` for the focused instance.
413
+ */
414
+ stop: (id?: string) => Promise<void>
415
+
416
+ /**
417
+ * Reload an instance's blueprint in place. The conversation survives.
418
+ *
419
+ * Omit `id` for the focused instance.
420
+ */
421
+ reboot: (id?: string) => Promise<void>
422
+
423
+ /**
424
+ * Send a message to the FOCUSED instance, as though the user had typed it
425
+ * and pressed Enter.
426
+ *
427
+ * Returns when the message is DELIVERED, not when the agent has answered,
428
+ * and yields nothing: an extension drives the conversation and never
429
+ * consumes it. Reading a model's output to decide what to do next is an
430
+ * agent's job — build a cognet.
431
+ *
432
+ * Focused rather than addressable, deliberately. Delivery is not a simple
433
+ * dispatch — a send during a switch is QUEUED for the agent arriving rather
434
+ * than delivered to the one being left, which is the difference between a
435
+ * message landing in the right conversation and the wrong one. That rule is
436
+ * defined in terms of what the user is looking at, so a per-instance send
437
+ * would need its own answer to a question the focused path already answers
438
+ * correctly.
439
+ *
440
+ * Note that `spawn()` does NOT focus what it starts, so sending to a
441
+ * freshly spawned agent means going to it first:
442
+ *
443
+ * const reviewer = await agents.spawn("@axon/reviewer")
444
+ * agents.focus(reviewer.id)
445
+ * await agents.send("review main")
446
+ */
447
+ send: (content: string) => Promise<void>
448
+
449
+ /** Interrupt the focused instance's current wake, as Escape does. True if something was interrupted. */
450
+ interrupt: () => boolean
451
+ }
452
+
453
+ // ── The TUI itself ───────────────────────────────────────────────────────────
454
+
455
+ /** Terminal dimensions in cells. */
456
+ export type TuiSize = {
457
+ readonly width: number
458
+ readonly height: number
459
+ }
460
+
461
+ // ── Themes ───────────────────────────────────────────────────────────────────
462
+
463
+ /**
464
+ * Every colour name the terminal can render.
465
+ *
466
+ * ── Generated, not written ──────────────────────────────────────────────────
467
+ *
468
+ * The list between the markers is produced by `scripts/contract.ts` from
469
+ * VTerm's own colour parser — its terminal basics (`brightcyan`) plus the full
470
+ * CSS3 named set. Do not edit it by hand; a name here that the parser does not
471
+ * know renders as nothing, which is the failure the union exists to prevent.
472
+ */
473
+ export type ColorName =
474
+ // <color-names>
475
+ | "aliceblue"
476
+ | "antiquewhite"
477
+ | "aqua"
478
+ | "aquamarine"
479
+ | "azure"
480
+ | "beige"
481
+ | "bisque"
482
+ | "black"
483
+ | "blanchedalmond"
484
+ | "blue"
485
+ | "blueviolet"
486
+ | "brightblack"
487
+ | "brightblue"
488
+ | "brightcyan"
489
+ | "brightgreen"
490
+ | "brightmagenta"
491
+ | "brightred"
492
+ | "brightwhite"
493
+ | "brightyellow"
494
+ | "brown"
495
+ | "burlywood"
496
+ | "cadetblue"
497
+ | "chartreuse"
498
+ | "chocolate"
499
+ | "coral"
500
+ | "cornflowerblue"
501
+ | "cornsilk"
502
+ | "crimson"
503
+ | "cyan"
504
+ | "darkblue"
505
+ | "darkcyan"
506
+ | "darkgoldenrod"
507
+ | "darkgray"
508
+ | "darkgreen"
509
+ | "darkgrey"
510
+ | "darkkhaki"
511
+ | "darkmagenta"
512
+ | "darkolivegreen"
513
+ | "darkorange"
514
+ | "darkorchid"
515
+ | "darkred"
516
+ | "darksalmon"
517
+ | "darkseagreen"
518
+ | "darkslateblue"
519
+ | "darkslategray"
520
+ | "darkslategrey"
521
+ | "darkturquoise"
522
+ | "darkviolet"
523
+ | "deeppink"
524
+ | "deepskyblue"
525
+ | "dimgray"
526
+ | "dimgrey"
527
+ | "dodgerblue"
528
+ | "firebrick"
529
+ | "floralwhite"
530
+ | "forestgreen"
531
+ | "fuchsia"
532
+ | "gainsboro"
533
+ | "ghostwhite"
534
+ | "gold"
535
+ | "goldenrod"
536
+ | "gray"
537
+ | "green"
538
+ | "greenyellow"
539
+ | "grey"
540
+ | "honeydew"
541
+ | "hotpink"
542
+ | "indianred"
543
+ | "indigo"
544
+ | "ivory"
545
+ | "khaki"
546
+ | "lavender"
547
+ | "lavenderblush"
548
+ | "lawngreen"
549
+ | "lemonchiffon"
550
+ | "lightblue"
551
+ | "lightcoral"
552
+ | "lightcyan"
553
+ | "lightgoldenrodyellow"
554
+ | "lightgray"
555
+ | "lightgreen"
556
+ | "lightgrey"
557
+ | "lightpink"
558
+ | "lightsalmon"
559
+ | "lightseagreen"
560
+ | "lightskyblue"
561
+ | "lightslategray"
562
+ | "lightslategrey"
563
+ | "lightsteelblue"
564
+ | "lightyellow"
565
+ | "lime"
566
+ | "limegreen"
567
+ | "linen"
568
+ | "magenta"
569
+ | "maroon"
570
+ | "mediumaquamarine"
571
+ | "mediumblue"
572
+ | "mediumorchid"
573
+ | "mediumpurple"
574
+ | "mediumseagreen"
575
+ | "mediumslateblue"
576
+ | "mediumspringgreen"
577
+ | "mediumturquoise"
578
+ | "mediumvioletred"
579
+ | "midnightblue"
580
+ | "mintcream"
581
+ | "mistyrose"
582
+ | "moccasin"
583
+ | "navajowhite"
584
+ | "navy"
585
+ | "oldlace"
586
+ | "olive"
587
+ | "olivedrab"
588
+ | "orange"
589
+ | "orangered"
590
+ | "orchid"
591
+ | "palegoldenrod"
592
+ | "palegreen"
593
+ | "paleturquoise"
594
+ | "palevioletred"
595
+ | "papayawhip"
596
+ | "peachpuff"
597
+ | "peru"
598
+ | "pink"
599
+ | "plum"
600
+ | "powderblue"
601
+ | "purple"
602
+ | "rebeccapurple"
603
+ | "red"
604
+ | "rosybrown"
605
+ | "royalblue"
606
+ | "saddlebrown"
607
+ | "salmon"
608
+ | "sandybrown"
609
+ | "seagreen"
610
+ | "seashell"
611
+ | "sienna"
612
+ | "silver"
613
+ | "skyblue"
614
+ | "slateblue"
615
+ | "slategray"
616
+ | "slategrey"
617
+ | "snow"
618
+ | "springgreen"
619
+ | "steelblue"
620
+ | "tan"
621
+ | "teal"
622
+ | "thistle"
623
+ | "tomato"
624
+ | "turquoise"
625
+ | "violet"
626
+ | "wheat"
627
+ | "white"
628
+ | "whitesmoke"
629
+ | "yellow"
630
+ | "yellowgreen"
631
+ // </color-names>
632
+
633
+ /**
634
+ * Any colour a theme token can hold.
635
+ *
636
+ * A named colour autocompletes; so does `transparent`, which means "paint
637
+ * nothing and let the real terminal show through" — the right answer for
638
+ * `background` in almost every theme.
639
+ *
640
+ * `(string & {})` keeps that autocomplete while still accepting the forms a
641
+ * union cannot enumerate: `#1a1b26`, `rgb(26, 27, 38)`, an rgba() with alpha.
642
+ * Unlike `syntax`, an unrecognised value here is not automatically a typo —
643
+ * hex is the common case — so this stays open where that one is closed.
644
+ */
645
+ export type ThemeColor =
646
+ | ColorName
647
+ | "transparent"
648
+ | (string & {})
649
+
650
+ /**
651
+ * The seven tokens every Axon surface draws from.
652
+ *
653
+ * Closed on purpose. The TUI reached ~30 hard-coded colours before this — four
654
+ * greys nobody chose deliberately, five reds — and a theme API with a field per
655
+ * call site would preserve that forever: a "theme" would mean thirty decisions,
656
+ * and no two themes would agree what any of them were for.
657
+ *
658
+ * Seven decisions, and every surface derives from them. That is what makes a
659
+ * theme portable: whatever an author writes lands on the same things.
660
+ */
661
+ export type ThemeTokens = {
662
+ /** Accent. Selection, the input rule, focused rows, links. */
663
+ primary: ThemeColor
664
+ /** The terminal's own ground. */
665
+ background: ThemeColor
666
+ /** Ordinary foreground — what most text is. */
667
+ text: ThemeColor
668
+ /** Secondary foreground: paths, descriptions, timestamps, anything subordinate. */
669
+ dim: ThemeColor
670
+ /** Something needs attention but nothing failed. */
671
+ warn: ThemeColor
672
+ /** Something failed. */
673
+ error: ThemeColor
674
+ /**
675
+ * Syntax highlighting for code blocks and the editor.
676
+ *
677
+ * A bundled theme name autocompletes — see `BundledSyntax` for the full
678
+ * set. An author who wants their own tokenisation passes a TextMate theme
679
+ * object instead, which is the same shape Shiki takes.
680
+ *
681
+ * Deliberately NOT widened with `(string & {})` the way `ThemeColor` is.
682
+ * A colour Axon does not recognise still renders — the terminal hands it
683
+ * to the ANSI layer and something sensible happens. A syntax theme name
684
+ * Shiki does not have loads nothing, so an unrecognised string is always a
685
+ * typo, and the union is what turns it into a red squiggle in the user's
686
+ * editor instead of unhighlighted code they have to diagnose.
687
+ */
688
+ syntax: BundledSyntax | Record<string, unknown>
689
+ }
690
+
691
+ /** A registered theme: its tokens plus the name it is addressed by. */
692
+ export type Theme = ThemeTokens & { name: string }
693
+
694
+ /**
695
+ * Every syntax theme that ships with Axon.
696
+ *
697
+ * ── Generated, not written ──────────────────────────────────────────────────
698
+ *
699
+ * The list between the markers below is produced by `scripts/contract.ts` from
700
+ * Shiki's own `bundledThemes`, and rewritten in place whenever that script
701
+ * runs. Do not edit it by hand — a name here that Shiki does not have is a
702
+ * theme that typechecks and then fails to load at runtime, which is exactly the
703
+ * failure a literal union is supposed to prevent.
704
+ *
705
+ * It is a literal union rather than an import because this file is copied
706
+ * verbatim into a profile's type frame, where there is no node_modules to
707
+ * import Shiki through. The generator is what keeps the copy honest.
708
+ *
709
+ * ── Bundling all of them is nearly free ─────────────────────────────────────
710
+ *
711
+ * Shiki's bundle is a map of dynamic-import thunks and the highlighter is
712
+ * constructed with ONE theme, calling `loadTheme()` for each further one a user
713
+ * actually selects. So the cost of offering every theme is a single import at
714
+ * the moment someone picks it — not the whole set at boot.
715
+ */
716
+ export type BundledSyntax =
717
+ // <bundled-syntax>
718
+ | "andromeeda"
719
+ | "aurora-x"
720
+ | "ayu-dark"
721
+ | "catppuccin-frappe"
722
+ | "catppuccin-latte"
723
+ | "catppuccin-macchiato"
724
+ | "catppuccin-mocha"
725
+ | "dark-plus"
726
+ | "dracula"
727
+ | "dracula-soft"
728
+ | "everforest-dark"
729
+ | "everforest-light"
730
+ | "github-dark"
731
+ | "github-dark-default"
732
+ | "github-dark-dimmed"
733
+ | "github-dark-high-contrast"
734
+ | "github-light"
735
+ | "github-light-default"
736
+ | "github-light-high-contrast"
737
+ | "houston"
738
+ | "kanagawa-dragon"
739
+ | "kanagawa-lotus"
740
+ | "kanagawa-wave"
741
+ | "laserwave"
742
+ | "light-plus"
743
+ | "material-theme"
744
+ | "material-theme-darker"
745
+ | "material-theme-lighter"
746
+ | "material-theme-ocean"
747
+ | "material-theme-palenight"
748
+ | "min-dark"
749
+ | "min-light"
750
+ | "monokai"
751
+ | "night-owl"
752
+ | "nord"
753
+ | "one-dark-pro"
754
+ | "one-light"
755
+ | "plastic"
756
+ | "poimandres"
757
+ | "red"
758
+ | "rose-pine"
759
+ | "rose-pine-dawn"
760
+ | "rose-pine-moon"
761
+ | "slack-dark"
762
+ | "slack-ochin"
763
+ | "snazzy-light"
764
+ | "solarized-dark"
765
+ | "solarized-light"
766
+ | "synthwave-84"
767
+ | "tokyo-night"
768
+ | "vesper"
769
+ | "vitesse-black"
770
+ | "vitesse-dark"
771
+ | "vitesse-light"
772
+ // </bundled-syntax>
773
+ /** Axon's own, and the default. */
774
+ | "arcnight"
775
+
776
+ /**
777
+ * Themes — the terminal's colours, and switching between them.
778
+ *
779
+ * A theme is registered like a palette and applied like a mode. `"` opens the
780
+ * built-in picker, which previews as the cursor moves: hovering a row paints it
781
+ * for real, because a preview that rendered differently from the result would
782
+ * be worth nothing.
783
+ */
784
+ export type ThemeApi = {
785
+ /**
786
+ * Register a theme. Throws if the name is taken. Returns a disposer.
787
+ *
788
+ * Name first, tokens second — the same shape as `palette.create`, so the
789
+ * two read alike rather than one carrying its identity inside the object
790
+ * and the other beside it.
791
+ */
792
+ create: (name: string, tokens: ThemeTokens) => Disposer
793
+
794
+ /** Paint a theme and keep it. Throws on an unknown name. */
795
+ set: (name: string) => void
796
+
797
+ /** Every registered theme, built-ins first. */
798
+ list: () => readonly Theme[]
799
+
800
+ /** The theme currently painted. */
801
+ readonly active: Theme
802
+ }
803
+
804
+ /**
805
+ * Everything that belongs to the terminal rather than to one of the domains
806
+ * above. Kept deliberately thin — a verb with a natural home in `palette`,
807
+ * `commands`, `keys`, `mode`, `input` or `agents` belongs there.
808
+ */
809
+ export type TuiApi = {
810
+ /**
811
+ * Go to an agent: focus the instance the user was last on, booting one if
812
+ * none is live. The `~` key's behaviour.
813
+ *
814
+ * Name-addressed on purpose — "take me to this agent" is a different verb
815
+ * from "focus this exact instance" (`agents.focus`), and both are real.
816
+ */
817
+ nav: (name: string) => Promise<void>
818
+
819
+ /**
820
+ * Register a lifecycle handler. See TuiHooks.
821
+ *
822
+ * Available everywhere — `main.ts`, a `plugins/` file, an extension's
823
+ * `setup()` — because there is no capability difference between them, only
824
+ * a timing one. `plugins/` is where hooks live by convention, not by rule.
825
+ */
826
+ hook: <N extends TuiHookName>(name: N, handler: TuiHooks[N]) => Disposer
827
+
828
+ /**
829
+ * A brief label on the cwd row — the same line the ctrl+c and double-esc
830
+ * hints borrow. Flashes for 300ms by default, then the row returns to the
831
+ * path.
832
+ *
833
+ * tui.info("deployed")
834
+ * tui.warn("nothing to do", 600)
835
+ * tui.error("command failed")
836
+ *
837
+ * ── A reaction, not a message ───────────────────────────────────────────
838
+ *
839
+ * This row's existing tenants are both feedback about the key just pressed,
840
+ * and these are the same thing: something to catch the eye, not something
841
+ * to read. Longer than ~50 characters is trailed with an ellipsis, which is
842
+ * the honest consequence of a one-line surface rather than a limit to work
843
+ * around.
844
+ *
845
+ * So anything with CONTENT — a reason, a path, a stack — does not belong
846
+ * here. Throw instead: it lands in the config error list on the chat page,
847
+ * which is scrollable and stays put.
848
+ *
849
+ * The second argument is milliseconds, clamped to a few seconds. The
850
+ * terminal's own hints outrank all three verbs — one fired during the
851
+ * ctrl+c window waits rather than displacing the exit ladder.
852
+ */
853
+ info: (message: string, ms?: number) => void
854
+
855
+ /** As `info`, in the warning colour. */
856
+ warn: (message: string, ms?: number) => void
857
+
858
+ /** As `info`, in the error colour. For "that failed" — never for why. */
859
+ error: (message: string, ms?: number) => void
860
+
861
+ readonly size: TuiSize
862
+
863
+ /** The directory the TUI was launched from. */
864
+ readonly cwd: string
865
+
866
+ /** Version of the running Axon CLI. */
867
+ readonly version: string
868
+
869
+ /**
870
+ * Quit, running the same exit guards a Ctrl+C does.
871
+ *
872
+ * There is deliberately no `update()`: a self-update hands off to a helper
873
+ * that runs after the process exits, and an extension triggering that is a
874
+ * way for a config to brick an install mid-session.
875
+ */
876
+ exit: () => Promise<void>
877
+ }
878
+
879
+ // ── Hooks ────────────────────────────────────────────────────────────────────
880
+ //
881
+ // ONE verb: `tui.hook(name, handler)`. There is deliberately no `.on()`
882
+ // alongside it.
883
+ //
884
+ // A blocking `hook()` and a fire-and-forget `on()` are indistinguishable at the
885
+ // call site — one letter apart, differing only in a consequence you cannot see
886
+ // — and picking the wrong one buys either a race or a hang. Whether the TUI
887
+ // waits is a property of the EVENT, not of how a handler was registered: `boot`
888
+ // has a meaningful "before" to run in, `mode:changed` announces something that
889
+ // already happened and waiting on it only delays the UI.
890
+ //
891
+ // So the event decides, the types say which is which, and a user who wants
892
+ // fire-and-forget writes it where it is visible:
893
+ //
894
+ // tui.hook("tui:boot", () => { void backgroundSync() })
895
+
896
+ /**
897
+ * Gating hooks — the TUI WAITS for these, and they can fail the operation.
898
+ *
899
+ * Only lifecycle transitions with a real "before" qualify. A slow handler here
900
+ * delays the terminal, so the runtime bounds it: exceeding the budget reports
901
+ * `extension X is blocking <hook>` and continues. It never hangs silently, and
902
+ * a config that stalls boot must always say so — an unexplained frozen terminal
903
+ * is the worst failure this feature can produce.
904
+ */
905
+ export type TuiGateHooks = {
906
+ /** Before the TUI becomes interactive. Registration is done; the screen is not up. */
907
+ "tui:boot": () => void | Promise<void>
908
+ /** Before shutdown proceeds. The last point at which anything can be flushed to disk. */
909
+ "tui:shutdown": () => void | Promise<void>
910
+ }
911
+
912
+ /**
913
+ * Notification hooks — announcements of something that ALREADY happened.
914
+ *
915
+ * Handlers return void: nothing waits, and nothing they do can alter the event.
916
+ * That is enforced by the signature rather than documented, so the question
917
+ * "does the TUI block on this?" is answered by the type instead of by reading
918
+ * the runtime. A handler needing async work owns it (`void doThing()`), which
919
+ * keeps the fire-and-forget visible at the call site.
920
+ */
921
+ export type TuiNotifyHooks = {
922
+ /** The TUI is live and interactive. */
923
+ "tui:ready": () => void
924
+
925
+ /**
926
+ * The config was reloaded — `:reload`, or a file change.
927
+ *
928
+ * Fires on the NEW generation, after every registration is in place. The
929
+ * old generation is already disposed and never sees it: its handlers went
930
+ * with everything else it registered.
931
+ *
932
+ * Distinct from `tui:boot`, which also runs on a reload but gates it. Use
933
+ * boot for setup that must finish first; use this to react to having been
934
+ * reloaded — refreshing a cached palette, re-reading a file on disk.
935
+ */
936
+ "tui:reloaded": () => void
937
+
938
+ /** An instance finished booting. */
939
+ "agent:ready": (instance: AgentInstance) => void
940
+ /** An instance shut down. */
941
+ "agent:stopped": (instance: AgentInstance) => void
942
+ /** A different instance came on screen. */
943
+ "agent:focused": (instance: AgentInstance) => void
944
+
945
+ /** The user sent a message. Fires once it is delivered. */
946
+ "message:sent": (payload: { content: string; instance: AgentInstance }) => void
947
+ /**
948
+ * The agent finished a wake.
949
+ *
950
+ * Carries no content on purpose. A payload with the model's reply would
951
+ * reopen the consumption boundary through the back door — an extension
952
+ * reacting to WHAT was said is writing an agent, which is a cognet's job.
953
+ * This says only THAT a wake completed.
954
+ */
955
+ "message:received": (payload: { instance: AgentInstance }) => void
956
+
957
+ /** The active mode changed. */
958
+ "mode:changed": (payload: { from: ModeName; to: ModeName }) => void
959
+ }
960
+
961
+ /** Every lifecycle hook, gating and notifying. */
962
+ export type TuiHooks = TuiGateHooks & TuiNotifyHooks
963
+
964
+ export type TuiHookName = keyof TuiHooks
965
+
966
+ /**
967
+ * A plugin file under `plugins/`.
968
+ *
969
+ * Plugins need no wrapper and no default export — `tui.hook(...)` at module
970
+ * scope is the whole API, exactly as `main.ts` registers commands at module
971
+ * scope. The file is hooks by convention rather than by ceremony, and there is
972
+ * one way to reach every verb from every file in a profile.
973
+ *
974
+ * What separates a plugin from `setup()` is TIME, not capability: setup runs at
975
+ * load, before anything is on screen, and is where registration belongs —
976
+ * registering a command from a live hook would flicker it into a palette the
977
+ * user is already looking at.
978
+ *
979
+ * A throwing handler disables its extension with a visible error. It never
980
+ * takes the TUI down, and it is never silently swallowed.
981
+ */
982
+ export type PluginModule = void
983
+
984
+ // ── Extensions ───────────────────────────────────────────────────────────────
985
+
986
+ /**
987
+ * An extension's `extension.config.ts`.
988
+ *
989
+ * ── An extension is a profile, packaged ──────────────────────────────────────
990
+ *
991
+ * There is no `setup()`. An extension's behaviour lives in its `main.ts` and
992
+ * its `plugins/`, registered at module scope, exactly as a user's own profile
993
+ * does — same files, same globals, same moment. That symmetry is the point: a
994
+ * user who has written a `main.ts` can publish it, and a reader who knows one
995
+ * layout knows both.
996
+ *
997
+ * A `setup()` wrapper would have made the two differ for no gain. It exists on
998
+ * `defineModule` because a module has data the loader must read WITHOUT
999
+ * executing it — an options schema to validate, `emits` for typegen to merge,
1000
+ * env and policy requirements, sub-modules to flatten at manifest time. An
1001
+ * extension has none of that: its identity is package.json, and its behaviour
1002
+ * is registration.
1003
+ *
1004
+ * ── Then why does this file exist? ───────────────────────────────────────────
1005
+ *
1006
+ * It marks the directory as an extension. A kind is identified by its config
1007
+ * file (see detectKind), and `main.ts` cannot be that marker — a profile has
1008
+ * one, and so does half of npm.
1009
+ *
1010
+ * It is deliberately empty today. Keeping it means declarative, inspectable
1011
+ * per-extension data has somewhere to land later without a breaking change —
1012
+ * options schemas being the obvious candidate, if third-party configuration
1013
+ * ever needs a validated boundary rather than a user editing TypeScript.
1014
+ */
1015
+ export type ExtensionConfig = {
1016
+ /**
1017
+ * Reserved. An extension declares nothing here yet — identity lives in
1018
+ * package.json and behaviour lives in main.ts.
1019
+ */
1020
+ readonly _reserved?: never
1021
+ }
1022
+
1023
+ /** What `defineExtension()` returns. */
1024
+ export type ExtensionDefinition = {
1025
+ _kind: "extension"
1026
+ config: ExtensionConfig
1027
+ }
1028
+
1029
+ // ── Profile ──────────────────────────────────────────────────────────────────
1030
+
1031
+ /**
1032
+ * One entry in `profile.config.ts`'s `extensions`.
1033
+ *
1034
+ * `"@axon/vim"` resolves from the registry and installs into the profile
1035
+ * frame; `"./extensions/sketch"` is a local directory. The object form lets an
1036
+ * extension be disabled without deleting its line — which is what makes this
1037
+ * editable by machine, the reason the enabled set is declared here rather than
1038
+ * being the side-effect of running code.
1039
+ */
1040
+ export type ExtensionEntry =
1041
+ | string
1042
+ | {
1043
+ /** Registry specifier or local path. */
1044
+ source: string
1045
+ /** Default true. False keeps the entry but does not load it. */
1046
+ enabled?: boolean
1047
+ }
1048
+
1049
+ /**
1050
+ * A user's `profile.config.ts` — what is ENABLED, declaratively.
1051
+ *
1052
+ * Declarative rather than imperative registration calls specifically so it can
1053
+ * be edited by machine: installing an extension from Fleet or the CLI is a data
1054
+ * edit to this array, which is not possible when the enabled set is the
1055
+ * side-effect of running arbitrary code.
1056
+ *
1057
+ * Behaviour lives in `main.ts`; this file only says what loads.
1058
+ */
1059
+ export type ProfileConfig = {
1060
+ extensions?: ExtensionEntry[]
1061
+ }
1062
+
1063
+ /** What `defineProfile()` returns. */
1064
+ export type ProfileDefinition = {
1065
+ _kind: "profile"
1066
+ config: ProfileConfig
1067
+ }