@songtonyli/dsh-cli 0.1.25 → 0.1.27

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.
@@ -8,7 +8,7 @@ import { canOpenNativePath, openNativeUrl } from "@deepseek-ai/dsh-native-comman
8
8
  import { SessionLogOffset } from "@deepseek-ai/dsh-session";
9
9
  import { homedir } from "node:os";
10
10
  import "@deepseek-ai/cordis";
11
- import { HarnessError, ReasoningEffortId, createUserMessage } from "@deepseek-ai/dsh-llm";
11
+ import { HarnessError, ReasoningEffortId, boundContextSummary, createUserMessage } from "@deepseek-ai/dsh-llm";
12
12
  import { activeAtToken, formatFileMention } from "@deepseek-ai/dsh-file-reference";
13
13
  import { formatSessionReferenceMention } from "@deepseek-ai/dsh-session-reference";
14
14
  import { assertNever } from "@deepseek-ai/dsh-util-values";
@@ -45,6 +45,130 @@ var AuthorizationDeclinedError = class extends AuthorizationError {
45
45
  }
46
46
  };
47
47
  //#endregion
48
+ //#region lib/types/alt-screen.js
49
+ /**
50
+ * The terminal's alternate screen, which a surface that owns the whole
51
+ * terminal draws on.
52
+ *
53
+ * A terminal keeps two screens. The main one is the conversation's own
54
+ * scrollback, which every line the application has ever printed belongs to;
55
+ * the alternate one is a scratch screen exactly `terminal.rows` tall with no
56
+ * scrollback at all, the screen a pager or an editor runs on. Switching to it
57
+ * saves the main screen, and switching back restores it unchanged: the
58
+ * surface drawn here cannot rewrite a line of the conversation, cannot scroll
59
+ * one out of the viewport, and leaves nothing of itself behind when it goes -
60
+ * none of which an overlay drawn over the conversation can promise, because
61
+ * its rows are the main screen's rows and become its scrollback.
62
+ *
63
+ * The screen is addressed by absolute row: every line is drawn where it
64
+ * belongs rather than by printing downward, so nothing here ever scrolls the
65
+ * terminal. Each paint writes only the rows whose text changed since the last
66
+ * one, wrapped in one synchronized-output pair so the terminal shows whole
67
+ * frames.
68
+ * @module @deepseek-ai/dsh-tui-app/alt-screen
69
+ */
70
+ /** Switch to the alternate screen, saving the main one. */
71
+ const ENTER = "\x1B[?1049h";
72
+ /** Switch back to the main screen, restoring it as it was. */
73
+ const LEAVE = "\x1B[?1049l";
74
+ /** Clear the whole screen. */
75
+ const CLEAR = "\x1B[2J";
76
+ /** Clear the row the cursor is on. */
77
+ const CLEAR_ROW = "\x1B[2K";
78
+ /** Stop drawing the terminal's own caret. */
79
+ const HIDE_CARET = "\x1B[?25l";
80
+ /** Draw the terminal's own caret again. */
81
+ const SHOW_CARET = "\x1B[?25h";
82
+ /**
83
+ * Stop wrapping at the right margin, so a line that fills the last row cannot
84
+ * scroll the screen.
85
+ */
86
+ const NO_AUTOWRAP = "\x1B[?7l";
87
+ /** Wrap at the right margin again, which is what the conversation needs. */
88
+ const AUTOWRAP = "\x1B[?7h";
89
+ /** Hold the frame back until every row of it has been written. */
90
+ const BEGIN_FRAME = "\x1B[?2026h";
91
+ /** Show the frame. */
92
+ const END_FRAME = "\x1B[?2026l";
93
+ /**
94
+ * The alternate screen as one surface: enter it, paint frames on it, leave it.
95
+ *
96
+ * Entering and leaving are balanced and idempotent, so a caller that takes the
97
+ * terminal twice, or gives it back twice, still leaves the terminal on the
98
+ * screen it started on.
99
+ */
100
+ var AlternateScreen = class {
101
+ terminal;
102
+ /** The rows the last paint left on the screen, which the next one is drawn against. */
103
+ drawn = [];
104
+ /** The terminal width the drawn rows were written at, so a resize repaints them all. */
105
+ drawnWidth = 0;
106
+ entered = false;
107
+ /**
108
+ * @param terminal - the terminal whose two screens these are.
109
+ */
110
+ constructor(terminal) {
111
+ this.terminal = terminal;
112
+ }
113
+ /** Whether the alternate screen is the one the terminal is showing. */
114
+ get active() {
115
+ return this.entered;
116
+ }
117
+ /**
118
+ * Take the terminal, saving the main screen and clearing this one.
119
+ *
120
+ * The caret is the surface's to draw, and none of the surfaces here draw
121
+ * one, so it is hidden for as long as this screen is up.
122
+ */
123
+ enter() {
124
+ if (this.entered) return;
125
+ this.entered = true;
126
+ this.drawn = [];
127
+ this.drawnWidth = this.terminal.columns;
128
+ this.terminal.write(`${ENTER}${NO_AUTOWRAP}${HIDE_CARET}${CLEAR}`);
129
+ }
130
+ /**
131
+ * Draw one frame.
132
+ * @param lines - the frame, one entry per screen row from the top; rows the
133
+ * frame no longer has are cleared. Nothing is written while the main screen
134
+ * is the one the terminal shows.
135
+ */
136
+ paint(lines) {
137
+ if (!this.entered) return;
138
+ if (this.terminal.columns !== this.drawnWidth) {
139
+ this.drawn = [];
140
+ this.drawnWidth = this.terminal.columns;
141
+ }
142
+ let frame = BEGIN_FRAME;
143
+ for (const [row, line] of lines.entries()) {
144
+ if (this.drawn[row] === line) continue;
145
+ frame += `${cursorTo(row)}${CLEAR_ROW}${line}`;
146
+ }
147
+ for (let row = lines.length; row < this.drawn.length; row += 1) frame += `${cursorTo(row)}${CLEAR_ROW}`;
148
+ this.drawn = [...lines];
149
+ frame += END_FRAME;
150
+ this.terminal.write(frame);
151
+ }
152
+ /**
153
+ * Give the terminal back, which restores the main screen exactly as it was
154
+ * when {@link AlternateScreen.enter} saved it.
155
+ */
156
+ leave() {
157
+ if (!this.entered) return;
158
+ this.entered = false;
159
+ this.drawn = [];
160
+ this.terminal.write(`${BEGIN_FRAME}${LEAVE}${AUTOWRAP}${SHOW_CARET}${END_FRAME}`);
161
+ }
162
+ };
163
+ /**
164
+ * Move the cursor to the first column of one screen row.
165
+ * @param row - the row, counted from 0 at the top of the screen.
166
+ * @returns the escape sequence that puts the cursor there.
167
+ */
168
+ function cursorTo(row) {
169
+ return `\u001b[${String(row + 1)};1H`;
170
+ }
171
+ //#endregion
48
172
  //#region lib/types/attach.js
