@useavalon/caelence-agent 0.1.0 → 0.1.1-canary.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/LICENSE +21 -0
- package/README.md +129 -137
- package/brand/logo/favicon-agent-bg-16.svg +7 -0
- package/brand/logo/favicon-agent-bg-32.svg +7 -0
- package/brand/previews/desktop-chat.png +0 -0
- package/brand/previews/desktop-commands.png +0 -0
- package/brand/previews/desktop-integrations.png +0 -0
- package/brand/previews/desktop-skills.png +0 -0
- package/package.json +5 -3
- package/skills/impeccable/LICENSE +13 -0
- package/skills/impeccable/NOTICE +14 -0
- package/skills/impeccable/SKILL.md +2 -1
- package/src/agent-cwd.ts +51 -0
- package/src/cli/agent-cwd.test.ts +65 -0
- package/src/cli/main.test.ts +5 -0
- package/src/cli/main.ts +282 -201
- package/src/cli/picker.test.ts +59 -1
- package/src/cli/picker.ts +46 -0
- package/src/cli/slash-dispatch.test.ts +116 -7
- package/src/cli/slash-dispatch.ts +343 -174
- package/src/cli/slash.test.ts +25 -2
- package/src/cli/slash.ts +37 -8
- package/src/cli/theme.test.ts +7 -0
- package/src/cli/theme.ts +6 -6
- package/src/cli/tui.tsx +385 -217
- package/src/config.ts +1 -1
- package/src/core/strands.ts +10 -1
- package/src/desktop/bridge.test.ts +56 -1
- package/src/desktop/bridge.ts +527 -390
- package/src/desktop/uploads.test.ts +57 -0
- package/src/desktop/uploads.ts +92 -0
- package/src/index.ts +26 -2
- package/src/init.test.ts +19 -2
- package/src/init.ts +25 -17
- package/src/integrations/loopback.test.ts +17 -0
- package/src/integrations/loopback.ts +91 -0
- package/src/observability/prompts.ts +1 -1
- package/src/product.ts +3 -1
- package/src/runtime.test.ts +24 -0
- package/src/runtime.ts +48 -5
- package/src/skills/catalog.test.ts +188 -0
- package/src/skills/catalog.ts +279 -0
- package/src/skills/disabled.test.ts +27 -0
- package/src/skills/disabled.ts +59 -0
- package/src/skills/loader.test.ts +31 -0
- package/src/skills/loader.ts +31 -4
- package/src/skills/registry.test.ts +64 -3
- package/src/skills/registry.ts +248 -93
- package/src/skills/skill-command.ts +2 -0
package/src/cli/tui.tsx
CHANGED
|
@@ -4,6 +4,7 @@ import type React from "react";
|
|
|
4
4
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
5
5
|
import { resolveOpenRouter } from "../config.ts";
|
|
6
6
|
import type { ApprovalRequest } from "../core/approval.ts";
|
|
7
|
+
import { errorMessage } from "../core/errors.ts";
|
|
7
8
|
import type { AgentEvent } from "../core/events.ts";
|
|
8
9
|
import type { Session } from "../core/session.ts";
|
|
9
10
|
import { formatUsage, type TokenUsage } from "../core/usage.ts";
|
|
@@ -13,7 +14,15 @@ import type { HarnessRuntime } from "../runtime.ts";
|
|
|
13
14
|
import { formatMediaComposerLine } from "./media-models.ts";
|
|
14
15
|
import { HARNESS_MODELS } from "./models.ts";
|
|
15
16
|
import { cachedLiveTargetNames, loadLiveTargetNames } from "./openrouter-live.ts";
|
|
16
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
inkPickerNav,
|
|
19
|
+
type PickerItem,
|
|
20
|
+
paintPickerLine,
|
|
21
|
+
pickerPage,
|
|
22
|
+
pickerVisibleRows,
|
|
23
|
+
sessionPickerItems,
|
|
24
|
+
stepIndex,
|
|
25
|
+
} from "./picker.ts";
|
|
17
26
|
import { plainTerminalText } from "./plain-text.ts";
|
|
18
27
|
import {
|
|
19
28
|
completeSlashCommand,
|
|
@@ -73,7 +82,7 @@ function previewInput(input: Record<string, unknown>): string {
|
|
|
73
82
|
function applyEvent(lines: StreamLine[], event: AgentEvent): StreamLine[] {
|
|
74
83
|
switch (event.kind) {
|
|
75
84
|
case "text_delta": {
|
|
76
|
-
const last = lines
|
|
85
|
+
const last = lines.at(-1);
|
|
77
86
|
if (last?.type === "assistant") {
|
|
78
87
|
return [...lines.slice(0, -1), { ...last, text: last.text + event.text }];
|
|
79
88
|
}
|
|
@@ -147,23 +156,31 @@ function useTerminalSize(): { columns: number; rows: number } {
|
|
|
147
156
|
return size;
|
|
148
157
|
}
|
|
149
158
|
|
|
150
|
-
function
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
159
|
+
function headerStatusMark(status: UiStatus): string {
|
|
160
|
+
if (status === "running") return "·";
|
|
161
|
+
if (status === "approval") return "!";
|
|
162
|
+
return "●";
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function headerStatusColor(status: UiStatus, theme: Theme): string {
|
|
166
|
+
if (status === "running") return theme.action;
|
|
167
|
+
if (status === "approval") return theme.warning;
|
|
168
|
+
return theme.brand;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function Header(
|
|
172
|
+
props: Readonly<{
|
|
173
|
+
theme: Theme;
|
|
174
|
+
model: string;
|
|
175
|
+
cwd: string;
|
|
176
|
+
title: string;
|
|
177
|
+
status: UiStatus;
|
|
178
|
+
mode: string;
|
|
179
|
+
spend?: string;
|
|
180
|
+
}>,
|
|
181
|
+
): React.ReactElement {
|
|
182
|
+
const mark = headerStatusMark(props.status);
|
|
183
|
+
const color = headerStatusColor(props.status, props.theme);
|
|
167
184
|
const label = modelLabel(props.model);
|
|
168
185
|
const target = cachedLiveTargetNames().get(props.model);
|
|
169
186
|
return (
|
|
@@ -186,13 +203,15 @@ function Header(props: {
|
|
|
186
203
|
);
|
|
187
204
|
}
|
|
188
205
|
|
|
189
|
-
function Sidebar(
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
206
|
+
function Sidebar(
|
|
207
|
+
props: Readonly<{
|
|
208
|
+
theme: Theme;
|
|
209
|
+
width: number;
|
|
210
|
+
height: number;
|
|
211
|
+
sessions: PickerItem[];
|
|
212
|
+
currentId?: string;
|
|
213
|
+
}>,
|
|
214
|
+
): React.ReactElement {
|
|
196
215
|
const inner = Math.max(8, props.width - 2);
|
|
197
216
|
const slots = Math.max(3, props.height - 6);
|
|
198
217
|
const items = props.sessions.slice(0, slots);
|
|
@@ -232,94 +251,122 @@ function Sidebar(props: {
|
|
|
232
251
|
);
|
|
233
252
|
}
|
|
234
253
|
|
|
235
|
-
function
|
|
254
|
+
function toolStatusMark(status: ToolStatus): string {
|
|
255
|
+
if (status === "running") return "…";
|
|
256
|
+
if (status === "ok") return "✓";
|
|
257
|
+
return "×";
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function toolStatusColor(status: ToolStatus, theme: Theme): string {
|
|
261
|
+
if (status === "running") return theme.action;
|
|
262
|
+
if (status === "ok") return theme.done;
|
|
263
|
+
return theme.danger;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
function StreamLineView(props: Readonly<{ theme: Theme; line: StreamLine }>): React.ReactElement {
|
|
267
|
+
const { theme, line } = props;
|
|
268
|
+
if (line.type === "user") {
|
|
269
|
+
return (
|
|
270
|
+
<Box marginBottom={1}>
|
|
271
|
+
<Text color={theme.brand}>› </Text>
|
|
272
|
+
<Text color={theme.ink}>{line.text}</Text>
|
|
273
|
+
</Box>
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
if (line.type === "assistant") {
|
|
277
|
+
return (
|
|
278
|
+
<Box marginBottom={1}>
|
|
279
|
+
<Text color={theme.ink}>{plainTerminalText(line.text)}</Text>
|
|
280
|
+
</Box>
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
if (line.type === "tool") {
|
|
284
|
+
return (
|
|
285
|
+
<Box flexDirection="column" marginBottom={1}>
|
|
286
|
+
<Text color={toolStatusColor(line.status, theme)}>
|
|
287
|
+
{toolStatusMark(line.status)} {line.name} <Text color={theme.muted}>{line.preview}</Text>
|
|
288
|
+
</Text>
|
|
289
|
+
{line.error ? <Text color={theme.danger}>{line.error}</Text> : null}
|
|
290
|
+
</Box>
|
|
291
|
+
);
|
|
292
|
+
}
|
|
293
|
+
if (line.type === "todos") {
|
|
294
|
+
return (
|
|
295
|
+
<Box marginBottom={1}>
|
|
296
|
+
<Text color={theme.muted}>todos {line.text}</Text>
|
|
297
|
+
</Box>
|
|
298
|
+
);
|
|
299
|
+
}
|
|
300
|
+
if (line.type === "error") {
|
|
301
|
+
return (
|
|
302
|
+
<Box marginBottom={1}>
|
|
303
|
+
<Text color={theme.danger}>{line.text}</Text>
|
|
304
|
+
</Box>
|
|
305
|
+
);
|
|
306
|
+
}
|
|
307
|
+
return (
|
|
308
|
+
<Box marginBottom={1}>
|
|
309
|
+
<Text color={theme.muted}>{line.text}</Text>
|
|
310
|
+
</Box>
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
function StreamView(props: Readonly<{ theme: Theme; lines: StreamLine[] }>): React.ReactElement {
|
|
236
315
|
return (
|
|
237
316
|
<Box flexDirection="column">
|
|
238
|
-
{props.lines.map((line) =>
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
<Text color={props.theme.ink}>{line.text}</Text>
|
|
244
|
-
</Box>
|
|
245
|
-
);
|
|
246
|
-
}
|
|
247
|
-
if (line.type === "assistant") {
|
|
248
|
-
return (
|
|
249
|
-
<Box key={line.key} marginBottom={1}>
|
|
250
|
-
<Text color={props.theme.ink}>{plainTerminalText(line.text)}</Text>
|
|
251
|
-
</Box>
|
|
252
|
-
);
|
|
253
|
-
}
|
|
254
|
-
if (line.type === "tool") {
|
|
255
|
-
const mark = line.status === "running" ? "…" : line.status === "ok" ? "✓" : "×";
|
|
256
|
-
const color =
|
|
257
|
-
line.status === "running"
|
|
258
|
-
? props.theme.action
|
|
259
|
-
: line.status === "ok"
|
|
260
|
-
? props.theme.done
|
|
261
|
-
: props.theme.danger;
|
|
262
|
-
return (
|
|
263
|
-
<Box key={line.key} flexDirection="column" marginBottom={1}>
|
|
264
|
-
<Text color={color}>
|
|
265
|
-
{mark} {line.name} <Text color={props.theme.muted}>{line.preview}</Text>
|
|
266
|
-
</Text>
|
|
267
|
-
{line.error ? <Text color={props.theme.danger}>{line.error}</Text> : null}
|
|
268
|
-
</Box>
|
|
269
|
-
);
|
|
270
|
-
}
|
|
271
|
-
if (line.type === "todos") {
|
|
272
|
-
return (
|
|
273
|
-
<Box key={line.key} marginBottom={1}>
|
|
274
|
-
<Text color={props.theme.muted}>todos {line.text}</Text>
|
|
275
|
-
</Box>
|
|
276
|
-
);
|
|
277
|
-
}
|
|
278
|
-
if (line.type === "error") {
|
|
279
|
-
return (
|
|
280
|
-
<Box key={line.key} marginBottom={1}>
|
|
281
|
-
<Text color={props.theme.danger}>{line.text}</Text>
|
|
282
|
-
</Box>
|
|
283
|
-
);
|
|
284
|
-
}
|
|
285
|
-
return (
|
|
286
|
-
<Box key={line.key} marginBottom={1}>
|
|
287
|
-
<Text color={props.theme.muted}>{line.text}</Text>
|
|
288
|
-
</Box>
|
|
289
|
-
);
|
|
290
|
-
})}
|
|
317
|
+
{props.lines.map((line) => (
|
|
318
|
+
<Box key={line.key}>
|
|
319
|
+
<StreamLineView theme={props.theme} line={line} />
|
|
320
|
+
</Box>
|
|
321
|
+
))}
|
|
291
322
|
</Box>
|
|
292
323
|
);
|
|
293
324
|
}
|
|
294
325
|
|
|
295
|
-
function
|
|
326
|
+
function pickerRowText(item: PickerItem, active: boolean): string {
|
|
327
|
+
const mark = active ? "› " : " ";
|
|
328
|
+
const hint = item.hint ? ` · ${item.hint}` : "";
|
|
329
|
+
return `${mark}${item.label}${hint}`;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function PickerMenu(
|
|
333
|
+
props: Readonly<{ theme: Theme; picker: PickerState; width: number; pageSize: number }>,
|
|
334
|
+
): React.ReactElement {
|
|
335
|
+
const page = pickerPage(props.picker.items, props.picker.index, props.pageSize);
|
|
336
|
+
const width = Math.max(1, props.width);
|
|
296
337
|
return (
|
|
297
|
-
<Box flexDirection="column" marginY={1}>
|
|
298
|
-
<
|
|
299
|
-
|
|
300
|
-
|
|
338
|
+
<Box flexDirection="column" flexGrow={1} marginY={1} width={width} overflow="hidden">
|
|
339
|
+
<Box width={width} height={1} overflow="hidden">
|
|
340
|
+
<Text color={props.theme.muted} wrap="truncate">
|
|
341
|
+
{paintPickerLine(props.picker.title, width)}
|
|
342
|
+
</Text>
|
|
343
|
+
</Box>
|
|
344
|
+
{page.items.map((item, index) => {
|
|
345
|
+
const active = page.offset + index === props.picker.index;
|
|
301
346
|
return (
|
|
302
|
-
<
|
|
303
|
-
<Text color={active ? props.theme.brand :
|
|
304
|
-
{active
|
|
305
|
-
</Text>
|
|
306
|
-
<Text color={active ? props.theme.brand : undefined} bold={active}>
|
|
307
|
-
{item.label}
|
|
347
|
+
<Box key={item.id} width={width} height={1} overflow="hidden">
|
|
348
|
+
<Text color={active ? props.theme.brand : undefined} bold={active} wrap="truncate">
|
|
349
|
+
{paintPickerLine(pickerRowText(item, active), width)}
|
|
308
350
|
</Text>
|
|
309
|
-
|
|
310
|
-
</Text>
|
|
351
|
+
</Box>
|
|
311
352
|
);
|
|
312
353
|
})}
|
|
313
|
-
<
|
|
354
|
+
<Box width={width} height={1} overflow="hidden">
|
|
355
|
+
<Text color={props.theme.line} wrap="truncate">
|
|
356
|
+
{paintPickerLine("tab or arrows · enter to choose · esc to cancel", width)}
|
|
357
|
+
</Text>
|
|
358
|
+
</Box>
|
|
314
359
|
</Box>
|
|
315
360
|
);
|
|
316
361
|
}
|
|
317
362
|
|
|
318
|
-
function SlashMenu(
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
363
|
+
function SlashMenu(
|
|
364
|
+
props: Readonly<{
|
|
365
|
+
theme: Theme;
|
|
366
|
+
items: ReturnType<typeof filterSlashCommands>;
|
|
367
|
+
selected: number;
|
|
368
|
+
}>,
|
|
369
|
+
): React.ReactElement {
|
|
323
370
|
if (props.items.length === 0) {
|
|
324
371
|
return <Text color={props.theme.muted}>No matching command</Text>;
|
|
325
372
|
}
|
|
@@ -327,23 +374,21 @@ function SlashMenu(props: {
|
|
|
327
374
|
<Box flexDirection="column" marginTop={1}>
|
|
328
375
|
{props.items.map((item, index) => {
|
|
329
376
|
const active = index === props.selected;
|
|
377
|
+
const mark = active ? "› " : " ";
|
|
330
378
|
return (
|
|
331
|
-
<
|
|
332
|
-
<Text color={active ? props.theme.brand :
|
|
333
|
-
{
|
|
334
|
-
|
|
335
|
-
<Text color={active ? props.theme.brand : undefined} bold={active}>
|
|
336
|
-
{formatSlashCommand(item)}
|
|
379
|
+
<Box key={item.name} height={1} overflow="hidden">
|
|
380
|
+
<Text color={active ? props.theme.brand : undefined} bold={active} wrap="truncate">
|
|
381
|
+
{mark}
|
|
382
|
+
{formatSlashCommand(item)} · {item.hint}
|
|
337
383
|
</Text>
|
|
338
|
-
|
|
339
|
-
</Text>
|
|
384
|
+
</Box>
|
|
340
385
|
);
|
|
341
386
|
})}
|
|
342
387
|
</Box>
|
|
343
388
|
);
|
|
344
389
|
}
|
|
345
390
|
|
|
346
|
-
function ApprovalCard(props: { theme: Theme; req: ApprovalRequest }): React.ReactElement {
|
|
391
|
+
function ApprovalCard(props: Readonly<{ theme: Theme; req: ApprovalRequest }>): React.ReactElement {
|
|
347
392
|
const command =
|
|
348
393
|
typeof props.req.input.command === "string"
|
|
349
394
|
? props.req.input.command
|
|
@@ -363,7 +408,135 @@ function ApprovalCard(props: { theme: Theme; req: ApprovalRequest }): React.Reac
|
|
|
363
408
|
);
|
|
364
409
|
}
|
|
365
410
|
|
|
366
|
-
function
|
|
411
|
+
function pickerSelectedValue(picker: SlashPickerKind, harness: HarnessRuntime): string | undefined {
|
|
412
|
+
if (picker === "model") return harness.modelId;
|
|
413
|
+
if (picker === "mode") return harness.mode;
|
|
414
|
+
const prefs = readMediaPrefs();
|
|
415
|
+
if (picker === "image") return prefs.imageModel;
|
|
416
|
+
if (picker === "video") return prefs.videoModel;
|
|
417
|
+
if (picker === "transcribe") return prefs.transcribeModel;
|
|
418
|
+
return undefined;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
function approvalDecision(input: string, escaped: boolean): "yes" | "no" | "always" | undefined {
|
|
422
|
+
if (input === "y" || input === "Y") return "yes";
|
|
423
|
+
if (input === "a" || input === "A") return "always";
|
|
424
|
+
if (input === "n" || input === "N" || escaped) return "no";
|
|
425
|
+
return undefined;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
function slashMenuNav(
|
|
429
|
+
key: { upArrow: boolean; downArrow: boolean; tab: boolean },
|
|
430
|
+
slashOpen: boolean,
|
|
431
|
+
count: number,
|
|
432
|
+
): "up" | "down" | "tab" | undefined {
|
|
433
|
+
if (!slashOpen || count === 0) return undefined;
|
|
434
|
+
if (key.upArrow) return "up";
|
|
435
|
+
if (key.downArrow) return "down";
|
|
436
|
+
if (key.tab) return "tab";
|
|
437
|
+
return undefined;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
function applyPickerKeys(
|
|
441
|
+
picker: PickerState,
|
|
442
|
+
key: {
|
|
443
|
+
escape: boolean;
|
|
444
|
+
upArrow: boolean;
|
|
445
|
+
downArrow: boolean;
|
|
446
|
+
tab: boolean;
|
|
447
|
+
shift: boolean;
|
|
448
|
+
return: boolean;
|
|
449
|
+
},
|
|
450
|
+
setPicker: (
|
|
451
|
+
value: PickerState | null | ((current: PickerState | null) => PickerState | null),
|
|
452
|
+
) => void,
|
|
453
|
+
setStatus: (status: UiStatus) => void,
|
|
454
|
+
setValue: (value: string) => void,
|
|
455
|
+
onEnter: (picker: PickerState) => void,
|
|
456
|
+
): void {
|
|
457
|
+
const nav = inkPickerNav(key);
|
|
458
|
+
if (nav === "esc") {
|
|
459
|
+
const next = draftAfterPicker(picker.kind);
|
|
460
|
+
setPicker(null);
|
|
461
|
+
setStatus("idle");
|
|
462
|
+
if (next) setValue(next);
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
465
|
+
if (nav === "enter") {
|
|
466
|
+
onEnter(picker);
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
if (typeof nav === "number") {
|
|
470
|
+
setPicker((current) =>
|
|
471
|
+
current
|
|
472
|
+
? { ...current, index: stepIndex(current.index, current.items.length, nav) }
|
|
473
|
+
: current,
|
|
474
|
+
);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
function trySlashMenuInput(
|
|
479
|
+
key: { upArrow: boolean; downArrow: boolean; tab: boolean },
|
|
480
|
+
slashOpen: boolean,
|
|
481
|
+
slashItems: ReturnType<typeof filterSlashCommands>,
|
|
482
|
+
slashIndex: number,
|
|
483
|
+
setSlashIndex: (fn: (index: number) => number) => void,
|
|
484
|
+
setValue: (value: string) => void,
|
|
485
|
+
): void {
|
|
486
|
+
const slashKey = slashMenuNav(key, slashOpen, slashItems.length);
|
|
487
|
+
if (slashKey === "up") {
|
|
488
|
+
setSlashIndex((index) => stepIndex(index, slashItems.length, -1));
|
|
489
|
+
return;
|
|
490
|
+
}
|
|
491
|
+
if (slashKey === "down") {
|
|
492
|
+
setSlashIndex((index) => stepIndex(index, slashItems.length, 1));
|
|
493
|
+
return;
|
|
494
|
+
}
|
|
495
|
+
if (slashKey === "tab") {
|
|
496
|
+
const selected = slashItems[slashIndex] ?? slashItems[0];
|
|
497
|
+
if (selected) setValue(completeSlashCommand(selected));
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
function ComposerFooter(
|
|
502
|
+
props: Readonly<{
|
|
503
|
+
theme: Theme;
|
|
504
|
+
status: UiStatus;
|
|
505
|
+
statusLabel: string;
|
|
506
|
+
value: string;
|
|
507
|
+
onChange: (value: string) => void;
|
|
508
|
+
onSubmit: (value: string) => void;
|
|
509
|
+
slashOpen: boolean;
|
|
510
|
+
slashItems: ReturnType<typeof filterSlashCommands>;
|
|
511
|
+
slashIndex: number;
|
|
512
|
+
mediaLine: string;
|
|
513
|
+
pickerOpen: boolean;
|
|
514
|
+
}>,
|
|
515
|
+
): React.ReactElement | null {
|
|
516
|
+
if (props.pickerOpen || props.status === "picker") return null;
|
|
517
|
+
if (props.status !== "idle") {
|
|
518
|
+
return <Text color={props.theme.muted}>{props.statusLabel}</Text>;
|
|
519
|
+
}
|
|
520
|
+
return (
|
|
521
|
+
<Box flexDirection="column">
|
|
522
|
+
<Box>
|
|
523
|
+
<Text color={props.theme.brand}>› </Text>
|
|
524
|
+
<TextInput value={props.value} onChange={props.onChange} onSubmit={props.onSubmit} />
|
|
525
|
+
</Box>
|
|
526
|
+
{props.slashOpen ? (
|
|
527
|
+
<SlashMenu
|
|
528
|
+
theme={props.theme}
|
|
529
|
+
items={props.slashItems}
|
|
530
|
+
selected={Math.min(props.slashIndex, Math.max(props.slashItems.length - 1, 0))}
|
|
531
|
+
/>
|
|
532
|
+
) : (
|
|
533
|
+
<Text color={props.theme.line}>{props.mediaLine}</Text>
|
|
534
|
+
)}
|
|
535
|
+
</Box>
|
|
536
|
+
);
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
function App(props: Readonly<{ harness: HarnessRuntime }>): React.ReactElement {
|
|
367
540
|
const { harness } = props;
|
|
368
541
|
const theme = harness.theme;
|
|
369
542
|
const { exit } = useApp();
|
|
@@ -384,6 +557,15 @@ function App(props: { harness: HarnessRuntime }): React.ReactElement {
|
|
|
384
557
|
resolve: (ok: boolean) => void;
|
|
385
558
|
} | null>(null);
|
|
386
559
|
const abortRef = useRef<AbortController | null>(null);
|
|
560
|
+
const pickerRef = useRef(picker);
|
|
561
|
+
pickerRef.current = picker;
|
|
562
|
+
const pickerEscTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
563
|
+
|
|
564
|
+
useEffect(() => {
|
|
565
|
+
return () => {
|
|
566
|
+
if (pickerEscTimer.current) clearTimeout(pickerEscTimer.current);
|
|
567
|
+
};
|
|
568
|
+
}, []);
|
|
387
569
|
|
|
388
570
|
const slashItems = useMemo(() => filterSlashCommands(value), [value]);
|
|
389
571
|
const slashOpen = status === "idle" && !picker && value.startsWith("/");
|
|
@@ -445,8 +627,8 @@ function App(props: { harness: HarnessRuntime }): React.ReactElement {
|
|
|
445
627
|
const item = state.items[state.index];
|
|
446
628
|
if (!item) return;
|
|
447
629
|
setPicker(null);
|
|
448
|
-
setStatus("idle");
|
|
449
630
|
if (state.kind === "resume") {
|
|
631
|
+
setStatus("idle");
|
|
450
632
|
void harness.store.get(item.id).then((session) => {
|
|
451
633
|
if (!session) {
|
|
452
634
|
pushSystem(`No session ${item.label}`);
|
|
@@ -456,84 +638,78 @@ function App(props: { harness: HarnessRuntime }): React.ReactElement {
|
|
|
456
638
|
});
|
|
457
639
|
return;
|
|
458
640
|
}
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
641
|
+
if (state.kind === "integration") setStatus("running");
|
|
642
|
+
else setStatus("idle");
|
|
643
|
+
void applyPickerChoice(harness, state.kind, item.id)
|
|
644
|
+
.then((result) => {
|
|
645
|
+
if (result.kind === "text") {
|
|
646
|
+
pushSystem(result.text);
|
|
647
|
+
}
|
|
648
|
+
setModel(harness.modelId);
|
|
649
|
+
setMode(harness.mode);
|
|
650
|
+
refreshMedia();
|
|
651
|
+
const nextDraft = draftAfterPicker(state.kind);
|
|
652
|
+
if (nextDraft) setValue(nextDraft);
|
|
653
|
+
})
|
|
654
|
+
.catch((err: unknown) => {
|
|
655
|
+
pushSystem(errorMessage(err));
|
|
656
|
+
})
|
|
657
|
+
.finally(() => {
|
|
658
|
+
setStatus("idle");
|
|
659
|
+
});
|
|
468
660
|
},
|
|
469
661
|
[applySession, harness, pushSystem, refreshMedia],
|
|
470
662
|
);
|
|
471
663
|
|
|
472
|
-
useInput(
|
|
473
|
-
|
|
474
|
-
if (
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
pending.resolve(false);
|
|
664
|
+
useInput(
|
|
665
|
+
(input, key) => {
|
|
666
|
+
if (status === "approval" && pending) {
|
|
667
|
+
const decision = approvalDecision(input, key.escape);
|
|
668
|
+
if (!decision) return;
|
|
669
|
+
if (decision === "always") harness.allowRiskyAlways(pending.req.toolName);
|
|
670
|
+
pending.resolve(decision !== "no");
|
|
480
671
|
setPending(null);
|
|
481
672
|
setStatus("running");
|
|
482
|
-
} else if (input === "a" || input === "A") {
|
|
483
|
-
harness.allowRiskyAlways(pending.req.toolName);
|
|
484
|
-
pending.resolve(true);
|
|
485
|
-
setPending(null);
|
|
486
|
-
setStatus("running");
|
|
487
|
-
} else if (key.escape) {
|
|
488
|
-
pending.resolve(false);
|
|
489
|
-
setPending(null);
|
|
490
|
-
setStatus("running");
|
|
491
|
-
}
|
|
492
|
-
return;
|
|
493
|
-
}
|
|
494
|
-
if (picker) {
|
|
495
|
-
if (key.escape) {
|
|
496
|
-
const next = draftAfterPicker(picker.kind);
|
|
497
|
-
setPicker(null);
|
|
498
|
-
setStatus("idle");
|
|
499
|
-
if (next) setValue(next);
|
|
500
673
|
return;
|
|
501
674
|
}
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
675
|
+
const open = pickerRef.current;
|
|
676
|
+
if (open) {
|
|
677
|
+
const nav = inkPickerNav(key);
|
|
678
|
+
if (nav === "esc") {
|
|
679
|
+
if (pickerEscTimer.current) clearTimeout(pickerEscTimer.current);
|
|
680
|
+
pickerEscTimer.current = setTimeout(() => {
|
|
681
|
+
pickerEscTimer.current = null;
|
|
682
|
+
const still = pickerRef.current;
|
|
683
|
+
if (!still) return;
|
|
684
|
+
applyPickerKeys(
|
|
685
|
+
still,
|
|
686
|
+
{
|
|
687
|
+
escape: true,
|
|
688
|
+
upArrow: false,
|
|
689
|
+
downArrow: false,
|
|
690
|
+
tab: false,
|
|
691
|
+
shift: false,
|
|
692
|
+
return: false,
|
|
693
|
+
},
|
|
694
|
+
setPicker,
|
|
695
|
+
setStatus,
|
|
696
|
+
setValue,
|
|
697
|
+
confirmPicker,
|
|
698
|
+
);
|
|
699
|
+
}, 40);
|
|
700
|
+
return;
|
|
701
|
+
}
|
|
702
|
+
if (pickerEscTimer.current) {
|
|
703
|
+
clearTimeout(pickerEscTimer.current);
|
|
704
|
+
pickerEscTimer.current = null;
|
|
705
|
+
}
|
|
706
|
+
applyPickerKeys(open, key, setPicker, setStatus, setValue, confirmPicker);
|
|
516
707
|
return;
|
|
517
708
|
}
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
}
|
|
523
|
-
if (status !== "idle" || !slashOpen || slashItems.length === 0) return;
|
|
524
|
-
if (key.upArrow) {
|
|
525
|
-
setSlashIndex((index) => stepIndex(index, slashItems.length, -1));
|
|
526
|
-
return;
|
|
527
|
-
}
|
|
528
|
-
if (key.downArrow) {
|
|
529
|
-
setSlashIndex((index) => stepIndex(index, slashItems.length, 1));
|
|
530
|
-
return;
|
|
531
|
-
}
|
|
532
|
-
if (key.tab) {
|
|
533
|
-
const selected = slashItems[slashIndex] ?? slashItems[0];
|
|
534
|
-
if (selected) setValue(completeSlashCommand(selected));
|
|
535
|
-
}
|
|
536
|
-
});
|
|
709
|
+
trySlashMenuInput(key, slashOpen, slashItems, slashIndex, setSlashIndex, setValue);
|
|
710
|
+
},
|
|
711
|
+
{ isActive: true },
|
|
712
|
+
);
|
|
537
713
|
|
|
538
714
|
const handleSlash = useCallback(
|
|
539
715
|
async (raw: string) => {
|
|
@@ -575,32 +751,20 @@ function App(props: { harness: HarnessRuntime }): React.ReactElement {
|
|
|
575
751
|
pushSystem(outcome.caption);
|
|
576
752
|
return;
|
|
577
753
|
}
|
|
578
|
-
const
|
|
579
|
-
const currentId =
|
|
580
|
-
outcome.picker === "model"
|
|
581
|
-
? harness.modelId
|
|
582
|
-
: outcome.picker === "mode"
|
|
583
|
-
? harness.mode
|
|
584
|
-
: outcome.picker === "image"
|
|
585
|
-
? prefs.imageModel
|
|
586
|
-
: outcome.picker === "video"
|
|
587
|
-
? prefs.videoModel
|
|
588
|
-
: outcome.picker === "transcribe"
|
|
589
|
-
? prefs.transcribeModel
|
|
590
|
-
: undefined;
|
|
754
|
+
const currentId = pickerSelectedValue(outcome.picker, harness);
|
|
591
755
|
const selected = currentId
|
|
592
756
|
? Math.max(
|
|
593
757
|
0,
|
|
594
758
|
outcome.items.findIndex((item) => item.id === currentId),
|
|
595
759
|
)
|
|
596
760
|
: 0;
|
|
761
|
+
setStatus("picker");
|
|
597
762
|
setPicker({
|
|
598
763
|
title: outcome.title,
|
|
599
764
|
kind: outcome.picker,
|
|
600
765
|
items: outcome.items,
|
|
601
766
|
index: selected,
|
|
602
767
|
});
|
|
603
|
-
setStatus("picker");
|
|
604
768
|
} finally {
|
|
605
769
|
setStatus((current) => (current === "picker" ? current : "idle"));
|
|
606
770
|
}
|
|
@@ -612,7 +776,8 @@ function App(props: { harness: HarnessRuntime }): React.ReactElement {
|
|
|
612
776
|
async (text: string) => {
|
|
613
777
|
const trimmed = text.trim();
|
|
614
778
|
if (!trimmed || status !== "idle") return;
|
|
615
|
-
const
|
|
779
|
+
const selected = slashOpen ? slashItems[slashIndex] : undefined;
|
|
780
|
+
const slash = resolveSlashSubmit(trimmed, selected);
|
|
616
781
|
if (slash?.action === "hold") return;
|
|
617
782
|
if (slash?.action === "complete") {
|
|
618
783
|
setValue(slash.line);
|
|
@@ -650,7 +815,7 @@ function App(props: { harness: HarnessRuntime }): React.ReactElement {
|
|
|
650
815
|
setStatus("idle");
|
|
651
816
|
}
|
|
652
817
|
},
|
|
653
|
-
[handleSlash, harness, status],
|
|
818
|
+
[handleSlash, harness, slashIndex, slashItems, slashOpen, status],
|
|
654
819
|
);
|
|
655
820
|
|
|
656
821
|
const statusLabel = useMemo(() => {
|
|
@@ -673,7 +838,6 @@ function App(props: { harness: HarnessRuntime }): React.ReactElement {
|
|
|
673
838
|
<Box flexDirection="column" width={mainWidth} height={rows}>
|
|
674
839
|
<Header
|
|
675
840
|
theme={theme}
|
|
676
|
-
name={harness.config.name}
|
|
677
841
|
model={model}
|
|
678
842
|
cwd={harness.cwd}
|
|
679
843
|
title={title}
|
|
@@ -681,30 +845,34 @@ function App(props: { harness: HarnessRuntime }): React.ReactElement {
|
|
|
681
845
|
mode={mode}
|
|
682
846
|
spend={spend ? formatUsage(spend) : undefined}
|
|
683
847
|
/>
|
|
684
|
-
|
|
685
|
-
<
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
{
|
|
696
|
-
<SlashMenu
|
|
697
|
-
theme={theme}
|
|
698
|
-
items={slashItems}
|
|
699
|
-
selected={Math.min(slashIndex, Math.max(slashItems.length - 1, 0))}
|
|
700
|
-
/>
|
|
701
|
-
) : (
|
|
702
|
-
<Text color={theme.line}>{mediaLine}</Text>
|
|
703
|
-
)}
|
|
848
|
+
{picker ? (
|
|
849
|
+
<Box flexGrow={1} overflow="hidden" width={mainWidth}>
|
|
850
|
+
<PickerMenu
|
|
851
|
+
theme={theme}
|
|
852
|
+
picker={picker}
|
|
853
|
+
width={mainWidth}
|
|
854
|
+
pageSize={pickerVisibleRows(rows)}
|
|
855
|
+
/>
|
|
856
|
+
</Box>
|
|
857
|
+
) : (
|
|
858
|
+
<Box flexDirection="column" flexGrow={1} overflow="hidden">
|
|
859
|
+
<StreamView theme={theme} lines={shown} />
|
|
704
860
|
</Box>
|
|
705
|
-
) : status === "picker" ? null : (
|
|
706
|
-
<Text color={theme.muted}>{statusLabel}</Text>
|
|
707
861
|
)}
|
|
862
|
+
{pending ? <ApprovalCard theme={theme} req={pending.req} /> : null}
|
|
863
|
+
<ComposerFooter
|
|
864
|
+
theme={theme}
|
|
865
|
+
status={status}
|
|
866
|
+
statusLabel={statusLabel}
|
|
867
|
+
value={value}
|
|
868
|
+
onChange={setValue}
|
|
869
|
+
onSubmit={submit}
|
|
870
|
+
slashOpen={slashOpen}
|
|
871
|
+
slashItems={slashItems}
|
|
872
|
+
slashIndex={slashIndex}
|
|
873
|
+
mediaLine={mediaLine}
|
|
874
|
+
pickerOpen={Boolean(picker)}
|
|
875
|
+
/>
|
|
708
876
|
</Box>
|
|
709
877
|
);
|
|
710
878
|
|