@songtonyli/dsh-cli 0.1.13 → 0.1.15

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.
@@ -1014,6 +1014,10 @@ const LUMINANCE = {
1014
1014
  };
1015
1015
  /** Largest value one color channel encodes. */
1016
1016
  const CHANNEL_MAX = 255;
1017
+ /** Channel scale SGR faint applies when a float-out reads a dim run. */
1018
+ const DIM_CHANNEL = .5;
1019
+ /** How far a float-out lifts a color that is already brighter than `fg` toward white. */
1020
+ const LIFT_TOWARD_WHITE = .5;
1017
1021
  /** Encoded sRGB value below which the transfer function is the linear segment. */
1018
1022
  const SRGB_LINEAR_CUT = .04045;
1019
1023
  /** Linear intensity below which the sRGB transfer function is the linear segment. */
@@ -1093,6 +1097,34 @@ function mix(from, to, ratio) {
1093
1097
  return toSrgb(linear + (toLinear(to) - linear) * ratio);
1094
1098
  }
1095
1099
  /**
1100
+ * Mix `from` toward `to` with the same smoothstep-in-linear-light interpolation
1101
+ * {@link buildFadeRamp} uses. Positions at or below 0 and at or above 1 return
1102
+ * that endpoint's bytes, so a float-out's last computed mix can match the
1103
+ * settled color it recedes toward.
1104
+ * @param from - the color at t = 0.
1105
+ * @param to - the color at t = 1.
1106
+ * @param t - position along the mix; values outside 0..1 clamp to an endpoint.
1107
+ * @returns the mixed sRGB color.
1108
+ */
1109
+ function mixFadeColor(from, to, t) {
1110
+ if (t <= 0) return {
1111
+ r: from.r,
1112
+ g: from.g,
1113
+ b: from.b
1114
+ };
1115
+ if (t >= 1) return {
1116
+ r: to.r,
1117
+ g: to.g,
1118
+ b: to.b
1119
+ };
1120
+ const eased = t * t * (3 - 2 * t);
1121
+ return {
1122
+ r: mix(from.r, to.r, eased),
1123
+ g: mix(from.g, to.g, eased),
1124
+ b: mix(from.b, to.b, eased)
1125
+ };
1126
+ }
1127
+ /**
1096
1128
  * Decode one sRGB channel to linear light, by the sRGB transfer function.
1097
1129
  * @param value - the channel byte.
1098
1130
  * @returns the linear intensity in 0..1.
@@ -1121,7 +1153,7 @@ function toSrgb(value) {
1121
1153
  function fadeSgr(style, age) {
1122
1154
  if (style.capability === "none") return "";
1123
1155
  if (style.capability === "dim") return age < DIM_AGES ? DIM : "";
1124
- const level = style.ramp[Math.max(0, Math.min(age, style.ramp.length - 1))];
1156
+ const level = style.ramp[Math.max(0, Math.min(Math.floor(age), style.ramp.length - 1))];
1125
1157
  if (level === void 0) return "";
1126
1158
  return style.capability === "truecolor" ? truecolorSgr(level) : grayscaleSgr(level);
1127
1159
  }
@@ -1163,31 +1195,340 @@ function restoreFor(capability) {
1163
1195
  /** Every SGR sequence, the sequences a block's own palette styling writes. */
