@useavalon/caelence-agent 0.2.5-canary.0 → 0.2.5-canary.2
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/desktop/README.md +2 -2
- package/desktop/scripts/run-tauri.ts +3 -2
- package/desktop/src/DeskChrome.tsx +18 -1
- package/desktop/src/app.css +32 -0
- package/package.json +2 -3
- package/src/agent-cwd.ts +51 -4
- package/src/cli/agent-cwd.test.ts +17 -0
- package/src/cli/main.ts +15 -9
- package/src/cli/theme.test.ts +40 -5
- package/src/cli/theme.ts +65 -4
- package/src/cli/tui-layout.test.ts +5 -3
- package/src/cli/tui-layout.ts +17 -8
- package/src/cli/tui-progress.test.ts +44 -0
- package/src/cli/tui-progress.ts +55 -0
- package/src/cli/tui-stream.ts +26 -0
- package/src/cli/tui-terminal-probe.test.ts +19 -0
- package/src/cli/tui-terminal-probe.ts +113 -0
- package/src/cli/tui-text-input-display.ts +6 -0
- package/src/cli/tui-text-input.test.ts +13 -1
- package/src/cli/tui-text-input.ts +14 -10
- package/src/cli/tui-text-input.tsx +45 -16
- package/src/cli/tui-transcript.test.ts +33 -0
- package/src/cli/tui-transcript.ts +59 -0
- package/src/cli/tui.tsx +279 -170
- package/src/desktop/bridge.ts +5 -1
- package/src/product.ts +1 -1
package/src/cli/tui.tsx
CHANGED
|
@@ -32,34 +32,14 @@ import {
|
|
|
32
32
|
resolveSlashSubmit,
|
|
33
33
|
} from "./slash.ts";
|
|
34
34
|
import { applyPickerChoice, dispatchSlash, type SlashPickerKind } from "./slash-dispatch.ts";
|
|
35
|
-
import type
|
|
36
|
-
import {
|
|
37
|
-
|
|
38
|
-
sidebarWidth,
|
|
39
|
-
takeVisibleLines,
|
|
40
|
-
tuiChromeRows,
|
|
41
|
-
visibleTranscriptCount,
|
|
42
|
-
} from "./tui-layout.ts";
|
|
35
|
+
import { resolveTheme, type Theme } from "./theme.ts";
|
|
36
|
+
import { clipLabel, sidebarWidth, tuiChromeRows, visibleTranscriptRows } from "./tui-layout.ts";
|
|
37
|
+
import { turnProgressLabel } from "./tui-progress.ts";
|
|
43
38
|
import { enterAltScreen } from "./tui-screen.ts";
|
|
39
|
+
import type { StreamLine, ToolStatus, TurnToolLine } from "./tui-stream.ts";
|
|
40
|
+
import { resolveTuiThemeEnv } from "./tui-terminal-probe.ts";
|
|
44
41
|
import { TuiTextInput } from "./tui-text-input.tsx";
|
|
45
|
-
|
|
46
|
-
type ToolStatus = "running" | "ok" | "fail";
|
|
47
|
-
|
|
48
|
-
type StreamLine =
|
|
49
|
-
| { key: string; type: "user"; text: string }
|
|
50
|
-
| { key: string; type: "assistant"; text: string }
|
|
51
|
-
| {
|
|
52
|
-
key: string;
|
|
53
|
-
type: "tool";
|
|
54
|
-
name: string;
|
|
55
|
-
callId: string;
|
|
56
|
-
status: ToolStatus;
|
|
57
|
-
preview: string;
|
|
58
|
-
error?: string;
|
|
59
|
-
}
|
|
60
|
-
| { key: string; type: "system"; text: string }
|
|
61
|
-
| { key: string; type: "error"; text: string }
|
|
62
|
-
| { key: string; type: "todos"; text: string };
|
|
42
|
+
import { summarizeTurnTools, takeLinesForRowBudget } from "./tui-transcript.ts";
|
|
63
43
|
|
|
64
44
|
type UiStatus = "idle" | "running" | "approval" | "picker";
|
|
65
45
|
|
|
@@ -89,30 +69,16 @@ function applyEvent(lines: StreamLine[], event: AgentEvent): StreamLine[] {
|
|
|
89
69
|
}
|
|
90
70
|
return [...lines, { key: `a-${lines.length}`, type: "assistant", text: event.text }];
|
|
91
71
|
}
|
|
92
|
-
case "reasoning_delta":
|
|
93
|
-
|
|
72
|
+
case "reasoning_delta": {
|
|
73
|
+
const last = lines.at(-1);
|
|
74
|
+
if (last?.type === "thought") {
|
|
75
|
+
return [...lines.slice(0, -1), { ...last, text: last.text + event.text }];
|
|
76
|
+
}
|
|
77
|
+
return [...lines, { key: `th-${lines.length}`, type: "thought", text: event.text }];
|
|
78
|
+
}
|
|
94
79
|
case "tool_call_start":
|
|
95
|
-
return [
|
|
96
|
-
...lines,
|
|
97
|
-
{
|
|
98
|
-
key: event.callId,
|
|
99
|
-
type: "tool",
|
|
100
|
-
name: event.toolName,
|
|
101
|
-
callId: event.callId,
|
|
102
|
-
status: "running",
|
|
103
|
-
preview: previewInput(event.input),
|
|
104
|
-
},
|
|
105
|
-
];
|
|
106
80
|
case "tool_call_end":
|
|
107
|
-
return lines
|
|
108
|
-
line.type === "tool" && line.callId === event.callId
|
|
109
|
-
? {
|
|
110
|
-
...line,
|
|
111
|
-
status: event.success ? "ok" : "fail",
|
|
112
|
-
error: event.error,
|
|
113
|
-
}
|
|
114
|
-
: line,
|
|
115
|
-
);
|
|
81
|
+
return lines;
|
|
116
82
|
case "session_meta":
|
|
117
83
|
return lines;
|
|
118
84
|
case "error":
|
|
@@ -133,6 +99,32 @@ function applyEvent(lines: StreamLine[], event: AgentEvent): StreamLine[] {
|
|
|
133
99
|
}
|
|
134
100
|
}
|
|
135
101
|
|
|
102
|
+
function applyTurnToolEvent(tools: TurnToolLine[], event: AgentEvent): TurnToolLine[] {
|
|
103
|
+
if (event.kind === "tool_call_start") {
|
|
104
|
+
return [
|
|
105
|
+
...tools,
|
|
106
|
+
{
|
|
107
|
+
callId: event.callId,
|
|
108
|
+
name: event.toolName,
|
|
109
|
+
status: "running",
|
|
110
|
+
preview: previewInput(event.input),
|
|
111
|
+
},
|
|
112
|
+
];
|
|
113
|
+
}
|
|
114
|
+
if (event.kind === "tool_call_end") {
|
|
115
|
+
return tools.map((tool) =>
|
|
116
|
+
tool.callId === event.callId
|
|
117
|
+
? {
|
|
118
|
+
...tool,
|
|
119
|
+
status: event.success ? "ok" : "fail",
|
|
120
|
+
error: event.error,
|
|
121
|
+
}
|
|
122
|
+
: tool,
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
return tools;
|
|
126
|
+
}
|
|
127
|
+
|
|
136
128
|
function modelLabel(id: string): string {
|
|
137
129
|
return HARNESS_MODELS.find((model) => model.id === id)?.label ?? id;
|
|
138
130
|
}
|
|
@@ -158,7 +150,7 @@ function useTerminalSize(): { columns: number; rows: number } {
|
|
|
158
150
|
}
|
|
159
151
|
|
|
160
152
|
function headerStatusMark(status: UiStatus): string {
|
|
161
|
-
if (status === "running") return "
|
|
153
|
+
if (status === "running") return "…";
|
|
162
154
|
if (status === "approval") return "!";
|
|
163
155
|
return "●";
|
|
164
156
|
}
|
|
@@ -188,10 +180,7 @@ function Header(
|
|
|
188
180
|
<Box flexDirection="column">
|
|
189
181
|
<Box>
|
|
190
182
|
<Text color={color}>{mark}</Text>
|
|
191
|
-
<Text
|
|
192
|
-
{" "}
|
|
193
|
-
{PRODUCT_NAME}
|
|
194
|
-
</Text>
|
|
183
|
+
<Text bold> {PRODUCT_NAME}</Text>
|
|
195
184
|
<Text color={props.theme.muted}>
|
|
196
185
|
{" "}
|
|
197
186
|
{props.title} · {props.mode} · {label}
|
|
@@ -237,7 +226,7 @@ function Sidebar(
|
|
|
237
226
|
items.map((item) => (
|
|
238
227
|
<Text
|
|
239
228
|
key={item.id}
|
|
240
|
-
color={item.id === props.currentId ? props.theme.brand :
|
|
229
|
+
color={item.id === props.currentId ? props.theme.brand : undefined}
|
|
241
230
|
wrap="truncate"
|
|
242
231
|
>
|
|
243
232
|
{item.id === props.currentId ? "› " : " "}
|
|
@@ -264,30 +253,55 @@ function toolStatusColor(status: ToolStatus, theme: Theme): string {
|
|
|
264
253
|
return theme.danger;
|
|
265
254
|
}
|
|
266
255
|
|
|
267
|
-
function StreamLineView(
|
|
256
|
+
function StreamLineView(
|
|
257
|
+
props: Readonly<{ theme: Theme; line: StreamLine; width: number }>,
|
|
258
|
+
): React.ReactElement {
|
|
268
259
|
const { theme, line } = props;
|
|
260
|
+
const width = Math.max(1, props.width);
|
|
269
261
|
if (line.type === "user") {
|
|
270
262
|
return (
|
|
271
|
-
<Box
|
|
272
|
-
<Text color={theme.brand}
|
|
273
|
-
|
|
263
|
+
<Box flexDirection="column" marginTop={1} marginBottom={0} width={width} overflow="hidden">
|
|
264
|
+
<Text color={theme.brand} bold>
|
|
265
|
+
You
|
|
266
|
+
</Text>
|
|
267
|
+
<Text color={theme.ink} wrap="wrap">
|
|
268
|
+
{line.text}
|
|
269
|
+
</Text>
|
|
274
270
|
</Box>
|
|
275
271
|
);
|
|
276
272
|
}
|
|
277
273
|
if (line.type === "assistant") {
|
|
278
274
|
return (
|
|
279
|
-
<Box
|
|
280
|
-
<Text color={theme.
|
|
275
|
+
<Box flexDirection="column" marginTop={1} marginBottom={0} width={width} overflow="hidden">
|
|
276
|
+
<Text color={theme.muted} bold>
|
|
277
|
+
Agent
|
|
278
|
+
</Text>
|
|
279
|
+
<Text color={theme.ink} wrap="wrap">
|
|
280
|
+
{plainTerminalText(line.text)}
|
|
281
|
+
</Text>
|
|
282
|
+
</Box>
|
|
283
|
+
);
|
|
284
|
+
}
|
|
285
|
+
if (line.type === "thought") {
|
|
286
|
+
return (
|
|
287
|
+
<Box flexDirection="column" marginTop={1} width={width} overflow="hidden">
|
|
288
|
+
<Text color={theme.muted} wrap="truncate">
|
|
289
|
+
{clipLabel(line.text.replace(/\s+/g, " ").trim(), width)}
|
|
290
|
+
</Text>
|
|
281
291
|
</Box>
|
|
282
292
|
);
|
|
283
293
|
}
|
|
284
294
|
if (line.type === "tool") {
|
|
285
295
|
return (
|
|
286
|
-
<Box flexDirection="column" marginBottom={1}>
|
|
287
|
-
<Text color={toolStatusColor(line.status, theme)}>
|
|
296
|
+
<Box flexDirection="column" marginBottom={1} width={width} overflow="hidden">
|
|
297
|
+
<Text color={toolStatusColor(line.status, theme)} wrap="truncate">
|
|
288
298
|
{toolStatusMark(line.status)} {line.name} <Text color={theme.muted}>{line.preview}</Text>
|
|
289
299
|
</Text>
|
|
290
|
-
{line.error ?
|
|
300
|
+
{line.error ? (
|
|
301
|
+
<Text color={theme.danger} wrap="truncate">
|
|
302
|
+
{line.error}
|
|
303
|
+
</Text>
|
|
304
|
+
) : null}
|
|
291
305
|
</Box>
|
|
292
306
|
);
|
|
293
307
|
}
|
|
@@ -312,18 +326,38 @@ function StreamLineView(props: Readonly<{ theme: Theme; line: StreamLine }>): Re
|
|
|
312
326
|
);
|
|
313
327
|
}
|
|
314
328
|
|
|
315
|
-
function StreamView(
|
|
329
|
+
function StreamView(
|
|
330
|
+
props: Readonly<{ theme: Theme; lines: StreamLine[]; width: number; height: number }>,
|
|
331
|
+
): React.ReactElement {
|
|
316
332
|
return (
|
|
317
|
-
<Box
|
|
333
|
+
<Box
|
|
334
|
+
flexDirection="column"
|
|
335
|
+
width={props.width}
|
|
336
|
+
height={props.height}
|
|
337
|
+
overflow="hidden"
|
|
338
|
+
flexShrink={0}
|
|
339
|
+
>
|
|
318
340
|
{props.lines.map((line) => (
|
|
319
|
-
<Box key={line.key}>
|
|
320
|
-
<StreamLineView theme={props.theme} line={line} />
|
|
341
|
+
<Box key={line.key} width={props.width} overflow="hidden" flexShrink={0}>
|
|
342
|
+
<StreamLineView theme={props.theme} line={line} width={props.width} />
|
|
321
343
|
</Box>
|
|
322
344
|
))}
|
|
323
345
|
</Box>
|
|
324
346
|
);
|
|
325
347
|
}
|
|
326
348
|
|
|
349
|
+
function TurnProgressBar(
|
|
350
|
+
props: Readonly<{ theme: Theme; label: string; width: number }>,
|
|
351
|
+
): React.ReactElement {
|
|
352
|
+
return (
|
|
353
|
+
<Box width={props.width} height={1} overflow="hidden" flexShrink={0}>
|
|
354
|
+
<Text color={props.theme.action} wrap="truncate">
|
|
355
|
+
… {props.label}
|
|
356
|
+
</Text>
|
|
357
|
+
</Box>
|
|
358
|
+
);
|
|
359
|
+
}
|
|
360
|
+
|
|
327
361
|
function pickerRowText(item: PickerItem, active: boolean): string {
|
|
328
362
|
const mark = active ? "› " : " ";
|
|
329
363
|
const hint = item.hint ? ` · ${item.hint}` : "";
|
|
@@ -412,13 +446,13 @@ function ApprovalCard(props: Readonly<{ theme: Theme; req: ApprovalRequest }>):
|
|
|
412
446
|
</Text>
|
|
413
447
|
{upload ? (
|
|
414
448
|
<>
|
|
415
|
-
<Text
|
|
416
|
-
<Text
|
|
449
|
+
<Text>Copy: {copyPath}</Text>
|
|
450
|
+
<Text>Original: {originalPath}</Text>
|
|
417
451
|
<Text color={props.theme.muted}>c copy · o original · n cancel</Text>
|
|
418
452
|
</>
|
|
419
453
|
) : (
|
|
420
454
|
<>
|
|
421
|
-
<Text
|
|
455
|
+
<Text>{command}</Text>
|
|
422
456
|
<Text color={props.theme.muted}>y approve · n deny · a always this session</Text>
|
|
423
457
|
</>
|
|
424
458
|
)}
|
|
@@ -453,18 +487,6 @@ function approvalDecision(
|
|
|
453
487
|
return undefined;
|
|
454
488
|
}
|
|
455
489
|
|
|
456
|
-
function slashMenuNav(
|
|
457
|
-
key: { upArrow: boolean; downArrow: boolean; tab: boolean },
|
|
458
|
-
slashOpen: boolean,
|
|
459
|
-
count: number,
|
|
460
|
-
): "up" | "down" | "tab" | undefined {
|
|
461
|
-
if (!slashOpen || count === 0) return undefined;
|
|
462
|
-
if (key.upArrow) return "up";
|
|
463
|
-
if (key.downArrow) return "down";
|
|
464
|
-
if (key.tab) return "tab";
|
|
465
|
-
return undefined;
|
|
466
|
-
}
|
|
467
|
-
|
|
468
490
|
function applyPickerKeys(
|
|
469
491
|
picker: PickerState,
|
|
470
492
|
key: {
|
|
@@ -503,53 +525,115 @@ function applyPickerKeys(
|
|
|
503
525
|
}
|
|
504
526
|
}
|
|
505
527
|
|
|
506
|
-
function
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
528
|
+
function applyTuiApprovalKey(
|
|
529
|
+
input: string,
|
|
530
|
+
key: { escape: boolean },
|
|
531
|
+
pending: { req: ApprovalRequest; resolve: (ok: boolean) => void },
|
|
532
|
+
harness: HarnessRuntime,
|
|
533
|
+
setPending: (value: null) => void,
|
|
534
|
+
setStatus: (status: UiStatus) => void,
|
|
513
535
|
): void {
|
|
514
|
-
const
|
|
515
|
-
if (
|
|
516
|
-
|
|
517
|
-
|
|
536
|
+
const decision = approvalDecision(input, key.escape, isUploadEditRequest(pending.req));
|
|
537
|
+
if (!decision) return;
|
|
538
|
+
if (decision === "always") harness.allowRiskyAlways(pending.req.toolName);
|
|
539
|
+
if (decision === "original") {
|
|
540
|
+
const original = pending.req.input.originalPath;
|
|
541
|
+
if (typeof original === "string" && original.trim()) {
|
|
542
|
+
pending.req.input.path = original;
|
|
543
|
+
}
|
|
518
544
|
}
|
|
519
|
-
|
|
520
|
-
|
|
545
|
+
pending.resolve(decision !== "no");
|
|
546
|
+
setPending(null);
|
|
547
|
+
setStatus("running");
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
function handleOpenPickerInput(
|
|
551
|
+
open: PickerState,
|
|
552
|
+
key: {
|
|
553
|
+
escape: boolean;
|
|
554
|
+
upArrow: boolean;
|
|
555
|
+
downArrow: boolean;
|
|
556
|
+
tab: boolean;
|
|
557
|
+
shift: boolean;
|
|
558
|
+
return: boolean;
|
|
559
|
+
},
|
|
560
|
+
ctx: {
|
|
561
|
+
pickerEscTimer: React.MutableRefObject<ReturnType<typeof setTimeout> | null>;
|
|
562
|
+
pickerRef: React.MutableRefObject<PickerState | null>;
|
|
563
|
+
setPicker: (
|
|
564
|
+
value: PickerState | null | ((current: PickerState | null) => PickerState | null),
|
|
565
|
+
) => void;
|
|
566
|
+
setStatus: (status: UiStatus) => void;
|
|
567
|
+
setValue: (value: string) => void;
|
|
568
|
+
confirmPicker: (state: PickerState) => void;
|
|
569
|
+
},
|
|
570
|
+
): void {
|
|
571
|
+
const nav = inkPickerNav(key);
|
|
572
|
+
if (nav === "esc") {
|
|
573
|
+
if (ctx.pickerEscTimer.current) clearTimeout(ctx.pickerEscTimer.current);
|
|
574
|
+
ctx.pickerEscTimer.current = setTimeout(() => {
|
|
575
|
+
ctx.pickerEscTimer.current = null;
|
|
576
|
+
const still = ctx.pickerRef.current;
|
|
577
|
+
if (!still) return;
|
|
578
|
+
applyPickerKeys(
|
|
579
|
+
still,
|
|
580
|
+
{
|
|
581
|
+
escape: true,
|
|
582
|
+
upArrow: false,
|
|
583
|
+
downArrow: false,
|
|
584
|
+
tab: false,
|
|
585
|
+
shift: false,
|
|
586
|
+
return: false,
|
|
587
|
+
},
|
|
588
|
+
ctx.setPicker,
|
|
589
|
+
ctx.setStatus,
|
|
590
|
+
ctx.setValue,
|
|
591
|
+
ctx.confirmPicker,
|
|
592
|
+
);
|
|
593
|
+
}, 40);
|
|
521
594
|
return;
|
|
522
595
|
}
|
|
523
|
-
if (
|
|
524
|
-
|
|
525
|
-
|
|
596
|
+
if (ctx.pickerEscTimer.current) {
|
|
597
|
+
clearTimeout(ctx.pickerEscTimer.current);
|
|
598
|
+
ctx.pickerEscTimer.current = null;
|
|
526
599
|
}
|
|
600
|
+
applyPickerKeys(open, key, ctx.setPicker, ctx.setStatus, ctx.setValue, ctx.confirmPicker);
|
|
527
601
|
}
|
|
528
602
|
|
|
529
603
|
function ComposerFooter(
|
|
530
604
|
props: Readonly<{
|
|
531
605
|
theme: Theme;
|
|
532
606
|
status: UiStatus;
|
|
533
|
-
statusLabel: string;
|
|
534
607
|
value: string;
|
|
608
|
+
width: number;
|
|
535
609
|
onChange: (value: string) => void;
|
|
536
610
|
onSubmit: (value: string) => void;
|
|
537
611
|
slashOpen: boolean;
|
|
538
612
|
slashItems: ReturnType<typeof filterSlashCommands>;
|
|
539
613
|
slashIndex: number;
|
|
540
|
-
|
|
614
|
+
onSlashUp: () => void;
|
|
615
|
+
onSlashDown: () => void;
|
|
616
|
+
onSlashTab: () => void;
|
|
617
|
+
hintLine: string;
|
|
541
618
|
pickerOpen: boolean;
|
|
542
619
|
}>,
|
|
543
620
|
): React.ReactElement | null {
|
|
544
621
|
if (props.pickerOpen || props.status === "picker") return null;
|
|
545
|
-
|
|
546
|
-
return <Text color={props.theme.muted}>{props.statusLabel}</Text>;
|
|
547
|
-
}
|
|
622
|
+
const typingEnabled = props.status !== "approval";
|
|
548
623
|
return (
|
|
549
|
-
<Box flexDirection="column">
|
|
550
|
-
<Box>
|
|
551
|
-
<
|
|
552
|
-
|
|
624
|
+
<Box flexDirection="column" width={props.width} flexShrink={0} overflow="hidden">
|
|
625
|
+
<Box width={props.width} overflow="hidden">
|
|
626
|
+
<TuiTextInput
|
|
627
|
+
value={props.value}
|
|
628
|
+
width={props.width}
|
|
629
|
+
enabled={typingEnabled}
|
|
630
|
+
slashOpen={props.slashOpen}
|
|
631
|
+
onSlashUp={props.onSlashUp}
|
|
632
|
+
onSlashDown={props.onSlashDown}
|
|
633
|
+
onSlashTab={props.onSlashTab}
|
|
634
|
+
onChange={props.onChange}
|
|
635
|
+
onSubmit={props.onSubmit}
|
|
636
|
+
/>
|
|
553
637
|
</Box>
|
|
554
638
|
{props.slashOpen ? (
|
|
555
639
|
<SlashMenu
|
|
@@ -558,17 +642,20 @@ function ComposerFooter(
|
|
|
558
642
|
selected={Math.min(props.slashIndex, Math.max(props.slashItems.length - 1, 0))}
|
|
559
643
|
/>
|
|
560
644
|
) : (
|
|
561
|
-
<Text color={props.theme.
|
|
645
|
+
<Text color={props.theme.muted} wrap="truncate">
|
|
646
|
+
{props.hintLine}
|
|
647
|
+
</Text>
|
|
562
648
|
)}
|
|
563
649
|
</Box>
|
|
564
650
|
);
|
|
565
651
|
}
|
|
566
652
|
|
|
567
|
-
function App(props: Readonly<{ harness: HarnessRuntime }>): React.ReactElement {
|
|
568
|
-
const { harness } = props;
|
|
569
|
-
const theme = harness.theme;
|
|
653
|
+
function App(props: Readonly<{ harness: HarnessRuntime; theme: Theme }>): React.ReactElement {
|
|
654
|
+
const { harness, theme } = props;
|
|
570
655
|
const { exit } = useApp();
|
|
571
656
|
const [lines, setLines] = useState<StreamLine[]>([]);
|
|
657
|
+
const [turnTools, setTurnTools] = useState<TurnToolLine[]>([]);
|
|
658
|
+
const [progressTick, setProgressTick] = useState(0);
|
|
572
659
|
const [value, setValue] = useState("");
|
|
573
660
|
const [status, setStatus] = useState<UiStatus>("idle");
|
|
574
661
|
const [title, setTitle] = useState("New chat");
|
|
@@ -602,6 +689,14 @@ function App(props: Readonly<{ harness: HarnessRuntime }>): React.ReactElement {
|
|
|
602
689
|
setSlashIndex(0);
|
|
603
690
|
}, [value]);
|
|
604
691
|
|
|
692
|
+
useEffect(() => {
|
|
693
|
+
if (status !== "running") return;
|
|
694
|
+
const timer = setInterval(() => {
|
|
695
|
+
setProgressTick((tick) => tick + 1);
|
|
696
|
+
}, 450);
|
|
697
|
+
return () => clearInterval(timer);
|
|
698
|
+
}, [status]);
|
|
699
|
+
|
|
605
700
|
useEffect(() => {
|
|
606
701
|
if (!harness.hasApiKey) return;
|
|
607
702
|
void loadLiveTargetNames(resolveOpenRouter(harness.config)).then(() => {
|
|
@@ -692,58 +787,22 @@ function App(props: Readonly<{ harness: HarnessRuntime }>): React.ReactElement {
|
|
|
692
787
|
useInput(
|
|
693
788
|
(input, key) => {
|
|
694
789
|
if (status === "approval" && pending) {
|
|
695
|
-
|
|
696
|
-
if (!decision) return;
|
|
697
|
-
if (decision === "always") harness.allowRiskyAlways(pending.req.toolName);
|
|
698
|
-
if (
|
|
699
|
-
decision === "original" &&
|
|
700
|
-
typeof pending.req.input.originalPath === "string" &&
|
|
701
|
-
pending.req.input.originalPath.trim()
|
|
702
|
-
) {
|
|
703
|
-
pending.req.input.path = pending.req.input.originalPath;
|
|
704
|
-
}
|
|
705
|
-
pending.resolve(decision !== "no");
|
|
706
|
-
setPending(null);
|
|
707
|
-
setStatus("running");
|
|
790
|
+
applyTuiApprovalKey(input, key, pending, harness, setPending, setStatus);
|
|
708
791
|
return;
|
|
709
792
|
}
|
|
710
793
|
const open = pickerRef.current;
|
|
711
794
|
if (open) {
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
still,
|
|
721
|
-
{
|
|
722
|
-
escape: true,
|
|
723
|
-
upArrow: false,
|
|
724
|
-
downArrow: false,
|
|
725
|
-
tab: false,
|
|
726
|
-
shift: false,
|
|
727
|
-
return: false,
|
|
728
|
-
},
|
|
729
|
-
setPicker,
|
|
730
|
-
setStatus,
|
|
731
|
-
setValue,
|
|
732
|
-
confirmPicker,
|
|
733
|
-
);
|
|
734
|
-
}, 40);
|
|
735
|
-
return;
|
|
736
|
-
}
|
|
737
|
-
if (pickerEscTimer.current) {
|
|
738
|
-
clearTimeout(pickerEscTimer.current);
|
|
739
|
-
pickerEscTimer.current = null;
|
|
740
|
-
}
|
|
741
|
-
applyPickerKeys(open, key, setPicker, setStatus, setValue, confirmPicker);
|
|
742
|
-
return;
|
|
795
|
+
handleOpenPickerInput(open, key, {
|
|
796
|
+
pickerEscTimer,
|
|
797
|
+
pickerRef,
|
|
798
|
+
setPicker,
|
|
799
|
+
setStatus,
|
|
800
|
+
setValue,
|
|
801
|
+
confirmPicker,
|
|
802
|
+
});
|
|
743
803
|
}
|
|
744
|
-
trySlashMenuInput(key, slashOpen, slashItems, slashIndex, setSlashIndex, setValue);
|
|
745
804
|
},
|
|
746
|
-
{ isActive:
|
|
805
|
+
{ isActive: (status === "approval" && Boolean(pending)) || Boolean(picker) },
|
|
747
806
|
);
|
|
748
807
|
|
|
749
808
|
const handleSlash = useCallback(
|
|
@@ -824,6 +883,7 @@ function App(props: Readonly<{ harness: HarnessRuntime }>): React.ReactElement {
|
|
|
824
883
|
return;
|
|
825
884
|
}
|
|
826
885
|
setLines((prev) => [...prev, { key: `u-${prev.length}`, type: "user", text: trimmed }]);
|
|
886
|
+
setTurnTools([]);
|
|
827
887
|
setStatus("running");
|
|
828
888
|
const controller = new AbortController();
|
|
829
889
|
abortRef.current = controller;
|
|
@@ -833,6 +893,26 @@ function App(props: Readonly<{ harness: HarnessRuntime }>): React.ReactElement {
|
|
|
833
893
|
(event) => {
|
|
834
894
|
if (event.kind === "session_meta") setTitle(event.title);
|
|
835
895
|
if (event.kind === "usage") setSpend(harness.spend);
|
|
896
|
+
if (event.kind === "completion") {
|
|
897
|
+
setTurnTools((tools) => {
|
|
898
|
+
const summary = summarizeTurnTools(tools);
|
|
899
|
+
setLines((prev) => {
|
|
900
|
+
const next = applyEvent(prev, event);
|
|
901
|
+
if (!summary) return next;
|
|
902
|
+
return [
|
|
903
|
+
...next,
|
|
904
|
+
{
|
|
905
|
+
key: `toolsum-${next.length}`,
|
|
906
|
+
type: "system" as const,
|
|
907
|
+
text: summary,
|
|
908
|
+
},
|
|
909
|
+
];
|
|
910
|
+
});
|
|
911
|
+
return [];
|
|
912
|
+
});
|
|
913
|
+
return;
|
|
914
|
+
}
|
|
915
|
+
setTurnTools((prev) => applyTurnToolEvent(prev, event));
|
|
836
916
|
setLines((prev) => applyEvent(prev, event));
|
|
837
917
|
},
|
|
838
918
|
{
|
|
@@ -853,21 +933,44 @@ function App(props: Readonly<{ harness: HarnessRuntime }>): React.ReactElement {
|
|
|
853
933
|
[handleSlash, harness, slashIndex, slashItems, slashOpen, status],
|
|
854
934
|
);
|
|
855
935
|
|
|
856
|
-
const
|
|
857
|
-
if (status === "running") return "
|
|
858
|
-
if (status === "approval") return "
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
936
|
+
const composerHint = useMemo(() => {
|
|
937
|
+
if (status === "running") return "Agent is working… (you can still type your next message)";
|
|
938
|
+
if (status === "approval") return "Answer the approval prompt above (y / n / a)";
|
|
939
|
+
return mediaLine;
|
|
940
|
+
}, [mediaLine, status]);
|
|
941
|
+
|
|
942
|
+
const slashUp = useCallback(
|
|
943
|
+
() => setSlashIndex((index) => stepIndex(index, slashItems.length, -1)),
|
|
944
|
+
[slashItems.length],
|
|
945
|
+
);
|
|
946
|
+
const slashDown = useCallback(
|
|
947
|
+
() => setSlashIndex((index) => stepIndex(index, slashItems.length, 1)),
|
|
948
|
+
[slashItems.length],
|
|
949
|
+
);
|
|
950
|
+
const slashTab = useCallback(() => {
|
|
951
|
+
const selected = slashItems[slashIndex] ?? slashItems[0];
|
|
952
|
+
if (selected) setValue(completeSlashCommand(selected));
|
|
953
|
+
}, [slashIndex, slashItems]);
|
|
862
954
|
|
|
863
955
|
const rail = sidebarWidth(columns);
|
|
956
|
+
const warmupSeed = useMemo(() => lines.filter((line) => line.type === "user").length, [lines]);
|
|
957
|
+
const assistantStarted = lines.at(-1)?.type === "assistant";
|
|
958
|
+
const progressLabel = turnProgressLabel({
|
|
959
|
+
tools: turnTools,
|
|
960
|
+
assistantStarted,
|
|
961
|
+
tick: progressTick,
|
|
962
|
+
warmupSeed,
|
|
963
|
+
});
|
|
964
|
+
const showProgress = status === "running";
|
|
864
965
|
const chrome = tuiChromeRows({
|
|
865
966
|
approval: Boolean(pending),
|
|
866
967
|
pickerCount: picker?.items.length ?? 0,
|
|
867
968
|
slashCount: slashOpen ? slashItems.length : 0,
|
|
969
|
+
activity: showProgress,
|
|
868
970
|
});
|
|
869
|
-
const
|
|
971
|
+
const transcriptHeight = visibleTranscriptRows(rows, chrome);
|
|
870
972
|
const mainWidth = rail ? Math.max(40, columns - rail) : columns;
|
|
973
|
+
const shown = takeLinesForRowBudget(lines, mainWidth, transcriptHeight);
|
|
871
974
|
|
|
872
975
|
const main = (
|
|
873
976
|
<Box flexDirection="column" width={mainWidth} height={rows}>
|
|
@@ -890,22 +993,26 @@ function App(props: Readonly<{ harness: HarnessRuntime }>): React.ReactElement {
|
|
|
890
993
|
/>
|
|
891
994
|
</Box>
|
|
892
995
|
) : (
|
|
893
|
-
<
|
|
894
|
-
<StreamView theme={theme} lines={shown} />
|
|
895
|
-
</Box>
|
|
996
|
+
<StreamView theme={theme} lines={shown} width={mainWidth} height={transcriptHeight} />
|
|
896
997
|
)}
|
|
897
998
|
{pending ? <ApprovalCard theme={theme} req={pending.req} /> : null}
|
|
999
|
+
{showProgress ? (
|
|
1000
|
+
<TurnProgressBar theme={theme} label={progressLabel} width={mainWidth} />
|
|
1001
|
+
) : null}
|
|
898
1002
|
<ComposerFooter
|
|
899
1003
|
theme={theme}
|
|
900
1004
|
status={status}
|
|
901
|
-
statusLabel={statusLabel}
|
|
902
1005
|
value={value}
|
|
1006
|
+
width={mainWidth}
|
|
903
1007
|
onChange={setValue}
|
|
904
1008
|
onSubmit={submit}
|
|
905
1009
|
slashOpen={slashOpen}
|
|
906
1010
|
slashItems={slashItems}
|
|
907
1011
|
slashIndex={slashIndex}
|
|
908
|
-
|
|
1012
|
+
onSlashUp={slashUp}
|
|
1013
|
+
onSlashDown={slashDown}
|
|
1014
|
+
onSlashTab={slashTab}
|
|
1015
|
+
hintLine={composerHint}
|
|
909
1016
|
pickerOpen={Boolean(picker)}
|
|
910
1017
|
/>
|
|
911
1018
|
</Box>
|
|
@@ -927,9 +1034,11 @@ function App(props: Readonly<{ harness: HarnessRuntime }>): React.ReactElement {
|
|
|
927
1034
|
}
|
|
928
1035
|
|
|
929
1036
|
export async function startTui(harness: HarnessRuntime): Promise<void> {
|
|
1037
|
+
const env = await resolveTuiThemeEnv({ ...process.env });
|
|
1038
|
+
const theme = resolveTheme(harness.config.theme, env);
|
|
930
1039
|
const restore = enterAltScreen();
|
|
931
1040
|
try {
|
|
932
|
-
const instance = render(<App harness={harness} />, { patchConsole: true });
|
|
1041
|
+
const instance = render(<App harness={harness} theme={theme} />, { patchConsole: true });
|
|
933
1042
|
await instance.waitUntilExit();
|
|
934
1043
|
} finally {
|
|
935
1044
|
restore();
|
package/src/desktop/bridge.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { randomBytes } from "node:crypto";
|
|
2
2
|
import { readFile, stat } from "node:fs/promises";
|
|
3
3
|
import { isAbsolute, relative, resolve } from "node:path";
|
|
4
|
+
import { resolveAgentCwd } from "../agent-cwd.ts";
|
|
4
5
|
import { mediaModelLabel } from "../cli/media-models.ts";
|
|
5
6
|
import { HARNESS_MODELS, modelPickerItems } from "../cli/models.ts";
|
|
6
7
|
import {
|
|
@@ -1056,7 +1057,10 @@ export async function startDesktopBridge(options: StartDesktopBridgeOptions): Pr
|
|
|
1056
1057
|
}
|
|
1057
1058
|
|
|
1058
1059
|
export async function main(): Promise<void> {
|
|
1059
|
-
const cwd =
|
|
1060
|
+
const cwd = resolveAgentCwd({
|
|
1061
|
+
start: process.env.HARNESS_CWD?.trim() || process.cwd(),
|
|
1062
|
+
explicit: process.env.HARNESS_CWD_EXPLICIT?.trim(),
|
|
1063
|
+
});
|
|
1060
1064
|
const { ready } = await startDesktopBridge({ cwd });
|
|
1061
1065
|
process.stdout.write(`HARNESS_READY=${JSON.stringify(ready)}\n`);
|
|
1062
1066
|
}
|
package/src/product.ts
CHANGED