@deathbeam/pi-delegate 0.0.16 → 0.0.18
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 +5 -3
- package/child.ts +4 -4
- package/format.ts +3 -3
- package/index.ts +46 -64
- 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
|
|
|
@@ -20,7 +20,7 @@ Optional `delegate` settings live in `~/.pi/agent/settings.json` or `.pi/setting
|
|
|
20
20
|
"delegate": {
|
|
21
21
|
"agentDirs": ["./.pi/agents"],
|
|
22
22
|
"models": {
|
|
23
|
-
"cheap": "anthropic/claude-haiku-latest",
|
|
23
|
+
"cheap": { "model": "anthropic/claude-haiku-latest", "thinking": "low" },
|
|
24
24
|
"balanced": "anthropic/claude-sonnet-latest",
|
|
25
25
|
"strong": "anthropic/claude-opus-latest"
|
|
26
26
|
}
|
|
@@ -29,7 +29,9 @@ Optional `delegate` settings live in `~/.pi/agent/settings.json` or `.pi/setting
|
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
Relative `agentDirs` resolve against the project cwd, later same-name definitions win. Project `models` override global
|
|
32
|
-
tiers (`cheap`, `balanced`, `strong`)
|
|
32
|
+
tiers (`cheap`, `balanced`, `strong`); a tier is a `provider/model` string or a `{ "model": "...", "thinking": "..." }`
|
|
33
|
+
object, otherwise the child uses the current session model and thinking level. Thinking resolves from the agent
|
|
34
|
+
frontmatter first, then the tier entry, then the session level.
|
|
33
35
|
|
|
34
36
|
Agents are Markdown files with frontmatter, the body becomes the child's system prompt:
|
|
35
37
|
|
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()));
|
|
@@ -173,15 +173,21 @@ function discoverAgents(cwd: string, configuredDirs: unknown): AgentFile[] {
|
|
|
173
173
|
return [...agents.values()];
|
|
174
174
|
}
|
|
175
175
|
|
|
176
|
-
function resolveModel(
|
|
176
|
+
export function resolveModel(
|
|
177
177
|
value: string | undefined,
|
|
178
178
|
models: Record<string, unknown>,
|
|
179
179
|
current: ExtensionContext["model"],
|
|
180
|
-
): string
|
|
181
|
-
if (value && !MODEL_TIERS.has(value)) return value;
|
|
180
|
+
): { model?: string; thinking?: string } {
|
|
181
|
+
if (value && !MODEL_TIERS.has(value)) return { model: value };
|
|
182
182
|
const configured = value ? models[value] : undefined;
|
|
183
|
-
|
|
184
|
-
|
|
183
|
+
const entry =
|
|
184
|
+
configured && typeof configured === "object"
|
|
185
|
+
? (configured as { model?: unknown; thinking?: unknown })
|
|
186
|
+
: undefined;
|
|
187
|
+
const model = typeof configured === "string" ? configured : typeof entry?.model === "string" ? entry.model : "";
|
|
188
|
+
// Tier thinking only applies when the model itself came from the tier entry.
|
|
189
|
+
if (model) return { model, thinking: typeof entry?.thinking === "string" ? entry.thinking : undefined };
|
|
190
|
+
return { model: current ? `${current.provider}/${current.id}` : undefined };
|
|
185
191
|
}
|
|
186
192
|
|
|
187
193
|
function contextWindowFor(ctx: ExtensionContext, model: string | undefined): number | undefined {
|
|
@@ -208,6 +214,11 @@ function resultFallback(body: string, theme: Theme, isError: boolean): Text {
|
|
|
208
214
|
return new Text(`\n${theme.fg(isError ? "error" : "toolOutput", body || "(no output)")}`, 0, 0);
|
|
209
215
|
}
|
|
210
216
|
|
|
217
|
+
/** Shared collapsed-output note so all three preview sites phrase it identically. */
|
|
218
|
+
function moreLines(theme: Theme, hidden: number): string {
|
|
219
|
+
return theme.fg("muted", `… ${hidden} more lines, `) + keyHint("app.tools.expand", "to expand");
|
|
220
|
+
}
|
|
221
|
+
|
|
211
222
|
/** Shared tool layout: an optional identity header, then a width-aware payload preview. */
|
|
212
223
|
function toolLayout(toolName: string, identity: string, payload: string, theme: Theme, expanded: boolean): Component {
|
|
213
224
|
const container = new Container();
|
|
@@ -232,11 +243,7 @@ function toolLayout(toolName: string, identity: string, payload: string, theme:
|
|
|
232
243
|
if (expanded || lines.length <= COLLAPSED_OUTPUT_LINES) return lines;
|
|
233
244
|
return [
|
|
234
245
|
...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
|
-
),
|
|
246
|
+
truncateToWidth(moreLines(theme, lines.length - COLLAPSED_OUTPUT_LINES), width),
|
|
240
247
|
];
|
|
241
248
|
},
|
|
242
249
|
invalidate: () => body.invalidate(),
|
|
@@ -413,14 +420,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
413
420
|
else if (report.output) {
|
|
414
421
|
const { shown, hidden } = outputPreview(report.output, expanded ? Infinity : COLLAPSED_OUTPUT_LINES);
|
|
415
422
|
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
|
-
);
|
|
423
|
+
if (hidden > 0) container.addChild(new Text(moreLines(theme, hidden), 0, 0));
|
|
424
424
|
}
|
|
425
425
|
return container;
|
|
426
426
|
});
|
|
@@ -445,24 +445,15 @@ export default function (pi: ExtensionAPI) {
|
|
|
445
445
|
let historyWidth = 1;
|
|
446
446
|
let markdown = new WeakMap<ChildActivity, Markdown>();
|
|
447
447
|
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
|
-
};
|
|
448
|
+
// Fixed rows: title, top rule, bottom rule, footer.
|
|
449
|
+
const bodyHeight = () => Math.max(0, tui.terminal.rows - 4);
|
|
460
450
|
const toolsLines = (job: InspectJob, width: number) =>
|
|
461
451
|
wrapTextWithAnsi(formatTools(job.tools), Math.max(1, width)).map((line) =>
|
|
462
452
|
theme.fg("dim", line),
|
|
463
453
|
);
|
|
454
|
+
// Fixed rows: header, model, description, rule, counter.
|
|
464
455
|
const historyHeight = (job: InspectJob, width: number) =>
|
|
465
|
-
Math.max(0, bodyHeight() -
|
|
456
|
+
Math.max(0, bodyHeight() - 5 - toolsLines(job, width).length);
|
|
466
457
|
// ScrollView needs fullscreen layout; window the history in regular TUI too.
|
|
467
458
|
const renderJobs = (width: number, items: InspectJob[], selectedIndex: number): string[] => {
|
|
468
459
|
const row = (text: string) =>
|
|
@@ -481,7 +472,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
481
472
|
row(theme.fg("muted", ` ${item.description}`)),
|
|
482
473
|
row(
|
|
483
474
|
theme.fg(
|
|
484
|
-
"
|
|
475
|
+
"muted",
|
|
485
476
|
` ${usageStats(item, (item.endedAt ?? Date.now()) - item.startedAt)}`,
|
|
486
477
|
),
|
|
487
478
|
),
|
|
@@ -489,7 +480,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
489
480
|
return [
|
|
490
481
|
...lines,
|
|
491
482
|
...Array(Math.max(0, bodyHeight() - 1 - lines.length)).fill(row("")),
|
|
492
|
-
row(theme.fg("dim",
|
|
483
|
+
row(theme.fg("dim", `${selectedIndex + 1}/${items.length}`)),
|
|
493
484
|
].slice(0, bodyHeight());
|
|
494
485
|
};
|
|
495
486
|
const renderEntry = (entry: ChildActivity, width: number): string[] => {
|
|
@@ -516,7 +507,6 @@ export default function (pi: ExtensionAPI) {
|
|
|
516
507
|
};
|
|
517
508
|
const renderHistory = (width: number, job: InspectJob): string[] => {
|
|
518
509
|
historyWidth = width;
|
|
519
|
-
const task = taskLines(job, width);
|
|
520
510
|
const tools = toolsLines(job, width);
|
|
521
511
|
const height = historyHeight(job, width);
|
|
522
512
|
const history = job.activity.flatMap((entry) => renderEntry(entry, width));
|
|
@@ -532,9 +522,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
532
522
|
truncateToWidth(`${statusText(theme, job.status)} ${jobIdentity(theme, job)}`, width),
|
|
533
523
|
truncateToWidth(theme.fg("dim", job.model), width),
|
|
534
524
|
...tools,
|
|
535
|
-
theme.fg("borderMuted", "─".repeat(Math.max(0, width))),
|
|
536
525
|
truncateToWidth(theme.fg("text", theme.bold(job.description)), width),
|
|
537
|
-
...task,
|
|
538
526
|
theme.fg("borderMuted", "─".repeat(Math.max(0, width))),
|
|
539
527
|
...shown,
|
|
540
528
|
...Array(Math.max(0, height - shown.length)).fill(""),
|
|
@@ -565,7 +553,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
565
553
|
const footer = truncateToWidth(
|
|
566
554
|
theme.fg(
|
|
567
555
|
"dim",
|
|
568
|
-
`${keyHint("tui.select.up", "
|
|
556
|
+
`${keyHint("tui.select.up", "up")} · ${keyHint("tui.select.down", "down")} · ${rawKeyHint("←/→", "switch pane")} · ${keyHint("tui.select.cancel", "close")}`,
|
|
569
557
|
),
|
|
570
558
|
width,
|
|
571
559
|
);
|
|
@@ -573,7 +561,8 @@ export default function (pi: ExtensionAPI) {
|
|
|
573
561
|
return [
|
|
574
562
|
title,
|
|
575
563
|
theme.fg("muted", "No delegates in this session."),
|
|
576
|
-
|
|
564
|
+
// Fixed rows: title, top rule, bottom rule, footer.
|
|
565
|
+
...Array(Math.max(0, tui.terminal.rows - 4)).fill(""),
|
|
577
566
|
footer,
|
|
578
567
|
].slice(0, tui.terminal.rows);
|
|
579
568
|
const sidebarWidth = Math.min(
|
|
@@ -603,6 +592,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
603
592
|
title,
|
|
604
593
|
theme.fg("borderMuted", "─".repeat(Math.max(0, width))),
|
|
605
594
|
...body,
|
|
595
|
+
theme.fg("borderMuted", "─".repeat(Math.max(0, width))),
|
|
606
596
|
footer,
|
|
607
597
|
].slice(0, tui.terminal.rows);
|
|
608
598
|
},
|
|
@@ -611,7 +601,6 @@ export default function (pi: ExtensionAPI) {
|
|
|
611
601
|
},
|
|
612
602
|
handleInput(data: string) {
|
|
613
603
|
if (keys.matches(data, "tui.select.cancel")) done(undefined);
|
|
614
|
-
else if (matchesKey(data, "tab")) focus = focus === "list" ? "history" : "list";
|
|
615
604
|
else if (matchesKey(data, "left")) focus = "list";
|
|
616
605
|
else if (
|
|
617
606
|
matchesKey(data, "right") ||
|
|
@@ -699,17 +688,23 @@ export default function (pi: ExtensionAPI) {
|
|
|
699
688
|
const names = agents.map((candidate) => candidate.name).join(", ") || "(none)";
|
|
700
689
|
throw new Error(`Unknown agent "${params.agent}". Available agents: ${names}.`);
|
|
701
690
|
}
|
|
702
|
-
const
|
|
691
|
+
const { model, thinking: tierThinking } = resolveModel(
|
|
692
|
+
params.model ?? agent.model,
|
|
693
|
+
config.models ?? {},
|
|
694
|
+
ctx.model,
|
|
695
|
+
);
|
|
703
696
|
if (!model) throw new Error(`No model found for "${params.agent}".`);
|
|
704
697
|
const tools = (agent.tools?.length ? agent.tools : pi.getActiveTools()).filter(
|
|
705
698
|
(tool) => !DELEGATION_TOOLS.has(tool),
|
|
706
699
|
);
|
|
700
|
+
const thinking = agent.thinking ?? tierThinking ?? ctx.thinkingLevel;
|
|
701
|
+
const displayModel = thinking ? `${model}:${thinking}` : model;
|
|
707
702
|
const job: DelegateJob = {
|
|
708
703
|
id: randomUUID().slice(0, 8),
|
|
709
704
|
agent: agent.name,
|
|
710
705
|
description: params.description.trim(),
|
|
711
706
|
task: params.task,
|
|
712
|
-
model,
|
|
707
|
+
model: displayModel,
|
|
713
708
|
status: "running",
|
|
714
709
|
activity: [],
|
|
715
710
|
tools,
|
|
@@ -723,13 +718,11 @@ export default function (pi: ExtensionAPI) {
|
|
|
723
718
|
agent: job.agent,
|
|
724
719
|
description: job.description,
|
|
725
720
|
task: job.task,
|
|
726
|
-
model,
|
|
721
|
+
model: displayModel,
|
|
727
722
|
tools,
|
|
728
|
-
// Only a UI can deliver a result that arrives after the tool returned; headless runs must block.
|
|
729
723
|
background: ctx.hasUI,
|
|
730
724
|
};
|
|
731
725
|
const args = ["--model", model, "--tools", tools.join(",")];
|
|
732
|
-
const thinking = agent.thinking ?? ctx.thinkingLevel;
|
|
733
726
|
if (thinking) args.push("--thinking", thinking);
|
|
734
727
|
if (agent.prompt) args.push("--append-system-prompt", agent.prompt);
|
|
735
728
|
const entrypoint = process.argv[1];
|
|
@@ -757,8 +750,6 @@ export default function (pi: ExtensionAPI) {
|
|
|
757
750
|
running.set(job.id, job);
|
|
758
751
|
if (!ticker) ticker = setInterval(() => refreshWidget(ctx), SPINNER_INTERVAL_MS);
|
|
759
752
|
refreshWidget(ctx);
|
|
760
|
-
// The only failure left here is reporting into a session that is being torn down,
|
|
761
|
-
// and an unhandled rejection would crash pi.
|
|
762
753
|
void run.done
|
|
763
754
|
.then(
|
|
764
755
|
(output) => finishJob(ctx, job, output),
|
|
@@ -769,7 +760,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
769
760
|
content: [
|
|
770
761
|
{
|
|
771
762
|
type: "text",
|
|
772
|
-
text: `Started
|
|
763
|
+
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
764
|
},
|
|
774
765
|
],
|
|
775
766
|
details,
|
|
@@ -799,19 +790,17 @@ export default function (pi: ExtensionAPI) {
|
|
|
799
790
|
const body = resultText(result);
|
|
800
791
|
if (context.isError || !details?.agent) return resultFallback(body, theme, context.isError);
|
|
801
792
|
const status = details.background ? "started in background" : "completed";
|
|
793
|
+
// The done icon means actual completion; a background launch reports its status without it.
|
|
794
|
+
const header = details.background
|
|
795
|
+
? `${jobIdentity(theme, details)} ${theme.fg("muted", status)}`
|
|
796
|
+
: `${statusText(theme, "done")} ${jobIdentity(theme, details)} ${theme.fg("muted", status)}`;
|
|
802
797
|
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
|
-
);
|
|
798
|
+
container.addChild(new Text(`\n${header}`, 0, 0));
|
|
810
799
|
// The call body already carries the task; only the launch metadata is new here.
|
|
811
800
|
if (expanded)
|
|
812
801
|
container.addChild(
|
|
813
802
|
new Text(
|
|
814
|
-
theme.fg("
|
|
803
|
+
theme.fg("muted", launchDetails({ model: details.model, tools: details.tools }).join("\n")),
|
|
815
804
|
0,
|
|
816
805
|
0,
|
|
817
806
|
),
|
|
@@ -820,14 +809,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
820
809
|
if (!details.background && body) {
|
|
821
810
|
const { shown, hidden } = outputPreview(body, expanded ? Infinity : COLLAPSED_OUTPUT_LINES);
|
|
822
811
|
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
|
-
);
|
|
812
|
+
if (hidden > 0) container.addChild(new Text(moreLines(theme, hidden), 0, 0));
|
|
831
813
|
}
|
|
832
814
|
return container;
|
|
833
815
|
},
|