@duckmind/dm-darwin-x64 0.43.4 → 0.48.5
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/dm +0 -0
- package/extensions/.dm-extensions.json +242 -50
- package/extensions/dm-9router-ext/package.json +2 -19
- package/extensions/dm-9router-ext/src/index.js +5 -0
- package/extensions/dm-ask-user/index.js +10 -0
- package/extensions/dm-ask-user/package.json +1 -21
- package/extensions/dm-cli-anything/package.json +0 -6
- package/extensions/dm-context/package.json +2 -12
- package/extensions/dm-context/src/context.js +1 -0
- package/extensions/dm-context/src/index.js +7 -0
- package/extensions/dm-context/src/utils.js +1 -0
- package/extensions/dm-cua/package.json +0 -7
- package/extensions/dm-fff/package.json +1 -28
- package/extensions/dm-fff/src/index.js +15 -0
- package/extensions/dm-fff/src/query.js +1 -0
- package/extensions/dm-goal/package.json +2 -31
- package/extensions/dm-goal/src/goal.js +43 -0
- package/extensions/dm-grill-me/index.js +174 -0
- package/extensions/dm-grill-me/package.json +1 -26
- package/extensions/dm-image2/package.json +0 -7
- package/extensions/dm-subagents/package.json +1 -32
- package/extensions/dm-subagents/src/agents/agent-management.js +37 -0
- package/extensions/dm-subagents/src/agents/agent-memory.js +6 -0
- package/extensions/dm-subagents/src/agents/agent-scope.js +1 -0
- package/extensions/dm-subagents/src/agents/agent-selection.js +1 -0
- package/extensions/dm-subagents/src/agents/agent-serializer.js +7 -0
- package/extensions/dm-subagents/src/agents/agents.js +11 -0
- package/extensions/dm-subagents/src/agents/chain-serializer.js +12 -0
- package/extensions/dm-subagents/src/agents/frontmatter.js +6 -0
- package/extensions/dm-subagents/src/agents/identity.js +1 -0
- package/extensions/dm-subagents/src/agents/proactive-skills.js +1 -0
- package/extensions/dm-subagents/src/agents/skills.js +6 -0
- package/extensions/dm-subagents/src/extension/config.js +2 -0
- package/extensions/dm-subagents/src/extension/control-notices.js +4 -0
- package/extensions/dm-subagents/src/extension/doctor.js +16 -0
- package/extensions/dm-subagents/src/extension/fanout-child.js +231 -0
- package/extensions/dm-subagents/src/extension/index.js +367 -0
- package/extensions/dm-subagents/src/extension/rpc.js +8 -0
- package/extensions/dm-subagents/src/extension/schemas.js +1 -0
- package/extensions/dm-subagents/src/extension/{tool-description.ts → tool-description.js} +6 -126
- package/extensions/dm-subagents/src/intercom/intercom-bridge.js +13 -0
- package/extensions/dm-subagents/src/intercom/native-supervisor-channel.js +5 -0
- package/extensions/dm-subagents/src/intercom/result-intercom.js +3 -0
- package/extensions/dm-subagents/src/profiles/profiles.js +3 -0
- package/extensions/dm-subagents/src/runs/background/async-execution.js +46 -0
- package/extensions/dm-subagents/src/runs/background/async-job-tracker.js +14 -0
- package/extensions/dm-subagents/src/runs/background/async-resume.js +8 -0
- package/extensions/dm-subagents/src/runs/background/async-status.js +12 -0
- package/extensions/dm-subagents/src/runs/background/chain-append.js +2 -0
- package/extensions/dm-subagents/src/runs/background/chain-root-attachment.js +1 -0
- package/extensions/dm-subagents/src/runs/background/completion-batcher.js +1 -0
- package/extensions/dm-subagents/src/runs/background/completion-dedupe.js +1 -0
- package/extensions/dm-subagents/src/runs/background/control-channel.js +1 -0
- package/extensions/dm-subagents/src/runs/background/fleet-view.js +17 -0
- package/extensions/dm-subagents/src/runs/background/notify.js +3 -0
- package/extensions/dm-subagents/src/runs/background/parallel-groups.js +1 -0
- package/extensions/dm-subagents/src/runs/background/result-watcher.js +8 -0
- package/extensions/dm-subagents/src/runs/background/run-id-resolver.js +4 -0
- package/extensions/dm-subagents/src/runs/background/run-status.js +23 -0
- package/extensions/dm-subagents/src/runs/background/scheduled-runs.js +4 -0
- package/extensions/dm-subagents/src/runs/background/stale-run-reconciler.js +11 -0
- package/extensions/dm-subagents/src/runs/background/subagent-runner.js +78 -0
- package/extensions/dm-subagents/src/runs/background/top-level-async.js +1 -0
- package/extensions/dm-subagents/src/runs/background/wait.js +11 -0
- package/extensions/dm-subagents/src/runs/foreground/chain-clarify.js +12 -0
- package/extensions/dm-subagents/src/runs/foreground/chain-execution.js +102 -0
- package/extensions/dm-subagents/src/runs/foreground/execution.js +51 -0
- package/extensions/dm-subagents/src/runs/foreground/subagent-executor.js +228 -0
- package/extensions/dm-subagents/src/runs/shared/acceptance.js +3 -0
- package/extensions/dm-subagents/src/runs/shared/chain-outputs.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/completion-guard.js +3 -0
- package/extensions/dm-subagents/src/runs/shared/dm-args.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/dm-spawn.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/dynamic-fanout.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/long-running-guard.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/mcp-direct-tool-allowlist.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/model-fallback.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/model-scope.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/nested-events.js +8 -0
- package/extensions/dm-subagents/src/runs/shared/nested-path.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/nested-render.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/parallel-utils.js +5 -0
- package/extensions/dm-subagents/src/runs/shared/run-history.js +5 -0
- package/extensions/dm-subagents/src/runs/shared/single-output.js +14 -0
- package/extensions/dm-subagents/src/runs/shared/structured-output.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/subagent-control.js +5 -0
- package/extensions/dm-subagents/src/runs/shared/subagent-prompt-runtime.js +22 -0
- package/extensions/dm-subagents/src/runs/shared/tool-budget.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/turn-budget.js +7 -0
- package/extensions/dm-subagents/src/runs/shared/workflow-graph.js +1 -0
- package/extensions/dm-subagents/src/runs/shared/worktree.js +3 -0
- package/extensions/dm-subagents/src/shared/artifacts.js +2 -0
- package/extensions/dm-subagents/src/shared/atomic-json.js +1 -0
- package/extensions/dm-subagents/src/shared/child-transcript.js +5 -0
- package/extensions/dm-subagents/src/shared/file-coalescer.js +1 -0
- package/extensions/dm-subagents/src/shared/fork-context.js +6 -0
- package/extensions/dm-subagents/src/shared/formatters.js +9 -0
- package/extensions/dm-subagents/src/shared/jsonl-writer.js +2 -0
- package/extensions/dm-subagents/src/shared/model-info.js +1 -0
- package/extensions/dm-subagents/src/shared/post-exit-stdio-guard.js +1 -0
- package/extensions/dm-subagents/src/shared/session-identity.js +1 -0
- package/extensions/dm-subagents/src/shared/session-tokens.js +2 -0
- package/extensions/dm-subagents/src/shared/settings.js +23 -0
- package/extensions/dm-subagents/src/shared/status-format.js +1 -0
- package/extensions/dm-subagents/src/shared/types.js +8 -0
- package/extensions/dm-subagents/src/shared/utils.js +2 -0
- package/extensions/dm-subagents/src/slash/prompt-template-bridge.js +1 -0
- package/extensions/dm-subagents/src/slash/prompt-workflows.js +7 -0
- package/extensions/dm-subagents/src/slash/slash-bridge.js +1 -0
- package/extensions/dm-subagents/src/slash/slash-commands.js +38 -0
- package/extensions/dm-subagents/src/slash/slash-live-state.js +6 -0
- package/extensions/dm-subagents/src/tui/render-helpers.js +1 -0
- package/extensions/dm-subagents/src/tui/render.js +4 -0
- package/extensions/dm-tasks/package.json +1 -30
- package/extensions/dm-tasks/src/auto-clear.js +1 -0
- package/extensions/dm-tasks/src/index.js +212 -0
- package/extensions/dm-tasks/src/process-tracker.js +1 -0
- package/extensions/dm-tasks/src/task-store.js +1 -0
- package/extensions/dm-tasks/src/tasks-config.js +1 -0
- package/extensions/dm-tasks/src/types.js +0 -0
- package/extensions/dm-tasks/src/ui/settings-menu.js +1 -0
- package/extensions/dm-tasks/src/ui/task-widget.js +1 -0
- package/extensions/dm-usage/index.js +9 -0
- package/extensions/dm-usage/package.json +1 -18
- package/extensions/greedysearch-dm/bin/search.mjs +51 -51
- package/extensions/greedysearch-dm/index.js +20 -0
- package/extensions/greedysearch-dm/package.json +1 -22
- package/extensions/greedysearch-dm/src/formatters/results.js +8 -0
- package/extensions/greedysearch-dm/src/formatters/sources.js +1 -0
- package/extensions/greedysearch-dm/src/formatters/synthesis.js +1 -0
- package/extensions/greedysearch-dm/src/search/research.mjs +59 -59
- package/extensions/greedysearch-dm/src/search/synthesis-runner.mjs +10 -10
- package/extensions/greedysearch-dm/src/tools/greedy-search-handler.js +20 -0
- package/extensions/greedysearch-dm/src/tools/shared.js +9 -0
- package/extensions/greedysearch-dm/src/types.js +0 -0
- package/extensions/greedysearch-dm/src/utils/helpers.js +1 -0
- package/package.json +1 -1
- package/extensions/dm-9router-ext/src/index.ts +0 -541
- package/extensions/dm-ask-user/index.ts +0 -857
- package/extensions/dm-context/src/context.ts +0 -158
- package/extensions/dm-context/src/index.ts +0 -439
- package/extensions/dm-context/src/utils.ts +0 -6
- package/extensions/dm-fff/src/index.ts +0 -1023
- package/extensions/dm-fff/src/query.ts +0 -87
- package/extensions/dm-goal/src/goal.ts +0 -1073
- package/extensions/dm-grill-me/index.ts +0 -1085
- package/extensions/dm-subagents/src/agents/agent-management.ts +0 -1052
- package/extensions/dm-subagents/src/agents/agent-memory.ts +0 -254
- package/extensions/dm-subagents/src/agents/agent-scope.ts +0 -6
- package/extensions/dm-subagents/src/agents/agent-selection.ts +0 -25
- package/extensions/dm-subagents/src/agents/agent-serializer.ts +0 -121
- package/extensions/dm-subagents/src/agents/agents.ts +0 -1553
- package/extensions/dm-subagents/src/agents/chain-serializer.ts +0 -277
- package/extensions/dm-subagents/src/agents/frontmatter.ts +0 -93
- package/extensions/dm-subagents/src/agents/identity.ts +0 -30
- package/extensions/dm-subagents/src/agents/proactive-skills.ts +0 -191
- package/extensions/dm-subagents/src/agents/skills.ts +0 -729
- package/extensions/dm-subagents/src/extension/config.ts +0 -39
- package/extensions/dm-subagents/src/extension/control-notices.ts +0 -92
- package/extensions/dm-subagents/src/extension/doctor.ts +0 -214
- package/extensions/dm-subagents/src/extension/fanout-child.ts +0 -172
- package/extensions/dm-subagents/src/extension/index.ts +0 -656
- package/extensions/dm-subagents/src/extension/rpc.ts +0 -369
- package/extensions/dm-subagents/src/extension/schemas.ts +0 -309
- package/extensions/dm-subagents/src/intercom/intercom-bridge.ts +0 -180
- package/extensions/dm-subagents/src/intercom/native-supervisor-channel.ts +0 -519
- package/extensions/dm-subagents/src/intercom/result-intercom.ts +0 -377
- package/extensions/dm-subagents/src/profiles/profiles.ts +0 -637
- package/extensions/dm-subagents/src/runs/background/async-execution.ts +0 -1065
- package/extensions/dm-subagents/src/runs/background/async-job-tracker.ts +0 -441
- package/extensions/dm-subagents/src/runs/background/async-resume.ts +0 -391
- package/extensions/dm-subagents/src/runs/background/async-status.ts +0 -395
- package/extensions/dm-subagents/src/runs/background/chain-append.ts +0 -282
- package/extensions/dm-subagents/src/runs/background/chain-root-attachment.ts +0 -191
- package/extensions/dm-subagents/src/runs/background/completion-batcher.ts +0 -166
- package/extensions/dm-subagents/src/runs/background/completion-dedupe.ts +0 -63
- package/extensions/dm-subagents/src/runs/background/control-channel.ts +0 -332
- package/extensions/dm-subagents/src/runs/background/fleet-view.ts +0 -515
- package/extensions/dm-subagents/src/runs/background/notify.ts +0 -225
- package/extensions/dm-subagents/src/runs/background/parallel-groups.ts +0 -45
- package/extensions/dm-subagents/src/runs/background/result-watcher.ts +0 -315
- package/extensions/dm-subagents/src/runs/background/run-id-resolver.ts +0 -84
- package/extensions/dm-subagents/src/runs/background/run-status.ts +0 -434
- package/extensions/dm-subagents/src/runs/background/scheduled-runs.ts +0 -514
- package/extensions/dm-subagents/src/runs/background/stale-run-reconciler.ts +0 -368
- package/extensions/dm-subagents/src/runs/background/subagent-runner.ts +0 -3171
- package/extensions/dm-subagents/src/runs/background/top-level-async.ts +0 -13
- package/extensions/dm-subagents/src/runs/background/wait.ts +0 -353
- package/extensions/dm-subagents/src/runs/foreground/chain-clarify.ts +0 -1333
- package/extensions/dm-subagents/src/runs/foreground/chain-execution.ts +0 -1313
- package/extensions/dm-subagents/src/runs/foreground/execution.ts +0 -1239
- package/extensions/dm-subagents/src/runs/foreground/subagent-executor.ts +0 -3613
- package/extensions/dm-subagents/src/runs/shared/acceptance.ts +0 -879
- package/extensions/dm-subagents/src/runs/shared/chain-outputs.ts +0 -116
- package/extensions/dm-subagents/src/runs/shared/completion-guard.ts +0 -147
- package/extensions/dm-subagents/src/runs/shared/dm-args.ts +0 -271
- package/extensions/dm-subagents/src/runs/shared/dm-spawn.ts +0 -147
- package/extensions/dm-subagents/src/runs/shared/dynamic-fanout.ts +0 -295
- package/extensions/dm-subagents/src/runs/shared/long-running-guard.ts +0 -175
- package/extensions/dm-subagents/src/runs/shared/mcp-direct-tool-allowlist.ts +0 -365
- package/extensions/dm-subagents/src/runs/shared/model-fallback.ts +0 -292
- package/extensions/dm-subagents/src/runs/shared/model-scope.ts +0 -128
- package/extensions/dm-subagents/src/runs/shared/nested-events.ts +0 -908
- package/extensions/dm-subagents/src/runs/shared/nested-path.ts +0 -52
- package/extensions/dm-subagents/src/runs/shared/nested-render.ts +0 -115
- package/extensions/dm-subagents/src/runs/shared/parallel-utils.ts +0 -198
- package/extensions/dm-subagents/src/runs/shared/run-history.ts +0 -60
- package/extensions/dm-subagents/src/runs/shared/single-output.ts +0 -180
- package/extensions/dm-subagents/src/runs/shared/structured-output.ts +0 -77
- package/extensions/dm-subagents/src/runs/shared/subagent-control.ts +0 -223
- package/extensions/dm-subagents/src/runs/shared/subagent-prompt-runtime.ts +0 -342
- package/extensions/dm-subagents/src/runs/shared/tool-budget.ts +0 -74
- package/extensions/dm-subagents/src/runs/shared/turn-budget.ts +0 -52
- package/extensions/dm-subagents/src/runs/shared/workflow-graph.ts +0 -206
- package/extensions/dm-subagents/src/runs/shared/worktree.ts +0 -600
- package/extensions/dm-subagents/src/shared/artifacts.ts +0 -113
- package/extensions/dm-subagents/src/shared/atomic-json.ts +0 -86
- package/extensions/dm-subagents/src/shared/child-transcript.ts +0 -212
- package/extensions/dm-subagents/src/shared/file-coalescer.ts +0 -40
- package/extensions/dm-subagents/src/shared/fork-context.ts +0 -194
- package/extensions/dm-subagents/src/shared/formatters.ts +0 -133
- package/extensions/dm-subagents/src/shared/jsonl-writer.ts +0 -81
- package/extensions/dm-subagents/src/shared/model-info.ts +0 -78
- package/extensions/dm-subagents/src/shared/post-exit-stdio-guard.ts +0 -85
- package/extensions/dm-subagents/src/shared/session-identity.ts +0 -10
- package/extensions/dm-subagents/src/shared/session-tokens.ts +0 -44
- package/extensions/dm-subagents/src/shared/settings.ts +0 -450
- package/extensions/dm-subagents/src/shared/status-format.ts +0 -49
- package/extensions/dm-subagents/src/shared/types.ts +0 -1257
- package/extensions/dm-subagents/src/shared/utils.ts +0 -554
- package/extensions/dm-subagents/src/slash/prompt-template-bridge.ts +0 -420
- package/extensions/dm-subagents/src/slash/prompt-workflows.ts +0 -330
- package/extensions/dm-subagents/src/slash/slash-bridge.ts +0 -176
- package/extensions/dm-subagents/src/slash/slash-commands.ts +0 -1296
- package/extensions/dm-subagents/src/slash/slash-live-state.ts +0 -292
- package/extensions/dm-subagents/src/tui/render-helpers.ts +0 -80
- package/extensions/dm-subagents/src/tui/render.ts +0 -1748
- package/extensions/dm-tasks/src/auto-clear.ts +0 -91
- package/extensions/dm-tasks/src/index.ts +0 -1145
- package/extensions/dm-tasks/src/process-tracker.ts +0 -140
- package/extensions/dm-tasks/src/task-store.ts +0 -305
- package/extensions/dm-tasks/src/tasks-config.ts +0 -23
- package/extensions/dm-tasks/src/types.ts +0 -40
- package/extensions/dm-tasks/src/ui/settings-menu.ts +0 -100
- package/extensions/dm-tasks/src/ui/task-widget.ts +0 -265
- package/extensions/dm-usage/index.ts +0 -1718
- package/extensions/greedysearch-dm/index.ts +0 -177
- package/extensions/greedysearch-dm/src/formatters/results.ts +0 -163
- package/extensions/greedysearch-dm/src/formatters/sources.ts +0 -116
- package/extensions/greedysearch-dm/src/formatters/synthesis.ts +0 -87
- package/extensions/greedysearch-dm/src/tools/greedy-search-handler.ts +0 -370
- package/extensions/greedysearch-dm/src/tools/shared.ts +0 -187
- package/extensions/greedysearch-dm/src/types.ts +0 -110
- package/extensions/greedysearch-dm/src/utils/helpers.ts +0 -40
|
@@ -1,1748 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Rendering functions for subagent results
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import * as path from "node:path";
|
|
6
|
-
import type { AgentToolResult } from "@duckmind/dm-agent-core";
|
|
7
|
-
import { getMarkdownTheme, keyText, type ExtensionContext } from "@duckmind/dm-coding-agent";
|
|
8
|
-
import { Container, Markdown, Spacer, Text, visibleWidth, type Component } from "@duckmind/dm-tui";
|
|
9
|
-
import {
|
|
10
|
-
type AgentProgress,
|
|
11
|
-
type AsyncJobState,
|
|
12
|
-
type AsyncJobStep,
|
|
13
|
-
type AsyncParallelGroupStatus,
|
|
14
|
-
type Details,
|
|
15
|
-
type NestedRunSummary,
|
|
16
|
-
type NestedStepSummary,
|
|
17
|
-
type WorkflowNodeStatus,
|
|
18
|
-
MAX_WIDGET_JOBS,
|
|
19
|
-
WIDGET_KEY,
|
|
20
|
-
} from "../shared/types.ts";
|
|
21
|
-
import { formatTokens, formatUsage, formatDuration, formatModelThinking, formatToolCall, shortenPath } from "../shared/formatters.ts";
|
|
22
|
-
import { getDisplayItems, getSingleResultOutput } from "../shared/utils.ts";
|
|
23
|
-
import { flatToLogicalStepIndex } from "../runs/background/parallel-groups.ts";
|
|
24
|
-
import { formatNestedAggregate } from "../runs/shared/nested-render.ts";
|
|
25
|
-
import { aggregateStepStatus, formatActivityLabel, formatAgentRunningLabel, formatParallelOutcome } from "../shared/status-format.ts";
|
|
26
|
-
|
|
27
|
-
type Theme = ExtensionContext["ui"]["theme"];
|
|
28
|
-
|
|
29
|
-
function liveDetailKeyText(): string {
|
|
30
|
-
return keyText("app.tools.expand");
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function liveDetailHintText(): string {
|
|
34
|
-
return `Press ${liveDetailKeyText()} for live detail`;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function getTermWidth(): number {
|
|
38
|
-
return process.stdout.columns || 120;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const segmenter = new Intl.Segmenter(undefined, { granularity: "grapheme" });
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Truncate a line to maxWidth, preserving ANSI styling through the ellipsis.
|
|
45
|
-
*
|
|
46
|
-
* pi-tui's truncateToWidth adds \x1b[0m before ellipsis which resets all styling,
|
|
47
|
-
* causing background color bleed in the TUI. This implementation tracks active
|
|
48
|
-
* ANSI styles and re-applies them before the ellipsis.
|
|
49
|
-
*
|
|
50
|
-
* Uses Intl.Segmenter for proper Unicode/emoji handling (not char-by-char).
|
|
51
|
-
*/
|
|
52
|
-
function truncLine(text: string, maxWidth: number): string {
|
|
53
|
-
if (visibleWidth(text) <= maxWidth) return text;
|
|
54
|
-
|
|
55
|
-
const targetWidth = maxWidth - 1;
|
|
56
|
-
let result = "";
|
|
57
|
-
let currentWidth = 0;
|
|
58
|
-
let activeStyles: string[] = [];
|
|
59
|
-
let i = 0;
|
|
60
|
-
|
|
61
|
-
while (i < text.length) {
|
|
62
|
-
const ansiMatch = text.slice(i).match(/^\x1b\[[0-9;]*m/);
|
|
63
|
-
if (ansiMatch) {
|
|
64
|
-
const code = ansiMatch[0];
|
|
65
|
-
result += code;
|
|
66
|
-
|
|
67
|
-
if (code === "\x1b[0m" || code === "\x1b[m") {
|
|
68
|
-
activeStyles = [];
|
|
69
|
-
} else {
|
|
70
|
-
activeStyles.push(code);
|
|
71
|
-
}
|
|
72
|
-
i += code.length;
|
|
73
|
-
continue;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
let end = i;
|
|
77
|
-
while (end < text.length && !text.slice(end).match(/^\x1b\[[0-9;]*m/)) {
|
|
78
|
-
end++;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const textPortion = text.slice(i, end);
|
|
82
|
-
for (const seg of segmenter.segment(textPortion)) {
|
|
83
|
-
const grapheme = seg.segment;
|
|
84
|
-
const graphemeWidth = visibleWidth(grapheme);
|
|
85
|
-
|
|
86
|
-
if (currentWidth + graphemeWidth > targetWidth) {
|
|
87
|
-
return result + activeStyles.join("") + "…";
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
result += grapheme;
|
|
91
|
-
currentWidth += graphemeWidth;
|
|
92
|
-
}
|
|
93
|
-
i = end;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
return result + activeStyles.join("") + "…";
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function wrapPlainText(text: string, maxWidth: number): string[] {
|
|
100
|
-
if (maxWidth <= 0) return [""];
|
|
101
|
-
const lines: string[] = [];
|
|
102
|
-
for (const rawLine of text.split("\n")) {
|
|
103
|
-
if (rawLine.length === 0) {
|
|
104
|
-
lines.push("");
|
|
105
|
-
continue;
|
|
106
|
-
}
|
|
107
|
-
let current = "";
|
|
108
|
-
let currentWidth = 0;
|
|
109
|
-
for (const seg of segmenter.segment(rawLine)) {
|
|
110
|
-
const grapheme = seg.segment;
|
|
111
|
-
const graphemeWidth = visibleWidth(grapheme);
|
|
112
|
-
if (currentWidth > 0 && currentWidth + graphemeWidth > maxWidth) {
|
|
113
|
-
lines.push(current);
|
|
114
|
-
current = grapheme;
|
|
115
|
-
currentWidth = graphemeWidth;
|
|
116
|
-
continue;
|
|
117
|
-
}
|
|
118
|
-
current += grapheme;
|
|
119
|
-
currentWidth += graphemeWidth;
|
|
120
|
-
}
|
|
121
|
-
lines.push(current);
|
|
122
|
-
}
|
|
123
|
-
return lines;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
const RUNNING_FRAMES = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
|
|
127
|
-
const STATIC_RUNNING_GLYPH = "●";
|
|
128
|
-
|
|
129
|
-
type ProgressSeedSource = Partial<Pick<AgentProgress, "index" | "toolCount" | "tokens" | "durationMs" | "lastActivityAt" | "currentToolStartedAt" | "turnCount">>;
|
|
130
|
-
|
|
131
|
-
function runningSeed(...values: Array<number | undefined>): number | undefined {
|
|
132
|
-
let seed: number | undefined;
|
|
133
|
-
for (const value of values) {
|
|
134
|
-
if (value === undefined || !Number.isFinite(value)) continue;
|
|
135
|
-
seed = (seed ?? 0) + Math.trunc(value);
|
|
136
|
-
}
|
|
137
|
-
return seed;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
function runningGlyph(seed?: number): string {
|
|
141
|
-
if (seed === undefined) return STATIC_RUNNING_GLYPH;
|
|
142
|
-
return RUNNING_FRAMES[Math.abs(seed) % RUNNING_FRAMES.length]!;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
function progressRunningSeed(progress: ProgressSeedSource | undefined): number | undefined {
|
|
146
|
-
if (!progress) return undefined;
|
|
147
|
-
return runningSeed(
|
|
148
|
-
progress.index,
|
|
149
|
-
progress.toolCount,
|
|
150
|
-
progress.tokens,
|
|
151
|
-
progress.durationMs,
|
|
152
|
-
progress.lastActivityAt,
|
|
153
|
-
progress.currentToolStartedAt,
|
|
154
|
-
progress.turnCount,
|
|
155
|
-
);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
interface LegacyResultAnimationContext {
|
|
159
|
-
state: { subagentResultAnimationTimer?: ReturnType<typeof setInterval> };
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
export function clearLegacyResultAnimationTimer(context: LegacyResultAnimationContext): void {
|
|
163
|
-
const timer = context.state.subagentResultAnimationTimer;
|
|
164
|
-
if (!timer) return;
|
|
165
|
-
clearInterval(timer);
|
|
166
|
-
context.state.subagentResultAnimationTimer = undefined;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
function extractOutputTarget(task: string): string | undefined {
|
|
170
|
-
const writeToMatch = task.match(/\[Write to:\s*([^\]\n]+)\]/i);
|
|
171
|
-
if (writeToMatch?.[1]?.trim()) return writeToMatch[1].trim();
|
|
172
|
-
const findingsMatch = task.match(/Write your findings to(?: exactly this path)?:\s*([^\r\n]+)/i);
|
|
173
|
-
if (findingsMatch?.[1]?.trim()) return findingsMatch[1].trim();
|
|
174
|
-
const outputMatch = task.match(/[Oo]utput(?:\s+to)?\s*:\s*(\S+)/i);
|
|
175
|
-
if (outputMatch?.[1]?.trim()) return outputMatch[1].trim();
|
|
176
|
-
return undefined;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
function hasEmptyTextOutputWithoutOutputTarget(task: string, output: string): boolean {
|
|
180
|
-
if (output.trim()) return false;
|
|
181
|
-
return !extractOutputTarget(task);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
function getToolCallLines(
|
|
185
|
-
result: Pick<Details["results"][number], "messages" | "toolCalls">,
|
|
186
|
-
expanded: boolean,
|
|
187
|
-
): string[] {
|
|
188
|
-
if (result.messages) {
|
|
189
|
-
return getDisplayItems(result.messages)
|
|
190
|
-
.filter((item): item is { type: "tool"; name: string; args: Record<string, unknown> } => item.type === "tool")
|
|
191
|
-
.map((item) => formatToolCall(item.name, item.args, expanded));
|
|
192
|
-
}
|
|
193
|
-
return result.toolCalls?.map((toolCall) => expanded ? toolCall.expandedText : toolCall.text) ?? [];
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
function snapshotNowForProgress(progress: Pick<AgentProgress, "currentToolStartedAt" | "durationMs" | "lastActivityAt">): number | undefined {
|
|
198
|
-
if (progress.currentToolStartedAt !== undefined && progress.durationMs !== undefined) return progress.currentToolStartedAt + progress.durationMs;
|
|
199
|
-
return progress.lastActivityAt;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
function formatCurrentToolLine(
|
|
203
|
-
progress: Pick<AgentProgress, "currentTool" | "currentToolArgs" | "currentToolStartedAt">,
|
|
204
|
-
availableWidth: number,
|
|
205
|
-
expanded: boolean,
|
|
206
|
-
snapshotNow?: number,
|
|
207
|
-
): string | undefined {
|
|
208
|
-
if (!progress.currentTool) return undefined;
|
|
209
|
-
const maxToolArgsLen = Math.max(50, availableWidth - 20);
|
|
210
|
-
const toolArgsPreview = progress.currentToolArgs
|
|
211
|
-
? (expanded || progress.currentToolArgs.length <= maxToolArgsLen
|
|
212
|
-
? progress.currentToolArgs
|
|
213
|
-
: `${progress.currentToolArgs.slice(0, maxToolArgsLen)}...`)
|
|
214
|
-
: "";
|
|
215
|
-
const durationSuffix = progress.currentToolStartedAt !== undefined && snapshotNow !== undefined
|
|
216
|
-
? ` | ${formatDuration(Math.max(0, snapshotNow - progress.currentToolStartedAt))}`
|
|
217
|
-
: "";
|
|
218
|
-
return toolArgsPreview
|
|
219
|
-
? `${progress.currentTool}: ${toolArgsPreview}${durationSuffix}`
|
|
220
|
-
: `${progress.currentTool}${durationSuffix}`;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
function buildLiveStatusLine(progress: Pick<AgentProgress, "activityState" | "lastActivityAt">, snapshotNow?: number): string | undefined {
|
|
224
|
-
if (progress.lastActivityAt !== undefined && snapshotNow !== undefined) return formatActivityLabel(progress.lastActivityAt, progress.activityState, snapshotNow);
|
|
225
|
-
if (progress.activityState === "needs_attention") return "needs attention";
|
|
226
|
-
if (progress.activityState === "active_long_running") return "active but long-running";
|
|
227
|
-
if (progress.lastActivityAt !== undefined) return "active";
|
|
228
|
-
return undefined;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
function themeBold(theme: Theme, text: string): string {
|
|
232
|
-
return ((theme as { bold?: (value: string) => string }).bold?.(text)) ?? text;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
function statJoin(theme: Theme, parts: string[]): string {
|
|
236
|
-
return parts.filter(Boolean).map((part) => theme.fg("dim", part)).join(` ${theme.fg("dim", "·")} `);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
function formatTokenStat(tokens: number): string {
|
|
240
|
-
return `${formatTokens(tokens)} token`;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
function formatToolUseStat(count: number): string {
|
|
244
|
-
return `${count} tool use${count === 1 ? "" : "s"}`;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
function formatTotalCostStat(totalCost: Details["totalCost"] | undefined): string {
|
|
248
|
-
if (!totalCost || (totalCost.inputTokens === 0 && totalCost.outputTokens === 0 && totalCost.costUsd === 0)) return "";
|
|
249
|
-
const parts: string[] = [];
|
|
250
|
-
if (totalCost.inputTokens) parts.push(`in:${formatTokens(totalCost.inputTokens)}`);
|
|
251
|
-
if (totalCost.outputTokens) parts.push(`out:${formatTokens(totalCost.outputTokens)}`);
|
|
252
|
-
if (totalCost.costUsd) parts.push(`$${totalCost.costUsd.toFixed(4)}`);
|
|
253
|
-
return parts.join(" ");
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
function formatProgressStats(theme: Theme, progress: Pick<AgentProgress, "toolCount" | "tokens" | "durationMs"> | undefined, includeDuration = true): string {
|
|
257
|
-
if (!progress) return "";
|
|
258
|
-
const parts: string[] = [];
|
|
259
|
-
if (progress.toolCount > 0) parts.push(formatToolUseStat(progress.toolCount));
|
|
260
|
-
if (progress.tokens > 0) parts.push(formatTokenStat(progress.tokens));
|
|
261
|
-
if (includeDuration && progress.durationMs > 0) parts.push(formatDuration(progress.durationMs));
|
|
262
|
-
return statJoin(theme, parts);
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
function firstOutputLine(text: string): string {
|
|
266
|
-
return text.split("\n").find((line) => line.trim())?.trim() ?? "";
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
function resultStatusLine(result: Details["results"][number], output: string): string {
|
|
270
|
-
if (result.detached) return result.detachedReason ? `Detached: ${result.detachedReason}` : "Detached";
|
|
271
|
-
if (result.interrupted) return "Paused";
|
|
272
|
-
if (result.exitCode !== 0) return `Error: ${result.error ?? (firstOutputLine(output) || `exit ${result.exitCode}`)}`;
|
|
273
|
-
if (result.acceptance?.status && result.acceptance.status !== "not-required") return `Done · acceptance: ${result.acceptance.status}`;
|
|
274
|
-
if (hasEmptyTextOutputWithoutOutputTarget(result.task, output)) return "Done (no text output)";
|
|
275
|
-
return "Done";
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
function resultGlyph(result: Details["results"][number], output: string, theme: Theme, running = result.progress?.status === "running", seed = progressRunningSeed(result.progress ?? result.progressSummary), frame?: number): string {
|
|
279
|
-
if (running) {
|
|
280
|
-
if (frame !== undefined) return theme.fg("accent", runningGlyph((seed ?? 0) + frame));
|
|
281
|
-
return theme.fg("accent", runningGlyph(seed));
|
|
282
|
-
}
|
|
283
|
-
if (result.detached) return theme.fg("warning", "■");
|
|
284
|
-
if (result.interrupted) return theme.fg("warning", "■");
|
|
285
|
-
if (result.exitCode !== 0) return theme.fg("error", "✗");
|
|
286
|
-
if (hasEmptyTextOutputWithoutOutputTarget(result.task, output)) return theme.fg("warning", "✓");
|
|
287
|
-
return theme.fg("success", "✓");
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
function compactCurrentActivity(progress: AgentProgress): string {
|
|
291
|
-
const snapshotNow = snapshotNowForProgress(progress);
|
|
292
|
-
return formatCurrentToolLine(progress, getTermWidth() - 4, false, snapshotNow) ?? buildLiveStatusLine(progress, snapshotNow) ?? "thinking…";
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
export function widgetRenderKey(job: AsyncJobState): string {
|
|
296
|
-
return JSON.stringify({
|
|
297
|
-
asyncDir: job.asyncDir,
|
|
298
|
-
status: job.status,
|
|
299
|
-
activityState: job.activityState,
|
|
300
|
-
lastActivityAt: job.lastActivityAt,
|
|
301
|
-
currentTool: job.currentTool,
|
|
302
|
-
currentToolStartedAt: job.currentToolStartedAt,
|
|
303
|
-
currentPath: job.currentPath,
|
|
304
|
-
turnCount: job.turnCount,
|
|
305
|
-
toolCount: job.toolCount,
|
|
306
|
-
mode: job.mode,
|
|
307
|
-
agents: job.agents,
|
|
308
|
-
currentStep: job.currentStep,
|
|
309
|
-
chainStepCount: job.chainStepCount,
|
|
310
|
-
parallelGroups: job.parallelGroups,
|
|
311
|
-
steps: job.steps,
|
|
312
|
-
nestedChildren: job.nestedChildren,
|
|
313
|
-
stepsTotal: job.stepsTotal,
|
|
314
|
-
runningSteps: job.runningSteps,
|
|
315
|
-
completedSteps: job.completedSteps,
|
|
316
|
-
activeParallelGroup: job.activeParallelGroup,
|
|
317
|
-
startedAt: job.startedAt,
|
|
318
|
-
updatedAt: job.updatedAt,
|
|
319
|
-
totalTokens: job.totalTokens,
|
|
320
|
-
});
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
function formatWidgetAgents(agents: string[]): string {
|
|
324
|
-
const distinct = [...new Set(agents)];
|
|
325
|
-
if (distinct.length === 1 && agents.length > 1) return `${distinct[0]} ×${agents.length}`;
|
|
326
|
-
if (agents.length > 3) return `${agents.slice(0, 2).join(", ")} +${agents.length - 2} more`;
|
|
327
|
-
return agents.join(", ");
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
function widgetJobName(job: AsyncJobState): string {
|
|
331
|
-
if (job.mode === "parallel") return "parallel";
|
|
332
|
-
if (job.mode === "chain") return "chain";
|
|
333
|
-
if (job.mode === "single" && job.agents?.length === 1) return job.agents[0]!;
|
|
334
|
-
if (job.agents?.length) return formatWidgetAgents(job.agents);
|
|
335
|
-
return job.mode ?? "subagent";
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
function widgetActivity(job: AsyncJobState): string {
|
|
339
|
-
const facts: string[] = [];
|
|
340
|
-
if (job.currentTool && job.currentToolStartedAt !== undefined && job.updatedAt !== undefined) facts.push(`${job.currentTool} ${formatDuration(Math.max(0, job.updatedAt - job.currentToolStartedAt))}`);
|
|
341
|
-
else if (job.currentTool) facts.push(job.currentTool);
|
|
342
|
-
if (job.currentPath) facts.push(shortenPath(job.currentPath));
|
|
343
|
-
if (job.turnCount !== undefined) facts.push(`${job.turnCount} turns`);
|
|
344
|
-
if (job.toolCount !== undefined) facts.push(`${job.toolCount} tools`);
|
|
345
|
-
const activity = buildLiveStatusLine(job, job.updatedAt);
|
|
346
|
-
if (activity && facts.length) return `${activity} · ${facts.join(" · ")}`;
|
|
347
|
-
if (activity) return activity;
|
|
348
|
-
if (facts.length) return facts.join(" · ");
|
|
349
|
-
if (job.status === "running") return "thinking…";
|
|
350
|
-
if (job.status === "queued") return "queued…";
|
|
351
|
-
if (job.status === "paused") return "Paused";
|
|
352
|
-
if (job.status === "failed") return "Failed";
|
|
353
|
-
return "Done";
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
function widgetStepRunningSeed(step: NonNullable<AsyncJobState["steps"]>[number], fallbackIndex?: number): number | undefined {
|
|
357
|
-
return runningSeed(
|
|
358
|
-
fallbackIndex,
|
|
359
|
-
step.index,
|
|
360
|
-
step.toolCount,
|
|
361
|
-
step.turnCount,
|
|
362
|
-
step.tokens?.total,
|
|
363
|
-
step.lastActivityAt,
|
|
364
|
-
step.currentToolStartedAt,
|
|
365
|
-
step.durationMs,
|
|
366
|
-
);
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
function widgetStepsRunningSeed(steps: Array<NonNullable<AsyncJobState["steps"]>[number]> | undefined): number | undefined {
|
|
370
|
-
let seed: number | undefined;
|
|
371
|
-
for (const [index, step] of (steps ?? []).entries()) seed = runningSeed(seed, widgetStepRunningSeed(step, index));
|
|
372
|
-
return seed;
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
function widgetJobRunningSeed(job: AsyncJobState): number | undefined {
|
|
376
|
-
return runningSeed(
|
|
377
|
-
job.updatedAt,
|
|
378
|
-
job.lastActivityAt,
|
|
379
|
-
job.toolCount,
|
|
380
|
-
job.turnCount,
|
|
381
|
-
job.totalTokens?.total,
|
|
382
|
-
job.currentStep,
|
|
383
|
-
job.runningSteps,
|
|
384
|
-
job.completedSteps,
|
|
385
|
-
widgetStepsRunningSeed(job.steps),
|
|
386
|
-
);
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
function widgetJobsRunningSeed(jobs: AsyncJobState[]): number | undefined {
|
|
390
|
-
let seed: number | undefined;
|
|
391
|
-
for (const job of jobs) seed = runningSeed(seed, widgetJobRunningSeed(job));
|
|
392
|
-
return seed;
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
function widgetStatusGlyph(job: AsyncJobState, theme: Theme): string {
|
|
396
|
-
if (job.status === "running") return theme.fg("accent", runningGlyph(widgetJobRunningSeed(job)));
|
|
397
|
-
if (job.status === "queued") return theme.fg("muted", "◦");
|
|
398
|
-
if (job.status === "complete") return theme.fg("success", "✓");
|
|
399
|
-
if (job.status === "paused") return theme.fg("warning", "■");
|
|
400
|
-
return theme.fg("error", "✗");
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
function widgetStepGlyph(status: AsyncJobStep["status"], theme: Theme, seed?: number): string {
|
|
404
|
-
if (status === "running") return theme.fg("accent", runningGlyph(seed));
|
|
405
|
-
if (status === "complete" || status === "completed") return theme.fg("success", "✓");
|
|
406
|
-
if (status === "failed") return theme.fg("error", "✗");
|
|
407
|
-
if (status === "paused") return theme.fg("warning", "■");
|
|
408
|
-
return theme.fg("muted", "◦");
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
function widgetStepStatus(status: AsyncJobStep["status"], theme: Theme): string {
|
|
412
|
-
if (status === "running") return theme.fg("accent", "running");
|
|
413
|
-
if (status === "complete" || status === "completed") return theme.fg("success", "complete");
|
|
414
|
-
if (status === "failed") return theme.fg("error", "failed");
|
|
415
|
-
if (status === "paused") return theme.fg("warning", "paused");
|
|
416
|
-
return theme.fg("dim", status);
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
function widgetStepActivity(step: NonNullable<AsyncJobState["steps"]>[number], snapshotNow?: number): string {
|
|
420
|
-
const facts: string[] = [];
|
|
421
|
-
if (step.currentTool && step.currentToolStartedAt !== undefined && snapshotNow !== undefined) facts.push(`${step.currentTool} ${formatDuration(Math.max(0, snapshotNow - step.currentToolStartedAt))}`);
|
|
422
|
-
else if (step.currentTool) facts.push(step.currentTool);
|
|
423
|
-
if (step.currentPath) facts.push(shortenPath(step.currentPath));
|
|
424
|
-
if (step.turnCount !== undefined) facts.push(`${step.turnCount} turns`);
|
|
425
|
-
if (step.toolCount !== undefined) facts.push(`${step.toolCount} tools`);
|
|
426
|
-
if (step.tokens?.total) facts.push(formatTokenStat(step.tokens.total));
|
|
427
|
-
const activity = buildLiveStatusLine(step, snapshotNow);
|
|
428
|
-
if (activity && facts.length) return `${activity} · ${facts.join(" · ")}`;
|
|
429
|
-
if (activity) return activity;
|
|
430
|
-
return facts.join(" · ");
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
function widgetChainDetails(job: AsyncJobState, theme: Theme, expanded = false, width = getTermWidth()): string[] {
|
|
435
|
-
if (!job.steps?.length) return [];
|
|
436
|
-
const total = job.chainStepCount ?? job.steps.length;
|
|
437
|
-
const lines: string[] = [];
|
|
438
|
-
for (const span of buildAsyncChainStepSpans(total, job.steps.length, job.parallelGroups)) {
|
|
439
|
-
const steps = job.steps.slice(span.start, span.start + span.count);
|
|
440
|
-
if (span.isParallel) {
|
|
441
|
-
const status = aggregateStepStatus(steps);
|
|
442
|
-
lines.push(` ${widgetStepGlyph(status, theme, widgetStepsRunningSeed(steps))} Step ${span.stepIndex + 1}/${total}: ${themeBold(theme, "parallel group")} ${theme.fg("dim", "·")} ${theme.fg("dim", formatParallelOutcome(steps, span.count))}`);
|
|
443
|
-
continue;
|
|
444
|
-
}
|
|
445
|
-
const step = steps[0];
|
|
446
|
-
if (!step) {
|
|
447
|
-
lines.push(` ${theme.fg("dim", `◦ Step ${span.stepIndex + 1}/${total}: pending`)}`);
|
|
448
|
-
continue;
|
|
449
|
-
}
|
|
450
|
-
lines.push(...foregroundStyleWidgetStepLines(job, theme, step, "Step", span.stepIndex + 1, total, expanded, width));
|
|
451
|
-
}
|
|
452
|
-
return lines;
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
function widgetParallelAgentDetails(job: AsyncJobState, theme: Theme, expanded = false, width = getTermWidth()): string[] {
|
|
456
|
-
if (!job.steps?.length) return [];
|
|
457
|
-
if (job.mode !== "parallel" && job.mode !== "chain") return [];
|
|
458
|
-
if (job.mode === "chain" && !job.activeParallelGroup && job.parallelGroups?.length) return widgetChainDetails(job, theme, expanded, width);
|
|
459
|
-
const total = job.stepsTotal ?? job.steps.length;
|
|
460
|
-
const lines: string[] = [];
|
|
461
|
-
for (const [index, step] of job.steps.entries()) {
|
|
462
|
-
const marker = index === job.steps.length - 1 ? "└" : "├";
|
|
463
|
-
const activity = widgetStepActivity(step, job.updatedAt);
|
|
464
|
-
const itemTitle = job.mode === "parallel" || job.activeParallelGroup ? "Agent" : "Step";
|
|
465
|
-
const modelDisplay = modelThinkingBadge(theme, step.model, step.thinking);
|
|
466
|
-
lines.push(` ${theme.fg("dim", `${marker} ${widgetStepGlyph(step.status, theme, widgetStepRunningSeed(step, index))} ${itemTitle} ${index + 1}/${total}: ${step.agent} · ${widgetStepStatus(step.status, theme)}${modelDisplay}${activity ? ` · ${activity}` : ""}`)}`);
|
|
467
|
-
for (const nestedLine of formatNestedWidgetLines(step.children, theme, width, expanded, job.updatedAt, expanded ? 8 : 1)) lines.push(` ${nestedLine}`);
|
|
468
|
-
}
|
|
469
|
-
return lines;
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
function parseParallelGroupAgentCount(label: string | undefined): number | undefined {
|
|
473
|
-
if (!label || !label.startsWith("[") || !label.endsWith("]")) return undefined;
|
|
474
|
-
const inner = label.slice(1, -1).trim();
|
|
475
|
-
if (!inner) return 0;
|
|
476
|
-
return inner.split("+").map((part) => part.trim()).filter(Boolean).length;
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
interface ChainStepSpan {
|
|
480
|
-
stepIndex: number;
|
|
481
|
-
start: number;
|
|
482
|
-
count: number;
|
|
483
|
-
isParallel: boolean;
|
|
484
|
-
status?: WorkflowNodeStatus;
|
|
485
|
-
label?: string;
|
|
486
|
-
error?: string;
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
function buildChainStepSpans(details: Pick<Details, "chainAgents" | "workflowGraph">): ChainStepSpan[] {
|
|
490
|
-
if (details.workflowGraph?.nodes?.length) {
|
|
491
|
-
const spans: ChainStepSpan[] = [];
|
|
492
|
-
let flatCursor = 0;
|
|
493
|
-
for (const node of details.workflowGraph.nodes) {
|
|
494
|
-
if (node.stepIndex === undefined) continue;
|
|
495
|
-
if (node.kind === "parallel-group" || node.kind === "dynamic-parallel-group") {
|
|
496
|
-
const childFlatIndexes = (node.children ?? [])
|
|
497
|
-
.map((child) => child.flatIndex)
|
|
498
|
-
.filter((value): value is number => typeof value === "number");
|
|
499
|
-
const start = childFlatIndexes.length ? Math.min(...childFlatIndexes) : flatCursor;
|
|
500
|
-
const count = node.children?.length ?? 0;
|
|
501
|
-
spans.push({ stepIndex: node.stepIndex, start, count, isParallel: true, status: node.status, label: node.label, error: node.error });
|
|
502
|
-
flatCursor = Math.max(flatCursor, start + count);
|
|
503
|
-
continue;
|
|
504
|
-
}
|
|
505
|
-
const start = node.flatIndex ?? flatCursor;
|
|
506
|
-
spans.push({ stepIndex: node.stepIndex, start, count: 1, isParallel: false, status: node.status, label: node.label, error: node.error });
|
|
507
|
-
flatCursor = Math.max(flatCursor, start + 1);
|
|
508
|
-
}
|
|
509
|
-
if (spans.length) return spans.sort((left, right) => left.stepIndex - right.stepIndex);
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
if (!details.chainAgents?.length) return [];
|
|
513
|
-
const spans: ChainStepSpan[] = [];
|
|
514
|
-
let start = 0;
|
|
515
|
-
for (let stepIndex = 0; stepIndex < details.chainAgents.length; stepIndex++) {
|
|
516
|
-
const label = details.chainAgents[stepIndex]!;
|
|
517
|
-
const parsedCount = parseParallelGroupAgentCount(label);
|
|
518
|
-
const count = parsedCount ?? 1;
|
|
519
|
-
spans.push({ stepIndex, start, count, isParallel: parsedCount !== undefined });
|
|
520
|
-
start += count;
|
|
521
|
-
}
|
|
522
|
-
return spans;
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
function isChainParallelGroupActive(details: Pick<Details, "mode" | "chainAgents" | "currentStepIndex" | "workflowGraph">): boolean {
|
|
526
|
-
if (details.mode !== "chain") return false;
|
|
527
|
-
if (details.currentStepIndex === undefined) return false;
|
|
528
|
-
return buildChainStepSpans(details).some((span) => span.stepIndex === details.currentStepIndex && span.isParallel);
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
function buildAsyncChainStepSpans(total: number, stepCount: number, parallelGroups: AsyncParallelGroupStatus[] = []): ChainStepSpan[] {
|
|
532
|
-
const spans: ChainStepSpan[] = [];
|
|
533
|
-
let flatIndex = 0;
|
|
534
|
-
for (let stepIndex = 0; stepIndex < total; stepIndex++) {
|
|
535
|
-
const group = parallelGroups.find((candidate) => candidate.stepIndex === stepIndex);
|
|
536
|
-
if (group) {
|
|
537
|
-
spans.push({ stepIndex, start: group.start, count: group.count, isParallel: true });
|
|
538
|
-
flatIndex = Math.max(flatIndex, group.start + group.count);
|
|
539
|
-
continue;
|
|
540
|
-
}
|
|
541
|
-
spans.push({ stepIndex, start: flatIndex, count: flatIndex < stepCount ? 1 : 0, isParallel: false });
|
|
542
|
-
flatIndex++;
|
|
543
|
-
}
|
|
544
|
-
return spans;
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
function isDoneResult(result: Details["results"][number]): boolean {
|
|
548
|
-
const status = result.progress?.status;
|
|
549
|
-
if (status === "completed") return true;
|
|
550
|
-
if (status === "running" || status === "pending") return false;
|
|
551
|
-
if (result.interrupted || result.detached) return false;
|
|
552
|
-
return result.exitCode === 0;
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
function workflowGraphHasStatus(details: Pick<Details, "workflowGraph">, statuses: WorkflowNodeStatus[]): boolean {
|
|
556
|
-
return details.workflowGraph?.nodes.some((node) => statuses.includes(node.status)) ?? false;
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
interface ChainRenderResultEntry {
|
|
560
|
-
kind: "result";
|
|
561
|
-
resultIndex: number;
|
|
562
|
-
rowNumber: number;
|
|
563
|
-
agentName: string;
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
interface ChainRenderPlaceholderEntry {
|
|
567
|
-
kind: "placeholder";
|
|
568
|
-
rowNumber: number;
|
|
569
|
-
stepLabel: string;
|
|
570
|
-
agentName: string;
|
|
571
|
-
status: WorkflowNodeStatus;
|
|
572
|
-
error?: string;
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
type ChainRenderEntry = ChainRenderResultEntry | ChainRenderPlaceholderEntry;
|
|
576
|
-
|
|
577
|
-
function buildChainRenderEntries(details: Details, label: MultiProgressLabel): ChainRenderEntry[] | undefined {
|
|
578
|
-
if (details.mode !== "chain" || !label.hasParallelInChain || label.showActiveGroupOnly) return undefined;
|
|
579
|
-
const entries: ChainRenderEntry[] = [];
|
|
580
|
-
for (const span of buildChainStepSpans(details)) {
|
|
581
|
-
if (span.isParallel && span.count === 0) {
|
|
582
|
-
entries.push({
|
|
583
|
-
kind: "placeholder",
|
|
584
|
-
rowNumber: span.stepIndex + 1,
|
|
585
|
-
stepLabel: `Step ${span.stepIndex + 1}`,
|
|
586
|
-
agentName: span.label ?? details.chainAgents?.[span.stepIndex] ?? `step-${span.stepIndex + 1}`,
|
|
587
|
-
status: span.status ?? "pending",
|
|
588
|
-
error: span.error,
|
|
589
|
-
});
|
|
590
|
-
continue;
|
|
591
|
-
}
|
|
592
|
-
for (let index = span.start; index < span.start + span.count; index++) {
|
|
593
|
-
entries.push({
|
|
594
|
-
kind: "result",
|
|
595
|
-
resultIndex: index,
|
|
596
|
-
rowNumber: index + 1,
|
|
597
|
-
agentName: details.results[index]?.agent ?? details.chainAgents?.[span.stepIndex] ?? `step-${span.stepIndex + 1}`,
|
|
598
|
-
});
|
|
599
|
-
}
|
|
600
|
-
}
|
|
601
|
-
return entries;
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
interface MultiProgressLabel {
|
|
605
|
-
headerLabel: string;
|
|
606
|
-
itemTitle: "Step" | "Agent";
|
|
607
|
-
totalCount: number;
|
|
608
|
-
hasParallelInChain: boolean;
|
|
609
|
-
activeParallelGroup: boolean;
|
|
610
|
-
groupStartIndex: number;
|
|
611
|
-
groupEndIndex: number;
|
|
612
|
-
showActiveGroupOnly: boolean;
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
function buildMultiProgressLabel(details: Pick<Details, "mode" | "results" | "progress" | "totalSteps" | "currentStepIndex" | "chainAgents" | "workflowGraph">, hasRunning: boolean): MultiProgressLabel {
|
|
616
|
-
const stepSpans = buildChainStepSpans(details);
|
|
617
|
-
const hasParallelInChain = details.mode === "chain" && stepSpans.some((span) => span.isParallel);
|
|
618
|
-
const activeParallelGroup = isChainParallelGroupActive(details);
|
|
619
|
-
const itemTitle: "Step" | "Agent" = details.mode === "parallel" || activeParallelGroup ? "Agent" : "Step";
|
|
620
|
-
|
|
621
|
-
if (details.mode === "parallel") {
|
|
622
|
-
const totalCount = details.totalSteps ?? details.results.length;
|
|
623
|
-
const statuses = new Array(totalCount).fill("pending") as Array<"pending" | "running" | "completed" | "failed" | "detached">;
|
|
624
|
-
for (const progress of details.progress ?? []) {
|
|
625
|
-
if (progress.index >= 0 && progress.index < totalCount) statuses[progress.index] = progress.status;
|
|
626
|
-
}
|
|
627
|
-
for (let i = 0; i < details.results.length; i++) {
|
|
628
|
-
const result = details.results[i]!;
|
|
629
|
-
const progressFromArray = details.progress?.find((progress) => progress.index === i)
|
|
630
|
-
|| details.progress?.find((progress) => progress.agent === result.agent && progress.status === "running");
|
|
631
|
-
const index = result.progress?.index ?? progressFromArray?.index ?? i;
|
|
632
|
-
if (index < 0 || index >= totalCount) continue;
|
|
633
|
-
const status = result.progress?.status
|
|
634
|
-
?? (result.interrupted || result.detached
|
|
635
|
-
? "detached"
|
|
636
|
-
: result.exitCode === 0
|
|
637
|
-
? "completed"
|
|
638
|
-
: "failed");
|
|
639
|
-
statuses[index] = status;
|
|
640
|
-
}
|
|
641
|
-
const running = statuses.filter((status) => status === "running").length;
|
|
642
|
-
const done = statuses.filter((status) => status === "completed").length;
|
|
643
|
-
const headerLabel = hasRunning
|
|
644
|
-
? `${formatAgentRunningLabel(running)} · ${done}/${totalCount} done`
|
|
645
|
-
: `${done}/${totalCount} done`;
|
|
646
|
-
return { headerLabel, itemTitle, totalCount, hasParallelInChain, activeParallelGroup, groupStartIndex: 0, groupEndIndex: totalCount, showActiveGroupOnly: false };
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
if (activeParallelGroup) {
|
|
650
|
-
const currentStepIndex = details.currentStepIndex!;
|
|
651
|
-
const span = stepSpans[currentStepIndex];
|
|
652
|
-
const groupSize = span?.count ?? 1;
|
|
653
|
-
const groupStart = span?.start ?? 0;
|
|
654
|
-
const groupEnd = groupStart + groupSize;
|
|
655
|
-
let running = 0;
|
|
656
|
-
let done = 0;
|
|
657
|
-
for (let index = groupStart; index < groupEnd; index++) {
|
|
658
|
-
const progressEntry = details.progress?.find((progress) => progress.index === index);
|
|
659
|
-
const resultEntry = details.results.find((result) => result.progress?.index === index);
|
|
660
|
-
if (progressEntry?.status === "running") {
|
|
661
|
-
running++;
|
|
662
|
-
continue;
|
|
663
|
-
}
|
|
664
|
-
if (progressEntry?.status === "completed") {
|
|
665
|
-
done++;
|
|
666
|
-
continue;
|
|
667
|
-
}
|
|
668
|
-
if (resultEntry && isDoneResult(resultEntry)) done++;
|
|
669
|
-
}
|
|
670
|
-
const totalSteps = details.totalSteps ?? details.chainAgents?.length ?? 1;
|
|
671
|
-
const headerLabel = hasRunning
|
|
672
|
-
? `step ${currentStepIndex + 1}/${totalSteps} · parallel group: ${formatAgentRunningLabel(running)} · ${done}/${groupSize} done`
|
|
673
|
-
: `step ${currentStepIndex + 1}/${totalSteps} · parallel group: ${done}/${groupSize} done`;
|
|
674
|
-
return { headerLabel, itemTitle, totalCount: groupSize, hasParallelInChain, activeParallelGroup, groupStartIndex: groupStart, groupEndIndex: groupEnd, showActiveGroupOnly: true };
|
|
675
|
-
}
|
|
676
|
-
|
|
677
|
-
if (details.mode === "chain" && details.chainAgents?.length) {
|
|
678
|
-
const totalCount = details.totalSteps ?? details.chainAgents.length;
|
|
679
|
-
const doneLogical = stepSpans.filter((span) => {
|
|
680
|
-
if (span.status && span.status !== "completed") return false;
|
|
681
|
-
if (span.count === 0) return span.status === "completed";
|
|
682
|
-
for (let index = span.start; index < span.start + span.count; index++) {
|
|
683
|
-
const progressEntry = details.progress?.find((progress) => progress.index === index);
|
|
684
|
-
const resultEntry = details.results.find((result) => result.progress?.index === index) ?? details.results[index];
|
|
685
|
-
if (progressEntry?.status === "running" || progressEntry?.status === "pending" || progressEntry?.status === "failed") return false;
|
|
686
|
-
if (!resultEntry || !isDoneResult(resultEntry)) return false;
|
|
687
|
-
}
|
|
688
|
-
return true;
|
|
689
|
-
}).length;
|
|
690
|
-
const currentStep = details.currentStepIndex !== undefined ? details.currentStepIndex + 1 : Math.min(totalCount, doneLogical + (hasRunning ? 1 : 0));
|
|
691
|
-
const headerLabel = hasRunning ? `step ${currentStep}/${totalCount}` : `step ${doneLogical}/${totalCount}`;
|
|
692
|
-
return { headerLabel, itemTitle, totalCount, hasParallelInChain, activeParallelGroup, groupStartIndex: 0, groupEndIndex: details.results.length, showActiveGroupOnly: false };
|
|
693
|
-
}
|
|
694
|
-
|
|
695
|
-
const totalCount = details.totalSteps ?? details.results.length;
|
|
696
|
-
const currentStep = details.currentStepIndex !== undefined ? details.currentStepIndex + 1 : Math.min(totalCount, details.results.filter(isDoneResult).length + (hasRunning ? 1 : 0));
|
|
697
|
-
const done = details.results.filter(isDoneResult).length;
|
|
698
|
-
const headerLabel = hasRunning ? `step ${currentStep}/${totalCount}` : `step ${done}/${totalCount}`;
|
|
699
|
-
return { headerLabel, itemTitle, totalCount, hasParallelInChain, activeParallelGroup, groupStartIndex: 0, groupEndIndex: details.results.length, showActiveGroupOnly: false };
|
|
700
|
-
}
|
|
701
|
-
|
|
702
|
-
function resultRowLabel(details: Pick<Details, "mode" | "chainAgents" | "workflowGraph">, label: MultiProgressLabel, resultIndex: number, stepNumber: number): string {
|
|
703
|
-
if (details.mode === "chain" && label.hasParallelInChain) {
|
|
704
|
-
const span = buildChainStepSpans(details).find((candidate) => resultIndex >= candidate.start && resultIndex < candidate.start + candidate.count);
|
|
705
|
-
if (span?.isParallel) return `Agent ${resultIndex - span.start + 1}/${span.count}`;
|
|
706
|
-
if (span) return `Step ${span.stepIndex + 1}`;
|
|
707
|
-
}
|
|
708
|
-
if (label.itemTitle === "Agent") {
|
|
709
|
-
const localStepNumber = label.activeParallelGroup
|
|
710
|
-
? Math.max(1, stepNumber - label.groupStartIndex)
|
|
711
|
-
: stepNumber;
|
|
712
|
-
return `Agent ${localStepNumber}/${label.totalCount}`;
|
|
713
|
-
}
|
|
714
|
-
return `Step ${stepNumber}`;
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
function widgetStats(job: AsyncJobState, theme: Theme): string {
|
|
718
|
-
const parts: string[] = [];
|
|
719
|
-
const stepsTotal = job.stepsTotal ?? (job.agents?.length ?? 1);
|
|
720
|
-
if (job.activeParallelGroup) {
|
|
721
|
-
const running = job.runningSteps ?? (job.status === "running" ? 1 : 0);
|
|
722
|
-
const done = job.completedSteps ?? (job.status === "complete" ? stepsTotal : 0);
|
|
723
|
-
if (job.mode === "parallel") {
|
|
724
|
-
if (job.status === "running" && running > 0) parts.push(formatAgentRunningLabel(running));
|
|
725
|
-
if (stepsTotal > 0) parts.push(`${done}/${stepsTotal} done`);
|
|
726
|
-
} else {
|
|
727
|
-
const activeGroup = job.currentStep !== undefined
|
|
728
|
-
? job.parallelGroups?.find((group) => job.currentStep! >= group.start && job.currentStep! < group.start + group.count)
|
|
729
|
-
: job.parallelGroups?.find((group) => group.start === 0);
|
|
730
|
-
const logicalStep = activeGroup?.stepIndex ?? job.currentStep ?? 0;
|
|
731
|
-
const total = job.chainStepCount ?? stepsTotal;
|
|
732
|
-
const groupParts = [`${done}/${stepsTotal} done`];
|
|
733
|
-
if (job.status === "running" && running > 0) groupParts.unshift(formatAgentRunningLabel(running));
|
|
734
|
-
parts.push(`step ${logicalStep + 1}/${total} · parallel group: ${groupParts.join(" · ")}`);
|
|
735
|
-
}
|
|
736
|
-
} else if (job.currentStep !== undefined) {
|
|
737
|
-
if (job.mode === "chain" && job.parallelGroups?.length) {
|
|
738
|
-
const total = job.chainStepCount ?? stepsTotal;
|
|
739
|
-
parts.push(`step ${flatToLogicalStepIndex(job.currentStep, total, job.parallelGroups) + 1}/${total}`);
|
|
740
|
-
} else {
|
|
741
|
-
parts.push(`step ${job.currentStep + 1}/${stepsTotal}`);
|
|
742
|
-
}
|
|
743
|
-
} else if (stepsTotal > 1) {
|
|
744
|
-
parts.push(`steps ${stepsTotal}`);
|
|
745
|
-
}
|
|
746
|
-
if (job.toolCount !== undefined) parts.push(formatToolUseStat(job.toolCount));
|
|
747
|
-
if (job.totalTokens?.total) parts.push(formatTokenStat(job.totalTokens.total));
|
|
748
|
-
if (job.startedAt !== undefined && job.updatedAt !== undefined) parts.push(formatDuration(Math.max(0, job.updatedAt - job.startedAt)));
|
|
749
|
-
return statJoin(theme, parts);
|
|
750
|
-
}
|
|
751
|
-
|
|
752
|
-
function widgetStepStats(theme: Theme, step: NonNullable<AsyncJobState["steps"]>[number]): string {
|
|
753
|
-
return statJoin(theme, [
|
|
754
|
-
step.turnCount !== undefined ? `${step.turnCount} turns` : "",
|
|
755
|
-
step.toolCount !== undefined ? formatToolUseStat(step.toolCount) : "",
|
|
756
|
-
step.tokens?.total ? formatTokenStat(step.tokens.total) : "",
|
|
757
|
-
step.durationMs !== undefined ? formatDuration(step.durationMs) : "",
|
|
758
|
-
]);
|
|
759
|
-
}
|
|
760
|
-
|
|
761
|
-
function modelThinkingBadge(theme: Theme, model?: string, thinking?: string): string {
|
|
762
|
-
const label = formatModelThinking(model, thinking);
|
|
763
|
-
return label ? theme.fg("dim", ` (${label})`) : "";
|
|
764
|
-
}
|
|
765
|
-
|
|
766
|
-
function widgetStepActivityLine(step: NonNullable<AsyncJobState["steps"]>[number], width: number, expanded: boolean, snapshotNow?: number): string {
|
|
767
|
-
const toolLine = formatCurrentToolLine(step, width, expanded, snapshotNow);
|
|
768
|
-
if (toolLine) return toolLine;
|
|
769
|
-
const activity = buildLiveStatusLine(step, snapshotNow);
|
|
770
|
-
if (activity) return activity;
|
|
771
|
-
if (step.status === "running") return "thinking…";
|
|
772
|
-
return "";
|
|
773
|
-
}
|
|
774
|
-
|
|
775
|
-
function widgetOutputPath(job: AsyncJobState, step: NonNullable<AsyncJobState["steps"]>[number]): string | undefined {
|
|
776
|
-
if (typeof step.index !== "number") return undefined;
|
|
777
|
-
return path.join(job.asyncDir, `output-${step.index}.log`);
|
|
778
|
-
}
|
|
779
|
-
|
|
780
|
-
function nestedRunName(run: NestedRunSummary): string {
|
|
781
|
-
if (run.agent) return run.agent;
|
|
782
|
-
if (run.agents?.length) return formatWidgetAgents(run.agents);
|
|
783
|
-
return run.id;
|
|
784
|
-
}
|
|
785
|
-
|
|
786
|
-
function nestedStatusGlyph(state: NestedRunSummary["state"] | NestedStepSummary["status"], theme: Theme, seed?: number): string {
|
|
787
|
-
if (state === "running") return theme.fg("accent", runningGlyph(seed));
|
|
788
|
-
if (state === "complete" || state === "completed") return theme.fg("success", "✓");
|
|
789
|
-
if (state === "failed") return theme.fg("error", "✗");
|
|
790
|
-
if (state === "paused") return theme.fg("warning", "■");
|
|
791
|
-
return theme.fg("muted", "◦");
|
|
792
|
-
}
|
|
793
|
-
|
|
794
|
-
function nestedRunSeed(run: NestedRunSummary): number | undefined {
|
|
795
|
-
return runningSeed(run.lastUpdate, run.lastActivityAt, run.currentStep, run.toolCount, run.turnCount, run.totalTokens?.total, run.currentToolStartedAt);
|
|
796
|
-
}
|
|
797
|
-
|
|
798
|
-
function nestedActivity(input: Pick<NestedRunSummary | NestedStepSummary, "activityState" | "lastActivityAt" | "currentTool" | "currentToolStartedAt" | "currentPath" | "turnCount" | "toolCount">, state: NestedRunSummary["state"] | NestedStepSummary["status"], snapshotNow?: number): string {
|
|
799
|
-
const facts: string[] = [];
|
|
800
|
-
if (input.currentTool && input.currentToolStartedAt !== undefined && snapshotNow !== undefined) facts.push(`${input.currentTool} ${formatDuration(Math.max(0, snapshotNow - input.currentToolStartedAt))}`);
|
|
801
|
-
else if (input.currentTool) facts.push(input.currentTool);
|
|
802
|
-
if (input.currentPath) facts.push(shortenPath(input.currentPath));
|
|
803
|
-
if (input.turnCount !== undefined) facts.push(`${input.turnCount} turns`);
|
|
804
|
-
if (input.toolCount !== undefined) facts.push(`${input.toolCount} tools`);
|
|
805
|
-
const activity = buildLiveStatusLine(input, snapshotNow);
|
|
806
|
-
if (activity && facts.length) return `${activity} · ${facts.join(" · ")}`;
|
|
807
|
-
if (activity) return activity;
|
|
808
|
-
if (facts.length) return facts.join(" · ");
|
|
809
|
-
if (state === "running") return "thinking…";
|
|
810
|
-
if (state === "queued" || state === "pending") return "queued…";
|
|
811
|
-
if (state === "paused") return "Paused";
|
|
812
|
-
if (state === "failed") return "Failed";
|
|
813
|
-
return "Done";
|
|
814
|
-
}
|
|
815
|
-
|
|
816
|
-
function formatNestedWidgetLines(children: NestedRunSummary[] | undefined, theme: Theme, width: number, expanded: boolean, snapshotNow?: number, lineBudget = expanded ? 12 : 1): string[] {
|
|
817
|
-
if (!children?.length || lineBudget <= 0) return [];
|
|
818
|
-
if (!expanded) {
|
|
819
|
-
const aggregate = formatNestedAggregate(children);
|
|
820
|
-
return aggregate ? [theme.fg("dim", `↳ ${aggregate}`)] : [];
|
|
821
|
-
}
|
|
822
|
-
const lines: string[] = [];
|
|
823
|
-
const maxDepth = 2;
|
|
824
|
-
const append = (items: NestedRunSummary[] | undefined, depth: number, prefix: string): void => {
|
|
825
|
-
if (!items?.length || lines.length >= lineBudget) return;
|
|
826
|
-
if (depth > maxDepth) {
|
|
827
|
-
const aggregate = formatNestedAggregate(items);
|
|
828
|
-
if (aggregate && lines.length < lineBudget) lines.push(theme.fg("dim", `${prefix}↳ ${aggregate}`));
|
|
829
|
-
return;
|
|
830
|
-
}
|
|
831
|
-
for (let index = 0; index < items.length; index++) {
|
|
832
|
-
const child = items[index]!;
|
|
833
|
-
if (lines.length >= lineBudget) {
|
|
834
|
-
const aggregate = formatNestedAggregate(items.slice(index));
|
|
835
|
-
if (aggregate) lines[lines.length - 1] = theme.fg("dim", `${prefix}↳ ${aggregate}`);
|
|
836
|
-
return;
|
|
837
|
-
}
|
|
838
|
-
const activity = nestedActivity(child, child.state, snapshotNow ?? child.lastUpdate);
|
|
839
|
-
const error = child.error ? ` · ${child.error}` : "";
|
|
840
|
-
lines.push(theme.fg("dim", `${prefix}↳ ${nestedStatusGlyph(child.state, theme, nestedRunSeed(child))} ${nestedRunName(child)} · ${child.state} · ${activity}${error}`));
|
|
841
|
-
if (depth === maxDepth) {
|
|
842
|
-
const aggregate = formatNestedAggregate([...(child.steps?.flatMap((step) => step.children ?? []) ?? []), ...(child.children ?? [])]);
|
|
843
|
-
if (aggregate && lines.length < lineBudget) lines.push(theme.fg("dim", `${prefix} ↳ ${aggregate}`));
|
|
844
|
-
continue;
|
|
845
|
-
}
|
|
846
|
-
for (const step of child.steps ?? []) {
|
|
847
|
-
if (lines.length >= lineBudget) return;
|
|
848
|
-
lines.push(theme.fg("dim", `${prefix} ↳ ${nestedStatusGlyph(step.status, theme)} ${step.agent} · ${step.status} · ${nestedActivity(step, step.status, snapshotNow ?? child.lastUpdate)}`));
|
|
849
|
-
append(step.children, depth + 1, `${prefix} `);
|
|
850
|
-
}
|
|
851
|
-
append(child.children, depth + 1, `${prefix} `);
|
|
852
|
-
}
|
|
853
|
-
};
|
|
854
|
-
append(children, 0, "");
|
|
855
|
-
return lines.map((line) => truncLine(line, width));
|
|
856
|
-
}
|
|
857
|
-
|
|
858
|
-
function foregroundStyleWidgetStepLines(
|
|
859
|
-
job: AsyncJobState,
|
|
860
|
-
theme: Theme,
|
|
861
|
-
step: NonNullable<AsyncJobState["steps"]>[number],
|
|
862
|
-
itemTitle: "Agent" | "Step",
|
|
863
|
-
index: number,
|
|
864
|
-
total: number,
|
|
865
|
-
expanded: boolean,
|
|
866
|
-
width: number,
|
|
867
|
-
): string[] {
|
|
868
|
-
const status = widgetStepStatus(step.status, theme);
|
|
869
|
-
const stats = widgetStepStats(theme, step);
|
|
870
|
-
const modelDisplay = modelThinkingBadge(theme, step.model, step.thinking);
|
|
871
|
-
const lines = [` ${widgetStepGlyph(step.status, theme, widgetStepRunningSeed(step, index - 1))} ${itemTitle} ${index}/${total}: ${themeBold(theme, step.agent)} ${theme.fg("dim", "·")} ${status}${modelDisplay}${stats ? ` ${theme.fg("dim", "·")} ${stats}` : ""}`];
|
|
872
|
-
const activity = widgetStepActivityLine(step, width, expanded, job.updatedAt);
|
|
873
|
-
if (activity) lines.push(` ${theme.fg("dim", `⎿ ${activity}`)}`);
|
|
874
|
-
for (const nestedLine of formatNestedWidgetLines(step.children, theme, width, expanded, job.updatedAt)) {
|
|
875
|
-
lines.push(` ${nestedLine}`);
|
|
876
|
-
}
|
|
877
|
-
if (step.status === "running") {
|
|
878
|
-
if (!expanded) lines.push(` ${theme.fg("accent", liveDetailHintText())}`);
|
|
879
|
-
const output = widgetOutputPath(job, step);
|
|
880
|
-
if (output) lines.push(` ${theme.fg("dim", `output: ${shortenPath(output)}`)}`);
|
|
881
|
-
if (expanded) {
|
|
882
|
-
const liveStatus = buildLiveStatusLine(step, job.updatedAt);
|
|
883
|
-
if (liveStatus && liveStatus !== activity) lines.push(` ${theme.fg("accent", liveStatus)}`);
|
|
884
|
-
for (const tool of step.recentTools?.slice(-3) ?? []) {
|
|
885
|
-
const maxArgsLen = Math.max(40, width - 30);
|
|
886
|
-
const argsPreview = tool.args.length <= maxArgsLen ? tool.args : `${tool.args.slice(0, maxArgsLen)}...`;
|
|
887
|
-
lines.push(` ${theme.fg("dim", `${tool.tool}${argsPreview ? `: ${argsPreview}` : ""}`)}`);
|
|
888
|
-
}
|
|
889
|
-
for (const line of step.recentOutput?.slice(-5) ?? []) {
|
|
890
|
-
lines.push(` ${theme.fg("dim", line)}`);
|
|
891
|
-
}
|
|
892
|
-
}
|
|
893
|
-
}
|
|
894
|
-
return lines;
|
|
895
|
-
}
|
|
896
|
-
|
|
897
|
-
function foregroundStyleWidgetDetails(job: AsyncJobState, theme: Theme, expanded: boolean, width: number): string[] {
|
|
898
|
-
if (!job.steps?.length) return [
|
|
899
|
-
` ${theme.fg("dim", `⎿ ${widgetActivity(job)}`)}`,
|
|
900
|
-
...formatNestedWidgetLines(job.nestedChildren, theme, width, expanded, job.updatedAt).map((line) => ` ${line}`),
|
|
901
|
-
];
|
|
902
|
-
if (job.mode === "chain" && !job.activeParallelGroup && job.parallelGroups?.length) return widgetChainDetails(job, theme, expanded, width);
|
|
903
|
-
const total = job.stepsTotal ?? job.steps.length;
|
|
904
|
-
const itemTitle = job.mode === "parallel" || job.activeParallelGroup ? "Agent" : "Step";
|
|
905
|
-
const lines: string[] = [];
|
|
906
|
-
for (const [index, step] of job.steps.entries()) {
|
|
907
|
-
lines.push(...foregroundStyleWidgetStepLines(job, theme, step, itemTitle, index + 1, total, expanded, width));
|
|
908
|
-
}
|
|
909
|
-
const attached = new Set(job.steps.flatMap((step) => step.children?.map((child) => child.id) ?? []));
|
|
910
|
-
const unattached = job.nestedChildren?.filter((child) => !attached.has(child.id)) ?? [];
|
|
911
|
-
for (const nestedLine of formatNestedWidgetLines(unattached, theme, width, expanded, job.updatedAt)) {
|
|
912
|
-
lines.push(` ${nestedLine}`);
|
|
913
|
-
}
|
|
914
|
-
return lines;
|
|
915
|
-
}
|
|
916
|
-
|
|
917
|
-
function buildSingleWidgetLines(job: AsyncJobState, theme: Theme, width: number, expanded: boolean): string[] {
|
|
918
|
-
const stats = widgetStats(job, theme);
|
|
919
|
-
const count = job.mode === "chain" ? job.chainStepCount : job.stepsTotal ?? job.agents?.length ?? job.steps?.length;
|
|
920
|
-
const mode = widgetJobName(job);
|
|
921
|
-
const title = `async subagent ${mode}${count && count > 1 ? ` (${count})` : ""}`;
|
|
922
|
-
return [
|
|
923
|
-
`${theme.fg("toolTitle", themeBold(theme, title))} ${theme.fg("dim", "· background")}`,
|
|
924
|
-
`${widgetStatusGlyph(job, theme)} ${themeBold(theme, mode)}${stats ? ` ${theme.fg("dim", "·")} ${stats}` : ""}`,
|
|
925
|
-
...foregroundStyleWidgetDetails(job, theme, expanded, width),
|
|
926
|
-
].map((line) => truncLine(line, width));
|
|
927
|
-
}
|
|
928
|
-
|
|
929
|
-
function compactSingleWidgetLines(job: AsyncJobState, theme: Theme, width: number): string[] {
|
|
930
|
-
const fullLines = buildSingleWidgetLines(job, theme, width, false);
|
|
931
|
-
if (fullLines.length <= 10 || !job.steps?.length || (job.mode !== "parallel" && !job.activeParallelGroup)) return fullLines;
|
|
932
|
-
|
|
933
|
-
const total = job.stepsTotal ?? job.steps.length;
|
|
934
|
-
const itemTitle = job.mode === "parallel" || job.activeParallelGroup ? "Agent" : "Step";
|
|
935
|
-
const lines = fullLines.slice(0, 2);
|
|
936
|
-
for (const [index, step] of job.steps.entries()) {
|
|
937
|
-
const status = widgetStepStatus(step.status, theme);
|
|
938
|
-
const activity = widgetStepActivityLine(step, width, false, job.updatedAt);
|
|
939
|
-
const stepStats = widgetStepStats(theme, step);
|
|
940
|
-
const activitySuffix = activity ? ` ${theme.fg("dim", "·")} ${theme.fg("dim", activity)}` : "";
|
|
941
|
-
const modelDisplay = modelThinkingBadge(theme, step.model, step.thinking);
|
|
942
|
-
lines.push(` ${widgetStepGlyph(step.status, theme, widgetStepRunningSeed(step, index))} ${itemTitle} ${index + 1}/${total}: ${themeBold(theme, step.agent)} ${theme.fg("dim", "·")} ${status}${modelDisplay}${activitySuffix}${stepStats ? ` ${theme.fg("dim", "·")} ${stepStats}` : ""}`);
|
|
943
|
-
for (const nestedLine of formatNestedWidgetLines(step.children, theme, width, false, job.updatedAt)) lines.push(` ${nestedLine}`);
|
|
944
|
-
}
|
|
945
|
-
if (job.steps.some((step) => step.status === "running")) lines.push(theme.fg("accent", ` ${liveDetailHintText()}`));
|
|
946
|
-
return lines.map((line) => truncLine(line, width));
|
|
947
|
-
}
|
|
948
|
-
|
|
949
|
-
type WidgetRenderTier = "full" | "single-line" | "progressive";
|
|
950
|
-
|
|
951
|
-
interface WidgetLayoutSession {
|
|
952
|
-
expanded: boolean;
|
|
953
|
-
rows: number;
|
|
954
|
-
columns: number;
|
|
955
|
-
tier: WidgetRenderTier;
|
|
956
|
-
lockedRows?: number;
|
|
957
|
-
visibleJobKeys: string[];
|
|
958
|
-
}
|
|
959
|
-
|
|
960
|
-
const RESERVED_NON_WIDGET_ROWS = 19;
|
|
961
|
-
|
|
962
|
-
let widgetLayoutSession: WidgetLayoutSession | undefined;
|
|
963
|
-
|
|
964
|
-
function resetWidgetLayoutSession(): void {
|
|
965
|
-
widgetLayoutSession = undefined;
|
|
966
|
-
}
|
|
967
|
-
|
|
968
|
-
function estimateAvailableWidgetRows(): number {
|
|
969
|
-
const rows = process.stdout.rows || 30;
|
|
970
|
-
return Math.max(1, rows - RESERVED_NON_WIDGET_ROWS);
|
|
971
|
-
}
|
|
972
|
-
|
|
973
|
-
function currentTerminalRows(): number {
|
|
974
|
-
return process.stdout.rows || 30;
|
|
975
|
-
}
|
|
976
|
-
|
|
977
|
-
function currentTerminalColumns(): number {
|
|
978
|
-
return process.stdout.columns || 120;
|
|
979
|
-
}
|
|
980
|
-
|
|
981
|
-
function widgetSessionMatches(expanded: boolean): boolean {
|
|
982
|
-
return widgetLayoutSession?.expanded === expanded
|
|
983
|
-
&& widgetLayoutSession.rows === currentTerminalRows()
|
|
984
|
-
&& widgetLayoutSession.columns === currentTerminalColumns();
|
|
985
|
-
}
|
|
986
|
-
|
|
987
|
-
function widgetHeaderCounts(jobs: AsyncJobState[]): { running: AsyncJobState[]; queued: AsyncJobState[]; complete: AsyncJobState[]; failed: AsyncJobState[]; paused: AsyncJobState[] } {
|
|
988
|
-
return {
|
|
989
|
-
running: jobs.filter((job) => job.status === "running"),
|
|
990
|
-
queued: jobs.filter((job) => job.status === "queued"),
|
|
991
|
-
complete: jobs.filter((job) => job.status === "complete"),
|
|
992
|
-
failed: jobs.filter((job) => job.status === "failed"),
|
|
993
|
-
paused: jobs.filter((job) => job.status === "paused"),
|
|
994
|
-
};
|
|
995
|
-
}
|
|
996
|
-
|
|
997
|
-
function buildSingleLineWidgetLines(jobs: AsyncJobState[], theme: Theme, width: number): string[] {
|
|
998
|
-
const counts = widgetHeaderCounts(jobs);
|
|
999
|
-
const hasActive = counts.running.length > 0 || counts.queued.length > 0;
|
|
1000
|
-
const glyph = counts.running.length > 0 ? runningGlyph(widgetJobsRunningSeed(counts.running)) : hasActive ? "●" : "○";
|
|
1001
|
-
const parts: string[] = [];
|
|
1002
|
-
if (counts.running.length > 0) parts.push(`${counts.running.length}/${jobs.length} running`);
|
|
1003
|
-
if (counts.queued.length > 0) parts.push(`${counts.queued.length} queued`);
|
|
1004
|
-
if (counts.failed.length > 0) parts.push(`${counts.failed.length} failed`);
|
|
1005
|
-
if (counts.paused.length > 0) parts.push(`${counts.paused.length} paused`);
|
|
1006
|
-
if (!hasActive && counts.complete.length > 0) parts.push(`${counts.complete.length}/${jobs.length} done`);
|
|
1007
|
-
return [truncLine(`${theme.fg(hasActive ? "accent" : "dim", glyph)} ${theme.fg(hasActive ? "accent" : "dim", "subagents")} (${parts.join(", ") || `${jobs.length} total`})`, width)];
|
|
1008
|
-
}
|
|
1009
|
-
|
|
1010
|
-
function orderedWidgetJobs(jobs: AsyncJobState[]): AsyncJobState[] {
|
|
1011
|
-
return [
|
|
1012
|
-
...jobs.filter((job) => job.status === "running"),
|
|
1013
|
-
...jobs.filter((job) => job.status === "queued"),
|
|
1014
|
-
...jobs.filter((job) => job.status !== "running" && job.status !== "queued"),
|
|
1015
|
-
];
|
|
1016
|
-
}
|
|
1017
|
-
|
|
1018
|
-
function progressiveJobKey(job: AsyncJobState): string {
|
|
1019
|
-
return job.asyncId;
|
|
1020
|
-
}
|
|
1021
|
-
|
|
1022
|
-
function isProgressiveActiveJob(job: AsyncJobState | undefined): boolean {
|
|
1023
|
-
return job?.status === "running" || job?.status === "queued";
|
|
1024
|
-
}
|
|
1025
|
-
|
|
1026
|
-
function selectProgressiveJobKeys(jobs: AsyncJobState[], previousKeys: string[], bodyRows: number): string[] {
|
|
1027
|
-
if (bodyRows <= 0) return [];
|
|
1028
|
-
const jobsByKey = new Map(jobs.map((job) => [progressiveJobKey(job), job]));
|
|
1029
|
-
const selected: string[] = [];
|
|
1030
|
-
const append = (key: string): void => {
|
|
1031
|
-
if (selected.includes(key) || !jobsByKey.has(key)) return;
|
|
1032
|
-
selected.push(key);
|
|
1033
|
-
};
|
|
1034
|
-
for (const key of previousKeys) {
|
|
1035
|
-
if (!isProgressiveActiveJob(jobsByKey.get(key))) continue;
|
|
1036
|
-
append(key);
|
|
1037
|
-
if (selected.length >= bodyRows) return selected;
|
|
1038
|
-
}
|
|
1039
|
-
for (const job of orderedWidgetJobs(jobs)) {
|
|
1040
|
-
if (!isProgressiveActiveJob(job)) continue;
|
|
1041
|
-
const key = progressiveJobKey(job);
|
|
1042
|
-
append(key);
|
|
1043
|
-
if (selected.length >= bodyRows) break;
|
|
1044
|
-
}
|
|
1045
|
-
if (selected.length >= bodyRows) return selected;
|
|
1046
|
-
for (const key of previousKeys) {
|
|
1047
|
-
if (isProgressiveActiveJob(jobsByKey.get(key))) continue;
|
|
1048
|
-
append(key);
|
|
1049
|
-
if (selected.length >= bodyRows) return selected;
|
|
1050
|
-
}
|
|
1051
|
-
for (const job of orderedWidgetJobs(jobs)) {
|
|
1052
|
-
const key = progressiveJobKey(job);
|
|
1053
|
-
append(key);
|
|
1054
|
-
if (selected.length >= bodyRows) break;
|
|
1055
|
-
}
|
|
1056
|
-
return selected;
|
|
1057
|
-
}
|
|
1058
|
-
|
|
1059
|
-
function progressiveHeaderLine(jobs: AsyncJobState[], theme: Theme, width: number): string {
|
|
1060
|
-
const counts = widgetHeaderCounts(jobs);
|
|
1061
|
-
const hasActive = counts.running.length > 0 || counts.queued.length > 0;
|
|
1062
|
-
const glyph = counts.running.length > 0 ? runningGlyph(widgetJobsRunningSeed(counts.running)) : hasActive ? "●" : "○";
|
|
1063
|
-
const parts: string[] = [];
|
|
1064
|
-
if (counts.running.length > 0) parts.push(formatAgentRunningLabel(counts.running.length));
|
|
1065
|
-
if (counts.queued.length > 0) parts.push(`${counts.queued.length} queued`);
|
|
1066
|
-
if (!hasActive) {
|
|
1067
|
-
if (counts.failed.length > 0) parts.push(`${counts.failed.length} failed`);
|
|
1068
|
-
if (counts.paused.length > 0) parts.push(`${counts.paused.length} paused`);
|
|
1069
|
-
if (counts.complete.length > 0) parts.push(`${counts.complete.length}/${jobs.length} done`);
|
|
1070
|
-
}
|
|
1071
|
-
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);
|
|
1072
|
-
}
|
|
1073
|
-
|
|
1074
|
-
function progressiveJobLine(job: AsyncJobState, theme: Theme, width: number): string {
|
|
1075
|
-
const stats = widgetStats(job, theme);
|
|
1076
|
-
const activity = widgetActivity(job);
|
|
1077
|
-
const status = job.status === "complete" ? "done" : job.status;
|
|
1078
|
-
const parts = [
|
|
1079
|
-
themeBold(theme, widgetJobName(job)),
|
|
1080
|
-
theme.fg("dim", status),
|
|
1081
|
-
stats,
|
|
1082
|
-
activity && activity.toLowerCase() !== status ? theme.fg("dim", activity) : "",
|
|
1083
|
-
].filter(Boolean);
|
|
1084
|
-
return truncLine(` ${widgetStatusGlyph(job, theme)} ${parts.join(` ${theme.fg("dim", "·")} `)}`, width);
|
|
1085
|
-
}
|
|
1086
|
-
|
|
1087
|
-
function progressiveHiddenLine(hiddenJobs: AsyncJobState[], theme: Theme, width: number): string {
|
|
1088
|
-
const counts = widgetHeaderCounts(hiddenJobs);
|
|
1089
|
-
const parts: string[] = [];
|
|
1090
|
-
if (counts.running.length > 0) parts.push(`${counts.running.length} running`);
|
|
1091
|
-
if (counts.queued.length > 0) parts.push(`${counts.queued.length} queued`);
|
|
1092
|
-
const finished = counts.complete.length + counts.failed.length + counts.paused.length;
|
|
1093
|
-
if (finished > 0) parts.push(`${finished} finished`);
|
|
1094
|
-
return truncLine(theme.fg("dim", ` +${hiddenJobs.length} more${parts.length ? ` (${parts.join(", ")})` : ""}`), width);
|
|
1095
|
-
}
|
|
1096
|
-
|
|
1097
|
-
function buildProgressiveWidgetLines(jobs: AsyncJobState[], theme: Theme, width: number, lockedRows: number, previousKeys: string[]): { lines: string[]; visibleJobKeys: string[] } {
|
|
1098
|
-
const rowCount = Math.max(1, lockedRows);
|
|
1099
|
-
if (rowCount === 1) return { lines: buildSingleLineWidgetLines(jobs, theme, width), visibleJobKeys: [] };
|
|
1100
|
-
|
|
1101
|
-
const bodyRows = rowCount - 1;
|
|
1102
|
-
let visibleJobKeys = selectProgressiveJobKeys(jobs, previousKeys, bodyRows);
|
|
1103
|
-
const jobsByKey = new Map(jobs.map((job) => [progressiveJobKey(job), job]));
|
|
1104
|
-
let visibleJobs = visibleJobKeys.map((key) => jobsByKey.get(key)).filter((job): job is AsyncJobState => Boolean(job));
|
|
1105
|
-
let hiddenJobs = jobs.filter((job) => !visibleJobKeys.includes(progressiveJobKey(job)));
|
|
1106
|
-
const needsHiddenLine = hiddenJobs.length > 0;
|
|
1107
|
-
|
|
1108
|
-
if (needsHiddenLine && visibleJobs.length >= bodyRows && bodyRows > 0) {
|
|
1109
|
-
visibleJobs = visibleJobs.slice(0, bodyRows - 1);
|
|
1110
|
-
visibleJobKeys = visibleJobs.map(progressiveJobKey);
|
|
1111
|
-
hiddenJobs = jobs.filter((job) => !visibleJobKeys.includes(progressiveJobKey(job)));
|
|
1112
|
-
}
|
|
1113
|
-
|
|
1114
|
-
const lines = [
|
|
1115
|
-
progressiveHeaderLine(jobs, theme, width),
|
|
1116
|
-
...visibleJobs.map((job) => progressiveJobLine(job, theme, width)),
|
|
1117
|
-
];
|
|
1118
|
-
if (hiddenJobs.length > 0 && lines.length < rowCount) lines.push(progressiveHiddenLine(hiddenJobs, theme, width));
|
|
1119
|
-
while (lines.length < rowCount) lines.push(" ");
|
|
1120
|
-
return { lines: lines.slice(0, rowCount), visibleJobKeys };
|
|
1121
|
-
}
|
|
1122
|
-
|
|
1123
|
-
function collapsedWidgetLineBudget(rows: number): number {
|
|
1124
|
-
return Math.max(10, Math.min(14, Math.floor(rows * 0.35)));
|
|
1125
|
-
}
|
|
1126
|
-
|
|
1127
|
-
function fitWidgetLineBudget(lines: string[], theme: Theme, width: number, expanded: boolean): string[] {
|
|
1128
|
-
const rows = process.stdout.rows || 30;
|
|
1129
|
-
const budget = expanded
|
|
1130
|
-
? Math.max(12, Math.min(24, Math.floor(rows * 0.55)))
|
|
1131
|
-
: collapsedWidgetLineBudget(rows);
|
|
1132
|
-
if (lines.length <= budget) return lines;
|
|
1133
|
-
const visibleLines = Math.max(1, budget - 1);
|
|
1134
|
-
const hiddenCount = lines.length - visibleLines;
|
|
1135
|
-
const hint = expanded
|
|
1136
|
-
? `… ${hiddenCount} live-detail lines hidden`
|
|
1137
|
-
: `… ${hiddenCount} lines hidden · ${liveDetailKeyText()} expands`;
|
|
1138
|
-
return [...lines.slice(0, visibleLines), truncLine(theme.fg("dim", hint), width)];
|
|
1139
|
-
}
|
|
1140
|
-
|
|
1141
|
-
function fitAdaptiveWidgetLines(jobs: AsyncJobState[], lines: string[], theme: Theme, width: number, expanded: boolean): string[] {
|
|
1142
|
-
if (expanded) {
|
|
1143
|
-
resetWidgetLayoutSession();
|
|
1144
|
-
return fitWidgetLineBudget(lines, theme, width, true);
|
|
1145
|
-
}
|
|
1146
|
-
|
|
1147
|
-
const hasMatchingSession = widgetSessionMatches(expanded);
|
|
1148
|
-
const rows = currentTerminalRows();
|
|
1149
|
-
const columns = currentTerminalColumns();
|
|
1150
|
-
const availableRows = estimateAvailableWidgetRows();
|
|
1151
|
-
|
|
1152
|
-
if (hasMatchingSession && widgetLayoutSession?.tier === "single-line") {
|
|
1153
|
-
return buildSingleLineWidgetLines(jobs, theme, width);
|
|
1154
|
-
}
|
|
1155
|
-
|
|
1156
|
-
if (hasMatchingSession && widgetLayoutSession?.tier === "progressive" && widgetLayoutSession.lockedRows !== undefined) {
|
|
1157
|
-
const rendered = buildProgressiveWidgetLines(jobs, theme, width, widgetLayoutSession.lockedRows, widgetLayoutSession.visibleJobKeys);
|
|
1158
|
-
widgetLayoutSession.visibleJobKeys = rendered.visibleJobKeys;
|
|
1159
|
-
return rendered.lines;
|
|
1160
|
-
}
|
|
1161
|
-
|
|
1162
|
-
if (lines.length <= availableRows) {
|
|
1163
|
-
widgetLayoutSession = { expanded, rows, columns, tier: "full", visibleJobKeys: [] };
|
|
1164
|
-
return fitWidgetLineBudget(lines, theme, width, false);
|
|
1165
|
-
}
|
|
1166
|
-
|
|
1167
|
-
if (availableRows <= 2) {
|
|
1168
|
-
widgetLayoutSession = { expanded, rows, columns, tier: "single-line", visibleJobKeys: [] };
|
|
1169
|
-
return buildSingleLineWidgetLines(jobs, theme, width);
|
|
1170
|
-
}
|
|
1171
|
-
|
|
1172
|
-
const lockedRows = Math.min(availableRows, collapsedWidgetLineBudget(rows));
|
|
1173
|
-
const rendered = buildProgressiveWidgetLines(jobs, theme, width, lockedRows, []);
|
|
1174
|
-
widgetLayoutSession = { expanded, rows, columns, tier: "progressive", lockedRows, visibleJobKeys: rendered.visibleJobKeys };
|
|
1175
|
-
return rendered.lines;
|
|
1176
|
-
}
|
|
1177
|
-
|
|
1178
|
-
function buildWidgetComponent(jobs: AsyncJobState[], expanded: boolean): (_tui: unknown, theme: Theme) => Component {
|
|
1179
|
-
return (_tui, theme) => {
|
|
1180
|
-
const width = getTermWidth();
|
|
1181
|
-
const lines = expanded
|
|
1182
|
-
? buildWidgetLines(jobs, theme, width, true)
|
|
1183
|
-
: jobs.length === 1
|
|
1184
|
-
? compactSingleWidgetLines(jobs[0]!, theme, width)
|
|
1185
|
-
: buildWidgetLines(jobs, theme, width, false);
|
|
1186
|
-
const container = new Container();
|
|
1187
|
-
for (const line of fitAdaptiveWidgetLines(jobs, lines, theme, width, expanded)) container.addChild(new Text(line, 1, 0));
|
|
1188
|
-
return container;
|
|
1189
|
-
};
|
|
1190
|
-
}
|
|
1191
|
-
|
|
1192
|
-
export function buildWidgetLines(jobs: AsyncJobState[], theme: Theme, width = getTermWidth(), expanded = false): string[] {
|
|
1193
|
-
if (jobs.length === 0) return [];
|
|
1194
|
-
if (jobs.length === 1) return buildSingleWidgetLines(jobs[0]!, theme, width, expanded);
|
|
1195
|
-
const running = jobs.filter((job) => job.status === "running");
|
|
1196
|
-
const queued = jobs.filter((job) => job.status === "queued");
|
|
1197
|
-
const finished = jobs.filter((job) => job.status !== "running" && job.status !== "queued");
|
|
1198
|
-
|
|
1199
|
-
const lines: string[] = [];
|
|
1200
|
-
const hasActive = running.length > 0 || queued.length > 0;
|
|
1201
|
-
const headerGlyph = running.length > 0 ? runningGlyph(widgetJobsRunningSeed(running)) : hasActive ? "●" : "○";
|
|
1202
|
-
lines.push(truncLine(`${theme.fg(hasActive ? "accent" : "dim", headerGlyph)} ${theme.fg(hasActive ? "accent" : "dim", "Async agents")} ${theme.fg("dim", "· background")}`, width));
|
|
1203
|
-
|
|
1204
|
-
const items: string[][] = [];
|
|
1205
|
-
let hiddenRunning = 0;
|
|
1206
|
-
let hiddenFinished = 0;
|
|
1207
|
-
let queuedSummaryShown = false;
|
|
1208
|
-
let slots = MAX_WIDGET_JOBS;
|
|
1209
|
-
|
|
1210
|
-
for (const job of running) {
|
|
1211
|
-
if (slots <= 0) { hiddenRunning++; continue; }
|
|
1212
|
-
const stats = widgetStats(job, theme);
|
|
1213
|
-
items.push([
|
|
1214
|
-
`${widgetStatusGlyph(job, theme)} ${themeBold(theme, widgetJobName(job))}${stats ? ` ${theme.fg("dim", "·")} ${stats}` : ""}`,
|
|
1215
|
-
` ${theme.fg("dim", `⎿ ${widgetActivity(job)}`)}`,
|
|
1216
|
-
...widgetParallelAgentDetails(job, theme, expanded, width),
|
|
1217
|
-
]);
|
|
1218
|
-
slots--;
|
|
1219
|
-
}
|
|
1220
|
-
|
|
1221
|
-
if (queued.length > 0 && slots > 0) {
|
|
1222
|
-
items.push([`${theme.fg("muted", "◦")} ${theme.fg("dim", `${queued.length} queued`)}`]);
|
|
1223
|
-
queuedSummaryShown = true;
|
|
1224
|
-
slots--;
|
|
1225
|
-
}
|
|
1226
|
-
|
|
1227
|
-
for (const job of finished) {
|
|
1228
|
-
if (slots <= 0) { hiddenFinished++; continue; }
|
|
1229
|
-
const stats = widgetStats(job, theme);
|
|
1230
|
-
items.push([
|
|
1231
|
-
`${widgetStatusGlyph(job, theme)} ${themeBold(theme, widgetJobName(job))}${stats ? ` ${theme.fg("dim", "·")} ${stats}` : ""}`,
|
|
1232
|
-
` ${theme.fg("dim", `⎿ ${widgetActivity(job)}`)}`,
|
|
1233
|
-
...widgetParallelAgentDetails(job, theme, expanded, width),
|
|
1234
|
-
]);
|
|
1235
|
-
slots--;
|
|
1236
|
-
}
|
|
1237
|
-
|
|
1238
|
-
const hiddenQueued = queued.length > 0 && !queuedSummaryShown ? queued.length : 0;
|
|
1239
|
-
const hiddenTotal = hiddenRunning + hiddenFinished + hiddenQueued;
|
|
1240
|
-
if (hiddenTotal > 0) {
|
|
1241
|
-
const parts: string[] = [];
|
|
1242
|
-
if (hiddenRunning > 0) parts.push(`${hiddenRunning} running`);
|
|
1243
|
-
if (hiddenQueued > 0) parts.push(`${hiddenQueued} queued`);
|
|
1244
|
-
if (hiddenFinished > 0) parts.push(`${hiddenFinished} finished`);
|
|
1245
|
-
items.push([theme.fg("dim", `+${hiddenTotal} more (${parts.join(", ")})`)]);
|
|
1246
|
-
}
|
|
1247
|
-
|
|
1248
|
-
for (let i = 0; i < items.length; i++) {
|
|
1249
|
-
const item = items[i]!;
|
|
1250
|
-
const last = i === items.length - 1;
|
|
1251
|
-
const branch = last ? "└─" : "├─";
|
|
1252
|
-
const continuation = last ? " " : "│ ";
|
|
1253
|
-
lines.push(truncLine(`${theme.fg("dim", branch)} ${item[0]}`, width));
|
|
1254
|
-
for (const detail of item.slice(1)) {
|
|
1255
|
-
lines.push(truncLine(`${theme.fg("dim", continuation)} ${detail}`, width));
|
|
1256
|
-
}
|
|
1257
|
-
}
|
|
1258
|
-
|
|
1259
|
-
return lines;
|
|
1260
|
-
}
|
|
1261
|
-
|
|
1262
|
-
/**
|
|
1263
|
-
* Render the async jobs widget
|
|
1264
|
-
*/
|
|
1265
|
-
export function renderWidget(ctx: ExtensionContext, jobs: AsyncJobState[]): void {
|
|
1266
|
-
if (jobs.length === 0) {
|
|
1267
|
-
resetWidgetLayoutSession();
|
|
1268
|
-
if (ctx.hasUI) ctx.ui.setWidget(WIDGET_KEY, undefined);
|
|
1269
|
-
return;
|
|
1270
|
-
}
|
|
1271
|
-
if (!ctx.hasUI) return;
|
|
1272
|
-
ctx.ui.setWidget(WIDGET_KEY, buildWidgetComponent(jobs, ctx.ui.getToolsExpanded?.() ?? false));
|
|
1273
|
-
}
|
|
1274
|
-
|
|
1275
|
-
function renderSingleCompact(d: Details, r: Details["results"][number], theme: Theme, frame?: number): Component {
|
|
1276
|
-
const output = r.truncation?.text || getSingleResultOutput(r);
|
|
1277
|
-
const progress = r.progress || r.progressSummary;
|
|
1278
|
-
const isRunning = r.progress?.status === "running";
|
|
1279
|
-
const contextBadge = d.context === "fork" ? theme.fg("warning", " [fork]") : "";
|
|
1280
|
-
const stats = statJoin(theme, [
|
|
1281
|
-
r.usage?.turns ? `⟳ ${r.usage.turns}` : "",
|
|
1282
|
-
formatProgressStats(theme, progress),
|
|
1283
|
-
]);
|
|
1284
|
-
const c = new Container();
|
|
1285
|
-
const width = getTermWidth() - 4;
|
|
1286
|
-
const modelDisplay = modelThinkingBadge(theme, r.model);
|
|
1287
|
-
c.addChild(new Text(truncLine(`${resultGlyph(r, output, theme, isRunning, undefined, frame)} ${theme.fg("toolTitle", theme.bold(r.agent))}${modelDisplay}${contextBadge}${stats ? ` ${theme.fg("dim", "·")} ${stats}` : ""}`, width), 0, 0));
|
|
1288
|
-
|
|
1289
|
-
if (isRunning && r.progress) {
|
|
1290
|
-
const progressSnapshotNow = snapshotNowForProgress(r.progress);
|
|
1291
|
-
const activity = compactCurrentActivity(r.progress);
|
|
1292
|
-
c.addChild(new Text(truncLine(theme.fg("dim", ` ⎿ ${activity}`), width), 0, 0));
|
|
1293
|
-
const liveStatus = buildLiveStatusLine(r.progress, progressSnapshotNow);
|
|
1294
|
-
if (liveStatus && liveStatus !== activity) c.addChild(new Text(truncLine(theme.fg("dim", ` ${liveStatus}`), width), 0, 0));
|
|
1295
|
-
c.addChild(new Text(truncLine(theme.fg("accent", ` ${liveDetailHintText()}`), width), 0, 0));
|
|
1296
|
-
if (r.artifactPaths) c.addChild(new Text(truncLine(theme.fg("dim", ` output: ${shortenPath(r.artifactPaths.outputPath)}`), width), 0, 0));
|
|
1297
|
-
return c;
|
|
1298
|
-
}
|
|
1299
|
-
|
|
1300
|
-
c.addChild(new Text(truncLine(theme.fg("dim", ` ⎿ ${resultStatusLine(r, output)}`), width), 0, 0));
|
|
1301
|
-
const preview = firstOutputLine(output);
|
|
1302
|
-
if (preview && r.exitCode === 0 && !hasEmptyTextOutputWithoutOutputTarget(r.task, output)) {
|
|
1303
|
-
c.addChild(new Text(truncLine(theme.fg("dim", ` ${preview}`), width), 0, 0));
|
|
1304
|
-
}
|
|
1305
|
-
if (r.sessionFile) c.addChild(new Text(truncLine(theme.fg("dim", ` session: ${shortenPath(r.sessionFile)}`), width), 0, 0));
|
|
1306
|
-
if (r.artifactPaths) c.addChild(new Text(truncLine(theme.fg("dim", ` output: ${shortenPath(r.artifactPaths.outputPath)}`), width), 0, 0));
|
|
1307
|
-
if (r.truncation?.artifactPath) c.addChild(new Text(truncLine(theme.fg("dim", ` full output: ${shortenPath(r.truncation.artifactPath)}`), width), 0, 0));
|
|
1308
|
-
return c;
|
|
1309
|
-
}
|
|
1310
|
-
|
|
1311
|
-
function renderMultiCompact(d: Details, theme: Theme, frame?: number): Component {
|
|
1312
|
-
const hasRunning = d.progress?.some((p) => p.status === "running")
|
|
1313
|
-
|| d.results.some((r) => r.progress?.status === "running")
|
|
1314
|
-
|| workflowGraphHasStatus(d, ["running"]);
|
|
1315
|
-
const failed = d.results.some((r) => r.exitCode !== 0 && r.progress?.status !== "running")
|
|
1316
|
-
|| workflowGraphHasStatus(d, ["failed"]);
|
|
1317
|
-
const paused = d.results.some((r) => (r.interrupted || r.detached) && r.progress?.status !== "running")
|
|
1318
|
-
|| workflowGraphHasStatus(d, ["paused", "detached"]);
|
|
1319
|
-
let totalSummary = d.progressSummary;
|
|
1320
|
-
if (!totalSummary) {
|
|
1321
|
-
let sawProgress = false;
|
|
1322
|
-
const summary = { toolCount: 0, tokens: 0, durationMs: 0 };
|
|
1323
|
-
for (const r of d.results) {
|
|
1324
|
-
const prog = r.progress || r.progressSummary;
|
|
1325
|
-
if (!prog) continue;
|
|
1326
|
-
sawProgress = true;
|
|
1327
|
-
summary.toolCount += prog.toolCount;
|
|
1328
|
-
summary.tokens += prog.tokens;
|
|
1329
|
-
summary.durationMs = d.mode === "chain" ? summary.durationMs + prog.durationMs : Math.max(summary.durationMs, prog.durationMs);
|
|
1330
|
-
}
|
|
1331
|
-
if (sawProgress) totalSummary = summary;
|
|
1332
|
-
}
|
|
1333
|
-
const multiLabel = buildMultiProgressLabel(d, hasRunning);
|
|
1334
|
-
const itemTitle = multiLabel.itemTitle;
|
|
1335
|
-
const stats = statJoin(theme, [multiLabel.headerLabel, formatProgressStats(theme, totalSummary), formatTotalCostStat(d.totalCost)]);
|
|
1336
|
-
const glyph = hasRunning
|
|
1337
|
-
? theme.fg("accent", runningGlyph(frame !== undefined ? (runningSeed(progressRunningSeed(totalSummary), d.currentStepIndex) ?? 0) + frame : runningSeed(progressRunningSeed(totalSummary), d.currentStepIndex)))
|
|
1338
|
-
: failed
|
|
1339
|
-
? theme.fg("error", "✗")
|
|
1340
|
-
: paused
|
|
1341
|
-
? theme.fg("warning", "■")
|
|
1342
|
-
: theme.fg("success", "✓");
|
|
1343
|
-
const contextBadge = d.context === "fork" ? theme.fg("warning", " [fork]") : "";
|
|
1344
|
-
const c = new Container();
|
|
1345
|
-
const width = getTermWidth() - 4;
|
|
1346
|
-
c.addChild(new Text(truncLine(`${glyph} ${theme.fg("toolTitle", theme.bold(d.mode))}${contextBadge}${stats ? ` ${theme.fg("dim", "·")} ${stats}` : ""}`, width), 0, 0));
|
|
1347
|
-
|
|
1348
|
-
const useResultsDirectly = multiLabel.hasParallelInChain || !d.chainAgents?.length;
|
|
1349
|
-
const displayStart = multiLabel.showActiveGroupOnly ? multiLabel.groupStartIndex : 0;
|
|
1350
|
-
const displayEnd = multiLabel.showActiveGroupOnly ? multiLabel.groupEndIndex : (useResultsDirectly ? d.results.length : d.chainAgents!.length);
|
|
1351
|
-
const chainEntries = buildChainRenderEntries(d, multiLabel);
|
|
1352
|
-
const renderEntries = chainEntries ?? Array.from({ length: displayEnd - displayStart }, (_, offset): ChainRenderEntry => {
|
|
1353
|
-
const i = displayStart + offset;
|
|
1354
|
-
const r = d.results[i];
|
|
1355
|
-
const fallbackLabel = itemTitle.toLowerCase();
|
|
1356
|
-
const rowNumber = multiLabel.showActiveGroupOnly ? (i - multiLabel.groupStartIndex + 1) : (i + 1);
|
|
1357
|
-
return { kind: "result", resultIndex: i, rowNumber, agentName: useResultsDirectly ? (r?.agent || `${fallbackLabel}-${rowNumber}`) : (d.chainAgents![i] || r?.agent || `${fallbackLabel}-${rowNumber}`) };
|
|
1358
|
-
});
|
|
1359
|
-
for (const entry of renderEntries) {
|
|
1360
|
-
if (entry.kind === "placeholder") {
|
|
1361
|
-
const glyph = widgetStepGlyph(entry.status as AsyncJobStep["status"], theme);
|
|
1362
|
-
const statusLabel = widgetStepStatus(entry.status as AsyncJobStep["status"], theme);
|
|
1363
|
-
c.addChild(new Text(truncLine(` ${glyph} ${entry.stepLabel}: ${themeBold(theme, entry.agentName)} ${theme.fg("dim", "·")} ${statusLabel}`, width), 0, 0));
|
|
1364
|
-
if (entry.error) c.addChild(new Text(truncLine(theme.fg("error", ` ⎿ Error: ${entry.error}`), width), 0, 0));
|
|
1365
|
-
continue;
|
|
1366
|
-
}
|
|
1367
|
-
const i = entry.resultIndex;
|
|
1368
|
-
const r = d.results[i];
|
|
1369
|
-
const rowNumber = entry.rowNumber;
|
|
1370
|
-
const agentName = entry.agentName;
|
|
1371
|
-
if (!r) {
|
|
1372
|
-
const pendingLabel = chainEntries ? resultRowLabel(d, multiLabel, i, rowNumber) : `${itemTitle} ${rowNumber}`;
|
|
1373
|
-
c.addChild(new Text(truncLine(theme.fg("dim", ` ◦ ${pendingLabel}: ${agentName} · pending`), width), 0, 0));
|
|
1374
|
-
continue;
|
|
1375
|
-
}
|
|
1376
|
-
const output = getSingleResultOutput(r);
|
|
1377
|
-
const progressFromArray = d.progress?.find((p) => p.index === i) || d.progress?.find((p) => p.agent === r.agent && p.status === "running");
|
|
1378
|
-
const rProg = r.progress || progressFromArray || r.progressSummary;
|
|
1379
|
-
const rRunning = rProg && "status" in rProg && rProg.status === "running";
|
|
1380
|
-
const rPending = rProg && "status" in rProg && rProg.status === "pending";
|
|
1381
|
-
const stepNumber = r.progress?.index !== undefined ? r.progress.index + 1 : progressFromArray?.index !== undefined ? progressFromArray.index + 1 : i + 1;
|
|
1382
|
-
const stepStats = formatProgressStats(theme, rProg);
|
|
1383
|
-
const glyph = rPending ? theme.fg("dim", "◦") : resultGlyph(r, output, theme, rRunning, progressRunningSeed(rProg), frame);
|
|
1384
|
-
const pendingLabel = rPending ? ` ${theme.fg("dim", "· pending")}` : "";
|
|
1385
|
-
const stepLabel = resultRowLabel(d, multiLabel, i, stepNumber);
|
|
1386
|
-
const line = `${glyph} ${stepLabel}: ${themeBold(theme, agentName)}${stepStats ? ` ${theme.fg("dim", "·")} ${stepStats}` : ""}${pendingLabel}`;
|
|
1387
|
-
c.addChild(new Text(truncLine(` ${line}`, width), 0, 0));
|
|
1388
|
-
if (rRunning && rProg && "status" in rProg) {
|
|
1389
|
-
const activity = compactCurrentActivity(rProg);
|
|
1390
|
-
c.addChild(new Text(truncLine(theme.fg("dim", ` ⎿ ${activity}`), width), 0, 0));
|
|
1391
|
-
c.addChild(new Text(truncLine(theme.fg("accent", ` ${liveDetailHintText()}`), width), 0, 0));
|
|
1392
|
-
} else if (!rPending && (r.exitCode !== 0 || r.interrupted || r.detached || hasEmptyTextOutputWithoutOutputTarget(r.task, output))) {
|
|
1393
|
-
c.addChild(new Text(truncLine(theme.fg(r.exitCode !== 0 ? "error" : "dim", ` ⎿ ${resultStatusLine(r, output)}`), width), 0, 0));
|
|
1394
|
-
}
|
|
1395
|
-
const outputTarget = extractOutputTarget(r.task);
|
|
1396
|
-
if (outputTarget) c.addChild(new Text(truncLine(theme.fg("dim", ` output: ${outputTarget}`), width), 0, 0));
|
|
1397
|
-
if (r.artifactPaths) c.addChild(new Text(truncLine(theme.fg("dim", ` output: ${shortenPath(r.artifactPaths.outputPath)}`), width), 0, 0));
|
|
1398
|
-
}
|
|
1399
|
-
if (d.artifacts) c.addChild(new Text(truncLine(theme.fg("dim", ` artifacts: ${shortenPath(d.artifacts.dir)}`), width), 0, 0));
|
|
1400
|
-
return c;
|
|
1401
|
-
}
|
|
1402
|
-
|
|
1403
|
-
/**
|
|
1404
|
-
* Render a subagent result
|
|
1405
|
-
*/
|
|
1406
|
-
export function renderSubagentResult(
|
|
1407
|
-
result: AgentToolResult<Details>,
|
|
1408
|
-
options: { expanded: boolean },
|
|
1409
|
-
theme: Theme,
|
|
1410
|
-
frame?: number,
|
|
1411
|
-
): Component {
|
|
1412
|
-
const d = result.details;
|
|
1413
|
-
if (!d || !d.results.length) {
|
|
1414
|
-
const t = result.content[0];
|
|
1415
|
-
const text = t?.type === "text" ? t.text : "(no output)";
|
|
1416
|
-
const contextPrefix = d?.context === "fork" ? `${theme.fg("warning", "[fork]")} ` : "";
|
|
1417
|
-
const width = getTermWidth() - 4;
|
|
1418
|
-
if (!text.includes("\n")) return new Text(truncLine(`${contextPrefix}${text}`, width), 0, 0);
|
|
1419
|
-
const c = new Container();
|
|
1420
|
-
const wrapped = wrapPlainText(`${contextPrefix}${text}`, width);
|
|
1421
|
-
for (const line of wrapped) c.addChild(new Text(line, 0, 0));
|
|
1422
|
-
return c;
|
|
1423
|
-
}
|
|
1424
|
-
|
|
1425
|
-
const expanded = options.expanded;
|
|
1426
|
-
const mdTheme = getMarkdownTheme();
|
|
1427
|
-
|
|
1428
|
-
if (d.mode === "single" && d.results.length === 1) {
|
|
1429
|
-
const r = d.results[0];
|
|
1430
|
-
if (!expanded) return renderSingleCompact(d, r, theme, frame);
|
|
1431
|
-
const isRunning = r.progress?.status === "running";
|
|
1432
|
-
const icon = isRunning
|
|
1433
|
-
? theme.fg("warning", "running")
|
|
1434
|
-
: r.detached
|
|
1435
|
-
? theme.fg("warning", "detached")
|
|
1436
|
-
: r.exitCode === 0
|
|
1437
|
-
? theme.fg("success", "ok")
|
|
1438
|
-
: theme.fg("error", "failed");
|
|
1439
|
-
const contextBadge = d.context === "fork" ? theme.fg("warning", " [fork]") : "";
|
|
1440
|
-
const output = r.truncation?.text || getSingleResultOutput(r);
|
|
1441
|
-
|
|
1442
|
-
const progressInfo = isRunning && r.progress
|
|
1443
|
-
? ` | ${r.progress.toolCount} tools, ${formatTokens(r.progress.tokens)} tok, ${formatDuration(r.progress.durationMs)}`
|
|
1444
|
-
: r.progressSummary
|
|
1445
|
-
? ` | ${r.progressSummary.toolCount} tools, ${formatTokens(r.progressSummary.tokens)} tok, ${formatDuration(r.progressSummary.durationMs)}`
|
|
1446
|
-
: "";
|
|
1447
|
-
|
|
1448
|
-
const w = getTermWidth() - 4;
|
|
1449
|
-
const fit = (text: string) => expanded ? text : truncLine(text, w);
|
|
1450
|
-
const toolCallLines = getToolCallLines(r, expanded);
|
|
1451
|
-
const c = new Container();
|
|
1452
|
-
c.addChild(new Text(fit(`${icon} ${theme.fg("toolTitle", theme.bold(r.agent))}${contextBadge}${progressInfo}`), 0, 0));
|
|
1453
|
-
c.addChild(new Spacer(1));
|
|
1454
|
-
const taskMaxLen = Math.max(20, w - 8);
|
|
1455
|
-
const taskPreview = expanded || r.task.length <= taskMaxLen
|
|
1456
|
-
? r.task
|
|
1457
|
-
: `${r.task.slice(0, taskMaxLen)}...`;
|
|
1458
|
-
c.addChild(
|
|
1459
|
-
new Text(fit(theme.fg("dim", `Task: ${taskPreview}`)), 0, 0),
|
|
1460
|
-
);
|
|
1461
|
-
c.addChild(new Spacer(1));
|
|
1462
|
-
|
|
1463
|
-
if (isRunning && r.progress) {
|
|
1464
|
-
const progressSnapshotNow = snapshotNowForProgress(r.progress);
|
|
1465
|
-
const toolLine = formatCurrentToolLine(r.progress, w, expanded, progressSnapshotNow);
|
|
1466
|
-
if (toolLine) {
|
|
1467
|
-
c.addChild(new Text(fit(theme.fg("warning", `> ${toolLine}`)), 0, 0));
|
|
1468
|
-
}
|
|
1469
|
-
const liveStatusLine = buildLiveStatusLine(r.progress, progressSnapshotNow);
|
|
1470
|
-
if (liveStatusLine) {
|
|
1471
|
-
c.addChild(new Text(fit(theme.fg("accent", liveStatusLine)), 0, 0));
|
|
1472
|
-
}
|
|
1473
|
-
c.addChild(new Text(fit(theme.fg("accent", liveDetailHintText())), 0, 0));
|
|
1474
|
-
if (r.artifactPaths) {
|
|
1475
|
-
c.addChild(new Text(fit(theme.fg("dim", `Artifacts: ${shortenPath(r.artifactPaths.outputPath)}`)), 0, 0));
|
|
1476
|
-
}
|
|
1477
|
-
if (r.progress.recentTools?.length) {
|
|
1478
|
-
for (const t of r.progress.recentTools.slice(-3)) {
|
|
1479
|
-
const maxArgsLen = Math.max(40, w - 24);
|
|
1480
|
-
const argsPreview = expanded || t.args.length <= maxArgsLen
|
|
1481
|
-
? t.args
|
|
1482
|
-
: `${t.args.slice(0, maxArgsLen)}...`;
|
|
1483
|
-
c.addChild(new Text(fit(theme.fg("dim", `${t.tool}: ${argsPreview}`)), 0, 0));
|
|
1484
|
-
}
|
|
1485
|
-
}
|
|
1486
|
-
for (const line of (r.progress.recentOutput ?? []).slice(-5)) {
|
|
1487
|
-
c.addChild(new Text(fit(theme.fg("dim", ` ${line}`)), 0, 0));
|
|
1488
|
-
}
|
|
1489
|
-
if (toolLine || liveStatusLine || r.progress.recentTools?.length || r.progress.recentOutput?.length || r.artifactPaths) {
|
|
1490
|
-
c.addChild(new Spacer(1));
|
|
1491
|
-
}
|
|
1492
|
-
}
|
|
1493
|
-
|
|
1494
|
-
if (expanded) {
|
|
1495
|
-
for (const line of toolCallLines) {
|
|
1496
|
-
c.addChild(new Text(fit(theme.fg("muted", line)), 0, 0));
|
|
1497
|
-
}
|
|
1498
|
-
if (toolCallLines.length) c.addChild(new Spacer(1));
|
|
1499
|
-
}
|
|
1500
|
-
|
|
1501
|
-
if (output) c.addChild(new Markdown(output, 0, 0, mdTheme));
|
|
1502
|
-
c.addChild(new Spacer(1));
|
|
1503
|
-
if (r.skills?.length) {
|
|
1504
|
-
c.addChild(new Text(fit(theme.fg("dim", `Skills: ${r.skills.join(", ")}`)), 0, 0));
|
|
1505
|
-
}
|
|
1506
|
-
if (r.skillsWarning) {
|
|
1507
|
-
c.addChild(new Text(fit(theme.fg("warning", `Warning: ${r.skillsWarning}`)), 0, 0));
|
|
1508
|
-
}
|
|
1509
|
-
if (r.attemptedModels && r.attemptedModels.length > 1) {
|
|
1510
|
-
c.addChild(new Text(fit(theme.fg("dim", `Fallbacks: ${r.attemptedModels.join(" → ")}`)), 0, 0));
|
|
1511
|
-
}
|
|
1512
|
-
c.addChild(new Text(fit(theme.fg("dim", formatUsage(r.usage, r.model))), 0, 0));
|
|
1513
|
-
if (r.sessionFile) {
|
|
1514
|
-
c.addChild(new Text(fit(theme.fg("dim", `Session: ${shortenPath(r.sessionFile)}`)), 0, 0));
|
|
1515
|
-
}
|
|
1516
|
-
|
|
1517
|
-
if (!isRunning && r.artifactPaths) {
|
|
1518
|
-
c.addChild(new Spacer(1));
|
|
1519
|
-
c.addChild(new Text(fit(theme.fg("dim", `Artifacts: ${shortenPath(r.artifactPaths.outputPath)}`)), 0, 0));
|
|
1520
|
-
}
|
|
1521
|
-
return c;
|
|
1522
|
-
}
|
|
1523
|
-
|
|
1524
|
-
if (!expanded) return renderMultiCompact(d, theme, frame);
|
|
1525
|
-
|
|
1526
|
-
const hasRunning = d.progress?.some((p) => p.status === "running")
|
|
1527
|
-
|| d.results.some((r) => r.progress?.status === "running")
|
|
1528
|
-
|| workflowGraphHasStatus(d, ["running"]);
|
|
1529
|
-
const ok = d.results.filter((r) => r.progress?.status === "completed" || (r.exitCode === 0 && r.progress?.status !== "running")).length;
|
|
1530
|
-
const hasEmptyWithoutTarget = d.results.some((r) =>
|
|
1531
|
-
r.exitCode === 0
|
|
1532
|
-
&& r.progress?.status !== "running"
|
|
1533
|
-
&& hasEmptyTextOutputWithoutOutputTarget(r.task, getSingleResultOutput(r)),
|
|
1534
|
-
);
|
|
1535
|
-
const hasWorkflowFailure = workflowGraphHasStatus(d, ["failed"]);
|
|
1536
|
-
const hasWorkflowPause = workflowGraphHasStatus(d, ["paused", "detached"]);
|
|
1537
|
-
const icon = hasRunning
|
|
1538
|
-
? theme.fg("warning", "running")
|
|
1539
|
-
: hasEmptyWithoutTarget
|
|
1540
|
-
? theme.fg("warning", "warning")
|
|
1541
|
-
: hasWorkflowFailure
|
|
1542
|
-
? theme.fg("error", "failed")
|
|
1543
|
-
: hasWorkflowPause
|
|
1544
|
-
? theme.fg("warning", "paused")
|
|
1545
|
-
: ok === d.results.length
|
|
1546
|
-
? theme.fg("success", "ok")
|
|
1547
|
-
: theme.fg("error", "failed");
|
|
1548
|
-
|
|
1549
|
-
const totalSummary =
|
|
1550
|
-
d.progressSummary ||
|
|
1551
|
-
d.results.reduce(
|
|
1552
|
-
(acc, r) => {
|
|
1553
|
-
const prog = r.progress || r.progressSummary;
|
|
1554
|
-
if (prog) {
|
|
1555
|
-
acc.toolCount += prog.toolCount;
|
|
1556
|
-
acc.tokens += prog.tokens;
|
|
1557
|
-
acc.durationMs =
|
|
1558
|
-
d.mode === "chain"
|
|
1559
|
-
? acc.durationMs + prog.durationMs
|
|
1560
|
-
: Math.max(acc.durationMs, prog.durationMs);
|
|
1561
|
-
}
|
|
1562
|
-
return acc;
|
|
1563
|
-
},
|
|
1564
|
-
{ toolCount: 0, tokens: 0, durationMs: 0 },
|
|
1565
|
-
);
|
|
1566
|
-
|
|
1567
|
-
const summaryParts = [
|
|
1568
|
-
totalSummary.toolCount || totalSummary.tokens
|
|
1569
|
-
? `${totalSummary.toolCount} tools, ${formatTokens(totalSummary.tokens)} tok, ${formatDuration(totalSummary.durationMs)}`
|
|
1570
|
-
: "",
|
|
1571
|
-
formatTotalCostStat(d.totalCost),
|
|
1572
|
-
].filter(Boolean);
|
|
1573
|
-
const summaryStr = summaryParts.length ? ` | ${summaryParts.join(", ")}` : "";
|
|
1574
|
-
|
|
1575
|
-
const modeLabel = d.mode;
|
|
1576
|
-
const contextBadge = d.context === "fork" ? theme.fg("warning", " [fork]") : "";
|
|
1577
|
-
const multiLabel = buildMultiProgressLabel(d, hasRunning);
|
|
1578
|
-
const itemTitle = multiLabel.itemTitle;
|
|
1579
|
-
|
|
1580
|
-
const chainVis = d.chainAgents?.length && !multiLabel.hasParallelInChain
|
|
1581
|
-
? d.chainAgents
|
|
1582
|
-
.map((agent, i) => {
|
|
1583
|
-
const result = d.results[i];
|
|
1584
|
-
const isFailed = result && result.exitCode !== 0 && result.progress?.status !== "running";
|
|
1585
|
-
const isComplete = result && result.exitCode === 0 && result.progress?.status !== "running";
|
|
1586
|
-
const isEmptyWithoutTarget = Boolean(result)
|
|
1587
|
-
&& Boolean(isComplete)
|
|
1588
|
-
&& hasEmptyTextOutputWithoutOutputTarget(result.task, getSingleResultOutput(result));
|
|
1589
|
-
const isCurrent = i === (d.currentStepIndex ?? d.results.length);
|
|
1590
|
-
const stepIcon = isFailed
|
|
1591
|
-
? theme.fg("error", "failed")
|
|
1592
|
-
: isEmptyWithoutTarget
|
|
1593
|
-
? theme.fg("warning", "warning")
|
|
1594
|
-
: isComplete
|
|
1595
|
-
? theme.fg("success", "done")
|
|
1596
|
-
: isCurrent && hasRunning
|
|
1597
|
-
? theme.fg("warning", "running")
|
|
1598
|
-
: theme.fg("dim", "pending");
|
|
1599
|
-
return `${stepIcon} ${agent}`;
|
|
1600
|
-
})
|
|
1601
|
-
.join(theme.fg("dim", " → "))
|
|
1602
|
-
: null;
|
|
1603
|
-
|
|
1604
|
-
const w = getTermWidth() - 4;
|
|
1605
|
-
const fit = (text: string) => expanded ? text : truncLine(text, w);
|
|
1606
|
-
const c = new Container();
|
|
1607
|
-
c.addChild(
|
|
1608
|
-
new Text(
|
|
1609
|
-
fit(`${icon} ${theme.fg("toolTitle", theme.bold(modeLabel))}${contextBadge} · ${multiLabel.headerLabel}${summaryStr}`),
|
|
1610
|
-
0,
|
|
1611
|
-
0,
|
|
1612
|
-
),
|
|
1613
|
-
);
|
|
1614
|
-
if (chainVis) {
|
|
1615
|
-
c.addChild(new Text(fit(` ${chainVis}`), 0, 0));
|
|
1616
|
-
}
|
|
1617
|
-
|
|
1618
|
-
const useResultsDirectly = multiLabel.hasParallelInChain || !d.chainAgents?.length;
|
|
1619
|
-
const displayStart = multiLabel.showActiveGroupOnly ? multiLabel.groupStartIndex : 0;
|
|
1620
|
-
const displayEnd = multiLabel.showActiveGroupOnly ? multiLabel.groupEndIndex : (useResultsDirectly ? d.results.length : d.chainAgents!.length);
|
|
1621
|
-
const chainEntries = buildChainRenderEntries(d, multiLabel);
|
|
1622
|
-
const renderEntries = chainEntries ?? Array.from({ length: displayEnd - displayStart }, (_, offset): ChainRenderEntry => {
|
|
1623
|
-
const i = displayStart + offset;
|
|
1624
|
-
const r = d.results[i];
|
|
1625
|
-
const rowNumber = multiLabel.showActiveGroupOnly ? (i - multiLabel.groupStartIndex + 1) : (i + 1);
|
|
1626
|
-
return { kind: "result", resultIndex: i, rowNumber, agentName: useResultsDirectly ? (r?.agent || `step-${rowNumber}`) : (d.chainAgents![i] || r?.agent || `step-${rowNumber}`) };
|
|
1627
|
-
});
|
|
1628
|
-
|
|
1629
|
-
c.addChild(new Spacer(1));
|
|
1630
|
-
|
|
1631
|
-
for (const entry of renderEntries) {
|
|
1632
|
-
if (entry.kind === "placeholder") {
|
|
1633
|
-
const statusLabel = widgetStepStatus(entry.status as AsyncJobStep["status"], theme);
|
|
1634
|
-
c.addChild(new Text(fit(` ${statusLabel} ${entry.stepLabel}: ${theme.bold(entry.agentName)}`), 0, 0));
|
|
1635
|
-
c.addChild(new Text(theme.fg(entry.status === "failed" ? "error" : "dim", ` status: ${entry.status}`), 0, 0));
|
|
1636
|
-
if (entry.error) c.addChild(new Text(theme.fg("error", ` error: ${entry.error}`), 0, 0));
|
|
1637
|
-
c.addChild(new Spacer(1));
|
|
1638
|
-
continue;
|
|
1639
|
-
}
|
|
1640
|
-
const i = entry.resultIndex;
|
|
1641
|
-
const r = d.results[i];
|
|
1642
|
-
const rowNumber = entry.rowNumber;
|
|
1643
|
-
const agentName = entry.agentName;
|
|
1644
|
-
|
|
1645
|
-
if (!r) {
|
|
1646
|
-
const pendingLabel = chainEntries ? resultRowLabel(d, multiLabel, i, rowNumber) : `${itemTitle} ${rowNumber}`;
|
|
1647
|
-
c.addChild(new Text(fit(theme.fg("dim", ` ${pendingLabel}: ${agentName}`)), 0, 0));
|
|
1648
|
-
c.addChild(new Text(theme.fg("dim", ` status: pending`), 0, 0));
|
|
1649
|
-
c.addChild(new Spacer(1));
|
|
1650
|
-
continue;
|
|
1651
|
-
}
|
|
1652
|
-
|
|
1653
|
-
const progressFromArray = d.progress?.find((p) => p.index === i)
|
|
1654
|
-
|| d.progress?.find((p) => p.agent === r.agent && p.status === "running");
|
|
1655
|
-
const rProg = r.progress || progressFromArray || r.progressSummary;
|
|
1656
|
-
const rRunning = rProg?.status === "running";
|
|
1657
|
-
const stepNumber = typeof rProg?.index === "number" ? rProg.index + 1 : i + 1;
|
|
1658
|
-
|
|
1659
|
-
const resultOutput = getSingleResultOutput(r);
|
|
1660
|
-
const statusIcon = rRunning
|
|
1661
|
-
? theme.fg("warning", "running")
|
|
1662
|
-
: r.exitCode !== 0
|
|
1663
|
-
? theme.fg("error", "failed")
|
|
1664
|
-
: hasEmptyTextOutputWithoutOutputTarget(r.task, resultOutput)
|
|
1665
|
-
? theme.fg("warning", "warning")
|
|
1666
|
-
: theme.fg("success", "done");
|
|
1667
|
-
const stats = rProg ? ` | ${rProg.toolCount} tools, ${formatDuration(rProg.durationMs)}` : "";
|
|
1668
|
-
const modelDisplay = modelThinkingBadge(theme, r.model);
|
|
1669
|
-
const stepLabel = resultRowLabel(d, multiLabel, i, stepNumber);
|
|
1670
|
-
const stepHeader = rRunning
|
|
1671
|
-
? `${statusIcon} ${stepLabel}: ${theme.bold(theme.fg("warning", r.agent))}${modelDisplay}${stats}`
|
|
1672
|
-
: `${statusIcon} ${stepLabel}: ${theme.bold(r.agent)}${modelDisplay}${stats}`;
|
|
1673
|
-
const toolCallLines = getToolCallLines(r, expanded);
|
|
1674
|
-
c.addChild(new Text(fit(stepHeader), 0, 0));
|
|
1675
|
-
|
|
1676
|
-
const taskMaxLen = Math.max(20, w - 12);
|
|
1677
|
-
const taskPreview = expanded || r.task.length <= taskMaxLen
|
|
1678
|
-
? r.task
|
|
1679
|
-
: `${r.task.slice(0, taskMaxLen)}...`;
|
|
1680
|
-
c.addChild(new Text(fit(theme.fg("dim", ` task: ${taskPreview}`)), 0, 0));
|
|
1681
|
-
|
|
1682
|
-
const outputTarget = extractOutputTarget(r.task);
|
|
1683
|
-
if (outputTarget) {
|
|
1684
|
-
c.addChild(new Text(fit(theme.fg("dim", ` output: ${outputTarget}`)), 0, 0));
|
|
1685
|
-
}
|
|
1686
|
-
|
|
1687
|
-
if (r.skills?.length) {
|
|
1688
|
-
c.addChild(new Text(fit(theme.fg("dim", ` skills: ${r.skills.join(", ")}`)), 0, 0));
|
|
1689
|
-
}
|
|
1690
|
-
if (r.skillsWarning) {
|
|
1691
|
-
c.addChild(new Text(fit(theme.fg("warning", ` Warning: ${r.skillsWarning}`)), 0, 0));
|
|
1692
|
-
}
|
|
1693
|
-
if (r.attemptedModels && r.attemptedModels.length > 1) {
|
|
1694
|
-
c.addChild(new Text(fit(theme.fg("dim", ` fallbacks: ${r.attemptedModels.join(" → ")}`)), 0, 0));
|
|
1695
|
-
}
|
|
1696
|
-
|
|
1697
|
-
if (rRunning && rProg) {
|
|
1698
|
-
if (rProg.skills?.length) {
|
|
1699
|
-
c.addChild(new Text(fit(theme.fg("accent", ` skills: ${rProg.skills.join(", ")}`)), 0, 0));
|
|
1700
|
-
}
|
|
1701
|
-
const progressSnapshotNow = snapshotNowForProgress(rProg);
|
|
1702
|
-
const toolLine = formatCurrentToolLine(rProg, w, expanded, progressSnapshotNow);
|
|
1703
|
-
if (toolLine) {
|
|
1704
|
-
c.addChild(new Text(fit(theme.fg("warning", ` > ${toolLine}`)), 0, 0));
|
|
1705
|
-
}
|
|
1706
|
-
const liveStatusLine = buildLiveStatusLine(rProg, progressSnapshotNow);
|
|
1707
|
-
if (liveStatusLine) {
|
|
1708
|
-
c.addChild(new Text(fit(theme.fg("accent", ` ${liveStatusLine}`)), 0, 0));
|
|
1709
|
-
}
|
|
1710
|
-
c.addChild(new Text(fit(theme.fg("accent", ` ${liveDetailHintText()}`)), 0, 0));
|
|
1711
|
-
if (r.artifactPaths) {
|
|
1712
|
-
c.addChild(new Text(fit(theme.fg("dim", ` artifacts: ${shortenPath(r.artifactPaths.outputPath)}`)), 0, 0));
|
|
1713
|
-
}
|
|
1714
|
-
if (rProg.recentTools?.length) {
|
|
1715
|
-
for (const t of rProg.recentTools.slice(-3)) {
|
|
1716
|
-
const maxArgsLen = Math.max(40, w - 30);
|
|
1717
|
-
const argsPreview = expanded || t.args.length <= maxArgsLen
|
|
1718
|
-
? t.args
|
|
1719
|
-
: `${t.args.slice(0, maxArgsLen)}...`;
|
|
1720
|
-
c.addChild(new Text(fit(theme.fg("dim", ` ${t.tool}: ${argsPreview}`)), 0, 0));
|
|
1721
|
-
}
|
|
1722
|
-
}
|
|
1723
|
-
const recentLines = (rProg.recentOutput ?? []).slice(-5);
|
|
1724
|
-
for (const line of recentLines) {
|
|
1725
|
-
c.addChild(new Text(fit(theme.fg("dim", ` ${line}`)), 0, 0));
|
|
1726
|
-
}
|
|
1727
|
-
}
|
|
1728
|
-
|
|
1729
|
-
if (!rRunning && r.artifactPaths) {
|
|
1730
|
-
c.addChild(new Text(fit(theme.fg("dim", ` artifacts: ${shortenPath(r.artifactPaths.outputPath)}`)), 0, 0));
|
|
1731
|
-
}
|
|
1732
|
-
|
|
1733
|
-
if (expanded && !rRunning) {
|
|
1734
|
-
for (const line of toolCallLines) {
|
|
1735
|
-
c.addChild(new Text(fit(theme.fg("muted", ` ${line}`)), 0, 0));
|
|
1736
|
-
}
|
|
1737
|
-
if (toolCallLines.length) c.addChild(new Spacer(1));
|
|
1738
|
-
}
|
|
1739
|
-
|
|
1740
|
-
c.addChild(new Spacer(1));
|
|
1741
|
-
}
|
|
1742
|
-
|
|
1743
|
-
if (d.artifacts) {
|
|
1744
|
-
c.addChild(new Spacer(1));
|
|
1745
|
-
c.addChild(new Text(fit(theme.fg("dim", `Artifacts dir: ${shortenPath(d.artifacts.dir)}`)), 0, 0));
|
|
1746
|
-
}
|
|
1747
|
-
return c;
|
|
1748
|
-
}
|