@songtonyli/dsh-cli 0.1.64 → 0.1.66

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.
Files changed (91) hide show
  1. package/README.md +1 -1
  2. package/bin/dsh.mjs +1 -1
  3. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/package.json +2 -2
  4. package/node_modules/@deepseek-ai/dsh-client-ui-sidebar/lib/client.js +1 -1
  5. package/node_modules/@deepseek-ai/dsh-otel/node_modules/@opentelemetry/resources/build/esm/version.js +1 -1
  6. package/node_modules/@deepseek-ai/dsh-otel/node_modules/@opentelemetry/resources/build/esnext/version.js +1 -1
  7. package/node_modules/@deepseek-ai/dsh-otel/node_modules/@opentelemetry/resources/build/src/version.js +1 -1
  8. package/node_modules/@deepseek-ai/dsh-otel/node_modules/@opentelemetry/resources/node_modules/@opentelemetry/core/build/esm/version.js +1 -1
  9. package/node_modules/@deepseek-ai/dsh-otel/node_modules/@opentelemetry/resources/node_modules/@opentelemetry/core/build/esnext/version.js +1 -1
  10. package/node_modules/@deepseek-ai/dsh-otel/node_modules/@opentelemetry/resources/node_modules/@opentelemetry/core/build/src/version.js +1 -1
  11. package/node_modules/@deepseek-ai/dsh-otel/node_modules/@opentelemetry/resources/node_modules/@opentelemetry/core/package.json +2 -2
  12. package/node_modules/@deepseek-ai/dsh-otel/node_modules/@opentelemetry/resources/package.json +3 -3
  13. package/node_modules/@deepseek-ai/dsh-sandbox/README.i18n.yaml +2 -2
  14. package/node_modules/@deepseek-ai/dsh-sandbox/README.md +1 -1
  15. package/node_modules/@deepseek-ai/dsh-sandbox/README.zh.md +1 -1
  16. package/node_modules/@deepseek-ai/dsh-sandbox/lib/index.js +13 -4
  17. package/node_modules/@deepseek-ai/dsh-sandbox-apple-container/README.i18n.yaml +2 -2
  18. package/node_modules/@deepseek-ai/dsh-sandbox-apple-container/README.md +2 -2
  19. package/node_modules/@deepseek-ai/dsh-sandbox-apple-container/README.zh.md +2 -2
  20. package/node_modules/@deepseek-ai/dsh-sandbox-apple-container/lib/index.js +14 -1
  21. package/node_modules/@deepseek-ai/dsh-tool-bash/lib/index.js +3 -1
  22. package/node_modules/@deepseek-ai/dsh-tui-app/README.md +3 -2
  23. package/node_modules/@deepseek-ai/dsh-tui-app/README.zh.md +3 -2
  24. package/node_modules/@deepseek-ai/dsh-tui-app/lib/index.js +977 -16
  25. package/node_modules/@deepseek-ai/dsh-tui-app/package.json +2 -0
  26. package/node_modules/execa/lib/arguments/command-file.js +55 -23
  27. package/node_modules/execa/lib/arguments/command.js +2 -1
  28. package/node_modules/execa/lib/arguments/cwd.js +10 -6
  29. package/node_modules/execa/lib/arguments/encoding-option.js +11 -0
  30. package/node_modules/execa/lib/arguments/escape.js +2 -2
  31. package/node_modules/execa/lib/arguments/fd-options.js +3 -7
  32. package/node_modules/execa/lib/arguments/options.js +13 -3
  33. package/node_modules/execa/lib/arguments/specific.js +2 -1
  34. package/node_modules/execa/lib/convert/duplex.js +3 -1
  35. package/node_modules/execa/lib/convert/iterable.js +3 -5
  36. package/node_modules/execa/lib/convert/readable.js +3 -1
  37. package/node_modules/execa/lib/convert/writable.js +8 -4
  38. package/node_modules/execa/lib/io/contents.js +8 -11
  39. package/node_modules/execa/lib/io/input-sync.js +8 -5
  40. package/node_modules/execa/lib/io/max-buffer.js +41 -28
  41. package/node_modules/execa/lib/io/output-sync.js +64 -40
  42. package/node_modules/execa/lib/io/strip-newline.js +4 -3
  43. package/node_modules/execa/lib/ipc/buffer-messages.js +12 -2
  44. package/node_modules/execa/lib/ipc/get-each.js +8 -2
  45. package/node_modules/execa/lib/ipc/get-one.js +3 -1
  46. package/node_modules/execa/lib/ipc/graceful.js +3 -2
  47. package/node_modules/execa/lib/ipc/incoming.js +10 -3
  48. package/node_modules/execa/lib/ipc/ipc-input.js +7 -2
  49. package/node_modules/execa/lib/ipc/send.js +3 -1
  50. package/node_modules/execa/lib/ipc/strict.js +13 -7
  51. package/node_modules/execa/lib/ipc/validation.js +1 -1
  52. package/node_modules/execa/lib/methods/bind.js +2 -8
  53. package/node_modules/execa/lib/methods/create.js +3 -1
  54. package/node_modules/execa/lib/methods/main-async.js +21 -11
  55. package/node_modules/execa/lib/methods/main-sync.js +7 -5
  56. package/node_modules/execa/lib/methods/node.js +1 -1
  57. package/node_modules/execa/lib/methods/script.js +1 -1
  58. package/node_modules/execa/lib/methods/template.js +24 -5
  59. package/node_modules/execa/lib/pipe/pipe-arguments.js +36 -5
  60. package/node_modules/execa/lib/pipe/throw.js +5 -3
  61. package/node_modules/execa/lib/resolve/all-async.js +43 -19
  62. package/node_modules/execa/lib/resolve/all-sync.js +27 -15
  63. package/node_modules/execa/lib/resolve/exit-sync.js +13 -5
  64. package/node_modules/execa/lib/resolve/stdio.js +2 -1
  65. package/node_modules/execa/lib/resolve/wait-stream.js +12 -2
  66. package/node_modules/execa/lib/resolve/wait-subprocess.js +3 -1
  67. package/node_modules/execa/lib/return/early-error.js +58 -21
  68. package/node_modules/execa/lib/return/message.js +2 -10
  69. package/node_modules/execa/lib/return/reject.js +1 -1
  70. package/node_modules/execa/lib/stdio/direction.js +36 -5
  71. package/node_modules/execa/lib/stdio/duplicate.js +26 -16
  72. package/node_modules/execa/lib/stdio/handle-async.js +6 -0
  73. package/node_modules/execa/lib/stdio/handle-sync.js +5 -3
  74. package/node_modules/execa/lib/stdio/handle.js +47 -24
  75. package/node_modules/execa/lib/stdio/native.js +3 -6
  76. package/node_modules/execa/lib/stdio/stdio-option.js +13 -18
  77. package/node_modules/execa/lib/stdio/type.js +2 -10
  78. package/node_modules/execa/lib/terminate/cancel.js +7 -0
  79. package/node_modules/execa/lib/terminate/kill-descendants.js +20 -4
  80. package/node_modules/execa/lib/transform/encoding-transform.js +15 -0
  81. package/node_modules/execa/lib/transform/generator.js +13 -2
  82. package/node_modules/execa/lib/transform/split.js +37 -23
  83. package/node_modules/execa/lib/utils/options.js +9 -0
  84. package/node_modules/execa/lib/utils/standard-stream.js +6 -0
  85. package/node_modules/execa/lib/utils/uint-array.js +1 -7
  86. package/node_modules/execa/lib/verbose/log.js +3 -6
  87. package/node_modules/execa/lib/verbose/output.js +3 -1
  88. package/node_modules/execa/package.json +51 -48
  89. package/node_modules/http-cache-semantics/index.js +32 -9
  90. package/node_modules/http-cache-semantics/package.json +3 -3
  91. package/package.json +3 -3
