@arcforge/types 2.0.144 → 2.0.145
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 +1 -1
- package/src/blueprint.ts +23 -0
- package/src/cognet/cognet.ts +14 -1
- package/src/engine.ts +31 -5
- package/src/handle.ts +26 -0
- package/src/index.ts +1 -0
- package/src/policy-resolve.ts +159 -0
- package/src/policy.ts +37 -0
- package/src/session/events/entries.ts +43 -2
- package/src/tui-contract.ts +1 -1
- package/src/tui.ts +108 -19
package/package.json
CHANGED
package/src/blueprint.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AxonConfig } from "./config"
|
|
2
|
+
import type { CapsulePartialConfig } from "./capsule-config"
|
|
2
3
|
import { CognetBlueprint } from "./cognet/blueprint"
|
|
3
4
|
import { AxonPlugin } from "./plugin"
|
|
4
5
|
import { AxonRoute } from "./route"
|
|
@@ -53,6 +54,27 @@ export type AxonBlueprint = {
|
|
|
53
54
|
/** resolved axon.config.ts — engine, policy, environment. no raw process.env reads at runtime. */
|
|
54
55
|
config: AxonConfig
|
|
55
56
|
|
|
57
|
+
/**
|
|
58
|
+
* The machine-wide policy CEILING, from the profile that owns this agent.
|
|
59
|
+
*
|
|
60
|
+
* Kept beside `config.policy` rather than merged into it, deliberately.
|
|
61
|
+
* The two layers stay distinct all the way to enforcement so a denial can
|
|
62
|
+
* name which one produced it — merged, a user reading "denied" would have
|
|
63
|
+
* no way to tell whether to edit their agent or their profile, and
|
|
64
|
+
* removing the agent rule would silently change nothing.
|
|
65
|
+
*
|
|
66
|
+
* Resolved at LOAD, never baked in at prepare: a blueprint travels (it is
|
|
67
|
+
* what `axon deploy` ships), and a deployed agent runs on a machine with
|
|
68
|
+
* no profile. Baking the ceiling in would carry one machine's rules to
|
|
69
|
+
* another, where they describe a filesystem and a threat model that do not
|
|
70
|
+
* exist there.
|
|
71
|
+
*
|
|
72
|
+
* Absent means no ceiling — every capability falls through to the agent's
|
|
73
|
+
* own policy. That is the case for a deployment, for `axon run` outside a
|
|
74
|
+
* profile, and for a profile that simply declares none.
|
|
75
|
+
*/
|
|
76
|
+
profilePolicy?: CapsulePartialConfig["policy"]
|
|
77
|
+
|
|
56
78
|
/**
|
|
57
79
|
* The brain. REQUIRED and never defaulted: an agent without a brain is
|
|
58
80
|
* not an agent — normalization fails loudly when it's missing. The CLI
|
|
@@ -110,6 +132,7 @@ export type AxonPartialBlueprint = {
|
|
|
110
132
|
boot?: string
|
|
111
133
|
bootFilePath?: string
|
|
112
134
|
config?: AxonBlueprint["config"]
|
|
135
|
+
profilePolicy?: AxonBlueprint["profilePolicy"]
|
|
113
136
|
cognet?: CognetBlueprint
|
|
114
137
|
env?: AxonBlueprint["env"]
|
|
115
138
|
tools?: AxonBlueprint["tools"]
|
package/src/cognet/cognet.ts
CHANGED
|
@@ -57,7 +57,20 @@ export type CognetConfig = {
|
|
|
57
57
|
/** Default wake mask — overridable by the blueprint's wakeOn. Absent = wake on everything. */
|
|
58
58
|
wakeOn?: Array<keyof AxonEntryEvent>
|
|
59
59
|
|
|
60
|
-
/**
|
|
60
|
+
/**
|
|
61
|
+
* Hard safety bound for one wake. Omitted means UNBOUNDED, which is the
|
|
62
|
+
* default and the right one for most cognets.
|
|
63
|
+
*
|
|
64
|
+
* A ceiling cannot distinguish a runaway loop from a long job — the only
|
|
65
|
+
* difference is whether the ticks accomplish anything, which a count
|
|
66
|
+
* cannot see. Zero capped this at 32 and killed a run mid-verification
|
|
67
|
+
* after forty clean turns of real work.
|
|
68
|
+
*
|
|
69
|
+
* Set it only where a wake is genuinely expected to converge in a known
|
|
70
|
+
* number of steps (a classifier, a fixed pipeline), so exceeding it really
|
|
71
|
+
* is a bug. For open-ended work, what bounds a wake is `<done/>`, the
|
|
72
|
+
* user's interrupt, and the engine failing loudly.
|
|
73
|
+
*/
|
|
61
74
|
maxTicksPerWake?: number
|
|
62
75
|
|
|
63
76
|
/**
|
package/src/engine.ts
CHANGED
|
@@ -24,12 +24,15 @@ export type EngineConfig = AxonEngineDef | EngineRef
|
|
|
24
24
|
* workspace writes, what a model pick in the TUI serializes, and the form
|
|
25
25
|
* the product contract promises: swap the reference, zero code changes.
|
|
26
26
|
*/
|
|
27
|
+
/** Requested reasoning effort. Unsupported engines accept and ignore it. */
|
|
28
|
+
export type EngineEffort = "low" | "medium" | "high" | "xhigh"
|
|
29
|
+
|
|
27
30
|
export type EngineRef =
|
|
28
|
-
| { provider: "axon"; model?: string; optimize?: EngineAutoWeights; limit?: EngineAutoLimits }
|
|
29
|
-
| { provider: "openrouter"; model: string }
|
|
30
|
-
| { provider: "codex"; model?: string }
|
|
31
|
-
| { provider: "ollama"; model: string }
|
|
32
|
-
| { provider: "mock" }
|
|
31
|
+
| { provider: "axon"; model?: string; effort?: EngineEffort; optimize?: EngineAutoWeights; limit?: EngineAutoLimits }
|
|
32
|
+
| { provider: "openrouter"; model: string; effort?: EngineEffort }
|
|
33
|
+
| { provider: "codex"; model?: string; effort?: EngineEffort }
|
|
34
|
+
| { provider: "ollama"; model: string; effort?: EngineEffort }
|
|
35
|
+
| { provider: "mock"; effort?: EngineEffort }
|
|
33
36
|
|
|
34
37
|
/**
|
|
35
38
|
* Axon({ model: "auto" }) weighting — resolved server-side against a
|
|
@@ -57,6 +60,8 @@ export type AxonEngineDef = {
|
|
|
57
60
|
* resolves server-side, per call; a client showing it should say so.
|
|
58
61
|
*/
|
|
59
62
|
model?: string
|
|
63
|
+
/** Requested reasoning effort, if configured. Unsupported providers ignore it. */
|
|
64
|
+
effort?: EngineEffort
|
|
60
65
|
/**
|
|
61
66
|
* Auto-selection weighting, when the constructor was given it. Only
|
|
62
67
|
* meaningful alongside model: "auto".
|
|
@@ -219,6 +224,27 @@ export type AxonEngineCall = AxonEngineRequest & {
|
|
|
219
224
|
}
|
|
220
225
|
/** Attempts after a response fails `output`. Ignored without one. Default 2. */
|
|
221
226
|
retries?: number
|
|
227
|
+
/**
|
|
228
|
+
* Re-render the request from the session, for a retry.
|
|
229
|
+
*
|
|
230
|
+
* A retry has to show the model its own rejected reply and the correction
|
|
231
|
+
* it earned, and those are session ENTRIES — so the only honest way to put
|
|
232
|
+
* them in front of the model is to render the document again now that they
|
|
233
|
+
* exist. Appending the correction to the finished messages instead put a
|
|
234
|
+
* `<system>` block AFTER `</timeline>`, outside every structure the
|
|
235
|
+
* context had just taught, in the highest-attention position on the wire.
|
|
236
|
+
* A model shown a floating block immediately before being told not to emit
|
|
237
|
+
* floating blocks does the obvious thing.
|
|
238
|
+
*
|
|
239
|
+
* Supplied by the caller because rendering belongs to cognition: the
|
|
240
|
+
* engine owns the retry budget and knows a reply failed, but has no view
|
|
241
|
+
* of a timeline and must not grow one.
|
|
242
|
+
*
|
|
243
|
+
* Optional — a caller that renders nothing (an internal one-shot) has no
|
|
244
|
+
* document to re-render, and the engine falls back to reusing the
|
|
245
|
+
* messages it was given.
|
|
246
|
+
*/
|
|
247
|
+
rerender?(): Promise<AxonEngineMessage[]>
|
|
222
248
|
}
|
|
223
249
|
|
|
224
250
|
/**
|
package/src/handle.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { EscalationCall } from "./policy"
|
|
1
2
|
import type { AxonEntry, AxonKernelEvent, AxonSessionEvent, AxonStimulusEvent, AxonStimulusType } from "./session"
|
|
2
3
|
import type { AxonOutputEvent } from "./session/events/stdio/output"
|
|
3
4
|
import type { AxonScript } from "./scripts"
|
|
@@ -23,6 +24,16 @@ import type { AxonAmbient } from "./session/events/activity"
|
|
|
23
24
|
export type AxonRequestInput = {
|
|
24
25
|
/** One stimulus, or an ordered batch committed before a single wake. */
|
|
25
26
|
prompt: string | string[]
|
|
27
|
+
/**
|
|
28
|
+
* The surface this message arrived on — and the address a reply goes back
|
|
29
|
+
* to. `terminal`, `axon-cli`, `telegram:8199237521`.
|
|
30
|
+
*
|
|
31
|
+
* Supplied by the host, because the runtime cannot know which surface it
|
|
32
|
+
* is embedded in. A channel module reaching the agent names its own line
|
|
33
|
+
* the same way, which is what lets the agent answer on the line it was
|
|
34
|
+
* asked. Defaults to `terminal`.
|
|
35
|
+
*/
|
|
36
|
+
channel?: string
|
|
26
37
|
/**
|
|
27
38
|
* The shape this response must have, as a TypeScript type.
|
|
28
39
|
*
|
|
@@ -102,6 +113,21 @@ export type AxonHost = {
|
|
|
102
113
|
}): Promise<unknown>
|
|
103
114
|
}
|
|
104
115
|
|
|
116
|
+
/**
|
|
117
|
+
* The platform's answer to a capsule's "may I?".
|
|
118
|
+
*
|
|
119
|
+
* Deliberately NOT a method on AxonHost. That is the GUEST-facing channel —
|
|
120
|
+
* sandboxed code calls through it — and a guest able to invoke the policy
|
|
121
|
+
* decider could raise its own escalations, or answer them. This is host-side
|
|
122
|
+
* code asking host-side code, on the trusted side of the same boundary the
|
|
123
|
+
* mediator enforces.
|
|
124
|
+
*
|
|
125
|
+
* Absent means no decider, which the capsule already treats as deny. That is
|
|
126
|
+
* the honest state for a headless run and for any embedder that never wired
|
|
127
|
+
* one.
|
|
128
|
+
*/
|
|
129
|
+
export type AxonEscalate = (call: EscalationCall) => Promise<boolean>
|
|
130
|
+
|
|
105
131
|
export type EngineDelegate = {
|
|
106
132
|
/** Tool execution target. Absent/undefined = no capsule attached; capsule RPCs reject loudly. */
|
|
107
133
|
capsule?: () => CapsuleDelegate | undefined
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import type { CapsulePolicy, PolicyRule, PolicyVerdictSource } from "./policy"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Resolving two policy layers into one verdict — the ceiling model.
|
|
5
|
+
*
|
|
6
|
+
* A PROFILE policy bounds every agent on the machine; an AGENT policy narrows
|
|
7
|
+
* within it. "No internet, no shell" set once at the profile is then true of
|
|
8
|
+
* every agent, and an agent can only ever tighten — which is the property that
|
|
9
|
+
* makes a profile worth setting at all.
|
|
10
|
+
*
|
|
11
|
+
* Lives here, in types, because three consumers must resolve identically: the
|
|
12
|
+
* kernel (enforcement), the CLI (`axon policy`), and Fleet (the policy view).
|
|
13
|
+
* A second implementation would drift on exactly the cases that matter.
|
|
14
|
+
*
|
|
15
|
+
* ── Verdicts intersect; globs do NOT merge ──────────────────────────────────
|
|
16
|
+
*
|
|
17
|
+
* Each layer is evaluated INDEPENDENTLY against the subject, then the stricter
|
|
18
|
+
* verdict wins. Merging the rule objects would be wrong in a way that quietly
|
|
19
|
+
* grants capability: profile `allow: ["git *"]` unioned with agent
|
|
20
|
+
* `allow: ["git push*"]` produces a rule permitting both, when the profile
|
|
21
|
+
* never permitted `git push` on its own. Evaluating separately makes widening
|
|
22
|
+
* impossible by construction rather than by careful glob authorship.
|
|
23
|
+
*
|
|
24
|
+
* ── Silence is "no opinion", not "deny" ─────────────────────────────────────
|
|
25
|
+
*
|
|
26
|
+
* The mediator's own default is deny-by-omission — correct for a sandbox
|
|
27
|
+
* holding foreign code. This is the opposite: a profile that declares one tool
|
|
28
|
+
* rule must not thereby deny every other tool on the machine, or adding a
|
|
29
|
+
* single line to a profile would break every agent on it. So an undeclared
|
|
30
|
+
* capability falls through to the other layer, and only DECLARED rules
|
|
31
|
+
* intersect.
|
|
32
|
+
*
|
|
33
|
+
* The two defaults sit inches apart and mean opposite things. That is
|
|
34
|
+
* deliberate, and it is the thing to re-read before changing either.
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
/** How strict a verdict is. Higher wins when two layers disagree. */
|
|
38
|
+
const RANK = { allow: 0, escalate: 1, deny: 2 } as const
|
|
39
|
+
|
|
40
|
+
export type PolicyVerdict = "allow" | "deny" | "escalate"
|
|
41
|
+
|
|
42
|
+
/** A verdict plus what produced it, for a surface that has to explain itself. */
|
|
43
|
+
export type ResolvedVerdict = {
|
|
44
|
+
verdict: PolicyVerdict
|
|
45
|
+
/** Absent when no layer declared a rule — the caller applies its own default. */
|
|
46
|
+
source?: PolicyVerdictSource
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Minimal glob matcher — `*` (any chars, no `/`), `**` (any chars including
|
|
51
|
+
* `/`), everything else literal.
|
|
52
|
+
*
|
|
53
|
+
* Duplicated from the capsule's own matcher on purpose: this package must not
|
|
54
|
+
* import from a runtime package (it is the contract every one of them depends
|
|
55
|
+
* on), and policy globs are a handful of characters rather than a library. The
|
|
56
|
+
* two are asserted equivalent by the resolver's tests — if either grows, that
|
|
57
|
+
* is the moment to promote one into a shared leaf.
|
|
58
|
+
*/
|
|
59
|
+
export function policyGlobMatch(pattern: string, value: string): boolean {
|
|
60
|
+
// Built by SCANNING rather than by chained replaces.
|
|
61
|
+
//
|
|
62
|
+
// The chained form used a space as its `**` placeholder and then rewrote
|
|
63
|
+
// every space to `.*` — including the literal spaces the user typed. So
|
|
64
|
+
// `allow: ["bun run *"]` compiled to `bun.*run.*[^/]*` and permitted
|
|
65
|
+
// `bun-run-anything`: an allowlist granting far more than it named, which
|
|
66
|
+
// is the exact failure a policy matcher must not have. Scanning has no
|
|
67
|
+
// placeholder to collide with.
|
|
68
|
+
let source = ""
|
|
69
|
+
for (let i = 0; i < pattern.length; i++) {
|
|
70
|
+
if (pattern[i] === "*") {
|
|
71
|
+
if (pattern[i + 1] === "*") {
|
|
72
|
+
source += ".*"
|
|
73
|
+
i++
|
|
74
|
+
} else {
|
|
75
|
+
source += "[^/]*"
|
|
76
|
+
}
|
|
77
|
+
continue
|
|
78
|
+
}
|
|
79
|
+
// Everything else is literal, including spaces.
|
|
80
|
+
source += pattern[i]!.replace(/[.+^${}()|[\]\\?*]/g, "\\$&")
|
|
81
|
+
}
|
|
82
|
+
return new RegExp(`^${source}$`).test(value)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Evaluate ONE layer's rule against a subject.
|
|
87
|
+
*
|
|
88
|
+
* Returns undefined when the layer declared nothing — distinct from a rule
|
|
89
|
+
* that declared something and matched nothing, which is a deny.
|
|
90
|
+
*
|
|
91
|
+
* Precedence inside a glob rule is deny → escalate → allow, matching the
|
|
92
|
+
* capsule mediator exactly: the strictest matching clause wins regardless of
|
|
93
|
+
* authoring order, so a user cannot accidentally out-order their own denial.
|
|
94
|
+
*/
|
|
95
|
+
export function evaluateRule(
|
|
96
|
+
rule: PolicyRule | undefined,
|
|
97
|
+
subject: string,
|
|
98
|
+
layer: PolicyVerdictSource["layer"],
|
|
99
|
+
): ResolvedVerdict | undefined {
|
|
100
|
+
if (rule === undefined) return undefined
|
|
101
|
+
|
|
102
|
+
if (rule === true) return { verdict: "allow", source: { layer, subject, rule } }
|
|
103
|
+
if (rule === false) return { verdict: "deny", source: { layer, subject, rule } }
|
|
104
|
+
if (rule === "escalate") return { verdict: "escalate", source: { layer, subject, rule } }
|
|
105
|
+
|
|
106
|
+
const denied = rule.deny?.find(pattern => policyGlobMatch(pattern, subject))
|
|
107
|
+
if (denied !== undefined) return { verdict: "deny", source: { layer, subject, pattern: denied, rule } }
|
|
108
|
+
|
|
109
|
+
const escalated = rule.escalate?.find(pattern => policyGlobMatch(pattern, subject))
|
|
110
|
+
if (escalated !== undefined) return { verdict: "escalate", source: { layer, subject, pattern: escalated, rule } }
|
|
111
|
+
|
|
112
|
+
const allowed = rule.allow?.find(pattern => policyGlobMatch(pattern, subject))
|
|
113
|
+
if (allowed !== undefined) return { verdict: "allow", source: { layer, subject, pattern: allowed, rule } }
|
|
114
|
+
|
|
115
|
+
// Declared, matched nothing. A glob rule is an allowlist: naming what is
|
|
116
|
+
// permitted and hitting none of it is a denial, not silence.
|
|
117
|
+
return { verdict: "deny", source: { layer, subject, rule } }
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* The effective verdict for one subject under both layers.
|
|
122
|
+
*
|
|
123
|
+
* The stricter of the two wins, and the returned `source` is the layer that
|
|
124
|
+
* PRODUCED that verdict — so a denial can always name who denied it. When both
|
|
125
|
+
* agree, the profile is reported: it is the binding constraint, and telling a
|
|
126
|
+
* user their agent denied something their profile also denies sends them to
|
|
127
|
+
* the wrong file.
|
|
128
|
+
*/
|
|
129
|
+
export function resolveVerdict(
|
|
130
|
+
profileRule: PolicyRule | undefined,
|
|
131
|
+
agentRule: PolicyRule | undefined,
|
|
132
|
+
subject: string,
|
|
133
|
+
): ResolvedVerdict {
|
|
134
|
+
const profile = evaluateRule(profileRule, subject, "profile")
|
|
135
|
+
const agent = evaluateRule(agentRule, subject, "agent")
|
|
136
|
+
|
|
137
|
+
if (!profile && !agent) return { verdict: "allow" }
|
|
138
|
+
if (!profile) return agent!
|
|
139
|
+
if (!agent) return profile
|
|
140
|
+
|
|
141
|
+
// Ties go to the profile — see above.
|
|
142
|
+
return RANK[agent.verdict] > RANK[profile.verdict] ? agent : profile
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Isolation is a TIER, not a rule, so it intersects as a maximum rather than
|
|
147
|
+
* through the verdict ranking: a profile asking for `hardened` cannot be
|
|
148
|
+
* loosened to `none` by an agent, but an agent may harden beyond its profile.
|
|
149
|
+
*/
|
|
150
|
+
const ISOLATION_RANK = { none: 0, auto: 1, hardened: 2 } as const
|
|
151
|
+
|
|
152
|
+
export function resolveIsolation(
|
|
153
|
+
profile: CapsulePolicy["isolation"],
|
|
154
|
+
agent: CapsulePolicy["isolation"],
|
|
155
|
+
): CapsulePolicy["isolation"] | undefined {
|
|
156
|
+
if (profile === undefined) return agent
|
|
157
|
+
if (agent === undefined) return profile
|
|
158
|
+
return ISOLATION_RANK[agent] > ISOLATION_RANK[profile] ? agent : profile
|
|
159
|
+
}
|
package/src/policy.ts
CHANGED
|
@@ -111,6 +111,43 @@ export type CapsulePolicy = {
|
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
|
|
114
|
+
/**
|
|
115
|
+
* Which layer produced a verdict.
|
|
116
|
+
*
|
|
117
|
+
* The ceiling model resolves two independently-authored policies, and a user
|
|
118
|
+
* reading a denial has to know WHICH said no — a profile denying `**\/secrets/**`
|
|
119
|
+
* while an agent allows `./data/**` denies `data/secrets/key`, and without the
|
|
120
|
+
* source that reads as the agent's own rule misbehaving.
|
|
121
|
+
*
|
|
122
|
+
* "grant" is a standing approval satisfying an escalation that would otherwise
|
|
123
|
+
* have prompted. Reported so an allow that came from a remembered decision is
|
|
124
|
+
* distinguishable from one the policy always permitted — the two look identical
|
|
125
|
+
* at the call site and mean very different things to someone auditing.
|
|
126
|
+
*/
|
|
127
|
+
export type PolicyLayer = "profile" | "agent" | "grant"
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Why an operation was denied or escalated — structured, never a string.
|
|
131
|
+
*
|
|
132
|
+
* This replaced `rule: String(rule)`, which stringified the object form to
|
|
133
|
+
* "[object Object]": the one case that carries the actual patterns was the one
|
|
134
|
+
* case that reported nothing. Every surface that has to explain a decision
|
|
135
|
+
* (the timeline, an escalation prompt, Fleet's policy view) reads this.
|
|
136
|
+
*/
|
|
137
|
+
export type PolicyVerdictSource = {
|
|
138
|
+
/** Which policy layer decided. */
|
|
139
|
+
layer: PolicyLayer
|
|
140
|
+
/** The subject matched against — a command, host, or tool namespace. */
|
|
141
|
+
subject: string
|
|
142
|
+
/**
|
|
143
|
+
* The specific pattern that matched, when the rule was glob-shaped.
|
|
144
|
+
* Absent for a bare `true`/`false`/`"escalate"`, which has no pattern.
|
|
145
|
+
*/
|
|
146
|
+
pattern?: string
|
|
147
|
+
/** The rule as authored, for a surface that wants to show it verbatim. */
|
|
148
|
+
rule: PolicyRule
|
|
149
|
+
}
|
|
150
|
+
|
|
114
151
|
/** Command sent back to the capsule to allow or deny a pending escalation. */
|
|
115
152
|
export type PolicyResponseCommand = {
|
|
116
153
|
id: string
|
|
@@ -16,7 +16,7 @@ import type { AxonOutputEvent } from "./stdio/output"
|
|
|
16
16
|
*
|
|
17
17
|
* Four families:
|
|
18
18
|
* - stimulus:* — exteroception: the world reaching the agent (stdio/stimuli.ts).
|
|
19
|
-
* A
|
|
19
|
+
* A terminal message is cognet:stimulus:text on channel "terminal".
|
|
20
20
|
* - output:* — effectorception: the cognet reaching the world, unmediated
|
|
21
21
|
* (stdio/output.ts). Committed exclusively by kernel.output()
|
|
22
22
|
* — the cognet never calls session.commit directly; it has
|
|
@@ -26,6 +26,10 @@ import type { AxonOutputEvent } from "./stdio/output"
|
|
|
26
26
|
* implementation, the moment the capsule's own
|
|
27
27
|
* cmd:complete/cmd:failed lands — same pattern as
|
|
28
28
|
* capsule:attach/detach, never something cognet code writes.
|
|
29
|
+
* - agent:* — the agent's own control signals, as opposed to what it
|
|
30
|
+
* emitted to the world. `axon:agent:done` is the turn it
|
|
31
|
+
* declared over; it reaches nobody outside the runtime, but
|
|
32
|
+
* it is part of the record the model reads back.
|
|
29
33
|
* - the rest — interoception: machine-body facts (interrupts).
|
|
30
34
|
*/
|
|
31
35
|
/**
|
|
@@ -34,7 +38,7 @@ import type { AxonOutputEvent } from "./stdio/output"
|
|
|
34
38
|
* renderers) derives from THIS list, never from its own prefix sniff: a new
|
|
35
39
|
* family added to AxonEntryEvent must be added here in the same change.
|
|
36
40
|
*/
|
|
37
|
-
export const ENTRY_EVENT_PREFIXES = ["cognet:stimulus:", "cognet:output:", "cognet:action:", "axon:interrupt", "axon:system:"] as const
|
|
41
|
+
export const ENTRY_EVENT_PREFIXES = ["cognet:stimulus:", "cognet:output:", "cognet:action:", "axon:interrupt", "axon:system:", "axon:agent:"] as const
|
|
38
42
|
|
|
39
43
|
export type AxonEntryEvent = AxonStimulusEvent & AxonOutputEvent & {
|
|
40
44
|
/** Kernel signal record — an interrupt is machinery, never a stimulus. */
|
|
@@ -63,4 +67,41 @@ export type AxonEntryEvent = AxonStimulusEvent & AxonOutputEvent & {
|
|
|
63
67
|
/** Additional trusted AIR attributes. `type` and `lang` are reserved. */
|
|
64
68
|
attributes?: Record<string, string>
|
|
65
69
|
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* A reply that broke the output contract, kept verbatim.
|
|
73
|
+
*
|
|
74
|
+
* The correction alone was a scolding with no referent: the malformed
|
|
75
|
+
* text never entered the log, so the next turn showed the model a
|
|
76
|
+
* complaint about output it could no longer see. It cannot fix a shape
|
|
77
|
+
* it is not looking at, and runs were observed repeating the same
|
|
78
|
+
* violation immediately after being corrected for it.
|
|
79
|
+
*
|
|
80
|
+
* Stored raw and uninterpreted — the parser already failed on it, so any
|
|
81
|
+
* structure claimed here would be a guess. It renders as the agent turn
|
|
82
|
+
* it was, directly above the correction it earned.
|
|
83
|
+
*/
|
|
84
|
+
/**
|
|
85
|
+
* The model declared its turn over.
|
|
86
|
+
*
|
|
87
|
+
* Committed so the model can SEE its own turn endings. `<done/>` was
|
|
88
|
+
* parsed as a signal and dropped, which made it the one block whose
|
|
89
|
+
* correct use matters most and the only one absent from the model's own
|
|
90
|
+
* record — it read the rule in the contract and never once saw itself
|
|
91
|
+
* having followed it. Over a long run that is the block with the least
|
|
92
|
+
* in-context reinforcement and the most consequence when it goes wrong.
|
|
93
|
+
*
|
|
94
|
+
* Carries no payload: the fact IS the event. A turn either ended here or
|
|
95
|
+
* it did not.
|
|
96
|
+
*/
|
|
97
|
+
"axon:agent:done": Record<string, never>
|
|
98
|
+
|
|
99
|
+
"axon:system:malformed": {
|
|
100
|
+
/** The model's output exactly as it came off the wire. */
|
|
101
|
+
content: string
|
|
102
|
+
/** The violation code this reply produced, matching the paired fault. */
|
|
103
|
+
code: string
|
|
104
|
+
/** Which engine attempt this was — 1-based, so a reader can see the sequence. */
|
|
105
|
+
attempt: number
|
|
106
|
+
}
|
|
66
107
|
}
|
package/src/tui-contract.ts
CHANGED
|
@@ -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 /**\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: CommandName | 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\" | \"reconnecting\" | \"disconnected\" | 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 // ── lines ───────────────────────────────────────────────────────────────────\n\n /**\n * One live value on a line — a name, when it changes, and what it says.\n *\n * THE TRIGGER IS DECLARED, and that is the whole design. A bare `() => string`\n * would leave the terminal with no idea when to call it: re-running every\n * component on every frame makes one slow component stall the paint, and the\n * alternative — asking users to wire their own reactivity — is the thing this\n * API exists to avoid. So a component states what wakes it and the renderer\n * evaluates it then and never otherwise.\n *\n * `render` is SYNCHRONOUS by contract. A frame cannot await, and a component\n * that needs real work (a git branch, a network call) does that work in its\n * trigger and returns the cached value here — the same discipline lualine\n * settles on, arrived at from the render loop rather than from convention.\n *\n * A component with neither `on` nor `every` renders once and stays put, which\n * is the right shape for something static.\n */\n type LineComponent = {\n /**\n * A glyph shown before the value — a NAME from the catalogue, or a literal.\n *\n * A NAME resolves through the active icon set, so one setting swaps every\n * icon at once — which is what makes a shared component work on a machine\n * without a patched font. A literal glyph is the escape hatch for\n * something the catalogue does not name, and it does NOT respond to the\n * setting: an author writing a raw character has said they know what\n * appears.\n *\n * The author's, not the config's — an icon is part of what a component\n * MEANS (a git component without its branch glyph is a worse git\n * component), where colour is part of how a LINE looks and belongs to\n * whoever composes the row.\n *\n * Rendered only when the component has something to say: an icon beside an\n * empty value is a glyph floating on its own.\n */\n icon?: IconName | (string & {})\n /**\n * Hook events that change this value — the same names `tui.hook` takes.\n *\n * Reusing that vocabulary is deliberate: the terminal already emits a\n * precise event for everything it does, so a component author picks from a\n * list they have already learned rather than inventing a subscription.\n */\n on?: readonly TuiHookName[]\n /**\n * Re-render every N milliseconds — for values that change with time rather\n * than with anything the terminal does. A clock is the case; there is no\n * event for \"a second passed\".\n *\n * Taken as written, with no floor. Painting a string is cheap and the\n * renderer diffs frames for exactly this; a component doing heavy work on\n * a fast interval is the author's call, the same as a slow hook handler.\n */\n every?: number\n /**\n * Run when the user clicks this component.\n *\n * Named for what the AUTHOR does, not for the event vterm dispatches\n * (`@press`). A config says \"when this is clicked\"; the transport's name\n * for that is an implementation detail of the layer below.\n *\n * What turns a status line into a control surface: a row of agent names\n * becomes a nav bar, a branch indicator becomes a branch picker. Without\n * it a line can only report, and reporting is the smaller half of what a\n * bar sitting in front of you all day could do.\n *\n * Unawaited by the terminal — a handler that takes a second must not hold\n * the frame — and a failure is reported like any other config fault rather\n * than surfacing as a click that silently did nothing.\n */\n click?: () => void | Promise<void>\n /**\n * What to show, coerced to text.\n *\n * Primitives only, deliberately. `string` alone forced `String(count)` on\n * the most ordinary component there is; `unknown` would accept an object,\n * an array or a promise and render `[object Object]` silently — and an\n * author who slipped an `async` onto this would get `[object Promise]` on\n * their line with nothing to explain it. Widening removes ceremony, not\n * the errors the type was catching.\n *\n * `null`/`undefined` are the honest way to say \"nothing right now\", and\n * render as empty rather than as the text \"null\".\n */\n render: () => string | number | null | undefined\n }\n\n /**\n * A line's content — up to three slots, laid out by the terminal.\n *\n * Axon owns spacing, separators, truncation and colour; a config supplies text\n * and its order. That split is the product decision: every layout knob is a\n * way for two configs to disagree, and the failure mode it prevents is a\n * handful of beautiful setups surrounded by mediocre ones. Users theme,\n * Axon lays out.\n *\n * `left` and `right` push apart. `middle` centres on the LINE, not on the gap\n * between the sides, and truncates when there is no room — one rule, so a\n * three-slot line never needs a negotiation nobody can predict.\n */\n type LineContent = {\n left?: LineSlot\n middle?: LineSlot\n right?: LineSlot\n /**\n * The style this line was DESIGNED for — a default, not a decree.\n *\n * An author knows what their line is meant to look like, so declaring it\n * here means a shared line arrives looking right with no configuration.\n * But the placement wins: a user who wants it plain says so in\n * `lines.set()` and never has to fork the line to restyle it.\n *\n * Precedence, narrowest first: placement → this → `lines.style()`.\n */\n style?: LineStyle\n }\n\n /**\n * One slot's contents: a flat list of components, or a list of SECTIONS.\n *\n * A section is the unit a separator divides and a background fills — which is\n * why the nesting exists at all. Inside one section every component shares a\n * ground, so the divider between them is a hairline; between sections the\n * ground changes, so the divider is a filled arrow. That is the whole\n * distinction lualine draws with `component_separators` and\n * `section_separators`, and it cannot be expressed on a flat list.\n *\n * A flat array is one section. Nothing already written changes meaning.\n */\n type LineSlot = readonly ComponentName[] | readonly (readonly ComponentName[])[]\n\n /**\n * A component's name — the catalogue Axon ships, or one you registered.\n *\n * The built-ins are enumerated so an editor completes them and a typo is a\n * compile error rather than a gap you find on screen. `(string & {})` keeps\n * that completion while still accepting names this union cannot know: a\n * component from an extension, or one the same config declared a few lines up.\n *\n * The same shape `ThemeColor` uses, for the same reason — a closed union would\n * make the escape hatch impossible, and an open `string` would make the\n * catalogue undiscoverable.\n */\n type ComponentName = RegistryName<AxonComponentRegistry>\n\n /**\n * A generated registry's names — CLOSED once the registry has entries.\n *\n * ── Why this is not simply `keyof R | (string & {})` ────────────────────────\n *\n * That shape gives completion but never rejects anything: the open arm accepts\n * every string, so a typo typechecks and only fails at runtime — which is the\n * bug the generator exists to remove.\n *\n * An empty registry still has to accept anything, though. A profile before its\n * first `axon prepare` has no generated file, and every name in it would be an\n * error against a `never` union — a config that was fine yesterday would light\n * up red because a build step had not run yet.\n *\n * So the union closes only when it has something to close AROUND: empty means\n * open, populated means exact. A name the generator genuinely cannot see (one\n * computed at runtime) is cast at the call site, which is the honest signal\n * that it is unverifiable rather than a hole left open for every name.\n */\n type RegistryName<R> = keyof R extends never ? string : keyof R & string\n\n /**\n * Every line name known at generation time.\n *\n * Same mechanism as AxonComponentRegistry — see that interface for why these\n * are generated rather than written by hand.\n */\n type LineName = RegistryName<AxonLineRegistry>\n\n /**\n * Every palette name known at generation time.\n */\n type PaletteName = RegistryName<AxonPaletteRegistry>\n\n /**\n * Every command path known at generation time, space-joined.\n */\n type CommandName = RegistryName<AxonCommandRegistry>\n\n /**\n * The registries `axon prepare` fills in.\n *\n * ── Generated, not hand-written ─────────────────────────────────────────────\n *\n * These were a hand-maintained union of the built-in names, which drifted the\n * first time someone added a component and forgot to update it. The generator\n * reads the actual catalogue AND every config's own `create` calls, so what an\n * editor completes is what is really registered — including the component you\n * declared four lines above the line using it.\n *\n * ── Why an interface rather than a type alias ───────────────────────────────\n *\n * Declaration merging. A generated `.d.ts` reopens the interface and adds its\n * keys, which means built-ins, extension contributions and a user's own\n * registrations all land in one union with no privileged tier. An alias could\n * only be replaced, not extended, so every source would need its own name and\n * the consumer would have to union them by hand.\n *\n * Empty here by design: a profile with no generated types still typechecks,\n * because every consuming alias keeps a `(string & {})` arm.\n */\n // eslint-disable-next-line @typescript-eslint/no-empty-object-type\n interface AxonComponentRegistry {}\n // eslint-disable-next-line @typescript-eslint/no-empty-object-type\n interface AxonLineRegistry {}\n // eslint-disable-next-line @typescript-eslint/no-empty-object-type\n interface AxonPaletteRegistry {}\n // eslint-disable-next-line @typescript-eslint/no-empty-object-type\n interface AxonCommandRegistry {}\n\n /**\n * How a line draws its separators and shades its sections.\n *\n * A preset, never individual glyphs. Axon owning the glyph set is the line\n * between \"every config looks like Axon\" and \"everyone invents their own bar\"\n * — and a config that picked its own would be choosing a look that has to hold\n * against every theme, which is not a decision anyone should have to make\n * per row.\n *\n * Backgrounds step from the EDGE INWARD: the outermost section takes the\n * accent, each step inward is softer, and the innermost sits on the terminal's\n * own ground. Position in the array is the section, so there is no background\n * to configure — which is what stops two configs disagreeing about what a\n * status bar looks like.\n */\n type LineStyle =\n /** No glyphs. Components separated by spacing alone — the default. */\n | \"plain\"\n /** Filled arrows between sections, hairlines within. Needs a Nerd Font. */\n | \"powerline\"\n /** The same, with round caps. Needs a Nerd Font. */\n | \"rounded\"\n /**\n * Square edges: a flat boundary between fills and a vertical bar within.\n *\n * The same section model as `powerline`, without the arrow's implied\n * direction — which reads as calmer beside a busy conversation, and is\n * what you want when the bar should sit still rather than point at\n * something. Needs a Nerd Font.\n */\n | \"block\"\n /** A thin middle dot between components, no section fills. */\n | \"minimal\"\n\n /**\n * A line's definition: the full three-slot form, or a bare array.\n *\n * The array means LEFT, always — never auto-distributed. Both built-in lines\n * are left-aligned, so it is the common case worth a shorthand, and a rule\n * that reads the same every time beats one that guesses.\n */\n type LineDefinition = LineContent | readonly string[]\n\n /**\n * One entry in the stack: a name, or a name with placement overrides.\n *\n * The bare string is the common case and stays the common case — an object is\n * only needed when this particular placement differs from what the line\n * declared.\n */\n type LineEntry = LineName | LinePlacement\n\n /**\n * How ONE line is placed in ONE stack.\n *\n * ── Why placement owns style ────────────────────────────────────────────────\n *\n * Three layers, three owners: a COMPONENT is what the data is (an extension\n * author's), a LINE is what sits where (shared or personal), and a PLACEMENT\n * is how it looks in this stack (always the user's).\n *\n * Style began on the line and that was the wrong layer. A shared line would\n * ship with its look baked in, so anyone installing `@cody/git-line` had to\n * fork it to restyle — which is the coupling that stops a registry being\n * worth having. A line may still declare a default, because an author knows\n * what their line was designed to look like; the placement wins when it says\n * otherwise.\n *\n * Precedence, narrowest first: this placement → the line's own default →\n * `lines.style()`.\n */\n type LinePlacement = {\n /** The registered line this entry places. */\n line: LineName\n /** How it draws here, overriding the line's default and the stack's. */\n style?: LineStyle\n /**\n * Start hidden, keeping its place in the stack.\n *\n * Declared here rather than left to a `hide()` call afterwards, so the\n * stack is one description instead of a description plus a sequence of\n * mutations. `toggle()` still flips it at runtime.\n */\n hidden?: boolean\n }\n\n /**\n * Where a line moves to. `\"up\"`/`\"down\"` are relative; a number is an absolute\n * index in the stack, clamped rather than throwing — a keybind that walks a\n * line to the top should stop there, not fail on the last press.\n */\n type LinePosition = \"up\" | \"down\" | number\n\n /** A registered line, as `lines.list()` reports it. */\n type Line = {\n /**\n * Unique within the stack — the name is NOT an identity, since a line may\n * be placed more than once (comparing two styles side by side is a real\n * thing to want).\n */\n id: string\n name: string\n content: LineContent\n /** How it draws. Falls back to the stack default when the line declared none. */\n style: LineStyle\n /** False when hidden. A hidden line keeps its place in the stack. */\n visible: boolean\n }\n\n /**\n * Components — the live values a line can show.\n *\n * Axon ships a catalogue under the `axon:` prefix (`axon:token/counter` and\n * friends), and anything else registers here. The two are the same kind of\n * thing: a built-in is a component the terminal registered against its own\n * hooks, with no privilege a user's cannot have.\n *\n * Names are `provider:name` rather than a package specifier. A package ships\n * many things; a component comes from one provider — conflating the two would\n * make every component name read like an import path.\n */\n type ComponentsApi = {\n /**\n * Register a component. Throws if the name is taken. Returns a disposer.\n *\n * A `render` that throws costs that component and nothing else: it renders\n * empty and the fault is reported, the same containment the config loader\n * applies per file. One bad value must not take down the line around it.\n */\n create: (name: string, component: LineComponent) => Disposer\n\n /** Every registered component name, built-ins included. */\n list: () => readonly string[]\n }\n\n /**\n * Lines — the configurable rows above the input bar.\n *\n * The terminal ships two of its own and they stay its: the cwd/token row and\n * the voice row. A user's lines sit between them, which is the one layout\n * decision Axon does not delegate — the rows that must always be readable are\n * not ones a config can push off screen.\n *\n * Registration and placement are SEPARATE VERBS, and that is what makes the\n * surface extensible: an extension `create`s lines without deciding where they\n * go, and the user `set`s the stack without knowing who authored what.\n */\n type LinesApi = {\n /**\n * Register a line. Throws if the name is taken, or if it names a component\n * that does not exist — a config error the loader can contain, reported\n * where it can be fixed rather than rendered as a blank row.\n */\n create: (name: string, definition: LineDefinition) => Disposer\n\n /**\n * The default style for every line that does not declare one.\n *\n * A stack-wide setting because a bar with one powerline row among plain\n * ones reads as a mistake, not a choice — and because the common case is\n * wanting ALL of them to match. A line that genuinely differs still says so\n * itself, which is the rarer thing and reads as deliberate at the call site.\n *\n * Called with no argument, returns the current default.\n */\n style: {\n (style: LineStyle): void\n (): LineStyle\n }\n\n /**\n * The single line ABOVE the conversation, or null to clear it.\n *\n * One line, not a stack. The room above the conversation is scarce in a\n * way the room below it is not — the bottom already holds the input bar\n * and its own rows, so a stack there is bounded by something. A second\n * unbounded stack at the top could push the conversation off screen, and\n * the constraint costs nothing: nobody has wanted two.\n *\n * Takes the same placement object as `set`, so a top line styles itself\n * the same way any other does.\n */\n top: {\n /** Set it by name, with placement options. */\n (name: LineName, options?: Omit<LinePlacement, \"line\">): void\n /** Set it from a placement object, or clear it with null. */\n (entry: LineEntry | null): void\n /** Read what is currently set. */\n (): Line | null\n }\n\n /**\n * Set the whole stack, top to bottom. Declarative and idempotent: this is\n * the one place order lives, so reordering is calling it again.\n *\n * An entry is a bare name, or an object when this placement differs from\n * the line's own defaults — see LinePlacement. Registered lines left out\n * of the array are not shown; an unknown name is reported.\n */\n set: (entries: readonly LineEntry[]) => void\n\n /**\n * Move one line within the stack. Addressed by NAME, never by index —\n * an index shifts when anything above it moves, so a keybind written today\n * would quietly mean something else tomorrow.\n */\n move: (name: string, position: LinePosition) => void\n\n /** Hide a line. It keeps its place, so showing it again returns it there. */\n hide: (name: string) => void\n /** Show a hidden line, back where it was. */\n show: (name: string) => void\n /** Flip visibility — the verb a keybind wants. */\n toggle: (name: string) => void\n\n /** Every registered line, in stack order. What a picker palette reads. */\n list: () => readonly Line[]\n }\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 /** Trailing options for `tui.info` / `warn` / `error`. */\n type NoticeOptions = {\n /** How long the notice holds the row, in milliseconds. Clamped to a few seconds. */\n ms: number\n }\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\", { ms: 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 * Takes any number of values and joins them with a space, the way\n * `console.log` does — so a config building a label from several pieces\n * does not have to concatenate first. Non-strings are stringified;\n * objects and arrays go through JSON so a stray value reads as data\n * rather than as `[object Object]`.\n *\n * The 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 * Duration is a trailing `{ ms }` rather than a bare number, because\n * under variadic args a trailing number is DATA: `tui.info(\"saved\", 500)`\n * has to mean \"saved 500\", not \"show this for half a second\".\n *\n * tui.info(\"[\", keys.join(\" \"), \"]\")\n * tui.warn(\"nothing to do\", { ms: 600 })\n */\n info: (...args: unknown[]) => void\n\n /** As `info`, in the warning colour. */\n warn: (...args: unknown[]) => void\n\n /** As `info`, in the error colour. For \"that failed\" — never for why. */\n error: (...args: unknown[]) => 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 * `tui:copy` — the text that was copied.\n *\n * The text is CARRIED rather than left for the handler to read back off the\n * selection: copying does not clear the selection, but nothing stops the user\n * (or another handler) from clearing it before this one runs, and a handler\n * that re-read it would then see an empty string for a copy that plainly\n * happened. What is passed is exactly what reached the clipboard.\n *\n * Never empty — an empty selection copies nothing and fires nothing.\n */\n type TuiCopyPayload = {\n /** The copied text, verbatim: original line breaks, no trimming. */\n text: string\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 /**\n * Where the command sits in the command TREE, one segment per level —\n * `[\"ext\", \"update\"]`, `[\"theme\", \"set\", \"gruvbox\"]`.\n *\n * An array rather than a space-joined string because the segments are what\n * both call sites already hold (`[...breadcrumb, node.label]` in the\n * palette, `toPath(path)` in `commands.run()`) and what registration,\n * lookup and COMMAND_NOT_FOUND all use. The string was a lossy projection\n * at one boundary: `split(\" \")` is not its inverse once an argument\n * contains a space, so the commands most worth reacting to — a pasted key,\n * a path with spaces — were exactly the ones a handler mis-parsed.\n *\n * A list-backed group puts its chosen row here, not in `arg`: a theme name\n * is a NODE the palette listed, from a closed set, so `:theme set gruvbox`\n * is three segments. That makes every pick a distinct path, which is how a\n * handler knows WHICH theme — so match a namespace with `path[0]`, not a\n * whole-array compare.\n */\n path: string[]\n\n /**\n * The raw text typed after an input command, or undefined when the command\n * takes none — `\"/some/dir\"` for `:watch /some/dir`.\n *\n * Separate from `path` because it is a different KIND of thing: a segment\n * comes from a closed set and is matchable, an argument is arbitrary user\n * text. Folding it in would turn \"did watch run\" from an equality check\n * into a prefix test, and make every invocation its own path.\n *\n * ── The invariant this field rests on ───────────────────────────────────\n *\n * An input node TERMINATES traversal — `CommandInput` has no children, and\n * everything after it is taken as the argument verbatim, spaces included\n * (traverse.ts: `rawSegments.slice(i + 1).join(\" \")`). So there is at most\n * one per path and it is always the tail, at whatever depth the input node\n * sits: `:watch <dir>` is depth 1, `:provider openrouter connect <key>` is\n * depth 3, and both put the whole remainder here.\n *\n * If the grammar ever admits MID-PATH arguments (`:agent <name> rename\n * <new>`), this field must change shape — one string cannot represent two.\n * That is a parser change, so it will be caught here rather than silently\n * producing a wrong `arg`.\n */\n arg?: 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 * Text was copied to the system clipboard.\n *\n * Fires after the copy is dispatched (OSC 52 plus the native fallback), for\n * a selection copy the user made in the terminal. Observational, like every\n * notify hook: a handler cannot alter or veto what was copied, and the\n * clipboard has already been written by the time it runs.\n *\n * It does NOT fire for an empty selection — copying nothing is not an\n * event — nor for text the user pastes, which is the opposite direction and\n * would need its own hook.\n */\n \"tui:copy\": (payload: TuiCopyPayload) => 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 * Which glyph set line components draw their icons from.\n *\n * ── Why this is a SETTING and not code ──────────────────────────────────\n *\n * It answers \"what does this machine's font support\", which is a property\n * of the terminal rather than of the config. A shared line should look\n * right on a laptop with a patched font and on a server without one, and\n * that cannot be true if the answer is compiled into the line.\n *\n * ── Why the default is \"auto\" ───────────────────────────────────────────\n *\n * Nerd Fonts are the de facto standard — lualine, starship, powerlevel10k\n * and oh-my-posh all assume one — so defaulting them OFF would give the\n * majority a plainer bar than they installed a patched font for.\n *\n * But a font cannot be detected from inside a terminal, so \"auto\" is a\n * heuristic, not a fact: it reads the same environment the ecosystem uses\n * (TERM_PROGRAM, and whether a font name mentions \"Nerd\"), and falls back\n * to unicode when nothing says yes. Someone seeing boxes sets \"unicode\" and\n * is done; someone seeing plain text sets \"nerd\".\n */\n icons?: IconSet\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 /**\n * A glyph vocabulary.\n *\n * `nerd` is the full Nerd Font range — branch symbols, folder icons, the lot.\n * `unicode` is the subset present in essentially every font (▸ ● ◆), which\n * renders everywhere and reads as deliberate rather than degraded. `none`\n * drops icons entirely, for a bar that should be text and nothing else.\n */\n type IconSet = \"auto\" | \"nerd\" | \"unicode\" | \"none\"\n\n /**\n * The named icons every set provides.\n *\n * Deliberately small and semantic: a component says what its value MEANS, and\n * the set decides what that looks like. Naming them after appearance\n * (\"triangle\") would tie every component to one set's vocabulary and defeat\n * the swap.\n */\n type IconName =\n | \"agent\"\n | \"model\"\n | \"session\"\n | \"tokens\"\n | \"messages\"\n | \"modules\"\n | \"branch\"\n | \"changes\"\n | \"ahead\"\n | \"behind\"\n | \"folder\"\n | \"clock\"\n | \"user\"\n | \"warning\"\n | \"error\"\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 AxonPalette = {\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: CommandName | 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 AxonMode = {\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 /**\n * Null when idle.\n *\n * The last two are ATTACHED instances only — an agent reached over a URL,\n * whose wire can drop without the agent itself stopping. A local instance\n * never reports them: its runtime lives in this process, so there is no\n * connection to lose.\n *\n * Kept in step with `AgentActivity` in the TUI and with the copy in\n * tui-contract.ts, which is what a user's own config typechecks against.\n */\n readonly activity: \"booting\" | \"rebooting\" | \"shutting-down\" | \"working\" | \"reconnecting\" | \"disconnected\" | 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 // ── lines ───────────────────────────────────────────────────────────────────\n\n /**\n * One live value on a line — a name, when it changes, and what it says.\n *\n * THE TRIGGER IS DECLARED, and that is the whole design. A bare `() => string`\n * would leave the terminal with no idea when to call it: re-running every\n * component on every frame makes one slow component stall the paint, and the\n * alternative — asking users to wire their own reactivity — is the thing this\n * API exists to avoid. So a component states what wakes it and the renderer\n * evaluates it then and never otherwise.\n *\n * `render` is SYNCHRONOUS by contract. A frame cannot await, and a component\n * that needs real work (a git branch, a network call) does that work in its\n * trigger and returns the cached value here — the same discipline lualine\n * settles on, arrived at from the render loop rather than from convention.\n *\n * A component with neither `on` nor `every` renders once and stays put, which\n * is the right shape for something static.\n */\n type LineComponent = {\n /**\n * A glyph shown before the value — a NAME from the catalogue, or a literal.\n *\n * A NAME resolves through the active icon set, so one setting swaps every\n * icon at once — which is what makes a shared component work on a machine\n * without a patched font. A literal glyph is the escape hatch for\n * something the catalogue does not name, and it does NOT respond to the\n * setting: an author writing a raw character has said they know what\n * appears.\n *\n * The author's, not the config's — an icon is part of what a component\n * MEANS (a git component without its branch glyph is a worse git\n * component), where colour is part of how a LINE looks and belongs to\n * whoever composes the row.\n *\n * Rendered only when the component has something to say: an icon beside an\n * empty value is a glyph floating on its own.\n */\n icon?: IconName | (string & {})\n /**\n * Hook events that change this value — the same names `tui.hook` takes.\n *\n * Reusing that vocabulary is deliberate: the terminal already emits a\n * precise event for everything it does, so a component author picks from a\n * list they have already learned rather than inventing a subscription.\n */\n on?: readonly TuiHookName[]\n /**\n * Re-render every N milliseconds — for values that change with time rather\n * than with anything the terminal does. A clock is the case; there is no\n * event for \"a second passed\".\n *\n * Taken as written, with no floor. Painting a string is cheap and the\n * renderer diffs frames for exactly this; a component doing heavy work on\n * a fast interval is the author's call, the same as a slow hook handler.\n */\n every?: number\n /**\n * Run when the user clicks this component.\n *\n * Named for what the AUTHOR does, not for the event vterm dispatches\n * (`@press`). A config says \"when this is clicked\"; the transport's name\n * for that is an implementation detail of the layer below.\n *\n * What turns a status line into a control surface: a row of agent names\n * becomes a nav bar, a branch indicator becomes a branch picker. Without\n * it a line can only report, and reporting is the smaller half of what a\n * bar sitting in front of you all day could do.\n *\n * Unawaited by the terminal — a handler that takes a second must not hold\n * the frame — and a failure is reported like any other config fault rather\n * than surfacing as a click that silently did nothing.\n */\n click?: () => void | Promise<void>\n /**\n * What to show, coerced to text.\n *\n * Primitives only, deliberately. `string` alone forced `String(count)` on\n * the most ordinary component there is; `unknown` would accept an object,\n * an array or a promise and render `[object Object]` silently — and an\n * author who slipped an `async` onto this would get `[object Promise]` on\n * their line with nothing to explain it. Widening removes ceremony, not\n * the errors the type was catching.\n *\n * `null`/`undefined` are the honest way to say \"nothing right now\", and\n * render as empty rather than as the text \"null\".\n */\n render: () => string | number | null | undefined\n }\n\n /**\n * A line's content — up to three slots, laid out by the terminal.\n *\n * Axon owns spacing, separators, truncation and colour; a config supplies text\n * and its order. That split is the product decision: every layout knob is a\n * way for two configs to disagree, and the failure mode it prevents is a\n * handful of beautiful setups surrounded by mediocre ones. Users theme,\n * Axon lays out.\n *\n * `left` and `right` push apart. `middle` centres on the LINE, not on the gap\n * between the sides, and truncates when there is no room — one rule, so a\n * three-slot line never needs a negotiation nobody can predict.\n */\n type LineContent = {\n left?: LineSlot\n middle?: LineSlot\n right?: LineSlot\n /**\n * The style this line was DESIGNED for — a default, not a decree.\n *\n * An author knows what their line is meant to look like, so declaring it\n * here means a shared line arrives looking right with no configuration.\n * But the placement wins: a user who wants it plain says so in\n * `lines.set()` and never has to fork the line to restyle it.\n *\n * Precedence, narrowest first: placement → this → `lines.style()`.\n */\n style?: AxonLineStyle\n }\n\n /**\n * One slot's contents: a flat list of components, or a list of SECTIONS.\n *\n * A section is the unit a separator divides and a background fills — which is\n * why the nesting exists at all. Inside one section every component shares a\n * ground, so the divider between them is a hairline; between sections the\n * ground changes, so the divider is a filled arrow. That is the whole\n * distinction lualine draws with `component_separators` and\n * `section_separators`, and it cannot be expressed on a flat list.\n *\n * A flat array is one section. Nothing already written changes meaning.\n */\n type LineSlot = readonly ComponentName[] | readonly (readonly ComponentName[])[]\n\n /**\n * A component's name — the catalogue Axon ships, or one you registered.\n *\n * The built-ins are enumerated so an editor completes them and a typo is a\n * compile error rather than a gap you find on screen. `(string & {})` keeps\n * that completion while still accepting names this union cannot know: a\n * component from an extension, or one the same config declared a few lines up.\n *\n * The same shape `ThemeColor` uses, for the same reason — a closed union would\n * make the escape hatch impossible, and an open `string` would make the\n * catalogue undiscoverable.\n */\n type ComponentName = RegistryName<AxonComponentRegistry>\n\n /**\n * A generated registry's names — CLOSED once the registry has entries.\n *\n * ── Why this is not simply `keyof R | (string & {})` ────────────────────────\n *\n * That shape gives completion but never rejects anything: the open arm accepts\n * every string, so a typo typechecks and only fails at runtime — which is the\n * bug the generator exists to remove.\n *\n * An empty registry still has to accept anything, though. A profile before its\n * first `axon prepare` has no generated file, and every name in it would be an\n * error against a `never` union — a config that was fine yesterday would light\n * up red because a build step had not run yet.\n *\n * So the union closes only when it has something to close AROUND: empty means\n * open, populated means exact. A name the generator genuinely cannot see (one\n * computed at runtime) is cast at the call site, which is the honest signal\n * that it is unverifiable rather than a hole left open for every name.\n */\n type RegistryName<R> = keyof R extends never ? string : keyof R & string\n\n /**\n * Every line name known at generation time.\n *\n * Same mechanism as AxonComponentRegistry — see that interface for why these\n * are generated rather than written by hand.\n */\n type LineName = RegistryName<AxonLineRegistry>\n\n /**\n * Every palette name known at generation time.\n */\n type PaletteName = RegistryName<AxonPaletteRegistry>\n\n /**\n * Every command path known at generation time, space-joined.\n */\n type CommandName = RegistryName<AxonCommandRegistry>\n\n /**\n * The registries `axon prepare` fills in.\n *\n * ── Generated, not hand-written ─────────────────────────────────────────────\n *\n * These were a hand-maintained union of the built-in names, which drifted the\n * first time someone added a component and forgot to update it. The generator\n * reads the actual catalogue AND every config's own `create` calls, so what an\n * editor completes is what is really registered — including the component you\n * declared four lines above the line using it.\n *\n * ── Why an interface rather than a type alias ───────────────────────────────\n *\n * Declaration merging. A generated `.d.ts` reopens the interface and adds its\n * keys, which means built-ins, extension contributions and a user's own\n * registrations all land in one union with no privileged tier. An alias could\n * only be replaced, not extended, so every source would need its own name and\n * the consumer would have to union them by hand.\n *\n * Empty here by design: a profile with no generated types still typechecks,\n * because every consuming alias keeps a `(string & {})` arm.\n */\n // eslint-disable-next-line @typescript-eslint/no-empty-object-type\n interface AxonComponentRegistry {}\n // eslint-disable-next-line @typescript-eslint/no-empty-object-type\n interface AxonLineRegistry {}\n // eslint-disable-next-line @typescript-eslint/no-empty-object-type\n interface AxonPaletteRegistry {}\n // eslint-disable-next-line @typescript-eslint/no-empty-object-type\n interface AxonCommandRegistry {}\n\n /**\n * How a line draws its separators and shades its sections.\n *\n * A preset, never individual glyphs. Axon owning the glyph set is the line\n * between \"every config looks like Axon\" and \"everyone invents their own bar\"\n * — and a config that picked its own would be choosing a look that has to hold\n * against every theme, which is not a decision anyone should have to make\n * per row.\n *\n * Backgrounds step from the EDGE INWARD: the outermost section takes the\n * accent, each step inward is softer, and the innermost sits on the terminal's\n * own ground. Position in the array is the section, so there is no background\n * to configure — which is what stops two configs disagreeing about what a\n * status bar looks like.\n */\n type AxonLineStyle =\n /** No glyphs. Components separated by spacing alone. */\n | \"plain\"\n /**\n * Filled arrows between sections, hairlines within — the default.\n *\n * The separator block (`U+E0B0`–`U+E0B7`) predates Nerd Fonts and ships far\n * more widely than the icon range, so a terminal that draws a git icon as a\n * box still renders these. One without even that sets `\"plain\"`.\n */\n | \"powerline\"\n /** The same, with round caps. Needs a Nerd Font. */\n | \"rounded\"\n /**\n * Square edges: a flat boundary between fills and a vertical bar within.\n *\n * The same section model as `powerline`, without the arrow's implied\n * direction — which reads as calmer beside a busy conversation, and is\n * what you want when the bar should sit still rather than point at\n * something. Needs a Nerd Font.\n */\n | \"block\"\n /** A thin middle dot between components, no section fills. */\n | \"minimal\"\n\n /**\n * A line's definition: the full three-slot form, or a bare array.\n *\n * The array means LEFT, always — never auto-distributed. Both built-in lines\n * are left-aligned, so it is the common case worth a shorthand, and a rule\n * that reads the same every time beats one that guesses.\n */\n type LineDefinition = LineContent | readonly string[]\n\n /**\n * One entry in the stack: a name, or a name with placement overrides.\n *\n * The bare string is the common case and stays the common case — an object is\n * only needed when this particular placement differs from what the line\n * declared.\n */\n type AxonLineEntry = LineName | AxonLinePlacement\n\n /**\n * How ONE line is placed in ONE stack.\n *\n * ── Why placement owns style ────────────────────────────────────────────────\n *\n * Three layers, three owners: a COMPONENT is what the data is (an extension\n * author's), a LINE is what sits where (shared or personal), and a PLACEMENT\n * is how it looks in this stack (always the user's).\n *\n * Style began on the line and that was the wrong layer. A shared line would\n * ship with its look baked in, so anyone installing `@cody/git-line` had to\n * fork it to restyle — which is the coupling that stops a registry being\n * worth having. A line may still declare a default, because an author knows\n * what their line was designed to look like; the placement wins when it says\n * otherwise.\n *\n * Precedence, narrowest first: this placement → the line's own default →\n * `lines.style()`.\n */\n type AxonLinePlacement = {\n /** The registered line this entry places. */\n line: LineName\n /** How it draws here, overriding the line's default and the stack's. */\n style?: AxonLineStyle\n /**\n * Start hidden, keeping its place in the stack.\n *\n * Declared here rather than left to a `hide()` call afterwards, so the\n * stack is one description instead of a description plus a sequence of\n * mutations. `toggle()` still flips it at runtime.\n */\n hidden?: boolean\n }\n\n /**\n * Where a line moves to. `\"up\"`/`\"down\"` are relative; a number is an absolute\n * index in the stack, clamped rather than throwing — a keybind that walks a\n * line to the top should stop there, not fail on the last press.\n */\n type LinePosition = \"up\" | \"down\" | number\n\n /** A registered line, as `lines.list()` reports it. */\n type Line = {\n /**\n * Unique within the stack — the name is NOT an identity, since a line may\n * be placed more than once (comparing two styles side by side is a real\n * thing to want).\n */\n id: string\n name: string\n content: LineContent\n /** How it draws. Falls back to the stack default when the line declared none. */\n style: AxonLineStyle\n /** False when hidden. A hidden line keeps its place in the stack. */\n visible: boolean\n }\n\n /**\n * Components — the live values a line can show.\n *\n * Axon ships a catalogue under the `axon:` prefix (`axon:token/counter` and\n * friends), and anything else registers here. The two are the same kind of\n * thing: a built-in is a component the terminal registered against its own\n * hooks, with no privilege a user's cannot have.\n *\n * Names are `provider:name` rather than a package specifier. A package ships\n * many things; a component comes from one provider — conflating the two would\n * make every component name read like an import path.\n */\n type AxonComponents = {\n /**\n * Register a component. Throws if the name is taken. Returns a disposer.\n *\n * A `render` that throws costs that component and nothing else: it renders\n * empty and the fault is reported, the same containment the config loader\n * applies per file. One bad value must not take down the line around it.\n */\n create: (name: string, component: LineComponent) => Disposer\n\n /** Every registered component name, built-ins included. */\n list: () => readonly string[]\n }\n\n /**\n * Lines — the configurable rows above the input bar.\n *\n * The terminal ships two of its own and they stay its: the cwd/token row and\n * the voice row. A user's lines sit between them, which is the one layout\n * decision Axon does not delegate — the rows that must always be readable are\n * not ones a config can push off screen.\n *\n * Registration and placement are SEPARATE VERBS, and that is what makes the\n * surface extensible: an extension `create`s lines without deciding where they\n * go, and the user `set`s the stack without knowing who authored what.\n */\n type AxonLines = {\n /**\n * Register a line. Throws if the name is taken, or if it names a component\n * that does not exist — a config error the loader can contain, reported\n * where it can be fixed rather than rendered as a blank row.\n */\n create: (name: string, definition: LineDefinition) => Disposer\n\n /**\n * The default style for every line that does not declare one.\n *\n * A stack-wide setting because a bar with one powerline row among plain\n * ones reads as a mistake, not a choice — and because the common case is\n * wanting ALL of them to match. A line that genuinely differs still says so\n * itself, which is the rarer thing and reads as deliberate at the call site.\n *\n * Called with no argument, returns the current default.\n */\n style: {\n (style: AxonLineStyle): void\n (): AxonLineStyle\n }\n\n /**\n * The single line ABOVE the conversation, or null to clear it.\n *\n * One line, not a stack. The room above the conversation is scarce in a\n * way the room below it is not — the bottom already holds the input bar\n * and its own rows, so a stack there is bounded by something. A second\n * unbounded stack at the top could push the conversation off screen, and\n * the constraint costs nothing: nobody has wanted two.\n *\n * Takes the same placement object as `set`, so a top line styles itself\n * the same way any other does.\n */\n top: {\n /** Set it by name, with placement options. */\n (name: LineName, options?: Omit<AxonLinePlacement, \"line\">): void\n /** Set it from a placement object, or clear it with null. */\n (entry: AxonLineEntry | null): void\n /** Read what is currently set. */\n (): Line | null\n }\n\n /**\n * Set the whole stack, top to bottom. Declarative and idempotent: this is\n * the one place order lives, so reordering is calling it again.\n *\n * An entry is a bare name, or an object when this placement differs from\n * the line's own defaults — see LinePlacement. Registered lines left out\n * of the array are not shown; an unknown name is reported.\n */\n set: (entries: readonly AxonLineEntry[]) => void\n\n /**\n * Move one line within the stack. Addressed by NAME, never by index —\n * an index shifts when anything above it moves, so a keybind written today\n * would quietly mean something else tomorrow.\n */\n move: (name: string, position: LinePosition) => void\n\n /** Hide a line. It keeps its place, so showing it again returns it there. */\n hide: (name: string) => void\n /** Show a hidden line, back where it was. */\n show: (name: string) => void\n /** Flip visibility — the verb a keybind wants. */\n toggle: (name: string) => void\n\n /** Every registered line, in stack order. What a picker palette reads. */\n list: () => readonly Line[]\n }\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 AxonTheme = {\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 /** Trailing options for `tui.info` / `warn` / `error`. */\n type NoticeOptions = {\n /** How long the notice holds the row, in milliseconds. Clamped to a few seconds. */\n ms: number\n }\n\n type AxonTui = {\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\", { ms: 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 * Takes any number of values and joins them with a space, the way\n * `console.log` does — so a config building a label from several pieces\n * does not have to concatenate first. Non-strings are stringified;\n * objects and arrays go through JSON so a stray value reads as data\n * rather than as `[object Object]`.\n *\n * The 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 * Duration is a trailing `{ ms }` rather than a bare number, because\n * under variadic args a trailing number is DATA: `tui.info(\"saved\", 500)`\n * has to mean \"saved 500\", not \"show this for half a second\".\n *\n * tui.info(\"[\", keys.join(\" \"), \"]\")\n * tui.warn(\"nothing to do\", { ms: 600 })\n */\n info: (...args: unknown[]) => void\n\n /** As `info`, in the warning colour. */\n warn: (...args: unknown[]) => void\n\n /** As `info`, in the error colour. For \"that failed\" — never for why. */\n error: (...args: unknown[]) => 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 * `tui:copy` — the text that was copied.\n *\n * The text is CARRIED rather than left for the handler to read back off the\n * selection: copying does not clear the selection, but nothing stops the user\n * (or another handler) from clearing it before this one runs, and a handler\n * that re-read it would then see an empty string for a copy that plainly\n * happened. What is passed is exactly what reached the clipboard.\n *\n * Never empty — an empty selection copies nothing and fires nothing.\n */\n type TuiCopyPayload = {\n /** The copied text, verbatim: original line breaks, no trimming. */\n text: string\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 /**\n * Where the command sits in the command TREE, one segment per level —\n * `[\"ext\", \"update\"]`, `[\"theme\", \"set\", \"gruvbox\"]`.\n *\n * An array rather than a space-joined string because the segments are what\n * both call sites already hold (`[...breadcrumb, node.label]` in the\n * palette, `toPath(path)` in `commands.run()`) and what registration,\n * lookup and COMMAND_NOT_FOUND all use. The string was a lossy projection\n * at one boundary: `split(\" \")` is not its inverse once an argument\n * contains a space, so the commands most worth reacting to — a pasted key,\n * a path with spaces — were exactly the ones a handler mis-parsed.\n *\n * A list-backed group puts its chosen row here, not in `arg`: a theme name\n * is a NODE the palette listed, from a closed set, so `:theme set gruvbox`\n * is three segments. That makes every pick a distinct path, which is how a\n * handler knows WHICH theme — so match a namespace with `path[0]`, not a\n * whole-array compare.\n */\n path: string[]\n\n /**\n * The raw text typed after an input command, or undefined when the command\n * takes none — `\"/some/dir\"` for `:watch /some/dir`.\n *\n * Separate from `path` because it is a different KIND of thing: a segment\n * comes from a closed set and is matchable, an argument is arbitrary user\n * text. Folding it in would turn \"did watch run\" from an equality check\n * into a prefix test, and make every invocation its own path.\n *\n * ── The invariant this field rests on ───────────────────────────────────\n *\n * An input node TERMINATES traversal — `CommandInput` has no children, and\n * everything after it is taken as the argument verbatim, spaces included\n * (traverse.ts: `rawSegments.slice(i + 1).join(\" \")`). So there is at most\n * one per path and it is always the tail, at whatever depth the input node\n * sits: `:watch <dir>` is depth 1, `:provider openrouter connect <key>` is\n * depth 3, and both put the whole remainder here.\n *\n * If the grammar ever admits MID-PATH arguments (`:agent <name> rename\n * <new>`), this field must change shape — one string cannot represent two.\n * That is a parser change, so it will be caught here rather than silently\n * producing a wrong `arg`.\n */\n arg?: 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 * Text was copied to the system clipboard.\n *\n * Fires after the copy is dispatched (OSC 52 plus the native fallback), for\n * a selection copy the user made in the terminal. Observational, like every\n * notify hook: a handler cannot alter or veto what was copied, and the\n * clipboard has already been written by the time it runs.\n *\n * It does NOT fire for an empty selection — copying nothing is not an\n * event — nor for text the user pastes, which is the opposite direction and\n * would need its own hook.\n */\n \"tui:copy\": (payload: TuiCopyPayload) => 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 * Which glyph set line components draw their icons from.\n *\n * ── Why this is a SETTING and not code ──────────────────────────────────\n *\n * It answers \"what does this machine's font support\", which is a property\n * of the terminal rather than of the config. A shared line should look\n * right on a laptop with a patched font and on a server without one, and\n * that cannot be true if the answer is compiled into the line.\n *\n * ── Why the default is \"auto\" ───────────────────────────────────────────\n *\n * Nerd Fonts are the de facto standard — lualine, starship, powerlevel10k\n * and oh-my-posh all assume one — so defaulting them OFF would give the\n * majority a plainer bar than they installed a patched font for.\n *\n * But a font cannot be detected from inside a terminal, so \"auto\" is a\n * heuristic, not a fact: it reads the same environment the ecosystem uses\n * (TERM_PROGRAM, and whether a font name mentions \"Nerd\"), and falls back\n * to unicode when nothing says yes. Someone seeing boxes sets \"unicode\" and\n * is done; someone seeing plain text sets \"nerd\".\n */\n icons?: IconSet\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 * The machine-wide policy CEILING every agent on this profile runs under.\n *\n * A top-level key rather than a setting: `ProfileSettings` is the set the\n * TERMINAL acts on, and this is read by the runtime and enforced inside\n * the capsule. Folding it in would widen that set's meaning to \"anything\n * configurable\" and lose the boundary it draws.\n *\n * An agent narrows within this and can never widen it. Set `process.run`\n * to `false` here and no agent on the machine gets a shell, whatever its\n * own axon.config.ts says. Set a rule to `\"escalate\"` and every agent asks\n * you — an agent author cannot suppress the prompt by allowing it.\n *\n * policy: {\n * process: { run: { allow: [\"bun *\", \"git *\"] }, spawn: false },\n * network: { \"api.anthropic.com:443\": true, \"*\": \"escalate\" },\n * tools: { github: \"escalate\" },\n * }\n *\n * Silence is no opinion, never a denial: a capability neither layer\n * mentions falls through to the agent's own policy, so adding one rule\n * here cannot lock out everything else.\n */\n policy?: ProfilePolicy\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 /**\n * One capability's rule.\n *\n * `true` allows, `false` denies, `\"escalate\"` asks. The object form matches\n * the first string argument — a command, a host, a path — by glob, where `*`\n * stops at a `/` and `**` crosses it. Inside one rule the strictest matching\n * clause wins: deny, then escalate, then allow, regardless of the order they\n * are written in.\n *\n * Declared INLINE rather than imported from the policy module, because this\n * file is copied verbatim into profile type frames and a profile directory has\n * no node_modules for an import to resolve through. `tui-policy.test.ts`\n * asserts it stays structurally identical to the real `PolicyRule` — a drift\n * here means a config that typechecks and does not enforce.\n */\n type ProfilePolicyRule =\n | boolean\n | \"escalate\"\n | {\n allow?: string[]\n deny?: string[]\n escalate?: string[]\n }\n\n /**\n * The subset of a capsule policy a PROFILE may declare.\n *\n * `fs` and `limits` are OS-layer facts (bind mounts, cgroups) rather than\n * per-call verdicts, and are taken from the profile wholesale when present —\n * a ceiling a bind mount ignores is not a ceiling.\n */\n type ProfilePolicy = {\n /**\n * OS confinement tier — Linux only, a no-op elsewhere. An agent may harden\n * beyond this but never drop below it.\n */\n isolation?: \"none\" | \"auto\" | \"hardened\"\n /** Filesystem view. Enforced by the mount namespace under `auto`/`hardened`. */\n fs?: {\n read?: string[]\n write?: string[]\n }\n /** Network destinations, keyed by `host:port` glob. */\n network?: Record<string, ProfilePolicyRule>\n /** Shell access. `run` is a one-shot command, `spawn` a long-lived child. */\n process?: {\n spawn?: ProfilePolicyRule\n run?: ProfilePolicyRule\n }\n /** OS resource caps, applied to the whole process tree. */\n limits?: {\n memory?: string\n cpu?: string\n pids?: number\n }\n /** Tool namespaces, keyed by the name a tool registers under. */\n tools?: Record<string, ProfilePolicyRule>\n }\n\n /**\n * A glyph vocabulary.\n *\n * `nerd` is the full Nerd Font range — branch symbols, folder icons, the lot.\n * `unicode` is the subset present in essentially every font (▸ ● ◆), which\n * renders everywhere and reads as deliberate rather than degraded. `none`\n * drops icons entirely, for a bar that should be text and nothing else.\n */\n type IconSet = \"auto\" | \"nerd\" | \"unicode\" | \"none\"\n\n /**\n * The named icons every set provides.\n *\n * Deliberately small and semantic: a component says what its value MEANS, and\n * the set decides what that looks like. Naming them after appearance\n * (\"triangle\") would tie every component to one set's vocabulary and defeat\n * the swap.\n */\n type IconName =\n | \"agent\"\n | \"model\"\n | \"session\"\n | \"tokens\"\n | \"messages\"\n | \"modules\"\n | \"branch\"\n | \"changes\"\n | \"ahead\"\n | \"behind\"\n | \"folder\"\n | \"clock\"\n | \"user\"\n | \"warning\"\n | \"error\"\n\n /** What `defineProfile()` returns. */\n type ProfileDefinition = {\n _kind: \"profile\"\n config: ProfileConfig\n }"
|
package/src/tui.ts
CHANGED
|
@@ -195,7 +195,7 @@ export type PickOption<T> = {
|
|
|
195
195
|
* `false` for `confirm`. That is in the return type deliberately: a caller is
|
|
196
196
|
* forced to handle the user walking away.
|
|
197
197
|
*/
|
|
198
|
-
export type
|
|
198
|
+
export type AxonPalette = {
|
|
199
199
|
/** Register a palette. Throws if `name` is taken. */
|
|
200
200
|
create: (name: string, definition: PaletteDefinition) => PaletteHandle
|
|
201
201
|
|
|
@@ -359,7 +359,7 @@ export type BuiltinMode =
|
|
|
359
359
|
|
|
360
360
|
export type ModeName = BuiltinMode | (string & {})
|
|
361
361
|
|
|
362
|
-
export type
|
|
362
|
+
export type AxonMode = {
|
|
363
363
|
/** Switch modes. Throws on an unknown mode rather than silently doing nothing. */
|
|
364
364
|
set: (mode: ModeName) => Promise<void>
|
|
365
365
|
/** The active mode. */
|
|
@@ -945,7 +945,7 @@ export type LineContent = {
|
|
|
945
945
|
*
|
|
946
946
|
* Precedence, narrowest first: placement → this → `lines.style()`.
|
|
947
947
|
*/
|
|
948
|
-
style?:
|
|
948
|
+
style?: AxonLineStyle
|
|
949
949
|
}
|
|
950
950
|
|
|
951
951
|
/**
|
|
@@ -1061,10 +1061,16 @@ export interface AxonCommandRegistry {}
|
|
|
1061
1061
|
* to configure — which is what stops two configs disagreeing about what a
|
|
1062
1062
|
* status bar looks like.
|
|
1063
1063
|
*/
|
|
1064
|
-
export type
|
|
1065
|
-
/** No glyphs. Components separated by spacing alone
|
|
1064
|
+
export type AxonLineStyle =
|
|
1065
|
+
/** No glyphs. Components separated by spacing alone. */
|
|
1066
1066
|
| "plain"
|
|
1067
|
-
/**
|
|
1067
|
+
/**
|
|
1068
|
+
* Filled arrows between sections, hairlines within — the default.
|
|
1069
|
+
*
|
|
1070
|
+
* The separator block (`U+E0B0`–`U+E0B7`) predates Nerd Fonts and ships far
|
|
1071
|
+
* more widely than the icon range, so a terminal that draws a git icon as a
|
|
1072
|
+
* box still renders these. One without even that sets `"plain"`.
|
|
1073
|
+
*/
|
|
1068
1074
|
| "powerline"
|
|
1069
1075
|
/** The same, with round caps. Needs a Nerd Font. */
|
|
1070
1076
|
| "rounded"
|
|
@@ -1096,7 +1102,7 @@ export type LineDefinition = LineContent | readonly string[]
|
|
|
1096
1102
|
* only needed when this particular placement differs from what the line
|
|
1097
1103
|
* declared.
|
|
1098
1104
|
*/
|
|
1099
|
-
export type
|
|
1105
|
+
export type AxonLineEntry = LineName | AxonLinePlacement
|
|
1100
1106
|
|
|
1101
1107
|
/**
|
|
1102
1108
|
* How ONE line is placed in ONE stack.
|
|
@@ -1117,11 +1123,11 @@ export type LineEntry = LineName | LinePlacement
|
|
|
1117
1123
|
* Precedence, narrowest first: this placement → the line's own default →
|
|
1118
1124
|
* `lines.style()`.
|
|
1119
1125
|
*/
|
|
1120
|
-
export type
|
|
1126
|
+
export type AxonLinePlacement = {
|
|
1121
1127
|
/** The registered line this entry places. */
|
|
1122
1128
|
line: LineName
|
|
1123
1129
|
/** How it draws here, overriding the line's default and the stack's. */
|
|
1124
|
-
style?:
|
|
1130
|
+
style?: AxonLineStyle
|
|
1125
1131
|
/**
|
|
1126
1132
|
* Start hidden, keeping its place in the stack.
|
|
1127
1133
|
*
|
|
@@ -1150,7 +1156,7 @@ export type Line = {
|
|
|
1150
1156
|
name: string
|
|
1151
1157
|
content: LineContent
|
|
1152
1158
|
/** How it draws. Falls back to the stack default when the line declared none. */
|
|
1153
|
-
style:
|
|
1159
|
+
style: AxonLineStyle
|
|
1154
1160
|
/** False when hidden. A hidden line keeps its place in the stack. */
|
|
1155
1161
|
visible: boolean
|
|
1156
1162
|
}
|
|
@@ -1167,7 +1173,7 @@ export type Line = {
|
|
|
1167
1173
|
* many things; a component comes from one provider — conflating the two would
|
|
1168
1174
|
* make every component name read like an import path.
|
|
1169
1175
|
*/
|
|
1170
|
-
export type
|
|
1176
|
+
export type AxonComponents = {
|
|
1171
1177
|
/**
|
|
1172
1178
|
* Register a component. Throws if the name is taken. Returns a disposer.
|
|
1173
1179
|
*
|
|
@@ -1193,7 +1199,7 @@ export type ComponentsApi = {
|
|
|
1193
1199
|
* surface extensible: an extension `create`s lines without deciding where they
|
|
1194
1200
|
* go, and the user `set`s the stack without knowing who authored what.
|
|
1195
1201
|
*/
|
|
1196
|
-
export type
|
|
1202
|
+
export type AxonLines = {
|
|
1197
1203
|
/**
|
|
1198
1204
|
* Register a line. Throws if the name is taken, or if it names a component
|
|
1199
1205
|
* that does not exist — a config error the loader can contain, reported
|
|
@@ -1212,8 +1218,8 @@ export type LinesApi = {
|
|
|
1212
1218
|
* Called with no argument, returns the current default.
|
|
1213
1219
|
*/
|
|
1214
1220
|
style: {
|
|
1215
|
-
(style:
|
|
1216
|
-
():
|
|
1221
|
+
(style: AxonLineStyle): void
|
|
1222
|
+
(): AxonLineStyle
|
|
1217
1223
|
}
|
|
1218
1224
|
|
|
1219
1225
|
/**
|
|
@@ -1230,9 +1236,9 @@ export type LinesApi = {
|
|
|
1230
1236
|
*/
|
|
1231
1237
|
top: {
|
|
1232
1238
|
/** Set it by name, with placement options. */
|
|
1233
|
-
(name: LineName, options?: Omit<
|
|
1239
|
+
(name: LineName, options?: Omit<AxonLinePlacement, "line">): void
|
|
1234
1240
|
/** Set it from a placement object, or clear it with null. */
|
|
1235
|
-
(entry:
|
|
1241
|
+
(entry: AxonLineEntry | null): void
|
|
1236
1242
|
/** Read what is currently set. */
|
|
1237
1243
|
(): Line | null
|
|
1238
1244
|
}
|
|
@@ -1245,7 +1251,7 @@ export type LinesApi = {
|
|
|
1245
1251
|
* the line's own defaults — see LinePlacement. Registered lines left out
|
|
1246
1252
|
* of the array are not shown; an unknown name is reported.
|
|
1247
1253
|
*/
|
|
1248
|
-
set: (entries: readonly
|
|
1254
|
+
set: (entries: readonly AxonLineEntry[]) => void
|
|
1249
1255
|
|
|
1250
1256
|
/**
|
|
1251
1257
|
* Move one line within the stack. Addressed by NAME, never by index —
|
|
@@ -1273,7 +1279,7 @@ export type LinesApi = {
|
|
|
1273
1279
|
* for real, because a preview that rendered differently from the result would
|
|
1274
1280
|
* be worth nothing.
|
|
1275
1281
|
*/
|
|
1276
|
-
export type
|
|
1282
|
+
export type AxonTheme = {
|
|
1277
1283
|
/**
|
|
1278
1284
|
* Register a theme. Throws if the name is taken. Returns a disposer.
|
|
1279
1285
|
*
|
|
@@ -1304,7 +1310,7 @@ export type NoticeOptions = {
|
|
|
1304
1310
|
ms: number
|
|
1305
1311
|
}
|
|
1306
1312
|
|
|
1307
|
-
export type
|
|
1313
|
+
export type AxonTui = {
|
|
1308
1314
|
/**
|
|
1309
1315
|
* Go to an agent: focus the instance the user was last on, booting one if
|
|
1310
1316
|
* none is live. The `~` key's behaviour.
|
|
@@ -1940,6 +1946,30 @@ export type ProfileConfig = {
|
|
|
1940
1946
|
extensions?: ExtensionEntry[]
|
|
1941
1947
|
/** Platform settings — see ProfileSettings. */
|
|
1942
1948
|
settings?: ProfileSettings
|
|
1949
|
+
/**
|
|
1950
|
+
* The machine-wide policy CEILING every agent on this profile runs under.
|
|
1951
|
+
*
|
|
1952
|
+
* A top-level key rather than a setting: `ProfileSettings` is the set the
|
|
1953
|
+
* TERMINAL acts on, and this is read by the runtime and enforced inside
|
|
1954
|
+
* the capsule. Folding it in would widen that set's meaning to "anything
|
|
1955
|
+
* configurable" and lose the boundary it draws.
|
|
1956
|
+
*
|
|
1957
|
+
* An agent narrows within this and can never widen it. Set `process.run`
|
|
1958
|
+
* to `false` here and no agent on the machine gets a shell, whatever its
|
|
1959
|
+
* own axon.config.ts says. Set a rule to `"escalate"` and every agent asks
|
|
1960
|
+
* you — an agent author cannot suppress the prompt by allowing it.
|
|
1961
|
+
*
|
|
1962
|
+
* policy: {
|
|
1963
|
+
* process: { run: { allow: ["bun *", "git *"] }, spawn: false },
|
|
1964
|
+
* network: { "api.anthropic.com:443": true, "*": "escalate" },
|
|
1965
|
+
* tools: { github: "escalate" },
|
|
1966
|
+
* }
|
|
1967
|
+
*
|
|
1968
|
+
* Silence is no opinion, never a denial: a capability neither layer
|
|
1969
|
+
* mentions falls through to the agent's own policy, so adding one rule
|
|
1970
|
+
* here cannot lock out everything else.
|
|
1971
|
+
*/
|
|
1972
|
+
policy?: ProfilePolicy
|
|
1943
1973
|
/**
|
|
1944
1974
|
* Extension settings, keyed by the extension's own scoped name.
|
|
1945
1975
|
*
|
|
@@ -1949,6 +1979,65 @@ export type ProfileConfig = {
|
|
|
1949
1979
|
[extension: `@${string}/${string}`]: unknown
|
|
1950
1980
|
}
|
|
1951
1981
|
|
|
1982
|
+
/**
|
|
1983
|
+
* One capability's rule.
|
|
1984
|
+
*
|
|
1985
|
+
* `true` allows, `false` denies, `"escalate"` asks. The object form matches
|
|
1986
|
+
* the first string argument — a command, a host, a path — by glob, where `*`
|
|
1987
|
+
* stops at a `/` and `**` crosses it. Inside one rule the strictest matching
|
|
1988
|
+
* clause wins: deny, then escalate, then allow, regardless of the order they
|
|
1989
|
+
* are written in.
|
|
1990
|
+
*
|
|
1991
|
+
* Declared INLINE rather than imported from the policy module, because this
|
|
1992
|
+
* file is copied verbatim into profile type frames and a profile directory has
|
|
1993
|
+
* no node_modules for an import to resolve through. `tui-policy.test.ts`
|
|
1994
|
+
* asserts it stays structurally identical to the real `PolicyRule` — a drift
|
|
1995
|
+
* here means a config that typechecks and does not enforce.
|
|
1996
|
+
*/
|
|
1997
|
+
export type ProfilePolicyRule =
|
|
1998
|
+
| boolean
|
|
1999
|
+
| "escalate"
|
|
2000
|
+
| {
|
|
2001
|
+
allow?: string[]
|
|
2002
|
+
deny?: string[]
|
|
2003
|
+
escalate?: string[]
|
|
2004
|
+
}
|
|
2005
|
+
|
|
2006
|
+
/**
|
|
2007
|
+
* The subset of a capsule policy a PROFILE may declare.
|
|
2008
|
+
*
|
|
2009
|
+
* `fs` and `limits` are OS-layer facts (bind mounts, cgroups) rather than
|
|
2010
|
+
* per-call verdicts, and are taken from the profile wholesale when present —
|
|
2011
|
+
* a ceiling a bind mount ignores is not a ceiling.
|
|
2012
|
+
*/
|
|
2013
|
+
export type ProfilePolicy = {
|
|
2014
|
+
/**
|
|
2015
|
+
* OS confinement tier — Linux only, a no-op elsewhere. An agent may harden
|
|
2016
|
+
* beyond this but never drop below it.
|
|
2017
|
+
*/
|
|
2018
|
+
isolation?: "none" | "auto" | "hardened"
|
|
2019
|
+
/** Filesystem view. Enforced by the mount namespace under `auto`/`hardened`. */
|
|
2020
|
+
fs?: {
|
|
2021
|
+
read?: string[]
|
|
2022
|
+
write?: string[]
|
|
2023
|
+
}
|
|
2024
|
+
/** Network destinations, keyed by `host:port` glob. */
|
|
2025
|
+
network?: Record<string, ProfilePolicyRule>
|
|
2026
|
+
/** Shell access. `run` is a one-shot command, `spawn` a long-lived child. */
|
|
2027
|
+
process?: {
|
|
2028
|
+
spawn?: ProfilePolicyRule
|
|
2029
|
+
run?: ProfilePolicyRule
|
|
2030
|
+
}
|
|
2031
|
+
/** OS resource caps, applied to the whole process tree. */
|
|
2032
|
+
limits?: {
|
|
2033
|
+
memory?: string
|
|
2034
|
+
cpu?: string
|
|
2035
|
+
pids?: number
|
|
2036
|
+
}
|
|
2037
|
+
/** Tool namespaces, keyed by the name a tool registers under. */
|
|
2038
|
+
tools?: Record<string, ProfilePolicyRule>
|
|
2039
|
+
}
|
|
2040
|
+
|
|
1952
2041
|
/**
|
|
1953
2042
|
* A glyph vocabulary.
|
|
1954
2043
|
*
|