oira666_pi-subagent 0.5.12 → 0.5.13
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/package.json +1 -1
- package/render.ts +27 -23
- package/ui/detail-lines.ts +7 -22
- package/ui/tree-format.ts +4 -3
package/package.json
CHANGED
package/render.ts
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Container,
|
|
3
|
+
Spacer,
|
|
4
|
+
Text,
|
|
5
|
+
sliceByColumn,
|
|
6
|
+
truncateToWidth,
|
|
7
|
+
visibleWidth,
|
|
8
|
+
type Component,
|
|
9
|
+
} from "@earendil-works/pi-tui";
|
|
2
10
|
|
|
3
|
-
|
|
11
|
+
// Truncation emits SGR 0, which clears the enclosing toolbox's background.
|
|
12
|
+
// Reset text styling only; the parent owns the background and its right padding.
|
|
13
|
+
const fitLine = (text: string, width: number) =>
|
|
14
|
+
truncateToWidth(text, width, "").replace(/\u001b\[0m/g, "\u001b[22;23;24;25;27;28;29;39m");
|
|
4
15
|
|
|
5
16
|
import { MAX_LIVE_LOG_ENTRIES, isSubagentDetails, type SubagentDetails } from "./types.js";
|
|
6
17
|
import { formatSubagentLabel } from "./ui/agent-label.js";
|
|
@@ -127,9 +138,10 @@ function compactText(text: string, maxLength = 240): string {
|
|
|
127
138
|
function takePromptLine(text: string, width: number): { line: string; rest: string } {
|
|
128
139
|
const normalized = text.replace(/\s+/g, " ").trim();
|
|
129
140
|
if (!normalized || width <= 0) return { line: "", rest: normalized };
|
|
130
|
-
if (normalized
|
|
131
|
-
|
|
132
|
-
|
|
141
|
+
if (visibleWidth(normalized) <= width) return { line: normalized, rest: "" };
|
|
142
|
+
const prefix = sliceByColumn(normalized, 0, width, true);
|
|
143
|
+
let split = prefix.lastIndexOf(" ");
|
|
144
|
+
if (split < 1 || visibleWidth(prefix.slice(0, split)) < Math.floor(width / 2)) split = prefix.length;
|
|
133
145
|
return { line: normalized.slice(0, split), rest: normalized.slice(split).trimStart() };
|
|
134
146
|
}
|
|
135
147
|
|
|
@@ -144,16 +156,18 @@ class CollapsedSubagentComponent implements Component {
|
|
|
144
156
|
const nodes = buildTopLevelNodes(this.details, { hydrateSessions: false });
|
|
145
157
|
const lines: string[] = [];
|
|
146
158
|
for (const node of nodes) {
|
|
147
|
-
const
|
|
148
|
-
const
|
|
159
|
+
const prefix = ` ${statusEmoji(node.status, this.theme)} ${this.theme.fg("accent", node.label)} `;
|
|
160
|
+
const prefixWidth = visibleWidth(prefix);
|
|
161
|
+
const firstWidth = Math.max(0, width - prefixWidth);
|
|
149
162
|
const first = takePromptLine(node.task ?? "", firstWidth);
|
|
150
|
-
const continuationIndent = " ".repeat(Math.min(
|
|
151
|
-
const
|
|
152
|
-
const
|
|
163
|
+
const continuationIndent = " ".repeat(Math.min(prefixWidth, Math.max(0, width - 8)));
|
|
164
|
+
const secondWidth = Math.max(0, width - continuationIndent.length);
|
|
165
|
+
const second = takePromptLine(first.rest, secondWidth);
|
|
166
|
+
const firstLine = `${prefix}${this.theme.fg("dim", first.line)}`;
|
|
153
167
|
lines.push(fitLine(firstLine, width));
|
|
154
168
|
if (first.rest) {
|
|
155
169
|
const hasMore = second.rest.length > 0;
|
|
156
|
-
const secondText =
|
|
170
|
+
const secondText = hasMore ? truncateToWidth(first.rest, secondWidth) : second.line;
|
|
157
171
|
lines.push(fitLine(`${continuationIndent}${this.theme.fg("dim", secondText)}`, width));
|
|
158
172
|
}
|
|
159
173
|
const actionAt = node.lastActionAt ?? node.startedAt;
|
|
@@ -203,12 +217,7 @@ export function renderResult(
|
|
|
203
217
|
const nodes = expandedNodes(details);
|
|
204
218
|
const counts = countNodes(nodes);
|
|
205
219
|
const showOutputPreview = verbose && !hasNestedChildren(nodes);
|
|
206
|
-
const icon =
|
|
207
|
-
counts.running > 0
|
|
208
|
-
? theme.fg("warning", "⏳")
|
|
209
|
-
: counts.error > 0
|
|
210
|
-
? theme.fg("error", "❌")
|
|
211
|
-
: theme.fg("success", "✅");
|
|
220
|
+
const icon = statusEmoji(counts.running > 0 ? "running" : counts.error > 0 ? "error" : "success", theme);
|
|
212
221
|
|
|
213
222
|
const container = new Container();
|
|
214
223
|
container.addChild(
|
|
@@ -235,12 +244,7 @@ export function renderResult(
|
|
|
235
244
|
agent: typeof item?.agent === "string" ? item.agent : "unknown agent",
|
|
236
245
|
intelligence: item?.intelligence,
|
|
237
246
|
});
|
|
238
|
-
const icon =
|
|
239
|
-
item?.exitCode === -1
|
|
240
|
-
? theme.fg("warning", "⏳")
|
|
241
|
-
: item?.exitCode === 0
|
|
242
|
-
? theme.fg("success", "✅")
|
|
243
|
-
: theme.fg("error", "❌");
|
|
247
|
+
const icon = statusEmoji(item?.exitCode === -1 ? "running" : item?.exitCode === 0 ? "success" : "error", theme);
|
|
244
248
|
lines.push(`${icon} ${theme.fg("accent", label)}`);
|
|
245
249
|
const liveLog = Array.isArray(item?.liveLog) ? item.liveLog.slice(-MAX_LIVE_LOG_ENTRIES) : [];
|
|
246
250
|
for (const entry of liveLog) {
|
package/ui/detail-lines.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { visibleWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
|
|
1
2
|
import { RESUME_SUBAGENTS_TOOL_NAME } from "../types.js";
|
|
2
3
|
import { displayIntelligence } from "../intelligence.js";
|
|
3
4
|
import { formatSubagentLabel } from "./agent-label.js";
|
|
4
|
-
import { type ThemeFg, formatClockTime, formatTokens, truncate } from "./tree-format.js";
|
|
5
|
+
import { type ThemeFg, formatClockTime, formatTokens, statusEmoji, truncate } from "./tree-format.js";
|
|
5
6
|
import type { DetailBlock, DetailChildRef, DetailUsage, SubagentDetail } from "./detail-model.js";
|
|
6
7
|
import {
|
|
7
8
|
getTurnTools,
|
|
@@ -18,28 +19,12 @@ export interface DetailTheme {
|
|
|
18
19
|
const PLAIN_THEME: DetailTheme = { fg: (_color, text) => text, bold: (text) => text };
|
|
19
20
|
|
|
20
21
|
export function wrapPlain(text: string, width: number): string[] {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
for (const rawLine of text.replace(/\r\n?/g, "\n").split("\n")) {
|
|
24
|
-
const line = rawLine.replace(/\t/g, " ");
|
|
25
|
-
if (line.length <= usable) {
|
|
26
|
-
out.push(line);
|
|
27
|
-
continue;
|
|
28
|
-
}
|
|
29
|
-
let rest = line;
|
|
30
|
-
while (rest.length > usable) {
|
|
31
|
-
let cut = rest.lastIndexOf(" ", usable);
|
|
32
|
-
if (cut < Math.floor(usable / 2)) cut = usable;
|
|
33
|
-
out.push(rest.slice(0, cut).trimEnd());
|
|
34
|
-
rest = rest.slice(cut).trimStart();
|
|
35
|
-
}
|
|
36
|
-
if (rest) out.push(rest);
|
|
37
|
-
}
|
|
38
|
-
return out.length > 0 ? out : [""];
|
|
22
|
+
if (width <= 0) return [""];
|
|
23
|
+
return wrapTextWithAnsi(text.replace(/\r\n?/g, "\n").replace(/\t/g, " "), width);
|
|
39
24
|
}
|
|
40
25
|
|
|
41
26
|
function statusIcon(status: DetailChildRef["status"]): string {
|
|
42
|
-
return status
|
|
27
|
+
return statusEmoji(status, PLAIN_THEME);
|
|
43
28
|
}
|
|
44
29
|
|
|
45
30
|
function usageLine(usage: DetailUsage): string {
|
|
@@ -137,7 +122,7 @@ export function renderTurnOverviewLines(
|
|
|
137
122
|
const branch = index === children.length - 1 ? "└─" : "├─";
|
|
138
123
|
const label = formatSubagentLabel(child);
|
|
139
124
|
const task = child.task
|
|
140
|
-
? ` — ${truncate(child.task.replace(/\s+/g, " "), Math.max(24, width - label
|
|
125
|
+
? ` — ${truncate(child.task.replace(/\s+/g, " "), Math.max(24, width - visibleWidth(label) - 13))}`
|
|
141
126
|
: "";
|
|
142
127
|
out.push(` ${branch} ${statusIcon(child.status)} ${theme.fg("accent", label)}${theme.fg("dim", task)}`);
|
|
143
128
|
});
|
|
@@ -200,7 +185,7 @@ export function renderChildTreeLines(
|
|
|
200
185
|
const branch = index === children.length - 1 ? "└─" : "├─";
|
|
201
186
|
const label = formatSubagentLabel(child);
|
|
202
187
|
const task = child.task
|
|
203
|
-
? ` — ${truncate(child.task.replace(/\s+/g, " "), Math.max(16, width - label
|
|
188
|
+
? ` — ${truncate(child.task.replace(/\s+/g, " "), Math.max(16, width - visibleWidth(label) - 12))}`
|
|
204
189
|
: "";
|
|
205
190
|
out.push(`${marker} ${branch} ${statusIcon(child.status)} ${theme.fg("accent", label)}${theme.fg("dim", task)}`);
|
|
206
191
|
});
|
package/ui/tree-format.ts
CHANGED
|
@@ -62,14 +62,15 @@ export function truncate(text: unknown, maxLen: number): string {
|
|
|
62
62
|
return safeText.length > maxLen ? `${safeText.slice(0, maxLen)}...` : safeText;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
// Avoid emoji: some terminal fonts display them in one cell while Pi measures two.
|
|
65
66
|
export function statusEmoji(status: NodeStatus, theme: { fg: ThemeFg }): string {
|
|
66
67
|
switch (status) {
|
|
67
68
|
case "running":
|
|
68
|
-
return theme.fg("warning", "
|
|
69
|
+
return theme.fg("warning", "…");
|
|
69
70
|
case "error":
|
|
70
|
-
return theme.fg("error", "
|
|
71
|
+
return theme.fg("error", "✗");
|
|
71
72
|
default:
|
|
72
|
-
return theme.fg("success", "
|
|
73
|
+
return theme.fg("success", "✓");
|
|
73
74
|
}
|
|
74
75
|
}
|
|
75
76
|
|