@songtonyli/dsh-cli 0.1.25 → 0.1.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/bin/dsh.mjs +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-sidebar/lib/client.js +1 -1
- package/node_modules/@deepseek-ai/dsh-tui-app/README.i18n.yaml +2 -2
- package/node_modules/@deepseek-ai/dsh-tui-app/README.md +15 -13
- package/node_modules/@deepseek-ai/dsh-tui-app/README.zh.md +15 -13
- package/node_modules/@deepseek-ai/dsh-tui-app/lib/index.js +298 -184
- package/node_modules/koffi/CHANGELOG.md +8 -0
- package/node_modules/koffi/cnoke.cjs +7 -7
- package/node_modules/koffi/lib/native/base/base.cc +28 -12
- package/node_modules/koffi/lib/native/base/base.hh +22 -3
- package/node_modules/koffi/package.json +1 -1
- package/node_modules/koffi/src/koffi/index.cjs +8 -8
- package/node_modules/koffi/src/koffi/index.js +6 -6
- package/node_modules/koffi/src/koffi/indirect.cjs +8 -8
- package/node_modules/koffi/src/koffi/indirect.js +6 -6
- package/node_modules/koffi/src/koffi/src/abi/riscv64.cc +16 -1
- package/node_modules/koffi/src/koffi/src/call.cc +24 -12
- package/node_modules/koffi/src/koffi/src/call.hh +0 -1
- package/node_modules/koffi/src/koffi/src/ffi.cc +4 -6
- package/node_modules/koffi/src/koffi/src/type.cc +3 -2
- package/node_modules/koffi/src/koffi/src/util.hh +2 -9
- package/package.json +22 -22
|
@@ -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
|
|
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
|
|
@@ -6803,29 +6926,24 @@ function readerRows(state, groups, render) {
|
|
|
6803
6926
|
];
|
|
6804
6927
|
}
|
|
6805
6928
|
//#endregion
|
|
6806
|
-
//#region lib/types/reader-
|
|
6929
|
+
//#region lib/types/reader-screen.js
|
|
6807
6930
|
/**
|
|
6808
|
-
* The reader as
|
|
6809
|
-
*
|
|
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.
|
|
6931
|
+
* The reader as the surface that owns the terminal: the pane drawn on the
|
|
6932
|
+
* alternate screen, and the key map that drives it.
|
|
6818
6933
|
*
|
|
6819
|
-
*
|
|
6820
|
-
*
|
|
6821
|
-
*
|
|
6822
|
-
*
|
|
6934
|
+
* It costs the conversation nothing at all. The application switches the
|
|
6935
|
+
* terminal to its alternate screen (`./alt-screen.ts`) and holds the
|
|
6936
|
+
* main screen off it for as long as the reader is up, so the conversation
|
|
6937
|
+
* keeps every line it had, the renderer's repaint boundary never moves, and
|
|
6938
|
+
* no row the reader draws can reach the terminal's scrollback. The pane fills
|
|
6939
|
+
* the screen: it is told how many rows the terminal has and returns exactly
|
|
6940
|
+
* that many.
|
|
6823
6941
|
*
|
|
6824
6942
|
* The pane holds no copy of the transcript: it re-reads the blocks and their
|
|
6825
6943
|
* turns on every render, so a reply that is still streaming grows inside it,
|
|
6826
6944
|
* a tool result that lands appears, and a new turn joins the list, all with
|
|
6827
6945
|
* no push and no second clock.
|
|
6828
|
-
* @module @deepseek-ai/dsh-tui-app/reader-
|
|
6946
|
+
* @module @deepseek-ai/dsh-tui-app/reader-screen
|
|
6829
6947
|
*/
|
|
6830
6948
|
/** The key that opens the query line. */
|
|
6831
6949
|
const FILTER_KEY = "/";
|
|
@@ -6835,9 +6953,6 @@ const FILTER_KEY = "/";
|
|
|
6835
6953
|
*/
|
|
6836
6954
|
var ReaderPane = class {
|
|
6837
6955
|
options;
|
|
6838
|
-
/** Where the reader left the keyboard and the reading. */
|
|
6839
|
-
settled;
|
|
6840
|
-
resolve;
|
|
6841
6956
|
/** Whether the reader is still open; a second close is ignored. */
|
|
6842
6957
|
open = true;
|
|
6843
6958
|
state;
|
|
@@ -6850,9 +6965,6 @@ var ReaderPane = class {
|
|
|
6850
6965
|
*/
|
|
6851
6966
|
constructor(options) {
|
|
6852
6967
|
this.options = options;
|
|
6853
|
-
this.settled = new Promise((resolve) => {
|
|
6854
|
-
this.resolve = resolve;
|
|
6855
|
-
});
|
|
6856
6968
|
this.state = {
|
|
6857
6969
|
cursor: options.cursor,
|
|
6858
6970
|
column: "pane",
|
|
@@ -6862,11 +6974,9 @@ var ReaderPane = class {
|
|
|
6862
6974
|
invalidate() {}
|
|
6863
6975
|
/**
|
|
6864
6976
|
* Draw the reader at `width`.
|
|
6865
|
-
* @param width - the columns the
|
|
6866
|
-
* @returns as many lines as `rows()` reports, so the
|
|
6867
|
-
*
|
|
6868
|
-
* shrinking it - and blank lines once the transcript it was reading is
|
|
6869
|
-
* gone.
|
|
6977
|
+
* @param width - the columns the screen has.
|
|
6978
|
+
* @returns as many lines as `rows()` reports, so the reader covers the
|
|
6979
|
+
* screen, and blank lines once the transcript it was reading is gone.
|
|
6870
6980
|
*/
|
|
6871
6981
|
render(width) {
|
|
6872
6982
|
this.width = width;
|
|
@@ -6896,23 +7006,7 @@ var ReaderPane = class {
|
|
|
6896
7006
|
rows,
|
|
6897
7007
|
minColumns: this.options.minColumns,
|
|
6898
7008
|
totalTurns: groups.length
|
|
6899
|
-
})
|
|
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)));
|
|
7009
|
+
});
|
|
6916
7010
|
}
|
|
6917
7011
|
/**
|
|
6918
7012
|
* Answer one key press.
|
|
@@ -6946,7 +7040,7 @@ var ReaderPane = class {
|
|
|
6946
7040
|
* The geometry of the frame as it stands.
|
|
6947
7041
|
* @param visible - the turns the rail lists.
|
|
6948
7042
|
* @param blocks - the navigable blocks.
|
|
6949
|
-
* @param rows - the rows the
|
|
7043
|
+
* @param rows - the rows the screen has.
|
|
6950
7044
|
* @returns the geometry, with the walking pane measured.
|
|
6951
7045
|
*/
|
|
6952
7046
|
geometryFor(visible, blocks, rows) {
|
|
@@ -6959,7 +7053,7 @@ var ReaderPane = class {
|
|
|
6959
7053
|
close(target) {
|
|
6960
7054
|
if (!this.open) return;
|
|
6961
7055
|
this.open = false;
|
|
6962
|
-
this.
|
|
7056
|
+
this.options.onExit({
|
|
6963
7057
|
cursor: this.state.cursor,
|
|
6964
7058
|
target
|
|
6965
7059
|
});
|
|
@@ -7432,6 +7526,12 @@ var SyntaxHighlighter = class {
|
|
|
7432
7526
|
* far into a block the renderer can still follow it, and
|
|
7433
7527
|
* {@link GuardedMainScreen} gives the application the one moment where that
|
|
7434
7528
|
* question can be answered: after a frame was built and before it is written.
|
|
7529
|
+
*
|
|
7530
|
+
* {@link GuardedMainScreen.suspend} is the other half of that rule: a
|
|
7531
|
+
* full-screen surface that takes the terminal holds the main screen off it
|
|
7532
|
+
* entirely rather than drawing over the conversation, so no line of the
|
|
7533
|
+
* conversation is rewritten while the surface is up and none of the surface's
|
|
7534
|
+
* own rows can reach the terminal's scrollback.
|
|
7435
7535
|
* @module @deepseek-ai/dsh-tui-app/screen
|
|
7436
7536
|
*/
|
|
7437
7537
|
/**
|
|
@@ -7453,40 +7553,6 @@ function repaintFloor(start, viewportTop) {
|
|
|
7453
7553
|
return Math.max(0, viewportTop - start);
|
|
7454
7554
|
}
|
|
7455
7555
|
/**
|
|
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
7556
|
* The main screen that settles each frame between building it and writing it.
|
|
7491
7557
|
*
|
|
7492
7558
|
* The guard is handed the frame's first repaintable line: the higher of the
|
|
@@ -7497,9 +7563,17 @@ var ViewportPad = class {
|
|
|
7497
7563
|
* tomorrow. Settling before the write also means a fade reaches the terminal
|
|
7498
7564
|
* already settled instead of changing in the next frame, by which time its
|
|
7499
7565
|
* lines may sit above the window.
|
|
7566
|
+
*
|
|
7567
|
+
* It can also be suspended, which stops every write to the terminal while
|
|
7568
|
+
* leaving the renderer's record of the main screen exactly as it was. The
|
|
7569
|
+
* terminal restores that same screen when the surface that took it gives it
|
|
7570
|
+
* back, so the first frame after {@link GuardedMainScreen.resume} writes only
|
|
7571
|
+
* what changed meanwhile.
|
|
7500
7572
|
*/
|
|
7501
7573
|
var GuardedMainScreen = class extends TuiMainScreen {
|
|
7502
7574
|
guard;
|
|
7575
|
+
/** What draws instead while another surface holds the terminal; absent while this screen does. */
|
|
7576
|
+
onSuspendedRender;
|
|
7503
7577
|
/**
|
|
7504
7578
|
* @param terminal - the terminal the tree renders into.
|
|
7505
7579
|
* @param showHardwareCursor - whether the terminal's own cursor is the caret.
|
|
@@ -7515,6 +7589,57 @@ var GuardedMainScreen = class extends TuiMainScreen {
|
|
|
7515
7589
|
this.guard = guard;
|
|
7516
7590
|
}
|
|
7517
7591
|
/**
|
|
7592
|
+
* Stop writing to the terminal, and answer every render request with
|
|
7593
|
+
* `onRender` instead.
|
|
7594
|
+
*
|
|
7595
|
+
* Nothing about the renderer's record of the main screen changes, so the
|
|
7596
|
+
* frame it will judge its next write against stays the frame the terminal
|
|
7597
|
+
* still holds behind the surface that took over.
|
|
7598
|
+
* @param onRender - called wherever a frame would have been written, so the
|
|
7599
|
+
* surface that owns the terminal draws on the application's existing render
|
|
7600
|
+
* requests rather than on a clock of its own.
|
|
7601
|
+
*/
|
|
7602
|
+
suspend(onRender) {
|
|
7603
|
+
this.onSuspendedRender = onRender;
|
|
7604
|
+
}
|
|
7605
|
+
/** Write to the terminal again, and draw whatever changed while suspended. */
|
|
7606
|
+
resume() {
|
|
7607
|
+
if (this.onSuspendedRender === void 0) return;
|
|
7608
|
+
this.onSuspendedRender = void 0;
|
|
7609
|
+
this.requestRender();
|
|
7610
|
+
}
|
|
7611
|
+
/**
|
|
7612
|
+
* Request a frame, or draw the surface that suspended this screen.
|
|
7613
|
+
* @param force - redraw from scratch; ignored while suspended, where
|
|
7614
|
+
* discarding the record would lose the screen the terminal is holding.
|
|
7615
|
+
*/
|
|
7616
|
+
requestRender(force = false) {
|
|
7617
|
+
const suspended = this.onSuspendedRender;
|
|
7618
|
+
if (suspended === void 0) {
|
|
7619
|
+
super.requestRender(force);
|
|
7620
|
+
return;
|
|
7621
|
+
}
|
|
7622
|
+
suspended();
|
|
7623
|
+
}
|
|
7624
|
+
/**
|
|
7625
|
+
* Write a frame now, or draw the suspending surface now.
|
|
7626
|
+
* @param force - redraw from scratch; ignored while suspended, as in
|
|
7627
|
+
* {@link GuardedMainScreen.requestRender}.
|
|
7628
|
+
*/
|
|
7629
|
+
renderNow(force = false) {
|
|
7630
|
+
const suspended = this.onSuspendedRender;
|
|
7631
|
+
if (suspended === void 0) {
|
|
7632
|
+
super.renderNow(force);
|
|
7633
|
+
return;
|
|
7634
|
+
}
|
|
7635
|
+
suspended();
|
|
7636
|
+
}
|
|
7637
|
+
/** Write the frame, unless another surface holds the terminal. */
|
|
7638
|
+
doRender() {
|
|
7639
|
+
if (this.onSuspendedRender !== void 0) return;
|
|
7640
|
+
super.doRender();
|
|
7641
|
+
}
|
|
7642
|
+
/**
|
|
7518
7643
|
* Build the frame, let the guard settle what its geometry decides, and build
|
|
7519
7644
|
* it again for every pass that changed a line.
|
|
7520
7645
|
* @param width - the total width the tree lays out in.
|
|
@@ -7696,8 +7821,6 @@ function renderSubagentPanel(view, render) {
|
|
|
7696
7821
|
const QUIT_TOAST = "press Ctrl+C again to quit";
|
|
7697
7822
|
/** What the line says when the transcript holds nothing the reader could open. */
|
|
7698
7823
|
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
7824
|
/**
|
|
7702
7825
|
* What the line says while the stop is armed. It names the turn it would
|
|
7703
7826
|
* stop, so a press after a turn boundary is read for what it is.
|
|
@@ -7907,21 +8030,8 @@ function splitModelValue(value) {
|
|
|
7907
8030
|
}
|
|
7908
8031
|
/** What the transcript is told when a session switch took the conversation the reader was showing. */
|
|
7909
8032
|
const READER_GONE = "the transcript changed · reader closed";
|
|
7910
|
-
/**
|
|
7911
|
-
|
|
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
|
-
};
|
|
8033
|
+
/** What the transcript is told when a fold key named a block the renderer can no longer rewrite. */
|
|
8034
|
+
const ABOVE_WINDOW_NOTICE = "above the repaint window · opened in the reader";
|
|
7925
8035
|
/**
|
|
7926
8036
|
* Row layout of the todo picker: the label column grows with the widest todo
|
|
7927
8037
|
* line instead of stopping at the list's 32-column default, which would cut a
|
|
@@ -8162,8 +8272,8 @@ var TuiApp = class {
|
|
|
8162
8272
|
transferringQueue = false;
|
|
8163
8273
|
/** Holds {@link panel} exactly while the bound session has subagent rows. */
|
|
8164
8274
|
panelSlot = new Container();
|
|
8165
|
-
/**
|
|
8166
|
-
|
|
8275
|
+
/** The terminal's alternate screen, which the reader draws on; see {@link AlternateScreen}. */
|
|
8276
|
+
readerScreen;
|
|
8167
8277
|
/** Colours fenced code in replies; see {@link SyntaxHighlighter}. */
|
|
8168
8278
|
codeHighlight;
|
|
8169
8279
|
/** The terminal's background once it answered; undefined until then, and on a terminal that answers none. */
|
|
@@ -8235,14 +8345,10 @@ var TuiApp = class {
|
|
|
8235
8345
|
chrome;
|
|
8236
8346
|
/** The lift the subagent panel's text was last built with, which only a repaint changes. */
|
|
8237
8347
|
panelLift = 0;
|
|
8238
|
-
/** The reader on screen right now, while one is open. */
|
|
8348
|
+
/** The reader on the alternate screen right now, while one is open. */
|
|
8239
8349
|
reader;
|
|
8240
|
-
/**
|
|
8241
|
-
|
|
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;
|
|
8350
|
+
/** Set while a paint of the open reader is already queued for this turn of the loop. */
|
|
8351
|
+
readerPaintQueued = false;
|
|
8246
8352
|
/** Prompts shown or waiting on the modal queue, which the reader steps aside for. */
|
|
8247
8353
|
queuedModals = 0;
|
|
8248
8354
|
/** Until when an `Escape` that reaches the editor does nothing at all. */
|
|
@@ -8251,8 +8357,9 @@ var TuiApp = class {
|
|
|
8251
8357
|
stopArmedUntil = 0;
|
|
8252
8358
|
/**
|
|
8253
8359
|
* How many of the viewport's own first lines the renderer can no longer
|
|
8254
|
-
* repaint, from the last frame the guard settled.
|
|
8255
|
-
* into those lines, so this is what decides
|
|
8360
|
+
* repaint, from the last frame the guard settled. The transient line
|
|
8361
|
+
* composites into those lines, so this is what decides whether it can float
|
|
8362
|
+
* at all.
|
|
8256
8363
|
*/
|
|
8257
8364
|
viewportFloor = 0;
|
|
8258
8365
|
/** Set while {@link TuiApp.bind} replays a session's history, which draws its cards settled. */
|
|
@@ -8300,6 +8407,7 @@ var TuiApp = class {
|
|
|
8300
8407
|
this.tui = new GuardedMainScreen(deps.terminal, true, (viewportTop, width, frameLines) => {
|
|
8301
8408
|
return this.settleFrame(viewportTop, width, frameLines);
|
|
8302
8409
|
});
|
|
8410
|
+
this.readerScreen = new AlternateScreen(deps.terminal);
|
|
8303
8411
|
this.header = new Text("", 0, 0);
|
|
8304
8412
|
this.inspector = new InspectorPane(() => this.inspectorView(), {
|
|
8305
8413
|
palette,
|
|
@@ -8341,8 +8449,7 @@ var TuiApp = class {
|
|
|
8341
8449
|
this.queueSlot,
|
|
8342
8450
|
this.editor,
|
|
8343
8451
|
this.panelSlot,
|
|
8344
|
-
this.footer
|
|
8345
|
-
this.pad
|
|
8452
|
+
this.footer
|
|
8346
8453
|
];
|
|
8347
8454
|
for (const child of tree) this.tui.addChild(child);
|
|
8348
8455
|
}
|
|
@@ -8854,7 +8961,6 @@ var TuiApp = class {
|
|
|
8854
8961
|
*/
|
|
8855
8962
|
showModal(prompt, signal) {
|
|
8856
8963
|
this.queuedModals += 1;
|
|
8857
|
-
this.finishReaderClose();
|
|
8858
8964
|
this.hideReader(true);
|
|
8859
8965
|
if (this.reader === void 0) this.focusEditor();
|
|
8860
8966
|
return this.modals.run(prompt, signal).finally(() => {
|
|
@@ -8864,12 +8970,15 @@ var TuiApp = class {
|
|
|
8864
8970
|
});
|
|
8865
8971
|
}
|
|
8866
8972
|
/**
|
|
8867
|
-
* Take the reader off the
|
|
8868
|
-
* put it back.
|
|
8973
|
+
* Take the reader off the terminal for as long as something else needs it,
|
|
8974
|
+
* or put it back. The reader itself stays open throughout, on the section
|
|
8975
|
+
* it was reading.
|
|
8869
8976
|
* @param hidden - whether the reader steps aside.
|
|
8870
8977
|
*/
|
|
8871
8978
|
hideReader(hidden) {
|
|
8872
|
-
this.reader
|
|
8979
|
+
if (this.reader === void 0) return;
|
|
8980
|
+
if (hidden) this.hideReaderScreen();
|
|
8981
|
+
else this.showReader();
|
|
8873
8982
|
}
|
|
8874
8983
|
/**
|
|
8875
8984
|
* Walk a list one entry at a time: the picker opens on `rows`, `Enter`
|
|
@@ -9083,25 +9192,25 @@ var TuiApp = class {
|
|
|
9083
9192
|
* their global meaning wherever the keyboard is; everything else is what
|
|
9084
9193
|
* {@link resolveKey} makes of the key in the region that holds it.
|
|
9085
9194
|
*
|
|
9086
|
-
* A reader
|
|
9087
|
-
*
|
|
9088
|
-
*
|
|
9089
|
-
* pane instead of the caret.
|
|
9195
|
+
* A reader holding the terminal takes every key here, so nothing reaches
|
|
9196
|
+
* the editor behind it and no frame of the conversation is asked for while
|
|
9197
|
+
* the terminal is showing another screen.
|
|
9090
9198
|
* @param data - the raw key bytes.
|
|
9091
9199
|
* @returns the consume marker, or undefined for the keys pi-tui's own
|
|
9092
9200
|
* editor answers.
|
|
9093
9201
|
*/
|
|
9094
9202
|
onKey(data) {
|
|
9095
9203
|
if (isKeyRelease(data)) return { consume: true };
|
|
9096
|
-
this.finishReaderClose();
|
|
9097
9204
|
if (this.modals.isActive()) {
|
|
9098
9205
|
if (!matchesKey(data, "ctrl+c")) return void 0;
|
|
9099
9206
|
this.modals.withdrawActive();
|
|
9100
9207
|
return { consume: true };
|
|
9101
9208
|
}
|
|
9102
|
-
|
|
9103
|
-
|
|
9104
|
-
|
|
9209
|
+
const reading = this.reader;
|
|
9210
|
+
if (reading !== void 0 && this.readerScreen.active) {
|
|
9211
|
+
if (matchesKey(data, "ctrl+c")) reading.pane.withdraw();
|
|
9212
|
+
else reading.pane.handleInput(data);
|
|
9213
|
+
this.queueReaderPaint();
|
|
9105
9214
|
return { consume: true };
|
|
9106
9215
|
}
|
|
9107
9216
|
if (this.focus === "editor" && !matchesKey(data, "escape")) this.disarmStop();
|
|
@@ -9286,10 +9395,12 @@ var TuiApp = class {
|
|
|
9286
9395
|
/**
|
|
9287
9396
|
* Read the transcript full screen.
|
|
9288
9397
|
*
|
|
9289
|
-
* The reader
|
|
9290
|
-
*
|
|
9291
|
-
*
|
|
9292
|
-
*
|
|
9398
|
+
* The reader takes the terminal rather than drawing over the conversation:
|
|
9399
|
+
* the frame on screen is written one last time, the main screen is then
|
|
9400
|
+
* held off the terminal, and the alternate screen carries the reader. The
|
|
9401
|
+
* conversation keeps every line it had, the renderer's repaint boundary
|
|
9402
|
+
* stays where it was, and nothing the reader draws can reach the terminal's
|
|
9403
|
+
* scrollback.
|
|
9293
9404
|
* @param at - the section to open on; the newest one when omitted.
|
|
9294
9405
|
*/
|
|
9295
9406
|
openReader(at) {
|
|
@@ -9299,46 +9410,79 @@ var TuiApp = class {
|
|
|
9299
9410
|
this.showToast(NOTHING_TO_READ_TOAST);
|
|
9300
9411
|
return;
|
|
9301
9412
|
}
|
|
9302
|
-
this.finishReaderClose();
|
|
9303
|
-
this.tui.renderNow();
|
|
9304
|
-
this.readerOpening = this.startMotion(6);
|
|
9305
9413
|
const pane = new ReaderPane({
|
|
9306
9414
|
palette: this.deps.palette,
|
|
9307
9415
|
blocks: () => navigableBlocks(this.chat.children),
|
|
9308
|
-
rows: () => Math.max(1, this.deps.terminal.rows
|
|
9416
|
+
rows: () => Math.max(1, this.deps.terminal.rows),
|
|
9309
9417
|
minColumns: this.deps.readerMinColumns,
|
|
9310
9418
|
cursor,
|
|
9311
|
-
|
|
9419
|
+
onExit: (exit) => {
|
|
9420
|
+
this.closeReader(exit);
|
|
9421
|
+
}
|
|
9312
9422
|
});
|
|
9313
|
-
this.reader = {
|
|
9314
|
-
|
|
9315
|
-
|
|
9316
|
-
|
|
9317
|
-
|
|
9318
|
-
|
|
9319
|
-
|
|
9423
|
+
this.reader = { pane };
|
|
9424
|
+
this.showReader();
|
|
9425
|
+
}
|
|
9426
|
+
/**
|
|
9427
|
+
* Put the open reader on the terminal: settle the conversation, hold the
|
|
9428
|
+
* main screen off the terminal, and draw the reader on the alternate one.
|
|
9429
|
+
*
|
|
9430
|
+
* Called with a reader open and the conversation on the terminal.
|
|
9431
|
+
*
|
|
9432
|
+
* Every render the application already asks for draws the reader while it is
|
|
9433
|
+
* up, so a landing tool result, a streamed word, and a resize all reach it
|
|
9434
|
+
* without a clock of its own.
|
|
9435
|
+
*/
|
|
9436
|
+
showReader() {
|
|
9437
|
+
this.tui.renderNow();
|
|
9438
|
+
this.tui.suspend(() => {
|
|
9439
|
+
this.queueReaderPaint();
|
|
9440
|
+
});
|
|
9441
|
+
this.readerScreen.enter();
|
|
9442
|
+
this.paintReader();
|
|
9443
|
+
}
|
|
9444
|
+
/**
|
|
9445
|
+
* Take the reader off the terminal and give the conversation its screen
|
|
9446
|
+
* back, leaving the reader itself open. Both steps answer for a terminal
|
|
9447
|
+
* the reader never took, so a caller needs to know only that it is done.
|
|
9448
|
+
*/
|
|
9449
|
+
hideReaderScreen() {
|
|
9450
|
+
this.readerScreen.leave();
|
|
9451
|
+
this.tui.resume();
|
|
9452
|
+
}
|
|
9453
|
+
/**
|
|
9454
|
+
* Draw the open reader, at most once per turn of the loop.
|
|
9455
|
+
*
|
|
9456
|
+
* The pane re-reads the conversation on every paint, so a burst of session
|
|
9457
|
+
* events costs one drawing rather than one per event.
|
|
9458
|
+
*/
|
|
9459
|
+
queueReaderPaint() {
|
|
9460
|
+
if (this.readerPaintQueued) return;
|
|
9461
|
+
this.readerPaintQueued = true;
|
|
9462
|
+
queueMicrotask(() => {
|
|
9463
|
+
this.readerPaintQueued = false;
|
|
9464
|
+
this.paintReader();
|
|
9320
9465
|
});
|
|
9321
9466
|
}
|
|
9467
|
+
/** Draw the open reader now, if one holds the terminal. */
|
|
9468
|
+
paintReader() {
|
|
9469
|
+
const open = this.reader;
|
|
9470
|
+
if (open === void 0 || !this.readerScreen.active) return;
|
|
9471
|
+
this.readerScreen.paint(open.pane.render(Math.max(1, this.deps.terminal.columns)));
|
|
9472
|
+
}
|
|
9322
9473
|
/**
|
|
9323
9474
|
* Take the reader down and put the keyboard where it left it.
|
|
9324
9475
|
* @param exit - the section last read and the region that takes over.
|
|
9325
9476
|
*/
|
|
9326
9477
|
closeReader(exit) {
|
|
9327
|
-
|
|
9328
|
-
if (open === void 0) return;
|
|
9478
|
+
if (this.reader === void 0) return;
|
|
9329
9479
|
this.reader = void 0;
|
|
9330
|
-
this.readerOpening = void 0;
|
|
9331
9480
|
this.cursor = exit.cursor;
|
|
9481
|
+
this.hideReaderScreen();
|
|
9332
9482
|
this.setFocus(exit.target);
|
|
9333
9483
|
this.refreshQueue();
|
|
9334
9484
|
this.refreshSubagentPanel();
|
|
9335
9485
|
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
9486
|
this.tui.requestRender();
|
|
9343
9487
|
}
|
|
9344
9488
|
/**
|
|
@@ -9349,11 +9493,10 @@ var TuiApp = class {
|
|
|
9349
9493
|
* @returns whether a reader was open, so the caller can report that it came down.
|
|
9350
9494
|
*/
|
|
9351
9495
|
dropReader() {
|
|
9352
|
-
this.finishReaderClose();
|
|
9353
9496
|
const open = this.reader;
|
|
9354
9497
|
if (open === void 0) return false;
|
|
9355
9498
|
this.reader = void 0;
|
|
9356
|
-
|
|
9499
|
+
this.hideReaderScreen();
|
|
9357
9500
|
open.pane.withdraw();
|
|
9358
9501
|
return true;
|
|
9359
9502
|
}
|
|
@@ -9714,7 +9857,6 @@ var TuiApp = class {
|
|
|
9714
9857
|
* @param region - the region that takes the keyboard.
|
|
9715
9858
|
*/
|
|
9716
9859
|
setFocus(region) {
|
|
9717
|
-
this.finishReaderClose();
|
|
9718
9860
|
if (region === "editor") this.chrome = void 0;
|
|
9719
9861
|
else this.startChrome("landing", 6);
|
|
9720
9862
|
this.focus = region;
|
|
@@ -9750,8 +9892,8 @@ var TuiApp = class {
|
|
|
9750
9892
|
if (section === void 0 || block === void 0 || !isFoldable(block)) return;
|
|
9751
9893
|
this.tui.renderNow();
|
|
9752
9894
|
if (this.highlighted?.block !== block) {
|
|
9895
|
+
this.notice(ABOVE_WINDOW_NOTICE);
|
|
9753
9896
|
this.openReader(section.cursor);
|
|
9754
|
-
this.showToast(ABOVE_WINDOW_TOAST);
|
|
9755
9897
|
return;
|
|
9756
9898
|
}
|
|
9757
9899
|
block.setExpanded(!block.isExpanded());
|
|
@@ -10624,28 +10766,6 @@ var TuiApp = class {
|
|
|
10624
10766
|
return this.focus === "panel" ? this.markLift() : 0;
|
|
10625
10767
|
}
|
|
10626
10768
|
/**
|
|
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
10769
|
* Arm the fade tick while streamed text or a card still draws below the last
|
|
10650
10770
|
* brightness level and disarm it otherwise, so a session that is not
|
|
10651
10771
|
* streaming runs no fade timer. Exactly one runs at a time, and a stopped
|
|
@@ -10684,19 +10804,14 @@ var TuiApp = class {
|
|
|
10684
10804
|
* @param viewportTop - the frame's first repaintable line.
|
|
10685
10805
|
* @param width - the width it was built at.
|
|
10686
10806
|
* @param frameLines - how many lines the frame has, which is what places
|
|
10687
|
-
*
|
|
10807
|
+
* the transient line: pi-tui composites an overlay into the frame's last
|
|
10808
|
+
* `rows` lines.
|
|
10688
10809
|
* @returns whether anything changed a line, so the frame is built again
|
|
10689
10810
|
* before it is written.
|
|
10690
10811
|
*/
|
|
10691
10812
|
settleFrame(viewportTop, width, frameLines) {
|
|
10692
10813
|
const rows = this.deps.terminal.rows;
|
|
10693
|
-
|
|
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
|
-
}
|
|
10814
|
+
this.viewportFloor = repaintFloor(Math.max(frameLines, rows) - rows, viewportTop);
|
|
10700
10815
|
const section = this.focusedSection();
|
|
10701
10816
|
const wanted = section !== void 0 && this.focus === "transcript" ? {
|
|
10702
10817
|
block: section.block,
|
|
@@ -10734,7 +10849,6 @@ var TuiApp = class {
|
|
|
10734
10849
|
this.reasoningTail?.tick();
|
|
10735
10850
|
this.blockFades.tick();
|
|
10736
10851
|
if (this.toast?.clock.expired() === true) this.hideToast();
|
|
10737
|
-
if (this.readerClosing?.motion.needsRepaint() === false) this.finishReaderClose();
|
|
10738
10852
|
if (this.panelLift !== this.panelLiftNow()) this.refreshSubagentPanel();
|
|
10739
10853
|
this.motions.tick();
|
|
10740
10854
|
this.tui.requestRender();
|