stitchkit-tui 0.1.4 → 0.2.1

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/dist/cli.js CHANGED
@@ -1,13 +1,272 @@
1
1
  #!/usr/bin/env bun
2
2
  // @bun
3
3
 
4
- // src/core/collection.ts
4
+ // src/cli.ts
5
+ import path6 from "path";
6
+ import { pathToFileURL } from "url";
7
+
8
+ // src/run.tsx
9
+ import path5 from "path";
10
+ import { createCliRenderer } from "@opentui/core";
11
+ import { createRoot } from "@opentui/react";
12
+
13
+ // src/App.tsx
14
+ import { useKeyboard, useTerminalDimensions } from "@opentui/react";
15
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
16
+
17
+ // src/commands.ts
18
+ import { z as z2 } from "zod";
19
+
20
+ // src/core/command-palette.ts
5
21
  import { z } from "zod";
6
- var TerminalCollectionStateSchema = z.object({
7
- keys: z.array(z.string().min(1)),
8
- selectedKey: z.string().min(1).nullable(),
9
- start: z.int().nonnegative(),
10
- capacity: z.int().positive()
22
+ var TerminalCommandDescriptorSchema = z.object({
23
+ id: z.string().regex(/^[a-z][a-z0-9-]*$/),
24
+ aliases: z.array(z.string().min(1)).default([]),
25
+ label: z.string().min(1),
26
+ description: z.string().default("")
27
+ }).strict();
28
+ var TerminalCommandPaletteStateSchema = z.object({
29
+ query: z.string(),
30
+ selectedIndex: z.int().nonnegative(),
31
+ dismissed: z.boolean()
32
+ }).strict();
33
+ function validateTerminalCommands(commands) {
34
+ const parsed = commands.map((command) => TerminalCommandDescriptorSchema.parse(command));
35
+ const owners = new Map;
36
+ for (const command of parsed) {
37
+ for (const name of [command.id, ...command.aliases]) {
38
+ const owner = owners.get(name);
39
+ if (owner)
40
+ throw new Error(`Terminal command ${name} collides with ${owner}`);
41
+ owners.set(name, command.id);
42
+ }
43
+ }
44
+ return parsed;
45
+ }
46
+ function createTerminalCommandPalette() {
47
+ return { query: "", selectedIndex: 0, dismissed: false };
48
+ }
49
+ function setTerminalCommandQuery(state, query) {
50
+ TerminalCommandPaletteStateSchema.parse(state);
51
+ return { query, selectedIndex: 0, dismissed: false };
52
+ }
53
+ function dismissTerminalCommandPalette(state) {
54
+ return { ...TerminalCommandPaletteStateSchema.parse(state), dismissed: true };
55
+ }
56
+ function terminalCommandMatches(state, commands, limit = 20) {
57
+ const current = TerminalCommandPaletteStateSchema.parse(state);
58
+ if (current.dismissed)
59
+ return [];
60
+ const parsed = validateTerminalCommands(commands);
61
+ const query = current.query.toLowerCase();
62
+ return parsed.filter((command) => command.id.includes(query) || command.label.toLowerCase().includes(query) || command.aliases.some((alias) => alias.includes(query))).slice(0, z.int().positive().parse(limit));
63
+ }
64
+ function moveTerminalCommandSelection(state, delta, matchCount) {
65
+ const current = TerminalCommandPaletteStateSchema.parse(state);
66
+ if (matchCount <= 0)
67
+ return { ...current, selectedIndex: 0 };
68
+ return {
69
+ ...current,
70
+ selectedIndex: ((current.selectedIndex + delta) % matchCount + matchCount) % matchCount
71
+ };
72
+ }
73
+ function selectedTerminalCommand(state, commands, limit = 20) {
74
+ const matches = terminalCommandMatches(state, commands, limit);
75
+ return matches[state.selectedIndex] ?? matches[0];
76
+ }
77
+ function resolveExactTerminalCommand(name, commands) {
78
+ return validateTerminalCommands(commands).find((command) => command.id === name || command.aliases.includes(name));
79
+ }
80
+
81
+ // src/commands.ts
82
+ var AgentTuiCommandOutcomeSchema = z2.discriminatedUnion("type", [
83
+ z2.object({ type: z2.literal("submit"), text: z2.string().min(1) }).strict(),
84
+ z2.object({
85
+ type: z2.literal("dialog"),
86
+ dialog: z2.string().min(1),
87
+ query: z2.string().optional()
88
+ }).strict(),
89
+ z2.object({ type: z2.literal("notice"), message: z2.string() }).strict(),
90
+ z2.object({ type: z2.literal("action"), action: z2.string().min(1) }).strict()
91
+ ]);
92
+ function defineTuiCommand(command) {
93
+ if (!/^[a-z][a-z0-9-]*$/.test(command.name)) {
94
+ throw new Error("TUI command names use lowercase letters, digits and hyphens");
95
+ }
96
+ for (const alias of command.aliases ?? []) {
97
+ if (alias !== "?" && !/^[a-z][a-z0-9-]*$/.test(alias)) {
98
+ throw new Error("TUI command aliases are invalid");
99
+ }
100
+ }
101
+ return command;
102
+ }
103
+ function composeTuiCommands(...groups) {
104
+ const commands = groups.flat();
105
+ validateTerminalCommands(commands.map((command) => ({
106
+ id: defineTuiCommand(command).name,
107
+ aliases: [...command.aliases ?? []],
108
+ label: command.name,
109
+ description: command.description
110
+ })));
111
+ return commands;
112
+ }
113
+ function resolveTuiCommand(text, commands) {
114
+ if (!text.startsWith("/"))
115
+ return { type: "prompt", text };
116
+ const match = /^\/([^\s]+)(?:\s+([\s\S]*))?$/.exec(text);
117
+ const name = match?.[1];
118
+ if (!name)
119
+ return { type: "prompt", text };
120
+ const command = commands.find((candidate) => candidate.name === name || candidate.aliases?.includes(name));
121
+ return command ? { type: "command", command, argumentsText: match?.[2] ?? "" } : { type: "prompt", text };
122
+ }
123
+ function commandCompletions(text, commands) {
124
+ if (!text.startsWith("/") || text.slice(1).includes(" "))
125
+ return [];
126
+ const state = setTerminalCommandQuery(createTerminalCommandPalette(), text.slice(1));
127
+ const descriptors = terminalCommandMatches(state, commands.map((command) => ({
128
+ id: command.name,
129
+ aliases: [...command.aliases ?? []],
130
+ label: command.name,
131
+ description: command.description
132
+ })), Math.max(1, commands.length));
133
+ return descriptors.map((descriptor) => commands.find((command) => command.name === descriptor.id)).filter((command) => command !== undefined);
134
+ }
135
+ function selectedCommandCompletion(text, commands, selectedIndex) {
136
+ const completions = commandCompletions(text, commands);
137
+ return completions[selectedIndex] ?? completions[0];
138
+ }
139
+ function moveCommandCompletionSelection(selectedIndex, direction, completionCount) {
140
+ if (completionCount <= 0)
141
+ return 0;
142
+ return moveTerminalCommandSelection({ query: "", selectedIndex, dismissed: false }, direction === "previous" ? -1 : 1, completionCount).selectedIndex;
143
+ }
144
+ function resolveTuiCommandSubmission(text, commands, selectedIndex, paletteDismissed = false) {
145
+ const completion = paletteDismissed ? undefined : selectedCommandCompletion(text, commands, selectedIndex);
146
+ return resolveTuiCommand(completion ? `/${completion.name}` : text, commands);
147
+ }
148
+
149
+ // src/builtins.ts
150
+ var dialog = (name, query) => ({
151
+ type: "dialog",
152
+ dialog: name,
153
+ ...query && { query }
154
+ });
155
+ var action = (name) => ({ type: "action", action: name });
156
+ function createAgentTuiBuiltinCommands() {
157
+ return [
158
+ defineTuiCommand({
159
+ name: "help",
160
+ aliases: ["?"],
161
+ description: "Show available terminal commands",
162
+ execute: () => dialog("help")
163
+ }),
164
+ defineTuiCommand({
165
+ name: "model",
166
+ description: "Choose the model for the next run",
167
+ execute: (query) => dialog("model", query.trim())
168
+ }),
169
+ defineTuiCommand({
170
+ name: "new",
171
+ description: "Start a new durable conversation",
172
+ execute: () => action("new-conversation")
173
+ }),
174
+ defineTuiCommand({
175
+ name: "sessions",
176
+ description: "Browse durable conversations",
177
+ execute: () => dialog("sessions")
178
+ }),
179
+ defineTuiCommand({
180
+ name: "resume",
181
+ description: "Resume a durable conversation",
182
+ execute: () => dialog("sessions")
183
+ }),
184
+ defineTuiCommand({
185
+ name: "status",
186
+ description: "Show session, conversation and run status",
187
+ execute: () => dialog("status")
188
+ }),
189
+ defineTuiCommand({
190
+ name: "tools",
191
+ description: "Show the direct tool surface",
192
+ execute: () => dialog("tools")
193
+ }),
194
+ defineTuiCommand({
195
+ name: "skills",
196
+ description: "Show lazily available skills and resources",
197
+ execute: () => dialog("skills")
198
+ }),
199
+ defineTuiCommand({
200
+ name: "permissions",
201
+ description: "Show approval and sandbox enforcement",
202
+ execute: () => dialog("permissions")
203
+ }),
204
+ defineTuiCommand({
205
+ name: "interrupt",
206
+ description: "Interrupt the active run",
207
+ available: ({ activeRunId }) => activeRunId !== undefined,
208
+ execute: () => action("interrupt")
209
+ }),
210
+ defineTuiCommand({
211
+ name: "clear",
212
+ description: "Start clean while keeping this conversation available to resume",
213
+ execute: () => action("clear-conversation")
214
+ }),
215
+ defineTuiCommand({
216
+ name: "quit",
217
+ aliases: ["exit"],
218
+ description: "Close this terminal host",
219
+ execute: () => action("quit")
220
+ })
221
+ ];
222
+ }
223
+
224
+ // src/composer.ts
225
+ import { z as z3 } from "zod";
226
+ var AgentTuiComposerSchema = z3.object({
227
+ draft: z3.string(),
228
+ history: z3.array(z3.string()),
229
+ historyIndex: z3.int().nonnegative().optional(),
230
+ preservedDraft: z3.string()
231
+ }).strict();
232
+ function createAgentTuiComposer() {
233
+ return { draft: "", history: [], preservedDraft: "" };
234
+ }
235
+ function setAgentTuiDraft(state, draft) {
236
+ const { historyIndex: _historyIndex, ...rest } = state;
237
+ return { ...rest, draft, preservedDraft: draft };
238
+ }
239
+ function submitAgentTuiComposer(state) {
240
+ const text = state.draft.trim();
241
+ if (!text)
242
+ return { state };
243
+ const history = state.history.at(-1) === text ? state.history : [...state.history, text];
244
+ return { state: { draft: "", history, preservedDraft: "" }, text };
245
+ }
246
+ function navigateAgentTuiHistory(state, direction) {
247
+ if (state.history.length === 0)
248
+ return state;
249
+ if (direction === "older") {
250
+ const index = state.historyIndex === undefined ? state.history.length - 1 : Math.max(0, state.historyIndex - 1);
251
+ return { ...state, historyIndex: index, draft: state.history[index] ?? state.draft };
252
+ }
253
+ if (state.historyIndex === undefined)
254
+ return state;
255
+ const index = state.historyIndex + 1;
256
+ if (index >= state.history.length) {
257
+ const { historyIndex: _historyIndex, ...rest } = state;
258
+ return { ...rest, draft: state.preservedDraft };
259
+ }
260
+ return { ...state, historyIndex: index, draft: state.history[index] ?? state.draft };
261
+ }
262
+
263
+ // src/core/collection.ts
264
+ import { z as z4 } from "zod";
265
+ var TerminalCollectionStateSchema = z4.object({
266
+ keys: z4.array(z4.string().min(1)),
267
+ selectedKey: z4.string().min(1).nullable(),
268
+ start: z4.int().nonnegative(),
269
+ capacity: z4.int().positive()
11
270
  }).strict();
12
271
  function maximumStart(total, capacity) {
13
272
  return Math.max(0, total - capacity);
@@ -21,7 +280,7 @@ function reveal(start, capacity, index, total) {
21
280
  return bounded;
22
281
  }
23
282
  function uniqueKeys(keys) {
24
- const result = z.array(z.string().min(1)).parse(keys);
283
+ const result = z4.array(z4.string().min(1)).parse(keys);
25
284
  if (new Set(result).size !== result.length) {
26
285
  throw new Error("Terminal collection keys must be unique");
27
286
  }
@@ -29,7 +288,7 @@ function uniqueKeys(keys) {
29
288
  }
30
289
  function createTerminalCollection(keys, capacity, selectedKey) {
31
290
  const parsedKeys = uniqueKeys(keys);
32
- const parsedCapacity = z.int().positive().parse(capacity);
291
+ const parsedCapacity = z4.int().positive().parse(capacity);
33
292
  const selected = selectedKey !== undefined && parsedKeys.includes(selectedKey) ? selectedKey : parsedKeys[0] ?? null;
34
293
  const index = selected === null ? -1 : parsedKeys.indexOf(selected);
35
294
  return TerminalCollectionStateSchema.parse({
@@ -46,19 +305,19 @@ function reduceTerminalCollection(state, action) {
46
305
  if (keys.length === 0)
47
306
  return { keys, selectedKey: null, start: 0, capacity: current.capacity };
48
307
  const previousIndex = current.selectedKey === null ? 0 : Math.max(0, current.keys.indexOf(current.selectedKey));
49
- const selectedKey2 = current.selectedKey !== null && keys.includes(current.selectedKey) ? current.selectedKey : keys[Math.min(previousIndex, keys.length - 1)];
50
- if (!selectedKey2)
308
+ const selectedKey = current.selectedKey !== null && keys.includes(current.selectedKey) ? current.selectedKey : keys[Math.min(previousIndex, keys.length - 1)];
309
+ if (!selectedKey)
51
310
  throw new Error("Terminal collection survivor is unavailable");
52
- const index = keys.indexOf(selectedKey2);
311
+ const index = keys.indexOf(selectedKey);
53
312
  return TerminalCollectionStateSchema.parse({
54
313
  ...current,
55
314
  keys,
56
- selectedKey: selectedKey2,
315
+ selectedKey,
57
316
  start: reveal(current.start, current.capacity, index, keys.length)
58
317
  });
59
318
  }
60
319
  if (action.type === "resize") {
61
- const capacity = z.int().positive().parse(action.capacity);
320
+ const capacity = z4.int().positive().parse(action.capacity);
62
321
  const index = current.selectedKey === null ? -1 : current.keys.indexOf(current.selectedKey);
63
322
  return TerminalCollectionStateSchema.parse({
64
323
  ...current,
@@ -95,72 +354,12 @@ function visibleTerminalCollectionRange(state) {
95
354
  end: Math.min(parsed.keys.length, parsed.start + parsed.capacity)
96
355
  };
97
356
  }
98
- // src/core/command-palette.ts
99
- import { z as z2 } from "zod";
100
- var TerminalCommandDescriptorSchema = z2.object({
101
- id: z2.string().regex(/^[a-z][a-z0-9-]*$/),
102
- aliases: z2.array(z2.string().min(1)).default([]),
103
- label: z2.string().min(1),
104
- description: z2.string().default("")
105
- }).strict();
106
- var TerminalCommandPaletteStateSchema = z2.object({
107
- query: z2.string(),
108
- selectedIndex: z2.int().nonnegative(),
109
- dismissed: z2.boolean()
110
- }).strict();
111
- function validateTerminalCommands(commands) {
112
- const parsed = commands.map((command) => TerminalCommandDescriptorSchema.parse(command));
113
- const owners = new Map;
114
- for (const command of parsed) {
115
- for (const name of [command.id, ...command.aliases]) {
116
- const owner = owners.get(name);
117
- if (owner)
118
- throw new Error(`Terminal command ${name} collides with ${owner}`);
119
- owners.set(name, command.id);
120
- }
121
- }
122
- return parsed;
123
- }
124
- function createTerminalCommandPalette() {
125
- return { query: "", selectedIndex: 0, dismissed: false };
126
- }
127
- function setTerminalCommandQuery(state, query) {
128
- TerminalCommandPaletteStateSchema.parse(state);
129
- return { query, selectedIndex: 0, dismissed: false };
130
- }
131
- function dismissTerminalCommandPalette(state) {
132
- return { ...TerminalCommandPaletteStateSchema.parse(state), dismissed: true };
133
- }
134
- function terminalCommandMatches(state, commands, limit = 20) {
135
- const current = TerminalCommandPaletteStateSchema.parse(state);
136
- if (current.dismissed)
137
- return [];
138
- const parsed = validateTerminalCommands(commands);
139
- const query = current.query.toLowerCase();
140
- return parsed.filter((command) => command.id.includes(query) || command.label.toLowerCase().includes(query) || command.aliases.some((alias) => alias.includes(query))).slice(0, z2.int().positive().parse(limit));
141
- }
142
- function moveTerminalCommandSelection(state, delta, matchCount) {
143
- const current = TerminalCommandPaletteStateSchema.parse(state);
144
- if (matchCount <= 0)
145
- return { ...current, selectedIndex: 0 };
146
- return {
147
- ...current,
148
- selectedIndex: ((current.selectedIndex + delta) % matchCount + matchCount) % matchCount
149
- };
150
- }
151
- function selectedTerminalCommand(state, commands, limit = 20) {
152
- const matches = terminalCommandMatches(state, commands, limit);
153
- return matches[state.selectedIndex] ?? matches[0];
154
- }
155
- function resolveExactTerminalCommand(name, commands) {
156
- return validateTerminalCommands(commands).find((command) => command.id === name || command.aliases.includes(name));
157
- }
158
357
  // src/core/operation.ts
159
- import { z as z3 } from "zod";
160
- var TerminalOperationStateSchema = z3.object({
161
- status: z3.enum(["idle", "confirming", "pending", "succeeded", "failed"]),
162
- operationId: z3.string().min(1).nullable(),
163
- message: z3.string().optional()
358
+ import { z as z5 } from "zod";
359
+ var TerminalOperationStateSchema = z5.object({
360
+ status: z5.enum(["idle", "confirming", "pending", "succeeded", "failed"]),
361
+ operationId: z5.string().min(1).nullable(),
362
+ message: z5.string().optional()
164
363
  }).strict();
165
364
  function createTerminalOperationState() {
166
365
  return { status: "idle", operationId: null };
@@ -198,27 +397,27 @@ function reduceTerminalOperationState(state, action) {
198
397
  });
199
398
  }
200
399
  // src/core/panes.ts
201
- import { z as z4 } from "zod";
202
- var TerminalPaneIdSchema = z4.enum(["primary", "secondary"]);
203
- var TerminalPaneModeSchema = z4.enum(["split", "single"]);
204
- var TerminalPaneStateSchema = z4.object({
400
+ import { z as z6 } from "zod";
401
+ var TerminalPaneIdSchema = z6.enum(["primary", "secondary"]);
402
+ var TerminalPaneModeSchema = z6.enum(["split", "single"]);
403
+ var TerminalPaneStateSchema = z6.object({
205
404
  mode: TerminalPaneModeSchema,
206
405
  focus: TerminalPaneIdSchema,
207
- primarySize: z4.int().positive(),
208
- totalSize: z4.int().positive(),
209
- minPrimary: z4.int().positive(),
210
- minSecondary: z4.int().positive()
406
+ primarySize: z6.int().positive(),
407
+ totalSize: z6.int().positive(),
408
+ minPrimary: z6.int().positive(),
409
+ minSecondary: z6.int().positive()
211
410
  }).strict();
212
411
  function clampPrimary(input) {
213
412
  const maximum = Math.max(input.minPrimary, input.totalSize - input.minSecondary);
214
413
  return Math.min(Math.max(input.minPrimary, input.primarySize), maximum);
215
414
  }
216
415
  function createTerminalPaneState(input) {
217
- const values = z4.object({
218
- totalSize: z4.int().positive(),
219
- primarySize: z4.int().positive(),
220
- minPrimary: z4.int().positive(),
221
- minSecondary: z4.int().positive(),
416
+ const values = z6.object({
417
+ totalSize: z6.int().positive(),
418
+ primarySize: z6.int().positive(),
419
+ minPrimary: z6.int().positive(),
420
+ minSecondary: z6.int().positive(),
222
421
  mode: TerminalPaneModeSchema.default("split"),
223
422
  focus: TerminalPaneIdSchema.default("primary")
224
423
  }).strict().parse(input);
@@ -263,20 +462,20 @@ function visibleTerminalPanes(state) {
263
462
  return parsed.mode === "split" ? ["primary", "secondary"] : [parsed.focus];
264
463
  }
265
464
  // src/core/viewport.ts
266
- import { z as z5 } from "zod";
267
- var TerminalFeedViewportSchema = z5.object({
268
- total: z5.int().nonnegative(),
269
- capacity: z5.int().positive(),
270
- start: z5.int().nonnegative(),
271
- followTail: z5.boolean(),
272
- unseen: z5.int().nonnegative()
465
+ import { z as z7 } from "zod";
466
+ var TerminalFeedViewportSchema = z7.object({
467
+ total: z7.int().nonnegative(),
468
+ capacity: z7.int().positive(),
469
+ start: z7.int().nonnegative(),
470
+ followTail: z7.boolean(),
471
+ unseen: z7.int().nonnegative()
273
472
  }).strict();
274
473
  function maximumStart2(total, capacity) {
275
474
  return Math.max(0, total - capacity);
276
475
  }
277
476
  function createTerminalFeedViewport(total, capacity) {
278
- const parsedTotal = z5.int().nonnegative().parse(total);
279
- const parsedCapacity = z5.int().positive().parse(capacity);
477
+ const parsedTotal = z7.int().nonnegative().parse(total);
478
+ const parsedCapacity = z7.int().positive().parse(capacity);
280
479
  return TerminalFeedViewportSchema.parse({
281
480
  total: parsedTotal,
282
481
  capacity: parsedCapacity,
@@ -306,7 +505,7 @@ function reduceTerminalFeedViewport(state, action) {
306
505
  });
307
506
  }
308
507
  if (action.type === "resize") {
309
- const capacity = z5.int().positive().parse(action.capacity);
508
+ const capacity = z7.int().positive().parse(action.capacity);
310
509
  return TerminalFeedViewportSchema.parse({
311
510
  ...current,
312
511
  capacity,
@@ -332,202 +531,6 @@ function visibleTerminalFeedRange(state) {
332
531
  const parsed = TerminalFeedViewportSchema.parse(state);
333
532
  return { start: parsed.start, end: Math.min(parsed.total, parsed.start + parsed.capacity) };
334
533
  }
335
- // src/cli.ts
336
- import path6 from "path";
337
- import { pathToFileURL } from "url";
338
-
339
- // src/run.tsx
340
- import path5 from "path";
341
- import { createCliRenderer } from "@opentui/core";
342
- import { createRoot } from "@opentui/react";
343
-
344
- // src/App.tsx
345
- import { useKeyboard, useTerminalDimensions } from "@opentui/react";
346
- import { useCallback, useEffect, useMemo, useRef, useState } from "react";
347
-
348
- // src/commands.ts
349
- import { z as z6 } from "zod";
350
- var AgentTuiCommandOutcomeSchema = z6.discriminatedUnion("type", [
351
- z6.object({ type: z6.literal("submit"), text: z6.string().min(1) }).strict(),
352
- z6.object({
353
- type: z6.literal("dialog"),
354
- dialog: z6.string().min(1),
355
- query: z6.string().optional()
356
- }).strict(),
357
- z6.object({ type: z6.literal("notice"), message: z6.string() }).strict(),
358
- z6.object({ type: z6.literal("action"), action: z6.string().min(1) }).strict()
359
- ]);
360
- function defineTuiCommand(command) {
361
- if (!/^[a-z][a-z0-9-]*$/.test(command.name)) {
362
- throw new Error("TUI command names use lowercase letters, digits and hyphens");
363
- }
364
- for (const alias of command.aliases ?? []) {
365
- if (alias !== "?" && !/^[a-z][a-z0-9-]*$/.test(alias)) {
366
- throw new Error("TUI command aliases are invalid");
367
- }
368
- }
369
- return command;
370
- }
371
- function composeTuiCommands(...groups) {
372
- const commands = groups.flat();
373
- validateTerminalCommands(commands.map((command) => ({
374
- id: defineTuiCommand(command).name,
375
- aliases: [...command.aliases ?? []],
376
- label: command.name,
377
- description: command.description
378
- })));
379
- return commands;
380
- }
381
- function resolveTuiCommand(text, commands) {
382
- if (!text.startsWith("/"))
383
- return { type: "prompt", text };
384
- const match = /^\/([^\s]+)(?:\s+([\s\S]*))?$/.exec(text);
385
- const name = match?.[1];
386
- if (!name)
387
- return { type: "prompt", text };
388
- const command = commands.find((candidate) => candidate.name === name || candidate.aliases?.includes(name));
389
- return command ? { type: "command", command, argumentsText: match?.[2] ?? "" } : { type: "prompt", text };
390
- }
391
- function commandCompletions(text, commands) {
392
- if (!text.startsWith("/") || text.slice(1).includes(" "))
393
- return [];
394
- const state = setTerminalCommandQuery(createTerminalCommandPalette(), text.slice(1));
395
- const descriptors = terminalCommandMatches(state, commands.map((command) => ({
396
- id: command.name,
397
- aliases: [...command.aliases ?? []],
398
- label: command.name,
399
- description: command.description
400
- })), Math.max(1, commands.length));
401
- return descriptors.map((descriptor) => commands.find((command) => command.name === descriptor.id)).filter((command) => command !== undefined);
402
- }
403
- function selectedCommandCompletion(text, commands, selectedIndex) {
404
- const completions = commandCompletions(text, commands);
405
- return completions[selectedIndex] ?? completions[0];
406
- }
407
- function moveCommandCompletionSelection(selectedIndex, direction, completionCount) {
408
- if (completionCount <= 0)
409
- return 0;
410
- return moveTerminalCommandSelection({ query: "", selectedIndex, dismissed: false }, direction === "previous" ? -1 : 1, completionCount).selectedIndex;
411
- }
412
- function resolveTuiCommandSubmission(text, commands, selectedIndex, paletteDismissed = false) {
413
- const completion = paletteDismissed ? undefined : selectedCommandCompletion(text, commands, selectedIndex);
414
- return resolveTuiCommand(completion ? `/${completion.name}` : text, commands);
415
- }
416
-
417
- // src/builtins.ts
418
- var dialog = (name, query) => ({
419
- type: "dialog",
420
- dialog: name,
421
- ...query && { query }
422
- });
423
- var action = (name) => ({ type: "action", action: name });
424
- function createAgentTuiBuiltinCommands() {
425
- return [
426
- defineTuiCommand({
427
- name: "help",
428
- aliases: ["?"],
429
- description: "Show available terminal commands",
430
- execute: () => dialog("help")
431
- }),
432
- defineTuiCommand({
433
- name: "model",
434
- description: "Choose the model for the next run",
435
- execute: (query) => dialog("model", query.trim())
436
- }),
437
- defineTuiCommand({
438
- name: "new",
439
- description: "Start a new durable conversation",
440
- execute: () => action("new-conversation")
441
- }),
442
- defineTuiCommand({
443
- name: "sessions",
444
- description: "Browse durable conversations",
445
- execute: () => dialog("sessions")
446
- }),
447
- defineTuiCommand({
448
- name: "resume",
449
- description: "Resume a durable conversation",
450
- execute: () => dialog("sessions")
451
- }),
452
- defineTuiCommand({
453
- name: "status",
454
- description: "Show session, conversation and run status",
455
- execute: () => dialog("status")
456
- }),
457
- defineTuiCommand({
458
- name: "tools",
459
- description: "Show the direct tool surface",
460
- execute: () => dialog("tools")
461
- }),
462
- defineTuiCommand({
463
- name: "skills",
464
- description: "Show lazily available skills and resources",
465
- execute: () => dialog("skills")
466
- }),
467
- defineTuiCommand({
468
- name: "permissions",
469
- description: "Show approval and sandbox enforcement",
470
- execute: () => dialog("permissions")
471
- }),
472
- defineTuiCommand({
473
- name: "interrupt",
474
- description: "Interrupt the active run",
475
- available: ({ activeRunId }) => activeRunId !== undefined,
476
- execute: () => action("interrupt")
477
- }),
478
- defineTuiCommand({
479
- name: "clear",
480
- description: "Start clean while keeping this conversation available to resume",
481
- execute: () => action("clear-conversation")
482
- }),
483
- defineTuiCommand({
484
- name: "quit",
485
- aliases: ["exit"],
486
- description: "Close this terminal host",
487
- execute: () => action("quit")
488
- })
489
- ];
490
- }
491
-
492
- // src/composer.ts
493
- import { z as z7 } from "zod";
494
- var AgentTuiComposerSchema = z7.object({
495
- draft: z7.string(),
496
- history: z7.array(z7.string()),
497
- historyIndex: z7.int().nonnegative().optional(),
498
- preservedDraft: z7.string()
499
- }).strict();
500
- function createAgentTuiComposer() {
501
- return { draft: "", history: [], preservedDraft: "" };
502
- }
503
- function setAgentTuiDraft(state, draft) {
504
- const { historyIndex: _historyIndex, ...rest } = state;
505
- return { ...rest, draft, preservedDraft: draft };
506
- }
507
- function submitAgentTuiComposer(state) {
508
- const text = state.draft.trim();
509
- if (!text)
510
- return { state };
511
- const history = state.history.at(-1) === text ? state.history : [...state.history, text];
512
- return { state: { draft: "", history, preservedDraft: "" }, text };
513
- }
514
- function navigateAgentTuiHistory(state, direction) {
515
- if (state.history.length === 0)
516
- return state;
517
- if (direction === "older") {
518
- const index2 = state.historyIndex === undefined ? state.history.length - 1 : Math.max(0, state.historyIndex - 1);
519
- return { ...state, historyIndex: index2, draft: state.history[index2] ?? state.draft };
520
- }
521
- if (state.historyIndex === undefined)
522
- return state;
523
- const index = state.historyIndex + 1;
524
- if (index >= state.history.length) {
525
- const { historyIndex: _historyIndex, ...rest } = state;
526
- return { ...rest, draft: state.preservedDraft };
527
- }
528
- return { ...state, historyIndex: index, draft: state.history[index] ?? state.draft };
529
- }
530
-
531
534
  // src/keyboard.ts
532
535
  function isAgentTuiExitKey(key) {
533
536
  return key.ctrl === true && key.name?.toLowerCase() === "c";
@@ -688,9 +691,9 @@ async function listAgentTuiSessions(rootDirectory) {
688
691
  return descriptors;
689
692
  }
690
693
  async function startAgentTuiSessionHost(input) {
691
- for (const descriptor2 of await listAgentTuiSessions(input.rootDirectory)) {
692
- if (!processAlive(descriptor2.pid))
693
- await removeDescriptor(input.rootDirectory, descriptor2);
694
+ for (const descriptor of await listAgentTuiSessions(input.rootDirectory)) {
695
+ if (!processAlive(descriptor.pid))
696
+ await removeDescriptor(input.rootDirectory, descriptor);
694
697
  }
695
698
  const sessionId = input.sessionId ?? createAgentTuiSessionId();
696
699
  const socketPath = path.join(sessionsDirectory(input.rootDirectory), `${sessionId}.sock`);
@@ -914,7 +917,7 @@ function projectAgentTuiTranscript(snapshot) {
914
917
  }
915
918
 
916
919
  // src/App.tsx
917
- import { jsxDEV } from "@opentui/react/jsx-dev-runtime";
920
+ import { jsx, jsxs } from "@opentui/react/jsx-runtime";
918
921
  function isDialog(value) {
919
922
  return ["help", "model", "sessions", "status", "tools", "skills", "permissions"].includes(value);
920
923
  }
@@ -924,12 +927,12 @@ function isString(value) {
924
927
  function errorMessage(error) {
925
928
  return error instanceof Error ? error.message : String(error);
926
929
  }
927
- function roleLabel(role2) {
928
- if (role2 === "you")
930
+ function roleLabel(role) {
931
+ if (role === "you")
929
932
  return "YOU";
930
- if (role2 === "agent")
933
+ if (role === "agent")
931
934
  return "AGENT";
932
- if (role2 === "tool")
935
+ if (role === "tool")
933
936
  return "TOOL";
934
937
  return "SYSTEM";
935
938
  }
@@ -968,7 +971,7 @@ function AgentTuiApp({
968
971
  }) {
969
972
  const dimensions = useTerminalDimensions();
970
973
  const [state, setState] = useState(controller.state());
971
- const [dialog2, setDialog] = useState();
974
+ const [dialog, setDialog] = useState();
972
975
  const [modelQuery, setModelQuery] = useState("");
973
976
  const [modelSearchFocused, setModelSearchFocused] = useState(true);
974
977
  const [composer, setComposer] = useState(createAgentTuiComposer);
@@ -979,7 +982,7 @@ function AgentTuiApp({
979
982
  const [hiddenBefore, setHiddenBefore] = useState(0);
980
983
  const [sessions, setSessions] = useState([]);
981
984
  const [sessionCursor, setSessionCursor] = useState();
982
- const [viewport2, setViewport] = useState(() => createTerminalFeedViewport(0, 1));
985
+ const [viewport, setViewport] = useState(() => createTerminalFeedViewport(0, 1));
983
986
  const previousTranscriptSize = useRef(0);
984
987
  const previousConversationId = useRef(state.conversationId);
985
988
  const composerRef = useRef(null);
@@ -1035,13 +1038,13 @@ function AgentTuiApp({
1035
1038
  });
1036
1039
  }, [dimensions.height, state.conversationId, transcriptUnits]);
1037
1040
  useEffect(() => {
1038
- if (dialog2 !== "sessions" || !conversations)
1041
+ if (dialog !== "sessions" || !conversations)
1039
1042
  return;
1040
1043
  conversations.list({ limit: 50 }).then((page) => {
1041
1044
  setSessions(page.items);
1042
1045
  setSessionCursor(page.nextCursor);
1043
1046
  }).catch((error) => setLocalNotice(errorMessage(error)));
1044
- }, [conversations, dialog2]);
1047
+ }, [conversations, dialog]);
1045
1048
  const applyOutcome = useCallback(async (outcome) => {
1046
1049
  if (outcome.type === "dialog") {
1047
1050
  setDialog(isDialog(outcome.dialog) ? outcome.dialog : "help");
@@ -1125,30 +1128,30 @@ function AgentTuiApp({
1125
1128
  controller.respondToApproval(false, "Denied from the terminal host").catch((error) => setLocalNotice(errorMessage(error)));
1126
1129
  return;
1127
1130
  }
1128
- if (dialog2 && key.name === "escape") {
1131
+ if (dialog && key.name === "escape") {
1129
1132
  setDialog(undefined);
1130
1133
  return;
1131
1134
  }
1132
- if (dialog2 === "model" && key.name === "tab") {
1135
+ if (dialog === "model" && key.name === "tab") {
1133
1136
  key.preventDefault();
1134
1137
  key.stopPropagation();
1135
1138
  setModelSearchFocused((focused) => !focused);
1136
1139
  return;
1137
1140
  }
1138
- if (!dialog2 && completions.length > 0 && key.name === "escape") {
1141
+ if (!dialog && completions.length > 0 && key.name === "escape") {
1139
1142
  key.preventDefault();
1140
1143
  key.stopPropagation();
1141
1144
  setDismissedCompletionDraft(draft);
1142
1145
  return;
1143
1146
  }
1144
- if (!dialog2 && completions.length > 0 && (key.name === "up" || key.name === "down")) {
1147
+ if (!dialog && completions.length > 0 && (key.name === "up" || key.name === "down")) {
1145
1148
  key.preventDefault();
1146
1149
  key.stopPropagation();
1147
1150
  const direction = key.name === "up" ? -1 : 1;
1148
1151
  setCompletionIndex((current) => moveCommandCompletionSelection(current, direction === -1 ? "previous" : "next", completions.length));
1149
1152
  return;
1150
1153
  }
1151
- if (!dialog2 && key.name === "tab" && completions[0]) {
1154
+ if (!dialog && key.name === "tab" && completions[0]) {
1152
1155
  key.preventDefault();
1153
1156
  key.stopPropagation();
1154
1157
  const selected = completions[completionIndex] ?? completions[0];
@@ -1159,28 +1162,28 @@ function AgentTuiApp({
1159
1162
  setDismissedCompletionDraft(undefined);
1160
1163
  return;
1161
1164
  }
1162
- if (!dialog2 && key.name === "pageup") {
1165
+ if (!dialog && key.name === "pageup") {
1163
1166
  transcriptRef.current?.scrollBy(-0.8, "viewport");
1164
1167
  setViewport((current) => reduceTerminalFeedViewport(current, { type: "page", pages: -1 }));
1165
1168
  }
1166
- if (!dialog2 && key.name === "pagedown") {
1169
+ if (!dialog && key.name === "pagedown") {
1167
1170
  transcriptRef.current?.scrollBy(0.8, "viewport");
1168
1171
  setViewport((current) => reduceTerminalFeedViewport(current, { type: "page", pages: 1 }));
1169
1172
  }
1170
- if (!dialog2 && key.option && (key.name === "up" || key.name === "down")) {
1173
+ if (!dialog && key.option && (key.name === "up" || key.name === "down")) {
1171
1174
  const lines = key.name === "up" ? -1 : 1;
1172
1175
  transcriptRef.current?.scrollBy(lines, "step");
1173
1176
  setViewport((current) => reduceTerminalFeedViewport(current, { type: "scroll", lines }));
1174
1177
  }
1175
- if (!dialog2 && key.name === "home" && key.ctrl) {
1178
+ if (!dialog && key.name === "home" && key.ctrl) {
1176
1179
  transcriptRef.current?.scrollTo(0);
1177
1180
  setViewport((current) => reduceTerminalFeedViewport(current, { type: "home" }));
1178
1181
  }
1179
- if (!dialog2 && key.name === "end" && key.ctrl) {
1182
+ if (!dialog && key.name === "end" && key.ctrl) {
1180
1183
  transcriptRef.current?.scrollTo(Number.MAX_SAFE_INTEGER);
1181
1184
  setViewport((current) => reduceTerminalFeedViewport(current, { type: "end" }));
1182
1185
  }
1183
- if (!dialog2 && key.ctrl && (key.name === "up" || key.name === "down")) {
1186
+ if (!dialog && key.ctrl && (key.name === "up" || key.name === "down")) {
1184
1187
  const next = navigateAgentTuiHistory(composer, key.name === "up" ? "older" : "newer");
1185
1188
  composerRef.current?.setText(next.draft);
1186
1189
  setComposer(next);
@@ -1196,14 +1199,14 @@ function AgentTuiApp({
1196
1199
  };
1197
1200
  });
1198
1201
  const selectedModelIndex = Math.max(0, visibleModels.models.findIndex(({ id }) => id === state.selectedModelId));
1199
- return /* @__PURE__ */ jsxDEV("box", {
1202
+ return /* @__PURE__ */ jsxs("box", {
1200
1203
  style: {
1201
1204
  width: "100%",
1202
1205
  height: "100%",
1203
1206
  flexDirection: "column"
1204
1207
  },
1205
1208
  children: [
1206
- /* @__PURE__ */ jsxDEV("box", {
1209
+ /* @__PURE__ */ jsxs("box", {
1207
1210
  style: {
1208
1211
  height: 1,
1209
1212
  paddingLeft: compact ? 1 : 2,
@@ -1212,28 +1215,28 @@ function AgentTuiApp({
1212
1215
  flexDirection: "row"
1213
1216
  },
1214
1217
  children: [
1215
- /* @__PURE__ */ jsxDEV("text", {
1218
+ /* @__PURE__ */ jsx("text", {
1216
1219
  fg: theme.accent,
1217
- children: /* @__PURE__ */ jsxDEV("strong", {
1220
+ children: /* @__PURE__ */ jsxs("strong", {
1218
1221
  children: [
1219
1222
  "\u25C6 ",
1220
1223
  title
1221
1224
  ]
1222
- }, undefined, true, undefined, this)
1223
- }, undefined, false, undefined, this),
1224
- !compact ? /* @__PURE__ */ jsxDEV("text", {
1225
+ })
1226
+ }),
1227
+ !compact ? /* @__PURE__ */ jsxs("text", {
1225
1228
  fg: theme.muted,
1226
1229
  children: [
1227
1230
  " \xB7 ",
1228
1231
  selectedModel?.name ?? state.selectedModelId
1229
1232
  ]
1230
- }, undefined, true, undefined, this) : null
1233
+ }) : null
1231
1234
  ]
1232
- }, undefined, true, undefined, this),
1233
- /* @__PURE__ */ jsxDEV("scrollbox", {
1235
+ }),
1236
+ /* @__PURE__ */ jsxs("scrollbox", {
1234
1237
  ref: transcriptRef,
1235
- focused: !dialog2 && !state.pendingApproval,
1236
- stickyScroll: viewport2.followTail,
1238
+ focused: !dialog && !state.pendingApproval,
1239
+ stickyScroll: viewport.followTail,
1237
1240
  stickyStart: "bottom",
1238
1241
  style: {
1239
1242
  flexGrow: 1,
@@ -1244,53 +1247,53 @@ function AgentTuiApp({
1244
1247
  scrollbarOptions: { visible: !compact }
1245
1248
  },
1246
1249
  children: [
1247
- entries.length === 0 ? /* @__PURE__ */ jsxDEV("box", {
1250
+ entries.length === 0 ? /* @__PURE__ */ jsxs("box", {
1248
1251
  style: { flexDirection: "column", paddingTop: 1 },
1249
1252
  children: [
1250
- /* @__PURE__ */ jsxDEV("text", {
1253
+ /* @__PURE__ */ jsx("text", {
1251
1254
  fg: theme.primary,
1252
- children: /* @__PURE__ */ jsxDEV("strong", {
1255
+ children: /* @__PURE__ */ jsx("strong", {
1253
1256
  children: "What do you want to build?"
1254
- }, undefined, false, undefined, this)
1255
- }, undefined, false, undefined, this),
1256
- /* @__PURE__ */ jsxDEV("text", {
1257
+ })
1258
+ }),
1259
+ /* @__PURE__ */ jsx("text", {
1257
1260
  fg: theme.muted,
1258
1261
  children: "Type / for commands"
1259
- }, undefined, false, undefined, this)
1262
+ })
1260
1263
  ]
1261
- }, undefined, true, undefined, this) : entries.map((entry) => /* @__PURE__ */ jsxDEV("box", {
1264
+ }) : entries.map((entry) => /* @__PURE__ */ jsxs("box", {
1262
1265
  style: { flexDirection: "column", marginBottom: 1 },
1263
1266
  children: [
1264
- /* @__PURE__ */ jsxDEV("text", {
1267
+ /* @__PURE__ */ jsx("text", {
1265
1268
  fg: entry.role === "you" ? theme.accent : theme.muted,
1266
- children: /* @__PURE__ */ jsxDEV("strong", {
1269
+ children: /* @__PURE__ */ jsx("strong", {
1267
1270
  children: roleLabel(entry.role)
1268
- }, undefined, false, undefined, this)
1269
- }, undefined, false, undefined, this),
1270
- /* @__PURE__ */ jsxDEV("text", {
1271
+ })
1272
+ }),
1273
+ /* @__PURE__ */ jsx("text", {
1271
1274
  fg: toneColor(entry.tone, theme),
1272
1275
  children: entry.text
1273
- }, undefined, false, undefined, this)
1276
+ })
1274
1277
  ]
1275
- }, entry.id, true, undefined, this)),
1276
- Object.entries(state.streaming).map(([streamRunId, text]) => /* @__PURE__ */ jsxDEV("box", {
1278
+ }, entry.id)),
1279
+ Object.entries(state.streaming).map(([streamRunId, text]) => /* @__PURE__ */ jsxs("box", {
1277
1280
  style: { flexDirection: "column", marginBottom: 1 },
1278
1281
  children: [
1279
- /* @__PURE__ */ jsxDEV("text", {
1282
+ /* @__PURE__ */ jsx("text", {
1280
1283
  fg: theme.muted,
1281
- children: /* @__PURE__ */ jsxDEV("strong", {
1284
+ children: /* @__PURE__ */ jsx("strong", {
1282
1285
  children: "AGENT \xB7 STREAMING"
1283
- }, undefined, false, undefined, this)
1284
- }, undefined, false, undefined, this),
1285
- /* @__PURE__ */ jsxDEV("text", {
1286
+ })
1287
+ }),
1288
+ /* @__PURE__ */ jsx("text", {
1286
1289
  fg: theme.primary,
1287
1290
  children: text
1288
- }, undefined, false, undefined, this)
1291
+ })
1289
1292
  ]
1290
- }, streamRunId, true, undefined, this))
1293
+ }, streamRunId))
1291
1294
  ]
1292
- }, undefined, true, undefined, this),
1293
- state.pendingApproval ? /* @__PURE__ */ jsxDEV("box", {
1295
+ }),
1296
+ state.pendingApproval ? /* @__PURE__ */ jsxs("box", {
1294
1297
  title: " APPROVAL ",
1295
1298
  titleColor: theme.warning,
1296
1299
  style: {
@@ -1304,25 +1307,25 @@ function AgentTuiApp({
1304
1307
  flexDirection: "column"
1305
1308
  },
1306
1309
  children: [
1307
- /* @__PURE__ */ jsxDEV("text", {
1310
+ /* @__PURE__ */ jsx("text", {
1308
1311
  fg: theme.primary,
1309
- children: /* @__PURE__ */ jsxDEV("strong", {
1312
+ children: /* @__PURE__ */ jsx("strong", {
1310
1313
  children: state.pendingApproval.toolName
1311
- }, undefined, false, undefined, this)
1312
- }, undefined, false, undefined, this),
1313
- /* @__PURE__ */ jsxDEV("text", {
1314
+ })
1315
+ }),
1316
+ /* @__PURE__ */ jsx("text", {
1314
1317
  fg: theme.muted,
1315
1318
  children: JSON.stringify(state.pendingApproval.input).slice(0, 240)
1316
- }, undefined, false, undefined, this),
1317
- /* @__PURE__ */ jsxDEV("text", {
1319
+ }),
1320
+ /* @__PURE__ */ jsx("text", {
1318
1321
  fg: theme.warning,
1319
1322
  children: "Y approve once \xB7 N / Esc deny"
1320
- }, undefined, false, undefined, this)
1323
+ })
1321
1324
  ]
1322
- }, undefined, true, undefined, this) : /* @__PURE__ */ jsxDEV("box", {
1325
+ }) : /* @__PURE__ */ jsxs("box", {
1323
1326
  style: { flexDirection: "column" },
1324
1327
  children: [
1325
- completions.length > 0 ? /* @__PURE__ */ jsxDEV("box", {
1328
+ completions.length > 0 ? /* @__PURE__ */ jsx("box", {
1326
1329
  style: {
1327
1330
  maxHeight: 7,
1328
1331
  marginLeft: compact ? 1 : 2,
@@ -1331,49 +1334,49 @@ function AgentTuiApp({
1331
1334
  borderColor: theme.border,
1332
1335
  flexDirection: "column"
1333
1336
  },
1334
- children: completions.map((command, index) => /* @__PURE__ */ jsxDEV("box", {
1337
+ children: completions.map((command, index) => /* @__PURE__ */ jsx("box", {
1335
1338
  style: {
1336
1339
  paddingLeft: 1,
1337
1340
  ...index === completionIndex && {
1338
1341
  backgroundColor: theme.panelRaised
1339
1342
  }
1340
1343
  },
1341
- children: /* @__PURE__ */ jsxDEV("text", {
1344
+ children: /* @__PURE__ */ jsxs("text", {
1342
1345
  fg: index === completionIndex ? theme.primary : theme.muted,
1343
1346
  children: [
1344
- /* @__PURE__ */ jsxDEV("span", {
1347
+ /* @__PURE__ */ jsxs("span", {
1345
1348
  fg: theme.accent,
1346
1349
  children: [
1347
1350
  index === completionIndex ? "\u203A" : " ",
1348
1351
  " /",
1349
1352
  command.name
1350
1353
  ]
1351
- }, undefined, true, undefined, this),
1354
+ }),
1352
1355
  " ",
1353
1356
  command.description
1354
1357
  ]
1355
- }, undefined, true, undefined, this)
1356
- }, command.name, false, undefined, this))
1357
- }, undefined, false, undefined, this) : null,
1358
- /* @__PURE__ */ jsxDEV("box", {
1358
+ })
1359
+ }, command.name))
1360
+ }) : null,
1361
+ /* @__PURE__ */ jsxs("box", {
1359
1362
  style: {
1360
1363
  height: 3,
1361
1364
  marginLeft: compact ? 1 : 2,
1362
1365
  marginRight: compact ? 1 : 2,
1363
1366
  border: ["top", "bottom"],
1364
- borderColor: dialog2 ? theme.border : theme.borderActive,
1367
+ borderColor: dialog ? theme.border : theme.borderActive,
1365
1368
  paddingLeft: 1,
1366
1369
  paddingRight: 1,
1367
1370
  flexDirection: "row"
1368
1371
  },
1369
1372
  children: [
1370
- /* @__PURE__ */ jsxDEV("text", {
1371
- fg: dialog2 ? theme.muted : theme.accent,
1373
+ /* @__PURE__ */ jsx("text", {
1374
+ fg: dialog ? theme.muted : theme.accent,
1372
1375
  children: "\u203A "
1373
- }, undefined, false, undefined, this),
1374
- /* @__PURE__ */ jsxDEV("textarea", {
1376
+ }),
1377
+ /* @__PURE__ */ jsx("textarea", {
1375
1378
  ref: composerRef,
1376
- focused: !dialog2,
1379
+ focused: !dialog,
1377
1380
  placeholder: "Message the agent or type / for commands\u2026",
1378
1381
  initialValue: draft,
1379
1382
  wrapMode: "word",
@@ -1389,27 +1392,27 @@ function AgentTuiApp({
1389
1392
  },
1390
1393
  onSubmit: () => void submit(),
1391
1394
  style: { width: "100%", height: "100%" }
1392
- }, undefined, false, undefined, this)
1395
+ })
1393
1396
  ]
1394
- }, undefined, true, undefined, this)
1397
+ })
1395
1398
  ]
1396
- }, undefined, true, undefined, this),
1397
- localNotice || state.notice || viewport2.unseen > 0 ? /* @__PURE__ */ jsxDEV("box", {
1399
+ }),
1400
+ localNotice || state.notice || viewport.unseen > 0 ? /* @__PURE__ */ jsx("box", {
1398
1401
  style: { height: 1, paddingLeft: compact ? 1 : 2, paddingRight: 1 },
1399
- children: /* @__PURE__ */ jsxDEV("text", {
1402
+ children: /* @__PURE__ */ jsx("text", {
1400
1403
  fg: localNotice || state.notice ? theme.danger : theme.accent,
1401
- children: localNotice ?? state.notice?.message ?? `${viewport2.unseen} new messages`
1402
- }, undefined, false, undefined, this)
1403
- }, undefined, false, undefined, this) : null,
1404
- statusRows.length > 0 ? /* @__PURE__ */ jsxDEV("box", {
1404
+ children: localNotice ?? state.notice?.message ?? `${viewport.unseen} new messages`
1405
+ })
1406
+ }) : null,
1407
+ statusRows.length > 0 ? /* @__PURE__ */ jsx("box", {
1405
1408
  style: {
1406
1409
  height: statusRows.length,
1407
1410
  paddingLeft: compact ? 1 : 2,
1408
1411
  paddingRight: 1,
1409
1412
  flexDirection: "column"
1410
1413
  },
1411
- children: statusRows.map((row, rowIndex) => /* @__PURE__ */ jsxDEV("text", {
1412
- children: row.map((segment, segmentIndex) => /* @__PURE__ */ jsxDEV("span", {
1414
+ children: statusRows.map((row, rowIndex) => /* @__PURE__ */ jsx("text", {
1415
+ children: row.map((segment, segmentIndex) => /* @__PURE__ */ jsxs("span", {
1413
1416
  fg: statusToneColor(segment.tone, theme),
1414
1417
  bg: segmentIndex % 2 === 0 ? theme.panel : theme.panelRaised,
1415
1418
  children: [
@@ -1417,11 +1420,11 @@ function AgentTuiApp({
1417
1420
  segment.text,
1418
1421
  " "
1419
1422
  ]
1420
- }, `${segment.text}-${segmentIndex}`, true, undefined, this))
1421
- }, `status-${rowIndex}`, false, undefined, this))
1422
- }, undefined, false, undefined, this) : null,
1423
- dialog2 ? /* @__PURE__ */ jsxDEV("box", {
1424
- title: ` ${dialog2.toUpperCase()} `,
1423
+ }, `${segment.text}-${segmentIndex}`))
1424
+ }, `status-${rowIndex}`))
1425
+ }) : null,
1426
+ dialog ? /* @__PURE__ */ jsxs("box", {
1427
+ title: ` ${dialog.toUpperCase()} `,
1425
1428
  titleColor: theme.accent,
1426
1429
  style: {
1427
1430
  position: "absolute",
@@ -1436,10 +1439,10 @@ function AgentTuiApp({
1436
1439
  flexDirection: "column"
1437
1440
  },
1438
1441
  children: [
1439
- dialog2 === "model" ? /* @__PURE__ */ jsxDEV("box", {
1442
+ dialog === "model" ? /* @__PURE__ */ jsxs("box", {
1440
1443
  style: { flexDirection: "column", width: "100%", height: "100%" },
1441
1444
  children: [
1442
- /* @__PURE__ */ jsxDEV("text", {
1445
+ /* @__PURE__ */ jsxs("text", {
1443
1446
  fg: theme.muted,
1444
1447
  children: [
1445
1448
  "Search the full catalog \xB7 showing ",
@@ -1449,8 +1452,8 @@ function AgentTuiApp({
1449
1452
  visibleModels.total,
1450
1453
  " matches \xB7 Tab switches search/list"
1451
1454
  ]
1452
- }, undefined, true, undefined, this),
1453
- /* @__PURE__ */ jsxDEV("box", {
1455
+ }),
1456
+ /* @__PURE__ */ jsx("box", {
1454
1457
  style: {
1455
1458
  height: 3,
1456
1459
  border: true,
@@ -1458,16 +1461,16 @@ function AgentTuiApp({
1458
1461
  paddingLeft: 1,
1459
1462
  paddingRight: 1
1460
1463
  },
1461
- children: /* @__PURE__ */ jsxDEV("input", {
1464
+ children: /* @__PURE__ */ jsx("input", {
1462
1465
  focused: modelSearchFocused,
1463
1466
  value: modelQuery,
1464
1467
  placeholder: "Filter by model, provider or capability\u2026",
1465
1468
  onInput: setModelQuery,
1466
1469
  onSubmit: () => setModelSearchFocused(false),
1467
1470
  style: { width: "100%" }
1468
- }, undefined, false, undefined, this)
1469
- }, undefined, false, undefined, this),
1470
- /* @__PURE__ */ jsxDEV("select", {
1471
+ })
1472
+ }),
1473
+ /* @__PURE__ */ jsx("select", {
1471
1474
  focused: !modelSearchFocused,
1472
1475
  options: modelOptions,
1473
1476
  selectedIndex: selectedModelIndex,
@@ -1487,9 +1490,9 @@ function AgentTuiApp({
1487
1490
  return;
1488
1491
  controller.selectModel(model.id).then(() => setDialog(undefined)).catch((error) => setLocalNotice(errorMessage(error)));
1489
1492
  }
1490
- }, undefined, false, undefined, this)
1493
+ })
1491
1494
  ]
1492
- }, undefined, true, undefined, this) : dialog2 === "sessions" ? conversations ? /* @__PURE__ */ jsxDEV("select", {
1495
+ }) : dialog === "sessions" ? conversations ? /* @__PURE__ */ jsx("select", {
1493
1496
  focused: true,
1494
1497
  options: sessions.map((session) => ({
1495
1498
  name: session.conversationId,
@@ -1514,113 +1517,113 @@ function AgentTuiApp({
1514
1517
  setHiddenBefore(0);
1515
1518
  }).catch((error) => setLocalNotice(errorMessage(error)));
1516
1519
  }
1517
- }, undefined, false, undefined, this) : /* @__PURE__ */ jsxDEV("text", {
1520
+ }) : /* @__PURE__ */ jsx("text", {
1518
1521
  fg: theme.muted,
1519
1522
  children: "This host does not provide a conversation catalog."
1520
- }, undefined, false, undefined, this) : dialog2 === "help" ? /* @__PURE__ */ jsxDEV("scrollbox", {
1523
+ }) : dialog === "help" ? /* @__PURE__ */ jsx("scrollbox", {
1521
1524
  focused: true,
1522
1525
  style: { flexGrow: 1, contentOptions: { flexDirection: "column" } },
1523
- children: commands.map((command) => /* @__PURE__ */ jsxDEV("text", {
1526
+ children: commands.map((command) => /* @__PURE__ */ jsxs("text", {
1524
1527
  fg: theme.primary,
1525
1528
  children: [
1526
- /* @__PURE__ */ jsxDEV("span", {
1529
+ /* @__PURE__ */ jsxs("span", {
1527
1530
  fg: theme.accent,
1528
1531
  children: [
1529
1532
  "/",
1530
1533
  command.name
1531
1534
  ]
1532
- }, undefined, true, undefined, this),
1535
+ }),
1533
1536
  " ",
1534
1537
  command.description
1535
1538
  ]
1536
- }, command.name, true, undefined, this))
1537
- }, undefined, false, undefined, this) : dialog2 === "status" ? /* @__PURE__ */ jsxDEV("box", {
1539
+ }, command.name))
1540
+ }) : dialog === "status" ? /* @__PURE__ */ jsxs("box", {
1538
1541
  style: { flexDirection: "column" },
1539
1542
  children: [
1540
- /* @__PURE__ */ jsxDEV("text", {
1543
+ /* @__PURE__ */ jsxs("text", {
1541
1544
  fg: theme.primary,
1542
1545
  children: [
1543
1546
  "Session ",
1544
1547
  sessionId
1545
1548
  ]
1546
- }, undefined, true, undefined, this),
1547
- /* @__PURE__ */ jsxDEV("text", {
1549
+ }),
1550
+ /* @__PURE__ */ jsxs("text", {
1548
1551
  fg: theme.primary,
1549
1552
  children: [
1550
1553
  "Conversation ",
1551
1554
  state.conversationId
1552
1555
  ]
1553
- }, undefined, true, undefined, this),
1554
- /* @__PURE__ */ jsxDEV("text", {
1556
+ }),
1557
+ /* @__PURE__ */ jsxs("text", {
1555
1558
  fg: theme.primary,
1556
1559
  children: [
1557
1560
  "Model ",
1558
1561
  state.selectedModelId
1559
1562
  ]
1560
- }, undefined, true, undefined, this),
1561
- /* @__PURE__ */ jsxDEV("text", {
1563
+ }),
1564
+ /* @__PURE__ */ jsxs("text", {
1562
1565
  fg: theme.primary,
1563
1566
  children: [
1564
1567
  "Run ",
1565
1568
  runId ?? "idle"
1566
1569
  ]
1567
- }, undefined, true, undefined, this),
1568
- /* @__PURE__ */ jsxDEV("text", {
1570
+ }),
1571
+ /* @__PURE__ */ jsx("text", {
1569
1572
  fg: theme.muted,
1570
1573
  children: "External clients submit through this host's controller."
1571
- }, undefined, false, undefined, this)
1574
+ })
1572
1575
  ]
1573
- }, undefined, true, undefined, this) : dialog2 === "tools" ? /* @__PURE__ */ jsxDEV("box", {
1576
+ }) : dialog === "tools" ? /* @__PURE__ */ jsxs("box", {
1574
1577
  style: { flexDirection: "column" },
1575
1578
  children: [
1576
1579
  [
1577
- ...new Set(entries.filter(({ role: role2 }) => role2 === "tool").map(({ text }) => text.split(" ")[1]).filter(isString))
1578
- ].map((name) => /* @__PURE__ */ jsxDEV("text", {
1580
+ ...new Set(entries.filter(({ role }) => role === "tool").map(({ text }) => text.split(" ")[1]).filter(isString))
1581
+ ].map((name) => /* @__PURE__ */ jsx("text", {
1579
1582
  fg: theme.primary,
1580
1583
  children: name
1581
- }, name, false, undefined, this)),
1582
- /* @__PURE__ */ jsxDEV("text", {
1584
+ }, name)),
1585
+ /* @__PURE__ */ jsx("text", {
1583
1586
  fg: theme.muted,
1584
1587
  children: "Direct tools retain their own durable identity."
1585
- }, undefined, false, undefined, this)
1588
+ })
1586
1589
  ]
1587
- }, undefined, true, undefined, this) : dialog2 === "permissions" ? /* @__PURE__ */ jsxDEV("box", {
1590
+ }) : dialog === "permissions" ? /* @__PURE__ */ jsxs("box", {
1588
1591
  style: { flexDirection: "column" },
1589
1592
  children: [
1590
- /* @__PURE__ */ jsxDEV("text", {
1593
+ /* @__PURE__ */ jsx("text", {
1591
1594
  fg: theme.primary,
1592
1595
  children: "Approval decisions are per exact tool call."
1593
- }, undefined, false, undefined, this),
1594
- /* @__PURE__ */ jsxDEV("text", {
1596
+ }),
1597
+ /* @__PURE__ */ jsx("text", {
1595
1598
  fg: theme.muted,
1596
1599
  children: "Sandbox enforcement is supplied and reported by the embedding host."
1597
- }, undefined, false, undefined, this)
1600
+ })
1598
1601
  ]
1599
- }, undefined, true, undefined, this) : /* @__PURE__ */ jsxDEV("box", {
1602
+ }) : /* @__PURE__ */ jsxs("box", {
1600
1603
  style: { flexDirection: "column" },
1601
1604
  children: [
1602
- /* @__PURE__ */ jsxDEV("text", {
1605
+ /* @__PURE__ */ jsx("text", {
1603
1606
  fg: theme.primary,
1604
1607
  children: "Skills and resources are discovered lazily by the harness."
1605
- }, undefined, false, undefined, this),
1606
- /* @__PURE__ */ jsxDEV("text", {
1608
+ }),
1609
+ /* @__PURE__ */ jsx("text", {
1607
1610
  fg: theme.muted,
1608
1611
  children: "The model reads exact content through the direct read_resource tool."
1609
- }, undefined, false, undefined, this)
1612
+ })
1610
1613
  ]
1611
- }, undefined, true, undefined, this),
1612
- dialog2 === "sessions" && sessionCursor ? /* @__PURE__ */ jsxDEV("text", {
1614
+ }),
1615
+ dialog === "sessions" && sessionCursor ? /* @__PURE__ */ jsx("text", {
1613
1616
  fg: theme.muted,
1614
1617
  children: "More conversations are available."
1615
- }, undefined, false, undefined, this) : null,
1616
- /* @__PURE__ */ jsxDEV("text", {
1618
+ }) : null,
1619
+ /* @__PURE__ */ jsx("text", {
1617
1620
  fg: theme.muted,
1618
1621
  children: "Esc close"
1619
- }, undefined, false, undefined, this)
1622
+ })
1620
1623
  ]
1621
- }, undefined, true, undefined, this) : null
1624
+ }) : null
1622
1625
  ]
1623
- }, undefined, true, undefined, this);
1626
+ });
1624
1627
  }
1625
1628
 
1626
1629
  // src/config.ts
@@ -1723,7 +1726,7 @@ async function createAgentTuiController(input) {
1723
1726
  const refresh = async () => {
1724
1727
  const targetConversationId = conversationId;
1725
1728
  const version = ++refreshVersion;
1726
- const [snapshot, approvals, selection2] = await Promise.all([
1729
+ const [snapshot, approvals, selection] = await Promise.all([
1727
1730
  input.harness.snapshot(targetConversationId),
1728
1731
  input.harness.pendingApprovals(targetConversationId),
1729
1732
  input.selections.load(targetConversationId)
@@ -1734,7 +1737,7 @@ async function createAgentTuiController(input) {
1734
1737
  ...current,
1735
1738
  conversationId: targetConversationId,
1736
1739
  snapshot,
1737
- ...selection2 && { selectedModelId: selection2.modelId },
1740
+ ...selection && { selectedModelId: selection.modelId },
1738
1741
  ...approvals[0] && { pendingApproval: approvals[0] }
1739
1742
  };
1740
1743
  if (!approvals[0])
@@ -2034,7 +2037,7 @@ async function createAgentTuiDiagnosticRecorder(input) {
2034
2037
  }
2035
2038
 
2036
2039
  // src/run.tsx
2037
- import { jsxDEV as jsxDEV2 } from "@opentui/react/jsx-dev-runtime";
2040
+ import { jsx as jsx2 } from "@opentui/react/jsx-runtime";
2038
2041
  function runtimeContext(config) {
2039
2042
  return Promise.resolve(config.context());
2040
2043
  }
@@ -2090,13 +2093,13 @@ async function runAgentTui(config) {
2090
2093
  }
2091
2094
  if (request.operation === "interrupt")
2092
2095
  await controller.interrupt(request.runId);
2093
- const activeRunId2 = controller.state().snapshot.runs.find(({ state }) => state === "running" || state === "interrupt_requested")?.id;
2096
+ const activeRunId = controller.state().snapshot.runs.find(({ state }) => state === "running" || state === "interrupt_requested")?.id;
2094
2097
  return {
2095
2098
  requestId: request.requestId,
2096
2099
  outcome: "ok",
2097
2100
  sessionId,
2098
2101
  conversationId: controller.state().conversationId,
2099
- ...activeRunId2 && { runId: activeRunId2 }
2102
+ ...activeRunId && { runId: activeRunId }
2100
2103
  };
2101
2104
  } catch {
2102
2105
  diagnostics.record({
@@ -2159,7 +2162,7 @@ async function runAgentTui(config) {
2159
2162
  })();
2160
2163
  return closing;
2161
2164
  };
2162
- root.render(/* @__PURE__ */ jsxDEV2(AgentTuiApp, {
2165
+ root.render(/* @__PURE__ */ jsx2(AgentTuiApp, {
2163
2166
  controller,
2164
2167
  catalog,
2165
2168
  ...bundle.conversations && { conversations: bundle.conversations },
@@ -2184,7 +2187,7 @@ async function runAgentTui(config) {
2184
2187
  });
2185
2188
  },
2186
2189
  onExit: close
2187
- }, undefined, false, undefined, this));
2190
+ }));
2188
2191
  process.once("SIGINT", onSignal);
2189
2192
  process.once("SIGTERM", onSignal);
2190
2193
  return { sessionId: host.sessionId, close };