@astralyn/pi 0.84.4 → 0.84.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.
Files changed (234) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/cli/args.d.ts +1 -0
  3. package/dist/cli/args.d.ts.map +1 -1
  4. package/dist/cli/args.js +11 -0
  5. package/dist/cli/args.js.map +1 -1
  6. package/dist/cli/auth-command.d.ts.map +1 -1
  7. package/dist/cli/auth-command.js +5 -4
  8. package/dist/cli/auth-command.js.map +1 -1
  9. package/dist/core/agent-session.d.ts +6 -1
  10. package/dist/core/agent-session.d.ts.map +1 -1
  11. package/dist/core/agent-session.js +7 -6
  12. package/dist/core/agent-session.js.map +1 -1
  13. package/dist/core/experimental.d.ts +4 -0
  14. package/dist/core/experimental.d.ts.map +1 -1
  15. package/dist/core/experimental.js +4 -0
  16. package/dist/core/experimental.js.map +1 -1
  17. package/dist/core/extensions/runner.d.ts.map +1 -1
  18. package/dist/core/extensions/runner.js +4 -0
  19. package/dist/core/extensions/runner.js.map +1 -1
  20. package/dist/core/extensions/types.d.ts +8 -1
  21. package/dist/core/extensions/types.d.ts.map +1 -1
  22. package/dist/core/extensions/types.js.map +1 -1
  23. package/dist/core/keybindings.d.ts +29 -0
  24. package/dist/core/keybindings.d.ts.map +1 -1
  25. package/dist/core/keybindings.js +4 -0
  26. package/dist/core/keybindings.js.map +1 -1
  27. package/dist/core/model-config.d.ts +5 -0
  28. package/dist/core/model-config.d.ts.map +1 -1
  29. package/dist/core/model-config.js +1 -0
  30. package/dist/core/model-config.js.map +1 -1
  31. package/dist/core/model-registry.d.ts +2 -0
  32. package/dist/core/model-registry.d.ts.map +1 -1
  33. package/dist/core/model-registry.js +4 -0
  34. package/dist/core/model-registry.js.map +1 -1
  35. package/dist/core/project-trust.js +2 -2
  36. package/dist/core/project-trust.js.map +1 -1
  37. package/dist/core/sdk.d.ts +5 -3
  38. package/dist/core/sdk.d.ts.map +1 -1
  39. package/dist/core/sdk.js +2 -1
  40. package/dist/core/sdk.js.map +1 -1
  41. package/dist/core/session-manager.js +2 -2
  42. package/dist/core/session-manager.js.map +1 -1
  43. package/dist/core/settings-manager.d.ts +6 -0
  44. package/dist/core/settings-manager.d.ts.map +1 -1
  45. package/dist/core/settings-manager.js +12 -0
  46. package/dist/core/settings-manager.js.map +1 -1
  47. package/dist/core/system-prompt.js +1 -1
  48. package/dist/core/system-prompt.js.map +1 -1
  49. package/dist/core/tools/bash.d.ts +2 -1
  50. package/dist/core/tools/bash.d.ts.map +1 -1
  51. package/dist/core/tools/bash.js +3 -1
  52. package/dist/core/tools/bash.js.map +1 -1
  53. package/dist/core/tools/edit.d.ts.map +1 -1
  54. package/dist/core/tools/edit.js +2 -0
  55. package/dist/core/tools/edit.js.map +1 -1
  56. package/dist/core/tools/find.js +1 -1
  57. package/dist/core/tools/find.js.map +1 -1
  58. package/dist/core/tools/grep.js +1 -1
  59. package/dist/core/tools/grep.js.map +1 -1
  60. package/dist/core/tools/read.d.ts.map +1 -1
  61. package/dist/core/tools/read.js +2 -0
  62. package/dist/core/tools/read.js.map +1 -1
  63. package/dist/core/tools/write.d.ts.map +1 -1
  64. package/dist/core/tools/write.js +2 -0
  65. package/dist/core/tools/write.js.map +1 -1
  66. package/dist/extensions/background/index.d.ts +74 -0
  67. package/dist/extensions/background/index.d.ts.map +1 -0
  68. package/dist/extensions/background/index.js +332 -0
  69. package/dist/extensions/background/index.js.map +1 -0
  70. package/dist/extensions/background/manager.d.ts +81 -0
  71. package/dist/extensions/background/manager.d.ts.map +1 -0
  72. package/dist/extensions/background/manager.js +320 -0
  73. package/dist/extensions/background/manager.js.map +1 -0
  74. package/dist/extensions/background/registry.d.ts +138 -0
  75. package/dist/extensions/background/registry.d.ts.map +1 -0
  76. package/dist/extensions/background/registry.js +358 -0
  77. package/dist/extensions/background/registry.js.map +1 -0
  78. package/dist/extensions/background/render.d.ts +26 -0
  79. package/dist/extensions/background/render.d.ts.map +1 -0
  80. package/dist/extensions/background/render.js +118 -0
  81. package/dist/extensions/background/render.js.map +1 -0
  82. package/dist/extensions/index.d.ts.map +1 -1
  83. package/dist/extensions/index.js +2 -0
  84. package/dist/extensions/index.js.map +1 -1
  85. package/dist/extensions/subagent/activity.d.ts +0 -1
  86. package/dist/extensions/subagent/activity.d.ts.map +1 -1
  87. package/dist/extensions/subagent/activity.js +2 -5
  88. package/dist/extensions/subagent/activity.js.map +1 -1
  89. package/dist/extensions/subagent/agents-command.d.ts.map +1 -1
  90. package/dist/extensions/subagent/agents-command.js +308 -153
  91. package/dist/extensions/subagent/agents-command.js.map +1 -1
  92. package/dist/extensions/subagent/agents.d.ts +3 -6
  93. package/dist/extensions/subagent/agents.d.ts.map +1 -1
  94. package/dist/extensions/subagent/agents.js +22 -192
  95. package/dist/extensions/subagent/agents.js.map +1 -1
  96. package/dist/extensions/subagent/constants.d.ts +4 -5
  97. package/dist/extensions/subagent/constants.d.ts.map +1 -1
  98. package/dist/extensions/subagent/constants.js +11 -7
  99. package/dist/extensions/subagent/constants.js.map +1 -1
  100. package/dist/extensions/subagent/index.d.ts +0 -3
  101. package/dist/extensions/subagent/index.d.ts.map +1 -1
  102. package/dist/extensions/subagent/index.js +56 -188
  103. package/dist/extensions/subagent/index.js.map +1 -1
  104. package/dist/extensions/subagent/render.d.ts +1 -1
  105. package/dist/extensions/subagent/render.d.ts.map +1 -1
  106. package/dist/extensions/subagent/render.js +208 -576
  107. package/dist/extensions/subagent/render.js.map +1 -1
  108. package/dist/extensions/subagent/resolve.d.ts +2 -2
  109. package/dist/extensions/subagent/resolve.d.ts.map +1 -1
  110. package/dist/extensions/subagent/resolve.js +23 -15
  111. package/dist/extensions/subagent/resolve.js.map +1 -1
  112. package/dist/extensions/subagent/runner.d.ts +1 -2
  113. package/dist/extensions/subagent/runner.d.ts.map +1 -1
  114. package/dist/extensions/subagent/runner.js +109 -131
  115. package/dist/extensions/subagent/runner.js.map +1 -1
  116. package/dist/extensions/subagent/schema.d.ts +4 -10
  117. package/dist/extensions/subagent/schema.d.ts.map +1 -1
  118. package/dist/extensions/subagent/schema.js +8 -13
  119. package/dist/extensions/subagent/schema.js.map +1 -1
  120. package/dist/extensions/subagent/sdk-runner.d.ts.map +1 -1
  121. package/dist/extensions/subagent/sdk-runner.js +9 -20
  122. package/dist/extensions/subagent/sdk-runner.js.map +1 -1
  123. package/dist/extensions/subagent/settings.d.ts +2 -2
  124. package/dist/extensions/subagent/settings.d.ts.map +1 -1
  125. package/dist/extensions/subagent/settings.js +27 -14
  126. package/dist/extensions/subagent/settings.js.map +1 -1
  127. package/dist/extensions/subagent/text.d.ts +3 -0
  128. package/dist/extensions/subagent/text.d.ts.map +1 -0
  129. package/dist/extensions/subagent/text.js +16 -0
  130. package/dist/extensions/subagent/text.js.map +1 -0
  131. package/dist/extensions/subagent/types.d.ts +13 -35
  132. package/dist/extensions/subagent/types.d.ts.map +1 -1
  133. package/dist/extensions/subagent/types.js.map +1 -1
  134. package/dist/extensions/subagent/ui/model-list.d.ts +4 -3
  135. package/dist/extensions/subagent/ui/model-list.d.ts.map +1 -1
  136. package/dist/extensions/subagent/ui/model-list.js +10 -4
  137. package/dist/extensions/subagent/ui/model-list.js.map +1 -1
  138. package/dist/index.d.ts +1 -1
  139. package/dist/index.d.ts.map +1 -1
  140. package/dist/index.js.map +1 -1
  141. package/dist/main.d.ts.map +1 -1
  142. package/dist/main.js +5 -1
  143. package/dist/main.js.map +1 -1
  144. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  145. package/dist/modes/interactive/components/model-selector.js +2 -1
  146. package/dist/modes/interactive/components/model-selector.js.map +1 -1
  147. package/dist/modes/interactive/components/settings-selector.d.ts +3 -1
  148. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  149. package/dist/modes/interactive/components/settings-selector.js +10 -0
  150. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  151. package/dist/modes/interactive/interactive-mode.d.ts +8 -2
  152. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  153. package/dist/modes/interactive/interactive-mode.js +77 -25
  154. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  155. package/dist/modes/interactive/model-catalog-refresh.d.ts +7 -0
  156. package/dist/modes/interactive/model-catalog-refresh.d.ts.map +1 -0
  157. package/dist/modes/interactive/model-catalog-refresh.js +36 -0
  158. package/dist/modes/interactive/model-catalog-refresh.js.map +1 -0
  159. package/dist/modes/interactive/theme/dark.json +2 -0
  160. package/dist/modes/interactive/theme/light.json +2 -0
  161. package/dist/modes/interactive/theme/theme-controller.d.ts +10 -2
  162. package/dist/modes/interactive/theme/theme-controller.d.ts.map +1 -1
  163. package/dist/modes/interactive/theme/theme-controller.js +23 -10
  164. package/dist/modes/interactive/theme/theme-controller.js.map +1 -1
  165. package/dist/modes/interactive/theme/theme-schema.json +9 -1
  166. package/dist/modes/interactive/theme/theme.d.ts +5 -3
  167. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  168. package/dist/modes/interactive/theme/theme.js +12 -2
  169. package/dist/modes/interactive/theme/theme.js.map +1 -1
  170. package/dist/modes/json-event.d.ts +4 -1
  171. package/dist/modes/json-event.d.ts.map +1 -1
  172. package/dist/modes/json-event.js +5 -2
  173. package/dist/modes/json-event.js.map +1 -1
  174. package/dist/package-manager-cli.js +1 -1
  175. package/dist/package-manager-cli.js.map +1 -1
  176. package/dist/server/create-harness.d.ts.map +1 -1
  177. package/dist/server/create-harness.js +2 -0
  178. package/dist/server/create-harness.js.map +1 -1
  179. package/dist/utils/tools-manager.d.ts +10 -1
  180. package/dist/utils/tools-manager.d.ts.map +1 -1
  181. package/dist/utils/tools-manager.js +14 -19
  182. package/dist/utils/tools-manager.js.map +1 -1
  183. package/docs/bundled/README.md +1 -0
  184. package/docs/bundled/extensions/background.md +64 -0
  185. package/docs/bundled/extensions/subagent.md +83 -71
  186. package/docs/compaction.md +6 -6
  187. package/docs/custom-provider.md +1 -1
  188. package/docs/docs.json +4 -0
  189. package/docs/environment-variables.md +8 -2
  190. package/docs/extensions.md +6 -2
  191. package/docs/json.md +6 -4
  192. package/docs/keybindings.md +9 -2
  193. package/docs/rpc.md +15 -4
  194. package/docs/sdk.md +9 -0
  195. package/docs/settings.md +31 -0
  196. package/docs/terminal-setup.md +23 -2
  197. package/docs/themes.md +24 -3
  198. package/docs/tui.md +2 -2
  199. package/docs/usage.md +4 -3
  200. package/examples/README.md +1 -1
  201. package/examples/extensions/README.md +0 -1
  202. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  203. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  204. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  205. package/examples/extensions/gondolin/package-lock.json +2 -2
  206. package/examples/extensions/gondolin/package.json +1 -1
  207. package/examples/extensions/sandbox/package-lock.json +2 -2
  208. package/examples/extensions/sandbox/package.json +1 -1
  209. package/examples/extensions/with-deps/package-lock.json +2 -2
  210. package/examples/extensions/with-deps/package.json +1 -1
  211. package/npm-shrinkwrap.json +170 -221
  212. package/package.json +6 -6
  213. package/dist/extensions/subagent/display-name.d.ts +0 -6
  214. package/dist/extensions/subagent/display-name.d.ts.map +0 -1
  215. package/dist/extensions/subagent/display-name.js +0 -13
  216. package/dist/extensions/subagent/display-name.js.map +0 -1
  217. package/dist/extensions/subagent/ui/profile-editor.d.ts +0 -54
  218. package/dist/extensions/subagent/ui/profile-editor.d.ts.map +0 -1
  219. package/dist/extensions/subagent/ui/profile-editor.js +0 -154
  220. package/dist/extensions/subagent/ui/profile-editor.js.map +0 -1
  221. package/dist/extensions/subagent/ui/profile-picker.d.ts +0 -32
  222. package/dist/extensions/subagent/ui/profile-picker.d.ts.map +0 -1
  223. package/dist/extensions/subagent/ui/profile-picker.js +0 -149
  224. package/dist/extensions/subagent/ui/profile-picker.js.map +0 -1
  225. package/examples/extensions/subagent/README.md +0 -175
  226. package/examples/extensions/subagent/agents/planner.md +0 -37
  227. package/examples/extensions/subagent/agents/reviewer.md +0 -35
  228. package/examples/extensions/subagent/agents/scout.md +0 -50
  229. package/examples/extensions/subagent/agents/worker.md +0 -24
  230. package/examples/extensions/subagent/agents.ts +0 -126
  231. package/examples/extensions/subagent/index.ts +0 -1009
  232. package/examples/extensions/subagent/prompts/implement-and-review.md +0 -10
  233. package/examples/extensions/subagent/prompts/implement.md +0 -10
  234. package/examples/extensions/subagent/prompts/scout-and-plan.md +0 -9