@@ -13,6 +13,7 @@ import "@deepseek-ai/cordis";
13
13
  import { activeAtToken, formatFileMention } from "@deepseek-ai/dsh-file-reference";
14
14
  import { formatSessionReferenceMention } from "@deepseek-ai/dsh-session-reference";
15
15
  import { AppleContainerSandboxProvider } from "@deepseek-ai/dsh-sandbox-apple-container";
16
+ import { JobId } from "@deepseek-ai/dsh-jobs";
16
17
  import { assertNever } from "@deepseek-ai/dsh-util-values";
17
18
  import { readFile } from "node:fs/promises";
18
19
  import { basename, extname, join, resolve } from "node:path";
@@ -644,6 +645,36 @@ function hunks(lines, context) {
644
645
  return out;
645
646
  }
646
647
  //#endregion
648
+ //#region lib/types/stream-args.js
649
+ /**
650
+ * Lines for a generic card's raw input when the presenter supplied no content.
651
+ * A todo list becomes one status line per item. A string is the program or path.
652
+ * @param value - the presenter's raw input.
653
+ * @returns the lines, empty when the value is absent or an empty string.
654
+ */
655
+ function rawInputLines(value) {
656
+ if (value === void 0) return [];
657
+ if (typeof value === "string") return value === "" ? [] : value.split("\n");
658
+ if (typeof value === "number" || typeof value === "boolean") return [String(value)];
659
+ const todos = todoLines$1(value);
660
+ if (todos !== void 0) return todos;
661
+ if (Array.isArray(value) && value.every((item) => typeof item === "string")) return value.flatMap((item) => item === "" ? [] : item.split("\n"));
662
+ const text = JSON.stringify(value);
663
+ return text === void 0 ? [] : [text];
664
+ }
665
+ /** One status line per todo item, or undefined when the value is not a todo list. */
666
+ function todoLines$1(value) {
667
+ if (!Array.isArray(value)) return void 0;
668
+ const lines = [];
669
+ for (const item of value) {
670
+ if (typeof item !== "object" || item === null) return void 0;
671
+ if (!("content" in item) || !("status" in item)) return void 0;
672
+ if (typeof item.content !== "string" || typeof item.status !== "string") return void 0;
673
+ lines.push(`${item.status} ${item.content}`);
674
+ }
675
+ return lines;
676
+ }
677
+ //#endregion
647
678
  //#region lib/types/transcript.js
648
679
  /**
649
680
  * Pure transcript formatting: durable session facts and tool presentation
@@ -1033,8 +1064,7 @@ function toolCallText(argumentsJson, view, toolName) {
1033
1064
  }
1034
1065
  switch (view.card) {
1035
1066
  case "generic": {
1036
- const lines = [];
1037
- if (view.content !== void 0) lines.push(...contentText(view.content).split("\n"));
1067
+ const lines = view.content === void 0 ? rawInputLines(view.rawInput) : contentText(view.content).split("\n");
1038
1068
  return {
1039
1069
  title: cardHeadline(toolName, view.title),
1040
1070
  lines
@@ -3623,11 +3653,11 @@ function editorTheme(palette) {
3623
3653
  * @module @deepseek-ai/dsh-tui-app/blocks
3624
3654
  */
3625
3655
  /** Columns the focus gutter takes from the width a block's content wraps at. */
3626
- const GUTTER_WIDTH = 2;
3656
+ const GUTTER_WIDTH$1 = 2;
3627
3657
  /** The gutter beside the lines of a focused block that are not the focused section. */
3628
- const BLOCK_GUTTER = "│ ";
3658
+ const BLOCK_GUTTER$1 = "│ ";
3629
3659
  /** The gutter beside the lines of the focused section itself. */
3630
- const PART_GUTTER = "┃ ";
3660
+ const PART_GUTTER$1 = "┃ ";
3631
3661
  /** What the call section reports for a tool the model called with no arguments. */
3632
3662
  const NO_ARGUMENTS = "(no arguments)";
3633
3663
  /** What the result section reports for a tool that answered with nothing. */
@@ -3664,7 +3694,7 @@ function focusFrame(width, highlight) {
3664
3694
  const marked = highlight !== void 0;
3665
3695
  return {
3666
3696
  marked,
3667
- content: marked ? Math.max(1, width - GUTTER_WIDTH) : width
3697
+ content: marked ? Math.max(1, width - GUTTER_WIDTH$1) : width
3668
3698
  };
3669
3699
  }
3670
3700
  /**
@@ -3678,8 +3708,8 @@ function focusFrame(width, highlight) {
3678
3708
  * @returns the lines behind their gutter.
3679
3709
  */
3680
3710
  function withGutter(palette, lines, focused, level) {
3681
- const mark = pulse(palette, palette.accent(PART_GUTTER), level);
3682
- return lines.map((line, index) => `${focused(index) ? mark : palette.dim(BLOCK_GUTTER)}${line}`);
3711
+ const mark = pulse(palette, palette.accent(PART_GUTTER$1), level);
3712
+ return lines.map((line, index) => `${focused(index) ? mark : palette.dim(BLOCK_GUTTER$1)}${line}`);
3683
3713
  }
