@arcforge/types 2.0.125 → 2.0.126

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcforge/types",
3
- "version": "2.0.125",
3
+ "version": "2.0.126",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "main": "./src/index.ts",
package/src/middleware.ts CHANGED
@@ -3,5 +3,20 @@ import type { EventHandler } from "h3"
3
3
  /** Server middleware entry — pre-resolved and pre-ordered by the CLI. */
4
4
  export type AxonMiddleware = {
5
5
  name: string
6
- handler: EventHandler
6
+ /** Absent when the middleware failed to load — see `failed`. */
7
+ handler?: EventHandler
8
+ /**
9
+ * Why this middleware could not be loaded.
10
+ *
11
+ * Set only for a MODULE's middleware, which degrades rather than crashing
12
+ * the agent. It is kept in the chain rather than dropped, and the runtime
13
+ * replaces it with a handler that refuses every request.
14
+ *
15
+ * Dropping it would be the one genuinely dangerous degradation in the
16
+ * system: middleware commonly carries auth and validation, so a skipped
17
+ * one is a request path running without the checks its author wrote — a
18
+ * security hole that looks like a working server. Failing closed is the
19
+ * same posture a reverse proxy takes for a backend it cannot reach.
20
+ */
21
+ failed?: string
7
22
  }
package/src/module.ts CHANGED
@@ -42,6 +42,22 @@ export type AxonModule = {
42
42
  apiPath?: string
43
43
  /** Absolute path to modules/<name>/data/knowledge/, when present. */
44
44
  knowledgePath?: string
45
+ /**
46
+ * Why this module loaded WITHOUT part of what it declares.
47
+ *
48
+ * Set when a scanner could not read something the module ships — tools
49
+ * that will not compile, a prompt that would not introspect. The module is
50
+ * still installed and still in the blueprint; some of its surface is
51
+ * missing.
52
+ *
53
+ * Present on the module rather than only in a warnings list because the
54
+ * MODEL has to be told. A tool that failed to declare is absent from
55
+ * <scope> by construction, which is correct but silent: without this the
56
+ * agent has no way to know it lost a capability, and confidently offers
57
+ * one it cannot call. Rendered into context so it can say "I cannot search
58
+ * arXiv right now" instead.
59
+ */
60
+ degraded?: string
45
61
  prompts: AxonPrompt[]
46
62
  scripts: AxonScript[]
47
63
  tools: AxonTool[]
package/src/scope.ts CHANGED
@@ -26,4 +26,17 @@ export type AxonScopeModule = {
26
26
  /** The complete TypeScript scope implemented by one live capsule. */
27
27
  export type AxonScope = {
28
28
  modules: readonly AxonScopeModule[]
29
+ /**
30
+ * Capabilities the agent declares but does NOT have this session.
31
+ *
32
+ * A module whose tools failed to compile contributes nothing to `modules`
33
+ * — correct, because the model must never be told about a tool the capsule
34
+ * cannot load. But that absence is silent: the agent has no way to know it
35
+ * lost something, so it answers as though the capability never existed, or
36
+ * worse, claims it does.
37
+ *
38
+ * Rendered alongside the scope so the model can say "I cannot search arXiv
39
+ * right now" rather than guessing. Empty in the normal case.
40
+ */
41
+ unavailable?: readonly { name: string; reason: string }[]
29
42
  }
@@ -129,7 +129,18 @@ export type BuildEventMap =
129
129
  * inside the runtime, which meant they arrived AFTER boot and only
130
130
  * for builds that got that far.
131
131
  */
132
- "build:warning": { domain: string; message: string; stage?: BuildStage }
132
+ /**
133
+ * Something the user wrote could not be read, and the build continued
134
+ * without it — a module whose tools will not compile, a prompt that
135
+ * would not introspect.
136
+ *
137
+ * `error` carries the full AxonError when the scanner had one. The
138
+ * flattened `message` remains the contract every consumer can rely on;
139
+ * a renderer that understands the structured form gets the code,
140
+ * location and source snippet, and one that does not still has a
141
+ * sentence to print.
142
+ */
143
+ "build:warning": { domain: string; message: string; stage?: BuildStage; error?: AxonError }
133
144
  }
134
145
 
135
146
  export type BuildEventName = keyof BuildEventMap
@@ -22,6 +22,21 @@ import type { AxonSpan } from "./span"
22
22
  * own code is running inside — not any one lifecycle prefix above — so it
23
23
  * gets its own namespace rather than folding into axon:log:*.
24
24
  */
25
+ /**
26
+ * What an install put somewhere — a module into THIS agent, or an extension
27
+ * into the user's terminal.
28
+ *
29
+ * On the event rather than in a second event family, because the two are the
30
+ * same operation with different destinations: same span, same failure modes,
31
+ * same "installed X in 558ms" line. A parallel `axon:ext:install` triad would
32
+ * be four more event types and a second renderer that must agree with the
33
+ * first about what an install looks like.
34
+ *
35
+ * Absent means module — every event written before extensions could be
36
+ * installed is one, and defaulting keeps those readable.
37
+ */
38
+ export type ArtifactInstalled = "module" | "extension"
39
+
25
40
  export type AxonRuntimeEvent =
26
41
  & AxonLogEvents<"axon">
27
42
  // ── Runtime lifecycle ────────────────────────────────────────────────────
@@ -38,9 +53,9 @@ export type AxonRuntimeEvent =
38
53
  // hot-swap path above) ─────────────────────────────────────────────
39
54
  & AxonSpan<
40
55
  "axon:install",
41
- { name: string; version?: string },
42
- { name: string; version: string; alreadyInstalled: boolean },
43
- { name: string; version?: string; error: AxonError }
56
+ { name: string; version?: string; artifact?: ArtifactInstalled },
57
+ { name: string; version: string; alreadyInstalled: boolean; artifact?: ArtifactInstalled },
58
+ { name: string; version?: string; error: AxonError; artifact?: ArtifactInstalled }
44
59
  >
45
60
  & {
46
61
  /**
@@ -5,4 +5,4 @@
5
5
  // A profile has no node_modules, so its globals cannot import — they must be
6
6
  // this text, inlined.
7
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 /** What the timeline shows. Every field optional; defaults applied at read. */\n type VerbosityProfile = {\n /** Session lifecycle events — quiet: errors only; normal (default): + info (reloads); verbose: + plumbing. */\n session?: \"quiet\" | \"normal\" | \"verbose\"\n /** Interleave kernel:* telemetry (runs, engine calls) into the timeline. Default false. */\n kernel?: boolean\n /** Interleave cognet:* telemetry (ticks, phases, systems). Default false. */\n cognet?: boolean\n }\n\n /**\n * The platform's own settings — a CLOSED, typed set.\n *\n * Closed on purpose. These are the keys the terminal itself acts on, so each\n * one has a meaning the platform enforces: `theme` names a registered theme,\n * `paths` are scanned for agents. An open bag would make \"is this setting\n * doing anything?\" unanswerable, which is the question a settings file exists\n * to answer.\n *\n * Extension settings live OUTSIDE this, as their own top-level key on the\n * profile config (`\"@cody/vim\": { leader: \",\" }`). Two reasons: an extension's\n * settings are its own contract rather than the platform's, and keeping them\n * out means adding a platform key can never collide with one an extension\n * already chose.\n */\n type ProfileSettings = {\n /** The active theme, by the name it was registered under. */\n theme?: string\n /**\n * Extra directories scanned for agent projects, beyond\n * `profiles/<email>/agents/`. `~` expands to the home directory.\n */\n paths?: string[]\n /** What the timeline shows. */\n verbosity?: VerbosityProfile\n /** Not wired to anything yet — kept for when it is. */\n telemetry?: boolean\n }\n\n /**\n * `profile.config.ts` — the one declarative source of truth for a terminal.\n *\n * Which extensions load, how the platform is configured, and whatever those\n * extensions were configured with. Written by hand AND edited surgically by\n * the terminal (`:theme set`, `axon ext install`) — so what you see in this\n * file is always what is in effect, with no second store that can disagree.\n *\n * Extension settings are top-level keys named after the extension, siblings of\n * `settings` rather than nested inside it:\n *\n * export default defineProfile({\n * extensions: [\"@cody/vim\"],\n * settings: { theme: \"ember\" },\n * \"@cody/vim\": { leader: \",\" },\n * })\n */\n type ProfileConfig = {\n extensions?: ExtensionEntry[]\n /** Platform settings — see ProfileSettings. */\n settings?: ProfileSettings\n /**\n * Extension settings, keyed by the extension's own scoped name.\n *\n * Typed as unknown because the platform has no business knowing an\n * extension's shape — the extension reads and validates its own block.\n */\n [extension: `@${string}/${string}`]: unknown\n }\n\n /** What `defineProfile()` returns. */\n type ProfileDefinition = {\n _kind: \"profile\"\n config: ProfileConfig\n }"
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 /** What the timeline shows. Every field optional; defaults applied at read. */\n type VerbosityProfile = {\n /** Session lifecycle events — quiet: errors only; normal (default): + info (reloads); verbose: + plumbing. */\n session?: \"quiet\" | \"normal\" | \"verbose\"\n /** Interleave kernel:* telemetry (runs, engine calls) into the timeline. Default false. */\n kernel?: boolean\n /** Interleave cognet:* telemetry (ticks, phases, systems). Default false. */\n cognet?: boolean\n }\n\n /**\n * The platform's own settings — a CLOSED, typed set.\n *\n * Closed on purpose. These are the keys the terminal itself acts on, so each\n * one has a meaning the platform enforces: `theme` names a registered theme,\n * `paths` are scanned for agents. An open bag would make \"is this setting\n * doing anything?\" unanswerable, which is the question a settings file exists\n * to answer.\n *\n * Extension settings live OUTSIDE this, as their own top-level key on the\n * profile config (`\"@cody/vim\": { leader: \",\" }`). Two reasons: an extension's\n * settings are its own contract rather than the platform's, and keeping them\n * out means adding a platform key can never collide with one an extension\n * already chose.\n */\n type ProfileSettings = {\n /** The active theme, by the name it was registered under. */\n theme?: string\n /**\n * Extra directories scanned for agent projects, beyond\n * `profiles/<email>/agents/`. `~` expands to the home directory.\n */\n paths?: string[]\n /** What the timeline shows. */\n verbosity?: VerbosityProfile\n /**\n * Blank space around the whole terminal UI, in cells.\n *\n * Shorthand for both axes: `padding-inline`/`padding-block` override it per\n * axis when present, so `{ padding: 1, \"padding-inline\": 4 }` reads as \"one\n * row top and bottom, four columns each side\".\n *\n * ── CSS names, spelled exactly ──────────────────────────────────────────\n *\n * This config layer speaks CSS — VTerm mimics browser CSS, and users write\n * scoped CSS in their own extensions. Where CSS already has a name for a\n * thing, these settings use it verbatim rather than a near-synonym, so\n * there is nothing to translate between what you write here and what you\n * write in a stylesheet. (VTerm implements only the physical longhands\n * internally, so these are expanded to `padding-top`/`-left`/... at the\n * layout that consumes them — an implementation detail of the renderer,\n * not a reason to rename the setting.)\n */\n padding?: number\n /** Columns of blank space at the left and right edges. Overrides `padding` horizontally. */\n \"padding-inline\"?: number\n /**\n * Rows of blank space added at the top and bottom edges. Overrides\n * `padding` vertically.\n *\n * ADDED to the layout's own one-row top offset rather than replacing it, so\n * 0 (the default) is the shipped look. The status line is the bottom edge\n * and sits flush by design; this is what lifts it off.\n */\n \"padding-block\"?: number\n /** Not wired to anything yet — kept for when it is. */\n telemetry?: boolean\n }\n\n /**\n * `profile.config.ts` — the one declarative source of truth for a terminal.\n *\n * Which extensions load, how the platform is configured, and whatever those\n * extensions were configured with. Written by hand AND edited surgically by\n * the terminal (`:theme set`, `axon ext install`) — so what you see in this\n * file is always what is in effect, with no second store that can disagree.\n *\n * Extension settings are top-level keys named after the extension, siblings of\n * `settings` rather than nested inside it:\n *\n * export default defineProfile({\n * extensions: [\"@cody/vim\"],\n * settings: { theme: \"ember\" },\n * \"@cody/vim\": { leader: \",\" },\n * })\n */\n type ProfileConfig = {\n extensions?: ExtensionEntry[]\n /** Platform settings — see ProfileSettings. */\n settings?: ProfileSettings\n /**\n * Extension settings, keyed by the extension's own scoped name.\n *\n * Typed as unknown because the platform has no business knowing an\n * extension's shape — the extension reads and validates its own block.\n */\n [extension: `@${string}/${string}`]: unknown\n }\n\n /** What `defineProfile()` returns. */\n type ProfileDefinition = {\n _kind: \"profile\"\n config: ProfileConfig\n }"
package/src/tui.ts CHANGED
@@ -1091,6 +1091,36 @@ export type ProfileSettings = {
1091
1091
  paths?: string[]
1092
1092
  /** What the timeline shows. */
1093
1093
  verbosity?: VerbosityProfile
1094
+ /**
1095
+ * Blank space around the whole terminal UI, in cells.
1096
+ *
1097
+ * Shorthand for both axes: `padding-inline`/`padding-block` override it per
1098
+ * axis when present, so `{ padding: 1, "padding-inline": 4 }` reads as "one
1099
+ * row top and bottom, four columns each side".
1100
+ *
1101
+ * ── CSS names, spelled exactly ──────────────────────────────────────────
1102
+ *
1103
+ * This config layer speaks CSS — VTerm mimics browser CSS, and users write
1104
+ * scoped CSS in their own extensions. Where CSS already has a name for a
1105
+ * thing, these settings use it verbatim rather than a near-synonym, so
1106
+ * there is nothing to translate between what you write here and what you
1107
+ * write in a stylesheet. (VTerm implements only the physical longhands
1108
+ * internally, so these are expanded to `padding-top`/`-left`/... at the
1109
+ * layout that consumes them — an implementation detail of the renderer,
1110
+ * not a reason to rename the setting.)
1111
+ */
1112
+ padding?: number
1113
+ /** Columns of blank space at the left and right edges. Overrides `padding` horizontally. */
1114
+ "padding-inline"?: number
1115
+ /**
1116
+ * Rows of blank space added at the top and bottom edges. Overrides
1117
+ * `padding` vertically.
1118
+ *
1119
+ * ADDED to the layout's own one-row top offset rather than replacing it, so
1120
+ * 0 (the default) is the shipped look. The status line is the bottom edge
1121
+ * and sits flush by design; this is what lifts it off.
1122
+ */
1123
+ "padding-block"?: number
1094
1124
  /** Not wired to anything yet — kept for when it is. */
1095
1125
  telemetry?: boolean
1096
1126
  }