@songtonyli/dsh-cli 0.1.65 → 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.
Files changed (86) hide show
  1. package/README.md +1 -1
  2. package/bin/dsh.mjs +1 -1
  3. package/node_modules/@babel/runtime/helpers/esm/interopRequireWildcard.js +16 -19
  4. package/node_modules/@babel/runtime/helpers/esm/toPrimitive.js +5 -5
  5. package/node_modules/@babel/runtime/helpers/interopRequireWildcard.js +16 -19
  6. package/node_modules/@babel/runtime/helpers/toPrimitive.js +5 -5
  7. package/node_modules/@babel/runtime/package.json +1 -1
  8. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/package.json +2 -2
  9. package/node_modules/@deepseek-ai/dsh-client-ui-sidebar/lib/client.js +1 -1
  10. package/node_modules/@deepseek-ai/dsh-otel/node_modules/@opentelemetry/resources/build/esm/version.js +1 -1
  11. package/node_modules/@deepseek-ai/dsh-otel/node_modules/@opentelemetry/resources/build/esnext/version.js +1 -1
  12. package/node_modules/@deepseek-ai/dsh-otel/node_modules/@opentelemetry/resources/build/src/version.js +1 -1
  13. package/node_modules/@deepseek-ai/dsh-otel/node_modules/@opentelemetry/resources/node_modules/@opentelemetry/core/build/esm/version.js +1 -1
  14. package/node_modules/@deepseek-ai/dsh-otel/node_modules/@opentelemetry/resources/node_modules/@opentelemetry/core/build/esnext/version.js +1 -1
  15. package/node_modules/@deepseek-ai/dsh-otel/node_modules/@opentelemetry/resources/node_modules/@opentelemetry/core/build/src/version.js +1 -1
  16. package/node_modules/@deepseek-ai/dsh-otel/node_modules/@opentelemetry/resources/node_modules/@opentelemetry/core/package.json +2 -2
  17. package/node_modules/@deepseek-ai/dsh-otel/node_modules/@opentelemetry/resources/package.json +3 -3
  18. package/node_modules/@deepseek-ai/dsh-tui-app/README.i18n.yaml +6 -6
  19. package/node_modules/@deepseek-ai/dsh-tui-app/README.md +4 -2
  20. package/node_modules/@deepseek-ai/dsh-tui-app/README.zh.md +4 -2
  21. package/node_modules/@deepseek-ai/dsh-tui-app/lib/index.js +1367 -18
  22. package/node_modules/@deepseek-ai/dsh-tui-app/package.json +2 -0
  23. package/node_modules/execa/lib/arguments/command-file.js +55 -23
  24. package/node_modules/execa/lib/arguments/command.js +2 -1
  25. package/node_modules/execa/lib/arguments/cwd.js +10 -6
  26. package/node_modules/execa/lib/arguments/encoding-option.js +11 -0
  27. package/node_modules/execa/lib/arguments/escape.js +2 -2
  28. package/node_modules/execa/lib/arguments/fd-options.js +3 -7
  29. package/node_modules/execa/lib/arguments/options.js +13 -3
  30. package/node_modules/execa/lib/arguments/specific.js +2 -1
  31. package/node_modules/execa/lib/convert/duplex.js +3 -1
  32. package/node_modules/execa/lib/convert/iterable.js +3 -5
  33. package/node_modules/execa/lib/convert/readable.js +3 -1
  34. package/node_modules/execa/lib/convert/writable.js +8 -4
  35. package/node_modules/execa/lib/io/contents.js +8 -11
  36. package/node_modules/execa/lib/io/input-sync.js +8 -5
  37. package/node_modules/execa/lib/io/max-buffer.js +41 -28
  38. package/node_modules/execa/lib/io/output-sync.js +64 -40
  39. package/node_modules/execa/lib/io/strip-newline.js +4 -3
  40. package/node_modules/execa/lib/ipc/buffer-messages.js +12 -2
  41. package/node_modules/execa/lib/ipc/get-each.js +8 -2
  42. package/node_modules/execa/lib/ipc/get-one.js +3 -1
  43. package/node_modules/execa/lib/ipc/graceful.js +3 -2
  44. package/node_modules/execa/lib/ipc/incoming.js +10 -3
  45. package/node_modules/execa/lib/ipc/ipc-input.js +7 -2
  46. package/node_modules/execa/lib/ipc/send.js +3 -1
  47. package/node_modules/execa/lib/ipc/strict.js +13 -7
  48. package/node_modules/execa/lib/ipc/validation.js +1 -1
  49. package/node_modules/execa/lib/methods/bind.js +2 -8
  50. package/node_modules/execa/lib/methods/create.js +3 -1
  51. package/node_modules/execa/lib/methods/main-async.js +21 -11
  52. package/node_modules/execa/lib/methods/main-sync.js +7 -5
  53. package/node_modules/execa/lib/methods/node.js +1 -1
  54. package/node_modules/execa/lib/methods/script.js +1 -1
  55. package/node_modules/execa/lib/methods/template.js +24 -5
  56. package/node_modules/execa/lib/pipe/pipe-arguments.js +36 -5
  57. package/node_modules/execa/lib/pipe/throw.js +5 -3
  58. package/node_modules/execa/lib/resolve/all-async.js +43 -19
  59. package/node_modules/execa/lib/resolve/all-sync.js +27 -15
  60. package/node_modules/execa/lib/resolve/exit-sync.js +13 -5
  61. package/node_modules/execa/lib/resolve/stdio.js +2 -1
  62. package/node_modules/execa/lib/resolve/wait-stream.js +12 -2
  63. package/node_modules/execa/lib/resolve/wait-subprocess.js +3 -1
  64. package/node_modules/execa/lib/return/early-error.js +58 -21
  65. package/node_modules/execa/lib/return/message.js +2 -10
  66. package/node_modules/execa/lib/return/reject.js +1 -1
  67. package/node_modules/execa/lib/stdio/direction.js +36 -5
  68. package/node_modules/execa/lib/stdio/duplicate.js +26 -16
  69. package/node_modules/execa/lib/stdio/handle-async.js +6 -0
  70. package/node_modules/execa/lib/stdio/handle-sync.js +5 -3
  71. package/node_modules/execa/lib/stdio/handle.js +47 -24
  72. package/node_modules/execa/lib/stdio/native.js +3 -6
  73. package/node_modules/execa/lib/stdio/stdio-option.js +13 -18
  74. package/node_modules/execa/lib/stdio/type.js +2 -10
  75. package/node_modules/execa/lib/terminate/cancel.js +7 -0
  76. package/node_modules/execa/lib/terminate/kill-descendants.js +20 -4
  77. package/node_modules/execa/lib/transform/encoding-transform.js +15 -0
  78. package/node_modules/execa/lib/transform/generator.js +13 -2
  79. package/node_modules/execa/lib/transform/split.js +37 -23
  80. package/node_modules/execa/lib/utils/options.js +9 -0
  81. package/node_modules/execa/lib/utils/standard-stream.js +6 -0
  82. package/node_modules/execa/lib/utils/uint-array.js +1 -7
  83. package/node_modules/execa/lib/verbose/log.js +3 -6
  84. package/node_modules/execa/lib/verbose/output.js +3 -1
  85. package/node_modules/execa/package.json +51 -48
  86. 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
