oira666_pi-subagent 0.1.13 → 0.1.14
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 +84 -1
- package/runner-sdk.ts +552 -500
- package/runner.ts +56 -0
- package/shared.ts +75 -75
- package/types.ts +23 -0
package/package.json
CHANGED
package/render.ts
CHANGED
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
* TUI rendering for subagent tool calls and results.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
+
import * as os from "node:os";
|
|
5
6
|
import { Container, Spacer, Text } from "@mariozechner/pi-tui";
|
|
6
7
|
import {
|
|
7
8
|
type DelegationMode,
|
|
9
|
+
type LiveLogEntry,
|
|
8
10
|
type NestedSubagentResult,
|
|
9
11
|
type SingleResult,
|
|
10
12
|
type SubagentDetails,
|
|
@@ -29,6 +31,7 @@ interface TreeNode {
|
|
|
29
31
|
meta?: string;
|
|
30
32
|
task?: string;
|
|
31
33
|
outputPreview?: string[];
|
|
34
|
+
liveActivity?: LiveLogEntry[];
|
|
32
35
|
children: TreeNode[];
|
|
33
36
|
}
|
|
34
37
|
|
|
@@ -203,6 +206,78 @@ function buildNestedChildren(result: SingleResult): TreeNode[] {
|
|
|
203
206
|
return nodes;
|
|
204
207
|
}
|
|
205
208
|
|
|
209
|
+
function formatToolArgPreview(toolName: string, args: Record<string, unknown>): string {
|
|
210
|
+
const shorten = (p: string) => {
|
|
211
|
+
const home = os.homedir();
|
|
212
|
+
return p.startsWith(home) ? `~${p.slice(home.length)}` : p;
|
|
213
|
+
};
|
|
214
|
+
const truncateTo = (s: string, n: number) =>
|
|
215
|
+
s.length > n ? s.slice(0, n) + "\u2026" : s;
|
|
216
|
+
|
|
217
|
+
switch (toolName) {
|
|
218
|
+
case "bash": {
|
|
219
|
+
const cmd = (args.command as string) || "";
|
|
220
|
+
return truncateTo(cmd.replace(/\s+/g, " "), 52);
|
|
221
|
+
}
|
|
222
|
+
case "read":
|
|
223
|
+
case "write":
|
|
224
|
+
case "edit":
|
|
225
|
+
return shorten(truncateTo((args.path ?? args.file_path ?? "") as string, 52));
|
|
226
|
+
case "grep":
|
|
227
|
+
return truncateTo(`/${args.pattern}/`, 30) +
|
|
228
|
+
(args.path ? ` in ${shorten(args.path as string)}` : "");
|
|
229
|
+
case "find":
|
|
230
|
+
return truncateTo((args.pattern ?? "*") as string, 30) +
|
|
231
|
+
(args.path ? ` in ${shorten(args.path as string)}` : "");
|
|
232
|
+
case "subagent": {
|
|
233
|
+
const tasks = (args.tasks as any[]) ?? [];
|
|
234
|
+
return tasks.map((t: any) => t.agent).join(", ");
|
|
235
|
+
}
|
|
236
|
+
default:
|
|
237
|
+
return "";
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function formatLiveLogEntry(
|
|
242
|
+
entry: LiveLogEntry,
|
|
243
|
+
theme: { fg: ThemeFg },
|
|
244
|
+
): string {
|
|
245
|
+
switch (entry.kind) {
|
|
246
|
+
case "turn_start":
|
|
247
|
+
return theme.fg("muted", "\u27f3") + " " + theme.fg("dim", "thinking\u2026");
|
|
248
|
+
|
|
249
|
+
case "turn_end": {
|
|
250
|
+
const tokens = entry.inputTokens || entry.outputTokens
|
|
251
|
+
? " " + theme.fg("dim",
|
|
252
|
+
`\u2191${formatTokens(entry.inputTokens)} \u2193${formatTokens(entry.outputTokens)}`)
|
|
253
|
+
: "";
|
|
254
|
+
return (
|
|
255
|
+
theme.fg("success", "\u2713") +
|
|
256
|
+
" " +
|
|
257
|
+
theme.fg("muted", `turn ${entry.turn}`) +
|
|
258
|
+
tokens
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
case "tool_start": {
|
|
263
|
+
const argPreview = formatToolArgPreview(entry.toolName, entry.args);
|
|
264
|
+
return (
|
|
265
|
+
theme.fg("muted", "\u2192") +
|
|
266
|
+
" " +
|
|
267
|
+
theme.fg("accent", entry.toolName) +
|
|
268
|
+
(argPreview ? " " + theme.fg("dim", argPreview) : "")
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
case "tool_end":
|
|
273
|
+
return (
|
|
274
|
+
theme.fg("success", "\u2713") +
|
|
275
|
+
" " +
|
|
276
|
+
theme.fg("accent", entry.toolName)
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
206
281
|
function buildLeafPreview(result: SingleResult): string[] | undefined {
|
|
207
282
|
const items = getDisplayItems(result.messages);
|
|
208
283
|
const lines: string[] = [];
|
|
@@ -228,12 +303,14 @@ function buildResultNode(result: SingleResult, delegationMode: DelegationMode):
|
|
|
228
303
|
}
|
|
229
304
|
|
|
230
305
|
const children = buildNestedChildren(result);
|
|
306
|
+
const isRunning = status === "running";
|
|
231
307
|
return {
|
|
232
308
|
label: result.agent,
|
|
233
309
|
status,
|
|
234
310
|
meta: metaParts.join(" • "),
|
|
235
311
|
task: result.task,
|
|
236
|
-
|
|
312
|
+
liveActivity: isRunning && result.liveLog?.length > 0 ? result.liveLog : undefined,
|
|
313
|
+
outputPreview: !isRunning && children.length === 0 ? buildLeafPreview(result) : undefined,
|
|
237
314
|
children,
|
|
238
315
|
};
|
|
239
316
|
}
|
|
@@ -262,6 +339,12 @@ function renderTreeLines(
|
|
|
262
339
|
}
|
|
263
340
|
}
|
|
264
341
|
|
|
342
|
+
if (showOutputPreview && node.liveActivity && node.liveActivity.length > 0) {
|
|
343
|
+
for (const entry of node.liveActivity) {
|
|
344
|
+
lines.push(`${indent} ${formatLiveLogEntry(entry, theme)}`);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
265
348
|
if (node.children.length > 0) {
|
|
266
349
|
lines.push(...renderTreeLines(node.children, theme, false, depth + 1));
|
|
267
350
|
}
|