@deathbeam/pi-delegate 0.0.15 → 0.0.17
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/README.md +1 -1
- package/child.ts +4 -4
- package/format.ts +3 -3
- package/index.ts +41 -52
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# [@deathbeam/pi-delegate](https://www.npmjs.com/package/@deathbeam/pi-delegate)
|
|
2
2
|
|
|
3
3
|
Run focused subagents with `delegate`, `delegate_list`, `delegate_steer`, and `delegate_cancel`.
|
|
4
|
-
Use `/delegate` command to
|
|
4
|
+
Use `/delegate` command to inspect jobs in a full-screen TUI.
|
|
5
5
|
|
|
6
6
|
## Installation
|
|
7
7
|
|
package/child.ts
CHANGED
|
@@ -73,7 +73,7 @@ export function runChild(
|
|
|
73
73
|
if (!child.stdin.destroyed) child.stdin.end();
|
|
74
74
|
signal?.removeEventListener("abort", abort);
|
|
75
75
|
const result = aborted
|
|
76
|
-
? new Error("
|
|
76
|
+
? new Error("Delegate was aborted")
|
|
77
77
|
: (error ??
|
|
78
78
|
childFailure ??
|
|
79
79
|
(code !== 0
|
|
@@ -86,7 +86,7 @@ export function runChild(
|
|
|
86
86
|
rejectPending(new Error(childError));
|
|
87
87
|
reject(new Error(childError));
|
|
88
88
|
} else {
|
|
89
|
-
rejectPending(new Error("
|
|
89
|
+
rejectPending(new Error("Delegate finished before acknowledging command"));
|
|
90
90
|
resolveChild(limitOutput(liveText.trim() || "(no output)"));
|
|
91
91
|
}
|
|
92
92
|
};
|
|
@@ -194,9 +194,9 @@ export function runChild(
|
|
|
194
194
|
const write = writeQueue.then(
|
|
195
195
|
() =>
|
|
196
196
|
new Promise<void>((resolveWrite, rejectWrite) => {
|
|
197
|
-
if (settled) return rejectWrite(childFailure ?? new Error("
|
|
197
|
+
if (settled) return rejectWrite(childFailure ?? new Error("Delegate has finished"));
|
|
198
198
|
if (child.stdin.destroyed || !child.stdin.writable) {
|
|
199
|
-
return rejectWrite(new Error("
|
|
199
|
+
return rejectWrite(new Error("Delegate stdin is not writable"));
|
|
200
200
|
}
|
|
201
201
|
child.stdin.write(line, (error) => (error ? rejectWrite(error) : resolveWrite()));
|
|
202
202
|
}),
|
package/format.ts
CHANGED
|
@@ -97,7 +97,7 @@ export function toolCallDetail(toolName: string, args: unknown): string {
|
|
|
97
97
|
case "read":
|
|
98
98
|
case "write":
|
|
99
99
|
case "edit":
|
|
100
|
-
return value("
|
|
100
|
+
return value("path");
|
|
101
101
|
case "grep":
|
|
102
102
|
return `/${value("pattern")}/ in ${path}`;
|
|
103
103
|
case "find":
|
|
@@ -150,9 +150,9 @@ export function resultPreview(result: unknown, maxChars = 120): string | undefin
|
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
export function reportText(report: DelegateReport): string {
|
|
153
|
-
if (report.error) return `
|
|
153
|
+
if (report.error) return `Delegate "${report.agent}" (job ${report.id}) failed: ${report.error}`;
|
|
154
154
|
const output = (report.output ?? "").trim();
|
|
155
|
-
return `
|
|
155
|
+
return `Delegate "${report.agent}" (job ${report.id}) finished.${output ? `\n\n${output}` : ""}`;
|
|
156
156
|
}
|
|
157
157
|
|
|
158
158
|
export function jobLine(info: { description?: string } & UsageInfo, elapsedMs: number): string {
|
package/index.ts
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
getMarkdownTheme,
|
|
12
12
|
keyHint,
|
|
13
13
|
parseFrontmatter,
|
|
14
|
+
rawKeyHint,
|
|
14
15
|
} from "@earendil-works/pi-coding-agent";
|
|
15
16
|
import {
|
|
16
17
|
type Component,
|
|
@@ -100,9 +101,9 @@ const MODEL_TIERS = new Set(["cheap", "balanced", "strong"]);
|
|
|
100
101
|
const WIDGET_KEY = "delegate";
|
|
101
102
|
const RESULT_MESSAGE = "delegate-result";
|
|
102
103
|
const REMINDER_MESSAGE = "delegate-reminder";
|
|
104
|
+
const JOB_ENTRY = "delegate-job";
|
|
103
105
|
const EXPLORATION_TOOLS = new Set(["read", "grep", "find", "ls", "bash", "powershell", "web_search", "web_fetch"]);
|
|
104
106
|
const FIRST_REMINDER_AT = 5;
|
|
105
|
-
const TASK_PREVIEW_LINES = 5;
|
|
106
107
|
|
|
107
108
|
function expandPath(value: string, cwd: string): string {
|
|
108
109
|
return resolve(cwd, value.replace(/^~(?=\/|$)/, homedir()));
|
|
@@ -207,6 +208,11 @@ function resultFallback(body: string, theme: Theme, isError: boolean): Text {
|
|
|
207
208
|
return new Text(`\n${theme.fg(isError ? "error" : "toolOutput", body || "(no output)")}`, 0, 0);
|
|
208
209
|
}
|
|
209
210
|
|
|
211
|
+
/** Shared collapsed-output note so all three preview sites phrase it identically. */
|
|
212
|
+
function moreLines(theme: Theme, hidden: number): string {
|
|
213
|
+
return theme.fg("muted", `… ${hidden} more lines, `) + keyHint("app.tools.expand", "to expand");
|
|
214
|
+
}
|
|
215
|
+
|
|
210
216
|
/** Shared tool layout: an optional identity header, then a width-aware payload preview. */
|
|
211
217
|
function toolLayout(toolName: string, identity: string, payload: string, theme: Theme, expanded: boolean): Component {
|
|
212
218
|
const container = new Container();
|
|
@@ -231,11 +237,7 @@ function toolLayout(toolName: string, identity: string, payload: string, theme:
|
|
|
231
237
|
if (expanded || lines.length <= COLLAPSED_OUTPUT_LINES) return lines;
|
|
232
238
|
return [
|
|
233
239
|
...lines.slice(0, COLLAPSED_OUTPUT_LINES),
|
|
234
|
-
truncateToWidth(
|
|
235
|
-
theme.fg("muted", `… ${lines.length - COLLAPSED_OUTPUT_LINES} more lines, `) +
|
|
236
|
-
keyHint("app.tools.expand", "to expand"),
|
|
237
|
-
width,
|
|
238
|
-
),
|
|
240
|
+
truncateToWidth(moreLines(theme, lines.length - COLLAPSED_OUTPUT_LINES), width),
|
|
239
241
|
];
|
|
240
242
|
},
|
|
241
243
|
invalidate: () => body.invalidate(),
|
|
@@ -270,7 +272,9 @@ export default function (pi: ExtensionAPI) {
|
|
|
270
272
|
job.status = status;
|
|
271
273
|
if (detail) addActivity(job, { kind: "status", text: detail });
|
|
272
274
|
const { controller, steer, lastTool, lastDetail, lastResult, ...snapshot } = job;
|
|
273
|
-
|
|
275
|
+
const entry: InspectJob = { ...snapshot, endedAt: Date.now() };
|
|
276
|
+
recent.unshift(entry);
|
|
277
|
+
pi.appendEntry(JOB_ENTRY, entry);
|
|
274
278
|
};
|
|
275
279
|
|
|
276
280
|
const jobSnapshot = (job: DelegateJob) => ({
|
|
@@ -356,6 +360,17 @@ export default function (pi: ExtensionAPI) {
|
|
|
356
360
|
viewing = undefined;
|
|
357
361
|
});
|
|
358
362
|
|
|
363
|
+
// Rebuilt from the active branch, like pi's todo example; abandoned branches are alternative histories.
|
|
364
|
+
const restoreJobs = (ctx: ExtensionContext) => {
|
|
365
|
+
recent.length = 0;
|
|
366
|
+
for (const entry of ctx.sessionManager.getBranch()) {
|
|
367
|
+
if (entry.type !== "custom" || entry.customType !== JOB_ENTRY || !entry.data) continue;
|
|
368
|
+
recent.unshift(entry.data as InspectJob);
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
pi.on("session_start", (_event, ctx) => restoreJobs(ctx));
|
|
372
|
+
pi.on("session_tree", (_event, ctx) => restoreJobs(ctx));
|
|
373
|
+
|
|
359
374
|
pi.on("before_agent_start", () => {
|
|
360
375
|
directCalls = 0;
|
|
361
376
|
nextReminder = FIRST_REMINDER_AT;
|
|
@@ -399,14 +414,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
399
414
|
else if (report.output) {
|
|
400
415
|
const { shown, hidden } = outputPreview(report.output, expanded ? Infinity : COLLAPSED_OUTPUT_LINES);
|
|
401
416
|
container.addChild(new Markdown(shown.join("\n"), 0, 0, getMarkdownTheme()));
|
|
402
|
-
if (hidden > 0)
|
|
403
|
-
container.addChild(
|
|
404
|
-
new Text(
|
|
405
|
-
theme.fg("muted", `… ${hidden} more lines, `) + keyHint("app.tools.expand", "to expand"),
|
|
406
|
-
0,
|
|
407
|
-
0,
|
|
408
|
-
),
|
|
409
|
-
);
|
|
417
|
+
if (hidden > 0) container.addChild(new Text(moreLines(theme, hidden), 0, 0));
|
|
410
418
|
}
|
|
411
419
|
return container;
|
|
412
420
|
});
|
|
@@ -431,24 +439,15 @@ export default function (pi: ExtensionAPI) {
|
|
|
431
439
|
let historyWidth = 1;
|
|
432
440
|
let markdown = new WeakMap<ChildActivity, Markdown>();
|
|
433
441
|
const jobs = () => [...running.values(), ...recent];
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
const taskLines = (job: InspectJob, width: number) => {
|
|
437
|
-
const lines = wrapTextWithAnsi(job.task.trim(), Math.max(1, width)).map((line) =>
|
|
438
|
-
theme.fg("text", line),
|
|
439
|
-
);
|
|
440
|
-
if (lines.length <= TASK_PREVIEW_LINES) return lines;
|
|
441
|
-
return [
|
|
442
|
-
...lines.slice(0, TASK_PREVIEW_LINES),
|
|
443
|
-
theme.fg("muted", `… ${lines.length - TASK_PREVIEW_LINES} more lines`),
|
|
444
|
-
];
|
|
445
|
-
};
|
|
442
|
+
// Fixed rows: title, top rule, bottom rule, footer.
|
|
443
|
+
const bodyHeight = () => Math.max(0, tui.terminal.rows - 4);
|
|
446
444
|
const toolsLines = (job: InspectJob, width: number) =>
|
|
447
445
|
wrapTextWithAnsi(formatTools(job.tools), Math.max(1, width)).map((line) =>
|
|
448
446
|
theme.fg("dim", line),
|
|
449
447
|
);
|
|
448
|
+
// Fixed rows: header, model, description, rule, counter.
|
|
450
449
|
const historyHeight = (job: InspectJob, width: number) =>
|
|
451
|
-
Math.max(0, bodyHeight() -
|
|
450
|
+
Math.max(0, bodyHeight() - 5 - toolsLines(job, width).length);
|
|
452
451
|
// ScrollView needs fullscreen layout; window the history in regular TUI too.
|
|
453
452
|
const renderJobs = (width: number, items: InspectJob[], selectedIndex: number): string[] => {
|
|
454
453
|
const row = (text: string) =>
|
|
@@ -467,7 +466,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
467
466
|
row(theme.fg("muted", ` ${item.description}`)),
|
|
468
467
|
row(
|
|
469
468
|
theme.fg(
|
|
470
|
-
"
|
|
469
|
+
"muted",
|
|
471
470
|
` ${usageStats(item, (item.endedAt ?? Date.now()) - item.startedAt)}`,
|
|
472
471
|
),
|
|
473
472
|
),
|
|
@@ -475,7 +474,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
475
474
|
return [
|
|
476
475
|
...lines,
|
|
477
476
|
...Array(Math.max(0, bodyHeight() - 1 - lines.length)).fill(row("")),
|
|
478
|
-
row(theme.fg("dim",
|
|
477
|
+
row(theme.fg("dim", `${selectedIndex + 1}/${items.length}`)),
|
|
479
478
|
].slice(0, bodyHeight());
|
|
480
479
|
};
|
|
481
480
|
const renderEntry = (entry: ChildActivity, width: number): string[] => {
|
|
@@ -502,7 +501,6 @@ export default function (pi: ExtensionAPI) {
|
|
|
502
501
|
};
|
|
503
502
|
const renderHistory = (width: number, job: InspectJob): string[] => {
|
|
504
503
|
historyWidth = width;
|
|
505
|
-
const task = taskLines(job, width);
|
|
506
504
|
const tools = toolsLines(job, width);
|
|
507
505
|
const height = historyHeight(job, width);
|
|
508
506
|
const history = job.activity.flatMap((entry) => renderEntry(entry, width));
|
|
@@ -518,9 +516,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
518
516
|
truncateToWidth(`${statusText(theme, job.status)} ${jobIdentity(theme, job)}`, width),
|
|
519
517
|
truncateToWidth(theme.fg("dim", job.model), width),
|
|
520
518
|
...tools,
|
|
521
|
-
theme.fg("borderMuted", "─".repeat(Math.max(0, width))),
|
|
522
519
|
truncateToWidth(theme.fg("text", theme.bold(job.description)), width),
|
|
523
|
-
...task,
|
|
524
520
|
theme.fg("borderMuted", "─".repeat(Math.max(0, width))),
|
|
525
521
|
...shown,
|
|
526
522
|
...Array(Math.max(0, height - shown.length)).fill(""),
|
|
@@ -551,7 +547,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
551
547
|
const footer = truncateToWidth(
|
|
552
548
|
theme.fg(
|
|
553
549
|
"dim",
|
|
554
|
-
`${keyHint("tui.select.up", "previous")} · ${keyHint("tui.select.down", "next")} ·
|
|
550
|
+
`${keyHint("tui.select.up", "previous")} · ${keyHint("tui.select.down", "next")} · ${rawKeyHint("←/→", "switch pane")} · ${keyHint("tui.select.cancel", "close")}`,
|
|
555
551
|
),
|
|
556
552
|
width,
|
|
557
553
|
);
|
|
@@ -559,7 +555,8 @@ export default function (pi: ExtensionAPI) {
|
|
|
559
555
|
return [
|
|
560
556
|
title,
|
|
561
557
|
theme.fg("muted", "No delegates in this session."),
|
|
562
|
-
|
|
558
|
+
// Fixed rows: title, top rule, bottom rule, footer.
|
|
559
|
+
...Array(Math.max(0, tui.terminal.rows - 4)).fill(""),
|
|
563
560
|
footer,
|
|
564
561
|
].slice(0, tui.terminal.rows);
|
|
565
562
|
const sidebarWidth = Math.min(
|
|
@@ -589,6 +586,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
589
586
|
title,
|
|
590
587
|
theme.fg("borderMuted", "─".repeat(Math.max(0, width))),
|
|
591
588
|
...body,
|
|
589
|
+
theme.fg("borderMuted", "─".repeat(Math.max(0, width))),
|
|
592
590
|
footer,
|
|
593
591
|
].slice(0, tui.terminal.rows);
|
|
594
592
|
},
|
|
@@ -755,7 +753,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
755
753
|
content: [
|
|
756
754
|
{
|
|
757
755
|
type: "text",
|
|
758
|
-
text: `Started
|
|
756
|
+
text: `Started delegate "${job.agent}" in the background (job ${job.id}). Steer it with delegate_steer or stop it with delegate_cancel. Do not call tools solely to wait, even no-op bash commands; when its report is your next dependency, end your turn and it will arrive automatically unless cancelled.`,
|
|
759
757
|
},
|
|
760
758
|
],
|
|
761
759
|
details,
|
|
@@ -785,19 +783,17 @@ export default function (pi: ExtensionAPI) {
|
|
|
785
783
|
const body = resultText(result);
|
|
786
784
|
if (context.isError || !details?.agent) return resultFallback(body, theme, context.isError);
|
|
787
785
|
const status = details.background ? "started in background" : "completed";
|
|
786
|
+
// The done icon means actual completion; a background launch reports its status without it.
|
|
787
|
+
const header = details.background
|
|
788
|
+
? `${jobIdentity(theme, details)} ${theme.fg("muted", status)}`
|
|
789
|
+
: `${statusText(theme, "done")} ${jobIdentity(theme, details)} ${theme.fg("muted", status)}`;
|
|
788
790
|
const container = new Container();
|
|
789
|
-
container.addChild(
|
|
790
|
-
new Text(
|
|
791
|
-
`\n${statusText(theme, "done")} ${jobIdentity(theme, details)} ${theme.fg("dim", status)}`,
|
|
792
|
-
0,
|
|
793
|
-
0,
|
|
794
|
-
),
|
|
795
|
-
);
|
|
791
|
+
container.addChild(new Text(`\n${header}`, 0, 0));
|
|
796
792
|
// The call body already carries the task; only the launch metadata is new here.
|
|
797
793
|
if (expanded)
|
|
798
794
|
container.addChild(
|
|
799
795
|
new Text(
|
|
800
|
-
theme.fg("
|
|
796
|
+
theme.fg("muted", launchDetails({ model: details.model, tools: details.tools }).join("\n")),
|
|
801
797
|
0,
|
|
802
798
|
0,
|
|
803
799
|
),
|
|
@@ -806,14 +802,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
806
802
|
if (!details.background && body) {
|
|
807
803
|
const { shown, hidden } = outputPreview(body, expanded ? Infinity : COLLAPSED_OUTPUT_LINES);
|
|
808
804
|
container.addChild(new Markdown(shown.join("\n"), 0, 0, getMarkdownTheme()));
|
|
809
|
-
if (hidden > 0)
|
|
810
|
-
container.addChild(
|
|
811
|
-
new Text(
|
|
812
|
-
theme.fg("muted", `… ${hidden} more lines, `) + keyHint("app.tools.expand", "to expand"),
|
|
813
|
-
0,
|
|
814
|
-
0,
|
|
815
|
-
),
|
|
816
|
-
);
|
|
805
|
+
if (hidden > 0) container.addChild(new Text(moreLines(theme, hidden), 0, 0));
|
|
817
806
|
}
|
|
818
807
|
return container;
|
|
819
808
|
},
|