@songtonyli/dsh-cli 0.1.16 → 0.1.18
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-api-session-controller/lib/types/client/sessions/queue-mirror.js +61 -0
- package/node_modules/@deepseek-ai/dsh-client-locale/lib/client.js +7 -7
- package/node_modules/@deepseek-ai/dsh-client-ui-agent-preset/lib/client.js +61 -61
- package/node_modules/@deepseek-ai/dsh-client-ui-approval/lib/client.js +11 -11
- package/node_modules/@deepseek-ai/dsh-client-ui-attachment/lib/client.js +55 -55
- package/node_modules/@deepseek-ai/dsh-client-ui-chat/lib/client.js +182 -182
- package/node_modules/@deepseek-ai/dsh-client-ui-commands/lib/client.js +16 -16
- package/node_modules/@deepseek-ai/dsh-client-ui-conversation/lib/client.js +151 -151
- package/node_modules/@deepseek-ai/dsh-client-ui-cordis/lib/client.js +74 -74
- package/node_modules/@deepseek-ai/dsh-client-ui-deliverables/lib/client.js +76 -76
- package/node_modules/@deepseek-ai/dsh-client-ui-directory-picker-browse/lib/client.js +39 -39
- package/node_modules/@deepseek-ai/dsh-client-ui-goal/lib/client.js +16 -16
- package/node_modules/@deepseek-ai/dsh-client-ui-input-trigger/lib/client.js +23 -23
- package/node_modules/@deepseek-ai/dsh-client-ui-jobs/lib/client.js +15 -15
- package/node_modules/@deepseek-ai/dsh-client-ui-layout/lib/client.js +8 -8
- package/node_modules/@deepseek-ai/dsh-client-ui-message-feedback/lib/client.js +13 -13
- package/node_modules/@deepseek-ai/dsh-client-ui-model-selection/lib/client.js +27 -27
- package/node_modules/@deepseek-ai/dsh-client-ui-open-in-app/lib/client.js +6 -6
- package/node_modules/@deepseek-ai/dsh-client-ui-permission-presets/lib/client.js +18 -18
- package/node_modules/@deepseek-ai/dsh-client-ui-plan/lib/client.js +22 -22
- package/node_modules/@deepseek-ai/dsh-client-ui-plugin-manager/lib/client.js +115 -115
- package/node_modules/@deepseek-ai/dsh-client-ui-schedule/lib/client.js +14 -14
- package/node_modules/@deepseek-ai/dsh-client-ui-settings-general/lib/client.js +40 -40
- package/node_modules/@deepseek-ai/dsh-client-ui-settings-models/lib/client.js +85 -85
- package/node_modules/@deepseek-ai/dsh-client-ui-settings-plugin-inventory/lib/client.js +35 -35
- package/node_modules/@deepseek-ai/dsh-client-ui-settings-plugins/lib/client.js +61 -61
- package/node_modules/@deepseek-ai/dsh-client-ui-settings-signin/lib/client.js +24 -24
- package/node_modules/@deepseek-ai/dsh-client-ui-settings-unarchive-sessions/lib/client.js +10 -10
- package/node_modules/@deepseek-ai/dsh-client-ui-sidebar/lib/client.js +41 -41
- package/node_modules/@deepseek-ai/dsh-client-ui-sidebar-browser/lib/client.js +17 -17
- package/node_modules/@deepseek-ai/dsh-client-ui-sidebar-documentpreview/lib/client.js +68 -68
- package/node_modules/@deepseek-ai/dsh-client-ui-sidebar-documentpreview/lib/client.pdf.js +12 -12
- package/node_modules/@deepseek-ai/dsh-client-ui-sidebar-files/lib/client.js +21 -21
- package/node_modules/@deepseek-ai/dsh-client-ui-sidebar-right/lib/client.js +24 -24
- package/node_modules/@deepseek-ai/dsh-client-ui-sidebar-terminal/lib/client.js +18 -18
- package/node_modules/@deepseek-ai/dsh-client-ui-sidebar-terminal/lib/client.terminal.js +11 -11
- package/node_modules/@deepseek-ai/dsh-client-ui-skill/lib/client.js +19 -19
- package/node_modules/@deepseek-ai/dsh-client-ui-subagent/lib/client.js +38 -38
- package/node_modules/@deepseek-ai/dsh-client-ui-theme/lib/client.js +25 -25
- package/node_modules/@deepseek-ai/dsh-client-ui-tool/lib/client.js +70 -70
- package/node_modules/@deepseek-ai/dsh-client-ui-trajectory/lib/client.js +198 -198
- package/node_modules/@deepseek-ai/dsh-client-ui-user-questions/lib/client.js +50 -50
- package/node_modules/@deepseek-ai/dsh-client-ui-workflow-run/lib/client.js +24 -24
- package/node_modules/@deepseek-ai/dsh-client-ui-workspace/lib/client.js +81 -81
- package/node_modules/@deepseek-ai/dsh-experimental-client-ui-agent-team/lib/client.js +25 -25
- package/node_modules/@deepseek-ai/dsh-llm-cursor/README.i18n.yaml +2 -2
- package/node_modules/@deepseek-ai/dsh-llm-cursor/README.md +1 -1
- package/node_modules/@deepseek-ai/dsh-llm-cursor/README.zh.md +1 -1
- package/node_modules/@deepseek-ai/dsh-llm-cursor/lib/index.js +22 -4
- package/node_modules/@deepseek-ai/dsh-session-log-export/lib/client.js +3 -3
- package/node_modules/@deepseek-ai/dsh-subprocess-local/lib/runner-launch-UEJ3Ntqn.js +1511 -0
- package/node_modules/@deepseek-ai/dsh-tui-app/README.i18n.yaml +2 -2
- package/node_modules/@deepseek-ai/dsh-tui-app/README.md +126 -32
- package/node_modules/@deepseek-ai/dsh-tui-app/README.zh.md +125 -31
- package/node_modules/@deepseek-ai/dsh-tui-app/lib/index.js +3125 -356
- package/node_modules/@deepseek-ai/dsh-tui-app/lib/startup.js +3 -2
- package/package.json +1 -1
|
@@ -429,16 +429,22 @@ function foldRows(lines, keep, marker) {
|
|
|
429
429
|
if (lines.length <= keep) return [...lines];
|
|
430
430
|
return [...lines.slice(0, keep), marker(lines.length - keep)];
|
|
431
431
|
}
|
|
432
|
+
/** The key each fold marker names, the one place these words are written. */
|
|
433
|
+
const FOLD_KEYS = {
|
|
434
|
+
marked: "Space expands",
|
|
435
|
+
transcript: "Ctrl+O expands",
|
|
436
|
+
inspector: "Ctrl+G reads it"
|
|
437
|
+
};
|
|
432
438
|
/**
|
|
433
|
-
*
|
|
434
|
-
*
|
|
435
|
-
*
|
|
436
|
-
* @param
|
|
437
|
-
* @
|
|
439
|
+
* The one fold grammar, on the row that stands for what a fold left out: how
|
|
440
|
+
* many rows are not drawn, and the key that reaches them from where the
|
|
441
|
+
* keyboard is.
|
|
442
|
+
* @param hidden - rows the fold left out.
|
|
443
|
+
* @param opens - where the folded rows are drawn.
|
|
444
|
+
* @returns the marker row, unstyled.
|
|
438
445
|
*/
|
|
439
|
-
function
|
|
440
|
-
|
|
441
|
-
return foldRows(lines, previewLines, (hidden) => `… ${String(hidden)} more line${hidden === 1 ? "" : "s"} (Ctrl+O expands)`);
|
|
446
|
+
function foldMarker(hidden, opens) {
|
|
447
|
+
return `… ${String(hidden)} more row${hidden === 1 ? "" : "s"} · ${FOLD_KEYS[opens]}`;
|
|
442
448
|
}
|
|
443
449
|
//#endregion
|
|
444
450
|
//#region lib/types/catalog.js
|
|
@@ -1855,6 +1861,90 @@ function paintLine(text, runs, restore) {
|
|
|
1855
1861
|
return `${out}${sliceByColumn(text, cursor, text.length + 1)}${restore}`;
|
|
1856
1862
|
}
|
|
1857
1863
|
//#endregion
|
|
1864
|
+
//#region lib/types/motion.js
|
|
1865
|
+
/**
|
|
1866
|
+
* Chrome motion: the brief lift a docked surface draws when the keyboard
|
|
1867
|
+
* lands on it or the mark it holds moves, and the reveal the full-screen
|
|
1868
|
+
* reader grows and shrinks through.
|
|
1869
|
+
*
|
|
1870
|
+
* Pure. A motion is a clock plus a three-level intensity ramp, so nothing
|
|
1871
|
+
* here queries a terminal, builds a color, or arms a timer: the application
|
|
1872
|
+
* reads {@link Motion.level} and {@link Motion.progress} while it renders and
|
|
1873
|
+
* drops the motion once it settles. Every motion is a {@link RegisteredFade},
|
|
1874
|
+
* so it rides the one fade tick the application already arms for streamed
|
|
1875
|
+
* text and disarms with it - an idle session runs no timer for motion.
|
|
1876
|
+
*
|
|
1877
|
+
* Two rules hold for every call site. A motion changes what a line is drawn
|
|
1878
|
+
* with, never how many lines a docked component returns, because each docked
|
|
1879
|
+
* row raises the renderer's repaint boundary for good (`./screen.ts`). And a
|
|
1880
|
+
* settled motion draws exactly what the surface draws at rest, so a terminal
|
|
1881
|
+
* that runs no motion at all - reduced motion, a disabled palette, no color -
|
|
1882
|
+
* loses nothing but the lift.
|
|
1883
|
+
* @module @deepseek-ai/dsh-tui-app/motion
|
|
1884
|
+
*/
|
|
1885
|
+
/** Share of a motion drawn at its peak. */
|
|
1886
|
+
const PEAK_SHARE = 1 / 3;
|
|
1887
|
+
/** Share of a motion drawn lifted, the peak included. */
|
|
1888
|
+
const LIFTED_SHARE = 2 / 3;
|
|
1889
|
+
/**
|
|
1890
|
+
* One chrome motion: how far through it the clock is, and how far above its
|
|
1891
|
+
* settled drawing the surface it belongs to is drawn right now.
|
|
1892
|
+
*/
|
|
1893
|
+
var Motion = class {
|
|
1894
|
+
options;
|
|
1895
|
+
/** @param options - the start, the length, the period, and the clock. */
|
|
1896
|
+
constructor(options) {
|
|
1897
|
+
this.options = options;
|
|
1898
|
+
}
|
|
1899
|
+
/**
|
|
1900
|
+
* How far through the motion the clock is.
|
|
1901
|
+
* @returns a fraction from 0 at the start to 1 once it has run its ticks;
|
|
1902
|
+
* 1 at once for a motion with no length at all.
|
|
1903
|
+
*/
|
|
1904
|
+
progress() {
|
|
1905
|
+
const { startedAt, ticks, stepMs, now } = this.options;
|
|
1906
|
+
const span = ticks * stepMs;
|
|
1907
|
+
if (span <= 0) return 1;
|
|
1908
|
+
return Math.min(1, Math.max(0, (now() - startedAt) / span));
|
|
1909
|
+
}
|
|
1910
|
+
/**
|
|
1911
|
+
* How far above its settled drawing the surface is right now.
|
|
1912
|
+
* @returns the peak for the first third of the motion, the lifted level for
|
|
1913
|
+
* the second, and the settled level for the rest.
|
|
1914
|
+
*/
|
|
1915
|
+
level() {
|
|
1916
|
+
const progress = this.progress();
|
|
1917
|
+
if (progress < PEAK_SHARE) return 2;
|
|
1918
|
+
if (progress < LIFTED_SHARE) return 1;
|
|
1919
|
+
return 0;
|
|
1920
|
+
}
|
|
1921
|
+
/**
|
|
1922
|
+
* Whether the motion still needs another repaint.
|
|
1923
|
+
* @returns true until it has run its ticks; the last periods draw the
|
|
1924
|
+
* settled level, which is what a reveal still grows through.
|
|
1925
|
+
*/
|
|
1926
|
+
needsRepaint() {
|
|
1927
|
+
return this.progress() < 1;
|
|
1928
|
+
}
|
|
1929
|
+
};
|
|
1930
|
+
/**
|
|
1931
|
+
* Lift one piece of chrome by a motion level.
|
|
1932
|
+
* @param palette - the palette the lift is drawn with.
|
|
1933
|
+
* @param text - the surface's own settled drawing of that piece, styling
|
|
1934
|
+
* included; the settled level hands it straight back.
|
|
1935
|
+
* @param level - how far above that drawing to lift it.
|
|
1936
|
+
* @returns the text at the peak, lifted, or exactly as it settles.
|
|
1937
|
+
*/
|
|
1938
|
+
function pulse(palette, text, level) {
|
|
1939
|
+
switch (level) {
|
|
1940
|
+
case 2: return palette.bold(palette.accent(text));
|
|
1941
|
+
case 1: return palette.accent(text);
|
|
1942
|
+
case 0: return text;
|
|
1943
|
+
/* v8 ignore next 2 -- closed-union exhaustiveness guard */
|
|
1944
|
+
default: return assertNever(level, "tui motion level");
|
|
1945
|
+
}
|
|
1946
|
+
}
|
|
1947
|
+
//#endregion
|
|
1858
1948
|
//#region lib/types/style.js
|
|
1859
1949
|
/**
|
|
1860
1950
|
* The terminal palette: one table of SGR open/close pairs behind named roles,
|
|
@@ -1987,14 +2077,53 @@ const NO_ARGUMENTS = "(no arguments)";
|
|
|
1987
2077
|
/** What the result section reports for a tool that answered with nothing. */
|
|
1988
2078
|
const NO_OUTPUT = "(no output)";
|
|
1989
2079
|
/**
|
|
2080
|
+
* Whether one transcript child folds.
|
|
2081
|
+
* @param child - a child of the transcript container.
|
|
2082
|
+
* @returns true when the child carries the foldable marker.
|
|
2083
|
+
*/
|
|
2084
|
+
function isFoldable(child) {
|
|
2085
|
+
return typeof child === "object" && child !== null && child.foldable === true;
|
|
2086
|
+
}
|
|
2087
|
+
/**
|
|
2088
|
+
* How one block draws while the keyboard holds it, or does not.
|
|
2089
|
+
* @param width - the width the transcript container gave the block.
|
|
2090
|
+
* @param highlight - the index of the focused section, or undefined while the keyboard is elsewhere.
|
|
2091
|
+
* @returns whether the gutter is drawn, and the columns it leaves the block.
|
|
2092
|
+
*/
|
|
2093
|
+
function focusFrame(width, highlight) {
|
|
2094
|
+
const marked = highlight !== void 0;
|
|
2095
|
+
return {
|
|
2096
|
+
marked,
|
|
2097
|
+
content: marked ? Math.max(1, width - GUTTER_WIDTH) : width
|
|
2098
|
+
};
|
|
2099
|
+
}
|
|
2100
|
+
/**
|
|
1990
2101
|
* Prepend the focus gutter to every line of a block that holds the focus.
|
|
1991
2102
|
* @param palette - the palette the gutter marks are styled with.
|
|
1992
2103
|
* @param lines - the block's final rendered lines, fades already applied.
|
|
1993
2104
|
* @param focused - whether the line at one index belongs to the focused section.
|
|
2105
|
+
* @param level - how far above its settled accent the focused section's own
|
|
2106
|
+
* mark is lifted, so a step of the walk is seen where it landed; the gutter
|
|
2107
|
+
* beside the block's other lines stays dim throughout.
|
|
1994
2108
|
* @returns the lines behind their gutter.
|
|
1995
2109
|
*/
|
|
1996
|
-
function withGutter(palette, lines, focused) {
|
|
1997
|
-
|
|
2110
|
+
function withGutter(palette, lines, focused, level) {
|
|
2111
|
+
const mark = pulse(palette, palette.accent(PART_GUTTER), level);
|
|
2112
|
+
return lines.map((line, index) => `${focused(index) ? mark : palette.dim(BLOCK_GUTTER)}${line}`);
|
|
2113
|
+
}
|
|
2114
|
+
/**
|
|
2115
|
+
* Which lines of a folded block the focus mark is drawn beside: the focused
|
|
2116
|
+
* section's own drawn rows, or the fold marker when the fold left that
|
|
2117
|
+
* section out of the transcript entirely. The marker stands for the rows the
|
|
2118
|
+
* fold took, so it is the line the mark belongs on once they include every
|
|
2119
|
+
* row the keyboard holds - a block drawn as focused always marks a line, and
|
|
2120
|
+
* the docked inspector's report that the block carries the mark stays true.
|
|
2121
|
+
* @param section - the focused section's drawn rows.
|
|
2122
|
+
* @param marker - the fold marker's rows; an empty run while the block folds nothing.
|
|
2123
|
+
* @returns the run the gutter accents.
|
|
2124
|
+
*/
|
|
2125
|
+
function markedRange(section, marker) {
|
|
2126
|
+
return section.to > section.from ? section : marker;
|
|
1998
2127
|
}
|
|
1999
2128
|
/** A prompt the user submitted, drawn with a leading `›`. */
|
|
2000
2129
|
var UserBlock = class {
|
|
@@ -2005,6 +2134,8 @@ var UserBlock = class {
|
|
|
2005
2134
|
blockKind = "user";
|
|
2006
2135
|
/** The section drawn as focused; absent while the keyboard is elsewhere. */
|
|
2007
2136
|
highlight;
|
|
2137
|
+
/** How far above its settled accent the focus mark is drawn right now. */
|
|
2138
|
+
highlightLevel = 0;
|
|
2008
2139
|
constructor(theme, text, turn) {
|
|
2009
2140
|
this.theme = theme;
|
|
2010
2141
|
this.text = text;
|
|
@@ -2024,16 +2155,16 @@ var UserBlock = class {
|
|
|
2024
2155
|
* Draw this prompt with the focus gutter, or without it.
|
|
2025
2156
|
* @param part - the index of the focused section, or undefined to clear the mark.
|
|
2026
2157
|
*/
|
|
2027
|
-
setHighlight(part) {
|
|
2158
|
+
setHighlight(part, level = 0) {
|
|
2028
2159
|
this.highlight = part;
|
|
2160
|
+
this.highlightLevel = level;
|
|
2029
2161
|
}
|
|
2030
2162
|
invalidate() {}
|
|
2031
2163
|
render(width) {
|
|
2032
2164
|
const palette = this.theme.palette;
|
|
2033
|
-
const marked = this.highlight
|
|
2034
|
-
const inner = marked ? Math.max(1, width - GUTTER_WIDTH) : width;
|
|
2165
|
+
const { marked, content: inner } = focusFrame(width, this.highlight);
|
|
2035
2166
|
const lines = ["", ...wrapTextWithAnsi(this.text, Math.max(1, inner - 2)).map((line, index) => `${palette.accent(index === 0 ? "›" : " ")} ${palette.bold(line)}`)];
|
|
2036
|
-
return marked ? withGutter(palette, lines, () => true) : lines;
|
|
2167
|
+
return marked ? withGutter(palette, lines, () => true, this.highlightLevel) : lines;
|
|
2037
2168
|
}
|
|
2038
2169
|
};
|
|
2039
2170
|
/** What a compact context row uses in place of the user prompt's `›`. */
|
|
@@ -2053,10 +2184,15 @@ var NoticeBlock = class {
|
|
|
2053
2184
|
}
|
|
2054
2185
|
};
|
|
2055
2186
|
/**
|
|
2056
|
-
* A system prompt or injected context
|
|
2057
|
-
*
|
|
2058
|
-
*
|
|
2059
|
-
*
|
|
2187
|
+
* A system prompt or injected context under a dim title, folded to
|
|
2188
|
+
* `contextPreviewLines` body rows until it is opened.
|
|
2189
|
+
*
|
|
2190
|
+
* One injection can carry more rows than the conversation around it, so the
|
|
2191
|
+
* transcript shows its head and names the key that draws the rest. What the
|
|
2192
|
+
* model was given is never cut from what the keyboard reads: `parts()` stays
|
|
2193
|
+
* complete, so the walk, the inspector, and any reader see every row whatever
|
|
2194
|
+
* the transcript draws. Snapshot contributions keep their names above their
|
|
2195
|
+
* own rows, and the Left/Right walk still addresses one contribution at a time.
|
|
2060
2196
|
*/
|
|
2061
2197
|
var ContextBlock = class {
|
|
2062
2198
|
theme;
|
|
@@ -2065,8 +2201,12 @@ var ContextBlock = class {
|
|
|
2065
2201
|
turn;
|
|
2066
2202
|
navigable = true;
|
|
2067
2203
|
blockKind = "context";
|
|
2204
|
+
foldable = true;
|
|
2068
2205
|
/** The section drawn as focused; absent while the keyboard is elsewhere. */
|
|
2069
2206
|
highlight;
|
|
2207
|
+
/** How far above its settled accent the focus mark is drawn right now. */
|
|
2208
|
+
highlightLevel = 0;
|
|
2209
|
+
expanded = false;
|
|
2070
2210
|
/**
|
|
2071
2211
|
* @param theme - the palette the glyph and title are styled with.
|
|
2072
2212
|
* @param title - form and producer, a notice summary, or `system prompt`.
|
|
@@ -2090,32 +2230,59 @@ var ContextBlock = class {
|
|
|
2090
2230
|
* Draw this row with the focus gutter, or without it.
|
|
2091
2231
|
* @param part - the index of the focused section, or undefined to clear the mark.
|
|
2092
2232
|
*/
|
|
2093
|
-
setHighlight(part) {
|
|
2233
|
+
setHighlight(part, level = 0) {
|
|
2094
2234
|
this.highlight = part;
|
|
2235
|
+
this.highlightLevel = level;
|
|
2236
|
+
}
|
|
2237
|
+
/**
|
|
2238
|
+
* Whether every model-facing row is drawn right now.
|
|
2239
|
+
* @returns true while the block is unfolded.
|
|
2240
|
+
*/
|
|
2241
|
+
isExpanded() {
|
|
2242
|
+
return this.expanded;
|
|
2243
|
+
}
|
|
2244
|
+
/**
|
|
2245
|
+
* Fold or unfold the body under the title.
|
|
2246
|
+
* @param expanded - whether every row is shown.
|
|
2247
|
+
*/
|
|
2248
|
+
setExpanded(expanded) {
|
|
2249
|
+
this.expanded = expanded;
|
|
2095
2250
|
}
|
|
2096
2251
|
invalidate() {}
|
|
2097
2252
|
render(width) {
|
|
2098
2253
|
const palette = this.theme.palette;
|
|
2099
|
-
const
|
|
2254
|
+
const { marked, content: inner } = focusFrame(width, this.highlight);
|
|
2100
2255
|
const textWidth = Math.max(1, inner - 2);
|
|
2101
2256
|
const indent = (line) => ` ${line}`;
|
|
2102
|
-
const
|
|
2257
|
+
const dimRows = (text) => wrapTextWithAnsi(text, textWidth).map((line) => indent(palette.dim(line)));
|
|
2258
|
+
const head = ["", ...wrapTextWithAnsi(this.title, textWidth).map((line, index) => `${palette.dim(index === 0 ? CONTEXT_GLYPH : " ")} ${palette.dim(line)}`)];
|
|
2259
|
+
const body = [];
|
|
2103
2260
|
const ranges = [];
|
|
2104
2261
|
for (const part of this.sectionParts) {
|
|
2105
|
-
const from =
|
|
2106
|
-
if (part.label !== void 0)
|
|
2107
|
-
if (!(part.rows.length === 1 && part.rows[0] === "")) for (const row of part.rows)
|
|
2262
|
+
const from = body.length;
|
|
2263
|
+
if (part.label !== void 0) body.push(...wrapTextWithAnsi(part.label, textWidth).map((line) => indent(palette.bold(line))));
|
|
2264
|
+
if (!(part.rows.length === 1 && part.rows[0] === "")) for (const row of part.rows) body.push(...dimRows(row));
|
|
2108
2265
|
ranges.push({
|
|
2109
2266
|
from,
|
|
2110
|
-
to:
|
|
2267
|
+
to: body.length
|
|
2111
2268
|
});
|
|
2112
2269
|
}
|
|
2270
|
+
const kept = this.theme.contextPreviewLines;
|
|
2271
|
+
const cut = !this.expanded && body.length > kept;
|
|
2272
|
+
const shown = cut ? [...body.slice(0, kept), ...dimRows(foldMarker(body.length - kept, marked ? "marked" : "transcript"))] : body;
|
|
2273
|
+
const lines = [...head, ...shown];
|
|
2113
2274
|
if (this.highlight === void 0) return lines;
|
|
2114
|
-
const section = ranges[this.highlight]
|
|
2115
|
-
|
|
2275
|
+
const section = ranges[this.highlight];
|
|
2276
|
+
if (section === void 0) return withGutter(palette, lines, () => true, this.highlightLevel);
|
|
2277
|
+
const drawn = Math.min(section.to, cut ? kept : body.length);
|
|
2278
|
+
const held = markedRange({
|
|
2279
|
+
from: head.length + section.from,
|
|
2280
|
+
to: head.length + drawn
|
|
2281
|
+
}, {
|
|
2282
|
+
from: head.length + (cut ? kept : body.length),
|
|
2116
2283
|
to: lines.length
|
|
2117
|
-
};
|
|
2118
|
-
return withGutter(palette, lines, (line) => line >=
|
|
2284
|
+
});
|
|
2285
|
+
return withGutter(palette, lines, (line) => line >= held.from && line < held.to, this.highlightLevel);
|
|
2119
2286
|
}
|
|
2120
2287
|
};
|
|
2121
2288
|
/**
|
|
@@ -2149,6 +2316,8 @@ var AssistantBlock = class {
|
|
|
2149
2316
|
repaintFloor = 0;
|
|
2150
2317
|
/** The section drawn as focused; absent while the keyboard is elsewhere. */
|
|
2151
2318
|
highlight;
|
|
2319
|
+
/** How far above its settled accent the focus mark is drawn right now. */
|
|
2320
|
+
highlightLevel = 0;
|
|
2152
2321
|
constructor(theme, turn) {
|
|
2153
2322
|
this.theme = theme;
|
|
2154
2323
|
this.turn = turn;
|
|
@@ -2180,8 +2349,9 @@ var AssistantBlock = class {
|
|
|
2180
2349
|
* Draw this message with the focus gutter, or without it.
|
|
2181
2350
|
* @param part - the index of the focused section, or undefined to clear the mark.
|
|
2182
2351
|
*/
|
|
2183
|
-
setHighlight(part) {
|
|
2352
|
+
setHighlight(part, level = 0) {
|
|
2184
2353
|
this.highlight = part;
|
|
2354
|
+
this.highlightLevel = level;
|
|
2185
2355
|
}
|
|
2186
2356
|
/**
|
|
2187
2357
|
* Draw this block's newest text through `fade` until it commits.
|
|
@@ -2246,7 +2416,7 @@ var AssistantBlock = class {
|
|
|
2246
2416
|
this.reasoningText.invalidate();
|
|
2247
2417
|
}
|
|
2248
2418
|
render(width) {
|
|
2249
|
-
const
|
|
2419
|
+
const { content: inner } = focusFrame(width, this.highlight);
|
|
2250
2420
|
const lines = [""];
|
|
2251
2421
|
const reasoning = {
|
|
2252
2422
|
from: 0,
|
|
@@ -2270,7 +2440,7 @@ var AssistantBlock = class {
|
|
|
2270
2440
|
if (this.interrupted) lines.push(this.theme.palette.dim("[interrupted]"));
|
|
2271
2441
|
if (this.highlight === void 0) return lines;
|
|
2272
2442
|
const section = this.parts()[this.highlight]?.kind === "reasoning" ? reasoning : reply;
|
|
2273
|
-
return withGutter(this.theme.palette, lines, (index) => index >= section.from && index < section.to);
|
|
2443
|
+
return withGutter(this.theme.palette, lines, (index) => index >= section.from && index < section.to, this.highlightLevel);
|
|
2274
2444
|
}
|
|
2275
2445
|
/**
|
|
2276
2446
|
* The reasoning lines, with the streaming tail floated out toward dim italic.
|
|
@@ -2324,6 +2494,7 @@ var ToolBlock = class {
|
|
|
2324
2494
|
turn;
|
|
2325
2495
|
navigable = true;
|
|
2326
2496
|
blockKind = "tool";
|
|
2497
|
+
foldable = true;
|
|
2327
2498
|
status = "running";
|
|
2328
2499
|
resultLines = [];
|
|
2329
2500
|
expanded = false;
|
|
@@ -2333,6 +2504,8 @@ var ToolBlock = class {
|
|
|
2333
2504
|
repaintFloor = 0;
|
|
2334
2505
|
/** The section drawn as focused; absent while the keyboard is elsewhere. */
|
|
2335
2506
|
highlight;
|
|
2507
|
+
/** How far above its settled accent the focus mark is drawn right now. */
|
|
2508
|
+
highlightLevel = 0;
|
|
2336
2509
|
constructor(theme, name, call, turn) {
|
|
2337
2510
|
this.theme = theme;
|
|
2338
2511
|
this.name = name;
|
|
@@ -2364,8 +2537,9 @@ var ToolBlock = class {
|
|
|
2364
2537
|
* Draw this card with the focus gutter, or without it.
|
|
2365
2538
|
* @param part - the index of the focused section, or undefined to clear the mark.
|
|
2366
2539
|
*/
|
|
2367
|
-
setHighlight(part) {
|
|
2540
|
+
setHighlight(part, level = 0) {
|
|
2368
2541
|
this.highlight = part;
|
|
2542
|
+
this.highlightLevel = level;
|
|
2369
2543
|
}
|
|
2370
2544
|
/**
|
|
2371
2545
|
* Draw the header and the call rows through `fade` until it settles.
|
|
@@ -2404,6 +2578,13 @@ var ToolBlock = class {
|
|
|
2404
2578
|
this.status = isError ? "error" : "done";
|
|
2405
2579
|
}
|
|
2406
2580
|
/**
|
|
2581
|
+
* Whether the whole body is drawn right now.
|
|
2582
|
+
* @returns true while the card is unfolded.
|
|
2583
|
+
*/
|
|
2584
|
+
isExpanded() {
|
|
2585
|
+
return this.expanded;
|
|
2586
|
+
}
|
|
2587
|
+
/**
|
|
2407
2588
|
* Fold or unfold the body.
|
|
2408
2589
|
* @param expanded - whether the full body is shown.
|
|
2409
2590
|
*/
|
|
@@ -2413,10 +2594,10 @@ var ToolBlock = class {
|
|
|
2413
2594
|
invalidate() {}
|
|
2414
2595
|
render(width) {
|
|
2415
2596
|
const palette = this.theme.palette;
|
|
2416
|
-
const
|
|
2597
|
+
const { marked, content: outer } = focusFrame(width, this.highlight);
|
|
2417
2598
|
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)}`}`;
|
|
2418
2599
|
const body = [...this.call.lines, ...this.resultLines];
|
|
2419
|
-
const shown =
|
|
2600
|
+
const shown = this.expanded ? body : foldRows(body, this.theme.toolPreviewLines, (hidden) => foldMarker(hidden, marked ? "marked" : "transcript"));
|
|
2420
2601
|
const callCount = Math.min(this.call.lines.length, shown.length);
|
|
2421
2602
|
const inner = Math.max(1, outer - 4);
|
|
2422
2603
|
const rows = (lines) => lines.flatMap((line) => wrapTextWithAnsi(line, inner).map((part) => ` ${palette.dim("│")} ${part}`));
|
|
@@ -2439,7 +2620,14 @@ var ToolBlock = class {
|
|
|
2439
2620
|
from: 1,
|
|
2440
2621
|
to: 1 + callLines.length
|
|
2441
2622
|
};
|
|
2442
|
-
|
|
2623
|
+
const held = markedRange({
|
|
2624
|
+
from: section.from,
|
|
2625
|
+
to: Math.min(section.to, sections)
|
|
2626
|
+
}, {
|
|
2627
|
+
from: sections,
|
|
2628
|
+
to: lines.length
|
|
2629
|
+
});
|
|
2630
|
+
return withGutter(palette, lines, (index) => index >= held.from && index < held.to, this.highlightLevel);
|
|
2443
2631
|
}
|
|
2444
2632
|
};
|
|
2445
2633
|
/**
|
|
@@ -2909,87 +3097,634 @@ async function exportSessionZip(ctx, sessionId, directory, signal) {
|
|
|
2909
3097
|
await pipeline(Readable.fromWeb(archive), createWriteStream(path), { signal });
|
|
2910
3098
|
return path;
|
|
2911
3099
|
}
|
|
3100
|
+
/** Columns the ` ─ ` between the chip and the title takes. */
|
|
3101
|
+
const CHIP_MARGIN = 3;
|
|
3102
|
+
/** What opens a top rule. */
|
|
3103
|
+
const TOP_LEFT = "╭";
|
|
3104
|
+
/** What closes a top rule. */
|
|
3105
|
+
const TOP_RIGHT = "╮";
|
|
3106
|
+
/** What opens a bottom rule. */
|
|
3107
|
+
const BOTTOM_LEFT = "╰";
|
|
3108
|
+
/** What closes a bottom rule. */
|
|
3109
|
+
const BOTTOM_RIGHT = "╯";
|
|
3110
|
+
/** What opens a rule drawn between two parts of one frame. */
|
|
3111
|
+
const LEGEND_LEFT = "├";
|
|
3112
|
+
/** What closes a rule drawn between two parts of one frame. */
|
|
3113
|
+
const LEGEND_RIGHT = "┤";
|
|
3114
|
+
/** What a rule fills the width between its texts with. */
|
|
3115
|
+
const FILL = "─";
|
|
3116
|
+
/** The left border of a body row; the frame has no right border. */
|
|
3117
|
+
const SIDE$1 = "│";
|
|
3118
|
+
/** What separates the chip from the title on a top rule. */
|
|
3119
|
+
const CHIP_JOIN = ` ${FILL} `;
|
|
3120
|
+
/** The mark the chip opens with, the one inverse block this surface draws. */
|
|
3121
|
+
const CHIP_MARK = "●";
|
|
3122
|
+
/** What ends a line the width cut short; one column, so the mark itself fits. */
|
|
3123
|
+
const ELLIPSIS$4 = "…";
|
|
3124
|
+
/**
|
|
3125
|
+
* The chip that names the active mode: the one inverse block this surface
|
|
3126
|
+
* draws, so a mode change is visible at a glance.
|
|
3127
|
+
* @param palette - the palette the chip is styled with.
|
|
3128
|
+
* @param text - the mode's name, as it is drawn.
|
|
3129
|
+
* @returns the chip, padded by one space on each side.
|
|
3130
|
+
*/
|
|
3131
|
+
function chip(palette, text) {
|
|
3132
|
+
return palette.inverse(palette.accent(` ${CHIP_MARK} ${text} `));
|
|
3133
|
+
}
|
|
3134
|
+
/**
|
|
3135
|
+
* Columns a rule leaves its own text.
|
|
3136
|
+
* @param width - the width the rule fits.
|
|
3137
|
+
* @param chipText - the chip a top rule opens with; omitted for a rule with none.
|
|
3138
|
+
* @returns the columns the title, the legend, and the readout share; at least 1.
|
|
3139
|
+
*/
|
|
3140
|
+
function ruleRoom(width, chipText = "") {
|
|
3141
|
+
const chipColumns = chipText === "" ? 0 : visibleWidth(chipText) + CHIP_MARGIN;
|
|
3142
|
+
return Math.max(1, width - 4 - chipColumns);
|
|
3143
|
+
}
|
|
3144
|
+
/**
|
|
3145
|
+
* The widest legend a width can hold.
|
|
3146
|
+
* @param steps - the declared steps, widest first.
|
|
3147
|
+
* @param width - the columns the legend has.
|
|
3148
|
+
* @returns the first step that fits, and the last step when none does — a
|
|
3149
|
+
* surface that names no way back would be worse than one cut short.
|
|
3150
|
+
*/
|
|
3151
|
+
function fitLegend(steps, width) {
|
|
3152
|
+
for (const step of steps) if (visibleWidth(step) <= width) return step;
|
|
3153
|
+
return steps.at(-1) ?? "";
|
|
3154
|
+
}
|
|
3155
|
+
/**
|
|
3156
|
+
* One rule of a frame.
|
|
3157
|
+
* @param open - the opening glyph.
|
|
3158
|
+
* @param close - the closing glyph.
|
|
3159
|
+
* @param parts - the texts, the width, the palette, and the tone.
|
|
3160
|
+
* @param chipText - the chip the rule opens with; empty for a rule with none.
|
|
3161
|
+
* @returns the line, exactly `width` columns while the closing glyph fits.
|
|
3162
|
+
*/
|
|
3163
|
+
function rule(open, close, parts, chipText) {
|
|
3164
|
+
const width = Math.max(1, parts.width);
|
|
3165
|
+
const { palette, level = 0 } = parts;
|
|
3166
|
+
const paint = parts.tone === "focus" ? (text) => pulse(palette, palette.accent(text), level) : palette.dim;
|
|
3167
|
+
const leading = [chipText, parts.left ?? ""].filter((text) => text !== "").join(paint(CHIP_JOIN));
|
|
3168
|
+
const head = leading === "" ? paint(open) : `${paint(open)} ${leading} `;
|
|
3169
|
+
const right = parts.right ?? "";
|
|
3170
|
+
const tail = right === "" ? paint(close) : ` ${right} ${paint(close)}`;
|
|
3171
|
+
const room = width - visibleWidth(tail);
|
|
3172
|
+
const cut = room >= 1 ? truncateToWidth(head, room, ELLIPSIS$4) : "";
|
|
3173
|
+
return truncateToWidth(`${cut}${paint(FILL.repeat(Math.max(0, width - visibleWidth(cut) - visibleWidth(tail))))}${tail}`, width, ELLIPSIS$4);
|
|
3174
|
+
}
|
|
3175
|
+
/**
|
|
3176
|
+
* The rule a framed surface opens with.
|
|
3177
|
+
* @param parts - the chip, the title, an optional readout, the width, the
|
|
3178
|
+
* palette, and the tone.
|
|
3179
|
+
* @returns the line, exactly `width` columns.
|
|
3180
|
+
*/
|
|
3181
|
+
function topRule(parts) {
|
|
3182
|
+
const { chip: chipText, title, ...rest } = parts;
|
|
3183
|
+
return rule(TOP_LEFT, TOP_RIGHT, {
|
|
3184
|
+
...rest,
|
|
3185
|
+
left: title ?? ""
|
|
3186
|
+
}, chipText ?? "");
|
|
3187
|
+
}
|
|
3188
|
+
/**
|
|
3189
|
+
* The rule a framed surface ends with, which carries its legend.
|
|
3190
|
+
* @param parts - the legend, an optional readout, the width, the palette, and the tone.
|
|
3191
|
+
* @returns the line, exactly `width` columns.
|
|
3192
|
+
*/
|
|
3193
|
+
function bottomRule(parts) {
|
|
3194
|
+
return rule(BOTTOM_LEFT, BOTTOM_RIGHT, parts, "");
|
|
3195
|
+
}
|
|
3196
|
+
/**
|
|
3197
|
+
* A rule drawn between two parts of one frame, for the legend of a surface
|
|
3198
|
+
* that goes on below it.
|
|
3199
|
+
* @param parts - the legend, an optional readout, the width, the palette, and the tone.
|
|
3200
|
+
* @returns the line, exactly `width` columns.
|
|
3201
|
+
*/
|
|
3202
|
+
function legendRule(parts) {
|
|
3203
|
+
return rule(LEGEND_LEFT, LEGEND_RIGHT, parts, "");
|
|
3204
|
+
}
|
|
3205
|
+
/**
|
|
3206
|
+
* One row inside a frame. There is no right border, so a row is not padded to
|
|
3207
|
+
* the width and a wrapped line keeps the width it was wrapped at.
|
|
3208
|
+
* @param content - the row, already styled and already wrapped.
|
|
3209
|
+
* @param width - the columns the line must fit.
|
|
3210
|
+
* @param palette - the palette the border is styled with.
|
|
3211
|
+
* @param tone - which role that border takes.
|
|
3212
|
+
* @param level - how far above its settled drawing the border is lifted, so
|
|
3213
|
+
* the whole outline of a frame moves as one; `0` draws the settled border.
|
|
3214
|
+
* @returns the line, no wider than `width`.
|
|
3215
|
+
*/
|
|
3216
|
+
function bodyLine(content, width, palette, tone, level = 0) {
|
|
3217
|
+
return truncateToWidth(`${tone === "focus" ? pulse(palette, palette.accent(SIDE$1), level) : palette.dim(SIDE$1)} ${content}`, Math.max(1, width), ELLIPSIS$4);
|
|
3218
|
+
}
|
|
3219
|
+
//#endregion
|
|
3220
|
+
//#region lib/types/keys.js
|
|
3221
|
+
/**
|
|
3222
|
+
* The key model: which action one press names in the region that holds the
|
|
3223
|
+
* keyboard, what one press types, how long a focus handoff silences the
|
|
3224
|
+
* editor's `Escape`, and the words every surface uses to name a key - the
|
|
3225
|
+
* legend each region degrades through, the entry keys the status bar
|
|
3226
|
+
* reserves, and the lines `/help` lists per region.
|
|
3227
|
+
*
|
|
3228
|
+
* Pure. It reads key bytes and returns actions, so the application owns every
|
|
3229
|
+
* effect and the whole map is decided without a terminal, a palette, or a
|
|
3230
|
+
* clock.
|
|
3231
|
+
* @module @deepseek-ai/dsh-tui-app/keys
|
|
3232
|
+
*/
|
|
3233
|
+
/** Characters a typed key never carries: C0 controls, DEL, and C1 controls. */
|
|
3234
|
+
const CONTROL_CHARACTERS = /[\u0000-\u001f\u007f-\u009f]/u;
|
|
3235
|
+
/**
|
|
3236
|
+
* The text one key press types.
|
|
3237
|
+
* @param data - the bytes the terminal sent.
|
|
3238
|
+
* @returns the characters to type, or undefined for control keys and escape sequences.
|
|
3239
|
+
*/
|
|
3240
|
+
function typedText(data) {
|
|
3241
|
+
const kitty = decodeKittyPrintable(data);
|
|
3242
|
+
if (kitty !== void 0) return kitty;
|
|
3243
|
+
return CONTROL_CHARACTERS.test(data) ? void 0 : data;
|
|
3244
|
+
}
|
|
3245
|
+
/**
|
|
3246
|
+
* The legend of each region, in declared degradation steps: the widest first,
|
|
3247
|
+
* every next one narrower, the last the shortest form that still names the way
|
|
3248
|
+
* back to the input. One grammar throughout - the keys the region answers,
|
|
3249
|
+
* then where `Esc` goes - so a legend is read the same way on every surface.
|
|
3250
|
+
* The editor draws no legend of its own: the unfocused status bar names the
|
|
3251
|
+
* keys that leave it.
|
|
3252
|
+
*/
|
|
3253
|
+
const HINTS = {
|
|
3254
|
+
editor: [],
|
|
3255
|
+
transcript: [
|
|
3256
|
+
"↑↓ sections · ←→ parts · Space folds · Ctrl+G reader · Esc input",
|
|
3257
|
+
"↑↓ ←→ · Space folds · Esc input",
|
|
3258
|
+
"Esc input"
|
|
3259
|
+
],
|
|
3260
|
+
panel: [
|
|
3261
|
+
"↑↓ children · Enter details · Tab regions · Esc input",
|
|
3262
|
+
"↑↓ children · Esc input",
|
|
3263
|
+
"Esc input"
|
|
3264
|
+
],
|
|
3265
|
+
bar: [
|
|
3266
|
+
"←→ segments · Enter details · Tab regions · Esc input",
|
|
3267
|
+
"←→ segments · Esc input",
|
|
3268
|
+
"Esc input"
|
|
3269
|
+
]
|
|
3270
|
+
};
|
|
3271
|
+
/**
|
|
3272
|
+
* The regions in the order `/help` lists them: the input first, because it is
|
|
3273
|
+
* where every other region is reached from and returned to. The screen stacks
|
|
3274
|
+
* them in another order, which {@link FocusRegion} states and the `Tab` walk
|
|
3275
|
+
* follows over the regions drawn right now.
|
|
3276
|
+
*/
|
|
3277
|
+
const FOCUS_REGIONS = [
|
|
3278
|
+
"editor",
|
|
3279
|
+
"transcript",
|
|
3280
|
+
"panel",
|
|
3281
|
+
"bar"
|
|
3282
|
+
];
|
|
3283
|
+
/** What each region is called where it is named rather than drawn. */
|
|
3284
|
+
const REGION_LABELS = {
|
|
3285
|
+
editor: "input",
|
|
3286
|
+
transcript: "conversation",
|
|
3287
|
+
panel: "subagent panel",
|
|
3288
|
+
bar: "status bar"
|
|
3289
|
+
};
|
|
3290
|
+
/** The two keys that leave the input, named on the unfocused status bar and in `/help`. */
|
|
3291
|
+
const ENTRY_KEYS = "Shift+↑ read · Shift+↓ status";
|
|
3292
|
+
/**
|
|
3293
|
+
* The entry keys the unfocused status bar reserves before any fact is placed,
|
|
3294
|
+
* in declared degradation steps. Both directions are named: reaching the
|
|
3295
|
+
* conversation and reaching the bar are the two ways out of the input, and a
|
|
3296
|
+
* key nobody can see is a key nobody presses.
|
|
3297
|
+
*/
|
|
3298
|
+
const ENTRY_HINTS = [ENTRY_KEYS, "Shift+↑↓ nav"];
|
|
3299
|
+
/**
|
|
3300
|
+
* The widest legend step of one region.
|
|
3301
|
+
* @param region - the region holding the keyboard.
|
|
3302
|
+
* @returns the step a surface draws when the width holds it, and the empty
|
|
3303
|
+
* string for the editor, which draws no legend.
|
|
3304
|
+
*/
|
|
3305
|
+
function widestHint(region) {
|
|
3306
|
+
return HINTS[region][0] ?? "";
|
|
3307
|
+
}
|
|
3308
|
+
/**
|
|
3309
|
+
* What `/help` lists per region: the legend the region draws, then the coarse
|
|
3310
|
+
* keys no legend has room for. The legends are read from {@link HINTS} rather
|
|
3311
|
+
* than written again, so a surface and `/help` can never name a key
|
|
3312
|
+
* differently. The editor draws no legend, so its own keys are listed here and
|
|
3313
|
+
* nowhere else. This is the screen's summary, not the complete map; the
|
|
3314
|
+
* package README carries every binding.
|
|
3315
|
+
*/
|
|
3316
|
+
const KEY_LINES = {
|
|
3317
|
+
editor: [
|
|
3318
|
+
"Enter sends · Shift+Enter newline · ↑↓ history · Ctrl+S steers · Shift+Tab effort",
|
|
3319
|
+
"@ completes paths and sessions · / completes commands · Tab takes one",
|
|
3320
|
+
`${ENTRY_KEYS} · Ctrl+G reader`,
|
|
3321
|
+
"Ctrl+O folds every tool card and context row",
|
|
3322
|
+
"Esc arms the stop · Esc again stops the turn",
|
|
3323
|
+
"Ctrl+C clears the input, twice quits · Ctrl+D quits an empty input"
|
|
3324
|
+
],
|
|
3325
|
+
transcript: [widestHint("transcript"), "Shift+↑↓ blocks · PgUp PgDn turns · Home End ends · Tab regions · Enter reads"],
|
|
3326
|
+
panel: [widestHint("panel")],
|
|
3327
|
+
bar: [widestHint("bar")]
|
|
3328
|
+
};
|
|
3329
|
+
/** `Escape`, which every region answers. */
|
|
3330
|
+
const ESCAPE = { kind: "escape" };
|
|
3331
|
+
/** `Ctrl+O`, which every region answers. */
|
|
3332
|
+
const FOLD_ALL = { kind: "fold-all" };
|
|
3333
|
+
/** `Ctrl+G`, which every region answers. */
|
|
3334
|
+
const READER = { kind: "reader" };
|
|
3335
|
+
/** `Enter` on the held section, row, or segment. */
|
|
3336
|
+
const OPEN = { kind: "open" };
|
|
3337
|
+
/**
|
|
3338
|
+
* What one key press means where the keyboard is.
|
|
3339
|
+
*
|
|
3340
|
+
* `Escape`, `Ctrl+O`, and `Ctrl+G` mean the same thing everywhere and are
|
|
3341
|
+
* answered first. Everything else is the region's own.
|
|
3342
|
+
* @param region - the region holding the keyboard.
|
|
3343
|
+
* @param data - the raw key bytes.
|
|
3344
|
+
* @returns the action to apply, or undefined when this region claims nothing
|
|
3345
|
+
* for the key: the editor lets pi-tui's own editor have it, and a docked
|
|
3346
|
+
* region consumes it without effect.
|
|
3347
|
+
*/
|
|
3348
|
+
function resolveKey(region, data) {
|
|
3349
|
+
if (matchesKey(data, "escape")) return ESCAPE;
|
|
3350
|
+
if (matchesKey(data, "ctrl+o")) return FOLD_ALL;
|
|
3351
|
+
if (matchesKey(data, "ctrl+g")) return READER;
|
|
3352
|
+
switch (region) {
|
|
3353
|
+
case "editor": return editorKey(data);
|
|
3354
|
+
case "transcript": return transcriptKey(data);
|
|
3355
|
+
case "panel": return panelKey(data);
|
|
3356
|
+
case "bar": return barKey(data);
|
|
3357
|
+
/* v8 ignore next 2 -- closed-union exhaustiveness guard */
|
|
3358
|
+
default: return assertNever(region, "tui focus region");
|
|
3359
|
+
}
|
|
3360
|
+
}
|
|
3361
|
+
/**
|
|
3362
|
+
* What one key means while the editor holds the keyboard.
|
|
3363
|
+
* @param data - the raw key bytes.
|
|
3364
|
+
* @returns the action, or undefined for every key pi-tui's editor owns.
|
|
3365
|
+
*/
|
|
3366
|
+
function editorKey(data) {
|
|
3367
|
+
if (matchesKey(data, "shift+up")) return {
|
|
3368
|
+
kind: "focus",
|
|
3369
|
+
region: "transcript"
|
|
3370
|
+
};
|
|
3371
|
+
if (matchesKey(data, "shift+down")) return {
|
|
3372
|
+
kind: "leave",
|
|
3373
|
+
direction: "down"
|
|
3374
|
+
};
|
|
3375
|
+
if (matchesKey(data, "ctrl+s")) return { kind: "steer" };
|
|
3376
|
+
if (matchesKey(data, "shift+tab")) return { kind: "effort" };
|
|
3377
|
+
}
|
|
3378
|
+
/**
|
|
3379
|
+
* The transcript's movement keys: the arrows step one section and one part,
|
|
3380
|
+
* the shift arrows a whole block and the ends of the held block, `PageUp` and
|
|
3381
|
+
* `PageDown` a turn, and `Home` and `End` the ends of the transcript.
|
|
3382
|
+
*/
|
|
3383
|
+
const TRANSCRIPT_MOVES = [
|
|
3384
|
+
{
|
|
3385
|
+
key: "up",
|
|
3386
|
+
axis: "section",
|
|
3387
|
+
to: "previous"
|
|
3388
|
+
},
|
|
3389
|
+
{
|
|
3390
|
+
key: "down",
|
|
3391
|
+
axis: "section",
|
|
3392
|
+
to: "next"
|
|
3393
|
+
},
|
|
3394
|
+
{
|
|
3395
|
+
key: "shift+up",
|
|
3396
|
+
axis: "block",
|
|
3397
|
+
to: "previous"
|
|
3398
|
+
},
|
|
3399
|
+
{
|
|
3400
|
+
key: "shift+down",
|
|
3401
|
+
axis: "block",
|
|
3402
|
+
to: "next"
|
|
3403
|
+
},
|
|
3404
|
+
{
|
|
3405
|
+
key: "pageUp",
|
|
3406
|
+
axis: "turn",
|
|
3407
|
+
to: "previous"
|
|
3408
|
+
},
|
|
3409
|
+
{
|
|
3410
|
+
key: "pageDown",
|
|
3411
|
+
axis: "turn",
|
|
3412
|
+
to: "next"
|
|
3413
|
+
},
|
|
3414
|
+
{
|
|
3415
|
+
key: "home",
|
|
3416
|
+
axis: "section",
|
|
3417
|
+
to: "first"
|
|
3418
|
+
},
|
|
3419
|
+
{
|
|
3420
|
+
key: "end",
|
|
3421
|
+
axis: "section",
|
|
3422
|
+
to: "last"
|
|
3423
|
+
},
|
|
3424
|
+
{
|
|
3425
|
+
key: "left",
|
|
3426
|
+
axis: "part",
|
|
3427
|
+
to: "previous"
|
|
3428
|
+
},
|
|
3429
|
+
{
|
|
3430
|
+
key: "right",
|
|
3431
|
+
axis: "part",
|
|
3432
|
+
to: "next"
|
|
3433
|
+
},
|
|
3434
|
+
{
|
|
3435
|
+
key: "shift+left",
|
|
3436
|
+
axis: "part",
|
|
3437
|
+
to: "first"
|
|
3438
|
+
},
|
|
3439
|
+
{
|
|
3440
|
+
key: "shift+right",
|
|
3441
|
+
axis: "part",
|
|
3442
|
+
to: "last"
|
|
3443
|
+
}
|
|
3444
|
+
];
|
|
3445
|
+
/**
|
|
3446
|
+
* The subagent panel's movement keys. The panel lists at most six rows, so
|
|
3447
|
+
* every coarse key means the same thing there: its first row or its last.
|
|
3448
|
+
*/
|
|
3449
|
+
const PANEL_MOVES = [
|
|
3450
|
+
{
|
|
3451
|
+
key: "up",
|
|
3452
|
+
axis: "row",
|
|
3453
|
+
to: "previous"
|
|
3454
|
+
},
|
|
3455
|
+
{
|
|
3456
|
+
key: "down",
|
|
3457
|
+
axis: "row",
|
|
3458
|
+
to: "next"
|
|
3459
|
+
},
|
|
3460
|
+
{
|
|
3461
|
+
key: "shift+up",
|
|
3462
|
+
axis: "row",
|
|
3463
|
+
to: "first"
|
|
3464
|
+
},
|
|
3465
|
+
{
|
|
3466
|
+
key: "home",
|
|
3467
|
+
axis: "row",
|
|
3468
|
+
to: "first"
|
|
3469
|
+
},
|
|
3470
|
+
{
|
|
3471
|
+
key: "pageUp",
|
|
3472
|
+
axis: "row",
|
|
3473
|
+
to: "first"
|
|
3474
|
+
},
|
|
3475
|
+
{
|
|
3476
|
+
key: "shift+down",
|
|
3477
|
+
axis: "row",
|
|
3478
|
+
to: "last"
|
|
3479
|
+
},
|
|
3480
|
+
{
|
|
3481
|
+
key: "end",
|
|
3482
|
+
axis: "row",
|
|
3483
|
+
to: "last"
|
|
3484
|
+
},
|
|
3485
|
+
{
|
|
3486
|
+
key: "pageDown",
|
|
3487
|
+
axis: "row",
|
|
3488
|
+
to: "last"
|
|
3489
|
+
}
|
|
3490
|
+
];
|
|
3491
|
+
/** The status bar's movement keys, along its one axis of segments. */
|
|
3492
|
+
const BAR_MOVES = [
|
|
3493
|
+
{
|
|
3494
|
+
key: "left",
|
|
3495
|
+
axis: "segment",
|
|
3496
|
+
to: "previous"
|
|
3497
|
+
},
|
|
3498
|
+
{
|
|
3499
|
+
key: "right",
|
|
3500
|
+
axis: "segment",
|
|
3501
|
+
to: "next"
|
|
3502
|
+
},
|
|
3503
|
+
{
|
|
3504
|
+
key: "shift+left",
|
|
3505
|
+
axis: "segment",
|
|
3506
|
+
to: "first"
|
|
3507
|
+
},
|
|
3508
|
+
{
|
|
3509
|
+
key: "home",
|
|
3510
|
+
axis: "segment",
|
|
3511
|
+
to: "first"
|
|
3512
|
+
},
|
|
3513
|
+
{
|
|
3514
|
+
key: "pageUp",
|
|
3515
|
+
axis: "segment",
|
|
3516
|
+
to: "first"
|
|
3517
|
+
},
|
|
3518
|
+
{
|
|
3519
|
+
key: "shift+right",
|
|
3520
|
+
axis: "segment",
|
|
3521
|
+
to: "last"
|
|
3522
|
+
},
|
|
3523
|
+
{
|
|
3524
|
+
key: "end",
|
|
3525
|
+
axis: "segment",
|
|
3526
|
+
to: "last"
|
|
3527
|
+
},
|
|
3528
|
+
{
|
|
3529
|
+
key: "pageDown",
|
|
3530
|
+
axis: "segment",
|
|
3531
|
+
to: "last"
|
|
3532
|
+
}
|
|
3533
|
+
];
|
|
3534
|
+
/**
|
|
3535
|
+
* What one press moves, in one region's table.
|
|
3536
|
+
* @param data - the raw key bytes.
|
|
3537
|
+
* @param bindings - the region's movement keys.
|
|
3538
|
+
* @returns the movement action, or undefined when the table has no binding for the key.
|
|
3539
|
+
*/
|
|
3540
|
+
function moveKey(data, bindings) {
|
|
3541
|
+
const binding = bindings.find((candidate) => matchesKey(data, candidate.key));
|
|
3542
|
+
return binding === void 0 ? void 0 : {
|
|
3543
|
+
kind: "move",
|
|
3544
|
+
axis: binding.axis,
|
|
3545
|
+
to: binding.to
|
|
3546
|
+
};
|
|
3547
|
+
}
|
|
3548
|
+
/**
|
|
3549
|
+
* `Tab` and `Shift+Tab`, which every region under the editor reads as the
|
|
3550
|
+
* walk between the regions that are drawn.
|
|
3551
|
+
* @param data - the raw key bytes.
|
|
3552
|
+
* @returns the cycling action, or undefined for any other key.
|
|
3553
|
+
*/
|
|
3554
|
+
function cycleKey(data) {
|
|
3555
|
+
if (matchesKey(data, "tab")) return {
|
|
3556
|
+
kind: "cycle",
|
|
3557
|
+
step: 1
|
|
3558
|
+
};
|
|
3559
|
+
if (matchesKey(data, "shift+tab")) return {
|
|
3560
|
+
kind: "cycle",
|
|
3561
|
+
step: -1
|
|
3562
|
+
};
|
|
3563
|
+
}
|
|
3564
|
+
/**
|
|
3565
|
+
* What one key means while the transcript holds the keyboard. `Space` is the
|
|
3566
|
+
* one printable key the transcript keeps for itself: folding the held block is
|
|
3567
|
+
* its primary verb, and a leading space would be trimmed off a prompt anyway.
|
|
3568
|
+
* @param data - the raw key bytes.
|
|
3569
|
+
* @returns the action, or undefined for a key the transcript consumes without effect.
|
|
3570
|
+
*/
|
|
3571
|
+
function transcriptKey(data) {
|
|
3572
|
+
const move = moveKey(data, TRANSCRIPT_MOVES);
|
|
3573
|
+
if (move !== void 0) return move;
|
|
3574
|
+
if (matchesKey(data, "enter")) return OPEN;
|
|
3575
|
+
if (matchesKey(data, "space")) return { kind: "fold" };
|
|
3576
|
+
return cycleKey(data) ?? typeKey(data);
|
|
3577
|
+
}
|
|
3578
|
+
/**
|
|
3579
|
+
* What one key means while the subagent panel holds the keyboard.
|
|
3580
|
+
* @param data - the raw key bytes.
|
|
3581
|
+
* @returns the action, or undefined for a key the panel consumes without effect.
|
|
3582
|
+
*/
|
|
3583
|
+
function panelKey(data) {
|
|
3584
|
+
const move = moveKey(data, PANEL_MOVES);
|
|
3585
|
+
if (move !== void 0) return move;
|
|
3586
|
+
if (matchesKey(data, "enter")) return OPEN;
|
|
3587
|
+
return cycleKey(data) ?? typeKey(data);
|
|
3588
|
+
}
|
|
3589
|
+
/**
|
|
3590
|
+
* What one key means while the status bar holds the keyboard. The bar is the
|
|
3591
|
+
* bottom of the stack, so `Up` leaves it and `Down` does nothing.
|
|
3592
|
+
* @param data - the raw key bytes.
|
|
3593
|
+
* @returns the action, or undefined for a key the bar consumes without effect.
|
|
3594
|
+
*/
|
|
3595
|
+
function barKey(data) {
|
|
3596
|
+
const move = moveKey(data, BAR_MOVES);
|
|
3597
|
+
if (move !== void 0) return move;
|
|
3598
|
+
if (matchesKey(data, "up")) return {
|
|
3599
|
+
kind: "leave",
|
|
3600
|
+
direction: "up"
|
|
3601
|
+
};
|
|
3602
|
+
if (matchesKey(data, "shift+up")) return {
|
|
3603
|
+
kind: "focus",
|
|
3604
|
+
region: "transcript"
|
|
3605
|
+
};
|
|
3606
|
+
if (matchesKey(data, "shift+down")) return {
|
|
3607
|
+
kind: "focus",
|
|
3608
|
+
region: "bar"
|
|
3609
|
+
};
|
|
3610
|
+
if (matchesKey(data, "enter")) return OPEN;
|
|
3611
|
+
return cycleKey(data) ?? typeKey(data);
|
|
3612
|
+
}
|
|
3613
|
+
/**
|
|
3614
|
+
* The printable law: a key that types something hands the keyboard back to
|
|
3615
|
+
* the editor and lands at its caret.
|
|
3616
|
+
* @param data - the raw key bytes.
|
|
3617
|
+
* @returns the typing action, or undefined for a key that types nothing.
|
|
3618
|
+
*/
|
|
3619
|
+
function typeKey(data) {
|
|
3620
|
+
const text = typedText(data);
|
|
3621
|
+
return text === void 0 ? void 0 : {
|
|
3622
|
+
kind: "type",
|
|
3623
|
+
text
|
|
3624
|
+
};
|
|
3625
|
+
}
|
|
2912
3626
|
//#endregion
|
|
2913
3627
|
//#region lib/types/inspector.js
|
|
2914
3628
|
/**
|
|
2915
3629
|
* The docked inspector above the editor: while the keyboard walks the
|
|
2916
|
-
* transcript it
|
|
2917
|
-
*
|
|
2918
|
-
*
|
|
3630
|
+
* transcript it frames the focused section - what it is, which part of its
|
|
3631
|
+
* block is held, and that part's own rows, folded at `focusPreviewLines` for
|
|
3632
|
+
* every section kind, with the reader drawing the rest.
|
|
2919
3633
|
*
|
|
2920
|
-
* It is the focus indicator that is always on screen
|
|
2921
|
-
*
|
|
2922
|
-
*
|
|
2923
|
-
*
|
|
2924
|
-
*
|
|
2925
|
-
*
|
|
2926
|
-
*
|
|
2927
|
-
*
|
|
3634
|
+
* It is the focus indicator that is always on screen: the frame is geometry
|
|
3635
|
+
* that appears only while the conversation holds the keyboard, and the chip
|
|
3636
|
+
* names the mode. A block is also marked in place, but only while the
|
|
3637
|
+
* renderer can still repaint its first line (`./navigation.ts`); when it
|
|
3638
|
+
* cannot, the heading says so and the frame itself goes dim, because what
|
|
3639
|
+
* cannot be marked cannot be rewritten either. Rows arrive as the block's
|
|
3640
|
+
* source text with no fade and no palette styling of their own, so a section
|
|
3641
|
+
* that is still streaming grows here as it arrives. A block with several parts
|
|
3642
|
+
* draws them as a numbered wrapping strip `← 1 call · [2 result] →` so
|
|
3643
|
+
* Left/Right walk is visible, the held part is legible without color, and
|
|
3644
|
+
* every part label stays on screen. The keyboard landing here lifts the whole
|
|
3645
|
+
* frame and its chip for a moment (`./motion.ts`); the row count is never part
|
|
3646
|
+
* of that, so the pane takes the same rows on every frame of the landing.
|
|
2928
3647
|
* @module @deepseek-ai/dsh-tui-app/inspector
|
|
2929
3648
|
*/
|
|
3649
|
+
/** What the chip names this mode. */
|
|
3650
|
+
const READ_CHIP = "READ";
|
|
3651
|
+
/** Columns a body row spends on the frame's left border and the space after it. */
|
|
3652
|
+
const BODY_MARGIN = 2;
|
|
2930
3653
|
/** What separates two labels of the parts strip. */
|
|
2931
3654
|
const SEPARATOR$3 = " · ";
|
|
2932
3655
|
/** What the heading appends while the focused block lies outside the repaint window. */
|
|
2933
3656
|
const OFF_SCREEN = " · off screen";
|
|
2934
|
-
/** The keys the inspector answers, drawn dim under its rows. */
|
|
2935
|
-
const HINT = "↑ ↓ sections · ← → parts · Enter page · Esc back";
|
|
2936
3657
|
/** Opens the numbered parts strip, so Left/Right read as a walk along this row. */
|
|
2937
3658
|
const STRIP_START = "← ";
|
|
2938
3659
|
/** Closes the numbered parts strip. */
|
|
2939
3660
|
const STRIP_END = " →";
|
|
2940
3661
|
/** What ends a line the width cut short; one column, so the mark itself fits. */
|
|
2941
|
-
const ELLIPSIS$
|
|
3662
|
+
const ELLIPSIS$3 = "…";
|
|
2942
3663
|
/**
|
|
2943
3664
|
* Draw the focused section.
|
|
2944
3665
|
* @param view - the section to show.
|
|
2945
3666
|
* @param render - the palette, the row budget, and the width.
|
|
2946
|
-
* @returns the inspector's lines, none wider than `width`:
|
|
2947
|
-
* the heading, the numbered parts strip when the block has more
|
|
2948
|
-
* (wrapped so every part stays on screen), the rows, and
|
|
3667
|
+
* @returns the inspector's lines, none wider than `width`: the top rule with
|
|
3668
|
+
* the chip and the heading, the numbered parts strip when the block has more
|
|
3669
|
+
* than one part (wrapped so every part stays on screen), the folded rows, and
|
|
3670
|
+
* the bottom rule with the legend.
|
|
2949
3671
|
*/
|
|
2950
3672
|
function renderInspector(view, render) {
|
|
2951
3673
|
const { palette } = render;
|
|
2952
3674
|
const width = Math.max(1, render.width);
|
|
2953
|
-
const
|
|
2954
|
-
|
|
2955
|
-
const
|
|
2956
|
-
const
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
|
|
2962
|
-
|
|
3675
|
+
const tone = view.highlighted ? "focus" : "muted";
|
|
3676
|
+
const level = tone === "focus" ? view.level ?? 0 : 0;
|
|
3677
|
+
const badge = chip(palette, READ_CHIP);
|
|
3678
|
+
const lines = [topRule({
|
|
3679
|
+
chip: pulse(palette, badge, level),
|
|
3680
|
+
title: heading(view, palette, ruleRoom(width, badge)),
|
|
3681
|
+
width,
|
|
3682
|
+
palette,
|
|
3683
|
+
tone,
|
|
3684
|
+
level
|
|
3685
|
+
})];
|
|
3686
|
+
const room = Math.max(1, width - BODY_MARGIN);
|
|
3687
|
+
if (view.parts.length > 1) for (const line of partsStrip(view.parts, palette, room)) lines.push(bodyLine(line, width, palette, tone, level));
|
|
3688
|
+
const body = foldRows(view.rows.flatMap((row) => wrapTextWithAnsi(row, room)), render.previewLines, (hidden) => palette.dim(foldMarker(hidden, "inspector")));
|
|
3689
|
+
for (const row of body) lines.push(bodyLine(row, width, palette, tone, level));
|
|
3690
|
+
lines.push(bottomRule({
|
|
3691
|
+
left: palette.dim(fitLegend(HINTS.transcript, ruleRoom(width))),
|
|
3692
|
+
width,
|
|
3693
|
+
palette,
|
|
3694
|
+
tone,
|
|
3695
|
+
level
|
|
3696
|
+
}));
|
|
3697
|
+
return lines;
|
|
2963
3698
|
}
|
|
2964
3699
|
/**
|
|
2965
|
-
* The heading
|
|
2966
|
-
* cut first and the off-screen mark stays whole: where the
|
|
2967
|
-
* must never be what the width hides.
|
|
3700
|
+
* The heading the top rule carries. A tool title can run past any terminal,
|
|
3701
|
+
* so the subject is cut first and the off-screen mark stays whole: where the
|
|
3702
|
+
* marked block went must never be what the width hides.
|
|
2968
3703
|
* @param view - the section to show.
|
|
2969
3704
|
* @param palette - the palette the heading is styled with.
|
|
2970
|
-
* @param
|
|
3705
|
+
* @param room - the columns the rule leaves its title; at least 1.
|
|
2971
3706
|
* @returns the heading, with the mark when the block is not on screen.
|
|
2972
3707
|
*/
|
|
2973
|
-
function heading(view, palette,
|
|
3708
|
+
function heading(view, palette, room) {
|
|
2974
3709
|
const subject = palette.bold(palette.accent(view.heading));
|
|
2975
3710
|
if (view.highlighted) return subject;
|
|
2976
3711
|
const suffix = palette.dim(OFF_SCREEN);
|
|
2977
|
-
return `${truncateToWidth(subject, Math.max(1,
|
|
3712
|
+
return `${truncateToWidth(subject, Math.max(1, room - visibleWidth(OFF_SCREEN)), ELLIPSIS$3)}${suffix}`;
|
|
2978
3713
|
}
|
|
2979
3714
|
/**
|
|
2980
3715
|
* Draw the parts of the focused block as numbered choices that wrap rather
|
|
2981
3716
|
* than disappearing past the width. `Left` / `Right` move along this list:
|
|
2982
|
-
* each label is `N name`, the held one is accented, and the
|
|
2983
|
-
* the walk stays inside this block.
|
|
3717
|
+
* each label is `N name`, the held one is bracketed and accented, and the
|
|
3718
|
+
* arrows mark that the walk stays inside this block.
|
|
2984
3719
|
* @param parts - the labels in reading order, the held one marked.
|
|
2985
3720
|
* @param palette - the palette the labels are styled with.
|
|
2986
|
-
* @param width - the width each line must fit; at least 1.
|
|
3721
|
+
* @param width - the width each line must fit inside the frame; at least 1.
|
|
2987
3722
|
* @returns the strip lines, every part present.
|
|
2988
3723
|
*/
|
|
2989
3724
|
function partsStrip(parts, palette, width) {
|
|
2990
3725
|
const tokens = parts.map((part, index) => {
|
|
2991
3726
|
const text = `${String(index + 1)} ${part.label}`;
|
|
2992
|
-
return part.focused ? palette.accent(text) : palette.dim(text);
|
|
3727
|
+
return part.focused ? palette.accent(`[${text}]`) : palette.dim(text);
|
|
2993
3728
|
});
|
|
2994
3729
|
const sep = palette.dim(SEPARATOR$3);
|
|
2995
3730
|
const indent = palette.dim(" ");
|
|
@@ -3017,9 +3752,9 @@ function partsStrip(parts, palette, width) {
|
|
|
3017
3752
|
leading = "";
|
|
3018
3753
|
leadingWidth = 0;
|
|
3019
3754
|
}
|
|
3020
|
-
const
|
|
3021
|
-
if (tokenWidth >
|
|
3022
|
-
const wrapped = wrapTextWithAnsi(token,
|
|
3755
|
+
const free = Math.max(1, width - used - extra);
|
|
3756
|
+
if (tokenWidth > free) {
|
|
3757
|
+
const wrapped = wrapTextWithAnsi(token, free);
|
|
3023
3758
|
const first = wrapped[0];
|
|
3024
3759
|
/* v8 ignore next -- wrapTextWithAnsi returns a line for nonempty text */
|
|
3025
3760
|
if (first === void 0) continue;
|
|
@@ -3082,6 +3817,8 @@ var InspectorPane = class {
|
|
|
3082
3817
|
* the call and the result of a tool — and `Left` / `Right` between the parts
|
|
3083
3818
|
* of the held block without leaving it. Snapshot contributions are separate
|
|
3084
3819
|
* parts of one injected block, so the arrows walk each named piece of context.
|
|
3820
|
+
* A long conversation is also walked coarsely: one block at a time, one turn
|
|
3821
|
+
* at a time over the groups each prompt opens, and to either end.
|
|
3085
3822
|
* This module turns the transcript container's children into that list and
|
|
3086
3823
|
* moves one cursor over it. Everything here is plain data: no pi-tui, no
|
|
3087
3824
|
* palette, no clock. The rows a part carries are the block's own source text,
|
|
@@ -3126,21 +3863,33 @@ function partCount(blocks, index) {
|
|
|
3126
3863
|
return blocks[index]?.parts().length ?? 0;
|
|
3127
3864
|
}
|
|
3128
3865
|
/**
|
|
3129
|
-
*
|
|
3130
|
-
* part, which is the most recent thing the session produced.
|
|
3866
|
+
* The oldest section of the transcript, which `Home` reaches.
|
|
3131
3867
|
* @param blocks - the navigable blocks.
|
|
3132
|
-
* @returns the cursor, or undefined when
|
|
3868
|
+
* @returns the cursor, or undefined when no block carries a section.
|
|
3133
3869
|
*/
|
|
3134
|
-
function
|
|
3135
|
-
|
|
3136
|
-
const parts = partCount(blocks, block);
|
|
3137
|
-
if (parts === 0) return void 0;
|
|
3138
|
-
return {
|
|
3870
|
+
function firstSection(blocks) {
|
|
3871
|
+
for (let block = 0; block < blocks.length; block += 1) if (partCount(blocks, block) > 0) return {
|
|
3139
3872
|
block,
|
|
3140
|
-
part:
|
|
3873
|
+
part: 0
|
|
3141
3874
|
};
|
|
3142
3875
|
}
|
|
3143
3876
|
/**
|
|
3877
|
+
* The newest section of the transcript: the most recent thing the session
|
|
3878
|
+
* produced, which `End` reaches and which the keyboard enters a transcript it
|
|
3879
|
+
* has not walked yet on.
|
|
3880
|
+
* @param blocks - the navigable blocks.
|
|
3881
|
+
* @returns the cursor, or undefined when no block carries a section.
|
|
3882
|
+
*/
|
|
3883
|
+
function lastSection(blocks) {
|
|
3884
|
+
for (let block = blocks.length - 1; block >= 0; block -= 1) {
|
|
3885
|
+
const parts = partCount(blocks, block);
|
|
3886
|
+
if (parts > 0) return {
|
|
3887
|
+
block,
|
|
3888
|
+
part: parts - 1
|
|
3889
|
+
};
|
|
3890
|
+
}
|
|
3891
|
+
}
|
|
3892
|
+
/**
|
|
3144
3893
|
* Every section of the transcript in drawing order, oldest block first and
|
|
3145
3894
|
* each block's parts in reading order. Blocks that currently expose no parts
|
|
3146
3895
|
* are omitted, so a walk never lands on an empty index.
|
|
@@ -3174,7 +3923,7 @@ function sameSection(left, right) {
|
|
|
3174
3923
|
* @param fallback - used when that index has no section.
|
|
3175
3924
|
* @returns that section.
|
|
3176
3925
|
*/
|
|
3177
|
-
function sectionAt(sections, index, fallback) {
|
|
3926
|
+
function sectionAt$1(sections, index, fallback) {
|
|
3178
3927
|
/* v8 ignore next -- callers pass an in-range index into a non-empty list */
|
|
3179
3928
|
return sections[index] ?? fallback;
|
|
3180
3929
|
}
|
|
@@ -3193,13 +3942,13 @@ function moveSection(cursor, step, blocks) {
|
|
|
3193
3942
|
const settled = clampCursor(cursor, blocks);
|
|
3194
3943
|
if (settled === void 0) {
|
|
3195
3944
|
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);
|
|
3945
|
+
if (index < 0) return sectionAt$1(sections, step >= 0 ? sections.length - 1 : 0, cursor);
|
|
3946
|
+
return sectionAt$1(sections, index, cursor);
|
|
3198
3947
|
}
|
|
3199
3948
|
const index = sections.findIndex((section) => sameSection(section, settled));
|
|
3200
3949
|
/* v8 ignore next -- a settled cursor is always in flattenSections */
|
|
3201
3950
|
if (index < 0) return settled;
|
|
3202
|
-
return sectionAt(sections, clampIndex(index + step, sections.length), settled);
|
|
3951
|
+
return sectionAt$1(sections, clampIndex(index + step, sections.length), settled);
|
|
3203
3952
|
}
|
|
3204
3953
|
/**
|
|
3205
3954
|
* Move between the parts of the held block.
|
|
@@ -3217,6 +3966,160 @@ function movePart(cursor, step, blocks) {
|
|
|
3217
3966
|
};
|
|
3218
3967
|
}
|
|
3219
3968
|
/**
|
|
3969
|
+
* Move to the neighbouring block, landing on its first section, which is the
|
|
3970
|
+
* coarse step over a conversation too long to walk section by section. A
|
|
3971
|
+
* block whose `parts()` is empty is skipped.
|
|
3972
|
+
* @param cursor - where the focus sits.
|
|
3973
|
+
* @param step - 1 for the next block, -1 for the previous one.
|
|
3974
|
+
* @param blocks - the navigable blocks.
|
|
3975
|
+
* @returns the new cursor; the held section at either end of the transcript,
|
|
3976
|
+
* and the cursor itself when no block carries a section.
|
|
3977
|
+
*/
|
|
3978
|
+
function moveBlock(cursor, step, blocks) {
|
|
3979
|
+
const settled = clampCursor(cursor, blocks);
|
|
3980
|
+
const from = settled?.block ?? cursor.block;
|
|
3981
|
+
for (let block = from + step; block >= 0 && block < blocks.length; block += step) if (partCount(blocks, block) > 0) return {
|
|
3982
|
+
block,
|
|
3983
|
+
part: 0
|
|
3984
|
+
};
|
|
3985
|
+
return settled ?? cursor;
|
|
3986
|
+
}
|
|
3987
|
+
/** What the group before the session's first prompt is called. */
|
|
3988
|
+
const SESSION_START = "session start";
|
|
3989
|
+
/**
|
|
3990
|
+
* The first line of one prompt, which names its turn.
|
|
3991
|
+
* @param parts - the prompt block's sections.
|
|
3992
|
+
* @returns the line, and the empty string for a prompt with no text.
|
|
3993
|
+
*/
|
|
3994
|
+
function promptLabel(parts) {
|
|
3995
|
+
const [first] = parts;
|
|
3996
|
+
const [line] = first?.rows ?? [];
|
|
3997
|
+
return line ?? "";
|
|
3998
|
+
}
|
|
3999
|
+
/**
|
|
4000
|
+
* Count one block into the group that holds it.
|
|
4001
|
+
* @param markers - the group's markers, updated in place.
|
|
4002
|
+
* @param block - the block.
|
|
4003
|
+
* @param parts - its sections, read once by the caller.
|
|
4004
|
+
*/
|
|
4005
|
+
function countMarkers(markers, block, parts) {
|
|
4006
|
+
if (block.blockKind === "context") markers.context += 1;
|
|
4007
|
+
if (block.blockKind === "tool") markers.tools += 1;
|
|
4008
|
+
for (const part of parts) {
|
|
4009
|
+
if (part.kind === "reasoning") markers.reasoning = true;
|
|
4010
|
+
if (part.kind === "reply") markers.reply = true;
|
|
4011
|
+
}
|
|
4012
|
+
}
|
|
4013
|
+
/**
|
|
4014
|
+
* Group the transcript by prompt: every `user` block opens a group, and the
|
|
4015
|
+
* blocks before the first prompt — a system prompt and the context injected
|
|
4016
|
+
* with it — form one `session start` group.
|
|
4017
|
+
*
|
|
4018
|
+
* The grouping is the prompts themselves rather than `block.turn`, because a
|
|
4019
|
+
* prompt block carries the turn in force when it was appended, which is the
|
|
4020
|
+
* turn before the one it opens.
|
|
4021
|
+
* @param blocks - the navigable blocks.
|
|
4022
|
+
* @returns the groups, oldest first; a group with no section at all is left
|
|
4023
|
+
* out, so every group the keyboard reaches can be entered.
|
|
4024
|
+
*/
|
|
4025
|
+
function turnGroups(blocks) {
|
|
4026
|
+
const groups = [];
|
|
4027
|
+
let open;
|
|
4028
|
+
for (const [index, block] of blocks.entries()) {
|
|
4029
|
+
const parts = block.parts();
|
|
4030
|
+
if (open === void 0 || block.blockKind === "user") {
|
|
4031
|
+
open = {
|
|
4032
|
+
turn: block.turn,
|
|
4033
|
+
label: block.blockKind === "user" ? promptLabel(parts) : SESSION_START,
|
|
4034
|
+
markers: {
|
|
4035
|
+
context: 0,
|
|
4036
|
+
reasoning: false,
|
|
4037
|
+
reply: false,
|
|
4038
|
+
tools: 0
|
|
4039
|
+
},
|
|
4040
|
+
sections: []
|
|
4041
|
+
};
|
|
4042
|
+
groups.push(open);
|
|
4043
|
+
}
|
|
4044
|
+
open.turn = Math.max(open.turn, block.turn);
|
|
4045
|
+
countMarkers(open.markers, block, parts);
|
|
4046
|
+
for (let part = 0; part < parts.length; part += 1) open.sections.push({
|
|
4047
|
+
block: index,
|
|
4048
|
+
part
|
|
4049
|
+
});
|
|
4050
|
+
}
|
|
4051
|
+
return groups.filter((group) => group.sections.length > 0);
|
|
4052
|
+
}
|
|
4053
|
+
/**
|
|
4054
|
+
* Which group holds one cursor.
|
|
4055
|
+
* @param cursor - where the focus sits.
|
|
4056
|
+
* @param groups - the groups of the same transcript.
|
|
4057
|
+
* @returns the index into `groups`, or -1 when no group holds the cursor's block.
|
|
4058
|
+
*/
|
|
4059
|
+
function turnIndexOf(cursor, groups) {
|
|
4060
|
+
return groups.findIndex((group) => group.sections.some((section) => section.block === cursor.block));
|
|
4061
|
+
}
|
|
4062
|
+
/**
|
|
4063
|
+
* One section of one group, by position.
|
|
4064
|
+
* @param groups - the groups of the transcript.
|
|
4065
|
+
* @param group - the index into `groups`; an index outside it is pulled to the nearest end.
|
|
4066
|
+
* @param section - the index into that group's sections, pulled the same way.
|
|
4067
|
+
* @returns the cursor, or undefined when the transcript has no group at all.
|
|
4068
|
+
*/
|
|
4069
|
+
function cursorAt(groups, group, section) {
|
|
4070
|
+
const held = groups[clampIndex(group, groups.length)];
|
|
4071
|
+
if (held === void 0) return void 0;
|
|
4072
|
+
return held.sections[clampIndex(section, held.sections.length)];
|
|
4073
|
+
}
|
|
4074
|
+
/**
|
|
4075
|
+
* Move to the neighbouring turn, landing on its first section.
|
|
4076
|
+
* @param cursor - where the focus sits.
|
|
4077
|
+
* @param step - 1 for the next turn, -1 for the previous one.
|
|
4078
|
+
* @param blocks - the navigable blocks.
|
|
4079
|
+
* @returns the new cursor; the first section of the held turn at either end,
|
|
4080
|
+
* and the cursor itself when no group holds it.
|
|
4081
|
+
*/
|
|
4082
|
+
function moveTurn(cursor, step, blocks) {
|
|
4083
|
+
const groups = turnGroups(blocks);
|
|
4084
|
+
const index = turnIndexOf(cursor, groups);
|
|
4085
|
+
if (index === -1) return cursor;
|
|
4086
|
+
/* v8 ignore next -- a clamped index names a group, and every group carries a section */
|
|
4087
|
+
return cursorAt(groups, index + step, 0) ?? cursor;
|
|
4088
|
+
}
|
|
4089
|
+
/**
|
|
4090
|
+
* Which way one target steps along its axis.
|
|
4091
|
+
* @param to - the target the key named.
|
|
4092
|
+
* @returns -1 towards the start of the axis, 1 towards its end.
|
|
4093
|
+
*/
|
|
4094
|
+
function stepFor(to) {
|
|
4095
|
+
return to === "previous" || to === "first" ? -1 : 1;
|
|
4096
|
+
}
|
|
4097
|
+
/**
|
|
4098
|
+
* Step the transcript focus along one axis, which is what every transcript
|
|
4099
|
+
* movement key does.
|
|
4100
|
+
* @param cursor - where the focus sits.
|
|
4101
|
+
* @param axis - what the key steps along.
|
|
4102
|
+
* @param to - which way along it.
|
|
4103
|
+
* @param blocks - the navigable blocks.
|
|
4104
|
+
* @returns the new cursor, and the held one at the end of the axis.
|
|
4105
|
+
*/
|
|
4106
|
+
function moveTranscriptCursor(cursor, axis, to, blocks) {
|
|
4107
|
+
switch (axis) {
|
|
4108
|
+
case "section":
|
|
4109
|
+
if (to === "first") return firstSection(blocks) ?? cursor;
|
|
4110
|
+
if (to === "last") return lastSection(blocks) ?? cursor;
|
|
4111
|
+
return moveSection(cursor, stepFor(to), blocks);
|
|
4112
|
+
case "part": {
|
|
4113
|
+
const reach = to === "first" || to === "last" ? partCount(blocks, cursor.block) : 1;
|
|
4114
|
+
return movePart(cursor, stepFor(to) * reach, blocks);
|
|
4115
|
+
}
|
|
4116
|
+
case "block": return moveBlock(cursor, stepFor(to), blocks);
|
|
4117
|
+
case "turn": return moveTurn(cursor, stepFor(to), blocks);
|
|
4118
|
+
/* v8 ignore next 2 -- closed-union exhaustiveness guard */
|
|
4119
|
+
default: return assertNever(axis, "tui transcript axis");
|
|
4120
|
+
}
|
|
4121
|
+
}
|
|
4122
|
+
/**
|
|
3220
4123
|
* Put a remembered cursor back on the current transcript, which grew a block,
|
|
3221
4124
|
* grew a part, or was replaced by another session since it was taken.
|
|
3222
4125
|
* @param cursor - the remembered cursor.
|
|
@@ -3268,6 +4171,18 @@ function subjectOf(block, part) {
|
|
|
3268
4171
|
}
|
|
3269
4172
|
}
|
|
3270
4173
|
/**
|
|
4174
|
+
* What one section is called: `you`, `reply`, the tool card and its section,
|
|
4175
|
+
* or the injected context and its contribution. The docked inspector names it
|
|
4176
|
+
* after the position and turn; a surface that already states both prints the
|
|
4177
|
+
* label alone.
|
|
4178
|
+
* @param block - the block the section belongs to.
|
|
4179
|
+
* @param part - the section.
|
|
4180
|
+
* @returns the label, e.g. `bash git status · result`.
|
|
4181
|
+
*/
|
|
4182
|
+
function sectionLabel(block, part) {
|
|
4183
|
+
return subjectOf(block, part).join(SEPARATOR$2);
|
|
4184
|
+
}
|
|
4185
|
+
/**
|
|
3271
4186
|
* The inspector heading of the held section: its position in the transcript,
|
|
3272
4187
|
* the turn it belongs to, and what the section is.
|
|
3273
4188
|
* @param cursor - where the focus sits.
|
|
@@ -3281,7 +4196,7 @@ function sectionHeading(cursor, blocks) {
|
|
|
3281
4196
|
return [
|
|
3282
4197
|
`${String(cursor.block + 1)}/${String(blocks.length)}`,
|
|
3283
4198
|
`turn ${String(block.turn)}`,
|
|
3284
|
-
|
|
4199
|
+
sectionLabel(block, part)
|
|
3285
4200
|
].join(SEPARATOR$2);
|
|
3286
4201
|
}
|
|
3287
4202
|
/**
|
|
@@ -3697,8 +4612,9 @@ function plural(count, noun) {
|
|
|
3697
4612
|
* of segments, each with a stable id, the short label the bar draws, and what
|
|
3698
4613
|
* `Enter` on it does — the rows the app prints, or the app's own navigable
|
|
3699
4614
|
* page with the one-line summary the focused bar expands; a second function
|
|
3700
|
-
* renders those segments as one unfocused line
|
|
3701
|
-
*
|
|
4615
|
+
* renders those segments as one unfocused line whose two ends are reserved
|
|
4616
|
+
* for the model and the entry keys, or as two focused lines whose first is
|
|
4617
|
+
* that same anchored model plus a sliding window around the selected
|
|
3702
4618
|
* segment. Everything here is pure — no Context, no
|
|
3703
4619
|
* services, no terminal, and no clock: elapsed values arrive already formatted,
|
|
3704
4620
|
* and the terminal width arrives as an input so every line fits it.
|
|
@@ -3717,12 +4633,29 @@ const SEPARATOR$1 = " · ";
|
|
|
3717
4633
|
const WORKSPACE_LABEL_WIDTH = 24;
|
|
3718
4634
|
/** The last two segments of a path, with the separators that precede them. */
|
|
3719
4635
|
const PATH_TAIL = /[/\\][^/\\]+[/\\][^/\\]+$/u;
|
|
3720
|
-
/**
|
|
3721
|
-
|
|
3722
|
-
|
|
3723
|
-
|
|
4636
|
+
/**
|
|
4637
|
+
* Longest model label the bar draws in full. A wider `provider/model` pair
|
|
4638
|
+
* falls back to the bare model name and only then is ellipsized, so the fact
|
|
4639
|
+
* the next request depends on is never the one the width eats. A presentation
|
|
4640
|
+
* choice of this terminal surface, not a deployment setting.
|
|
4641
|
+
*/
|
|
4642
|
+
const MODEL_LABEL_WIDTH = 20;
|
|
4643
|
+
/** Narrowest line that still names an entry key; below it the facts take the whole width. */
|
|
4644
|
+
const HINT_MIN_WIDTH = 40;
|
|
4645
|
+
/** The most of the line one entry hint takes, as a divisor: a third, so the facts keep the rest. */
|
|
4646
|
+
const HINT_WIDTH_SHARE = 3;
|
|
4647
|
+
/** Columns kept clear between the last fact and the entry hint, so they never read as one list. */
|
|
4648
|
+
const HINT_GAP = 2;
|
|
4649
|
+
/** What marks that the focused window starts after the segment next to the anchor. */
|
|
4650
|
+
const WINDOW_START = "‹";
|
|
4651
|
+
/** What marks that the focused window ends before the last segment. */
|
|
4652
|
+
const WINDOW_END = "›";
|
|
4653
|
+
/** Columns the closing window mark takes, the space before it included. */
|
|
4654
|
+
const WINDOW_MARK_WIDTH = 2;
|
|
4655
|
+
/** Columns the brackets around the selected label take. */
|
|
4656
|
+
const BRACKET_WIDTH = 2;
|
|
3724
4657
|
/** What ends a line the width cut short; one column, so the mark itself fits. */
|
|
3725
|
-
const ELLIPSIS = "…";
|
|
4658
|
+
const ELLIPSIS$2 = "…";
|
|
3726
4659
|
/** Facts the unfocused line keeps; every other present segment folds into `+N`. */
|
|
3727
4660
|
const KEY_SEGMENT_IDS = new Set([
|
|
3728
4661
|
"model",
|
|
@@ -3818,6 +4751,7 @@ function buildFooterSegments(inputs) {
|
|
|
3818
4751
|
const segments = [{
|
|
3819
4752
|
id: "model",
|
|
3820
4753
|
label: `${selection.provider}/${selection.model}`,
|
|
4754
|
+
short: selection.model,
|
|
3821
4755
|
detail: printed([
|
|
3822
4756
|
`provider: ${selection.provider}`,
|
|
3823
4757
|
`model: ${selection.model}`,
|
|
@@ -3930,21 +4864,77 @@ function windowSpan(widths, selected, budget, sep) {
|
|
|
3930
4864
|
* @returns the line, ellipsized when it was wider.
|
|
3931
4865
|
*/
|
|
3932
4866
|
function fitLine(line, width) {
|
|
3933
|
-
return truncateToWidth(line, Math.max(1, width), ELLIPSIS);
|
|
4867
|
+
return truncateToWidth(line, Math.max(1, width), ELLIPSIS$2);
|
|
3934
4868
|
}
|
|
3935
4869
|
/**
|
|
3936
|
-
* The
|
|
4870
|
+
* The label the bar draws for the segment it anchors on, which
|
|
4871
|
+
* `buildFooterSegments` always emits first: the full one while it fits its
|
|
4872
|
+
* budget, then the segment's own shorter form, and only then an ellipsis.
|
|
4873
|
+
* @param segment - the anchored segment; absent for an empty bar.
|
|
4874
|
+
* @returns the label, never wider than {@link MODEL_LABEL_WIDTH}.
|
|
4875
|
+
*/
|
|
4876
|
+
function anchorLabel(segment) {
|
|
4877
|
+
if (segment === void 0) return "";
|
|
4878
|
+
if (visibleWidth(segment.label) <= MODEL_LABEL_WIDTH) return segment.label;
|
|
4879
|
+
return truncateToWidth(segment.short ?? segment.label, MODEL_LABEL_WIDTH, ELLIPSIS$2);
|
|
4880
|
+
}
|
|
4881
|
+
/**
|
|
4882
|
+
* The entry keys this width names.
|
|
4883
|
+
* @param width - terminal columns the line must fit.
|
|
4884
|
+
* @returns the widest step that keeps the facts the majority of the line, and
|
|
4885
|
+
* the empty string on a terminal too narrow to spare the columns.
|
|
4886
|
+
*/
|
|
4887
|
+
function entryHint(width) {
|
|
4888
|
+
if (width < HINT_MIN_WIDTH) return "";
|
|
4889
|
+
return fitLegend(ENTRY_HINTS, Math.floor(width / HINT_WIDTH_SHARE));
|
|
4890
|
+
}
|
|
4891
|
+
/**
|
|
4892
|
+
* The key facts that fit the middle of the unfocused line.
|
|
4893
|
+
* @param facts - the key labels after the anchor, in bar order.
|
|
4894
|
+
* @param hidden - segments the bar folds away whatever the width, because
|
|
4895
|
+
* they are not among its key facts.
|
|
4896
|
+
* @param room - columns the middle has, the anchor and the hint already taken.
|
|
4897
|
+
* @returns the labels to draw, the `+N` token last when anything is folded.
|
|
4898
|
+
*/
|
|
4899
|
+
function middleFacts(facts, hidden, room) {
|
|
4900
|
+
const drawn = [];
|
|
4901
|
+
let used = 0;
|
|
4902
|
+
for (const label of facts) {
|
|
4903
|
+
const cost = visibleWidth(SEPARATOR$1) + visibleWidth(label);
|
|
4904
|
+
if (used + cost > room) break;
|
|
4905
|
+
used += cost;
|
|
4906
|
+
drawn.push(label);
|
|
4907
|
+
}
|
|
4908
|
+
let folded = hidden + facts.length - drawn.length;
|
|
4909
|
+
if (folded === 0) return drawn;
|
|
4910
|
+
const token = () => `+${String(folded)}`;
|
|
4911
|
+
const fits = () => used + visibleWidth(SEPARATOR$1) + visibleWidth(token()) <= room;
|
|
4912
|
+
while (!fits() && drawn.length > 0) {
|
|
4913
|
+
used -= visibleWidth(SEPARATOR$1) + visibleWidth(drawn.pop());
|
|
4914
|
+
folded += 1;
|
|
4915
|
+
}
|
|
4916
|
+
if (fits()) drawn.push(token());
|
|
4917
|
+
return drawn;
|
|
4918
|
+
}
|
|
4919
|
+
/**
|
|
4920
|
+
* The unfocused line, built from both ends inward: the anchored model label,
|
|
4921
|
+
* the entry keys reserved at the right edge, and the key facts filling
|
|
4922
|
+
* whatever middle is left, every segment they cannot hold folded into `+N`.
|
|
3937
4923
|
* @param segments - the segments in bar order.
|
|
3938
4924
|
* @param palette - the palette the line is dimmed with.
|
|
3939
4925
|
* @param width - terminal columns the line must fit.
|
|
3940
4926
|
* @returns one dim line.
|
|
3941
4927
|
*/
|
|
3942
4928
|
function unfocusedLine(segments, palette, width) {
|
|
3943
|
-
const
|
|
3944
|
-
const
|
|
3945
|
-
|
|
3946
|
-
|
|
3947
|
-
|
|
4929
|
+
const [anchor, ...rest] = segments;
|
|
4930
|
+
const model = anchorLabel(anchor);
|
|
4931
|
+
const hint = entryHint(width);
|
|
4932
|
+
const reserved = hint === "" ? 0 : visibleWidth(hint) + HINT_GAP;
|
|
4933
|
+
const facts = rest.filter((segment) => KEY_SEGMENT_IDS.has(segment.id)).map((segment) => segment.label);
|
|
4934
|
+
const drawn = middleFacts(facts, rest.length - facts.length, width - visibleWidth(model) - reserved);
|
|
4935
|
+
const left = palette.dim([model, ...drawn].filter((token) => token !== "").join(SEPARATOR$1));
|
|
4936
|
+
if (hint === "") return fitLine(left, width);
|
|
4937
|
+
return fitLine(`${left}${" ".repeat(Math.max(1, width - visibleWidth(left) - visibleWidth(hint)))}${palette.dim(hint)}`, width);
|
|
3948
4938
|
}
|
|
3949
4939
|
/**
|
|
3950
4940
|
* The first detail row of a printed segment, or the summary of a page segment.
|
|
@@ -3957,40 +4947,103 @@ function expansionBody(segment) {
|
|
|
3957
4947
|
return segment.detail.rows[0];
|
|
3958
4948
|
}
|
|
3959
4949
|
/**
|
|
3960
|
-
* The focused second line: the selected segment's summary plus the
|
|
4950
|
+
* The focused second line: the selected segment's summary plus the keys the
|
|
4951
|
+
* bar answers. The legend takes the width's own step before the summary is
|
|
4952
|
+
* measured, so a narrow terminal drops legend words instead of cutting the
|
|
4953
|
+
* way back to the input off the end of the line.
|
|
3961
4954
|
* @param segment - the selected segment.
|
|
3962
4955
|
* @param palette - the palette the line is dimmed with.
|
|
3963
4956
|
* @param width - terminal columns the line must fit.
|
|
3964
|
-
* @returns one dim line
|
|
4957
|
+
* @returns one dim line.
|
|
3965
4958
|
*/
|
|
3966
4959
|
function expansionLine(segment, palette, width) {
|
|
3967
4960
|
const body = expansionBody(segment);
|
|
3968
|
-
const
|
|
4961
|
+
const legend = fitLegend(HINTS.bar, width);
|
|
4962
|
+
const suffix = palette.dim(body === "" ? legend : `${SEPARATOR$1}${legend}`);
|
|
3969
4963
|
const prefix = palette.dim(body);
|
|
3970
4964
|
const rest = width - visibleWidth(suffix);
|
|
3971
4965
|
if (rest < 1) return fitLine(`${prefix}${suffix}`, width);
|
|
3972
|
-
return `${truncateToWidth(prefix, rest, ELLIPSIS)}${suffix}`;
|
|
3973
|
-
}
|
|
3974
|
-
/**
|
|
3975
|
-
*
|
|
4966
|
+
return `${truncateToWidth(prefix, rest, ELLIPSIS$2)}${suffix}`;
|
|
4967
|
+
}
|
|
4968
|
+
/**
|
|
4969
|
+
* One segment label as the focused bar draws it. The selected one is
|
|
4970
|
+
* bracketed as well as accented, so which segment `Enter` opens is legible
|
|
4971
|
+
* without color, and a walk that just reached it draws it lifted until the
|
|
4972
|
+
* motion settles back onto the accent.
|
|
4973
|
+
* @param text - the label.
|
|
4974
|
+
* @param selected - whether the bar holds this segment.
|
|
4975
|
+
* @param palette - the palette the label is styled with.
|
|
4976
|
+
* @param level - how far above the settled label to lift it.
|
|
4977
|
+
* @returns the styled label.
|
|
4978
|
+
*/
|
|
4979
|
+
function segmentLabel(text, selected, palette, level) {
|
|
4980
|
+
return selected ? pulse(palette, palette.accent(`[${text}]`), level) : palette.dim(text);
|
|
4981
|
+
}
|
|
4982
|
+
/**
|
|
4983
|
+
* The text a selected label keeps where the window cannot hold all of it. The
|
|
4984
|
+
* brackets are what says which segment `Enter` opens on a terminal without
|
|
4985
|
+
* color, so the label's own text is what gives way rather than the bracket
|
|
4986
|
+
* that closes it.
|
|
4987
|
+
* @param text - the label.
|
|
4988
|
+
* @param room - columns the bracketed label may take.
|
|
4989
|
+
* @returns the text, cut so that it and both brackets fit `room`.
|
|
4990
|
+
*/
|
|
4991
|
+
function fitSelected(text, room) {
|
|
4992
|
+
const inside = room - BRACKET_WIDTH;
|
|
4993
|
+
if (visibleWidth(text) <= inside) return text;
|
|
4994
|
+
return truncateToWidth(text, Math.max(1, inside), ELLIPSIS$2);
|
|
4995
|
+
}
|
|
4996
|
+
/**
|
|
4997
|
+
* The segments after the anchor, windowed around the selection. `‹` and `›`
|
|
4998
|
+
* mark the side the window is cut on, so a walk that slid past a fact says so
|
|
4999
|
+
* rather than appearing to have lost it.
|
|
5000
|
+
* @param rest - the segments after the anchored one, in bar order.
|
|
5001
|
+
* @param held - index of the selected segment within them; negative while the
|
|
5002
|
+
* anchor itself is selected, which draws no selection here.
|
|
5003
|
+
* @param palette - the palette the labels and marks are styled with.
|
|
5004
|
+
* @param room - columns left after the anchor.
|
|
5005
|
+
* @param level - how far above its settled drawing the selected label is lifted.
|
|
5006
|
+
* @returns the window, opening with its connector, or the empty string when
|
|
5007
|
+
* the bar draws nothing but its anchor.
|
|
5008
|
+
*/
|
|
5009
|
+
function focusedWindow(rest, held, palette, room, level) {
|
|
5010
|
+
if (rest.length === 0) return "";
|
|
5011
|
+
const sep = palette.dim(SEPARATOR$1);
|
|
5012
|
+
const sepWidth = visibleWidth(SEPARATOR$1);
|
|
5013
|
+
const selected = Math.max(0, held);
|
|
5014
|
+
const budget = room - sepWidth;
|
|
5015
|
+
const cap = budget - (selected < rest.length - 1 ? WINDOW_MARK_WIDTH : 0);
|
|
5016
|
+
const styled = rest.map((segment, index) => segmentLabel(index === held ? fitSelected(segment.label, cap) : segment.label, index === held, palette, level));
|
|
5017
|
+
const widths = styled.map(visibleWidth);
|
|
5018
|
+
const last = rest.length - 1;
|
|
5019
|
+
const opened = windowSpan(widths, selected, budget, sepWidth);
|
|
5020
|
+
const span = opened.end < last ? windowSpan(widths, selected, budget - WINDOW_MARK_WIDTH, sepWidth) : opened;
|
|
5021
|
+
const lead = span.start > 0 ? palette.dim(` ${WINDOW_START} `) : sep;
|
|
5022
|
+
const trail = span.end < last ? palette.dim(` ${WINDOW_END}`) : "";
|
|
5023
|
+
return `${lead}${styled.slice(span.start, span.end + 1).join(sep)}${trail}`;
|
|
5024
|
+
}
|
|
5025
|
+
/**
|
|
5026
|
+
* The focused bar: the anchored model label, a sliding window of the segments
|
|
5027
|
+
* after it, then the expansion line.
|
|
3976
5028
|
* @param segments - the segments in bar order.
|
|
3977
5029
|
* @param selected - index of the held segment.
|
|
3978
5030
|
* @param palette - the palette the labels and hints are styled with.
|
|
3979
5031
|
* @param width - terminal columns each line must fit.
|
|
3980
|
-
* @
|
|
5032
|
+
* @param level - how far above its settled drawing the selected label is lifted.
|
|
5033
|
+
* @returns two lines, the anchor and the selected label always in the first.
|
|
3981
5034
|
*/
|
|
3982
|
-
function focusedLines(segments, selected, palette, width) {
|
|
5035
|
+
function focusedLines(segments, selected, palette, width, level) {
|
|
3983
5036
|
const held = Math.min(Math.max(0, selected), Math.max(0, segments.length - 1));
|
|
3984
|
-
const
|
|
3985
|
-
const
|
|
3986
|
-
|
|
3987
|
-
return [fitLine(styled.slice(start, end + 1).join(sep), width), expansionLine(segments[held], palette, width)];
|
|
5037
|
+
const [anchor, ...rest] = segments;
|
|
5038
|
+
const model = anchor === void 0 ? "" : segmentLabel(anchorLabel(anchor), held === 0, palette, level);
|
|
5039
|
+
return [fitLine(`${model}${focusedWindow(rest, held - 1, palette, width - visibleWidth(model), level)}`, width), expansionLine(segments[held], palette, width)];
|
|
3988
5040
|
}
|
|
3989
5041
|
/**
|
|
3990
|
-
* Render the footer. Unfocused it is one dim line
|
|
3991
|
-
*
|
|
3992
|
-
*
|
|
3993
|
-
*
|
|
5042
|
+
* Render the footer. Unfocused it is one dim line built from both ends: the
|
|
5043
|
+
* model anchored left, the entry keys anchored right, and the key facts in
|
|
5044
|
+
* between. Focused it is the anchored model, the navigable segments (windowed
|
|
5045
|
+
* to `width` so the selected one is never dropped) and an expansion of that
|
|
5046
|
+
* segment plus the navigation keys. Every returned line fits `width`.
|
|
3994
5047
|
* @param segments - the segments in bar order.
|
|
3995
5048
|
* @param render - the palette, optional selected index, and terminal width.
|
|
3996
5049
|
* @returns the footer lines, one when unfocused and two when focused.
|
|
@@ -3998,7 +5051,7 @@ function focusedLines(segments, selected, palette, width) {
|
|
|
3998
5051
|
function renderFooter(segments, render) {
|
|
3999
5052
|
const width = Math.max(1, render.width);
|
|
4000
5053
|
if (render.selected === void 0) return [unfocusedLine(segments, render.palette, width)];
|
|
4001
|
-
return focusedLines(segments, render.selected, render.palette, width);
|
|
5054
|
+
return focusedLines(segments, render.selected, render.palette, width, render.level ?? 0);
|
|
4002
5055
|
}
|
|
4003
5056
|
/**
|
|
4004
5057
|
* The status bar as a mounted component. The view is read once per render
|
|
@@ -4182,18 +5235,6 @@ var ApprovalPrompt = class extends ListPrompt {
|
|
|
4182
5235
|
const CURRENT_MARK = " ✓";
|
|
4183
5236
|
/** What the filter line says while the query is empty. */
|
|
4184
5237
|
const FILTER_HINT = "type to filter · Enter selects · Esc cancels";
|
|
4185
|
-
/** Characters a typed query never carries: C0 controls, DEL, and C1 controls. */
|
|
4186
|
-
const CONTROL_CHARACTERS = /[\u0000-\u001f\u007f-\u009f]/u;
|
|
4187
|
-
/**
|
|
4188
|
-
* The text one key press types.
|
|
4189
|
-
* @param data - the bytes the terminal sent.
|
|
4190
|
-
* @returns the characters to append to a query, or undefined for control keys and escape sequences.
|
|
4191
|
-
*/
|
|
4192
|
-
function typedText(data) {
|
|
4193
|
-
const kitty = decodeKittyPrintable(data);
|
|
4194
|
-
if (kitty !== void 0) return kitty;
|
|
4195
|
-
return CONTROL_CHARACTERS.test(data) ? void 0 : data;
|
|
4196
|
-
}
|
|
4197
5238
|
/**
|
|
4198
5239
|
* The text a picker row is matched against.
|
|
4199
5240
|
* @param row - the row.
|
|
@@ -4558,6 +5599,1029 @@ var ModalQueue = class {
|
|
|
4558
5599
|
this.active?.withdraw();
|
|
4559
5600
|
}
|
|
4560
5601
|
};
|
|
5602
|
+
/** Below this width the body draws one column at a time: the rail, or the sections it opens. */
|
|
5603
|
+
const TWO_COLUMN_MIN_WIDTH = 60;
|
|
5604
|
+
/** Columns a pane needs before it is worth drawing beside another one. */
|
|
5605
|
+
const READER_MIN_PANE = 24;
|
|
5606
|
+
/** Narrowest turn rail. */
|
|
5607
|
+
const RAIL_MIN_WIDTH = 18;
|
|
5608
|
+
/** Widest turn rail. */
|
|
5609
|
+
const RAIL_MAX_WIDTH = 30;
|
|
5610
|
+
/** Share of the terminal the turn rail asks for between its two bounds. */
|
|
5611
|
+
const RAIL_SHARE = .28;
|
|
5612
|
+
/** Rows the frame itself takes: the top rule, the legend rule, and the bottom rule. */
|
|
5613
|
+
const CHROME_ROWS = 3;
|
|
5614
|
+
/** Columns one body column spends on the border before it and the space after it. */
|
|
5615
|
+
const COLUMN_MARGIN = 2;
|
|
5616
|
+
/** Columns a pane row spends on its left edge, which the held section accents. */
|
|
5617
|
+
const EDGE_WIDTH = 1;
|
|
5618
|
+
/** What the chip names this mode. */
|
|
5619
|
+
const READER_CHIP = "READER";
|
|
5620
|
+
/** What ends a line the width cut short; one column, so the mark itself fits. */
|
|
5621
|
+
const ELLIPSIS$1 = "…";
|
|
5622
|
+
/** The left border of a body row and the border between two body columns. */
|
|
5623
|
+
const SIDE = "│";
|
|
5624
|
+
/** Marks the rail row the keyboard holds. */
|
|
5625
|
+
const RAIL_MARK = "▸ ";
|
|
5626
|
+
/** The left edge every row of the held section carries. */
|
|
5627
|
+
const HELD_EDGE = "▌";
|
|
5628
|
+
/** What a section header opens with before its label. */
|
|
5629
|
+
const HEADER_LEAD = "──";
|
|
5630
|
+
/** What a section header fills the rest of its pane with. */
|
|
5631
|
+
const HEADER_FILL = "─";
|
|
5632
|
+
/** What the reader says on a terminal it cannot draw its frame in. */
|
|
5633
|
+
const TOO_SMALL = `terminal too small for the reader (needs ${String(24)}×${String(8)})`;
|
|
5634
|
+
/**
|
|
5635
|
+
* The legend of each keyboard owner inside the reader, in declared
|
|
5636
|
+
* degradation steps, widest first: the turn rail, and the sections of the
|
|
5637
|
+
* held turn. The query line borrows the rail's half of the legend rule, so it
|
|
5638
|
+
* declares none of its own. `/help` lists the widest step of each, so the
|
|
5639
|
+
* reader's keys are named in one place.
|
|
5640
|
+
*/
|
|
5641
|
+
const READER_HINTS = {
|
|
5642
|
+
rail: [
|
|
5643
|
+
"↑↓ turns · → sections · Enter opens · / filters · Esc closes",
|
|
5644
|
+
"↑↓ turns · → sections · Esc closes",
|
|
5645
|
+
"Esc closes"
|
|
5646
|
+
],
|
|
5647
|
+
pane: [
|
|
5648
|
+
"↑↓ sections · ⇧↑↓ scroll · PgUp PgDn page · Enter pins · Esc back",
|
|
5649
|
+
"↑↓ sections · Enter pins · Esc back",
|
|
5650
|
+
"Esc back"
|
|
5651
|
+
]
|
|
5652
|
+
};
|
|
5653
|
+
/** A pane with nothing in it, for a reader with no turn to show. */
|
|
5654
|
+
const EMPTY_MEASURE = {
|
|
5655
|
+
headers: [],
|
|
5656
|
+
total: 0
|
|
5657
|
+
};
|
|
5658
|
+
/**
|
|
5659
|
+
* Hold one index inside a list.
|
|
5660
|
+
* @param value - the wanted index.
|
|
5661
|
+
* @param min - the lowest allowed value.
|
|
5662
|
+
* @param max - the highest allowed value.
|
|
5663
|
+
* @returns the value, moved to the nearest bound when it falls outside.
|
|
5664
|
+
*/
|
|
5665
|
+
function clamp(value, min, max) {
|
|
5666
|
+
return Math.max(min, Math.min(value, max));
|
|
5667
|
+
}
|
|
5668
|
+
/**
|
|
5669
|
+
* Whether two cursors name the same section.
|
|
5670
|
+
* @param left - one cursor.
|
|
5671
|
+
* @param right - the other.
|
|
5672
|
+
* @returns true when both name the same block and part.
|
|
5673
|
+
*/
|
|
5674
|
+
function sameCursor(left, right) {
|
|
5675
|
+
return left.block === right.block && left.part === right.part;
|
|
5676
|
+
}
|
|
5677
|
+
/**
|
|
5678
|
+
* Which turn the reader holds.
|
|
5679
|
+
* @param state - where the reader is.
|
|
5680
|
+
* @param groups - the turns the rail lists.
|
|
5681
|
+
* @returns the index into `groups`, and 0 when no listed turn holds the cursor.
|
|
5682
|
+
*/
|
|
5683
|
+
function groupIndex(state, groups) {
|
|
5684
|
+
const index = turnIndexOf(state.cursor, groups);
|
|
5685
|
+
return index === -1 ? 0 : index;
|
|
5686
|
+
}
|
|
5687
|
+
/**
|
|
5688
|
+
* Which section of its turn the reader holds.
|
|
5689
|
+
* @param state - where the reader is.
|
|
5690
|
+
* @param group - the turn that holds the cursor.
|
|
5691
|
+
* @returns the index into the turn's sections, and 0 when the turn no longer carries it.
|
|
5692
|
+
*/
|
|
5693
|
+
function sectionIndex(state, group) {
|
|
5694
|
+
const index = group.sections.findIndex((section) => sameCursor(section, state.cursor));
|
|
5695
|
+
return index === -1 ? 0 : index;
|
|
5696
|
+
}
|
|
5697
|
+
/**
|
|
5698
|
+
* The block and part one cursor names.
|
|
5699
|
+
* @param cursor - the section.
|
|
5700
|
+
* @param blocks - the navigable blocks.
|
|
5701
|
+
* @returns both, or undefined when the cursor points past the transcript.
|
|
5702
|
+
*/
|
|
5703
|
+
function sectionAt(cursor, blocks) {
|
|
5704
|
+
const block = blocks[cursor.block];
|
|
5705
|
+
const part = block?.parts()[cursor.part];
|
|
5706
|
+
if (block === void 0 || part === void 0) return void 0;
|
|
5707
|
+
return {
|
|
5708
|
+
block,
|
|
5709
|
+
part
|
|
5710
|
+
};
|
|
5711
|
+
}
|
|
5712
|
+
/**
|
|
5713
|
+
* What one section is called in the pane, with the glyph that says what kind
|
|
5714
|
+
* of thing it is at a glance.
|
|
5715
|
+
* @param block - the block the section belongs to.
|
|
5716
|
+
* @param part - the section.
|
|
5717
|
+
* @returns the label, e.g. `✻ reasoning` or `⚒ bash git status · result`.
|
|
5718
|
+
*/
|
|
5719
|
+
function paneLabel(block, part) {
|
|
5720
|
+
const label = sectionLabel(block, part);
|
|
5721
|
+
switch (block.blockKind) {
|
|
5722
|
+
case "context": return `⬡ ${label}`;
|
|
5723
|
+
case "tool": return `⚒ ${label}`;
|
|
5724
|
+
case "user": return label;
|
|
5725
|
+
case "assistant": return part.kind === "reasoning" ? `✻ ${label}` : `¶ ${label}`;
|
|
5726
|
+
/* v8 ignore next 2 -- closed-union exhaustiveness guard */
|
|
5727
|
+
default: return assertNever(block, "tui reader block kind");
|
|
5728
|
+
}
|
|
5729
|
+
}
|
|
5730
|
+
/**
|
|
5731
|
+
* One section's rows as the pane wraps them; never folded, because folding is
|
|
5732
|
+
* a decision the transcript makes and this is where the rest of the text is.
|
|
5733
|
+
* @param cursor - the section.
|
|
5734
|
+
* @param blocks - the navigable blocks.
|
|
5735
|
+
* @param width - the pane's columns.
|
|
5736
|
+
* @returns the wrapped rows, unstyled.
|
|
5737
|
+
*/
|
|
5738
|
+
function sectionBody(cursor, blocks, width) {
|
|
5739
|
+
const held = sectionAt(cursor, blocks);
|
|
5740
|
+
if (held === void 0) return [];
|
|
5741
|
+
const room = Math.max(1, width - EDGE_WIDTH);
|
|
5742
|
+
return held.part.rows.flatMap((row) => wrapTextWithAnsi(row, room));
|
|
5743
|
+
}
|
|
5744
|
+
/**
|
|
5745
|
+
* Measure the walking pane, which is what the scroll keys move over.
|
|
5746
|
+
* @param group - the turn the pane shows.
|
|
5747
|
+
* @param blocks - the navigable blocks.
|
|
5748
|
+
* @param width - the pane's columns.
|
|
5749
|
+
* @returns where each section's header lands and how many rows the pane has.
|
|
5750
|
+
*/
|
|
5751
|
+
function measurePane(group, blocks, width) {
|
|
5752
|
+
const headers = [];
|
|
5753
|
+
let total = 0;
|
|
5754
|
+
for (const cursor of group.sections) {
|
|
5755
|
+
headers.push(total);
|
|
5756
|
+
total += 1 + sectionBody(cursor, blocks, width).length;
|
|
5757
|
+
}
|
|
5758
|
+
return {
|
|
5759
|
+
headers,
|
|
5760
|
+
total
|
|
5761
|
+
};
|
|
5762
|
+
}
|
|
5763
|
+
/**
|
|
5764
|
+
* What the legend says about a pin the terminal cannot draw beside the walk.
|
|
5765
|
+
*
|
|
5766
|
+
* Compare needs a body that splits in two at all as well as the configured
|
|
5767
|
+
* width, so the line names whichever of the two is larger.
|
|
5768
|
+
* @param minColumns - columns compare needs before the body splits in two.
|
|
5769
|
+
* @returns the refusal.
|
|
5770
|
+
*/
|
|
5771
|
+
function compareRefusal(minColumns) {
|
|
5772
|
+
return `compare needs ${String(Math.max(minColumns, TWO_COLUMN_MIN_WIDTH))} columns`;
|
|
5773
|
+
}
|
|
5774
|
+
/**
|
|
5775
|
+
* How the reader's body splits one terminal.
|
|
5776
|
+
*
|
|
5777
|
+
* The rail is what gives way: compare keeps its two panes wherever both still
|
|
5778
|
+
* hold a readable section, and a terminal too narrow for two columns draws
|
|
5779
|
+
* whichever one the keyboard is in.
|
|
5780
|
+
* @param width - the terminal's columns.
|
|
5781
|
+
* @param rows - the rows the reader draws.
|
|
5782
|
+
* @param state - where the reader is, which decides the single narrow column and whether compare is on.
|
|
5783
|
+
* @param minColumns - columns compare needs before the body splits in two.
|
|
5784
|
+
* @param pane - the walking pane's measured rows, which the geometry carries for the key model.
|
|
5785
|
+
* @returns the rail width, the pane widths in drawing order, the body rows,
|
|
5786
|
+
* and the refusal the legend reports.
|
|
5787
|
+
*/
|
|
5788
|
+
function readerGeometry(width, rows, state, minColumns, pane) {
|
|
5789
|
+
const base = {
|
|
5790
|
+
body: Math.max(0, rows - CHROME_ROWS),
|
|
5791
|
+
refusal: "",
|
|
5792
|
+
tiny: false,
|
|
5793
|
+
pane
|
|
5794
|
+
};
|
|
5795
|
+
if (width < 24 || rows < 8) return {
|
|
5796
|
+
...base,
|
|
5797
|
+
rail: 0,
|
|
5798
|
+
panes: [],
|
|
5799
|
+
tiny: true
|
|
5800
|
+
};
|
|
5801
|
+
const refusal = state.pinned === void 0 ? "" : compareRefusal(minColumns);
|
|
5802
|
+
if (width < TWO_COLUMN_MIN_WIDTH) return state.column === "pane" ? {
|
|
5803
|
+
...base,
|
|
5804
|
+
refusal,
|
|
5805
|
+
rail: 0,
|
|
5806
|
+
panes: [width - COLUMN_MARGIN]
|
|
5807
|
+
} : {
|
|
5808
|
+
...base,
|
|
5809
|
+
refusal,
|
|
5810
|
+
rail: width - COLUMN_MARGIN,
|
|
5811
|
+
panes: []
|
|
5812
|
+
};
|
|
5813
|
+
const rail = clamp(Math.floor(width * RAIL_SHARE), RAIL_MIN_WIDTH, RAIL_MAX_WIDTH);
|
|
5814
|
+
const single = width - rail - 2 * COLUMN_MARGIN;
|
|
5815
|
+
if (state.pinned === void 0) return {
|
|
5816
|
+
...base,
|
|
5817
|
+
rail,
|
|
5818
|
+
panes: [single]
|
|
5819
|
+
};
|
|
5820
|
+
if (width < minColumns) return {
|
|
5821
|
+
...base,
|
|
5822
|
+
rail,
|
|
5823
|
+
panes: [single],
|
|
5824
|
+
refusal
|
|
5825
|
+
};
|
|
5826
|
+
const shared = Math.floor((width - rail - 3 * COLUMN_MARGIN) / 2);
|
|
5827
|
+
if (shared >= READER_MIN_PANE) return {
|
|
5828
|
+
...base,
|
|
5829
|
+
rail,
|
|
5830
|
+
panes: [shared, shared]
|
|
5831
|
+
};
|
|
5832
|
+
const wide = Math.floor((width - 2 * COLUMN_MARGIN) / 2);
|
|
5833
|
+
return {
|
|
5834
|
+
...base,
|
|
5835
|
+
rail: 0,
|
|
5836
|
+
panes: [wide, wide]
|
|
5837
|
+
};
|
|
5838
|
+
}
|
|
5839
|
+
/**
|
|
5840
|
+
* The reader's geometry over the transcript it is showing, with the walking
|
|
5841
|
+
* pane measured at the width that geometry gives it.
|
|
5842
|
+
* @param state - where the reader is.
|
|
5843
|
+
* @param groups - the turns the rail lists.
|
|
5844
|
+
* @param blocks - the navigable blocks.
|
|
5845
|
+
* @param width - the terminal's columns.
|
|
5846
|
+
* @param rows - the rows the reader draws.
|
|
5847
|
+
* @param minColumns - columns compare needs before the body splits in two.
|
|
5848
|
+
* @returns the geometry, with its pane measure filled in.
|
|
5849
|
+
*/
|
|
5850
|
+
function readerGeometryFor(state, groups, blocks, width, rows, minColumns) {
|
|
5851
|
+
const layout = readerGeometry(width, rows, state, minColumns, EMPTY_MEASURE);
|
|
5852
|
+
const group = groups[groupIndex(state, groups)];
|
|
5853
|
+
const paneWidth = layout.panes.at(-1);
|
|
5854
|
+
if (group === void 0 || paneWidth === void 0) return layout;
|
|
5855
|
+
return {
|
|
5856
|
+
...layout,
|
|
5857
|
+
pane: measurePane(group, blocks, paneWidth)
|
|
5858
|
+
};
|
|
5859
|
+
}
|
|
5860
|
+
/**
|
|
5861
|
+
* The largest first visible pane row; 0 while the pane fits at once.
|
|
5862
|
+
* @param geometry - the reader's geometry.
|
|
5863
|
+
* @returns the row the scroll stops at.
|
|
5864
|
+
*/
|
|
5865
|
+
function maxOffset(geometry) {
|
|
5866
|
+
return Math.max(0, geometry.pane.total - geometry.body);
|
|
5867
|
+
}
|
|
5868
|
+
/**
|
|
5869
|
+
* Where the pane scrolls to put one section's header on its first row.
|
|
5870
|
+
* @param index - the section, by position in its turn.
|
|
5871
|
+
* @param geometry - the reader's geometry.
|
|
5872
|
+
* @returns the offset.
|
|
5873
|
+
*/
|
|
5874
|
+
function showSection(index, geometry) {
|
|
5875
|
+
return Math.min(geometry.pane.headers[index] ?? 0, maxOffset(geometry));
|
|
5876
|
+
}
|
|
5877
|
+
/**
|
|
5878
|
+
* Where one movement target lands along a list.
|
|
5879
|
+
* @param to - which way the key steps.
|
|
5880
|
+
* @param index - where the selection sits now.
|
|
5881
|
+
* @param count - how many entries the list has; at least 1.
|
|
5882
|
+
* @returns the index to select.
|
|
5883
|
+
*/
|
|
5884
|
+
function targetIndex(to, index, count) {
|
|
5885
|
+
switch (to) {
|
|
5886
|
+
case "previous": return clamp(index - 1, 0, count - 1);
|
|
5887
|
+
case "next": return clamp(index + 1, 0, count - 1);
|
|
5888
|
+
case "first": return 0;
|
|
5889
|
+
case "last": return count - 1;
|
|
5890
|
+
/* v8 ignore next 2 -- closed-union exhaustiveness guard */
|
|
5891
|
+
default: return assertNever(to, "tui reader move target");
|
|
5892
|
+
}
|
|
5893
|
+
}
|
|
5894
|
+
/**
|
|
5895
|
+
* The state without its pinned section.
|
|
5896
|
+
* @param state - where the reader is.
|
|
5897
|
+
* @returns the same state with compare off.
|
|
5898
|
+
*/
|
|
5899
|
+
function withoutPin(state) {
|
|
5900
|
+
return {
|
|
5901
|
+
cursor: state.cursor,
|
|
5902
|
+
column: state.column,
|
|
5903
|
+
offset: state.offset,
|
|
5904
|
+
...state.query === void 0 ? {} : { query: state.query }
|
|
5905
|
+
};
|
|
5906
|
+
}
|
|
5907
|
+
/**
|
|
5908
|
+
* The state without its query.
|
|
5909
|
+
* @param state - where the reader is.
|
|
5910
|
+
* @returns the same state with the rail listing every turn again.
|
|
5911
|
+
*/
|
|
5912
|
+
function withoutQuery(state) {
|
|
5913
|
+
return {
|
|
5914
|
+
cursor: state.cursor,
|
|
5915
|
+
column: state.column,
|
|
5916
|
+
offset: state.offset,
|
|
5917
|
+
...state.pinned === void 0 ? {} : { pinned: state.pinned }
|
|
5918
|
+
};
|
|
5919
|
+
}
|
|
5920
|
+
/**
|
|
5921
|
+
* Put the reader on one section of the turn it holds.
|
|
5922
|
+
* @param state - where the reader is.
|
|
5923
|
+
* @param index - the section, by position in its turn.
|
|
5924
|
+
* @param groups - the turns the rail lists.
|
|
5925
|
+
* @param geometry - the reader's geometry.
|
|
5926
|
+
* @returns the state on that section, scrolled to it.
|
|
5927
|
+
*/
|
|
5928
|
+
function selectSection(state, index, groups, geometry) {
|
|
5929
|
+
const group = groups[groupIndex(state, groups)];
|
|
5930
|
+
if (group === void 0) return state;
|
|
5931
|
+
const at = clamp(index, 0, group.sections.length - 1);
|
|
5932
|
+
const cursor = group.sections[at];
|
|
5933
|
+
/* v8 ignore next -- a listed turn carries at least one section */
|
|
5934
|
+
if (cursor === void 0) return state;
|
|
5935
|
+
return {
|
|
5936
|
+
...state,
|
|
5937
|
+
column: "pane",
|
|
5938
|
+
cursor,
|
|
5939
|
+
offset: showSection(at, geometry)
|
|
5940
|
+
};
|
|
5941
|
+
}
|
|
5942
|
+
/**
|
|
5943
|
+
* Put the reader on one turn, at its first section.
|
|
5944
|
+
* @param state - where the reader is.
|
|
5945
|
+
* @param index - the turn, by position in the listed turns.
|
|
5946
|
+
* @param groups - the turns the rail lists.
|
|
5947
|
+
* @returns the state on that turn, scrolled to its top.
|
|
5948
|
+
*/
|
|
5949
|
+
function selectTurn(state, index, groups) {
|
|
5950
|
+
const cursor = cursorAt(groups, index, 0);
|
|
5951
|
+
/* v8 ignore next -- both callers refuse an empty rail first */
|
|
5952
|
+
if (cursor === void 0) return state;
|
|
5953
|
+
return {
|
|
5954
|
+
...state,
|
|
5955
|
+
cursor,
|
|
5956
|
+
offset: 0
|
|
5957
|
+
};
|
|
5958
|
+
}
|
|
5959
|
+
/**
|
|
5960
|
+
* Answer one page key: a page of the pane's rows with one row of overlap, or
|
|
5961
|
+
* a rail's worth of turns.
|
|
5962
|
+
* @param state - where the reader is.
|
|
5963
|
+
* @param step - 1 for the next page, -1 for the previous one.
|
|
5964
|
+
* @param groups - the turns the rail lists.
|
|
5965
|
+
* @param geometry - the reader's geometry.
|
|
5966
|
+
* @returns the state after the page.
|
|
5967
|
+
*/
|
|
5968
|
+
function pageBy(state, step, groups, geometry) {
|
|
5969
|
+
if (state.column === "pane") {
|
|
5970
|
+
const by = Math.max(1, geometry.body - 1);
|
|
5971
|
+
return {
|
|
5972
|
+
...state,
|
|
5973
|
+
offset: clamp(state.offset + step * by, 0, maxOffset(geometry))
|
|
5974
|
+
};
|
|
5975
|
+
}
|
|
5976
|
+
if (groups.length === 0) return state;
|
|
5977
|
+
return selectTurn(state, clamp(groupIndex(state, groups) + step * Math.max(1, geometry.body), 0, groups.length - 1), groups);
|
|
5978
|
+
}
|
|
5979
|
+
/**
|
|
5980
|
+
* Whether the body draws one of its columns at a time, which is what a
|
|
5981
|
+
* terminal too narrow to hold the rail beside a pane does.
|
|
5982
|
+
* @param geometry - the reader's geometry.
|
|
5983
|
+
* @returns true while the rail and the sections take turns at the body.
|
|
5984
|
+
*/
|
|
5985
|
+
function singleColumn(geometry) {
|
|
5986
|
+
return geometry.rail === 0 && geometry.panes.length === 1;
|
|
5987
|
+
}
|
|
5988
|
+
/**
|
|
5989
|
+
* Answer `Escape` inside the reader: clear the query, close the query line,
|
|
5990
|
+
* unpin, then - on a terminal that draws one column at a time - step back to
|
|
5991
|
+
* the rail. {@link readerClosesOnEscape} reports when the chain is spent and
|
|
5992
|
+
* the press closes the reader instead.
|
|
5993
|
+
* @param state - where the reader is.
|
|
5994
|
+
* @returns the state after one step of the chain.
|
|
5995
|
+
*/
|
|
5996
|
+
function escapeStep(state) {
|
|
5997
|
+
if (state.column === "filter") {
|
|
5998
|
+
if (state.query !== void 0 && state.query !== "") return {
|
|
5999
|
+
...state,
|
|
6000
|
+
query: ""
|
|
6001
|
+
};
|
|
6002
|
+
return withoutQuery({
|
|
6003
|
+
...state,
|
|
6004
|
+
column: "rail"
|
|
6005
|
+
});
|
|
6006
|
+
}
|
|
6007
|
+
if (state.pinned !== void 0) return withoutPin(state);
|
|
6008
|
+
return {
|
|
6009
|
+
...state,
|
|
6010
|
+
column: "rail"
|
|
6011
|
+
};
|
|
6012
|
+
}
|
|
6013
|
+
/**
|
|
6014
|
+
* Whether `Escape` closes the reader rather than stepping its own chain.
|
|
6015
|
+
* @param state - where the reader is.
|
|
6016
|
+
* @param geometry - the reader's geometry, which decides whether the sections
|
|
6017
|
+
* still have a rail of their own to step back to.
|
|
6018
|
+
* @returns true once no query line is open, nothing is pinned, and the
|
|
6019
|
+
* keyboard is not in a narrow terminal's sections.
|
|
6020
|
+
*/
|
|
6021
|
+
function readerClosesOnEscape(state, geometry) {
|
|
6022
|
+
if (state.column === "filter" || state.pinned !== void 0) return false;
|
|
6023
|
+
return !(state.column === "pane" && singleColumn(geometry));
|
|
6024
|
+
}
|
|
6025
|
+
/**
|
|
6026
|
+
* Apply one key press to the reader.
|
|
6027
|
+
* @param state - where the reader is.
|
|
6028
|
+
* @param intent - what the key meant.
|
|
6029
|
+
* @param groups - the turns the rail lists, already narrowed by the query.
|
|
6030
|
+
* @param geometry - the reader's geometry, with the walking pane measured.
|
|
6031
|
+
* @returns the state after the press; the state itself when nothing moves.
|
|
6032
|
+
*/
|
|
6033
|
+
function reduceReader(state, intent, groups, geometry) {
|
|
6034
|
+
switch (intent.kind) {
|
|
6035
|
+
case "turn": return groups.length === 0 ? state : selectTurn(state, targetIndex(intent.to, groupIndex(state, groups), groups.length), groups);
|
|
6036
|
+
case "section": {
|
|
6037
|
+
const group = groups[groupIndex(state, groups)];
|
|
6038
|
+
if (group === void 0) return state;
|
|
6039
|
+
return selectSection(state, targetIndex(intent.to, sectionIndex(state, group), group.sections.length), groups, geometry);
|
|
6040
|
+
}
|
|
6041
|
+
case "section-at": return selectSection(state, intent.index, groups, geometry);
|
|
6042
|
+
case "scroll": return {
|
|
6043
|
+
...state,
|
|
6044
|
+
offset: clamp(state.offset + intent.step, 0, maxOffset(geometry))
|
|
6045
|
+
};
|
|
6046
|
+
case "page": return pageBy(state, intent.step, groups, geometry);
|
|
6047
|
+
case "column": return intent.to === "rail" ? {
|
|
6048
|
+
...state,
|
|
6049
|
+
column: "rail"
|
|
6050
|
+
} : selectSection(state, 0, groups, geometry);
|
|
6051
|
+
case "pin": return state.pinned !== void 0 && sameCursor(state.pinned, state.cursor) ? withoutPin(state) : {
|
|
6052
|
+
...state,
|
|
6053
|
+
pinned: state.cursor
|
|
6054
|
+
};
|
|
6055
|
+
case "filter": return {
|
|
6056
|
+
...state,
|
|
6057
|
+
column: "filter",
|
|
6058
|
+
query: state.query ?? ""
|
|
6059
|
+
};
|
|
6060
|
+
case "query": return {
|
|
6061
|
+
...state,
|
|
6062
|
+
query: `${state.query ?? ""}${intent.text}`
|
|
6063
|
+
};
|
|
6064
|
+
case "erase": return {
|
|
6065
|
+
...state,
|
|
6066
|
+
query: intent.all ? "" : (state.query ?? "").slice(0, -1)
|
|
6067
|
+
};
|
|
6068
|
+
case "commit": return {
|
|
6069
|
+
...state,
|
|
6070
|
+
column: "rail"
|
|
6071
|
+
};
|
|
6072
|
+
case "escape": return escapeStep(state);
|
|
6073
|
+
case "anchor": return anchorOffset(state, groups, geometry);
|
|
6074
|
+
/* v8 ignore next 2 -- closed-union exhaustiveness guard */
|
|
6075
|
+
default: return assertNever(intent, "tui reader intent");
|
|
6076
|
+
}
|
|
6077
|
+
}
|
|
6078
|
+
/**
|
|
6079
|
+
* Put the held section back in view after a resize rewrapped the pane under
|
|
6080
|
+
* it: the reader re-anchors on the section itself, never on a row number, so
|
|
6081
|
+
* a narrower terminal does not lose the user's place.
|
|
6082
|
+
* @param state - where the reader is.
|
|
6083
|
+
* @param groups - the turns the rail lists.
|
|
6084
|
+
* @param geometry - the reader's geometry after the change.
|
|
6085
|
+
* @returns the state with its offset settled.
|
|
6086
|
+
*/
|
|
6087
|
+
function anchorOffset(state, groups, geometry) {
|
|
6088
|
+
const group = groups[groupIndex(state, groups)];
|
|
6089
|
+
if (group === void 0) return state;
|
|
6090
|
+
const index = sectionIndex(state, group);
|
|
6091
|
+
const header = geometry.pane.headers[index] ?? 0;
|
|
6092
|
+
const top = clamp(state.offset, 0, maxOffset(geometry));
|
|
6093
|
+
const visible = header >= top && header < top + geometry.body;
|
|
6094
|
+
return {
|
|
6095
|
+
...state,
|
|
6096
|
+
offset: visible ? top : showSection(index, geometry)
|
|
6097
|
+
};
|
|
6098
|
+
}
|
|
6099
|
+
/**
|
|
6100
|
+
* Narrow the turns to the ones a query matches, keeping the conversation's
|
|
6101
|
+
* own order: the rail is a timeline, so it is filtered rather than ranked.
|
|
6102
|
+
* @param groups - every turn of the transcript.
|
|
6103
|
+
* @param blocks - the navigable blocks, for the text inside each turn.
|
|
6104
|
+
* @param query - what the user typed; an empty query keeps every turn.
|
|
6105
|
+
* @returns the turns to list.
|
|
6106
|
+
*/
|
|
6107
|
+
function filterTurns(groups, blocks, query) {
|
|
6108
|
+
if (query === void 0 || query === "") return groups;
|
|
6109
|
+
const text = (group) => [group.label, ...group.sections.map((cursor) => sectionAt(cursor, blocks)?.part.rows.join(" ") ?? "")].join(" ");
|
|
6110
|
+
const matched = new Set(fuzzyFilter([...groups], query, text));
|
|
6111
|
+
return groups.filter((group) => matched.has(group));
|
|
6112
|
+
}
|
|
6113
|
+
/**
|
|
6114
|
+
* What one turn contributed, as the rail reports it at a glance.
|
|
6115
|
+
* @param markers - the turn's counts and flags.
|
|
6116
|
+
* @returns the marker strip, empty for a turn that contributed none of them.
|
|
6117
|
+
*/
|
|
6118
|
+
function markerStrip(markers) {
|
|
6119
|
+
const marks = [];
|
|
6120
|
+
if (markers.context > 0) marks.push(`⬡${String(markers.context)}`);
|
|
6121
|
+
if (markers.reasoning) marks.push("✻");
|
|
6122
|
+
if (markers.reply) marks.push("¶");
|
|
6123
|
+
if (markers.tools > 0) marks.push(`⚒${String(markers.tools)}`);
|
|
6124
|
+
return marks.join("");
|
|
6125
|
+
}
|
|
6126
|
+
/**
|
|
6127
|
+
* Fit one styled text to an exact number of columns.
|
|
6128
|
+
* @param text - the text, already styled.
|
|
6129
|
+
* @param width - the columns the cell takes.
|
|
6130
|
+
* @returns the text cut and padded to exactly `width`.
|
|
6131
|
+
*/
|
|
6132
|
+
function cell(text, width) {
|
|
6133
|
+
const cut = truncateToWidth(text, Math.max(1, width), ELLIPSIS$1);
|
|
6134
|
+
return `${cut}${" ".repeat(Math.max(0, width - visibleWidth(cut)))}`;
|
|
6135
|
+
}
|
|
6136
|
+
/**
|
|
6137
|
+
* One row of the turn rail: the mark, the turn number, its prompt, and what
|
|
6138
|
+
* the turn contributed.
|
|
6139
|
+
* @param group - the turn.
|
|
6140
|
+
* @param selected - whether the keyboard holds it.
|
|
6141
|
+
* @param palette - the palette the row is styled with.
|
|
6142
|
+
* @param width - the rail's columns.
|
|
6143
|
+
* @returns the row, exactly `width` columns.
|
|
6144
|
+
*/
|
|
6145
|
+
function railRow(group, selected, palette, width) {
|
|
6146
|
+
const marks = markerStrip(group.markers);
|
|
6147
|
+
const room = Math.max(1, width - visibleWidth(marks));
|
|
6148
|
+
const lead = `${selected ? RAIL_MARK : " "}${String(group.turn)} `;
|
|
6149
|
+
const label = truncateToWidth(group.label, Math.max(1, room - visibleWidth(lead) - (selected ? 2 : 0)), ELLIPSIS$1);
|
|
6150
|
+
const head = `${lead}${selected ? `[${label}]` : label}`;
|
|
6151
|
+
const text = truncateToWidth(selected ? palette.bold(palette.accent(head)) : palette.dim(head), room, ELLIPSIS$1);
|
|
6152
|
+
return `${text}${" ".repeat(Math.max(0, room - visibleWidth(text)))}${palette.dim(marks)}`;
|
|
6153
|
+
}
|
|
6154
|
+
/**
|
|
6155
|
+
* The turn rail's rows, windowed so the held turn is always drawn.
|
|
6156
|
+
* @param groups - the turns the rail lists.
|
|
6157
|
+
* @param selected - the held turn's index.
|
|
6158
|
+
* @param palette - the palette the rows are styled with.
|
|
6159
|
+
* @param width - the rail's columns.
|
|
6160
|
+
* @param body - the rows the body has.
|
|
6161
|
+
* @returns the rows to draw, oldest first.
|
|
6162
|
+
*/
|
|
6163
|
+
function railColumn(groups, selected, palette, width, body) {
|
|
6164
|
+
const start = clamp(selected - Math.floor(Math.max(0, body - 1) / 2), 0, Math.max(0, groups.length - body));
|
|
6165
|
+
return groups.slice(start, start + body).map((group, index) => railRow(group, start + index === selected, palette, width));
|
|
6166
|
+
}
|
|
6167
|
+
/**
|
|
6168
|
+
* One section header inside a pane.
|
|
6169
|
+
* @param text - what the section is called, with its turn.
|
|
6170
|
+
* @param palette - the palette the header is styled with.
|
|
6171
|
+
* @param width - the pane's columns.
|
|
6172
|
+
* @param held - whether the keyboard holds this section.
|
|
6173
|
+
* @returns the header row.
|
|
6174
|
+
*/
|
|
6175
|
+
function headerRow(text, palette, width, held) {
|
|
6176
|
+
const body = ` ${text} `;
|
|
6177
|
+
const line = `${HEADER_LEAD}${body}${HEADER_FILL.repeat(Math.max(0, width - visibleWidth(HEADER_LEAD) - visibleWidth(body)))}`;
|
|
6178
|
+
return held ? palette.bold(palette.accent(line)) : palette.dim(line);
|
|
6179
|
+
}
|
|
6180
|
+
/**
|
|
6181
|
+
* One section as a pane draws it: its header and every one of its rows.
|
|
6182
|
+
* @param cursor - the section.
|
|
6183
|
+
* @param blocks - the navigable blocks.
|
|
6184
|
+
* @param palette - the palette the header and the edge are styled with.
|
|
6185
|
+
* @param width - the pane's columns.
|
|
6186
|
+
* @param held - whether the keyboard holds this section.
|
|
6187
|
+
* @returns the rows, header first.
|
|
6188
|
+
*/
|
|
6189
|
+
function sectionRows(cursor, blocks, palette, width, held) {
|
|
6190
|
+
const found = sectionAt(cursor, blocks);
|
|
6191
|
+
if (found === void 0) return [];
|
|
6192
|
+
const edge = held ? palette.accent(HELD_EDGE) : " ";
|
|
6193
|
+
return [headerRow(`${paneLabel(found.block, found.part)} · turn ${String(found.block.turn)}`, palette, width, held), ...sectionBody(cursor, blocks, width).map((row) => `${edge}${row}`)];
|
|
6194
|
+
}
|
|
6195
|
+
/**
|
|
6196
|
+
* The walking pane's rows: every section of the held turn, in reading order.
|
|
6197
|
+
* @param group - the turn the pane shows.
|
|
6198
|
+
* @param blocks - the navigable blocks.
|
|
6199
|
+
* @param cursor - the section the keyboard holds.
|
|
6200
|
+
* @param palette - the palette the headers and edges are styled with.
|
|
6201
|
+
* @param width - the pane's columns.
|
|
6202
|
+
* @returns the rows, before the scroll window is applied.
|
|
6203
|
+
*/
|
|
6204
|
+
function paneColumn(group, blocks, cursor, palette, width) {
|
|
6205
|
+
return group.sections.flatMap((section) => sectionRows(section, blocks, palette, width, sameCursor(section, cursor)));
|
|
6206
|
+
}
|
|
6207
|
+
/**
|
|
6208
|
+
* Assemble one body row from the columns that are drawn.
|
|
6209
|
+
* @param columns - the columns in drawing order.
|
|
6210
|
+
* @param row - which of their rows to draw.
|
|
6211
|
+
* @param palette - the palette the borders are styled with.
|
|
6212
|
+
* @param width - the frame's columns.
|
|
6213
|
+
* @returns the row, no wider than `width`.
|
|
6214
|
+
*/
|
|
6215
|
+
function bodyRow(columns, row, palette, width) {
|
|
6216
|
+
const border = palette.accent(SIDE);
|
|
6217
|
+
let line = `${border} `;
|
|
6218
|
+
for (const [index, column] of columns.entries()) {
|
|
6219
|
+
const text = column.rows[row] ?? "";
|
|
6220
|
+
line += index === columns.length - 1 ? truncateToWidth(text, Math.max(1, column.width), ELLIPSIS$1) : `${cell(text, column.width)}${border} `;
|
|
6221
|
+
}
|
|
6222
|
+
return truncateToWidth(line, Math.max(1, width), ELLIPSIS$1);
|
|
6223
|
+
}
|
|
6224
|
+
/**
|
|
6225
|
+
* What the legend rule says on its left: the query line while one is open,
|
|
6226
|
+
* the reason compare is not drawn, or the keys this column answers.
|
|
6227
|
+
* @param state - where the reader is.
|
|
6228
|
+
* @param geometry - the reader's geometry.
|
|
6229
|
+
* @param palette - the palette the text is styled with.
|
|
6230
|
+
* @param room - the columns the rule leaves its legend.
|
|
6231
|
+
* @returns the styled text.
|
|
6232
|
+
*/
|
|
6233
|
+
function legendText(state, geometry, palette, room) {
|
|
6234
|
+
if (state.column === "filter") return palette.accent(truncateToWidth(`/ ${state.query ?? ""}`, Math.max(1, room), ELLIPSIS$1));
|
|
6235
|
+
if (geometry.refusal !== "") return palette.dim(truncateToWidth(geometry.refusal, Math.max(1, room), ELLIPSIS$1));
|
|
6236
|
+
return palette.dim(fitLegend(READER_HINTS[state.column === "rail" ? "rail" : "pane"], room));
|
|
6237
|
+
}
|
|
6238
|
+
/**
|
|
6239
|
+
* Where one entry sits in the list it belongs to, as both the top rule and
|
|
6240
|
+
* the legend readout state it: the 1-based position, and 0 for a list with no
|
|
6241
|
+
* entry to be at. A turn's own number is not its position — the blocks before
|
|
6242
|
+
* the first prompt are a turn of the rail too — so the position is what every
|
|
6243
|
+
* count in the frame is built from.
|
|
6244
|
+
* @param index - the entry's index into the list.
|
|
6245
|
+
* @param count - how many entries the list has.
|
|
6246
|
+
* @returns the position.
|
|
6247
|
+
*/
|
|
6248
|
+
function place(index, count) {
|
|
6249
|
+
return Math.min(index + 1, count);
|
|
6250
|
+
}
|
|
6251
|
+
/**
|
|
6252
|
+
* What the legend rule reports on its right: how far the walk has come, or
|
|
6253
|
+
* how much of the transcript a query still holds.
|
|
6254
|
+
* @param state - where the reader is.
|
|
6255
|
+
* @param groups - the turns the rail lists.
|
|
6256
|
+
* @param geometry - the reader's geometry.
|
|
6257
|
+
* @param totalTurns - the turns the transcript has before the query.
|
|
6258
|
+
* @returns the readout.
|
|
6259
|
+
*/
|
|
6260
|
+
function readout(state, groups, geometry, totalTurns) {
|
|
6261
|
+
if (state.query !== void 0 && state.query !== "") return `${String(groups.length)}/${String(totalTurns)} turns`;
|
|
6262
|
+
const index = groupIndex(state, groups);
|
|
6263
|
+
const group = groups[index];
|
|
6264
|
+
const section = group === void 0 ? 0 : sectionIndex(state, group);
|
|
6265
|
+
const sections = group?.sections.length ?? 0;
|
|
6266
|
+
const rowsShown = Math.min(state.offset + 1, geometry.pane.total);
|
|
6267
|
+
return [
|
|
6268
|
+
`turn ${String(place(index, groups.length))}/${String(groups.length)}`,
|
|
6269
|
+
`section ${String(place(section, sections))}/${String(sections)}`,
|
|
6270
|
+
`row ${String(rowsShown)}/${String(geometry.pane.total)}`
|
|
6271
|
+
].join(" · ");
|
|
6272
|
+
}
|
|
6273
|
+
/**
|
|
6274
|
+
* Draw the reader.
|
|
6275
|
+
* @param state - where the reader is.
|
|
6276
|
+
* @param groups - the turns the rail lists, already narrowed by the query.
|
|
6277
|
+
* @param render - the palette, the blocks, the geometry inputs, and the turn total.
|
|
6278
|
+
* @returns exactly `render.rows` lines, none wider than `render.width`.
|
|
6279
|
+
*/
|
|
6280
|
+
function readerRows(state, groups, render) {
|
|
6281
|
+
const { palette, blocks, width, totalTurns } = render;
|
|
6282
|
+
const rows = Math.max(1, render.rows);
|
|
6283
|
+
const geometry = readerGeometryFor(state, groups, blocks, width, rows, render.minColumns);
|
|
6284
|
+
if (geometry.tiny) {
|
|
6285
|
+
const lines = Array.from({ length: rows }, () => "");
|
|
6286
|
+
lines[0] = truncateToWidth(palette.dim(TOO_SMALL), Math.max(1, width), ELLIPSIS$1);
|
|
6287
|
+
return lines;
|
|
6288
|
+
}
|
|
6289
|
+
const selected = groupIndex(state, groups);
|
|
6290
|
+
const group = groups[selected];
|
|
6291
|
+
const columns = [];
|
|
6292
|
+
if (geometry.rail > 0) columns.push({
|
|
6293
|
+
width: geometry.rail,
|
|
6294
|
+
rows: groups.length === 0 ? [palette.dim(`no turn matches "${state.query ?? ""}"`)] : railColumn(groups, selected, palette, geometry.rail, geometry.body)
|
|
6295
|
+
});
|
|
6296
|
+
const [pinnedWidth, comparedWidth] = geometry.panes;
|
|
6297
|
+
const pinned = state.pinned;
|
|
6298
|
+
if (pinned !== void 0 && comparedWidth !== void 0 && pinnedWidth !== void 0) columns.push({
|
|
6299
|
+
width: pinnedWidth,
|
|
6300
|
+
rows: sectionRows(pinned, blocks, palette, pinnedWidth, false)
|
|
6301
|
+
});
|
|
6302
|
+
const paneWidth = geometry.panes.at(-1);
|
|
6303
|
+
if (paneWidth !== void 0) columns.push({
|
|
6304
|
+
width: paneWidth,
|
|
6305
|
+
rows: group === void 0 ? [] : paneColumn(group, blocks, state.cursor, palette, paneWidth).slice(state.offset)
|
|
6306
|
+
});
|
|
6307
|
+
const body = [];
|
|
6308
|
+
for (let row = 0; row < geometry.body; row += 1) body.push(bodyRow(columns, row, palette, width));
|
|
6309
|
+
const badge = chip(palette, READER_CHIP);
|
|
6310
|
+
const position = `${String(state.cursor.block + 1)}/${String(blocks.length)}`;
|
|
6311
|
+
const report = readout(state, groups, geometry, totalTurns);
|
|
6312
|
+
const legendRoom = ruleRoom(width) - visibleWidth(report) - 1;
|
|
6313
|
+
return [
|
|
6314
|
+
topRule({
|
|
6315
|
+
chip: badge,
|
|
6316
|
+
title: palette.bold(palette.accent(`turn ${String(place(selected, groups.length))} of ${String(groups.length)}`)),
|
|
6317
|
+
right: palette.dim(position),
|
|
6318
|
+
width,
|
|
6319
|
+
palette,
|
|
6320
|
+
tone: "focus"
|
|
6321
|
+
}),
|
|
6322
|
+
...body,
|
|
6323
|
+
legendRule({
|
|
6324
|
+
left: legendText(state, geometry, palette, legendRoom),
|
|
6325
|
+
right: palette.dim(report),
|
|
6326
|
+
width,
|
|
6327
|
+
palette,
|
|
6328
|
+
tone: "focus"
|
|
6329
|
+
}),
|
|
6330
|
+
bottomRule({
|
|
6331
|
+
width,
|
|
6332
|
+
palette,
|
|
6333
|
+
tone: "focus"
|
|
6334
|
+
})
|
|
6335
|
+
];
|
|
6336
|
+
}
|
|
6337
|
+
//#endregion
|
|
6338
|
+
//#region lib/types/reader-overlay.js
|
|
6339
|
+
/**
|
|
6340
|
+
* The reader as a mounted overlay: the component pi-tui composites over the
|
|
6341
|
+
* viewport, and the key map that drives it.
|
|
6342
|
+
*
|
|
6343
|
+
* It costs the frame no rows. pi-tui composites an overlay into the last
|
|
6344
|
+
* terminal-height lines of the frame after the tree rendered, so the
|
|
6345
|
+
* conversation underneath keeps every line it had and the renderer's repaint
|
|
6346
|
+
* boundary is never raised. The application places it against the bottom of
|
|
6347
|
+
* the viewport and tells it how many rows it may draw, which is one fewer for
|
|
6348
|
+
* every viewport line the renderer can no longer repaint; the pane fills
|
|
6349
|
+
* exactly that many.
|
|
6350
|
+
*
|
|
6351
|
+
* Opening and closing are the two moments it moves: the application hands the
|
|
6352
|
+
* pane a reveal it reads per render, and the pane draws that share of its
|
|
6353
|
+
* frame from the bottom rule up, so the reader rises into place and sinks
|
|
6354
|
+
* away without the frame underneath it gaining or losing a line.
|
|
6355
|
+
*
|
|
6356
|
+
* The pane holds no copy of the transcript: it re-reads the blocks and their
|
|
6357
|
+
* turns on every render, so a reply that is still streaming grows inside it,
|
|
6358
|
+
* a tool result that lands appears, and a new turn joins the rail, all with
|
|
6359
|
+
* no push and no second clock.
|
|
6360
|
+
* @module @deepseek-ai/dsh-tui-app/reader-overlay
|
|
6361
|
+
*/
|
|
6362
|
+
/** Which digits select a section of the held turn directly. */
|
|
6363
|
+
const SECTION_DIGIT = /^[1-9]$/u;
|
|
6364
|
+
/** The key that opens the query line. */
|
|
6365
|
+
const FILTER_KEY = "/";
|
|
6366
|
+
/**
|
|
6367
|
+
* The reader pane: it renders exactly the rows it was given, maps every key
|
|
6368
|
+
* to one {@link ReaderIntent}, and settles once when the reader closes.
|
|
6369
|
+
*/
|
|
6370
|
+
var ReaderPane = class {
|
|
6371
|
+
options;
|
|
6372
|
+
/** Where the reader left the keyboard and the walk. */
|
|
6373
|
+
settled;
|
|
6374
|
+
resolve;
|
|
6375
|
+
/** Whether the reader is still open; a second close is ignored. */
|
|
6376
|
+
open = true;
|
|
6377
|
+
state;
|
|
6378
|
+
/** The width the last render laid out at; 0 before the first one. */
|
|
6379
|
+
width = 0;
|
|
6380
|
+
/** The body the last render anchored on, so one rewrap re-anchors exactly once. */
|
|
6381
|
+
layout = "";
|
|
6382
|
+
/**
|
|
6383
|
+
* @param options - the palette, the live transcript reads, and the section to open on.
|
|
6384
|
+
*/
|
|
6385
|
+
constructor(options) {
|
|
6386
|
+
this.options = options;
|
|
6387
|
+
this.settled = new Promise((resolve) => {
|
|
6388
|
+
this.resolve = resolve;
|
|
6389
|
+
});
|
|
6390
|
+
this.state = {
|
|
6391
|
+
cursor: options.cursor,
|
|
6392
|
+
column: "pane",
|
|
6393
|
+
offset: 0
|
|
6394
|
+
};
|
|
6395
|
+
}
|
|
6396
|
+
invalidate() {}
|
|
6397
|
+
/**
|
|
6398
|
+
* Draw the reader at `width`.
|
|
6399
|
+
* @param width - the columns the overlay was laid out at.
|
|
6400
|
+
* @returns as many lines as `rows()` reports, so the overlay covers the
|
|
6401
|
+
* viewport it was placed in - fewer while a reveal is still growing or
|
|
6402
|
+
* shrinking it - and blank lines once the transcript it was reading is
|
|
6403
|
+
* gone.
|
|
6404
|
+
*/
|
|
6405
|
+
render(width) {
|
|
6406
|
+
this.width = width;
|
|
6407
|
+
const rows = Math.max(1, this.options.rows());
|
|
6408
|
+
const blocks = this.options.blocks();
|
|
6409
|
+
const settled = clampCursor(this.state.cursor, blocks) ?? lastSection(blocks);
|
|
6410
|
+
if (settled === void 0) {
|
|
6411
|
+
this.close("editor");
|
|
6412
|
+
return Array.from({ length: rows }, () => "");
|
|
6413
|
+
}
|
|
6414
|
+
this.state = {
|
|
6415
|
+
...this.state,
|
|
6416
|
+
cursor: settled
|
|
6417
|
+
};
|
|
6418
|
+
const groups = turnGroups(blocks);
|
|
6419
|
+
const visible = filterTurns(groups, blocks, this.state.query);
|
|
6420
|
+
const geometry = this.geometryFor(visible, blocks, rows);
|
|
6421
|
+
const layout = `${geometry.panes.join(",")}x${String(geometry.body)}`;
|
|
6422
|
+
if (this.layout !== layout) {
|
|
6423
|
+
this.layout = layout;
|
|
6424
|
+
this.state = reduceReader(this.state, { kind: "anchor" }, visible, geometry);
|
|
6425
|
+
}
|
|
6426
|
+
return readerRows(this.state, visible, {
|
|
6427
|
+
palette: this.options.palette,
|
|
6428
|
+
blocks,
|
|
6429
|
+
width,
|
|
6430
|
+
rows,
|
|
6431
|
+
minColumns: this.options.minColumns,
|
|
6432
|
+
totalTurns: groups.length
|
|
6433
|
+
}).slice(rows - this.drawnRows(rows));
|
|
6434
|
+
}
|
|
6435
|
+
/**
|
|
6436
|
+
* How many of the frame's lines the reveal draws right now.
|
|
6437
|
+
*
|
|
6438
|
+
* The overlay is anchored at the bottom of the viewport, so a pane that
|
|
6439
|
+
* draws fewer lines keeps every line it does draw on the terminal row it
|
|
6440
|
+
* will settle on: the reader rises into place rather than sliding, and the
|
|
6441
|
+
* conversation above it keeps its own lines throughout.
|
|
6442
|
+
* @param rows - the height the frame was laid out at.
|
|
6443
|
+
* @returns the lines to keep, counted from the bottom rule up; at least one
|
|
6444
|
+
* and never more than the frame has.
|
|
6445
|
+
*/
|
|
6446
|
+
drawnRows(rows) {
|
|
6447
|
+
const reveal = this.options.reveal?.() ?? 1;
|
|
6448
|
+
if (reveal >= 1) return rows;
|
|
6449
|
+
return Math.max(1, Math.min(rows, Math.ceil(reveal * rows)));
|
|
6450
|
+
}
|
|
6451
|
+
/**
|
|
6452
|
+
* Answer one key press.
|
|
6453
|
+
* @param data - the raw key bytes.
|
|
6454
|
+
*/
|
|
6455
|
+
handleInput(data) {
|
|
6456
|
+
if (matchesKey(data, "ctrl+g")) {
|
|
6457
|
+
this.close("editor");
|
|
6458
|
+
return;
|
|
6459
|
+
}
|
|
6460
|
+
const blocks = this.options.blocks();
|
|
6461
|
+
const visible = filterTurns(turnGroups(blocks), blocks, this.state.query);
|
|
6462
|
+
const geometry = this.geometryFor(visible, blocks, Math.max(1, this.options.rows()));
|
|
6463
|
+
if (geometry.tiny) {
|
|
6464
|
+
if (matchesKey(data, "escape")) this.close("transcript");
|
|
6465
|
+
return;
|
|
6466
|
+
}
|
|
6467
|
+
if (matchesKey(data, "escape") && readerClosesOnEscape(this.state, geometry)) {
|
|
6468
|
+
this.close("transcript");
|
|
6469
|
+
return;
|
|
6470
|
+
}
|
|
6471
|
+
const intent = this.intentOf(data);
|
|
6472
|
+
if (intent === void 0) return;
|
|
6473
|
+
this.state = reduceReader(this.state, intent, visible, geometry);
|
|
6474
|
+
}
|
|
6475
|
+
/** Close the reader from outside, which is what quitting and `Ctrl+C` do. */
|
|
6476
|
+
withdraw() {
|
|
6477
|
+
this.close("editor");
|
|
6478
|
+
}
|
|
6479
|
+
/**
|
|
6480
|
+
* The geometry of the frame as it stands.
|
|
6481
|
+
* @param visible - the turns the rail lists.
|
|
6482
|
+
* @param blocks - the navigable blocks.
|
|
6483
|
+
* @param rows - the rows the overlay draws.
|
|
6484
|
+
* @returns the geometry, with the walking pane measured.
|
|
6485
|
+
*/
|
|
6486
|
+
geometryFor(visible, blocks, rows) {
|
|
6487
|
+
return readerGeometryFor(this.state, visible, blocks, Math.max(1, this.width), rows, this.options.minColumns);
|
|
6488
|
+
}
|
|
6489
|
+
/**
|
|
6490
|
+
* Settle the reader once.
|
|
6491
|
+
* @param target - which region takes the keyboard back.
|
|
6492
|
+
*/
|
|
6493
|
+
close(target) {
|
|
6494
|
+
if (!this.open) return;
|
|
6495
|
+
this.open = false;
|
|
6496
|
+
this.resolve({
|
|
6497
|
+
cursor: this.state.cursor,
|
|
6498
|
+
target
|
|
6499
|
+
});
|
|
6500
|
+
}
|
|
6501
|
+
/**
|
|
6502
|
+
* What one key means where the reader's keyboard is.
|
|
6503
|
+
* @param data - the raw key bytes.
|
|
6504
|
+
* @returns the intent, or undefined for a key this column claims nothing for.
|
|
6505
|
+
*/
|
|
6506
|
+
intentOf(data) {
|
|
6507
|
+
switch (this.state.column) {
|
|
6508
|
+
case "filter": return filterIntent(data);
|
|
6509
|
+
case "rail": return railIntent(data);
|
|
6510
|
+
case "pane": return paneIntent(data);
|
|
6511
|
+
/* v8 ignore next 2 -- closed-union exhaustiveness guard */
|
|
6512
|
+
default: return assertNever(this.state.column, "tui reader column");
|
|
6513
|
+
}
|
|
6514
|
+
}
|
|
6515
|
+
};
|
|
6516
|
+
/**
|
|
6517
|
+
* What one key means while the query line owns the keyboard.
|
|
6518
|
+
* @param data - the raw key bytes.
|
|
6519
|
+
* @returns the intent, or undefined for a key the query line ignores.
|
|
6520
|
+
*/
|
|
6521
|
+
function filterIntent(data) {
|
|
6522
|
+
if (matchesKey(data, "backspace")) return {
|
|
6523
|
+
kind: "erase",
|
|
6524
|
+
all: false
|
|
6525
|
+
};
|
|
6526
|
+
if (matchesKey(data, "ctrl+u")) return {
|
|
6527
|
+
kind: "erase",
|
|
6528
|
+
all: true
|
|
6529
|
+
};
|
|
6530
|
+
if (matchesKey(data, "enter")) return { kind: "commit" };
|
|
6531
|
+
if (matchesKey(data, "escape")) return { kind: "escape" };
|
|
6532
|
+
const text = typedText(data);
|
|
6533
|
+
return text === void 0 ? void 0 : {
|
|
6534
|
+
kind: "query",
|
|
6535
|
+
text
|
|
6536
|
+
};
|
|
6537
|
+
}
|
|
6538
|
+
/**
|
|
6539
|
+
* What one key means while the turn rail owns the keyboard.
|
|
6540
|
+
* @param data - the raw key bytes.
|
|
6541
|
+
* @returns the intent, or undefined for a key the rail ignores.
|
|
6542
|
+
*/
|
|
6543
|
+
function railIntent(data) {
|
|
6544
|
+
if (matchesKey(data, "up")) return {
|
|
6545
|
+
kind: "turn",
|
|
6546
|
+
to: "previous"
|
|
6547
|
+
};
|
|
6548
|
+
if (matchesKey(data, "down")) return {
|
|
6549
|
+
kind: "turn",
|
|
6550
|
+
to: "next"
|
|
6551
|
+
};
|
|
6552
|
+
if (matchesKey(data, "home")) return {
|
|
6553
|
+
kind: "turn",
|
|
6554
|
+
to: "first"
|
|
6555
|
+
};
|
|
6556
|
+
if (matchesKey(data, "end")) return {
|
|
6557
|
+
kind: "turn",
|
|
6558
|
+
to: "last"
|
|
6559
|
+
};
|
|
6560
|
+
if (matchesKey(data, "pageUp")) return {
|
|
6561
|
+
kind: "page",
|
|
6562
|
+
step: -1
|
|
6563
|
+
};
|
|
6564
|
+
if (matchesKey(data, "pageDown")) return {
|
|
6565
|
+
kind: "page",
|
|
6566
|
+
step: 1
|
|
6567
|
+
};
|
|
6568
|
+
if (matchesKey(data, "right") || matchesKey(data, "tab") || matchesKey(data, "enter")) return {
|
|
6569
|
+
kind: "column",
|
|
6570
|
+
to: "pane"
|
|
6571
|
+
};
|
|
6572
|
+
if (matchesKey(data, "escape")) return { kind: "escape" };
|
|
6573
|
+
return typedText(data) === FILTER_KEY ? { kind: "filter" } : void 0;
|
|
6574
|
+
}
|
|
6575
|
+
/**
|
|
6576
|
+
* What one key means while the sections own the keyboard.
|
|
6577
|
+
* @param data - the raw key bytes.
|
|
6578
|
+
* @returns the intent, or undefined for a key the pane ignores.
|
|
6579
|
+
*/
|
|
6580
|
+
function paneIntent(data) {
|
|
6581
|
+
if (matchesKey(data, "shift+up")) return {
|
|
6582
|
+
kind: "scroll",
|
|
6583
|
+
step: -1
|
|
6584
|
+
};
|
|
6585
|
+
if (matchesKey(data, "shift+down")) return {
|
|
6586
|
+
kind: "scroll",
|
|
6587
|
+
step: 1
|
|
6588
|
+
};
|
|
6589
|
+
if (matchesKey(data, "up")) return {
|
|
6590
|
+
kind: "section",
|
|
6591
|
+
to: "previous"
|
|
6592
|
+
};
|
|
6593
|
+
if (matchesKey(data, "down") || matchesKey(data, "right")) return {
|
|
6594
|
+
kind: "section",
|
|
6595
|
+
to: "next"
|
|
6596
|
+
};
|
|
6597
|
+
if (matchesKey(data, "pageUp")) return {
|
|
6598
|
+
kind: "page",
|
|
6599
|
+
step: -1
|
|
6600
|
+
};
|
|
6601
|
+
if (matchesKey(data, "pageDown")) return {
|
|
6602
|
+
kind: "page",
|
|
6603
|
+
step: 1
|
|
6604
|
+
};
|
|
6605
|
+
if (matchesKey(data, "home")) return {
|
|
6606
|
+
kind: "section",
|
|
6607
|
+
to: "first"
|
|
6608
|
+
};
|
|
6609
|
+
if (matchesKey(data, "end")) return {
|
|
6610
|
+
kind: "section",
|
|
6611
|
+
to: "last"
|
|
6612
|
+
};
|
|
6613
|
+
if (matchesKey(data, "left") || matchesKey(data, "tab") || matchesKey(data, "shift+tab")) return {
|
|
6614
|
+
kind: "column",
|
|
6615
|
+
to: "rail"
|
|
6616
|
+
};
|
|
6617
|
+
if (matchesKey(data, "enter")) return { kind: "pin" };
|
|
6618
|
+
if (matchesKey(data, "escape")) return { kind: "escape" };
|
|
6619
|
+
const digit = typedText(data);
|
|
6620
|
+
return digit !== void 0 && SECTION_DIGIT.test(digit) ? {
|
|
6621
|
+
kind: "section-at",
|
|
6622
|
+
index: Number(digit) - 1
|
|
6623
|
+
} : void 0;
|
|
6624
|
+
}
|
|
4561
6625
|
//#endregion
|
|
4562
6626
|
//#region lib/types/screen.js
|
|
4563
6627
|
/**
|
|
@@ -4616,10 +6680,12 @@ var GuardedMainScreen = class extends TuiMainScreen {
|
|
|
4616
6680
|
/**
|
|
4617
6681
|
* @param terminal - the terminal the tree renders into.
|
|
4618
6682
|
* @param showHardwareCursor - whether the terminal's own cursor is the caret.
|
|
4619
|
-
* @param guard - given the frame's first repaintable line
|
|
4620
|
-
*
|
|
4621
|
-
* changed any line; run at most
|
|
4622
|
-
* `true` on a frame that is
|
|
6683
|
+
* @param guard - given the frame's first repaintable line, the width it was
|
|
6684
|
+
* built at, and how many lines it has, applies what that geometry decides
|
|
6685
|
+
* and reports whether it changed any line; run at most
|
|
6686
|
+
* {@link SETTLE_PASSES} times per frame, each `true` on a frame that is
|
|
6687
|
+
* built again. The frame's own length is what places an overlay, which
|
|
6688
|
+
* pi-tui composites into its last `terminal.rows` lines.
|
|
4623
6689
|
*/
|
|
4624
6690
|
constructor(terminal, showHardwareCursor, guard) {
|
|
4625
6691
|
super(terminal, showHardwareCursor);
|
|
@@ -4635,7 +6701,7 @@ var GuardedMainScreen = class extends TuiMainScreen {
|
|
|
4635
6701
|
const previousTop = this.captureRenderState().previousViewportTop;
|
|
4636
6702
|
let lines = super.render(width);
|
|
4637
6703
|
for (let pass = 0; pass < SETTLE_PASSES; pass += 1) {
|
|
4638
|
-
if (!this.guard(Math.max(previousTop, lines.length - this.terminal.rows), width)) break;
|
|
6704
|
+
if (!this.guard(Math.max(previousTop, lines.length - this.terminal.rows), width, lines.length)) break;
|
|
4639
6705
|
lines = super.render(width);
|
|
4640
6706
|
}
|
|
4641
6707
|
return lines;
|
|
@@ -4690,8 +6756,16 @@ function describeSession(choice) {
|
|
|
4690
6756
|
const DEPTH_INDENT = " ";
|
|
4691
6757
|
/** What separates two facts inside one row, and two parts of the heading. */
|
|
4692
6758
|
const SEPARATOR = " · ";
|
|
4693
|
-
/**
|
|
4694
|
-
|
|
6759
|
+
/**
|
|
6760
|
+
* The keys the focused panel answers, appended to its heading, in the steps
|
|
6761
|
+
* the width chooses between. The key model owns the text, so `/help` and the
|
|
6762
|
+
* panel name the same keys.
|
|
6763
|
+
* @param room - columns the heading has left after its counts.
|
|
6764
|
+
* @returns the widest step that fits, and the shortest one when none does.
|
|
6765
|
+
*/
|
|
6766
|
+
function focusHints(room) {
|
|
6767
|
+
return fitLegend(HINTS.panel, room);
|
|
6768
|
+
}
|
|
4695
6769
|
/**
|
|
4696
6770
|
* The elapsed part of a row: the open turn's running time, else the total the
|
|
4697
6771
|
* child's settled turns took. Absent when no timing projection is registered.
|
|
@@ -4749,31 +6823,230 @@ function subagentPanelView(inputs) {
|
|
|
4749
6823
|
};
|
|
4750
6824
|
}
|
|
4751
6825
|
/**
|
|
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
|
|
4756
|
-
*
|
|
4757
|
-
* @param
|
|
4758
|
-
* @
|
|
6826
|
+
* Render the panel. Unfocused it is one dim summary line — the listed count
|
|
6827
|
+
* and the first child's key label. Focused it is the heading with navigation
|
|
6828
|
+
* keys, one line per drawn row, the overflow count, and the last listing
|
|
6829
|
+
* failure. The selected row is accented while the panel holds the keyboard,
|
|
6830
|
+
* and lifted above that accent while a landing is still moving.
|
|
6831
|
+
* @param view - the rows one draw produced.
|
|
6832
|
+
* @param render - the palette, the selected row, its lift, the width, and the listing failure.
|
|
6833
|
+
* @returns the panel text, one line when unfocused and one line per row when focused.
|
|
6834
|
+
*/
|
|
6835
|
+
function renderSubagentPanel(view, render) {
|
|
6836
|
+
const { palette, selected } = render;
|
|
6837
|
+
const total = view.rows.length + view.hidden;
|
|
6838
|
+
if (selected === void 0) {
|
|
6839
|
+
const first = view.rows[0]?.text.trimStart().split(SEPARATOR)[0];
|
|
6840
|
+
const parts = [`subagents${SEPARATOR}${String(total)} listed`];
|
|
6841
|
+
if (first) parts.push(first);
|
|
6842
|
+
if (render.failure !== void 0) parts.push(`listing failed: ${render.failure}`);
|
|
6843
|
+
return palette.dim(parts.join(SEPARATOR));
|
|
6844
|
+
}
|
|
6845
|
+
const counts = `subagents${SEPARATOR}${String(total)} listed`;
|
|
6846
|
+
const heading = `${counts}${SEPARATOR}${focusHints(render.width - visibleWidth(counts) - visibleWidth(SEPARATOR))}`;
|
|
6847
|
+
const lines = [palette.dim(heading)];
|
|
6848
|
+
for (const [index, row] of view.rows.entries()) lines.push(index === selected ? pulse(palette, palette.accent(row.text), render.level ?? 0) : palette.dim(row.text));
|
|
6849
|
+
if (view.hidden > 0) lines.push(palette.dim(`+${String(view.hidden)} more${SEPARATOR}/subagents lists them all`));
|
|
6850
|
+
if (render.failure !== void 0) lines.push(palette.dim(`listing failed: ${render.failure}`));
|
|
6851
|
+
return lines.join("\n");
|
|
6852
|
+
}
|
|
6853
|
+
//#endregion
|
|
6854
|
+
//#region lib/types/toast.js
|
|
6855
|
+
/**
|
|
6856
|
+
* The transient key-feedback line: a framed notice that floats over the
|
|
6857
|
+
* conversation for a moment and then fades out.
|
|
6858
|
+
*
|
|
6859
|
+
* It costs the frame no rows at all. pi-tui composites an overlay into the
|
|
6860
|
+
* last terminal-height lines of the frame after the tree rendered, so nothing
|
|
6861
|
+
* the conversation or the docked chrome drew moves, and the renderer's
|
|
6862
|
+
* repaint boundary is never raised. Guidance that is worth keeping stays a
|
|
6863
|
+
* transcript notice; this surface is for what the next key press makes
|
|
6864
|
+
* obsolete.
|
|
6865
|
+
* @module @deepseek-ai/dsh-tui-app/toast
|
|
6866
|
+
*/
|
|
6867
|
+
/**
|
|
6868
|
+
* What the line says when a second `Ctrl+C` would quit. The transient lines
|
|
6869
|
+
* are catalogued here, one constant each, so the surface that shows them and
|
|
6870
|
+
* the tests that pin them read the same words.
|
|
6871
|
+
*/
|
|
6872
|
+
const QUIT_TOAST = "press Ctrl+C again to quit";
|
|
6873
|
+
/** What the line says when the transcript holds nothing the reader could open. */
|
|
6874
|
+
const NOTHING_TO_READ_TOAST = "nothing in the transcript to read yet";
|
|
6875
|
+
/** What the line says when a fold key named a block the renderer can no longer rewrite. */
|
|
6876
|
+
const ABOVE_WINDOW_TOAST = "above the repaint window · opened in the reader";
|
|
6877
|
+
/**
|
|
6878
|
+
* What the line says while the stop is armed. It names the turn it would
|
|
6879
|
+
* stop, so a press after a turn boundary is read for what it is.
|
|
6880
|
+
* @param turn - the running turn's number.
|
|
6881
|
+
* @returns the line.
|
|
6882
|
+
*/
|
|
6883
|
+
function stopTurnToast(turn) {
|
|
6884
|
+
return `press Esc again to stop turn ${String(turn)}`;
|
|
6885
|
+
}
|
|
6886
|
+
/**
|
|
6887
|
+
* How long one line holds at full strength before it fades out, which is also
|
|
6888
|
+
* how long the window it names lasts: the second `Esc` that stops a turn is
|
|
6889
|
+
* armed for exactly as long as any part of the line is on screen. The shipped
|
|
6890
|
+
* default of the `toastMs` setting.
|
|
6891
|
+
*/
|
|
6892
|
+
const TOAST_MS = 2e3;
|
|
6893
|
+
/** Columns the frame itself takes: the two rules and the space after the left one. */
|
|
6894
|
+
const FRAME_COLUMNS = 3;
|
|
6895
|
+
/** Narrowest box that still holds a rule, a space, one column of text, and the closing rule. */
|
|
6896
|
+
const MIN_WIDTH = 4;
|
|
6897
|
+
/** What ends a line the width cut short; one column, so the mark itself fits. */
|
|
6898
|
+
const ELLIPSIS = "…";
|
|
6899
|
+
/** How much of the terminal one line takes when its own text needs less. */
|
|
6900
|
+
const TOAST_WIDTH = "40%";
|
|
6901
|
+
/** Which line of the viewport the box starts on, as its top margin. */
|
|
6902
|
+
const TOAST_ROW = 1;
|
|
6903
|
+
/**
|
|
6904
|
+
* Whether the renderer can still repaint the lines a transient line lands on.
|
|
6905
|
+
*
|
|
6906
|
+
* pi-tui composites an overlay into the last `terminal.rows` lines of the
|
|
6907
|
+
* frame, so a line that floats near the top of the viewport is the first to
|
|
6908
|
+
* fall out of the repaint window when a frame shrinks - and rewriting a line
|
|
6909
|
+
* above that window costs the terminal's whole scrollback.
|
|
6910
|
+
* @param viewportFloor - how many of the viewport's own first lines the
|
|
6911
|
+
* renderer can no longer repaint, as `repaintFloor` reports it for the
|
|
6912
|
+
* viewport's first line.
|
|
6913
|
+
* @returns true while the box lies inside the repaint window.
|
|
6914
|
+
*/
|
|
6915
|
+
function toastDrawable(viewportFloor) {
|
|
6916
|
+
return viewportFloor <= TOAST_ROW;
|
|
6917
|
+
}
|
|
6918
|
+
/**
|
|
6919
|
+
* Where one transient line floats and how wide it is.
|
|
6920
|
+
*
|
|
6921
|
+
* It sits in the top-right corner of the viewport, over the conversation and
|
|
6922
|
+
* clear of the docked chrome, and it is at least as wide as its own text: a
|
|
6923
|
+
* line that says which key stops a turn is worth no ellipsis. A terminal too
|
|
6924
|
+
* narrow for that clamps the box and the text is cut instead. The percentage
|
|
6925
|
+
* is re-resolved per render, so a resize needs no notification, and
|
|
6926
|
+
* `nonCapturing` leaves the keyboard where the user put it.
|
|
6927
|
+
* @param text - what the line says.
|
|
6928
|
+
* @param drawable - read per render: whether the renderer can still repaint
|
|
6929
|
+
* the box where it lands, which a frame that shrank under it can deny.
|
|
6930
|
+
* @returns the overlay options this line is shown with.
|
|
6931
|
+
*/
|
|
6932
|
+
function toastOverlay(text, drawable) {
|
|
6933
|
+
return {
|
|
6934
|
+
width: TOAST_WIDTH,
|
|
6935
|
+
minWidth: visibleWidth(text) + FRAME_COLUMNS,
|
|
6936
|
+
anchor: "top-right",
|
|
6937
|
+
margin: {
|
|
6938
|
+
top: TOAST_ROW,
|
|
6939
|
+
right: 2
|
|
6940
|
+
},
|
|
6941
|
+
nonCapturing: true,
|
|
6942
|
+
visible: drawable
|
|
6943
|
+
};
|
|
6944
|
+
}
|
|
6945
|
+
/**
|
|
6946
|
+
* How long one toast stays on screen and how far through its fade-out it is.
|
|
6947
|
+
*
|
|
6948
|
+
* It is a {@link RegisteredFade} so the application's one fade tick keeps
|
|
6949
|
+
* running while a line is up and disarms itself the moment the line expires -
|
|
6950
|
+
* including under reduced motion, where nothing else is moving but the line
|
|
6951
|
+
* still has to come down.
|
|
6952
|
+
*/
|
|
6953
|
+
var ToastClock = class {
|
|
6954
|
+
options;
|
|
6955
|
+
/** Whether the line came down before its time, which settles the clock at once. */
|
|
6956
|
+
taken = false;
|
|
6957
|
+
/**
|
|
6958
|
+
* @param options - when the line went up, how long it holds at full
|
|
6959
|
+
* strength, the fade-out that follows that hold on a terminal which draws a
|
|
6960
|
+
* ramp, and the clock both phases are measured against.
|
|
6961
|
+
*/
|
|
6962
|
+
constructor(options) {
|
|
6963
|
+
this.options = options;
|
|
6964
|
+
}
|
|
6965
|
+
/**
|
|
6966
|
+
* Settle this clock now, for a line the next key press took down or
|
|
6967
|
+
* replaced: the registry drops it at the following tick and the one fade
|
|
6968
|
+
* tick disarms with it, so nothing keeps repainting for a line that is no
|
|
6969
|
+
* longer drawn.
|
|
6970
|
+
*/
|
|
6971
|
+
settle() {
|
|
6972
|
+
this.taken = true;
|
|
6973
|
+
}
|
|
6974
|
+
/**
|
|
6975
|
+
* How long this line is on screen in total.
|
|
6976
|
+
* @returns the hold plus the fade-out, in milliseconds; the hold alone when
|
|
6977
|
+
* the terminal draws no ramp.
|
|
6978
|
+
*/
|
|
6979
|
+
lifetimeMs() {
|
|
6980
|
+
const { holdMs, steps, stepMs, fading } = this.options;
|
|
6981
|
+
return holdMs + (fading ? steps * stepMs : 0);
|
|
6982
|
+
}
|
|
6983
|
+
/**
|
|
6984
|
+
* How far through the fade-out this line is.
|
|
6985
|
+
* @returns the age in units of `stepMs` that {@link recolorLines} draws at,
|
|
6986
|
+
* or undefined while the line still holds at full strength.
|
|
6987
|
+
*/
|
|
6988
|
+
age() {
|
|
6989
|
+
const { shownAt, holdMs, stepMs, now } = this.options;
|
|
6990
|
+
const elapsed = now() - shownAt;
|
|
6991
|
+
return elapsed < holdMs ? void 0 : (elapsed - holdMs) / stepMs;
|
|
6992
|
+
}
|
|
6993
|
+
/**
|
|
6994
|
+
* Whether the line has come down.
|
|
6995
|
+
* @returns true once the hold and the fade-out have both elapsed, and at
|
|
6996
|
+
* once for a line {@link ToastClock.settle} took down early.
|
|
6997
|
+
*/
|
|
6998
|
+
expired() {
|
|
6999
|
+
return this.taken || this.options.now() - this.options.shownAt >= this.lifetimeMs();
|
|
7000
|
+
}
|
|
7001
|
+
/**
|
|
7002
|
+
* Whether the line still needs another repaint.
|
|
7003
|
+
* @returns true until it expires.
|
|
7004
|
+
*/
|
|
7005
|
+
needsRepaint() {
|
|
7006
|
+
return !this.expired();
|
|
7007
|
+
}
|
|
7008
|
+
};
|
|
7009
|
+
/**
|
|
7010
|
+
* One transient line as a mounted overlay: a dim rounded box around the text,
|
|
7011
|
+
* every line exactly the width it was laid out at, so it reads solid over
|
|
7012
|
+
* whatever the conversation drew underneath.
|
|
7013
|
+
*
|
|
7014
|
+
* The fade is read once per render rather than pushed in, so the clock alone
|
|
7015
|
+
* decides what a frame draws.
|
|
4759
7016
|
*/
|
|
4760
|
-
|
|
4761
|
-
|
|
4762
|
-
|
|
4763
|
-
|
|
4764
|
-
|
|
4765
|
-
|
|
4766
|
-
|
|
4767
|
-
|
|
4768
|
-
|
|
7017
|
+
var ToastPane = class {
|
|
7018
|
+
text;
|
|
7019
|
+
settings;
|
|
7020
|
+
/**
|
|
7021
|
+
* @param text - what the line says; it is cut to the width with an ellipsis.
|
|
7022
|
+
* @param settings - the palette and the fade; the width arrives per render.
|
|
7023
|
+
*/
|
|
7024
|
+
constructor(text, settings) {
|
|
7025
|
+
this.text = text;
|
|
7026
|
+
this.settings = settings;
|
|
4769
7027
|
}
|
|
4770
|
-
|
|
4771
|
-
|
|
4772
|
-
|
|
4773
|
-
|
|
4774
|
-
|
|
4775
|
-
|
|
4776
|
-
|
|
7028
|
+
invalidate() {}
|
|
7029
|
+
/**
|
|
7030
|
+
* Draw the box at `width`.
|
|
7031
|
+
* @param width - the total width the overlay was laid out at.
|
|
7032
|
+
* @returns exactly three lines, each of that width.
|
|
7033
|
+
*/
|
|
7034
|
+
render(width) {
|
|
7035
|
+
const { palette } = this.settings;
|
|
7036
|
+
const columns = Math.max(MIN_WIDTH, width);
|
|
7037
|
+
const rule = "─".repeat(columns - 2);
|
|
7038
|
+
const field = columns - FRAME_COLUMNS;
|
|
7039
|
+
const body = truncateToWidth(this.text, field, ELLIPSIS);
|
|
7040
|
+
const padding = " ".repeat(Math.max(0, field - visibleWidth(body)));
|
|
7041
|
+
const lines = [
|
|
7042
|
+
`╭${rule}╮`,
|
|
7043
|
+
`│ ${body}${padding}│`,
|
|
7044
|
+
`╰${rule}╯`
|
|
7045
|
+
].map(palette.dim);
|
|
7046
|
+
const age = this.settings.age();
|
|
7047
|
+
return age === void 0 ? lines : recolorLines(lines, age, this.settings.style());
|
|
7048
|
+
}
|
|
7049
|
+
};
|
|
4777
7050
|
//#endregion
|
|
4778
7051
|
//#region lib/types/app.js
|
|
4779
7052
|
/**
|
|
@@ -4792,6 +7065,23 @@ function renderSubagentPanel(view, render) {
|
|
|
4792
7065
|
*/
|
|
4793
7066
|
/** A second Ctrl+C inside this window quits. */
|
|
4794
7067
|
const QUIT_DOUBLE_PRESS_MS = 600;
|
|
7068
|
+
/** What the transcript is told when a session switch took the conversation the reader was showing. */
|
|
7069
|
+
const READER_GONE = "the transcript changed · reader closed";
|
|
7070
|
+
/**
|
|
7071
|
+
* How the reader is mounted: the whole viewport, anchored at its bottom edge.
|
|
7072
|
+
*
|
|
7073
|
+
* pi-tui composites an overlay into the last `terminal.rows` lines of the
|
|
7074
|
+
* frame, so anchoring at the bottom puts the pane's first line exactly on the
|
|
7075
|
+
* frame's last repaintable line whatever the frame's own length is - and the
|
|
7076
|
+
* pane draws one line fewer for every viewport line the renderer can no
|
|
7077
|
+
* longer repaint ({@link TuiApp.viewportFloor}), so opening the reader never
|
|
7078
|
+
* rewrites a line above the window.
|
|
7079
|
+
*/
|
|
7080
|
+
const READER_OVERLAY = {
|
|
7081
|
+
width: "100%",
|
|
7082
|
+
maxHeight: "100%",
|
|
7083
|
+
anchor: "bottom-left"
|
|
7084
|
+
};
|
|
4795
7085
|
/**
|
|
4796
7086
|
* Row layout of the todo picker: the label column grows with the widest todo
|
|
4797
7087
|
* line instead of stopping at the list's 32-column default, which would cut a
|
|
@@ -4853,6 +7143,40 @@ const DARK_FOREGROUND = {
|
|
|
4853
7143
|
function assumedForeground(background) {
|
|
4854
7144
|
return (.2126 * background.r + .7152 * background.g + .0722 * background.b) / 255 < DARK_BACKGROUND_LUMINANCE ? LIGHT_FOREGROUND : DARK_FOREGROUND;
|
|
4855
7145
|
}
|
|
7146
|
+
/**
|
|
7147
|
+
* Where one step along the status bar's segments lands: one either way,
|
|
7148
|
+
* wrapping at both ends, or straight to an end.
|
|
7149
|
+
* @param to - which way the key steps.
|
|
7150
|
+
* @param index - where the selection sits now.
|
|
7151
|
+
* @param count - how many segments the bar draws; at least 1.
|
|
7152
|
+
* @returns the index to select.
|
|
7153
|
+
*/
|
|
7154
|
+
function barTarget(to, index, count) {
|
|
7155
|
+
switch (to) {
|
|
7156
|
+
case "previous": return (index - 1 + count) % count;
|
|
7157
|
+
case "next": return (index + 1) % count;
|
|
7158
|
+
case "first": return 0;
|
|
7159
|
+
case "last": return count - 1;
|
|
7160
|
+
/* v8 ignore next 2 -- closed-union exhaustiveness guard */
|
|
7161
|
+
default: return assertNever(to, "tui move target");
|
|
7162
|
+
}
|
|
7163
|
+
}
|
|
7164
|
+
/** What `/help` calls the reader, the one focus state outside the docked stack. */
|
|
7165
|
+
const READER_LABEL = "reader";
|
|
7166
|
+
/** Columns between a focus state's name and the keys it answers. */
|
|
7167
|
+
const HELP_LABEL_GAP = 2;
|
|
7168
|
+
/**
|
|
7169
|
+
* The key lines `/help` prints: one row per focus state in the order the
|
|
7170
|
+
* screen stacks them, the reader last, with a state's further lines under a
|
|
7171
|
+
* blank name column. The text of every line is the legend its own surface
|
|
7172
|
+
* draws.
|
|
7173
|
+
* @returns the lines, unstyled.
|
|
7174
|
+
*/
|
|
7175
|
+
function helpKeyLines() {
|
|
7176
|
+
const states = [...FOCUS_REGIONS.map((region) => [REGION_LABELS[region], KEY_LINES[region]]), [READER_LABEL, [READER_HINTS.rail[0], READER_HINTS.pane[0]]]];
|
|
7177
|
+
const column = Math.max(...states.map(([label]) => visibleWidth(label))) + HELP_LABEL_GAP;
|
|
7178
|
+
return states.flatMap(([label, lines]) => lines.map((line, index) => `${(index === 0 ? label : "").padEnd(column)}${line}`));
|
|
7179
|
+
}
|
|
4856
7180
|
/** The terminal's own commands, handled before the shared command registry. */
|
|
4857
7181
|
const LOCAL_COMMANDS = [
|
|
4858
7182
|
{
|
|
@@ -4941,7 +7265,11 @@ const LOCAL_COMMANDS = [
|
|
|
4941
7265
|
},
|
|
4942
7266
|
{
|
|
4943
7267
|
name: "tools",
|
|
4944
|
-
description: "Expand or collapse every tool card"
|
|
7268
|
+
description: "Expand or collapse every tool card and context row"
|
|
7269
|
+
},
|
|
7270
|
+
{
|
|
7271
|
+
name: "turns",
|
|
7272
|
+
description: "Read the conversation full screen, turns side by side (Ctrl+G)"
|
|
4945
7273
|
},
|
|
4946
7274
|
{
|
|
4947
7275
|
name: "quit",
|
|
@@ -4999,8 +7327,8 @@ var TuiApp = class {
|
|
|
4999
7327
|
focus = "editor";
|
|
5000
7328
|
/**
|
|
5001
7329
|
* Where the transcript focus sits, kept across a page and a return to the
|
|
5002
|
-
* editor
|
|
5003
|
-
*
|
|
7330
|
+
* editor so `Shift+Up` comes back to the section the walk was left on. A
|
|
7331
|
+
* session switch clears it with the blocks it named.
|
|
5004
7332
|
*/
|
|
5005
7333
|
cursor;
|
|
5006
7334
|
/** The section drawn with the focus gutter right now; set only by {@link TuiApp.settleFrame}. */
|
|
@@ -5029,6 +7357,36 @@ var TuiApp = class {
|
|
|
5029
7357
|
reasoningTail;
|
|
5030
7358
|
/** The card fades running right now; each drops itself once it settles. */
|
|
5031
7359
|
blockFades = new FadeRegistry();
|
|
7360
|
+
/**
|
|
7361
|
+
* The chrome motions running right now. It is consulted whatever the
|
|
7362
|
+
* terminal draws, because a transient line has to come down again even on a
|
|
7363
|
+
* terminal that fades nothing.
|
|
7364
|
+
*/
|
|
7365
|
+
motions = new FadeRegistry();
|
|
7366
|
+
/** The transient line on screen right now, with the clock that takes it down. */
|
|
7367
|
+
toast;
|
|
7368
|
+
/** The chrome motion running right now, and how much of the focused surface it lifts. */
|
|
7369
|
+
chrome;
|
|
7370
|
+
/** The lift the subagent panel's text was last built with, which only a repaint changes. */
|
|
7371
|
+
panelLift = 0;
|
|
7372
|
+
/** The reader on screen right now, while one is open. */
|
|
7373
|
+
reader;
|
|
7374
|
+
/** The motion growing the open reader into place; settled or absent draws it whole. */
|
|
7375
|
+
readerOpening;
|
|
7376
|
+
/** The reader shrinking away, still mounted until its motion settles. */
|
|
7377
|
+
readerClosing;
|
|
7378
|
+
/** Prompts shown or waiting on the modal queue, which the reader steps aside for. */
|
|
7379
|
+
queuedModals = 0;
|
|
7380
|
+
/** Until when an `Escape` that reaches the editor does nothing at all. */
|
|
7381
|
+
escapeQuietUntil = 0;
|
|
7382
|
+
/** Until when a second editor `Escape` stops the running turn. */
|
|
7383
|
+
stopArmedUntil = 0;
|
|
7384
|
+
/**
|
|
7385
|
+
* How many of the viewport's own first lines the renderer can no longer
|
|
7386
|
+
* repaint, from the last frame the guard settled. An overlay composites
|
|
7387
|
+
* into those lines, so this is what decides where one can be drawn.
|
|
7388
|
+
*/
|
|
7389
|
+
viewportFloor = 0;
|
|
5032
7390
|
/** Set while {@link TuiApp.bind} replays a session's history, which draws its cards settled. */
|
|
5033
7391
|
replaying = false;
|
|
5034
7392
|
/** Whether this terminal draws a ramp at all, decided once at start. */
|
|
@@ -5037,6 +7395,7 @@ var TuiApp = class {
|
|
|
5037
7395
|
fadeStyle = NO_FADE;
|
|
5038
7396
|
bound;
|
|
5039
7397
|
streaming;
|
|
7398
|
+
/** Whether the fold keys left every foldable block open; one appended later follows it. */
|
|
5040
7399
|
toolsExpanded = false;
|
|
5041
7400
|
/** Set while a session switch awaits the host, so input cannot target the session being left. */
|
|
5042
7401
|
switching = false;
|
|
@@ -5053,9 +7412,12 @@ var TuiApp = class {
|
|
|
5053
7412
|
this.bound = deps.initial;
|
|
5054
7413
|
this.theme = {
|
|
5055
7414
|
palette,
|
|
5056
|
-
toolPreviewLines: deps.toolPreviewLines
|
|
7415
|
+
toolPreviewLines: deps.toolPreviewLines,
|
|
7416
|
+
contextPreviewLines: deps.contextPreviewLines
|
|
5057
7417
|
};
|
|
5058
|
-
this.tui = new GuardedMainScreen(deps.terminal, true, (viewportTop, width) =>
|
|
7418
|
+
this.tui = new GuardedMainScreen(deps.terminal, true, (viewportTop, width, frameLines) => {
|
|
7419
|
+
return this.settleFrame(viewportTop, width, frameLines);
|
|
7420
|
+
});
|
|
5059
7421
|
this.header = new Text("", 0, 0);
|
|
5060
7422
|
this.inspector = new InspectorPane(() => this.inspectorView(), {
|
|
5061
7423
|
palette,
|
|
@@ -5076,7 +7438,10 @@ var TuiApp = class {
|
|
|
5076
7438
|
segments: this.segments,
|
|
5077
7439
|
render: {
|
|
5078
7440
|
palette: this.deps.palette,
|
|
5079
|
-
...this.focus === "bar" ? {
|
|
7441
|
+
...this.focus === "bar" ? {
|
|
7442
|
+
selected: footerSelectionIndex(this.segments, this.barSelection),
|
|
7443
|
+
level: this.markLift()
|
|
7444
|
+
} : {}
|
|
5080
7445
|
}
|
|
5081
7446
|
}));
|
|
5082
7447
|
this.modals = new ModalQueue({
|
|
@@ -5185,6 +7550,8 @@ var TuiApp = class {
|
|
|
5185
7550
|
this.updateFadeTicker();
|
|
5186
7551
|
for (const dispose of this.disposers.splice(0)) dispose();
|
|
5187
7552
|
this.modals.withdrawActive();
|
|
7553
|
+
this.dropReader();
|
|
7554
|
+
this.hideToast();
|
|
5188
7555
|
this.loader.stop();
|
|
5189
7556
|
this.deps.terminal.write(SET_TERMINAL_DEFAULT_CURSOR);
|
|
5190
7557
|
this.tui.stop();
|
|
@@ -5194,8 +7561,10 @@ var TuiApp = class {
|
|
|
5194
7561
|
/** Draw `next` as the terminal's session: clear the transcript and replay its history. */
|
|
5195
7562
|
bind(next) {
|
|
5196
7563
|
this.bound = next;
|
|
7564
|
+
const reading = this.dropReader();
|
|
5197
7565
|
this.focusEditor();
|
|
5198
7566
|
this.highlighted = void 0;
|
|
7567
|
+
this.cursor = void 0;
|
|
5199
7568
|
this.chat.clear();
|
|
5200
7569
|
this.toolBlocks.clear();
|
|
5201
7570
|
this.toolArguments.clear();
|
|
@@ -5217,6 +7586,7 @@ var TuiApp = class {
|
|
|
5217
7586
|
this.replaying = true;
|
|
5218
7587
|
for (const event of next.history) this.onSessionEvent(next.agent.session, event);
|
|
5219
7588
|
this.replaying = false;
|
|
7589
|
+
if (reading) this.notice(READER_GONE);
|
|
5220
7590
|
this.refreshHeader();
|
|
5221
7591
|
this.refreshFooter();
|
|
5222
7592
|
this.refreshSubagentPanel();
|
|
@@ -5229,7 +7599,7 @@ var TuiApp = class {
|
|
|
5229
7599
|
*/
|
|
5230
7600
|
async switchSession(open, verb) {
|
|
5231
7601
|
if (this.agent.status === "running") {
|
|
5232
|
-
this.notice("stop the running turn (Esc) before switching sessions", "error");
|
|
7602
|
+
this.notice("stop the running turn (Esc twice) before switching sessions", "error");
|
|
5233
7603
|
return;
|
|
5234
7604
|
}
|
|
5235
7605
|
this.switching = true;
|
|
@@ -5365,13 +7735,19 @@ var TuiApp = class {
|
|
|
5365
7735
|
this.panelSelection = void 0;
|
|
5366
7736
|
if (this.focus === "panel") this.setFocus("editor");
|
|
5367
7737
|
if (mounted) this.panelSlot.removeChild(this.panel);
|
|
7738
|
+
this.panelLift = 0;
|
|
5368
7739
|
} else {
|
|
5369
7740
|
if (!mounted) this.panelSlot.addChild(this.panel);
|
|
5370
7741
|
const selected = this.panelSelectionIndex(view.rows);
|
|
5371
7742
|
this.panelSelection = view.rows[selected]?.id;
|
|
7743
|
+
this.panelLift = this.panelLiftNow();
|
|
5372
7744
|
this.panel.setText(renderSubagentPanel(view, {
|
|
5373
7745
|
palette: this.deps.palette,
|
|
5374
|
-
|
|
7746
|
+
width: this.deps.terminal.columns,
|
|
7747
|
+
...this.focus === "panel" ? {
|
|
7748
|
+
selected,
|
|
7749
|
+
level: this.panelLift
|
|
7750
|
+
} : {},
|
|
5375
7751
|
...this.listingFailure === void 0 ? {} : { failure: this.listingFailure }
|
|
5376
7752
|
}));
|
|
5377
7753
|
}
|
|
@@ -5523,8 +7899,23 @@ var TuiApp = class {
|
|
|
5523
7899
|
* @returns the prompt's settled value.
|
|
5524
7900
|
*/
|
|
5525
7901
|
showModal(prompt, signal) {
|
|
5526
|
-
this.
|
|
5527
|
-
|
|
7902
|
+
this.queuedModals += 1;
|
|
7903
|
+
this.finishReaderClose();
|
|
7904
|
+
this.hideReader(true);
|
|
7905
|
+
if (this.reader === void 0) this.focusEditor();
|
|
7906
|
+
return this.modals.run(prompt, signal).finally(() => {
|
|
7907
|
+
this.queuedModals -= 1;
|
|
7908
|
+
this.armEscapeHandoff();
|
|
7909
|
+
if (this.queuedModals === 0) this.hideReader(false);
|
|
7910
|
+
});
|
|
7911
|
+
}
|
|
7912
|
+
/**
|
|
7913
|
+
* Take the reader off the screen for as long as something else needs it, or
|
|
7914
|
+
* put it back.
|
|
7915
|
+
* @param hidden - whether the reader steps aside.
|
|
7916
|
+
*/
|
|
7917
|
+
hideReader(hidden) {
|
|
7918
|
+
this.reader?.handle.setHidden(hidden);
|
|
5528
7919
|
}
|
|
5529
7920
|
/**
|
|
5530
7921
|
* Walk a list one entry at a time: the picker opens on `rows`, `Enter`
|
|
@@ -5727,12 +8118,34 @@ var TuiApp = class {
|
|
|
5727
8118
|
model: agent.options.model ?? "default"
|
|
5728
8119
|
};
|
|
5729
8120
|
}
|
|
8121
|
+
/**
|
|
8122
|
+
* Answer one key press.
|
|
8123
|
+
*
|
|
8124
|
+
* A visible prompt owns the whole key stream; `Ctrl+C` and `Ctrl+D` keep
|
|
8125
|
+
* their global meaning wherever the keyboard is; everything else is what
|
|
8126
|
+
* {@link resolveKey} makes of the key in the region that holds it.
|
|
8127
|
+
*
|
|
8128
|
+
* A reader that is still shrinking away goes first, before the key is read:
|
|
8129
|
+
* pi-tui hands the key stream back to an overlay it still holds a focus
|
|
8130
|
+
* restore for, so a key this listener leaves to the editor would reach the
|
|
8131
|
+
* pane instead of the caret.
|
|
8132
|
+
* @param data - the raw key bytes.
|
|
8133
|
+
* @returns the consume marker, or undefined for the keys pi-tui's own
|
|
8134
|
+
* editor answers.
|
|
8135
|
+
*/
|
|
5730
8136
|
onKey(data) {
|
|
8137
|
+
this.finishReaderClose();
|
|
5731
8138
|
if (this.modals.isActive()) {
|
|
5732
8139
|
if (!matchesKey(data, "ctrl+c")) return void 0;
|
|
5733
8140
|
this.modals.withdrawActive();
|
|
5734
8141
|
return { consume: true };
|
|
5735
8142
|
}
|
|
8143
|
+
if (this.reader !== void 0) {
|
|
8144
|
+
if (!matchesKey(data, "ctrl+c")) return void 0;
|
|
8145
|
+
this.reader.pane.withdraw();
|
|
8146
|
+
return { consume: true };
|
|
8147
|
+
}
|
|
8148
|
+
if (this.focus === "editor" && !matchesKey(data, "escape")) this.disarmStop();
|
|
5736
8149
|
if (matchesKey(data, "ctrl+c")) {
|
|
5737
8150
|
this.focusEditor();
|
|
5738
8151
|
const now = Date.now();
|
|
@@ -5742,7 +8155,7 @@ var TuiApp = class {
|
|
|
5742
8155
|
}
|
|
5743
8156
|
this.lastCtrlC = now;
|
|
5744
8157
|
this.editor.setText("");
|
|
5745
|
-
this.
|
|
8158
|
+
this.showToast(QUIT_TOAST);
|
|
5746
8159
|
return { consume: true };
|
|
5747
8160
|
}
|
|
5748
8161
|
if (matchesKey(data, "ctrl+d")) {
|
|
@@ -5750,155 +8163,316 @@ var TuiApp = class {
|
|
|
5750
8163
|
if (this.editor.getText() === "") this.stop();
|
|
5751
8164
|
return { consume: true };
|
|
5752
8165
|
}
|
|
5753
|
-
|
|
5754
|
-
if (this.focus === "
|
|
5755
|
-
|
|
5756
|
-
|
|
5757
|
-
|
|
5758
|
-
|
|
5759
|
-
|
|
5760
|
-
|
|
5761
|
-
|
|
5762
|
-
|
|
5763
|
-
|
|
5764
|
-
|
|
5765
|
-
|
|
5766
|
-
|
|
5767
|
-
|
|
5768
|
-
this.
|
|
8166
|
+
const action = resolveKey(this.focus, data);
|
|
8167
|
+
if (action === void 0) return this.focus === "editor" ? void 0 : { consume: true };
|
|
8168
|
+
return this.onAction(action, data);
|
|
8169
|
+
}
|
|
8170
|
+
/**
|
|
8171
|
+
* Apply one resolved key action.
|
|
8172
|
+
* @param action - what the key named where the keyboard is.
|
|
8173
|
+
* @param data - the raw key bytes, which a typing action hands to the editor.
|
|
8174
|
+
* @returns the consume marker, or undefined for the one key the editor's
|
|
8175
|
+
* open autocomplete answers itself.
|
|
8176
|
+
*/
|
|
8177
|
+
onAction(action, data) {
|
|
8178
|
+
switch (action.kind) {
|
|
8179
|
+
case "focus":
|
|
8180
|
+
if (action.region === "transcript") this.focusTranscript();
|
|
8181
|
+
else this.focusBar();
|
|
8182
|
+
return { consume: true };
|
|
8183
|
+
case "leave":
|
|
8184
|
+
if (action.direction === "down") this.focusBelowEditor();
|
|
8185
|
+
else this.focusAboveBar();
|
|
8186
|
+
return { consume: true };
|
|
8187
|
+
case "cycle":
|
|
8188
|
+
this.cycleRegion(action.step);
|
|
8189
|
+
return { consume: true };
|
|
8190
|
+
case "move":
|
|
8191
|
+
this.moveBy(action.axis, action.to);
|
|
8192
|
+
return { consume: true };
|
|
8193
|
+
case "open":
|
|
8194
|
+
this.openFocused();
|
|
8195
|
+
return { consume: true };
|
|
8196
|
+
case "fold":
|
|
8197
|
+
this.foldFocused();
|
|
8198
|
+
return { consume: true };
|
|
8199
|
+
case "fold-all":
|
|
8200
|
+
this.toggleFolding();
|
|
8201
|
+
return { consume: true };
|
|
8202
|
+
case "reader": {
|
|
8203
|
+
const held = this.focus === "transcript" ? this.focusedSection() : void 0;
|
|
8204
|
+
this.openReader(held?.cursor);
|
|
8205
|
+
return { consume: true };
|
|
5769
8206
|
}
|
|
5770
|
-
|
|
5771
|
-
|
|
5772
|
-
|
|
5773
|
-
|
|
5774
|
-
|
|
5775
|
-
|
|
5776
|
-
|
|
5777
|
-
|
|
5778
|
-
|
|
5779
|
-
|
|
5780
|
-
|
|
5781
|
-
|
|
5782
|
-
|
|
5783
|
-
|
|
5784
|
-
|
|
5785
|
-
|
|
5786
|
-
|
|
8207
|
+
case "escape": return this.onEscape();
|
|
8208
|
+
case "steer":
|
|
8209
|
+
this.onSubmit(this.editor.getText(), "steer");
|
|
8210
|
+
return { consume: true };
|
|
8211
|
+
case "effort":
|
|
8212
|
+
this.effortCycle = this.effortCycle.then(
|
|
8213
|
+
() => this.cycleEffort(),
|
|
8214
|
+
/* v8 ignore next -- cycleEffort handles its own failures; this recovers a rejected chain */
|
|
8215
|
+
() => this.cycleEffort()
|
|
8216
|
+
);
|
|
8217
|
+
return { consume: true };
|
|
8218
|
+
case "type":
|
|
8219
|
+
this.focusEditor();
|
|
8220
|
+
this.editor.handleInput(data);
|
|
8221
|
+
this.tui.requestRender();
|
|
8222
|
+
return { consume: true };
|
|
8223
|
+
/* v8 ignore next 2 -- closed-union exhaustiveness guard */
|
|
8224
|
+
default: return assertNever(action, "tui key action");
|
|
5787
8225
|
}
|
|
5788
8226
|
}
|
|
5789
8227
|
/**
|
|
5790
|
-
* Answer
|
|
5791
|
-
*
|
|
5792
|
-
*
|
|
5793
|
-
*
|
|
5794
|
-
*
|
|
5795
|
-
*
|
|
8228
|
+
* Answer `Escape`.
|
|
8229
|
+
*
|
|
8230
|
+
* From a docked region it hands the keyboard back to the editor and starts
|
|
8231
|
+
* the handoff window, so a second press landing in the editor does nothing
|
|
8232
|
+
* at all: leaving a region, a page, or a picker can never stop a running
|
|
8233
|
+
* turn. In the editor it arms the stop and says so, and only a second press
|
|
8234
|
+
* while that line is still on screen stops the turn.
|
|
8235
|
+
* @returns the consume marker, or undefined while the editor's open
|
|
8236
|
+
* autocomplete answers the key itself.
|
|
5796
8237
|
*/
|
|
5797
|
-
|
|
5798
|
-
if (
|
|
8238
|
+
onEscape() {
|
|
8239
|
+
if (this.focus !== "editor") {
|
|
5799
8240
|
this.focusEditor();
|
|
8241
|
+
this.armEscapeHandoff();
|
|
5800
8242
|
return { consume: true };
|
|
5801
8243
|
}
|
|
5802
|
-
|
|
5803
|
-
|
|
5804
|
-
|
|
5805
|
-
}
|
|
5806
|
-
if (
|
|
5807
|
-
this.
|
|
8244
|
+
const now = this.deps.now();
|
|
8245
|
+
if (now < this.escapeQuietUntil) return { consume: true };
|
|
8246
|
+
if (this.editor.isShowingAutocomplete()) return void 0;
|
|
8247
|
+
if (this.agent.status !== "running") return { consume: true };
|
|
8248
|
+
if (now >= this.stopArmedUntil) {
|
|
8249
|
+
this.stopArmedUntil = now + this.showToast(stopTurnToast(this.turn));
|
|
5808
8250
|
return { consume: true };
|
|
5809
8251
|
}
|
|
8252
|
+
this.disarmStop();
|
|
8253
|
+
this.agent.cancel({ kind: "user" }, { keepInbox: true });
|
|
8254
|
+
const queued = this.agent.inbox.nextTurn.length + this.agent.inbox.nextStep.length;
|
|
8255
|
+
this.notice(queued === 0 ? "stopping the turn…" : `stopping the turn… ${String(queued)} queued message(s) stay queued`);
|
|
8256
|
+
return { consume: true };
|
|
8257
|
+
}
|
|
8258
|
+
/** Start the window in which an `Escape` reaching the editor does nothing at all. */
|
|
8259
|
+
armEscapeHandoff() {
|
|
8260
|
+
this.escapeQuietUntil = this.deps.now() + 750;
|
|
8261
|
+
}
|
|
8262
|
+
/** Disarm the stop and take the line that armed it down. */
|
|
8263
|
+
disarmStop() {
|
|
8264
|
+
this.stopArmedUntil = 0;
|
|
8265
|
+
this.hideToast();
|
|
5810
8266
|
}
|
|
5811
8267
|
/**
|
|
5812
|
-
*
|
|
5813
|
-
*
|
|
5814
|
-
*
|
|
5815
|
-
*
|
|
5816
|
-
*
|
|
5817
|
-
|
|
5818
|
-
|
|
5819
|
-
|
|
5820
|
-
|
|
5821
|
-
|
|
5822
|
-
|
|
5823
|
-
|
|
5824
|
-
|
|
5825
|
-
|
|
5826
|
-
|
|
5827
|
-
|
|
5828
|
-
|
|
5829
|
-
|
|
5830
|
-
|
|
5831
|
-
|
|
5832
|
-
|
|
8268
|
+
* Show one transient line over the conversation, replacing whichever line
|
|
8269
|
+
* is up.
|
|
8270
|
+
*
|
|
8271
|
+
* It normally costs the frame no rows: pi-tui composites an overlay into
|
|
8272
|
+
* the viewport after the tree rendered, so nothing already drawn moves and
|
|
8273
|
+
* the renderer's repaint boundary stays where it was. Where the renderer
|
|
8274
|
+
* can no longer repaint that part of the viewport the line is printed into
|
|
8275
|
+
* the conversation instead, which costs a row and keeps it: a line that says
|
|
8276
|
+
* which key stops a turn is worth more than its own disappearance.
|
|
8277
|
+
* @param text - what the line says.
|
|
8278
|
+
* @returns how long the line answers for, in milliseconds - the time it is
|
|
8279
|
+
* drawn when it floats, and the same window when the conversation kept it.
|
|
8280
|
+
*/
|
|
8281
|
+
showToast(text) {
|
|
8282
|
+
this.hideToast();
|
|
8283
|
+
this.tui.renderNow();
|
|
8284
|
+
if (!toastDrawable(this.viewportFloor)) {
|
|
8285
|
+
this.notice(text);
|
|
8286
|
+
return this.deps.toastMs;
|
|
8287
|
+
}
|
|
8288
|
+
const clock = new ToastClock({
|
|
8289
|
+
shownAt: this.deps.now(),
|
|
8290
|
+
holdMs: this.deps.toastMs,
|
|
8291
|
+
steps: this.deps.fadeSteps,
|
|
8292
|
+
stepMs: this.deps.fadeStepMs,
|
|
8293
|
+
fading: this.fading && this.fadeStyle.capability !== "none",
|
|
8294
|
+
now: () => this.deps.now()
|
|
8295
|
+
});
|
|
8296
|
+
const pane = new ToastPane(text, {
|
|
8297
|
+
palette: this.deps.palette,
|
|
8298
|
+
age: () => clock.age(),
|
|
8299
|
+
style: () => this.fadeStyle
|
|
8300
|
+
});
|
|
8301
|
+
this.toast = {
|
|
8302
|
+
handle: this.tui.showOverlay(pane, toastOverlay(text, () => toastDrawable(this.viewportFloor))),
|
|
8303
|
+
clock
|
|
8304
|
+
};
|
|
8305
|
+
this.motions.add(clock);
|
|
8306
|
+
this.updateFadeTicker();
|
|
8307
|
+
return clock.lifetimeMs();
|
|
8308
|
+
}
|
|
8309
|
+
/** Take the transient line down, if one is up. */
|
|
8310
|
+
hideToast() {
|
|
8311
|
+
const toast = this.toast;
|
|
8312
|
+
if (toast === void 0) return;
|
|
8313
|
+
toast.handle.hide();
|
|
8314
|
+
toast.clock.settle();
|
|
8315
|
+
this.toast = void 0;
|
|
8316
|
+
this.updateFadeTicker();
|
|
8317
|
+
}
|
|
8318
|
+
/**
|
|
8319
|
+
* Read the transcript full screen.
|
|
8320
|
+
*
|
|
8321
|
+
* The reader is an overlay, so it costs the conversation no line and the
|
|
8322
|
+
* renderer's repaint boundary stays where it was. The frame is settled
|
|
8323
|
+
* first, so the pane knows how much of the viewport the renderer can still
|
|
8324
|
+
* repaint before it decides how tall to draw.
|
|
8325
|
+
* @param at - the section to open on; the newest one when omitted.
|
|
8326
|
+
*/
|
|
8327
|
+
openReader(at) {
|
|
8328
|
+
const blocks = navigableBlocks(this.chat.children);
|
|
8329
|
+
const cursor = at ?? lastSection(blocks);
|
|
8330
|
+
if (cursor === void 0) {
|
|
8331
|
+
this.showToast(NOTHING_TO_READ_TOAST);
|
|
8332
|
+
return;
|
|
5833
8333
|
}
|
|
5834
|
-
|
|
5835
|
-
|
|
8334
|
+
this.finishReaderClose();
|
|
8335
|
+
this.tui.renderNow();
|
|
8336
|
+
this.readerOpening = this.startMotion(6);
|
|
8337
|
+
const pane = new ReaderPane({
|
|
8338
|
+
palette: this.deps.palette,
|
|
8339
|
+
blocks: () => navigableBlocks(this.chat.children),
|
|
8340
|
+
rows: () => Math.max(1, this.deps.terminal.rows - this.viewportFloor),
|
|
8341
|
+
minColumns: this.deps.readerMinColumns,
|
|
8342
|
+
cursor,
|
|
8343
|
+
reveal: () => this.readerReveal()
|
|
8344
|
+
});
|
|
8345
|
+
this.reader = {
|
|
8346
|
+
handle: this.tui.showOverlay(pane, READER_OVERLAY),
|
|
8347
|
+
pane
|
|
8348
|
+
};
|
|
8349
|
+
this.tui.requestRender();
|
|
8350
|
+
pane.settled.then((exit) => {
|
|
8351
|
+
this.closeReader(exit);
|
|
8352
|
+
});
|
|
5836
8353
|
}
|
|
5837
8354
|
/**
|
|
5838
|
-
*
|
|
5839
|
-
*
|
|
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.
|
|
5844
|
-
* @param data - the raw key bytes.
|
|
5845
|
-
* @returns the consume marker the input listener returns.
|
|
8355
|
+
* Take the reader down and put the keyboard where it left it.
|
|
8356
|
+
* @param exit - the section last read and the region that takes over.
|
|
5846
8357
|
*/
|
|
5847
|
-
|
|
5848
|
-
|
|
5849
|
-
|
|
5850
|
-
|
|
8358
|
+
closeReader(exit) {
|
|
8359
|
+
const open = this.reader;
|
|
8360
|
+
if (open === void 0) return;
|
|
8361
|
+
this.reader = void 0;
|
|
8362
|
+
this.readerOpening = void 0;
|
|
8363
|
+
this.cursor = exit.cursor;
|
|
8364
|
+
this.setFocus(exit.target);
|
|
8365
|
+
this.refreshSubagentPanel();
|
|
8366
|
+
this.armEscapeHandoff();
|
|
8367
|
+
const motion = this.startMotion(4);
|
|
8368
|
+
if (motion === void 0) open.handle.hide();
|
|
8369
|
+
else this.readerClosing = {
|
|
8370
|
+
handle: open.handle,
|
|
8371
|
+
motion
|
|
8372
|
+
};
|
|
8373
|
+
this.tui.requestRender();
|
|
8374
|
+
}
|
|
8375
|
+
/**
|
|
8376
|
+
* Take the reader down from outside, for a terminal that is stopping or a
|
|
8377
|
+
* conversation that is being replaced. The application's own record goes
|
|
8378
|
+
* first, so the pane's settlement moves no focus and puts no cursor of a
|
|
8379
|
+
* transcript that is gone back on the walk.
|
|
8380
|
+
* @returns whether a reader was open, so the caller can report that it came down.
|
|
8381
|
+
*/
|
|
8382
|
+
dropReader() {
|
|
8383
|
+
this.finishReaderClose();
|
|
8384
|
+
const open = this.reader;
|
|
8385
|
+
if (open === void 0) return false;
|
|
8386
|
+
this.reader = void 0;
|
|
8387
|
+
open.handle.hide();
|
|
8388
|
+
open.pane.withdraw();
|
|
8389
|
+
return true;
|
|
8390
|
+
}
|
|
8391
|
+
/**
|
|
8392
|
+
* Step the selection of the region that holds the keyboard.
|
|
8393
|
+
* @param axis - what the key steps along; each axis belongs to one region.
|
|
8394
|
+
* @param to - which way along it.
|
|
8395
|
+
*/
|
|
8396
|
+
moveBy(axis, to) {
|
|
8397
|
+
switch (axis) {
|
|
8398
|
+
case "section":
|
|
8399
|
+
case "block":
|
|
8400
|
+
case "turn":
|
|
8401
|
+
case "part":
|
|
8402
|
+
this.moveTranscript(axis, to);
|
|
8403
|
+
return;
|
|
8404
|
+
case "row":
|
|
8405
|
+
this.movePanelBy(to);
|
|
8406
|
+
return;
|
|
8407
|
+
case "segment":
|
|
8408
|
+
this.moveStatusBar(to);
|
|
8409
|
+
return;
|
|
8410
|
+
/* v8 ignore next 2 -- closed-union exhaustiveness guard */
|
|
8411
|
+
default: assertNever(axis, "tui move axis");
|
|
5851
8412
|
}
|
|
8413
|
+
}
|
|
8414
|
+
/**
|
|
8415
|
+
* Walk the transcript focus along one axis. Past the newest section the
|
|
8416
|
+
* walk continues in the editor, which is drawn directly under the
|
|
8417
|
+
* conversation; the oldest section is the end of the walk, and a part,
|
|
8418
|
+
* block, or turn step stays in the transcript at both ends.
|
|
8419
|
+
* @param axis - what the key steps along.
|
|
8420
|
+
* @param to - which way along it.
|
|
8421
|
+
*/
|
|
8422
|
+
moveTranscript(axis, to) {
|
|
5852
8423
|
const section = this.focusedSection();
|
|
5853
8424
|
/* v8 ignore next 5 -- only a session change empties the transcript, and it hands the keyboard back first */
|
|
5854
8425
|
if (section === void 0) {
|
|
5855
8426
|
this.focusEditor();
|
|
5856
|
-
return
|
|
8427
|
+
return;
|
|
5857
8428
|
}
|
|
5858
8429
|
const { cursor, blocks } = section;
|
|
5859
|
-
|
|
5860
|
-
|
|
5861
|
-
|
|
5862
|
-
|
|
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);
|
|
5867
|
-
return { consume: true };
|
|
5868
|
-
}
|
|
5869
|
-
if (matchesKey(data, "left")) {
|
|
5870
|
-
this.moveCursor(movePart(cursor, -1, blocks));
|
|
5871
|
-
return { consume: true };
|
|
5872
|
-
}
|
|
5873
|
-
if (matchesKey(data, "right")) {
|
|
5874
|
-
this.moveCursor(movePart(cursor, 1, blocks));
|
|
5875
|
-
return { consume: true };
|
|
5876
|
-
}
|
|
5877
|
-
if (matchesKey(data, "enter")) this.openSection(section);
|
|
5878
|
-
return { consume: true };
|
|
8430
|
+
const next = moveTranscriptCursor(cursor, axis, to, blocks);
|
|
8431
|
+
const held = next.block === cursor.block && next.part === cursor.part;
|
|
8432
|
+
if (axis === "section" && to === "next" && held) this.focusEditor();
|
|
8433
|
+
else this.moveCursor(next);
|
|
5879
8434
|
}
|
|
5880
8435
|
/**
|
|
5881
|
-
*
|
|
5882
|
-
*
|
|
5883
|
-
*
|
|
5884
|
-
|
|
5885
|
-
|
|
5886
|
-
|
|
5887
|
-
|
|
5888
|
-
|
|
5889
|
-
|
|
5890
|
-
|
|
5891
|
-
|
|
5892
|
-
|
|
5893
|
-
|
|
8436
|
+
* Walk the subagent panel's selection. Above the first row the walk
|
|
8437
|
+
* continues in the editor, below the last one at the status bar.
|
|
8438
|
+
* @param to - which way along the drawn rows.
|
|
8439
|
+
*/
|
|
8440
|
+
movePanelBy(to) {
|
|
8441
|
+
const rows = this.panelView.rows;
|
|
8442
|
+
const index = this.panelSelectionIndex(rows);
|
|
8443
|
+
switch (to) {
|
|
8444
|
+
case "previous":
|
|
8445
|
+
if (index === 0) this.focusEditor();
|
|
8446
|
+
else this.selectPanelRow(index - 1);
|
|
8447
|
+
return;
|
|
8448
|
+
case "next":
|
|
8449
|
+
if (index === rows.length - 1) this.focusBar();
|
|
8450
|
+
else this.selectPanelRow(index + 1);
|
|
8451
|
+
return;
|
|
8452
|
+
case "first":
|
|
8453
|
+
this.selectPanelRow(0);
|
|
8454
|
+
return;
|
|
8455
|
+
case "last":
|
|
8456
|
+
this.selectPanelRow(rows.length - 1);
|
|
8457
|
+
return;
|
|
8458
|
+
/* v8 ignore next 2 -- closed-union exhaustiveness guard */
|
|
8459
|
+
default: assertNever(to, "tui move target");
|
|
5894
8460
|
}
|
|
5895
|
-
|
|
5896
|
-
|
|
5897
|
-
|
|
5898
|
-
|
|
8461
|
+
}
|
|
8462
|
+
/** Open what the focused region's `Enter` leads to. */
|
|
8463
|
+
openFocused() {
|
|
8464
|
+
if (this.focus === "panel") {
|
|
8465
|
+
this.navigate("subagent details", () => this.openPanelRow());
|
|
8466
|
+
return;
|
|
5899
8467
|
}
|
|
5900
|
-
if (
|
|
5901
|
-
|
|
8468
|
+
if (this.focus === "bar") {
|
|
8469
|
+
this.openSegment(this.barSelection);
|
|
8470
|
+
return;
|
|
8471
|
+
}
|
|
8472
|
+
const section = this.focusedSection();
|
|
8473
|
+
/* v8 ignore next -- the transcript answers Enter only while it holds a section */
|
|
8474
|
+
if (section === void 0) return;
|
|
8475
|
+
this.openReader(section.cursor);
|
|
5902
8476
|
}
|
|
5903
8477
|
/**
|
|
5904
8478
|
* Open one page a docked region's `Enter` leads to, reporting a failure as
|
|
@@ -5928,33 +8502,41 @@ var TuiApp = class {
|
|
|
5928
8502
|
this.navigate("/todos", () => this.browseTodos());
|
|
5929
8503
|
}
|
|
5930
8504
|
/**
|
|
5931
|
-
* Move the bar's selection
|
|
5932
|
-
*
|
|
8505
|
+
* Move the bar's selection: one segment either way wrapping at both ends,
|
|
8506
|
+
* or straight to an end.
|
|
8507
|
+
* @param to - which way along the drawn segments.
|
|
5933
8508
|
*/
|
|
5934
|
-
moveStatusBar(
|
|
8509
|
+
moveStatusBar(to) {
|
|
5935
8510
|
const count = this.segments.length;
|
|
5936
|
-
const next = this.segments[(footerSelectionIndex(this.segments, this.barSelection)
|
|
8511
|
+
const next = this.segments[barTarget(to, footerSelectionIndex(this.segments, this.barSelection), count)];
|
|
5937
8512
|
/* v8 ignore next -- the wrapped index stays inside the bar's own segments */
|
|
5938
8513
|
if (next !== void 0) this.barSelection = next.id;
|
|
8514
|
+
this.startChrome("selection", 4);
|
|
5939
8515
|
this.refreshFooter();
|
|
5940
8516
|
}
|
|
5941
8517
|
/**
|
|
5942
|
-
*
|
|
5943
|
-
*
|
|
5944
|
-
*
|
|
5945
|
-
* @param step - 1 for the next row, -1 for the previous one.
|
|
8518
|
+
* Put the panel's selection on one of its drawn rows. The rows behind a
|
|
8519
|
+
* `+<n> more` row are not selectable; `/subagents` walks the complete tree.
|
|
8520
|
+
* @param index - the row the selection lands on.
|
|
5946
8521
|
*/
|
|
5947
|
-
|
|
5948
|
-
|
|
5949
|
-
const next = rows[Math.max(0, Math.min(this.panelSelectionIndex(rows) + step, rows.length - 1))];
|
|
5950
|
-
/* v8 ignore next -- the clamped index stays inside the panel's own rows */
|
|
5951
|
-
if (next !== void 0) this.panelSelection = next.id;
|
|
8522
|
+
selectPanelRow(index) {
|
|
8523
|
+
this.panelSelection = this.panelView.rows[index]?.id;
|
|
5952
8524
|
this.refreshSubagentPanel();
|
|
5953
8525
|
}
|
|
5954
|
-
/**
|
|
8526
|
+
/**
|
|
8527
|
+
* Give the keyboard to the status bar, starting at its first segment. The
|
|
8528
|
+
* bar is redrawn even when it already held the keyboard, because the
|
|
8529
|
+
* selection this reset would otherwise disagree with the segment still
|
|
8530
|
+
* drawn as selected, and `Enter` would open the other one.
|
|
8531
|
+
*/
|
|
5955
8532
|
focusBar() {
|
|
5956
8533
|
this.barSelection = FIRST_FOOTER_SEGMENT;
|
|
5957
|
-
this.
|
|
8534
|
+
if (this.focus !== "bar") {
|
|
8535
|
+
this.focusRegion("bar");
|
|
8536
|
+
return;
|
|
8537
|
+
}
|
|
8538
|
+
this.startChrome("selection", 4);
|
|
8539
|
+
this.refreshFooter();
|
|
5958
8540
|
}
|
|
5959
8541
|
/**
|
|
5960
8542
|
* Give the keyboard to the subagent panel on one of its rows.
|
|
@@ -5973,13 +8555,33 @@ var TuiApp = class {
|
|
|
5973
8555
|
else this.focusBar();
|
|
5974
8556
|
}
|
|
5975
8557
|
/**
|
|
5976
|
-
* Give the keyboard to the
|
|
5977
|
-
*
|
|
8558
|
+
* Give the keyboard to the region above the status bar: the subagent
|
|
8559
|
+
* panel's last row while the panel is drawn, and the editor otherwise,
|
|
8560
|
+
* which is what the bar sits under once no panel is between them.
|
|
8561
|
+
*/
|
|
8562
|
+
focusAboveBar() {
|
|
8563
|
+
if (this.panelView.rows.length > 0) this.focusPanel(this.panelView.rows.length - 1);
|
|
8564
|
+
else this.focusEditor();
|
|
8565
|
+
}
|
|
8566
|
+
/**
|
|
8567
|
+
* The section the conversation takes the keyboard on: the one it was left
|
|
8568
|
+
* on, settled against the blocks drawn now, and the newest section when no
|
|
8569
|
+
* remembered cursor survives — which is every first entry, because a
|
|
8570
|
+
* session switch forgets the cursor with the blocks it named.
|
|
8571
|
+
* @returns the cursor, or undefined when the transcript has nothing to read.
|
|
8572
|
+
*/
|
|
8573
|
+
transcriptEntry() {
|
|
8574
|
+
const blocks = navigableBlocks(this.chat.children);
|
|
8575
|
+
return (this.cursor === void 0 ? void 0 : clampCursor(this.cursor, blocks)) ?? lastSection(blocks);
|
|
8576
|
+
}
|
|
8577
|
+
/**
|
|
8578
|
+
* Give the keyboard to the transcript, where it left off. A session with
|
|
8579
|
+
* nothing to read yet says so and leaves the keyboard where it was.
|
|
5978
8580
|
*/
|
|
5979
8581
|
focusTranscript() {
|
|
5980
|
-
const cursor =
|
|
8582
|
+
const cursor = this.transcriptEntry();
|
|
5981
8583
|
if (cursor === void 0) {
|
|
5982
|
-
this.
|
|
8584
|
+
this.showToast(NOTHING_TO_READ_TOAST);
|
|
5983
8585
|
return;
|
|
5984
8586
|
}
|
|
5985
8587
|
this.cursor = cursor;
|
|
@@ -5987,19 +8589,48 @@ var TuiApp = class {
|
|
|
5987
8589
|
this.tui.requestRender();
|
|
5988
8590
|
}
|
|
5989
8591
|
/**
|
|
8592
|
+
* The regions drawn around the editor right now, in stack order: the
|
|
8593
|
+
* conversation while it holds a section, the subagent panel while it has
|
|
8594
|
+
* rows, and the status bar, which is always drawn.
|
|
8595
|
+
* @returns the regions `Tab` walks.
|
|
8596
|
+
*/
|
|
8597
|
+
drawnRegions() {
|
|
8598
|
+
const drawn = [];
|
|
8599
|
+
if (this.transcriptEntry() !== void 0) drawn.push("transcript");
|
|
8600
|
+
if (this.panelView.rows.length > 0) drawn.push("panel");
|
|
8601
|
+
drawn.push("bar");
|
|
8602
|
+
return drawn;
|
|
8603
|
+
}
|
|
8604
|
+
/**
|
|
8605
|
+
* Give the keyboard to the next drawn region, wrapping at both ends. The
|
|
8606
|
+
* editor is not in the walk: `Esc` and the printable keys return there from
|
|
8607
|
+
* anywhere.
|
|
8608
|
+
* @param step - 1 for the next region, -1 for the previous one.
|
|
8609
|
+
*/
|
|
8610
|
+
cycleRegion(step) {
|
|
8611
|
+
const drawn = this.drawnRegions();
|
|
8612
|
+
const next = drawn[(drawn.findIndex((region) => region === this.focus) + step + drawn.length) % drawn.length];
|
|
8613
|
+
/* v8 ignore next -- the status bar is always drawn, so the wrapped index names a region */
|
|
8614
|
+
if (next === void 0) return;
|
|
8615
|
+
if (next === "transcript") this.focusTranscript();
|
|
8616
|
+
else if (next === "panel") this.focusPanel(this.panelSelectionIndex(this.panelView.rows));
|
|
8617
|
+
else this.focusBar();
|
|
8618
|
+
}
|
|
8619
|
+
/**
|
|
5990
8620
|
* Put the transcript focus on another section.
|
|
5991
8621
|
* @param cursor - where the focus moves to.
|
|
5992
8622
|
*/
|
|
5993
8623
|
moveCursor(cursor) {
|
|
5994
8624
|
this.cursor = cursor;
|
|
8625
|
+
this.startChrome("selection", 3);
|
|
5995
8626
|
this.tui.requestRender();
|
|
5996
8627
|
}
|
|
5997
8628
|
/**
|
|
5998
8629
|
* Read the remembered cursor against the transcript as it is drawn right
|
|
5999
|
-
* now
|
|
6000
|
-
*
|
|
6001
|
-
*
|
|
6002
|
-
*
|
|
8630
|
+
* now, which grew parts and blocks since the cursor was taken. The cursor
|
|
8631
|
+
* itself is left alone, so a page and a trip through the editor come back
|
|
8632
|
+
* to the same section; {@link TuiApp.moveCursor} moves it and
|
|
8633
|
+
* {@link TuiApp.bind} drops it with the session it belonged to.
|
|
6003
8634
|
* @returns the section the cursor names, or undefined when the transcript
|
|
6004
8635
|
* has nothing to hold it.
|
|
6005
8636
|
*/
|
|
@@ -6019,18 +8650,6 @@ var TuiApp = class {
|
|
|
6019
8650
|
};
|
|
6020
8651
|
}
|
|
6021
8652
|
/**
|
|
6022
|
-
* Open the focused section as a read-only page and come back to it.
|
|
6023
|
-
* @param section - the focused section.
|
|
6024
|
-
*/
|
|
6025
|
-
openSection(section) {
|
|
6026
|
-
const { cursor, blocks } = section;
|
|
6027
|
-
const prompt = new DetailPrompt(this.deps.palette, sectionHeading(cursor, blocks), section.part.rows);
|
|
6028
|
-
this.navigate("section", async () => {
|
|
6029
|
-
await this.showModal(prompt);
|
|
6030
|
-
this.focusRegion("transcript");
|
|
6031
|
-
});
|
|
6032
|
-
}
|
|
6033
|
-
/**
|
|
6034
8653
|
* The focused section as the docked inspector draws it.
|
|
6035
8654
|
* @returns the view, or undefined while the keyboard is not in the
|
|
6036
8655
|
* transcript, which draws no inspector at all.
|
|
@@ -6044,7 +8663,7 @@ var TuiApp = class {
|
|
|
6044
8663
|
parts: partLabels(cursor, blocks),
|
|
6045
8664
|
rows: section.part.rows,
|
|
6046
8665
|
highlighted: this.highlighted !== void 0,
|
|
6047
|
-
|
|
8666
|
+
level: this.frameLift()
|
|
6048
8667
|
};
|
|
6049
8668
|
}
|
|
6050
8669
|
/** Hand the keyboard back to the editor; a no-op while the editor already has it. */
|
|
@@ -6064,16 +8683,55 @@ var TuiApp = class {
|
|
|
6064
8683
|
/**
|
|
6065
8684
|
* Give the keyboard to `region` and redraw the bar. The caller redraws the
|
|
6066
8685
|
* panel; the panel's own refresh calls this when its last row leaves.
|
|
8686
|
+
*
|
|
8687
|
+
* A region taking the keyboard lifts its own chrome for a moment, which is
|
|
8688
|
+
* what makes the landing visible; the editor taking it back settles
|
|
8689
|
+
* whatever was still moving, because nothing that motion lifted is drawn
|
|
8690
|
+
* any more.
|
|
6067
8691
|
* @param region - the region that takes the keyboard.
|
|
6068
8692
|
*/
|
|
6069
8693
|
setFocus(region) {
|
|
8694
|
+
this.finishReaderClose();
|
|
8695
|
+
if (region === "editor") this.chrome = void 0;
|
|
8696
|
+
else this.startChrome("landing", 6);
|
|
6070
8697
|
this.focus = region;
|
|
6071
|
-
this.tui.setFocus(region === "editor" ? this.editor : null);
|
|
8698
|
+
if (this.reader === void 0) this.tui.setFocus(region === "editor" ? this.editor : null);
|
|
6072
8699
|
this.refreshFooter();
|
|
6073
8700
|
}
|
|
6074
|
-
|
|
8701
|
+
/**
|
|
8702
|
+
* Answer `Ctrl+O` and `/tools`: fold or unfold every block that folds, tool
|
|
8703
|
+
* cards and context rows alike. The setting outlives the blocks on screen,
|
|
8704
|
+
* so a card or an injection that arrives later opens with the rest.
|
|
8705
|
+
*
|
|
8706
|
+
* On a transcript taller than the terminal this rewrites lines the renderer
|
|
8707
|
+
* can no longer repaint and pi-tui redraws the screen in full. It is the one
|
|
8708
|
+
* key that does; `Space` turns the held block alone, inside the window.
|
|
8709
|
+
*/
|
|
8710
|
+
toggleFolding() {
|
|
6075
8711
|
this.toolsExpanded = !this.toolsExpanded;
|
|
6076
|
-
for (const
|
|
8712
|
+
for (const child of this.chat.children) if (isFoldable(child)) child.setExpanded(this.toolsExpanded);
|
|
8713
|
+
this.tui.requestRender();
|
|
8714
|
+
}
|
|
8715
|
+
/**
|
|
8716
|
+
* Answer `Space`: fold or unfold the block the transcript focus holds.
|
|
8717
|
+
*
|
|
8718
|
+
* Rewriting a block in place is legal only while the renderer can still
|
|
8719
|
+
* repaint its first line, and the frame's own guard is what knows that: the
|
|
8720
|
+
* render settles the frame, and the mark it leaves names the one block this
|
|
8721
|
+
* key may rewrite. A block above that window keeps what it draws, and the
|
|
8722
|
+
* line names the key that opens every block at once instead.
|
|
8723
|
+
*/
|
|
8724
|
+
foldFocused() {
|
|
8725
|
+
const section = this.focusedSection();
|
|
8726
|
+
const block = section?.block;
|
|
8727
|
+
if (section === void 0 || block === void 0 || !isFoldable(block)) return;
|
|
8728
|
+
this.tui.renderNow();
|
|
8729
|
+
if (this.highlighted?.block !== block) {
|
|
8730
|
+
this.openReader(section.cursor);
|
|
8731
|
+
this.showToast(ABOVE_WINDOW_TOAST);
|
|
8732
|
+
return;
|
|
8733
|
+
}
|
|
8734
|
+
block.setExpanded(!block.isExpanded());
|
|
6077
8735
|
this.tui.requestRender();
|
|
6078
8736
|
}
|
|
6079
8737
|
/**
|
|
@@ -6136,7 +8794,10 @@ var TuiApp = class {
|
|
|
6136
8794
|
this.stop();
|
|
6137
8795
|
return;
|
|
6138
8796
|
case "tools":
|
|
6139
|
-
this.
|
|
8797
|
+
this.toggleFolding();
|
|
8798
|
+
return;
|
|
8799
|
+
case "turns":
|
|
8800
|
+
this.openReader();
|
|
6140
8801
|
return;
|
|
6141
8802
|
case "model":
|
|
6142
8803
|
await this.chooseModel(argument);
|
|
@@ -6219,24 +8880,19 @@ var TuiApp = class {
|
|
|
6219
8880
|
default: await this.runSharedCommand(line, name);
|
|
6220
8881
|
}
|
|
6221
8882
|
}
|
|
8883
|
+
/**
|
|
8884
|
+
* Print the commands and the keys: one row per focus state, the keys it
|
|
8885
|
+
* answers beside its name. Every legend is the one its own surface draws,
|
|
8886
|
+
* read from the module that owns it, so this list cannot name a key the
|
|
8887
|
+
* screen names differently.
|
|
8888
|
+
*/
|
|
6222
8889
|
showHelp() {
|
|
6223
8890
|
const palette = this.deps.palette;
|
|
6224
8891
|
const rows = this.completableCommands().map((command) => `/${command.name.padEnd(12)} ${palette.dim(command.description)}`);
|
|
6225
|
-
const keys = [
|
|
6226
|
-
"Enter sends · Shift+Enter inserts a newline · Up/Down recall history",
|
|
6227
|
-
"While a turn runs: Enter queues for the next turn · Ctrl+S steers the running turn",
|
|
6228
|
-
"@ completes paths and sessions (workspace, ../, ~/, absolute) · / completes commands",
|
|
6229
|
-
"Esc stops the running turn · Ctrl+O expands or collapses tool output",
|
|
6230
|
-
"Shift+Tab cycles the current model's reasoning effort for the next request",
|
|
6231
|
-
"Shift+Up focuses the transcript, Shift+Down the subagent panel or the status bar",
|
|
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)",
|
|
6233
|
-
"Enter opens the focused section or segment, Esc returns to the input",
|
|
6234
|
-
"Ctrl+C clears the input (twice quits) · Ctrl+D on an empty input quits"
|
|
6235
|
-
];
|
|
6236
8892
|
this.chat.addChild(new Text([
|
|
6237
8893
|
...rows,
|
|
6238
8894
|
"",
|
|
6239
|
-
...
|
|
8895
|
+
...helpKeyLines().map(palette.dim)
|
|
6240
8896
|
].join("\n"), 0, 1));
|
|
6241
8897
|
this.tui.requestRender();
|
|
6242
8898
|
}
|
|
@@ -6780,6 +9436,92 @@ var TuiApp = class {
|
|
|
6780
9436
|
this.updateFadeTicker();
|
|
6781
9437
|
}
|
|
6782
9438
|
/**
|
|
9439
|
+
* Start one motion on the application's own clock and tick.
|
|
9440
|
+
*
|
|
9441
|
+
* A terminal that draws no ramp at all - reduced motion, a disabled
|
|
9442
|
+
* palette, no color - runs no motion either, and every call site draws its
|
|
9443
|
+
* settled rendering instead, so nothing here is on the path of a terminal
|
|
9444
|
+
* that asked for none.
|
|
9445
|
+
* @param ticks - how many fade periods the motion lasts.
|
|
9446
|
+
* @returns the motion, or undefined on a terminal that runs none.
|
|
9447
|
+
*/
|
|
9448
|
+
startMotion(ticks) {
|
|
9449
|
+
if (!this.fading) return void 0;
|
|
9450
|
+
const motion = new Motion({
|
|
9451
|
+
startedAt: this.deps.now(),
|
|
9452
|
+
ticks,
|
|
9453
|
+
stepMs: this.deps.fadeStepMs,
|
|
9454
|
+
now: () => this.deps.now()
|
|
9455
|
+
});
|
|
9456
|
+
this.motions.add(motion);
|
|
9457
|
+
this.updateFadeTicker();
|
|
9458
|
+
return motion;
|
|
9459
|
+
}
|
|
9460
|
+
/**
|
|
9461
|
+
* Lift the chrome of the region that holds the keyboard. One motion runs at
|
|
9462
|
+
* a time, because one region holds the keyboard at a time: a step replaces
|
|
9463
|
+
* the landing that brought the keyboard here, which settles the frame back
|
|
9464
|
+
* as soon as the walk goes on.
|
|
9465
|
+
* @param scope - how much of the surface the motion lifts.
|
|
9466
|
+
* @param ticks - how many fade periods it lasts.
|
|
9467
|
+
*/
|
|
9468
|
+
startChrome(scope, ticks) {
|
|
9469
|
+
const motion = this.startMotion(ticks);
|
|
9470
|
+
this.chrome = motion === void 0 ? void 0 : {
|
|
9471
|
+
motion,
|
|
9472
|
+
scope
|
|
9473
|
+
};
|
|
9474
|
+
}
|
|
9475
|
+
/**
|
|
9476
|
+
* How far above its settled drawing the focused surface's own frame is
|
|
9477
|
+
* drawn right now.
|
|
9478
|
+
* @returns the level, and the settled one for everything but a landing.
|
|
9479
|
+
*/
|
|
9480
|
+
frameLift() {
|
|
9481
|
+
return this.chrome?.scope === "landing" ? this.chrome.motion.level() : 0;
|
|
9482
|
+
}
|
|
9483
|
+
/**
|
|
9484
|
+
* How far above its settled drawing the mark the focused region holds is
|
|
9485
|
+
* drawn right now.
|
|
9486
|
+
* @returns the level, and the settled one while nothing moves.
|
|
9487
|
+
*/
|
|
9488
|
+
markLift() {
|
|
9489
|
+
return this.chrome?.motion.level() ?? 0;
|
|
9490
|
+
}
|
|
9491
|
+
/**
|
|
9492
|
+
* The lift the subagent panel's selected row is drawn with. The panel's
|
|
9493
|
+
* text is built when something changes it rather than once per frame, so
|
|
9494
|
+
* this is also what the fade tick compares against to know it must build it
|
|
9495
|
+
* again.
|
|
9496
|
+
* @returns the level, and the settled one whenever the panel does not hold
|
|
9497
|
+
* the keyboard.
|
|
9498
|
+
*/
|
|
9499
|
+
panelLiftNow() {
|
|
9500
|
+
return this.focus === "panel" ? this.markLift() : 0;
|
|
9501
|
+
}
|
|
9502
|
+
/**
|
|
9503
|
+
* How much of its height the reader draws right now.
|
|
9504
|
+
* @returns the share of the pane's rows: growing while it opens, shrinking
|
|
9505
|
+
* while it comes down, and 1 for a reader that is simply up.
|
|
9506
|
+
*/
|
|
9507
|
+
readerReveal() {
|
|
9508
|
+
const closing = this.readerClosing;
|
|
9509
|
+
if (closing !== void 0) return 1 - closing.motion.progress();
|
|
9510
|
+
return this.readerOpening?.progress() ?? 1;
|
|
9511
|
+
}
|
|
9512
|
+
/**
|
|
9513
|
+
* Take a shrinking reader off the screen now, for anything that needs the
|
|
9514
|
+
* viewport back before the motion settles: another overlay, a prompt, a
|
|
9515
|
+
* session change, or the next key press - pi-tui would hand the key stream
|
|
9516
|
+
* back to an overlay it still holds a focus restore for.
|
|
9517
|
+
*/
|
|
9518
|
+
finishReaderClose() {
|
|
9519
|
+
const closing = this.readerClosing;
|
|
9520
|
+
if (closing === void 0) return;
|
|
9521
|
+
this.readerClosing = void 0;
|
|
9522
|
+
closing.handle.hide();
|
|
9523
|
+
}
|
|
9524
|
+
/**
|
|
6783
9525
|
* Arm the fade tick while streamed text or a card still draws below the last
|
|
6784
9526
|
* brightness level and disarm it otherwise, so a session that is not
|
|
6785
9527
|
* streaming runs no fade timer. Exactly one runs at a time, and a stopped
|
|
@@ -6803,7 +9545,7 @@ var TuiApp = class {
|
|
|
6803
9545
|
* @returns true while a tail or a card fade keeps changing what is drawn.
|
|
6804
9546
|
*/
|
|
6805
9547
|
fadesMoving() {
|
|
6806
|
-
return this.textTail?.needsRepaint() === true || this.reasoningTail?.needsRepaint() === true || this.blockFades.needsRepaint();
|
|
9548
|
+
return this.textTail?.needsRepaint() === true || this.reasoningTail?.needsRepaint() === true || this.blockFades.needsRepaint() || this.motions.needsRepaint();
|
|
6807
9549
|
}
|
|
6808
9550
|
/**
|
|
6809
9551
|
* Apply everything the frame's geometry decides, on the frame that was just
|
|
@@ -6817,14 +9559,19 @@ var TuiApp = class {
|
|
|
6817
9559
|
* unmarked, and the inspector reports that instead.
|
|
6818
9560
|
* @param viewportTop - the frame's first repaintable line.
|
|
6819
9561
|
* @param width - the width it was built at.
|
|
9562
|
+
* @param frameLines - how many lines the frame has, which is what places
|
|
9563
|
+
* an overlay: pi-tui composites one into the frame's last `rows` lines.
|
|
6820
9564
|
* @returns whether anything changed a line, so the frame is built again
|
|
6821
9565
|
* before it is written.
|
|
6822
9566
|
*/
|
|
6823
|
-
settleFrame(viewportTop, width) {
|
|
9567
|
+
settleFrame(viewportTop, width, frameLines) {
|
|
9568
|
+
const rows = this.deps.terminal.rows;
|
|
9569
|
+
this.viewportFloor = repaintFloor(Math.max(frameLines, rows) - rows, viewportTop);
|
|
6824
9570
|
const section = this.focusedSection();
|
|
6825
9571
|
const wanted = section !== void 0 && this.focus === "transcript" ? {
|
|
6826
9572
|
block: section.block,
|
|
6827
|
-
part: section.cursor.part
|
|
9573
|
+
part: section.cursor.part,
|
|
9574
|
+
level: this.markLift()
|
|
6828
9575
|
} : void 0;
|
|
6829
9576
|
const fades = this.fadesMoving();
|
|
6830
9577
|
if (!fades && wanted === void 0 && this.highlighted === void 0) return false;
|
|
@@ -6840,9 +9587,9 @@ var TuiApp = class {
|
|
|
6840
9587
|
}
|
|
6841
9588
|
const target = wantedStart !== void 0 && repaintFloor(wantedStart, viewportTop) === 0 ? wanted : void 0;
|
|
6842
9589
|
const current = this.highlighted;
|
|
6843
|
-
if (current?.block === target?.block && current?.part === target?.part) return changed;
|
|
9590
|
+
if (current?.block === target?.block && current?.part === target?.part && current?.level === target?.level) return changed;
|
|
6844
9591
|
current?.block.setHighlight(void 0);
|
|
6845
|
-
target?.block.setHighlight(target.part);
|
|
9592
|
+
target?.block.setHighlight(target.part, target.level);
|
|
6846
9593
|
this.highlighted = target;
|
|
6847
9594
|
return true;
|
|
6848
9595
|
}
|
|
@@ -6856,6 +9603,10 @@ var TuiApp = class {
|
|
|
6856
9603
|
this.textTail?.tick();
|
|
6857
9604
|
this.reasoningTail?.tick();
|
|
6858
9605
|
this.blockFades.tick();
|
|
9606
|
+
if (this.toast?.clock.expired() === true) this.hideToast();
|
|
9607
|
+
if (this.readerClosing?.motion.needsRepaint() === false) this.finishReaderClose();
|
|
9608
|
+
if (this.panelLift !== this.panelLiftNow()) this.refreshSubagentPanel();
|
|
9609
|
+
this.motions.tick();
|
|
6859
9610
|
this.tui.requestRender();
|
|
6860
9611
|
this.updateFadeTicker();
|
|
6861
9612
|
}
|
|
@@ -7022,7 +9773,7 @@ var TuiApp = class {
|
|
|
7022
9773
|
}
|
|
7023
9774
|
const view = injectedContextView(source, message.content);
|
|
7024
9775
|
if (view === void 0) return;
|
|
7025
|
-
this.
|
|
9776
|
+
this.addContext(view.title, view.parts, this.turn);
|
|
7026
9777
|
}
|
|
7027
9778
|
/**
|
|
7028
9779
|
* Draw one nonempty system prompt as a navigable context block.
|
|
@@ -7032,7 +9783,19 @@ var TuiApp = class {
|
|
|
7032
9783
|
const view = systemPromptView(contentText(data.message.content), this.sawSystemPrompt);
|
|
7033
9784
|
if (view === void 0) return;
|
|
7034
9785
|
this.sawSystemPrompt = true;
|
|
7035
|
-
this.
|
|
9786
|
+
this.addContext(view.title, view.parts, data.turn);
|
|
9787
|
+
}
|
|
9788
|
+
/**
|
|
9789
|
+
* Append one context block, folded as every other foldable block is drawn
|
|
9790
|
+
* right now.
|
|
9791
|
+
* @param title - form and producer, a notice summary, or `system prompt`.
|
|
9792
|
+
* @param parts - the model-facing rows, one part per contribution.
|
|
9793
|
+
* @param turn - the turn the message was appended in.
|
|
9794
|
+
*/
|
|
9795
|
+
addContext(title, parts, turn) {
|
|
9796
|
+
const block = new ContextBlock(this.theme, title, parts, turn);
|
|
9797
|
+
block.setExpanded(this.toolsExpanded);
|
|
9798
|
+
this.chat.addChild(block);
|
|
7036
9799
|
}
|
|
7037
9800
|
presentCall(name, args) {
|
|
7038
9801
|
const definition = this.deps.ctx.get("tools")?.get(name, this.agent);
|
|
@@ -7138,7 +9901,10 @@ const Config = z.object({
|
|
|
7138
9901
|
prompt: z.string(),
|
|
7139
9902
|
resume: z.string(),
|
|
7140
9903
|
toolPreviewLines: z.natural().min(1).default(8),
|
|
9904
|
+
contextPreviewLines: z.natural().min(1).default(4),
|
|
7141
9905
|
focusPreviewLines: z.natural().min(1).default(12),
|
|
9906
|
+
readerMinColumns: z.natural().min(40).default(80),
|
|
9907
|
+
toastMs: z.natural().min(500).default(TOAST_MS),
|
|
7142
9908
|
liveRefreshMs: z.natural().min(100).default(1e3),
|
|
7143
9909
|
streamFadeSteps: z.natural().min(2).default(8),
|
|
7144
9910
|
streamFadeStepMs: z.natural().min(16).default(33),
|
|
@@ -7314,7 +10080,10 @@ async function run(ctx, config, host) {
|
|
|
7314
10080
|
terminal: host.createTerminal(),
|
|
7315
10081
|
palette: createPalette(host.color),
|
|
7316
10082
|
toolPreviewLines: config.toolPreviewLines,
|
|
10083
|
+
contextPreviewLines: config.contextPreviewLines,
|
|
7317
10084
|
focusPreviewLines: config.focusPreviewLines,
|
|
10085
|
+
readerMinColumns: config.readerMinColumns,
|
|
10086
|
+
toastMs: config.toastMs,
|
|
7318
10087
|
liveRefreshMs: config.liveRefreshMs,
|
|
7319
10088
|
fadeSteps: config.streamFadeSteps,
|
|
7320
10089
|
fadeStepMs: config.streamFadeStepMs,
|