@fitchmultz/pi-subagents 0.0.0-stage → 0.44.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/CHANGELOG.md +1654 -0
- package/LICENSE +21 -0
- package/README.md +1533 -2
- package/agents/context-builder.md +97 -0
- package/agents/debugger.md +51 -0
- package/agents/delegate.md +13 -0
- package/agents/fixer.md +37 -0
- package/agents/oracle.md +71 -0
- package/agents/planner.md +72 -0
- package/agents/researcher.md +51 -0
- package/agents/reviewer-claude.md +69 -0
- package/agents/reviewer-gpt.md +68 -0
- package/agents/reviewer-ponytail.md +82 -0
- package/agents/reviewer-security.md +81 -0
- package/agents/reviewer.md +69 -0
- package/agents/scout.md +66 -0
- package/agents/ui-designer.md +51 -0
- package/agents/watcher.md +26 -0
- package/agents/worker.md +46 -0
- package/agents/writer.md +36 -0
- package/dist/agents/agent-management.js +923 -0
- package/dist/agents/agent-scope.js +7 -0
- package/dist/agents/agent-selection.js +20 -0
- package/dist/agents/agent-serializer.js +100 -0
- package/dist/agents/agents.js +752 -0
- package/dist/agents/chain-serializer.js +367 -0
- package/dist/agents/frontmatter.js +21 -0
- package/dist/agents/identity.js +29 -0
- package/dist/agents/skills.js +570 -0
- package/dist/extension/build-info.js +1 -0
- package/dist/extension/compact-tools.js +112 -0
- package/dist/extension/config.js +22 -0
- package/dist/extension/control-notices.js +29 -0
- package/dist/extension/doctor.js +143 -0
- package/dist/extension/fanout-child.js +326 -0
- package/dist/extension/index.js +577 -0
- package/dist/extension/schemas.js +416 -0
- package/dist/extension/tool-input.js +20 -0
- package/dist/extension/tool-result.js +14 -0
- package/dist/history/canonical-result.js +81 -0
- package/dist/history/database.js +72 -0
- package/dist/history/index.js +199 -0
- package/dist/history/ingest.js +468 -0
- package/dist/history/queries.js +350 -0
- package/dist/history/store.js +216 -0
- package/dist/history/types.js +4 -0
- package/dist/history/worker.js +466 -0
- package/dist/intercom/intercom-bridge.js +112 -0
- package/dist/intercom/live-intercom.js +94 -0
- package/dist/intercom/result-intercom.js +373 -0
- package/dist/pi-intercom/agent-dir.js +10 -0
- package/dist/pi-intercom/bridge.js +750 -0
- package/dist/pi-intercom/broker/broker.js +426 -0
- package/dist/pi-intercom/broker/client.js +492 -0
- package/dist/pi-intercom/broker/framing.js +65 -0
- package/dist/pi-intercom/broker/paths.js +42 -0
- package/dist/pi-intercom/broker/pid.js +66 -0
- package/dist/pi-intercom/broker/spawn.js +221 -0
- package/dist/pi-intercom/config.js +102 -0
- package/dist/pi-intercom/index.js +2942 -0
- package/dist/pi-intercom/reply-tracker.js +182 -0
- package/dist/pi-intercom/session-targets.js +128 -0
- package/dist/pi-intercom/subagent-live-events.js +132 -0
- package/dist/pi-intercom/topics.js +157 -0
- package/dist/pi-intercom/types.js +163 -0
- package/dist/pi-intercom/ui/compose.js +269 -0
- package/dist/pi-intercom/ui/inline-message.js +80 -0
- package/dist/pi-intercom/ui/session-list.js +124 -0
- package/dist/runs/background/async-control.js +95 -0
- package/dist/runs/background/async-execution.js +676 -0
- package/dist/runs/background/async-job-tracker.js +383 -0
- package/dist/runs/background/async-result-file.js +58 -0
- package/dist/runs/background/async-resume.js +305 -0
- package/dist/runs/background/async-status.js +442 -0
- package/dist/runs/background/completion-dedupe.js +69 -0
- package/dist/runs/background/completion-delivery.js +245 -0
- package/dist/runs/background/notify.js +71 -0
- package/dist/runs/background/parallel-groups.js +55 -0
- package/dist/runs/background/result-watcher.js +426 -0
- package/dist/runs/background/run-id-resolver.js +64 -0
- package/dist/runs/background/run-status.js +382 -0
- package/dist/runs/background/stale-run-reconciler.js +335 -0
- package/dist/runs/background/subagent-runner-launcher.js +55 -0
- package/dist/runs/background/subagent-runner.js +1872 -0
- package/dist/runs/background/top-level-async.js +5 -0
- package/dist/runs/foreground/chain-clarify.js +1152 -0
- package/dist/runs/foreground/clarify-invocation.js +72 -0
- package/dist/runs/foreground/execution-input.js +423 -0
- package/dist/runs/foreground/foreground-control.js +817 -0
- package/dist/runs/foreground/question-control.js +88 -0
- package/dist/runs/foreground/run-async-path.js +205 -0
- package/dist/runs/foreground/subagent-executor.js +442 -0
- package/dist/runs/foreground/subagent-params.js +165 -0
- package/dist/runs/foreground/wait-run.js +141 -0
- package/dist/runs/shared/acceptance-contract.js +253 -0
- package/dist/runs/shared/acceptance-evaluation.js +256 -0
- package/dist/runs/shared/acceptance-finalization.js +280 -0
- package/dist/runs/shared/acceptance-reports.js +147 -0
- package/dist/runs/shared/acceptance.js +4 -0
- package/dist/runs/shared/chain-outputs.js +110 -0
- package/dist/runs/shared/child-attempt.js +693 -0
- package/dist/runs/shared/child-execution-cwd.js +96 -0
- package/dist/runs/shared/child-observations.js +114 -0
- package/dist/runs/shared/claude-code.js +199 -0
- package/dist/runs/shared/completion-guard.js +31 -0
- package/dist/runs/shared/dynamic-fanout.js +274 -0
- package/dist/runs/shared/history-index.js +72 -0
- package/dist/runs/shared/mcp-direct-tool-allowlist.js +334 -0
- package/dist/runs/shared/model-fallback.js +185 -0
- package/dist/runs/shared/mutating-tool-guard.js +170 -0
- package/dist/runs/shared/native-finalization.js +101 -0
- package/dist/runs/shared/native-usage.js +153 -0
- package/dist/runs/shared/nested-events.js +700 -0
- package/dist/runs/shared/nested-path.js +48 -0
- package/dist/runs/shared/nested-render.js +108 -0
- package/dist/runs/shared/parallel-utils.js +61 -0
- package/dist/runs/shared/parent-receipts.js +68 -0
- package/dist/runs/shared/parent-usage.js +121 -0
- package/dist/runs/shared/pi-args.js +310 -0
- package/dist/runs/shared/pi-spawn.js +52 -0
- package/dist/runs/shared/run-history-queries.js +45 -0
- package/dist/runs/shared/run-history.js +110 -0
- package/dist/runs/shared/run-id-ambiguity.js +4 -0
- package/dist/runs/shared/run-records.js +679 -0
- package/dist/runs/shared/session-cwd-preload.js +33 -0
- package/dist/runs/shared/single-output.js +222 -0
- package/dist/runs/shared/streaming-text.js +15 -0
- package/dist/runs/shared/structured-output.js +55 -0
- package/dist/runs/shared/subagent-control.js +179 -0
- package/dist/runs/shared/subagent-prompt-runtime.js +197 -0
- package/dist/runs/shared/subagent-tool-loop-guard.js +66 -0
- package/dist/runs/shared/supervisor-questions.js +350 -0
- package/dist/runs/shared/workflow-graph.js +214 -0
- package/dist/runs/shared/workflow-policy.js +84 -0
- package/dist/runs/shared/worktree.js +525 -0
- package/dist/shared/agent-context-policy.js +126 -0
- package/dist/shared/artifacts.js +96 -0
- package/dist/shared/atomic-json.js +13 -0
- package/dist/shared/cooperative.js +20 -0
- package/dist/shared/execution-cwd.js +14 -0
- package/dist/shared/file-coalescer.js +21 -0
- package/dist/shared/fork-context.js +49 -0
- package/dist/shared/formatters.js +85 -0
- package/dist/shared/journal-reader.js +407 -0
- package/dist/shared/lazy-tools.js +32 -0
- package/dist/shared/model-info.js +68 -0
- package/dist/shared/native-session.js +15 -0
- package/dist/shared/native-tui.js +18 -0
- package/dist/shared/native-typebox.js +20 -0
- package/dist/shared/post-exit-stdio-guard.js +197 -0
- package/dist/shared/prompt-sections.js +8 -0
- package/dist/shared/session-entries.js +52 -0
- package/dist/shared/session-identity.js +14 -0
- package/dist/shared/settings.js +254 -0
- package/dist/shared/status-format.js +111 -0
- package/dist/shared/temp-root.js +114 -0
- package/dist/shared/types.js +207 -0
- package/dist/shared/ui-mode.js +3 -0
- package/dist/shared/utils.js +334 -0
- package/dist/slash/prompt-template-bridge.js +298 -0
- package/dist/slash/slash-bridge.js +116 -0
- package/dist/slash/slash-commands.js +607 -0
- package/dist/slash/slash-live-state.js +246 -0
- package/dist/tui/action-hints.js +75 -0
- package/dist/tui/agent-history.js +197 -0
- package/dist/tui/agent-view.js +1656 -0
- package/dist/tui/render.js +1515 -0
- package/docs/intercom-bridge.md +212 -0
- package/docs/intercom.md +581 -0
- package/docs/performance.md +121 -0
- package/package.json +102 -4
- package/prompts/gather-context-and-clarify.md +14 -0
- package/prompts/parallel-cleanup.md +62 -0
- package/prompts/parallel-context-build.md +56 -0
- package/prompts/parallel-handoff-plan.md +62 -0
- package/prompts/parallel-research.md +51 -0
- package/prompts/parallel-review.md +59 -0
- package/prompts/review-loop.md +42 -0
- package/scripts/build.mjs +134 -0
- package/scripts/check-compat.mjs +48 -0
- package/scripts/compat-host.mjs +19 -0
- package/scripts/intercom-bridge-credentials.mjs +143 -0
- package/scripts/intercom-remote.mjs +103 -0
- package/scripts/linux-smoke.sh +51 -0
- package/scripts/local-install-smoke.mjs +66 -0
- package/scripts/native-package-smoke.mjs +82 -0
- package/scripts/package-smoke.mjs +209 -0
- package/scripts/prepare.mjs +67 -0
- package/scripts/real-pi-smoke.mjs +415 -0
- package/scripts/run-tests.mjs +149 -0
- package/skills/pi-intercom/SKILL.md +113 -0
- package/skills/pi-intercom/evals/evals.json +29 -0
- package/skills/pi-intercom/evals/trigger-evals.json +47 -0
- package/skills/pi-intercom/references/peer-sessions.md +69 -0
- package/skills/pi-subagents/SKILL.md +76 -0
- package/skills/pi-subagents/evals/evals.json +29 -0
- package/skills/pi-subagents/evals/trigger-evals.json +42 -0
- package/skills/pi-subagents/references/full-orchestration-guide.md +863 -0
- package/src/agents/agent-management.ts +813 -0
- package/src/agents/agent-scope.ts +7 -0
- package/src/agents/agent-selection.ts +23 -0
- package/src/agents/agent-serializer.ts +99 -0
- package/src/agents/agents.ts +916 -0
- package/src/agents/chain-serializer.ts +329 -0
- package/src/agents/frontmatter.ts +21 -0
- package/src/agents/identity.ts +30 -0
- package/src/agents/skills.ts +637 -0
- package/src/extension/build-info.ts +2 -0
- package/src/extension/compact-tools.ts +114 -0
- package/src/extension/config.ts +23 -0
- package/src/extension/control-notices.ts +47 -0
- package/src/extension/doctor.ts +171 -0
- package/src/extension/fanout-child.ts +312 -0
- package/src/extension/index.ts +649 -0
- package/src/extension/schemas.ts +444 -0
- package/src/extension/tool-input.ts +19 -0
- package/src/extension/tool-result.ts +16 -0
- package/src/history/canonical-result.ts +62 -0
- package/src/history/database.ts +59 -0
- package/src/history/index.ts +156 -0
- package/src/history/ingest.ts +349 -0
- package/src/history/queries.ts +241 -0
- package/src/history/store.ts +203 -0
- package/src/history/types.ts +166 -0
- package/src/history/worker.ts +321 -0
- package/src/intercom/intercom-bridge.ts +123 -0
- package/src/intercom/live-intercom.ts +104 -0
- package/src/intercom/result-intercom.ts +429 -0
- package/src/pi-intercom/agent-dir.ts +9 -0
- package/src/pi-intercom/bridge.ts +668 -0
- package/src/pi-intercom/broker/broker.ts +463 -0
- package/src/pi-intercom/broker/client.ts +558 -0
- package/src/pi-intercom/broker/framing.ts +77 -0
- package/src/pi-intercom/broker/paths.ts +47 -0
- package/src/pi-intercom/broker/pid.ts +59 -0
- package/src/pi-intercom/broker/spawn.ts +248 -0
- package/src/pi-intercom/config.ts +142 -0
- package/src/pi-intercom/index.ts +2929 -0
- package/src/pi-intercom/reply-tracker.ts +211 -0
- package/src/pi-intercom/session-targets.ts +172 -0
- package/src/pi-intercom/subagent-live-events.ts +133 -0
- package/src/pi-intercom/topics.ts +125 -0
- package/src/pi-intercom/types.ts +271 -0
- package/src/pi-intercom/ui/compose.ts +289 -0
- package/src/pi-intercom/ui/inline-message.ts +92 -0
- package/src/pi-intercom/ui/session-list.ts +139 -0
- package/src/runs/background/async-control.ts +89 -0
- package/src/runs/background/async-execution.ts +850 -0
- package/src/runs/background/async-job-tracker.ts +385 -0
- package/src/runs/background/async-result-file.ts +62 -0
- package/src/runs/background/async-resume.ts +333 -0
- package/src/runs/background/async-status.ts +481 -0
- package/src/runs/background/completion-dedupe.ts +79 -0
- package/src/runs/background/completion-delivery.ts +195 -0
- package/src/runs/background/notify.ts +123 -0
- package/src/runs/background/parallel-groups.ts +53 -0
- package/src/runs/background/result-watcher.ts +423 -0
- package/src/runs/background/run-id-resolver.ts +69 -0
- package/src/runs/background/run-status.ts +384 -0
- package/src/runs/background/stale-run-reconciler.ts +369 -0
- package/src/runs/background/subagent-runner-launcher.ts +56 -0
- package/src/runs/background/subagent-runner.ts +2053 -0
- package/src/runs/background/top-level-async.ts +13 -0
- package/src/runs/foreground/chain-clarify.ts +1340 -0
- package/src/runs/foreground/clarify-invocation.ts +77 -0
- package/src/runs/foreground/execution-input.ts +467 -0
- package/src/runs/foreground/foreground-control.ts +821 -0
- package/src/runs/foreground/question-control.ts +82 -0
- package/src/runs/foreground/run-async-path.ts +243 -0
- package/src/runs/foreground/subagent-executor.ts +501 -0
- package/src/runs/foreground/subagent-params.ts +320 -0
- package/src/runs/foreground/wait-run.ts +124 -0
- package/src/runs/shared/acceptance-contract.ts +257 -0
- package/src/runs/shared/acceptance-evaluation.ts +275 -0
- package/src/runs/shared/acceptance-finalization.ts +353 -0
- package/src/runs/shared/acceptance-reports.ts +152 -0
- package/src/runs/shared/acceptance.ts +33 -0
- package/src/runs/shared/chain-outputs.ts +114 -0
- package/src/runs/shared/child-attempt.ts +623 -0
- package/src/runs/shared/child-execution-cwd.ts +91 -0
- package/src/runs/shared/child-observations.ts +99 -0
- package/src/runs/shared/claude-code.ts +243 -0
- package/src/runs/shared/completion-guard.ts +35 -0
- package/src/runs/shared/dynamic-fanout.ts +295 -0
- package/src/runs/shared/history-index.ts +69 -0
- package/src/runs/shared/mcp-direct-tool-allowlist.ts +376 -0
- package/src/runs/shared/model-fallback.ts +219 -0
- package/src/runs/shared/mutating-tool-guard.ts +194 -0
- package/src/runs/shared/native-finalization.ts +128 -0
- package/src/runs/shared/native-usage.ts +113 -0
- package/src/runs/shared/nested-events.ts +752 -0
- package/src/runs/shared/nested-path.ts +52 -0
- package/src/runs/shared/nested-render.ts +119 -0
- package/src/runs/shared/parallel-utils.ts +153 -0
- package/src/runs/shared/parent-receipts.ts +59 -0
- package/src/runs/shared/parent-usage.ts +121 -0
- package/src/runs/shared/pi-args.ts +350 -0
- package/src/runs/shared/pi-spawn.ts +52 -0
- package/src/runs/shared/run-history-queries.ts +44 -0
- package/src/runs/shared/run-history.ts +100 -0
- package/src/runs/shared/run-id-ambiguity.ts +4 -0
- package/src/runs/shared/run-records.ts +607 -0
- package/src/runs/shared/session-cwd-preload.ts +27 -0
- package/src/runs/shared/single-output.ts +267 -0
- package/src/runs/shared/streaming-text.ts +18 -0
- package/src/runs/shared/structured-output.ts +68 -0
- package/src/runs/shared/subagent-control.ts +219 -0
- package/src/runs/shared/subagent-prompt-runtime.ts +201 -0
- package/src/runs/shared/subagent-tool-loop-guard.ts +89 -0
- package/src/runs/shared/supervisor-questions.ts +415 -0
- package/src/runs/shared/workflow-graph.ts +220 -0
- package/src/runs/shared/workflow-policy.ts +125 -0
- package/src/runs/shared/worktree.ts +635 -0
- package/src/shared/agent-context-policy.ts +184 -0
- package/src/shared/artifacts.ts +95 -0
- package/src/shared/atomic-json.ts +16 -0
- package/src/shared/cooperative.ts +21 -0
- package/src/shared/execution-cwd.ts +14 -0
- package/src/shared/file-coalescer.ts +29 -0
- package/src/shared/fork-context.ts +68 -0
- package/src/shared/formatters.ts +84 -0
- package/src/shared/journal-reader.ts +333 -0
- package/src/shared/lazy-tools.ts +36 -0
- package/src/shared/model-info.ts +81 -0
- package/src/shared/native-session.ts +8 -0
- package/src/shared/native-tui.ts +10 -0
- package/src/shared/native-typebox.ts +14 -0
- package/src/shared/post-exit-stdio-guard.ts +204 -0
- package/src/shared/prompt-sections.ts +10 -0
- package/src/shared/session-entries.ts +49 -0
- package/src/shared/session-identity.ts +18 -0
- package/src/shared/settings.ts +384 -0
- package/src/shared/status-format.ts +123 -0
- package/src/shared/temp-root.ts +107 -0
- package/src/shared/types.ts +1260 -0
- package/src/shared/ui-mode.ts +5 -0
- package/src/shared/utils.ts +342 -0
- package/src/slash/prompt-template-bridge.ts +408 -0
- package/src/slash/slash-bridge.ts +178 -0
- package/src/slash/slash-commands.ts +617 -0
- package/src/slash/slash-live-state.ts +292 -0
- package/src/tui/action-hints.ts +69 -0
- package/src/tui/agent-history.ts +210 -0
- package/src/tui/agent-view.ts +1323 -0
- package/src/tui/render.ts +1550 -0
- package/tsconfig.build.json +12 -0
- package/tsconfig.json +19 -0
|
@@ -0,0 +1,1515 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rendering functions for subagent results
|
|
3
|
+
*/
|
|
4
|
+
import * as path from "node:path";
|
|
5
|
+
import { getMarkdownTheme, keyText } from "@earendil-works/pi-coding-agent";
|
|
6
|
+
import { Container, Markdown, Spacer, Text, TruncatedText, visibleWidth } from "@earendil-works/pi-tui";
|
|
7
|
+
import { MAX_WIDGET_JOBS, WIDGET_KEY, } from "../shared/types.js";
|
|
8
|
+
import { formatTokens, formatUsage, formatDuration, formatModelThinking, formatToolCall, shortenPath } from "../shared/formatters.js";
|
|
9
|
+
import { getDisplayItems, getSingleResultOutput } from "../shared/utils.js";
|
|
10
|
+
import { flatToLogicalStepIndex } from "../runs/background/parallel-groups.js";
|
|
11
|
+
import { formatNestedAggregate } from "../runs/shared/nested-render.js";
|
|
12
|
+
import { aggregateStepStatus, formatActivityLabel, formatAgentRunningLabel, formatParallelOutcome } from "../shared/status-format.js";
|
|
13
|
+
import { acceptanceHumanAction } from "../runs/shared/acceptance.js";
|
|
14
|
+
import { formatAgentProcessExit } from "../shared/status-format.js";
|
|
15
|
+
import { isTuiContext } from "../shared/ui-mode.js";
|
|
16
|
+
function getTermWidth() {
|
|
17
|
+
return process.stdout.columns || 120;
|
|
18
|
+
}
|
|
19
|
+
const segmenter = new Intl.Segmenter(undefined, { granularity: "grapheme" });
|
|
20
|
+
/**
|
|
21
|
+
* Truncate a line to maxWidth, preserving ANSI styling through the ellipsis.
|
|
22
|
+
*
|
|
23
|
+
* pi-tui's truncateToWidth adds \x1b[0m before ellipsis which resets all styling,
|
|
24
|
+
* causing background color bleed in the TUI. This implementation tracks active
|
|
25
|
+
* ANSI styles and re-applies them before the ellipsis.
|
|
26
|
+
*
|
|
27
|
+
* Uses Intl.Segmenter for proper Unicode/emoji handling (not char-by-char).
|
|
28
|
+
*/
|
|
29
|
+
function truncLine(text, maxWidth) {
|
|
30
|
+
if (visibleWidth(text) <= maxWidth)
|
|
31
|
+
return text;
|
|
32
|
+
const targetWidth = maxWidth - 1;
|
|
33
|
+
let result = "";
|
|
34
|
+
let currentWidth = 0;
|
|
35
|
+
let activeStyles = [];
|
|
36
|
+
let i = 0;
|
|
37
|
+
while (i < text.length) {
|
|
38
|
+
const ansiMatch = text.slice(i).match(/^\x1b\[[0-9;]*m/);
|
|
39
|
+
if (ansiMatch) {
|
|
40
|
+
const code = ansiMatch[0];
|
|
41
|
+
result += code;
|
|
42
|
+
if (code === "\x1b[0m" || code === "\x1b[m") {
|
|
43
|
+
activeStyles = [];
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
activeStyles.push(code);
|
|
47
|
+
}
|
|
48
|
+
i += code.length;
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
let end = i;
|
|
52
|
+
while (end < text.length && !text.slice(end).match(/^\x1b\[[0-9;]*m/)) {
|
|
53
|
+
end++;
|
|
54
|
+
}
|
|
55
|
+
const textPortion = text.slice(i, end);
|
|
56
|
+
for (const seg of segmenter.segment(textPortion)) {
|
|
57
|
+
const grapheme = seg.segment;
|
|
58
|
+
const graphemeWidth = visibleWidth(grapheme);
|
|
59
|
+
if (currentWidth + graphemeWidth > targetWidth) {
|
|
60
|
+
return result + activeStyles.join("") + "…";
|
|
61
|
+
}
|
|
62
|
+
result += grapheme;
|
|
63
|
+
currentWidth += graphemeWidth;
|
|
64
|
+
}
|
|
65
|
+
i = end;
|
|
66
|
+
}
|
|
67
|
+
return result + activeStyles.join("") + "…";
|
|
68
|
+
}
|
|
69
|
+
const RUNNING_FRAMES = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
|
|
70
|
+
const STATIC_RUNNING_GLYPH = "●";
|
|
71
|
+
function runningSeed(...values) {
|
|
72
|
+
let seed;
|
|
73
|
+
for (const value of values) {
|
|
74
|
+
if (value === undefined || !Number.isFinite(value))
|
|
75
|
+
continue;
|
|
76
|
+
seed = (seed ?? 0) + Math.trunc(value);
|
|
77
|
+
}
|
|
78
|
+
return seed;
|
|
79
|
+
}
|
|
80
|
+
function runningGlyph(seed) {
|
|
81
|
+
if (seed === undefined)
|
|
82
|
+
return STATIC_RUNNING_GLYPH;
|
|
83
|
+
return RUNNING_FRAMES[Math.abs(seed) % RUNNING_FRAMES.length];
|
|
84
|
+
}
|
|
85
|
+
function progressRunningSeed(progress) {
|
|
86
|
+
if (!progress)
|
|
87
|
+
return undefined;
|
|
88
|
+
return runningSeed(progress.index, progress.toolCount, progress.tokens, progress.durationMs, progress.lastActivityAt, progress.currentToolStartedAt, progress.turnCount);
|
|
89
|
+
}
|
|
90
|
+
function extractOutputTarget(task) {
|
|
91
|
+
const writeToMatch = task.match(/\[Write to:\s*([^\]\n]+)\]/i);
|
|
92
|
+
if (writeToMatch?.[1]?.trim())
|
|
93
|
+
return writeToMatch[1].trim();
|
|
94
|
+
const findingsMatch = task.match(/Write your findings to:\s*(\S+)/i);
|
|
95
|
+
if (findingsMatch?.[1]?.trim())
|
|
96
|
+
return findingsMatch[1].trim();
|
|
97
|
+
const outputMatch = task.match(/[Oo]utput(?:\s+to)?\s*:\s*(\S+)/i);
|
|
98
|
+
if (outputMatch?.[1]?.trim())
|
|
99
|
+
return outputMatch[1].trim();
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
function hasEmptyTextOutputWithoutOutputTarget(task, output) {
|
|
103
|
+
if (output.trim())
|
|
104
|
+
return false;
|
|
105
|
+
return !extractOutputTarget(task);
|
|
106
|
+
}
|
|
107
|
+
function getToolCallLines(result, expanded) {
|
|
108
|
+
if (result.messages) {
|
|
109
|
+
return getDisplayItems(result.messages)
|
|
110
|
+
.filter((item) => item.type === "tool")
|
|
111
|
+
.map((item) => formatToolCall(item.name, item.args, expanded));
|
|
112
|
+
}
|
|
113
|
+
return result.toolCalls?.map((toolCall) => expanded ? toolCall.expandedText : toolCall.text) ?? [];
|
|
114
|
+
}
|
|
115
|
+
function snapshotNowForProgress(progress) {
|
|
116
|
+
if (progress.currentToolStartedAt !== undefined && progress.durationMs !== undefined)
|
|
117
|
+
return progress.currentToolStartedAt + progress.durationMs;
|
|
118
|
+
return progress.lastActivityAt;
|
|
119
|
+
}
|
|
120
|
+
function formatCurrentToolLine(progress, availableWidth, expanded, snapshotNow) {
|
|
121
|
+
if (!progress.currentTool)
|
|
122
|
+
return undefined;
|
|
123
|
+
const maxToolArgsLen = Math.max(50, availableWidth - 20);
|
|
124
|
+
const toolArgsPreview = progress.currentToolArgs
|
|
125
|
+
? (expanded || progress.currentToolArgs.length <= maxToolArgsLen
|
|
126
|
+
? progress.currentToolArgs
|
|
127
|
+
: `${progress.currentToolArgs.slice(0, maxToolArgsLen)}...`)
|
|
128
|
+
: "";
|
|
129
|
+
const durationSuffix = progress.currentToolStartedAt !== undefined && snapshotNow !== undefined
|
|
130
|
+
? ` | ${formatDuration(Math.max(0, snapshotNow - progress.currentToolStartedAt))}`
|
|
131
|
+
: "";
|
|
132
|
+
return toolArgsPreview
|
|
133
|
+
? `${progress.currentTool}: ${toolArgsPreview}${durationSuffix}`
|
|
134
|
+
: `${progress.currentTool}${durationSuffix}`;
|
|
135
|
+
}
|
|
136
|
+
function buildLiveStatusLine(progress, snapshotNow) {
|
|
137
|
+
if (progress.lastActivityAt !== undefined && snapshotNow !== undefined)
|
|
138
|
+
return formatActivityLabel(progress.lastActivityAt, progress.activityState, snapshotNow);
|
|
139
|
+
if (progress.activityState === "needs_attention")
|
|
140
|
+
return "needs attention";
|
|
141
|
+
if (progress.lastActivityAt !== undefined)
|
|
142
|
+
return "active";
|
|
143
|
+
return undefined;
|
|
144
|
+
}
|
|
145
|
+
function themeBold(theme, text) {
|
|
146
|
+
return (theme.bold?.(text)) ?? text;
|
|
147
|
+
}
|
|
148
|
+
function statJoin(theme, parts) {
|
|
149
|
+
return parts.filter(Boolean).map((part) => theme.fg("dim", part)).join(` ${theme.fg("dim", "·")} `);
|
|
150
|
+
}
|
|
151
|
+
function formatTokenStat(tokens) {
|
|
152
|
+
return `${formatTokens(tokens)} token`;
|
|
153
|
+
}
|
|
154
|
+
function formatToolUseStat(count) {
|
|
155
|
+
return `${count} tool use${count === 1 ? "" : "s"}`;
|
|
156
|
+
}
|
|
157
|
+
function formatProgressStats(theme, progress, includeDuration = true) {
|
|
158
|
+
if (!progress)
|
|
159
|
+
return "";
|
|
160
|
+
const parts = [];
|
|
161
|
+
if (progress.toolCount > 0)
|
|
162
|
+
parts.push(formatToolUseStat(progress.toolCount));
|
|
163
|
+
if (progress.tokens > 0)
|
|
164
|
+
parts.push(formatTokenStat(progress.tokens));
|
|
165
|
+
if (includeDuration && progress.durationMs > 0)
|
|
166
|
+
parts.push(formatDuration(progress.durationMs));
|
|
167
|
+
return statJoin(theme, parts);
|
|
168
|
+
}
|
|
169
|
+
function firstOutputLine(text) {
|
|
170
|
+
return text.split("\n").find((line) => line.trim())?.replace(/[\u0000-\u0008\u000b-\u001f\u007f]/g, "").trim() ?? "";
|
|
171
|
+
}
|
|
172
|
+
function formatAcceptanceStatus(result) {
|
|
173
|
+
const acceptance = result.acceptance;
|
|
174
|
+
if (!acceptance?.status || acceptance.status === "not-required")
|
|
175
|
+
return undefined;
|
|
176
|
+
const finalization = acceptance.finalization
|
|
177
|
+
? ` · finalization: ${acceptance.finalization.status} after ${acceptance.finalization.turns.length}/${acceptance.finalization.maxTurns} turns`
|
|
178
|
+
: "";
|
|
179
|
+
return `acceptance: ${acceptance.status}${finalization}`;
|
|
180
|
+
}
|
|
181
|
+
function resultStatusLine(result, output) {
|
|
182
|
+
if (result.detached)
|
|
183
|
+
return result.detachedReason ? `Detached: ${result.detachedReason}` : "Detached";
|
|
184
|
+
if (result.timedOut)
|
|
185
|
+
return `Timed out${result.error ? `: ${result.error}` : ""}`;
|
|
186
|
+
if (result.interrupted)
|
|
187
|
+
return "Paused";
|
|
188
|
+
if (result.exitCode !== 0)
|
|
189
|
+
return `Error: ${result.error ?? (firstOutputLine(output) || `exit ${result.exitCode}`)}`;
|
|
190
|
+
if (result.acceptance?.status === "blocked")
|
|
191
|
+
return `Needs your action · acceptance incomplete · ${acceptanceHumanAction(result.acceptance)?.split("\n")[0]}`;
|
|
192
|
+
const acceptance = formatAcceptanceStatus(result);
|
|
193
|
+
if (acceptance)
|
|
194
|
+
return `Done · ${acceptance}`;
|
|
195
|
+
if (hasEmptyTextOutputWithoutOutputTarget(result.task, output))
|
|
196
|
+
return "Done (no text output)";
|
|
197
|
+
return "Done";
|
|
198
|
+
}
|
|
199
|
+
function resultGlyph(result, output, theme, running = result.progress?.status === "running", seed = progressRunningSeed(result.progress ?? result.progressSummary)) {
|
|
200
|
+
if (running)
|
|
201
|
+
return theme.fg("accent", runningGlyph(seed));
|
|
202
|
+
if (result.detached)
|
|
203
|
+
return theme.fg("warning", "■");
|
|
204
|
+
if (result.timedOut)
|
|
205
|
+
return theme.fg("error", "✗");
|
|
206
|
+
if (result.interrupted)
|
|
207
|
+
return theme.fg("warning", "■");
|
|
208
|
+
if (result.exitCode !== 0)
|
|
209
|
+
return theme.fg("error", "✗");
|
|
210
|
+
if (result.acceptance?.status === "blocked")
|
|
211
|
+
return theme.fg("warning", "■");
|
|
212
|
+
if (hasEmptyTextOutputWithoutOutputTarget(result.task, output))
|
|
213
|
+
return theme.fg("warning", "✓");
|
|
214
|
+
return theme.fg("success", "✓");
|
|
215
|
+
}
|
|
216
|
+
function compactCurrentActivity(progress) {
|
|
217
|
+
const snapshotNow = snapshotNowForProgress(progress);
|
|
218
|
+
return formatCurrentToolLine(progress, getTermWidth() - 4, false, snapshotNow) ?? buildLiveStatusLine(progress, snapshotNow) ?? "thinking…";
|
|
219
|
+
}
|
|
220
|
+
export function widgetRenderKey(job) {
|
|
221
|
+
return JSON.stringify({
|
|
222
|
+
asyncDir: job.asyncDir,
|
|
223
|
+
status: job.status,
|
|
224
|
+
activityState: job.activityState,
|
|
225
|
+
lastActivityAt: job.lastActivityAt,
|
|
226
|
+
currentTool: job.currentTool,
|
|
227
|
+
currentToolStartedAt: job.currentToolStartedAt,
|
|
228
|
+
currentPath: job.currentPath,
|
|
229
|
+
turnCount: job.turnCount,
|
|
230
|
+
toolCount: job.toolCount,
|
|
231
|
+
mode: job.mode,
|
|
232
|
+
agents: job.agents,
|
|
233
|
+
currentStep: job.currentStep,
|
|
234
|
+
chainStepCount: job.chainStepCount,
|
|
235
|
+
parallelGroups: job.parallelGroups,
|
|
236
|
+
steps: job.steps,
|
|
237
|
+
nestedChildren: job.nestedChildren,
|
|
238
|
+
stepsTotal: job.stepsTotal,
|
|
239
|
+
runningSteps: job.runningSteps,
|
|
240
|
+
completedSteps: job.completedSteps,
|
|
241
|
+
activeParallelGroup: job.activeParallelGroup,
|
|
242
|
+
startedAt: job.startedAt,
|
|
243
|
+
updatedAt: job.updatedAt,
|
|
244
|
+
totalTokens: job.totalTokens,
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
function formatWidgetAgents(agents) {
|
|
248
|
+
const distinct = [...new Set(agents)];
|
|
249
|
+
if (distinct.length === 1 && agents.length > 1)
|
|
250
|
+
return `${distinct[0]} ×${agents.length}`;
|
|
251
|
+
if (agents.length > 3)
|
|
252
|
+
return `${agents.slice(0, 2).join(", ")} +${agents.length - 2} more`;
|
|
253
|
+
return agents.join(", ");
|
|
254
|
+
}
|
|
255
|
+
function widgetJobName(job) {
|
|
256
|
+
if (job.mode === "parallel")
|
|
257
|
+
return "parallel";
|
|
258
|
+
if (job.mode === "chain")
|
|
259
|
+
return "chain";
|
|
260
|
+
if (job.mode === "single" && job.agents?.length === 1)
|
|
261
|
+
return job.agents[0];
|
|
262
|
+
if (job.agents?.length)
|
|
263
|
+
return formatWidgetAgents(job.agents);
|
|
264
|
+
return job.mode ?? "subagent";
|
|
265
|
+
}
|
|
266
|
+
function widgetActivity(job, includeCounts = true) {
|
|
267
|
+
const facts = [];
|
|
268
|
+
if (job.currentTool && job.currentToolStartedAt !== undefined && job.updatedAt !== undefined)
|
|
269
|
+
facts.push(`${job.currentTool} ${formatDuration(Math.max(0, job.updatedAt - job.currentToolStartedAt))}`);
|
|
270
|
+
else if (job.currentTool)
|
|
271
|
+
facts.push(job.currentTool);
|
|
272
|
+
if (job.currentPath)
|
|
273
|
+
facts.push(shortenPath(job.currentPath));
|
|
274
|
+
if (includeCounts && job.turnCount !== undefined)
|
|
275
|
+
facts.push(`${job.turnCount} turns`);
|
|
276
|
+
if (includeCounts && job.toolCount !== undefined)
|
|
277
|
+
facts.push(`${job.toolCount} tools`);
|
|
278
|
+
if (job.status !== "running") {
|
|
279
|
+
const status = job.status === "queued" ? "queued…" : job.status === "paused" ? "Paused" : job.status === "failed" ? "Failed" : job.status === "blocked" ? "Needs your action" : "Done";
|
|
280
|
+
const error = job.status === "failed" ? job.steps?.find((step) => step.error)?.error : undefined;
|
|
281
|
+
return [status, error ? firstOutputLine(error) : "", ...facts].filter(Boolean).join(" · ");
|
|
282
|
+
}
|
|
283
|
+
const activity = buildLiveStatusLine(job, job.updatedAt);
|
|
284
|
+
if (activity && facts.length)
|
|
285
|
+
return `${activity} · ${facts.join(" · ")}`;
|
|
286
|
+
if (activity)
|
|
287
|
+
return activity;
|
|
288
|
+
if (facts.length)
|
|
289
|
+
return facts.join(" · ");
|
|
290
|
+
return "thinking…";
|
|
291
|
+
}
|
|
292
|
+
function widgetStepRunningSeed(step, fallbackIndex) {
|
|
293
|
+
return runningSeed(fallbackIndex, step.index, step.toolCount, step.turnCount, step.tokens?.total, step.lastActivityAt, step.currentToolStartedAt, step.durationMs);
|
|
294
|
+
}
|
|
295
|
+
function widgetStepsRunningSeed(steps) {
|
|
296
|
+
let seed;
|
|
297
|
+
for (const [index, step] of (steps ?? []).entries())
|
|
298
|
+
seed = runningSeed(seed, widgetStepRunningSeed(step, index));
|
|
299
|
+
return seed;
|
|
300
|
+
}
|
|
301
|
+
function widgetJobRunningSeed(job) {
|
|
302
|
+
return runningSeed(job.updatedAt, job.lastActivityAt, job.toolCount, job.turnCount, job.totalTokens?.total, job.currentStep, job.runningSteps, job.completedSteps, widgetStepsRunningSeed(job.steps));
|
|
303
|
+
}
|
|
304
|
+
function widgetJobsRunningSeed(jobs) {
|
|
305
|
+
let seed;
|
|
306
|
+
for (const job of jobs)
|
|
307
|
+
seed = runningSeed(seed, widgetJobRunningSeed(job));
|
|
308
|
+
return seed;
|
|
309
|
+
}
|
|
310
|
+
function widgetStatusGlyph(job, theme) {
|
|
311
|
+
if (job.status === "running")
|
|
312
|
+
return theme.fg("accent", runningGlyph(widgetJobRunningSeed(job)));
|
|
313
|
+
if (job.status === "queued")
|
|
314
|
+
return theme.fg("muted", "◦");
|
|
315
|
+
if (job.status === "complete")
|
|
316
|
+
return theme.fg("success", "✓");
|
|
317
|
+
if (job.status === "blocked")
|
|
318
|
+
return theme.fg("warning", "■");
|
|
319
|
+
if (job.status === "paused")
|
|
320
|
+
return theme.fg("warning", "■");
|
|
321
|
+
return theme.fg("error", "✗");
|
|
322
|
+
}
|
|
323
|
+
function widgetStepGlyph(status, theme, seed) {
|
|
324
|
+
if (status === "running")
|
|
325
|
+
return theme.fg("accent", runningGlyph(seed));
|
|
326
|
+
if (status === "complete" || status === "completed")
|
|
327
|
+
return theme.fg("success", "✓");
|
|
328
|
+
if (status === "failed" || status === "timed-out")
|
|
329
|
+
return theme.fg("error", "✗");
|
|
330
|
+
if (status === "blocked")
|
|
331
|
+
return theme.fg("warning", "■");
|
|
332
|
+
if (status === "paused")
|
|
333
|
+
return theme.fg("warning", "■");
|
|
334
|
+
return theme.fg("muted", "◦");
|
|
335
|
+
}
|
|
336
|
+
function widgetStepStatus(status, theme) {
|
|
337
|
+
if (status === "running")
|
|
338
|
+
return theme.fg("accent", "running");
|
|
339
|
+
if (status === "complete" || status === "completed")
|
|
340
|
+
return theme.fg("success", "complete");
|
|
341
|
+
if (status === "failed")
|
|
342
|
+
return theme.fg("error", "failed");
|
|
343
|
+
if (status === "timed-out")
|
|
344
|
+
return theme.fg("error", "timed out");
|
|
345
|
+
if (status === "blocked")
|
|
346
|
+
return theme.fg("warning", "needs your action");
|
|
347
|
+
if (status === "paused")
|
|
348
|
+
return theme.fg("warning", "paused");
|
|
349
|
+
return theme.fg("dim", status);
|
|
350
|
+
}
|
|
351
|
+
function widgetStepActivity(step, snapshotNow) {
|
|
352
|
+
if ((step.status === "failed" || step.status === "timed-out") && step.error)
|
|
353
|
+
return firstOutputLine(step.error);
|
|
354
|
+
const facts = [];
|
|
355
|
+
if (step.currentTool && step.currentToolStartedAt !== undefined && snapshotNow !== undefined)
|
|
356
|
+
facts.push(`${step.currentTool} ${formatDuration(Math.max(0, snapshotNow - step.currentToolStartedAt))}`);
|
|
357
|
+
else if (step.currentTool)
|
|
358
|
+
facts.push(step.currentTool);
|
|
359
|
+
if (step.currentPath)
|
|
360
|
+
facts.push(shortenPath(step.currentPath));
|
|
361
|
+
if (step.turnCount !== undefined)
|
|
362
|
+
facts.push(`${step.turnCount} turns`);
|
|
363
|
+
if (step.toolCount !== undefined)
|
|
364
|
+
facts.push(`${step.toolCount} tools`);
|
|
365
|
+
if (step.tokens?.total)
|
|
366
|
+
facts.push(formatTokenStat(step.tokens.total));
|
|
367
|
+
const activity = buildLiveStatusLine(step, snapshotNow);
|
|
368
|
+
if (activity && facts.length)
|
|
369
|
+
return `${activity} · ${facts.join(" · ")}`;
|
|
370
|
+
if (activity)
|
|
371
|
+
return activity;
|
|
372
|
+
return facts.join(" · ");
|
|
373
|
+
}
|
|
374
|
+
function widgetChainDetails(job, theme, width = getTermWidth()) {
|
|
375
|
+
if (!job.steps?.length)
|
|
376
|
+
return [];
|
|
377
|
+
const total = job.chainStepCount ?? job.steps.length;
|
|
378
|
+
const lines = [];
|
|
379
|
+
for (const span of buildAsyncChainStepSpans(total, job.steps.length, job.parallelGroups)) {
|
|
380
|
+
const steps = job.steps.slice(span.start, span.start + span.count);
|
|
381
|
+
if (span.isParallel) {
|
|
382
|
+
const status = aggregateStepStatus(steps);
|
|
383
|
+
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))}`);
|
|
384
|
+
continue;
|
|
385
|
+
}
|
|
386
|
+
const step = steps[0];
|
|
387
|
+
if (!step) {
|
|
388
|
+
lines.push(` ${theme.fg("dim", `◦ Step ${span.stepIndex + 1}/${total}: pending`)}`);
|
|
389
|
+
continue;
|
|
390
|
+
}
|
|
391
|
+
lines.push(...foregroundStyleWidgetStepLines(job, theme, step, "Step", span.stepIndex + 1, total, width));
|
|
392
|
+
}
|
|
393
|
+
return lines;
|
|
394
|
+
}
|
|
395
|
+
function widgetParallelAgentDetails(job, theme, width = getTermWidth()) {
|
|
396
|
+
if (!job.steps?.length)
|
|
397
|
+
return [];
|
|
398
|
+
if (job.mode !== "parallel" && job.mode !== "chain")
|
|
399
|
+
return [];
|
|
400
|
+
if (job.mode === "chain" && !job.activeParallelGroup && job.parallelGroups?.length)
|
|
401
|
+
return widgetChainDetails(job, theme, width);
|
|
402
|
+
const total = job.stepsTotal ?? job.steps.length;
|
|
403
|
+
const lines = [];
|
|
404
|
+
for (const [index, step] of job.steps.entries()) {
|
|
405
|
+
const marker = index === job.steps.length - 1 ? "└" : "├";
|
|
406
|
+
const activity = widgetStepActivity(step, job.updatedAt);
|
|
407
|
+
const itemTitle = job.mode === "parallel" || job.activeParallelGroup ? "Agent" : "Step";
|
|
408
|
+
const modelDisplay = modelThinkingBadge(theme, step.model, step.thinking);
|
|
409
|
+
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}` : ""}`)}`);
|
|
410
|
+
for (const nestedLine of formatNestedWidgetLines(step.children, theme, width, job.updatedAt, 8))
|
|
411
|
+
lines.push(` ${nestedLine}`);
|
|
412
|
+
}
|
|
413
|
+
return lines;
|
|
414
|
+
}
|
|
415
|
+
function parseParallelGroupAgentCount(label) {
|
|
416
|
+
if (!label || !label.startsWith("[") || !label.endsWith("]"))
|
|
417
|
+
return undefined;
|
|
418
|
+
const inner = label.slice(1, -1).trim();
|
|
419
|
+
if (!inner)
|
|
420
|
+
return 0;
|
|
421
|
+
return inner.split("+").map((part) => part.trim()).filter(Boolean).length;
|
|
422
|
+
}
|
|
423
|
+
function buildChainStepSpans(details) {
|
|
424
|
+
if (details.workflowGraph?.nodes?.length) {
|
|
425
|
+
const spans = [];
|
|
426
|
+
let flatCursor = 0;
|
|
427
|
+
for (const node of details.workflowGraph.nodes) {
|
|
428
|
+
if (node.stepIndex === undefined)
|
|
429
|
+
continue;
|
|
430
|
+
if (node.kind === "parallel-group" || node.kind === "dynamic-parallel-group") {
|
|
431
|
+
const childFlatIndexes = (node.children ?? [])
|
|
432
|
+
.map((child) => child.flatIndex)
|
|
433
|
+
.filter((value) => typeof value === "number");
|
|
434
|
+
const start = childFlatIndexes.length ? Math.min(...childFlatIndexes) : flatCursor;
|
|
435
|
+
const count = node.children?.length ?? 0;
|
|
436
|
+
spans.push({ stepIndex: node.stepIndex, start, count, isParallel: true, status: node.status, label: node.label, error: node.error });
|
|
437
|
+
flatCursor = Math.max(flatCursor, start + count);
|
|
438
|
+
continue;
|
|
439
|
+
}
|
|
440
|
+
const start = node.flatIndex ?? flatCursor;
|
|
441
|
+
spans.push({ stepIndex: node.stepIndex, start, count: 1, isParallel: false, status: node.status, label: node.label, error: node.error });
|
|
442
|
+
flatCursor = Math.max(flatCursor, start + 1);
|
|
443
|
+
}
|
|
444
|
+
if (spans.length)
|
|
445
|
+
return spans.sort((left, right) => left.stepIndex - right.stepIndex);
|
|
446
|
+
}
|
|
447
|
+
if (!details.chainAgents?.length)
|
|
448
|
+
return [];
|
|
449
|
+
const spans = [];
|
|
450
|
+
let start = 0;
|
|
451
|
+
for (let stepIndex = 0; stepIndex < details.chainAgents.length; stepIndex++) {
|
|
452
|
+
const label = details.chainAgents[stepIndex];
|
|
453
|
+
const parsedCount = parseParallelGroupAgentCount(label);
|
|
454
|
+
const count = parsedCount ?? 1;
|
|
455
|
+
spans.push({ stepIndex, start, count, isParallel: parsedCount !== undefined });
|
|
456
|
+
start += count;
|
|
457
|
+
}
|
|
458
|
+
return spans;
|
|
459
|
+
}
|
|
460
|
+
function isChainParallelGroupActive(details) {
|
|
461
|
+
if (details.mode !== "chain")
|
|
462
|
+
return false;
|
|
463
|
+
if (details.currentStepIndex === undefined)
|
|
464
|
+
return false;
|
|
465
|
+
return buildChainStepSpans(details).some((span) => span.stepIndex === details.currentStepIndex && span.isParallel);
|
|
466
|
+
}
|
|
467
|
+
function buildAsyncChainStepSpans(total, stepCount, parallelGroups = []) {
|
|
468
|
+
const spans = [];
|
|
469
|
+
let flatIndex = 0;
|
|
470
|
+
for (let stepIndex = 0; stepIndex < total; stepIndex++) {
|
|
471
|
+
const group = parallelGroups.find((candidate) => candidate.stepIndex === stepIndex);
|
|
472
|
+
if (group) {
|
|
473
|
+
spans.push({ stepIndex, start: group.start, count: group.count, isParallel: true });
|
|
474
|
+
flatIndex = Math.max(flatIndex, group.start + group.count);
|
|
475
|
+
continue;
|
|
476
|
+
}
|
|
477
|
+
spans.push({ stepIndex, start: flatIndex, count: flatIndex < stepCount ? 1 : 0, isParallel: false });
|
|
478
|
+
flatIndex++;
|
|
479
|
+
}
|
|
480
|
+
return spans;
|
|
481
|
+
}
|
|
482
|
+
function isDoneResult(result) {
|
|
483
|
+
if (result.interrupted || result.detached || result.timedOut || result.acceptance?.status === "blocked")
|
|
484
|
+
return false;
|
|
485
|
+
const status = result.progress?.status;
|
|
486
|
+
if (status === "completed")
|
|
487
|
+
return true;
|
|
488
|
+
if (status === "running" || status === "pending")
|
|
489
|
+
return false;
|
|
490
|
+
return result.exitCode === 0;
|
|
491
|
+
}
|
|
492
|
+
function workflowGraphHasStatus(details, statuses) {
|
|
493
|
+
return details.workflowGraph?.nodes.some((node) => statuses.includes(node.status)) ?? false;
|
|
494
|
+
}
|
|
495
|
+
function buildChainRenderEntries(details, label) {
|
|
496
|
+
if (details.mode !== "chain" || (!label.hasParallelInChain && !details.workflowGraph?.nodes.length) || label.showActiveGroupOnly)
|
|
497
|
+
return undefined;
|
|
498
|
+
const entries = [];
|
|
499
|
+
for (const span of buildChainStepSpans(details)) {
|
|
500
|
+
if (span.isParallel ? span.count === 0 : !details.results[span.start]) {
|
|
501
|
+
entries.push({
|
|
502
|
+
kind: "placeholder",
|
|
503
|
+
rowNumber: span.stepIndex + 1,
|
|
504
|
+
stepLabel: `Step ${span.stepIndex + 1}`,
|
|
505
|
+
agentName: (!span.isParallel ? details.chainAgents?.[span.stepIndex] : undefined) ?? span.label ?? details.chainAgents?.[span.stepIndex] ?? `step-${span.stepIndex + 1}`,
|
|
506
|
+
status: span.status ?? "pending",
|
|
507
|
+
error: span.error,
|
|
508
|
+
});
|
|
509
|
+
continue;
|
|
510
|
+
}
|
|
511
|
+
for (let index = span.start; index < span.start + span.count; index++) {
|
|
512
|
+
entries.push({
|
|
513
|
+
kind: "result",
|
|
514
|
+
resultIndex: index,
|
|
515
|
+
rowNumber: index + 1,
|
|
516
|
+
agentName: details.results[index]?.agent ?? details.chainAgents?.[span.stepIndex] ?? `step-${span.stepIndex + 1}`,
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
return entries;
|
|
521
|
+
}
|
|
522
|
+
function buildMultiProgressLabel(details, hasRunning) {
|
|
523
|
+
const stepSpans = buildChainStepSpans(details);
|
|
524
|
+
const hasParallelInChain = details.mode === "chain" && stepSpans.some((span) => span.isParallel);
|
|
525
|
+
const activeParallelGroup = isChainParallelGroupActive(details);
|
|
526
|
+
const itemTitle = details.mode === "parallel" || activeParallelGroup ? "Agent" : "Step";
|
|
527
|
+
if (details.mode === "parallel") {
|
|
528
|
+
const totalCount = details.totalSteps ?? details.results.length;
|
|
529
|
+
const statuses = new Array(totalCount).fill("pending");
|
|
530
|
+
for (const progress of details.progress ?? []) {
|
|
531
|
+
if (progress.index >= 0 && progress.index < totalCount)
|
|
532
|
+
statuses[progress.index] = progress.status;
|
|
533
|
+
}
|
|
534
|
+
for (let i = 0; i < details.results.length; i++) {
|
|
535
|
+
const result = details.results[i];
|
|
536
|
+
const progressFromArray = details.progress?.find((progress) => progress.index === i)
|
|
537
|
+
|| details.progress?.find((progress) => progress.agent === result.agent && progress.status === "running");
|
|
538
|
+
const index = result.progress?.index ?? progressFromArray?.index ?? i;
|
|
539
|
+
if (index < 0 || index >= totalCount)
|
|
540
|
+
continue;
|
|
541
|
+
const status = result.progress?.status
|
|
542
|
+
?? (result.timedOut
|
|
543
|
+
? "timed-out"
|
|
544
|
+
: result.interrupted || result.detached
|
|
545
|
+
? "detached"
|
|
546
|
+
: result.exitCode === 0
|
|
547
|
+
? result.acceptance?.status === "blocked" ? "blocked" : "completed"
|
|
548
|
+
: "failed");
|
|
549
|
+
statuses[index] = status;
|
|
550
|
+
}
|
|
551
|
+
const running = statuses.filter((status) => status === "running").length;
|
|
552
|
+
const succeeded = statuses.filter((status) => status === "completed").length;
|
|
553
|
+
const failed = statuses.filter((status) => status === "failed" || status === "timed-out").length;
|
|
554
|
+
const paused = statuses.filter((status) => status === "paused" || status === "detached").length;
|
|
555
|
+
const blockedCount = statuses.filter((status) => status === "blocked").length;
|
|
556
|
+
const parts = [`${succeeded}/${totalCount} succeeded`];
|
|
557
|
+
if (blockedCount)
|
|
558
|
+
parts.push(`${blockedCount} need human action`);
|
|
559
|
+
if (hasRunning)
|
|
560
|
+
parts.unshift(formatAgentRunningLabel(running));
|
|
561
|
+
if (failed > 0)
|
|
562
|
+
parts.push(`${failed} failed`);
|
|
563
|
+
if (paused > 0)
|
|
564
|
+
parts.push(`${paused} paused`);
|
|
565
|
+
const headerLabel = parts.join(" · ");
|
|
566
|
+
return { headerLabel, itemTitle, totalCount, hasParallelInChain, activeParallelGroup, groupStartIndex: 0, groupEndIndex: totalCount, showActiveGroupOnly: false };
|
|
567
|
+
}
|
|
568
|
+
if (activeParallelGroup) {
|
|
569
|
+
const currentStepIndex = details.currentStepIndex;
|
|
570
|
+
const span = stepSpans[currentStepIndex];
|
|
571
|
+
const groupSize = span?.count ?? 1;
|
|
572
|
+
const groupStart = span?.start ?? 0;
|
|
573
|
+
const groupEnd = groupStart + groupSize;
|
|
574
|
+
let running = 0;
|
|
575
|
+
let succeeded = 0;
|
|
576
|
+
let failed = 0;
|
|
577
|
+
let paused = 0;
|
|
578
|
+
let blocked = 0;
|
|
579
|
+
for (let index = groupStart; index < groupEnd; index++) {
|
|
580
|
+
const progressEntry = details.progress?.find((progress) => progress.index === index);
|
|
581
|
+
const resultEntry = details.results.find((result, position) => (result.progress?.index ?? position) === index);
|
|
582
|
+
const status = progressEntry?.status ?? resultEntry?.progress?.status;
|
|
583
|
+
if (status === "running")
|
|
584
|
+
running++;
|
|
585
|
+
else if (status === "failed" || status === "timed-out" || resultEntry?.timedOut)
|
|
586
|
+
failed++;
|
|
587
|
+
else if (status === "paused" || status === "detached" || resultEntry?.interrupted || resultEntry?.detached)
|
|
588
|
+
paused++;
|
|
589
|
+
else if (resultEntry && resultEntry.exitCode !== 0)
|
|
590
|
+
failed++;
|
|
591
|
+
else if (status === "blocked" || resultEntry?.acceptance?.status === "blocked")
|
|
592
|
+
blocked++;
|
|
593
|
+
else if (status === "completed" || (resultEntry && isDoneResult(resultEntry)))
|
|
594
|
+
succeeded++;
|
|
595
|
+
}
|
|
596
|
+
const totalSteps = details.totalSteps ?? details.chainAgents?.length ?? 1;
|
|
597
|
+
const groupParts = [`${succeeded}/${groupSize} succeeded`];
|
|
598
|
+
if (hasRunning)
|
|
599
|
+
groupParts.unshift(formatAgentRunningLabel(running));
|
|
600
|
+
if (failed > 0)
|
|
601
|
+
groupParts.push(`${failed} failed`);
|
|
602
|
+
if (paused > 0)
|
|
603
|
+
groupParts.push(`${paused} paused`);
|
|
604
|
+
if (blocked > 0)
|
|
605
|
+
groupParts.push(`${blocked} need human action`);
|
|
606
|
+
const headerLabel = `step ${currentStepIndex + 1}/${totalSteps} · parallel group: ${groupParts.join(" · ")}`;
|
|
607
|
+
return { headerLabel, itemTitle, totalCount: groupSize, hasParallelInChain, activeParallelGroup, groupStartIndex: groupStart, groupEndIndex: groupEnd, showActiveGroupOnly: true };
|
|
608
|
+
}
|
|
609
|
+
if (details.mode === "chain" && details.chainAgents?.length) {
|
|
610
|
+
const totalCount = details.totalSteps ?? details.chainAgents.length;
|
|
611
|
+
const doneLogical = stepSpans.filter((span) => {
|
|
612
|
+
if (span.status && span.status !== "completed")
|
|
613
|
+
return false;
|
|
614
|
+
if (span.count === 0)
|
|
615
|
+
return span.status === "completed";
|
|
616
|
+
for (let index = span.start; index < span.start + span.count; index++) {
|
|
617
|
+
const progressEntry = details.progress?.find((progress) => progress.index === index);
|
|
618
|
+
const resultEntry = details.results.find((result) => result.progress?.index === index) ?? details.results[index];
|
|
619
|
+
if (progressEntry?.status === "running" || progressEntry?.status === "pending" || progressEntry?.status === "failed")
|
|
620
|
+
return false;
|
|
621
|
+
if (!resultEntry || !isDoneResult(resultEntry))
|
|
622
|
+
return false;
|
|
623
|
+
}
|
|
624
|
+
return true;
|
|
625
|
+
}).length;
|
|
626
|
+
const currentStep = details.currentStepIndex !== undefined ? details.currentStepIndex + 1 : Math.min(totalCount, doneLogical + (hasRunning ? 1 : 0));
|
|
627
|
+
const headerLabel = hasRunning ? `step ${currentStep}/${totalCount}` : `step ${doneLogical}/${totalCount}`;
|
|
628
|
+
return { headerLabel, itemTitle, totalCount, hasParallelInChain, activeParallelGroup, groupStartIndex: 0, groupEndIndex: details.results.length, showActiveGroupOnly: false };
|
|
629
|
+
}
|
|
630
|
+
const totalCount = details.totalSteps ?? details.results.length;
|
|
631
|
+
const currentStep = details.currentStepIndex !== undefined ? details.currentStepIndex + 1 : Math.min(totalCount, details.results.filter(isDoneResult).length + (hasRunning ? 1 : 0));
|
|
632
|
+
const done = details.results.filter(isDoneResult).length;
|
|
633
|
+
const headerLabel = hasRunning ? `step ${currentStep}/${totalCount}` : `step ${done}/${totalCount}`;
|
|
634
|
+
return { headerLabel, itemTitle, totalCount, hasParallelInChain, activeParallelGroup, groupStartIndex: 0, groupEndIndex: details.results.length, showActiveGroupOnly: false };
|
|
635
|
+
}
|
|
636
|
+
function resultRowLabel(details, label, resultIndex, stepNumber) {
|
|
637
|
+
if (details.mode === "chain" && label.hasParallelInChain) {
|
|
638
|
+
const span = buildChainStepSpans(details).find((candidate) => resultIndex >= candidate.start && resultIndex < candidate.start + candidate.count);
|
|
639
|
+
if (span?.isParallel)
|
|
640
|
+
return `Agent ${resultIndex - span.start + 1}/${span.count}`;
|
|
641
|
+
if (span)
|
|
642
|
+
return `Step ${span.stepIndex + 1}`;
|
|
643
|
+
}
|
|
644
|
+
if (label.itemTitle === "Agent") {
|
|
645
|
+
const localStepNumber = label.activeParallelGroup
|
|
646
|
+
? Math.max(1, stepNumber - label.groupStartIndex)
|
|
647
|
+
: stepNumber;
|
|
648
|
+
return `Agent ${localStepNumber}/${label.totalCount}`;
|
|
649
|
+
}
|
|
650
|
+
return `Step ${stepNumber}`;
|
|
651
|
+
}
|
|
652
|
+
function widgetStats(job, theme) {
|
|
653
|
+
const parts = [];
|
|
654
|
+
const stepsTotal = job.stepsTotal ?? (job.agents?.length ?? 1);
|
|
655
|
+
if (job.activeParallelGroup) {
|
|
656
|
+
const running = job.runningSteps ?? (job.status === "running" ? 1 : 0);
|
|
657
|
+
const succeeded = job.completedSteps ?? (job.status === "complete" ? stepsTotal : 0);
|
|
658
|
+
if (job.mode === "parallel") {
|
|
659
|
+
if (job.status === "running" && running > 0)
|
|
660
|
+
parts.push(formatAgentRunningLabel(running));
|
|
661
|
+
if (stepsTotal > 0)
|
|
662
|
+
parts.push(`${succeeded}/${stepsTotal} succeeded`);
|
|
663
|
+
}
|
|
664
|
+
else {
|
|
665
|
+
const activeGroup = job.currentStep !== undefined
|
|
666
|
+
? job.parallelGroups?.find((group) => job.currentStep >= group.start && job.currentStep < group.start + group.count)
|
|
667
|
+
: job.parallelGroups?.find((group) => group.start === 0);
|
|
668
|
+
const logicalStep = activeGroup?.stepIndex ?? job.currentStep ?? 0;
|
|
669
|
+
const total = job.chainStepCount ?? stepsTotal;
|
|
670
|
+
const groupParts = [`${succeeded}/${stepsTotal} succeeded`];
|
|
671
|
+
if (job.status === "running" && running > 0)
|
|
672
|
+
groupParts.unshift(formatAgentRunningLabel(running));
|
|
673
|
+
parts.push(`step ${logicalStep + 1}/${total} · parallel group: ${groupParts.join(" · ")}`);
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
else if (job.currentStep !== undefined) {
|
|
677
|
+
if (job.mode === "chain" && job.parallelGroups?.length) {
|
|
678
|
+
const total = job.chainStepCount ?? stepsTotal;
|
|
679
|
+
parts.push(`step ${flatToLogicalStepIndex(job.currentStep, total, job.parallelGroups) + 1}/${total}`);
|
|
680
|
+
}
|
|
681
|
+
else {
|
|
682
|
+
parts.push(`step ${job.currentStep + 1}/${stepsTotal}`);
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
else if (stepsTotal > 1) {
|
|
686
|
+
parts.push(`steps ${stepsTotal}`);
|
|
687
|
+
}
|
|
688
|
+
if (job.toolCount !== undefined)
|
|
689
|
+
parts.push(formatToolUseStat(job.toolCount));
|
|
690
|
+
if (job.totalTokens?.total)
|
|
691
|
+
parts.push(formatTokenStat(job.totalTokens.total));
|
|
692
|
+
if (job.status !== "queued" && job.startedAt !== undefined && job.updatedAt !== undefined)
|
|
693
|
+
parts.push(formatDuration(Math.max(0, job.updatedAt - job.startedAt)));
|
|
694
|
+
return statJoin(theme, parts);
|
|
695
|
+
}
|
|
696
|
+
function widgetStepStats(theme, step) {
|
|
697
|
+
return statJoin(theme, [
|
|
698
|
+
step.turnCount !== undefined ? `${step.turnCount} turns` : "",
|
|
699
|
+
step.toolCount !== undefined ? formatToolUseStat(step.toolCount) : "",
|
|
700
|
+
step.tokens?.total ? formatTokenStat(step.tokens.total) : "",
|
|
701
|
+
step.durationMs !== undefined ? formatDuration(step.durationMs) : "",
|
|
702
|
+
]);
|
|
703
|
+
}
|
|
704
|
+
function modelThinkingBadge(theme, model, thinking) {
|
|
705
|
+
const label = formatModelThinking(model, thinking);
|
|
706
|
+
return label ? theme.fg("dim", ` (${label})`) : "";
|
|
707
|
+
}
|
|
708
|
+
function modelStat(theme, model) {
|
|
709
|
+
return model ? ` ${theme.fg("dim", "·")} ${theme.fg("dim", model)}` : "";
|
|
710
|
+
}
|
|
711
|
+
function widgetStepActivityLine(step, width, expanded, snapshotNow) {
|
|
712
|
+
if ((step.status === "failed" || step.status === "timed-out") && step.error)
|
|
713
|
+
return firstOutputLine(step.error);
|
|
714
|
+
const toolLine = formatCurrentToolLine(step, width, expanded, snapshotNow);
|
|
715
|
+
if (toolLine)
|
|
716
|
+
return toolLine;
|
|
717
|
+
const activity = buildLiveStatusLine(step, snapshotNow);
|
|
718
|
+
if (activity)
|
|
719
|
+
return activity;
|
|
720
|
+
if (step.status === "running")
|
|
721
|
+
return "thinking…";
|
|
722
|
+
return "";
|
|
723
|
+
}
|
|
724
|
+
function widgetOutputPath(job, step) {
|
|
725
|
+
if (typeof step.index !== "number")
|
|
726
|
+
return undefined;
|
|
727
|
+
return path.join(job.asyncDir, `output-${step.index}.log`);
|
|
728
|
+
}
|
|
729
|
+
function nestedRunName(run) {
|
|
730
|
+
if (run.agent)
|
|
731
|
+
return run.agent;
|
|
732
|
+
if (run.agents?.length)
|
|
733
|
+
return formatWidgetAgents(run.agents);
|
|
734
|
+
return run.id;
|
|
735
|
+
}
|
|
736
|
+
function nestedStatusGlyph(state, theme, seed) {
|
|
737
|
+
if (state === "running")
|
|
738
|
+
return theme.fg("accent", runningGlyph(seed));
|
|
739
|
+
if (state === "complete" || state === "completed")
|
|
740
|
+
return theme.fg("success", "✓");
|
|
741
|
+
if (state === "failed")
|
|
742
|
+
return theme.fg("error", "✗");
|
|
743
|
+
if (state === "blocked")
|
|
744
|
+
return theme.fg("warning", "■");
|
|
745
|
+
if (state === "paused")
|
|
746
|
+
return theme.fg("warning", "■");
|
|
747
|
+
return theme.fg("muted", "◦");
|
|
748
|
+
}
|
|
749
|
+
function nestedRunSeed(run) {
|
|
750
|
+
return runningSeed(run.lastUpdate, run.lastActivityAt, run.currentStep, run.toolCount, run.turnCount, run.totalTokens?.total, run.currentToolStartedAt);
|
|
751
|
+
}
|
|
752
|
+
function nestedActivity(input, state, snapshotNow) {
|
|
753
|
+
const facts = [];
|
|
754
|
+
if (input.currentTool && input.currentToolStartedAt !== undefined && snapshotNow !== undefined)
|
|
755
|
+
facts.push(`${input.currentTool} ${formatDuration(Math.max(0, snapshotNow - input.currentToolStartedAt))}`);
|
|
756
|
+
else if (input.currentTool)
|
|
757
|
+
facts.push(input.currentTool);
|
|
758
|
+
if (input.currentPath)
|
|
759
|
+
facts.push(shortenPath(input.currentPath));
|
|
760
|
+
if (input.turnCount !== undefined)
|
|
761
|
+
facts.push(`${input.turnCount} turns`);
|
|
762
|
+
if (input.toolCount !== undefined)
|
|
763
|
+
facts.push(`${input.toolCount} tools`);
|
|
764
|
+
const activity = buildLiveStatusLine(input, snapshotNow);
|
|
765
|
+
if (activity && facts.length)
|
|
766
|
+
return `${activity} · ${facts.join(" · ")}`;
|
|
767
|
+
if (activity)
|
|
768
|
+
return activity;
|
|
769
|
+
if (facts.length)
|
|
770
|
+
return facts.join(" · ");
|
|
771
|
+
if (state === "running")
|
|
772
|
+
return "thinking…";
|
|
773
|
+
if (state === "queued" || state === "pending")
|
|
774
|
+
return "queued…";
|
|
775
|
+
if (state === "blocked")
|
|
776
|
+
return "Needs your action";
|
|
777
|
+
if (state === "paused")
|
|
778
|
+
return "Paused";
|
|
779
|
+
if (state === "failed")
|
|
780
|
+
return "Failed";
|
|
781
|
+
return "Done";
|
|
782
|
+
}
|
|
783
|
+
/** Nested runs only render in the expanded widget; the collapsed view is one line per run. */
|
|
784
|
+
function formatNestedWidgetLines(children, theme, width, snapshotNow, lineBudget = 12) {
|
|
785
|
+
if (!children?.length || lineBudget <= 0)
|
|
786
|
+
return [];
|
|
787
|
+
const lines = [];
|
|
788
|
+
const maxDepth = 2;
|
|
789
|
+
const append = (items, depth, prefix) => {
|
|
790
|
+
if (!items?.length || lines.length >= lineBudget)
|
|
791
|
+
return;
|
|
792
|
+
if (depth > maxDepth) {
|
|
793
|
+
const aggregate = formatNestedAggregate(items);
|
|
794
|
+
if (aggregate && lines.length < lineBudget)
|
|
795
|
+
lines.push(theme.fg("dim", `${prefix}↳ ${aggregate}`));
|
|
796
|
+
return;
|
|
797
|
+
}
|
|
798
|
+
for (let index = 0; index < items.length; index++) {
|
|
799
|
+
const child = items[index];
|
|
800
|
+
if (lines.length >= lineBudget) {
|
|
801
|
+
const aggregate = formatNestedAggregate(items.slice(index));
|
|
802
|
+
if (aggregate)
|
|
803
|
+
lines[lines.length - 1] = theme.fg("dim", `${prefix}↳ ${aggregate}`);
|
|
804
|
+
return;
|
|
805
|
+
}
|
|
806
|
+
const activity = nestedActivity(child, child.state, snapshotNow ?? child.lastUpdate);
|
|
807
|
+
const error = child.error ? ` · ${child.error}` : "";
|
|
808
|
+
lines.push(theme.fg("dim", `${prefix}↳ ${nestedStatusGlyph(child.state, theme, nestedRunSeed(child))} ${nestedRunName(child)} · ${child.state} · ${activity}${error}`));
|
|
809
|
+
if (depth === maxDepth) {
|
|
810
|
+
const aggregate = formatNestedAggregate([...(child.steps?.flatMap((step) => step.children ?? []) ?? []), ...(child.children ?? [])]);
|
|
811
|
+
if (aggregate && lines.length < lineBudget)
|
|
812
|
+
lines.push(theme.fg("dim", `${prefix} ↳ ${aggregate}`));
|
|
813
|
+
continue;
|
|
814
|
+
}
|
|
815
|
+
for (const step of child.steps ?? []) {
|
|
816
|
+
if (lines.length >= lineBudget)
|
|
817
|
+
return;
|
|
818
|
+
lines.push(theme.fg("dim", `${prefix} ↳ ${nestedStatusGlyph(step.status, theme)} ${step.agent} · ${step.status} · ${nestedActivity(step, step.status, snapshotNow ?? child.lastUpdate)}`));
|
|
819
|
+
append(step.children, depth + 1, `${prefix} `);
|
|
820
|
+
}
|
|
821
|
+
append(child.children, depth + 1, `${prefix} `);
|
|
822
|
+
}
|
|
823
|
+
};
|
|
824
|
+
append(children, 0, "");
|
|
825
|
+
return lines.map((line) => truncLine(line, width));
|
|
826
|
+
}
|
|
827
|
+
function foregroundStyleWidgetStepLines(job, theme, step, itemTitle, index, total, width) {
|
|
828
|
+
const status = widgetStepStatus(step.status, theme);
|
|
829
|
+
const stats = widgetStepStats(theme, step);
|
|
830
|
+
const modelDisplay = modelThinkingBadge(theme, step.model, step.thinking);
|
|
831
|
+
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}` : ""}`];
|
|
832
|
+
const activity = widgetStepActivityLine(step, width, true, job.updatedAt);
|
|
833
|
+
if (activity)
|
|
834
|
+
lines.push(` ${theme.fg("dim", `⎿ ${activity}`)}`);
|
|
835
|
+
for (const nestedLine of formatNestedWidgetLines(step.children, theme, width, job.updatedAt)) {
|
|
836
|
+
lines.push(` ${nestedLine}`);
|
|
837
|
+
}
|
|
838
|
+
if (step.status === "running") {
|
|
839
|
+
const output = widgetOutputPath(job, step);
|
|
840
|
+
if (output)
|
|
841
|
+
lines.push(` ${theme.fg("dim", `output: ${shortenPath(output)}`)}`);
|
|
842
|
+
const liveStatus = buildLiveStatusLine(step, job.updatedAt);
|
|
843
|
+
if (liveStatus && liveStatus !== activity)
|
|
844
|
+
lines.push(` ${theme.fg("accent", liveStatus)}`);
|
|
845
|
+
for (const tool of step.recentTools?.slice(-3) ?? []) {
|
|
846
|
+
const maxArgsLen = Math.max(40, width - 30);
|
|
847
|
+
const argsPreview = tool.args.length <= maxArgsLen ? tool.args : `${tool.args.slice(0, maxArgsLen)}...`;
|
|
848
|
+
lines.push(` ${theme.fg("dim", `${tool.tool}${argsPreview ? `: ${argsPreview}` : ""}`)}`);
|
|
849
|
+
}
|
|
850
|
+
for (const line of step.recentOutput?.slice(-5) ?? []) {
|
|
851
|
+
lines.push(` ${theme.fg("dim", line)}`);
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
return lines;
|
|
855
|
+
}
|
|
856
|
+
function foregroundStyleWidgetDetails(job, theme, width) {
|
|
857
|
+
if (!job.steps?.length)
|
|
858
|
+
return [
|
|
859
|
+
` ${theme.fg("dim", `⎿ ${widgetActivity(job)}`)}`,
|
|
860
|
+
...formatNestedWidgetLines(job.nestedChildren, theme, width, job.updatedAt).map((line) => ` ${line}`),
|
|
861
|
+
];
|
|
862
|
+
if (job.mode === "chain" && !job.activeParallelGroup && job.parallelGroups?.length)
|
|
863
|
+
return widgetChainDetails(job, theme, width);
|
|
864
|
+
const total = job.stepsTotal ?? job.steps.length;
|
|
865
|
+
const itemTitle = job.mode === "parallel" || job.activeParallelGroup ? "Agent" : "Step";
|
|
866
|
+
const lines = [];
|
|
867
|
+
for (const [index, step] of job.steps.entries()) {
|
|
868
|
+
lines.push(...foregroundStyleWidgetStepLines(job, theme, step, itemTitle, index + 1, total, width));
|
|
869
|
+
}
|
|
870
|
+
const attached = new Set(job.steps.flatMap((step) => step.children?.map((child) => child.id) ?? []));
|
|
871
|
+
const unattached = job.nestedChildren?.filter((child) => !attached.has(child.id)) ?? [];
|
|
872
|
+
for (const nestedLine of formatNestedWidgetLines(unattached, theme, width, job.updatedAt)) {
|
|
873
|
+
lines.push(` ${nestedLine}`);
|
|
874
|
+
}
|
|
875
|
+
return lines;
|
|
876
|
+
}
|
|
877
|
+
/** The expanded single-run view; the collapsed view never reaches this path. */
|
|
878
|
+
function buildSingleWidgetLines(job, theme, width) {
|
|
879
|
+
const stats = widgetStats(job, theme);
|
|
880
|
+
const count = job.mode === "chain" ? job.chainStepCount : job.stepsTotal ?? job.agents?.length ?? job.steps?.length;
|
|
881
|
+
const mode = widgetJobName(job);
|
|
882
|
+
const title = `async subagent ${mode}${count && count > 1 ? ` (${count})` : ""}`;
|
|
883
|
+
return [
|
|
884
|
+
`${theme.fg("toolTitle", themeBold(theme, title))} ${theme.fg("dim", "· background")}`,
|
|
885
|
+
`${widgetStatusGlyph(job, theme)} ${themeBold(theme, mode)}${stats ? ` ${theme.fg("dim", "·")} ${stats}` : ""}`,
|
|
886
|
+
...foregroundStyleWidgetDetails(job, theme, width),
|
|
887
|
+
].map((line) => truncLine(line, width));
|
|
888
|
+
}
|
|
889
|
+
/** Collapsed rows carry the live tool inline, since detail lines wait for Ctrl+O. */
|
|
890
|
+
function collapsedJobRow(job, theme, width) {
|
|
891
|
+
const stats = widgetStats(job, theme);
|
|
892
|
+
// The job root mirrors an active step's tool but drops its args, so prefer the step itself.
|
|
893
|
+
const runningSteps = job.steps?.filter((step) => step.status === "running") ?? [];
|
|
894
|
+
const soloStep = runningSteps.length === 1 ? runningSteps[0] : undefined;
|
|
895
|
+
const activity = job.status !== "running"
|
|
896
|
+
? widgetActivity(job, false)
|
|
897
|
+
: soloStep
|
|
898
|
+
? widgetStepActivityLine(soloStep, width, false, job.updatedAt)
|
|
899
|
+
: widgetActivity(job, false);
|
|
900
|
+
return `${widgetStatusGlyph(job, theme)} ${themeBold(theme, widgetJobName(job))}${stats ? ` ${theme.fg("dim", "·")} ${stats}` : ""}${activity ? ` ${theme.fg("dim", "·")} ${theme.fg("dim", activity)}` : ""}`;
|
|
901
|
+
}
|
|
902
|
+
function fitWidgetLineBudget(lines, theme, width, expanded) {
|
|
903
|
+
const rows = process.stdout.rows || 30;
|
|
904
|
+
const budget = expanded
|
|
905
|
+
? Math.max(4, Math.min(24, Math.floor(rows * 0.4)))
|
|
906
|
+
: MAX_WIDGET_JOBS + 2;
|
|
907
|
+
if (lines.length <= budget)
|
|
908
|
+
return lines;
|
|
909
|
+
const visibleLines = Math.max(1, budget - 1);
|
|
910
|
+
const hiddenCount = lines.length - visibleLines;
|
|
911
|
+
const hint = expanded
|
|
912
|
+
? `… ${hiddenCount} live-detail lines hidden`
|
|
913
|
+
: `… ${hiddenCount} lines hidden · Ctrl+O expands`;
|
|
914
|
+
return [...lines.slice(0, visibleLines), truncLine(theme.fg("dim", hint), width)];
|
|
915
|
+
}
|
|
916
|
+
function buildWidgetComponent(jobs, isExpanded) {
|
|
917
|
+
return (_tui, theme) => ({
|
|
918
|
+
render(availableWidth) {
|
|
919
|
+
// Text pads one column on each side, so build against its inner width on every render.
|
|
920
|
+
const width = Math.max(1, availableWidth - 2);
|
|
921
|
+
const expanded = isExpanded();
|
|
922
|
+
const lines = fitWidgetLineBudget(buildWidgetLines(jobs, theme, width, expanded), theme, width, expanded);
|
|
923
|
+
const container = new Container();
|
|
924
|
+
for (const line of lines)
|
|
925
|
+
container.addChild(new Text(line, 1, 0));
|
|
926
|
+
return container.render(availableWidth);
|
|
927
|
+
},
|
|
928
|
+
invalidate() { },
|
|
929
|
+
});
|
|
930
|
+
}
|
|
931
|
+
export function buildWidgetLines(jobs, theme, width = getTermWidth(), expanded = false) {
|
|
932
|
+
if (jobs.length === 0)
|
|
933
|
+
return [];
|
|
934
|
+
if (jobs.length === 1 && expanded)
|
|
935
|
+
return buildSingleWidgetLines(jobs[0], theme, width);
|
|
936
|
+
const running = jobs.filter((job) => job.status === "running");
|
|
937
|
+
const queued = jobs.filter((job) => job.status === "queued");
|
|
938
|
+
const finished = jobs.filter((job) => job.status !== "running" && job.status !== "queued");
|
|
939
|
+
const jobItem = (job) => {
|
|
940
|
+
if (!expanded)
|
|
941
|
+
return [collapsedJobRow(job, theme, width)];
|
|
942
|
+
const stats = widgetStats(job, theme);
|
|
943
|
+
return [
|
|
944
|
+
`${widgetStatusGlyph(job, theme)} ${themeBold(theme, widgetJobName(job))}${stats ? ` ${theme.fg("dim", "·")} ${stats}` : ""}`,
|
|
945
|
+
` ${theme.fg("dim", `⎿ ${widgetActivity(job)}`)}`,
|
|
946
|
+
...widgetParallelAgentDetails(job, theme, width),
|
|
947
|
+
];
|
|
948
|
+
};
|
|
949
|
+
const items = [];
|
|
950
|
+
let hiddenRunning = 0;
|
|
951
|
+
let hiddenFinished = 0;
|
|
952
|
+
let queuedShown = false;
|
|
953
|
+
let slots = MAX_WIDGET_JOBS;
|
|
954
|
+
for (const job of running) {
|
|
955
|
+
if (slots <= 0) {
|
|
956
|
+
hiddenRunning++;
|
|
957
|
+
continue;
|
|
958
|
+
}
|
|
959
|
+
items.push(jobItem(job));
|
|
960
|
+
slots--;
|
|
961
|
+
}
|
|
962
|
+
if (queued.length > 0 && slots > 0) {
|
|
963
|
+
// One collapsed queued run has room for its own name; a backlog collapses to a count.
|
|
964
|
+
items.push(queued.length === 1 && !expanded ? jobItem(queued[0]) : [`${theme.fg("muted", "◦")} ${theme.fg("dim", `${queued.length} queued`)}`]);
|
|
965
|
+
queuedShown = true;
|
|
966
|
+
slots--;
|
|
967
|
+
}
|
|
968
|
+
for (const job of finished) {
|
|
969
|
+
if (slots <= 0) {
|
|
970
|
+
hiddenFinished++;
|
|
971
|
+
continue;
|
|
972
|
+
}
|
|
973
|
+
items.push(jobItem(job));
|
|
974
|
+
slots--;
|
|
975
|
+
}
|
|
976
|
+
const hiddenQueued = queued.length > 0 && !queuedShown ? queued.length : 0;
|
|
977
|
+
const hiddenTotal = hiddenRunning + hiddenFinished + hiddenQueued;
|
|
978
|
+
if (hiddenTotal > 0) {
|
|
979
|
+
const parts = [];
|
|
980
|
+
if (hiddenRunning > 0)
|
|
981
|
+
parts.push(`${hiddenRunning} running`);
|
|
982
|
+
if (hiddenQueued > 0)
|
|
983
|
+
parts.push(`${hiddenQueued} queued`);
|
|
984
|
+
if (hiddenFinished > 0)
|
|
985
|
+
parts.push(`${hiddenFinished} finished`);
|
|
986
|
+
items.push([theme.fg("dim", `+${hiddenTotal} more (${parts.join(", ")})`)]);
|
|
987
|
+
}
|
|
988
|
+
const hint = running.length > 0 && !expanded ? ` ${theme.fg("dim", "·")} ${theme.fg("accent", "Ctrl+O")}` : "";
|
|
989
|
+
if (items.length === 1 && !expanded)
|
|
990
|
+
return [truncLine(`${items[0][0]}${hint}`, width)];
|
|
991
|
+
const lines = [];
|
|
992
|
+
const hasActive = running.length > 0 || queued.length > 0;
|
|
993
|
+
const headerGlyph = running.length > 0 ? runningGlyph(widgetJobsRunningSeed(running)) : hasActive ? "●" : "○";
|
|
994
|
+
lines.push(truncLine(`${theme.fg(hasActive ? "accent" : "dim", headerGlyph)} ${theme.fg(hasActive ? "accent" : "dim", "Async agents")} ${theme.fg("dim", "· background")}${hint}`, width));
|
|
995
|
+
for (let i = 0; i < items.length; i++) {
|
|
996
|
+
const item = items[i];
|
|
997
|
+
const last = i === items.length - 1;
|
|
998
|
+
const branch = last ? "└─" : "├─";
|
|
999
|
+
const continuation = last ? " " : "│ ";
|
|
1000
|
+
lines.push(truncLine(`${theme.fg("dim", branch)} ${item[0]}`, width));
|
|
1001
|
+
for (const detail of item.slice(1)) {
|
|
1002
|
+
lines.push(truncLine(`${theme.fg("dim", continuation)} ${detail}`, width));
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
return lines;
|
|
1006
|
+
}
|
|
1007
|
+
/**
|
|
1008
|
+
* Render the async jobs widget
|
|
1009
|
+
*/
|
|
1010
|
+
export function renderWidget(ctx, jobs) {
|
|
1011
|
+
if (jobs.length === 0) {
|
|
1012
|
+
if (isTuiContext(ctx))
|
|
1013
|
+
ctx.ui.setWidget(WIDGET_KEY, undefined);
|
|
1014
|
+
return;
|
|
1015
|
+
}
|
|
1016
|
+
if (!isTuiContext(ctx))
|
|
1017
|
+
return;
|
|
1018
|
+
ctx.ui.setWidget(WIDGET_KEY, buildWidgetComponent(jobs, () => ctx.ui.getToolsExpanded()));
|
|
1019
|
+
}
|
|
1020
|
+
function renderSingleCompact(d, r, theme, isError = false) {
|
|
1021
|
+
const expandKey = keyText("app.tools.expand");
|
|
1022
|
+
const output = r.truncation?.text || getSingleResultOutput(r);
|
|
1023
|
+
const statusOutput = output || (d.intercomDelivery?.delivered ? d.intercomDelivery.summary : "");
|
|
1024
|
+
const progress = r.progress || r.progressSummary;
|
|
1025
|
+
const isRunning = !isError && r.progress?.status === "running";
|
|
1026
|
+
const contextBadge = d.context === "fork" ? theme.fg("warning", " [fork]") : "";
|
|
1027
|
+
const stats = statJoin(theme, [
|
|
1028
|
+
r.usage?.turns ? `⟳ ${r.usage.turns}` : "",
|
|
1029
|
+
formatProgressStats(theme, progress),
|
|
1030
|
+
]);
|
|
1031
|
+
const c = new Container();
|
|
1032
|
+
const width = getTermWidth() - 4;
|
|
1033
|
+
const modelDisplay = modelThinkingBadge(theme, r.model);
|
|
1034
|
+
c.addChild(new TruncatedText(`${isError ? theme.fg("error", "✗") : resultGlyph(r, statusOutput, theme, isRunning)} ${theme.fg("toolTitle", theme.bold(r.agent))}${modelDisplay}${contextBadge}${stats ? ` ${theme.fg("dim", "·")} ${stats}` : ""}`));
|
|
1035
|
+
if (isRunning && r.progress) {
|
|
1036
|
+
const progressSnapshotNow = snapshotNowForProgress(r.progress);
|
|
1037
|
+
const activity = compactCurrentActivity(r.progress);
|
|
1038
|
+
c.addChild(new Text(truncLine(theme.fg("dim", ` ⎿ ${activity}`), width), 0, 0));
|
|
1039
|
+
const liveStatus = buildLiveStatusLine(r.progress, progressSnapshotNow);
|
|
1040
|
+
if (liveStatus && liveStatus !== activity)
|
|
1041
|
+
c.addChild(new Text(truncLine(theme.fg("dim", ` ${liveStatus}`), width), 0, 0));
|
|
1042
|
+
if (expandKey)
|
|
1043
|
+
c.addChild(new Text(truncLine(theme.fg("accent", ` Press ${expandKey} for live detail`), width), 0, 0));
|
|
1044
|
+
if (r.artifactPaths)
|
|
1045
|
+
c.addChild(new Text(truncLine(theme.fg("dim", ` output: ${shortenPath(r.artifactPaths.outputPath)}`), width), 0, 0));
|
|
1046
|
+
return c;
|
|
1047
|
+
}
|
|
1048
|
+
c.addChild(new TruncatedText(theme.fg("dim", ` ⎿ ${resultStatusLine(r, statusOutput)}`)));
|
|
1049
|
+
const preview = firstOutputLine(output);
|
|
1050
|
+
if (preview && r.exitCode === 0 && !hasEmptyTextOutputWithoutOutputTarget(r.task, output)) {
|
|
1051
|
+
c.addChild(new TruncatedText(theme.fg("dim", ` ${preview}`)));
|
|
1052
|
+
}
|
|
1053
|
+
if (r.sessionFile)
|
|
1054
|
+
c.addChild(new TruncatedText(theme.fg("dim", ` session: ${shortenPath(r.sessionFile)}`)));
|
|
1055
|
+
if (r.artifactPaths)
|
|
1056
|
+
c.addChild(new TruncatedText(theme.fg("dim", ` output: ${shortenPath(r.artifactPaths.outputPath)}`)));
|
|
1057
|
+
if (r.truncation?.artifactPath)
|
|
1058
|
+
c.addChild(new TruncatedText(theme.fg("dim", ` full output: ${shortenPath(r.truncation.artifactPath)}`)));
|
|
1059
|
+
c.addChild(new TruncatedText(theme.fg("dim", ` ${keyText("app.tools.expand")} ${d.intercomDelivery?.delivered ? "receipt details" : "full response"}`)));
|
|
1060
|
+
return c;
|
|
1061
|
+
}
|
|
1062
|
+
function renderMultiCompact(d, theme, isError = false) {
|
|
1063
|
+
const expandKey = keyText("app.tools.expand");
|
|
1064
|
+
const hasRunning = !isError && (d.progress?.some((p) => p.status === "running")
|
|
1065
|
+
|| d.results.some((r) => r.progress?.status === "running")
|
|
1066
|
+
|| workflowGraphHasStatus(d, ["running"]));
|
|
1067
|
+
const failed = isError || d.results.some((r) => r.exitCode !== 0 && r.progress?.status !== "running")
|
|
1068
|
+
|| workflowGraphHasStatus(d, ["failed", "timed-out"]);
|
|
1069
|
+
const blocked = d.results.some((r) => r.acceptance?.status === "blocked" && r.exitCode === 0);
|
|
1070
|
+
const paused = d.results.some((r) => (r.interrupted || r.detached) && r.progress?.status !== "running")
|
|
1071
|
+
|| workflowGraphHasStatus(d, ["paused", "detached"]);
|
|
1072
|
+
let totalSummary = d.progressSummary;
|
|
1073
|
+
if (!totalSummary) {
|
|
1074
|
+
let sawProgress = false;
|
|
1075
|
+
const summary = { toolCount: 0, tokens: 0, durationMs: 0 };
|
|
1076
|
+
for (const r of d.results) {
|
|
1077
|
+
const prog = r.progress || r.progressSummary;
|
|
1078
|
+
if (!prog)
|
|
1079
|
+
continue;
|
|
1080
|
+
sawProgress = true;
|
|
1081
|
+
summary.toolCount += prog.toolCount;
|
|
1082
|
+
summary.tokens += prog.tokens;
|
|
1083
|
+
summary.durationMs = d.mode === "chain" ? summary.durationMs + prog.durationMs : Math.max(summary.durationMs, prog.durationMs);
|
|
1084
|
+
}
|
|
1085
|
+
if (sawProgress)
|
|
1086
|
+
totalSummary = summary;
|
|
1087
|
+
}
|
|
1088
|
+
const multiLabel = buildMultiProgressLabel(d, hasRunning);
|
|
1089
|
+
const itemTitle = multiLabel.itemTitle;
|
|
1090
|
+
const stats = statJoin(theme, [multiLabel.headerLabel, formatProgressStats(theme, totalSummary)]);
|
|
1091
|
+
const glyph = hasRunning
|
|
1092
|
+
? theme.fg("accent", runningGlyph(runningSeed(progressRunningSeed(totalSummary), d.currentStepIndex)))
|
|
1093
|
+
: failed
|
|
1094
|
+
? theme.fg("error", "✗")
|
|
1095
|
+
: paused || blocked
|
|
1096
|
+
? theme.fg("warning", "■")
|
|
1097
|
+
: theme.fg("success", "✓");
|
|
1098
|
+
const contextBadge = d.context === "fork" ? theme.fg("warning", " [fork]") : "";
|
|
1099
|
+
const c = new Container();
|
|
1100
|
+
const width = getTermWidth() - 4;
|
|
1101
|
+
c.addChild(new TruncatedText(`${glyph} ${theme.fg("toolTitle", theme.bold(d.mode))}${contextBadge}${stats ? ` ${theme.fg("dim", "·")} ${stats}` : ""}`));
|
|
1102
|
+
const useResultsDirectly = multiLabel.hasParallelInChain || !d.chainAgents?.length;
|
|
1103
|
+
const displayStart = multiLabel.showActiveGroupOnly ? multiLabel.groupStartIndex : 0;
|
|
1104
|
+
const displayEnd = multiLabel.showActiveGroupOnly ? multiLabel.groupEndIndex : (useResultsDirectly ? d.results.length : d.chainAgents.length);
|
|
1105
|
+
const chainEntries = buildChainRenderEntries(d, multiLabel);
|
|
1106
|
+
const renderEntries = chainEntries ?? Array.from({ length: displayEnd - displayStart }, (_, offset) => {
|
|
1107
|
+
const i = displayStart + offset;
|
|
1108
|
+
const r = d.results[i];
|
|
1109
|
+
const fallbackLabel = itemTitle.toLowerCase();
|
|
1110
|
+
const rowNumber = multiLabel.showActiveGroupOnly ? (i - multiLabel.groupStartIndex + 1) : (i + 1);
|
|
1111
|
+
return { kind: "result", resultIndex: i, rowNumber, agentName: useResultsDirectly ? (r?.agent || `${fallbackLabel}-${rowNumber}`) : (d.chainAgents[i] || r?.agent || `${fallbackLabel}-${rowNumber}`) };
|
|
1112
|
+
});
|
|
1113
|
+
const maxCompactRows = 6;
|
|
1114
|
+
const visibleEntries = hasRunning || failed || paused || blocked ? renderEntries : renderEntries.slice(0, maxCompactRows);
|
|
1115
|
+
let showLiveDetailHint = false;
|
|
1116
|
+
for (const entry of visibleEntries) {
|
|
1117
|
+
if (entry.kind === "placeholder") {
|
|
1118
|
+
const glyph = widgetStepGlyph(entry.status, theme);
|
|
1119
|
+
const statusLabel = widgetStepStatus(entry.status, theme);
|
|
1120
|
+
c.addChild(new TruncatedText(` ${glyph} ${entry.stepLabel}: ${themeBold(theme, entry.agentName)} ${theme.fg("dim", "·")} ${statusLabel}`));
|
|
1121
|
+
if (entry.error)
|
|
1122
|
+
c.addChild(new TruncatedText(theme.fg("error", ` ⎿ Error: ${entry.error}`)));
|
|
1123
|
+
continue;
|
|
1124
|
+
}
|
|
1125
|
+
const i = entry.resultIndex;
|
|
1126
|
+
const r = d.results[i];
|
|
1127
|
+
const rowNumber = entry.rowNumber;
|
|
1128
|
+
const agentName = entry.agentName;
|
|
1129
|
+
if (!r) {
|
|
1130
|
+
const pendingLabel = chainEntries ? resultRowLabel(d, multiLabel, i, rowNumber) : `${itemTitle} ${rowNumber}`;
|
|
1131
|
+
c.addChild(new TruncatedText(theme.fg("dim", ` ◦ ${pendingLabel}: ${agentName} · pending`)));
|
|
1132
|
+
continue;
|
|
1133
|
+
}
|
|
1134
|
+
const output = getSingleResultOutput(r) || (d.intercomDelivery?.delivered ? d.intercomDelivery.summary : "");
|
|
1135
|
+
const progressFromArray = d.progress?.find((p) => p.index === i) || d.progress?.find((p) => p.agent === r.agent && p.status === "running");
|
|
1136
|
+
const rProg = r.progress || progressFromArray || r.progressSummary;
|
|
1137
|
+
const rRunning = rProg && "status" in rProg && rProg.status === "running";
|
|
1138
|
+
const rPending = rProg && "status" in rProg && rProg.status === "pending";
|
|
1139
|
+
const stepNumber = r.progress?.index !== undefined ? r.progress.index + 1 : progressFromArray?.index !== undefined ? progressFromArray.index + 1 : i + 1;
|
|
1140
|
+
const stepStats = formatProgressStats(theme, rProg);
|
|
1141
|
+
const glyph = rPending ? theme.fg("dim", "◦") : resultGlyph(r, output, theme, rRunning, progressRunningSeed(rProg));
|
|
1142
|
+
const pendingLabel = rPending ? ` ${theme.fg("dim", "· pending")}` : "";
|
|
1143
|
+
const stepLabel = resultRowLabel(d, multiLabel, i, stepNumber);
|
|
1144
|
+
const line = `${glyph} ${stepLabel}: ${themeBold(theme, agentName)}${modelStat(theme, r.model)}${stepStats ? ` ${theme.fg("dim", "·")} ${stepStats}` : ""}${pendingLabel}`;
|
|
1145
|
+
c.addChild(new TruncatedText(` ${line}`));
|
|
1146
|
+
if (rRunning && rProg && "status" in rProg) {
|
|
1147
|
+
const activity = compactCurrentActivity(rProg);
|
|
1148
|
+
c.addChild(new Text(truncLine(theme.fg("dim", ` ⎿ ${activity}`), width), 0, 0));
|
|
1149
|
+
showLiveDetailHint = true;
|
|
1150
|
+
}
|
|
1151
|
+
else if (!rPending && (r.exitCode !== 0 || r.interrupted || r.detached || r.timedOut || r.acceptance?.status === "blocked" || hasEmptyTextOutputWithoutOutputTarget(r.task, output))) {
|
|
1152
|
+
c.addChild(new TruncatedText(theme.fg(r.exitCode !== 0 ? "error" : "dim", ` ⎿ ${resultStatusLine(r, output)}`)));
|
|
1153
|
+
}
|
|
1154
|
+
const outputTarget = extractOutputTarget(r.task);
|
|
1155
|
+
if (outputTarget)
|
|
1156
|
+
c.addChild(new TruncatedText(theme.fg("dim", ` output: ${outputTarget}`)));
|
|
1157
|
+
if (r.artifactPaths)
|
|
1158
|
+
c.addChild(new TruncatedText(theme.fg("dim", ` output: ${shortenPath(r.artifactPaths.outputPath)}`)));
|
|
1159
|
+
}
|
|
1160
|
+
if (renderEntries.length > visibleEntries.length)
|
|
1161
|
+
c.addChild(new Text(theme.fg("dim", ` +${renderEntries.length - visibleEntries.length} more${expandKey ? ` · ${expandKey} expands` : ""}`), 0, 0));
|
|
1162
|
+
if (showLiveDetailHint && expandKey)
|
|
1163
|
+
c.addChild(new Text(theme.fg("accent", ` Press ${expandKey} for live detail`), 0, 0));
|
|
1164
|
+
if (d.artifacts)
|
|
1165
|
+
c.addChild(new TruncatedText(theme.fg("dim", ` artifacts: ${shortenPath(d.artifacts.dir)}`)));
|
|
1166
|
+
if (!hasRunning)
|
|
1167
|
+
c.addChild(new TruncatedText(theme.fg("dim", ` ${keyText("app.tools.expand")} ${d.intercomDelivery?.delivered ? "receipt details" : "full response"}`)));
|
|
1168
|
+
return c;
|
|
1169
|
+
}
|
|
1170
|
+
/**
|
|
1171
|
+
* Render a subagent result
|
|
1172
|
+
*/
|
|
1173
|
+
export function renderSubagentResult(result, options, theme, context) {
|
|
1174
|
+
const isError = context?.isError ?? result.isError;
|
|
1175
|
+
const expandKey = keyText("app.tools.expand");
|
|
1176
|
+
const d = result.details;
|
|
1177
|
+
if (!d || !d.results.length) {
|
|
1178
|
+
const t = result.content[0];
|
|
1179
|
+
const text = t?.type === "text" ? t.text : "(no output)";
|
|
1180
|
+
const contextPrefix = d?.context === "fork" ? `${theme.fg("warning", "[fork]")} ` : "";
|
|
1181
|
+
if (options.expanded)
|
|
1182
|
+
return new Text(`${contextPrefix}${text}`, 0, 0);
|
|
1183
|
+
if (d?.asyncId && d.mode !== "management" && !isError) {
|
|
1184
|
+
const headline = d.managementControl?.revivedFromRunId ? "Revived async" : firstOutputLine(text).replace(` [${d.asyncId}]`, "");
|
|
1185
|
+
const c = new Container();
|
|
1186
|
+
c.addChild(new TruncatedText(`${contextPrefix}[${d.asyncId.slice(0, 8)}] ${headline}`));
|
|
1187
|
+
c.addChild(new TruncatedText(theme.fg("dim", `${keyText("app.tools.expand")} details`)));
|
|
1188
|
+
return c;
|
|
1189
|
+
}
|
|
1190
|
+
const maxCompactLines = 12;
|
|
1191
|
+
const lines = text.replace(/\n+$/, "").split("\n");
|
|
1192
|
+
if (lines.length === 1)
|
|
1193
|
+
return new Text(truncLine(`${contextPrefix}${lines[0]}`, getTermWidth() - 4), 0, 0);
|
|
1194
|
+
const visibleLines = lines.slice(0, maxCompactLines);
|
|
1195
|
+
if (lines.length > visibleLines.length)
|
|
1196
|
+
visibleLines.push(theme.fg("dim", `+${lines.length - visibleLines.length} more${expandKey ? ` · ${expandKey} expands` : ""}`));
|
|
1197
|
+
return new Text(`${contextPrefix}${visibleLines.join("\n")}`, 0, 0);
|
|
1198
|
+
}
|
|
1199
|
+
const expanded = options.expanded;
|
|
1200
|
+
const hasWorkflowFailure = workflowGraphHasStatus(d, ["failed", "timed-out"]);
|
|
1201
|
+
const hasWorkflowBlocked = d.results.some((r) => r.exitCode === 0 && r.acceptance?.status === "blocked") || workflowGraphHasStatus(d, ["blocked"]);
|
|
1202
|
+
const hasWorkflowPause = d.results.some((r) => r.interrupted || r.detached)
|
|
1203
|
+
|| workflowGraphHasStatus(d, ["paused", "detached"]);
|
|
1204
|
+
const receiptText = expanded && (isError || hasWorkflowFailure || hasWorkflowBlocked || hasWorkflowPause || d.intercomDelivery?.delivered)
|
|
1205
|
+
? result.content.filter((part) => part.type === "text").map((part) => part.text).join("\n")
|
|
1206
|
+
: undefined;
|
|
1207
|
+
const mdTheme = getMarkdownTheme();
|
|
1208
|
+
if (d.mode === "single" && d.results.length === 1) {
|
|
1209
|
+
const r = d.results[0];
|
|
1210
|
+
if (!expanded)
|
|
1211
|
+
return renderSingleCompact(d, r, theme, isError);
|
|
1212
|
+
const isRunning = !isError && r.progress?.status === "running";
|
|
1213
|
+
const icon = isRunning
|
|
1214
|
+
? theme.fg("warning", "running")
|
|
1215
|
+
: isError || r.timedOut
|
|
1216
|
+
? theme.fg("error", "failed")
|
|
1217
|
+
: r.detached || r.interrupted
|
|
1218
|
+
? theme.fg("warning", r.detached ? "detached" : "paused")
|
|
1219
|
+
: r.exitCode === 0
|
|
1220
|
+
? r.acceptance?.status === "blocked" ? theme.fg("warning", "needs your action") : theme.fg("success", "ok")
|
|
1221
|
+
: theme.fg("error", "failed");
|
|
1222
|
+
const contextBadge = d.context === "fork" ? theme.fg("warning", " [fork]") : "";
|
|
1223
|
+
const output = r.truncation?.text || getSingleResultOutput(r);
|
|
1224
|
+
const progressInfo = isRunning && r.progress
|
|
1225
|
+
? ` | ${r.progress.toolCount} tools, ${formatTokens(r.progress.tokens)} tok, ${formatDuration(r.progress.durationMs)}`
|
|
1226
|
+
: r.progressSummary
|
|
1227
|
+
? ` | ${r.progressSummary.toolCount} tools, ${formatTokens(r.progressSummary.tokens)} tok, ${formatDuration(r.progressSummary.durationMs)}`
|
|
1228
|
+
: "";
|
|
1229
|
+
const w = getTermWidth() - 4;
|
|
1230
|
+
const fit = (text) => expanded ? text : truncLine(text, w);
|
|
1231
|
+
const toolCallLines = getToolCallLines(r, expanded);
|
|
1232
|
+
const c = new Container();
|
|
1233
|
+
c.addChild(new Text(fit(`${icon} ${theme.fg("toolTitle", theme.bold(r.agent))}${contextBadge}${progressInfo}`), 0, 0));
|
|
1234
|
+
if ((isError || hasWorkflowFailure || hasWorkflowBlocked || hasWorkflowPause) && d.runId)
|
|
1235
|
+
c.addChild(new Text(theme.fg("dim", `Run: ${d.runId}`), 0, 0));
|
|
1236
|
+
c.addChild(new Spacer(1));
|
|
1237
|
+
const taskMaxLen = Math.max(20, w - 8);
|
|
1238
|
+
const taskPreview = expanded || r.task.length <= taskMaxLen
|
|
1239
|
+
? r.task
|
|
1240
|
+
: `${r.task.slice(0, taskMaxLen)}...`;
|
|
1241
|
+
c.addChild(new Text(fit(theme.fg("dim", `Task: ${taskPreview}`)), 0, 0));
|
|
1242
|
+
c.addChild(new Spacer(1));
|
|
1243
|
+
if (isRunning && r.progress) {
|
|
1244
|
+
const progressSnapshotNow = snapshotNowForProgress(r.progress);
|
|
1245
|
+
const toolLine = formatCurrentToolLine(r.progress, w, expanded, progressSnapshotNow);
|
|
1246
|
+
if (toolLine) {
|
|
1247
|
+
c.addChild(new Text(fit(theme.fg("warning", `> ${toolLine}`)), 0, 0));
|
|
1248
|
+
}
|
|
1249
|
+
const liveStatusLine = buildLiveStatusLine(r.progress, progressSnapshotNow);
|
|
1250
|
+
if (liveStatusLine) {
|
|
1251
|
+
c.addChild(new Text(fit(theme.fg("accent", liveStatusLine)), 0, 0));
|
|
1252
|
+
}
|
|
1253
|
+
if (expandKey)
|
|
1254
|
+
c.addChild(new Text(fit(theme.fg("accent", `Press ${expandKey} for live detail`)), 0, 0));
|
|
1255
|
+
if (r.artifactPaths) {
|
|
1256
|
+
c.addChild(new Text(fit(theme.fg("dim", `Artifacts: ${shortenPath(r.artifactPaths.outputPath)}`)), 0, 0));
|
|
1257
|
+
}
|
|
1258
|
+
if (r.progress.recentTools?.length) {
|
|
1259
|
+
for (const t of r.progress.recentTools.slice(-3)) {
|
|
1260
|
+
const maxArgsLen = Math.max(40, w - 24);
|
|
1261
|
+
const argsPreview = expanded || t.args.length <= maxArgsLen
|
|
1262
|
+
? t.args
|
|
1263
|
+
: `${t.args.slice(0, maxArgsLen)}...`;
|
|
1264
|
+
c.addChild(new Text(fit(theme.fg("dim", `${t.tool}: ${argsPreview}`)), 0, 0));
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
for (const line of (r.progress.recentOutput ?? []).slice(-5)) {
|
|
1268
|
+
c.addChild(new Text(fit(theme.fg("dim", ` ${line}`)), 0, 0));
|
|
1269
|
+
}
|
|
1270
|
+
if (toolLine || liveStatusLine || r.progress.recentTools?.length || r.progress.recentOutput?.length || r.artifactPaths) {
|
|
1271
|
+
c.addChild(new Spacer(1));
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
if (expanded) {
|
|
1275
|
+
for (const line of toolCallLines) {
|
|
1276
|
+
c.addChild(new Text(fit(theme.fg("muted", line)), 0, 0));
|
|
1277
|
+
}
|
|
1278
|
+
if (toolCallLines.length)
|
|
1279
|
+
c.addChild(new Spacer(1));
|
|
1280
|
+
}
|
|
1281
|
+
if (r.error && !output.includes(r.error))
|
|
1282
|
+
c.addChild(new Text(theme.fg("error", r.error), 0, 0));
|
|
1283
|
+
if (output)
|
|
1284
|
+
c.addChild(new Markdown(output, 0, 0, mdTheme));
|
|
1285
|
+
if (receiptText)
|
|
1286
|
+
c.addChild(new Text(receiptText, 0, 0));
|
|
1287
|
+
c.addChild(new Spacer(1));
|
|
1288
|
+
if (r.skills?.length) {
|
|
1289
|
+
c.addChild(new Text(fit(theme.fg("dim", `Skills: ${r.skills.join(", ")}`)), 0, 0));
|
|
1290
|
+
}
|
|
1291
|
+
if (r.skillsWarning) {
|
|
1292
|
+
c.addChild(new Text(fit(theme.fg("warning", `Warning: ${r.skillsWarning}`)), 0, 0));
|
|
1293
|
+
}
|
|
1294
|
+
if (r.attemptedModels && r.attemptedModels.length > 1) {
|
|
1295
|
+
c.addChild(new Text(fit(theme.fg("dim", `Fallbacks: ${r.attemptedModels.join(" → ")}`)), 0, 0));
|
|
1296
|
+
}
|
|
1297
|
+
c.addChild(new Text(fit(theme.fg("dim", [formatUsage(r.usage, r.model), r.accounting?.state === "incomplete" ? "accounting incomplete · reported totals only" : undefined].filter(Boolean).join(" · "))), 0, 0));
|
|
1298
|
+
if (!isRunning)
|
|
1299
|
+
c.addChild(new Text(fit(theme.fg("dim", formatAgentProcessExit(r.agentProcessExit))), 0, 0));
|
|
1300
|
+
if (r.sessionFile) {
|
|
1301
|
+
c.addChild(new Text(fit(theme.fg("dim", `Session: ${shortenPath(r.sessionFile)}`)), 0, 0));
|
|
1302
|
+
}
|
|
1303
|
+
if (!isRunning && r.artifactPaths) {
|
|
1304
|
+
c.addChild(new Spacer(1));
|
|
1305
|
+
c.addChild(new Text(fit(theme.fg("dim", `Artifacts: ${shortenPath(r.artifactPaths.outputPath)}`)), 0, 0));
|
|
1306
|
+
}
|
|
1307
|
+
return c;
|
|
1308
|
+
}
|
|
1309
|
+
if (!expanded)
|
|
1310
|
+
return renderMultiCompact(d, theme, isError);
|
|
1311
|
+
const hasRunning = !isError && (d.progress?.some((p) => p.status === "running")
|
|
1312
|
+
|| d.results.some((r) => r.progress?.status === "running")
|
|
1313
|
+
|| workflowGraphHasStatus(d, ["running"]));
|
|
1314
|
+
const hasFailure = isError || hasWorkflowFailure || d.results.some((r) => (r.exitCode !== 0 || r.timedOut) && !r.interrupted && !r.detached && r.progress?.status !== "running");
|
|
1315
|
+
const hasEmptyWithoutTarget = !d.intercomDelivery?.delivered && d.results.some((r) => r.exitCode === 0
|
|
1316
|
+
&& r.progress?.status !== "running"
|
|
1317
|
+
&& hasEmptyTextOutputWithoutOutputTarget(r.task, getSingleResultOutput(r)));
|
|
1318
|
+
const icon = hasRunning
|
|
1319
|
+
? theme.fg("warning", "running")
|
|
1320
|
+
: hasFailure
|
|
1321
|
+
? theme.fg("error", "failed")
|
|
1322
|
+
: hasWorkflowBlocked
|
|
1323
|
+
? theme.fg("warning", "needs your action")
|
|
1324
|
+
: hasWorkflowPause
|
|
1325
|
+
? theme.fg("warning", "paused")
|
|
1326
|
+
: hasEmptyWithoutTarget
|
|
1327
|
+
? theme.fg("warning", "warning")
|
|
1328
|
+
: theme.fg("success", "ok");
|
|
1329
|
+
const totalSummary = d.progressSummary ||
|
|
1330
|
+
d.results.reduce((acc, r) => {
|
|
1331
|
+
const prog = r.progress || r.progressSummary;
|
|
1332
|
+
if (prog) {
|
|
1333
|
+
acc.toolCount += prog.toolCount;
|
|
1334
|
+
acc.tokens += prog.tokens;
|
|
1335
|
+
acc.durationMs =
|
|
1336
|
+
d.mode === "chain"
|
|
1337
|
+
? acc.durationMs + prog.durationMs
|
|
1338
|
+
: Math.max(acc.durationMs, prog.durationMs);
|
|
1339
|
+
}
|
|
1340
|
+
return acc;
|
|
1341
|
+
}, { toolCount: 0, tokens: 0, durationMs: 0 });
|
|
1342
|
+
const summaryStr = totalSummary.toolCount || totalSummary.tokens
|
|
1343
|
+
? ` | ${totalSummary.toolCount} tools, ${formatTokens(totalSummary.tokens)} tok, ${formatDuration(totalSummary.durationMs)}`
|
|
1344
|
+
: "";
|
|
1345
|
+
const modeLabel = d.mode;
|
|
1346
|
+
const contextBadge = d.context === "fork" ? theme.fg("warning", " [fork]") : "";
|
|
1347
|
+
const multiLabel = buildMultiProgressLabel(d, hasRunning);
|
|
1348
|
+
if (!hasRunning)
|
|
1349
|
+
multiLabel.showActiveGroupOnly = false;
|
|
1350
|
+
const itemTitle = multiLabel.itemTitle;
|
|
1351
|
+
const chainVis = d.chainAgents?.length && !multiLabel.hasParallelInChain
|
|
1352
|
+
? d.chainAgents
|
|
1353
|
+
.map((agent, i) => {
|
|
1354
|
+
const result = d.results[i];
|
|
1355
|
+
const isFailed = result && result.exitCode !== 0 && result.progress?.status !== "running";
|
|
1356
|
+
const isComplete = result && isDoneResult(result);
|
|
1357
|
+
const isEmptyWithoutTarget = !d.intercomDelivery?.delivered && Boolean(result)
|
|
1358
|
+
&& Boolean(isComplete)
|
|
1359
|
+
&& hasEmptyTextOutputWithoutOutputTarget(result.task, getSingleResultOutput(result));
|
|
1360
|
+
const isCurrent = i === (d.currentStepIndex ?? d.results.length);
|
|
1361
|
+
const stepIcon = isFailed
|
|
1362
|
+
? theme.fg("error", "failed")
|
|
1363
|
+
: result?.acceptance?.status === "blocked" ? theme.fg("warning", "needs your action")
|
|
1364
|
+
: result?.interrupted || result?.detached ? theme.fg("warning", result.detached ? "detached" : "paused")
|
|
1365
|
+
: isEmptyWithoutTarget
|
|
1366
|
+
? theme.fg("warning", "warning")
|
|
1367
|
+
: isComplete
|
|
1368
|
+
? theme.fg("success", "done")
|
|
1369
|
+
: isCurrent && hasRunning
|
|
1370
|
+
? theme.fg("warning", "running")
|
|
1371
|
+
: theme.fg("dim", "pending");
|
|
1372
|
+
return `${stepIcon} ${agent}`;
|
|
1373
|
+
})
|
|
1374
|
+
.join(theme.fg("dim", " → "))
|
|
1375
|
+
: null;
|
|
1376
|
+
const w = getTermWidth() - 4;
|
|
1377
|
+
const fit = (text) => expanded ? text : truncLine(text, w);
|
|
1378
|
+
const c = new Container();
|
|
1379
|
+
c.addChild(new Text(fit(`${icon} ${theme.fg("toolTitle", theme.bold(modeLabel))}${contextBadge} · ${multiLabel.headerLabel}${summaryStr}`), 0, 0));
|
|
1380
|
+
if ((isError || hasWorkflowFailure || hasWorkflowBlocked || hasWorkflowPause) && d.runId)
|
|
1381
|
+
c.addChild(new Text(theme.fg("dim", `Run: ${d.runId}`), 0, 0));
|
|
1382
|
+
if (chainVis) {
|
|
1383
|
+
c.addChild(new Text(fit(` ${chainVis}`), 0, 0));
|
|
1384
|
+
}
|
|
1385
|
+
if (receiptText)
|
|
1386
|
+
c.addChild(new Text(receiptText, 0, 0));
|
|
1387
|
+
const useResultsDirectly = multiLabel.hasParallelInChain || !d.chainAgents?.length;
|
|
1388
|
+
const displayStart = multiLabel.showActiveGroupOnly ? multiLabel.groupStartIndex : 0;
|
|
1389
|
+
const displayEnd = multiLabel.showActiveGroupOnly ? multiLabel.groupEndIndex : (useResultsDirectly ? d.results.length : d.chainAgents.length);
|
|
1390
|
+
const chainEntries = buildChainRenderEntries(d, multiLabel);
|
|
1391
|
+
const renderEntries = chainEntries ?? Array.from({ length: displayEnd - displayStart }, (_, offset) => {
|
|
1392
|
+
const i = displayStart + offset;
|
|
1393
|
+
const r = d.results[i];
|
|
1394
|
+
const rowNumber = multiLabel.showActiveGroupOnly ? (i - multiLabel.groupStartIndex + 1) : (i + 1);
|
|
1395
|
+
return { kind: "result", resultIndex: i, rowNumber, agentName: useResultsDirectly ? (r?.agent || `step-${rowNumber}`) : (d.chainAgents[i] || r?.agent || `step-${rowNumber}`) };
|
|
1396
|
+
});
|
|
1397
|
+
c.addChild(new Spacer(1));
|
|
1398
|
+
for (const entry of renderEntries) {
|
|
1399
|
+
if (entry.kind === "placeholder") {
|
|
1400
|
+
const statusLabel = widgetStepStatus(entry.status, theme);
|
|
1401
|
+
c.addChild(new Text(fit(` ${statusLabel} ${entry.stepLabel}: ${theme.bold(entry.agentName)}`), 0, 0));
|
|
1402
|
+
c.addChild(new Text(theme.fg(entry.status === "failed" ? "error" : "dim", ` status: ${entry.status}`), 0, 0));
|
|
1403
|
+
if (entry.error)
|
|
1404
|
+
c.addChild(new Text(theme.fg("error", ` error: ${entry.error}`), 0, 0));
|
|
1405
|
+
c.addChild(new Spacer(1));
|
|
1406
|
+
continue;
|
|
1407
|
+
}
|
|
1408
|
+
const i = entry.resultIndex;
|
|
1409
|
+
const r = d.results[i];
|
|
1410
|
+
const rowNumber = entry.rowNumber;
|
|
1411
|
+
const agentName = entry.agentName;
|
|
1412
|
+
if (!r) {
|
|
1413
|
+
const pendingLabel = chainEntries ? resultRowLabel(d, multiLabel, i, rowNumber) : `${itemTitle} ${rowNumber}`;
|
|
1414
|
+
c.addChild(new Text(fit(theme.fg("dim", ` ${pendingLabel}: ${agentName}`)), 0, 0));
|
|
1415
|
+
c.addChild(new Text(theme.fg("dim", ` status: pending`), 0, 0));
|
|
1416
|
+
c.addChild(new Spacer(1));
|
|
1417
|
+
continue;
|
|
1418
|
+
}
|
|
1419
|
+
const progressFromArray = d.progress?.find((p) => p.index === i)
|
|
1420
|
+
|| d.progress?.find((p) => p.agent === r.agent && p.status === "running");
|
|
1421
|
+
const rProg = r.progress || progressFromArray || r.progressSummary;
|
|
1422
|
+
const rRunning = rProg?.status === "running";
|
|
1423
|
+
const stepNumber = typeof rProg?.index === "number" ? rProg.index + 1 : i + 1;
|
|
1424
|
+
const resultOutput = r.truncation?.text || getSingleResultOutput(r);
|
|
1425
|
+
const statusIcon = rRunning
|
|
1426
|
+
? theme.fg("warning", "running")
|
|
1427
|
+
: r.detached || r.interrupted
|
|
1428
|
+
? theme.fg("warning", r.detached ? "detached" : "paused")
|
|
1429
|
+
: r.exitCode !== 0
|
|
1430
|
+
? theme.fg("error", "failed")
|
|
1431
|
+
: r.acceptance?.status === "blocked"
|
|
1432
|
+
? theme.fg("warning", "needs your action")
|
|
1433
|
+
: !d.intercomDelivery?.delivered && hasEmptyTextOutputWithoutOutputTarget(r.task, resultOutput)
|
|
1434
|
+
? theme.fg("warning", "warning")
|
|
1435
|
+
: theme.fg("success", "done");
|
|
1436
|
+
const stats = rProg ? ` | ${rProg.toolCount} tools, ${formatDuration(rProg.durationMs)}` : "";
|
|
1437
|
+
const modelDisplay = modelThinkingBadge(theme, r.model);
|
|
1438
|
+
const stepLabel = resultRowLabel(d, multiLabel, i, stepNumber);
|
|
1439
|
+
const stepHeader = rRunning
|
|
1440
|
+
? `${statusIcon} ${stepLabel}: ${theme.bold(theme.fg("warning", r.agent))}${modelDisplay}${stats}`
|
|
1441
|
+
: `${statusIcon} ${stepLabel}: ${theme.bold(r.agent)}${modelDisplay}${stats}`;
|
|
1442
|
+
const toolCallLines = getToolCallLines(r, expanded);
|
|
1443
|
+
c.addChild(new Text(fit(stepHeader), 0, 0));
|
|
1444
|
+
const taskMaxLen = Math.max(20, w - 12);
|
|
1445
|
+
const taskPreview = expanded || r.task.length <= taskMaxLen
|
|
1446
|
+
? r.task
|
|
1447
|
+
: `${r.task.slice(0, taskMaxLen)}...`;
|
|
1448
|
+
c.addChild(new Text(fit(theme.fg("dim", ` task: ${taskPreview}`)), 0, 0));
|
|
1449
|
+
const outputTarget = extractOutputTarget(r.task);
|
|
1450
|
+
if (outputTarget) {
|
|
1451
|
+
c.addChild(new Text(fit(theme.fg("dim", ` output: ${outputTarget}`)), 0, 0));
|
|
1452
|
+
}
|
|
1453
|
+
if (r.skills?.length) {
|
|
1454
|
+
c.addChild(new Text(fit(theme.fg("dim", ` skills: ${r.skills.join(", ")}`)), 0, 0));
|
|
1455
|
+
}
|
|
1456
|
+
if (r.skillsWarning) {
|
|
1457
|
+
c.addChild(new Text(fit(theme.fg("warning", ` Warning: ${r.skillsWarning}`)), 0, 0));
|
|
1458
|
+
}
|
|
1459
|
+
if (r.attemptedModels && r.attemptedModels.length > 1) {
|
|
1460
|
+
c.addChild(new Text(fit(theme.fg("dim", ` model attempts: ${r.attemptedModels.join(" → ")}`)), 0, 0));
|
|
1461
|
+
}
|
|
1462
|
+
if (rRunning && rProg) {
|
|
1463
|
+
if (rProg.skills?.length) {
|
|
1464
|
+
c.addChild(new Text(fit(theme.fg("accent", ` skills: ${rProg.skills.join(", ")}`)), 0, 0));
|
|
1465
|
+
}
|
|
1466
|
+
const progressSnapshotNow = snapshotNowForProgress(rProg);
|
|
1467
|
+
const toolLine = formatCurrentToolLine(rProg, w, expanded, progressSnapshotNow);
|
|
1468
|
+
if (toolLine) {
|
|
1469
|
+
c.addChild(new Text(fit(theme.fg("warning", ` > ${toolLine}`)), 0, 0));
|
|
1470
|
+
}
|
|
1471
|
+
const liveStatusLine = buildLiveStatusLine(rProg, progressSnapshotNow);
|
|
1472
|
+
if (liveStatusLine) {
|
|
1473
|
+
c.addChild(new Text(fit(theme.fg("accent", ` ${liveStatusLine}`)), 0, 0));
|
|
1474
|
+
}
|
|
1475
|
+
if (expandKey)
|
|
1476
|
+
c.addChild(new Text(fit(theme.fg("accent", ` Press ${expandKey} for live detail`)), 0, 0));
|
|
1477
|
+
if (r.artifactPaths) {
|
|
1478
|
+
c.addChild(new Text(fit(theme.fg("dim", ` artifacts: ${shortenPath(r.artifactPaths.outputPath)}`)), 0, 0));
|
|
1479
|
+
}
|
|
1480
|
+
if (rProg.recentTools?.length) {
|
|
1481
|
+
for (const t of rProg.recentTools.slice(-3)) {
|
|
1482
|
+
const maxArgsLen = Math.max(40, w - 30);
|
|
1483
|
+
const argsPreview = expanded || t.args.length <= maxArgsLen
|
|
1484
|
+
? t.args
|
|
1485
|
+
: `${t.args.slice(0, maxArgsLen)}...`;
|
|
1486
|
+
c.addChild(new Text(fit(theme.fg("dim", ` ${t.tool}: ${argsPreview}`)), 0, 0));
|
|
1487
|
+
}
|
|
1488
|
+
}
|
|
1489
|
+
const recentLines = (rProg.recentOutput ?? []).slice(-5);
|
|
1490
|
+
for (const line of recentLines) {
|
|
1491
|
+
c.addChild(new Text(fit(theme.fg("dim", ` ${line}`)), 0, 0));
|
|
1492
|
+
}
|
|
1493
|
+
}
|
|
1494
|
+
if (!rRunning && r.artifactPaths) {
|
|
1495
|
+
c.addChild(new Text(fit(theme.fg("dim", ` artifacts: ${shortenPath(r.artifactPaths.outputPath)}`)), 0, 0));
|
|
1496
|
+
}
|
|
1497
|
+
if (expanded && !rRunning) {
|
|
1498
|
+
for (const line of toolCallLines) {
|
|
1499
|
+
c.addChild(new Text(fit(theme.fg("muted", ` ${line}`)), 0, 0));
|
|
1500
|
+
}
|
|
1501
|
+
if (toolCallLines.length)
|
|
1502
|
+
c.addChild(new Spacer(1));
|
|
1503
|
+
if (r.error && !resultOutput.includes(r.error))
|
|
1504
|
+
c.addChild(new Text(theme.fg("error", r.error), 0, 0));
|
|
1505
|
+
if (resultOutput)
|
|
1506
|
+
c.addChild(new Markdown(resultOutput, 0, 0, mdTheme));
|
|
1507
|
+
}
|
|
1508
|
+
c.addChild(new Spacer(1));
|
|
1509
|
+
}
|
|
1510
|
+
if (d.artifacts) {
|
|
1511
|
+
c.addChild(new Spacer(1));
|
|
1512
|
+
c.addChild(new Text(fit(theme.fg("dim", `Artifacts dir: ${shortenPath(d.artifacts.dir)}`)), 0, 0));
|
|
1513
|
+
}
|
|
1514
|
+
return c;
|
|
1515
|
+
}
|