@@ -1,223 +1,52 @@
1
1
  import { Container, Markdown, Spacer, Text } from "@earendil-works/pi-tui";
2
- import { keyHint } from "../../modes/interactive/components/keybinding-hints.js";
3
2
  import { getMarkdownTheme } from "../../modes/interactive/theme/theme.js";
4
- import { displayAgentName } from "./display-name.js";
5
3
  import { getSubagentRetryView } from "./retry.js";
6
4
  import { statusSummary } from "./runner.js";
7
- const SINGLE_EXCERPT_LIMIT = 200;
8
- const RUN_LINE_EXCERPT_LIMIT = 96;
9
- const RUN_ERROR_EXCERPT_LIMIT = 200;
10
- const RETRY_ERROR_EXCERPT_LIMIT = 160;
11
- const LIVE_TAIL_LIMIT = 100;
12
- const COLLAPSED_RUN_LIMIT = 4;
13
- const PROMPT_PREVIEW_LINES = 2;
14
- const PROMPT_PREVIEW_LINE_LIMIT = 120;
15
- const ACTIVITY_SUMMARY_LIMIT = 96;
16
- const ACTIVITY_RESULT_LIMIT = 64;
17
- // Sub-10s tool calls are routine; a duration only earns ink when it
18
- // explains where the time went.
5
+ import { firstPlainLine, plainLine } from "./text.js";
6
+ const TASK_SUMMARY_LIMIT = 72;
7
+ const ACTIVITY_SUMMARY_LIMIT = 120;
8
+ const ACTIVITY_RESULT_LIMIT = 96;
9
+ const RETRY_ERROR_LIMIT = 160;
10
+ const FALLBACK_OUTPUT_LIMIT = 4_000;
19
11
  const ACTIVITY_DURATION_MIN_MS = 10_000;
