@songtonyli/dsh-cli 0.1.60 → 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 +4 -4
- package/node_modules/@deepseek-ai/dsh-tui-app/README.md +6 -9
- package/node_modules/@deepseek-ai/dsh-tui-app/README.zh.md +6 -9
- package/node_modules/@deepseek-ai/dsh-tui-app/lib/index.js +533 -820
- package/node_modules/@types/node/README.md +1 -1
- package/node_modules/@types/node/package.json +2 -2
- package/package.json +2 -2
|
@@ -4864,149 +4864,25 @@ const ACTIVITY_SPINNERS = {
|
|
|
4864
4864
|
]
|
|
4865
4865
|
};
|
|
4866
4866
|
/**
|
|
4867
|
-
* The animation
|
|
4868
|
-
*
|
|
4869
|
-
*
|
|
4870
|
-
*
|
|
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.
|
|
4871
4873
|
*/
|
|
4872
|
-
const
|
|
4873
|
-
|
|
4874
|
-
|
|
4875
|
-
|
|
4876
|
-
|
|
4877
|
-
|
|
4878
|
-
|
|
4879
|
-
|
|
4880
|
-
|
|
4881
|
-
|
|
4882
|
-
"▄"
|
|
4883
|
-
],
|
|
4884
|
-
/** File mutation: a diamond setting solid. */
|
|
4885
|
-
edit: [
|
|
4886
|
-
"⋄",
|
|
4887
|
-
"◇",
|
|
4888
|
-
"◈",
|
|
4889
|
-
"◆",
|
|
4890
|
-
"❖",
|
|
4891
|
-
"◆",
|
|
4892
|
-
"◈",
|
|
4893
|
-
"◇"
|
|
4894
|
-
],
|
|
4895
|
-
/** Reading and searching: a lens focusing. */
|
|
4896
|
-
search: [
|
|
4897
|
-
"·",
|
|
4898
|
-
"∘",
|
|
4899
|
-
"◌",
|
|
4900
|
-
"○",
|
|
4901
|
-
"◍",
|
|
4902
|
-
"◎",
|
|
4903
|
-
"◉",
|
|
4904
|
-
"●"
|
|
4905
|
-
],
|
|
4906
|
-
/** Delegation to a child agent, a folded subagent row included: a pointer turning. */
|
|
4907
|
-
subagent: [
|
|
4908
|
-
"▲",
|
|
4909
|
-
"◥",
|
|
4910
|
-
"►",
|
|
4911
|
-
"◢",
|
|
4912
|
-
"▼",
|
|
4913
|
-
"◣",
|
|
4914
|
-
"◄",
|
|
4915
|
-
"◤"
|
|
4916
|
-
],
|
|
4917
|
-
/** Planning and scheduling, and an in-progress todo row: a bar rising and falling. */
|
|
4918
|
-
todo: [
|
|
4919
|
-
"▁",
|
|
4920
|
-
"▂",
|
|
4921
|
-
"▃",
|
|
4922
|
-
"▅",
|
|
4923
|
-
"▇",
|
|
4924
|
-
"▅",
|
|
4925
|
-
"▃",
|
|
4926
|
-
"▂"
|
|
4927
|
-
],
|
|
4928
|
-
/** Waiting on a human answer: a shade breathing in and out. */
|
|
4929
|
-
waiting: [
|
|
4930
|
-
" ",
|
|
4931
|
-
"░",
|
|
4932
|
-
"▒",
|
|
4933
|
-
"▓",
|
|
4934
|
-
"█",
|
|
4935
|
-
"▓",
|
|
4936
|
-
"▒",
|
|
4937
|
-
"░"
|
|
4938
|
-
],
|
|
4939
|
-
/** A tool with no family of its own: a star blooming. */
|
|
4940
|
-
other: [
|
|
4941
|
-
"✧",
|
|
4942
|
-
"✦",
|
|
4943
|
-
"✶",
|
|
4944
|
-
"✷",
|
|
4945
|
-
"✸",
|
|
4946
|
-
"✹",
|
|
4947
|
-
"✺",
|
|
4948
|
-
"✻"
|
|
4949
|
-
]
|
|
4950
|
-
};
|
|
4874
|
+
const TOOL_SPINNER = [
|
|
4875
|
+
"✧",
|
|
4876
|
+
"✦",
|
|
4877
|
+
"✶",
|
|
4878
|
+
"✷",
|
|
4879
|
+
"✸",
|
|
4880
|
+
"✹",
|
|
4881
|
+
"✺",
|
|
4882
|
+
"✻"
|
|
4883
|
+
];
|
|
4951
4884
|
/** Blank steps between two shimmer passes, so the sweep pauses past the word's end. */
|
|
4952
4885
|
const SHIMMER_GAP = 6;
|
|
4953
|
-
/** Tool names that execute commands. */
|
|
4954
|
-
const SHELL_TOOLS = new Set([
|
|
4955
|
-
"bash",
|
|
4956
|
-
"pwsh",
|
|
4957
|
-
"run_code"
|
|
4958
|
-
]);
|
|
4959
|
-
/** Tool names that mutate files. */
|
|
4960
|
-
const EDIT_TOOLS = new Set([
|
|
4961
|
-
"edit",
|
|
4962
|
-
"write",
|
|
4963
|
-
"str_replace_editor"
|
|
4964
|
-
]);
|
|
4965
|
-
/** Tool names that read or search, beyond the `TOOL_PREFIXES` below. */
|
|
4966
|
-
const SEARCH_TOOLS = new Set([
|
|
4967
|
-
"read",
|
|
4968
|
-
"read_image",
|
|
4969
|
-
"glob",
|
|
4970
|
-
"grep",
|
|
4971
|
-
"lsp",
|
|
4972
|
-
"skill",
|
|
4973
|
-
"web_fetch",
|
|
4974
|
-
"web_search",
|
|
4975
|
-
"load_workspace_dependencies",
|
|
4976
|
-
"list_subagent_models"
|
|
4977
|
-
]);
|
|
4978
|
-
/** Tool names that delegate or steer a child agent, beyond `subagent` itself. */
|
|
4979
|
-
const SUBAGENT_TOOLS = new Set([
|
|
4980
|
-
"send_message",
|
|
4981
|
-
"interrupt_agent",
|
|
4982
|
-
"list_agents",
|
|
4983
|
-
"ralph",
|
|
4984
|
-
"workflow",
|
|
4985
|
-
"spawn_teammate",
|
|
4986
|
-
"wait_agent"
|
|
4987
|
-
]);
|
|
4988
|
-
/** Tool names that plan or schedule work. */
|
|
4989
|
-
const TODO_TOOLS = new Set([
|
|
4990
|
-
"todo_write",
|
|
4991
|
-
"create_goal",
|
|
4992
|
-
"get_goal",
|
|
4993
|
-
"update_goal"
|
|
4994
|
-
]);
|
|
4995
|
-
/** Tool names that wait on a human answer. */
|
|
4996
|
-
const WAITING_TOOLS = new Set(["ask_user_question", "exit_plan_mode"]);
|
|
4997
|
-
/**
|
|
4998
|
-
* Tool-name prefixes per family, checked after the exact sets above. An MCP
|
|
4999
|
-
* or custom tool that keeps its family's prefix inherits the animation.
|
|
5000
|
-
*/
|
|
5001
|
-
const TOOL_PREFIXES = [
|
|
5002
|
-
["terminal_", "shell"],
|
|
5003
|
-
["session_", "search"],
|
|
5004
|
-
["cordis_inspect_", "search"],
|
|
5005
|
-
["list_mcp_", "search"],
|
|
5006
|
-
["read_mcp_", "search"],
|
|
5007
|
-
["team_task_", "subagent"],
|
|
5008
|
-
["schedule_", "todo"]
|
|
5009
|
-
];
|
|
5010
4886
|
/** The activity line's label while a compaction condenses history. */
|
|
5011
4887
|
const COMPACTING_ACTIVITY = "compacting";
|
|
5012
4888
|
/**
|
|
@@ -5041,21 +4917,6 @@ function activityStatus(activity) {
|
|
|
5041
4917
|
return "thinking";
|
|
5042
4918
|
}
|
|
5043
4919
|
/**
|
|
5044
|
-
* The family whose animation a running tool card draws for `name`.
|
|
5045
|
-
* @param name - the tool the model called.
|
|
5046
|
-
* @returns the tool's family, or `other` for a tool with no family.
|
|
5047
|
-
*/
|
|
5048
|
-
function toolFamily(name) {
|
|
5049
|
-
if (SHELL_TOOLS.has(name)) return "shell";
|
|
5050
|
-
if (EDIT_TOOLS.has(name)) return "edit";
|
|
5051
|
-
if (SEARCH_TOOLS.has(name)) return "search";
|
|
5052
|
-
if (isSubagentTool(name) || SUBAGENT_TOOLS.has(name)) return "subagent";
|
|
5053
|
-
if (TODO_TOOLS.has(name)) return "todo";
|
|
5054
|
-
if (WAITING_TOOLS.has(name)) return "waiting";
|
|
5055
|
-
for (const [prefix, family] of TOOL_PREFIXES) if (name.startsWith(prefix)) return family;
|
|
5056
|
-
return "other";
|
|
5057
|
-
}
|
|
5058
|
-
/**
|
|
5059
4920
|
* The frame an indicator draws at one instant. The frame index advances
|
|
5060
4921
|
* once per `periodMs` of wall clock, so indicators drawn at the same instant
|
|
5061
4922
|
* step together, and a change of animation keeps the beat.
|
|
@@ -5070,45 +4931,30 @@ function spinnerFrame(frames, now, periodMs, phase = 0) {
|
|
|
5070
4931
|
return frames[(Math.floor(now / periodMs) + phase) % 8] ?? frames[0];
|
|
5071
4932
|
}
|
|
5072
4933
|
/**
|
|
5073
|
-
*
|
|
5074
|
-
* frames
|
|
5075
|
-
*
|
|
5076
|
-
*
|
|
5077
|
-
*
|
|
5078
|
-
|
|
5079
|
-
|
|
5080
|
-
let count = 0;
|
|
5081
|
-
for (const [index, frame] of frames.entries()) if (frame === frames[((index + shift) % 8 + 8) % 8]) count += 1;
|
|
5082
|
-
return count;
|
|
5083
|
-
}
|
|
5084
|
-
/**
|
|
5085
|
-
* The phase a new indicator of `frames` spins at beside the indicators of
|
|
5086
|
-
* the same animation already spinning: a phase whose glyph differs from each
|
|
5087
|
-
* of theirs at every instant while one is left, otherwise the phase whose
|
|
5088
|
-
* glyph coincides with theirs at the fewest instants of a cycle. Ties go to
|
|
5089
|
-
* the phase farthest from its nearest neighbour, then to the lowest. An
|
|
5090
|
-
* animation whose frames are all distinct leaves every phase no indicator
|
|
5091
|
-
* holds; a palindromic one leaves only the phases an odd number of frames
|
|
5092
|
-
* away from each.
|
|
5093
|
-
* @param frames - the animation the new indicator draws.
|
|
5094
|
-
* @param taken - the phases of the indicators of `frames` spinning now, one per indicator.
|
|
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.
|
|
5095
4941
|
* @returns a phase from 0 to {@link SPINNER_CYCLE} - 1.
|
|
5096
4942
|
*/
|
|
5097
|
-
function staggerPhase(
|
|
4943
|
+
function staggerPhase(taken) {
|
|
5098
4944
|
let best = 0;
|
|
5099
4945
|
let fewest = Number.POSITIVE_INFINITY;
|
|
5100
4946
|
let widest = -1;
|
|
5101
4947
|
for (let phase = 0; phase < 8; phase += 1) {
|
|
5102
|
-
let
|
|
4948
|
+
let holders = 0;
|
|
5103
4949
|
let gap = 8;
|
|
5104
4950
|
for (const other of taken) {
|
|
5105
|
-
|
|
4951
|
+
if (other === phase) holders += 1;
|
|
5106
4952
|
const distance = Math.abs(phase - other);
|
|
5107
4953
|
gap = Math.min(gap, distance, 8 - distance);
|
|
5108
4954
|
}
|
|
5109
|
-
if (
|
|
4955
|
+
if (holders < fewest || holders === fewest && gap > widest) {
|
|
5110
4956
|
best = phase;
|
|
5111
|
-
fewest =
|
|
4957
|
+
fewest = holders;
|
|
5112
4958
|
widest = gap;
|
|
5113
4959
|
}
|
|
5114
4960
|
}
|
|
@@ -8016,26 +7862,6 @@ function turnGroups(blocks) {
|
|
|
8016
7862
|
return groups.filter((group) => group.sections.length > 0);
|
|
8017
7863
|
}
|
|
8018
7864
|
/**
|
|
8019
|
-
* The prompt that opens the newest turn: the first `user` section of the last
|
|
8020
|
-
* group {@link turnGroups} forms that has one. Every prompt block opens a
|
|
8021
|
-
* group and only a prompt block carries a `user` section, so that is the
|
|
8022
|
-
* newest prompt block's own, found by reading back from the newest block
|
|
8023
|
-
* without reading the parts of the blocks before it.
|
|
8024
|
-
* @param blocks - the navigable blocks.
|
|
8025
|
-
* @returns the prompt, or undefined while no block carries one.
|
|
8026
|
-
*/
|
|
8027
|
-
function lastPrompt(blocks) {
|
|
8028
|
-
for (let index = blocks.length - 1; index >= 0; index -= 1) {
|
|
8029
|
-
const block = blocks[index];
|
|
8030
|
-
if (block?.blockKind !== "user") continue;
|
|
8031
|
-
const part = block.parts().find((candidate) => candidate.kind === "user");
|
|
8032
|
-
if (part !== void 0) return {
|
|
8033
|
-
block,
|
|
8034
|
-
part
|
|
8035
|
-
};
|
|
8036
|
-
}
|
|
8037
|
-
}
|
|
8038
|
-
/**
|
|
8039
7865
|
* Which group holds one cursor.
|
|
8040
7866
|
* @param cursor - where the focus sits.
|
|
8041
7867
|
* @param groups - the groups of the same transcript.
|
|
@@ -8200,442 +8026,119 @@ function partLabels(cursor, blocks) {
|
|
|
8200
8026
|
}));
|
|
8201
8027
|
}
|
|
8202
8028
|
//#endregion
|
|
8203
|
-
//#region lib/types/
|
|
8029
|
+
//#region lib/types/todos.js
|
|
8204
8030
|
/**
|
|
8205
|
-
* The
|
|
8206
|
-
*
|
|
8207
|
-
*
|
|
8208
|
-
*
|
|
8209
|
-
*
|
|
8210
|
-
* `
|
|
8211
|
-
*
|
|
8212
|
-
* discards the terminal's scrollback - as soon as a line above it changed.
|
|
8213
|
-
* `previousViewportTop` is a high-water mark: every frame raises it towards
|
|
8214
|
-
* `frameLines - terminal.rows` and a shorter frame never lowers it again, so a
|
|
8215
|
-
* line that once left the window stays out of reach until the renderer redraws
|
|
8216
|
-
* in full and resets it.
|
|
8217
|
-
*
|
|
8218
|
-
* Anything that redraws lines a component already produced - the streaming
|
|
8219
|
-
* fade, a card fade, the focus gutter - therefore asks {@link repaintFloor} how
|
|
8220
|
-
* far into a block the renderer can still follow it, and
|
|
8221
|
-
* {@link GuardedMainScreen} gives the application the one moment where that
|
|
8222
|
-
* question can be answered: after a frame was built and before it is written.
|
|
8223
|
-
*
|
|
8224
|
-
* {@link GuardedMainScreen.suspend} is the other half of that rule: a
|
|
8225
|
-
* full-screen surface that takes the terminal holds the main screen off it
|
|
8226
|
-
* entirely rather than drawing over the conversation, so no line of the
|
|
8227
|
-
* conversation is rewritten while the surface is up and none of the surface's
|
|
8228
|
-
* own rows can reach the terminal's scrollback.
|
|
8229
|
-
*
|
|
8230
|
-
* The screen also keeps {@link PAGE_MARGIN_COLUMNS} blank columns on each
|
|
8231
|
-
* side of every frame: the tree lays out in the columns that remain and each
|
|
8232
|
-
* drawn line is moved right by that many spaces, so nothing the conversation
|
|
8233
|
-
* or the docked chrome draws touches either edge of the terminal.
|
|
8234
|
-
*
|
|
8235
|
-
* Every frame leaves here without its key marks: the screen takes them out
|
|
8236
|
-
* of the finished frame, overlays composited, and keeps where each marked
|
|
8237
|
-
* key was drawn ({@link GuardedMainScreen.keyFrame}).
|
|
8238
|
-
* @module @deepseek-ai/dsh-tui-app/screen
|
|
8031
|
+
* The agent's todo list as terminal rows: the status glyphs every todo surface
|
|
8032
|
+
* of this terminal draws, the picker choices the list offers, and the detail
|
|
8033
|
+
* rows one entered item prints. Completed picker content can take a paint
|
|
8034
|
+
* function so the list scratches it out. Everything here is pure text work
|
|
8035
|
+
* over plain values; the single service touch is one optional read of the
|
|
8036
|
+
* `todos` session projection.
|
|
8037
|
+
* @module @deepseek-ai/dsh-tui-app/todos
|
|
8239
8038
|
*/
|
|
8240
8039
|
/**
|
|
8241
|
-
*
|
|
8242
|
-
*
|
|
8243
|
-
*
|
|
8244
|
-
*
|
|
8040
|
+
* Terminal columns a picker row spends on content. The list draws one row per
|
|
8041
|
+
* todo, so content past this cap ends in `…` instead of wrapping onto a second
|
|
8042
|
+
* row; 64 columns plus the status glyph and the list's own row marker fit an
|
|
8043
|
+
* 80-column terminal. Columns, not characters: one wide character fills two of
|
|
8044
|
+
* them. A presentation choice of this terminal surface, not a deployment
|
|
8045
|
+
* setting.
|
|
8245
8046
|
*/
|
|
8246
|
-
const
|
|
8247
|
-
/** Columns a frame keeps for the tree before the margins are worth their cost. */
|
|
8248
|
-
const MIN_CONTENT_COLUMNS = 8;
|
|
8047
|
+
const TODO_LABEL_COLUMNS = 64;
|
|
8249
8048
|
/**
|
|
8250
|
-
*
|
|
8251
|
-
*
|
|
8252
|
-
*
|
|
8253
|
-
*
|
|
8254
|
-
*
|
|
8255
|
-
* @param width - the terminal's total width.
|
|
8256
|
-
* @returns the width inside the page margins, or the whole width on a terminal
|
|
8257
|
-
* too narrow for them.
|
|
8049
|
+
* Columns the detail rows wrap one item's full content to. Fixed rather than
|
|
8050
|
+
* read from the terminal so these rows stay plain values; 72 columns fit an
|
|
8051
|
+
* 80-column terminal, and a narrower terminal wraps them again when it draws
|
|
8052
|
+
* them. A presentation choice of this terminal surface, not a deployment
|
|
8053
|
+
* setting.
|
|
8258
8054
|
*/
|
|
8259
|
-
|
|
8260
|
-
|
|
8261
|
-
|
|
8055
|
+
const TODO_DETAIL_COLUMNS = 72;
|
|
8056
|
+
/**
|
|
8057
|
+
* Glyph per todo status: the marker a todo row leads with. This module is the
|
|
8058
|
+
* one home of the markers — every module of this terminal surface that prints
|
|
8059
|
+
* a todo row imports them from here rather than keeping its own table.
|
|
8060
|
+
*/
|
|
8061
|
+
const TODO_GLYPH = {
|
|
8062
|
+
completed: "✓",
|
|
8063
|
+
in_progress: "▸",
|
|
8064
|
+
pending: "○"
|
|
8065
|
+
};
|
|
8066
|
+
/** The word each status is spelled out as. */
|
|
8067
|
+
const TODO_WORD = {
|
|
8068
|
+
completed: "completed",
|
|
8069
|
+
in_progress: "in progress",
|
|
8070
|
+
pending: "pending"
|
|
8071
|
+
};
|
|
8072
|
+
/** Every status, in the order a counts row lists them. */
|
|
8073
|
+
const TODO_STATUSES = [
|
|
8074
|
+
"completed",
|
|
8075
|
+
"in_progress",
|
|
8076
|
+
"pending"
|
|
8077
|
+
];
|
|
8078
|
+
/**
|
|
8079
|
+
* The content a todo row shows: completed items take `paint` so the list can
|
|
8080
|
+
* scratch them out; every other status is the content unchanged.
|
|
8081
|
+
* @param content - the text after any row-length cut.
|
|
8082
|
+
* @param status - the item's status.
|
|
8083
|
+
* @param paint - how completed content is marked.
|
|
8084
|
+
* @returns the painted content, or `content` when the item is not completed or no paint was given.
|
|
8085
|
+
*/
|
|
8086
|
+
function paintTodoContent(content, status, paint) {
|
|
8087
|
+
return status === "completed" && paint !== void 0 ? paint(content) : content;
|
|
8262
8088
|
}
|
|
8263
|
-
/** The left margin as the spaces each drawn line is moved right by. */
|
|
8264
|
-
const LEFT_MARGIN = " ".repeat(1);
|
|
8265
8089
|
/**
|
|
8266
|
-
* The
|
|
8267
|
-
*
|
|
8268
|
-
* the
|
|
8269
|
-
* @param
|
|
8270
|
-
* @returns
|
|
8271
|
-
*
|
|
8090
|
+
* The agent's current todo list as picker rows, in write order.
|
|
8091
|
+
* @param ctx - plugin context carrying the optional session-projection registry.
|
|
8092
|
+
* @param session - the session whose todo list is read.
|
|
8093
|
+
* @param paint - how completed content is marked; omitted leaves it unmarked.
|
|
8094
|
+
* @returns one choice per item. Empty in three cases: no projection registry
|
|
8095
|
+
* is composed in this profile, the registry has no `todos` unit registered, or
|
|
8096
|
+
* the value is `null` — which it is before the first `todo_write` of the
|
|
8097
|
+
* current turn, since every `turn/start` clears the list.
|
|
8272
8098
|
*/
|
|
8273
|
-
function
|
|
8274
|
-
|
|
8099
|
+
function listTodoChoices(ctx, session, paint) {
|
|
8100
|
+
const projections = ctx.get("sessionProjections");
|
|
8101
|
+
if (projections === void 0) return [];
|
|
8102
|
+
const items = projections.snapshot(session, ["todos"]).values.todos;
|
|
8103
|
+
if (items === void 0 || items === null) return [];
|
|
8104
|
+
return items.map((item, index) => ({
|
|
8105
|
+
index,
|
|
8106
|
+
label: `${TODO_GLYPH[item.status]} ${paintTodoContent(labelContent(item.content), item.status, paint)}`,
|
|
8107
|
+
description: describeStatus(item.status),
|
|
8108
|
+
status: item.status
|
|
8109
|
+
}));
|
|
8275
8110
|
}
|
|
8276
8111
|
/**
|
|
8277
|
-
*
|
|
8278
|
-
*
|
|
8279
|
-
*
|
|
8280
|
-
*
|
|
8281
|
-
*
|
|
8282
|
-
* gave its margins up.
|
|
8283
|
-
* @returns the frame as it is written.
|
|
8112
|
+
* One content line cut to a single picker row.
|
|
8113
|
+
* @param content - the item's content.
|
|
8114
|
+
* @returns the content unchanged, or its leading columns followed by `…`,
|
|
8115
|
+
* together never wider than {@link TODO_LABEL_COLUMNS}. A wide character that
|
|
8116
|
+
* would straddle the cut is dropped rather than halved.
|
|
8284
8117
|
*/
|
|
8285
|
-
function
|
|
8286
|
-
if (
|
|
8287
|
-
return
|
|
8118
|
+
function labelContent(content) {
|
|
8119
|
+
if (visibleWidth(content) <= TODO_LABEL_COLUMNS) return content;
|
|
8120
|
+
return `${sliceByColumn(content, 0, TODO_LABEL_COLUMNS - 1, true)}…`;
|
|
8288
8121
|
}
|
|
8289
8122
|
/**
|
|
8290
|
-
* The
|
|
8291
|
-
* @param
|
|
8292
|
-
* @
|
|
8293
|
-
* {@link GuardedMainScreen} hands it to its guard.
|
|
8294
|
-
* @returns the block's own first repaintable line index, 0 while the whole
|
|
8295
|
-
* block lies inside the window.
|
|
8123
|
+
* The picker description for one status.
|
|
8124
|
+
* @param status - the item's status.
|
|
8125
|
+
* @returns the status word, and for `in_progress` that the item is being worked on now.
|
|
8296
8126
|
*/
|
|
8297
|
-
function
|
|
8298
|
-
return
|
|
8127
|
+
function describeStatus(status) {
|
|
8128
|
+
return status === "in_progress" ? `${TODO_WORD[status]} · being worked on now` : TODO_WORD[status];
|
|
8299
8129
|
}
|
|
8300
8130
|
/**
|
|
8301
|
-
* The
|
|
8302
|
-
*
|
|
8303
|
-
*
|
|
8304
|
-
*
|
|
8305
|
-
*
|
|
8306
|
-
*
|
|
8307
|
-
*
|
|
8308
|
-
*
|
|
8309
|
-
*
|
|
8310
|
-
*
|
|
8311
|
-
*
|
|
8312
|
-
* A frame the renderer writes in full instead - after a resize, or for a
|
|
8313
|
-
* change above its window - leaves the window at that frame's own viewport.
|
|
8314
|
-
* When the guard settled that frame against a higher `previousViewportTop`,
|
|
8315
|
-
* what it decided no longer matches the terminal, so the screen renders once
|
|
8316
|
-
* more and the guard settles against the window the terminal now has.
|
|
8317
|
-
*
|
|
8318
|
-
* It can also be suspended, which stops every write to the terminal while
|
|
8319
|
-
* leaving the renderer's record of the main screen exactly as it was. The
|
|
8320
|
-
* terminal restores that same screen when the surface that took it gives it
|
|
8321
|
-
* back, so the first frame after {@link GuardedMainScreen.resume} writes only
|
|
8322
|
-
* what changed meanwhile.
|
|
8323
|
-
*/
|
|
8324
|
-
var GuardedMainScreen = class extends TuiMainScreen {
|
|
8325
|
-
guard;
|
|
8326
|
-
/** What draws instead while another surface holds the terminal; absent while this screen does. */
|
|
8327
|
-
onSuspendedRender;
|
|
8328
|
-
/** The keys the last frame drew, by frame line. */
|
|
8329
|
-
keys = EMPTY_KEY_FRAME;
|
|
8330
|
-
/**
|
|
8331
|
-
* Whether the guard settled the last frame against a `previousViewportTop`
|
|
8332
|
-
* above that frame's own viewport, which a frame written in full lowers.
|
|
8333
|
-
*/
|
|
8334
|
-
settledAboveViewport = false;
|
|
8335
|
-
/**
|
|
8336
|
-
* @param terminal - the terminal the tree renders into.
|
|
8337
|
-
* @param showHardwareCursor - whether the terminal's own cursor is the caret.
|
|
8338
|
-
* @param guard - given the frame's first repaintable line, the width it was
|
|
8339
|
-
* built at, and how many lines it has, applies what that geometry decides
|
|
8340
|
-
* and reports whether it changed any line; run at most
|
|
8341
|
-
* {@link SETTLE_PASSES} times per frame, each `true` on a frame that is
|
|
8342
|
-
* built again. The frame's own length is what places an overlay, which
|
|
8343
|
-
* pi-tui composites into its last `terminal.rows` lines.
|
|
8344
|
-
*/
|
|
8345
|
-
constructor(terminal, showHardwareCursor, guard) {
|
|
8346
|
-
super(terminal, showHardwareCursor);
|
|
8347
|
-
this.guard = guard;
|
|
8348
|
-
}
|
|
8349
|
-
/**
|
|
8350
|
-
* Stop writing to the terminal, and answer every render request with
|
|
8351
|
-
* `onRender` instead.
|
|
8352
|
-
*
|
|
8353
|
-
* Nothing about the renderer's record of the main screen changes, so the
|
|
8354
|
-
* frame it will judge its next write against stays the frame the terminal
|
|
8355
|
-
* still holds behind the surface that took over.
|
|
8356
|
-
* @param onRender - called wherever a frame would have been written, so the
|
|
8357
|
-
* surface that owns the terminal draws on the application's existing render
|
|
8358
|
-
* requests rather than on a clock of its own.
|
|
8359
|
-
*/
|
|
8360
|
-
suspend(onRender) {
|
|
8361
|
-
this.onSuspendedRender = onRender;
|
|
8362
|
-
}
|
|
8363
|
-
/** Write to the terminal again, and draw whatever changed while suspended. */
|
|
8364
|
-
resume() {
|
|
8365
|
-
if (this.onSuspendedRender === void 0) return;
|
|
8366
|
-
this.onSuspendedRender = void 0;
|
|
8367
|
-
this.requestRender();
|
|
8368
|
-
}
|
|
8369
|
-
/**
|
|
8370
|
-
* Request a frame, or draw the surface that suspended this screen.
|
|
8371
|
-
* @param force - redraw from scratch; ignored while suspended, where
|
|
8372
|
-
* discarding the record would lose the screen the terminal is holding.
|
|
8373
|
-
*/
|
|
8374
|
-
requestRender(force = false) {
|
|
8375
|
-
const suspended = this.onSuspendedRender;
|
|
8376
|
-
if (suspended === void 0) {
|
|
8377
|
-
super.requestRender(force);
|
|
8378
|
-
return;
|
|
8379
|
-
}
|
|
8380
|
-
suspended();
|
|
8381
|
-
}
|
|
8382
|
-
/**
|
|
8383
|
-
* Write a frame now, or draw the suspending surface now.
|
|
8384
|
-
* @param force - redraw from scratch; ignored while suspended, as in
|
|
8385
|
-
* {@link GuardedMainScreen.requestRender}.
|
|
8386
|
-
*/
|
|
8387
|
-
renderNow(force = false) {
|
|
8388
|
-
const suspended = this.onSuspendedRender;
|
|
8389
|
-
if (suspended === void 0) {
|
|
8390
|
-
super.renderNow(force);
|
|
8391
|
-
return;
|
|
8392
|
-
}
|
|
8393
|
-
suspended();
|
|
8394
|
-
}
|
|
8395
|
-
/**
|
|
8396
|
-
* Where the last written frame drew its keys, and the frame line the
|
|
8397
|
-
* terminal's cursor was left on, which is what a cursor report places the
|
|
8398
|
-
* frame by.
|
|
8399
|
-
* @returns the snapshot; later frames never change it.
|
|
8400
|
-
*/
|
|
8401
|
-
keyFrame() {
|
|
8402
|
-
return {
|
|
8403
|
-
keys: this.keys,
|
|
8404
|
-
cursorLine: this.captureRenderState().hardwareCursorRow
|
|
8405
|
-
};
|
|
8406
|
-
}
|
|
8407
|
-
/**
|
|
8408
|
-
* Take every key mark out of the finished frame before pi-tui resets and
|
|
8409
|
-
* writes its lines, keeping where each key was drawn. The renderer calls
|
|
8410
|
-
* this once per frame, after the overlays are composited into it and before
|
|
8411
|
-
* it is compared with what the terminal holds, so the kept cells are the
|
|
8412
|
-
* written frame's own.
|
|
8413
|
-
* @param lines - the finished frame.
|
|
8414
|
-
* @returns the frame with pi-tui's line resets applied and no key mark left.
|
|
8415
|
-
*/
|
|
8416
|
-
applyLineResets(lines) {
|
|
8417
|
-
const marked = takeKeyFrame(lines);
|
|
8418
|
-
this.keys = marked.keys;
|
|
8419
|
-
return super.applyLineResets(marked.lines);
|
|
8420
|
-
}
|
|
8421
|
-
/**
|
|
8422
|
-
* Write the frame, unless another surface holds the terminal, and request
|
|
8423
|
-
* one more frame when this one was written in full after the guard settled
|
|
8424
|
-
* it against a window top the full write lowered.
|
|
8425
|
-
*/
|
|
8426
|
-
doRender() {
|
|
8427
|
-
if (this.onSuspendedRender !== void 0) return;
|
|
8428
|
-
const fullRedraws = this.fullRedraws;
|
|
8429
|
-
super.doRender();
|
|
8430
|
-
if (this.fullRedraws !== fullRedraws && this.settledAboveViewport) this.requestRender();
|
|
8431
|
-
}
|
|
8432
|
-
/**
|
|
8433
|
-
* Build the frame inside the page margins, let the guard settle what its
|
|
8434
|
-
* geometry decides, and build it again for every pass that changed a line.
|
|
8435
|
-
*
|
|
8436
|
-
* The guard is handed the width the tree was laid out in, not the terminal's
|
|
8437
|
-
* own, so the line counts it walks are the ones this frame has.
|
|
8438
|
-
* @param width - the terminal's total width.
|
|
8439
|
-
* @returns the frame to write, indented by the left margin and settled
|
|
8440
|
-
* against its own geometry.
|
|
8441
|
-
*/
|
|
8442
|
-
render(width) {
|
|
8443
|
-
const content = pageContentWidth(width);
|
|
8444
|
-
const margin = pageMargin(width);
|
|
8445
|
-
const previousTop = this.captureRenderState().previousViewportTop;
|
|
8446
|
-
let lines = indentFrame(super.render(content), margin);
|
|
8447
|
-
for (let pass = 0; pass < SETTLE_PASSES; pass += 1) {
|
|
8448
|
-
if (!this.guard(Math.max(previousTop, lines.length - this.terminal.rows), content, lines.length)) break;
|
|
8449
|
-
lines = indentFrame(super.render(content), margin);
|
|
8450
|
-
}
|
|
8451
|
-
this.settledAboveViewport = previousTop > Math.max(0, lines.length - this.terminal.rows);
|
|
8452
|
-
return lines;
|
|
8453
|
-
}
|
|
8454
|
-
};
|
|
8455
|
-
/** What ends a bar the width cut short; one column, so the mark itself fits. */
|
|
8456
|
-
const ELLIPSIS$3 = "…";
|
|
8457
|
-
/**
|
|
8458
|
-
* One prompt as a single row: the prompt glyph, then the prompt's rows joined
|
|
8459
|
-
* with every run of whitespace collapsed to one space, cut to `width` with an
|
|
8460
|
-
* ellipsis, on the prompt band.
|
|
8461
|
-
* @param palette - the palette the band is drawn with.
|
|
8462
|
-
* @param rows - the prompt's source rows.
|
|
8463
|
-
* @param width - the columns the bar spans.
|
|
8464
|
-
* @returns the row: exactly `width` columns under the band on an enabled
|
|
8465
|
-
* palette, and the unpadded text, no wider than `width`, on a disabled one.
|
|
8466
|
-
*/
|
|
8467
|
-
function pinnedPromptRow(palette, rows, width) {
|
|
8468
|
-
return bandRow(palette, truncateToWidth(` ❯ ${rows.join(" ").replaceAll(/\s+/gu, " ").trim()} `, width, ELLIPSIS$3), width);
|
|
8469
|
-
}
|
|
8470
|
-
/**
|
|
8471
|
-
* The viewport row the main screen floats the bar on: the first row the
|
|
8472
|
-
* terminal shows, `viewportFloor` rows into the viewport, whose line is the
|
|
8473
|
-
* renderer's first repaintable one. The bar is drawn there while every line
|
|
8474
|
-
* of the prompt's block lies above that line and the line belongs to the
|
|
8475
|
-
* conversation rather than the header or the docked chrome. A frame that
|
|
8476
|
-
* shrank by the terminal's height or more leaves that line past the frame's
|
|
8477
|
-
* end, which belongs to neither.
|
|
8478
|
-
* @param geometry - where the prompt, the conversation, and the viewport sit.
|
|
8479
|
-
* @returns the row, counted from the viewport's top, or undefined while no
|
|
8480
|
-
* bar is drawn.
|
|
8481
|
-
*/
|
|
8482
|
-
function pinnedPromptPlacement(geometry) {
|
|
8483
|
-
const { promptEnd, transcriptEnd, viewportStart, viewportFloor } = geometry;
|
|
8484
|
-
const shown = viewportStart + viewportFloor;
|
|
8485
|
-
return promptEnd <= shown && shown < transcriptEnd ? viewportFloor : void 0;
|
|
8486
|
-
}
|
|
8487
|
-
/**
|
|
8488
|
-
* Where the main screen's bar floats: on one viewport row, across the
|
|
8489
|
-
* terminal's whole width, and without taking the keyboard. The pane lays the
|
|
8490
|
-
* bar out inside the page margins itself, as the main screen lays out its
|
|
8491
|
-
* frame, so the bar lines up with the conversation at every width.
|
|
8492
|
-
* @param row - the viewport row, as {@link pinnedPromptPlacement} places it.
|
|
8493
|
-
* @returns the overlay options the bar is shown with.
|
|
8494
|
-
*/
|
|
8495
|
-
function pinnedPromptOverlay(row) {
|
|
8496
|
-
return {
|
|
8497
|
-
anchor: "top-left",
|
|
8498
|
-
width: "100%",
|
|
8499
|
-
margin: { top: row },
|
|
8500
|
-
nonCapturing: true
|
|
8501
|
-
};
|
|
8502
|
-
}
|
|
8503
|
-
/** The bar as the main screen floats it: the left page margin, then the bar across the columns between the margins. */
|
|
8504
|
-
var PinnedPromptPane = class {
|
|
8505
|
-
palette;
|
|
8506
|
-
rows;
|
|
8507
|
-
/**
|
|
8508
|
-
* @param palette - the palette the bar is drawn with.
|
|
8509
|
-
* @param rows - the prompt's source rows.
|
|
8510
|
-
*/
|
|
8511
|
-
constructor(palette, rows) {
|
|
8512
|
-
this.palette = palette;
|
|
8513
|
-
this.rows = rows;
|
|
8514
|
-
}
|
|
8515
|
-
invalidate() {}
|
|
8516
|
-
/**
|
|
8517
|
-
* Draw the bar at `width`.
|
|
8518
|
-
* @param width - the width the overlay was laid out at, which is the terminal's own.
|
|
8519
|
-
* @returns exactly one line.
|
|
8520
|
-
*/
|
|
8521
|
-
render(width) {
|
|
8522
|
-
return [`${pageMargin(width)}${pinnedPromptRow(this.palette, this.rows, pageContentWidth(width))}`];
|
|
8523
|
-
}
|
|
8524
|
-
};
|
|
8525
|
-
//#endregion
|
|
8526
|
-
//#region lib/types/todos.js
|
|
8527
|
-
/**
|
|
8528
|
-
* The agent's todo list as terminal rows: the status glyphs every todo surface
|
|
8529
|
-
* of this terminal draws, the picker choices the list offers, and the detail
|
|
8530
|
-
* rows one entered item prints. Completed picker content can take a paint
|
|
8531
|
-
* function so the list scratches it out. Everything here is pure text work
|
|
8532
|
-
* over plain values; the single service touch is one optional read of the
|
|
8533
|
-
* `todos` session projection.
|
|
8534
|
-
* @module @deepseek-ai/dsh-tui-app/todos
|
|
8535
|
-
*/
|
|
8536
|
-
/**
|
|
8537
|
-
* Terminal columns a picker row spends on content. The list draws one row per
|
|
8538
|
-
* todo, so content past this cap ends in `…` instead of wrapping onto a second
|
|
8539
|
-
* row; 64 columns plus the status glyph and the list's own row marker fit an
|
|
8540
|
-
* 80-column terminal. Columns, not characters: one wide character fills two of
|
|
8541
|
-
* them. A presentation choice of this terminal surface, not a deployment
|
|
8542
|
-
* setting.
|
|
8543
|
-
*/
|
|
8544
|
-
const TODO_LABEL_COLUMNS = 64;
|
|
8545
|
-
/**
|
|
8546
|
-
* Columns the detail rows wrap one item's full content to. Fixed rather than
|
|
8547
|
-
* read from the terminal so these rows stay plain values; 72 columns fit an
|
|
8548
|
-
* 80-column terminal, and a narrower terminal wraps them again when it draws
|
|
8549
|
-
* them. A presentation choice of this terminal surface, not a deployment
|
|
8550
|
-
* setting.
|
|
8551
|
-
*/
|
|
8552
|
-
const TODO_DETAIL_COLUMNS = 72;
|
|
8553
|
-
/**
|
|
8554
|
-
* Glyph per todo status: the marker a todo row leads with. This module is the
|
|
8555
|
-
* one home of the markers — every module of this terminal surface that prints
|
|
8556
|
-
* a todo row imports them from here rather than keeping its own table.
|
|
8557
|
-
*/
|
|
8558
|
-
const TODO_GLYPH = {
|
|
8559
|
-
completed: "✓",
|
|
8560
|
-
in_progress: "▸",
|
|
8561
|
-
pending: "○"
|
|
8562
|
-
};
|
|
8563
|
-
/** The word each status is spelled out as. */
|
|
8564
|
-
const TODO_WORD = {
|
|
8565
|
-
completed: "completed",
|
|
8566
|
-
in_progress: "in progress",
|
|
8567
|
-
pending: "pending"
|
|
8568
|
-
};
|
|
8569
|
-
/** Every status, in the order a counts row lists them. */
|
|
8570
|
-
const TODO_STATUSES = [
|
|
8571
|
-
"completed",
|
|
8572
|
-
"in_progress",
|
|
8573
|
-
"pending"
|
|
8574
|
-
];
|
|
8575
|
-
/**
|
|
8576
|
-
* The content a todo row shows: completed items take `paint` so the list can
|
|
8577
|
-
* scratch them out; every other status is the content unchanged.
|
|
8578
|
-
* @param content - the text after any row-length cut.
|
|
8579
|
-
* @param status - the item's status.
|
|
8580
|
-
* @param paint - how completed content is marked.
|
|
8581
|
-
* @returns the painted content, or `content` when the item is not completed or no paint was given.
|
|
8582
|
-
*/
|
|
8583
|
-
function paintTodoContent(content, status, paint) {
|
|
8584
|
-
return status === "completed" && paint !== void 0 ? paint(content) : content;
|
|
8585
|
-
}
|
|
8586
|
-
/**
|
|
8587
|
-
* The agent's current todo list as picker rows, in write order.
|
|
8588
|
-
* @param ctx - plugin context carrying the optional session-projection registry.
|
|
8589
|
-
* @param session - the session whose todo list is read.
|
|
8590
|
-
* @param paint - how completed content is marked; omitted leaves it unmarked.
|
|
8591
|
-
* @returns one choice per item. Empty in three cases: no projection registry
|
|
8592
|
-
* is composed in this profile, the registry has no `todos` unit registered, or
|
|
8593
|
-
* the value is `null` — which it is before the first `todo_write` of the
|
|
8594
|
-
* current turn, since every `turn/start` clears the list.
|
|
8595
|
-
*/
|
|
8596
|
-
function listTodoChoices(ctx, session, paint) {
|
|
8597
|
-
const projections = ctx.get("sessionProjections");
|
|
8598
|
-
if (projections === void 0) return [];
|
|
8599
|
-
const items = projections.snapshot(session, ["todos"]).values.todos;
|
|
8600
|
-
if (items === void 0 || items === null) return [];
|
|
8601
|
-
return items.map((item, index) => ({
|
|
8602
|
-
index,
|
|
8603
|
-
label: `${TODO_GLYPH[item.status]} ${paintTodoContent(labelContent(item.content), item.status, paint)}`,
|
|
8604
|
-
description: describeStatus(item.status),
|
|
8605
|
-
status: item.status
|
|
8606
|
-
}));
|
|
8607
|
-
}
|
|
8608
|
-
/**
|
|
8609
|
-
* One content line cut to a single picker row.
|
|
8610
|
-
* @param content - the item's content.
|
|
8611
|
-
* @returns the content unchanged, or its leading columns followed by `…`,
|
|
8612
|
-
* together never wider than {@link TODO_LABEL_COLUMNS}. A wide character that
|
|
8613
|
-
* would straddle the cut is dropped rather than halved.
|
|
8614
|
-
*/
|
|
8615
|
-
function labelContent(content) {
|
|
8616
|
-
if (visibleWidth(content) <= TODO_LABEL_COLUMNS) return content;
|
|
8617
|
-
return `${sliceByColumn(content, 0, TODO_LABEL_COLUMNS - 1, true)}…`;
|
|
8618
|
-
}
|
|
8619
|
-
/**
|
|
8620
|
-
* The picker description for one status.
|
|
8621
|
-
* @param status - the item's status.
|
|
8622
|
-
* @returns the status word, and for `in_progress` that the item is being worked on now.
|
|
8623
|
-
*/
|
|
8624
|
-
function describeStatus(status) {
|
|
8625
|
-
return status === "in_progress" ? `${TODO_WORD[status]} · being worked on now` : TODO_WORD[status];
|
|
8626
|
-
}
|
|
8627
|
-
/**
|
|
8628
|
-
* The rows one entered todo prints: its full content wrapped to
|
|
8629
|
-
* {@link TODO_DETAIL_COLUMNS}, its status, its position in the list, the
|
|
8630
|
-
* list's counts by status, and — when the caller tracked them — the turn the
|
|
8631
|
-
* item first appeared in and the turn its status last changed in. Equal turns
|
|
8632
|
-
* print the appearance row alone: an item still holding the status it was
|
|
8633
|
-
* written with has no later change to report.
|
|
8634
|
-
* @param items - the list the entered row was drawn from.
|
|
8635
|
-
* @param index - zero-based position of the entered row.
|
|
8636
|
-
* @param transition - the turn facts the caller tracked for this item, when it has them.
|
|
8637
|
-
* @returns the detail rows; one row naming the missing item when `index` is
|
|
8638
|
-
* outside the list, which it is once a later `todo/write` shortened it.
|
|
8131
|
+
* The rows one entered todo prints: its full content wrapped to
|
|
8132
|
+
* {@link TODO_DETAIL_COLUMNS}, its status, its position in the list, the
|
|
8133
|
+
* list's counts by status, and — when the caller tracked them — the turn the
|
|
8134
|
+
* item first appeared in and the turn its status last changed in. Equal turns
|
|
8135
|
+
* print the appearance row alone: an item still holding the status it was
|
|
8136
|
+
* written with has no later change to report.
|
|
8137
|
+
* @param items - the list the entered row was drawn from.
|
|
8138
|
+
* @param index - zero-based position of the entered row.
|
|
8139
|
+
* @param transition - the turn facts the caller tracked for this item, when it has them.
|
|
8140
|
+
* @returns the detail rows; one row naming the missing item when `index` is
|
|
8141
|
+
* outside the list, which it is once a later `todo/write` shortened it.
|
|
8639
8142
|
*/
|
|
8640
8143
|
function todoDetail(items, index, transition) {
|
|
8641
8144
|
const item = items[index];
|
|
@@ -8967,7 +8470,7 @@ const WINDOW_MARK_WIDTH = 2;
|
|
|
8967
8470
|
/** Columns the brackets around the selected label take. */
|
|
8968
8471
|
const BRACKET_WIDTH = 2;
|
|
8969
8472
|
/** What ends a line the width cut short; one column, so the mark itself fits. */
|
|
8970
|
-
const ELLIPSIS$
|
|
8473
|
+
const ELLIPSIS$3 = "…";
|
|
8971
8474
|
/** Facts the unfocused line keeps; every other present segment folds into `+N`. */
|
|
8972
8475
|
const KEY_SEGMENT_IDS = new Set([
|
|
8973
8476
|
"model",
|
|
@@ -9176,7 +8679,7 @@ function windowSpan(widths, selected, budget, sep) {
|
|
|
9176
8679
|
* @returns the line, ellipsized when it was wider.
|
|
9177
8680
|
*/
|
|
9178
8681
|
function fitLine(line, width) {
|
|
9179
|
-
return truncateToWidth(line, Math.max(1, width), ELLIPSIS$
|
|
8682
|
+
return truncateToWidth(line, Math.max(1, width), ELLIPSIS$3);
|
|
9180
8683
|
}
|
|
9181
8684
|
/**
|
|
9182
8685
|
* The label the bar draws for the segment it anchors on, which
|
|
@@ -9188,7 +8691,7 @@ function fitLine(line, width) {
|
|
|
9188
8691
|
function anchorLabel(segment) {
|
|
9189
8692
|
if (segment === void 0) return "";
|
|
9190
8693
|
if (visibleWidth(segment.label) <= MODEL_LABEL_WIDTH) return segment.label;
|
|
9191
|
-
return truncateToWidth(segment.short ?? segment.label, MODEL_LABEL_WIDTH, ELLIPSIS$
|
|
8694
|
+
return truncateToWidth(segment.short ?? segment.label, MODEL_LABEL_WIDTH, ELLIPSIS$3);
|
|
9192
8695
|
}
|
|
9193
8696
|
/**
|
|
9194
8697
|
* The entry keys this width names.
|
|
@@ -9282,7 +8785,7 @@ function expansionLine(segment, palette, width) {
|
|
|
9282
8785
|
const prefix = palette.dim(body);
|
|
9283
8786
|
const rest = width - visibleWidth(suffix);
|
|
9284
8787
|
if (rest < 1) return fitLine(`${prefix}${suffix}`, width);
|
|
9285
|
-
return `${truncateToWidth(prefix, rest, ELLIPSIS$
|
|
8788
|
+
return `${truncateToWidth(prefix, rest, ELLIPSIS$3)}${suffix}`;
|
|
9286
8789
|
}
|
|
9287
8790
|
/**
|
|
9288
8791
|
* One segment label as the focused bar draws it. The selected one is
|
|
@@ -9310,7 +8813,7 @@ function segmentLabel(text, selected, palette, level) {
|
|
|
9310
8813
|
function fitSelected(text, room) {
|
|
9311
8814
|
const inside = room - BRACKET_WIDTH;
|
|
9312
8815
|
if (visibleWidth(text) <= inside) return text;
|
|
9313
|
-
return truncateToWidth(text, Math.max(1, inside), ELLIPSIS$
|
|
8816
|
+
return truncateToWidth(text, Math.max(1, inside), ELLIPSIS$3);
|
|
9314
8817
|
}
|
|
9315
8818
|
/**
|
|
9316
8819
|
* The segments after the anchor, windowed around the selection. `‹` and `›`
|
|
@@ -9583,6 +9086,21 @@ function renderQueuePanel(rows, render) {
|
|
|
9583
9086
|
}));
|
|
9584
9087
|
return lines.join("\n");
|
|
9585
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
|
+
}
|
|
9586
9104
|
/** Narrowest turn list. */
|
|
9587
9105
|
const LIST_MIN_WIDTH = 18;
|
|
9588
9106
|
/** Widest turn list. */
|
|
@@ -11345,146 +10863,399 @@ function parseHexColor(color) {
|
|
|
11345
10863
|
};
|
|
11346
10864
|
}
|
|
11347
10865
|
/**
|
|
11348
|
-
* The terminal's syntax highlighter: one shiki core, built when the first
|
|
11349
|
-
* fence, file row, or shell command resolves a grammar and grown as further
|
|
11350
|
-
* languages are asked for.
|
|
10866
|
+
* The terminal's syntax highlighter: one shiki core, built when the first
|
|
10867
|
+
* fence, file row, or shell command resolves a grammar and grown as further
|
|
10868
|
+
* languages are asked for.
|
|
10869
|
+
*/
|
|
10870
|
+
var SyntaxHighlighter = class {
|
|
10871
|
+
options;
|
|
10872
|
+
/** The shiki core, once a theme and one grammar have landed. */
|
|
10873
|
+
core;
|
|
10874
|
+
/**
|
|
10875
|
+
* The core being built, so two fences of different languages on one frame
|
|
10876
|
+
* share it: each would otherwise build a core of its own, and the one that
|
|
10877
|
+
* finished last would be the only one holding a grammar.
|
|
10878
|
+
*/
|
|
10879
|
+
building;
|
|
10880
|
+
/** The theme's own name, which `codeToTokens` resolves it by. */
|
|
10881
|
+
theme = "";
|
|
10882
|
+
/** Grammar ids already registered on the core. */
|
|
10883
|
+
loaded = /* @__PURE__ */ new Set();
|
|
10884
|
+
/** Grammar ids whose import is in flight, so each is asked for once. */
|
|
10885
|
+
pending = /* @__PURE__ */ new Set();
|
|
10886
|
+
/**
|
|
10887
|
+
* @param options - the colour depth, the terminal background, and the redraw request.
|
|
10888
|
+
*/
|
|
10889
|
+
constructor(options) {
|
|
10890
|
+
this.options = options;
|
|
10891
|
+
}
|
|
10892
|
+
/**
|
|
10893
|
+
* Colour one fenced block, file row group, or shell command.
|
|
10894
|
+
* @param code - the block's source, newline separated.
|
|
10895
|
+
* @param lang - the fence's info string, a file extension, `shellscript`, or
|
|
10896
|
+
* undefined for a bare fence.
|
|
10897
|
+
* @returns one styled line per source line, or undefined while the language
|
|
10898
|
+
* has no grammar here, its grammar is still loading, or the terminal takes
|
|
10899
|
+
* no colour - all of which the caller draws plain.
|
|
10900
|
+
*/
|
|
10901
|
+
lines(code, lang) {
|
|
10902
|
+
if (this.options.depth === "none") return void 0;
|
|
10903
|
+
const resolved = ALIASES.get((lang ?? "").toLowerCase());
|
|
10904
|
+
if (resolved === void 0) return void 0;
|
|
10905
|
+
if (!this.loaded.has(resolved)) {
|
|
10906
|
+
this.load(resolved);
|
|
10907
|
+
return;
|
|
10908
|
+
}
|
|
10909
|
+
const core = this.core;
|
|
10910
|
+
/* v8 ignore next -- a loaded grammar means the core is built */
|
|
10911
|
+
if (core === void 0) return void 0;
|
|
10912
|
+
try {
|
|
10913
|
+
const { tokens } = core.codeToTokens(code, {
|
|
10914
|
+
lang: resolved,
|
|
10915
|
+
theme: this.theme
|
|
10916
|
+
});
|
|
10917
|
+
return tokens.map((line) => line.map((token) => this.paint(token)).join("") + RESET_FOREGROUND);
|
|
10918
|
+
} catch {
|
|
10919
|
+
this.loaded.delete(resolved);
|
|
10920
|
+
return;
|
|
10921
|
+
}
|
|
10922
|
+
}
|
|
10923
|
+
/**
|
|
10924
|
+
* Draw one token with the theme's colour and font style.
|
|
10925
|
+
* @param token - the themed token.
|
|
10926
|
+
* @returns the token's text, wrapped in the sequences it is drawn with.
|
|
10927
|
+
*/
|
|
10928
|
+
paint(token) {
|
|
10929
|
+
const color = tokenSgr(token.color, this.options.depth);
|
|
10930
|
+
/* v8 ignore next -- shiki writes a style of 0 rather than leaving it out */
|
|
10931
|
+
const style = token.fontStyle ?? 0;
|
|
10932
|
+
const bold = (style & FONT_STYLE.bold) === 0 ? "" : BOLD;
|
|
10933
|
+
const italic = (style & FONT_STYLE.italic) === 0 ? "" : ITALIC;
|
|
10934
|
+
const closeBold = bold === "" ? "" : RESET_BOLD;
|
|
10935
|
+
const closeItalic = italic === "" ? "" : RESET_ITALIC;
|
|
10936
|
+
return `${color}${bold}${italic}${token.content}${closeItalic}${closeBold}`;
|
|
10937
|
+
}
|
|
10938
|
+
/**
|
|
10939
|
+
* Bring up the core for one grammar, then ask for the frame again.
|
|
10940
|
+
* @param id - the grammar to register.
|
|
10941
|
+
*/
|
|
10942
|
+
async load(id) {
|
|
10943
|
+
if (this.pending.has(id)) return;
|
|
10944
|
+
const grammar = GRAMMARS.get(id);
|
|
10945
|
+
/* v8 ignore next -- every alias resolves to a grammar in the same table */
|
|
10946
|
+
if (grammar === void 0) return;
|
|
10947
|
+
this.pending.add(id);
|
|
10948
|
+
try {
|
|
10949
|
+
const module = await (this.options.import ?? ((load) => load()))(grammar);
|
|
10950
|
+
if (!await this.register(id, module)) return;
|
|
10951
|
+
} catch {
|
|
10952
|
+
this.loaded.delete(id);
|
|
10953
|
+
return;
|
|
10954
|
+
} finally {
|
|
10955
|
+
this.pending.delete(id);
|
|
10956
|
+
}
|
|
10957
|
+
this.options.changed();
|
|
10958
|
+
}
|
|
10959
|
+
/**
|
|
10960
|
+
* Put one grammar on the core, building the core and its theme first.
|
|
10961
|
+
* @param id - the grammar's id.
|
|
10962
|
+
* @param module - the grammar module.
|
|
10963
|
+
* @returns whether the core now resolves that id.
|
|
10964
|
+
*/
|
|
10965
|
+
async register(id, module) {
|
|
10966
|
+
const core = await this.ensureCore();
|
|
10967
|
+
await core.loadLanguage(grammarOf(module));
|
|
10968
|
+
if (!core.getLoadedLanguages().includes(id)) return false;
|
|
10969
|
+
this.loaded.add(id);
|
|
10970
|
+
core.codeToTokens("", {
|
|
10971
|
+
lang: id,
|
|
10972
|
+
theme: this.theme
|
|
10973
|
+
});
|
|
10974
|
+
return true;
|
|
10975
|
+
}
|
|
10976
|
+
/**
|
|
10977
|
+
* The core, built once however many languages ask for it at the same time.
|
|
10978
|
+
* @returns the core.
|
|
10979
|
+
*/
|
|
10980
|
+
async ensureCore() {
|
|
10981
|
+
const built = this.core;
|
|
10982
|
+
if (built !== void 0) return built;
|
|
10983
|
+
this.building ??= this.buildCore();
|
|
10984
|
+
return this.building;
|
|
10985
|
+
}
|
|
10986
|
+
/**
|
|
10987
|
+
* Build the core with the theme the terminal's background asks for.
|
|
10988
|
+
* @returns the core, which every later grammar registers on.
|
|
10989
|
+
*/
|
|
10990
|
+
async buildCore() {
|
|
10991
|
+
const run = this.options.import ?? ((load) => load());
|
|
10992
|
+
const [{ createHighlighterCoreSync }, { createJavaScriptRegexEngine }, theme] = await Promise.all([
|
|
10993
|
+
import("shiki/core"),
|
|
10994
|
+
import("shiki/engine/javascript"),
|
|
10995
|
+
run(THEMES[backgroundIsLight(this.options.background()) ? "light" : "dark"])
|
|
10996
|
+
]);
|
|
10997
|
+
/* v8 ignore next -- every bundled theme carries its own name */
|
|
10998
|
+
this.theme = theme.default.name ?? "";
|
|
10999
|
+
const core = createHighlighterCoreSync({
|
|
11000
|
+
themes: [theme.default],
|
|
11001
|
+
langs: [],
|
|
11002
|
+
engine: createJavaScriptRegexEngine({ forgiving: true })
|
|
11003
|
+
});
|
|
11004
|
+
this.core = core;
|
|
11005
|
+
return core;
|
|
11006
|
+
}
|
|
11007
|
+
};
|
|
11008
|
+
//#endregion
|
|
11009
|
+
//#region lib/types/screen.js
|
|
11010
|
+
/**
|
|
11011
|
+
* The main screen this application renders through, and the repaint rule the
|
|
11012
|
+
* renderer imposes on everything drawn above the terminal's viewport.
|
|
11013
|
+
*
|
|
11014
|
+
* pi-tui's `TuiMainScreen` draws into the terminal's own scrollback. It
|
|
11015
|
+
* repaints differentially only the lines whose index is at or after
|
|
11016
|
+
* `previousViewportTop`, the top of the last written frame's viewport, and
|
|
11017
|
+
* falls back to a full redraw that writes `ESC[2J ESC[H ESC[3J` - which
|
|
11018
|
+
* discards the terminal's scrollback - as soon as a line above it changed.
|
|
11019
|
+
* `previousViewportTop` is a high-water mark: every frame raises it towards
|
|
11020
|
+
* `frameLines - terminal.rows` and a shorter frame never lowers it again, so a
|
|
11021
|
+
* line that once left the window stays out of reach until the renderer redraws
|
|
11022
|
+
* in full and resets it.
|
|
11023
|
+
*
|
|
11024
|
+
* Anything that redraws lines a component already produced - the streaming
|
|
11025
|
+
* fade, a card fade, the focus gutter - therefore asks {@link repaintFloor} how
|
|
11026
|
+
* far into a block the renderer can still follow it, and
|
|
11027
|
+
* {@link GuardedMainScreen} gives the application the one moment where that
|
|
11028
|
+
* question can be answered: after a frame was built and before it is written.
|
|
11029
|
+
*
|
|
11030
|
+
* {@link GuardedMainScreen.suspend} is the other half of that rule: a
|
|
11031
|
+
* full-screen surface that takes the terminal holds the main screen off it
|
|
11032
|
+
* entirely rather than drawing over the conversation, so no line of the
|
|
11033
|
+
* conversation is rewritten while the surface is up and none of the surface's
|
|
11034
|
+
* own rows can reach the terminal's scrollback.
|
|
11035
|
+
*
|
|
11036
|
+
* The screen also keeps {@link PAGE_MARGIN_COLUMNS} blank columns on each
|
|
11037
|
+
* side of every frame: the tree lays out in the columns that remain and each
|
|
11038
|
+
* drawn line is moved right by that many spaces, so nothing the conversation
|
|
11039
|
+
* or the docked chrome draws touches either edge of the terminal.
|
|
11040
|
+
*
|
|
11041
|
+
* Every frame leaves here without its key marks: the screen takes them out
|
|
11042
|
+
* of the finished frame, overlays composited, and keeps where each marked
|
|
11043
|
+
* key was drawn ({@link GuardedMainScreen.keyFrame}).
|
|
11044
|
+
* @module @deepseek-ai/dsh-tui-app/screen
|
|
11045
|
+
*/
|
|
11046
|
+
/**
|
|
11047
|
+
* How many times one frame is offered to the guard before it is written. Two
|
|
11048
|
+
* passes let the guard answer for the geometry its own first pass produced -
|
|
11049
|
+
* a gutter rewraps the block it marks - and end on a frame the application's
|
|
11050
|
+
* own record of what is marked describes.
|
|
11051
|
+
*/
|
|
11052
|
+
const SETTLE_PASSES = 2;
|
|
11053
|
+
/** Columns a frame keeps for the tree before the margins are worth their cost. */
|
|
11054
|
+
const MIN_CONTENT_COLUMNS = 8;
|
|
11055
|
+
/**
|
|
11056
|
+
* The columns the tree lays out in at a terminal width, which is what every
|
|
11057
|
+
* surface drawn into the main screen is measured against. A terminal too
|
|
11058
|
+
* narrow to hold {@link MIN_CONTENT_COLUMNS} beside the margins gives up the
|
|
11059
|
+
* margins rather than the text, and the frame then fills its width, because a
|
|
11060
|
+
* line wider than the terminal is a frame pi-tui refuses.
|
|
11061
|
+
* @param width - the terminal's total width.
|
|
11062
|
+
* @returns the width inside the page margins, or the whole width on a terminal
|
|
11063
|
+
* too narrow for them.
|
|
11064
|
+
*/
|
|
11065
|
+
function pageContentWidth(width) {
|
|
11066
|
+
const inside = width - 2;
|
|
11067
|
+
return inside < MIN_CONTENT_COLUMNS ? Math.max(1, width) : inside;
|
|
11068
|
+
}
|
|
11069
|
+
/** The left margin as the spaces each drawn line is moved right by. */
|
|
11070
|
+
const LEFT_MARGIN = " ".repeat(1);
|
|
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
|
+
/**
|
|
11083
|
+
* Move every drawn line right by the left margin. A line with nothing on it
|
|
11084
|
+
* keeps its own emptiness rather than gaining trailing spaces, so a frame adds
|
|
11085
|
+
* no whitespace to what the terminal's scrollback holds.
|
|
11086
|
+
* @param lines - the frame the tree built inside the margins.
|
|
11087
|
+
* @param margin - the spaces to move each line by; empty on a terminal that
|
|
11088
|
+
* gave its margins up.
|
|
11089
|
+
* @returns the frame as it is written.
|
|
11090
|
+
*/
|
|
11091
|
+
function indentFrame(lines, margin) {
|
|
11092
|
+
if (margin === "") return [...lines];
|
|
11093
|
+
return lines.map((line) => line === "" ? line : `${margin}${line}`);
|
|
11094
|
+
}
|
|
11095
|
+
/**
|
|
11096
|
+
* The first line of one block the renderer can still repaint.
|
|
11097
|
+
* @param start - index of the block's first line in the frame.
|
|
11098
|
+
* @param viewportTop - the frame's first repaintable line, as
|
|
11099
|
+
* {@link GuardedMainScreen} hands it to its guard.
|
|
11100
|
+
* @returns the block's own first repaintable line index, 0 while the whole
|
|
11101
|
+
* block lies inside the window.
|
|
11102
|
+
*/
|
|
11103
|
+
function repaintFloor(start, viewportTop) {
|
|
11104
|
+
return Math.max(0, viewportTop - start);
|
|
11105
|
+
}
|
|
11106
|
+
/**
|
|
11107
|
+
* The main screen that settles each frame between building it and writing it.
|
|
11108
|
+
*
|
|
11109
|
+
* The guard is handed the frame's first repaintable line: the higher of the
|
|
11110
|
+
* renderer's own `previousViewportTop` and the boundary the frame just built
|
|
11111
|
+
* imposes once it is written. The first term is what the renderer judges this
|
|
11112
|
+
* write against. The second keeps every decision one frame ahead of that
|
|
11113
|
+
* judgement, so what the guard changes today it can still change back
|
|
11114
|
+
* tomorrow. Settling before the write also means a fade reaches the terminal
|
|
11115
|
+
* already settled instead of changing in the next frame, by which time its
|
|
11116
|
+
* lines may sit above the window.
|
|
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
|
+
*
|
|
11124
|
+
* It can also be suspended, which stops every write to the terminal while
|
|
11125
|
+
* leaving the renderer's record of the main screen exactly as it was. The
|
|
11126
|
+
* terminal restores that same screen when the surface that took it gives it
|
|
11127
|
+
* back, so the first frame after {@link GuardedMainScreen.resume} writes only
|
|
11128
|
+
* what changed meanwhile.
|
|
11351
11129
|
*/
|
|
11352
|
-
var
|
|
11353
|
-
|
|
11354
|
-
/**
|
|
11355
|
-
|
|
11130
|
+
var GuardedMainScreen = class extends TuiMainScreen {
|
|
11131
|
+
guard;
|
|
11132
|
+
/** What draws instead while another surface holds the terminal; absent while this screen does. */
|
|
11133
|
+
onSuspendedRender;
|
|
11134
|
+
/** The keys the last frame drew, by frame line. */
|
|
11135
|
+
keys = EMPTY_KEY_FRAME;
|
|
11356
11136
|
/**
|
|
11357
|
-
*
|
|
11358
|
-
*
|
|
11359
|
-
* finished last would be the only one holding a grammar.
|
|
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.
|
|
11360
11139
|
*/
|
|
11361
|
-
|
|
11362
|
-
/** The theme's own name, which `codeToTokens` resolves it by. */
|
|
11363
|
-
theme = "";
|
|
11364
|
-
/** Grammar ids already registered on the core. */
|
|
11365
|
-
loaded = /* @__PURE__ */ new Set();
|
|
11366
|
-
/** Grammar ids whose import is in flight, so each is asked for once. */
|
|
11367
|
-
pending = /* @__PURE__ */ new Set();
|
|
11140
|
+
settledAboveViewport = false;
|
|
11368
11141
|
/**
|
|
11369
|
-
* @param
|
|
11142
|
+
* @param terminal - the terminal the tree renders into.
|
|
11143
|
+
* @param showHardwareCursor - whether the terminal's own cursor is the caret.
|
|
11144
|
+
* @param guard - given the frame's first repaintable line, the width it was
|
|
11145
|
+
* built at, and how many lines it has, applies what that geometry decides
|
|
11146
|
+
* and reports whether it changed any line; run at most
|
|
11147
|
+
* {@link SETTLE_PASSES} times per frame, each `true` on a frame that is
|
|
11148
|
+
* built again. The frame's own length is what places an overlay, which
|
|
11149
|
+
* pi-tui composites into its last `terminal.rows` lines.
|
|
11370
11150
|
*/
|
|
11371
|
-
constructor(
|
|
11372
|
-
|
|
11151
|
+
constructor(terminal, showHardwareCursor, guard) {
|
|
11152
|
+
super(terminal, showHardwareCursor);
|
|
11153
|
+
this.guard = guard;
|
|
11373
11154
|
}
|
|
11374
11155
|
/**
|
|
11375
|
-
*
|
|
11376
|
-
*
|
|
11377
|
-
*
|
|
11378
|
-
*
|
|
11379
|
-
*
|
|
11380
|
-
*
|
|
11381
|
-
*
|
|
11156
|
+
* Stop writing to the terminal, and answer every render request with
|
|
11157
|
+
* `onRender` instead.
|
|
11158
|
+
*
|
|
11159
|
+
* Nothing about the renderer's record of the main screen changes, so the
|
|
11160
|
+
* frame it will judge its next write against stays the frame the terminal
|
|
11161
|
+
* still holds behind the surface that took over.
|
|
11162
|
+
* @param onRender - called wherever a frame would have been written, so the
|
|
11163
|
+
* surface that owns the terminal draws on the application's existing render
|
|
11164
|
+
* requests rather than on a clock of its own.
|
|
11382
11165
|
*/
|
|
11383
|
-
|
|
11384
|
-
|
|
11385
|
-
|
|
11386
|
-
|
|
11387
|
-
|
|
11388
|
-
|
|
11389
|
-
|
|
11390
|
-
|
|
11391
|
-
const core = this.core;
|
|
11392
|
-
/* v8 ignore next -- a loaded grammar means the core is built */
|
|
11393
|
-
if (core === void 0) return void 0;
|
|
11394
|
-
try {
|
|
11395
|
-
const { tokens } = core.codeToTokens(code, {
|
|
11396
|
-
lang: resolved,
|
|
11397
|
-
theme: this.theme
|
|
11398
|
-
});
|
|
11399
|
-
return tokens.map((line) => line.map((token) => this.paint(token)).join("") + RESET_FOREGROUND);
|
|
11400
|
-
} catch {
|
|
11401
|
-
this.loaded.delete(resolved);
|
|
11402
|
-
return;
|
|
11403
|
-
}
|
|
11166
|
+
suspend(onRender) {
|
|
11167
|
+
this.onSuspendedRender = onRender;
|
|
11168
|
+
}
|
|
11169
|
+
/** Write to the terminal again, and draw whatever changed while suspended. */
|
|
11170
|
+
resume() {
|
|
11171
|
+
if (this.onSuspendedRender === void 0) return;
|
|
11172
|
+
this.onSuspendedRender = void 0;
|
|
11173
|
+
this.requestRender();
|
|
11404
11174
|
}
|
|
11405
11175
|
/**
|
|
11406
|
-
*
|
|
11407
|
-
* @param
|
|
11408
|
-
*
|
|
11176
|
+
* Request a frame, or draw the surface that suspended this screen.
|
|
11177
|
+
* @param force - redraw from scratch; ignored while suspended, where
|
|
11178
|
+
* discarding the record would lose the screen the terminal is holding.
|
|
11409
11179
|
*/
|
|
11410
|
-
|
|
11411
|
-
const
|
|
11412
|
-
|
|
11413
|
-
|
|
11414
|
-
|
|
11415
|
-
|
|
11416
|
-
|
|
11417
|
-
const closeItalic = italic === "" ? "" : RESET_ITALIC;
|
|
11418
|
-
return `${color}${bold}${italic}${token.content}${closeItalic}${closeBold}`;
|
|
11180
|
+
requestRender(force = false) {
|
|
11181
|
+
const suspended = this.onSuspendedRender;
|
|
11182
|
+
if (suspended === void 0) {
|
|
11183
|
+
super.requestRender(force);
|
|
11184
|
+
return;
|
|
11185
|
+
}
|
|
11186
|
+
suspended();
|
|
11419
11187
|
}
|
|
11420
11188
|
/**
|
|
11421
|
-
*
|
|
11422
|
-
* @param
|
|
11189
|
+
* Write a frame now, or draw the suspending surface now.
|
|
11190
|
+
* @param force - redraw from scratch; ignored while suspended, as in
|
|
11191
|
+
* {@link GuardedMainScreen.requestRender}.
|
|
11423
11192
|
*/
|
|
11424
|
-
|
|
11425
|
-
|
|
11426
|
-
|
|
11427
|
-
|
|
11428
|
-
if (grammar === void 0) return;
|
|
11429
|
-
this.pending.add(id);
|
|
11430
|
-
try {
|
|
11431
|
-
const module = await (this.options.import ?? ((load) => load()))(grammar);
|
|
11432
|
-
if (!await this.register(id, module)) return;
|
|
11433
|
-
} catch {
|
|
11434
|
-
this.loaded.delete(id);
|
|
11193
|
+
renderNow(force = false) {
|
|
11194
|
+
const suspended = this.onSuspendedRender;
|
|
11195
|
+
if (suspended === void 0) {
|
|
11196
|
+
super.renderNow(force);
|
|
11435
11197
|
return;
|
|
11436
|
-
} finally {
|
|
11437
|
-
this.pending.delete(id);
|
|
11438
11198
|
}
|
|
11439
|
-
|
|
11199
|
+
suspended();
|
|
11440
11200
|
}
|
|
11441
11201
|
/**
|
|
11442
|
-
*
|
|
11443
|
-
*
|
|
11444
|
-
*
|
|
11445
|
-
* @returns
|
|
11202
|
+
* Where the last written frame drew its keys, and the frame line the
|
|
11203
|
+
* terminal's cursor was left on, which is what a cursor report places the
|
|
11204
|
+
* frame by.
|
|
11205
|
+
* @returns the snapshot; later frames never change it.
|
|
11446
11206
|
*/
|
|
11447
|
-
|
|
11448
|
-
|
|
11449
|
-
|
|
11450
|
-
|
|
11451
|
-
|
|
11452
|
-
core.codeToTokens("", {
|
|
11453
|
-
lang: id,
|
|
11454
|
-
theme: this.theme
|
|
11455
|
-
});
|
|
11456
|
-
return true;
|
|
11207
|
+
keyFrame() {
|
|
11208
|
+
return {
|
|
11209
|
+
keys: this.keys,
|
|
11210
|
+
cursorLine: this.captureRenderState().hardwareCursorRow
|
|
11211
|
+
};
|
|
11457
11212
|
}
|
|
11458
11213
|
/**
|
|
11459
|
-
*
|
|
11460
|
-
*
|
|
11214
|
+
* Take every key mark out of the finished frame before pi-tui resets and
|
|
11215
|
+
* writes its lines, keeping where each key was drawn. The renderer calls
|
|
11216
|
+
* this once per frame, after the overlays are composited into it and before
|
|
11217
|
+
* it is compared with what the terminal holds, so the kept cells are the
|
|
11218
|
+
* written frame's own.
|
|
11219
|
+
* @param lines - the finished frame.
|
|
11220
|
+
* @returns the frame with pi-tui's line resets applied and no key mark left.
|
|
11461
11221
|
*/
|
|
11462
|
-
|
|
11463
|
-
const
|
|
11464
|
-
|
|
11465
|
-
|
|
11466
|
-
return this.building;
|
|
11222
|
+
applyLineResets(lines) {
|
|
11223
|
+
const marked = takeKeyFrame(lines);
|
|
11224
|
+
this.keys = marked.keys;
|
|
11225
|
+
return super.applyLineResets(marked.lines);
|
|
11467
11226
|
}
|
|
11468
11227
|
/**
|
|
11469
|
-
*
|
|
11470
|
-
*
|
|
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.
|
|
11471
11231
|
*/
|
|
11472
|
-
|
|
11473
|
-
|
|
11474
|
-
const
|
|
11475
|
-
|
|
11476
|
-
|
|
11477
|
-
|
|
11478
|
-
|
|
11479
|
-
|
|
11480
|
-
|
|
11481
|
-
|
|
11482
|
-
|
|
11483
|
-
|
|
11484
|
-
|
|
11485
|
-
|
|
11486
|
-
|
|
11487
|
-
|
|
11232
|
+
doRender() {
|
|
11233
|
+
if (this.onSuspendedRender !== void 0) return;
|
|
11234
|
+
const fullRedraws = this.fullRedraws;
|
|
11235
|
+
super.doRender();
|
|
11236
|
+
if (this.fullRedraws !== fullRedraws && this.settledAboveViewport) this.requestRender();
|
|
11237
|
+
}
|
|
11238
|
+
/**
|
|
11239
|
+
* Build the frame inside the page margins, let the guard settle what its
|
|
11240
|
+
* geometry decides, and build it again for every pass that changed a line.
|
|
11241
|
+
*
|
|
11242
|
+
* The guard is handed the width the tree was laid out in, not the terminal's
|
|
11243
|
+
* own, so the line counts it walks are the ones this frame has.
|
|
11244
|
+
* @param width - the terminal's total width.
|
|
11245
|
+
* @returns the frame to write, indented by the left margin and settled
|
|
11246
|
+
* against its own geometry.
|
|
11247
|
+
*/
|
|
11248
|
+
render(width) {
|
|
11249
|
+
const content = pageContentWidth(width);
|
|
11250
|
+
const margin = pageMargin(width);
|
|
11251
|
+
const previousTop = this.captureRenderState().previousViewportTop;
|
|
11252
|
+
let lines = indentFrame(super.render(content), margin);
|
|
11253
|
+
for (let pass = 0; pass < SETTLE_PASSES; pass += 1) {
|
|
11254
|
+
if (!this.guard(Math.max(previousTop, lines.length - this.terminal.rows), content, lines.length)) break;
|
|
11255
|
+
lines = indentFrame(super.render(content), margin);
|
|
11256
|
+
}
|
|
11257
|
+
this.settledAboveViewport = previousTop > Math.max(0, lines.length - this.terminal.rows);
|
|
11258
|
+
return lines;
|
|
11488
11259
|
}
|
|
11489
11260
|
};
|
|
11490
11261
|
//#endregion
|
|
@@ -12665,13 +12436,6 @@ var TuiApp = class {
|
|
|
12665
12436
|
motions = new FadeRegistry();
|
|
12666
12437
|
/** The transient line on screen right now, with the clock that takes it down. */
|
|
12667
12438
|
toast;
|
|
12668
|
-
/**
|
|
12669
|
-
* The bar naming the newest prompt while it floats over the first row the
|
|
12670
|
-
* terminal shows, with the prompt block it names and the viewport row it
|
|
12671
|
-
* was shown on; absent while no bar is drawn, because pi-tui pads every
|
|
12672
|
-
* frame to the terminal's height while any overlay is mounted, drawn or not.
|
|
12673
|
-
*/
|
|
12674
|
-
pinned;
|
|
12675
12439
|
/** The chrome motion running right now, and how much of the focused surface it lifts. */
|
|
12676
12440
|
chrome;
|
|
12677
12441
|
/** The lift the subagent panel's text was last built with, which only a repaint changes. */
|
|
@@ -12703,8 +12467,8 @@ var TuiApp = class {
|
|
|
12703
12467
|
/**
|
|
12704
12468
|
* How many of the viewport's own first lines the renderer can no longer
|
|
12705
12469
|
* repaint, from the last frame the guard settled. The terminal's first row
|
|
12706
|
-
* shows the line after them
|
|
12707
|
-
* stays clear of them
|
|
12470
|
+
* shows the line after them, and the transient line floats only while its
|
|
12471
|
+
* box stays clear of them.
|
|
12708
12472
|
*/
|
|
12709
12473
|
viewportFloor = 0;
|
|
12710
12474
|
/** Set while {@link TuiApp.bind} replays a session's history, which draws its cards settled. */
|
|
@@ -12975,10 +12739,6 @@ var TuiApp = class {
|
|
|
12975
12739
|
this.modals.withdrawActive();
|
|
12976
12740
|
this.dropReader();
|
|
12977
12741
|
this.hideToast();
|
|
12978
|
-
if (this.pinned !== void 0) {
|
|
12979
|
-
this.pinPrompt(void 0);
|
|
12980
|
-
this.tui.renderNow();
|
|
12981
|
-
}
|
|
12982
12742
|
this.deps.terminal.write(SET_TERMINAL_DEFAULT_CURSOR);
|
|
12983
12743
|
this.tui.stop();
|
|
12984
12744
|
this.deps.releaseInput();
|
|
@@ -13365,7 +13125,7 @@ var TuiApp = class {
|
|
|
13365
13125
|
this.syncBoardSpinners(this.deps.reducedMotion ? [] : spinningTodos(view));
|
|
13366
13126
|
const now = this.deps.now();
|
|
13367
13127
|
const spinners = /* @__PURE__ */ new Map();
|
|
13368
|
-
for (const [content, phase] of this.boardSpinners) spinners.set(content, spinnerFrame(
|
|
13128
|
+
for (const [content, phase] of this.boardSpinners) spinners.set(content, spinnerFrame(TOOL_SPINNER, now, this.deps.spinnerMs, phase));
|
|
13369
13129
|
const text = renderActivityBoard(view, {
|
|
13370
13130
|
palette: this.deps.palette,
|
|
13371
13131
|
todoFades: this.activityTodoFades,
|
|
@@ -13384,7 +13144,7 @@ var TuiApp = class {
|
|
|
13384
13144
|
}
|
|
13385
13145
|
/**
|
|
13386
13146
|
* Keep the phase of each in-progress todo row that still spins, drop the
|
|
13387
|
-
* rest, and stagger a row that starts spinning against every other
|
|
13147
|
+
* rest, and stagger a row that starts spinning against every other tool
|
|
13388
13148
|
* indicator on screen.
|
|
13389
13149
|
* @param contents - the content of each in-progress row the board draws now.
|
|
13390
13150
|
*/
|
|
@@ -13392,7 +13152,7 @@ var TuiApp = class {
|
|
|
13392
13152
|
for (const content of this.boardSpinners.keys()) if (!contents.includes(content)) this.boardSpinners.delete(content);
|
|
13393
13153
|
for (const content of contents) {
|
|
13394
13154
|
if (this.boardSpinners.has(content)) continue;
|
|
13395
|
-
this.boardSpinners.set(content, staggerPhase(
|
|
13155
|
+
this.boardSpinners.set(content, staggerPhase(this.spinningPhases()));
|
|
13396
13156
|
}
|
|
13397
13157
|
}
|
|
13398
13158
|
/**
|
|
@@ -16032,32 +15792,28 @@ var TuiApp = class {
|
|
|
16032
15792
|
this.trackReveal(block);
|
|
16033
15793
|
}
|
|
16034
15794
|
/**
|
|
16035
|
-
* Spin a new card's glyph in
|
|
16036
|
-
*
|
|
16037
|
-
*
|
|
16038
|
-
*
|
|
16039
|
-
* animation. A card drawn from a replayed log, and every card under
|
|
16040
|
-
* reduced motion, draws the static glyph.
|
|
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.
|
|
16041
15799
|
* @param block - the card that was just mounted.
|
|
16042
15800
|
*/
|
|
16043
15801
|
spinBlock(block) {
|
|
16044
15802
|
if (this.replaying || this.deps.reducedMotion) return;
|
|
16045
|
-
const
|
|
16046
|
-
|
|
16047
|
-
block.setSpinner(() => spinnerFrame(TOOL_SPINNERS[toolFamily(block.name)], this.deps.now(), this.deps.spinnerMs, phase));
|
|
15803
|
+
const phase = staggerPhase(this.spinningPhases());
|
|
15804
|
+
block.setSpinner(() => spinnerFrame(TOOL_SPINNER, this.deps.now(), this.deps.spinnerMs, phase));
|
|
16048
15805
|
this.spinners.set(block, phase);
|
|
16049
15806
|
this.updateSpinTicker();
|
|
16050
15807
|
}
|
|
16051
15808
|
/**
|
|
16052
|
-
* The phases of the
|
|
16053
|
-
*
|
|
16054
|
-
* @
|
|
16055
|
-
* @returns one phase per spinning indicator of that family.
|
|
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.
|
|
16056
15812
|
*/
|
|
16057
|
-
spinningPhases(
|
|
15813
|
+
spinningPhases() {
|
|
16058
15814
|
const phases = [];
|
|
16059
|
-
for (const [block, phase] of this.spinners) if (block.spinning()
|
|
16060
|
-
|
|
15815
|
+
for (const [block, phase] of this.spinners) if (block.spinning()) phases.push(phase);
|
|
15816
|
+
phases.push(...this.boardSpinners.values());
|
|
16061
15817
|
return phases;
|
|
16062
15818
|
}
|
|
16063
15819
|
/**
|
|
@@ -16228,19 +15984,14 @@ var TuiApp = class {
|
|
|
16228
15984
|
* running fade, which is told each block's own first repaintable line, and
|
|
16229
15985
|
* the focus gutter, which a block gains or loses only while its first line
|
|
16230
15986
|
* lies inside the window. A focused block above the window simply stays
|
|
16231
|
-
* unmarked, and the inspector reports that instead.
|
|
16232
|
-
* the bar naming the newest prompt ({@link TuiApp.pinPrompt}) on the first
|
|
16233
|
-
* row the terminal shows, which after the frame shrank lies under the
|
|
16234
|
-
* lines the renderer can no longer repaint: pi-tui composites overlays into
|
|
16235
|
-
* a frame after building it, so a bar shown, moved, or taken down here is
|
|
16236
|
-
* drawn that way in this same frame.
|
|
15987
|
+
* unmarked, and the inspector reports that instead.
|
|
16237
15988
|
* @param viewportTop - the frame's first repaintable line.
|
|
16238
15989
|
* @param width - the width it was built at.
|
|
16239
15990
|
* @param frameLines - how many lines the frame has, which is what places
|
|
16240
|
-
* the transient line
|
|
16241
|
-
*
|
|
15991
|
+
* the transient line: pi-tui composites an overlay into the frame's last
|
|
15992
|
+
* `rows` lines.
|
|
16242
15993
|
* @returns whether anything changed a line, so the frame is built again
|
|
16243
|
-
* before it is written
|
|
15994
|
+
* before it is written.
|
|
16244
15995
|
*/
|
|
16245
15996
|
settleFrame(viewportTop, width, frameLines) {
|
|
16246
15997
|
const rows = this.deps.terminal.rows;
|
|
@@ -16253,34 +16004,16 @@ var TuiApp = class {
|
|
|
16253
16004
|
level: this.markLift()
|
|
16254
16005
|
} : void 0;
|
|
16255
16006
|
const fades = this.fadesMoving() || this.spinners.size > 0;
|
|
16256
|
-
const prompt = this.stopped ? void 0 : lastPrompt(navigableBlocks(this.chat.children));
|
|
16257
16007
|
let start = this.header.render(width).length;
|
|
16258
16008
|
let wantedStart;
|
|
16259
|
-
let promptEnd;
|
|
16260
16009
|
let changed = false;
|
|
16261
16010
|
for (const child of this.chat.children) {
|
|
16262
16011
|
if (isSectionSource(child) && child === wanted?.block) wantedStart = start;
|
|
16263
|
-
const isPrompt = isSectionSource(child) && child === prompt?.block;
|
|
16264
16012
|
if (fades && (child instanceof AssistantBlock || child instanceof ToolBlock)) {
|
|
16265
16013
|
if (child.setRepaintFloor(repaintFloor(start, viewportTop))) changed = true;
|
|
16266
16014
|
}
|
|
16267
16015
|
start += child.render(width).length;
|
|
16268
|
-
if (isPrompt) promptEnd = start;
|
|
16269
|
-
}
|
|
16270
|
-
let pin;
|
|
16271
|
-
if (prompt !== void 0 && promptEnd !== void 0) {
|
|
16272
|
-
const row = pinnedPromptPlacement({
|
|
16273
|
-
promptEnd,
|
|
16274
|
-
transcriptEnd: start,
|
|
16275
|
-
viewportStart,
|
|
16276
|
-
viewportFloor: this.viewportFloor
|
|
16277
|
-
});
|
|
16278
|
-
if (row !== void 0) pin = {
|
|
16279
|
-
prompt,
|
|
16280
|
-
row
|
|
16281
|
-
};
|
|
16282
16016
|
}
|
|
16283
|
-
this.pinPrompt(pin);
|
|
16284
16017
|
const target = wantedStart !== void 0 && repaintFloor(wantedStart, viewportTop) === 0 ? wanted : void 0;
|
|
16285
16018
|
const current = this.highlighted;
|
|
16286
16019
|
if (current?.block === target?.block && current?.part === target?.part && current?.level === target?.level) return changed;
|
|
@@ -16290,26 +16023,6 @@ var TuiApp = class {
|
|
|
16290
16023
|
return true;
|
|
16291
16024
|
}
|
|
16292
16025
|
/**
|
|
16293
|
-
* Float the bar naming one prompt over one viewport row, or take the bar
|
|
16294
|
-
* down. The overlay is mounted only while a bar is drawn, and an overlay's
|
|
16295
|
-
* row is fixed when it is shown, so a different prompt or a different row
|
|
16296
|
-
* mounts the bar again.
|
|
16297
|
-
* @param pin - the prompt to name and the row to draw it on, or undefined
|
|
16298
|
-
* to draw no bar.
|
|
16299
|
-
*/
|
|
16300
|
-
pinPrompt(pin) {
|
|
16301
|
-
if (this.pinned?.block === pin?.prompt.block && this.pinned?.row === pin?.row) return;
|
|
16302
|
-
this.pinned?.handle.hide();
|
|
16303
|
-
this.pinned = void 0;
|
|
16304
|
-
if (pin === void 0) return;
|
|
16305
|
-
const pane = new PinnedPromptPane(this.deps.palette, pin.prompt.part.rows);
|
|
16306
|
-
this.pinned = {
|
|
16307
|
-
block: pin.prompt.block,
|
|
16308
|
-
row: pin.row,
|
|
16309
|
-
handle: this.tui.showOverlay(pane, pinnedPromptOverlay(pin.row))
|
|
16310
|
-
};
|
|
16311
|
-
}
|
|
16312
|
-
/**
|
|
16313
16026
|
* One fade period: every tracked fade drops what settled since the last one,
|
|
16314
16027
|
* the render request redraws the levels the clock moved, and the disarm
|
|
16315
16028
|
* check follows. Ages come from the clock, so this period repaints the
|