@deathbeam/pi-delegate 0.0.33 → 0.0.34
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/child.ts +6 -10
- package/index.ts +10 -8
- package/inspector.ts +8 -2
- package/package.json +1 -1
- package/store.ts +9 -9
package/child.ts
CHANGED
|
@@ -15,12 +15,10 @@ export type ChildActivity = {
|
|
|
15
15
|
kind: "tool" | "result" | "assistant" | "user" | "status";
|
|
16
16
|
text: string;
|
|
17
17
|
detail?: string;
|
|
18
|
+
isError?: boolean;
|
|
18
19
|
};
|
|
19
20
|
export type ChildUpdate = {
|
|
20
21
|
toolCalls?: number;
|
|
21
|
-
lastTool?: string;
|
|
22
|
-
lastDetail?: string;
|
|
23
|
-
lastResult?: string;
|
|
24
22
|
contextTokens?: number;
|
|
25
23
|
activity?: ChildActivity;
|
|
26
24
|
};
|
|
@@ -132,9 +130,6 @@ export function runChild(
|
|
|
132
130
|
const detail = toolCallDetail(event.toolName, event.args);
|
|
133
131
|
onUpdate?.({
|
|
134
132
|
toolCalls,
|
|
135
|
-
lastTool: event.toolName,
|
|
136
|
-
lastDetail: detail,
|
|
137
|
-
lastResult: "",
|
|
138
133
|
activity: { kind: "tool", text: event.toolName, detail },
|
|
139
134
|
});
|
|
140
135
|
return;
|
|
@@ -142,10 +137,10 @@ export function runChild(
|
|
|
142
137
|
case "tool_execution_end": {
|
|
143
138
|
const preview = resultPreview(event.result);
|
|
144
139
|
onUpdate?.({
|
|
145
|
-
lastResult: preview,
|
|
146
140
|
activity: {
|
|
147
141
|
kind: "result",
|
|
148
|
-
text:
|
|
142
|
+
text: preview ?? "",
|
|
143
|
+
...(event.isError ? { isError: true } : {}),
|
|
149
144
|
},
|
|
150
145
|
});
|
|
151
146
|
return;
|
|
@@ -357,7 +352,7 @@ export function priorActivity(sessionDir: string, id: string): ChildActivity[] {
|
|
|
357
352
|
? (entry.message as {
|
|
358
353
|
role?: "assistant" | "user" | "toolResult";
|
|
359
354
|
content?: unknown;
|
|
360
|
-
|
|
355
|
+
isError?: boolean;
|
|
361
356
|
})
|
|
362
357
|
: undefined;
|
|
363
358
|
if (!message?.role) continue;
|
|
@@ -365,7 +360,8 @@ export function priorActivity(sessionDir: string, id: string): ChildActivity[] {
|
|
|
365
360
|
const preview = resultPreview({ content: message.content });
|
|
366
361
|
activity.push({
|
|
367
362
|
kind: "result",
|
|
368
|
-
text: normalize(
|
|
363
|
+
text: normalize(preview ?? ""),
|
|
364
|
+
...(message.isError ? { isError: true } : {}),
|
|
369
365
|
});
|
|
370
366
|
continue;
|
|
371
367
|
}
|
package/index.ts
CHANGED
|
@@ -30,7 +30,7 @@ import {
|
|
|
30
30
|
widgetJobs,
|
|
31
31
|
} from "./format.ts";
|
|
32
32
|
import { priorActivity, runChild } from "./child.ts";
|
|
33
|
-
import { createJobStore, type DelegateJob, type InspectJob } from "./store.ts";
|
|
33
|
+
import { createJobStore, type DelegateJob, lastToolCall, type InspectJob } from "./store.ts";
|
|
34
34
|
import {
|
|
35
35
|
applyClone,
|
|
36
36
|
cloneCwd,
|
|
@@ -162,11 +162,15 @@ export default function (pi: ExtensionAPI) {
|
|
|
162
162
|
`${statusText(theme, "running", now)} ${jobIdentity(theme, job)} ${theme.fg("muted", jobLine(job, elapsedMs(job, now)))}`,
|
|
163
163
|
);
|
|
164
164
|
if (!detail) continue;
|
|
165
|
-
|
|
165
|
+
const { tool, result } = lastToolCall(job);
|
|
166
|
+
if (tool)
|
|
166
167
|
lines.push(
|
|
167
|
-
` ${theme.fg("toolTitle", theme.bold(
|
|
168
|
+
` ${theme.fg("toolTitle", theme.bold(tool.text))}${tool.detail ? ` ${theme.fg("accent", tool.detail)}` : ""}`,
|
|
169
|
+
);
|
|
170
|
+
if (result?.text)
|
|
171
|
+
lines.push(
|
|
172
|
+
` ${theme.fg("muted", "↳")} ${theme.fg(result.isError ? "error" : "toolOutput", result.text)}`,
|
|
168
173
|
);
|
|
169
|
-
if (job.lastResult) lines.push(` ${theme.fg("muted", "↳")} ${theme.fg("toolOutput", job.lastResult)}`);
|
|
170
174
|
}
|
|
171
175
|
if (hidden) lines.push(` ${theme.fg("muted", `… ${hidden} more running`)}`);
|
|
172
176
|
ctx.ui.setWidget(WIDGET_KEY, lines);
|
|
@@ -769,10 +773,8 @@ export default function (pi: ExtensionAPI) {
|
|
|
769
773
|
if (!jobs.length) return { content: [{ type: "text", text: "No delegates yet." }], details: undefined };
|
|
770
774
|
const running = jobs.filter((job) => job.status === "running").length;
|
|
771
775
|
const lastActivity = (job: InspectJob) => {
|
|
772
|
-
const {
|
|
773
|
-
return job.status === "running" &&
|
|
774
|
-
? ` · ${lastTool}${lastDetail ? ` ${lastDetail}` : ""}`
|
|
775
|
-
: "";
|
|
776
|
+
const { tool } = lastToolCall(job);
|
|
777
|
+
return job.status === "running" && tool ? ` · ${tool.text}${tool.detail ? ` ${tool.detail}` : ""}` : "";
|
|
776
778
|
};
|
|
777
779
|
const lines = jobs.map((job) => {
|
|
778
780
|
const tag = isolationWords(job);
|
package/inspector.ts
CHANGED
|
@@ -72,12 +72,18 @@ export function registerInspector(pi: ExtensionAPI, store: JobStore) {
|
|
|
72
72
|
if (entry.kind === "tool")
|
|
73
73
|
return [
|
|
74
74
|
truncateToWidth(
|
|
75
|
-
theme.fg("toolTitle", entry.text) +
|
|
75
|
+
theme.fg("toolTitle", theme.bold(entry.text)) +
|
|
76
76
|
(entry.detail ? ` ${theme.fg("accent", entry.detail)}` : ""),
|
|
77
77
|
width,
|
|
78
78
|
),
|
|
79
79
|
];
|
|
80
|
-
if (entry.kind === "result")
|
|
80
|
+
if (entry.kind === "result")
|
|
81
|
+
return [
|
|
82
|
+
truncateToWidth(
|
|
83
|
+
` ${theme.fg("muted", "↳")} ${theme.fg(entry.isError ? "error" : "toolOutput", entry.text || "(no text output)")}`,
|
|
84
|
+
width,
|
|
85
|
+
),
|
|
86
|
+
];
|
|
81
87
|
// Only failure detail still says anything; the header icon carries the status.
|
|
82
88
|
if (!entry.text) return [];
|
|
83
89
|
return [truncateToWidth(theme.fg(STATUS_COLORS.failed, entry.text), width)];
|
package/package.json
CHANGED
package/store.ts
CHANGED
|
@@ -21,10 +21,14 @@ export type InspectJob = {
|
|
|
21
21
|
cloneClosed?: boolean;
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
+
/** The job's latest tool call and its result, once the result arrives. */
|
|
25
|
+
export function lastToolCall(job: InspectJob): { tool?: ChildActivity; result?: ChildActivity } {
|
|
26
|
+
const at = job.activity.findLastIndex((entry) => entry.kind === "tool");
|
|
27
|
+
if (at < 0) return {};
|
|
28
|
+
return { tool: job.activity[at], result: job.activity.slice(at + 1).find((entry) => entry.kind === "result") };
|
|
29
|
+
}
|
|
30
|
+
|
|
24
31
|
export type DelegateJob = InspectJob & {
|
|
25
|
-
lastTool?: string;
|
|
26
|
-
lastDetail?: string;
|
|
27
|
-
lastResult?: string;
|
|
28
32
|
controller: AbortController;
|
|
29
33
|
steer?: (message: string) => Promise<void>;
|
|
30
34
|
swapModel?: (provider: string, modelId: string, level?: string, onModelSet?: () => void) => Promise<void>;
|
|
@@ -61,10 +65,9 @@ export function createJobStore(append: (customType: string, data: InspectJob) =>
|
|
|
61
65
|
if (stale >= 0) history.splice(stale, 1);
|
|
62
66
|
};
|
|
63
67
|
const find = (id: string) => running.get(id) ?? history.find((item) => item.id === id);
|
|
64
|
-
/** The serializable form of a job: runtime handles
|
|
68
|
+
/** The serializable form of a job: runtime handles stay out. */
|
|
65
69
|
const snapshot = (job: InspectJob): InspectJob => {
|
|
66
|
-
const { controller, steer, swapModel,
|
|
67
|
-
Partial<DelegateJob>;
|
|
70
|
+
const { controller, steer, swapModel, ...plain } = job as InspectJob & Partial<DelegateJob>;
|
|
68
71
|
// Copy activity: the live job keeps appending to its own array after the launch snapshot.
|
|
69
72
|
return { ...plain, activity: [...plain.activity] };
|
|
70
73
|
};
|
|
@@ -104,9 +107,6 @@ export function createJobStore(append: (customType: string, data: InspectJob) =>
|
|
|
104
107
|
record: (job: DelegateJob, update: ChildUpdate) => {
|
|
105
108
|
if (job.status !== "running") return;
|
|
106
109
|
if (update.toolCalls !== undefined) job.toolCalls = update.toolCalls;
|
|
107
|
-
if (update.lastTool !== undefined) job.lastTool = update.lastTool;
|
|
108
|
-
if (update.lastDetail !== undefined) job.lastDetail = update.lastDetail;
|
|
109
|
-
if (update.lastResult !== undefined) job.lastResult = update.lastResult;
|
|
110
110
|
if (update.contextTokens !== undefined) job.contextTokens = update.contextTokens;
|
|
111
111
|
if (update.activity) addActivity(job, update.activity);
|
|
112
112
|
},
|