@pi-archimedes/subagent 1.8.3 → 1.9.0
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 +2 -2
- package/src/compact.ts +17 -5
- package/src/expanded.ts +22 -6
- package/src/handlers.ts +16 -3
- package/src/types.ts +9 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-archimedes/subagent",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package"
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
],
|
|
12
12
|
"main": "./src/index.ts",
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@pi-archimedes/core": "1.
|
|
14
|
+
"@pi-archimedes/core": "1.9.0"
|
|
15
15
|
},
|
|
16
16
|
"peerDependencies": {
|
|
17
17
|
"@earendil-works/pi-ai": ">=0.1.0",
|
package/src/compact.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Text } from "@earendil-works/pi-tui";
|
|
2
|
-
import type { SubagentDetails, SubagentProgress, SubagentResult, SubagentToolResult } from "./types.js";
|
|
2
|
+
import type { SubagentDetails, SubagentProgress, SubagentResult, SubagentToolCall, SubagentToolResult } from "./types.js";
|
|
3
3
|
import { formatTokens, formatDuration, formatCost, truncLine, buildStatsLine, buildAgentLabel } from "./format.js";
|
|
4
4
|
|
|
5
5
|
type Theme = { fg: (token: string, text: string) => string; bold: (text: string) => string };
|
|
@@ -14,7 +14,7 @@ interface ActivityData {
|
|
|
14
14
|
finalOutput: string | undefined;
|
|
15
15
|
status: "running" | "completed" | "failed" | undefined;
|
|
16
16
|
error: string | undefined;
|
|
17
|
-
toolCalls?: string[] | undefined;
|
|
17
|
+
toolCalls?: (SubagentToolCall | string)[] | undefined;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
export function buildActivityLine(
|
|
@@ -35,7 +35,7 @@ export function buildActivityLine(
|
|
|
35
35
|
return theme.fg("error", "✗ Failed");
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
// Running: show the current tool with live duration
|
|
38
|
+
// Running: show the current tool with live duration (grey while running)
|
|
39
39
|
if (data.currentTool) {
|
|
40
40
|
const arrow = theme.fg("muted", "↳ ");
|
|
41
41
|
const argsPreview = data.currentToolArgs
|
|
@@ -44,7 +44,7 @@ export function buildActivityLine(
|
|
|
44
44
|
const durationPart = data.currentToolStartedAt
|
|
45
45
|
? " | " + formatDuration(Date.now() - data.currentToolStartedAt)
|
|
46
46
|
: "";
|
|
47
|
-
let line = theme.fg("
|
|
47
|
+
let line = theme.fg("muted", data.currentTool);
|
|
48
48
|
if (argsPreview) {
|
|
49
49
|
line += theme.fg("dim", ": " + argsPreview);
|
|
50
50
|
}
|
|
@@ -55,9 +55,21 @@ export function buildActivityLine(
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
// Running, no active tool: show the most recently completed tool call
|
|
58
|
+
// Color only the tool name green (success) or red (error)
|
|
58
59
|
if (data.toolCalls && data.toolCalls.length > 0) {
|
|
59
60
|
const lastCall = data.toolCalls[data.toolCalls.length - 1];
|
|
60
|
-
if (lastCall)
|
|
61
|
+
if (lastCall) {
|
|
62
|
+
if (typeof lastCall === "string") {
|
|
63
|
+
return theme.fg("dim", "↳ " + truncLine(lastCall, 60));
|
|
64
|
+
}
|
|
65
|
+
const color = lastCall.error ? "error" : "success";
|
|
66
|
+
const arrow = theme.fg("muted", "↳ ");
|
|
67
|
+
const name = theme.fg(color, lastCall.name);
|
|
68
|
+
const argsPart = lastCall.argsPreview
|
|
69
|
+
? theme.fg("dim", ": " + truncLine(lastCall.argsPreview, 60))
|
|
70
|
+
: "";
|
|
71
|
+
return arrow + name + argsPart;
|
|
72
|
+
}
|
|
61
73
|
}
|
|
62
74
|
|
|
63
75
|
// Running, no tool history: show first line of streamed output if any
|
package/src/expanded.ts
CHANGED
|
@@ -1,9 +1,25 @@
|
|
|
1
1
|
import { Text } from "@earendil-works/pi-tui";
|
|
2
|
-
import type { SubagentDetails, SubagentProgress, SubagentResult } from "./types.js";
|
|
2
|
+
import type { SubagentDetails, SubagentProgress, SubagentResult, SubagentToolCall } from "./types.js";
|
|
3
3
|
import { formatTokens, formatDuration, truncLine, buildStatsLine, buildAgentLabel } from "./format.js";
|
|
4
4
|
|
|
5
5
|
type Theme = { fg: (token: string, text: string) => string; bold: (text: string) => string };
|
|
6
6
|
|
|
7
|
+
// ── Helpers ─────────────────────────────────────────────────────────────────
|
|
8
|
+
|
|
9
|
+
function formatToolCall(call: SubagentToolCall | string, theme: Theme): string {
|
|
10
|
+
// Backward compat: old persisted sessions may have toolCalls as string[]
|
|
11
|
+
if (typeof call === "string") {
|
|
12
|
+
return theme.fg("dim", "↳ " + call);
|
|
13
|
+
}
|
|
14
|
+
const arrow = theme.fg("muted", "↳ ");
|
|
15
|
+
const color = call.error ? "error" : "success";
|
|
16
|
+
const name = theme.fg(color, call.name);
|
|
17
|
+
const argsPart = call.argsPreview
|
|
18
|
+
? theme.fg("dim", ": " + call.argsPreview)
|
|
19
|
+
: "";
|
|
20
|
+
return arrow + name + argsPart;
|
|
21
|
+
}
|
|
22
|
+
|
|
7
23
|
// ── Expanded completed result ───────────────────────────────────────────────
|
|
8
24
|
|
|
9
25
|
export function buildExpandedText(
|
|
@@ -43,7 +59,7 @@ export function buildExpandedText(
|
|
|
43
59
|
if (toolCalls && toolCalls.length > 0) {
|
|
44
60
|
lines.push("");
|
|
45
61
|
for (const call of toolCalls) {
|
|
46
|
-
lines.push(
|
|
62
|
+
lines.push(formatToolCall(call, theme));
|
|
47
63
|
}
|
|
48
64
|
}
|
|
49
65
|
|
|
@@ -116,7 +132,7 @@ export function renderProgressExpanded(
|
|
|
116
132
|
if (progress.toolCalls && progress.toolCalls.length > 0) {
|
|
117
133
|
lines.push("");
|
|
118
134
|
for (const call of progress.toolCalls) {
|
|
119
|
-
lines.push(
|
|
135
|
+
lines.push(formatToolCall(call, theme));
|
|
120
136
|
}
|
|
121
137
|
}
|
|
122
138
|
|
|
@@ -129,7 +145,7 @@ export function renderProgressExpanded(
|
|
|
129
145
|
const durationPart = progress.currentToolStartedAt
|
|
130
146
|
? " | " + formatDuration(Date.now() - progress.currentToolStartedAt)
|
|
131
147
|
: "";
|
|
132
|
-
let line = theme.fg("
|
|
148
|
+
let line = theme.fg("muted", progress.currentTool);
|
|
133
149
|
if (argsPreview) {
|
|
134
150
|
line += theme.fg("dim", ": " + argsPreview);
|
|
135
151
|
}
|
|
@@ -192,7 +208,7 @@ export function buildProgressExpandedText(
|
|
|
192
208
|
if (progress.toolCalls && progress.toolCalls.length > 0) {
|
|
193
209
|
lines.push("");
|
|
194
210
|
for (const call of progress.toolCalls) {
|
|
195
|
-
lines.push(
|
|
211
|
+
lines.push(formatToolCall(call, theme));
|
|
196
212
|
}
|
|
197
213
|
}
|
|
198
214
|
|
|
@@ -204,7 +220,7 @@ export function buildProgressExpandedText(
|
|
|
204
220
|
const durationPart = progress.currentToolStartedAt
|
|
205
221
|
? " | " + formatDuration(Date.now() - progress.currentToolStartedAt)
|
|
206
222
|
: "";
|
|
207
|
-
let line = theme.fg("
|
|
223
|
+
let line = theme.fg("muted", progress.currentTool);
|
|
208
224
|
if (argsPreview) {
|
|
209
225
|
line += theme.fg("dim", ": " + argsPreview);
|
|
210
226
|
}
|
package/src/handlers.ts
CHANGED
|
@@ -50,11 +50,16 @@ export function extractArgsPreview(args: unknown): string {
|
|
|
50
50
|
export function handleToolStart(state: StreamState, event: JsonEvent): void {
|
|
51
51
|
state.toolCount++;
|
|
52
52
|
state.currentTool = event.toolName as string;
|
|
53
|
-
|
|
53
|
+
// Use extractArgsPreview instead of JSON.stringify for readable display
|
|
54
|
+
const argsPreview = extractArgsPreview(event.args);
|
|
55
|
+
state.currentToolArgs = argsPreview;
|
|
54
56
|
state.currentToolStartedAt = Date.now();
|
|
55
57
|
// Record tool call with args preview
|
|
56
|
-
|
|
57
|
-
|
|
58
|
+
state.toolCalls.push({
|
|
59
|
+
name: state.currentTool,
|
|
60
|
+
argsPreview,
|
|
61
|
+
error: false,
|
|
62
|
+
});
|
|
58
63
|
if (state.toolCalls.length > TOOL_CALLS_MAX) {
|
|
59
64
|
state.toolCalls.splice(0, state.toolCalls.length - TOOL_CALLS_MAX);
|
|
60
65
|
}
|
|
@@ -75,6 +80,14 @@ export function handleToolEnd(state: StreamState): void {
|
|
|
75
80
|
*/
|
|
76
81
|
export function handleToolResult(state: StreamState, event: JsonEvent): void {
|
|
77
82
|
const result = event.result as Record<string, unknown> | undefined;
|
|
83
|
+
|
|
84
|
+
// Mark the last tool call as errored if the result indicates an error
|
|
85
|
+
const lastCall = state.toolCalls[state.toolCalls.length - 1];
|
|
86
|
+
const isError = event.isError === true || result?.isError === true;
|
|
87
|
+
if (lastCall && lastCall.name === (event.toolName as string) && isError) {
|
|
88
|
+
lastCall.error = true;
|
|
89
|
+
}
|
|
90
|
+
|
|
78
91
|
if (!result) return;
|
|
79
92
|
|
|
80
93
|
const toolName = (event.toolName as string) ?? "tool";
|
package/src/types.ts
CHANGED
|
@@ -7,6 +7,12 @@ export interface SubagentUsage {
|
|
|
7
7
|
turns: number;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
export interface SubagentToolCall {
|
|
11
|
+
name: string;
|
|
12
|
+
argsPreview: string;
|
|
13
|
+
error: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
10
16
|
export interface SubagentProgress {
|
|
11
17
|
agent: string;
|
|
12
18
|
status: "running" | "completed" | "failed";
|
|
@@ -27,8 +33,8 @@ export interface SubagentProgress {
|
|
|
27
33
|
output: string | undefined;
|
|
28
34
|
/** Last N lines of assistant text for live display */
|
|
29
35
|
recentOutput: string[] | undefined;
|
|
30
|
-
/** History of tool calls
|
|
31
|
-
toolCalls:
|
|
36
|
+
/** History of tool calls with status tracking */
|
|
37
|
+
toolCalls: SubagentToolCall[] | undefined;
|
|
32
38
|
}
|
|
33
39
|
|
|
34
40
|
export interface SubagentResult {
|
|
@@ -70,7 +76,7 @@ export interface StreamState {
|
|
|
70
76
|
model: string | undefined;
|
|
71
77
|
accumulatedOutput: string[];
|
|
72
78
|
recentOutput: string[];
|
|
73
|
-
toolCalls:
|
|
79
|
+
toolCalls: SubagentToolCall[];
|
|
74
80
|
finalOutput: string | undefined;
|
|
75
81
|
}
|
|
76
82
|
|