49
173
  /**
50
174
  * `/attach`: read a local file and admit it into the attachment store as the
@@ -2021,8 +2145,7 @@ function paintLine(text, runs, restore) {
2021
2145
  //#region lib/types/motion.js
2022
2146
  /**
2023
2147
  * Chrome motion: the brief lift a docked surface draws when the keyboard
2024
- * lands on it or the mark it holds moves, and the reveal the full-screen
2025
- * reader grows and shrinks through.
2148
+ * lands on it or the mark it holds moves.
2026
2149
  *
2027
2150
  * Pure. A motion is a clock plus a three-level intensity ramp, so nothing
2028
2151
  * here queries a terminal, builds a color, or arms a timer: the application
@@ -3385,6 +3508,79 @@ var BarCursorEditor = class extends Editor {
3385
3508
  });
3386
3509
  }
3387
3510
  };
3511
+ //#endregion
3512
+ //#region lib/types/shell-line.js
3513
+ /**
3514
+ * Parse and present a user-typed `!` / `!!` shell line. The terminal runs the
3515
+ * command itself; `!` becomes next-step context and `!!` stays local.
3516
+ * @module @deepseek-ai/dsh-tui-app/shell-line
3517
+ */
3518
+ /**
3519
+ * Read a submitted editor line as a user shell command.
3520
+ * @param text - the trimmed editor text.
3521
+ * @returns the command and whether it is excluded, or undefined when the line
3522
+ * is not a nonempty `!` / `!!` prefix.
3523
+ */
3524
+ function parseUserShellLine(text) {
3525
+ const trimmed = text.trim();
3526
+ if (!trimmed.startsWith("!")) return void 0;
3527
+ const excluded = trimmed.startsWith("!!");
3528
+ const command = (excluded ? trimmed.slice(2) : trimmed.slice(1)).trim();
3529
+ return command === "" ? void 0 : {
3530
+ command,
3531
+ excluded
3532
+ };
3533
+ }
3534
+ /**
3535
+ * Shape one finished run as the text the next model request reads.
3536
+ * @param command - the command the user typed after `!`.
3537
+ * @param result - the completed foreground run.
3538
+ * @returns the model-facing notice body.
3539
+ */
3540
+ function userShellContextText(command, result) {
3541
+ const output = combinedOutput(result);
3542
+ let text = `The user ran \`${command}\` in the terminal.\n`;
3543
+ text += output === "" ? "(no output)" : `\`\`\`\n${output}\n\`\`\``;
3544
+ if (result.aborted) text += "\n\n(command cancelled)";
3545
+ else if (result.timedOut) text += `\n\n[timed out after ${String(result.timeoutMs)}ms]`;
3546
+ else if (result.signal !== null) text += `\n\n[killed by signal: ${result.signal}]`;
3547
+ else if (result.exitCode !== null && result.exitCode !== 0) text += `\n\nCommand exited with code ${String(result.exitCode)}`;
3548
+ return text;
3549
+ }
3550
+ /**
3551
+ * Shape one finished run as the rows the transcript draws immediately.
3552
+ * @param command - the command the user typed after `!`.
3553
+ * @param result - the completed foreground run.
3554
+ * @returns `$ command`, any output, and a cancel or nonzero-exit marker.
3555
+ */
3556
+ function userShellTranscriptRows(command, result) {
3557
+ const output = combinedOutput(result);
3558
+ const rows = [`$ ${command}`];
3559
+ if (output !== "") rows.push(output);
3560
+ if (result.aborted) rows.push("(command cancelled)");
3561
+ else if (result.exitCode !== null && result.exitCode !== 0) rows.push(`(exit ${String(result.exitCode)})`);
3562
+ return rows;
3563
+ }
3564
+ /**
3565
+ * Join stdout and a marked stderr section, dropping a single trailing newline
3566
+ * so a fenced body does not carry a blank last line.
3567
+ * @param result - the completed foreground run.
3568
+ * @returns the combined body, or the empty string when both streams are empty.
3569
+ */
3570
+ function combinedOutput(result) {
3571
+ const out = streamText(result.stdout);
3572
+ const err = streamText(result.stderr);
3573
+ if (err === "") return out;
3574
+ return out === "" ? `[stderr]\n${err}` : `${out}\n[stderr]\n${err}`;
3575
+ }
3576
+ /**
3577
+ * Take one collected stream, appending its truncation marker when present.
3578
+ * @param output - one captured stream.
3579
+ * @returns the text without a single trailing newline.
3580
+ */
3581
+ function streamText(output) {
3582
+ return (output.truncated ? `${output.text}\n[output truncated; full output: ${output.spillPath ?? "(unavailable)"}]` : output.text).replace(/\n$/u, "");
3583
+ }
3388
3584
  /** What the provider-default row is called. */
3389
3585
  const PROVIDER_DEFAULT_LABEL = "Provider default";
3390
3586
  /** The `/effort` argument that restores the provider default. */