3684
3714
  /**
3685
3715
  * Which lines of a folded block the focus mark is drawn beside: the focused
@@ -4818,6 +4848,685 @@ function fadingInSpans(fade) {
4818
4848
  function floatingOutSpans(fade) {
4819
4849
  return fade.spans().filter((span) => span.age < fade.steps);
4820
4850
  }
4851
+ //#endregion
4852
+ //#region lib/types/workflow-block.js
4853
+ /**
4854
+ * Foldable terminal rendering for one durable workflow run. It keeps run and
4855
+ * phase disclosure choices local while the application owns durable replay and
4856
+ * child-session liveness.
4857
+ * @module @deepseek-ai/dsh-tui-app/workflow-block
4858
+ */
4859
+ /** Columns the focus gutter takes from this block's content. */
4860
+ const GUTTER_WIDTH = 2;
4861
+ /** Gutter beside an unfocused section of a focused workflow block. */
4862
+ const BLOCK_GUTTER = "│ ";
4863
+ /** Gutter beside the focused workflow section. */
4864
+ const PART_GUTTER = "┃ ";
4865
+ /**
4866
+ * One workflow run in the transcript. The block's source state can advance
4867
+ * while its already-written scrollback stays frozen; reader and inspector rows
4868
+ * always read the newest durable projection.
4869
+ */
4870
+ var WorkflowBlock = class {
4871
+ theme;
4872
+ turn;
4873
+ navigable = true;
4874
+ blockKind = "workflow";
4875
+ foldable = true;
4876
+ /** Data used by reader, inspector, navigation, and child opening. */
4877
+ source;
4878
+ /** Data currently safe to rewrite in the terminal transcript. */
4879
+ displayed;
4880
+ runDisclosure;
4881
+ phaseDisclosures = /* @__PURE__ */ new Map();
4882
+ openableChildren = /* @__PURE__ */ new Set();
4883
+ highlight;
4884
+ highlightLevel = 0;
4885
+ repaintLocked = false;
4886
+ /** Child ids received while the block cannot safely redraw. */
4887
+ pendingOpenable;
4888
+ /** Clean collapse deferred until the block can be redrawn. */
4889
+ pendingCollapse = false;
4890
+ /** Focus mark received while the block cannot safely redraw. */
4891
+ pendingHighlight;
4892
+ revision = 0;
4893
+ drawn;
4894
+ /**
4895
+ * @param theme - terminal palette shared with transcript blocks.
4896
+ * @param initial - durable run projection at insertion.
4897
+ * @param turn - turn that recorded the run start.
4898
+ */
4899
+ constructor(theme, initial, turn) {
4900
+ this.theme = theme;
4901
+ this.turn = turn;
4902
+ this.source = initial;
4903
+ this.displayed = initial;
4904
+ this.runDisclosure = initialDisclosure(runFacts(initial));
4905
+ this.syncPhaseDisclosures(initial);
4906
+ }
4907
+ /** Durable name read by transcript navigation. */
4908
+ get name() {
4909
+ return this.source.name;
4910
+ }
4911
+ /**
4912
+ * Replace the durable rendering projection. A block above the repaint window
4913
+ * keeps its earlier transcript rows until the next safe redraw.
4914
+ * @param next - latest folded workflow data.
4915
+ */
4916
+ setData(next) {
4917
+ this.source = next;
4918
+ if (this.repaintLocked) return;
4919
+ this.reconcileDisclosures(next);
4920
+ this.displayed = next;
4921
+ this.changed();
4922
+ }
4923
+ /**
4924
+ * Replace the direct child ids that may be opened from currently running
4925
+ * member rows.
4926
+ * @param ids - locally resident direct children of the bound session.
4927
+ */
4928
+ setOpenableChildren(ids) {
4929
+ if (this.repaintLocked) {
4930
+ if (sameIds(this.pendingOpenable ?? this.openableChildren, ids)) return;
4931
+ this.pendingOpenable = ids;
4932
+ return;
4933
+ }
4934
+ this.pendingOpenable = void 0;
4935
+ if (sameIds(this.openableChildren, ids)) return;
4936
+ this.openableChildren = new Set(ids);
4937
+ this.changed();
4938
+ }
4939
+ /**
4940
+ * Keep presentation updates out of immutable terminal scrollback, then apply
4941
+ * deferred updates when the whole block can be redrawn safely.
4942
+ * @param floor - first block line the renderer may repaint.
4943
+ * @returns true when a deferred projection became drawable.
4944
+ */
4945
+ setRepaintFloor(floor) {
4946
+ if (floor > 0) {
4947
+ this.repaintLocked = true;
4948
+ return false;
4949
+ }
4950
+ if (!this.repaintLocked) return false;
4951
+ this.repaintLocked = false;
4952
+ return this.applyDeferred();
4953
+ }
4954
+ /** Whether the run body is currently visible. */
4955
+ isExpanded() {
4956
+ return this.runDisclosure.open;
4957
+ }
4958
+ /**
4959
+ * Expand or collapse the run and every currently known phase. This is the
4960
+ * all-block action used by `Ctrl+O`.
4961
+ * @param expanded - whether every level should draw its members.
4962
+ */
4963
+ setExpanded(expanded) {
4964
+ this.repaintLocked = false;
4965
+ this.pendingCollapse = false;
4966
+ let changed = false;
4967
+ if (this.pendingOpenable !== void 0) {
4968
+ this.openableChildren = new Set(this.pendingOpenable);
4969
+ this.pendingOpenable = void 0;
4970
+ changed = true;
4971
+ }
4972
+ if (this.pendingHighlight !== void 0) {
4973
+ this.highlight = this.pendingHighlight.part;
4974
+ this.highlightLevel = this.pendingHighlight.level;
4975
+ this.pendingHighlight = void 0;
4976
+ changed = true;
4977
+ }
4978
+ if (this.displayed !== this.source) {
4979
+ this.reconcileDisclosures(this.source);
4980
+ this.displayed = this.source;
4981
+ changed = true;
4982
+ }
4983
+ changed ||= this.runDisclosure.open !== expanded || this.runDisclosure.pendingCleanCollapse;
4984
+ this.runDisclosure = {
4985
+ ...this.runDisclosure,
4986
+ open: expanded,
4987
+ pendingCleanCollapse: false
4988
+ };
4989
+ const phases = /* @__PURE__ */ new Map();
4990
+ for (const phase of this.source.phases) {
4991
+ /* v8 ignore next -- setExpanded reconciles every source phase before this lookup. */
4992
+ const current = this.phaseDisclosures.get(phase.key) ?? initialDisclosure(phaseFacts(phase));
4993
+ changed ||= current.open !== expanded || current.pendingCleanCollapse;
4994
+ phases.set(phase.key, {
4995
+ ...current,
4996
+ open: expanded,
4997
+ pendingCleanCollapse: false
4998
+ });
4999
+ }
5000
+ this.phaseDisclosures = phases;
5001
+ if (changed) this.changed();
5002
+ }
5003
+ /**
5004
+ * Toggle the run or phase represented by one source part.
5005
+ * @param part - source part index held by the transcript cursor.
5006
+ * @returns true when the part owns a disclosure.
5007
+ */
5008
+ togglePart(part) {
5009
+ const ref = this.sourceParts()[part];
5010
+ if (ref === void 0 || ref.kind === "member") return false;
5011
+ if (ref.kind === "run") {
5012
+ this.runDisclosure = {
5013
+ ...this.runDisclosure,
5014
+ open: !this.runDisclosure.open,
5015
+ pendingCleanCollapse: false
5016
+ };
5017
+ this.changed();
5018
+ return true;
5019
+ }
5020
+ const current = this.phaseDisclosures.get(ref.key);
5021
+ if (current === void 0) return false;
5022
+ const openingHiddenRun = !this.runDisclosure.open;
5023
+ if (openingHiddenRun) this.runDisclosure = {
5024
+ ...this.runDisclosure,
5025
+ open: true,
5026
+ pendingCleanCollapse: false
5027
+ };
5028
+ this.phaseDisclosures.set(ref.key, {
5029
+ ...current,
5030
+ open: openingHiddenRun ? true : !current.open,
5031
+ pendingCleanCollapse: false
5032
+ });
5033
+ this.changed();
5034
+ return true;
5035
+ }
5036
+ /**
5037
+ * Return a member's child only while this block and the app both consider it
5038
+ * locally openable.
5039
+ * @param part - source part index held by the transcript cursor.
5040
+ * @returns the direct child target, or undefined for every other part.
5041
+ */
5042
+ memberTarget(part) {
5043
+ const ref = this.sourceParts()[part];
5044
+ if (ref === void 0 || ref.kind !== "member" || ref.member.status !== "running") return void 0;
5045
+ if (!this.openableChildren.has(ref.member.childId)) return void 0;
5046
+ return {
5047
+ childId: ref.member.childId,
5048
+ label: memberName(ref.member.label)
5049
+ };
5050
+ }
5051
+ /** Build full source rows for the inspector and reader. */
5052
+ parts() {
5053
+ const rows = [{
5054
+ kind: "workflow-run",
5055
+ label: "run",
5056
+ rows: [
5057
+ `workflow ${this.source.name}`,
5058
+ `${String(memberCount(this.source))} member${memberCount(this.source) === 1 ? "" : "s"}`,
5059
+ statusText(this.source.status)
5060
+ ]
5061
+ }];
5062
+ for (const phase of this.source.phases) {
5063
+ rows.push({
5064
+ kind: "workflow-phase",
5065
+ label: `phase ${phaseName(phase.phase)}`,
5066
+ rows: [
5067
+ phaseName(phase.phase),
5068
+ `${String(phase.members.length)} member${phase.members.length === 1 ? "" : "s"}`,
5069
+ phaseSummary(phase)
5070
+ ]
5071
+ });
5072
+ for (const member of phase.members) rows.push({
5073
+ kind: "workflow-member",
5074
+ label: `member ${memberName(member.label)}`,
5075
+ rows: [
5076
+ memberName(member.label),
5077
+ statusText(member.status),
5078
+ `child ${member.childId}`
5079
+ ]
5080
+ });
5081
+ }
5082
+ return rows;
5083
+ }
5084
+ /**
5085
+ * Draw the in-place focus marker for one source part.
5086
+ * @param part - source part index, or undefined when the keyboard leaves it.
5087
+ * @param level - current keyboard-landing motion level.
5088
+ */
5089
+ setHighlight(part, level = 0) {
5090
+ if (this.repaintLocked) {
5091
+ this.pendingHighlight = {
5092
+ part,
5093
+ level
5094
+ };
5095
+ if (part === void 0) this.pendingCollapse = true;
5096
+ return;
5097
+ }
5098
+ this.commitHighlight(part, level);
5099
+ }
5100
+ invalidate() {
5101
+ this.drawn = void 0;
5102
+ }
5103
+ /**
5104
+ * Draw the run, nested phases, and started members at one width.
5105
+ * @param width - transcript columns available to the block.
5106
+ * @returns terminal rows, including its separating leading blank line.
5107
+ */
5108
+ render(width) {
5109
+ const highlight = this.highlight;
5110
+ const content = Math.max(1, width - (highlight === void 0 ? 0 : GUTTER_WIDTH));
5111
+ const layout = this.layout(content);
5112
+ if (highlight === void 0) return [...layout.lines];
5113
+ const focused = layout.ranges[highlight] ?? layout.fallbacks[highlight] ?? layout.ranges[0];
5114
+ /* v8 ignore next -- buildLayout always records a range for the run header, and highlight falls back to it. */
5115
+ if (focused === void 0) return [...layout.lines];
5116
+ const marker = pulse(this.theme.palette, this.theme.palette.accent(PART_GUTTER), this.highlightLevel);
5117
+ return layout.lines.map((line, index) => `${index >= focused.from && index < focused.to ? marker : this.theme.palette.dim(BLOCK_GUTTER)}${line}`);
5118
+ }
5119
+ /**
5120
+ * Apply source, child links, and a deferred clean collapse once the block
5121
+ * can be redrawn. Disclosure is reconciled here so a locked update cannot
5122
+ * change the height of rows already written.
5123
+ * @returns true when the drawn rows changed.
5124
+ */
5125
+ applyDeferred() {
5126
+ const openable = this.pendingOpenable;
5127
+ const highlight = this.pendingHighlight;
5128
+ const openableChanged = openable !== void 0 && !sameIds(this.openableChildren, openable);
5129
+ const sourceChanged = this.displayed !== this.source;
5130
+ const collapse = this.pendingCollapse;
5131
+ if (!openableChanged && !sourceChanged && !collapse && highlight === void 0) return false;
5132
+ if (openable !== void 0) {
5133
+ this.openableChildren = new Set(openable);
5134
+ this.pendingOpenable = void 0;
5135
+ }
5136
+ if (highlight !== void 0) {
5137
+ this.highlight = highlight.part;
5138
+ this.highlightLevel = highlight.level;
5139
+ this.pendingHighlight = void 0;
5140
+ }
5141
+ if (sourceChanged) {
5142
+ this.reconcileDisclosures(this.source);
5143
+ this.displayed = this.source;
5144
+ }
5145
+ this.pendingCollapse = false;
5146
+ if (collapse) this.collapsePending();
5147
+ this.changed();
5148
+ return true;
5149
+ }
5150
+ /**
5151
+ * Apply a focus mark and collapse a clean group when focus leaves it.
5152
+ * @param part - source part index, or undefined when the keyboard leaves it.
5153
+ * @param level - current keyboard-landing motion level.
5154
+ */
5155
+ commitHighlight(part, level) {
5156
+ const changed = this.highlight !== part || this.highlightLevel !== level;
5157
+ this.highlight = part;
5158
+ this.highlightLevel = level;
5159
+ if (part === void 0) this.collapsePending();
5160
+ if (changed) this.changed();
5161
+ }
5162
+ /** Preserve disclosure choices and apply status-driven automatic changes. */
5163
+ reconcileDisclosures(next) {
5164
+ const held = this.highlight === void 0 ? void 0 : this.sourceParts()[this.highlight];
5165
+ const phases = /* @__PURE__ */ new Map();
5166
+ for (const phase of next.phases) {
5167
+ const focusWithin = held?.kind === "phase" && held.key === phase.key || held?.kind === "member" && held.key === phase.key;
5168
+ const current = this.phaseDisclosures.get(phase.key);
5169
+ phases.set(phase.key, current === void 0 ? initialDisclosure(phaseFacts(phase)) : advanceDisclosure(current, phaseFacts(phase), focusWithin));
5170
+ }
5171
+ this.phaseDisclosures = phases;
5172
+ const focusWithinRun = held !== void 0;
5173
+ this.runDisclosure = advanceDisclosure(this.runDisclosure, runFacts(next), focusWithinRun);
5174
+ }
5175
+ /** Seed phases without applying an update transition. */
5176
+ syncPhaseDisclosures(data) {
5177
+ this.phaseDisclosures = new Map(data.phases.map((phase) => [phase.key, initialDisclosure(phaseFacts(phase))]));
5178
+ }
5179
+ /** Collapse clean groups after the keyboard leaves them. */
5180
+ collapsePending() {
5181
+ let changed = false;
5182
+ const run = collapseDisclosure(this.runDisclosure);
5183
+ if (run !== this.runDisclosure) {
5184
+ this.runDisclosure = run;
5185
+ changed = true;
5186
+ }
5187
+ const phases = /* @__PURE__ */ new Map();
5188
+ for (const [key, state] of this.phaseDisclosures) {
5189
+ const settled = collapseDisclosure(state);
5190
+ if (settled !== state) changed = true;
5191
+ phases.set(key, settled);
5192
+ }
5193
+ this.phaseDisclosures = phases;
5194
+ if (changed) this.changed();
5195
+ }
5196
+ /** Flat source order used by navigation, folding, and member opening. */
5197
+ sourceParts() {
5198
+ return workflowParts(this.source);
5199
+ }
5200
+ /** Cached layout for unchanged width and visible state. */
5201
+ layout(width) {
5202
+ const key = `${String(width)}:${String(this.revision)}`;
5203
+ if (this.drawn?.key === key) return this.drawn.layout;
5204
+ const layout = this.buildLayout(width);
5205
+ this.drawn = {
5206
+ key,
5207
+ layout
5208
+ };
5209
+ return layout;
5210
+ }
5211
+ /** Build visible rows and hidden-part fallback ranges from the displayed projection. */
5212
+ buildLayout(width) {
5213
+ const lines = [""];
5214
+ const refs = workflowParts(this.displayed);
5215
+ const ranges = Array.from({ length: refs.length });
5216
+ const fallbacks = Array.from({ length: refs.length });
5217
+ const append = (part, row) => {
5218
+ const from = lines.length;
5219
+ lines.push(...wrapTextWithAnsi(row, width));
5220
+ const range = {
5221
+ from,
5222
+ to: lines.length
5223
+ };
5224
+ ranges[part] = range;
5225
+ fallbacks[part] = range;
5226
+ return range;
5227
+ };
5228
+ let part = 0;
5229
+ const runRange = append(part, runRow(this.theme, this.displayed));
5230
+ part += 1;
5231
+ if (!this.runDisclosure.open) {
5232
+ for (; part < refs.length; part += 1) fallbacks[part] = runRange;
5233
+ return {
5234
+ lines,
5235
+ ranges,
5236
+ fallbacks
5237
+ };
5238
+ }
5239
+ for (const phase of this.displayed.phases) {
5240
+ const phaseRange = append(part, phaseRow(this.theme, phase));
5241
+ part += 1;
5242
+ if (!(this.phaseDisclosures.get(phase.key) ?? initialDisclosure(phaseFacts(phase))).open) {
5243
+ for (let index = 0; index < phase.members.length; index += 1) {
5244
+ fallbacks[part] = phaseRange;
5245
+ part += 1;
5246
+ }
5247
+ continue;
5248
+ }
5249
+ for (const member of phase.members) {
5250
+ append(part, memberRow(this.theme, member, this.openableChildren.has(member.childId)));
5251
+ part += 1;
5252
+ }
5253
+ }
5254
+ return {
5255
+ lines,
5256
+ ranges,
5257
+ fallbacks
5258
+ };
5259
+ }
5260
+ /** Forget cached output after any input the layout reads changes. */
5261
+ changed() {
5262
+ this.revision += 1;
5263
+ this.drawn = void 0;
5264
+ }
5265
+ };
5266
+ /** Facts of one phase, derived from its current members. */
5267
+ function phaseFacts(phase) {
5268
+ return {
5269
+ mode: phase.members.some((member) => abnormal(member.status)) ? "abnormal" : phase.members.some((member) => member.status === "running") ? "running" : "clean",
5270
+ activityCount: phase.members.length
5271
+ };
5272
+ }
5273
+ /** Facts of a whole run, derived from its status and phase groups. */
5274
+ function runFacts(run) {
5275
+ const phases = run.phases.map(phaseFacts);
5276
+ return {
5277
+ mode: abnormal(run.status) || phases.some((phase) => phase.mode === "abnormal") ? "abnormal" : run.status === "running" || phases.some((phase) => phase.mode === "running") ? "running" : "clean",
5278
+ activityCount: phases.reduce((count, phase) => count + phase.activityCount, 0)
5279
+ };
5280
+ }
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;
5504
+ return {
5505
+ ...state,
5506
+ members: state.members.map((member, memberIndex) => memberIndex === index ? {
5507
+ ...member,
5508
+ outcome: data.outcome
5509
+ } : member)
5510
+ };
5511
+ }
5512
+ function statusFromStopReason(stopReason) {
5513
+ switch (stopReason) {
5514
+ case "completed": return "completed";
5515
+ case "cancelled": return "cancelled";
5516
+ case "error": return "failed";
5517
+ /* v8 ignore next -- WorkflowStopReason is closed and every variant is handled above. */
5518
+ default: return assertNever(stopReason, "workflow stop reason");
5519
+ }
5520
+ }
5521
+ function statusFromOutcome(outcome) {
5522
+ switch (outcome) {
5523
+ case "completed": return "completed";
5524
+ case "cancelled": return "cancelled";
5525
+ case "failed": return "failed";
5526
+ /* v8 ignore next -- WorkflowAgentOutcome is closed and every variant is handled above. */
5527
+ default: return assertNever(outcome, "workflow agent outcome");
5528
+ }
5529
+ }
4821
5530
  /**
4822
5531
  * The activity line's animation for each working status. Every glyph is
4823
5532
  * braille and no card or todo row draws braille. A presentation choice of
@@ -7972,7 +8681,7 @@ function promptLabel(parts) {
7972
8681
  */
