@deathbeam/pi-delegate 0.0.16 → 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 +26 -51
- 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,
|
|
@@ -103,7 +104,6 @@ const REMINDER_MESSAGE = "delegate-reminder";
|
|
|
103
104
|
const JOB_ENTRY = "delegate-job";
|
|
104
105
|
const EXPLORATION_TOOLS = new Set(["read", "grep", "find", "ls", "bash", "powershell", "web_search", "web_fetch"]);
|
|
105
106
|
const FIRST_REMINDER_AT = 5;
|
|
106
|
-
const TASK_PREVIEW_LINES = 5;
|
|
107
107
|
|
|
108
108
|
function expandPath(value: string, cwd: string): string {
|
|
109
109
|
return resolve(cwd, value.replace(/^~(?=\/|$)/, homedir()));
|
|
@@ -208,6 +208,11 @@ function resultFallback(body: string, theme: Theme, isError: boolean): Text {
|
|
|
208
208
|
return new Text(`\n${theme.fg(isError ? "error" : "toolOutput", body || "(no output)")}`, 0, 0);
|
|
209
209
|
}
|
|
210
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
|
+
|
|
211
216
|
/** Shared tool layout: an optional identity header, then a width-aware payload preview. */
|
|
212
217
|
function toolLayout(toolName: string, identity: string, payload: string, theme: Theme, expanded: boolean): Component {
|
|
213
218
|
const container = new Container();
|
|
@@ -232,11 +237,7 @@ function toolLayout(toolName: string, identity: string, payload: string, theme:
|
|
|
232
237
|
if (expanded || lines.length <= COLLAPSED_OUTPUT_LINES) return lines;
|
|
233
238
|
return [
|
|
234
239
|
...lines.slice(0, COLLAPSED_OUTPUT_LINES),
|
|
235
|
-
truncateToWidth(
|
|
236
|
-
theme.fg("muted", `… ${lines.length - COLLAPSED_OUTPUT_LINES} more lines, `) +
|
|
237
|
-
keyHint("app.tools.expand", "to expand"),
|
|
238
|
-
width,
|
|
239
|
-
),
|
|
240
|
+
truncateToWidth(moreLines(theme, lines.length - COLLAPSED_OUTPUT_LINES), width),
|
|
240
241
|
];
|
|
241
242
|
},
|
|
242
243
|
invalidate: () => body.invalidate(),
|
|
@@ -413,14 +414,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
413
414
|
else if (report.output) {
|
|
414
415
|
const { shown, hidden } = outputPreview(report.output, expanded ? Infinity : COLLAPSED_OUTPUT_LINES);
|
|
415
416
|
container.addChild(new Markdown(shown.join("\n"), 0, 0, getMarkdownTheme()));
|
|
416
|
-
if (hidden > 0)
|
|
417
|
-
container.addChild(
|
|
418
|
-
new Text(
|
|
419
|
-
theme.fg("muted", `… ${hidden} more lines, `) + keyHint("app.tools.expand", "to expand"),
|
|
420
|
-
0,
|
|
421
|
-
0,
|
|
422
|
-
),
|
|
423
|
-
);
|
|
417
|
+
if (hidden > 0) container.addChild(new Text(moreLines(theme, hidden), 0, 0));
|
|
424
418
|
}
|
|
425
419
|
return container;
|
|
426
420
|
});
|
|
@@ -445,24 +439,15 @@ export default function (pi: ExtensionAPI) {
|
|
|
445
439
|
let historyWidth = 1;
|
|
446
440
|
let markdown = new WeakMap<ChildActivity, Markdown>();
|
|
447
441
|
const jobs = () => [...running.values(), ...recent];
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
const taskLines = (job: InspectJob, width: number) => {
|
|
451
|
-
const lines = wrapTextWithAnsi(job.task.trim(), Math.max(1, width)).map((line) =>
|
|
452
|
-
theme.fg("text", line),
|
|
453
|
-
);
|
|
454
|
-
if (lines.length <= TASK_PREVIEW_LINES) return lines;
|
|
455
|
-
return [
|
|
456
|
-
...lines.slice(0, TASK_PREVIEW_LINES),
|
|
457
|
-
theme.fg("muted", `… ${lines.length - TASK_PREVIEW_LINES} more lines`),
|
|
458
|
-
];
|
|
459
|
-
};
|
|
442
|
+
// Fixed rows: title, top rule, bottom rule, footer.
|
|
443
|
+
const bodyHeight = () => Math.max(0, tui.terminal.rows - 4);
|
|
460
444
|
const toolsLines = (job: InspectJob, width: number) =>
|
|
461
445
|
wrapTextWithAnsi(formatTools(job.tools), Math.max(1, width)).map((line) =>
|
|
462
446
|
theme.fg("dim", line),
|
|
463
447
|
);
|
|
448
|
+
// Fixed rows: header, model, description, rule, counter.
|
|
464
449
|
const historyHeight = (job: InspectJob, width: number) =>
|
|
465
|
-
Math.max(0, bodyHeight() -
|
|
450
|
+
Math.max(0, bodyHeight() - 5 - toolsLines(job, width).length);
|
|
466
451
|
// ScrollView needs fullscreen layout; window the history in regular TUI too.
|
|
467
452
|
const renderJobs = (width: number, items: InspectJob[], selectedIndex: number): string[] => {
|
|
468
453
|
const row = (text: string) =>
|
|
@@ -481,7 +466,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
481
466
|
row(theme.fg("muted", ` ${item.description}`)),
|
|
482
467
|
row(
|
|
483
468
|
theme.fg(
|
|
484
|
-
"
|
|
469
|
+
"muted",
|
|
485
470
|
` ${usageStats(item, (item.endedAt ?? Date.now()) - item.startedAt)}`,
|
|
486
471
|
),
|
|
487
472
|
),
|
|
@@ -489,7 +474,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
489
474
|
return [
|
|
490
475
|
...lines,
|
|
491
476
|
...Array(Math.max(0, bodyHeight() - 1 - lines.length)).fill(row("")),
|
|
492
|
-
row(theme.fg("dim",
|
|
477
|
+
row(theme.fg("dim", `${selectedIndex + 1}/${items.length}`)),
|
|
493
478
|
].slice(0, bodyHeight());
|
|
494
479
|
};
|
|
495
480
|
const renderEntry = (entry: ChildActivity, width: number): string[] => {
|
|
@@ -516,7 +501,6 @@ export default function (pi: ExtensionAPI) {
|
|
|
516
501
|
};
|
|
517
502
|
const renderHistory = (width: number, job: InspectJob): string[] => {
|
|
518
503
|
historyWidth = width;
|
|
519
|
-
const task = taskLines(job, width);
|
|
520
504
|
const tools = toolsLines(job, width);
|
|
521
505
|
const height = historyHeight(job, width);
|
|
522
506
|
const history = job.activity.flatMap((entry) => renderEntry(entry, width));
|
|
@@ -532,9 +516,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
532
516
|
truncateToWidth(`${statusText(theme, job.status)} ${jobIdentity(theme, job)}`, width),
|
|
533
517
|
truncateToWidth(theme.fg("dim", job.model), width),
|
|
534
518
|
...tools,
|
|
535
|
-
theme.fg("borderMuted", "─".repeat(Math.max(0, width))),
|
|
536
519
|
truncateToWidth(theme.fg("text", theme.bold(job.description)), width),
|
|
537
|
-
...task,
|
|
538
520
|
theme.fg("borderMuted", "─".repeat(Math.max(0, width))),
|
|
539
521
|
...shown,
|
|
540
522
|
...Array(Math.max(0, height - shown.length)).fill(""),
|
|
@@ -565,7 +547,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
565
547
|
const footer = truncateToWidth(
|
|
566
548
|
theme.fg(
|
|
567
549
|
"dim",
|
|
568
|
-
`${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")}`,
|
|
569
551
|
),
|
|
570
552
|
width,
|
|
571
553
|
);
|
|
@@ -573,7 +555,8 @@ export default function (pi: ExtensionAPI) {
|
|
|
573
555
|
return [
|
|
574
556
|
title,
|
|
575
557
|
theme.fg("muted", "No delegates in this session."),
|
|
576
|
-
|
|
558
|
+
// Fixed rows: title, top rule, bottom rule, footer.
|
|
559
|
+
...Array(Math.max(0, tui.terminal.rows - 4)).fill(""),
|
|
577
560
|
footer,
|
|
578
561
|
].slice(0, tui.terminal.rows);
|
|
579
562
|
const sidebarWidth = Math.min(
|
|
@@ -603,6 +586,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
603
586
|
title,
|
|
604
587
|
theme.fg("borderMuted", "─".repeat(Math.max(0, width))),
|
|
605
588
|
...body,
|
|
589
|
+
theme.fg("borderMuted", "─".repeat(Math.max(0, width))),
|
|
606
590
|
footer,
|
|
607
591
|
].slice(0, tui.terminal.rows);
|
|
608
592
|
},
|
|
@@ -769,7 +753,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
769
753
|
content: [
|
|
770
754
|
{
|
|
771
755
|
type: "text",
|
|
772
|
-
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.`,
|
|
773
757
|
},
|
|
774
758
|
],
|
|
775
759
|
details,
|
|
@@ -799,19 +783,17 @@ export default function (pi: ExtensionAPI) {
|
|
|
799
783
|
const body = resultText(result);
|
|
800
784
|
if (context.isError || !details?.agent) return resultFallback(body, theme, context.isError);
|
|
801
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)}`;
|
|
802
790
|
const container = new Container();
|
|
803
|
-
container.addChild(
|
|
804
|
-
new Text(
|
|
805
|
-
`\n${statusText(theme, "done")} ${jobIdentity(theme, details)} ${theme.fg("dim", status)}`,
|
|
806
|
-
0,
|
|
807
|
-
0,
|
|
808
|
-
),
|
|
809
|
-
);
|
|
791
|
+
container.addChild(new Text(`\n${header}`, 0, 0));
|
|
810
792
|
// The call body already carries the task; only the launch metadata is new here.
|
|
811
793
|
if (expanded)
|
|
812
794
|
container.addChild(
|
|
813
795
|
new Text(
|
|
814
|
-
theme.fg("
|
|
796
|
+
theme.fg("muted", launchDetails({ model: details.model, tools: details.tools }).join("\n")),
|
|
815
797
|
0,
|
|
816
798
|
0,
|
|
817
799
|
),
|
|
@@ -820,14 +802,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
820
802
|
if (!details.background && body) {
|
|
821
803
|
const { shown, hidden } = outputPreview(body, expanded ? Infinity : COLLAPSED_OUTPUT_LINES);
|
|
822
804
|
container.addChild(new Markdown(shown.join("\n"), 0, 0, getMarkdownTheme()));
|
|
823
|
-
if (hidden > 0)
|
|
824
|
-
container.addChild(
|
|
825
|
-
new Text(
|
|
826
|
-
theme.fg("muted", `… ${hidden} more lines, `) + keyHint("app.tools.expand", "to expand"),
|
|
827
|
-
0,
|
|
828
|
-
0,
|
|
829
|
-
),
|
|
830
|
-
);
|
|
805
|
+
if (hidden > 0) container.addChild(new Text(moreLines(theme, hidden), 0, 0));
|
|
831
806
|
}
|
|
832
807
|
return container;
|
|
833
808
|
},
|