@@ -4957,6 +4987,23 @@ const TOOL_SPINNERS = {
4957
4987
  "✯"
4958
4988
  ]
4959
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
+ ];
4960
5007
  /** Blank steps between two shimmer passes, so the sweep pauses past the word's end. */
4961
5008
  const SHIMMER_GAP = 6;
4962
5009
  /** Tool names that execute commands. */
@@ -5143,6 +5190,913 @@ function shimmer(palette, text, now, periodMs) {
5143
5190
  return out;
5144
5191
  }
5145
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
+ }
5348
+ //#endregion
5349
+ //#region lib/types/workflow-block.js
5350
+ /**
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.
5355
+ * @module @deepseek-ai/dsh-tui-app/workflow-block
5356
+ */
5357
+ /** Columns the focus gutter takes from this block's content. */
5358
+ const GUTTER_WIDTH = 2;
5359
+ /** Gutter beside an unfocused section of a focused workflow block. */
5360
+ const BLOCK_GUTTER = "│ ";
5361
+ /** Gutter beside the focused workflow section. */
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
+ ];
5373
+ /**
5374
+ * One workflow run in the transcript. The block's source state can advance
5375
+ * while its already-written scrollback stays frozen; reader and inspector rows
5376
+ * always read the newest durable projection.
5377
+ */
5378
+ var WorkflowBlock = class {
5379
+ theme;
5380
+ turn;
5381
+ navigable = true;
5382
+ blockKind = "workflow";
5383
+ foldable = true;
5384
+ /** Data used by reader, inspector, navigation, and child opening. */
5385
+ source;
5386
+ /** Data currently safe to rewrite in the terminal transcript. */
5387
+ displayed;
5388
+ runDisclosure;
5389
+ phaseDisclosures = /* @__PURE__ */ new Map();
5390
+ openableChildren = /* @__PURE__ */ new Set();
5391
+ highlight;
5392
+ highlightLevel = 0;
5393
+ repaintLocked = false;
5394
+ /** Child ids received while the block cannot safely redraw. */
5395
+ pendingOpenable;
5396
+ /** Clean collapse deferred until the block can be redrawn. */
5397
+ pendingCollapse = false;
5398
+ /** Focus mark received while the block cannot safely redraw. */
5399
+ pendingHighlight;
5400
+ revision = 0;
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;
5408
+ /**
5409
+ * @param theme - terminal palette shared with transcript blocks.
5410
+ * @param initial - durable run projection at insertion.
5411
+ * @param turn - turn that recorded the run start.
5412
+ */
5413
+ constructor(theme, initial, turn) {
5414
+ this.theme = theme;
5415
+ this.turn = turn;
5416
+ this.source = initial;
5417
+ this.displayed = initial;
5418
+ this.runDisclosure = initialDisclosure(runFacts(initial));
5419
+ this.syncPhaseDisclosures(initial);
5420
+ }
5421
+ /** Durable name read by transcript navigation. */
5422
+ get name() {
5423
+ return this.source.name;
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
+ }
5445
+ /**
5446
+ * Replace the durable rendering projection. A block above the repaint window
5447
+ * keeps its earlier transcript rows until the next safe redraw.
5448
+ * @param next - latest folded workflow data.
5449
+ */
5450
+ setData(next) {
5451
+ this.source = next;
5452
+ if (this.repaintLocked) return;
5453
+ this.reconcileDisclosures(next);
5454
+ this.displayed = next;
5455
+ this.changed();
5456
+ }
5457
+ /**
5458
+ * Replace the direct child ids that may be opened from currently running
5459
+ * member rows.
5460
+ * @param ids - locally resident direct children of the bound session.
5461
+ */
5462
+ setOpenableChildren(ids) {
5463
+ if (this.repaintLocked) {
5464
+ if (sameIds(this.pendingOpenable ?? this.openableChildren, ids)) return;
5465
+ this.pendingOpenable = ids;
5466
+ return;
5467
+ }
5468
+ this.pendingOpenable = void 0;
5469
+ if (sameIds(this.openableChildren, ids)) return;
5470
+ this.openableChildren = new Set(ids);
5471
+ this.changed();
5472
+ }
5473
+ /**
5474
+ * Keep presentation updates out of immutable terminal scrollback, then apply
5475
+ * deferred updates when the whole block can be redrawn safely.
5476
+ * @param floor - first block line the renderer may repaint.
5477
+ * @returns true when a deferred projection became drawable.
5478
+ */
5479
+ setRepaintFloor(floor) {
5480
+ if (floor > 0) {
5481
+ this.repaintLocked = true;
5482
+ return false;
5483
+ }
5484
+ if (!this.repaintLocked) return false;
5485
+ this.repaintLocked = false;
5486
+ return this.applyDeferred();
5487
+ }
5488
+ /** Whether the run body is currently visible. */
5489
+ isExpanded() {
5490
+ return this.runDisclosure.open;
5491
+ }
5492
+ /**
5493
+ * Expand or collapse the run and every currently known phase. This is the
5494
+ * all-block action used by `Ctrl+O`.
5495
+ * @param expanded - whether every level should draw its members.
5496
+ */
5497
+ setExpanded(expanded) {
5498
+ this.repaintLocked = false;
5499
+ this.pendingCollapse = false;
5500
+ let changed = false;
5501
+ if (this.pendingOpenable !== void 0) {
5502
+ this.openableChildren = new Set(this.pendingOpenable);
5503
+ this.pendingOpenable = void 0;
5504
+ changed = true;
5505
+ }
5506
+ if (this.pendingHighlight !== void 0) {
5507
+ this.highlight = this.pendingHighlight.part;
5508
+ this.highlightLevel = this.pendingHighlight.level;
5509
+ this.pendingHighlight = void 0;
5510
+ changed = true;
5511
+ }
5512
+ if (this.displayed !== this.source) {
5513
+ this.reconcileDisclosures(this.source);
5514
+ this.displayed = this.source;
5515
+ changed = true;
5516
+ }
5517
+ changed ||= this.runDisclosure.open !== expanded || this.runDisclosure.pendingCleanCollapse;
5518
+ this.runDisclosure = {
5519
+ ...this.runDisclosure,
5520
+ open: expanded,
5521
+ pendingCleanCollapse: false
5522
+ };
5523
+ const phases = /* @__PURE__ */ new Map();
5524
+ for (const phase of this.source.phases) {
5525
+ /* v8 ignore next -- setExpanded reconciles every source phase before this lookup. */
5526
+ const current = this.phaseDisclosures.get(phase.key) ?? initialDisclosure(phaseFacts(phase));
5527
+ changed ||= current.open !== expanded || current.pendingCleanCollapse;
5528
+ phases.set(phase.key, {
5529
+ ...current,
5530
+ open: expanded,
5531
+ pendingCleanCollapse: false
5532
+ });
5533
+ }
5534
+ this.phaseDisclosures = phases;
5535
+ if (changed) this.changed();
5536
+ }
5537
+ /**
5538
+ * Toggle the run or phase represented by one source part.
5539
+ * @param part - source part index held by the transcript cursor.
5540
+ * @returns true when the part owns a disclosure.
5541
+ */
5542
+ togglePart(part) {
5543
+ const ref = this.sourceParts()[part];
5544
+ if (ref === void 0 || ref.kind === "member") return false;
5545
+ if (ref.kind === "run") {
5546
+ this.runDisclosure = {
5547
+ ...this.runDisclosure,
5548
+ open: !this.runDisclosure.open,
5549
+ pendingCleanCollapse: false
5550
+ };
5551
+ this.changed();
5552
+ return true;
5553
+ }
5554
+ const current = this.phaseDisclosures.get(ref.key);
5555
+ if (current === void 0) return false;
5556
+ const openingHiddenRun = !this.runDisclosure.open;
5557
+ if (openingHiddenRun) this.runDisclosure = {
5558
+ ...this.runDisclosure,
5559
+ open: true,
5560
+ pendingCleanCollapse: false
5561
+ };
5562
+ this.phaseDisclosures.set(ref.key, {
5563
+ ...current,
5564
+ open: openingHiddenRun ? true : !current.open,
5565
+ pendingCleanCollapse: false
5566
+ });
5567
+ this.changed();
5568
+ return true;
5569
+ }
5570
+ /**
5571
+ * Return a member's child only while this block and the app both consider it
5572
+ * locally openable.
5573
+ * @param part - source part index held by the transcript cursor.
5574
+ * @returns the direct child target, or undefined for every other part.
5575
+ */
5576
+ memberTarget(part) {
5577
+ const ref = this.sourceParts()[part];
5578
+ if (ref === void 0 || ref.kind !== "member" || ref.member.status !== "running") return void 0;
5579
+ if (!this.openableChildren.has(ref.member.childId)) return void 0;
5580
+ return {
5581
+ childId: ref.member.childId,
5582
+ label: workflowMemberName(ref.member.label)
5583
+ };
5584
+ }
5585
+ /** Build full source rows for the inspector and reader. */
5586
+ parts() {
5587
+ const rows = [{
5588
+ kind: "workflow-run",
5589
+ label: "run",
5590
+ rows: [
5591
+ `workflow ${this.source.name}`,
5592
+ `${String(memberCount(this.source))} member${memberCount(this.source) === 1 ? "" : "s"}`,
5593
+ statusText(this.source.status)
5594
+ ]
5595
+ }];
5596
+ for (const phase of this.source.phases) {
5597
+ rows.push({
5598
+ kind: "workflow-phase",
5599
+ label: `phase ${workflowPhaseName(phase.phase)}`,
5600
+ rows: [
5601
+ workflowPhaseName(phase.phase),
5602
+ `${String(phase.members.length)} member${phase.members.length === 1 ? "" : "s"}`,
5603
+ phaseSummary(phase)
5604
+ ]
5605
+ });
5606
+ for (const member of phase.members) rows.push({
5607
+ kind: "workflow-member",
5608
+ label: `member ${workflowMemberName(member.label)}`,
5609
+ rows: [
5610
+ workflowMemberName(member.label),
5611
+ statusText(member.status),
5612
+ `child ${member.childId}`
5613
+ ]
5614
+ });
5615
+ }
5616
+ return rows;
5617
+ }
5618
+ /**
5619
+ * Draw the in-place focus marker for one source part.
5620
+ * @param part - source part index, or undefined when the keyboard leaves it.
5621
+ * @param level - current keyboard-landing motion level.
5622
+ */
5623
+ setHighlight(part, level = 0) {
5624
+ if (this.repaintLocked) {
5625
+ this.pendingHighlight = {
5626
+ part,
5627
+ level
5628
+ };
5629
+ if (part === void 0) this.pendingCollapse = true;
5630
+ return;
5631
+ }
5632
+ this.commitHighlight(part, level);
5633
+ }
5634
+ invalidate() {
5635
+ this.drawn = void 0;
5636
+ }
5637
+ /**
5638
+ * Draw the run, nested phases, and started members at one width.
5639
+ * @param width - transcript columns available to the block.
5640
+ * @returns terminal rows, including its separating leading blank line.
5641
+ */
5642
+ render(width) {
5643
+ const highlight = this.highlight;
5644
+ const content = Math.max(1, width - (highlight === void 0 ? 0 : GUTTER_WIDTH));
5645
+ const layout = this.layout(content);
5646
+ if (highlight === void 0) return [...layout.lines];
5647
+ const focused = layout.ranges[highlight] ?? layout.fallbacks[highlight] ?? layout.ranges[0];
5648
+ /* v8 ignore next -- buildLayout always records a range for the run header, and highlight falls back to it. */
5649
+ if (focused === void 0) return [...layout.lines];
5650
+ const marker = pulse(this.theme.palette, this.theme.palette.accent(PART_GUTTER), this.highlightLevel);
5651
+ return layout.lines.map((line, index) => `${index >= focused.from && index < focused.to ? marker : this.theme.palette.dim(BLOCK_GUTTER)}${line}`);
5652
+ }
5653
+ /**
5654
+ * Apply source, child links, and a deferred clean collapse once the block
5655
+ * can be redrawn. Disclosure is reconciled here so a locked update cannot
5656
+ * change the height of rows already written.
5657
+ * @returns true when the drawn rows changed.
5658
+ */
5659
+ applyDeferred() {
5660
+ const openable = this.pendingOpenable;
5661
+ const highlight = this.pendingHighlight;
5662
+ const openableChanged = openable !== void 0 && !sameIds(this.openableChildren, openable);
5663
+ const sourceChanged = this.displayed !== this.source;
5664
+ const collapse = this.pendingCollapse;
5665
+ if (!openableChanged && !sourceChanged && !collapse && highlight === void 0) return false;
5666
+ if (openable !== void 0) {
5667
+ this.openableChildren = new Set(openable);
5668
+ this.pendingOpenable = void 0;
5669
+ }
5670
+ if (highlight !== void 0) {
5671
+ this.highlight = highlight.part;
5672
+ this.highlightLevel = highlight.level;
5673
+ this.pendingHighlight = void 0;
5674
+ }
5675
+ if (sourceChanged) {
5676
+ this.reconcileDisclosures(this.source);
5677
+ this.displayed = this.source;
5678
+ }
5679
+ this.pendingCollapse = false;
5680
+ if (collapse) this.collapsePending();
5681
+ this.changed();
5682
+ return true;
5683
+ }
5684
+ /**
5685
+ * Apply a focus mark and collapse a clean group when focus leaves it.
5686
+ * @param part - source part index, or undefined when the keyboard leaves it.
5687
+ * @param level - current keyboard-landing motion level.
5688
+ */
5689
+ commitHighlight(part, level) {
5690
+ const changed = this.highlight !== part || this.highlightLevel !== level;
5691
+ this.highlight = part;
5692
+ this.highlightLevel = level;
5693
+ if (part === void 0) this.collapsePending();
5694
+ if (changed) this.changed();
5695
+ }
5696
+ /** Preserve disclosure choices and apply status-driven automatic changes. */
5697
+ reconcileDisclosures(next) {
5698
+ const held = this.highlight === void 0 ? void 0 : this.sourceParts()[this.highlight];
5699
+ const phases = /* @__PURE__ */ new Map();
5700
+ for (const phase of next.phases) {
5701
+ const focusWithin = held?.kind === "phase" && held.key === phase.key || held?.kind === "member" && held.key === phase.key;
5702
+ const current = this.phaseDisclosures.get(phase.key);
5703
+ phases.set(phase.key, current === void 0 ? initialDisclosure(phaseFacts(phase)) : advanceDisclosure(current, phaseFacts(phase), focusWithin));
5704
+ }
5705
+ this.phaseDisclosures = phases;
5706
+ const focusWithinRun = held !== void 0;
5707
+ this.runDisclosure = advanceDisclosure(this.runDisclosure, runFacts(next), focusWithinRun);
5708
+ }
5709
+ /** Seed phases without applying an update transition. */
5710
+ syncPhaseDisclosures(data) {
5711
+ this.phaseDisclosures = new Map(data.phases.map((phase) => [phase.key, initialDisclosure(phaseFacts(phase))]));
5712
+ }
5713
+ /** Collapse clean groups after the keyboard leaves them. */
5714
+ collapsePending() {
5715
+ let changed = false;
5716
+ const run = collapseDisclosure(this.runDisclosure);
5717
+ if (run !== this.runDisclosure) {
5718
+ this.runDisclosure = run;
5719
+ changed = true;
5720
+ }
5721
+ const phases = /* @__PURE__ */ new Map();
5722
+ for (const [key, state] of this.phaseDisclosures) {
5723
+ const settled = collapseDisclosure(state);
5724
+ if (settled !== state) changed = true;
5725
+ phases.set(key, settled);
5726
+ }
5727
+ this.phaseDisclosures = phases;
5728
+ if (changed) this.changed();
5729
+ }
5730
+ /** Flat source order used by navigation, folding, and member opening. */
5731
+ sourceParts() {
5732
+ return workflowParts(this.source);
5733
+ }
5734
+ /** Cached layout for unchanged width and visible state. */
5735
+ layout(width) {
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) : "-"}`;
5743
+ if (this.drawn?.key === key) return this.drawn.layout;
5744
+ const layout = this.buildLayout(width, animated ? spinGlyphs(this.spinIndex) : void 0);
5745
+ this.drawn = {
5746
+ key,
5747
+ layout
5748
+ };
5749
+ return layout;
5750
+ }
5751
+ /** Build visible rows and hidden-part fallback ranges from the displayed projection. */
5752
+ buildLayout(width, spin) {
5753
+ const lines = [""];
5754
+ const refs = workflowParts(this.displayed);
5755
+ const ranges = Array.from({ length: refs.length });
5756
+ const fallbacks = Array.from({ length: refs.length });
5757
+ const append = (part, row) => {
5758
+ const from = lines.length;
5759
+ lines.push(...wrapTextWithAnsi(row, width));
5760
+ const range = {
5761
+ from,
5762
+ to: lines.length
5763
+ };
5764
+ ranges[part] = range;
5765
+ fallbacks[part] = range;
5766
+ return range;
5767
+ };
5768
+ let part = 0;
5769
+ const runRange = append(part, runRow(this.theme, this.displayed, spin));
5770
+ part += 1;
5771
+ if (!this.runDisclosure.open) {
5772
+ for (; part < refs.length; part += 1) fallbacks[part] = runRange;
5773
+ return {
5774
+ lines,
5775
+ ranges,
5776
+ fallbacks
5777
+ };
5778
+ }
5779
+ for (const phase of this.displayed.phases) {
5780
+ const phaseRange = append(part, phaseRow(this.theme, phase));
5781
+ part += 1;
5782
+ if (!(this.phaseDisclosures.get(phase.key) ?? initialDisclosure(phaseFacts(phase))).open) {
5783
+ for (let index = 0; index < phase.members.length; index += 1) {
5784
+ fallbacks[part] = phaseRange;
5785
+ part += 1;
5786
+ }
5787
+ continue;
5788
+ }
5789
+ for (const member of phase.members) {
5790
+ append(part, memberRow(this.theme, member, this.openableChildren.has(member.childId), spin));
5791
+ part += 1;
5792
+ }
5793
+ }
5794
+ return {
5795
+ lines,
5796
+ ranges,
5797
+ fallbacks
5798
+ };
5799
+ }
5800
+ /** Forget cached output after any input the layout reads changes. */
5801
+ changed() {
5802
+ this.revision += 1;
5803
+ this.drawn = void 0;
5804
+ }
5805
+ };
5806
+ /** Facts of one phase, derived from its current members. */
5807
+ function phaseFacts(phase) {
5808
+ return {
5809
+ mode: phase.members.some((member) => abnormal(member.status)) ? "abnormal" : phase.members.some((member) => member.status === "running") ? "running" : "clean",
5810
+ activityCount: phase.members.length
5811
+ };
5812
+ }
5813
+ /** Facts of a whole run, derived from its status and phase groups. */
5814
+ function runFacts(run) {
5815
+ const phases = run.phases.map(phaseFacts);
5816
+ return {
5817
+ mode: abnormal(run.status) || phases.some((phase) => phase.mode === "abnormal") ? "abnormal" : run.status === "running" || phases.some((phase) => phase.mode === "running") ? "running" : "clean",
5818
+ activityCount: phases.reduce((count, phase) => count + phase.activityCount, 0)
5819
+ };
5820
+ }
5821
+ /** Initial disclosure follows the same status-driven choice as the Web run node. */
5822
+ function initialDisclosure(facts) {
5823
+ return {
5824
+ ...facts,
5825
+ open: facts.mode !== "clean",
5826
+ pendingCleanCollapse: false
5827
+ };
5828
+ }
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
+ };
5838
+ }
5839
+ if (facts.mode === "clean") {
5840
+ const defer = current.open && focusWithin;
5841
+ return {
5842
+ ...facts,
5843
+ open: defer,
5844
+ pendingCleanCollapse: defer
5845
+ };
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;
5906
+ }
5907
+ /**
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.
5911
+ */
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;
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
+ };
6018
+ /**
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.
6024
+ */
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
+ };
6031
+ }
6032
+ /**
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`.
6036
+ */
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"}`;
6041
+ }
6042
+ /**
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.
6047
+ */
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
+ }
6073
+ }
6074
+ /**
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.
6079
+ */
6080
+ function memberOpenable(member, openable) {
6081
+ return member.status === "running" && openable.has(member.childId);
6082
+ }
6083
+ /**
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.
6089
+ */
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
+ ];
6098
+ }
6099
+ //#endregion
5146
6100
  //#region lib/types/completion.js