20
- const EXPANDED_LIVE_TAIL_LINES = 3;
21
- class IndentedText {
22
- constructor(text, indent) {
23
- this.text = new Text(text, 0, 0);
24
- this.indent = indent;
25
- }
26
- render(width) {
27
- const indent = Math.min(this.indent, Math.max(0, width - 1));
28
- const prefix = " ".repeat(indent);
29
- return this.text.render(Math.max(1, width - indent)).map((line) => `${prefix}${line}`);
30
- }
31
- invalidate() {
32
- this.text.invalidate();
33
- }
34
- }
35
- function singleAgentName(args) {
36
- return displayAgentName(args.agent ?? "general");
37
- }
38
12
  function truncate(text, limit) {
39
- // Count code points, not UTF-16 code units: slicing a surrogate pair in
40
- // half would render as a lone replacement glyph in the terminal.
41
- const chars = [...text];
42
- return chars.length <= limit ? text : `${chars.slice(0, Math.max(0, limit - 1)).join("")}…`;
43
- }
44
- const DUNDER_IDENTIFIER_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*$/u;
45
- const CODE_OPERATOR_SUFFIX_PATTERN = /(?:={1,3}|!={1,2}|<=?|>=?|:=|[-+*/%&|^]=?)$/u;
46
- const CODE_OPERATOR_PREFIX_PATTERN = /^(?:={1,3}|!={1,2}|<=?|>=?|:=|[-+*/%&|^]=?)/u;
47
- const CODE_KEYWORD_SUFFIX_PATTERN = /\b(?:return|yield|raise|del|global|nonlocal|import|from|as)\s*$/u;
48
- // Double underscores are ambiguous: Markdown uses them for strong emphasis,
49
- // while code uses them for dunder identifiers. Preserve identifier-shaped
50
- // spans in clear code contexts and strip the remaining emphasis markers.
51
- function stripUnderscoreStrong(text) {
52
- return text.replace(/__([^_\n]+)__/gu, (match, content, offset) => {
53
- const before = text[offset - 1] ?? "";
54
- const after = text[offset + match.length] ?? "";
55
- const pairedCodeDelimiter = (before === "`" && after === "`") || (before === '"' && after === '"') || (before === "'" && after === "'");
56
- const codeAdjacent = before === "." || after === "(" || after === "." || after === "[";
57
- const trimmedBefore = text.slice(0, offset).trimEnd();
58
- const trimmedAfter = text.slice(offset + match.length).trimStart();
59
- const operatorAdjacent = CODE_OPERATOR_SUFFIX_PATTERN.test(trimmedBefore) || CODE_OPERATOR_PREFIX_PATTERN.test(trimmedAfter);
60
- const keywordAdjacent = CODE_KEYWORD_SUFFIX_PATTERN.test(trimmedBefore);
61
- return DUNDER_IDENTIFIER_PATTERN.test(content) &&
62
- (pairedCodeDelimiter || codeAdjacent || operatorAdjacent || keywordAdjacent)
63
- ? match
64
- : content;
65
- });
66
- }
67
- // Transcript excerpts render inside plain Text components, so markdown
68
- // punctuation would show up literally; strip the common inline syntax.
69
- function stripInlineMarkdown(text) {
70
- return (stripUnderscoreStrong(text.replace(/```[a-zA-Z0-9-]*/gu, ""))
71
- .replace(/`([^`]*)`/gu, "$1")
72
- // Demarcated bold only: `x**2**` is exponentiation, not emphasis.
73
- .replace(/(?<![A-Za-z0-9])\*\*([^*]+)\*\*(?![A-Za-z0-9])/gu, "$1")
74
- .replace(/\[([^\]]+)\]\([^)]*\)/gu, "$1")
75
- .replace(/^#{1,6}\s+/gmu, ""));
76
- }
77
- // Markdown tables and horizontal rules turn into symbol soup when
78
- // flattened onto one line; drop those lines before inline stripping.
79
- function stripBlockMarkdown(text) {
80
- return text
81
- .split("\n")
82
- .filter((line) => {
83
- const trimmed = line.trim();
84
- if (trimmed.startsWith("|"))
85
- return false;
86
- return !(trimmed.length >= 3 && /^[-—─═=*_|:\s]+$/u.test(trimmed));
87
- })
88
- .join("\n");
89
- }
90
- // finalOutput/liveText carry model-facing truncation notices from
91
- // boundText/tailText. Only recognize their exact boundary lines so literal
92
- // discussion of the marker remains visible in the transcript.
93
- const OUTPUT_TRUNCATION_NOTICE_PATTERN = /^\[Output truncated(?:: \d+ bytes omitted)?\.\]$/u;
94
- const EARLIER_OUTPUT_NOTICE = "[Earlier output omitted.]";
95
- function terminalOutputNotice(text) {
96
- const lines = text.split("\n");
97
- let index = lines.length - 1;
98
- while (index >= 0 && !lines[index]?.trim())
99
- index--;
100
- if (index < 0 || !OUTPUT_TRUNCATION_NOTICE_PATTERN.test(lines[index]?.trim() ?? "")) {
101
- return { text, truncated: false };
102
- }
103
- lines.splice(index, 1);
104
- return { text: lines.join("\n").trimEnd(), truncated: true };
105
- }
106
- function replaceBoundaryNotices(text) {
107
- const lines = text.split("\n");
108
- const first = lines.findIndex((line) => Boolean(line.trim()));
109
- if (first >= 0 && lines[first]?.trim() === EARLIER_OUTPUT_NOTICE)
110
- lines[first] = "…";
111
- let last = lines.length - 1;
112
- while (last >= 0 && !lines[last]?.trim())
113
- last--;
114
- if (last >= 0 && OUTPUT_TRUNCATION_NOTICE_PATTERN.test(lines[last]?.trim() ?? ""))
115
- lines[last] = "…";
116
- return lines.join("\n");
117
- }
118
- function plainExcerpt(text, limit) {
119
- return truncate(stripInlineMarkdown(stripBlockMarkdown(text)).replace(/\s+/gu, " ").trim(), limit);
120
- }
121
- function excerpt(text, limit) {
122
- return plainExcerpt(replaceBoundaryNotices(text), limit);
123
- }
124
- // Generated notice-only boundary lines must never become the live line the
125
- // user watches; identical text in the body remains ordinary model output.
126
- function liveTailLines(run) {
127
- const { text } = terminalOutputNotice(run.liveText);
128
- const lines = text
129
- .split("\n")
130
- .map((line) => line.trim())
131
- .filter(Boolean);
132
- if (lines[0] === EARLIER_OUTPUT_NOTICE)
133
- lines.shift();
134
- return lines;
135
- }
136
- function liveTail(run) {
137
- const last = liveTailLines(run).at(-1);
138
- return last ? excerpt(last, LIVE_TAIL_LIMIT) : undefined;
139
- }
140
- // Completed-run excerpts read better cut at a sentence boundary than
141
- // mid-word; fall back to a hard truncate when no boundary lands in the
142
- // second half of the window.
143
- function leadingSentences(text, limit) {
144
- const cleaned = excerpt(text, Number.MAX_SAFE_INTEGER);
145
- if (cleaned.length <= limit)
146
- return cleaned;
147
- const window = cleaned.slice(0, limit);
148
- let boundary = -1;
149
- for (const match of window.matchAll(/[.!?。!?](?=\s|$)/gu)) {
150
- boundary = (match.index ?? 0) + match[0].length;
151
- }
152
- if (boundary >= limit / 2)
153
- return window.slice(0, boundary).trimEnd();
154
- return truncate(cleaned, limit);
13
+ const characters = [...text];
14
+ return characters.length <= limit ? text : `${characters.slice(0, Math.max(0, limit - 1)).join("")}…`;
15
+ }
16
+ function taskPrompt(args, index, run) {
17
+ // Tool calls restored from before the tasks-array shape carry a legacy
18
+ // args object without `tasks`; those rows fall back to the description.
19
+ const tasks = args.tasks;
20
+ return tasks?.[index]?.prompt ?? run.description;
21
+ }
22
+ function taskSummary(args, index, run) {
23
+ const firstLine = firstPlainLine(taskPrompt(args, index, run));
24
+ return truncate(firstLine || plainLine(run.description) || `Task ${index + 1}`, TASK_SUMMARY_LIMIT);
25
+ }
26
+ function profileLabel(agent) {
27
+ if (agent === "explorer")
28
+ return "Explorer";
29
+ if (agent === "general")
30
+ return "General";
31
+ return agent;
155
32
  }
156
- const VERIFY_COMMAND_PATTERN = /\b(test|lint|typecheck|tsc|vitest|jest|pytest|build|check|fmt|format|compile)\b/iu;
157
- const INSPECT_COMMAND_PATTERN = /\b(rg|grep|find|git (?:diff|status|log|show)|ls|tree|cat|head|tail)\b/iu;
158
- const RETRY_MARKER_PATTERN = /^Retrying\b/u;
159
- const STREAM_MARKERS = new Set(["Thinking…", "Writing response…"]);
160
- function retryText(run) {
161
- const retry = getSubagentRetryView(run);
162
- if (!retry)
163
- return undefined;
164
- const status = retry.remainingSeconds > 0
165
- ? `Retrying (${retry.attempt}/${retry.maxAttempts}) in ${retry.remainingSeconds}s`
166
- : `Retrying now… (${retry.attempt}/${retry.maxAttempts})`;
167
- const error = excerpt(retry.error, RETRY_ERROR_EXCERPT_LIMIT);
168
- return error ? `${status} — ${error}` : status;
169
- }
170
- // Translates raw tool traffic into what the worker is doing right now, so
171
- // the collapsed card reads as a phase instead of a command line. Modelled
172
- // on tool-type classification; the raw tool summary stays as evidence on
173
- // the next line.
174
- function runIntent(run) {
175
- const retry = retryText(run);
176
- if (retry)
177
- return retry;
178
- const current = run.currentActivity;
179
- if (current && RETRY_MARKER_PATTERN.test(current))
180
- return current;
181
- const running = [...run.activities].reverse().find((activity) => activity.status === "running");
182
- if (running) {
183
- if (running.toolName === "edit" || running.toolName === "write")
184
- return "Applying changes";
185
- if (running.toolName === "bash") {
186
- if (VERIFY_COMMAND_PATTERN.test(running.summary))
187
- return "Verifying changes";
188
- return INSPECT_COMMAND_PATTERN.test(running.summary) ? "Exploring code" : "Running commands";
189
- }
190
- return "Exploring code";
191
- }
192
- const recent = run.activities.slice(-5);
193
- if (current && STREAM_MARKERS.has(current)) {
194
- if (recent.some((activity) => activity.status === "failed"))
195
- return "Investigating a failure";
196
- return current;
197
- }
198
- if (recent.some((activity) => activity.status === "failed"))
199
- return "Investigating a failure";
200
- if (recent.some((activity) => activity.toolName === "edit" || activity.toolName === "write"))
201
- return "Reviewing changes";
202
- if (recent.length > 0)
203
- return "Exploring code";
204
- return current ?? "Thinking…";
33
+ function formatTokens(value) {
34
+ if (value < 1_000)
35
+ return String(value);
36
+ if (value < 1_000_000)
37
+ return `${(value / 1_000).toFixed(value < 10_000 ? 1 : 0)}k`;
38
+ return `${(value / 1_000_000).toFixed(1)}M`;
205
39
  }
206
- // The raw tool summary backs up the intent line; suppress it when it would
207
- // just repeat a stream/retry marker.
208
- function runEvidence(run) {
209
- if (getSubagentRetryView(run))
210
- return undefined;
211
- const current = run.currentActivity;
212
- if (!current || STREAM_MARKERS.has(current) || RETRY_MARKER_PATTERN.test(current))
213
- return undefined;
214
- return current;
40
+ function formatDuration(seconds) {
41
+ const roundedSeconds = Math.round(seconds);
42
+ if (roundedSeconds >= 60)
43
+ return `${Math.floor(roundedSeconds / 60)}m ${roundedSeconds % 60}s`;
44
+ return `${seconds.toFixed(seconds < 10 ? 1 : 0)}s`;
215
45
  }
216
- function liveElapsed(run) {
217
- if (run.startedAt === undefined)
46
+ function elapsed(startedAt, endedAt) {
47
+ if (startedAt === undefined)
218
48
  return undefined;
219
- const end = run.endedAt ?? Date.now();
220
- return formatDuration(Math.max(0, (end - run.startedAt) / 1000));
49
+ return formatDuration(Math.max(0, ((endedAt ?? Date.now()) - startedAt) / 1_000));
221
50
  }
222
51
  function statusColor(status) {
223
52
  switch (status) {
@@ -233,9 +62,6 @@ function statusColor(status) {
233
62
  return "muted";
234
63
  }
235
64
  }
236
- // The tool shell already paints a call-level status dot (● in
237
- // warning/success/error), so `●` is off-limits here: `›` marks where the
238
- // work currently is, and the remaining glyphs are terminal states.
239
65
  function statusMarker(status, theme) {
240
66
  const glyph = status === "completed"
241
67
  ? "✓"
@@ -249,413 +75,219 @@ function statusMarker(status, theme) {
249
75
  return theme.fg(statusColor(status), glyph);
250
76
  }
251
77
  function statusWord(status) {
252
- switch (status) {
253
- case "completed":
254
- return "Completed";
255
- case "failed":
256
- return "Failed";
257
- case "aborted":
258
- return "Aborted";
259
- case "running":
260
- return "Running";
261
- default:
262
- return "Queued";
263
- }
78
+ if (status === "completed")
79
+ return "Completed";
80
+ if (status === "failed")
81
+ return "Failed";
82
+ if (status === "aborted")
83
+ return "Aborted";
84
+ if (status === "running")
85
+ return "Running";
86
+ return "Queued";
264
87
  }
265
- function runTitle(run, theme, index) {
266
- const number = index === undefined ? "" : theme.fg("dim", `${index} · `);
267
- return `${statusMarker(run.status, theme)} ${number}${theme.fg("accent", displayAgentName(run.agent))}${theme.fg("dim", ` · ${truncate(run.description, 48)}`)}`;
268
- }
269
- // Mid-run token totals are cache-inflated (totalTokens sums cache reads
270
- // across turns), so live lines quote tool uses and the context watermark
271
- // instead; settled lines get the real total.
272
- function runProgressText(run) {
273
- const items = [`${run.usage.toolUses} tool use${run.usage.toolUses === 1 ? "" : "s"}`];
274
- if (run.usage.contextTokens)
275
- items.push(`ctx: ${formatTokens(run.usage.contextTokens)}`);
276
- return items.join(" · ");
88
+ function retryText(run) {
89
+ const retry = getSubagentRetryView(run);
90
+ if (!retry)
91
+ return undefined;
92
+ const state = retry.remainingSeconds > 0
93
+ ? `Retrying (${retry.attempt}/${retry.maxAttempts}) in ${retry.remainingSeconds}s`
94
+ : `Retrying now… (${retry.attempt}/${retry.maxAttempts})`;
95
+ const error = truncate(plainLine(retry.error), RETRY_ERROR_LIMIT);
96
+ return error ? `${state} — ${error}` : state;
277
97
  }
278
- function runLine(run, theme, index) {
279
- let line = runTitle(run, theme, index);
98
+ function runningDetail(run) {
280
99
  const retry = retryText(run);
281
- const detail = retry ??
282
- (run.status === "running"
283
- ? excerpt(runIntent(run), LIVE_TAIL_LIMIT)
284
- : run.status === "failed" || run.status === "aborted"
285
- ? undefined
286
- : run.finalOutput && leadingSentences(run.finalOutput, RUN_LINE_EXCERPT_LIMIT));
287
- if (detail)
100
+ if (retry)
101
+ return retry;
102
+ if (run.currentActivity)
103
+ return truncate(plainLine(run.currentActivity), ACTIVITY_SUMMARY_LIMIT);
104
+ if (run.status === "queued")
105
+ return "Waiting for a worker slot";
106
+ if (run.status === "running" && run.usage.turns === 0 && run.usage.toolUses === 0)
107
+ return "Initializing…";
108
+ if (run.status === "running")
109
+ return "Thinking…";
110
+ if ((run.status === "failed" || run.status === "aborted") && run.error) {
111
+ return truncate(plainLine(run.error), ACTIVITY_RESULT_LIMIT);
112
+ }
113
+ return undefined;
114
+ }
115
+ function batchMarker(details, theme) {
116
+ if (details.runs.some((run) => run.status === "failed"))
117
+ return theme.fg("error", "×");
118
+ if (details.runs.some((run) => run.status === "aborted"))
119
+ return theme.fg("warning", "■");
120
+ return theme.fg("success", "✓");
121
+ }
122
+ function progressHeader(details, theme) {
123
+ const settled = details.runs.filter((run) => run.status !== "running" && run.status !== "queued").length;
124
+ return theme.fg("accent", `› ${settled}/${details.runs.length} done · ${elapsed(details.startedAt) ?? "0.0s"}`);
125
+ }
126
+ function taskRow(run, index, args, theme, live) {
127
+ let line = ` ${statusMarker(run.status, theme)} ${theme.fg("accent", profileLabel(run.agent))}${theme.fg("dim", ` · ${taskSummary(args, index, run)}`)}`;
128
+ const detail = live ? runningDetail(run) : undefined;
129
+ if (detail) {
288
130
  line += theme.fg("dim", ` — ${detail}`);
289
- if (run.status === "running") {
290
- line += theme.fg("dim", ` · ${runProgressText(run)}`);
291
- if (run.usage.cost)
292
- line += theme.fg("dim", ` · $${run.usage.cost.toFixed(3)}`);
293
- const elapsed = liveElapsed(run);
294
- if (elapsed)
295
- line += theme.fg("dim", ` · ${elapsed}`);
296
131
  }
297
- const settled = run.status !== "running" && run.status !== "queued";
298
- if (settled && run.startedAt !== undefined && run.endedAt !== undefined) {
299
- line += theme.fg("dim", ` · ${formatDuration(Math.max(0, (run.endedAt - run.startedAt) / 1000))}`);
132
+ else if (run.status !== "running" && run.status !== "queued") {
133
+ const duration = elapsed(run.startedAt, run.endedAt);
134
+ if (duration)
135
+ line += theme.fg("dim", ` · ${duration}`);
300
136
  }
301
137
  return line;
302
138
  }
303
- function runErrorExcerpt(run) {
304
- if ((run.status !== "failed" && run.status !== "aborted") || !run.error)
305
- return undefined;
306
- return leadingSentences(run.error, RUN_ERROR_EXCERPT_LIMIT);
307
- }
308
- function runErrorIndent(index) {
309
- return index === undefined ? 2 : 5 + String(index).length;
310
- }
311
- function addRunSummary(container, run, theme, index) {
312
- container.addChild(new Text(runLine(run, theme, index), 0, 0));
313
- const error = runErrorExcerpt(run);
314
- if (error)
315
- container.addChild(new IndentedText(theme.fg("error", error), runErrorIndent(index)));
316
- }
317
- // Keep active work visible while a batch is in flight: completed runs
318
- // may otherwise crowd a still-running task out of the collapsed window.
319
- function selectCollapsedRuns(runs, isPartial) {
320
- if (runs.length <= COLLAPSED_RUN_LIMIT)
321
- return runs;
322
- if (!isPartial)
323
- return runs.slice(0, COLLAPSED_RUN_LIMIT);
324
- const active = runs.filter((run) => run.status === "running" || run.status === "queued");
325
- const retrying = active.filter((run) => getSubagentRetryView(run));
326
- const retryingSet = new Set(retrying);
327
- const otherActive = active.filter((run) => !retryingSet.has(run));
328
- const settled = runs.filter((run) => run.status !== "running" && run.status !== "queued");
329
- return [...retrying, ...otherActive, ...settled].slice(0, COLLAPSED_RUN_LIMIT);
330
- }
331
- function singleCollapsedLines(details, theme) {
332
- const run = details.runs[0];
333
- if (!run)
334
- return [theme.fg("muted", "Initializing…")];
335
- if (run.status === "running" || run.status === "queued") {
336
- const retry = retryText(run);
337
- const isInitializing = run.status === "running" &&
338
- !retry &&
339
- run.usage.turns === 0 &&
340
- run.usage.toolUses === 0 &&
341
- run.liveText.length === 0;
342
- const rawIntent = retry ??
343
- (run.status === "queued"
344
- ? (run.currentActivity ?? statusWord(run.status))
345
- : isInitializing
346
- ? "Initializing…"
347
- : runIntent(run));
348
- const intent = excerpt(rawIntent, LIVE_TAIL_LIMIT);
349
- // No status marker here: the shell's call-level dot already covers
350
- // the whole card, and a single run has nothing to disambiguate.
351
- let status = theme.fg("dim", intent);
352
- if (run.status === "running" && !isInitializing) {
353
- status += theme.fg("dim", ` · ${runProgressText(run)}`);
354
- if (run.usage.cost)
355
- status += theme.fg("dim", ` · $${run.usage.cost.toFixed(3)}`);
356
- const elapsed = liveElapsed(run);
357
- if (elapsed)
358
- status += theme.fg("dim", ` · ${elapsed}`);
359
- }
360
- const lines = [status];
361
- const evidence = runEvidence(run);
362
- if (evidence && evidence !== rawIntent)
363
- lines.push(`${theme.fg("accent", "›")} ${theme.fg("dim", excerpt(evidence, LIVE_TAIL_LIMIT))}`);
364
- const tail = liveTail(run);
365
- if (tail)
366
- lines.push(theme.fg("dim", tail));
367
- return lines;
368
- }
369
- if (run.error)
370
- return [theme.fg("error", excerpt(run.error, SINGLE_EXCERPT_LIMIT))];
371
- if (run.finalOutput)
372
- return [theme.fg("toolOutput", leadingSentences(run.finalOutput, SINGLE_EXCERPT_LIMIT))];
373
- return [theme.fg("muted", statusWord(run.status))];
374
- }
375
- // Deep-trimmed settled footer: turns and per-run breakdowns belong to the
376
- // expanded view. Parallel batches keep only whole-call numbers — the run
377
- // rows above already localize the work.
378
- function collapsedUsageText(details, extended) {
379
- const usage = details.usage;
380
- const items = [];
381
- if (usage.totalTokens)
382
- items.push(`${formatTokens(usage.totalTokens)} tok`);
383
- if (extended && usage.toolUses)
384
- items.push(`${usage.toolUses} tool use${usage.toolUses === 1 ? "" : "s"}`);
385
- if (extended && usage.contextTokens)
386
- items.push(`ctx: ${formatTokens(usage.contextTokens)}`);
387
- if (usage.cost)
388
- items.push(`$${usage.cost.toFixed(3)}`);
389
- if (details.endedAt !== undefined) {
390
- items.push(formatDuration(Math.max(0, (details.endedAt - details.startedAt) / 1000)));
391
- }
392
- return items.join(" · ");
393
- }
394
- function batchUsageText(details, isPartial) {
395
- const usage = details.usage;
396
- const items = [];
397
- // The aggregate mixes settled and running runs while partial, and the
398
- // running share is cache-inflated — quote the total only once settled.
399
- if (!isPartial && usage.totalTokens)
400
- items.push(`${formatTokens(usage.totalTokens)} tok`);
401
- if (usage.toolUses)
402
- items.push(`${usage.toolUses} tool use${usage.toolUses === 1 ? "" : "s"}`);
403
- if (usage.turns)
404
- items.push(`${usage.turns} turn${usage.turns === 1 ? "" : "s"}`);
405
- if (usage.contextTokens)
406
- items.push(`ctx: ${formatTokens(usage.contextTokens)}`);
407
- if (usage.cost)
408
- items.push(`$${usage.cost.toFixed(3)}`);
409
- if (details.endedAt !== undefined) {
410
- items.push(formatDuration(Math.max(0, (details.endedAt - details.startedAt) / 1000)));
411
- }
412
- return items.join(" · ");
413
- }
414
- function formatTokens(value) {
415
- if (value < 1_000)
416
- return String(value);
417
- if (value < 1_000_000)
418
- return `${(value / 1_000).toFixed(value < 10_000 ? 1 : 0)}k`;
419
- return `${(value / 1_000_000).toFixed(1)}M`;
420
- }
421
- function formatDuration(seconds) {
422
- const roundedSeconds = Math.round(seconds);
423
- if (roundedSeconds >= 60)
424
- return `${Math.floor(roundedSeconds / 60)}m ${roundedSeconds % 60}s`;
425
- return `${seconds.toFixed(seconds < 10 ? 1 : 0)}s`;
426
- }
427
- function runDurationText(run) {
428
- if (run.startedAt === undefined || run.endedAt === undefined)
429
- return undefined;
430
- return formatDuration(Math.max(0, (run.endedAt - run.startedAt) / 1000));
431
- }
432
- // One dim line per run: what it cost. Settled runs quote the real token
433
- // total; running runs skip it (cache-inflated mid-run) and tick elapsed
434
- // time instead. Batch sections fold model/thinking/cwd in here because
435
- // their `──` header already carries verdict and duration.
436
- function runMetricsText(run, includeIdentity) {
437
- const usage = run.usage;
139
+ function outcomeSummary(details) {
140
+ const completed = details.runs.filter((run) => run.status === "completed").length;
141
+ const failed = details.runs.filter((run) => run.status === "failed").length;
142
+ const aborted = details.runs.filter((run) => run.status === "aborted").length;
143
+ const parts = [];
144
+ if (completed)
145
+ parts.push(`${completed} completed`);
146
+ if (failed)
147
+ parts.push(`${failed} failed`);
148
+ if (aborted)
149
+ parts.push(`${aborted} aborted`);
150
+ if (parts.length === 0)
151
+ parts.push(statusSummary(details));
152
+ const duration = elapsed(details.startedAt, details.endedAt);
153
+ if (duration)
154
+ parts.push(duration);
155
+ if (details.usage.cost)
156
+ parts.push(`$${details.usage.cost.toFixed(3)}`);
157
+ return parts.join(" · ");
158
+ }
159
+ function runMetrics(run) {
160
+ const items = [run.model];
161
+ if (run.thinking !== "off")
162
+ items.push(`${run.thinking} thinking`);
163
+ if (run.cwd)
164
+ items.push(`cwd: ${run.cwd}`);
438
165
  const settled = run.status !== "running" && run.status !== "queued";
439
- const items = [];
440
- if (includeIdentity) {
441
- items.push(run.model);
442
- if (run.thinking !== "off")
443
- items.push(run.thinking);
444
- if (run.cwd)
445
- items.push(`cwd: ${run.cwd}`);
446
- }
447
- if (settled && usage.totalTokens)
448
- items.push(`${formatTokens(usage.totalTokens)} tok`);
449
- if (usage.toolUses)
450
- items.push(`${usage.toolUses} tool use${usage.toolUses === 1 ? "" : "s"}`);
451
- if (usage.turns)
452
- items.push(`${usage.turns} turn${usage.turns === 1 ? "" : "s"}`);
453
- if (usage.contextTokens)
454
- items.push(`ctx: ${formatTokens(usage.contextTokens)}`);
455
- if (usage.cost)
456
- items.push(`$${usage.cost.toFixed(3)}`);
457
- const duration = settled ? (includeIdentity ? undefined : runDurationText(run)) : liveElapsed(run);
166
+ if (settled && run.usage.totalTokens)
167
+ items.push(`${formatTokens(run.usage.totalTokens)} tok`);
168
+ if (run.usage.toolUses)
169
+ items.push(`${run.usage.toolUses} tool use${run.usage.toolUses === 1 ? "" : "s"}`);
170
+ if (run.usage.turns)
171
+ items.push(`${run.usage.turns} turn${run.usage.turns === 1 ? "" : "s"}`);
172
+ if (run.usage.contextTokens)
173
+ items.push(`ctx: ${formatTokens(run.usage.contextTokens)}`);
174
+ if (run.usage.cost)
175
+ items.push(`$${run.usage.cost.toFixed(3)}`);
176
+ const duration = elapsed(run.startedAt, run.endedAt);
458
177
  if (duration)
459
178
  items.push(duration);
460
179
  return items.join(" · ");
461
180
  }
462
- // The details prompt is a 1KB bounded copy of the briefing; the preview
463
- // shows the first content lines (blank lines carry nothing at two lines
464
- // of budget) and never pretends to more fidelity than that.
465
- function promptSection(run, theme) {
466
- const boundedPrompt = terminalOutputNotice(run.prompt);
467
- const lines = boundedPrompt.text
468
- .split("\n")
469
- .map((line) => plainExcerpt(line.trim(), Number.MAX_SAFE_INTEGER))
470
- .filter(Boolean);
471
- const shown = lines.slice(0, PROMPT_PREVIEW_LINES);
472
- const preview = shown.map((line) => theme.fg("dim", truncate(line, PROMPT_PREVIEW_LINE_LIMIT)));
473
- // A one-line briefing clipped mid-sentence must still say it continues.
474
- const clipped = shown.some((line) => line.length > PROMPT_PREVIEW_LINE_LIMIT);
475
- const remaining = lines.length - shown.length;
476
- const capped = boundedPrompt.truncated;
477
- const section = [theme.fg("muted", "Prompt"), ...preview];
478
- if (remaining > 0 || capped || clipped) {
479
- let note = "… continues";
480
- if (remaining > 0)
481
- note += `, ${remaining} more line${remaining === 1 ? "" : "s"}`;
482
- if (capped)
483
- note += " · capped at 1KB";
484
- section.push(theme.fg("muted", note));
181
+ function activityLine(activity, run, theme) {
182
+ const summary = activity.status === "running" && run.currentActivity
183
+ ? truncate(plainLine(run.currentActivity), ACTIVITY_SUMMARY_LIMIT)
184
+ : truncate(plainLine(activity.summary), ACTIVITY_SUMMARY_LIMIT);
185
+ let line = activity.status === "failed"
186
+ ? `${theme.fg("error", "×")} ${theme.fg("toolOutput", summary)}`
187
+ : activity.status === "running"
188
+ ? `${theme.fg("accent", "›")} ${theme.fg("toolOutput", summary)}`
189
+ : ` ${theme.fg("toolOutput", summary)}`;
190
+ if (activity.status === "failed" && activity.resultSummary) {
191
+ line += theme.fg("error", ` · ${truncate(plainLine(activity.resultSummary), ACTIVITY_RESULT_LIMIT)}`);
192
+ }
193
+ if (activity.endedAt !== undefined && activity.endedAt - activity.startedAt >= ACTIVITY_DURATION_MIN_MS) {
194
+ line += theme.fg("dim", ` · ${formatDuration((activity.endedAt - activity.startedAt) / 1_000)}`);
485
195
  }
486
- return section;
196
+ return line;
197
+ }
198
+ function runHeader(run, index, args, theme) {
199
+ return `${theme.fg("dim", `── #${index + 1} `)}${statusMarker(run.status, theme)} ${theme.fg("accent", profileLabel(run.agent))}${theme.fg("dim", ` · ${taskSummary(args, index, run)}`)}`;
487
200
  }
488
- // Each run expands into a report cover sheet: verdict and cost up top, a
489
- // bounded Prompt/Activity digest in the middle, then the full Report —
490
- // the one unbounded element, placed last so the card ends where reading
491
- // begins. Single runs skip the `──` header (the call header already names
492
- // them); batch sections carry a numbered header matching the contents
493
- // list above.
494
- function renderRunDetails(run, theme, single, index) {
201
+ function renderRunningRun(run, index, args, theme) {
495
202
  const container = new Container();
496
- const settled = run.status !== "running" && run.status !== "queued";
497
- if (single) {
498
- const identity = [run.model];
499
- if (run.thinking !== "off")
500
- identity.push(`${run.thinking} thinking`);
501
- if (run.cwd)
502
- identity.push(`cwd: ${run.cwd}`);
503
- container.addChild(new Text(`${statusMarker(run.status, theme)} ${theme.fg(statusColor(run.status), statusWord(run.status))}${theme.fg("dim", ` · ${identity.join(" · ")}`)}`, 0, 0));
504
- }
505
- else {
506
- const label = index === undefined ? "" : `${index} · `;
507
- const duration = settled ? runDurationText(run) : undefined;
508
- container.addChild(new Text(`${theme.fg("dim", `── ${label}`)}${statusMarker(run.status, theme)} ${theme.fg("accent", displayAgentName(run.agent))}${theme.fg("dim", ` · ${truncate(run.description, 48)}`)}${duration ? theme.fg("dim", ` · ${duration}`) : ""}`, 0, 0));
509
- }
510
- if (run.status !== "queued") {
511
- const metrics = runMetricsText(run, !single);
512
- if (metrics)
513
- container.addChild(new Text(theme.fg("dim", metrics), 0, 0));
514
- }
203
+ container.addChild(new Text(runHeader(run, index, args, theme), 0, 0));
204
+ container.addChild(new Text(theme.fg("dim", runMetrics(run)), 0, 0));
515
205
  const retry = retryText(run);
516
206
  if (retry)
517
207
  container.addChild(new Text(theme.fg("accent", retry), 0, 0));
518
208
  container.addChild(new Spacer(1));
519
- for (const line of promptSection(run, theme))
520
- container.addChild(new Text(line, 0, 0));
209
+ const total = Math.max(run.usage.toolUses, run.activities.length);
210
+ const label = total > run.activities.length ? `Activity · last ${run.activities.length} of ${total}` : "Activity";
211
+ container.addChild(new Text(theme.fg("muted", label), 0, 0));
521
212
  if (run.activities.length > 0) {
522
- container.addChild(new Spacer(1));
523
- const total = run.usage.toolUses;
524
- const label = total > run.activities.length ? `Activity · last ${run.activities.length} of ${total}` : "Activity";
525
- container.addChild(new Text(theme.fg("muted", label), 0, 0));
526
- for (const activity of run.activities) {
527
- // Deviation earns ink: × and › are marked, success rows are quiet
528
- // one-liners without result echoes.
529
- let text;
530
- if (activity.status === "failed") {
531
- text = `${theme.fg("error", "×")} ${theme.fg("toolOutput", excerpt(activity.summary, ACTIVITY_SUMMARY_LIMIT))}`;
532
- if (activity.resultSummary) {
533
- text += ` ${theme.fg("error", `· ${excerpt(activity.resultSummary, ACTIVITY_RESULT_LIMIT)}`)}`;
534
- }
535
- }
536
- else if (activity.status === "running") {
537
- text = `${theme.fg("accent", "›")} ${theme.fg("toolOutput", excerpt(activity.summary, ACTIVITY_SUMMARY_LIMIT))}`;
538
- }
539
- else {
540
- text = ` ${theme.fg("toolOutput", excerpt(activity.summary, ACTIVITY_SUMMARY_LIMIT))}`;
541
- }
542
- if (activity.endedAt !== undefined && activity.endedAt - activity.startedAt >= ACTIVITY_DURATION_MIN_MS) {
543
- text += ` ${theme.fg("dim", `· ${formatDuration((activity.endedAt - activity.startedAt) / 1000)}`)}`;
544
- }
545
- container.addChild(new Text(text, 0, 0));
546
- }
213
+ for (const activity of run.activities)
214
+ container.addChild(new Text(activityLine(activity, run, theme), 0, 0));
547
215
  }
548
- // The live tail is the "now" end of the timeline; once the run settles,
549
- // Report takes this slot without moving anything above it.
550
- if (run.status === "running" && run.liveText) {
551
- const tail = liveTailLines(run).slice(-EXPANDED_LIVE_TAIL_LINES);
552
- if (tail.length > 0) {
553
- container.addChild(new Spacer(1));
554
- container.addChild(new Text(theme.fg("muted", "Working"), 0, 0));
555
- for (const line of tail) {
556
- container.addChild(new Text(theme.fg("dim", excerpt(line, LIVE_TAIL_LIMIT)), 0, 0));
557
- }
558
- }
216
+ else {
217
+ const fallback = retry
218
+ ? "Waiting to retry"
219
+ : run.status === "failed" || run.status === "aborted"
220
+ ? "No activity recorded"
221
+ : (runningDetail(run) ?? statusWord(run.status));
222
+ container.addChild(new Text(theme.fg("dim", ` ${fallback}`), 0, 0));
559
223
  }
560
224
  if (run.error) {
561
225
  container.addChild(new Spacer(1));
562
226
  container.addChild(new Text(theme.fg("muted", "Error"), 0, 0));
563
227
  container.addChild(new Text(theme.fg("error", run.error), 0, 0));
564
228
  }
565
- if (run.finalOutput) {
229
+ return container;
230
+ }
231
+ function renderSettledRun(run, index, args, theme) {
232
+ const container = new Container();
233
+ container.addChild(new Text(runHeader(run, index, args, theme), 0, 0));
234
+ container.addChild(new Text(theme.fg("dim", runMetrics(run)), 0, 0));
235
+ container.addChild(new Spacer(1));
236
+ container.addChild(new Text(theme.fg("muted", "Prompt"), 0, 0));
237
+ container.addChild(new Text(theme.fg("toolOutput", taskPrompt(args, index, run)), 0, 0));
238
+ if (run.error) {
566
239
  container.addChild(new Spacer(1));
567
- const label = settled && run.status !== "completed" ? "Report · partial" : "Report";
568
- container.addChild(new Text(theme.fg("muted", label), 0, 0));
569
- container.addChild(new Markdown(run.finalOutput, 0, 0, getMarkdownTheme(), {
240
+ container.addChild(new Text(theme.fg("muted", "Error"), 0, 0));
241
+ container.addChild(new Text(theme.fg("error", run.error), 0, 0));
242
+ }
243
+ container.addChild(new Spacer(1));
244
+ const reportLabel = run.status !== "completed" && run.report ? "Report · partial" : "Report";
245
+ container.addChild(new Text(theme.fg("muted", reportLabel), 0, 0));
246
+ if (run.report) {
247
+ container.addChild(new Markdown(run.report, 0, 0, getMarkdownTheme(), {
570
248
  color: (text) => theme.fg("toolOutput", text),
571
249
  }));
572
250
  }
251
+ else {
252
+ container.addChild(new Text(theme.fg("muted", "(No report.)"), 0, 0));
253
+ }
573
254
  return container;
574
255
  }
575
- // The call header stays a single line: run rows in the result area take
576
- // over within the first update and carry richer per-task state, so a
577
- // task list here would render everything twice. The task count alone
578
- // distinguishes a batch from a single delegation.
256
+ function fallbackResult(result, theme, isError) {
257
+ const text = result.content.find((part) => part.type === "text");
258
+ const value = text?.type === "text" ? truncate(text.text, FALLBACK_OUTPUT_LIMIT) : "(no output)";
259
+ return new Text(theme.fg(isError ? "error" : "muted", value), 0, 0);
260
+ }
579
261
  export function renderSubagentCall(args, theme) {
580
- const modes = [args.prompt != null && "prompt", args.tasks != null && "tasks"].filter((mode) => Boolean(mode));
581
- if (modes.length > 1) {
582
- return new Text(`${theme.fg("toolTitle", theme.bold("Subagent "))}${theme.fg("error", `invalid · ${modes.join(" + ")}`)}`, 0, 0);
583
- }
584
- if (args.tasks) {
585
- return new Text(`${theme.fg("toolTitle", theme.bold("Multi-Agent"))}${theme.fg("dim", ` · ${args.tasks.length} task${args.tasks.length === 1 ? "" : "s"}`)}`, 0, 0);
586
- }
587
- let text = theme.fg("toolTitle", theme.bold(`${singleAgentName(args)} Agent`));
588
- if (args.description)
589
- text += theme.fg("dim", ` · ${truncate(args.description, 72)}`);
590
- return new Text(text, 0, 0);
262
+ const count = Array.isArray(args.tasks) ? args.tasks.length : 0;
263
+ const label = `${count} task${count === 1 ? "" : "s"}`;
264
+ return new Text(`${theme.fg("toolTitle", theme.bold("Subagent"))}${theme.fg(count > 0 ? "dim" : "error", ` · ${label}`)}`, 0, 0);
591
265
  }
592
- export function renderSubagentResult(result, options, theme, isError) {
266
+ export function renderSubagentResult(result, options, theme, args, isError) {
593
267
  const details = result.details;
594
- if (!details) {
595
- const text = result.content.find((part) => part.type === "text");
596
- const label = text?.type === "text" ? text.text : "(no output)";
597
- return new Text(theme.fg(isError ? "error" : "muted", label), 0, 0);
598
- }
599
- // The pre-resolution first paint carries no runs yet, in either mode.
600
- if (details.runs.length === 0) {
268
+ if (!details || !Array.isArray(details.runs))
269
+ return fallbackResult(result, theme, isError);
270
+ if (details.runs.length === 0)
601
271
  return new Text(theme.fg("muted", "Initializing…"), 0, 0);
602
- }
603
272
  if (!options.expanded) {
604
- if (details.mode === "single") {
605
- const lines = singleCollapsedLines(details, theme);
606
- if (!options.isPartial) {
607
- const usage = collapsedUsageText(details, true);
608
- if (usage)
609
- lines.push(theme.fg("dim", usage));
610
- lines.push(theme.fg("muted", `(${keyHint("app.tools.expand", "to expand")})`));
611
- }
612
- return new Text(lines.join("\n"), 0, 0);
613
- }
614
273
  const container = new Container();
615
- let header = statusSummary(details);
616
- if (options.isPartial) {
617
- header += ` · ${formatDuration(Math.max(0, (Date.now() - details.startedAt) / 1000))}`;
618
- }
619
- container.addChild(new Text(theme.fg(isError ? "error" : options.isPartial ? "accent" : "muted", header), 0, 0));
620
- const shown = selectCollapsedRuns(details.runs, Boolean(options.isPartial));
621
- // Stable ordinals (the run's task position, not its display slot)
622
- // keep identity readable while active-first ordering reshuffles
623
- // rows, and match the expanded section numbers.
624
- for (const run of shown)
625
- addRunSummary(container, run, theme, details.runs.indexOf(run) + 1);
626
- const hidden = details.runs.length - shown.length;
627
- if (hidden > 0)
628
- container.addChild(new Text(theme.fg("muted", `+${hidden} more`), 0, 0));
629
- if (!options.isPartial) {
630
- const usage = collapsedUsageText(details, false);
631
- if (usage)
632
- container.addChild(new Text(theme.fg("dim", usage), 0, 0));
633
- container.addChild(new Text(theme.fg("muted", `(${keyHint("app.tools.expand", "to expand")})`), 0, 0));
274
+ const header = options.isPartial
275
+ ? progressHeader(details, theme)
276
+ : `${batchMarker(details, theme)} ${theme.fg(isError ? "error" : "muted", outcomeSummary(details))}`;
277
+ container.addChild(new Text(header, 0, 0));
278
+ for (const [index, run] of details.runs.entries()) {
279
+ container.addChild(new Text(taskRow(run, index, args, theme, options.isPartial), 0, 0));
634
280
  }
635
281
  return container;
636
282
  }
637
283
  const container = new Container();
638
- const single = details.mode === "single" && details.runs.length === 1;
639
- if (!single) {
640
- container.addChild(new Text(theme.fg(isError ? "error" : "toolTitle", statusSummary(details)), 0, 0));
641
- // Numbered table of contents: the TUI cannot jump, but matching the
642
- // numbers against the `──` section headers below makes an 8-run
643
- // batch navigable by eye.
644
- details.runs.forEach((run, index) => {
645
- addRunSummary(container, run, theme, index + 1);
646
- });
647
- }
648
- details.runs.forEach((run, index) => {
649
- if (!single || index > 0)
650
- container.addChild(new Spacer(1));
651
- container.addChild(renderRunDetails(run, theme, single, single ? undefined : index + 1));
652
- });
653
- if (!single) {
654
- const usage = batchUsageText(details, Boolean(options.isPartial));
655
- if (usage) {
656
- container.addChild(new Spacer(1));
657
- container.addChild(new Text(theme.fg("dim", usage), 0, 0));
658
- }
284
+ const header = options.isPartial
285
+ ? progressHeader(details, theme)
286
+ : `${batchMarker(details, theme)} ${theme.fg(isError ? "error" : "toolTitle", outcomeSummary(details))}`;
287
+ container.addChild(new Text(header, 0, 0));
288
+ for (const [index, run] of details.runs.entries()) {
289
+ container.addChild(new Spacer(1));
290
+ container.addChild(options.isPartial ? renderRunningRun(run, index, args, theme) : renderSettledRun(run, index, args, theme));
659
291
  }
660
292
  return container;
661
293
  }