@deathbeam/pi-delegate 0.0.38 → 0.0.39
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 +9 -16
- package/format.ts +14 -14
- package/index.ts +12 -17
- package/inspector.ts +0 -1
- package/package.json +1 -1
- package/store.ts +7 -7
package/child.ts
CHANGED
|
@@ -5,12 +5,6 @@ import { limitOutput, resultPreview, toolCallDetail } from "./format.ts";
|
|
|
5
5
|
|
|
6
6
|
type Child = ChildProcessWithoutNullStreams;
|
|
7
7
|
|
|
8
|
-
function usageTokens(usage: any): number | undefined {
|
|
9
|
-
if (!usage) return undefined;
|
|
10
|
-
const tokens = usage.totalTokens || usage.input + usage.output + usage.cacheRead + usage.cacheWrite;
|
|
11
|
-
return tokens > 0 ? tokens : undefined;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
8
|
export type ChildActivity = {
|
|
15
9
|
kind: "tool" | "result" | "assistant" | "user" | "status";
|
|
16
10
|
text: string;
|
|
@@ -30,6 +24,12 @@ type ChildRun = {
|
|
|
30
24
|
swapModel: (provider: string, modelId: string, level?: string, onModelSet?: () => void) => Promise<void>;
|
|
31
25
|
};
|
|
32
26
|
|
|
27
|
+
function usageTokens(usage: any): number | undefined {
|
|
28
|
+
if (!usage) return undefined;
|
|
29
|
+
const tokens = usage.totalTokens || usage.input + usage.output + usage.cacheRead + usage.cacheWrite;
|
|
30
|
+
return tokens > 0 ? tokens : undefined;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
33
|
/** Run one RPC child, keeping its writer serialized so backpressure and EPIPE reach the caller. */
|
|
34
34
|
export function runChild(
|
|
35
35
|
child: Child,
|
|
@@ -157,14 +157,7 @@ export function runChild(
|
|
|
157
157
|
case "message_end": {
|
|
158
158
|
const role = event.message?.role;
|
|
159
159
|
if (role !== "assistant" && role !== "user") return;
|
|
160
|
-
const
|
|
161
|
-
const text =
|
|
162
|
-
typeof content === "string"
|
|
163
|
-
? content
|
|
164
|
-
: (content
|
|
165
|
-
?.filter((part: any) => part.type === "text")
|
|
166
|
-
.map((part: any) => part.text ?? "")
|
|
167
|
-
.join("") ?? "");
|
|
160
|
+
const text = transcriptText(event.message.content).join("");
|
|
168
161
|
if (role === "assistant") {
|
|
169
162
|
childError = event.message.errorMessage;
|
|
170
163
|
if (text) liveText = text;
|
|
@@ -304,7 +297,7 @@ export function runChild(
|
|
|
304
297
|
};
|
|
305
298
|
}
|
|
306
299
|
|
|
307
|
-
/** Text
|
|
300
|
+
/** Text parts of a message's content, in order. */
|
|
308
301
|
function transcriptText(content: unknown): string[] {
|
|
309
302
|
if (typeof content === "string") return [content];
|
|
310
303
|
if (!Array.isArray(content)) return [];
|
|
@@ -331,7 +324,7 @@ export function priorActivity(sessionDir: string, id: string): ChildActivity[] {
|
|
|
331
324
|
return [];
|
|
332
325
|
}
|
|
333
326
|
if (!sessionFile) return [];
|
|
334
|
-
let lines: string[]
|
|
327
|
+
let lines: string[];
|
|
335
328
|
try {
|
|
336
329
|
lines = readFileSync(join(sessionDir, sessionFile), "utf8").split("\n");
|
|
337
330
|
} catch {
|
package/format.ts
CHANGED
|
@@ -32,6 +32,20 @@ export type DelegateReport = {
|
|
|
32
32
|
cloneClosed?: boolean;
|
|
33
33
|
};
|
|
34
34
|
|
|
35
|
+
/** The isolation state to show for a job: pending means its clone still holds unapplied work. */
|
|
36
|
+
export type IsolationMark = "isolated" | "pending";
|
|
37
|
+
|
|
38
|
+
type IsolationStateFields = {
|
|
39
|
+
isolation?: unknown;
|
|
40
|
+
cloneClosed?: boolean;
|
|
41
|
+
status?: string;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export type DelegateDetails = Pick<
|
|
45
|
+
DelegateJob,
|
|
46
|
+
"id" | "agent" | "description" | "task" | "model" | "tools" | "status" | "isolation" | "cloneClosed"
|
|
47
|
+
> & { background: boolean };
|
|
48
|
+
|
|
35
49
|
const SPINNER_FRAMES = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
|
|
36
50
|
export const SPINNER_INTERVAL_MS = 100;
|
|
37
51
|
const STATUS_ICONS = {
|
|
@@ -64,15 +78,6 @@ export function statusText(theme: Theme, status: JobStatus, now = Date.now()): s
|
|
|
64
78
|
return theme.fg(STATUS_COLORS[status], statusIcon(status, now));
|
|
65
79
|
}
|
|
66
80
|
|
|
67
|
-
/** The isolation state to show for a job: pending means its clone still holds unapplied work. */
|
|
68
|
-
export type IsolationMark = "isolated" | "pending";
|
|
69
|
-
|
|
70
|
-
type IsolationStateFields = {
|
|
71
|
-
isolation?: unknown;
|
|
72
|
-
cloneClosed?: boolean;
|
|
73
|
-
status?: string;
|
|
74
|
-
};
|
|
75
|
-
|
|
76
81
|
/** Derives the mark from a job: an isolation with no clone left, or a still-running one, is not pending. */
|
|
77
82
|
export function isolationMarkOf(job: IsolationStateFields): IsolationMark | undefined {
|
|
78
83
|
if (!job.isolation) return undefined;
|
|
@@ -291,11 +296,6 @@ export function widgetJobs<T>(jobs: T[]): { shown: T[]; hidden: number } {
|
|
|
291
296
|
return { shown, hidden: jobs.length - shown.length };
|
|
292
297
|
}
|
|
293
298
|
|
|
294
|
-
export type DelegateDetails = Pick<
|
|
295
|
-
DelegateJob,
|
|
296
|
-
"id" | "agent" | "description" | "task" | "model" | "tools" | "status" | "isolation" | "cloneClosed"
|
|
297
|
-
> & { background: boolean };
|
|
298
|
-
|
|
299
299
|
export function resultFallback(body: string, theme: Theme, isError: boolean): Text {
|
|
300
300
|
const mark = statusText(theme, isError ? "failed" : "done");
|
|
301
301
|
return new Text(`\n${mark} ${theme.fg(isError ? "error" : "toolOutput", body || "(no output)")}`, 0, 0);
|
package/index.ts
CHANGED
|
@@ -96,6 +96,11 @@ function withIsolation(output: string, isolation: IsolationState | undefined): s
|
|
|
96
96
|
return isolation ? [output, isolationSummary(isolation)].filter(Boolean).join("\n\n") : output;
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
+
/** Status icon, identity, and the muted detail line: the row the widget and delegate_list both show. */
|
|
100
|
+
function jobRow(theme: Theme, job: InspectJob, now: number): string {
|
|
101
|
+
return `${statusText(theme, job.status, now)} ${jobIdentity(theme, job)} ${theme.fg("muted", jobLine(job, elapsedMs(job, now)))}`;
|
|
102
|
+
}
|
|
103
|
+
|
|
99
104
|
export default function (pi: ExtensionAPI) {
|
|
100
105
|
const store = createJobStore(pi.appendEntry);
|
|
101
106
|
let ticker: ReturnType<typeof setInterval> | undefined;
|
|
@@ -112,7 +117,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
112
117
|
/** The clone is the unit: every job id that ran in it is only a handle, so state changes reach all of them. */
|
|
113
118
|
const jobsInClone = (clone: string) => store.all().filter((job) => job.isolation?.clone === clone);
|
|
114
119
|
|
|
115
|
-
/** A job that still has a clone;
|
|
120
|
+
/** A job that still has a clone; throws explaining why it has none. */
|
|
116
121
|
const clonedJob = (id: string) => {
|
|
117
122
|
const job = store.findOrThrow(id);
|
|
118
123
|
const isolation = job.isolation;
|
|
@@ -153,14 +158,10 @@ export default function (pi: ExtensionAPI) {
|
|
|
153
158
|
const theme = ctx.ui.theme;
|
|
154
159
|
const now = Date.now();
|
|
155
160
|
const { shown, hidden } = widgetJobs(jobs);
|
|
156
|
-
const
|
|
157
|
-
const
|
|
158
|
-
const counts = tally(jobs.length, all, now);
|
|
159
|
-
lines.push(`${statusText(theme, "running", now)} ${theme.fg("muted", counts)}`);
|
|
161
|
+
const counts = tally(jobs.length, store.all(), now);
|
|
162
|
+
const lines = [`${statusText(theme, "running", now)} ${theme.fg("muted", counts)}`];
|
|
160
163
|
for (const job of shown) {
|
|
161
|
-
lines.push(
|
|
162
|
-
`${statusText(theme, "running", now)} ${jobIdentity(theme, job)} ${theme.fg("muted", jobLine(job, elapsedMs(job, now)))}`,
|
|
163
|
-
);
|
|
164
|
+
lines.push(jobRow(theme, job, now));
|
|
164
165
|
const { tool, result } = lastToolCall(job);
|
|
165
166
|
if (tool)
|
|
166
167
|
lines.push(
|
|
@@ -181,7 +182,6 @@ export default function (pi: ExtensionAPI) {
|
|
|
181
182
|
});
|
|
182
183
|
};
|
|
183
184
|
|
|
184
|
-
// The ticker animates spinners exactly while live jobs exist.
|
|
185
185
|
const syncTicker = (ctx: ExtensionContext) => {
|
|
186
186
|
if (store.live().length > 0) ticker ??= setInterval(() => refreshWidget(ctx), SPINNER_INTERVAL_MS);
|
|
187
187
|
else if (ticker) {
|
|
@@ -427,8 +427,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
427
427
|
|
|
428
428
|
registerInspector(pi, store);
|
|
429
429
|
|
|
430
|
-
const
|
|
431
|
-
const agentList = agentsFor(cwd).map((agent) => {
|
|
430
|
+
const agentList = agentsFor(process.cwd()).map((agent) => {
|
|
432
431
|
const qualifiers = [agent.model, agent.isolated ? "isolated" : undefined].filter(Boolean).join(", ");
|
|
433
432
|
return `- ${agent.name}${qualifiers ? ` (${qualifiers})` : ""}: ${agent.description}`;
|
|
434
433
|
});
|
|
@@ -798,13 +797,9 @@ export default function (pi: ExtensionAPI) {
|
|
|
798
797
|
const jobs = (result.details as { jobs?: InspectJob[] } | undefined)?.jobs;
|
|
799
798
|
if (!jobs?.length || context.isError) return resultFallback(resultText(result), theme, context.isError);
|
|
800
799
|
const now = Date.now();
|
|
800
|
+
const rows = jobs.map((job) => jobRow(theme, job, now)).join("\n");
|
|
801
801
|
return new Text(
|
|
802
|
-
`\n${statusText(theme, "done")} ${theme.fg("muted", `${jobs.length} delegates`)}\n${
|
|
803
|
-
.map(
|
|
804
|
-
(job) =>
|
|
805
|
-
`${statusText(theme, job.status, now)} ${jobIdentity(theme, job)} ${theme.fg("muted", jobLine(job, elapsedMs(job, now)))}`,
|
|
806
|
-
)
|
|
807
|
-
.join("\n")}`,
|
|
802
|
+
`\n${statusText(theme, "done")} ${theme.fg("muted", `${jobs.length} delegates`)}\n${rows}`,
|
|
808
803
|
0,
|
|
809
804
|
0,
|
|
810
805
|
);
|
package/inspector.ts
CHANGED
|
@@ -154,7 +154,6 @@ export function registerInspector(pi: ExtensionAPI, store: JobStore) {
|
|
|
154
154
|
return [
|
|
155
155
|
title,
|
|
156
156
|
theme.fg("muted", "No delegates in this session."),
|
|
157
|
-
// Fixed rows: title, top rule, bottom rule, footer.
|
|
158
157
|
...Array(Math.max(0, tui.terminal.rows - 4)).fill(""),
|
|
159
158
|
footer,
|
|
160
159
|
].slice(0, tui.terminal.rows);
|
package/package.json
CHANGED
package/store.ts
CHANGED
|
@@ -21,13 +21,6 @@ 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
|
-
|
|
31
24
|
export type DelegateJob = InspectJob & {
|
|
32
25
|
controller: AbortController;
|
|
33
26
|
steer?: (message: string) => Promise<void>;
|
|
@@ -164,3 +157,10 @@ export function createJobStore(append: (customType: string, data: InspectJob) =>
|
|
|
164
157
|
}
|
|
165
158
|
|
|
166
159
|
export type JobStore = ReturnType<typeof createJobStore>;
|
|
160
|
+
|
|
161
|
+
/** The job's latest tool call and its result, once the result arrives. */
|
|
162
|
+
export function lastToolCall(job: InspectJob): { tool?: ChildActivity; result?: ChildActivity } {
|
|
163
|
+
const at = job.activity.findLastIndex((entry) => entry.kind === "tool");
|
|
164
|
+
if (at < 0) return {};
|
|
165
|
+
return { tool: job.activity[at], result: job.activity.slice(at + 1).find((entry) => entry.kind === "result") };
|
|
166
|
+
}
|