@songtonyli/dsh-cli 0.1.59 → 0.1.61
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/bin/dsh.mjs +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-primitives/package.json +2 -2
- package/node_modules/@deepseek-ai/dsh-client-ui-sidebar/lib/client.js +1 -1
- package/node_modules/@deepseek-ai/dsh-experimental-auto-review/README.i18n.yaml +4 -4
- package/node_modules/@deepseek-ai/dsh-experimental-auto-review/README.md +2 -2
- package/node_modules/@deepseek-ai/dsh-experimental-auto-review/README.zh.md +2 -2
- package/node_modules/@deepseek-ai/dsh-experimental-auto-review/lib/index.js +33 -8
- package/node_modules/@deepseek-ai/dsh-sandbox/lib/index.js +13 -2
- package/node_modules/@deepseek-ai/dsh-sandbox-apple-container/README.i18n.yaml +2 -2
- package/node_modules/@deepseek-ai/dsh-sandbox-apple-container/README.md +2 -2
- package/node_modules/@deepseek-ai/dsh-sandbox-apple-container/README.zh.md +2 -2
- package/node_modules/@deepseek-ai/dsh-sandbox-apple-container/lib/index.js +1 -1
- package/node_modules/@deepseek-ai/dsh-tool-fs/README.i18n.yaml +2 -2
- package/node_modules/@deepseek-ai/dsh-tool-fs/README.md +1 -1
- package/node_modules/@deepseek-ai/dsh-tool-fs/README.zh.md +1 -1
- package/node_modules/@deepseek-ai/dsh-tool-fs/lib/index.js +108 -13
- package/node_modules/@deepseek-ai/dsh-tui-app/README.i18n.yaml +8 -8
- package/node_modules/@deepseek-ai/dsh-tui-app/README.md +11 -8
- package/node_modules/@deepseek-ai/dsh-tui-app/README.zh.md +11 -8
- package/node_modules/@deepseek-ai/dsh-tui-app/lib/index.js +1864 -1781
- package/node_modules/@types/node/README.md +1 -1
- package/node_modules/@types/node/package.json +2 -2
- package/package.json +2 -2
|
@@ -12,15 +12,16 @@ import { homedir } from "node:os";
|
|
|
12
12
|
import "@deepseek-ai/cordis";
|
|
13
13
|
import { activeAtToken, formatFileMention } from "@deepseek-ai/dsh-file-reference";
|
|
14
14
|
import { formatSessionReferenceMention } from "@deepseek-ai/dsh-session-reference";
|
|
15
|
+
import { AppleContainerSandboxProvider } from "@deepseek-ai/dsh-sandbox-apple-container";
|
|
15
16
|
import { assertNever } from "@deepseek-ai/dsh-util-values";
|
|
16
17
|
import { readFile } from "node:fs/promises";
|
|
17
18
|
import { basename, extname, join, resolve } from "node:path";
|
|
18
19
|
import { pluginFiberPhase } from "@deepseek-ai/dsh-host-plugin-inventory";
|
|
20
|
+
import { planReviewOptions } from "@deepseek-ai/dsh-user-questions";
|
|
19
21
|
import { createWriteStream } from "node:fs";
|
|
20
22
|
import { Readable } from "node:stream";
|
|
21
23
|
import { pipeline } from "node:stream/promises";
|
|
22
24
|
import { DEFAULT_SESSION_LOG_COMPRESSION_LEVEL, flushLiveSessionLog, readSessionLogText, sessionLogExportDeps, sessionLogZipFilename, streamSessionLogZip } from "@deepseek-ai/dsh-session-log-export";
|
|
23
|
-
import { planReviewOptions } from "@deepseek-ai/dsh-user-questions";
|
|
24
25
|
import { isCompactCheckpointSource } from "@deepseek-ai/dsh-compaction/checkpoint";
|
|
25
26
|
import { isSurfaceEvent } from "@deepseek-ai/dsh-session/surface";
|
|
26
27
|
//#region lib/types/resume-model.js
|
|
@@ -304,14 +305,13 @@ function mark(width, key) {
|
|
|
304
305
|
return `${MARK_PREFIX}${String(width)};${key}${MARK_END}`;
|
|
305
306
|
}
|
|
306
307
|
/**
|
|
307
|
-
* How a chip is drawn: the accent color,
|
|
308
|
-
*
|
|
309
|
-
* color.
|
|
308
|
+
* How a chip is drawn: italic in the accent color, so a key reads apart from
|
|
309
|
+
* the words around it, and by its color from the dim italic of reasoning.
|
|
310
310
|
* @param palette - the active palette.
|
|
311
311
|
* @returns the chip style.
|
|
312
312
|
*/
|
|
313
313
|
function chipStyle(palette) {
|
|
314
|
-
return (text) => palette.
|
|
314
|
+
return (text) => palette.italic(palette.accent(text));
|
|
315
315
|
}
|
|
316
316
|
/**
|
|
317
317
|
* Draw the keys a text names as chips and every other run of it in `base`.
|
|
@@ -4801,225 +4801,179 @@ function fadingInSpans(fade) {
|
|
|
4801
4801
|
function floatingOutSpans(fade) {
|
|
4802
4802
|
return fade.spans().filter((span) => span.age < fade.steps);
|
|
4803
4803
|
}
|
|
4804
|
-
//#endregion
|
|
4805
|
-
//#region lib/types/spinner.js
|
|
4806
|
-
/**
|
|
4807
|
-
* Working indicators: rotating braille dots above the prompt, tool-family
|
|
4808
|
-
* glyphs on running cards, and a shimmer across the working activity word.
|
|
4809
|
-
*
|
|
4810
|
-
* Pure. Frame lookups read a wall-clock instant the caller passes in, so
|
|
4811
|
-
* every surface drawing at the same moment draws the same frame, and the
|
|
4812
|
-
* application owns the tick that redraws them.
|
|
4813
|
-
* @module @deepseek-ai/dsh-tui-app/spinner
|
|
4814
|
-
*/
|
|
4815
4804
|
/**
|
|
4816
|
-
* The
|
|
4817
|
-
*
|
|
4818
|
-
* a deployment setting.
|
|
4805
|
+
* The activity line's animation for each working status. Every glyph is
|
|
4806
|
+
* braille and no card or todo row draws braille. A presentation choice of
|
|
4807
|
+
* this terminal surface, not a deployment setting.
|
|
4819
4808
|
*/
|
|
4820
|
-
const
|
|
4821
|
-
/** Model reasoning with no
|
|
4809
|
+
const ACTIVITY_SPINNERS = {
|
|
4810
|
+
/** Model reasoning, and any label with no status of its own: three dots circling the cell. */
|
|
4822
4811
|
thinking: [
|
|
4823
|
-
"⠋",
|
|
4824
4812
|
"⠙",
|
|
4825
|
-
"⠹",
|
|
4826
4813
|
"⠸",
|
|
4827
|
-
"
|
|
4828
|
-
"
|
|
4829
|
-
"
|
|
4830
|
-
"
|
|
4814
|
+
"⢰",
|
|
4815
|
+
"⣠",
|
|
4816
|
+
"⣄",
|
|
4817
|
+
"⡆",
|
|
4831
4818
|
"⠇",
|
|
4832
|
-
"
|
|
4819
|
+
"⠋"
|
|
4833
4820
|
],
|
|
4834
|
-
/** Visible text streaming in:
|
|
4821
|
+
/** Visible reply text streaming in: lines filling the cell, then streaming up out of it. */
|
|
4835
4822
|
writing: [
|
|
4836
|
-
"
|
|
4837
|
-
"
|
|
4838
|
-
"
|
|
4839
|
-
"
|
|
4840
|
-
"
|
|
4841
|
-
"
|
|
4823
|
+
"⠉",
|
|
4824
|
+
"⠛",
|
|
4825
|
+
"⠿",
|
|
4826
|
+
"⣿",
|
|
4827
|
+
"⣶",
|
|
4828
|
+
"⣤",
|
|
4829
|
+
"⣀",
|
|
4830
|
+
"⣉"
|
|
4842
4831
|
],
|
|
4843
|
-
/** A tool
|
|
4832
|
+
/** A tool call streamed or running, whichever tool it names: one dot orbiting the cell. */
|
|
4844
4833
|
calling: [
|
|
4845
|
-
"◐",
|
|
4846
|
-
"◓",
|
|
4847
|
-
"◑",
|
|
4848
|
-
"◒"
|
|
4849
|
-
],
|
|
4850
|
-
/** Command execution: the same diamond animation as file edits. */
|
|
4851
|
-
shell: [
|
|
4852
|
-
"◇",
|
|
4853
|
-
"◈",
|
|
4854
|
-
"◆",
|
|
4855
|
-
"◈"
|
|
4856
|
-
],
|
|
4857
|
-
/** Reading and searching: a lens pulsing into focus. */
|
|
4858
|
-
search: [
|
|
4859
|
-
"○",
|
|
4860
|
-
"◉",
|
|
4861
|
-
"●",
|
|
4862
|
-
"◉"
|
|
4863
|
-
],
|
|
4864
|
-
/** File mutation: a diamond setting solid. */
|
|
4865
|
-
edit: [
|
|
4866
|
-
"◇",
|
|
4867
|
-
"◈",
|
|
4868
|
-
"◆",
|
|
4869
|
-
"◈"
|
|
4870
|
-
],
|
|
4871
|
-
/** Delegation to a child agent: dots diving deeper. */
|
|
4872
|
-
subagent: [
|
|
4873
4834
|
"⠁",
|
|
4874
|
-
"
|
|
4875
|
-
"
|
|
4876
|
-
"
|
|
4877
|
-
"
|
|
4878
|
-
"
|
|
4879
|
-
"
|
|
4880
|
-
"
|
|
4835
|
+
"⠈",
|
|
4836
|
+
"⠐",
|
|
4837
|
+
"⠠",
|
|
4838
|
+
"⢀",
|
|
4839
|
+
"⡀",
|
|
4840
|
+
"⠄",
|
|
4841
|
+
"⠂"
|
|
4881
4842
|
],
|
|
4882
|
-
/**
|
|
4883
|
-
|
|
4884
|
-
|
|
4885
|
-
|
|
4886
|
-
"
|
|
4887
|
-
"
|
|
4888
|
-
"
|
|
4889
|
-
"
|
|
4843
|
+
/** A scheduled model-request retry: a bar sliding down the cell and back. */
|
|
4844
|
+
retrying: [
|
|
4845
|
+
"⠉",
|
|
4846
|
+
"⠛",
|
|
4847
|
+
"⠶",
|
|
4848
|
+
"⣤",
|
|
4849
|
+
"⣀",
|
|
4850
|
+
"⣤",
|
|
4851
|
+
"⠶",
|
|
4852
|
+
"⠛"
|
|
4890
4853
|
],
|
|
4891
|
-
/** Condensing older history into a summary: a
|
|
4854
|
+
/** Condensing older history into a summary: a full cell settling and refilling. */
|
|
4892
4855
|
compacting: [
|
|
4893
4856
|
"⣿",
|
|
4857
|
+
"⣷",
|
|
4894
4858
|
"⣶",
|
|
4859
|
+
"⣦",
|
|
4895
4860
|
"⣤",
|
|
4896
|
-
"
|
|
4897
|
-
"
|
|
4898
|
-
"
|
|
4861
|
+
"⣦",
|
|
4862
|
+
"⣶",
|
|
4863
|
+
"⣷"
|
|
4899
4864
|
]
|
|
4900
4865
|
};
|
|
4866
|
+
/**
|
|
4867
|
+
* The animation every running tool card, folded subagent row, and in-progress
|
|
4868
|
+
* todo row draws, whatever the tool: a star blooming from a thin four-pointed
|
|
4869
|
+
* outline to a full asterisk. No frame is braille and no two frames match, so
|
|
4870
|
+
* two indicators at different phases never draw the same glyph at the same
|
|
4871
|
+
* instant. A presentation choice of this terminal surface, not a deployment
|
|
4872
|
+
* setting.
|
|
4873
|
+
*/
|
|
4874
|
+
const TOOL_SPINNER = [
|
|
4875
|
+
"✧",
|
|
4876
|
+
"✦",
|
|
4877
|
+
"✶",
|
|
4878
|
+
"✷",
|
|
4879
|
+
"✸",
|
|
4880
|
+
"✹",
|
|
4881
|
+
"✺",
|
|
4882
|
+
"✻"
|
|
4883
|
+
];
|
|
4901
4884
|
/** Blank steps between two shimmer passes, so the sweep pauses past the word's end. */
|
|
4902
4885
|
const SHIMMER_GAP = 6;
|
|
4903
|
-
/**
|
|
4904
|
-
const SHELL_TOOLS = new Set([
|
|
4905
|
-
"bash",
|
|
4906
|
-
"pwsh",
|
|
4907
|
-
"run_code"
|
|
4908
|
-
]);
|
|
4909
|
-
/** Tool names that mutate files. */
|
|
4910
|
-
const EDIT_TOOLS = new Set([
|
|
4911
|
-
"edit",
|
|
4912
|
-
"write",
|
|
4913
|
-
"str_replace_editor"
|
|
4914
|
-
]);
|
|
4915
|
-
/** Tool names that read or search, beyond the `TOOL_PREFIXES` below. */
|
|
4916
|
-
const SEARCH_TOOLS = new Set([
|
|
4917
|
-
"read",
|
|
4918
|
-
"read_image",
|
|
4919
|
-
"glob",
|
|
4920
|
-
"grep",
|
|
4921
|
-
"lsp",
|
|
4922
|
-
"skill",
|
|
4923
|
-
"web_fetch",
|
|
4924
|
-
"web_search",
|
|
4925
|
-
"load_workspace_dependencies",
|
|
4926
|
-
"list_subagent_models"
|
|
4927
|
-
]);
|
|
4928
|
-
/** Tool names that delegate or steer a child agent, beyond `subagent` itself. */
|
|
4929
|
-
const SUBAGENT_TOOLS = new Set([
|
|
4930
|
-
"send_message",
|
|
4931
|
-
"interrupt_agent",
|
|
4932
|
-
"list_agents",
|
|
4933
|
-
"ralph",
|
|
4934
|
-
"workflow",
|
|
4935
|
-
"spawn_teammate",
|
|
4936
|
-
"wait_agent"
|
|
4937
|
-
]);
|
|
4938
|
-
/** Tool names that plan or schedule work. */
|
|
4939
|
-
const TODO_TOOLS = new Set([
|
|
4940
|
-
"todo_write",
|
|
4941
|
-
"create_goal",
|
|
4942
|
-
"get_goal",
|
|
4943
|
-
"update_goal"
|
|
4944
|
-
]);
|
|
4945
|
-
/** Tool names that wait on a human answer. */
|
|
4946
|
-
const WAITING_TOOLS = new Set(["ask_user_question", "exit_plan_mode"]);
|
|
4947
|
-
/**
|
|
4948
|
-
* Tool-name prefixes per spinner family, checked after the exact sets above.
|
|
4949
|
-
* An MCP or custom tool that keeps its family's prefix inherits the animation.
|
|
4950
|
-
*/
|
|
4951
|
-
const TOOL_PREFIXES = [
|
|
4952
|
-
["terminal_", "shell"],
|
|
4953
|
-
["session_", "search"],
|
|
4954
|
-
["cordis_inspect_", "search"],
|
|
4955
|
-
["list_mcp_", "search"],
|
|
4956
|
-
["read_mcp_", "search"],
|
|
4957
|
-
["team_task_", "subagent"],
|
|
4958
|
-
["schedule_", "todo"]
|
|
4959
|
-
];
|
|
4960
|
-
/** The working spinner's label while a compaction condenses history. */
|
|
4886
|
+
/** The activity line's label while a compaction condenses history. */
|
|
4961
4887
|
const COMPACTING_ACTIVITY = "compacting";
|
|
4962
4888
|
/**
|
|
4963
|
-
* The
|
|
4964
|
-
* @param
|
|
4965
|
-
* @
|
|
4966
|
-
* @param intervalMs - how long each frame lasts, in milliseconds; positive.
|
|
4967
|
-
* @returns one frame of that scenario.
|
|
4889
|
+
* The activity line's label for a streamed or executing tool call.
|
|
4890
|
+
* @param name - the tool name when one is known.
|
|
4891
|
+
* @returns `calling <name>`, or `calling` when the name has not arrived.
|
|
4968
4892
|
*/
|
|
4969
|
-
function
|
|
4970
|
-
|
|
4971
|
-
/* v8 ignore next -- the modulo keeps the index inside the frame list */
|
|
4972
|
-
return frames[Math.floor(now / intervalMs) % frames.length] ?? frames[0];
|
|
4893
|
+
function callingActivity(name) {
|
|
4894
|
+
return name ? `calling ${name}` : "calling";
|
|
4973
4895
|
}
|
|
4974
4896
|
/**
|
|
4975
|
-
*
|
|
4976
|
-
* @param
|
|
4977
|
-
* @returns
|
|
4897
|
+
* Whether the activity line already names a tool call.
|
|
4898
|
+
* @param activity - the activity line's current label.
|
|
4899
|
+
* @returns true for `calling` and `calling <name>`.
|
|
4978
4900
|
*/
|
|
4979
|
-
function
|
|
4980
|
-
|
|
4981
|
-
if (EDIT_TOOLS.has(name)) return "edit";
|
|
4982
|
-
if (SEARCH_TOOLS.has(name)) return "search";
|
|
4983
|
-
if (isSubagentTool(name) || SUBAGENT_TOOLS.has(name)) return "subagent";
|
|
4984
|
-
if (TODO_TOOLS.has(name)) return "todo";
|
|
4985
|
-
if (WAITING_TOOLS.has(name)) return "waiting";
|
|
4986
|
-
for (const [prefix, kind] of TOOL_PREFIXES) if (name.startsWith(prefix)) return kind;
|
|
4987
|
-
return "calling";
|
|
4901
|
+
function isCallingActivity(activity) {
|
|
4902
|
+
return activity === "calling" || activity.startsWith("calling ");
|
|
4988
4903
|
}
|
|
4989
4904
|
/**
|
|
4990
|
-
* The
|
|
4991
|
-
* @param
|
|
4992
|
-
*
|
|
4905
|
+
* The status the activity line animates for its label.
|
|
4906
|
+
* @param activity - the label: `thinking`, `writing`, `calling` or
|
|
4907
|
+
* `calling <name>`, a scheduled retry starting with `retrying`, or
|
|
4908
|
+
* {@link COMPACTING_ACTIVITY}.
|
|
4909
|
+
* @returns the label's status; `calling` whichever tool the label names, and
|
|
4910
|
+
* `thinking` for any other label.
|
|
4993
4911
|
*/
|
|
4994
|
-
function
|
|
4912
|
+
function activityStatus(activity) {
|
|
4913
|
+
if (activity === "writing") return "writing";
|
|
4914
|
+
if (isCallingActivity(activity)) return "calling";
|
|
4915
|
+
if (activity.startsWith("retrying")) return "retrying";
|
|
4916
|
+
if (activity === "compacting") return "compacting";
|
|
4995
4917
|
return "thinking";
|
|
4996
4918
|
}
|
|
4997
4919
|
/**
|
|
4998
|
-
* The
|
|
4999
|
-
*
|
|
5000
|
-
*
|
|
5001
|
-
* @param
|
|
5002
|
-
* @
|
|
4920
|
+
* The frame an indicator draws at one instant. The frame index advances
|
|
4921
|
+
* once per `periodMs` of wall clock, so indicators drawn at the same instant
|
|
4922
|
+
* step together, and a change of animation keeps the beat.
|
|
4923
|
+
* @param frames - the animation drawn.
|
|
4924
|
+
* @param now - the current time in milliseconds.
|
|
4925
|
+
* @param periodMs - how long each frame lasts, in milliseconds; positive.
|
|
4926
|
+
* @param phase - how many frames the indicator runs ahead of the clock, from 0 to {@link SPINNER_CYCLE} - 1.
|
|
4927
|
+
* @returns the frame at that instant.
|
|
5003
4928
|
*/
|
|
5004
|
-
function
|
|
5005
|
-
|
|
5006
|
-
|
|
5007
|
-
|
|
5008
|
-
|
|
4929
|
+
function spinnerFrame(frames, now, periodMs, phase = 0) {
|
|
4930
|
+
/* v8 ignore next -- the modulo keeps the index inside the frame list */
|
|
4931
|
+
return frames[(Math.floor(now / periodMs) + phase) % 8] ?? frames[0];
|
|
4932
|
+
}
|
|
4933
|
+
/**
|
|
4934
|
+
* The phase a new {@link TOOL_SPINNER} indicator spins at beside the
|
|
4935
|
+
* indicators already spinning. No two frames of that animation match, so two
|
|
4936
|
+
* indicators at different phases never draw the same glyph at the same
|
|
4937
|
+
* instant. A phase no indicator holds is taken, the one farthest from its
|
|
4938
|
+
* nearest neighbour first and the lowest on a tie; once every phase is held,
|
|
4939
|
+
* the lowest phase held by the fewest indicators.
|
|
4940
|
+
* @param taken - the phases of the indicators spinning now, one per indicator.
|
|
4941
|
+
* @returns a phase from 0 to {@link SPINNER_CYCLE} - 1.
|
|
4942
|
+
*/
|
|
4943
|
+
function staggerPhase(taken) {
|
|
4944
|
+
let best = 0;
|
|
4945
|
+
let fewest = Number.POSITIVE_INFINITY;
|
|
4946
|
+
let widest = -1;
|
|
4947
|
+
for (let phase = 0; phase < 8; phase += 1) {
|
|
4948
|
+
let holders = 0;
|
|
4949
|
+
let gap = 8;
|
|
4950
|
+
for (const other of taken) {
|
|
4951
|
+
if (other === phase) holders += 1;
|
|
4952
|
+
const distance = Math.abs(phase - other);
|
|
4953
|
+
gap = Math.min(gap, distance, 8 - distance);
|
|
4954
|
+
}
|
|
4955
|
+
if (holders < fewest || holders === fewest && gap > widest) {
|
|
4956
|
+
best = phase;
|
|
4957
|
+
fewest = holders;
|
|
4958
|
+
widest = gap;
|
|
4959
|
+
}
|
|
4960
|
+
}
|
|
4961
|
+
return best;
|
|
5009
4962
|
}
|
|
5010
4963
|
/**
|
|
5011
4964
|
* Draw `text` dim with a bright highlight sweeping across it, one character
|
|
5012
|
-
* per
|
|
5013
|
-
*
|
|
5014
|
-
*
|
|
4965
|
+
* per `periodMs`: the character under the sweep is bold, its neighbours are
|
|
4966
|
+
* drawn at the plain foreground, and the sweep rests for {@link SHIMMER_GAP}
|
|
4967
|
+
* steps past the end before starting again.
|
|
5015
4968
|
* @param palette - the palette the sweep is drawn with; a disabled palette returns `text` unchanged.
|
|
5016
4969
|
* @param text - the plain text to draw.
|
|
5017
4970
|
* @param now - the current time in milliseconds.
|
|
4971
|
+
* @param periodMs - how long the sweep rests on each character, in milliseconds; positive.
|
|
5018
4972
|
* @returns the styled text, the same visible width as `text`.
|
|
5019
4973
|
*/
|
|
5020
|
-
function shimmer(palette, text, now) {
|
|
4974
|
+
function shimmer(palette, text, now, periodMs) {
|
|
5021
4975
|
const chars = Array.from(new Intl.Segmenter().segment(text), (part) => part.segment);
|
|
5022
|
-
const at = Math.floor(now /
|
|
4976
|
+
const at = Math.floor(now / periodMs) % (chars.length + SHIMMER_GAP);
|
|
5023
4977
|
const tone = (index) => {
|
|
5024
4978
|
const distance = Math.abs(index - at);
|
|
5025
4979
|
return distance === 0 ? "bright" : distance === 1 ? "plain" : "dim";
|
|
@@ -5979,561 +5933,160 @@ function matchPermission(options, typed) {
|
|
|
5979
5933
|
return options.find((option) => option.value.toLowerCase() === wanted)?.value ?? null;
|
|
5980
5934
|
}
|
|
5981
5935
|
//#endregion
|
|
5982
|
-
//#region lib/types/
|
|
5936
|
+
//#region lib/types/keys.js
|
|
5983
5937
|
/**
|
|
5984
|
-
*
|
|
5985
|
-
*
|
|
5986
|
-
*
|
|
5938
|
+
* The key model: which action one press names in the region that holds the
|
|
5939
|
+
* keyboard, what one press types, how long a focus handoff silences the
|
|
5940
|
+
* editor's `Escape`, and the words every surface uses to name a key - the
|
|
5941
|
+
* legend each region degrades through, the entry keys the status bar
|
|
5942
|
+
* reserves, and the lines `/help` lists per region.
|
|
5943
|
+
*
|
|
5944
|
+
* Pure. It reads key bytes and returns actions, so the application owns every
|
|
5945
|
+
* effect and the whole map is decided without a terminal, a palette, or a
|
|
5946
|
+
* clock.
|
|
5947
|
+
* @module @deepseek-ai/dsh-tui-app/keys
|
|
5987
5948
|
*/
|
|
5949
|
+
/** Characters a typed key never carries: C0 controls, DEL, and C1 controls. */
|
|
5950
|
+
const CONTROL_CHARACTERS = /[\u0000-\u001f\u007f-\u009f]/u;
|
|
5988
5951
|
/**
|
|
5989
|
-
*
|
|
5990
|
-
*
|
|
5991
|
-
* @
|
|
5992
|
-
* @param sessionId - the session to export.
|
|
5993
|
-
* @param directory - the directory the archive is written into.
|
|
5994
|
-
* @param signal - cancels the export.
|
|
5995
|
-
* @returns the archive's absolute path.
|
|
5996
|
-
* @throws when a required service is not composed or the session has no persisted log.
|
|
5952
|
+
* The text one key press types.
|
|
5953
|
+
* @param data - the bytes the terminal sent.
|
|
5954
|
+
* @returns the characters to type, or undefined for control keys and escape sequences.
|
|
5997
5955
|
*/
|
|
5998
|
-
|
|
5999
|
-
const
|
|
6000
|
-
if (
|
|
6001
|
-
|
|
6002
|
-
...deps,
|
|
6003
|
-
sessionQuery: deps.sessionQuery,
|
|
6004
|
-
sessionPersistence: deps.sessionPersistence,
|
|
6005
|
-
attachments: deps.attachments
|
|
6006
|
-
};
|
|
6007
|
-
await flushLiveSessionLog(deps, sessionId, signal);
|
|
6008
|
-
const root = await readSessionLogText(deps.sessionPersistence, sessionId, signal);
|
|
6009
|
-
if (root === void 0) throw new Error(`session ${sessionId} has no persisted log to export`);
|
|
6010
|
-
const path = join(directory, sessionLogZipFilename(sessionId));
|
|
6011
|
-
const archive = streamSessionLogZip(ready, root, sessionId, true, DEFAULT_SESSION_LOG_COMPRESSION_LEVEL, signal);
|
|
6012
|
-
await pipeline(Readable.fromWeb(archive), createWriteStream(path), { signal });
|
|
6013
|
-
return path;
|
|
5956
|
+
function typedText(data) {
|
|
5957
|
+
const kitty = decodeKittyPrintable(data);
|
|
5958
|
+
if (kitty !== void 0) return kitty;
|
|
5959
|
+
return CONTROL_CHARACTERS.test(data) ? void 0 : data;
|
|
6014
5960
|
}
|
|
6015
|
-
//#endregion
|
|
6016
|
-
//#region lib/types/pace.js
|
|
6017
5961
|
/**
|
|
6018
|
-
*
|
|
6019
|
-
*
|
|
5962
|
+
* The legend of each region, in declared degradation steps: the widest first,
|
|
5963
|
+
* every next one narrower, the last the shortest form that still names the way
|
|
5964
|
+
* back to the input. One grammar throughout - the keys the region answers,
|
|
5965
|
+
* then where `Esc` goes - so a legend is read the same way on every surface.
|
|
5966
|
+
* The editor draws no legend of its own: the unfocused status bar names the
|
|
5967
|
+
* keys that leave it.
|
|
6020
5968
|
*/
|
|
6021
|
-
const
|
|
6022
|
-
|
|
6023
|
-
|
|
6024
|
-
|
|
6025
|
-
|
|
6026
|
-
|
|
6027
|
-
|
|
6028
|
-
|
|
6029
|
-
|
|
6030
|
-
|
|
6031
|
-
|
|
6032
|
-
|
|
6033
|
-
|
|
6034
|
-
|
|
6035
|
-
|
|
6036
|
-
|
|
6037
|
-
|
|
6038
|
-
|
|
6039
|
-
|
|
6040
|
-
|
|
6041
|
-
|
|
6042
|
-
|
|
6043
|
-
push(channel, text, release) {
|
|
6044
|
-
const last = this.entries.at(-1);
|
|
6045
|
-
if (last !== void 0 && last.channel === channel) last.text += text;
|
|
6046
|
-
else this.entries.push({
|
|
6047
|
-
channel,
|
|
6048
|
-
text,
|
|
6049
|
-
release
|
|
6050
|
-
});
|
|
6051
|
-
this.backlog += text.length;
|
|
6052
|
-
}
|
|
6053
|
-
/**
|
|
6054
|
-
* Whether text is still waiting for a frame.
|
|
6055
|
-
* @returns true while any entry is queued.
|
|
6056
|
-
*/
|
|
6057
|
-
pending() {
|
|
6058
|
-
return this.entries.length > 0;
|
|
6059
|
-
}
|
|
6060
|
-
/**
|
|
6061
|
-
* Release one frame's share of the backlog.
|
|
6062
|
-
* @returns whether text is still queued after this frame.
|
|
6063
|
-
*/
|
|
6064
|
-
frame() {
|
|
6065
|
-
this.credit += Math.max(1, this.backlog / this.drainFrames);
|
|
6066
|
-
let budget = Math.floor(this.credit);
|
|
6067
|
-
this.credit -= budget;
|
|
6068
|
-
for (let entry = this.entries[0]; entry !== void 0; entry = this.entries[0]) {
|
|
6069
|
-
const cut = cutGraphemes(entry.text, budget);
|
|
6070
|
-
if (cut.graphemes === 0 && entry.text !== "") break;
|
|
6071
|
-
budget -= cut.graphemes;
|
|
6072
|
-
this.backlog -= cut.length;
|
|
6073
|
-
const head = entry.text.slice(0, cut.length);
|
|
6074
|
-
entry.text = entry.text.slice(cut.length);
|
|
6075
|
-
if (entry.text === "") this.entries.shift();
|
|
6076
|
-
entry.release(head);
|
|
6077
|
-
}
|
|
6078
|
-
if (this.entries.length === 0) this.credit = 0;
|
|
6079
|
-
return this.entries.length > 0;
|
|
6080
|
-
}
|
|
6081
|
-
/** Release everything queued, in order, at once. */
|
|
6082
|
-
flush() {
|
|
6083
|
-
const entries = this.entries.splice(0);
|
|
6084
|
-
this.backlog = 0;
|
|
6085
|
-
this.credit = 0;
|
|
6086
|
-
for (const entry of entries) entry.release(entry.text);
|
|
6087
|
-
}
|
|
6088
|
-
/**
|
|
6089
|
-
* Release every queued entry of one channel now, and keep every other
|
|
6090
|
-
* entry in arrival order. A finished thinking block uses this so its
|
|
6091
|
-
* remainder is drawn before later reply text is paced.
|
|
6092
|
-
* @param channel - the channel to release.
|
|
6093
|
-
* @returns whether any entry of that channel was queued.
|
|
6094
|
-
*/
|
|
6095
|
-
flushChannel(channel) {
|
|
6096
|
-
const pending = this.entries.splice(0);
|
|
6097
|
-
const kept = [];
|
|
6098
|
-
const release = [];
|
|
6099
|
-
let backlog = 0;
|
|
6100
|
-
for (const entry of pending) if (entry.channel === channel) release.push(entry);
|
|
6101
|
-
else {
|
|
6102
|
-
kept.push(entry);
|
|
6103
|
-
backlog += entry.text.length;
|
|
6104
|
-
}
|
|
6105
|
-
this.entries.push(...kept);
|
|
6106
|
-
this.backlog = backlog;
|
|
6107
|
-
if (this.entries.length === 0) this.credit = 0;
|
|
6108
|
-
for (const entry of release) entry.release(entry.text);
|
|
6109
|
-
return release.length > 0;
|
|
6110
|
-
}
|
|
6111
|
-
/** Drop everything queued without releasing it. */
|
|
6112
|
-
clear() {
|
|
6113
|
-
this.entries.length = 0;
|
|
6114
|
-
this.backlog = 0;
|
|
6115
|
-
this.credit = 0;
|
|
6116
|
-
}
|
|
5969
|
+
const HINTS = {
|
|
5970
|
+
editor: [],
|
|
5971
|
+
transcript: [
|
|
5972
|
+
"↑↓ sections · ←→ parts · Space folds · Ctrl+G reader · Esc input",
|
|
5973
|
+
"↑↓ ←→ · Space folds · Esc input",
|
|
5974
|
+
"Esc input"
|
|
5975
|
+
],
|
|
5976
|
+
queue: [
|
|
5977
|
+
"↑↓ select · Enter steer · E edit · I inject · Esc input",
|
|
5978
|
+
"↑↓ · Enter steer · E edit · Esc input",
|
|
5979
|
+
"Esc input"
|
|
5980
|
+
],
|
|
5981
|
+
panel: [
|
|
5982
|
+
"↑↓ children · Enter opens · Tab regions · Esc input",
|
|
5983
|
+
"↑↓ children · Esc input",
|
|
5984
|
+
"Esc input"
|
|
5985
|
+
],
|
|
5986
|
+
bar: [
|
|
5987
|
+
"←→ segments · Enter details · Tab regions · Esc input",
|
|
5988
|
+
"←→ segments · Esc input",
|
|
5989
|
+
"Esc input"
|
|
5990
|
+
]
|
|
6117
5991
|
};
|
|
6118
5992
|
/**
|
|
6119
|
-
*
|
|
6120
|
-
*
|
|
6121
|
-
*
|
|
6122
|
-
*
|
|
6123
|
-
* block reports its full row count after every render and draws only the
|
|
6124
|
-
* first {@link RowReveal.shown} rows until the reveal catches up.
|
|
5993
|
+
* The regions in the order `/help` lists them: the input first, because it is
|
|
5994
|
+
* where every other region is reached from and returned to. The screen stacks
|
|
5995
|
+
* them in another order, which {@link FocusRegion} states and the `Tab` walk
|
|
5996
|
+
* follows over the regions drawn right now.
|
|
6125
5997
|
*/
|
|
6126
|
-
|
|
6127
|
-
|
|
6128
|
-
|
|
6129
|
-
|
|
6130
|
-
|
|
6131
|
-
|
|
6132
|
-
|
|
6133
|
-
|
|
6134
|
-
|
|
6135
|
-
|
|
6136
|
-
|
|
6137
|
-
|
|
6138
|
-
|
|
6139
|
-
|
|
6140
|
-
* Rows drawn right now.
|
|
6141
|
-
* @returns the count, which may exceed the block's rows after {@link RowReveal.settle}.
|
|
6142
|
-
*/
|
|
6143
|
-
shown() {
|
|
6144
|
-
return this.count;
|
|
6145
|
-
}
|
|
6146
|
-
/**
|
|
6147
|
-
* Draw one frame's share of the rows still hidden.
|
|
6148
|
-
* @param total - the block's full row count at its last render.
|
|
6149
|
-
* @returns whether rows are still hidden after this frame.
|
|
6150
|
-
*/
|
|
6151
|
-
frame(total) {
|
|
6152
|
-
if (this.count >= total) {
|
|
6153
|
-
this.credit = 0;
|
|
6154
|
-
return false;
|
|
6155
|
-
}
|
|
6156
|
-
this.credit += (total - this.count) / this.drainFrames;
|
|
6157
|
-
const rows = Math.max(1, Math.floor(this.credit));
|
|
6158
|
-
this.credit = Math.max(0, this.credit - rows);
|
|
6159
|
-
this.count = Math.min(total, this.count + rows);
|
|
6160
|
-
return this.count < total;
|
|
6161
|
-
}
|
|
6162
|
-
/**
|
|
6163
|
-
* Hold the count at the block's full row count, so rows the block loses
|
|
6164
|
-
* later are not owed again when it grows back.
|
|
6165
|
-
* @param total - the block's full row count at this render.
|
|
6166
|
-
*/
|
|
6167
|
-
clamp(total) {
|
|
6168
|
-
if (this.count > total) this.count = total;
|
|
6169
|
-
}
|
|
6170
|
-
/** Draw every row the block has at its next render. */
|
|
6171
|
-
settle() {
|
|
6172
|
-
this.count = Number.POSITIVE_INFINITY;
|
|
6173
|
-
this.credit = 0;
|
|
6174
|
-
}
|
|
5998
|
+
const FOCUS_REGIONS = [
|
|
5999
|
+
"editor",
|
|
6000
|
+
"transcript",
|
|
6001
|
+
"queue",
|
|
6002
|
+
"panel",
|
|
6003
|
+
"bar"
|
|
6004
|
+
];
|
|
6005
|
+
/** What each region is called where it is named rather than drawn. */
|
|
6006
|
+
const REGION_LABELS = {
|
|
6007
|
+
editor: "input",
|
|
6008
|
+
transcript: "conversation",
|
|
6009
|
+
queue: "follow-ups",
|
|
6010
|
+
panel: "subagent panel",
|
|
6011
|
+
bar: "status bar"
|
|
6175
6012
|
};
|
|
6013
|
+
/** The two keys that leave the input when no follow-up waits. */
|
|
6014
|
+
const ENTRY_KEYS = "Shift+↑ read · Shift+↓ status";
|
|
6015
|
+
/** The same pair while follow-ups wait: Shift+↑ selects one instead of reading. */
|
|
6016
|
+
const QUEUE_ENTRY_KEYS = "Shift+↑ select · Shift+↓ status";
|
|
6176
6017
|
/**
|
|
6177
|
-
*
|
|
6178
|
-
*
|
|
6179
|
-
*
|
|
6180
|
-
* @returns the prefix's grapheme count and UTF-16 length.
|
|
6181
|
-
*/
|
|
6182
|
-
function cutGraphemes(text, limit) {
|
|
6183
|
-
if (limit <= 0) return {
|
|
6184
|
-
graphemes: 0,
|
|
6185
|
-
length: 0
|
|
6186
|
-
};
|
|
6187
|
-
let graphemes = 0;
|
|
6188
|
-
let length = 0;
|
|
6189
|
-
for (const part of GRAPHEMES.segment(text)) {
|
|
6190
|
-
if (graphemes === limit) break;
|
|
6191
|
-
graphemes += 1;
|
|
6192
|
-
length += part.segment.length;
|
|
6193
|
-
}
|
|
6194
|
-
return {
|
|
6195
|
-
graphemes,
|
|
6196
|
-
length
|
|
6197
|
-
};
|
|
6198
|
-
}
|
|
6199
|
-
//#endregion
|
|
6200
|
-
//#region lib/types/view-banner.js
|
|
6201
|
-
/**
|
|
6202
|
-
* The line above the editor that says the terminal is showing a subagent
|
|
6203
|
-
* session rather than the main one: the path of views from the main session
|
|
6204
|
-
* down to the one on screen, and the key that goes back one level. The
|
|
6205
|
-
* header names the view too, but it scrolls away with the transcript; this
|
|
6206
|
-
* line stays next to the editor for as long as the view is open, and draws
|
|
6207
|
-
* nothing while the main session is on screen.
|
|
6208
|
-
* @module @deepseek-ai/dsh-tui-app/view-banner
|
|
6018
|
+
* The keys the unfocused follow-ups list names: ↑ on an empty input revises
|
|
6019
|
+
* the newest follow-up, and Shift+↑ is the direction out of the input toward
|
|
6020
|
+
* whatever sits above it.
|
|
6209
6021
|
*/
|
|
6210
|
-
|
|
6211
|
-
const MAIN_SESSION_LABEL = "main";
|
|
6212
|
-
/** What the line calls a subagent view unless the app names the view otherwise. */
|
|
6213
|
-
const SUBAGENT_VIEW_TITLE = "subagent view";
|
|
6214
|
-
/** Glyph the banner opens with; the header marks a subagent view with the same one. */
|
|
6215
|
-
const VIEW_GLYPH = "◆";
|
|
6216
|
-
/** Draws the subagent-view line while a subagent session is on screen. */
|
|
6217
|
-
var ViewBanner = class {
|
|
6218
|
-
palette;
|
|
6219
|
-
/** Labels of the open views, outermost first; empty while the main session is on screen. */
|
|
6220
|
-
views = [];
|
|
6221
|
-
/** @param palette - the palette the line is styled with. */
|
|
6222
|
-
constructor(palette) {
|
|
6223
|
-
this.palette = palette;
|
|
6224
|
-
}
|
|
6225
|
-
/** What the line calls the view on screen. */
|
|
6226
|
-
title = SUBAGENT_VIEW_TITLE;
|
|
6227
|
-
/**
|
|
6228
|
-
* Replace the views the line names.
|
|
6229
|
-
* @param views - the label of every open subagent view, outermost first;
|
|
6230
|
-
* empty draws nothing.
|
|
6231
|
-
* @param title - what the line calls the view on screen; `subagent view` when omitted.
|
|
6232
|
-
*/
|
|
6233
|
-
setViews(views, title = SUBAGENT_VIEW_TITLE) {
|
|
6234
|
-
this.views = [...views];
|
|
6235
|
-
this.title = title;
|
|
6236
|
-
}
|
|
6237
|
-
invalidate() {}
|
|
6238
|
-
/**
|
|
6239
|
-
* Draw the line.
|
|
6240
|
-
* @param width - the columns the line fits.
|
|
6241
|
-
* @returns one banded row while a view is open, and no rows otherwise.
|
|
6242
|
-
*/
|
|
6243
|
-
render(width) {
|
|
6244
|
-
const current = this.views.at(-1);
|
|
6245
|
-
if (current === void 0) return [];
|
|
6246
|
-
const palette = this.palette;
|
|
6247
|
-
const back = this.views.at(-2) ?? "main";
|
|
6248
|
-
const trail = [MAIN_SESSION_LABEL, ...this.views.slice(0, -1)].map((label) => palette.dim(label));
|
|
6249
|
-
return [bandRow(palette, truncateToWidth(` ${[
|
|
6250
|
-
`${palette.warning(VIEW_GLYPH)} ${palette.bold(palette.warning(this.title))}`,
|
|
6251
|
-
[...trail, palette.bold(current)].join(palette.dim(" › ")),
|
|
6252
|
-
`${paintKeys(palette, "Ctrl+P")} ${palette.dim(`back to ${back}`)}`
|
|
6253
|
-
].join(palette.dim(" · "))}`, width, "…"), width)];
|
|
6254
|
-
}
|
|
6255
|
-
};
|
|
6256
|
-
/** Columns the ` ─ ` between the chip and the title takes. */
|
|
6257
|
-
const CHIP_MARGIN = 3;
|
|
6258
|
-
/** What opens a top rule. */
|
|
6259
|
-
const TOP_LEFT = "╭";
|
|
6260
|
-
/** What closes a top rule. */
|
|
6261
|
-
const TOP_RIGHT = "╮";
|
|
6262
|
-
/** What opens a bottom rule. */
|
|
6263
|
-
const BOTTOM_LEFT = "╰";
|
|
6264
|
-
/** What closes a bottom rule. */
|
|
6265
|
-
const BOTTOM_RIGHT = "╯";
|
|
6266
|
-
/** What opens a rule drawn between two parts of one frame. */
|
|
6267
|
-
const LEGEND_LEFT = "├";
|
|
6268
|
-
/** What closes a rule drawn between two parts of one frame. */
|
|
6269
|
-
const LEGEND_RIGHT = "┤";
|
|
6270
|
-
/** What a rule fills the width between its texts with. */
|
|
6271
|
-
const FILL = "─";
|
|
6272
|
-
/** The border drawn on each side of a body row. */
|
|
6273
|
-
const SIDE$1 = "│";
|
|
6274
|
-
/** What separates the chip from the title on a top rule. */
|
|
6275
|
-
const CHIP_JOIN = ` ${FILL} `;
|
|
6276
|
-
/** The mark the chip opens with, the one inverse block this surface draws. */
|
|
6277
|
-
const CHIP_MARK = "●";
|
|
6278
|
-
/** What ends a line the width cut short; one column, so the mark itself fits. */
|
|
6279
|
-
const ELLIPSIS$4 = "…";
|
|
6022
|
+
const QUEUE_ENTRY_HINT = "↑ edit · Shift+↑ select";
|
|
6280
6023
|
/**
|
|
6281
|
-
* The
|
|
6282
|
-
*
|
|
6283
|
-
*
|
|
6284
|
-
*
|
|
6285
|
-
* @
|
|
6024
|
+
* The entry keys the unfocused status bar reserves before any fact is placed,
|
|
6025
|
+
* in declared degradation steps. Both directions are named: reaching the
|
|
6026
|
+
* conversation or a waiting follow-up, and reaching the bar, are the two
|
|
6027
|
+
* ways out of the input, and a key nobody can see is a key nobody presses.
|
|
6028
|
+
* @param drawn - whether follow-ups sit above the editor, which Shift+↑ enters.
|
|
6029
|
+
* @returns the widest pair first, then the compact form.
|
|
6286
6030
|
*/
|
|
6287
|
-
function
|
|
6288
|
-
return
|
|
6031
|
+
function entryHints(drawn = {}) {
|
|
6032
|
+
return [drawn.queue === true ? QUEUE_ENTRY_KEYS : ENTRY_KEYS, "Shift+↑↓ nav"];
|
|
6289
6033
|
}
|
|
6034
|
+
entryHints();
|
|
6290
6035
|
/**
|
|
6291
|
-
*
|
|
6292
|
-
* @param
|
|
6293
|
-
* @
|
|
6294
|
-
*
|
|
6036
|
+
* The widest legend step of one region.
|
|
6037
|
+
* @param region - the region holding the keyboard.
|
|
6038
|
+
* @returns the step a surface draws when the width holds it, and the empty
|
|
6039
|
+
* string for the editor, which draws no legend.
|
|
6295
6040
|
*/
|
|
6296
|
-
function
|
|
6297
|
-
|
|
6298
|
-
return Math.max(1, width - 4 - chipColumns);
|
|
6041
|
+
function widestHint(region) {
|
|
6042
|
+
return HINTS[region][0] ?? "";
|
|
6299
6043
|
}
|
|
6300
6044
|
/**
|
|
6301
|
-
*
|
|
6302
|
-
*
|
|
6303
|
-
*
|
|
6304
|
-
*
|
|
6305
|
-
*
|
|
6045
|
+
* What `/help` lists per region: the legend the region draws, then the coarse
|
|
6046
|
+
* keys no legend has room for. The legends are read from {@link HINTS} rather
|
|
6047
|
+
* than written again, so a surface and `/help` can never name a key
|
|
6048
|
+
* differently. The editor draws no legend, so its own keys are listed here and
|
|
6049
|
+
* nowhere else. This is the screen's summary, not the complete map; the
|
|
6050
|
+
* package README carries every binding.
|
|
6306
6051
|
*/
|
|
6307
|
-
|
|
6308
|
-
|
|
6309
|
-
|
|
6310
|
-
|
|
6052
|
+
const KEY_LINES = {
|
|
6053
|
+
editor: [
|
|
6054
|
+
"Enter sends · Shift+Enter newline · ↑↓ history · Ctrl+S steers",
|
|
6055
|
+
"Shift+Tab effort list · Shift+←→ words",
|
|
6056
|
+
"@ completes paths and sessions · / completes commands · Tab takes one",
|
|
6057
|
+
"!cmd runs here · the next prompt can read it · !!cmd stays local",
|
|
6058
|
+
`${ENTRY_KEYS} · Ctrl+G reader`,
|
|
6059
|
+
"While follow-ups wait: ↑ on an empty input edits the newest · Shift+↑ selects one",
|
|
6060
|
+
"Ctrl+O folds every tool card and context row",
|
|
6061
|
+
"Ctrl+T todos · Ctrl+P parent session · Ctrl+L redraw · ? keys",
|
|
6062
|
+
"Ctrl+B moves running tool calls to the background · /jobs lists them",
|
|
6063
|
+
"Esc arms the stop · Esc again stops the turn · Esc cancels a running /compact",
|
|
6064
|
+
"Ctrl+C clears the input, twice quits · Ctrl+D quits an empty input"
|
|
6065
|
+
],
|
|
6066
|
+
transcript: [widestHint("transcript"), "Shift+↑↓ blocks · PgUp PgDn turns · Home End ends · Tab regions · Enter reads"],
|
|
6067
|
+
queue: [widestHint("queue")],
|
|
6068
|
+
panel: [widestHint("panel")],
|
|
6069
|
+
bar: [widestHint("bar")]
|
|
6070
|
+
};
|
|
6071
|
+
/** `Escape`, which every region answers. */
|
|
6072
|
+
const ESCAPE = { kind: "escape" };
|
|
6073
|
+
/** `Ctrl+O`, which every region answers. */
|
|
6074
|
+
const FOLD_ALL = { kind: "fold-all" };
|
|
6075
|
+
/** `Ctrl+G`, which every region answers. */
|
|
6076
|
+
const READER = { kind: "reader" };
|
|
6077
|
+
/** `Enter` on the held section, row, or segment. */
|
|
6078
|
+
const OPEN = { kind: "open" };
|
|
6311
6079
|
/**
|
|
6312
|
-
*
|
|
6313
|
-
*
|
|
6314
|
-
*
|
|
6315
|
-
*
|
|
6316
|
-
*
|
|
6317
|
-
* @
|
|
6318
|
-
|
|
6319
|
-
|
|
6320
|
-
|
|
6321
|
-
|
|
6322
|
-
const paint = parts.tone === "focus" ? (text) => pulse(palette, palette.accent(text), level) : palette.dim;
|
|
6323
|
-
const leading = [chipText, parts.left ?? ""].filter((text) => text !== "").join(paint(CHIP_JOIN));
|
|
6324
|
-
const head = leading === "" ? paint(open) : `${paint(open)} ${leading} `;
|
|
6325
|
-
const right = parts.right ?? "";
|
|
6326
|
-
const tail = right === "" ? paint(close) : ` ${right} ${paint(close)}`;
|
|
6327
|
-
const room = width - visibleWidth(tail);
|
|
6328
|
-
const cut = room >= 1 ? truncateToWidth(head, room, ELLIPSIS$4) : "";
|
|
6329
|
-
return truncateToWidth(`${cut}${paint(FILL.repeat(Math.max(0, width - visibleWidth(cut) - visibleWidth(tail))))}${tail}`, width, ELLIPSIS$4);
|
|
6330
|
-
}
|
|
6331
|
-
/**
|
|
6332
|
-
* The rule a framed surface opens with.
|
|
6333
|
-
* @param parts - the chip, the title, an optional readout, the width, the
|
|
6334
|
-
* palette, and the tone.
|
|
6335
|
-
* @returns the line, exactly `width` columns.
|
|
6336
|
-
*/
|
|
6337
|
-
function topRule(parts) {
|
|
6338
|
-
const { chip: chipText, title, ...rest } = parts;
|
|
6339
|
-
return rule(TOP_LEFT, TOP_RIGHT, {
|
|
6340
|
-
...rest,
|
|
6341
|
-
left: title ?? ""
|
|
6342
|
-
}, chipText ?? "");
|
|
6343
|
-
}
|
|
6344
|
-
/**
|
|
6345
|
-
* The rule a framed surface ends with, which carries its legend.
|
|
6346
|
-
* @param parts - the legend, an optional readout, the width, the palette, and the tone.
|
|
6347
|
-
* @returns the line, exactly `width` columns.
|
|
6348
|
-
*/
|
|
6349
|
-
function bottomRule(parts) {
|
|
6350
|
-
return rule(BOTTOM_LEFT, BOTTOM_RIGHT, parts, "");
|
|
6351
|
-
}
|
|
6352
|
-
/**
|
|
6353
|
-
* A rule drawn between two parts of one frame, for the legend of a surface
|
|
6354
|
-
* that goes on below it.
|
|
6355
|
-
* @param parts - the legend, an optional readout, the width, the palette, and the tone.
|
|
6356
|
-
* @returns the line, exactly `width` columns.
|
|
6357
|
-
*/
|
|
6358
|
-
function legendRule(parts) {
|
|
6359
|
-
return rule(LEGEND_LEFT, LEGEND_RIGHT, parts, "");
|
|
6360
|
-
}
|
|
6361
|
-
/**
|
|
6362
|
-
* One row inside a frame, closed on both sides: the content is padded to the
|
|
6363
|
-
* room between the borders, so a frame reads as one box however short its
|
|
6364
|
-
* rows are. Content wrapped at {@link BODY_MARGIN} columns less than the width
|
|
6365
|
-
* is drawn whole; anything wider is cut.
|
|
6366
|
-
* @param content - the row, already styled and already wrapped.
|
|
6367
|
-
* @param width - the columns the line must fit.
|
|
6368
|
-
* @param palette - the palette the borders are styled with.
|
|
6369
|
-
* @param tone - which role those borders take.
|
|
6370
|
-
* @param level - how far above its settled drawing the borders are lifted, so
|
|
6371
|
-
* the whole outline of a frame moves as one; `0` draws the settled borders.
|
|
6372
|
-
* @returns the line, exactly `width` columns while both borders fit.
|
|
6373
|
-
*/
|
|
6374
|
-
function bodyLine(content, width, palette, tone, level = 0) {
|
|
6375
|
-
const border = tone === "focus" ? pulse(palette, palette.accent(SIDE$1), level) : palette.dim(SIDE$1);
|
|
6376
|
-
const columns = Math.max(1, width);
|
|
6377
|
-
const room = columns - 4;
|
|
6378
|
-
if (room < 1) return truncateToWidth(`${border} ${content}`, columns, ELLIPSIS$4);
|
|
6379
|
-
const cut = truncateToWidth(content, room, ELLIPSIS$4);
|
|
6380
|
-
return `${border} ${cut}${" ".repeat(Math.max(0, room - visibleWidth(cut)))} ${border}`;
|
|
6381
|
-
}
|
|
6382
|
-
//#endregion
|
|
6383
|
-
//#region lib/types/keys.js
|
|
6384
|
-
/**
|
|
6385
|
-
* The key model: which action one press names in the region that holds the
|
|
6386
|
-
* keyboard, what one press types, how long a focus handoff silences the
|
|
6387
|
-
* editor's `Escape`, and the words every surface uses to name a key - the
|
|
6388
|
-
* legend each region degrades through, the entry keys the status bar
|
|
6389
|
-
* reserves, and the lines `/help` lists per region.
|
|
6390
|
-
*
|
|
6391
|
-
* Pure. It reads key bytes and returns actions, so the application owns every
|
|
6392
|
-
* effect and the whole map is decided without a terminal, a palette, or a
|
|
6393
|
-
* clock.
|
|
6394
|
-
* @module @deepseek-ai/dsh-tui-app/keys
|
|
6395
|
-
*/
|
|
6396
|
-
/** Characters a typed key never carries: C0 controls, DEL, and C1 controls. */
|
|
6397
|
-
const CONTROL_CHARACTERS = /[\u0000-\u001f\u007f-\u009f]/u;
|
|
6398
|
-
/**
|
|
6399
|
-
* The text one key press types.
|
|
6400
|
-
* @param data - the bytes the terminal sent.
|
|
6401
|
-
* @returns the characters to type, or undefined for control keys and escape sequences.
|
|
6402
|
-
*/
|
|
6403
|
-
function typedText(data) {
|
|
6404
|
-
const kitty = decodeKittyPrintable(data);
|
|
6405
|
-
if (kitty !== void 0) return kitty;
|
|
6406
|
-
return CONTROL_CHARACTERS.test(data) ? void 0 : data;
|
|
6407
|
-
}
|
|
6408
|
-
/**
|
|
6409
|
-
* The legend of each region, in declared degradation steps: the widest first,
|
|
6410
|
-
* every next one narrower, the last the shortest form that still names the way
|
|
6411
|
-
* back to the input. One grammar throughout - the keys the region answers,
|
|
6412
|
-
* then where `Esc` goes - so a legend is read the same way on every surface.
|
|
6413
|
-
* The editor draws no legend of its own: the unfocused status bar names the
|
|
6414
|
-
* keys that leave it.
|
|
6415
|
-
*/
|
|
6416
|
-
const HINTS = {
|
|
6417
|
-
editor: [],
|
|
6418
|
-
transcript: [
|
|
6419
|
-
"↑↓ sections · ←→ parts · Space folds · Ctrl+G reader · Esc input",
|
|
6420
|
-
"↑↓ ←→ · Space folds · Esc input",
|
|
6421
|
-
"Esc input"
|
|
6422
|
-
],
|
|
6423
|
-
queue: [
|
|
6424
|
-
"↑↓ select · Enter steer · E edit · I inject · Esc input",
|
|
6425
|
-
"↑↓ · Enter steer · E edit · Esc input",
|
|
6426
|
-
"Esc input"
|
|
6427
|
-
],
|
|
6428
|
-
panel: [
|
|
6429
|
-
"↑↓ children · Enter opens · Tab regions · Esc input",
|
|
6430
|
-
"↑↓ children · Esc input",
|
|
6431
|
-
"Esc input"
|
|
6432
|
-
],
|
|
6433
|
-
bar: [
|
|
6434
|
-
"←→ segments · Enter details · Tab regions · Esc input",
|
|
6435
|
-
"←→ segments · Esc input",
|
|
6436
|
-
"Esc input"
|
|
6437
|
-
]
|
|
6438
|
-
};
|
|
6439
|
-
/**
|
|
6440
|
-
* The regions in the order `/help` lists them: the input first, because it is
|
|
6441
|
-
* where every other region is reached from and returned to. The screen stacks
|
|
6442
|
-
* them in another order, which {@link FocusRegion} states and the `Tab` walk
|
|
6443
|
-
* follows over the regions drawn right now.
|
|
6444
|
-
*/
|
|
6445
|
-
const FOCUS_REGIONS = [
|
|
6446
|
-
"editor",
|
|
6447
|
-
"transcript",
|
|
6448
|
-
"queue",
|
|
6449
|
-
"panel",
|
|
6450
|
-
"bar"
|
|
6451
|
-
];
|
|
6452
|
-
/** What each region is called where it is named rather than drawn. */
|
|
6453
|
-
const REGION_LABELS = {
|
|
6454
|
-
editor: "input",
|
|
6455
|
-
transcript: "conversation",
|
|
6456
|
-
queue: "follow-ups",
|
|
6457
|
-
panel: "subagent panel",
|
|
6458
|
-
bar: "status bar"
|
|
6459
|
-
};
|
|
6460
|
-
/** The two keys that leave the input when no follow-up waits. */
|
|
6461
|
-
const ENTRY_KEYS = "Shift+↑ read · Shift+↓ status";
|
|
6462
|
-
/** The same pair while follow-ups wait: Shift+↑ selects one instead of reading. */
|
|
6463
|
-
const QUEUE_ENTRY_KEYS = "Shift+↑ select · Shift+↓ status";
|
|
6464
|
-
/**
|
|
6465
|
-
* The keys the unfocused follow-ups list names: ↑ on an empty input revises
|
|
6466
|
-
* the newest follow-up, and Shift+↑ is the direction out of the input toward
|
|
6467
|
-
* whatever sits above it.
|
|
6468
|
-
*/
|
|
6469
|
-
const QUEUE_ENTRY_HINT = "↑ edit · Shift+↑ select";
|
|
6470
|
-
/**
|
|
6471
|
-
* The entry keys the unfocused status bar reserves before any fact is placed,
|
|
6472
|
-
* in declared degradation steps. Both directions are named: reaching the
|
|
6473
|
-
* conversation or a waiting follow-up, and reaching the bar, are the two
|
|
6474
|
-
* ways out of the input, and a key nobody can see is a key nobody presses.
|
|
6475
|
-
* @param drawn - whether follow-ups sit above the editor, which Shift+↑ enters.
|
|
6476
|
-
* @returns the widest pair first, then the compact form.
|
|
6477
|
-
*/
|
|
6478
|
-
function entryHints(drawn = {}) {
|
|
6479
|
-
return [drawn.queue === true ? QUEUE_ENTRY_KEYS : ENTRY_KEYS, "Shift+↑↓ nav"];
|
|
6480
|
-
}
|
|
6481
|
-
entryHints();
|
|
6482
|
-
/**
|
|
6483
|
-
* The widest legend step of one region.
|
|
6484
|
-
* @param region - the region holding the keyboard.
|
|
6485
|
-
* @returns the step a surface draws when the width holds it, and the empty
|
|
6486
|
-
* string for the editor, which draws no legend.
|
|
6487
|
-
*/
|
|
6488
|
-
function widestHint(region) {
|
|
6489
|
-
return HINTS[region][0] ?? "";
|
|
6490
|
-
}
|
|
6491
|
-
/**
|
|
6492
|
-
* What `/help` lists per region: the legend the region draws, then the coarse
|
|
6493
|
-
* keys no legend has room for. The legends are read from {@link HINTS} rather
|
|
6494
|
-
* than written again, so a surface and `/help` can never name a key
|
|
6495
|
-
* differently. The editor draws no legend, so its own keys are listed here and
|
|
6496
|
-
* nowhere else. This is the screen's summary, not the complete map; the
|
|
6497
|
-
* package README carries every binding.
|
|
6498
|
-
*/
|
|
6499
|
-
const KEY_LINES = {
|
|
6500
|
-
editor: [
|
|
6501
|
-
"Enter sends · Shift+Enter newline · ↑↓ history · Ctrl+S steers",
|
|
6502
|
-
"Shift+Tab effort list · Shift+←→ words",
|
|
6503
|
-
"@ completes paths and sessions · / completes commands · Tab takes one",
|
|
6504
|
-
"!cmd runs here · the next prompt can read it · !!cmd stays local",
|
|
6505
|
-
`${ENTRY_KEYS} · Ctrl+G reader`,
|
|
6506
|
-
"While follow-ups wait: ↑ on an empty input edits the newest · Shift+↑ selects one",
|
|
6507
|
-
"Ctrl+O folds every tool card and context row",
|
|
6508
|
-
"Ctrl+T todos · Ctrl+P parent session · Ctrl+L redraw · ? keys",
|
|
6509
|
-
"Ctrl+B moves running tool calls to the background · /jobs lists them",
|
|
6510
|
-
"Esc arms the stop · Esc again stops the turn · Esc cancels a running /compact",
|
|
6511
|
-
"Ctrl+C clears the input, twice quits · Ctrl+D quits an empty input"
|
|
6512
|
-
],
|
|
6513
|
-
transcript: [widestHint("transcript"), "Shift+↑↓ blocks · PgUp PgDn turns · Home End ends · Tab regions · Enter reads"],
|
|
6514
|
-
queue: [widestHint("queue")],
|
|
6515
|
-
panel: [widestHint("panel")],
|
|
6516
|
-
bar: [widestHint("bar")]
|
|
6517
|
-
};
|
|
6518
|
-
/** `Escape`, which every region answers. */
|
|
6519
|
-
const ESCAPE = { kind: "escape" };
|
|
6520
|
-
/** `Ctrl+O`, which every region answers. */
|
|
6521
|
-
const FOLD_ALL = { kind: "fold-all" };
|
|
6522
|
-
/** `Ctrl+G`, which every region answers. */
|
|
6523
|
-
const READER = { kind: "reader" };
|
|
6524
|
-
/** `Enter` on the held section, row, or segment. */
|
|
6525
|
-
const OPEN = { kind: "open" };
|
|
6526
|
-
/**
|
|
6527
|
-
* What one key press means where the keyboard is.
|
|
6528
|
-
*
|
|
6529
|
-
* `Escape`, `Ctrl+O`, `Ctrl+G`, `Ctrl+B`, `Ctrl+T`, `Ctrl+P`, and `Ctrl+L`
|
|
6530
|
-
* mean the same thing everywhere and are answered first. Everything else is
|
|
6531
|
-
* the region's own.
|
|
6532
|
-
* @param region - the region holding the keyboard.
|
|
6533
|
-
* @param data - the raw key bytes.
|
|
6534
|
-
* @returns the action to apply, or undefined when this region claims nothing
|
|
6535
|
-
* for the key: the editor lets pi-tui's own editor have it, and a docked
|
|
6536
|
-
* region consumes it without effect.
|
|
6080
|
+
* What one key press means where the keyboard is.
|
|
6081
|
+
*
|
|
6082
|
+
* `Escape`, `Ctrl+O`, `Ctrl+G`, `Ctrl+B`, `Ctrl+T`, `Ctrl+P`, and `Ctrl+L`
|
|
6083
|
+
* mean the same thing everywhere and are answered first. Everything else is
|
|
6084
|
+
* the region's own.
|
|
6085
|
+
* @param region - the region holding the keyboard.
|
|
6086
|
+
* @param data - the raw key bytes.
|
|
6087
|
+
* @returns the action to apply, or undefined when this region claims nothing
|
|
6088
|
+
* for the key: the editor lets pi-tui's own editor have it, and a docked
|
|
6089
|
+
* region consumes it without effect.
|
|
6537
6090
|
*/
|
|
6538
6091
|
function resolveKey(region, data) {
|
|
6539
6092
|
if (matchesKey(data, "escape")) return ESCAPE;
|
|
@@ -6874,262 +6427,1272 @@ function typeKey(data) {
|
|
|
6874
6427
|
};
|
|
6875
6428
|
}
|
|
6876
6429
|
//#endregion
|
|
6877
|
-
//#region lib/types/
|
|
6430
|
+
//#region lib/types/prompts.js
|
|
6878
6431
|
/**
|
|
6879
|
-
*
|
|
6880
|
-
*
|
|
6881
|
-
*
|
|
6882
|
-
*
|
|
6883
|
-
*
|
|
6884
|
-
* It is the focus indicator that is always on screen: the frame is geometry
|
|
6885
|
-
* that appears only while the conversation holds the keyboard, and the chip
|
|
6886
|
-
* names the mode. A block is also marked in place, but only while the
|
|
6887
|
-
* renderer can still repaint its first line (`./navigation.ts`); when it
|
|
6888
|
-
* cannot, the heading says so and the frame itself goes dim, because what
|
|
6889
|
-
* cannot be marked cannot be rewritten either. Rows arrive as the block's
|
|
6890
|
-
* source text with no fade and no palette styling of their own, so a section
|
|
6891
|
-
* that is still streaming grows here as it arrives. A block with several parts
|
|
6892
|
-
* draws them as a numbered wrapping strip `← 1 call · [2 result] →` so
|
|
6893
|
-
* Left/Right walk is visible, the held part is legible without color, and
|
|
6894
|
-
* every part label stays on screen. The keyboard landing here lifts the whole
|
|
6895
|
-
* frame and its chip for a moment (`./motion.ts`); the row count is never part
|
|
6896
|
-
* of that, so the pane takes the same rows on every frame of the landing.
|
|
6897
|
-
* @module @deepseek-ai/dsh-tui-app/inspector
|
|
6432
|
+
* Modal prompts the terminal shows above the editor — the approval and
|
|
6433
|
+
* user-questions seams, list pickers, and read-only detail pages — and the
|
|
6434
|
+
* queue that shows them one at a time.
|
|
6435
|
+
* @module @deepseek-ai/dsh-tui-app/prompts
|
|
6898
6436
|
*/
|
|
6899
|
-
/**
|
|
6900
|
-
const
|
|
6901
|
-
/**
|
|
6902
|
-
const
|
|
6903
|
-
/** What the heading appends while the focused block lies outside the repaint window. */
|
|
6904
|
-
const OFF_SCREEN = " · off screen";
|
|
6905
|
-
/** Opens the numbered parts strip, so Left/Right read as a walk along this row. */
|
|
6906
|
-
const STRIP_START = "← ";
|
|
6907
|
-
/** Closes the numbered parts strip. */
|
|
6908
|
-
const STRIP_END = " →";
|
|
6909
|
-
/** What ends a line the width cut short; one column, so the mark itself fits. */
|
|
6910
|
-
const ELLIPSIS$3 = "…";
|
|
6437
|
+
/** Rows a select list shows before scrolling. */
|
|
6438
|
+
const SELECT_MAX_VISIBLE = 8;
|
|
6439
|
+
/** Call-detail rows an approval shows before folding the rest into a count. */
|
|
6440
|
+
const APPROVAL_DETAIL_MAX_ROWS = 12;
|
|
6911
6441
|
/**
|
|
6912
|
-
*
|
|
6913
|
-
* @param
|
|
6914
|
-
* @
|
|
6915
|
-
* @returns the inspector's lines, none wider than `width`: the top rule with
|
|
6916
|
-
* the chip and the heading, the numbered parts strip when the block has more
|
|
6917
|
-
* than one part (wrapped so every part stays on screen), the folded rows, and
|
|
6918
|
-
* the bottom rule with the legend.
|
|
6919
|
-
*/
|
|
6920
|
-
function renderInspector(view, render) {
|
|
6921
|
-
const { palette } = render;
|
|
6922
|
-
const width = Math.max(1, render.width);
|
|
6923
|
-
const tone = view.highlighted ? "focus" : "muted";
|
|
6924
|
-
const level = tone === "focus" ? view.level ?? 0 : 0;
|
|
6925
|
-
const badge = chip(palette, READ_CHIP);
|
|
6926
|
-
const lines = [topRule({
|
|
6927
|
-
chip: pulse(palette, badge, level),
|
|
6928
|
-
title: heading(view, palette, ruleRoom(width, badge)),
|
|
6929
|
-
width,
|
|
6930
|
-
palette,
|
|
6931
|
-
tone,
|
|
6932
|
-
level
|
|
6933
|
-
})];
|
|
6934
|
-
const room = Math.max(1, width - 4);
|
|
6935
|
-
if (view.parts.length > 1) for (const line of partsStrip(view.parts, palette, room)) lines.push(bodyLine(line, width, palette, tone, level));
|
|
6936
|
-
const body = foldRows(view.rows.flatMap((row) => wrapTextWithAnsi(row, room)), render.previewLines, (hidden) => paintKeys(palette, foldMarker(hidden, "inspector")));
|
|
6937
|
-
for (const row of body) lines.push(bodyLine(row, width, palette, tone, level));
|
|
6938
|
-
lines.push(bottomRule({
|
|
6939
|
-
left: paintKeys(palette, fitLegend(HINTS.transcript, ruleRoom(width))),
|
|
6940
|
-
width,
|
|
6941
|
-
palette,
|
|
6942
|
-
tone,
|
|
6943
|
-
level
|
|
6944
|
-
}));
|
|
6945
|
-
return lines;
|
|
6946
|
-
}
|
|
6947
|
-
/**
|
|
6948
|
-
* The heading the top rule carries. A tool title can run past any terminal,
|
|
6949
|
-
* so the subject is cut first and the off-screen mark stays whole: where the
|
|
6950
|
-
* marked block went must never be what the width hides.
|
|
6951
|
-
* @param view - the section to show.
|
|
6952
|
-
* @param palette - the palette the heading is styled with.
|
|
6953
|
-
* @param room - the columns the rule leaves its title; at least 1.
|
|
6954
|
-
* @returns the heading, with the mark when the block is not on screen.
|
|
6442
|
+
* The trailing row an approval's folded call detail carries.
|
|
6443
|
+
* @param hidden - rows left out.
|
|
6444
|
+
* @returns the marker row.
|
|
6955
6445
|
*/
|
|
6956
|
-
function
|
|
6957
|
-
|
|
6958
|
-
if (view.highlighted) return subject;
|
|
6959
|
-
const suffix = palette.dim(OFF_SCREEN);
|
|
6960
|
-
return `${truncateToWidth(subject, Math.max(1, room - visibleWidth(OFF_SCREEN)), ELLIPSIS$3)}${suffix}`;
|
|
6446
|
+
function approvalFoldMarker(hidden) {
|
|
6447
|
+
return `… ${String(hidden)} more line${hidden === 1 ? "" : "s"}`;
|
|
6961
6448
|
}
|
|
6962
|
-
/**
|
|
6963
|
-
|
|
6964
|
-
|
|
6965
|
-
|
|
6966
|
-
|
|
6967
|
-
|
|
6968
|
-
|
|
6969
|
-
|
|
6970
|
-
|
|
6971
|
-
*/
|
|
6972
|
-
function partsStrip(parts, palette, width) {
|
|
6973
|
-
const tokens = parts.map((part, index) => {
|
|
6974
|
-
const text = `${String(index + 1)} ${part.label}`;
|
|
6975
|
-
return part.focused ? palette.accent(`[${text}]`) : palette.dim(text);
|
|
6976
|
-
});
|
|
6977
|
-
const sep = palette.dim(SEPARATOR$4);
|
|
6978
|
-
const indent = palette.dim(" ");
|
|
6979
|
-
const end = palette.dim(STRIP_END);
|
|
6980
|
-
const indentWidth = visibleWidth(" ");
|
|
6981
|
-
const endWidth = visibleWidth(STRIP_END);
|
|
6982
|
-
const lines = [];
|
|
6983
|
-
let current = palette.dim(STRIP_START);
|
|
6984
|
-
let used = visibleWidth(STRIP_START);
|
|
6985
|
-
const startLine = () => {
|
|
6986
|
-
lines.push(current);
|
|
6987
|
-
current = indent;
|
|
6988
|
-
used = indentWidth;
|
|
6989
|
-
};
|
|
6990
|
-
for (let index = 0; index < tokens.length; index += 1) {
|
|
6991
|
-
const token = tokens[index];
|
|
6992
|
-
/* v8 ignore next -- the loop bound is tokens.length */
|
|
6993
|
-
if (token === void 0) continue;
|
|
6994
|
-
const extra = index === tokens.length - 1 ? endWidth : 0;
|
|
6995
|
-
let leading = index === 0 || current === indent ? "" : sep;
|
|
6996
|
-
let leadingWidth = leading === "" ? 0 : visibleWidth(SEPARATOR$4);
|
|
6997
|
-
const tokenWidth = visibleWidth(token);
|
|
6998
|
-
if (used + leadingWidth + tokenWidth + extra > width && used > indentWidth) {
|
|
6999
|
-
startLine();
|
|
7000
|
-
leading = "";
|
|
7001
|
-
leadingWidth = 0;
|
|
7002
|
-
}
|
|
7003
|
-
const free = Math.max(1, width - used - extra);
|
|
7004
|
-
if (tokenWidth > free) {
|
|
7005
|
-
const wrapped = wrapTextWithAnsi(token, free);
|
|
7006
|
-
const first = wrapped[0];
|
|
7007
|
-
/* v8 ignore next -- wrapTextWithAnsi returns a line for nonempty text */
|
|
7008
|
-
if (first === void 0) continue;
|
|
7009
|
-
current += leading + first;
|
|
7010
|
-
used += leadingWidth + visibleWidth(first);
|
|
7011
|
-
for (const more of wrapped.slice(1)) {
|
|
7012
|
-
startLine();
|
|
7013
|
-
current += more;
|
|
7014
|
-
used += visibleWidth(more);
|
|
7015
|
-
}
|
|
7016
|
-
} else {
|
|
7017
|
-
current += leading + token;
|
|
7018
|
-
used += leadingWidth + tokenWidth;
|
|
7019
|
-
}
|
|
6449
|
+
/** One settlement slot: the first value wins, later values are ignored. */
|
|
6450
|
+
var Settlement = class {
|
|
6451
|
+
settled;
|
|
6452
|
+
resolve;
|
|
6453
|
+
open = true;
|
|
6454
|
+
constructor() {
|
|
6455
|
+
this.settled = new Promise((resolve) => {
|
|
6456
|
+
this.resolve = resolve;
|
|
6457
|
+
});
|
|
7020
6458
|
}
|
|
7021
|
-
|
|
7022
|
-
|
|
7023
|
-
|
|
6459
|
+
/**
|
|
6460
|
+
* Settle with `value` unless already settled.
|
|
6461
|
+
* @param value - the outcome.
|
|
6462
|
+
*/
|
|
6463
|
+
settle(value) {
|
|
6464
|
+
if (!this.open) return;
|
|
6465
|
+
this.open = false;
|
|
6466
|
+
this.resolve(value);
|
|
6467
|
+
}
|
|
6468
|
+
};
|
|
7024
6469
|
/**
|
|
7025
|
-
*
|
|
7026
|
-
*
|
|
7027
|
-
* The view is read once per render rather than pushed in, so a section that is
|
|
7028
|
-
* still streaming and a tool result that has just landed reach the screen with
|
|
7029
|
-
* the frame that draws them, without the application refreshing the pane.
|
|
6470
|
+
* A heading, optional dim indented body rows, then a select list; subclasses
|
|
6471
|
+
* map the chosen row and the cancel key to a value.
|
|
7030
6472
|
*/
|
|
7031
|
-
var
|
|
7032
|
-
|
|
7033
|
-
|
|
6473
|
+
var ListPrompt = class {
|
|
6474
|
+
palette;
|
|
6475
|
+
body;
|
|
6476
|
+
choose;
|
|
6477
|
+
cancel;
|
|
6478
|
+
layout;
|
|
6479
|
+
settled;
|
|
6480
|
+
settlement = new Settlement();
|
|
6481
|
+
heading;
|
|
6482
|
+
list;
|
|
6483
|
+
constructor(palette, heading, body, items, choose, cancel, layout) {
|
|
6484
|
+
this.palette = palette;
|
|
6485
|
+
this.body = body;
|
|
6486
|
+
this.choose = choose;
|
|
6487
|
+
this.cancel = cancel;
|
|
6488
|
+
this.layout = layout;
|
|
6489
|
+
this.settled = this.settlement.settled;
|
|
6490
|
+
this.heading = new Text(heading, 0, 0);
|
|
6491
|
+
this.list = this.listOver(items);
|
|
6492
|
+
}
|
|
7034
6493
|
/**
|
|
7035
|
-
*
|
|
7036
|
-
*
|
|
7037
|
-
*
|
|
6494
|
+
* A select list over `items` wired to this prompt's settlement. `SelectList`
|
|
6495
|
+
* takes its rows at construction and exposes no way to replace them, so a
|
|
6496
|
+
* different row set means a different list.
|
|
6497
|
+
* @param items - the rows to show.
|
|
6498
|
+
* @returns the list, highlighting its first row.
|
|
7038
6499
|
*/
|
|
7039
|
-
|
|
7040
|
-
this.
|
|
7041
|
-
|
|
6500
|
+
listOver(items) {
|
|
6501
|
+
const list = new SelectList(items, SELECT_MAX_VISIBLE, selectListTheme(this.palette), this.layout);
|
|
6502
|
+
list.onSelect = (item) => {
|
|
6503
|
+
this.settlement.settle(this.choose(item));
|
|
6504
|
+
};
|
|
6505
|
+
list.onCancel = () => {
|
|
6506
|
+
this.settlement.settle(this.cancel());
|
|
6507
|
+
};
|
|
6508
|
+
return list;
|
|
7042
6509
|
}
|
|
7043
|
-
invalidate() {}
|
|
7044
6510
|
/**
|
|
7045
|
-
*
|
|
7046
|
-
* @param
|
|
7047
|
-
|
|
6511
|
+
* Show `items` instead of the current rows, highlighting the first one.
|
|
6512
|
+
* @param items - the rows to show.
|
|
6513
|
+
*/
|
|
6514
|
+
setRows(items) {
|
|
6515
|
+
this.list = this.listOver(items);
|
|
6516
|
+
}
|
|
6517
|
+
/**
|
|
6518
|
+
* Settle from outside the list, for withdrawal.
|
|
6519
|
+
* @param value - the outcome.
|
|
6520
|
+
*/
|
|
6521
|
+
settle(value) {
|
|
6522
|
+
this.settlement.settle(value);
|
|
6523
|
+
}
|
|
6524
|
+
/**
|
|
6525
|
+
* Open the list on one row instead of the first.
|
|
6526
|
+
* @param index - the row to highlight.
|
|
6527
|
+
*/
|
|
6528
|
+
highlight(index) {
|
|
6529
|
+
this.list.setSelectedIndex(index);
|
|
6530
|
+
}
|
|
6531
|
+
/**
|
|
6532
|
+
* The row the highlight sits on.
|
|
6533
|
+
* @returns that row, or null while the list shows no row.
|
|
7048
6534
|
*/
|
|
6535
|
+
selected() {
|
|
6536
|
+
return this.list.getSelectedItem();
|
|
6537
|
+
}
|
|
6538
|
+
handleInput(data) {
|
|
6539
|
+
this.list.handleInput(data);
|
|
6540
|
+
}
|
|
6541
|
+
invalidate() {
|
|
6542
|
+
this.heading.invalidate();
|
|
6543
|
+
this.list.invalidate();
|
|
6544
|
+
}
|
|
7049
6545
|
render(width) {
|
|
7050
|
-
const
|
|
7051
|
-
|
|
7052
|
-
|
|
7053
|
-
|
|
7054
|
-
|
|
6546
|
+
const inner = Math.max(1, width - 2);
|
|
6547
|
+
const body = this.body.flatMap((line) => wrapTextWithAnsi(this.paintBody(line), inner).map((part) => ` ${part}`));
|
|
6548
|
+
return [
|
|
6549
|
+
"",
|
|
6550
|
+
...this.heading.render(width),
|
|
6551
|
+
...body,
|
|
6552
|
+
...this.listLines(width)
|
|
6553
|
+
];
|
|
6554
|
+
}
|
|
6555
|
+
/**
|
|
6556
|
+
* Style one body row.
|
|
6557
|
+
* @param line - the row, unstyled.
|
|
6558
|
+
* @returns the row dim; a subclass whose rows name keys draws those as chips.
|
|
6559
|
+
*/
|
|
6560
|
+
paintBody(line) {
|
|
6561
|
+
return this.palette.dim(line);
|
|
6562
|
+
}
|
|
6563
|
+
/**
|
|
6564
|
+
* The lines under the body rows: the select list, which a subclass may
|
|
6565
|
+
* precede or replace.
|
|
6566
|
+
* @param width - the terminal width.
|
|
6567
|
+
* @returns the rendered lines.
|
|
6568
|
+
*/
|
|
6569
|
+
listLines(width) {
|
|
6570
|
+
return this.list.render(width);
|
|
7055
6571
|
}
|
|
7056
6572
|
};
|
|
7057
|
-
//#endregion
|
|
7058
|
-
//#region lib/types/navigation.js
|
|
7059
6573
|
/**
|
|
7060
|
-
*
|
|
7061
|
-
*
|
|
7062
|
-
*
|
|
7063
|
-
* in two directions: `Up` / `Down` through every section in reading order —
|
|
7064
|
-
* a system prompt, injected context, the reasoning and the reply of a message,
|
|
7065
|
-
* the call and the result of a tool — and `Left` / `Right` between the parts
|
|
7066
|
-
* of the held block without leaving it. Snapshot contributions are separate
|
|
7067
|
-
* parts of one injected block, so the arrows walk each named piece of context.
|
|
7068
|
-
* A long conversation is also walked coarsely: one block at a time, one turn
|
|
7069
|
-
* at a time over the groups each prompt opens, and to either end.
|
|
7070
|
-
* This module turns the transcript container's children into that list and
|
|
7071
|
-
* moves one cursor over it. Everything here is plain data: no pi-tui, no
|
|
7072
|
-
* palette, no clock. The rows a part carries are the block's own source text,
|
|
7073
|
-
* so the page `Enter` opens shows what the model wrote rather than a rendering
|
|
7074
|
-
* of it.
|
|
7075
|
-
* @module @deepseek-ai/dsh-tui-app/navigation
|
|
7076
|
-
*/
|
|
7077
|
-
/** What separates two facts inside one heading. */
|
|
7078
|
-
const SEPARATOR$3 = " · ";
|
|
7079
|
-
/**
|
|
7080
|
-
* Whether one transcript child is navigable.
|
|
7081
|
-
* @param child - a child of the transcript container.
|
|
7082
|
-
* @returns true when the child carries the navigable marker.
|
|
6574
|
+
* Approval question: allow this one tool call or reject it; Escape rejects.
|
|
6575
|
+
* `detail` is the call's pre-rendered rows, the same text the tool card
|
|
6576
|
+
* shows, drawn dim under the heading and folded past {@link APPROVAL_DETAIL_MAX_ROWS}.
|
|
7083
6577
|
*/
|
|
7084
|
-
|
|
7085
|
-
|
|
7086
|
-
}
|
|
6578
|
+
var ApprovalPrompt = class extends ListPrompt {
|
|
6579
|
+
constructor(palette, toolName, reason, detail = []) {
|
|
6580
|
+
const title = `${palette.warning("?")} ${palette.bold(`Allow ${toolName}?`)}`;
|
|
6581
|
+
super(palette, reason === void 0 ? title : `${title}\n${palette.dim(reason)}`, foldRows(detail, APPROVAL_DETAIL_MAX_ROWS, approvalFoldMarker), [{
|
|
6582
|
+
value: "allowed-once",
|
|
6583
|
+
label: "Allow once",
|
|
6584
|
+
description: "run this call"
|
|
6585
|
+
}, {
|
|
6586
|
+
value: "rejected",
|
|
6587
|
+
label: "Reject",
|
|
6588
|
+
description: "the tool call fails and the model is told"
|
|
6589
|
+
}], (item) => item.value, () => "rejected");
|
|
6590
|
+
}
|
|
6591
|
+
withdraw() {
|
|
6592
|
+
this.settle("cancelled");
|
|
6593
|
+
}
|
|
6594
|
+
};
|
|
6595
|
+
/** Marks the row a picker opened on, so it stays visible after the highlight moves. */
|
|
6596
|
+
const CURRENT_MARK = " ✓";
|
|
6597
|
+
/** What the filter line says while the query is empty. */
|
|
6598
|
+
const FILTER_HINT = "type to filter · Enter selects · Esc cancels";
|
|
7087
6599
|
/**
|
|
7088
|
-
* The
|
|
7089
|
-
* @param
|
|
7090
|
-
* @returns the
|
|
6600
|
+
* The text a picker row is matched against.
|
|
6601
|
+
* @param row - the row.
|
|
6602
|
+
* @returns the label and description joined, so one query can span both.
|
|
7091
6603
|
*/
|
|
7092
|
-
function
|
|
7093
|
-
return
|
|
6604
|
+
function rowText(row) {
|
|
6605
|
+
return row.description === void 0 ? row.label : `${row.label} ${row.description}`;
|
|
7094
6606
|
}
|
|
7095
6607
|
/**
|
|
7096
|
-
*
|
|
7097
|
-
*
|
|
7098
|
-
*
|
|
7099
|
-
*
|
|
6608
|
+
* A generic list picker (models, sessions) with a type-to-filter query.
|
|
6609
|
+
* Printable keys extend the query, Backspace drops its last character, and
|
|
6610
|
+
* Ctrl+U clears it; Escape clears a non-empty query and settles undefined
|
|
6611
|
+
* once the query is empty. The visible rows are the query's fuzzy matches
|
|
6612
|
+
* against each row's label and description, best match first; the row in
|
|
6613
|
+
* force keeps its mark and stays highlighted only while the query is empty.
|
|
6614
|
+
* `Ctrl+S` hands the highlighted row to `onSave` without closing the picker.
|
|
7100
6615
|
*/
|
|
7101
|
-
|
|
7102
|
-
|
|
7103
|
-
|
|
6616
|
+
var PickPrompt = class extends ListPrompt {
|
|
6617
|
+
items;
|
|
6618
|
+
/** Every row in declared order, without the mark, as matched against. */
|
|
6619
|
+
rows;
|
|
6620
|
+
/** The same rows with the in-force one marked, shown while the query is empty. */
|
|
6621
|
+
markedRows;
|
|
6622
|
+
/** Index of the row in force, or -1 when no row is. */
|
|
6623
|
+
inForce;
|
|
6624
|
+
/** What the user has typed, empty until the first printable key. */
|
|
6625
|
+
query = "";
|
|
6626
|
+
/** The rows the list shows: all of them, or the query's matches. */
|
|
6627
|
+
visible;
|
|
6628
|
+
/** What `Ctrl+S` does with the highlighted row, when the caller gave it a meaning. */
|
|
6629
|
+
onSave;
|
|
6630
|
+
/** What `Ctrl+K` does with the highlighted row, when the caller gave it a meaning. */
|
|
6631
|
+
onStop;
|
|
6632
|
+
constructor(palette, title, items, options = {}) {
|
|
6633
|
+
const rows = items.map((item) => ({ ...item }));
|
|
6634
|
+
const inForce = items.findIndex((item) => item.value === options.current);
|
|
6635
|
+
const markedRows = rows.map((row, index) => index === inForce ? {
|
|
6636
|
+
...row,
|
|
6637
|
+
label: `${row.label}${CURRENT_MARK}`
|
|
6638
|
+
} : row);
|
|
6639
|
+
super(palette, `${palette.accent("?")} ${palette.bold(title)}`, options.body ?? [], [...markedRows], (row) => items.find((item) => item.value === row.value), () => void 0, options.layout);
|
|
6640
|
+
this.items = items;
|
|
6641
|
+
this.rows = rows;
|
|
6642
|
+
this.markedRows = markedRows;
|
|
6643
|
+
this.inForce = inForce;
|
|
6644
|
+
this.visible = markedRows;
|
|
6645
|
+
this.onSave = options.onSave;
|
|
6646
|
+
this.onStop = options.onStop;
|
|
6647
|
+
if (inForce > 0) this.highlight(inForce);
|
|
6648
|
+
}
|
|
6649
|
+
/**
|
|
6650
|
+
* Apply `query` and rebuild the visible rows from it.
|
|
6651
|
+
* @param query - the new query; an empty one restores the declared order, the mark, and the row in force.
|
|
6652
|
+
*/
|
|
6653
|
+
setQuery(query) {
|
|
6654
|
+
if (query === this.query) return;
|
|
6655
|
+
this.query = query;
|
|
6656
|
+
this.visible = query === "" ? this.markedRows : fuzzyFilter([...this.rows], query, rowText);
|
|
6657
|
+
this.setRows([...this.visible]);
|
|
6658
|
+
if (query === "" && this.inForce > 0) this.highlight(this.inForce);
|
|
6659
|
+
}
|
|
6660
|
+
withdraw() {
|
|
6661
|
+
this.settle(void 0);
|
|
6662
|
+
}
|
|
6663
|
+
/**
|
|
6664
|
+
* Style one body row: a picker's rows are hints its caller wrote, so the
|
|
6665
|
+
* keys they name are drawn as chips.
|
|
6666
|
+
* @param line - the row, unstyled.
|
|
6667
|
+
* @returns the row dim, its keys as chips.
|
|
6668
|
+
*/
|
|
6669
|
+
paintBody(line) {
|
|
6670
|
+
return paintKeys(this.palette, line, this.palette.dim, "prose");
|
|
6671
|
+
}
|
|
6672
|
+
handleInput(data) {
|
|
6673
|
+
if (matchesKey(data, "escape") && this.query !== "") {
|
|
6674
|
+
this.setQuery("");
|
|
6675
|
+
return;
|
|
6676
|
+
}
|
|
6677
|
+
if (matchesKey(data, "backspace")) {
|
|
6678
|
+
this.setQuery(this.query.slice(0, -1));
|
|
6679
|
+
return;
|
|
6680
|
+
}
|
|
6681
|
+
if (matchesKey(data, "ctrl+u")) {
|
|
6682
|
+
this.setQuery("");
|
|
6683
|
+
return;
|
|
6684
|
+
}
|
|
6685
|
+
if (matchesKey(data, "ctrl+s") || matchesKey(data, "ctrl+k")) {
|
|
6686
|
+
const row = this.selected();
|
|
6687
|
+
const item = row === null ? void 0 : this.items.find((candidate) => candidate.value === row.value);
|
|
6688
|
+
if (item !== void 0) (matchesKey(data, "ctrl+s") ? this.onSave : this.onStop)?.(item);
|
|
6689
|
+
return;
|
|
6690
|
+
}
|
|
6691
|
+
const typed = typedText(data);
|
|
6692
|
+
if (typed === void 0) {
|
|
6693
|
+
super.handleInput(data);
|
|
6694
|
+
return;
|
|
6695
|
+
}
|
|
6696
|
+
this.setQuery(this.query + typed);
|
|
6697
|
+
}
|
|
6698
|
+
listLines(width) {
|
|
6699
|
+
return [this.query === "" ? paintKeys(this.palette, FILTER_HINT) : this.palette.dim(`filter: ${this.query} · ${String(this.visible.length)}/${String(this.rows.length)}`), ...this.query !== "" && this.visible.length === 0 ? [this.palette.dim(` no row matches "${this.query}"`)] : super.listLines(width)];
|
|
6700
|
+
}
|
|
6701
|
+
};
|
|
6702
|
+
/** Detail rows a read-only page draws at once; the rest wait behind a scroll. */
|
|
6703
|
+
const DETAIL_MAX_VISIBLE = 16;
|
|
6704
|
+
/** The keys a read-only detail page answers, drawn dim under its rows. */
|
|
6705
|
+
const DETAIL_HINT = "↑ ↓ scroll · Enter, Esc, or ← returns";
|
|
7104
6706
|
/**
|
|
7105
|
-
*
|
|
7106
|
-
*
|
|
7107
|
-
*
|
|
7108
|
-
*
|
|
6707
|
+
* A read-only page over rows the caller already rendered: an accented
|
|
6708
|
+
* heading, the rows wrapped to the terminal width, and the hint line. `Up`
|
|
6709
|
+
* and `Down` move one row, `PageUp` and `PageDown` a full page, and the hint
|
|
6710
|
+
* line carries the first visible row and the total once the rows pass
|
|
6711
|
+
* {@link DETAIL_MAX_VISIBLE}. `Enter`, `Escape`, and `Left` settle it; every
|
|
6712
|
+
* other key is ignored.
|
|
7109
6713
|
*/
|
|
7110
|
-
|
|
7111
|
-
|
|
7112
|
-
|
|
6714
|
+
var DetailPrompt = class {
|
|
6715
|
+
palette;
|
|
6716
|
+
rows;
|
|
6717
|
+
settled;
|
|
6718
|
+
settlement = new Settlement();
|
|
6719
|
+
heading;
|
|
6720
|
+
/** Index of the first visible wrapped row. */
|
|
6721
|
+
offset = 0;
|
|
6722
|
+
/** Wrapped rows the last render produced, which bounds scrolling; 0 before the first render. */
|
|
6723
|
+
total = 0;
|
|
6724
|
+
constructor(palette, heading, rows) {
|
|
6725
|
+
this.palette = palette;
|
|
6726
|
+
this.rows = rows;
|
|
6727
|
+
this.settled = this.settlement.settled;
|
|
6728
|
+
this.heading = new Text(palette.bold(palette.accent(heading)), 0, 0);
|
|
6729
|
+
}
|
|
6730
|
+
/**
|
|
6731
|
+
* The largest first-visible row index; 0 while every row fits at once.
|
|
6732
|
+
* @returns the index scrolling stops at.
|
|
6733
|
+
*/
|
|
6734
|
+
maxOffset() {
|
|
6735
|
+
return Math.max(0, this.total - DETAIL_MAX_VISIBLE);
|
|
6736
|
+
}
|
|
6737
|
+
/**
|
|
6738
|
+
* Move the visible window, stopping at both ends.
|
|
6739
|
+
* @param step - rows to move by; negative scrolls toward the first row.
|
|
6740
|
+
*/
|
|
6741
|
+
scroll(step) {
|
|
6742
|
+
this.offset = Math.max(0, Math.min(this.offset + step, this.maxOffset()));
|
|
6743
|
+
}
|
|
6744
|
+
withdraw() {
|
|
6745
|
+
this.settlement.settle();
|
|
6746
|
+
}
|
|
6747
|
+
handleInput(data) {
|
|
6748
|
+
if (matchesKey(data, "up")) this.scroll(-1);
|
|
6749
|
+
else if (matchesKey(data, "down")) this.scroll(1);
|
|
6750
|
+
else if (matchesKey(data, "pageUp")) this.scroll(-16);
|
|
6751
|
+
else if (matchesKey(data, "pageDown")) this.scroll(DETAIL_MAX_VISIBLE);
|
|
6752
|
+
else if (matchesKey(data, "enter") || matchesKey(data, "escape") || matchesKey(data, "left")) this.settlement.settle();
|
|
6753
|
+
}
|
|
6754
|
+
invalidate() {
|
|
6755
|
+
this.heading.invalidate();
|
|
6756
|
+
}
|
|
6757
|
+
render(width) {
|
|
6758
|
+
const wrapped = this.rows.flatMap((row) => wrapTextWithAnsi(row, Math.max(1, width)));
|
|
6759
|
+
this.total = wrapped.length;
|
|
6760
|
+
this.offset = Math.min(this.offset, this.maxOffset());
|
|
6761
|
+
const position = this.maxOffset() === 0 ? "" : ` · (${String(this.offset + 1)}/${String(this.total)})`;
|
|
6762
|
+
return [
|
|
6763
|
+
"",
|
|
6764
|
+
...this.heading.render(width),
|
|
6765
|
+
...wrapped.slice(this.offset, this.offset + DETAIL_MAX_VISIBLE),
|
|
6766
|
+
`${paintKeys(this.palette, DETAIL_HINT)}${position === "" ? "" : this.palette.dim(position)}`
|
|
6767
|
+
];
|
|
6768
|
+
}
|
|
6769
|
+
};
|
|
6770
|
+
/** Marker value of the free-text row. */
|
|
6771
|
+
const CUSTOM_VALUE = "\0custom";
|
|
6772
|
+
/** Marker value of the multi-select confirmation row. */
|
|
6773
|
+
const DONE_VALUE = "\0done";
|
|
6774
|
+
/** Marker value of the plan-review row that returns the user to the composer. */
|
|
6775
|
+
const DISCUSS_VALUE = "\0discuss";
|
|
7113
6776
|
/**
|
|
7114
|
-
*
|
|
7115
|
-
*
|
|
7116
|
-
* @
|
|
6777
|
+
* A plan-review row: the fixed verdict label, with the asker's option text as
|
|
6778
|
+
* the description so the user sees what the answer carries.
|
|
6779
|
+
* @param label - the row label.
|
|
6780
|
+
* @param option - the asker's option the row answers with.
|
|
6781
|
+
* @returns the row.
|
|
7117
6782
|
*/
|
|
7118
|
-
function
|
|
7119
|
-
|
|
7120
|
-
|
|
7121
|
-
|
|
6783
|
+
function verdictRow(label, option) {
|
|
6784
|
+
const description = option.description ?? (option.label === label ? void 0 : option.label);
|
|
6785
|
+
return {
|
|
6786
|
+
value: option.label,
|
|
6787
|
+
label,
|
|
6788
|
+
...description === void 0 ? {} : { description }
|
|
7122
6789
|
};
|
|
7123
6790
|
}
|
|
7124
6791
|
/**
|
|
7125
|
-
*
|
|
7126
|
-
*
|
|
7127
|
-
*
|
|
7128
|
-
*
|
|
7129
|
-
*
|
|
7130
|
-
|
|
7131
|
-
|
|
7132
|
-
|
|
6792
|
+
* One `ask_user_question` item: its options as a list, plus a free-text row,
|
|
6793
|
+
* with `detail` rendered as Markdown under the question. Multi-select toggles
|
|
6794
|
+
* with Space and confirms through the `Done` row; a question with no options
|
|
6795
|
+
* opens straight into free text, and Escape there returns to the one-row list
|
|
6796
|
+
* where a second Escape dismisses the question. A plan-review question shows
|
|
6797
|
+
* the plan and offers Approve, Decline (when the asker offered a second
|
|
6798
|
+
* option), and Discuss; the verdicts answer with the asker's option label and
|
|
6799
|
+
* Discuss dismisses the question so the user can reply in the composer.
|
|
6800
|
+
*/
|
|
6801
|
+
var QuestionPrompt = class {
|
|
6802
|
+
palette;
|
|
6803
|
+
question;
|
|
6804
|
+
settled;
|
|
6805
|
+
settlement = new Settlement();
|
|
6806
|
+
heading;
|
|
6807
|
+
detail;
|
|
6808
|
+
list;
|
|
6809
|
+
input = new Input();
|
|
6810
|
+
selected = /* @__PURE__ */ new Set();
|
|
6811
|
+
typing;
|
|
6812
|
+
constructor(palette, question) {
|
|
6813
|
+
this.palette = palette;
|
|
6814
|
+
this.question = question;
|
|
6815
|
+
this.settled = this.settlement.settled;
|
|
6816
|
+
const header = question.header === void 0 ? "" : `${palette.dim(question.header)}\n`;
|
|
6817
|
+
this.heading = new Text(`${header}${palette.warning("?")} ${palette.bold(question.question)}`, 0, 0);
|
|
6818
|
+
this.detail = question.detail === void 0 ? void 0 : new Markdown(question.detail, 0, 0, markdownTheme(palette));
|
|
6819
|
+
const options = question.options ?? [];
|
|
6820
|
+
this.typing = options.length === 0;
|
|
6821
|
+
const review = planReviewOptions(question);
|
|
6822
|
+
const items = [];
|
|
6823
|
+
if (review === void 0) {
|
|
6824
|
+
for (const { label, description } of options) items.push({
|
|
6825
|
+
value: label,
|
|
6826
|
+
label,
|
|
6827
|
+
...description === void 0 ? {} : { description }
|
|
6828
|
+
});
|
|
6829
|
+
items.push({
|
|
6830
|
+
value: CUSTOM_VALUE,
|
|
6831
|
+
label: "Type an answer…"
|
|
6832
|
+
});
|
|
6833
|
+
if (question.multiSelect === true) items.push({
|
|
6834
|
+
value: DONE_VALUE,
|
|
6835
|
+
label: "Done",
|
|
6836
|
+
description: "confirm the selection"
|
|
6837
|
+
});
|
|
6838
|
+
} else {
|
|
6839
|
+
items.push(verdictRow("Approve", review.approve));
|
|
6840
|
+
if (review.decline !== void 0) items.push(verdictRow("Decline", review.decline));
|
|
6841
|
+
items.push({
|
|
6842
|
+
value: DISCUSS_VALUE,
|
|
6843
|
+
label: "Discuss",
|
|
6844
|
+
description: "reply in the composer instead"
|
|
6845
|
+
});
|
|
6846
|
+
}
|
|
6847
|
+
this.list = new SelectList(items, SELECT_MAX_VISIBLE, selectListTheme(palette));
|
|
6848
|
+
this.list.onSelect = (item) => {
|
|
6849
|
+
this.choose(item.value);
|
|
6850
|
+
};
|
|
6851
|
+
this.list.onCancel = () => {
|
|
6852
|
+
this.settlement.settle(null);
|
|
6853
|
+
};
|
|
6854
|
+
this.input.onSubmit = (value) => {
|
|
6855
|
+
const custom = value.trim();
|
|
6856
|
+
if (custom === "") return;
|
|
6857
|
+
this.settlement.settle({
|
|
6858
|
+
id: this.question.id,
|
|
6859
|
+
selected: [...this.selected],
|
|
6860
|
+
custom
|
|
6861
|
+
});
|
|
6862
|
+
};
|
|
6863
|
+
this.input.onEscape = () => {
|
|
6864
|
+
this.typing = false;
|
|
6865
|
+
};
|
|
6866
|
+
}
|
|
6867
|
+
choose(value) {
|
|
6868
|
+
if (value === CUSTOM_VALUE) {
|
|
6869
|
+
this.typing = true;
|
|
6870
|
+
return;
|
|
6871
|
+
}
|
|
6872
|
+
if (value === DISCUSS_VALUE) {
|
|
6873
|
+
this.settlement.settle(null);
|
|
6874
|
+
return;
|
|
6875
|
+
}
|
|
6876
|
+
if (value === DONE_VALUE) {
|
|
6877
|
+
this.settlement.settle({
|
|
6878
|
+
id: this.question.id,
|
|
6879
|
+
selected: [...this.selected]
|
|
6880
|
+
});
|
|
6881
|
+
return;
|
|
6882
|
+
}
|
|
6883
|
+
if (this.question.multiSelect === true) {
|
|
6884
|
+
if (this.selected.has(value)) this.selected.delete(value);
|
|
6885
|
+
else this.selected.add(value);
|
|
6886
|
+
return;
|
|
6887
|
+
}
|
|
6888
|
+
this.settlement.settle({
|
|
6889
|
+
id: this.question.id,
|
|
6890
|
+
selected: [value]
|
|
6891
|
+
});
|
|
6892
|
+
}
|
|
6893
|
+
withdraw() {
|
|
6894
|
+
this.settlement.settle(null);
|
|
6895
|
+
}
|
|
6896
|
+
handleInput(data) {
|
|
6897
|
+
if (this.typing) {
|
|
6898
|
+
this.input.handleInput(data);
|
|
6899
|
+
return;
|
|
6900
|
+
}
|
|
6901
|
+
if (this.question.multiSelect === true && matchesKey(data, "space")) {
|
|
6902
|
+
const item = this.list.getSelectedItem();
|
|
6903
|
+
/* v8 ignore next -- the unfiltered list always has a highlighted row */
|
|
6904
|
+
if (item !== null) this.choose(item.value);
|
|
6905
|
+
return;
|
|
6906
|
+
}
|
|
6907
|
+
this.list.handleInput(data);
|
|
6908
|
+
}
|
|
6909
|
+
invalidate() {
|
|
6910
|
+
this.heading.invalidate();
|
|
6911
|
+
this.detail?.invalidate();
|
|
6912
|
+
this.list.invalidate();
|
|
6913
|
+
this.input.invalidate();
|
|
6914
|
+
}
|
|
6915
|
+
render(width) {
|
|
6916
|
+
const lines = ["", ...this.heading.render(width)];
|
|
6917
|
+
if (this.detail !== void 0) lines.push("", ...this.detail.render(width), "");
|
|
6918
|
+
if (this.question.multiSelect === true && this.selected.size > 0) lines.push(...wrapTextWithAnsi(this.palette.dim(`selected: ${[...this.selected].join(", ")}`), width));
|
|
6919
|
+
if (this.typing) {
|
|
6920
|
+
this.input.focused = true;
|
|
6921
|
+
lines.push(...this.input.render(width));
|
|
6922
|
+
lines.push(paintKeys(this.palette, "Enter answers · Esc back to the options"));
|
|
6923
|
+
} else {
|
|
6924
|
+
lines.push(...this.list.render(width));
|
|
6925
|
+
if (this.question.multiSelect === true) lines.push(paintKeys(this.palette, "Space toggles · Enter on Done confirms · Esc cancels"));
|
|
6926
|
+
}
|
|
6927
|
+
return lines;
|
|
6928
|
+
}
|
|
6929
|
+
};
|
|
6930
|
+
/** Continuation of the queue chain after a turn settles either way. */
|
|
6931
|
+
function settledTurn() {}
|
|
6932
|
+
/**
|
|
6933
|
+
* Serialize prompts: one is visible and focused at a time, later ones wait
|
|
6934
|
+
* their turn, and an abort signal withdraws a waiting or visible prompt.
|
|
6935
|
+
*/
|
|
6936
|
+
var ModalQueue = class {
|
|
6937
|
+
host;
|
|
6938
|
+
chain = Promise.resolve();
|
|
6939
|
+
active;
|
|
6940
|
+
constructor(host) {
|
|
6941
|
+
this.host = host;
|
|
6942
|
+
}
|
|
6943
|
+
/**
|
|
6944
|
+
* Whether a prompt currently owns the keyboard.
|
|
6945
|
+
* @returns true while a prompt is visible and focused.
|
|
6946
|
+
*/
|
|
6947
|
+
isActive() {
|
|
6948
|
+
return this.active !== void 0;
|
|
6949
|
+
}
|
|
6950
|
+
/**
|
|
6951
|
+
* Show `prompt` once earlier prompts have settled.
|
|
6952
|
+
* @param prompt - the prompt to show.
|
|
6953
|
+
* @param signal - withdraws the prompt when aborted.
|
|
6954
|
+
* @returns the prompt's settled value.
|
|
6955
|
+
*/
|
|
6956
|
+
run(prompt, signal) {
|
|
6957
|
+
const onAbort = () => {
|
|
6958
|
+
prompt.withdraw();
|
|
6959
|
+
};
|
|
6960
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
6961
|
+
const turn = this.chain.then(async () => {
|
|
6962
|
+
if (signal?.aborted === true) prompt.withdraw();
|
|
6963
|
+
this.active = prompt;
|
|
6964
|
+
this.host.slot.addChild(prompt);
|
|
6965
|
+
this.host.tui.setFocus(prompt);
|
|
6966
|
+
this.host.tui.requestRender();
|
|
6967
|
+
try {
|
|
6968
|
+
return await prompt.settled;
|
|
6969
|
+
} finally {
|
|
6970
|
+
signal?.removeEventListener("abort", onAbort);
|
|
6971
|
+
this.host.slot.removeChild(prompt);
|
|
6972
|
+
this.active = void 0;
|
|
6973
|
+
this.host.tui.setFocus(this.host.focusAfter);
|
|
6974
|
+
this.host.tui.requestRender();
|
|
6975
|
+
}
|
|
6976
|
+
});
|
|
6977
|
+
this.chain = turn.then(settledTurn, settledTurn);
|
|
6978
|
+
return turn;
|
|
6979
|
+
}
|
|
6980
|
+
/** Withdraw the visible prompt, if any. */
|
|
6981
|
+
withdrawActive() {
|
|
6982
|
+
this.active?.withdraw();
|
|
6983
|
+
}
|
|
6984
|
+
};
|
|
6985
|
+
//#endregion
|
|
6986
|
+
//#region lib/types/sandbox.js
|
|
6987
|
+
/** Sandbox backend selection with a live preview of file access. */
|
|
6988
|
+
/**
|
|
6989
|
+
* Preview the highlighted backend without changing session policy. Enter applies
|
|
6990
|
+
* the choice through the caller; Escape keeps the recorded backend.
|
|
6991
|
+
*/
|
|
6992
|
+
var SandboxPrompt = class extends PickPrompt {
|
|
6993
|
+
policy;
|
|
6994
|
+
constructor(palette, provider, session, policy) {
|
|
6995
|
+
const current = provider.backendFor(session);
|
|
6996
|
+
super(palette, "Sandbox backend", [...provider.containerSupported ? [{
|
|
6997
|
+
value: "container",
|
|
6998
|
+
label: "Container",
|
|
6999
|
+
description: "Linux VM · isolated host access"
|
|
7000
|
+
}] : [], {
|
|
7001
|
+
value: "local",
|
|
7002
|
+
label: "Local",
|
|
7003
|
+
description: "This host · native tools and paths"
|
|
7004
|
+
}], {
|
|
7005
|
+
current,
|
|
7006
|
+
body: [`current: ${current} · file policy: ${policy.mode} · Esc keeps it`, ...provider.containerSupported ? [] : ["Container unavailable: requires macOS on Apple silicon and the container CLI."]]
|
|
7007
|
+
});
|
|
7008
|
+
this.policy = policy;
|
|
7009
|
+
}
|
|
7010
|
+
listLines(width) {
|
|
7011
|
+
const lines = super.listLines(width).flatMap((line) => wrapTextWithAnsi(line, Math.max(1, width)));
|
|
7012
|
+
const selected = this.selected();
|
|
7013
|
+
if (selected === null) return lines;
|
|
7014
|
+
const container = selected.value === "container";
|
|
7015
|
+
const unrestricted = this.policy.mode === "danger-full-access";
|
|
7016
|
+
const writes = this.policy.mode === "read-only" ? "BLOCKED · file modifications" : this.policy.mode === "workspace-write" ? "ALLOWED · workspace writes except provider-protected paths; temporary areas may be writable" : "UNRESTRICTED · host file modifications";
|
|
7017
|
+
const preview = [
|
|
7018
|
+
this.palette.bold(`Access preview · ${selected.label.replace(" ✓", "")}`),
|
|
7019
|
+
`Workspace: ${this.policy.workspaceRoot}`,
|
|
7020
|
+
unrestricted ? this.palette.warning("! Sandbox bypassed: commands run on the host, regardless of backend choice.") : `Commands → ${container ? "Linux container → shared workspace" : "host → native file sandbox"}`,
|
|
7021
|
+
`${this.policy.mode === "read-only" ? "−" : "+"} ${writes}`,
|
|
7022
|
+
...container && !unrestricted ? [
|
|
7023
|
+
"+ READ · workspace and configured read-only mounts",
|
|
7024
|
+
"− HOST ACCESS · other host paths and configured secret-file patterns hidden",
|
|
7025
|
+
" Guest files outside shared mounts are not visible to host file tools."
|
|
7026
|
+
] : ["+ READ · host paths (subject to OS permissions)", ...unrestricted ? [] : ["− WRITE · outside permitted paths; provider-protected paths remain blocked"]],
|
|
7027
|
+
"Backend changes do not change file policy or approval settings: use /permission.",
|
|
7028
|
+
"Wider access requires approved one-shot escalation when approvals are enabled."
|
|
7029
|
+
];
|
|
7030
|
+
const inner = Math.max(1, width - 2);
|
|
7031
|
+
return [
|
|
7032
|
+
...lines,
|
|
7033
|
+
"",
|
|
7034
|
+
...preview.flatMap((line) => wrapTextWithAnsi(line, inner).map((part) => ` ${part}`))
|
|
7035
|
+
];
|
|
7036
|
+
}
|
|
7037
|
+
};
|
|
7038
|
+
//#endregion
|
|
7039
|
+
//#region lib/types/export.js
|
|
7040
|
+
/**
|
|
7041
|
+
* `/export`: the same session-log ZIP the browser downloads, written to a
|
|
7042
|
+
* local directory through the export package's archive helpers.
|
|
7043
|
+
* @module @deepseek-ai/dsh-tui-app/export
|
|
7044
|
+
*/
|
|
7045
|
+
/**
|
|
7046
|
+
* Write the session tree (the session, its sub-sessions, and attachments) as
|
|
7047
|
+
* a ZIP archive into `directory`.
|
|
7048
|
+
* @param ctx - plugin context carrying the query, persistence, and attachment services.
|
|
7049
|
+
* @param sessionId - the session to export.
|
|
7050
|
+
* @param directory - the directory the archive is written into.
|
|
7051
|
+
* @param signal - cancels the export.
|
|
7052
|
+
* @returns the archive's absolute path.
|
|
7053
|
+
* @throws when a required service is not composed or the session has no persisted log.
|
|
7054
|
+
*/
|
|
7055
|
+
async function exportSessionZip(ctx, sessionId, directory, signal) {
|
|
7056
|
+
const deps = sessionLogExportDeps(ctx);
|
|
7057
|
+
if (deps.sessionQuery === void 0 || deps.sessionPersistence === void 0 || deps.attachments === void 0) throw new Error("export needs the session query, persistence, and attachment services");
|
|
7058
|
+
const ready = {
|
|
7059
|
+
...deps,
|
|
7060
|
+
sessionQuery: deps.sessionQuery,
|
|
7061
|
+
sessionPersistence: deps.sessionPersistence,
|
|
7062
|
+
attachments: deps.attachments
|
|
7063
|
+
};
|
|
7064
|
+
await flushLiveSessionLog(deps, sessionId, signal);
|
|
7065
|
+
const root = await readSessionLogText(deps.sessionPersistence, sessionId, signal);
|
|
7066
|
+
if (root === void 0) throw new Error(`session ${sessionId} has no persisted log to export`);
|
|
7067
|
+
const path = join(directory, sessionLogZipFilename(sessionId));
|
|
7068
|
+
const archive = streamSessionLogZip(ready, root, sessionId, true, DEFAULT_SESSION_LOG_COMPRESSION_LEVEL, signal);
|
|
7069
|
+
await pipeline(Readable.fromWeb(archive), createWriteStream(path), { signal });
|
|
7070
|
+
return path;
|
|
7071
|
+
}
|
|
7072
|
+
//#endregion
|
|
7073
|
+
//#region lib/types/pace.js
|
|
7074
|
+
/**
|
|
7075
|
+
* Grapheme segmenter for release cuts, so a frame never splits a surrogate
|
|
7076
|
+
* pair, a combining sequence, or a joined emoji.
|
|
7077
|
+
*/
|
|
7078
|
+
const GRAPHEMES = new Intl.Segmenter(void 0, { granularity: "grapheme" });
|
|
7079
|
+
/** The ordered queue of streamed text waiting for a frame. */
|
|
7080
|
+
var StreamPacer = class {
|
|
7081
|
+
drainFrames;
|
|
7082
|
+
entries = [];
|
|
7083
|
+
/** Graphemes the next frame may release beyond its own share. */
|
|
7084
|
+
credit = 0;
|
|
7085
|
+
/** UTF-16 length of the queued text, used as the backlog estimate. */
|
|
7086
|
+
backlog = 0;
|
|
7087
|
+
/** @param options - the drain length in frames. */
|
|
7088
|
+
constructor(options) {
|
|
7089
|
+
this.drainFrames = Math.max(1, options.drainFrames);
|
|
7090
|
+
}
|
|
7091
|
+
/**
|
|
7092
|
+
* Queue one delta.
|
|
7093
|
+
* @param channel - what the text belongs to; a push onto the same channel
|
|
7094
|
+
* as the newest entry extends that entry and keeps its `release`.
|
|
7095
|
+
* @param text - the delta. An empty delta still queues an entry, released
|
|
7096
|
+
* on the next frame at no cost, so a tool name that arrives without
|
|
7097
|
+
* arguments reaches the transcript in order.
|
|
7098
|
+
* @param release - receives the released parts of this entry, in order.
|
|
7099
|
+
*/
|
|
7100
|
+
push(channel, text, release) {
|
|
7101
|
+
const last = this.entries.at(-1);
|
|
7102
|
+
if (last !== void 0 && last.channel === channel) last.text += text;
|
|
7103
|
+
else this.entries.push({
|
|
7104
|
+
channel,
|
|
7105
|
+
text,
|
|
7106
|
+
release
|
|
7107
|
+
});
|
|
7108
|
+
this.backlog += text.length;
|
|
7109
|
+
}
|
|
7110
|
+
/**
|
|
7111
|
+
* Whether text is still waiting for a frame.
|
|
7112
|
+
* @returns true while any entry is queued.
|
|
7113
|
+
*/
|
|
7114
|
+
pending() {
|
|
7115
|
+
return this.entries.length > 0;
|
|
7116
|
+
}
|
|
7117
|
+
/**
|
|
7118
|
+
* Release one frame's share of the backlog.
|
|
7119
|
+
* @returns whether text is still queued after this frame.
|
|
7120
|
+
*/
|
|
7121
|
+
frame() {
|
|
7122
|
+
this.credit += Math.max(1, this.backlog / this.drainFrames);
|
|
7123
|
+
let budget = Math.floor(this.credit);
|
|
7124
|
+
this.credit -= budget;
|
|
7125
|
+
for (let entry = this.entries[0]; entry !== void 0; entry = this.entries[0]) {
|
|
7126
|
+
const cut = cutGraphemes(entry.text, budget);
|
|
7127
|
+
if (cut.graphemes === 0 && entry.text !== "") break;
|
|
7128
|
+
budget -= cut.graphemes;
|
|
7129
|
+
this.backlog -= cut.length;
|
|
7130
|
+
const head = entry.text.slice(0, cut.length);
|
|
7131
|
+
entry.text = entry.text.slice(cut.length);
|
|
7132
|
+
if (entry.text === "") this.entries.shift();
|
|
7133
|
+
entry.release(head);
|
|
7134
|
+
}
|
|
7135
|
+
if (this.entries.length === 0) this.credit = 0;
|
|
7136
|
+
return this.entries.length > 0;
|
|
7137
|
+
}
|
|
7138
|
+
/** Release everything queued, in order, at once. */
|
|
7139
|
+
flush() {
|
|
7140
|
+
const entries = this.entries.splice(0);
|
|
7141
|
+
this.backlog = 0;
|
|
7142
|
+
this.credit = 0;
|
|
7143
|
+
for (const entry of entries) entry.release(entry.text);
|
|
7144
|
+
}
|
|
7145
|
+
/**
|
|
7146
|
+
* Release every queued entry of one channel now, and keep every other
|
|
7147
|
+
* entry in arrival order. A finished thinking block uses this so its
|
|
7148
|
+
* remainder is drawn before later reply text is paced.
|
|
7149
|
+
* @param channel - the channel to release.
|
|
7150
|
+
* @returns whether any entry of that channel was queued.
|
|
7151
|
+
*/
|
|
7152
|
+
flushChannel(channel) {
|
|
7153
|
+
const pending = this.entries.splice(0);
|
|
7154
|
+
const kept = [];
|
|
7155
|
+
const release = [];
|
|
7156
|
+
let backlog = 0;
|
|
7157
|
+
for (const entry of pending) if (entry.channel === channel) release.push(entry);
|
|
7158
|
+
else {
|
|
7159
|
+
kept.push(entry);
|
|
7160
|
+
backlog += entry.text.length;
|
|
7161
|
+
}
|
|
7162
|
+
this.entries.push(...kept);
|
|
7163
|
+
this.backlog = backlog;
|
|
7164
|
+
if (this.entries.length === 0) this.credit = 0;
|
|
7165
|
+
for (const entry of release) entry.release(entry.text);
|
|
7166
|
+
return release.length > 0;
|
|
7167
|
+
}
|
|
7168
|
+
/** Drop everything queued without releasing it. */
|
|
7169
|
+
clear() {
|
|
7170
|
+
this.entries.length = 0;
|
|
7171
|
+
this.backlog = 0;
|
|
7172
|
+
this.credit = 0;
|
|
7173
|
+
}
|
|
7174
|
+
};
|
|
7175
|
+
/**
|
|
7176
|
+
* How many rows of a growing block are drawn, advanced on the application's
|
|
7177
|
+
* frame tick the same way {@link StreamPacer} releases text: each frame draws
|
|
7178
|
+
* `hidden / drainFrames` more rows, at least one, with the fractional part
|
|
7179
|
+
* carried to the next frame. The
|
|
7180
|
+
* block reports its full row count after every render and draws only the
|
|
7181
|
+
* first {@link RowReveal.shown} rows until the reveal catches up.
|
|
7182
|
+
*/
|
|
7183
|
+
var RowReveal = class {
|
|
7184
|
+
drainFrames;
|
|
7185
|
+
count;
|
|
7186
|
+
/** Rows the next frame may draw beyond its own share. */
|
|
7187
|
+
credit = 0;
|
|
7188
|
+
/**
|
|
7189
|
+
* @param drainFrames - frames a hidden run takes to unroll; at least 1.
|
|
7190
|
+
* @param shown - rows drawn before the first frame.
|
|
7191
|
+
*/
|
|
7192
|
+
constructor(drainFrames, shown) {
|
|
7193
|
+
this.drainFrames = Math.max(1, drainFrames);
|
|
7194
|
+
this.count = shown;
|
|
7195
|
+
}
|
|
7196
|
+
/**
|
|
7197
|
+
* Rows drawn right now.
|
|
7198
|
+
* @returns the count, which may exceed the block's rows after {@link RowReveal.settle}.
|
|
7199
|
+
*/
|
|
7200
|
+
shown() {
|
|
7201
|
+
return this.count;
|
|
7202
|
+
}
|
|
7203
|
+
/**
|
|
7204
|
+
* Draw one frame's share of the rows still hidden.
|
|
7205
|
+
* @param total - the block's full row count at its last render.
|
|
7206
|
+
* @returns whether rows are still hidden after this frame.
|
|
7207
|
+
*/
|
|
7208
|
+
frame(total) {
|
|
7209
|
+
if (this.count >= total) {
|
|
7210
|
+
this.credit = 0;
|
|
7211
|
+
return false;
|
|
7212
|
+
}
|
|
7213
|
+
this.credit += (total - this.count) / this.drainFrames;
|
|
7214
|
+
const rows = Math.max(1, Math.floor(this.credit));
|
|
7215
|
+
this.credit = Math.max(0, this.credit - rows);
|
|
7216
|
+
this.count = Math.min(total, this.count + rows);
|
|
7217
|
+
return this.count < total;
|
|
7218
|
+
}
|
|
7219
|
+
/**
|
|
7220
|
+
* Hold the count at the block's full row count, so rows the block loses
|
|
7221
|
+
* later are not owed again when it grows back.
|
|
7222
|
+
* @param total - the block's full row count at this render.
|
|
7223
|
+
*/
|
|
7224
|
+
clamp(total) {
|
|
7225
|
+
if (this.count > total) this.count = total;
|
|
7226
|
+
}
|
|
7227
|
+
/** Draw every row the block has at its next render. */
|
|
7228
|
+
settle() {
|
|
7229
|
+
this.count = Number.POSITIVE_INFINITY;
|
|
7230
|
+
this.credit = 0;
|
|
7231
|
+
}
|
|
7232
|
+
};
|
|
7233
|
+
/**
|
|
7234
|
+
* Measure the longest prefix of `text` that holds at most `limit` graphemes.
|
|
7235
|
+
* @param text - the queued text.
|
|
7236
|
+
* @param limit - graphemes the frame may still release.
|
|
7237
|
+
* @returns the prefix's grapheme count and UTF-16 length.
|
|
7238
|
+
*/
|
|
7239
|
+
function cutGraphemes(text, limit) {
|
|
7240
|
+
if (limit <= 0) return {
|
|
7241
|
+
graphemes: 0,
|
|
7242
|
+
length: 0
|
|
7243
|
+
};
|
|
7244
|
+
let graphemes = 0;
|
|
7245
|
+
let length = 0;
|
|
7246
|
+
for (const part of GRAPHEMES.segment(text)) {
|
|
7247
|
+
if (graphemes === limit) break;
|
|
7248
|
+
graphemes += 1;
|
|
7249
|
+
length += part.segment.length;
|
|
7250
|
+
}
|
|
7251
|
+
return {
|
|
7252
|
+
graphemes,
|
|
7253
|
+
length
|
|
7254
|
+
};
|
|
7255
|
+
}
|
|
7256
|
+
//#endregion
|
|
7257
|
+
//#region lib/types/view-banner.js
|
|
7258
|
+
/**
|
|
7259
|
+
* The line above the editor that says the terminal is showing a subagent
|
|
7260
|
+
* session rather than the main one: the path of views from the main session
|
|
7261
|
+
* down to the one on screen, and the key that goes back one level. The
|
|
7262
|
+
* header names the view too, but it scrolls away with the transcript; this
|
|
7263
|
+
* line stays next to the editor for as long as the view is open, and draws
|
|
7264
|
+
* nothing while the main session is on screen.
|
|
7265
|
+
* @module @deepseek-ai/dsh-tui-app/view-banner
|
|
7266
|
+
*/
|
|
7267
|
+
/** What the trail calls the session the first subagent view was opened from. */
|
|
7268
|
+
const MAIN_SESSION_LABEL = "main";
|
|
7269
|
+
/** What the line calls a subagent view unless the app names the view otherwise. */
|
|
7270
|
+
const SUBAGENT_VIEW_TITLE = "subagent view";
|
|
7271
|
+
/** Glyph the banner opens with; the header marks a subagent view with the same one. */
|
|
7272
|
+
const VIEW_GLYPH = "◆";
|
|
7273
|
+
/** Draws the subagent-view line while a subagent session is on screen. */
|
|
7274
|
+
var ViewBanner = class {
|
|
7275
|
+
palette;
|
|
7276
|
+
/** Labels of the open views, outermost first; empty while the main session is on screen. */
|
|
7277
|
+
views = [];
|
|
7278
|
+
/** @param palette - the palette the line is styled with. */
|
|
7279
|
+
constructor(palette) {
|
|
7280
|
+
this.palette = palette;
|
|
7281
|
+
}
|
|
7282
|
+
/** What the line calls the view on screen. */
|
|
7283
|
+
title = SUBAGENT_VIEW_TITLE;
|
|
7284
|
+
/**
|
|
7285
|
+
* Replace the views the line names.
|
|
7286
|
+
* @param views - the label of every open subagent view, outermost first;
|
|
7287
|
+
* empty draws nothing.
|
|
7288
|
+
* @param title - what the line calls the view on screen; `subagent view` when omitted.
|
|
7289
|
+
*/
|
|
7290
|
+
setViews(views, title = SUBAGENT_VIEW_TITLE) {
|
|
7291
|
+
this.views = [...views];
|
|
7292
|
+
this.title = title;
|
|
7293
|
+
}
|
|
7294
|
+
invalidate() {}
|
|
7295
|
+
/**
|
|
7296
|
+
* Draw the line.
|
|
7297
|
+
* @param width - the columns the line fits.
|
|
7298
|
+
* @returns one banded row while a view is open, and no rows otherwise.
|
|
7299
|
+
*/
|
|
7300
|
+
render(width) {
|
|
7301
|
+
const current = this.views.at(-1);
|
|
7302
|
+
if (current === void 0) return [];
|
|
7303
|
+
const palette = this.palette;
|
|
7304
|
+
const back = this.views.at(-2) ?? "main";
|
|
7305
|
+
const trail = [MAIN_SESSION_LABEL, ...this.views.slice(0, -1)].map((label) => palette.dim(label));
|
|
7306
|
+
return [bandRow(palette, truncateToWidth(` ${[
|
|
7307
|
+
`${palette.warning(VIEW_GLYPH)} ${palette.bold(palette.warning(this.title))}`,
|
|
7308
|
+
[...trail, palette.bold(current)].join(palette.dim(" › ")),
|
|
7309
|
+
`${paintKeys(palette, "Ctrl+P")} ${palette.dim(`back to ${back}`)}`
|
|
7310
|
+
].join(palette.dim(" · "))}`, width, "…"), width)];
|
|
7311
|
+
}
|
|
7312
|
+
};
|
|
7313
|
+
/** Columns the ` ─ ` between the chip and the title takes. */
|
|
7314
|
+
const CHIP_MARGIN = 3;
|
|
7315
|
+
/** What opens a top rule. */
|
|
7316
|
+
const TOP_LEFT = "╭";
|
|
7317
|
+
/** What closes a top rule. */
|
|
7318
|
+
const TOP_RIGHT = "╮";
|
|
7319
|
+
/** What opens a bottom rule. */
|
|
7320
|
+
const BOTTOM_LEFT = "╰";
|
|
7321
|
+
/** What closes a bottom rule. */
|
|
7322
|
+
const BOTTOM_RIGHT = "╯";
|
|
7323
|
+
/** What opens a rule drawn between two parts of one frame. */
|
|
7324
|
+
const LEGEND_LEFT = "├";
|
|
7325
|
+
/** What closes a rule drawn between two parts of one frame. */
|
|
7326
|
+
const LEGEND_RIGHT = "┤";
|
|
7327
|
+
/** What a rule fills the width between its texts with. */
|
|
7328
|
+
const FILL = "─";
|
|
7329
|
+
/** The border drawn on each side of a body row. */
|
|
7330
|
+
const SIDE$1 = "│";
|
|
7331
|
+
/** What separates the chip from the title on a top rule. */
|
|
7332
|
+
const CHIP_JOIN = ` ${FILL} `;
|
|
7333
|
+
/** The mark the chip opens with, the one inverse block this surface draws. */
|
|
7334
|
+
const CHIP_MARK = "●";
|
|
7335
|
+
/** What ends a line the width cut short; one column, so the mark itself fits. */
|
|
7336
|
+
const ELLIPSIS$5 = "…";
|
|
7337
|
+
/**
|
|
7338
|
+
* The chip that names the active mode: the one inverse block this surface
|
|
7339
|
+
* draws, so a mode change is visible at a glance.
|
|
7340
|
+
* @param palette - the palette the chip is styled with.
|
|
7341
|
+
* @param text - the mode's name, as it is drawn.
|
|
7342
|
+
* @returns the chip, padded by one space on each side.
|
|
7343
|
+
*/
|
|
7344
|
+
function chip(palette, text) {
|
|
7345
|
+
return palette.inverse(palette.accent(` ${CHIP_MARK} ${text} `));
|
|
7346
|
+
}
|
|
7347
|
+
/**
|
|
7348
|
+
* Columns a rule leaves its own text.
|
|
7349
|
+
* @param width - the width the rule fits.
|
|
7350
|
+
* @param chipText - the chip a top rule opens with; omitted for a rule with none.
|
|
7351
|
+
* @returns the columns the title, the legend, and the readout share; at least 1.
|
|
7352
|
+
*/
|
|
7353
|
+
function ruleRoom(width, chipText = "") {
|
|
7354
|
+
const chipColumns = chipText === "" ? 0 : visibleWidth(chipText) + CHIP_MARGIN;
|
|
7355
|
+
return Math.max(1, width - 4 - chipColumns);
|
|
7356
|
+
}
|
|
7357
|
+
/**
|
|
7358
|
+
* The widest legend a width can hold.
|
|
7359
|
+
* @param steps - the declared steps, widest first.
|
|
7360
|
+
* @param width - the columns the legend has.
|
|
7361
|
+
* @returns the first step that fits, and the last step when none does — a
|
|
7362
|
+
* surface that names no way back would be worse than one cut short.
|
|
7363
|
+
*/
|
|
7364
|
+
function fitLegend(steps, width) {
|
|
7365
|
+
for (const step of steps) if (visibleWidth(step) <= width) return step;
|
|
7366
|
+
return steps.at(-1) ?? "";
|
|
7367
|
+
}
|
|
7368
|
+
/**
|
|
7369
|
+
* One rule of a frame.
|
|
7370
|
+
* @param open - the opening glyph.
|
|
7371
|
+
* @param close - the closing glyph.
|
|
7372
|
+
* @param parts - the texts, the width, the palette, and the tone.
|
|
7373
|
+
* @param chipText - the chip the rule opens with; empty for a rule with none.
|
|
7374
|
+
* @returns the line, exactly `width` columns while the closing glyph fits.
|
|
7375
|
+
*/
|
|
7376
|
+
function rule(open, close, parts, chipText) {
|
|
7377
|
+
const width = Math.max(1, parts.width);
|
|
7378
|
+
const { palette, level = 0 } = parts;
|
|
7379
|
+
const paint = parts.tone === "focus" ? (text) => pulse(palette, palette.accent(text), level) : palette.dim;
|
|
7380
|
+
const leading = [chipText, parts.left ?? ""].filter((text) => text !== "").join(paint(CHIP_JOIN));
|
|
7381
|
+
const head = leading === "" ? paint(open) : `${paint(open)} ${leading} `;
|
|
7382
|
+
const right = parts.right ?? "";
|
|
7383
|
+
const tail = right === "" ? paint(close) : ` ${right} ${paint(close)}`;
|
|
7384
|
+
const room = width - visibleWidth(tail);
|
|
7385
|
+
const cut = room >= 1 ? truncateToWidth(head, room, ELLIPSIS$5) : "";
|
|
7386
|
+
return truncateToWidth(`${cut}${paint(FILL.repeat(Math.max(0, width - visibleWidth(cut) - visibleWidth(tail))))}${tail}`, width, ELLIPSIS$5);
|
|
7387
|
+
}
|
|
7388
|
+
/**
|
|
7389
|
+
* The rule a framed surface opens with.
|
|
7390
|
+
* @param parts - the chip, the title, an optional readout, the width, the
|
|
7391
|
+
* palette, and the tone.
|
|
7392
|
+
* @returns the line, exactly `width` columns.
|
|
7393
|
+
*/
|
|
7394
|
+
function topRule(parts) {
|
|
7395
|
+
const { chip: chipText, title, ...rest } = parts;
|
|
7396
|
+
return rule(TOP_LEFT, TOP_RIGHT, {
|
|
7397
|
+
...rest,
|
|
7398
|
+
left: title ?? ""
|
|
7399
|
+
}, chipText ?? "");
|
|
7400
|
+
}
|
|
7401
|
+
/**
|
|
7402
|
+
* The rule a framed surface ends with, which carries its legend.
|
|
7403
|
+
* @param parts - the legend, an optional readout, the width, the palette, and the tone.
|
|
7404
|
+
* @returns the line, exactly `width` columns.
|
|
7405
|
+
*/
|
|
7406
|
+
function bottomRule(parts) {
|
|
7407
|
+
return rule(BOTTOM_LEFT, BOTTOM_RIGHT, parts, "");
|
|
7408
|
+
}
|
|
7409
|
+
/**
|
|
7410
|
+
* A rule drawn between two parts of one frame, for the legend of a surface
|
|
7411
|
+
* that goes on below it.
|
|
7412
|
+
* @param parts - the legend, an optional readout, the width, the palette, and the tone.
|
|
7413
|
+
* @returns the line, exactly `width` columns.
|
|
7414
|
+
*/
|
|
7415
|
+
function legendRule(parts) {
|
|
7416
|
+
return rule(LEGEND_LEFT, LEGEND_RIGHT, parts, "");
|
|
7417
|
+
}
|
|
7418
|
+
/**
|
|
7419
|
+
* One row inside a frame, closed on both sides: the content is padded to the
|
|
7420
|
+
* room between the borders, so a frame reads as one box however short its
|
|
7421
|
+
* rows are. Content wrapped at {@link BODY_MARGIN} columns less than the width
|
|
7422
|
+
* is drawn whole; anything wider is cut.
|
|
7423
|
+
* @param content - the row, already styled and already wrapped.
|
|
7424
|
+
* @param width - the columns the line must fit.
|
|
7425
|
+
* @param palette - the palette the borders are styled with.
|
|
7426
|
+
* @param tone - which role those borders take.
|
|
7427
|
+
* @param level - how far above its settled drawing the borders are lifted, so
|
|
7428
|
+
* the whole outline of a frame moves as one; `0` draws the settled borders.
|
|
7429
|
+
* @returns the line, exactly `width` columns while both borders fit.
|
|
7430
|
+
*/
|
|
7431
|
+
function bodyLine(content, width, palette, tone, level = 0) {
|
|
7432
|
+
const border = tone === "focus" ? pulse(palette, palette.accent(SIDE$1), level) : palette.dim(SIDE$1);
|
|
7433
|
+
const columns = Math.max(1, width);
|
|
7434
|
+
const room = columns - 4;
|
|
7435
|
+
if (room < 1) return truncateToWidth(`${border} ${content}`, columns, ELLIPSIS$5);
|
|
7436
|
+
const cut = truncateToWidth(content, room, ELLIPSIS$5);
|
|
7437
|
+
return `${border} ${cut}${" ".repeat(Math.max(0, room - visibleWidth(cut)))} ${border}`;
|
|
7438
|
+
}
|
|
7439
|
+
//#endregion
|
|
7440
|
+
//#region lib/types/inspector.js
|
|
7441
|
+
/**
|
|
7442
|
+
* The docked inspector above the editor: while the keyboard walks the
|
|
7443
|
+
* transcript it frames the focused section - what it is, which part of its
|
|
7444
|
+
* block is held, and that part's own rows, folded at `focusPreviewLines` for
|
|
7445
|
+
* every section kind, with the reader drawing the rest.
|
|
7446
|
+
*
|
|
7447
|
+
* It is the focus indicator that is always on screen: the frame is geometry
|
|
7448
|
+
* that appears only while the conversation holds the keyboard, and the chip
|
|
7449
|
+
* names the mode. A block is also marked in place, but only while the
|
|
7450
|
+
* renderer can still repaint its first line (`./navigation.ts`); when it
|
|
7451
|
+
* cannot, the heading says so and the frame itself goes dim, because what
|
|
7452
|
+
* cannot be marked cannot be rewritten either. Rows arrive as the block's
|
|
7453
|
+
* source text with no fade and no palette styling of their own, so a section
|
|
7454
|
+
* that is still streaming grows here as it arrives. A block with several parts
|
|
7455
|
+
* draws them as a numbered wrapping strip `← 1 call · [2 result] →` so
|
|
7456
|
+
* Left/Right walk is visible, the held part is legible without color, and
|
|
7457
|
+
* every part label stays on screen. The keyboard landing here lifts the whole
|
|
7458
|
+
* frame and its chip for a moment (`./motion.ts`); the row count is never part
|
|
7459
|
+
* of that, so the pane takes the same rows on every frame of the landing.
|
|
7460
|
+
* @module @deepseek-ai/dsh-tui-app/inspector
|
|
7461
|
+
*/
|
|
7462
|
+
/** What the chip names this mode. */
|
|
7463
|
+
const READ_CHIP = "READ";
|
|
7464
|
+
/** What separates two labels of the parts strip. */
|
|
7465
|
+
const SEPARATOR$4 = " · ";
|
|
7466
|
+
/** What the heading appends while the focused block lies outside the repaint window. */
|
|
7467
|
+
const OFF_SCREEN = " · off screen";
|
|
7468
|
+
/** Opens the numbered parts strip, so Left/Right read as a walk along this row. */
|
|
7469
|
+
const STRIP_START = "← ";
|
|
7470
|
+
/** Closes the numbered parts strip. */
|
|
7471
|
+
const STRIP_END = " →";
|
|
7472
|
+
/** What ends a line the width cut short; one column, so the mark itself fits. */
|
|
7473
|
+
const ELLIPSIS$4 = "…";
|
|
7474
|
+
/**
|
|
7475
|
+
* Draw the focused section.
|
|
7476
|
+
* @param view - the section to show.
|
|
7477
|
+
* @param render - the palette, the row budget, and the width.
|
|
7478
|
+
* @returns the inspector's lines, none wider than `width`: the top rule with
|
|
7479
|
+
* the chip and the heading, the numbered parts strip when the block has more
|
|
7480
|
+
* than one part (wrapped so every part stays on screen), the folded rows, and
|
|
7481
|
+
* the bottom rule with the legend.
|
|
7482
|
+
*/
|
|
7483
|
+
function renderInspector(view, render) {
|
|
7484
|
+
const { palette } = render;
|
|
7485
|
+
const width = Math.max(1, render.width);
|
|
7486
|
+
const tone = view.highlighted ? "focus" : "muted";
|
|
7487
|
+
const level = tone === "focus" ? view.level ?? 0 : 0;
|
|
7488
|
+
const badge = chip(palette, READ_CHIP);
|
|
7489
|
+
const lines = [topRule({
|
|
7490
|
+
chip: pulse(palette, badge, level),
|
|
7491
|
+
title: heading(view, palette, ruleRoom(width, badge)),
|
|
7492
|
+
width,
|
|
7493
|
+
palette,
|
|
7494
|
+
tone,
|
|
7495
|
+
level
|
|
7496
|
+
})];
|
|
7497
|
+
const room = Math.max(1, width - 4);
|
|
7498
|
+
if (view.parts.length > 1) for (const line of partsStrip(view.parts, palette, room)) lines.push(bodyLine(line, width, palette, tone, level));
|
|
7499
|
+
const body = foldRows(view.rows.flatMap((row) => wrapTextWithAnsi(row, room)), render.previewLines, (hidden) => paintKeys(palette, foldMarker(hidden, "inspector")));
|
|
7500
|
+
for (const row of body) lines.push(bodyLine(row, width, palette, tone, level));
|
|
7501
|
+
lines.push(bottomRule({
|
|
7502
|
+
left: paintKeys(palette, fitLegend(HINTS.transcript, ruleRoom(width))),
|
|
7503
|
+
width,
|
|
7504
|
+
palette,
|
|
7505
|
+
tone,
|
|
7506
|
+
level
|
|
7507
|
+
}));
|
|
7508
|
+
return lines;
|
|
7509
|
+
}
|
|
7510
|
+
/**
|
|
7511
|
+
* The heading the top rule carries. A tool title can run past any terminal,
|
|
7512
|
+
* so the subject is cut first and the off-screen mark stays whole: where the
|
|
7513
|
+
* marked block went must never be what the width hides.
|
|
7514
|
+
* @param view - the section to show.
|
|
7515
|
+
* @param palette - the palette the heading is styled with.
|
|
7516
|
+
* @param room - the columns the rule leaves its title; at least 1.
|
|
7517
|
+
* @returns the heading, with the mark when the block is not on screen.
|
|
7518
|
+
*/
|
|
7519
|
+
function heading(view, palette, room) {
|
|
7520
|
+
const subject = palette.bold(palette.accent(view.heading));
|
|
7521
|
+
if (view.highlighted) return subject;
|
|
7522
|
+
const suffix = palette.dim(OFF_SCREEN);
|
|
7523
|
+
return `${truncateToWidth(subject, Math.max(1, room - visibleWidth(OFF_SCREEN)), ELLIPSIS$4)}${suffix}`;
|
|
7524
|
+
}
|
|
7525
|
+
/**
|
|
7526
|
+
* Draw the parts of the focused block as numbered choices that wrap rather
|
|
7527
|
+
* than disappearing past the width. `Left` / `Right` move along this list:
|
|
7528
|
+
* each label is `N name`, the held one is bracketed and accented, and the
|
|
7529
|
+
* arrows mark that the walk stays inside this block.
|
|
7530
|
+
* @param parts - the labels in reading order, the held one marked.
|
|
7531
|
+
* @param palette - the palette the labels are styled with.
|
|
7532
|
+
* @param width - the width each line must fit inside the frame; at least 1.
|
|
7533
|
+
* @returns the strip lines, every part present.
|
|
7534
|
+
*/
|
|
7535
|
+
function partsStrip(parts, palette, width) {
|
|
7536
|
+
const tokens = parts.map((part, index) => {
|
|
7537
|
+
const text = `${String(index + 1)} ${part.label}`;
|
|
7538
|
+
return part.focused ? palette.accent(`[${text}]`) : palette.dim(text);
|
|
7539
|
+
});
|
|
7540
|
+
const sep = palette.dim(SEPARATOR$4);
|
|
7541
|
+
const indent = palette.dim(" ");
|
|
7542
|
+
const end = palette.dim(STRIP_END);
|
|
7543
|
+
const indentWidth = visibleWidth(" ");
|
|
7544
|
+
const endWidth = visibleWidth(STRIP_END);
|
|
7545
|
+
const lines = [];
|
|
7546
|
+
let current = palette.dim(STRIP_START);
|
|
7547
|
+
let used = visibleWidth(STRIP_START);
|
|
7548
|
+
const startLine = () => {
|
|
7549
|
+
lines.push(current);
|
|
7550
|
+
current = indent;
|
|
7551
|
+
used = indentWidth;
|
|
7552
|
+
};
|
|
7553
|
+
for (let index = 0; index < tokens.length; index += 1) {
|
|
7554
|
+
const token = tokens[index];
|
|
7555
|
+
/* v8 ignore next -- the loop bound is tokens.length */
|
|
7556
|
+
if (token === void 0) continue;
|
|
7557
|
+
const extra = index === tokens.length - 1 ? endWidth : 0;
|
|
7558
|
+
let leading = index === 0 || current === indent ? "" : sep;
|
|
7559
|
+
let leadingWidth = leading === "" ? 0 : visibleWidth(SEPARATOR$4);
|
|
7560
|
+
const tokenWidth = visibleWidth(token);
|
|
7561
|
+
if (used + leadingWidth + tokenWidth + extra > width && used > indentWidth) {
|
|
7562
|
+
startLine();
|
|
7563
|
+
leading = "";
|
|
7564
|
+
leadingWidth = 0;
|
|
7565
|
+
}
|
|
7566
|
+
const free = Math.max(1, width - used - extra);
|
|
7567
|
+
if (tokenWidth > free) {
|
|
7568
|
+
const wrapped = wrapTextWithAnsi(token, free);
|
|
7569
|
+
const first = wrapped[0];
|
|
7570
|
+
/* v8 ignore next -- wrapTextWithAnsi returns a line for nonempty text */
|
|
7571
|
+
if (first === void 0) continue;
|
|
7572
|
+
current += leading + first;
|
|
7573
|
+
used += leadingWidth + visibleWidth(first);
|
|
7574
|
+
for (const more of wrapped.slice(1)) {
|
|
7575
|
+
startLine();
|
|
7576
|
+
current += more;
|
|
7577
|
+
used += visibleWidth(more);
|
|
7578
|
+
}
|
|
7579
|
+
} else {
|
|
7580
|
+
current += leading + token;
|
|
7581
|
+
used += leadingWidth + tokenWidth;
|
|
7582
|
+
}
|
|
7583
|
+
}
|
|
7584
|
+
lines.push(`${current}${end}`);
|
|
7585
|
+
return lines;
|
|
7586
|
+
}
|
|
7587
|
+
/**
|
|
7588
|
+
* The inspector as a mounted component.
|
|
7589
|
+
*
|
|
7590
|
+
* The view is read once per render rather than pushed in, so a section that is
|
|
7591
|
+
* still streaming and a tool result that has just landed reach the screen with
|
|
7592
|
+
* the frame that draws them, without the application refreshing the pane.
|
|
7593
|
+
*/
|
|
7594
|
+
var InspectorPane = class {
|
|
7595
|
+
view;
|
|
7596
|
+
settings;
|
|
7597
|
+
/**
|
|
7598
|
+
* @param view - reads the section to draw; undefined draws nothing at all,
|
|
7599
|
+
* which is what an unmounted moment and a transcript with no cursor yield.
|
|
7600
|
+
* @param settings - the palette and the row budget; the width arrives per render.
|
|
7601
|
+
*/
|
|
7602
|
+
constructor(view, settings) {
|
|
7603
|
+
this.view = view;
|
|
7604
|
+
this.settings = settings;
|
|
7605
|
+
}
|
|
7606
|
+
invalidate() {}
|
|
7607
|
+
/**
|
|
7608
|
+
* Draw the focused section at `width`.
|
|
7609
|
+
* @param width - the total width the pane lays out in.
|
|
7610
|
+
* @returns the inspector's lines, or none when no section is focused.
|
|
7611
|
+
*/
|
|
7612
|
+
render(width) {
|
|
7613
|
+
const view = this.view();
|
|
7614
|
+
return view === void 0 ? [] : renderInspector(view, {
|
|
7615
|
+
...this.settings,
|
|
7616
|
+
width
|
|
7617
|
+
});
|
|
7618
|
+
}
|
|
7619
|
+
};
|
|
7620
|
+
//#endregion
|
|
7621
|
+
//#region lib/types/navigation.js
|
|
7622
|
+
/**
|
|
7623
|
+
* The transcript as a list of navigable sections.
|
|
7624
|
+
*
|
|
7625
|
+
* A conversation is drawn as one component per fact, and the keyboard walks it
|
|
7626
|
+
* in two directions: `Up` / `Down` through every section in reading order —
|
|
7627
|
+
* a system prompt, injected context, the reasoning and the reply of a message,
|
|
7628
|
+
* the call and the result of a tool — and `Left` / `Right` between the parts
|
|
7629
|
+
* of the held block without leaving it. Snapshot contributions are separate
|
|
7630
|
+
* parts of one injected block, so the arrows walk each named piece of context.
|
|
7631
|
+
* A long conversation is also walked coarsely: one block at a time, one turn
|
|
7632
|
+
* at a time over the groups each prompt opens, and to either end.
|
|
7633
|
+
* This module turns the transcript container's children into that list and
|
|
7634
|
+
* moves one cursor over it. Everything here is plain data: no pi-tui, no
|
|
7635
|
+
* palette, no clock. The rows a part carries are the block's own source text,
|
|
7636
|
+
* so the page `Enter` opens shows what the model wrote rather than a rendering
|
|
7637
|
+
* of it.
|
|
7638
|
+
* @module @deepseek-ai/dsh-tui-app/navigation
|
|
7639
|
+
*/
|
|
7640
|
+
/** What separates two facts inside one heading. */
|
|
7641
|
+
const SEPARATOR$3 = " · ";
|
|
7642
|
+
/**
|
|
7643
|
+
* Whether one transcript child is navigable.
|
|
7644
|
+
* @param child - a child of the transcript container.
|
|
7645
|
+
* @returns true when the child carries the navigable marker.
|
|
7646
|
+
*/
|
|
7647
|
+
function isSectionSource(child) {
|
|
7648
|
+
return typeof child === "object" && child !== null && child.navigable === true;
|
|
7649
|
+
}
|
|
7650
|
+
/**
|
|
7651
|
+
* The navigable blocks of a transcript, in drawing order.
|
|
7652
|
+
* @param children - the transcript container's children.
|
|
7653
|
+
* @returns the children that expose sections; notices and printed rows are left out.
|
|
7654
|
+
*/
|
|
7655
|
+
function navigableBlocks(children) {
|
|
7656
|
+
return children.filter(isSectionSource);
|
|
7657
|
+
}
|
|
7658
|
+
/**
|
|
7659
|
+
* Hold one index inside a list.
|
|
7660
|
+
* @param index - the wanted index.
|
|
7661
|
+
* @param length - the list length; at least 1.
|
|
7662
|
+
* @returns the index, moved to the nearest end when it falls outside.
|
|
7663
|
+
*/
|
|
7664
|
+
function clampIndex(index, length) {
|
|
7665
|
+
return Math.max(0, Math.min(index, length - 1));
|
|
7666
|
+
}
|
|
7667
|
+
/**
|
|
7668
|
+
* How many parts one block carries.
|
|
7669
|
+
* @param blocks - the navigable blocks.
|
|
7670
|
+
* @param index - the block to count.
|
|
7671
|
+
* @returns the count, and 0 for an index past the list.
|
|
7672
|
+
*/
|
|
7673
|
+
function partCount(blocks, index) {
|
|
7674
|
+
return blocks[index]?.parts().length ?? 0;
|
|
7675
|
+
}
|
|
7676
|
+
/**
|
|
7677
|
+
* The oldest section of the transcript, which `Home` reaches.
|
|
7678
|
+
* @param blocks - the navigable blocks.
|
|
7679
|
+
* @returns the cursor, or undefined when no block carries a section.
|
|
7680
|
+
*/
|
|
7681
|
+
function firstSection(blocks) {
|
|
7682
|
+
for (let block = 0; block < blocks.length; block += 1) if (partCount(blocks, block) > 0) return {
|
|
7683
|
+
block,
|
|
7684
|
+
part: 0
|
|
7685
|
+
};
|
|
7686
|
+
}
|
|
7687
|
+
/**
|
|
7688
|
+
* The newest section of the transcript: the most recent thing the session
|
|
7689
|
+
* produced, which `End` reaches and which the keyboard enters a transcript it
|
|
7690
|
+
* has not walked yet on.
|
|
7691
|
+
* @param blocks - the navigable blocks.
|
|
7692
|
+
* @returns the cursor, or undefined when no block carries a section.
|
|
7693
|
+
*/
|
|
7694
|
+
function lastSection(blocks) {
|
|
7695
|
+
for (let block = blocks.length - 1; block >= 0; block -= 1) {
|
|
7133
7696
|
const parts = partCount(blocks, block);
|
|
7134
7697
|
if (parts > 0) return {
|
|
7135
7698
|
block,
|
|
@@ -7907,7 +8470,7 @@ const WINDOW_MARK_WIDTH = 2;
|
|
|
7907
8470
|
/** Columns the brackets around the selected label take. */
|
|
7908
8471
|
const BRACKET_WIDTH = 2;
|
|
7909
8472
|
/** What ends a line the width cut short; one column, so the mark itself fits. */
|
|
7910
|
-
const ELLIPSIS$
|
|
8473
|
+
const ELLIPSIS$3 = "…";
|
|
7911
8474
|
/** Facts the unfocused line keeps; every other present segment folds into `+N`. */
|
|
7912
8475
|
const KEY_SEGMENT_IDS = new Set([
|
|
7913
8476
|
"model",
|
|
@@ -8112,787 +8675,231 @@ function windowSpan(widths, selected, budget, sep) {
|
|
|
8112
8675
|
/**
|
|
8113
8676
|
* Cut `line` to `width` columns.
|
|
8114
8677
|
* @param line - the already-styled line.
|
|
8115
|
-
* @param width - terminal columns the line must fit; at least 1.
|
|
8116
|
-
* @returns the line, ellipsized when it was wider.
|
|
8117
|
-
*/
|
|
8118
|
-
function fitLine(line, width) {
|
|
8119
|
-
return truncateToWidth(line, Math.max(1, width), ELLIPSIS$
|
|
8120
|
-
}
|
|
8121
|
-
/**
|
|
8122
|
-
* The label the bar draws for the segment it anchors on, which
|
|
8123
|
-
* `buildFooterSegments` always emits first: the full one while it fits its
|
|
8124
|
-
* budget, then the segment's own shorter form, and only then an ellipsis.
|
|
8125
|
-
* @param segment - the anchored segment; absent for an empty bar.
|
|
8126
|
-
* @returns the label, never wider than {@link MODEL_LABEL_WIDTH}.
|
|
8127
|
-
*/
|
|
8128
|
-
function anchorLabel(segment) {
|
|
8129
|
-
if (segment === void 0) return "";
|
|
8130
|
-
if (visibleWidth(segment.label) <= MODEL_LABEL_WIDTH) return segment.label;
|
|
8131
|
-
return truncateToWidth(segment.short ?? segment.label, MODEL_LABEL_WIDTH, ELLIPSIS$2);
|
|
8132
|
-
}
|
|
8133
|
-
/**
|
|
8134
|
-
* The entry keys this width names.
|
|
8135
|
-
* @param width - terminal columns the line must fit.
|
|
8136
|
-
* @param queue - whether follow-ups are drawn, which rewrites Shift+↑.
|
|
8137
|
-
* @returns the widest step that keeps the facts the majority of the line, and
|
|
8138
|
-
* the empty string on a terminal too narrow to spare the columns.
|
|
8139
|
-
*/
|
|
8140
|
-
function entryHint(width, queue) {
|
|
8141
|
-
if (width < HINT_MIN_WIDTH) return "";
|
|
8142
|
-
return fitLegend(entryHints({ queue }), Math.floor(width / HINT_WIDTH_SHARE));
|
|
8143
|
-
}
|
|
8144
|
-
/**
|
|
8145
|
-
* The key facts that fit the middle of the unfocused line.
|
|
8146
|
-
* @param facts - the key labels after the anchor, in bar order.
|
|
8147
|
-
* @param hidden - segments the bar folds away whatever the width, because
|
|
8148
|
-
* they are not among its key facts.
|
|
8149
|
-
* @param room - columns the middle has, the anchor and the hint already taken.
|
|
8150
|
-
* @returns the labels to draw, the `+N` token last when anything is folded.
|
|
8151
|
-
*/
|
|
8152
|
-
function middleFacts(facts, hidden, room) {
|
|
8153
|
-
const drawn = [];
|
|
8154
|
-
let used = 0;
|
|
8155
|
-
for (const label of facts) {
|
|
8156
|
-
const cost = visibleWidth(SEPARATOR$2) + visibleWidth(label);
|
|
8157
|
-
if (used + cost > room) break;
|
|
8158
|
-
used += cost;
|
|
8159
|
-
drawn.push(label);
|
|
8160
|
-
}
|
|
8161
|
-
let folded = hidden + facts.length - drawn.length;
|
|
8162
|
-
if (folded === 0) return drawn;
|
|
8163
|
-
const token = () => `+${String(folded)}`;
|
|
8164
|
-
const fits = () => used + visibleWidth(SEPARATOR$2) + visibleWidth(token()) <= room;
|
|
8165
|
-
while (!fits() && drawn.length > 0) {
|
|
8166
|
-
used -= visibleWidth(SEPARATOR$2) + visibleWidth(drawn.pop());
|
|
8167
|
-
folded += 1;
|
|
8168
|
-
}
|
|
8169
|
-
if (fits()) drawn.push(token());
|
|
8170
|
-
return drawn;
|
|
8171
|
-
}
|
|
8172
|
-
/**
|
|
8173
|
-
* The unfocused line, built from both ends inward: the anchored model label,
|
|
8174
|
-
* the entry keys reserved at the right edge, and the key facts filling
|
|
8175
|
-
* whatever middle is left, every segment they cannot hold folded into `+N`.
|
|
8176
|
-
* @param segments - the segments in bar order.
|
|
8177
|
-
* @param palette - the palette that distinguishes the model, live facts, and entry keys.
|
|
8178
|
-
* @param width - terminal columns the line must fit.
|
|
8179
|
-
* @param queue - whether follow-ups are drawn, which rewrites Shift+↑.
|
|
8180
|
-
* @returns one line with colored key facts and dim secondary facts.
|
|
8181
|
-
*/
|
|
8182
|
-
function unfocusedLine(segments, palette, width, queue) {
|
|
8183
|
-
const [anchor, ...rest] = segments;
|
|
8184
|
-
const model = anchorLabel(anchor);
|
|
8185
|
-
const hint = entryHint(width, queue);
|
|
8186
|
-
const reserved = hint === "" ? 0 : visibleWidth(hint) + HINT_GAP;
|
|
8187
|
-
const facts = rest.filter((segment) => KEY_SEGMENT_IDS.has(segment.id)).map((segment) => {
|
|
8188
|
-
if (segment.id === "turn") return palette.warning(segment.label);
|
|
8189
|
-
if (segment.id === "context") return palette.link(segment.label);
|
|
8190
|
-
if (segment.id === "todo") return palette.success(segment.label);
|
|
8191
|
-
return palette.dim(segment.label);
|
|
8192
|
-
});
|
|
8193
|
-
const drawn = middleFacts(facts, rest.length - facts.length, width - visibleWidth(model) - reserved);
|
|
8194
|
-
const left = [model === "" ? "" : palette.accent(model), ...drawn].filter((token) => token !== "").join(palette.dim(SEPARATOR$2));
|
|
8195
|
-
if (hint === "") return fitLine(left, width);
|
|
8196
|
-
return fitLine(`${left}${" ".repeat(Math.max(1, width - visibleWidth(left) - visibleWidth(hint)))}${paintKeys(palette, hint, palette.link)}`, width);
|
|
8197
|
-
}
|
|
8198
|
-
/**
|
|
8199
|
-
* The first detail row of a printed segment, or the summary of a page segment.
|
|
8200
|
-
* @param segment - the selected segment; absent when the bar has none.
|
|
8201
|
-
* @returns the expansion body.
|
|
8202
|
-
*/
|
|
8203
|
-
function expansionBody(segment) {
|
|
8204
|
-
if (segment === void 0) return "";
|
|
8205
|
-
if (segment.detail.kind === "page") return segment.detail.summary;
|
|
8206
|
-
return segment.detail.rows[0];
|
|
8207
|
-
}
|
|
8208
|
-
/**
|
|
8209
|
-
* The focused second line: the selected segment's summary plus the keys the
|
|
8210
|
-
* bar answers. The legend takes the width's own step before the summary is
|
|
8211
|
-
* measured, so a narrow terminal drops legend words instead of cutting the
|
|
8212
|
-
* way back to the input off the end of the line.
|
|
8213
|
-
* @param segment - the selected segment.
|
|
8214
|
-
* @param palette - the palette the line is dimmed with.
|
|
8215
|
-
* @param width - terminal columns the line must fit.
|
|
8216
|
-
* @returns one dim line.
|
|
8217
|
-
*/
|
|
8218
|
-
function expansionLine(segment, palette, width) {
|
|
8219
|
-
const body = expansionBody(segment);
|
|
8220
|
-
const legend = paintKeys(palette, fitLegend(HINTS.bar, width));
|
|
8221
|
-
const suffix = body === "" ? legend : `${palette.dim(SEPARATOR$2)}${legend}`;
|
|
8222
|
-
const prefix = palette.dim(body);
|
|
8223
|
-
const rest = width - visibleWidth(suffix);
|
|
8224
|
-
if (rest < 1) return fitLine(`${prefix}${suffix}`, width);
|
|
8225
|
-
return `${truncateToWidth(prefix, rest, ELLIPSIS$2)}${suffix}`;
|
|
8226
|
-
}
|
|
8227
|
-
/**
|
|
8228
|
-
* One segment label as the focused bar draws it. The selected one is
|
|
8229
|
-
* bracketed as well as accented, so which segment `Enter` opens is legible
|
|
8230
|
-
* without color, and a walk that just reached it draws it lifted until the
|
|
8231
|
-
* motion settles back onto the accent.
|
|
8232
|
-
* @param text - the label.
|
|
8233
|
-
* @param selected - whether the bar holds this segment.
|
|
8234
|
-
* @param palette - the palette the label is styled with.
|
|
8235
|
-
* @param level - how far above the settled label to lift it.
|
|
8236
|
-
* @returns the styled label.
|
|
8237
|
-
*/
|
|
8238
|
-
function segmentLabel(text, selected, palette, level) {
|
|
8239
|
-
return selected ? pulse(palette, palette.accent(`[${text}]`), level) : palette.dim(text);
|
|
8240
|
-
}
|
|
8241
|
-
/**
|
|
8242
|
-
* The text a selected label keeps where the window cannot hold all of it. The
|
|
8243
|
-
* brackets are what says which segment `Enter` opens on a terminal without
|
|
8244
|
-
* color, so the label's own text is what gives way rather than the bracket
|
|
8245
|
-
* that closes it.
|
|
8246
|
-
* @param text - the label.
|
|
8247
|
-
* @param room - columns the bracketed label may take.
|
|
8248
|
-
* @returns the text, cut so that it and both brackets fit `room`.
|
|
8249
|
-
*/
|
|
8250
|
-
function fitSelected(text, room) {
|
|
8251
|
-
const inside = room - BRACKET_WIDTH;
|
|
8252
|
-
if (visibleWidth(text) <= inside) return text;
|
|
8253
|
-
return truncateToWidth(text, Math.max(1, inside), ELLIPSIS$2);
|
|
8254
|
-
}
|
|
8255
|
-
/**
|
|
8256
|
-
* The segments after the anchor, windowed around the selection. `‹` and `›`
|
|
8257
|
-
* mark the side the window is cut on, so a walk that slid past a fact says so
|
|
8258
|
-
* rather than appearing to have lost it.
|
|
8259
|
-
* @param rest - the segments after the anchored one, in bar order.
|
|
8260
|
-
* @param held - index of the selected segment within them; negative while the
|
|
8261
|
-
* anchor itself is selected, which draws no selection here.
|
|
8262
|
-
* @param palette - the palette the labels and marks are styled with.
|
|
8263
|
-
* @param room - columns left after the anchor.
|
|
8264
|
-
* @param level - how far above its settled drawing the selected label is lifted.
|
|
8265
|
-
* @returns the window, opening with its connector, or the empty string when
|
|
8266
|
-
* the bar draws nothing but its anchor.
|
|
8267
|
-
*/
|
|
8268
|
-
function focusedWindow(rest, held, palette, room, level) {
|
|
8269
|
-
if (rest.length === 0) return "";
|
|
8270
|
-
const sep = palette.dim(SEPARATOR$2);
|
|
8271
|
-
const sepWidth = visibleWidth(SEPARATOR$2);
|
|
8272
|
-
const selected = Math.max(0, held);
|
|
8273
|
-
const budget = room - sepWidth;
|
|
8274
|
-
const cap = budget - (selected < rest.length - 1 ? WINDOW_MARK_WIDTH : 0);
|
|
8275
|
-
const styled = rest.map((segment, index) => segmentLabel(index === held ? fitSelected(segment.label, cap) : segment.label, index === held, palette, level));
|
|
8276
|
-
const widths = styled.map(visibleWidth);
|
|
8277
|
-
const last = rest.length - 1;
|
|
8278
|
-
const opened = windowSpan(widths, selected, budget, sepWidth);
|
|
8279
|
-
const span = opened.end < last ? windowSpan(widths, selected, budget - WINDOW_MARK_WIDTH, sepWidth) : opened;
|
|
8280
|
-
const lead = span.start > 0 ? palette.dim(` ${WINDOW_START} `) : sep;
|
|
8281
|
-
const trail = span.end < last ? palette.dim(` ${WINDOW_END}`) : "";
|
|
8282
|
-
return `${lead}${styled.slice(span.start, span.end + 1).join(sep)}${trail}`;
|
|
8283
|
-
}
|
|
8284
|
-
/**
|
|
8285
|
-
* The focused bar: the anchored model label, a sliding window of the segments
|
|
8286
|
-
* after it, then the expansion line.
|
|
8287
|
-
* @param segments - the segments in bar order.
|
|
8288
|
-
* @param selected - index of the held segment.
|
|
8289
|
-
* @param palette - the palette the labels and hints are styled with.
|
|
8290
|
-
* @param width - terminal columns each line must fit.
|
|
8291
|
-
* @param level - how far above its settled drawing the selected label is lifted.
|
|
8292
|
-
* @returns two lines, the anchor and the selected label always in the first.
|
|
8293
|
-
*/
|
|
8294
|
-
function focusedLines(segments, selected, palette, width, level) {
|
|
8295
|
-
const held = Math.min(Math.max(0, selected), Math.max(0, segments.length - 1));
|
|
8296
|
-
const [anchor, ...rest] = segments;
|
|
8297
|
-
const model = anchor === void 0 ? "" : segmentLabel(anchorLabel(anchor), held === 0, palette, level);
|
|
8298
|
-
return [fitLine(`${model}${focusedWindow(rest, held - 1, palette, width - visibleWidth(model), level)}`, width), expansionLine(segments[held], palette, width)];
|
|
8299
|
-
}
|
|
8300
|
-
/**
|
|
8301
|
-
* Render the footer. Unfocused it is one dim line built from both ends: the
|
|
8302
|
-
* model anchored left, the entry keys anchored right, and the key facts in
|
|
8303
|
-
* between. Focused it is the anchored model, the navigable segments (windowed
|
|
8304
|
-
* to `width` so the selected one is never dropped) and an expansion of that
|
|
8305
|
-
* segment plus the navigation keys. Every returned line fits `width`.
|
|
8306
|
-
* @param segments - the segments in bar order.
|
|
8307
|
-
* @param render - the palette, optional selected index, and terminal width.
|
|
8308
|
-
* @returns the footer lines, one when unfocused and two when focused.
|
|
8309
|
-
*/
|
|
8310
|
-
function renderFooter(segments, render) {
|
|
8311
|
-
const width = Math.max(1, render.width);
|
|
8312
|
-
if (render.selected === void 0) return [unfocusedLine(segments, render.palette, width, render.queue === true)];
|
|
8313
|
-
return focusedLines(segments, render.selected, render.palette, width, render.level ?? 0);
|
|
8314
|
-
}
|
|
8315
|
-
/**
|
|
8316
|
-
* The status bar as a mounted component. The view is read once per render
|
|
8317
|
-
* rather than pushed in, so the terminal width of that frame windows and
|
|
8318
|
-
* truncates the lines.
|
|
8319
|
-
*/
|
|
8320
|
-
var FooterBar = class {
|
|
8321
|
-
view;
|
|
8322
|
-
/**
|
|
8323
|
-
* @param view - reads the segments and selection the bar draws.
|
|
8324
|
-
*/
|
|
8325
|
-
constructor(view) {
|
|
8326
|
-
this.view = view;
|
|
8327
|
-
}
|
|
8328
|
-
invalidate() {}
|
|
8329
|
-
/**
|
|
8330
|
-
* Draw the status bar at `width`.
|
|
8331
|
-
* @param width - the total width the bar lays out in.
|
|
8332
|
-
* @returns the footer lines, each no wider than `width`.
|
|
8333
|
-
*/
|
|
8334
|
-
render(width) {
|
|
8335
|
-
const { segments, render } = this.view();
|
|
8336
|
-
return renderFooter(segments, {
|
|
8337
|
-
...render,
|
|
8338
|
-
width
|
|
8339
|
-
});
|
|
8340
|
-
}
|
|
8341
|
-
};
|
|
8342
|
-
//#endregion
|
|
8343
|
-
//#region lib/types/prompts.js
|
|
8678
|
+
* @param width - terminal columns the line must fit; at least 1.
|
|
8679
|
+
* @returns the line, ellipsized when it was wider.
|
|
8680
|
+
*/
|
|
8681
|
+
function fitLine(line, width) {
|
|
8682
|
+
return truncateToWidth(line, Math.max(1, width), ELLIPSIS$3);
|
|
8683
|
+
}
|
|
8344
8684
|
/**
|
|
8345
|
-
*
|
|
8346
|
-
*
|
|
8347
|
-
*
|
|
8348
|
-
* @
|
|
8685
|
+
* The label the bar draws for the segment it anchors on, which
|
|
8686
|
+
* `buildFooterSegments` always emits first: the full one while it fits its
|
|
8687
|
+
* budget, then the segment's own shorter form, and only then an ellipsis.
|
|
8688
|
+
* @param segment - the anchored segment; absent for an empty bar.
|
|
8689
|
+
* @returns the label, never wider than {@link MODEL_LABEL_WIDTH}.
|
|
8349
8690
|
*/
|
|
8350
|
-
|
|
8351
|
-
|
|
8352
|
-
|
|
8353
|
-
|
|
8691
|
+
function anchorLabel(segment) {
|
|
8692
|
+
if (segment === void 0) return "";
|
|
8693
|
+
if (visibleWidth(segment.label) <= MODEL_LABEL_WIDTH) return segment.label;
|
|
8694
|
+
return truncateToWidth(segment.short ?? segment.label, MODEL_LABEL_WIDTH, ELLIPSIS$3);
|
|
8695
|
+
}
|
|
8354
8696
|
/**
|
|
8355
|
-
* The
|
|
8356
|
-
* @param
|
|
8357
|
-
* @
|
|
8697
|
+
* The entry keys this width names.
|
|
8698
|
+
* @param width - terminal columns the line must fit.
|
|
8699
|
+
* @param queue - whether follow-ups are drawn, which rewrites Shift+↑.
|
|
8700
|
+
* @returns the widest step that keeps the facts the majority of the line, and
|
|
8701
|
+
* the empty string on a terminal too narrow to spare the columns.
|
|
8358
8702
|
*/
|
|
8359
|
-
function
|
|
8360
|
-
|
|
8703
|
+
function entryHint(width, queue) {
|
|
8704
|
+
if (width < HINT_MIN_WIDTH) return "";
|
|
8705
|
+
return fitLegend(entryHints({ queue }), Math.floor(width / HINT_WIDTH_SHARE));
|
|
8361
8706
|
}
|
|
8362
|
-
/** One settlement slot: the first value wins, later values are ignored. */
|
|
8363
|
-
var Settlement = class {
|
|
8364
|
-
settled;
|
|
8365
|
-
resolve;
|
|
8366
|
-
open = true;
|
|
8367
|
-
constructor() {
|
|
8368
|
-
this.settled = new Promise((resolve) => {
|
|
8369
|
-
this.resolve = resolve;
|
|
8370
|
-
});
|
|
8371
|
-
}
|
|
8372
|
-
/**
|
|
8373
|
-
* Settle with `value` unless already settled.
|
|
8374
|
-
* @param value - the outcome.
|
|
8375
|
-
*/
|
|
8376
|
-
settle(value) {
|
|
8377
|
-
if (!this.open) return;
|
|
8378
|
-
this.open = false;
|
|
8379
|
-
this.resolve(value);
|
|
8380
|
-
}
|
|
8381
|
-
};
|
|
8382
8707
|
/**
|
|
8383
|
-
*
|
|
8384
|
-
*
|
|
8708
|
+
* The key facts that fit the middle of the unfocused line.
|
|
8709
|
+
* @param facts - the key labels after the anchor, in bar order.
|
|
8710
|
+
* @param hidden - segments the bar folds away whatever the width, because
|
|
8711
|
+
* they are not among its key facts.
|
|
8712
|
+
* @param room - columns the middle has, the anchor and the hint already taken.
|
|
8713
|
+
* @returns the labels to draw, the `+N` token last when anything is folded.
|
|
8385
8714
|
*/
|
|
8386
|
-
|
|
8387
|
-
|
|
8388
|
-
|
|
8389
|
-
|
|
8390
|
-
|
|
8391
|
-
|
|
8392
|
-
|
|
8393
|
-
|
|
8394
|
-
heading;
|
|
8395
|
-
list;
|
|
8396
|
-
constructor(palette, heading, body, items, choose, cancel, layout) {
|
|
8397
|
-
this.palette = palette;
|
|
8398
|
-
this.body = body;
|
|
8399
|
-
this.choose = choose;
|
|
8400
|
-
this.cancel = cancel;
|
|
8401
|
-
this.layout = layout;
|
|
8402
|
-
this.settled = this.settlement.settled;
|
|
8403
|
-
this.heading = new Text(heading, 0, 0);
|
|
8404
|
-
this.list = this.listOver(items);
|
|
8405
|
-
}
|
|
8406
|
-
/**
|
|
8407
|
-
* A select list over `items` wired to this prompt's settlement. `SelectList`
|
|
8408
|
-
* takes its rows at construction and exposes no way to replace them, so a
|
|
8409
|
-
* different row set means a different list.
|
|
8410
|
-
* @param items - the rows to show.
|
|
8411
|
-
* @returns the list, highlighting its first row.
|
|
8412
|
-
*/
|
|
8413
|
-
listOver(items) {
|
|
8414
|
-
const list = new SelectList(items, SELECT_MAX_VISIBLE, selectListTheme(this.palette), this.layout);
|
|
8415
|
-
list.onSelect = (item) => {
|
|
8416
|
-
this.settlement.settle(this.choose(item));
|
|
8417
|
-
};
|
|
8418
|
-
list.onCancel = () => {
|
|
8419
|
-
this.settlement.settle(this.cancel());
|
|
8420
|
-
};
|
|
8421
|
-
return list;
|
|
8422
|
-
}
|
|
8423
|
-
/**
|
|
8424
|
-
* Show `items` instead of the current rows, highlighting the first one.
|
|
8425
|
-
* @param items - the rows to show.
|
|
8426
|
-
*/
|
|
8427
|
-
setRows(items) {
|
|
8428
|
-
this.list = this.listOver(items);
|
|
8429
|
-
}
|
|
8430
|
-
/**
|
|
8431
|
-
* Settle from outside the list, for withdrawal.
|
|
8432
|
-
* @param value - the outcome.
|
|
8433
|
-
*/
|
|
8434
|
-
settle(value) {
|
|
8435
|
-
this.settlement.settle(value);
|
|
8436
|
-
}
|
|
8437
|
-
/**
|
|
8438
|
-
* Open the list on one row instead of the first.
|
|
8439
|
-
* @param index - the row to highlight.
|
|
8440
|
-
*/
|
|
8441
|
-
highlight(index) {
|
|
8442
|
-
this.list.setSelectedIndex(index);
|
|
8443
|
-
}
|
|
8444
|
-
/**
|
|
8445
|
-
* The row the highlight sits on.
|
|
8446
|
-
* @returns that row, or null while the list shows no row.
|
|
8447
|
-
*/
|
|
8448
|
-
selected() {
|
|
8449
|
-
return this.list.getSelectedItem();
|
|
8450
|
-
}
|
|
8451
|
-
handleInput(data) {
|
|
8452
|
-
this.list.handleInput(data);
|
|
8453
|
-
}
|
|
8454
|
-
invalidate() {
|
|
8455
|
-
this.heading.invalidate();
|
|
8456
|
-
this.list.invalidate();
|
|
8457
|
-
}
|
|
8458
|
-
render(width) {
|
|
8459
|
-
const inner = Math.max(1, width - 2);
|
|
8460
|
-
const body = this.body.flatMap((line) => wrapTextWithAnsi(this.paintBody(line), inner).map((part) => ` ${part}`));
|
|
8461
|
-
return [
|
|
8462
|
-
"",
|
|
8463
|
-
...this.heading.render(width),
|
|
8464
|
-
...body,
|
|
8465
|
-
...this.listLines(width)
|
|
8466
|
-
];
|
|
8467
|
-
}
|
|
8468
|
-
/**
|
|
8469
|
-
* Style one body row.
|
|
8470
|
-
* @param line - the row, unstyled.
|
|
8471
|
-
* @returns the row dim; a subclass whose rows name keys draws those as chips.
|
|
8472
|
-
*/
|
|
8473
|
-
paintBody(line) {
|
|
8474
|
-
return this.palette.dim(line);
|
|
8715
|
+
function middleFacts(facts, hidden, room) {
|
|
8716
|
+
const drawn = [];
|
|
8717
|
+
let used = 0;
|
|
8718
|
+
for (const label of facts) {
|
|
8719
|
+
const cost = visibleWidth(SEPARATOR$2) + visibleWidth(label);
|
|
8720
|
+
if (used + cost > room) break;
|
|
8721
|
+
used += cost;
|
|
8722
|
+
drawn.push(label);
|
|
8475
8723
|
}
|
|
8476
|
-
|
|
8477
|
-
|
|
8478
|
-
|
|
8479
|
-
|
|
8480
|
-
|
|
8481
|
-
|
|
8482
|
-
|
|
8483
|
-
return this.list.render(width);
|
|
8724
|
+
let folded = hidden + facts.length - drawn.length;
|
|
8725
|
+
if (folded === 0) return drawn;
|
|
8726
|
+
const token = () => `+${String(folded)}`;
|
|
8727
|
+
const fits = () => used + visibleWidth(SEPARATOR$2) + visibleWidth(token()) <= room;
|
|
8728
|
+
while (!fits() && drawn.length > 0) {
|
|
8729
|
+
used -= visibleWidth(SEPARATOR$2) + visibleWidth(drawn.pop());
|
|
8730
|
+
folded += 1;
|
|
8484
8731
|
}
|
|
8485
|
-
|
|
8732
|
+
if (fits()) drawn.push(token());
|
|
8733
|
+
return drawn;
|
|
8734
|
+
}
|
|
8486
8735
|
/**
|
|
8487
|
-
*
|
|
8488
|
-
*
|
|
8489
|
-
*
|
|
8736
|
+
* The unfocused line, built from both ends inward: the anchored model label,
|
|
8737
|
+
* the entry keys reserved at the right edge, and the key facts filling
|
|
8738
|
+
* whatever middle is left, every segment they cannot hold folded into `+N`.
|
|
8739
|
+
* @param segments - the segments in bar order.
|
|
8740
|
+
* @param palette - the palette that distinguishes the model, live facts, and entry keys.
|
|
8741
|
+
* @param width - terminal columns the line must fit.
|
|
8742
|
+
* @param queue - whether follow-ups are drawn, which rewrites Shift+↑.
|
|
8743
|
+
* @returns one line with colored key facts and dim secondary facts.
|
|
8490
8744
|
*/
|
|
8491
|
-
|
|
8492
|
-
|
|
8493
|
-
|
|
8494
|
-
|
|
8495
|
-
|
|
8496
|
-
|
|
8497
|
-
|
|
8498
|
-
|
|
8499
|
-
|
|
8500
|
-
|
|
8501
|
-
|
|
8502
|
-
|
|
8503
|
-
|
|
8504
|
-
|
|
8505
|
-
|
|
8506
|
-
|
|
8507
|
-
};
|
|
8508
|
-
/** Marks the row a picker opened on, so it stays visible after the highlight moves. */
|
|
8509
|
-
const CURRENT_MARK = " ✓";
|
|
8510
|
-
/** What the filter line says while the query is empty. */
|
|
8511
|
-
const FILTER_HINT = "type to filter · Enter selects · Esc cancels";
|
|
8745
|
+
function unfocusedLine(segments, palette, width, queue) {
|
|
8746
|
+
const [anchor, ...rest] = segments;
|
|
8747
|
+
const model = anchorLabel(anchor);
|
|
8748
|
+
const hint = entryHint(width, queue);
|
|
8749
|
+
const reserved = hint === "" ? 0 : visibleWidth(hint) + HINT_GAP;
|
|
8750
|
+
const facts = rest.filter((segment) => KEY_SEGMENT_IDS.has(segment.id)).map((segment) => {
|
|
8751
|
+
if (segment.id === "turn") return palette.warning(segment.label);
|
|
8752
|
+
if (segment.id === "context") return palette.link(segment.label);
|
|
8753
|
+
if (segment.id === "todo") return palette.success(segment.label);
|
|
8754
|
+
return palette.dim(segment.label);
|
|
8755
|
+
});
|
|
8756
|
+
const drawn = middleFacts(facts, rest.length - facts.length, width - visibleWidth(model) - reserved);
|
|
8757
|
+
const left = [model === "" ? "" : palette.accent(model), ...drawn].filter((token) => token !== "").join(palette.dim(SEPARATOR$2));
|
|
8758
|
+
if (hint === "") return fitLine(left, width);
|
|
8759
|
+
return fitLine(`${left}${" ".repeat(Math.max(1, width - visibleWidth(left) - visibleWidth(hint)))}${paintKeys(palette, hint, palette.link)}`, width);
|
|
8760
|
+
}
|
|
8512
8761
|
/**
|
|
8513
|
-
* The
|
|
8514
|
-
* @param
|
|
8515
|
-
* @returns the
|
|
8762
|
+
* The first detail row of a printed segment, or the summary of a page segment.
|
|
8763
|
+
* @param segment - the selected segment; absent when the bar has none.
|
|
8764
|
+
* @returns the expansion body.
|
|
8765
|
+
*/
|
|
8766
|
+
function expansionBody(segment) {
|
|
8767
|
+
if (segment === void 0) return "";
|
|
8768
|
+
if (segment.detail.kind === "page") return segment.detail.summary;
|
|
8769
|
+
return segment.detail.rows[0];
|
|
8770
|
+
}
|
|
8771
|
+
/**
|
|
8772
|
+
* The focused second line: the selected segment's summary plus the keys the
|
|
8773
|
+
* bar answers. The legend takes the width's own step before the summary is
|
|
8774
|
+
* measured, so a narrow terminal drops legend words instead of cutting the
|
|
8775
|
+
* way back to the input off the end of the line.
|
|
8776
|
+
* @param segment - the selected segment.
|
|
8777
|
+
* @param palette - the palette the line is dimmed with.
|
|
8778
|
+
* @param width - terminal columns the line must fit.
|
|
8779
|
+
* @returns one dim line.
|
|
8780
|
+
*/
|
|
8781
|
+
function expansionLine(segment, palette, width) {
|
|
8782
|
+
const body = expansionBody(segment);
|
|
8783
|
+
const legend = paintKeys(palette, fitLegend(HINTS.bar, width));
|
|
8784
|
+
const suffix = body === "" ? legend : `${palette.dim(SEPARATOR$2)}${legend}`;
|
|
8785
|
+
const prefix = palette.dim(body);
|
|
8786
|
+
const rest = width - visibleWidth(suffix);
|
|
8787
|
+
if (rest < 1) return fitLine(`${prefix}${suffix}`, width);
|
|
8788
|
+
return `${truncateToWidth(prefix, rest, ELLIPSIS$3)}${suffix}`;
|
|
8789
|
+
}
|
|
8790
|
+
/**
|
|
8791
|
+
* One segment label as the focused bar draws it. The selected one is
|
|
8792
|
+
* bracketed as well as accented, so which segment `Enter` opens is legible
|
|
8793
|
+
* without color, and a walk that just reached it draws it lifted until the
|
|
8794
|
+
* motion settles back onto the accent.
|
|
8795
|
+
* @param text - the label.
|
|
8796
|
+
* @param selected - whether the bar holds this segment.
|
|
8797
|
+
* @param palette - the palette the label is styled with.
|
|
8798
|
+
* @param level - how far above the settled label to lift it.
|
|
8799
|
+
* @returns the styled label.
|
|
8516
8800
|
*/
|
|
8517
|
-
function
|
|
8518
|
-
return
|
|
8801
|
+
function segmentLabel(text, selected, palette, level) {
|
|
8802
|
+
return selected ? pulse(palette, palette.accent(`[${text}]`), level) : palette.dim(text);
|
|
8519
8803
|
}
|
|
8520
8804
|
/**
|
|
8521
|
-
*
|
|
8522
|
-
*
|
|
8523
|
-
*
|
|
8524
|
-
*
|
|
8525
|
-
*
|
|
8526
|
-
*
|
|
8527
|
-
*
|
|
8805
|
+
* The text a selected label keeps where the window cannot hold all of it. The
|
|
8806
|
+
* brackets are what says which segment `Enter` opens on a terminal without
|
|
8807
|
+
* color, so the label's own text is what gives way rather than the bracket
|
|
8808
|
+
* that closes it.
|
|
8809
|
+
* @param text - the label.
|
|
8810
|
+
* @param room - columns the bracketed label may take.
|
|
8811
|
+
* @returns the text, cut so that it and both brackets fit `room`.
|
|
8528
8812
|
*/
|
|
8529
|
-
|
|
8530
|
-
|
|
8531
|
-
|
|
8532
|
-
|
|
8533
|
-
|
|
8534
|
-
markedRows;
|
|
8535
|
-
/** Index of the row in force, or -1 when no row is. */
|
|
8536
|
-
inForce;
|
|
8537
|
-
/** What the user has typed, empty until the first printable key. */
|
|
8538
|
-
query = "";
|
|
8539
|
-
/** The rows the list shows: all of them, or the query's matches. */
|
|
8540
|
-
visible;
|
|
8541
|
-
/** What `Ctrl+S` does with the highlighted row, when the caller gave it a meaning. */
|
|
8542
|
-
onSave;
|
|
8543
|
-
/** What `Ctrl+K` does with the highlighted row, when the caller gave it a meaning. */
|
|
8544
|
-
onStop;
|
|
8545
|
-
constructor(palette, title, items, options = {}) {
|
|
8546
|
-
const rows = items.map((item) => ({ ...item }));
|
|
8547
|
-
const inForce = items.findIndex((item) => item.value === options.current);
|
|
8548
|
-
const markedRows = rows.map((row, index) => index === inForce ? {
|
|
8549
|
-
...row,
|
|
8550
|
-
label: `${row.label}${CURRENT_MARK}`
|
|
8551
|
-
} : row);
|
|
8552
|
-
super(palette, `${palette.accent("?")} ${palette.bold(title)}`, options.body ?? [], [...markedRows], (row) => items.find((item) => item.value === row.value), () => void 0, options.layout);
|
|
8553
|
-
this.items = items;
|
|
8554
|
-
this.rows = rows;
|
|
8555
|
-
this.markedRows = markedRows;
|
|
8556
|
-
this.inForce = inForce;
|
|
8557
|
-
this.visible = markedRows;
|
|
8558
|
-
this.onSave = options.onSave;
|
|
8559
|
-
this.onStop = options.onStop;
|
|
8560
|
-
if (inForce > 0) this.highlight(inForce);
|
|
8561
|
-
}
|
|
8562
|
-
/**
|
|
8563
|
-
* Apply `query` and rebuild the visible rows from it.
|
|
8564
|
-
* @param query - the new query; an empty one restores the declared order, the mark, and the row in force.
|
|
8565
|
-
*/
|
|
8566
|
-
setQuery(query) {
|
|
8567
|
-
if (query === this.query) return;
|
|
8568
|
-
this.query = query;
|
|
8569
|
-
this.visible = query === "" ? this.markedRows : fuzzyFilter([...this.rows], query, rowText);
|
|
8570
|
-
this.setRows([...this.visible]);
|
|
8571
|
-
if (query === "" && this.inForce > 0) this.highlight(this.inForce);
|
|
8572
|
-
}
|
|
8573
|
-
withdraw() {
|
|
8574
|
-
this.settle(void 0);
|
|
8575
|
-
}
|
|
8576
|
-
/**
|
|
8577
|
-
* Style one body row: a picker's rows are hints its caller wrote, so the
|
|
8578
|
-
* keys they name are drawn as chips.
|
|
8579
|
-
* @param line - the row, unstyled.
|
|
8580
|
-
* @returns the row dim, its keys as chips.
|
|
8581
|
-
*/
|
|
8582
|
-
paintBody(line) {
|
|
8583
|
-
return paintKeys(this.palette, line, this.palette.dim, "prose");
|
|
8584
|
-
}
|
|
8585
|
-
handleInput(data) {
|
|
8586
|
-
if (matchesKey(data, "escape") && this.query !== "") {
|
|
8587
|
-
this.setQuery("");
|
|
8588
|
-
return;
|
|
8589
|
-
}
|
|
8590
|
-
if (matchesKey(data, "backspace")) {
|
|
8591
|
-
this.setQuery(this.query.slice(0, -1));
|
|
8592
|
-
return;
|
|
8593
|
-
}
|
|
8594
|
-
if (matchesKey(data, "ctrl+u")) {
|
|
8595
|
-
this.setQuery("");
|
|
8596
|
-
return;
|
|
8597
|
-
}
|
|
8598
|
-
if (matchesKey(data, "ctrl+s") || matchesKey(data, "ctrl+k")) {
|
|
8599
|
-
const row = this.selected();
|
|
8600
|
-
const item = row === null ? void 0 : this.items.find((candidate) => candidate.value === row.value);
|
|
8601
|
-
if (item !== void 0) (matchesKey(data, "ctrl+s") ? this.onSave : this.onStop)?.(item);
|
|
8602
|
-
return;
|
|
8603
|
-
}
|
|
8604
|
-
const typed = typedText(data);
|
|
8605
|
-
if (typed === void 0) {
|
|
8606
|
-
super.handleInput(data);
|
|
8607
|
-
return;
|
|
8608
|
-
}
|
|
8609
|
-
this.setQuery(this.query + typed);
|
|
8610
|
-
}
|
|
8611
|
-
listLines(width) {
|
|
8612
|
-
return [this.query === "" ? paintKeys(this.palette, FILTER_HINT) : this.palette.dim(`filter: ${this.query} · ${String(this.visible.length)}/${String(this.rows.length)}`), ...this.query !== "" && this.visible.length === 0 ? [this.palette.dim(` no row matches "${this.query}"`)] : super.listLines(width)];
|
|
8613
|
-
}
|
|
8614
|
-
};
|
|
8615
|
-
/** Detail rows a read-only page draws at once; the rest wait behind a scroll. */
|
|
8616
|
-
const DETAIL_MAX_VISIBLE = 16;
|
|
8617
|
-
/** The keys a read-only detail page answers, drawn dim under its rows. */
|
|
8618
|
-
const DETAIL_HINT = "↑ ↓ scroll · Enter, Esc, or ← returns";
|
|
8813
|
+
function fitSelected(text, room) {
|
|
8814
|
+
const inside = room - BRACKET_WIDTH;
|
|
8815
|
+
if (visibleWidth(text) <= inside) return text;
|
|
8816
|
+
return truncateToWidth(text, Math.max(1, inside), ELLIPSIS$3);
|
|
8817
|
+
}
|
|
8619
8818
|
/**
|
|
8620
|
-
*
|
|
8621
|
-
*
|
|
8622
|
-
*
|
|
8623
|
-
*
|
|
8624
|
-
*
|
|
8625
|
-
*
|
|
8819
|
+
* The segments after the anchor, windowed around the selection. `‹` and `›`
|
|
8820
|
+
* mark the side the window is cut on, so a walk that slid past a fact says so
|
|
8821
|
+
* rather than appearing to have lost it.
|
|
8822
|
+
* @param rest - the segments after the anchored one, in bar order.
|
|
8823
|
+
* @param held - index of the selected segment within them; negative while the
|
|
8824
|
+
* anchor itself is selected, which draws no selection here.
|
|
8825
|
+
* @param palette - the palette the labels and marks are styled with.
|
|
8826
|
+
* @param room - columns left after the anchor.
|
|
8827
|
+
* @param level - how far above its settled drawing the selected label is lifted.
|
|
8828
|
+
* @returns the window, opening with its connector, or the empty string when
|
|
8829
|
+
* the bar draws nothing but its anchor.
|
|
8626
8830
|
*/
|
|
8627
|
-
|
|
8628
|
-
|
|
8629
|
-
|
|
8630
|
-
|
|
8631
|
-
|
|
8632
|
-
|
|
8633
|
-
|
|
8634
|
-
|
|
8635
|
-
|
|
8636
|
-
|
|
8637
|
-
|
|
8638
|
-
|
|
8639
|
-
|
|
8640
|
-
|
|
8641
|
-
|
|
8642
|
-
|
|
8643
|
-
/**
|
|
8644
|
-
* The largest first-visible row index; 0 while every row fits at once.
|
|
8645
|
-
* @returns the index scrolling stops at.
|
|
8646
|
-
*/
|
|
8647
|
-
maxOffset() {
|
|
8648
|
-
return Math.max(0, this.total - DETAIL_MAX_VISIBLE);
|
|
8649
|
-
}
|
|
8650
|
-
/**
|
|
8651
|
-
* Move the visible window, stopping at both ends.
|
|
8652
|
-
* @param step - rows to move by; negative scrolls toward the first row.
|
|
8653
|
-
*/
|
|
8654
|
-
scroll(step) {
|
|
8655
|
-
this.offset = Math.max(0, Math.min(this.offset + step, this.maxOffset()));
|
|
8656
|
-
}
|
|
8657
|
-
withdraw() {
|
|
8658
|
-
this.settlement.settle();
|
|
8659
|
-
}
|
|
8660
|
-
handleInput(data) {
|
|
8661
|
-
if (matchesKey(data, "up")) this.scroll(-1);
|
|
8662
|
-
else if (matchesKey(data, "down")) this.scroll(1);
|
|
8663
|
-
else if (matchesKey(data, "pageUp")) this.scroll(-16);
|
|
8664
|
-
else if (matchesKey(data, "pageDown")) this.scroll(DETAIL_MAX_VISIBLE);
|
|
8665
|
-
else if (matchesKey(data, "enter") || matchesKey(data, "escape") || matchesKey(data, "left")) this.settlement.settle();
|
|
8666
|
-
}
|
|
8667
|
-
invalidate() {
|
|
8668
|
-
this.heading.invalidate();
|
|
8669
|
-
}
|
|
8670
|
-
render(width) {
|
|
8671
|
-
const wrapped = this.rows.flatMap((row) => wrapTextWithAnsi(row, Math.max(1, width)));
|
|
8672
|
-
this.total = wrapped.length;
|
|
8673
|
-
this.offset = Math.min(this.offset, this.maxOffset());
|
|
8674
|
-
const position = this.maxOffset() === 0 ? "" : ` · (${String(this.offset + 1)}/${String(this.total)})`;
|
|
8675
|
-
return [
|
|
8676
|
-
"",
|
|
8677
|
-
...this.heading.render(width),
|
|
8678
|
-
...wrapped.slice(this.offset, this.offset + DETAIL_MAX_VISIBLE),
|
|
8679
|
-
`${paintKeys(this.palette, DETAIL_HINT)}${position === "" ? "" : this.palette.dim(position)}`
|
|
8680
|
-
];
|
|
8681
|
-
}
|
|
8682
|
-
};
|
|
8683
|
-
/** Marker value of the free-text row. */
|
|
8684
|
-
const CUSTOM_VALUE = "\0custom";
|
|
8685
|
-
/** Marker value of the multi-select confirmation row. */
|
|
8686
|
-
const DONE_VALUE = "\0done";
|
|
8687
|
-
/** Marker value of the plan-review row that returns the user to the composer. */
|
|
8688
|
-
const DISCUSS_VALUE = "\0discuss";
|
|
8831
|
+
function focusedWindow(rest, held, palette, room, level) {
|
|
8832
|
+
if (rest.length === 0) return "";
|
|
8833
|
+
const sep = palette.dim(SEPARATOR$2);
|
|
8834
|
+
const sepWidth = visibleWidth(SEPARATOR$2);
|
|
8835
|
+
const selected = Math.max(0, held);
|
|
8836
|
+
const budget = room - sepWidth;
|
|
8837
|
+
const cap = budget - (selected < rest.length - 1 ? WINDOW_MARK_WIDTH : 0);
|
|
8838
|
+
const styled = rest.map((segment, index) => segmentLabel(index === held ? fitSelected(segment.label, cap) : segment.label, index === held, palette, level));
|
|
8839
|
+
const widths = styled.map(visibleWidth);
|
|
8840
|
+
const last = rest.length - 1;
|
|
8841
|
+
const opened = windowSpan(widths, selected, budget, sepWidth);
|
|
8842
|
+
const span = opened.end < last ? windowSpan(widths, selected, budget - WINDOW_MARK_WIDTH, sepWidth) : opened;
|
|
8843
|
+
const lead = span.start > 0 ? palette.dim(` ${WINDOW_START} `) : sep;
|
|
8844
|
+
const trail = span.end < last ? palette.dim(` ${WINDOW_END}`) : "";
|
|
8845
|
+
return `${lead}${styled.slice(span.start, span.end + 1).join(sep)}${trail}`;
|
|
8846
|
+
}
|
|
8689
8847
|
/**
|
|
8690
|
-
*
|
|
8691
|
-
*
|
|
8692
|
-
* @param
|
|
8693
|
-
* @param
|
|
8694
|
-
* @
|
|
8848
|
+
* The focused bar: the anchored model label, a sliding window of the segments
|
|
8849
|
+
* after it, then the expansion line.
|
|
8850
|
+
* @param segments - the segments in bar order.
|
|
8851
|
+
* @param selected - index of the held segment.
|
|
8852
|
+
* @param palette - the palette the labels and hints are styled with.
|
|
8853
|
+
* @param width - terminal columns each line must fit.
|
|
8854
|
+
* @param level - how far above its settled drawing the selected label is lifted.
|
|
8855
|
+
* @returns two lines, the anchor and the selected label always in the first.
|
|
8695
8856
|
*/
|
|
8696
|
-
function
|
|
8697
|
-
const
|
|
8698
|
-
|
|
8699
|
-
|
|
8700
|
-
|
|
8701
|
-
...description === void 0 ? {} : { description }
|
|
8702
|
-
};
|
|
8857
|
+
function focusedLines(segments, selected, palette, width, level) {
|
|
8858
|
+
const held = Math.min(Math.max(0, selected), Math.max(0, segments.length - 1));
|
|
8859
|
+
const [anchor, ...rest] = segments;
|
|
8860
|
+
const model = anchor === void 0 ? "" : segmentLabel(anchorLabel(anchor), held === 0, palette, level);
|
|
8861
|
+
return [fitLine(`${model}${focusedWindow(rest, held - 1, palette, width - visibleWidth(model), level)}`, width), expansionLine(segments[held], palette, width)];
|
|
8703
8862
|
}
|
|
8704
8863
|
/**
|
|
8705
|
-
*
|
|
8706
|
-
*
|
|
8707
|
-
*
|
|
8708
|
-
*
|
|
8709
|
-
*
|
|
8710
|
-
*
|
|
8711
|
-
*
|
|
8712
|
-
*
|
|
8864
|
+
* Render the footer. Unfocused it is one dim line built from both ends: the
|
|
8865
|
+
* model anchored left, the entry keys anchored right, and the key facts in
|
|
8866
|
+
* between. Focused it is the anchored model, the navigable segments (windowed
|
|
8867
|
+
* to `width` so the selected one is never dropped) and an expansion of that
|
|
8868
|
+
* segment plus the navigation keys. Every returned line fits `width`.
|
|
8869
|
+
* @param segments - the segments in bar order.
|
|
8870
|
+
* @param render - the palette, optional selected index, and terminal width.
|
|
8871
|
+
* @returns the footer lines, one when unfocused and two when focused.
|
|
8713
8872
|
*/
|
|
8714
|
-
|
|
8715
|
-
|
|
8716
|
-
|
|
8717
|
-
|
|
8718
|
-
|
|
8719
|
-
heading;
|
|
8720
|
-
detail;
|
|
8721
|
-
list;
|
|
8722
|
-
input = new Input();
|
|
8723
|
-
selected = /* @__PURE__ */ new Set();
|
|
8724
|
-
typing;
|
|
8725
|
-
constructor(palette, question) {
|
|
8726
|
-
this.palette = palette;
|
|
8727
|
-
this.question = question;
|
|
8728
|
-
this.settled = this.settlement.settled;
|
|
8729
|
-
const header = question.header === void 0 ? "" : `${palette.dim(question.header)}\n`;
|
|
8730
|
-
this.heading = new Text(`${header}${palette.warning("?")} ${palette.bold(question.question)}`, 0, 0);
|
|
8731
|
-
this.detail = question.detail === void 0 ? void 0 : new Markdown(question.detail, 0, 0, markdownTheme(palette));
|
|
8732
|
-
const options = question.options ?? [];
|
|
8733
|
-
this.typing = options.length === 0;
|
|
8734
|
-
const review = planReviewOptions(question);
|
|
8735
|
-
const items = [];
|
|
8736
|
-
if (review === void 0) {
|
|
8737
|
-
for (const { label, description } of options) items.push({
|
|
8738
|
-
value: label,
|
|
8739
|
-
label,
|
|
8740
|
-
...description === void 0 ? {} : { description }
|
|
8741
|
-
});
|
|
8742
|
-
items.push({
|
|
8743
|
-
value: CUSTOM_VALUE,
|
|
8744
|
-
label: "Type an answer…"
|
|
8745
|
-
});
|
|
8746
|
-
if (question.multiSelect === true) items.push({
|
|
8747
|
-
value: DONE_VALUE,
|
|
8748
|
-
label: "Done",
|
|
8749
|
-
description: "confirm the selection"
|
|
8750
|
-
});
|
|
8751
|
-
} else {
|
|
8752
|
-
items.push(verdictRow("Approve", review.approve));
|
|
8753
|
-
if (review.decline !== void 0) items.push(verdictRow("Decline", review.decline));
|
|
8754
|
-
items.push({
|
|
8755
|
-
value: DISCUSS_VALUE,
|
|
8756
|
-
label: "Discuss",
|
|
8757
|
-
description: "reply in the composer instead"
|
|
8758
|
-
});
|
|
8759
|
-
}
|
|
8760
|
-
this.list = new SelectList(items, SELECT_MAX_VISIBLE, selectListTheme(palette));
|
|
8761
|
-
this.list.onSelect = (item) => {
|
|
8762
|
-
this.choose(item.value);
|
|
8763
|
-
};
|
|
8764
|
-
this.list.onCancel = () => {
|
|
8765
|
-
this.settlement.settle(null);
|
|
8766
|
-
};
|
|
8767
|
-
this.input.onSubmit = (value) => {
|
|
8768
|
-
const custom = value.trim();
|
|
8769
|
-
if (custom === "") return;
|
|
8770
|
-
this.settlement.settle({
|
|
8771
|
-
id: this.question.id,
|
|
8772
|
-
selected: [...this.selected],
|
|
8773
|
-
custom
|
|
8774
|
-
});
|
|
8775
|
-
};
|
|
8776
|
-
this.input.onEscape = () => {
|
|
8777
|
-
this.typing = false;
|
|
8778
|
-
};
|
|
8779
|
-
}
|
|
8780
|
-
choose(value) {
|
|
8781
|
-
if (value === CUSTOM_VALUE) {
|
|
8782
|
-
this.typing = true;
|
|
8783
|
-
return;
|
|
8784
|
-
}
|
|
8785
|
-
if (value === DISCUSS_VALUE) {
|
|
8786
|
-
this.settlement.settle(null);
|
|
8787
|
-
return;
|
|
8788
|
-
}
|
|
8789
|
-
if (value === DONE_VALUE) {
|
|
8790
|
-
this.settlement.settle({
|
|
8791
|
-
id: this.question.id,
|
|
8792
|
-
selected: [...this.selected]
|
|
8793
|
-
});
|
|
8794
|
-
return;
|
|
8795
|
-
}
|
|
8796
|
-
if (this.question.multiSelect === true) {
|
|
8797
|
-
if (this.selected.has(value)) this.selected.delete(value);
|
|
8798
|
-
else this.selected.add(value);
|
|
8799
|
-
return;
|
|
8800
|
-
}
|
|
8801
|
-
this.settlement.settle({
|
|
8802
|
-
id: this.question.id,
|
|
8803
|
-
selected: [value]
|
|
8804
|
-
});
|
|
8805
|
-
}
|
|
8806
|
-
withdraw() {
|
|
8807
|
-
this.settlement.settle(null);
|
|
8808
|
-
}
|
|
8809
|
-
handleInput(data) {
|
|
8810
|
-
if (this.typing) {
|
|
8811
|
-
this.input.handleInput(data);
|
|
8812
|
-
return;
|
|
8813
|
-
}
|
|
8814
|
-
if (this.question.multiSelect === true && matchesKey(data, "space")) {
|
|
8815
|
-
const item = this.list.getSelectedItem();
|
|
8816
|
-
/* v8 ignore next -- the unfiltered list always has a highlighted row */
|
|
8817
|
-
if (item !== null) this.choose(item.value);
|
|
8818
|
-
return;
|
|
8819
|
-
}
|
|
8820
|
-
this.list.handleInput(data);
|
|
8821
|
-
}
|
|
8822
|
-
invalidate() {
|
|
8823
|
-
this.heading.invalidate();
|
|
8824
|
-
this.detail?.invalidate();
|
|
8825
|
-
this.list.invalidate();
|
|
8826
|
-
this.input.invalidate();
|
|
8827
|
-
}
|
|
8828
|
-
render(width) {
|
|
8829
|
-
const lines = ["", ...this.heading.render(width)];
|
|
8830
|
-
if (this.detail !== void 0) lines.push("", ...this.detail.render(width), "");
|
|
8831
|
-
if (this.question.multiSelect === true && this.selected.size > 0) lines.push(...wrapTextWithAnsi(this.palette.dim(`selected: ${[...this.selected].join(", ")}`), width));
|
|
8832
|
-
if (this.typing) {
|
|
8833
|
-
this.input.focused = true;
|
|
8834
|
-
lines.push(...this.input.render(width));
|
|
8835
|
-
lines.push(paintKeys(this.palette, "Enter answers · Esc back to the options"));
|
|
8836
|
-
} else {
|
|
8837
|
-
lines.push(...this.list.render(width));
|
|
8838
|
-
if (this.question.multiSelect === true) lines.push(paintKeys(this.palette, "Space toggles · Enter on Done confirms · Esc cancels"));
|
|
8839
|
-
}
|
|
8840
|
-
return lines;
|
|
8841
|
-
}
|
|
8842
|
-
};
|
|
8843
|
-
/** Continuation of the queue chain after a turn settles either way. */
|
|
8844
|
-
function settledTurn() {}
|
|
8873
|
+
function renderFooter(segments, render) {
|
|
8874
|
+
const width = Math.max(1, render.width);
|
|
8875
|
+
if (render.selected === void 0) return [unfocusedLine(segments, render.palette, width, render.queue === true)];
|
|
8876
|
+
return focusedLines(segments, render.selected, render.palette, width, render.level ?? 0);
|
|
8877
|
+
}
|
|
8845
8878
|
/**
|
|
8846
|
-
*
|
|
8847
|
-
*
|
|
8879
|
+
* The status bar as a mounted component. The view is read once per render
|
|
8880
|
+
* rather than pushed in, so the terminal width of that frame windows and
|
|
8881
|
+
* truncates the lines.
|
|
8848
8882
|
*/
|
|
8849
|
-
var
|
|
8850
|
-
|
|
8851
|
-
chain = Promise.resolve();
|
|
8852
|
-
active;
|
|
8853
|
-
constructor(host) {
|
|
8854
|
-
this.host = host;
|
|
8855
|
-
}
|
|
8883
|
+
var FooterBar = class {
|
|
8884
|
+
view;
|
|
8856
8885
|
/**
|
|
8857
|
-
*
|
|
8858
|
-
* @returns true while a prompt is visible and focused.
|
|
8886
|
+
* @param view - reads the segments and selection the bar draws.
|
|
8859
8887
|
*/
|
|
8860
|
-
|
|
8861
|
-
|
|
8888
|
+
constructor(view) {
|
|
8889
|
+
this.view = view;
|
|
8862
8890
|
}
|
|
8891
|
+
invalidate() {}
|
|
8863
8892
|
/**
|
|
8864
|
-
*
|
|
8865
|
-
* @param
|
|
8866
|
-
* @
|
|
8867
|
-
* @returns the prompt's settled value.
|
|
8893
|
+
* Draw the status bar at `width`.
|
|
8894
|
+
* @param width - the total width the bar lays out in.
|
|
8895
|
+
* @returns the footer lines, each no wider than `width`.
|
|
8868
8896
|
*/
|
|
8869
|
-
|
|
8870
|
-
const
|
|
8871
|
-
|
|
8872
|
-
|
|
8873
|
-
|
|
8874
|
-
const turn = this.chain.then(async () => {
|
|
8875
|
-
if (signal?.aborted === true) prompt.withdraw();
|
|
8876
|
-
this.active = prompt;
|
|
8877
|
-
this.host.slot.addChild(prompt);
|
|
8878
|
-
this.host.tui.setFocus(prompt);
|
|
8879
|
-
this.host.tui.requestRender();
|
|
8880
|
-
try {
|
|
8881
|
-
return await prompt.settled;
|
|
8882
|
-
} finally {
|
|
8883
|
-
signal?.removeEventListener("abort", onAbort);
|
|
8884
|
-
this.host.slot.removeChild(prompt);
|
|
8885
|
-
this.active = void 0;
|
|
8886
|
-
this.host.tui.setFocus(this.host.focusAfter);
|
|
8887
|
-
this.host.tui.requestRender();
|
|
8888
|
-
}
|
|
8897
|
+
render(width) {
|
|
8898
|
+
const { segments, render } = this.view();
|
|
8899
|
+
return renderFooter(segments, {
|
|
8900
|
+
...render,
|
|
8901
|
+
width
|
|
8889
8902
|
});
|
|
8890
|
-
this.chain = turn.then(settledTurn, settledTurn);
|
|
8891
|
-
return turn;
|
|
8892
|
-
}
|
|
8893
|
-
/** Withdraw the visible prompt, if any. */
|
|
8894
|
-
withdrawActive() {
|
|
8895
|
-
this.active?.withdraw();
|
|
8896
8903
|
}
|
|
8897
8904
|
};
|
|
8898
8905
|
/** What separates two facts on the descendant line. */
|
|
@@ -8955,16 +8962,16 @@ function activityTurnEndStatus(reason) {
|
|
|
8955
8962
|
return turnEndNotice(reason) ?? "done";
|
|
8956
8963
|
}
|
|
8957
8964
|
/**
|
|
8958
|
-
*
|
|
8965
|
+
* The rows of one board draw that a spinner animates.
|
|
8959
8966
|
* @param view - the rows one draw produced.
|
|
8960
|
-
* @returns
|
|
8967
|
+
* @returns the content of every drawn in-progress todo, in write order.
|
|
8961
8968
|
*/
|
|
8962
|
-
function
|
|
8963
|
-
return view.todos.
|
|
8969
|
+
function spinningTodos(view) {
|
|
8970
|
+
return view.todos.filter((row) => row.status === "in_progress").map((row) => row.content);
|
|
8964
8971
|
}
|
|
8965
8972
|
/**
|
|
8966
8973
|
* Render the board. Todo rows lead with status-colored glyphs, an in-progress
|
|
8967
|
-
* one with
|
|
8974
|
+
* one with its spinner frame when one is given; completed content is dim and
|
|
8968
8975
|
* scratched out. A list past the cap ends on `+<n> more`.
|
|
8969
8976
|
* The descendant line is last. An empty view returns the empty string so the
|
|
8970
8977
|
* slot can unmount.
|
|
@@ -8978,7 +8985,7 @@ function renderActivityBoard(view, render) {
|
|
|
8978
8985
|
for (const row of view.todos) {
|
|
8979
8986
|
const content = paintTodoContent(row.content, row.status, (text) => palette.dim(palette.strikethrough(text)));
|
|
8980
8987
|
const paint = row.status === "completed" ? palette.success : row.status === "in_progress" ? palette.warning : palette.accent;
|
|
8981
|
-
const glyph = row.status === "in_progress"
|
|
8988
|
+
const glyph = (row.status === "in_progress" ? render.spinners?.get(row.content) : void 0) ?? TODO_GLYPH[row.status];
|
|
8982
8989
|
lines.push(fadedLine(`${paint(glyph)} ${content}`, render.todoFades?.get(row.content)));
|
|
8983
8990
|
}
|
|
8984
8991
|
if (view.hidden > 0) lines.push(palette.dim(`+${String(view.hidden)} more`));
|
|
@@ -9079,6 +9086,21 @@ function renderQueuePanel(rows, render) {
|
|
|
9079
9086
|
}));
|
|
9080
9087
|
return lines.join("\n");
|
|
9081
9088
|
}
|
|
9089
|
+
/** What ends a row the width cut short; one column, so the mark itself fits. */
|
|
9090
|
+
const ELLIPSIS$2 = "…";
|
|
9091
|
+
/**
|
|
9092
|
+
* One prompt as a single row: the prompt glyph, then the prompt's rows joined
|
|
9093
|
+
* with every run of whitespace collapsed to one space, cut to `width` with an
|
|
9094
|
+
* ellipsis, on the prompt band.
|
|
9095
|
+
* @param palette - the palette the band is drawn with.
|
|
9096
|
+
* @param rows - the prompt's source rows.
|
|
9097
|
+
* @param width - the columns the row spans.
|
|
9098
|
+
* @returns the row: exactly `width` columns under the band on an enabled
|
|
9099
|
+
* palette, and the unpadded text, no wider than `width`, on a disabled one.
|
|
9100
|
+
*/
|
|
9101
|
+
function pinnedPromptRow(palette, rows, width) {
|
|
9102
|
+
return bandRow(palette, truncateToWidth(` ❯ ${rows.join(" ").replaceAll(/\s+/gu, " ").trim()} `, width, ELLIPSIS$2), width);
|
|
9103
|
+
}
|
|
9082
9104
|
/** Narrowest turn list. */
|
|
9083
9105
|
const LIST_MIN_WIDTH = 18;
|
|
9084
9106
|
/** Widest turn list. */
|
|
@@ -9099,8 +9121,6 @@ const ELLIPSIS$1 = "…";
|
|
|
9099
9121
|
const SIDE = "│";
|
|
9100
9122
|
/** Marks the listed section the keyboard holds. */
|
|
9101
9123
|
const LIST_MARK = "▸";
|
|
9102
|
-
/** Opens the prompt band and the list's row for the turn being read, as it opens a prompt in the conversation. */
|
|
9103
|
-
const PROMPT_GLYPH = "❯";
|
|
9104
9124
|
/** The gutter beside every row of the section the reader holds: the conversation walk's own mark. */
|
|
9105
9125
|
const HELD_GUTTER = "┃ ";
|
|
9106
9126
|
/** The gutter beside every other row of the panel. */
|
|
@@ -9269,7 +9289,7 @@ function sectionAt(cursor, blocks) {
|
|
|
9269
9289
|
*/
|
|
9270
9290
|
function sectionGlyph(block, part) {
|
|
9271
9291
|
switch (block.blockKind) {
|
|
9272
|
-
case "user": return
|
|
9292
|
+
case "user": return "❯";
|
|
9273
9293
|
case "context": return "⬡";
|
|
9274
9294
|
case "assistant": return part.kind === "reasoning" ? "✻" : "¶";
|
|
9275
9295
|
case "tool": return part.kind === "result" ? "⎿" : "◆";
|
|
@@ -9411,7 +9431,7 @@ function cell(text, width) {
|
|
|
9411
9431
|
function promptRows(rows, width, look) {
|
|
9412
9432
|
const { palette, tints, held } = look;
|
|
9413
9433
|
const room = Math.max(1, width - visibleWidth(BODY_INDENT));
|
|
9414
|
-
const glyph = held ? palette.bold(palette.accent(
|
|
9434
|
+
const glyph = held ? palette.bold(palette.accent("❯")) : palette.accent("❯");
|
|
9415
9435
|
return rows.flatMap((row) => wrapTextWithAnsi(row, room)).map((line, index) => {
|
|
9416
9436
|
const text = cell(`${index === 0 ? `${glyph} ` : BODY_INDENT}${palette.bold(line)}`, width);
|
|
9417
9437
|
return tints === void 0 ? text : tints.prompt(text);
|
|
@@ -9891,7 +9911,7 @@ function listPaint(text, selected, look) {
|
|
|
9891
9911
|
function turnRow(group, open, look) {
|
|
9892
9912
|
const marks = markerStrip(group.markers);
|
|
9893
9913
|
const room = Math.max(1, look.width - visibleWidth(marks) - (marks === "" ? 0 : 1));
|
|
9894
|
-
const text = truncateToWidth(listPaint(`${`${open ?
|
|
9914
|
+
const text = truncateToWidth(listPaint(`${`${open ? "❯" : " "} ${String(group.turn).padStart(look.digits)} `}${group.label}`, open, look), room, ELLIPSIS$1);
|
|
9895
9915
|
return cell(`${text}${" ".repeat(Math.max(0, look.width - visibleWidth(text) - visibleWidth(marks)))}${look.palette.dim(marks)}`, look.width);
|
|
9896
9916
|
}
|
|
9897
9917
|
/**
|
|
@@ -10038,7 +10058,7 @@ function readerRows(state, groups, render) {
|
|
|
10038
10058
|
const legendRoom = ruleRoom(width) - visibleWidth(report) - 1;
|
|
10039
10059
|
const prompt = group?.sections.map((section) => blocks[section.block]?.parts()[section.part]).find((part) => part?.kind === "user");
|
|
10040
10060
|
return [
|
|
10041
|
-
(geometry.pane > 0 && state.offset > 0 && prompt !== void 0 ?
|
|
10061
|
+
(geometry.pane > 0 && state.offset > 0 && prompt !== void 0 ? pinnedPromptRow(palette, prompt.rows, width) : void 0) ?? topRule({
|
|
10042
10062
|
chip: chip(palette, READER_CHIP),
|
|
10043
10063
|
title: palette.bold(palette.accent(`turn ${String(place(selected, groups.length))} of ${String(groups.length)}`)),
|
|
10044
10064
|
width,
|
|
@@ -11049,6 +11069,17 @@ function pageContentWidth(width) {
|
|
|
11049
11069
|
/** The left margin as the spaces each drawn line is moved right by. */
|
|
11050
11070
|
const LEFT_MARGIN = " ".repeat(1);
|
|
11051
11071
|
/**
|
|
11072
|
+
* The left page margin at a terminal width: what every drawn line, and
|
|
11073
|
+
* anything floated over one, is moved right by to line up with the columns
|
|
11074
|
+
* the tree lays out in.
|
|
11075
|
+
* @param width - the terminal's total width.
|
|
11076
|
+
* @returns the margin's spaces; empty on a terminal too narrow for the
|
|
11077
|
+
* margins, as {@link pageContentWidth} decides.
|
|
11078
|
+
*/
|
|
11079
|
+
function pageMargin(width) {
|
|
11080
|
+
return pageContentWidth(width) === width ? "" : LEFT_MARGIN;
|
|
11081
|
+
}
|
|
11082
|
+
/**
|
|
11052
11083
|
* Move every drawn line right by the left margin. A line with nothing on it
|
|
11053
11084
|
* keeps its own emptiness rather than gaining trailing spaces, so a frame adds
|
|
11054
11085
|
* no whitespace to what the terminal's scrollback holds.
|
|
@@ -11084,6 +11115,12 @@ function repaintFloor(start, viewportTop) {
|
|
|
11084
11115
|
* already settled instead of changing in the next frame, by which time its
|
|
11085
11116
|
* lines may sit above the window.
|
|
11086
11117
|
*
|
|
11118
|
+
* A frame the renderer writes in full instead - after a resize, or for a
|
|
11119
|
+
* change above its window - leaves the window at that frame's own viewport.
|
|
11120
|
+
* When the guard settled that frame against a higher `previousViewportTop`,
|
|
11121
|
+
* what it decided no longer matches the terminal, so the screen renders once
|
|
11122
|
+
* more and the guard settles against the window the terminal now has.
|
|
11123
|
+
*
|
|
11087
11124
|
* It can also be suspended, which stops every write to the terminal while
|
|
11088
11125
|
* leaving the renderer's record of the main screen exactly as it was. The
|
|
11089
11126
|
* terminal restores that same screen when the surface that took it gives it
|
|
@@ -11097,6 +11134,11 @@ var GuardedMainScreen = class extends TuiMainScreen {
|
|
|
11097
11134
|
/** The keys the last frame drew, by frame line. */
|
|
11098
11135
|
keys = EMPTY_KEY_FRAME;
|
|
11099
11136
|
/**
|
|
11137
|
+
* Whether the guard settled the last frame against a `previousViewportTop`
|
|
11138
|
+
* above that frame's own viewport, which a frame written in full lowers.
|
|
11139
|
+
*/
|
|
11140
|
+
settledAboveViewport = false;
|
|
11141
|
+
/**
|
|
11100
11142
|
* @param terminal - the terminal the tree renders into.
|
|
11101
11143
|
* @param showHardwareCursor - whether the terminal's own cursor is the caret.
|
|
11102
11144
|
* @param guard - given the frame's first repaintable line, the width it was
|
|
@@ -11182,10 +11224,16 @@ var GuardedMainScreen = class extends TuiMainScreen {
|
|
|
11182
11224
|
this.keys = marked.keys;
|
|
11183
11225
|
return super.applyLineResets(marked.lines);
|
|
11184
11226
|
}
|
|
11185
|
-
/**
|
|
11227
|
+
/**
|
|
11228
|
+
* Write the frame, unless another surface holds the terminal, and request
|
|
11229
|
+
* one more frame when this one was written in full after the guard settled
|
|
11230
|
+
* it against a window top the full write lowered.
|
|
11231
|
+
*/
|
|
11186
11232
|
doRender() {
|
|
11187
11233
|
if (this.onSuspendedRender !== void 0) return;
|
|
11234
|
+
const fullRedraws = this.fullRedraws;
|
|
11188
11235
|
super.doRender();
|
|
11236
|
+
if (this.fullRedraws !== fullRedraws && this.settledAboveViewport) this.requestRender();
|
|
11189
11237
|
}
|
|
11190
11238
|
/**
|
|
11191
11239
|
* Build the frame inside the page margins, let the guard settle what its
|
|
@@ -11199,13 +11247,14 @@ var GuardedMainScreen = class extends TuiMainScreen {
|
|
|
11199
11247
|
*/
|
|
11200
11248
|
render(width) {
|
|
11201
11249
|
const content = pageContentWidth(width);
|
|
11202
|
-
const margin =
|
|
11250
|
+
const margin = pageMargin(width);
|
|
11203
11251
|
const previousTop = this.captureRenderState().previousViewportTop;
|
|
11204
11252
|
let lines = indentFrame(super.render(content), margin);
|
|
11205
11253
|
for (let pass = 0; pass < SETTLE_PASSES; pass += 1) {
|
|
11206
11254
|
if (!this.guard(Math.max(previousTop, lines.length - this.terminal.rows), content, lines.length)) break;
|
|
11207
11255
|
lines = indentFrame(super.render(content), margin);
|
|
11208
11256
|
}
|
|
11257
|
+
this.settledAboveViewport = previousTop > Math.max(0, lines.length - this.terminal.rows);
|
|
11209
11258
|
return lines;
|
|
11210
11259
|
}
|
|
11211
11260
|
};
|
|
@@ -12224,22 +12273,6 @@ const SHELL_MISSING = "! needs a shell executor in this composition";
|
|
|
12224
12273
|
/** Shown when a second `!` is submitted while one is still running. */
|
|
12225
12274
|
const SHELL_BUSY = "A shell command is already running. Press Esc to cancel it first.";
|
|
12226
12275
|
/**
|
|
12227
|
-
* Spinner word for a streamed or executing tool.
|
|
12228
|
-
* @param name - the tool name when one is known.
|
|
12229
|
-
* @returns `calling <name>`, or `calling` when the name has not arrived.
|
|
12230
|
-
*/
|
|
12231
|
-
function callingActivity(name) {
|
|
12232
|
-
return name ? `calling ${name}` : "calling";
|
|
12233
|
-
}
|
|
12234
|
-
/**
|
|
12235
|
-
* Whether the spinner is already naming a tool call.
|
|
12236
|
-
* @param activity - the current spinner word.
|
|
12237
|
-
* @returns true for `calling` and `calling <name>`.
|
|
12238
|
-
*/
|
|
12239
|
-
function isCallingActivity(activity) {
|
|
12240
|
-
return activity === "calling" || activity.startsWith("calling ");
|
|
12241
|
-
}
|
|
12242
|
-
/**
|
|
12243
12276
|
* Source for a prompt the person typed in this terminal.
|
|
12244
12277
|
* A string `rpcId` is the admission mark Auto review treats as a human instruction.
|
|
12245
12278
|
* An edited draft keeps a non-user source; a user draft is admitted again.
|
|
@@ -12377,10 +12410,16 @@ var TuiApp = class {
|
|
|
12377
12410
|
pacer;
|
|
12378
12411
|
/** Tool cards whose rows are still unrolling; each drops out once its reveal caught up. */
|
|
12379
12412
|
reveals = /* @__PURE__ */ new Set();
|
|
12380
|
-
/**
|
|
12381
|
-
|
|
12382
|
-
|
|
12383
|
-
|
|
12413
|
+
/**
|
|
12414
|
+
* Running tool cards whose glyph spins, with the phase each spins at for
|
|
12415
|
+
* its whole run; each drops out once it stops spinning.
|
|
12416
|
+
*/
|
|
12417
|
+
spinners = /* @__PURE__ */ new Map();
|
|
12418
|
+
/**
|
|
12419
|
+
* The phase each in-progress todo row the activity board last drew spins
|
|
12420
|
+
* at, by content; a row keeps its phase while it stays in progress.
|
|
12421
|
+
*/
|
|
12422
|
+
boardSpinners = /* @__PURE__ */ new Map();
|
|
12384
12423
|
/**
|
|
12385
12424
|
* Whether the open turn has committed an assistant message, after which a
|
|
12386
12425
|
* user prompt reaching the log was steered or injected rather than opening
|
|
@@ -12427,9 +12466,9 @@ var TuiApp = class {
|
|
|
12427
12466
|
compactions;
|
|
12428
12467
|
/**
|
|
12429
12468
|
* How many of the viewport's own first lines the renderer can no longer
|
|
12430
|
-
* repaint, from the last frame the guard settled. The
|
|
12431
|
-
*
|
|
12432
|
-
*
|
|
12469
|
+
* repaint, from the last frame the guard settled. The terminal's first row
|
|
12470
|
+
* shows the line after them, and the transient line floats only while its
|
|
12471
|
+
* box stays clear of them.
|
|
12433
12472
|
*/
|
|
12434
12473
|
viewportFloor = 0;
|
|
12435
12474
|
/** Set while {@link TuiApp.bind} replays a session's history, which draws its cards settled. */
|
|
@@ -12470,8 +12509,6 @@ var TuiApp = class {
|
|
|
12470
12509
|
usageExact = false;
|
|
12471
12510
|
/** Spinner label without the live ↑↓ suffix (`thinking`, `writing`, `calling read`, …). */
|
|
12472
12511
|
loaderActivity = "thinking";
|
|
12473
|
-
/** Animation the loader draws; undefined while it is stopped, so the next start syncs it. */
|
|
12474
|
-
loaderSpinnerKind = void 0;
|
|
12475
12512
|
/** Tool names still streamed or executing, in first-seen order. */
|
|
12476
12513
|
pendingToolNames = /* @__PURE__ */ new Map();
|
|
12477
12514
|
lastCtrlC = 0;
|
|
@@ -12516,9 +12553,8 @@ var TuiApp = class {
|
|
|
12516
12553
|
palette,
|
|
12517
12554
|
previewLines: deps.focusPreviewLines
|
|
12518
12555
|
});
|
|
12519
|
-
this.loader = new Loader(this.tui, palette.accent, (message) => this.paintLoaderMessage(message), "thinking");
|
|
12556
|
+
this.loader = new Loader(this.tui, palette.accent, (message) => this.paintLoaderMessage(message), "thinking", { frames: [] });
|
|
12520
12557
|
this.compactions = new CompactionLedger((message) => deps.ctx.get("tokenMeter")?.estimateMessage(message));
|
|
12521
|
-
this.loader.stop();
|
|
12522
12558
|
this.editor = new BarCursorEditor(this.tui, editorTheme(palette), { paddingX: 1 });
|
|
12523
12559
|
this.editor.shellPaint = {
|
|
12524
12560
|
highlight: this.codeHighlight,
|
|
@@ -12703,7 +12739,6 @@ var TuiApp = class {
|
|
|
12703
12739
|
this.modals.withdrawActive();
|
|
12704
12740
|
this.dropReader();
|
|
12705
12741
|
this.hideToast();
|
|
12706
|
-
this.loader.stop();
|
|
12707
12742
|
this.deps.terminal.write(SET_TERMINAL_DEFAULT_CURSOR);
|
|
12708
12743
|
this.tui.stop();
|
|
12709
12744
|
this.deps.releaseInput();
|
|
@@ -12996,23 +13031,26 @@ var TuiApp = class {
|
|
|
12996
13031
|
}
|
|
12997
13032
|
setWorking(working) {
|
|
12998
13033
|
if (working) {
|
|
12999
|
-
if (this.statusSlot.
|
|
13000
|
-
this.statusSlot.addChild(this.loader);
|
|
13001
|
-
this.loader.start();
|
|
13002
|
-
}
|
|
13003
|
-
this.syncLoaderIndicator();
|
|
13034
|
+
if (!this.loaderMounted()) this.statusSlot.addChild(this.loader);
|
|
13004
13035
|
this.refreshLoader();
|
|
13005
|
-
} else if (this.
|
|
13006
|
-
this.loader.stop();
|
|
13036
|
+
} else if (this.loaderMounted()) {
|
|
13007
13037
|
this.statusSlot.removeChild(this.loader);
|
|
13008
13038
|
this.pendingToolNames.clear();
|
|
13009
13039
|
this.loaderActivity = "thinking";
|
|
13010
|
-
this.loaderSpinnerKind = void 0;
|
|
13011
13040
|
this.clearLiveUsage();
|
|
13012
13041
|
this.loader.setMessage("thinking");
|
|
13013
13042
|
}
|
|
13043
|
+
this.updateSpinTicker();
|
|
13014
13044
|
this.tui.requestRender();
|
|
13015
13045
|
}
|
|
13046
|
+
/**
|
|
13047
|
+
* Whether the activity line is drawn, which it is exactly while the agent
|
|
13048
|
+
* works or a dispatched `/compact` runs.
|
|
13049
|
+
* @returns true while the loader is mounted.
|
|
13050
|
+
*/
|
|
13051
|
+
loaderMounted() {
|
|
13052
|
+
return this.statusSlot.children.length > 0;
|
|
13053
|
+
}
|
|
13016
13054
|
refreshHeader() {
|
|
13017
13055
|
const palette = this.deps.palette;
|
|
13018
13056
|
const session = this.agent.session;
|
|
@@ -13084,12 +13122,15 @@ var TuiApp = class {
|
|
|
13084
13122
|
todos: this.activityTodos,
|
|
13085
13123
|
...this.activitySubagent === void 0 ? {} : { subagent: this.activitySubagent }
|
|
13086
13124
|
});
|
|
13087
|
-
this.
|
|
13125
|
+
this.syncBoardSpinners(this.deps.reducedMotion ? [] : spinningTodos(view));
|
|
13126
|
+
const now = this.deps.now();
|
|
13127
|
+
const spinners = /* @__PURE__ */ new Map();
|
|
13128
|
+
for (const [content, phase] of this.boardSpinners) spinners.set(content, spinnerFrame(TOOL_SPINNER, now, this.deps.spinnerMs, phase));
|
|
13088
13129
|
const text = renderActivityBoard(view, {
|
|
13089
13130
|
palette: this.deps.palette,
|
|
13090
13131
|
todoFades: this.activityTodoFades,
|
|
13091
13132
|
...this.activitySubagentFade === void 0 ? {} : { subagentFade: this.activitySubagentFade },
|
|
13092
|
-
|
|
13133
|
+
spinners
|
|
13093
13134
|
});
|
|
13094
13135
|
this.updateSpinTicker();
|
|
13095
13136
|
const mounted = this.activitySlot.children.length > 0;
|
|
@@ -13102,6 +13143,19 @@ var TuiApp = class {
|
|
|
13102
13143
|
this.tui.requestRender();
|
|
13103
13144
|
}
|
|
13104
13145
|
/**
|
|
13146
|
+
* Keep the phase of each in-progress todo row that still spins, drop the
|
|
13147
|
+
* rest, and stagger a row that starts spinning against every other tool
|
|
13148
|
+
* indicator on screen.
|
|
13149
|
+
* @param contents - the content of each in-progress row the board draws now.
|
|
13150
|
+
*/
|
|
13151
|
+
syncBoardSpinners(contents) {
|
|
13152
|
+
for (const content of this.boardSpinners.keys()) if (!contents.includes(content)) this.boardSpinners.delete(content);
|
|
13153
|
+
for (const content of contents) {
|
|
13154
|
+
if (this.boardSpinners.has(content)) continue;
|
|
13155
|
+
this.boardSpinners.set(content, staggerPhase(this.spinningPhases()));
|
|
13156
|
+
}
|
|
13157
|
+
}
|
|
13158
|
+
/**
|
|
13105
13159
|
* Replace the board's todos from the same `todos` projection `/todos` reads
|
|
13106
13160
|
* and fade rows that are new or that changed status.
|
|
13107
13161
|
*/
|
|
@@ -14847,6 +14901,9 @@ var TuiApp = class {
|
|
|
14847
14901
|
case "permission":
|
|
14848
14902
|
await this.choosePermission(argument);
|
|
14849
14903
|
return;
|
|
14904
|
+
case "sandbox":
|
|
14905
|
+
await this.chooseSandbox(argument);
|
|
14906
|
+
return;
|
|
14850
14907
|
case "search":
|
|
14851
14908
|
await this.chooseSearchRoute(argument);
|
|
14852
14909
|
return;
|
|
@@ -15287,6 +15344,20 @@ var TuiApp = class {
|
|
|
15287
15344
|
}
|
|
15288
15345
|
}
|
|
15289
15346
|
/**
|
|
15347
|
+
* Preview backend access in a picker; typed arguments retain the shared command.
|
|
15348
|
+
* @param argument - a backend id, or empty for the picker.
|
|
15349
|
+
*/
|
|
15350
|
+
async chooseSandbox(argument) {
|
|
15351
|
+
const provider = this.deps.ctx.get("sandbox");
|
|
15352
|
+
const policy = this.deps.ctx.get("sandboxPolicy");
|
|
15353
|
+
if (argument !== "" || !(provider instanceof AppleContainerSandboxProvider) || policy === void 0 || this.deps.ctx.get("commands") === void 0) {
|
|
15354
|
+
await this.runSharedCommand(argument === "" ? "/sandbox" : `/sandbox ${argument}`, "sandbox");
|
|
15355
|
+
return;
|
|
15356
|
+
}
|
|
15357
|
+
const picked = await this.showModal(new SandboxPrompt(this.deps.palette, provider, this.agent.session, policy.resolve({ session: this.agent.session })));
|
|
15358
|
+
if (picked !== void 0) await this.runSharedCommand(`/sandbox ${picked.value}`, "sandbox");
|
|
15359
|
+
}
|
|
15360
|
+
/**
|
|
15290
15361
|
* Choose the bound session's permission preset: an empty argument opens
|
|
15291
15362
|
* the picker on the preset in force, and anything else names a catalog
|
|
15292
15363
|
* value. A pick submits `/permission <preset>` when the shared command
|
|
@@ -15721,28 +15792,48 @@ var TuiApp = class {
|
|
|
15721
15792
|
this.trackReveal(block);
|
|
15722
15793
|
}
|
|
15723
15794
|
/**
|
|
15724
|
-
* Spin a new card's glyph in
|
|
15725
|
-
*
|
|
15726
|
-
*
|
|
15727
|
-
*
|
|
15795
|
+
* Spin a new card's glyph in the tool animation until its result lands, at
|
|
15796
|
+
* a phase staggered against the other tool indicators on screen and kept
|
|
15797
|
+
* for the card's whole run. A card drawn from a replayed log, and every
|
|
15798
|
+
* card under reduced motion, draws the static glyph.
|
|
15728
15799
|
* @param block - the card that was just mounted.
|
|
15729
15800
|
*/
|
|
15730
15801
|
spinBlock(block) {
|
|
15731
15802
|
if (this.replaying || this.deps.reducedMotion) return;
|
|
15732
|
-
|
|
15733
|
-
this.
|
|
15803
|
+
const phase = staggerPhase(this.spinningPhases());
|
|
15804
|
+
block.setSpinner(() => spinnerFrame(TOOL_SPINNER, this.deps.now(), this.deps.spinnerMs, phase));
|
|
15805
|
+
this.spinners.set(block, phase);
|
|
15734
15806
|
this.updateSpinTicker();
|
|
15735
15807
|
}
|
|
15736
15808
|
/**
|
|
15737
|
-
*
|
|
15738
|
-
*
|
|
15739
|
-
*
|
|
15809
|
+
* The phases of the tool indicators spinning right now: running cards and
|
|
15810
|
+
* the activity board's in-progress todo rows.
|
|
15811
|
+
* @returns one phase per spinning indicator.
|
|
15812
|
+
*/
|
|
15813
|
+
spinningPhases() {
|
|
15814
|
+
const phases = [];
|
|
15815
|
+
for (const [block, phase] of this.spinners) if (block.spinning()) phases.push(phase);
|
|
15816
|
+
phases.push(...this.boardSpinners.values());
|
|
15817
|
+
return phases;
|
|
15818
|
+
}
|
|
15819
|
+
/**
|
|
15820
|
+
* Whether the activity line animates: it is drawn and reduced motion is off.
|
|
15821
|
+
* @returns true while its glyph and shimmer step on the spinner tick.
|
|
15822
|
+
*/
|
|
15823
|
+
loaderAnimates() {
|
|
15824
|
+
return !this.deps.reducedMotion && this.loaderMounted();
|
|
15825
|
+
}
|
|
15826
|
+
/**
|
|
15827
|
+
* Arm the spinner tick while the activity line animates, a card spins, or
|
|
15828
|
+
* an in-progress todo spins, and disarm it otherwise, so a session with
|
|
15829
|
+
* nothing running runs no spinner timer. Exactly one runs at a time, and a
|
|
15830
|
+
* stopped app runs none.
|
|
15740
15831
|
*/
|
|
15741
15832
|
updateSpinTicker() {
|
|
15742
|
-
if (!this.stopped && (this.spinners.size > 0 || this.
|
|
15833
|
+
if (!this.stopped && (this.loaderAnimates() || this.spinners.size > 0 || this.boardSpinners.size > 0)) {
|
|
15743
15834
|
this.spinTicker ??= this.deps.tick(() => {
|
|
15744
15835
|
this.onSpinTick();
|
|
15745
|
-
},
|
|
15836
|
+
}, this.deps.spinnerMs);
|
|
15746
15837
|
return;
|
|
15747
15838
|
}
|
|
15748
15839
|
const ticker = this.spinTicker;
|
|
@@ -15751,13 +15842,15 @@ var TuiApp = class {
|
|
|
15751
15842
|
ticker();
|
|
15752
15843
|
}
|
|
15753
15844
|
/**
|
|
15754
|
-
* One spinner period: drop the cards that stopped spinning, then redraw
|
|
15755
|
-
*
|
|
15756
|
-
* built
|
|
15845
|
+
* One spinner period: drop the cards that stopped spinning, then redraw
|
|
15846
|
+
* everything that animates in one render. The activity line's message and
|
|
15847
|
+
* the board's text are built when something changes them, so both are
|
|
15848
|
+
* built again here on their next frame.
|
|
15757
15849
|
*/
|
|
15758
15850
|
onSpinTick() {
|
|
15759
|
-
for (const block of this.spinners) if (!block.spinning()) this.spinners.delete(block);
|
|
15760
|
-
if (this.
|
|
15851
|
+
for (const block of this.spinners.keys()) if (!block.spinning()) this.spinners.delete(block);
|
|
15852
|
+
if (this.loaderAnimates()) this.refreshLoader();
|
|
15853
|
+
if (this.boardSpinners.size > 0) this.refreshActivityBoard();
|
|
15761
15854
|
else if (this.spinners.size > 0) this.tui.requestRender();
|
|
15762
15855
|
this.updateSpinTicker();
|
|
15763
15856
|
}
|
|
@@ -15902,7 +15995,8 @@ var TuiApp = class {
|
|
|
15902
15995
|
*/
|
|
15903
15996
|
settleFrame(viewportTop, width, frameLines) {
|
|
15904
15997
|
const rows = this.deps.terminal.rows;
|
|
15905
|
-
|
|
15998
|
+
const viewportStart = Math.max(frameLines, rows) - rows;
|
|
15999
|
+
this.viewportFloor = repaintFloor(viewportStart, viewportTop);
|
|
15906
16000
|
const section = this.focusedSection();
|
|
15907
16001
|
const wanted = section !== void 0 && this.focus === "transcript" ? {
|
|
15908
16002
|
block: section.block,
|
|
@@ -15910,7 +16004,6 @@ var TuiApp = class {
|
|
|
15910
16004
|
level: this.markLift()
|
|
15911
16005
|
} : void 0;
|
|
15912
16006
|
const fades = this.fadesMoving() || this.spinners.size > 0;
|
|
15913
|
-
if (!fades && wanted === void 0 && this.highlighted === void 0) return false;
|
|
15914
16007
|
let start = this.header.render(width).length;
|
|
15915
16008
|
let wantedStart;
|
|
15916
16009
|
let changed = false;
|
|
@@ -16217,21 +16310,9 @@ var TuiApp = class {
|
|
|
16217
16310
|
*/
|
|
16218
16311
|
setLoaderActivity(activity) {
|
|
16219
16312
|
this.loaderActivity = activity;
|
|
16220
|
-
this.syncLoaderIndicator();
|
|
16221
16313
|
this.refreshLoader();
|
|
16222
16314
|
}
|
|
16223
16315
|
/**
|
|
16224
|
-
* Draw the loader's animation for its activity word. Setting the indicator
|
|
16225
|
-
* restarts the animation, so it runs only when the kind changed — a repeat
|
|
16226
|
-
* label would otherwise pin the spinner to its first frame.
|
|
16227
|
-
*/
|
|
16228
|
-
syncLoaderIndicator() {
|
|
16229
|
-
const kind = spinnerKindForActivity(this.loaderActivity);
|
|
16230
|
-
if (kind === this.loaderSpinnerKind) return;
|
|
16231
|
-
this.loaderSpinnerKind = kind;
|
|
16232
|
-
this.loader.setIndicator(loaderIndicator(kind));
|
|
16233
|
-
}
|
|
16234
|
-
/**
|
|
16235
16316
|
* Label a streamed reasoning or visible-text chunk unless a tool call is
|
|
16236
16317
|
* already the current activity: calling stays until the last in-flight
|
|
16237
16318
|
* tool settles or a new model call begins.
|
|
@@ -16263,7 +16344,6 @@ var TuiApp = class {
|
|
|
16263
16344
|
};
|
|
16264
16345
|
if (this.pendingToolNames.size === 0) this.loaderActivity = "thinking";
|
|
16265
16346
|
else this.syncLoaderFromPendingTools();
|
|
16266
|
-
this.syncLoaderIndicator();
|
|
16267
16347
|
this.refreshLiveUsage();
|
|
16268
16348
|
}
|
|
16269
16349
|
/**
|
|
@@ -16313,18 +16393,21 @@ var TuiApp = class {
|
|
|
16313
16393
|
this.refreshFooter();
|
|
16314
16394
|
}
|
|
16315
16395
|
/**
|
|
16316
|
-
* Paint the
|
|
16317
|
-
* word
|
|
16318
|
-
*
|
|
16396
|
+
* Paint the activity line for the current instant: the status glyph of the
|
|
16397
|
+
* activity word in the accent color and a space, then the word carrying the
|
|
16398
|
+
* shimmer, then the live ↑↓ suffix dim. Under reduced motion no glyph is
|
|
16399
|
+
* drawn and the whole message is dim.
|
|
16319
16400
|
* @param message - the loader's message, the activity word first.
|
|
16320
|
-
* @returns the styled
|
|
16401
|
+
* @returns the styled line.
|
|
16321
16402
|
*/
|
|
16322
16403
|
paintLoaderMessage(message) {
|
|
16323
16404
|
const palette = this.deps.palette;
|
|
16324
16405
|
const activity = this.loaderActivity;
|
|
16325
16406
|
if (this.deps.reducedMotion || !message.startsWith(activity)) return paintKeys(palette, message, palette.dim, "prose");
|
|
16407
|
+
const now = this.deps.now();
|
|
16408
|
+
const glyph = spinnerFrame(ACTIVITY_SPINNERS[activityStatus(activity)], now, this.deps.spinnerMs);
|
|
16326
16409
|
const rest = message.slice(activity.length);
|
|
16327
|
-
return `${shimmer(palette, activity, this.deps.
|
|
16410
|
+
return `${palette.accent(glyph)} ${shimmer(palette, activity, now, this.deps.spinnerMs)}${rest === "" ? "" : paintKeys(palette, rest, palette.dim, "prose")}`;
|
|
16328
16411
|
}
|
|
16329
16412
|
/**
|
|
16330
16413
|
* Draw the spinner label plus the current call's ↑send ↓receive suffix,
|
|
@@ -16547,7 +16630,7 @@ const Config = z.object({
|
|
|
16547
16630
|
streamFadeStepMs: z.natural().min(16).default(16),
|
|
16548
16631
|
streamPaceFrames: z.natural().default(8),
|
|
16549
16632
|
toolRevealFrames: z.natural().default(6),
|
|
16550
|
-
|
|
16633
|
+
spinnerMs: z.natural().min(80).default(100),
|
|
16551
16634
|
reducedMotion: z.boolean().default(false),
|
|
16552
16635
|
mouse: z.boolean().default(false),
|
|
16553
16636
|
openBrowser: z.boolean().default(true),
|
|
@@ -16823,7 +16906,7 @@ async function run(ctx, config, host) {
|
|
|
16823
16906
|
fadeStepMs: config.streamFadeStepMs,
|
|
16824
16907
|
streamPaceFrames: config.streamPaceFrames,
|
|
16825
16908
|
toolRevealFrames: config.toolRevealFrames,
|
|
16826
|
-
|
|
16909
|
+
spinnerMs: config.spinnerMs,
|
|
16827
16910
|
reducedMotion: config.reducedMotion,
|
|
16828
16911
|
env: process.env,
|
|
16829
16912
|
now: () => Date.now(),
|