@ryan_nookpi/pi-extension-subagent 0.4.2 → 0.4.4

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 (2) hide show
  1. package/package.json +1 -1
  2. package/tool-render.ts +18 -21
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ryan_nookpi/pi-extension-subagent",
3
- "version": "0.4.2",
3
+ "version": "0.4.4",
4
4
  "description": "Asynchronous subagent delegation for pi with run, batch, chain, and continuation workflows.",
5
5
  "license": "MIT",
6
6
  "repository": {
package/tool-render.ts CHANGED
@@ -7,6 +7,7 @@
7
7
  import { getMarkdownTheme, type ThemeColor } from "@earendil-works/pi-coding-agent";
8
8
  import { Container, Markdown, Spacer, Text, visibleWidth } from "@earendil-works/pi-tui";
9
9
  import { parseSubagentToolCommand } from "./cli.js";
10
+ import { SUBAGENT_STRONG_WAIT_MESSAGE } from "./constants.js";
10
11
  import { formatToolCall, formatUsageStats } from "./format.js";
11
12
  import { getDisplayItems, getFinalOutput } from "./runner.js";
12
13
  import { COLLAPSED_ITEM_COUNT, truncateText } from "./store.js";
@@ -29,7 +30,7 @@ type ToolCallRenderContext = { expanded: boolean };
29
30
  type CompactBlock = { agent: string; task: string };
30
31
  type ListAgentsDetails = { agents?: Array<{ name?: unknown }> };
31
32
 
32
- const COMPACT_TASK_PREVIEW_WIDTH = 72;
33
+ const COMPACT_TASK_PREVIEW_WIDTH = 67;
33
34
  const COMPACT_AGENT_WIDTH = 20;
34
35
  const COMPACT_MAX_ITEMS = 3;
35
36
  const COMPACT_AGENT_LIST_COUNT = 3;
@@ -117,6 +118,20 @@ function getToolResultText(result: ToolRenderResult): string {
117
118
  return (raw?.type === "text" ? raw.text : undefined) ?? "(no output)";
118
119
  }
119
120
 
121
+ function renderPlainToolResult(fullText: string, expanded: boolean, theme: RenderTheme): Text {
122
+ if (expanded) return new Text(fullText, 0, 0);
123
+
124
+ const waitMessageIndex = fullText.indexOf(SUBAGENT_STRONG_WAIT_MESSAGE);
125
+ if (waitMessageIndex >= 0) {
126
+ return new Text(fullText.slice(0, waitMessageIndex).trimEnd(), 0, 0);
127
+ }
128
+
129
+ const firstLine = fullText.split("\n")[0] ?? "";
130
+ const lineCount = fullText.split("\n").length;
131
+ const suffix = lineCount > 1 ? theme.fg("muted", ` (+${lineCount - 1} lines)`) : "";
132
+ return new Text(firstLine + suffix, 0, 0);
133
+ }
134
+
120
135
  function renderDisplayItems(items: DisplayItem[], expanded: boolean, theme: RenderTheme, limit?: number): string {
121
136
  const toShow = limit ? items.slice(-limit) : items;
122
137
  const skipped = limit && items.length > limit ? items.length - limit : 0;
@@ -200,30 +215,12 @@ export function renderSubagentToolResult(
200
215
  ) {
201
216
  const details = result.details as SubagentDetails | undefined;
202
217
  if (!details || details.results.length === 0) {
203
- const raw = result.content[0];
204
- const fullText = (raw?.type === "text" ? raw.text : undefined) ?? "(no output)";
205
- if (!expanded) {
206
- const firstLine = fullText.split("\n")[0] ?? "";
207
- const lineCount = fullText.split("\n").length;
208
- const suffix = lineCount > 1 ? theme.fg("muted", ` (+${lineCount - 1} lines)`) : "";
209
- return new Text(firstLine + suffix, 0, 0);
210
- }
211
- return new Text(fullText, 0, 0);
218
+ return renderPlainToolResult(getToolResultText(result), expanded, theme);
212
219
  }
213
220
 
214
221
  const mdTheme = getMarkdownTheme();
215
222
  const r = details.results[0];
216
- if (!r) {
217
- const raw2 = result.content[0];
218
- const fullText2 = (raw2?.type === "text" ? raw2.text : undefined) ?? "(no output)";
219
- if (!expanded) {
220
- const firstLine = fullText2.split("\n")[0] ?? "";
221
- const lineCount = fullText2.split("\n").length;
222
- const suffix = lineCount > 1 ? theme.fg("muted", ` (+${lineCount - 1} lines)`) : "";
223
- return new Text(firstLine + suffix, 0, 0);
224
- }
225
- return new Text(fullText2, 0, 0);
226
- }
223
+ if (!r) return renderPlainToolResult(getToolResultText(result), expanded, theme);
227
224
 
228
225
  const isError = r.exitCode !== 0 || r.stopReason === "error" || r.stopReason === "aborted";
229
226
  const icon = isError ? theme.fg("error", "✗") : theme.fg("success", "✓");