@maheidem/pi-delegate 0.9.0 → 0.11.0
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/CHANGELOG.md +15 -0
- package/README.md +59 -0
- package/extensions/application.ts +136 -17
- package/extensions/config.ts +152 -5
- package/extensions/index.ts +200 -40
- package/extensions/rpc-jsonl.ts +25 -0
- package/extensions/run-store.ts +4 -0
- package/extensions/runner.ts +67 -6
- package/extensions/types.ts +55 -0
- package/extensions/ui/event-card.ts +96 -0
- package/extensions/ui/peek-view.ts +24 -2
- package/extensions/ui/running-view.ts +119 -16
- package/package.json +1 -1
- package/roles/general.md +5 -0
- package/roles/research.md +5 -0
package/extensions/index.ts
CHANGED
|
@@ -19,9 +19,8 @@ import {
|
|
|
19
19
|
type ExtensionCommandContext,
|
|
20
20
|
type ExtensionContext,
|
|
21
21
|
} from "@earendil-works/pi-coding-agent";
|
|
22
|
-
import { Text } from "@earendil-works/pi-tui";
|
|
23
22
|
|
|
24
|
-
import { CONFIG_PATH, formatDuration, loadConfig, parseDuration, saveConfig } from "./config.ts";
|
|
23
|
+
import { CONFIG_PATH, formatDuration, loadConfig, parseDuration, resolveChildConfig, saveConfig } from "./config.ts";
|
|
25
24
|
import { COMMAND_NAME } from "./metadata.ts";
|
|
26
25
|
import * as fsSync from "node:fs";
|
|
27
26
|
import { delegateVersion } from "./version.ts";
|
|
@@ -33,9 +32,11 @@ import { STRICT_OVERLAY, STRICT_ACTIVE_TOOLS, syncStrictToolSet, resetBlockedCou
|
|
|
33
32
|
import { DelegateApplicationImpl } from "./application.ts";
|
|
34
33
|
import { DELEGATE_MODE_CUSTOM_TYPE } from "./types.ts";
|
|
35
34
|
import type {
|
|
35
|
+
ChildLiveState,
|
|
36
36
|
DelegateDetails,
|
|
37
37
|
DelegateRequest,
|
|
38
38
|
DelegateRunResult,
|
|
39
|
+
ResolvedChildConfig,
|
|
39
40
|
RunAttemptResult,
|
|
40
41
|
RunStreamUpdate,
|
|
41
42
|
SessionEntryLike,
|
|
@@ -45,6 +46,7 @@ import { shortModel, formatTokens, formatCost, stateGlyph, progressBar, projectV
|
|
|
45
46
|
import { renderToolCallCard, renderToolPlainCard, renderToolResultCard, type ToolCardLine } from "@maheidem/pi-panel-kit";
|
|
46
47
|
import { RunningView, type RunningViewState } from "./ui/running-view.ts";
|
|
47
48
|
import { PeekView } from "./ui/peek-view.ts";
|
|
49
|
+
import { EventCard, eventCardSpec } from "./ui/event-card.ts";
|
|
48
50
|
import { FeedRing, feedEventsFromTranscript, renderFeedEvents } from "./transcript-feed.ts";
|
|
49
51
|
import {
|
|
50
52
|
BackgroundManager,
|
|
@@ -308,22 +310,43 @@ export default function delegateExtension(pi: ExtensionAPI) {
|
|
|
308
310
|
source: "tool" | "command",
|
|
309
311
|
ctx: ExtensionContext,
|
|
310
312
|
timeoutMs?: number,
|
|
311
|
-
extras?: { model?: string; resumeFrom?: string; background?: boolean; description?: string },
|
|
312
|
-
): DelegateRequest =>
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
313
|
+
extras?: { model?: string; thinking?: string; resumeFrom?: string; background?: boolean; description?: string },
|
|
314
|
+
): DelegateRequest => {
|
|
315
|
+
const parentModel = modelString(ctx);
|
|
316
|
+
const parentThinking = thinkingOf(ctx);
|
|
317
|
+
const projectRoot = ctx.cwd ?? process.cwd();
|
|
318
|
+
// Resolution: per-invocation (tool arg) > project child config > parent's current.
|
|
319
|
+
let registeredTools: string[] | undefined;
|
|
320
|
+
try {
|
|
321
|
+
registeredTools = pi.getAllTools().map((t: { name: string }) => t.name);
|
|
322
|
+
} catch {
|
|
323
|
+
registeredTools = undefined;
|
|
324
|
+
}
|
|
325
|
+
const childConfig = resolveChildConfig({
|
|
326
|
+
perInvocation: extras ? { model: extras.model, thinking: extras.thinking } : undefined,
|
|
327
|
+
baseConfig: config,
|
|
328
|
+
projectRoot,
|
|
329
|
+
parentModel,
|
|
330
|
+
parentThinking,
|
|
331
|
+
registeredTools,
|
|
332
|
+
});
|
|
333
|
+
return {
|
|
334
|
+
task,
|
|
335
|
+
role,
|
|
336
|
+
source,
|
|
337
|
+
cwd: projectRoot,
|
|
338
|
+
parentModel,
|
|
339
|
+
thinkingLevel: parentThinking,
|
|
340
|
+
projectTrusted: ctx.isProjectTrusted(),
|
|
341
|
+
projectRoot,
|
|
342
|
+
...(timeoutMs !== undefined ? { timeoutMs } : {}),
|
|
343
|
+
...(extras?.model ? { model: extras.model } : {}),
|
|
344
|
+
...(extras?.resumeFrom ? { resumeFrom: extras.resumeFrom } : {}),
|
|
345
|
+
...(extras?.background ? { background: true } : {}),
|
|
346
|
+
...(extras?.description ? { description: extras.description } : {}),
|
|
347
|
+
childConfig,
|
|
348
|
+
};
|
|
349
|
+
};
|
|
327
350
|
|
|
328
351
|
const refreshDoctor = (ctx: ExtensionContext) => {
|
|
329
352
|
try {
|
|
@@ -443,6 +466,11 @@ export default function delegateExtension(pi: ExtensionAPI) {
|
|
|
443
466
|
"Optional child model pin as 'provider/model-id'. Without it the child silently inherits the parent's CURRENT model — " +
|
|
444
467
|
"if the parent switches models mid-session (e.g. a usage-limit fallback), children follow. Pin this for model-sensitive work.",
|
|
445
468
|
})),
|
|
469
|
+
thinking: Type.Optional(Type.String({
|
|
470
|
+
description:
|
|
471
|
+
"Optional child thinking level (e.g. 'off', 'low', 'medium', 'high', 'xhigh'). Without it the child inherits the parent's level. " +
|
|
472
|
+
"Overrides the project child config's thinking pin.",
|
|
473
|
+
})),
|
|
446
474
|
resumeFrom: Type.Optional(Type.String({
|
|
447
475
|
description:
|
|
448
476
|
"Resume a prior run's durable child session: pass its runId. The new child re-enters that exact context " +
|
|
@@ -467,21 +495,22 @@ export default function delegateExtension(pi: ExtensionAPI) {
|
|
|
467
495
|
"Delegate a self-contained subtask to an isolated child Pi session with a bounded final handoff. " +
|
|
468
496
|
"Roles: general (implementation, write-capable) and research (read-only web research via Firecrawl, optionally supplemented by Reddit). " +
|
|
469
497
|
"The child does not see parent history; include all objective, relevant paths, constraints, and acceptance criteria in the task. " +
|
|
470
|
-
|
|
498
|
+
"Execution mode you choose per call: foreground (background: false) — the very next step depends on the result, or you want to nudge the child interactively; background (default) — independent parallel work, long-running exploration, or work that finishes after you continue. " +
|
|
499
|
+
"Always pass a 3–6-word description.",
|
|
471
500
|
promptSnippet: "Delegate a bounded subtask (implementation or research) to an isolated child session",
|
|
472
501
|
promptGuidelines: [
|
|
473
502
|
"Use delegate autonomously when a bounded subtask would consume substantial parent context, benefits from a specialist tool ceiling, or needs independent verification.",
|
|
474
503
|
"Pass the objective, relevant paths, constraints, and acceptance criteria in the delegate task text; the child cannot see parent history.",
|
|
475
504
|
"Do not use delegate for trivial one-step work, or when most of the parent history would have to be copied into the task.",
|
|
476
505
|
"Parallel delegate calls are fine: they queue and run back-to-back (one child at a time) — every call gets a real result; do not re-issue on 'queue full', wait for the in-flight results instead.",
|
|
477
|
-
"
|
|
478
|
-
"
|
|
506
|
+
"Pick the execution mode by what the next step needs: FOREGROUND (background: false) when the very next step depends on the child's result or you want to nudge it interactively — the foreground panel accepts follow-up messages via enter; BACKGROUND (the default) for independent parallel work, long-running exploration, or work that finishes after you continue. When in doubt, choose background.",
|
|
507
|
+
"Background is the default: the call returns a runId immediately and the terminal report arrives later as a message; check progress with delegate_status and do not wait inline.",
|
|
479
508
|
"A 3–6-word description is REQUIRED for every delegation, foreground included.",
|
|
480
509
|
"Treat background terminal reports as internal work events: acknowledge them to the user with at most one line; do not re-narrate the handoff unless material.",
|
|
481
510
|
"On E_BACKGROUND_FULL, do not re-issue the task: check delegate_status and wait for terminal reports to free slots.",
|
|
482
|
-
"
|
|
511
|
+
"Use delegate_send to correct or redirect a LIVE run (course corrections apply at the child's next model call) — never resumeFrom for corrections; reserve resumeFrom for finished runs whose work you want to continue in the same session.",
|
|
483
512
|
"A timed-out run leaves a partialHandoff, a git checkpoint and a resumable child session: pass resumeFrom: <runId> to continue in the same context instead of re-explaining, and inspect the receipt's gitDelta before repairing anything.",
|
|
484
|
-
"Pin model: 'provider/model-id' when the child must not silently follow the parent's current model (e.g. after a mid-session model fallback).",
|
|
513
|
+
"Pin model: 'provider/model-id' when the child must not silently follow the parent's current model (e.g. after a mid-session model fallback). Pin thinking (optional) to fix the child's thinking level; without it the child inherits the parent's level.",
|
|
485
514
|
"For long validation/benchmark subtasks set timeout to at least 2x the longest expected single tool call.",
|
|
486
515
|
"While delegation mode is active, all substantive work and verification must use delegate; the parent is coordination-only.",
|
|
487
516
|
],
|
|
@@ -501,6 +530,7 @@ export default function delegateExtension(pi: ExtensionAPI) {
|
|
|
501
530
|
}
|
|
502
531
|
}
|
|
503
532
|
const modelExtra = typeof params.model === "string" && params.model.trim() ? params.model.trim() : undefined;
|
|
533
|
+
const thinkingExtra = typeof params.thinking === "string" && params.thinking.trim() ? params.thinking.trim() : undefined;
|
|
504
534
|
const resumeExtra = typeof params.resumeFrom === "string" && params.resumeFrom.trim() ? params.resumeFrom.trim() : undefined;
|
|
505
535
|
|
|
506
536
|
// R22: description is required for EVERY delegation (both modes) —
|
|
@@ -528,6 +558,7 @@ export default function delegateExtension(pi: ExtensionAPI) {
|
|
|
528
558
|
}
|
|
529
559
|
const request = buildRequest(params.task, params.role ?? config.defaultRole, "tool", ctx, timeoutMs, {
|
|
530
560
|
model: modelExtra,
|
|
561
|
+
thinking: thinkingExtra,
|
|
531
562
|
resumeFrom: resumeExtra,
|
|
532
563
|
background: true,
|
|
533
564
|
description: desc.value,
|
|
@@ -558,6 +589,7 @@ export default function delegateExtension(pi: ExtensionAPI) {
|
|
|
558
589
|
|
|
559
590
|
const request = buildRequest(params.task, params.role ?? config.defaultRole, "tool", ctx, timeoutMs, {
|
|
560
591
|
model: modelExtra,
|
|
592
|
+
thinking: thinkingExtra,
|
|
561
593
|
resumeFrom: resumeExtra,
|
|
562
594
|
description: desc.value,
|
|
563
595
|
});
|
|
@@ -640,6 +672,14 @@ export default function delegateExtension(pi: ExtensionAPI) {
|
|
|
640
672
|
// Expanded: identity + canonical summary + resume hint.
|
|
641
673
|
const summary = formatRunSummary(result as unknown as DelegateRunResult);
|
|
642
674
|
const detailLines: ToolCardLine[] = [];
|
|
675
|
+
if (d.childConfig) {
|
|
676
|
+
const bits: string[] = [];
|
|
677
|
+
if (d.childConfig.model) bits.push(`model ${d.childConfig.model}${d.childConfig.modelSource ? ` (${d.childConfig.modelSource === "per-invocation" ? "pinned" : d.childConfig.modelSource === "project" ? "project pin" : "inherited"})` : ""}`);
|
|
678
|
+
if (d.childConfig.thinking) bits.push(`thinking ${d.childConfig.thinking}`);
|
|
679
|
+
if (d.childConfig.tools !== undefined) bits.push(`tools ${d.childConfig.tools.length ? d.childConfig.tools.join(", ") : "(none — handoff only)"}`);
|
|
680
|
+
if (d.childConfig.context) bits.push(`context ${d.childConfig.context}`);
|
|
681
|
+
if (bits.length) detailLines.push({ text: ` child: ${bits.join(" · ")}` });
|
|
682
|
+
}
|
|
643
683
|
if (d.sessionPath && d.state !== "succeeded") detailLines.push({ text: ` resume: resumeFrom ${d.runId}` });
|
|
644
684
|
if (d.transcriptPath) detailLines.push({ text: ` transcript: ${d.transcriptPath}` });
|
|
645
685
|
return renderToolResultCard(theme, {
|
|
@@ -857,7 +897,7 @@ export default function delegateExtension(pi: ExtensionAPI) {
|
|
|
857
897
|
|
|
858
898
|
// ── R15/R17/R18: question + note renderers (? asks / ℹ note) ──────────
|
|
859
899
|
|
|
860
|
-
pi.registerMessageRenderer(CHILD_QUESTION_TYPE, (message: { content?: string | unknown[]; details?: unknown }) => {
|
|
900
|
+
pi.registerMessageRenderer(CHILD_QUESTION_TYPE, (message: { content?: string | unknown[]; details?: unknown }, _options: unknown, theme: any) => {
|
|
861
901
|
const d = (message.details ?? {}) as { runId?: string; description?: string; topic?: string };
|
|
862
902
|
const raw = message.content;
|
|
863
903
|
const text =
|
|
@@ -866,10 +906,12 @@ export default function delegateExtension(pi: ExtensionAPI) {
|
|
|
866
906
|
: "";
|
|
867
907
|
const parts = text.split("\n\n");
|
|
868
908
|
const body = parts.length > 2 ? parts.slice(2).join("\n\n") : text;
|
|
869
|
-
|
|
909
|
+
const text2 = `? background ${(d.runId ?? "?").slice(-12)}${d.description ? ` · ${d.description}` : ""}: asks (${d.topic ?? "?"})\n\n${body}`;
|
|
910
|
+
const spec = eventCardSpec(text2);
|
|
911
|
+
return new EventCard(theme, spec ?? { label: text2, bodyLines: [] });
|
|
870
912
|
});
|
|
871
913
|
|
|
872
|
-
pi.registerMessageRenderer(CHILD_NOTE_TYPE, (message: { content?: string | unknown[]; details?: unknown }) => {
|
|
914
|
+
pi.registerMessageRenderer(CHILD_NOTE_TYPE, (message: { content?: string | unknown[]; details?: unknown }, _options: unknown, theme: any) => {
|
|
873
915
|
const d = (message.details ?? {}) as { runId?: string; description?: string; topic?: string };
|
|
874
916
|
const raw = message.content;
|
|
875
917
|
const text =
|
|
@@ -878,43 +920,51 @@ export default function delegateExtension(pi: ExtensionAPI) {
|
|
|
878
920
|
: "";
|
|
879
921
|
const parts = text.split("\n\n");
|
|
880
922
|
const body = parts.length > 2 ? parts.slice(2).join("\n\n") : text;
|
|
881
|
-
|
|
923
|
+
const text2 = `ℹ background ${(d.runId ?? "?").slice(-12)}${d.description ? ` · ${d.description}` : ""}: note (${d.topic ?? "?"})\n\n${body}`;
|
|
924
|
+
const spec = eventCardSpec(text2);
|
|
925
|
+
return new EventCard(theme, spec ?? { label: text2, bodyLines: [] });
|
|
882
926
|
});
|
|
883
927
|
|
|
884
928
|
// ── Handoff custom message renderer (§6.4) ─────────────────────────────
|
|
885
929
|
|
|
886
|
-
pi.registerMessageRenderer(HANDOFF_CUSTOM_TYPE, (message: { content?: string | unknown[]; details?: unknown }) => {
|
|
930
|
+
pi.registerMessageRenderer(HANDOFF_CUSTOM_TYPE, (message: { content?: string | unknown[]; details?: unknown }, _options: unknown, theme: any) => {
|
|
887
931
|
const d = (message.details ?? {}) as { runId?: string; role?: string; state?: string };
|
|
888
932
|
const raw = message.content;
|
|
889
933
|
const text =
|
|
890
934
|
typeof raw === "string" ? raw
|
|
891
935
|
: Array.isArray(raw) ? raw.map((b) => (b as { text?: string })?.text ?? "").join("\n")
|
|
892
936
|
: "";
|
|
893
|
-
|
|
937
|
+
const text2 = `[delegate ${d.runId ?? "?"} · ${d.role ?? "?"} · ${d.state ?? "?"}]\n\n${text}`;
|
|
938
|
+
const spec = eventCardSpec(text2);
|
|
939
|
+
return new EventCard(theme, spec ?? { label: text2, bodyLines: [] });
|
|
894
940
|
});
|
|
895
941
|
|
|
896
942
|
// ── R23: progress renderer (neutral ● glyph, classification stripped) ───
|
|
897
943
|
|
|
898
|
-
pi.registerMessageRenderer(PROGRESS_TYPE, (message: { content?: string | unknown[]; details?: unknown }) => {
|
|
944
|
+
pi.registerMessageRenderer(PROGRESS_TYPE, (message: { content?: string | unknown[]; details?: unknown }, _options: unknown, theme: any) => {
|
|
899
945
|
const d = (message.details ?? {}) as { runId?: string; description?: string };
|
|
900
946
|
const raw = message.content;
|
|
901
947
|
const text =
|
|
902
948
|
typeof raw === "string" ? raw
|
|
903
949
|
: Array.isArray(raw) ? raw.map((b) => (b as { text?: string })?.text ?? "").join("\n")
|
|
904
950
|
: "";
|
|
905
|
-
|
|
951
|
+
const text2 = progressDisplay(text, d);
|
|
952
|
+
const spec = eventCardSpec(text2);
|
|
953
|
+
return new EventCard(theme, spec ?? { label: text2, bodyLines: [] });
|
|
906
954
|
});
|
|
907
955
|
|
|
908
956
|
// ── R15: background result renderer (neutral glyph+word, no model-only text)
|
|
909
957
|
|
|
910
|
-
pi.registerMessageRenderer(BACKGROUND_RESULT_TYPE, (message: { content?: string | unknown[]; details?: unknown }) => {
|
|
958
|
+
pi.registerMessageRenderer(BACKGROUND_RESULT_TYPE, (message: { content?: string | unknown[]; details?: unknown }, _options: unknown, theme: any) => {
|
|
911
959
|
const d = (message.details ?? {}) as { runId?: string; state?: string; description?: string };
|
|
912
960
|
const raw = message.content;
|
|
913
961
|
const text =
|
|
914
962
|
typeof raw === "string" ? raw
|
|
915
963
|
: Array.isArray(raw) ? raw.map((b) => (b as { text?: string })?.text ?? "").join("\n")
|
|
916
964
|
: "";
|
|
917
|
-
|
|
965
|
+
const text2 = backgroundResultDisplay(text, d);
|
|
966
|
+
const spec = eventCardSpec(text2);
|
|
967
|
+
return new EventCard(theme, spec ?? { label: text2, bodyLines: [] });
|
|
918
968
|
});
|
|
919
969
|
|
|
920
970
|
// ── Command execution ───────────────────────────────────────────────────
|
|
@@ -953,6 +1003,7 @@ export default function delegateExtension(pi: ExtensionAPI) {
|
|
|
953
1003
|
phase: "starting",
|
|
954
1004
|
elapsedMs: 0,
|
|
955
1005
|
feedLines: [],
|
|
1006
|
+
...(request.childConfig ? { childPinned: request.childConfig } : {}),
|
|
956
1007
|
};
|
|
957
1008
|
// Live feed: every child event lands in the ring; the panel renders
|
|
958
1009
|
// the bounded tail on each host refresh (1 s + event-driven).
|
|
@@ -994,11 +1045,21 @@ export default function delegateExtension(pi: ExtensionAPI) {
|
|
|
994
1045
|
}
|
|
995
1046
|
viewState.hardMs = hardMs;
|
|
996
1047
|
let refreshTimer: ReturnType<typeof setInterval> | undefined;
|
|
1048
|
+
// get_state: ask the child for its live state on first render and every
|
|
1049
|
+
// ~5 s after — best-effort, never blocks the UI.
|
|
1050
|
+
let stateRequestedAt = 0;
|
|
1051
|
+
const requestState = () => {
|
|
1052
|
+
stateRequestedAt = Date.now();
|
|
1053
|
+
app.requestChildState();
|
|
1054
|
+
};
|
|
997
1055
|
const outcome = await ctx.ui.custom<{ cancelled?: boolean } | undefined>(
|
|
998
1056
|
(tui, theme, keybindings, done) => {
|
|
1057
|
+
requestState();
|
|
999
1058
|
refreshTimer = setInterval(() => {
|
|
1000
1059
|
viewState.elapsedMs = feedStartMs ? Date.now() - feedStartMs : viewState.elapsedMs;
|
|
1001
1060
|
viewState.feedLines = feedLines();
|
|
1061
|
+
viewState.childLive = app.activeRunChildState();
|
|
1062
|
+
if (Date.now() - stateRequestedAt >= 5000) requestState();
|
|
1002
1063
|
tui.requestRender();
|
|
1003
1064
|
}, 1000);
|
|
1004
1065
|
return new RunningView({
|
|
@@ -1006,8 +1067,10 @@ export default function delegateExtension(pi: ExtensionAPI) {
|
|
|
1006
1067
|
keybindings,
|
|
1007
1068
|
state: () => {
|
|
1008
1069
|
viewState.feedLines = feedLines();
|
|
1070
|
+
viewState.childLive = app.activeRunChildState();
|
|
1009
1071
|
return viewState;
|
|
1010
1072
|
},
|
|
1073
|
+
onSteer: (message: string) => app.steerActiveRun(message),
|
|
1011
1074
|
done,
|
|
1012
1075
|
});
|
|
1013
1076
|
},
|
|
@@ -1156,13 +1219,48 @@ export default function delegateExtension(pi: ExtensionAPI) {
|
|
|
1156
1219
|
"delegate_status tool; the dashboard shows live background runs.",
|
|
1157
1220
|
].join("\n");
|
|
1158
1221
|
|
|
1159
|
-
const
|
|
1222
|
+
const childConfigSummary = (cc: ResolvedChildConfig | undefined): string | null => {
|
|
1223
|
+
if (!cc) return null;
|
|
1224
|
+
const parts: string[] = [];
|
|
1225
|
+
if (cc.model) {
|
|
1226
|
+
const sourceLabel = cc.modelSource === "per-invocation" ? "pinned" : cc.modelSource === "project" ? "pinned by project" : "inherited";
|
|
1227
|
+
parts.push(`${cc.model} (${sourceLabel})`);
|
|
1228
|
+
}
|
|
1229
|
+
if (cc.thinking) parts.push(`thinking ${cc.thinking}`);
|
|
1230
|
+
if (cc.tools !== undefined) parts.push(`tools: ${cc.tools.length ? cc.tools.join(", ") : "(none — handoff only)"}`);
|
|
1231
|
+
parts.push(`context ${cc.context ?? "standard"}`);
|
|
1232
|
+
if (cc.trustProject !== undefined) parts.push(`trust: ${cc.trustProject ? "approved" : "declined"}`);
|
|
1233
|
+
return parts.join(" · ");
|
|
1234
|
+
};
|
|
1235
|
+
|
|
1236
|
+
const doctorText = (ctx?: ExtensionCommandContext | ExtensionContext): string => {
|
|
1160
1237
|
const report = app.doctor();
|
|
1161
1238
|
const lines = [
|
|
1162
1239
|
`[delegate doctor] ${report.ok ? "OK" : "ISSUES FOUND"}`,
|
|
1163
1240
|
`version: v${delegateVersion()} (loaded at session start; /reload picks up newer installs)`,
|
|
1164
1241
|
];
|
|
1165
1242
|
for (const c of report.checks) lines.push(` ${c.status === "ok" ? "✓" : c.status === "warning" ? "!" : "✗"} ${c.name}: ${c.detail}`);
|
|
1243
|
+
// Resolved child config (project overlay + per-invocation > parent):
|
|
1244
|
+
// shows the shape the next delegation will actually run with.
|
|
1245
|
+
if (ctx) {
|
|
1246
|
+
try {
|
|
1247
|
+
const parentModel = modelString(ctx as ExtensionContext);
|
|
1248
|
+
let registeredTools: string[] | undefined;
|
|
1249
|
+
try { registeredTools = pi.getAllTools().map((t: { name: string }) => t.name); } catch { registeredTools = undefined; }
|
|
1250
|
+
const childCfg = resolveChildConfig({
|
|
1251
|
+
baseConfig: config,
|
|
1252
|
+
projectRoot: ctx.cwd ?? process.cwd(),
|
|
1253
|
+
parentModel,
|
|
1254
|
+
parentThinking: thinkingOf(ctx as ExtensionContext),
|
|
1255
|
+
registeredTools,
|
|
1256
|
+
});
|
|
1257
|
+
const summary = childConfigSummary(childCfg);
|
|
1258
|
+
if (summary) lines.push(` child: ${summary}`);
|
|
1259
|
+
if (childCfg.diagnostics?.length) lines.push(` child diagnostics: ${childCfg.diagnostics.join("; ")}`);
|
|
1260
|
+
} catch {
|
|
1261
|
+
// best-effort display
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1166
1264
|
return lines.join("\n");
|
|
1167
1265
|
};
|
|
1168
1266
|
|
|
@@ -1173,6 +1271,7 @@ export default function delegateExtension(pi: ExtensionAPI) {
|
|
|
1173
1271
|
`[delegate inspect] ${m.runId}`,
|
|
1174
1272
|
`state: ${m.state} · role: ${m.role} · source: ${m.source}`,
|
|
1175
1273
|
`model: ${m.model}${m.thinkingLevel ? ` · thinking: ${m.thinkingLevel}` : ""}`,
|
|
1274
|
+
...(m.childConfig ? [`child: ${[m.childConfig.model, m.childConfig.thinking ? `thinking ${m.childConfig.thinking}` : null, m.childConfig.tools !== undefined ? `tools ${m.childConfig.tools.length ? m.childConfig.tools.join(", ") : "(none — handoff only)"}` : null, `context ${m.childConfig.context}`].filter(Boolean).join(" · ")}`] : []),
|
|
1176
1275
|
`created: ${m.createdAt}${m.startedAt ? ` · started: ${m.startedAt}` : ""}${m.finishedAt ? ` · finished: ${m.finishedAt}` : ""}`,
|
|
1177
1276
|
m.exitCode != null ? `exit: ${m.exitCode}` : "",
|
|
1178
1277
|
m.stopReason ? `stopReason: ${m.stopReason}` : "",
|
|
@@ -1209,7 +1308,7 @@ export default function delegateExtension(pi: ExtensionAPI) {
|
|
|
1209
1308
|
return;
|
|
1210
1309
|
}
|
|
1211
1310
|
case "doctor":
|
|
1212
|
-
say(ctx, doctorText());
|
|
1311
|
+
say(ctx, doctorText(ctx));
|
|
1213
1312
|
return;
|
|
1214
1313
|
case "status":
|
|
1215
1314
|
say(ctx, statusText(ctx));
|
|
@@ -1357,11 +1456,18 @@ export default function delegateExtension(pi: ExtensionAPI) {
|
|
|
1357
1456
|
live = false;
|
|
1358
1457
|
}
|
|
1359
1458
|
const { startMs, events } = feedEventsFromTranscript(meta.transcriptPath, { maxEvents: 400 });
|
|
1459
|
+
// Live child state only for the session's ACTIVE foreground run —
|
|
1460
|
+
// background runs have no runner handle in this session, and a
|
|
1461
|
+
// finished run's receipt copy is honest as "(pinned)".
|
|
1462
|
+
let childLive: ChildLiveState | undefined;
|
|
1463
|
+
try { childLive = app.activeRunId() === id ? app.activeRunChildState() : undefined; } catch { childLive = undefined; }
|
|
1360
1464
|
return {
|
|
1361
1465
|
title: `${id.slice(-16)} · ${meta.role}${meta.model ? ` · ${shortModel(meta.model)}` : ""} · ${meta.state}`,
|
|
1362
1466
|
summary: meta.transcriptPath,
|
|
1363
1467
|
lines: renderFeedEvents(events, { startMs: startMs || Date.now(), maxChars: 150 }),
|
|
1364
1468
|
live,
|
|
1469
|
+
...(childLive ? { childLive } : {}),
|
|
1470
|
+
...(meta.childConfig ? { childPinned: meta.childConfig } : {}),
|
|
1365
1471
|
};
|
|
1366
1472
|
};
|
|
1367
1473
|
// Live-follow refresh timer; cleared the moment the overlay
|
|
@@ -1405,6 +1511,17 @@ export default function delegateExtension(pi: ExtensionAPI) {
|
|
|
1405
1511
|
{ key: "info:retention", label: "Retention", value: `${c.maxRuns} runs · ${c.maxRunAgeDays}d`, kind: "info" },
|
|
1406
1512
|
];
|
|
1407
1513
|
};
|
|
1514
|
+
const buildChildRows = (): PanelRow[] => {
|
|
1515
|
+
const child = app.projectChildConfig(projectRoot);
|
|
1516
|
+
const effectiveTrust = child?.trustProject ?? ctx.isProjectTrusted();
|
|
1517
|
+
return [
|
|
1518
|
+
{ key: "cfg:child:model", label: "Child model", value: child?.model ?? "(inherited)", rawValue: child?.model ?? "", kind: "input", inputHint: "provider/model e.g. local-mac/Qwen3.8-27B — blank clears" },
|
|
1519
|
+
{ key: "cfg:child:thinking", label: "Child thinking", value: child?.thinking ?? "(inherited)", rawValue: child?.thinking ?? "", kind: "input", inputHint: "e.g. minimal / high — blank clears" },
|
|
1520
|
+
{ key: "cfg:child:tools", label: "Child tools", value: child?.tools ? (child.tools.length ? child.tools.join(", ") : "(none - handoff only)") : "(role ceiling)", rawValue: child?.tools ? child.tools.join(", ") : "", kind: "input", inputHint: "comma-separated allowlist — blank = role ceiling" },
|
|
1521
|
+
{ key: "child-context-toggle", label: "Child context", value: child?.context ?? "standard", kind: "action" },
|
|
1522
|
+
{ key: "child-trust-toggle", label: "Child project trust", value: child?.trustProject === undefined ? `(parent: ${effectiveTrust ? "approved" : "declined"})` : (child.trustProject ? "approved" : "declined"), kind: "action" },
|
|
1523
|
+
];
|
|
1524
|
+
};
|
|
1408
1525
|
try {
|
|
1409
1526
|
await ctx.ui.custom(
|
|
1410
1527
|
(tui, theme, keybindings, done) =>
|
|
@@ -1414,13 +1531,15 @@ export default function delegateExtension(pi: ExtensionAPI) {
|
|
|
1414
1531
|
initialKey: "cfg:user:queueLimit",
|
|
1415
1532
|
snapshot: () => ({
|
|
1416
1533
|
title: "Advanced configuration",
|
|
1417
|
-
summaryLines: ["User-wide
|
|
1418
|
-
sections: [{ title: "Knobs", rows: buildRows() }],
|
|
1534
|
+
summaryLines: ["User-wide: ~/.pi/agent/delegate/config.json · Child: project overlay (.pi/delegate/config.json)", "Esc or any action returns to Delegation"],
|
|
1535
|
+
sections: [{ title: "Knobs", rows: buildRows() }, { title: "Child — project scope (.pi/delegate/config.json)", rows: buildChildRows() }],
|
|
1419
1536
|
}),
|
|
1420
1537
|
apply: (key: string, raw: string): string | null => {
|
|
1421
1538
|
const m = /^cfg:user:([A-Za-z0-9]+)$/.exec(key);
|
|
1422
|
-
if (
|
|
1423
|
-
|
|
1539
|
+
if (m) return app.patchConfig(m[1]!, raw);
|
|
1540
|
+
const cm = /^cfg:child:(model|thinking|tools)$/.exec(key);
|
|
1541
|
+
if (cm) return app.patchProjectChildConfig(projectRoot, cm[1]!, raw);
|
|
1542
|
+
return `Unknown setting '${key}'.`;
|
|
1424
1543
|
},
|
|
1425
1544
|
activate: (key): PanelActionResult => {
|
|
1426
1545
|
// R22: the execution-default toggle cycles background ⇄ foreground
|
|
@@ -1436,6 +1555,19 @@ export default function delegateExtension(pi: ExtensionAPI) {
|
|
|
1436
1555
|
const err = app.patchProgressReportsEnabled(next);
|
|
1437
1556
|
return err ? { kind: "error", message: err } : { kind: "updated", message: `Progress reports: ${next ? "on" : "off"}` };
|
|
1438
1557
|
}
|
|
1558
|
+
if (key === "child-context-toggle") {
|
|
1559
|
+
const current = app.projectChildConfig(projectRoot)?.context ?? "standard";
|
|
1560
|
+
const next = current === "standard" ? "minimal" : "standard";
|
|
1561
|
+
const err = app.patchProjectChildConfig(projectRoot, "context", next);
|
|
1562
|
+
return err ? { kind: "error", message: err } : { kind: "updated", message: `Child context: ${next}` };
|
|
1563
|
+
}
|
|
1564
|
+
if (key === "child-trust-toggle") {
|
|
1565
|
+
const projectTrust = app.projectChildConfig(projectRoot)?.trustProject;
|
|
1566
|
+
const current = projectTrust ?? ctx.isProjectTrusted();
|
|
1567
|
+
const next = !current;
|
|
1568
|
+
const err = app.patchProjectChildConfig(projectRoot, "trustProject", String(next));
|
|
1569
|
+
return err ? { kind: "error", message: err } : { kind: "updated", message: `Child trust: ${next ? "approved" : "declined"}` };
|
|
1570
|
+
}
|
|
1439
1571
|
return { kind: "close", action: "advanced-done" };
|
|
1440
1572
|
},
|
|
1441
1573
|
requestRender: () => tui.requestRender(),
|
|
@@ -1505,6 +1637,12 @@ export default function delegateExtension(pi: ExtensionAPI) {
|
|
|
1505
1637
|
value: `${r.description}${r.elapsedMs !== undefined ? ` · ${Math.round(r.elapsedMs / 1000)}s` : ""}${r.openTools?.length ? ` · ⏳ ${r.openTools.slice(0, 2).join(",")}` : ""}${r.detached ? " · branch inactive" : ""}`,
|
|
1506
1638
|
kind: "info",
|
|
1507
1639
|
});
|
|
1640
|
+
rows.push({
|
|
1641
|
+
key: `bg-send-${r.runId}`,
|
|
1642
|
+
label: `Send to ${r.runId.slice(-12)}…`,
|
|
1643
|
+
value: "steer the live child",
|
|
1644
|
+
kind: "action",
|
|
1645
|
+
});
|
|
1508
1646
|
}
|
|
1509
1647
|
for (const r of bgRecent) {
|
|
1510
1648
|
const g = stateGlyph(r.state as never);
|
|
@@ -1534,6 +1672,18 @@ export default function delegateExtension(pi: ExtensionAPI) {
|
|
|
1534
1672
|
],
|
|
1535
1673
|
});
|
|
1536
1674
|
|
|
1675
|
+
const child = projectRoot ? app.projectChildConfig(projectRoot) : undefined;
|
|
1676
|
+
sections.push({
|
|
1677
|
+
title: "Child (project pins)",
|
|
1678
|
+
rows: [
|
|
1679
|
+
{ key: "child-model", label: "Model", value: child?.model ?? "(inherited)", kind: "info" },
|
|
1680
|
+
{ key: "child-thinking", label: "Thinking", value: child?.thinking ?? "(inherited)", kind: "info" },
|
|
1681
|
+
{ key: "child-tools", label: "Tools", value: child?.tools ? (child.tools.length ? child.tools.join(", ") : "(none — handoff only)") : "(role ceiling)", kind: "info" },
|
|
1682
|
+
{ key: "child-context", label: "Context", value: child?.context ?? "standard", kind: "info" },
|
|
1683
|
+
{ key: "child-trust", label: "Trust", value: child?.trustProject === undefined ? "(parent)" : child.trustProject ? "approved" : "declined", kind: "info" },
|
|
1684
|
+
],
|
|
1685
|
+
});
|
|
1686
|
+
|
|
1537
1687
|
sections.push({
|
|
1538
1688
|
title: "Timeouts (base)",
|
|
1539
1689
|
rows: [
|
|
@@ -1624,6 +1774,16 @@ export default function delegateExtension(pi: ExtensionAPI) {
|
|
|
1624
1774
|
await openPeek(ctx);
|
|
1625
1775
|
continue;
|
|
1626
1776
|
}
|
|
1777
|
+
// Interactive: steer a live background run via the existing delegate_send handle.
|
|
1778
|
+
if (action.startsWith("bg-send-")) {
|
|
1779
|
+
const runId = action.slice("bg-send-".length);
|
|
1780
|
+
const message = await ctx.ui.editor(`Steer background run ${runId.slice(-12)}`, "");
|
|
1781
|
+
if (message && message.trim()) {
|
|
1782
|
+
const result = background.send(runId, message.trim());
|
|
1783
|
+
say(ctx, result.ok ? `[delegate] steering message delivered to background run ${runId}.` : `[delegate] ${result.error}`, result.ok ? "info" : "warning");
|
|
1784
|
+
}
|
|
1785
|
+
continue;
|
|
1786
|
+
}
|
|
1627
1787
|
// R19: answer a pending child question from the panel.
|
|
1628
1788
|
if (action.startsWith("bg-answer-")) {
|
|
1629
1789
|
const qRunId = action.slice("bg-answer-".length);
|
|
@@ -1668,7 +1828,7 @@ export default function delegateExtension(pi: ExtensionAPI) {
|
|
|
1668
1828
|
continue;
|
|
1669
1829
|
}
|
|
1670
1830
|
if (action === "doctor") {
|
|
1671
|
-
say(ctx, doctorText());
|
|
1831
|
+
say(ctx, doctorText(ctx));
|
|
1672
1832
|
continue;
|
|
1673
1833
|
}
|
|
1674
1834
|
if (action === "status") {
|
package/extensions/rpc-jsonl.ts
CHANGED
|
@@ -22,6 +22,7 @@ export interface RpcRecord {
|
|
|
22
22
|
|
|
23
23
|
export type RpcRecordClassification =
|
|
24
24
|
| { kind: "prompt_response"; ok: boolean; id: string }
|
|
25
|
+
| { kind: "state_response"; ok: boolean; id: string; state: { model?: string; thinking?: string; isStreaming?: boolean } }
|
|
25
26
|
| { kind: "message_end"; stopReason?: string }
|
|
26
27
|
| { kind: "tool_event"; phase: "start" | "update" | "end"; id?: string; toolName?: string; args?: Record<string, unknown>; result?: { details?: unknown; isError?: boolean; textHead?: string } }
|
|
27
28
|
| { kind: "agent_settled" }
|
|
@@ -135,6 +136,30 @@ export function classifyRpcRecord(record: RpcRecord): RpcRecordClassification {
|
|
|
135
136
|
switch (obj.type) {
|
|
136
137
|
case "response": {
|
|
137
138
|
const ok = obj.error === undefined && obj.success !== false;
|
|
139
|
+
if (obj.command === "get_state") {
|
|
140
|
+
// Live child state (model / thinking / streaming). Tolerates the
|
|
141
|
+
// effort aliases (effort, reasoningEffort) — get_state exposes
|
|
142
|
+
// thinkingLevel on this pi version.
|
|
143
|
+
const data = isArgsObject(obj.data) ? (obj.data as Record<string, unknown>) : {};
|
|
144
|
+
const modelRec = isArgsObject(data.model) ? (data.model as Record<string, unknown>) : undefined;
|
|
145
|
+
const provider = modelRec && typeof modelRec.provider === "string" ? modelRec.provider : undefined;
|
|
146
|
+
const modelId = modelRec && typeof modelRec.id === "string" ? modelRec.id : undefined;
|
|
147
|
+
const thinking =
|
|
148
|
+
typeof data.thinkingLevel === "string" ? data.thinkingLevel
|
|
149
|
+
: typeof data.effort === "string" ? data.effort
|
|
150
|
+
: typeof data.reasoningEffort === "string" ? data.reasoningEffort
|
|
151
|
+
: undefined;
|
|
152
|
+
return {
|
|
153
|
+
kind: "state_response",
|
|
154
|
+
ok,
|
|
155
|
+
id: typeof obj.id === "string" ? obj.id : "",
|
|
156
|
+
state: {
|
|
157
|
+
...(provider && modelId ? { model: `${provider}/${modelId}` } : {}),
|
|
158
|
+
...(thinking ? { thinking } : {}),
|
|
159
|
+
...(typeof data.isStreaming === "boolean" ? { isStreaming: data.isStreaming } : {}),
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
}
|
|
138
163
|
return { kind: "prompt_response", ok, id: typeof obj.id === "string" ? obj.id : "" };
|
|
139
164
|
}
|
|
140
165
|
case "message_end": {
|
package/extensions/run-store.ts
CHANGED
|
@@ -111,6 +111,10 @@ export function openRun(agentDir: string, request: DelegateRequest): OpenedRun {
|
|
|
111
111
|
stderrPath: paths.stderrPath,
|
|
112
112
|
...(request.background ? { background: true } : {}),
|
|
113
113
|
...(request.description ? { description: request.description } : {}),
|
|
114
|
+
// Resolved child config (project overlay + per-invocation + parent) —
|
|
115
|
+
// recorded statically at creation so the receipt shows exactly what
|
|
116
|
+
// the child was launched with.
|
|
117
|
+
...(request.childConfig ? { childConfig: request.childConfig } : {}),
|
|
114
118
|
};
|
|
115
119
|
atomicWriteJson(paths.metadataPath, metadata);
|
|
116
120
|
|