pi-subagent-manager 1.0.0 → 1.2.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/docs/subagent-extension-limitations.md +10 -1
- package/package.json +1 -1
- package/src/index.ts +9 -1
- package/src/orch/diagnostics.ts +11 -0
- package/src/orch/runtime.ts +2 -2
- package/src/ui/dialog.ts +10 -3
- package/src/ui/settings-ui.ts +4 -1
- package/src/ui/ui.ts +20 -3
|
@@ -39,7 +39,7 @@ function report(pi, level, message, source) {
|
|
|
39
39
|
// historical transcript marker. No listener in a normal top-level session.
|
|
40
40
|
let hosted = false;
|
|
41
41
|
pi.events.emit("pi-subagent-manager:diagnostic:probe", {
|
|
42
|
-
respond: () => { hosted =
|
|
42
|
+
respond: (capability) => { hosted = capability?.protocol === 1 && typeof capability.version === "string"; },
|
|
43
43
|
});
|
|
44
44
|
if (hosted) {
|
|
45
45
|
pi.events.emit("pi-subagent-manager:diagnostic", { level, message, source });
|
|
@@ -87,3 +87,12 @@ For **model-authored** progress or error reports, the existing child-only
|
|
|
87
87
|
the task or triggering a parent turn. Use `agent_pause` when parent input is
|
|
88
88
|
needed. No duplicate error-reporting tool is necessary; extension diagnostics
|
|
89
89
|
are a separate host channel and do not require model tool permissions.
|
|
90
|
+
|
|
91
|
+
Since **1.1.0**, both the child diagnostic probe and the parent-session
|
|
92
|
+
`pi-subagent-manager:capabilities:probe` synchronously reply via
|
|
93
|
+
`respond({ version, protocol: 1 })`. `version` comes from this package's manifest.
|
|
94
|
+
Consumers must validate protocol 1 and a semver meeting their minimum version;
|
|
95
|
+
legacy argument-free replies are not compatible. The parent probe is available
|
|
96
|
+
while the manager is enabled; it does not install a child diagnostic sink.
|
|
97
|
+
Extensions in one session share Pi's public event bus, but each child has its own
|
|
98
|
+
bus. Discovery is capability detection among trusted extensions, not authentication.
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { diagnosticAgentText } from "./orch/diagnostics.ts";
|
|
1
|
+
import { CAPABILITY_PROBE_CHANNEL, respondDiagnosticCapability, diagnosticAgentText } from "./orch/diagnostics.ts";
|
|
2
2
|
import { randomUUID } from "node:crypto";
|
|
3
3
|
import { buildSessionContext, getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
4
4
|
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
@@ -44,6 +44,10 @@ type RootNotification = {
|
|
|
44
44
|
};
|
|
45
45
|
|
|
46
46
|
export default function piSubagent(pi: ExtensionAPI): void {
|
|
47
|
+
let capabilityActive = true;
|
|
48
|
+
pi.events.on(CAPABILITY_PROBE_CHANNEL, (payload) => {
|
|
49
|
+
if (capabilityActive && limits.subagentMode !== "off") respondDiagnosticCapability(payload);
|
|
50
|
+
});
|
|
47
51
|
let context: ExtensionContext | undefined;
|
|
48
52
|
const inheritedTools = createInheritedToolSource(pi);
|
|
49
53
|
let store = new ConfigStore({
|
|
@@ -698,6 +702,7 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
698
702
|
ctx.ui.notify(diagnostics.join("\n"), "warning");
|
|
699
703
|
};
|
|
700
704
|
pi.on("session_start", async (event, ctx) => {
|
|
705
|
+
capabilityActive = true;
|
|
701
706
|
await attachSession(ctx, true, event.reason !== "startup");
|
|
702
707
|
if (limits.subagentMode !== "off") await importAgents(ctx, true);
|
|
703
708
|
});
|
|
@@ -722,6 +727,7 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
722
727
|
pi.on("session_before_switch", stopWorkingThreads);
|
|
723
728
|
pi.on("session_before_fork", stopWorkingThreads);
|
|
724
729
|
pi.on("session_shutdown", async () => {
|
|
730
|
+
capabilityActive = false;
|
|
725
731
|
cancelSummary();
|
|
726
732
|
housekeeping.cancelAll();
|
|
727
733
|
generation++;
|
|
@@ -829,6 +835,7 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
829
835
|
await editAgentTypes(ctx, store, limits.nerdFontIcons, {
|
|
830
836
|
getAllTools: () => pi.getAllTools(),
|
|
831
837
|
toolFiltering: limits.toolFiltering,
|
|
838
|
+
resolveAgentSettings: (type) => driverFactory.resolveAgentSettings(type, "/root"),
|
|
832
839
|
});
|
|
833
840
|
store.reload();
|
|
834
841
|
} else if (command === "reload") {
|
|
@@ -851,6 +858,7 @@ export default function piSubagent(pi: ExtensionAPI): void {
|
|
|
851
858
|
agentDir: getAgentDir(),
|
|
852
859
|
getAllTools: () => pi.getAllTools(),
|
|
853
860
|
checklistStatus: () => currentChecklistStatus(ctx),
|
|
861
|
+
resolveAgentSettings: (type) => driverFactory.resolveAgentSettings(type, "/root"),
|
|
854
862
|
apply: () => {
|
|
855
863
|
const diagnostics = loadLimits(ctx);
|
|
856
864
|
requireManager().setLimits(limits);
|
package/src/orch/diagnostics.ts
CHANGED
|
@@ -1,8 +1,19 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
1
2
|
import type { ChildDiagnostic } from "../types.ts";
|
|
2
3
|
|
|
3
4
|
/** Child-local pi.events channel. Payloads are explicit, never captured from console/transcripts. */
|
|
4
5
|
export const DIAGNOSTIC_CHANNEL = "pi-subagent-manager:diagnostic";
|
|
5
6
|
export const DIAGNOSTIC_PROBE_CHANNEL = `${DIAGNOSTIC_CHANNEL}:probe`;
|
|
7
|
+
/** Session-wide discovery, not a child report channel or an authentication boundary. */
|
|
8
|
+
export const CAPABILITY_PROBE_CHANNEL = "pi-subagent-manager:capabilities:probe";
|
|
9
|
+
const packageVersion: string = createRequire(import.meta.url)("../../package.json").version;
|
|
10
|
+
export function respondDiagnosticCapability(payload: unknown): void {
|
|
11
|
+
try {
|
|
12
|
+
if (!payload || typeof payload !== "object") return;
|
|
13
|
+
const respond = (payload as { respond?: unknown }).respond;
|
|
14
|
+
if (typeof respond === "function") respond({ version: packageVersion, protocol: 1 });
|
|
15
|
+
} catch { /* Discovery callbacks must not escape into EventBus stderr. */ }
|
|
16
|
+
}
|
|
6
17
|
|
|
7
18
|
function clean(value: string, limit: number): string {
|
|
8
19
|
return value
|
package/src/orch/runtime.ts
CHANGED
|
@@ -49,6 +49,7 @@ import {
|
|
|
49
49
|
import {
|
|
50
50
|
DIAGNOSTIC_CHANNEL,
|
|
51
51
|
DIAGNOSTIC_PROBE_CHANNEL,
|
|
52
|
+
respondDiagnosticCapability,
|
|
52
53
|
diagnosticSink,
|
|
53
54
|
diagnosticText,
|
|
54
55
|
} from "./diagnostics.ts";
|
|
@@ -464,8 +465,7 @@ export function createDriverFactory(
|
|
|
464
465
|
typeof payload !== "object"
|
|
465
466
|
)
|
|
466
467
|
return;
|
|
467
|
-
|
|
468
|
-
if (typeof respond === "function") respond();
|
|
468
|
+
respondDiagnosticCapability(payload);
|
|
469
469
|
} catch {
|
|
470
470
|
/* Untrusted callbacks cannot escape into EventBus's stderr handler. */
|
|
471
471
|
}
|
package/src/ui/dialog.ts
CHANGED
|
@@ -36,6 +36,8 @@ export interface DialogRow {
|
|
|
36
36
|
/** Trusted formatter for a fixed three-cell middle column, styled at render time. */
|
|
37
37
|
renderIndicators?: (theme: Theme) => string;
|
|
38
38
|
value?: string;
|
|
39
|
+
/** Optional second line beneath the value, clipped to the same column. */
|
|
40
|
+
valueDetail?: string;
|
|
39
41
|
valueColor?: Parameters<Theme["fg"]>[0];
|
|
40
42
|
help?: string;
|
|
41
43
|
}
|
|
@@ -239,7 +241,8 @@ export class DialogMenu {
|
|
|
239
241
|
.split(/\r\n?|\n/)
|
|
240
242
|
.flatMap((line) => wrapTextWithAnsi(dialogText(line), Math.max(1, inner - 1)))
|
|
241
243
|
.slice(0, Math.max(1, height - 7 - legend.length));
|
|
242
|
-
|
|
244
|
+
const rowHeight = this.rows.some((row) => row.valueDetail !== undefined) ? 2 : 1;
|
|
245
|
+
this.viewport = Math.max(1, Math.floor((height - 6 - help.length - legend.length) / rowHeight));
|
|
243
246
|
const start = Math.max(
|
|
244
247
|
0,
|
|
245
248
|
Math.min(
|
|
@@ -260,7 +263,7 @@ export class DialogMenu {
|
|
|
260
263
|
"dim",
|
|
261
264
|
` ${this.rows.length ? this.selected + 1 : 0}/${this.rows.length} · Field / ${hasIndicators ? "Saved / " : ""}Value`,
|
|
262
265
|
),
|
|
263
|
-
...this.rows.slice(start, start + this.viewport).
|
|
266
|
+
...this.rows.slice(start, start + this.viewport).flatMap((row, i) => {
|
|
264
267
|
const selected = start + i === this.selected;
|
|
265
268
|
const color = (text: string) => selected ? this.theme.fg("accent", text) : text;
|
|
266
269
|
const plainLabel = dialogText(row.label);
|
|
@@ -274,11 +277,15 @@ export class DialogMenu {
|
|
|
274
277
|
const indicators = truncateToWidth(row.renderIndicators?.(this.theme) ?? "", indicatorWidth, "", true);
|
|
275
278
|
const indicatorPadding = " ".repeat(Math.max(0, indicatorWidth - visibleWidth(indicators)));
|
|
276
279
|
const value = dialogText(row.value ?? "");
|
|
277
|
-
|
|
280
|
+
const primary = color(`${selected ? "›" : " "} `)
|
|
278
281
|
+ (row.renderLabel ? label : color(label))
|
|
279
282
|
+ color(`${padding} │ `)
|
|
280
283
|
+ (hasIndicators ? indicators + color(`${indicatorPadding} │ `) : "")
|
|
281
284
|
+ (row.valueColor ? this.theme.fg(row.valueColor, value) : color(value));
|
|
285
|
+
if (rowHeight === 1) return [primary];
|
|
286
|
+
const valueStart = 2 + labelWidth + 3 + (hasIndicators ? indicatorWidth + 3 : 0);
|
|
287
|
+
const detail = truncateToWidth(dialogText(row.valueDetail ?? ""), Math.max(0, inner - valueStart));
|
|
288
|
+
return [primary, " ".repeat(valueStart) + this.theme.fg("muted", detail)];
|
|
282
289
|
}),
|
|
283
290
|
"",
|
|
284
291
|
...help.map((line) => this.theme.fg("muted", ` ${line}`)),
|
package/src/ui/settings-ui.ts
CHANGED
|
@@ -29,7 +29,7 @@ import {
|
|
|
29
29
|
type ToolFilteringMode,
|
|
30
30
|
type WidgetMode,
|
|
31
31
|
} from "../prefs/settings.ts";
|
|
32
|
-
import { editAgentTypes } from "./ui.ts";
|
|
32
|
+
import { editAgentTypes, type AgentEditorOptions } from "./ui.ts";
|
|
33
33
|
import { HOUSEKEEPING_PICKER_CANCEL, pickHousekeepingModel } from "./model-picker.ts";
|
|
34
34
|
import type { ToolEditorOptions } from "./tool-picker.ts";
|
|
35
35
|
import { AGENT_LOADERS, availableLoaderStyles, effectiveLoaderStyle } from "./agent-loader.ts";
|
|
@@ -331,6 +331,7 @@ export async function configureAgents(
|
|
|
331
331
|
settings: ManagerSettings;
|
|
332
332
|
agentDir: string;
|
|
333
333
|
getAllTools?: ToolEditorOptions["getAllTools"];
|
|
334
|
+
resolveAgentSettings?: AgentEditorOptions["resolveAgentSettings"];
|
|
334
335
|
/** Live pi-checklist eligibility; absent means unavailable (fail closed). */
|
|
335
336
|
checklistStatus?: () => ChecklistStatus;
|
|
336
337
|
apply(): void;
|
|
@@ -368,6 +369,7 @@ async function configureAgentsDialog(
|
|
|
368
369
|
settings: ManagerSettings;
|
|
369
370
|
agentDir: string;
|
|
370
371
|
getAllTools?: ToolEditorOptions["getAllTools"];
|
|
372
|
+
resolveAgentSettings?: AgentEditorOptions["resolveAgentSettings"];
|
|
371
373
|
/** Live pi-checklist eligibility; absent means unavailable (fail closed). */
|
|
372
374
|
checklistStatus?: () => ChecklistStatus;
|
|
373
375
|
apply(): void;
|
|
@@ -651,6 +653,7 @@ async function configureAgentsDialog(
|
|
|
651
653
|
await editAgentTypes(ctx, options.store, draft.nerdFontIcons, {
|
|
652
654
|
getAllTools: options.getAllTools ?? (() => []),
|
|
653
655
|
toolFiltering: draft.toolFiltering,
|
|
656
|
+
resolveAgentSettings: options.resolveAgentSettings,
|
|
654
657
|
});
|
|
655
658
|
options.store.reload();
|
|
656
659
|
} else if (action === "save") {
|
package/src/ui/ui.ts
CHANGED
|
@@ -43,7 +43,7 @@ import type { LoaderStyle, WidgetMode } from "../prefs/settings.ts";
|
|
|
43
43
|
import { AGENT_PROGRESS_INTERVAL, agentProgressIcon, isAgentLoaderGlyph } from "./agent-loader.ts";
|
|
44
44
|
export { AGENT_PROGRESS_INTERVAL, agentProgressIcon } from "./agent-loader.ts";
|
|
45
45
|
import { buildStatusTree, lastStarted, threadActivity, type StatusRow } from "./thread-tree.ts";
|
|
46
|
-
import { THINKING_LEVELS, type AgentType, type ThreadService, type ThreadView } from "../types.ts";
|
|
46
|
+
import { THINKING_LEVELS, type AgentType, type ResolvedAgentSettings, type ThreadService, type ThreadView } from "../types.ts";
|
|
47
47
|
|
|
48
48
|
export type ThreadController = Pick<
|
|
49
49
|
ThreadService,
|
|
@@ -1025,11 +1025,27 @@ function editMenuLabel(action: EditMenuAction, draft: AgentType): string {
|
|
|
1025
1025
|
}
|
|
1026
1026
|
}
|
|
1027
1027
|
|
|
1028
|
+
export interface AgentEditorOptions extends ToolEditorOptions {
|
|
1029
|
+
/** The runtime resolver used by agent_types, for children of this session's root. */
|
|
1030
|
+
resolveAgentSettings?: (type: AgentType) => ResolvedAgentSettings;
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
function effectiveModelLine(type: AgentType, options: AgentEditorOptions): string {
|
|
1034
|
+
try {
|
|
1035
|
+
const settings = options.resolveAgentSettings?.(type);
|
|
1036
|
+
return settings
|
|
1037
|
+
? `Model: ${settings.model} · thinking: ${settings.thinkingLevel}`
|
|
1038
|
+
: "Model: unavailable";
|
|
1039
|
+
} catch {
|
|
1040
|
+
return "Model: unavailable";
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1028
1044
|
export async function editAgentTypes(
|
|
1029
1045
|
ctx: ExtensionCommandContext,
|
|
1030
1046
|
store: ConfigStore,
|
|
1031
1047
|
nerdFontIcons = false,
|
|
1032
|
-
toolEditor:
|
|
1048
|
+
toolEditor: AgentEditorOptions = { getAllTools: () => [], toolFiltering: "allowed" },
|
|
1033
1049
|
): Promise<void> {
|
|
1034
1050
|
if (!canOpenDialog(ctx)) return;
|
|
1035
1051
|
await withDialogSession(ctx, (scoped) =>
|
|
@@ -1079,7 +1095,7 @@ async function editAgentTypesDialog(
|
|
|
1079
1095
|
ctx: ExtensionCommandContext,
|
|
1080
1096
|
store: ConfigStore,
|
|
1081
1097
|
nerdFontIcons: boolean,
|
|
1082
|
-
toolEditor:
|
|
1098
|
+
toolEditor: AgentEditorOptions,
|
|
1083
1099
|
): Promise<void> {
|
|
1084
1100
|
while (true) {
|
|
1085
1101
|
const types = store.list();
|
|
@@ -1096,6 +1112,7 @@ async function editAgentTypesDialog(
|
|
|
1096
1112
|
renderLabel: (label: string, theme: Theme) =>
|
|
1097
1113
|
agentTypeBadge(label, type.color, theme, type.icon, nerdFontIcons),
|
|
1098
1114
|
value: type.description,
|
|
1115
|
+
valueDetail: effectiveModelLine(type, toolEditor),
|
|
1099
1116
|
help: agentSourceHelp(store, type.name),
|
|
1100
1117
|
})),
|
|
1101
1118
|
]);
|