1164
1196
  const SGR_SEQUENCE = /\u001b\[[0-9;]*m/g;
1165
1197
  /**
1166
- * Draw whole rendered lines at one brightness level, for a block that fades in
1167
- * as a unit rather than word by word.
1198
+ * Draw whole rendered lines as a float-out: each SGR run starts at a lifted
1199
+ * mix toward the assumed foreground and recedes to the run's own settled
1200
+ * color. At `age >= ramp.length` the lines come back byte-identical, so the
1201
+ * palette sequences win without a snap. The two-level mode overlays faint for
1202
+ * the whole flight; the caller stops invoking this once the clock settles.
1168
1203
  *
1169
- * The level is opened at the start of the line and reasserted after every SGR
1170
- * the line already carries, so the palette colors inside a card - the status
1171
- * glyph, the dim body rule, the bold tool name - are overridden while the card
1172
- * fades and come back on their own once it settles. Each line ends with the
1173
- * sequence that undoes what the level set - the terminal's own foreground, or
1174
- * its normal intensity in the two-level mode - so the level never leaks past
1175
- * the line it was applied to. Empty lines come back byte-identical, so
1176
- * the renderer leaves the blank rows around a card alone.
1204
+ * The mix is opened after every SGR the line already carries, so the status
1205
+ * glyph, the dim body rule, and the bold tool name each recede toward their
1206
+ * own color. Each line ends with the sequence that undoes the overlay, so the
1207
+ * mix never leaks past the line it was applied to. Empty lines come back
1208
+ * byte-identical, so the renderer leaves the blank rows around a card alone.
1177
1209
  * @param lines - the rendered lines of the block.
1178
- * @param age - the brightness level to draw them at.
1179
- * @param style - the capability and the ramp.
1180
- * @param from - first line the level is applied to; the lines before it come
1210
+ * @param age - elapsed time in units of `stepMs`; `ramp.length` is t = 1.
1211
+ * @param style - the capability and the ramp whose last level is the assumed foreground.
1212
+ * @param from - first line the mix is applied to; the lines before it come
1181
1213
  * back byte-identical, which is how a caller keeps rows the renderer can no
1182
1214
  * longer repaint out of the fade.
1183
- * @returns the lines at that level; copies when the style writes no sequence
1184
- * for this age, which is what the `none` capability and a settled age yield.
1215
+ * @returns the lines at that mix; copies when the style writes no sequence,
1216
+ * which is what the `none` capability and a settled age yield.
1185
1217
  */
1186
1218
  function recolorLines(lines, age, style, from = 0) {
1187
- const sgr = fadeSgr(style, age);
1188
- if (sgr === "") return [...lines];
1189
- const restore = restoreFor(style.capability);
1190
- return lines.map((line, index) => index < from || line === "" ? line : `${sgr}${line.replace(SGR_SEQUENCE, (match) => match + sgr)}${restore}`);
1219
+ const capability = style.capability;
1220
+ if (capability === "none") return [...lines];
1221
+ if (capability === "dim") return lines.map((line, index) => index < from || line === "" ? line : `${DIM}${line}${RESET_INTENSITY}`);
1222
+ const steps = style.ramp.length;
1223
+ const fg = style.ramp[steps - 1];
1224
+ if (fg === void 0 || age >= steps) return [...lines];
1225
+ const t = age / steps;
1226
+ return lines.map((line, index) => index < from || line === "" ? line : floatOutLine(line, t, capability, fg));
1227
+ }
1228
+ /** Assumed terminal white, used only to lift a settled color that is already brighter than `fg`. */
1229
+ const WHITE_RGB = {
1230
+ r: CHANNEL_MAX,
1231
+ g: CHANNEL_MAX,
1232
+ b: CHANNEL_MAX
1233
+ };
1234
+ /** xterm 16-color palette, indices 0..15. */
1235
+ const ANSI16 = [
1236
+ {
1237
+ r: 0,
1238
+ g: 0,
1239
+ b: 0
1240
+ },
1241
+ {
1242
+ r: 205,
1243
+ g: 0,
1244
+ b: 0
1245
+ },
1246
+ {
1247
+ r: 0,
1248
+ g: 205,
1249
+ b: 0
1250
+ },
1251
+ {
1252
+ r: 205,
1253
+ g: 205,
1254
+ b: 0
1255
+ },
1256
+ {
1257
+ r: 0,
1258
+ g: 0,
1259
+ b: 238
1260
+ },
1261
+ {
1262
+ r: 205,
1263
+ g: 0,
1264
+ b: 205
1265
+ },
1266
+ {
1267
+ r: 0,
1268
+ g: 205,
1269
+ b: 205
1270
+ },
1271
+ {
1272
+ r: 229,
1273
+ g: 229,
1274
+ b: 229
1275
+ },
1276
+ {
1277
+ r: 127,
1278
+ g: 127,
1279
+ b: 127
1280
+ },
1281
+ {
1282
+ r: 255,
1283
+ g: 0,
1284
+ b: 0
1285
+ },
1286
+ {
1287
+ r: 0,
1288
+ g: 255,
1289
+ b: 0
1290
+ },
1291
+ {
1292
+ r: 255,
1293
+ g: 255,
1294
+ b: 0
1295
+ },
1296
+ {
1297
+ r: 92,
1298
+ g: 92,
1299
+ b: 255
1300
+ },
1301
+ {
1302
+ r: 255,
1303
+ g: 0,
1304
+ b: 255
1305
+ },
1306
+ {
1307
+ r: 0,
1308
+ g: 255,
1309
+ b: 255
1310
+ },
1311
+ {
1312
+ r: 255,
1313
+ g: 255,
1314
+ b: 255
1315
+ }
1316
+ ];
1317
+ /**
1318
+ * Relative luminance of one sRGB color, using the same weights as the grayscale encoder.
1319
+ * @param color - the color.
1320
+ * @returns the weighted sum of the channels.
1321
+ */
1322
+ function colorLuminance(color) {
1323
+ return LUMINANCE.r * color.r + LUMINANCE.g * color.g + LUMINANCE.b * color.b;
1324
+ }
1325
+ /**
1326
+ * The color a float-out starts from: the assumed foreground when that is
1327
+ * brighter than the settle, otherwise a mix toward white.
1328
+ * @param settled - the run's color at t = 1.
1329
+ * @param fg - the assumed terminal foreground.
1330
+ * @returns the lifted color at t = 0.
1331
+ */
1332
+ function liftColor(settled, fg) {
1333
+ return colorLuminance(fg) >= colorLuminance(settled) ? fg : mixFadeColor(settled, WHITE_RGB, LIFT_TOWARD_WHITE);
1334
+ }
1335
+ /**
1336
+ * Apply SGR faint as a channel scale, matching what a dim palette run looks like.
1337
+ * @param color - the undimmed RGB.
1338
+ * @returns the dimmed RGB.
1339
+ */
1340
+ function dimColor(color) {
1341
+ return {
1342
+ r: Math.round(color.r * DIM_CHANNEL),
1343
+ g: Math.round(color.g * DIM_CHANNEL),
1344
+ b: Math.round(color.b * DIM_CHANNEL)
1345
+ };
1346
+ }
1347
+ /**
1348
+ * The RGB a run settles at, given the SGR in force and the assumed default foreground.
1349
+ * @param state - the SGR foreground and dim flag.
1350
+ * @param fg - the assumed default foreground.
1351
+ * @returns the settled color the mix recedes toward.
1352
+ */
1353
+ function settledRgb(state, fg) {
1354
+ const base = state.color ?? fg;
1355
+ return state.dim ? dimColor(base) : base;
1356
+ }
1357
+ /**
1358
+ * Encode one mixed color under a color capability.
1359
+ * @param capability - `truecolor` or `ansi256`.
1360
+ * @param color - the mixed RGB.
1361
+ * @returns the SGR sequence, or empty when the capability cannot encode a mix.
1362
+ */
1363
+ function encodeMix(capability, color) {
1364
+ return capability === "truecolor" ? truecolorSgr(color) : `${CSI}38;5;${String(nearestAnsi256(color))}m`;
1365
+ }
1366
+ /**
1367
+ * Rebuild one card row as a per-run float-out mix.
1368
+ * @param line - the rendered line.
1369
+ * @param t - 0 at lift, 1 at settle.
1370
+ * @param capability - how the mix is encoded.
1371
+ * @param fg - the assumed default foreground.
1372
+ * @returns the line with each run overlaid, closed by {@link RESET_FOREGROUND}.
1373
+ */
1374
+ function floatOutLine(line, t, capability, fg) {
1375
+ let out = "";
1376
+ let last = 0;
1377
+ const state = {
1378
+ color: void 0,
1379
+ dim: false
1380
+ };
1381
+ for (const match of line.matchAll(SGR_SEQUENCE)) {
1382
+ const start = match.index;
1383
+ if (start > last) out += paintSegment(line.slice(last, start), state, t, capability, fg);
1384
+ applySgr(state, match[0]);
1385
+ out += match[0];
1386
+ last = start + match[0].length;
1387
+ }
1388
+ if (last < line.length) out += paintSegment(line.slice(last), state, t, capability, fg);
1389
+ return `${out}${RESET_FOREGROUND}`;
1390
+ }
1391
+ /**
1392
+ * Overlay one text run with the float-out mix for the SGR in force.
1393
+ * @param text - the run's characters, with no SGR.
1394
+ * @param state - the SGR in force.
1395
+ * @param t - 0 at lift, 1 at settle.
1396
+ * @param capability - how the mix is encoded.
1397
+ * @param fg - the assumed default foreground.
1398
+ * @returns the run prefixed by intensity-reset and the mixed color.
1399
+ */
1400
+ function paintSegment(text, state, t, capability, fg) {
1401
+ const settled = settledRgb(state, fg);
1402
+ return `${RESET_INTENSITY}${encodeMix(capability, mixFadeColor(liftColor(settled, fg), settled, t))}${text}`;
1403
+ }
1404
+ /**
1405
+ * The float-out sequence one reasoning span draws under, toward dimmed `fg`.
1406
+ * @param style - the capability and the ramp.
1407
+ * @param age - elapsed time in units of `stepMs`.
1408
+ * @returns the sequence, or empty once `age` reaches the ramp length.
1409
+ */
1410
+ function floatOutSpanSgr(style, age) {
1411
+ if (style.capability === "dim") return DIM;
1412
+ if (style.capability !== "truecolor" && style.capability !== "ansi256") return "";
1413
+ const steps = style.ramp.length;
1414
+ const fg = style.ramp[steps - 1];
1415
+ if (fg === void 0 || age >= steps) return "";
1416
+ const settled = dimColor(fg);
1417
+ const mixed = mixFadeColor(liftColor(settled, fg), settled, age / steps);
1418
+ return `${RESET_INTENSITY}${encodeMix(style.capability, mixed)}`;
1419
+ }
1420
+ /**
1421
+ * Apply one SGR sequence to the float-out foreground state.
1422
+ * @param state - the state to update.
1423
+ * @param sequence - a CSI SGR including the trailing `m`.
1424
+ */
1425
+ function applySgr(state, sequence) {
1426
+ const body = sequence.slice(2, -1);
1427
+ const parts = body === "" ? [0] : body.split(";").map((part) => part === "" ? 0 : Number(part));
1428
+ for (let index = 0; index < parts.length; index += 1) {
1429
+ const code = colorParam(parts, index);
1430
+ if (code === 0) {
1431
+ state.color = void 0;
1432
+ state.dim = false;
1433
+ } else if (code === 2) state.dim = true;
1434
+ else if (code === 22) state.dim = false;
1435
+ else if (code === 39) state.color = void 0;
1436
+ else if (code >= 30 && code <= 37) state.color = ANSI16[code - 30];
1437
+ else if (code >= 90 && code <= 97) state.color = ANSI16[code - 90 + 8];
1438
+ else if (code === 38) {
1439
+ const read = readExtendedColor(parts, index);
1440
+ state.color = read.color;
1441
+ index += read.skip;
1442
+ } else if (code === 48) index += readExtendedColor(parts, index).skip;
1443
+ }
1444
+ }
1445
+ /**
1446
+ * Consume an ITU T.416 extended color (`38`/`48` plus `2;R;G;B` or `5;N`).
1447
+ * @param parts - the SGR parameter list.
1448
+ * @param index - index of the `38` or `48` code.
1449
+ * @returns the RGB for a foreground read, and how many following parameters were consumed.
1450
+ */
1451
+ function readExtendedColor(parts, index) {
1452
+ const mode = parts[index + 1];
1453
+ if (mode === 2) return {
1454
+ color: {
1455
+ r: channel(colorParam(parts, index + 2)),
1456
+ g: channel(colorParam(parts, index + 3)),
1457
+ b: channel(colorParam(parts, index + 4))
1458
+ },
1459
+ skip: 4
1460
+ };
1461
+ if (mode === 5) return {
1462
+ color: ansi256Rgb(colorParam(parts, index + 2)),
1463
+ skip: 2
1464
+ };
1465
+ return {
1466
+ color: void 0,
1467
+ skip: mode === void 0 ? 0 : 1
1468
+ };
1469
+ }
1470
+ /**
1471
+ * Read one SGR numeric parameter, defaulting a missing slot to 0.
1472
+ * @param parts - the SGR parameter list.
1473
+ * @param index - the slot to read.
1474
+ * @returns the parameter, or 0 when it is absent.
1475
+ */
1476
+ function colorParam(parts, index) {
1477
+ return parts[index] ?? 0;
1478
+ }
1479
+ /**
1480
+ * RGB for one xterm 256-color index.
1481
+ * @param index - 0..255.
1482
+ * @returns the palette color, clamped onto the table.
1483
+ */
1484
+ function ansi256Rgb(index) {
1485
+ const n = Math.max(0, Math.min(255, Math.floor(index)));
1486
+ if (n < 16) {
1487
+ const color = ANSI16[n];
1488
+ /* v8 ignore next -- ANSI16 has 16 entries and n is already clamped to 0..15 */
1489
+ if (color === void 0) return {
1490
+ r: 0,
1491
+ g: 0,
1492
+ b: 0
1493
+ };
1494
+ return color;
1495
+ }
1496
+ if (n >= GRAY_FIRST_INDEX) {
1497
+ const value = GRAY_FIRST_VALUE + (n - GRAY_FIRST_INDEX) * GRAY_VALUE_STEP;
1498
+ return {
1499
+ r: value,
1500
+ g: value,
1501
+ b: value
1502
+ };
1503
+ }
1504
+ const cube = n - 16;
1505
+ const r = Math.floor(cube / 36);
1506
+ const g = Math.floor(cube % 36 / 6);
1507
+ const b = cube % 6;
1508
+ const level = (step) => step === 0 ? 0 : 55 + step * 40;
1509
+ return {
1510
+ r: level(r),
1511
+ g: level(g),
1512
+ b: level(b)
1513
+ };
1514
+ }
1515
+ /**
1516
+ * Nearest xterm 256-color index to one RGB, by squared channel distance.
1517
+ * @param color - the mixed RGB.
1518
+ * @returns an index in 0..255.
1519
+ */
1520
+ function nearestAnsi256(color) {
1521
+ let best = 0;
1522
+ let bestDist = Infinity;
1523
+ for (let n = 0; n < 256; n += 1) {
1524
+ const candidate = ansi256Rgb(n);
1525
+ const dist = (candidate.r - color.r) ** 2 + (candidate.g - color.g) ** 2 + (candidate.b - color.b) ** 2;
1526
+ if (dist < bestDist) {
1527
+ bestDist = dist;
1528
+ best = n;
1529
+ }
1530
+ }
1531
+ return best;
1191
1532
  }
1192
1533
  /**
1193
1534
  * The tail of one streaming region - the visible text or the reasoning of one
@@ -1202,8 +1543,8 @@ function recolorLines(lines, age, style, from = 0) {
1202
1543
  * Ages are read, never counted. A chunk's age is the elapsed time since it
1203
1544
  * became visible divided by `stepMs`, computed at the moment a render asks for
1204
1545
  * it, so a render triggered by a delta between two fade periods draws every
1205
- * word at its own level and words do not move in lockstep. That is what makes
1206
- * the trailing edge continuous rather than banded.
1546
+ * word at its own mix and words do not move in lockstep. Fade-in floors that
1547
+ * age onto a ramp slot; float-out uses the fractional value.
1207
1548
  *
1208
1549
  * Arrival rate changes the tail's length, never its depth: whatever the rate,
1209
1550
  * a chunk is at the foreground `steps * stepMs` after it appeared, so a fast
@@ -1252,7 +1593,7 @@ var FadeTracker = class {
1252
1593
  * Drop the chunks that reached the step count, which the application runs
1253
1594
  * once per fade period so a settled chunk stops being matched against the
1254
1595
  * rendered lines.
1255
- * @returns whether a chunk still draws below the last brightness level, and
1596
+ * @returns whether a chunk is still younger than `steps * stepMs`, and
1256
1597
  * so whether the tail keeps moving after this period.
1257
1598
  */
1258
1599
  tick() {
@@ -1263,11 +1604,10 @@ var FadeTracker = class {
1263
1604
  }
1264
1605
  /**
1265
1606
  * Whether the current frame still differs from the settled rendering.
1266
- * @returns true while a tracked chunk draws below the last ramp level, which
1267
- * is the only reason to keep ticking.
1607
+ * @returns true while a tracked chunk is younger than `steps * stepMs`.
1268
1608
  */
1269
1609
  needsRepaint() {
1270
- return this.chunks.some((chunk) => this.ageOf(chunk) < this.steps - 1);
1610
+ return this.chunks.some((chunk) => this.ageOf(chunk) < this.steps);
1271
1611
  }
1272
1612
  /**
1273
1613
  * The tail {@link recolorTail} recolors.
@@ -1290,21 +1630,22 @@ var FadeTracker = class {
1290
1630
  this.openChunk = void 0;
1291
1631
  }
1292
1632
  /**
1293
- * The brightness level one chunk draws at right now.
1633
+ * The brightness age one chunk draws at right now.
1294
1634
  * @param chunk - the tracked chunk.
1295
- * @returns levels elapsed since it became visible, 0 for a chunk younger than one level.
1635
+ * @returns elapsed time since it became visible, in units of `stepMs`.
1296
1636
  */
1297
1637
  ageOf(chunk) {
1298
- return Math.floor((this.now() - chunk.bornAt) / this.stepMs);
1638
+ return (this.now() - chunk.bornAt) / this.stepMs;
1299
1639
  }
1300
1640
  };
1301
1641
  /**
1302
- * The age of one whole block that fades in as a unit - a tool card's rows,
1642
+ * The age of one whole block that floats out as a unit - a tool card's rows,
1303
1643
  * which arrive complete rather than word by word.
1304
1644
  *
1305
- * The last level is withheld the way the word tail withholds it: that level is
1306
- * an assumed foreground, so a block one level below the end is handed back to
1307
- * the terminal's own colors instead, and nothing jumps color as it settles.
1645
+ * Progress is `elapsed / (steps * stepMs)`, eased by the same smoothstep the
1646
+ * ramp uses. {@link BlockFadeClock.age} stays defined until that progress
1647
+ * reaches 1, so the last overlay frame can sit near the settled colors and
1648
+ * the next frame is the component's own bytes.
1308
1649
  */
1309
1650
  var BlockFadeClock = class {
1310
1651
  options;
@@ -1312,18 +1653,25 @@ var BlockFadeClock = class {
1312
1653
  this.options = options;
1313
1654
  }
1314
1655
  /**
1315
- * The brightness level the block draws at right now.
1316
- * @returns the level, or undefined once the block reached the last drawn
1317
- * level and renders in the colors the component itself produced.
1656
+ * How far through the float-out this block is.
1657
+ * @returns 0 at birth, 1 at or after `steps * stepMs`.
1318
1658
  */
1319
- age() {
1659
+ progress() {
1320
1660
  const { bornAt, stepMs, steps, now } = this.options;
1321
- const age = Math.floor((now() - bornAt) / stepMs);
1322
- return age < steps - 1 ? age : void 0;
1661
+ return Math.min(1, Math.max(0, (now() - bornAt) / (steps * stepMs)));
1662
+ }
1663
+ /**
1664
+ * The fractional age the block draws at right now, in units of `stepMs`.
1665
+ * @returns `progress * steps`, or undefined once progress has reached 1 and
1666
+ * the block renders in the colors the component itself produced.
1667
+ */
1668
+ age() {
1669
+ const t = this.progress();
1670
+ return t >= 1 ? void 0 : t * this.options.steps;
1323
1671
  }
1324
1672
  /**
1325
- * Whether this block still draws below the last brightness level.
1326
- * @returns true while {@link BlockFadeClock.age} yields a level.
1673
+ * Whether this block still draws below the settled colors.
1674
+ * @returns true while {@link BlockFadeClock.age} yields a value.
1327
1675
  */
1328
1676
  needsRepaint() {
1329
1677
  return this.age() !== void 0;
@@ -1376,27 +1724,32 @@ var FadeRegistry = class {
1376
1724
  *
1377
1725
  * Styling inside a recolored run survives. The run reasserts the sequences in
1378
1726
  * force at its start, so an enclosing bold or italic continues across it; an
1379
- * enclosing foreground color reasserted there wins over the ramp, and that run
1380
- * simply does not fade. Each recolored line ends with `ESC[39m` (or `ESC[22m`
1381
- * in the two-level mode, which also ends bold) after the line's own closing
1382
- * sequences, so the recolor never leaks past the line it was applied to.
1727
+ * enclosing foreground color reasserted there wins over the fade-in ramp, and
1728
+ * that run simply does not fade. Each recolored line ends with `ESC[39m` (or
1729
+ * `ESC[22m` in the two-level mode, which also ends bold) after the line's own
1730
+ * closing sequences, so the recolor never leaks past the line it was applied
1731
+ * to. Float-out resets intensity before the mixed color so a dim wrapper does
1732
+ * not stack on the overlay, and at t >= 1 the original lines come back
1733
+ * unchanged.
1383
1734
  * @param lines - the rendered lines of the streaming block, newest text last.
1384
1735
  * @param spans - the tail from {@link FadeTracker.spans}, oldest first.
1385
1736
  * @param style - the capability and the ramp.
1386
1737
  * @param from - first line the tail may recolor; the lines before it come back
1387
1738
  * byte-identical, which is how a caller keeps rows the renderer can no longer
1388
1739
  * repaint out of the fade.
1740
+ * @param mode - `in` climbs {@link buildFadeRamp}; `out` recedes toward the
1741
+ * dim foreground reasoning settles in. Defaults to `in`.
1389
1742
  * @returns the lines with the tail recolored; lines the tail does not cover
1390
1743
  * are returned byte-identical, so the renderer leaves them alone.
1391
1744
  */
1392
- function recolorTail(lines, spans, style, from = 0) {
1393
- if (style.capability === "none" || spans.length === 0 || lines.length === 0) return [...lines];
1745
+ function recolorTail(lines, spans, style, from = 0, mode = "in") {
1746
+ if (spans.length === 0 || lines.length === 0) return [...lines];
1394
1747
  const cells = cellsFromEnd(lines);
1395
1748
  const runs = [];
1396
1749
  for (const span of [...spans].reverse()) {
1397
1750
  const covered = consumeSpan(cells, span.text);
1398
1751
  if (covered === void 0) break;
1399
- const sgr = fadeSgr(style, span.age);
1752
+ const sgr = mode === "out" ? floatOutSpanSgr(style, span.age) : fadeSgr(style, span.age);
1400
1753
  if (sgr !== "") collectRuns(runs, covered, sgr);
1401
1754
  }
1402
1755
  const byLine = /* @__PURE__ */ new Map();
@@ -1609,16 +1962,18 @@ function editorTheme(palette) {
1609
1962
  //#region lib/types/blocks.js
1610
1963
  /**
1611
1964
  * Transcript components: one pi-tui component per rendered fact (a user
1612
- * prompt, an assistant reply, a tool card, a notice). Each owns its display
1613
- * state and re-renders from it at any width.
1965
+ * prompt, an assistant reply, a tool card, a system prompt or injected
1966
+ * context, a notice). Each owns its display state and re-renders from it at
1967
+ * any width.
1614
1968
  *
1615
- * The prompt, the reply, and the tool card are also the navigable blocks the
1616
- * keyboard walks (`./navigation.ts`): each reports its sections as plain source
1617
- * rows and draws a two-column gutter beside them while it holds the focus -
1618
- * accented on the focused section's own lines and dim on the rest of the
1619
- * block. The gutter narrows the width the block's content wraps at and is
1620
- * prepended after any fade recoloring, so the fade keeps matching the block's
1621
- * own text and the gutter's styling never enters that match.
1969
+ * The prompt, the reply, the tool card, and the compact context row are also
1970
+ * the navigable blocks the keyboard walks (`./navigation.ts`): each reports
1971
+ * its sections as plain source rows and draws a two-column gutter beside them
1972
+ * while it holds the focus - accented on the focused section's own lines and
1973
+ * dim on the rest of the block. The gutter narrows the width the block's
1974
+ * content wraps at and is prepended after any fade recoloring, so the fade
1975
+ * keeps matching the block's own text and the gutter's styling never enters
1976
+ * that match.
1622
1977
  * @module @deepseek-ai/dsh-tui-app/blocks
1623
1978
  */
1624
1979
  /** Columns the focus gutter takes from the width a block's content wraps at. */
@@ -1667,7 +2022,7 @@ var UserBlock = class {
1667
2022
  }
1668
2023
  /**
1669
2024
  * Draw this prompt with the focus gutter, or without it.
1670
- * @param part - the focused section, or undefined to clear the mark.
2025
+ * @param part - the index of the focused section, or undefined to clear the mark.
1671
2026
  */
1672
2027
  setHighlight(part) {
1673
2028
  this.highlight = part;
@@ -1681,6 +2036,8 @@ var UserBlock = class {
1681
2036
  return marked ? withGutter(palette, lines, () => true) : lines;
1682
2037
  }
1683
2038
  };
2039
+ /** What a compact context row uses in place of the user prompt's `›`. */
2040
+ const CONTEXT_GLYPH = "⬡";
1684
2041
  /** A dim one-line notice about the session (a stopped turn, a command result, a model switch). */
1685
2042
  var NoticeBlock = class {
1686
2043
  text;
@@ -1696,12 +2053,79 @@ var NoticeBlock = class {
1696
2053
  }
1697
2054
  };
1698
2055
  /**
2056
+ * A system prompt or injected context, drawn in full under a dim title.
2057
+ * Snapshot contributions keep their names above their own rows so every
2058
+ * piece of context is visible in the transcript; the inspector Left/Right
2059
+ * walk still addresses one contribution at a time.
2060
+ */
2061
+ var ContextBlock = class {
2062
+ theme;
2063
+ title;
2064
+ sectionParts;
2065
+ turn;
2066
+ navigable = true;
2067
+ blockKind = "context";
2068
+ /** The section drawn as focused; absent while the keyboard is elsewhere. */
2069
+ highlight;
2070
+ /**
2071
+ * @param theme - the palette the glyph and title are styled with.
2072
+ * @param title - form and producer, a notice summary, or `system prompt`.
2073
+ * @param sectionParts - the model-facing rows, one part per snapshot contribution.
2074
+ * @param turn - the turn the message was appended in.
2075
+ */
2076
+ constructor(theme, title, sectionParts, turn) {
2077
+ this.theme = theme;
2078
+ this.title = title;
2079
+ this.sectionParts = sectionParts;
2080
+ this.turn = turn;
2081
+ }
2082
+ /**
2083
+ * The injection as navigable sections.
2084
+ * @returns the parts the constructor was given.
2085
+ */
2086
+ parts() {
2087
+ return this.sectionParts;
2088
+ }
2089
+ /**
2090
+ * Draw this row with the focus gutter, or without it.
2091
+ * @param part - the index of the focused section, or undefined to clear the mark.
2092
+ */
2093
+ setHighlight(part) {
2094
+ this.highlight = part;
2095
+ }
2096
+ invalidate() {}
2097
+ render(width) {
2098
+ const palette = this.theme.palette;
2099
+ const inner = this.highlight !== void 0 ? Math.max(1, width - GUTTER_WIDTH) : width;
2100
+ const textWidth = Math.max(1, inner - 2);
2101
+ const indent = (line) => ` ${line}`;
2102
+ const lines = ["", ...wrapTextWithAnsi(this.title, textWidth).map((line, index) => `${palette.dim(index === 0 ? CONTEXT_GLYPH : " ")} ${palette.dim(line)}`)];
2103
+ const ranges = [];
2104
+ for (const part of this.sectionParts) {
2105
+ const from = lines.length;
2106
+ if (part.label !== void 0) lines.push(...wrapTextWithAnsi(part.label, textWidth).map((line) => indent(palette.bold(line))));
2107
+ if (!(part.rows.length === 1 && part.rows[0] === "")) for (const row of part.rows) lines.push(...wrapTextWithAnsi(row, textWidth).map((line) => indent(palette.dim(line))));
2108
+ ranges.push({
2109
+ from,
2110
+ to: lines.length
2111
+ });
2112
+ }
2113
+ if (this.highlight === void 0) return lines;
2114
+ const section = ranges[this.highlight] ?? {
2115
+ from: 0,
2116
+ to: lines.length
2117
+ };
2118
+ return withGutter(palette, lines, (line) => line >= section.from && line < section.to);
2119
+ }
2120
+ };
2121
+ /**
1699
2122
  * An assistant reply: streamed reasoning above streamed Markdown text. The
1700
2123
  * durable `assistant/message` replaces both with the committed content.
1701
2124
  *
1702
2125
  * A block that is streaming right now can carry a {@link FadeRender} for its
1703
- * text and another for its reasoning, each drawing that region's newest words
1704
- * dimmed and brightening. A block rebuilt from history carries neither, and
2126
+ * text and another for its reasoning. Visible text draws newest words dimmed
2127
+ * and brightening; reasoning floats out from a lifted color toward the dim
2128
+ * italic it settles in. A block rebuilt from history carries neither, and
1705
2129
  * {@link AssistantBlock.commit} drops the ones a streaming block had, so
1706
2130
  * settled text is never recolored.
1707
2131
  */
@@ -1737,7 +2161,8 @@ var AssistantBlock = class {
1737
2161
  * reasoning as it was streamed or committed, and the reply as Markdown
1738
2162
  * source rather than the rendering the transcript draws.
1739
2163
  * @returns the reasoning part while the message has reasoning, then the
1740
- * reply, which is present from the start and empty until text arrives.
2164
+ * reply once visible text has arrived. An empty reply is kept only while the
2165
+ * message has no reasoning, so a tool-call step does not add a blank section.
1741
2166
  */
1742
2167
  parts() {
1743
2168
  const parts = [];
@@ -1745,7 +2170,7 @@ var AssistantBlock = class {
1745
2170
  kind: "reasoning",
1746
2171
  rows: this.reasoning.split("\n")
1747
2172
  });
1748
- parts.push({
2173
+ if (this.text !== "" || parts.length === 0) parts.push({
1749
2174
  kind: "reply",
1750
2175
  rows: this.text.split("\n")
1751
2176
  });
@@ -1753,7 +2178,7 @@ var AssistantBlock = class {
1753
2178
  }
1754
2179
  /**
1755
2180
  * Draw this message with the focus gutter, or without it.
1756
- * @param part - the focused section, or undefined to clear the mark.
2181
+ * @param part - the index of the focused section, or undefined to clear the mark.
1757
2182
  */
1758
2183
  setHighlight(part) {
1759
2184
  this.highlight = part;
@@ -1783,7 +2208,7 @@ var AssistantBlock = class {
1783
2208
  setRepaintFloor(floor) {
1784
2209
  if (floor <= this.repaintFloor) return false;
1785
2210
  this.repaintFloor = floor;
1786
- return drawnSpans(this.fade).length > 0 || drawnSpans(this.reasoningFade).length > 0;
2211
+ return this.fade !== void 0 && fadingInSpans(this.fade).length > 0 || this.reasoningFade !== void 0 && floatingOutSpans(this.reasoningFade).length > 0;
1787
2212
  }
1788
2213
  /**
1789
2214
  * Append streamed visible text.
@@ -1821,8 +2246,7 @@ var AssistantBlock = class {
1821
2246
  this.reasoningText.invalidate();
1822
2247
  }
1823
2248
  render(width) {
1824
- const marked = this.highlight !== void 0;
1825
- const inner = marked ? Math.max(1, width - GUTTER_WIDTH) : width;
2249
+ const inner = this.highlight !== void 0 ? Math.max(1, width - GUTTER_WIDTH) : width;
1826
2250
  const lines = [""];
1827
2251
  const reasoning = {
1828
2252
  from: 0,
@@ -1844,18 +2268,16 @@ var AssistantBlock = class {
1844
2268
  reply.to = lines.length;
1845
2269
  }
1846
2270
  if (this.interrupted) lines.push(this.theme.palette.dim("[interrupted]"));
1847
- if (!marked) return lines;
1848
- const section = this.highlight === "reasoning" ? reasoning : reply;
2271
+ if (this.highlight === void 0) return lines;
2272
+ const section = this.parts()[this.highlight]?.kind === "reasoning" ? reasoning : reply;
1849
2273
  return withGutter(this.theme.palette, lines, (index) => index >= section.from && index < section.to);
1850
2274
  }
1851
2275
  /**
1852
- * The reasoning lines, with the streaming tail recolored.
2276
+ * The reasoning lines, with the streaming tail floated out toward dim italic.
1853
2277
  *
1854
- * The ramp climbs towards the assumed terminal foreground, but the reasoning
1855
- * draws inside the faint and italic sequences `appendReasoning` wrapped it
1856
- * in, and a recolored run reasserts the styling in force at its start. The
1857
- * tail therefore arrives at the dim foreground the settled reasoning carries,
1858
- * not at the plain one.
2278
+ * The mix starts at a lifted color and recedes to the faint foreground the
2279
+ * settled reasoning already carries. At full age the original dim italic
2280
+ * bytes come back unchanged.
1859
2281
  * @param width - the width the reasoning lays out in.
1860
2282
  * @param at - index of the region's first line in this block's render.
1861
2283
  * @returns the lines to draw.
@@ -1866,7 +2288,7 @@ var AssistantBlock = class {
1866
2288
  if (fade === void 0) return lines;
1867
2289
  if (this.reasoningFadeWidth !== void 0 && this.reasoningFadeWidth !== width) fade.flush();
1868
2290
  this.reasoningFadeWidth = width;
1869
- return recolorTail(lines, drawnSpans(fade), fade.style(), this.repaintFloor - at);
2291
+ return recolorTail(lines, floatingOutSpans(fade), fade.style(), this.repaintFloor - at, "out");
1870
2292
  }
1871
2293
  /**
1872
2294
  * The Markdown lines, with the streaming tail recolored.
@@ -1885,14 +2307,14 @@ var AssistantBlock = class {
1885
2307
  if (fade === void 0) return lines;
1886
2308
  if (this.fadeWidth !== void 0 && this.fadeWidth !== width) fade.flush();
1887
2309
  this.fadeWidth = width;
1888
- return recolorTail(lines, drawnSpans(fade), fade.style(), this.repaintFloor - at);
2310
+ return recolorTail(lines, fadingInSpans(fade), fade.style(), this.repaintFloor - at);
1889
2311
  }
1890
2312
  };
1891
2313
  /**
1892
2314
  * A tool call card: status glyph, tool name, headline, then a foldable body.
1893
2315
  *
1894
- * The card arrives in two pieces, and each fades in on its own: the header and
1895
- * the call rows when the call is logged, the result rows when the tool
2316
+ * The card arrives in two pieces, and each floats out on its own: the header
2317
+ * and the call rows when the call is logged, the result rows when the tool
1896
2318
  * answers. A card rebuilt from history carries neither fade.
1897
2319
  */
1898
2320
  var ToolBlock = class {
@@ -1940,7 +2362,7 @@ var ToolBlock = class {
1940
2362
  }
1941
2363
  /**
1942
2364
  * Draw this card with the focus gutter, or without it.
1943
- * @param part - the focused section, or undefined to clear the mark.
2365
+ * @param part - the index of the focused section, or undefined to clear the mark.
1944
2366
  */
1945
2367
  setHighlight(part) {
1946
2368
  this.highlight = part;
@@ -1961,7 +2383,7 @@ var ToolBlock = class {
1961
2383
  }
1962
2384
  /**
1963
2385
  * Hand the rows the renderer can no longer repaint back to the colors this
1964
- * card drew them in, so a fade that is still climbing never rewrites them.
2386
+ * card drew them in, so a fade that is still moving never rewrites them.
1965
2387
  * @param floor - this card's own first repaintable line; the application
1966
2388
  * raises it as the frame grows and never lowers it.
1967
2389
  * @returns whether the floor took rows away from a fade that is drawing
@@ -1991,8 +2413,7 @@ var ToolBlock = class {
1991
2413
  invalidate() {}
1992
2414
  render(width) {
1993
2415
  const palette = this.theme.palette;
1994
- const marked = this.highlight !== void 0;
1995
- const outer = marked ? Math.max(1, width - GUTTER_WIDTH) : width;
2416
+ const outer = this.highlight !== void 0 ? Math.max(1, width - GUTTER_WIDTH) : width;
1996
2417
  const header = `${this.status === "running" ? palette.warning("●") : this.status === "done" ? palette.success("●") : palette.error("●")} ${palette.bold(this.name)}${this.call.title === "" ? "" : ` ${palette.dim(this.call.title)}`}`;
1997
2418
  const body = [...this.call.lines, ...this.resultLines];
1998
2419
  const shown = previewLines(body, this.theme.toolPreviewLines, this.expanded);
@@ -2008,10 +2429,10 @@ var ToolBlock = class {
2008
2429
  ...call,
2009
2430
  ...result
2010
2431
  ];
2011
- if (!marked) return lines;
2432
+ if (this.highlight === void 0) return lines;
2012
2433
  const cut = !this.expanded && body.length > this.theme.toolPreviewLines;
2013
2434
  const sections = lines.length - (cut ? rows(shown.slice(-1)).length : 0);
2014
- const section = this.highlight === "result" ? {
2435
+ const section = this.parts()[this.highlight]?.kind === "result" ? {
2015
2436
  from: 1 + callLines.length,
2016
2437
  to: lines.length
2017
2438
  } : {
@@ -2022,11 +2443,11 @@ var ToolBlock = class {
2022
2443
  }
2023
2444
  };
2024
2445
  /**
2025
- * Draw one group of a card's rows at the level its fade reports.
2446
+ * Draw one group of a card's rows at the mix its fade reports.
2026
2447
  * @param lines - the group's final rendered lines.
2027
2448
  * @param fade - the group's fade; absent for a card that never faded.
2028
2449
  * @param from - first line of the group the fade may recolor.
2029
- * @returns the lines at that level, or the lines themselves once the fade
2450
+ * @returns the lines at that mix, or the lines themselves once the fade
2030
2451
  * settled or was never attached.
2031
2452
  */
2032
2453
  function faded(lines, fade, from) {
@@ -2035,18 +2456,30 @@ function faded(lines, fade, from) {
2035
2456
  return age === void 0 ? lines : recolorLines(lines, age, fade.style(), from);
2036
2457
  }
2037
2458
  /**
2038
- * The tail chunks one streaming region still draws below the terminal's own
2459
+ * The tail chunks one streaming reply still draws below the terminal's own
2039
2460
  * foreground.
2040
2461
  *
2041
2462
  * The last ramp level is an assumed foreground - pi-tui reports the terminal
2042
2463
  * background but not its foreground - so a chunk that reached it is left to
2043
2464
  * draw in the terminal's own foreground, which is also what it draws in once it
2044
2465
  * leaves the tail. No chunk can therefore jump color as it settles.
2045
- * @param fade - the region's fade; absent for a region that never faded.
2466
+ * @param fade - the region's fade.
2046
2467
  * @returns the spans to recolor, oldest first.
2047
2468
  */
2048
- function drawnSpans(fade) {
2049
- return fade === void 0 ? [] : fade.spans().filter((span) => span.age < fade.steps - 1);
2469
+ function fadingInSpans(fade) {
2470
+ return fade.spans().filter((span) => span.age < fade.steps - 1);
2471
+ }
2472
+ /**
2473
+ * The tail chunks one streaming reasoning region still floats out.
2474
+ *
2475
+ * Overlay continues until `age >= steps`, which is `steps * stepMs` after the
2476
+ * word appeared. The last overlay sits near the dim settle; the next frame is
2477
+ * the original dim italic bytes.
2478
+ * @param fade - the region's fade.
2479
+ * @returns the spans to recolor, oldest first.
2480
+ */
2481
+ function floatingOutSpans(fade) {
2482
+ return fade.spans().filter((span) => span.age < fade.steps);
2050
2483
  }
2051
2484
  //#endregion
2052
2485
  //#region lib/types/completion.js
@@ -2107,6 +2540,202 @@ function editorCompletion(sources) {
2107
2540
  };
2108
2541
  }
2109
2542
  //#endregion
2543
+ //#region lib/types/context.js
2544
+ /**
2545
+ * Project logged system prompts and injected user-role messages into the
2546
+ * compact titles and navigable sections the terminal transcript walks.
2547
+ *
2548
+ * Compaction replacements, tool results, and the user's own prompts are not
2549
+ * context: those have their own blocks. An empty system-prompt rendering logs
2550
+ * that no prompt is in force and is omitted here.
2551
+ * @module @deepseek-ai/dsh-tui-app/context
2552
+ */
2553
+ /** Producer-declared forms this surface presents structurally. */
2554
+ const KNOWN_FORMS = [
2555
+ "instructions",
2556
+ "catalog",
2557
+ "snapshot",
2558
+ "notice",
2559
+ "relay",
2560
+ "recall"
2561
+ ];
2562
+ /**
2563
+ * Project one nonempty system prompt into a transcript section.
2564
+ * @param text - the rendered prompt; `''` means no prompt is in force.
2565
+ * @param update - whether a nonempty prompt already appeared in this transcript.
2566
+ * @returns the section, or undefined when `text` is empty.
2567
+ */
2568
+ function systemPromptView(text, update) {
2569
+ if (text === "") return void 0;
2570
+ return {
2571
+ title: update ? "system prompt update" : "system prompt",
2572
+ parts: [{
2573
+ kind: "system",
2574
+ rows: text.split("\n")
2575
+ }]
2576
+ };
2577
+ }
2578
+ /**
2579
+ * Project one injected `user/message` into a transcript section.
2580
+ * @param source - the message's durable source.
2581
+ * @param content - the model-facing blocks.
2582
+ * @returns the section, or undefined when this message is not injected context.
2583
+ */
2584
+ function injectedContextView(source, content) {
2585
+ const record = recordOf(source);
2586
+ const kind = stringField(record, "kind");
2587
+ if (record === void 0 || kind === void 0) return void 0;
2588
+ if (kind === "user" || kind === "tool" || kind === "model") return void 0;
2589
+ if (kind === "plugin" && stringField(record, "plugin") === "compact") return void 0;
2590
+ const form = knownForm(stringField(record, "form"));
2591
+ return {
2592
+ title: titled(form, producerOf(record, kind), stringField(record, "summary")),
2593
+ parts: form === "snapshot" ? snapshotParts(record, content) : [{
2594
+ kind: partKind(form),
2595
+ rows: rowsOf(content)
2596
+ }]
2597
+ };
2598
+ }
2599
+ /**
2600
+ * Narrow a value to a string-keyed record.
2601
+ * @param value - a durable source or a snapshot entry.
2602
+ * @returns the record, or undefined when the value is not one.
2603
+ */
2604
+ function recordOf(value) {
2605
+ if (value === null || typeof value !== "object" || Array.isArray(value)) return void 0;
2606
+ return value;
2607
+ }
2608
+ /**
2609
+ * Read a nonempty string field.
2610
+ * @param record - the record to read, or undefined.
2611
+ * @param key - the field name.
2612
+ * @returns the field, or undefined when it is missing or empty.
2613
+ */
2614
+ function stringField(record, key) {
2615
+ const value = record?.[key];
2616
+ return typeof value === "string" && value !== "" ? value : void 0;
2617
+ }
2618
+ /**
2619
+ * Collect nonempty named strings from an array field, first-seen order.
2620
+ * @param record - the source record.
2621
+ * @param member - the array field.
2622
+ * @param key - the entry field that names the item.
2623
+ * @returns the labels.
2624
+ */
2625
+ function labelsIn(record, member, key) {
2626
+ const list = record?.[member];
2627
+ if (!Array.isArray(list)) return [];
2628
+ const labels = [];
2629
+ for (const entry of list) {
2630
+ const label = stringField(recordOf(entry), key);
2631
+ if (label !== void 0 && !labels.includes(label)) labels.push(label);
2632
+ }
2633
+ return labels;
2634
+ }
2635
+ /**
2636
+ * Name the producer a durable source identifies.
2637
+ * @param record - the source record.
2638
+ * @param kind - the source kind, already read.
2639
+ * @returns a label the heading can show.
2640
+ */
2641
+ function producerOf(record, kind) {
2642
+ switch (kind) {
2643
+ case "plugin": return stringField(record, "plugin") ?? kind;
2644
+ case "skill-invocation": return stringField(record, "name") ?? kind;
2645
+ case "session-reference": {
2646
+ const labels = labelsIn(record, "references", "label");
2647
+ return labels.length > 0 ? labels.join(", ") : kind;
2648
+ }
2649
+ case "agent-instructions": {
2650
+ const paths = labelsIn(record, "changes", "path");
2651
+ return paths.length > 0 ? paths.join(", ") : kind;
2652
+ }
2653
+ default: return kind;
2654
+ }
2655
+ }
2656
+ /**
2657
+ * Narrow a logged form to one this surface presents structurally.
2658
+ * @param form - the source's `form` field.
2659
+ * @returns the form, or undefined for an absent or unknown value.
2660
+ */
2661
+ function knownForm(form) {
2662
+ return form !== void 0 && KNOWN_FORMS.includes(form) ? form : void 0;
2663
+ }
2664
+ /**
2665
+ * The section kind that matches a known form, or `context` for an opaque body.
2666
+ * @param form - the known form, or undefined.
2667
+ * @returns the kind.
2668
+ */
2669
+ function partKind(form) {
2670
+ return form ?? "context";
2671
+ }
2672
+ /**
2673
+ * Compose the compact title from form, producer, and an optional notice summary.
2674
+ * @param form - the known form, or undefined.
2675
+ * @param producer - the producer label.
2676
+ * @param summary - a notice's one-line account, when present.
2677
+ * @returns the title.
2678
+ */
2679
+ function titled(form, producer, summary) {
2680
+ if (form === "notice") return summary === void 0 ? `notice · ${producer}` : `notice · ${summary}`;
2681
+ return form === void 0 ? producer : `${form} · ${producer}`;
2682
+ }
2683
+ /**
2684
+ * The assembled snapshot as one part, used when named contributions are
2685
+ * absent or unreadable so the model-facing text is never dropped.
2686
+ * @param content - the assembled blocks.
2687
+ * @returns one snapshot part.
2688
+ */
2689
+ function assembledSnapshot(content) {
2690
+ return [{
2691
+ kind: "snapshot",
2692
+ rows: rowsOf(content)
2693
+ }];
2694
+ }
2695
+ /**
2696
+ * Split a snapshot into one part per named contribution.
2697
+ *
2698
+ * The list is all-or-nothing: one unreadable entry means the assembled
2699
+ * text is the part, matching how a partial list would hide the only
2700
+ * complete account of what the model read.
2701
+ * @param record - the source record, which may carry `sections`.
2702
+ * @param content - the assembled model-facing blocks, used when sections are absent or unreadable.
2703
+ * @returns the parts.
2704
+ */
2705
+ function snapshotParts(record, content) {
2706
+ const list = record.sections;
2707
+ if (!Array.isArray(list) || list.length === 0) return assembledSnapshot(content);
2708
+ const parts = [];
2709
+ for (const entry of list) {
2710
+ const item = recordOf(entry);
2711
+ if (item === void 0) return assembledSnapshot(content);
2712
+ const name = stringField(item, "name");
2713
+ if (name === void 0 || typeof item.text !== "string") return assembledSnapshot(content);
2714
+ parts.push({
2715
+ kind: "snapshot",
2716
+ label: name,
2717
+ rows: rowsOfText(item.text)
2718
+ });
2719
+ }
2720
+ return parts;
2721
+ }
2722
+ /**
2723
+ * The model-facing blocks as source rows.
2724
+ * @param content - the content blocks.
2725
+ * @returns the rows; one blank row when there is no text, so the keyboard still has a section.
2726
+ */
2727
+ function rowsOf(content) {
2728
+ return rowsOfText(contentText(content));
2729
+ }
2730
+ /**
2731
+ * Split text into source rows.
2732
+ * @param text - the model-facing text.
2733
+ * @returns the rows; one blank row when `text` is empty.
2734
+ */
2735
+ function rowsOfText(text) {
2736
+ return text === "" ? [""] : text.split("\n");
2737
+ }
2738
+ //#endregion
2110
2739
  //#region lib/types/editor.js
2111
2740
  /**
2112
2741
  * The prompt editor's caret. pi-tui draws the caret cell itself in reverse
@@ -2285,43 +2914,52 @@ async function exportSessionZip(ctx, sessionId, directory, signal) {
2285
2914
  /**
2286
2915
  * The docked inspector above the editor: while the keyboard walks the
2287
2916
  * transcript it shows the focused section in full - what it is, which part of
2288
- * its block is held, and the start of that part's own rows.
2917
+ * its block is held, and that part's own rows. Context sections draw every
2918
+ * row; other sections fold at `focusPreviewLines` with Enter opening the rest.
2289
2919
  *
2290
2920
  * It is the focus indicator that is always on screen. A block is also marked
2291
2921
  * in place, but only while the renderer can still repaint its first line
2292
2922
  * (`./navigation.ts`), so the heading says when the marked block itself has
2293
2923
  * scrolled out of reach. Rows arrive as the block's source text with no fade
2294
2924
  * and no palette styling of their own, so a section that is still streaming
2295
- * grows here as it arrives.
2925
+ * grows here as it arrives. A block with several parts draws them as a numbered
2926
+ * wrapping strip `← 1 reasoning · 2 reply →` so Left/Right walk is visible
2927
+ * and every part label stays on screen.
2296
2928
  * @module @deepseek-ai/dsh-tui-app/inspector
2297
2929
  */
2298
2930
  /** What separates two labels of the parts strip. */
2299
2931
  const SEPARATOR$3 = " · ";
2300
- /** Brackets the parts strip, so the strip reads as one row of choices. */
2301
- const STRIP_ENDS = ["‹ ", " ›"];
2302
2932
  /** What the heading appends while the focused block lies outside the repaint window. */
2303
2933
  const OFF_SCREEN = " · off screen";
2304
2934
  /** The keys the inspector answers, drawn dim under its rows. */
2305
- const HINT = "↑ ↓ blocks · ← → parts · Enter page · Esc back";
2935
+ const HINT = "↑ ↓ sections · ← → parts · Enter page · Esc back";
2936
+ /** Opens the numbered parts strip, so Left/Right read as a walk along this row. */
2937
+ const STRIP_START = "← ";
2938
+ /** Closes the numbered parts strip. */
2939
+ const STRIP_END = " →";
2306
2940
  /** What ends a line the width cut short; one column, so the mark itself fits. */
2307
- const ELLIPSIS = "…";
2941
+ const ELLIPSIS$1 = "…";
2308
2942
  /**
2309
2943
  * Draw the focused section.
2310
2944
  * @param view - the section to show.
2311
2945
  * @param render - the palette, the row budget, and the width.
2312
2946
  * @returns the inspector's lines, none wider than `width`: a blank separator,
2313
- * the heading, the parts strip when the block has more than one part, the
2314
- * folded rows, and the hints.
2947
+ * the heading, the numbered parts strip when the block has more than one part
2948
+ * (wrapped so every part stays on screen), the rows, and the hints.
2315
2949
  */
2316
2950
  function renderInspector(view, render) {
2317
2951
  const { palette } = render;
2318
2952
  const width = Math.max(1, render.width);
2319
- const lines = ["", heading(view, palette, width)];
2320
- if (view.parts.length > 1) lines.push(partsStrip(view.parts, palette));
2953
+ const chrome = ["", heading(view, palette, width)];
2954
+ if (view.parts.length > 1) chrome.push(...partsStrip(view.parts, palette, width));
2321
2955
  const wrapped = view.rows.flatMap((row) => wrapTextWithAnsi(row, width));
2322
- lines.push(...foldRows(wrapped, render.previewLines, (hidden) => palette.dim(`… ${String(hidden)} more row${hidden === 1 ? "" : "s"} · Enter opens the page`)));
2323
- lines.push(palette.dim(HINT));
2324
- return lines.map((line) => truncateToWidth(line, width, ELLIPSIS));
2956
+ const body = view.complete === true ? wrapped : foldRows(wrapped, render.previewLines, (hidden) => palette.dim(`… ${String(hidden)} more row${hidden === 1 ? "" : "s"} · Enter opens the page`));
2957
+ const cut = (line) => truncateToWidth(line, width, ELLIPSIS$1);
2958
+ return [
2959
+ ...chrome.map(cut),
2960
+ ...view.complete === true ? body : body.map(cut),
2961
+ cut(palette.dim(HINT))
2962
+ ];
2325
2963
  }
2326
2964
  /**
2327
2965
  * The heading line. A tool title can run past any terminal, so the subject is
@@ -2336,17 +2974,69 @@ function heading(view, palette, width) {
2336
2974
  const subject = palette.bold(palette.accent(view.heading));
2337
2975
  if (view.highlighted) return subject;
2338
2976
  const suffix = palette.dim(OFF_SCREEN);
2339
- return `${truncateToWidth(subject, Math.max(1, width - visibleWidth(suffix)), ELLIPSIS)}${suffix}`;
2977
+ return `${truncateToWidth(subject, Math.max(1, width - visibleWidth(suffix)), ELLIPSIS$1)}${suffix}`;
2340
2978
  }
2341
2979
  /**
2342
- * Draw the parts of the focused block as one row of choices.
2980
+ * Draw the parts of the focused block as numbered choices that wrap rather
2981
+ * than disappearing past the width. `Left` / `Right` move along this list:
2982
+ * each label is `N name`, the held one is accented, and the arrows mark that
2983
+ * the walk stays inside this block.
2343
2984
  * @param parts - the labels in reading order, the held one marked.
2344
2985
  * @param palette - the palette the labels are styled with.
2345
- * @returns the strip line.
2986
+ * @param width - the width each line must fit; at least 1.
2987
+ * @returns the strip lines, every part present.
2346
2988
  */
2347
- function partsStrip(parts, palette) {
2348
- const labels = parts.map((part) => part.focused ? palette.accent(part.label) : palette.dim(part.label)).join(palette.dim(SEPARATOR$3));
2349
- return `${palette.dim(STRIP_ENDS[0])}${labels}${palette.dim(STRIP_ENDS[1])}`;
2989
+ function partsStrip(parts, palette, width) {
2990
+ const tokens = parts.map((part, index) => {
2991
+ const text = `${String(index + 1)} ${part.label}`;
2992
+ return part.focused ? palette.accent(text) : palette.dim(text);
2993
+ });
2994
+ const sep = palette.dim(SEPARATOR$3);
2995
+ const indent = palette.dim(" ");
2996
+ const end = palette.dim(STRIP_END);
2997
+ const indentWidth = visibleWidth(" ");
2998
+ const endWidth = visibleWidth(STRIP_END);
2999
+ const lines = [];
3000
+ let current = palette.dim(STRIP_START);
3001
+ let used = visibleWidth(STRIP_START);
3002
+ const startLine = () => {
3003
+ lines.push(current);
3004
+ current = indent;
3005
+ used = indentWidth;
3006
+ };
3007
+ for (let index = 0; index < tokens.length; index += 1) {
3008
+ const token = tokens[index];
3009
+ /* v8 ignore next -- the loop bound is tokens.length */
3010
+ if (token === void 0) continue;
3011
+ const extra = index === tokens.length - 1 ? endWidth : 0;
3012
+ let leading = index === 0 || current === indent ? "" : sep;
3013
+ let leadingWidth = leading === "" ? 0 : visibleWidth(SEPARATOR$3);
3014
+ const tokenWidth = visibleWidth(token);
3015
+ if (used + leadingWidth + tokenWidth + extra > width && used > indentWidth) {
3016
+ startLine();
3017
+ leading = "";
3018
+ leadingWidth = 0;
3019
+ }
3020
+ const room = Math.max(1, width - used - extra);
3021
+ if (tokenWidth > room) {
3022
+ const wrapped = wrapTextWithAnsi(token, room);
3023
+ const first = wrapped[0];
3024
+ /* v8 ignore next -- wrapTextWithAnsi returns a line for nonempty text */
3025
+ if (first === void 0) continue;
3026
+ current += leading + first;
3027
+ used += leadingWidth + visibleWidth(first);
3028
+ for (const more of wrapped.slice(1)) {
3029
+ startLine();
3030
+ current += more;
3031
+ used += visibleWidth(more);
3032
+ }
3033
+ } else {
3034
+ current += leading + token;
3035
+ used += leadingWidth + tokenWidth;
3036
+ }
3037
+ }
3038
+ lines.push(`${current}${end}`);
3039
+ return lines;
2350
3040
  }
2351
3041
  /**
2352
3042
  * The inspector as a mounted component.
@@ -2387,8 +3077,11 @@ var InspectorPane = class {
2387
3077
  * The transcript as a list of navigable sections.
2388
3078
  *
2389
3079
  * A conversation is drawn as one component per fact, and the keyboard walks it
2390
- * in two directions: between blocks and, inside a block, between its parts -
2391
- * the reasoning and the reply of a message, the call and the result of a tool.
3080
+ * in two directions: `Up` / `Down` through every section in reading order —
3081
+ * a system prompt, injected context, the reasoning and the reply of a message,
3082
+ * the call and the result of a tool — and `Left` / `Right` between the parts
3083
+ * of the held block without leaving it. Snapshot contributions are separate
3084
+ * parts of one injected block, so the arrows walk each named piece of context.
2392
3085
  * This module turns the transcript container's children into that list and
2393
3086
  * moves one cursor over it. Everything here is plain data: no pi-tui, no
2394
3087
  * palette, no clock. The rows a part carries are the block's own source text,
@@ -2448,19 +3141,65 @@ function enterNewest(blocks) {
2448
3141
  };
2449
3142
  }
2450
3143
  /**
2451
- * Move to another block, landing on its last part.
3144
+ * Every section of the transcript in drawing order, oldest block first and
3145
+ * each block's parts in reading order. Blocks that currently expose no parts
3146
+ * are omitted, so a walk never lands on an empty index.
3147
+ * @param blocks - the navigable blocks.
3148
+ * @returns one cursor per section.
3149
+ */
3150
+ function flattenSections(blocks) {
3151
+ const sections = [];
3152
+ for (let block = 0; block < blocks.length; block += 1) {
3153
+ const count = partCount(blocks, block);
3154
+ for (let part = 0; part < count; part += 1) sections.push({
3155
+ block,
3156
+ part
3157
+ });
3158
+ }
3159
+ return sections;
3160
+ }
3161
+ /**
3162
+ * Whether two cursors name the same section.
3163
+ * @param left - one cursor.
3164
+ * @param right - the other.
3165
+ * @returns true when both name the same block and part.
3166
+ */
3167
+ function sameSection(left, right) {
3168
+ return left.block === right.block && left.part === right.part;
3169
+ }
3170
+ /**
3171
+ * Index into a non-empty flattened section list.
3172
+ * @param sections - the flattened sections; length at least 1.
3173
+ * @param index - an in-range index.
3174
+ * @param fallback - used when that index has no section.
3175
+ * @returns that section.
3176
+ */
3177
+ function sectionAt(sections, index, fallback) {
3178
+ /* v8 ignore next -- callers pass an in-range index into a non-empty list */
3179
+ return sections[index] ?? fallback;
3180
+ }
3181
+ /**
3182
+ * Move to another section in reading order: the previous or next part of the
3183
+ * held block, or the last or first part of the neighbouring block that has
3184
+ * one. A block whose `parts()` is empty is skipped.
2452
3185
  * @param cursor - where the focus sits.
2453
- * @param step - 1 for the next block, -1 for the previous one.
3186
+ * @param step - 1 for the next section, -1 for the previous one.
2454
3187
  * @param blocks - the navigable blocks.
2455
- * @returns the new cursor; the cursor itself at either end of the list.
3188
+ * @returns the new cursor; the cursor itself at either end of the transcript.
2456
3189
  */
2457
- function moveBlock(cursor, step, blocks) {
2458
- const block = clampIndex(cursor.block + step, blocks.length);
2459
- if (block === cursor.block) return cursor;
2460
- return {
2461
- block,
2462
- part: Math.max(0, partCount(blocks, block) - 1)
2463
- };
3190
+ function moveSection(cursor, step, blocks) {
3191
+ const sections = flattenSections(blocks);
3192
+ if (sections.length === 0) return cursor;
3193
+ const settled = clampCursor(cursor, blocks);
3194
+ if (settled === void 0) {
3195
+ const index = step >= 0 ? sections.findIndex((section) => section.block > cursor.block) : sections.findLastIndex((section) => section.block < cursor.block);
3196
+ if (index < 0) return sectionAt(sections, step >= 0 ? sections.length - 1 : 0, cursor);
3197
+ return sectionAt(sections, index, cursor);
3198
+ }
3199
+ const index = sections.findIndex((section) => sameSection(section, settled));
3200
+ /* v8 ignore next -- a settled cursor is always in flattenSections */
3201
+ if (index < 0) return settled;
3202
+ return sectionAt(sections, clampIndex(index + step, sections.length), settled);
2464
3203
  }
2465
3204
  /**
2466
3205
  * Move between the parts of the held block.
@@ -2523,6 +3262,7 @@ function subjectOf(block, part) {
2523
3262
  case "user":
2524
3263
  case "assistant": return [partLabel(part.kind)];
2525
3264
  case "tool": return [block.title === "" ? block.name : `${block.name} ${block.title}`, block.parts().some((candidate) => candidate.kind === "result") ? partLabel(part.kind) : "running"];
3265
+ case "context": return part.label === void 0 || part.label === block.title ? [block.title] : [block.title, part.label];
2526
3266
  /* v8 ignore next -- closed-union exhaustiveness guard */
2527
3267
  default: return assertNever(block, "tui transcript block kind");
2528
3268
  }
@@ -2555,7 +3295,7 @@ function partLabels(cursor, blocks) {
2555
3295
  const block = blocks[cursor.block];
2556
3296
  if (block === void 0) return [];
2557
3297
  return block.parts().map((part, index) => ({
2558
- label: partLabel(part.kind),
3298
+ label: part.label ?? partLabel(part.kind),
2559
3299
  focused: index === cursor.part
2560
3300
  }));
2561
3301
  }
@@ -2841,6 +3581,19 @@ function todoLines(facts) {
2841
3581
  return [`todos: ${String(done)} done · ${String(active)} active · ${String(pending)} pending`, ...items.map((item) => ` ${TODO_GLYPH[item.status]} ${item.content}`)];
2842
3582
  }
2843
3583
  /**
3584
+ * One-line todo expansion for the status bar: the counts by status, and the
3585
+ * item being worked on, or the next pending item when none is in progress.
3586
+ * @param facts - the facts one status read produced.
3587
+ * @returns the expansion; empty when no todo list is known.
3588
+ */
3589
+ function todoSummary(facts) {
3590
+ if (facts.todos === void 0) return "";
3591
+ const { items, done, active, pending } = facts.todos;
3592
+ const counts = `todos: ${String(done)} done · ${String(active)} active · ${String(pending)} pending`;
3593
+ const current = items.find((item) => item.status === "in_progress") ?? items.find((item) => item.status === "pending");
3594
+ return current === void 0 ? counts : `${counts} · ${current.content}`;
3595
+ }
3596
+ /**
2844
3597
  * The goal section: phase, admitted rounds, objective, and the blocking
2845
3598
  * condition while the goal is blocked.
2846
3599
  * @param facts - the facts one status read produced.
@@ -2943,10 +3696,12 @@ function plural(count, noun) {
2943
3696
  * The status bar under the editor: plain session facts become an ordered list
2944
3697
  * of segments, each with a stable id, the short label the bar draws, and what
2945
3698
  * `Enter` on it does — the rows the app prints, or the app's own navigable
2946
- * page; a second function renders the segments as the footer's two lines, dim
2947
- * while the editor holds focus and with the selected segment accented while
2948
- * the bar does. Everything here is pure — no Context, no services, no
2949
- * terminal, and no clock: elapsed values arrive already formatted.
3699
+ * page with the one-line summary the focused bar expands; a second function
3700
+ * renders those segments as one unfocused line of key facts, or as two focused
3701
+ * lines whose first is a sliding window that always includes the selected
3702
+ * segment. Everything here is pure — no Context, no
3703
+ * services, no terminal, and no clock: elapsed values arrive already formatted,
3704
+ * and the terminal width arrives as an input so every line fits it.
2950
3705
  * @module @deepseek-ai/dsh-tui-app/footer
2951
3706
  */
2952
3707
  /** The segment focus enters the bar on; `buildFooterSegments` always emits it first. */
@@ -2962,21 +3717,30 @@ const SEPARATOR$1 = " · ";
2962
3717
  const WORKSPACE_LABEL_WIDTH = 24;
2963
3718
  /** The last two segments of a path, with the separators that precede them. */
2964
3719
  const PATH_TAIL = /[/\\][^/\\]+[/\\][^/\\]+$/u;
2965
- /** The keys the focused bar answers, replacing the usual hints. */
3720
+ /** The keys the focused bar answers, drawn on the expansion line. */
2966
3721
  const FOCUS_HINTS$1 = `← → select${SEPARATOR$1}↑ ↓ regions${SEPARATOR$1}Enter details${SEPARATOR$1}Esc back`;
2967
- /** What the unfocused hints advertise as the two ways out of the editor. */
2968
- const ENTRY_HINT = `Shift+↑ transcript${SEPARATOR$1}Shift+↓ status bar`;
3722
+ /** The one entry key the unfocused line keeps, trailing the facts. */
3723
+ const ENTRY_HINT = "Shift+↓";
3724
+ /** What ends a line the width cut short; one column, so the mark itself fits. */
3725
+ const ELLIPSIS = "…";
3726
+ /** Facts the unfocused line keeps; every other present segment folds into `+N`. */
3727
+ const KEY_SEGMENT_IDS = new Set([
3728
+ "model",
3729
+ "effort",
3730
+ "turn",
3731
+ "context",
3732
+ "todo",
3733
+ "workspace"
3734
+ ]);
2969
3735
  /** The command that prints every projection section at once. */
2970
3736
  const STATUS_COMMAND_ROW = "/status prints all of these sections";
2971
3737
  /**
2972
3738
  * What opening each projection-fact segment does: a section builder produces
2973
- * the rows the app prints, and `OPENED_PAGE` names a fact the app has its own
2974
- * navigable page for. The printed `/status` report still carries a todo
2975
- * section; the bar hands the todo list to the app instead.
3739
+ * the rows the app prints. The `todo` segment is a page instead: the bar
3740
+ * expands its counts on line 2 and the app opens the same list `/todos` opens.
2976
3741
  */
2977
3742
  const STATUS_SECTIONS = {
2978
3743
  context: contextLines,
2979
- todo: { kind: "page" },
2980
3744
  goal: goalLines,
2981
3745
  plan: planLines
2982
3746
  };
@@ -2992,6 +3756,17 @@ function printed(rows) {
2992
3756
  };
2993
3757
  }
2994
3758
  /**
3759
+ * A segment the app opens as a page, with the one-line summary the bar expands.
3760
+ * @param summary - the expansion the focused bar draws.
3761
+ * @returns the detail.
3762
+ */
3763
+ function openedPage(summary) {
3764
+ return {
3765
+ kind: "page",
3766
+ summary
3767
+ };
3768
+ }
3769
+ /**
2995
3770
  * The workspace label: a home-directory prefix becomes `~`, and a path still
2996
3771
  * wider than the bar allows keeps only its last two segments.
2997
3772
  * @param cwd - the workspace root.
@@ -3016,10 +3791,24 @@ function startsWithDirectory(path, directory) {
3016
3791
  return next === "" || next === "/" || next === "\\";
3017
3792
  }
3018
3793
  /**
3794
+ * The effort segment: always present, labelled `effort default` when the
3795
+ * selection leaves reasoning effort to the model.
3796
+ * @param effort - the selection's reasoning effort; absent is the model's own default.
3797
+ * @returns the segment.
3798
+ */
3799
+ function effortSegment(effort) {
3800
+ const unset = effort === void 0;
3801
+ return {
3802
+ id: "effort",
3803
+ label: unset ? "effort default" : `effort ${effort}`,
3804
+ detail: printed([unset ? "reasoning effort: the model's own default" : `reasoning effort: ${effort}`, `Shift+Tab cycles it${SEPARATOR$1}/effort picks one`])
3805
+ };
3806
+ }
3807
+ /**
3019
3808
  * Build the status bar's segments in the order it draws them: model, effort,
3020
- * permission, turn, usage, the projection facts, workspace, attachments. Only
3021
- * the model and workspace segments are always present; every other segment
3022
- * needs its fact.
3809
+ * permission, turn, usage, the projection facts, workspace, attachments. The
3810
+ * model, effort, and workspace segments are always present; every other
3811
+ * segment needs its fact.
3023
3812
  * @param inputs - the facts the app read for the bound session.
3024
3813
  * @returns the segments, the model segment first.
3025
3814
  */
@@ -3035,12 +3824,7 @@ function buildFooterSegments(inputs) {
3035
3824
  effort === void 0 ? "reasoning effort: the model's own default" : `reasoning effort: ${effort}`,
3036
3825
  "/model picks the provider and model for the next request"
3037
3826
  ])
3038
- }];
3039
- if (effort !== void 0) segments.push({
3040
- id: "effort",
3041
- label: `effort ${effort}`,
3042
- detail: printed([`reasoning effort: ${effort}`, `Shift+Tab cycles it${SEPARATOR$1}/effort picks one`])
3043
- });
3827
+ }, effortSegment(effort)];
3044
3828
  if (inputs.permission !== void 0) {
3045
3829
  const projected = permissionLines(facts);
3046
3830
  segments.push({
@@ -3069,11 +3853,19 @@ function buildFooterSegments(inputs) {
3069
3853
  ])
3070
3854
  });
3071
3855
  for (const part of footerStatus(facts)) {
3856
+ if (part.id === "todo") {
3857
+ segments.push({
3858
+ id: "todo",
3859
+ label: part.label,
3860
+ detail: openedPage(todoSummary(facts))
3861
+ });
3862
+ continue;
3863
+ }
3072
3864
  const section = STATUS_SECTIONS[part.id];
3073
3865
  segments.push({
3074
3866
  id: part.id,
3075
3867
  label: part.label,
3076
- detail: typeof section === "function" ? printed([...section(facts), STATUS_COMMAND_ROW]) : section
3868
+ detail: printed([...section(facts), STATUS_COMMAND_ROW])
3077
3869
  });
3078
3870
  }
3079
3871
  segments.push({
@@ -3099,20 +3891,142 @@ function footerSelectionIndex(segments, selected) {
3099
3891
  return index === -1 ? 0 : index;
3100
3892
  }
3101
3893
  /**
3102
- * Render the footer's two lines: the segment labels, then the key hints.
3103
- * Unfocused the whole bar is dim and the hints advertise the entry key;
3104
- * focused the selected segment is accented and the hints name the navigation
3105
- * keys instead.
3894
+ * Inclusive span of `widths` that contains `selected` and fits `budget`.
3895
+ * @param widths - visible width of each part, in order.
3896
+ * @param selected - the index that must stay in the span.
3897
+ * @param budget - maximum visible width of the joined span.
3898
+ * @param sep - visible width of the separator between two parts.
3899
+ * @returns start and end indices, inclusive.
3900
+ */
3901
+ function windowSpan(widths, selected, budget, sep) {
3902
+ let start = selected;
3903
+ let end = selected;
3904
+ let used = widths[selected];
3905
+ if (used >= budget) return {
3906
+ start,
3907
+ end
3908
+ };
3909
+ while (end + 1 < widths.length) {
3910
+ const next = used + sep + widths[end + 1];
3911
+ if (next > budget) break;
3912
+ end += 1;
3913
+ used = next;
3914
+ }
3915
+ while (start > 0) {
3916
+ const next = used + sep + widths[start - 1];
3917
+ if (next > budget) break;
3918
+ start -= 1;
3919
+ used = next;
3920
+ }
3921
+ return {
3922
+ start,
3923
+ end
3924
+ };
3925
+ }
3926
+ /**
3927
+ * Cut `line` to `width` columns.
3928
+ * @param line - the already-styled line.
3929
+ * @param width - terminal columns the line must fit; at least 1.
3930
+ * @returns the line, ellipsized when it was wider.
3931
+ */
3932
+ function fitLine(line, width) {
3933
+ return truncateToWidth(line, Math.max(1, width), ELLIPSIS);
3934
+ }
3935
+ /**
3936
+ * The unfocused line: key facts, a `+N` token for the rest, and the entry key.
3937
+ * @param segments - the segments in bar order.
3938
+ * @param palette - the palette the line is dimmed with.
3939
+ * @param width - terminal columns the line must fit.
3940
+ * @returns one dim line.
3941
+ */
3942
+ function unfocusedLine(segments, palette, width) {
3943
+ const key = segments.filter((segment) => KEY_SEGMENT_IDS.has(segment.id)).map((segment) => segment.label);
3944
+ const folded = segments.length - key.length;
3945
+ if (folded > 0) key.push(`+${String(folded)}`);
3946
+ key.push(ENTRY_HINT);
3947
+ return fitLine(palette.dim(key.join(SEPARATOR$1)), width);
3948
+ }
3949
+ /**
3950
+ * The first detail row of a printed segment, or the summary of a page segment.
3951
+ * @param segment - the selected segment; absent when the bar has none.
3952
+ * @returns the expansion body.
3953
+ */
3954
+ function expansionBody(segment) {
3955
+ if (segment === void 0) return "";
3956
+ if (segment.detail.kind === "page") return segment.detail.summary;
3957
+ return segment.detail.rows[0];
3958
+ }
3959
+ /**
3960
+ * The focused second line: the selected segment's summary plus the navigation keys.
3961
+ * @param segment - the selected segment.
3962
+ * @param palette - the palette the line is dimmed with.
3963
+ * @param width - terminal columns the line must fit.
3964
+ * @returns one dim line that keeps the hints when they fit.
3965
+ */
3966
+ function expansionLine(segment, palette, width) {
3967
+ const body = expansionBody(segment);
3968
+ const suffix = palette.dim(body === "" ? FOCUS_HINTS$1 : `${SEPARATOR$1}${FOCUS_HINTS$1}`);
3969
+ const prefix = palette.dim(body);
3970
+ const rest = width - visibleWidth(suffix);
3971
+ if (rest < 1) return fitLine(`${prefix}${suffix}`, width);
3972
+ return `${truncateToWidth(prefix, rest, ELLIPSIS)}${suffix}`;
3973
+ }
3974
+ /**
3975
+ * The focused bar: a sliding window of segment labels, then the expansion line.
3106
3976
  * @param segments - the segments in bar order.
3107
- * @param render - the palette, the selected index, and the unfocused hints.
3108
- * @returns the footer text, two lines separated by a newline.
3977
+ * @param selected - index of the held segment.
3978
+ * @param palette - the palette the labels and hints are styled with.
3979
+ * @param width - terminal columns each line must fit.
3980
+ * @returns two lines, the selected label always in the first.
3981
+ */
3982
+ function focusedLines(segments, selected, palette, width) {
3983
+ const held = Math.min(Math.max(0, selected), Math.max(0, segments.length - 1));
3984
+ const styled = segments.map((segment, index) => index === held ? palette.bold(palette.accent(segment.label)) : palette.dim(segment.label));
3985
+ const sep = palette.dim(SEPARATOR$1);
3986
+ const { start, end } = windowSpan(styled.map(visibleWidth), held, width, visibleWidth(sep));
3987
+ return [fitLine(styled.slice(start, end + 1).join(sep), width), expansionLine(segments[held], palette, width)];
3988
+ }
3989
+ /**
3990
+ * Render the footer. Unfocused it is one dim line of key facts with a trailing
3991
+ * `Shift+↓`; focused it is the navigable segments (windowed to `width` so the
3992
+ * selected one is never dropped) and an expansion of that segment plus the
3993
+ * navigation keys. Every returned line fits `width`.
3994
+ * @param segments - the segments in bar order.
3995
+ * @param render - the palette, optional selected index, and terminal width.
3996
+ * @returns the footer lines, one when unfocused and two when focused.
3109
3997
  */
3110
3998
  function renderFooter(segments, render) {
3111
- const { palette, selected, hints } = render;
3112
- const labels = segments.map((segment) => segment.label);
3113
- if (selected === void 0) return `${palette.dim(labels.join(SEPARATOR$1))}\n${palette.dim(`${hints}${SEPARATOR$1}${ENTRY_HINT}`)}`;
3114
- return `${labels.map((label, index) => index === selected ? palette.bold(palette.accent(label)) : palette.dim(label)).join(palette.dim(SEPARATOR$1))}\n${palette.dim(FOCUS_HINTS$1)}`;
3999
+ const width = Math.max(1, render.width);
4000
+ if (render.selected === void 0) return [unfocusedLine(segments, render.palette, width)];
4001
+ return focusedLines(segments, render.selected, render.palette, width);
3115
4002
  }
4003
+ /**
4004
+ * The status bar as a mounted component. The view is read once per render
4005
+ * rather than pushed in, so the terminal width of that frame windows and
4006
+ * truncates the lines.
4007
+ */
4008
+ var FooterBar = class {
4009
+ view;
4010
+ /**
4011
+ * @param view - reads the segments and selection the bar draws.
4012
+ */
4013
+ constructor(view) {
4014
+ this.view = view;
4015
+ }
4016
+ invalidate() {}
4017
+ /**
4018
+ * Draw the status bar at `width`.
4019
+ * @param width - the total width the bar lays out in.
4020
+ * @returns the footer lines, each no wider than `width`.
4021
+ */
4022
+ render(width) {
4023
+ const { segments, render } = this.view();
4024
+ return renderFooter(segments, {
4025
+ ...render,
4026
+ width
4027
+ });
4028
+ }
4029
+ };
3116
4030
  //#endregion
3117
4031
  //#region lib/types/prompts.js
3118
4032
  /**
@@ -3835,18 +4749,25 @@ function subagentPanelView(inputs) {
3835
4749
  };
3836
4750
  }
3837
4751
  /**
3838
- * Render the panel: a heading counting the listed children, one line per
3839
- * drawn row, the overflow count, and the last listing failure. The whole
3840
- * panel is dim while the keyboard is elsewhere; the selected row is accented
3841
- * while the panel holds it.
4752
+ * Render the panel. Unfocused it is one dim summary line — the listed count
4753
+ * and the first child's key label. Focused it is the heading with navigation
4754
+ * keys, one line per drawn row, the overflow count, and the last listing
4755
+ * failure. The selected row is accented while the panel holds the keyboard.
3842
4756
  * @param view - the rows one draw produced.
3843
4757
  * @param render - the palette, the selected row, and the listing failure.
3844
- * @returns the panel text, one line per row.
4758
+ * @returns the panel text, one line when unfocused and one line per row when focused.
3845
4759
  */
3846
4760
  function renderSubagentPanel(view, render) {
3847
4761
  const { palette, selected } = render;
3848
4762
  const total = view.rows.length + view.hidden;
3849
- const heading = `subagents${SEPARATOR}${String(total)} listed${selected === void 0 ? "" : `${SEPARATOR}${FOCUS_HINTS}`}`;
4763
+ if (selected === void 0) {
4764
+ const first = view.rows[0]?.text.trimStart().split(SEPARATOR)[0];
4765
+ const parts = [`subagents${SEPARATOR}${String(total)} listed`];
4766
+ if (first) parts.push(first);
4767
+ if (render.failure !== void 0) parts.push(`listing failed: ${render.failure}`);
4768
+ return palette.dim(parts.join(SEPARATOR));
4769
+ }
4770
+ const heading = `subagents${SEPARATOR}${String(total)} listed${SEPARATOR}${FOCUS_HINTS}`;
3850
4771
  const lines = [palette.dim(heading)];
3851
4772
  for (const [index, row] of view.rows.entries()) lines.push(index === selected ? palette.bold(palette.accent(row.text)) : palette.dim(row.text));
3852
4773
  if (view.hidden > 0) lines.push(palette.dim(`+${String(view.hidden)} more${SEPARATOR}/subagents lists them all`));
@@ -3863,8 +4784,8 @@ function renderSubagentPanel(view, render) {
3863
4784
  * the editor it keeps two docked regions the keyboard can take over — the
3864
4785
  * subagent panel and the status bar — and one repeating tick advances their
3865
4786
  * elapsed counters and re-reads a stale subagent listing. A second tick, at
3866
- * its own period, brightens the text of the message streaming right now and
3867
- * the tool cards that just landed, each only as far up the frame as the
4787
+ * its own period, brightens streamed reply text and floats out reasoning and
4788
+ * tool cards that just landed, each only as far up the frame as the
3868
4789
  * renderer repaints without discarding the terminal's scrollback
3869
4790
  * (`./screen.ts`).
3870
4791
  * @module @deepseek-ai/dsh-tui-app/app
@@ -4065,6 +4986,8 @@ var TuiApp = class {
4065
4986
  todoTurns = /* @__PURE__ */ new Map();
4066
4987
  /** The turn the last logged `turn/start` opened; 0 before the first one. */
4067
4988
  turn = 0;
4989
+ /** Whether a nonempty system prompt has already been drawn in this transcript. */
4990
+ sawSystemPrompt = false;
4068
4991
  /** When the running turn started, from its `turn/start` envelope; absent between turns. */
4069
4992
  turnStartedAt;
4070
4993
  pending = [];
@@ -4149,7 +5072,13 @@ var TuiApp = class {
4149
5072
  this.onSubmit(text);
4150
5073
  };
4151
5074
  this.panel = new Text("", 0, 0);
4152
- this.footer = new Text("", 0, 0);
5075
+ this.footer = new FooterBar(() => ({
5076
+ segments: this.segments,
5077
+ render: {
5078
+ palette: this.deps.palette,
5079
+ ...this.focus === "bar" ? { selected: footerSelectionIndex(this.segments, this.barSelection) } : {}
5080
+ }
5081
+ }));
4153
5082
  this.modals = new ModalQueue({
4154
5083
  tui: this.tui,
4155
5084
  slot: this.modalSlot,
@@ -4273,6 +5202,7 @@ var TuiApp = class {
4273
5202
  this.submittedIds.clear();
4274
5203
  this.todoTurns.clear();
4275
5204
  this.turn = 0;
5205
+ this.sawSystemPrompt = false;
4276
5206
  this.turnStartedAt = void 0;
4277
5207
  this.streaming = void 0;
4278
5208
  this.endFade();
@@ -4393,7 +5323,6 @@ var TuiApp = class {
4393
5323
  this.tui.requestRender();
4394
5324
  }
4395
5325
  refreshFooter() {
4396
- const palette = this.deps.palette;
4397
5326
  const permission = this.deps.ctx.get("permissionPresets")?.current(this.agent.session);
4398
5327
  const started = this.turnStartedAt;
4399
5328
  const inbox = this.agent.inbox;
@@ -4416,12 +5345,6 @@ var TuiApp = class {
4416
5345
  kind: attachment.block.type
4417
5346
  }))
4418
5347
  });
4419
- const hints = this.agent.status === "running" ? "Enter queues for the next turn · Ctrl+S steers this turn · Esc stops it · Ctrl+O tool output · Ctrl+C twice quits" : "Enter sends · Esc stops the turn · Ctrl+O tool output · Ctrl+C twice quits";
4420
- this.footer.setText(renderFooter(this.segments, {
4421
- palette,
4422
- ...this.focus === "bar" ? { selected: footerSelectionIndex(this.segments, this.barSelection) } : {},
4423
- hints
4424
- }));
4425
5348
  this.tui.requestRender();
4426
5349
  }
4427
5350
  /**
@@ -4866,7 +5789,8 @@ var TuiApp = class {
4866
5789
  /**
4867
5790
  * Answer the keys every non-editor region answers the same way: `Escape`
4868
5791
  * hands the keyboard back to the editor, `Shift+Up` names the conversation,
4869
- * and `Shift+Down` the status bar.
5792
+ * and `Shift+Down` the status bar. The transcript reads those two shift
5793
+ * arrows as a walk instead, so this helper is for the bar and the panel.
4870
5794
  * @param data - the raw key bytes.
4871
5795
  * @returns the consume marker when the key named a region, `undefined` when the focused region owns the key.
4872
5796
  */
@@ -4886,7 +5810,8 @@ var TuiApp = class {
4886
5810
  }
4887
5811
  /**
4888
5812
  * Answer one key while the status bar holds focus. Every key is consumed
4889
- * here, so nothing typed at the bar reaches the editor.
5813
+ * here, so nothing typed at the bar reaches the editor. `Shift+Left` and
5814
+ * `Shift+Right` move between segments the same way as `Left` and `Right`.
4890
5815
  * @param data - the raw key bytes.
4891
5816
  * @returns the consume marker the input listener returns.
4892
5817
  */
@@ -4898,11 +5823,11 @@ var TuiApp = class {
4898
5823
  else this.focusTranscript();
4899
5824
  return { consume: true };
4900
5825
  }
4901
- if (matchesKey(data, "left") || matchesKey(data, "shift+tab")) {
5826
+ if (matchesKey(data, "left") || matchesKey(data, "shift+left") || matchesKey(data, "shift+tab")) {
4902
5827
  this.moveStatusBar(-1);
4903
5828
  return { consume: true };
4904
5829
  }
4905
- if (matchesKey(data, "right") || matchesKey(data, "tab")) {
5830
+ if (matchesKey(data, "right") || matchesKey(data, "shift+right") || matchesKey(data, "tab")) {
4906
5831
  this.moveStatusBar(1);
4907
5832
  return { consume: true };
4908
5833
  }
@@ -4913,12 +5838,17 @@ var TuiApp = class {
4913
5838
  * Answer one key while the transcript holds focus. Every key is consumed
4914
5839
  * here, so nothing typed while reading the conversation reaches the editor;
4915
5840
  * `Ctrl+C` and `Ctrl+D` never reach this far and keep their global meaning.
5841
+ * `Up` / `Down` and `Shift+Up` / `Shift+Down` walk every section in reading
5842
+ * order; `Shift+Up` from the editor still enters on the newest section, and
5843
+ * `Shift+Down` from the editor still names the regions under it.
4916
5844
  * @param data - the raw key bytes.
4917
5845
  * @returns the consume marker the input listener returns.
4918
5846
  */
4919
5847
  onTranscriptKey(data) {
4920
- const region = this.onRegionKey(data);
4921
- if (region !== void 0) return region;
5848
+ if (matchesKey(data, "escape")) {
5849
+ this.focusEditor();
5850
+ return { consume: true };
5851
+ }
4922
5852
  const section = this.focusedSection();
4923
5853
  /* v8 ignore next 5 -- only a session change empties the transcript, and it hands the keyboard back first */
4924
5854
  if (section === void 0) {
@@ -4926,13 +5856,14 @@ var TuiApp = class {
4926
5856
  return { consume: true };
4927
5857
  }
4928
5858
  const { cursor, blocks } = section;
4929
- if (matchesKey(data, "up")) {
4930
- this.moveCursor(moveBlock(cursor, -1, blocks));
5859
+ if (matchesKey(data, "up") || matchesKey(data, "shift+up")) {
5860
+ this.moveCursor(moveSection(cursor, -1, blocks));
4931
5861
  return { consume: true };
4932
5862
  }
4933
- if (matchesKey(data, "down")) {
4934
- if (cursor.block === blocks.length - 1) this.focusBelowEditor();
4935
- else this.moveCursor(moveBlock(cursor, 1, blocks));
5863
+ if (matchesKey(data, "down") || matchesKey(data, "shift+down")) {
5864
+ const next = moveSection(cursor, 1, blocks);
5865
+ if (next.block === cursor.block && next.part === cursor.part) this.focusBelowEditor();
5866
+ else this.moveCursor(next);
4936
5867
  return { consume: true };
4937
5868
  }
4938
5869
  if (matchesKey(data, "left")) {
@@ -5112,7 +6043,8 @@ var TuiApp = class {
5112
6043
  heading: sectionHeading(cursor, blocks),
5113
6044
  parts: partLabels(cursor, blocks),
5114
6045
  rows: section.part.rows,
5115
- highlighted: this.highlighted !== void 0
6046
+ highlighted: this.highlighted !== void 0,
6047
+ complete: section.block.blockKind === "context"
5116
6048
  };
5117
6049
  }
5118
6050
  /** Hand the keyboard back to the editor; a no-op while the editor already has it. */
@@ -5297,7 +6229,7 @@ var TuiApp = class {
5297
6229
  "Esc stops the running turn · Ctrl+O expands or collapses tool output",
5298
6230
  "Shift+Tab cycles the current model's reasoning effort for the next request",
5299
6231
  "Shift+Up focuses the transcript, Shift+Down the subagent panel or the status bar",
5300
- "Then ↑ ↓ move between blocks, panel rows, and the bar; ← → move between a block's parts or the bar's segments",
6232
+ "Then ↑ ↓ walk every section, panel row, and bar segment; ← → move between a block's parts or the bar's segments (Shift+← → also move the bar)",
5301
6233
  "Enter opens the focused section or segment, Esc returns to the input",
5302
6234
  "Ctrl+C clears the input (twice quits) · Ctrl+D on an empty input quits"
5303
6235
  ];
@@ -5762,9 +6694,9 @@ var TuiApp = class {
5762
6694
  this.updateFadeTicker();
5763
6695
  }
5764
6696
  /**
5765
- * Take one reasoning delta, which fades in on its own tail: the reasoning
5766
- * and the visible text of one message stream at different times and each
5767
- * brightens from the moment its own words appeared.
6697
+ * Take one reasoning delta, which floats out on its own tail: the reasoning
6698
+ * and the visible text of one message stream at different times, and each
6699
+ * ages from the moment its own words appeared.
5768
6700
  * @param delta - the streamed reasoning delta.
5769
6701
  */
5770
6702
  appendStreamedReasoning(delta) {
@@ -5892,7 +6824,7 @@ var TuiApp = class {
5892
6824
  const section = this.focusedSection();
5893
6825
  const wanted = section !== void 0 && this.focus === "transcript" ? {
5894
6826
  block: section.block,
5895
- part: section.part.kind
6827
+ part: section.cursor.part
5896
6828
  } : void 0;
5897
6829
  const fades = this.fadesMoving();
5898
6830
  if (!fades && wanted === void 0 && this.highlighted === void 0) return false;
@@ -5982,6 +6914,9 @@ var TuiApp = class {
5982
6914
  case "user/message":
5983
6915
  this.onUserMessage(event.data);
5984
6916
  break;
6917
+ case "system/message":
6918
+ this.onSystemMessage(event.data);
6919
+ break;
5985
6920
  case "assistant/message": {
5986
6921
  const { message, usage, interrupted } = event.data;
5987
6922
  const text = message.content.filter((block) => block.type === "text").map((block) => block.text).join("");
@@ -6085,7 +7020,19 @@ var TuiApp = class {
6085
7020
  this.chat.addChild(new UserBlock(this.theme, [contentText(message.content), ...attachments].filter((part) => part !== "").join("\n"), this.turn));
6086
7021
  return;
6087
7022
  }
6088
- if (source.kind === "plugin" && source.form === "notice") this.chat.addChild(new NoticeBlock(this.theme, source.summary));
7023
+ const view = injectedContextView(source, message.content);
7024
+ if (view === void 0) return;
7025
+ this.chat.addChild(new ContextBlock(this.theme, view.title, view.parts, this.turn));
7026
+ }
7027
+ /**
7028
+ * Draw one nonempty system prompt as a navigable context block.
7029
+ * @param data - the durable `system/message` payload.
7030
+ */
7031
+ onSystemMessage(data) {
7032
+ const view = systemPromptView(contentText(data.message.content), this.sawSystemPrompt);
7033
+ if (view === void 0) return;
7034
+ this.sawSystemPrompt = true;
7035
+ this.chat.addChild(new ContextBlock(this.theme, view.title, view.parts, data.turn));
6089
7036
  }
6090
7037
  presentCall(name, args) {
6091
7038
  const definition = this.deps.ctx.get("tools")?.get(name, this.agent);