@songtonyli/dsh-cli 0.1.79 → 0.1.81
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-modules/lib/index.js +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-sidebar/lib/client.js +1 -1
- package/node_modules/@deepseek-ai/dsh-tui-app/README.i18n.yaml +8 -8
- package/node_modules/@deepseek-ai/dsh-tui-app/README.md +10 -6
- package/node_modules/@deepseek-ai/dsh-tui-app/README.zh.md +10 -6
- package/node_modules/@deepseek-ai/dsh-tui-app/lib/index.js +825 -219
- package/package.json +1 -1
|
@@ -2324,6 +2324,280 @@ function sliceColumns(line, cuts) {
|
|
|
2324
2324
|
}
|
|
2325
2325
|
return pieces;
|
|
2326
2326
|
}
|
|
2327
|
+
//#endregion
|
|
2328
|
+
//#region lib/types/style.js
|
|
2329
|
+
/**
|
|
2330
|
+
* The terminal palette: one table of SGR open/close pairs behind named roles,
|
|
2331
|
+
* so components never emit raw escape codes. Colored roles draw from the
|
|
2332
|
+
* Tokyo Night (Night) hues, as 24-bit color on a terminal that declares
|
|
2333
|
+
* truecolor and as the nearest xterm-256 index otherwise. A disabled palette
|
|
2334
|
+
* returns text unchanged for dumb terminals and captured output. The palette
|
|
2335
|
+
* also says whether the keys a surface names are clickable, because it is what
|
|
2336
|
+
* every surface draws a key chip with.
|
|
2337
|
+
* @module @deepseek-ai/dsh-tui-app/style
|
|
2338
|
+
*/
|
|
2339
|
+
const ESC = "\x1B[";
|
|
2340
|
+
/** SGR that resets the foreground, closing every hue. */
|
|
2341
|
+
const FOREGROUND_CLOSE = "39";
|
|
2342
|
+
/** Each hue's Tokyo Night (Night) color and its nearest xterm-256 index. */
|
|
2343
|
+
const HUES = {
|
|
2344
|
+
blue: ["#7aa2f7", 111],
|
|
2345
|
+
cyan: ["#7dcfff", 117],
|
|
2346
|
+
teal: ["#73daca", 80],
|
|
2347
|
+
green: ["#9ece6a", 149],
|
|
2348
|
+
yellow: ["#e0af68", 179],
|
|
2349
|
+
orange: ["#ff9e64", 215],
|
|
2350
|
+
red: ["#f7768e", 210],
|
|
2351
|
+
magenta: ["#bb9af7", 141],
|
|
2352
|
+
purple: ["#9d7cd8", 140]
|
|
2353
|
+
};
|
|
2354
|
+
/** The hue each colored role draws in. */
|
|
2355
|
+
const ROLE_HUES = {
|
|
2356
|
+
accent: "blue",
|
|
2357
|
+
heading: "orange",
|
|
2358
|
+
link: "magenta",
|
|
2359
|
+
success: "green",
|
|
2360
|
+
warning: "yellow",
|
|
2361
|
+
error: "red",
|
|
2362
|
+
tool: "cyan",
|
|
2363
|
+
subject: "teal",
|
|
2364
|
+
model: "purple",
|
|
2365
|
+
addedSign: "green",
|
|
2366
|
+
removedSign: "red"
|
|
2367
|
+
};
|
|
2368
|
+
/** SGR open/close code pairs of the roles that are not a hue. */
|
|
2369
|
+
const SGR = {
|
|
2370
|
+
dim: ["2", "22"],
|
|
2371
|
+
bold: ["1", "22"],
|
|
2372
|
+
italic: ["3", "23"],
|
|
2373
|
+
underline: ["4", "24"],
|
|
2374
|
+
strikethrough: ["9", "29"],
|
|
2375
|
+
inverse: ["7", "27"],
|
|
2376
|
+
band: ["48;5;236", "49"],
|
|
2377
|
+
injectedBand: ["48;5;234", "49"],
|
|
2378
|
+
addedBand: ["48;5;22", "49"],
|
|
2379
|
+
removedBand: ["48;5;52", "49"]
|
|
2380
|
+
};
|
|
2381
|
+
/**
|
|
2382
|
+
* The SGR parameters that set one hue as the foreground.
|
|
2383
|
+
* @param hue - the hue.
|
|
2384
|
+
* @param depth - how the terminal encodes it.
|
|
2385
|
+
* @returns e.g. `38;2;122;162;247` or `38;5;111`.
|
|
2386
|
+
*/
|
|
2387
|
+
function hueOpen(hue, depth) {
|
|
2388
|
+
const [rgb, ansi256] = HUES[hue];
|
|
2389
|
+
if (depth === "ansi256") return `38;5;${String(ansi256)}`;
|
|
2390
|
+
const value = Number.parseInt(rgb.slice(1), 16);
|
|
2391
|
+
return `38;2;${String(value >> 16)};${String(value >> 8 & 255)};${String(value & 255)}`;
|
|
2392
|
+
}
|
|
2393
|
+
/**
|
|
2394
|
+
* Whether the environment declares 24-bit color: `COLORTERM` of `truecolor` or `24bit`.
|
|
2395
|
+
* @param env - the process environment.
|
|
2396
|
+
* @returns true when `ESC[38;2;R;G;Bm` is understood.
|
|
2397
|
+
*/
|
|
2398
|
+
function declaresTruecolor(env) {
|
|
2399
|
+
const colorterm = (env.COLORTERM ?? "").toLowerCase();
|
|
2400
|
+
return colorterm === "truecolor" || colorterm === "24bit";
|
|
2401
|
+
}
|
|
2402
|
+
/**
|
|
2403
|
+
* Decide how the palette encodes its hues.
|
|
2404
|
+
* @param env - the process environment.
|
|
2405
|
+
* @returns `truecolor` when the environment declares it, otherwise `ansi256`.
|
|
2406
|
+
*/
|
|
2407
|
+
function paletteDepth(env) {
|
|
2408
|
+
return declaresTruecolor(env) ? "truecolor" : "ansi256";
|
|
2409
|
+
}
|
|
2410
|
+
/**
|
|
2411
|
+
* Build the palette.
|
|
2412
|
+
* @param enabled - whether escape sequences are emitted; false makes every role the identity.
|
|
2413
|
+
* @param clickableKeys - whether key chips carry click marks; false by default.
|
|
2414
|
+
* @param depth - how hues are encoded; `ansi256` by default.
|
|
2415
|
+
* @returns the palette.
|
|
2416
|
+
*/
|
|
2417
|
+
function createPalette(enabled, clickableKeys = false, depth = "ansi256") {
|
|
2418
|
+
const wrap = (open, close) => enabled ? (text) => `${ESC}${open}m${text}${ESC}${close}m` : (text) => text;
|
|
2419
|
+
const role = (name) => wrap(...SGR[name]);
|
|
2420
|
+
const paint = (name) => wrap(hueOpen(name, depth), FOREGROUND_CLOSE);
|
|
2421
|
+
const hue = {
|
|
2422
|
+
blue: paint("blue"),
|
|
2423
|
+
cyan: paint("cyan"),
|
|
2424
|
+
teal: paint("teal"),
|
|
2425
|
+
green: paint("green"),
|
|
2426
|
+
yellow: paint("yellow"),
|
|
2427
|
+
orange: paint("orange"),
|
|
2428
|
+
red: paint("red"),
|
|
2429
|
+
magenta: paint("magenta"),
|
|
2430
|
+
purple: paint("purple")
|
|
2431
|
+
};
|
|
2432
|
+
const colored = (name) => hue[ROLE_HUES[name]];
|
|
2433
|
+
return {
|
|
2434
|
+
dim: role("dim"),
|
|
2435
|
+
bold: role("bold"),
|
|
2436
|
+
italic: role("italic"),
|
|
2437
|
+
underline: role("underline"),
|
|
2438
|
+
strikethrough: role("strikethrough"),
|
|
2439
|
+
accent: colored("accent"),
|
|
2440
|
+
heading: colored("heading"),
|
|
2441
|
+
link: colored("link"),
|
|
2442
|
+
success: colored("success"),
|
|
2443
|
+
warning: colored("warning"),
|
|
2444
|
+
error: colored("error"),
|
|
2445
|
+
tool: colored("tool"),
|
|
2446
|
+
subject: colored("subject"),
|
|
2447
|
+
model: colored("model"),
|
|
2448
|
+
inverse: role("inverse"),
|
|
2449
|
+
band: role("band"),
|
|
2450
|
+
injectedBand: role("injectedBand"),
|
|
2451
|
+
addedBand: role("addedBand"),
|
|
2452
|
+
removedBand: role("removedBand"),
|
|
2453
|
+
addedSign: colored("addedSign"),
|
|
2454
|
+
removedSign: colored("removedSign"),
|
|
2455
|
+
hue,
|
|
2456
|
+
enabled,
|
|
2457
|
+
clickableKeys
|
|
2458
|
+
};
|
|
2459
|
+
}
|
|
2460
|
+
/**
|
|
2461
|
+
* Paint added and removed diff rows while leaving context and metadata rows
|
|
2462
|
+
* unchanged. `source` stays plain so syntax-colored rows can be classified.
|
|
2463
|
+
* @param rows - rows after optional syntax highlighting.
|
|
2464
|
+
* @param source - corresponding plain rows carrying the diff prefixes.
|
|
2465
|
+
* @param palette - active terminal palette.
|
|
2466
|
+
* @returns the rows with additions green and removals red.
|
|
2467
|
+
*/
|
|
2468
|
+
function paintDiffRows(rows, source, palette) {
|
|
2469
|
+
return rows.map((row, index) => {
|
|
2470
|
+
const plain = source[index];
|
|
2471
|
+
if (plain?.startsWith("+ ") === true) return palette.success(row);
|
|
2472
|
+
if (plain?.startsWith("- ") === true) return palette.error(row);
|
|
2473
|
+
return row;
|
|
2474
|
+
});
|
|
2475
|
+
}
|
|
2476
|
+
/**
|
|
2477
|
+
* Lay one row on a background tint across the full width.
|
|
2478
|
+
* @param palette - the active palette.
|
|
2479
|
+
* @param row - the styled row, at most `width` columns.
|
|
2480
|
+
* @param width - the columns the band spans.
|
|
2481
|
+
* @param band - the tint; {@link Palette.band} by default.
|
|
2482
|
+
* @returns the row padded to `width` under the tint; the row unchanged, with
|
|
2483
|
+
* no padding, when the palette is disabled.
|
|
2484
|
+
*/
|
|
2485
|
+
function bandRow(palette, row, width, band = palette.band) {
|
|
2486
|
+
return palette.enabled ? band(`${row}${" ".repeat(Math.max(0, width - visibleWidth(row)))}`) : row;
|
|
2487
|
+
}
|
|
2488
|
+
/**
|
|
2489
|
+
* The `+` or `-` of a changed row, painted apart from the tint the row is
|
|
2490
|
+
* filled with. The sign sits in the plain row's own prefix - the file line
|
|
2491
|
+
* number, when the diff carries one, then the sign and a space - and syntax
|
|
2492
|
+
* colour starts after it, so the styled row opens with the same characters.
|
|
2493
|
+
* @param row - the styled row.
|
|
2494
|
+
* @param plain - the same row before any syntax colour.
|
|
2495
|
+
* @param mark - whether the row is an addition or a removal.
|
|
2496
|
+
* @param palette - the active palette.
|
|
2497
|
+
* @returns the row with its sign painted, or unchanged when the styled row
|
|
2498
|
+
* does not open with the plain prefix.
|
|
2499
|
+
*/
|
|
2500
|
+
function paintDiffSign(row, plain, mark, palette) {
|
|
2501
|
+
const sign = mark === "added" ? "+" : "-";
|
|
2502
|
+
const at = plain.indexOf(`${sign} `);
|
|
2503
|
+
if (at === -1 || !row.startsWith(plain.slice(0, at + 1))) return row;
|
|
2504
|
+
const paint = mark === "added" ? palette.addedSign : palette.removedSign;
|
|
2505
|
+
return `${row.slice(0, at)}${paint(sign)}${row.slice(at + 1)}`;
|
|
2506
|
+
}
|
|
2507
|
+
/**
|
|
2508
|
+
* Wrap rows to `width` and fill each changed row edge to edge with its own
|
|
2509
|
+
* background tint - green for an addition, red for a removal - so a run of
|
|
2510
|
+
* changes reads as one region without spending a column on a border. The `+`
|
|
2511
|
+
* and `-` are painted in their own lighter colour, apart from the fill, and a
|
|
2512
|
+
* wrapped continuation carries the tint with no sign of its own. Every
|
|
2513
|
+
* returned line is at most `width` columns, and every filled line is exactly
|
|
2514
|
+
* `width`; a disabled palette pads nothing and returns the rows as they are.
|
|
2515
|
+
* @param rows - the styled rows.
|
|
2516
|
+
* @param plain - the same rows before any syntax colour, which carry the signs.
|
|
2517
|
+
* @param marks - per row, whether it is an addition or a removal; undefined
|
|
2518
|
+
* for a row no tint fills.
|
|
2519
|
+
* @param width - the columns the rows fit.
|
|
2520
|
+
* @param palette - the active palette.
|
|
2521
|
+
* @returns the wrapped rows, the changed ones filled.
|
|
2522
|
+
*/
|
|
2523
|
+
function bandDiffRows(rows, plain, marks, width, palette) {
|
|
2524
|
+
const columns = Math.max(1, width);
|
|
2525
|
+
const out = [];
|
|
2526
|
+
for (const [index, row] of rows.entries()) {
|
|
2527
|
+
const mark = marks[index];
|
|
2528
|
+
if (mark === void 0) {
|
|
2529
|
+
out.push(...wrapTextWithAnsi(row, columns));
|
|
2530
|
+
continue;
|
|
2531
|
+
}
|
|
2532
|
+
const fill = mark === "added" ? palette.addedBand : palette.removedBand;
|
|
2533
|
+
const signed = paintDiffSign(row, plain[index] ?? "", mark, palette);
|
|
2534
|
+
for (const part of wrapTextWithAnsi(signed, columns)) out.push(palette.enabled ? fill(`${part}${" ".repeat(Math.max(0, columns - visibleWidth(part)))}`) : part);
|
|
2535
|
+
}
|
|
2536
|
+
return out;
|
|
2537
|
+
}
|
|
2538
|
+
/**
|
|
2539
|
+
* Decide whether the terminal gets color: `NO_COLOR` (any non-empty value)
|
|
2540
|
+
* wins, then a non-empty non-zero `FORCE_COLOR`, then whether stdout is a TTY.
|
|
2541
|
+
* @param env - the process environment.
|
|
2542
|
+
* @param isTty - whether stdout is a terminal.
|
|
2543
|
+
* @returns true when SGR styling should be emitted.
|
|
2544
|
+
*/
|
|
2545
|
+
function colorEnabled(env, isTty) {
|
|
2546
|
+
if (env.NO_COLOR !== void 0 && env.NO_COLOR !== "") return false;
|
|
2547
|
+
if (env.FORCE_COLOR !== void 0 && env.FORCE_COLOR !== "" && env.FORCE_COLOR !== "0") return true;
|
|
2548
|
+
return isTty;
|
|
2549
|
+
}
|
|
2550
|
+
/**
|
|
2551
|
+
* The Markdown theme derived from the palette.
|
|
2552
|
+
* @param palette - the active palette.
|
|
2553
|
+
* @param highlight - colours fenced code; omitted draws every block plain,
|
|
2554
|
+
* which is also what a block whose language has no grammar here draws as.
|
|
2555
|
+
* @returns a complete pi-tui Markdown theme.
|
|
2556
|
+
*/
|
|
2557
|
+
function markdownTheme(palette, highlight) {
|
|
2558
|
+
return {
|
|
2559
|
+
highlightCode: (code, lang) => highlight?.lines(code, lang) ?? code.split("\n"),
|
|
2560
|
+
heading: (text) => palette.bold(palette.heading(text)),
|
|
2561
|
+
link: (text) => palette.underline(palette.link(text)),
|
|
2562
|
+
linkUrl: palette.dim,
|
|
2563
|
+
code: palette.link,
|
|
2564
|
+
codeBlock: (text) => text,
|
|
2565
|
+
codeBlockBorder: palette.dim,
|
|
2566
|
+
quote: (text) => palette.italic(palette.dim(text)),
|
|
2567
|
+
quoteBorder: palette.dim,
|
|
2568
|
+
hr: palette.dim,
|
|
2569
|
+
listBullet: palette.heading,
|
|
2570
|
+
bold: palette.bold,
|
|
2571
|
+
italic: palette.italic,
|
|
2572
|
+
strikethrough: palette.strikethrough,
|
|
2573
|
+
underline: palette.underline
|
|
2574
|
+
};
|
|
2575
|
+
}
|
|
2576
|
+
/**
|
|
2577
|
+
* The select-list theme derived from the palette.
|
|
2578
|
+
* @param palette - the active palette.
|
|
2579
|
+
* @returns a complete pi-tui select-list theme.
|
|
2580
|
+
*/
|
|
2581
|
+
function selectListTheme(palette) {
|
|
2582
|
+
return {
|
|
2583
|
+
selectedPrefix: palette.accent,
|
|
2584
|
+
selectedText: (text) => palette.bold(palette.accent(text)),
|
|
2585
|
+
description: palette.dim,
|
|
2586
|
+
scrollInfo: palette.dim,
|
|
2587
|
+
noMatch: palette.dim
|
|
2588
|
+
};
|
|
2589
|
+
}
|
|
2590
|
+
/**
|
|
2591
|
+
* The editor theme derived from the palette.
|
|
2592
|
+
* @param palette - the active palette.
|
|
2593
|
+
* @returns a complete pi-tui editor theme.
|
|
2594
|
+
*/
|
|
2595
|
+
function editorTheme(palette) {
|
|
2596
|
+
return {
|
|
2597
|
+
borderColor: palette.dim,
|
|
2598
|
+
selectList: selectListTheme(palette)
|
|
2599
|
+
};
|
|
2600
|
+
}
|
|
2327
2601
|
/** Control Sequence Introducer. */
|
|
2328
2602
|
const CSI$2 = "\x1B[";
|
|
2329
2603
|
/**
|
|
@@ -2391,8 +2665,7 @@ function resolveFadeCapability(input) {
|
|
|
2391
2665
|
if (env.NO_COLOR !== void 0 && env.NO_COLOR !== "") return "none";
|
|
2392
2666
|
const term = env.TERM ?? "";
|
|
2393
2667
|
if (term === "dumb") return "none";
|
|
2394
|
-
|
|
2395
|
-
if (colorterm === "truecolor" || colorterm === "24bit") return "truecolor";
|
|
2668
|
+
if (declaresTruecolor(env)) return "truecolor";
|
|
2396
2669
|
return term.includes("256color") ? "ansi256" : "dim";
|
|
2397
2670
|
}
|
|
2398
2671
|
/**
|
|
@@ -3455,213 +3728,6 @@ var TailWrappedText = class {
|
|
|
3455
3728
|
}
|
|
3456
3729
|
};
|
|
3457
3730
|
//#endregion
|
|
3458
|
-
//#region lib/types/style.js
|
|
3459
|
-
/**
|
|
3460
|
-
* The terminal palette: one table of SGR open/close pairs behind named roles,
|
|
3461
|
-
* so components never emit raw escape codes. A disabled palette returns text
|
|
3462
|
-
* unchanged for dumb terminals and captured output. The palette also says
|
|
3463
|
-
* whether the keys a surface names are clickable, because it is what every
|
|
3464
|
-
* surface draws a key chip with.
|
|
3465
|
-
* @module @deepseek-ai/dsh-tui-app/style
|
|
3466
|
-
*/
|
|
3467
|
-
const ESC = "\x1B[";
|
|
3468
|
-
/** SGR open/close code pairs by role. */
|
|
3469
|
-
const SGR = {
|
|
3470
|
-
dim: ["2", "22"],
|
|
3471
|
-
bold: ["1", "22"],
|
|
3472
|
-
italic: ["3", "23"],
|
|
3473
|
-
underline: ["4", "24"],
|
|
3474
|
-
strikethrough: ["9", "29"],
|
|
3475
|
-
accent: ["36", "39"],
|
|
3476
|
-
heading: ["38;5;215", "39"],
|
|
3477
|
-
link: ["38;5;141", "39"],
|
|
3478
|
-
success: ["32", "39"],
|
|
3479
|
-
warning: ["33", "39"],
|
|
3480
|
-
error: ["31", "39"],
|
|
3481
|
-
inverse: ["7", "27"],
|
|
3482
|
-
band: ["48;5;236", "49"],
|
|
3483
|
-
injectedBand: ["48;5;234", "49"],
|
|
3484
|
-
addedBand: ["48;5;22", "49"],
|
|
3485
|
-
removedBand: ["48;5;52", "49"],
|
|
3486
|
-
addedSign: ["38;5;120", "39"],
|
|
3487
|
-
removedSign: ["38;5;210", "39"]
|
|
3488
|
-
};
|
|
3489
|
-
/**
|
|
3490
|
-
* Build the palette.
|
|
3491
|
-
* @param enabled - whether escape sequences are emitted; false makes every role the identity.
|
|
3492
|
-
* @param clickableKeys - whether key chips carry click marks; false by default.
|
|
3493
|
-
* @returns the palette.
|
|
3494
|
-
*/
|
|
3495
|
-
function createPalette(enabled, clickableKeys = false) {
|
|
3496
|
-
const role = (name) => {
|
|
3497
|
-
const [open, close] = SGR[name];
|
|
3498
|
-
return enabled ? (text) => `${ESC}${open}m${text}${ESC}${close}m` : (text) => text;
|
|
3499
|
-
};
|
|
3500
|
-
return {
|
|
3501
|
-
dim: role("dim"),
|
|
3502
|
-
bold: role("bold"),
|
|
3503
|
-
italic: role("italic"),
|
|
3504
|
-
underline: role("underline"),
|
|
3505
|
-
strikethrough: role("strikethrough"),
|
|
3506
|
-
accent: role("accent"),
|
|
3507
|
-
heading: role("heading"),
|
|
3508
|
-
link: role("link"),
|
|
3509
|
-
success: role("success"),
|
|
3510
|
-
warning: role("warning"),
|
|
3511
|
-
error: role("error"),
|
|
3512
|
-
inverse: role("inverse"),
|
|
3513
|
-
band: role("band"),
|
|
3514
|
-
injectedBand: role("injectedBand"),
|
|
3515
|
-
addedBand: role("addedBand"),
|
|
3516
|
-
removedBand: role("removedBand"),
|
|
3517
|
-
addedSign: role("addedSign"),
|
|
3518
|
-
removedSign: role("removedSign"),
|
|
3519
|
-
enabled,
|
|
3520
|
-
clickableKeys
|
|
3521
|
-
};
|
|
3522
|
-
}
|
|
3523
|
-
/**
|
|
3524
|
-
* Paint added and removed diff rows while leaving context and metadata rows
|
|
3525
|
-
* unchanged. `source` stays plain so syntax-colored rows can be classified.
|
|
3526
|
-
* @param rows - rows after optional syntax highlighting.
|
|
3527
|
-
* @param source - corresponding plain rows carrying the diff prefixes.
|
|
3528
|
-
* @param palette - active terminal palette.
|
|
3529
|
-
* @returns the rows with additions green and removals red.
|
|
3530
|
-
*/
|
|
3531
|
-
function paintDiffRows(rows, source, palette) {
|
|
3532
|
-
return rows.map((row, index) => {
|
|
3533
|
-
const plain = source[index];
|
|
3534
|
-
if (plain?.startsWith("+ ") === true) return palette.success(row);
|
|
3535
|
-
if (plain?.startsWith("- ") === true) return palette.error(row);
|
|
3536
|
-
return row;
|
|
3537
|
-
});
|
|
3538
|
-
}
|
|
3539
|
-
/**
|
|
3540
|
-
* Lay one row on a background tint across the full width.
|
|
3541
|
-
* @param palette - the active palette.
|
|
3542
|
-
* @param row - the styled row, at most `width` columns.
|
|
3543
|
-
* @param width - the columns the band spans.
|
|
3544
|
-
* @param band - the tint; {@link Palette.band} by default.
|
|
3545
|
-
* @returns the row padded to `width` under the tint; the row unchanged, with
|
|
3546
|
-
* no padding, when the palette is disabled.
|
|
3547
|
-
*/
|
|
3548
|
-
function bandRow(palette, row, width, band = palette.band) {
|
|
3549
|
-
return palette.enabled ? band(`${row}${" ".repeat(Math.max(0, width - visibleWidth(row)))}`) : row;
|
|
3550
|
-
}
|
|
3551
|
-
/**
|
|
3552
|
-
* The `+` or `-` of a changed row, painted apart from the tint the row is
|
|
3553
|
-
* filled with. The sign sits in the plain row's own prefix - the file line
|
|
3554
|
-
* number, when the diff carries one, then the sign and a space - and syntax
|
|
3555
|
-
* colour starts after it, so the styled row opens with the same characters.
|
|
3556
|
-
* @param row - the styled row.
|
|
3557
|
-
* @param plain - the same row before any syntax colour.
|
|
3558
|
-
* @param mark - whether the row is an addition or a removal.
|
|
3559
|
-
* @param palette - the active palette.
|
|
3560
|
-
* @returns the row with its sign painted, or unchanged when the styled row
|
|
3561
|
-
* does not open with the plain prefix.
|
|
3562
|
-
*/
|
|
3563
|
-
function paintDiffSign(row, plain, mark, palette) {
|
|
3564
|
-
const sign = mark === "added" ? "+" : "-";
|
|
3565
|
-
const at = plain.indexOf(`${sign} `);
|
|
3566
|
-
if (at === -1 || !row.startsWith(plain.slice(0, at + 1))) return row;
|
|
3567
|
-
const paint = mark === "added" ? palette.addedSign : palette.removedSign;
|
|
3568
|
-
return `${row.slice(0, at)}${paint(sign)}${row.slice(at + 1)}`;
|
|
3569
|
-
}
|
|
3570
|
-
/**
|
|
3571
|
-
* Wrap rows to `width` and fill each changed row edge to edge with its own
|
|
3572
|
-
* background tint - green for an addition, red for a removal - so a run of
|
|
3573
|
-
* changes reads as one region without spending a column on a border. The `+`
|
|
3574
|
-
* and `-` are painted in their own lighter colour, apart from the fill, and a
|
|
3575
|
-
* wrapped continuation carries the tint with no sign of its own. Every
|
|
3576
|
-
* returned line is at most `width` columns, and every filled line is exactly
|
|
3577
|
-
* `width`; a disabled palette pads nothing and returns the rows as they are.
|
|
3578
|
-
* @param rows - the styled rows.
|
|
3579
|
-
* @param plain - the same rows before any syntax colour, which carry the signs.
|
|
3580
|
-
* @param marks - per row, whether it is an addition or a removal; undefined
|
|
3581
|
-
* for a row no tint fills.
|
|
3582
|
-
* @param width - the columns the rows fit.
|
|
3583
|
-
* @param palette - the active palette.
|
|
3584
|
-
* @returns the wrapped rows, the changed ones filled.
|
|
3585
|
-
*/
|
|
3586
|
-
function bandDiffRows(rows, plain, marks, width, palette) {
|
|
3587
|
-
const columns = Math.max(1, width);
|
|
3588
|
-
const out = [];
|
|
3589
|
-
for (const [index, row] of rows.entries()) {
|
|
3590
|
-
const mark = marks[index];
|
|
3591
|
-
if (mark === void 0) {
|
|
3592
|
-
out.push(...wrapTextWithAnsi(row, columns));
|
|
3593
|
-
continue;
|
|
3594
|
-
}
|
|
3595
|
-
const fill = mark === "added" ? palette.addedBand : palette.removedBand;
|
|
3596
|
-
const signed = paintDiffSign(row, plain[index] ?? "", mark, palette);
|
|
3597
|
-
for (const part of wrapTextWithAnsi(signed, columns)) out.push(palette.enabled ? fill(`${part}${" ".repeat(Math.max(0, columns - visibleWidth(part)))}`) : part);
|
|
3598
|
-
}
|
|
3599
|
-
return out;
|
|
3600
|
-
}
|
|
3601
|
-
/**
|
|
3602
|
-
* Decide whether the terminal gets color: `NO_COLOR` (any non-empty value)
|
|
3603
|
-
* wins, then a non-empty non-zero `FORCE_COLOR`, then whether stdout is a TTY.
|
|
3604
|
-
* @param env - the process environment.
|
|
3605
|
-
* @param isTty - whether stdout is a terminal.
|
|
3606
|
-
* @returns true when SGR styling should be emitted.
|
|
3607
|
-
*/
|
|
3608
|
-
function colorEnabled(env, isTty) {
|
|
3609
|
-
if (env.NO_COLOR !== void 0 && env.NO_COLOR !== "") return false;
|
|
3610
|
-
if (env.FORCE_COLOR !== void 0 && env.FORCE_COLOR !== "" && env.FORCE_COLOR !== "0") return true;
|
|
3611
|
-
return isTty;
|
|
3612
|
-
}
|
|
3613
|
-
/**
|
|
3614
|
-
* The Markdown theme derived from the palette.
|
|
3615
|
-
* @param palette - the active palette.
|
|
3616
|
-
* @param highlight - colours fenced code; omitted draws every block plain,
|
|
3617
|
-
* which is also what a block whose language has no grammar here draws as.
|
|
3618
|
-
* @returns a complete pi-tui Markdown theme.
|
|
3619
|
-
*/
|
|
3620
|
-
function markdownTheme(palette, highlight) {
|
|
3621
|
-
return {
|
|
3622
|
-
highlightCode: (code, lang) => highlight?.lines(code, lang) ?? code.split("\n"),
|
|
3623
|
-
heading: (text) => palette.bold(palette.heading(text)),
|
|
3624
|
-
link: (text) => palette.underline(palette.link(text)),
|
|
3625
|
-
linkUrl: palette.dim,
|
|
3626
|
-
code: palette.link,
|
|
3627
|
-
codeBlock: (text) => text,
|
|
3628
|
-
codeBlockBorder: palette.dim,
|
|
3629
|
-
quote: (text) => palette.italic(palette.dim(text)),
|
|
3630
|
-
quoteBorder: palette.dim,
|
|
3631
|
-
hr: palette.dim,
|
|
3632
|
-
listBullet: palette.heading,
|
|
3633
|
-
bold: palette.bold,
|
|
3634
|
-
italic: palette.italic,
|
|
3635
|
-
strikethrough: palette.strikethrough,
|
|
3636
|
-
underline: palette.underline
|
|
3637
|
-
};
|
|
3638
|
-
}
|
|
3639
|
-
/**
|
|
3640
|
-
* The select-list theme derived from the palette.
|
|
3641
|
-
* @param palette - the active palette.
|
|
3642
|
-
* @returns a complete pi-tui select-list theme.
|
|
3643
|
-
*/
|
|
3644
|
-
function selectListTheme(palette) {
|
|
3645
|
-
return {
|
|
3646
|
-
selectedPrefix: palette.accent,
|
|
3647
|
-
selectedText: (text) => palette.bold(palette.accent(text)),
|
|
3648
|
-
description: palette.dim,
|
|
3649
|
-
scrollInfo: palette.dim,
|
|
3650
|
-
noMatch: palette.dim
|
|
3651
|
-
};
|
|
3652
|
-
}
|
|
3653
|
-
/**
|
|
3654
|
-
* The editor theme derived from the palette.
|
|
3655
|
-
* @param palette - the active palette.
|
|
3656
|
-
* @returns a complete pi-tui editor theme.
|
|
3657
|
-
*/
|
|
3658
|
-
function editorTheme(palette) {
|
|
3659
|
-
return {
|
|
3660
|
-
borderColor: palette.dim,
|
|
3661
|
-
selectList: selectListTheme(palette)
|
|
3662
|
-
};
|
|
3663
|
-
}
|
|
3664
|
-
//#endregion
|
|
3665
3731
|
//#region lib/types/blocks.js
|
|
3666
3732
|
/**
|
|
3667
3733
|
* Transcript components: one pi-tui component per rendered fact (a user
|
|
@@ -4829,7 +4895,7 @@ var ToolBlock = class {
|
|
|
4829
4895
|
marker: 0
|
|
4830
4896
|
};
|
|
4831
4897
|
}
|
|
4832
|
-
const header = `${this.statusStyle()(TOOL_GLYPH)} ${palette.bold(this.toolName)}${this.call.title === "" ? "" : ` ${palette.
|
|
4898
|
+
const header = `${this.statusStyle()(TOOL_GLYPH)} ${palette.bold(palette.tool(this.toolName))}${this.call.title === "" ? "" : ` ${palette.subject(this.call.title)}`}`;
|
|
4833
4899
|
const loading = this.status === "running" ? ["…"] : [];
|
|
4834
4900
|
const body = [
|
|
4835
4901
|
...this.call.lines,
|
|
@@ -4899,7 +4965,7 @@ var ToolBlock = class {
|
|
|
4899
4965
|
}
|
|
4900
4966
|
/**
|
|
4901
4967
|
* The one row a folded subagent card draws, led by the status-coloured
|
|
4902
|
-
* {@link SUBAGENT_RUNNING_GLYPH}. A running row carries the
|
|
4968
|
+
* {@link SUBAGENT_RUNNING_GLYPH}. A running row carries the cyan tool
|
|
4903
4969
|
* name; a settled row is dim and ends on its outcome tag at the right edge:
|
|
4904
4970
|
* `[failed]` for an error, `[started]` for a call that handed the child to
|
|
4905
4971
|
* the background, whose result reads `started …` and whose glyph is dim,
|
|
@@ -4913,7 +4979,7 @@ var ToolBlock = class {
|
|
|
4913
4979
|
const meta = facts.meta.length === 0 ? "" : ` ${palette.dim(facts.meta.join(" · "))}`;
|
|
4914
4980
|
const description = facts.description === "" ? "" : ` ${facts.description}`;
|
|
4915
4981
|
if (this.status === "running") {
|
|
4916
|
-
const name = palette.bold(palette.
|
|
4982
|
+
const name = palette.bold(palette.tool(this.toolName));
|
|
4917
4983
|
return truncateToWidth(`${palette.warning("◆")} ${name}${description}${meta}`, width, "…");
|
|
4918
4984
|
}
|
|
4919
4985
|
const started = this.status === "done" && this.resultLines[0]?.startsWith("started ") === true;
|
|
@@ -6137,6 +6203,458 @@ function sameIds(left, right) {
|
|
|
6137
6203
|
return true;
|
|
6138
6204
|
}
|
|
6139
6205
|
//#endregion
|
|
6206
|
+
//#region lib/types/context-usage.js
|
|
6207
|
+
/**
|
|
6208
|
+
* The `/context` report: how the bound session's context window splits
|
|
6209
|
+
* across the system prompt, tool definitions, instruction files, skills,
|
|
6210
|
+
* other injected context, and the conversation, drawn as a grid of cells
|
|
6211
|
+
* beside a legend.
|
|
6212
|
+
*
|
|
6213
|
+
* {@link contextUsage} joins the token meter's per-node prices with the
|
|
6214
|
+
* transcript's surface mirror (`./compaction.ts`), so no historical event is
|
|
6215
|
+
* read again. The cells holding tokens the newest turn added are the hot
|
|
6216
|
+
* region. {@link ContextUsageBlock} fills the grid on open, sweeps a shimmer
|
|
6217
|
+
* through the hot region, blinks the first free cell, and re-reads the usage
|
|
6218
|
+
* while a turn runs; it then settles on the drawing
|
|
6219
|
+
* {@link contextUsageLines} returns at rest, which is also all a terminal
|
|
6220
|
+
* without motion draws. Every frame of one block at one width has the same
|
|
6221
|
+
* line count.
|
|
6222
|
+
* @module @deepseek-ai/dsh-tui-app/context-usage
|
|
6223
|
+
*/
|
|
6224
|
+
/** Every category, in the order the grid fills and the legend lists them. */
|
|
6225
|
+
const CONTEXT_CATEGORIES = [
|
|
6226
|
+
"system",
|
|
6227
|
+
"tools",
|
|
6228
|
+
"instructions",
|
|
6229
|
+
"skills",
|
|
6230
|
+
"context",
|
|
6231
|
+
"messages"
|
|
6232
|
+
];
|
|
6233
|
+
/** The legend label of each category. */
|
|
6234
|
+
const CATEGORY_LABEL = {
|
|
6235
|
+
system: "System prompt",
|
|
6236
|
+
tools: "System tools",
|
|
6237
|
+
instructions: "Instructions",
|
|
6238
|
+
skills: "Skills",
|
|
6239
|
+
context: "Injected context",
|
|
6240
|
+
messages: "Messages"
|
|
6241
|
+
};
|
|
6242
|
+
/**
|
|
6243
|
+
* Attribute every priced node to a category and to the hot region.
|
|
6244
|
+
* @param input - the measurement, the surface mirror, and the occupancy facts.
|
|
6245
|
+
* @returns the usage; a node the mirror does not name counts as `messages`.
|
|
6246
|
+
*/
|
|
6247
|
+
function contextUsage(input) {
|
|
6248
|
+
const named = new Map(input.surface.map((node) => [node.seq, node]));
|
|
6249
|
+
const tokens = /* @__PURE__ */ new Map();
|
|
6250
|
+
const hot = /* @__PURE__ */ new Map();
|
|
6251
|
+
tokens.set("tools", input.toolsTokens);
|
|
6252
|
+
for (const { seq, tokens: price } of input.priced) {
|
|
6253
|
+
const node = named.get(seq);
|
|
6254
|
+
const id = categoryOf(node);
|
|
6255
|
+
tokens.set(id, (tokens.get(id) ?? 0) + price);
|
|
6256
|
+
const fact = node?.fact;
|
|
6257
|
+
if (input.turn > 0 && fact !== void 0 && fact.kind !== "system" && fact.turn === input.turn) hot.set(id, (hot.get(id) ?? 0) + price);
|
|
6258
|
+
}
|
|
6259
|
+
const categories = CONTEXT_CATEGORIES.map((id) => ({
|
|
6260
|
+
id,
|
|
6261
|
+
tokens: tokens.get(id) ?? 0,
|
|
6262
|
+
hotTokens: hot.get(id) ?? 0
|
|
6263
|
+
}));
|
|
6264
|
+
const total = categories.reduce((sum, category) => sum + category.tokens, 0);
|
|
6265
|
+
return {
|
|
6266
|
+
model: input.model,
|
|
6267
|
+
used: input.used ?? total,
|
|
6268
|
+
...input.window === void 0 ? {} : { window: input.window },
|
|
6269
|
+
turn: input.turn,
|
|
6270
|
+
categories
|
|
6271
|
+
};
|
|
6272
|
+
}
|
|
6273
|
+
/**
|
|
6274
|
+
* The category one mirrored node belongs to.
|
|
6275
|
+
* @param node - the node, or undefined when the mirror does not hold it.
|
|
6276
|
+
* @returns the category.
|
|
6277
|
+
*/
|
|
6278
|
+
function categoryOf(node) {
|
|
6279
|
+
if (node === void 0) return "messages";
|
|
6280
|
+
const { fact } = node;
|
|
6281
|
+
switch (fact.kind) {
|
|
6282
|
+
case "system": return "system";
|
|
6283
|
+
case "context": return node.group ?? "context";
|
|
6284
|
+
case "prompt":
|
|
6285
|
+
case "summary":
|
|
6286
|
+
case "reply":
|
|
6287
|
+
case "result":
|
|
6288
|
+
case "developer": return "messages";
|
|
6289
|
+
/* v8 ignore next 2 -- closed-union exhaustiveness guard */
|
|
6290
|
+
default: return assertNever(fact, "surface fact");
|
|
6291
|
+
}
|
|
6292
|
+
}
|
|
6293
|
+
/** Cells per grid row when the width allows; narrower widths draw half as many. */
|
|
6294
|
+
const WIDE_GRID_COLUMNS = 20;
|
|
6295
|
+
/** Columns between the grid and the legend. */
|
|
6296
|
+
const LEGEND_GAP = 3;
|
|
6297
|
+
/**
|
|
6298
|
+
* Columns kept for the legend beside the grid. The layout depends on this
|
|
6299
|
+
* reserve rather than on the legend's own width, so a live re-read whose
|
|
6300
|
+
* numbers grow never moves the legend under the grid.
|
|
6301
|
+
*/
|
|
6302
|
+
const LEGEND_COLUMNS = 36;
|
|
6303
|
+
/** A used cell. */
|
|
6304
|
+
const FULL_GLYPH = "⛁";
|
|
6305
|
+
/** A free cell. */
|
|
6306
|
+
const FREE_GLYPH = "⛶";
|
|
6307
|
+
/** The hot-region marker in the legend. */
|
|
6308
|
+
const HOT_GLYPH = "▲";
|
|
6309
|
+
/**
|
|
6310
|
+
* Lay the usage out on {@link GRID_CELLS} cells: the used share of the
|
|
6311
|
+
* window split across the categories by their estimates, each category's hot
|
|
6312
|
+
* cells at its own end, then free space. A nonzero category always gets a
|
|
6313
|
+
* cell. Without a known window the categories share every cell.
|
|
6314
|
+
* @param usage - one read of the usage.
|
|
6315
|
+
* @returns the cells in fill order.
|
|
6316
|
+
*/
|
|
6317
|
+
function gridCells(usage) {
|
|
6318
|
+
const used = usage.categories.filter((category) => category.tokens > 0);
|
|
6319
|
+
const share = usage.window === void 0 ? 200 : Math.round(Math.min(1, usage.used / usage.window) * 200);
|
|
6320
|
+
const cells = [];
|
|
6321
|
+
const target = used.length === 0 ? 0 : Math.min(200, Math.max(share, used.length));
|
|
6322
|
+
for (const { category, count } of allocate(used, target)) {
|
|
6323
|
+
const hot = category.hotTokens === 0 ? 0 : Math.min(count, Math.max(1, Math.round(count * category.hotTokens / category.tokens)));
|
|
6324
|
+
for (let cell = 0; cell < count; cell++) cells.push({
|
|
6325
|
+
category: category.id,
|
|
6326
|
+
hot: cell >= count - hot
|
|
6327
|
+
});
|
|
6328
|
+
}
|
|
6329
|
+
while (cells.length < 200) cells.push(void 0);
|
|
6330
|
+
return cells;
|
|
6331
|
+
}
|
|
6332
|
+
/**
|
|
6333
|
+
* Split `target` cells across categories by tokens with the largest-remainder
|
|
6334
|
+
* rule, giving each category at least one cell.
|
|
6335
|
+
* @param categories - the categories with tokens, in fill order.
|
|
6336
|
+
* @param target - the cells to hand out; at least one per category, and 0 for none.
|
|
6337
|
+
* @returns one count per category, in the same order, summing to `target`.
|
|
6338
|
+
*/
|
|
6339
|
+
function allocate(categories, target) {
|
|
6340
|
+
const sum = categories.reduce((total, category) => total + category.tokens, 0);
|
|
6341
|
+
const shares = categories.map((category, index) => {
|
|
6342
|
+
const exact = category.tokens / sum * target;
|
|
6343
|
+
return {
|
|
6344
|
+
category,
|
|
6345
|
+
index,
|
|
6346
|
+
count: Math.max(1, Math.floor(exact)),
|
|
6347
|
+
remainder: exact - Math.floor(exact)
|
|
6348
|
+
};
|
|
6349
|
+
});
|
|
6350
|
+
let left = target - shares.reduce((total, entry) => total + entry.count, 0);
|
|
6351
|
+
const byRemainder = [...shares].sort((a, b) => b.remainder - a.remainder || a.index - b.index);
|
|
6352
|
+
while (left > 0) {
|
|
6353
|
+
for (const entry of byRemainder.slice(0, left)) entry.count++;
|
|
6354
|
+
left = target - shares.reduce((total, entry) => total + entry.count, 0);
|
|
6355
|
+
}
|
|
6356
|
+
while (left < 0) {
|
|
6357
|
+
const largest = shares.reduce((most, entry) => entry.count > most.count ? entry : most);
|
|
6358
|
+
largest.count--;
|
|
6359
|
+
left++;
|
|
6360
|
+
}
|
|
6361
|
+
return shares;
|
|
6362
|
+
}
|
|
6363
|
+
/** The resting drawing: every cell filled, no shimmer, no lit frontier. */
|
|
6364
|
+
const AT_REST = {
|
|
6365
|
+
fill: 1,
|
|
6366
|
+
frontier: false,
|
|
6367
|
+
live: false
|
|
6368
|
+
};
|
|
6369
|
+
/** Hot cells the shimmer's head travels past the region's end before it starts over. */
|
|
6370
|
+
const WAVE_TRAIL = 6;
|
|
6371
|
+
/**
|
|
6372
|
+
* Draw the report.
|
|
6373
|
+
* @param usage - one read of the usage.
|
|
6374
|
+
* @param palette - the terminal palette.
|
|
6375
|
+
* @param width - the columns the block lays out in.
|
|
6376
|
+
* @param frame - the animation frame; defaults to {@link AT_REST}.
|
|
6377
|
+
* @returns the lines, each at most `width` columns, as many for every frame
|
|
6378
|
+
* and usage at one width.
|
|
6379
|
+
*/
|
|
6380
|
+
function contextUsageLines(usage, palette, width, frame = AT_REST) {
|
|
6381
|
+
const columns = width >= gridWidth(WIDE_GRID_COLUMNS) ? WIDE_GRID_COLUMNS : WIDE_GRID_COLUMNS / 2;
|
|
6382
|
+
const grid = gridRows(gridCells(usage), columns, palette, frame);
|
|
6383
|
+
const legend = legendRows(usage, palette, frame);
|
|
6384
|
+
const left = gridWidth(columns);
|
|
6385
|
+
const body = width >= left + LEGEND_GAP + LEGEND_COLUMNS ? legend.map((entry, row) => {
|
|
6386
|
+
const cells = grid[row] ?? " ".repeat(left);
|
|
6387
|
+
return entry === "" ? cells : `${cells}${" ".repeat(LEGEND_GAP)}${entry}`;
|
|
6388
|
+
}) : [
|
|
6389
|
+
...grid,
|
|
6390
|
+
"",
|
|
6391
|
+
...legend
|
|
6392
|
+
];
|
|
6393
|
+
return [
|
|
6394
|
+
"",
|
|
6395
|
+
palette.bold("Context usage"),
|
|
6396
|
+
...body,
|
|
6397
|
+
""
|
|
6398
|
+
].map((line) => truncateToWidth(line, width, "…"));
|
|
6399
|
+
}
|
|
6400
|
+
/**
|
|
6401
|
+
* Columns one grid row takes.
|
|
6402
|
+
* @param columns - cells per row.
|
|
6403
|
+
* @returns the width, one space between each two cells.
|
|
6404
|
+
*/
|
|
6405
|
+
function gridWidth(columns) {
|
|
6406
|
+
return columns * 2 - 1;
|
|
6407
|
+
}
|
|
6408
|
+
/**
|
|
6409
|
+
* The grid rows of one frame.
|
|
6410
|
+
* @param cells - the laid-out cells.
|
|
6411
|
+
* @param columns - cells per row.
|
|
6412
|
+
* @param palette - the terminal palette.
|
|
6413
|
+
* @param frame - the animation frame.
|
|
6414
|
+
* @returns the rows.
|
|
6415
|
+
*/
|
|
6416
|
+
function gridRows(cells, columns, palette, frame) {
|
|
6417
|
+
const usedCount = cells.filter((cell) => cell !== void 0).length;
|
|
6418
|
+
const hotCount = cells.filter((cell) => cell?.hot === true).length;
|
|
6419
|
+
const filled = Math.ceil(Math.min(1, Math.max(0, frame.fill)) * usedCount);
|
|
6420
|
+
const head = frame.wave === void 0 || hotCount === 0 ? void 0 : frame.wave % (hotCount + WAVE_TRAIL);
|
|
6421
|
+
const drawn = [];
|
|
6422
|
+
let used = 0;
|
|
6423
|
+
let hot = 0;
|
|
6424
|
+
for (const [index, cell] of cells.entries()) {
|
|
6425
|
+
if (cell === void 0 || used >= filled) {
|
|
6426
|
+
const lit = frame.frontier && index === usedCount && filled === usedCount;
|
|
6427
|
+
drawn.push(lit ? palette.bold(palette.accent(FREE_GLYPH)) : palette.dim(FREE_GLYPH));
|
|
6428
|
+
if (cell !== void 0) used++;
|
|
6429
|
+
continue;
|
|
6430
|
+
}
|
|
6431
|
+
used++;
|
|
6432
|
+
const color = categoryStyle(palette, cell.category);
|
|
6433
|
+
if (!cell.hot) {
|
|
6434
|
+
drawn.push(color(FULL_GLYPH));
|
|
6435
|
+
continue;
|
|
6436
|
+
}
|
|
6437
|
+
drawn.push(hotCell(palette, color, head === void 0 ? void 0 : head - hot));
|
|
6438
|
+
hot++;
|
|
6439
|
+
}
|
|
6440
|
+
const rows = [];
|
|
6441
|
+
for (let start = 0; start < drawn.length; start += columns) rows.push(drawn.slice(start, start + columns).join(" "));
|
|
6442
|
+
return rows;
|
|
6443
|
+
}
|
|
6444
|
+
/**
|
|
6445
|
+
* One hot cell: bold at rest; under the shimmer, inverse at the head, bold
|
|
6446
|
+
* in the two cells behind it, and plain elsewhere, so a bright band sweeps
|
|
6447
|
+
* through the region.
|
|
6448
|
+
* @param palette - the terminal palette.
|
|
6449
|
+
* @param color - the cell's category color.
|
|
6450
|
+
* @param behind - how many cells the shimmer's head is past this cell; undefined at rest.
|
|
6451
|
+
* @returns the drawn cell.
|
|
6452
|
+
*/
|
|
6453
|
+
function hotCell(palette, color, behind) {
|
|
6454
|
+
if (behind === void 0) return palette.bold(color(FULL_GLYPH));
|
|
6455
|
+
if (behind === 0) return palette.inverse(palette.bold(color(FULL_GLYPH)));
|
|
6456
|
+
if (behind === 1 || behind === 2) return palette.bold(color(FULL_GLYPH));
|
|
6457
|
+
return color(FULL_GLYPH);
|
|
6458
|
+
}
|
|
6459
|
+
/**
|
|
6460
|
+
* The legend rows: the model, the occupancy, the hot region, then one row per
|
|
6461
|
+
* category and the free space. The row count never depends on the usage.
|
|
6462
|
+
* @param usage - one read of the usage.
|
|
6463
|
+
* @param palette - the terminal palette.
|
|
6464
|
+
* @param frame - the animation frame, which marks a live read.
|
|
6465
|
+
* @returns the rows.
|
|
6466
|
+
*/
|
|
6467
|
+
function legendRows(usage, palette, frame) {
|
|
6468
|
+
const { window, used } = usage;
|
|
6469
|
+
const occupancy = window === void 0 ? `${formatTokens(used)} tokens · window not reported yet` : `${formatTokens(used)}/${formatTokens(window)} tokens (${percent(used / window, true)})`;
|
|
6470
|
+
const share = (tokens) => {
|
|
6471
|
+
const base = window ?? usage.categories.reduce((sum, category) => sum + category.tokens, 0);
|
|
6472
|
+
return base > 0 ? ` (${percent(tokens / base, false)})` : "";
|
|
6473
|
+
};
|
|
6474
|
+
const rows = [
|
|
6475
|
+
palette.bold(usage.model),
|
|
6476
|
+
occupancy,
|
|
6477
|
+
hotRow(usage, palette, frame),
|
|
6478
|
+
"",
|
|
6479
|
+
palette.dim(palette.italic("Estimated usage by category")),
|
|
6480
|
+
...usage.categories.map((category) => `${categoryStyle(palette, category.id)(FULL_GLYPH)} ${CATEGORY_LABEL[category.id]}: ${formatTokens(category.tokens)} tokens${share(category.tokens)}`)
|
|
6481
|
+
];
|
|
6482
|
+
rows.push(window === void 0 ? `${palette.dim(FREE_GLYPH)} Free space: unknown` : `${palette.dim(FREE_GLYPH)} Free space: ${formatTokens(Math.max(0, window - used))}${share(Math.max(0, window - used))}`);
|
|
6483
|
+
return rows;
|
|
6484
|
+
}
|
|
6485
|
+
/**
|
|
6486
|
+
* The hot-region row.
|
|
6487
|
+
* @param usage - one read of the usage.
|
|
6488
|
+
* @param palette - the terminal palette.
|
|
6489
|
+
* @param frame - the animation frame.
|
|
6490
|
+
* @returns e.g. `▲ hot: +2.1k tokens in turn 3 · live`.
|
|
6491
|
+
*/
|
|
6492
|
+
function hotRow(usage, palette, frame) {
|
|
6493
|
+
const live = frame.live ? palette.dim(" · live") : "";
|
|
6494
|
+
if (usage.turn === 0) return palette.dim(`${HOT_GLYPH} hot: no turn yet`) + live;
|
|
6495
|
+
const tokens = usage.categories.reduce((sum, category) => sum + category.hotTokens, 0);
|
|
6496
|
+
if (tokens === 0) return palette.dim(`${HOT_GLYPH} hot: nothing added in turn ${String(usage.turn)}`) + live;
|
|
6497
|
+
return `${palette.bold(palette.error(HOT_GLYPH))} hot: +${formatTokens(tokens)} tokens in turn ${String(usage.turn)}${live}`;
|
|
6498
|
+
}
|
|
6499
|
+
/**
|
|
6500
|
+
* The color one category draws in.
|
|
6501
|
+
* @param palette - the terminal palette.
|
|
6502
|
+
* @param id - the category.
|
|
6503
|
+
* @returns its style.
|
|
6504
|
+
*/
|
|
6505
|
+
function categoryStyle(palette, id) {
|
|
6506
|
+
switch (id) {
|
|
6507
|
+
case "system": return palette.hue.blue;
|
|
6508
|
+
case "tools": return palette.hue.cyan;
|
|
6509
|
+
case "instructions": return palette.hue.orange;
|
|
6510
|
+
case "skills": return palette.hue.yellow;
|
|
6511
|
+
case "context": return palette.hue.green;
|
|
6512
|
+
case "messages": return palette.hue.magenta;
|
|
6513
|
+
/* v8 ignore next 2 -- closed-union exhaustiveness guard */
|
|
6514
|
+
default: return assertNever(id, "context category");
|
|
6515
|
+
}
|
|
6516
|
+
}
|
|
6517
|
+
/**
|
|
6518
|
+
* A ratio as a percentage to one decimal, dropping a trailing `.0` from 10% up.
|
|
6519
|
+
* @param ratio - the share, from 0.
|
|
6520
|
+
* @param whole - round to a whole number, as the occupancy does.
|
|
6521
|
+
* @returns e.g. `0.0%`, `0.2%`, `98.8%`, `100%`.
|
|
6522
|
+
*/
|
|
6523
|
+
function percent(ratio, whole) {
|
|
6524
|
+
const value = ratio * 100;
|
|
6525
|
+
if (whole) return `${String(Math.round(value))}%`;
|
|
6526
|
+
const tenths = Math.round(value * 10) / 10;
|
|
6527
|
+
return tenths >= 10 && Number.isInteger(tenths) ? `${String(tenths)}%` : `${tenths.toFixed(1)}%`;
|
|
6528
|
+
}
|
|
6529
|
+
/** Milliseconds the grid takes to fill on open. */
|
|
6530
|
+
const FILL_MS = 480;
|
|
6531
|
+
/** Milliseconds the hot region shimmers after open before a settled turn lets the block rest. */
|
|
6532
|
+
const SHIMMER_MS = 3200;
|
|
6533
|
+
/** Milliseconds per shimmer step. */
|
|
6534
|
+
const WAVE_STEP_MS = 70;
|
|
6535
|
+
/** Milliseconds the first free cell stays lit, then dark, while live. */
|
|
6536
|
+
const BLINK_MS = 400;
|
|
6537
|
+
/** Milliseconds between re-reads of the usage. */
|
|
6538
|
+
const REFRESH_MS = 250;
|
|
6539
|
+
/**
|
|
6540
|
+
* The `/context` transcript block. While it moves it is a
|
|
6541
|
+
* {@link RegisteredFade}: the application calls {@link ContextUsageBlock.tick}
|
|
6542
|
+
* on each fade period, and it settles once the open animation ran and no
|
|
6543
|
+
* turn runs, when it is retired, or once every row left the repaint window.
|
|
6544
|
+
* Rows above the repaint floor keep the text last drawn there.
|
|
6545
|
+
*/
|
|
6546
|
+
var ContextUsageBlock = class {
|
|
6547
|
+
palette;
|
|
6548
|
+
options;
|
|
6549
|
+
usage;
|
|
6550
|
+
frame;
|
|
6551
|
+
bornAt;
|
|
6552
|
+
refreshedAt;
|
|
6553
|
+
settled;
|
|
6554
|
+
floor = 0;
|
|
6555
|
+
shown;
|
|
6556
|
+
memo;
|
|
6557
|
+
/**
|
|
6558
|
+
* @param palette - the terminal palette.
|
|
6559
|
+
* @param options - the usage reader, the live check, and the clock.
|
|
6560
|
+
*/
|
|
6561
|
+
constructor(palette, options) {
|
|
6562
|
+
this.palette = palette;
|
|
6563
|
+
this.options = options;
|
|
6564
|
+
this.usage = options.read();
|
|
6565
|
+
const now = options.now?.();
|
|
6566
|
+
this.bornAt = now ?? 0;
|
|
6567
|
+
this.refreshedAt = this.bornAt;
|
|
6568
|
+
this.settled = now === void 0;
|
|
6569
|
+
this.frame = this.settled ? AT_REST : frameAt(0, options.live());
|
|
6570
|
+
}
|
|
6571
|
+
/** @returns true until the block settled. */
|
|
6572
|
+
needsRepaint() {
|
|
6573
|
+
return !this.settled;
|
|
6574
|
+
}
|
|
6575
|
+
/** Advance one fade period: re-read the usage when it is due, then move the animation or settle. */
|
|
6576
|
+
tick() {
|
|
6577
|
+
const clock = this.options.now;
|
|
6578
|
+
if (this.settled || clock === void 0) return;
|
|
6579
|
+
const now = clock();
|
|
6580
|
+
const live = this.options.live();
|
|
6581
|
+
if (!live && now - this.bornAt >= SHIMMER_MS) {
|
|
6582
|
+
this.usage = this.options.read();
|
|
6583
|
+
this.rest();
|
|
6584
|
+
return;
|
|
6585
|
+
}
|
|
6586
|
+
if (now - this.refreshedAt >= REFRESH_MS) {
|
|
6587
|
+
this.usage = this.options.read();
|
|
6588
|
+
this.refreshedAt = now;
|
|
6589
|
+
}
|
|
6590
|
+
const next = frameAt(now - this.bornAt, live);
|
|
6591
|
+
if (frameKey(next) !== frameKey(this.frame)) this.frame = next;
|
|
6592
|
+
}
|
|
6593
|
+
/** Settle on the last read without reading again, for a session switch or a newer `/context`. */
|
|
6594
|
+
retire() {
|
|
6595
|
+
this.rest();
|
|
6596
|
+
}
|
|
6597
|
+
/**
|
|
6598
|
+
* Hold the rows the renderer can no longer repaint.
|
|
6599
|
+
* @param floor - the first block line the renderer may repaint.
|
|
6600
|
+
*/
|
|
6601
|
+
setRepaintFloor(floor) {
|
|
6602
|
+
this.floor = floor;
|
|
6603
|
+
if (this.shown !== void 0 && floor >= this.shown.lines.length) this.rest();
|
|
6604
|
+
}
|
|
6605
|
+
invalidate() {
|
|
6606
|
+
this.memo = void 0;
|
|
6607
|
+
}
|
|
6608
|
+
render(width) {
|
|
6609
|
+
const memo = this.memo;
|
|
6610
|
+
if (memo?.width === width && memo.usage === this.usage && memo.frame === this.frame && memo.floor === this.floor) return memo.lines;
|
|
6611
|
+
const lines = contextUsageLines(this.usage, this.palette, width, this.frame);
|
|
6612
|
+
const shown = this.shown;
|
|
6613
|
+
if (shown?.width === width) {
|
|
6614
|
+
const held = Math.min(this.floor, lines.length, shown.lines.length);
|
|
6615
|
+
lines.splice(0, held, ...shown.lines.slice(0, held));
|
|
6616
|
+
}
|
|
6617
|
+
this.shown = {
|
|
6618
|
+
width,
|
|
6619
|
+
lines
|
|
6620
|
+
};
|
|
6621
|
+
this.memo = {
|
|
6622
|
+
width,
|
|
6623
|
+
usage: this.usage,
|
|
6624
|
+
frame: this.frame,
|
|
6625
|
+
floor: this.floor,
|
|
6626
|
+
lines
|
|
6627
|
+
};
|
|
6628
|
+
return lines;
|
|
6629
|
+
}
|
|
6630
|
+
rest() {
|
|
6631
|
+
this.settled = true;
|
|
6632
|
+
this.frame = AT_REST;
|
|
6633
|
+
}
|
|
6634
|
+
};
|
|
6635
|
+
/**
|
|
6636
|
+
* The animation frame at one moment after open.
|
|
6637
|
+
* @param elapsed - milliseconds since the block opened.
|
|
6638
|
+
* @param live - whether a turn runs.
|
|
6639
|
+
* @returns the frame.
|
|
6640
|
+
*/
|
|
6641
|
+
function frameAt(elapsed, live) {
|
|
6642
|
+
return {
|
|
6643
|
+
fill: Math.min(1, elapsed / FILL_MS),
|
|
6644
|
+
wave: Math.floor(elapsed / WAVE_STEP_MS),
|
|
6645
|
+
frontier: live && Math.floor(elapsed / BLINK_MS) % 2 === 0,
|
|
6646
|
+
live
|
|
6647
|
+
};
|
|
6648
|
+
}
|
|
6649
|
+
/**
|
|
6650
|
+
* A key equal for exactly the frames that draw the same.
|
|
6651
|
+
* @param frame - the frame.
|
|
6652
|
+
* @returns its fields joined.
|
|
6653
|
+
*/
|
|
6654
|
+
function frameKey(frame) {
|
|
6655
|
+
return `${String(frame.fill)}|${String(frame.wave)}|${String(frame.frontier)}|${String(frame.live)}`;
|
|
6656
|
+
}
|
|
6657
|
+
//#endregion
|
|
6140
6658
|
//#region lib/types/workflow-panel.js
|
|
6141
6659
|
/**
|
|
6142
6660
|
* Rows of the `/workflows` pickers: one row per workflow run of the bound
|
|
@@ -6363,6 +6881,19 @@ function injectedContextTitle(source) {
|
|
|
6363
6881
|
const context = contextSource(source);
|
|
6364
6882
|
return context === void 0 ? void 0 : contextTitle(context);
|
|
6365
6883
|
}
|
|
6884
|
+
/** Source kinds the skill packages stamp on their catalog and on an invoked skill's body. */
|
|
6885
|
+
const SKILL_KINDS = ["skill-catalog", "skill-invocation"];
|
|
6886
|
+
/**
|
|
6887
|
+
* Attribute one injected `user/message` to a {@link ContextGroup}.
|
|
6888
|
+
* @param source - the message's durable source.
|
|
6889
|
+
* @returns the group, or undefined when this message is not injected context.
|
|
6890
|
+
*/
|
|
6891
|
+
function contextGroup(source) {
|
|
6892
|
+
const context = contextSource(source);
|
|
6893
|
+
if (context === void 0) return void 0;
|
|
6894
|
+
if (SKILL_KINDS.includes(context.kind)) return "skills";
|
|
6895
|
+
return context.form === "instructions" ? "instructions" : "context";
|
|
6896
|
+
}
|
|
6366
6897
|
/**
|
|
6367
6898
|
* Narrow a message source to injected context.
|
|
6368
6899
|
* @param source - the message's durable source.
|
|
@@ -10076,7 +10607,7 @@ function unfocusedLine(segments, palette, width, queue) {
|
|
|
10076
10607
|
return palette.dim(segment.label);
|
|
10077
10608
|
});
|
|
10078
10609
|
const drawn = middleFacts(facts, rest.length - facts.length, width - visibleWidth(model) - reserved);
|
|
10079
|
-
const left = [model === "" ? "" : palette.
|
|
10610
|
+
const left = [model === "" ? "" : palette.model(model), ...drawn].filter((token) => token !== "").join(palette.dim(SEPARATOR$2));
|
|
10080
10611
|
if (hint === "") return fitLine(left, width);
|
|
10081
10612
|
return fitLine(`${left}${" ".repeat(Math.max(1, width - visibleWidth(left) - visibleWidth(hint)))}${paintKeys(palette, hint, palette.link)}`, width);
|
|
10082
10613
|
}
|
|
@@ -10668,7 +11199,7 @@ function sectionName(block, part) {
|
|
|
10668
11199
|
function restingHeader(block, part, palette) {
|
|
10669
11200
|
const glyph = sectionGlyph(block, part);
|
|
10670
11201
|
const name = sectionName(block, part);
|
|
10671
|
-
if (block.blockKind === "tool" && part.kind === "call") return `${(settledTool(block) ? palette.success : palette.warning)(glyph)} ${palette.bold(block.name)}${palette.
|
|
11202
|
+
if (block.blockKind === "tool" && part.kind === "call") return `${(settledTool(block) ? palette.success : palette.warning)(glyph)} ${palette.bold(palette.tool(block.name))}${palette.subject(name.slice(block.name.length))}`;
|
|
10672
11203
|
if (block.blockKind === "assistant" && part.kind === "reply") return `${palette.accent(glyph)} ${name}`;
|
|
10673
11204
|
return palette.dim(`${glyph} ${name}`);
|
|
10674
11205
|
}
|
|
@@ -12272,8 +12803,7 @@ function resolveColorDepth(input) {
|
|
|
12272
12803
|
if (!input.paletteEnabled) return "none";
|
|
12273
12804
|
const term = input.env.TERM ?? "";
|
|
12274
12805
|
if (term === "dumb") return "none";
|
|
12275
|
-
|
|
12276
|
-
if (colorterm === "truecolor" || colorterm === "24bit") return "truecolor";
|
|
12806
|
+
if (declaresTruecolor(input.env)) return "truecolor";
|
|
12277
12807
|
return term.includes("256color") ? "ansi256" : "none";
|
|
12278
12808
|
}
|
|
12279
12809
|
/**
|
|
@@ -12827,6 +13357,13 @@ var CompactionLedger = class {
|
|
|
12827
13357
|
constructor(estimate) {
|
|
12828
13358
|
this.estimate = estimate;
|
|
12829
13359
|
}
|
|
13360
|
+
/**
|
|
13361
|
+
* The mirrored surface as it stands now.
|
|
13362
|
+
* @returns the nodes in surface order; the array is the ledger's own and changes with the next observed event.
|
|
13363
|
+
*/
|
|
13364
|
+
surface() {
|
|
13365
|
+
return this.nodes;
|
|
13366
|
+
}
|
|
12830
13367
|
/** Forget the mirrored surface and every open transaction. */
|
|
12831
13368
|
clear() {
|
|
12832
13369
|
this.nodes.length = 0;
|
|
@@ -12858,9 +13395,15 @@ var CompactionLedger = class {
|
|
|
12858
13395
|
default: break;
|
|
12859
13396
|
}
|
|
12860
13397
|
if (!isSurfaceEvent(event)) return void 0;
|
|
12861
|
-
const
|
|
13398
|
+
const fact = this.factOf(event, turn);
|
|
13399
|
+
const group = fact.kind === "context" && event.type === "user/message" ? contextGroup(event.data.source) : void 0;
|
|
13400
|
+
const node = group === void 0 ? {
|
|
13401
|
+
seq: event.seq,
|
|
13402
|
+
fact
|
|
13403
|
+
} : {
|
|
12862
13404
|
seq: event.seq,
|
|
12863
|
-
fact
|
|
13405
|
+
fact,
|
|
13406
|
+
group
|
|
12864
13407
|
};
|
|
12865
13408
|
if (event.surfaceOp === "append") {
|
|
12866
13409
|
this.nodes.push(node);
|
|
@@ -13674,6 +14217,10 @@ const LOCAL_COMMANDS = [
|
|
|
13674
14217
|
name: "status",
|
|
13675
14218
|
description: "Show context usage, token totals, session stats, todos, goal, plan, and permission"
|
|
13676
14219
|
},
|
|
14220
|
+
{
|
|
14221
|
+
name: "context",
|
|
14222
|
+
description: "Show how the context window is used right now, by category, with the newest turn's tokens highlighted"
|
|
14223
|
+
},
|
|
13677
14224
|
{
|
|
13678
14225
|
name: "todos",
|
|
13679
14226
|
description: "Browse the agent's todo list (Enter shows one item in full)"
|
|
@@ -13950,6 +14497,8 @@ var TuiApp = class {
|
|
|
13950
14497
|
* terminal that fades nothing.
|
|
13951
14498
|
*/
|
|
13952
14499
|
motions = new FadeRegistry();
|
|
14500
|
+
/** The newest `/context` block while it still animates or re-reads. */
|
|
14501
|
+
contextUsageBlock;
|
|
13953
14502
|
/** The transient line on screen right now, with the clock that takes it down. */
|
|
13954
14503
|
toast;
|
|
13955
14504
|
/** The chrome motion running right now, and how much of the focused surface it lifts. */
|
|
@@ -14308,6 +14857,7 @@ var TuiApp = class {
|
|
|
14308
14857
|
this.streaming = void 0;
|
|
14309
14858
|
this.endFade();
|
|
14310
14859
|
this.blockFades.clear();
|
|
14860
|
+
this.retireContextUsage();
|
|
14311
14861
|
this.usage = EMPTY_USAGE;
|
|
14312
14862
|
this.clearLiveUsage();
|
|
14313
14863
|
this.pending = [];
|
|
@@ -15543,6 +16093,54 @@ var TuiApp = class {
|
|
|
15543
16093
|
showStatus() {
|
|
15544
16094
|
this.showBlock(statusReport(this.statusFacts()));
|
|
15545
16095
|
}
|
|
16096
|
+
/**
|
|
16097
|
+
* Print the `/context` report for the bound session. It animates on a
|
|
16098
|
+
* terminal that runs motion, and re-reads the usage while a turn runs; a
|
|
16099
|
+
* newer report or a session switch settles the one before it.
|
|
16100
|
+
*/
|
|
16101
|
+
showContextUsage() {
|
|
16102
|
+
const meter = this.deps.ctx.get("tokenMeter");
|
|
16103
|
+
if (meter === void 0) {
|
|
16104
|
+
this.notice("/context needs the token meter in this composition", "error");
|
|
16105
|
+
return;
|
|
16106
|
+
}
|
|
16107
|
+
this.retireContextUsage();
|
|
16108
|
+
const bound = this.bound;
|
|
16109
|
+
const read = () => {
|
|
16110
|
+
const { session } = bound.agent;
|
|
16111
|
+
const projections = this.deps.ctx.get("sessionProjections");
|
|
16112
|
+
const facts = projections === void 0 ? {} : readStatusFacts(projections, session);
|
|
16113
|
+
const selection = this.currentSelection(bound);
|
|
16114
|
+
const window = facts.context?.window ?? session.requestContext()?.contextWindow;
|
|
16115
|
+
return contextUsage({
|
|
16116
|
+
model: `${selection.provider}/${selection.model}`,
|
|
16117
|
+
turn: this.turn,
|
|
16118
|
+
priced: meter.measure(session).nodes,
|
|
16119
|
+
surface: this.compactions.surface(),
|
|
16120
|
+
toolsTokens: facts.breakdown?.toolsTokens ?? 0,
|
|
16121
|
+
...facts.context === void 0 ? {} : { used: facts.context.used },
|
|
16122
|
+
...window === void 0 ? {} : { window }
|
|
16123
|
+
});
|
|
16124
|
+
};
|
|
16125
|
+
const animate = this.fading && !this.deps.reducedMotion;
|
|
16126
|
+
const block = new ContextUsageBlock(this.deps.palette, {
|
|
16127
|
+
read,
|
|
16128
|
+
live: () => this.turnStartedAt !== void 0,
|
|
16129
|
+
...animate ? { now: () => this.deps.now() } : {}
|
|
16130
|
+
});
|
|
16131
|
+
this.chat.addChild(block);
|
|
16132
|
+
if (block.needsRepaint()) {
|
|
16133
|
+
this.contextUsageBlock = block;
|
|
16134
|
+
this.motions.add(block);
|
|
16135
|
+
this.updateFadeTicker();
|
|
16136
|
+
}
|
|
16137
|
+
this.tui.requestRender();
|
|
16138
|
+
}
|
|
16139
|
+
/** Settle the running `/context` block, if any, on what it last read. */
|
|
16140
|
+
retireContextUsage() {
|
|
16141
|
+
this.contextUsageBlock?.retire();
|
|
16142
|
+
this.contextUsageBlock = void 0;
|
|
16143
|
+
}
|
|
15546
16144
|
currentSelection(bound = this.bound) {
|
|
15547
16145
|
const { selection, agent } = bound;
|
|
15548
16146
|
const selected = selection.current ?? agent.session.requestHeader()?.config;
|
|
@@ -16666,6 +17264,9 @@ var TuiApp = class {
|
|
|
16666
17264
|
case "status":
|
|
16667
17265
|
this.showStatus();
|
|
16668
17266
|
return;
|
|
17267
|
+
case "context":
|
|
17268
|
+
this.showContextUsage();
|
|
17269
|
+
return;
|
|
16669
17270
|
case "todos":
|
|
16670
17271
|
await this.browseTodos();
|
|
16671
17272
|
return;
|
|
@@ -17753,6 +18354,7 @@ var TuiApp = class {
|
|
|
17753
18354
|
if (child instanceof WorkflowBlock) {
|
|
17754
18355
|
if (child.setRepaintFloor(repaintFloor(start, viewportTop))) changed = true;
|
|
17755
18356
|
}
|
|
18357
|
+
if (child instanceof ContextUsageBlock) child.setRepaintFloor(repaintFloor(start, viewportTop));
|
|
17756
18358
|
if (fades && (child instanceof AssistantBlock || child instanceof ToolBlock)) {
|
|
17757
18359
|
if (child.setRepaintFloor(repaintFloor(start, viewportTop))) changed = true;
|
|
17758
18360
|
}
|
|
@@ -17781,6 +18383,8 @@ var TuiApp = class {
|
|
|
17781
18383
|
if (this.toast?.clock.expired() === true) this.hideToast();
|
|
17782
18384
|
if (this.panelLift !== this.panelLiftNow()) this.refreshSubagentPanel();
|
|
17783
18385
|
if (this.activitySlot.children.length > 0) this.refreshActivityBoard();
|
|
18386
|
+
this.contextUsageBlock?.tick();
|
|
18387
|
+
if (this.contextUsageBlock?.needsRepaint() === false) this.contextUsageBlock = void 0;
|
|
17784
18388
|
this.motions.tick();
|
|
17785
18389
|
this.tui.requestRender();
|
|
17786
18390
|
this.updateFadeTicker();
|
|
@@ -18590,6 +19194,7 @@ const internals = {
|
|
|
18590
19194
|
},
|
|
18591
19195
|
stderr: process.stderr,
|
|
18592
19196
|
color: colorEnabled(process.env, process.stdout.isTTY),
|
|
19197
|
+
depth: paletteDepth(process.env),
|
|
18593
19198
|
canOpenUrl: () => canOpenNativePath(),
|
|
18594
19199
|
openUrl: openNativeUrl
|
|
18595
19200
|
};
|
|
@@ -18841,7 +19446,7 @@ async function run(ctx, config, host) {
|
|
|
18841
19446
|
host: sessions,
|
|
18842
19447
|
initial,
|
|
18843
19448
|
terminal: host.createTerminal(),
|
|
18844
|
-
palette: createPalette(host.color, config.mouse),
|
|
19449
|
+
palette: createPalette(host.color, config.mouse, host.depth),
|
|
18845
19450
|
toolPreviewLines: config.toolPreviewLines,
|
|
18846
19451
|
contextPreviewLines: config.contextPreviewLines,
|
|
18847
19452
|
focusPreviewLines: config.focusPreviewLines,
|
|
@@ -18900,6 +19505,7 @@ function apply(ctx, config) {
|
|
|
18900
19505
|
releaseInput: internals.releaseInput,
|
|
18901
19506
|
stderr: internals.stderr,
|
|
18902
19507
|
color: internals.color,
|
|
19508
|
+
depth: internals.depth,
|
|
18903
19509
|
canOpenUrl: internals.canOpenUrl,
|
|
18904
19510
|
openUrl: internals.openUrl,
|
|
18905
19511
|
exit
|