@@ -3700,6 +3896,7 @@ const KEY_LINES = {
3700
3896
  "Enter sends · Shift+Enter newline · ↑↓ history · Ctrl+S steers",
3701
3897
  "Shift+Tab effort list · Shift+←→ words",
3702
3898
  "@ completes paths and sessions · / completes commands · Tab takes one",
3899
+ "!cmd runs here · the next prompt can read it · !!cmd stays local",
3703
3900
  `${ENTRY_KEYS} · Ctrl+G reader`,
3704
3901
  "Ctrl+O folds every tool card and context row",
3705
3902
  "Esc arms the stop · Esc again stops the turn",
@@ -6057,6 +6254,8 @@ var ModalQueue = class {
6057
6254
  */
6058
6255
  /**
6059
6256
  * Build the panel rows in claim order: next-step input before ordinary turns.
6257
+ * Messages whose source is not `user` are omitted: a `!` notice waiting for
6258
+ * the next prompt is context, not a prompt the keyboard can steer or edit.
6060
6259
  * @param nextStep - messages waiting for the nearest step boundary.
6061
6260
  * @param nextTurn - messages waiting for separate turns.
6062
6261
  * @returns selectable pending-prompt rows.
@@ -6067,7 +6266,8 @@ function queuePanelRows(nextStep, nextTurn) {
6067
6266
  target,
6068
6267
  text: contentText(message.content).split("\n", 1)[0] ?? ""
6069
6268
  });
6070
- return [...nextStep.map((message) => row("next-step", message)), ...nextTurn.map((message) => row("next-turn", message))];
6269
+ const pending = (target, messages) => messages.filter((message) => message.source.kind === "user").map((message) => row(target, message));
6270
+ return [...pending("next-step", nextStep), ...pending("next-turn", nextTurn)];
6071
6271
  }
6072
6272
  /**
6073
6273
  * Render the pending prompts inside a frame. A focused panel accents its held
@@ -6803,29 +7003,24 @@ function readerRows(state, groups, render) {
6803
7003
  ];
6804
7004
  }
6805
7005
  //#endregion
6806
- //#region lib/types/reader-overlay.js
7006
+ //#region lib/types/reader-screen.js
6807
7007
  /**
6808
- * The reader as a mounted overlay: the component pi-tui composites over the
6809
- * viewport, and the key map that drives it.
6810
- *
6811
- * It costs the frame no rows. pi-tui composites an overlay into the last
6812
- * terminal-height lines of the frame after the tree rendered, so the
6813
- * conversation underneath keeps every line it had and the renderer's repaint
6814
- * boundary is never raised. The application places it against the bottom of
6815
- * the viewport and tells it how many rows it may draw, which is one fewer for
6816
- * every viewport line the renderer can no longer repaint; the pane fills
6817
- * exactly that many.
7008
+ * The reader as the surface that owns the terminal: the pane drawn on the
7009
+ * alternate screen, and the key map that drives it.
6818
7010
  *
6819
- * Opening and closing are the two moments it moves: the application hands the
6820
- * pane a reveal it reads per render, and the pane draws that share of its
6821
- * frame from the bottom rule up, so the reader rises into place and sinks
6822
- * away without the frame underneath it gaining or losing a line.
7011
+ * It costs the conversation nothing at all. The application switches the
7012
+ * terminal to its alternate screen (`./alt-screen.ts`) and holds the
7013
+ * main screen off it for as long as the reader is up, so the conversation
7014
+ * keeps every line it had, the renderer's repaint boundary never moves, and
7015
+ * no row the reader draws can reach the terminal's scrollback. The pane fills
7016
+ * the screen: it is told how many rows the terminal has and returns exactly
7017
+ * that many.
6823
7018
  *
6824
7019
  * The pane holds no copy of the transcript: it re-reads the blocks and their
6825
7020
  * turns on every render, so a reply that is still streaming grows inside it,
6826
7021
  * a tool result that lands appears, and a new turn joins the list, all with
6827
7022
  * no push and no second clock.
6828
- * @module @deepseek-ai/dsh-tui-app/reader-overlay
7023
+ * @module @deepseek-ai/dsh-tui-app/reader-screen
6829
7024
  */
6830
7025
  /** The key that opens the query line. */
6831
7026
  const FILTER_KEY = "/";
@@ -6835,9 +7030,6 @@ const FILTER_KEY = "/";
6835
7030
  */
6836
7031
  var ReaderPane = class {
6837
7032
  options;
6838
- /** Where the reader left the keyboard and the reading. */
6839
- settled;
6840
- resolve;
6841
7033
  /** Whether the reader is still open; a second close is ignored. */
6842
7034
  open = true;
6843
7035
  state;
@@ -6850,9 +7042,6 @@ var ReaderPane = class {
6850
7042
  */
6851
7043
  constructor(options) {
6852
7044
  this.options = options;
6853
- this.settled = new Promise((resolve) => {
6854
- this.resolve = resolve;
6855
- });
6856
7045
  this.state = {
6857
7046
  cursor: options.cursor,
6858
7047
  column: "pane",
@@ -6862,11 +7051,9 @@ var ReaderPane = class {
6862
7051
  invalidate() {}
6863
7052
  /**
6864
7053
  * Draw the reader at `width`.
6865
- * @param width - the columns the overlay was laid out at.
6866
- * @returns as many lines as `rows()` reports, so the overlay covers the
6867
- * viewport it was placed in - fewer while a reveal is still growing or
6868
- * shrinking it - and blank lines once the transcript it was reading is
6869
- * gone.
7054
+ * @param width - the columns the screen has.
7055
+ * @returns as many lines as `rows()` reports, so the reader covers the
7056
+ * screen, and blank lines once the transcript it was reading is gone.
6870
7057
  */
6871
7058
  render(width) {
6872
7059
  this.width = width;
@@ -6896,23 +7083,7 @@ var ReaderPane = class {
6896
7083
  rows,
6897
7084
  minColumns: this.options.minColumns,
6898
7085
  totalTurns: groups.length
6899
- }).slice(rows - this.drawnRows(rows));
6900
- }
6901
- /**
6902
- * How many of the frame's lines the reveal draws right now.
6903
- *
6904
- * The overlay is anchored at the bottom of the viewport, so a pane that
6905
- * draws fewer lines keeps every line it does draw on the terminal row it
6906
- * will settle on: the reader rises into place rather than sliding, and the
6907
- * conversation above it keeps its own lines throughout.
6908
- * @param rows - the height the frame was laid out at.
6909
- * @returns the lines to keep, counted from the bottom rule up; at least one
6910
- * and never more than the frame has.
6911
- */
6912
- drawnRows(rows) {
6913
- const reveal = this.options.reveal?.() ?? 1;
6914
- if (reveal >= 1) return rows;
6915
- return Math.max(1, Math.min(rows, Math.ceil(reveal * rows)));
7086
+ });
6916
7087
  }
6917
7088
  /**
6918
7089
  * Answer one key press.
@@ -6946,7 +7117,7 @@ var ReaderPane = class {
6946
7117
  * The geometry of the frame as it stands.
6947
7118
  * @param visible - the turns the rail lists.
6948
7119
  * @param blocks - the navigable blocks.
6949
- * @param rows - the rows the overlay draws.
7120
+ * @param rows - the rows the screen has.
6950
7121
  * @returns the geometry, with the walking pane measured.
6951
7122
  */
6952
7123
  geometryFor(visible, blocks, rows) {
@@ -6959,7 +7130,7 @@ var ReaderPane = class {
6959
7130
  close(target) {
6960
7131
  if (!this.open) return;
6961
7132
  this.open = false;
6962
- this.resolve({
7133
+ this.options.onExit({
6963
7134
  cursor: this.state.cursor,
6964
7135
  target
6965
7136
  });
@@ -7432,6 +7603,12 @@ var SyntaxHighlighter = class {
7432
7603
  * far into a block the renderer can still follow it, and
7433
7604
  * {@link GuardedMainScreen} gives the application the one moment where that
7434
7605
  * question can be answered: after a frame was built and before it is written.
7606
+ *
7607
+ * {@link GuardedMainScreen.suspend} is the other half of that rule: a
7608
+ * full-screen surface that takes the terminal holds the main screen off it
7609
+ * entirely rather than drawing over the conversation, so no line of the
7610
+ * conversation is rewritten while the surface is up and none of the surface's
7611
+ * own rows can reach the terminal's scrollback.
7435
7612
  * @module @deepseek-ai/dsh-tui-app/screen
7436
7613
  */
7437
7614
  /**
@@ -7453,40 +7630,6 @@ function repaintFloor(start, viewportTop) {
7453
7630
  return Math.max(0, viewportTop - start);
7454
7631
  }
7455
7632
  /**
7456
- * Blank rows at the foot of the frame, which a surface mounts while it needs
7457
- * the whole viewport.
7458
- *
7459
- * The renderer repaints a line only at or after {@link repaintFloor}'s own
7460
- * `viewportTop`, a high-water mark a taller frame raises for good. A frame
7461
- * that has since shrunk therefore leaves the top of the viewport out of
7462
- * reach, and an overlay that may not draw there stops short of the screen.
7463
- * These rows push the frame back up to that mark: the terminal scrolls by
7464
- * exactly the shortfall, every line of the viewport becomes repaintable
7465
- * again, and an overlay composited into the frame's last `terminal.rows`
7466
- * lines covers all of them. They are never seen - the overlay is drawn over
7467
- * them, and they are gone before it is.
7468
- *
7469
- * pi-tui's `Text` drops blank lines, so the rows are a component of their own.
7470
- */
7471
- var ViewportPad = class {
7472
- rows;
7473
- /**
7474
- * @param rows - how many blank lines to draw, read on every render.
7475
- */
7476
- constructor(rows) {
7477
- this.rows = rows;
7478
- }
7479
- invalidate() {}
7480
- /**
7481
- * Draw the pad.
7482
- * @returns that many empty lines, and none at all where the frame already
7483
- * reaches the mark.
7484
- */
7485
- render() {
7486
- return Array.from({ length: Math.max(0, this.rows()) }, () => "");
7487
- }
7488
- };
7489
- /**
7490
7633
  * The main screen that settles each frame between building it and writing it.
7491
7634
  *
7492
7635
  * The guard is handed the frame's first repaintable line: the higher of the
@@ -7497,9 +7640,17 @@ var ViewportPad = class {
7497
7640
  * tomorrow. Settling before the write also means a fade reaches the terminal
7498
7641
  * already settled instead of changing in the next frame, by which time its
7499
7642
  * lines may sit above the window.
7643
+ *
7644
+ * It can also be suspended, which stops every write to the terminal while
7645
+ * leaving the renderer's record of the main screen exactly as it was. The
7646
+ * terminal restores that same screen when the surface that took it gives it
7647
+ * back, so the first frame after {@link GuardedMainScreen.resume} writes only
7648
+ * what changed meanwhile.
7500
7649
  */
7501
7650
  var GuardedMainScreen = class extends TuiMainScreen {
7502
7651
  guard;
7652
+ /** What draws instead while another surface holds the terminal; absent while this screen does. */
7653
+ onSuspendedRender;
7503
7654
  /**
7504
7655
  * @param terminal - the terminal the tree renders into.
7505
7656
  * @param showHardwareCursor - whether the terminal's own cursor is the caret.
@@ -7515,6 +7666,57 @@ var GuardedMainScreen = class extends TuiMainScreen {
7515
7666
  this.guard = guard;
7516
7667
  }
7517
7668
  /**
7669
+ * Stop writing to the terminal, and answer every render request with
7670
+ * `onRender` instead.
7671
+ *
7672
+ * Nothing about the renderer's record of the main screen changes, so the
7673
+ * frame it will judge its next write against stays the frame the terminal
7674
+ * still holds behind the surface that took over.
7675
+ * @param onRender - called wherever a frame would have been written, so the
7676
+ * surface that owns the terminal draws on the application's existing render
7677
+ * requests rather than on a clock of its own.
7678
+ */
7679
+ suspend(onRender) {
7680
+ this.onSuspendedRender = onRender;
7681
+ }
7682
+ /** Write to the terminal again, and draw whatever changed while suspended. */
7683
+ resume() {
7684
+ if (this.onSuspendedRender === void 0) return;
7685
+ this.onSuspendedRender = void 0;
7686
+ this.requestRender();
7687
+ }
7688
+ /**
7689
+ * Request a frame, or draw the surface that suspended this screen.
7690
+ * @param force - redraw from scratch; ignored while suspended, where
7691
+ * discarding the record would lose the screen the terminal is holding.
7692
+ */
7693
+ requestRender(force = false) {
7694
+ const suspended = this.onSuspendedRender;
7695
+ if (suspended === void 0) {
7696
+ super.requestRender(force);
7697
+ return;
7698
+ }
7699
+ suspended();
7700
+ }
7701
+ /**
7702
+ * Write a frame now, or draw the suspending surface now.
7703
+ * @param force - redraw from scratch; ignored while suspended, as in
7704
+ * {@link GuardedMainScreen.requestRender}.
7705
+ */
7706
+ renderNow(force = false) {
7707
+ const suspended = this.onSuspendedRender;
7708
+ if (suspended === void 0) {
7709
+ super.renderNow(force);
7710
+ return;
7711
+ }
7712
+ suspended();
7713
+ }
7714
+ /** Write the frame, unless another surface holds the terminal. */
7715
+ doRender() {
7716
+ if (this.onSuspendedRender !== void 0) return;
7717
+ super.doRender();
7718
+ }
7719
+ /**
7518
7720
  * Build the frame, let the guard settle what its geometry decides, and build
7519
7721
  * it again for every pass that changed a line.
7520
7722
  * @param width - the total width the tree lays out in.
@@ -7696,8 +7898,6 @@ function renderSubagentPanel(view, render) {
7696
7898
  const QUIT_TOAST = "press Ctrl+C again to quit";
7697
7899
  /** What the line says when the transcript holds nothing the reader could open. */
7698
7900
  const NOTHING_TO_READ_TOAST = "nothing in the transcript to read yet";
7699
- /** What the line says when a fold key named a block the renderer can no longer rewrite. */
7700
- const ABOVE_WINDOW_TOAST = "above the repaint window · opened in the reader";
7701
7901
  /**
7702
7902
  * What the line says while the stop is armed. It names the turn it would
7703
7903
  * stop, so a press after a turn boundary is read for what it is.
@@ -7907,21 +8107,8 @@ function splitModelValue(value) {
7907
8107
  }
7908
8108
  /** What the transcript is told when a session switch took the conversation the reader was showing. */
7909
8109
  const READER_GONE = "the transcript changed · reader closed";
7910
- /**
7911
- * How the reader is mounted: the whole viewport, anchored at its bottom edge.
7912
- *
7913
- * pi-tui composites an overlay into the last `terminal.rows` lines of the
7914
- * frame, so anchoring at the bottom puts the pane's first line exactly on the
7915
- * frame's last repaintable line whatever the frame's own length is - and the
7916
- * pane draws one line fewer for every viewport line the renderer can no
7917
- * longer repaint ({@link TuiApp.viewportFloor}), so opening the reader never
7918
- * rewrites a line above the window.
7919
- */
7920
- const READER_OVERLAY = {
7921
- width: "100%",
7922
- maxHeight: "100%",
7923
- anchor: "bottom-left"
7924
- };
8110
+ /** What the transcript is told when a fold key named a block the renderer can no longer rewrite. */
8111
+ const ABOVE_WINDOW_NOTICE = "above the repaint window · opened in the reader";
7925
8112
  /**
7926
8113
  * Row layout of the todo picker: the label column grows with the widest todo
7927
8114
  * line instead of stopping at the list's 32-column default, which would cut a
@@ -8136,6 +8323,10 @@ const LOCAL_COMMANDS = [
8136
8323
  function isSubscriptionMethod(method) {
8137
8324
  return method.id !== "api-key";
8138
8325
  }
8326
+ /** Shown when `!` is submitted and this composition has no `ctx.shell`. */
8327
+ const SHELL_MISSING = "! needs a shell executor in this composition";
8328
+ /** Shown when a second `!` is submitted while one is still running. */
8329
+ const SHELL_BUSY = "A shell command is already running. Press Esc to cancel it first.";
8139
8330
  /** The interactive terminal application; one instance per process. */
8140
8331
  var TuiApp = class {
8141
8332
  deps;
@@ -8162,8 +8353,8 @@ var TuiApp = class {
8162
8353
  transferringQueue = false;
8163
8354
  /** Holds {@link panel} exactly while the bound session has subagent rows. */
8164
8355
  panelSlot = new Container();
8165
- /** Blank rows that give the mounted reader the whole viewport; see {@link ViewportPad}. */
8166
- pad = new ViewportPad(() => this.readerPad);
8356
+ /** The terminal's alternate screen, which the reader draws on; see {@link AlternateScreen}. */
8357
+ readerScreen;
8167
8358
  /** Colours fenced code in replies; see {@link SyntaxHighlighter}. */
8168
8359
  codeHighlight;
8169
8360
  /** The terminal's background once it answered; undefined until then, and on a terminal that answers none. */
@@ -8235,24 +8426,23 @@ var TuiApp = class {
8235
8426
  chrome;
8236
8427
  /** The lift the subagent panel's text was last built with, which only a repaint changes. */
8237
8428
  panelLift = 0;
8238
- /** The reader on screen right now, while one is open. */
8429
+ /** The reader on the alternate screen right now, while one is open. */
8239
8430
  reader;
8240
- /** Blank rows {@link ViewportPad} draws so the mounted reader covers the whole viewport. */
8241
- readerPad = 0;
8242
- /** The motion growing the open reader into place; settled or absent draws it whole. */
8243
- readerOpening;
8244
- /** The reader shrinking away, still mounted until its motion settles. */
8245
- readerClosing;
8431
+ /** Set while a paint of the open reader is already queued for this turn of the loop. */
8432
+ readerPaintQueued = false;
8246
8433
  /** Prompts shown or waiting on the modal queue, which the reader steps aside for. */
8247
8434
  queuedModals = 0;
8248
8435
  /** Until when an `Escape` that reaches the editor does nothing at all. */
8249
8436
  escapeQuietUntil = 0;
8250
8437
  /** Until when a second editor `Escape` stops the running turn. */
8251
8438
  stopArmedUntil = 0;
8439
+ /** Abort of the in-flight user `!` command, when one is running. */
8440
+ shellAbort;
8252
8441
  /**
8253
8442
  * How many of the viewport's own first lines the renderer can no longer
8254
- * repaint, from the last frame the guard settled. An overlay composites
8255
- * into those lines, so this is what decides where one can be drawn.
8443
+ * repaint, from the last frame the guard settled. The transient line
8444
+ * composites into those lines, so this is what decides whether it can float
8445
+ * at all.
8256
8446
  */
8257
8447
  viewportFloor = 0;
8258
8448
  /** Set while {@link TuiApp.bind} replays a session's history, which draws its cards settled. */
@@ -8300,6 +8490,7 @@ var TuiApp = class {
8300
8490
  this.tui = new GuardedMainScreen(deps.terminal, true, (viewportTop, width, frameLines) => {
8301
8491
  return this.settleFrame(viewportTop, width, frameLines);
8302
8492
  });
8493
+ this.readerScreen = new AlternateScreen(deps.terminal);
8303
8494
  this.header = new Text("", 0, 0);
8304
8495
  this.inspector = new InspectorPane(() => this.inspectorView(), {
8305
8496
  palette,
@@ -8315,6 +8506,9 @@ var TuiApp = class {
8315
8506
  this.editor.onSubmit = (text) => {
8316
8507
  this.onSubmit(text);
8317
8508
  };
8509
+ this.editor.onChange = () => {
8510
+ this.syncEditorBorder();
8511
+ };
8318
8512
  this.queue = new Text("", 0, 0);
8319
8513
  this.panel = new Text("", 0, 0);
8320
8514
  this.footer = new FooterBar(() => ({
@@ -8341,8 +8535,7 @@ var TuiApp = class {
8341
8535
  this.queueSlot,
8342
8536
  this.editor,
8343
8537
  this.panelSlot,
8344
- this.footer,
8345
- this.pad
8538
+ this.footer
8346
8539
  ];
8347
8540
  for (const child of tree) this.tui.addChild(child);
8348
8541
  }
@@ -8437,6 +8630,7 @@ var TuiApp = class {
8437
8630
  /** Release the terminal and tell the host to exit; later calls are no-ops. */
8438
8631
  stop() {
8439
8632
  if (this.stopped) return;
8633
+ this.dropUserShell();
8440
8634
  this.restoreQueueDraft();
8441
8635
  this.stopped = true;
8442
8636
  this.updateTicker();
@@ -8454,6 +8648,7 @@ var TuiApp = class {
8454
8648
  }
8455
8649
  /** Draw `next` as the terminal's session: clear the transcript and replay its history. */
8456
8650
  bind(next) {
8651
+ this.dropUserShell();
8457
8652
  if (this.queueDraft !== void 0) {
8458
8653
  this.restoreQueueDraft();
8459
8654
  this.editor.setText("");
@@ -8854,7 +9049,6 @@ var TuiApp = class {
8854
9049
  */
8855
9050
  showModal(prompt, signal) {
8856
9051
  this.queuedModals += 1;
8857
- this.finishReaderClose();
8858
9052
  this.hideReader(true);
8859
9053
  if (this.reader === void 0) this.focusEditor();
8860
9054
  return this.modals.run(prompt, signal).finally(() => {
@@ -8864,12 +9058,15 @@ var TuiApp = class {
8864
9058
  });
8865
9059
  }
8866
9060
  /**
8867
- * Take the reader off the screen for as long as something else needs it, or
8868
- * put it back.
9061
+ * Take the reader off the terminal for as long as something else needs it,
9062
+ * or put it back. The reader itself stays open throughout, on the section
9063
+ * it was reading.
8869
9064
  * @param hidden - whether the reader steps aside.
8870
9065
  */
8871
9066
  hideReader(hidden) {
8872
- this.reader?.handle.setHidden(hidden);
9067
+ if (this.reader === void 0) return;
9068
+ if (hidden) this.hideReaderScreen();
9069
+ else this.showReader();
8873
9070
  }
8874
9071
  /**
8875
9072
  * Walk a list one entry at a time: the picker opens on `rows`, `Enter`
@@ -9083,25 +9280,25 @@ var TuiApp = class {
9083
9280
  * their global meaning wherever the keyboard is; everything else is what
9084
9281
  * {@link resolveKey} makes of the key in the region that holds it.
9085
9282
  *
9086
- * A reader that is still shrinking away goes first, before the key is read:
9087
- * pi-tui hands the key stream back to an overlay it still holds a focus
9088
- * restore for, so a key this listener leaves to the editor would reach the
9089
- * pane instead of the caret.
9283
+ * A reader holding the terminal takes every key here, so nothing reaches
9284
+ * the editor behind it and no frame of the conversation is asked for while
9285
+ * the terminal is showing another screen.
9090
9286
  * @param data - the raw key bytes.
9091
9287
  * @returns the consume marker, or undefined for the keys pi-tui's own
9092
9288
  * editor answers.
9093
9289
  */
9094
9290
  onKey(data) {
9095
9291
  if (isKeyRelease(data)) return { consume: true };
9096
- this.finishReaderClose();
9097
9292
  if (this.modals.isActive()) {
9098
9293
  if (!matchesKey(data, "ctrl+c")) return void 0;
9099
9294
  this.modals.withdrawActive();
9100
9295
  return { consume: true };
9101
9296
  }
9102
- if (this.reader !== void 0) {
9103
- if (!matchesKey(data, "ctrl+c")) return void 0;
9104
- this.reader.pane.withdraw();
9297
+ const reading = this.reader;
9298
+ if (reading !== void 0 && this.readerScreen.active) {
9299
+ if (matchesKey(data, "ctrl+c")) reading.pane.withdraw();
9300
+ else reading.pane.handleInput(data);
9301
+ this.queueReaderPaint();
9105
9302
  return { consume: true };
9106
9303
  }
9107
9304
  if (this.focus === "editor" && !matchesKey(data, "escape")) this.disarmStop();
@@ -9212,7 +9409,17 @@ var TuiApp = class {
9212
9409
  const now = this.deps.now();
9213
9410
  if (now < this.escapeQuietUntil) return { consume: true };
9214
9411
  if (this.editor.isShowingAutocomplete()) return void 0;
9215
- if (this.agent.status !== "running") return { consume: true };
9412
+ if (this.shellAbort !== void 0) {
9413
+ this.shellAbort.abort();
9414
+ return { consume: true };
9415
+ }
9416
+ if (this.agent.status !== "running") {
9417
+ if (this.editor.getText().trimStart().startsWith("!")) {
9418
+ this.editor.setText("");
9419
+ this.syncEditorBorder();
9420
+ }
9421
+ return { consume: true };
9422
+ }
9216
9423
  if (now >= this.stopArmedUntil) {
9217
9424
  this.stopArmedUntil = now + this.showToast(stopTurnToast(this.turn));
9218
9425
  return { consume: true };
@@ -9286,10 +9493,12 @@ var TuiApp = class {
9286
9493
  /**
9287
9494
  * Read the transcript full screen.
9288
9495
  *
9289
- * The reader is an overlay, so it costs the conversation no line and the
9290
- * renderer's repaint boundary stays where it was. The frame is settled
9291
- * first, so the pane knows how much of the viewport the renderer can still
9292
- * repaint before it decides how tall to draw.
9496
+ * The reader takes the terminal rather than drawing over the conversation:
9497
+ * the frame on screen is written one last time, the main screen is then
9498
+ * held off the terminal, and the alternate screen carries the reader. The
9499
+ * conversation keeps every line it had, the renderer's repaint boundary
9500
+ * stays where it was, and nothing the reader draws can reach the terminal's
9501
+ * scrollback.
9293
9502
  * @param at - the section to open on; the newest one when omitted.
9294
9503
  */
9295
9504
  openReader(at) {
@@ -9299,46 +9508,79 @@ var TuiApp = class {
9299
9508
  this.showToast(NOTHING_TO_READ_TOAST);
9300
9509
  return;
9301
9510
  }
9302
- this.finishReaderClose();
9303
- this.tui.renderNow();
9304
- this.readerOpening = this.startMotion(6);
9305
9511
  const pane = new ReaderPane({
9306
9512
  palette: this.deps.palette,
9307
9513
  blocks: () => navigableBlocks(this.chat.children),
9308
- rows: () => Math.max(1, this.deps.terminal.rows - this.viewportFloor),
9514
+ rows: () => Math.max(1, this.deps.terminal.rows),
9309
9515
  minColumns: this.deps.readerMinColumns,
9310
9516
  cursor,
9311
- reveal: () => this.readerReveal()
9517
+ onExit: (exit) => {
9518
+ this.closeReader(exit);
9519
+ }
9312
9520
  });
9313
- this.reader = {
9314
- handle: this.tui.showOverlay(pane, READER_OVERLAY),
9315
- pane
9316
- };
9317
- this.tui.requestRender();
9318
- pane.settled.then((exit) => {
9319
- this.closeReader(exit);
9521
+ this.reader = { pane };
9522
+ this.showReader();
9523
+ }
9524
+ /**
9525
+ * Put the open reader on the terminal: settle the conversation, hold the
9526
+ * main screen off the terminal, and draw the reader on the alternate one.
9527
+ *
9528
+ * Called with a reader open and the conversation on the terminal.
9529
+ *
9530
+ * Every render the application already asks for draws the reader while it is
9531
+ * up, so a landing tool result, a streamed word, and a resize all reach it
9532
+ * without a clock of its own.
9533
+ */
9534
+ showReader() {
9535
+ this.tui.renderNow();
9536
+ this.tui.suspend(() => {
9537
+ this.queueReaderPaint();
9320
9538
  });
9539
+ this.readerScreen.enter();
9540
+ this.paintReader();
9541
+ }
9542
+ /**
9543
+ * Take the reader off the terminal and give the conversation its screen
9544
+ * back, leaving the reader itself open. Both steps answer for a terminal
9545
+ * the reader never took, so a caller needs to know only that it is done.
9546
+ */
9547
+ hideReaderScreen() {
9548
+ this.readerScreen.leave();
9549
+ this.tui.resume();
9550
+ }
9551
+ /**
9552
+ * Draw the open reader, at most once per turn of the loop.
9553
+ *
9554
+ * The pane re-reads the conversation on every paint, so a burst of session
9555
+ * events costs one drawing rather than one per event.
9556
+ */
9557
+ queueReaderPaint() {
9558
+ if (this.readerPaintQueued) return;
9559
+ this.readerPaintQueued = true;
9560
+ queueMicrotask(() => {
9561
+ this.readerPaintQueued = false;
9562
+ this.paintReader();
9563
+ });
9564
+ }
9565
+ /** Draw the open reader now, if one holds the terminal. */
9566
+ paintReader() {
9567
+ const open = this.reader;
9568
+ if (open === void 0 || !this.readerScreen.active) return;
9569
+ this.readerScreen.paint(open.pane.render(Math.max(1, this.deps.terminal.columns)));
9321
9570
  }
9322
9571
  /**
9323
9572
  * Take the reader down and put the keyboard where it left it.
9324
9573
  * @param exit - the section last read and the region that takes over.
9325
9574
  */
9326
9575
  closeReader(exit) {
9327
- const open = this.reader;
9328
- if (open === void 0) return;
9576
+ if (this.reader === void 0) return;
9329
9577
  this.reader = void 0;
9330
- this.readerOpening = void 0;
9331
9578
  this.cursor = exit.cursor;
9579
+ this.hideReaderScreen();
9332
9580
  this.setFocus(exit.target);
9333
9581
  this.refreshQueue();
9334
9582
  this.refreshSubagentPanel();
9335
9583
  this.armEscapeHandoff();
9336
- const motion = this.startMotion(4);
9337
- if (motion === void 0) open.handle.hide();
9338
- else this.readerClosing = {
9339
- handle: open.handle,
9340
- motion
9341
- };
9342
9584
  this.tui.requestRender();
9343
9585
  }
9344
9586
  /**
@@ -9349,11 +9591,10 @@ var TuiApp = class {
9349
9591
  * @returns whether a reader was open, so the caller can report that it came down.
9350
9592
  */
9351
9593
  dropReader() {
9352
- this.finishReaderClose();
9353
9594
  const open = this.reader;
9354
9595
  if (open === void 0) return false;
9355
9596
  this.reader = void 0;
9356
- open.handle.hide();
9597
+ this.hideReaderScreen();
9357
9598
  open.pane.withdraw();
9358
9599
  return true;
9359
9600
  }
@@ -9714,7 +9955,6 @@ var TuiApp = class {
9714
9955
  * @param region - the region that takes the keyboard.
9715
9956
  */
9716
9957
  setFocus(region) {
9717
- this.finishReaderClose();
9718
9958
  if (region === "editor") this.chrome = void 0;
9719
9959
  else this.startChrome("landing", 6);
9720
9960
  this.focus = region;
@@ -9750,16 +9990,16 @@ var TuiApp = class {
9750
9990
  if (section === void 0 || block === void 0 || !isFoldable(block)) return;
9751
9991
  this.tui.renderNow();
9752
9992
  if (this.highlighted?.block !== block) {
9993
+ this.notice(ABOVE_WINDOW_NOTICE);
9753
9994
  this.openReader(section.cursor);
9754
- this.showToast(ABOVE_WINDOW_TOAST);
9755
9995
  return;
9756
9996
  }
9757
9997
  block.setExpanded(!block.isExpanded());
9758
9998
  this.tui.requestRender();
9759
9999
  }
9760
10000
  /**
9761
- * Handle a submitted editor line: a `/` line runs a command, anything else
9762
- * becomes a user message.
10001
+ * Handle a submitted editor line: a `/` line runs a command, a nonempty `!`
10002
+ * / `!!` line runs in the terminal, and anything else becomes a user message.
9763
10003
  * @param raw - the editor text.
9764
10004
  * @param mode - how a message reaches a running Agent: `queue` waits for the next turn, `steer` enters the current one.
9765
10005
  */
@@ -9778,6 +10018,11 @@ var TuiApp = class {
9778
10018
  this.dispatchCommand(text);
9779
10019
  return;
9780
10020
  }
10021
+ const shell = draft === void 0 ? parseUserShellLine(text) : void 0;
10022
+ if (shell !== void 0) {
10023
+ this.runUserShell(shell.command, shell.excluded);
10024
+ return;
10025
+ }
9781
10026
  this.submit(text, mode, draft);
9782
10027
  }
9783
10028
  /**
@@ -9791,6 +10036,100 @@ var TuiApp = class {
9791
10036
  this.notice(`${name} failed: ${describeFailure(error)}`, "error");
9792
10037
  });
9793
10038
  }
10039
+ /**
10040
+ * Run one user-typed shell command in this process and, unless it was `!!`,
10041
+ * inject the result as next-step context for the next admitted request.
10042
+ * @param command - the text after `!` / `!!`.
10043
+ * @param excluded - true when the line used `!!`.
10044
+ */
10045
+ async runUserShell(command, excluded) {
10046
+ if (this.shellAbort !== void 0) {
10047
+ this.notice(SHELL_BUSY, "error");
10048
+ this.editor.setText(excluded ? `!!${command}` : `!${command}`);
10049
+ this.syncEditorBorder();
10050
+ return;
10051
+ }
10052
+ const shell = this.deps.ctx.get("shell");
10053
+ if (shell === void 0) {
10054
+ this.notice(SHELL_MISSING, "error");
10055
+ return;
10056
+ }
10057
+ /* v8 ignore next -- TUI sessions record cwd on create; process cwd is the fallback when a header omitted it */
10058
+ const workdir = this.agent.session.header.cwd ?? this.deps.cwd;
10059
+ const controller = new AbortController();
10060
+ this.shellAbort = controller;
10061
+ try {
10062
+ const result = await shell.run(shell.resolve({
10063
+ command,
10064
+ workdir,
10065
+ signal: controller.signal,
10066
+ sandboxPolicy: {
10067
+ mode: "danger-full-access",
10068
+ workspaceRoot: workdir,
10069
+ sessionId: this.agent.session.id
10070
+ }
10071
+ }));
10072
+ if (!this.userShellCurrent(controller)) return;
10073
+ this.showUserShell(command, result, excluded);
10074
+ } catch (error) {
10075
+ if (!this.userShellCurrent(controller)) return;
10076
+ this.notice(`! failed: ${describeFailure(error)}`, "error");
10077
+ } finally {
10078
+ if (this.shellAbort === controller) this.shellAbort = void 0;
10079
+ }
10080
+ }
10081
+ /**
10082
+ * Whether `controller` is still the in-flight user-shell run on this bound
10083
+ * session. Bind and quit drop the controller so a late settle cannot draw or
10084
+ * inject into the next session.
10085
+ * @param controller - the AbortController created for this run.
10086
+ * @returns true while this run still owns `shellAbort` and the app is up.
10087
+ */
10088
+ userShellCurrent(controller) {
10089
+ return !this.stopped && this.shellAbort === controller;
10090
+ }
10091
+ /**
10092
+ * Detach and abort the in-flight user-shell run, if any. A late settle then
10093
+ * sees a different controller (or a stopped app) and stays silent.
10094
+ */
10095
+ dropUserShell() {
10096
+ const running = this.shellAbort;
10097
+ this.shellAbort = void 0;
10098
+ running?.abort();
10099
+ }
10100
+ /**
10101
+ * Draw one finished user shell run and inject the model-facing notice.
10102
+ * @param command - the text after `!` / `!!`.
10103
+ * @param result - the completed foreground run.
10104
+ * @param excluded - true when the line used `!!`.
10105
+ */
10106
+ showUserShell(command, result, excluded) {
10107
+ this.showBlock(userShellTranscriptRows(command, result));
10108
+ if (excluded) return;
10109
+ const message = createUserMessage({
10110
+ content: [{
10111
+ type: "text",
10112
+ text: userShellContextText(command, result)
10113
+ }],
10114
+ source: {
10115
+ kind: "plugin",
10116
+ plugin: "tui-app",
10117
+ form: "notice",
10118
+ summary: boundContextSummary(`! ${command}`)
10119
+ }
10120
+ });
10121
+ this.submittedIds.add(message.id);
10122
+ this.agent.inject(message);
10123
+ this.refreshQueue();
10124
+ }
10125
+ /**
10126
+ * Recolor the editor border while the draft starts with `!`.
10127
+ */
10128
+ syncEditorBorder() {
10129
+ const palette = this.deps.palette;
10130
+ this.editor.borderColor = this.editor.getText().trimStart().startsWith("!") ? palette.warning : palette.dim;
10131
+ this.tui.requestRender();
10132
+ }
9794
10133
  /** Return an abandoned edit to the ordinary-turn inbox without waking the Agent. */
9795
10134
  restoreQueueDraft() {
9796
10135
  const draft = this.queueDraft;
@@ -10320,7 +10659,8 @@ var TuiApp = class {
10320
10659
  this.notice("queue cleared", "success");
10321
10660
  return;
10322
10661
  }
10323
- const rows = [...inbox.nextTurn.map((message) => `next turn: ${contentText(message.content)}`), ...inbox.nextStep.map((message) => `next step: ${contentText(message.content)}`)];
10662
+ const queued = (messages) => messages.filter((message) => message.source.kind === "user");
10663
+ const rows = [...queued(inbox.nextTurn).map((message) => `next turn: ${contentText(message.content)}`), ...queued(inbox.nextStep).map((message) => `next step: ${contentText(message.content)}`)];
10324
10664
  this.notice(rows.length === 0 ? "nothing is queued" : rows.join("\n"));
10325
10665
  }
10326
10666
  async showSkills() {
@@ -10624,28 +10964,6 @@ var TuiApp = class {
10624
10964
  return this.focus === "panel" ? this.markLift() : 0;
10625
10965
  }
10626
10966
  /**
10627
- * How much of its height the reader draws right now.
10628
- * @returns the share of the pane's rows: growing while it opens, shrinking
10629
- * while it comes down, and 1 for a reader that is simply up.
10630
- */
10631
- readerReveal() {
10632
- const closing = this.readerClosing;
10633
- if (closing !== void 0) return 1 - closing.motion.progress();
10634
- return this.readerOpening?.progress() ?? 1;
10635
- }
10636
- /**
10637
- * Take a shrinking reader off the screen now, for anything that needs the
10638
- * viewport back before the motion settles: another overlay, a prompt, a
10639
- * session change, or the next key press - pi-tui would hand the key stream
10640
- * back to an overlay it still holds a focus restore for.
10641
- */
10642
- finishReaderClose() {
10643
- const closing = this.readerClosing;
10644
- if (closing === void 0) return;
10645
- this.readerClosing = void 0;
10646
- closing.handle.hide();
10647
- }
10648
- /**
10649
10967
  * Arm the fade tick while streamed text or a card still draws below the last
10650
10968
  * brightness level and disarm it otherwise, so a session that is not
10651
10969
  * streaming runs no fade timer. Exactly one runs at a time, and a stopped
@@ -10684,19 +11002,14 @@ var TuiApp = class {
10684
11002
  * @param viewportTop - the frame's first repaintable line.
10685
11003
  * @param width - the width it was built at.
10686
11004
  * @param frameLines - how many lines the frame has, which is what places
10687
- * an overlay: pi-tui composites one into the frame's last `rows` lines.
11005
+ * the transient line: pi-tui composites an overlay into the frame's last
11006
+ * `rows` lines.
10688
11007
  * @returns whether anything changed a line, so the frame is built again
10689
11008
  * before it is written.
10690
11009
  */
10691
11010
  settleFrame(viewportTop, width, frameLines) {
10692
11011
  const rows = this.deps.terminal.rows;
10693
- const floor = repaintFloor(Math.max(frameLines - this.readerPad, rows) - rows, viewportTop);
10694
- const pad = this.reader === void 0 && this.readerClosing === void 0 ? 0 : floor;
10695
- this.viewportFloor = floor - pad;
10696
- if (pad !== this.readerPad) {
10697
- this.readerPad = pad;
10698
- return true;
10699
- }
11012
+ this.viewportFloor = repaintFloor(Math.max(frameLines, rows) - rows, viewportTop);
10700
11013
  const section = this.focusedSection();
10701
11014
  const wanted = section !== void 0 && this.focus === "transcript" ? {
10702
11015
  block: section.block,
@@ -10734,7 +11047,6 @@ var TuiApp = class {
10734
11047
  this.reasoningTail?.tick();
10735
11048
  this.blockFades.tick();
10736
11049
  if (this.toast?.clock.expired() === true) this.hideToast();
10737
- if (this.readerClosing?.motion.needsRepaint() === false) this.finishReaderClose();
10738
11050
  if (this.panelLift !== this.panelLiftNow()) this.refreshSubagentPanel();
10739
11051
  this.motions.tick();
10740
11052
  this.tui.requestRender();
@@ -10894,9 +11206,9 @@ var TuiApp = class {
10894
11206
  this.todoTurns = tracked;
10895
11207
  }
10896
11208
  onUserMessage(message) {
11209
+ if (this.submittedIds.has(message.id)) return;
10897
11210
  const source = message.source;
10898
11211
  if (source.kind === "user") {
10899
- if (this.submittedIds.has(message.id)) return;
10900
11212
  const attachments = message.content.filter((block) => block.type !== "text").map((block) => `[${block.type}]`);
10901
11213
  this.chat.addChild(new UserBlock(this.theme, [contentText(message.content), ...attachments].filter((part) => part !== "").join("\n"), this.turn));
10902
11214
  return;