5147
6101
  /**
5148
6102
  * Editor completion: `/` at the start of the message opens the command list,
@@ -7972,7 +8926,7 @@ function promptLabel(parts) {
7972
8926
  */
7973
8927
  function countMarkers(markers, block, parts) {
7974
8928
  if (block.blockKind === "context") markers.context += 1;
7975
- if (block.blockKind === "tool") markers.tools += 1;
8929
+ if (block.blockKind === "tool" || block.blockKind === "workflow") markers.tools += 1;
7976
8930
  for (const part of parts) {
7977
8931
  if (part.kind === "reasoning") markers.reasoning = true;
7978
8932
  if (part.kind === "reply") markers.reply = true;
@@ -8134,6 +9088,7 @@ function subjectOf(block, part) {
8134
9088
  case "assistant": return [partLabel(part.kind)];
8135
9089
  case "tool": return [block.title === "" ? block.name : `${block.name} ${block.title}`, block.parts().some((candidate) => candidate.kind === "result") ? partLabel(part.kind) : "running"];
8136
9090
  case "context": return part.label === void 0 || part.label === block.title ? [block.title] : [block.title, part.label];
9091
+ case "workflow": return [`workflow ${block.name}`, part.label ?? partLabel(part.kind)];
8137
9092
  /* v8 ignore next -- closed-union exhaustiveness guard */
8138
9093
  default: return assertNever(block, "tui transcript block kind");
8139
9094
  }
@@ -9450,6 +10405,9 @@ function sectionGlyph(block, part) {
9450
10405
  case "context": return "⬡";
9451
10406
  case "assistant": return part.kind === "reasoning" ? "✻" : "¶";
9452
10407
  case "tool": return part.kind === "result" ? "⎿" : "◆";
10408
+ case "workflow":
10409
+ if (part.kind === "workflow-run") return "◇";
10410
+ return part.kind === "workflow-phase" ? "▸" : "○";
9453
10411
  /* v8 ignore next 2 -- closed-union exhaustiveness guard */
9454
10412
  default: return assertNever(block, "tui reader block kind");
9455
10413
  }
@@ -9481,6 +10439,7 @@ function sectionName(block, part) {
9481
10439
  const card = block.title === "" ? block.name : `${block.name} ${block.title}`;
9482
10440
  return settledTool(block) ? card : `${card} · running`;
9483
10441
  }
10442
+ case "workflow": return sectionLabel(block, part);
9484
10443
  /* v8 ignore next 2 -- closed-union exhaustiveness guard */
9485
10444
  default: return assertNever(block, "tui reader block kind");
9486
10445
  }
@@ -12268,7 +13227,12 @@ var ToastPane = class {
12268
13227
  * seams for that Agent, and switches between sessions through its host. Above
12269
13228
  * the editor it draws an activity board of the open turn's todos and the
12270
13229
  * 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
13230
+ * moves the running tool calls to those jobs (`./background.ts`). A top-level
13231
+ * workflow call draws a run beside its tool card: the name, member count,
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
12272
13236
  * editor it keeps two docked regions the keyboard can take over — the
12273
13237
  * subagent panel and the status bar — and one repeating tick advances their
12274
13238
  * elapsed counters and the jobs line's, and re-reads a stale subagent
@@ -12405,6 +13369,24 @@ function helpKeyLines() {
12405
13369
  const column = Math.max(...states.map(([label]) => visibleWidth(label))) + HELP_LABEL_GAP;
12406
13370
  return states.flatMap(([label, lines]) => lines.map((line, index) => `${(index === 0 ? label : "").padEnd(column)}${line}`));
12407
13371
  }
13372
+ /**
13373
+ * Read a workflow tool call's name and background flag.
13374
+ * @param value - parsed tool arguments.
13375
+ * @returns the association facts, or undefined when the arguments are not a workflow call.
13376
+ */
13377
+ function workflowCallArgs(value) {
13378
+ if (typeof value !== "object" || value === null) return void 0;
13379
+ const meta = value.meta;
13380
+ if (typeof meta !== "object" || meta === null) return void 0;
13381
+ const name = meta.name;
13382
+ if (typeof name !== "string") return void 0;
13383
+ const background = value.run_in_background;
13384
+ if (background !== void 0 && typeof background !== "boolean") return void 0;
13385
+ return {
13386
+ name,
13387
+ background: background === true
13388
+ };
13389
+ }
12408
13390
  /** The terminal's own commands, handled before the shared command registry. */
12409
13391
  const LOCAL_COMMANDS = [
12410
13392
  {
@@ -12500,6 +13482,11 @@ const LOCAL_COMMANDS = [
12500
13482
  name: "jobs",
12501
13483
  description: "Browse this session's background jobs (Enter shows the output, Ctrl+K stops one; Ctrl+B moves running tool calls here)"
12502
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
+ },
12503
13490
  {
12504
13491
  name: "parent",
12505
13492
  description: "Return from a subagent view or a /btw side agent to the session it was opened from"
@@ -12639,6 +13626,18 @@ var TuiApp = class {
12639
13626
  modals;
12640
13627
  theme;
12641
13628
  toolBlocks = /* @__PURE__ */ new Map();
13629
+ /** Durable workflow blocks keyed by their run record. */
13630
+ workflowBlocks = /* @__PURE__ */ new Map();
13631
+ /** Reducer state behind {@link workflowBlocks}, replayed from durable events. */
13632
+ workflowStates = /* @__PURE__ */ new Map();
13633
+ /** Workflow-shaped calls awaiting their durable run-start record. */
13634
+ workflowCalls = /* @__PURE__ */ new Map();
13635
+ /** Process-local ownership for unfinished-run interpretation after replay. */
13636
+ workflowOwners = /* @__PURE__ */ new Map();
13637
+ /** Workflow blocks whose running glyphs step on the spinner tick. */
13638
+ workflowSpinners = /* @__PURE__ */ new Set();
13639
+ /** The global fold action has not chosen a workflow default until the first `Ctrl+O`. */
13640
+ workflowExpanded;
12642
13641
  toolArguments = /* @__PURE__ */ new Map();
12643
13642
  /** Raw argument text accumulated from `tool-call-delta` chunks, keyed by call id. */
12644
13643
  toolStreamArgs = /* @__PURE__ */ new Map();
@@ -12941,17 +13940,20 @@ var TuiApp = class {
12941
13940
  }), ctx.on("agent/status", ({ agent: subject, status }) => {
12942
13941
  if (subject !== this.agent) {
12943
13942
  this.markSubagentsStale();
13943
+ this.refreshWorkflowChildLinks();
12944
13944
  return;
12945
13945
  }
12946
13946
  this.setWorking(status === "running");
12947
13947
  }), ctx.on("subagent/start", (info) => {
12948
13948
  this.markSubagentsStale();
13949
+ this.refreshWorkflowChildLinks();
12949
13950
  if (this.isBoundDescendantId(info.id)) this.setActivitySubagent({
12950
13951
  label: this.activityLabelFor(info.id),
12951
13952
  status: "running"
12952
13953
  });
12953
13954
  }), ctx.on("subagent/end", (info) => {
12954
13955
  this.markSubagentsStale();
13956
+ this.refreshWorkflowChildLinks();
12955
13957
  if (this.isBoundDescendantId(info.id)) this.setActivitySubagent({
12956
13958
  label: this.activityLabelFor(info.id),
12957
13959
  status: info.stopReason
@@ -13066,6 +14068,11 @@ var TuiApp = class {
13066
14068
  this.cursor = void 0;
13067
14069
  this.chat.clear();
13068
14070
  this.toolBlocks.clear();
14071
+ this.workflowBlocks.clear();
14072
+ this.workflowStates.clear();
14073
+ this.workflowCalls.clear();
14074
+ this.workflowOwners.clear();
14075
+ this.workflowSpinners.clear();
13069
14076
  this.toolArguments.clear();
13070
14077
  this.toolStreamArgs.clear();
13071
14078
  this.unconfirmedTools.clear();
@@ -13100,6 +14107,8 @@ var TuiApp = class {
13100
14107
  this.replaying = true;
13101
14108
  for (const event of next.history) this.onSessionEvent(next.agent.session, event);
13102
14109
  this.replaying = false;
14110
+ this.finishWorkflowReplay();
14111
+ this.refreshWorkflowChildLinks();
13103
14112
  if (reading) this.notice(READER_GONE);
13104
14113
  this.refreshHeader();
13105
14114
  this.banner.setViews(this.viewLabels, this.asides.has(next) ? BTW_VIEW_TITLE : void 0);
@@ -13159,8 +14168,9 @@ var TuiApp = class {
13159
14168
  * follow the entry notice.
13160
14169
  * @param id - the subagent session.
13161
14170
  * @param row - the listing entry, for its label and detail rows.
14171
+ * @param options - `liveOnly` refuses to resume a child that is not running here.
13162
14172
  */
13163
- async enterSubagent(id, row) {
14173
+ async enterSubagent(id, row, options) {
13164
14174
  if (this.switching) {
13165
14175
  this.notice("wait for the session switch to finish", "error");
13166
14176
  return;
@@ -13168,7 +14178,7 @@ var TuiApp = class {
13168
14178
  this.switching = true;
13169
14179
  let next;
13170
14180
  try {
13171
- next = await this.deps.host.observe(id);
14181
+ next = await this.deps.host.observe(id, options);
13172
14182
  } catch (error) {
13173
14183
  this.switching = false;
13174
14184
  this.notice(`opening subagent ${id} failed: ${describeFailure(error)}`, "error");
@@ -13704,7 +14714,10 @@ var TuiApp = class {
13704
14714
  this.reportListingFailure(describeFailure(error));
13705
14715
  } finally {
13706
14716
  this.listing = false;
13707
- if (!this.stopped) this.refreshSubagentPanel();
14717
+ if (!this.stopped) {
14718
+ this.refreshSubagentPanel();
14719
+ this.refreshWorkflowChildLinks();
14720
+ }
13708
14721
  }
13709
14722
  }
13710
14723
  /**
@@ -13986,6 +14999,116 @@ var TuiApp = class {
13986
14999
  this.showToast(outcome === "requested" ? `stopping ${view.id}` : `${view.id} already finished`);
13987
15000
  }
13988
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
+ /**
13989
15112
  * Walk the agent's todo list: one row per item, and entering a row shows
13990
15113
  * that item in full with its position, the list's counts by status, and the
13991
15114
  * turns it was first written in and last changed status in.
@@ -14720,6 +15843,17 @@ var TuiApp = class {
14720
15843
  const section = this.focusedSection();
14721
15844
  /* v8 ignore next -- the transcript answers Enter only while it holds a section */
14722
15845
  if (section === void 0) return;
15846
+ if (section.block.blockKind === "workflow") {
15847
+ const target = section.block.memberTarget(section.cursor.part);
15848
+ if (target !== void 0) {
15849
+ this.navigate("workflow member", () => this.openWorkflowMember(target));
15850
+ return;
15851
+ }
15852
+ if (section.part.kind !== "workflow-member") {
15853
+ this.foldFocused();
15854
+ return;
15855
+ }
15856
+ }
14723
15857
  this.openReader(section.cursor);
14724
15858
  }
14725
15859
  /**
@@ -14970,6 +16104,7 @@ var TuiApp = class {
14970
16104
  */
14971
16105
  toggleFolding() {
14972
16106
  this.toolsExpanded = !this.toolsExpanded;
16107
+ this.workflowExpanded = this.toolsExpanded;
14973
16108
  for (const child of this.chat.children) if (isFoldable(child)) child.setExpanded(this.toolsExpanded);
14974
16109
  this.tui.requestRender();
14975
16110
  }
@@ -14992,6 +16127,11 @@ var TuiApp = class {
14992
16127
  this.openReader(section.cursor);
14993
16128
  return;
14994
16129
  }
16130
+ if (block instanceof WorkflowBlock) {
16131
+ block.togglePart(section.cursor.part);
16132
+ this.tui.requestRender();
16133
+ return;
16134
+ }
14995
16135
  block.setExpanded(!block.isExpanded());
14996
16136
  this.tui.requestRender();
14997
16137
  }
@@ -15282,6 +16422,9 @@ var TuiApp = class {
15282
16422
  case "jobs":
15283
16423
  await this.browseJobs();
15284
16424
  return;
16425
+ case "workflows":
16426
+ await this.browseWorkflows(argument);
16427
+ return;
15285
16428
  case "settings":
15286
16429
  await this.settings(argument);
15287
16430
  return;
@@ -16134,7 +17277,8 @@ var TuiApp = class {
16134
17277
  * stopped app runs none.
16135
17278
  */
16136
17279
  updateSpinTicker() {
16137
- if (!this.stopped && (this.loaderAnimates() || this.spinners.size > 0 || this.boardSpinners.size > 0)) {
17280
+ const spinning = this.spinners.size > 0 || this.boardSpinners.size > 0 || this.workflowSpinners.size > 0;
17281
+ if (!this.stopped && (this.loaderAnimates() || spinning)) {
16138
17282
  this.spinTicker ??= this.deps.tick(() => {
16139
17283
  this.onSpinTick();
16140
17284
  }, this.deps.spinnerMs);
@@ -16153,9 +17297,10 @@ var TuiApp = class {
16153
17297
  */
16154
17298
  onSpinTick() {
16155
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);
16156
17301
  if (this.loaderAnimates()) this.refreshLoader();
16157
17302
  if (this.boardSpinners.size > 0) this.refreshActivityBoard();
16158
- else if (this.spinners.size > 0) this.tui.requestRender();
17303
+ else if (this.spinners.size > 0 || this.workflowSpinners.size > 0) this.tui.requestRender();
16159
17304
  this.updateSpinTicker();
16160
17305
  }
16161
17306
  /**
@@ -16313,6 +17458,9 @@ var TuiApp = class {
16313
17458
  let changed = false;
16314
17459
  for (const child of this.chat.children) {
16315
17460
  if (isSectionSource(child) && child === wanted?.block) wantedStart = start;
17461
+ if (child instanceof WorkflowBlock) {
17462
+ if (child.setRepaintFloor(repaintFloor(start, viewportTop))) changed = true;
17463
+ }
16316
17464
  if (fades && (child instanceof AssistantBlock || child instanceof ToolBlock)) {
16317
17465
  if (child.setRepaintFloor(repaintFloor(start, viewportTop))) changed = true;
16318
17466
  }
@@ -16467,10 +17615,12 @@ var TuiApp = class {
16467
17615
  this.pendingToolNames.set(callId, name);
16468
17616
  this.setLoaderActivity(callingActivity(name));
16469
17617
  this.upsertToolCard(callId, name, argumentsJson, "log");
17618
+ this.rememberWorkflowCall(callId, this.toolArguments.get(callId));
16470
17619
  break;
16471
17620
  }
16472
17621
  case "tool/result": {
16473
17622
  const result = event.data.message;
17623
+ this.noteWorkflowJob(result.toolCallId, result.content, result.isError === true);
16474
17624
  const block = this.toolBlocks.get(result.toolCallId);
16475
17625
  if (block === void 0) break;
16476
17626
  const isError = result.isError === true;
@@ -16489,6 +17639,27 @@ var TuiApp = class {
16489
17639
  this.syncLoaderFromPendingTools();
16490
17640
  break;
16491
17641
  }
17642
+ case "tool-workflow/run-start":
17643
+ this.startWorkflowRun(event.data);
17644
+ break;
17645
+ case "tool-workflow/agent-start":
17646
+ this.updateWorkflowRun({
17647
+ type: event.type,
17648
+ data: event.data
17649
+ });
17650
+ break;
17651
+ case "tool-workflow/agent-end":
17652
+ this.updateWorkflowRun({
17653
+ type: event.type,
17654
+ data: event.data
17655
+ });
17656
+ break;
17657
+ case "tool-workflow/run-end":
17658
+ this.updateWorkflowRun({
17659
+ type: event.type,
17660
+ data: event.data
17661
+ });
17662
+ break;
16492
17663
  case "turn/end": {
16493
17664
  this.turnStartedAt = void 0;
16494
17665
  this.updateTicker();
@@ -16526,6 +17697,183 @@ var TuiApp = class {
16526
17697
  if (event.type === "tool/call" && !this.replaying) this.tui.renderNow();
16527
17698
  }
16528
17699
  /**
17700
+ * Remember a logged workflow call until its durable run-start can claim it.
17701
+ * Durable records carry the run name and no tool-call id.
17702
+ * @param callId - the logged tool call.
17703
+ * @param args - arguments stored for that call.
17704
+ */
17705
+ rememberWorkflowCall(callId, args) {
17706
+ if (this.pendingToolNames.get(callId) !== "workflow") return;
17707
+ const parsed = workflowCallArgs(args);
17708
+ if (parsed === void 0) return;
17709
+ this.workflowCalls.set(callId, parsed);
17710
+ }
17711
+ /**
17712
+ * Claim the oldest unmatched workflow call with this run's name.
17713
+ * @param name - the durable run name.
17714
+ * @returns the call record, still stored so a later result can name its job.
17715
+ */
17716
+ claimWorkflowCall(name) {
17717
+ for (const record of this.workflowCalls.values()) if (record.runId === void 0 && record.name === name) return record;
17718
+ }
17719
+ /**
17720
+ * Fold a run-start into the session's workflow map and draw it.
17721
+ * @param data - the durable run-start payload.
17722
+ */
17723
+ startWorkflowRun(data) {
17724
+ const current = this.workflowStates.get(data.runId);
17725
+ const next = foldWorkflowRun(current, {
17726
+ type: "tool-workflow/run-start",
17727
+ data
17728
+ });
17729
+ /* v8 ignore next -- foldWorkflowRun never returns undefined for run-start */
17730
+ if (next === void 0) return;
17731
+ this.workflowStates.set(data.runId, next);
17732
+ if (current === void 0) {
17733
+ const call = this.claimWorkflowCall(data.name);
17734
+ if (call !== void 0) {
17735
+ call.runId = data.runId;
17736
+ this.workflowOwners.set(data.runId, {
17737
+ background: call.background,
17738
+ ...call.jobId === void 0 ? {} : { jobId: call.jobId }
17739
+ });
17740
+ }
17741
+ }
17742
+ this.projectWorkflow(data.runId);
17743
+ }
17744
+ /**
17745
+ * Fold one durable workflow update and redraw that run when the record changed.
17746
+ * @param event - an agent-start, agent-end, or run-end record.
17747
+ */
17748
+ updateWorkflowRun(event) {
17749
+ const current = this.workflowStates.get(event.data.runId);
17750
+ const next = foldWorkflowRun(current, event);
17751
+ if (next === void 0 || next === current) return;
17752
+ this.workflowStates.set(event.data.runId, next);
17753
+ this.projectWorkflow(event.data.runId);
17754
+ }
17755
+ /**
17756
+ * Draw one run from its durable state. Live events stay running until a
17757
+ * terminal record arrives; replay interruption is applied later.
17758
+ * @param runId - the run to project.
17759
+ */
17760
+ projectWorkflow(runId) {
17761
+ const state = this.workflowStates.get(runId);
17762
+ /* v8 ignore next -- projectWorkflow is only called after the state is stored */
17763
+ if (state === void 0) return;
17764
+ const view = projectWorkflowRun(state);
17765
+ const existing = this.workflowBlocks.get(runId);
17766
+ if (existing === void 0) {
17767
+ const block = new WorkflowBlock(this.theme, view, this.turn);
17768
+ if (this.workflowExpanded !== void 0) block.setExpanded(this.workflowExpanded);
17769
+ block.setOpenableChildren(this.liveDirectChildren());
17770
+ this.workflowBlocks.set(runId, block);
17771
+ this.chat.addChild(block);
17772
+ if (!this.replaying) this.spinWorkflow(block);
17773
+ return;
17774
+ }
17775
+ existing.setOpenableChildren(this.liveDirectChildren());
17776
+ existing.setData(view);
17777
+ }
17778
+ /**
17779
+ * After history replay, unfinished runs with no live background job are
17780
+ * interrupted. A launch turn ending is not itself an interruption.
17781
+ */
17782
+ finishWorkflowReplay() {
17783
+ for (const [runId, state] of this.workflowStates) {
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 }));
17791
+ }
17792
+ }
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
+ /**
17805
+ * Whether a background workflow is still owned by a live job in this process.
17806
+ * @param runId - the durable run.
17807
+ * @returns true while that job is running or stopping.
17808
+ */
17809
+ workflowOwnedLive(runId) {
17810
+ const owner = this.workflowOwners.get(runId);
17811
+ if (owner?.background !== true || owner.jobId === void 0) return false;
17812
+ const jobs = this.deps.ctx.get("jobs");
17813
+ if (jobs === void 0) return false;
17814
+ try {
17815
+ return isLive(jobs.get(owner.jobId, this.agent.session.id));
17816
+ } catch (error) {
17817
+ describeFailure(error);
17818
+ return false;
17819
+ }
17820
+ }
17821
+ /**
17822
+ * Attach a background job id from the workflow tool result, then drop the
17823
+ * call record once its run is known. An error before run-start drops the
17824
+ * record so a later run of the same name cannot claim it.
17825
+ * @param callId - the tool result's call.
17826
+ * @param content - the result body, which names the job when launch succeeded.
17827
+ * @param isError - whether the tool result failed.
17828
+ */
17829
+ noteWorkflowJob(callId, content, isError) {
17830
+ const call = this.workflowCalls.get(callId);
17831
+ if (call === void 0) return;
17832
+ if (call.background && !isError) {
17833
+ const rawId = /started in the background as job (\S+?)\./u.exec(contentText(content))?.[1];
17834
+ if (rawId !== void 0) {
17835
+ call.jobId = JobId(rawId);
17836
+ if (call.runId !== void 0) this.workflowOwners.set(call.runId, {
17837
+ background: call.background,
17838
+ jobId: call.jobId
17839
+ });
17840
+ }
17841
+ }
17842
+ if (call.runId !== void 0 || isError) this.workflowCalls.delete(callId);
17843
+ }
17844
+ /** Direct children of the bound session that are running in this process. */
17845
+ liveDirectChildren() {
17846
+ const ids = /* @__PURE__ */ new Set();
17847
+ const parentId = this.agent.session.id;
17848
+ const agents = this.deps.ctx.get("agents");
17849
+ for (const entry of this.subagentEntries) {
17850
+ if (entry.kind !== "child" || entry.depth !== 1) continue;
17851
+ const child = agents?.get(entry.id);
17852
+ if (child?.status === "running" && child.session.header.parentSession === parentId) ids.add(entry.id);
17853
+ }
17854
+ return ids;
17855
+ }
17856
+ /** Give every workflow block the current set of openable member sessions. */
17857
+ refreshWorkflowChildLinks() {
17858
+ if (this.workflowBlocks.size === 0) return;
17859
+ const ids = this.liveDirectChildren();
17860
+ for (const block of this.workflowBlocks.values()) block.setOpenableChildren(ids);
17861
+ }
17862
+ /**
17863
+ * Open a running workflow member without resuming a child that has finished.
17864
+ * @param target - the member row's child session and label.
17865
+ */
17866
+ async openWorkflowMember(target) {
17867
+ const entry = this.subagentEntries.find((candidate) => candidate.kind === "child" && candidate.id === target.childId);
17868
+ const child = entry === void 0 ? void 0 : this.deps.ctx.get("agents")?.get(entry.id);
17869
+ if (entry === void 0 || entry.depth !== 1 || child?.status !== "running" || child.session.header.parentSession !== this.agent.session.id) {
17870
+ this.notice("that workflow member is no longer running here");
17871
+ this.refreshWorkflowChildLinks();
17872
+ return;
17873
+ }
17874
+ await this.enterSubagent(entry.id, this.subagentBrowseRow(subagentChoice(entry)), { liveOnly: true });
17875
+ }
17876
+ /**
16529
17877
  * Fold one whole-list todo write into the turn facts: a content this
16530
17878
  * session has not carried before starts at the current turn, a known
16531
17879
  * content whose status moved records that turn, and a content the write
@@ -17159,10 +18507,9 @@ function sessionHost(ctx, core, cwd, btw) {
17159
18507
  });
17160
18508
  }, []);
17161
18509
  },
17162
- observe: async (id) => {
18510
+ observe: async (id, options) => {
17163
18511
  const resident = agents.get(id);
17164
- if (resident === void 0) return resume(id);
17165
- return {
18512
+ if (resident !== void 0 && (options?.liveOnly !== true || resident.status === "running")) return {
17166
18513
  agent: resident,
17167
18514
  selection: {
17168
18515
  current: void 0,
@@ -17171,6 +18518,8 @@ function sessionHost(ctx, core, cwd, btw) {
17171
18518
  history: await observeBoundHistory(ctx, id),
17172
18519
  dispose: () => Promise.resolve()
17173
18520
  };
18521
+ if (options?.liveOnly === true) throw new Error("that session is not running in this process");
18522
+ return resume(id);
17174
18523
  }
17175
18524
  };
17176
18525
  }