@xzzpig/pi-subagents 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +456 -4
- package/README.md +3 -3
- package/agents/claude-code-writer.md +15 -0
- package/agents/claude-code.md +15 -0
- package/agents/codex-exec-writer.md +15 -0
- package/agents/codex-exec.md +15 -0
- package/agents/cursor-agent-writer.md +14 -0
- package/agents/cursor-agent.md +14 -0
- package/agents/reviewer.md +13 -3
- package/agents/scout.md +1 -1
- package/docs/agents.md +154 -42
- package/docs/configuration.md +85 -26
- package/docs/extension-api.md +81 -16
- package/docs/missions.md +2 -0
- package/docs/models.md +75 -11
- package/docs/observability.md +34 -21
- package/docs/tool-reference.md +142 -18
- package/docs/watchdog.md +92 -114
- package/docs/workflows.md +148 -4
- package/index.ts +10 -1
- package/install.mjs +1 -1
- package/package.json +7 -6
- package/prompts/council.md +19 -7
- package/prompts/parallel-review.md +5 -1
- package/prompts/review-loop.md +11 -7
- package/skills/council-mode/SKILL.md +44 -215
- package/skills/council-mode/references/pass-contracts.md +150 -0
- package/skills/pi-subagents/SKILL.md +90 -32
- package/skills/pi-subagents/references/constraints-and-recipes.md +34 -223
- package/skills/pi-subagents/references/execution-controls.md +104 -19
- package/skills/pi-subagents/references/management-authoring-rpc.md +5 -5
- package/skills/pi-subagents/references/multi-lane-orchestration.md +16 -4
- package/skills/pi-subagents/references/prompting-and-roles.md +71 -36
- package/skills/pi-subagents/references/review-and-validation.md +73 -0
- package/src/agents/agent-management.ts +471 -114
- package/src/agents/agent-refinements.ts +4 -4
- package/src/agents/agent-serializer.ts +16 -4
- package/src/agents/agents.ts +1076 -351
- package/src/agents/builtin-names.ts +6 -0
- package/src/agents/runtime-agent-events.ts +70 -0
- package/src/agents/runtime-agent-registry.ts +31 -20
- package/src/api/agents.ts +10 -5
- package/src/api/background-work.ts +12 -3
- package/src/api/capability-ceiling.ts +0 -1
- package/src/api/{pi-args.ts → child-tool-plan.ts} +1 -1
- package/src/api/delegation.ts +0 -7
- package/src/api/external-job-provider.ts +10 -1
- package/src/api/external-runs.ts +67 -4
- package/src/api/preflight.ts +97 -34
- package/src/api/project-panes.ts +2 -0
- package/src/api/shared-types.ts +6 -0
- package/src/extension/config.ts +90 -0
- package/src/extension/doctor.ts +15 -13
- package/src/extension/fanout-child.ts +17 -16
- package/src/extension/index.ts +139 -41
- package/src/extension/public-execution.ts +113 -22
- package/src/extension/rpc.ts +182 -13
- package/src/extension/schemas.ts +63 -21
- package/src/extension/tool-description.ts +48 -23
- package/src/extension/tool-result.ts +19 -0
- package/src/inspectors/herdr/actions.ts +2 -1
- package/src/inspectors/herdr/client.ts +3 -3
- package/src/inspectors/herdr/focus.ts +55 -0
- package/src/inspectors/herdr/inspector-runner.ts +21 -23
- package/src/inspectors/herdr/project-panes.ts +228 -44
- package/src/inspectors/herdr/session-roots-codec.ts +42 -0
- package/src/integrations/herdr-status.ts +75 -5
- package/src/intercom/native-supervisor-channel.ts +138 -60
- package/src/intercom/result-intercom.ts +2 -0
- package/src/intercom/supervisor-ui.ts +243 -0
- package/src/profiles/profiles.ts +5 -6
- package/src/runs/background/active-async-capacity.ts +103 -18
- package/src/runs/background/async-execution.ts +492 -125
- package/src/runs/background/async-job-tracker.ts +127 -28
- package/src/runs/background/async-resume.ts +67 -29
- package/src/runs/background/async-retention.ts +21 -4
- package/src/runs/background/async-status-snapshot.ts +23 -261
- package/src/runs/background/async-status.ts +199 -14
- package/src/runs/background/auto-drain.ts +1 -1
- package/src/runs/background/chain-append.ts +8 -3
- package/src/runs/background/chain-root-attachment.ts +79 -8
- package/src/runs/background/control-channel.ts +101 -214
- package/src/runs/background/fleet-view.ts +38 -22
- package/src/runs/background/inspect-rpc.ts +8 -8
- package/src/runs/background/notify.ts +295 -8
- package/src/runs/background/process-terminal.ts +16 -0
- package/src/runs/background/result-delivery-ownership.ts +45 -0
- package/src/runs/background/result-files.ts +28 -14
- package/src/runs/background/result-watcher.ts +43 -19
- package/src/runs/background/resume-guidance.ts +2 -2
- package/src/runs/background/retained-children.ts +1 -1
- package/src/runs/background/run-child-session.ts +613 -0
- package/src/runs/background/run-status.ts +99 -18
- package/src/runs/background/runner-aliases.ts +125 -0
- package/src/runs/background/runner-child-sessions.ts +31 -0
- package/src/runs/background/scheduled-runs.ts +174 -18
- package/src/runs/background/stale-run-reconciler.ts +13 -4
- package/src/runs/background/steering.ts +8 -15
- package/src/runs/background/subagent-runner.ts +959 -1159
- package/src/runs/background/subagent-wait.ts +86 -31
- package/src/runs/background/terminal-run-index.ts +1 -1
- package/src/runs/background/wait-completions.ts +45 -2
- package/src/runs/background/wait-config.ts +23 -9
- package/src/runs/background/wait-tool.ts +27 -19
- package/src/runs/foreground/async-steering-action.ts +3 -19
- package/src/runs/foreground/async-stop-action.ts +23 -2
- package/src/runs/foreground/execution.ts +585 -481
- package/src/runs/foreground/foreground-control.ts +13 -0
- package/src/runs/foreground/foreground-history.ts +26 -3
- package/src/runs/foreground/subagent-executor.ts +1549 -410
- package/src/runs/foreground/workflow-detach-reconcile.ts +141 -104
- package/src/runs/foreground/workflow-foreground-steering.ts +24 -98
- package/src/runs/shared/abort-recovery.ts +119 -0
- package/src/runs/shared/acceptance.ts +147 -39
- package/src/runs/shared/agent-contract.ts +1 -1
- package/src/runs/shared/async-status-projection.ts +565 -0
- package/src/runs/shared/background-process-options.ts +9 -0
- package/src/runs/shared/capability-ceiling.ts +2 -2
- package/src/runs/shared/child-hooks.ts +25 -0
- package/src/runs/shared/child-identity.ts +62 -0
- package/src/runs/shared/child-launch-plan.ts +151 -0
- package/src/runs/shared/child-launch.ts +314 -0
- package/src/runs/shared/child-lifecycle.ts +25 -0
- package/src/runs/shared/child-runtime-config.ts +126 -0
- package/src/runs/shared/child-session.ts +342 -0
- package/src/runs/shared/child-tool-plan.ts +540 -0
- package/src/runs/shared/claude-code-adapter.ts +133 -0
- package/src/runs/shared/codex-exec-adapter.ts +129 -0
- package/src/runs/shared/completion-evidence.ts +89 -0
- package/src/runs/shared/completion-guard.ts +57 -6
- package/src/runs/shared/cursor-agent-adapter.ts +114 -0
- package/src/runs/shared/dynamic-fanout.ts +4 -4
- package/src/runs/shared/extension-bindings.ts +78 -0
- package/src/runs/shared/external-cli-contract.ts +167 -0
- package/src/runs/shared/external-cli-preflight.ts +138 -0
- package/src/runs/shared/external-cli-runner.ts +349 -54
- package/src/runs/shared/external-job-bridge.ts +53 -37
- package/src/runs/shared/external-job-runner.ts +126 -23
- package/src/runs/shared/fast-mode-extension.ts +10 -0
- package/src/runs/shared/host-step-status.ts +231 -0
- package/src/runs/shared/lane-metadata.ts +126 -0
- package/src/runs/shared/launch-cwd.ts +16 -0
- package/src/runs/shared/long-running-guard.ts +2 -1
- package/src/runs/shared/mcp-config-sources.ts +422 -0
- package/src/runs/shared/mcp-direct-tool-allowlist.ts +222 -158
- package/src/runs/shared/mcp-direct-tool-grant.ts +194 -0
- package/src/runs/shared/model-exclusions.ts +141 -10
- package/src/runs/shared/model-fallback.ts +187 -33
- package/src/runs/shared/model-scope.ts +106 -39
- package/src/runs/shared/mutation-evidence.ts +199 -0
- package/src/runs/shared/nested-events.ts +38 -48
- package/src/runs/shared/nested-path.ts +0 -14
- package/src/runs/shared/nested-render.ts +9 -5
- package/src/runs/shared/orca-progress-tabs.ts +83 -16
- package/src/runs/shared/parallel-handoff.ts +423 -7
- package/src/runs/shared/parallel-utils.ts +28 -5
- package/src/runs/shared/permissions.ts +1 -14
- package/src/runs/shared/pi-spawn.ts +69 -35
- package/src/runs/shared/process-signal.ts +16 -0
- package/src/runs/shared/run-fanout-budget.ts +0 -13
- package/src/runs/shared/run-history.ts +21 -1
- package/src/runs/shared/runtime-acknowledged-extensions.ts +0 -27
- package/src/runs/shared/single-output.ts +89 -22
- package/src/runs/shared/structured-output.ts +61 -7
- package/src/runs/shared/subagent-control.ts +6 -2
- package/src/runs/shared/subagent-prompt-runtime.ts +216 -360
- package/src/runs/shared/task-intent.ts +21 -7
- package/src/runs/shared/tool-availability.ts +18 -64
- package/src/runs/shared/tool-budget.ts +0 -14
- package/src/runs/shared/tool-timeout.ts +1 -1
- package/src/runs/shared/workflow-graph.ts +16 -0
- package/src/runs/shared/worktree-cleanup-plan.ts +866 -0
- package/src/runs/shared/worktree.ts +571 -62
- package/src/shared/atomic-json.ts +3 -1
- package/src/shared/child-session-name.ts +46 -0
- package/src/shared/extension-context.ts +24 -0
- package/src/shared/fork-context.ts +21 -12
- package/src/shared/fork-session-cwd.ts +27 -0
- package/src/shared/formatters.ts +18 -3
- package/src/shared/jsonl-writer.ts +11 -0
- package/src/shared/launch-contract.ts +20 -6
- package/src/shared/pruned-fork.ts +450 -0
- package/src/shared/session-file-trust.ts +19 -0
- package/src/shared/session-tokens.ts +14 -3
- package/src/shared/settings.ts +21 -102
- package/src/shared/shortcuts.ts +17 -0
- package/src/shared/thinking-ceiling.ts +46 -0
- package/src/shared/types.ts +644 -75
- package/src/shared/utils.ts +60 -93
- package/src/shared/workflow-child-permit.ts +207 -0
- package/src/slash/delegation-adapters.ts +1 -9
- package/src/slash/delegation-request.ts +0 -4
- package/src/slash/prompt-template-bridge.ts +37 -1
- package/src/slash/slash-bridge.ts +1 -2
- package/src/slash/slash-commands.ts +383 -116
- package/src/slash/slash-live-state.ts +22 -11
- package/src/slash/subagents-admin.ts +29 -12
- package/src/tui/fleet-native-transcript.ts +4 -0
- package/src/tui/fleet-status.ts +278 -90
- package/src/tui/fleet-transcript.ts +11 -5
- package/src/tui/fleet.ts +54 -28
- package/src/tui/render-helpers.ts +31 -0
- package/src/tui/render.ts +1433 -166
- package/src/watchdog/change-signature.ts +40 -1
- package/src/watchdog/child-status.ts +54 -34
- package/src/watchdog/diff-tool.ts +77 -0
- package/src/watchdog/emission-guard.ts +5 -3
- package/src/watchdog/guidance.ts +20 -0
- package/src/watchdog/permission-arbiter.ts +59 -52
- package/src/watchdog/register-child.ts +28 -25
- package/src/watchdog/register-main.ts +10 -9
- package/src/watchdog/render.ts +4 -5
- package/src/watchdog/review.ts +15 -4
- package/src/watchdog/rules.ts +70 -0
- package/src/watchdog/runtime.ts +75 -92
- package/src/watchdog/scope.ts +0 -11
- package/src/watchdog/settings.ts +48 -104
- package/src/watchdog/turn-delta.ts +1 -1
- package/src/watchdog/types.ts +18 -32
- package/src/watchdog/warning-format.ts +0 -1
- package/src/workflows/chat-progress.ts +7 -3
- package/src/workflows/host-command.ts +235 -0
- package/src/workflows/scripted-workflow.ts +1142 -69
- package/src/workflows/workflow-checklist.ts +439 -0
- package/src/workflows/workflow-child-summary.ts +121 -0
- package/src/workflows/workflow-preflight.ts +297 -0
- package/src/workflows/workflow-receipt.ts +232 -6
- package/src/workflows/workflow-resources.ts +150 -0
- package/src/workflows/workflow-settlement.ts +246 -0
- package/src/runs/shared/child-protocol.ts +0 -401
- package/src/runs/shared/pi-args.ts +0 -858
- package/src/runs/shared/subagent-startup-retry.ts +0 -116
- package/src/runs/shared/turn-budget.ts +0 -98
- package/src/shared/post-exit-stdio-guard.ts +0 -85
package/src/tui/render.ts
CHANGED
|
@@ -7,32 +7,53 @@ import { createHash } from "node:crypto";
|
|
|
7
7
|
import type { AgentToolResult } from "@earendil-works/pi-agent-core";
|
|
8
8
|
import { getMarkdownTheme, keyText, type ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
9
9
|
import { Container, Markdown, Spacer, Text, visibleWidth, type Component } from "@earendil-works/pi-tui";
|
|
10
|
+
import { unresolvedChildWatchdogBlockers } from "../watchdog/child-status.ts";
|
|
10
11
|
import {
|
|
11
12
|
type AgentProgress,
|
|
12
13
|
type AsyncJobState,
|
|
13
14
|
type AsyncJobStep,
|
|
14
15
|
type AsyncParallelGroupStatus,
|
|
15
16
|
type Details,
|
|
17
|
+
type HostStepState,
|
|
18
|
+
type HostStepVerdict,
|
|
16
19
|
type NestedRunSummary,
|
|
17
20
|
type NestedStepSummary,
|
|
21
|
+
type WorkflowGraphNode,
|
|
18
22
|
type WorkflowNodeStatus,
|
|
19
23
|
type MainWindowRendererConfig,
|
|
20
24
|
MAX_WIDGET_JOBS,
|
|
21
|
-
|
|
25
|
+
WIDGET_ANIMATION_INTERVAL_MS,
|
|
22
26
|
WIDGET_KEY,
|
|
23
27
|
} from "../shared/types.ts";
|
|
24
|
-
import { sanitizeDisplayText, truncateDisplayText } from "../shared/display-text.ts";
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
28
|
+
import { previewDisplayText, sanitizeDisplayText, truncateDisplayText } from "../shared/display-text.ts";
|
|
29
|
+
import { FLEET_OPEN_SHORTCUT, formatShortcutLabel } from "../shared/shortcuts.ts";
|
|
30
|
+
import { formatContextUsage, formatTokens, formatUsage, formatDuration, formatModelThinking, formatToolCall, formatTokenUsage, shortenPath } from "../shared/formatters.ts";
|
|
31
|
+
import { getDisplayItems, getSingleResultOutput, PROMPT_REDACTED } from "../shared/utils.ts";
|
|
27
32
|
import { flatToLogicalStepIndex } from "../runs/background/parallel-groups.ts";
|
|
28
33
|
import { formatNestedAggregate } from "../runs/shared/nested-render.ts";
|
|
29
34
|
import { aggregateStepStatus, formatActivityLabel, formatAgentRunningLabel, formatParallelOutcome } from "../shared/status-format.ts";
|
|
30
35
|
import { contextModeBadge, contextModePrefix } from "../runs/shared/context-mode.ts";
|
|
36
|
+
import { shouldSuppressSingleStep, stripRepeatedAgentPrefix, withDuplicateLabelDiscriminators } from "./render-helpers.ts";
|
|
31
37
|
import { buildWorkflowChatProgressRows, type WorkflowChatProgressRow } from "../workflows/chat-progress.ts";
|
|
38
|
+
import { formatWorkflowPreflight, formatWorkflowPreflightPlanSummary, formatWorkflowPreflightWarningSummary, formatWorkflowPreflightWarnings } from "../workflows/workflow-preflight.ts";
|
|
32
39
|
import { encodeAsyncStatusSnapshotWidget } from "../runs/background/async-status-snapshot.ts";
|
|
40
|
+
import { projectAsyncWorkflowRows, type AsyncStatusWorkflowRow } from "../runs/shared/async-status-projection.ts";
|
|
41
|
+
import { hostStepReportName, hostStepVerdictLabel } from "../runs/shared/host-step-status.ts";
|
|
42
|
+
import { workflowGraphStageNodes } from "../runs/shared/workflow-graph.ts";
|
|
43
|
+
import { formatWorkflowChecklistBottleneck, formatWorkflowChecklistPhase, formatWorkflowChecklistSummary, projectWorkflowChecklist, type WorkflowChecklistItem, type WorkflowChecklistProjection, type WorkflowChecklistState, type WorkflowChecklistStep } from "../workflows/workflow-checklist.ts";
|
|
33
44
|
|
|
34
45
|
type Theme = ExtensionContext["ui"]["theme"];
|
|
35
46
|
|
|
47
|
+
interface WorkflowWidgetProjection {
|
|
48
|
+
stages: WorkflowGraphNode[];
|
|
49
|
+
steps: AsyncJobStep[];
|
|
50
|
+
stageProgress?: { total: number; current?: number };
|
|
51
|
+
plannedKeys?: Set<string>;
|
|
52
|
+
checklist?: WorkflowChecklistProjection;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
type WorkflowWidgetProjectionLookup = (job: AsyncJobState) => WorkflowWidgetProjection;
|
|
56
|
+
|
|
36
57
|
interface MainWindowRenderLayout {
|
|
37
58
|
horizontalSpacing: number;
|
|
38
59
|
compactResultMaxLines?: number;
|
|
@@ -69,23 +90,17 @@ function liveDetailKeyText(): string {
|
|
|
69
90
|
return keyText("app.tools.expand");
|
|
70
91
|
}
|
|
71
92
|
|
|
72
|
-
function liveDetailHintText(): string {
|
|
73
|
-
return `Press ${liveDetailKeyText()} for live detail`;
|
|
93
|
+
export function liveDetailHintText(): string {
|
|
94
|
+
return `Press ${liveDetailKeyText()} for live detail · ${formatShortcutLabel(FLEET_OPEN_SHORTCUT)} Fleet`;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function workflowDetailHintText(): string {
|
|
98
|
+
return `Press ${liveDetailKeyText()} for details · ${formatShortcutLabel(FLEET_OPEN_SHORTCUT)} Fleet`;
|
|
74
99
|
}
|
|
75
100
|
|
|
76
101
|
function foregroundSingleHintText(shortcut?: string): string {
|
|
77
102
|
if (!shortcut) return liveDetailHintText();
|
|
78
|
-
const label = shortcut
|
|
79
|
-
.split("+")
|
|
80
|
-
.map((part) => {
|
|
81
|
-
const normalized = part.trim().toLowerCase();
|
|
82
|
-
if (normalized === "ctrl") return "Ctrl";
|
|
83
|
-
if (normalized === "alt") return "Alt";
|
|
84
|
-
if (normalized === "shift") return "Shift";
|
|
85
|
-
if (normalized === "super") return "Super";
|
|
86
|
-
return normalized.length === 1 ? normalized.toUpperCase() : part.trim();
|
|
87
|
-
})
|
|
88
|
-
.join("+");
|
|
103
|
+
const label = formatShortcutLabel(shortcut);
|
|
89
104
|
return `${liveDetailHintText()} · ${label} to run in background`;
|
|
90
105
|
}
|
|
91
106
|
|
|
@@ -263,6 +278,7 @@ const noisyStatusPatterns = [
|
|
|
263
278
|
/^(?:checking|fetching|reading|inspecting|verifying|collecting|confirming|polling)\b/i,
|
|
264
279
|
/^(?:async\s+subagent\s+)?[\w.-]+\s*·\s*(?:step|agent)\s+\d+\/\d+\s*·/i,
|
|
265
280
|
/^(?:Step|Agent)\s+\d+\/\d+:\s+[\w.-]+\s*·\s*(?:running|queued|pending|complete|completed)\b/i,
|
|
281
|
+
/^(?:async\s+subagent\s+)?[\w.-]+(?:\s+\[(?:fresh|fork|mixed)\])?\s*·\s*(?:running|queued|pending|complete|completed|done)\b/i,
|
|
266
282
|
/^Press\s+\S+\s+for\s+live\s+detail$/i,
|
|
267
283
|
/^output:\s+.+\/async-subagent-runs\//i,
|
|
268
284
|
];
|
|
@@ -273,6 +289,397 @@ function oneLine(text: string): string {
|
|
|
273
289
|
return text.replace(ansiEscapePattern, "").replace(/\s+/g, " ").trim();
|
|
274
290
|
}
|
|
275
291
|
|
|
292
|
+
const COMPACT_TASK_MAX_CHARS = 96;
|
|
293
|
+
|
|
294
|
+
/** Display label for a child run: the derived session name (agent + task
|
|
295
|
+
* excerpt) when the launcher provided one, else the bare agent name. */
|
|
296
|
+
function childDisplayName(result: { agent?: string; sessionName?: string } | undefined, fallback = "subagent"): string {
|
|
297
|
+
return result?.sessionName?.trim() || result?.agent || fallback;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
export function compactTaskText(task: string | undefined, label?: string): string | undefined {
|
|
301
|
+
const taskText = task?.trim();
|
|
302
|
+
const labelText = label?.trim();
|
|
303
|
+
const normalizedTask = taskText && taskText !== PROMPT_REDACTED ? oneLine(taskText) : "";
|
|
304
|
+
const normalizedLabel = labelText && labelText !== PROMPT_REDACTED ? oneLine(labelText) : "";
|
|
305
|
+
const normalized = normalizedLabel && normalizedTask && normalizedLabel !== normalizedTask
|
|
306
|
+
? `${normalizedLabel} — ${normalizedTask}`
|
|
307
|
+
: normalizedLabel || normalizedTask;
|
|
308
|
+
if (!normalized) return undefined;
|
|
309
|
+
return previewDisplayText(normalized, COMPACT_TASK_MAX_CHARS);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
export interface AsyncLaneProjection {
|
|
313
|
+
label?: string;
|
|
314
|
+
role: string;
|
|
315
|
+
phase?: string;
|
|
316
|
+
state: AsyncJobState["status"] | AsyncJobStep["status"];
|
|
317
|
+
gate?: string;
|
|
318
|
+
next?: string;
|
|
319
|
+
output?: string;
|
|
320
|
+
workspace?: string;
|
|
321
|
+
ref: string;
|
|
322
|
+
chips: string[];
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
const LANE_VALUE_MAX_CHARS = 48;
|
|
326
|
+
|
|
327
|
+
function boundedLaneValue(value: string | undefined, maxChars = LANE_VALUE_MAX_CHARS): string | undefined {
|
|
328
|
+
if (!value?.trim() || value.trim() === PROMPT_REDACTED) return undefined;
|
|
329
|
+
return previewDisplayText(oneLine(value), maxChars);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function workflowNodeStepStatus(status: WorkflowNodeStatus): AsyncJobStep["status"] {
|
|
333
|
+
switch (status) {
|
|
334
|
+
case "completed":
|
|
335
|
+
return "completed";
|
|
336
|
+
case "detached":
|
|
337
|
+
return "paused";
|
|
338
|
+
default:
|
|
339
|
+
return status;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
function workflowNodeStatusLabel(status: WorkflowNodeStatus): string {
|
|
344
|
+
switch (status) {
|
|
345
|
+
case "completed":
|
|
346
|
+
return "complete";
|
|
347
|
+
case "detached":
|
|
348
|
+
return "paused";
|
|
349
|
+
default:
|
|
350
|
+
return status;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
function workflowStepPriority(step: AsyncJobStep, currentNodeId?: string): number {
|
|
355
|
+
const isCurrent = step.workflowKey === currentNodeId;
|
|
356
|
+
if (step.status === "running" || (isCurrent && step.status !== "complete" && step.status !== "completed")) return 0;
|
|
357
|
+
const gate = laneGate(step);
|
|
358
|
+
if (
|
|
359
|
+
step.status === "failed"
|
|
360
|
+
|| step.status === "partial"
|
|
361
|
+
|| step.status === "paused"
|
|
362
|
+
|| step.status === "stopped"
|
|
363
|
+
|| step.status === "rejected"
|
|
364
|
+
|| step.toolBudgetBlocked === true
|
|
365
|
+
|| step.turnBudgetExceeded === true
|
|
366
|
+
|| step.activityState === "needs_attention"
|
|
367
|
+
|| step.watchdog?.phase === "stale"
|
|
368
|
+
|| unresolvedChildWatchdogBlockers(step.watchdog).length > 0
|
|
369
|
+
|| gate !== undefined
|
|
370
|
+
) return 1;
|
|
371
|
+
if (step.status === "pending") return 2;
|
|
372
|
+
return 3;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/** Merge materialized child rows with the planned workflow stages for rendering. */
|
|
376
|
+
function workflowWidgetSteps(job: AsyncJobState, planned = job.mode === "workflow" ? workflowGraphStageNodes(job.workflowGraph) : []): AsyncJobStep[] {
|
|
377
|
+
const loaded = job.steps ?? [];
|
|
378
|
+
if (planned.length === 0) return loaded;
|
|
379
|
+
|
|
380
|
+
const loadedIndexesByKey = new Map<string, number[]>();
|
|
381
|
+
for (const [index, step] of loaded.entries()) {
|
|
382
|
+
if (!step.workflowKey) continue;
|
|
383
|
+
const indexes = loadedIndexesByKey.get(step.workflowKey) ?? [];
|
|
384
|
+
indexes.push(index);
|
|
385
|
+
loadedIndexesByKey.set(step.workflowKey, indexes);
|
|
386
|
+
}
|
|
387
|
+
const consumed = new Set<number>();
|
|
388
|
+
const entries: Array<{ step: AsyncJobStep; order: number }> = [];
|
|
389
|
+
for (const [order, node] of planned.entries()) {
|
|
390
|
+
const loadedIndex = loadedIndexesByKey.get(node.id)?.find((index) => !consumed.has(index));
|
|
391
|
+
if (loadedIndex !== undefined) {
|
|
392
|
+
consumed.add(loadedIndex);
|
|
393
|
+
const loadedStep = loaded[loadedIndex]!;
|
|
394
|
+
entries.push({
|
|
395
|
+
step: {
|
|
396
|
+
...loadedStep,
|
|
397
|
+
index: node.flatIndex ?? loadedStep.index ?? order,
|
|
398
|
+
agent: loadedStep.agent || node.agent || job.agents?.[0] || "workflow",
|
|
399
|
+
phase: loadedStep.phase ?? node.phase,
|
|
400
|
+
label: loadedStep.label ?? node.label,
|
|
401
|
+
workflowKey: loadedStep.workflowKey ?? node.id,
|
|
402
|
+
...(loadedStep.outputName === undefined && node.outputName !== undefined ? { outputName: node.outputName } : {}),
|
|
403
|
+
...(loadedStep.structured === undefined && node.structured !== undefined ? { structured: node.structured } : {}),
|
|
404
|
+
...(loadedStep.error === undefined && node.error !== undefined ? { error: node.error } : {}),
|
|
405
|
+
},
|
|
406
|
+
order,
|
|
407
|
+
});
|
|
408
|
+
continue;
|
|
409
|
+
}
|
|
410
|
+
entries.push({
|
|
411
|
+
step: {
|
|
412
|
+
index: node.flatIndex ?? order,
|
|
413
|
+
agent: node.agent ?? job.agents?.[0] ?? "workflow",
|
|
414
|
+
status: workflowNodeStepStatus(node.status),
|
|
415
|
+
workflowKey: node.id,
|
|
416
|
+
label: node.label,
|
|
417
|
+
...(node.phase ? { phase: node.phase } : {}),
|
|
418
|
+
...(node.outputName ? { outputName: node.outputName } : {}),
|
|
419
|
+
...(node.structured !== undefined ? { structured: node.structured } : {}),
|
|
420
|
+
...(node.error ? { error: node.error } : {}),
|
|
421
|
+
},
|
|
422
|
+
order,
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
for (const [index, step] of loaded.entries()) {
|
|
426
|
+
if (!consumed.has(index)) entries.push({ step, order: planned.length + index });
|
|
427
|
+
}
|
|
428
|
+
entries.sort((left, right) => workflowStepPriority(left.step, job.workflowGraph?.currentNodeId) - workflowStepPriority(right.step, job.workflowGraph?.currentNodeId) || left.order - right.order);
|
|
429
|
+
return entries.map(({ step }) => step);
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
function workflowStageProgress(job: AsyncJobState, stages = job.mode === "workflow" ? workflowGraphStageNodes(job.workflowGraph) : []): { total: number; current?: number } | undefined {
|
|
433
|
+
if (job.mode !== "workflow") return undefined;
|
|
434
|
+
if (stages.length === 0) return undefined;
|
|
435
|
+
const currentId = job.workflowGraph?.currentNodeId;
|
|
436
|
+
const currentIndex = currentId ? stages.findIndex((stage) => stage.id === currentId) : -1;
|
|
437
|
+
if (currentIndex >= 0 && stages[currentIndex]?.status !== "completed") return { total: stages.length, current: currentIndex };
|
|
438
|
+
const runningIndex = stages.findIndex((stage) => stage.status === "running");
|
|
439
|
+
if (runningIndex >= 0) return { total: stages.length, current: runningIndex };
|
|
440
|
+
const indexedStage = job.currentStep !== undefined && job.currentStep >= 0 ? stages[job.currentStep] : undefined;
|
|
441
|
+
if (indexedStage && indexedStage.status !== "completed") return { total: stages.length, current: job.currentStep };
|
|
442
|
+
if (stages.every((stage) => stage.status === "completed")) return { total: stages.length, current: stages.length - 1 };
|
|
443
|
+
return { total: stages.length };
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
function buildWorkflowWidgetProjection(job: AsyncJobState): WorkflowWidgetProjection {
|
|
447
|
+
const stages = job.mode === "workflow" ? workflowGraphStageNodes(job.workflowGraph) : [];
|
|
448
|
+
const stageProgress = workflowStageProgress(job, stages);
|
|
449
|
+
const steps = workflowWidgetSteps(job, stages);
|
|
450
|
+
const projection: WorkflowWidgetProjection = { stages, steps };
|
|
451
|
+
if (stageProgress) projection.stageProgress = stageProgress;
|
|
452
|
+
if (stages.length) projection.plannedKeys = new Set(stages.map((node) => node.id));
|
|
453
|
+
if (job.mode === "workflow") {
|
|
454
|
+
const checklist = projectWorkflowChecklist({
|
|
455
|
+
graph: job.workflowGraph,
|
|
456
|
+
steps: job.steps,
|
|
457
|
+
hostSteps: job.hostSteps,
|
|
458
|
+
preflight: job.preflight,
|
|
459
|
+
trace: job.workflow?.trace,
|
|
460
|
+
now: job.updatedAt ?? Date.now(),
|
|
461
|
+
});
|
|
462
|
+
if (checklist.total > 0) projection.checklist = checklist;
|
|
463
|
+
}
|
|
464
|
+
return projection;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
function workflowWidgetProjectionLookup(): WorkflowWidgetProjectionLookup {
|
|
468
|
+
const projections = new WeakMap<AsyncJobState, WorkflowWidgetProjection>();
|
|
469
|
+
return (job: AsyncJobState) => {
|
|
470
|
+
const cached = projections.get(job);
|
|
471
|
+
if (cached) return cached;
|
|
472
|
+
const projection = buildWorkflowWidgetProjection(job);
|
|
473
|
+
projections.set(job, projection);
|
|
474
|
+
return projection;
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
function laneStepForJob(job: AsyncJobState, steps = workflowWidgetSteps(job)): AsyncJobStep | undefined {
|
|
479
|
+
if (steps.length === 0) return undefined;
|
|
480
|
+
const graphCurrent = job.workflowGraph?.currentNodeId;
|
|
481
|
+
if (graphCurrent) {
|
|
482
|
+
const current = steps.find((step) => step.workflowKey === graphCurrent);
|
|
483
|
+
if (current) return current;
|
|
484
|
+
}
|
|
485
|
+
if (job.currentStep !== undefined) {
|
|
486
|
+
const current = steps[job.currentStep];
|
|
487
|
+
if (current && (current.index === undefined || current.index === job.currentStep)) return current;
|
|
488
|
+
// Active parallel groups retain flat indices while exposing only the group slice.
|
|
489
|
+
const indexedCurrent = steps.find((step) => step.index === job.currentStep);
|
|
490
|
+
if (indexedCurrent) return indexedCurrent;
|
|
491
|
+
return steps[0];
|
|
492
|
+
}
|
|
493
|
+
return steps.find((step) => step.status === "running")
|
|
494
|
+
?? steps.find((step) => step.status === "pending")
|
|
495
|
+
?? steps.at(-1);
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
function laneTraceForJob(job: AsyncJobState): NonNullable<AsyncJobState["workflow"]>["trace"][number] | undefined {
|
|
499
|
+
return Array.isArray(job.workflow?.trace) ? job.workflow.trace.at(-1) : undefined;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
function laneGate(step: AsyncJobStep | undefined): string | undefined {
|
|
503
|
+
const review = step?.review?.status ?? step?.acceptance?.reviewResult?.status;
|
|
504
|
+
if (review === "blockers") return "review blockers";
|
|
505
|
+
if (review === "review-required") return "review required";
|
|
506
|
+
if (review === "reviewed") return "reviewed";
|
|
507
|
+
const acceptance = step?.acceptance?.status;
|
|
508
|
+
if (acceptance === "review-required") return "acceptance review";
|
|
509
|
+
if (acceptance === "checked" || acceptance === "verified" || acceptance === "accepted") return "acceptance";
|
|
510
|
+
return undefined;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
function laneNextAction(state: AsyncLaneProjection["state"], step: AsyncJobStep | undefined, output: string | undefined, gate: string | undefined): string | undefined {
|
|
514
|
+
if (unresolvedChildWatchdogBlockers(step?.watchdog).length > 0) return "resolve watchdog blockers";
|
|
515
|
+
if (step?.watchdog?.phase === "stale") return "inspect stale state";
|
|
516
|
+
if (step?.toolBudgetBlocked === true || step?.turnBudgetExceeded === true) return "inspect blocked state";
|
|
517
|
+
if (gate === "review blockers") return "resolve review blockers";
|
|
518
|
+
if (gate === "review required" || gate === "acceptance review") return "review output";
|
|
519
|
+
if (step?.activityState === "needs_attention") return "inspect attention";
|
|
520
|
+
if (state === "queued" || state === "pending") return "await launch";
|
|
521
|
+
if (state === "failed" || state === "rejected") return "inspect failure";
|
|
522
|
+
if (state === "partial") return "inspect partial state";
|
|
523
|
+
if (state === "paused") return "inspect paused state";
|
|
524
|
+
if (state === "stopped") return "inspect stopped state";
|
|
525
|
+
if ((state === "complete" || state === "completed") && gate === "reviewed") return "ready";
|
|
526
|
+
if ((state === "complete" || state === "completed") && output) return "inspect output";
|
|
527
|
+
return undefined;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
function isTerminalLaneState(state: AsyncJobState["status"]): boolean {
|
|
531
|
+
return state !== "queued" && state !== "running";
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
/** Project already-loaded async status facts into one bounded, render-only lane row. */
|
|
535
|
+
export function projectAsyncLane(job: AsyncJobState, ...args: [selectedStep?: AsyncJobStep]): AsyncLaneProjection | undefined {
|
|
536
|
+
const selectedStep = args.length === 0 ? laneStepForJob(job) : args[0];
|
|
537
|
+
const trace = laneTraceForJob(job);
|
|
538
|
+
const workspace = job.cwd ? boundedLaneValue(shortenPath(job.cwd)) : undefined;
|
|
539
|
+
const label = compactTaskText(selectedStep?.description, selectedStep?.label)
|
|
540
|
+
?? boundedLaneValue(trace?.label)
|
|
541
|
+
?? (workspace ? undefined : boundedLaneValue(selectedStep?.workflowKey ?? job.workflowKey));
|
|
542
|
+
const role = boundedLaneValue(selectedStep?.agent ?? trace?.agent ?? job.agents?.[0] ?? widgetJobName(job), 32) ?? "subagent";
|
|
543
|
+
const phase = boundedLaneValue(selectedStep?.phase ?? trace?.phase);
|
|
544
|
+
const gate = laneGate(selectedStep);
|
|
545
|
+
const output = boundedLaneValue(selectedStep?.outputName);
|
|
546
|
+
const ref = boundedLaneValue(selectedStep?.workflowKey ?? job.workflowKey ?? job.asyncId.slice(0, 8), 24) ?? job.asyncId.slice(0, 8);
|
|
547
|
+
const chips = [
|
|
548
|
+
selectedStep?.context,
|
|
549
|
+
selectedStep?.structured ? "structured" : undefined,
|
|
550
|
+
selectedStep?.activityState === "active_long_running" ? "long-running" : undefined,
|
|
551
|
+
selectedStep?.activityState === "needs_attention" ? "attention" : undefined,
|
|
552
|
+
selectedStep?.watchdog?.phase === "stale" ? "stale" : undefined,
|
|
553
|
+
unresolvedChildWatchdogBlockers(selectedStep?.watchdog).length > 0 ? `wd:${unresolvedChildWatchdogBlockers(selectedStep?.watchdog).length}` : undefined,
|
|
554
|
+
selectedStep?.toolBudgetBlocked === true || selectedStep?.turnBudgetExceeded === true ? "blocked" : undefined,
|
|
555
|
+
].filter((chip): chip is string => Boolean(chip));
|
|
556
|
+
const state = isTerminalLaneState(job.status) ? job.status : selectedStep?.status ?? job.status;
|
|
557
|
+
const next = laneNextAction(state, selectedStep, output, gate);
|
|
558
|
+
if (!label && !phase && !gate && !output && !selectedStep?.workflowKey && !job.workflowKey && !trace?.label && !trace?.phase) return undefined;
|
|
559
|
+
return { ...(label ? { label } : {}), role, ...(phase ? { phase } : {}), state, ...(gate ? { gate } : {}), ...(next ? { next } : {}), ...(output ? { output } : {}), ...(workspace ? { workspace } : {}), ref, chips };
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
function laneStateLabel(state: AsyncLaneProjection["state"], theme: Theme): string {
|
|
563
|
+
if (state === "running") return theme.fg("accent", "running");
|
|
564
|
+
if (state === "queued" || state === "pending") return theme.fg("muted", state);
|
|
565
|
+
if (state === "complete" || state === "completed") return theme.fg("success", "complete");
|
|
566
|
+
if (state === "failed" || state === "rejected") return theme.fg("error", state === "rejected" ? "rejected" : "failed");
|
|
567
|
+
return theme.fg("warning", state);
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
function formatLaneProjection(lane: AsyncLaneProjection, theme: Theme): string {
|
|
571
|
+
const label = boundedLaneValue(lane.label, 56);
|
|
572
|
+
const identity = [label, lane.role ? `role:${lane.role}` : undefined].filter(Boolean).join(" · ");
|
|
573
|
+
return `${identity ? theme.bold(identity) : theme.bold(lane.role)} · ${laneStateLabel(lane.state, theme)}`;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
function formatLaneChip(chip: string, theme: Theme): string {
|
|
577
|
+
const text = `[${chip}]`;
|
|
578
|
+
if (chip === "blocked") return theme.fg("error", text);
|
|
579
|
+
if (chip === "stale") return theme.fg("warning", text);
|
|
580
|
+
return text;
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
function formatLaneProjectionDetails(lane: AsyncLaneProjection, theme: Theme): string | undefined {
|
|
584
|
+
const details = [
|
|
585
|
+
lane.phase ? `phase:${lane.phase}` : undefined,
|
|
586
|
+
lane.gate ? `gate:${lane.gate}` : undefined,
|
|
587
|
+
lane.next ? `next:${lane.next}` : undefined,
|
|
588
|
+
lane.output ? `out:${lane.output}` : undefined,
|
|
589
|
+
lane.workspace ? `workspace:${lane.workspace}` : lane.ref ? `ref:${lane.ref}` : undefined,
|
|
590
|
+
].filter(Boolean);
|
|
591
|
+
const chips = lane.chips.map((chip) => formatLaneChip(chip, theme));
|
|
592
|
+
return [...(details.length ? [theme.fg("dim", details.join(" · "))] : []), ...chips].join(" · ") || undefined;
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
function formatLaneProjectionLines(lane: AsyncLaneProjection, theme: Theme, indent: string): string[] {
|
|
596
|
+
const details = formatLaneProjectionDetails(lane, theme);
|
|
597
|
+
return [
|
|
598
|
+
`${indent}${formatLaneProjection(lane, theme)}`,
|
|
599
|
+
...(details ? [`${indent} ${details}`] : []),
|
|
600
|
+
];
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
function laneRenderKey(job: AsyncJobState, projection?: WorkflowWidgetProjection): unknown {
|
|
604
|
+
const selectedStep = projection ? laneStepForJob(job, projection.steps) : laneStepForJob(job);
|
|
605
|
+
const lane = projectAsyncLane(job, selectedStep);
|
|
606
|
+
return lane ? [lane.label, lane.role, lane.phase, lane.state, lane.gate, lane.next, lane.output, lane.workspace, lane.ref, lane.chips] : undefined;
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
function widgetLaneDetailLines(job: AsyncJobState, theme: Theme, projection?: WorkflowWidgetProjection): string[] {
|
|
610
|
+
if (job.steps?.length && (job.mode === "parallel" || job.mode === "chain")) return [];
|
|
611
|
+
const selectedStep = projection ? laneStepForJob(job, projection.steps) : laneStepForJob(job);
|
|
612
|
+
const lane = projectAsyncLane(job, selectedStep);
|
|
613
|
+
return lane ? formatLaneProjectionLines(lane, theme, " ") : [];
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
function workflowPreflightLines(job: AsyncJobState): string[] {
|
|
617
|
+
if (job.mode !== "workflow" || !job.preflight) return [];
|
|
618
|
+
return [
|
|
619
|
+
...formatWorkflowPreflight(job.preflight, { indent: " " }).split("\n"),
|
|
620
|
+
...(job.workflow?.preflightWarnings ? formatWorkflowPreflightWarnings(job.workflow.preflightWarnings, { indent: " " }).split("\n") : []),
|
|
621
|
+
];
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
function workflowLabelForResult(details: Details, resultIndex: number): string | undefined {
|
|
625
|
+
const flatIndex = foregroundResultIndex(details, resultIndex);
|
|
626
|
+
const visit = (nodes: NonNullable<Details["workflowGraph"]>["nodes"]): string | undefined => {
|
|
627
|
+
for (const node of nodes) {
|
|
628
|
+
if (node.flatIndex === flatIndex && node.label.trim()) return node.label;
|
|
629
|
+
const nested = node.children ? visit(node.children) : undefined;
|
|
630
|
+
if (nested) return nested;
|
|
631
|
+
}
|
|
632
|
+
return undefined;
|
|
633
|
+
};
|
|
634
|
+
return details.workflowGraph ? visit(details.workflowGraph.nodes) : undefined;
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
function foregroundProgressForResult(details: Details, resultIndex: number): AgentProgress | undefined {
|
|
638
|
+
const result = details.results[resultIndex];
|
|
639
|
+
if (result?.progress) return result.progress;
|
|
640
|
+
const index = result?.index ?? resultIndex;
|
|
641
|
+
const indexed = details.progress?.find((progress) => progress.index === index);
|
|
642
|
+
if (indexed) return indexed;
|
|
643
|
+
return result?.agent
|
|
644
|
+
? details.progress?.find((progress) => progress.agent === result.agent && progress.status === "running")
|
|
645
|
+
: undefined;
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
function foregroundResultIndex(details: Details, resultIndex: number): number {
|
|
649
|
+
const result = details.results[resultIndex];
|
|
650
|
+
if (typeof result?.index === "number") return result.index;
|
|
651
|
+
return foregroundProgressForResult(details, resultIndex)?.index ?? resultIndex;
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
function foregroundResultDisplayName(
|
|
655
|
+
details: Details,
|
|
656
|
+
resultIndex: number,
|
|
657
|
+
result: Details["results"][number] | undefined,
|
|
658
|
+
fallback: string,
|
|
659
|
+
): string {
|
|
660
|
+
const progress = foregroundProgressForResult(details, resultIndex);
|
|
661
|
+
const agent = normalizedParallelDisplayText(result?.agent) ?? normalizedParallelDisplayText(progress?.agent);
|
|
662
|
+
const workflowLabel = normalizedParallelDisplayText(workflowLabelForResult(details, resultIndex));
|
|
663
|
+
if (workflowLabel) return compactTaskText(undefined, workflowLabel) ?? workflowLabel;
|
|
664
|
+
|
|
665
|
+
const sessionName = normalizedParallelDisplayText(result?.sessionName) ?? normalizedParallelDisplayText(progress?.sessionName);
|
|
666
|
+
if (sessionName) {
|
|
667
|
+
const sessionTask = stripRepeatedAgentPrefix(sessionName, agent);
|
|
668
|
+
if (sessionTask && sessionTask !== PROMPT_REDACTED && sessionTask.toLowerCase() !== agent?.toLowerCase()) {
|
|
669
|
+
return compactTaskText(sessionTask) ?? sessionTask;
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
return compactTaskText(result?.task) ?? compactTaskText(progress?.task) ?? agent ?? fallback;
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
function foregroundSingleDisplayName(result: Details["results"][number] | undefined): string {
|
|
677
|
+
return normalizedParallelDisplayText(result?.agent)
|
|
678
|
+
?? normalizedParallelDisplayText(result?.sessionName)
|
|
679
|
+
?? compactTaskText(result?.task)
|
|
680
|
+
?? "subagent";
|
|
681
|
+
}
|
|
682
|
+
|
|
276
683
|
function hasLiveOutputSignal(line: string): boolean {
|
|
277
684
|
const clean = oneLine(line);
|
|
278
685
|
return liveOutputWordSignalPattern.test(clean) || liveOutputCodeSignalPattern.test(clean);
|
|
@@ -456,7 +863,7 @@ function resultStatusLine(result: Details["results"][number], output: string): s
|
|
|
456
863
|
|
|
457
864
|
type ResultPresentation = {
|
|
458
865
|
glyph: string;
|
|
459
|
-
label: "running" | "detached" | "stopped" | "paused" | "failed" | "completed";
|
|
866
|
+
label: "running" | "detached" | "stopped" | "paused" | "failed" | "partial" | "completed";
|
|
460
867
|
tone: "accent" | "warning" | "error" | "success";
|
|
461
868
|
};
|
|
462
869
|
|
|
@@ -466,6 +873,7 @@ function semanticResultPresentation(input: {
|
|
|
466
873
|
stopped?: boolean;
|
|
467
874
|
interrupted?: boolean;
|
|
468
875
|
failed?: boolean;
|
|
876
|
+
partial?: boolean;
|
|
469
877
|
completedWithoutOutput?: boolean;
|
|
470
878
|
seed?: number;
|
|
471
879
|
frame?: number;
|
|
@@ -478,6 +886,7 @@ function semanticResultPresentation(input: {
|
|
|
478
886
|
if (input.stopped) return { glyph: "■", label: "stopped", tone: "warning" };
|
|
479
887
|
if (input.interrupted) return { glyph: "■", label: "paused", tone: "warning" };
|
|
480
888
|
if (input.failed) return { glyph: "✗", label: "failed", tone: "error" };
|
|
889
|
+
if (input.partial) return { glyph: "■", label: "partial", tone: "warning" };
|
|
481
890
|
return { glyph: "✓", label: "completed", tone: input.completedWithoutOutput ? "warning" : "success" };
|
|
482
891
|
}
|
|
483
892
|
|
|
@@ -556,6 +965,7 @@ function widgetStepRenderKey(step: AsyncJobStep, index: number, expanded = false
|
|
|
556
965
|
return [
|
|
557
966
|
step.index ?? index,
|
|
558
967
|
step.agent,
|
|
968
|
+
step.sessionName,
|
|
559
969
|
step.workflowKey,
|
|
560
970
|
step.phase,
|
|
561
971
|
step.label,
|
|
@@ -575,6 +985,24 @@ function widgetStepRenderKey(step: AsyncJobStep, index: number, expanded = false
|
|
|
575
985
|
step.model,
|
|
576
986
|
step.thinking,
|
|
577
987
|
step.context,
|
|
988
|
+
step.description,
|
|
989
|
+
step.outputName,
|
|
990
|
+
step.structured,
|
|
991
|
+
step.acceptance?.status,
|
|
992
|
+
step.acceptance?.reviewResult?.status,
|
|
993
|
+
step.review?.status,
|
|
994
|
+
step.toolBudgetBlocked,
|
|
995
|
+
step.turnBudgetExceeded,
|
|
996
|
+
step.timedOut,
|
|
997
|
+
step.stopped,
|
|
998
|
+
step.execution?.status,
|
|
999
|
+
step.execution?.error,
|
|
1000
|
+
step.execution?.timedOut,
|
|
1001
|
+
step.execution?.interrupted,
|
|
1002
|
+
step.execution?.stopped,
|
|
1003
|
+
step.execution?.detached,
|
|
1004
|
+
step.watchdog?.phase,
|
|
1005
|
+
unresolvedChildWatchdogBlockers(step.watchdog).length,
|
|
578
1006
|
step.error,
|
|
579
1007
|
expanded ? expandedStepActivityRenderKey(step) : undefined,
|
|
580
1008
|
nestedRenderKey(step.children, expanded),
|
|
@@ -586,6 +1014,7 @@ function nestedRenderKey(children: NestedRunSummary[] | undefined, expanded = fa
|
|
|
586
1014
|
child.id,
|
|
587
1015
|
child.state,
|
|
588
1016
|
child.agent,
|
|
1017
|
+
child.sessionName,
|
|
589
1018
|
child.model,
|
|
590
1019
|
child.thinking,
|
|
591
1020
|
child.activityState,
|
|
@@ -605,10 +1034,28 @@ function nestedRenderKey(children: NestedRunSummary[] | undefined, expanded = fa
|
|
|
605
1034
|
]);
|
|
606
1035
|
}
|
|
607
1036
|
|
|
1037
|
+
function hostStepRenderKey(row: AsyncStatusWorkflowRow): unknown[] {
|
|
1038
|
+
return [
|
|
1039
|
+
row.kind,
|
|
1040
|
+
row.name,
|
|
1041
|
+
row.state,
|
|
1042
|
+
row.provider,
|
|
1043
|
+
row.role,
|
|
1044
|
+
row.verdict,
|
|
1045
|
+
row.reasonCode,
|
|
1046
|
+
row.detail,
|
|
1047
|
+
row.target,
|
|
1048
|
+
row.freshness,
|
|
1049
|
+
row.reportPath,
|
|
1050
|
+
];
|
|
1051
|
+
}
|
|
1052
|
+
|
|
608
1053
|
export function widgetRenderKey(job: AsyncJobState, expanded = false): string {
|
|
1054
|
+
const projection = buildWorkflowWidgetProjection(job);
|
|
609
1055
|
return JSON.stringify({
|
|
610
1056
|
asyncDir: job.asyncDir,
|
|
611
1057
|
status: job.status,
|
|
1058
|
+
description: job.mode === "workflow" ? job.description : undefined,
|
|
612
1059
|
activityState: job.activityState,
|
|
613
1060
|
lastActivityAt: job.lastActivityAt,
|
|
614
1061
|
currentTool: job.currentTool,
|
|
@@ -621,14 +1068,33 @@ export function widgetRenderKey(job: AsyncJobState, expanded = false): string {
|
|
|
621
1068
|
currentStep: job.currentStep,
|
|
622
1069
|
chainStepCount: job.chainStepCount,
|
|
623
1070
|
parallelGroups: job.parallelGroups,
|
|
1071
|
+
workflowHostSteps: projectAsyncWorkflowRows([], job.hostSteps).map(hostStepRenderKey),
|
|
1072
|
+
workflowGraph: job.mode === "workflow" && job.workflowGraph ? {
|
|
1073
|
+
currentNodeId: job.workflowGraph.currentNodeId,
|
|
1074
|
+
stages: projection.stages.map((node) => [node.id, node.status, node.agent, node.phase, node.label, node.flatIndex, node.outputName, node.structured, node.error]),
|
|
1075
|
+
} : undefined,
|
|
1076
|
+
preflight: expanded ? job.preflight : job.preflight?.lanes.map((lane) => [lane.key, lane.mode, lane.decision, lane.claims, lane.expectedOutput]),
|
|
1077
|
+
preflightWarnings: expanded ? job.workflow?.preflightWarnings : undefined,
|
|
1078
|
+
checklist: projection.checklist ? {
|
|
1079
|
+
total: projection.checklist.total,
|
|
1080
|
+
done: projection.checklist.done,
|
|
1081
|
+
running: projection.checklist.running,
|
|
1082
|
+
queued: projection.checklist.queued,
|
|
1083
|
+
blocked: projection.checklist.blocked,
|
|
1084
|
+
failed: projection.checklist.failed,
|
|
1085
|
+
phases: projection.checklist.phases.map((phase) => [phase.key, phase.state, phase.done, phase.total, phase.running, phase.queued, phase.blocked, phase.failed, phase.paused, phase.stopped, phase.items.map((item) => [item.key, item.label, item.agent, item.state, item.preflight?.key, item.preflight?.mode, item.preflight?.decision, item.preflight?.claims, item.preflight?.expectedOutput, item.currentTool, item.currentPath, item.durationMs, item.toolCount, item.error])]),
|
|
1086
|
+
} : undefined,
|
|
624
1087
|
steps: job.steps?.map((step, index) => widgetStepRenderKey(step, index, expanded)),
|
|
625
1088
|
nestedChildren: nestedRenderKey(job.nestedChildren, expanded),
|
|
1089
|
+
lane: laneRenderKey(job, projection),
|
|
626
1090
|
stepsTotal: job.stepsTotal,
|
|
627
1091
|
runningSteps: job.runningSteps,
|
|
628
1092
|
completedSteps: job.completedSteps,
|
|
629
1093
|
activeParallelGroup: job.activeParallelGroup,
|
|
630
1094
|
startedAt: job.startedAt,
|
|
631
1095
|
updatedAt: job.updatedAt,
|
|
1096
|
+
timedOut: job.timedOut,
|
|
1097
|
+
stopped: job.stopped,
|
|
632
1098
|
totalTokens: job.totalTokens,
|
|
633
1099
|
});
|
|
634
1100
|
}
|
|
@@ -648,6 +1114,65 @@ function widgetJobName(job: AsyncJobState): string {
|
|
|
648
1114
|
return job.mode ?? "subagent";
|
|
649
1115
|
}
|
|
650
1116
|
|
|
1117
|
+
function isSingleChildAsyncJob(job: AsyncJobState): boolean {
|
|
1118
|
+
return job.mode === "single"
|
|
1119
|
+
&& job.steps?.length === 1
|
|
1120
|
+
&& shouldSuppressSingleStep(job.chainStepCount, job.stepsTotal);
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
function isCompletedWidgetStepStatus(status: AsyncJobStep["status"]): boolean {
|
|
1124
|
+
return status === "complete" || status === "completed";
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
function singleChildAgentName(job: AsyncJobState, step: AsyncJobStep): string {
|
|
1128
|
+
return job.agents?.length === 1 ? job.agents[0]! : step.agent || widgetJobName(job);
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
function hasSingleChildDetailEvidence(job: AsyncJobState, step: AsyncJobStep): boolean {
|
|
1132
|
+
return Boolean(
|
|
1133
|
+
step.error?.trim()
|
|
1134
|
+
|| step.execution?.error?.trim()
|
|
1135
|
+
|| step.phase?.trim()
|
|
1136
|
+
|| step.label?.trim()
|
|
1137
|
+
|| step.workflowKey?.trim()
|
|
1138
|
+
|| step.outputName?.trim()
|
|
1139
|
+
|| step.lane
|
|
1140
|
+
|| job.workflowKey?.trim()
|
|
1141
|
+
|| job.lane
|
|
1142
|
+
|| laneTraceForJob(job)?.phase?.trim()
|
|
1143
|
+
|| laneTraceForJob(job)?.label?.trim()
|
|
1144
|
+
|| step.timedOut
|
|
1145
|
+
|| step.stopped
|
|
1146
|
+
|| step.execution?.timedOut
|
|
1147
|
+
|| step.execution?.interrupted
|
|
1148
|
+
|| step.execution?.stopped
|
|
1149
|
+
|| step.execution?.detached
|
|
1150
|
+
|| job.timedOut
|
|
1151
|
+
|| job.stopped
|
|
1152
|
+
|| ["failed", "partial", "paused", "stopped", "detached"].includes(step.execution?.status ?? "")
|
|
1153
|
+
|| step.acceptance?.status === "rejected"
|
|
1154
|
+
|| step.acceptance?.reviewResult?.status === "blockers"
|
|
1155
|
+
|| step.review?.status === "blockers",
|
|
1156
|
+
);
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
function shouldCollapseSingleChildDetails(job: AsyncJobState, step: AsyncJobStep): boolean {
|
|
1160
|
+
if (!isSingleChildAsyncJob(job) || hasSingleChildDetailEvidence(job, step)) return false;
|
|
1161
|
+
if (job.status === "running") return step.status === "running";
|
|
1162
|
+
if (job.status === "complete") return isCompletedWidgetStepStatus(step.status);
|
|
1163
|
+
return false;
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1166
|
+
function singleChildTask(job: AsyncJobState, step: AsyncJobStep): string | undefined {
|
|
1167
|
+
const task = compactTaskText(step.description, step.label);
|
|
1168
|
+
if (task) return task;
|
|
1169
|
+
const sessionName = step.sessionName?.trim();
|
|
1170
|
+
if (!sessionName) return undefined;
|
|
1171
|
+
const agentName = singleChildAgentName(job, step);
|
|
1172
|
+
const sessionTask = stripRepeatedAgentPrefix(sessionName, agentName);
|
|
1173
|
+
return sessionTask === agentName ? undefined : compactTaskText(sessionTask);
|
|
1174
|
+
}
|
|
1175
|
+
|
|
651
1176
|
function widgetActivity(job: AsyncJobState): string {
|
|
652
1177
|
const facts: string[] = [];
|
|
653
1178
|
if (job.currentTool && job.currentToolStartedAt !== undefined && job.updatedAt !== undefined) facts.push(`${job.currentTool} ${formatDuration(Math.max(0, job.updatedAt - job.currentToolStartedAt))}`);
|
|
@@ -663,6 +1188,7 @@ function widgetActivity(job: AsyncJobState): string {
|
|
|
663
1188
|
if (job.status === "queued") return "queued…";
|
|
664
1189
|
if (job.status === "paused") return "Paused";
|
|
665
1190
|
if (job.status === "stopped") return "Stopped";
|
|
1191
|
+
if (job.status === "partial") return "Partial";
|
|
666
1192
|
if (job.status === "failed") return "Failed";
|
|
667
1193
|
return "Done";
|
|
668
1194
|
}
|
|
@@ -733,6 +1259,287 @@ function widgetStepStatus(status: AsyncJobStep["status"], theme: Theme): string
|
|
|
733
1259
|
return theme.fg("dim", status);
|
|
734
1260
|
}
|
|
735
1261
|
|
|
1262
|
+
function workflowChecklistStateLabel(state: WorkflowChecklistState): string {
|
|
1263
|
+
if (state === "running") return "running";
|
|
1264
|
+
if (state === "complete") return "complete";
|
|
1265
|
+
return state;
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1268
|
+
function workflowChecklistGlyph(item: { state: WorkflowChecklistState; startedAt?: number; durationMs?: number; toolCount?: number; currentToolStartedAt?: number }, theme: Theme, frame?: number): string {
|
|
1269
|
+
if (item.state === "running") return theme.fg("accent", runningGlyph(animatedSeed(runningSeed(item.startedAt, item.durationMs, item.toolCount, item.currentToolStartedAt), frame)));
|
|
1270
|
+
if (item.state === "complete") return theme.fg("success", "✓");
|
|
1271
|
+
if (item.state === "blocked") return theme.fg("error", "!");
|
|
1272
|
+
if (item.state === "failed") return theme.fg("error", "✗");
|
|
1273
|
+
if (item.state === "paused" || item.state === "stopped") return theme.fg("warning", "■");
|
|
1274
|
+
return theme.fg("muted", "◦");
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1277
|
+
function workflowChecklistItemPriority(state: WorkflowChecklistState): number {
|
|
1278
|
+
if (state === "blocked") return 0;
|
|
1279
|
+
if (state === "failed") return 1;
|
|
1280
|
+
if (state === "running") return 2;
|
|
1281
|
+
if (state === "paused") return 3;
|
|
1282
|
+
if (state === "stopped") return 4;
|
|
1283
|
+
if (state === "queued") return 5;
|
|
1284
|
+
return 6;
|
|
1285
|
+
}
|
|
1286
|
+
|
|
1287
|
+
function workflowChecklistItemLine(item: WorkflowChecklistItem, theme: Theme, indent: string, frame?: number): string {
|
|
1288
|
+
const identity = [item.label, item.agent && item.agent !== item.label ? item.agent : undefined].filter(Boolean).join(" · ");
|
|
1289
|
+
const context = contextModeBadge(theme, item.context);
|
|
1290
|
+
const state = item.state === "complete" ? "" : ` ${theme.fg("dim", `· ${workflowChecklistStateLabel(item.state)}`)}`;
|
|
1291
|
+
const details = [
|
|
1292
|
+
item.currentTool ? `${item.currentTool}${item.durationMs !== undefined ? ` ${formatDuration(item.durationMs)}` : ""}` : undefined,
|
|
1293
|
+
!item.currentTool && item.currentPath ? shortenPath(item.currentPath) : undefined,
|
|
1294
|
+
!item.currentTool && item.durationMs !== undefined ? formatDuration(item.durationMs) : undefined,
|
|
1295
|
+
item.toolCount !== undefined ? `${item.toolCount} tools` : undefined,
|
|
1296
|
+
item.outputName ? `out:${item.outputName}` : undefined,
|
|
1297
|
+
item.error ? `error:${oneLine(item.error)}` : undefined,
|
|
1298
|
+
].filter(Boolean).join(" · ");
|
|
1299
|
+
return `${indent}${workflowChecklistGlyph(item, theme, frame)} ${theme.bold(identity || item.key)}${context}${state}${details ? ` ${theme.fg("dim", `· ${details}`)}` : ""}`;
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
const COLLAPSED_WORKFLOW_PHASE_LIMIT = 4;
|
|
1303
|
+
|
|
1304
|
+
function workflowChecklistWidgetLines(checklist: WorkflowChecklistProjection | undefined, theme: Theme, indent: string, expanded: boolean, frame?: number, includeSummary = true, limitPhases = !expanded, includeBottleneckOutput = expanded): string[] {
|
|
1305
|
+
if (!checklist?.total) return [];
|
|
1306
|
+
const lines = includeSummary ? [`${indent}${theme.fg("dim", `Checklist ${formatWorkflowChecklistSummary(checklist)}`)}`] : [];
|
|
1307
|
+
const phases = !limitPhases || checklist.phases.length <= COLLAPSED_WORKFLOW_PHASE_LIMIT
|
|
1308
|
+
? checklist.phases
|
|
1309
|
+
: checklist.phases
|
|
1310
|
+
.map((phase, index) => ({ phase, index }))
|
|
1311
|
+
.sort((left, right) => Number(left.phase.state !== "running") - Number(right.phase.state !== "running")
|
|
1312
|
+
|| Number(left.phase.state === "complete") - Number(right.phase.state === "complete")
|
|
1313
|
+
|| left.index - right.index)
|
|
1314
|
+
.slice(0, COLLAPSED_WORKFLOW_PHASE_LIMIT)
|
|
1315
|
+
.sort((left, right) => left.index - right.index)
|
|
1316
|
+
.map(({ phase }) => phase);
|
|
1317
|
+
for (const phase of phases) {
|
|
1318
|
+
const phaseItem = phase.items.find((item) => item.state === "running") ?? phase.items[0];
|
|
1319
|
+
const glyph = workflowChecklistGlyph({
|
|
1320
|
+
state: phase.state,
|
|
1321
|
+
startedAt: phaseItem?.startedAt,
|
|
1322
|
+
durationMs: phaseItem?.durationMs,
|
|
1323
|
+
toolCount: phaseItem?.toolCount,
|
|
1324
|
+
currentToolStartedAt: phaseItem?.currentToolStartedAt,
|
|
1325
|
+
}, theme, frame);
|
|
1326
|
+
lines.push(`${indent}${glyph} ${theme.bold(formatWorkflowChecklistPhase(phase))}`);
|
|
1327
|
+
if (expanded) {
|
|
1328
|
+
for (const item of [...phase.items].sort((left, right) => workflowChecklistItemPriority(left.state) - workflowChecklistItemPriority(right.state))) {
|
|
1329
|
+
lines.push(workflowChecklistItemLine(item, theme, `${indent} `, frame));
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
const bottleneck = formatWorkflowChecklistBottleneck(checklist.bottleneck, { includeOutput: includeBottleneckOutput });
|
|
1334
|
+
if (bottleneck) {
|
|
1335
|
+
const tone = checklist.bottleneck?.state === "blocked" || checklist.bottleneck?.state === "failed" ? "error" : checklist.bottleneck?.state === "running" ? "accent" : "warning";
|
|
1336
|
+
lines.push(`${indent}${theme.fg(tone, `bottleneck · ${bottleneck}`)}`);
|
|
1337
|
+
}
|
|
1338
|
+
return lines;
|
|
1339
|
+
}
|
|
1340
|
+
|
|
1341
|
+
interface CompactWorkflowLaneRow {
|
|
1342
|
+
key: string;
|
|
1343
|
+
state: WorkflowChecklistState;
|
|
1344
|
+
agent?: string;
|
|
1345
|
+
mode?: string;
|
|
1346
|
+
decision?: string;
|
|
1347
|
+
claims?: string;
|
|
1348
|
+
expectedOutput?: string;
|
|
1349
|
+
label?: string;
|
|
1350
|
+
toolUses?: number;
|
|
1351
|
+
durationMs?: number;
|
|
1352
|
+
}
|
|
1353
|
+
|
|
1354
|
+
interface CompactWorkflowLaneCounts {
|
|
1355
|
+
total: number;
|
|
1356
|
+
done: number;
|
|
1357
|
+
active: number;
|
|
1358
|
+
queued: number;
|
|
1359
|
+
blocked: number;
|
|
1360
|
+
failed: number;
|
|
1361
|
+
paused: number;
|
|
1362
|
+
stopped: number;
|
|
1363
|
+
}
|
|
1364
|
+
|
|
1365
|
+
function compactWorkflowLaneState(items: readonly WorkflowChecklistItem[]): WorkflowChecklistState {
|
|
1366
|
+
let state: WorkflowChecklistState | undefined;
|
|
1367
|
+
for (const item of items) {
|
|
1368
|
+
if (state === undefined || workflowChecklistItemPriority(item.state) < workflowChecklistItemPriority(state)) state = item.state;
|
|
1369
|
+
}
|
|
1370
|
+
return state ?? "queued";
|
|
1371
|
+
}
|
|
1372
|
+
|
|
1373
|
+
function compactWorkflowLaneOwner(items: readonly WorkflowChecklistItem[]): string | undefined {
|
|
1374
|
+
const owners = [...new Set(items.map((item) => item.agent ?? item.role).filter((value): value is string => Boolean(value?.trim())))];
|
|
1375
|
+
if (owners.length === 0) return undefined;
|
|
1376
|
+
return boundedLaneValue(owners.length > 2 ? `${owners.slice(0, 2).join(", ")} +${owners.length - 2}` : owners.join(", "), 32);
|
|
1377
|
+
}
|
|
1378
|
+
|
|
1379
|
+
function compactWorkflowLaneLabel(items: readonly WorkflowChecklistItem[], key: string): string | undefined {
|
|
1380
|
+
const labels = [...new Set(items.map((item) => item.label).filter((value): value is string => Boolean(value?.trim() && value.trim() !== key)))];
|
|
1381
|
+
if (labels.length === 0) return undefined;
|
|
1382
|
+
return boundedLaneValue(labels.length > 1 ? `${labels[0]} +${labels.length - 1}` : labels[0], 48);
|
|
1383
|
+
}
|
|
1384
|
+
|
|
1385
|
+
function compactWorkflowLaneRow(key: string, items: readonly WorkflowChecklistItem[], lane = items.find((item) => item.preflight)?.preflight, fallbackState: WorkflowChecklistState = "queued"): CompactWorkflowLaneRow {
|
|
1386
|
+
const state = items.length ? compactWorkflowLaneState(items) : fallbackState;
|
|
1387
|
+
const toolCounts = items.map((item) => item.toolCount).filter((value): value is number => value !== undefined);
|
|
1388
|
+
const durations = items.map((item) => item.durationMs).filter((value): value is number => value !== undefined);
|
|
1389
|
+
const label = compactWorkflowLaneLabel(items, key);
|
|
1390
|
+
return {
|
|
1391
|
+
key: boundedLaneValue(key, 40) ?? key,
|
|
1392
|
+
state,
|
|
1393
|
+
agent: compactWorkflowLaneOwner(items),
|
|
1394
|
+
...(lane?.mode ? { mode: lane.mode } : {}),
|
|
1395
|
+
...(lane?.decision ? { decision: boundedLaneValue(lane.decision, 56) } : {}),
|
|
1396
|
+
...(lane?.claims?.length ? { claims: boundedLaneValue(lane.claims.join(", "), 56) } : {}),
|
|
1397
|
+
...(lane?.expectedOutput ? { expectedOutput: boundedLaneValue(lane.expectedOutput, 56) } : {}),
|
|
1398
|
+
...(label ? { label } : {}),
|
|
1399
|
+
...(toolCounts.length ? { toolUses: toolCounts.reduce((sum, value) => sum + value, 0) } : {}),
|
|
1400
|
+
...(durations.length ? { durationMs: Math.max(...durations) } : {}),
|
|
1401
|
+
};
|
|
1402
|
+
}
|
|
1403
|
+
|
|
1404
|
+
function compactWorkflowFallbackState(job: AsyncJobState): WorkflowChecklistState {
|
|
1405
|
+
if (job.activityState === "needs_attention" || job.timedOut || job.toolBudgetBlocked || job.turnBudgetExceeded) return "blocked";
|
|
1406
|
+
switch (job.status) {
|
|
1407
|
+
case "complete": return "complete";
|
|
1408
|
+
case "failed": return "failed";
|
|
1409
|
+
case "paused": return "paused";
|
|
1410
|
+
case "stopped": return "stopped";
|
|
1411
|
+
case "partial":
|
|
1412
|
+
case "rejected": return "blocked";
|
|
1413
|
+
default: return "queued";
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1416
|
+
|
|
1417
|
+
/** Flatten the loaded checklist into one compact row per declared lane. */
|
|
1418
|
+
function compactWorkflowLaneRows(job: AsyncJobState, checklist: WorkflowChecklistProjection | undefined): CompactWorkflowLaneRow[] {
|
|
1419
|
+
const groups = new Map<string, WorkflowChecklistItem[]>();
|
|
1420
|
+
for (const item of checklist?.phases.flatMap((phase) => phase.items) ?? []) {
|
|
1421
|
+
const key = item.preflight?.key ?? item.key;
|
|
1422
|
+
const group = groups.get(key);
|
|
1423
|
+
if (group) group.push(item);
|
|
1424
|
+
else groups.set(key, [item]);
|
|
1425
|
+
}
|
|
1426
|
+
|
|
1427
|
+
const rows: CompactWorkflowLaneRow[] = [];
|
|
1428
|
+
const preflightKeys = new Set(job.preflight?.lanes.map((lane) => lane.key) ?? []);
|
|
1429
|
+
if (job.preflight?.lanes.length) {
|
|
1430
|
+
for (const lane of job.preflight.lanes) {
|
|
1431
|
+
rows.push(compactWorkflowLaneRow(lane.key, groups.get(lane.key) ?? [], lane, compactWorkflowFallbackState(job)));
|
|
1432
|
+
}
|
|
1433
|
+
}
|
|
1434
|
+
|
|
1435
|
+
for (const [key, items] of groups) {
|
|
1436
|
+
if (preflightKeys.has(key)) continue;
|
|
1437
|
+
rows.push(compactWorkflowLaneRow(key, items));
|
|
1438
|
+
}
|
|
1439
|
+
return rows;
|
|
1440
|
+
}
|
|
1441
|
+
|
|
1442
|
+
function compactWorkflowLaneCounts(rows: readonly CompactWorkflowLaneRow[]): CompactWorkflowLaneCounts {
|
|
1443
|
+
const counts: CompactWorkflowLaneCounts = { total: rows.length, done: 0, active: 0, queued: 0, blocked: 0, failed: 0, paused: 0, stopped: 0 };
|
|
1444
|
+
for (const row of rows) {
|
|
1445
|
+
switch (row.state) {
|
|
1446
|
+
case "complete": counts.done++; break;
|
|
1447
|
+
case "running": counts.active++; break;
|
|
1448
|
+
case "queued": counts.queued++; break;
|
|
1449
|
+
case "blocked": counts.blocked++; break;
|
|
1450
|
+
case "failed": counts.failed++; break;
|
|
1451
|
+
case "paused": counts.paused++; break;
|
|
1452
|
+
case "stopped": counts.stopped++; break;
|
|
1453
|
+
}
|
|
1454
|
+
}
|
|
1455
|
+
return counts;
|
|
1456
|
+
}
|
|
1457
|
+
|
|
1458
|
+
function compactWorkflowLaneLine(row: CompactWorkflowLaneRow, theme: Theme, indent: string, frame?: number): string {
|
|
1459
|
+
const owner = row.agent && row.mode ? `${row.agent}/${row.mode}` : row.agent ?? row.mode;
|
|
1460
|
+
const state = row.state === "complete" ? undefined : row.state === "running" ? "active" : row.state;
|
|
1461
|
+
const intent = [
|
|
1462
|
+
row.decision,
|
|
1463
|
+
row.claims,
|
|
1464
|
+
row.expectedOutput,
|
|
1465
|
+
!row.mode && row.label ? row.label : undefined,
|
|
1466
|
+
].filter((value): value is string => Boolean(value));
|
|
1467
|
+
return `${indent}${workflowChecklistGlyph({ state: row.state, durationMs: row.durationMs, toolCount: row.toolUses }, theme, frame)} ${theme.bold(row.key)}${owner ? ` ${theme.fg("dim", `· ${owner}`)}` : ""}${state ? ` ${theme.fg("dim", `· ${state}`)}` : ""}${intent.length ? ` ${theme.fg("dim", `· ${intent.join(" · ")}`)}` : ""}`;
|
|
1468
|
+
}
|
|
1469
|
+
|
|
1470
|
+
function compactWorkflowShortId(job: AsyncJobState): string {
|
|
1471
|
+
return job.asyncId.slice(0, 8);
|
|
1472
|
+
}
|
|
1473
|
+
|
|
1474
|
+
function compactWorkflowDisplayLabel(job: AsyncJobState): string {
|
|
1475
|
+
return boundedLaneValue(job.description, 64) ?? compactWorkflowShortId(job);
|
|
1476
|
+
}
|
|
1477
|
+
|
|
1478
|
+
function compactWorkflowStats(job: AsyncJobState, rows: readonly CompactWorkflowLaneRow[], theme: Theme, projection: WorkflowWidgetProjection): string {
|
|
1479
|
+
const counts = compactWorkflowLaneCounts(rows);
|
|
1480
|
+
const total = counts.total || projection.stageProgress?.total || job.stepsTotal || job.agents?.length || 0;
|
|
1481
|
+
const progress = [
|
|
1482
|
+
total > 0 ? `${counts.done}/${total} done` : undefined,
|
|
1483
|
+
counts.active ? `${counts.active} active` : undefined,
|
|
1484
|
+
counts.queued ? `${counts.queued} queued` : undefined,
|
|
1485
|
+
counts.blocked ? `${counts.blocked} blocked` : undefined,
|
|
1486
|
+
counts.failed ? `${counts.failed} failed` : undefined,
|
|
1487
|
+
counts.paused ? `${counts.paused} paused` : undefined,
|
|
1488
|
+
counts.stopped ? `${counts.stopped} stopped` : undefined,
|
|
1489
|
+
].filter((value): value is string => Boolean(value));
|
|
1490
|
+
const rowToolUses = rows.map((row) => row.toolUses).filter((value): value is number => value !== undefined);
|
|
1491
|
+
const toolUses = job.toolCount ?? (rowToolUses.length ? rowToolUses.reduce((sum, value) => sum + value, 0) : undefined);
|
|
1492
|
+
const rowDuration = rows.map((row) => row.durationMs).filter((value): value is number => value !== undefined);
|
|
1493
|
+
const durationMs = job.startedAt !== undefined && job.updatedAt !== undefined
|
|
1494
|
+
? Math.max(0, job.updatedAt - job.startedAt)
|
|
1495
|
+
: rowDuration.length ? Math.max(...rowDuration) : undefined;
|
|
1496
|
+
return statJoin(theme, [
|
|
1497
|
+
`id: ${compactWorkflowShortId(job)}`,
|
|
1498
|
+
...progress,
|
|
1499
|
+
toolUses !== undefined ? formatToolUseStat(toolUses) : undefined,
|
|
1500
|
+
durationMs !== undefined ? formatDuration(durationMs) : undefined,
|
|
1501
|
+
].filter((value): value is string => Boolean(value)));
|
|
1502
|
+
}
|
|
1503
|
+
|
|
1504
|
+
interface CompactWorkflowBottleneck {
|
|
1505
|
+
text: string;
|
|
1506
|
+
tone: "warning" | "error";
|
|
1507
|
+
}
|
|
1508
|
+
|
|
1509
|
+
function compactWorkflowBottleneck(rows: readonly CompactWorkflowLaneRow[], job: AsyncJobState): CompactWorkflowBottleneck | undefined {
|
|
1510
|
+
let row: CompactWorkflowLaneRow | undefined;
|
|
1511
|
+
for (const candidate of rows) {
|
|
1512
|
+
if (candidate.state !== "blocked" && candidate.state !== "failed" && candidate.state !== "paused" && candidate.state !== "stopped") continue;
|
|
1513
|
+
if (!row || workflowChecklistItemPriority(candidate.state) < workflowChecklistItemPriority(row.state)) row = candidate;
|
|
1514
|
+
}
|
|
1515
|
+
if (row) return { text: `${row.key} · ${row.state}`, tone: row.state === "blocked" || row.state === "failed" ? "error" : "warning" };
|
|
1516
|
+
if (job.activityState === "needs_attention" || job.timedOut || job.toolBudgetBlocked || job.turnBudgetExceeded) return { text: `workflow · ${job.activityState === "needs_attention" ? "needs attention" : "blocked"}`, tone: job.activityState === "needs_attention" ? "warning" : "error" };
|
|
1517
|
+
if (job.status === "failed" || job.status === "partial" || job.status === "rejected") return { text: `workflow · ${job.status}`, tone: "error" };
|
|
1518
|
+
if (job.status === "paused" || job.status === "stopped") return { text: `workflow · ${job.status}`, tone: "warning" };
|
|
1519
|
+
return undefined;
|
|
1520
|
+
}
|
|
1521
|
+
|
|
1522
|
+
function compactWorkflowHeaderLine(job: AsyncJobState, theme: Theme, width?: number): string {
|
|
1523
|
+
const label = compactWorkflowDisplayLabel(job);
|
|
1524
|
+
const full = `${theme.fg("toolTitle", themeBold(theme, `async workflow: ${label}`))} ${theme.fg("dim", "─ background")}`;
|
|
1525
|
+
if (width === undefined || visibleWidth(full) <= width) return full;
|
|
1526
|
+
return `${theme.fg("toolTitle", themeBold(theme, `async workflow ${label}`))} ${theme.fg("dim", "· background")}`;
|
|
1527
|
+
}
|
|
1528
|
+
|
|
1529
|
+
function compactWorkflowWidgetBodyLines(job: AsyncJobState, theme: Theme, frame: number | undefined, projection: WorkflowWidgetProjection): string[] {
|
|
1530
|
+
const rows = compactWorkflowLaneRows(job, projection.checklist);
|
|
1531
|
+
const lines = [` ${compactWorkflowStats(job, rows, theme, projection)}`];
|
|
1532
|
+
if (rows.length) {
|
|
1533
|
+
for (const row of rows) lines.push(compactWorkflowLaneLine(row, theme, " ", frame));
|
|
1534
|
+
} else {
|
|
1535
|
+
lines.push(` ${theme.fg("dim", "◦ waiting for workflow lanes")}`);
|
|
1536
|
+
}
|
|
1537
|
+
const bottleneck = compactWorkflowBottleneck(rows, job);
|
|
1538
|
+
if (bottleneck) lines.push(` ${theme.fg(bottleneck.tone, `bottleneck · ${bottleneck.text}`)}`);
|
|
1539
|
+
if (job.status === "running" || rows.some((row) => row.state === "running")) lines.push(` ${theme.fg("accent", workflowDetailHintText())}`);
|
|
1540
|
+
return lines;
|
|
1541
|
+
}
|
|
1542
|
+
|
|
736
1543
|
function widgetStepActivity(step: NonNullable<AsyncJobState["steps"]>[number], snapshotNow?: number): string {
|
|
737
1544
|
const facts: string[] = [];
|
|
738
1545
|
if (step.currentTool && step.currentToolStartedAt !== undefined && snapshotNow !== undefined) facts.push(`${step.currentTool} ${formatDuration(Math.max(0, snapshotNow - step.currentToolStartedAt))}`);
|
|
@@ -740,7 +1547,7 @@ function widgetStepActivity(step: NonNullable<AsyncJobState["steps"]>[number], s
|
|
|
740
1547
|
if (step.currentPath) facts.push(shortenPath(step.currentPath));
|
|
741
1548
|
if (step.turnCount !== undefined) facts.push(`${step.turnCount} turns`);
|
|
742
1549
|
if (step.toolCount !== undefined) facts.push(`${step.toolCount} tools`);
|
|
743
|
-
if (step.tokens?.total) facts.push(
|
|
1550
|
+
if (step.tokens?.total) facts.push(formatTokenUsage(step.tokens, "token"));
|
|
744
1551
|
const activity = buildLiveStatusLine(step, snapshotNow);
|
|
745
1552
|
if (activity && facts.length) return `${activity} · ${facts.join(" · ")}`;
|
|
746
1553
|
if (activity) return activity;
|
|
@@ -755,8 +1562,7 @@ function widgetChainDetails(job: AsyncJobState, theme: Theme, expanded = false,
|
|
|
755
1562
|
for (const span of buildAsyncChainStepSpans(total, job.steps.length, job.parallelGroups)) {
|
|
756
1563
|
const steps = job.steps.slice(span.start, span.start + span.count);
|
|
757
1564
|
if (span.isParallel) {
|
|
758
|
-
|
|
759
|
-
lines.push(` ${widgetStepGlyph(status, theme, widgetStepsRunningSeed(steps), frame)} Step ${span.stepIndex + 1}/${total}: ${themeBold(theme, "parallel group")} ${theme.fg("dim", "·")} ${theme.fg("dim", formatParallelOutcome(steps, span.count))}`);
|
|
1565
|
+
lines.push(...parallelWidgetGroupDetails(job, theme, { steps, total: span.count, stepIndex: span.stepIndex, chainTotal: total }, expanded, width, frame, false));
|
|
760
1566
|
continue;
|
|
761
1567
|
}
|
|
762
1568
|
const step = steps[0];
|
|
@@ -773,6 +1579,8 @@ function widgetParallelAgentDetails(job: AsyncJobState, theme: Theme, expanded =
|
|
|
773
1579
|
if (!job.steps?.length) return [];
|
|
774
1580
|
if (job.mode !== "parallel" && job.mode !== "chain") return [];
|
|
775
1581
|
if (job.mode === "chain" && !job.activeParallelGroup && job.parallelGroups?.length) return widgetChainDetails(job, theme, expanded, width, frame);
|
|
1582
|
+
const group = activeParallelWidgetGroup(job);
|
|
1583
|
+
if (group) return parallelWidgetGroupDetails(job, theme, group, expanded, width, frame, Boolean(job.activeParallelGroup));
|
|
776
1584
|
const total = job.stepsTotal ?? job.steps.length;
|
|
777
1585
|
const lines: string[] = [];
|
|
778
1586
|
for (const [index, step] of job.steps.entries()) {
|
|
@@ -780,7 +1588,11 @@ function widgetParallelAgentDetails(job: AsyncJobState, theme: Theme, expanded =
|
|
|
780
1588
|
const activity = widgetStepActivity(step, job.updatedAt);
|
|
781
1589
|
const itemTitle = job.mode === "parallel" || job.activeParallelGroup ? "Agent" : "Step";
|
|
782
1590
|
const modelDisplay = modelThinkingBadge(theme, step.model, step.thinking);
|
|
783
|
-
|
|
1591
|
+
const label = compactTaskText(step.description, step.label);
|
|
1592
|
+
const display = step.sessionName?.trim() || (label ? `${label} (${step.agent})` : step.agent);
|
|
1593
|
+
lines.push(` ${theme.fg("dim", `${marker} ${widgetStepGlyph(step.status, theme, widgetStepRunningSeed(step, index), frame)} ${itemTitle} ${index + 1}/${total}: ${display} · ${widgetStepStatus(step.status, theme)}${modelDisplay}${activity ? ` · ${activity}` : ""}`)}`);
|
|
1594
|
+
const lane = projectAsyncLane(job, step);
|
|
1595
|
+
if (lane) lines.push(...formatLaneProjectionLines(lane, theme, " "));
|
|
784
1596
|
for (const nestedLine of formatNestedWidgetLines(step.children, theme, width, expanded, job.updatedAt, expanded ? 8 : 6)) lines.push(` ${nestedLine}`);
|
|
785
1597
|
}
|
|
786
1598
|
return lines;
|
|
@@ -859,6 +1671,127 @@ function buildAsyncChainStepSpans(total: number, stepCount: number, parallelGrou
|
|
|
859
1671
|
return spans;
|
|
860
1672
|
}
|
|
861
1673
|
|
|
1674
|
+
interface ParallelWidgetGroup {
|
|
1675
|
+
steps: AsyncJobStep[];
|
|
1676
|
+
total: number;
|
|
1677
|
+
stepIndex?: number;
|
|
1678
|
+
chainTotal?: number;
|
|
1679
|
+
}
|
|
1680
|
+
|
|
1681
|
+
interface ParallelWidgetStepRow {
|
|
1682
|
+
step: AsyncJobStep;
|
|
1683
|
+
index: number;
|
|
1684
|
+
rowLabel: string;
|
|
1685
|
+
}
|
|
1686
|
+
|
|
1687
|
+
function normalizedParallelDisplayText(value: string | undefined): string | undefined {
|
|
1688
|
+
if (!value?.trim()) return undefined;
|
|
1689
|
+
const normalized = oneLine(value);
|
|
1690
|
+
return normalized && normalized !== PROMPT_REDACTED ? normalized : undefined;
|
|
1691
|
+
}
|
|
1692
|
+
|
|
1693
|
+
function parallelWidgetStepDisplayName(step: AsyncJobStep): string {
|
|
1694
|
+
const agent = normalizedParallelDisplayText(step.agent);
|
|
1695
|
+
const explicitLabel = normalizedParallelDisplayText(step.label);
|
|
1696
|
+
if (explicitLabel) {
|
|
1697
|
+
const label = compactTaskText(step.description, explicitLabel) ?? explicitLabel;
|
|
1698
|
+
return agent ? `${label} (${agent})` : label;
|
|
1699
|
+
}
|
|
1700
|
+
|
|
1701
|
+
const sessionName = normalizedParallelDisplayText(step.sessionName);
|
|
1702
|
+
if (sessionName) {
|
|
1703
|
+
const sessionTask = stripRepeatedAgentPrefix(sessionName, agent);
|
|
1704
|
+
if (sessionTask && sessionTask !== PROMPT_REDACTED && sessionTask.toLowerCase() !== agent?.toLowerCase()) return sessionTask;
|
|
1705
|
+
}
|
|
1706
|
+
|
|
1707
|
+
return compactTaskText(step.description) ?? agent ?? "subagent";
|
|
1708
|
+
}
|
|
1709
|
+
|
|
1710
|
+
function parallelWidgetStepPriority(step: AsyncJobStep): number {
|
|
1711
|
+
if (step.status === "running" || step.activityState === "needs_attention") return 0;
|
|
1712
|
+
switch (step.status) {
|
|
1713
|
+
case "failed":
|
|
1714
|
+
case "rejected":
|
|
1715
|
+
case "partial":
|
|
1716
|
+
case "stopped":
|
|
1717
|
+
case "paused":
|
|
1718
|
+
return 1;
|
|
1719
|
+
case "complete":
|
|
1720
|
+
case "completed":
|
|
1721
|
+
return 2;
|
|
1722
|
+
default:
|
|
1723
|
+
return 3;
|
|
1724
|
+
}
|
|
1725
|
+
}
|
|
1726
|
+
|
|
1727
|
+
function parallelWidgetStepRows(steps: AsyncJobStep[], total: number, prioritizeActive: boolean): ParallelWidgetStepRow[] {
|
|
1728
|
+
const indexed = steps.map((step, index) => ({ step, index, displayName: parallelWidgetStepDisplayName(step) }));
|
|
1729
|
+
if (prioritizeActive) indexed.sort((left, right) => parallelWidgetStepPriority(left.step) - parallelWidgetStepPriority(right.step) || left.index - right.index);
|
|
1730
|
+
return withDuplicateLabelDiscriminators(indexed, total).map(({ displayName, ...row }) => row);
|
|
1731
|
+
}
|
|
1732
|
+
|
|
1733
|
+
function activeParallelWidgetGroup(job: AsyncJobState): ParallelWidgetGroup | undefined {
|
|
1734
|
+
const steps = job.steps ?? [];
|
|
1735
|
+
if (!steps.length) return undefined;
|
|
1736
|
+
if (job.mode === "parallel") return { steps, total: job.stepsTotal ?? steps.length };
|
|
1737
|
+
if (job.mode !== "chain" || !job.activeParallelGroup) return undefined;
|
|
1738
|
+
|
|
1739
|
+
const chainTotal = job.chainStepCount ?? job.stepsTotal ?? steps.length;
|
|
1740
|
+
const spans = buildAsyncChainStepSpans(chainTotal, steps.length, job.parallelGroups);
|
|
1741
|
+
const currentStep = job.currentStep;
|
|
1742
|
+
const activeSpan = currentStep === undefined
|
|
1743
|
+
? spans.find((span) => span.isParallel)
|
|
1744
|
+
: spans.find((span) => span.isParallel
|
|
1745
|
+
&& currentStep >= span.start
|
|
1746
|
+
&& currentStep < span.start + span.count);
|
|
1747
|
+
return {
|
|
1748
|
+
steps,
|
|
1749
|
+
total: activeSpan?.count ?? job.stepsTotal ?? steps.length,
|
|
1750
|
+
stepIndex: activeSpan?.stepIndex,
|
|
1751
|
+
chainTotal,
|
|
1752
|
+
};
|
|
1753
|
+
}
|
|
1754
|
+
|
|
1755
|
+
function parallelWidgetGroupHeader(
|
|
1756
|
+
group: ParallelWidgetGroup,
|
|
1757
|
+
theme: Theme,
|
|
1758
|
+
frame?: number,
|
|
1759
|
+
): string {
|
|
1760
|
+
const status = aggregateStepStatus(group.steps);
|
|
1761
|
+
const label = group.stepIndex !== undefined && group.chainTotal !== undefined
|
|
1762
|
+
? `Step ${group.stepIndex + 1}/${group.chainTotal}: parallel group`
|
|
1763
|
+
: "parallel group";
|
|
1764
|
+
return ` ${widgetStepGlyph(status, theme, widgetStepsRunningSeed(group.steps), frame)} ${themeBold(theme, label)} ${theme.fg("dim", "·")} ${theme.fg("dim", formatParallelOutcome(group.steps, group.total))}`;
|
|
1765
|
+
}
|
|
1766
|
+
|
|
1767
|
+
function parallelWidgetGroupDetails(
|
|
1768
|
+
job: AsyncJobState,
|
|
1769
|
+
theme: Theme,
|
|
1770
|
+
group: ParallelWidgetGroup,
|
|
1771
|
+
expanded: boolean,
|
|
1772
|
+
width: number,
|
|
1773
|
+
frame: number | undefined,
|
|
1774
|
+
prioritizeActive: boolean,
|
|
1775
|
+
): string[] {
|
|
1776
|
+
const lines = [parallelWidgetGroupHeader(group, theme, frame)];
|
|
1777
|
+
const rows = parallelWidgetStepRows(group.steps, group.total, prioritizeActive);
|
|
1778
|
+
for (const [rowIndex, row] of rows.entries()) {
|
|
1779
|
+
const marker = rowIndex === rows.length - 1 && rows.length >= group.total ? "└─" : "├─";
|
|
1780
|
+
lines.push(...foregroundStyleWidgetStepLines(job, theme, row.step, "Agent", row.index + 1, group.total, expanded, width, frame, {
|
|
1781
|
+
rowLabel: row.rowLabel,
|
|
1782
|
+
rowIndent: " ",
|
|
1783
|
+
detailIndent: " ",
|
|
1784
|
+
rowMarker: marker,
|
|
1785
|
+
includeCurrentPath: true,
|
|
1786
|
+
}));
|
|
1787
|
+
}
|
|
1788
|
+
for (let index = rows.length; index < group.total; index++) {
|
|
1789
|
+
const marker = index === group.total - 1 ? "└─" : "├─";
|
|
1790
|
+
lines.push(` ${marker} ${theme.fg("muted", "◦")} ${theme.fg("dim", "pending")}`);
|
|
1791
|
+
}
|
|
1792
|
+
return lines;
|
|
1793
|
+
}
|
|
1794
|
+
|
|
862
1795
|
function isDoneResult(result: Details["results"][number]): boolean {
|
|
863
1796
|
const status = result.progress?.status;
|
|
864
1797
|
if (status === "completed") return true;
|
|
@@ -877,41 +1810,83 @@ interface ChainRenderResultEntry {
|
|
|
877
1810
|
rowNumber: number;
|
|
878
1811
|
rowLabel?: string;
|
|
879
1812
|
agentName: string;
|
|
1813
|
+
displayIndex: number;
|
|
1814
|
+
isParallel?: boolean;
|
|
880
1815
|
}
|
|
881
1816
|
|
|
882
|
-
interface
|
|
883
|
-
kind: "
|
|
884
|
-
rowNumber: number;
|
|
1817
|
+
interface ChainRenderGroupEntry {
|
|
1818
|
+
kind: "group";
|
|
885
1819
|
stepLabel: string;
|
|
886
|
-
|
|
1820
|
+
groupLabel?: string;
|
|
887
1821
|
status: WorkflowNodeStatus;
|
|
888
1822
|
error?: string;
|
|
889
1823
|
}
|
|
890
1824
|
|
|
891
|
-
type ChainRenderEntry = ChainRenderResultEntry |
|
|
1825
|
+
type ChainRenderEntry = ChainRenderResultEntry | ChainRenderGroupEntry;
|
|
1826
|
+
|
|
1827
|
+
function chainSpanStatus(details: Details, span: ChainStepSpan): WorkflowNodeStatus {
|
|
1828
|
+
if (span.status) return span.status;
|
|
1829
|
+
const results = details.results.slice(span.start, span.start + span.count);
|
|
1830
|
+
if (results.some((result) => isResultRunning(result))) return "running";
|
|
1831
|
+
if (results.some((result) => !hasTerminalResultFlag(result) && (result.progress?.status === "failed" || result.exitCode !== 0) && !isResultRunning(result))) return "failed";
|
|
1832
|
+
if (results.some((result) => result.stopped)) return "stopped";
|
|
1833
|
+
if (results.some((result) => result.interrupted)) return "paused";
|
|
1834
|
+
if (results.some((result) => result.detached || result.progress?.status === "detached")) return "detached";
|
|
1835
|
+
if (results.length < span.count) return "pending";
|
|
1836
|
+
if (results.length > 0 && results.every(isDoneResult)) return "completed";
|
|
1837
|
+
return "pending";
|
|
1838
|
+
}
|
|
1839
|
+
|
|
1840
|
+
function withDuplicateForegroundLabels(entries: ChainRenderResultEntry[], total: number): ChainRenderResultEntry[] {
|
|
1841
|
+
return withDuplicateLabelDiscriminators(
|
|
1842
|
+
entries.map((entry) => ({ ...entry, index: entry.displayIndex, displayName: entry.agentName })),
|
|
1843
|
+
total,
|
|
1844
|
+
).map(({ displayName, rowLabel, ...entry }) => ({
|
|
1845
|
+
...entry,
|
|
1846
|
+
rowLabel: rowLabel === displayName ? undefined : rowLabel.slice(0, -(displayName.length + 2)),
|
|
1847
|
+
}));
|
|
1848
|
+
}
|
|
892
1849
|
|
|
893
1850
|
function buildChainRenderEntries(details: Details, label: MultiProgressLabel): ChainRenderEntry[] | undefined {
|
|
894
1851
|
if (details.mode !== "chain" || !label.hasParallelInChain || label.showActiveGroupOnly) return undefined;
|
|
895
1852
|
const entries: ChainRenderEntry[] = [];
|
|
896
1853
|
for (const span of buildChainStepSpans(details)) {
|
|
897
|
-
if (span.isParallel
|
|
1854
|
+
if (span.isParallel) {
|
|
898
1855
|
entries.push({
|
|
899
|
-
kind: "
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
status: span.status ?? "pending",
|
|
1856
|
+
kind: "group",
|
|
1857
|
+
stepLabel: `Step ${span.stepIndex + 1}/${label.logicalStepCount}: parallel group`,
|
|
1858
|
+
groupLabel: span.label?.trim() || undefined,
|
|
1859
|
+
status: chainSpanStatus(details, span),
|
|
904
1860
|
error: span.error,
|
|
905
1861
|
});
|
|
1862
|
+
const groupEntries: ChainRenderResultEntry[] = [];
|
|
1863
|
+
for (let index = span.start; index < span.start + span.count; index++) {
|
|
1864
|
+
const result = details.results[index];
|
|
1865
|
+
const localIndex = foregroundResultIndex(details, index);
|
|
1866
|
+
const displayIndex = localIndex >= span.start && localIndex < span.start + span.count
|
|
1867
|
+
? localIndex - span.start
|
|
1868
|
+
: index - span.start;
|
|
1869
|
+
groupEntries.push({
|
|
1870
|
+
kind: "result",
|
|
1871
|
+
resultIndex: index,
|
|
1872
|
+
rowNumber: index - span.start + 1,
|
|
1873
|
+
agentName: foregroundResultDisplayName(details, index, result, `agent-${displayIndex + 1}`),
|
|
1874
|
+
displayIndex,
|
|
1875
|
+
isParallel: true,
|
|
1876
|
+
});
|
|
1877
|
+
}
|
|
1878
|
+
entries.push(...withDuplicateForegroundLabels(groupEntries, span.count));
|
|
906
1879
|
continue;
|
|
907
1880
|
}
|
|
908
1881
|
for (let index = span.start; index < span.start + span.count; index++) {
|
|
1882
|
+
const result = details.results[index];
|
|
909
1883
|
entries.push({
|
|
910
1884
|
kind: "result",
|
|
911
1885
|
resultIndex: index,
|
|
912
|
-
rowNumber:
|
|
913
|
-
rowLabel:
|
|
914
|
-
agentName: details
|
|
1886
|
+
rowNumber: span.stepIndex + 1,
|
|
1887
|
+
rowLabel: resultRowLabel(label, span.stepIndex + 1),
|
|
1888
|
+
agentName: foregroundResultDisplayName(details, index, result, details.chainAgents?.[span.stepIndex] ?? `step-${span.stepIndex + 1}`),
|
|
1889
|
+
displayIndex: foregroundResultIndex(details, index),
|
|
915
1890
|
});
|
|
916
1891
|
}
|
|
917
1892
|
}
|
|
@@ -927,6 +1902,7 @@ interface MultiProgressLabel {
|
|
|
927
1902
|
groupStartIndex: number;
|
|
928
1903
|
groupEndIndex: number;
|
|
929
1904
|
showActiveGroupOnly: boolean;
|
|
1905
|
+
logicalStepCount: number;
|
|
930
1906
|
}
|
|
931
1907
|
|
|
932
1908
|
function buildMultiProgressLabel(details: Pick<Details, "mode" | "results" | "progress" | "totalSteps" | "currentStepIndex" | "chainAgents" | "workflowGraph">, hasRunning: boolean): MultiProgressLabel {
|
|
@@ -962,7 +1938,7 @@ function buildMultiProgressLabel(details: Pick<Details, "mode" | "results" | "pr
|
|
|
962
1938
|
const headerLabel = hasRunning
|
|
963
1939
|
? `${formatAgentRunningLabel(running)} · ${done}/${totalCount} done`
|
|
964
1940
|
: `${done}/${totalCount} done`;
|
|
965
|
-
return { headerLabel, itemTitle, totalCount, hasParallelInChain, activeParallelGroup, groupStartIndex: 0, groupEndIndex: totalCount, showActiveGroupOnly: false };
|
|
1941
|
+
return { headerLabel, itemTitle, totalCount, hasParallelInChain, activeParallelGroup, groupStartIndex: 0, groupEndIndex: totalCount, showActiveGroupOnly: false, logicalStepCount: totalCount };
|
|
966
1942
|
}
|
|
967
1943
|
|
|
968
1944
|
if (activeParallelGroup) {
|
|
@@ -990,7 +1966,7 @@ function buildMultiProgressLabel(details: Pick<Details, "mode" | "results" | "pr
|
|
|
990
1966
|
const headerLabel = hasRunning
|
|
991
1967
|
? `step ${currentStepIndex + 1}/${totalSteps} · parallel group: ${formatAgentRunningLabel(running)} · ${done}/${groupSize} done`
|
|
992
1968
|
: `step ${currentStepIndex + 1}/${totalSteps} · parallel group: ${done}/${groupSize} done`;
|
|
993
|
-
return { headerLabel, itemTitle, totalCount: groupSize, hasParallelInChain, activeParallelGroup, groupStartIndex: groupStart, groupEndIndex: groupEnd, showActiveGroupOnly: true };
|
|
1969
|
+
return { headerLabel, itemTitle, totalCount: groupSize, hasParallelInChain, activeParallelGroup, groupStartIndex: groupStart, groupEndIndex: groupEnd, showActiveGroupOnly: true, logicalStepCount: totalSteps };
|
|
994
1970
|
}
|
|
995
1971
|
|
|
996
1972
|
if (details.mode === "chain" && details.chainAgents?.length) {
|
|
@@ -1008,30 +1984,68 @@ function buildMultiProgressLabel(details: Pick<Details, "mode" | "results" | "pr
|
|
|
1008
1984
|
}).length;
|
|
1009
1985
|
const currentStep = details.currentStepIndex !== undefined ? details.currentStepIndex + 1 : Math.min(totalCount, doneLogical + (hasRunning ? 1 : 0));
|
|
1010
1986
|
const headerLabel = hasRunning ? `step ${currentStep}/${totalCount}` : `step ${doneLogical}/${totalCount}`;
|
|
1011
|
-
return { headerLabel, itemTitle, totalCount, hasParallelInChain, activeParallelGroup, groupStartIndex: 0, groupEndIndex: details.results.length, showActiveGroupOnly: false };
|
|
1987
|
+
return { headerLabel, itemTitle, totalCount, hasParallelInChain, activeParallelGroup, groupStartIndex: 0, groupEndIndex: details.results.length, showActiveGroupOnly: false, logicalStepCount: totalCount };
|
|
1012
1988
|
}
|
|
1013
1989
|
|
|
1014
1990
|
const totalCount = details.totalSteps ?? details.results.length;
|
|
1015
1991
|
const currentStep = details.currentStepIndex !== undefined ? details.currentStepIndex + 1 : Math.min(totalCount, details.results.filter(isDoneResult).length + (hasRunning ? 1 : 0));
|
|
1016
1992
|
const done = details.results.filter(isDoneResult).length;
|
|
1017
1993
|
const headerLabel = hasRunning ? `step ${currentStep}/${totalCount}` : `step ${done}/${totalCount}`;
|
|
1018
|
-
return { headerLabel, itemTitle, totalCount, hasParallelInChain, activeParallelGroup, groupStartIndex: 0, groupEndIndex: details.results.length, showActiveGroupOnly: false };
|
|
1019
|
-
}
|
|
1020
|
-
|
|
1021
|
-
function resultRowLabel(label: MultiProgressLabel,
|
|
1022
|
-
if (label.itemTitle === "Agent")
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1994
|
+
return { headerLabel, itemTitle, totalCount, hasParallelInChain, activeParallelGroup, groupStartIndex: 0, groupEndIndex: details.results.length, showActiveGroupOnly: false, logicalStepCount: totalCount };
|
|
1995
|
+
}
|
|
1996
|
+
|
|
1997
|
+
function resultRowLabel(label: MultiProgressLabel, stepNumber: number): string | undefined {
|
|
1998
|
+
if (label.itemTitle === "Agent") return undefined;
|
|
1999
|
+
if (shouldSuppressSingleStep(label.logicalStepCount)) return undefined;
|
|
2000
|
+
return `Step ${stepNumber}/${label.logicalStepCount}`;
|
|
2001
|
+
}
|
|
2002
|
+
|
|
2003
|
+
function buildForegroundResultEntries(
|
|
2004
|
+
details: Details,
|
|
2005
|
+
label: MultiProgressLabel,
|
|
2006
|
+
displayStart: number,
|
|
2007
|
+
displayEnd: number,
|
|
2008
|
+
useResultsDirectly: boolean,
|
|
2009
|
+
): ChainRenderResultEntry[] {
|
|
2010
|
+
const fallbackLabel = label.itemTitle.toLowerCase();
|
|
2011
|
+
const entries = Array.from({ length: displayEnd - displayStart }, (_, offset): ChainRenderResultEntry => {
|
|
2012
|
+
const index = displayStart + offset;
|
|
2013
|
+
const result = details.results[index];
|
|
2014
|
+
const stableIndex = foregroundResultIndex(details, index);
|
|
2015
|
+
const rowNumber = label.showActiveGroupOnly ? index - label.groupStartIndex + 1 : stableIndex + 1;
|
|
2016
|
+
const fallbackAgent = useResultsDirectly
|
|
2017
|
+
? (result?.agent || `${fallbackLabel}-${rowNumber}`)
|
|
2018
|
+
: (details.chainAgents![index] || result?.agent || `${fallbackLabel}-${rowNumber}`);
|
|
2019
|
+
const displayIndex = label.activeParallelGroup && stableIndex >= label.groupStartIndex && stableIndex < label.groupEndIndex
|
|
2020
|
+
? stableIndex - label.groupStartIndex
|
|
2021
|
+
: label.activeParallelGroup ? index - label.groupStartIndex : stableIndex;
|
|
2022
|
+
return {
|
|
2023
|
+
kind: "result",
|
|
2024
|
+
resultIndex: index,
|
|
2025
|
+
rowNumber,
|
|
2026
|
+
rowLabel: resultRowLabel(label, rowNumber),
|
|
2027
|
+
agentName: foregroundResultDisplayName(details, index, result, fallbackAgent),
|
|
2028
|
+
displayIndex,
|
|
2029
|
+
};
|
|
2030
|
+
});
|
|
2031
|
+
return label.itemTitle === "Agent" ? withDuplicateForegroundLabels(entries, label.totalCount) : entries;
|
|
1029
2032
|
}
|
|
1030
2033
|
|
|
1031
|
-
function widgetStats(job: AsyncJobState, theme: Theme): string {
|
|
2034
|
+
function widgetStats(job: AsyncJobState, theme: Theme, projection = buildWorkflowWidgetProjection(job), collapsed = false): string {
|
|
1032
2035
|
const parts: string[] = [];
|
|
1033
|
-
const
|
|
1034
|
-
|
|
2036
|
+
const { stageProgress } = projection;
|
|
2037
|
+
const stepsTotal = stageProgress?.total ?? job.stepsTotal ?? (job.agents?.length ?? 1);
|
|
2038
|
+
const isSingleChild = isSingleChildAsyncJob(job);
|
|
2039
|
+
const checklistPrimary = collapsed && job.mode === "workflow" && projection.checklist !== undefined;
|
|
2040
|
+
if (checklistPrimary) {
|
|
2041
|
+
parts.push(formatWorkflowChecklistSummary(projection.checklist!));
|
|
2042
|
+
} else if (stageProgress) {
|
|
2043
|
+
const currentStage = stageProgress.current !== undefined ? projection.stages[stageProgress.current] : undefined;
|
|
2044
|
+
const focus = currentStage
|
|
2045
|
+
? [compactTaskText(undefined, currentStage.label) ?? boundedLaneValue(currentStage.id), currentStage.agent ? boundedLaneValue(currentStage.agent) : "", workflowNodeStatusLabel(currentStage.status)].filter(Boolean)
|
|
2046
|
+
: [];
|
|
2047
|
+
parts.push(["staged lane", stageProgress.current !== undefined ? `stage ${stageProgress.current + 1}/${stageProgress.total}` : `${stageProgress.total} stages`, ...focus].join(" · "));
|
|
2048
|
+
} else if (job.activeParallelGroup) {
|
|
1035
2049
|
const running = job.runningSteps ?? (job.status === "running" ? 1 : 0);
|
|
1036
2050
|
const done = job.completedSteps ?? (job.status === "complete" ? stepsTotal : 0);
|
|
1037
2051
|
if (job.mode === "parallel") {
|
|
@@ -1048,17 +2062,18 @@ function widgetStats(job: AsyncJobState, theme: Theme): string {
|
|
|
1048
2062
|
parts.push(`step ${logicalStep + 1}/${total} · parallel group: ${groupParts.join(" · ")}`);
|
|
1049
2063
|
}
|
|
1050
2064
|
} else if (job.currentStep !== undefined) {
|
|
1051
|
-
if (job.mode === "chain"
|
|
2065
|
+
if (job.mode === "chain") {
|
|
1052
2066
|
const total = job.chainStepCount ?? stepsTotal;
|
|
1053
|
-
parts.push(`step ${flatToLogicalStepIndex(job.currentStep, total, job.parallelGroups) + 1}/${total}`);
|
|
1054
|
-
} else {
|
|
2067
|
+
parts.push(`step ${flatToLogicalStepIndex(job.currentStep, total, job.parallelGroups ?? []) + 1}/${total}`);
|
|
2068
|
+
} else if (!isSingleChild) {
|
|
1055
2069
|
parts.push(`step ${job.currentStep + 1}/${stepsTotal}`);
|
|
1056
2070
|
}
|
|
1057
2071
|
} else if (stepsTotal > 1) {
|
|
1058
2072
|
parts.push(`steps ${stepsTotal}`);
|
|
1059
2073
|
}
|
|
2074
|
+
if (projection.checklist && !checklistPrimary) parts.push(formatWorkflowChecklistSummary(projection.checklist));
|
|
1060
2075
|
if (job.toolCount !== undefined) parts.push(formatToolUseStat(job.toolCount));
|
|
1061
|
-
if (job.totalTokens?.total) parts.push(
|
|
2076
|
+
if (job.totalTokens?.total) parts.push(formatTokenUsage(job.totalTokens, "token"));
|
|
1062
2077
|
if (job.startedAt !== undefined && job.updatedAt !== undefined) parts.push(formatDuration(Math.max(0, job.updatedAt - job.startedAt)));
|
|
1063
2078
|
return statJoin(theme, parts);
|
|
1064
2079
|
}
|
|
@@ -1067,7 +2082,11 @@ function widgetStepStats(theme: Theme, step: NonNullable<AsyncJobState["steps"]>
|
|
|
1067
2082
|
return statJoin(theme, [
|
|
1068
2083
|
step.turnCount !== undefined ? `${step.turnCount} turns` : "",
|
|
1069
2084
|
step.toolCount !== undefined ? formatToolUseStat(step.toolCount) : "",
|
|
1070
|
-
step.tokens
|
|
2085
|
+
step.tokens
|
|
2086
|
+
? step.contextLimit !== undefined
|
|
2087
|
+
? formatContextUsage(step.tokens, step.contextLimit) ?? formatTokenUsage(step.tokens, "token")
|
|
2088
|
+
: step.tokens.total ? formatTokenUsage(step.tokens, "token") : ""
|
|
2089
|
+
: "",
|
|
1071
2090
|
step.durationMs !== undefined ? formatDuration(step.durationMs) : "",
|
|
1072
2091
|
]);
|
|
1073
2092
|
}
|
|
@@ -1092,6 +2111,7 @@ function widgetOutputPath(job: AsyncJobState, step: NonNullable<AsyncJobState["s
|
|
|
1092
2111
|
}
|
|
1093
2112
|
|
|
1094
2113
|
function nestedRunName(run: NestedRunSummary): string {
|
|
2114
|
+
if (run.sessionName?.trim()) return run.sessionName.trim();
|
|
1095
2115
|
if (run.agent) return run.agent;
|
|
1096
2116
|
if (run.agents?.length) return formatWidgetAgents(run.agents);
|
|
1097
2117
|
return run.id;
|
|
@@ -1101,6 +2121,7 @@ function nestedStatusGlyph(state: NestedRunSummary["state"] | NestedStepSummary[
|
|
|
1101
2121
|
if (state === "running") return theme.fg("accent", runningGlyph(seed));
|
|
1102
2122
|
if (state === "complete" || state === "completed") return theme.fg("success", "✓");
|
|
1103
2123
|
if (state === "failed") return theme.fg("error", "✗");
|
|
2124
|
+
if (state === "partial") return theme.fg("warning", "■");
|
|
1104
2125
|
if (state === "paused") return theme.fg("warning", "■");
|
|
1105
2126
|
if (state === "stopped") return theme.fg("warning", "■");
|
|
1106
2127
|
return theme.fg("muted", "◦");
|
|
@@ -1148,6 +2169,7 @@ function nestedActivity(input: Pick<NestedRunSummary | NestedStepSummary, "activ
|
|
|
1148
2169
|
if (state === "queued" || state === "pending") return "queued…";
|
|
1149
2170
|
if (state === "paused") return "Paused";
|
|
1150
2171
|
if (state === "stopped") return "Stopped";
|
|
2172
|
+
if (state === "partial") return "Partial";
|
|
1151
2173
|
if (state === "failed") return "Failed";
|
|
1152
2174
|
return "Done";
|
|
1153
2175
|
}
|
|
@@ -1172,7 +2194,7 @@ function formatNestedWidgetLines(children: NestedRunSummary[] | undefined, theme
|
|
|
1172
2194
|
const activity = nestedActivity(step, state, snapshotNow ?? fallback);
|
|
1173
2195
|
const timestamp = "status" in step ? nestedStepTimestamp(step, fallback) : formatClockTime(nestedRunEventTime(step));
|
|
1174
2196
|
const error = step.error ? ` · ${step.error}` : "";
|
|
1175
|
-
const name = "status" in step ? step
|
|
2197
|
+
const name = "status" in step ? childDisplayName(step) : nestedRunName(step);
|
|
1176
2198
|
rows.push({
|
|
1177
2199
|
prefix,
|
|
1178
2200
|
text: `${nestedTimestampPrefix(timestamp)}${nestedStatusGlyph(state, theme)} ${name} · ${state}${modelThinking ? ` · ${modelThinking}` : ""}${activity ? ` · ${activity}` : ""}${error}`,
|
|
@@ -1234,7 +2256,7 @@ function formatNestedWidgetLines(children: NestedRunSummary[] | undefined, theme
|
|
|
1234
2256
|
for (const step of child.steps ?? []) {
|
|
1235
2257
|
if (lines.length >= lineBudget) return;
|
|
1236
2258
|
const modelThinking = formatModelThinking(step.model, step.thinking);
|
|
1237
|
-
lines.push(theme.fg("dim", `${prefix} ↳ ${nestedTimestampPrefix(nestedStepTimestamp(step, child.lastUpdate))}${nestedStatusGlyph(step.status, theme)} ${step
|
|
2259
|
+
lines.push(theme.fg("dim", `${prefix} ↳ ${nestedTimestampPrefix(nestedStepTimestamp(step, child.lastUpdate))}${nestedStatusGlyph(step.status, theme)} ${childDisplayName(step)} · ${step.status}${modelThinking ? ` · ${modelThinking}` : ""} · ${nestedActivity(step, step.status, snapshotNow ?? child.lastUpdate)}`));
|
|
1238
2260
|
append(step.children, depth + 1, `${prefix} `);
|
|
1239
2261
|
}
|
|
1240
2262
|
append(child.children, depth + 1, `${prefix} `);
|
|
@@ -1248,55 +2270,132 @@ function foregroundStyleWidgetStepLines(
|
|
|
1248
2270
|
job: AsyncJobState,
|
|
1249
2271
|
theme: Theme,
|
|
1250
2272
|
step: NonNullable<AsyncJobState["steps"]>[number],
|
|
1251
|
-
itemTitle: "Agent" | "Step",
|
|
2273
|
+
itemTitle: "Agent" | "Stage" | "Step",
|
|
1252
2274
|
index: number,
|
|
1253
2275
|
total: number,
|
|
1254
2276
|
expanded: boolean,
|
|
1255
2277
|
width: number,
|
|
1256
2278
|
frame?: number,
|
|
2279
|
+
options?: { rowLabel?: string; rowIndent?: string; detailIndent?: string; rowMarker?: string; includeCurrentPath?: boolean },
|
|
1257
2280
|
): string[] {
|
|
2281
|
+
const rowIndent = options?.rowIndent ?? " ";
|
|
2282
|
+
const detailIndent = options?.detailIndent ?? " ";
|
|
1258
2283
|
const status = widgetStepStatus(step.status, theme);
|
|
1259
2284
|
const stats = widgetStepStats(theme, step);
|
|
1260
2285
|
const modelDisplay = modelThinkingBadge(theme, step.model, step.thinking);
|
|
1261
|
-
const
|
|
2286
|
+
const collapseDetails = shouldCollapseSingleChildDetails(job, step);
|
|
2287
|
+
const displayName = collapseDetails ? singleChildAgentName(job, step) : childDisplayName(step);
|
|
2288
|
+
const stageName = itemTitle === "Stage"
|
|
2289
|
+
? compactTaskText(undefined, step.label) ?? boundedLaneValue(step.workflowKey) ?? displayName
|
|
2290
|
+
: undefined;
|
|
2291
|
+
const stageIdentity = stageName && stageName !== displayName ? `${stageName} (${displayName})` : stageName ?? displayName;
|
|
2292
|
+
const rowLabel = collapseDetails ? displayName : (options?.rowLabel ?? `${itemTitle} ${index}/${total}: ${itemTitle === "Stage" ? stageIdentity : displayName}`);
|
|
2293
|
+
const rowMarker = options?.rowMarker ? `${options.rowMarker} ` : "";
|
|
2294
|
+
const lines = [`${rowIndent}${rowMarker}${widgetStepGlyph(step.status, theme, widgetStepRunningSeed(step, index - 1), frame)} ${themeBold(theme, rowLabel)}${contextModeBadge(theme, step.context)} ${theme.fg("dim", "·")} ${status}${modelDisplay}${stats ? ` ${theme.fg("dim", "·")} ${stats}` : ""}`];
|
|
2295
|
+
const lane = projectAsyncLane(job, step);
|
|
2296
|
+
if (lane) lines.push(...formatLaneProjectionLines(lane, theme, detailIndent));
|
|
2297
|
+
const task = collapseDetails ? singleChildTask(job, step) : compactTaskText(step.description, step.label);
|
|
2298
|
+
if (task) lines.push(`${detailIndent}${theme.fg("dim", `task: ${task}`)}`);
|
|
1262
2299
|
const activity = widgetStepActivityLine(step, width, expanded, job.updatedAt);
|
|
1263
|
-
|
|
2300
|
+
const currentPath = options?.includeCurrentPath && step.currentPath ? shortenPath(step.currentPath) : undefined;
|
|
2301
|
+
const activityWithPath = currentPath && activity && !activity.includes(currentPath)
|
|
2302
|
+
? `${activity} · ${currentPath}`
|
|
2303
|
+
: activity ?? currentPath;
|
|
2304
|
+
if (activityWithPath) lines.push(`${detailIndent}${theme.fg("dim", `⎿ ${activityWithPath}`)}`);
|
|
1264
2305
|
for (const nestedLine of formatNestedWidgetLines(step.children, theme, width, expanded, job.updatedAt, expanded ? 12 : 6)) {
|
|
1265
|
-
lines.push(
|
|
2306
|
+
lines.push(`${detailIndent}${nestedLine}`);
|
|
1266
2307
|
}
|
|
2308
|
+
const error = step.error?.trim() || step.execution?.error?.trim();
|
|
2309
|
+
if (error) lines.push(`${detailIndent}${theme.fg("error", `error: ${oneLine(error)}`)}`);
|
|
1267
2310
|
if (step.status === "running") {
|
|
1268
|
-
if (!expanded) lines.push(
|
|
2311
|
+
if (!expanded) lines.push(`${detailIndent}${theme.fg("accent", liveDetailHintText())}`);
|
|
1269
2312
|
const output = widgetOutputPath(job, step);
|
|
1270
|
-
if (output) lines.push(
|
|
2313
|
+
if (output) lines.push(`${detailIndent}${theme.fg("dim", `output: ${shortenPath(output)}`)}`);
|
|
1271
2314
|
if (expanded) {
|
|
1272
2315
|
const liveStatus = buildLiveStatusLine(step, job.updatedAt);
|
|
1273
|
-
if (liveStatus && liveStatus !== activity) lines.push(
|
|
2316
|
+
if (liveStatus && liveStatus !== activity) lines.push(`${detailIndent}${theme.fg("accent", liveStatus)}`);
|
|
1274
2317
|
for (const tool of step.recentTools?.slice(-3) ?? []) {
|
|
1275
2318
|
const maxArgsLen = Math.max(40, width - 30);
|
|
1276
2319
|
const argsPreview = renderToolArgsPreview(tool.args, maxArgsLen, expanded);
|
|
1277
|
-
lines.push(
|
|
2320
|
+
lines.push(`${detailIndent} ${theme.fg("dim", `${tool.tool}${argsPreview ? `: ${argsPreview}` : ""}`)}`);
|
|
1278
2321
|
}
|
|
1279
2322
|
for (const line of compactRecentOutputLines(step.recentOutput)) {
|
|
1280
|
-
lines.push(
|
|
2323
|
+
lines.push(`${detailIndent} ${theme.fg("dim", line)}`);
|
|
1281
2324
|
}
|
|
1282
2325
|
}
|
|
1283
2326
|
}
|
|
1284
2327
|
return lines;
|
|
1285
2328
|
}
|
|
1286
2329
|
|
|
1287
|
-
function
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
2330
|
+
function hostStepWidgetLines(job: AsyncJobState, theme: Theme, indent: string): string[] {
|
|
2331
|
+
const rows = projectAsyncWorkflowRows([], job.hostSteps).filter((row) => row.kind);
|
|
2332
|
+
const visible = rows.slice(0, 8);
|
|
2333
|
+
const lines = visible.map((row) => {
|
|
2334
|
+
const state = hostStepVerdictLabel(row.state as HostStepState, row.verdict as HostStepVerdict | undefined);
|
|
2335
|
+
const glyph = state === "running" ? theme.fg("accent", "●")
|
|
2336
|
+
: state === "pending" ? theme.fg("muted", "◦")
|
|
2337
|
+
: state === "pass" ? theme.fg("success", "✓")
|
|
2338
|
+
: state === "fail" || state === "error" ? theme.fg("error", "✗")
|
|
2339
|
+
: theme.fg("warning", "■");
|
|
2340
|
+
const details = [
|
|
2341
|
+
row.provider ? `provider:${row.provider}` : undefined,
|
|
2342
|
+
row.role ? `role:${row.role}` : undefined,
|
|
2343
|
+
row.target,
|
|
2344
|
+
row.detail,
|
|
2345
|
+
row.reasonCode ? `reason:${row.reasonCode}` : undefined,
|
|
2346
|
+
row.freshness?.stale ? "stale" : row.freshness?.observedRef ? `ref:${row.freshness.observedRef}` : undefined,
|
|
2347
|
+
row.reportPath ? `out:${hostStepReportName(row.reportPath)}` : undefined,
|
|
2348
|
+
].filter(Boolean).join(" · ");
|
|
2349
|
+
return `${indent}${glyph} ${row.kind}: ${row.name} · ${state}${details ? ` · ${details}` : ""}`;
|
|
2350
|
+
});
|
|
2351
|
+
if (rows.length > visible.length) lines.push(`${indent}${theme.fg("dim", `… +${rows.length - visible.length} host steps hidden`)}`);
|
|
2352
|
+
return lines;
|
|
2353
|
+
}
|
|
2354
|
+
|
|
2355
|
+
function foregroundStyleWidgetDetails(job: AsyncJobState, theme: Theme, expanded: boolean, width: number, frame?: number, projection = buildWorkflowWidgetProjection(job)): string[] {
|
|
2356
|
+
const { steps } = projection;
|
|
2357
|
+
if (!expanded && job.mode === "workflow") {
|
|
2358
|
+
return compactWorkflowWidgetBodyLines(job, theme, frame, projection);
|
|
2359
|
+
}
|
|
2360
|
+
if (!steps.length) {
|
|
2361
|
+
const lane = projectAsyncLane(job, laneStepForJob(job, steps));
|
|
2362
|
+
return [
|
|
2363
|
+
...(expanded ? workflowPreflightLines(job) : []),
|
|
2364
|
+
...workflowChecklistWidgetLines(projection.checklist, theme, " ", expanded, frame),
|
|
2365
|
+
...(lane ? formatLaneProjectionLines(lane, theme, " ") : []),
|
|
2366
|
+
...hostStepWidgetLines(job, theme, " "),
|
|
2367
|
+
` ${theme.fg("dim", `⎿ ${widgetActivity(job)}`)}`,
|
|
2368
|
+
...formatNestedWidgetLines(job.nestedChildren, theme, width, expanded, job.updatedAt, expanded ? 12 : 6).map((line) => ` ${line}`),
|
|
2369
|
+
];
|
|
2370
|
+
}
|
|
1292
2371
|
if (job.mode === "chain" && !job.activeParallelGroup && job.parallelGroups?.length) return widgetChainDetails(job, theme, expanded, width, frame);
|
|
1293
|
-
const
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
2372
|
+
const lines: string[] = [
|
|
2373
|
+
...(expanded ? workflowPreflightLines(job) : []),
|
|
2374
|
+
...workflowChecklistWidgetLines(projection.checklist, theme, " ", expanded, frame),
|
|
2375
|
+
];
|
|
2376
|
+
const group = activeParallelWidgetGroup(job);
|
|
2377
|
+
if (group) {
|
|
2378
|
+
lines.push(...parallelWidgetGroupDetails(job, theme, group, expanded, width, frame, Boolean(job.activeParallelGroup)));
|
|
2379
|
+
} else {
|
|
2380
|
+
const { stageProgress, plannedKeys } = projection;
|
|
2381
|
+
const total = job.mode === "chain"
|
|
2382
|
+
? job.chainStepCount ?? job.stepsTotal ?? steps.length
|
|
2383
|
+
: stageProgress?.total ?? job.stepsTotal ?? steps.length;
|
|
2384
|
+
const stageTotal = stageProgress?.total ?? total;
|
|
2385
|
+
const extraStepCount = plannedKeys
|
|
2386
|
+
? steps.filter((step) => step.workflowKey === undefined || !plannedKeys.has(step.workflowKey)).length
|
|
2387
|
+
: total;
|
|
2388
|
+
let extraStepIndex = 0;
|
|
2389
|
+
for (const [index, step] of steps.entries()) {
|
|
2390
|
+
const isPlannedStage = plannedKeys !== undefined && step.workflowKey !== undefined && plannedKeys.has(step.workflowKey);
|
|
2391
|
+
const itemTitle = isPlannedStage ? "Stage" : "Step";
|
|
2392
|
+
const displayIndex = isPlannedStage ? (step.index ?? index) + 1 : plannedKeys ? ++extraStepIndex : index + 1;
|
|
2393
|
+
const displayTotal = isPlannedStage ? stageTotal : extraStepCount;
|
|
2394
|
+
lines.push(...foregroundStyleWidgetStepLines(job, theme, step, itemTitle, displayIndex, displayTotal, expanded, width, frame));
|
|
2395
|
+
}
|
|
1298
2396
|
}
|
|
1299
|
-
|
|
2397
|
+
lines.push(...hostStepWidgetLines(job, theme, " "));
|
|
2398
|
+
const attached = new Set(steps.flatMap((step) => step.children?.map((child) => child.id) ?? []));
|
|
1300
2399
|
const unattached = job.nestedChildren?.filter((child) => !attached.has(child.id)) ?? [];
|
|
1301
2400
|
for (const nestedLine of formatNestedWidgetLines(unattached, theme, width, expanded, job.updatedAt, expanded ? 12 : 6)) {
|
|
1302
2401
|
lines.push(` ${nestedLine}`);
|
|
@@ -1304,34 +2403,51 @@ function foregroundStyleWidgetDetails(job: AsyncJobState, theme: Theme, expanded
|
|
|
1304
2403
|
return lines;
|
|
1305
2404
|
}
|
|
1306
2405
|
|
|
1307
|
-
function buildSingleWidgetLines(job: AsyncJobState, theme: Theme, width: number, expanded: boolean, frame?: number): string[] {
|
|
1308
|
-
|
|
1309
|
-
const
|
|
2406
|
+
function buildSingleWidgetLines(job: AsyncJobState, theme: Theme, width: number, expanded: boolean, frame?: number, projection = buildWorkflowWidgetProjection(job)): string[] {
|
|
2407
|
+
if (!expanded && job.mode === "workflow") return [compactWorkflowHeaderLine(job, theme, width), ...compactWorkflowWidgetBodyLines(job, theme, frame, projection)].map((line) => truncLine(line, width));
|
|
2408
|
+
const stats = widgetStats(job, theme, projection, !expanded);
|
|
2409
|
+
const count = job.mode === "workflow"
|
|
2410
|
+
? projection.checklist?.total ?? projection.stageProgress?.total ?? job.stepsTotal ?? job.agents?.length ?? job.steps?.length
|
|
2411
|
+
: job.mode === "chain" ? job.chainStepCount : projection.stageProgress?.total ?? job.stepsTotal ?? job.agents?.length ?? job.steps?.length;
|
|
1310
2412
|
const mode = widgetJobName(job);
|
|
1311
|
-
const title =
|
|
2413
|
+
const title = isSingleChildAsyncJob(job)
|
|
2414
|
+
? "async subagent"
|
|
2415
|
+
: `async subagent ${mode}${count && count > 1 ? ` (${count})` : ""}`;
|
|
2416
|
+
const checklistPrimary = !expanded && job.mode === "workflow" && projection.checklist !== undefined;
|
|
2417
|
+
const collapseDetails = !checklistPrimary && job.steps?.length === 1 && shouldCollapseSingleChildDetails(job, job.steps[0]!);
|
|
2418
|
+
const summary = `${widgetStatusGlyph(job, theme, frame)} ${themeBold(theme, mode)}${contextModeBadge(theme, job.context)}${stats ? ` ${theme.fg("dim", "·")} ${stats}` : ""}`;
|
|
1312
2419
|
return [
|
|
1313
2420
|
`${theme.fg("toolTitle", themeBold(theme, title))} ${theme.fg("dim", "· background")}`,
|
|
1314
|
-
|
|
1315
|
-
...foregroundStyleWidgetDetails(job, theme, expanded, width, frame),
|
|
2421
|
+
...(collapseDetails ? [] : [summary]),
|
|
2422
|
+
...foregroundStyleWidgetDetails(job, theme, expanded, width, frame, projection),
|
|
1316
2423
|
].map((line) => truncLine(line, width));
|
|
1317
2424
|
}
|
|
1318
2425
|
|
|
1319
|
-
function compactSingleWidgetLines(job: AsyncJobState, theme: Theme, width: number, frame?: number): string[] {
|
|
1320
|
-
const fullLines = buildSingleWidgetLines(job, theme, width, false, frame);
|
|
2426
|
+
function compactSingleWidgetLines(job: AsyncJobState, theme: Theme, width: number, frame?: number, projection = buildWorkflowWidgetProjection(job)): string[] {
|
|
2427
|
+
const fullLines = buildSingleWidgetLines(job, theme, width, false, frame, projection);
|
|
1321
2428
|
if (fullLines.length <= 10 || !job.steps?.length || (job.mode !== "parallel" && !job.activeParallelGroup)) return fullLines;
|
|
1322
2429
|
|
|
1323
|
-
const
|
|
1324
|
-
|
|
2430
|
+
const group = activeParallelWidgetGroup(job);
|
|
2431
|
+
if (!group) return fullLines;
|
|
2432
|
+
const rows = parallelWidgetStepRows(group.steps, group.total, Boolean(job.activeParallelGroup));
|
|
1325
2433
|
const lines = fullLines.slice(0, 2);
|
|
1326
|
-
|
|
2434
|
+
lines.push(parallelWidgetGroupHeader(group, theme, frame));
|
|
2435
|
+
for (const [rowIndex, row] of rows.entries()) {
|
|
2436
|
+
const step = row.step;
|
|
1327
2437
|
const status = widgetStepStatus(step.status, theme);
|
|
1328
2438
|
const activity = widgetStepActivityLine(step, width, false, job.updatedAt);
|
|
1329
2439
|
const stepStats = widgetStepStats(theme, step);
|
|
1330
2440
|
const activitySuffix = activity ? ` ${theme.fg("dim", "·")} ${theme.fg("dim", activity)}` : "";
|
|
1331
2441
|
const modelDisplay = modelThinkingBadge(theme, step.model, step.thinking);
|
|
1332
|
-
|
|
1333
|
-
|
|
2442
|
+
const task = compactTaskText(step.description, step.label);
|
|
2443
|
+
const taskSuffix = task ? ` ${theme.fg("dim", "·")} ${theme.fg("dim", `task: ${task}`)}` : "";
|
|
2444
|
+
const marker = rowIndex === rows.length - 1 && rowIndex >= group.total - 1 ? "└─" : "├─";
|
|
2445
|
+
lines.push(` ${marker} ${widgetStepGlyph(step.status, theme, widgetStepRunningSeed(step, row.index), frame)} ${themeBold(theme, row.rowLabel)}${contextModeBadge(theme, step.context)} ${theme.fg("dim", "·")} ${status}${modelDisplay}${taskSuffix}${activitySuffix}${stepStats ? ` ${theme.fg("dim", "·")} ${stepStats}` : ""}`);
|
|
2446
|
+
const lane = projectAsyncLane(job, step);
|
|
2447
|
+
if (lane) lines.push(...formatLaneProjectionLines(lane, theme, " "));
|
|
2448
|
+
for (const nestedLine of formatNestedWidgetLines(step.children, theme, width, false, job.updatedAt, 6)) lines.push(` ${nestedLine}`);
|
|
1334
2449
|
}
|
|
2450
|
+
lines.push(...hostStepWidgetLines(job, theme, " "));
|
|
1335
2451
|
if (job.steps.some((step) => step.status === "running")) lines.push(theme.fg("accent", ` ${liveDetailHintText()}`));
|
|
1336
2452
|
return lines.map((line) => truncLine(line, width));
|
|
1337
2453
|
}
|
|
@@ -1464,13 +2580,29 @@ function progressiveHeaderLine(jobs: AsyncJobState[], theme: Theme, width: numbe
|
|
|
1464
2580
|
return truncLine(`${theme.fg(hasActive ? "accent" : "dim", glyph)} ${theme.fg(hasActive ? "accent" : "dim", "Async agents")} ${theme.fg("dim", "·")} ${theme.fg("dim", parts.join(", ") || `${jobs.length} total`)}`, width);
|
|
1465
2581
|
}
|
|
1466
2582
|
|
|
1467
|
-
function progressiveJobLine(job: AsyncJobState, theme: Theme, width: number, frame?: number): string {
|
|
1468
|
-
const
|
|
2583
|
+
function progressiveJobLine(job: AsyncJobState, theme: Theme, width: number, frame?: number, projection = buildWorkflowWidgetProjection(job)): string {
|
|
2584
|
+
const compactWorkflow = job.mode === "workflow";
|
|
2585
|
+
const compactRows = compactWorkflow ? compactWorkflowLaneRows(job, projection.checklist) : undefined;
|
|
2586
|
+
const stats = compactWorkflow ? compactWorkflowStats(job, compactRows ?? [], theme, projection) : widgetStats(job, theme, projection, true);
|
|
2587
|
+
if (compactWorkflow) {
|
|
2588
|
+
const bottleneck = compactWorkflowBottleneck(compactRows ?? [], job);
|
|
2589
|
+
const suffix = [stats, bottleneck ? theme.fg(bottleneck.tone, `bottleneck · ${bottleneck.text}`) : undefined].filter((value): value is string => Boolean(value)).join(` ${theme.fg("dim", "·")} `);
|
|
2590
|
+
return truncLine(` ${widgetStatusGlyph(job, theme, frame)} ${compactWorkflowHeaderLine(job, theme, Math.max(0, width - 4))}${suffix ? ` ${theme.fg("dim", "·")} ${suffix}` : ""}`, width);
|
|
2591
|
+
}
|
|
1469
2592
|
const activity = widgetActivity(job);
|
|
1470
2593
|
const status = job.status === "complete" ? "done" : job.status;
|
|
2594
|
+
const lane = projectAsyncLane(job, laneStepForJob(job, projection.steps));
|
|
2595
|
+
const laneSummary = lane
|
|
2596
|
+
? [lane.label ?? lane.role, lane.phase ? `phase:${lane.phase}` : undefined, lane.output ? `out:${lane.output}` : undefined, lane.workspace ? `workspace:${lane.workspace}` : `ref:${lane.ref}`].filter(Boolean).join(" · ")
|
|
2597
|
+
: "";
|
|
2598
|
+
const laneSignals = lane
|
|
2599
|
+
? [lane.next ? `next:${lane.next}` : undefined, ...lane.chips.map((chip) => formatLaneChip(chip, theme))].filter(Boolean).join(" · ")
|
|
2600
|
+
: "";
|
|
1471
2601
|
const parts = [
|
|
1472
2602
|
`${themeBold(theme, widgetJobName(job))}${contextModeBadge(theme, job.context)}`,
|
|
1473
2603
|
theme.fg("dim", status),
|
|
2604
|
+
laneSignals ? laneSignals : "",
|
|
2605
|
+
laneSummary ? theme.fg("dim", laneSummary) : "",
|
|
1474
2606
|
stats,
|
|
1475
2607
|
activity && activity.toLowerCase() !== status ? theme.fg("dim", activity) : "",
|
|
1476
2608
|
].filter(Boolean);
|
|
@@ -1487,7 +2619,7 @@ function progressiveHiddenLine(hiddenJobs: AsyncJobState[], theme: Theme, width:
|
|
|
1487
2619
|
return truncLine(theme.fg("dim", ` +${hiddenJobs.length} more${parts.length ? ` (${parts.join(", ")})` : ""}`), width);
|
|
1488
2620
|
}
|
|
1489
2621
|
|
|
1490
|
-
function buildProgressiveWidgetLines(jobs: AsyncJobState[], theme: Theme, width: number, lockedRows: number, previousKeys: string[], frame?: number): { lines: string[]; visibleJobKeys: string[] } {
|
|
2622
|
+
function buildProgressiveWidgetLines(jobs: AsyncJobState[], theme: Theme, width: number, lockedRows: number, previousKeys: string[], frame?: number, projectionFor: WorkflowWidgetProjectionLookup = workflowWidgetProjectionLookup()): { lines: string[]; visibleJobKeys: string[] } {
|
|
1491
2623
|
const rowCount = Math.max(1, lockedRows);
|
|
1492
2624
|
if (rowCount === 1) return { lines: buildSingleLineWidgetLines(jobs, theme, width, frame), visibleJobKeys: [] };
|
|
1493
2625
|
|
|
@@ -1506,7 +2638,7 @@ function buildProgressiveWidgetLines(jobs: AsyncJobState[], theme: Theme, width:
|
|
|
1506
2638
|
|
|
1507
2639
|
const lines = [
|
|
1508
2640
|
progressiveHeaderLine(jobs, theme, width, frame),
|
|
1509
|
-
...visibleJobs.map((job) => progressiveJobLine(job, theme, width, frame)),
|
|
2641
|
+
...visibleJobs.map((job) => progressiveJobLine(job, theme, width, frame, projectionFor(job))),
|
|
1510
2642
|
];
|
|
1511
2643
|
if (hiddenJobs.length > 0 && lines.length < rowCount) lines.push(progressiveHiddenLine(hiddenJobs, theme, width));
|
|
1512
2644
|
while (lines.length < rowCount) lines.push(" ");
|
|
@@ -1537,7 +2669,7 @@ function fitWidgetLineBudget(lines: string[], theme: Theme, width: number, expan
|
|
|
1537
2669
|
return [...lines.slice(0, visibleLines), truncLine(theme.fg("dim", hint), width)];
|
|
1538
2670
|
}
|
|
1539
2671
|
|
|
1540
|
-
function fitAdaptiveWidgetLines(jobs: AsyncJobState[], buildLines: () => string[], theme: Theme, width: number, expanded: boolean, frame?: number): string[] {
|
|
2672
|
+
function fitAdaptiveWidgetLines(jobs: AsyncJobState[], buildLines: () => string[], theme: Theme, width: number, expanded: boolean, frame?: number, projectionFor?: WorkflowWidgetProjectionLookup): string[] {
|
|
1541
2673
|
if (expanded) {
|
|
1542
2674
|
resetWidgetLayoutSession();
|
|
1543
2675
|
return fitWidgetLineBudget(buildLines(), theme, width, true);
|
|
@@ -1553,7 +2685,7 @@ function fitAdaptiveWidgetLines(jobs: AsyncJobState[], buildLines: () => string[
|
|
|
1553
2685
|
}
|
|
1554
2686
|
|
|
1555
2687
|
if (hasMatchingSession && widgetLayoutSession?.tier === "progressive" && widgetLayoutSession.lockedRows !== undefined) {
|
|
1556
|
-
const rendered = buildProgressiveWidgetLines(jobs, theme, width, widgetLayoutSession.lockedRows, widgetLayoutSession.visibleJobKeys, frame);
|
|
2688
|
+
const rendered = buildProgressiveWidgetLines(jobs, theme, width, widgetLayoutSession.lockedRows, widgetLayoutSession.visibleJobKeys, frame, projectionFor);
|
|
1557
2689
|
widgetLayoutSession.visibleJobKeys = rendered.visibleJobKeys;
|
|
1558
2690
|
return rendered.lines;
|
|
1559
2691
|
}
|
|
@@ -1563,6 +2695,10 @@ function fitAdaptiveWidgetLines(jobs: AsyncJobState[], buildLines: () => string[
|
|
|
1563
2695
|
widgetLayoutSession = { expanded, rows, columns, tier: "full", visibleJobKeys: [] };
|
|
1564
2696
|
return fitWidgetLineBudget(lines, theme, width, false);
|
|
1565
2697
|
}
|
|
2698
|
+
if (availableRows > 2 && jobs.length === 1 && projectionFor?.(jobs[0]!).stageProgress) {
|
|
2699
|
+
widgetLayoutSession = { expanded, rows, columns, tier: "full", visibleJobKeys: [] };
|
|
2700
|
+
return fitWidgetLineBudget(lines, theme, width, false);
|
|
2701
|
+
}
|
|
1566
2702
|
|
|
1567
2703
|
if (availableRows <= 2) {
|
|
1568
2704
|
widgetLayoutSession = { expanded, rows, columns, tier: "single-line", visibleJobKeys: [] };
|
|
@@ -1570,31 +2706,42 @@ function fitAdaptiveWidgetLines(jobs: AsyncJobState[], buildLines: () => string[
|
|
|
1570
2706
|
}
|
|
1571
2707
|
|
|
1572
2708
|
const lockedRows = Math.min(availableRows, collapsedWidgetLineBudget(rows));
|
|
1573
|
-
const rendered = buildProgressiveWidgetLines(jobs, theme, width, lockedRows, [], frame);
|
|
2709
|
+
const rendered = buildProgressiveWidgetLines(jobs, theme, width, lockedRows, [], frame, projectionFor);
|
|
1574
2710
|
widgetLayoutSession = { expanded, rows, columns, tier: "progressive", lockedRows, visibleJobKeys: rendered.visibleJobKeys };
|
|
1575
2711
|
return rendered.lines;
|
|
1576
2712
|
}
|
|
1577
2713
|
|
|
1578
|
-
function buildWidgetComponent(jobs: AsyncJobState[],
|
|
2714
|
+
function buildWidgetComponent(jobs: AsyncJobState[], isExpanded: () => boolean): (_tui: unknown, theme: Theme) => Component {
|
|
1579
2715
|
return (_tui, theme) => {
|
|
1580
2716
|
const container = new Container();
|
|
2717
|
+
let cachedRenderWidth: number | undefined;
|
|
2718
|
+
let cachedFrame: number | undefined;
|
|
2719
|
+
let cachedExpanded: boolean | undefined;
|
|
2720
|
+
let cachedLines: string[] | undefined;
|
|
1581
2721
|
container.render = (renderWidth: number): string[] => {
|
|
2722
|
+
const frame = Math.floor(Date.now() / WIDGET_ANIMATION_INTERVAL_MS);
|
|
2723
|
+
const expanded = isExpanded();
|
|
2724
|
+
if (cachedLines && cachedRenderWidth === renderWidth && cachedFrame === frame && cachedExpanded === expanded) return cachedLines;
|
|
1582
2725
|
const width = Math.max(0, renderWidth - 2);
|
|
1583
|
-
const
|
|
2726
|
+
const projectionFor = workflowWidgetProjectionLookup();
|
|
1584
2727
|
const buildLines = (): string[] => expanded
|
|
1585
|
-
?
|
|
2728
|
+
? buildWidgetLinesWithProjection(jobs, theme, width, true, frame, projectionFor)
|
|
1586
2729
|
: jobs.length === 1
|
|
1587
|
-
? compactSingleWidgetLines(jobs[0]!, theme, width, frame)
|
|
1588
|
-
:
|
|
1589
|
-
|
|
2730
|
+
? compactSingleWidgetLines(jobs[0]!, theme, width, frame, projectionFor(jobs[0]!))
|
|
2731
|
+
: buildWidgetLinesWithProjection(jobs, theme, width, false, frame, projectionFor);
|
|
2732
|
+
cachedRenderWidth = renderWidth;
|
|
2733
|
+
cachedFrame = frame;
|
|
2734
|
+
cachedExpanded = expanded;
|
|
2735
|
+
cachedLines = fitAdaptiveWidgetLines(jobs, buildLines, theme, width, expanded, frame, projectionFor).map((line) => paddedWidgetLine(line, renderWidth));
|
|
2736
|
+
return cachedLines;
|
|
1590
2737
|
};
|
|
1591
2738
|
return container;
|
|
1592
2739
|
};
|
|
1593
2740
|
}
|
|
1594
2741
|
|
|
1595
|
-
|
|
2742
|
+
function buildWidgetLinesWithProjection(jobs: AsyncJobState[], theme: Theme, width = getTermWidth(), expanded = false, frame?: number, projectionFor: WorkflowWidgetProjectionLookup = workflowWidgetProjectionLookup()): string[] {
|
|
1596
2743
|
if (jobs.length === 0) return [];
|
|
1597
|
-
if (jobs.length === 1) return buildSingleWidgetLines(jobs[0]!, theme, width, expanded, frame);
|
|
2744
|
+
if (jobs.length === 1) return buildSingleWidgetLines(jobs[0]!, theme, width, expanded, frame, projectionFor(jobs[0]!));
|
|
1598
2745
|
const running = jobs.filter((job) => job.status === "running");
|
|
1599
2746
|
const queued = jobs.filter((job) => job.status === "queued");
|
|
1600
2747
|
const finished = jobs.filter((job) => job.status !== "running" && job.status !== "queued");
|
|
@@ -1609,15 +2756,31 @@ export function buildWidgetLines(jobs: AsyncJobState[], theme: Theme, width = ge
|
|
|
1609
2756
|
let hiddenFinished = 0;
|
|
1610
2757
|
let queuedSummaryShown = false;
|
|
1611
2758
|
let slots = MAX_WIDGET_JOBS;
|
|
2759
|
+
const appendJob = (job: AsyncJobState): void => {
|
|
2760
|
+
const projection = projectionFor(job);
|
|
2761
|
+
const compactWorkflow = !expanded && job.mode === "workflow";
|
|
2762
|
+
const stats = compactWorkflow ? "" : widgetStats(job, theme, projection, !expanded);
|
|
2763
|
+
const details = compactWorkflow
|
|
2764
|
+
? [
|
|
2765
|
+
...compactWorkflowWidgetBodyLines(job, theme, frame, projection),
|
|
2766
|
+
]
|
|
2767
|
+
: [
|
|
2768
|
+
` ${theme.fg("dim", `⎿ ${widgetActivity(job)}`)}`,
|
|
2769
|
+
...widgetLaneDetailLines(job, theme, projection),
|
|
2770
|
+
...workflowChecklistWidgetLines(projection.checklist, theme, " ", expanded, frame),
|
|
2771
|
+
...widgetParallelAgentDetails(job, theme, expanded, width, frame),
|
|
2772
|
+
];
|
|
2773
|
+
items.push([
|
|
2774
|
+
compactWorkflow
|
|
2775
|
+
? compactWorkflowHeaderLine(job, theme, width)
|
|
2776
|
+
: `${widgetStatusGlyph(job, theme, frame)} ${themeBold(theme, widgetJobName(job))}${contextModeBadge(theme, job.context)}${stats ? ` ${theme.fg("dim", "·")} ${stats}` : ""}`,
|
|
2777
|
+
...details,
|
|
2778
|
+
]);
|
|
2779
|
+
};
|
|
1612
2780
|
|
|
1613
2781
|
for (const job of running) {
|
|
1614
2782
|
if (slots <= 0) { hiddenRunning++; continue; }
|
|
1615
|
-
|
|
1616
|
-
items.push([
|
|
1617
|
-
`${widgetStatusGlyph(job, theme, frame)} ${themeBold(theme, widgetJobName(job))}${contextModeBadge(theme, job.context)}${stats ? ` ${theme.fg("dim", "·")} ${stats}` : ""}`,
|
|
1618
|
-
` ${theme.fg("dim", `⎿ ${widgetActivity(job)}`)}`,
|
|
1619
|
-
...widgetParallelAgentDetails(job, theme, expanded, width, frame),
|
|
1620
|
-
]);
|
|
2783
|
+
appendJob(job);
|
|
1621
2784
|
slots--;
|
|
1622
2785
|
}
|
|
1623
2786
|
|
|
@@ -1629,12 +2792,7 @@ export function buildWidgetLines(jobs: AsyncJobState[], theme: Theme, width = ge
|
|
|
1629
2792
|
|
|
1630
2793
|
for (const job of finished) {
|
|
1631
2794
|
if (slots <= 0) { hiddenFinished++; continue; }
|
|
1632
|
-
|
|
1633
|
-
items.push([
|
|
1634
|
-
`${widgetStatusGlyph(job, theme, frame)} ${themeBold(theme, widgetJobName(job))}${contextModeBadge(theme, job.context)}${stats ? ` ${theme.fg("dim", "·")} ${stats}` : ""}`,
|
|
1635
|
-
` ${theme.fg("dim", `⎿ ${widgetActivity(job)}`)}`,
|
|
1636
|
-
...widgetParallelAgentDetails(job, theme, expanded, width, frame),
|
|
1637
|
-
]);
|
|
2795
|
+
appendJob(job);
|
|
1638
2796
|
slots--;
|
|
1639
2797
|
}
|
|
1640
2798
|
|
|
@@ -1662,6 +2820,10 @@ export function buildWidgetLines(jobs: AsyncJobState[], theme: Theme, width = ge
|
|
|
1662
2820
|
return lines;
|
|
1663
2821
|
}
|
|
1664
2822
|
|
|
2823
|
+
export function buildWidgetLines(jobs: AsyncJobState[], theme: Theme, width = getTermWidth(), expanded = false, frame?: number): string[] {
|
|
2824
|
+
return buildWidgetLinesWithProjection(jobs, theme, width, expanded, frame);
|
|
2825
|
+
}
|
|
2826
|
+
|
|
1665
2827
|
/**
|
|
1666
2828
|
* Render the async jobs widget
|
|
1667
2829
|
*/
|
|
@@ -1676,7 +2838,7 @@ export function renderWidget(ctx: ExtensionContext, jobs: AsyncJobState[]): void
|
|
|
1676
2838
|
ctx.ui.setWidget(WIDGET_KEY, encodeAsyncStatusSnapshotWidget(jobs));
|
|
1677
2839
|
return;
|
|
1678
2840
|
}
|
|
1679
|
-
ctx.ui.setWidget(WIDGET_KEY, buildWidgetComponent(jobs, ctx.ui.getToolsExpanded?.() ?? false));
|
|
2841
|
+
ctx.ui.setWidget(WIDGET_KEY, buildWidgetComponent(jobs, () => ctx.ui.getToolsExpanded?.() ?? false));
|
|
1680
2842
|
}
|
|
1681
2843
|
|
|
1682
2844
|
function renderSingleCompact(
|
|
@@ -1700,9 +2862,11 @@ function renderSingleCompact(
|
|
|
1700
2862
|
const detailIndent = mainWindowIndent(layout, 1);
|
|
1701
2863
|
const continuationIndent = mainWindowIndent(layout, 2) + (layout.horizontalSpacing > 0 ? " " : "");
|
|
1702
2864
|
const modelDisplay = modelThinkingBadge(theme, r.model ?? r.progress?.model, r.thinking ?? r.progress?.thinking);
|
|
1703
|
-
c.addChild(new Text(truncLine(`${resultGlyph(r, output, theme, isRunning, undefined, frame)} ${theme.fg("toolTitle", theme.bold(r
|
|
2865
|
+
c.addChild(new Text(truncLine(`${resultGlyph(r, output, theme, isRunning, undefined, frame)} ${theme.fg("toolTitle", theme.bold(foregroundSingleDisplayName(r)))}${modelDisplay}${contextBadge}${stats ? ` ${theme.fg("dim", "·")} ${stats}` : ""}`, width), 0, 0));
|
|
1704
2866
|
|
|
1705
2867
|
if (isRunning && r.progress) {
|
|
2868
|
+
const task = compactTaskText(r.task);
|
|
2869
|
+
if (task) c.addChild(new Text(truncLine(theme.fg("dim", `${detailIndent}task: ${task}`), width), 0, 0));
|
|
1706
2870
|
const progressSnapshotNow = snapshotNowForProgress(r.progress);
|
|
1707
2871
|
const activity = compactCurrentActivity(r.progress);
|
|
1708
2872
|
c.addChild(new Text(truncLine(theme.fg("dim", `${detailIndent}⎿ ${activity}`), width), 0, 0));
|
|
@@ -1731,6 +2895,7 @@ function renderSingleCompact(
|
|
|
1731
2895
|
}
|
|
1732
2896
|
|
|
1733
2897
|
function workflowRowGlyph(row: WorkflowChatProgressRow, theme: Theme, frame?: number): string {
|
|
2898
|
+
if (row.state === "planned") return theme.fg("muted", "◦");
|
|
1734
2899
|
if (row.state === "running") return theme.fg("accent", runningGlyph(frame));
|
|
1735
2900
|
if (row.state === "complete") return theme.fg("success", "✓");
|
|
1736
2901
|
if (row.state === "detached" || row.state === "stopped") return theme.fg("warning", "■");
|
|
@@ -1739,6 +2904,7 @@ function workflowRowGlyph(row: WorkflowChatProgressRow, theme: Theme, frame?: nu
|
|
|
1739
2904
|
|
|
1740
2905
|
function workflowRowStateLabel(row: WorkflowChatProgressRow, theme: Theme): string {
|
|
1741
2906
|
const label = (row.state === "complete" ? "complete" : row.state).padEnd(8);
|
|
2907
|
+
if (row.state === "planned") return theme.fg("dim", label);
|
|
1742
2908
|
if (row.state === "running") return theme.fg("accent", label);
|
|
1743
2909
|
if (row.state === "complete") return theme.fg("success", label);
|
|
1744
2910
|
if (row.state === "detached" || row.state === "stopped") return theme.fg("warning", label);
|
|
@@ -1746,15 +2912,72 @@ function workflowRowStateLabel(row: WorkflowChatProgressRow, theme: Theme): stri
|
|
|
1746
2912
|
}
|
|
1747
2913
|
|
|
1748
2914
|
function workflowOverallState(rows: WorkflowChatProgressRow[], hasTerminalValue: boolean, isError?: boolean): "running" | "complete" | "failed" | "paused" {
|
|
1749
|
-
if (
|
|
2915
|
+
if (rows.some((row) => row.state === "failed")) return "failed";
|
|
1750
2916
|
if (rows.some((row) => row.state === "detached")) return "paused";
|
|
2917
|
+
if (isError) return "failed";
|
|
1751
2918
|
if ((rows.length > 0 && rows.every((row) => row.state === "complete")) || hasTerminalValue) return "complete";
|
|
1752
2919
|
return "running";
|
|
1753
2920
|
}
|
|
1754
2921
|
|
|
1755
|
-
function
|
|
2922
|
+
function foregroundWorkflowChecklist(details: Details): WorkflowChecklistProjection | undefined {
|
|
2923
|
+
if (details.mode !== "workflow") return undefined;
|
|
2924
|
+
const stageNodes = details.workflowGraph ? workflowGraphStageNodes(details.workflowGraph) : [];
|
|
2925
|
+
const steps: WorkflowChecklistStep[] = details.results.flatMap((result, resultIndex) => {
|
|
2926
|
+
const stableIndex = foregroundResultIndex(details, resultIndex);
|
|
2927
|
+
const workflowKey = (result as { workflowKey?: unknown }).workflowKey;
|
|
2928
|
+
if (details.workflowGraph && typeof workflowKey !== "string") return [];
|
|
2929
|
+
const node = typeof workflowKey === "string"
|
|
2930
|
+
? stageNodes.find((candidate) => candidate.id === workflowKey)
|
|
2931
|
+
: undefined;
|
|
2932
|
+
const progress = foregroundProgressForResult(details, resultIndex);
|
|
2933
|
+
const status = isResultRunning(result) || progress?.status === "running"
|
|
2934
|
+
? "running"
|
|
2935
|
+
: result.detached
|
|
2936
|
+
? "paused"
|
|
2937
|
+
: result.stopped
|
|
2938
|
+
? "stopped"
|
|
2939
|
+
: result.exitCode === 0
|
|
2940
|
+
? "complete"
|
|
2941
|
+
: "failed";
|
|
2942
|
+
return [{
|
|
2943
|
+
key: node?.id ?? (typeof workflowKey === "string" ? workflowKey : `result-${resultIndex + 1}`),
|
|
2944
|
+
label: node?.label ?? workflowLabelForResult(details, resultIndex) ?? result.task ?? result.agent,
|
|
2945
|
+
phase: node?.phase,
|
|
2946
|
+
agent: result.agent,
|
|
2947
|
+
status,
|
|
2948
|
+
context: result.context,
|
|
2949
|
+
activityState: progress?.activityState,
|
|
2950
|
+
startedAt: progress?.lastActivityAt !== undefined && progress.durationMs !== undefined ? progress.lastActivityAt - progress.durationMs : undefined,
|
|
2951
|
+
durationMs: progress?.durationMs,
|
|
2952
|
+
currentTool: progress?.currentTool,
|
|
2953
|
+
currentToolStartedAt: progress?.currentToolStartedAt,
|
|
2954
|
+
currentPath: progress?.currentPath,
|
|
2955
|
+
turnCount: progress?.turnCount,
|
|
2956
|
+
toolCount: progress?.toolCount ?? result.progressSummary?.toolCount,
|
|
2957
|
+
error: result.error,
|
|
2958
|
+
toolBudgetBlocked: result.toolBudgetBlocked,
|
|
2959
|
+
turnBudgetExceeded: result.turnBudgetExceeded,
|
|
2960
|
+
timedOut: result.timedOut,
|
|
2961
|
+
stopped: result.stopped,
|
|
2962
|
+
acceptance: result.acceptance ? { status: result.acceptance.status, reviewResult: result.acceptance.reviewResult ? { status: result.acceptance.reviewResult.status } : undefined } : undefined,
|
|
2963
|
+
review: result.review ? { status: result.review.status } : undefined,
|
|
2964
|
+
watchdog: result.watchdog,
|
|
2965
|
+
}];
|
|
2966
|
+
});
|
|
2967
|
+
const checklist = projectWorkflowChecklist({
|
|
2968
|
+
graph: details.workflowGraph,
|
|
2969
|
+
steps,
|
|
2970
|
+
hostSteps: details.workflow?.receipt?.hostSteps,
|
|
2971
|
+
preflight: details.preflight,
|
|
2972
|
+
trace: details.workflow?.trace,
|
|
2973
|
+
now: Date.now(),
|
|
2974
|
+
});
|
|
2975
|
+
return checklist.total > 0 ? checklist : undefined;
|
|
2976
|
+
}
|
|
2977
|
+
|
|
2978
|
+
function renderWorkflowChatProgress(d: Details, result: AgentToolResult<Details>, theme: Theme, layout: MainWindowRenderLayout, frame?: number, expanded = false): Component {
|
|
1756
2979
|
const workflow = d.workflow;
|
|
1757
|
-
const rows = workflow ? buildWorkflowChatProgressRows(workflow.trace) : [];
|
|
2980
|
+
const rows = workflow ? buildWorkflowChatProgressRows(workflow.trace, d.preflight) : d.preflight ? buildWorkflowChatProgressRows([], d.preflight) : [];
|
|
1758
2981
|
const state = workflowOverallState(rows, workflow?.value !== undefined, result.isError);
|
|
1759
2982
|
const glyph = state === "running" ? theme.fg("accent", runningGlyph(frame)) : state === "complete" ? theme.fg("success", "✓") : state === "paused" ? theme.fg("warning", "■") : theme.fg("error", "✗");
|
|
1760
2983
|
const width = getTermWidth() - 4;
|
|
@@ -1765,7 +2988,12 @@ function renderWorkflowChatProgress(d: Details, result: AgentToolResult<Details>
|
|
|
1765
2988
|
const rowIndent = mainWindowIndent(layout, 1);
|
|
1766
2989
|
c.addChild(new Text(truncLine(`${glyph} ${theme.fg("toolTitle", theme.bold("workflow"))} ${runId} ${theme.fg("dim", "·")} ${d.chatProgress?.repoRelation === "same" ? "same repo" : "other repo"} ${theme.fg("dim", "·")} ${state}`, width), 0, 0));
|
|
1767
2990
|
c.addChild(new Text(truncLine(theme.fg("dim", `${rowIndent}Repo ${repoLabel}`), width), 0, 0));
|
|
2991
|
+
if (d.preflight) c.addChild(new Text(truncLine(theme.fg("dim", formatWorkflowPreflightPlanSummary(d.preflight, { indent: rowIndent })), width), 0, 0));
|
|
1768
2992
|
if (phase) c.addChild(new Text(truncLine(theme.fg("dim", `${rowIndent}Phase ${phase}`), width), 0, 0));
|
|
2993
|
+
const checklist = projectWorkflowChecklist({ hostSteps: workflow?.receipt?.hostSteps, preflight: d.preflight, trace: workflow?.trace, now: Date.now() });
|
|
2994
|
+
for (const line of workflowChecklistWidgetLines(checklist, theme, rowIndent, false, frame, true, !expanded, expanded)) {
|
|
2995
|
+
c.addChild(new Text(truncLine(line, width), 0, 0));
|
|
2996
|
+
}
|
|
1769
2997
|
if (rows.length === 0) {
|
|
1770
2998
|
c.addChild(new Text(truncLine(theme.fg("dim", `${rowIndent}◦ waiting for workflow child launches`), width), 0, 0));
|
|
1771
2999
|
return c;
|
|
@@ -1778,7 +3006,20 @@ function renderWorkflowChatProgress(d: Details, result: AgentToolResult<Details>
|
|
|
1778
3006
|
const duration = row.durationMs !== undefined ? ` ${theme.fg("dim", `· ${formatDuration(row.durationMs)}`)}` : "";
|
|
1779
3007
|
const run = row.runId ? ` ${theme.fg("dim", `[${row.runId.slice(0, 8)}]`)}` : "";
|
|
1780
3008
|
const error = row.error ? ` ${theme.fg(row.state === "detached" ? "warning" : "error", `· ${compactWorkflowError(row.error)}`)}` : "";
|
|
1781
|
-
|
|
3009
|
+
const hints = expanded && row.preflight ? [
|
|
3010
|
+
row.preflight.mode ? `mode:${row.preflight.mode}` : undefined,
|
|
3011
|
+
row.preflight.decision ? `decision:${row.preflight.decision}` : undefined,
|
|
3012
|
+
row.preflight.claims?.length ? `claims:${row.preflight.claims.join(",")}` : undefined,
|
|
3013
|
+
row.preflight.expectedOutput ? `expected:${row.preflight.expectedOutput}` : undefined,
|
|
3014
|
+
row.preflight.independence ? `independence:${row.preflight.independence}` : undefined,
|
|
3015
|
+
].filter((value): value is string => Boolean(value)).join(" · ") : "";
|
|
3016
|
+
c.addChild(new Text(truncLine(`${rowIndent}${workflowRowGlyph(row, theme, frame)} ${status} ${theme.bold(row.key)}${label}${run}${duration}${error}${hints ? ` ${theme.fg("dim", `· ${hints}`)}` : ""}`, width), 0, 0));
|
|
3017
|
+
}
|
|
3018
|
+
if (workflow?.preflightWarnings?.length) {
|
|
3019
|
+
const warningLines = expanded
|
|
3020
|
+
? formatWorkflowPreflightWarnings(workflow.preflightWarnings, { indent: rowIndent }).split("\n")
|
|
3021
|
+
: [formatWorkflowPreflightWarningSummary(workflow.preflightWarnings, { indent: rowIndent, hint: "expand for debug" })];
|
|
3022
|
+
for (const warningLine of warningLines) c.addChild(new Text(truncLine(theme.fg("warning", warningLine), width), 0, 0));
|
|
1782
3023
|
}
|
|
1783
3024
|
if (workflow?.emits.length) c.addChild(new Text(truncLine(theme.fg("dim", `${rowIndent}Emits ${workflow.emits.length}`), width), 0, 0));
|
|
1784
3025
|
return c;
|
|
@@ -1794,6 +3035,7 @@ function renderMultiCompact(d: Details, theme: Theme, layout: MainWindowRenderLa
|
|
|
1794
3035
|
|| workflowGraphHasStatus(d, ["failed"]);
|
|
1795
3036
|
const paused = d.results.some((r) => r.interrupted)
|
|
1796
3037
|
|| workflowGraphHasStatus(d, ["paused"]);
|
|
3038
|
+
const partial = workflowGraphHasStatus(d, ["partial"]);
|
|
1797
3039
|
let totalSummary = d.progressSummary;
|
|
1798
3040
|
if (!totalSummary) {
|
|
1799
3041
|
let sawProgress = false;
|
|
@@ -1810,13 +3052,16 @@ function renderMultiCompact(d: Details, theme: Theme, layout: MainWindowRenderLa
|
|
|
1810
3052
|
}
|
|
1811
3053
|
const multiLabel = buildMultiProgressLabel(d, hasRunning);
|
|
1812
3054
|
const itemTitle = multiLabel.itemTitle;
|
|
1813
|
-
const
|
|
3055
|
+
const workflowChecklist = foregroundWorkflowChecklist(d);
|
|
3056
|
+
const checklistPrimary = d.mode === "workflow" && workflowChecklist !== undefined;
|
|
3057
|
+
const stats = statJoin(theme, [checklistPrimary ? formatWorkflowChecklistSummary(workflowChecklist) : multiLabel.headerLabel, formatProgressStats(theme, totalSummary), formatTotalCostStat(d.totalCost)]);
|
|
1814
3058
|
const aggregatePresentation = semanticResultPresentation({
|
|
1815
3059
|
running: hasRunning,
|
|
1816
3060
|
detached,
|
|
1817
3061
|
stopped,
|
|
1818
3062
|
interrupted: paused,
|
|
1819
3063
|
failed,
|
|
3064
|
+
partial,
|
|
1820
3065
|
seed: runningSeed(progressRunningSeed(totalSummary), d.currentStepIndex),
|
|
1821
3066
|
frame,
|
|
1822
3067
|
});
|
|
@@ -1826,25 +3071,29 @@ function renderMultiCompact(d: Details, theme: Theme, layout: MainWindowRenderLa
|
|
|
1826
3071
|
const width = getTermWidth() - 4;
|
|
1827
3072
|
const rowIndent = mainWindowIndent(layout, 1);
|
|
1828
3073
|
const detailIndent = mainWindowIndent(layout, 2);
|
|
1829
|
-
const continuationIndent = mainWindowIndent(layout, 3) + (layout.horizontalSpacing > 0 ? " " : "");
|
|
1830
3074
|
c.addChild(new Text(truncLine(`${glyph} ${theme.fg("toolTitle", theme.bold(d.mode))}${contextBadge}${stats ? ` ${theme.fg("dim", "·")} ${stats}` : ""}`, width), 0, 0));
|
|
3075
|
+
if (checklistPrimary) {
|
|
3076
|
+
for (const line of workflowChecklistWidgetLines(workflowChecklist, theme, rowIndent, false, frame, false)) {
|
|
3077
|
+
c.addChild(new Text(truncLine(line, width), 0, 0));
|
|
3078
|
+
}
|
|
3079
|
+
if (hasRunning || workflowChecklist.running > 0) c.addChild(new Text(truncLine(theme.fg("accent", `${rowIndent}${liveDetailHintText()}`), width), 0, 0));
|
|
3080
|
+
return c;
|
|
3081
|
+
}
|
|
3082
|
+
for (const line of workflowChecklistWidgetLines(workflowChecklist, theme, rowIndent, false, frame)) {
|
|
3083
|
+
c.addChild(new Text(truncLine(line, width), 0, 0));
|
|
3084
|
+
}
|
|
1831
3085
|
|
|
1832
3086
|
const useResultsDirectly = multiLabel.hasParallelInChain || !d.chainAgents?.length;
|
|
1833
3087
|
const displayStart = multiLabel.showActiveGroupOnly ? multiLabel.groupStartIndex : 0;
|
|
1834
3088
|
const displayEnd = multiLabel.showActiveGroupOnly ? multiLabel.groupEndIndex : (useResultsDirectly ? d.results.length : d.chainAgents!.length);
|
|
1835
3089
|
const chainEntries = buildChainRenderEntries(d, multiLabel);
|
|
1836
|
-
const renderEntries = chainEntries ??
|
|
1837
|
-
const i = displayStart + offset;
|
|
1838
|
-
const r = d.results[i];
|
|
1839
|
-
const fallbackLabel = itemTitle.toLowerCase();
|
|
1840
|
-
const rowNumber = multiLabel.showActiveGroupOnly ? (i - multiLabel.groupStartIndex + 1) : (i + 1);
|
|
1841
|
-
return { kind: "result", resultIndex: i, rowNumber, agentName: useResultsDirectly ? (r?.agent || `${fallbackLabel}-${rowNumber}`) : (d.chainAgents![i] || r?.agent || `${fallbackLabel}-${rowNumber}`) };
|
|
1842
|
-
});
|
|
3090
|
+
const renderEntries = chainEntries ?? buildForegroundResultEntries(d, multiLabel, displayStart, displayEnd, useResultsDirectly);
|
|
1843
3091
|
for (const entry of renderEntries) {
|
|
1844
|
-
if (entry.kind === "
|
|
3092
|
+
if (entry.kind === "group") {
|
|
1845
3093
|
const glyph = widgetStepGlyph(entry.status as AsyncJobStep["status"], theme);
|
|
1846
3094
|
const statusLabel = widgetStepStatus(entry.status as AsyncJobStep["status"], theme);
|
|
1847
|
-
|
|
3095
|
+
const groupLabel = entry.groupLabel ? ` (${compactTaskText(undefined, entry.groupLabel) ?? entry.groupLabel})` : "";
|
|
3096
|
+
c.addChild(new Text(truncLine(`${rowIndent}${glyph} ${entry.stepLabel}${groupLabel} ${theme.fg("dim", "·")} ${statusLabel}`, width), 0, 0));
|
|
1848
3097
|
if (entry.error) c.addChild(new Text(truncLine(theme.fg("error", `${detailIndent}⎿ Error: ${entry.error}`), width), 0, 0));
|
|
1849
3098
|
continue;
|
|
1850
3099
|
}
|
|
@@ -1853,24 +3102,29 @@ function renderMultiCompact(d: Details, theme: Theme, layout: MainWindowRenderLa
|
|
|
1853
3102
|
const rowNumber = entry.rowNumber;
|
|
1854
3103
|
const agentName = entry.agentName;
|
|
1855
3104
|
if (!r) {
|
|
1856
|
-
const pendingLabel = entry.rowLabel ?? `${itemTitle} ${rowNumber}
|
|
1857
|
-
|
|
3105
|
+
const pendingLabel = entry.rowLabel ?? (entry.isParallel ? "" : `${itemTitle} ${rowNumber}`);
|
|
3106
|
+
const labelPrefix = pendingLabel ? `${pendingLabel}: ` : "";
|
|
3107
|
+
c.addChild(new Text(truncLine(theme.fg("dim", `${rowIndent}◦ ${labelPrefix}${agentName} · pending`), width), 0, 0));
|
|
1858
3108
|
continue;
|
|
1859
3109
|
}
|
|
1860
3110
|
const output = getSingleResultOutput(r);
|
|
1861
|
-
const progressFromArray = d
|
|
3111
|
+
const progressFromArray = foregroundProgressForResult(d, i);
|
|
1862
3112
|
const rProg = r.progress || progressFromArray || r.progressSummary;
|
|
1863
3113
|
const rRunning = rProg && "status" in rProg && isResultRunning(r, rProg.status);
|
|
1864
3114
|
const rPending = rProg && "status" in rProg && rProg.status === "pending";
|
|
1865
|
-
const stepNumber = r.progress?.index !== undefined ? r.progress.index + 1 : progressFromArray?.index !== undefined ? progressFromArray.index + 1 : i + 1;
|
|
1866
3115
|
const stepStats = formatProgressStats(theme, rProg);
|
|
1867
3116
|
const glyph = rPending ? theme.fg("dim", "◦") : resultGlyph(r, output, theme, rRunning, progressRunningSeed(rProg), frame);
|
|
1868
3117
|
const pendingLabel = rPending ? ` ${theme.fg("dim", "· pending")}` : "";
|
|
1869
|
-
const stepLabel = entry.rowLabel
|
|
3118
|
+
const stepLabel = entry.rowLabel;
|
|
1870
3119
|
const rowProgressModel = rProg && "status" in rProg ? rProg : undefined;
|
|
1871
3120
|
const rowModelDisplay = modelThinkingBadge(theme, r.model ?? rowProgressModel?.model, r.thinking ?? rowProgressModel?.thinking);
|
|
1872
|
-
const
|
|
3121
|
+
const labelPrefix = stepLabel ? `${stepLabel}: ` : "";
|
|
3122
|
+
const line = `${glyph} ${labelPrefix}${themeBold(theme, agentName)}${contextModeBadge(theme, r.context)}${rowModelDisplay}${stepStats ? ` ${theme.fg("dim", "·")} ${stepStats}` : ""}${pendingLabel}`;
|
|
1873
3123
|
c.addChild(new Text(truncLine(`${rowIndent}${line}`, width), 0, 0));
|
|
3124
|
+
if (rRunning || rPending) {
|
|
3125
|
+
const task = compactTaskText(r.task, workflowLabelForResult(d, i));
|
|
3126
|
+
if (task) c.addChild(new Text(truncLine(theme.fg("dim", `${detailIndent}task: ${task}`), width), 0, 0));
|
|
3127
|
+
}
|
|
1874
3128
|
if (rRunning && rProg && "status" in rProg) {
|
|
1875
3129
|
const liveProgress = rProg as AgentProgress;
|
|
1876
3130
|
const activity = compactCurrentActivity(liveProgress);
|
|
@@ -1916,7 +3170,8 @@ export function renderSubagentSummary(
|
|
|
1916
3170
|
const failed = result.isError === true
|
|
1917
3171
|
|| results.some((entry) => !hasTerminalResultFlag(entry) && entry.exitCode !== 0 && !isResultRunning(entry))
|
|
1918
3172
|
|| Boolean(details && workflowGraphHasStatus(details, ["failed"]));
|
|
1919
|
-
const
|
|
3173
|
+
const partial = Boolean(details && workflowGraphHasStatus(details, ["partial"]));
|
|
3174
|
+
const state = running ? "running" : failed ? "failed" : stopped ? "stopped" : paused ? "paused" : partial ? "partial" : "completed";
|
|
1920
3175
|
const glyph = state === "running"
|
|
1921
3176
|
? theme.fg("accent", STATIC_RUNNING_GLYPH)
|
|
1922
3177
|
: state === "completed"
|
|
@@ -1925,7 +3180,7 @@ export function renderSubagentSummary(
|
|
|
1925
3180
|
? theme.fg("error", "✗")
|
|
1926
3181
|
: theme.fg("warning", "■");
|
|
1927
3182
|
const label = details?.mode === "single" && results.length === 1
|
|
1928
|
-
? results[0]
|
|
3183
|
+
? foregroundSingleDisplayName(results[0])
|
|
1929
3184
|
: details?.mode || "subagent";
|
|
1930
3185
|
return new Text(
|
|
1931
3186
|
truncLine(`${glyph} ${theme.fg("toolTitle", theme.bold(label))} ${theme.fg("dim", "·")} ${theme.fg(state === "failed" ? "error" : state === "completed" ? "success" : state === "running" ? "accent" : "warning", state)}`, getTermWidth() - 4),
|
|
@@ -1948,8 +3203,8 @@ export function renderSubagentResult(
|
|
|
1948
3203
|
const layout = resolveMainWindowRenderLayout(rendererConfig);
|
|
1949
3204
|
const compact = (component: Component): Component => capCompactMainWindowResult(component, layout, theme, !options.expanded);
|
|
1950
3205
|
const d = result.details;
|
|
1951
|
-
if (d?.mode === "workflow" && d.chatProgress?.mode === "live-card" && !result.isError
|
|
1952
|
-
return compact(renderWorkflowChatProgress(d, result, theme, options.expanded ? resolveMainWindowRenderLayout() : layout, frame));
|
|
3206
|
+
if (d?.mode === "workflow" && d.chatProgress?.mode === "live-card" && d.workflow?.value === undefined && (!result.isError || (d.workflow?.trace.length ?? 0) > 0)) {
|
|
3207
|
+
return compact(renderWorkflowChatProgress(d, result, theme, options.expanded ? resolveMainWindowRenderLayout() : layout, frame, options.expanded));
|
|
1953
3208
|
}
|
|
1954
3209
|
if (!d || !d.results.length) {
|
|
1955
3210
|
const t = result.content[0];
|
|
@@ -1960,9 +3215,12 @@ export function renderSubagentResult(
|
|
|
1960
3215
|
if (d && !options.expanded && !result.isError) {
|
|
1961
3216
|
const lines = text.split(/\r?\n/);
|
|
1962
3217
|
const firstNonEmptyLine = lines.find((line) => line.trim())?.trim() || "(no output)";
|
|
3218
|
+
const compactLine = d.mode === "workflow" && d.preflight
|
|
3219
|
+
? formatWorkflowPreflightPlanSummary(d.preflight)
|
|
3220
|
+
: firstNonEmptyLine;
|
|
1963
3221
|
const c = new Container();
|
|
1964
3222
|
const detailIndent = mainWindowIndent(layout, 1);
|
|
1965
|
-
c.addChild(new Text(truncLine(`${contextPrefix}${
|
|
3223
|
+
c.addChild(new Text(truncLine(`${contextPrefix}${compactLine} · ${lines.length} lines`, width), 0, 0));
|
|
1966
3224
|
c.addChild(new Text(truncLine(theme.fg("accent", `${detailIndent}Press ${liveDetailKeyText()} for full output`), width), 0, 0));
|
|
1967
3225
|
return compact(c);
|
|
1968
3226
|
}
|
|
@@ -1995,7 +3253,7 @@ export function renderSubagentResult(
|
|
|
1995
3253
|
const fit = (text: string) => expanded ? text : truncLine(text, w);
|
|
1996
3254
|
const toolCallLines = getToolCallLines(r, expanded);
|
|
1997
3255
|
const c = new Container();
|
|
1998
|
-
c.addChild(new Text(fit(`${presentation.glyph} ${theme.fg("toolTitle", theme.bold(r
|
|
3256
|
+
c.addChild(new Text(fit(`${presentation.glyph} ${theme.fg("toolTitle", theme.bold(foregroundSingleDisplayName(r)))}${contextBadge}${progressInfo} ${theme.fg("dim", "·")} ${presentation.label}`), 0, 0));
|
|
1999
3257
|
c.addChild(new Spacer(1));
|
|
2000
3258
|
const taskMaxLen = Math.max(20, w - 8);
|
|
2001
3259
|
const taskPreview = expanded || r.task.length <= taskMaxLen
|
|
@@ -2005,6 +3263,9 @@ export function renderSubagentResult(
|
|
|
2005
3263
|
new Text(fit(theme.fg("dim", `Task: ${taskPreview}`)), 0, 0),
|
|
2006
3264
|
);
|
|
2007
3265
|
c.addChild(new Spacer(1));
|
|
3266
|
+
if (!isRunning && (r.exitCode !== 0 || r.interrupted || r.detached || r.stopped)) {
|
|
3267
|
+
c.addChild(new Text(fit(theme.fg(r.exitCode !== 0 ? "error" : "dim", ` ⎿ ${resultStatusLine(r, output)}`)), 0, 0));
|
|
3268
|
+
}
|
|
2008
3269
|
|
|
2009
3270
|
if (isRunning && r.progress) {
|
|
2010
3271
|
const progressSnapshotNow = snapshotNowForProgress(r.progress);
|
|
@@ -2083,6 +3344,7 @@ export function renderSubagentResult(
|
|
|
2083
3344
|
|| workflowGraphHasStatus(d, ["failed"]);
|
|
2084
3345
|
const paused = d.results.some((r) => r.interrupted)
|
|
2085
3346
|
|| workflowGraphHasStatus(d, ["paused"]);
|
|
3347
|
+
const partial = workflowGraphHasStatus(d, ["partial"]);
|
|
2086
3348
|
const completedWithoutOutput = d.results.some((r) =>
|
|
2087
3349
|
!hasTerminalResultFlag(r)
|
|
2088
3350
|
&& r.exitCode === 0
|
|
@@ -2095,6 +3357,7 @@ export function renderSubagentResult(
|
|
|
2095
3357
|
stopped,
|
|
2096
3358
|
interrupted: paused,
|
|
2097
3359
|
failed,
|
|
3360
|
+
partial,
|
|
2098
3361
|
completedWithoutOutput,
|
|
2099
3362
|
frame,
|
|
2100
3363
|
}), theme);
|
|
@@ -2134,6 +3397,7 @@ export function renderSubagentResult(
|
|
|
2134
3397
|
? d.chainAgents
|
|
2135
3398
|
.map((agent, i) => {
|
|
2136
3399
|
const result = d.results[i];
|
|
3400
|
+
const displayName = foregroundResultDisplayName(d, i, result, agent);
|
|
2137
3401
|
const isCurrent = i === (d.currentStepIndex ?? d.results.length);
|
|
2138
3402
|
const stepPresentation = result
|
|
2139
3403
|
? styledResultPresentation(resultPresentation(result, getSingleResultOutput(result), isCurrent && hasRunning && !hasTerminalResultFlag(result)), theme)
|
|
@@ -2141,7 +3405,7 @@ export function renderSubagentResult(
|
|
|
2141
3405
|
const stepStatus = stepPresentation
|
|
2142
3406
|
? `${stepPresentation.glyph} ${stepPresentation.label}`
|
|
2143
3407
|
: theme.fg("dim", "◦ pending");
|
|
2144
|
-
return `${stepStatus} ${
|
|
3408
|
+
return `${stepStatus} ${displayName}${contextModeBadge(theme, result?.context)}`;
|
|
2145
3409
|
})
|
|
2146
3410
|
.join(theme.fg("dim", " → "))
|
|
2147
3411
|
: null;
|
|
@@ -2159,24 +3423,24 @@ export function renderSubagentResult(
|
|
|
2159
3423
|
if (chainVis) {
|
|
2160
3424
|
c.addChild(new Text(fit(` ${chainVis}`), 0, 0));
|
|
2161
3425
|
}
|
|
3426
|
+
const workflowChecklist = foregroundWorkflowChecklist(d);
|
|
3427
|
+
for (const line of workflowChecklistWidgetLines(workflowChecklist, theme, " ", true, frame)) {
|
|
3428
|
+
c.addChild(new Text(fit(line), 0, 0));
|
|
3429
|
+
}
|
|
2162
3430
|
|
|
2163
3431
|
const useResultsDirectly = multiLabel.hasParallelInChain || !d.chainAgents?.length;
|
|
2164
3432
|
const displayStart = multiLabel.showActiveGroupOnly ? multiLabel.groupStartIndex : 0;
|
|
2165
3433
|
const displayEnd = multiLabel.showActiveGroupOnly ? multiLabel.groupEndIndex : (useResultsDirectly ? d.results.length : d.chainAgents!.length);
|
|
2166
3434
|
const chainEntries = buildChainRenderEntries(d, multiLabel);
|
|
2167
|
-
const renderEntries = chainEntries ??
|
|
2168
|
-
const i = displayStart + offset;
|
|
2169
|
-
const r = d.results[i];
|
|
2170
|
-
const rowNumber = multiLabel.showActiveGroupOnly ? (i - multiLabel.groupStartIndex + 1) : (i + 1);
|
|
2171
|
-
return { kind: "result", resultIndex: i, rowNumber, agentName: useResultsDirectly ? (r?.agent || `step-${rowNumber}`) : (d.chainAgents![i] || r?.agent || `step-${rowNumber}`) };
|
|
2172
|
-
});
|
|
3435
|
+
const renderEntries = chainEntries ?? buildForegroundResultEntries(d, multiLabel, displayStart, displayEnd, useResultsDirectly);
|
|
2173
3436
|
|
|
2174
3437
|
c.addChild(new Spacer(1));
|
|
2175
3438
|
|
|
2176
3439
|
for (const entry of renderEntries) {
|
|
2177
|
-
if (entry.kind === "
|
|
3440
|
+
if (entry.kind === "group") {
|
|
2178
3441
|
const statusLabel = widgetStepStatus(entry.status as AsyncJobStep["status"], theme);
|
|
2179
|
-
|
|
3442
|
+
const groupLabel = entry.groupLabel ? ` (${compactTaskText(undefined, entry.groupLabel) ?? entry.groupLabel})` : "";
|
|
3443
|
+
c.addChild(new Text(fit(` ${statusLabel} ${entry.stepLabel}${groupLabel}`), 0, 0));
|
|
2180
3444
|
c.addChild(new Text(theme.fg(entry.status === "failed" ? "error" : "dim", ` status: ${entry.status}`), 0, 0));
|
|
2181
3445
|
if (entry.error) c.addChild(new Text(theme.fg("error", ` error: ${entry.error}`), 0, 0));
|
|
2182
3446
|
c.addChild(new Spacer(1));
|
|
@@ -2188,28 +3452,28 @@ export function renderSubagentResult(
|
|
|
2188
3452
|
const agentName = entry.agentName;
|
|
2189
3453
|
|
|
2190
3454
|
if (!r) {
|
|
2191
|
-
const pendingLabel = entry.rowLabel ?? `${itemTitle} ${rowNumber}
|
|
2192
|
-
|
|
3455
|
+
const pendingLabel = entry.rowLabel ?? (entry.isParallel ? "" : `${itemTitle} ${rowNumber}`);
|
|
3456
|
+
const labelPrefix = pendingLabel ? `${pendingLabel}: ` : "";
|
|
3457
|
+
c.addChild(new Text(fit(theme.fg("dim", ` ${labelPrefix}${agentName}`)), 0, 0));
|
|
2193
3458
|
c.addChild(new Text(theme.fg("dim", ` status: pending`), 0, 0));
|
|
2194
3459
|
c.addChild(new Spacer(1));
|
|
2195
3460
|
continue;
|
|
2196
3461
|
}
|
|
2197
3462
|
|
|
2198
|
-
const progressFromArray = d
|
|
2199
|
-
|| d.progress?.find((p) => p.agent === r.agent && p.status === "running");
|
|
3463
|
+
const progressFromArray = foregroundProgressForResult(d, i);
|
|
2200
3464
|
const rProg = r.progress || progressFromArray || r.progressSummary;
|
|
2201
3465
|
const rRunning = isResultRunning(r, rProg?.status);
|
|
2202
|
-
const stepNumber = typeof rProg?.index === "number" ? rProg.index + 1 : i + 1;
|
|
2203
3466
|
|
|
2204
3467
|
const resultOutput = getSingleResultOutput(r);
|
|
2205
3468
|
const rowPresentation = styledResultPresentation(resultPresentation(r, resultOutput, rRunning, progressRunningSeed(rProg), frame), theme);
|
|
2206
3469
|
const stats = rProg ? ` | ${rProg.toolCount} tools, ${formatDuration(rProg.durationMs)}` : "";
|
|
2207
3470
|
const modelDisplay = modelThinkingBadge(theme, r.model ?? rProg?.model, r.thinking ?? rProg?.thinking);
|
|
2208
|
-
const stepLabel = entry.rowLabel
|
|
3471
|
+
const stepLabel = entry.rowLabel;
|
|
2209
3472
|
const contextBadge = contextModeBadge(theme, r.context);
|
|
3473
|
+
const labelPrefix = stepLabel ? `${stepLabel}: ` : "";
|
|
2210
3474
|
const stepHeader = rRunning
|
|
2211
|
-
? `${rowPresentation.glyph} ${
|
|
2212
|
-
: `${rowPresentation.glyph} ${
|
|
3475
|
+
? `${rowPresentation.glyph} ${labelPrefix}${theme.bold(theme.fg("warning", agentName))}${contextBadge}${modelDisplay}${stats} ${theme.fg("dim", "·")} ${rowPresentation.label}`
|
|
3476
|
+
: `${rowPresentation.glyph} ${labelPrefix}${theme.bold(agentName)}${contextBadge}${modelDisplay}${stats} ${theme.fg("dim", "·")} ${rowPresentation.label}`;
|
|
2213
3477
|
const toolCallLines = getToolCallLines(r, expanded);
|
|
2214
3478
|
c.addChild(new Text(fit(stepHeader), 0, 0));
|
|
2215
3479
|
|
|
@@ -2223,6 +3487,9 @@ export function renderSubagentResult(
|
|
|
2223
3487
|
if (outputTarget) {
|
|
2224
3488
|
c.addChild(new Text(fit(theme.fg("dim", ` output: ${outputTarget}`)), 0, 0));
|
|
2225
3489
|
}
|
|
3490
|
+
if (!rRunning && (r.exitCode !== 0 || r.interrupted || r.detached || r.stopped)) {
|
|
3491
|
+
c.addChild(new Text(fit(theme.fg(r.exitCode !== 0 ? "error" : "dim", ` ⎿ ${resultStatusLine(r, resultOutput)}`)), 0, 0));
|
|
3492
|
+
}
|
|
2226
3493
|
|
|
2227
3494
|
if (r.skills?.length) {
|
|
2228
3495
|
c.addChild(new Text(fit(theme.fg("dim", ` skills: ${r.skills.join(", ")}`)), 0, 0));
|