@deathbeam/pi-delegate 0.0.21 → 0.0.23
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 +7 -8
- package/agents/explore.md +0 -1
- package/agents/general.md +0 -1
- package/agents/researcher.md +0 -1
- package/agents/reviewer.md +0 -1
- package/agents.ts +17 -13
- package/child.ts +80 -0
- package/index.ts +20 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -20,18 +20,18 @@ 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":
|
|
24
|
-
"balanced": "anthropic/claude-sonnet-
|
|
25
|
-
"strong": "anthropic/claude-opus-
|
|
23
|
+
"cheap": "anthropic/claude-haiku-5-5:low",
|
|
24
|
+
"balanced": "anthropic/claude-sonnet-5-5:high",
|
|
25
|
+
"strong": "anthropic/claude-opus-5-5:high"
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
}
|
|
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`); a tier is a `provider/model` string
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
tiers (`cheap`, `balanced`, `strong`); a tier is a `provider/model` string with an optional `:<thinking>` suffix, as in
|
|
33
|
+
pi's `--model`. An unset tier makes the child use the current session model. Thinking resolves from the agent's
|
|
34
|
+
`model` suffix first, then the tier suffix, then the session level.
|
|
35
35
|
|
|
36
36
|
Agents are Markdown files with frontmatter, the body becomes the child's system prompt:
|
|
37
37
|
|
|
@@ -41,13 +41,12 @@ name: scout
|
|
|
41
41
|
description: Explore the codebase
|
|
42
42
|
tools: read, grep
|
|
43
43
|
model: cheap
|
|
44
|
-
thinking: low
|
|
45
44
|
---
|
|
46
45
|
|
|
47
46
|
Explore the codebase and report relevant paths.
|
|
48
47
|
```
|
|
49
48
|
|
|
50
|
-
Omit `tools` to inherit active tools. `model` can also be an explicit `provider/model`. The model sees the agent list from
|
|
49
|
+
Omit `tools` to inherit active tools. `model` can also be an explicit `provider/model[:thinking]`. The model sees the agent list from
|
|
51
50
|
when the extension loaded, so run `/reload` after adding agents or changing their descriptions.
|
|
52
51
|
|
|
53
52
|
The main session is prompted to act as an orchestrator. When it makes 5, 10, 20, … direct exploration calls (`read`,
|
package/agents/explore.md
CHANGED
|
@@ -3,7 +3,6 @@ name: explore
|
|
|
3
3
|
description: "Read-only codebase search: finds files, callers, and data flow. Use it for anything beyond one targeted search and before editing unfamiliar code; launch several in parallel for separate areas."
|
|
4
4
|
tools: read, grep, find, ls
|
|
5
5
|
model: cheap
|
|
6
|
-
thinking: low
|
|
7
6
|
---
|
|
8
7
|
|
|
9
8
|
You are a read-only codebase exploration agent with an isolated context.
|
package/agents/general.md
CHANGED
|
@@ -3,7 +3,6 @@ name: general
|
|
|
3
3
|
description: Multi-step work in its own context; can inspect, edit, run commands, and validate. Use it for implementation, debugging loops (reproduce, fix, verify), repetitive edits across many files, and test or build runs whose output you need only summarized.
|
|
4
4
|
tools: read, grep, find, ls, bash, edit, write
|
|
5
5
|
model: balanced
|
|
6
|
-
thinking: high
|
|
7
6
|
---
|
|
8
7
|
|
|
9
8
|
You are a delegated coding agent with an isolated context.
|
package/agents/researcher.md
CHANGED
|
@@ -3,7 +3,6 @@ name: researcher
|
|
|
3
3
|
description: Web research with cited sources. Use it whenever the answer needs external docs, versions, or current facts, instead of searching and fetching pages yourself.
|
|
4
4
|
tools: read, web_search, web_fetch
|
|
5
5
|
model: balanced
|
|
6
|
-
thinking: medium
|
|
7
6
|
---
|
|
8
7
|
|
|
9
8
|
You are a focused web research agent with an isolated context.
|
package/agents/reviewer.md
CHANGED
|
@@ -3,7 +3,6 @@ name: reviewer
|
|
|
3
3
|
description: Independent review of a diff, plan, or finished change. Use it before claiming non-trivial work is done.
|
|
4
4
|
tools: read, grep, find, ls, bash
|
|
5
5
|
model: strong
|
|
6
|
-
thinking: high
|
|
7
6
|
---
|
|
8
7
|
|
|
9
8
|
You are a skeptical code reviewer with an isolated context.
|
package/agents.ts
CHANGED
|
@@ -10,7 +10,6 @@ type AgentFile = {
|
|
|
10
10
|
description: string;
|
|
11
11
|
tools?: string[];
|
|
12
12
|
model?: string;
|
|
13
|
-
thinking?: string;
|
|
14
13
|
prompt: string;
|
|
15
14
|
};
|
|
16
15
|
|
|
@@ -70,7 +69,6 @@ function loadAgents(dir: string): AgentFile[] {
|
|
|
70
69
|
description: frontmatter.description,
|
|
71
70
|
tools: stringList(frontmatter.tools),
|
|
72
71
|
model: typeof frontmatter.model === "string" ? frontmatter.model : undefined,
|
|
73
|
-
thinking: typeof frontmatter.thinking === "string" ? frontmatter.thinking : undefined,
|
|
74
72
|
prompt: body.trim(),
|
|
75
73
|
});
|
|
76
74
|
} catch {
|
|
@@ -91,21 +89,27 @@ export function discoverAgents(cwd: string, configuredDirs: unknown): AgentFile[
|
|
|
91
89
|
return [...agents.values()];
|
|
92
90
|
}
|
|
93
91
|
|
|
92
|
+
// Same `:<thinking>` suffix pi's --model takes; only known levels split, so ids like `llama3:8b` stay whole.
|
|
93
|
+
function splitThinking(value: string): { model: string; thinking?: string } {
|
|
94
|
+
const match = /^(.*):(off|minimal|low|medium|high|xhigh|max)$/.exec(value);
|
|
95
|
+
return match ? { model: match[1], thinking: match[2] } : { model: value };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Precedence: requested `:<thinking>` suffix, then the tier suffix, then the session level.
|
|
94
99
|
export function resolveModel(
|
|
95
100
|
value: string | undefined,
|
|
96
101
|
models: Record<string, unknown>,
|
|
97
|
-
|
|
102
|
+
ctx: Pick<ExtensionContext, "model" | "thinkingLevel">,
|
|
98
103
|
): { model?: string; thinking?: string } {
|
|
99
|
-
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
return { model: current ? `${current.provider}/${current.id}` : undefined };
|
|
104
|
+
const split = splitThinking(value ?? "");
|
|
105
|
+
const thinking = split.thinking ?? ctx.thinkingLevel;
|
|
106
|
+
if (split.model && !MODEL_TIERS.has(split.model)) return { model: split.model, thinking };
|
|
107
|
+
const configured = models[split.model];
|
|
108
|
+
if (typeof configured === "string" && configured) {
|
|
109
|
+
const tier = splitThinking(configured);
|
|
110
|
+
return { model: tier.model, thinking: split.thinking ?? tier.thinking ?? ctx.thinkingLevel };
|
|
111
|
+
}
|
|
112
|
+
return { model: ctx.model ? `${ctx.model.provider}/${ctx.model.id}` : undefined, thinking };
|
|
109
113
|
}
|
|
110
114
|
|
|
111
115
|
export function contextWindowFor(ctx: ExtensionContext, model: string | undefined): number | undefined {
|
package/child.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { ChildProcessWithoutNullStreams } from "node:child_process";
|
|
2
|
+
import { readdirSync, readFileSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
2
4
|
import { limitOutput, resultPreview, toolCallDetail } from "./format.ts";
|
|
3
5
|
|
|
4
6
|
type Child = ChildProcessWithoutNullStreams;
|
|
@@ -299,3 +301,81 @@ export function runChild(
|
|
|
299
301
|
steer: (message) => send({ type: "steer", message }),
|
|
300
302
|
};
|
|
301
303
|
}
|
|
304
|
+
|
|
305
|
+
/** Text content of a persisted transcript message, in part order. */
|
|
306
|
+
function transcriptText(content: unknown): string[] {
|
|
307
|
+
if (typeof content === "string") return [content];
|
|
308
|
+
if (!Array.isArray(content)) return [];
|
|
309
|
+
return content
|
|
310
|
+
.map((part) => (part && typeof part === "object" ? (part as { type?: string; text?: string }) : {}))
|
|
311
|
+
.filter((part) => part.type === "text" && typeof part.text === "string")
|
|
312
|
+
.map((part) => part.text!);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Replays the child's persisted transcript as the activity a resumed job continues from, so the
|
|
317
|
+
* inspector keeps the old history. A missing or unreadable transcript seeds nothing: the resume
|
|
318
|
+
* itself still works.
|
|
319
|
+
*/
|
|
320
|
+
export function priorActivity(sessionDir: string, id: string): ChildActivity[] {
|
|
321
|
+
let sessionFile: string | undefined;
|
|
322
|
+
try {
|
|
323
|
+
// Sessions are <timestamp>_<sessionId>.jsonl; a recreated pinned session is the newest one.
|
|
324
|
+
sessionFile = readdirSync(sessionDir)
|
|
325
|
+
.filter((name) => name.endsWith(`_delegate-${id}.jsonl`))
|
|
326
|
+
.sort()
|
|
327
|
+
.at(-1);
|
|
328
|
+
} catch {
|
|
329
|
+
return [];
|
|
330
|
+
}
|
|
331
|
+
if (!sessionFile) return [];
|
|
332
|
+
let lines: string[] = [];
|
|
333
|
+
try {
|
|
334
|
+
lines = readFileSync(join(sessionDir, sessionFile), "utf8").split("\n");
|
|
335
|
+
} catch {
|
|
336
|
+
return [];
|
|
337
|
+
}
|
|
338
|
+
const normalize = (text: string) => text.replace(/\s+/g, " ").trim();
|
|
339
|
+
const activity: ChildActivity[] = [];
|
|
340
|
+
for (const line of lines) {
|
|
341
|
+
if (!line.trim()) continue;
|
|
342
|
+
let entry: { type?: string; message?: unknown };
|
|
343
|
+
try {
|
|
344
|
+
entry = JSON.parse(line);
|
|
345
|
+
} catch {
|
|
346
|
+
continue; // Same tolerance pi's session reader has for malformed lines.
|
|
347
|
+
}
|
|
348
|
+
const message =
|
|
349
|
+
entry?.type === "message"
|
|
350
|
+
? (entry.message as {
|
|
351
|
+
role?: "assistant" | "user" | "toolResult";
|
|
352
|
+
content?: unknown;
|
|
353
|
+
toolName?: string;
|
|
354
|
+
})
|
|
355
|
+
: undefined;
|
|
356
|
+
if (!message?.role) continue;
|
|
357
|
+
if (message.role === "toolResult") {
|
|
358
|
+
const preview = resultPreview({ content: message.content });
|
|
359
|
+
activity.push({
|
|
360
|
+
kind: "result",
|
|
361
|
+
text: normalize(`↳ ${message.toolName ?? "tool"}: ${preview ?? "(no text output)"}`),
|
|
362
|
+
});
|
|
363
|
+
continue;
|
|
364
|
+
}
|
|
365
|
+
// Assistant text lands before its tool calls, matching the live event order.
|
|
366
|
+
const text = transcriptText(message.content).join("");
|
|
367
|
+
if (text) activity.push({ kind: message.role, text });
|
|
368
|
+
if (message.role !== "assistant") continue;
|
|
369
|
+
for (const part of Array.isArray(message.content) ? message.content : []) {
|
|
370
|
+
const call =
|
|
371
|
+
part && typeof part === "object" ? (part as { type?: string; name?: string; arguments?: unknown }) : {};
|
|
372
|
+
if (call.type !== "toolCall" || !call.name) continue;
|
|
373
|
+
activity.push({
|
|
374
|
+
kind: "tool",
|
|
375
|
+
text: normalize(call.name),
|
|
376
|
+
detail: normalize(toolCallDetail(call.name, call.arguments)) || undefined,
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
return activity;
|
|
381
|
+
}
|
package/index.ts
CHANGED
|
@@ -29,13 +29,14 @@ import {
|
|
|
29
29
|
usageStats,
|
|
30
30
|
widgetJobs,
|
|
31
31
|
} from "./format.ts";
|
|
32
|
-
import { runChild } from "./child.ts";
|
|
32
|
+
import { priorActivity, runChild } from "./child.ts";
|
|
33
33
|
import { createJobStore, resumeDecision, type DelegateJob } from "./store.ts";
|
|
34
34
|
import { registerInspector } from "./inspector.ts";
|
|
35
35
|
import { configFor, contextWindowFor, discoverAgents, resolveModel } from "./agents.ts";
|
|
36
36
|
|
|
37
37
|
type DelegateDetails = Pick<DelegateJob, "id" | "agent" | "description" | "task" | "model" | "tools"> & {
|
|
38
38
|
background: boolean;
|
|
39
|
+
resumed: boolean;
|
|
39
40
|
};
|
|
40
41
|
|
|
41
42
|
type SteerDetails = Pick<
|
|
@@ -307,7 +308,10 @@ export default function (pi: ExtensionAPI) {
|
|
|
307
308
|
Type.String({ description: "Self-contained brief; the delegate cannot see this conversation." }),
|
|
308
309
|
),
|
|
309
310
|
model: Type.Optional(
|
|
310
|
-
Type.String({
|
|
311
|
+
Type.String({
|
|
312
|
+
description:
|
|
313
|
+
"Model tier (cheap, balanced, strong) or an explicit provider/model, with an optional :<thinking> suffix.",
|
|
314
|
+
}),
|
|
311
315
|
),
|
|
312
316
|
resume: Type.Optional(
|
|
313
317
|
Type.String({
|
|
@@ -337,16 +341,11 @@ export default function (pi: ExtensionAPI) {
|
|
|
337
341
|
const names = agents.map((candidate) => candidate.name).join(", ") || "(none)";
|
|
338
342
|
throw new Error(`Unknown agent "${prior?.agent ?? params.agent}". Available agents: ${names}.`);
|
|
339
343
|
}
|
|
340
|
-
const { model, thinking
|
|
341
|
-
params.model ?? agent.model,
|
|
342
|
-
config.models ?? {},
|
|
343
|
-
ctx.model,
|
|
344
|
-
);
|
|
344
|
+
const { model, thinking } = resolveModel(params.model ?? agent.model, config.models ?? {}, ctx);
|
|
345
345
|
if (!model) throw new Error(`No model found for "${agent.name}".`);
|
|
346
346
|
const tools = (agent.tools?.length ? agent.tools : pi.getActiveTools()).filter(
|
|
347
347
|
(tool) => !DELEGATION_TOOLS.has(tool),
|
|
348
348
|
);
|
|
349
|
-
const thinking = agent.thinking ?? tierThinking ?? ctx.thinkingLevel;
|
|
350
349
|
const displayModel = thinking ? `${model}:${thinking}` : model;
|
|
351
350
|
const job: DelegateJob = {
|
|
352
351
|
// A resumed job keeps its id: the pinned child session id reopens the old transcript.
|
|
@@ -356,7 +355,8 @@ export default function (pi: ExtensionAPI) {
|
|
|
356
355
|
task: prior?.task ?? params.task ?? "",
|
|
357
356
|
model: displayModel,
|
|
358
357
|
status: "running",
|
|
359
|
-
|
|
358
|
+
// A resume continues the pinned transcript, so the inspector replays the child's own history.
|
|
359
|
+
activity: prior ? priorActivity(DELEGATE_SESSION_DIR, prior.id) : [],
|
|
360
360
|
tools,
|
|
361
361
|
toolCalls: 0,
|
|
362
362
|
startedAt: Date.now(),
|
|
@@ -371,6 +371,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
371
371
|
model: displayModel,
|
|
372
372
|
tools,
|
|
373
373
|
background: ctx.hasUI,
|
|
374
|
+
resumed: Boolean(prior),
|
|
374
375
|
};
|
|
375
376
|
const args = [
|
|
376
377
|
"--session-id",
|
|
@@ -428,7 +429,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
428
429
|
content: [
|
|
429
430
|
{
|
|
430
431
|
type: "text",
|
|
431
|
-
text:
|
|
432
|
+
text: `${prior ? "Resumed" : "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.`,
|
|
432
433
|
},
|
|
433
434
|
],
|
|
434
435
|
details,
|
|
@@ -436,18 +437,21 @@ export default function (pi: ExtensionAPI) {
|
|
|
436
437
|
},
|
|
437
438
|
|
|
438
439
|
renderCall(args, theme, context) {
|
|
439
|
-
|
|
440
|
-
const
|
|
440
|
+
// A resume passes only the job id; recover the identity and task from the stored job.
|
|
441
|
+
const resumed = args?.resume ? store.find(jobId(args.resume)) : undefined;
|
|
442
|
+
const agent = argText(args?.agent).trim() || resumed?.agent || "";
|
|
443
|
+
const description = argText(args?.description).trim() || resumed?.description || "";
|
|
441
444
|
const identity = [
|
|
442
445
|
agent ? theme.fg("toolTitle", theme.bold(agent)) : "",
|
|
443
446
|
description ? theme.fg("accent", description) : "",
|
|
447
|
+
resumed ? theme.fg("muted", "(resumed)") : "",
|
|
444
448
|
]
|
|
445
449
|
.filter(Boolean)
|
|
446
450
|
.join(" ");
|
|
447
451
|
return toolLayout(
|
|
448
452
|
"delegate",
|
|
449
453
|
identity || theme.fg("muted", "…"),
|
|
450
|
-
argText(args?.task),
|
|
454
|
+
argText(args?.task) || resumed?.task || "",
|
|
451
455
|
theme,
|
|
452
456
|
context.expanded,
|
|
453
457
|
);
|
|
@@ -457,7 +461,9 @@ export default function (pi: ExtensionAPI) {
|
|
|
457
461
|
const details = result.details as DelegateDetails | undefined;
|
|
458
462
|
const body = resultText(result);
|
|
459
463
|
if (context.isError || !details?.agent) return resultFallback(body, theme, context.isError);
|
|
460
|
-
const status = details.background
|
|
464
|
+
const status = details.background
|
|
465
|
+
? `${details.resumed ? "resumed" : "started"} in background`
|
|
466
|
+
: "completed";
|
|
461
467
|
// The done icon means actual completion; a background launch reports its status without it.
|
|
462
468
|
const header = details.background
|
|
463
469
|
? `${jobIdentity(theme, details)} ${theme.fg("muted", status)}`
|