@songtonyli/dsh-cli 0.1.33 → 0.1.34
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/README.md +1 -1
- package/bin/dsh.mjs +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-sidebar/lib/client.js +1 -1
- package/node_modules/@deepseek-ai/dsh-llm-cursor/README.i18n.yaml +2 -2
- package/node_modules/@deepseek-ai/dsh-llm-cursor/README.md +5 -4
- package/node_modules/@deepseek-ai/dsh-llm-cursor/README.zh.md +5 -4
- package/node_modules/@deepseek-ai/dsh-llm-cursor/lib/index.js +607 -63
- package/node_modules/@deepseek-ai/dsh-tui-app/README.i18n.yaml +2 -2
- package/node_modules/@deepseek-ai/dsh-tui-app/README.md +35 -22
- package/node_modules/@deepseek-ai/dsh-tui-app/README.zh.md +35 -22
- package/node_modules/@deepseek-ai/dsh-tui-app/lib/index.js +1077 -205
- package/package.json +1 -1
|
@@ -551,6 +551,32 @@ function extensionOf(path) {
|
|
|
551
551
|
return dot <= 0 ? void 0 : base.slice(dot + 1).toLowerCase();
|
|
552
552
|
}
|
|
553
553
|
/**
|
|
554
|
+
* Whether a tool delegates to a subagent, by the same name rule the browser's
|
|
555
|
+
* process view applies: the `subagent` tool and every `subagent_*` tool.
|
|
556
|
+
* @param name - the tool name.
|
|
557
|
+
* @returns true for a tool whose card draws as one compact subagent row.
|
|
558
|
+
*/
|
|
559
|
+
function isSubagentTool(name) {
|
|
560
|
+
return name === "subagent" || name.startsWith("subagent_");
|
|
561
|
+
}
|
|
562
|
+
/**
|
|
563
|
+
* Read a subagent call's arguments into the facts its compact row draws.
|
|
564
|
+
* @param args - the parsed arguments, or undefined while they do not parse yet.
|
|
565
|
+
* @returns the description and the dim facts; empty ones for arguments that carry none.
|
|
566
|
+
*/
|
|
567
|
+
function subagentRowFacts(args) {
|
|
568
|
+
const record = typeof args === "object" && args !== null ? { ...args } : {};
|
|
569
|
+
const text = (value) => typeof value === "string" && value !== "" ? value : void 0;
|
|
570
|
+
const meta = [];
|
|
571
|
+
const model = text(record.model);
|
|
572
|
+
if (model !== void 0) meta.push(model);
|
|
573
|
+
if (record.run_in_background === true) meta.push("background");
|
|
574
|
+
return {
|
|
575
|
+
description: text(record.description) ?? "",
|
|
576
|
+
meta
|
|
577
|
+
};
|
|
578
|
+
}
|
|
579
|
+
/**
|
|
554
580
|
* Parse the model's raw argument JSON for presentation.
|
|
555
581
|
* @param argumentsJson - the `tool/call` event's verbatim argument string.
|
|
556
582
|
* @returns the parsed value, or undefined when it is not JSON.
|
|
@@ -573,10 +599,12 @@ function diffBody(diff) {
|
|
|
573
599
|
const rows = hunks(diffLines(diff.oldText, diff.newText), DIFF_CONTEXT_LINES);
|
|
574
600
|
const lines = [];
|
|
575
601
|
const code = [];
|
|
602
|
+
const marks = [];
|
|
576
603
|
for (const row of rows) {
|
|
577
604
|
if (row === void 0) {
|
|
578
605
|
lines.push(" …");
|
|
579
606
|
code.push(void 0);
|
|
607
|
+
marks.push(void 0);
|
|
580
608
|
continue;
|
|
581
609
|
}
|
|
582
610
|
const prefix = row.kind === "added" ? "+ " : row.kind === "removed" ? "- " : " ";
|
|
@@ -586,10 +614,12 @@ function diffBody(diff) {
|
|
|
586
614
|
prefix,
|
|
587
615
|
source: row.text
|
|
588
616
|
});
|
|
617
|
+
marks.push(row.kind === "context" ? void 0 : row.kind);
|
|
589
618
|
}
|
|
590
619
|
return {
|
|
591
620
|
lines,
|
|
592
|
-
code
|
|
621
|
+
code,
|
|
622
|
+
diff: marks
|
|
593
623
|
};
|
|
594
624
|
}
|
|
595
625
|
/**
|
|
@@ -600,14 +630,17 @@ function diffBody(diff) {
|
|
|
600
630
|
function diffsBody(diffs) {
|
|
601
631
|
const lines = [];
|
|
602
632
|
const code = [];
|
|
633
|
+
const marks = [];
|
|
603
634
|
for (const diff of diffs) {
|
|
604
635
|
const body = diffBody(diff);
|
|
605
636
|
lines.push(diff.path, ...body.lines);
|
|
606
637
|
code.push(void 0, ...body.code);
|
|
638
|
+
marks.push(void 0, ...body.diff);
|
|
607
639
|
}
|
|
608
640
|
return {
|
|
609
641
|
lines,
|
|
610
|
-
code
|
|
642
|
+
code,
|
|
643
|
+
diff: marks
|
|
611
644
|
};
|
|
612
645
|
}
|
|
613
646
|
/**
|
|
@@ -1310,17 +1343,17 @@ function reportChange(result) {
|
|
|
1310
1343
|
return text;
|
|
1311
1344
|
}
|
|
1312
1345
|
/** Control Sequence Introducer. */
|
|
1313
|
-
const CSI$
|
|
1346
|
+
const CSI$2 = "\x1B[";
|
|
1314
1347
|
/**
|
|
1315
1348
|
* Ends the foreground color a recolored run set. SGR 39 restores the default
|
|
1316
1349
|
* foreground only: bold, italic, underline, inverse, and the background set by
|
|
1317
1350
|
* enclosing markdown styling stay in force.
|
|
1318
1351
|
*/
|
|
1319
|
-
const RESET_FOREGROUND$1 = `${CSI$
|
|
1352
|
+
const RESET_FOREGROUND$1 = `${CSI$2}39m`;
|
|
1320
1353
|
/** Faint intensity: the only ramp level the two-level mode draws. */
|
|
1321
|
-
const DIM = `${CSI$
|
|
1354
|
+
const DIM = `${CSI$2}2m`;
|
|
1322
1355
|
/** Ends faint intensity. SGR 22 also ends bold, which shares the code. */
|
|
1323
|
-
const RESET_INTENSITY = `${CSI$
|
|
1356
|
+
const RESET_INTENSITY = `${CSI$2}22m`;
|
|
1324
1357
|
/** Ages the two-level mode draws faint; later ages draw as rendered. */
|
|
1325
1358
|
const DIM_AGES = 2;
|
|
1326
1359
|
/** First xterm 256-color grayscale index. */
|
|
@@ -1358,7 +1391,7 @@ const SRGB_GAMMA = 2.4;
|
|
|
1358
1391
|
* segmenter private, so this module holds one; grapheme segmentation does not
|
|
1359
1392
|
* vary by locale.
|
|
1360
1393
|
*/
|
|
1361
|
-
const GRAPHEMES$
|
|
1394
|
+
const GRAPHEMES$2 = new Intl.Segmenter(void 0, { granularity: "grapheme" });
|
|
1362
1395
|
/**
|
|
1363
1396
|
* Decide how far the terminal can draw the ramp.
|
|
1364
1397
|
*
|
|
@@ -1394,7 +1427,7 @@ function resolveFadeCapability(input) {
|
|
|
1394
1427
|
* @param steps - brightness levels; defaults to {@link FADE_STEPS}.
|
|
1395
1428
|
* @returns `steps` levels, darkest first.
|
|
1396
1429
|
*/
|
|
1397
|
-
function buildFadeRamp(bg, fg, steps =
|
|
1430
|
+
function buildFadeRamp(bg, fg, steps = 24) {
|
|
1398
1431
|
return Array.from({ length: steps }, (_unused, level) => {
|
|
1399
1432
|
if (level === steps - 1) return {
|
|
1400
1433
|
r: fg.r,
|
|
@@ -1469,6 +1502,11 @@ function toSrgb(value) {
|
|
|
1469
1502
|
}
|
|
1470
1503
|
/**
|
|
1471
1504
|
* The SGR sequence one age draws under.
|
|
1505
|
+
*
|
|
1506
|
+
* Truecolor draws a fractional age between its two neighbouring ramp levels,
|
|
1507
|
+
* mixed in linear light, so a word brightens continuously however the frames
|
|
1508
|
+
* fall against the level boundaries. The grayscale encoding has fewer values
|
|
1509
|
+
* than the ramp has levels and draws the level the age floors onto.
|
|
1472
1510
|
* @param style - the capability and the ramp.
|
|
1473
1511
|
* @param age - the brightness level; levels past the ramp draw its last one.
|
|
1474
1512
|
* @returns the sequence to open the run with, or the empty string when the
|
|
@@ -1478,9 +1516,19 @@ function toSrgb(value) {
|
|
|
1478
1516
|
function fadeSgr(style, age) {
|
|
1479
1517
|
if (style.capability === "none") return "";
|
|
1480
1518
|
if (style.capability === "dim") return age < DIM_AGES ? DIM : "";
|
|
1481
|
-
const
|
|
1519
|
+
const last = style.ramp.length - 1;
|
|
1520
|
+
const floor = Math.max(0, Math.min(Math.floor(age), last));
|
|
1521
|
+
const level = style.ramp[floor];
|
|
1482
1522
|
if (level === void 0) return "";
|
|
1483
|
-
|
|
1523
|
+
if (style.capability !== "truecolor") return grayscaleSgr(level);
|
|
1524
|
+
const next = style.ramp[floor + 1];
|
|
1525
|
+
const fraction = age - floor;
|
|
1526
|
+
if (next === void 0 || fraction <= 0) return truecolorSgr(level);
|
|
1527
|
+
return truecolorSgr({
|
|
1528
|
+
r: mix(level.r, next.r, fraction),
|
|
1529
|
+
g: mix(level.g, next.g, fraction),
|
|
1530
|
+
b: mix(level.b, next.b, fraction)
|
|
1531
|
+
});
|
|
1484
1532
|
}
|
|
1485
1533
|
/**
|
|
1486
1534
|
* Encode one level as a 24-bit foreground.
|
|
@@ -1488,7 +1536,7 @@ function fadeSgr(style, age) {
|
|
|
1488
1536
|
* @returns `ESC[38;2;R;G;Bm` with each channel clamped to a byte.
|
|
1489
1537
|
*/
|
|
1490
1538
|
function truecolorSgr(color) {
|
|
1491
|
-
return `${CSI$
|
|
1539
|
+
return `${CSI$2}38;2;${channel(color.r)};${channel(color.g)};${channel(color.b)}m`;
|
|
1492
1540
|
}
|
|
1493
1541
|
/**
|
|
1494
1542
|
* Encode one level as the nearest xterm grayscale index.
|
|
@@ -1498,7 +1546,7 @@ function truecolorSgr(color) {
|
|
|
1498
1546
|
function grayscaleSgr(color) {
|
|
1499
1547
|
const luminance = LUMINANCE$1.r * color.r + LUMINANCE$1.g * color.g + LUMINANCE$1.b * color.b;
|
|
1500
1548
|
const step = Math.round((luminance - GRAY_FIRST_VALUE) / GRAY_VALUE_STEP);
|
|
1501
|
-
return `${CSI$
|
|
1549
|
+
return `${CSI$2}38;5;${GRAY_FIRST_INDEX + Math.max(0, Math.min(GRAY_LEVELS - 1, step))}m`;
|
|
1502
1550
|
}
|
|
1503
1551
|
/**
|
|
1504
1552
|
* Clamp one channel to what an SGR byte carries.
|
|
@@ -1686,7 +1734,7 @@ function settledRgb(state, fg) {
|
|
|
1686
1734
|
* @returns the SGR sequence, or empty when the capability cannot encode a mix.
|
|
1687
1735
|
*/
|
|
1688
1736
|
function encodeMix(capability, color) {
|
|
1689
|
-
return capability === "truecolor" ? truecolorSgr(color) : `${CSI$
|
|
1737
|
+
return capability === "truecolor" ? truecolorSgr(color) : `${CSI$2}38;5;${String(nearestAnsi256(color))}m`;
|
|
1690
1738
|
}
|
|
1691
1739
|
/**
|
|
1692
1740
|
* Rebuild one card row as a per-run float-out mix.
|
|
@@ -1883,8 +1931,8 @@ var FadeTracker = class {
|
|
|
1883
1931
|
chunks = [];
|
|
1884
1932
|
openChunk = void 0;
|
|
1885
1933
|
constructor(options) {
|
|
1886
|
-
this.steps = options.steps ??
|
|
1887
|
-
this.stepMs = options.stepMs ??
|
|
1934
|
+
this.steps = options.steps ?? 24;
|
|
1935
|
+
this.stepMs = options.stepMs ?? 16;
|
|
1888
1936
|
this.now = options.now;
|
|
1889
1937
|
}
|
|
1890
1938
|
/**
|
|
@@ -2104,7 +2152,7 @@ function* cellsFromEnd(lines) {
|
|
|
2104
2152
|
for (const [line, text] of [...lines.entries()].reverse()) {
|
|
2105
2153
|
const cells = [];
|
|
2106
2154
|
let column = 0;
|
|
2107
|
-
for (const part of GRAPHEMES$
|
|
2155
|
+
for (const part of GRAPHEMES$2.segment(stripTerminalSequences(text))) {
|
|
2108
2156
|
const width = visibleWidth(part.segment);
|
|
2109
2157
|
cells.push({
|
|
2110
2158
|
line,
|
|
@@ -2167,7 +2215,7 @@ var CellWalk = class {
|
|
|
2167
2215
|
* the walk reached the start of the rendered text mid-chunk.
|
|
2168
2216
|
*/
|
|
2169
2217
|
function consumeSpan(cells, text) {
|
|
2170
|
-
const wanted = Array.from(GRAPHEMES$
|
|
2218
|
+
const wanted = Array.from(GRAPHEMES$2.segment(text), (part) => part.segment).filter((part) => !isBlank(part)).reverse();
|
|
2171
2219
|
const covered = [];
|
|
2172
2220
|
let index = 0;
|
|
2173
2221
|
let matched = 0;
|
|
@@ -2348,7 +2396,8 @@ const SGR = {
|
|
|
2348
2396
|
success: ["32", "39"],
|
|
2349
2397
|
warning: ["33", "39"],
|
|
2350
2398
|
error: ["31", "39"],
|
|
2351
|
-
inverse: ["7", "27"]
|
|
2399
|
+
inverse: ["7", "27"],
|
|
2400
|
+
band: ["48;5;236", "49"]
|
|
2352
2401
|
};
|
|
2353
2402
|
/**
|
|
2354
2403
|
* Build the palette.
|
|
@@ -2373,6 +2422,7 @@ function createPalette(enabled) {
|
|
|
2373
2422
|
warning: role("warning"),
|
|
2374
2423
|
error: role("error"),
|
|
2375
2424
|
inverse: role("inverse"),
|
|
2425
|
+
band: role("band"),
|
|
2376
2426
|
enabled
|
|
2377
2427
|
};
|
|
2378
2428
|
}
|
|
@@ -2393,6 +2443,58 @@ function paintDiffRows(rows, source, palette) {
|
|
|
2393
2443
|
});
|
|
2394
2444
|
}
|
|
2395
2445
|
/**
|
|
2446
|
+
* Lay one row on the {@link Palette.band} tint across the full width.
|
|
2447
|
+
* @param palette - the active palette.
|
|
2448
|
+
* @param row - the styled row, at most `width` columns.
|
|
2449
|
+
* @param width - the columns the band spans.
|
|
2450
|
+
* @returns the row padded to `width` under the tint; the row unchanged, with
|
|
2451
|
+
* no padding, when the palette is disabled.
|
|
2452
|
+
*/
|
|
2453
|
+
function bandRow(palette, row, width) {
|
|
2454
|
+
return palette.enabled ? palette.band(`${row}${" ".repeat(Math.max(0, width - visibleWidth(row)))}`) : row;
|
|
2455
|
+
}
|
|
2456
|
+
/** Narrowest width a diff box is drawn at: two borders, two spaces, and one column of text. */
|
|
2457
|
+
const DIFF_BOX_MIN_WIDTH = 5;
|
|
2458
|
+
/**
|
|
2459
|
+
* Wrap rows to `width`, framing each run of consecutive additions in a green
|
|
2460
|
+
* rounded box and each run of consecutive removals in a red one, so a change
|
|
2461
|
+
* reads as one region. A removal run directly followed by an addition run
|
|
2462
|
+
* draws as two stacked boxes, the old text above the new. Every returned line
|
|
2463
|
+
* is at most `width` columns, and every box line is exactly `width`.
|
|
2464
|
+
* @param rows - the styled rows.
|
|
2465
|
+
* @param marks - per row, whether it is an addition or a removal; undefined
|
|
2466
|
+
* for a row outside every box.
|
|
2467
|
+
* @param width - the columns the rows fit.
|
|
2468
|
+
* @param palette - the active palette; a disabled one draws the boxes uncolored.
|
|
2469
|
+
* @returns the wrapped rows with the boxes drawn around the changes; rows
|
|
2470
|
+
* wrapped without boxes when the width cannot hold a box.
|
|
2471
|
+
*/
|
|
2472
|
+
function boxDiffRows(rows, marks, width, palette) {
|
|
2473
|
+
const out = [];
|
|
2474
|
+
const inner = width - 4;
|
|
2475
|
+
let open;
|
|
2476
|
+
const close = () => {
|
|
2477
|
+
if (open === void 0) return;
|
|
2478
|
+
const paint = open === "added" ? palette.success : palette.error;
|
|
2479
|
+
out.push(paint(`╰${"─".repeat(width - 2)}╯`));
|
|
2480
|
+
open = void 0;
|
|
2481
|
+
};
|
|
2482
|
+
for (const [index, row] of rows.entries()) {
|
|
2483
|
+
const mark = width < DIFF_BOX_MIN_WIDTH ? void 0 : marks[index];
|
|
2484
|
+
if (mark !== open) close();
|
|
2485
|
+
if (mark === void 0) {
|
|
2486
|
+
out.push(...wrapTextWithAnsi(row, Math.max(1, width)));
|
|
2487
|
+
continue;
|
|
2488
|
+
}
|
|
2489
|
+
const paint = mark === "added" ? palette.success : palette.error;
|
|
2490
|
+
if (open === void 0) out.push(paint(`╭${"─".repeat(width - 2)}╮`));
|
|
2491
|
+
open = mark;
|
|
2492
|
+
for (const part of wrapTextWithAnsi(row, inner)) out.push(`${paint("│")} ${part}${" ".repeat(Math.max(0, inner - visibleWidth(part)))} ${paint("│")}`);
|
|
2493
|
+
}
|
|
2494
|
+
close();
|
|
2495
|
+
return out;
|
|
2496
|
+
}
|
|
2497
|
+
/**
|
|
2396
2498
|
* Decide whether the terminal gets color: `NO_COLOR` (any non-empty value)
|
|
2397
2499
|
* wins, then a non-empty non-zero `FORCE_COLOR`, then whether stdout is a TTY.
|
|
2398
2500
|
* @param env - the process environment.
|
|
@@ -2496,6 +2598,20 @@ const PART_GUTTER = "┃ ";
|
|
|
2496
2598
|
const NO_ARGUMENTS = "(no arguments)";
|
|
2497
2599
|
/** What the result section reports for a tool that answered with nothing. */
|
|
2498
2600
|
const NO_OUTPUT = "(no output)";
|
|
2601
|
+
/** Glyph a tool card header opens with, coloured by the card's status. */
|
|
2602
|
+
const TOOL_GLYPH = "◆";
|
|
2603
|
+
/** Glyph a user prompt opens with. */
|
|
2604
|
+
const USER_GLYPH = "❯";
|
|
2605
|
+
/** Glyph the reasoning header opens with; the reader marks reasoning sections with the same one. */
|
|
2606
|
+
const REASONING_GLYPH = "✻";
|
|
2607
|
+
/**
|
|
2608
|
+
* The header above a message's reasoning rows. It is one fixed string for a
|
|
2609
|
+
* streaming and a committed message alike, so committing never rewrites a row
|
|
2610
|
+
* that may already sit above the repaint floor.
|
|
2611
|
+
*/
|
|
2612
|
+
const REASONING_TITLE = "Thinking";
|
|
2613
|
+
/** Columns the reasoning rows are indented under their header. */
|
|
2614
|
+
const REASONING_INDENT = " ";
|
|
2499
2615
|
/**
|
|
2500
2616
|
* Whether one transcript child folds.
|
|
2501
2617
|
* @param child - a child of the transcript container.
|
|
@@ -2649,7 +2765,7 @@ var UserShellBlock = class {
|
|
|
2649
2765
|
this.drawn.clear();
|
|
2650
2766
|
}
|
|
2651
2767
|
/**
|
|
2652
|
-
* Draw the run, colouring `$ command` when the grammar answers.
|
|
2768
|
+
* Draw the run, colouring `$ command` when the grammar answers and the `$` in the accent.
|
|
2653
2769
|
* @param width - the columns the block lays out in.
|
|
2654
2770
|
* @returns a blank line, the wrapped rows, and a trailing blank line.
|
|
2655
2771
|
*/
|
|
@@ -2658,15 +2774,19 @@ var UserShellBlock = class {
|
|
|
2658
2774
|
const { lines, code } = shellCommandBody(this.command, this.rows.slice(1));
|
|
2659
2775
|
const painted = paintCodeRows(lines, code, this.theme.codeHighlight);
|
|
2660
2776
|
const inner = Math.max(1, width);
|
|
2777
|
+
const [command = "", ...output] = painted;
|
|
2661
2778
|
return [
|
|
2662
2779
|
"",
|
|
2663
|
-
...
|
|
2780
|
+
...[`${this.theme.palette.accent("$ ".trimEnd())} ${command.slice(2)}`, ...output].flatMap((row) => wrapTextWithAnsi(row, inner)),
|
|
2664
2781
|
""
|
|
2665
2782
|
];
|
|
2666
2783
|
});
|
|
2667
2784
|
}
|
|
2668
2785
|
};
|
|
2669
|
-
/**
|
|
2786
|
+
/**
|
|
2787
|
+
* A prompt the user submitted, drawn with a leading {@link USER_GLYPH} on the
|
|
2788
|
+
* palette's background band, which spans every row of the prompt.
|
|
2789
|
+
*/
|
|
2670
2790
|
var UserBlock = class {
|
|
2671
2791
|
theme;
|
|
2672
2792
|
text;
|
|
@@ -2709,12 +2829,15 @@ var UserBlock = class {
|
|
|
2709
2829
|
const palette = this.theme.palette;
|
|
2710
2830
|
const { marked, content: inner } = focusFrame(width, this.highlight);
|
|
2711
2831
|
const lines = this.drawn.get(`${String(width)}:${String(marked)}`, () => {
|
|
2712
|
-
return ["", ...wrapTextWithAnsi(this.text, Math.max(1, inner - 2)).map((line, index) => `${palette.accent(index === 0 ?
|
|
2832
|
+
return ["", ...wrapTextWithAnsi(this.text, Math.max(1, inner - 2)).map((line, index) => bandRow(palette, `${palette.accent(index === 0 ? USER_GLYPH : " ")} ${palette.bold(line)}`, inner))];
|
|
2713
2833
|
});
|
|
2714
2834
|
return marked ? withGutter(palette, lines, () => true, this.highlightLevel) : lines;
|
|
2715
2835
|
}
|
|
2716
2836
|
};
|
|
2717
|
-
/**
|
|
2837
|
+
/**
|
|
2838
|
+
* What a compact context row uses in place of the user prompt's
|
|
2839
|
+
* {@link USER_GLYPH}; the reader marks context sections with the same one.
|
|
2840
|
+
*/
|
|
2718
2841
|
const CONTEXT_GLYPH = "⬡";
|
|
2719
2842
|
/** A dim one-line notice about the session (a stopped turn, a command result, a model switch). */
|
|
2720
2843
|
var NoticeBlock = class {
|
|
@@ -3071,7 +3194,8 @@ var AssistantBlock = class {
|
|
|
3071
3194
|
return withGutter(this.theme.palette, lines, (index) => index >= section.from && index < section.to, this.highlightLevel);
|
|
3072
3195
|
}
|
|
3073
3196
|
/**
|
|
3074
|
-
* Stack the reasoning
|
|
3197
|
+
* Stack the reasoning, under its {@link REASONING_TITLE} header and
|
|
3198
|
+
* indented, over the reply, each through its own tail.
|
|
3075
3199
|
* @param inner - the columns the message lays out in.
|
|
3076
3200
|
* @returns the lines, gutter not yet applied, and where each section falls.
|
|
3077
3201
|
*/
|
|
@@ -3086,8 +3210,11 @@ var AssistantBlock = class {
|
|
|
3086
3210
|
to: 0
|
|
3087
3211
|
};
|
|
3088
3212
|
if (this.reasoning.trim() !== "") {
|
|
3213
|
+
const palette = this.theme.palette;
|
|
3089
3214
|
reasoning.from = lines.length;
|
|
3090
|
-
lines.push(
|
|
3215
|
+
lines.push(truncateToWidth(`${palette.heading(REASONING_GLYPH)} ${palette.dim(REASONING_TITLE)}`, inner, "…"));
|
|
3216
|
+
const width = Math.max(1, inner - 2);
|
|
3217
|
+
lines.push(...this.renderReasoning(width, lines.length).map((line) => `${REASONING_INDENT}${line}`));
|
|
3091
3218
|
reasoning.to = lines.length;
|
|
3092
3219
|
lines.push("");
|
|
3093
3220
|
}
|
|
@@ -3188,7 +3315,8 @@ var AssistantBlock = class {
|
|
|
3188
3315
|
}
|
|
3189
3316
|
};
|
|
3190
3317
|
/**
|
|
3191
|
-
* A tool call card: status
|
|
3318
|
+
* A tool call card: the status-coloured {@link TOOL_GLYPH}, the bold tool
|
|
3319
|
+
* name, the headline in the link colour, then a foldable body.
|
|
3192
3320
|
*
|
|
3193
3321
|
* The card arrives in two pieces, and each floats out on its own: the header
|
|
3194
3322
|
* and the call rows when the model starts the call (a stream delta, or the
|
|
@@ -3206,6 +3334,10 @@ var ToolBlock = class {
|
|
|
3206
3334
|
resultLines = [];
|
|
3207
3335
|
/** The code span behind each result row, for a `read` or `diff` result; absent otherwise. */
|
|
3208
3336
|
resultCode;
|
|
3337
|
+
/** Which result rows are diff additions or removals, for a `diff` result; absent otherwise. */
|
|
3338
|
+
resultDiff;
|
|
3339
|
+
/** The facts a folded subagent card draws as one row; absent for every other tool. */
|
|
3340
|
+
subagent;
|
|
3209
3341
|
expanded = false;
|
|
3210
3342
|
fade;
|
|
3211
3343
|
resultFade;
|
|
@@ -3272,6 +3404,16 @@ var ToolBlock = class {
|
|
|
3272
3404
|
this.revision += 1;
|
|
3273
3405
|
}
|
|
3274
3406
|
/**
|
|
3407
|
+
* Draw this card, while folded, as one subagent row: the task description
|
|
3408
|
+
* and its route, with the tool name while it runs and the outcome tag once
|
|
3409
|
+
* it settled. Unfolding draws the full card.
|
|
3410
|
+
* @param facts - the row's description and dim facts.
|
|
3411
|
+
*/
|
|
3412
|
+
setSubagent(facts) {
|
|
3413
|
+
this.subagent = facts;
|
|
3414
|
+
this.revision += 1;
|
|
3415
|
+
}
|
|
3416
|
+
/**
|
|
3275
3417
|
* Draw the header and the call rows through `fade` until it settles.
|
|
3276
3418
|
* @param fade - the level and drawing settings of this card's own fade.
|
|
3277
3419
|
*/
|
|
@@ -3303,10 +3445,12 @@ var ToolBlock = class {
|
|
|
3303
3445
|
* @param lines - the result rows before preview truncation.
|
|
3304
3446
|
* @param isError - whether the tool reported failure.
|
|
3305
3447
|
* @param code - the span behind each row, for a result the card colours as code.
|
|
3448
|
+
* @param diff - which rows are diff additions or removals, for a result the card boxes as a diff.
|
|
3306
3449
|
*/
|
|
3307
|
-
setResult(lines, isError, code) {
|
|
3450
|
+
setResult(lines, isError, code, diff) {
|
|
3308
3451
|
this.resultLines = lines;
|
|
3309
3452
|
this.resultCode = code;
|
|
3453
|
+
this.resultDiff = diff;
|
|
3310
3454
|
this.status = isError ? "error" : "done";
|
|
3311
3455
|
this.revision += 1;
|
|
3312
3456
|
}
|
|
@@ -3365,7 +3509,16 @@ var ToolBlock = class {
|
|
|
3365
3509
|
*/
|
|
3366
3510
|
layout(outer, marked) {
|
|
3367
3511
|
const palette = this.theme.palette;
|
|
3368
|
-
|
|
3512
|
+
if (this.subagent !== void 0 && !this.expanded) {
|
|
3513
|
+
const row = this.subagentRow(this.subagent, outer);
|
|
3514
|
+
return {
|
|
3515
|
+
call: [row],
|
|
3516
|
+
result: [],
|
|
3517
|
+
lines: ["", row],
|
|
3518
|
+
marker: 0
|
|
3519
|
+
};
|
|
3520
|
+
}
|
|
3521
|
+
const header = `${this.statusStyle()(TOOL_GLYPH)} ${palette.bold(this.toolName)}${this.call.title === "" ? "" : ` ${palette.link(this.call.title)}`}`;
|
|
3369
3522
|
const loading = this.status === "running" ? ["…"] : [];
|
|
3370
3523
|
const body = [
|
|
3371
3524
|
...this.call.lines,
|
|
@@ -3380,11 +3533,16 @@ var ToolBlock = class {
|
|
|
3380
3533
|
const kept = this.expanded ? body : foldRows(body, this.theme.toolPreviewLines, (hidden) => foldMarker(hidden, marked ? "marked" : "transcript"));
|
|
3381
3534
|
const shown = paintDiffRows(paintCodeRows(kept, code, this.theme.codeHighlight), kept, palette);
|
|
3382
3535
|
const callCount = Math.min(this.call.lines.length + loading.length, shown.length);
|
|
3383
|
-
const inner = Math.max(1, outer - 4);
|
|
3384
|
-
const rows = (lines) => lines.flatMap((line) => wrapTextWithAnsi(line, inner).map((part) => ` ${palette.dim("│")} ${part}`));
|
|
3385
|
-
const call = [...wrapTextWithAnsi(header, outer), ...rows(shown.slice(0, callCount))];
|
|
3386
|
-
const result = rows(shown.slice(callCount));
|
|
3387
3536
|
const cut = !this.expanded && body.length > this.theme.toolPreviewLines;
|
|
3537
|
+
const marks = [
|
|
3538
|
+
...this.call.diff ?? new Array(this.call.lines.length).fill(void 0),
|
|
3539
|
+
...new Array(loading.length).fill(void 0),
|
|
3540
|
+
...this.resultDiff ?? new Array(this.resultLines.length).fill(void 0)
|
|
3541
|
+
].slice(0, cut ? kept.length - 1 : kept.length);
|
|
3542
|
+
const inner = Math.max(1, outer - 4);
|
|
3543
|
+
const rows = (from, to) => boxDiffRows(shown.slice(from, to), marks.slice(from, to), inner, palette).map((part) => ` ${palette.dim("│")} ${part}`);
|
|
3544
|
+
const call = [...wrapTextWithAnsi(header, outer), ...rows(0, callCount)];
|
|
3545
|
+
const result = rows(callCount, shown.length);
|
|
3388
3546
|
return {
|
|
3389
3547
|
call,
|
|
3390
3548
|
result,
|
|
@@ -3393,9 +3551,41 @@ var ToolBlock = class {
|
|
|
3393
3551
|
...call,
|
|
3394
3552
|
...result
|
|
3395
3553
|
],
|
|
3396
|
-
marker: cut ? rows(shown.
|
|
3554
|
+
marker: cut ? rows(shown.length - 1, shown.length).length : 0
|
|
3397
3555
|
};
|
|
3398
3556
|
}
|
|
3557
|
+
/**
|
|
3558
|
+
* The colour of this card's status glyph.
|
|
3559
|
+
* @returns warning while running, success once done, error once failed.
|
|
3560
|
+
*/
|
|
3561
|
+
statusStyle() {
|
|
3562
|
+
const palette = this.theme.palette;
|
|
3563
|
+
return this.status === "running" ? palette.warning : this.status === "done" ? palette.success : palette.error;
|
|
3564
|
+
}
|
|
3565
|
+
/**
|
|
3566
|
+
* The one row a folded subagent card draws, led by the status-coloured
|
|
3567
|
+
* {@link SUBAGENT_RUNNING_GLYPH}. A running row carries the accent tool
|
|
3568
|
+
* name; a settled row is dim and ends on its outcome tag at the right edge:
|
|
3569
|
+
* `[failed]` for an error, `[started]` for a call that handed the child to
|
|
3570
|
+
* the background, whose result reads `started …` and whose glyph is dim,
|
|
3571
|
+
* and `[done]` for a call that returned the child's answer.
|
|
3572
|
+
* @param facts - the description and the dim facts.
|
|
3573
|
+
* @param width - the columns the row fits.
|
|
3574
|
+
* @returns the row, no wider than `width`.
|
|
3575
|
+
*/
|
|
3576
|
+
subagentRow(facts, width) {
|
|
3577
|
+
const palette = this.theme.palette;
|
|
3578
|
+
const meta = facts.meta.length === 0 ? "" : ` ${palette.dim(facts.meta.join(" · "))}`;
|
|
3579
|
+
const description = facts.description === "" ? "" : ` ${facts.description}`;
|
|
3580
|
+
if (this.status === "running") {
|
|
3581
|
+
const name = palette.bold(palette.accent(this.toolName));
|
|
3582
|
+
return truncateToWidth(`${palette.warning("◆")} ${name}${description}${meta}`, width, "…");
|
|
3583
|
+
}
|
|
3584
|
+
const started = this.status === "done" && this.resultLines[0]?.startsWith("started ") === true;
|
|
3585
|
+
const tag = this.status === "error" ? palette.error("[failed]") : started ? palette.dim("[started]") : palette.success("[done]");
|
|
3586
|
+
const cut = truncateToWidth(`${started ? palette.dim("◆") : this.statusStyle()("◆")} ${palette.dim(facts.description === "" ? this.toolName : facts.description)}${meta}`, Math.max(1, width - visibleWidth(tag) - 1), "…");
|
|
3587
|
+
return truncateToWidth(`${cut}${" ".repeat(Math.max(1, width - visibleWidth(cut) - visibleWidth(tag)))}${tag}`, width, "…");
|
|
3588
|
+
}
|
|
3399
3589
|
};
|
|
3400
3590
|
/**
|
|
3401
3591
|
* Draw one group of a card's rows at the mix its fade reports.
|
|
@@ -3814,7 +4004,7 @@ const REVERSE_VIDEO_OFF = "\x1B[0m";
|
|
|
3814
4004
|
/** Ends colour, bold, and italic a sliced token may have left open. */
|
|
3815
4005
|
const RESET_PAINT = "\x1B[39m\x1B[22m\x1B[23m";
|
|
3816
4006
|
/** Graphemes the overlay wraps at, matching the editor's default segmenter. */
|
|
3817
|
-
const GRAPHEMES = new Intl.Segmenter(void 0, { granularity: "grapheme" });
|
|
4007
|
+
const GRAPHEMES$1 = new Intl.Segmenter(void 0, { granularity: "grapheme" });
|
|
3818
4008
|
/**
|
|
3819
4009
|
* Take pi-tui's drawn block cursor off one rendered editor line.
|
|
3820
4010
|
*
|
|
@@ -3964,7 +4154,7 @@ function wrapEditorLine(line, maxWidth) {
|
|
|
3964
4154
|
endIndex: line.length
|
|
3965
4155
|
}];
|
|
3966
4156
|
const chunks = [];
|
|
3967
|
-
const segments = [...GRAPHEMES.segment(line)];
|
|
4157
|
+
const segments = [...GRAPHEMES$1.segment(line)];
|
|
3968
4158
|
let currentWidth = 0;
|
|
3969
4159
|
let chunkStart = 0;
|
|
3970
4160
|
let wrapOppIndex = -1;
|
|
@@ -4317,6 +4507,109 @@ async function exportSessionZip(ctx, sessionId, directory, signal) {
|
|
|
4317
4507
|
await pipeline(Readable.fromWeb(archive), createWriteStream(path), { signal });
|
|
4318
4508
|
return path;
|
|
4319
4509
|
}
|
|
4510
|
+
//#endregion
|
|
4511
|
+
//#region lib/types/pace.js
|
|
4512
|
+
/**
|
|
4513
|
+
* Grapheme segmenter for release cuts, so a frame never splits a surrogate
|
|
4514
|
+
* pair, a combining sequence, or a joined emoji.
|
|
4515
|
+
*/
|
|
4516
|
+
const GRAPHEMES = new Intl.Segmenter(void 0, { granularity: "grapheme" });
|
|
4517
|
+
/** The ordered queue of streamed text waiting for a frame. */
|
|
4518
|
+
var StreamPacer = class {
|
|
4519
|
+
drainFrames;
|
|
4520
|
+
entries = [];
|
|
4521
|
+
/** Graphemes the next frame may release beyond its own share. */
|
|
4522
|
+
credit = 0;
|
|
4523
|
+
/** UTF-16 length of the queued text, used as the backlog estimate. */
|
|
4524
|
+
backlog = 0;
|
|
4525
|
+
/** @param options - the drain length in frames. */
|
|
4526
|
+
constructor(options) {
|
|
4527
|
+
this.drainFrames = Math.max(1, options.drainFrames);
|
|
4528
|
+
}
|
|
4529
|
+
/**
|
|
4530
|
+
* Queue one delta.
|
|
4531
|
+
* @param channel - what the text belongs to; a push onto the same channel
|
|
4532
|
+
* as the newest entry extends that entry and keeps its `release`.
|
|
4533
|
+
* @param text - the delta. An empty delta still queues an entry, released
|
|
4534
|
+
* on the next frame at no cost, so a tool name that arrives without
|
|
4535
|
+
* arguments reaches the transcript in order.
|
|
4536
|
+
* @param release - receives the released parts of this entry, in order.
|
|
4537
|
+
*/
|
|
4538
|
+
push(channel, text, release) {
|
|
4539
|
+
const last = this.entries.at(-1);
|
|
4540
|
+
if (last !== void 0 && last.channel === channel) last.text += text;
|
|
4541
|
+
else this.entries.push({
|
|
4542
|
+
channel,
|
|
4543
|
+
text,
|
|
4544
|
+
release
|
|
4545
|
+
});
|
|
4546
|
+
this.backlog += text.length;
|
|
4547
|
+
}
|
|
4548
|
+
/**
|
|
4549
|
+
* Whether text is still waiting for a frame.
|
|
4550
|
+
* @returns true while any entry is queued.
|
|
4551
|
+
*/
|
|
4552
|
+
pending() {
|
|
4553
|
+
return this.entries.length > 0;
|
|
4554
|
+
}
|
|
4555
|
+
/**
|
|
4556
|
+
* Release one frame's share of the backlog.
|
|
4557
|
+
* @returns whether text is still queued after this frame.
|
|
4558
|
+
*/
|
|
4559
|
+
frame() {
|
|
4560
|
+
this.credit += Math.max(1, this.backlog / this.drainFrames);
|
|
4561
|
+
let budget = Math.floor(this.credit);
|
|
4562
|
+
this.credit -= budget;
|
|
4563
|
+
for (let entry = this.entries[0]; entry !== void 0; entry = this.entries[0]) {
|
|
4564
|
+
const cut = cutGraphemes(entry.text, budget);
|
|
4565
|
+
if (cut.graphemes === 0 && entry.text !== "") break;
|
|
4566
|
+
budget -= cut.graphemes;
|
|
4567
|
+
this.backlog -= cut.length;
|
|
4568
|
+
const head = entry.text.slice(0, cut.length);
|
|
4569
|
+
entry.text = entry.text.slice(cut.length);
|
|
4570
|
+
if (entry.text === "") this.entries.shift();
|
|
4571
|
+
entry.release(head);
|
|
4572
|
+
}
|
|
4573
|
+
if (this.entries.length === 0) this.credit = 0;
|
|
4574
|
+
return this.entries.length > 0;
|
|
4575
|
+
}
|
|
4576
|
+
/** Release everything queued, in order, at once. */
|
|
4577
|
+
flush() {
|
|
4578
|
+
const entries = this.entries.splice(0);
|
|
4579
|
+
this.backlog = 0;
|
|
4580
|
+
this.credit = 0;
|
|
4581
|
+
for (const entry of entries) entry.release(entry.text);
|
|
4582
|
+
}
|
|
4583
|
+
/** Drop everything queued without releasing it. */
|
|
4584
|
+
clear() {
|
|
4585
|
+
this.entries.length = 0;
|
|
4586
|
+
this.backlog = 0;
|
|
4587
|
+
this.credit = 0;
|
|
4588
|
+
}
|
|
4589
|
+
};
|
|
4590
|
+
/**
|
|
4591
|
+
* Measure the longest prefix of `text` that holds at most `limit` graphemes.
|
|
4592
|
+
* @param text - the queued text.
|
|
4593
|
+
* @param limit - graphemes the frame may still release.
|
|
4594
|
+
* @returns the prefix's grapheme count and UTF-16 length.
|
|
4595
|
+
*/
|
|
4596
|
+
function cutGraphemes(text, limit) {
|
|
4597
|
+
if (limit <= 0) return {
|
|
4598
|
+
graphemes: 0,
|
|
4599
|
+
length: 0
|
|
4600
|
+
};
|
|
4601
|
+
let graphemes = 0;
|
|
4602
|
+
let length = 0;
|
|
4603
|
+
for (const part of GRAPHEMES.segment(text)) {
|
|
4604
|
+
if (graphemes === limit) break;
|
|
4605
|
+
graphemes += 1;
|
|
4606
|
+
length += part.segment.length;
|
|
4607
|
+
}
|
|
4608
|
+
return {
|
|
4609
|
+
graphemes,
|
|
4610
|
+
length
|
|
4611
|
+
};
|
|
4612
|
+
}
|
|
4320
4613
|
/** Columns the ` ─ ` between the chip and the title takes. */
|
|
4321
4614
|
const CHIP_MARGIN = 3;
|
|
4322
4615
|
/** What opens a top rule. */
|
|
@@ -4483,7 +4776,7 @@ const HINTS = {
|
|
|
4483
4776
|
"esc cancel"
|
|
4484
4777
|
],
|
|
4485
4778
|
panel: [
|
|
4486
|
-
"↑↓ children · Enter
|
|
4779
|
+
"↑↓ children · Enter opens · Tab regions · Esc input",
|
|
4487
4780
|
"↑↓ children · Esc input",
|
|
4488
4781
|
"Esc input"
|
|
4489
4782
|
],
|
|
@@ -4561,6 +4854,7 @@ const KEY_LINES = {
|
|
|
4561
4854
|
`${ENTRY_KEYS} · Ctrl+G reader`,
|
|
4562
4855
|
"Shift+↑ selects follow-ups while they wait",
|
|
4563
4856
|
"Ctrl+O folds every tool card and context row",
|
|
4857
|
+
"Ctrl+T todos · Ctrl+P parent session · Ctrl+L redraw · ? keys",
|
|
4564
4858
|
"Esc arms the stop · Esc again stops the turn",
|
|
4565
4859
|
"Ctrl+C clears the input, twice quits · Ctrl+D quits an empty input"
|
|
4566
4860
|
],
|
|
@@ -4580,8 +4874,8 @@ const OPEN = { kind: "open" };
|
|
|
4580
4874
|
/**
|
|
4581
4875
|
* What one key press means where the keyboard is.
|
|
4582
4876
|
*
|
|
4583
|
-
* `Escape`, `Ctrl+O`, and `Ctrl+
|
|
4584
|
-
* answered first. Everything else is the region's own.
|
|
4877
|
+
* `Escape`, `Ctrl+O`, `Ctrl+G`, `Ctrl+T`, `Ctrl+P`, and `Ctrl+L` mean the
|
|
4878
|
+
* same thing everywhere and are answered first. Everything else is the region's own.
|
|
4585
4879
|
* @param region - the region holding the keyboard.
|
|
4586
4880
|
* @param data - the raw key bytes.
|
|
4587
4881
|
* @returns the action to apply, or undefined when this region claims nothing
|
|
@@ -4592,6 +4886,9 @@ function resolveKey(region, data) {
|
|
|
4592
4886
|
if (matchesKey(data, "escape")) return ESCAPE;
|
|
4593
4887
|
if (matchesKey(data, "ctrl+o")) return FOLD_ALL;
|
|
4594
4888
|
if (matchesKey(data, "ctrl+g")) return READER;
|
|
4889
|
+
if (matchesKey(data, "ctrl+t")) return { kind: "todos" };
|
|
4890
|
+
if (matchesKey(data, "ctrl+p")) return { kind: "parent" };
|
|
4891
|
+
if (matchesKey(data, "ctrl+l")) return { kind: "redraw" };
|
|
4595
4892
|
switch (region) {
|
|
4596
4893
|
case "editor": return editorKey(data);
|
|
4597
4894
|
case "transcript": return transcriptKey(data);
|
|
@@ -4621,6 +4918,7 @@ function editorKey(data) {
|
|
|
4621
4918
|
};
|
|
4622
4919
|
if (matchesKey(data, "ctrl+s")) return { kind: "steer" };
|
|
4623
4920
|
if (matchesKey(data, "shift+tab")) return { kind: "effort" };
|
|
4921
|
+
if (data === "?") return { kind: "help" };
|
|
4624
4922
|
}
|
|
4625
4923
|
/**
|
|
4626
4924
|
* The transcript's movement keys: the arrows step one section and one part,
|
|
@@ -4879,7 +5177,7 @@ function queueKey(data) {
|
|
|
4879
5177
|
function panelKey(data) {
|
|
4880
5178
|
const move = moveKey(data, PANEL_MOVES);
|
|
4881
5179
|
if (move !== void 0) return move;
|
|
4882
|
-
if (matchesKey(data, "enter")) return OPEN;
|
|
5180
|
+
if (matchesKey(data, "enter") || matchesKey(data, "right")) return OPEN;
|
|
4883
5181
|
return cycleKey(data) ?? typeKey(data);
|
|
4884
5182
|
}
|
|
4885
5183
|
/**
|
|
@@ -5209,7 +5507,7 @@ function flattenSections(blocks) {
|
|
|
5209
5507
|
* @param right - the other.
|
|
5210
5508
|
* @returns true when both name the same block and part.
|
|
5211
5509
|
*/
|
|
5212
|
-
function sameSection(left, right) {
|
|
5510
|
+
function sameSection$1(left, right) {
|
|
5213
5511
|
return left.block === right.block && left.part === right.part;
|
|
5214
5512
|
}
|
|
5215
5513
|
/**
|
|
@@ -5241,7 +5539,7 @@ function moveSection(cursor, step, blocks) {
|
|
|
5241
5539
|
if (index < 0) return sectionAt$1(sections, step >= 0 ? sections.length - 1 : 0, cursor);
|
|
5242
5540
|
return sectionAt$1(sections, index, cursor);
|
|
5243
5541
|
}
|
|
5244
|
-
const index = sections.findIndex((section) => sameSection(section, settled));
|
|
5542
|
+
const index = sections.findIndex((section) => sameSection$1(section, settled));
|
|
5245
5543
|
/* v8 ignore next -- a settled cursor is always in flattenSections */
|
|
5246
5544
|
if (index < 0) return settled;
|
|
5247
5545
|
return sectionAt$1(sections, clampIndex(index + step, sections.length), settled);
|
|
@@ -7105,9 +7403,9 @@ function renderQueuePanel(rows, render) {
|
|
|
7105
7403
|
/** Narrowest turn list. */
|
|
7106
7404
|
const LIST_MIN_WIDTH = 18;
|
|
7107
7405
|
/** Widest turn list. */
|
|
7108
|
-
const LIST_MAX_WIDTH =
|
|
7406
|
+
const LIST_MAX_WIDTH = 28;
|
|
7109
7407
|
/** Share of the terminal the turn list asks for between its two bounds. */
|
|
7110
|
-
const LIST_SHARE = .
|
|
7408
|
+
const LIST_SHARE = .25;
|
|
7111
7409
|
/** Rows the frame itself takes: the top rule, the legend rule, and the bottom rule. */
|
|
7112
7410
|
const CHROME_ROWS = 3;
|
|
7113
7411
|
/** Columns one body column spends on the border before it and the space after it. */
|
|
@@ -7118,12 +7416,46 @@ const READER_CHIP = "READER";
|
|
|
7118
7416
|
const ELLIPSIS$1 = "…";
|
|
7119
7417
|
/** The left border of a body row and the border between the two panels. */
|
|
7120
7418
|
const SIDE = "│";
|
|
7121
|
-
/** Marks the listed
|
|
7122
|
-
const LIST_MARK = "▸
|
|
7123
|
-
/**
|
|
7124
|
-
const
|
|
7125
|
-
/**
|
|
7126
|
-
const
|
|
7419
|
+
/** Marks the listed section the keyboard holds. */
|
|
7420
|
+
const LIST_MARK = "▸";
|
|
7421
|
+
/** Opens the prompt band and the list's row for the turn being read, as it opens a prompt in the conversation. */
|
|
7422
|
+
const PROMPT_GLYPH = "❯";
|
|
7423
|
+
/** The gutter beside every row of the section the reader holds: the conversation walk's own mark. */
|
|
7424
|
+
const HELD_GUTTER = "┃ ";
|
|
7425
|
+
/** The gutter beside every other row of the panel. */
|
|
7426
|
+
const GUTTER = " ";
|
|
7427
|
+
/** Columns a section's rows are indented by under its header. */
|
|
7428
|
+
const BODY_INDENT = " ";
|
|
7429
|
+
/** Columns a tool result's header is indented by, so it reads as the answer to the call above it. */
|
|
7430
|
+
const RESULT_INDENT = " ";
|
|
7431
|
+
/** What a Markdown bullet of a reply is drawn as. */
|
|
7432
|
+
const BULLET = "• ";
|
|
7433
|
+
/** A Markdown bullet at the start of a reply row: its indentation, then the marker and one space. */
|
|
7434
|
+
const MARKDOWN_BULLET = /^(\s*)[-*+] /;
|
|
7435
|
+
/** What opens a source row a diff adds. */
|
|
7436
|
+
const ADDED_PREFIX = "+ ";
|
|
7437
|
+
/** What opens a source row a diff removes. */
|
|
7438
|
+
const REMOVED_PREFIX = "- ";
|
|
7439
|
+
/** Share of the way from the terminal background toward the foreground the prompt band is mixed at. */
|
|
7440
|
+
const PROMPT_TINT = .12;
|
|
7441
|
+
/** Share of the way from the terminal background toward green or red a diff band is mixed at. */
|
|
7442
|
+
const DIFF_TINT = .22;
|
|
7443
|
+
/** The color the added band is mixed toward: the palette's own `success` green. */
|
|
7444
|
+
const ADDED_RGB = {
|
|
7445
|
+
r: 0,
|
|
7446
|
+
g: 205,
|
|
7447
|
+
b: 0
|
|
7448
|
+
};
|
|
7449
|
+
/** The color the removed band is mixed toward: the palette's own `error` red. */
|
|
7450
|
+
const REMOVED_RGB = {
|
|
7451
|
+
r: 205,
|
|
7452
|
+
g: 0,
|
|
7453
|
+
b: 0
|
|
7454
|
+
};
|
|
7455
|
+
/** Control Sequence Introducer. */
|
|
7456
|
+
const CSI$1 = "\x1B[";
|
|
7457
|
+
/** Ends a background a band set, and nothing else. */
|
|
7458
|
+
const RESET_BACKGROUND = `${CSI$1}49m`;
|
|
7127
7459
|
/** What the reader says on a terminal it cannot draw its frame in. */
|
|
7128
7460
|
const TOO_SMALL = `terminal too small for the reader (needs ${String(24)}×${String(8)})`;
|
|
7129
7461
|
/**
|
|
@@ -7135,11 +7467,13 @@ const TOO_SMALL = `terminal too small for the reader (needs ${String(24)}×${Str
|
|
|
7135
7467
|
*/
|
|
7136
7468
|
const READER_HINTS = {
|
|
7137
7469
|
list: [
|
|
7470
|
+
"↑↓ jk sections · PgUp PgDn [ ] turns · → opens · / filters · Esc q closes",
|
|
7138
7471
|
"↑↓ sections · PgUp PgDn turns · → opens · / filters · Esc closes",
|
|
7139
7472
|
"↑↓ sections · → opens · Esc closes",
|
|
7140
7473
|
"Esc closes"
|
|
7141
7474
|
],
|
|
7142
7475
|
pane: [
|
|
7476
|
+
"↑↓ jk scrolls · PgUp PgDn Space b pages · [ ] turns · ← list · Esc q closes",
|
|
7143
7477
|
"↑↓ scrolls · PgUp PgDn pages · ← turns · Esc closes",
|
|
7144
7478
|
"↑↓ scrolls · ← turns · Esc closes",
|
|
7145
7479
|
"Esc closes"
|
|
@@ -7151,6 +7485,36 @@ const EMPTY_MEASURE = {
|
|
|
7151
7485
|
total: 0
|
|
7152
7486
|
};
|
|
7153
7487
|
/**
|
|
7488
|
+
* Encode one band color as a background under the capability that reads it.
|
|
7489
|
+
* @param capability - `truecolor` writes the color itself, `ansi256` the nearest index.
|
|
7490
|
+
* @param color - the band color.
|
|
7491
|
+
* @returns the style that lays the band under a text.
|
|
7492
|
+
*/
|
|
7493
|
+
function band(capability, color) {
|
|
7494
|
+
const open = capability === "truecolor" ? `${CSI$1}48;2;${String(color.r)};${String(color.g)};${String(color.b)}m` : `${CSI$1}48;5;${String(nearestAnsi256(color))}m`;
|
|
7495
|
+
return (text) => `${open}${text}${RESET_BACKGROUND}`;
|
|
7496
|
+
}
|
|
7497
|
+
/**
|
|
7498
|
+
* The bands the turn panel lays under the prompt and the diff rows, mixed from
|
|
7499
|
+
* the terminal's own background so they stay a shade off it on any theme.
|
|
7500
|
+
* @param style - the fade drawing settings, whose capability says how far the
|
|
7501
|
+
* terminal encodes a color and whose ramp ends on the assumed foreground.
|
|
7502
|
+
* @param background - the terminal background, as the terminal reported it.
|
|
7503
|
+
* @returns the bands, or undefined on a terminal that encodes no color, that
|
|
7504
|
+
* reported no background, or that has no ramp to read the foreground from.
|
|
7505
|
+
*/
|
|
7506
|
+
function readerTints(style, background) {
|
|
7507
|
+
const capability = style.capability;
|
|
7508
|
+
const foreground = style.ramp.at(-1);
|
|
7509
|
+
if (capability !== "truecolor" && capability !== "ansi256") return void 0;
|
|
7510
|
+
if (background === void 0 || foreground === void 0) return void 0;
|
|
7511
|
+
return {
|
|
7512
|
+
prompt: band(capability, mixFadeColor(background, foreground, PROMPT_TINT)),
|
|
7513
|
+
added: band(capability, mixFadeColor(background, ADDED_RGB, DIFF_TINT)),
|
|
7514
|
+
removed: band(capability, mixFadeColor(background, REMOVED_RGB, DIFF_TINT))
|
|
7515
|
+
};
|
|
7516
|
+
}
|
|
7517
|
+
/**
|
|
7154
7518
|
* Hold one index inside a list.
|
|
7155
7519
|
* @param value - the wanted index.
|
|
7156
7520
|
* @param min - the lowest allowed value.
|
|
@@ -7166,7 +7530,7 @@ function clamp(value, min, max) {
|
|
|
7166
7530
|
* @param right - the other.
|
|
7167
7531
|
* @returns true when both name the same block and part.
|
|
7168
7532
|
*/
|
|
7169
|
-
function
|
|
7533
|
+
function sameSection(left, right) {
|
|
7170
7534
|
return left.block === right.block && left.part === right.part;
|
|
7171
7535
|
}
|
|
7172
7536
|
/**
|
|
@@ -7180,13 +7544,23 @@ function groupIndex(state, groups) {
|
|
|
7180
7544
|
return index === -1 ? 0 : index;
|
|
7181
7545
|
}
|
|
7182
7546
|
/**
|
|
7547
|
+
* The turn the panel shows.
|
|
7548
|
+
* @param state - where the reader is.
|
|
7549
|
+
* @param groups - the turns the list names.
|
|
7550
|
+
* @returns the turn holding the cursor, the first listed turn when none
|
|
7551
|
+
* holds it, and undefined for a list naming no turn.
|
|
7552
|
+
*/
|
|
7553
|
+
function readerTurn(state, groups) {
|
|
7554
|
+
return groups[groupIndex(state, groups)];
|
|
7555
|
+
}
|
|
7556
|
+
/**
|
|
7183
7557
|
* Which section of its turn the reader is reading.
|
|
7184
7558
|
* @param state - where the reader is.
|
|
7185
7559
|
* @param group - the turn that holds the cursor.
|
|
7186
7560
|
* @returns the index into the turn's sections, and 0 when the turn no longer carries it.
|
|
7187
7561
|
*/
|
|
7188
7562
|
function sectionIndex(state, group) {
|
|
7189
|
-
const index = group.sections.findIndex((section) =>
|
|
7563
|
+
const index = group.sections.findIndex((section) => sameSection(section, state.cursor));
|
|
7190
7564
|
return index === -1 ? 0 : index;
|
|
7191
7565
|
}
|
|
7192
7566
|
/**
|
|
@@ -7205,49 +7579,231 @@ function sectionAt(cursor, blocks) {
|
|
|
7205
7579
|
};
|
|
7206
7580
|
}
|
|
7207
7581
|
/**
|
|
7208
|
-
*
|
|
7209
|
-
* kind of
|
|
7582
|
+
* The glyph a section opens with, in the list and in its panel header: the
|
|
7583
|
+
* glyph the conversation draws that kind of block with, so a section reads the
|
|
7584
|
+
* same on both surfaces.
|
|
7585
|
+
* @param block - the block the section belongs to.
|
|
7586
|
+
* @param part - the section.
|
|
7587
|
+
* @returns the glyph.
|
|
7588
|
+
*/
|
|
7589
|
+
function sectionGlyph(block, part) {
|
|
7590
|
+
switch (block.blockKind) {
|
|
7591
|
+
case "user": return PROMPT_GLYPH;
|
|
7592
|
+
case "context": return "⬡";
|
|
7593
|
+
case "assistant": return part.kind === "reasoning" ? "✻" : "¶";
|
|
7594
|
+
case "tool": return part.kind === "result" ? "⎿" : "◆";
|
|
7595
|
+
/* v8 ignore next 2 -- closed-union exhaustiveness guard */
|
|
7596
|
+
default: return assertNever(block, "tui reader block kind");
|
|
7597
|
+
}
|
|
7598
|
+
}
|
|
7599
|
+
/**
|
|
7600
|
+
* Whether a tool's result has landed.
|
|
7601
|
+
* @param block - the tool's block.
|
|
7602
|
+
* @returns true once the block carries its result section.
|
|
7603
|
+
*/
|
|
7604
|
+
function settledTool(block) {
|
|
7605
|
+
return block.parts().some((candidate) => candidate.kind === "result");
|
|
7606
|
+
}
|
|
7607
|
+
/**
|
|
7608
|
+
* What a section is named after its glyph: `Prompt`, `Thinking`, and `Reply`
|
|
7609
|
+
* for a message, the tool and its headline for a call, `Result` for its
|
|
7610
|
+
* answer, and the injected context's own label. A tool whose result has not
|
|
7611
|
+
* landed says it is still running.
|
|
7210
7612
|
* @param block - the block the section belongs to.
|
|
7211
7613
|
* @param part - the section.
|
|
7212
|
-
* @returns the
|
|
7614
|
+
* @returns the name, unstyled.
|
|
7213
7615
|
*/
|
|
7214
|
-
function
|
|
7215
|
-
const label = sectionLabel(block, part);
|
|
7616
|
+
function sectionName(block, part) {
|
|
7216
7617
|
switch (block.blockKind) {
|
|
7217
|
-
case "
|
|
7218
|
-
case "
|
|
7219
|
-
case "
|
|
7220
|
-
case "
|
|
7618
|
+
case "user": return "Prompt";
|
|
7619
|
+
case "context": return sectionLabel(block, part);
|
|
7620
|
+
case "assistant": return part.kind === "reasoning" ? "Thinking" : "Reply";
|
|
7621
|
+
case "tool": {
|
|
7622
|
+
if (part.kind === "result") return "Result";
|
|
7623
|
+
const card = block.title === "" ? block.name : `${block.name} ${block.title}`;
|
|
7624
|
+
return settledTool(block) ? card : `${card} · running`;
|
|
7625
|
+
}
|
|
7221
7626
|
/* v8 ignore next 2 -- closed-union exhaustiveness guard */
|
|
7222
7627
|
default: return assertNever(block, "tui reader block kind");
|
|
7223
7628
|
}
|
|
7224
7629
|
}
|
|
7225
7630
|
/**
|
|
7226
|
-
* One section's
|
|
7227
|
-
*
|
|
7631
|
+
* One section's header as it is drawn at rest, styled the way the
|
|
7632
|
+
* conversation draws that kind of block: a call's `◆` in its status color
|
|
7633
|
+
* with the tool name in bold and its headline in the link blue, and a
|
|
7634
|
+
* reasoning, a result, and an injected context recessed.
|
|
7635
|
+
* @param block - the block the section belongs to.
|
|
7636
|
+
* @param part - the section.
|
|
7637
|
+
* @param palette - the palette the header is styled with.
|
|
7638
|
+
* @returns the styled glyph and name.
|
|
7639
|
+
*/
|
|
7640
|
+
function restingHeader(block, part, palette) {
|
|
7641
|
+
const glyph = sectionGlyph(block, part);
|
|
7642
|
+
const name = sectionName(block, part);
|
|
7643
|
+
if (block.blockKind === "tool" && part.kind === "call") return `${(settledTool(block) ? palette.success : palette.warning)(glyph)} ${palette.bold(block.name)}${palette.link(name.slice(block.name.length))}`;
|
|
7644
|
+
if (block.blockKind === "assistant" && part.kind === "reply") return `${palette.accent(glyph)} ${name}`;
|
|
7645
|
+
return palette.dim(`${glyph} ${name}`);
|
|
7646
|
+
}
|
|
7647
|
+
/**
|
|
7648
|
+
* The tone one source row draws in.
|
|
7649
|
+
* @param block - the block the section belongs to.
|
|
7650
|
+
* @param part - the section.
|
|
7651
|
+
* @param row - the source row.
|
|
7652
|
+
* @returns the tone: a tool's diff rows by their prefix, a reasoning or a
|
|
7653
|
+
* call recessed, and everything else plain.
|
|
7654
|
+
*/
|
|
7655
|
+
function rowTone(block, part, row) {
|
|
7656
|
+
if (block.blockKind === "tool") {
|
|
7657
|
+
if (row.startsWith(ADDED_PREFIX)) return "added";
|
|
7658
|
+
if (row.startsWith(REMOVED_PREFIX)) return "removed";
|
|
7659
|
+
}
|
|
7660
|
+
return part.kind === "reasoning" || part.kind === "call" ? "dim" : "plain";
|
|
7661
|
+
}
|
|
7662
|
+
/**
|
|
7663
|
+
* The source rows a section's body draws. A call whose first row repeats the
|
|
7664
|
+
* headline the header already names starts after it, and a reply's Markdown
|
|
7665
|
+
* bullets are drawn as `•`; every other row is the model-facing text as is.
|
|
7666
|
+
* @param block - the block the section belongs to.
|
|
7667
|
+
* @param part - the section.
|
|
7668
|
+
* @returns the rows, unwrapped.
|
|
7669
|
+
*/
|
|
7670
|
+
function bodySource(block, part) {
|
|
7671
|
+
if (block.blockKind === "tool" && part.kind === "call" && block.title !== "" && part.rows[0] === block.title) return part.rows.slice(1);
|
|
7672
|
+
if (part.kind === "reply") return part.rows.map((row) => row.replace(MARKDOWN_BULLET, `$1${BULLET}`));
|
|
7673
|
+
return part.rows;
|
|
7674
|
+
}
|
|
7675
|
+
/**
|
|
7676
|
+
* Fit one styled text to an exact number of columns.
|
|
7677
|
+
* @param text - the text, already styled.
|
|
7678
|
+
* @param width - the columns the cell takes.
|
|
7679
|
+
* @returns the text cut and padded to exactly `width`.
|
|
7680
|
+
*/
|
|
7681
|
+
function cell(text, width) {
|
|
7682
|
+
const cut = truncateToWidth(text, Math.max(1, width), ELLIPSIS$1);
|
|
7683
|
+
return `${cut}${" ".repeat(Math.max(0, width - visibleWidth(cut)))}`;
|
|
7684
|
+
}
|
|
7685
|
+
/**
|
|
7686
|
+
* The prompt that opens a turn: every wrapped row on one band across the
|
|
7687
|
+
* panel, the first led by `❯`, as the conversation draws a prompt.
|
|
7688
|
+
* @param rows - the prompt's source rows.
|
|
7689
|
+
* @param width - the columns right of the gutter.
|
|
7690
|
+
* @param look - the palette, the bands, and whether the reader holds the prompt.
|
|
7691
|
+
* @returns the rows, each exactly `width` columns.
|
|
7692
|
+
*/
|
|
7693
|
+
function promptRows(rows, width, look) {
|
|
7694
|
+
const { palette, tints, held } = look;
|
|
7695
|
+
const room = Math.max(1, width - visibleWidth(BODY_INDENT));
|
|
7696
|
+
const glyph = held ? palette.bold(palette.accent(PROMPT_GLYPH)) : palette.accent(PROMPT_GLYPH);
|
|
7697
|
+
return rows.flatMap((row) => wrapTextWithAnsi(row, room)).map((line, index) => {
|
|
7698
|
+
const text = cell(`${index === 0 ? `${glyph} ` : BODY_INDENT}${palette.bold(line)}`, width);
|
|
7699
|
+
return tints === void 0 ? text : tints.prompt(text);
|
|
7700
|
+
});
|
|
7701
|
+
}
|
|
7702
|
+
/**
|
|
7703
|
+
* One section's header row: its glyph and name, accented end to end while the
|
|
7704
|
+
* reader holds the section.
|
|
7705
|
+
* @param block - the block the section belongs to.
|
|
7706
|
+
* @param part - the section.
|
|
7707
|
+
* @param width - the columns right of the gutter.
|
|
7708
|
+
* @param look - the palette and whether the reader holds the section.
|
|
7709
|
+
* @returns the header, no wider than `width`.
|
|
7710
|
+
*/
|
|
7711
|
+
function headerRow(block, part, width, look) {
|
|
7712
|
+
const { palette, held } = look;
|
|
7713
|
+
return truncateToWidth(`${part.kind === "result" ? RESULT_INDENT : ""}${held ? palette.bold(palette.accent(`${sectionGlyph(block, part)} ${sectionName(block, part)}`)) : restingHeader(block, part, palette)}`, Math.max(1, width), ELLIPSIS$1);
|
|
7714
|
+
}
|
|
7715
|
+
/**
|
|
7716
|
+
* One wrapped body row, painted in its tone.
|
|
7717
|
+
* @param line - the wrapped text.
|
|
7718
|
+
* @param tone - how the source row it came from is tinted.
|
|
7719
|
+
* @param indent - the columns before it.
|
|
7720
|
+
* @param width - the columns right of the gutter.
|
|
7721
|
+
* @param look - the palette and the bands.
|
|
7722
|
+
* @returns the row; a diff row on a band fills the panel to its last column.
|
|
7723
|
+
*/
|
|
7724
|
+
function bodyRow(line, tone, indent, width, look) {
|
|
7725
|
+
const { palette, tints } = look;
|
|
7726
|
+
switch (tone) {
|
|
7727
|
+
case "plain": return `${indent}${line}`;
|
|
7728
|
+
case "dim": return `${indent}${palette.dim(line)}`;
|
|
7729
|
+
case "added":
|
|
7730
|
+
case "removed": {
|
|
7731
|
+
const paint = tone === "added" ? palette.success : palette.error;
|
|
7732
|
+
const tint = tints === void 0 ? void 0 : tone === "added" ? tints.added : tints.removed;
|
|
7733
|
+
if (tint === void 0) return `${indent}${paint(line)}`;
|
|
7734
|
+
return `${indent}${tint(cell(paint(line), Math.max(1, width - visibleWidth(indent))))}`;
|
|
7735
|
+
}
|
|
7736
|
+
/* v8 ignore next 2 -- closed-union exhaustiveness guard */
|
|
7737
|
+
default: return assertNever(tone, "tui reader row tone");
|
|
7738
|
+
}
|
|
7739
|
+
}
|
|
7740
|
+
/**
|
|
7741
|
+
* One section's rows as the panel draws them: the prompt band, or a header
|
|
7742
|
+
* and the section's rows wrapped under it, every row behind the gutter that
|
|
7743
|
+
* carries the conversation walk's `┃` while the reader holds the section.
|
|
7744
|
+
* Never folded, because folding is a decision the transcript makes and this
|
|
7745
|
+
* is where the rest of the text is. How many rows come back depends on the
|
|
7746
|
+
* text and the width alone, never on the palette, the bands, or whether the
|
|
7747
|
+
* section is held.
|
|
7228
7748
|
* @param cursor - the section.
|
|
7229
7749
|
* @param blocks - the navigable blocks.
|
|
7230
|
-
* @param width - the panel's columns.
|
|
7231
|
-
* @
|
|
7750
|
+
* @param width - the panel's columns, the gutter included.
|
|
7751
|
+
* @param look - the palette, the bands, and whether the reader holds the section.
|
|
7752
|
+
* @returns the rows, or none for a section the transcript no longer carries.
|
|
7232
7753
|
*/
|
|
7233
|
-
function
|
|
7234
|
-
const
|
|
7235
|
-
if (
|
|
7236
|
-
|
|
7754
|
+
function sectionRows(cursor, blocks, width, look) {
|
|
7755
|
+
const found = sectionAt(cursor, blocks);
|
|
7756
|
+
if (found === void 0) return [];
|
|
7757
|
+
const { block, part } = found;
|
|
7758
|
+
const content = Math.max(1, width - visibleWidth(GUTTER));
|
|
7759
|
+
let rows;
|
|
7760
|
+
if (block.blockKind === "user") rows = promptRows(part.rows, content, look);
|
|
7761
|
+
else {
|
|
7762
|
+
const indent = part.kind === "result" ? `${RESULT_INDENT}${BODY_INDENT}` : BODY_INDENT;
|
|
7763
|
+
const room = Math.max(1, content - visibleWidth(indent));
|
|
7764
|
+
rows = [headerRow(block, part, content, look), ...bodySource(block, part).flatMap((row) => {
|
|
7765
|
+
const tone = rowTone(block, part, row);
|
|
7766
|
+
return wrapTextWithAnsi(row, room).map((line) => bodyRow(line, tone, indent, content, look));
|
|
7767
|
+
})];
|
|
7768
|
+
}
|
|
7769
|
+
const gutter = look.held ? look.palette.accent(HELD_GUTTER) : GUTTER;
|
|
7770
|
+
return rows.map((row) => `${gutter}${row}`);
|
|
7771
|
+
}
|
|
7772
|
+
/**
|
|
7773
|
+
* Lay out every section of one turn, a blank row between each two.
|
|
7774
|
+
* @param group - the turn the panel shows.
|
|
7775
|
+
* @param blocks - the navigable blocks.
|
|
7776
|
+
* @param width - the panel's columns.
|
|
7777
|
+
* @param look - the palette and bands, and which section the reader holds.
|
|
7778
|
+
* @returns each section's rows, the blank row after it included, in reading order.
|
|
7779
|
+
*/
|
|
7780
|
+
function turnLayout(group, blocks, width, look) {
|
|
7781
|
+
const last = group.sections.length - 1;
|
|
7782
|
+
return group.sections.map((section, index) => {
|
|
7783
|
+
const held = look.cursor !== void 0 && sameSection(section, look.cursor);
|
|
7784
|
+
const rows = sectionRows(section, blocks, width, {
|
|
7785
|
+
palette: look.palette,
|
|
7786
|
+
tints: look.tints,
|
|
7787
|
+
held
|
|
7788
|
+
});
|
|
7789
|
+
return index === last || rows.length === 0 ? rows : [...rows, ""];
|
|
7790
|
+
});
|
|
7237
7791
|
}
|
|
7792
|
+
/** An unstyled palette, which is all measuring needs: styling never changes a row count. */
|
|
7793
|
+
const MEASURING = createPalette(false);
|
|
7238
7794
|
/**
|
|
7239
7795
|
* Measure the turn panel, which is what the scroll keys move over.
|
|
7240
7796
|
* @param group - the turn the panel shows.
|
|
7241
7797
|
* @param blocks - the navigable blocks.
|
|
7242
7798
|
* @param width - the panel's columns.
|
|
7243
|
-
* @returns where each section's
|
|
7799
|
+
* @returns where each section's first row lands and how many rows the panel has.
|
|
7244
7800
|
*/
|
|
7245
7801
|
function measurePane(group, blocks, width) {
|
|
7246
7802
|
const headers = [];
|
|
7247
7803
|
let total = 0;
|
|
7248
|
-
for (const
|
|
7804
|
+
for (const rows of turnLayout(group, blocks, width, { palette: MEASURING })) {
|
|
7249
7805
|
headers.push(total);
|
|
7250
|
-
total +=
|
|
7806
|
+
total += rows.length;
|
|
7251
7807
|
}
|
|
7252
7808
|
return {
|
|
7253
7809
|
headers,
|
|
@@ -7305,7 +7861,7 @@ function readerGeometry(width, rows, state, minColumns) {
|
|
|
7305
7861
|
*/
|
|
7306
7862
|
function readerGeometryFor(state, groups, blocks, width, rows, minColumns) {
|
|
7307
7863
|
const layout = readerGeometry(width, rows, state, minColumns);
|
|
7308
|
-
const group =
|
|
7864
|
+
const group = readerTurn(state, groups);
|
|
7309
7865
|
if (group === void 0 || layout.pane === 0) return layout;
|
|
7310
7866
|
return {
|
|
7311
7867
|
...layout,
|
|
@@ -7333,7 +7889,7 @@ function readerOutline(state, groups) {
|
|
|
7333
7889
|
return [turn, ...group.sections.map((cursor) => ({
|
|
7334
7890
|
kind: "section",
|
|
7335
7891
|
cursor,
|
|
7336
|
-
held:
|
|
7892
|
+
held: sameSection(cursor, state.cursor)
|
|
7337
7893
|
}))];
|
|
7338
7894
|
});
|
|
7339
7895
|
}
|
|
@@ -7355,7 +7911,7 @@ function maxOffset(geometry) {
|
|
|
7355
7911
|
return Math.max(0, geometry.measure.total - geometry.body);
|
|
7356
7912
|
}
|
|
7357
7913
|
/**
|
|
7358
|
-
* Where the panel scrolls to put one section's
|
|
7914
|
+
* Where the panel scrolls to put one section's first row on its first row.
|
|
7359
7915
|
* @param index - the section, by position in its turn.
|
|
7360
7916
|
* @param geometry - the reader's geometry.
|
|
7361
7917
|
* @returns the offset.
|
|
@@ -7395,7 +7951,7 @@ function measureOf(group, held, geometry, blocks) {
|
|
|
7395
7951
|
return geometry.pane === 0 ? EMPTY_MEASURE : measurePane(group, blocks, geometry.pane);
|
|
7396
7952
|
}
|
|
7397
7953
|
/**
|
|
7398
|
-
* Put the reader on one section, with the panel scrolled to its
|
|
7954
|
+
* Put the reader on one section, with the panel scrolled to its first row.
|
|
7399
7955
|
* @param state - where the reader is.
|
|
7400
7956
|
* @param cursor - the section to read.
|
|
7401
7957
|
* @param groups - the turns the list names.
|
|
@@ -7404,12 +7960,12 @@ function measureOf(group, held, geometry, blocks) {
|
|
|
7404
7960
|
* @returns the state on that section.
|
|
7405
7961
|
*/
|
|
7406
7962
|
function readSection(state, cursor, groups, geometry, blocks) {
|
|
7407
|
-
const held =
|
|
7963
|
+
const held = readerTurn(state, groups);
|
|
7408
7964
|
const next = groups[turnIndexOf(cursor, groups)];
|
|
7409
7965
|
/* v8 ignore next -- every cursor the list steps to comes from a listed turn */
|
|
7410
7966
|
if (next === void 0) return state;
|
|
7411
7967
|
const measure = measureOf(next, held, geometry, blocks);
|
|
7412
|
-
const index = next.sections.findIndex((section) =>
|
|
7968
|
+
const index = next.sections.findIndex((section) => sameSection(section, cursor));
|
|
7413
7969
|
/* v8 ignore next -- the cursor came from this turn's own sections, so the measure has its row */
|
|
7414
7970
|
const header = measure.headers[index] ?? 0;
|
|
7415
7971
|
return {
|
|
@@ -7440,7 +7996,7 @@ function withoutQuery(state) {
|
|
|
7440
7996
|
* @returns the state at that row.
|
|
7441
7997
|
*/
|
|
7442
7998
|
function readAt(state, offset, groups, geometry) {
|
|
7443
|
-
const group =
|
|
7999
|
+
const group = readerTurn(state, groups);
|
|
7444
8000
|
const index = geometry.measure.headers.findLastIndex((header) => header <= offset);
|
|
7445
8001
|
const cursor = group?.sections[index];
|
|
7446
8002
|
return cursor === void 0 ? {
|
|
@@ -7510,7 +8066,7 @@ function reduceReader(state, intent, groups, geometry, blocks) {
|
|
|
7510
8066
|
switch (intent.kind) {
|
|
7511
8067
|
case "section": {
|
|
7512
8068
|
const sections = allSections(groups);
|
|
7513
|
-
const at = sections.findIndex((section) =>
|
|
8069
|
+
const at = sections.findIndex((section) => sameSection(section, state.cursor));
|
|
7514
8070
|
const cursor = sections[targetIndex(intent.to, Math.max(0, at), sections.length)];
|
|
7515
8071
|
return cursor === void 0 ? state : readSection(state, cursor, groups, geometry, blocks);
|
|
7516
8072
|
}
|
|
@@ -7554,7 +8110,7 @@ function reduceReader(state, intent, groups, geometry, blocks) {
|
|
|
7554
8110
|
* @returns the state with its offset settled.
|
|
7555
8111
|
*/
|
|
7556
8112
|
function anchorOffset(state, groups, geometry) {
|
|
7557
|
-
const group =
|
|
8113
|
+
const group = readerTurn(state, groups);
|
|
7558
8114
|
if (group === void 0) return state;
|
|
7559
8115
|
return {
|
|
7560
8116
|
...state,
|
|
@@ -7585,108 +8141,83 @@ function markerStrip(markers) {
|
|
|
7585
8141
|
if (markers.context > 0) marks.push(`⬡${String(markers.context)}`);
|
|
7586
8142
|
if (markers.reasoning) marks.push("✻");
|
|
7587
8143
|
if (markers.reply) marks.push("¶");
|
|
7588
|
-
if (markers.tools > 0) marks.push(
|
|
8144
|
+
if (markers.tools > 0) marks.push(`◆${String(markers.tools)}`);
|
|
7589
8145
|
return marks.join("");
|
|
7590
8146
|
}
|
|
7591
8147
|
/**
|
|
7592
|
-
*
|
|
7593
|
-
* @param text - the text
|
|
7594
|
-
* @param
|
|
7595
|
-
* @
|
|
8148
|
+
* Paint one list row by whether it is the selection.
|
|
8149
|
+
* @param text - the row's text.
|
|
8150
|
+
* @param selected - whether it is the open turn or the held section.
|
|
8151
|
+
* @param look - the list's focus and palette.
|
|
8152
|
+
* @returns the row accented for the selection, bold only while the list has
|
|
8153
|
+
* the keyboard, and recessed otherwise.
|
|
7596
8154
|
*/
|
|
7597
|
-
function
|
|
7598
|
-
const
|
|
7599
|
-
|
|
8155
|
+
function listPaint(text, selected, look) {
|
|
8156
|
+
const { palette, focused } = look;
|
|
8157
|
+
if (!selected) return palette.dim(text);
|
|
8158
|
+
return focused ? palette.bold(palette.accent(text)) : palette.accent(text);
|
|
7600
8159
|
}
|
|
7601
8160
|
/**
|
|
7602
|
-
* One row of the
|
|
7603
|
-
* the turn contributed.
|
|
8161
|
+
* One turn row of the list: `❯` on the turn being read, the turn number, its
|
|
8162
|
+
* prompt, and right-aligned what the turn contributed.
|
|
7604
8163
|
* @param group - the turn.
|
|
7605
8164
|
* @param open - whether this is the turn being read, whose sections follow it.
|
|
7606
|
-
* @param
|
|
7607
|
-
* @
|
|
7608
|
-
* @param width - the list's columns.
|
|
7609
|
-
* @returns the row, exactly `width` columns.
|
|
8165
|
+
* @param look - the list's focus, palette, width, and number column.
|
|
8166
|
+
* @returns the row, exactly `look.width` columns.
|
|
7610
8167
|
*/
|
|
7611
|
-
function
|
|
8168
|
+
function turnRow(group, open, look) {
|
|
7612
8169
|
const marks = markerStrip(group.markers);
|
|
7613
|
-
const room = Math.max(1, width - visibleWidth(marks));
|
|
7614
|
-
const
|
|
7615
|
-
|
|
7616
|
-
const head = `${lead}${open ? `[${label}]` : label}`;
|
|
7617
|
-
const paint = (text) => {
|
|
7618
|
-
if (!open) return palette.dim(text);
|
|
7619
|
-
return focused ? palette.bold(palette.accent(text)) : palette.accent(text);
|
|
7620
|
-
};
|
|
7621
|
-
const text = truncateToWidth(paint(head), room, ELLIPSIS$1);
|
|
7622
|
-
return `${text}${" ".repeat(Math.max(0, room - visibleWidth(text)))}${palette.dim(marks)}`;
|
|
8170
|
+
const room = Math.max(1, look.width - visibleWidth(marks) - (marks === "" ? 0 : 1));
|
|
8171
|
+
const text = truncateToWidth(listPaint(`${`${open ? PROMPT_GLYPH : " "} ${String(group.turn).padStart(look.digits)} `}${group.label}`, open, look), room, ELLIPSIS$1);
|
|
8172
|
+
return cell(`${text}${" ".repeat(Math.max(0, look.width - visibleWidth(text) - visibleWidth(marks)))}${look.palette.dim(marks)}`, look.width);
|
|
7623
8173
|
}
|
|
7624
|
-
/** Columns a section row is indented by, so the turn it belongs to reads as its heading. */
|
|
7625
|
-
const SECTION_INDENT = " ";
|
|
7626
8174
|
/**
|
|
7627
|
-
* One section row of the
|
|
7628
|
-
*
|
|
8175
|
+
* One section row of the list: `▸` on the section the reader holds, then the
|
|
8176
|
+
* glyph and the name its header in the panel carries.
|
|
7629
8177
|
* @param cursor - the section.
|
|
7630
8178
|
* @param blocks - the navigable blocks.
|
|
7631
|
-
* @param
|
|
7632
|
-
* @param
|
|
7633
|
-
* @
|
|
7634
|
-
* @param width - the list's columns.
|
|
7635
|
-
* @returns the row, exactly `width` columns.
|
|
8179
|
+
* @param held - whether the cursor holds it.
|
|
8180
|
+
* @param look - the list's focus, palette, and width.
|
|
8181
|
+
* @returns the row, exactly `look.width` columns.
|
|
7636
8182
|
*/
|
|
7637
|
-
function
|
|
8183
|
+
function outlineSectionRow(cursor, blocks, held, look) {
|
|
7638
8184
|
const found = sectionAt(cursor, blocks);
|
|
7639
|
-
const label = found === void 0 ? "" :
|
|
7640
|
-
|
|
7641
|
-
const paint = (text) => {
|
|
7642
|
-
if (!selected) return palette.dim(text);
|
|
7643
|
-
return focused ? palette.bold(palette.accent(text)) : palette.accent(text);
|
|
7644
|
-
};
|
|
7645
|
-
return cell(paint(head), width);
|
|
8185
|
+
const label = found === void 0 ? "" : `${sectionGlyph(found.block, found.part)} ${sectionName(found.block, found.part)}`;
|
|
8186
|
+
return cell(listPaint(` ${held ? LIST_MARK : " "} ${label}`, held, look), look.width);
|
|
7646
8187
|
}
|
|
7647
8188
|
/**
|
|
7648
8189
|
* The turn list's rows, windowed so the row the cursor holds is always drawn.
|
|
7649
8190
|
* @param rows - the outline the list draws.
|
|
7650
8191
|
* @param blocks - the navigable blocks, for each section's own label.
|
|
7651
|
-
* @param
|
|
7652
|
-
* @param palette - the palette the rows are styled with.
|
|
7653
|
-
* @param width - the list's columns.
|
|
8192
|
+
* @param look - the list's focus, palette, width, and number column.
|
|
7654
8193
|
* @param body - the rows the body has.
|
|
7655
8194
|
* @returns the rows to draw, oldest first.
|
|
7656
8195
|
*/
|
|
7657
|
-
function listColumn(rows, blocks,
|
|
8196
|
+
function listColumn(rows, blocks, look, body) {
|
|
7658
8197
|
const cursor = rows.findIndex((row) => row.kind === "section" && row.held);
|
|
7659
8198
|
const start = clamp(Math.max(0, cursor) - Math.floor(Math.max(0, body - 1) / 2), 0, Math.max(0, rows.length - body));
|
|
7660
|
-
return rows.slice(start, start + body).map((row) => row.kind === "turn" ?
|
|
7661
|
-
}
|
|
7662
|
-
/**
|
|
7663
|
-
* One section header inside the turn panel.
|
|
7664
|
-
* @param text - what the section is called, with its turn.
|
|
7665
|
-
* @param palette - the palette the header is styled with.
|
|
7666
|
-
* @param width - the panel's columns.
|
|
7667
|
-
* @param reading - whether this is the section the top row belongs to.
|
|
7668
|
-
* @returns the header row.
|
|
7669
|
-
*/
|
|
7670
|
-
function headerRow(text, palette, width, reading) {
|
|
7671
|
-
const body = ` ${text} `;
|
|
7672
|
-
const line = `${HEADER_LEAD}${body}${HEADER_FILL.repeat(Math.max(0, width - visibleWidth(HEADER_LEAD) - visibleWidth(body)))}`;
|
|
7673
|
-
return reading ? palette.bold(palette.accent(line)) : palette.dim(line);
|
|
8199
|
+
return rows.slice(start, start + body).map((row) => row.kind === "turn" ? turnRow(row.group, row.open, look) : outlineSectionRow(row.cursor, blocks, row.held, look));
|
|
7674
8200
|
}
|
|
7675
8201
|
/**
|
|
7676
8202
|
* The turn panel's rows: every section of the held turn, in reading order,
|
|
7677
|
-
*
|
|
8203
|
+
* the prompt on its band and every other section under its own header, with a
|
|
8204
|
+
* reveal in flight floating out the rows it covers.
|
|
7678
8205
|
* @param group - the turn the panel shows.
|
|
7679
8206
|
* @param blocks - the navigable blocks.
|
|
7680
|
-
* @param cursor - the section the
|
|
7681
|
-
* @param
|
|
8207
|
+
* @param cursor - the section the reader holds.
|
|
8208
|
+
* @param render - the palette, the bands, and the reveal.
|
|
7682
8209
|
* @param width - the panel's columns.
|
|
7683
8210
|
* @returns the rows, before the scroll window is applied.
|
|
7684
8211
|
*/
|
|
7685
|
-
function paneColumn(group, blocks, cursor,
|
|
7686
|
-
|
|
7687
|
-
|
|
7688
|
-
|
|
7689
|
-
|
|
8212
|
+
function paneColumn(group, blocks, cursor, render, width) {
|
|
8213
|
+
const { palette, tints, reveal } = render;
|
|
8214
|
+
return turnLayout(group, blocks, width, {
|
|
8215
|
+
palette,
|
|
8216
|
+
tints,
|
|
8217
|
+
cursor
|
|
8218
|
+
}).flatMap((rows, index) => {
|
|
8219
|
+
const section = group.sections[index];
|
|
8220
|
+
return reveal !== void 0 && (reveal.section === void 0 || section !== void 0 && sameSection(section, reveal.section)) ? recolorLines(rows, reveal.age, reveal.style) : rows;
|
|
7690
8221
|
});
|
|
7691
8222
|
}
|
|
7692
8223
|
/**
|
|
@@ -7697,12 +8228,11 @@ function paneColumn(group, blocks, cursor, palette, width) {
|
|
|
7697
8228
|
* @param width - the frame's columns.
|
|
7698
8229
|
* @returns the row, no wider than `width`.
|
|
7699
8230
|
*/
|
|
7700
|
-
function
|
|
7701
|
-
|
|
7702
|
-
let line = `${border} `;
|
|
8231
|
+
function frameRow(columns, row, palette, width) {
|
|
8232
|
+
let line = `${palette.accent(SIDE)} `;
|
|
7703
8233
|
for (const [index, column] of columns.entries()) {
|
|
7704
8234
|
const text = column.rows[row] ?? "";
|
|
7705
|
-
line += index === columns.length - 1 ? truncateToWidth(text, Math.max(1, column.width), ELLIPSIS$1) : `${cell(text, column.width)}${
|
|
8235
|
+
line += index === columns.length - 1 ? truncateToWidth(text, Math.max(1, column.width), ELLIPSIS$1) : `${cell(text, column.width)}${palette.dim(SIDE)} `;
|
|
7706
8236
|
}
|
|
7707
8237
|
return truncateToWidth(line, Math.max(1, width), ELLIPSIS$1);
|
|
7708
8238
|
}
|
|
@@ -7750,7 +8280,8 @@ function readout(state, groups, geometry, totalTurns) {
|
|
|
7750
8280
|
* Draw the reader.
|
|
7751
8281
|
* @param state - where the reader is.
|
|
7752
8282
|
* @param groups - the turns the list names, already narrowed by the query.
|
|
7753
|
-
* @param render - the palette, the blocks, the geometry inputs,
|
|
8283
|
+
* @param render - the palette, the blocks, the geometry inputs, the turn
|
|
8284
|
+
* total, and the bands and reveal the turn panel is drawn with.
|
|
7754
8285
|
* @returns exactly `render.rows` lines, none wider than `render.width`.
|
|
7755
8286
|
*/
|
|
7756
8287
|
function readerRows(state, groups, render) {
|
|
@@ -7765,16 +8296,24 @@ function readerRows(state, groups, render) {
|
|
|
7765
8296
|
const selected = groupIndex(state, groups);
|
|
7766
8297
|
const group = groups[selected];
|
|
7767
8298
|
const columns = [];
|
|
7768
|
-
if (geometry.list > 0)
|
|
7769
|
-
|
|
7770
|
-
|
|
7771
|
-
|
|
8299
|
+
if (geometry.list > 0) {
|
|
8300
|
+
const look = {
|
|
8301
|
+
focused: state.column !== "pane",
|
|
8302
|
+
palette,
|
|
8303
|
+
width: geometry.list,
|
|
8304
|
+
digits: Math.max(1, ...groups.map((entry) => String(entry.turn).length))
|
|
8305
|
+
};
|
|
8306
|
+
columns.push({
|
|
8307
|
+
width: geometry.list,
|
|
8308
|
+
rows: groups.length === 0 ? [palette.dim(`no turn matches "${state.query ?? ""}"`)] : listColumn(readerOutline(state, groups), blocks, look, geometry.body)
|
|
8309
|
+
});
|
|
8310
|
+
}
|
|
7772
8311
|
if (geometry.pane > 0) columns.push({
|
|
7773
8312
|
width: geometry.pane,
|
|
7774
|
-
rows: group === void 0 ? [] : paneColumn(group, blocks, state.cursor,
|
|
8313
|
+
rows: group === void 0 ? [] : paneColumn(group, blocks, state.cursor, render, geometry.pane).slice(state.offset)
|
|
7775
8314
|
});
|
|
7776
8315
|
const body = [];
|
|
7777
|
-
for (let row = 0; row < geometry.body; row += 1) body.push(
|
|
8316
|
+
for (let row = 0; row < geometry.body; row += 1) body.push(frameRow(columns, row, palette, width));
|
|
7778
8317
|
const report = readout(state, groups, geometry, totalTurns);
|
|
7779
8318
|
const legendRoom = ruleRoom(width) - visibleWidth(report) - 1;
|
|
7780
8319
|
return [
|
|
@@ -7818,10 +8357,76 @@ function readerRows(state, groups, render) {
|
|
|
7818
8357
|
* turns on every render, so a reply that is still streaming grows inside it,
|
|
7819
8358
|
* a tool result that lands appears, and a new turn joins the list, all with
|
|
7820
8359
|
* no push and no second clock.
|
|
8360
|
+
*
|
|
8361
|
+
* Opening the reader, showing another turn, and stepping the list to another
|
|
8362
|
+
* section of the same turn each start a reveal: the rows newly in view float
|
|
8363
|
+
* out from a lifted color to the colors they settle at, on a clock the
|
|
8364
|
+
* application runs on its fade tick. Scrolling, live growth, and a rewrap
|
|
8365
|
+
* reveal nothing. A reveal changes colors only, and a terminal that runs no
|
|
8366
|
+
* motion draws the settled reader from the first frame.
|
|
7821
8367
|
* @module @deepseek-ai/dsh-tui-app/reader-screen
|
|
7822
8368
|
*/
|
|
7823
8369
|
/** The key that opens the query line. */
|
|
7824
8370
|
const FILTER_KEY = "/";
|
|
8371
|
+
/** Printable keys either panel answers the way a pager does, beside the named keys. */
|
|
8372
|
+
const ALIASES$1 = [["[", {
|
|
8373
|
+
kind: "turn",
|
|
8374
|
+
step: -1
|
|
8375
|
+
}], ["]", {
|
|
8376
|
+
kind: "turn",
|
|
8377
|
+
step: 1
|
|
8378
|
+
}]];
|
|
8379
|
+
/** Printable keys the turn list answers beside the named keys. */
|
|
8380
|
+
const LIST_ALIASES = new Map([
|
|
8381
|
+
...ALIASES$1,
|
|
8382
|
+
["k", {
|
|
8383
|
+
kind: "section",
|
|
8384
|
+
to: "previous"
|
|
8385
|
+
}],
|
|
8386
|
+
["j", {
|
|
8387
|
+
kind: "section",
|
|
8388
|
+
to: "next"
|
|
8389
|
+
}],
|
|
8390
|
+
["g", {
|
|
8391
|
+
kind: "section",
|
|
8392
|
+
to: "first"
|
|
8393
|
+
}],
|
|
8394
|
+
["G", {
|
|
8395
|
+
kind: "section",
|
|
8396
|
+
to: "last"
|
|
8397
|
+
}],
|
|
8398
|
+
[FILTER_KEY, { kind: "filter" }]
|
|
8399
|
+
]);
|
|
8400
|
+
/** Printable keys the turn panel answers beside the named keys. */
|
|
8401
|
+
const PANE_ALIASES = new Map([
|
|
8402
|
+
...ALIASES$1,
|
|
8403
|
+
["k", {
|
|
8404
|
+
kind: "scroll",
|
|
8405
|
+
to: "previous"
|
|
8406
|
+
}],
|
|
8407
|
+
["j", {
|
|
8408
|
+
kind: "scroll",
|
|
8409
|
+
to: "next"
|
|
8410
|
+
}],
|
|
8411
|
+
["g", {
|
|
8412
|
+
kind: "scroll",
|
|
8413
|
+
to: "first"
|
|
8414
|
+
}],
|
|
8415
|
+
["G", {
|
|
8416
|
+
kind: "scroll",
|
|
8417
|
+
to: "last"
|
|
8418
|
+
}],
|
|
8419
|
+
[" ", {
|
|
8420
|
+
kind: "page",
|
|
8421
|
+
step: 1
|
|
8422
|
+
}],
|
|
8423
|
+
["b", {
|
|
8424
|
+
kind: "page",
|
|
8425
|
+
step: -1
|
|
8426
|
+
}]
|
|
8427
|
+
]);
|
|
8428
|
+
/** The printable key that closes the reader from either panel, as `Escape` does. */
|
|
8429
|
+
const QUIT_KEY = "q";
|
|
7825
8430
|
/**
|
|
7826
8431
|
* The reader pane: it renders exactly the rows it was given, maps every key
|
|
7827
8432
|
* to one {@link ReaderIntent}, and settles once when the reader closes.
|
|
@@ -7835,6 +8440,10 @@ var ReaderPane = class {
|
|
|
7835
8440
|
width = 0;
|
|
7836
8441
|
/** The body the last render anchored on, so one rewrap re-anchors exactly once. */
|
|
7837
8442
|
layout = "";
|
|
8443
|
+
/** The turn the last render showed, by index into every turn; -1 for none, undefined before the first render. */
|
|
8444
|
+
shownTurn;
|
|
8445
|
+
/** The reveal in flight, and the one section it covers when it covers no whole turn. */
|
|
8446
|
+
reveal;
|
|
7838
8447
|
/**
|
|
7839
8448
|
* @param options - the palette, the live transcript reads, and the section to open on.
|
|
7840
8449
|
*/
|
|
@@ -7874,13 +8483,22 @@ var ReaderPane = class {
|
|
|
7874
8483
|
this.layout = layout;
|
|
7875
8484
|
this.state = reduceReader(this.state, { kind: "anchor" }, visible, geometry, blocks);
|
|
7876
8485
|
}
|
|
8486
|
+
const held = readerTurn(this.state, visible);
|
|
8487
|
+
const turn = held === void 0 ? -1 : groups.indexOf(held);
|
|
8488
|
+
if (this.shownTurn !== turn) {
|
|
8489
|
+
this.shownTurn = turn;
|
|
8490
|
+
this.startReveal(void 0);
|
|
8491
|
+
}
|
|
8492
|
+
const effects = this.options.effects;
|
|
7877
8493
|
return readerRows(this.state, visible, {
|
|
7878
8494
|
palette: this.options.palette,
|
|
7879
8495
|
blocks,
|
|
7880
8496
|
width,
|
|
7881
8497
|
rows,
|
|
7882
8498
|
minColumns: this.options.minColumns,
|
|
7883
|
-
totalTurns: groups.length
|
|
8499
|
+
totalTurns: groups.length,
|
|
8500
|
+
tints: effects === void 0 ? void 0 : readerTints(effects.style(), effects.background()),
|
|
8501
|
+
reveal: this.revealNow()
|
|
7884
8502
|
});
|
|
7885
8503
|
}
|
|
7886
8504
|
/**
|
|
@@ -7899,19 +8517,56 @@ var ReaderPane = class {
|
|
|
7899
8517
|
if (matchesKey(data, "escape")) this.close("transcript");
|
|
7900
8518
|
return;
|
|
7901
8519
|
}
|
|
7902
|
-
if (matchesKey(data, "escape")
|
|
8520
|
+
if (readerClosesOnEscape(this.state) && (matchesKey(data, "escape") || typedText(data) === QUIT_KEY)) {
|
|
7903
8521
|
this.close("transcript");
|
|
7904
8522
|
return;
|
|
7905
8523
|
}
|
|
7906
8524
|
const intent = this.intentOf(data);
|
|
7907
8525
|
if (intent === void 0) return;
|
|
8526
|
+
const before = this.state.cursor;
|
|
7908
8527
|
this.state = reduceReader(this.state, intent, visible, geometry, blocks);
|
|
8528
|
+
if (intent.kind === "section" && !sameSection(before, this.state.cursor)) this.startReveal(this.state.cursor);
|
|
7909
8529
|
}
|
|
7910
8530
|
/** Close the reader from outside, which is what quitting and `Ctrl+C` do. */
|
|
7911
8531
|
withdraw() {
|
|
7912
8532
|
this.close("editor");
|
|
7913
8533
|
}
|
|
7914
8534
|
/**
|
|
8535
|
+
* Start a reveal, replacing the one in flight.
|
|
8536
|
+
* @param section - the one section it covers; undefined covers the whole turn.
|
|
8537
|
+
*/
|
|
8538
|
+
startReveal(section) {
|
|
8539
|
+
const clock = this.options.effects?.startReveal();
|
|
8540
|
+
if (clock === void 0) return;
|
|
8541
|
+
this.reveal = section === void 0 ? { clock } : {
|
|
8542
|
+
clock,
|
|
8543
|
+
section
|
|
8544
|
+
};
|
|
8545
|
+
}
|
|
8546
|
+
/**
|
|
8547
|
+
* The reveal as this render draws it.
|
|
8548
|
+
* @returns the age, the drawing settings, and the section it covers, or
|
|
8549
|
+
* undefined once it settled, which also forgets it.
|
|
8550
|
+
*/
|
|
8551
|
+
revealNow() {
|
|
8552
|
+
const reveal = this.reveal;
|
|
8553
|
+
const effects = this.options.effects;
|
|
8554
|
+
const age = reveal?.clock.age();
|
|
8555
|
+
if (reveal === void 0 || effects === void 0 || age === void 0) {
|
|
8556
|
+
this.reveal = void 0;
|
|
8557
|
+
return;
|
|
8558
|
+
}
|
|
8559
|
+
const style = effects.style();
|
|
8560
|
+
return reveal.section === void 0 ? {
|
|
8561
|
+
age,
|
|
8562
|
+
style
|
|
8563
|
+
} : {
|
|
8564
|
+
age,
|
|
8565
|
+
style,
|
|
8566
|
+
section: reveal.section
|
|
8567
|
+
};
|
|
8568
|
+
}
|
|
8569
|
+
/**
|
|
7915
8570
|
* The geometry of the frame as it stands.
|
|
7916
8571
|
* @param visible - the turns the rail lists.
|
|
7917
8572
|
* @param blocks - the navigable blocks.
|
|
@@ -8006,7 +8661,7 @@ function listIntent(data) {
|
|
|
8006
8661
|
kind: "column",
|
|
8007
8662
|
to: "pane"
|
|
8008
8663
|
};
|
|
8009
|
-
return
|
|
8664
|
+
return aliasOf(data, LIST_ALIASES);
|
|
8010
8665
|
}
|
|
8011
8666
|
/**
|
|
8012
8667
|
* What one key means while the turn panel owns the keyboard.
|
|
@@ -8042,6 +8697,17 @@ function paneIntent(data) {
|
|
|
8042
8697
|
kind: "column",
|
|
8043
8698
|
to: "list"
|
|
8044
8699
|
};
|
|
8700
|
+
return aliasOf(data, PANE_ALIASES);
|
|
8701
|
+
}
|
|
8702
|
+
/**
|
|
8703
|
+
* What one printable key means in a panel's alias table.
|
|
8704
|
+
* @param data - the raw key bytes.
|
|
8705
|
+
* @param aliases - the panel's printable keys.
|
|
8706
|
+
* @returns the intent, or undefined for a key the table names nothing for.
|
|
8707
|
+
*/
|
|
8708
|
+
function aliasOf(data, aliases) {
|
|
8709
|
+
const text = typedText(data);
|
|
8710
|
+
return text === void 0 ? void 0 : aliases.get(text);
|
|
8045
8711
|
}
|
|
8046
8712
|
//#endregion
|
|
8047
8713
|
//#region lib/types/highlight.js
|
|
@@ -9094,7 +9760,11 @@ const LOCAL_COMMANDS = [
|
|
|
9094
9760
|
},
|
|
9095
9761
|
{
|
|
9096
9762
|
name: "subagents",
|
|
9097
|
-
description: "Browse the subagent sessions under this session (Enter
|
|
9763
|
+
description: "Browse the subagent sessions under this session (Enter opens one as a live session view)"
|
|
9764
|
+
},
|
|
9765
|
+
{
|
|
9766
|
+
name: "parent",
|
|
9767
|
+
description: "Return from a subagent view to the session it was opened from"
|
|
9098
9768
|
},
|
|
9099
9769
|
{
|
|
9100
9770
|
name: "settings",
|
|
@@ -9262,6 +9932,8 @@ var TuiApp = class {
|
|
|
9262
9932
|
reasoningTail;
|
|
9263
9933
|
/** The card fades running right now; each drops itself once it settles. */
|
|
9264
9934
|
blockFades = new FadeRegistry();
|
|
9935
|
+
/** Streamed deltas waiting for a frame; absent when deltas are drawn as they arrive. */
|
|
9936
|
+
pacer;
|
|
9265
9937
|
/**
|
|
9266
9938
|
* The chrome motions running right now. It is consulted whatever the
|
|
9267
9939
|
* terminal draws, because a transient line has to come down again even on a
|
|
@@ -9300,6 +9972,11 @@ var TuiApp = class {
|
|
|
9300
9972
|
/** How streamed text is drawn; `none` until the background query settles. */
|
|
9301
9973
|
fadeStyle = NO_FADE;
|
|
9302
9974
|
bound;
|
|
9975
|
+
/**
|
|
9976
|
+
* The sessions a subagent view was entered from, root first; empty while
|
|
9977
|
+
* the root session is bound. `/parent` returns to the last one.
|
|
9978
|
+
*/
|
|
9979
|
+
parents = [];
|
|
9303
9980
|
streaming;
|
|
9304
9981
|
/** Whether the fold keys left every foldable block open; one appended later follows it. */
|
|
9305
9982
|
toolsExpanded = false;
|
|
@@ -9328,6 +10005,7 @@ var TuiApp = class {
|
|
|
9328
10005
|
this.deps = deps;
|
|
9329
10006
|
const palette = deps.palette;
|
|
9330
10007
|
this.bound = deps.initial;
|
|
10008
|
+
this.pacer = deps.reducedMotion || deps.streamPaceFrames === 0 ? void 0 : new StreamPacer({ drainFrames: deps.streamPaceFrames });
|
|
9331
10009
|
this.codeHighlight = new SyntaxHighlighter({
|
|
9332
10010
|
depth: deps.codeHighlight ? resolveColorDepth({
|
|
9333
10011
|
paletteEnabled: palette.enabled,
|
|
@@ -9518,7 +10196,13 @@ var TuiApp = class {
|
|
|
9518
10196
|
this.deps.terminal.write(SET_TERMINAL_DEFAULT_CURSOR);
|
|
9519
10197
|
this.tui.stop();
|
|
9520
10198
|
this.deps.releaseInput();
|
|
9521
|
-
this.
|
|
10199
|
+
const [root, ...views] = [...this.parents, this.bound];
|
|
10200
|
+
for (const view of views.reverse()) view.dispose().catch((error) => {
|
|
10201
|
+
this.deps.terminal.write(`releasing a subagent view failed: ${describeFailure(error)}\n`);
|
|
10202
|
+
});
|
|
10203
|
+
this.parents.length = 0;
|
|
10204
|
+
/* v8 ignore next -- the destructured list always holds the bound session */
|
|
10205
|
+
this.deps.onQuit(root ?? this.bound);
|
|
9522
10206
|
}
|
|
9523
10207
|
/** Draw `next` as the terminal's session: clear the transcript and replay its history. */
|
|
9524
10208
|
bind(next) {
|
|
@@ -9543,6 +10227,7 @@ var TuiApp = class {
|
|
|
9543
10227
|
this.turn = 0;
|
|
9544
10228
|
this.sawSystemPrompt = false;
|
|
9545
10229
|
this.turnStartedAt = void 0;
|
|
10230
|
+
this.pacer?.clear();
|
|
9546
10231
|
this.streaming = void 0;
|
|
9547
10232
|
this.endFade();
|
|
9548
10233
|
this.blockFades.clear();
|
|
@@ -9573,7 +10258,7 @@ var TuiApp = class {
|
|
|
9573
10258
|
* @param verb - what the notice calls the move.
|
|
9574
10259
|
*/
|
|
9575
10260
|
async switchSession(open, verb) {
|
|
9576
|
-
if (this.agent.status === "running") {
|
|
10261
|
+
if ([this.bound, ...this.parents].some((bound) => bound.agent.status === "running")) {
|
|
9577
10262
|
this.notice("stop the running turn (Esc twice) before switching sessions", "error");
|
|
9578
10263
|
return;
|
|
9579
10264
|
}
|
|
@@ -9592,17 +10277,94 @@ var TuiApp = class {
|
|
|
9592
10277
|
await next.dispose();
|
|
9593
10278
|
return;
|
|
9594
10279
|
}
|
|
9595
|
-
const
|
|
10280
|
+
const released = [this.bound, ...this.parents.splice(0).reverse()];
|
|
9596
10281
|
const dropped = this.pending.length;
|
|
9597
10282
|
this.bind(next);
|
|
9598
10283
|
this.notice(`${verb}: session ${next.agent.session.id}`, "success");
|
|
9599
10284
|
if (dropped > 0) this.notice(`${String(dropped)} pending attachment(s) stayed with the previous session`);
|
|
9600
|
-
try {
|
|
10285
|
+
for (const previous of released) try {
|
|
9601
10286
|
await previous.dispose();
|
|
9602
10287
|
} catch (error) {
|
|
9603
10288
|
this.notice(`releasing the previous session failed: ${describeFailure(error)}`, "error");
|
|
9604
10289
|
}
|
|
9605
10290
|
}
|
|
10291
|
+
/**
|
|
10292
|
+
* Draw one subagent session in place of the bound one, keeping the bound
|
|
10293
|
+
* one alive to return to: the whole conversation surface - the live
|
|
10294
|
+
* transcript, the conversation walk, the inspector, the reader, and that
|
|
10295
|
+
* session's own subagents - then reads the child. The entry's detail rows
|
|
10296
|
+
* follow the entry notice.
|
|
10297
|
+
* @param id - the subagent session.
|
|
10298
|
+
* @param row - the listing entry, for its label and detail rows.
|
|
10299
|
+
*/
|
|
10300
|
+
async enterSubagent(id, row) {
|
|
10301
|
+
if (this.switching) {
|
|
10302
|
+
this.notice("wait for the session switch to finish", "error");
|
|
10303
|
+
return;
|
|
10304
|
+
}
|
|
10305
|
+
this.switching = true;
|
|
10306
|
+
let next;
|
|
10307
|
+
try {
|
|
10308
|
+
next = await this.deps.host.observe(id);
|
|
10309
|
+
} catch (error) {
|
|
10310
|
+
this.switching = false;
|
|
10311
|
+
this.notice(`opening subagent ${id} failed: ${describeFailure(error)}`, "error");
|
|
10312
|
+
return;
|
|
10313
|
+
}
|
|
10314
|
+
this.switching = false;
|
|
10315
|
+
if (this.stopped) {
|
|
10316
|
+
await next.dispose();
|
|
10317
|
+
return;
|
|
10318
|
+
}
|
|
10319
|
+
const parent = this.bound;
|
|
10320
|
+
const dropped = this.pending.length;
|
|
10321
|
+
this.parents.push(parent);
|
|
10322
|
+
this.bind(next);
|
|
10323
|
+
this.notice(`subagent ${row.item.label} · Ctrl+P or /parent returns to session ${parent.agent.session.id}`, "success");
|
|
10324
|
+
if (dropped > 0) this.notice(`${String(dropped)} pending attachment(s) stayed with the parent session`);
|
|
10325
|
+
for (const line of await this.detailRows(row)) this.notice(line);
|
|
10326
|
+
}
|
|
10327
|
+
/**
|
|
10328
|
+
* Return from a subagent view to the session it was entered from, drawn
|
|
10329
|
+
* from its log as it stands now, and release the view.
|
|
10330
|
+
*/
|
|
10331
|
+
async leaveSubagent() {
|
|
10332
|
+
const parent = this.parents.at(-1);
|
|
10333
|
+
if (parent === void 0) {
|
|
10334
|
+
this.notice("this is the root session; /parent returns from a subagent view", "error");
|
|
10335
|
+
return;
|
|
10336
|
+
}
|
|
10337
|
+
if (this.switching) {
|
|
10338
|
+
this.notice("wait for the session switch to finish", "error");
|
|
10339
|
+
return;
|
|
10340
|
+
}
|
|
10341
|
+
this.switching = true;
|
|
10342
|
+
let history;
|
|
10343
|
+
try {
|
|
10344
|
+
const observed = await this.deps.host.observe(parent.agent.session.id);
|
|
10345
|
+
history = observed.history;
|
|
10346
|
+
await observed.dispose();
|
|
10347
|
+
} catch (error) {
|
|
10348
|
+
this.switching = false;
|
|
10349
|
+
this.notice(`returning to session ${parent.agent.session.id} failed: ${describeFailure(error)}`, "error");
|
|
10350
|
+
return;
|
|
10351
|
+
}
|
|
10352
|
+
this.switching = false;
|
|
10353
|
+
/* v8 ignore next -- quitting releases every view before a pending return settles */
|
|
10354
|
+
if (this.stopped) return;
|
|
10355
|
+
const view = this.bound;
|
|
10356
|
+
this.parents.pop();
|
|
10357
|
+
this.bind({
|
|
10358
|
+
...parent,
|
|
10359
|
+
history
|
|
10360
|
+
});
|
|
10361
|
+
this.notice(`back in session ${parent.agent.session.id}`, "success");
|
|
10362
|
+
try {
|
|
10363
|
+
await view.dispose();
|
|
10364
|
+
} catch (error) {
|
|
10365
|
+
this.notice(`releasing the subagent view failed: ${describeFailure(error)}`, "error");
|
|
10366
|
+
}
|
|
10367
|
+
}
|
|
9606
10368
|
completableCommands() {
|
|
9607
10369
|
const shared = (this.deps.ctx.get("commands")?.list(this.agent) ?? []).filter((command) => !LOCAL_COMMAND_NAMES.has(command.name));
|
|
9608
10370
|
return [...LOCAL_COMMANDS, ...shared.map((command) => ({
|
|
@@ -9669,7 +10431,8 @@ var TuiApp = class {
|
|
|
9669
10431
|
const session = this.agent.session;
|
|
9670
10432
|
const title = this.deps.ctx.get("sessionTitle")?.get(session)?.title;
|
|
9671
10433
|
const name = title === void 0 ? `session ${session.id}` : `${title} ${palette.dim(`(${session.id})`)}`;
|
|
9672
|
-
this.
|
|
10434
|
+
const trail = this.parents.length === 0 ? palette.dim("· /help for commands") : `${palette.accent(`◆ subagent view ${"›".repeat(this.parents.length)}`)} ${palette.dim("· Ctrl+P returns")}`;
|
|
10435
|
+
this.header.setText(`${palette.bold(palette.accent("dsh"))} ${palette.dim("·")} ${name} ${trail}`);
|
|
9673
10436
|
this.tui.requestRender();
|
|
9674
10437
|
}
|
|
9675
10438
|
refreshFooter() {
|
|
@@ -10233,6 +10996,28 @@ var TuiApp = class {
|
|
|
10233
10996
|
this.notice("usage: /plugins · /plugins bundles · /plugins enable|disable <entry id or bundle> · /plugins add <spec> · /plugins remove <bundle>", "error");
|
|
10234
10997
|
}
|
|
10235
10998
|
/**
|
|
10999
|
+
* Walk the subagent listing: `Enter` on a session opens it as a live view,
|
|
11000
|
+
* and on a row the listing could not read shows why, then reopens the list
|
|
11001
|
+
* on that row.
|
|
11002
|
+
* @param choices - the listing rows, in listing order.
|
|
11003
|
+
*/
|
|
11004
|
+
async browseSubagents(choices) {
|
|
11005
|
+
const rows = choices.map((choice) => this.subagentBrowseRow(choice));
|
|
11006
|
+
let visited;
|
|
11007
|
+
for (;;) {
|
|
11008
|
+
const picked = await this.showModal(new PickPrompt(this.deps.palette, "Subagent sessions", rows.map((row) => row.item), { ...visited === void 0 ? {} : { current: visited } }));
|
|
11009
|
+
const index = rows.findIndex((candidate) => candidate.item.value === picked?.value);
|
|
11010
|
+
const [choice, row] = [choices[index], rows[index]];
|
|
11011
|
+
if (choice === void 0 || row === void 0) return;
|
|
11012
|
+
if (choice.enterable) {
|
|
11013
|
+
await this.enterSubagent(choice.id, row);
|
|
11014
|
+
return;
|
|
11015
|
+
}
|
|
11016
|
+
visited = choice.id;
|
|
11017
|
+
await this.showDetail(row);
|
|
11018
|
+
}
|
|
11019
|
+
}
|
|
11020
|
+
/**
|
|
10236
11021
|
* The browsable entry behind one subagent row: the same detail page the
|
|
10237
11022
|
* `/subagents` list and the live panel open.
|
|
10238
11023
|
* @param choice - the listing row.
|
|
@@ -10250,9 +11035,9 @@ var TuiApp = class {
|
|
|
10250
11035
|
};
|
|
10251
11036
|
}
|
|
10252
11037
|
/**
|
|
10253
|
-
* Open the selected panel row
|
|
10254
|
-
*
|
|
10255
|
-
*
|
|
11038
|
+
* Open the selected panel row as a subagent view, which hands the keyboard
|
|
11039
|
+
* to the input of that view. A diagnostic row explains itself in the panel
|
|
11040
|
+
* and opens nothing.
|
|
10256
11041
|
*/
|
|
10257
11042
|
async openPanelRow() {
|
|
10258
11043
|
const rows = this.panelView.rows;
|
|
@@ -10263,8 +11048,7 @@ var TuiApp = class {
|
|
|
10263
11048
|
const entry = this.subagentEntries.find((candidate) => candidate.id === row.id);
|
|
10264
11049
|
/* v8 ignore next -- every drawn row comes from the entries of the last listing */
|
|
10265
11050
|
if (entry === void 0) return;
|
|
10266
|
-
await this.
|
|
10267
|
-
if (this.panelView.rows.length > 0) this.focusRegion("panel");
|
|
11051
|
+
await this.enterSubagent(entry.id, this.subagentBrowseRow(subagentChoice(entry)));
|
|
10268
11052
|
}
|
|
10269
11053
|
async settings(argument) {
|
|
10270
11054
|
const [first, second, ...rest] = argument === "" ? [] : argument.split(/\s+/u);
|
|
@@ -10412,6 +11196,21 @@ var TuiApp = class {
|
|
|
10412
11196
|
}
|
|
10413
11197
|
this.dispatchCommand("/effort");
|
|
10414
11198
|
return { consume: true };
|
|
11199
|
+
case "todos":
|
|
11200
|
+
this.focusEditor();
|
|
11201
|
+
this.dispatchCommand("/todos");
|
|
11202
|
+
return { consume: true };
|
|
11203
|
+
case "parent":
|
|
11204
|
+
this.focusEditor();
|
|
11205
|
+
this.leaveSubagent();
|
|
11206
|
+
return { consume: true };
|
|
11207
|
+
case "help":
|
|
11208
|
+
if (this.editor.getText() !== "") return void 0;
|
|
11209
|
+
this.dispatchCommand("/help");
|
|
11210
|
+
return { consume: true };
|
|
11211
|
+
case "redraw":
|
|
11212
|
+
this.tui.requestRender(true);
|
|
11213
|
+
return { consume: true };
|
|
10415
11214
|
case "type":
|
|
10416
11215
|
this.focusEditor();
|
|
10417
11216
|
this.editor.handleInput(data);
|
|
@@ -10546,6 +11345,11 @@ var TuiApp = class {
|
|
|
10546
11345
|
rows: () => Math.max(1, this.deps.terminal.rows),
|
|
10547
11346
|
minColumns: this.deps.readerMinColumns,
|
|
10548
11347
|
cursor,
|
|
11348
|
+
effects: {
|
|
11349
|
+
style: () => this.fadeStyle,
|
|
11350
|
+
background: () => this.background,
|
|
11351
|
+
startReveal: () => this.startReaderReveal()
|
|
11352
|
+
},
|
|
10549
11353
|
onExit: (exit) => {
|
|
10550
11354
|
this.closeReader(exit);
|
|
10551
11355
|
}
|
|
@@ -10554,6 +11358,24 @@ var TuiApp = class {
|
|
|
10554
11358
|
this.showReader();
|
|
10555
11359
|
}
|
|
10556
11360
|
/**
|
|
11361
|
+
* Start one reveal of the reader on the application's fade tick, which
|
|
11362
|
+
* repaints the reader until the reveal settles. A terminal that runs no
|
|
11363
|
+
* motion reveals nothing, and the reader draws its settled rows.
|
|
11364
|
+
* @returns the reveal's clock, or undefined on a terminal that runs no motion.
|
|
11365
|
+
*/
|
|
11366
|
+
startReaderReveal() {
|
|
11367
|
+
if (!this.fading) return void 0;
|
|
11368
|
+
const clock = new BlockFadeClock({
|
|
11369
|
+
bornAt: this.deps.now(),
|
|
11370
|
+
stepMs: this.deps.fadeStepMs,
|
|
11371
|
+
steps: this.deps.fadeSteps,
|
|
11372
|
+
now: () => this.deps.now()
|
|
11373
|
+
});
|
|
11374
|
+
this.motions.add(clock);
|
|
11375
|
+
this.updateFadeTicker();
|
|
11376
|
+
return clock;
|
|
11377
|
+
}
|
|
11378
|
+
/**
|
|
10557
11379
|
* Put the open reader on the terminal: settle the conversation, hold the
|
|
10558
11380
|
* main screen off the terminal, and draw the reader on the alternate one.
|
|
10559
11381
|
*
|
|
@@ -10799,7 +11621,7 @@ var TuiApp = class {
|
|
|
10799
11621
|
const next = this.segments[barTarget(to, footerSelectionIndex(this.segments, this.barSelection), count)];
|
|
10800
11622
|
/* v8 ignore next -- the wrapped index stays inside the bar's own segments */
|
|
10801
11623
|
if (next !== void 0) this.barSelection = next.id;
|
|
10802
|
-
this.startChrome("selection",
|
|
11624
|
+
this.startChrome("selection", 8);
|
|
10803
11625
|
this.refreshFooter();
|
|
10804
11626
|
}
|
|
10805
11627
|
/**
|
|
@@ -10823,7 +11645,7 @@ var TuiApp = class {
|
|
|
10823
11645
|
this.focusRegion("bar");
|
|
10824
11646
|
return;
|
|
10825
11647
|
}
|
|
10826
|
-
this.startChrome("selection",
|
|
11648
|
+
this.startChrome("selection", 8);
|
|
10827
11649
|
this.refreshFooter();
|
|
10828
11650
|
}
|
|
10829
11651
|
/** Give the keyboard to the queued-prompt panel on one of its rows. */
|
|
@@ -10923,7 +11745,7 @@ var TuiApp = class {
|
|
|
10923
11745
|
*/
|
|
10924
11746
|
moveCursor(cursor) {
|
|
10925
11747
|
this.cursor = cursor;
|
|
10926
|
-
this.startChrome("selection",
|
|
11748
|
+
this.startChrome("selection", 6);
|
|
10927
11749
|
this.tui.requestRender();
|
|
10928
11750
|
}
|
|
10929
11751
|
/**
|
|
@@ -10994,7 +11816,7 @@ var TuiApp = class {
|
|
|
10994
11816
|
*/
|
|
10995
11817
|
setFocus(region) {
|
|
10996
11818
|
if (region === "editor") this.chrome = void 0;
|
|
10997
|
-
else this.startChrome("landing",
|
|
11819
|
+
else this.startChrome("landing", 12);
|
|
10998
11820
|
this.focus = region;
|
|
10999
11821
|
if (this.reader === void 0) this.tui.setFocus(region === "editor" ? this.editor : null);
|
|
11000
11822
|
this.refreshFooter();
|
|
@@ -11299,9 +12121,12 @@ var TuiApp = class {
|
|
|
11299
12121
|
this.notice("no subagent sessions");
|
|
11300
12122
|
return;
|
|
11301
12123
|
}
|
|
11302
|
-
await this.
|
|
12124
|
+
await this.browseSubagents(choices);
|
|
11303
12125
|
return;
|
|
11304
12126
|
}
|
|
12127
|
+
case "parent":
|
|
12128
|
+
await this.leaveSubagent();
|
|
12129
|
+
return;
|
|
11305
12130
|
case "settings":
|
|
11306
12131
|
await this.settings(argument);
|
|
11307
12132
|
return;
|
|
@@ -11889,6 +12714,22 @@ var TuiApp = class {
|
|
|
11889
12714
|
return this.streaming;
|
|
11890
12715
|
}
|
|
11891
12716
|
/**
|
|
12717
|
+
* Hand one live-stream delta to the transcript: through the pacer, which
|
|
12718
|
+
* releases it on a later frame, or at once when deltas are not paced.
|
|
12719
|
+
* @param channel - what the delta belongs to; consecutive deltas of one
|
|
12720
|
+
* channel release through the first delta's `release`.
|
|
12721
|
+
* @param text - the delta.
|
|
12722
|
+
* @param release - draws a released part of the delta.
|
|
12723
|
+
*/
|
|
12724
|
+
pace(channel, text, release) {
|
|
12725
|
+
if (this.pacer === void 0) {
|
|
12726
|
+
release(text);
|
|
12727
|
+
return;
|
|
12728
|
+
}
|
|
12729
|
+
this.pacer.push(channel, text, release);
|
|
12730
|
+
this.updateFadeTicker();
|
|
12731
|
+
}
|
|
12732
|
+
/**
|
|
11892
12733
|
* Take one visible text delta: the block draws it and the tail of that same
|
|
11893
12734
|
* block ages it. The tail is created with the first delta of a message, so
|
|
11894
12735
|
* a block rebuilt from history or committed from the log never carries one.
|
|
@@ -12079,7 +12920,7 @@ var TuiApp = class {
|
|
|
12079
12920
|
* @returns true while a tail or a card fade keeps changing what is drawn.
|
|
12080
12921
|
*/
|
|
12081
12922
|
fadesMoving() {
|
|
12082
|
-
return this.textTail?.needsRepaint() === true || this.reasoningTail?.needsRepaint() === true || this.blockFades.needsRepaint() || this.motions.needsRepaint();
|
|
12923
|
+
return this.pacer?.pending() === true || this.textTail?.needsRepaint() === true || this.reasoningTail?.needsRepaint() === true || this.blockFades.needsRepaint() || this.motions.needsRepaint();
|
|
12083
12924
|
}
|
|
12084
12925
|
/**
|
|
12085
12926
|
* Apply everything the frame's geometry decides, on the frame that was just
|
|
@@ -12135,6 +12976,7 @@ var TuiApp = class {
|
|
|
12135
12976
|
* levels the elapsed time asks for however long the period itself ran.
|
|
12136
12977
|
*/
|
|
12137
12978
|
onFadeTick() {
|
|
12979
|
+
this.pacer?.frame();
|
|
12138
12980
|
this.textTail?.tick();
|
|
12139
12981
|
this.reasoningTail?.tick();
|
|
12140
12982
|
this.blockFades.tick();
|
|
@@ -12148,6 +12990,7 @@ var TuiApp = class {
|
|
|
12148
12990
|
onStreamFrame(frame) {
|
|
12149
12991
|
switch (frame.type) {
|
|
12150
12992
|
case "start":
|
|
12993
|
+
this.pacer?.flush();
|
|
12151
12994
|
this.streaming = void 0;
|
|
12152
12995
|
this.endFade();
|
|
12153
12996
|
this.beginLiveUsage();
|
|
@@ -12158,20 +13001,29 @@ var TuiApp = class {
|
|
|
12158
13001
|
switch (chunk.type) {
|
|
12159
13002
|
case "text-delta":
|
|
12160
13003
|
if (chunk.text !== "") {
|
|
12161
|
-
this.
|
|
13004
|
+
this.pace("text", chunk.text, (text) => {
|
|
13005
|
+
this.appendStreamedText(text);
|
|
13006
|
+
this.setStreamActivity("writing");
|
|
13007
|
+
});
|
|
12162
13008
|
this.noteStreamedChars(chunk.text.length);
|
|
12163
|
-
this.setStreamActivity("writing");
|
|
12164
13009
|
}
|
|
12165
13010
|
break;
|
|
12166
13011
|
case "reasoning-delta":
|
|
12167
13012
|
if (chunk.text !== "") {
|
|
12168
|
-
this.
|
|
13013
|
+
this.pace("reasoning", chunk.text, (text) => {
|
|
13014
|
+
this.appendStreamedReasoning(text);
|
|
13015
|
+
this.setStreamActivity("thinking");
|
|
13016
|
+
});
|
|
12169
13017
|
this.noteStreamedChars(chunk.text.length);
|
|
12170
|
-
this.setStreamActivity("thinking");
|
|
12171
13018
|
}
|
|
12172
13019
|
break;
|
|
12173
13020
|
case "tool-call-delta":
|
|
12174
|
-
this.
|
|
13021
|
+
this.pace(`tool:${chunk.id}:${chunk.name ?? ""}`, chunk.argumentsDelta, (text) => {
|
|
13022
|
+
this.onToolCallDelta({
|
|
13023
|
+
...chunk,
|
|
13024
|
+
argumentsDelta: text
|
|
13025
|
+
});
|
|
13026
|
+
});
|
|
12175
13027
|
this.noteStreamedChars(chunk.argumentsDelta.length);
|
|
12176
13028
|
break;
|
|
12177
13029
|
case "usage":
|
|
@@ -12183,10 +13035,11 @@ var TuiApp = class {
|
|
|
12183
13035
|
/* v8 ignore next -- closed-union exhaustiveness guard */
|
|
12184
13036
|
default: assertNever(chunk, "tui stream chunk");
|
|
12185
13037
|
}
|
|
12186
|
-
this.tui.requestRender();
|
|
13038
|
+
if (this.pacer === void 0) this.tui.requestRender();
|
|
12187
13039
|
return;
|
|
12188
13040
|
}
|
|
12189
13041
|
case "end":
|
|
13042
|
+
this.pacer?.flush();
|
|
12190
13043
|
this.streaming = void 0;
|
|
12191
13044
|
this.endFade();
|
|
12192
13045
|
if (frame.outcome.kind === "abandoned" || frame.outcome.kind === "committed" && frame.outcome.eventType === "assistant/attempt") this.dropUnconfirmedTools();
|
|
@@ -12202,6 +13055,7 @@ var TuiApp = class {
|
|
|
12202
13055
|
if (this.isBoundDescendant(session)) this.onDescendantActivity(session, event);
|
|
12203
13056
|
return;
|
|
12204
13057
|
}
|
|
13058
|
+
this.pacer?.flush();
|
|
12205
13059
|
switch (event.type) {
|
|
12206
13060
|
case "turn/start":
|
|
12207
13061
|
this.turn = event.data.turn;
|
|
@@ -12246,7 +13100,7 @@ var TuiApp = class {
|
|
|
12246
13100
|
if (block === void 0) break;
|
|
12247
13101
|
const isError = result.isError === true;
|
|
12248
13102
|
const body = toolResultBody(this.presentResult(block.name, this.toolArguments.get(result.toolCallId), result.content, isError, event.data.meta), result.content);
|
|
12249
|
-
block.setResult(body.lines, isError, body.code);
|
|
13103
|
+
block.setResult(body.lines, isError, body.code, body.diff);
|
|
12250
13104
|
this.fadeBlock((fade) => {
|
|
12251
13105
|
block.setResultFade(fade);
|
|
12252
13106
|
});
|
|
@@ -12477,10 +13331,12 @@ var TuiApp = class {
|
|
|
12477
13331
|
const existing = this.toolBlocks.get(callId);
|
|
12478
13332
|
if (existing !== void 0) {
|
|
12479
13333
|
existing.setCall(name, call);
|
|
13334
|
+
if (isSubagentTool(name)) existing.setSubagent(subagentRowFacts(args));
|
|
12480
13335
|
if (source === "log") this.unconfirmedTools.delete(callId);
|
|
12481
13336
|
return;
|
|
12482
13337
|
}
|
|
12483
13338
|
const block = new ToolBlock(this.theme, name, call, this.turn);
|
|
13339
|
+
if (isSubagentTool(name)) block.setSubagent(subagentRowFacts(args));
|
|
12484
13340
|
block.setExpanded(this.toolsExpanded);
|
|
12485
13341
|
this.toolBlocks.set(callId, block);
|
|
12486
13342
|
this.chat.addChild(block);
|
|
@@ -12616,8 +13472,9 @@ const Config = z.object({
|
|
|
12616
13472
|
codeHighlight: z.boolean().default(true),
|
|
12617
13473
|
toastMs: z.natural().min(500).default(TOAST_MS),
|
|
12618
13474
|
liveRefreshMs: z.natural().min(100).default(1e3),
|
|
12619
|
-
streamFadeSteps: z.natural().min(2).default(
|
|
12620
|
-
streamFadeStepMs: z.natural().min(16).default(
|
|
13475
|
+
streamFadeSteps: z.natural().min(2).default(24),
|
|
13476
|
+
streamFadeStepMs: z.natural().min(16).default(16),
|
|
13477
|
+
streamPaceFrames: z.natural().default(8),
|
|
12621
13478
|
reducedMotion: z.boolean().default(false),
|
|
12622
13479
|
openBrowser: z.boolean().default(true)
|
|
12623
13480
|
});
|
|
@@ -12755,28 +13612,42 @@ function sessionHost(ctx, core, cwd) {
|
|
|
12755
13612
|
setup
|
|
12756
13613
|
});
|
|
12757
13614
|
}, seed ?? []);
|
|
13615
|
+
const resume = async (id) => {
|
|
13616
|
+
const selection = {
|
|
13617
|
+
current: void 0,
|
|
13618
|
+
assembled: void 0
|
|
13619
|
+
};
|
|
13620
|
+
const handle = await agents.resume({
|
|
13621
|
+
resumeSessionId: id,
|
|
13622
|
+
setup: (agentCtx) => {
|
|
13623
|
+
installModelSelection(agentCtx, selection);
|
|
13624
|
+
}
|
|
13625
|
+
});
|
|
13626
|
+
await handle.agent.whenIdle();
|
|
13627
|
+
return {
|
|
13628
|
+
agent: handle.agent,
|
|
13629
|
+
selection,
|
|
13630
|
+
history: await observeBoundHistory(ctx, id),
|
|
13631
|
+
dispose: () => handle.dispose()
|
|
13632
|
+
};
|
|
13633
|
+
};
|
|
12758
13634
|
return {
|
|
12759
13635
|
create: () => create(void 0, void 0),
|
|
12760
|
-
resume
|
|
12761
|
-
|
|
12762
|
-
|
|
12763
|
-
|
|
12764
|
-
|
|
12765
|
-
const handle = await agents.resume({
|
|
12766
|
-
resumeSessionId: id,
|
|
12767
|
-
setup: (agentCtx) => {
|
|
12768
|
-
installModelSelection(agentCtx, selection);
|
|
12769
|
-
}
|
|
12770
|
-
});
|
|
12771
|
-
await handle.agent.whenIdle();
|
|
13636
|
+
resume,
|
|
13637
|
+
fork: async (id, turn) => create(await forkSeed(ctx, id, turn), id),
|
|
13638
|
+
observe: async (id) => {
|
|
13639
|
+
const resident = agents.get(id);
|
|
13640
|
+
if (resident === void 0) return resume(id);
|
|
12772
13641
|
return {
|
|
12773
|
-
agent:
|
|
12774
|
-
selection
|
|
13642
|
+
agent: resident,
|
|
13643
|
+
selection: {
|
|
13644
|
+
current: void 0,
|
|
13645
|
+
assembled: void 0
|
|
13646
|
+
},
|
|
12775
13647
|
history: await observeBoundHistory(ctx, id),
|
|
12776
|
-
dispose: () =>
|
|
13648
|
+
dispose: () => Promise.resolve()
|
|
12777
13649
|
};
|
|
12778
|
-
}
|
|
12779
|
-
fork: async (id, turn) => create(await forkSeed(ctx, id, turn), id)
|
|
13650
|
+
}
|
|
12780
13651
|
};
|
|
12781
13652
|
}
|
|
12782
13653
|
/** Report an unexpected runner failure and request a failing exit. */
|
|
@@ -12814,6 +13685,7 @@ async function run(ctx, config, host) {
|
|
|
12814
13685
|
liveRefreshMs: config.liveRefreshMs,
|
|
12815
13686
|
fadeSteps: config.streamFadeSteps,
|
|
12816
13687
|
fadeStepMs: config.streamFadeStepMs,
|
|
13688
|
+
streamPaceFrames: config.streamPaceFrames,
|
|
12817
13689
|
reducedMotion: config.reducedMotion,
|
|
12818
13690
|
env: process.env,
|
|
12819
13691
|
now: () => Date.now(),
|