@arcforge/types 2.0.120 → 2.0.122

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@arcforge/types",
3
- "version": "2.0.120",
3
+ "version": "2.0.122",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "main": "./src/index.ts",
7
7
  "exports": {
8
8
  ".": "./src/index.ts",
9
9
  "./session": "./src/session/index.ts",
10
+ "./tui-contract": "./src/tui-contract.ts",
10
11
  "./tsconfig.base.json": "./tsconfig.base.json"
11
12
  },
12
13
  "files": [
@@ -14,6 +15,7 @@
14
15
  "tsconfig.base.json"
15
16
  ],
16
17
  "scripts": {
18
+ "contract": "bun run scripts/contract.ts",
17
19
  "deploy": "echo \"This package is published ONLY by apps/tui/scripts/release.ts, which pins workspace:* deps to concrete versions first. Publishing it directly ships an unresolvable dependency.\" && exit 1"
18
20
  },
19
21
  "dependencies": {
package/src/engine.ts CHANGED
@@ -57,6 +57,19 @@ export type AxonEngineDef = {
57
57
  * resolves server-side, per call; a client showing it should say so.
58
58
  */
59
59
  model?: string
60
+ /**
61
+ * Auto-selection weighting, when the constructor was given it. Only
62
+ * meaningful alongside model: "auto".
63
+ *
64
+ * On the DEF rather than only inside the driver's closure because with
65
+ * "auto" these are what decides the real model, so a client asking
66
+ * "what am I running on" (cloud.engine.resolve) must be able to read
67
+ * them — resolving without them answers for the default, not for this
68
+ * agent.
69
+ */
70
+ optimize?: EngineAutoWeights
71
+ /** Hard ceilings applied before scoring. Only meaningful alongside model: "auto". */
72
+ limit?: EngineAutoLimits
60
73
  create(res: EngineResources): AxonEngineDriver
61
74
  }
62
75
 
package/src/error.ts CHANGED
@@ -76,6 +76,19 @@ export interface AxonError extends Error {
76
76
  description: string
77
77
  source: AxonErrorSource
78
78
  severity: AxonErrorSeverity
79
+ /**
80
+ * The USER caused this and can fix it from the message alone — a wrong
81
+ * directory, a missing argument, a name that does not exist.
82
+ *
83
+ * Renderers show these without frames or a cause chain: our call stack is
84
+ * not part of the answer, and printing it tells the user to debug software
85
+ * they did not write. Absent means unexpected (the safe default), which
86
+ * still gets the full diagnostic.
87
+ *
88
+ * A different axis from `severity`: PROJECT_NOT_FOUND is both `fatal` (the
89
+ * command cannot continue) and expected.
90
+ */
91
+ expected?: boolean
79
92
  context: AxonErrorContext | undefined
80
93
  frames: AxonStackFrame[]
81
94
  /** native Error.cause — walk this to render the full chain */
package/src/index.ts CHANGED
@@ -23,4 +23,5 @@ export * from "./session"
23
23
  export * from "./kernel"
24
24
  export * from "./cognet"
25
25
  export * from "./tools"
26
+ export * from "./tui"
26
27
  export * from "./bench"
@@ -54,16 +54,41 @@ export type AxonEventContext = {
54
54
  * `K` narrows to one event type.
55
55
  */
56
56
  export type AxonEvent<M, K extends keyof M = keyof M, C extends object = AxonEventContext> = {
57
- /** UUIDv7 — globally unique and time-sortable. Idempotent ingest. */
58
- id: string
59
57
  type: K
60
58
  time: {
61
59
  /** Wall clock ms since epoch. */
62
60
  ms: number
63
- /** Monotonic per-session counter — authoritative ordering, immune to clock skew. */
61
+ /**
62
+ * Monotonic per-session counter — authoritative ordering, immune to
63
+ * clock skew, and the event's IDENTITY.
64
+ *
65
+ * There used to be a UUIDv7 `id` alongside this. It was removed:
66
+ * measured on a real 1M-event session it cost 8.8MB (14% of the
67
+ * file) to express something `seq` already expressed better —
68
+ * verified unique and monotonic across 300k consecutive events, and
69
+ * never read back by the runtime. A session log is a sequence, and
70
+ * a sequence numbers its members.
71
+ *
72
+ * Unique within one session. A consumer needing global uniqueness
73
+ * (cloud ingest) pairs it with the session id from the header.
74
+ */
64
75
  seq: number
65
76
  }
66
- context: C
77
+ /**
78
+ * Correlation ids for this event.
79
+ *
80
+ * Optional ONLY for the session envelope, whose context is
81
+ * `AxonEventContext` — there, most events have no correlation at all,
82
+ * and an empty object on every line is exactly the kind of constant
83
+ * this format exists to stop writing. What is true of the WHOLE FILE
84
+ * (agent, session) lives in the header line instead; only
85
+ * `runId`/`spanId`, which genuinely vary per event, are carried here.
86
+ *
87
+ * A stream that supplies its own context type — bench, test — keeps it
88
+ * required, because for those it identifies WHICH run or case the event
89
+ * belongs to and an event without it would be unattributable.
90
+ */
91
+ context: AxonEventContext extends C ? C | undefined : C
67
92
  /** Typed payload — the registry map is the single source of payload truth. */
68
93
  data: M[K]
69
94
  }
@@ -40,6 +40,15 @@ import type { CapsuleScope } from "../../capsule-scope"
40
40
  * behavior is lost, which is exactly what the JSON shape describes.
41
41
  */
42
42
 
43
+ /**
44
+ * Who asked for a capsule command to run — see the capsule:cmd span below.
45
+ *
46
+ * Declared here rather than in @axon/capsule for the same reason the event
47
+ * map is: every type that can reach a session log lives in this package's
48
+ * registry, and @axon/capsule re-exports from here rather than owning it.
49
+ */
50
+ export type CapsuleCommandOrigin = "cognet" | "host"
51
+
43
52
  export type CapsuleEventMap =
44
53
  // ── Lifecycle ────────────────────────────────────────────────────────────
45
54
  & AxonSpan<"capsule:boot", {}, {}, { error: AxonErrorJSON }>
@@ -69,9 +78,16 @@ export type CapsuleEventMap =
69
78
  { restartCount: number; error: AxonErrorJSON }
70
79
  >
71
80
  // ── Command execution (one run() = one command id) ──────────────────────
81
+ // `origin` is provenance, never privilege: a "host" command (a
82
+ // developer typing into Fleet's capsule input) travels the identical
83
+ // path under the identical policy gate as the cognet's own code. It
84
+ // is recorded because this log is a record of what the AGENT did,
85
+ // and an unmarked human command would make that record lie.
86
+ // Absent means "cognet" — every command predating this field, and
87
+ // every command the runtime itself issues.
72
88
  & AxonCancellableSpan<
73
89
  "capsule:cmd",
74
- { id: string },
90
+ { id: string; origin?: CapsuleCommandOrigin },
75
91
  { id: string; result: unknown; scope: CapsuleScope },
76
92
  { id: string; error: AxonErrorJSON },
77
93
  { id: string; durationMs: number }
@@ -6,7 +6,7 @@ export type {
6
6
  } from "./envelope"
7
7
  export type { AxonKernelEventMap } from "./events/kernel"
8
8
  export type { CognetEventMap } from "./events/cognet"
9
- export type { CapsuleEventMap, CapsuleEventName, AnyCapsuleEvent } from "./events/capsule"
9
+ export type { CapsuleEventMap, CapsuleEventName, AnyCapsuleEvent, CapsuleCommandOrigin } from "./events/capsule"
10
10
  export type { BuildEventMap, BuildEventName, AnyBuildEvent, BuildStage } from "./events/build"
11
11
  export { isBuildEvent } from "./events/build"
12
12
  export type { Activity, ActivityHandle, ActivityPayloads, ActivityPhase, ActivityType, AxonAmbient } from "./events/activity"
@@ -20,7 +20,8 @@ import { isSpanEnd, isSpanStart, spanStem } from "./events/span"
20
20
  export type ReadableEvent = {
21
21
  type: string
22
22
  time: { seq: number; ms: number }
23
- context: { runId?: string }
23
+ /** Optional: most events carry no correlation at all — see AxonEvent. */
24
+ context?: { runId?: string }
24
25
  data: Record<string, unknown>
25
26
  }
26
27
 
@@ -67,7 +68,7 @@ function bracketKey(event: ReadableEvent): string {
67
68
  const value = d[field]
68
69
  if (typeof value === "string" || typeof value === "number") parts.push(`${field}:${value}`)
69
70
  }
70
- const spanId = (event.context as { spanId?: string }).spanId
71
+ const spanId = (event.context as { spanId?: string } | undefined)?.spanId
71
72
  if (spanId) parts.push(`span:${spanId}`)
72
73
  return parts.join("|")
73
74
  }
@@ -0,0 +1,8 @@
1
+ // GENERATED by scripts/contract.ts from src/tui.ts — do not edit.
2
+ //
3
+ // The TUI contract as source text, for `axon prepare` to wrap in
4
+ // `declare global` and write into a profile's or extension's type frame.
5
+ // A profile has no node_modules, so its globals cannot import — they must be
6
+ // this text, inlined.
7
+
8
+ export const TUI_CONTRACT = " /**\n * The TUI extension contract — what a user's `main.ts`, a profile config, and\n * a published extension are written against.\n *\n * ── This file is copied verbatim into generated type frames ──────────────────\n *\n * `axon prepare` writes this source text into a profile's `.axon/types/` and an\n * extension's `.extension/types/` as ambient globals. That is why it declares\n * NO imports: a profile directory has no node_modules for an import to resolve\n * through (see prompt-dts.ts, which accepted the same constraint for the same\n * reason). Unlike prompts, there is no duplicated copy to keep in step — the\n * generator reads THIS file, so the contract and the globals cannot drift.\n *\n * Adding an import here breaks every profile's typecheck. Add the type instead.\n *\n * ── What this layer is for ───────────────────────────────────────────────────\n *\n * Workflow design in the terminal, and nothing more. The rule that draws the\n * boundary: an extension DRIVES the conversation, it never CONSUMES it.\n * `agents.send()` returns void — an extension that awaited model output and\n * branched on its text would be writing an agent, in the config layer, badly.\n * Agent behaviour belongs in a cognet, which the same user can build.\n *\n * The surface is deliberately small and complete against one test: everything\n * reachable from the keyboard is reachable from code. Mode keys → `mode`,\n * typing → `input`, palette navigation → `palette`, `:` → `commands`, chords →\n * `keys`, `~`/`/`/`^` → `agents`, Ctrl+C → `tui`. `keys.send()` backstops\n * whatever this missed. Nothing here renders: user surfaces are built from the\n * palette primitives, so every extension's UI is as good as the built-in one\n * and stays that way when the palette improves.\n */\n\n // ── Disposal ─────────────────────────────────────────────────────────────────\n\n /**\n * Undoes one registration.\n *\n * Every `register`/`create` returns one, and the loader tracks them per\n * extension so a hot-reload can tear the previous load down before running\n * setup again. Without this, each reload leaves its registrations behind and\n * one keystroke fires N handlers — the accumulation `Hooks().reset()` exists to\n * prevent on the agent runtime side.\n */\n type Disposer = () => void\n\n // ── Palette ──────────────────────────────────────────────────────────────────\n\n /**\n * One row in any palette — user-created or built-in.\n *\n * This is the SAME item type the TUI's own modes produce. A user palette that\n * could not express what `~` or `^` expresses would turn every gap into a\n * feature request, so the built-ins hold no privileged row shape: they are\n * simply the palettes that ship.\n */\n type PaletteItem = {\n id: string\n label: string\n description?: string\n /**\n * Independently-searchable parts of this row, for a list long enough that\n * one substring match over `label` stops being enough — every query term\n * narrows against any chunk. The model palette sets route and model id as\n * separate chunks, which is what lets ~800 rows live in one flat list with\n * no tabs or pages. Omit for ordinary rows.\n */\n chunks?: readonly string[]\n /**\n * Run on Enter. A returned promise holds the palette in its working state\n * until it settles. The signal aborts when the user escapes mid-flight —\n * actions that cannot be cancelled may ignore it.\n */\n action?: (signal: AbortSignal) => void | Promise<void>\n /** Selecting this row rewrites the query to this text instead of running `action` — descending into a group. */\n descendQuery?: string\n /** Selecting this row shows these rows as a follow-up list — a confirm/choice step. Computed at the moment it is confirmed. */\n choices?: () => PaletteItem[]\n /** Run on cursor movement, before confirming — live preview. */\n preview?: () => void\n /** Shown in the working row while an async `action` is in flight. */\n workingMessage?: string\n /**\n * Close immediately and let `action` finish in the background, rather than\n * holding the list open behind a working row.\n *\n * Only for actions whose progress has its OWN surface. An action that\n * reports nowhere else must not set this, or its failure becomes invisible.\n */\n detach?: boolean\n /** Non-selectable section header. */\n header?: boolean\n /** Non-selectable blank spacer between groups. */\n separator?: boolean\n }\n\n /** A tab in a tabbed palette. First tab is active on entry. */\n type PaletteTab = {\n id: string\n label: string\n }\n\n /** Loading/error indicator shown above the item list. */\n type PaletteStatus =\n | { kind: \"loading\"; message: string }\n | { kind: \"error\"; message: string }\n | null\n\n /**\n * What one query resolves to — items plus everything else this palette has to\n * say about that same query.\n *\n * Derived from a single call so status, breadcrumb and items can never drift\n * out of sync, which is the failure mode of computing them as independently\n * triggered fields. Returning a bare array is shorthand for `{ items }`.\n */\n type PaletteResult = {\n items: PaletteItem[]\n /** Prefix shown on every row — a path walked so far. */\n breadcrumb?: string | null\n status?: PaletteStatus\n /** True when the query cannot resolve to anything selectable — a dead-end token. */\n invalid?: boolean\n }\n\n /**\n * A user-defined palette.\n *\n * `list` is the only required member: given the query and active tab, return\n * the rows. It may be async — the palette shows its own loading state while the\n * first call is in flight, and results are cached until `refresh()` is called\n * on the handle.\n */\n type PaletteDefinition = {\n /**\n * Produce the rows for one query.\n *\n * The TUI applies its own substring filter over the returned items unless\n * `filter: false` — so a list that does not care about `query` can ignore\n * the argument entirely and still be searchable.\n */\n list: (query: string, tab: string | null) => PaletteItem[] | PaletteResult | Promise<PaletteItem[] | PaletteResult>\n /** This palette filters by query itself — the TUI must not filter again. */\n filter?: boolean\n /** Declares this palette as tabbed. Omit for a single flat list. */\n tabs?: PaletteTab[]\n /** Max visible rows before scrolling. */\n maxHeight?: number\n /**\n * \"top\" (default): newest first, cursor starts at the top. \"bottom\": items\n * are given oldest→newest, the cursor starts on the last row and up-arrow\n * walks back in time — the terminal-log feel of history and session mode.\n */\n anchor?: \"top\" | \"bottom\"\n /**\n * A mode key that opens this palette from an empty input, e.g. \"&\".\n *\n * Throws at registration if the key is already taken — a silently shadowed\n * mode key is unbearable to debug in someone else's config.\n */\n key?: string\n /** Symbol shown in the input bar while this palette is open. Defaults to `key`. */\n symbol?: string\n /** One-line description, shown in `?` (help) alongside the built-in modes. */\n description?: string\n }\n\n /** Handle on one registered palette. */\n type PaletteHandle = {\n readonly name: string\n /** Open it. Rejects if another palette is already open — see `palette.open`. */\n open: () => Promise<void>\n /** Drop the cached list so the next open recomputes it. Does not reopen. */\n refresh: () => void\n /** Unregister, closing it first if it is open. */\n dispose: Disposer\n }\n\n /** A pick option carrying a value, for `pick` over things that are not strings. */\n type PickOption<T> = {\n label: string\n description?: string\n value: T\n }\n\n /**\n * The palette — the TUI's interaction primitive, and the reason this layer can\n * stay small. Registered palettes cover \"the user opens a list\"; `pick`,\n * `confirm` and `prompt` cover \"code asks the user a question\".\n *\n * The question verbs return promises rather than taking callbacks, which is\n * what makes multi-step flows fall out for free: they are sequential awaits,\n * not a wizard framework.\n *\n * Every question resolves to a cancelled value on escape — `undefined`, or\n * `false` for `confirm`. That is in the return type deliberately: a caller is\n * forced to handle the user walking away.\n */\n type PaletteApi = {\n /** Register a palette. Throws if `name` is taken. */\n create: (name: string, definition: PaletteDefinition) => PaletteHandle\n\n /** A registered palette by name, or null. */\n get: (name: string) => PaletteHandle | null\n\n /**\n * Open a registered palette by name.\n *\n * Throws if no palette has that name, and throws if another palette is\n * already open — stealing the palette out from under someone mid-navigation\n * is exactly the kind of silent degradation that makes an extension system\n * feel haunted. Check `palette.isOpen` first if a keybind might collide.\n */\n open: (name: string) => Promise<void>\n\n /** Close whatever is open. No-op when nothing is. */\n close: () => void\n\n /** True while any palette is open, built-in or user-defined. */\n readonly isOpen: boolean\n\n /** Ask the user to choose one of a list of strings. Resolves undefined on escape. */\n pick: {\n (options: readonly string[], opts?: { placeholder?: string }): Promise<string | undefined>\n <T>(options: readonly PickOption<T>[], opts?: { placeholder?: string }): Promise<T | undefined>\n }\n\n /** Ask a yes/no question. Resolves false on escape. */\n confirm: (message: string) => Promise<boolean>\n\n /** Ask for a line of text. Resolves undefined on escape. */\n prompt: (message: string, opts?: { placeholder?: string; initial?: string }) => Promise<string | undefined>\n }\n\n // ── Commands ─────────────────────────────────────────────────────────────────\n\n /**\n * Where a command sits in the `:` tree.\n *\n * `\"deploy\"` is top level; `[\"theme\", \"set\"]` is nested under a group, which is\n * created on demand. Both forms accepted — a flat command should not have to be\n * written as a one-element array.\n */\n type CommandPath = string | readonly string[]\n\n type CommandOptions = {\n /** Shown beside the command in the palette. */\n description?: string\n /** Shown in the working row while an async command runs. */\n workingMessage?: string\n }\n\n type CommandsApi = {\n /**\n * Add a command to the `:` tree.\n *\n * Built-in commands always win a collision, and two extensions colliding is\n * first-registered-wins with a warning naming both — never silent shadowing.\n */\n register: (path: CommandPath, action: (signal: AbortSignal) => void | Promise<void>, options?: CommandOptions) => Disposer\n\n /**\n * Run a command by path, exactly as pressing Enter on it would.\n *\n * This is how an extension reaches functionality that has a command but no\n * dedicated API — one verb instead of re-exposing every command's\n * implementation. Throws if the path resolves to nothing.\n */\n run: (path: CommandPath) => Promise<void>\n\n /** Every registered command path, built-in and user. */\n list: () => readonly string[][]\n }\n\n // ── Keys ─────────────────────────────────────────────────────────────────────\n\n type KeysApi = {\n /**\n * Bind a chord, e.g. \"ctrl+o\".\n *\n * Built-in bindings win; two extensions colliding is first-wins with a\n * warning naming both. Bindings do not fire while a palette is open.\n */\n register: (chord: string, handler: () => void | Promise<void>) => Disposer\n\n /**\n * Deliver a keypress as though the user had typed it.\n *\n * The escape hatch that keeps this surface honest: anything the API forgot\n * to expose is still reachable, so a missing verb is an inconvenience\n * rather than a wall.\n */\n send: (chord: string) => void\n }\n\n // ── Modes ────────────────────────────────────────────────────────────────────\n\n /**\n * Built-in mode names. A user palette registered with a `key` adds its own\n * name to what `mode.set` accepts at runtime, which is why this is not a\n * closed union at the type level.\n */\n type BuiltinMode =\n | \"normal\"\n | \"command\"\n | \"model\"\n | \"session\"\n | \"agent\"\n | \"instance\"\n | \"voice\"\n | \"help\"\n | \"history\"\n | \"prompt\"\n | \"module\"\n | \"script\"\n\n type ModeName = BuiltinMode | (string & {})\n\n type ModeApi = {\n /** Switch modes. Throws on an unknown mode rather than silently doing nothing. */\n set: (mode: ModeName) => Promise<void>\n /** The active mode. */\n get: () => ModeName\n /** The symbol currently shown in the input bar. */\n symbol: () => string\n }\n\n // ── Input ────────────────────────────────────────────────────────────────────\n\n /** The message box the user types into. */\n type InputApi = {\n get: () => string\n set: (text: string) => void\n /** Append to the current text without clearing it — the voice-transcript behaviour. */\n append: (text: string) => void\n clear: () => void\n /**\n * Send the current input as a message to the focused agent, exactly as\n * pressing Enter would, and clear the box. No-op when it is empty.\n */\n submit: () => Promise<void>\n }\n\n // ── Agents ───────────────────────────────────────────────────────────────────\n\n /** What a running instance looks like to an extension. */\n type AgentInstance = {\n /** Stable identity of this instance. Every instance verb addresses by this. */\n readonly id: string\n /** The agent project's name — several instances may share one. */\n readonly name: string\n /** True for the instance currently on screen. */\n readonly focused: boolean\n /** Null when idle. */\n readonly activity: \"booting\" | \"rebooting\" | \"shutting-down\" | \"working\" | null\n }\n\n /** An agent that can be started — a local project or a deployment. */\n type AgentTarget = {\n readonly name: string\n readonly kind: \"local\" | \"deployed\"\n /** Running instances of this agent, most recently focused first. */\n readonly instances: readonly AgentInstance[]\n }\n\n /**\n * Agents, addressed the way the TUI addresses them: you START by name and then\n * everything else is BY INSTANCE.\n *\n * That split is not incidental. One agent can have many live instances — that\n * is what `spawn` twice gives you — so a verb taking a name has no answer for\n * \"which one\", and collapsing the two would make siblings unreachable from\n * extensions.\n */\n type AgentsApi = {\n /** Every agent that can be started, with its live instances. */\n targets: () => Promise<readonly AgentTarget[]>\n\n /** Every running instance, in spawn order. */\n list: () => readonly AgentInstance[]\n\n /** One instance by id, or null if it is not running. */\n get: (id: string) => AgentInstance | null\n\n /** The instance currently on screen, or null when nothing is running. */\n focused: () => AgentInstance | null\n\n /**\n * Boot a new instance of an agent IN THE BACKGROUND, resolving once it is\n * live. The view does not change.\n *\n * Always a NEW instance — this is the sibling verb.\n *\n * Background is the whole point: a config that booted two agents would\n * otherwise have them race for the screen, and neither asked to be looked\n * at. Showing one is a separate, explicit act — `tui.nav(name)` goes to an\n * agent (booting one if none is live), and `agents.focus(id)` goes to a\n * specific instance.\n *\n * Returns the instance, which is what makes a workflow composable: the id\n * is how every other verb here addresses it, and one agent may have many\n * live instances, so \"the one I just started\" cannot be recovered from the\n * name afterwards.\n */\n spawn: (name: string) => Promise<AgentInstance>\n\n /** Put an instance on screen. Throws if it is not running. */\n focus: (id: string) => void\n\n /**\n * Shut an instance down. The only verb here that ends a conversation.\n *\n * Omit `id` for the focused instance.\n */\n stop: (id?: string) => Promise<void>\n\n /**\n * Reload an instance's blueprint in place. The conversation survives.\n *\n * Omit `id` for the focused instance.\n */\n reboot: (id?: string) => Promise<void>\n\n /**\n * Send a message to the FOCUSED instance, as though the user had typed it\n * and pressed Enter.\n *\n * Returns when the message is DELIVERED, not when the agent has answered,\n * and yields nothing: an extension drives the conversation and never\n * consumes it. Reading a model's output to decide what to do next is an\n * agent's job — build a cognet.\n *\n * Focused rather than addressable, deliberately. Delivery is not a simple\n * dispatch — a send during a switch is QUEUED for the agent arriving rather\n * than delivered to the one being left, which is the difference between a\n * message landing in the right conversation and the wrong one. That rule is\n * defined in terms of what the user is looking at, so a per-instance send\n * would need its own answer to a question the focused path already answers\n * correctly.\n *\n * Note that `spawn()` does NOT focus what it starts, so sending to a\n * freshly spawned agent means going to it first:\n *\n * const reviewer = await agents.spawn(\"@axon/reviewer\")\n * agents.focus(reviewer.id)\n * await agents.send(\"review main\")\n */\n send: (content: string) => Promise<void>\n\n /** Interrupt the focused instance's current wake, as Escape does. True if something was interrupted. */\n interrupt: () => boolean\n }\n\n // ── The TUI itself ───────────────────────────────────────────────────────────\n\n /** Terminal dimensions in cells. */\n type TuiSize = {\n readonly width: number\n readonly height: number\n }\n\n // ── Themes ───────────────────────────────────────────────────────────────────\n\n /**\n * Every colour name the terminal can render.\n *\n * ── Generated, not written ──────────────────────────────────────────────────\n *\n * The list between the markers is produced by `scripts/contract.ts` from\n * VTerm's own colour parser — its terminal basics (`brightcyan`) plus the full\n * CSS3 named set. Do not edit it by hand; a name here that the parser does not\n * know renders as nothing, which is the failure the union exists to prevent.\n */\n type ColorName =\n // <color-names>\n | \"aliceblue\"\n | \"antiquewhite\"\n | \"aqua\"\n | \"aquamarine\"\n | \"azure\"\n | \"beige\"\n | \"bisque\"\n | \"black\"\n | \"blanchedalmond\"\n | \"blue\"\n | \"blueviolet\"\n | \"brightblack\"\n | \"brightblue\"\n | \"brightcyan\"\n | \"brightgreen\"\n | \"brightmagenta\"\n | \"brightred\"\n | \"brightwhite\"\n | \"brightyellow\"\n | \"brown\"\n | \"burlywood\"\n | \"cadetblue\"\n | \"chartreuse\"\n | \"chocolate\"\n | \"coral\"\n | \"cornflowerblue\"\n | \"cornsilk\"\n | \"crimson\"\n | \"cyan\"\n | \"darkblue\"\n | \"darkcyan\"\n | \"darkgoldenrod\"\n | \"darkgray\"\n | \"darkgreen\"\n | \"darkgrey\"\n | \"darkkhaki\"\n | \"darkmagenta\"\n | \"darkolivegreen\"\n | \"darkorange\"\n | \"darkorchid\"\n | \"darkred\"\n | \"darksalmon\"\n | \"darkseagreen\"\n | \"darkslateblue\"\n | \"darkslategray\"\n | \"darkslategrey\"\n | \"darkturquoise\"\n | \"darkviolet\"\n | \"deeppink\"\n | \"deepskyblue\"\n | \"dimgray\"\n | \"dimgrey\"\n | \"dodgerblue\"\n | \"firebrick\"\n | \"floralwhite\"\n | \"forestgreen\"\n | \"fuchsia\"\n | \"gainsboro\"\n | \"ghostwhite\"\n | \"gold\"\n | \"goldenrod\"\n | \"gray\"\n | \"green\"\n | \"greenyellow\"\n | \"grey\"\n | \"honeydew\"\n | \"hotpink\"\n | \"indianred\"\n | \"indigo\"\n | \"ivory\"\n | \"khaki\"\n | \"lavender\"\n | \"lavenderblush\"\n | \"lawngreen\"\n | \"lemonchiffon\"\n | \"lightblue\"\n | \"lightcoral\"\n | \"lightcyan\"\n | \"lightgoldenrodyellow\"\n | \"lightgray\"\n | \"lightgreen\"\n | \"lightgrey\"\n | \"lightpink\"\n | \"lightsalmon\"\n | \"lightseagreen\"\n | \"lightskyblue\"\n | \"lightslategray\"\n | \"lightslategrey\"\n | \"lightsteelblue\"\n | \"lightyellow\"\n | \"lime\"\n | \"limegreen\"\n | \"linen\"\n | \"magenta\"\n | \"maroon\"\n | \"mediumaquamarine\"\n | \"mediumblue\"\n | \"mediumorchid\"\n | \"mediumpurple\"\n | \"mediumseagreen\"\n | \"mediumslateblue\"\n | \"mediumspringgreen\"\n | \"mediumturquoise\"\n | \"mediumvioletred\"\n | \"midnightblue\"\n | \"mintcream\"\n | \"mistyrose\"\n | \"moccasin\"\n | \"navajowhite\"\n | \"navy\"\n | \"oldlace\"\n | \"olive\"\n | \"olivedrab\"\n | \"orange\"\n | \"orangered\"\n | \"orchid\"\n | \"palegoldenrod\"\n | \"palegreen\"\n | \"paleturquoise\"\n | \"palevioletred\"\n | \"papayawhip\"\n | \"peachpuff\"\n | \"peru\"\n | \"pink\"\n | \"plum\"\n | \"powderblue\"\n | \"purple\"\n | \"rebeccapurple\"\n | \"red\"\n | \"rosybrown\"\n | \"royalblue\"\n | \"saddlebrown\"\n | \"salmon\"\n | \"sandybrown\"\n | \"seagreen\"\n | \"seashell\"\n | \"sienna\"\n | \"silver\"\n | \"skyblue\"\n | \"slateblue\"\n | \"slategray\"\n | \"slategrey\"\n | \"snow\"\n | \"springgreen\"\n | \"steelblue\"\n | \"tan\"\n | \"teal\"\n | \"thistle\"\n | \"tomato\"\n | \"turquoise\"\n | \"violet\"\n | \"wheat\"\n | \"white\"\n | \"whitesmoke\"\n | \"yellow\"\n | \"yellowgreen\"\n // </color-names>\n\n /**\n * Any colour a theme token can hold.\n *\n * A named colour autocompletes; so does `transparent`, which means \"paint\n * nothing and let the real terminal show through\" — the right answer for\n * `background` in almost every theme.\n *\n * `(string & {})` keeps that autocomplete while still accepting the forms a\n * union cannot enumerate: `#1a1b26`, `rgb(26, 27, 38)`, an rgba() with alpha.\n * Unlike `syntax`, an unrecognised value here is not automatically a typo —\n * hex is the common case — so this stays open where that one is closed.\n */\n type ThemeColor =\n | ColorName\n | \"transparent\"\n | (string & {})\n\n /**\n * The seven tokens every Axon surface draws from.\n *\n * Closed on purpose. The TUI reached ~30 hard-coded colours before this — four\n * greys nobody chose deliberately, five reds — and a theme API with a field per\n * call site would preserve that forever: a \"theme\" would mean thirty decisions,\n * and no two themes would agree what any of them were for.\n *\n * Seven decisions, and every surface derives from them. That is what makes a\n * theme portable: whatever an author writes lands on the same things.\n */\n type ThemeTokens = {\n /** Accent. Selection, the input rule, focused rows, links. */\n primary: ThemeColor\n /** The terminal's own ground. */\n background: ThemeColor\n /** Ordinary foreground — what most text is. */\n text: ThemeColor\n /** Secondary foreground: paths, descriptions, timestamps, anything subordinate. */\n dim: ThemeColor\n /** Something needs attention but nothing failed. */\n warn: ThemeColor\n /** Something failed. */\n error: ThemeColor\n /**\n * Syntax highlighting for code blocks and the editor.\n *\n * A bundled theme name autocompletes — see `BundledSyntax` for the full\n * set. An author who wants their own tokenisation passes a TextMate theme\n * object instead, which is the same shape Shiki takes.\n *\n * Deliberately NOT widened with `(string & {})` the way `ThemeColor` is.\n * A colour Axon does not recognise still renders — the terminal hands it\n * to the ANSI layer and something sensible happens. A syntax theme name\n * Shiki does not have loads nothing, so an unrecognised string is always a\n * typo, and the union is what turns it into a red squiggle in the user's\n * editor instead of unhighlighted code they have to diagnose.\n */\n syntax: BundledSyntax | Record<string, unknown>\n }\n\n /** A registered theme: its tokens plus the name it is addressed by. */\n type Theme = ThemeTokens & { name: string }\n\n /**\n * Every syntax theme that ships with Axon.\n *\n * ── Generated, not written ──────────────────────────────────────────────────\n *\n * The list between the markers below is produced by `scripts/contract.ts` from\n * Shiki's own `bundledThemes`, and rewritten in place whenever that script\n * runs. Do not edit it by hand — a name here that Shiki does not have is a\n * theme that typechecks and then fails to load at runtime, which is exactly the\n * failure a literal union is supposed to prevent.\n *\n * It is a literal union rather than an import because this file is copied\n * verbatim into a profile's type frame, where there is no node_modules to\n * import Shiki through. The generator is what keeps the copy honest.\n *\n * ── Bundling all of them is nearly free ─────────────────────────────────────\n *\n * Shiki's bundle is a map of dynamic-import thunks and the highlighter is\n * constructed with ONE theme, calling `loadTheme()` for each further one a user\n * actually selects. So the cost of offering every theme is a single import at\n * the moment someone picks it — not the whole set at boot.\n */\n type BundledSyntax =\n // <bundled-syntax>\n | \"andromeeda\"\n | \"aurora-x\"\n | \"ayu-dark\"\n | \"catppuccin-frappe\"\n | \"catppuccin-latte\"\n | \"catppuccin-macchiato\"\n | \"catppuccin-mocha\"\n | \"dark-plus\"\n | \"dracula\"\n | \"dracula-soft\"\n | \"everforest-dark\"\n | \"everforest-light\"\n | \"github-dark\"\n | \"github-dark-default\"\n | \"github-dark-dimmed\"\n | \"github-dark-high-contrast\"\n | \"github-light\"\n | \"github-light-default\"\n | \"github-light-high-contrast\"\n | \"houston\"\n | \"kanagawa-dragon\"\n | \"kanagawa-lotus\"\n | \"kanagawa-wave\"\n | \"laserwave\"\n | \"light-plus\"\n | \"material-theme\"\n | \"material-theme-darker\"\n | \"material-theme-lighter\"\n | \"material-theme-ocean\"\n | \"material-theme-palenight\"\n | \"min-dark\"\n | \"min-light\"\n | \"monokai\"\n | \"night-owl\"\n | \"nord\"\n | \"one-dark-pro\"\n | \"one-light\"\n | \"plastic\"\n | \"poimandres\"\n | \"red\"\n | \"rose-pine\"\n | \"rose-pine-dawn\"\n | \"rose-pine-moon\"\n | \"slack-dark\"\n | \"slack-ochin\"\n | \"snazzy-light\"\n | \"solarized-dark\"\n | \"solarized-light\"\n | \"synthwave-84\"\n | \"tokyo-night\"\n | \"vesper\"\n | \"vitesse-black\"\n | \"vitesse-dark\"\n | \"vitesse-light\"\n // </bundled-syntax>\n /** Axon's own, and the default. */\n | \"arcnight\"\n\n /**\n * Themes — the terminal's colours, and switching between them.\n *\n * A theme is registered like a palette and applied like a mode. `\"` opens the\n * built-in picker, which previews as the cursor moves: hovering a row paints it\n * for real, because a preview that rendered differently from the result would\n * be worth nothing.\n */\n type ThemeApi = {\n /**\n * Register a theme. Throws if the name is taken. Returns a disposer.\n *\n * Name first, tokens second — the same shape as `palette.create`, so the\n * two read alike rather than one carrying its identity inside the object\n * and the other beside it.\n */\n create: (name: string, tokens: ThemeTokens) => Disposer\n\n /** Paint a theme and keep it. Throws on an unknown name. */\n set: (name: string) => void\n\n /** Every registered theme, built-ins first. */\n list: () => readonly Theme[]\n\n /** The theme currently painted. */\n readonly active: Theme\n }\n\n /**\n * Everything that belongs to the terminal rather than to one of the domains\n * above. Kept deliberately thin — a verb with a natural home in `palette`,\n * `commands`, `keys`, `mode`, `input` or `agents` belongs there.\n */\n type TuiApi = {\n /**\n * Go to an agent: focus the instance the user was last on, booting one if\n * none is live. The `~` key's behaviour.\n *\n * Name-addressed on purpose — \"take me to this agent\" is a different verb\n * from \"focus this exact instance\" (`agents.focus`), and both are real.\n */\n nav: (name: string) => Promise<void>\n\n /**\n * Register a lifecycle handler. See TuiHooks.\n *\n * Available everywhere — `main.ts`, a `plugins/` file, an extension's\n * `setup()` — because there is no capability difference between them, only\n * a timing one. `plugins/` is where hooks live by convention, not by rule.\n */\n hook: <N extends TuiHookName>(name: N, handler: TuiHooks[N]) => Disposer\n\n /**\n * A brief label on the cwd row — the same line the ctrl+c and double-esc\n * hints borrow. Flashes for 300ms by default, then the row returns to the\n * path.\n *\n * tui.info(\"deployed\")\n * tui.warn(\"nothing to do\", 600)\n * tui.error(\"command failed\")\n *\n * ── A reaction, not a message ───────────────────────────────────────────\n *\n * This row's existing tenants are both feedback about the key just pressed,\n * and these are the same thing: something to catch the eye, not something\n * to read. Longer than ~50 characters is trailed with an ellipsis, which is\n * the honest consequence of a one-line surface rather than a limit to work\n * around.\n *\n * So anything with CONTENT — a reason, a path, a stack — does not belong\n * here. Throw instead: it lands in the config error list on the chat page,\n * which is scrollable and stays put.\n *\n * The second argument is milliseconds, clamped to a few seconds. The\n * terminal's own hints outrank all three verbs — one fired during the\n * ctrl+c window waits rather than displacing the exit ladder.\n */\n info: (message: string, ms?: number) => void\n\n /** As `info`, in the warning colour. */\n warn: (message: string, ms?: number) => void\n\n /** As `info`, in the error colour. For \"that failed\" — never for why. */\n error: (message: string, ms?: number) => void\n\n readonly size: TuiSize\n\n /** The directory the TUI was launched from. */\n readonly cwd: string\n\n /** Version of the running Axon CLI. */\n readonly version: string\n\n /**\n * Quit, running the same exit guards a Ctrl+C does.\n *\n * There is deliberately no `update()`: a self-update hands off to a helper\n * that runs after the process exits, and an extension triggering that is a\n * way for a config to brick an install mid-session.\n */\n exit: () => Promise<void>\n }\n\n // ── Hooks ────────────────────────────────────────────────────────────────────\n //\n // ONE verb: `tui.hook(name, handler)`. There is deliberately no `.on()`\n // alongside it.\n //\n // A blocking `hook()` and a fire-and-forget `on()` are indistinguishable at the\n // call site — one letter apart, differing only in a consequence you cannot see\n // — and picking the wrong one buys either a race or a hang. Whether the TUI\n // waits is a property of the EVENT, not of how a handler was registered: `boot`\n // has a meaningful \"before\" to run in, `mode:changed` announces something that\n // already happened and waiting on it only delays the UI.\n //\n // So the event decides, the types say which is which, and a user who wants\n // fire-and-forget writes it where it is visible:\n //\n // tui.hook(\"tui:boot\", () => { void backgroundSync() })\n\n /**\n * Gating hooks — the TUI WAITS for these, and they can fail the operation.\n *\n * Only lifecycle transitions with a real \"before\" qualify. A slow handler here\n * delays the terminal, so the runtime bounds it: exceeding the budget reports\n * `extension X is blocking <hook>` and continues. It never hangs silently, and\n * a config that stalls boot must always say so — an unexplained frozen terminal\n * is the worst failure this feature can produce.\n */\n type TuiGateHooks = {\n /** Before the TUI becomes interactive. Registration is done; the screen is not up. */\n \"tui:boot\": () => void | Promise<void>\n /** Before shutdown proceeds. The last point at which anything can be flushed to disk. */\n \"tui:shutdown\": () => void | Promise<void>\n }\n\n /**\n * Notification hooks — announcements of something that ALREADY happened.\n *\n * Handlers return void: nothing waits, and nothing they do can alter the event.\n * That is enforced by the signature rather than documented, so the question\n * \"does the TUI block on this?\" is answered by the type instead of by reading\n * the runtime. A handler needing async work owns it (`void doThing()`), which\n * keeps the fire-and-forget visible at the call site.\n */\n type TuiNotifyHooks = {\n /** The TUI is live and interactive. */\n \"tui:ready\": () => void\n\n /**\n * The config was reloaded — `:reload`, or a file change.\n *\n * Fires on the NEW generation, after every registration is in place. The\n * old generation is already disposed and never sees it: its handlers went\n * with everything else it registered.\n *\n * Distinct from `tui:boot`, which also runs on a reload but gates it. Use\n * boot for setup that must finish first; use this to react to having been\n * reloaded — refreshing a cached palette, re-reading a file on disk.\n */\n \"tui:reloaded\": () => void\n\n /** An instance finished booting. */\n \"agent:ready\": (instance: AgentInstance) => void\n /** An instance shut down. */\n \"agent:stopped\": (instance: AgentInstance) => void\n /** A different instance came on screen. */\n \"agent:focused\": (instance: AgentInstance) => void\n\n /** The user sent a message. Fires once it is delivered. */\n \"message:sent\": (payload: { content: string; instance: AgentInstance }) => void\n /**\n * The agent finished a wake.\n *\n * Carries no content on purpose. A payload with the model's reply would\n * reopen the consumption boundary through the back door — an extension\n * reacting to WHAT was said is writing an agent, which is a cognet's job.\n * This says only THAT a wake completed.\n */\n \"message:received\": (payload: { instance: AgentInstance }) => void\n\n /** The active mode changed. */\n \"mode:changed\": (payload: { from: ModeName; to: ModeName }) => void\n }\n\n /** Every lifecycle hook, gating and notifying. */\n type TuiHooks = TuiGateHooks & TuiNotifyHooks\n\n type TuiHookName = keyof TuiHooks\n\n /**\n * A plugin file under `plugins/`.\n *\n * Plugins need no wrapper and no default export — `tui.hook(...)` at module\n * scope is the whole API, exactly as `main.ts` registers commands at module\n * scope. The file is hooks by convention rather than by ceremony, and there is\n * one way to reach every verb from every file in a profile.\n *\n * What separates a plugin from `setup()` is TIME, not capability: setup runs at\n * load, before anything is on screen, and is where registration belongs —\n * registering a command from a live hook would flicker it into a palette the\n * user is already looking at.\n *\n * A throwing handler disables its extension with a visible error. It never\n * takes the TUI down, and it is never silently swallowed.\n */\n type PluginModule = void\n\n // ── Extensions ───────────────────────────────────────────────────────────────\n\n /**\n * An extension's `extension.config.ts`.\n *\n * ── An extension is a profile, packaged ──────────────────────────────────────\n *\n * There is no `setup()`. An extension's behaviour lives in its `main.ts` and\n * its `plugins/`, registered at module scope, exactly as a user's own profile\n * does — same files, same globals, same moment. That symmetry is the point: a\n * user who has written a `main.ts` can publish it, and a reader who knows one\n * layout knows both.\n *\n * A `setup()` wrapper would have made the two differ for no gain. It exists on\n * `defineModule` because a module has data the loader must read WITHOUT\n * executing it — an options schema to validate, `emits` for typegen to merge,\n * env and policy requirements, sub-modules to flatten at manifest time. An\n * extension has none of that: its identity is package.json, and its behaviour\n * is registration.\n *\n * ── Then why does this file exist? ───────────────────────────────────────────\n *\n * It marks the directory as an extension. A kind is identified by its config\n * file (see detectKind), and `main.ts` cannot be that marker — a profile has\n * one, and so does half of npm.\n *\n * It is deliberately empty today. Keeping it means declarative, inspectable\n * per-extension data has somewhere to land later without a breaking change —\n * options schemas being the obvious candidate, if third-party configuration\n * ever needs a validated boundary rather than a user editing TypeScript.\n */\n type ExtensionConfig = {\n /**\n * Reserved. An extension declares nothing here yet — identity lives in\n * package.json and behaviour lives in main.ts.\n */\n readonly _reserved?: never\n }\n\n /** What `defineExtension()` returns. */\n type ExtensionDefinition = {\n _kind: \"extension\"\n config: ExtensionConfig\n }\n\n // ── Profile ──────────────────────────────────────────────────────────────────\n\n /**\n * One entry in `profile.config.ts`'s `extensions`.\n *\n * `\"@axon/vim\"` resolves from the registry and installs into the profile\n * frame; `\"./extensions/sketch\"` is a local directory. The object form lets an\n * extension be disabled without deleting its line — which is what makes this\n * editable by machine, the reason the enabled set is declared here rather than\n * being the side-effect of running code.\n */\n type ExtensionEntry =\n | string\n | {\n /** Registry specifier or local path. */\n source: string\n /** Default true. False keeps the entry but does not load it. */\n enabled?: boolean\n }\n\n /**\n * A user's `profile.config.ts` — what is ENABLED, declaratively.\n *\n * Declarative rather than imperative registration calls specifically so it can\n * be edited by machine: installing an extension from Fleet or the CLI is a data\n * edit to this array, which is not possible when the enabled set is the\n * side-effect of running arbitrary code.\n *\n * Behaviour lives in `main.ts`; this file only says what loads.\n */\n type ProfileConfig = {\n extensions?: ExtensionEntry[]\n }\n\n /** What `defineProfile()` returns. */\n type ProfileDefinition = {\n _kind: \"profile\"\n config: ProfileConfig\n }"