@songtonyli/dsh-cli 0.1.66 → 0.1.67
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/@babel/runtime/helpers/esm/interopRequireWildcard.js +16 -19
- package/node_modules/@babel/runtime/helpers/esm/toPrimitive.js +5 -5
- package/node_modules/@babel/runtime/helpers/interopRequireWildcard.js +16 -19
- package/node_modules/@babel/runtime/helpers/toPrimitive.js +5 -5
- package/node_modules/@babel/runtime/package.json +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-client-ui-slots/package.json +2 -2
- package/node_modules/@deepseek-ai/dsh-tui-app/README.i18n.yaml +6 -6
- package/node_modules/@deepseek-ai/dsh-tui-app/README.md +3 -2
- package/node_modules/@deepseek-ai/dsh-tui-app/README.zh.md +3 -2
- package/node_modules/@deepseek-ai/dsh-tui-app/lib/index.js +955 -567
- package/package.json +2 -2
|
@@ -4848,12 +4848,510 @@ function fadingInSpans(fade) {
|
|
|
4848
4848
|
function floatingOutSpans(fade) {
|
|
4849
4849
|
return fade.spans().filter((span) => span.age < fade.steps);
|
|
4850
4850
|
}
|
|
4851
|
+
/**
|
|
4852
|
+
* The activity line's animation for each working status. Every glyph is
|
|
4853
|
+
* braille and no card or todo row draws braille. A presentation choice of
|
|
4854
|
+
* this terminal surface, not a deployment setting.
|
|
4855
|
+
*/
|
|
4856
|
+
const ACTIVITY_SPINNERS = {
|
|
4857
|
+
/** Model reasoning, and any label with no status of its own: three dots circling the cell. */
|
|
4858
|
+
thinking: [
|
|
4859
|
+
"⠙",
|
|
4860
|
+
"⠸",
|
|
4861
|
+
"⢰",
|
|
4862
|
+
"⣠",
|
|
4863
|
+
"⣄",
|
|
4864
|
+
"⡆",
|
|
4865
|
+
"⠇",
|
|
4866
|
+
"⠋"
|
|
4867
|
+
],
|
|
4868
|
+
/** Visible reply text streaming in: lines filling the cell, then streaming up out of it. */
|
|
4869
|
+
writing: [
|
|
4870
|
+
"⠉",
|
|
4871
|
+
"⠛",
|
|
4872
|
+
"⠿",
|
|
4873
|
+
"⣿",
|
|
4874
|
+
"⣶",
|
|
4875
|
+
"⣤",
|
|
4876
|
+
"⣀",
|
|
4877
|
+
"⣉"
|
|
4878
|
+
],
|
|
4879
|
+
/** A tool call streamed or running, whichever tool it names: one dot orbiting the cell. */
|
|
4880
|
+
calling: [
|
|
4881
|
+
"⠁",
|
|
4882
|
+
"⠈",
|
|
4883
|
+
"⠐",
|
|
4884
|
+
"⠠",
|
|
4885
|
+
"⢀",
|
|
4886
|
+
"⡀",
|
|
4887
|
+
"⠄",
|
|
4888
|
+
"⠂"
|
|
4889
|
+
],
|
|
4890
|
+
/** A scheduled model-request retry: a bar sliding down the cell and back. */
|
|
4891
|
+
retrying: [
|
|
4892
|
+
"⠉",
|
|
4893
|
+
"⠛",
|
|
4894
|
+
"⠶",
|
|
4895
|
+
"⣤",
|
|
4896
|
+
"⣀",
|
|
4897
|
+
"⣤",
|
|
4898
|
+
"⠶",
|
|
4899
|
+
"⠛"
|
|
4900
|
+
],
|
|
4901
|
+
/** Condensing older history into a summary: a full cell settling and refilling. */
|
|
4902
|
+
compacting: [
|
|
4903
|
+
"⣿",
|
|
4904
|
+
"⣷",
|
|
4905
|
+
"⣶",
|
|
4906
|
+
"⣦",
|
|
4907
|
+
"⣤",
|
|
4908
|
+
"⣦",
|
|
4909
|
+
"⣶",
|
|
4910
|
+
"⣷"
|
|
4911
|
+
]
|
|
4912
|
+
};
|
|
4913
|
+
/**
|
|
4914
|
+
* The animation a running tool card draws, by tool family; a folded subagent
|
|
4915
|
+
* row draws `subagent`, and the activity board's in-progress todo rows draw
|
|
4916
|
+
* `todo`. Each cycle mixes flowers, blooms, and stars. No frame is braille,
|
|
4917
|
+
* no two families share a glyph, and the eight frames of one family all
|
|
4918
|
+
* differ, so two indicators of that family at different phases never draw the
|
|
4919
|
+
* same glyph at the same instant. A presentation choice of this terminal
|
|
4920
|
+
* surface, not a deployment setting.
|
|
4921
|
+
*/
|
|
4922
|
+
const TOOL_SPINNERS = {
|
|
4923
|
+
/** Command execution: four-pointed stars, teardrop blooms, and florettes. */
|
|
4924
|
+
shell: [
|
|
4925
|
+
"✧",
|
|
4926
|
+
"✢",
|
|
4927
|
+
"✽",
|
|
4928
|
+
"✿",
|
|
4929
|
+
"❋",
|
|
4930
|
+
"✸",
|
|
4931
|
+
"❀",
|
|
4932
|
+
"✹"
|
|
4933
|
+
],
|
|
4934
|
+
/** File mutation: florettes between outlined stars and an open bloom. */
|
|
4935
|
+
edit: [
|
|
4936
|
+
"✩",
|
|
4937
|
+
"✤",
|
|
4938
|
+
"✾",
|
|
4939
|
+
"❁",
|
|
4940
|
+
"✭",
|
|
4941
|
+
"✮",
|
|
4942
|
+
"❂",
|
|
4943
|
+
"✲"
|
|
4944
|
+
],
|
|
4945
|
+
/** Reading and searching: flowers and an open bloom among stars. */
|
|
4946
|
+
search: [
|
|
4947
|
+
"⋆",
|
|
4948
|
+
"✱",
|
|
4949
|
+
"✵",
|
|
4950
|
+
"⚘",
|
|
4951
|
+
"❃",
|
|
4952
|
+
"✶",
|
|
4953
|
+
"⁕",
|
|
4954
|
+
"✷"
|
|
4955
|
+
],
|
|
4956
|
+
/** Delegation, a folded subagent row included: floral hearts, pinwheel blooms, and stars. */
|
|
4957
|
+
subagent: [
|
|
4958
|
+
"✦",
|
|
4959
|
+
"✣",
|
|
4960
|
+
"❊",
|
|
4961
|
+
"❦",
|
|
4962
|
+
"❉",
|
|
4963
|
+
"✪",
|
|
4964
|
+
"✫",
|
|
4965
|
+
"❧"
|
|
4966
|
+
],
|
|
4967
|
+
/** Planning and scheduling, and an in-progress todo row: a florette, teardrop blooms, and stars. */
|
|
4968
|
+
todo: [
|
|
4969
|
+
"☆",
|
|
4970
|
+
"✥",
|
|
4971
|
+
"✼",
|
|
4972
|
+
"❅",
|
|
4973
|
+
"✻",
|
|
4974
|
+
"✬",
|
|
4975
|
+
"★",
|
|
4976
|
+
"✰"
|
|
4977
|
+
],
|
|
4978
|
+
/** A tool with no family of its own: a sparkle and a florette among stars. */
|
|
4979
|
+
other: [
|
|
4980
|
+
"∗",
|
|
4981
|
+
"❈",
|
|
4982
|
+
"⁎",
|
|
4983
|
+
"❆",
|
|
4984
|
+
"⚝",
|
|
4985
|
+
"✺",
|
|
4986
|
+
"⚹",
|
|
4987
|
+
"✯"
|
|
4988
|
+
]
|
|
4989
|
+
};
|
|
4990
|
+
/**
|
|
4991
|
+
* The animation a running workflow run's header draws in place of its static
|
|
4992
|
+
* `◇`: a diamond filling, blooming, and emptying again. Its running members
|
|
4993
|
+
* spin in the `subagent` family of {@link TOOL_SPINNERS}, each a phase ahead
|
|
4994
|
+
* of the member before it. A presentation choice of this terminal surface,
|
|
4995
|
+
* not a deployment setting.
|
|
4996
|
+
*/
|
|
4997
|
+
const WORKFLOW_SPINNER = [
|
|
4998
|
+
"◇",
|
|
4999
|
+
"◈",
|
|
5000
|
+
"◆",
|
|
5001
|
+
"❖",
|
|
5002
|
+
"◆",
|
|
5003
|
+
"◈",
|
|
5004
|
+
"◇",
|
|
5005
|
+
"◊"
|
|
5006
|
+
];
|
|
5007
|
+
/** Blank steps between two shimmer passes, so the sweep pauses past the word's end. */
|
|
5008
|
+
const SHIMMER_GAP = 6;
|
|
5009
|
+
/** Tool names that execute commands. */
|
|
5010
|
+
const SHELL_TOOLS = new Set([
|
|
5011
|
+
"bash",
|
|
5012
|
+
"pwsh",
|
|
5013
|
+
"run_code"
|
|
5014
|
+
]);
|
|
5015
|
+
/** Tool names that mutate files. */
|
|
5016
|
+
const EDIT_TOOLS = new Set([
|
|
5017
|
+
"edit",
|
|
5018
|
+
"write",
|
|
5019
|
+
"str_replace_editor"
|
|
5020
|
+
]);
|
|
5021
|
+
/** Tool names that read or search, beyond the `TOOL_PREFIXES` below. */
|
|
5022
|
+
const SEARCH_TOOLS = new Set([
|
|
5023
|
+
"read",
|
|
5024
|
+
"read_image",
|
|
5025
|
+
"glob",
|
|
5026
|
+
"grep",
|
|
5027
|
+
"lsp",
|
|
5028
|
+
"skill",
|
|
5029
|
+
"web_fetch",
|
|
5030
|
+
"web_search",
|
|
5031
|
+
"load_workspace_dependencies",
|
|
5032
|
+
"list_subagent_models"
|
|
5033
|
+
]);
|
|
5034
|
+
/** Tool names that delegate or steer a child agent, beyond `subagent` itself. */
|
|
5035
|
+
const SUBAGENT_TOOLS = new Set([
|
|
5036
|
+
"send_message",
|
|
5037
|
+
"interrupt_agent",
|
|
5038
|
+
"list_agents",
|
|
5039
|
+
"ralph",
|
|
5040
|
+
"workflow",
|
|
5041
|
+
"spawn_teammate",
|
|
5042
|
+
"wait_agent"
|
|
5043
|
+
]);
|
|
5044
|
+
/** Tool names that plan or schedule work. */
|
|
5045
|
+
const TODO_TOOLS = new Set([
|
|
5046
|
+
"todo_write",
|
|
5047
|
+
"create_goal",
|
|
5048
|
+
"get_goal",
|
|
5049
|
+
"update_goal"
|
|
5050
|
+
]);
|
|
5051
|
+
/**
|
|
5052
|
+
* Tool-name prefixes per family, checked after the exact sets above. An MCP
|
|
5053
|
+
* or custom tool that keeps its family's prefix inherits the animation.
|
|
5054
|
+
*/
|
|
5055
|
+
const TOOL_PREFIXES = [
|
|
5056
|
+
["terminal_", "shell"],
|
|
5057
|
+
["session_", "search"],
|
|
5058
|
+
["cordis_inspect_", "search"],
|
|
5059
|
+
["list_mcp_", "search"],
|
|
5060
|
+
["read_mcp_", "search"],
|
|
5061
|
+
["team_task_", "subagent"],
|
|
5062
|
+
["schedule_", "todo"]
|
|
5063
|
+
];
|
|
5064
|
+
/** The activity line's label while a compaction condenses history. */
|
|
5065
|
+
const COMPACTING_ACTIVITY = "compacting";
|
|
5066
|
+
/**
|
|
5067
|
+
* The activity line's label for a streamed or executing tool call.
|
|
5068
|
+
* @param name - the tool name when one is known.
|
|
5069
|
+
* @returns `calling <name>`, or `calling` when the name has not arrived.
|
|
5070
|
+
*/
|
|
5071
|
+
function callingActivity(name) {
|
|
5072
|
+
return name ? `calling ${name}` : "calling";
|
|
5073
|
+
}
|
|
5074
|
+
/**
|
|
5075
|
+
* Whether the activity line already names a tool call.
|
|
5076
|
+
* @param activity - the activity line's current label.
|
|
5077
|
+
* @returns true for `calling` and `calling <name>`.
|
|
5078
|
+
*/
|
|
5079
|
+
function isCallingActivity(activity) {
|
|
5080
|
+
return activity === "calling" || activity.startsWith("calling ");
|
|
5081
|
+
}
|
|
5082
|
+
/**
|
|
5083
|
+
* The status the activity line animates for its label.
|
|
5084
|
+
* @param activity - the label: `thinking`, `writing`, `calling` or
|
|
5085
|
+
* `calling <name>`, a scheduled retry starting with `retrying`, or
|
|
5086
|
+
* {@link COMPACTING_ACTIVITY}.
|
|
5087
|
+
* @returns the label's status; `calling` whichever tool the label names, and
|
|
5088
|
+
* `thinking` for any other label.
|
|
5089
|
+
*/
|
|
5090
|
+
function activityStatus(activity) {
|
|
5091
|
+
if (activity === "writing") return "writing";
|
|
5092
|
+
if (isCallingActivity(activity)) return "calling";
|
|
5093
|
+
if (activity.startsWith("retrying")) return "retrying";
|
|
5094
|
+
if (activity === "compacting") return "compacting";
|
|
5095
|
+
return "thinking";
|
|
5096
|
+
}
|
|
5097
|
+
/**
|
|
5098
|
+
* The family whose animation a running tool card draws for `name`.
|
|
5099
|
+
* @param name - the tool the model called.
|
|
5100
|
+
* @returns the tool's family, or `other` for a tool with no family.
|
|
5101
|
+
*/
|
|
5102
|
+
function toolFamily(name) {
|
|
5103
|
+
if (SHELL_TOOLS.has(name)) return "shell";
|
|
5104
|
+
if (EDIT_TOOLS.has(name)) return "edit";
|
|
5105
|
+
if (SEARCH_TOOLS.has(name)) return "search";
|
|
5106
|
+
if (isSubagentTool(name) || SUBAGENT_TOOLS.has(name)) return "subagent";
|
|
5107
|
+
if (TODO_TOOLS.has(name)) return "todo";
|
|
5108
|
+
for (const [prefix, family] of TOOL_PREFIXES) if (name.startsWith(prefix)) return family;
|
|
5109
|
+
return "other";
|
|
5110
|
+
}
|
|
5111
|
+
/**
|
|
5112
|
+
* The frame an indicator draws at one instant. The frame index advances
|
|
5113
|
+
* once per `periodMs` of wall clock, so indicators drawn at the same instant
|
|
5114
|
+
* step together, and a change of animation keeps the beat.
|
|
5115
|
+
* @param frames - the animation drawn.
|
|
5116
|
+
* @param now - the current time in milliseconds.
|
|
5117
|
+
* @param periodMs - how long each frame lasts, in milliseconds; positive.
|
|
5118
|
+
* @param phase - how many frames the indicator runs ahead of the clock, from 0 to {@link SPINNER_CYCLE} - 1.
|
|
5119
|
+
* @returns the frame at that instant.
|
|
5120
|
+
*/
|
|
5121
|
+
function spinnerFrame(frames, now, periodMs, phase = 0) {
|
|
5122
|
+
/* v8 ignore next -- the modulo keeps the index inside the frame list */
|
|
5123
|
+
return frames[(Math.floor(now / periodMs) + phase) % 8] ?? frames[0];
|
|
5124
|
+
}
|
|
5125
|
+
/**
|
|
5126
|
+
* The phase a new indicator spins at beside the indicators of the same
|
|
5127
|
+
* animation already spinning. Every {@link TOOL_SPINNERS} animation uses
|
|
5128
|
+
* eight different frames, so two indicators of one family at different phases
|
|
5129
|
+
* never draw the same glyph. A phase no indicator holds is taken, the one
|
|
5130
|
+
* farthest from its nearest neighbour first and the lowest on a tie; once
|
|
5131
|
+
* every phase is held, the lowest phase held by the fewest indicators.
|
|
5132
|
+
* @param taken - the phases of the indicators of that animation spinning now, one per indicator.
|
|
5133
|
+
* @returns a phase from 0 to {@link SPINNER_CYCLE} - 1.
|
|
5134
|
+
*/
|
|
5135
|
+
function staggerPhase(taken) {
|
|
5136
|
+
let best = 0;
|
|
5137
|
+
let fewest = Number.POSITIVE_INFINITY;
|
|
5138
|
+
let widest = -1;
|
|
5139
|
+
for (let phase = 0; phase < 8; phase += 1) {
|
|
5140
|
+
let holders = 0;
|
|
5141
|
+
let gap = 8;
|
|
5142
|
+
for (const other of taken) {
|
|
5143
|
+
if (other === phase) holders += 1;
|
|
5144
|
+
const distance = Math.abs(phase - other);
|
|
5145
|
+
gap = Math.min(gap, distance, 8 - distance);
|
|
5146
|
+
}
|
|
5147
|
+
if (holders < fewest || holders === fewest && gap > widest) {
|
|
5148
|
+
best = phase;
|
|
5149
|
+
fewest = holders;
|
|
5150
|
+
widest = gap;
|
|
5151
|
+
}
|
|
5152
|
+
}
|
|
5153
|
+
return best;
|
|
5154
|
+
}
|
|
5155
|
+
/**
|
|
5156
|
+
* Draw `text` dim with a bright highlight sweeping across it, one character
|
|
5157
|
+
* per `periodMs`: the character under the sweep is bold, its neighbours are
|
|
5158
|
+
* drawn at the plain foreground, and the sweep rests for {@link SHIMMER_GAP}
|
|
5159
|
+
* steps past the end before starting again.
|
|
5160
|
+
* @param palette - the palette the sweep is drawn with; a disabled palette returns `text` unchanged.
|
|
5161
|
+
* @param text - the plain text to draw.
|
|
5162
|
+
* @param now - the current time in milliseconds.
|
|
5163
|
+
* @param periodMs - how long the sweep rests on each character, in milliseconds; positive.
|
|
5164
|
+
* @returns the styled text, the same visible width as `text`.
|
|
5165
|
+
*/
|
|
5166
|
+
function shimmer(palette, text, now, periodMs) {
|
|
5167
|
+
const chars = Array.from(new Intl.Segmenter().segment(text), (part) => part.segment);
|
|
5168
|
+
const at = Math.floor(now / periodMs) % (chars.length + SHIMMER_GAP);
|
|
5169
|
+
const tone = (index) => {
|
|
5170
|
+
const distance = Math.abs(index - at);
|
|
5171
|
+
return distance === 0 ? "bright" : distance === 1 ? "plain" : "dim";
|
|
5172
|
+
};
|
|
5173
|
+
let out = "";
|
|
5174
|
+
let run = "";
|
|
5175
|
+
let current;
|
|
5176
|
+
const flush = () => {
|
|
5177
|
+
if (current === void 0 || run === "") return;
|
|
5178
|
+
out += current === "bright" ? palette.bold(run) : current === "plain" ? run : palette.dim(run);
|
|
5179
|
+
run = "";
|
|
5180
|
+
};
|
|
5181
|
+
for (const [index, char] of chars.entries()) {
|
|
5182
|
+
const next = tone(index);
|
|
5183
|
+
if (next !== current) {
|
|
5184
|
+
flush();
|
|
5185
|
+
current = next;
|
|
5186
|
+
}
|
|
5187
|
+
run += char;
|
|
5188
|
+
}
|
|
5189
|
+
flush();
|
|
5190
|
+
return out;
|
|
5191
|
+
}
|
|
5192
|
+
//#endregion
|
|
5193
|
+
//#region lib/types/workflow.js
|
|
5194
|
+
/**
|
|
5195
|
+
* Pure replay and presentation for durable tool-workflow runs. Consumers keep
|
|
5196
|
+
* each state under its run id; this module owns no mutable run registry.
|
|
5197
|
+
* @module @deepseek-ai/dsh-tui-app/workflow
|
|
5198
|
+
*/
|
|
5199
|
+
/**
|
|
5200
|
+
* Build a collision-free key for an exact phase identity.
|
|
5201
|
+
* @param phase - phase title, or null when a member event omitted it.
|
|
5202
|
+
* @returns a stable key distinct for null, empty, and every non-empty phase title.
|
|
5203
|
+
*/
|
|
5204
|
+
function workflowPhaseKey(phase) {
|
|
5205
|
+
return phase === null ? "missing" : `value:${String(phase.length)}:${phase}`;
|
|
5206
|
+
}
|
|
5207
|
+
/**
|
|
5208
|
+
* Fold one durable event into an externally owned workflow run state.
|
|
5209
|
+
* @param state - state stored under the event's run id, or undefined before its start.
|
|
5210
|
+
* @param event - durable workflow event to replay.
|
|
5211
|
+
* @returns the created or updated state, or undefined when an update arrives before a start.
|
|
5212
|
+
* Events for another run and unmatched member endings leave an existing state unchanged.
|
|
5213
|
+
*/
|
|
5214
|
+
function foldWorkflowRun(state, event) {
|
|
5215
|
+
if (event.type === "tool-workflow/run-start") return state ?? {
|
|
5216
|
+
runId: event.data.runId,
|
|
5217
|
+
name: event.data.name,
|
|
5218
|
+
members: []
|
|
5219
|
+
};
|
|
5220
|
+
if (state === void 0 || state.runId !== event.data.runId) return state;
|
|
5221
|
+
switch (event.type) {
|
|
5222
|
+
case "tool-workflow/agent-start": return {
|
|
5223
|
+
...state,
|
|
5224
|
+
members: [...state.members, {
|
|
5225
|
+
seq: event.data.seq,
|
|
5226
|
+
label: event.data.label,
|
|
5227
|
+
childId: event.data.childId,
|
|
5228
|
+
...event.data.phase === void 0 ? {} : { phase: event.data.phase }
|
|
5229
|
+
}]
|
|
5230
|
+
};
|
|
5231
|
+
case "tool-workflow/agent-end": return settleMember(state, event.data);
|
|
5232
|
+
case "tool-workflow/run-end": return {
|
|
5233
|
+
...state,
|
|
5234
|
+
stopReason: event.data.stopReason
|
|
5235
|
+
};
|
|
5236
|
+
/* v8 ignore next -- WorkflowRunEvent is closed and every update event is handled above. */
|
|
5237
|
+
default: return assertNever(event, "workflow run event");
|
|
5238
|
+
}
|
|
5239
|
+
}
|
|
5240
|
+
/**
|
|
5241
|
+
* Project durable workflow state for terminal presentation.
|
|
5242
|
+
* @param state - replayed workflow run state.
|
|
5243
|
+
* @param options - caller-selected handling for unfinished records.
|
|
5244
|
+
* @returns ordered phase and member data with derived statuses.
|
|
5245
|
+
*/
|
|
5246
|
+
function projectWorkflowRun(state, options = {}) {
|
|
5247
|
+
const interrupted = state.stopReason === void 0 && options.markUnfinishedInterrupted === true;
|
|
5248
|
+
const phases = /* @__PURE__ */ new Map();
|
|
5249
|
+
for (const member of state.members) {
|
|
5250
|
+
const phase = member.phase === void 0 ? null : member.phase;
|
|
5251
|
+
const key = workflowPhaseKey(phase);
|
|
5252
|
+
let group = phases.get(key);
|
|
5253
|
+
if (group === void 0) {
|
|
5254
|
+
group = {
|
|
5255
|
+
phase,
|
|
5256
|
+
members: []
|
|
5257
|
+
};
|
|
5258
|
+
phases.set(key, group);
|
|
5259
|
+
}
|
|
5260
|
+
group.members.push({
|
|
5261
|
+
seq: member.seq,
|
|
5262
|
+
label: member.label,
|
|
5263
|
+
childId: member.childId,
|
|
5264
|
+
status: member.outcome === void 0 ? interrupted ? "interrupted" : "running" : statusFromOutcome(member.outcome)
|
|
5265
|
+
});
|
|
5266
|
+
}
|
|
5267
|
+
return {
|
|
5268
|
+
runId: state.runId,
|
|
5269
|
+
name: state.name,
|
|
5270
|
+
status: state.stopReason === void 0 ? interrupted ? "interrupted" : "running" : statusFromStopReason(state.stopReason),
|
|
5271
|
+
phases: [...phases].map(([key, group]) => ({
|
|
5272
|
+
key,
|
|
5273
|
+
phase: group.phase,
|
|
5274
|
+
members: group.members
|
|
5275
|
+
}))
|
|
5276
|
+
};
|
|
5277
|
+
}
|
|
5278
|
+
/**
|
|
5279
|
+
* Readable terminal label for an exact phase identity.
|
|
5280
|
+
* @param phase - phase title, or null when the member event omitted it.
|
|
5281
|
+
* @returns the title, or a placeholder for an empty or omitted one.
|
|
5282
|
+
*/
|
|
5283
|
+
function workflowPhaseName(phase) {
|
|
5284
|
+
if (phase === null) return "unassigned";
|
|
5285
|
+
return phase === "" ? "(empty phase)" : phase;
|
|
5286
|
+
}
|
|
5287
|
+
/**
|
|
5288
|
+
* Readable terminal label for a workflow member label.
|
|
5289
|
+
* @param label - the label the member started with.
|
|
5290
|
+
* @returns the label, or a placeholder for an empty one.
|
|
5291
|
+
*/
|
|
5292
|
+
function workflowMemberName(label) {
|
|
5293
|
+
return label === "" ? "(unnamed member)" : label;
|
|
5294
|
+
}
|
|
5295
|
+
/**
|
|
5296
|
+
* Count the started members of one run by status.
|
|
5297
|
+
* @param view - projected workflow run.
|
|
5298
|
+
* @returns totals over every phase.
|
|
5299
|
+
*/
|
|
5300
|
+
function workflowProgress(view) {
|
|
5301
|
+
const counts = {
|
|
5302
|
+
running: 0,
|
|
5303
|
+
completed: 0,
|
|
5304
|
+
failed: 0,
|
|
5305
|
+
cancelled: 0,
|
|
5306
|
+
interrupted: 0
|
|
5307
|
+
};
|
|
5308
|
+
let total = 0;
|
|
5309
|
+
for (const phase of view.phases) for (const member of phase.members) {
|
|
5310
|
+
counts[member.status] += 1;
|
|
5311
|
+
total += 1;
|
|
5312
|
+
}
|
|
5313
|
+
return {
|
|
5314
|
+
total,
|
|
5315
|
+
settled: total - counts.running,
|
|
5316
|
+
counts
|
|
5317
|
+
};
|
|
5318
|
+
}
|
|
5319
|
+
function settleMember(state, data) {
|
|
5320
|
+
const index = state.members.findIndex((member) => member.seq === data.seq);
|
|
5321
|
+
if (index === -1) return state;
|
|
5322
|
+
return {
|
|
5323
|
+
...state,
|
|
5324
|
+
members: state.members.map((member, memberIndex) => memberIndex === index ? {
|
|
5325
|
+
...member,
|
|
5326
|
+
outcome: data.outcome
|
|
5327
|
+
} : member)
|
|
5328
|
+
};
|
|
5329
|
+
}
|
|
5330
|
+
function statusFromStopReason(stopReason) {
|
|
5331
|
+
switch (stopReason) {
|
|
5332
|
+
case "completed": return "completed";
|
|
5333
|
+
case "cancelled": return "cancelled";
|
|
5334
|
+
case "error": return "failed";
|
|
5335
|
+
/* v8 ignore next -- WorkflowStopReason is closed and every variant is handled above. */
|
|
5336
|
+
default: return assertNever(stopReason, "workflow stop reason");
|
|
5337
|
+
}
|
|
5338
|
+
}
|
|
5339
|
+
function statusFromOutcome(outcome) {
|
|
5340
|
+
switch (outcome) {
|
|
5341
|
+
case "completed": return "completed";
|
|
5342
|
+
case "cancelled": return "cancelled";
|
|
5343
|
+
case "failed": return "failed";
|
|
5344
|
+
/* v8 ignore next -- WorkflowAgentOutcome is closed and every variant is handled above. */
|
|
5345
|
+
default: return assertNever(outcome, "workflow agent outcome");
|
|
5346
|
+
}
|
|
5347
|
+
}
|
|
4851
5348
|
//#endregion
|
|
4852
5349
|
//#region lib/types/workflow-block.js
|
|
4853
5350
|
/**
|
|
4854
|
-
* Foldable terminal rendering for one durable workflow run
|
|
4855
|
-
*
|
|
4856
|
-
*
|
|
5351
|
+
* Foldable terminal rendering for one durable workflow run: a run header with
|
|
5352
|
+
* a member progress bar, phase headers, and member rows. It keeps run and
|
|
5353
|
+
* phase disclosure choices and the last drawn spinner frame local while the
|
|
5354
|
+
* application owns durable replay, child-session liveness, and the spinner tick.
|
|
4857
5355
|
* @module @deepseek-ai/dsh-tui-app/workflow-block
|
|
4858
5356
|
*/
|
|
4859
5357
|
/** Columns the focus gutter takes from this block's content. */
|
|
@@ -4862,6 +5360,16 @@ const GUTTER_WIDTH = 2;
|
|
|
4862
5360
|
const BLOCK_GUTTER = "│ ";
|
|
4863
5361
|
/** Gutter beside the focused workflow section. */
|
|
4864
5362
|
const PART_GUTTER = "┃ ";
|
|
5363
|
+
/** Cells of the member progress bar on a run header. */
|
|
5364
|
+
const PROGRESS_CELLS = 10;
|
|
5365
|
+
/** Order the progress bar fills its cells in, settled statuses first. */
|
|
5366
|
+
const PROGRESS_ORDER = [
|
|
5367
|
+
"completed",
|
|
5368
|
+
"failed",
|
|
5369
|
+
"cancelled",
|
|
5370
|
+
"interrupted",
|
|
5371
|
+
"running"
|
|
5372
|
+
];
|
|
4865
5373
|
/**
|
|
4866
5374
|
* One workflow run in the transcript. The block's source state can advance
|
|
4867
5375
|
* while its already-written scrollback stays frozen; reader and inspector rows
|
|
@@ -4891,6 +5399,12 @@ var WorkflowBlock = class {
|
|
|
4891
5399
|
pendingHighlight;
|
|
4892
5400
|
revision = 0;
|
|
4893
5401
|
drawn;
|
|
5402
|
+
/** Reads the current spinner frame number; undefined draws the static glyphs. */
|
|
5403
|
+
spinClock;
|
|
5404
|
+
/** Frame number last drawn; a block under the repaint floor keeps it. */
|
|
5405
|
+
spinIndex = 0;
|
|
5406
|
+
/** Whether a spinner frame was drawn inside the repaint window, so a locked block keeps drawing it. */
|
|
5407
|
+
spinStarted = false;
|
|
4894
5408
|
/**
|
|
4895
5409
|
* @param theme - terminal palette shared with transcript blocks.
|
|
4896
5410
|
* @param initial - durable run projection at insertion.
|
|
@@ -4908,6 +5422,26 @@ var WorkflowBlock = class {
|
|
|
4908
5422
|
get name() {
|
|
4909
5423
|
return this.source.name;
|
|
4910
5424
|
}
|
|
5425
|
+
/** Newest durable projection, including updates not yet drawn. */
|
|
5426
|
+
get view() {
|
|
5427
|
+
return this.source;
|
|
5428
|
+
}
|
|
5429
|
+
/**
|
|
5430
|
+
* Spin the run header and running member glyphs while the run runs. A block
|
|
5431
|
+
* above the repaint window keeps the frame it last drew.
|
|
5432
|
+
* @param clock - reads the current spinner frame number; undefined draws the static glyphs.
|
|
5433
|
+
*/
|
|
5434
|
+
setSpinner(clock) {
|
|
5435
|
+
this.spinClock = clock;
|
|
5436
|
+
this.changed();
|
|
5437
|
+
}
|
|
5438
|
+
/**
|
|
5439
|
+
* Whether the block still animates on the spinner tick.
|
|
5440
|
+
* @returns true while a spinner is set and the newest projection runs.
|
|
5441
|
+
*/
|
|
5442
|
+
spinning() {
|
|
5443
|
+
return this.spinClock !== void 0 && this.source.status === "running";
|
|
5444
|
+
}
|
|
4911
5445
|
/**
|
|
4912
5446
|
* Replace the durable rendering projection. A block above the repaint window
|
|
4913
5447
|
* keeps its earlier transcript rows until the next safe redraw.
|
|
@@ -5045,7 +5579,7 @@ var WorkflowBlock = class {
|
|
|
5045
5579
|
if (!this.openableChildren.has(ref.member.childId)) return void 0;
|
|
5046
5580
|
return {
|
|
5047
5581
|
childId: ref.member.childId,
|
|
5048
|
-
label:
|
|
5582
|
+
label: workflowMemberName(ref.member.label)
|
|
5049
5583
|
};
|
|
5050
5584
|
}
|
|
5051
5585
|
/** Build full source rows for the inspector and reader. */
|
|
@@ -5062,18 +5596,18 @@ var WorkflowBlock = class {
|
|
|
5062
5596
|
for (const phase of this.source.phases) {
|
|
5063
5597
|
rows.push({
|
|
5064
5598
|
kind: "workflow-phase",
|
|
5065
|
-
label: `phase ${
|
|
5599
|
+
label: `phase ${workflowPhaseName(phase.phase)}`,
|
|
5066
5600
|
rows: [
|
|
5067
|
-
|
|
5601
|
+
workflowPhaseName(phase.phase),
|
|
5068
5602
|
`${String(phase.members.length)} member${phase.members.length === 1 ? "" : "s"}`,
|
|
5069
5603
|
phaseSummary(phase)
|
|
5070
5604
|
]
|
|
5071
5605
|
});
|
|
5072
5606
|
for (const member of phase.members) rows.push({
|
|
5073
5607
|
kind: "workflow-member",
|
|
5074
|
-
label: `member ${
|
|
5608
|
+
label: `member ${workflowMemberName(member.label)}`,
|
|
5075
5609
|
rows: [
|
|
5076
|
-
|
|
5610
|
+
workflowMemberName(member.label),
|
|
5077
5611
|
statusText(member.status),
|
|
5078
5612
|
`child ${member.childId}`
|
|
5079
5613
|
]
|
|
@@ -5199,9 +5733,15 @@ var WorkflowBlock = class {
|
|
|
5199
5733
|
}
|
|
5200
5734
|
/** Cached layout for unchanged width and visible state. */
|
|
5201
5735
|
layout(width) {
|
|
5202
|
-
const
|
|
5736
|
+
const clock = this.displayed.status === "running" ? this.spinClock : void 0;
|
|
5737
|
+
if (clock !== void 0 && !this.repaintLocked) {
|
|
5738
|
+
this.spinIndex = clock();
|
|
5739
|
+
this.spinStarted = true;
|
|
5740
|
+
}
|
|
5741
|
+
const animated = clock !== void 0 && this.spinStarted;
|
|
5742
|
+
const key = `${String(width)}:${String(this.revision)}:${animated ? String(this.spinIndex) : "-"}`;
|
|
5203
5743
|
if (this.drawn?.key === key) return this.drawn.layout;
|
|
5204
|
-
const layout = this.buildLayout(width);
|
|
5744
|
+
const layout = this.buildLayout(width, animated ? spinGlyphs(this.spinIndex) : void 0);
|
|
5205
5745
|
this.drawn = {
|
|
5206
5746
|
key,
|
|
5207
5747
|
layout
|
|
@@ -5209,7 +5749,7 @@ var WorkflowBlock = class {
|
|
|
5209
5749
|
return layout;
|
|
5210
5750
|
}
|
|
5211
5751
|
/** Build visible rows and hidden-part fallback ranges from the displayed projection. */
|
|
5212
|
-
buildLayout(width) {
|
|
5752
|
+
buildLayout(width, spin) {
|
|
5213
5753
|
const lines = [""];
|
|
5214
5754
|
const refs = workflowParts(this.displayed);
|
|
5215
5755
|
const ranges = Array.from({ length: refs.length });
|
|
@@ -5226,7 +5766,7 @@ var WorkflowBlock = class {
|
|
|
5226
5766
|
return range;
|
|
5227
5767
|
};
|
|
5228
5768
|
let part = 0;
|
|
5229
|
-
const runRange = append(part, runRow(this.theme, this.displayed));
|
|
5769
|
+
const runRange = append(part, runRow(this.theme, this.displayed, spin));
|
|
5230
5770
|
part += 1;
|
|
5231
5771
|
if (!this.runDisclosure.open) {
|
|
5232
5772
|
for (; part < refs.length; part += 1) fallbacks[part] = runRange;
|
|
@@ -5247,7 +5787,7 @@ var WorkflowBlock = class {
|
|
|
5247
5787
|
continue;
|
|
5248
5788
|
}
|
|
5249
5789
|
for (const member of phase.members) {
|
|
5250
|
-
append(part, memberRow(this.theme, member, this.openableChildren.has(member.childId)));
|
|
5790
|
+
append(part, memberRow(this.theme, member, this.openableChildren.has(member.childId), spin));
|
|
5251
5791
|
part += 1;
|
|
5252
5792
|
}
|
|
5253
5793
|
}
|
|
@@ -5278,578 +5818,283 @@ function runFacts(run) {
|
|
|
5278
5818
|
activityCount: phases.reduce((count, phase) => count + phase.activityCount, 0)
|
|
5279
5819
|
};
|
|
5280
5820
|
}
|
|
5281
|
-
/** Initial disclosure follows the same status-driven choice as the Web run node. */
|
|
5282
|
-
function initialDisclosure(facts) {
|
|
5283
|
-
return {
|
|
5284
|
-
...facts,
|
|
5285
|
-
open: facts.mode !== "clean",
|
|
5286
|
-
pendingCleanCollapse: false
|
|
5287
|
-
};
|
|
5288
|
-
}
|
|
5289
|
-
/** Advance a disclosure without overwriting a person's choice during ordinary updates. */
|
|
5290
|
-
function advanceDisclosure(current, facts, focusWithin) {
|
|
5291
|
-
if (current.mode === facts.mode && current.activityCount === facts.activityCount) {
|
|
5292
|
-
if (!current.pendingCleanCollapse || focusWithin) return current;
|
|
5293
|
-
return {
|
|
5294
|
-
...current,
|
|
5295
|
-
open: false,
|
|
5296
|
-
pendingCleanCollapse: false
|
|
5297
|
-
};
|
|
5298
|
-
}
|
|
5299
|
-
if (facts.mode === "clean") {
|
|
5300
|
-
const defer = current.open && focusWithin;
|
|
5301
|
-
return {
|
|
5302
|
-
...facts,
|
|
5303
|
-
open: defer,
|
|
5304
|
-
pendingCleanCollapse: defer
|
|
5305
|
-
};
|
|
5306
|
-
}
|
|
5307
|
-
if (current.mode === "clean" || facts.mode === "abnormal" && current.mode !== "abnormal") return {
|
|
5308
|
-
...facts,
|
|
5309
|
-
open: true,
|
|
5310
|
-
pendingCleanCollapse: false
|
|
5311
|
-
};
|
|
5312
|
-
return {
|
|
5313
|
-
...facts,
|
|
5314
|
-
open: current.open,
|
|
5315
|
-
pendingCleanCollapse: false
|
|
5316
|
-
};
|
|
5317
|
-
}
|
|
5318
|
-
/** Close a disclosure whose clean transition waited for focus to leave. */
|
|
5319
|
-
function collapseDisclosure(state) {
|
|
5320
|
-
return state.pendingCleanCollapse ? {
|
|
5321
|
-
...state,
|
|
5322
|
-
open: false,
|
|
5323
|
-
pendingCleanCollapse: false
|
|
5324
|
-
} : state;
|
|
5325
|
-
}
|
|
5326
|
-
/** Whether a status needs attention rather than a clean completion treatment. */
|
|
5327
|
-
function abnormal(status) {
|
|
5328
|
-
return status === "failed" || status === "cancelled" || status === "interrupted";
|
|
5329
|
-
}
|
|
5330
|
-
/** Flat run, phase, member order matching {@link WorkflowBlock.parts}. */
|
|
5331
|
-
function workflowParts(data) {
|
|
5332
|
-
const parts = [{ kind: "run" }];
|
|
5333
|
-
for (const phase of data.phases) {
|
|
5334
|
-
parts.push({
|
|
5335
|
-
kind: "phase",
|
|
5336
|
-
key: phase.key
|
|
5337
|
-
});
|
|
5338
|
-
for (const member of phase.members) parts.push({
|
|
5339
|
-
kind: "member",
|
|
5340
|
-
key: phase.key,
|
|
5341
|
-
member
|
|
5342
|
-
});
|
|
5343
|
-
}
|
|
5344
|
-
return parts;
|
|
5345
|
-
}
|
|
5346
|
-
/** Number of started members in every phase. */
|
|
5347
|
-
function memberCount(data) {
|
|
5348
|
-
return data.phases.reduce((count, phase) => count + phase.members.length, 0);
|
|
5349
|
-
}
|
|
5350
|
-
/** Readable terminal label for an exact phase identity. */
|
|
5351
|
-
function phaseName(phase) {
|
|
5352
|
-
if (phase === null) return "unassigned";
|
|
5353
|
-
return phase === "" ? "(empty phase)" : phase;
|
|
5354
|
-
}
|
|
5355
|
-
/** Readable terminal label for an optional workflow member label. */
|
|
5356
|
-
function memberName(label) {
|
|
5357
|
-
return label === "" ? "(unnamed member)" : label;
|
|
5358
|
-
}
|
|
5359
|
-
/** Compact status count summary matching a phase disclosure's tail. */
|
|
5360
|
-
function phaseSummary(phase) {
|
|
5361
|
-
const counts = /* @__PURE__ */ new Map();
|
|
5362
|
-
for (const member of phase.members) counts.set(member.status, (counts.get(member.status) ?? 0) + 1);
|
|
5363
|
-
const count = (status) => counts.get(status) ?? 0;
|
|
5364
|
-
const active = [
|
|
5365
|
-
"running",
|
|
5366
|
-
"failed",
|
|
5367
|
-
"cancelled",
|
|
5368
|
-
"interrupted"
|
|
5369
|
-
].filter((status) => count(status) > 0);
|
|
5370
|
-
return (active.length === 0 ? ["completed"] : active.includes("interrupted") && count("completed") > 0 ? ["completed", ...active] : active).map((status) => `${String(count(status))} ${status}`).join(" · ");
|
|
5371
|
-
}
|
|
5372
|
-
/** Plain status label kept in source rows. */
|
|
5373
|
-
function statusText(status) {
|
|
5374
|
-
return status;
|
|
5375
|
-
}
|
|
5376
|
-
/** One run header in transcript colors. */
|
|
5377
|
-
function runRow(theme, run) {
|
|
5378
|
-
const { palette } = theme;
|
|
5379
|
-
const count = memberCount(run);
|
|
5380
|
-
return `${statusStyle(palette, run.status)("◇")} ${palette.bold("workflow")} ${palette.link(run.name)} ${palette.dim(`· ${String(count)} member${count === 1 ? "" : "s"} · `)}${statusStyle(palette, run.status)(statusText(run.status))}`;
|
|
5381
|
-
}
|
|
5382
|
-
/** One phase header in transcript colors. */
|
|
5383
|
-
function phaseRow(theme, phase) {
|
|
5384
|
-
const { palette } = theme;
|
|
5385
|
-
const count = phase.members.length;
|
|
5386
|
-
const mode = phaseFacts(phase).mode;
|
|
5387
|
-
const status = phase.members.find((member) => abnormal(member.status))?.status ?? (mode === "running" ? "running" : "completed");
|
|
5388
|
-
return ` ${statusStyle(palette, status)("▸")} ${palette.heading(phaseName(phase.phase))} ${palette.dim(`· ${String(count)} member${count === 1 ? "" : "s"} · `)}${statusStyle(palette, status)(phaseSummary(phase))}`;
|
|
5389
|
-
}
|
|
5390
|
-
/** One member row in transcript colors. */
|
|
5391
|
-
function memberRow(theme, member, openable) {
|
|
5392
|
-
const { palette } = theme;
|
|
5393
|
-
const label = memberName(member.label);
|
|
5394
|
-
const name = openable ? palette.link(label) : label;
|
|
5395
|
-
return ` ${statusStyle(palette, member.status)("○")} ${name} ${statusStyle(palette, member.status)(`[${statusText(member.status)}]`)}`;
|
|
5396
|
-
}
|
|
5397
|
-
/** Palette role for one workflow status. */
|
|
5398
|
-
function statusStyle(theme, status) {
|
|
5399
|
-
switch (status) {
|
|
5400
|
-
case "running": return theme.warning;
|
|
5401
|
-
case "completed": return theme.success;
|
|
5402
|
-
case "failed": return theme.error;
|
|
5403
|
-
case "cancelled":
|
|
5404
|
-
case "interrupted": return theme.warning;
|
|
5405
|
-
/* v8 ignore next -- WorkflowRunStatus is closed and every variant is handled above. */
|
|
5406
|
-
default: return status;
|
|
5407
|
-
}
|
|
5408
|
-
}
|
|
5409
|
-
/** Compare local liveness ids before rebuilding a member-row layout. */
|
|
5410
|
-
function sameIds(left, right) {
|
|
5411
|
-
if (left.size !== right.size) return false;
|
|
5412
|
-
for (const id of left) if (!right.has(id)) return false;
|
|
5413
|
-
return true;
|
|
5414
|
-
}
|
|
5415
|
-
//#endregion
|
|
5416
|
-
//#region lib/types/workflow.js
|
|
5417
|
-
/**
|
|
5418
|
-
* Pure replay and presentation for durable tool-workflow runs. Consumers keep
|
|
5419
|
-
* each state under its run id; this module owns no mutable run registry.
|
|
5420
|
-
* @module @deepseek-ai/dsh-tui-app/workflow
|
|
5421
|
-
*/
|
|
5422
|
-
/**
|
|
5423
|
-
* Build a collision-free key for an exact phase identity.
|
|
5424
|
-
* @param phase - phase title, or null when a member event omitted it.
|
|
5425
|
-
* @returns a stable key distinct for null, empty, and every non-empty phase title.
|
|
5426
|
-
*/
|
|
5427
|
-
function workflowPhaseKey(phase) {
|
|
5428
|
-
return phase === null ? "missing" : `value:${String(phase.length)}:${phase}`;
|
|
5429
|
-
}
|
|
5430
|
-
/**
|
|
5431
|
-
* Fold one durable event into an externally owned workflow run state.
|
|
5432
|
-
* @param state - state stored under the event's run id, or undefined before its start.
|
|
5433
|
-
* @param event - durable workflow event to replay.
|
|
5434
|
-
* @returns the created or updated state, or undefined when an update arrives before a start.
|
|
5435
|
-
* Events for another run and unmatched member endings leave an existing state unchanged.
|
|
5436
|
-
*/
|
|
5437
|
-
function foldWorkflowRun(state, event) {
|
|
5438
|
-
if (event.type === "tool-workflow/run-start") return state ?? {
|
|
5439
|
-
runId: event.data.runId,
|
|
5440
|
-
name: event.data.name,
|
|
5441
|
-
members: []
|
|
5442
|
-
};
|
|
5443
|
-
if (state === void 0 || state.runId !== event.data.runId) return state;
|
|
5444
|
-
switch (event.type) {
|
|
5445
|
-
case "tool-workflow/agent-start": return {
|
|
5446
|
-
...state,
|
|
5447
|
-
members: [...state.members, {
|
|
5448
|
-
seq: event.data.seq,
|
|
5449
|
-
label: event.data.label,
|
|
5450
|
-
childId: event.data.childId,
|
|
5451
|
-
...event.data.phase === void 0 ? {} : { phase: event.data.phase }
|
|
5452
|
-
}]
|
|
5453
|
-
};
|
|
5454
|
-
case "tool-workflow/agent-end": return settleMember(state, event.data);
|
|
5455
|
-
case "tool-workflow/run-end": return {
|
|
5456
|
-
...state,
|
|
5457
|
-
stopReason: event.data.stopReason
|
|
5458
|
-
};
|
|
5459
|
-
/* v8 ignore next -- WorkflowRunEvent is closed and every update event is handled above. */
|
|
5460
|
-
default: return assertNever(event, "workflow run event");
|
|
5461
|
-
}
|
|
5462
|
-
}
|
|
5463
|
-
/**
|
|
5464
|
-
* Project durable workflow state for terminal presentation.
|
|
5465
|
-
* @param state - replayed workflow run state.
|
|
5466
|
-
* @param options - caller-selected handling for unfinished records.
|
|
5467
|
-
* @returns ordered phase and member data with derived statuses.
|
|
5468
|
-
*/
|
|
5469
|
-
function projectWorkflowRun(state, options = {}) {
|
|
5470
|
-
const interrupted = state.stopReason === void 0 && options.markUnfinishedInterrupted === true;
|
|
5471
|
-
const phases = /* @__PURE__ */ new Map();
|
|
5472
|
-
for (const member of state.members) {
|
|
5473
|
-
const phase = member.phase === void 0 ? null : member.phase;
|
|
5474
|
-
const key = workflowPhaseKey(phase);
|
|
5475
|
-
let group = phases.get(key);
|
|
5476
|
-
if (group === void 0) {
|
|
5477
|
-
group = {
|
|
5478
|
-
phase,
|
|
5479
|
-
members: []
|
|
5480
|
-
};
|
|
5481
|
-
phases.set(key, group);
|
|
5482
|
-
}
|
|
5483
|
-
group.members.push({
|
|
5484
|
-
seq: member.seq,
|
|
5485
|
-
label: member.label,
|
|
5486
|
-
childId: member.childId,
|
|
5487
|
-
status: member.outcome === void 0 ? interrupted ? "interrupted" : "running" : statusFromOutcome(member.outcome)
|
|
5488
|
-
});
|
|
5489
|
-
}
|
|
5490
|
-
return {
|
|
5491
|
-
runId: state.runId,
|
|
5492
|
-
name: state.name,
|
|
5493
|
-
status: state.stopReason === void 0 ? interrupted ? "interrupted" : "running" : statusFromStopReason(state.stopReason),
|
|
5494
|
-
phases: [...phases].map(([key, group]) => ({
|
|
5495
|
-
key,
|
|
5496
|
-
phase: group.phase,
|
|
5497
|
-
members: group.members
|
|
5498
|
-
}))
|
|
5499
|
-
};
|
|
5500
|
-
}
|
|
5501
|
-
function settleMember(state, data) {
|
|
5502
|
-
const index = state.members.findIndex((member) => member.seq === data.seq);
|
|
5503
|
-
if (index === -1) return state;
|
|
5821
|
+
/** Initial disclosure follows the same status-driven choice as the Web run node. */
|
|
5822
|
+
function initialDisclosure(facts) {
|
|
5504
5823
|
return {
|
|
5505
|
-
...
|
|
5506
|
-
|
|
5507
|
-
|
|
5508
|
-
outcome: data.outcome
|
|
5509
|
-
} : member)
|
|
5824
|
+
...facts,
|
|
5825
|
+
open: facts.mode !== "clean",
|
|
5826
|
+
pendingCleanCollapse: false
|
|
5510
5827
|
};
|
|
5511
5828
|
}
|
|
5512
|
-
|
|
5513
|
-
|
|
5514
|
-
|
|
5515
|
-
|
|
5516
|
-
|
|
5517
|
-
|
|
5518
|
-
|
|
5829
|
+
/** Advance a disclosure without overwriting a person's choice during ordinary updates. */
|
|
5830
|
+
function advanceDisclosure(current, facts, focusWithin) {
|
|
5831
|
+
if (current.mode === facts.mode && current.activityCount === facts.activityCount) {
|
|
5832
|
+
if (!current.pendingCleanCollapse || focusWithin) return current;
|
|
5833
|
+
return {
|
|
5834
|
+
...current,
|
|
5835
|
+
open: false,
|
|
5836
|
+
pendingCleanCollapse: false
|
|
5837
|
+
};
|
|
5519
5838
|
}
|
|
5520
|
-
|
|
5521
|
-
|
|
5522
|
-
|
|
5523
|
-
|
|
5524
|
-
|
|
5525
|
-
|
|
5526
|
-
|
|
5527
|
-
default: return assertNever(outcome, "workflow agent outcome");
|
|
5839
|
+
if (facts.mode === "clean") {
|
|
5840
|
+
const defer = current.open && focusWithin;
|
|
5841
|
+
return {
|
|
5842
|
+
...facts,
|
|
5843
|
+
open: defer,
|
|
5844
|
+
pendingCleanCollapse: defer
|
|
5845
|
+
};
|
|
5528
5846
|
}
|
|
5847
|
+
if (current.mode === "clean" || facts.mode === "abnormal" && current.mode !== "abnormal") return {
|
|
5848
|
+
...facts,
|
|
5849
|
+
open: true,
|
|
5850
|
+
pendingCleanCollapse: false
|
|
5851
|
+
};
|
|
5852
|
+
return {
|
|
5853
|
+
...facts,
|
|
5854
|
+
open: current.open,
|
|
5855
|
+
pendingCleanCollapse: false
|
|
5856
|
+
};
|
|
5857
|
+
}
|
|
5858
|
+
/** Close a disclosure whose clean transition waited for focus to leave. */
|
|
5859
|
+
function collapseDisclosure(state) {
|
|
5860
|
+
return state.pendingCleanCollapse ? {
|
|
5861
|
+
...state,
|
|
5862
|
+
open: false,
|
|
5863
|
+
pendingCleanCollapse: false
|
|
5864
|
+
} : state;
|
|
5865
|
+
}
|
|
5866
|
+
/** Whether a status needs attention rather than a clean completion treatment. */
|
|
5867
|
+
function abnormal(status) {
|
|
5868
|
+
return status === "failed" || status === "cancelled" || status === "interrupted";
|
|
5869
|
+
}
|
|
5870
|
+
/** Flat run, phase, member order matching {@link WorkflowBlock.parts}. */
|
|
5871
|
+
function workflowParts(data) {
|
|
5872
|
+
const parts = [{ kind: "run" }];
|
|
5873
|
+
for (const phase of data.phases) {
|
|
5874
|
+
parts.push({
|
|
5875
|
+
kind: "phase",
|
|
5876
|
+
key: phase.key
|
|
5877
|
+
});
|
|
5878
|
+
for (const member of phase.members) parts.push({
|
|
5879
|
+
kind: "member",
|
|
5880
|
+
key: phase.key,
|
|
5881
|
+
member
|
|
5882
|
+
});
|
|
5883
|
+
}
|
|
5884
|
+
return parts;
|
|
5885
|
+
}
|
|
5886
|
+
/** Number of started members in every phase. */
|
|
5887
|
+
function memberCount(data) {
|
|
5888
|
+
return data.phases.reduce((count, phase) => count + phase.members.length, 0);
|
|
5889
|
+
}
|
|
5890
|
+
/** Compact status count summary matching a phase disclosure's tail. */
|
|
5891
|
+
function phaseSummary(phase) {
|
|
5892
|
+
const counts = /* @__PURE__ */ new Map();
|
|
5893
|
+
for (const member of phase.members) counts.set(member.status, (counts.get(member.status) ?? 0) + 1);
|
|
5894
|
+
const count = (status) => counts.get(status) ?? 0;
|
|
5895
|
+
const active = [
|
|
5896
|
+
"running",
|
|
5897
|
+
"failed",
|
|
5898
|
+
"cancelled",
|
|
5899
|
+
"interrupted"
|
|
5900
|
+
].filter((status) => count(status) > 0);
|
|
5901
|
+
return (active.length === 0 ? ["completed"] : active.includes("interrupted") && count("completed") > 0 ? ["completed", ...active] : active).map((status) => `${String(count(status))} ${status}`).join(" · ");
|
|
5902
|
+
}
|
|
5903
|
+
/** Plain status label kept in source rows. */
|
|
5904
|
+
function statusText(status) {
|
|
5905
|
+
return status;
|
|
5529
5906
|
}
|
|
5530
5907
|
/**
|
|
5531
|
-
* The
|
|
5532
|
-
*
|
|
5533
|
-
*
|
|
5534
|
-
*/
|
|
5535
|
-
const ACTIVITY_SPINNERS = {
|
|
5536
|
-
/** Model reasoning, and any label with no status of its own: three dots circling the cell. */
|
|
5537
|
-
thinking: [
|
|
5538
|
-
"⠙",
|
|
5539
|
-
"⠸",
|
|
5540
|
-
"⢰",
|
|
5541
|
-
"⣠",
|
|
5542
|
-
"⣄",
|
|
5543
|
-
"⡆",
|
|
5544
|
-
"⠇",
|
|
5545
|
-
"⠋"
|
|
5546
|
-
],
|
|
5547
|
-
/** Visible reply text streaming in: lines filling the cell, then streaming up out of it. */
|
|
5548
|
-
writing: [
|
|
5549
|
-
"⠉",
|
|
5550
|
-
"⠛",
|
|
5551
|
-
"⠿",
|
|
5552
|
-
"⣿",
|
|
5553
|
-
"⣶",
|
|
5554
|
-
"⣤",
|
|
5555
|
-
"⣀",
|
|
5556
|
-
"⣉"
|
|
5557
|
-
],
|
|
5558
|
-
/** A tool call streamed or running, whichever tool it names: one dot orbiting the cell. */
|
|
5559
|
-
calling: [
|
|
5560
|
-
"⠁",
|
|
5561
|
-
"⠈",
|
|
5562
|
-
"⠐",
|
|
5563
|
-
"⠠",
|
|
5564
|
-
"⢀",
|
|
5565
|
-
"⡀",
|
|
5566
|
-
"⠄",
|
|
5567
|
-
"⠂"
|
|
5568
|
-
],
|
|
5569
|
-
/** A scheduled model-request retry: a bar sliding down the cell and back. */
|
|
5570
|
-
retrying: [
|
|
5571
|
-
"⠉",
|
|
5572
|
-
"⠛",
|
|
5573
|
-
"⠶",
|
|
5574
|
-
"⣤",
|
|
5575
|
-
"⣀",
|
|
5576
|
-
"⣤",
|
|
5577
|
-
"⠶",
|
|
5578
|
-
"⠛"
|
|
5579
|
-
],
|
|
5580
|
-
/** Condensing older history into a summary: a full cell settling and refilling. */
|
|
5581
|
-
compacting: [
|
|
5582
|
-
"⣿",
|
|
5583
|
-
"⣷",
|
|
5584
|
-
"⣶",
|
|
5585
|
-
"⣦",
|
|
5586
|
-
"⣤",
|
|
5587
|
-
"⣦",
|
|
5588
|
-
"⣶",
|
|
5589
|
-
"⣷"
|
|
5590
|
-
]
|
|
5591
|
-
};
|
|
5592
|
-
/**
|
|
5593
|
-
* The animation a running tool card draws, by tool family; a folded subagent
|
|
5594
|
-
* row draws `subagent`, and the activity board's in-progress todo rows draw
|
|
5595
|
-
* `todo`. Each cycle mixes flowers, blooms, and stars. No frame is braille,
|
|
5596
|
-
* no two families share a glyph, and the eight frames of one family all
|
|
5597
|
-
* differ, so two indicators of that family at different phases never draw the
|
|
5598
|
-
* same glyph at the same instant. A presentation choice of this terminal
|
|
5599
|
-
* surface, not a deployment setting.
|
|
5600
|
-
*/
|
|
5601
|
-
const TOOL_SPINNERS = {
|
|
5602
|
-
/** Command execution: four-pointed stars, teardrop blooms, and florettes. */
|
|
5603
|
-
shell: [
|
|
5604
|
-
"✧",
|
|
5605
|
-
"✢",
|
|
5606
|
-
"✽",
|
|
5607
|
-
"✿",
|
|
5608
|
-
"❋",
|
|
5609
|
-
"✸",
|
|
5610
|
-
"❀",
|
|
5611
|
-
"✹"
|
|
5612
|
-
],
|
|
5613
|
-
/** File mutation: florettes between outlined stars and an open bloom. */
|
|
5614
|
-
edit: [
|
|
5615
|
-
"✩",
|
|
5616
|
-
"✤",
|
|
5617
|
-
"✾",
|
|
5618
|
-
"❁",
|
|
5619
|
-
"✭",
|
|
5620
|
-
"✮",
|
|
5621
|
-
"❂",
|
|
5622
|
-
"✲"
|
|
5623
|
-
],
|
|
5624
|
-
/** Reading and searching: flowers and an open bloom among stars. */
|
|
5625
|
-
search: [
|
|
5626
|
-
"⋆",
|
|
5627
|
-
"✱",
|
|
5628
|
-
"✵",
|
|
5629
|
-
"⚘",
|
|
5630
|
-
"❃",
|
|
5631
|
-
"✶",
|
|
5632
|
-
"⁕",
|
|
5633
|
-
"✷"
|
|
5634
|
-
],
|
|
5635
|
-
/** Delegation, a folded subagent row included: floral hearts, pinwheel blooms, and stars. */
|
|
5636
|
-
subagent: [
|
|
5637
|
-
"✦",
|
|
5638
|
-
"✣",
|
|
5639
|
-
"❊",
|
|
5640
|
-
"❦",
|
|
5641
|
-
"❉",
|
|
5642
|
-
"✪",
|
|
5643
|
-
"✫",
|
|
5644
|
-
"❧"
|
|
5645
|
-
],
|
|
5646
|
-
/** Planning and scheduling, and an in-progress todo row: a florette, teardrop blooms, and stars. */
|
|
5647
|
-
todo: [
|
|
5648
|
-
"☆",
|
|
5649
|
-
"✥",
|
|
5650
|
-
"✼",
|
|
5651
|
-
"❅",
|
|
5652
|
-
"✻",
|
|
5653
|
-
"✬",
|
|
5654
|
-
"★",
|
|
5655
|
-
"✰"
|
|
5656
|
-
],
|
|
5657
|
-
/** A tool with no family of its own: a sparkle and a florette among stars. */
|
|
5658
|
-
other: [
|
|
5659
|
-
"∗",
|
|
5660
|
-
"❈",
|
|
5661
|
-
"⁎",
|
|
5662
|
-
"❆",
|
|
5663
|
-
"⚝",
|
|
5664
|
-
"✺",
|
|
5665
|
-
"⚹",
|
|
5666
|
-
"✯"
|
|
5667
|
-
]
|
|
5668
|
-
};
|
|
5669
|
-
/** Blank steps between two shimmer passes, so the sweep pauses past the word's end. */
|
|
5670
|
-
const SHIMMER_GAP = 6;
|
|
5671
|
-
/** Tool names that execute commands. */
|
|
5672
|
-
const SHELL_TOOLS = new Set([
|
|
5673
|
-
"bash",
|
|
5674
|
-
"pwsh",
|
|
5675
|
-
"run_code"
|
|
5676
|
-
]);
|
|
5677
|
-
/** Tool names that mutate files. */
|
|
5678
|
-
const EDIT_TOOLS = new Set([
|
|
5679
|
-
"edit",
|
|
5680
|
-
"write",
|
|
5681
|
-
"str_replace_editor"
|
|
5682
|
-
]);
|
|
5683
|
-
/** Tool names that read or search, beyond the `TOOL_PREFIXES` below. */
|
|
5684
|
-
const SEARCH_TOOLS = new Set([
|
|
5685
|
-
"read",
|
|
5686
|
-
"read_image",
|
|
5687
|
-
"glob",
|
|
5688
|
-
"grep",
|
|
5689
|
-
"lsp",
|
|
5690
|
-
"skill",
|
|
5691
|
-
"web_fetch",
|
|
5692
|
-
"web_search",
|
|
5693
|
-
"load_workspace_dependencies",
|
|
5694
|
-
"list_subagent_models"
|
|
5695
|
-
]);
|
|
5696
|
-
/** Tool names that delegate or steer a child agent, beyond `subagent` itself. */
|
|
5697
|
-
const SUBAGENT_TOOLS = new Set([
|
|
5698
|
-
"send_message",
|
|
5699
|
-
"interrupt_agent",
|
|
5700
|
-
"list_agents",
|
|
5701
|
-
"ralph",
|
|
5702
|
-
"workflow",
|
|
5703
|
-
"spawn_teammate",
|
|
5704
|
-
"wait_agent"
|
|
5705
|
-
]);
|
|
5706
|
-
/** Tool names that plan or schedule work. */
|
|
5707
|
-
const TODO_TOOLS = new Set([
|
|
5708
|
-
"todo_write",
|
|
5709
|
-
"create_goal",
|
|
5710
|
-
"get_goal",
|
|
5711
|
-
"update_goal"
|
|
5712
|
-
]);
|
|
5713
|
-
/**
|
|
5714
|
-
* Tool-name prefixes per family, checked after the exact sets above. An MCP
|
|
5715
|
-
* or custom tool that keeps its family's prefix inherits the animation.
|
|
5716
|
-
*/
|
|
5717
|
-
const TOOL_PREFIXES = [
|
|
5718
|
-
["terminal_", "shell"],
|
|
5719
|
-
["session_", "search"],
|
|
5720
|
-
["cordis_inspect_", "search"],
|
|
5721
|
-
["list_mcp_", "search"],
|
|
5722
|
-
["read_mcp_", "search"],
|
|
5723
|
-
["team_task_", "subagent"],
|
|
5724
|
-
["schedule_", "todo"]
|
|
5725
|
-
];
|
|
5726
|
-
/** The activity line's label while a compaction condenses history. */
|
|
5727
|
-
const COMPACTING_ACTIVITY = "compacting";
|
|
5728
|
-
/**
|
|
5729
|
-
* The activity line's label for a streamed or executing tool call.
|
|
5730
|
-
* @param name - the tool name when one is known.
|
|
5731
|
-
* @returns `calling <name>`, or `calling` when the name has not arrived.
|
|
5732
|
-
*/
|
|
5733
|
-
function callingActivity(name) {
|
|
5734
|
-
return name ? `calling ${name}` : "calling";
|
|
5735
|
-
}
|
|
5736
|
-
/**
|
|
5737
|
-
* Whether the activity line already names a tool call.
|
|
5738
|
-
* @param activity - the activity line's current label.
|
|
5739
|
-
* @returns true for `calling` and `calling <name>`.
|
|
5908
|
+
* The glyphs of one spinner frame.
|
|
5909
|
+
* @param index - the frame number the clock reads.
|
|
5910
|
+
* @returns the run glyph and a member glyph staggered by sequence number.
|
|
5740
5911
|
*/
|
|
5741
|
-
function
|
|
5742
|
-
|
|
5912
|
+
function spinGlyphs(index) {
|
|
5913
|
+
const at = (frames, phase) => {
|
|
5914
|
+
/* v8 ignore next -- the modulo keeps the index inside the frame list */
|
|
5915
|
+
return frames[(index + phase) % 8] ?? frames[0];
|
|
5916
|
+
};
|
|
5917
|
+
return {
|
|
5918
|
+
run: at(WORKFLOW_SPINNER, 0),
|
|
5919
|
+
member: (seq) => at(TOOL_SPINNERS.subagent, Math.abs(seq) % 8)
|
|
5920
|
+
};
|
|
5921
|
+
}
|
|
5922
|
+
/** One run header in transcript colors. */
|
|
5923
|
+
function runRow(theme, run, spin) {
|
|
5924
|
+
const { palette } = theme;
|
|
5925
|
+
const count = memberCount(run);
|
|
5926
|
+
const glyph = spin === void 0 ? "◇" : spin.run;
|
|
5927
|
+
const bar = count === 0 ? "" : ` ${progressBar(palette, run)}`;
|
|
5928
|
+
return `${statusStyle(palette, run.status)(glyph)} ${palette.bold("workflow")} ${palette.link(run.name)} ${palette.dim(`· ${String(count)} member${count === 1 ? "" : "s"} · `)}${statusStyle(palette, run.status)(statusText(run.status))}${bar}`;
|
|
5929
|
+
}
|
|
5930
|
+
/**
|
|
5931
|
+
* A bar of {@link PROGRESS_CELLS} cells over the started members, settled
|
|
5932
|
+
* members first in their status colors and running members dim, followed by
|
|
5933
|
+
* the settled count.
|
|
5934
|
+
* @param palette - transcript colors.
|
|
5935
|
+
* @param run - the run drawn.
|
|
5936
|
+
* @returns the bar and `settled/total`.
|
|
5937
|
+
*/
|
|
5938
|
+
function progressBar(palette, run) {
|
|
5939
|
+
const progress = workflowProgress(run);
|
|
5940
|
+
const ordered = PROGRESS_ORDER.flatMap((status) => Array.from({ length: progress.counts[status] }, () => status));
|
|
5941
|
+
let bar = "";
|
|
5942
|
+
let pending;
|
|
5943
|
+
const flush = () => {
|
|
5944
|
+
if (pending === void 0) return;
|
|
5945
|
+
bar += pending.status === "running" ? palette.dim("─".repeat(pending.width)) : statusStyle(palette, pending.status)("━".repeat(pending.width));
|
|
5946
|
+
};
|
|
5947
|
+
for (let cell = 0; cell < PROGRESS_CELLS; cell += 1) {
|
|
5948
|
+
/* v8 ignore next -- the cell position stays inside the ordered members */
|
|
5949
|
+
const status = ordered[Math.floor((cell + .5) * progress.total / PROGRESS_CELLS)] ?? "running";
|
|
5950
|
+
if (pending?.status === status) {
|
|
5951
|
+
pending.width += 1;
|
|
5952
|
+
continue;
|
|
5953
|
+
}
|
|
5954
|
+
flush();
|
|
5955
|
+
pending = {
|
|
5956
|
+
status,
|
|
5957
|
+
width: 1
|
|
5958
|
+
};
|
|
5959
|
+
}
|
|
5960
|
+
flush();
|
|
5961
|
+
return `${bar} ${palette.dim(`${String(progress.settled)}/${String(progress.total)}`)}`;
|
|
5962
|
+
}
|
|
5963
|
+
/** One phase header in transcript colors. */
|
|
5964
|
+
function phaseRow(theme, phase) {
|
|
5965
|
+
const { palette } = theme;
|
|
5966
|
+
const count = phase.members.length;
|
|
5967
|
+
const mode = phaseFacts(phase).mode;
|
|
5968
|
+
const status = phase.members.find((member) => abnormal(member.status))?.status ?? (mode === "running" ? "running" : "completed");
|
|
5969
|
+
return ` ${statusStyle(palette, status)("▸")} ${palette.heading(workflowPhaseName(phase.phase))} ${palette.dim(`· ${String(count)} member${count === 1 ? "" : "s"} · `)}${statusStyle(palette, status)(phaseSummary(phase))}`;
|
|
5970
|
+
}
|
|
5971
|
+
/** One member row in transcript colors. */
|
|
5972
|
+
function memberRow(theme, member, openable, spin) {
|
|
5973
|
+
const { palette } = theme;
|
|
5974
|
+
const label = workflowMemberName(member.label);
|
|
5975
|
+
const name = openable ? palette.link(label) : label;
|
|
5976
|
+
const glyph = spin !== void 0 && member.status === "running" ? spin.member(member.seq) : "○";
|
|
5977
|
+
return ` ${statusStyle(palette, member.status)(glyph)} ${name} ${statusStyle(palette, member.status)(`[${statusText(member.status)}]`)}`;
|
|
5978
|
+
}
|
|
5979
|
+
/** Palette role for one workflow status. */
|
|
5980
|
+
function statusStyle(theme, status) {
|
|
5981
|
+
switch (status) {
|
|
5982
|
+
case "running": return theme.warning;
|
|
5983
|
+
case "completed": return theme.success;
|
|
5984
|
+
case "failed": return theme.error;
|
|
5985
|
+
case "cancelled":
|
|
5986
|
+
case "interrupted": return theme.warning;
|
|
5987
|
+
/* v8 ignore next -- WorkflowRunStatus is closed and every variant is handled above. */
|
|
5988
|
+
default: return status;
|
|
5989
|
+
}
|
|
5990
|
+
}
|
|
5991
|
+
/** Compare local liveness ids before rebuilding a member-row layout. */
|
|
5992
|
+
function sameIds(left, right) {
|
|
5993
|
+
if (left.size !== right.size) return false;
|
|
5994
|
+
for (const id of left) if (!right.has(id)) return false;
|
|
5995
|
+
return true;
|
|
5743
5996
|
}
|
|
5997
|
+
//#endregion
|
|
5998
|
+
//#region lib/types/workflow-panel.js
|
|
5999
|
+
/**
|
|
6000
|
+
* Rows of the `/workflows` pickers: one row per workflow run of the bound
|
|
6001
|
+
* session, one row per started member of a run, and a member's detail page.
|
|
6002
|
+
* Pure: the application reads the projections, the owning jobs, and the
|
|
6003
|
+
* openable children, and hands them in.
|
|
6004
|
+
* @module @deepseek-ai/dsh-tui-app/workflow-panel
|
|
6005
|
+
*/
|
|
6006
|
+
/** Dim row under the run picker's heading, naming its keys. */
|
|
6007
|
+
const WORKFLOWS_PICKER_HINT = "Enter lists the members · Ctrl+K stops a background run";
|
|
6008
|
+
/** Dim row under a member picker's heading, naming its keys. */
|
|
6009
|
+
const WORKFLOW_MEMBERS_HINT = "Enter opens a running member, or shows a settled one";
|
|
6010
|
+
/** Glyph each status row in the pickers starts with. */
|
|
6011
|
+
const STATUS_GLYPH = {
|
|
6012
|
+
running: "◇",
|
|
6013
|
+
completed: "✓",
|
|
6014
|
+
failed: "✗",
|
|
6015
|
+
cancelled: "⊘",
|
|
6016
|
+
interrupted: "⊘"
|
|
6017
|
+
};
|
|
5744
6018
|
/**
|
|
5745
|
-
*
|
|
5746
|
-
* @param
|
|
5747
|
-
*
|
|
5748
|
-
*
|
|
5749
|
-
* @returns the
|
|
5750
|
-
* `thinking` for any other label.
|
|
6019
|
+
* One run row of the run picker.
|
|
6020
|
+
* @param value - the run's picker value.
|
|
6021
|
+
* @param view - the run's newest projection.
|
|
6022
|
+
* @param jobId - the background job that owns the run, when one does.
|
|
6023
|
+
* @returns the picker row.
|
|
5751
6024
|
*/
|
|
5752
|
-
function
|
|
5753
|
-
|
|
5754
|
-
|
|
5755
|
-
|
|
5756
|
-
|
|
5757
|
-
|
|
6025
|
+
function workflowRunChoice(value, view, jobId) {
|
|
6026
|
+
return {
|
|
6027
|
+
value,
|
|
6028
|
+
label: `${STATUS_GLYPH[view.status]} ${view.name}`,
|
|
6029
|
+
description: [workflowRunSummary(view), ...jobId === void 0 ? [] : [`job ${jobId}`]].join(" · ")
|
|
6030
|
+
};
|
|
5758
6031
|
}
|
|
5759
6032
|
/**
|
|
5760
|
-
* The
|
|
5761
|
-
* @param
|
|
5762
|
-
* @returns
|
|
6033
|
+
* The status, settled members, and phase count of one run.
|
|
6034
|
+
* @param view - the run's newest projection.
|
|
6035
|
+
* @returns e.g. `running · 2/5 members settled · 2 phases`.
|
|
5763
6036
|
*/
|
|
5764
|
-
function
|
|
5765
|
-
|
|
5766
|
-
|
|
5767
|
-
|
|
5768
|
-
if (isSubagentTool(name) || SUBAGENT_TOOLS.has(name)) return "subagent";
|
|
5769
|
-
if (TODO_TOOLS.has(name)) return "todo";
|
|
5770
|
-
for (const [prefix, family] of TOOL_PREFIXES) if (name.startsWith(prefix)) return family;
|
|
5771
|
-
return "other";
|
|
6037
|
+
function workflowRunSummary(view) {
|
|
6038
|
+
const progress = workflowProgress(view);
|
|
6039
|
+
const phases = view.phases.length;
|
|
6040
|
+
return `${view.status} · ${String(progress.settled)}/${String(progress.total)} members settled · ${String(phases)} phase${phases === 1 ? "" : "s"}`;
|
|
5772
6041
|
}
|
|
5773
6042
|
/**
|
|
5774
|
-
*
|
|
5775
|
-
*
|
|
5776
|
-
*
|
|
5777
|
-
* @
|
|
5778
|
-
* @param now - the current time in milliseconds.
|
|
5779
|
-
* @param periodMs - how long each frame lasts, in milliseconds; positive.
|
|
5780
|
-
* @param phase - how many frames the indicator runs ahead of the clock, from 0 to {@link SPINNER_CYCLE} - 1.
|
|
5781
|
-
* @returns the frame at that instant.
|
|
6043
|
+
* One row per started member, in phase then start order.
|
|
6044
|
+
* @param view - the run's newest projection.
|
|
6045
|
+
* @param openable - direct children that are running in this process.
|
|
6046
|
+
* @returns the picker rows, each valued by the member's sequence number.
|
|
5782
6047
|
*/
|
|
5783
|
-
function
|
|
5784
|
-
|
|
5785
|
-
|
|
6048
|
+
function workflowMemberChoices(view, openable) {
|
|
6049
|
+
return view.phases.flatMap((phase) => phase.members.map((member) => ({
|
|
6050
|
+
value: String(member.seq),
|
|
6051
|
+
label: `${STATUS_GLYPH[member.status]} ${workflowMemberName(member.label)}`,
|
|
6052
|
+
description: [
|
|
6053
|
+
workflowPhaseName(phase.phase),
|
|
6054
|
+
member.status,
|
|
6055
|
+
...memberOpenable(member, openable) ? ["Enter opens"] : []
|
|
6056
|
+
].join(" · ")
|
|
6057
|
+
})));
|
|
6058
|
+
}
|
|
6059
|
+
/**
|
|
6060
|
+
* Find one member of a run by its picker value.
|
|
6061
|
+
* @param view - the run's newest projection.
|
|
6062
|
+
* @param value - the member row's value.
|
|
6063
|
+
* @returns the member and its phase title, or undefined when none matches.
|
|
6064
|
+
*/
|
|
6065
|
+
function findWorkflowMember(view, value) {
|
|
6066
|
+
for (const phase of view.phases) {
|
|
6067
|
+
const member = phase.members.find((candidate) => String(candidate.seq) === value);
|
|
6068
|
+
if (member !== void 0) return {
|
|
6069
|
+
member,
|
|
6070
|
+
phase: phase.phase
|
|
6071
|
+
};
|
|
6072
|
+
}
|
|
5786
6073
|
}
|
|
5787
6074
|
/**
|
|
5788
|
-
*
|
|
5789
|
-
*
|
|
5790
|
-
*
|
|
5791
|
-
*
|
|
5792
|
-
* farthest from its nearest neighbour first and the lowest on a tie; once
|
|
5793
|
-
* every phase is held, the lowest phase held by the fewest indicators.
|
|
5794
|
-
* @param taken - the phases of the indicators of that animation spinning now, one per indicator.
|
|
5795
|
-
* @returns a phase from 0 to {@link SPINNER_CYCLE} - 1.
|
|
6075
|
+
* Whether a member row can open its child Session as a live view.
|
|
6076
|
+
* @param member - the member.
|
|
6077
|
+
* @param openable - direct children that are running in this process.
|
|
6078
|
+
* @returns true while the member runs and its child is resident here.
|
|
5796
6079
|
*/
|
|
5797
|
-
function
|
|
5798
|
-
|
|
5799
|
-
let fewest = Number.POSITIVE_INFINITY;
|
|
5800
|
-
let widest = -1;
|
|
5801
|
-
for (let phase = 0; phase < 8; phase += 1) {
|
|
5802
|
-
let holders = 0;
|
|
5803
|
-
let gap = 8;
|
|
5804
|
-
for (const other of taken) {
|
|
5805
|
-
if (other === phase) holders += 1;
|
|
5806
|
-
const distance = Math.abs(phase - other);
|
|
5807
|
-
gap = Math.min(gap, distance, 8 - distance);
|
|
5808
|
-
}
|
|
5809
|
-
if (holders < fewest || holders === fewest && gap > widest) {
|
|
5810
|
-
best = phase;
|
|
5811
|
-
fewest = holders;
|
|
5812
|
-
widest = gap;
|
|
5813
|
-
}
|
|
5814
|
-
}
|
|
5815
|
-
return best;
|
|
6080
|
+
function memberOpenable(member, openable) {
|
|
6081
|
+
return member.status === "running" && openable.has(member.childId);
|
|
5816
6082
|
}
|
|
5817
6083
|
/**
|
|
5818
|
-
*
|
|
5819
|
-
*
|
|
5820
|
-
*
|
|
5821
|
-
*
|
|
5822
|
-
* @
|
|
5823
|
-
* @param text - the plain text to draw.
|
|
5824
|
-
* @param now - the current time in milliseconds.
|
|
5825
|
-
* @param periodMs - how long the sweep rests on each character, in milliseconds; positive.
|
|
5826
|
-
* @returns the styled text, the same visible width as `text`.
|
|
6084
|
+
* The detail page of one member.
|
|
6085
|
+
* @param view - the run the member belongs to.
|
|
6086
|
+
* @param member - the member.
|
|
6087
|
+
* @param phase - the member's phase title, or null when its start omitted one.
|
|
6088
|
+
* @returns the page rows.
|
|
5827
6089
|
*/
|
|
5828
|
-
function
|
|
5829
|
-
|
|
5830
|
-
|
|
5831
|
-
|
|
5832
|
-
|
|
5833
|
-
|
|
5834
|
-
|
|
5835
|
-
|
|
5836
|
-
let run = "";
|
|
5837
|
-
let current;
|
|
5838
|
-
const flush = () => {
|
|
5839
|
-
if (current === void 0 || run === "") return;
|
|
5840
|
-
out += current === "bright" ? palette.bold(run) : current === "plain" ? run : palette.dim(run);
|
|
5841
|
-
run = "";
|
|
5842
|
-
};
|
|
5843
|
-
for (const [index, char] of chars.entries()) {
|
|
5844
|
-
const next = tone(index);
|
|
5845
|
-
if (next !== current) {
|
|
5846
|
-
flush();
|
|
5847
|
-
current = next;
|
|
5848
|
-
}
|
|
5849
|
-
run += char;
|
|
5850
|
-
}
|
|
5851
|
-
flush();
|
|
5852
|
-
return out;
|
|
6090
|
+
function workflowMemberDetail(view, member, phase) {
|
|
6091
|
+
return [
|
|
6092
|
+
`workflow ${view.name} (${view.status})`,
|
|
6093
|
+
`phase ${workflowPhaseName(phase)}`,
|
|
6094
|
+
`member #${String(member.seq)} ${workflowMemberName(member.label)}`,
|
|
6095
|
+
`status ${member.status}`,
|
|
6096
|
+
`child ${member.childId}`
|
|
6097
|
+
];
|
|
5853
6098
|
}
|
|
5854
6099
|
//#endregion
|
|
5855
6100
|
//#region lib/types/completion.js
|
|
@@ -12984,7 +13229,10 @@ var ToastPane = class {
|
|
|
12984
13229
|
* latest descendant line, and a live line while background jobs run; `Ctrl+B`
|
|
12985
13230
|
* moves the running tool calls to those jobs (`./background.ts`). A top-level
|
|
12986
13231
|
* workflow call draws a run beside its tool card: the name, member count,
|
|
12987
|
-
* status, phases, and started members
|
|
13232
|
+
* status, a member progress bar, phases, and started members, with running
|
|
13233
|
+
* glyphs stepping on the spinner tick (`./workflow-block.ts`); `/workflows`
|
|
13234
|
+
* walks the runs and their members and stops a background run
|
|
13235
|
+
* (`./workflow-panel.ts`). Under the
|
|
12988
13236
|
* editor it keeps two docked regions the keyboard can take over — the
|
|
12989
13237
|
* subagent panel and the status bar — and one repeating tick advances their
|
|
12990
13238
|
* elapsed counters and the jobs line's, and re-reads a stale subagent
|
|
@@ -13234,6 +13482,11 @@ const LOCAL_COMMANDS = [
|
|
|
13234
13482
|
name: "jobs",
|
|
13235
13483
|
description: "Browse this session's background jobs (Enter shows the output, Ctrl+K stops one; Ctrl+B moves running tool calls here)"
|
|
13236
13484
|
},
|
|
13485
|
+
{
|
|
13486
|
+
name: "workflows",
|
|
13487
|
+
description: "Browse this session's workflow runs (Enter lists a run's members and opens a running one, Ctrl+K stops a background run; /workflows <name> opens that run)",
|
|
13488
|
+
hint: "[name]"
|
|
13489
|
+
},
|
|
13237
13490
|
{
|
|
13238
13491
|
name: "parent",
|
|
13239
13492
|
description: "Return from a subagent view or a /btw side agent to the session it was opened from"
|
|
@@ -13381,6 +13634,8 @@ var TuiApp = class {
|
|
|
13381
13634
|
workflowCalls = /* @__PURE__ */ new Map();
|
|
13382
13635
|
/** Process-local ownership for unfinished-run interpretation after replay. */
|
|
13383
13636
|
workflowOwners = /* @__PURE__ */ new Map();
|
|
13637
|
+
/** Workflow blocks whose running glyphs step on the spinner tick. */
|
|
13638
|
+
workflowSpinners = /* @__PURE__ */ new Set();
|
|
13384
13639
|
/** The global fold action has not chosen a workflow default until the first `Ctrl+O`. */
|
|
13385
13640
|
workflowExpanded;
|
|
13386
13641
|
toolArguments = /* @__PURE__ */ new Map();
|
|
@@ -13817,6 +14072,7 @@ var TuiApp = class {
|
|
|
13817
14072
|
this.workflowStates.clear();
|
|
13818
14073
|
this.workflowCalls.clear();
|
|
13819
14074
|
this.workflowOwners.clear();
|
|
14075
|
+
this.workflowSpinners.clear();
|
|
13820
14076
|
this.toolArguments.clear();
|
|
13821
14077
|
this.toolStreamArgs.clear();
|
|
13822
14078
|
this.unconfirmedTools.clear();
|
|
@@ -14743,6 +14999,116 @@ var TuiApp = class {
|
|
|
14743
14999
|
this.showToast(outcome === "requested" ? `stopping ${view.id}` : `${view.id} already finished`);
|
|
14744
15000
|
}
|
|
14745
15001
|
/**
|
|
15002
|
+
* Walk the bound session's workflow runs, newest last: `Enter` lists a
|
|
15003
|
+
* run's members and `Ctrl+K` stops a background run. The rows are read
|
|
15004
|
+
* again each time the list opens, so a return from the members shows the
|
|
15005
|
+
* statuses as they are now.
|
|
15006
|
+
* @param name - a run name to open directly; empty opens the run list.
|
|
15007
|
+
*/
|
|
15008
|
+
async browseWorkflows(name) {
|
|
15009
|
+
if (name !== "") {
|
|
15010
|
+
const match = [...this.workflowBlocks].findLast(([, block]) => block.view.name === name);
|
|
15011
|
+
if (match === void 0) {
|
|
15012
|
+
this.notice(`no workflow run named ${name} in this session`, "error");
|
|
15013
|
+
return;
|
|
15014
|
+
}
|
|
15015
|
+
await this.browseWorkflowMembers(match[0]);
|
|
15016
|
+
return;
|
|
15017
|
+
}
|
|
15018
|
+
let visited;
|
|
15019
|
+
for (;;) {
|
|
15020
|
+
const runs = [...this.workflowBlocks];
|
|
15021
|
+
if (runs.length === 0) {
|
|
15022
|
+
this.notice("no workflow runs in this session");
|
|
15023
|
+
return;
|
|
15024
|
+
}
|
|
15025
|
+
const choices = runs.map(([runId, block], index) => workflowRunChoice(String(index), block.view, this.workflowOwners.get(runId)?.jobId));
|
|
15026
|
+
const picked = await this.showModal(new PickPrompt(this.deps.palette, "Workflow runs", choices, {
|
|
15027
|
+
body: [WORKFLOWS_PICKER_HINT],
|
|
15028
|
+
...visited === void 0 ? {} : { current: visited },
|
|
15029
|
+
onStop: (item) => {
|
|
15030
|
+
const run = runs[Number(item.value)];
|
|
15031
|
+
/* v8 ignore next -- the picker answers with one of the rows it was handed */
|
|
15032
|
+
if (run !== void 0) this.stopWorkflow(run[0]);
|
|
15033
|
+
}
|
|
15034
|
+
}));
|
|
15035
|
+
const run = picked === void 0 ? void 0 : runs[Number(picked.value)];
|
|
15036
|
+
if (picked === void 0 || run === void 0) return;
|
|
15037
|
+
visited = picked.value;
|
|
15038
|
+
if (await this.browseWorkflowMembers(run[0])) return;
|
|
15039
|
+
}
|
|
15040
|
+
}
|
|
15041
|
+
/**
|
|
15042
|
+
* Walk one run's started members: `Enter` on a running member whose child
|
|
15043
|
+
* runs here opens it as a live view, and on any other member shows its
|
|
15044
|
+
* detail page.
|
|
15045
|
+
* @param runId - the run to walk.
|
|
15046
|
+
* @returns true when a member opened, which leaves every picker.
|
|
15047
|
+
*/
|
|
15048
|
+
async browseWorkflowMembers(runId) {
|
|
15049
|
+
let visited;
|
|
15050
|
+
for (;;) {
|
|
15051
|
+
const block = this.workflowBlocks.get(runId);
|
|
15052
|
+
/* v8 ignore next -- a session switch closes the pickers before it clears the blocks */
|
|
15053
|
+
if (block === void 0) return false;
|
|
15054
|
+
const view = block.view;
|
|
15055
|
+
const heading = `Workflow ${view.name}`;
|
|
15056
|
+
const openable = this.liveDirectChildren();
|
|
15057
|
+
const choices = workflowMemberChoices(view, openable);
|
|
15058
|
+
if (choices.length === 0) {
|
|
15059
|
+
await this.showModal(new DetailPrompt(this.deps.palette, heading, [
|
|
15060
|
+
workflowRunSummary(view),
|
|
15061
|
+
"",
|
|
15062
|
+
"no member has started yet"
|
|
15063
|
+
]));
|
|
15064
|
+
return false;
|
|
15065
|
+
}
|
|
15066
|
+
const picked = await this.showModal(new PickPrompt(this.deps.palette, heading, choices, {
|
|
15067
|
+
body: [workflowRunSummary(view), WORKFLOW_MEMBERS_HINT],
|
|
15068
|
+
...visited === void 0 ? {} : { current: visited }
|
|
15069
|
+
}));
|
|
15070
|
+
const found = picked === void 0 ? void 0 : findWorkflowMember(view, picked.value);
|
|
15071
|
+
if (picked === void 0 || found === void 0) return false;
|
|
15072
|
+
visited = picked.value;
|
|
15073
|
+
if (memberOpenable(found.member, openable)) {
|
|
15074
|
+
await this.openWorkflowMember({
|
|
15075
|
+
childId: found.member.childId,
|
|
15076
|
+
label: found.member.label
|
|
15077
|
+
});
|
|
15078
|
+
return true;
|
|
15079
|
+
}
|
|
15080
|
+
await this.showModal(new DetailPrompt(this.deps.palette, `Member ${found.member.label}`, workflowMemberDetail(view, found.member, found.phase)));
|
|
15081
|
+
}
|
|
15082
|
+
}
|
|
15083
|
+
/**
|
|
15084
|
+
* Stop one workflow run from `/workflows`: a background run stops through
|
|
15085
|
+
* its job, and a run inside the turn names the key that stops the turn.
|
|
15086
|
+
* @param runId - the highlighted run.
|
|
15087
|
+
*/
|
|
15088
|
+
stopWorkflow(runId) {
|
|
15089
|
+
const view = this.workflowBlocks.get(runId)?.view;
|
|
15090
|
+
/* v8 ignore next -- the picker lists only drawn runs */
|
|
15091
|
+
if (view === void 0) return;
|
|
15092
|
+
if (view.status !== "running") {
|
|
15093
|
+
this.showToast(`workflow ${view.name} already finished`);
|
|
15094
|
+
return;
|
|
15095
|
+
}
|
|
15096
|
+
const owner = this.workflowOwners.get(runId);
|
|
15097
|
+
const jobs = this.deps.ctx.get("jobs");
|
|
15098
|
+
if (owner?.background !== true || owner.jobId === void 0 || jobs === void 0) {
|
|
15099
|
+
this.showToast(`workflow ${view.name} runs inside the turn · Esc twice stops the turn`);
|
|
15100
|
+
return;
|
|
15101
|
+
}
|
|
15102
|
+
let outcome;
|
|
15103
|
+
try {
|
|
15104
|
+
outcome = jobs.kill(owner.jobId, this.agent.session.id, USER_STOP_REASON);
|
|
15105
|
+
} catch (error) {
|
|
15106
|
+
this.showToast(`could not stop workflow ${view.name}: ${describeFailure(error)}`);
|
|
15107
|
+
return;
|
|
15108
|
+
}
|
|
15109
|
+
this.showToast(outcome === "requested" ? `stopping workflow ${view.name}` : `workflow ${view.name} already finished`);
|
|
15110
|
+
}
|
|
15111
|
+
/**
|
|
14746
15112
|
* Walk the agent's todo list: one row per item, and entering a row shows
|
|
14747
15113
|
* that item in full with its position, the list's counts by status, and the
|
|
14748
15114
|
* turns it was first written in and last changed status in.
|
|
@@ -16056,6 +16422,9 @@ var TuiApp = class {
|
|
|
16056
16422
|
case "jobs":
|
|
16057
16423
|
await this.browseJobs();
|
|
16058
16424
|
return;
|
|
16425
|
+
case "workflows":
|
|
16426
|
+
await this.browseWorkflows(argument);
|
|
16427
|
+
return;
|
|
16059
16428
|
case "settings":
|
|
16060
16429
|
await this.settings(argument);
|
|
16061
16430
|
return;
|
|
@@ -16908,7 +17277,8 @@ var TuiApp = class {
|
|
|
16908
17277
|
* stopped app runs none.
|
|
16909
17278
|
*/
|
|
16910
17279
|
updateSpinTicker() {
|
|
16911
|
-
|
|
17280
|
+
const spinning = this.spinners.size > 0 || this.boardSpinners.size > 0 || this.workflowSpinners.size > 0;
|
|
17281
|
+
if (!this.stopped && (this.loaderAnimates() || spinning)) {
|
|
16912
17282
|
this.spinTicker ??= this.deps.tick(() => {
|
|
16913
17283
|
this.onSpinTick();
|
|
16914
17284
|
}, this.deps.spinnerMs);
|
|
@@ -16927,9 +17297,10 @@ var TuiApp = class {
|
|
|
16927
17297
|
*/
|
|
16928
17298
|
onSpinTick() {
|
|
16929
17299
|
for (const block of this.spinners.keys()) if (!block.spinning()) this.spinners.delete(block);
|
|
17300
|
+
for (const block of this.workflowSpinners) if (!block.spinning()) this.workflowSpinners.delete(block);
|
|
16930
17301
|
if (this.loaderAnimates()) this.refreshLoader();
|
|
16931
17302
|
if (this.boardSpinners.size > 0) this.refreshActivityBoard();
|
|
16932
|
-
else if (this.spinners.size > 0) this.tui.requestRender();
|
|
17303
|
+
else if (this.spinners.size > 0 || this.workflowSpinners.size > 0) this.tui.requestRender();
|
|
16933
17304
|
this.updateSpinTicker();
|
|
16934
17305
|
}
|
|
16935
17306
|
/**
|
|
@@ -17398,6 +17769,7 @@ var TuiApp = class {
|
|
|
17398
17769
|
block.setOpenableChildren(this.liveDirectChildren());
|
|
17399
17770
|
this.workflowBlocks.set(runId, block);
|
|
17400
17771
|
this.chat.addChild(block);
|
|
17772
|
+
if (!this.replaying) this.spinWorkflow(block);
|
|
17401
17773
|
return;
|
|
17402
17774
|
}
|
|
17403
17775
|
existing.setOpenableChildren(this.liveDirectChildren());
|
|
@@ -17409,11 +17781,27 @@ var TuiApp = class {
|
|
|
17409
17781
|
*/
|
|
17410
17782
|
finishWorkflowReplay() {
|
|
17411
17783
|
for (const [runId, state] of this.workflowStates) {
|
|
17412
|
-
if (state.stopReason !== void 0
|
|
17413
|
-
this.workflowBlocks.get(runId)
|
|
17784
|
+
if (state.stopReason !== void 0) continue;
|
|
17785
|
+
const block = this.workflowBlocks.get(runId);
|
|
17786
|
+
if (this.workflowOwnedLive(runId)) {
|
|
17787
|
+
if (block !== void 0) this.spinWorkflow(block);
|
|
17788
|
+
continue;
|
|
17789
|
+
}
|
|
17790
|
+
block?.setData(projectWorkflowRun(state, { markUnfinishedInterrupted: true }));
|
|
17414
17791
|
}
|
|
17415
17792
|
}
|
|
17416
17793
|
/**
|
|
17794
|
+
* Step a running workflow block's glyphs on the spinner tick until its run
|
|
17795
|
+
* settles. Every block under reduced motion draws the static glyphs.
|
|
17796
|
+
* @param block - a block whose run is running.
|
|
17797
|
+
*/
|
|
17798
|
+
spinWorkflow(block) {
|
|
17799
|
+
if (this.deps.reducedMotion || block.view.status !== "running") return;
|
|
17800
|
+
block.setSpinner(() => Math.floor(this.deps.now() / this.deps.spinnerMs));
|
|
17801
|
+
this.workflowSpinners.add(block);
|
|
17802
|
+
this.updateSpinTicker();
|
|
17803
|
+
}
|
|
17804
|
+
/**
|
|
17417
17805
|
* Whether a background workflow is still owned by a live job in this process.
|
|
17418
17806
|
* @param runId - the durable run.
|
|
17419
17807
|
* @returns true while that job is running or stopping.
|