@arcforge/types 2.0.140 → 2.0.142

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.140",
3
+ "version": "2.0.142",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "main": "./src/index.ts",
package/src/blueprint.ts CHANGED
@@ -7,6 +7,7 @@ import { AxonModule } from "./module"
7
7
  import { AxonTool } from "./tools"
8
8
  import { AxonScript } from "./scripts"
9
9
  import { AxonPrompt } from "./prompts"
10
+ import { AxonKnowledge } from "./knowledge"
10
11
 
11
12
  /**
12
13
  * The blueprint is the boundary between CLI and runtime.
@@ -71,6 +72,15 @@ export type AxonBlueprint = {
71
72
  tools: AxonTool[]
72
73
  prompts: AxonPrompt[]
73
74
  scripts: AxonScript[]
75
+ /**
76
+ * Every knowledge file this agent can reach — its own `data/knowledge/`
77
+ * plus each installed module's, namespaced by module.
78
+ *
79
+ * Discovered at build time and carried as paths, so a module's corpus is
80
+ * never copied into the agent. The kernel enumerates these rather than
81
+ * walking one directory, which is what makes knowledge shareable.
82
+ */
83
+ knowledge: AxonKnowledge[]
74
84
 
75
85
  server: AxonServerBlueprint
76
86
 
@@ -105,6 +115,7 @@ export type AxonPartialBlueprint = {
105
115
  tools?: AxonBlueprint["tools"]
106
116
  prompts?: AxonBlueprint["prompts"]
107
117
  scripts?: AxonBlueprint["scripts"]
118
+ knowledge?: AxonBlueprint["knowledge"]
108
119
  server?: Partial<AxonServerBlueprint>
109
120
  modules?: AxonBlueprint["modules"]
110
121
  paths?: Partial<AxonBlueprint["paths"]>
package/src/index.ts CHANGED
@@ -15,6 +15,7 @@ export * from "./plugin"
15
15
  export * from "./policy"
16
16
  export * from "./capsule-config"
17
17
  export * from "./capsule-scope"
18
+ export * from "./knowledge"
18
19
  export * from "./prompts"
19
20
  export * from "./route"
20
21
  export * from "./scripts"
package/src/kernel/abi.ts CHANGED
@@ -92,6 +92,123 @@ export type KernelStore = {
92
92
  set<K extends keyof CognetStoreSchema>(key: K, value: CognetStoreSchema[K]): Promise<void>
93
93
  }
94
94
 
95
+ /**
96
+ * One catalogued item in the knowledge store.
97
+ *
98
+ * A NAME, never a path. The cognet addresses knowledge by a stable
99
+ * identifier the author chose; where that lands on this machine is the
100
+ * kernel's business and must stay invisible — the same rule `models`
101
+ * states, for the same reason (a path is environmental, and a brain that
102
+ * learned one stops being portable to a body that stores things
103
+ * differently).
104
+ *
105
+ * `description` is author-supplied metadata, empty string when none —
106
+ * never undefined, so a renderer never branches. It exists because the
107
+ * catalogue's whole job is being cheap enough to hold ambiently: an LLM
108
+ * brain renders name + description for everything it has and reads only
109
+ * what the task needs. A brain that already knows its names ignores all
110
+ * of it and calls read() directly, the way a controller ignores stream().
111
+ */
112
+ export type KnowledgeEntry = {
113
+ /** Stable identifier. Namespaced for module material, so two corpora cannot collide. */
114
+ name: string
115
+ /** Author-supplied summary. Empty when the entry declares none — never undefined. */
116
+ description: string
117
+ /** Bytes on disk — lets a cognet decide whether to read before it does. */
118
+ size: number
119
+ /**
120
+ * Absolute path to the file.
121
+ *
122
+ * Present because knowledge is no longer one directory: a module's corpus
123
+ * lives inside its own package, so a name cannot be joined to a root the
124
+ * way `AXON_HOME/data/knowledge/<name>` once could. A cognet that wants
125
+ * the model to open a file with ordinary fs tools has to render something
126
+ * openable, and the alternative — teaching the model two path rules and
127
+ * which entries follow which — is worse than handing it the answer.
128
+ *
129
+ * This is the same call `models` already makes: the kernel resolves, the
130
+ * brain receives. What a cognet must not do is DERIVE a path from a
131
+ * layout it assumed; reading one it was given is ordinary.
132
+ */
133
+ path: string
134
+ }
135
+
136
+ /**
137
+ * The knowledge store — durable, human-readable, human-editable material
138
+ * the brain consults and maintains. The long-term counterpart to
139
+ * `store`'s private kv.
140
+ *
141
+ * Three things distinguish it from every other durable surface:
142
+ *
143
+ * - It is INPUT, not output. A session log records what the agent did; a
144
+ * knowledge entry is what someone (a human, a module, or the brain
145
+ * itself) decided is worth keeping. That is why it lives outside
146
+ * .agent/ and is published with the agent.
147
+ * - It is NOT a cache. Unlike `store`, losing it is real data loss, so
148
+ * writes are atomic and a missing entry throws rather than returning
149
+ * null. If a brain was told an entry exists and it does not, something
150
+ * is wrong and silence would hide it.
151
+ * - It is FORMAT-AGNOSTIC by refusal. The kernel hands over bytes and a
152
+ * name; what those bytes mean is the cognet's business, exactly as the
153
+ * weights behind `models` are. Markdown, JSON, CSV, a serialized graph —
154
+ * the store has no opinion and will never grow one.
155
+ *
156
+ * RETRIEVAL IS COGNITION AND LIVES IN THE COGNET. There is no semantic
157
+ * search, no ranking, no embedding here and there must never be: choosing
158
+ * how a mind recalls is a memory policy, which the kernel is forbidden
159
+ * from holding (see the design rules on KernelAbi). `list`'s `match` is a
160
+ * substring filter over catalogue metadata the caller supplies — the
161
+ * kernel executes a predicate it is given, it never supplies one. A brain
162
+ * that wants full-text search greps through run(); a brain that wants
163
+ * embeddings builds them and keeps the index in `store`, where derived
164
+ * state belongs.
165
+ *
166
+ * Writes are confined to the store root and enforced, not trusted — a
167
+ * name that resolves outside it throws. The cognet gains one more mediated
168
+ * door, never a filesystem.
169
+ */
170
+ export type KernelKnowledge = {
171
+ /**
172
+ * The catalogue — every entry, name and description only, never content.
173
+ *
174
+ * Ordered by `name`, bytewise ascending. STATED rather than left to the
175
+ * filesystem because an unspecified order is a ranking nobody declared
176
+ * and every cognet silently inherits; a caller that wants a different
177
+ * one sorts the result it was given.
178
+ *
179
+ * `match` is a case-insensitive substring test against name and
180
+ * description. `limit` truncates AFTER ordering, so a capped render is
181
+ * a stable prefix rather than an arbitrary sample.
182
+ */
183
+ list(opts?: { match?: string; limit?: number }): Promise<readonly KnowledgeEntry[]>
184
+
185
+ /**
186
+ * Read one entry's content, as UTF-8 text.
187
+ *
188
+ * Throws KNOWLEDGE_NOT_FOUND when absent. Deliberately not null-on-
189
+ * missing: this is not a cache, and a brain reading something the
190
+ * catalogue advertised has hit a real inconsistency that must be loud.
191
+ */
192
+ read(name: string): Promise<string>
193
+
194
+ /**
195
+ * Write one entry, creating or replacing it. Atomic (temp + rename) —
196
+ * a kill mid-write leaves the previous content, never a torn file,
197
+ * because unlike `store` this cannot be silently rebuilt.
198
+ *
199
+ * Parent directories are created as needed, so a brain organising its
200
+ * own memory into folders needs no separate verb for it.
201
+ */
202
+ write(name: string, content: string): Promise<void>
203
+
204
+ /**
205
+ * Delete one entry. A no-op when already absent — removal is
206
+ * idempotent, and a brain pruning its own memory should not have to
207
+ * check first.
208
+ */
209
+ remove(name: string): Promise<void>
210
+ }
211
+
95
212
  /**
96
213
  * The outcome of one capsule run — success and failure are both ordinary
97
214
  * values here, never a rejection. `stdout` is every console.* call this
@@ -263,6 +380,17 @@ export type KernelAbi = {
263
380
  */
264
381
  store: KernelStore
265
382
 
383
+ /**
384
+ * Long-term knowledge — durable, human-readable material the brain
385
+ * consults and maintains. See KernelKnowledge for the doctrine.
386
+ *
387
+ * Mediated for the same reason `store` is: the cognet declares a name,
388
+ * the kernel owns the path. It is a peer of store, not a replacement —
389
+ * store is a private cache over the log, knowledge is shared input that
390
+ * outlives every session and is published with the agent.
391
+ */
392
+ knowledge: KernelKnowledge
393
+
266
394
  /**
267
395
  * Wake the brain — the mind's own rhythm, driven from inside it.
268
396
  *
@@ -1,3 +1,3 @@
1
1
  export { KERNEL_ABI_VERSION } from "./abi"
2
- export type { KernelAbi, CognetWake, CognetEngineCall, AxonRunResult, KernelStore, KernelClock } from "./abi"
2
+ export type { KernelAbi, CognetWake, CognetEngineCall, AxonRunResult, KernelStore, KernelClock, KernelKnowledge, KnowledgeEntry } from "./abi"
3
3
 
@@ -0,0 +1,36 @@
1
+ /**
2
+ * One catalogued knowledge file, as the BUILD sees it.
3
+ *
4
+ * Distinct from the kernel's `KnowledgeEntry` (the shape a cognet reads)
5
+ * exactly as `AxonPrompt` is distinct from a rendered prompt: this carries
6
+ * where the file physically is and who contributed it, and the kernel's
7
+ * carries only what a brain may know. The absolute path lives here and
8
+ * stops here.
9
+ *
10
+ * Discovered at build time so a module's corpus never has to be COPIED into
11
+ * the agent installing it. Copying would fork the material on the first
12
+ * update and duplicate megabytes into every agent; a blueprint entry keeps
13
+ * one copy in the module and lets `axon update` refresh it.
14
+ */
15
+ export type AxonKnowledge = {
16
+ /**
17
+ * The name a cognet addresses this by — already namespaced for module
18
+ * material, so an agent's own `axon/agent.md` and a module's can coexist.
19
+ */
20
+ name: string
21
+ /** Frontmatter `description`, falling back to `title`. Empty when neither. */
22
+ description: string
23
+ /** Bytes on disk, read during the scan that found the file. */
24
+ size: number
25
+ /** Absolute path. Build- and kernel-side only; never rendered to a model. */
26
+ path: string
27
+ /**
28
+ * Who contributed it. The one field that decides writability: an agent's
29
+ * own store is writable, a module's is not — its files live under
30
+ * node_modules and would be destroyed by the next install, silently
31
+ * losing whatever the agent wrote there.
32
+ */
33
+ origin: "agent" | "module"
34
+ /** The contributing module's name. Absent for the agent's own material. */
35
+ module?: string
36
+ }
@@ -66,6 +66,22 @@ export type CognetEventMap =
66
66
  { tick: number; phase: string | null; system: string }
67
67
  >
68
68
  & {
69
+ // ── Knowledge mutations ──────────────────────────────────────────────────
70
+ //
71
+ // Emitted by the KERNEL when a cognet writes or removes long-term
72
+ // knowledge — the cognet never records its own mutations, the same rule
73
+ // that governs run()'s action/result pair.
74
+ //
75
+ // Not a span: a write is a settled act, not a bracket. There is no
76
+ // meaningful "in progress" for an atomic temp+rename, so :start/:complete
77
+ // would be two lines describing one instant.
78
+ //
79
+ // Traced because "the agent modified its own long-term memory" is exactly
80
+ // the fact you want when behaviour drifts weeks later. Name only, never
81
+ // content — the log records that memory changed, not a second copy of it.
82
+ "cognet:knowledge:write": { name: string }
83
+ "cognet:knowledge:remove": { name: string }
84
+
69
85
  // ── World writes ─────────────────────────────────────────────────────────
70
86
  "cognet:entity:add": { tick: number; phase: string | null; entity: string }
71
87
  "cognet:entity:remove": { tick: number; phase: string | null; entity: string }
@@ -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 /**\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 }"
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 /**\n * What a command IS — its behaviour and how it presents.\n *\n * ── Why a definition object rather than trailing options ────────────────────\n *\n * The alternative was `register(path, action, options?)`, and it loses for the\n * same reason positional hook arguments do. A third parameter is a fixed slot:\n * the day a command needs a fourth thing, it is either a fourth positional\n * nobody discovers or a breaking change. And `register(\"x\", fn, {...})` reads\n * as a function with some settings bolted on, when the truth is that the\n * behaviour and the presentation are one declaration.\n *\n * It also matches `palette.create(name, definition)`, which already takes its\n * work verb (`list`) inside the object. Two registration APIs shaped\n * differently is a thing to remember for no reason.\n *\n * The verb is `run` because that is what a command does. `action` was the\n * internal name and it describes a slot in a data structure, not the thing a\n * user is writing.\n */\n type CommandDefinition = {\n /**\n * The command's behaviour.\n *\n * A returned promise holds the palette in its working state until it\n * settles. The signal aborts when the user escapes mid-flight — a command\n * that cannot be cancelled may ignore it.\n */\n run: (signal: AbortSignal) => void | Promise<void>\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 * Two forms, and the short one is not a legacy shape to be migrated off:\n *\n * commands.register(\"deploy\", async () => { ... })\n * commands.register(\"deploy\", {\n * async run() { ... },\n * description: \"Restart and redeploy\",\n * })\n *\n * A command with nothing to configure is genuinely just its behaviour, and\n * making that case carry `{ run }` would be ceremony charged to the most\n * common thing anyone writes. The moment there IS configuration, the object\n * form keeps it in one declaration instead of trailing off the end.\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: {\n (path: CommandPath, run: (signal: AbortSignal) => void | Promise<void>): Disposer\n (path: CommandPath, definition: CommandDefinition): Disposer\n }\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\": (payload: TuiBootPayload) => void | Promise<void>\n /** Before shutdown proceeds. The last point at which anything can be flushed to disk. */\n \"tui:shutdown\": (payload: TuiShutdownPayload) => void | Promise<void>\n }\n\n // ── Hook payloads ────────────────────────────────────────────────────────────\n //\n // EVERY hook takes exactly one object, always — including the ones that have\n // nothing to say. `tui.hook(name, ({ x }) => ...)` is the shape throughout, so\n // a handler is written the same way whichever event it listens to, and reading\n // one tells you nothing about which.\n //\n // Positional arguments were the alternative and they lose on every axis that\n // matters here. They fix an order, so adding a field is a choice between a\n // trailing bag nobody discovers and a breaking change; they cannot be\n // destructured by name, so `(a, b)` at a call site says nothing about what a\n // and b are; and they make the empty case a THIRD spelling (`() => {}` beside\n // `(x) => {}` beside `(x, y) => {}`) for no gain. An empty object costs a\n // handler nothing — `() => {}` still type-checks, because a function may always\n // ignore parameters it was handed.\n //\n // So the rule is mechanical and has no exceptions: one payload object per hook,\n // named fields, and a payload type declared here even when it is empty. An\n // empty payload is where a field will go, and having the type already named is\n // what makes adding one a non-event.\n\n /**\n * `tui:boot` — nothing yet.\n *\n * Empty rather than absent: the parameter exists so a later field arrives\n * without changing any handler's shape, and so boot is written exactly like\n * every other hook.\n */\n type TuiBootPayload = {}\n\n /** `tui:shutdown` — nothing yet. Empty for the same reason as boot. */\n type TuiShutdownPayload = {}\n\n /** `tui:reloaded` — nothing yet. Empty for the same reason as boot. */\n type TuiReloadedPayload = {}\n\n /** `tui:resize` — the terminal's new dimensions, in cells. */\n type TuiResizePayload = {\n /** Columns. */\n width: number\n /** Rows. */\n height: number\n }\n\n /**\n * `key:pressed` — one keystroke the TUI did not act on.\n *\n * `mode` rides along because \"was a palette open when this fired\" is the first\n * question a handler asks, and reading it back through `mode.get()` would race\n * the very transition that may have been caused by this key.\n */\n type KeyPressedPayload = {\n /**\n * The chord, in the spelling `keys.register()` accepts — `\"a\"`, `\"ctrl+o\"`,\n * `\"shift+tab\"`. Round-trips deliberately: a handler that decides to claim\n * a key can pass this string straight to `keys.register`.\n */\n key: string\n /** The mode that was active when the key arrived. */\n mode: ModeName\n }\n\n /** `palette:opened` / `palette:closed` — which palette. */\n type PalettePayload = {\n /** The palette's mode name — `\"command\"`, `\"agent\"`, or a user palette's. */\n name: ModeName\n }\n\n /** What one instance hook reports. */\n type AgentPayload = {\n instance: AgentInstance\n }\n\n /** `message:sent` — the text, and where it went. */\n type MessageSentPayload = {\n content: string\n instance: AgentInstance\n }\n\n /** `message:received` — see the hook for why there is no content. */\n type MessageReceivedPayload = {\n instance: AgentInstance\n }\n\n /** `mode:changed` — the transition, both ends. */\n type ModeChangedPayload = {\n from: ModeName\n to: ModeName\n }\n\n /** `command:ran` / `command:failed` — which command, and how it was reached. */\n type CommandPayload = {\n /** The full path, space-joined — `\"ext update\"`, `\"theme set\"`. */\n path: string\n /**\n * How it was invoked: chosen in the command palette, or run by\n * `commands.run()`.\n *\n * Present so a handler can tell the user's action from its own — an\n * extension that reacts to every command by running another would otherwise\n * have no way to avoid recursing into itself.\n *\n * There is deliberately no `\"key\"`. A key bound to a command calls\n * `commands.run()` from its handler, so it IS an api call and reporting it\n * as its own source would be inventing a distinction the runtime cannot\n * actually make — a handler that checked for it would never match.\n */\n source: \"palette\" | \"api\"\n }\n\n /** `command:failed` — the above, plus what went wrong. */\n type CommandFailedPayload = CommandPayload & {\n /** The thrown value, exactly as it was thrown. */\n error: unknown\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 * There is deliberately no `tui:ready`. It existed, was typed, was documented,\n * and never fired — and the moment it is wired it is indistinguishable from\n * `tui:boot`, which already runs once registration is complete and gates the\n * terminal becoming interactive. Two hooks separated only by whether the screen\n * has painted is a distinction nothing in this API can act on.\n */\n type TuiNotifyHooks = {\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\": (payload: TuiReloadedPayload) => void\n\n /**\n * The terminal was resized.\n *\n * Fires after the new size is in effect, so `tui.size` and this payload\n * always agree. Coalesced by the underlying watcher: a drag produces the\n * sizes the terminal actually reported, not one event per column.\n */\n \"tui:resize\": (payload: TuiResizePayload) => void\n\n /**\n * A key the TUI did not handle.\n *\n * ── Unhandled only, and never consumable ────────────────────────────────\n *\n * This fires at the END of dispatch — after reserved chords, after\n * `keys.register()` bindings, after mode keys. A key that did something\n * does not arrive here.\n *\n * That is not a limitation to route around; it is the only shape that can\n * be safe. User key handling is mounted as a WILDCARD, and wildcards fire\n * before exact-key handlers — so a hook able to consume a press would beat\n * every built-in binding, including the ctrl+c exit ladder. The reserved\n * list refuses those chords at registration precisely because a check at\n * press time is already too late.\n *\n * So there is no return value and no consumption: this observes, exactly\n * like every other notify hook. To OWN a key, register it —\n * `keys.register(\"ctrl+o\", ...)` — which is checked against the reserved\n * set and cannot break the terminal.\n */\n \"key:pressed\": (payload: KeyPressedPayload) => void\n\n /**\n * A palette opened.\n *\n * Narrower than `mode:changed`, and deliberately its own event: not every\n * mode is a palette. `loading` is a spinner and `voice` is a capture state,\n * and an extension gating on \"is the user picking something\" has to exclude\n * them — a derivation every consumer would otherwise write, and get wrong\n * the same way.\n */\n \"palette:opened\": (payload: PalettePayload) => void\n\n /** A palette closed. Fires for whichever palette was open. */\n \"palette:closed\": (payload: PalettePayload) => void\n\n /**\n * A command finished successfully.\n *\n * Covers built-ins and user commands alike, however they were reached —\n * `source` says which. Fires AFTER the action resolves, so an async command\n * reports when it is genuinely done rather than when it started.\n */\n \"command:ran\": (payload: CommandPayload) => void\n\n /**\n * A command threw.\n *\n * Its own event rather than a field on `command:ran`, so a handler that\n * only cares about failures does not have to filter — and so the success\n * payload never carries an error slot that is null almost always.\n */\n \"command:failed\": (payload: CommandFailedPayload) => void\n\n /** An instance finished booting. */\n \"agent:ready\": (payload: AgentPayload) => void\n /** An instance shut down. */\n \"agent:stopped\": (payload: AgentPayload) => void\n /** A different instance came on screen. */\n \"agent:focused\": (payload: AgentPayload) => void\n\n /** The user sent a message. Fires once it is delivered. */\n \"message:sent\": (payload: MessageSentPayload) => 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: MessageReceivedPayload) => void\n\n /**\n * The active mode changed.\n *\n * The general event; `palette:opened`/`closed` are the specific ones. Use\n * this to observe every transition (including `loading` and `voice`), those\n * to react to the user opening something to pick from.\n */\n \"mode:changed\": (payload: ModeChangedPayload) => 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
@@ -242,7 +242,35 @@ export type PaletteApi = {
242
242
  */
243
243
  export type CommandPath = string | readonly string[]
244
244
 
245
- export type CommandOptions = {
245
+ /**
246
+ * What a command IS — its behaviour and how it presents.
247
+ *
248
+ * ── Why a definition object rather than trailing options ────────────────────
249
+ *
250
+ * The alternative was `register(path, action, options?)`, and it loses for the
251
+ * same reason positional hook arguments do. A third parameter is a fixed slot:
252
+ * the day a command needs a fourth thing, it is either a fourth positional
253
+ * nobody discovers or a breaking change. And `register("x", fn, {...})` reads
254
+ * as a function with some settings bolted on, when the truth is that the
255
+ * behaviour and the presentation are one declaration.
256
+ *
257
+ * It also matches `palette.create(name, definition)`, which already takes its
258
+ * work verb (`list`) inside the object. Two registration APIs shaped
259
+ * differently is a thing to remember for no reason.
260
+ *
261
+ * The verb is `run` because that is what a command does. `action` was the
262
+ * internal name and it describes a slot in a data structure, not the thing a
263
+ * user is writing.
264
+ */
265
+ export type CommandDefinition = {
266
+ /**
267
+ * The command's behaviour.
268
+ *
269
+ * A returned promise holds the palette in its working state until it
270
+ * settles. The signal aborts when the user escapes mid-flight — a command
271
+ * that cannot be cancelled may ignore it.
272
+ */
273
+ run: (signal: AbortSignal) => void | Promise<void>
246
274
  /** Shown beside the command in the palette. */
247
275
  description?: string
248
276
  /** Shown in the working row while an async command runs. */
@@ -253,10 +281,26 @@ export type CommandsApi = {
253
281
  /**
254
282
  * Add a command to the `:` tree.
255
283
  *
284
+ * Two forms, and the short one is not a legacy shape to be migrated off:
285
+ *
286
+ * commands.register("deploy", async () => { ... })
287
+ * commands.register("deploy", {
288
+ * async run() { ... },
289
+ * description: "Restart and redeploy",
290
+ * })
291
+ *
292
+ * A command with nothing to configure is genuinely just its behaviour, and
293
+ * making that case carry `{ run }` would be ceremony charged to the most
294
+ * common thing anyone writes. The moment there IS configuration, the object
295
+ * form keeps it in one declaration instead of trailing off the end.
296
+ *
256
297
  * Built-in commands always win a collision, and two extensions colliding is
257
298
  * first-registered-wins with a warning naming both — never silent shadowing.
258
299
  */
259
- register: (path: CommandPath, action: (signal: AbortSignal) => void | Promise<void>, options?: CommandOptions) => Disposer
300
+ register: {
301
+ (path: CommandPath, run: (signal: AbortSignal) => void | Promise<void>): Disposer
302
+ (path: CommandPath, definition: CommandDefinition): Disposer
303
+ }
260
304
 
261
305
  /**
262
306
  * Run a command by path, exactly as pressing Enter on it would.
@@ -904,9 +948,125 @@ export type TuiApi = {
904
948
  */
905
949
  export type TuiGateHooks = {
906
950
  /** Before the TUI becomes interactive. Registration is done; the screen is not up. */
907
- "tui:boot": () => void | Promise<void>
951
+ "tui:boot": (payload: TuiBootPayload) => void | Promise<void>
908
952
  /** Before shutdown proceeds. The last point at which anything can be flushed to disk. */
909
- "tui:shutdown": () => void | Promise<void>
953
+ "tui:shutdown": (payload: TuiShutdownPayload) => void | Promise<void>
954
+ }
955
+
956
+ // ── Hook payloads ────────────────────────────────────────────────────────────
957
+ //
958
+ // EVERY hook takes exactly one object, always — including the ones that have
959
+ // nothing to say. `tui.hook(name, ({ x }) => ...)` is the shape throughout, so
960
+ // a handler is written the same way whichever event it listens to, and reading
961
+ // one tells you nothing about which.
962
+ //
963
+ // Positional arguments were the alternative and they lose on every axis that
964
+ // matters here. They fix an order, so adding a field is a choice between a
965
+ // trailing bag nobody discovers and a breaking change; they cannot be
966
+ // destructured by name, so `(a, b)` at a call site says nothing about what a
967
+ // and b are; and they make the empty case a THIRD spelling (`() => {}` beside
968
+ // `(x) => {}` beside `(x, y) => {}`) for no gain. An empty object costs a
969
+ // handler nothing — `() => {}` still type-checks, because a function may always
970
+ // ignore parameters it was handed.
971
+ //
972
+ // So the rule is mechanical and has no exceptions: one payload object per hook,
973
+ // named fields, and a payload type declared here even when it is empty. An
974
+ // empty payload is where a field will go, and having the type already named is
975
+ // what makes adding one a non-event.
976
+
977
+ /**
978
+ * `tui:boot` — nothing yet.
979
+ *
980
+ * Empty rather than absent: the parameter exists so a later field arrives
981
+ * without changing any handler's shape, and so boot is written exactly like
982
+ * every other hook.
983
+ */
984
+ export type TuiBootPayload = {}
985
+
986
+ /** `tui:shutdown` — nothing yet. Empty for the same reason as boot. */
987
+ export type TuiShutdownPayload = {}
988
+
989
+ /** `tui:reloaded` — nothing yet. Empty for the same reason as boot. */
990
+ export type TuiReloadedPayload = {}
991
+
992
+ /** `tui:resize` — the terminal's new dimensions, in cells. */
993
+ export type TuiResizePayload = {
994
+ /** Columns. */
995
+ width: number
996
+ /** Rows. */
997
+ height: number
998
+ }
999
+
1000
+ /**
1001
+ * `key:pressed` — one keystroke the TUI did not act on.
1002
+ *
1003
+ * `mode` rides along because "was a palette open when this fired" is the first
1004
+ * question a handler asks, and reading it back through `mode.get()` would race
1005
+ * the very transition that may have been caused by this key.
1006
+ */
1007
+ export type KeyPressedPayload = {
1008
+ /**
1009
+ * The chord, in the spelling `keys.register()` accepts — `"a"`, `"ctrl+o"`,
1010
+ * `"shift+tab"`. Round-trips deliberately: a handler that decides to claim
1011
+ * a key can pass this string straight to `keys.register`.
1012
+ */
1013
+ key: string
1014
+ /** The mode that was active when the key arrived. */
1015
+ mode: ModeName
1016
+ }
1017
+
1018
+ /** `palette:opened` / `palette:closed` — which palette. */
1019
+ export type PalettePayload = {
1020
+ /** The palette's mode name — `"command"`, `"agent"`, or a user palette's. */
1021
+ name: ModeName
1022
+ }
1023
+
1024
+ /** What one instance hook reports. */
1025
+ export type AgentPayload = {
1026
+ instance: AgentInstance
1027
+ }
1028
+
1029
+ /** `message:sent` — the text, and where it went. */
1030
+ export type MessageSentPayload = {
1031
+ content: string
1032
+ instance: AgentInstance
1033
+ }
1034
+
1035
+ /** `message:received` — see the hook for why there is no content. */
1036
+ export type MessageReceivedPayload = {
1037
+ instance: AgentInstance
1038
+ }
1039
+
1040
+ /** `mode:changed` — the transition, both ends. */
1041
+ export type ModeChangedPayload = {
1042
+ from: ModeName
1043
+ to: ModeName
1044
+ }
1045
+
1046
+ /** `command:ran` / `command:failed` — which command, and how it was reached. */
1047
+ export type CommandPayload = {
1048
+ /** The full path, space-joined — `"ext update"`, `"theme set"`. */
1049
+ path: string
1050
+ /**
1051
+ * How it was invoked: chosen in the command palette, or run by
1052
+ * `commands.run()`.
1053
+ *
1054
+ * Present so a handler can tell the user's action from its own — an
1055
+ * extension that reacts to every command by running another would otherwise
1056
+ * have no way to avoid recursing into itself.
1057
+ *
1058
+ * There is deliberately no `"key"`. A key bound to a command calls
1059
+ * `commands.run()` from its handler, so it IS an api call and reporting it
1060
+ * as its own source would be inventing a distinction the runtime cannot
1061
+ * actually make — a handler that checked for it would never match.
1062
+ */
1063
+ source: "palette" | "api"
1064
+ }
1065
+
1066
+ /** `command:failed` — the above, plus what went wrong. */
1067
+ export type CommandFailedPayload = CommandPayload & {
1068
+ /** The thrown value, exactly as it was thrown. */
1069
+ error: unknown
910
1070
  }
911
1071
 
912
1072
  /**
@@ -917,11 +1077,14 @@ export type TuiGateHooks = {
917
1077
  * "does the TUI block on this?" is answered by the type instead of by reading
918
1078
  * the runtime. A handler needing async work owns it (`void doThing()`), which
919
1079
  * keeps the fire-and-forget visible at the call site.
1080
+ *
1081
+ * There is deliberately no `tui:ready`. It existed, was typed, was documented,
1082
+ * and never fired — and the moment it is wired it is indistinguishable from
1083
+ * `tui:boot`, which already runs once registration is complete and gates the
1084
+ * terminal becoming interactive. Two hooks separated only by whether the screen
1085
+ * has painted is a distinction nothing in this API can act on.
920
1086
  */
921
1087
  export type TuiNotifyHooks = {
922
- /** The TUI is live and interactive. */
923
- "tui:ready": () => void
924
-
925
1088
  /**
926
1089
  * The config was reloaded — `:reload`, or a file change.
927
1090
  *
@@ -933,17 +1096,81 @@ export type TuiNotifyHooks = {
933
1096
  * boot for setup that must finish first; use this to react to having been
934
1097
  * reloaded — refreshing a cached palette, re-reading a file on disk.
935
1098
  */
936
- "tui:reloaded": () => void
1099
+ "tui:reloaded": (payload: TuiReloadedPayload) => void
1100
+
1101
+ /**
1102
+ * The terminal was resized.
1103
+ *
1104
+ * Fires after the new size is in effect, so `tui.size` and this payload
1105
+ * always agree. Coalesced by the underlying watcher: a drag produces the
1106
+ * sizes the terminal actually reported, not one event per column.
1107
+ */
1108
+ "tui:resize": (payload: TuiResizePayload) => void
1109
+
1110
+ /**
1111
+ * A key the TUI did not handle.
1112
+ *
1113
+ * ── Unhandled only, and never consumable ────────────────────────────────
1114
+ *
1115
+ * This fires at the END of dispatch — after reserved chords, after
1116
+ * `keys.register()` bindings, after mode keys. A key that did something
1117
+ * does not arrive here.
1118
+ *
1119
+ * That is not a limitation to route around; it is the only shape that can
1120
+ * be safe. User key handling is mounted as a WILDCARD, and wildcards fire
1121
+ * before exact-key handlers — so a hook able to consume a press would beat
1122
+ * every built-in binding, including the ctrl+c exit ladder. The reserved
1123
+ * list refuses those chords at registration precisely because a check at
1124
+ * press time is already too late.
1125
+ *
1126
+ * So there is no return value and no consumption: this observes, exactly
1127
+ * like every other notify hook. To OWN a key, register it —
1128
+ * `keys.register("ctrl+o", ...)` — which is checked against the reserved
1129
+ * set and cannot break the terminal.
1130
+ */
1131
+ "key:pressed": (payload: KeyPressedPayload) => void
1132
+
1133
+ /**
1134
+ * A palette opened.
1135
+ *
1136
+ * Narrower than `mode:changed`, and deliberately its own event: not every
1137
+ * mode is a palette. `loading` is a spinner and `voice` is a capture state,
1138
+ * and an extension gating on "is the user picking something" has to exclude
1139
+ * them — a derivation every consumer would otherwise write, and get wrong
1140
+ * the same way.
1141
+ */
1142
+ "palette:opened": (payload: PalettePayload) => void
1143
+
1144
+ /** A palette closed. Fires for whichever palette was open. */
1145
+ "palette:closed": (payload: PalettePayload) => void
1146
+
1147
+ /**
1148
+ * A command finished successfully.
1149
+ *
1150
+ * Covers built-ins and user commands alike, however they were reached —
1151
+ * `source` says which. Fires AFTER the action resolves, so an async command
1152
+ * reports when it is genuinely done rather than when it started.
1153
+ */
1154
+ "command:ran": (payload: CommandPayload) => void
1155
+
1156
+ /**
1157
+ * A command threw.
1158
+ *
1159
+ * Its own event rather than a field on `command:ran`, so a handler that
1160
+ * only cares about failures does not have to filter — and so the success
1161
+ * payload never carries an error slot that is null almost always.
1162
+ */
1163
+ "command:failed": (payload: CommandFailedPayload) => void
937
1164
 
938
1165
  /** An instance finished booting. */
939
- "agent:ready": (instance: AgentInstance) => void
1166
+ "agent:ready": (payload: AgentPayload) => void
940
1167
  /** An instance shut down. */
941
- "agent:stopped": (instance: AgentInstance) => void
1168
+ "agent:stopped": (payload: AgentPayload) => void
942
1169
  /** A different instance came on screen. */
943
- "agent:focused": (instance: AgentInstance) => void
1170
+ "agent:focused": (payload: AgentPayload) => void
944
1171
 
945
1172
  /** The user sent a message. Fires once it is delivered. */
946
- "message:sent": (payload: { content: string; instance: AgentInstance }) => void
1173
+ "message:sent": (payload: MessageSentPayload) => void
947
1174
  /**
948
1175
  * The agent finished a wake.
949
1176
  *
@@ -952,10 +1179,16 @@ export type TuiNotifyHooks = {
952
1179
  * reacting to WHAT was said is writing an agent, which is a cognet's job.
953
1180
  * This says only THAT a wake completed.
954
1181
  */
955
- "message:received": (payload: { instance: AgentInstance }) => void
1182
+ "message:received": (payload: MessageReceivedPayload) => void
956
1183
 
957
- /** The active mode changed. */
958
- "mode:changed": (payload: { from: ModeName; to: ModeName }) => void
1184
+ /**
1185
+ * The active mode changed.
1186
+ *
1187
+ * The general event; `palette:opened`/`closed` are the specific ones. Use
1188
+ * this to observe every transition (including `loading` and `voice`), those
1189
+ * to react to the user opening something to pick from.
1190
+ */
1191
+ "mode:changed": (payload: ModeChangedPayload) => void
959
1192
  }
960
1193
 
961
1194
  /** Every lifecycle hook, gating and notifying. */