7973
8682
  function countMarkers(markers, block, parts) {
7974
8683
  if (block.blockKind === "context") markers.context += 1;
7975
- if (block.blockKind === "tool") markers.tools += 1;
8684
+ if (block.blockKind === "tool" || block.blockKind === "workflow") markers.tools += 1;
7976
8685
  for (const part of parts) {
7977
8686
  if (part.kind === "reasoning") markers.reasoning = true;
7978
8687
  if (part.kind === "reply") markers.reply = true;
@@ -8134,6 +8843,7 @@ function subjectOf(block, part) {
8134
8843
  case "assistant": return [partLabel(part.kind)];
8135
8844
  case "tool": return [block.title === "" ? block.name : `${block.name} ${block.title}`, block.parts().some((candidate) => candidate.kind === "result") ? partLabel(part.kind) : "running"];
8136
8845
  case "context": return part.label === void 0 || part.label === block.title ? [block.title] : [block.title, part.label];
8846
+ case "workflow": return [`workflow ${block.name}`, part.label ?? partLabel(part.kind)];
8137
8847
  /* v8 ignore next -- closed-union exhaustiveness guard */
8138
8848
  default: return assertNever(block, "tui transcript block kind");
8139
8849
  }
@@ -9450,6 +10160,9 @@ function sectionGlyph(block, part) {
9450
10160
  case "context": return "⬡";
9451
10161
  case "assistant": return part.kind === "reasoning" ? "✻" : "¶";
9452
10162
  case "tool": return part.kind === "result" ? "⎿" : "◆";
10163
+ case "workflow":
10164
+ if (part.kind === "workflow-run") return "◇";
10165
+ return part.kind === "workflow-phase" ? "▸" : "○";
9453
10166
  /* v8 ignore next 2 -- closed-union exhaustiveness guard */
9454
10167
  default: return assertNever(block, "tui reader block kind");
9455
10168
  }
@@ -9481,6 +10194,7 @@ function sectionName(block, part) {
9481
10194
  const card = block.title === "" ? block.name : `${block.name} ${block.title}`;
9482
10195
  return settledTool(block) ? card : `${card} · running`;
9483
10196
  }
10197
+ case "workflow": return sectionLabel(block, part);
9484
10198
  /* v8 ignore next 2 -- closed-union exhaustiveness guard */
9485
10199
  default: return assertNever(block, "tui reader block kind");
9486
10200
  }
@@ -12268,7 +12982,9 @@ var ToastPane = class {
12268
12982
  * seams for that Agent, and switches between sessions through its host. Above
12269
12983
  * the editor it draws an activity board of the open turn's todos and the
12270
12984
  * latest descendant line, and a live line while background jobs run; `Ctrl+B`
12271
- * moves the running tool calls to those jobs (`./background.ts`). Under the
12985
+ * moves the running tool calls to those jobs (`./background.ts`). A top-level
12986
+ * workflow call draws a run beside its tool card: the name, member count,
12987
+ * status, phases, and started members (`./workflow-block.ts`). Under the
12272
12988
  * editor it keeps two docked regions the keyboard can take over — the
12273
12989
  * subagent panel and the status bar — and one repeating tick advances their
12274
12990
  * elapsed counters and the jobs line's, and re-reads a stale subagent
@@ -12405,6 +13121,24 @@ function helpKeyLines() {
12405
13121
  const column = Math.max(...states.map(([label]) => visibleWidth(label))) + HELP_LABEL_GAP;
12406
13122
  return states.flatMap(([label, lines]) => lines.map((line, index) => `${(index === 0 ? label : "").padEnd(column)}${line}`));
12407
13123
  }
13124
+ /**
13125
+ * Read a workflow tool call's name and background flag.
13126
+ * @param value - parsed tool arguments.
13127
+ * @returns the association facts, or undefined when the arguments are not a workflow call.
13128
+ */
13129
+ function workflowCallArgs(value) {
13130
+ if (typeof value !== "object" || value === null) return void 0;
13131
+ const meta = value.meta;
13132
+ if (typeof meta !== "object" || meta === null) return void 0;
13133
+ const name = meta.name;
13134
+ if (typeof name !== "string") return void 0;
13135
+ const background = value.run_in_background;
13136
+ if (background !== void 0 && typeof background !== "boolean") return void 0;
13137
+ return {
13138
+ name,
13139
+ background: background === true
13140
+ };
13141
+ }
12408
13142
  /** The terminal's own commands, handled before the shared command registry. */
12409
13143
  const LOCAL_COMMANDS = [
12410
13144
  {
@@ -12639,6 +13373,16 @@ var TuiApp = class {
12639
13373
  modals;
12640
13374
  theme;
12641
13375
  toolBlocks = /* @__PURE__ */ new Map();
13376
+ /** Durable workflow blocks keyed by their run record. */
13377
+ workflowBlocks = /* @__PURE__ */ new Map();
13378
+ /** Reducer state behind {@link workflowBlocks}, replayed from durable events. */
13379
+ workflowStates = /* @__PURE__ */ new Map();
13380
+ /** Workflow-shaped calls awaiting their durable run-start record. */
13381
+ workflowCalls = /* @__PURE__ */ new Map();
13382
+ /** Process-local ownership for unfinished-run interpretation after replay. */
13383
+ workflowOwners = /* @__PURE__ */ new Map();
13384
+ /** The global fold action has not chosen a workflow default until the first `Ctrl+O`. */
13385
+ workflowExpanded;
12642
13386
  toolArguments = /* @__PURE__ */ new Map();
12643
13387
  /** Raw argument text accumulated from `tool-call-delta` chunks, keyed by call id. */
12644
13388
  toolStreamArgs = /* @__PURE__ */ new Map();
@@ -12941,17 +13685,20 @@ var TuiApp = class {
12941
13685
  }), ctx.on("agent/status", ({ agent: subject, status }) => {
12942
13686
  if (subject !== this.agent) {
12943
13687
  this.markSubagentsStale();
13688
+ this.refreshWorkflowChildLinks();
12944
13689
  return;
12945
13690
  }
12946
13691
  this.setWorking(status === "running");
12947
13692
  }), ctx.on("subagent/start", (info) => {
12948
13693
  this.markSubagentsStale();
13694
+ this.refreshWorkflowChildLinks();
12949
13695
  if (this.isBoundDescendantId(info.id)) this.setActivitySubagent({
12950
13696
  label: this.activityLabelFor(info.id),
12951
13697
  status: "running"
12952
13698
  });
12953
13699
  }), ctx.on("subagent/end", (info) => {
12954
13700
  this.markSubagentsStale();
13701
+ this.refreshWorkflowChildLinks();
12955
13702
  if (this.isBoundDescendantId(info.id)) this.setActivitySubagent({
12956
13703
  label: this.activityLabelFor(info.id),
12957
13704
  status: info.stopReason
@@ -13066,6 +13813,10 @@ var TuiApp = class {
13066
13813
  this.cursor = void 0;
13067
13814
  this.chat.clear();
13068
13815
  this.toolBlocks.clear();
13816
+ this.workflowBlocks.clear();
13817
+ this.workflowStates.clear();
13818
+ this.workflowCalls.clear();
13819
+ this.workflowOwners.clear();
13069
13820
  this.toolArguments.clear();
13070
13821
  this.toolStreamArgs.clear();
13071
13822
  this.unconfirmedTools.clear();
@@ -13100,6 +13851,8 @@ var TuiApp = class {
13100
13851
  this.replaying = true;
13101
13852
  for (const event of next.history) this.onSessionEvent(next.agent.session, event);
13102
13853
  this.replaying = false;
13854
+ this.finishWorkflowReplay();
13855
+ this.refreshWorkflowChildLinks();
13103
13856
  if (reading) this.notice(READER_GONE);
13104
13857
  this.refreshHeader();
13105
13858
  this.banner.setViews(this.viewLabels, this.asides.has(next) ? BTW_VIEW_TITLE : void 0);
@@ -13159,8 +13912,9 @@ var TuiApp = class {
13159
13912
  * follow the entry notice.
13160
13913
  * @param id - the subagent session.
13161
13914
  * @param row - the listing entry, for its label and detail rows.
13915
+ * @param options - `liveOnly` refuses to resume a child that is not running here.
13162
13916
  */
13163
- async enterSubagent(id, row) {
13917
+ async enterSubagent(id, row, options) {
13164
13918
  if (this.switching) {
13165
13919
  this.notice("wait for the session switch to finish", "error");
13166
13920
  return;
@@ -13168,7 +13922,7 @@ var TuiApp = class {
13168
13922
  this.switching = true;
13169
13923
  let next;
13170
13924
  try {
13171
- next = await this.deps.host.observe(id);
13925
+ next = await this.deps.host.observe(id, options);
13172
13926
  } catch (error) {
13173
13927
  this.switching = false;
13174
13928
  this.notice(`opening subagent ${id} failed: ${describeFailure(error)}`, "error");
@@ -13704,7 +14458,10 @@ var TuiApp = class {
13704
14458
  this.reportListingFailure(describeFailure(error));
13705
14459
  } finally {
13706
14460
  this.listing = false;
13707
- if (!this.stopped) this.refreshSubagentPanel();
14461
+ if (!this.stopped) {
14462
+ this.refreshSubagentPanel();
14463
+ this.refreshWorkflowChildLinks();
14464
+ }
13708
14465
  }
13709
14466
  }
13710
14467
  /**
@@ -14720,6 +15477,17 @@ var TuiApp = class {
14720
15477
  const section = this.focusedSection();
14721
15478
  /* v8 ignore next -- the transcript answers Enter only while it holds a section */
14722
15479
  if (section === void 0) return;
15480
+ if (section.block.blockKind === "workflow") {
15481
+ const target = section.block.memberTarget(section.cursor.part);
15482
+ if (target !== void 0) {
15483
+ this.navigate("workflow member", () => this.openWorkflowMember(target));
15484
+ return;
15485
+ }
15486
+ if (section.part.kind !== "workflow-member") {
15487
+ this.foldFocused();
15488
+ return;
15489
+ }
15490
+ }
14723
15491
  this.openReader(section.cursor);
14724
15492
  }
14725
15493
  /**
@@ -14970,6 +15738,7 @@ var TuiApp = class {
14970
15738
  */
14971
15739
  toggleFolding() {
14972
15740
  this.toolsExpanded = !this.toolsExpanded;
15741
+ this.workflowExpanded = this.toolsExpanded;
14973
15742
  for (const child of this.chat.children) if (isFoldable(child)) child.setExpanded(this.toolsExpanded);
14974
15743
  this.tui.requestRender();
14975
15744
  }
@@ -14992,6 +15761,11 @@ var TuiApp = class {
14992
15761
  this.openReader(section.cursor);
14993
15762
  return;
14994
15763
  }
15764
+ if (block instanceof WorkflowBlock) {
15765
+ block.togglePart(section.cursor.part);
15766
+ this.tui.requestRender();
15767
+ return;
15768
+ }
14995
15769
  block.setExpanded(!block.isExpanded());
14996
15770
  this.tui.requestRender();
14997
15771
  }
@@ -16313,6 +17087,9 @@ var TuiApp = class {
16313
17087
  let changed = false;
16314
17088
  for (const child of this.chat.children) {
16315
17089
  if (isSectionSource(child) && child === wanted?.block) wantedStart = start;
17090
+ if (child instanceof WorkflowBlock) {
17091
+ if (child.setRepaintFloor(repaintFloor(start, viewportTop))) changed = true;
17092
+ }
16316
17093
  if (fades && (child instanceof AssistantBlock || child instanceof ToolBlock)) {
16317
17094
  if (child.setRepaintFloor(repaintFloor(start, viewportTop))) changed = true;
16318
17095
  }
@@ -16467,10 +17244,12 @@ var TuiApp = class {
16467
17244
  this.pendingToolNames.set(callId, name);
16468
17245
  this.setLoaderActivity(callingActivity(name));
16469
17246
  this.upsertToolCard(callId, name, argumentsJson, "log");
17247
+ this.rememberWorkflowCall(callId, this.toolArguments.get(callId));
16470
17248
  break;
16471
17249
  }
16472
17250
  case "tool/result": {
16473
17251
  const result = event.data.message;
17252
+ this.noteWorkflowJob(result.toolCallId, result.content, result.isError === true);
16474
17253
  const block = this.toolBlocks.get(result.toolCallId);
16475
17254
  if (block === void 0) break;
16476
17255
  const isError = result.isError === true;
@@ -16489,6 +17268,27 @@ var TuiApp = class {
16489
17268
  this.syncLoaderFromPendingTools();
16490
17269
  break;
16491
17270
  }
17271
+ case "tool-workflow/run-start":
17272
+ this.startWorkflowRun(event.data);
17273
+ break;
17274
+ case "tool-workflow/agent-start":
17275
+ this.updateWorkflowRun({
17276
+ type: event.type,
17277
+ data: event.data
17278
+ });
17279
+ break;
17280
+ case "tool-workflow/agent-end":
17281
+ this.updateWorkflowRun({
17282
+ type: event.type,
17283
+ data: event.data
17284
+ });
17285
+ break;
17286
+ case "tool-workflow/run-end":
17287
+ this.updateWorkflowRun({
17288
+ type: event.type,
17289
+ data: event.data
17290
+ });
17291
+ break;
16492
17292
  case "turn/end": {
16493
17293
  this.turnStartedAt = void 0;
16494
17294
  this.updateTicker();
@@ -16526,6 +17326,166 @@ var TuiApp = class {
16526
17326
  if (event.type === "tool/call" && !this.replaying) this.tui.renderNow();
16527
17327
  }
16528
17328
  /**
17329
+ * Remember a logged workflow call until its durable run-start can claim it.
17330
+ * Durable records carry the run name and no tool-call id.
17331
+ * @param callId - the logged tool call.
17332
+ * @param args - arguments stored for that call.
17333
+ */
17334
+ rememberWorkflowCall(callId, args) {
17335
+ if (this.pendingToolNames.get(callId) !== "workflow") return;
17336
+ const parsed = workflowCallArgs(args);
17337
+ if (parsed === void 0) return;
17338
+ this.workflowCalls.set(callId, parsed);
17339
+ }
17340
+ /**
17341
+ * Claim the oldest unmatched workflow call with this run's name.
17342
+ * @param name - the durable run name.
17343
+ * @returns the call record, still stored so a later result can name its job.
17344
+ */
17345
+ claimWorkflowCall(name) {
17346
+ for (const record of this.workflowCalls.values()) if (record.runId === void 0 && record.name === name) return record;
17347
+ }
17348
+ /**
17349
+ * Fold a run-start into the session's workflow map and draw it.
17350
+ * @param data - the durable run-start payload.
17351
+ */
17352
+ startWorkflowRun(data) {
17353
+ const current = this.workflowStates.get(data.runId);
17354
+ const next = foldWorkflowRun(current, {
17355
+ type: "tool-workflow/run-start",
17356
+ data
17357
+ });
17358
+ /* v8 ignore next -- foldWorkflowRun never returns undefined for run-start */
17359
+ if (next === void 0) return;
17360
+ this.workflowStates.set(data.runId, next);
17361
+ if (current === void 0) {
17362
+ const call = this.claimWorkflowCall(data.name);
17363
+ if (call !== void 0) {
17364
+ call.runId = data.runId;
17365
+ this.workflowOwners.set(data.runId, {
17366
+ background: call.background,
17367
+ ...call.jobId === void 0 ? {} : { jobId: call.jobId }
17368
+ });
17369
+ }
17370
+ }
17371
+ this.projectWorkflow(data.runId);
17372
+ }
17373
+ /**
17374
+ * Fold one durable workflow update and redraw that run when the record changed.
17375
+ * @param event - an agent-start, agent-end, or run-end record.
17376
+ */
17377
+ updateWorkflowRun(event) {
17378
+ const current = this.workflowStates.get(event.data.runId);
17379
+ const next = foldWorkflowRun(current, event);
17380
+ if (next === void 0 || next === current) return;
17381
+ this.workflowStates.set(event.data.runId, next);
17382
+ this.projectWorkflow(event.data.runId);
17383
+ }
17384
+ /**
17385
+ * Draw one run from its durable state. Live events stay running until a
17386
+ * terminal record arrives; replay interruption is applied later.
17387
+ * @param runId - the run to project.
17388
+ */
17389
+ projectWorkflow(runId) {
17390
+ const state = this.workflowStates.get(runId);
17391
+ /* v8 ignore next -- projectWorkflow is only called after the state is stored */
17392
+ if (state === void 0) return;
17393
+ const view = projectWorkflowRun(state);
17394
+ const existing = this.workflowBlocks.get(runId);
17395
+ if (existing === void 0) {
17396
+ const block = new WorkflowBlock(this.theme, view, this.turn);
17397
+ if (this.workflowExpanded !== void 0) block.setExpanded(this.workflowExpanded);
17398
+ block.setOpenableChildren(this.liveDirectChildren());
17399
+ this.workflowBlocks.set(runId, block);
17400
+ this.chat.addChild(block);
17401
+ return;
17402
+ }
17403
+ existing.setOpenableChildren(this.liveDirectChildren());
17404
+ existing.setData(view);
17405
+ }
17406
+ /**
17407
+ * After history replay, unfinished runs with no live background job are
17408
+ * interrupted. A launch turn ending is not itself an interruption.
17409
+ */
17410
+ finishWorkflowReplay() {
17411
+ for (const [runId, state] of this.workflowStates) {
17412
+ if (state.stopReason !== void 0 || this.workflowOwnedLive(runId)) continue;
17413
+ this.workflowBlocks.get(runId)?.setData(projectWorkflowRun(state, { markUnfinishedInterrupted: true }));
17414
+ }
17415
+ }
17416
+ /**
17417
+ * Whether a background workflow is still owned by a live job in this process.
17418
+ * @param runId - the durable run.
17419
+ * @returns true while that job is running or stopping.
17420
+ */
17421
+ workflowOwnedLive(runId) {
17422
+ const owner = this.workflowOwners.get(runId);
17423
+ if (owner?.background !== true || owner.jobId === void 0) return false;
17424
+ const jobs = this.deps.ctx.get("jobs");
17425
+ if (jobs === void 0) return false;
17426
+ try {
17427
+ return isLive(jobs.get(owner.jobId, this.agent.session.id));
17428
+ } catch (error) {
17429
+ describeFailure(error);
17430
+ return false;
17431
+ }
17432
+ }
17433
+ /**
17434
+ * Attach a background job id from the workflow tool result, then drop the
17435
+ * call record once its run is known. An error before run-start drops the
17436
+ * record so a later run of the same name cannot claim it.
17437
+ * @param callId - the tool result's call.
17438
+ * @param content - the result body, which names the job when launch succeeded.
17439
+ * @param isError - whether the tool result failed.
17440
+ */
17441
+ noteWorkflowJob(callId, content, isError) {
17442
+ const call = this.workflowCalls.get(callId);
17443
+ if (call === void 0) return;
17444
+ if (call.background && !isError) {
17445
+ const rawId = /started in the background as job (\S+?)\./u.exec(contentText(content))?.[1];
17446
+ if (rawId !== void 0) {
17447
+ call.jobId = JobId(rawId);
17448
+ if (call.runId !== void 0) this.workflowOwners.set(call.runId, {
17449
+ background: call.background,
17450
+ jobId: call.jobId
17451
+ });
17452
+ }
17453
+ }
17454
+ if (call.runId !== void 0 || isError) this.workflowCalls.delete(callId);
17455
+ }
17456
+ /** Direct children of the bound session that are running in this process. */
17457
+ liveDirectChildren() {
17458
+ const ids = /* @__PURE__ */ new Set();
17459
+ const parentId = this.agent.session.id;
17460
+ const agents = this.deps.ctx.get("agents");
17461
+ for (const entry of this.subagentEntries) {
17462
+ if (entry.kind !== "child" || entry.depth !== 1) continue;
17463
+ const child = agents?.get(entry.id);
17464
+ if (child?.status === "running" && child.session.header.parentSession === parentId) ids.add(entry.id);
17465
+ }
17466
+ return ids;
17467
+ }
17468
+ /** Give every workflow block the current set of openable member sessions. */
17469
+ refreshWorkflowChildLinks() {
17470
+ if (this.workflowBlocks.size === 0) return;
17471
+ const ids = this.liveDirectChildren();
17472
+ for (const block of this.workflowBlocks.values()) block.setOpenableChildren(ids);
17473
+ }
17474
+ /**
17475
+ * Open a running workflow member without resuming a child that has finished.
17476
+ * @param target - the member row's child session and label.
17477
+ */
17478
+ async openWorkflowMember(target) {
17479
+ const entry = this.subagentEntries.find((candidate) => candidate.kind === "child" && candidate.id === target.childId);
17480
+ const child = entry === void 0 ? void 0 : this.deps.ctx.get("agents")?.get(entry.id);
17481
+ if (entry === void 0 || entry.depth !== 1 || child?.status !== "running" || child.session.header.parentSession !== this.agent.session.id) {
17482
+ this.notice("that workflow member is no longer running here");
17483
+ this.refreshWorkflowChildLinks();
17484
+ return;
17485
+ }
17486
+ await this.enterSubagent(entry.id, this.subagentBrowseRow(subagentChoice(entry)), { liveOnly: true });
17487
+ }
17488
+ /**
16529
17489
  * Fold one whole-list todo write into the turn facts: a content this
16530
17490
  * session has not carried before starts at the current turn, a known
16531
17491
  * content whose status moved records that turn, and a content the write
@@ -17159,10 +18119,9 @@ function sessionHost(ctx, core, cwd, btw) {
17159
18119
  });
17160
18120
  }, []);
17161
18121
  },
17162
- observe: async (id) => {
18122
+ observe: async (id, options) => {
17163
18123
  const resident = agents.get(id);
17164
- if (resident === void 0) return resume(id);
17165
- return {
18124
+ if (resident !== void 0 && (options?.liveOnly !== true || resident.status === "running")) return {
17166
18125
  agent: resident,
17167
18126
  selection: {
17168
18127
  current: void 0,
@@ -17171,6 +18130,8 @@ function sessionHost(ctx, core, cwd, btw) {
17171
18130
  history: await observeBoundHistory(ctx, id),
17172
18131
  dispose: () => Promise.resolve()
17173
18132
  };
18133
+ if (options?.liveOnly === true) throw new Error("that session is not running in this process");
18134
+ return resume(id);
17174
18135
  }
17175
18136
  };
17176
18137
  }